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"
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"
69 /* readline include files */
70 #include "readline/readline.h"
71 #include "readline/history.h"
73 /* readline defines this. */
76 #include "mi/mi-common.h"
77 #include "python/python.h"
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void breakpoint_re_set_default (struct breakpoint *);
99 static void clear_command (char *, int);
101 static void catch_command (char *, int);
103 static int can_use_hardware_watchpoint (struct value *);
105 static void break_command_1 (char *, int, int);
107 static void mention (struct breakpoint *);
109 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
111 const struct breakpoint_ops *);
112 /* This function is used in gdbtk sources and thus can not be made
114 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
115 struct symtab_and_line,
117 const struct breakpoint_ops *);
119 static struct breakpoint *
120 momentary_breakpoint_from_master (struct breakpoint *orig,
122 const struct breakpoint_ops *ops);
124 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
126 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
130 static void describe_other_breakpoints (struct gdbarch *,
131 struct program_space *, CORE_ADDR,
132 struct obj_section *, int);
134 static int breakpoint_address_match (struct address_space *aspace1,
136 struct address_space *aspace2,
139 static int watchpoint_locations_match (struct bp_location *loc1,
140 struct bp_location *loc2);
142 static int breakpoint_location_address_match (struct bp_location *bl,
143 struct address_space *aspace,
146 static void breakpoints_info (char *, int);
148 static void watchpoints_info (char *, int);
150 static int breakpoint_1 (char *, int,
151 int (*) (const struct breakpoint *));
153 static int breakpoint_cond_eval (void *);
155 static void cleanup_executing_breakpoints (void *);
157 static void commands_command (char *, int);
159 static void condition_command (char *, int);
168 static int remove_breakpoint (struct bp_location *, insertion_state_t);
169 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
171 static enum print_stop_action print_bp_stop_message (bpstat bs);
173 static int watchpoint_check (void *);
175 static void maintenance_info_breakpoints (char *, int);
177 static int hw_breakpoint_used_count (void);
179 static int hw_watchpoint_used_count (enum bptype, int *);
181 static void hbreak_command (char *, int);
183 static void thbreak_command (char *, int);
185 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp);
187 static void stop_command (char *arg, int from_tty);
189 static void stopin_command (char *arg, int from_tty);
191 static void stopat_command (char *arg, int from_tty);
193 static char *ep_parse_optional_if_clause (char **arg);
195 static void catch_exception_command_1 (enum exception_event_kind ex_event,
196 char *arg, int tempflag, int from_tty);
198 static void tcatch_command (char *arg, int from_tty);
200 static void detach_single_step_breakpoints (void);
202 static int single_step_breakpoint_inserted_here_p (struct address_space *,
205 static void free_bp_location (struct bp_location *loc);
206 static void incref_bp_location (struct bp_location *loc);
207 static void decref_bp_location (struct bp_location **loc);
209 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
211 static void update_global_location_list (int);
213 static void update_global_location_list_nothrow (int);
215 static int is_hardware_watchpoint (const struct breakpoint *bpt);
217 static void insert_breakpoint_locations (void);
219 static int syscall_catchpoint_p (struct breakpoint *b);
221 static void tracepoints_info (char *, int);
223 static void delete_trace_command (char *, int);
225 static void enable_trace_command (char *, int);
227 static void disable_trace_command (char *, int);
229 static void trace_pass_command (char *, int);
231 static int is_masked_watchpoint (const struct breakpoint *b);
233 /* Assuming we're creating a static tracepoint, does S look like a
234 static tracepoint marker spec ("-m MARKER_ID")? */
235 #define is_marker_spec(s) \
236 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
238 /* The abstract base class all breakpoint_ops structures inherit
240 static struct breakpoint_ops base_breakpoint_ops;
242 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
243 that are implemented on top of software or hardware breakpoints
244 (user breakpoints, internal and momentary breakpoints, etc.). */
245 static struct breakpoint_ops bkpt_base_breakpoint_ops;
247 /* Internal breakpoints class type. */
248 static struct breakpoint_ops internal_breakpoint_ops;
250 /* Momentary breakpoints class type. */
251 static struct breakpoint_ops momentary_breakpoint_ops;
253 /* The breakpoint_ops structure to be used in regular user created
255 struct breakpoint_ops bkpt_breakpoint_ops;
257 /* A reference-counted struct command_line. This lets multiple
258 breakpoints share a single command list. */
259 struct counted_command_line
261 /* The reference count. */
264 /* The command list. */
265 struct command_line *commands;
268 struct command_line *
269 breakpoint_commands (struct breakpoint *b)
271 return b->commands ? b->commands->commands : NULL;
274 /* Flag indicating that a command has proceeded the inferior past the
275 current breakpoint. */
277 static int breakpoint_proceeded;
280 bpdisp_text (enum bpdisp disp)
282 /* NOTE: the following values are a part of MI protocol and
283 represent values of 'disp' field returned when inferior stops at
285 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
287 return bpdisps[(int) disp];
290 /* Prototypes for exported functions. */
291 /* If FALSE, gdb will not use hardware support for watchpoints, even
292 if such is available. */
293 static int can_use_hw_watchpoints;
296 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
297 struct cmd_list_element *c,
300 fprintf_filtered (file,
301 _("Debugger's willingness to use "
302 "watchpoint hardware is %s.\n"),
306 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
307 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
308 for unrecognized breakpoint locations.
309 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
310 static enum auto_boolean pending_break_support;
312 show_pending_break_support (struct ui_file *file, int from_tty,
313 struct cmd_list_element *c,
316 fprintf_filtered (file,
317 _("Debugger's behavior regarding "
318 "pending breakpoints is %s.\n"),
322 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
323 set with "break" but falling in read-only memory.
324 If 0, gdb will warn about such breakpoints, but won't automatically
325 use hardware breakpoints. */
326 static int automatic_hardware_breakpoints;
328 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
329 struct cmd_list_element *c,
332 fprintf_filtered (file,
333 _("Automatic usage of hardware breakpoints is %s.\n"),
337 /* If on, gdb will keep breakpoints inserted even as inferior is
338 stopped, and immediately insert any new breakpoints. If off, gdb
339 will insert breakpoints into inferior only when resuming it, and
340 will remove breakpoints upon stop. If auto, GDB will behave as ON
341 if in non-stop mode, and as OFF if all-stop mode.*/
343 static const char always_inserted_auto[] = "auto";
344 static const char always_inserted_on[] = "on";
345 static const char always_inserted_off[] = "off";
346 static const char *always_inserted_enums[] = {
347 always_inserted_auto,
352 static const char *always_inserted_mode = always_inserted_auto;
354 show_always_inserted_mode (struct ui_file *file, int from_tty,
355 struct cmd_list_element *c, const char *value)
357 if (always_inserted_mode == always_inserted_auto)
358 fprintf_filtered (file,
359 _("Always inserted breakpoint "
360 "mode is %s (currently %s).\n"),
362 breakpoints_always_inserted_mode () ? "on" : "off");
364 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
369 breakpoints_always_inserted_mode (void)
371 return (always_inserted_mode == always_inserted_on
372 || (always_inserted_mode == always_inserted_auto && non_stop));
375 void _initialize_breakpoint (void);
377 /* Are we executing breakpoint commands? */
378 static int executing_breakpoint_commands;
380 /* Are overlay event breakpoints enabled? */
381 static int overlay_events_enabled;
383 /* See description in breakpoint.h. */
384 int target_exact_watchpoints = 0;
386 /* Walk the following statement or block through all breakpoints.
387 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
388 current breakpoint. */
390 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
392 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
393 for (B = breakpoint_chain; \
394 B ? (TMP=B->next, 1): 0; \
397 /* Similar iterator for the low-level breakpoints. SAFE variant is
398 not provided so update_global_location_list must not be called
399 while executing the block of ALL_BP_LOCATIONS. */
401 #define ALL_BP_LOCATIONS(B,BP_TMP) \
402 for (BP_TMP = bp_location; \
403 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
406 /* Iterator for tracepoints only. */
408 #define ALL_TRACEPOINTS(B) \
409 for (B = breakpoint_chain; B; B = B->next) \
410 if (is_tracepoint (B))
412 /* Chains of all breakpoints defined. */
414 struct breakpoint *breakpoint_chain;
416 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
418 static struct bp_location **bp_location;
420 /* Number of elements of BP_LOCATION. */
422 static unsigned bp_location_count;
424 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
425 ADDRESS for the current elements of BP_LOCATION which get a valid
426 result from bp_location_has_shadow. You can use it for roughly
427 limiting the subrange of BP_LOCATION to scan for shadow bytes for
428 an address you need to read. */
430 static CORE_ADDR bp_location_placed_address_before_address_max;
432 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
433 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
434 BP_LOCATION which get a valid result from bp_location_has_shadow.
435 You can use it for roughly limiting the subrange of BP_LOCATION to
436 scan for shadow bytes for an address you need to read. */
438 static CORE_ADDR bp_location_shadow_len_after_address_max;
440 /* The locations that no longer correspond to any breakpoint, unlinked
441 from bp_location array, but for which a hit may still be reported
443 VEC(bp_location_p) *moribund_locations = NULL;
445 /* Number of last breakpoint made. */
447 static int breakpoint_count;
449 /* The value of `breakpoint_count' before the last command that
450 created breakpoints. If the last (break-like) command created more
451 than one breakpoint, then the difference between BREAKPOINT_COUNT
452 and PREV_BREAKPOINT_COUNT is more than one. */
453 static int prev_breakpoint_count;
455 /* Number of last tracepoint made. */
457 static int tracepoint_count;
459 static struct cmd_list_element *breakpoint_set_cmdlist;
460 static struct cmd_list_element *breakpoint_show_cmdlist;
461 struct cmd_list_element *save_cmdlist;
463 /* Return whether a breakpoint is an active enabled breakpoint. */
465 breakpoint_enabled (struct breakpoint *b)
467 return (b->enable_state == bp_enabled);
470 /* Set breakpoint count to NUM. */
473 set_breakpoint_count (int num)
475 prev_breakpoint_count = breakpoint_count;
476 breakpoint_count = num;
477 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
480 /* Used by `start_rbreak_breakpoints' below, to record the current
481 breakpoint count before "rbreak" creates any breakpoint. */
482 static int rbreak_start_breakpoint_count;
484 /* Called at the start an "rbreak" command to record the first
488 start_rbreak_breakpoints (void)
490 rbreak_start_breakpoint_count = breakpoint_count;
493 /* Called at the end of an "rbreak" command to record the last
497 end_rbreak_breakpoints (void)
499 prev_breakpoint_count = rbreak_start_breakpoint_count;
502 /* Used in run_command to zero the hit count when a new run starts. */
505 clear_breakpoint_hit_counts (void)
507 struct breakpoint *b;
513 /* Allocate a new counted_command_line with reference count of 1.
514 The new structure owns COMMANDS. */
516 static struct counted_command_line *
517 alloc_counted_command_line (struct command_line *commands)
519 struct counted_command_line *result
520 = xmalloc (sizeof (struct counted_command_line));
523 result->commands = commands;
527 /* Increment reference count. This does nothing if CMD is NULL. */
530 incref_counted_command_line (struct counted_command_line *cmd)
536 /* Decrement reference count. If the reference count reaches 0,
537 destroy the counted_command_line. Sets *CMDP to NULL. This does
538 nothing if *CMDP is NULL. */
541 decref_counted_command_line (struct counted_command_line **cmdp)
545 if (--(*cmdp)->refc == 0)
547 free_command_lines (&(*cmdp)->commands);
554 /* A cleanup function that calls decref_counted_command_line. */
557 do_cleanup_counted_command_line (void *arg)
559 decref_counted_command_line (arg);
562 /* Create a cleanup that calls decref_counted_command_line on the
565 static struct cleanup *
566 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
568 return make_cleanup (do_cleanup_counted_command_line, cmdp);
571 /* Default address, symtab and line to put a breakpoint at
572 for "break" command with no arg.
573 If default_breakpoint_valid is zero, the other three are
574 not valid, and "break" with no arg is an error.
576 This set by print_stack_frame, which calls set_default_breakpoint. */
578 int default_breakpoint_valid;
579 CORE_ADDR default_breakpoint_address;
580 struct symtab *default_breakpoint_symtab;
581 int default_breakpoint_line;
582 struct program_space *default_breakpoint_pspace;
585 /* Return the breakpoint with the specified number, or NULL
586 if the number does not refer to an existing breakpoint. */
589 get_breakpoint (int num)
591 struct breakpoint *b;
594 if (b->number == num)
603 set_breakpoint_condition (struct breakpoint *b, char *exp,
606 xfree (b->cond_string);
607 b->cond_string = NULL;
609 if (is_watchpoint (b))
611 struct watchpoint *w = (struct watchpoint *) b;
618 struct bp_location *loc;
620 for (loc = b->loc; loc; loc = loc->next)
630 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
636 /* I don't know if it matters whether this is the string the user
637 typed in or the decompiled expression. */
638 b->cond_string = xstrdup (arg);
639 b->condition_not_parsed = 0;
641 if (is_watchpoint (b))
643 struct watchpoint *w = (struct watchpoint *) b;
645 innermost_block = NULL;
647 w->cond_exp = parse_exp_1 (&arg, 0, 0);
649 error (_("Junk at end of expression"));
650 w->cond_exp_valid_block = innermost_block;
654 struct bp_location *loc;
656 for (loc = b->loc; loc; loc = loc->next)
660 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
662 error (_("Junk at end of expression"));
666 breakpoints_changed ();
667 observer_notify_breakpoint_modified (b);
670 /* condition N EXP -- set break condition of breakpoint N to EXP. */
673 condition_command (char *arg, int from_tty)
675 struct breakpoint *b;
680 error_no_arg (_("breakpoint number"));
683 bnum = get_number (&p);
685 error (_("Bad breakpoint argument: '%s'"), arg);
688 if (b->number == bnum)
690 /* Check if this breakpoint has a Python object assigned to
691 it, and if it has a definition of the "stop"
692 method. This method and conditions entered into GDB from
693 the CLI are mutually exclusive. */
695 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
696 error (_("Cannot set a condition where a Python 'stop' "
697 "method has been defined in the breakpoint."));
698 set_breakpoint_condition (b, p, from_tty);
702 error (_("No breakpoint number %d."), bnum);
705 /* Check that COMMAND do not contain commands that are suitable
706 only for tracepoints and not suitable for ordinary breakpoints.
707 Throw if any such commands is found. */
710 check_no_tracepoint_commands (struct command_line *commands)
712 struct command_line *c;
714 for (c = commands; c; c = c->next)
718 if (c->control_type == while_stepping_control)
719 error (_("The 'while-stepping' command can "
720 "only be used for tracepoints"));
722 for (i = 0; i < c->body_count; ++i)
723 check_no_tracepoint_commands ((c->body_list)[i]);
725 /* Not that command parsing removes leading whitespace and comment
726 lines and also empty lines. So, we only need to check for
728 if (strstr (c->line, "collect ") == c->line)
729 error (_("The 'collect' command can only be used for tracepoints"));
731 if (strstr (c->line, "teval ") == c->line)
732 error (_("The 'teval' command can only be used for tracepoints"));
736 /* Encapsulate tests for different types of tracepoints. */
739 is_tracepoint_type (enum bptype type)
741 return (type == bp_tracepoint
742 || type == bp_fast_tracepoint
743 || type == bp_static_tracepoint);
747 is_tracepoint (const struct breakpoint *b)
749 return is_tracepoint_type (b->type);
752 /* A helper function that validates that COMMANDS are valid for a
753 breakpoint. This function will throw an exception if a problem is
757 validate_commands_for_breakpoint (struct breakpoint *b,
758 struct command_line *commands)
760 if (is_tracepoint (b))
762 /* We need to verify that each top-level element of commands is
763 valid for tracepoints, that there's at most one
764 while-stepping element, and that while-stepping's body has
765 valid tracing commands excluding nested while-stepping. */
766 struct command_line *c;
767 struct command_line *while_stepping = 0;
768 for (c = commands; c; c = c->next)
770 if (c->control_type == while_stepping_control)
772 if (b->type == bp_fast_tracepoint)
773 error (_("The 'while-stepping' command "
774 "cannot be used for fast tracepoint"));
775 else if (b->type == bp_static_tracepoint)
776 error (_("The 'while-stepping' command "
777 "cannot be used for static tracepoint"));
780 error (_("The 'while-stepping' command "
781 "can be used only once"));
788 struct command_line *c2;
790 gdb_assert (while_stepping->body_count == 1);
791 c2 = while_stepping->body_list[0];
792 for (; c2; c2 = c2->next)
794 if (c2->control_type == while_stepping_control)
795 error (_("The 'while-stepping' command cannot be nested"));
801 check_no_tracepoint_commands (commands);
805 /* Return a vector of all the static tracepoints set at ADDR. The
806 caller is responsible for releasing the vector. */
809 static_tracepoints_here (CORE_ADDR addr)
811 struct breakpoint *b;
812 VEC(breakpoint_p) *found = 0;
813 struct bp_location *loc;
816 if (b->type == bp_static_tracepoint)
818 for (loc = b->loc; loc; loc = loc->next)
819 if (loc->address == addr)
820 VEC_safe_push(breakpoint_p, found, b);
826 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
827 validate that only allowed commands are included. */
830 breakpoint_set_commands (struct breakpoint *b,
831 struct command_line *commands)
833 validate_commands_for_breakpoint (b, commands);
835 decref_counted_command_line (&b->commands);
836 b->commands = alloc_counted_command_line (commands);
837 breakpoints_changed ();
838 observer_notify_breakpoint_modified (b);
841 /* Set the internal `silent' flag on the breakpoint. Note that this
842 is not the same as the "silent" that may appear in the breakpoint's
846 breakpoint_set_silent (struct breakpoint *b, int silent)
848 int old_silent = b->silent;
851 if (old_silent != silent)
852 observer_notify_breakpoint_modified (b);
855 /* Set the thread for this breakpoint. If THREAD is -1, make the
856 breakpoint work for any thread. */
859 breakpoint_set_thread (struct breakpoint *b, int thread)
861 int old_thread = b->thread;
864 if (old_thread != thread)
865 observer_notify_breakpoint_modified (b);
868 /* Set the task for this breakpoint. If TASK is 0, make the
869 breakpoint work for any task. */
872 breakpoint_set_task (struct breakpoint *b, int task)
874 int old_task = b->task;
877 if (old_task != task)
878 observer_notify_breakpoint_modified (b);
882 check_tracepoint_command (char *line, void *closure)
884 struct breakpoint *b = closure;
886 validate_actionline (&line, b);
889 /* A structure used to pass information through
890 map_breakpoint_numbers. */
894 /* True if the command was typed at a tty. */
897 /* The breakpoint range spec. */
900 /* Non-NULL if the body of the commands are being read from this
901 already-parsed command. */
902 struct command_line *control;
904 /* The command lines read from the user, or NULL if they have not
906 struct counted_command_line *cmd;
909 /* A callback for map_breakpoint_numbers that sets the commands for
913 do_map_commands_command (struct breakpoint *b, void *data)
915 struct commands_info *info = data;
917 if (info->cmd == NULL)
919 struct command_line *l;
921 if (info->control != NULL)
922 l = copy_command_lines (info->control->body_list[0]);
925 struct cleanup *old_chain;
928 str = xstrprintf (_("Type commands for breakpoint(s) "
929 "%s, one per line."),
932 old_chain = make_cleanup (xfree, str);
934 l = read_command_lines (str,
937 ? check_tracepoint_command : 0),
940 do_cleanups (old_chain);
943 info->cmd = alloc_counted_command_line (l);
946 /* If a breakpoint was on the list more than once, we don't need to
948 if (b->commands != info->cmd)
950 validate_commands_for_breakpoint (b, info->cmd->commands);
951 incref_counted_command_line (info->cmd);
952 decref_counted_command_line (&b->commands);
953 b->commands = info->cmd;
954 breakpoints_changed ();
955 observer_notify_breakpoint_modified (b);
960 commands_command_1 (char *arg, int from_tty,
961 struct command_line *control)
963 struct cleanup *cleanups;
964 struct commands_info info;
966 info.from_tty = from_tty;
967 info.control = control;
969 /* If we read command lines from the user, then `info' will hold an
970 extra reference to the commands that we must clean up. */
971 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
973 if (arg == NULL || !*arg)
975 if (breakpoint_count - prev_breakpoint_count > 1)
976 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
978 else if (breakpoint_count > 0)
979 arg = xstrprintf ("%d", breakpoint_count);
982 /* So that we don't try to free the incoming non-NULL
983 argument in the cleanup below. Mapping breakpoint
984 numbers will fail in this case. */
989 /* The command loop has some static state, so we need to preserve
994 make_cleanup (xfree, arg);
998 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1000 if (info.cmd == NULL)
1001 error (_("No breakpoints specified."));
1003 do_cleanups (cleanups);
1007 commands_command (char *arg, int from_tty)
1009 commands_command_1 (arg, from_tty, NULL);
1012 /* Like commands_command, but instead of reading the commands from
1013 input stream, takes them from an already parsed command structure.
1015 This is used by cli-script.c to DTRT with breakpoint commands
1016 that are part of if and while bodies. */
1017 enum command_control_type
1018 commands_from_control_command (char *arg, struct command_line *cmd)
1020 commands_command_1 (arg, 0, cmd);
1021 return simple_control;
1024 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1027 bp_location_has_shadow (struct bp_location *bl)
1029 if (bl->loc_type != bp_loc_software_breakpoint)
1033 if (bl->target_info.shadow_len == 0)
1034 /* BL isn't valid, or doesn't shadow memory. */
1039 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1040 by replacing any memory breakpoints with their shadowed contents.
1042 The range of shadowed area by each bp_location is:
1043 bl->address - bp_location_placed_address_before_address_max
1044 up to bl->address + bp_location_shadow_len_after_address_max
1045 The range we were requested to resolve shadows for is:
1046 memaddr ... memaddr + len
1047 Thus the safe cutoff boundaries for performance optimization are
1048 memaddr + len <= (bl->address
1049 - bp_location_placed_address_before_address_max)
1051 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1054 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
1056 /* Left boundary, right boundary and median element of our binary
1058 unsigned bc_l, bc_r, bc;
1060 /* Find BC_L which is a leftmost element which may affect BUF
1061 content. It is safe to report lower value but a failure to
1062 report higher one. */
1065 bc_r = bp_location_count;
1066 while (bc_l + 1 < bc_r)
1068 struct bp_location *bl;
1070 bc = (bc_l + bc_r) / 2;
1071 bl = bp_location[bc];
1073 /* Check first BL->ADDRESS will not overflow due to the added
1074 constant. Then advance the left boundary only if we are sure
1075 the BC element can in no way affect the BUF content (MEMADDR
1076 to MEMADDR + LEN range).
1078 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1079 offset so that we cannot miss a breakpoint with its shadow
1080 range tail still reaching MEMADDR. */
1082 if ((bl->address + bp_location_shadow_len_after_address_max
1084 && (bl->address + bp_location_shadow_len_after_address_max
1091 /* Due to the binary search above, we need to make sure we pick the
1092 first location that's at BC_L's address. E.g., if there are
1093 multiple locations at the same address, BC_L may end up pointing
1094 at a duplicate location, and miss the "master"/"inserted"
1095 location. Say, given locations L1, L2 and L3 at addresses A and
1098 L1@A, L2@A, L3@B, ...
1100 BC_L could end up pointing at location L2, while the "master"
1101 location could be L1. Since the `loc->inserted' flag is only set
1102 on "master" locations, we'd forget to restore the shadow of L1
1105 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1108 /* Now do full processing of the found relevant range of elements. */
1110 for (bc = bc_l; bc < bp_location_count; bc++)
1112 struct bp_location *bl = bp_location[bc];
1113 CORE_ADDR bp_addr = 0;
1117 /* bp_location array has BL->OWNER always non-NULL. */
1118 if (bl->owner->type == bp_none)
1119 warning (_("reading through apparently deleted breakpoint #%d?"),
1122 /* Performance optimization: any further element can no longer affect BUF
1125 if (bl->address >= bp_location_placed_address_before_address_max
1126 && memaddr + len <= (bl->address
1127 - bp_location_placed_address_before_address_max))
1130 if (!bp_location_has_shadow (bl))
1132 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1133 current_program_space->aspace, 0))
1136 /* Addresses and length of the part of the breakpoint that
1138 bp_addr = bl->target_info.placed_address;
1139 bp_size = bl->target_info.shadow_len;
1141 if (bp_addr + bp_size <= memaddr)
1142 /* The breakpoint is entirely before the chunk of memory we
1146 if (bp_addr >= memaddr + len)
1147 /* The breakpoint is entirely after the chunk of memory we are
1151 /* Offset within shadow_contents. */
1152 if (bp_addr < memaddr)
1154 /* Only copy the second part of the breakpoint. */
1155 bp_size -= memaddr - bp_addr;
1156 bptoffset = memaddr - bp_addr;
1160 if (bp_addr + bp_size > memaddr + len)
1162 /* Only copy the first part of the breakpoint. */
1163 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1166 memcpy (buf + bp_addr - memaddr,
1167 bl->target_info.shadow_contents + bptoffset, bp_size);
1172 /* Return true if BPT is of any hardware watchpoint kind. */
1175 is_hardware_watchpoint (const struct breakpoint *bpt)
1177 return (bpt->type == bp_hardware_watchpoint
1178 || bpt->type == bp_read_watchpoint
1179 || bpt->type == bp_access_watchpoint);
1182 /* Return true if BPT is of any watchpoint kind, hardware or
1186 is_watchpoint (const struct breakpoint *bpt)
1188 return (is_hardware_watchpoint (bpt)
1189 || bpt->type == bp_watchpoint);
1192 /* Returns true if the current thread and its running state are safe
1193 to evaluate or update watchpoint B. Watchpoints on local
1194 expressions need to be evaluated in the context of the thread that
1195 was current when the watchpoint was created, and, that thread needs
1196 to be stopped to be able to select the correct frame context.
1197 Watchpoints on global expressions can be evaluated on any thread,
1198 and in any state. It is presently left to the target allowing
1199 memory accesses when threads are running. */
1202 watchpoint_in_thread_scope (struct watchpoint *b)
1204 return (ptid_equal (b->watchpoint_thread, null_ptid)
1205 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1206 && !is_executing (inferior_ptid)));
1209 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1210 associated bp_watchpoint_scope breakpoint. */
1213 watchpoint_del_at_next_stop (struct watchpoint *w)
1215 struct breakpoint *b = &w->base;
1217 if (b->related_breakpoint != b)
1219 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1220 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1221 b->related_breakpoint->disposition = disp_del_at_next_stop;
1222 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1223 b->related_breakpoint = b;
1225 b->disposition = disp_del_at_next_stop;
1228 /* Assuming that B is a watchpoint:
1229 - Reparse watchpoint expression, if REPARSE is non-zero
1230 - Evaluate expression and store the result in B->val
1231 - Evaluate the condition if there is one, and store the result
1233 - Update the list of values that must be watched in B->loc.
1235 If the watchpoint disposition is disp_del_at_next_stop, then do
1236 nothing. If this is local watchpoint that is out of scope, delete
1239 Even with `set breakpoint always-inserted on' the watchpoints are
1240 removed + inserted on each stop here. Normal breakpoints must
1241 never be removed because they might be missed by a running thread
1242 when debugging in non-stop mode. On the other hand, hardware
1243 watchpoints (is_hardware_watchpoint; processed here) are specific
1244 to each LWP since they are stored in each LWP's hardware debug
1245 registers. Therefore, such LWP must be stopped first in order to
1246 be able to modify its hardware watchpoints.
1248 Hardware watchpoints must be reset exactly once after being
1249 presented to the user. It cannot be done sooner, because it would
1250 reset the data used to present the watchpoint hit to the user. And
1251 it must not be done later because it could display the same single
1252 watchpoint hit during multiple GDB stops. Note that the latter is
1253 relevant only to the hardware watchpoint types bp_read_watchpoint
1254 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1255 not user-visible - its hit is suppressed if the memory content has
1258 The following constraints influence the location where we can reset
1259 hardware watchpoints:
1261 * target_stopped_by_watchpoint and target_stopped_data_address are
1262 called several times when GDB stops.
1265 * Multiple hardware watchpoints can be hit at the same time,
1266 causing GDB to stop. GDB only presents one hardware watchpoint
1267 hit at a time as the reason for stopping, and all the other hits
1268 are presented later, one after the other, each time the user
1269 requests the execution to be resumed. Execution is not resumed
1270 for the threads still having pending hit event stored in
1271 LWP_INFO->STATUS. While the watchpoint is already removed from
1272 the inferior on the first stop the thread hit event is kept being
1273 reported from its cached value by linux_nat_stopped_data_address
1274 until the real thread resume happens after the watchpoint gets
1275 presented and thus its LWP_INFO->STATUS gets reset.
1277 Therefore the hardware watchpoint hit can get safely reset on the
1278 watchpoint removal from inferior. */
1281 update_watchpoint (struct watchpoint *b, int reparse)
1283 int within_current_scope;
1284 struct frame_id saved_frame_id;
1287 /* If this is a local watchpoint, we only want to check if the
1288 watchpoint frame is in scope if the current thread is the thread
1289 that was used to create the watchpoint. */
1290 if (!watchpoint_in_thread_scope (b))
1293 if (b->base.disposition == disp_del_at_next_stop)
1298 /* Determine if the watchpoint is within scope. */
1299 if (b->exp_valid_block == NULL)
1300 within_current_scope = 1;
1303 struct frame_info *fi = get_current_frame ();
1304 struct gdbarch *frame_arch = get_frame_arch (fi);
1305 CORE_ADDR frame_pc = get_frame_pc (fi);
1307 /* If we're in a function epilogue, unwinding may not work
1308 properly, so do not attempt to recreate locations at this
1309 point. See similar comments in watchpoint_check. */
1310 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1313 /* Save the current frame's ID so we can restore it after
1314 evaluating the watchpoint expression on its own frame. */
1315 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1316 took a frame parameter, so that we didn't have to change the
1319 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1321 fi = frame_find_by_id (b->watchpoint_frame);
1322 within_current_scope = (fi != NULL);
1323 if (within_current_scope)
1327 /* We don't free locations. They are stored in the bp_location array
1328 and update_global_location_list will eventually delete them and
1329 remove breakpoints if needed. */
1332 if (within_current_scope && reparse)
1341 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1342 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1343 /* If the meaning of expression itself changed, the old value is
1344 no longer relevant. We don't want to report a watchpoint hit
1345 to the user when the old value and the new value may actually
1346 be completely different objects. */
1347 value_free (b->val);
1351 /* Note that unlike with breakpoints, the watchpoint's condition
1352 expression is stored in the breakpoint object, not in the
1353 locations (re)created below. */
1354 if (b->base.cond_string != NULL)
1356 if (b->cond_exp != NULL)
1358 xfree (b->cond_exp);
1362 s = b->base.cond_string;
1363 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1367 /* If we failed to parse the expression, for example because
1368 it refers to a global variable in a not-yet-loaded shared library,
1369 don't try to insert watchpoint. We don't automatically delete
1370 such watchpoint, though, since failure to parse expression
1371 is different from out-of-scope watchpoint. */
1372 if ( !target_has_execution)
1374 /* Without execution, memory can't change. No use to try and
1375 set watchpoint locations. The watchpoint will be reset when
1376 the target gains execution, through breakpoint_re_set. */
1378 else if (within_current_scope && b->exp)
1381 struct value *val_chain, *v, *result, *next;
1382 struct program_space *frame_pspace;
1384 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1386 /* Avoid setting b->val if it's already set. The meaning of
1387 b->val is 'the last value' user saw, and we should update
1388 it only if we reported that last value to user. As it
1389 happens, the code that reports it updates b->val directly.
1390 We don't keep track of the memory value for masked
1392 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1398 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1400 /* Look at each value on the value chain. */
1401 for (v = val_chain; v; v = value_next (v))
1403 /* If it's a memory location, and GDB actually needed
1404 its contents to evaluate the expression, then we
1405 must watch it. If the first value returned is
1406 still lazy, that means an error occurred reading it;
1407 watch it anyway in case it becomes readable. */
1408 if (VALUE_LVAL (v) == lval_memory
1409 && (v == val_chain || ! value_lazy (v)))
1411 struct type *vtype = check_typedef (value_type (v));
1413 /* We only watch structs and arrays if user asked
1414 for it explicitly, never if they just happen to
1415 appear in the middle of some value chain. */
1417 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1418 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1422 struct bp_location *loc, **tmp;
1424 addr = value_address (v);
1425 len = TYPE_LENGTH (value_type (v));
1427 if (b->base.type == bp_read_watchpoint)
1429 else if (b->base.type == bp_access_watchpoint)
1432 loc = allocate_bp_location (&b->base);
1433 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1436 loc->gdbarch = get_type_arch (value_type (v));
1438 loc->pspace = frame_pspace;
1439 loc->address = addr;
1441 loc->watchpoint_type = type;
1446 /* Change the type of breakpoint between hardware assisted or
1447 an ordinary watchpoint depending on the hardware support
1448 and free hardware slots. REPARSE is set when the inferior
1453 enum bp_loc_type loc_type;
1454 struct bp_location *bl;
1456 reg_cnt = can_use_hardware_watchpoint (val_chain);
1460 int i, target_resources_ok, other_type_used;
1462 /* Use an exact watchpoint when there's only one memory region to be
1463 watched, and only one debug register is needed to watch it. */
1464 b->exact = target_exact_watchpoints && reg_cnt == 1;
1466 /* We need to determine how many resources are already
1467 used for all other hardware watchpoints plus this one
1468 to see if we still have enough resources to also fit
1469 this watchpoint in as well. To guarantee the
1470 hw_watchpoint_used_count call below counts this
1471 watchpoint, make sure that it is marked as a hardware
1473 if (b->base.type == bp_watchpoint)
1474 b->base.type = bp_hardware_watchpoint;
1476 i = hw_watchpoint_used_count (b->base.type, &other_type_used);
1477 target_resources_ok = target_can_use_hardware_watchpoint
1478 (b->base.type, i, other_type_used);
1479 if (target_resources_ok <= 0)
1481 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1483 if (target_resources_ok == 0 && !sw_mode)
1484 error (_("Target does not support this type of "
1485 "hardware watchpoint."));
1486 else if (target_resources_ok < 0 && !sw_mode)
1487 error (_("There are not enough available hardware "
1488 "resources for this watchpoint."));
1490 b->base.type = bp_watchpoint;
1493 else if (!b->base.ops->works_in_software_mode (&b->base))
1494 error (_("Expression cannot be implemented with "
1495 "read/access watchpoint."));
1497 b->base.type = bp_watchpoint;
1499 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1500 : bp_loc_hardware_watchpoint);
1501 for (bl = b->base.loc; bl; bl = bl->next)
1502 bl->loc_type = loc_type;
1505 for (v = val_chain; v; v = next)
1507 next = value_next (v);
1512 /* If a software watchpoint is not watching any memory, then the
1513 above left it without any location set up. But,
1514 bpstat_stop_status requires a location to be able to report
1515 stops, so make sure there's at least a dummy one. */
1516 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1518 struct breakpoint *base = &b->base;
1519 base->loc = allocate_bp_location (base);
1520 base->loc->pspace = frame_pspace;
1521 base->loc->address = -1;
1522 base->loc->length = -1;
1523 base->loc->watchpoint_type = -1;
1526 else if (!within_current_scope)
1528 printf_filtered (_("\
1529 Watchpoint %d deleted because the program has left the block\n\
1530 in which its expression is valid.\n"),
1532 watchpoint_del_at_next_stop (b);
1535 /* Restore the selected frame. */
1537 select_frame (frame_find_by_id (saved_frame_id));
1541 /* Returns 1 iff breakpoint location should be
1542 inserted in the inferior. */
1544 should_be_inserted (struct bp_location *bl)
1546 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1549 if (bl->owner->disposition == disp_del_at_next_stop)
1552 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1555 /* This is set for example, when we're attached to the parent of a
1556 vfork, and have detached from the child. The child is running
1557 free, and we expect it to do an exec or exit, at which point the
1558 OS makes the parent schedulable again (and the target reports
1559 that the vfork is done). Until the child is done with the shared
1560 memory region, do not insert breakpoints in the parent, otherwise
1561 the child could still trip on the parent's breakpoints. Since
1562 the parent is blocked anyway, it won't miss any breakpoint. */
1563 if (bl->pspace->breakpoints_not_allowed)
1566 /* Tracepoints are inserted by the target at a time of its choosing,
1568 if (is_tracepoint (bl->owner))
1574 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1575 location. Any error messages are printed to TMP_ERROR_STREAM; and
1576 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1578 NOTE drow/2003-09-09: This routine could be broken down to an
1579 object-style method for each breakpoint or catchpoint type. */
1581 insert_bp_location (struct bp_location *bl,
1582 struct ui_file *tmp_error_stream,
1583 int *disabled_breaks,
1584 int *hw_breakpoint_error)
1588 if (!should_be_inserted (bl) || bl->inserted)
1591 /* Initialize the target-specific information. */
1592 memset (&bl->target_info, 0, sizeof (bl->target_info));
1593 bl->target_info.placed_address = bl->address;
1594 bl->target_info.placed_address_space = bl->pspace->aspace;
1595 bl->target_info.length = bl->length;
1597 if (bl->loc_type == bp_loc_software_breakpoint
1598 || bl->loc_type == bp_loc_hardware_breakpoint)
1600 if (bl->owner->type != bp_hardware_breakpoint)
1602 /* If the explicitly specified breakpoint type
1603 is not hardware breakpoint, check the memory map to see
1604 if the breakpoint address is in read only memory or not.
1606 Two important cases are:
1607 - location type is not hardware breakpoint, memory
1608 is readonly. We change the type of the location to
1609 hardware breakpoint.
1610 - location type is hardware breakpoint, memory is
1611 read-write. This means we've previously made the
1612 location hardware one, but then the memory map changed,
1615 When breakpoints are removed, remove_breakpoints will use
1616 location types we've just set here, the only possible
1617 problem is that memory map has changed during running
1618 program, but it's not going to work anyway with current
1620 struct mem_region *mr
1621 = lookup_mem_region (bl->target_info.placed_address);
1625 if (automatic_hardware_breakpoints)
1627 enum bp_loc_type new_type;
1629 if (mr->attrib.mode != MEM_RW)
1630 new_type = bp_loc_hardware_breakpoint;
1632 new_type = bp_loc_software_breakpoint;
1634 if (new_type != bl->loc_type)
1636 static int said = 0;
1638 bl->loc_type = new_type;
1641 fprintf_filtered (gdb_stdout,
1642 _("Note: automatically using "
1643 "hardware breakpoints for "
1644 "read-only addresses.\n"));
1649 else if (bl->loc_type == bp_loc_software_breakpoint
1650 && mr->attrib.mode != MEM_RW)
1651 warning (_("cannot set software breakpoint "
1652 "at readonly address %s"),
1653 paddress (bl->gdbarch, bl->address));
1657 /* First check to see if we have to handle an overlay. */
1658 if (overlay_debugging == ovly_off
1659 || bl->section == NULL
1660 || !(section_is_overlay (bl->section)))
1662 /* No overlay handling: just set the breakpoint. */
1664 val = bl->owner->ops->insert_location (bl);
1668 /* This breakpoint is in an overlay section.
1669 Shall we set a breakpoint at the LMA? */
1670 if (!overlay_events_enabled)
1672 /* Yes -- overlay event support is not active,
1673 so we must try to set a breakpoint at the LMA.
1674 This will not work for a hardware breakpoint. */
1675 if (bl->loc_type == bp_loc_hardware_breakpoint)
1676 warning (_("hardware breakpoint %d not supported in overlay!"),
1680 CORE_ADDR addr = overlay_unmapped_address (bl->address,
1682 /* Set a software (trap) breakpoint at the LMA. */
1683 bl->overlay_target_info = bl->target_info;
1684 bl->overlay_target_info.placed_address = addr;
1685 val = target_insert_breakpoint (bl->gdbarch,
1686 &bl->overlay_target_info);
1688 fprintf_unfiltered (tmp_error_stream,
1689 "Overlay breakpoint %d "
1690 "failed: in ROM?\n",
1694 /* Shall we set a breakpoint at the VMA? */
1695 if (section_is_mapped (bl->section))
1697 /* Yes. This overlay section is mapped into memory. */
1698 val = bl->owner->ops->insert_location (bl);
1702 /* No. This breakpoint will not be inserted.
1703 No error, but do not mark the bp as 'inserted'. */
1710 /* Can't set the breakpoint. */
1711 if (solib_name_from_address (bl->pspace, bl->address))
1713 /* See also: disable_breakpoints_in_shlibs. */
1715 bl->shlib_disabled = 1;
1716 observer_notify_breakpoint_modified (bl->owner);
1717 if (!*disabled_breaks)
1719 fprintf_unfiltered (tmp_error_stream,
1720 "Cannot insert breakpoint %d.\n",
1722 fprintf_unfiltered (tmp_error_stream,
1723 "Temporarily disabling shared "
1724 "library breakpoints:\n");
1726 *disabled_breaks = 1;
1727 fprintf_unfiltered (tmp_error_stream,
1728 "breakpoint #%d\n", bl->owner->number);
1732 if (bl->loc_type == bp_loc_hardware_breakpoint)
1734 *hw_breakpoint_error = 1;
1735 fprintf_unfiltered (tmp_error_stream,
1736 "Cannot insert hardware "
1742 fprintf_unfiltered (tmp_error_stream,
1743 "Cannot insert breakpoint %d.\n",
1745 fprintf_filtered (tmp_error_stream,
1746 "Error accessing memory address ");
1747 fputs_filtered (paddress (bl->gdbarch, bl->address),
1749 fprintf_filtered (tmp_error_stream, ": %s.\n",
1750 safe_strerror (val));
1761 else if (bl->loc_type == bp_loc_hardware_watchpoint
1762 /* NOTE drow/2003-09-08: This state only exists for removing
1763 watchpoints. It's not clear that it's necessary... */
1764 && bl->owner->disposition != disp_del_at_next_stop)
1766 gdb_assert (bl->owner->ops != NULL
1767 && bl->owner->ops->insert_location != NULL);
1769 val = bl->owner->ops->insert_location (bl);
1771 /* If trying to set a read-watchpoint, and it turns out it's not
1772 supported, try emulating one with an access watchpoint. */
1773 if (val == 1 && bl->watchpoint_type == hw_read)
1775 struct bp_location *loc, **loc_temp;
1777 /* But don't try to insert it, if there's already another
1778 hw_access location that would be considered a duplicate
1780 ALL_BP_LOCATIONS (loc, loc_temp)
1782 && loc->watchpoint_type == hw_access
1783 && watchpoint_locations_match (bl, loc))
1787 bl->target_info = loc->target_info;
1788 bl->watchpoint_type = hw_access;
1795 bl->watchpoint_type = hw_access;
1796 val = bl->owner->ops->insert_location (bl);
1799 /* Back to the original value. */
1800 bl->watchpoint_type = hw_read;
1804 bl->inserted = (val == 0);
1807 else if (bl->owner->type == bp_catchpoint)
1809 gdb_assert (bl->owner->ops != NULL
1810 && bl->owner->ops->insert_location != NULL);
1812 val = bl->owner->ops->insert_location (bl);
1815 bl->owner->enable_state = bp_disabled;
1819 Error inserting catchpoint %d: Your system does not support this type\n\
1820 of catchpoint."), bl->owner->number);
1822 warning (_("Error inserting catchpoint %d."), bl->owner->number);
1825 bl->inserted = (val == 0);
1827 /* We've already printed an error message if there was a problem
1828 inserting this catchpoint, and we've disabled the catchpoint,
1829 so just return success. */
1836 /* This function is called when program space PSPACE is about to be
1837 deleted. It takes care of updating breakpoints to not reference
1841 breakpoint_program_space_exit (struct program_space *pspace)
1843 struct breakpoint *b, *b_temp;
1844 struct bp_location *loc, **loc_temp;
1846 /* Remove any breakpoint that was set through this program space. */
1847 ALL_BREAKPOINTS_SAFE (b, b_temp)
1849 if (b->pspace == pspace)
1850 delete_breakpoint (b);
1853 /* Breakpoints set through other program spaces could have locations
1854 bound to PSPACE as well. Remove those. */
1855 ALL_BP_LOCATIONS (loc, loc_temp)
1857 struct bp_location *tmp;
1859 if (loc->pspace == pspace)
1861 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1862 if (loc->owner->loc == loc)
1863 loc->owner->loc = loc->next;
1865 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1866 if (tmp->next == loc)
1868 tmp->next = loc->next;
1874 /* Now update the global location list to permanently delete the
1875 removed locations above. */
1876 update_global_location_list (0);
1879 /* Make sure all breakpoints are inserted in inferior.
1880 Throws exception on any error.
1881 A breakpoint that is already inserted won't be inserted
1882 again, so calling this function twice is safe. */
1884 insert_breakpoints (void)
1886 struct breakpoint *bpt;
1888 ALL_BREAKPOINTS (bpt)
1889 if (is_hardware_watchpoint (bpt))
1891 struct watchpoint *w = (struct watchpoint *) bpt;
1893 update_watchpoint (w, 0 /* don't reparse. */);
1896 update_global_location_list (1);
1898 /* update_global_location_list does not insert breakpoints when
1899 always_inserted_mode is not enabled. Explicitly insert them
1901 if (!breakpoints_always_inserted_mode ())
1902 insert_breakpoint_locations ();
1905 /* insert_breakpoints is used when starting or continuing the program.
1906 remove_breakpoints is used when the program stops.
1907 Both return zero if successful,
1908 or an `errno' value if could not write the inferior. */
1911 insert_breakpoint_locations (void)
1913 struct breakpoint *bpt;
1914 struct bp_location *bl, **blp_tmp;
1917 int disabled_breaks = 0;
1918 int hw_breakpoint_error = 0;
1920 struct ui_file *tmp_error_stream = mem_fileopen ();
1921 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1923 /* Explicitly mark the warning -- this will only be printed if
1924 there was an error. */
1925 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1927 save_current_space_and_thread ();
1929 ALL_BP_LOCATIONS (bl, blp_tmp)
1931 if (!should_be_inserted (bl) || bl->inserted)
1934 /* There is no point inserting thread-specific breakpoints if
1935 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1936 has BL->OWNER always non-NULL. */
1937 if (bl->owner->thread != -1
1938 && !valid_thread_id (bl->owner->thread))
1941 switch_to_program_space_and_thread (bl->pspace);
1943 /* For targets that support global breakpoints, there's no need
1944 to select an inferior to insert breakpoint to. In fact, even
1945 if we aren't attached to any process yet, we should still
1946 insert breakpoints. */
1947 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1948 && ptid_equal (inferior_ptid, null_ptid))
1951 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
1952 &hw_breakpoint_error);
1957 /* If we failed to insert all locations of a watchpoint, remove
1958 them, as half-inserted watchpoint is of limited use. */
1959 ALL_BREAKPOINTS (bpt)
1961 int some_failed = 0;
1962 struct bp_location *loc;
1964 if (!is_hardware_watchpoint (bpt))
1967 if (!breakpoint_enabled (bpt))
1970 if (bpt->disposition == disp_del_at_next_stop)
1973 for (loc = bpt->loc; loc; loc = loc->next)
1974 if (!loc->inserted && should_be_inserted (loc))
1981 for (loc = bpt->loc; loc; loc = loc->next)
1983 remove_breakpoint (loc, mark_uninserted);
1985 hw_breakpoint_error = 1;
1986 fprintf_unfiltered (tmp_error_stream,
1987 "Could not insert hardware watchpoint %d.\n",
1995 /* If a hardware breakpoint or watchpoint was inserted, add a
1996 message about possibly exhausted resources. */
1997 if (hw_breakpoint_error)
1999 fprintf_unfiltered (tmp_error_stream,
2000 "Could not insert hardware breakpoints:\n\
2001 You may have requested too many hardware breakpoints/watchpoints.\n");
2003 target_terminal_ours_for_output ();
2004 error_stream (tmp_error_stream);
2007 do_cleanups (cleanups);
2011 remove_breakpoints (void)
2013 struct bp_location *bl, **blp_tmp;
2016 ALL_BP_LOCATIONS (bl, blp_tmp)
2019 val |= remove_breakpoint (bl, mark_uninserted);
2024 /* Remove breakpoints of process PID. */
2027 remove_breakpoints_pid (int pid)
2029 struct bp_location *bl, **blp_tmp;
2031 struct inferior *inf = find_inferior_pid (pid);
2033 ALL_BP_LOCATIONS (bl, blp_tmp)
2035 if (bl->pspace != inf->pspace)
2040 val = remove_breakpoint (bl, mark_uninserted);
2049 reattach_breakpoints (int pid)
2051 struct cleanup *old_chain;
2052 struct bp_location *bl, **blp_tmp;
2054 struct ui_file *tmp_error_stream;
2055 int dummy1 = 0, dummy2 = 0;
2056 struct inferior *inf;
2057 struct thread_info *tp;
2059 tp = any_live_thread_of_process (pid);
2063 inf = find_inferior_pid (pid);
2064 old_chain = save_inferior_ptid ();
2066 inferior_ptid = tp->ptid;
2068 tmp_error_stream = mem_fileopen ();
2069 make_cleanup_ui_file_delete (tmp_error_stream);
2071 ALL_BP_LOCATIONS (bl, blp_tmp)
2073 if (bl->pspace != inf->pspace)
2079 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2082 do_cleanups (old_chain);
2087 do_cleanups (old_chain);
2091 static int internal_breakpoint_number = -1;
2093 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2094 If INTERNAL is non-zero, the breakpoint number will be populated
2095 from internal_breakpoint_number and that variable decremented.
2096 Otherwise the breakpoint number will be populated from
2097 breakpoint_count and that value incremented. Internal breakpoints
2098 do not set the internal var bpnum. */
2100 set_breakpoint_number (int internal, struct breakpoint *b)
2103 b->number = internal_breakpoint_number--;
2106 set_breakpoint_count (breakpoint_count + 1);
2107 b->number = breakpoint_count;
2111 static struct breakpoint *
2112 create_internal_breakpoint (struct gdbarch *gdbarch,
2113 CORE_ADDR address, enum bptype type,
2114 const struct breakpoint_ops *ops)
2116 struct symtab_and_line sal;
2117 struct breakpoint *b;
2119 init_sal (&sal); /* Initialize to zeroes. */
2122 sal.section = find_pc_overlay (sal.pc);
2123 sal.pspace = current_program_space;
2125 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2126 b->number = internal_breakpoint_number--;
2127 b->disposition = disp_donttouch;
2132 static const char *const longjmp_names[] =
2134 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2136 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2138 /* Per-objfile data private to breakpoint.c. */
2139 struct breakpoint_objfile_data
2141 /* Minimal symbol for "_ovly_debug_event" (if any). */
2142 struct minimal_symbol *overlay_msym;
2144 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2145 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2147 /* Minimal symbol for "std::terminate()" (if any). */
2148 struct minimal_symbol *terminate_msym;
2150 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2151 struct minimal_symbol *exception_msym;
2154 static const struct objfile_data *breakpoint_objfile_key;
2156 /* Minimal symbol not found sentinel. */
2157 static struct minimal_symbol msym_not_found;
2159 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2162 msym_not_found_p (const struct minimal_symbol *msym)
2164 return msym == &msym_not_found;
2167 /* Return per-objfile data needed by breakpoint.c.
2168 Allocate the data if necessary. */
2170 static struct breakpoint_objfile_data *
2171 get_breakpoint_objfile_data (struct objfile *objfile)
2173 struct breakpoint_objfile_data *bp_objfile_data;
2175 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2176 if (bp_objfile_data == NULL)
2178 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2179 sizeof (*bp_objfile_data));
2181 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2182 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2184 return bp_objfile_data;
2188 create_overlay_event_breakpoint (void)
2190 struct objfile *objfile;
2191 const char *const func_name = "_ovly_debug_event";
2193 ALL_OBJFILES (objfile)
2195 struct breakpoint *b;
2196 struct breakpoint_objfile_data *bp_objfile_data;
2199 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2201 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2204 if (bp_objfile_data->overlay_msym == NULL)
2206 struct minimal_symbol *m;
2208 m = lookup_minimal_symbol_text (func_name, objfile);
2211 /* Avoid future lookups in this objfile. */
2212 bp_objfile_data->overlay_msym = &msym_not_found;
2215 bp_objfile_data->overlay_msym = m;
2218 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2219 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2221 &internal_breakpoint_ops);
2222 b->addr_string = xstrdup (func_name);
2224 if (overlay_debugging == ovly_auto)
2226 b->enable_state = bp_enabled;
2227 overlay_events_enabled = 1;
2231 b->enable_state = bp_disabled;
2232 overlay_events_enabled = 0;
2235 update_global_location_list (1);
2239 create_longjmp_master_breakpoint (void)
2241 struct program_space *pspace;
2242 struct cleanup *old_chain;
2244 old_chain = save_current_program_space ();
2246 ALL_PSPACES (pspace)
2248 struct objfile *objfile;
2250 set_current_program_space (pspace);
2252 ALL_OBJFILES (objfile)
2255 struct gdbarch *gdbarch;
2256 struct breakpoint_objfile_data *bp_objfile_data;
2258 gdbarch = get_objfile_arch (objfile);
2259 if (!gdbarch_get_longjmp_target_p (gdbarch))
2262 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2264 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2266 struct breakpoint *b;
2267 const char *func_name;
2270 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2273 func_name = longjmp_names[i];
2274 if (bp_objfile_data->longjmp_msym[i] == NULL)
2276 struct minimal_symbol *m;
2278 m = lookup_minimal_symbol_text (func_name, objfile);
2281 /* Prevent future lookups in this objfile. */
2282 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2285 bp_objfile_data->longjmp_msym[i] = m;
2288 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2289 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2290 &internal_breakpoint_ops);
2291 b->addr_string = xstrdup (func_name);
2292 b->enable_state = bp_disabled;
2296 update_global_location_list (1);
2298 do_cleanups (old_chain);
2301 /* Create a master std::terminate breakpoint. */
2303 create_std_terminate_master_breakpoint (void)
2305 struct program_space *pspace;
2306 struct cleanup *old_chain;
2307 const char *const func_name = "std::terminate()";
2309 old_chain = save_current_program_space ();
2311 ALL_PSPACES (pspace)
2313 struct objfile *objfile;
2316 set_current_program_space (pspace);
2318 ALL_OBJFILES (objfile)
2320 struct breakpoint *b;
2321 struct breakpoint_objfile_data *bp_objfile_data;
2323 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2325 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2328 if (bp_objfile_data->terminate_msym == NULL)
2330 struct minimal_symbol *m;
2332 m = lookup_minimal_symbol (func_name, NULL, objfile);
2333 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2334 && MSYMBOL_TYPE (m) != mst_file_text))
2336 /* Prevent future lookups in this objfile. */
2337 bp_objfile_data->terminate_msym = &msym_not_found;
2340 bp_objfile_data->terminate_msym = m;
2343 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2344 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2345 bp_std_terminate_master,
2346 &internal_breakpoint_ops);
2347 b->addr_string = xstrdup (func_name);
2348 b->enable_state = bp_disabled;
2352 update_global_location_list (1);
2354 do_cleanups (old_chain);
2357 /* Install a master breakpoint on the unwinder's debug hook. */
2360 create_exception_master_breakpoint (void)
2362 struct objfile *objfile;
2363 const char *const func_name = "_Unwind_DebugHook";
2365 ALL_OBJFILES (objfile)
2367 struct breakpoint *b;
2368 struct gdbarch *gdbarch;
2369 struct breakpoint_objfile_data *bp_objfile_data;
2372 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2374 if (msym_not_found_p (bp_objfile_data->exception_msym))
2377 gdbarch = get_objfile_arch (objfile);
2379 if (bp_objfile_data->exception_msym == NULL)
2381 struct minimal_symbol *debug_hook;
2383 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
2384 if (debug_hook == NULL)
2386 bp_objfile_data->exception_msym = &msym_not_found;
2390 bp_objfile_data->exception_msym = debug_hook;
2393 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
2394 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2396 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
2397 &internal_breakpoint_ops);
2398 b->addr_string = xstrdup (func_name);
2399 b->enable_state = bp_disabled;
2402 update_global_location_list (1);
2406 update_breakpoints_after_exec (void)
2408 struct breakpoint *b, *b_tmp;
2409 struct bp_location *bploc, **bplocp_tmp;
2411 /* We're about to delete breakpoints from GDB's lists. If the
2412 INSERTED flag is true, GDB will try to lift the breakpoints by
2413 writing the breakpoints' "shadow contents" back into memory. The
2414 "shadow contents" are NOT valid after an exec, so GDB should not
2415 do that. Instead, the target is responsible from marking
2416 breakpoints out as soon as it detects an exec. We don't do that
2417 here instead, because there may be other attempts to delete
2418 breakpoints after detecting an exec and before reaching here. */
2419 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2420 if (bploc->pspace == current_program_space)
2421 gdb_assert (!bploc->inserted);
2423 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2425 if (b->pspace != current_program_space)
2428 /* Solib breakpoints must be explicitly reset after an exec(). */
2429 if (b->type == bp_shlib_event)
2431 delete_breakpoint (b);
2435 /* JIT breakpoints must be explicitly reset after an exec(). */
2436 if (b->type == bp_jit_event)
2438 delete_breakpoint (b);
2442 /* Thread event breakpoints must be set anew after an exec(),
2443 as must overlay event and longjmp master breakpoints. */
2444 if (b->type == bp_thread_event || b->type == bp_overlay_event
2445 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
2446 || b->type == bp_exception_master)
2448 delete_breakpoint (b);
2452 /* Step-resume breakpoints are meaningless after an exec(). */
2453 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
2455 delete_breakpoint (b);
2459 /* Longjmp and longjmp-resume breakpoints are also meaningless
2461 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
2462 || b->type == bp_exception || b->type == bp_exception_resume)
2464 delete_breakpoint (b);
2468 if (b->type == bp_catchpoint)
2470 /* For now, none of the bp_catchpoint breakpoints need to
2471 do anything at this point. In the future, if some of
2472 the catchpoints need to something, we will need to add
2473 a new method, and call this method from here. */
2477 /* bp_finish is a special case. The only way we ought to be able
2478 to see one of these when an exec() has happened, is if the user
2479 caught a vfork, and then said "finish". Ordinarily a finish just
2480 carries them to the call-site of the current callee, by setting
2481 a temporary bp there and resuming. But in this case, the finish
2482 will carry them entirely through the vfork & exec.
2484 We don't want to allow a bp_finish to remain inserted now. But
2485 we can't safely delete it, 'cause finish_command has a handle to
2486 the bp on a bpstat, and will later want to delete it. There's a
2487 chance (and I've seen it happen) that if we delete the bp_finish
2488 here, that its storage will get reused by the time finish_command
2489 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2490 We really must allow finish_command to delete a bp_finish.
2492 In the absence of a general solution for the "how do we know
2493 it's safe to delete something others may have handles to?"
2494 problem, what we'll do here is just uninsert the bp_finish, and
2495 let finish_command delete it.
2497 (We know the bp_finish is "doomed" in the sense that it's
2498 momentary, and will be deleted as soon as finish_command sees
2499 the inferior stopped. So it doesn't matter that the bp's
2500 address is probably bogus in the new a.out, unlike e.g., the
2501 solib breakpoints.) */
2503 if (b->type == bp_finish)
2508 /* Without a symbolic address, we have little hope of the
2509 pre-exec() address meaning the same thing in the post-exec()
2511 if (b->addr_string == NULL)
2513 delete_breakpoint (b);
2517 /* FIXME what about longjmp breakpoints? Re-create them here? */
2518 create_overlay_event_breakpoint ();
2519 create_longjmp_master_breakpoint ();
2520 create_std_terminate_master_breakpoint ();
2521 create_exception_master_breakpoint ();
2525 detach_breakpoints (int pid)
2527 struct bp_location *bl, **blp_tmp;
2529 struct cleanup *old_chain = save_inferior_ptid ();
2530 struct inferior *inf = current_inferior ();
2532 if (pid == PIDGET (inferior_ptid))
2533 error (_("Cannot detach breakpoints of inferior_ptid"));
2535 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2536 inferior_ptid = pid_to_ptid (pid);
2537 ALL_BP_LOCATIONS (bl, blp_tmp)
2539 if (bl->pspace != inf->pspace)
2543 val |= remove_breakpoint_1 (bl, mark_inserted);
2546 /* Detach single-step breakpoints as well. */
2547 detach_single_step_breakpoints ();
2549 do_cleanups (old_chain);
2553 /* Remove the breakpoint location BL from the current address space.
2554 Note that this is used to detach breakpoints from a child fork.
2555 When we get here, the child isn't in the inferior list, and neither
2556 do we have objects to represent its address space --- we should
2557 *not* look at bl->pspace->aspace here. */
2560 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
2564 /* BL is never in moribund_locations by our callers. */
2565 gdb_assert (bl->owner != NULL);
2567 if (bl->owner->enable_state == bp_permanent)
2568 /* Permanent breakpoints cannot be inserted or removed. */
2571 /* The type of none suggests that owner is actually deleted.
2572 This should not ever happen. */
2573 gdb_assert (bl->owner->type != bp_none);
2575 if (bl->loc_type == bp_loc_software_breakpoint
2576 || bl->loc_type == bp_loc_hardware_breakpoint)
2578 /* "Normal" instruction breakpoint: either the standard
2579 trap-instruction bp (bp_breakpoint), or a
2580 bp_hardware_breakpoint. */
2582 /* First check to see if we have to handle an overlay. */
2583 if (overlay_debugging == ovly_off
2584 || bl->section == NULL
2585 || !(section_is_overlay (bl->section)))
2587 /* No overlay handling: just remove the breakpoint. */
2588 val = bl->owner->ops->remove_location (bl);
2592 /* This breakpoint is in an overlay section.
2593 Did we set a breakpoint at the LMA? */
2594 if (!overlay_events_enabled)
2596 /* Yes -- overlay event support is not active, so we
2597 should have set a breakpoint at the LMA. Remove it.
2599 /* Ignore any failures: if the LMA is in ROM, we will
2600 have already warned when we failed to insert it. */
2601 if (bl->loc_type == bp_loc_hardware_breakpoint)
2602 target_remove_hw_breakpoint (bl->gdbarch,
2603 &bl->overlay_target_info);
2605 target_remove_breakpoint (bl->gdbarch,
2606 &bl->overlay_target_info);
2608 /* Did we set a breakpoint at the VMA?
2609 If so, we will have marked the breakpoint 'inserted'. */
2612 /* Yes -- remove it. Previously we did not bother to
2613 remove the breakpoint if the section had been
2614 unmapped, but let's not rely on that being safe. We
2615 don't know what the overlay manager might do. */
2617 /* However, we should remove *software* breakpoints only
2618 if the section is still mapped, or else we overwrite
2619 wrong code with the saved shadow contents. */
2620 if (bl->loc_type == bp_loc_hardware_breakpoint
2621 || section_is_mapped (bl->section))
2622 val = bl->owner->ops->remove_location (bl);
2628 /* No -- not inserted, so no need to remove. No error. */
2633 /* In some cases, we might not be able to remove a breakpoint
2634 in a shared library that has already been removed, but we
2635 have not yet processed the shlib unload event. */
2636 if (val && solib_name_from_address (bl->pspace, bl->address))
2641 bl->inserted = (is == mark_inserted);
2643 else if (bl->loc_type == bp_loc_hardware_watchpoint)
2645 gdb_assert (bl->owner->ops != NULL
2646 && bl->owner->ops->remove_location != NULL);
2648 bl->inserted = (is == mark_inserted);
2649 bl->owner->ops->remove_location (bl);
2651 /* Failure to remove any of the hardware watchpoints comes here. */
2652 if ((is == mark_uninserted) && (bl->inserted))
2653 warning (_("Could not remove hardware watchpoint %d."),
2656 else if (bl->owner->type == bp_catchpoint
2657 && breakpoint_enabled (bl->owner)
2660 gdb_assert (bl->owner->ops != NULL
2661 && bl->owner->ops->remove_location != NULL);
2663 val = bl->owner->ops->remove_location (bl);
2667 bl->inserted = (is == mark_inserted);
2674 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
2677 struct cleanup *old_chain;
2679 /* BL is never in moribund_locations by our callers. */
2680 gdb_assert (bl->owner != NULL);
2682 if (bl->owner->enable_state == bp_permanent)
2683 /* Permanent breakpoints cannot be inserted or removed. */
2686 /* The type of none suggests that owner is actually deleted.
2687 This should not ever happen. */
2688 gdb_assert (bl->owner->type != bp_none);
2690 old_chain = save_current_space_and_thread ();
2692 switch_to_program_space_and_thread (bl->pspace);
2694 ret = remove_breakpoint_1 (bl, is);
2696 do_cleanups (old_chain);
2700 /* Clear the "inserted" flag in all breakpoints. */
2703 mark_breakpoints_out (void)
2705 struct bp_location *bl, **blp_tmp;
2707 ALL_BP_LOCATIONS (bl, blp_tmp)
2708 if (bl->pspace == current_program_space)
2712 /* Clear the "inserted" flag in all breakpoints and delete any
2713 breakpoints which should go away between runs of the program.
2715 Plus other such housekeeping that has to be done for breakpoints
2718 Note: this function gets called at the end of a run (by
2719 generic_mourn_inferior) and when a run begins (by
2720 init_wait_for_inferior). */
2725 breakpoint_init_inferior (enum inf_context context)
2727 struct breakpoint *b, *b_tmp;
2728 struct bp_location *bl, **blp_tmp;
2730 struct program_space *pspace = current_program_space;
2732 /* If breakpoint locations are shared across processes, then there's
2734 if (gdbarch_has_global_breakpoints (target_gdbarch))
2737 ALL_BP_LOCATIONS (bl, blp_tmp)
2739 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2740 if (bl->pspace == pspace
2741 && bl->owner->enable_state != bp_permanent)
2745 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2747 if (b->loc && b->loc->pspace != pspace)
2754 /* If the call dummy breakpoint is at the entry point it will
2755 cause problems when the inferior is rerun, so we better get
2758 case bp_watchpoint_scope:
2760 /* Also get rid of scope breakpoints. */
2762 case bp_shlib_event:
2764 /* Also remove solib event breakpoints. Their addresses may
2765 have changed since the last time we ran the program.
2766 Actually we may now be debugging against different target;
2767 and so the solib backend that installed this breakpoint may
2768 not be used in by the target. E.g.,
2770 (gdb) file prog-linux
2771 (gdb) run # native linux target
2774 (gdb) file prog-win.exe
2775 (gdb) tar rem :9999 # remote Windows gdbserver.
2778 delete_breakpoint (b);
2782 case bp_hardware_watchpoint:
2783 case bp_read_watchpoint:
2784 case bp_access_watchpoint:
2786 struct watchpoint *w = (struct watchpoint *) b;
2788 /* Likewise for watchpoints on local expressions. */
2789 if (w->exp_valid_block != NULL)
2790 delete_breakpoint (b);
2791 else if (context == inf_starting)
2793 /* Reset val field to force reread of starting value in
2794 insert_breakpoints. */
2796 value_free (w->val);
2807 /* Get rid of the moribund locations. */
2808 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
2809 decref_bp_location (&bl);
2810 VEC_free (bp_location_p, moribund_locations);
2813 /* These functions concern about actual breakpoints inserted in the
2814 target --- to e.g. check if we need to do decr_pc adjustment or if
2815 we need to hop over the bkpt --- so we check for address space
2816 match, not program space. */
2818 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2819 exists at PC. It returns ordinary_breakpoint_here if it's an
2820 ordinary breakpoint, or permanent_breakpoint_here if it's a
2821 permanent breakpoint.
2822 - When continuing from a location with an ordinary breakpoint, we
2823 actually single step once before calling insert_breakpoints.
2824 - When continuing from a location with a permanent breakpoint, we
2825 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2826 the target, to advance the PC past the breakpoint. */
2828 enum breakpoint_here
2829 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2831 struct bp_location *bl, **blp_tmp;
2832 int any_breakpoint_here = 0;
2834 ALL_BP_LOCATIONS (bl, blp_tmp)
2836 if (bl->loc_type != bp_loc_software_breakpoint
2837 && bl->loc_type != bp_loc_hardware_breakpoint)
2840 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2841 if ((breakpoint_enabled (bl->owner)
2842 || bl->owner->enable_state == bp_permanent)
2843 && breakpoint_location_address_match (bl, aspace, pc))
2845 if (overlay_debugging
2846 && section_is_overlay (bl->section)
2847 && !section_is_mapped (bl->section))
2848 continue; /* unmapped overlay -- can't be a match */
2849 else if (bl->owner->enable_state == bp_permanent)
2850 return permanent_breakpoint_here;
2852 any_breakpoint_here = 1;
2856 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2859 /* Return true if there's a moribund breakpoint at PC. */
2862 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2864 struct bp_location *loc;
2867 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2868 if (breakpoint_location_address_match (loc, aspace, pc))
2874 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2875 inserted using regular breakpoint_chain / bp_location array
2876 mechanism. This does not check for single-step breakpoints, which
2877 are inserted and removed using direct target manipulation. */
2880 regular_breakpoint_inserted_here_p (struct address_space *aspace,
2883 struct bp_location *bl, **blp_tmp;
2885 ALL_BP_LOCATIONS (bl, blp_tmp)
2887 if (bl->loc_type != bp_loc_software_breakpoint
2888 && bl->loc_type != bp_loc_hardware_breakpoint)
2892 && breakpoint_location_address_match (bl, aspace, pc))
2894 if (overlay_debugging
2895 && section_is_overlay (bl->section)
2896 && !section_is_mapped (bl->section))
2897 continue; /* unmapped overlay -- can't be a match */
2905 /* Returns non-zero iff there's either regular breakpoint
2906 or a single step breakpoint inserted at PC. */
2909 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2911 if (regular_breakpoint_inserted_here_p (aspace, pc))
2914 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2920 /* This function returns non-zero iff there is a software breakpoint
2924 software_breakpoint_inserted_here_p (struct address_space *aspace,
2927 struct bp_location *bl, **blp_tmp;
2929 ALL_BP_LOCATIONS (bl, blp_tmp)
2931 if (bl->loc_type != bp_loc_software_breakpoint)
2935 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2938 if (overlay_debugging
2939 && section_is_overlay (bl->section)
2940 && !section_is_mapped (bl->section))
2941 continue; /* unmapped overlay -- can't be a match */
2947 /* Also check for software single-step breakpoints. */
2948 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2955 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2956 CORE_ADDR addr, ULONGEST len)
2958 struct breakpoint *bpt;
2960 ALL_BREAKPOINTS (bpt)
2962 struct bp_location *loc;
2964 if (bpt->type != bp_hardware_watchpoint
2965 && bpt->type != bp_access_watchpoint)
2968 if (!breakpoint_enabled (bpt))
2971 for (loc = bpt->loc; loc; loc = loc->next)
2972 if (loc->pspace->aspace == aspace && loc->inserted)
2976 /* Check for intersection. */
2977 l = max (loc->address, addr);
2978 h = min (loc->address + loc->length, addr + len);
2986 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2987 PC is valid for process/thread PTID. */
2990 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2993 struct bp_location *bl, **blp_tmp;
2994 /* The thread and task IDs associated to PTID, computed lazily. */
2998 ALL_BP_LOCATIONS (bl, blp_tmp)
3000 if (bl->loc_type != bp_loc_software_breakpoint
3001 && bl->loc_type != bp_loc_hardware_breakpoint)
3004 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3005 if (!breakpoint_enabled (bl->owner)
3006 && bl->owner->enable_state != bp_permanent)
3009 if (!breakpoint_location_address_match (bl, aspace, pc))
3012 if (bl->owner->thread != -1)
3014 /* This is a thread-specific breakpoint. Check that ptid
3015 matches that thread. If thread hasn't been computed yet,
3016 it is now time to do so. */
3018 thread = pid_to_thread_id (ptid);
3019 if (bl->owner->thread != thread)
3023 if (bl->owner->task != 0)
3025 /* This is a task-specific breakpoint. Check that ptid
3026 matches that task. If task hasn't been computed yet,
3027 it is now time to do so. */
3029 task = ada_get_task_number (ptid);
3030 if (bl->owner->task != task)
3034 if (overlay_debugging
3035 && section_is_overlay (bl->section)
3036 && !section_is_mapped (bl->section))
3037 continue; /* unmapped overlay -- can't be a match */
3046 /* bpstat stuff. External routines' interfaces are documented
3050 ep_is_catchpoint (struct breakpoint *ep)
3052 return (ep->type == bp_catchpoint);
3055 /* Frees any storage that is part of a bpstat. Does not walk the
3059 bpstat_free (bpstat bs)
3061 if (bs->old_val != NULL)
3062 value_free (bs->old_val);
3063 decref_counted_command_line (&bs->commands);
3064 decref_bp_location (&bs->bp_location_at);
3068 /* Clear a bpstat so that it says we are not at any breakpoint.
3069 Also free any storage that is part of a bpstat. */
3072 bpstat_clear (bpstat *bsp)
3089 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3090 is part of the bpstat is copied as well. */
3093 bpstat_copy (bpstat bs)
3097 bpstat retval = NULL;
3102 for (; bs != NULL; bs = bs->next)
3104 tmp = (bpstat) xmalloc (sizeof (*tmp));
3105 memcpy (tmp, bs, sizeof (*tmp));
3106 incref_counted_command_line (tmp->commands);
3107 incref_bp_location (tmp->bp_location_at);
3108 if (bs->old_val != NULL)
3110 tmp->old_val = value_copy (bs->old_val);
3111 release_value (tmp->old_val);
3115 /* This is the first thing in the chain. */
3125 /* Find the bpstat associated with this breakpoint. */
3128 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3133 for (; bsp != NULL; bsp = bsp->next)
3135 if (bsp->breakpoint_at == breakpoint)
3141 /* Put in *NUM the breakpoint number of the first breakpoint we are
3142 stopped at. *BSP upon return is a bpstat which points to the
3143 remaining breakpoints stopped at (but which is not guaranteed to be
3144 good for anything but further calls to bpstat_num).
3146 Return 0 if passed a bpstat which does not indicate any breakpoints.
3147 Return -1 if stopped at a breakpoint that has been deleted since
3149 Return 1 otherwise. */
3152 bpstat_num (bpstat *bsp, int *num)
3154 struct breakpoint *b;
3157 return 0; /* No more breakpoint values */
3159 /* We assume we'll never have several bpstats that correspond to a
3160 single breakpoint -- otherwise, this function might return the
3161 same number more than once and this will look ugly. */
3162 b = (*bsp)->breakpoint_at;
3163 *bsp = (*bsp)->next;
3165 return -1; /* breakpoint that's been deleted since */
3167 *num = b->number; /* We have its number */
3171 /* Modify BS so that the actions will not be performed. */
3174 bpstat_clear_actions (bpstat bs)
3176 for (; bs != NULL; bs = bs->next)
3178 decref_counted_command_line (&bs->commands);
3179 bs->commands_left = NULL;
3180 if (bs->old_val != NULL)
3182 value_free (bs->old_val);
3188 /* Called when a command is about to proceed the inferior. */
3191 breakpoint_about_to_proceed (void)
3193 if (!ptid_equal (inferior_ptid, null_ptid))
3195 struct thread_info *tp = inferior_thread ();
3197 /* Allow inferior function calls in breakpoint commands to not
3198 interrupt the command list. When the call finishes
3199 successfully, the inferior will be standing at the same
3200 breakpoint as if nothing happened. */
3201 if (tp->control.in_infcall)
3205 breakpoint_proceeded = 1;
3208 /* Stub for cleaning up our state if we error-out of a breakpoint
3211 cleanup_executing_breakpoints (void *ignore)
3213 executing_breakpoint_commands = 0;
3216 /* Execute all the commands associated with all the breakpoints at
3217 this location. Any of these commands could cause the process to
3218 proceed beyond this point, etc. We look out for such changes by
3219 checking the global "breakpoint_proceeded" after each command.
3221 Returns true if a breakpoint command resumed the inferior. In that
3222 case, it is the caller's responsibility to recall it again with the
3223 bpstat of the current thread. */
3226 bpstat_do_actions_1 (bpstat *bsp)
3229 struct cleanup *old_chain;
3232 /* Avoid endless recursion if a `source' command is contained
3234 if (executing_breakpoint_commands)
3237 executing_breakpoint_commands = 1;
3238 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3240 prevent_dont_repeat ();
3242 /* This pointer will iterate over the list of bpstat's. */
3245 breakpoint_proceeded = 0;
3246 for (; bs != NULL; bs = bs->next)
3248 struct counted_command_line *ccmd;
3249 struct command_line *cmd;
3250 struct cleanup *this_cmd_tree_chain;
3252 /* Take ownership of the BSP's command tree, if it has one.
3254 The command tree could legitimately contain commands like
3255 'step' and 'next', which call clear_proceed_status, which
3256 frees stop_bpstat's command tree. To make sure this doesn't
3257 free the tree we're executing out from under us, we need to
3258 take ownership of the tree ourselves. Since a given bpstat's
3259 commands are only executed once, we don't need to copy it; we
3260 can clear the pointer in the bpstat, and make sure we free
3261 the tree when we're done. */
3262 ccmd = bs->commands;
3263 bs->commands = NULL;
3265 = make_cleanup_decref_counted_command_line (&ccmd);
3266 cmd = bs->commands_left;
3267 bs->commands_left = NULL;
3271 execute_control_command (cmd);
3273 if (breakpoint_proceeded)
3279 /* We can free this command tree now. */
3280 do_cleanups (this_cmd_tree_chain);
3282 if (breakpoint_proceeded)
3284 if (target_can_async_p ())
3285 /* If we are in async mode, then the target might be still
3286 running, not stopped at any breakpoint, so nothing for
3287 us to do here -- just return to the event loop. */
3290 /* In sync mode, when execute_control_command returns
3291 we're already standing on the next breakpoint.
3292 Breakpoint commands for that stop were not run, since
3293 execute_command does not run breakpoint commands --
3294 only command_line_handler does, but that one is not
3295 involved in execution of breakpoint commands. So, we
3296 can now execute breakpoint commands. It should be
3297 noted that making execute_command do bpstat actions is
3298 not an option -- in this case we'll have recursive
3299 invocation of bpstat for each breakpoint with a
3300 command, and can easily blow up GDB stack. Instead, we
3301 return true, which will trigger the caller to recall us
3302 with the new stop_bpstat. */
3307 do_cleanups (old_chain);
3312 bpstat_do_actions (void)
3314 /* Do any commands attached to breakpoint we are stopped at. */
3315 while (!ptid_equal (inferior_ptid, null_ptid)
3316 && target_has_execution
3317 && !is_exited (inferior_ptid)
3318 && !is_executing (inferior_ptid))
3319 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3320 and only return when it is stopped at the next breakpoint, we
3321 keep doing breakpoint actions until it returns false to
3322 indicate the inferior was not resumed. */
3323 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3327 /* Print out the (old or new) value associated with a watchpoint. */
3330 watchpoint_value_print (struct value *val, struct ui_file *stream)
3333 fprintf_unfiltered (stream, _("<unreadable>"));
3336 struct value_print_options opts;
3337 get_user_print_options (&opts);
3338 value_print (val, stream, &opts);
3342 /* Generic routine for printing messages indicating why we
3343 stopped. The behavior of this function depends on the value
3344 'print_it' in the bpstat structure. Under some circumstances we
3345 may decide not to print anything here and delegate the task to
3348 static enum print_stop_action
3349 print_bp_stop_message (bpstat bs)
3351 switch (bs->print_it)
3354 /* Nothing should be printed for this bpstat entry. */
3355 return PRINT_UNKNOWN;
3359 /* We still want to print the frame, but we already printed the
3360 relevant messages. */
3361 return PRINT_SRC_AND_LOC;
3364 case print_it_normal:
3366 struct breakpoint *b = bs->breakpoint_at;
3368 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3369 which has since been deleted. */
3371 return PRINT_UNKNOWN;
3373 /* Normal case. Call the breakpoint's print_it method. */
3374 return b->ops->print_it (bs);
3379 internal_error (__FILE__, __LINE__,
3380 _("print_bp_stop_message: unrecognized enum value"));
3385 /* Print a message indicating what happened. This is called from
3386 normal_stop(). The input to this routine is the head of the bpstat
3387 list - a list of the eventpoints that caused this stop. This
3388 routine calls the generic print routine for printing a message
3389 about reasons for stopping. This will print (for example) the
3390 "Breakpoint n," part of the output. The return value of this
3393 PRINT_UNKNOWN: Means we printed nothing.
3394 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3395 code to print the location. An example is
3396 "Breakpoint 1, " which should be followed by
3398 PRINT_SRC_ONLY: Means we printed something, but there is no need
3399 to also print the location part of the message.
3400 An example is the catch/throw messages, which
3401 don't require a location appended to the end.
3402 PRINT_NOTHING: We have done some printing and we don't need any
3403 further info to be printed. */
3405 enum print_stop_action
3406 bpstat_print (bpstat bs)
3410 /* Maybe another breakpoint in the chain caused us to stop.
3411 (Currently all watchpoints go on the bpstat whether hit or not.
3412 That probably could (should) be changed, provided care is taken
3413 with respect to bpstat_explains_signal). */
3414 for (; bs; bs = bs->next)
3416 val = print_bp_stop_message (bs);
3417 if (val == PRINT_SRC_ONLY
3418 || val == PRINT_SRC_AND_LOC
3419 || val == PRINT_NOTHING)
3423 /* We reached the end of the chain, or we got a null BS to start
3424 with and nothing was printed. */
3425 return PRINT_UNKNOWN;
3428 /* Evaluate the expression EXP and return 1 if value is zero. This is
3429 used inside a catch_errors to evaluate the breakpoint condition.
3430 The argument is a "struct expression *" that has been cast to a
3431 "char *" to make it pass through catch_errors. */
3434 breakpoint_cond_eval (void *exp)
3436 struct value *mark = value_mark ();
3437 int i = !value_true (evaluate_expression ((struct expression *) exp));
3439 value_free_to_mark (mark);
3443 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3446 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
3450 bs = (bpstat) xmalloc (sizeof (*bs));
3452 **bs_link_pointer = bs;
3453 *bs_link_pointer = &bs->next;
3454 bs->breakpoint_at = bl->owner;
3455 bs->bp_location_at = bl;
3456 incref_bp_location (bl);
3457 /* If the condition is false, etc., don't do the commands. */
3458 bs->commands = NULL;
3459 bs->commands_left = NULL;
3461 bs->print_it = print_it_normal;
3465 /* The target has stopped with waitstatus WS. Check if any hardware
3466 watchpoints have triggered, according to the target. */
3469 watchpoints_triggered (struct target_waitstatus *ws)
3471 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3473 struct breakpoint *b;
3475 if (!stopped_by_watchpoint)
3477 /* We were not stopped by a watchpoint. Mark all watchpoints
3478 as not triggered. */
3480 if (is_hardware_watchpoint (b))
3482 struct watchpoint *w = (struct watchpoint *) b;
3484 w->watchpoint_triggered = watch_triggered_no;
3490 if (!target_stopped_data_address (¤t_target, &addr))
3492 /* We were stopped by a watchpoint, but we don't know where.
3493 Mark all watchpoints as unknown. */
3495 if (is_hardware_watchpoint (b))
3497 struct watchpoint *w = (struct watchpoint *) b;
3499 w->watchpoint_triggered = watch_triggered_unknown;
3502 return stopped_by_watchpoint;
3505 /* The target could report the data address. Mark watchpoints
3506 affected by this data address as triggered, and all others as not
3510 if (is_hardware_watchpoint (b))
3512 struct watchpoint *w = (struct watchpoint *) b;
3513 struct bp_location *loc;
3515 w->watchpoint_triggered = watch_triggered_no;
3516 for (loc = b->loc; loc; loc = loc->next)
3518 if (is_masked_watchpoint (b))
3520 CORE_ADDR newaddr = addr & w->hw_wp_mask;
3521 CORE_ADDR start = loc->address & w->hw_wp_mask;
3523 if (newaddr == start)
3525 w->watchpoint_triggered = watch_triggered_yes;
3529 /* Exact match not required. Within range is sufficient. */
3530 else if (target_watchpoint_addr_within_range (¤t_target,
3534 w->watchpoint_triggered = watch_triggered_yes;
3543 /* Possible return values for watchpoint_check (this can't be an enum
3544 because of check_errors). */
3545 /* The watchpoint has been deleted. */
3546 #define WP_DELETED 1
3547 /* The value has changed. */
3548 #define WP_VALUE_CHANGED 2
3549 /* The value has not changed. */
3550 #define WP_VALUE_NOT_CHANGED 3
3551 /* Ignore this watchpoint, no matter if the value changed or not. */
3554 #define BP_TEMPFLAG 1
3555 #define BP_HARDWAREFLAG 2
3557 /* Evaluate watchpoint condition expression and check if its value
3560 P should be a pointer to struct bpstat, but is defined as a void *
3561 in order for this function to be usable with catch_errors. */
3564 watchpoint_check (void *p)
3566 bpstat bs = (bpstat) p;
3567 struct watchpoint *b;
3568 struct frame_info *fr;
3569 int within_current_scope;
3571 /* BS is built from an existing struct breakpoint. */
3572 gdb_assert (bs->breakpoint_at != NULL);
3573 b = (struct watchpoint *) bs->breakpoint_at;
3575 /* If this is a local watchpoint, we only want to check if the
3576 watchpoint frame is in scope if the current thread is the thread
3577 that was used to create the watchpoint. */
3578 if (!watchpoint_in_thread_scope (b))
3581 if (b->exp_valid_block == NULL)
3582 within_current_scope = 1;
3585 struct frame_info *frame = get_current_frame ();
3586 struct gdbarch *frame_arch = get_frame_arch (frame);
3587 CORE_ADDR frame_pc = get_frame_pc (frame);
3589 /* in_function_epilogue_p() returns a non-zero value if we're
3590 still in the function but the stack frame has already been
3591 invalidated. Since we can't rely on the values of local
3592 variables after the stack has been destroyed, we are treating
3593 the watchpoint in that state as `not changed' without further
3594 checking. Don't mark watchpoints as changed if the current
3595 frame is in an epilogue - even if they are in some other
3596 frame, our view of the stack is likely to be wrong and
3597 frame_find_by_id could error out. */
3598 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3601 fr = frame_find_by_id (b->watchpoint_frame);
3602 within_current_scope = (fr != NULL);
3604 /* If we've gotten confused in the unwinder, we might have
3605 returned a frame that can't describe this variable. */
3606 if (within_current_scope)
3608 struct symbol *function;
3610 function = get_frame_function (fr);
3611 if (function == NULL
3612 || !contained_in (b->exp_valid_block,
3613 SYMBOL_BLOCK_VALUE (function)))
3614 within_current_scope = 0;
3617 if (within_current_scope)
3618 /* If we end up stopping, the current frame will get selected
3619 in normal_stop. So this call to select_frame won't affect
3624 if (within_current_scope)
3626 /* We use value_{,free_to_}mark because it could be a *long*
3627 time before we return to the command level and call
3628 free_all_values. We can't call free_all_values because we
3629 might be in the middle of evaluating a function call. */
3633 struct value *new_val;
3635 if (is_masked_watchpoint (&b->base))
3636 /* Since we don't know the exact trigger address (from
3637 stopped_data_address), just tell the user we've triggered
3638 a mask watchpoint. */
3639 return WP_VALUE_CHANGED;
3641 mark = value_mark ();
3642 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
3644 /* We use value_equal_contents instead of value_equal because
3645 the latter coerces an array to a pointer, thus comparing just
3646 the address of the array instead of its contents. This is
3647 not what we want. */
3648 if ((b->val != NULL) != (new_val != NULL)
3649 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3651 if (new_val != NULL)
3653 release_value (new_val);
3654 value_free_to_mark (mark);
3656 bs->old_val = b->val;
3659 return WP_VALUE_CHANGED;
3663 /* Nothing changed. */
3664 value_free_to_mark (mark);
3665 return WP_VALUE_NOT_CHANGED;
3670 /* This seems like the only logical thing to do because
3671 if we temporarily ignored the watchpoint, then when
3672 we reenter the block in which it is valid it contains
3673 garbage (in the case of a function, it may have two
3674 garbage values, one before and one after the prologue).
3675 So we can't even detect the first assignment to it and
3676 watch after that (since the garbage may or may not equal
3677 the first value assigned). */
3678 /* We print all the stop information in
3679 breakpoint_ops->print_it, but in this case, by the time we
3680 call breakpoint_ops->print_it this bp will be deleted
3681 already. So we have no choice but print the information
3683 if (ui_out_is_mi_like_p (uiout))
3685 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3686 ui_out_text (uiout, "\nWatchpoint ");
3687 ui_out_field_int (uiout, "wpnum", b->base.number);
3689 " deleted because the program has left the block in\n\
3690 which its expression is valid.\n");
3692 /* Make sure the watchpoint's commands aren't executed. */
3693 decref_counted_command_line (&b->base.commands);
3694 watchpoint_del_at_next_stop (b);
3700 /* Return true if it looks like target has stopped due to hitting
3701 breakpoint location BL. This function does not check if we should
3702 stop, only if BL explains the stop. */
3705 bpstat_check_location (const struct bp_location *bl,
3706 struct address_space *aspace, CORE_ADDR bp_addr)
3708 struct breakpoint *b = bl->owner;
3710 /* BL is from an existing breakpoint. */
3711 gdb_assert (b != NULL);
3713 return b->ops->breakpoint_hit (bl, aspace, bp_addr);
3716 /* Determine if the watched values have actually changed, and we
3717 should stop. If not, set BS->stop to 0. */
3720 bpstat_check_watchpoint (bpstat bs)
3722 const struct bp_location *bl;
3723 struct watchpoint *b;
3725 /* BS is built for existing struct breakpoint. */
3726 bl = bs->bp_location_at;
3727 gdb_assert (bl != NULL);
3728 b = (struct watchpoint *) bs->breakpoint_at;
3729 gdb_assert (b != NULL);
3732 int must_check_value = 0;
3734 if (b->base.type == bp_watchpoint)
3735 /* For a software watchpoint, we must always check the
3737 must_check_value = 1;
3738 else if (b->watchpoint_triggered == watch_triggered_yes)
3739 /* We have a hardware watchpoint (read, write, or access)
3740 and the target earlier reported an address watched by
3742 must_check_value = 1;
3743 else if (b->watchpoint_triggered == watch_triggered_unknown
3744 && b->base.type == bp_hardware_watchpoint)
3745 /* We were stopped by a hardware watchpoint, but the target could
3746 not report the data address. We must check the watchpoint's
3747 value. Access and read watchpoints are out of luck; without
3748 a data address, we can't figure it out. */
3749 must_check_value = 1;
3751 if (must_check_value)
3754 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3756 struct cleanup *cleanups = make_cleanup (xfree, message);
3757 int e = catch_errors (watchpoint_check, bs, message,
3759 do_cleanups (cleanups);
3763 /* We've already printed what needs to be printed. */
3764 bs->print_it = print_it_done;
3768 bs->print_it = print_it_noop;
3771 case WP_VALUE_CHANGED:
3772 if (b->base.type == bp_read_watchpoint)
3774 /* There are two cases to consider here:
3776 1. We're watching the triggered memory for reads.
3777 In that case, trust the target, and always report
3778 the watchpoint hit to the user. Even though
3779 reads don't cause value changes, the value may
3780 have changed since the last time it was read, and
3781 since we're not trapping writes, we will not see
3782 those, and as such we should ignore our notion of
3785 2. We're watching the triggered memory for both
3786 reads and writes. There are two ways this may
3789 2.1. This is a target that can't break on data
3790 reads only, but can break on accesses (reads or
3791 writes), such as e.g., x86. We detect this case
3792 at the time we try to insert read watchpoints.
3794 2.2. Otherwise, the target supports read
3795 watchpoints, but, the user set an access or write
3796 watchpoint watching the same memory as this read
3799 If we're watching memory writes as well as reads,
3800 ignore watchpoint hits when we find that the
3801 value hasn't changed, as reads don't cause
3802 changes. This still gives false positives when
3803 the program writes the same value to memory as
3804 what there was already in memory (we will confuse
3805 it for a read), but it's much better than
3808 int other_write_watchpoint = 0;
3810 if (bl->watchpoint_type == hw_read)
3812 struct breakpoint *other_b;
3814 ALL_BREAKPOINTS (other_b)
3815 if (other_b->type == bp_hardware_watchpoint
3816 || other_b->type == bp_access_watchpoint)
3818 struct watchpoint *other_w =
3819 (struct watchpoint *) other_b;
3821 if (other_w->watchpoint_triggered
3822 == watch_triggered_yes)
3824 other_write_watchpoint = 1;
3830 if (other_write_watchpoint
3831 || bl->watchpoint_type == hw_access)
3833 /* We're watching the same memory for writes,
3834 and the value changed since the last time we
3835 updated it, so this trap must be for a write.
3837 bs->print_it = print_it_noop;
3842 case WP_VALUE_NOT_CHANGED:
3843 if (b->base.type == bp_hardware_watchpoint
3844 || b->base.type == bp_watchpoint)
3846 /* Don't stop: write watchpoints shouldn't fire if
3847 the value hasn't changed. */
3848 bs->print_it = print_it_noop;
3856 /* Error from catch_errors. */
3857 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
3858 watchpoint_del_at_next_stop (b);
3859 /* We've already printed what needs to be printed. */
3860 bs->print_it = print_it_done;
3864 else /* must_check_value == 0 */
3866 /* This is a case where some watchpoint(s) triggered, but
3867 not at the address of this watchpoint, or else no
3868 watchpoint triggered after all. So don't print
3869 anything for this watchpoint. */
3870 bs->print_it = print_it_noop;
3877 /* Check conditions (condition proper, frame, thread and ignore count)
3878 of breakpoint referred to by BS. If we should not stop for this
3879 breakpoint, set BS->stop to 0. */
3882 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3884 int thread_id = pid_to_thread_id (ptid);
3885 const struct bp_location *bl;
3886 struct breakpoint *b;
3888 /* BS is built for existing struct breakpoint. */
3889 bl = bs->bp_location_at;
3890 gdb_assert (bl != NULL);
3891 b = bs->breakpoint_at;
3892 gdb_assert (b != NULL);
3894 if (frame_id_p (b->frame_id)
3895 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3899 int value_is_zero = 0;
3900 struct expression *cond;
3902 /* Evaluate Python breakpoints that have a "stop"
3903 method implemented. */
3904 if (b->py_bp_object)
3905 bs->stop = gdbpy_should_stop (b->py_bp_object);
3907 if (is_watchpoint (b))
3909 struct watchpoint *w = (struct watchpoint *) b;
3916 if (cond && b->disposition != disp_del_at_next_stop)
3918 int within_current_scope = 1;
3919 struct watchpoint * w;
3921 /* We use value_mark and value_free_to_mark because it could
3922 be a long time before we return to the command level and
3923 call free_all_values. We can't call free_all_values
3924 because we might be in the middle of evaluating a
3926 struct value *mark = value_mark ();
3928 if (is_watchpoint (b))
3929 w = (struct watchpoint *) b;
3933 /* Need to select the frame, with all that implies so that
3934 the conditions will have the right context. Because we
3935 use the frame, we will not see an inlined function's
3936 variables when we arrive at a breakpoint at the start
3937 of the inlined function; the current frame will be the
3939 if (w == NULL || w->cond_exp_valid_block == NULL)
3940 select_frame (get_current_frame ());
3943 struct frame_info *frame;
3945 /* For local watchpoint expressions, which particular
3946 instance of a local is being watched matters, so we
3947 keep track of the frame to evaluate the expression
3948 in. To evaluate the condition however, it doesn't
3949 really matter which instantiation of the function
3950 where the condition makes sense triggers the
3951 watchpoint. This allows an expression like "watch
3952 global if q > 10" set in `func', catch writes to
3953 global on all threads that call `func', or catch
3954 writes on all recursive calls of `func' by a single
3955 thread. We simply always evaluate the condition in
3956 the innermost frame that's executing where it makes
3957 sense to evaluate the condition. It seems
3959 frame = block_innermost_frame (w->cond_exp_valid_block);
3961 select_frame (frame);
3963 within_current_scope = 0;
3965 if (within_current_scope)
3967 = catch_errors (breakpoint_cond_eval, cond,
3968 "Error in testing breakpoint condition:\n",
3972 warning (_("Watchpoint condition cannot be tested "
3973 "in the current scope"));
3974 /* If we failed to set the right context for this
3975 watchpoint, unconditionally report it. */
3978 /* FIXME-someday, should give breakpoint #. */
3979 value_free_to_mark (mark);
3982 if (cond && value_is_zero)
3986 else if (b->thread != -1 && b->thread != thread_id)
3990 else if (b->ignore_count > 0)
3993 annotate_ignore_count_change ();
3995 /* Increase the hit count even though we don't stop. */
3997 observer_notify_breakpoint_modified (b);
4003 /* Get a bpstat associated with having just stopped at address
4004 BP_ADDR in thread PTID.
4006 Determine whether we stopped at a breakpoint, etc, or whether we
4007 don't understand this stop. Result is a chain of bpstat's such
4010 if we don't understand the stop, the result is a null pointer.
4012 if we understand why we stopped, the result is not null.
4014 Each element of the chain refers to a particular breakpoint or
4015 watchpoint at which we have stopped. (We may have stopped for
4016 several reasons concurrently.)
4018 Each element of the chain has valid next, breakpoint_at,
4019 commands, FIXME??? fields. */
4022 bpstat_stop_status (struct address_space *aspace,
4023 CORE_ADDR bp_addr, ptid_t ptid)
4025 struct breakpoint *b = NULL;
4026 struct bp_location *bl;
4027 struct bp_location *loc;
4028 /* First item of allocated bpstat's. */
4029 bpstat bs_head = NULL, *bs_link = &bs_head;
4030 /* Pointer to the last thing in the chain currently. */
4033 int need_remove_insert;
4036 /* First, build the bpstat chain with locations that explain a
4037 target stop, while being careful to not set the target running,
4038 as that may invalidate locations (in particular watchpoint
4039 locations are recreated). Resuming will happen here with
4040 breakpoint conditions or watchpoint expressions that include
4041 inferior function calls. */
4045 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4048 for (bl = b->loc; bl != NULL; bl = bl->next)
4050 /* For hardware watchpoints, we look only at the first
4051 location. The watchpoint_check function will work on the
4052 entire expression, not the individual locations. For
4053 read watchpoints, the watchpoints_triggered function has
4054 checked all locations already. */
4055 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4058 if (bl->shlib_disabled)
4061 if (!bpstat_check_location (bl, aspace, bp_addr))
4064 /* Come here if it's a watchpoint, or if the break address
4067 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4070 /* Assume we stop. Should we find a watchpoint that is not
4071 actually triggered, or if the condition of the breakpoint
4072 evaluates as false, we'll reset 'stop' to 0. */
4076 /* If this is a scope breakpoint, mark the associated
4077 watchpoint as triggered so that we will handle the
4078 out-of-scope event. We'll get to the watchpoint next
4080 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4082 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4084 w->watchpoint_triggered = watch_triggered_yes;
4089 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4091 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4093 bs = bpstat_alloc (loc, &bs_link);
4094 /* For hits of moribund locations, we should just proceed. */
4097 bs->print_it = print_it_noop;
4101 /* Now go through the locations that caused the target to stop, and
4102 check whether we're interested in reporting this stop to higher
4103 layers, or whether we should resume the target transparently. */
4107 for (bs = bs_head; bs != NULL; bs = bs->next)
4112 b = bs->breakpoint_at;
4113 b->ops->check_status (bs);
4116 bpstat_check_breakpoint_conditions (bs, ptid);
4121 observer_notify_breakpoint_modified (b);
4123 /* We will stop here. */
4124 if (b->disposition == disp_disable)
4126 if (b->enable_state != bp_permanent)
4127 b->enable_state = bp_disabled;
4132 bs->commands = b->commands;
4133 incref_counted_command_line (bs->commands);
4134 bs->commands_left = bs->commands ? bs->commands->commands : NULL;
4135 if (bs->commands_left
4136 && (strcmp ("silent", bs->commands_left->line) == 0
4139 bs->commands_left->line) == 0)))
4141 bs->commands_left = bs->commands_left->next;
4146 /* Print nothing for this entry if we don't stop or don't print. */
4147 if (bs->stop == 0 || bs->print == 0)
4148 bs->print_it = print_it_noop;
4152 /* If we aren't stopping, the value of some hardware watchpoint may
4153 not have changed, but the intermediate memory locations we are
4154 watching may have. Don't bother if we're stopping; this will get
4156 need_remove_insert = 0;
4157 if (! bpstat_causes_stop (bs_head))
4158 for (bs = bs_head; bs != NULL; bs = bs->next)
4160 && bs->breakpoint_at
4161 && is_hardware_watchpoint (bs->breakpoint_at))
4163 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4165 update_watchpoint (w, 0 /* don't reparse. */);
4166 need_remove_insert = 1;
4169 if (need_remove_insert)
4170 update_global_location_list (1);
4171 else if (removed_any)
4172 update_global_location_list (0);
4178 handle_jit_event (void)
4180 struct frame_info *frame;
4181 struct gdbarch *gdbarch;
4183 /* Switch terminal for any messages produced by
4184 breakpoint_re_set. */
4185 target_terminal_ours_for_output ();
4187 frame = get_current_frame ();
4188 gdbarch = get_frame_arch (frame);
4190 jit_event_handler (gdbarch);
4192 target_terminal_inferior ();
4195 /* Prepare WHAT final decision for infrun. */
4197 /* Decide what infrun needs to do with this bpstat. */
4200 bpstat_what (bpstat bs_head)
4202 struct bpstat_what retval;
4203 /* We need to defer calling `solib_add', as adding new symbols
4204 resets breakpoints, which in turn deletes breakpoint locations,
4205 and hence may clear unprocessed entries in the BS chain. */
4206 int shlib_event = 0;
4210 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4211 retval.call_dummy = STOP_NONE;
4212 retval.is_longjmp = 0;
4214 for (bs = bs_head; bs != NULL; bs = bs->next)
4216 /* Extract this BS's action. After processing each BS, we check
4217 if its action overrides all we've seem so far. */
4218 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4221 if (bs->breakpoint_at == NULL)
4223 /* I suspect this can happen if it was a momentary
4224 breakpoint which has since been deleted. */
4228 bptype = bs->breakpoint_at->type;
4235 case bp_hardware_breakpoint:
4241 this_action = BPSTAT_WHAT_STOP_NOISY;
4243 this_action = BPSTAT_WHAT_STOP_SILENT;
4246 this_action = BPSTAT_WHAT_SINGLE;
4249 case bp_hardware_watchpoint:
4250 case bp_read_watchpoint:
4251 case bp_access_watchpoint:
4255 this_action = BPSTAT_WHAT_STOP_NOISY;
4257 this_action = BPSTAT_WHAT_STOP_SILENT;
4261 /* There was a watchpoint, but we're not stopping.
4262 This requires no further action. */
4267 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4268 retval.is_longjmp = bptype == bp_longjmp;
4270 case bp_longjmp_resume:
4271 case bp_exception_resume:
4272 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4273 retval.is_longjmp = bptype == bp_longjmp_resume;
4275 case bp_step_resume:
4277 this_action = BPSTAT_WHAT_STEP_RESUME;
4280 /* It is for the wrong frame. */
4281 this_action = BPSTAT_WHAT_SINGLE;
4284 case bp_hp_step_resume:
4286 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
4289 /* It is for the wrong frame. */
4290 this_action = BPSTAT_WHAT_SINGLE;
4293 case bp_watchpoint_scope:
4294 case bp_thread_event:
4295 case bp_overlay_event:
4296 case bp_longjmp_master:
4297 case bp_std_terminate_master:
4298 case bp_exception_master:
4299 this_action = BPSTAT_WHAT_SINGLE;
4305 this_action = BPSTAT_WHAT_STOP_NOISY;
4307 this_action = BPSTAT_WHAT_STOP_SILENT;
4311 /* There was a catchpoint, but we're not stopping.
4312 This requires no further action. */
4315 case bp_shlib_event:
4318 /* If requested, stop when the dynamic linker notifies GDB
4319 of events. This allows the user to get control and place
4320 breakpoints in initializer routines for dynamically
4321 loaded objects (among other things). */
4322 if (stop_on_solib_events)
4323 this_action = BPSTAT_WHAT_STOP_NOISY;
4325 this_action = BPSTAT_WHAT_SINGLE;
4329 this_action = BPSTAT_WHAT_SINGLE;
4332 /* Make sure the action is stop (silent or noisy),
4333 so infrun.c pops the dummy frame. */
4334 retval.call_dummy = STOP_STACK_DUMMY;
4335 this_action = BPSTAT_WHAT_STOP_SILENT;
4337 case bp_std_terminate:
4338 /* Make sure the action is stop (silent or noisy),
4339 so infrun.c pops the dummy frame. */
4340 retval.call_dummy = STOP_STD_TERMINATE;
4341 this_action = BPSTAT_WHAT_STOP_SILENT;
4344 case bp_fast_tracepoint:
4345 case bp_static_tracepoint:
4346 /* Tracepoint hits should not be reported back to GDB, and
4347 if one got through somehow, it should have been filtered
4349 internal_error (__FILE__, __LINE__,
4350 _("bpstat_what: tracepoint encountered"));
4352 case bp_gnu_ifunc_resolver:
4353 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4354 this_action = BPSTAT_WHAT_SINGLE;
4356 case bp_gnu_ifunc_resolver_return:
4357 /* The breakpoint will be removed, execution will restart from the
4358 PC of the former breakpoint. */
4359 this_action = BPSTAT_WHAT_KEEP_CHECKING;
4362 internal_error (__FILE__, __LINE__,
4363 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4366 retval.main_action = max (retval.main_action, this_action);
4369 /* These operations may affect the bs->breakpoint_at state so they are
4370 delayed after MAIN_ACTION is decided above. */
4375 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
4377 /* Check for any newly added shared libraries if we're supposed
4378 to be adding them automatically. */
4380 /* Switch terminal for any messages produced by
4381 breakpoint_re_set. */
4382 target_terminal_ours_for_output ();
4385 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4387 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4390 target_terminal_inferior ();
4396 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4398 handle_jit_event ();
4401 for (bs = bs_head; bs != NULL; bs = bs->next)
4403 struct breakpoint *b = bs->breakpoint_at;
4409 case bp_gnu_ifunc_resolver:
4410 gnu_ifunc_resolver_stop (b);
4412 case bp_gnu_ifunc_resolver_return:
4413 gnu_ifunc_resolver_return_stop (b);
4421 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4422 without hardware support). This isn't related to a specific bpstat,
4423 just to things like whether watchpoints are set. */
4426 bpstat_should_step (void)
4428 struct breakpoint *b;
4431 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4437 bpstat_causes_stop (bpstat bs)
4439 for (; bs != NULL; bs = bs->next)
4448 /* Compute a string of spaces suitable to indent the next line
4449 so it starts at the position corresponding to the table column
4450 named COL_NAME in the currently active table of UIOUT. */
4453 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
4455 static char wrap_indent[80];
4456 int i, total_width, width, align;
4460 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
4462 if (strcmp (text, col_name) == 0)
4464 gdb_assert (total_width < sizeof wrap_indent);
4465 memset (wrap_indent, ' ', total_width);
4466 wrap_indent[total_width] = 0;
4471 total_width += width + 1;
4477 /* Print the LOC location out of the list of B->LOC locations. */
4480 print_breakpoint_location (struct breakpoint *b,
4481 struct bp_location *loc)
4483 struct cleanup *old_chain = save_current_program_space ();
4485 if (loc != NULL && loc->shlib_disabled)
4489 set_current_program_space (loc->pspace);
4491 if (b->display_canonical)
4492 ui_out_field_string (uiout, "what", b->addr_string);
4493 else if (b->source_file && loc)
4496 = find_pc_sect_function (loc->address, loc->section);
4499 ui_out_text (uiout, "in ");
4500 ui_out_field_string (uiout, "func",
4501 SYMBOL_PRINT_NAME (sym));
4502 ui_out_text (uiout, " ");
4503 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
4504 ui_out_text (uiout, "at ");
4506 ui_out_field_string (uiout, "file", b->source_file);
4507 ui_out_text (uiout, ":");
4509 if (ui_out_is_mi_like_p (uiout))
4511 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4512 char *fullname = symtab_to_fullname (sal.symtab);
4515 ui_out_field_string (uiout, "fullname", fullname);
4518 ui_out_field_int (uiout, "line", b->line_number);
4522 struct ui_stream *stb = ui_out_stream_new (uiout);
4523 struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb);
4525 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4527 ui_out_field_stream (uiout, "at", stb);
4529 do_cleanups (stb_chain);
4532 ui_out_field_string (uiout, "pending", b->addr_string);
4534 do_cleanups (old_chain);
4538 bptype_string (enum bptype type)
4540 struct ep_type_description
4545 static struct ep_type_description bptypes[] =
4547 {bp_none, "?deleted?"},
4548 {bp_breakpoint, "breakpoint"},
4549 {bp_hardware_breakpoint, "hw breakpoint"},
4550 {bp_until, "until"},
4551 {bp_finish, "finish"},
4552 {bp_watchpoint, "watchpoint"},
4553 {bp_hardware_watchpoint, "hw watchpoint"},
4554 {bp_read_watchpoint, "read watchpoint"},
4555 {bp_access_watchpoint, "acc watchpoint"},
4556 {bp_longjmp, "longjmp"},
4557 {bp_longjmp_resume, "longjmp resume"},
4558 {bp_exception, "exception"},
4559 {bp_exception_resume, "exception resume"},
4560 {bp_step_resume, "step resume"},
4561 {bp_hp_step_resume, "high-priority step resume"},
4562 {bp_watchpoint_scope, "watchpoint scope"},
4563 {bp_call_dummy, "call dummy"},
4564 {bp_std_terminate, "std::terminate"},
4565 {bp_shlib_event, "shlib events"},
4566 {bp_thread_event, "thread events"},
4567 {bp_overlay_event, "overlay events"},
4568 {bp_longjmp_master, "longjmp master"},
4569 {bp_std_terminate_master, "std::terminate master"},
4570 {bp_exception_master, "exception master"},
4571 {bp_catchpoint, "catchpoint"},
4572 {bp_tracepoint, "tracepoint"},
4573 {bp_fast_tracepoint, "fast tracepoint"},
4574 {bp_static_tracepoint, "static tracepoint"},
4575 {bp_jit_event, "jit events"},
4576 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
4577 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
4580 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4581 || ((int) type != bptypes[(int) type].type))
4582 internal_error (__FILE__, __LINE__,
4583 _("bptypes table does not describe type #%d."),
4586 return bptypes[(int) type].description;
4589 /* Print B to gdb_stdout. */
4592 print_one_breakpoint_location (struct breakpoint *b,
4593 struct bp_location *loc,
4595 struct bp_location **last_loc,
4598 struct command_line *l;
4599 static char bpenables[] = "nynny";
4601 int header_of_multiple = 0;
4602 int part_of_multiple = (loc != NULL);
4603 struct value_print_options opts;
4605 get_user_print_options (&opts);
4607 gdb_assert (!loc || loc_number != 0);
4608 /* See comment in print_one_breakpoint concerning treatment of
4609 breakpoints with single disabled location. */
4612 && (b->loc->next != NULL || !b->loc->enabled)))
4613 header_of_multiple = 1;
4621 if (part_of_multiple)
4624 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4625 ui_out_field_string (uiout, "number", formatted);
4630 ui_out_field_int (uiout, "number", b->number);
4635 if (part_of_multiple)
4636 ui_out_field_skip (uiout, "type");
4638 ui_out_field_string (uiout, "type", bptype_string (b->type));
4642 if (part_of_multiple)
4643 ui_out_field_skip (uiout, "disp");
4645 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4650 if (part_of_multiple)
4651 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4653 ui_out_field_fmt (uiout, "enabled", "%c",
4654 bpenables[(int) b->enable_state]);
4655 ui_out_spaces (uiout, 2);
4659 if (b->ops != NULL && b->ops->print_one != NULL)
4661 /* Although the print_one can possibly print all locations,
4662 calling it here is not likely to get any nice result. So,
4663 make sure there's just one location. */
4664 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4665 b->ops->print_one (b, last_loc);
4671 internal_error (__FILE__, __LINE__,
4672 _("print_one_breakpoint: bp_none encountered\n"));
4676 case bp_hardware_watchpoint:
4677 case bp_read_watchpoint:
4678 case bp_access_watchpoint:
4680 struct watchpoint *w = (struct watchpoint *) b;
4682 /* Field 4, the address, is omitted (which makes the columns
4683 not line up too nicely with the headers, but the effect
4684 is relatively readable). */
4685 if (opts.addressprint)
4686 ui_out_field_skip (uiout, "addr");
4688 ui_out_field_string (uiout, "what", w->exp_string);
4693 case bp_hardware_breakpoint:
4697 case bp_longjmp_resume:
4699 case bp_exception_resume:
4700 case bp_step_resume:
4701 case bp_hp_step_resume:
4702 case bp_watchpoint_scope:
4704 case bp_std_terminate:
4705 case bp_shlib_event:
4706 case bp_thread_event:
4707 case bp_overlay_event:
4708 case bp_longjmp_master:
4709 case bp_std_terminate_master:
4710 case bp_exception_master:
4712 case bp_fast_tracepoint:
4713 case bp_static_tracepoint:
4715 case bp_gnu_ifunc_resolver:
4716 case bp_gnu_ifunc_resolver_return:
4717 if (opts.addressprint)
4720 if (header_of_multiple)
4721 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4722 else if (b->loc == NULL || loc->shlib_disabled)
4723 ui_out_field_string (uiout, "addr", "<PENDING>");
4725 ui_out_field_core_addr (uiout, "addr",
4726 loc->gdbarch, loc->address);
4729 if (!header_of_multiple)
4730 print_breakpoint_location (b, loc);
4737 /* For backward compatibility, don't display inferiors unless there
4740 && !header_of_multiple
4742 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4743 && (number_of_program_spaces () > 1
4744 || number_of_inferiors () > 1)
4745 /* LOC is for existing B, it cannot be in
4746 moribund_locations and thus having NULL OWNER. */
4747 && loc->owner->type != bp_catchpoint)))
4749 struct inferior *inf;
4752 for (inf = inferior_list; inf != NULL; inf = inf->next)
4754 if (inf->pspace == loc->pspace)
4759 ui_out_text (uiout, " inf ");
4762 ui_out_text (uiout, ", ");
4763 ui_out_text (uiout, plongest (inf->num));
4768 if (!part_of_multiple)
4770 if (b->thread != -1)
4772 /* FIXME: This seems to be redundant and lost here; see the
4773 "stop only in" line a little further down. */
4774 ui_out_text (uiout, " thread ");
4775 ui_out_field_int (uiout, "thread", b->thread);
4777 else if (b->task != 0)
4779 ui_out_text (uiout, " task ");
4780 ui_out_field_int (uiout, "task", b->task);
4784 ui_out_text (uiout, "\n");
4786 if (!part_of_multiple)
4787 b->ops->print_one_detail (b, uiout);
4789 if (part_of_multiple && frame_id_p (b->frame_id))
4792 ui_out_text (uiout, "\tstop only in stack frame at ");
4793 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4795 ui_out_field_core_addr (uiout, "frame",
4796 b->gdbarch, b->frame_id.stack_addr);
4797 ui_out_text (uiout, "\n");
4800 if (!part_of_multiple && b->cond_string)
4803 if (is_tracepoint (b))
4804 ui_out_text (uiout, "\ttrace only if ");
4806 ui_out_text (uiout, "\tstop only if ");
4807 ui_out_field_string (uiout, "cond", b->cond_string);
4808 ui_out_text (uiout, "\n");
4811 if (!part_of_multiple && b->thread != -1)
4813 /* FIXME should make an annotation for this. */
4814 ui_out_text (uiout, "\tstop only in thread ");
4815 ui_out_field_int (uiout, "thread", b->thread);
4816 ui_out_text (uiout, "\n");
4819 if (!part_of_multiple && b->hit_count)
4821 /* FIXME should make an annotation for this. */
4822 if (ep_is_catchpoint (b))
4823 ui_out_text (uiout, "\tcatchpoint");
4825 ui_out_text (uiout, "\tbreakpoint");
4826 ui_out_text (uiout, " already hit ");
4827 ui_out_field_int (uiout, "times", b->hit_count);
4828 if (b->hit_count == 1)
4829 ui_out_text (uiout, " time\n");
4831 ui_out_text (uiout, " times\n");
4834 /* Output the count also if it is zero, but only if this is mi.
4835 FIXME: Should have a better test for this. */
4836 if (ui_out_is_mi_like_p (uiout))
4837 if (!part_of_multiple && b->hit_count == 0)
4838 ui_out_field_int (uiout, "times", b->hit_count);
4840 if (!part_of_multiple && b->ignore_count)
4843 ui_out_text (uiout, "\tignore next ");
4844 ui_out_field_int (uiout, "ignore", b->ignore_count);
4845 ui_out_text (uiout, " hits\n");
4848 l = b->commands ? b->commands->commands : NULL;
4849 if (!part_of_multiple && l)
4851 struct cleanup *script_chain;
4854 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4855 print_command_lines (uiout, l, 4);
4856 do_cleanups (script_chain);
4859 if (is_tracepoint (b))
4861 struct tracepoint *t = (struct tracepoint *) b;
4863 if (!part_of_multiple && t->pass_count)
4865 annotate_field (10);
4866 ui_out_text (uiout, "\tpass count ");
4867 ui_out_field_int (uiout, "pass", t->pass_count);
4868 ui_out_text (uiout, " \n");
4872 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4874 if (is_watchpoint (b))
4876 struct watchpoint *w = (struct watchpoint *) b;
4878 ui_out_field_string (uiout, "original-location", w->exp_string);
4880 else if (b->addr_string)
4881 ui_out_field_string (uiout, "original-location", b->addr_string);
4886 print_one_breakpoint (struct breakpoint *b,
4887 struct bp_location **last_loc,
4890 struct cleanup *bkpt_chain;
4892 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4894 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
4895 do_cleanups (bkpt_chain);
4897 /* If this breakpoint has custom print function,
4898 it's already printed. Otherwise, print individual
4899 locations, if any. */
4900 if (b->ops == NULL || b->ops->print_one == NULL)
4902 /* If breakpoint has a single location that is disabled, we
4903 print it as if it had several locations, since otherwise it's
4904 hard to represent "breakpoint enabled, location disabled"
4907 Note that while hardware watchpoints have several locations
4908 internally, that's not a property exposed to user. */
4910 && !is_hardware_watchpoint (b)
4911 && (b->loc->next || !b->loc->enabled))
4913 struct bp_location *loc;
4916 for (loc = b->loc; loc; loc = loc->next, ++n)
4918 struct cleanup *inner2 =
4919 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
4920 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
4921 do_cleanups (inner2);
4928 breakpoint_address_bits (struct breakpoint *b)
4930 int print_address_bits = 0;
4931 struct bp_location *loc;
4933 for (loc = b->loc; loc; loc = loc->next)
4937 /* Software watchpoints that aren't watching memory don't have
4938 an address to print. */
4939 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
4942 addr_bit = gdbarch_addr_bit (loc->gdbarch);
4943 if (addr_bit > print_address_bits)
4944 print_address_bits = addr_bit;
4947 return print_address_bits;
4950 struct captured_breakpoint_query_args
4956 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
4958 struct captured_breakpoint_query_args *args = data;
4959 struct breakpoint *b;
4960 struct bp_location *dummy_loc = NULL;
4964 if (args->bnum == b->number)
4966 print_one_breakpoint (b, &dummy_loc, 0);
4974 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
4975 char **error_message)
4977 struct captured_breakpoint_query_args args;
4980 /* For the moment we don't trust print_one_breakpoint() to not throw
4982 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
4983 error_message, RETURN_MASK_ALL) < 0)
4989 /* Return true if this breakpoint was set by the user, false if it is
4990 internal or momentary. */
4993 user_breakpoint_p (struct breakpoint *b)
4995 return b->number > 0;
4998 /* Print information on user settable breakpoint (watchpoint, etc)
4999 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5000 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5001 FILTER is non-NULL, call it on each breakpoint and only include the
5002 ones for which it returns non-zero. Return the total number of
5003 breakpoints listed. */
5006 breakpoint_1 (char *args, int allflag,
5007 int (*filter) (const struct breakpoint *))
5009 struct breakpoint *b;
5010 struct bp_location *last_loc = NULL;
5011 int nr_printable_breakpoints;
5012 struct cleanup *bkpttbl_chain;
5013 struct value_print_options opts;
5014 int print_address_bits = 0;
5015 int print_type_col_width = 14;
5017 get_user_print_options (&opts);
5019 /* Compute the number of rows in the table, as well as the size
5020 required for address fields. */
5021 nr_printable_breakpoints = 0;
5024 /* If we have a filter, only list the breakpoints it accepts. */
5025 if (filter && !filter (b))
5028 /* If we have an "args" string, it is a list of breakpoints to
5029 accept. Skip the others. */
5030 if (args != NULL && *args != '\0')
5032 if (allflag && parse_and_eval_long (args) != b->number)
5034 if (!allflag && !number_is_in_list (args, b->number))
5038 if (allflag || user_breakpoint_p (b))
5040 int addr_bit, type_len;
5042 addr_bit = breakpoint_address_bits (b);
5043 if (addr_bit > print_address_bits)
5044 print_address_bits = addr_bit;
5046 type_len = strlen (bptype_string (b->type));
5047 if (type_len > print_type_col_width)
5048 print_type_col_width = type_len;
5050 nr_printable_breakpoints++;
5054 if (opts.addressprint)
5056 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5057 nr_printable_breakpoints,
5061 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5062 nr_printable_breakpoints,
5065 if (nr_printable_breakpoints > 0)
5066 annotate_breakpoints_headers ();
5067 if (nr_printable_breakpoints > 0)
5069 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5070 if (nr_printable_breakpoints > 0)
5072 ui_out_table_header (uiout, print_type_col_width, ui_left,
5073 "type", "Type"); /* 2 */
5074 if (nr_printable_breakpoints > 0)
5076 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5077 if (nr_printable_breakpoints > 0)
5079 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5080 if (opts.addressprint)
5082 if (nr_printable_breakpoints > 0)
5084 if (print_address_bits <= 32)
5085 ui_out_table_header (uiout, 10, ui_left,
5086 "addr", "Address"); /* 5 */
5088 ui_out_table_header (uiout, 18, ui_left,
5089 "addr", "Address"); /* 5 */
5091 if (nr_printable_breakpoints > 0)
5093 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5094 ui_out_table_body (uiout);
5095 if (nr_printable_breakpoints > 0)
5096 annotate_breakpoints_table ();
5101 /* If we have a filter, only list the breakpoints it accepts. */
5102 if (filter && !filter (b))
5105 /* If we have an "args" string, it is a list of breakpoints to
5106 accept. Skip the others. */
5108 if (args != NULL && *args != '\0')
5110 if (allflag) /* maintenance info breakpoint */
5112 if (parse_and_eval_long (args) != b->number)
5115 else /* all others */
5117 if (!number_is_in_list (args, b->number))
5121 /* We only print out user settable breakpoints unless the
5123 if (allflag || user_breakpoint_p (b))
5124 print_one_breakpoint (b, &last_loc, allflag);
5127 do_cleanups (bkpttbl_chain);
5129 if (nr_printable_breakpoints == 0)
5131 /* If there's a filter, let the caller decide how to report
5135 if (args == NULL || *args == '\0')
5136 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5138 ui_out_message (uiout, 0,
5139 "No breakpoint or watchpoint matching '%s'.\n",
5145 if (last_loc && !server_command)
5146 set_next_address (last_loc->gdbarch, last_loc->address);
5149 /* FIXME? Should this be moved up so that it is only called when
5150 there have been breakpoints? */
5151 annotate_breakpoints_table_end ();
5153 return nr_printable_breakpoints;
5156 /* Display the value of default-collect in a way that is generally
5157 compatible with the breakpoint list. */
5160 default_collect_info (void)
5162 /* If it has no value (which is frequently the case), say nothing; a
5163 message like "No default-collect." gets in user's face when it's
5165 if (!*default_collect)
5168 /* The following phrase lines up nicely with per-tracepoint collect
5170 ui_out_text (uiout, "default collect ");
5171 ui_out_field_string (uiout, "default-collect", default_collect);
5172 ui_out_text (uiout, " \n");
5176 breakpoints_info (char *args, int from_tty)
5178 breakpoint_1 (args, 0, NULL);
5180 default_collect_info ();
5184 watchpoints_info (char *args, int from_tty)
5186 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
5188 if (num_printed == 0)
5190 if (args == NULL || *args == '\0')
5191 ui_out_message (uiout, 0, "No watchpoints.\n");
5193 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
5198 maintenance_info_breakpoints (char *args, int from_tty)
5200 breakpoint_1 (args, 1, NULL);
5202 default_collect_info ();
5206 breakpoint_has_pc (struct breakpoint *b,
5207 struct program_space *pspace,
5208 CORE_ADDR pc, struct obj_section *section)
5210 struct bp_location *bl = b->loc;
5212 for (; bl; bl = bl->next)
5214 if (bl->pspace == pspace
5215 && bl->address == pc
5216 && (!overlay_debugging || bl->section == section))
5222 /* Print a message describing any breakpoints set at PC. This
5223 concerns with logical breakpoints, so we match program spaces, not
5227 describe_other_breakpoints (struct gdbarch *gdbarch,
5228 struct program_space *pspace, CORE_ADDR pc,
5229 struct obj_section *section, int thread)
5232 struct breakpoint *b;
5235 others += breakpoint_has_pc (b, pspace, pc, section);
5239 printf_filtered (_("Note: breakpoint "));
5240 else /* if (others == ???) */
5241 printf_filtered (_("Note: breakpoints "));
5243 if (breakpoint_has_pc (b, pspace, pc, section))
5246 printf_filtered ("%d", b->number);
5247 if (b->thread == -1 && thread != -1)
5248 printf_filtered (" (all threads)");
5249 else if (b->thread != -1)
5250 printf_filtered (" (thread %d)", b->thread);
5251 printf_filtered ("%s%s ",
5252 ((b->enable_state == bp_disabled
5253 || b->enable_state == bp_call_disabled
5254 || b->enable_state == bp_startup_disabled)
5256 : b->enable_state == bp_permanent
5260 : ((others == 1) ? " and" : ""));
5262 printf_filtered (_("also set at pc "));
5263 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5264 printf_filtered (".\n");
5268 /* Set the default place to put a breakpoint
5269 for the `break' command with no arguments. */
5272 set_default_breakpoint (int valid, struct program_space *pspace,
5273 CORE_ADDR addr, struct symtab *symtab,
5276 default_breakpoint_valid = valid;
5277 default_breakpoint_pspace = pspace;
5278 default_breakpoint_address = addr;
5279 default_breakpoint_symtab = symtab;
5280 default_breakpoint_line = line;
5283 /* Return true iff it is meaningful to use the address member of
5284 BPT. For some breakpoint types, the address member is irrelevant
5285 and it makes no sense to attempt to compare it to other addresses
5286 (or use it for any other purpose either).
5288 More specifically, each of the following breakpoint types will
5289 always have a zero valued address and we don't want to mark
5290 breakpoints of any of these types to be a duplicate of an actual
5291 breakpoint at address zero:
5299 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5301 enum bptype type = bpt->type;
5303 return (type != bp_watchpoint && type != bp_catchpoint);
5306 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5307 true if LOC1 and LOC2 represent the same watchpoint location. */
5310 watchpoint_locations_match (struct bp_location *loc1,
5311 struct bp_location *loc2)
5313 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
5314 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
5316 /* Both of them must exist. */
5317 gdb_assert (w1 != NULL);
5318 gdb_assert (w2 != NULL);
5320 /* If the target can evaluate the condition expression in hardware,
5321 then we we need to insert both watchpoints even if they are at
5322 the same place. Otherwise the watchpoint will only trigger when
5323 the condition of whichever watchpoint was inserted evaluates to
5324 true, not giving a chance for GDB to check the condition of the
5325 other watchpoint. */
5327 && target_can_accel_watchpoint_condition (loc1->address,
5329 loc1->watchpoint_type,
5332 && target_can_accel_watchpoint_condition (loc2->address,
5334 loc2->watchpoint_type,
5338 /* Note that this checks the owner's type, not the location's. In
5339 case the target does not support read watchpoints, but does
5340 support access watchpoints, we'll have bp_read_watchpoint
5341 watchpoints with hw_access locations. Those should be considered
5342 duplicates of hw_read locations. The hw_read locations will
5343 become hw_access locations later. */
5344 return (loc1->owner->type == loc2->owner->type
5345 && loc1->pspace->aspace == loc2->pspace->aspace
5346 && loc1->address == loc2->address
5347 && loc1->length == loc2->length);
5350 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5351 same breakpoint location. In most targets, this can only be true
5352 if ASPACE1 matches ASPACE2. On targets that have global
5353 breakpoints, the address space doesn't really matter. */
5356 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5357 struct address_space *aspace2, CORE_ADDR addr2)
5359 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5360 || aspace1 == aspace2)
5364 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5365 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5366 matches ASPACE2. On targets that have global breakpoints, the address
5367 space doesn't really matter. */
5370 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
5371 int len1, struct address_space *aspace2,
5374 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5375 || aspace1 == aspace2)
5376 && addr2 >= addr1 && addr2 < addr1 + len1);
5379 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5380 a ranged breakpoint. In most targets, a match happens only if ASPACE
5381 matches the breakpoint's address space. On targets that have global
5382 breakpoints, the address space doesn't really matter. */
5385 breakpoint_location_address_match (struct bp_location *bl,
5386 struct address_space *aspace,
5389 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
5392 && breakpoint_address_match_range (bl->pspace->aspace,
5393 bl->address, bl->length,
5397 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5398 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5399 represent the same location. */
5402 breakpoint_locations_match (struct bp_location *loc1,
5403 struct bp_location *loc2)
5405 int hw_point1, hw_point2;
5407 /* Both of them must not be in moribund_locations. */
5408 gdb_assert (loc1->owner != NULL);
5409 gdb_assert (loc2->owner != NULL);
5411 hw_point1 = is_hardware_watchpoint (loc1->owner);
5412 hw_point2 = is_hardware_watchpoint (loc2->owner);
5414 if (hw_point1 != hw_point2)
5417 return watchpoint_locations_match (loc1, loc2);
5419 /* We compare bp_location.length in order to cover ranged breakpoints. */
5420 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5421 loc2->pspace->aspace, loc2->address)
5422 && loc1->length == loc2->length);
5426 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5427 int bnum, int have_bnum)
5429 /* The longest string possibly returned by hex_string_custom
5430 is 50 chars. These must be at least that big for safety. */
5434 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5435 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5437 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5438 bnum, astr1, astr2);
5440 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5443 /* Adjust a breakpoint's address to account for architectural
5444 constraints on breakpoint placement. Return the adjusted address.
5445 Note: Very few targets require this kind of adjustment. For most
5446 targets, this function is simply the identity function. */
5449 adjust_breakpoint_address (struct gdbarch *gdbarch,
5450 CORE_ADDR bpaddr, enum bptype bptype)
5452 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5454 /* Very few targets need any kind of breakpoint adjustment. */
5457 else if (bptype == bp_watchpoint
5458 || bptype == bp_hardware_watchpoint
5459 || bptype == bp_read_watchpoint
5460 || bptype == bp_access_watchpoint
5461 || bptype == bp_catchpoint)
5463 /* Watchpoints and the various bp_catch_* eventpoints should not
5464 have their addresses modified. */
5469 CORE_ADDR adjusted_bpaddr;
5471 /* Some targets have architectural constraints on the placement
5472 of breakpoint instructions. Obtain the adjusted address. */
5473 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5475 /* An adjusted breakpoint address can significantly alter
5476 a user's expectations. Print a warning if an adjustment
5478 if (adjusted_bpaddr != bpaddr)
5479 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5481 return adjusted_bpaddr;
5486 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
5487 struct breakpoint *owner)
5489 memset (loc, 0, sizeof (*loc));
5491 gdb_assert (ops != NULL);
5496 loc->shlib_disabled = 0;
5499 switch (owner->type)
5505 case bp_longjmp_resume:
5507 case bp_exception_resume:
5508 case bp_step_resume:
5509 case bp_hp_step_resume:
5510 case bp_watchpoint_scope:
5512 case bp_std_terminate:
5513 case bp_shlib_event:
5514 case bp_thread_event:
5515 case bp_overlay_event:
5517 case bp_longjmp_master:
5518 case bp_std_terminate_master:
5519 case bp_exception_master:
5520 case bp_gnu_ifunc_resolver:
5521 case bp_gnu_ifunc_resolver_return:
5522 loc->loc_type = bp_loc_software_breakpoint;
5524 case bp_hardware_breakpoint:
5525 loc->loc_type = bp_loc_hardware_breakpoint;
5527 case bp_hardware_watchpoint:
5528 case bp_read_watchpoint:
5529 case bp_access_watchpoint:
5530 loc->loc_type = bp_loc_hardware_watchpoint;
5535 case bp_fast_tracepoint:
5536 case bp_static_tracepoint:
5537 loc->loc_type = bp_loc_other;
5540 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5546 /* Allocate a struct bp_location. */
5548 static struct bp_location *
5549 allocate_bp_location (struct breakpoint *bpt)
5551 return bpt->ops->allocate_location (bpt);
5555 free_bp_location (struct bp_location *loc)
5557 loc->ops->dtor (loc);
5561 /* Increment reference count. */
5564 incref_bp_location (struct bp_location *bl)
5569 /* Decrement reference count. If the reference count reaches 0,
5570 destroy the bp_location. Sets *BLP to NULL. */
5573 decref_bp_location (struct bp_location **blp)
5575 gdb_assert ((*blp)->refc > 0);
5577 if (--(*blp)->refc == 0)
5578 free_bp_location (*blp);
5582 /* Add breakpoint B at the end of the global breakpoint chain. */
5585 add_to_breakpoint_chain (struct breakpoint *b)
5587 struct breakpoint *b1;
5589 /* Add this breakpoint to the end of the chain so that a list of
5590 breakpoints will come out in order of increasing numbers. */
5592 b1 = breakpoint_chain;
5594 breakpoint_chain = b;
5603 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5606 init_raw_breakpoint_without_location (struct breakpoint *b,
5607 struct gdbarch *gdbarch,
5609 const struct breakpoint_ops *ops)
5611 memset (b, 0, sizeof (*b));
5613 gdb_assert (ops != NULL);
5617 b->gdbarch = gdbarch;
5618 b->language = current_language->la_language;
5619 b->input_radix = input_radix;
5621 b->enable_state = bp_enabled;
5624 b->ignore_count = 0;
5626 b->frame_id = null_frame_id;
5627 b->condition_not_parsed = 0;
5628 b->py_bp_object = NULL;
5629 b->related_breakpoint = b;
5632 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5633 that has type BPTYPE and has no locations as yet. */
5635 static struct breakpoint *
5636 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5638 const struct breakpoint_ops *ops)
5640 struct breakpoint *b = XNEW (struct breakpoint);
5642 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
5643 add_to_breakpoint_chain (b);
5647 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5648 resolutions should be made as the user specified the location explicitly
5652 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
5654 gdb_assert (loc->owner != NULL);
5656 if (loc->owner->type == bp_breakpoint
5657 || loc->owner->type == bp_hardware_breakpoint
5658 || is_tracepoint (loc->owner))
5662 find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name,
5663 NULL, NULL, &is_gnu_ifunc);
5665 if (is_gnu_ifunc && !explicit_loc)
5667 struct breakpoint *b = loc->owner;
5669 gdb_assert (loc->pspace == current_program_space);
5670 if (gnu_ifunc_resolve_name (loc->function_name,
5671 &loc->requested_address))
5673 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5674 loc->address = adjust_breakpoint_address (loc->gdbarch,
5675 loc->requested_address,
5678 else if (b->type == bp_breakpoint && b->loc == loc
5679 && loc->next == NULL && b->related_breakpoint == b)
5681 /* Create only the whole new breakpoint of this type but do not
5682 mess more complicated breakpoints with multiple locations. */
5683 b->type = bp_gnu_ifunc_resolver;
5687 if (loc->function_name)
5688 loc->function_name = xstrdup (loc->function_name);
5692 /* Attempt to determine architecture of location identified by SAL. */
5693 static struct gdbarch *
5694 get_sal_arch (struct symtab_and_line sal)
5697 return get_objfile_arch (sal.section->objfile);
5699 return get_objfile_arch (sal.symtab->objfile);
5704 /* Low level routine for partially initializing a breakpoint of type
5705 BPTYPE. The newly created breakpoint's address, section, source
5706 file name, and line number are provided by SAL.
5708 It is expected that the caller will complete the initialization of
5709 the newly created breakpoint struct as well as output any status
5710 information regarding the creation of a new breakpoint. */
5713 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
5714 struct symtab_and_line sal, enum bptype bptype,
5715 const struct breakpoint_ops *ops)
5717 CORE_ADDR adjusted_address;
5718 struct gdbarch *loc_gdbarch;
5720 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
5722 loc_gdbarch = get_sal_arch (sal);
5724 loc_gdbarch = b->gdbarch;
5726 if (bptype != bp_catchpoint)
5727 gdb_assert (sal.pspace != NULL);
5729 /* Adjust the breakpoint's address prior to allocating a location.
5730 Once we call allocate_bp_location(), that mostly uninitialized
5731 location will be placed on the location chain. Adjustment of the
5732 breakpoint may cause target_read_memory() to be called and we do
5733 not want its scan of the location chain to find a breakpoint and
5734 location that's only been partially initialized. */
5735 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
5738 b->loc = allocate_bp_location (b);
5739 b->loc->gdbarch = loc_gdbarch;
5740 b->loc->requested_address = sal.pc;
5741 b->loc->address = adjusted_address;
5742 b->loc->pspace = sal.pspace;
5744 /* Store the program space that was used to set the breakpoint, for
5745 breakpoint resetting. */
5746 b->pspace = sal.pspace;
5748 if (sal.symtab == NULL)
5749 b->source_file = NULL;
5751 b->source_file = xstrdup (sal.symtab->filename);
5752 b->loc->section = sal.section;
5753 b->line_number = sal.line;
5755 set_breakpoint_location_function (b->loc,
5756 sal.explicit_pc || sal.explicit_line);
5758 breakpoints_changed ();
5761 /* set_raw_breakpoint is a low level routine for allocating and
5762 partially initializing a breakpoint of type BPTYPE. The newly
5763 created breakpoint's address, section, source file name, and line
5764 number are provided by SAL. The newly created and partially
5765 initialized breakpoint is added to the breakpoint chain and
5766 is also returned as the value of this function.
5768 It is expected that the caller will complete the initialization of
5769 the newly created breakpoint struct as well as output any status
5770 information regarding the creation of a new breakpoint. In
5771 particular, set_raw_breakpoint does NOT set the breakpoint
5772 number! Care should be taken to not allow an error to occur
5773 prior to completing the initialization of the breakpoint. If this
5774 should happen, a bogus breakpoint will be left on the chain. */
5777 set_raw_breakpoint (struct gdbarch *gdbarch,
5778 struct symtab_and_line sal, enum bptype bptype,
5779 const struct breakpoint_ops *ops)
5781 struct breakpoint *b = XNEW (struct breakpoint);
5783 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
5784 add_to_breakpoint_chain (b);
5789 /* Note that the breakpoint object B describes a permanent breakpoint
5790 instruction, hard-wired into the inferior's code. */
5792 make_breakpoint_permanent (struct breakpoint *b)
5794 struct bp_location *bl;
5796 b->enable_state = bp_permanent;
5798 /* By definition, permanent breakpoints are already present in the
5799 code. Mark all locations as inserted. For now,
5800 make_breakpoint_permanent is called in just one place, so it's
5801 hard to say if it's reasonable to have permanent breakpoint with
5802 multiple locations or not, but it's easy to implement. */
5803 for (bl = b->loc; bl; bl = bl->next)
5807 /* Call this routine when stepping and nexting to enable a breakpoint
5808 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5809 initiated the operation. */
5812 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
5814 struct breakpoint *b, *b_tmp;
5815 int thread = tp->num;
5817 /* To avoid having to rescan all objfile symbols at every step,
5818 we maintain a list of continually-inserted but always disabled
5819 longjmp "master" breakpoints. Here, we simply create momentary
5820 clones of those and enable them for the requested thread. */
5821 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5822 if (b->pspace == current_program_space
5823 && (b->type == bp_longjmp_master
5824 || b->type == bp_exception_master))
5826 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
5827 struct breakpoint *clone;
5829 clone = momentary_breakpoint_from_master (b, type,
5830 &momentary_breakpoint_ops);
5831 clone->thread = thread;
5834 tp->initiating_frame = frame;
5837 /* Delete all longjmp breakpoints from THREAD. */
5839 delete_longjmp_breakpoint (int thread)
5841 struct breakpoint *b, *b_tmp;
5843 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5844 if (b->type == bp_longjmp || b->type == bp_exception)
5846 if (b->thread == thread)
5847 delete_breakpoint (b);
5852 enable_overlay_breakpoints (void)
5854 struct breakpoint *b;
5857 if (b->type == bp_overlay_event)
5859 b->enable_state = bp_enabled;
5860 update_global_location_list (1);
5861 overlay_events_enabled = 1;
5866 disable_overlay_breakpoints (void)
5868 struct breakpoint *b;
5871 if (b->type == bp_overlay_event)
5873 b->enable_state = bp_disabled;
5874 update_global_location_list (0);
5875 overlay_events_enabled = 0;
5879 /* Set an active std::terminate breakpoint for each std::terminate
5880 master breakpoint. */
5882 set_std_terminate_breakpoint (void)
5884 struct breakpoint *b, *b_tmp;
5886 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5887 if (b->pspace == current_program_space
5888 && b->type == bp_std_terminate_master)
5890 momentary_breakpoint_from_master (b, bp_std_terminate,
5891 &momentary_breakpoint_ops);
5895 /* Delete all the std::terminate breakpoints. */
5897 delete_std_terminate_breakpoint (void)
5899 struct breakpoint *b, *b_tmp;
5901 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5902 if (b->type == bp_std_terminate)
5903 delete_breakpoint (b);
5907 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5909 struct breakpoint *b;
5911 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
5912 &internal_breakpoint_ops);
5914 b->enable_state = bp_enabled;
5915 /* addr_string has to be used or breakpoint_re_set will delete me. */
5917 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5919 update_global_location_list_nothrow (1);
5925 remove_thread_event_breakpoints (void)
5927 struct breakpoint *b, *b_tmp;
5929 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5930 if (b->type == bp_thread_event
5931 && b->loc->pspace == current_program_space)
5932 delete_breakpoint (b);
5935 struct lang_and_radix
5941 /* Create a breakpoint for JIT code registration and unregistration. */
5944 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5946 struct breakpoint *b;
5948 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
5949 &internal_breakpoint_ops);
5950 update_global_location_list_nothrow (1);
5954 /* Remove JIT code registration and unregistration breakpoint(s). */
5957 remove_jit_event_breakpoints (void)
5959 struct breakpoint *b, *b_tmp;
5961 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5962 if (b->type == bp_jit_event
5963 && b->loc->pspace == current_program_space)
5964 delete_breakpoint (b);
5968 remove_solib_event_breakpoints (void)
5970 struct breakpoint *b, *b_tmp;
5972 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5973 if (b->type == bp_shlib_event
5974 && b->loc->pspace == current_program_space)
5975 delete_breakpoint (b);
5979 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5981 struct breakpoint *b;
5983 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
5984 &internal_breakpoint_ops);
5985 update_global_location_list_nothrow (1);
5989 /* Disable any breakpoints that are on code in shared libraries. Only
5990 apply to enabled breakpoints, disabled ones can just stay disabled. */
5993 disable_breakpoints_in_shlibs (void)
5995 struct bp_location *loc, **locp_tmp;
5997 ALL_BP_LOCATIONS (loc, locp_tmp)
5999 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6000 struct breakpoint *b = loc->owner;
6002 /* We apply the check to all breakpoints, including disabled for
6003 those with loc->duplicate set. This is so that when breakpoint
6004 becomes enabled, or the duplicate is removed, gdb will try to
6005 insert all breakpoints. If we don't set shlib_disabled here,
6006 we'll try to insert those breakpoints and fail. */
6007 if (((b->type == bp_breakpoint)
6008 || (b->type == bp_jit_event)
6009 || (b->type == bp_hardware_breakpoint)
6010 || (is_tracepoint (b)))
6011 && loc->pspace == current_program_space
6012 && !loc->shlib_disabled
6014 && PC_SOLIB (loc->address)
6016 && solib_name_from_address (loc->pspace, loc->address)
6020 loc->shlib_disabled = 1;
6025 /* Disable any breakpoints that are in an unloaded shared library.
6026 Only apply to enabled breakpoints, disabled ones can just stay
6030 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6032 struct bp_location *loc, **locp_tmp;
6033 int disabled_shlib_breaks = 0;
6035 /* SunOS a.out shared libraries are always mapped, so do not
6036 disable breakpoints; they will only be reported as unloaded
6037 through clear_solib when GDB discards its shared library
6038 list. See clear_solib for more information. */
6039 if (exec_bfd != NULL
6040 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6043 ALL_BP_LOCATIONS (loc, locp_tmp)
6045 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6046 struct breakpoint *b = loc->owner;
6048 if ((loc->loc_type == bp_loc_hardware_breakpoint
6049 || loc->loc_type == bp_loc_software_breakpoint)
6050 && solib->pspace == loc->pspace
6051 && !loc->shlib_disabled
6052 && (b->type == bp_breakpoint
6053 || b->type == bp_jit_event
6054 || b->type == bp_hardware_breakpoint)
6055 && solib_contains_address_p (solib, loc->address))
6057 loc->shlib_disabled = 1;
6058 /* At this point, we cannot rely on remove_breakpoint
6059 succeeding so we must mark the breakpoint as not inserted
6060 to prevent future errors occurring in remove_breakpoints. */
6063 /* This may cause duplicate notifications for the same breakpoint. */
6064 observer_notify_breakpoint_modified (b);
6066 if (!disabled_shlib_breaks)
6068 target_terminal_ours_for_output ();
6069 warning (_("Temporarily disabling breakpoints "
6070 "for unloaded shared library \"%s\""),
6073 disabled_shlib_breaks = 1;
6078 /* FORK & VFORK catchpoints. */
6080 /* An instance of this type is used to represent a fork or vfork
6081 catchpoint. It includes a "struct breakpoint" as a kind of base
6082 class; users downcast to "struct breakpoint *" when needed. A
6083 breakpoint is really of this type iff its ops pointer points to
6084 CATCH_FORK_BREAKPOINT_OPS. */
6086 struct fork_catchpoint
6088 /* The base class. */
6089 struct breakpoint base;
6091 /* Process id of a child process whose forking triggered this
6092 catchpoint. This field is only valid immediately after this
6093 catchpoint has triggered. */
6094 ptid_t forked_inferior_pid;
6097 /* Implement the "insert" breakpoint_ops method for fork
6101 insert_catch_fork (struct bp_location *bl)
6103 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
6106 /* Implement the "remove" breakpoint_ops method for fork
6110 remove_catch_fork (struct bp_location *bl)
6112 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
6115 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6119 breakpoint_hit_catch_fork (const struct bp_location *bl,
6120 struct address_space *aspace, CORE_ADDR bp_addr)
6122 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6124 return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid);
6127 /* Implement the "print_it" breakpoint_ops method for fork
6130 static enum print_stop_action
6131 print_it_catch_fork (bpstat bs)
6133 struct breakpoint *b = bs->breakpoint_at;
6134 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
6136 annotate_catchpoint (b->number);
6137 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6138 b->number, ptid_get_pid (c->forked_inferior_pid));
6139 return PRINT_SRC_AND_LOC;
6142 /* Implement the "print_one" breakpoint_ops method for fork
6146 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
6148 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6149 struct value_print_options opts;
6151 get_user_print_options (&opts);
6153 /* Field 4, the address, is omitted (which makes the columns not
6154 line up too nicely with the headers, but the effect is relatively
6156 if (opts.addressprint)
6157 ui_out_field_skip (uiout, "addr");
6159 ui_out_text (uiout, "fork");
6160 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6162 ui_out_text (uiout, ", process ");
6163 ui_out_field_int (uiout, "what",
6164 ptid_get_pid (c->forked_inferior_pid));
6165 ui_out_spaces (uiout, 1);
6169 /* Implement the "print_mention" breakpoint_ops method for fork
6173 print_mention_catch_fork (struct breakpoint *b)
6175 printf_filtered (_("Catchpoint %d (fork)"), b->number);
6178 /* Implement the "print_recreate" breakpoint_ops method for fork
6182 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
6184 fprintf_unfiltered (fp, "catch fork");
6185 print_recreate_thread (b, fp);
6188 /* The breakpoint_ops structure to be used in fork catchpoints. */
6190 static struct breakpoint_ops catch_fork_breakpoint_ops;
6192 /* Implement the "insert" breakpoint_ops method for vfork
6196 insert_catch_vfork (struct bp_location *bl)
6198 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
6201 /* Implement the "remove" breakpoint_ops method for vfork
6205 remove_catch_vfork (struct bp_location *bl)
6207 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
6210 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6214 breakpoint_hit_catch_vfork (const struct bp_location *bl,
6215 struct address_space *aspace, CORE_ADDR bp_addr)
6217 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
6219 return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid);
6222 /* Implement the "print_it" breakpoint_ops method for vfork
6225 static enum print_stop_action
6226 print_it_catch_vfork (bpstat bs)
6228 struct breakpoint *b = bs->breakpoint_at;
6229 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6231 annotate_catchpoint (b->number);
6232 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6233 b->number, ptid_get_pid (c->forked_inferior_pid));
6234 return PRINT_SRC_AND_LOC;
6237 /* Implement the "print_one" breakpoint_ops method for vfork
6241 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
6243 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
6244 struct value_print_options opts;
6246 get_user_print_options (&opts);
6247 /* Field 4, the address, is omitted (which makes the columns not
6248 line up too nicely with the headers, but the effect is relatively
6250 if (opts.addressprint)
6251 ui_out_field_skip (uiout, "addr");
6253 ui_out_text (uiout, "vfork");
6254 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
6256 ui_out_text (uiout, ", process ");
6257 ui_out_field_int (uiout, "what",
6258 ptid_get_pid (c->forked_inferior_pid));
6259 ui_out_spaces (uiout, 1);
6263 /* Implement the "print_mention" breakpoint_ops method for vfork
6267 print_mention_catch_vfork (struct breakpoint *b)
6269 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6272 /* Implement the "print_recreate" breakpoint_ops method for vfork
6276 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6278 fprintf_unfiltered (fp, "catch vfork");
6279 print_recreate_thread (b, fp);
6282 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6284 static struct breakpoint_ops catch_vfork_breakpoint_ops;
6286 /* An instance of this type is used to represent a syscall catchpoint.
6287 It includes a "struct breakpoint" as a kind of base class; users
6288 downcast to "struct breakpoint *" when needed. A breakpoint is
6289 really of this type iff its ops pointer points to
6290 CATCH_SYSCALL_BREAKPOINT_OPS. */
6292 struct syscall_catchpoint
6294 /* The base class. */
6295 struct breakpoint base;
6297 /* Syscall numbers used for the 'catch syscall' feature. If no
6298 syscall has been specified for filtering, its value is NULL.
6299 Otherwise, it holds a list of all syscalls to be caught. The
6300 list elements are allocated with xmalloc. */
6301 VEC(int) *syscalls_to_be_caught;
6304 /* Implement the "dtor" breakpoint_ops method for syscall
6308 dtor_catch_syscall (struct breakpoint *b)
6310 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6312 VEC_free (int, c->syscalls_to_be_caught);
6314 base_breakpoint_ops.dtor (b);
6317 /* Implement the "insert" breakpoint_ops method for syscall
6321 insert_catch_syscall (struct bp_location *bl)
6323 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6324 struct inferior *inf = current_inferior ();
6326 ++inf->total_syscalls_count;
6327 if (!c->syscalls_to_be_caught)
6328 ++inf->any_syscall_count;
6334 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6339 if (iter >= VEC_length (int, inf->syscalls_counts))
6341 int old_size = VEC_length (int, inf->syscalls_counts);
6342 uintptr_t vec_addr_offset
6343 = old_size * ((uintptr_t) sizeof (int));
6345 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6346 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6348 memset ((void *) vec_addr, 0,
6349 (iter + 1 - old_size) * sizeof (int));
6351 elem = VEC_index (int, inf->syscalls_counts, iter);
6352 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6356 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6357 inf->total_syscalls_count != 0,
6358 inf->any_syscall_count,
6359 VEC_length (int, inf->syscalls_counts),
6360 VEC_address (int, inf->syscalls_counts));
6363 /* Implement the "remove" breakpoint_ops method for syscall
6367 remove_catch_syscall (struct bp_location *bl)
6369 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
6370 struct inferior *inf = current_inferior ();
6372 --inf->total_syscalls_count;
6373 if (!c->syscalls_to_be_caught)
6374 --inf->any_syscall_count;
6380 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6384 if (iter >= VEC_length (int, inf->syscalls_counts))
6385 /* Shouldn't happen. */
6387 elem = VEC_index (int, inf->syscalls_counts, iter);
6388 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6392 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6393 inf->total_syscalls_count != 0,
6394 inf->any_syscall_count,
6395 VEC_length (int, inf->syscalls_counts),
6397 inf->syscalls_counts));
6400 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6404 breakpoint_hit_catch_syscall (const struct bp_location *bl,
6405 struct address_space *aspace, CORE_ADDR bp_addr)
6407 /* We must check if we are catching specific syscalls in this
6408 breakpoint. If we are, then we must guarantee that the called
6409 syscall is the same syscall we are catching. */
6410 int syscall_number = 0;
6411 const struct syscall_catchpoint *c
6412 = (const struct syscall_catchpoint *) bl->owner;
6414 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6417 /* Now, checking if the syscall is the same. */
6418 if (c->syscalls_to_be_caught)
6423 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6425 if (syscall_number == iter)
6435 /* Implement the "print_it" breakpoint_ops method for syscall
6438 static enum print_stop_action
6439 print_it_catch_syscall (bpstat bs)
6441 struct breakpoint *b = bs->breakpoint_at;
6442 /* These are needed because we want to know in which state a
6443 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6444 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6445 must print "called syscall" or "returned from syscall". */
6447 struct target_waitstatus last;
6449 struct cleanup *old_chain;
6452 get_last_target_status (&ptid, &last);
6454 get_syscall_by_number (last.value.syscall_number, &s);
6456 annotate_catchpoint (b->number);
6459 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6461 syscall_id = xstrprintf ("'%s'", s.name);
6463 old_chain = make_cleanup (xfree, syscall_id);
6465 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6466 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6467 b->number, syscall_id);
6468 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6469 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6470 b->number, syscall_id);
6472 do_cleanups (old_chain);
6474 return PRINT_SRC_AND_LOC;
6477 /* Implement the "print_one" breakpoint_ops method for syscall
6481 print_one_catch_syscall (struct breakpoint *b,
6482 struct bp_location **last_loc)
6484 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6485 struct value_print_options opts;
6487 get_user_print_options (&opts);
6488 /* Field 4, the address, is omitted (which makes the columns not
6489 line up too nicely with the headers, but the effect is relatively
6491 if (opts.addressprint)
6492 ui_out_field_skip (uiout, "addr");
6495 if (c->syscalls_to_be_caught
6496 && VEC_length (int, c->syscalls_to_be_caught) > 1)
6497 ui_out_text (uiout, "syscalls \"");
6499 ui_out_text (uiout, "syscall \"");
6501 if (c->syscalls_to_be_caught)
6504 char *text = xstrprintf ("%s", "");
6507 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6512 get_syscall_by_number (iter, &s);
6515 text = xstrprintf ("%s%s, ", text, s.name);
6517 text = xstrprintf ("%s%d, ", text, iter);
6519 /* We have to xfree the last 'text' (now stored at 'x')
6520 because xstrprintf dynamically allocates new space for it
6524 /* Remove the last comma. */
6525 text[strlen (text) - 2] = '\0';
6526 ui_out_field_string (uiout, "what", text);
6529 ui_out_field_string (uiout, "what", "<any syscall>");
6530 ui_out_text (uiout, "\" ");
6533 /* Implement the "print_mention" breakpoint_ops method for syscall
6537 print_mention_catch_syscall (struct breakpoint *b)
6539 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6541 if (c->syscalls_to_be_caught)
6545 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
6546 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6548 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6551 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6555 get_syscall_by_number (iter, &s);
6558 printf_filtered (" '%s' [%d]", s.name, s.number);
6560 printf_filtered (" %d", s.number);
6562 printf_filtered (")");
6565 printf_filtered (_("Catchpoint %d (any syscall)"),
6569 /* Implement the "print_recreate" breakpoint_ops method for syscall
6573 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6575 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
6577 fprintf_unfiltered (fp, "catch syscall");
6579 if (c->syscalls_to_be_caught)
6584 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6589 get_syscall_by_number (iter, &s);
6591 fprintf_unfiltered (fp, " %s", s.name);
6593 fprintf_unfiltered (fp, " %d", s.number);
6596 print_recreate_thread (b, fp);
6599 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6601 static struct breakpoint_ops catch_syscall_breakpoint_ops;
6603 /* Returns non-zero if 'b' is a syscall catchpoint. */
6606 syscall_catchpoint_p (struct breakpoint *b)
6608 return (b->ops == &catch_syscall_breakpoint_ops);
6611 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6612 is non-zero, then make the breakpoint temporary. If COND_STRING is
6613 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6614 the breakpoint_ops structure associated to the catchpoint. */
6617 init_catchpoint (struct breakpoint *b,
6618 struct gdbarch *gdbarch, int tempflag,
6620 const struct breakpoint_ops *ops)
6622 struct symtab_and_line sal;
6625 sal.pspace = current_program_space;
6627 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
6629 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6630 b->disposition = tempflag ? disp_del : disp_donttouch;
6634 install_breakpoint (int internal, struct breakpoint *b)
6636 add_to_breakpoint_chain (b);
6637 set_breakpoint_number (internal, b);
6640 observer_notify_breakpoint_created (b);
6641 update_global_location_list (1);
6645 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6646 int tempflag, char *cond_string,
6647 const struct breakpoint_ops *ops)
6649 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
6651 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
6653 c->forked_inferior_pid = null_ptid;
6655 install_breakpoint (0, &c->base);
6658 /* Exec catchpoints. */
6660 /* An instance of this type is used to represent an exec catchpoint.
6661 It includes a "struct breakpoint" as a kind of base class; users
6662 downcast to "struct breakpoint *" when needed. A breakpoint is
6663 really of this type iff its ops pointer points to
6664 CATCH_EXEC_BREAKPOINT_OPS. */
6666 struct exec_catchpoint
6668 /* The base class. */
6669 struct breakpoint base;
6671 /* Filename of a program whose exec triggered this catchpoint.
6672 This field is only valid immediately after this catchpoint has
6674 char *exec_pathname;
6677 /* Implement the "dtor" breakpoint_ops method for exec
6681 dtor_catch_exec (struct breakpoint *b)
6683 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6685 xfree (c->exec_pathname);
6687 base_breakpoint_ops.dtor (b);
6691 insert_catch_exec (struct bp_location *bl)
6693 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6697 remove_catch_exec (struct bp_location *bl)
6699 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6703 breakpoint_hit_catch_exec (const struct bp_location *bl,
6704 struct address_space *aspace, CORE_ADDR bp_addr)
6706 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
6708 return inferior_has_execd (inferior_ptid, &c->exec_pathname);
6711 static enum print_stop_action
6712 print_it_catch_exec (bpstat bs)
6714 struct breakpoint *b = bs->breakpoint_at;
6715 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6717 annotate_catchpoint (b->number);
6718 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6720 return PRINT_SRC_AND_LOC;
6724 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6726 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
6727 struct value_print_options opts;
6729 get_user_print_options (&opts);
6731 /* Field 4, the address, is omitted (which makes the columns
6732 not line up too nicely with the headers, but the effect
6733 is relatively readable). */
6734 if (opts.addressprint)
6735 ui_out_field_skip (uiout, "addr");
6737 ui_out_text (uiout, "exec");
6738 if (c->exec_pathname != NULL)
6740 ui_out_text (uiout, ", program \"");
6741 ui_out_field_string (uiout, "what", c->exec_pathname);
6742 ui_out_text (uiout, "\" ");
6747 print_mention_catch_exec (struct breakpoint *b)
6749 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6752 /* Implement the "print_recreate" breakpoint_ops method for exec
6756 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6758 fprintf_unfiltered (fp, "catch exec");
6759 print_recreate_thread (b, fp);
6762 static struct breakpoint_ops catch_exec_breakpoint_ops;
6765 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6766 const struct breakpoint_ops *ops)
6768 struct syscall_catchpoint *c;
6769 struct gdbarch *gdbarch = get_current_arch ();
6771 c = XNEW (struct syscall_catchpoint);
6772 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
6773 c->syscalls_to_be_caught = filter;
6775 install_breakpoint (0, &c->base);
6779 hw_breakpoint_used_count (void)
6782 struct breakpoint *b;
6783 struct bp_location *bl;
6787 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6788 for (bl = b->loc; bl; bl = bl->next)
6790 /* Special types of hardware breakpoints may use more than
6792 i += b->ops->resources_needed (bl);
6800 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
6803 struct breakpoint *b;
6804 struct bp_location *bl;
6806 *other_type_used = 0;
6809 if (!breakpoint_enabled (b))
6812 if (b->type == type)
6813 for (bl = b->loc; bl; bl = bl->next)
6815 /* Special types of hardware watchpoints may use more than
6817 i += b->ops->resources_needed (bl);
6819 else if (is_hardware_watchpoint (b))
6820 *other_type_used = 1;
6827 disable_watchpoints_before_interactive_call_start (void)
6829 struct breakpoint *b;
6833 if (is_watchpoint (b) && breakpoint_enabled (b))
6835 b->enable_state = bp_call_disabled;
6836 update_global_location_list (0);
6842 enable_watchpoints_after_interactive_call_stop (void)
6844 struct breakpoint *b;
6848 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6850 b->enable_state = bp_enabled;
6851 update_global_location_list (1);
6857 disable_breakpoints_before_startup (void)
6859 struct breakpoint *b;
6864 if (b->pspace != current_program_space)
6867 if ((b->type == bp_breakpoint
6868 || b->type == bp_hardware_breakpoint)
6869 && breakpoint_enabled (b))
6871 b->enable_state = bp_startup_disabled;
6877 update_global_location_list (0);
6879 current_program_space->executing_startup = 1;
6883 enable_breakpoints_after_startup (void)
6885 struct breakpoint *b;
6888 current_program_space->executing_startup = 0;
6892 if (b->pspace != current_program_space)
6895 if ((b->type == bp_breakpoint
6896 || b->type == bp_hardware_breakpoint)
6897 && b->enable_state == bp_startup_disabled)
6899 b->enable_state = bp_enabled;
6905 breakpoint_re_set ();
6909 /* Set a breakpoint that will evaporate an end of command
6910 at address specified by SAL.
6911 Restrict it to frame FRAME if FRAME is nonzero. */
6914 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6915 struct frame_id frame_id, enum bptype type)
6917 struct breakpoint *b;
6919 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6921 gdb_assert (!frame_id_inlined_p (frame_id));
6923 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
6924 b->enable_state = bp_enabled;
6925 b->disposition = disp_donttouch;
6926 b->frame_id = frame_id;
6928 /* If we're debugging a multi-threaded program, then we want
6929 momentary breakpoints to be active in only a single thread of
6931 if (in_thread_list (inferior_ptid))
6932 b->thread = pid_to_thread_id (inferior_ptid);
6934 update_global_location_list_nothrow (1);
6939 /* Make a momentary breakpoint based on the master breakpoint ORIG.
6940 The new breakpoint will have type TYPE, and use OPS as it
6943 static struct breakpoint *
6944 momentary_breakpoint_from_master (struct breakpoint *orig,
6946 const struct breakpoint_ops *ops)
6948 struct breakpoint *copy;
6950 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
6951 copy->loc = allocate_bp_location (copy);
6952 set_breakpoint_location_function (copy->loc, 1);
6954 copy->loc->gdbarch = orig->loc->gdbarch;
6955 copy->loc->requested_address = orig->loc->requested_address;
6956 copy->loc->address = orig->loc->address;
6957 copy->loc->section = orig->loc->section;
6958 copy->loc->pspace = orig->loc->pspace;
6960 if (orig->source_file == NULL)
6961 copy->source_file = NULL;
6963 copy->source_file = xstrdup (orig->source_file);
6965 copy->line_number = orig->line_number;
6966 copy->frame_id = orig->frame_id;
6967 copy->thread = orig->thread;
6968 copy->pspace = orig->pspace;
6970 copy->enable_state = bp_enabled;
6971 copy->disposition = disp_donttouch;
6972 copy->number = internal_breakpoint_number--;
6974 update_global_location_list_nothrow (0);
6978 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6982 clone_momentary_breakpoint (struct breakpoint *orig)
6984 /* If there's nothing to clone, then return nothing. */
6988 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
6992 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
6995 struct symtab_and_line sal;
6997 sal = find_pc_line (pc, 0);
6999 sal.section = find_pc_overlay (pc);
7000 sal.explicit_pc = 1;
7002 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
7006 /* Tell the user we have just set a breakpoint B. */
7009 mention (struct breakpoint *b)
7011 b->ops->print_mention (b);
7012 if (ui_out_is_mi_like_p (uiout))
7014 printf_filtered ("\n");
7018 static struct bp_location *
7019 add_location_to_breakpoint (struct breakpoint *b,
7020 const struct symtab_and_line *sal)
7022 struct bp_location *loc, **tmp;
7024 loc = allocate_bp_location (b);
7025 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
7028 loc->gdbarch = get_sal_arch (*sal);
7030 loc->gdbarch = b->gdbarch;
7031 loc->requested_address = sal->pc;
7032 loc->address = adjust_breakpoint_address (loc->gdbarch,
7033 loc->requested_address, b->type);
7034 loc->pspace = sal->pspace;
7035 gdb_assert (loc->pspace != NULL);
7036 loc->section = sal->section;
7038 set_breakpoint_location_function (loc,
7039 sal->explicit_pc || sal->explicit_line);
7044 /* Return 1 if LOC is pointing to a permanent breakpoint,
7045 return 0 otherwise. */
7048 bp_loc_is_permanent (struct bp_location *loc)
7052 const gdb_byte *brk;
7053 gdb_byte *target_mem;
7054 struct cleanup *cleanup;
7057 gdb_assert (loc != NULL);
7059 addr = loc->address;
7060 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
7062 /* Software breakpoints unsupported? */
7066 target_mem = alloca (len);
7068 /* Enable the automatic memory restoration from breakpoints while
7069 we read the memory. Otherwise we could say about our temporary
7070 breakpoints they are permanent. */
7071 cleanup = save_current_space_and_thread ();
7073 switch_to_program_space_and_thread (loc->pspace);
7074 make_show_memory_breakpoints_cleanup (0);
7076 if (target_read_memory (loc->address, target_mem, len) == 0
7077 && memcmp (target_mem, brk, len) == 0)
7080 do_cleanups (cleanup);
7087 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7088 as textual description of the location, and COND_STRING
7089 as condition expression. */
7092 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
7093 struct symtabs_and_lines sals, char *addr_string,
7095 enum bptype type, enum bpdisp disposition,
7096 int thread, int task, int ignore_count,
7097 const struct breakpoint_ops *ops, int from_tty,
7098 int enabled, int internal, int display_canonical)
7102 if (type == bp_hardware_breakpoint)
7104 int i = hw_breakpoint_used_count ();
7105 int target_resources_ok =
7106 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
7108 if (target_resources_ok == 0)
7109 error (_("No hardware breakpoint support in the target."));
7110 else if (target_resources_ok < 0)
7111 error (_("Hardware breakpoints used exceeds limit."));
7114 gdb_assert (sals.nelts > 0);
7116 for (i = 0; i < sals.nelts; ++i)
7118 struct symtab_and_line sal = sals.sals[i];
7119 struct bp_location *loc;
7123 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7125 loc_gdbarch = gdbarch;
7127 describe_other_breakpoints (loc_gdbarch,
7128 sal.pspace, sal.pc, sal.section, thread);
7133 init_raw_breakpoint (b, gdbarch, sal, type, ops);
7137 b->cond_string = cond_string;
7138 b->ignore_count = ignore_count;
7139 b->enable_state = enabled ? bp_enabled : bp_disabled;
7140 b->disposition = disposition;
7141 b->pspace = sals.sals[0].pspace;
7143 if (type == bp_static_tracepoint)
7145 struct tracepoint *t = (struct tracepoint *) b;
7146 struct static_tracepoint_marker marker;
7148 if (is_marker_spec (addr_string))
7150 /* We already know the marker exists, otherwise, we
7151 wouldn't see a sal for it. */
7152 char *p = &addr_string[3];
7157 p = skip_spaces (p);
7159 endp = skip_to_space (p);
7161 marker_str = savestring (p, endp - p);
7162 t->static_trace_marker_id = marker_str;
7164 printf_filtered (_("Probed static tracepoint "
7166 t->static_trace_marker_id);
7168 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
7170 t->static_trace_marker_id = xstrdup (marker.str_id);
7171 release_static_tracepoint_marker (&marker);
7173 printf_filtered (_("Probed static tracepoint "
7175 t->static_trace_marker_id);
7178 warning (_("Couldn't determine the static "
7179 "tracepoint marker to probe"));
7182 if (enabled && b->pspace->executing_startup
7183 && (b->type == bp_breakpoint
7184 || b->type == bp_hardware_breakpoint))
7185 b->enable_state = bp_startup_disabled;
7191 loc = add_location_to_breakpoint (b, &sal);
7194 if (bp_loc_is_permanent (loc))
7195 make_breakpoint_permanent (b);
7199 char *arg = b->cond_string;
7200 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7202 error (_("Garbage %s follows condition"), arg);
7206 b->display_canonical = display_canonical;
7208 b->addr_string = addr_string;
7210 /* addr_string has to be used or breakpoint_re_set will delete
7213 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7217 create_breakpoint_sal (struct gdbarch *gdbarch,
7218 struct symtabs_and_lines sals, char *addr_string,
7220 enum bptype type, enum bpdisp disposition,
7221 int thread, int task, int ignore_count,
7222 const struct breakpoint_ops *ops, int from_tty,
7223 int enabled, int internal, int display_canonical)
7225 struct breakpoint *b;
7226 struct cleanup *old_chain;
7228 if (is_tracepoint_type (type))
7230 struct tracepoint *t;
7232 t = XCNEW (struct tracepoint);
7236 b = XNEW (struct breakpoint);
7238 old_chain = make_cleanup (xfree, b);
7240 init_breakpoint_sal (b, gdbarch,
7244 thread, task, ignore_count,
7246 enabled, internal, display_canonical);
7247 discard_cleanups (old_chain);
7249 install_breakpoint (internal, b);
7252 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7253 elements to fill the void space. */
7255 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7257 int i = index_to_remove+1;
7258 int last_index = sal->nelts-1;
7260 for (;i <= last_index; ++i)
7261 sal->sals[i-1] = sal->sals[i];
7266 /* If appropriate, obtains all sals that correspond to the same file
7267 and line as SAL, in all program spaces. Users debugging with IDEs,
7268 will want to set a breakpoint at foo.c:line, and not really care
7269 about program spaces. This is done only if SAL does not have
7270 explicit PC and has line and file information. If we got just a
7271 single expanded sal, return the original.
7273 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7274 which the name of enclosing function is different from SAL. This
7275 makes sure that if we have breakpoint originally set in template
7276 instantiation, say foo<int>(), we won't expand SAL to locations at
7277 the same line in all existing instantiations of 'foo'. */
7279 static struct symtabs_and_lines
7280 expand_line_sal_maybe (struct symtab_and_line sal)
7282 struct symtabs_and_lines expanded;
7283 CORE_ADDR original_pc = sal.pc;
7284 char *original_function = NULL;
7287 struct cleanup *old_chain;
7289 /* If we have explicit pc, don't expand.
7290 If we have no line number, we can't expand. */
7291 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7294 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7295 expanded.sals[0] = sal;
7301 old_chain = save_current_space_and_thread ();
7303 switch_to_program_space_and_thread (sal.pspace);
7305 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7307 /* Note that expand_line_sal visits *all* program spaces. */
7308 expanded = expand_line_sal (sal);
7310 if (expanded.nelts == 1)
7312 /* We had one sal, we got one sal. Return that sal, adjusting it
7313 past the function prologue if necessary. */
7314 xfree (expanded.sals);
7316 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7317 sal.pc = original_pc;
7318 expanded.sals[0] = sal;
7319 skip_prologue_sal (&expanded.sals[0]);
7320 do_cleanups (old_chain);
7324 if (!sal.explicit_line)
7326 CORE_ADDR func_addr, func_end;
7327 for (i = 0; i < expanded.nelts; ++i)
7329 CORE_ADDR pc = expanded.sals[i].pc;
7330 char *this_function;
7332 /* We need to switch threads as well since we're about to
7334 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7336 if (find_pc_partial_function (pc, &this_function,
7337 &func_addr, &func_end))
7340 && strcmp (this_function, original_function) != 0)
7342 remove_sal (&expanded, i);
7349 /* Skip the function prologue if necessary. */
7350 for (i = 0; i < expanded.nelts; ++i)
7351 skip_prologue_sal (&expanded.sals[i]);
7353 do_cleanups (old_chain);
7355 if (expanded.nelts <= 1)
7357 /* This is an ugly workaround. If we get zero expanded sals
7358 then something is really wrong. Fix that by returning the
7361 xfree (expanded.sals);
7363 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7364 sal.pc = original_pc;
7365 expanded.sals[0] = sal;
7372 for (i = 0; i < expanded.nelts; ++i)
7373 if (expanded.sals[i].pc == original_pc)
7384 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7385 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7386 value. COND_STRING, if not NULL, specified the condition to be
7387 used for all breakpoints. Essentially the only case where
7388 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7389 function. In that case, it's still not possible to specify
7390 separate conditions for different overloaded functions, so
7391 we take just a single condition string.
7393 NOTE: If the function succeeds, the caller is expected to cleanup
7394 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7395 array contents). If the function fails (error() is called), the
7396 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7397 COND and SALS arrays and each of those arrays contents. */
7400 create_breakpoints_sal (struct gdbarch *gdbarch,
7401 struct symtabs_and_lines sals,
7402 struct linespec_result *canonical,
7404 enum bptype type, enum bpdisp disposition,
7405 int thread, int task, int ignore_count,
7406 const struct breakpoint_ops *ops, int from_tty,
7407 int enabled, int internal)
7411 for (i = 0; i < sals.nelts; ++i)
7413 struct symtabs_and_lines expanded =
7414 expand_line_sal_maybe (sals.sals[i]);
7416 create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i],
7417 cond_string, type, disposition,
7418 thread, task, ignore_count, ops,
7419 from_tty, enabled, internal,
7420 canonical->special_display);
7424 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7425 followed by conditionals. On return, SALS contains an array of SAL
7426 addresses found. ADDR_STRING contains a vector of (canonical)
7427 address strings. ADDRESS points to the end of the SAL.
7429 The array and the line spec strings are allocated on the heap, it is
7430 the caller's responsibility to free them. */
7433 parse_breakpoint_sals (char **address,
7434 struct symtabs_and_lines *sals,
7435 struct linespec_result *canonical)
7437 char *addr_start = *address;
7439 /* If no arg given, or if first arg is 'if ', use the default
7441 if ((*address) == NULL
7442 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7444 if (default_breakpoint_valid)
7446 struct symtab_and_line sal;
7448 init_sal (&sal); /* Initialize to zeroes. */
7449 sals->sals = (struct symtab_and_line *)
7450 xmalloc (sizeof (struct symtab_and_line));
7451 sal.pc = default_breakpoint_address;
7452 sal.line = default_breakpoint_line;
7453 sal.symtab = default_breakpoint_symtab;
7454 sal.pspace = default_breakpoint_pspace;
7455 sal.section = find_pc_overlay (sal.pc);
7457 /* "break" without arguments is equivalent to "break *PC"
7458 where PC is the default_breakpoint_address. So make sure
7459 to set sal.explicit_pc to prevent GDB from trying to
7460 expand the list of sals to include all other instances
7461 with the same symtab and line. */
7462 sal.explicit_pc = 1;
7464 sals->sals[0] = sal;
7468 error (_("No default breakpoint address now."));
7472 /* Force almost all breakpoints to be in terms of the
7473 current_source_symtab (which is decode_line_1's default).
7474 This should produce the results we want almost all of the
7475 time while leaving default_breakpoint_* alone.
7477 ObjC: However, don't match an Objective-C method name which
7478 may have a '+' or '-' succeeded by a '[' */
7480 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7482 if (default_breakpoint_valid
7484 || ((strchr ("+-", (*address)[0]) != NULL)
7485 && ((*address)[1] != '['))))
7486 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
7487 default_breakpoint_line, canonical);
7489 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7492 /* For any SAL that didn't have a canonical string, fill one in. */
7493 if (sals->nelts > 0 && canonical->canonical == NULL)
7494 canonical->canonical = xcalloc (sals->nelts, sizeof (char *));
7495 if (addr_start != (*address))
7499 for (i = 0; i < sals->nelts; i++)
7501 /* Add the string if not present. */
7502 if (canonical->canonical[i] == NULL)
7503 canonical->canonical[i] = savestring (addr_start,
7504 (*address) - addr_start);
7510 /* Convert each SAL into a real PC. Verify that the PC can be
7511 inserted as a breakpoint. If it can't throw an error. */
7514 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7518 for (i = 0; i < sals->nelts; i++)
7519 resolve_sal_pc (&sals->sals[i]);
7522 /* Fast tracepoints may have restrictions on valid locations. For
7523 instance, a fast tracepoint using a jump instead of a trap will
7524 likely have to overwrite more bytes than a trap would, and so can
7525 only be placed where the instruction is longer than the jump, or a
7526 multi-instruction sequence does not have a jump into the middle of
7530 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7531 struct symtabs_and_lines *sals)
7534 struct symtab_and_line *sal;
7536 struct cleanup *old_chain;
7538 for (i = 0; i < sals->nelts; i++)
7540 sal = &sals->sals[i];
7542 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7544 old_chain = make_cleanup (xfree, msg);
7547 error (_("May not have a fast tracepoint at 0x%s%s"),
7548 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7550 do_cleanups (old_chain);
7554 /* Given TOK, a string specification of condition and thread, as
7555 accepted by the 'break' command, extract the condition
7556 string and thread number and set *COND_STRING and *THREAD.
7557 PC identifies the context at which the condition should be parsed.
7558 If no condition is found, *COND_STRING is set to NULL.
7559 If no thread is found, *THREAD is set to -1. */
7561 find_condition_and_thread (char *tok, CORE_ADDR pc,
7562 char **cond_string, int *thread, int *task)
7564 *cond_string = NULL;
7570 char *cond_start = NULL;
7571 char *cond_end = NULL;
7573 tok = skip_spaces (tok);
7575 end_tok = skip_to_space (tok);
7577 toklen = end_tok - tok;
7579 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7581 struct expression *expr;
7583 tok = cond_start = end_tok + 1;
7584 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7587 *cond_string = savestring (cond_start,
7588 cond_end - cond_start);
7590 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7596 *thread = strtol (tok, &tok, 0);
7598 error (_("Junk after thread keyword."));
7599 if (!valid_thread_id (*thread))
7600 error (_("Unknown thread %d."), *thread);
7602 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7608 *task = strtol (tok, &tok, 0);
7610 error (_("Junk after task keyword."));
7611 if (!valid_task_id (*task))
7612 error (_("Unknown task %d."), *task);
7615 error (_("Junk at end of arguments."));
7619 /* Decode a static tracepoint marker spec. */
7621 static struct symtabs_and_lines
7622 decode_static_tracepoint_spec (char **arg_p)
7624 VEC(static_tracepoint_marker_p) *markers = NULL;
7625 struct symtabs_and_lines sals;
7626 struct symtab_and_line sal;
7628 struct cleanup *old_chain;
7629 char *p = &(*arg_p)[3];
7634 p = skip_spaces (p);
7636 endp = skip_to_space (p);
7638 marker_str = savestring (p, endp - p);
7639 old_chain = make_cleanup (xfree, marker_str);
7641 markers = target_static_tracepoint_markers_by_strid (marker_str);
7642 if (VEC_empty(static_tracepoint_marker_p, markers))
7643 error (_("No known static tracepoint marker named %s"), marker_str);
7645 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
7646 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
7648 for (i = 0; i < sals.nelts; i++)
7650 struct static_tracepoint_marker *marker;
7652 marker = VEC_index (static_tracepoint_marker_p, markers, i);
7654 init_sal (&sals.sals[i]);
7656 sals.sals[i] = find_pc_line (marker->address, 0);
7657 sals.sals[i].pc = marker->address;
7659 release_static_tracepoint_marker (marker);
7662 do_cleanups (old_chain);
7668 /* Set a breakpoint. This function is shared between CLI and MI
7669 functions for setting a breakpoint. This function has two major
7670 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7671 parameter. If non-zero, the function will parse arg, extracting
7672 breakpoint location, address and thread. Otherwise, ARG is just
7673 the location of breakpoint, with condition and thread specified by
7674 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7675 the breakpoint number will be allocated from the internal
7676 breakpoint count. Returns true if any breakpoint was created;
7680 create_breakpoint (struct gdbarch *gdbarch,
7681 char *arg, char *cond_string, int thread,
7682 int parse_condition_and_thread,
7683 int tempflag, enum bptype type_wanted,
7685 enum auto_boolean pending_break_support,
7686 const struct breakpoint_ops *ops,
7687 int from_tty, int enabled, int internal)
7689 volatile struct gdb_exception e;
7690 struct symtabs_and_lines sals;
7691 struct symtab_and_line pending_sal;
7693 char *addr_start = arg;
7694 struct linespec_result canonical;
7695 struct cleanup *old_chain;
7696 struct cleanup *bkpt_chain = NULL;
7700 int prev_bkpt_count = breakpoint_count;
7702 gdb_assert (ops != NULL);
7706 init_linespec_result (&canonical);
7708 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
7712 sals = decode_static_tracepoint_spec (&arg);
7714 copy_arg = savestring (addr_start, arg - addr_start);
7715 canonical.canonical = xcalloc (sals.nelts, sizeof (char *));
7716 for (i = 0; i < sals.nelts; i++)
7717 canonical.canonical[i] = xstrdup (copy_arg);
7721 TRY_CATCH (e, RETURN_MASK_ALL)
7723 parse_breakpoint_sals (&arg, &sals, &canonical);
7726 /* If caller is interested in rc value from parse, set value. */
7730 throw_exception (e);
7734 case NOT_FOUND_ERROR:
7736 /* If pending breakpoint support is turned off, throw
7739 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7740 throw_exception (e);
7742 exception_print (gdb_stderr, e);
7744 /* If pending breakpoint support is auto query and the user
7745 selects no, then simply return the error code. */
7746 if (pending_break_support == AUTO_BOOLEAN_AUTO
7747 && !nquery (_("Make breakpoint pending on "
7748 "future shared library load? ")))
7751 /* At this point, either the user was queried about setting
7752 a pending breakpoint and selected yes, or pending
7753 breakpoint behavior is on and thus a pending breakpoint
7754 is defaulted on behalf of the user. */
7755 copy_arg = xstrdup (addr_start);
7756 canonical.canonical = ©_arg;
7758 sals.sals = &pending_sal;
7763 throw_exception (e);
7773 /* Create a chain of things that always need to be cleaned up. */
7774 old_chain = make_cleanup (null_cleanup, 0);
7778 /* Make sure that all storage allocated to SALS gets freed. */
7779 make_cleanup (xfree, sals.sals);
7781 /* Cleanup the canonical array but not its contents. */
7782 make_cleanup (xfree, canonical.canonical);
7785 /* ----------------------------- SNIP -----------------------------
7786 Anything added to the cleanup chain beyond this point is assumed
7787 to be part of a breakpoint. If the breakpoint create succeeds
7788 then the memory is not reclaimed. */
7789 bkpt_chain = make_cleanup (null_cleanup, 0);
7791 /* Mark the contents of the canonical for cleanup. These go on
7792 the bkpt_chain and only occur if the breakpoint create fails. */
7793 for (i = 0; i < sals.nelts; i++)
7795 if (canonical.canonical[i] != NULL)
7796 make_cleanup (xfree, canonical.canonical[i]);
7799 /* Resolve all line numbers to PC's and verify that the addresses
7800 are ok for the target. */
7802 breakpoint_sals_to_pc (&sals);
7804 /* Fast tracepoints may have additional restrictions on location. */
7805 if (type_wanted == bp_fast_tracepoint)
7806 check_fast_tracepoint_sals (gdbarch, &sals);
7808 /* Verify that condition can be parsed, before setting any
7809 breakpoints. Allocate a separate condition expression for each
7813 if (parse_condition_and_thread)
7815 /* Here we only parse 'arg' to separate condition
7816 from thread number, so parsing in context of first
7817 sal is OK. When setting the breakpoint we'll
7818 re-parse it in context of each sal. */
7821 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7824 make_cleanup (xfree, cond_string);
7828 /* Create a private copy of condition string. */
7831 cond_string = xstrdup (cond_string);
7832 make_cleanup (xfree, cond_string);
7836 /* If the user is creating a static tracepoint by marker id
7837 (strace -m MARKER_ID), then store the sals index, so that
7838 breakpoint_re_set can try to match up which of the newly
7839 found markers corresponds to this one, and, don't try to
7840 expand multiple locations for each sal, given than SALS
7841 already should contain all sals for MARKER_ID. */
7842 if (type_wanted == bp_static_tracepoint
7843 && is_marker_spec (canonical.canonical[0]))
7847 for (i = 0; i < sals.nelts; ++i)
7849 struct symtabs_and_lines expanded;
7850 struct tracepoint *tp;
7851 struct cleanup *old_chain;
7854 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7855 expanded.sals[0] = sals.sals[i];
7856 old_chain = make_cleanup (xfree, expanded.sals);
7858 tp = XCNEW (struct tracepoint);
7859 init_breakpoint_sal (&tp->base, gdbarch, expanded,
7860 canonical.canonical[i],
7861 cond_string, type_wanted,
7862 tempflag ? disp_del : disp_donttouch,
7863 thread, task, ignore_count, ops,
7864 from_tty, enabled, internal,
7865 canonical.special_display);
7866 /* Given that its possible to have multiple markers with
7867 the same string id, if the user is creating a static
7868 tracepoint by marker id ("strace -m MARKER_ID"), then
7869 store the sals index, so that breakpoint_re_set can
7870 try to match up which of the newly found markers
7871 corresponds to this one */
7872 tp->static_trace_marker_id_idx = i;
7874 install_breakpoint (internal, &tp->base);
7876 do_cleanups (old_chain);
7880 create_breakpoints_sal (gdbarch, sals, &canonical, cond_string,
7882 tempflag ? disp_del : disp_donttouch,
7883 thread, task, ignore_count, ops, from_tty,
7888 struct breakpoint *b;
7890 make_cleanup (xfree, copy_arg);
7892 b = set_raw_breakpoint_without_location (gdbarch, type_wanted, ops);
7893 set_breakpoint_number (internal, b);
7895 b->addr_string = canonical.canonical[0];
7896 b->cond_string = NULL;
7897 b->ignore_count = ignore_count;
7898 b->disposition = tempflag ? disp_del : disp_donttouch;
7899 b->condition_not_parsed = 1;
7900 b->enable_state = enabled ? bp_enabled : bp_disabled;
7901 b->pspace = current_program_space;
7902 b->py_bp_object = NULL;
7904 if (enabled && b->pspace->executing_startup
7905 && (b->type == bp_breakpoint
7906 || b->type == bp_hardware_breakpoint))
7907 b->enable_state = bp_startup_disabled;
7910 /* Do not mention breakpoints with a negative number,
7911 but do notify observers. */
7913 observer_notify_breakpoint_created (b);
7918 warning (_("Multiple breakpoints were set.\nUse the "
7919 "\"delete\" command to delete unwanted breakpoints."));
7920 prev_breakpoint_count = prev_bkpt_count;
7923 /* That's it. Discard the cleanups for data inserted into the
7925 discard_cleanups (bkpt_chain);
7926 /* But cleanup everything else. */
7927 do_cleanups (old_chain);
7929 /* error call may happen here - have BKPT_CHAIN already discarded. */
7930 update_global_location_list (1);
7935 /* Set a breakpoint.
7936 ARG is a string describing breakpoint address,
7937 condition, and thread.
7938 FLAG specifies if a breakpoint is hardware on,
7939 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7943 break_command_1 (char *arg, int flag, int from_tty)
7945 int tempflag = flag & BP_TEMPFLAG;
7946 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
7947 ? bp_hardware_breakpoint
7950 create_breakpoint (get_current_arch (),
7952 NULL, 0, 1 /* parse arg */,
7953 tempflag, type_wanted,
7954 0 /* Ignore count */,
7955 pending_break_support,
7956 &bkpt_breakpoint_ops,
7962 /* Helper function for break_command_1 and disassemble_command. */
7965 resolve_sal_pc (struct symtab_and_line *sal)
7969 if (sal->pc == 0 && sal->symtab != NULL)
7971 if (!find_line_pc (sal->symtab, sal->line, &pc))
7972 error (_("No line %d in file \"%s\"."),
7973 sal->line, sal->symtab->filename);
7976 /* If this SAL corresponds to a breakpoint inserted using a line
7977 number, then skip the function prologue if necessary. */
7978 if (sal->explicit_line)
7979 skip_prologue_sal (sal);
7982 if (sal->section == 0 && sal->symtab != NULL)
7984 struct blockvector *bv;
7988 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
7991 sym = block_linkage_function (b);
7994 fixup_symbol_section (sym, sal->symtab->objfile);
7995 sal->section = SYMBOL_OBJ_SECTION (sym);
7999 /* It really is worthwhile to have the section, so we'll
8000 just have to look harder. This case can be executed
8001 if we have line numbers but no functions (as can
8002 happen in assembly source). */
8004 struct minimal_symbol *msym;
8005 struct cleanup *old_chain = save_current_space_and_thread ();
8007 switch_to_program_space_and_thread (sal->pspace);
8009 msym = lookup_minimal_symbol_by_pc (sal->pc);
8011 sal->section = SYMBOL_OBJ_SECTION (msym);
8013 do_cleanups (old_chain);
8020 break_command (char *arg, int from_tty)
8022 break_command_1 (arg, 0, from_tty);
8026 tbreak_command (char *arg, int from_tty)
8028 break_command_1 (arg, BP_TEMPFLAG, from_tty);
8032 hbreak_command (char *arg, int from_tty)
8034 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
8038 thbreak_command (char *arg, int from_tty)
8040 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
8044 stop_command (char *arg, int from_tty)
8046 printf_filtered (_("Specify the type of breakpoint to set.\n\
8047 Usage: stop in <function | address>\n\
8048 stop at <line>\n"));
8052 stopin_command (char *arg, int from_tty)
8056 if (arg == (char *) NULL)
8058 else if (*arg != '*')
8063 /* Look for a ':'. If this is a line number specification, then
8064 say it is bad, otherwise, it should be an address or
8065 function/method name. */
8066 while (*argptr && !hasColon)
8068 hasColon = (*argptr == ':');
8073 badInput = (*argptr != ':'); /* Not a class::method */
8075 badInput = isdigit (*arg); /* a simple line number */
8079 printf_filtered (_("Usage: stop in <function | address>\n"));
8081 break_command_1 (arg, 0, from_tty);
8085 stopat_command (char *arg, int from_tty)
8089 if (arg == (char *) NULL || *arg == '*') /* no line number */
8096 /* Look for a ':'. If there is a '::' then get out, otherwise
8097 it is probably a line number. */
8098 while (*argptr && !hasColon)
8100 hasColon = (*argptr == ':');
8105 badInput = (*argptr == ':'); /* we have class::method */
8107 badInput = !isdigit (*arg); /* not a line number */
8111 printf_filtered (_("Usage: stop at <line>\n"));
8113 break_command_1 (arg, 0, from_tty);
8116 /* Implement the "breakpoint_hit" breakpoint_ops method for
8117 ranged breakpoints. */
8120 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
8121 struct address_space *aspace,
8124 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
8125 bl->length, aspace, bp_addr);
8128 /* Implement the "resources_needed" breakpoint_ops method for
8129 ranged breakpoints. */
8132 resources_needed_ranged_breakpoint (const struct bp_location *bl)
8134 return target_ranged_break_num_registers ();
8137 /* Implement the "print_it" breakpoint_ops method for
8138 ranged breakpoints. */
8140 static enum print_stop_action
8141 print_it_ranged_breakpoint (bpstat bs)
8143 struct breakpoint *b = bs->breakpoint_at;
8144 struct bp_location *bl = b->loc;
8146 gdb_assert (b->type == bp_hardware_breakpoint);
8148 /* Ranged breakpoints have only one location. */
8149 gdb_assert (bl && bl->next == NULL);
8151 annotate_breakpoint (b->number);
8152 if (b->disposition == disp_del)
8153 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
8155 ui_out_text (uiout, "\nRanged breakpoint ");
8156 if (ui_out_is_mi_like_p (uiout))
8158 ui_out_field_string (uiout, "reason",
8159 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8160 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8162 ui_out_field_int (uiout, "bkptno", b->number);
8163 ui_out_text (uiout, ", ");
8165 return PRINT_SRC_AND_LOC;
8168 /* Implement the "print_one" breakpoint_ops method for
8169 ranged breakpoints. */
8172 print_one_ranged_breakpoint (struct breakpoint *b,
8173 struct bp_location **last_loc)
8175 struct bp_location *bl = b->loc;
8176 struct value_print_options opts;
8178 /* Ranged breakpoints have only one location. */
8179 gdb_assert (bl && bl->next == NULL);
8181 get_user_print_options (&opts);
8183 if (opts.addressprint)
8184 /* We don't print the address range here, it will be printed later
8185 by print_one_detail_ranged_breakpoint. */
8186 ui_out_field_skip (uiout, "addr");
8188 print_breakpoint_location (b, bl);
8192 /* Implement the "print_one_detail" breakpoint_ops method for
8193 ranged breakpoints. */
8196 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
8197 struct ui_out *uiout)
8199 CORE_ADDR address_start, address_end;
8200 struct bp_location *bl = b->loc;
8201 struct ui_stream *stb = ui_out_stream_new (uiout);
8202 struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb);
8206 address_start = bl->address;
8207 address_end = address_start + bl->length - 1;
8209 ui_out_text (uiout, "\taddress range: ");
8210 fprintf_unfiltered (stb->stream, "[%s, %s]",
8211 print_core_address (bl->gdbarch, address_start),
8212 print_core_address (bl->gdbarch, address_end));
8213 ui_out_field_stream (uiout, "addr", stb);
8214 ui_out_text (uiout, "\n");
8216 do_cleanups (cleanup);
8219 /* Implement the "print_mention" breakpoint_ops method for
8220 ranged breakpoints. */
8223 print_mention_ranged_breakpoint (struct breakpoint *b)
8225 struct bp_location *bl = b->loc;
8228 gdb_assert (b->type == bp_hardware_breakpoint);
8230 if (ui_out_is_mi_like_p (uiout))
8233 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8234 b->number, paddress (bl->gdbarch, bl->address),
8235 paddress (bl->gdbarch, bl->address + bl->length - 1));
8238 /* Implement the "print_recreate" breakpoint_ops method for
8239 ranged breakpoints. */
8242 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
8244 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
8245 b->addr_string_range_end);
8246 print_recreate_thread (b, fp);
8249 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8251 static struct breakpoint_ops ranged_breakpoint_ops;
8253 /* Find the address where the end of the breakpoint range should be
8254 placed, given the SAL of the end of the range. This is so that if
8255 the user provides a line number, the end of the range is set to the
8256 last instruction of the given line. */
8259 find_breakpoint_range_end (struct symtab_and_line sal)
8263 /* If the user provided a PC value, use it. Otherwise,
8264 find the address of the end of the given location. */
8265 if (sal.explicit_pc)
8272 ret = find_line_pc_range (sal, &start, &end);
8274 error (_("Could not find location of the end of the range."));
8276 /* find_line_pc_range returns the start of the next line. */
8283 /* Implement the "break-range" CLI command. */
8286 break_range_command (char *arg, int from_tty)
8288 char *arg_start, *addr_string_start, *addr_string_end;
8289 struct linespec_result canonical_start, canonical_end;
8290 int bp_count, can_use_bp, length;
8292 struct breakpoint *b;
8293 struct symtab_and_line sal_start, sal_end;
8294 struct symtabs_and_lines sals_start, sals_end;
8295 struct cleanup *cleanup_bkpt;
8297 /* We don't support software ranged breakpoints. */
8298 if (target_ranged_break_num_registers () < 0)
8299 error (_("This target does not support hardware ranged breakpoints."));
8301 bp_count = hw_breakpoint_used_count ();
8302 bp_count += target_ranged_break_num_registers ();
8303 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8306 error (_("Hardware breakpoints used exceeds limit."));
8308 if (arg == NULL || arg[0] == '\0')
8309 error(_("No address range specified."));
8311 sals_start.sals = NULL;
8312 sals_start.nelts = 0;
8313 init_linespec_result (&canonical_start);
8315 while (*arg == ' ' || *arg == '\t')
8318 parse_breakpoint_sals (&arg, &sals_start, &canonical_start);
8320 sal_start = sals_start.sals[0];
8321 addr_string_start = canonical_start.canonical[0];
8322 cleanup_bkpt = make_cleanup (xfree, addr_string_start);
8323 xfree (sals_start.sals);
8324 xfree (canonical_start.canonical);
8327 error (_("Too few arguments."));
8328 else if (sals_start.nelts == 0)
8329 error (_("Could not find location of the beginning of the range."));
8330 else if (sals_start.nelts != 1)
8331 error (_("Cannot create a ranged breakpoint with multiple locations."));
8333 resolve_sal_pc (&sal_start);
8335 arg++; /* Skip the comma. */
8336 while (*arg == ' ' || *arg == '\t')
8339 /* Parse the end location. */
8341 sals_end.sals = NULL;
8343 init_linespec_result (&canonical_end);
8346 /* We call decode_line_1 directly here instead of using
8347 parse_breakpoint_sals because we need to specify the start location's
8348 symtab and line as the default symtab and line for the end of the
8349 range. This makes it possible to have ranges like "foo.c:27, +14",
8350 where +14 means 14 lines from the start location. */
8351 sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line,
8354 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8355 if (canonical_end.canonical == NULL)
8356 canonical_end.canonical = xcalloc (1, sizeof (char *));
8357 /* Add the string if not present. */
8358 if (arg_start != arg && canonical_end.canonical[0] == NULL)
8359 canonical_end.canonical[0] = savestring (arg_start, arg - arg_start);
8361 sal_end = sals_end.sals[0];
8362 addr_string_end = canonical_end.canonical[0];
8363 make_cleanup (xfree, addr_string_end);
8364 xfree (sals_end.sals);
8365 xfree (canonical_end.canonical);
8367 if (sals_end.nelts == 0)
8368 error (_("Could not find location of the end of the range."));
8369 else if (sals_end.nelts != 1)
8370 error (_("Cannot create a ranged breakpoint with multiple locations."));
8372 resolve_sal_pc (&sal_end);
8374 end = find_breakpoint_range_end (sal_end);
8375 if (sal_start.pc > end)
8376 error (_("Invalid address range, end precedes start."));
8378 length = end - sal_start.pc + 1;
8380 /* Length overflowed. */
8381 error (_("Address range too large."));
8382 else if (length == 1)
8384 /* This range is simple enough to be handled by
8385 the `hbreak' command. */
8386 hbreak_command (addr_string_start, 1);
8388 do_cleanups (cleanup_bkpt);
8393 /* Now set up the breakpoint. */
8394 b = set_raw_breakpoint (get_current_arch (), sal_start,
8395 bp_hardware_breakpoint, &ranged_breakpoint_ops);
8396 set_breakpoint_count (breakpoint_count + 1);
8397 b->number = breakpoint_count;
8398 b->disposition = disp_donttouch;
8399 b->addr_string = addr_string_start;
8400 b->addr_string_range_end = addr_string_end;
8401 b->loc->length = length;
8403 discard_cleanups (cleanup_bkpt);
8406 observer_notify_breakpoint_created (b);
8407 update_global_location_list (1);
8410 /* Return non-zero if EXP is verified as constant. Returned zero
8411 means EXP is variable. Also the constant detection may fail for
8412 some constant expressions and in such case still falsely return
8415 watchpoint_exp_is_const (const struct expression *exp)
8423 /* We are only interested in the descriptor of each element. */
8424 operator_length (exp, i, &oplenp, &argsp);
8427 switch (exp->elts[i].opcode)
8437 case BINOP_LOGICAL_AND:
8438 case BINOP_LOGICAL_OR:
8439 case BINOP_BITWISE_AND:
8440 case BINOP_BITWISE_IOR:
8441 case BINOP_BITWISE_XOR:
8443 case BINOP_NOTEQUAL:
8459 case TERNOP_SLICE_COUNT:
8471 case OP_OBJC_NSSTRING:
8474 case UNOP_LOGICAL_NOT:
8475 case UNOP_COMPLEMENT:
8478 /* Unary, binary and ternary operators: We have to check
8479 their operands. If they are constant, then so is the
8480 result of that operation. For instance, if A and B are
8481 determined to be constants, then so is "A + B".
8483 UNOP_IND is one exception to the rule above, because the
8484 value of *ADDR is not necessarily a constant, even when
8489 /* Check whether the associated symbol is a constant.
8491 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8492 possible that a buggy compiler could mark a variable as
8493 constant even when it is not, and TYPE_CONST would return
8494 true in this case, while SYMBOL_CLASS wouldn't.
8496 We also have to check for function symbols because they
8497 are always constant. */
8499 struct symbol *s = exp->elts[i + 2].symbol;
8501 if (SYMBOL_CLASS (s) != LOC_BLOCK
8502 && SYMBOL_CLASS (s) != LOC_CONST
8503 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
8508 /* The default action is to return 0 because we are using
8509 the optimistic approach here: If we don't know something,
8510 then it is not a constant. */
8519 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8522 dtor_watchpoint (struct breakpoint *self)
8524 struct watchpoint *w = (struct watchpoint *) self;
8526 xfree (w->cond_exp);
8528 xfree (w->exp_string);
8529 xfree (w->exp_string_reparse);
8530 value_free (w->val);
8532 base_breakpoint_ops.dtor (self);
8535 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8538 re_set_watchpoint (struct breakpoint *b)
8540 struct watchpoint *w = (struct watchpoint *) b;
8542 /* Watchpoint can be either on expression using entirely global
8543 variables, or it can be on local variables.
8545 Watchpoints of the first kind are never auto-deleted, and even
8546 persist across program restarts. Since they can use variables
8547 from shared libraries, we need to reparse expression as libraries
8548 are loaded and unloaded.
8550 Watchpoints on local variables can also change meaning as result
8551 of solib event. For example, if a watchpoint uses both a local
8552 and a global variables in expression, it's a local watchpoint,
8553 but unloading of a shared library will make the expression
8554 invalid. This is not a very common use case, but we still
8555 re-evaluate expression, to avoid surprises to the user.
8557 Note that for local watchpoints, we re-evaluate it only if
8558 watchpoints frame id is still valid. If it's not, it means the
8559 watchpoint is out of scope and will be deleted soon. In fact,
8560 I'm not sure we'll ever be called in this case.
8562 If a local watchpoint's frame id is still valid, then
8563 w->exp_valid_block is likewise valid, and we can safely use it.
8565 Don't do anything about disabled watchpoints, since they will be
8566 reevaluated again when enabled. */
8567 update_watchpoint (w, 1 /* reparse */);
8570 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8573 insert_watchpoint (struct bp_location *bl)
8575 struct watchpoint *w = (struct watchpoint *) bl->owner;
8576 int length = w->exact ? 1 : bl->length;
8578 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
8582 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8585 remove_watchpoint (struct bp_location *bl)
8587 struct watchpoint *w = (struct watchpoint *) bl->owner;
8588 int length = w->exact ? 1 : bl->length;
8590 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
8595 breakpoint_hit_watchpoint (const struct bp_location *bl,
8596 struct address_space *aspace, CORE_ADDR bp_addr)
8598 struct breakpoint *b = bl->owner;
8599 struct watchpoint *w = (struct watchpoint *) b;
8601 /* Continuable hardware watchpoints are treated as non-existent if the
8602 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8603 some data address). Otherwise gdb won't stop on a break instruction
8604 in the code (not from a breakpoint) when a hardware watchpoint has
8605 been defined. Also skip watchpoints which we know did not trigger
8606 (did not match the data address). */
8607 if (is_hardware_watchpoint (b)
8608 && w->watchpoint_triggered == watch_triggered_no)
8615 check_status_watchpoint (bpstat bs)
8617 gdb_assert (is_watchpoint (bs->breakpoint_at));
8619 bpstat_check_watchpoint (bs);
8622 /* Implement the "resources_needed" breakpoint_ops method for
8623 hardware watchpoints. */
8626 resources_needed_watchpoint (const struct bp_location *bl)
8628 struct watchpoint *w = (struct watchpoint *) bl->owner;
8629 int length = w->exact? 1 : bl->length;
8631 return target_region_ok_for_hw_watchpoint (bl->address, length);
8634 /* Implement the "works_in_software_mode" breakpoint_ops method for
8635 hardware watchpoints. */
8638 works_in_software_mode_watchpoint (const struct breakpoint *b)
8640 return b->type == bp_hardware_watchpoint;
8643 static enum print_stop_action
8644 print_it_watchpoint (bpstat bs)
8646 struct cleanup *old_chain;
8647 struct breakpoint *b;
8648 const struct bp_location *bl;
8649 struct ui_stream *stb;
8650 enum print_stop_action result;
8651 struct watchpoint *w;
8653 gdb_assert (bs->bp_location_at != NULL);
8655 bl = bs->bp_location_at;
8656 b = bs->breakpoint_at;
8657 w = (struct watchpoint *) b;
8659 stb = ui_out_stream_new (uiout);
8660 old_chain = make_cleanup_ui_out_stream_delete (stb);
8665 case bp_hardware_watchpoint:
8666 annotate_watchpoint (b->number);
8667 if (ui_out_is_mi_like_p (uiout))
8670 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
8672 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8673 ui_out_text (uiout, "\nOld value = ");
8674 watchpoint_value_print (bs->old_val, stb->stream);
8675 ui_out_field_stream (uiout, "old", stb);
8676 ui_out_text (uiout, "\nNew value = ");
8677 watchpoint_value_print (w->val, stb->stream);
8678 ui_out_field_stream (uiout, "new", stb);
8679 ui_out_text (uiout, "\n");
8680 /* More than one watchpoint may have been triggered. */
8681 result = PRINT_UNKNOWN;
8684 case bp_read_watchpoint:
8685 if (ui_out_is_mi_like_p (uiout))
8688 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
8690 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8691 ui_out_text (uiout, "\nValue = ");
8692 watchpoint_value_print (w->val, stb->stream);
8693 ui_out_field_stream (uiout, "value", stb);
8694 ui_out_text (uiout, "\n");
8695 result = PRINT_UNKNOWN;
8698 case bp_access_watchpoint:
8699 if (bs->old_val != NULL)
8701 annotate_watchpoint (b->number);
8702 if (ui_out_is_mi_like_p (uiout))
8705 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8707 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8708 ui_out_text (uiout, "\nOld value = ");
8709 watchpoint_value_print (bs->old_val, stb->stream);
8710 ui_out_field_stream (uiout, "old", stb);
8711 ui_out_text (uiout, "\nNew value = ");
8716 if (ui_out_is_mi_like_p (uiout))
8719 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8720 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8721 ui_out_text (uiout, "\nValue = ");
8723 watchpoint_value_print (w->val, stb->stream);
8724 ui_out_field_stream (uiout, "new", stb);
8725 ui_out_text (uiout, "\n");
8726 result = PRINT_UNKNOWN;
8729 result = PRINT_UNKNOWN;
8732 do_cleanups (old_chain);
8736 /* Implement the "print_mention" breakpoint_ops method for hardware
8740 print_mention_watchpoint (struct breakpoint *b)
8742 struct cleanup *ui_out_chain;
8743 struct watchpoint *w = (struct watchpoint *) b;
8748 ui_out_text (uiout, "Watchpoint ");
8749 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
8751 case bp_hardware_watchpoint:
8752 ui_out_text (uiout, "Hardware watchpoint ");
8753 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
8755 case bp_read_watchpoint:
8756 ui_out_text (uiout, "Hardware read watchpoint ");
8757 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
8759 case bp_access_watchpoint:
8760 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
8761 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
8764 internal_error (__FILE__, __LINE__,
8765 _("Invalid hardware watchpoint type."));
8768 ui_out_field_int (uiout, "number", b->number);
8769 ui_out_text (uiout, ": ");
8770 ui_out_field_string (uiout, "exp", w->exp_string);
8771 do_cleanups (ui_out_chain);
8774 /* Implement the "print_recreate" breakpoint_ops method for
8778 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
8780 struct watchpoint *w = (struct watchpoint *) b;
8785 case bp_hardware_watchpoint:
8786 fprintf_unfiltered (fp, "watch");
8788 case bp_read_watchpoint:
8789 fprintf_unfiltered (fp, "rwatch");
8791 case bp_access_watchpoint:
8792 fprintf_unfiltered (fp, "awatch");
8795 internal_error (__FILE__, __LINE__,
8796 _("Invalid watchpoint type."));
8799 fprintf_unfiltered (fp, " %s", w->exp_string);
8800 print_recreate_thread (b, fp);
8803 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8805 static struct breakpoint_ops watchpoint_breakpoint_ops;
8807 /* Implement the "insert" breakpoint_ops method for
8808 masked hardware watchpoints. */
8811 insert_masked_watchpoint (struct bp_location *bl)
8813 struct watchpoint *w = (struct watchpoint *) bl->owner;
8815 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
8816 bl->watchpoint_type);
8819 /* Implement the "remove" breakpoint_ops method for
8820 masked hardware watchpoints. */
8823 remove_masked_watchpoint (struct bp_location *bl)
8825 struct watchpoint *w = (struct watchpoint *) bl->owner;
8827 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
8828 bl->watchpoint_type);
8831 /* Implement the "resources_needed" breakpoint_ops method for
8832 masked hardware watchpoints. */
8835 resources_needed_masked_watchpoint (const struct bp_location *bl)
8837 struct watchpoint *w = (struct watchpoint *) bl->owner;
8839 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
8842 /* Implement the "works_in_software_mode" breakpoint_ops method for
8843 masked hardware watchpoints. */
8846 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
8851 /* Implement the "print_it" breakpoint_ops method for
8852 masked hardware watchpoints. */
8854 static enum print_stop_action
8855 print_it_masked_watchpoint (bpstat bs)
8857 struct breakpoint *b = bs->breakpoint_at;
8859 /* Masked watchpoints have only one location. */
8860 gdb_assert (b->loc && b->loc->next == NULL);
8864 case bp_hardware_watchpoint:
8865 annotate_watchpoint (b->number);
8866 if (ui_out_is_mi_like_p (uiout))
8869 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
8872 case bp_read_watchpoint:
8873 if (ui_out_is_mi_like_p (uiout))
8876 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
8879 case bp_access_watchpoint:
8880 if (ui_out_is_mi_like_p (uiout))
8883 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
8886 internal_error (__FILE__, __LINE__,
8887 _("Invalid hardware watchpoint type."));
8891 ui_out_text (uiout, _("\n\
8892 Check the underlying instruction at PC for the memory\n\
8893 address and value which triggered this watchpoint.\n"));
8894 ui_out_text (uiout, "\n");
8896 /* More than one watchpoint may have been triggered. */
8897 return PRINT_UNKNOWN;
8900 /* Implement the "print_one_detail" breakpoint_ops method for
8901 masked hardware watchpoints. */
8904 print_one_detail_masked_watchpoint (const struct breakpoint *b,
8905 struct ui_out *uiout)
8907 struct watchpoint *w = (struct watchpoint *) b;
8909 /* Masked watchpoints have only one location. */
8910 gdb_assert (b->loc && b->loc->next == NULL);
8912 ui_out_text (uiout, "\tmask ");
8913 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
8914 ui_out_text (uiout, "\n");
8917 /* Implement the "print_mention" breakpoint_ops method for
8918 masked hardware watchpoints. */
8921 print_mention_masked_watchpoint (struct breakpoint *b)
8923 struct watchpoint *w = (struct watchpoint *) b;
8924 struct cleanup *ui_out_chain;
8928 case bp_hardware_watchpoint:
8929 ui_out_text (uiout, "Masked hardware watchpoint ");
8930 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
8932 case bp_read_watchpoint:
8933 ui_out_text (uiout, "Masked hardware read watchpoint ");
8934 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
8936 case bp_access_watchpoint:
8937 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
8938 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
8941 internal_error (__FILE__, __LINE__,
8942 _("Invalid hardware watchpoint type."));
8945 ui_out_field_int (uiout, "number", b->number);
8946 ui_out_text (uiout, ": ");
8947 ui_out_field_string (uiout, "exp", w->exp_string);
8948 do_cleanups (ui_out_chain);
8951 /* Implement the "print_recreate" breakpoint_ops method for
8952 masked hardware watchpoints. */
8955 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
8957 struct watchpoint *w = (struct watchpoint *) b;
8962 case bp_hardware_watchpoint:
8963 fprintf_unfiltered (fp, "watch");
8965 case bp_read_watchpoint:
8966 fprintf_unfiltered (fp, "rwatch");
8968 case bp_access_watchpoint:
8969 fprintf_unfiltered (fp, "awatch");
8972 internal_error (__FILE__, __LINE__,
8973 _("Invalid hardware watchpoint type."));
8976 sprintf_vma (tmp, w->hw_wp_mask);
8977 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
8978 print_recreate_thread (b, fp);
8981 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
8983 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
8985 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
8988 is_masked_watchpoint (const struct breakpoint *b)
8990 return b->ops == &masked_watchpoint_breakpoint_ops;
8993 /* accessflag: hw_write: watch write,
8994 hw_read: watch read,
8995 hw_access: watch access (read or write) */
8997 watch_command_1 (char *arg, int accessflag, int from_tty,
8998 int just_location, int internal)
9000 volatile struct gdb_exception e;
9001 struct breakpoint *b, *scope_breakpoint = NULL;
9002 struct expression *exp;
9003 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
9004 struct value *val, *mark, *result;
9005 struct frame_info *frame;
9006 char *exp_start = NULL;
9007 char *exp_end = NULL;
9008 char *tok, *end_tok;
9010 char *cond_start = NULL;
9011 char *cond_end = NULL;
9012 enum bptype bp_type;
9015 /* Flag to indicate whether we are going to use masks for
9016 the hardware watchpoint. */
9019 struct watchpoint *w;
9021 /* Make sure that we actually have parameters to parse. */
9022 if (arg != NULL && arg[0] != '\0')
9026 /* Look for "parameter value" pairs at the end
9027 of the arguments string. */
9028 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
9030 /* Skip whitespace at the end of the argument list. */
9031 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9034 /* Find the beginning of the last token.
9035 This is the value of the parameter. */
9036 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9038 value_start = tok + 1;
9040 /* Skip whitespace. */
9041 while (tok > arg && (*tok == ' ' || *tok == '\t'))
9046 /* Find the beginning of the second to last token.
9047 This is the parameter itself. */
9048 while (tok > arg && (*tok != ' ' && *tok != '\t'))
9051 toklen = end_tok - tok + 1;
9053 if (toklen == 6 && !strncmp (tok, "thread", 6))
9055 /* At this point we've found a "thread" token, which means
9056 the user is trying to set a watchpoint that triggers
9057 only in a specific thread. */
9061 error(_("You can specify only one thread."));
9063 /* Extract the thread ID from the next token. */
9064 thread = strtol (value_start, &endp, 0);
9066 /* Check if the user provided a valid numeric value for the
9068 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
9069 error (_("Invalid thread ID specification %s."), value_start);
9071 /* Check if the thread actually exists. */
9072 if (!valid_thread_id (thread))
9073 error (_("Unknown thread %d."), thread);
9075 else if (toklen == 4 && !strncmp (tok, "mask", 4))
9077 /* We've found a "mask" token, which means the user wants to
9078 create a hardware watchpoint that is going to have the mask
9080 struct value *mask_value, *mark;
9083 error(_("You can specify only one mask."));
9085 use_mask = just_location = 1;
9087 mark = value_mark ();
9088 mask_value = parse_to_comma_and_eval (&value_start);
9089 mask = value_as_address (mask_value);
9090 value_free_to_mark (mark);
9093 /* We didn't recognize what we found. We should stop here. */
9096 /* Truncate the string and get rid of the "parameter value" pair before
9097 the arguments string is parsed by the parse_exp_1 function. */
9102 /* Parse the rest of the arguments. */
9103 innermost_block = NULL;
9105 exp = parse_exp_1 (&arg, 0, 0);
9107 /* Remove trailing whitespace from the expression before saving it.
9108 This makes the eventual display of the expression string a bit
9110 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
9113 /* Checking if the expression is not constant. */
9114 if (watchpoint_exp_is_const (exp))
9118 len = exp_end - exp_start;
9119 while (len > 0 && isspace (exp_start[len - 1]))
9121 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
9124 exp_valid_block = innermost_block;
9125 mark = value_mark ();
9126 fetch_subexp_value (exp, &pc, &val, &result, NULL);
9132 exp_valid_block = NULL;
9133 val = value_addr (result);
9134 release_value (val);
9135 value_free_to_mark (mark);
9139 ret = target_masked_watch_num_registers (value_as_address (val),
9142 error (_("This target does not support masked watchpoints."));
9144 error (_("Invalid mask or memory region."));
9147 else if (val != NULL)
9148 release_value (val);
9150 tok = skip_spaces (arg);
9151 end_tok = skip_to_space (tok);
9153 toklen = end_tok - tok;
9154 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9156 struct expression *cond;
9158 innermost_block = NULL;
9159 tok = cond_start = end_tok + 1;
9160 cond = parse_exp_1 (&tok, 0, 0);
9162 /* The watchpoint expression may not be local, but the condition
9163 may still be. E.g.: `watch global if local > 0'. */
9164 cond_exp_valid_block = innermost_block;
9170 error (_("Junk at end of command."));
9172 if (accessflag == hw_read)
9173 bp_type = bp_read_watchpoint;
9174 else if (accessflag == hw_access)
9175 bp_type = bp_access_watchpoint;
9177 bp_type = bp_hardware_watchpoint;
9179 frame = block_innermost_frame (exp_valid_block);
9181 /* If the expression is "local", then set up a "watchpoint scope"
9182 breakpoint at the point where we've left the scope of the watchpoint
9183 expression. Create the scope breakpoint before the watchpoint, so
9184 that we will encounter it first in bpstat_stop_status. */
9185 if (exp_valid_block && frame)
9187 if (frame_id_p (frame_unwind_caller_id (frame)))
9190 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
9191 frame_unwind_caller_pc (frame),
9192 bp_watchpoint_scope,
9193 &momentary_breakpoint_ops);
9195 scope_breakpoint->enable_state = bp_enabled;
9197 /* Automatically delete the breakpoint when it hits. */
9198 scope_breakpoint->disposition = disp_del;
9200 /* Only break in the proper frame (help with recursion). */
9201 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
9203 /* Set the address at which we will stop. */
9204 scope_breakpoint->loc->gdbarch
9205 = frame_unwind_caller_arch (frame);
9206 scope_breakpoint->loc->requested_address
9207 = frame_unwind_caller_pc (frame);
9208 scope_breakpoint->loc->address
9209 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
9210 scope_breakpoint->loc->requested_address,
9211 scope_breakpoint->type);
9215 /* Now set up the breakpoint. */
9217 w = XCNEW (struct watchpoint);
9220 init_raw_breakpoint_without_location (b, NULL, bp_type,
9221 &masked_watchpoint_breakpoint_ops);
9223 init_raw_breakpoint_without_location (b, NULL, bp_type,
9224 &watchpoint_breakpoint_ops);
9226 b->disposition = disp_donttouch;
9227 b->pspace = current_program_space;
9229 w->exp_valid_block = exp_valid_block;
9230 w->cond_exp_valid_block = cond_exp_valid_block;
9233 struct type *t = value_type (val);
9234 CORE_ADDR addr = value_as_address (val);
9237 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
9238 name = type_to_string (t);
9240 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
9241 core_addr_to_string (addr));
9244 w->exp_string = xstrprintf ("-location %.*s",
9245 (int) (exp_end - exp_start), exp_start);
9247 /* The above expression is in C. */
9248 b->language = language_c;
9251 w->exp_string = savestring (exp_start, exp_end - exp_start);
9255 w->hw_wp_mask = mask;
9264 b->cond_string = savestring (cond_start, cond_end - cond_start);
9270 w->watchpoint_frame = get_frame_id (frame);
9271 w->watchpoint_thread = inferior_ptid;
9275 w->watchpoint_frame = null_frame_id;
9276 w->watchpoint_thread = null_ptid;
9279 if (scope_breakpoint != NULL)
9281 /* The scope breakpoint is related to the watchpoint. We will
9282 need to act on them together. */
9283 b->related_breakpoint = scope_breakpoint;
9284 scope_breakpoint->related_breakpoint = b;
9288 value_free_to_mark (mark);
9290 TRY_CATCH (e, RETURN_MASK_ALL)
9292 /* Finally update the new watchpoint. This creates the locations
9293 that should be inserted. */
9294 update_watchpoint (w, 1);
9298 delete_breakpoint (b);
9299 throw_exception (e);
9302 install_breakpoint (internal, b);
9305 /* Return count of debug registers needed to watch the given expression.
9306 If the watchpoint cannot be handled in hardware return zero. */
9309 can_use_hardware_watchpoint (struct value *v)
9311 int found_memory_cnt = 0;
9312 struct value *head = v;
9314 /* Did the user specifically forbid us to use hardware watchpoints? */
9315 if (!can_use_hw_watchpoints)
9318 /* Make sure that the value of the expression depends only upon
9319 memory contents, and values computed from them within GDB. If we
9320 find any register references or function calls, we can't use a
9321 hardware watchpoint.
9323 The idea here is that evaluating an expression generates a series
9324 of values, one holding the value of every subexpression. (The
9325 expression a*b+c has five subexpressions: a, b, a*b, c, and
9326 a*b+c.) GDB's values hold almost enough information to establish
9327 the criteria given above --- they identify memory lvalues,
9328 register lvalues, computed values, etcetera. So we can evaluate
9329 the expression, and then scan the chain of values that leaves
9330 behind to decide whether we can detect any possible change to the
9331 expression's final value using only hardware watchpoints.
9333 However, I don't think that the values returned by inferior
9334 function calls are special in any way. So this function may not
9335 notice that an expression involving an inferior function call
9336 can't be watched with hardware watchpoints. FIXME. */
9337 for (; v; v = value_next (v))
9339 if (VALUE_LVAL (v) == lval_memory)
9341 if (v != head && value_lazy (v))
9342 /* A lazy memory lvalue in the chain is one that GDB never
9343 needed to fetch; we either just used its address (e.g.,
9344 `a' in `a.b') or we never needed it at all (e.g., `a'
9345 in `a,b'). This doesn't apply to HEAD; if that is
9346 lazy then it was not readable, but watch it anyway. */
9350 /* Ahh, memory we actually used! Check if we can cover
9351 it with hardware watchpoints. */
9352 struct type *vtype = check_typedef (value_type (v));
9354 /* We only watch structs and arrays if user asked for it
9355 explicitly, never if they just happen to appear in a
9356 middle of some value chain. */
9358 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
9359 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
9361 CORE_ADDR vaddr = value_address (v);
9365 len = (target_exact_watchpoints
9366 && is_scalar_type_recursive (vtype))?
9367 1 : TYPE_LENGTH (value_type (v));
9369 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
9373 found_memory_cnt += num_regs;
9377 else if (VALUE_LVAL (v) != not_lval
9378 && deprecated_value_modifiable (v) == 0)
9379 return 0; /* These are values from the history (e.g., $1). */
9380 else if (VALUE_LVAL (v) == lval_register)
9381 return 0; /* Cannot watch a register with a HW watchpoint. */
9384 /* The expression itself looks suitable for using a hardware
9385 watchpoint, but give the target machine a chance to reject it. */
9386 return found_memory_cnt;
9390 watch_command_wrapper (char *arg, int from_tty, int internal)
9392 watch_command_1 (arg, hw_write, from_tty, 0, internal);
9395 /* A helper function that looks for an argument at the start of a
9396 string. The argument must also either be at the end of the string,
9397 or be followed by whitespace. Returns 1 if it finds the argument,
9398 0 otherwise. If the argument is found, it updates *STR. */
9401 check_for_argument (char **str, char *arg, int arg_len)
9403 if (strncmp (*str, arg, arg_len) == 0
9404 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
9412 /* A helper function that looks for the "-location" argument and then
9413 calls watch_command_1. */
9416 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
9418 int just_location = 0;
9421 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
9422 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
9424 arg = skip_spaces (arg);
9428 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
9432 watch_command (char *arg, int from_tty)
9434 watch_maybe_just_location (arg, hw_write, from_tty);
9438 rwatch_command_wrapper (char *arg, int from_tty, int internal)
9440 watch_command_1 (arg, hw_read, from_tty, 0, internal);
9444 rwatch_command (char *arg, int from_tty)
9446 watch_maybe_just_location (arg, hw_read, from_tty);
9450 awatch_command_wrapper (char *arg, int from_tty, int internal)
9452 watch_command_1 (arg, hw_access, from_tty, 0, internal);
9456 awatch_command (char *arg, int from_tty)
9458 watch_maybe_just_location (arg, hw_access, from_tty);
9462 /* Helper routines for the until_command routine in infcmd.c. Here
9463 because it uses the mechanisms of breakpoints. */
9465 struct until_break_command_continuation_args
9467 struct breakpoint *breakpoint;
9468 struct breakpoint *breakpoint2;
9472 /* This function is called by fetch_inferior_event via the
9473 cmd_continuation pointer, to complete the until command. It takes
9474 care of cleaning up the temporary breakpoints set up by the until
9477 until_break_command_continuation (void *arg, int err)
9479 struct until_break_command_continuation_args *a = arg;
9481 delete_breakpoint (a->breakpoint);
9483 delete_breakpoint (a->breakpoint2);
9484 delete_longjmp_breakpoint (a->thread_num);
9488 until_break_command (char *arg, int from_tty, int anywhere)
9490 struct symtabs_and_lines sals;
9491 struct symtab_and_line sal;
9492 struct frame_info *frame = get_selected_frame (NULL);
9493 struct breakpoint *breakpoint;
9494 struct breakpoint *breakpoint2 = NULL;
9495 struct cleanup *old_chain;
9497 struct thread_info *tp;
9499 clear_proceed_status ();
9501 /* Set a breakpoint where the user wants it and at return from
9504 if (default_breakpoint_valid)
9505 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
9506 default_breakpoint_line, NULL);
9508 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL);
9510 if (sals.nelts != 1)
9511 error (_("Couldn't get information on specified line."));
9514 xfree (sals.sals); /* malloc'd, so freed. */
9517 error (_("Junk at end of arguments."));
9519 resolve_sal_pc (&sal);
9522 /* If the user told us to continue until a specified location,
9523 we don't specify a frame at which we need to stop. */
9524 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9525 null_frame_id, bp_until);
9527 /* Otherwise, specify the selected frame, because we want to stop
9528 only at the very same frame. */
9529 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
9530 get_stack_frame_id (frame),
9533 old_chain = make_cleanup_delete_breakpoint (breakpoint);
9535 tp = inferior_thread ();
9538 /* Keep within the current frame, or in frames called by the current
9541 if (frame_id_p (frame_unwind_caller_id (frame)))
9543 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
9544 sal.pc = frame_unwind_caller_pc (frame);
9545 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
9547 frame_unwind_caller_id (frame),
9549 make_cleanup_delete_breakpoint (breakpoint2);
9551 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame));
9552 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
9555 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
9557 /* If we are running asynchronously, and proceed call above has
9558 actually managed to start the target, arrange for breakpoints to
9559 be deleted when the target stops. Otherwise, we're already
9560 stopped and delete breakpoints via cleanup chain. */
9562 if (target_can_async_p () && is_running (inferior_ptid))
9564 struct until_break_command_continuation_args *args;
9565 args = xmalloc (sizeof (*args));
9567 args->breakpoint = breakpoint;
9568 args->breakpoint2 = breakpoint2;
9569 args->thread_num = thread;
9571 discard_cleanups (old_chain);
9572 add_continuation (inferior_thread (),
9573 until_break_command_continuation, args,
9577 do_cleanups (old_chain);
9580 /* This function attempts to parse an optional "if <cond>" clause
9581 from the arg string. If one is not found, it returns NULL.
9583 Else, it returns a pointer to the condition string. (It does not
9584 attempt to evaluate the string against a particular block.) And,
9585 it updates arg to point to the first character following the parsed
9586 if clause in the arg string. */
9589 ep_parse_optional_if_clause (char **arg)
9593 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
9596 /* Skip the "if" keyword. */
9599 /* Skip any extra leading whitespace, and record the start of the
9600 condition string. */
9601 *arg = skip_spaces (*arg);
9604 /* Assume that the condition occupies the remainder of the arg
9606 (*arg) += strlen (cond_string);
9611 /* Commands to deal with catching events, such as signals, exceptions,
9612 process start/exit, etc. */
9616 catch_fork_temporary, catch_vfork_temporary,
9617 catch_fork_permanent, catch_vfork_permanent
9622 catch_fork_command_1 (char *arg, int from_tty,
9623 struct cmd_list_element *command)
9625 struct gdbarch *gdbarch = get_current_arch ();
9626 char *cond_string = NULL;
9627 catch_fork_kind fork_kind;
9630 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
9631 tempflag = (fork_kind == catch_fork_temporary
9632 || fork_kind == catch_vfork_temporary);
9636 arg = skip_spaces (arg);
9638 /* The allowed syntax is:
9640 catch [v]fork if <cond>
9642 First, check if there's an if clause. */
9643 cond_string = ep_parse_optional_if_clause (&arg);
9645 if ((*arg != '\0') && !isspace (*arg))
9646 error (_("Junk at end of arguments."));
9648 /* If this target supports it, create a fork or vfork catchpoint
9649 and enable reporting of such events. */
9652 case catch_fork_temporary:
9653 case catch_fork_permanent:
9654 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
9655 &catch_fork_breakpoint_ops);
9657 case catch_vfork_temporary:
9658 case catch_vfork_permanent:
9659 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
9660 &catch_vfork_breakpoint_ops);
9663 error (_("unsupported or unknown fork kind; cannot catch it"));
9669 catch_exec_command_1 (char *arg, int from_tty,
9670 struct cmd_list_element *command)
9672 struct exec_catchpoint *c;
9673 struct gdbarch *gdbarch = get_current_arch ();
9675 char *cond_string = NULL;
9677 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9681 arg = skip_spaces (arg);
9683 /* The allowed syntax is:
9685 catch exec if <cond>
9687 First, check if there's an if clause. */
9688 cond_string = ep_parse_optional_if_clause (&arg);
9690 if ((*arg != '\0') && !isspace (*arg))
9691 error (_("Junk at end of arguments."));
9693 c = XNEW (struct exec_catchpoint);
9694 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
9695 &catch_exec_breakpoint_ops);
9696 c->exec_pathname = NULL;
9698 install_breakpoint (0, &c->base);
9701 static enum print_stop_action
9702 print_it_exception_catchpoint (bpstat bs)
9704 struct breakpoint *b = bs->breakpoint_at;
9705 int bp_temp, bp_throw;
9707 annotate_catchpoint (b->number);
9709 bp_throw = strstr (b->addr_string, "throw") != NULL;
9710 if (b->loc->address != b->loc->requested_address)
9711 breakpoint_adjustment_warning (b->loc->requested_address,
9714 bp_temp = b->disposition == disp_del;
9716 bp_temp ? "Temporary catchpoint "
9718 if (!ui_out_is_mi_like_p (uiout))
9719 ui_out_field_int (uiout, "bkptno", b->number);
9721 bp_throw ? " (exception thrown), "
9722 : " (exception caught), ");
9723 if (ui_out_is_mi_like_p (uiout))
9725 ui_out_field_string (uiout, "reason",
9726 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9727 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9728 ui_out_field_int (uiout, "bkptno", b->number);
9730 return PRINT_SRC_AND_LOC;
9734 print_one_exception_catchpoint (struct breakpoint *b,
9735 struct bp_location **last_loc)
9737 struct value_print_options opts;
9739 get_user_print_options (&opts);
9740 if (opts.addressprint)
9743 if (b->loc == NULL || b->loc->shlib_disabled)
9744 ui_out_field_string (uiout, "addr", "<PENDING>");
9746 ui_out_field_core_addr (uiout, "addr",
9747 b->loc->gdbarch, b->loc->address);
9752 if (strstr (b->addr_string, "throw") != NULL)
9753 ui_out_field_string (uiout, "what", "exception throw");
9755 ui_out_field_string (uiout, "what", "exception catch");
9759 print_mention_exception_catchpoint (struct breakpoint *b)
9764 bp_temp = b->disposition == disp_del;
9765 bp_throw = strstr (b->addr_string, "throw") != NULL;
9766 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
9767 : _("Catchpoint "));
9768 ui_out_field_int (uiout, "bkptno", b->number);
9769 ui_out_text (uiout, bp_throw ? _(" (throw)")
9773 /* Implement the "print_recreate" breakpoint_ops method for throw and
9774 catch catchpoints. */
9777 print_recreate_exception_catchpoint (struct breakpoint *b,
9783 bp_temp = b->disposition == disp_del;
9784 bp_throw = strstr (b->addr_string, "throw") != NULL;
9785 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
9786 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
9787 print_recreate_thread (b, fp);
9790 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
9793 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
9794 enum exception_event_kind ex_event, int from_tty)
9796 char *trigger_func_name;
9798 if (ex_event == EX_EVENT_CATCH)
9799 trigger_func_name = "__cxa_begin_catch";
9801 trigger_func_name = "__cxa_throw";
9803 create_breakpoint (get_current_arch (),
9804 trigger_func_name, cond_string, -1,
9805 0 /* condition and thread are valid. */,
9806 tempflag, bp_breakpoint,
9808 AUTO_BOOLEAN_TRUE /* pending */,
9809 &gnu_v3_exception_catchpoint_ops, from_tty,
9816 /* Deal with "catch catch" and "catch throw" commands. */
9819 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
9820 int tempflag, int from_tty)
9822 char *cond_string = NULL;
9826 arg = skip_spaces (arg);
9828 cond_string = ep_parse_optional_if_clause (&arg);
9830 if ((*arg != '\0') && !isspace (*arg))
9831 error (_("Junk at end of arguments."));
9833 if (ex_event != EX_EVENT_THROW
9834 && ex_event != EX_EVENT_CATCH)
9835 error (_("Unsupported or unknown exception event; cannot catch it"));
9837 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
9840 warning (_("Unsupported with this platform/compiler combination."));
9843 /* Implementation of "catch catch" command. */
9846 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
9848 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9850 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
9853 /* Implementation of "catch throw" command. */
9856 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
9858 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9860 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
9864 init_ada_exception_breakpoint (struct breakpoint *b,
9865 struct gdbarch *gdbarch,
9866 struct symtab_and_line sal,
9868 const struct breakpoint_ops *ops,
9874 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9876 loc_gdbarch = gdbarch;
9878 describe_other_breakpoints (loc_gdbarch,
9879 sal.pspace, sal.pc, sal.section, -1);
9880 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9881 version for exception catchpoints, because two catchpoints
9882 used for different exception names will use the same address.
9883 In this case, a "breakpoint ... also set at..." warning is
9884 unproductive. Besides, the warning phrasing is also a bit
9885 inappropriate, we should use the word catchpoint, and tell
9886 the user what type of catchpoint it is. The above is good
9887 enough for now, though. */
9890 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
9892 b->enable_state = bp_enabled;
9893 b->disposition = tempflag ? disp_del : disp_donttouch;
9894 b->addr_string = addr_string;
9895 b->language = language_ada;
9898 /* Cleanup function for a syscall filter list. */
9900 clean_up_filters (void *arg)
9902 VEC(int) *iter = *(VEC(int) **) arg;
9903 VEC_free (int, iter);
9906 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9907 filter list, or NULL if no filtering is required. */
9909 catch_syscall_split_args (char *arg)
9911 VEC(int) *result = NULL;
9912 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
9914 while (*arg != '\0')
9916 int i, syscall_number;
9921 /* Skip whitespace. */
9922 while (isspace (*arg))
9925 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
9926 cur_name[i] = arg[i];
9930 /* Check if the user provided a syscall name or a number. */
9931 syscall_number = (int) strtol (cur_name, &endptr, 0);
9932 if (*endptr == '\0')
9933 get_syscall_by_number (syscall_number, &s);
9936 /* We have a name. Let's check if it's valid and convert it
9938 get_syscall_by_name (cur_name, &s);
9940 if (s.number == UNKNOWN_SYSCALL)
9941 /* Here we have to issue an error instead of a warning,
9942 because GDB cannot do anything useful if there's no
9943 syscall number to be caught. */
9944 error (_("Unknown syscall name '%s'."), cur_name);
9947 /* Ok, it's valid. */
9948 VEC_safe_push (int, result, s.number);
9951 discard_cleanups (cleanup);
9955 /* Implement the "catch syscall" command. */
9958 catch_syscall_command_1 (char *arg, int from_tty,
9959 struct cmd_list_element *command)
9964 struct gdbarch *gdbarch = get_current_arch ();
9966 /* Checking if the feature if supported. */
9967 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
9968 error (_("The feature 'catch syscall' is not supported on \
9969 this architecture yet."));
9971 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9973 arg = skip_spaces (arg);
9975 /* We need to do this first "dummy" translation in order
9976 to get the syscall XML file loaded or, most important,
9977 to display a warning to the user if there's no XML file
9978 for his/her architecture. */
9979 get_syscall_by_number (0, &s);
9981 /* The allowed syntax is:
9983 catch syscall <name | number> [<name | number> ... <name | number>]
9985 Let's check if there's a syscall name. */
9988 filter = catch_syscall_split_args (arg);
9992 create_syscall_event_catchpoint (tempflag, filter,
9993 &catch_syscall_breakpoint_ops);
9997 catch_command (char *arg, int from_tty)
9999 error (_("Catch requires an event name."));
10004 tcatch_command (char *arg, int from_tty)
10006 error (_("Catch requires an event name."));
10009 /* Delete breakpoints by address or line. */
10012 clear_command (char *arg, int from_tty)
10014 struct breakpoint *b;
10015 VEC(breakpoint_p) *found = 0;
10018 struct symtabs_and_lines sals;
10019 struct symtab_and_line sal;
10024 sals = decode_line_spec (arg, 1);
10029 sals.sals = (struct symtab_and_line *)
10030 xmalloc (sizeof (struct symtab_and_line));
10031 make_cleanup (xfree, sals.sals);
10032 init_sal (&sal); /* Initialize to zeroes. */
10033 sal.line = default_breakpoint_line;
10034 sal.symtab = default_breakpoint_symtab;
10035 sal.pc = default_breakpoint_address;
10036 sal.pspace = default_breakpoint_pspace;
10037 if (sal.symtab == 0)
10038 error (_("No source file specified."));
10040 sals.sals[0] = sal;
10046 /* We don't call resolve_sal_pc here. That's not as bad as it
10047 seems, because all existing breakpoints typically have both
10048 file/line and pc set. So, if clear is given file/line, we can
10049 match this to existing breakpoint without obtaining pc at all.
10051 We only support clearing given the address explicitly
10052 present in breakpoint table. Say, we've set breakpoint
10053 at file:line. There were several PC values for that file:line,
10054 due to optimization, all in one block.
10056 We've picked one PC value. If "clear" is issued with another
10057 PC corresponding to the same file:line, the breakpoint won't
10058 be cleared. We probably can still clear the breakpoint, but
10059 since the other PC value is never presented to user, user
10060 can only find it by guessing, and it does not seem important
10061 to support that. */
10063 /* For each line spec given, delete bps which correspond to it. Do
10064 it in two passes, solely to preserve the current behavior that
10065 from_tty is forced true if we delete more than one
10069 for (i = 0; i < sals.nelts; i++)
10071 /* If exact pc given, clear bpts at that pc.
10072 If line given (pc == 0), clear all bpts on specified line.
10073 If defaulting, clear all bpts on default line
10076 defaulting sal.pc != 0 tests to do
10081 1 0 <can't happen> */
10083 sal = sals.sals[i];
10085 /* Find all matching breakpoints and add them to 'found'. */
10086 ALL_BREAKPOINTS (b)
10089 /* Are we going to delete b? */
10090 if (b->type != bp_none && !is_watchpoint (b))
10092 struct bp_location *loc = b->loc;
10093 for (; loc; loc = loc->next)
10095 int pc_match = sal.pc
10096 && (loc->pspace == sal.pspace)
10097 && (loc->address == sal.pc)
10098 && (!section_is_overlay (loc->section)
10099 || loc->section == sal.section);
10100 int line_match = ((default_match || (0 == sal.pc))
10101 && b->source_file != NULL
10102 && sal.symtab != NULL
10103 && sal.pspace == loc->pspace
10104 && filename_cmp (b->source_file,
10105 sal.symtab->filename) == 0
10106 && b->line_number == sal.line);
10107 if (pc_match || line_match)
10116 VEC_safe_push(breakpoint_p, found, b);
10119 /* Now go thru the 'found' chain and delete them. */
10120 if (VEC_empty(breakpoint_p, found))
10123 error (_("No breakpoint at %s."), arg);
10125 error (_("No breakpoint at this line."));
10128 if (VEC_length(breakpoint_p, found) > 1)
10129 from_tty = 1; /* Always report if deleted more than one. */
10132 if (VEC_length(breakpoint_p, found) == 1)
10133 printf_unfiltered (_("Deleted breakpoint "));
10135 printf_unfiltered (_("Deleted breakpoints "));
10137 breakpoints_changed ();
10139 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
10142 printf_unfiltered ("%d ", b->number);
10143 delete_breakpoint (b);
10146 putchar_unfiltered ('\n');
10149 /* Delete breakpoint in BS if they are `delete' breakpoints and
10150 all breakpoints that are marked for deletion, whether hit or not.
10151 This is called after any breakpoint is hit, or after errors. */
10154 breakpoint_auto_delete (bpstat bs)
10156 struct breakpoint *b, *b_tmp;
10158 for (; bs; bs = bs->next)
10159 if (bs->breakpoint_at
10160 && bs->breakpoint_at->disposition == disp_del
10162 delete_breakpoint (bs->breakpoint_at);
10164 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10166 if (b->disposition == disp_del_at_next_stop)
10167 delete_breakpoint (b);
10171 /* A comparison function for bp_location AP and BP being interfaced to
10172 qsort. Sort elements primarily by their ADDRESS (no matter what
10173 does breakpoint_address_is_meaningful say for its OWNER),
10174 secondarily by ordering first bp_permanent OWNERed elements and
10175 terciarily just ensuring the array is sorted stable way despite
10176 qsort being an unstable algorithm. */
10179 bp_location_compare (const void *ap, const void *bp)
10181 struct bp_location *a = *(void **) ap;
10182 struct bp_location *b = *(void **) bp;
10183 /* A and B come from existing breakpoints having non-NULL OWNER. */
10184 int a_perm = a->owner->enable_state == bp_permanent;
10185 int b_perm = b->owner->enable_state == bp_permanent;
10187 if (a->address != b->address)
10188 return (a->address > b->address) - (a->address < b->address);
10190 /* Sort permanent breakpoints first. */
10191 if (a_perm != b_perm)
10192 return (a_perm < b_perm) - (a_perm > b_perm);
10194 /* Make the user-visible order stable across GDB runs. Locations of
10195 the same breakpoint can be sorted in arbitrary order. */
10197 if (a->owner->number != b->owner->number)
10198 return (a->owner->number > b->owner->number)
10199 - (a->owner->number < b->owner->number);
10201 return (a > b) - (a < b);
10204 /* Set bp_location_placed_address_before_address_max and
10205 bp_location_shadow_len_after_address_max according to the current
10206 content of the bp_location array. */
10209 bp_location_target_extensions_update (void)
10211 struct bp_location *bl, **blp_tmp;
10213 bp_location_placed_address_before_address_max = 0;
10214 bp_location_shadow_len_after_address_max = 0;
10216 ALL_BP_LOCATIONS (bl, blp_tmp)
10218 CORE_ADDR start, end, addr;
10220 if (!bp_location_has_shadow (bl))
10223 start = bl->target_info.placed_address;
10224 end = start + bl->target_info.shadow_len;
10226 gdb_assert (bl->address >= start);
10227 addr = bl->address - start;
10228 if (addr > bp_location_placed_address_before_address_max)
10229 bp_location_placed_address_before_address_max = addr;
10231 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10233 gdb_assert (bl->address < end);
10234 addr = end - bl->address;
10235 if (addr > bp_location_shadow_len_after_address_max)
10236 bp_location_shadow_len_after_address_max = addr;
10240 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10241 into the inferior, only remove already-inserted locations that no
10242 longer should be inserted. Functions that delete a breakpoint or
10243 breakpoints should pass false, so that deleting a breakpoint
10244 doesn't have the side effect of inserting the locations of other
10245 breakpoints that are marked not-inserted, but should_be_inserted
10246 returns true on them.
10248 This behaviour is useful is situations close to tear-down -- e.g.,
10249 after an exec, while the target still has execution, but breakpoint
10250 shadows of the previous executable image should *NOT* be restored
10251 to the new image; or before detaching, where the target still has
10252 execution and wants to delete breakpoints from GDB's lists, and all
10253 breakpoints had already been removed from the inferior. */
10256 update_global_location_list (int should_insert)
10258 struct breakpoint *b;
10259 struct bp_location **locp, *loc;
10260 struct cleanup *cleanups;
10262 /* Used in the duplicates detection below. When iterating over all
10263 bp_locations, points to the first bp_location of a given address.
10264 Breakpoints and watchpoints of different types are never
10265 duplicates of each other. Keep one pointer for each type of
10266 breakpoint/watchpoint, so we only need to loop over all locations
10268 struct bp_location *bp_loc_first; /* breakpoint */
10269 struct bp_location *wp_loc_first; /* hardware watchpoint */
10270 struct bp_location *awp_loc_first; /* access watchpoint */
10271 struct bp_location *rwp_loc_first; /* read watchpoint */
10273 /* Saved former bp_location array which we compare against the newly
10274 built bp_location from the current state of ALL_BREAKPOINTS. */
10275 struct bp_location **old_location, **old_locp;
10276 unsigned old_location_count;
10278 old_location = bp_location;
10279 old_location_count = bp_location_count;
10280 bp_location = NULL;
10281 bp_location_count = 0;
10282 cleanups = make_cleanup (xfree, old_location);
10284 ALL_BREAKPOINTS (b)
10285 for (loc = b->loc; loc; loc = loc->next)
10286 bp_location_count++;
10288 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
10289 locp = bp_location;
10290 ALL_BREAKPOINTS (b)
10291 for (loc = b->loc; loc; loc = loc->next)
10293 qsort (bp_location, bp_location_count, sizeof (*bp_location),
10294 bp_location_compare);
10296 bp_location_target_extensions_update ();
10298 /* Identify bp_location instances that are no longer present in the
10299 new list, and therefore should be freed. Note that it's not
10300 necessary that those locations should be removed from inferior --
10301 if there's another location at the same address (previously
10302 marked as duplicate), we don't need to remove/insert the
10305 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10306 and former bp_location array state respectively. */
10308 locp = bp_location;
10309 for (old_locp = old_location; old_locp < old_location + old_location_count;
10312 struct bp_location *old_loc = *old_locp;
10313 struct bp_location **loc2p;
10315 /* Tells if 'old_loc' is found among the new locations. If
10316 not, we have to free it. */
10317 int found_object = 0;
10318 /* Tells if the location should remain inserted in the target. */
10319 int keep_in_target = 0;
10322 /* Skip LOCP entries which will definitely never be needed.
10323 Stop either at or being the one matching OLD_LOC. */
10324 while (locp < bp_location + bp_location_count
10325 && (*locp)->address < old_loc->address)
10329 (loc2p < bp_location + bp_location_count
10330 && (*loc2p)->address == old_loc->address);
10333 if (*loc2p == old_loc)
10340 /* If this location is no longer present, and inserted, look if
10341 there's maybe a new location at the same address. If so,
10342 mark that one inserted, and don't remove this one. This is
10343 needed so that we don't have a time window where a breakpoint
10344 at certain location is not inserted. */
10346 if (old_loc->inserted)
10348 /* If the location is inserted now, we might have to remove
10351 if (found_object && should_be_inserted (old_loc))
10353 /* The location is still present in the location list,
10354 and still should be inserted. Don't do anything. */
10355 keep_in_target = 1;
10359 /* The location is either no longer present, or got
10360 disabled. See if there's another location at the
10361 same address, in which case we don't need to remove
10362 this one from the target. */
10364 /* OLD_LOC comes from existing struct breakpoint. */
10365 if (breakpoint_address_is_meaningful (old_loc->owner))
10368 (loc2p < bp_location + bp_location_count
10369 && (*loc2p)->address == old_loc->address);
10372 struct bp_location *loc2 = *loc2p;
10374 if (breakpoint_locations_match (loc2, old_loc))
10376 /* For the sake of should_be_inserted.
10377 Duplicates check below will fix up this
10379 loc2->duplicate = 0;
10381 /* Read watchpoint locations are switched to
10382 access watchpoints, if the former are not
10383 supported, but the latter are. */
10384 if (is_hardware_watchpoint (old_loc->owner))
10386 gdb_assert (is_hardware_watchpoint (loc2->owner));
10387 loc2->watchpoint_type = old_loc->watchpoint_type;
10390 if (loc2 != old_loc && should_be_inserted (loc2))
10392 loc2->inserted = 1;
10393 loc2->target_info = old_loc->target_info;
10394 keep_in_target = 1;
10402 if (!keep_in_target)
10404 if (remove_breakpoint (old_loc, mark_uninserted))
10406 /* This is just about all we can do. We could keep
10407 this location on the global list, and try to
10408 remove it next time, but there's no particular
10409 reason why we will succeed next time.
10411 Note that at this point, old_loc->owner is still
10412 valid, as delete_breakpoint frees the breakpoint
10413 only after calling us. */
10414 printf_filtered (_("warning: Error removing "
10415 "breakpoint %d\n"),
10416 old_loc->owner->number);
10424 if (removed && non_stop
10425 && breakpoint_address_is_meaningful (old_loc->owner)
10426 && !is_hardware_watchpoint (old_loc->owner))
10428 /* This location was removed from the target. In
10429 non-stop mode, a race condition is possible where
10430 we've removed a breakpoint, but stop events for that
10431 breakpoint are already queued and will arrive later.
10432 We apply an heuristic to be able to distinguish such
10433 SIGTRAPs from other random SIGTRAPs: we keep this
10434 breakpoint location for a bit, and will retire it
10435 after we see some number of events. The theory here
10436 is that reporting of events should, "on the average",
10437 be fair, so after a while we'll see events from all
10438 threads that have anything of interest, and no longer
10439 need to keep this breakpoint location around. We
10440 don't hold locations forever so to reduce chances of
10441 mistaking a non-breakpoint SIGTRAP for a breakpoint
10444 The heuristic failing can be disastrous on
10445 decr_pc_after_break targets.
10447 On decr_pc_after_break targets, like e.g., x86-linux,
10448 if we fail to recognize a late breakpoint SIGTRAP,
10449 because events_till_retirement has reached 0 too
10450 soon, we'll fail to do the PC adjustment, and report
10451 a random SIGTRAP to the user. When the user resumes
10452 the inferior, it will most likely immediately crash
10453 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10454 corrupted, because of being resumed e.g., in the
10455 middle of a multi-byte instruction, or skipped a
10456 one-byte instruction. This was actually seen happen
10457 on native x86-linux, and should be less rare on
10458 targets that do not support new thread events, like
10459 remote, due to the heuristic depending on
10462 Mistaking a random SIGTRAP for a breakpoint trap
10463 causes similar symptoms (PC adjustment applied when
10464 it shouldn't), but then again, playing with SIGTRAPs
10465 behind the debugger's back is asking for trouble.
10467 Since hardware watchpoint traps are always
10468 distinguishable from other traps, so we don't need to
10469 apply keep hardware watchpoint moribund locations
10470 around. We simply always ignore hardware watchpoint
10471 traps we can no longer explain. */
10473 old_loc->events_till_retirement = 3 * (thread_count () + 1);
10474 old_loc->owner = NULL;
10476 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
10480 old_loc->owner = NULL;
10481 decref_bp_location (&old_loc);
10486 /* Rescan breakpoints at the same address and section, marking the
10487 first one as "first" and any others as "duplicates". This is so
10488 that the bpt instruction is only inserted once. If we have a
10489 permanent breakpoint at the same place as BPT, make that one the
10490 official one, and the rest as duplicates. Permanent breakpoints
10491 are sorted first for the same address.
10493 Do the same for hardware watchpoints, but also considering the
10494 watchpoint's type (regular/access/read) and length. */
10496 bp_loc_first = NULL;
10497 wp_loc_first = NULL;
10498 awp_loc_first = NULL;
10499 rwp_loc_first = NULL;
10500 ALL_BP_LOCATIONS (loc, locp)
10502 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10504 struct breakpoint *b = loc->owner;
10505 struct bp_location **loc_first_p;
10507 if (b->enable_state == bp_disabled
10508 || b->enable_state == bp_call_disabled
10509 || b->enable_state == bp_startup_disabled
10511 || loc->shlib_disabled
10512 || !breakpoint_address_is_meaningful (b)
10513 || is_tracepoint (b))
10516 /* Permanent breakpoint should always be inserted. */
10517 if (b->enable_state == bp_permanent && ! loc->inserted)
10518 internal_error (__FILE__, __LINE__,
10519 _("allegedly permanent breakpoint is not "
10520 "actually inserted"));
10522 if (b->type == bp_hardware_watchpoint)
10523 loc_first_p = &wp_loc_first;
10524 else if (b->type == bp_read_watchpoint)
10525 loc_first_p = &rwp_loc_first;
10526 else if (b->type == bp_access_watchpoint)
10527 loc_first_p = &awp_loc_first;
10529 loc_first_p = &bp_loc_first;
10531 if (*loc_first_p == NULL
10532 || (overlay_debugging && loc->section != (*loc_first_p)->section)
10533 || !breakpoint_locations_match (loc, *loc_first_p))
10535 *loc_first_p = loc;
10536 loc->duplicate = 0;
10540 loc->duplicate = 1;
10542 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
10543 && b->enable_state != bp_permanent)
10544 internal_error (__FILE__, __LINE__,
10545 _("another breakpoint was inserted on top of "
10546 "a permanent breakpoint"));
10549 if (breakpoints_always_inserted_mode () && should_insert
10550 && (have_live_inferiors ()
10551 || (gdbarch_has_global_breakpoints (target_gdbarch))))
10552 insert_breakpoint_locations ();
10554 do_cleanups (cleanups);
10558 breakpoint_retire_moribund (void)
10560 struct bp_location *loc;
10563 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
10564 if (--(loc->events_till_retirement) == 0)
10566 decref_bp_location (&loc);
10567 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
10573 update_global_location_list_nothrow (int inserting)
10575 struct gdb_exception e;
10577 TRY_CATCH (e, RETURN_MASK_ERROR)
10578 update_global_location_list (inserting);
10581 /* Clear BKP from a BPS. */
10584 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
10588 for (bs = bps; bs; bs = bs->next)
10589 if (bs->breakpoint_at == bpt)
10591 bs->breakpoint_at = NULL;
10592 bs->old_val = NULL;
10593 /* bs->commands will be freed later. */
10597 /* Callback for iterate_over_threads. */
10599 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
10601 struct breakpoint *bpt = data;
10603 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
10607 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10611 say_where (struct breakpoint *b)
10613 struct value_print_options opts;
10615 get_user_print_options (&opts);
10617 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10619 if (b->loc == NULL)
10621 printf_filtered (_(" (%s) pending."), b->addr_string);
10625 if (opts.addressprint || b->source_file == NULL)
10627 printf_filtered (" at ");
10628 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
10631 if (b->source_file)
10632 printf_filtered (": file %s, line %d.",
10633 b->source_file, b->line_number);
10637 struct bp_location *loc = b->loc;
10639 for (; loc; loc = loc->next)
10641 printf_filtered (" (%d locations)", n);
10646 /* Default bp_location_ops methods. */
10649 bp_location_dtor (struct bp_location *self)
10651 xfree (self->cond);
10652 xfree (self->function_name);
10655 static const struct bp_location_ops bp_location_ops =
10660 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10664 base_breakpoint_dtor (struct breakpoint *self)
10666 decref_counted_command_line (&self->commands);
10667 xfree (self->cond_string);
10668 xfree (self->addr_string);
10669 xfree (self->addr_string_range_end);
10670 xfree (self->source_file);
10673 static struct bp_location *
10674 base_breakpoint_allocate_location (struct breakpoint *self)
10676 struct bp_location *loc;
10678 loc = XNEW (struct bp_location);
10679 init_bp_location (loc, &bp_location_ops, self);
10684 base_breakpoint_re_set (struct breakpoint *b)
10686 /* Nothing to re-set. */
10689 #define internal_error_pure_virtual_called() \
10690 gdb_assert_not_reached ("pure virtual function called")
10693 base_breakpoint_insert_location (struct bp_location *bl)
10695 internal_error_pure_virtual_called ();
10699 base_breakpoint_remove_location (struct bp_location *bl)
10701 internal_error_pure_virtual_called ();
10705 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
10706 struct address_space *aspace,
10709 internal_error_pure_virtual_called ();
10713 base_breakpoint_check_status (bpstat bs)
10718 /* A "works_in_software_mode" breakpoint_ops method that just internal
10722 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
10724 internal_error_pure_virtual_called ();
10727 /* A "resources_needed" breakpoint_ops method that just internal
10731 base_breakpoint_resources_needed (const struct bp_location *bl)
10733 internal_error_pure_virtual_called ();
10736 static enum print_stop_action
10737 base_breakpoint_print_it (bpstat bs)
10739 internal_error_pure_virtual_called ();
10743 base_breakpoint_print_one_detail (const struct breakpoint *self,
10744 struct ui_out *uiout)
10750 base_breakpoint_print_mention (struct breakpoint *b)
10752 internal_error_pure_virtual_called ();
10756 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
10758 internal_error_pure_virtual_called ();
10761 static struct breakpoint_ops base_breakpoint_ops =
10763 base_breakpoint_dtor,
10764 base_breakpoint_allocate_location,
10765 base_breakpoint_re_set,
10766 base_breakpoint_insert_location,
10767 base_breakpoint_remove_location,
10768 base_breakpoint_breakpoint_hit,
10769 base_breakpoint_check_status,
10770 base_breakpoint_resources_needed,
10771 base_breakpoint_works_in_software_mode,
10772 base_breakpoint_print_it,
10774 base_breakpoint_print_one_detail,
10775 base_breakpoint_print_mention,
10776 base_breakpoint_print_recreate
10779 /* Default breakpoint_ops methods. */
10782 bkpt_re_set (struct breakpoint *b)
10784 /* Do not attempt to re-set breakpoints disabled during startup. */
10785 if (b->enable_state == bp_startup_disabled)
10788 /* FIXME: is this still reachable? */
10789 if (b->addr_string == NULL)
10791 /* Anything without a string can't be re-set. */
10792 delete_breakpoint (b);
10796 breakpoint_re_set_default (b);
10800 bkpt_insert_location (struct bp_location *bl)
10802 if (bl->loc_type == bp_loc_hardware_breakpoint)
10803 return target_insert_hw_breakpoint (bl->gdbarch,
10806 return target_insert_breakpoint (bl->gdbarch,
10811 bkpt_remove_location (struct bp_location *bl)
10813 if (bl->loc_type == bp_loc_hardware_breakpoint)
10814 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
10816 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
10820 bkpt_breakpoint_hit (const struct bp_location *bl,
10821 struct address_space *aspace, CORE_ADDR bp_addr)
10823 struct breakpoint *b = bl->owner;
10825 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
10829 if (overlay_debugging /* unmapped overlay section */
10830 && section_is_overlay (bl->section)
10831 && !section_is_mapped (bl->section))
10838 bkpt_resources_needed (const struct bp_location *bl)
10840 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
10845 static enum print_stop_action
10846 bkpt_print_it (bpstat bs)
10848 struct breakpoint *b;
10849 const struct bp_location *bl;
10852 gdb_assert (bs->bp_location_at != NULL);
10854 bl = bs->bp_location_at;
10855 b = bs->breakpoint_at;
10857 bp_temp = b->disposition == disp_del;
10858 if (bl->address != bl->requested_address)
10859 breakpoint_adjustment_warning (bl->requested_address,
10862 annotate_breakpoint (b->number);
10864 ui_out_text (uiout, "\nTemporary breakpoint ");
10866 ui_out_text (uiout, "\nBreakpoint ");
10867 if (ui_out_is_mi_like_p (uiout))
10869 ui_out_field_string (uiout, "reason",
10870 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10871 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10873 ui_out_field_int (uiout, "bkptno", b->number);
10874 ui_out_text (uiout, ", ");
10876 return PRINT_SRC_AND_LOC;
10880 bkpt_print_mention (struct breakpoint *b)
10882 if (ui_out_is_mi_like_p (uiout))
10887 case bp_breakpoint:
10888 case bp_gnu_ifunc_resolver:
10889 if (b->disposition == disp_del)
10890 printf_filtered (_("Temporary breakpoint"));
10892 printf_filtered (_("Breakpoint"));
10893 printf_filtered (_(" %d"), b->number);
10894 if (b->type == bp_gnu_ifunc_resolver)
10895 printf_filtered (_(" at gnu-indirect-function resolver"));
10897 case bp_hardware_breakpoint:
10898 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
10906 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
10908 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
10909 fprintf_unfiltered (fp, "tbreak");
10910 else if (tp->type == bp_breakpoint)
10911 fprintf_unfiltered (fp, "break");
10912 else if (tp->type == bp_hardware_breakpoint
10913 && tp->disposition == disp_del)
10914 fprintf_unfiltered (fp, "thbreak");
10915 else if (tp->type == bp_hardware_breakpoint)
10916 fprintf_unfiltered (fp, "hbreak");
10918 internal_error (__FILE__, __LINE__,
10919 _("unhandled breakpoint type %d"), (int) tp->type);
10921 fprintf_unfiltered (fp, " %s", tp->addr_string);
10924 /* Virtual table for internal breakpoints. */
10927 internal_bkpt_re_set (struct breakpoint *b)
10931 /* Delete overlay event and longjmp master breakpoints; they
10932 will be reset later by breakpoint_re_set. */
10933 case bp_overlay_event:
10934 case bp_longjmp_master:
10935 case bp_std_terminate_master:
10936 case bp_exception_master:
10937 delete_breakpoint (b);
10940 /* This breakpoint is special, it's set up when the inferior
10941 starts and we really don't want to touch it. */
10942 case bp_shlib_event:
10944 /* Like bp_shlib_event, this breakpoint type is special. Once
10945 it is set up, we do not want to touch it. */
10946 case bp_thread_event:
10952 internal_bkpt_check_status (bpstat bs)
10954 /* We do not stop for these. */
10958 static enum print_stop_action
10959 internal_bkpt_print_it (bpstat bs)
10961 struct breakpoint *b;
10963 b = bs->breakpoint_at;
10967 case bp_shlib_event:
10968 /* Did we stop because the user set the stop_on_solib_events
10969 variable? (If so, we report this as a generic, "Stopped due
10970 to shlib event" message.) */
10971 printf_filtered (_("Stopped due to shared library event\n"));
10974 case bp_thread_event:
10975 /* Not sure how we will get here.
10976 GDB should not stop for these breakpoints. */
10977 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
10980 case bp_overlay_event:
10981 /* By analogy with the thread event, GDB should not stop for these. */
10982 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
10985 case bp_longjmp_master:
10986 /* These should never be enabled. */
10987 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
10990 case bp_std_terminate_master:
10991 /* These should never be enabled. */
10992 printf_filtered (_("std::terminate Master Breakpoint: "
10993 "gdb should not stop!\n"));
10996 case bp_exception_master:
10997 /* These should never be enabled. */
10998 printf_filtered (_("Exception Master Breakpoint: "
10999 "gdb should not stop!\n"));
11003 return PRINT_NOTHING;
11007 internal_bkpt_print_mention (struct breakpoint *b)
11009 /* Nothing to mention. These breakpoints are internal. */
11012 /* Virtual table for momentary breakpoints */
11015 momentary_bkpt_re_set (struct breakpoint *b)
11017 /* Keep temporary breakpoints, which can be encountered when we step
11018 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11019 Otherwise these should have been blown away via the cleanup chain
11020 or by breakpoint_init_inferior when we rerun the executable. */
11024 momentary_bkpt_check_status (bpstat bs)
11026 /* Nothing. The point of these breakpoints is causing a stop. */
11029 static enum print_stop_action
11030 momentary_bkpt_print_it (bpstat bs)
11032 if (ui_out_is_mi_like_p (uiout))
11034 struct breakpoint *b = bs->breakpoint_at;
11039 ui_out_field_string
11041 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
11045 ui_out_field_string
11047 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
11052 return PRINT_UNKNOWN;
11056 momentary_bkpt_print_mention (struct breakpoint *b)
11058 /* Nothing to mention. These breakpoints are internal. */
11061 /* The breakpoint_ops structure to be used in tracepoints. */
11064 tracepoint_re_set (struct breakpoint *b)
11066 breakpoint_re_set_default (b);
11070 tracepoint_breakpoint_hit (const struct bp_location *bl,
11071 struct address_space *aspace, CORE_ADDR bp_addr)
11073 /* By definition, the inferior does not report stops at
11079 tracepoint_print_one_detail (const struct breakpoint *self,
11080 struct ui_out *uiout)
11082 struct tracepoint *tp = (struct tracepoint *) self;
11083 if (tp->static_trace_marker_id)
11085 gdb_assert (self->type == bp_static_tracepoint);
11087 ui_out_text (uiout, "\tmarker id is ");
11088 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
11089 tp->static_trace_marker_id);
11090 ui_out_text (uiout, "\n");
11095 tracepoint_print_mention (struct breakpoint *b)
11097 if (ui_out_is_mi_like_p (uiout))
11102 case bp_tracepoint:
11103 printf_filtered (_("Tracepoint"));
11104 printf_filtered (_(" %d"), b->number);
11106 case bp_fast_tracepoint:
11107 printf_filtered (_("Fast tracepoint"));
11108 printf_filtered (_(" %d"), b->number);
11110 case bp_static_tracepoint:
11111 printf_filtered (_("Static tracepoint"));
11112 printf_filtered (_(" %d"), b->number);
11115 internal_error (__FILE__, __LINE__,
11116 _("unhandled tracepoint type %d"), (int) b->type);
11123 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
11125 struct tracepoint *tp = (struct tracepoint *) self;
11127 if (self->type == bp_fast_tracepoint)
11128 fprintf_unfiltered (fp, "ftrace");
11129 if (self->type == bp_static_tracepoint)
11130 fprintf_unfiltered (fp, "strace");
11131 else if (self->type == bp_tracepoint)
11132 fprintf_unfiltered (fp, "trace");
11134 internal_error (__FILE__, __LINE__,
11135 _("unhandled tracepoint type %d"), (int) self->type);
11137 fprintf_unfiltered (fp, " %s", self->addr_string);
11138 print_recreate_thread (self, fp);
11140 if (tp->pass_count)
11141 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11144 struct breakpoint_ops tracepoint_breakpoint_ops;
11146 /* Delete a breakpoint and clean up all traces of it in the data
11150 delete_breakpoint (struct breakpoint *bpt)
11152 struct breakpoint *b;
11154 gdb_assert (bpt != NULL);
11156 /* Has this bp already been deleted? This can happen because
11157 multiple lists can hold pointers to bp's. bpstat lists are
11160 One example of this happening is a watchpoint's scope bp. When
11161 the scope bp triggers, we notice that the watchpoint is out of
11162 scope, and delete it. We also delete its scope bp. But the
11163 scope bp is marked "auto-deleting", and is already on a bpstat.
11164 That bpstat is then checked for auto-deleting bp's, which are
11167 A real solution to this problem might involve reference counts in
11168 bp's, and/or giving them pointers back to their referencing
11169 bpstat's, and teaching delete_breakpoint to only free a bp's
11170 storage when no more references were extent. A cheaper bandaid
11172 if (bpt->type == bp_none)
11175 /* At least avoid this stale reference until the reference counting
11176 of breakpoints gets resolved. */
11177 if (bpt->related_breakpoint != bpt)
11179 struct breakpoint *related;
11180 struct watchpoint *w;
11182 if (bpt->type == bp_watchpoint_scope)
11183 w = (struct watchpoint *) bpt->related_breakpoint;
11184 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
11185 w = (struct watchpoint *) bpt;
11189 watchpoint_del_at_next_stop (w);
11191 /* Unlink bpt from the bpt->related_breakpoint ring. */
11192 for (related = bpt; related->related_breakpoint != bpt;
11193 related = related->related_breakpoint);
11194 related->related_breakpoint = bpt->related_breakpoint;
11195 bpt->related_breakpoint = bpt;
11198 /* watch_command_1 creates a watchpoint but only sets its number if
11199 update_watchpoint succeeds in creating its bp_locations. If there's
11200 a problem in that process, we'll be asked to delete the half-created
11201 watchpoint. In that case, don't announce the deletion. */
11203 observer_notify_breakpoint_deleted (bpt);
11205 if (breakpoint_chain == bpt)
11206 breakpoint_chain = bpt->next;
11208 ALL_BREAKPOINTS (b)
11209 if (b->next == bpt)
11211 b->next = bpt->next;
11215 /* Be sure no bpstat's are pointing at the breakpoint after it's
11217 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11218 in all threads for now. Note that we cannot just remove bpstats
11219 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11220 commands are associated with the bpstat; if we remove it here,
11221 then the later call to bpstat_do_actions (&stop_bpstat); in
11222 event-top.c won't do anything, and temporary breakpoints with
11223 commands won't work. */
11225 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
11227 /* Now that breakpoint is removed from breakpoint list, update the
11228 global location list. This will remove locations that used to
11229 belong to this breakpoint. Do this before freeing the breakpoint
11230 itself, since remove_breakpoint looks at location's owner. It
11231 might be better design to have location completely
11232 self-contained, but it's not the case now. */
11233 update_global_location_list (0);
11235 bpt->ops->dtor (bpt);
11236 /* On the chance that someone will soon try again to delete this
11237 same bp, we mark it as deleted before freeing its storage. */
11238 bpt->type = bp_none;
11243 do_delete_breakpoint_cleanup (void *b)
11245 delete_breakpoint (b);
11249 make_cleanup_delete_breakpoint (struct breakpoint *b)
11251 return make_cleanup (do_delete_breakpoint_cleanup, b);
11254 /* Iterator function to call a user-provided callback function once
11255 for each of B and its related breakpoints. */
11258 iterate_over_related_breakpoints (struct breakpoint *b,
11259 void (*function) (struct breakpoint *,
11263 struct breakpoint *related;
11268 struct breakpoint *next;
11270 /* FUNCTION may delete RELATED. */
11271 next = related->related_breakpoint;
11273 if (next == related)
11275 /* RELATED is the last ring entry. */
11276 function (related, data);
11278 /* FUNCTION may have deleted it, so we'd never reach back to
11279 B. There's nothing left to do anyway, so just break
11284 function (related, data);
11288 while (related != b);
11292 do_delete_breakpoint (struct breakpoint *b, void *ignore)
11294 delete_breakpoint (b);
11297 /* A callback for map_breakpoint_numbers that calls
11298 delete_breakpoint. */
11301 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
11303 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
11307 delete_command (char *arg, int from_tty)
11309 struct breakpoint *b, *b_tmp;
11315 int breaks_to_delete = 0;
11317 /* Delete all breakpoints if no argument. Do not delete
11318 internal breakpoints, these have to be deleted with an
11319 explicit breakpoint number argument. */
11320 ALL_BREAKPOINTS (b)
11321 if (user_breakpoint_p (b))
11323 breaks_to_delete = 1;
11327 /* Ask user only if there are some breakpoints to delete. */
11329 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
11331 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11332 if (user_breakpoint_p (b))
11333 delete_breakpoint (b);
11337 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
11341 all_locations_are_pending (struct bp_location *loc)
11343 for (; loc; loc = loc->next)
11344 if (!loc->shlib_disabled)
11349 /* Subroutine of update_breakpoint_locations to simplify it.
11350 Return non-zero if multiple fns in list LOC have the same name.
11351 Null names are ignored. */
11354 ambiguous_names_p (struct bp_location *loc)
11356 struct bp_location *l;
11357 htab_t htab = htab_create_alloc (13, htab_hash_string,
11358 (int (*) (const void *,
11359 const void *)) streq,
11360 NULL, xcalloc, xfree);
11362 for (l = loc; l != NULL; l = l->next)
11365 const char *name = l->function_name;
11367 /* Allow for some names to be NULL, ignore them. */
11371 slot = (const char **) htab_find_slot (htab, (const void *) name,
11373 /* NOTE: We can assume slot != NULL here because xcalloc never
11377 htab_delete (htab);
11383 htab_delete (htab);
11387 /* When symbols change, it probably means the sources changed as well,
11388 and it might mean the static tracepoint markers are no longer at
11389 the same address or line numbers they used to be at last we
11390 checked. Losing your static tracepoints whenever you rebuild is
11391 undesirable. This function tries to resync/rematch gdb static
11392 tracepoints with the markers on the target, for static tracepoints
11393 that have not been set by marker id. Static tracepoint that have
11394 been set by marker id are reset by marker id in breakpoint_re_set.
11397 1) For a tracepoint set at a specific address, look for a marker at
11398 the old PC. If one is found there, assume to be the same marker.
11399 If the name / string id of the marker found is different from the
11400 previous known name, assume that means the user renamed the marker
11401 in the sources, and output a warning.
11403 2) For a tracepoint set at a given line number, look for a marker
11404 at the new address of the old line number. If one is found there,
11405 assume to be the same marker. If the name / string id of the
11406 marker found is different from the previous known name, assume that
11407 means the user renamed the marker in the sources, and output a
11410 3) If a marker is no longer found at the same address or line, it
11411 may mean the marker no longer exists. But it may also just mean
11412 the code changed a bit. Maybe the user added a few lines of code
11413 that made the marker move up or down (in line number terms). Ask
11414 the target for info about the marker with the string id as we knew
11415 it. If found, update line number and address in the matching
11416 static tracepoint. This will get confused if there's more than one
11417 marker with the same ID (possible in UST, although unadvised
11418 precisely because it confuses tools). */
11420 static struct symtab_and_line
11421 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
11423 struct tracepoint *tp = (struct tracepoint *) b;
11424 struct static_tracepoint_marker marker;
11430 find_line_pc (sal.symtab, sal.line, &pc);
11432 if (target_static_tracepoint_marker_at (pc, &marker))
11434 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
11435 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11437 tp->static_trace_marker_id, marker.str_id);
11439 xfree (tp->static_trace_marker_id);
11440 tp->static_trace_marker_id = xstrdup (marker.str_id);
11441 release_static_tracepoint_marker (&marker);
11446 /* Old marker wasn't found on target at lineno. Try looking it up
11448 if (!sal.explicit_pc
11450 && sal.symtab != NULL
11451 && tp->static_trace_marker_id != NULL)
11453 VEC(static_tracepoint_marker_p) *markers;
11456 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
11458 if (!VEC_empty(static_tracepoint_marker_p, markers))
11460 struct symtab_and_line sal;
11461 struct symbol *sym;
11462 struct static_tracepoint_marker *marker;
11464 marker = VEC_index (static_tracepoint_marker_p, markers, 0);
11466 xfree (tp->static_trace_marker_id);
11467 tp->static_trace_marker_id = xstrdup (marker->str_id);
11469 warning (_("marker for static tracepoint %d (%s) not "
11470 "found at previous line number"),
11471 b->number, tp->static_trace_marker_id);
11475 sal.pc = marker->address;
11477 sal = find_pc_line (marker->address, 0);
11478 sym = find_pc_sect_function (marker->address, NULL);
11479 ui_out_text (uiout, "Now in ");
11482 ui_out_field_string (uiout, "func",
11483 SYMBOL_PRINT_NAME (sym));
11484 ui_out_text (uiout, " at ");
11486 ui_out_field_string (uiout, "file", sal.symtab->filename);
11487 ui_out_text (uiout, ":");
11489 if (ui_out_is_mi_like_p (uiout))
11491 char *fullname = symtab_to_fullname (sal.symtab);
11494 ui_out_field_string (uiout, "fullname", fullname);
11497 ui_out_field_int (uiout, "line", sal.line);
11498 ui_out_text (uiout, "\n");
11500 b->line_number = sal.line;
11502 xfree (b->source_file);
11504 b->source_file = xstrdup (sal.symtab->filename);
11506 b->source_file = NULL;
11508 xfree (b->addr_string);
11509 b->addr_string = xstrprintf ("%s:%d",
11510 sal.symtab->filename, b->line_number);
11512 /* Might be nice to check if function changed, and warn if
11515 release_static_tracepoint_marker (marker);
11521 /* Returns 1 iff locations A and B are sufficiently same that
11522 we don't need to report breakpoint as changed. */
11525 locations_are_equal (struct bp_location *a, struct bp_location *b)
11529 if (a->address != b->address)
11532 if (a->shlib_disabled != b->shlib_disabled)
11535 if (a->enabled != b->enabled)
11542 if ((a == NULL) != (b == NULL))
11548 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11549 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11550 a ranged breakpoint. */
11553 update_breakpoint_locations (struct breakpoint *b,
11554 struct symtabs_and_lines sals,
11555 struct symtabs_and_lines sals_end)
11558 struct bp_location *existing_locations = b->loc;
11560 /* Ranged breakpoints have only one start location and one end location. */
11561 gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1));
11563 /* If there's no new locations, and all existing locations are
11564 pending, don't do anything. This optimizes the common case where
11565 all locations are in the same shared library, that was unloaded.
11566 We'd like to retain the location, so that when the library is
11567 loaded again, we don't loose the enabled/disabled status of the
11568 individual locations. */
11569 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
11574 for (i = 0; i < sals.nelts; ++i)
11576 struct bp_location *new_loc =
11577 add_location_to_breakpoint (b, &(sals.sals[i]));
11579 /* Reparse conditions, they might contain references to the
11581 if (b->cond_string != NULL)
11584 struct gdb_exception e;
11586 s = b->cond_string;
11587 TRY_CATCH (e, RETURN_MASK_ERROR)
11589 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
11594 warning (_("failed to reevaluate condition "
11595 "for breakpoint %d: %s"),
11596 b->number, e.message);
11597 new_loc->enabled = 0;
11601 if (b->source_file != NULL)
11602 xfree (b->source_file);
11603 if (sals.sals[i].symtab == NULL)
11604 b->source_file = NULL;
11606 b->source_file = xstrdup (sals.sals[i].symtab->filename);
11608 if (b->line_number == 0)
11609 b->line_number = sals.sals[i].line;
11611 if (sals_end.nelts)
11613 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
11615 new_loc->length = end - sals.sals[0].pc + 1;
11619 /* Update locations of permanent breakpoints. */
11620 if (b->enable_state == bp_permanent)
11621 make_breakpoint_permanent (b);
11623 /* If possible, carry over 'disable' status from existing
11626 struct bp_location *e = existing_locations;
11627 /* If there are multiple breakpoints with the same function name,
11628 e.g. for inline functions, comparing function names won't work.
11629 Instead compare pc addresses; this is just a heuristic as things
11630 may have moved, but in practice it gives the correct answer
11631 often enough until a better solution is found. */
11632 int have_ambiguous_names = ambiguous_names_p (b->loc);
11634 for (; e; e = e->next)
11636 if (!e->enabled && e->function_name)
11638 struct bp_location *l = b->loc;
11639 if (have_ambiguous_names)
11641 for (; l; l = l->next)
11642 if (breakpoint_locations_match (e, l))
11650 for (; l; l = l->next)
11651 if (l->function_name
11652 && strcmp (e->function_name, l->function_name) == 0)
11662 if (!locations_are_equal (existing_locations, b->loc))
11663 observer_notify_breakpoint_modified (b);
11665 update_global_location_list (1);
11668 /* Find the SaL locations corresponding to the given ADDR_STRING.
11669 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11671 static struct symtabs_and_lines
11672 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
11676 struct symtabs_and_lines sals = {0};
11677 struct gdb_exception e;
11680 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s);
11682 TRY_CATCH (e, RETURN_MASK_ERROR)
11686 struct tracepoint *tp = (struct tracepoint *) b;
11688 sals = decode_static_tracepoint_spec (&s);
11689 if (sals.nelts > tp->static_trace_marker_id_idx)
11691 sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx];
11695 error (_("marker %s not found"), tp->static_trace_marker_id);
11698 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL);
11702 int not_found_and_ok = 0;
11703 /* For pending breakpoints, it's expected that parsing will
11704 fail until the right shared library is loaded. User has
11705 already told to create pending breakpoints and don't need
11706 extra messages. If breakpoint is in bp_shlib_disabled
11707 state, then user already saw the message about that
11708 breakpoint being disabled, and don't want to see more
11710 if (e.error == NOT_FOUND_ERROR
11711 && (b->condition_not_parsed
11712 || (b->loc && b->loc->shlib_disabled)
11713 || b->enable_state == bp_disabled))
11714 not_found_and_ok = 1;
11716 if (!not_found_and_ok)
11718 /* We surely don't want to warn about the same breakpoint
11719 10 times. One solution, implemented here, is disable
11720 the breakpoint on error. Another solution would be to
11721 have separate 'warning emitted' flag. Since this
11722 happens only when a binary has changed, I don't know
11723 which approach is better. */
11724 b->enable_state = bp_disabled;
11725 throw_exception (e);
11729 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
11731 gdb_assert (sals.nelts == 1);
11733 resolve_sal_pc (&sals.sals[0]);
11734 if (b->condition_not_parsed && s && s[0])
11736 char *cond_string = 0;
11740 find_condition_and_thread (s, sals.sals[0].pc,
11741 &cond_string, &thread, &task);
11743 b->cond_string = cond_string;
11744 b->thread = thread;
11746 b->condition_not_parsed = 0;
11749 if (b->type == bp_static_tracepoint && !marker_spec)
11750 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
11760 /* The default re_set method, for typical hardware or software
11761 breakpoints. Reevaluate the breakpoint and recreate its
11765 breakpoint_re_set_default (struct breakpoint *b)
11768 struct symtabs_and_lines sals, sals_end;
11769 struct symtabs_and_lines expanded = {0};
11770 struct symtabs_and_lines expanded_end = {0};
11772 sals = addr_string_to_sals (b, b->addr_string, &found);
11775 make_cleanup (xfree, sals.sals);
11776 expanded = expand_line_sal_maybe (sals.sals[0]);
11779 if (b->addr_string_range_end)
11781 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
11784 make_cleanup (xfree, sals_end.sals);
11785 expanded_end = expand_line_sal_maybe (sals_end.sals[0]);
11789 update_breakpoint_locations (b, expanded, expanded_end);
11792 /* Prepare the global context for a re-set of breakpoint B. */
11794 static struct cleanup *
11795 prepare_re_set_context (struct breakpoint *b)
11797 struct cleanup *cleanups;
11799 input_radix = b->input_radix;
11800 cleanups = save_current_space_and_thread ();
11801 switch_to_program_space_and_thread (b->pspace);
11802 set_language (b->language);
11807 /* Reset a breakpoint given it's struct breakpoint * BINT.
11808 The value we return ends up being the return value from catch_errors.
11809 Unused in this case. */
11812 breakpoint_re_set_one (void *bint)
11814 /* Get past catch_errs. */
11815 struct breakpoint *b = (struct breakpoint *) bint;
11816 struct cleanup *cleanups;
11818 cleanups = prepare_re_set_context (b);
11819 b->ops->re_set (b);
11820 do_cleanups (cleanups);
11824 /* Re-set all breakpoints after symbols have been re-loaded. */
11826 breakpoint_re_set (void)
11828 struct breakpoint *b, *b_tmp;
11829 enum language save_language;
11830 int save_input_radix;
11831 struct cleanup *old_chain;
11833 save_language = current_language->la_language;
11834 save_input_radix = input_radix;
11835 old_chain = save_current_program_space ();
11837 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11839 /* Format possible error msg. */
11840 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
11842 struct cleanup *cleanups = make_cleanup (xfree, message);
11843 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
11844 do_cleanups (cleanups);
11846 set_language (save_language);
11847 input_radix = save_input_radix;
11849 jit_breakpoint_re_set ();
11851 do_cleanups (old_chain);
11853 create_overlay_event_breakpoint ();
11854 create_longjmp_master_breakpoint ();
11855 create_std_terminate_master_breakpoint ();
11856 create_exception_master_breakpoint ();
11859 /* Reset the thread number of this breakpoint:
11861 - If the breakpoint is for all threads, leave it as-is.
11862 - Else, reset it to the current thread for inferior_ptid. */
11864 breakpoint_re_set_thread (struct breakpoint *b)
11866 if (b->thread != -1)
11868 if (in_thread_list (inferior_ptid))
11869 b->thread = pid_to_thread_id (inferior_ptid);
11871 /* We're being called after following a fork. The new fork is
11872 selected as current, and unless this was a vfork will have a
11873 different program space from the original thread. Reset that
11875 b->loc->pspace = current_program_space;
11879 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11880 If from_tty is nonzero, it prints a message to that effect,
11881 which ends with a period (no newline). */
11884 set_ignore_count (int bptnum, int count, int from_tty)
11886 struct breakpoint *b;
11891 ALL_BREAKPOINTS (b)
11892 if (b->number == bptnum)
11894 if (is_tracepoint (b))
11896 if (from_tty && count != 0)
11897 printf_filtered (_("Ignore count ignored for tracepoint %d."),
11902 b->ignore_count = count;
11906 printf_filtered (_("Will stop next time "
11907 "breakpoint %d is reached."),
11909 else if (count == 1)
11910 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
11913 printf_filtered (_("Will ignore next %d "
11914 "crossings of breakpoint %d."),
11917 breakpoints_changed ();
11918 observer_notify_breakpoint_modified (b);
11922 error (_("No breakpoint number %d."), bptnum);
11925 /* Command to set ignore-count of breakpoint N to COUNT. */
11928 ignore_command (char *args, int from_tty)
11934 error_no_arg (_("a breakpoint number"));
11936 num = get_number (&p);
11938 error (_("bad breakpoint number: '%s'"), args);
11940 error (_("Second argument (specified ignore-count) is missing."));
11942 set_ignore_count (num,
11943 longest_to_int (value_as_long (parse_and_eval (p))),
11946 printf_filtered ("\n");
11949 /* Call FUNCTION on each of the breakpoints
11950 whose numbers are given in ARGS. */
11953 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
11958 struct breakpoint *b, *tmp;
11960 struct get_number_or_range_state state;
11963 error_no_arg (_("one or more breakpoint numbers"));
11965 init_number_or_range (&state, args);
11967 while (!state.finished)
11969 char *p = state.string;
11973 num = get_number_or_range (&state);
11976 warning (_("bad breakpoint number at or near '%s'"), p);
11980 ALL_BREAKPOINTS_SAFE (b, tmp)
11981 if (b->number == num)
11984 function (b, data);
11988 printf_unfiltered (_("No breakpoint number %d.\n"), num);
11993 static struct bp_location *
11994 find_location_by_number (char *number)
11996 char *dot = strchr (number, '.');
12000 struct breakpoint *b;
12001 struct bp_location *loc;
12006 bp_num = get_number (&p1);
12008 error (_("Bad breakpoint number '%s'"), number);
12010 ALL_BREAKPOINTS (b)
12011 if (b->number == bp_num)
12016 if (!b || b->number != bp_num)
12017 error (_("Bad breakpoint number '%s'"), number);
12020 loc_num = get_number (&p1);
12022 error (_("Bad breakpoint location number '%s'"), number);
12026 for (;loc_num && loc; --loc_num, loc = loc->next)
12029 error (_("Bad breakpoint location number '%s'"), dot+1);
12035 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12036 If from_tty is nonzero, it prints a message to that effect,
12037 which ends with a period (no newline). */
12040 disable_breakpoint (struct breakpoint *bpt)
12042 /* Never disable a watchpoint scope breakpoint; we want to
12043 hit them when we leave scope so we can delete both the
12044 watchpoint and its scope breakpoint at that time. */
12045 if (bpt->type == bp_watchpoint_scope)
12048 /* You can't disable permanent breakpoints. */
12049 if (bpt->enable_state == bp_permanent)
12052 bpt->enable_state = bp_disabled;
12054 if (target_supports_enable_disable_tracepoint ()
12055 && current_trace_status ()->running && is_tracepoint (bpt))
12057 struct bp_location *location;
12059 for (location = bpt->loc; location; location = location->next)
12060 target_disable_tracepoint (location);
12063 update_global_location_list (0);
12065 observer_notify_breakpoint_modified (bpt);
12068 /* A callback for iterate_over_related_breakpoints. */
12071 do_disable_breakpoint (struct breakpoint *b, void *ignore)
12073 disable_breakpoint (b);
12076 /* A callback for map_breakpoint_numbers that calls
12077 disable_breakpoint. */
12080 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
12082 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
12086 disable_command (char *args, int from_tty)
12090 struct breakpoint *bpt;
12092 ALL_BREAKPOINTS (bpt)
12093 if (user_breakpoint_p (bpt))
12094 disable_breakpoint (bpt);
12096 else if (strchr (args, '.'))
12098 struct bp_location *loc = find_location_by_number (args);
12102 if (target_supports_enable_disable_tracepoint ()
12103 && current_trace_status ()->running && loc->owner
12104 && is_tracepoint (loc->owner))
12105 target_disable_tracepoint (loc);
12107 update_global_location_list (0);
12110 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
12114 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition)
12116 int target_resources_ok;
12118 if (bpt->type == bp_hardware_breakpoint)
12121 i = hw_breakpoint_used_count ();
12122 target_resources_ok =
12123 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
12125 if (target_resources_ok == 0)
12126 error (_("No hardware breakpoint support in the target."));
12127 else if (target_resources_ok < 0)
12128 error (_("Hardware breakpoints used exceeds limit."));
12131 if (is_watchpoint (bpt))
12133 /* Initialize it just to avoid a GCC false warning. */
12134 enum enable_state orig_enable_state = 0;
12135 struct gdb_exception e;
12137 TRY_CATCH (e, RETURN_MASK_ALL)
12139 struct watchpoint *w = (struct watchpoint *) bpt;
12141 orig_enable_state = bpt->enable_state;
12142 bpt->enable_state = bp_enabled;
12143 update_watchpoint (w, 1 /* reparse */);
12147 bpt->enable_state = orig_enable_state;
12148 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
12154 if (bpt->enable_state != bp_permanent)
12155 bpt->enable_state = bp_enabled;
12157 if (target_supports_enable_disable_tracepoint ()
12158 && current_trace_status ()->running && is_tracepoint (bpt))
12160 struct bp_location *location;
12162 for (location = bpt->loc; location; location = location->next)
12163 target_enable_tracepoint (location);
12166 bpt->disposition = disposition;
12167 update_global_location_list (1);
12168 breakpoints_changed ();
12170 observer_notify_breakpoint_modified (bpt);
12175 enable_breakpoint (struct breakpoint *bpt)
12177 enable_breakpoint_disp (bpt, bpt->disposition);
12181 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
12183 enable_breakpoint (bpt);
12186 /* A callback for map_breakpoint_numbers that calls
12187 enable_breakpoint. */
12190 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
12192 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
12195 /* The enable command enables the specified breakpoints (or all defined
12196 breakpoints) so they once again become (or continue to be) effective
12197 in stopping the inferior. */
12200 enable_command (char *args, int from_tty)
12204 struct breakpoint *bpt;
12206 ALL_BREAKPOINTS (bpt)
12207 if (user_breakpoint_p (bpt))
12208 enable_breakpoint (bpt);
12210 else if (strchr (args, '.'))
12212 struct bp_location *loc = find_location_by_number (args);
12216 if (target_supports_enable_disable_tracepoint ()
12217 && current_trace_status ()->running && loc->owner
12218 && is_tracepoint (loc->owner))
12219 target_enable_tracepoint (loc);
12221 update_global_location_list (1);
12224 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
12228 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
12230 enum bpdisp disp = *(enum bpdisp *) arg;
12232 enable_breakpoint_disp (bpt, disp);
12236 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
12238 enum bpdisp disp = disp_disable;
12240 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
12244 enable_once_command (char *args, int from_tty)
12246 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
12250 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
12252 enum bpdisp disp = disp_del;
12254 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
12258 enable_delete_command (char *args, int from_tty)
12260 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
12264 set_breakpoint_cmd (char *args, int from_tty)
12269 show_breakpoint_cmd (char *args, int from_tty)
12273 /* Invalidate last known value of any hardware watchpoint if
12274 the memory which that value represents has been written to by
12278 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
12279 const bfd_byte *data)
12281 struct breakpoint *bp;
12283 ALL_BREAKPOINTS (bp)
12284 if (bp->enable_state == bp_enabled
12285 && bp->type == bp_hardware_watchpoint)
12287 struct watchpoint *wp = (struct watchpoint *) bp;
12289 if (wp->val_valid && wp->val)
12291 struct bp_location *loc;
12293 for (loc = bp->loc; loc != NULL; loc = loc->next)
12294 if (loc->loc_type == bp_loc_hardware_watchpoint
12295 && loc->address + loc->length > addr
12296 && addr + len > loc->address)
12298 value_free (wp->val);
12306 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
12308 struct symtabs_and_lines
12309 decode_line_spec_1 (char *string, int funfirstline)
12311 struct symtabs_and_lines sals;
12314 error (_("Empty line specification."));
12315 if (default_breakpoint_valid)
12316 sals = decode_line_1 (&string, funfirstline,
12317 default_breakpoint_symtab,
12318 default_breakpoint_line,
12321 sals = decode_line_1 (&string, funfirstline,
12322 (struct symtab *) NULL, 0, NULL);
12324 error (_("Junk at end of line specification: %s"), string);
12328 /* Create and insert a raw software breakpoint at PC. Return an
12329 identifier, which should be used to remove the breakpoint later.
12330 In general, places which call this should be using something on the
12331 breakpoint chain instead; this function should be eliminated
12335 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
12336 struct address_space *aspace, CORE_ADDR pc)
12338 struct bp_target_info *bp_tgt;
12340 bp_tgt = XZALLOC (struct bp_target_info);
12342 bp_tgt->placed_address_space = aspace;
12343 bp_tgt->placed_address = pc;
12345 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
12347 /* Could not insert the breakpoint. */
12355 /* Remove a breakpoint BP inserted by
12356 deprecated_insert_raw_breakpoint. */
12359 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
12361 struct bp_target_info *bp_tgt = bp;
12364 ret = target_remove_breakpoint (gdbarch, bp_tgt);
12370 /* One (or perhaps two) breakpoints used for software single
12373 static void *single_step_breakpoints[2];
12374 static struct gdbarch *single_step_gdbarch[2];
12376 /* Create and insert a breakpoint for software single step. */
12379 insert_single_step_breakpoint (struct gdbarch *gdbarch,
12380 struct address_space *aspace,
12385 if (single_step_breakpoints[0] == NULL)
12387 bpt_p = &single_step_breakpoints[0];
12388 single_step_gdbarch[0] = gdbarch;
12392 gdb_assert (single_step_breakpoints[1] == NULL);
12393 bpt_p = &single_step_breakpoints[1];
12394 single_step_gdbarch[1] = gdbarch;
12397 /* NOTE drow/2006-04-11: A future improvement to this function would
12398 be to only create the breakpoints once, and actually put them on
12399 the breakpoint chain. That would let us use set_raw_breakpoint.
12400 We could adjust the addresses each time they were needed. Doing
12401 this requires corresponding changes elsewhere where single step
12402 breakpoints are handled, however. So, for now, we use this. */
12404 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
12405 if (*bpt_p == NULL)
12406 error (_("Could not insert single-step breakpoint at %s"),
12407 paddress (gdbarch, next_pc));
12410 /* Check if the breakpoints used for software single stepping
12411 were inserted or not. */
12414 single_step_breakpoints_inserted (void)
12416 return (single_step_breakpoints[0] != NULL
12417 || single_step_breakpoints[1] != NULL);
12420 /* Remove and delete any breakpoints used for software single step. */
12423 remove_single_step_breakpoints (void)
12425 gdb_assert (single_step_breakpoints[0] != NULL);
12427 /* See insert_single_step_breakpoint for more about this deprecated
12429 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
12430 single_step_breakpoints[0]);
12431 single_step_gdbarch[0] = NULL;
12432 single_step_breakpoints[0] = NULL;
12434 if (single_step_breakpoints[1] != NULL)
12436 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
12437 single_step_breakpoints[1]);
12438 single_step_gdbarch[1] = NULL;
12439 single_step_breakpoints[1] = NULL;
12443 /* Delete software single step breakpoints without removing them from
12444 the inferior. This is intended to be used if the inferior's address
12445 space where they were inserted is already gone, e.g. after exit or
12449 cancel_single_step_breakpoints (void)
12453 for (i = 0; i < 2; i++)
12454 if (single_step_breakpoints[i])
12456 xfree (single_step_breakpoints[i]);
12457 single_step_breakpoints[i] = NULL;
12458 single_step_gdbarch[i] = NULL;
12462 /* Detach software single-step breakpoints from INFERIOR_PTID without
12466 detach_single_step_breakpoints (void)
12470 for (i = 0; i < 2; i++)
12471 if (single_step_breakpoints[i])
12472 target_remove_breakpoint (single_step_gdbarch[i],
12473 single_step_breakpoints[i]);
12476 /* Check whether a software single-step breakpoint is inserted at
12480 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
12485 for (i = 0; i < 2; i++)
12487 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
12489 && breakpoint_address_match (bp_tgt->placed_address_space,
12490 bp_tgt->placed_address,
12498 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12499 non-zero otherwise. */
12501 is_syscall_catchpoint_enabled (struct breakpoint *bp)
12503 if (syscall_catchpoint_p (bp)
12504 && bp->enable_state != bp_disabled
12505 && bp->enable_state != bp_call_disabled)
12512 catch_syscall_enabled (void)
12514 struct inferior *inf = current_inferior ();
12516 return inf->total_syscalls_count != 0;
12520 catching_syscall_number (int syscall_number)
12522 struct breakpoint *bp;
12524 ALL_BREAKPOINTS (bp)
12525 if (is_syscall_catchpoint_enabled (bp))
12527 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
12529 if (c->syscalls_to_be_caught)
12533 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
12535 if (syscall_number == iter)
12545 /* Complete syscall names. Used by "catch syscall". */
12547 catch_syscall_completer (struct cmd_list_element *cmd,
12548 char *text, char *word)
12550 const char **list = get_syscall_names ();
12552 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
12558 /* Tracepoint-specific operations. */
12560 /* Set tracepoint count to NUM. */
12562 set_tracepoint_count (int num)
12564 tracepoint_count = num;
12565 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
12569 trace_command (char *arg, int from_tty)
12571 if (create_breakpoint (get_current_arch (),
12573 NULL, 0, 1 /* parse arg */,
12575 bp_tracepoint /* type_wanted */,
12576 0 /* Ignore count */,
12577 pending_break_support,
12578 &tracepoint_breakpoint_ops,
12582 set_tracepoint_count (breakpoint_count);
12586 ftrace_command (char *arg, int from_tty)
12588 if (create_breakpoint (get_current_arch (),
12590 NULL, 0, 1 /* parse arg */,
12592 bp_fast_tracepoint /* type_wanted */,
12593 0 /* Ignore count */,
12594 pending_break_support,
12595 &tracepoint_breakpoint_ops,
12599 set_tracepoint_count (breakpoint_count);
12602 /* strace command implementation. Creates a static tracepoint. */
12605 strace_command (char *arg, int from_tty)
12607 if (create_breakpoint (get_current_arch (),
12609 NULL, 0, 1 /* parse arg */,
12611 bp_static_tracepoint /* type_wanted */,
12612 0 /* Ignore count */,
12613 pending_break_support,
12614 &tracepoint_breakpoint_ops,
12618 set_tracepoint_count (breakpoint_count);
12621 /* Set up a fake reader function that gets command lines from a linked
12622 list that was acquired during tracepoint uploading. */
12624 static struct uploaded_tp *this_utp;
12625 static int next_cmd;
12628 read_uploaded_action (void)
12632 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
12639 /* Given information about a tracepoint as recorded on a target (which
12640 can be either a live system or a trace file), attempt to create an
12641 equivalent GDB tracepoint. This is not a reliable process, since
12642 the target does not necessarily have all the information used when
12643 the tracepoint was originally defined. */
12645 struct tracepoint *
12646 create_tracepoint_from_upload (struct uploaded_tp *utp)
12648 char *addr_str, small_buf[100];
12649 struct tracepoint *tp;
12651 if (utp->at_string)
12652 addr_str = utp->at_string;
12655 /* In the absence of a source location, fall back to raw
12656 address. Since there is no way to confirm that the address
12657 means the same thing as when the trace was started, warn the
12659 warning (_("Uploaded tracepoint %d has no "
12660 "source location, using raw address"),
12662 sprintf (small_buf, "*%s", hex_string (utp->addr));
12663 addr_str = small_buf;
12666 /* There's not much we can do with a sequence of bytecodes. */
12667 if (utp->cond && !utp->cond_string)
12668 warning (_("Uploaded tracepoint %d condition "
12669 "has no source form, ignoring it"),
12672 if (!create_breakpoint (get_current_arch (),
12674 utp->cond_string, -1, 0 /* parse cond/thread */,
12676 utp->type /* type_wanted */,
12677 0 /* Ignore count */,
12678 pending_break_support,
12679 &tracepoint_breakpoint_ops,
12681 utp->enabled /* enabled */,
12685 set_tracepoint_count (breakpoint_count);
12687 /* Get the tracepoint we just created. */
12688 tp = get_tracepoint (tracepoint_count);
12689 gdb_assert (tp != NULL);
12693 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
12695 trace_pass_command (small_buf, 0);
12698 /* If we have uploaded versions of the original commands, set up a
12699 special-purpose "reader" function and call the usual command line
12700 reader, then pass the result to the breakpoint command-setting
12702 if (!VEC_empty (char_ptr, utp->cmd_strings))
12704 struct command_line *cmd_list;
12709 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
12711 breakpoint_set_commands (&tp->base, cmd_list);
12713 else if (!VEC_empty (char_ptr, utp->actions)
12714 || !VEC_empty (char_ptr, utp->step_actions))
12715 warning (_("Uploaded tracepoint %d actions "
12716 "have no source form, ignoring them"),
12722 /* Print information on tracepoint number TPNUM_EXP, or all if
12726 tracepoints_info (char *args, int from_tty)
12730 num_printed = breakpoint_1 (args, 0, is_tracepoint);
12732 if (num_printed == 0)
12734 if (args == NULL || *args == '\0')
12735 ui_out_message (uiout, 0, "No tracepoints.\n");
12737 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
12740 default_collect_info ();
12743 /* The 'enable trace' command enables tracepoints.
12744 Not supported by all targets. */
12746 enable_trace_command (char *args, int from_tty)
12748 enable_command (args, from_tty);
12751 /* The 'disable trace' command disables tracepoints.
12752 Not supported by all targets. */
12754 disable_trace_command (char *args, int from_tty)
12756 disable_command (args, from_tty);
12759 /* Remove a tracepoint (or all if no argument). */
12761 delete_trace_command (char *arg, int from_tty)
12763 struct breakpoint *b, *b_tmp;
12769 int breaks_to_delete = 0;
12771 /* Delete all breakpoints if no argument.
12772 Do not delete internal or call-dummy breakpoints, these
12773 have to be deleted with an explicit breakpoint number
12775 ALL_TRACEPOINTS (b)
12776 if (is_tracepoint (b) && user_breakpoint_p (b))
12778 breaks_to_delete = 1;
12782 /* Ask user only if there are some breakpoints to delete. */
12784 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
12786 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12787 if (is_tracepoint (b) && user_breakpoint_p (b))
12788 delete_breakpoint (b);
12792 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
12795 /* Helper function for trace_pass_command. */
12798 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
12800 tp->pass_count = count;
12801 observer_notify_tracepoint_modified (tp->base.number);
12803 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12804 tp->base.number, count);
12807 /* Set passcount for tracepoint.
12809 First command argument is passcount, second is tracepoint number.
12810 If tracepoint number omitted, apply to most recently defined.
12811 Also accepts special argument "all". */
12814 trace_pass_command (char *args, int from_tty)
12816 struct tracepoint *t1;
12817 unsigned int count;
12819 if (args == 0 || *args == 0)
12820 error (_("passcount command requires an "
12821 "argument (count + optional TP num)"));
12823 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
12825 while (*args && isspace ((int) *args))
12828 if (*args && strncasecmp (args, "all", 3) == 0)
12830 struct breakpoint *b;
12832 args += 3; /* Skip special argument "all". */
12834 error (_("Junk at end of arguments."));
12836 ALL_TRACEPOINTS (b)
12838 t1 = (struct tracepoint *) b;
12839 trace_pass_set_count (t1, count, from_tty);
12842 else if (*args == '\0')
12844 t1 = get_tracepoint_by_number (&args, NULL, 1);
12846 trace_pass_set_count (t1, count, from_tty);
12850 struct get_number_or_range_state state;
12852 init_number_or_range (&state, args);
12853 while (!state.finished)
12855 t1 = get_tracepoint_by_number (&args, &state, 1);
12857 trace_pass_set_count (t1, count, from_tty);
12862 struct tracepoint *
12863 get_tracepoint (int num)
12865 struct breakpoint *t;
12867 ALL_TRACEPOINTS (t)
12868 if (t->number == num)
12869 return (struct tracepoint *) t;
12874 /* Find the tracepoint with the given target-side number (which may be
12875 different from the tracepoint number after disconnecting and
12878 struct tracepoint *
12879 get_tracepoint_by_number_on_target (int num)
12881 struct breakpoint *b;
12883 ALL_TRACEPOINTS (b)
12885 struct tracepoint *t = (struct tracepoint *) b;
12887 if (t->number_on_target == num)
12894 /* Utility: parse a tracepoint number and look it up in the list.
12895 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
12896 If OPTIONAL_P is true, then if the argument is missing, the most
12897 recent tracepoint (tracepoint_count) is returned. */
12898 struct tracepoint *
12899 get_tracepoint_by_number (char **arg,
12900 struct get_number_or_range_state *state,
12903 extern int tracepoint_count;
12904 struct breakpoint *t;
12906 char *instring = arg == NULL ? NULL : *arg;
12910 gdb_assert (!state->finished);
12911 tpnum = get_number_or_range (state);
12913 else if (arg == NULL || *arg == NULL || ! **arg)
12916 tpnum = tracepoint_count;
12918 error_no_arg (_("tracepoint number"));
12921 tpnum = get_number (arg);
12925 if (instring && *instring)
12926 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
12929 printf_filtered (_("Tracepoint argument missing "
12930 "and no previous tracepoint\n"));
12934 ALL_TRACEPOINTS (t)
12935 if (t->number == tpnum)
12937 return (struct tracepoint *) t;
12940 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
12945 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
12947 if (b->thread != -1)
12948 fprintf_unfiltered (fp, " thread %d", b->thread);
12951 fprintf_unfiltered (fp, " task %d", b->task);
12953 fprintf_unfiltered (fp, "\n");
12956 /* Save information on user settable breakpoints (watchpoints, etc) to
12957 a new script file named FILENAME. If FILTER is non-NULL, call it
12958 on each breakpoint and only include the ones for which it returns
12962 save_breakpoints (char *filename, int from_tty,
12963 int (*filter) (const struct breakpoint *))
12965 struct breakpoint *tp;
12968 struct cleanup *cleanup;
12969 struct ui_file *fp;
12970 int extra_trace_bits = 0;
12972 if (filename == 0 || *filename == 0)
12973 error (_("Argument required (file name in which to save)"));
12975 /* See if we have anything to save. */
12976 ALL_BREAKPOINTS (tp)
12978 /* Skip internal and momentary breakpoints. */
12979 if (!user_breakpoint_p (tp))
12982 /* If we have a filter, only save the breakpoints it accepts. */
12983 if (filter && !filter (tp))
12988 if (is_tracepoint (tp))
12990 extra_trace_bits = 1;
12992 /* We can stop searching. */
12999 warning (_("Nothing to save."));
13003 pathname = tilde_expand (filename);
13004 cleanup = make_cleanup (xfree, pathname);
13005 fp = gdb_fopen (pathname, "w");
13007 error (_("Unable to open file '%s' for saving (%s)"),
13008 filename, safe_strerror (errno));
13009 make_cleanup_ui_file_delete (fp);
13011 if (extra_trace_bits)
13012 save_trace_state_variables (fp);
13014 ALL_BREAKPOINTS (tp)
13016 /* Skip internal and momentary breakpoints. */
13017 if (!user_breakpoint_p (tp))
13020 /* If we have a filter, only save the breakpoints it accepts. */
13021 if (filter && !filter (tp))
13024 tp->ops->print_recreate (tp, fp);
13026 /* Note, we can't rely on tp->number for anything, as we can't
13027 assume the recreated breakpoint numbers will match. Use $bpnum
13030 if (tp->cond_string)
13031 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
13033 if (tp->ignore_count)
13034 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
13038 volatile struct gdb_exception ex;
13040 fprintf_unfiltered (fp, " commands\n");
13042 ui_out_redirect (uiout, fp);
13043 TRY_CATCH (ex, RETURN_MASK_ALL)
13045 print_command_lines (uiout, tp->commands->commands, 2);
13047 ui_out_redirect (uiout, NULL);
13050 throw_exception (ex);
13052 fprintf_unfiltered (fp, " end\n");
13055 if (tp->enable_state == bp_disabled)
13056 fprintf_unfiltered (fp, "disable\n");
13058 /* If this is a multi-location breakpoint, check if the locations
13059 should be individually disabled. Watchpoint locations are
13060 special, and not user visible. */
13061 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
13063 struct bp_location *loc;
13066 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
13068 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
13072 if (extra_trace_bits && *default_collect)
13073 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
13075 do_cleanups (cleanup);
13077 printf_filtered (_("Saved to file '%s'.\n"), filename);
13080 /* The `save breakpoints' command. */
13083 save_breakpoints_command (char *args, int from_tty)
13085 save_breakpoints (args, from_tty, NULL);
13088 /* The `save tracepoints' command. */
13091 save_tracepoints_command (char *args, int from_tty)
13093 save_breakpoints (args, from_tty, is_tracepoint);
13096 /* Create a vector of all tracepoints. */
13098 VEC(breakpoint_p) *
13099 all_tracepoints (void)
13101 VEC(breakpoint_p) *tp_vec = 0;
13102 struct breakpoint *tp;
13104 ALL_TRACEPOINTS (tp)
13106 VEC_safe_push (breakpoint_p, tp_vec, tp);
13113 /* This help string is used for the break, hbreak, tbreak and thbreak
13114 commands. It is defined as a macro to prevent duplication.
13115 COMMAND should be a string constant containing the name of the
13117 #define BREAK_ARGS_HELP(command) \
13118 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13119 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13120 If a line number is specified, break at start of code for that line.\n\
13121 If a function is specified, break at start of code for that function.\n\
13122 If an address is specified, break at that exact address.\n\
13123 With no LOCATION, uses current execution address of the selected\n\
13124 stack frame. This is useful for breaking on return to a stack frame.\n\
13126 THREADNUM is the number from \"info threads\".\n\
13127 CONDITION is a boolean expression.\n\
13129 Multiple breakpoints at one place are permitted, and useful if their\n\
13130 conditions are different.\n\
13132 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13134 /* List of subcommands for "catch". */
13135 static struct cmd_list_element *catch_cmdlist;
13137 /* List of subcommands for "tcatch". */
13138 static struct cmd_list_element *tcatch_cmdlist;
13141 add_catch_command (char *name, char *docstring,
13142 void (*sfunc) (char *args, int from_tty,
13143 struct cmd_list_element *command),
13144 char **(*completer) (struct cmd_list_element *cmd,
13145 char *text, char *word),
13146 void *user_data_catch,
13147 void *user_data_tcatch)
13149 struct cmd_list_element *command;
13151 command = add_cmd (name, class_breakpoint, NULL, docstring,
13153 set_cmd_sfunc (command, sfunc);
13154 set_cmd_context (command, user_data_catch);
13155 set_cmd_completer (command, completer);
13157 command = add_cmd (name, class_breakpoint, NULL, docstring,
13159 set_cmd_sfunc (command, sfunc);
13160 set_cmd_context (command, user_data_tcatch);
13161 set_cmd_completer (command, completer);
13165 clear_syscall_counts (struct inferior *inf)
13167 inf->total_syscalls_count = 0;
13168 inf->any_syscall_count = 0;
13169 VEC_free (int, inf->syscalls_counts);
13173 save_command (char *arg, int from_tty)
13175 printf_unfiltered (_("\"save\" must be followed by "
13176 "the name of a save subcommand.\n"));
13177 help_list (save_cmdlist, "save ", -1, gdb_stdout);
13180 struct breakpoint *
13181 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
13184 struct breakpoint *b, *b_tmp;
13186 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13188 if ((*callback) (b, data))
13196 initialize_breakpoint_ops (void)
13198 static int initialized = 0;
13200 struct breakpoint_ops *ops;
13206 /* The breakpoint_ops structure to be inherit by all kinds of
13207 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13208 internal and momentary breakpoints, etc.). */
13209 ops = &bkpt_base_breakpoint_ops;
13210 *ops = base_breakpoint_ops;
13211 ops->re_set = bkpt_re_set;
13212 ops->insert_location = bkpt_insert_location;
13213 ops->remove_location = bkpt_remove_location;
13214 ops->breakpoint_hit = bkpt_breakpoint_hit;
13216 /* The breakpoint_ops structure to be used in regular breakpoints. */
13217 ops = &bkpt_breakpoint_ops;
13218 *ops = bkpt_base_breakpoint_ops;
13219 ops->re_set = bkpt_re_set;
13220 ops->resources_needed = bkpt_resources_needed;
13221 ops->print_it = bkpt_print_it;
13222 ops->print_mention = bkpt_print_mention;
13223 ops->print_recreate = bkpt_print_recreate;
13225 /* Ranged breakpoints. */
13226 ops = &ranged_breakpoint_ops;
13227 *ops = bkpt_breakpoint_ops;
13228 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
13229 ops->resources_needed = resources_needed_ranged_breakpoint;
13230 ops->print_it = print_it_ranged_breakpoint;
13231 ops->print_one = print_one_ranged_breakpoint;
13232 ops->print_one_detail = print_one_detail_ranged_breakpoint;
13233 ops->print_mention = print_mention_ranged_breakpoint;
13234 ops->print_recreate = print_recreate_ranged_breakpoint;
13236 /* Internal breakpoints. */
13237 ops = &internal_breakpoint_ops;
13238 *ops = bkpt_base_breakpoint_ops;
13239 ops->re_set = internal_bkpt_re_set;
13240 ops->check_status = internal_bkpt_check_status;
13241 ops->print_it = internal_bkpt_print_it;
13242 ops->print_mention = internal_bkpt_print_mention;
13244 /* Momentary breakpoints. */
13245 ops = &momentary_breakpoint_ops;
13246 *ops = bkpt_base_breakpoint_ops;
13247 ops->re_set = momentary_bkpt_re_set;
13248 ops->check_status = momentary_bkpt_check_status;
13249 ops->print_it = momentary_bkpt_print_it;
13250 ops->print_mention = momentary_bkpt_print_mention;
13252 /* GNU v3 exception catchpoints. */
13253 ops = &gnu_v3_exception_catchpoint_ops;
13254 *ops = bkpt_breakpoint_ops;
13255 ops->print_it = print_it_exception_catchpoint;
13256 ops->print_one = print_one_exception_catchpoint;
13257 ops->print_mention = print_mention_exception_catchpoint;
13258 ops->print_recreate = print_recreate_exception_catchpoint;
13261 ops = &watchpoint_breakpoint_ops;
13262 *ops = base_breakpoint_ops;
13263 ops->dtor = dtor_watchpoint;
13264 ops->re_set = re_set_watchpoint;
13265 ops->insert_location = insert_watchpoint;
13266 ops->remove_location = remove_watchpoint;
13267 ops->breakpoint_hit = breakpoint_hit_watchpoint;
13268 ops->check_status = check_status_watchpoint;
13269 ops->resources_needed = resources_needed_watchpoint;
13270 ops->works_in_software_mode = works_in_software_mode_watchpoint;
13271 ops->print_it = print_it_watchpoint;
13272 ops->print_mention = print_mention_watchpoint;
13273 ops->print_recreate = print_recreate_watchpoint;
13275 /* Masked watchpoints. */
13276 ops = &masked_watchpoint_breakpoint_ops;
13277 *ops = watchpoint_breakpoint_ops;
13278 ops->insert_location = insert_masked_watchpoint;
13279 ops->remove_location = remove_masked_watchpoint;
13280 ops->resources_needed = resources_needed_masked_watchpoint;
13281 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
13282 ops->print_it = print_it_masked_watchpoint;
13283 ops->print_one_detail = print_one_detail_masked_watchpoint;
13284 ops->print_mention = print_mention_masked_watchpoint;
13285 ops->print_recreate = print_recreate_masked_watchpoint;
13288 ops = &tracepoint_breakpoint_ops;
13289 *ops = base_breakpoint_ops;
13290 ops->re_set = tracepoint_re_set;
13291 ops->breakpoint_hit = tracepoint_breakpoint_hit;
13292 ops->print_one_detail = tracepoint_print_one_detail;
13293 ops->print_mention = tracepoint_print_mention;
13294 ops->print_recreate = tracepoint_print_recreate;
13296 /* Fork catchpoints. */
13297 ops = &catch_fork_breakpoint_ops;
13298 *ops = base_breakpoint_ops;
13299 ops->insert_location = insert_catch_fork;
13300 ops->remove_location = remove_catch_fork;
13301 ops->breakpoint_hit = breakpoint_hit_catch_fork;
13302 ops->print_it = print_it_catch_fork;
13303 ops->print_one = print_one_catch_fork;
13304 ops->print_mention = print_mention_catch_fork;
13305 ops->print_recreate = print_recreate_catch_fork;
13307 /* Vfork catchpoints. */
13308 ops = &catch_vfork_breakpoint_ops;
13309 *ops = base_breakpoint_ops;
13310 ops->insert_location = insert_catch_vfork;
13311 ops->remove_location = remove_catch_vfork;
13312 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
13313 ops->print_it = print_it_catch_vfork;
13314 ops->print_one = print_one_catch_vfork;
13315 ops->print_mention = print_mention_catch_vfork;
13316 ops->print_recreate = print_recreate_catch_vfork;
13318 /* Exec catchpoints. */
13319 ops = &catch_exec_breakpoint_ops;
13320 *ops = base_breakpoint_ops;
13321 ops->dtor = dtor_catch_exec;
13322 ops->insert_location = insert_catch_exec;
13323 ops->remove_location = remove_catch_exec;
13324 ops->breakpoint_hit = breakpoint_hit_catch_exec;
13325 ops->print_it = print_it_catch_exec;
13326 ops->print_one = print_one_catch_exec;
13327 ops->print_mention = print_mention_catch_exec;
13328 ops->print_recreate = print_recreate_catch_exec;
13330 /* Syscall catchpoints. */
13331 ops = &catch_syscall_breakpoint_ops;
13332 *ops = base_breakpoint_ops;
13333 ops->dtor = dtor_catch_syscall;
13334 ops->insert_location = insert_catch_syscall;
13335 ops->remove_location = remove_catch_syscall;
13336 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
13337 ops->print_it = print_it_catch_syscall;
13338 ops->print_one = print_one_catch_syscall;
13339 ops->print_mention = print_mention_catch_syscall;
13340 ops->print_recreate = print_recreate_catch_syscall;
13344 _initialize_breakpoint (void)
13346 struct cmd_list_element *c;
13348 initialize_breakpoint_ops ();
13350 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
13351 observer_attach_inferior_exit (clear_syscall_counts);
13352 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
13354 breakpoint_objfile_key = register_objfile_data ();
13356 breakpoint_chain = 0;
13357 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13358 before a breakpoint is set. */
13359 breakpoint_count = 0;
13361 tracepoint_count = 0;
13363 add_com ("ignore", class_breakpoint, ignore_command, _("\
13364 Set ignore-count of breakpoint number N to COUNT.\n\
13365 Usage is `ignore N COUNT'."));
13367 add_com_alias ("bc", "ignore", class_breakpoint, 1);
13369 add_com ("commands", class_breakpoint, commands_command, _("\
13370 Set commands to be executed when a breakpoint is hit.\n\
13371 Give breakpoint number as argument after \"commands\".\n\
13372 With no argument, the targeted breakpoint is the last one set.\n\
13373 The commands themselves follow starting on the next line.\n\
13374 Type a line containing \"end\" to indicate the end of them.\n\
13375 Give \"silent\" as the first line to make the breakpoint silent;\n\
13376 then no output is printed when it is hit, except what the commands print."));
13378 add_com ("condition", class_breakpoint, condition_command, _("\
13379 Specify breakpoint number N to break only if COND is true.\n\
13380 Usage is `condition N COND', where N is an integer and COND is an\n\
13381 expression to be evaluated whenever breakpoint N is reached."));
13383 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
13384 Set a temporary breakpoint.\n\
13385 Like \"break\" except the breakpoint is only temporary,\n\
13386 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13387 by using \"enable delete\" on the breakpoint number.\n\
13389 BREAK_ARGS_HELP ("tbreak")));
13390 set_cmd_completer (c, location_completer);
13392 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
13393 Set a hardware assisted breakpoint.\n\
13394 Like \"break\" except the breakpoint requires hardware support,\n\
13395 some target hardware may not have this support.\n\
13397 BREAK_ARGS_HELP ("hbreak")));
13398 set_cmd_completer (c, location_completer);
13400 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
13401 Set a temporary hardware assisted breakpoint.\n\
13402 Like \"hbreak\" except the breakpoint is only temporary,\n\
13403 so it will be deleted when hit.\n\
13405 BREAK_ARGS_HELP ("thbreak")));
13406 set_cmd_completer (c, location_completer);
13408 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
13409 Enable some breakpoints.\n\
13410 Give breakpoint numbers (separated by spaces) as arguments.\n\
13411 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13412 This is used to cancel the effect of the \"disable\" command.\n\
13413 With a subcommand you can enable temporarily."),
13414 &enablelist, "enable ", 1, &cmdlist);
13416 add_com ("ab", class_breakpoint, enable_command, _("\
13417 Enable some breakpoints.\n\
13418 Give breakpoint numbers (separated by spaces) as arguments.\n\
13419 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13420 This is used to cancel the effect of the \"disable\" command.\n\
13421 With a subcommand you can enable temporarily."));
13423 add_com_alias ("en", "enable", class_breakpoint, 1);
13425 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
13426 Enable some breakpoints.\n\
13427 Give breakpoint numbers (separated by spaces) as arguments.\n\
13428 This is used to cancel the effect of the \"disable\" command.\n\
13429 May be abbreviated to simply \"enable\".\n"),
13430 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
13432 add_cmd ("once", no_class, enable_once_command, _("\
13433 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13434 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13437 add_cmd ("delete", no_class, enable_delete_command, _("\
13438 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13439 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13442 add_cmd ("delete", no_class, enable_delete_command, _("\
13443 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13444 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13447 add_cmd ("once", no_class, enable_once_command, _("\
13448 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13449 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13452 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
13453 Disable some breakpoints.\n\
13454 Arguments are breakpoint numbers with spaces in between.\n\
13455 To disable all breakpoints, give no argument.\n\
13456 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13457 &disablelist, "disable ", 1, &cmdlist);
13458 add_com_alias ("dis", "disable", class_breakpoint, 1);
13459 add_com_alias ("disa", "disable", class_breakpoint, 1);
13461 add_com ("sb", class_breakpoint, disable_command, _("\
13462 Disable some breakpoints.\n\
13463 Arguments are breakpoint numbers with spaces in between.\n\
13464 To disable all breakpoints, give no argument.\n\
13465 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13467 add_cmd ("breakpoints", class_alias, disable_command, _("\
13468 Disable some breakpoints.\n\
13469 Arguments are breakpoint numbers with spaces in between.\n\
13470 To disable all breakpoints, give no argument.\n\
13471 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13472 This command may be abbreviated \"disable\"."),
13475 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
13476 Delete some breakpoints or auto-display expressions.\n\
13477 Arguments are breakpoint numbers with spaces in between.\n\
13478 To delete all breakpoints, give no argument.\n\
13480 Also a prefix command for deletion of other GDB objects.\n\
13481 The \"unset\" command is also an alias for \"delete\"."),
13482 &deletelist, "delete ", 1, &cmdlist);
13483 add_com_alias ("d", "delete", class_breakpoint, 1);
13484 add_com_alias ("del", "delete", class_breakpoint, 1);
13486 add_com ("db", class_breakpoint, delete_command, _("\
13487 Delete some breakpoints.\n\
13488 Arguments are breakpoint numbers with spaces in between.\n\
13489 To delete all breakpoints, give no argument.\n"));
13491 add_cmd ("breakpoints", class_alias, delete_command, _("\
13492 Delete some breakpoints or auto-display expressions.\n\
13493 Arguments are breakpoint numbers with spaces in between.\n\
13494 To delete all breakpoints, give no argument.\n\
13495 This command may be abbreviated \"delete\"."),
13498 add_com ("clear", class_breakpoint, clear_command, _("\
13499 Clear breakpoint at specified line or function.\n\
13500 Argument may be line number, function name, or \"*\" and an address.\n\
13501 If line number is specified, all breakpoints in that line are cleared.\n\
13502 If function is specified, breakpoints at beginning of function are cleared.\n\
13503 If an address is specified, breakpoints at that address are cleared.\n\
13505 With no argument, clears all breakpoints in the line that the selected frame\n\
13506 is executing in.\n\
13508 See also the \"delete\" command which clears breakpoints by number."));
13509 add_com_alias ("cl", "clear", class_breakpoint, 1);
13511 c = add_com ("break", class_breakpoint, break_command, _("\
13512 Set breakpoint at specified line or function.\n"
13513 BREAK_ARGS_HELP ("break")));
13514 set_cmd_completer (c, location_completer);
13516 add_com_alias ("b", "break", class_run, 1);
13517 add_com_alias ("br", "break", class_run, 1);
13518 add_com_alias ("bre", "break", class_run, 1);
13519 add_com_alias ("brea", "break", class_run, 1);
13522 add_com_alias ("ba", "break", class_breakpoint, 1);
13526 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
13527 Break in function/address or break at a line in the current file."),
13528 &stoplist, "stop ", 1, &cmdlist);
13529 add_cmd ("in", class_breakpoint, stopin_command,
13530 _("Break in function or address."), &stoplist);
13531 add_cmd ("at", class_breakpoint, stopat_command,
13532 _("Break at a line in the current file."), &stoplist);
13533 add_com ("status", class_info, breakpoints_info, _("\
13534 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13535 The \"Type\" column indicates one of:\n\
13536 \tbreakpoint - normal breakpoint\n\
13537 \twatchpoint - watchpoint\n\
13538 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13539 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13540 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13541 address and file/line number respectively.\n\
13543 Convenience variable \"$_\" and default examine address for \"x\"\n\
13544 are set to the address of the last breakpoint listed unless the command\n\
13545 is prefixed with \"server \".\n\n\
13546 Convenience variable \"$bpnum\" contains the number of the last\n\
13547 breakpoint set."));
13550 add_info ("breakpoints", breakpoints_info, _("\
13551 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13552 The \"Type\" column indicates one of:\n\
13553 \tbreakpoint - normal breakpoint\n\
13554 \twatchpoint - watchpoint\n\
13555 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13556 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13557 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13558 address and file/line number respectively.\n\
13560 Convenience variable \"$_\" and default examine address for \"x\"\n\
13561 are set to the address of the last breakpoint listed unless the command\n\
13562 is prefixed with \"server \".\n\n\
13563 Convenience variable \"$bpnum\" contains the number of the last\n\
13564 breakpoint set."));
13566 add_info_alias ("b", "breakpoints", 1);
13569 add_com ("lb", class_breakpoint, breakpoints_info, _("\
13570 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13571 The \"Type\" column indicates one of:\n\
13572 \tbreakpoint - normal breakpoint\n\
13573 \twatchpoint - watchpoint\n\
13574 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13575 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13576 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13577 address and file/line number respectively.\n\
13579 Convenience variable \"$_\" and default examine address for \"x\"\n\
13580 are set to the address of the last breakpoint listed unless the command\n\
13581 is prefixed with \"server \".\n\n\
13582 Convenience variable \"$bpnum\" contains the number of the last\n\
13583 breakpoint set."));
13585 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
13586 Status of all breakpoints, or breakpoint number NUMBER.\n\
13587 The \"Type\" column indicates one of:\n\
13588 \tbreakpoint - normal breakpoint\n\
13589 \twatchpoint - watchpoint\n\
13590 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13591 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13592 \tuntil - internal breakpoint used by the \"until\" command\n\
13593 \tfinish - internal breakpoint used by the \"finish\" command\n\
13594 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13595 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13596 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13597 address and file/line number respectively.\n\
13599 Convenience variable \"$_\" and default examine address for \"x\"\n\
13600 are set to the address of the last breakpoint listed unless the command\n\
13601 is prefixed with \"server \".\n\n\
13602 Convenience variable \"$bpnum\" contains the number of the last\n\
13604 &maintenanceinfolist);
13606 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
13607 Set catchpoints to catch events."),
13608 &catch_cmdlist, "catch ",
13609 0/*allow-unknown*/, &cmdlist);
13611 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
13612 Set temporary catchpoints to catch events."),
13613 &tcatch_cmdlist, "tcatch ",
13614 0/*allow-unknown*/, &cmdlist);
13616 /* Add catch and tcatch sub-commands. */
13617 add_catch_command ("catch", _("\
13618 Catch an exception, when caught.\n\
13619 With an argument, catch only exceptions with the given name."),
13620 catch_catch_command,
13624 add_catch_command ("throw", _("\
13625 Catch an exception, when thrown.\n\
13626 With an argument, catch only exceptions with the given name."),
13627 catch_throw_command,
13631 add_catch_command ("fork", _("Catch calls to fork."),
13632 catch_fork_command_1,
13634 (void *) (uintptr_t) catch_fork_permanent,
13635 (void *) (uintptr_t) catch_fork_temporary);
13636 add_catch_command ("vfork", _("Catch calls to vfork."),
13637 catch_fork_command_1,
13639 (void *) (uintptr_t) catch_vfork_permanent,
13640 (void *) (uintptr_t) catch_vfork_temporary);
13641 add_catch_command ("exec", _("Catch calls to exec."),
13642 catch_exec_command_1,
13646 add_catch_command ("syscall", _("\
13647 Catch system calls by their names and/or numbers.\n\
13648 Arguments say which system calls to catch. If no arguments\n\
13649 are given, every system call will be caught.\n\
13650 Arguments, if given, should be one or more system call names\n\
13651 (if your system supports that), or system call numbers."),
13652 catch_syscall_command_1,
13653 catch_syscall_completer,
13657 c = add_com ("watch", class_breakpoint, watch_command, _("\
13658 Set a watchpoint for an expression.\n\
13659 Usage: watch [-l|-location] EXPRESSION\n\
13660 A watchpoint stops execution of your program whenever the value of\n\
13661 an expression changes.\n\
13662 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13663 the memory to which it refers."));
13664 set_cmd_completer (c, expression_completer);
13666 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
13667 Set a read watchpoint for an expression.\n\
13668 Usage: rwatch [-l|-location] EXPRESSION\n\
13669 A watchpoint stops execution of your program whenever the value of\n\
13670 an expression is read.\n\
13671 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13672 the memory to which it refers."));
13673 set_cmd_completer (c, expression_completer);
13675 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
13676 Set a watchpoint for an expression.\n\
13677 Usage: awatch [-l|-location] EXPRESSION\n\
13678 A watchpoint stops execution of your program whenever the value of\n\
13679 an expression is either read or written.\n\
13680 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13681 the memory to which it refers."));
13682 set_cmd_completer (c, expression_completer);
13684 add_info ("watchpoints", watchpoints_info, _("\
13685 Status of specified watchpoints (all watchpoints if no argument)."));
13687 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13688 respond to changes - contrary to the description. */
13689 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
13690 &can_use_hw_watchpoints, _("\
13691 Set debugger's willingness to use watchpoint hardware."), _("\
13692 Show debugger's willingness to use watchpoint hardware."), _("\
13693 If zero, gdb will not use hardware for new watchpoints, even if\n\
13694 such is available. (However, any hardware watchpoints that were\n\
13695 created before setting this to nonzero, will continue to use watchpoint\n\
13698 show_can_use_hw_watchpoints,
13699 &setlist, &showlist);
13701 can_use_hw_watchpoints = 1;
13703 /* Tracepoint manipulation commands. */
13705 c = add_com ("trace", class_breakpoint, trace_command, _("\
13706 Set a tracepoint at specified line or function.\n\
13708 BREAK_ARGS_HELP ("trace") "\n\
13709 Do \"help tracepoints\" for info on other tracepoint commands."));
13710 set_cmd_completer (c, location_completer);
13712 add_com_alias ("tp", "trace", class_alias, 0);
13713 add_com_alias ("tr", "trace", class_alias, 1);
13714 add_com_alias ("tra", "trace", class_alias, 1);
13715 add_com_alias ("trac", "trace", class_alias, 1);
13717 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
13718 Set a fast tracepoint at specified line or function.\n\
13720 BREAK_ARGS_HELP ("ftrace") "\n\
13721 Do \"help tracepoints\" for info on other tracepoint commands."));
13722 set_cmd_completer (c, location_completer);
13724 c = add_com ("strace", class_breakpoint, strace_command, _("\
13725 Set a static tracepoint at specified line, function or marker.\n\
13727 strace [LOCATION] [if CONDITION]\n\
13728 LOCATION may be a line number, function name, \"*\" and an address,\n\
13729 or -m MARKER_ID.\n\
13730 If a line number is specified, probe the marker at start of code\n\
13731 for that line. If a function is specified, probe the marker at start\n\
13732 of code for that function. If an address is specified, probe the marker\n\
13733 at that exact address. If a marker id is specified, probe the marker\n\
13734 with that name. With no LOCATION, uses current execution address of\n\
13735 the selected stack frame.\n\
13736 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13737 This collects arbitrary user data passed in the probe point call to the\n\
13738 tracing library. You can inspect it when analyzing the trace buffer,\n\
13739 by printing the $_sdata variable like any other convenience variable.\n\
13741 CONDITION is a boolean expression.\n\
13743 Multiple tracepoints at one place are permitted, and useful if their\n\
13744 conditions are different.\n\
13746 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13747 Do \"help tracepoints\" for info on other tracepoint commands."));
13748 set_cmd_completer (c, location_completer);
13750 add_info ("tracepoints", tracepoints_info, _("\
13751 Status of specified tracepoints (all tracepoints if no argument).\n\
13752 Convenience variable \"$tpnum\" contains the number of the\n\
13753 last tracepoint set."));
13755 add_info_alias ("tp", "tracepoints", 1);
13757 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
13758 Delete specified tracepoints.\n\
13759 Arguments are tracepoint numbers, separated by spaces.\n\
13760 No argument means delete all tracepoints."),
13763 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
13764 Disable specified tracepoints.\n\
13765 Arguments are tracepoint numbers, separated by spaces.\n\
13766 No argument means disable all tracepoints."),
13768 deprecate_cmd (c, "disable");
13770 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
13771 Enable specified tracepoints.\n\
13772 Arguments are tracepoint numbers, separated by spaces.\n\
13773 No argument means enable all tracepoints."),
13775 deprecate_cmd (c, "enable");
13777 add_com ("passcount", class_trace, trace_pass_command, _("\
13778 Set the passcount for a tracepoint.\n\
13779 The trace will end when the tracepoint has been passed 'count' times.\n\
13780 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13781 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13783 add_prefix_cmd ("save", class_breakpoint, save_command,
13784 _("Save breakpoint definitions as a script."),
13785 &save_cmdlist, "save ",
13786 0/*allow-unknown*/, &cmdlist);
13788 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
13789 Save current breakpoint definitions as a script.\n\
13790 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13791 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13792 session to restore them."),
13794 set_cmd_completer (c, filename_completer);
13796 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
13797 Save current tracepoint definitions as a script.\n\
13798 Use the 'source' command in another debug session to restore them."),
13800 set_cmd_completer (c, filename_completer);
13802 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
13803 deprecate_cmd (c, "save tracepoints");
13805 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
13806 Breakpoint specific settings\n\
13807 Configure various breakpoint-specific variables such as\n\
13808 pending breakpoint behavior"),
13809 &breakpoint_set_cmdlist, "set breakpoint ",
13810 0/*allow-unknown*/, &setlist);
13811 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
13812 Breakpoint specific settings\n\
13813 Configure various breakpoint-specific variables such as\n\
13814 pending breakpoint behavior"),
13815 &breakpoint_show_cmdlist, "show breakpoint ",
13816 0/*allow-unknown*/, &showlist);
13818 add_setshow_auto_boolean_cmd ("pending", no_class,
13819 &pending_break_support, _("\
13820 Set debugger's behavior regarding pending breakpoints."), _("\
13821 Show debugger's behavior regarding pending breakpoints."), _("\
13822 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13823 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13824 an error. If auto, an unrecognized breakpoint location results in a\n\
13825 user-query to see if a pending breakpoint should be created."),
13827 show_pending_break_support,
13828 &breakpoint_set_cmdlist,
13829 &breakpoint_show_cmdlist);
13831 pending_break_support = AUTO_BOOLEAN_AUTO;
13833 add_setshow_boolean_cmd ("auto-hw", no_class,
13834 &automatic_hardware_breakpoints, _("\
13835 Set automatic usage of hardware breakpoints."), _("\
13836 Show automatic usage of hardware breakpoints."), _("\
13837 If set, the debugger will automatically use hardware breakpoints for\n\
13838 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13839 a warning will be emitted for such breakpoints."),
13841 show_automatic_hardware_breakpoints,
13842 &breakpoint_set_cmdlist,
13843 &breakpoint_show_cmdlist);
13845 add_setshow_enum_cmd ("always-inserted", class_support,
13846 always_inserted_enums, &always_inserted_mode, _("\
13847 Set mode for inserting breakpoints."), _("\
13848 Show mode for inserting breakpoints."), _("\
13849 When this mode is off, breakpoints are inserted in inferior when it is\n\
13850 resumed, and removed when execution stops. When this mode is on,\n\
13851 breakpoints are inserted immediately and removed only when the user\n\
13852 deletes the breakpoint. When this mode is auto (which is the default),\n\
13853 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13854 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13855 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13856 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13858 &show_always_inserted_mode,
13859 &breakpoint_set_cmdlist,
13860 &breakpoint_show_cmdlist);
13862 add_com ("break-range", class_breakpoint, break_range_command, _("\
13863 Set a breakpoint for an address range.\n\
13864 break-range START-LOCATION, END-LOCATION\n\
13865 where START-LOCATION and END-LOCATION can be one of the following:\n\
13866 LINENUM, for that line in the current file,\n\
13867 FILE:LINENUM, for that line in that file,\n\
13868 +OFFSET, for that number of lines after the current line\n\
13869 or the start of the range\n\
13870 FUNCTION, for the first line in that function,\n\
13871 FILE:FUNCTION, to distinguish among like-named static functions.\n\
13872 *ADDRESS, for the instruction at that address.\n\
13874 The breakpoint will stop execution of the inferior whenever it executes\n\
13875 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
13876 range (including START-LOCATION and END-LOCATION)."));
13878 automatic_hardware_breakpoints = 1;
13880 observer_attach_about_to_proceed (breakpoint_about_to_proceed);