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 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"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
64 #include "parser-defs.h"
66 /* readline include files */
67 #include "readline/readline.h"
68 #include "readline/history.h"
70 /* readline defines this. */
73 #include "mi/mi-common.h"
75 /* Arguments to pass as context to some catch command handlers. */
76 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
77 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
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 clear_command (char *, int);
99 static void catch_command (char *, int);
101 static int can_use_hardware_watchpoint (struct value
*);
103 static void break_command_1 (char *, int, int);
105 static void mention (struct breakpoint
*);
107 /* This function is used in gdbtk sources and thus can not be made static. */
108 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
109 struct symtab_and_line
,
112 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
114 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
118 static void describe_other_breakpoints (struct gdbarch
*,
119 struct program_space
*, CORE_ADDR
,
120 struct obj_section
*, int);
122 static int breakpoint_address_match (struct address_space
*aspace1
,
124 struct address_space
*aspace2
,
127 static int watchpoint_locations_match (struct bp_location
*loc1
,
128 struct bp_location
*loc2
);
130 static void breakpoints_info (char *, int);
132 static void watchpoints_info (char *, int);
134 static int breakpoint_1 (int, int, int (*) (const struct breakpoint
*));
136 static int breakpoint_cond_eval (void *);
138 static void cleanup_executing_breakpoints (void *);
140 static void commands_command (char *, int);
142 static void condition_command (char *, int);
144 static int get_number_trailer (char **, int);
153 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
154 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
156 static enum print_stop_action
print_it_typical (bpstat
);
158 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
160 static int watchpoint_check (void *);
162 static void maintenance_info_breakpoints (char *, int);
164 static int hw_breakpoint_used_count (void);
166 static int hw_watchpoint_used_count (enum bptype
, int *);
168 static void hbreak_command (char *, int);
170 static void thbreak_command (char *, int);
172 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
174 static void stop_command (char *arg
, int from_tty
);
176 static void stopin_command (char *arg
, int from_tty
);
178 static void stopat_command (char *arg
, int from_tty
);
180 static char *ep_parse_optional_if_clause (char **arg
);
182 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
183 char *arg
, int tempflag
, int from_tty
);
185 static void tcatch_command (char *arg
, int from_tty
);
187 static void ep_skip_leading_whitespace (char **s
);
189 static void detach_single_step_breakpoints (void);
191 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
194 static void free_bp_location (struct bp_location
*loc
);
195 static void incref_bp_location (struct bp_location
*loc
);
196 static void decref_bp_location (struct bp_location
**loc
);
198 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
200 static void update_global_location_list (int);
202 static void update_global_location_list_nothrow (int);
204 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
206 static int is_watchpoint (const struct breakpoint
*bpt
);
208 static void insert_breakpoint_locations (void);
210 static int syscall_catchpoint_p (struct breakpoint
*b
);
212 static void tracepoints_info (char *, int);
214 static void delete_trace_command (char *, int);
216 static void enable_trace_command (char *, int);
218 static void disable_trace_command (char *, int);
220 static void trace_pass_command (char *, int);
222 /* Assuming we're creating a static tracepoint, does S look like a
223 static tracepoint marker spec ("-m MARKER_ID")? */
224 #define is_marker_spec(s) \
225 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
227 /* A reference-counted struct command_line. This lets multiple
228 breakpoints share a single command list. */
229 struct counted_command_line
231 /* The reference count. */
234 /* The command list. */
235 struct command_line
*commands
;
238 struct command_line
*
239 breakpoint_commands (struct breakpoint
*b
)
241 return b
->commands
? b
->commands
->commands
: NULL
;
244 /* Flag indicating that a command has proceeded the inferior past the
245 current breakpoint. */
247 static int breakpoint_proceeded
;
250 bpdisp_text (enum bpdisp disp
)
252 /* NOTE: the following values are a part of MI protocol and represent
253 values of 'disp' field returned when inferior stops at a breakpoint. */
254 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
256 return bpdisps
[(int) disp
];
259 /* Prototypes for exported functions. */
260 /* If FALSE, gdb will not use hardware support for watchpoints, even
261 if such is available. */
262 static int can_use_hw_watchpoints
;
265 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
266 struct cmd_list_element
*c
,
269 fprintf_filtered (file
, _("\
270 Debugger's willingness to use watchpoint hardware is %s.\n"),
274 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
275 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
276 for unrecognized breakpoint locations.
277 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
278 static enum auto_boolean pending_break_support
;
280 show_pending_break_support (struct ui_file
*file
, int from_tty
,
281 struct cmd_list_element
*c
,
284 fprintf_filtered (file
, _("\
285 Debugger's behavior regarding pending breakpoints is %s.\n"),
289 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
290 set with "break" but falling in read-only memory.
291 If 0, gdb will warn about such breakpoints, but won't automatically
292 use hardware breakpoints. */
293 static int automatic_hardware_breakpoints
;
295 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
296 struct cmd_list_element
*c
,
299 fprintf_filtered (file
, _("\
300 Automatic usage of hardware breakpoints is %s.\n"),
304 /* If on, gdb will keep breakpoints inserted even as inferior is
305 stopped, and immediately insert any new breakpoints. If off, gdb
306 will insert breakpoints into inferior only when resuming it, and
307 will remove breakpoints upon stop. If auto, GDB will behave as ON
308 if in non-stop mode, and as OFF if all-stop mode.*/
310 static const char always_inserted_auto
[] = "auto";
311 static const char always_inserted_on
[] = "on";
312 static const char always_inserted_off
[] = "off";
313 static const char *always_inserted_enums
[] = {
314 always_inserted_auto
,
319 static const char *always_inserted_mode
= always_inserted_auto
;
321 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
322 struct cmd_list_element
*c
, const char *value
)
324 if (always_inserted_mode
== always_inserted_auto
)
325 fprintf_filtered (file
, _("\
326 Always inserted breakpoint mode is %s (currently %s).\n"),
328 breakpoints_always_inserted_mode () ? "on" : "off");
330 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
334 breakpoints_always_inserted_mode (void)
336 return (always_inserted_mode
== always_inserted_on
337 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
340 void _initialize_breakpoint (void);
342 /* Are we executing breakpoint commands? */
343 static int executing_breakpoint_commands
;
345 /* Are overlay event breakpoints enabled? */
346 static int overlay_events_enabled
;
348 /* Walk the following statement or block through all breakpoints.
349 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
352 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
354 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
355 for (B = breakpoint_chain; \
356 B ? (TMP=B->next, 1): 0; \
359 /* Similar iterator for the low-level breakpoints. SAFE variant is not
360 provided so update_global_location_list must not be called while executing
361 the block of ALL_BP_LOCATIONS. */
363 #define ALL_BP_LOCATIONS(B,BP_TMP) \
364 for (BP_TMP = bp_location; \
365 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
368 /* Iterator for tracepoints only. */
370 #define ALL_TRACEPOINTS(B) \
371 for (B = breakpoint_chain; B; B = B->next) \
372 if (is_tracepoint (B))
374 /* Chains of all breakpoints defined. */
376 struct breakpoint
*breakpoint_chain
;
378 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
380 static struct bp_location
**bp_location
;
382 /* Number of elements of BP_LOCATION. */
384 static unsigned bp_location_count
;
386 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
387 for the current elements of BP_LOCATION which get a valid result from
388 bp_location_has_shadow. You can use it for roughly limiting the subrange of
389 BP_LOCATION to scan for shadow bytes for an address you need to read. */
391 static CORE_ADDR bp_location_placed_address_before_address_max
;
393 /* Maximum offset plus alignment between
394 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
395 the current elements of BP_LOCATION which get a valid result from
396 bp_location_has_shadow. You can use it for roughly limiting the subrange of
397 BP_LOCATION to scan for shadow bytes for an address you need to read. */
399 static CORE_ADDR bp_location_shadow_len_after_address_max
;
401 /* The locations that no longer correspond to any breakpoint,
402 unlinked from bp_location array, but for which a hit
403 may still be reported by a target. */
404 VEC(bp_location_p
) *moribund_locations
= NULL
;
406 /* Number of last breakpoint made. */
408 static int breakpoint_count
;
410 /* The value of `breakpoint_count' before the last command that
411 created breakpoints. If the last (break-like) command created more
412 than one breakpoint, then the difference between BREAKPOINT_COUNT
413 and PREV_BREAKPOINT_COUNT is more than one. */
414 static int prev_breakpoint_count
;
416 /* Number of last tracepoint made. */
418 static int tracepoint_count
;
420 static struct cmd_list_element
*breakpoint_set_cmdlist
;
421 static struct cmd_list_element
*breakpoint_show_cmdlist
;
422 struct cmd_list_element
*save_cmdlist
;
424 /* Return whether a breakpoint is an active enabled breakpoint. */
426 breakpoint_enabled (struct breakpoint
*b
)
428 return (b
->enable_state
== bp_enabled
);
431 /* Set breakpoint count to NUM. */
434 set_breakpoint_count (int num
)
436 prev_breakpoint_count
= breakpoint_count
;
437 breakpoint_count
= num
;
438 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
441 /* Used by `start_rbreak_breakpoints' below, to record the current
442 breakpoint count before "rbreak" creates any breakpoint. */
443 static int rbreak_start_breakpoint_count
;
445 /* Called at the start an "rbreak" command to record the first
449 start_rbreak_breakpoints (void)
451 rbreak_start_breakpoint_count
= breakpoint_count
;
454 /* Called at the end of an "rbreak" command to record the last
458 end_rbreak_breakpoints (void)
460 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
463 /* Used in run_command to zero the hit count when a new run starts. */
466 clear_breakpoint_hit_counts (void)
468 struct breakpoint
*b
;
474 /* Allocate a new counted_command_line with reference count of 1.
475 The new structure owns COMMANDS. */
477 static struct counted_command_line
*
478 alloc_counted_command_line (struct command_line
*commands
)
480 struct counted_command_line
*result
481 = xmalloc (sizeof (struct counted_command_line
));
484 result
->commands
= commands
;
488 /* Increment reference count. This does nothing if CMD is NULL. */
491 incref_counted_command_line (struct counted_command_line
*cmd
)
497 /* Decrement reference count. If the reference count reaches 0,
498 destroy the counted_command_line. Sets *CMDP to NULL. This does
499 nothing if *CMDP is NULL. */
502 decref_counted_command_line (struct counted_command_line
**cmdp
)
506 if (--(*cmdp
)->refc
== 0)
508 free_command_lines (&(*cmdp
)->commands
);
515 /* A cleanup function that calls decref_counted_command_line. */
518 do_cleanup_counted_command_line (void *arg
)
520 decref_counted_command_line (arg
);
523 /* Create a cleanup that calls decref_counted_command_line on the
526 static struct cleanup
*
527 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
529 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
532 /* Default address, symtab and line to put a breakpoint at
533 for "break" command with no arg.
534 if default_breakpoint_valid is zero, the other three are
535 not valid, and "break" with no arg is an error.
537 This set by print_stack_frame, which calls set_default_breakpoint. */
539 int default_breakpoint_valid
;
540 CORE_ADDR default_breakpoint_address
;
541 struct symtab
*default_breakpoint_symtab
;
542 int default_breakpoint_line
;
543 struct program_space
*default_breakpoint_pspace
;
546 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
547 Advance *PP after the string and any trailing whitespace.
549 Currently the string can either be a number or "$" followed by the name
550 of a convenience variable. Making it an expression wouldn't work well
551 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
553 If the string is a NULL pointer, that denotes the last breakpoint.
555 TRAILER is a character which can be found after the number; most
556 commonly this is `-'. If you don't want a trailer, use \0. */
558 get_number_trailer (char **pp
, int trailer
)
560 int retval
= 0; /* default */
564 /* Empty line means refer to the last breakpoint. */
565 return breakpoint_count
;
568 /* Make a copy of the name, so we can null-terminate it
569 to pass to lookup_internalvar(). */
574 while (isalnum (*p
) || *p
== '_')
576 varname
= (char *) alloca (p
- start
+ 1);
577 strncpy (varname
, start
, p
- start
);
578 varname
[p
- start
] = '\0';
579 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
583 printf_filtered (_("Convenience variable must have integer value.\n"));
591 while (*p
>= '0' && *p
<= '9')
594 /* There is no number here. (e.g. "cond a == b"). */
596 /* Skip non-numeric token */
597 while (*p
&& !isspace((int) *p
))
599 /* Return zero, which caller must interpret as error. */
605 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
607 /* Trailing junk: return 0 and let caller print error msg. */
608 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
619 /* Like get_number_trailer, but don't allow a trailer. */
621 get_number (char **pp
)
623 return get_number_trailer (pp
, '\0');
626 /* Parse a number or a range.
627 * A number will be of the form handled by get_number.
628 * A range will be of the form <number1> - <number2>, and
629 * will represent all the integers between number1 and number2,
632 * While processing a range, this fuction is called iteratively;
633 * At each call it will return the next value in the range.
635 * At the beginning of parsing a range, the char pointer PP will
636 * be advanced past <number1> and left pointing at the '-' token.
637 * Subsequent calls will not advance the pointer until the range
638 * is completed. The call that completes the range will advance
639 * pointer PP past <number2>.
643 get_number_or_range (char **pp
)
645 static int last_retval
, end_value
;
646 static char *end_ptr
;
647 static int in_range
= 0;
651 /* Default case: pp is pointing either to a solo number,
652 or to the first number of a range. */
653 last_retval
= get_number_trailer (pp
, '-');
658 /* This is the start of a range (<number1> - <number2>).
659 Skip the '-', parse and remember the second number,
660 and also remember the end of the final token. */
664 while (isspace ((int) *end_ptr
))
665 end_ptr
++; /* skip white space */
666 end_value
= get_number (temp
);
667 if (end_value
< last_retval
)
669 error (_("inverted range"));
671 else if (end_value
== last_retval
)
673 /* degenerate range (number1 == number2). Advance the
674 token pointer so that the range will be treated as a
683 error (_("negative value"));
686 /* pp points to the '-' that betokens a range. All
687 number-parsing has already been done. Return the next
688 integer value (one greater than the saved previous value).
689 Do not advance the token pointer 'pp' until the end of range
692 if (++last_retval
== end_value
)
694 /* End of range reached; advance token pointer. */
702 /* Return the breakpoint with the specified number, or NULL
703 if the number does not refer to an existing breakpoint. */
706 get_breakpoint (int num
)
708 struct breakpoint
*b
;
711 if (b
->number
== num
)
720 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
723 struct bp_location
*loc
= b
->loc
;
725 for (; loc
; loc
= loc
->next
)
730 xfree (b
->cond_string
);
731 b
->cond_string
= NULL
;
738 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
744 /* I don't know if it matters whether this is the string the user
745 typed in or the decompiled expression. */
746 b
->cond_string
= xstrdup (arg
);
747 b
->condition_not_parsed
= 0;
749 if (is_watchpoint (b
))
751 innermost_block
= NULL
;
753 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
755 error (_("Junk at end of expression"));
756 b
->cond_exp_valid_block
= innermost_block
;
760 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
764 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
766 error (_("Junk at end of expression"));
770 breakpoints_changed ();
771 observer_notify_breakpoint_modified (b
->number
);
774 /* condition N EXP -- set break condition of breakpoint N to EXP. */
777 condition_command (char *arg
, int from_tty
)
779 struct breakpoint
*b
;
784 error_no_arg (_("breakpoint number"));
787 bnum
= get_number (&p
);
789 error (_("Bad breakpoint argument: '%s'"), arg
);
792 if (b
->number
== bnum
)
794 set_breakpoint_condition (b
, p
, from_tty
);
798 error (_("No breakpoint number %d."), bnum
);
801 /* Check that COMMAND do not contain commands that are suitable
802 only for tracepoints and not suitable for ordinary breakpoints.
803 Throw if any such commands is found.
806 check_no_tracepoint_commands (struct command_line
*commands
)
808 struct command_line
*c
;
810 for (c
= commands
; c
; c
= c
->next
)
814 if (c
->control_type
== while_stepping_control
)
815 error (_("The 'while-stepping' command can only be used for tracepoints"));
817 for (i
= 0; i
< c
->body_count
; ++i
)
818 check_no_tracepoint_commands ((c
->body_list
)[i
]);
820 /* Not that command parsing removes leading whitespace and comment
821 lines and also empty lines. So, we only need to check for
823 if (strstr (c
->line
, "collect ") == c
->line
)
824 error (_("The 'collect' command can only be used for tracepoints"));
826 if (strstr (c
->line
, "teval ") == c
->line
)
827 error (_("The 'teval' command can only be used for tracepoints"));
831 /* Encapsulate tests for different types of tracepoints. */
834 is_tracepoint (const struct breakpoint
*b
)
836 return (b
->type
== bp_tracepoint
837 || b
->type
== bp_fast_tracepoint
838 || b
->type
== bp_static_tracepoint
);
841 /* A helper function that validsates that COMMANDS are valid for a
842 breakpoint. This function will throw an exception if a problem is
846 validate_commands_for_breakpoint (struct breakpoint
*b
,
847 struct command_line
*commands
)
849 if (is_tracepoint (b
))
851 /* We need to verify that each top-level element of commands
852 is valid for tracepoints, that there's at most one while-stepping
853 element, and that while-stepping's body has valid tracing commands
854 excluding nested while-stepping. */
855 struct command_line
*c
;
856 struct command_line
*while_stepping
= 0;
857 for (c
= commands
; c
; c
= c
->next
)
859 if (c
->control_type
== while_stepping_control
)
861 if (b
->type
== bp_fast_tracepoint
)
863 The 'while-stepping' command cannot be used for fast tracepoint"));
864 else if (b
->type
== bp_static_tracepoint
)
866 The 'while-stepping' command cannot be used for static tracepoint"));
869 error (_("The 'while-stepping' command can be used only once"));
876 struct command_line
*c2
;
878 gdb_assert (while_stepping
->body_count
== 1);
879 c2
= while_stepping
->body_list
[0];
880 for (; c2
; c2
= c2
->next
)
882 if (c2
->control_type
== while_stepping_control
)
883 error (_("The 'while-stepping' command cannot be nested"));
889 check_no_tracepoint_commands (commands
);
893 /* Return a vector of all the static tracepoints set at ADDR. The
894 caller is responsible for releasing the vector. */
897 static_tracepoints_here (CORE_ADDR addr
)
899 struct breakpoint
*b
;
900 VEC(breakpoint_p
) *found
= 0;
901 struct bp_location
*loc
;
904 if (b
->type
== bp_static_tracepoint
)
906 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
907 if (loc
->address
== addr
)
908 VEC_safe_push(breakpoint_p
, found
, b
);
914 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
915 validate that only allowed commands are included.
919 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
921 validate_commands_for_breakpoint (b
, commands
);
923 decref_counted_command_line (&b
->commands
);
924 b
->commands
= alloc_counted_command_line (commands
);
925 breakpoints_changed ();
926 observer_notify_breakpoint_modified (b
->number
);
930 check_tracepoint_command (char *line
, void *closure
)
932 struct breakpoint
*b
= closure
;
934 validate_actionline (&line
, b
);
937 /* A structure used to pass information through
938 map_breakpoint_numbers. */
942 /* True if the command was typed at a tty. */
945 /* The breakpoint range spec. */
948 /* Non-NULL if the body of the commands are being read from this
949 already-parsed command. */
950 struct command_line
*control
;
952 /* The command lines read from the user, or NULL if they have not
954 struct counted_command_line
*cmd
;
957 /* A callback for map_breakpoint_numbers that sets the commands for
961 do_map_commands_command (struct breakpoint
*b
, void *data
)
963 struct commands_info
*info
= data
;
965 if (info
->cmd
== NULL
)
967 struct command_line
*l
;
969 if (info
->control
!= NULL
)
970 l
= copy_command_lines (info
->control
->body_list
[0]);
973 struct cleanup
*old_chain
;
976 str
= xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
979 old_chain
= make_cleanup (xfree
, str
);
981 l
= read_command_lines (str
,
984 ? check_tracepoint_command
: 0),
987 do_cleanups (old_chain
);
990 info
->cmd
= alloc_counted_command_line (l
);
993 /* If a breakpoint was on the list more than once, we don't need to
995 if (b
->commands
!= info
->cmd
)
997 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
998 incref_counted_command_line (info
->cmd
);
999 decref_counted_command_line (&b
->commands
);
1000 b
->commands
= info
->cmd
;
1001 breakpoints_changed ();
1002 observer_notify_breakpoint_modified (b
->number
);
1007 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
1009 struct cleanup
*cleanups
;
1010 struct commands_info info
;
1012 info
.from_tty
= from_tty
;
1013 info
.control
= control
;
1015 /* If we read command lines from the user, then `info' will hold an
1016 extra reference to the commands that we must clean up. */
1017 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1019 if (arg
== NULL
|| !*arg
)
1021 if (breakpoint_count
- prev_breakpoint_count
> 1)
1022 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1, breakpoint_count
);
1023 else if (breakpoint_count
> 0)
1024 arg
= xstrprintf ("%d", breakpoint_count
);
1027 /* So that we don't try to free the incoming non-NULL
1028 argument in the cleanup below. Mapping breakpoint
1029 numbers will fail in this case. */
1034 /* The command loop has some static state, so we need to preserve
1036 arg
= xstrdup (arg
);
1039 make_cleanup (xfree
, arg
);
1043 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1045 if (info
.cmd
== NULL
)
1046 error (_("No breakpoints specified."));
1048 do_cleanups (cleanups
);
1052 commands_command (char *arg
, int from_tty
)
1054 commands_command_1 (arg
, from_tty
, NULL
);
1057 /* Like commands_command, but instead of reading the commands from
1058 input stream, takes them from an already parsed command structure.
1060 This is used by cli-script.c to DTRT with breakpoint commands
1061 that are part of if and while bodies. */
1062 enum command_control_type
1063 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1065 commands_command_1 (arg
, 0, cmd
);
1066 return simple_control
;
1069 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1072 bp_location_has_shadow (struct bp_location
*bl
)
1074 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1078 if (bl
->target_info
.shadow_len
== 0)
1079 /* bp isn't valid, or doesn't shadow memory. */
1084 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1085 by replacing any memory breakpoints with their shadowed contents.
1087 The range of shadowed area by each bp_location is:
1088 bl->address - bp_location_placed_address_before_address_max
1089 up to bl->address + bp_location_shadow_len_after_address_max
1090 The range we were requested to resolve shadows for is:
1091 memaddr ... memaddr + len
1092 Thus the safe cutoff boundaries for performance optimization are
1093 memaddr + len <= (bl->address
1094 - bp_location_placed_address_before_address_max)
1096 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1099 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1101 /* Left boundary, right boundary and median element of our binary search. */
1102 unsigned bc_l
, bc_r
, bc
;
1104 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1105 safe to report lower value but a failure to report higher one. */
1108 bc_r
= bp_location_count
;
1109 while (bc_l
+ 1 < bc_r
)
1111 struct bp_location
*bl
;
1113 bc
= (bc_l
+ bc_r
) / 2;
1114 bl
= bp_location
[bc
];
1116 /* Check first BL->ADDRESS will not overflow due to the added constant.
1117 Then advance the left boundary only if we are sure the BC element can
1118 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1120 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1121 we cannot miss a breakpoint with its shadow range tail still reaching
1124 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1126 && (bl
->address
+ bp_location_shadow_len_after_address_max
1133 /* Due to the binary search above, we need to make sure we pick the
1134 first location that's at BC_L's address. E.g., if there are
1135 multiple locations at the same address, BC_L may end up pointing
1136 at a duplicate location, and miss the "master"/"inserted"
1137 location. Say, given locations L1, L2 and L3 at addresses A and
1140 L1@A, L2@A, L3@B, ...
1142 BC_L could end up pointing at location L2, while the "master"
1143 location could be L1. Since the `loc->inserted' flag is only set
1144 on "master" locations, we'd forget to restore the shadow of L1
1147 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1150 /* Now do full processing of the found relevant range of elements. */
1152 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1154 struct bp_location
*bl
= bp_location
[bc
];
1155 CORE_ADDR bp_addr
= 0;
1159 /* bp_location array has BL->OWNER always non-NULL. */
1160 if (bl
->owner
->type
== bp_none
)
1161 warning (_("reading through apparently deleted breakpoint #%d?"),
1164 /* Performance optimization: any futher element can no longer affect BUF
1167 if (bl
->address
>= bp_location_placed_address_before_address_max
1168 && memaddr
+ len
<= (bl
->address
1169 - bp_location_placed_address_before_address_max
))
1172 if (!bp_location_has_shadow (bl
))
1174 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1175 current_program_space
->aspace
, 0))
1178 /* Addresses and length of the part of the breakpoint that
1180 bp_addr
= bl
->target_info
.placed_address
;
1181 bp_size
= bl
->target_info
.shadow_len
;
1183 if (bp_addr
+ bp_size
<= memaddr
)
1184 /* The breakpoint is entirely before the chunk of memory we
1188 if (bp_addr
>= memaddr
+ len
)
1189 /* The breakpoint is entirely after the chunk of memory we are
1193 /* Offset within shadow_contents. */
1194 if (bp_addr
< memaddr
)
1196 /* Only copy the second part of the breakpoint. */
1197 bp_size
-= memaddr
- bp_addr
;
1198 bptoffset
= memaddr
- bp_addr
;
1202 if (bp_addr
+ bp_size
> memaddr
+ len
)
1204 /* Only copy the first part of the breakpoint. */
1205 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1208 memcpy (buf
+ bp_addr
- memaddr
,
1209 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1214 /* A wrapper function for inserting catchpoints. */
1216 insert_catchpoint (struct ui_out
*uo
, void *args
)
1218 struct breakpoint
*b
= (struct breakpoint
*) args
;
1220 gdb_assert (b
->type
== bp_catchpoint
);
1221 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1226 /* Return true if BPT is of any hardware watchpoint kind. */
1229 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1231 return (bpt
->type
== bp_hardware_watchpoint
1232 || bpt
->type
== bp_read_watchpoint
1233 || bpt
->type
== bp_access_watchpoint
);
1236 /* Return true if BPT is of any watchpoint kind, hardware or
1240 is_watchpoint (const struct breakpoint
*bpt
)
1242 return (is_hardware_watchpoint (bpt
)
1243 || bpt
->type
== bp_watchpoint
);
1246 /* Assuming that B is a watchpoint: returns true if the current thread
1247 and its running state are safe to evaluate or update watchpoint B.
1248 Watchpoints on local expressions need to be evaluated in the
1249 context of the thread that was current when the watchpoint was
1250 created, and, that thread needs to be stopped to be able to select
1251 the correct frame context. Watchpoints on global expressions can
1252 be evaluated on any thread, and in any state. It is presently left
1253 to the target allowing memory accesses when threads are
1257 watchpoint_in_thread_scope (struct breakpoint
*b
)
1259 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1260 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1261 && !is_executing (inferior_ptid
)));
1264 /* Assuming that B is a watchpoint:
1265 - Reparse watchpoint expression, if REPARSE is non-zero
1266 - Evaluate expression and store the result in B->val
1267 - Evaluate the condition if there is one, and store the result
1269 - Update the list of values that must be watched in B->loc.
1271 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1272 If this is local watchpoint that is out of scope, delete it.
1274 Even with `set breakpoint always-inserted on' the watchpoints are removed
1275 + inserted on each stop here. Normal breakpoints must never be removed
1276 because they might be missed by a running thread when debugging in non-stop
1277 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1278 processed here) are specific to each LWP since they are stored in each LWP's
1279 hardware debug registers. Therefore, such LWP must be stopped first in
1280 order to be able to modify its hardware watchpoints.
1282 Hardware watchpoints must be reset exactly once after being presented to the
1283 user. It cannot be done sooner, because it would reset the data used to
1284 present the watchpoint hit to the user. And it must not be done later
1285 because it could display the same single watchpoint hit during multiple GDB
1286 stops. Note that the latter is relevant only to the hardware watchpoint
1287 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1288 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1289 memory content has not changed.
1291 The following constraints influence the location where we can reset hardware
1294 * target_stopped_by_watchpoint and target_stopped_data_address are called
1295 several times when GDB stops.
1298 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1299 stop. GDB only presents one hardware watchpoint hit at a time as the
1300 reason for stopping, and all the other hits are presented later, one after
1301 the other, each time the user requests the execution to be resumed.
1302 Execution is not resumed for the threads still having pending hit event
1303 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1304 the inferior on the first stop the thread hit event is kept being reported
1305 from its cached value by linux_nat_stopped_data_address until the real
1306 thread resume happens after the watchpoint gets presented and thus its
1307 LWP_INFO->STATUS gets reset.
1309 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1310 removal from inferior. */
1313 update_watchpoint (struct breakpoint
*b
, int reparse
)
1315 int within_current_scope
;
1316 struct frame_id saved_frame_id
;
1319 /* If this is a local watchpoint, we only want to check if the
1320 watchpoint frame is in scope if the current thread is the thread
1321 that was used to create the watchpoint. */
1322 if (!watchpoint_in_thread_scope (b
))
1325 /* We don't free locations. They are stored in bp_location array and
1326 update_global_locations will eventually delete them and remove
1327 breakpoints if needed. */
1330 if (b
->disposition
== disp_del_at_next_stop
)
1335 /* Determine if the watchpoint is within scope. */
1336 if (b
->exp_valid_block
== NULL
)
1337 within_current_scope
= 1;
1340 struct frame_info
*fi
;
1342 /* Save the current frame's ID so we can restore it after
1343 evaluating the watchpoint expression on its own frame. */
1344 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1345 took a frame parameter, so that we didn't have to change the
1348 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1350 fi
= frame_find_by_id (b
->watchpoint_frame
);
1351 within_current_scope
= (fi
!= NULL
);
1352 if (within_current_scope
)
1356 if (within_current_scope
&& reparse
)
1365 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1366 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1367 /* If the meaning of expression itself changed, the old value is
1368 no longer relevant. We don't want to report a watchpoint hit
1369 to the user when the old value and the new value may actually
1370 be completely different objects. */
1371 value_free (b
->val
);
1375 /* Note that unlike with breakpoints, the watchpoint's condition
1376 expression is stored in the breakpoint object, not in the
1377 locations (re)created below. */
1378 if (b
->cond_string
!= NULL
)
1380 if (b
->cond_exp
!= NULL
)
1382 xfree (b
->cond_exp
);
1387 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1391 /* If we failed to parse the expression, for example because
1392 it refers to a global variable in a not-yet-loaded shared library,
1393 don't try to insert watchpoint. We don't automatically delete
1394 such watchpoint, though, since failure to parse expression
1395 is different from out-of-scope watchpoint. */
1396 if ( !target_has_execution
)
1398 /* Without execution, memory can't change. No use to try and
1399 set watchpoint locations. The watchpoint will be reset when
1400 the target gains execution, through breakpoint_re_set. */
1402 else if (within_current_scope
&& b
->exp
)
1405 struct value
*val_chain
, *v
, *result
, *next
;
1406 struct program_space
*frame_pspace
;
1408 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1410 /* Avoid setting b->val if it's already set. The meaning of
1411 b->val is 'the last value' user saw, and we should update
1412 it only if we reported that last value to user. As it
1413 happens, the code that reports it updates b->val directly. */
1420 /* Change the type of breakpoint between hardware assisted or an
1421 ordinary watchpoint depending on the hardware support and free
1422 hardware slots. REPARSE is set when the inferior is started. */
1423 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1426 int i
, mem_cnt
, other_type_used
;
1428 /* We need to determine how many resources are already used
1429 for all other hardware watchpoints to see if we still have
1430 enough resources to also fit this watchpoint in as well.
1431 To avoid the hw_watchpoint_used_count call below from counting
1432 this watchpoint, make sure that it is marked as a software
1434 b
->type
= bp_watchpoint
;
1435 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1437 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1440 b
->type
= bp_watchpoint
;
1443 int target_resources_ok
= target_can_use_hardware_watchpoint
1444 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1445 if (target_resources_ok
<= 0)
1446 b
->type
= bp_watchpoint
;
1448 b
->type
= bp_hardware_watchpoint
;
1452 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1454 /* Look at each value on the value chain. */
1455 for (v
= val_chain
; v
; v
= next
)
1457 /* If it's a memory location, and GDB actually needed
1458 its contents to evaluate the expression, then we
1459 must watch it. If the first value returned is
1460 still lazy, that means an error occurred reading it;
1461 watch it anyway in case it becomes readable. */
1462 if (VALUE_LVAL (v
) == lval_memory
1463 && (v
== val_chain
|| ! value_lazy (v
)))
1465 struct type
*vtype
= check_typedef (value_type (v
));
1467 /* We only watch structs and arrays if user asked
1468 for it explicitly, never if they just happen to
1469 appear in the middle of some value chain. */
1471 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1472 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1476 struct bp_location
*loc
, **tmp
;
1478 addr
= value_address (v
);
1479 len
= TYPE_LENGTH (value_type (v
));
1481 if (b
->type
== bp_read_watchpoint
)
1483 else if (b
->type
== bp_access_watchpoint
)
1486 loc
= allocate_bp_location (b
);
1487 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1490 loc
->gdbarch
= get_type_arch (value_type (v
));
1492 loc
->pspace
= frame_pspace
;
1493 loc
->address
= addr
;
1495 loc
->watchpoint_type
= type
;
1499 next
= value_next (v
);
1504 /* If a software watchpoint is not watching any memory, then the
1505 above left it without any location set up. But,
1506 bpstat_stop_status requires a location to be able to report
1507 stops, so make sure there's at least a dummy one. */
1508 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1510 b
->loc
= allocate_bp_location (b
);
1511 b
->loc
->pspace
= frame_pspace
;
1512 b
->loc
->address
= -1;
1513 b
->loc
->length
= -1;
1514 b
->loc
->watchpoint_type
= -1;
1517 else if (!within_current_scope
)
1519 printf_filtered (_("\
1520 Watchpoint %d deleted because the program has left the block\n\
1521 in which its expression is valid.\n"),
1523 if (b
->related_breakpoint
)
1525 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1526 b
->related_breakpoint
->related_breakpoint
= NULL
;
1527 b
->related_breakpoint
= NULL
;
1529 b
->disposition
= disp_del_at_next_stop
;
1532 /* Restore the selected frame. */
1534 select_frame (frame_find_by_id (saved_frame_id
));
1538 /* Returns 1 iff breakpoint location should be
1539 inserted in the inferior. */
1541 should_be_inserted (struct bp_location
*bl
)
1543 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1546 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1549 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1552 /* This is set for example, when we're attached to the parent of a
1553 vfork, and have detached from the child. The child is running
1554 free, and we expect it to do an exec or exit, at which point the
1555 OS makes the parent schedulable again (and the target reports
1556 that the vfork is done). Until the child is done with the shared
1557 memory region, do not insert breakpoints in the parent, otherwise
1558 the child could still trip on the parent's breakpoints. Since
1559 the parent is blocked anyway, it won't miss any breakpoint. */
1560 if (bl
->pspace
->breakpoints_not_allowed
)
1563 /* Tracepoints are inserted by the target at a time of its choosing,
1565 if (is_tracepoint (bl
->owner
))
1571 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1572 location. Any error messages are printed to TMP_ERROR_STREAM; and
1573 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1575 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1576 method for each breakpoint or catchpoint type. */
1578 insert_bp_location (struct bp_location
*bl
,
1579 struct ui_file
*tmp_error_stream
,
1580 int *disabled_breaks
,
1581 int *hw_breakpoint_error
)
1585 if (!should_be_inserted (bl
) || bl
->inserted
)
1588 /* Initialize the target-specific information. */
1589 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1590 bl
->target_info
.placed_address
= bl
->address
;
1591 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1593 if (bl
->loc_type
== bp_loc_software_breakpoint
1594 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1596 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1598 /* If the explicitly specified breakpoint type
1599 is not hardware breakpoint, check the memory map to see
1600 if the breakpoint address is in read only memory or not.
1601 Two important cases are:
1602 - location type is not hardware breakpoint, memory
1603 is readonly. We change the type of the location to
1604 hardware breakpoint.
1605 - location type is hardware breakpoint, memory is read-write.
1606 This means we've previously made the location hardware one, but
1607 then the memory map changed, so we undo.
1609 When breakpoints are removed, remove_breakpoints will
1610 use location types we've just set here, the only possible
1611 problem is that memory map has changed during running program,
1612 but it's not going to work anyway with current gdb. */
1613 struct mem_region
*mr
1614 = lookup_mem_region (bl
->target_info
.placed_address
);
1618 if (automatic_hardware_breakpoints
)
1620 enum bp_loc_type new_type
;
1622 if (mr
->attrib
.mode
!= MEM_RW
)
1623 new_type
= bp_loc_hardware_breakpoint
;
1625 new_type
= bp_loc_software_breakpoint
;
1627 if (new_type
!= bl
->loc_type
)
1629 static int said
= 0;
1631 bl
->loc_type
= new_type
;
1634 fprintf_filtered (gdb_stdout
, _("\
1635 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1640 else if (bl
->loc_type
== bp_loc_software_breakpoint
1641 && mr
->attrib
.mode
!= MEM_RW
)
1642 warning (_("cannot set software breakpoint at readonly address %s"),
1643 paddress (bl
->gdbarch
, bl
->address
));
1647 /* First check to see if we have to handle an overlay. */
1648 if (overlay_debugging
== ovly_off
1649 || bl
->section
== NULL
1650 || !(section_is_overlay (bl
->section
)))
1652 /* No overlay handling: just set the breakpoint. */
1654 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1655 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1658 val
= target_insert_breakpoint (bl
->gdbarch
,
1663 /* This breakpoint is in an overlay section.
1664 Shall we set a breakpoint at the LMA? */
1665 if (!overlay_events_enabled
)
1667 /* Yes -- overlay event support is not active,
1668 so we must try to set a breakpoint at the LMA.
1669 This will not work for a hardware breakpoint. */
1670 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1671 warning (_("hardware breakpoint %d not supported in overlay!"),
1675 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1677 /* Set a software (trap) breakpoint at the LMA. */
1678 bl
->overlay_target_info
= bl
->target_info
;
1679 bl
->overlay_target_info
.placed_address
= addr
;
1680 val
= target_insert_breakpoint (bl
->gdbarch
,
1681 &bl
->overlay_target_info
);
1683 fprintf_unfiltered (tmp_error_stream
,
1684 "Overlay breakpoint %d failed: in ROM?\n",
1688 /* Shall we set a breakpoint at the VMA? */
1689 if (section_is_mapped (bl
->section
))
1691 /* Yes. This overlay section is mapped into memory. */
1692 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1693 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1696 val
= target_insert_breakpoint (bl
->gdbarch
,
1701 /* No. This breakpoint will not be inserted.
1702 No error, but do not mark the bp as 'inserted'. */
1709 /* Can't set the breakpoint. */
1710 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1712 /* See also: disable_breakpoints_in_shlibs. */
1714 bl
->shlib_disabled
= 1;
1715 if (!*disabled_breaks
)
1717 fprintf_unfiltered (tmp_error_stream
,
1718 "Cannot insert breakpoint %d.\n",
1720 fprintf_unfiltered (tmp_error_stream
,
1721 "Temporarily disabling shared library breakpoints:\n");
1723 *disabled_breaks
= 1;
1724 fprintf_unfiltered (tmp_error_stream
,
1725 "breakpoint #%d\n", bl
->owner
->number
);
1729 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1731 *hw_breakpoint_error
= 1;
1732 fprintf_unfiltered (tmp_error_stream
,
1733 "Cannot insert hardware breakpoint %d.\n",
1738 fprintf_unfiltered (tmp_error_stream
,
1739 "Cannot insert breakpoint %d.\n",
1741 fprintf_filtered (tmp_error_stream
,
1742 "Error accessing memory address ");
1743 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1745 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1746 safe_strerror (val
));
1757 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1758 /* NOTE drow/2003-09-08: This state only exists for removing
1759 watchpoints. It's not clear that it's necessary... */
1760 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1762 val
= target_insert_watchpoint (bl
->address
,
1764 bl
->watchpoint_type
,
1765 bl
->owner
->cond_exp
);
1767 /* If trying to set a read-watchpoint, and it turns out it's not
1768 supported, try emulating one with an access watchpoint. */
1769 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1771 struct bp_location
*loc
, **loc_temp
;
1773 /* But don't try to insert it, if there's already another
1774 hw_access location that would be considered a duplicate
1776 ALL_BP_LOCATIONS (loc
, loc_temp
)
1778 && loc
->watchpoint_type
== hw_access
1779 && watchpoint_locations_match (bl
, loc
))
1783 bl
->target_info
= loc
->target_info
;
1784 bl
->watchpoint_type
= hw_access
;
1791 val
= target_insert_watchpoint (bl
->address
,
1794 bl
->owner
->cond_exp
);
1796 bl
->watchpoint_type
= hw_access
;
1800 bl
->inserted
= (val
== 0);
1803 else if (bl
->owner
->type
== bp_catchpoint
)
1805 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1806 bl
->owner
, RETURN_MASK_ERROR
);
1807 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1810 bl
->owner
->enable_state
= bp_disabled
;
1814 /* We've already printed an error message if there was a problem
1815 inserting this catchpoint, and we've disabled the catchpoint,
1816 so just return success. */
1823 /* This function is called when program space PSPACE is about to be
1824 deleted. It takes care of updating breakpoints to not reference
1828 breakpoint_program_space_exit (struct program_space
*pspace
)
1830 struct breakpoint
*b
, *b_temp
;
1831 struct bp_location
*loc
, **loc_temp
;
1833 /* Remove any breakpoint that was set through this program space. */
1834 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1836 if (b
->pspace
== pspace
)
1837 delete_breakpoint (b
);
1840 /* Breakpoints set through other program spaces could have locations
1841 bound to PSPACE as well. Remove those. */
1842 ALL_BP_LOCATIONS (loc
, loc_temp
)
1844 struct bp_location
*tmp
;
1846 if (loc
->pspace
== pspace
)
1848 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1849 if (loc
->owner
->loc
== loc
)
1850 loc
->owner
->loc
= loc
->next
;
1852 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1853 if (tmp
->next
== loc
)
1855 tmp
->next
= loc
->next
;
1861 /* Now update the global location list to permanently delete the
1862 removed locations above. */
1863 update_global_location_list (0);
1866 /* Make sure all breakpoints are inserted in inferior.
1867 Throws exception on any error.
1868 A breakpoint that is already inserted won't be inserted
1869 again, so calling this function twice is safe. */
1871 insert_breakpoints (void)
1873 struct breakpoint
*bpt
;
1875 ALL_BREAKPOINTS (bpt
)
1876 if (is_hardware_watchpoint (bpt
))
1877 update_watchpoint (bpt
, 0 /* don't reparse. */);
1879 update_global_location_list (1);
1881 /* update_global_location_list does not insert breakpoints when
1882 always_inserted_mode is not enabled. Explicitly insert them
1884 if (!breakpoints_always_inserted_mode ())
1885 insert_breakpoint_locations ();
1888 /* insert_breakpoints is used when starting or continuing the program.
1889 remove_breakpoints is used when the program stops.
1890 Both return zero if successful,
1891 or an `errno' value if could not write the inferior. */
1894 insert_breakpoint_locations (void)
1896 struct breakpoint
*bpt
;
1897 struct bp_location
*bl
, **blp_tmp
;
1900 int disabled_breaks
= 0;
1901 int hw_breakpoint_error
= 0;
1903 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1904 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1906 /* Explicitly mark the warning -- this will only be printed if
1907 there was an error. */
1908 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1910 save_current_space_and_thread ();
1912 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1914 if (!should_be_inserted (bl
) || bl
->inserted
)
1917 /* There is no point inserting thread-specific breakpoints if the
1918 thread no longer exists. ALL_BP_LOCATIONS bp_location has BL->OWNER
1920 if (bl
->owner
->thread
!= -1
1921 && !valid_thread_id (bl
->owner
->thread
))
1924 switch_to_program_space_and_thread (bl
->pspace
);
1926 /* For targets that support global breakpoints, there's no need
1927 to select an inferior to insert breakpoint to. In fact, even
1928 if we aren't attached to any process yet, we should still
1929 insert breakpoints. */
1930 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1931 && ptid_equal (inferior_ptid
, null_ptid
))
1934 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1935 &hw_breakpoint_error
);
1940 /* If we failed to insert all locations of a watchpoint,
1941 remove them, as half-inserted watchpoint is of limited use. */
1942 ALL_BREAKPOINTS (bpt
)
1944 int some_failed
= 0;
1945 struct bp_location
*loc
;
1947 if (!is_hardware_watchpoint (bpt
))
1950 if (!breakpoint_enabled (bpt
))
1953 if (bpt
->disposition
== disp_del_at_next_stop
)
1956 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1957 if (!loc
->inserted
&& should_be_inserted (loc
))
1964 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1966 remove_breakpoint (loc
, mark_uninserted
);
1968 hw_breakpoint_error
= 1;
1969 fprintf_unfiltered (tmp_error_stream
,
1970 "Could not insert hardware watchpoint %d.\n",
1978 /* If a hardware breakpoint or watchpoint was inserted, add a
1979 message about possibly exhausted resources. */
1980 if (hw_breakpoint_error
)
1982 fprintf_unfiltered (tmp_error_stream
,
1983 "Could not insert hardware breakpoints:\n\
1984 You may have requested too many hardware breakpoints/watchpoints.\n");
1986 target_terminal_ours_for_output ();
1987 error_stream (tmp_error_stream
);
1990 do_cleanups (cleanups
);
1994 remove_breakpoints (void)
1996 struct bp_location
*bl
, **blp_tmp
;
1999 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2002 val
|= remove_breakpoint (bl
, mark_uninserted
);
2007 /* Remove breakpoints of process PID. */
2010 remove_breakpoints_pid (int pid
)
2012 struct bp_location
*bl
, **blp_tmp
;
2014 struct inferior
*inf
= find_inferior_pid (pid
);
2016 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2018 if (bl
->pspace
!= inf
->pspace
)
2023 val
= remove_breakpoint (bl
, mark_uninserted
);
2032 remove_hw_watchpoints (void)
2034 struct bp_location
*bl
, **blp_tmp
;
2037 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2039 if (bl
->inserted
&& bl
->loc_type
== bp_loc_hardware_watchpoint
)
2040 val
|= remove_breakpoint (bl
, mark_uninserted
);
2046 reattach_breakpoints (int pid
)
2048 struct cleanup
*old_chain
;
2049 struct bp_location
*bl
, **blp_tmp
;
2051 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2052 int dummy1
= 0, dummy2
= 0;
2053 struct inferior
*inf
;
2054 struct thread_info
*tp
;
2056 tp
= any_live_thread_of_process (pid
);
2060 inf
= find_inferior_pid (pid
);
2061 old_chain
= save_inferior_ptid ();
2063 inferior_ptid
= tp
->ptid
;
2065 make_cleanup_ui_file_delete (tmp_error_stream
);
2067 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2069 if (bl
->pspace
!= inf
->pspace
)
2075 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2078 do_cleanups (old_chain
);
2083 do_cleanups (old_chain
);
2087 static int internal_breakpoint_number
= -1;
2089 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2090 If INTERNAL is non-zero, the breakpoint number will be populated
2091 from internal_breakpoint_number and that variable decremented.
2092 Otherwis the breakpoint number will be populated from
2093 breakpoint_count and that value incremented. Internal breakpoints
2094 do not set the internal var bpnum. */
2096 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2099 b
->number
= internal_breakpoint_number
--;
2102 set_breakpoint_count (breakpoint_count
+ 1);
2103 b
->number
= breakpoint_count
;
2107 static struct breakpoint
*
2108 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2109 CORE_ADDR address
, enum bptype type
)
2111 struct symtab_and_line sal
;
2112 struct breakpoint
*b
;
2114 init_sal (&sal
); /* initialize to zeroes */
2117 sal
.section
= find_pc_overlay (sal
.pc
);
2118 sal
.pspace
= current_program_space
;
2120 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2121 b
->number
= internal_breakpoint_number
--;
2122 b
->disposition
= disp_donttouch
;
2128 create_overlay_event_breakpoint (char *func_name
)
2130 struct objfile
*objfile
;
2132 ALL_OBJFILES (objfile
)
2134 struct breakpoint
*b
;
2135 struct minimal_symbol
*m
;
2137 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2141 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2142 SYMBOL_VALUE_ADDRESS (m
),
2144 b
->addr_string
= xstrdup (func_name
);
2146 if (overlay_debugging
== ovly_auto
)
2148 b
->enable_state
= bp_enabled
;
2149 overlay_events_enabled
= 1;
2153 b
->enable_state
= bp_disabled
;
2154 overlay_events_enabled
= 0;
2157 update_global_location_list (1);
2161 create_longjmp_master_breakpoint (char *func_name
)
2163 struct program_space
*pspace
;
2164 struct objfile
*objfile
;
2165 struct cleanup
*old_chain
;
2167 old_chain
= save_current_program_space ();
2169 ALL_PSPACES (pspace
)
2170 ALL_OBJFILES (objfile
)
2172 struct breakpoint
*b
;
2173 struct minimal_symbol
*m
;
2175 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2178 set_current_program_space (pspace
);
2180 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2184 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2185 SYMBOL_VALUE_ADDRESS (m
),
2187 b
->addr_string
= xstrdup (func_name
);
2188 b
->enable_state
= bp_disabled
;
2190 update_global_location_list (1);
2192 do_cleanups (old_chain
);
2195 /* Create a master std::terminate breakpoint. The actual function
2196 looked for is named FUNC_NAME. */
2198 create_std_terminate_master_breakpoint (const char *func_name
)
2200 struct program_space
*pspace
;
2201 struct objfile
*objfile
;
2202 struct cleanup
*old_chain
;
2204 old_chain
= save_current_program_space ();
2206 ALL_PSPACES (pspace
)
2207 ALL_OBJFILES (objfile
)
2209 struct breakpoint
*b
;
2210 struct minimal_symbol
*m
;
2212 set_current_program_space (pspace
);
2214 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2215 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2216 && MSYMBOL_TYPE (m
) != mst_file_text
))
2219 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2220 SYMBOL_VALUE_ADDRESS (m
),
2221 bp_std_terminate_master
);
2222 b
->addr_string
= xstrdup (func_name
);
2223 b
->enable_state
= bp_disabled
;
2225 update_global_location_list (1);
2227 do_cleanups (old_chain
);
2230 /* Install a master breakpoint on the unwinder's debug hook. */
2233 create_exception_master_breakpoint (void)
2235 struct objfile
*objfile
;
2237 ALL_OBJFILES (objfile
)
2239 struct minimal_symbol
*debug_hook
;
2241 debug_hook
= lookup_minimal_symbol ("_Unwind_DebugHook", NULL
, objfile
);
2242 if (debug_hook
!= NULL
)
2244 struct breakpoint
*b
;
2245 CORE_ADDR addr
= SYMBOL_VALUE_ADDRESS (debug_hook
);
2246 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2248 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2250 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2251 b
->addr_string
= xstrdup ("_Unwind_DebugHook");
2252 b
->enable_state
= bp_disabled
;
2256 update_global_location_list (1);
2260 update_breakpoints_after_exec (void)
2262 struct breakpoint
*b
, *b_tmp
;
2263 struct bp_location
*bploc
, **bplocp_tmp
;
2265 /* We're about to delete breakpoints from GDB's lists. If the
2266 INSERTED flag is true, GDB will try to lift the breakpoints by
2267 writing the breakpoints' "shadow contents" back into memory. The
2268 "shadow contents" are NOT valid after an exec, so GDB should not
2269 do that. Instead, the target is responsible from marking
2270 breakpoints out as soon as it detects an exec. We don't do that
2271 here instead, because there may be other attempts to delete
2272 breakpoints after detecting an exec and before reaching here. */
2273 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2274 if (bploc
->pspace
== current_program_space
)
2275 gdb_assert (!bploc
->inserted
);
2277 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2279 if (b
->pspace
!= current_program_space
)
2282 /* Solib breakpoints must be explicitly reset after an exec(). */
2283 if (b
->type
== bp_shlib_event
)
2285 delete_breakpoint (b
);
2289 /* JIT breakpoints must be explicitly reset after an exec(). */
2290 if (b
->type
== bp_jit_event
)
2292 delete_breakpoint (b
);
2296 /* Thread event breakpoints must be set anew after an exec(),
2297 as must overlay event and longjmp master breakpoints. */
2298 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2299 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2300 || b
->type
== bp_exception_master
)
2302 delete_breakpoint (b
);
2306 /* Step-resume breakpoints are meaningless after an exec(). */
2307 if (b
->type
== bp_step_resume
)
2309 delete_breakpoint (b
);
2313 /* Longjmp and longjmp-resume breakpoints are also meaningless
2315 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2316 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2318 delete_breakpoint (b
);
2322 if (b
->type
== bp_catchpoint
)
2324 /* For now, none of the bp_catchpoint breakpoints need to
2325 do anything at this point. In the future, if some of
2326 the catchpoints need to something, we will need to add
2327 a new method, and call this method from here. */
2331 /* bp_finish is a special case. The only way we ought to be able
2332 to see one of these when an exec() has happened, is if the user
2333 caught a vfork, and then said "finish". Ordinarily a finish just
2334 carries them to the call-site of the current callee, by setting
2335 a temporary bp there and resuming. But in this case, the finish
2336 will carry them entirely through the vfork & exec.
2338 We don't want to allow a bp_finish to remain inserted now. But
2339 we can't safely delete it, 'cause finish_command has a handle to
2340 the bp on a bpstat, and will later want to delete it. There's a
2341 chance (and I've seen it happen) that if we delete the bp_finish
2342 here, that its storage will get reused by the time finish_command
2343 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2344 We really must allow finish_command to delete a bp_finish.
2346 In the absense of a general solution for the "how do we know
2347 it's safe to delete something others may have handles to?"
2348 problem, what we'll do here is just uninsert the bp_finish, and
2349 let finish_command delete it.
2351 (We know the bp_finish is "doomed" in the sense that it's
2352 momentary, and will be deleted as soon as finish_command sees
2353 the inferior stopped. So it doesn't matter that the bp's
2354 address is probably bogus in the new a.out, unlike e.g., the
2355 solib breakpoints.) */
2357 if (b
->type
== bp_finish
)
2362 /* Without a symbolic address, we have little hope of the
2363 pre-exec() address meaning the same thing in the post-exec()
2365 if (b
->addr_string
== NULL
)
2367 delete_breakpoint (b
);
2371 /* FIXME what about longjmp breakpoints? Re-create them here? */
2372 create_overlay_event_breakpoint ("_ovly_debug_event");
2373 create_longjmp_master_breakpoint ("longjmp");
2374 create_longjmp_master_breakpoint ("_longjmp");
2375 create_longjmp_master_breakpoint ("siglongjmp");
2376 create_longjmp_master_breakpoint ("_siglongjmp");
2377 create_std_terminate_master_breakpoint ("std::terminate()");
2378 create_exception_master_breakpoint ();
2382 detach_breakpoints (int pid
)
2384 struct bp_location
*bl
, **blp_tmp
;
2386 struct cleanup
*old_chain
= save_inferior_ptid ();
2387 struct inferior
*inf
= current_inferior ();
2389 if (pid
== PIDGET (inferior_ptid
))
2390 error (_("Cannot detach breakpoints of inferior_ptid"));
2392 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2393 inferior_ptid
= pid_to_ptid (pid
);
2394 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2396 if (bl
->pspace
!= inf
->pspace
)
2400 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2403 /* Detach single-step breakpoints as well. */
2404 detach_single_step_breakpoints ();
2406 do_cleanups (old_chain
);
2410 /* Remove the breakpoint location BL from the current address space.
2411 Note that this is used to detach breakpoints from a child fork.
2412 When we get here, the child isn't in the inferior list, and neither
2413 do we have objects to represent its address space --- we should
2414 *not* look at bl->pspace->aspace here. */
2417 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2421 /* BL is never in moribund_locations by our callers. */
2422 gdb_assert (bl
->owner
!= NULL
);
2424 if (bl
->owner
->enable_state
== bp_permanent
)
2425 /* Permanent breakpoints cannot be inserted or removed. */
2428 /* The type of none suggests that owner is actually deleted.
2429 This should not ever happen. */
2430 gdb_assert (bl
->owner
->type
!= bp_none
);
2432 if (bl
->loc_type
== bp_loc_software_breakpoint
2433 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2435 /* "Normal" instruction breakpoint: either the standard
2436 trap-instruction bp (bp_breakpoint), or a
2437 bp_hardware_breakpoint. */
2439 /* First check to see if we have to handle an overlay. */
2440 if (overlay_debugging
== ovly_off
2441 || bl
->section
== NULL
2442 || !(section_is_overlay (bl
->section
)))
2444 /* No overlay handling: just remove the breakpoint. */
2446 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2447 val
= target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2449 val
= target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2453 /* This breakpoint is in an overlay section.
2454 Did we set a breakpoint at the LMA? */
2455 if (!overlay_events_enabled
)
2457 /* Yes -- overlay event support is not active, so we
2458 should have set a breakpoint at the LMA. Remove it.
2460 /* Ignore any failures: if the LMA is in ROM, we will
2461 have already warned when we failed to insert it. */
2462 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2463 target_remove_hw_breakpoint (bl
->gdbarch
,
2464 &bl
->overlay_target_info
);
2466 target_remove_breakpoint (bl
->gdbarch
,
2467 &bl
->overlay_target_info
);
2469 /* Did we set a breakpoint at the VMA?
2470 If so, we will have marked the breakpoint 'inserted'. */
2473 /* Yes -- remove it. Previously we did not bother to
2474 remove the breakpoint if the section had been
2475 unmapped, but let's not rely on that being safe. We
2476 don't know what the overlay manager might do. */
2477 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2478 val
= target_remove_hw_breakpoint (bl
->gdbarch
,
2481 /* However, we should remove *software* breakpoints only
2482 if the section is still mapped, or else we overwrite
2483 wrong code with the saved shadow contents. */
2484 else if (section_is_mapped (bl
->section
))
2485 val
= target_remove_breakpoint (bl
->gdbarch
,
2492 /* No -- not inserted, so no need to remove. No error. */
2497 /* In some cases, we might not be able to remove a breakpoint
2498 in a shared library that has already been removed, but we
2499 have not yet processed the shlib unload event. */
2500 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2505 bl
->inserted
= (is
== mark_inserted
);
2507 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2509 bl
->inserted
= (is
== mark_inserted
);
2510 val
= target_remove_watchpoint (bl
->address
, bl
->length
,
2511 bl
->watchpoint_type
, bl
->owner
->cond_exp
);
2513 /* Failure to remove any of the hardware watchpoints comes here. */
2514 if ((is
== mark_uninserted
) && (bl
->inserted
))
2515 warning (_("Could not remove hardware watchpoint %d."),
2518 else if (bl
->owner
->type
== bp_catchpoint
2519 && breakpoint_enabled (bl
->owner
)
2522 gdb_assert (bl
->owner
->ops
!= NULL
&& bl
->owner
->ops
->remove
!= NULL
);
2524 val
= bl
->owner
->ops
->remove (bl
->owner
);
2527 bl
->inserted
= (is
== mark_inserted
);
2534 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2537 struct cleanup
*old_chain
;
2539 /* BL is never in moribund_locations by our callers. */
2540 gdb_assert (bl
->owner
!= NULL
);
2542 if (bl
->owner
->enable_state
== bp_permanent
)
2543 /* Permanent breakpoints cannot be inserted or removed. */
2546 /* The type of none suggests that owner is actually deleted.
2547 This should not ever happen. */
2548 gdb_assert (bl
->owner
->type
!= bp_none
);
2550 old_chain
= save_current_space_and_thread ();
2552 switch_to_program_space_and_thread (bl
->pspace
);
2554 ret
= remove_breakpoint_1 (bl
, is
);
2556 do_cleanups (old_chain
);
2560 /* Clear the "inserted" flag in all breakpoints. */
2563 mark_breakpoints_out (void)
2565 struct bp_location
*bl
, **blp_tmp
;
2567 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2568 if (bl
->pspace
== current_program_space
)
2572 /* Clear the "inserted" flag in all breakpoints and delete any
2573 breakpoints which should go away between runs of the program.
2575 Plus other such housekeeping that has to be done for breakpoints
2578 Note: this function gets called at the end of a run (by
2579 generic_mourn_inferior) and when a run begins (by
2580 init_wait_for_inferior). */
2585 breakpoint_init_inferior (enum inf_context context
)
2587 struct breakpoint
*b
, *b_tmp
;
2588 struct bp_location
*bl
, **blp_tmp
;
2590 struct program_space
*pspace
= current_program_space
;
2592 /* If breakpoint locations are shared across processes, then there's
2594 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2597 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2599 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2600 if (bl
->pspace
== pspace
2601 && bl
->owner
->enable_state
!= bp_permanent
)
2605 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2607 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2614 /* If the call dummy breakpoint is at the entry point it will
2615 cause problems when the inferior is rerun, so we better get
2618 case bp_watchpoint_scope
:
2620 /* Also get rid of scope breakpoints. */
2622 case bp_shlib_event
:
2624 /* Also remove solib event breakpoints. Their addresses may
2625 have changed since the last time we ran the program.
2626 Actually we may now be debugging against different target;
2627 and so the solib backend that installed this breakpoint may
2628 not be used in by the target. E.g.,
2630 (gdb) file prog-linux
2631 (gdb) run # native linux target
2634 (gdb) file prog-win.exe
2635 (gdb) tar rem :9999 # remote Windows gdbserver.
2638 delete_breakpoint (b
);
2642 case bp_hardware_watchpoint
:
2643 case bp_read_watchpoint
:
2644 case bp_access_watchpoint
:
2646 /* Likewise for watchpoints on local expressions. */
2647 if (b
->exp_valid_block
!= NULL
)
2648 delete_breakpoint (b
);
2649 else if (context
== inf_starting
)
2651 /* Reset val field to force reread of starting value
2652 in insert_breakpoints. */
2654 value_free (b
->val
);
2664 /* Get rid of the moribund locations. */
2665 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2666 decref_bp_location (&bl
);
2667 VEC_free (bp_location_p
, moribund_locations
);
2670 /* These functions concern about actual breakpoints inserted in the
2671 target --- to e.g. check if we need to do decr_pc adjustment or if
2672 we need to hop over the bkpt --- so we check for address space
2673 match, not program space. */
2675 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2676 exists at PC. It returns ordinary_breakpoint_here if it's an
2677 ordinary breakpoint, or permanent_breakpoint_here if it's a
2678 permanent breakpoint.
2679 - When continuing from a location with an ordinary breakpoint, we
2680 actually single step once before calling insert_breakpoints.
2681 - When continuing from a localion with a permanent breakpoint, we
2682 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2683 the target, to advance the PC past the breakpoint. */
2685 enum breakpoint_here
2686 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2688 struct bp_location
*bl
, **blp_tmp
;
2689 int any_breakpoint_here
= 0;
2691 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2693 if (bl
->loc_type
!= bp_loc_software_breakpoint
2694 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2697 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2698 if ((breakpoint_enabled (bl
->owner
)
2699 || bl
->owner
->enable_state
== bp_permanent
)
2700 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2703 if (overlay_debugging
2704 && section_is_overlay (bl
->section
)
2705 && !section_is_mapped (bl
->section
))
2706 continue; /* unmapped overlay -- can't be a match */
2707 else if (bl
->owner
->enable_state
== bp_permanent
)
2708 return permanent_breakpoint_here
;
2710 any_breakpoint_here
= 1;
2714 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2717 /* Return true if there's a moribund breakpoint at PC. */
2720 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2722 struct bp_location
*loc
;
2725 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2726 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2733 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2734 inserted using regular breakpoint_chain / bp_location array mechanism.
2735 This does not check for single-step breakpoints, which are
2736 inserted and removed using direct target manipulation. */
2739 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2741 struct bp_location
*bl
, **blp_tmp
;
2743 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2745 if (bl
->loc_type
!= bp_loc_software_breakpoint
2746 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2750 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2753 if (overlay_debugging
2754 && section_is_overlay (bl
->section
)
2755 && !section_is_mapped (bl
->section
))
2756 continue; /* unmapped overlay -- can't be a match */
2764 /* Returns non-zero iff there's either regular breakpoint
2765 or a single step breakpoint inserted at PC. */
2768 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2770 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2773 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2779 /* This function returns non-zero iff there is a software breakpoint
2783 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2785 struct bp_location
*bl
, **blp_tmp
;
2787 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2789 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2793 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2796 if (overlay_debugging
2797 && section_is_overlay (bl
->section
)
2798 && !section_is_mapped (bl
->section
))
2799 continue; /* unmapped overlay -- can't be a match */
2805 /* Also check for software single-step breakpoints. */
2806 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2813 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2814 CORE_ADDR addr
, ULONGEST len
)
2816 struct breakpoint
*bpt
;
2818 ALL_BREAKPOINTS (bpt
)
2820 struct bp_location
*loc
;
2822 if (bpt
->type
!= bp_hardware_watchpoint
2823 && bpt
->type
!= bp_access_watchpoint
)
2826 if (!breakpoint_enabled (bpt
))
2829 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2830 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2834 /* Check for intersection. */
2835 l
= max (loc
->address
, addr
);
2836 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2844 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2845 PC is valid for process/thread PTID. */
2848 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2851 struct bp_location
*bl
, **blp_tmp
;
2852 /* The thread and task IDs associated to PTID, computed lazily. */
2856 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2858 if (bl
->loc_type
!= bp_loc_software_breakpoint
2859 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2862 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2863 if (!breakpoint_enabled (bl
->owner
)
2864 && bl
->owner
->enable_state
!= bp_permanent
)
2867 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2871 if (bl
->owner
->thread
!= -1)
2873 /* This is a thread-specific breakpoint. Check that ptid
2874 matches that thread. If thread hasn't been computed yet,
2875 it is now time to do so. */
2877 thread
= pid_to_thread_id (ptid
);
2878 if (bl
->owner
->thread
!= thread
)
2882 if (bl
->owner
->task
!= 0)
2884 /* This is a task-specific breakpoint. Check that ptid
2885 matches that task. If task hasn't been computed yet,
2886 it is now time to do so. */
2888 task
= ada_get_task_number (ptid
);
2889 if (bl
->owner
->task
!= task
)
2893 if (overlay_debugging
2894 && section_is_overlay (bl
->section
)
2895 && !section_is_mapped (bl
->section
))
2896 continue; /* unmapped overlay -- can't be a match */
2905 /* bpstat stuff. External routines' interfaces are documented
2909 ep_is_catchpoint (struct breakpoint
*ep
)
2911 return (ep
->type
== bp_catchpoint
);
2914 /* Frees any storage that is part of a bpstat. Does not walk the
2918 bpstat_free (bpstat bs
)
2920 if (bs
->old_val
!= NULL
)
2921 value_free (bs
->old_val
);
2922 decref_counted_command_line (&bs
->commands
);
2923 decref_bp_location (&bs
->bp_location_at
);
2927 /* Clear a bpstat so that it says we are not at any breakpoint.
2928 Also free any storage that is part of a bpstat. */
2931 bpstat_clear (bpstat
*bsp
)
2948 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2949 is part of the bpstat is copied as well. */
2952 bpstat_copy (bpstat bs
)
2956 bpstat retval
= NULL
;
2961 for (; bs
!= NULL
; bs
= bs
->next
)
2963 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2964 memcpy (tmp
, bs
, sizeof (*tmp
));
2965 incref_counted_command_line (tmp
->commands
);
2966 incref_bp_location (tmp
->bp_location_at
);
2967 if (bs
->old_val
!= NULL
)
2969 tmp
->old_val
= value_copy (bs
->old_val
);
2970 release_value (tmp
->old_val
);
2974 /* This is the first thing in the chain. */
2984 /* Find the bpstat associated with this breakpoint */
2987 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2992 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2994 if (bsp
->breakpoint_at
== breakpoint
)
3000 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
3001 at. *BSP upon return is a bpstat which points to the remaining
3002 breakpoints stopped at (but which is not guaranteed to be good for
3003 anything but further calls to bpstat_num).
3004 Return 0 if passed a bpstat which does not indicate any breakpoints.
3005 Return -1 if stopped at a breakpoint that has been deleted since
3007 Return 1 otherwise. */
3010 bpstat_num (bpstat
*bsp
, int *num
)
3012 struct breakpoint
*b
;
3015 return 0; /* No more breakpoint values */
3017 /* We assume we'll never have several bpstats that
3018 correspond to a single breakpoint -- otherwise,
3019 this function might return the same number more
3020 than once and this will look ugly. */
3021 b
= (*bsp
)->breakpoint_at
;
3022 *bsp
= (*bsp
)->next
;
3024 return -1; /* breakpoint that's been deleted since */
3026 *num
= b
->number
; /* We have its number */
3030 /* Modify BS so that the actions will not be performed. */
3033 bpstat_clear_actions (bpstat bs
)
3035 for (; bs
!= NULL
; bs
= bs
->next
)
3037 decref_counted_command_line (&bs
->commands
);
3038 bs
->commands_left
= NULL
;
3039 if (bs
->old_val
!= NULL
)
3041 value_free (bs
->old_val
);
3047 /* Called when a command is about to proceed the inferior. */
3050 breakpoint_about_to_proceed (void)
3052 if (!ptid_equal (inferior_ptid
, null_ptid
))
3054 struct thread_info
*tp
= inferior_thread ();
3056 /* Allow inferior function calls in breakpoint commands to not
3057 interrupt the command list. When the call finishes
3058 successfully, the inferior will be standing at the same
3059 breakpoint as if nothing happened. */
3060 if (tp
->control
.in_infcall
)
3064 breakpoint_proceeded
= 1;
3067 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3069 cleanup_executing_breakpoints (void *ignore
)
3071 executing_breakpoint_commands
= 0;
3074 /* Execute all the commands associated with all the breakpoints at this
3075 location. Any of these commands could cause the process to proceed
3076 beyond this point, etc. We look out for such changes by checking
3077 the global "breakpoint_proceeded" after each command.
3079 Returns true if a breakpoint command resumed the inferior. In that
3080 case, it is the caller's responsibility to recall it again with the
3081 bpstat of the current thread. */
3084 bpstat_do_actions_1 (bpstat
*bsp
)
3087 struct cleanup
*old_chain
;
3090 /* Avoid endless recursion if a `source' command is contained
3092 if (executing_breakpoint_commands
)
3095 executing_breakpoint_commands
= 1;
3096 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3098 /* This pointer will iterate over the list of bpstat's. */
3101 breakpoint_proceeded
= 0;
3102 for (; bs
!= NULL
; bs
= bs
->next
)
3104 struct counted_command_line
*ccmd
;
3105 struct command_line
*cmd
;
3106 struct cleanup
*this_cmd_tree_chain
;
3108 /* Take ownership of the BSP's command tree, if it has one.
3110 The command tree could legitimately contain commands like
3111 'step' and 'next', which call clear_proceed_status, which
3112 frees stop_bpstat's command tree. To make sure this doesn't
3113 free the tree we're executing out from under us, we need to
3114 take ownership of the tree ourselves. Since a given bpstat's
3115 commands are only executed once, we don't need to copy it; we
3116 can clear the pointer in the bpstat, and make sure we free
3117 the tree when we're done. */
3118 ccmd
= bs
->commands
;
3119 bs
->commands
= NULL
;
3121 = make_cleanup_decref_counted_command_line (&ccmd
);
3122 cmd
= bs
->commands_left
;
3123 bs
->commands_left
= NULL
;
3127 execute_control_command (cmd
);
3129 if (breakpoint_proceeded
)
3135 /* We can free this command tree now. */
3136 do_cleanups (this_cmd_tree_chain
);
3138 if (breakpoint_proceeded
)
3140 if (target_can_async_p ())
3141 /* If we are in async mode, then the target might be still
3142 running, not stopped at any breakpoint, so nothing for
3143 us to do here -- just return to the event loop. */
3146 /* In sync mode, when execute_control_command returns
3147 we're already standing on the next breakpoint.
3148 Breakpoint commands for that stop were not run, since
3149 execute_command does not run breakpoint commands --
3150 only command_line_handler does, but that one is not
3151 involved in execution of breakpoint commands. So, we
3152 can now execute breakpoint commands. It should be
3153 noted that making execute_command do bpstat actions is
3154 not an option -- in this case we'll have recursive
3155 invocation of bpstat for each breakpoint with a
3156 command, and can easily blow up GDB stack. Instead, we
3157 return true, which will trigger the caller to recall us
3158 with the new stop_bpstat. */
3163 do_cleanups (old_chain
);
3168 bpstat_do_actions (void)
3170 /* Do any commands attached to breakpoint we are stopped at. */
3171 while (!ptid_equal (inferior_ptid
, null_ptid
)
3172 && target_has_execution
3173 && !is_exited (inferior_ptid
)
3174 && !is_executing (inferior_ptid
))
3175 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3176 and only return when it is stopped at the next breakpoint, we
3177 keep doing breakpoint actions until it returns false to
3178 indicate the inferior was not resumed. */
3179 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3183 /* Print out the (old or new) value associated with a watchpoint. */
3186 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3189 fprintf_unfiltered (stream
, _("<unreadable>"));
3192 struct value_print_options opts
;
3193 get_user_print_options (&opts
);
3194 value_print (val
, stream
, &opts
);
3198 /* This is the normal print function for a bpstat. In the future,
3199 much of this logic could (should?) be moved to bpstat_stop_status,
3200 by having it set different print_it values.
3202 Current scheme: When we stop, bpstat_print() is called. It loops
3203 through the bpstat list of things causing this stop, calling the
3204 print_bp_stop_message function on each one. The behavior of the
3205 print_bp_stop_message function depends on the print_it field of
3206 bpstat. If such field so indicates, call this function here.
3208 Return values from this routine (ultimately used by bpstat_print()
3209 and normal_stop() to decide what to do):
3210 PRINT_NOTHING: Means we already printed all we needed to print,
3211 don't print anything else.
3212 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3213 that something to be followed by a location.
3214 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3215 that something to be followed by a location.
3216 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3219 static enum print_stop_action
3220 print_it_typical (bpstat bs
)
3222 struct cleanup
*old_chain
;
3223 struct breakpoint
*b
;
3224 const struct bp_location
*bl
;
3225 struct ui_stream
*stb
;
3227 enum print_stop_action result
;
3229 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3230 which has since been deleted. */
3231 if (bs
->breakpoint_at
== NULL
)
3232 return PRINT_UNKNOWN
;
3234 gdb_assert (bs
->bp_location_at
!= NULL
);
3236 bl
= bs
->bp_location_at
;
3237 b
= bs
->breakpoint_at
;
3239 stb
= ui_out_stream_new (uiout
);
3240 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3245 case bp_hardware_breakpoint
:
3246 bp_temp
= b
->disposition
== disp_del
;
3247 if (bl
->address
!= bl
->requested_address
)
3248 breakpoint_adjustment_warning (bl
->requested_address
,
3251 annotate_breakpoint (b
->number
);
3253 ui_out_text (uiout
, "\nTemporary breakpoint ");
3255 ui_out_text (uiout
, "\nBreakpoint ");
3256 if (ui_out_is_mi_like_p (uiout
))
3258 ui_out_field_string (uiout
, "reason",
3259 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3260 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3262 ui_out_field_int (uiout
, "bkptno", b
->number
);
3263 ui_out_text (uiout
, ", ");
3264 result
= PRINT_SRC_AND_LOC
;
3267 case bp_shlib_event
:
3268 /* Did we stop because the user set the stop_on_solib_events
3269 variable? (If so, we report this as a generic, "Stopped due
3270 to shlib event" message.) */
3271 printf_filtered (_("Stopped due to shared library event\n"));
3272 result
= PRINT_NOTHING
;
3275 case bp_thread_event
:
3276 /* Not sure how we will get here.
3277 GDB should not stop for these breakpoints. */
3278 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3279 result
= PRINT_NOTHING
;
3282 case bp_overlay_event
:
3283 /* By analogy with the thread event, GDB should not stop for these. */
3284 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3285 result
= PRINT_NOTHING
;
3288 case bp_longjmp_master
:
3289 /* These should never be enabled. */
3290 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3291 result
= PRINT_NOTHING
;
3294 case bp_std_terminate_master
:
3295 /* These should never be enabled. */
3296 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3297 result
= PRINT_NOTHING
;
3300 case bp_exception_master
:
3301 /* These should never be enabled. */
3302 printf_filtered (_("Exception Master Breakpoint: gdb should not stop!\n"));
3303 result
= PRINT_NOTHING
;
3307 case bp_hardware_watchpoint
:
3308 annotate_watchpoint (b
->number
);
3309 if (ui_out_is_mi_like_p (uiout
))
3312 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3314 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3315 ui_out_text (uiout
, "\nOld value = ");
3316 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3317 ui_out_field_stream (uiout
, "old", stb
);
3318 ui_out_text (uiout
, "\nNew value = ");
3319 watchpoint_value_print (b
->val
, stb
->stream
);
3320 ui_out_field_stream (uiout
, "new", stb
);
3321 ui_out_text (uiout
, "\n");
3322 /* More than one watchpoint may have been triggered. */
3323 result
= PRINT_UNKNOWN
;
3326 case bp_read_watchpoint
:
3327 if (ui_out_is_mi_like_p (uiout
))
3330 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3332 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3333 ui_out_text (uiout
, "\nValue = ");
3334 watchpoint_value_print (b
->val
, stb
->stream
);
3335 ui_out_field_stream (uiout
, "value", stb
);
3336 ui_out_text (uiout
, "\n");
3337 result
= PRINT_UNKNOWN
;
3340 case bp_access_watchpoint
:
3341 if (bs
->old_val
!= NULL
)
3343 annotate_watchpoint (b
->number
);
3344 if (ui_out_is_mi_like_p (uiout
))
3347 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3349 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3350 ui_out_text (uiout
, "\nOld value = ");
3351 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3352 ui_out_field_stream (uiout
, "old", stb
);
3353 ui_out_text (uiout
, "\nNew value = ");
3358 if (ui_out_is_mi_like_p (uiout
))
3361 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3362 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3363 ui_out_text (uiout
, "\nValue = ");
3365 watchpoint_value_print (b
->val
, stb
->stream
);
3366 ui_out_field_stream (uiout
, "new", stb
);
3367 ui_out_text (uiout
, "\n");
3368 result
= PRINT_UNKNOWN
;
3371 /* Fall through, we don't deal with these types of breakpoints
3375 if (ui_out_is_mi_like_p (uiout
))
3378 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3379 result
= PRINT_UNKNOWN
;
3383 if (ui_out_is_mi_like_p (uiout
))
3386 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3387 result
= PRINT_UNKNOWN
;
3392 case bp_longjmp_resume
:
3394 case bp_exception_resume
:
3395 case bp_step_resume
:
3396 case bp_watchpoint_scope
:
3398 case bp_std_terminate
:
3400 case bp_fast_tracepoint
:
3403 result
= PRINT_UNKNOWN
;
3407 do_cleanups (old_chain
);
3411 /* Generic routine for printing messages indicating why we
3412 stopped. The behavior of this function depends on the value
3413 'print_it' in the bpstat structure. Under some circumstances we
3414 may decide not to print anything here and delegate the task to
3417 static enum print_stop_action
3418 print_bp_stop_message (bpstat bs
)
3420 switch (bs
->print_it
)
3423 /* Nothing should be printed for this bpstat entry. */
3424 return PRINT_UNKNOWN
;
3428 /* We still want to print the frame, but we already printed the
3429 relevant messages. */
3430 return PRINT_SRC_AND_LOC
;
3433 case print_it_normal
:
3435 struct breakpoint
*b
= bs
->breakpoint_at
;
3437 /* Normal case. Call the breakpoint's print_it method, or
3438 print_it_typical. */
3439 /* FIXME: how breakpoint can ever be NULL here? */
3440 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3441 return b
->ops
->print_it (b
);
3443 return print_it_typical (bs
);
3448 internal_error (__FILE__
, __LINE__
,
3449 _("print_bp_stop_message: unrecognized enum value"));
3454 /* Print a message indicating what happened. This is called from
3455 normal_stop(). The input to this routine is the head of the bpstat
3456 list - a list of the eventpoints that caused this stop. This
3457 routine calls the generic print routine for printing a message
3458 about reasons for stopping. This will print (for example) the
3459 "Breakpoint n," part of the output. The return value of this
3462 PRINT_UNKNOWN: Means we printed nothing
3463 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3464 code to print the location. An example is
3465 "Breakpoint 1, " which should be followed by
3467 PRINT_SRC_ONLY: Means we printed something, but there is no need
3468 to also print the location part of the message.
3469 An example is the catch/throw messages, which
3470 don't require a location appended to the end.
3471 PRINT_NOTHING: We have done some printing and we don't need any
3472 further info to be printed.*/
3474 enum print_stop_action
3475 bpstat_print (bpstat bs
)
3479 /* Maybe another breakpoint in the chain caused us to stop.
3480 (Currently all watchpoints go on the bpstat whether hit or not.
3481 That probably could (should) be changed, provided care is taken
3482 with respect to bpstat_explains_signal). */
3483 for (; bs
; bs
= bs
->next
)
3485 val
= print_bp_stop_message (bs
);
3486 if (val
== PRINT_SRC_ONLY
3487 || val
== PRINT_SRC_AND_LOC
3488 || val
== PRINT_NOTHING
)
3492 /* We reached the end of the chain, or we got a null BS to start
3493 with and nothing was printed. */
3494 return PRINT_UNKNOWN
;
3497 /* Evaluate the expression EXP and return 1 if value is zero.
3498 This is used inside a catch_errors to evaluate the breakpoint condition.
3499 The argument is a "struct expression *" that has been cast to char * to
3500 make it pass through catch_errors. */
3503 breakpoint_cond_eval (void *exp
)
3505 struct value
*mark
= value_mark ();
3506 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3508 value_free_to_mark (mark
);
3512 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3515 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3519 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3521 **bs_link_pointer
= bs
;
3522 *bs_link_pointer
= &bs
->next
;
3523 bs
->breakpoint_at
= bl
->owner
;
3524 bs
->bp_location_at
= bl
;
3525 incref_bp_location (bl
);
3526 /* If the condition is false, etc., don't do the commands. */
3527 bs
->commands
= NULL
;
3528 bs
->commands_left
= NULL
;
3530 bs
->print_it
= print_it_normal
;
3534 /* The target has stopped with waitstatus WS. Check if any hardware
3535 watchpoints have triggered, according to the target. */
3538 watchpoints_triggered (struct target_waitstatus
*ws
)
3540 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3542 struct breakpoint
*b
;
3544 if (!stopped_by_watchpoint
)
3546 /* We were not stopped by a watchpoint. Mark all watchpoints
3547 as not triggered. */
3549 if (is_hardware_watchpoint (b
))
3550 b
->watchpoint_triggered
= watch_triggered_no
;
3555 if (!target_stopped_data_address (¤t_target
, &addr
))
3557 /* We were stopped by a watchpoint, but we don't know where.
3558 Mark all watchpoints as unknown. */
3560 if (is_hardware_watchpoint (b
))
3561 b
->watchpoint_triggered
= watch_triggered_unknown
;
3563 return stopped_by_watchpoint
;
3566 /* The target could report the data address. Mark watchpoints
3567 affected by this data address as triggered, and all others as not
3571 if (is_hardware_watchpoint (b
))
3573 struct bp_location
*loc
;
3575 b
->watchpoint_triggered
= watch_triggered_no
;
3576 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3577 /* Exact match not required. Within range is
3579 if (target_watchpoint_addr_within_range (¤t_target
,
3583 b
->watchpoint_triggered
= watch_triggered_yes
;
3591 /* Possible return values for watchpoint_check (this can't be an enum
3592 because of check_errors). */
3593 /* The watchpoint has been deleted. */
3594 #define WP_DELETED 1
3595 /* The value has changed. */
3596 #define WP_VALUE_CHANGED 2
3597 /* The value has not changed. */
3598 #define WP_VALUE_NOT_CHANGED 3
3599 /* Ignore this watchpoint, no matter if the value changed or not. */
3602 #define BP_TEMPFLAG 1
3603 #define BP_HARDWAREFLAG 2
3605 /* Evaluate watchpoint condition expression and check if its value changed.
3607 P should be a pointer to struct bpstat, but is defined as a void *
3608 in order for this function to be usable with catch_errors. */
3611 watchpoint_check (void *p
)
3613 bpstat bs
= (bpstat
) p
;
3614 struct breakpoint
*b
;
3615 struct frame_info
*fr
;
3616 int within_current_scope
;
3618 /* BS is built from an existing struct breakpoint. */
3619 gdb_assert (bs
->breakpoint_at
!= NULL
);
3620 b
= bs
->breakpoint_at
;
3622 /* If this is a local watchpoint, we only want to check if the
3623 watchpoint frame is in scope if the current thread is the thread
3624 that was used to create the watchpoint. */
3625 if (!watchpoint_in_thread_scope (b
))
3628 if (b
->exp_valid_block
== NULL
)
3629 within_current_scope
= 1;
3632 struct frame_info
*frame
= get_current_frame ();
3633 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3634 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3636 /* in_function_epilogue_p() returns a non-zero value if we're still
3637 in the function but the stack frame has already been invalidated.
3638 Since we can't rely on the values of local variables after the
3639 stack has been destroyed, we are treating the watchpoint in that
3640 state as `not changed' without further checking. Don't mark
3641 watchpoints as changed if the current frame is in an epilogue -
3642 even if they are in some other frame, our view of the stack
3643 is likely to be wrong and frame_find_by_id could error out. */
3644 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3647 fr
= frame_find_by_id (b
->watchpoint_frame
);
3648 within_current_scope
= (fr
!= NULL
);
3650 /* If we've gotten confused in the unwinder, we might have
3651 returned a frame that can't describe this variable. */
3652 if (within_current_scope
)
3654 struct symbol
*function
;
3656 function
= get_frame_function (fr
);
3657 if (function
== NULL
3658 || !contained_in (b
->exp_valid_block
,
3659 SYMBOL_BLOCK_VALUE (function
)))
3660 within_current_scope
= 0;
3663 if (within_current_scope
)
3664 /* If we end up stopping, the current frame will get selected
3665 in normal_stop. So this call to select_frame won't affect
3670 if (within_current_scope
)
3672 /* We use value_{,free_to_}mark because it could be a
3673 *long* time before we return to the command level and
3674 call free_all_values. We can't call free_all_values because
3675 we might be in the middle of evaluating a function call. */
3678 struct value
*mark
= value_mark ();
3679 struct value
*new_val
;
3681 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3683 /* We use value_equal_contents instead of value_equal because the latter
3684 coerces an array to a pointer, thus comparing just the address of the
3685 array instead of its contents. This is not what we want. */
3686 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3687 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3689 if (new_val
!= NULL
)
3691 release_value (new_val
);
3692 value_free_to_mark (mark
);
3694 bs
->old_val
= b
->val
;
3697 return WP_VALUE_CHANGED
;
3701 /* Nothing changed. */
3702 value_free_to_mark (mark
);
3703 return WP_VALUE_NOT_CHANGED
;
3708 /* This seems like the only logical thing to do because
3709 if we temporarily ignored the watchpoint, then when
3710 we reenter the block in which it is valid it contains
3711 garbage (in the case of a function, it may have two
3712 garbage values, one before and one after the prologue).
3713 So we can't even detect the first assignment to it and
3714 watch after that (since the garbage may or may not equal
3715 the first value assigned). */
3716 /* We print all the stop information in print_it_typical(), but
3717 in this case, by the time we call print_it_typical() this bp
3718 will be deleted already. So we have no choice but print the
3719 information here. */
3720 if (ui_out_is_mi_like_p (uiout
))
3722 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3723 ui_out_text (uiout
, "\nWatchpoint ");
3724 ui_out_field_int (uiout
, "wpnum", b
->number
);
3725 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3726 which its expression is valid.\n");
3728 if (b
->related_breakpoint
)
3730 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3731 b
->related_breakpoint
->related_breakpoint
= NULL
;
3732 b
->related_breakpoint
= NULL
;
3734 b
->disposition
= disp_del_at_next_stop
;
3740 /* Return true if it looks like target has stopped due to hitting
3741 breakpoint location BL. This function does not check if we
3742 should stop, only if BL explains the stop. */
3744 bpstat_check_location (const struct bp_location
*bl
,
3745 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3747 struct breakpoint
*b
= bl
->owner
;
3749 /* BL is from existing struct breakpoint. */
3750 gdb_assert (b
!= NULL
);
3752 /* By definition, the inferior does not report stops at
3754 if (is_tracepoint (b
))
3757 if (!is_watchpoint (b
)
3758 && b
->type
!= bp_hardware_breakpoint
3759 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3761 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3764 if (overlay_debugging
/* unmapped overlay section */
3765 && section_is_overlay (bl
->section
)
3766 && !section_is_mapped (bl
->section
))
3770 /* Continuable hardware watchpoints are treated as non-existent if the
3771 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3772 some data address). Otherwise gdb won't stop on a break instruction
3773 in the code (not from a breakpoint) when a hardware watchpoint has
3774 been defined. Also skip watchpoints which we know did not trigger
3775 (did not match the data address). */
3777 if (is_hardware_watchpoint (b
)
3778 && b
->watchpoint_triggered
== watch_triggered_no
)
3781 if (b
->type
== bp_hardware_breakpoint
)
3783 if (bl
->address
!= bp_addr
)
3785 if (overlay_debugging
/* unmapped overlay section */
3786 && section_is_overlay (bl
->section
)
3787 && !section_is_mapped (bl
->section
))
3791 if (b
->type
== bp_catchpoint
)
3793 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3794 if (!b
->ops
->breakpoint_hit (b
))
3801 /* If BS refers to a watchpoint, determine if the watched values
3802 has actually changed, and we should stop. If not, set BS->stop
3805 bpstat_check_watchpoint (bpstat bs
)
3807 const struct bp_location
*bl
;
3808 struct breakpoint
*b
;
3810 /* BS is built for existing struct breakpoint. */
3811 bl
= bs
->bp_location_at
;
3812 gdb_assert (bl
!= NULL
);
3813 b
= bs
->breakpoint_at
;
3814 gdb_assert (b
!= NULL
);
3816 if (is_watchpoint (b
))
3818 int must_check_value
= 0;
3820 if (b
->type
== bp_watchpoint
)
3821 /* For a software watchpoint, we must always check the
3823 must_check_value
= 1;
3824 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3825 /* We have a hardware watchpoint (read, write, or access)
3826 and the target earlier reported an address watched by
3828 must_check_value
= 1;
3829 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3830 && b
->type
== bp_hardware_watchpoint
)
3831 /* We were stopped by a hardware watchpoint, but the target could
3832 not report the data address. We must check the watchpoint's
3833 value. Access and read watchpoints are out of luck; without
3834 a data address, we can't figure it out. */
3835 must_check_value
= 1;
3837 if (must_check_value
)
3839 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3841 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3842 int e
= catch_errors (watchpoint_check
, bs
, message
,
3844 do_cleanups (cleanups
);
3848 /* We've already printed what needs to be printed. */
3849 bs
->print_it
= print_it_done
;
3853 bs
->print_it
= print_it_noop
;
3856 case WP_VALUE_CHANGED
:
3857 if (b
->type
== bp_read_watchpoint
)
3859 /* There are two cases to consider here:
3861 1. we're watching the triggered memory for reads.
3862 In that case, trust the target, and always report
3863 the watchpoint hit to the user. Even though
3864 reads don't cause value changes, the value may
3865 have changed since the last time it was read, and
3866 since we're not trapping writes, we will not see
3867 those, and as such we should ignore our notion of
3870 2. we're watching the triggered memory for both
3871 reads and writes. There are two ways this may
3874 2.1. this is a target that can't break on data
3875 reads only, but can break on accesses (reads or
3876 writes), such as e.g., x86. We detect this case
3877 at the time we try to insert read watchpoints.
3879 2.2. otherwise, the target supports read
3880 watchpoints, but, the user set an access or write
3881 watchpoint watching the same memory as this read
3884 If we're watching memory writes as well as reads,
3885 ignore watchpoint hits when we find that the
3886 value hasn't changed, as reads don't cause
3887 changes. This still gives false positives when
3888 the program writes the same value to memory as
3889 what there was already in memory (we will confuse
3890 it for a read), but it's much better than
3893 int other_write_watchpoint
= 0;
3895 if (bl
->watchpoint_type
== hw_read
)
3897 struct breakpoint
*other_b
;
3899 ALL_BREAKPOINTS (other_b
)
3900 if ((other_b
->type
== bp_hardware_watchpoint
3901 || other_b
->type
== bp_access_watchpoint
)
3902 && (other_b
->watchpoint_triggered
3903 == watch_triggered_yes
))
3905 other_write_watchpoint
= 1;
3910 if (other_write_watchpoint
3911 || bl
->watchpoint_type
== hw_access
)
3913 /* We're watching the same memory for writes,
3914 and the value changed since the last time we
3915 updated it, so this trap must be for a write.
3917 bs
->print_it
= print_it_noop
;
3922 case WP_VALUE_NOT_CHANGED
:
3923 if (b
->type
== bp_hardware_watchpoint
3924 || b
->type
== bp_watchpoint
)
3926 /* Don't stop: write watchpoints shouldn't fire if
3927 the value hasn't changed. */
3928 bs
->print_it
= print_it_noop
;
3936 /* Error from catch_errors. */
3937 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3938 if (b
->related_breakpoint
)
3939 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3940 b
->disposition
= disp_del_at_next_stop
;
3941 /* We've already printed what needs to be printed. */
3942 bs
->print_it
= print_it_done
;
3946 else /* must_check_value == 0 */
3948 /* This is a case where some watchpoint(s) triggered, but
3949 not at the address of this watchpoint, or else no
3950 watchpoint triggered after all. So don't print
3951 anything for this watchpoint. */
3952 bs
->print_it
= print_it_noop
;
3959 /* Check conditions (condition proper, frame, thread and ignore count)
3960 of breakpoint referred to by BS. If we should not stop for this
3961 breakpoint, set BS->stop to 0. */
3964 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3966 int thread_id
= pid_to_thread_id (ptid
);
3967 const struct bp_location
*bl
;
3968 struct breakpoint
*b
;
3970 /* BS is built for existing struct breakpoint. */
3971 bl
= bs
->bp_location_at
;
3972 gdb_assert (bl
!= NULL
);
3973 b
= bs
->breakpoint_at
;
3974 gdb_assert (b
!= NULL
);
3976 if (frame_id_p (b
->frame_id
)
3977 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3981 int value_is_zero
= 0;
3982 struct expression
*cond
;
3984 if (is_watchpoint (b
))
3989 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3991 int within_current_scope
= 1;
3993 /* We use value_mark and value_free_to_mark because it could
3994 be a long time before we return to the command level and
3995 call free_all_values. We can't call free_all_values
3996 because we might be in the middle of evaluating a
3998 struct value
*mark
= value_mark ();
4000 /* Need to select the frame, with all that implies so that
4001 the conditions will have the right context. Because we
4002 use the frame, we will not see an inlined function's
4003 variables when we arrive at a breakpoint at the start
4004 of the inlined function; the current frame will be the
4006 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
4007 select_frame (get_current_frame ());
4010 struct frame_info
*frame
;
4012 /* For local watchpoint expressions, which particular
4013 instance of a local is being watched matters, so we
4014 keep track of the frame to evaluate the expression
4015 in. To evaluate the condition however, it doesn't
4016 really matter which instantiation of the function
4017 where the condition makes sense triggers the
4018 watchpoint. This allows an expression like "watch
4019 global if q > 10" set in `func', catch writes to
4020 global on all threads that call `func', or catch
4021 writes on all recursive calls of `func' by a single
4022 thread. We simply always evaluate the condition in
4023 the innermost frame that's executing where it makes
4024 sense to evaluate the condition. It seems
4026 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
4028 select_frame (frame
);
4030 within_current_scope
= 0;
4032 if (within_current_scope
)
4034 = catch_errors (breakpoint_cond_eval
, cond
,
4035 "Error in testing breakpoint condition:\n",
4039 warning (_("Watchpoint condition cannot be tested "
4040 "in the current scope"));
4041 /* If we failed to set the right context for this
4042 watchpoint, unconditionally report it. */
4045 /* FIXME-someday, should give breakpoint # */
4046 value_free_to_mark (mark
);
4049 if (cond
&& value_is_zero
)
4053 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4057 else if (b
->ignore_count
> 0)
4060 annotate_ignore_count_change ();
4062 /* Increase the hit count even though we don't
4070 /* Get a bpstat associated with having just stopped at address
4071 BP_ADDR in thread PTID.
4073 Determine whether we stopped at a breakpoint, etc, or whether we
4074 don't understand this stop. Result is a chain of bpstat's such that:
4076 if we don't understand the stop, the result is a null pointer.
4078 if we understand why we stopped, the result is not null.
4080 Each element of the chain refers to a particular breakpoint or
4081 watchpoint at which we have stopped. (We may have stopped for
4082 several reasons concurrently.)
4084 Each element of the chain has valid next, breakpoint_at,
4085 commands, FIXME??? fields. */
4088 bpstat_stop_status (struct address_space
*aspace
,
4089 CORE_ADDR bp_addr
, ptid_t ptid
)
4091 struct breakpoint
*b
= NULL
;
4092 struct bp_location
*bl
;
4093 struct bp_location
*loc
;
4094 /* First item of allocated bpstat's. */
4095 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4096 /* Pointer to the last thing in the chain currently. */
4099 int need_remove_insert
;
4102 /* First, build the bpstat chain with locations that explain a
4103 target stop, while being careful to not set the target running,
4104 as that may invalidate locations (in particular watchpoint
4105 locations are recreated). Resuming will happen here with
4106 breakpoint conditions or watchpoint expressions that include
4107 inferior function calls. */
4111 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4114 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4116 /* For hardware watchpoints, we look only at the first location.
4117 The watchpoint_check function will work on the entire expression,
4118 not the individual locations. For read watchpoints, the
4119 watchpoints_triggered function has checked all locations
4121 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4124 if (bl
->shlib_disabled
)
4127 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4130 /* Come here if it's a watchpoint, or if the break address matches */
4132 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to explain stop */
4134 /* Assume we stop. Should we find a watchpoint that is not
4135 actually triggered, or if the condition of the breakpoint
4136 evaluates as false, we'll reset 'stop' to 0. */
4140 /* If this is a scope breakpoint, mark the associated
4141 watchpoint as triggered so that we will handle the
4142 out-of-scope event. We'll get to the watchpoint next
4144 if (b
->type
== bp_watchpoint_scope
)
4145 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4149 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4151 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4154 bs
= bpstat_alloc (loc
, &bs_link
);
4155 /* For hits of moribund locations, we should just proceed. */
4158 bs
->print_it
= print_it_noop
;
4162 /* Now go through the locations that caused the target to stop, and
4163 check whether we're interested in reporting this stop to higher
4164 layers, or whether we should resume the target transparently. */
4168 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4173 bpstat_check_watchpoint (bs
);
4177 b
= bs
->breakpoint_at
;
4179 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4180 || b
->type
== bp_longjmp_master
4181 || b
->type
== bp_std_terminate_master
4182 || b
->type
== bp_exception_master
)
4183 /* We do not stop for these. */
4186 bpstat_check_breakpoint_conditions (bs
, ptid
);
4192 /* We will stop here */
4193 if (b
->disposition
== disp_disable
)
4195 if (b
->enable_state
!= bp_permanent
)
4196 b
->enable_state
= bp_disabled
;
4201 bs
->commands
= b
->commands
;
4202 incref_counted_command_line (bs
->commands
);
4203 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4204 if (bs
->commands_left
4205 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4208 bs
->commands_left
->line
) == 0)))
4210 bs
->commands_left
= bs
->commands_left
->next
;
4215 /* Print nothing for this entry if we dont stop or dont print. */
4216 if (bs
->stop
== 0 || bs
->print
== 0)
4217 bs
->print_it
= print_it_noop
;
4220 /* If we aren't stopping, the value of some hardware watchpoint may
4221 not have changed, but the intermediate memory locations we are
4222 watching may have. Don't bother if we're stopping; this will get
4224 need_remove_insert
= 0;
4225 if (! bpstat_causes_stop (bs_head
))
4226 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4228 && bs
->breakpoint_at
4229 && is_hardware_watchpoint (bs
->breakpoint_at
))
4231 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4232 need_remove_insert
= 1;
4235 if (need_remove_insert
)
4236 update_global_location_list (1);
4237 else if (removed_any
)
4238 update_global_location_list (0);
4244 handle_jit_event (void)
4246 struct frame_info
*frame
;
4247 struct gdbarch
*gdbarch
;
4249 /* Switch terminal for any messages produced by
4250 breakpoint_re_set. */
4251 target_terminal_ours_for_output ();
4253 frame
= get_current_frame ();
4254 gdbarch
= get_frame_arch (frame
);
4256 jit_event_handler (gdbarch
);
4258 target_terminal_inferior ();
4261 /* Prepare WHAT final decision for infrun. */
4263 /* Decide what infrun needs to do with this bpstat. */
4266 bpstat_what (bpstat bs
)
4268 struct bpstat_what retval
;
4269 /* We need to defer calling `solib_add', as adding new symbols
4270 resets breakpoints, which in turn deletes breakpoint locations,
4271 and hence may clear unprocessed entries in the BS chain. */
4272 int shlib_event
= 0;
4275 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4276 retval
.call_dummy
= STOP_NONE
;
4277 retval
.is_longjmp
= 0;
4279 for (; bs
!= NULL
; bs
= bs
->next
)
4281 /* Extract this BS's action. After processing each BS, we check
4282 if its action overrides all we've seem so far. */
4283 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4286 if (bs
->breakpoint_at
== NULL
)
4288 /* I suspect this can happen if it was a momentary
4289 breakpoint which has since been deleted. */
4292 else if (bs
->breakpoint_at
== NULL
)
4295 bptype
= bs
->breakpoint_at
->type
;
4302 case bp_hardware_breakpoint
:
4308 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4310 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4313 this_action
= BPSTAT_WHAT_SINGLE
;
4316 case bp_hardware_watchpoint
:
4317 case bp_read_watchpoint
:
4318 case bp_access_watchpoint
:
4322 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4324 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4328 /* There was a watchpoint, but we're not stopping.
4329 This requires no further action. */
4334 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4335 retval
.is_longjmp
= bptype
== bp_longjmp
;
4337 case bp_longjmp_resume
:
4338 case bp_exception_resume
:
4339 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4340 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4342 case bp_step_resume
:
4344 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4347 /* It is for the wrong frame. */
4348 this_action
= BPSTAT_WHAT_SINGLE
;
4351 case bp_watchpoint_scope
:
4352 case bp_thread_event
:
4353 case bp_overlay_event
:
4354 case bp_longjmp_master
:
4355 case bp_std_terminate_master
:
4356 case bp_exception_master
:
4357 this_action
= BPSTAT_WHAT_SINGLE
;
4363 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4365 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4369 /* There was a catchpoint, but we're not stopping.
4370 This requires no further action. */
4373 case bp_shlib_event
:
4376 /* If requested, stop when the dynamic linker notifies GDB
4377 of events. This allows the user to get control and place
4378 breakpoints in initializer routines for dynamically
4379 loaded objects (among other things). */
4380 if (stop_on_solib_events
)
4381 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4383 this_action
= BPSTAT_WHAT_SINGLE
;
4387 this_action
= BPSTAT_WHAT_SINGLE
;
4390 /* Make sure the action is stop (silent or noisy),
4391 so infrun.c pops the dummy frame. */
4392 retval
.call_dummy
= STOP_STACK_DUMMY
;
4393 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4395 case bp_std_terminate
:
4396 /* Make sure the action is stop (silent or noisy),
4397 so infrun.c pops the dummy frame. */
4398 retval
.call_dummy
= STOP_STD_TERMINATE
;
4399 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4402 case bp_fast_tracepoint
:
4403 case bp_static_tracepoint
:
4404 /* Tracepoint hits should not be reported back to GDB, and
4405 if one got through somehow, it should have been filtered
4407 internal_error (__FILE__
, __LINE__
,
4408 _("bpstat_what: tracepoint encountered"));
4410 internal_error (__FILE__
, __LINE__
,
4411 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4414 retval
.main_action
= max (retval
.main_action
, this_action
);
4420 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4422 /* Check for any newly added shared libraries if we're supposed
4423 to be adding them automatically. */
4425 /* Switch terminal for any messages produced by
4426 breakpoint_re_set. */
4427 target_terminal_ours_for_output ();
4430 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4432 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4435 target_terminal_inferior ();
4441 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4443 handle_jit_event ();
4449 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4450 without hardware support). This isn't related to a specific bpstat,
4451 just to things like whether watchpoints are set. */
4454 bpstat_should_step (void)
4456 struct breakpoint
*b
;
4459 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4465 bpstat_causes_stop (bpstat bs
)
4467 for (; bs
!= NULL
; bs
= bs
->next
)
4476 /* Print the LOC location out of the list of B->LOC locations. */
4478 static void print_breakpoint_location (struct breakpoint
*b
,
4479 struct bp_location
*loc
,
4481 struct ui_stream
*stb
)
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
->source_file
&& loc
)
4494 = find_pc_sect_function (loc
->address
, loc
->section
);
4497 ui_out_text (uiout
, "in ");
4498 ui_out_field_string (uiout
, "func",
4499 SYMBOL_PRINT_NAME (sym
));
4500 ui_out_wrap_hint (uiout
, wrap_indent
);
4501 ui_out_text (uiout
, " at ");
4503 ui_out_field_string (uiout
, "file", b
->source_file
);
4504 ui_out_text (uiout
, ":");
4506 if (ui_out_is_mi_like_p (uiout
))
4508 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4509 char *fullname
= symtab_to_fullname (sal
.symtab
);
4512 ui_out_field_string (uiout
, "fullname", fullname
);
4515 ui_out_field_int (uiout
, "line", b
->line_number
);
4519 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4521 ui_out_field_stream (uiout
, "at", stb
);
4524 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4526 do_cleanups (old_chain
);
4530 bptype_string (enum bptype type
)
4532 struct ep_type_description
4537 static struct ep_type_description bptypes
[] =
4539 {bp_none
, "?deleted?"},
4540 {bp_breakpoint
, "breakpoint"},
4541 {bp_hardware_breakpoint
, "hw breakpoint"},
4542 {bp_until
, "until"},
4543 {bp_finish
, "finish"},
4544 {bp_watchpoint
, "watchpoint"},
4545 {bp_hardware_watchpoint
, "hw watchpoint"},
4546 {bp_read_watchpoint
, "read watchpoint"},
4547 {bp_access_watchpoint
, "acc watchpoint"},
4548 {bp_longjmp
, "longjmp"},
4549 {bp_longjmp_resume
, "longjmp resume"},
4550 {bp_exception
, "exception"},
4551 {bp_exception_resume
, "exception resume"},
4552 {bp_step_resume
, "step resume"},
4553 {bp_watchpoint_scope
, "watchpoint scope"},
4554 {bp_call_dummy
, "call dummy"},
4555 {bp_std_terminate
, "std::terminate"},
4556 {bp_shlib_event
, "shlib events"},
4557 {bp_thread_event
, "thread events"},
4558 {bp_overlay_event
, "overlay events"},
4559 {bp_longjmp_master
, "longjmp master"},
4560 {bp_std_terminate_master
, "std::terminate master"},
4561 {bp_exception_master
, "exception master"},
4562 {bp_catchpoint
, "catchpoint"},
4563 {bp_tracepoint
, "tracepoint"},
4564 {bp_fast_tracepoint
, "fast tracepoint"},
4565 {bp_static_tracepoint
, "static tracepoint"},
4566 {bp_jit_event
, "jit events"},
4569 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4570 || ((int) type
!= bptypes
[(int) type
].type
))
4571 internal_error (__FILE__
, __LINE__
,
4572 _("bptypes table does not describe type #%d."),
4575 return bptypes
[(int) type
].description
;
4578 /* Print B to gdb_stdout. */
4581 print_one_breakpoint_location (struct breakpoint
*b
,
4582 struct bp_location
*loc
,
4584 struct bp_location
**last_loc
,
4585 int print_address_bits
,
4588 struct command_line
*l
;
4589 static char bpenables
[] = "nynny";
4590 char wrap_indent
[80];
4591 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4592 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4593 struct cleanup
*bkpt_chain
;
4595 int header_of_multiple
= 0;
4596 int part_of_multiple
= (loc
!= NULL
);
4597 struct value_print_options opts
;
4599 get_user_print_options (&opts
);
4601 gdb_assert (!loc
|| loc_number
!= 0);
4602 /* See comment in print_one_breakpoint concerning
4603 treatment of breakpoints with single disabled
4607 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4608 header_of_multiple
= 1;
4613 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4617 if (part_of_multiple
)
4620 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4621 ui_out_field_string (uiout
, "number", formatted
);
4626 ui_out_field_int (uiout
, "number", b
->number
);
4631 if (part_of_multiple
)
4632 ui_out_field_skip (uiout
, "type");
4634 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4638 if (part_of_multiple
)
4639 ui_out_field_skip (uiout
, "disp");
4641 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4646 if (part_of_multiple
)
4647 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4649 ui_out_field_fmt (uiout
, "enabled", "%c",
4650 bpenables
[(int) b
->enable_state
]);
4651 ui_out_spaces (uiout
, 2);
4655 strcpy (wrap_indent
, " ");
4656 if (opts
.addressprint
)
4658 if (print_address_bits
<= 32)
4659 strcat (wrap_indent
, " ");
4661 strcat (wrap_indent
, " ");
4664 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4666 /* Although the print_one can possibly print
4667 all locations, calling it here is not likely
4668 to get any nice result. So, make sure there's
4669 just one location. */
4670 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4671 b
->ops
->print_one (b
, last_loc
);
4677 internal_error (__FILE__
, __LINE__
,
4678 _("print_one_breakpoint: bp_none encountered\n"));
4682 case bp_hardware_watchpoint
:
4683 case bp_read_watchpoint
:
4684 case bp_access_watchpoint
:
4685 /* Field 4, the address, is omitted (which makes the columns
4686 not line up too nicely with the headers, but the effect
4687 is relatively readable). */
4688 if (opts
.addressprint
)
4689 ui_out_field_skip (uiout
, "addr");
4691 ui_out_field_string (uiout
, "what", b
->exp_string
);
4695 case bp_hardware_breakpoint
:
4699 case bp_longjmp_resume
:
4701 case bp_exception_resume
:
4702 case bp_step_resume
:
4703 case bp_watchpoint_scope
:
4705 case bp_std_terminate
:
4706 case bp_shlib_event
:
4707 case bp_thread_event
:
4708 case bp_overlay_event
:
4709 case bp_longjmp_master
:
4710 case bp_std_terminate_master
:
4711 case bp_exception_master
:
4713 case bp_fast_tracepoint
:
4714 case bp_static_tracepoint
:
4716 if (opts
.addressprint
)
4719 if (header_of_multiple
)
4720 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4721 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4722 ui_out_field_string (uiout
, "addr", "<PENDING>");
4724 ui_out_field_core_addr (uiout
, "addr",
4725 loc
->gdbarch
, loc
->address
);
4728 if (!header_of_multiple
)
4729 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4736 /* For backward compatibility, don't display inferiors unless there
4739 && !header_of_multiple
4741 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4742 && (number_of_program_spaces () > 1
4743 || number_of_inferiors () > 1)
4744 /* LOC is for existing B, it cannot be in moribund_locations and
4745 thus having NULL OWNER. */
4746 && loc
->owner
->type
!= bp_catchpoint
)))
4748 struct inferior
*inf
;
4751 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4753 if (inf
->pspace
== loc
->pspace
)
4758 ui_out_text (uiout
, " inf ");
4761 ui_out_text (uiout
, ", ");
4762 ui_out_text (uiout
, plongest (inf
->num
));
4767 if (!part_of_multiple
)
4769 if (b
->thread
!= -1)
4771 /* FIXME: This seems to be redundant and lost here; see the
4772 "stop only in" line a little further down. */
4773 ui_out_text (uiout
, " thread ");
4774 ui_out_field_int (uiout
, "thread", b
->thread
);
4776 else if (b
->task
!= 0)
4778 ui_out_text (uiout
, " task ");
4779 ui_out_field_int (uiout
, "task", b
->task
);
4783 ui_out_text (uiout
, "\n");
4785 if (!part_of_multiple
&& b
->static_trace_marker_id
)
4787 gdb_assert (b
->type
== bp_static_tracepoint
);
4789 ui_out_text (uiout
, "\tmarker id is ");
4790 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
4791 b
->static_trace_marker_id
);
4792 ui_out_text (uiout
, "\n");
4795 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4798 ui_out_text (uiout
, "\tstop only in stack frame at ");
4799 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4801 ui_out_field_core_addr (uiout
, "frame",
4802 b
->gdbarch
, b
->frame_id
.stack_addr
);
4803 ui_out_text (uiout
, "\n");
4806 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4808 /* We do not print the condition for Ada exception catchpoints
4809 because the condition is an internal implementation detail
4810 that we do not want to expose to the user. */
4812 if (is_tracepoint (b
))
4813 ui_out_text (uiout
, "\ttrace only if ");
4815 ui_out_text (uiout
, "\tstop only if ");
4816 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4817 ui_out_text (uiout
, "\n");
4820 if (!part_of_multiple
&& b
->thread
!= -1)
4822 /* FIXME should make an annotation for this */
4823 ui_out_text (uiout
, "\tstop only in thread ");
4824 ui_out_field_int (uiout
, "thread", b
->thread
);
4825 ui_out_text (uiout
, "\n");
4828 if (!part_of_multiple
&& b
->hit_count
)
4830 /* FIXME should make an annotation for this */
4831 if (ep_is_catchpoint (b
))
4832 ui_out_text (uiout
, "\tcatchpoint");
4834 ui_out_text (uiout
, "\tbreakpoint");
4835 ui_out_text (uiout
, " already hit ");
4836 ui_out_field_int (uiout
, "times", b
->hit_count
);
4837 if (b
->hit_count
== 1)
4838 ui_out_text (uiout
, " time\n");
4840 ui_out_text (uiout
, " times\n");
4843 /* Output the count also if it is zero, but only if this is
4844 mi. FIXME: Should have a better test for this. */
4845 if (ui_out_is_mi_like_p (uiout
))
4846 if (!part_of_multiple
&& b
->hit_count
== 0)
4847 ui_out_field_int (uiout
, "times", b
->hit_count
);
4849 if (!part_of_multiple
&& b
->ignore_count
)
4852 ui_out_text (uiout
, "\tignore next ");
4853 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4854 ui_out_text (uiout
, " hits\n");
4857 l
= b
->commands
? b
->commands
->commands
: NULL
;
4858 if (!part_of_multiple
&& l
)
4860 struct cleanup
*script_chain
;
4863 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4864 print_command_lines (uiout
, l
, 4);
4865 do_cleanups (script_chain
);
4868 if (!part_of_multiple
&& b
->pass_count
)
4870 annotate_field (10);
4871 ui_out_text (uiout
, "\tpass count ");
4872 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4873 ui_out_text (uiout
, " \n");
4876 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4879 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4880 else if (b
->exp_string
)
4881 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4884 do_cleanups (bkpt_chain
);
4885 do_cleanups (old_chain
);
4889 print_one_breakpoint (struct breakpoint
*b
,
4890 struct bp_location
**last_loc
, int print_address_bits
,
4893 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4894 print_address_bits
, allflag
);
4896 /* If this breakpoint has custom print function,
4897 it's already printed. Otherwise, print individual
4898 locations, if any. */
4899 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4901 /* If breakpoint has a single location that is
4902 disabled, we print it as if it had
4903 several locations, since otherwise it's hard to
4904 represent "breakpoint enabled, location disabled"
4906 Note that while hardware watchpoints have
4907 several locations internally, that's no a property
4910 && !is_hardware_watchpoint (b
)
4911 && (b
->loc
->next
|| !b
->loc
->enabled
)
4912 && !ui_out_is_mi_like_p (uiout
))
4914 struct bp_location
*loc
;
4916 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4917 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4918 print_address_bits
, allflag
);
4924 breakpoint_address_bits (struct breakpoint
*b
)
4926 int print_address_bits
= 0;
4927 struct bp_location
*loc
;
4929 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4933 /* Software watchpoints that aren't watching memory don't have
4934 an address to print. */
4935 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4938 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4939 if (addr_bit
> print_address_bits
)
4940 print_address_bits
= addr_bit
;
4943 return print_address_bits
;
4946 struct captured_breakpoint_query_args
4952 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4954 struct captured_breakpoint_query_args
*args
= data
;
4955 struct breakpoint
*b
;
4956 struct bp_location
*dummy_loc
= NULL
;
4960 if (args
->bnum
== b
->number
)
4962 int print_address_bits
= breakpoint_address_bits (b
);
4964 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4972 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4974 struct captured_breakpoint_query_args args
;
4977 /* For the moment we don't trust print_one_breakpoint() to not throw
4979 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4980 error_message
, RETURN_MASK_ALL
) < 0)
4986 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4987 catchpoints, et.al.). */
4990 user_settable_breakpoint (const struct breakpoint
*b
)
4992 return (b
->type
== bp_breakpoint
4993 || b
->type
== bp_catchpoint
4994 || b
->type
== bp_hardware_breakpoint
4995 || is_tracepoint (b
)
4996 || is_watchpoint (b
));
4999 /* Print information on user settable breakpoint (watchpoint, etc)
5000 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5001 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5002 FILTER is non-NULL, call it on each breakpoint and only include the
5003 ones for which it returns non-zero. Return the total number of
5004 breakpoints listed. */
5007 breakpoint_1 (int bnum
, int allflag
, 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
5020 size required for address fields. */
5021 nr_printable_breakpoints
= 0;
5024 || bnum
== b
->number
)
5026 /* If we have a filter, only list the breakpoints it accepts. */
5027 if (filter
&& !filter (b
))
5030 if (allflag
|| (user_settable_breakpoint (b
)
5033 int addr_bit
, type_len
;
5035 addr_bit
= breakpoint_address_bits (b
);
5036 if (addr_bit
> print_address_bits
)
5037 print_address_bits
= addr_bit
;
5039 type_len
= strlen (bptype_string (b
->type
));
5040 if (type_len
> print_type_col_width
)
5041 print_type_col_width
= type_len
;
5043 nr_printable_breakpoints
++;
5047 if (opts
.addressprint
)
5049 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
5053 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
5056 if (nr_printable_breakpoints
> 0)
5057 annotate_breakpoints_headers ();
5058 if (nr_printable_breakpoints
> 0)
5060 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5061 if (nr_printable_breakpoints
> 0)
5063 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5064 "type", "Type"); /* 2 */
5065 if (nr_printable_breakpoints
> 0)
5067 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5068 if (nr_printable_breakpoints
> 0)
5070 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5071 if (opts
.addressprint
)
5073 if (nr_printable_breakpoints
> 0)
5075 if (print_address_bits
<= 32)
5076 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
5078 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
5080 if (nr_printable_breakpoints
> 0)
5082 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5083 ui_out_table_body (uiout
);
5084 if (nr_printable_breakpoints
> 0)
5085 annotate_breakpoints_table ();
5091 || bnum
== b
->number
)
5093 /* If we have a filter, only list the breakpoints it accepts. */
5094 if (filter
&& !filter (b
))
5097 /* We only print out user settable breakpoints unless the
5099 if (allflag
|| (user_settable_breakpoint (b
)
5101 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5105 do_cleanups (bkpttbl_chain
);
5107 if (nr_printable_breakpoints
== 0)
5109 /* If there's a filter, let the caller decide how to report empty list. */
5113 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5115 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5121 if (last_loc
&& !server_command
)
5122 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5125 /* FIXME? Should this be moved up so that it is only called when
5126 there have been breakpoints? */
5127 annotate_breakpoints_table_end ();
5129 return nr_printable_breakpoints
;
5132 /* Display the value of default-collect in a way that is generally
5133 compatible with the breakpoint list. */
5136 default_collect_info (void)
5138 /* If it has no value (which is frequently the case), say nothing; a
5139 message like "No default-collect." gets in user's face when it's
5141 if (!*default_collect
)
5144 /* The following phrase lines up nicely with per-tracepoint collect
5146 ui_out_text (uiout
, "default collect ");
5147 ui_out_field_string (uiout
, "default-collect", default_collect
);
5148 ui_out_text (uiout
, " \n");
5152 breakpoints_info (char *bnum_exp
, int from_tty
)
5157 bnum
= parse_and_eval_long (bnum_exp
);
5159 breakpoint_1 (bnum
, 0, NULL
);
5161 default_collect_info ();
5165 watchpoints_info (char *wpnum_exp
, int from_tty
)
5167 int wpnum
= -1, num_printed
;
5170 wpnum
= parse_and_eval_long (wpnum_exp
);
5172 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5174 if (num_printed
== 0)
5177 ui_out_message (uiout
, 0, "No watchpoints.\n");
5179 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5184 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5189 bnum
= parse_and_eval_long (bnum_exp
);
5191 breakpoint_1 (bnum
, 1, NULL
);
5193 default_collect_info ();
5197 breakpoint_has_pc (struct breakpoint
*b
,
5198 struct program_space
*pspace
,
5199 CORE_ADDR pc
, struct obj_section
*section
)
5201 struct bp_location
*bl
= b
->loc
;
5203 for (; bl
; bl
= bl
->next
)
5205 if (bl
->pspace
== pspace
5206 && bl
->address
== pc
5207 && (!overlay_debugging
|| bl
->section
== section
))
5213 /* Print a message describing any breakpoints set at PC. This
5214 concerns with logical breakpoints, so we match program spaces, not
5218 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5219 struct program_space
*pspace
, CORE_ADDR pc
,
5220 struct obj_section
*section
, int thread
)
5223 struct breakpoint
*b
;
5226 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5230 printf_filtered (_("Note: breakpoint "));
5231 else /* if (others == ???) */
5232 printf_filtered (_("Note: breakpoints "));
5234 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5237 printf_filtered ("%d", b
->number
);
5238 if (b
->thread
== -1 && thread
!= -1)
5239 printf_filtered (" (all threads)");
5240 else if (b
->thread
!= -1)
5241 printf_filtered (" (thread %d)", b
->thread
);
5242 printf_filtered ("%s%s ",
5243 ((b
->enable_state
== bp_disabled
5244 || b
->enable_state
== bp_call_disabled
5245 || b
->enable_state
== bp_startup_disabled
)
5247 : b
->enable_state
== bp_permanent
5251 : ((others
== 1) ? " and" : ""));
5253 printf_filtered (_("also set at pc "));
5254 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5255 printf_filtered (".\n");
5259 /* Set the default place to put a breakpoint
5260 for the `break' command with no arguments. */
5263 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5264 CORE_ADDR addr
, struct symtab
*symtab
,
5267 default_breakpoint_valid
= valid
;
5268 default_breakpoint_pspace
= pspace
;
5269 default_breakpoint_address
= addr
;
5270 default_breakpoint_symtab
= symtab
;
5271 default_breakpoint_line
= line
;
5274 /* Return true iff it is meaningful to use the address member of
5275 BPT. For some breakpoint types, the address member is irrelevant
5276 and it makes no sense to attempt to compare it to other addresses
5277 (or use it for any other purpose either).
5279 More specifically, each of the following breakpoint types will always
5280 have a zero valued address and we don't want to mark breakpoints of any of
5281 these types to be a duplicate of an actual breakpoint at address zero:
5289 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5291 enum bptype type
= bpt
->type
;
5293 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5296 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5297 true if LOC1 and LOC2 represent the same watchpoint location. */
5300 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5302 /* Both of them must not be in moribund_locations. */
5303 gdb_assert (loc1
->owner
!= NULL
);
5304 gdb_assert (loc2
->owner
!= NULL
);
5306 /* If the target can evaluate the condition expression in hardware, then we
5307 we need to insert both watchpoints even if they are at the same place.
5308 Otherwise the watchpoint will only trigger when the condition of whichever
5309 watchpoint was inserted evaluates to true, not giving a chance for GDB to
5310 check the condition of the other watchpoint. */
5311 if ((loc1
->owner
->cond_exp
5312 && target_can_accel_watchpoint_condition (loc1
->address
, loc1
->length
,
5313 loc1
->watchpoint_type
,
5314 loc1
->owner
->cond_exp
))
5315 || (loc2
->owner
->cond_exp
5316 && target_can_accel_watchpoint_condition (loc2
->address
, loc2
->length
,
5317 loc2
->watchpoint_type
,
5318 loc2
->owner
->cond_exp
)))
5321 /* Note that this checks the owner's type, not the location's. In
5322 case the target does not support read watchpoints, but does
5323 support access watchpoints, we'll have bp_read_watchpoint
5324 watchpoints with hw_access locations. Those should be considered
5325 duplicates of hw_read locations. The hw_read locations will
5326 become hw_access locations later. */
5327 return (loc1
->owner
->type
== loc2
->owner
->type
5328 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5329 && loc1
->address
== loc2
->address
5330 && loc1
->length
== loc2
->length
);
5333 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5334 same breakpoint location. In most targets, this can only be true
5335 if ASPACE1 matches ASPACE2. On targets that have global
5336 breakpoints, the address space doesn't really matter. */
5339 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5340 struct address_space
*aspace2
, CORE_ADDR addr2
)
5342 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5343 || aspace1
== aspace2
)
5347 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5348 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5349 represent the same location. */
5352 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5354 int hw_point1
, hw_point2
;
5356 /* Both of them must not be in moribund_locations. */
5357 gdb_assert (loc1
->owner
!= NULL
);
5358 gdb_assert (loc2
->owner
!= NULL
);
5360 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5361 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5363 if (hw_point1
!= hw_point2
)
5366 return watchpoint_locations_match (loc1
, loc2
);
5368 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5369 loc2
->pspace
->aspace
, loc2
->address
);
5373 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5374 int bnum
, int have_bnum
)
5379 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5380 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5382 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5383 bnum
, astr1
, astr2
);
5385 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5388 /* Adjust a breakpoint's address to account for architectural constraints
5389 on breakpoint placement. Return the adjusted address. Note: Very
5390 few targets require this kind of adjustment. For most targets,
5391 this function is simply the identity function. */
5394 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5395 CORE_ADDR bpaddr
, enum bptype bptype
)
5397 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5399 /* Very few targets need any kind of breakpoint adjustment. */
5402 else if (bptype
== bp_watchpoint
5403 || bptype
== bp_hardware_watchpoint
5404 || bptype
== bp_read_watchpoint
5405 || bptype
== bp_access_watchpoint
5406 || bptype
== bp_catchpoint
)
5408 /* Watchpoints and the various bp_catch_* eventpoints should not
5409 have their addresses modified. */
5414 CORE_ADDR adjusted_bpaddr
;
5416 /* Some targets have architectural constraints on the placement
5417 of breakpoint instructions. Obtain the adjusted address. */
5418 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5420 /* An adjusted breakpoint address can significantly alter
5421 a user's expectations. Print a warning if an adjustment
5423 if (adjusted_bpaddr
!= bpaddr
)
5424 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5426 return adjusted_bpaddr
;
5430 /* Allocate a struct bp_location. */
5432 static struct bp_location
*
5433 allocate_bp_location (struct breakpoint
*bpt
)
5435 struct bp_location
*loc
;
5437 loc
= xmalloc (sizeof (struct bp_location
));
5438 memset (loc
, 0, sizeof (*loc
));
5442 loc
->shlib_disabled
= 0;
5451 case bp_longjmp_resume
:
5453 case bp_exception_resume
:
5454 case bp_step_resume
:
5455 case bp_watchpoint_scope
:
5457 case bp_std_terminate
:
5458 case bp_shlib_event
:
5459 case bp_thread_event
:
5460 case bp_overlay_event
:
5462 case bp_longjmp_master
:
5463 case bp_std_terminate_master
:
5464 case bp_exception_master
:
5465 loc
->loc_type
= bp_loc_software_breakpoint
;
5467 case bp_hardware_breakpoint
:
5468 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5470 case bp_hardware_watchpoint
:
5471 case bp_read_watchpoint
:
5472 case bp_access_watchpoint
:
5473 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5478 case bp_fast_tracepoint
:
5479 case bp_static_tracepoint
:
5480 loc
->loc_type
= bp_loc_other
;
5483 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5491 free_bp_location (struct bp_location
*loc
)
5496 if (loc
->function_name
)
5497 xfree (loc
->function_name
);
5502 /* Increment reference count. */
5505 incref_bp_location (struct bp_location
*bl
)
5510 /* Decrement reference count. If the reference count reaches 0,
5511 destroy the bp_location. Sets *BLP to NULL. */
5514 decref_bp_location (struct bp_location
**blp
)
5516 gdb_assert ((*blp
)->refc
> 0);
5518 if (--(*blp
)->refc
== 0)
5519 free_bp_location (*blp
);
5523 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5524 that has type BPTYPE and has no locations as yet. */
5525 /* This function is used in gdbtk sources and thus can not be made static. */
5527 static struct breakpoint
*
5528 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5531 struct breakpoint
*b
, *b1
;
5533 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5534 memset (b
, 0, sizeof (*b
));
5537 b
->gdbarch
= gdbarch
;
5538 b
->language
= current_language
->la_language
;
5539 b
->input_radix
= input_radix
;
5541 b
->enable_state
= bp_enabled
;
5544 b
->ignore_count
= 0;
5546 b
->frame_id
= null_frame_id
;
5547 b
->forked_inferior_pid
= null_ptid
;
5548 b
->exec_pathname
= NULL
;
5549 b
->syscalls_to_be_caught
= NULL
;
5551 b
->condition_not_parsed
= 0;
5552 b
->py_bp_object
= NULL
;
5554 /* Add this breakpoint to the end of the chain
5555 so that a list of breakpoints will come out in order
5556 of increasing numbers. */
5558 b1
= breakpoint_chain
;
5560 breakpoint_chain
= b
;
5570 /* Initialize loc->function_name. */
5572 set_breakpoint_location_function (struct bp_location
*loc
)
5574 gdb_assert (loc
->owner
!= NULL
);
5576 if (loc
->owner
->type
== bp_breakpoint
5577 || loc
->owner
->type
== bp_hardware_breakpoint
5578 || is_tracepoint (loc
->owner
))
5580 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5582 if (loc
->function_name
)
5583 loc
->function_name
= xstrdup (loc
->function_name
);
5587 /* Attempt to determine architecture of location identified by SAL. */
5588 static struct gdbarch
*
5589 get_sal_arch (struct symtab_and_line sal
)
5592 return get_objfile_arch (sal
.section
->objfile
);
5594 return get_objfile_arch (sal
.symtab
->objfile
);
5599 /* set_raw_breakpoint is a low level routine for allocating and
5600 partially initializing a breakpoint of type BPTYPE. The newly
5601 created breakpoint's address, section, source file name, and line
5602 number are provided by SAL. The newly created and partially
5603 initialized breakpoint is added to the breakpoint chain and
5604 is also returned as the value of this function.
5606 It is expected that the caller will complete the initialization of
5607 the newly created breakpoint struct as well as output any status
5608 information regarding the creation of a new breakpoint. In
5609 particular, set_raw_breakpoint does NOT set the breakpoint
5610 number! Care should be taken to not allow an error to occur
5611 prior to completing the initialization of the breakpoint. If this
5612 should happen, a bogus breakpoint will be left on the chain. */
5615 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5616 struct symtab_and_line sal
, enum bptype bptype
)
5618 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5619 CORE_ADDR adjusted_address
;
5620 struct gdbarch
*loc_gdbarch
;
5622 loc_gdbarch
= get_sal_arch (sal
);
5624 loc_gdbarch
= b
->gdbarch
;
5626 if (bptype
!= bp_catchpoint
)
5627 gdb_assert (sal
.pspace
!= NULL
);
5629 /* Adjust the breakpoint's address prior to allocating a location.
5630 Once we call allocate_bp_location(), that mostly uninitialized
5631 location will be placed on the location chain. Adjustment of the
5632 breakpoint may cause target_read_memory() to be called and we do
5633 not want its scan of the location chain to find a breakpoint and
5634 location that's only been partially initialized. */
5635 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5637 b
->loc
= allocate_bp_location (b
);
5638 b
->loc
->gdbarch
= loc_gdbarch
;
5639 b
->loc
->requested_address
= sal
.pc
;
5640 b
->loc
->address
= adjusted_address
;
5641 b
->loc
->pspace
= sal
.pspace
;
5643 /* Store the program space that was used to set the breakpoint, for
5644 breakpoint resetting. */
5645 b
->pspace
= sal
.pspace
;
5647 if (sal
.symtab
== NULL
)
5648 b
->source_file
= NULL
;
5650 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5651 b
->loc
->section
= sal
.section
;
5652 b
->line_number
= sal
.line
;
5654 set_breakpoint_location_function (b
->loc
);
5656 breakpoints_changed ();
5662 /* Note that the breakpoint object B describes a permanent breakpoint
5663 instruction, hard-wired into the inferior's code. */
5665 make_breakpoint_permanent (struct breakpoint
*b
)
5667 struct bp_location
*bl
;
5669 b
->enable_state
= bp_permanent
;
5671 /* By definition, permanent breakpoints are already present in the code.
5672 Mark all locations as inserted. For now, make_breakpoint_permanent
5673 is called in just one place, so it's hard to say if it's reasonable
5674 to have permanent breakpoint with multiple locations or not,
5675 but it's easy to implmement. */
5676 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5680 /* Call this routine when stepping and nexting to enable a breakpoint
5681 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5682 initiated the operation. */
5685 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5687 struct breakpoint
*b
, *b_tmp
;
5688 int thread
= tp
->num
;
5690 /* To avoid having to rescan all objfile symbols at every step,
5691 we maintain a list of continually-inserted but always disabled
5692 longjmp "master" breakpoints. Here, we simply create momentary
5693 clones of those and enable them for the requested thread. */
5694 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5695 if (b
->pspace
== current_program_space
5696 && (b
->type
== bp_longjmp_master
5697 || b
->type
== bp_exception_master
))
5699 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5701 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5702 clone
->thread
= thread
;
5705 tp
->initiating_frame
= frame
;
5708 /* Delete all longjmp breakpoints from THREAD. */
5710 delete_longjmp_breakpoint (int thread
)
5712 struct breakpoint
*b
, *b_tmp
;
5714 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5715 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5717 if (b
->thread
== thread
)
5718 delete_breakpoint (b
);
5723 enable_overlay_breakpoints (void)
5725 struct breakpoint
*b
;
5728 if (b
->type
== bp_overlay_event
)
5730 b
->enable_state
= bp_enabled
;
5731 update_global_location_list (1);
5732 overlay_events_enabled
= 1;
5737 disable_overlay_breakpoints (void)
5739 struct breakpoint
*b
;
5742 if (b
->type
== bp_overlay_event
)
5744 b
->enable_state
= bp_disabled
;
5745 update_global_location_list (0);
5746 overlay_events_enabled
= 0;
5750 /* Set an active std::terminate breakpoint for each std::terminate
5751 master breakpoint. */
5753 set_std_terminate_breakpoint (void)
5755 struct breakpoint
*b
, *b_tmp
;
5757 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5758 if (b
->pspace
== current_program_space
5759 && b
->type
== bp_std_terminate_master
)
5761 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5762 clone
->type
= bp_std_terminate
;
5766 /* Delete all the std::terminate breakpoints. */
5768 delete_std_terminate_breakpoint (void)
5770 struct breakpoint
*b
, *b_tmp
;
5772 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5773 if (b
->type
== bp_std_terminate
)
5774 delete_breakpoint (b
);
5778 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5780 struct breakpoint
*b
;
5782 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5784 b
->enable_state
= bp_enabled
;
5785 /* addr_string has to be used or breakpoint_re_set will delete me. */
5787 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5789 update_global_location_list_nothrow (1);
5795 remove_thread_event_breakpoints (void)
5797 struct breakpoint
*b
, *b_tmp
;
5799 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5800 if (b
->type
== bp_thread_event
5801 && b
->loc
->pspace
== current_program_space
)
5802 delete_breakpoint (b
);
5805 struct captured_parse_breakpoint_args
5808 struct symtabs_and_lines
*sals_p
;
5809 char ***addr_string_p
;
5813 struct lang_and_radix
5819 /* Create a breakpoint for JIT code registration and unregistration. */
5822 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5824 struct breakpoint
*b
;
5826 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5827 update_global_location_list_nothrow (1);
5832 remove_solib_event_breakpoints (void)
5834 struct breakpoint
*b
, *b_tmp
;
5836 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5837 if (b
->type
== bp_shlib_event
5838 && b
->loc
->pspace
== current_program_space
)
5839 delete_breakpoint (b
);
5843 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5845 struct breakpoint
*b
;
5847 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5848 update_global_location_list_nothrow (1);
5852 /* Disable any breakpoints that are on code in shared libraries. Only
5853 apply to enabled breakpoints, disabled ones can just stay disabled. */
5856 disable_breakpoints_in_shlibs (void)
5858 struct bp_location
*loc
, **locp_tmp
;
5860 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5862 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5863 struct breakpoint
*b
= loc
->owner
;
5865 /* We apply the check to all breakpoints, including disabled
5866 for those with loc->duplicate set. This is so that when breakpoint
5867 becomes enabled, or the duplicate is removed, gdb will try to insert
5868 all breakpoints. If we don't set shlib_disabled here, we'll try
5869 to insert those breakpoints and fail. */
5870 if (((b
->type
== bp_breakpoint
)
5871 || (b
->type
== bp_jit_event
)
5872 || (b
->type
== bp_hardware_breakpoint
)
5873 || (is_tracepoint (b
)))
5874 && loc
->pspace
== current_program_space
5875 && !loc
->shlib_disabled
5877 && PC_SOLIB (loc
->address
)
5879 && solib_name_from_address (loc
->pspace
, loc
->address
)
5883 loc
->shlib_disabled
= 1;
5888 /* Disable any breakpoints that are in in an unloaded shared library. Only
5889 apply to enabled breakpoints, disabled ones can just stay disabled. */
5892 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5894 struct bp_location
*loc
, **locp_tmp
;
5895 int disabled_shlib_breaks
= 0;
5897 /* SunOS a.out shared libraries are always mapped, so do not
5898 disable breakpoints; they will only be reported as unloaded
5899 through clear_solib when GDB discards its shared library
5900 list. See clear_solib for more information. */
5901 if (exec_bfd
!= NULL
5902 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5905 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5907 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5908 struct breakpoint
*b
= loc
->owner
;
5910 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5911 || loc
->loc_type
== bp_loc_software_breakpoint
)
5912 && solib
->pspace
== loc
->pspace
5913 && !loc
->shlib_disabled
5914 && (b
->type
== bp_breakpoint
5915 || b
->type
== bp_jit_event
5916 || b
->type
== bp_hardware_breakpoint
)
5917 && solib_contains_address_p (solib
, loc
->address
))
5919 loc
->shlib_disabled
= 1;
5920 /* At this point, we cannot rely on remove_breakpoint
5921 succeeding so we must mark the breakpoint as not inserted
5922 to prevent future errors occurring in remove_breakpoints. */
5924 if (!disabled_shlib_breaks
)
5926 target_terminal_ours_for_output ();
5927 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5930 disabled_shlib_breaks
= 1;
5935 /* FORK & VFORK catchpoints. */
5937 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5940 insert_catch_fork (struct breakpoint
*b
)
5942 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5945 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5948 remove_catch_fork (struct breakpoint
*b
)
5950 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5953 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5957 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5959 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5962 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5964 static enum print_stop_action
5965 print_it_catch_fork (struct breakpoint
*b
)
5967 annotate_catchpoint (b
->number
);
5968 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5969 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5970 return PRINT_SRC_AND_LOC
;
5973 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5976 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5978 struct value_print_options opts
;
5980 get_user_print_options (&opts
);
5982 /* Field 4, the address, is omitted (which makes the columns
5983 not line up too nicely with the headers, but the effect
5984 is relatively readable). */
5985 if (opts
.addressprint
)
5986 ui_out_field_skip (uiout
, "addr");
5988 ui_out_text (uiout
, "fork");
5989 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5991 ui_out_text (uiout
, ", process ");
5992 ui_out_field_int (uiout
, "what",
5993 ptid_get_pid (b
->forked_inferior_pid
));
5994 ui_out_spaces (uiout
, 1);
5998 /* Implement the "print_mention" breakpoint_ops method for fork
6002 print_mention_catch_fork (struct breakpoint
*b
)
6004 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6007 /* Implement the "print_recreate" breakpoint_ops method for fork
6011 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6013 fprintf_unfiltered (fp
, "catch fork");
6016 /* The breakpoint_ops structure to be used in fork catchpoints. */
6018 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6022 breakpoint_hit_catch_fork
,
6023 print_it_catch_fork
,
6024 print_one_catch_fork
,
6025 print_mention_catch_fork
,
6026 print_recreate_catch_fork
6029 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
6032 insert_catch_vfork (struct breakpoint
*b
)
6034 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6037 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
6040 remove_catch_vfork (struct breakpoint
*b
)
6042 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6045 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6049 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
6051 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
6054 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
6056 static enum print_stop_action
6057 print_it_catch_vfork (struct breakpoint
*b
)
6059 annotate_catchpoint (b
->number
);
6060 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6061 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6062 return PRINT_SRC_AND_LOC
;
6065 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
6068 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6070 struct value_print_options opts
;
6072 get_user_print_options (&opts
);
6073 /* Field 4, the address, is omitted (which makes the columns
6074 not line up too nicely with the headers, but the effect
6075 is relatively readable). */
6076 if (opts
.addressprint
)
6077 ui_out_field_skip (uiout
, "addr");
6079 ui_out_text (uiout
, "vfork");
6080 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6082 ui_out_text (uiout
, ", process ");
6083 ui_out_field_int (uiout
, "what",
6084 ptid_get_pid (b
->forked_inferior_pid
));
6085 ui_out_spaces (uiout
, 1);
6089 /* Implement the "print_mention" breakpoint_ops method for vfork
6093 print_mention_catch_vfork (struct breakpoint
*b
)
6095 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6098 /* Implement the "print_recreate" breakpoint_ops method for vfork
6102 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6104 fprintf_unfiltered (fp
, "catch vfork");
6107 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6109 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6113 breakpoint_hit_catch_vfork
,
6114 print_it_catch_vfork
,
6115 print_one_catch_vfork
,
6116 print_mention_catch_vfork
,
6117 print_recreate_catch_vfork
6120 /* Implement the "insert" breakpoint_ops method for syscall
6124 insert_catch_syscall (struct breakpoint
*b
)
6126 struct inferior
*inf
= current_inferior ();
6128 ++inf
->total_syscalls_count
;
6129 if (!b
->syscalls_to_be_caught
)
6130 ++inf
->any_syscall_count
;
6136 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6141 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6143 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6144 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
6146 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6147 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6149 memset ((void *) vec_addr
, 0,
6150 (iter
+ 1 - old_size
) * sizeof (int));
6152 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6153 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6157 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6158 inf
->total_syscalls_count
!= 0,
6159 inf
->any_syscall_count
,
6160 VEC_length (int, inf
->syscalls_counts
),
6161 VEC_address (int, inf
->syscalls_counts
));
6164 /* Implement the "remove" breakpoint_ops method for syscall
6168 remove_catch_syscall (struct breakpoint
*b
)
6170 struct inferior
*inf
= current_inferior ();
6172 --inf
->total_syscalls_count
;
6173 if (!b
->syscalls_to_be_caught
)
6174 --inf
->any_syscall_count
;
6180 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6184 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6185 /* Shouldn't happen. */
6187 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6188 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6192 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6193 inf
->total_syscalls_count
!= 0,
6194 inf
->any_syscall_count
,
6195 VEC_length (int, inf
->syscalls_counts
),
6196 VEC_address (int, inf
->syscalls_counts
));
6199 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6203 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6205 /* We must check if we are catching specific syscalls in this breakpoint.
6206 If we are, then we must guarantee that the called syscall is the same
6207 syscall we are catching. */
6208 int syscall_number
= 0;
6210 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6213 /* Now, checking if the syscall is the same. */
6214 if (b
->syscalls_to_be_caught
)
6219 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6221 if (syscall_number
== iter
)
6231 /* Implement the "print_it" breakpoint_ops method for syscall
6234 static enum print_stop_action
6235 print_it_catch_syscall (struct breakpoint
*b
)
6237 /* These are needed because we want to know in which state a
6238 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6239 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6240 must print "called syscall" or "returned from syscall". */
6242 struct target_waitstatus last
;
6244 struct cleanup
*old_chain
;
6247 get_last_target_status (&ptid
, &last
);
6249 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6251 annotate_catchpoint (b
->number
);
6254 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6256 syscall_id
= xstrprintf ("'%s'", s
.name
);
6258 old_chain
= make_cleanup (xfree
, syscall_id
);
6260 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6261 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6262 b
->number
, syscall_id
);
6263 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6264 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6265 b
->number
, syscall_id
);
6267 do_cleanups (old_chain
);
6269 return PRINT_SRC_AND_LOC
;
6272 /* Implement the "print_one" breakpoint_ops method for syscall
6276 print_one_catch_syscall (struct breakpoint
*b
,
6277 struct bp_location
**last_loc
)
6279 struct value_print_options opts
;
6281 get_user_print_options (&opts
);
6282 /* Field 4, the address, is omitted (which makes the columns
6283 not line up too nicely with the headers, but the effect
6284 is relatively readable). */
6285 if (opts
.addressprint
)
6286 ui_out_field_skip (uiout
, "addr");
6289 if (b
->syscalls_to_be_caught
6290 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6291 ui_out_text (uiout
, "syscalls \"");
6293 ui_out_text (uiout
, "syscall \"");
6295 if (b
->syscalls_to_be_caught
)
6298 char *text
= xstrprintf ("%s", "");
6301 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6306 get_syscall_by_number (iter
, &s
);
6309 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6311 text
= xstrprintf ("%s%d, ", text
, iter
);
6313 /* We have to xfree the last 'text' (now stored at 'x')
6314 because xstrprintf dinamically allocates new space for it
6318 /* Remove the last comma. */
6319 text
[strlen (text
) - 2] = '\0';
6320 ui_out_field_string (uiout
, "what", text
);
6323 ui_out_field_string (uiout
, "what", "<any syscall>");
6324 ui_out_text (uiout
, "\" ");
6327 /* Implement the "print_mention" breakpoint_ops method for syscall
6331 print_mention_catch_syscall (struct breakpoint
*b
)
6333 if (b
->syscalls_to_be_caught
)
6337 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6338 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6340 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6343 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6347 get_syscall_by_number (iter
, &s
);
6350 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6352 printf_filtered (" %d", s
.number
);
6354 printf_filtered (")");
6357 printf_filtered (_("Catchpoint %d (any syscall)"),
6361 /* Implement the "print_recreate" breakpoint_ops method for syscall
6365 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6367 fprintf_unfiltered (fp
, "catch syscall");
6369 if (b
->syscalls_to_be_caught
)
6374 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6379 get_syscall_by_number (iter
, &s
);
6381 fprintf_unfiltered (fp
, " %s", s
.name
);
6383 fprintf_unfiltered (fp
, " %d", s
.number
);
6388 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6390 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6392 insert_catch_syscall
,
6393 remove_catch_syscall
,
6394 breakpoint_hit_catch_syscall
,
6395 print_it_catch_syscall
,
6396 print_one_catch_syscall
,
6397 print_mention_catch_syscall
,
6398 print_recreate_catch_syscall
6401 /* Returns non-zero if 'b' is a syscall catchpoint. */
6404 syscall_catchpoint_p (struct breakpoint
*b
)
6406 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6409 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6410 but does NOT mention it nor update the global location list.
6411 This is useful if you need to fill more fields in the
6412 struct breakpoint before calling mention.
6414 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6415 If COND_STRING is not NULL, then store it in the breakpoint.
6416 OPS, if not NULL, is the breakpoint_ops structure associated
6417 to the catchpoint. */
6419 static struct breakpoint
*
6420 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6422 struct breakpoint_ops
*ops
)
6424 struct symtab_and_line sal
;
6425 struct breakpoint
*b
;
6428 sal
.pspace
= current_program_space
;
6430 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6431 set_breakpoint_count (breakpoint_count
+ 1);
6432 b
->number
= breakpoint_count
;
6434 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6436 b
->addr_string
= NULL
;
6437 b
->enable_state
= bp_enabled
;
6438 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6444 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6446 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6447 If COND_STRING is not NULL, then store it in the breakpoint.
6448 OPS, if not NULL, is the breakpoint_ops structure associated
6449 to the catchpoint. */
6451 static struct breakpoint
*
6452 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6453 char *cond_string
, struct breakpoint_ops
*ops
)
6455 struct breakpoint
*b
=
6456 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6459 update_global_location_list (1);
6465 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6466 int tempflag
, char *cond_string
,
6467 struct breakpoint_ops
*ops
)
6469 struct breakpoint
*b
6470 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6472 /* FIXME: We should put this information in a breakpoint private data
6474 b
->forked_inferior_pid
= null_ptid
;
6477 /* Exec catchpoints. */
6480 insert_catch_exec (struct breakpoint
*b
)
6482 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6486 remove_catch_exec (struct breakpoint
*b
)
6488 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6492 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6494 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6497 static enum print_stop_action
6498 print_it_catch_exec (struct breakpoint
*b
)
6500 annotate_catchpoint (b
->number
);
6501 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6503 return PRINT_SRC_AND_LOC
;
6507 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6509 struct value_print_options opts
;
6511 get_user_print_options (&opts
);
6513 /* Field 4, the address, is omitted (which makes the columns
6514 not line up too nicely with the headers, but the effect
6515 is relatively readable). */
6516 if (opts
.addressprint
)
6517 ui_out_field_skip (uiout
, "addr");
6519 ui_out_text (uiout
, "exec");
6520 if (b
->exec_pathname
!= NULL
)
6522 ui_out_text (uiout
, ", program \"");
6523 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6524 ui_out_text (uiout
, "\" ");
6529 print_mention_catch_exec (struct breakpoint
*b
)
6531 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6534 /* Implement the "print_recreate" breakpoint_ops method for exec
6538 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6540 fprintf_unfiltered (fp
, "catch exec");
6543 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6547 breakpoint_hit_catch_exec
,
6548 print_it_catch_exec
,
6549 print_one_catch_exec
,
6550 print_mention_catch_exec
,
6551 print_recreate_catch_exec
6555 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6556 struct breakpoint_ops
*ops
)
6558 struct gdbarch
*gdbarch
= get_current_arch ();
6559 struct breakpoint
*b
=
6560 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6562 b
->syscalls_to_be_caught
= filter
;
6564 /* Now, we have to mention the breakpoint and update the global
6567 update_global_location_list (1);
6571 hw_breakpoint_used_count (void)
6573 struct breakpoint
*b
;
6578 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6586 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6588 struct breakpoint
*b
;
6591 *other_type_used
= 0;
6594 if (breakpoint_enabled (b
))
6596 if (b
->type
== type
)
6598 else if (is_hardware_watchpoint (b
))
6599 *other_type_used
= 1;
6606 disable_watchpoints_before_interactive_call_start (void)
6608 struct breakpoint
*b
;
6612 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6614 b
->enable_state
= bp_call_disabled
;
6615 update_global_location_list (0);
6621 enable_watchpoints_after_interactive_call_stop (void)
6623 struct breakpoint
*b
;
6627 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6629 b
->enable_state
= bp_enabled
;
6630 update_global_location_list (1);
6636 disable_breakpoints_before_startup (void)
6638 struct breakpoint
*b
;
6643 if (b
->pspace
!= current_program_space
)
6646 if ((b
->type
== bp_breakpoint
6647 || b
->type
== bp_hardware_breakpoint
)
6648 && breakpoint_enabled (b
))
6650 b
->enable_state
= bp_startup_disabled
;
6656 update_global_location_list (0);
6658 current_program_space
->executing_startup
= 1;
6662 enable_breakpoints_after_startup (void)
6664 struct breakpoint
*b
;
6667 current_program_space
->executing_startup
= 0;
6671 if (b
->pspace
!= current_program_space
)
6674 if ((b
->type
== bp_breakpoint
6675 || b
->type
== bp_hardware_breakpoint
)
6676 && b
->enable_state
== bp_startup_disabled
)
6678 b
->enable_state
= bp_enabled
;
6684 breakpoint_re_set ();
6688 /* Set a breakpoint that will evaporate an end of command
6689 at address specified by SAL.
6690 Restrict it to frame FRAME if FRAME is nonzero. */
6693 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6694 struct frame_id frame_id
, enum bptype type
)
6696 struct breakpoint
*b
;
6698 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6700 gdb_assert (!frame_id_inlined_p (frame_id
));
6702 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6703 b
->enable_state
= bp_enabled
;
6704 b
->disposition
= disp_donttouch
;
6705 b
->frame_id
= frame_id
;
6707 /* If we're debugging a multi-threaded program, then we
6708 want momentary breakpoints to be active in only a
6709 single thread of control. */
6710 if (in_thread_list (inferior_ptid
))
6711 b
->thread
= pid_to_thread_id (inferior_ptid
);
6713 update_global_location_list_nothrow (1);
6718 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6722 clone_momentary_breakpoint (struct breakpoint
*orig
)
6724 struct breakpoint
*copy
;
6726 /* If there's nothing to clone, then return nothing. */
6730 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6731 copy
->loc
= allocate_bp_location (copy
);
6732 set_breakpoint_location_function (copy
->loc
);
6734 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6735 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6736 copy
->loc
->address
= orig
->loc
->address
;
6737 copy
->loc
->section
= orig
->loc
->section
;
6738 copy
->loc
->pspace
= orig
->loc
->pspace
;
6740 if (orig
->source_file
== NULL
)
6741 copy
->source_file
= NULL
;
6743 copy
->source_file
= xstrdup (orig
->source_file
);
6745 copy
->line_number
= orig
->line_number
;
6746 copy
->frame_id
= orig
->frame_id
;
6747 copy
->thread
= orig
->thread
;
6748 copy
->pspace
= orig
->pspace
;
6750 copy
->enable_state
= bp_enabled
;
6751 copy
->disposition
= disp_donttouch
;
6752 copy
->number
= internal_breakpoint_number
--;
6754 update_global_location_list_nothrow (0);
6759 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6762 struct symtab_and_line sal
;
6764 sal
= find_pc_line (pc
, 0);
6766 sal
.section
= find_pc_overlay (pc
);
6767 sal
.explicit_pc
= 1;
6769 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6773 /* Tell the user we have just set a breakpoint B. */
6776 mention (struct breakpoint
*b
)
6779 struct cleanup
*ui_out_chain
;
6780 struct value_print_options opts
;
6782 get_user_print_options (&opts
);
6784 /* FIXME: This is misplaced; mention() is called by things (like
6785 hitting a watchpoint) other than breakpoint creation. It should
6786 be possible to clean this up and at the same time replace the
6787 random calls to breakpoint_changed with this hook. */
6788 observer_notify_breakpoint_created (b
->number
);
6790 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6791 b
->ops
->print_mention (b
);
6796 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6799 ui_out_text (uiout
, "Watchpoint ");
6800 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6801 ui_out_field_int (uiout
, "number", b
->number
);
6802 ui_out_text (uiout
, ": ");
6803 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6804 do_cleanups (ui_out_chain
);
6806 case bp_hardware_watchpoint
:
6807 ui_out_text (uiout
, "Hardware watchpoint ");
6808 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6809 ui_out_field_int (uiout
, "number", b
->number
);
6810 ui_out_text (uiout
, ": ");
6811 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6812 do_cleanups (ui_out_chain
);
6814 case bp_read_watchpoint
:
6815 ui_out_text (uiout
, "Hardware read watchpoint ");
6816 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6817 ui_out_field_int (uiout
, "number", b
->number
);
6818 ui_out_text (uiout
, ": ");
6819 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6820 do_cleanups (ui_out_chain
);
6822 case bp_access_watchpoint
:
6823 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6824 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6825 ui_out_field_int (uiout
, "number", b
->number
);
6826 ui_out_text (uiout
, ": ");
6827 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6828 do_cleanups (ui_out_chain
);
6831 if (ui_out_is_mi_like_p (uiout
))
6836 if (b
->disposition
== disp_del
)
6837 printf_filtered (_("Temporary breakpoint"));
6839 printf_filtered (_("Breakpoint"));
6840 printf_filtered (_(" %d"), b
->number
);
6843 case bp_hardware_breakpoint
:
6844 if (ui_out_is_mi_like_p (uiout
))
6849 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6853 if (ui_out_is_mi_like_p (uiout
))
6858 printf_filtered (_("Tracepoint"));
6859 printf_filtered (_(" %d"), b
->number
);
6862 case bp_fast_tracepoint
:
6863 if (ui_out_is_mi_like_p (uiout
))
6868 printf_filtered (_("Fast tracepoint"));
6869 printf_filtered (_(" %d"), b
->number
);
6872 case bp_static_tracepoint
:
6873 if (ui_out_is_mi_like_p (uiout
))
6878 printf_filtered (_("Static tracepoint"));
6879 printf_filtered (_(" %d"), b
->number
);
6886 case bp_longjmp_resume
:
6888 case bp_exception_resume
:
6889 case bp_step_resume
:
6891 case bp_std_terminate
:
6892 case bp_watchpoint_scope
:
6893 case bp_shlib_event
:
6894 case bp_thread_event
:
6895 case bp_overlay_event
:
6897 case bp_longjmp_master
:
6898 case bp_std_terminate_master
:
6899 case bp_exception_master
:
6905 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6909 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6913 if (opts
.addressprint
|| b
->source_file
== NULL
)
6915 printf_filtered (" at ");
6916 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6920 printf_filtered (": file %s, line %d.",
6921 b
->source_file
, b
->line_number
);
6925 struct bp_location
*loc
= b
->loc
;
6927 for (; loc
; loc
= loc
->next
)
6929 printf_filtered (" (%d locations)", n
);
6934 if (ui_out_is_mi_like_p (uiout
))
6936 printf_filtered ("\n");
6940 static struct bp_location
*
6941 add_location_to_breakpoint (struct breakpoint
*b
,
6942 const struct symtab_and_line
*sal
)
6944 struct bp_location
*loc
, **tmp
;
6946 loc
= allocate_bp_location (b
);
6947 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6950 loc
->gdbarch
= get_sal_arch (*sal
);
6952 loc
->gdbarch
= b
->gdbarch
;
6953 loc
->requested_address
= sal
->pc
;
6954 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6955 loc
->requested_address
, b
->type
);
6956 loc
->pspace
= sal
->pspace
;
6957 gdb_assert (loc
->pspace
!= NULL
);
6958 loc
->section
= sal
->section
;
6960 set_breakpoint_location_function (loc
);
6965 /* Return 1 if LOC is pointing to a permanent breakpoint,
6966 return 0 otherwise. */
6969 bp_loc_is_permanent (struct bp_location
*loc
)
6973 const gdb_byte
*brk
;
6974 gdb_byte
*target_mem
;
6975 struct cleanup
*cleanup
;
6978 gdb_assert (loc
!= NULL
);
6980 addr
= loc
->address
;
6981 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6983 /* Software breakpoints unsupported? */
6987 target_mem
= alloca (len
);
6989 /* Enable the automatic memory restoration from breakpoints while
6990 we read the memory. Otherwise we could say about our temporary
6991 breakpoints they are permanent. */
6992 cleanup
= save_current_space_and_thread ();
6994 switch_to_program_space_and_thread (loc
->pspace
);
6995 make_show_memory_breakpoints_cleanup (0);
6997 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6998 && memcmp (target_mem
, brk
, len
) == 0)
7001 do_cleanups (cleanup
);
7008 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7009 as textual description of the location, and COND_STRING
7010 as condition expression. */
7013 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7014 struct symtabs_and_lines sals
, char *addr_string
,
7016 enum bptype type
, enum bpdisp disposition
,
7017 int thread
, int task
, int ignore_count
,
7018 struct breakpoint_ops
*ops
, int from_tty
,
7019 int enabled
, int internal
)
7021 struct breakpoint
*b
= NULL
;
7024 if (type
== bp_hardware_breakpoint
)
7026 int i
= hw_breakpoint_used_count ();
7027 int target_resources_ok
=
7028 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7030 if (target_resources_ok
== 0)
7031 error (_("No hardware breakpoint support in the target."));
7032 else if (target_resources_ok
< 0)
7033 error (_("Hardware breakpoints used exceeds limit."));
7036 gdb_assert (sals
.nelts
> 0);
7038 for (i
= 0; i
< sals
.nelts
; ++i
)
7040 struct symtab_and_line sal
= sals
.sals
[i
];
7041 struct bp_location
*loc
;
7045 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7047 loc_gdbarch
= gdbarch
;
7049 describe_other_breakpoints (loc_gdbarch
,
7050 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7055 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7056 set_breakpoint_number (internal
, b
);
7060 b
->cond_string
= cond_string
;
7061 b
->ignore_count
= ignore_count
;
7062 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7063 b
->disposition
= disposition
;
7064 b
->pspace
= sals
.sals
[0].pspace
;
7066 if (type
== bp_static_tracepoint
)
7068 struct static_tracepoint_marker marker
;
7070 if (is_marker_spec (addr_string
))
7072 /* We already know the marker exists, otherwise, we
7073 wouldn't see a sal for it. */
7074 char *p
= &addr_string
[3];
7079 while (*p
== ' ' || *p
== '\t')
7083 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7086 marker_str
= savestring (p
, endp
- p
);
7087 b
->static_trace_marker_id
= marker_str
;
7089 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
7090 b
->static_trace_marker_id
);
7092 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7094 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7095 release_static_tracepoint_marker (&marker
);
7097 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
7098 b
->static_trace_marker_id
);
7102 Couldn't determine the static tracepoint marker to probe"));
7105 if (enabled
&& b
->pspace
->executing_startup
7106 && (b
->type
== bp_breakpoint
7107 || b
->type
== bp_hardware_breakpoint
))
7108 b
->enable_state
= bp_startup_disabled
;
7114 loc
= add_location_to_breakpoint (b
, &sal
);
7117 if (bp_loc_is_permanent (loc
))
7118 make_breakpoint_permanent (b
);
7122 char *arg
= b
->cond_string
;
7123 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7125 error (_("Garbage %s follows condition"), arg
);
7130 b
->addr_string
= addr_string
;
7132 /* addr_string has to be used or breakpoint_re_set will delete
7135 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7139 /* Do not mention breakpoints with a negative number, but do
7140 notify observers. */
7141 observer_notify_breakpoint_created (b
->number
);
7146 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7147 elements to fill the void space. */
7149 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7151 int i
= index_to_remove
+1;
7152 int last_index
= sal
->nelts
-1;
7154 for (;i
<= last_index
; ++i
)
7155 sal
->sals
[i
-1] = sal
->sals
[i
];
7160 /* If appropriate, obtains all sals that correspond to the same file
7161 and line as SAL, in all program spaces. Users debugging with IDEs,
7162 will want to set a breakpoint at foo.c:line, and not really care
7163 about program spaces. This is done only if SAL does not have
7164 explicit PC and has line and file information. If we got just a
7165 single expanded sal, return the original.
7167 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7168 which the name of enclosing function is different from SAL. This
7169 makes sure that if we have breakpoint originally set in template
7170 instantiation, say foo<int>(), we won't expand SAL to locations at
7171 the same line in all existing instantiations of 'foo'. */
7173 static struct symtabs_and_lines
7174 expand_line_sal_maybe (struct symtab_and_line sal
)
7176 struct symtabs_and_lines expanded
;
7177 CORE_ADDR original_pc
= sal
.pc
;
7178 char *original_function
= NULL
;
7181 struct cleanup
*old_chain
;
7183 /* If we have explicit pc, don't expand.
7184 If we have no line number, we can't expand. */
7185 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7188 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7189 expanded
.sals
[0] = sal
;
7195 old_chain
= save_current_space_and_thread ();
7197 switch_to_program_space_and_thread (sal
.pspace
);
7199 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7201 /* Note that expand_line_sal visits *all* program spaces. */
7202 expanded
= expand_line_sal (sal
);
7204 if (expanded
.nelts
== 1)
7206 /* We had one sal, we got one sal. Return that sal, adjusting it
7207 past the function prologue if necessary. */
7208 xfree (expanded
.sals
);
7210 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7211 sal
.pc
= original_pc
;
7212 expanded
.sals
[0] = sal
;
7213 skip_prologue_sal (&expanded
.sals
[0]);
7214 do_cleanups (old_chain
);
7218 if (!sal
.explicit_line
)
7220 CORE_ADDR func_addr
, func_end
;
7221 for (i
= 0; i
< expanded
.nelts
; ++i
)
7223 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7224 char *this_function
;
7226 /* We need to switch threads as well since we're about to
7228 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7230 if (find_pc_partial_function (pc
, &this_function
,
7231 &func_addr
, &func_end
))
7234 && strcmp (this_function
, original_function
) != 0)
7236 remove_sal (&expanded
, i
);
7243 /* Skip the function prologue if necessary. */
7244 for (i
= 0; i
< expanded
.nelts
; ++i
)
7245 skip_prologue_sal (&expanded
.sals
[i
]);
7247 do_cleanups (old_chain
);
7249 if (expanded
.nelts
<= 1)
7251 /* This is un ugly workaround. If we get zero
7252 expanded sals then something is really wrong.
7253 Fix that by returnign the original sal. */
7254 xfree (expanded
.sals
);
7256 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7257 sal
.pc
= original_pc
;
7258 expanded
.sals
[0] = sal
;
7265 for (i
= 0; i
< expanded
.nelts
; ++i
)
7266 if (expanded
.sals
[i
].pc
== original_pc
)
7277 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7278 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7279 value. COND_STRING, if not NULL, specified the condition to be
7280 used for all breakpoints. Essentially the only case where
7281 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7282 function. In that case, it's still not possible to specify
7283 separate conditions for different overloaded functions, so
7284 we take just a single condition string.
7286 NOTE: If the function succeeds, the caller is expected to cleanup
7287 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7288 array contents). If the function fails (error() is called), the
7289 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7290 COND and SALS arrays and each of those arrays contents. */
7293 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7294 struct symtabs_and_lines sals
, char **addr_string
,
7296 enum bptype type
, enum bpdisp disposition
,
7297 int thread
, int task
, int ignore_count
,
7298 struct breakpoint_ops
*ops
, int from_tty
,
7299 int enabled
, int internal
)
7303 for (i
= 0; i
< sals
.nelts
; ++i
)
7305 struct symtabs_and_lines expanded
=
7306 expand_line_sal_maybe (sals
.sals
[i
]);
7308 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7309 cond_string
, type
, disposition
,
7310 thread
, task
, ignore_count
, ops
,
7311 from_tty
, enabled
, internal
);
7315 /* Parse ARG which is assumed to be a SAL specification possibly
7316 followed by conditionals. On return, SALS contains an array of SAL
7317 addresses found. ADDR_STRING contains a vector of (canonical)
7318 address strings. ARG points to the end of the SAL. */
7321 parse_breakpoint_sals (char **address
,
7322 struct symtabs_and_lines
*sals
,
7323 char ***addr_string
,
7326 char *addr_start
= *address
;
7328 *addr_string
= NULL
;
7329 /* If no arg given, or if first arg is 'if ', use the default
7331 if ((*address
) == NULL
7332 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7334 if (default_breakpoint_valid
)
7336 struct symtab_and_line sal
;
7338 init_sal (&sal
); /* initialize to zeroes */
7339 sals
->sals
= (struct symtab_and_line
*)
7340 xmalloc (sizeof (struct symtab_and_line
));
7341 sal
.pc
= default_breakpoint_address
;
7342 sal
.line
= default_breakpoint_line
;
7343 sal
.symtab
= default_breakpoint_symtab
;
7344 sal
.pspace
= default_breakpoint_pspace
;
7345 sal
.section
= find_pc_overlay (sal
.pc
);
7347 /* "break" without arguments is equivalent to "break *PC" where PC is
7348 the default_breakpoint_address. So make sure to set
7349 sal.explicit_pc to prevent GDB from trying to expand the list of
7350 sals to include all other instances with the same symtab and line.
7352 sal
.explicit_pc
= 1;
7354 sals
->sals
[0] = sal
;
7358 error (_("No default breakpoint address now."));
7362 /* Force almost all breakpoints to be in terms of the
7363 current_source_symtab (which is decode_line_1's default). This
7364 should produce the results we want almost all of the time while
7365 leaving default_breakpoint_* alone.
7366 ObjC: However, don't match an Objective-C method name which
7367 may have a '+' or '-' succeeded by a '[' */
7369 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7371 if (default_breakpoint_valid
7373 || ((strchr ("+-", (*address
)[0]) != NULL
)
7374 && ((*address
)[1] != '['))))
7375 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7376 default_breakpoint_line
, addr_string
,
7379 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7380 addr_string
, not_found_ptr
);
7382 /* For any SAL that didn't have a canonical string, fill one in. */
7383 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7384 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7385 if (addr_start
!= (*address
))
7389 for (i
= 0; i
< sals
->nelts
; i
++)
7391 /* Add the string if not present. */
7392 if ((*addr_string
)[i
] == NULL
)
7393 (*addr_string
)[i
] = savestring (addr_start
,
7394 (*address
) - addr_start
);
7400 /* Convert each SAL into a real PC. Verify that the PC can be
7401 inserted as a breakpoint. If it can't throw an error. */
7404 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7408 for (i
= 0; i
< sals
->nelts
; i
++)
7409 resolve_sal_pc (&sals
->sals
[i
]);
7412 /* Fast tracepoints may have restrictions on valid locations. For
7413 instance, a fast tracepoint using a jump instead of a trap will
7414 likely have to overwrite more bytes than a trap would, and so can
7415 only be placed where the instruction is longer than the jump, or a
7416 multi-instruction sequence does not have a jump into the middle of
7420 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7421 struct symtabs_and_lines
*sals
)
7424 struct symtab_and_line
*sal
;
7426 struct cleanup
*old_chain
;
7428 for (i
= 0; i
< sals
->nelts
; i
++)
7430 sal
= &sals
->sals
[i
];
7432 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7434 old_chain
= make_cleanup (xfree
, msg
);
7437 error (_("May not have a fast tracepoint at 0x%s%s"),
7438 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7440 do_cleanups (old_chain
);
7445 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7447 struct captured_parse_breakpoint_args
*args
= data
;
7449 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7450 args
->not_found_ptr
);
7453 /* Given TOK, a string specification of condition and thread, as
7454 accepted by the 'break' command, extract the condition
7455 string and thread number and set *COND_STRING and *THREAD.
7456 PC identifies the context at which the condition should be parsed.
7457 If no condition is found, *COND_STRING is set to NULL.
7458 If no thread is found, *THREAD is set to -1. */
7460 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7461 char **cond_string
, int *thread
, int *task
)
7463 *cond_string
= NULL
;
7469 char *cond_start
= NULL
;
7470 char *cond_end
= NULL
;
7472 while (*tok
== ' ' || *tok
== '\t')
7477 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7480 toklen
= end_tok
- tok
;
7482 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7484 struct expression
*expr
;
7486 tok
= cond_start
= end_tok
+ 1;
7487 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7490 *cond_string
= savestring (cond_start
,
7491 cond_end
- cond_start
);
7493 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7499 *thread
= strtol (tok
, &tok
, 0);
7501 error (_("Junk after thread keyword."));
7502 if (!valid_thread_id (*thread
))
7503 error (_("Unknown thread %d."), *thread
);
7505 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7511 *task
= strtol (tok
, &tok
, 0);
7513 error (_("Junk after task keyword."));
7514 if (!valid_task_id (*task
))
7515 error (_("Unknown task %d."), *task
);
7518 error (_("Junk at end of arguments."));
7522 /* Decode a static tracepoint marker spec. */
7524 static struct symtabs_and_lines
7525 decode_static_tracepoint_spec (char **arg_p
)
7527 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7528 struct symtabs_and_lines sals
;
7529 struct symtab_and_line sal
;
7531 struct cleanup
*old_chain
;
7532 char *p
= &(*arg_p
)[3];
7537 while (*p
== ' ' || *p
== '\t')
7541 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7544 marker_str
= savestring (p
, endp
- p
);
7545 old_chain
= make_cleanup (xfree
, marker_str
);
7547 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7548 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7549 error (_("No known static tracepoint marker named %s"), marker_str
);
7551 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7552 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7554 for (i
= 0; i
< sals
.nelts
; i
++)
7556 struct static_tracepoint_marker
*marker
;
7558 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7560 init_sal (&sals
.sals
[i
]);
7562 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7563 sals
.sals
[i
].pc
= marker
->address
;
7565 release_static_tracepoint_marker (marker
);
7568 do_cleanups (old_chain
);
7574 /* Set a breakpoint. This function is shared between CLI and MI
7575 functions for setting a breakpoint. This function has two major
7576 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7577 parameter. If non-zero, the function will parse arg, extracting
7578 breakpoint location, address and thread. Otherwise, ARG is just the
7579 location of breakpoint, with condition and thread specified by the
7580 COND_STRING and THREAD parameters. If INTERNAL is non-zero, the
7581 breakpoint number will be allocated from the internal breakpoint
7582 count. Returns true if any breakpoint was created; false
7586 create_breakpoint (struct gdbarch
*gdbarch
,
7587 char *arg
, char *cond_string
, int thread
,
7588 int parse_condition_and_thread
,
7589 int tempflag
, enum bptype type_wanted
,
7591 enum auto_boolean pending_break_support
,
7592 struct breakpoint_ops
*ops
,
7593 int from_tty
, int enabled
, int internal
)
7595 struct gdb_exception e
;
7596 struct symtabs_and_lines sals
;
7597 struct symtab_and_line pending_sal
;
7599 char *addr_start
= arg
;
7601 struct cleanup
*old_chain
;
7602 struct cleanup
*bkpt_chain
= NULL
;
7603 struct captured_parse_breakpoint_args parse_args
;
7608 int prev_bkpt_count
= breakpoint_count
;
7614 parse_args
.arg_p
= &arg
;
7615 parse_args
.sals_p
= &sals
;
7616 parse_args
.addr_string_p
= &addr_string
;
7617 parse_args
.not_found_ptr
= ¬_found
;
7619 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7623 sals
= decode_static_tracepoint_spec (&arg
);
7625 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7626 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7627 for (i
= 0; i
< sals
.nelts
; i
++)
7628 addr_string
[i
] = xstrdup (copy_arg
);
7632 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7633 &parse_args
, RETURN_MASK_ALL
);
7635 /* If caller is interested in rc value from parse, set value. */
7639 throw_exception (e
);
7643 case NOT_FOUND_ERROR
:
7645 /* If pending breakpoint support is turned off, throw
7648 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7649 throw_exception (e
);
7651 exception_print (gdb_stderr
, e
);
7653 /* If pending breakpoint support is auto query and the user
7654 selects no, then simply return the error code. */
7655 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7656 && !nquery (_("Make breakpoint pending on future shared library load? ")))
7659 /* At this point, either the user was queried about setting
7660 a pending breakpoint and selected yes, or pending
7661 breakpoint behavior is on and thus a pending breakpoint
7662 is defaulted on behalf of the user. */
7663 copy_arg
= xstrdup (addr_start
);
7664 addr_string
= ©_arg
;
7666 sals
.sals
= &pending_sal
;
7671 throw_exception (e
);
7680 /* Create a chain of things that always need to be cleaned up. */
7681 old_chain
= make_cleanup (null_cleanup
, 0);
7685 /* Make sure that all storage allocated to SALS gets freed. */
7686 make_cleanup (xfree
, sals
.sals
);
7688 /* Cleanup the addr_string array but not its contents. */
7689 make_cleanup (xfree
, addr_string
);
7692 /* ----------------------------- SNIP -----------------------------
7693 Anything added to the cleanup chain beyond this point is assumed
7694 to be part of a breakpoint. If the breakpoint create succeeds
7695 then the memory is not reclaimed. */
7696 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7698 /* Mark the contents of the addr_string for cleanup. These go on
7699 the bkpt_chain and only occur if the breakpoint create fails. */
7700 for (i
= 0; i
< sals
.nelts
; i
++)
7702 if (addr_string
[i
] != NULL
)
7703 make_cleanup (xfree
, addr_string
[i
]);
7706 /* Resolve all line numbers to PC's and verify that the addresses
7707 are ok for the target. */
7709 breakpoint_sals_to_pc (&sals
);
7711 /* Fast tracepoints may have additional restrictions on location. */
7712 if (type_wanted
== bp_fast_tracepoint
)
7713 check_fast_tracepoint_sals (gdbarch
, &sals
);
7715 /* Verify that condition can be parsed, before setting any
7716 breakpoints. Allocate a separate condition expression for each
7720 if (parse_condition_and_thread
)
7722 /* Here we only parse 'arg' to separate condition
7723 from thread number, so parsing in context of first
7724 sal is OK. When setting the breakpoint we'll
7725 re-parse it in context of each sal. */
7728 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7731 make_cleanup (xfree
, cond_string
);
7735 /* Create a private copy of condition string. */
7738 cond_string
= xstrdup (cond_string
);
7739 make_cleanup (xfree
, cond_string
);
7743 /* If the user is creating a static tracepoint by marker id
7744 (strace -m MARKER_ID), then store the sals index, so that
7745 breakpoint_re_set can try to match up which of the newly
7746 found markers corresponds to this one, and, don't try to
7747 expand multiple locations for each sal, given than SALS
7748 already should contain all sals for MARKER_ID. */
7749 if (type_wanted
== bp_static_tracepoint
7750 && is_marker_spec (addr_string
[0]))
7754 for (i
= 0; i
< sals
.nelts
; ++i
)
7756 struct symtabs_and_lines expanded
;
7757 struct breakpoint
*tp
;
7758 struct cleanup
*old_chain
;
7761 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7762 expanded
.sals
[0] = sals
.sals
[i
];
7763 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7765 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7766 cond_string
, type_wanted
,
7767 tempflag
? disp_del
: disp_donttouch
,
7768 thread
, task
, ignore_count
, ops
,
7769 from_tty
, enabled
, internal
);
7771 do_cleanups (old_chain
);
7773 /* Get the tracepoint we just created. */
7775 tp
= get_breakpoint (internal_breakpoint_number
);
7777 tp
= get_breakpoint (breakpoint_count
);
7778 gdb_assert (tp
!= NULL
);
7780 /* Given that its possible to have multiple markers with
7781 the same string id, if the user is creating a static
7782 tracepoint by marker id ("strace -m MARKER_ID"), then
7783 store the sals index, so that breakpoint_re_set can
7784 try to match up which of the newly found markers
7785 corresponds to this one */
7786 tp
->static_trace_marker_id_idx
= i
;
7790 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7791 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7792 thread
, task
, ignore_count
, ops
, from_tty
,
7797 struct breakpoint
*b
;
7799 make_cleanup (xfree
, copy_arg
);
7801 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7802 set_breakpoint_number (internal
, b
);
7804 b
->addr_string
= addr_string
[0];
7805 b
->cond_string
= NULL
;
7806 b
->ignore_count
= ignore_count
;
7807 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7808 b
->condition_not_parsed
= 1;
7810 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7811 b
->pspace
= current_program_space
;
7812 b
->py_bp_object
= NULL
;
7814 if (enabled
&& b
->pspace
->executing_startup
7815 && (b
->type
== bp_breakpoint
7816 || b
->type
== bp_hardware_breakpoint
))
7817 b
->enable_state
= bp_startup_disabled
;
7820 /* Do not mention breakpoints with a negative number,
7821 but do notify observers. */
7822 observer_notify_breakpoint_created (b
->number
);
7829 warning (_("Multiple breakpoints were set.\n"
7830 "Use the \"delete\" command to delete unwanted breakpoints."));
7831 prev_breakpoint_count
= prev_bkpt_count
;
7834 /* That's it. Discard the cleanups for data inserted into the
7836 discard_cleanups (bkpt_chain
);
7837 /* But cleanup everything else. */
7838 do_cleanups (old_chain
);
7840 /* error call may happen here - have BKPT_CHAIN already discarded. */
7841 update_global_location_list (1);
7846 /* Set a breakpoint.
7847 ARG is a string describing breakpoint address,
7848 condition, and thread.
7849 FLAG specifies if a breakpoint is hardware on,
7850 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7854 break_command_1 (char *arg
, int flag
, int from_tty
)
7856 int tempflag
= flag
& BP_TEMPFLAG
;
7857 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7858 ? bp_hardware_breakpoint
7861 create_breakpoint (get_current_arch (),
7863 NULL
, 0, 1 /* parse arg */,
7864 tempflag
, type_wanted
,
7865 0 /* Ignore count */,
7866 pending_break_support
,
7867 NULL
/* breakpoint_ops */,
7874 /* Helper function for break_command_1 and disassemble_command. */
7877 resolve_sal_pc (struct symtab_and_line
*sal
)
7881 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7883 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7884 error (_("No line %d in file \"%s\"."),
7885 sal
->line
, sal
->symtab
->filename
);
7888 /* If this SAL corresponds to a breakpoint inserted using
7889 a line number, then skip the function prologue if necessary. */
7890 if (sal
->explicit_line
)
7891 skip_prologue_sal (sal
);
7894 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7896 struct blockvector
*bv
;
7900 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7903 sym
= block_linkage_function (b
);
7906 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7907 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7911 /* It really is worthwhile to have the section, so we'll just
7912 have to look harder. This case can be executed if we have
7913 line numbers but no functions (as can happen in assembly
7916 struct minimal_symbol
*msym
;
7917 struct cleanup
*old_chain
= save_current_space_and_thread ();
7919 switch_to_program_space_and_thread (sal
->pspace
);
7921 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7923 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7925 do_cleanups (old_chain
);
7932 break_command (char *arg
, int from_tty
)
7934 break_command_1 (arg
, 0, from_tty
);
7938 tbreak_command (char *arg
, int from_tty
)
7940 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7944 hbreak_command (char *arg
, int from_tty
)
7946 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7950 thbreak_command (char *arg
, int from_tty
)
7952 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7956 stop_command (char *arg
, int from_tty
)
7958 printf_filtered (_("Specify the type of breakpoint to set.\n\
7959 Usage: stop in <function | address>\n\
7960 stop at <line>\n"));
7964 stopin_command (char *arg
, int from_tty
)
7968 if (arg
== (char *) NULL
)
7970 else if (*arg
!= '*')
7975 /* look for a ':'. If this is a line number specification, then
7976 say it is bad, otherwise, it should be an address or
7977 function/method name */
7978 while (*argptr
&& !hasColon
)
7980 hasColon
= (*argptr
== ':');
7985 badInput
= (*argptr
!= ':'); /* Not a class::method */
7987 badInput
= isdigit (*arg
); /* a simple line number */
7991 printf_filtered (_("Usage: stop in <function | address>\n"));
7993 break_command_1 (arg
, 0, from_tty
);
7997 stopat_command (char *arg
, int from_tty
)
8001 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8008 /* look for a ':'. If there is a '::' then get out, otherwise
8009 it is probably a line number. */
8010 while (*argptr
&& !hasColon
)
8012 hasColon
= (*argptr
== ':');
8017 badInput
= (*argptr
== ':'); /* we have class::method */
8019 badInput
= !isdigit (*arg
); /* not a line number */
8023 printf_filtered (_("Usage: stop at <line>\n"));
8025 break_command_1 (arg
, 0, from_tty
);
8028 /* Return non-zero if EXP is verified as constant. Returned zero means EXP is
8029 variable. Also the constant detection may fail for some constant
8030 expressions and in such case still falsely return zero. */
8032 watchpoint_exp_is_const (const struct expression
*exp
)
8040 /* We are only interested in the descriptor of each element. */
8041 operator_length (exp
, i
, &oplenp
, &argsp
);
8044 switch (exp
->elts
[i
].opcode
)
8054 case BINOP_LOGICAL_AND
:
8055 case BINOP_LOGICAL_OR
:
8056 case BINOP_BITWISE_AND
:
8057 case BINOP_BITWISE_IOR
:
8058 case BINOP_BITWISE_XOR
:
8060 case BINOP_NOTEQUAL
:
8076 case TERNOP_SLICE_COUNT
:
8088 case OP_OBJC_NSSTRING
:
8091 case UNOP_LOGICAL_NOT
:
8092 case UNOP_COMPLEMENT
:
8095 /* Unary, binary and ternary operators: We have to check their
8096 operands. If they are constant, then so is the result of
8097 that operation. For instance, if A and B are determined to be
8098 constants, then so is "A + B".
8100 UNOP_IND is one exception to the rule above, because the value
8101 of *ADDR is not necessarily a constant, even when ADDR is. */
8105 /* Check whether the associated symbol is a constant.
8106 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8107 possible that a buggy compiler could mark a variable as constant
8108 even when it is not, and TYPE_CONST would return true in this
8109 case, while SYMBOL_CLASS wouldn't.
8110 We also have to check for function symbols because they are
8113 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8115 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8116 && SYMBOL_CLASS (s
) != LOC_CONST
8117 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8122 /* The default action is to return 0 because we are using
8123 the optimistic approach here: If we don't know something,
8124 then it is not a constant. */
8133 /* accessflag: hw_write: watch write,
8134 hw_read: watch read,
8135 hw_access: watch access (read or write) */
8137 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8138 int just_location
, int internal
)
8140 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8141 struct expression
*exp
;
8142 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8143 struct value
*val
, *mark
, *result
;
8144 struct frame_info
*frame
;
8145 char *exp_start
= NULL
;
8146 char *exp_end
= NULL
;
8147 char *tok
, *id_tok_start
, *end_tok
;
8149 char *cond_start
= NULL
;
8150 char *cond_end
= NULL
;
8151 int i
, other_type_used
, target_resources_ok
= 0;
8152 enum bptype bp_type
;
8157 /* Make sure that we actually have parameters to parse. */
8158 if (arg
!= NULL
&& arg
[0] != '\0')
8160 toklen
= strlen (arg
); /* Size of argument list. */
8162 /* Points tok to the end of the argument list. */
8163 tok
= arg
+ toklen
- 1;
8165 /* Go backwards in the parameters list. Skip the last parameter.
8166 If we're expecting a 'thread <thread_num>' parameter, this should
8167 be the thread identifier. */
8168 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8170 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8173 /* Points end_tok to the beginning of the last token. */
8174 id_tok_start
= tok
+ 1;
8176 /* Go backwards in the parameters list. Skip one more parameter.
8177 If we're expecting a 'thread <thread_num>' parameter, we should
8178 reach a "thread" token. */
8179 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8184 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8187 /* Move the pointer forward to skip the whitespace and
8188 calculate the length of the token. */
8190 toklen
= end_tok
- tok
;
8192 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8194 /* At this point we've found a "thread" token, which means
8195 the user is trying to set a watchpoint that triggers
8196 only in a specific thread. */
8199 /* Extract the thread ID from the next token. */
8200 thread
= strtol (id_tok_start
, &endp
, 0);
8202 /* Check if the user provided a valid numeric value for the
8204 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8205 error (_("Invalid thread ID specification %s."), id_tok_start
);
8207 /* Check if the thread actually exists. */
8208 if (!valid_thread_id (thread
))
8209 error (_("Unknown thread %d."), thread
);
8211 /* Truncate the string and get rid of the thread <thread_num>
8212 parameter before the parameter list is parsed by the
8213 evaluate_expression() function. */
8218 /* Parse the rest of the arguments. */
8219 innermost_block
= NULL
;
8221 exp
= parse_exp_1 (&arg
, 0, 0);
8223 /* Remove trailing whitespace from the expression before saving it.
8224 This makes the eventual display of the expression string a bit
8226 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8229 /* Checking if the expression is not constant. */
8230 if (watchpoint_exp_is_const (exp
))
8234 len
= exp_end
- exp_start
;
8235 while (len
> 0 && isspace (exp_start
[len
- 1]))
8237 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8240 exp_valid_block
= innermost_block
;
8241 mark
= value_mark ();
8242 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8246 exp_valid_block
= NULL
;
8247 val
= value_addr (result
);
8248 release_value (val
);
8249 value_free_to_mark (mark
);
8251 else if (val
!= NULL
)
8252 release_value (val
);
8255 while (*tok
== ' ' || *tok
== '\t')
8259 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
8262 toklen
= end_tok
- tok
;
8263 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8265 struct expression
*cond
;
8267 innermost_block
= NULL
;
8268 tok
= cond_start
= end_tok
+ 1;
8269 cond
= parse_exp_1 (&tok
, 0, 0);
8271 /* The watchpoint expression may not be local, but the condition
8272 may still be. E.g.: `watch global if local > 0'. */
8273 cond_exp_valid_block
= innermost_block
;
8279 error (_("Junk at end of command."));
8281 if (accessflag
== hw_read
)
8282 bp_type
= bp_read_watchpoint
;
8283 else if (accessflag
== hw_access
)
8284 bp_type
= bp_access_watchpoint
;
8286 bp_type
= bp_hardware_watchpoint
;
8288 mem_cnt
= can_use_hardware_watchpoint (val
);
8289 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8290 error (_("Expression cannot be implemented with read/access watchpoint."));
8293 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8294 target_resources_ok
=
8295 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
8297 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8298 error (_("Target does not support this type of hardware watchpoint."));
8300 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8301 error (_("Target can only support one kind of HW watchpoint at a time."));
8304 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
8305 watchpoint could not be set. */
8306 if (!mem_cnt
|| target_resources_ok
<= 0)
8307 bp_type
= bp_watchpoint
;
8309 frame
= block_innermost_frame (exp_valid_block
);
8311 /* If the expression is "local", then set up a "watchpoint scope"
8312 breakpoint at the point where we've left the scope of the watchpoint
8313 expression. Create the scope breakpoint before the watchpoint, so
8314 that we will encounter it first in bpstat_stop_status. */
8315 if (exp_valid_block
&& frame
)
8317 if (frame_id_p (frame_unwind_caller_id (frame
)))
8320 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8321 frame_unwind_caller_pc (frame
),
8322 bp_watchpoint_scope
);
8324 scope_breakpoint
->enable_state
= bp_enabled
;
8326 /* Automatically delete the breakpoint when it hits. */
8327 scope_breakpoint
->disposition
= disp_del
;
8329 /* Only break in the proper frame (help with recursion). */
8330 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8332 /* Set the address at which we will stop. */
8333 scope_breakpoint
->loc
->gdbarch
8334 = frame_unwind_caller_arch (frame
);
8335 scope_breakpoint
->loc
->requested_address
8336 = frame_unwind_caller_pc (frame
);
8337 scope_breakpoint
->loc
->address
8338 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8339 scope_breakpoint
->loc
->requested_address
,
8340 scope_breakpoint
->type
);
8344 /* Now set up the breakpoint. */
8345 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8346 set_breakpoint_number (internal
, b
);
8348 b
->disposition
= disp_donttouch
;
8350 b
->exp_valid_block
= exp_valid_block
;
8351 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8354 struct type
*t
= value_type (val
);
8355 CORE_ADDR addr
= value_as_address (val
);
8358 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8359 name
= type_to_string (t
);
8361 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8362 core_addr_to_string (addr
));
8365 b
->exp_string
= xstrprintf ("-location: %.*s",
8366 (int) (exp_end
- exp_start
), exp_start
);
8368 /* The above expression is in C. */
8369 b
->language
= language_c
;
8372 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8376 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8382 b
->watchpoint_frame
= get_frame_id (frame
);
8383 b
->watchpoint_thread
= inferior_ptid
;
8387 b
->watchpoint_frame
= null_frame_id
;
8388 b
->watchpoint_thread
= null_ptid
;
8391 if (scope_breakpoint
!= NULL
)
8393 /* The scope breakpoint is related to the watchpoint. We will
8394 need to act on them together. */
8395 b
->related_breakpoint
= scope_breakpoint
;
8396 scope_breakpoint
->related_breakpoint
= b
;
8400 value_free_to_mark (mark
);
8402 /* Finally update the new watchpoint. This creates the locations
8403 that should be inserted. */
8404 update_watchpoint (b
, 1);
8406 /* Do not mention breakpoints with a negative number, but do
8407 notify observers. */
8408 observer_notify_breakpoint_created (b
->number
);
8411 update_global_location_list (1);
8414 /* Return count of locations need to be watched and can be handled
8415 in hardware. If the watchpoint can not be handled
8416 in hardware return zero. */
8419 can_use_hardware_watchpoint (struct value
*v
)
8421 int found_memory_cnt
= 0;
8422 struct value
*head
= v
;
8424 /* Did the user specifically forbid us to use hardware watchpoints? */
8425 if (!can_use_hw_watchpoints
)
8428 /* Make sure that the value of the expression depends only upon
8429 memory contents, and values computed from them within GDB. If we
8430 find any register references or function calls, we can't use a
8431 hardware watchpoint.
8433 The idea here is that evaluating an expression generates a series
8434 of values, one holding the value of every subexpression. (The
8435 expression a*b+c has five subexpressions: a, b, a*b, c, and
8436 a*b+c.) GDB's values hold almost enough information to establish
8437 the criteria given above --- they identify memory lvalues,
8438 register lvalues, computed values, etcetera. So we can evaluate
8439 the expression, and then scan the chain of values that leaves
8440 behind to decide whether we can detect any possible change to the
8441 expression's final value using only hardware watchpoints.
8443 However, I don't think that the values returned by inferior
8444 function calls are special in any way. So this function may not
8445 notice that an expression involving an inferior function call
8446 can't be watched with hardware watchpoints. FIXME. */
8447 for (; v
; v
= value_next (v
))
8449 if (VALUE_LVAL (v
) == lval_memory
)
8451 if (v
!= head
&& value_lazy (v
))
8452 /* A lazy memory lvalue in the chain is one that GDB never
8453 needed to fetch; we either just used its address (e.g.,
8454 `a' in `a.b') or we never needed it at all (e.g., `a'
8455 in `a,b'). This doesn't apply to HEAD; if that is
8456 lazy then it was not readable, but watch it anyway. */
8460 /* Ahh, memory we actually used! Check if we can cover
8461 it with hardware watchpoints. */
8462 struct type
*vtype
= check_typedef (value_type (v
));
8464 /* We only watch structs and arrays if user asked for it
8465 explicitly, never if they just happen to appear in a
8466 middle of some value chain. */
8468 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8469 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8471 CORE_ADDR vaddr
= value_address (v
);
8472 int len
= TYPE_LENGTH (value_type (v
));
8474 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
8481 else if (VALUE_LVAL (v
) != not_lval
8482 && deprecated_value_modifiable (v
) == 0)
8483 return 0; /* These are values from the history (e.g., $1). */
8484 else if (VALUE_LVAL (v
) == lval_register
)
8485 return 0; /* Cannot watch a register with a HW watchpoint. */
8488 /* The expression itself looks suitable for using a hardware
8489 watchpoint, but give the target machine a chance to reject it. */
8490 return found_memory_cnt
;
8494 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
8496 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
8499 /* A helper function that looks for an argument at the start of a
8500 string. The argument must also either be at the end of the string,
8501 or be followed by whitespace. Returns 1 if it finds the argument,
8502 0 otherwise. If the argument is found, it updates *STR. */
8505 check_for_argument (char **str
, char *arg
, int arg_len
)
8507 if (strncmp (*str
, arg
, arg_len
) == 0
8508 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8516 /* A helper function that looks for the "-location" argument and then
8517 calls watch_command_1. */
8520 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8522 int just_location
= 0;
8525 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8526 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8528 ep_skip_leading_whitespace (&arg
);
8532 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
8536 watch_command (char *arg
, int from_tty
)
8538 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8542 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8544 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
8548 rwatch_command (char *arg
, int from_tty
)
8550 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8554 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8556 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
8560 awatch_command (char *arg
, int from_tty
)
8562 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8566 /* Helper routines for the until_command routine in infcmd.c. Here
8567 because it uses the mechanisms of breakpoints. */
8569 struct until_break_command_continuation_args
8571 struct breakpoint
*breakpoint
;
8572 struct breakpoint
*breakpoint2
;
8576 /* This function is called by fetch_inferior_event via the
8577 cmd_continuation pointer, to complete the until command. It takes
8578 care of cleaning up the temporary breakpoints set up by the until
8581 until_break_command_continuation (void *arg
)
8583 struct until_break_command_continuation_args
*a
= arg
;
8585 delete_breakpoint (a
->breakpoint
);
8587 delete_breakpoint (a
->breakpoint2
);
8588 delete_longjmp_breakpoint (a
->thread_num
);
8592 until_break_command (char *arg
, int from_tty
, int anywhere
)
8594 struct symtabs_and_lines sals
;
8595 struct symtab_and_line sal
;
8596 struct frame_info
*frame
= get_selected_frame (NULL
);
8597 struct breakpoint
*breakpoint
;
8598 struct breakpoint
*breakpoint2
= NULL
;
8599 struct cleanup
*old_chain
;
8601 struct thread_info
*tp
;
8603 clear_proceed_status ();
8605 /* Set a breakpoint where the user wants it and at return from
8608 if (default_breakpoint_valid
)
8609 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8610 default_breakpoint_line
, (char ***) NULL
, NULL
);
8612 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8613 0, (char ***) NULL
, NULL
);
8615 if (sals
.nelts
!= 1)
8616 error (_("Couldn't get information on specified line."));
8619 xfree (sals
.sals
); /* malloc'd, so freed */
8622 error (_("Junk at end of arguments."));
8624 resolve_sal_pc (&sal
);
8627 /* If the user told us to continue until a specified location,
8628 we don't specify a frame at which we need to stop. */
8629 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8630 null_frame_id
, bp_until
);
8632 /* Otherwise, specify the selected frame, because we want to stop only
8633 at the very same frame. */
8634 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8635 get_stack_frame_id (frame
),
8638 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8640 tp
= inferior_thread ();
8643 /* Keep within the current frame, or in frames called by the current
8646 if (frame_id_p (frame_unwind_caller_id (frame
)))
8648 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8649 sal
.pc
= frame_unwind_caller_pc (frame
);
8650 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8652 frame_unwind_caller_id (frame
),
8654 make_cleanup_delete_breakpoint (breakpoint2
);
8656 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
8657 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
8660 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8662 /* If we are running asynchronously, and proceed call above has actually
8663 managed to start the target, arrange for breakpoints to be
8664 deleted when the target stops. Otherwise, we're already stopped and
8665 delete breakpoints via cleanup chain. */
8667 if (target_can_async_p () && is_running (inferior_ptid
))
8669 struct until_break_command_continuation_args
*args
;
8670 args
= xmalloc (sizeof (*args
));
8672 args
->breakpoint
= breakpoint
;
8673 args
->breakpoint2
= breakpoint2
;
8674 args
->thread_num
= thread
;
8676 discard_cleanups (old_chain
);
8677 add_continuation (inferior_thread (),
8678 until_break_command_continuation
, args
,
8682 do_cleanups (old_chain
);
8686 ep_skip_leading_whitespace (char **s
)
8688 if ((s
== NULL
) || (*s
== NULL
))
8690 while (isspace (**s
))
8694 /* This function attempts to parse an optional "if <cond>" clause
8695 from the arg string. If one is not found, it returns NULL.
8697 Else, it returns a pointer to the condition string. (It does not
8698 attempt to evaluate the string against a particular block.) And,
8699 it updates arg to point to the first character following the parsed
8700 if clause in the arg string. */
8703 ep_parse_optional_if_clause (char **arg
)
8707 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8710 /* Skip the "if" keyword. */
8713 /* Skip any extra leading whitespace, and record the start of the
8714 condition string. */
8715 ep_skip_leading_whitespace (arg
);
8718 /* Assume that the condition occupies the remainder of the arg string. */
8719 (*arg
) += strlen (cond_string
);
8724 /* Commands to deal with catching events, such as signals, exceptions,
8725 process start/exit, etc. */
8729 catch_fork_temporary
, catch_vfork_temporary
,
8730 catch_fork_permanent
, catch_vfork_permanent
8735 catch_fork_command_1 (char *arg
, int from_tty
,
8736 struct cmd_list_element
*command
)
8738 struct gdbarch
*gdbarch
= get_current_arch ();
8739 char *cond_string
= NULL
;
8740 catch_fork_kind fork_kind
;
8743 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8744 tempflag
= (fork_kind
== catch_fork_temporary
8745 || fork_kind
== catch_vfork_temporary
);
8749 ep_skip_leading_whitespace (&arg
);
8751 /* The allowed syntax is:
8753 catch [v]fork if <cond>
8755 First, check if there's an if clause. */
8756 cond_string
= ep_parse_optional_if_clause (&arg
);
8758 if ((*arg
!= '\0') && !isspace (*arg
))
8759 error (_("Junk at end of arguments."));
8761 /* If this target supports it, create a fork or vfork catchpoint
8762 and enable reporting of such events. */
8765 case catch_fork_temporary
:
8766 case catch_fork_permanent
:
8767 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8768 &catch_fork_breakpoint_ops
);
8770 case catch_vfork_temporary
:
8771 case catch_vfork_permanent
:
8772 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8773 &catch_vfork_breakpoint_ops
);
8776 error (_("unsupported or unknown fork kind; cannot catch it"));
8782 catch_exec_command_1 (char *arg
, int from_tty
,
8783 struct cmd_list_element
*command
)
8785 struct gdbarch
*gdbarch
= get_current_arch ();
8787 char *cond_string
= NULL
;
8789 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8793 ep_skip_leading_whitespace (&arg
);
8795 /* The allowed syntax is:
8797 catch exec if <cond>
8799 First, check if there's an if clause. */
8800 cond_string
= ep_parse_optional_if_clause (&arg
);
8802 if ((*arg
!= '\0') && !isspace (*arg
))
8803 error (_("Junk at end of arguments."));
8805 /* If this target supports it, create an exec catchpoint
8806 and enable reporting of such events. */
8807 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8808 &catch_exec_breakpoint_ops
);
8811 static enum print_stop_action
8812 print_exception_catchpoint (struct breakpoint
*b
)
8814 int bp_temp
, bp_throw
;
8816 annotate_catchpoint (b
->number
);
8818 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8819 if (b
->loc
->address
!= b
->loc
->requested_address
)
8820 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8823 bp_temp
= b
->disposition
== disp_del
;
8825 bp_temp
? "Temporary catchpoint "
8827 if (!ui_out_is_mi_like_p (uiout
))
8828 ui_out_field_int (uiout
, "bkptno", b
->number
);
8830 bp_throw
? " (exception thrown), "
8831 : " (exception caught), ");
8832 if (ui_out_is_mi_like_p (uiout
))
8834 ui_out_field_string (uiout
, "reason",
8835 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8836 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8837 ui_out_field_int (uiout
, "bkptno", b
->number
);
8839 return PRINT_SRC_AND_LOC
;
8843 print_one_exception_catchpoint (struct breakpoint
*b
,
8844 struct bp_location
**last_loc
)
8846 struct value_print_options opts
;
8848 get_user_print_options (&opts
);
8849 if (opts
.addressprint
)
8852 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8853 ui_out_field_string (uiout
, "addr", "<PENDING>");
8855 ui_out_field_core_addr (uiout
, "addr",
8856 b
->loc
->gdbarch
, b
->loc
->address
);
8861 if (strstr (b
->addr_string
, "throw") != NULL
)
8862 ui_out_field_string (uiout
, "what", "exception throw");
8864 ui_out_field_string (uiout
, "what", "exception catch");
8868 print_mention_exception_catchpoint (struct breakpoint
*b
)
8873 bp_temp
= b
->disposition
== disp_del
;
8874 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8875 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8876 : _("Catchpoint "));
8877 ui_out_field_int (uiout
, "bkptno", b
->number
);
8878 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8882 /* Implement the "print_recreate" breakpoint_ops method for throw and
8883 catch catchpoints. */
8886 print_recreate_exception_catchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8891 bp_temp
= b
->disposition
== disp_del
;
8892 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8893 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
8894 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
8897 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8900 NULL
, /* breakpoint_hit */
8901 print_exception_catchpoint
,
8902 print_one_exception_catchpoint
,
8903 print_mention_exception_catchpoint
,
8904 print_recreate_exception_catchpoint
8908 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8909 enum exception_event_kind ex_event
, int from_tty
)
8911 char *trigger_func_name
;
8913 if (ex_event
== EX_EVENT_CATCH
)
8914 trigger_func_name
= "__cxa_begin_catch";
8916 trigger_func_name
= "__cxa_throw";
8918 create_breakpoint (get_current_arch (),
8919 trigger_func_name
, cond_string
, -1,
8920 0 /* condition and thread are valid. */,
8921 tempflag
, bp_breakpoint
,
8923 AUTO_BOOLEAN_TRUE
/* pending */,
8924 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8931 /* Deal with "catch catch" and "catch throw" commands */
8934 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8935 int tempflag
, int from_tty
)
8937 char *cond_string
= NULL
;
8941 ep_skip_leading_whitespace (&arg
);
8943 cond_string
= ep_parse_optional_if_clause (&arg
);
8945 if ((*arg
!= '\0') && !isspace (*arg
))
8946 error (_("Junk at end of arguments."));
8948 if (ex_event
!= EX_EVENT_THROW
8949 && ex_event
!= EX_EVENT_CATCH
)
8950 error (_("Unsupported or unknown exception event; cannot catch it"));
8952 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8955 warning (_("Unsupported with this platform/compiler combination."));
8958 /* Implementation of "catch catch" command. */
8961 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8963 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8965 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8968 /* Implementation of "catch throw" command. */
8971 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8973 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8975 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8978 /* Create a breakpoint struct for Ada exception catchpoints. */
8981 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8982 struct symtab_and_line sal
,
8986 struct expression
*cond
,
8987 struct breakpoint_ops
*ops
,
8991 struct breakpoint
*b
;
8995 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8997 loc_gdbarch
= gdbarch
;
8999 describe_other_breakpoints (loc_gdbarch
,
9000 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9001 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9002 version for exception catchpoints, because two catchpoints
9003 used for different exception names will use the same address.
9004 In this case, a "breakpoint ... also set at..." warning is
9005 unproductive. Besides. the warning phrasing is also a bit
9006 inapropriate, we should use the word catchpoint, and tell
9007 the user what type of catchpoint it is. The above is good
9008 enough for now, though. */
9011 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9012 set_breakpoint_count (breakpoint_count
+ 1);
9014 b
->enable_state
= bp_enabled
;
9015 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9016 b
->number
= breakpoint_count
;
9017 b
->ignore_count
= 0;
9018 b
->loc
->cond
= cond
;
9019 b
->addr_string
= addr_string
;
9020 b
->language
= language_ada
;
9021 b
->cond_string
= cond_string
;
9022 b
->exp_string
= exp_string
;
9027 update_global_location_list (1);
9030 /* Implement the "catch exception" command. */
9033 catch_ada_exception_command (char *arg
, int from_tty
,
9034 struct cmd_list_element
*command
)
9036 struct gdbarch
*gdbarch
= get_current_arch ();
9038 struct symtab_and_line sal
;
9039 char *addr_string
= NULL
;
9040 char *exp_string
= NULL
;
9041 char *cond_string
= NULL
;
9042 struct expression
*cond
= NULL
;
9043 struct breakpoint_ops
*ops
= NULL
;
9045 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9049 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9050 &cond_string
, &cond
, &ops
);
9051 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9052 cond_string
, cond
, ops
, tempflag
,
9056 /* Cleanup function for a syscall filter list. */
9058 clean_up_filters (void *arg
)
9060 VEC(int) *iter
= *(VEC(int) **) arg
;
9061 VEC_free (int, iter
);
9064 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9065 filter list, or NULL if no filtering is required. */
9067 catch_syscall_split_args (char *arg
)
9069 VEC(int) *result
= NULL
;
9070 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9072 while (*arg
!= '\0')
9074 int i
, syscall_number
;
9079 /* Skip whitespace. */
9080 while (isspace (*arg
))
9083 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9084 cur_name
[i
] = arg
[i
];
9088 /* Check if the user provided a syscall name or a number. */
9089 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9090 if (*endptr
== '\0')
9091 get_syscall_by_number (syscall_number
, &s
);
9094 /* We have a name. Let's check if it's valid and convert it
9096 get_syscall_by_name (cur_name
, &s
);
9098 if (s
.number
== UNKNOWN_SYSCALL
)
9099 /* Here we have to issue an error instead of a warning, because
9100 GDB cannot do anything useful if there's no syscall number to
9102 error (_("Unknown syscall name '%s'."), cur_name
);
9105 /* Ok, it's valid. */
9106 VEC_safe_push (int, result
, s
.number
);
9109 discard_cleanups (cleanup
);
9113 /* Implement the "catch syscall" command. */
9116 catch_syscall_command_1 (char *arg
, int from_tty
,
9117 struct cmd_list_element
*command
)
9122 struct gdbarch
*gdbarch
= get_current_arch ();
9124 /* Checking if the feature if supported. */
9125 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9126 error (_("The feature 'catch syscall' is not supported on \
9127 this architeture yet."));
9129 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9131 ep_skip_leading_whitespace (&arg
);
9133 /* We need to do this first "dummy" translation in order
9134 to get the syscall XML file loaded or, most important,
9135 to display a warning to the user if there's no XML file
9136 for his/her architecture. */
9137 get_syscall_by_number (0, &s
);
9139 /* The allowed syntax is:
9141 catch syscall <name | number> [<name | number> ... <name | number>]
9143 Let's check if there's a syscall name. */
9146 filter
= catch_syscall_split_args (arg
);
9150 create_syscall_event_catchpoint (tempflag
, filter
,
9151 &catch_syscall_breakpoint_ops
);
9154 /* Implement the "catch assert" command. */
9157 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9159 struct gdbarch
*gdbarch
= get_current_arch ();
9161 struct symtab_and_line sal
;
9162 char *addr_string
= NULL
;
9163 struct breakpoint_ops
*ops
= NULL
;
9165 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9169 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9170 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9171 ops
, tempflag
, from_tty
);
9175 catch_command (char *arg
, int from_tty
)
9177 error (_("Catch requires an event name."));
9182 tcatch_command (char *arg
, int from_tty
)
9184 error (_("Catch requires an event name."));
9187 /* Delete breakpoints by address or line. */
9190 clear_command (char *arg
, int from_tty
)
9192 struct breakpoint
*b
;
9193 VEC(breakpoint_p
) *found
= 0;
9196 struct symtabs_and_lines sals
;
9197 struct symtab_and_line sal
;
9202 sals
= decode_line_spec (arg
, 1);
9207 sals
.sals
= (struct symtab_and_line
*)
9208 xmalloc (sizeof (struct symtab_and_line
));
9209 make_cleanup (xfree
, sals
.sals
);
9210 init_sal (&sal
); /* initialize to zeroes */
9211 sal
.line
= default_breakpoint_line
;
9212 sal
.symtab
= default_breakpoint_symtab
;
9213 sal
.pc
= default_breakpoint_address
;
9214 sal
.pspace
= default_breakpoint_pspace
;
9215 if (sal
.symtab
== 0)
9216 error (_("No source file specified."));
9224 /* We don't call resolve_sal_pc here. That's not
9225 as bad as it seems, because all existing breakpoints
9226 typically have both file/line and pc set. So, if
9227 clear is given file/line, we can match this to existing
9228 breakpoint without obtaining pc at all.
9230 We only support clearing given the address explicitly
9231 present in breakpoint table. Say, we've set breakpoint
9232 at file:line. There were several PC values for that file:line,
9233 due to optimization, all in one block.
9234 We've picked one PC value. If "clear" is issued with another
9235 PC corresponding to the same file:line, the breakpoint won't
9236 be cleared. We probably can still clear the breakpoint, but
9237 since the other PC value is never presented to user, user
9238 can only find it by guessing, and it does not seem important
9241 /* For each line spec given, delete bps which correspond
9242 to it. Do it in two passes, solely to preserve the current
9243 behavior that from_tty is forced true if we delete more than
9247 for (i
= 0; i
< sals
.nelts
; i
++)
9249 /* If exact pc given, clear bpts at that pc.
9250 If line given (pc == 0), clear all bpts on specified line.
9251 If defaulting, clear all bpts on default line
9254 defaulting sal.pc != 0 tests to do
9259 1 0 <can't happen> */
9263 /* Find all matching breakpoints and add them to
9268 /* Are we going to delete b? */
9269 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9271 struct bp_location
*loc
= b
->loc
;
9272 for (; loc
; loc
= loc
->next
)
9274 int pc_match
= sal
.pc
9275 && (loc
->pspace
== sal
.pspace
)
9276 && (loc
->address
== sal
.pc
)
9277 && (!section_is_overlay (loc
->section
)
9278 || loc
->section
== sal
.section
);
9279 int line_match
= ((default_match
|| (0 == sal
.pc
))
9280 && b
->source_file
!= NULL
9281 && sal
.symtab
!= NULL
9282 && sal
.pspace
== loc
->pspace
9283 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
9284 && b
->line_number
== sal
.line
);
9285 if (pc_match
|| line_match
)
9294 VEC_safe_push(breakpoint_p
, found
, b
);
9297 /* Now go thru the 'found' chain and delete them. */
9298 if (VEC_empty(breakpoint_p
, found
))
9301 error (_("No breakpoint at %s."), arg
);
9303 error (_("No breakpoint at this line."));
9306 if (VEC_length(breakpoint_p
, found
) > 1)
9307 from_tty
= 1; /* Always report if deleted more than one */
9310 if (VEC_length(breakpoint_p
, found
) == 1)
9311 printf_unfiltered (_("Deleted breakpoint "));
9313 printf_unfiltered (_("Deleted breakpoints "));
9315 breakpoints_changed ();
9317 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9320 printf_unfiltered ("%d ", b
->number
);
9321 delete_breakpoint (b
);
9324 putchar_unfiltered ('\n');
9327 /* Delete breakpoint in BS if they are `delete' breakpoints and
9328 all breakpoints that are marked for deletion, whether hit or not.
9329 This is called after any breakpoint is hit, or after errors. */
9332 breakpoint_auto_delete (bpstat bs
)
9334 struct breakpoint
*b
, *b_tmp
;
9336 for (; bs
; bs
= bs
->next
)
9337 if (bs
->breakpoint_at
9338 && bs
->breakpoint_at
->disposition
== disp_del
9340 delete_breakpoint (bs
->breakpoint_at
);
9342 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9344 if (b
->disposition
== disp_del_at_next_stop
)
9345 delete_breakpoint (b
);
9349 /* A comparison function for bp_location AP and BP being interfaced to qsort.
9350 Sort elements primarily by their ADDRESS (no matter what does
9351 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
9352 first bp_permanent OWNERed elements and terciarily just ensuring the array
9353 is sorted stable way despite qsort being an instable algorithm. */
9356 bp_location_compare (const void *ap
, const void *bp
)
9358 struct bp_location
*a
= *(void **) ap
;
9359 struct bp_location
*b
= *(void **) bp
;
9360 /* A and B come from existing breakpoints having non-NULL OWNER. */
9361 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9362 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9364 if (a
->address
!= b
->address
)
9365 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9367 /* Sort permanent breakpoints first. */
9368 if (a_perm
!= b_perm
)
9369 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9371 /* Make the user-visible order stable across GDB runs. Locations of the same
9372 breakpoint can be sorted in arbitrary order. */
9374 if (a
->owner
->number
!= b
->owner
->number
)
9375 return (a
->owner
->number
> b
->owner
->number
)
9376 - (a
->owner
->number
< b
->owner
->number
);
9378 return (a
> b
) - (a
< b
);
9381 /* Set bp_location_placed_address_before_address_max and
9382 bp_location_shadow_len_after_address_max according to the current content of
9383 the bp_location array. */
9386 bp_location_target_extensions_update (void)
9388 struct bp_location
*bl
, **blp_tmp
;
9390 bp_location_placed_address_before_address_max
= 0;
9391 bp_location_shadow_len_after_address_max
= 0;
9393 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9395 CORE_ADDR start
, end
, addr
;
9397 if (!bp_location_has_shadow (bl
))
9400 start
= bl
->target_info
.placed_address
;
9401 end
= start
+ bl
->target_info
.shadow_len
;
9403 gdb_assert (bl
->address
>= start
);
9404 addr
= bl
->address
- start
;
9405 if (addr
> bp_location_placed_address_before_address_max
)
9406 bp_location_placed_address_before_address_max
= addr
;
9408 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9410 gdb_assert (bl
->address
< end
);
9411 addr
= end
- bl
->address
;
9412 if (addr
> bp_location_shadow_len_after_address_max
)
9413 bp_location_shadow_len_after_address_max
= addr
;
9417 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9418 into the inferior, only remove already-inserted locations that no
9419 longer should be inserted. Functions that delete a breakpoint or
9420 breakpoints should pass false, so that deleting a breakpoint
9421 doesn't have the side effect of inserting the locations of other
9422 breakpoints that are marked not-inserted, but should_be_inserted
9423 returns true on them.
9425 This behaviour is useful is situations close to tear-down -- e.g.,
9426 after an exec, while the target still has execution, but breakpoint
9427 shadows of the previous executable image should *NOT* be restored
9428 to the new image; or before detaching, where the target still has
9429 execution and wants to delete breakpoints from GDB's lists, and all
9430 breakpoints had already been removed from the inferior. */
9433 update_global_location_list (int should_insert
)
9435 struct breakpoint
*b
;
9436 struct bp_location
**locp
, *loc
;
9437 struct cleanup
*cleanups
;
9439 /* Used in the duplicates detection below. When iterating over all
9440 bp_locations, points to the first bp_location of a given address.
9441 Breakpoints and watchpoints of different types are never
9442 duplicates of each other. Keep one pointer for each type of
9443 breakpoint/watchpoint, so we only need to loop over all locations
9445 struct bp_location
*bp_loc_first
; /* breakpoint */
9446 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9447 struct bp_location
*awp_loc_first
; /* access watchpoint */
9448 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9450 /* Saved former bp_location array which we compare against the newly built
9451 bp_location from the current state of ALL_BREAKPOINTS. */
9452 struct bp_location
**old_location
, **old_locp
;
9453 unsigned old_location_count
;
9455 old_location
= bp_location
;
9456 old_location_count
= bp_location_count
;
9458 bp_location_count
= 0;
9459 cleanups
= make_cleanup (xfree
, old_location
);
9462 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9463 bp_location_count
++;
9465 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9468 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9470 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9471 bp_location_compare
);
9473 bp_location_target_extensions_update ();
9475 /* Identify bp_location instances that are no longer present in the new
9476 list, and therefore should be freed. Note that it's not necessary that
9477 those locations should be removed from inferior -- if there's another
9478 location at the same address (previously marked as duplicate),
9479 we don't need to remove/insert the location.
9481 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
9482 former bp_location array state respectively. */
9485 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9488 struct bp_location
*old_loc
= *old_locp
;
9489 struct bp_location
**loc2p
;
9491 /* Tells if 'old_loc' is found amoung the new locations. If not, we
9493 int found_object
= 0;
9494 /* Tells if the location should remain inserted in the target. */
9495 int keep_in_target
= 0;
9498 /* Skip LOCP entries which will definitely never be needed. Stop either
9499 at or being the one matching OLD_LOC. */
9500 while (locp
< bp_location
+ bp_location_count
9501 && (*locp
)->address
< old_loc
->address
)
9505 (loc2p
< bp_location
+ bp_location_count
9506 && (*loc2p
)->address
== old_loc
->address
);
9509 if (*loc2p
== old_loc
)
9516 /* If this location is no longer present, and inserted, look if there's
9517 maybe a new location at the same address. If so, mark that one
9518 inserted, and don't remove this one. This is needed so that we
9519 don't have a time window where a breakpoint at certain location is not
9522 if (old_loc
->inserted
)
9524 /* If the location is inserted now, we might have to remove it. */
9526 if (found_object
&& should_be_inserted (old_loc
))
9528 /* The location is still present in the location list, and still
9529 should be inserted. Don't do anything. */
9534 /* The location is either no longer present, or got disabled.
9535 See if there's another location at the same address, in which
9536 case we don't need to remove this one from the target. */
9538 /* OLD_LOC comes from existing struct breakpoint. */
9539 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9542 (loc2p
< bp_location
+ bp_location_count
9543 && (*loc2p
)->address
== old_loc
->address
);
9546 struct bp_location
*loc2
= *loc2p
;
9548 if (breakpoint_locations_match (loc2
, old_loc
))
9550 /* For the sake of should_be_inserted.
9551 Duplicates check below will fix up this later. */
9552 loc2
->duplicate
= 0;
9554 /* Read watchpoint locations are switched to
9555 access watchpoints, if the former are not
9556 supported, but the latter are. */
9557 if (is_hardware_watchpoint (old_loc
->owner
))
9559 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9560 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9563 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9566 loc2
->target_info
= old_loc
->target_info
;
9575 if (!keep_in_target
)
9577 if (remove_breakpoint (old_loc
, mark_uninserted
))
9579 /* This is just about all we can do. We could keep this
9580 location on the global list, and try to remove it next
9581 time, but there's no particular reason why we will
9584 Note that at this point, old_loc->owner is still valid,
9585 as delete_breakpoint frees the breakpoint only
9586 after calling us. */
9587 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9588 old_loc
->owner
->number
);
9596 if (removed
&& non_stop
9597 && breakpoint_address_is_meaningful (old_loc
->owner
)
9598 && !is_hardware_watchpoint (old_loc
->owner
))
9600 /* This location was removed from the target. In
9601 non-stop mode, a race condition is possible where
9602 we've removed a breakpoint, but stop events for that
9603 breakpoint are already queued and will arrive later.
9604 We apply an heuristic to be able to distinguish such
9605 SIGTRAPs from other random SIGTRAPs: we keep this
9606 breakpoint location for a bit, and will retire it
9607 after we see some number of events. The theory here
9608 is that reporting of events should, "on the average",
9609 be fair, so after a while we'll see events from all
9610 threads that have anything of interest, and no longer
9611 need to keep this breakpoint location around. We
9612 don't hold locations forever so to reduce chances of
9613 mistaking a non-breakpoint SIGTRAP for a breakpoint
9616 The heuristic failing can be disastrous on
9617 decr_pc_after_break targets.
9619 On decr_pc_after_break targets, like e.g., x86-linux,
9620 if we fail to recognize a late breakpoint SIGTRAP,
9621 because events_till_retirement has reached 0 too
9622 soon, we'll fail to do the PC adjustment, and report
9623 a random SIGTRAP to the user. When the user resumes
9624 the inferior, it will most likely immediately crash
9625 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9626 corrupted, because of being resumed e.g., in the
9627 middle of a multi-byte instruction, or skipped a
9628 one-byte instruction. This was actually seen happen
9629 on native x86-linux, and should be less rare on
9630 targets that do not support new thread events, like
9631 remote, due to the heuristic depending on
9634 Mistaking a random SIGTRAP for a breakpoint trap
9635 causes similar symptoms (PC adjustment applied when
9636 it shouldn't), but then again, playing with SIGTRAPs
9637 behind the debugger's back is asking for trouble.
9639 Since hardware watchpoint traps are always
9640 distinguishable from other traps, so we don't need to
9641 apply keep hardware watchpoint moribund locations
9642 around. We simply always ignore hardware watchpoint
9643 traps we can no longer explain. */
9645 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9646 old_loc
->owner
= NULL
;
9648 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9652 old_loc
->owner
= NULL
;
9653 decref_bp_location (&old_loc
);
9658 /* Rescan breakpoints at the same address and section, marking the
9659 first one as "first" and any others as "duplicates". This is so
9660 that the bpt instruction is only inserted once. If we have a
9661 permanent breakpoint at the same place as BPT, make that one the
9662 official one, and the rest as duplicates. Permanent breakpoints
9663 are sorted first for the same address.
9665 Do the same for hardware watchpoints, but also considering the
9666 watchpoint's type (regular/access/read) and length. */
9668 bp_loc_first
= NULL
;
9669 wp_loc_first
= NULL
;
9670 awp_loc_first
= NULL
;
9671 rwp_loc_first
= NULL
;
9672 ALL_BP_LOCATIONS (loc
, locp
)
9674 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
9675 struct breakpoint
*b
= loc
->owner
;
9676 struct bp_location
**loc_first_p
;
9678 if (b
->enable_state
== bp_disabled
9679 || b
->enable_state
== bp_call_disabled
9680 || b
->enable_state
== bp_startup_disabled
9682 || loc
->shlib_disabled
9683 || !breakpoint_address_is_meaningful (b
)
9684 || is_tracepoint (b
))
9687 /* Permanent breakpoint should always be inserted. */
9688 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9689 internal_error (__FILE__
, __LINE__
,
9690 _("allegedly permanent breakpoint is not "
9691 "actually inserted"));
9693 if (b
->type
== bp_hardware_watchpoint
)
9694 loc_first_p
= &wp_loc_first
;
9695 else if (b
->type
== bp_read_watchpoint
)
9696 loc_first_p
= &rwp_loc_first
;
9697 else if (b
->type
== bp_access_watchpoint
)
9698 loc_first_p
= &awp_loc_first
;
9700 loc_first_p
= &bp_loc_first
;
9702 if (*loc_first_p
== NULL
9703 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9704 || !breakpoint_locations_match (loc
, *loc_first_p
))
9713 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9714 && b
->enable_state
!= bp_permanent
)
9715 internal_error (__FILE__
, __LINE__
,
9716 _("another breakpoint was inserted on top of "
9717 "a permanent breakpoint"));
9720 if (breakpoints_always_inserted_mode () && should_insert
9721 && (have_live_inferiors ()
9722 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9723 insert_breakpoint_locations ();
9725 do_cleanups (cleanups
);
9729 breakpoint_retire_moribund (void)
9731 struct bp_location
*loc
;
9734 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9735 if (--(loc
->events_till_retirement
) == 0)
9737 decref_bp_location (&loc
);
9738 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9744 update_global_location_list_nothrow (int inserting
)
9746 struct gdb_exception e
;
9748 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9749 update_global_location_list (inserting
);
9752 /* Clear BKP from a BPS. */
9755 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
9759 for (bs
= bps
; bs
; bs
= bs
->next
)
9760 if (bs
->breakpoint_at
== bpt
)
9762 bs
->breakpoint_at
= NULL
;
9764 /* bs->commands will be freed later. */
9768 /* Callback for iterate_over_threads. */
9770 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9772 struct breakpoint
*bpt
= data
;
9774 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
9778 /* Delete a breakpoint and clean up all traces of it in the data
9782 delete_breakpoint (struct breakpoint
*bpt
)
9784 struct breakpoint
*b
;
9786 gdb_assert (bpt
!= NULL
);
9788 /* Has this bp already been deleted? This can happen because multiple
9789 lists can hold pointers to bp's. bpstat lists are especial culprits.
9791 One example of this happening is a watchpoint's scope bp. When the
9792 scope bp triggers, we notice that the watchpoint is out of scope, and
9793 delete it. We also delete its scope bp. But the scope bp is marked
9794 "auto-deleting", and is already on a bpstat. That bpstat is then
9795 checked for auto-deleting bp's, which are deleted.
9797 A real solution to this problem might involve reference counts in bp's,
9798 and/or giving them pointers back to their referencing bpstat's, and
9799 teaching delete_breakpoint to only free a bp's storage when no more
9800 references were extent. A cheaper bandaid was chosen. */
9801 if (bpt
->type
== bp_none
)
9804 /* At least avoid this stale reference until the reference counting of
9805 breakpoints gets resolved. */
9806 if (bpt
->related_breakpoint
!= NULL
)
9808 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9809 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9810 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9811 bpt
->related_breakpoint
= NULL
;
9814 observer_notify_breakpoint_deleted (bpt
->number
);
9816 if (breakpoint_chain
== bpt
)
9817 breakpoint_chain
= bpt
->next
;
9822 b
->next
= bpt
->next
;
9826 decref_counted_command_line (&bpt
->commands
);
9827 xfree (bpt
->cond_string
);
9828 xfree (bpt
->cond_exp
);
9829 xfree (bpt
->addr_string
);
9831 xfree (bpt
->exp_string
);
9832 xfree (bpt
->exp_string_reparse
);
9833 value_free (bpt
->val
);
9834 xfree (bpt
->source_file
);
9835 xfree (bpt
->exec_pathname
);
9836 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9839 /* Be sure no bpstat's are pointing at the breakpoint after it's
9841 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
9842 in all threeds for now. Note that we cannot just remove bpstats
9843 pointing at bpt from the stop_bpstat list entirely, as breakpoint
9844 commands are associated with the bpstat; if we remove it here,
9845 then the later call to bpstat_do_actions (&stop_bpstat); in
9846 event-top.c won't do anything, and temporary breakpoints with
9847 commands won't work. */
9849 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9851 /* Now that breakpoint is removed from breakpoint
9852 list, update the global location list. This
9853 will remove locations that used to belong to
9854 this breakpoint. Do this before freeing
9855 the breakpoint itself, since remove_breakpoint
9856 looks at location's owner. It might be better
9857 design to have location completely self-contained,
9858 but it's not the case now. */
9859 update_global_location_list (0);
9862 /* On the chance that someone will soon try again to delete this same
9863 bp, we mark it as deleted before freeing its storage. */
9864 bpt
->type
= bp_none
;
9870 do_delete_breakpoint_cleanup (void *b
)
9872 delete_breakpoint (b
);
9876 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9878 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9881 /* A callback for map_breakpoint_numbers that calls
9882 delete_breakpoint. */
9885 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9887 delete_breakpoint (b
);
9891 delete_command (char *arg
, int from_tty
)
9893 struct breakpoint
*b
, *b_tmp
;
9899 int breaks_to_delete
= 0;
9901 /* Delete all breakpoints if no argument.
9902 Do not delete internal or call-dummy breakpoints, these
9903 have to be deleted with an explicit breakpoint number argument. */
9906 if (b
->type
!= bp_call_dummy
9907 && b
->type
!= bp_std_terminate
9908 && b
->type
!= bp_shlib_event
9909 && b
->type
!= bp_jit_event
9910 && b
->type
!= bp_thread_event
9911 && b
->type
!= bp_overlay_event
9912 && b
->type
!= bp_longjmp_master
9913 && b
->type
!= bp_std_terminate_master
9914 && b
->type
!= bp_exception_master
9917 breaks_to_delete
= 1;
9922 /* Ask user only if there are some breakpoints to delete. */
9924 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9926 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9928 if (b
->type
!= bp_call_dummy
9929 && b
->type
!= bp_std_terminate
9930 && b
->type
!= bp_shlib_event
9931 && b
->type
!= bp_thread_event
9932 && b
->type
!= bp_jit_event
9933 && b
->type
!= bp_overlay_event
9934 && b
->type
!= bp_longjmp_master
9935 && b
->type
!= bp_std_terminate_master
9936 && b
->type
!= bp_exception_master
9938 delete_breakpoint (b
);
9943 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9947 all_locations_are_pending (struct bp_location
*loc
)
9949 for (; loc
; loc
= loc
->next
)
9950 if (!loc
->shlib_disabled
)
9955 /* Subroutine of update_breakpoint_locations to simplify it.
9956 Return non-zero if multiple fns in list LOC have the same name.
9957 Null names are ignored. */
9960 ambiguous_names_p (struct bp_location
*loc
)
9962 struct bp_location
*l
;
9963 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9964 (int (*) (const void *,
9965 const void *)) streq
,
9966 NULL
, xcalloc
, xfree
);
9968 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9971 const char *name
= l
->function_name
;
9973 /* Allow for some names to be NULL, ignore them. */
9977 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9979 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9993 /* When symbols change, it probably means the sources changed as well,
9994 and it might mean the static tracepoint markers are no longer at
9995 the same address or line numbers they used to be at last we
9996 checked. Losing your static tracepoints whenever you rebuild is
9997 undesirable. This function tries to resync/rematch gdb static
9998 tracepoints with the markers on the target, for static tracepoints
9999 that have not been set by marker id. Static tracepoint that have
10000 been set by marker id are reset by marker id in breakpoint_re_set.
10003 1) For a tracepoint set at a specific address, look for a marker at
10004 the old PC. If one is found there, assume to be the same marker.
10005 If the name / string id of the marker found is different from the
10006 previous known name, assume that means the user renamed the marker
10007 in the sources, and output a warning.
10009 2) For a tracepoint set at a given line number, look for a marker
10010 at the new address of the old line number. If one is found there,
10011 assume to be the same marker. If the name / string id of the
10012 marker found is different from the previous known name, assume that
10013 means the user renamed the marker in the sources, and output a
10016 3) If a marker is no longer found at the same address or line, it
10017 may mean the marker no longer exists. But it may also just mean
10018 the code changed a bit. Maybe the user added a few lines of code
10019 that made the marker move up or down (in line number terms). Ask
10020 the target for info about the marker with the string id as we knew
10021 it. If found, update line number and address in the matching
10022 static tracepoint. This will get confused if there's more than one
10023 marker with the same ID (possible in UST, although unadvised
10024 precisely because it confuses tools). */
10026 static struct symtab_and_line
10027 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10029 struct static_tracepoint_marker marker
;
10035 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10037 if (target_static_tracepoint_marker_at (pc
, &marker
))
10039 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10040 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10042 b
->static_trace_marker_id
, marker
.str_id
);
10044 xfree (b
->static_trace_marker_id
);
10045 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10046 release_static_tracepoint_marker (&marker
);
10051 /* Old marker wasn't found on target at lineno. Try looking it up
10053 if (!sal
.explicit_pc
10055 && sal
.symtab
!= NULL
10056 && b
->static_trace_marker_id
!= NULL
)
10058 VEC(static_tracepoint_marker_p
) *markers
;
10061 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10063 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10065 struct symtab_and_line sal
;
10066 struct symbol
*sym
;
10067 struct static_tracepoint_marker
*marker
;
10069 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10071 xfree (b
->static_trace_marker_id
);
10072 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10074 warning (_("marker for static tracepoint %d (%s) not "
10075 "found at previous line number"),
10076 b
->number
, b
->static_trace_marker_id
);
10080 sal
.pc
= marker
->address
;
10082 sal
= find_pc_line (marker
->address
, 0);
10083 sym
= find_pc_sect_function (marker
->address
, NULL
);
10084 ui_out_text (uiout
, "Now in ");
10087 ui_out_field_string (uiout
, "func",
10088 SYMBOL_PRINT_NAME (sym
));
10089 ui_out_text (uiout
, " at ");
10091 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
10092 ui_out_text (uiout
, ":");
10094 if (ui_out_is_mi_like_p (uiout
))
10096 char *fullname
= symtab_to_fullname (sal
.symtab
);
10099 ui_out_field_string (uiout
, "fullname", fullname
);
10102 ui_out_field_int (uiout
, "line", sal
.line
);
10103 ui_out_text (uiout
, "\n");
10105 b
->line_number
= sal
.line
;
10107 xfree (b
->source_file
);
10109 b
->source_file
= xstrdup (sal
.symtab
->filename
);
10111 b
->source_file
= NULL
;
10113 xfree (b
->addr_string
);
10114 b
->addr_string
= xstrprintf ("%s:%d",
10115 sal
.symtab
->filename
, b
->line_number
);
10117 /* Might be nice to check if function changed, and warn if
10120 release_static_tracepoint_marker (marker
);
10127 update_breakpoint_locations (struct breakpoint
*b
,
10128 struct symtabs_and_lines sals
)
10132 struct bp_location
*existing_locations
= b
->loc
;
10134 /* If there's no new locations, and all existing locations
10135 are pending, don't do anything. This optimizes
10136 the common case where all locations are in the same
10137 shared library, that was unloaded. We'd like to
10138 retain the location, so that when the library
10139 is loaded again, we don't loose the enabled/disabled
10140 status of the individual locations. */
10141 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10146 for (i
= 0; i
< sals
.nelts
; ++i
)
10148 struct bp_location
*new_loc
=
10149 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10151 /* Reparse conditions, they might contain references to the
10153 if (b
->cond_string
!= NULL
)
10155 struct gdb_exception e
;
10157 s
= b
->cond_string
;
10158 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10160 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10165 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
10166 b
->number
, e
.message
);
10167 new_loc
->enabled
= 0;
10171 if (b
->source_file
!= NULL
)
10172 xfree (b
->source_file
);
10173 if (sals
.sals
[i
].symtab
== NULL
)
10174 b
->source_file
= NULL
;
10176 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10178 if (b
->line_number
== 0)
10179 b
->line_number
= sals
.sals
[i
].line
;
10182 /* Update locations of permanent breakpoints. */
10183 if (b
->enable_state
== bp_permanent
)
10184 make_breakpoint_permanent (b
);
10186 /* If possible, carry over 'disable' status from existing breakpoints. */
10188 struct bp_location
*e
= existing_locations
;
10189 /* If there are multiple breakpoints with the same function name,
10190 e.g. for inline functions, comparing function names won't work.
10191 Instead compare pc addresses; this is just a heuristic as things
10192 may have moved, but in practice it gives the correct answer
10193 often enough until a better solution is found. */
10194 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10196 for (; e
; e
= e
->next
)
10198 if (!e
->enabled
&& e
->function_name
)
10200 struct bp_location
*l
= b
->loc
;
10201 if (have_ambiguous_names
)
10203 for (; l
; l
= l
->next
)
10204 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10205 l
->pspace
->aspace
, l
->address
))
10213 for (; l
; l
= l
->next
)
10214 if (l
->function_name
10215 && strcmp (e
->function_name
, l
->function_name
) == 0)
10225 update_global_location_list (1);
10228 /* Reset a breakpoint given it's struct breakpoint * BINT.
10229 The value we return ends up being the return value from catch_errors.
10230 Unused in this case. */
10233 breakpoint_re_set_one (void *bint
)
10235 /* get past catch_errs */
10236 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10238 int *not_found_ptr
= ¬_found
;
10239 struct symtabs_and_lines sals
= {0};
10240 struct symtabs_and_lines expanded
= {0};
10242 struct gdb_exception e
;
10243 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10244 int marker_spec
= 0;
10249 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10252 case bp_breakpoint
:
10253 case bp_hardware_breakpoint
:
10254 case bp_tracepoint
:
10255 case bp_fast_tracepoint
:
10256 case bp_static_tracepoint
:
10257 /* Do not attempt to re-set breakpoints disabled during startup. */
10258 if (b
->enable_state
== bp_startup_disabled
)
10261 if (b
->addr_string
== NULL
)
10263 /* Anything without a string can't be re-set. */
10264 delete_breakpoint (b
);
10268 input_radix
= b
->input_radix
;
10269 s
= b
->addr_string
;
10271 save_current_space_and_thread ();
10272 switch_to_program_space_and_thread (b
->pspace
);
10274 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10276 set_language (b
->language
);
10277 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10281 sals
= decode_static_tracepoint_spec (&s
);
10282 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10284 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10288 error (_("marker %s not found"), b
->static_trace_marker_id
);
10291 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
10296 int not_found_and_ok
= 0;
10297 /* For pending breakpoints, it's expected that parsing
10298 will fail until the right shared library is loaded.
10299 User has already told to create pending breakpoints and
10300 don't need extra messages. If breakpoint is in bp_shlib_disabled
10301 state, then user already saw the message about that breakpoint
10302 being disabled, and don't want to see more errors. */
10304 && (b
->condition_not_parsed
10305 || (b
->loc
&& b
->loc
->shlib_disabled
)
10306 || b
->enable_state
== bp_disabled
))
10307 not_found_and_ok
= 1;
10309 if (!not_found_and_ok
)
10311 /* We surely don't want to warn about the same breakpoint
10312 10 times. One solution, implemented here, is disable
10313 the breakpoint on error. Another solution would be to
10314 have separate 'warning emitted' flag. Since this
10315 happens only when a binary has changed, I don't know
10316 which approach is better. */
10317 b
->enable_state
= bp_disabled
;
10318 throw_exception (e
);
10324 gdb_assert (sals
.nelts
== 1);
10326 resolve_sal_pc (&sals
.sals
[0]);
10327 if (b
->condition_not_parsed
&& s
&& s
[0])
10329 char *cond_string
= 0;
10333 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10334 &cond_string
, &thread
, &task
);
10336 b
->cond_string
= cond_string
;
10337 b
->thread
= thread
;
10339 b
->condition_not_parsed
= 0;
10342 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10343 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10345 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10348 make_cleanup (xfree
, sals
.sals
);
10349 update_breakpoint_locations (b
, expanded
);
10352 case bp_watchpoint
:
10353 case bp_hardware_watchpoint
:
10354 case bp_read_watchpoint
:
10355 case bp_access_watchpoint
:
10356 /* Watchpoint can be either on expression using entirely global variables,
10357 or it can be on local variables.
10359 Watchpoints of the first kind are never auto-deleted, and even persist
10360 across program restarts. Since they can use variables from shared
10361 libraries, we need to reparse expression as libraries are loaded
10364 Watchpoints on local variables can also change meaning as result
10365 of solib event. For example, if a watchpoint uses both a local and
10366 a global variables in expression, it's a local watchpoint, but
10367 unloading of a shared library will make the expression invalid.
10368 This is not a very common use case, but we still re-evaluate
10369 expression, to avoid surprises to the user.
10371 Note that for local watchpoints, we re-evaluate it only if
10372 watchpoints frame id is still valid. If it's not, it means
10373 the watchpoint is out of scope and will be deleted soon. In fact,
10374 I'm not sure we'll ever be called in this case.
10376 If a local watchpoint's frame id is still valid, then
10377 b->exp_valid_block is likewise valid, and we can safely use it.
10379 Don't do anything about disabled watchpoints, since they will
10380 be reevaluated again when enabled. */
10381 update_watchpoint (b
, 1 /* reparse */);
10383 /* We needn't really do anything to reset these, since the mask
10384 that requests them is unaffected by e.g., new libraries being
10386 case bp_catchpoint
:
10390 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10392 /* Delete overlay event and longjmp master breakpoints; they will be
10393 reset later by breakpoint_re_set. */
10394 case bp_overlay_event
:
10395 case bp_longjmp_master
:
10396 case bp_std_terminate_master
:
10397 case bp_exception_master
:
10398 delete_breakpoint (b
);
10401 /* This breakpoint is special, it's set up when the inferior
10402 starts and we really don't want to touch it. */
10403 case bp_shlib_event
:
10405 /* Like bp_shlib_event, this breakpoint type is special.
10406 Once it is set up, we do not want to touch it. */
10407 case bp_thread_event
:
10409 /* Keep temporary breakpoints, which can be encountered when we step
10410 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
10411 Otherwise these should have been blown away via the cleanup chain
10412 or by breakpoint_init_inferior when we rerun the executable. */
10415 case bp_watchpoint_scope
:
10416 case bp_call_dummy
:
10417 case bp_std_terminate
:
10418 case bp_step_resume
:
10420 case bp_longjmp_resume
:
10422 case bp_exception_resume
:
10427 do_cleanups (cleanups
);
10431 /* Re-set all breakpoints after symbols have been re-loaded. */
10433 breakpoint_re_set (void)
10435 struct breakpoint
*b
, *b_tmp
;
10436 enum language save_language
;
10437 int save_input_radix
;
10438 struct cleanup
*old_chain
;
10440 save_language
= current_language
->la_language
;
10441 save_input_radix
= input_radix
;
10442 old_chain
= save_current_program_space ();
10444 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10446 /* Format possible error msg */
10447 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10449 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10450 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10451 do_cleanups (cleanups
);
10453 set_language (save_language
);
10454 input_radix
= save_input_radix
;
10456 jit_breakpoint_re_set ();
10458 do_cleanups (old_chain
);
10460 create_overlay_event_breakpoint ("_ovly_debug_event");
10461 create_longjmp_master_breakpoint ("longjmp");
10462 create_longjmp_master_breakpoint ("_longjmp");
10463 create_longjmp_master_breakpoint ("siglongjmp");
10464 create_longjmp_master_breakpoint ("_siglongjmp");
10465 create_std_terminate_master_breakpoint ("std::terminate()");
10466 create_exception_master_breakpoint ();
10469 /* Reset the thread number of this breakpoint:
10471 - If the breakpoint is for all threads, leave it as-is.
10472 - Else, reset it to the current thread for inferior_ptid. */
10474 breakpoint_re_set_thread (struct breakpoint
*b
)
10476 if (b
->thread
!= -1)
10478 if (in_thread_list (inferior_ptid
))
10479 b
->thread
= pid_to_thread_id (inferior_ptid
);
10481 /* We're being called after following a fork. The new fork is
10482 selected as current, and unless this was a vfork will have a
10483 different program space from the original thread. Reset that
10485 b
->loc
->pspace
= current_program_space
;
10489 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10490 If from_tty is nonzero, it prints a message to that effect,
10491 which ends with a period (no newline). */
10494 set_ignore_count (int bptnum
, int count
, int from_tty
)
10496 struct breakpoint
*b
;
10501 ALL_BREAKPOINTS (b
)
10502 if (b
->number
== bptnum
)
10504 if (is_tracepoint (b
))
10506 if (from_tty
&& count
!= 0)
10507 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10512 b
->ignore_count
= count
;
10516 printf_filtered (_("Will stop next time breakpoint %d is reached."),
10518 else if (count
== 1)
10519 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10522 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
10525 breakpoints_changed ();
10526 observer_notify_breakpoint_modified (b
->number
);
10530 error (_("No breakpoint number %d."), bptnum
);
10534 make_breakpoint_silent (struct breakpoint
*b
)
10536 /* Silence the breakpoint. */
10540 /* Command to set ignore-count of breakpoint N to COUNT. */
10543 ignore_command (char *args
, int from_tty
)
10549 error_no_arg (_("a breakpoint number"));
10551 num
= get_number (&p
);
10553 error (_("bad breakpoint number: '%s'"), args
);
10555 error (_("Second argument (specified ignore-count) is missing."));
10557 set_ignore_count (num
,
10558 longest_to_int (value_as_long (parse_and_eval (p
))),
10561 printf_filtered ("\n");
10564 /* Call FUNCTION on each of the breakpoints
10565 whose numbers are given in ARGS. */
10568 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10575 struct breakpoint
*b
, *tmp
;
10579 error_no_arg (_("one or more breakpoint numbers"));
10586 num
= get_number_or_range (&p1
);
10589 warning (_("bad breakpoint number at or near '%s'"), p
);
10593 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10594 if (b
->number
== num
)
10596 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10598 function (b
, data
);
10599 if (related_breakpoint
)
10600 function (related_breakpoint
, data
);
10604 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
10610 static struct bp_location
*
10611 find_location_by_number (char *number
)
10613 char *dot
= strchr (number
, '.');
10617 struct breakpoint
*b
;
10618 struct bp_location
*loc
;
10623 bp_num
= get_number_or_range (&p1
);
10625 error (_("Bad breakpoint number '%s'"), number
);
10627 ALL_BREAKPOINTS (b
)
10628 if (b
->number
== bp_num
)
10633 if (!b
|| b
->number
!= bp_num
)
10634 error (_("Bad breakpoint number '%s'"), number
);
10637 loc_num
= get_number_or_range (&p1
);
10639 error (_("Bad breakpoint location number '%s'"), number
);
10643 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
10646 error (_("Bad breakpoint location number '%s'"), dot
+1);
10652 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10653 If from_tty is nonzero, it prints a message to that effect,
10654 which ends with a period (no newline). */
10657 disable_breakpoint (struct breakpoint
*bpt
)
10659 /* Never disable a watchpoint scope breakpoint; we want to
10660 hit them when we leave scope so we can delete both the
10661 watchpoint and its scope breakpoint at that time. */
10662 if (bpt
->type
== bp_watchpoint_scope
)
10665 /* You can't disable permanent breakpoints. */
10666 if (bpt
->enable_state
== bp_permanent
)
10669 bpt
->enable_state
= bp_disabled
;
10671 update_global_location_list (0);
10673 observer_notify_breakpoint_modified (bpt
->number
);
10676 /* A callback for map_breakpoint_numbers that calls
10677 disable_breakpoint. */
10680 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
10682 disable_breakpoint (b
);
10686 disable_command (char *args
, int from_tty
)
10688 struct breakpoint
*bpt
;
10691 ALL_BREAKPOINTS (bpt
)
10695 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10698 case bp_breakpoint
:
10699 case bp_tracepoint
:
10700 case bp_fast_tracepoint
:
10701 case bp_static_tracepoint
:
10702 case bp_catchpoint
:
10703 case bp_hardware_breakpoint
:
10704 case bp_watchpoint
:
10705 case bp_hardware_watchpoint
:
10706 case bp_read_watchpoint
:
10707 case bp_access_watchpoint
:
10708 disable_breakpoint (bpt
);
10712 else if (strchr (args
, '.'))
10714 struct bp_location
*loc
= find_location_by_number (args
);
10717 update_global_location_list (0);
10720 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10724 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10726 int target_resources_ok
;
10728 if (bpt
->type
== bp_hardware_breakpoint
)
10731 i
= hw_breakpoint_used_count ();
10732 target_resources_ok
=
10733 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10735 if (target_resources_ok
== 0)
10736 error (_("No hardware breakpoint support in the target."));
10737 else if (target_resources_ok
< 0)
10738 error (_("Hardware breakpoints used exceeds limit."));
10741 if (is_watchpoint (bpt
))
10743 struct gdb_exception e
;
10745 TRY_CATCH (e
, RETURN_MASK_ALL
)
10747 update_watchpoint (bpt
, 1 /* reparse */);
10751 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10757 if (bpt
->enable_state
!= bp_permanent
)
10758 bpt
->enable_state
= bp_enabled
;
10759 bpt
->disposition
= disposition
;
10760 update_global_location_list (1);
10761 breakpoints_changed ();
10763 observer_notify_breakpoint_modified (bpt
->number
);
10768 enable_breakpoint (struct breakpoint
*bpt
)
10770 do_enable_breakpoint (bpt
, bpt
->disposition
);
10773 /* A callback for map_breakpoint_numbers that calls
10774 enable_breakpoint. */
10777 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10779 enable_breakpoint (b
);
10782 /* The enable command enables the specified breakpoints (or all defined
10783 breakpoints) so they once again become (or continue to be) effective
10784 in stopping the inferior. */
10787 enable_command (char *args
, int from_tty
)
10789 struct breakpoint
*bpt
;
10792 ALL_BREAKPOINTS (bpt
)
10796 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10799 case bp_breakpoint
:
10800 case bp_tracepoint
:
10801 case bp_fast_tracepoint
:
10802 case bp_static_tracepoint
:
10803 case bp_catchpoint
:
10804 case bp_hardware_breakpoint
:
10805 case bp_watchpoint
:
10806 case bp_hardware_watchpoint
:
10807 case bp_read_watchpoint
:
10808 case bp_access_watchpoint
:
10809 enable_breakpoint (bpt
);
10813 else if (strchr (args
, '.'))
10815 struct bp_location
*loc
= find_location_by_number (args
);
10818 update_global_location_list (1);
10821 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10825 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10827 do_enable_breakpoint (bpt
, disp_disable
);
10831 enable_once_command (char *args
, int from_tty
)
10833 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10837 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10839 do_enable_breakpoint (bpt
, disp_del
);
10843 enable_delete_command (char *args
, int from_tty
)
10845 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10849 set_breakpoint_cmd (char *args
, int from_tty
)
10854 show_breakpoint_cmd (char *args
, int from_tty
)
10858 /* Invalidate last known value of any hardware watchpoint if
10859 the memory which that value represents has been written to by
10863 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10864 const bfd_byte
*data
)
10866 struct breakpoint
*bp
;
10868 ALL_BREAKPOINTS (bp
)
10869 if (bp
->enable_state
== bp_enabled
10870 && bp
->type
== bp_hardware_watchpoint
10871 && bp
->val_valid
&& bp
->val
)
10873 struct bp_location
*loc
;
10875 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10876 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10877 && loc
->address
+ loc
->length
> addr
10878 && addr
+ len
> loc
->address
)
10880 value_free (bp
->val
);
10887 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10889 struct symtabs_and_lines
10890 decode_line_spec_1 (char *string
, int funfirstline
)
10892 struct symtabs_and_lines sals
;
10895 error (_("Empty line specification."));
10896 if (default_breakpoint_valid
)
10897 sals
= decode_line_1 (&string
, funfirstline
,
10898 default_breakpoint_symtab
,
10899 default_breakpoint_line
,
10900 (char ***) NULL
, NULL
);
10902 sals
= decode_line_1 (&string
, funfirstline
,
10903 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10905 error (_("Junk at end of line specification: %s"), string
);
10909 /* Create and insert a raw software breakpoint at PC. Return an
10910 identifier, which should be used to remove the breakpoint later.
10911 In general, places which call this should be using something on the
10912 breakpoint chain instead; this function should be eliminated
10916 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10917 struct address_space
*aspace
, CORE_ADDR pc
)
10919 struct bp_target_info
*bp_tgt
;
10921 bp_tgt
= XZALLOC (struct bp_target_info
);
10923 bp_tgt
->placed_address_space
= aspace
;
10924 bp_tgt
->placed_address
= pc
;
10926 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10928 /* Could not insert the breakpoint. */
10936 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10939 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10941 struct bp_target_info
*bp_tgt
= bp
;
10944 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10950 /* One (or perhaps two) breakpoints used for software single stepping. */
10952 static void *single_step_breakpoints
[2];
10953 static struct gdbarch
*single_step_gdbarch
[2];
10955 /* Create and insert a breakpoint for software single step. */
10958 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10959 struct address_space
*aspace
, CORE_ADDR next_pc
)
10963 if (single_step_breakpoints
[0] == NULL
)
10965 bpt_p
= &single_step_breakpoints
[0];
10966 single_step_gdbarch
[0] = gdbarch
;
10970 gdb_assert (single_step_breakpoints
[1] == NULL
);
10971 bpt_p
= &single_step_breakpoints
[1];
10972 single_step_gdbarch
[1] = gdbarch
;
10975 /* NOTE drow/2006-04-11: A future improvement to this function would be
10976 to only create the breakpoints once, and actually put them on the
10977 breakpoint chain. That would let us use set_raw_breakpoint. We could
10978 adjust the addresses each time they were needed. Doing this requires
10979 corresponding changes elsewhere where single step breakpoints are
10980 handled, however. So, for now, we use this. */
10982 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10983 if (*bpt_p
== NULL
)
10984 error (_("Could not insert single-step breakpoint at %s"),
10985 paddress (gdbarch
, next_pc
));
10988 /* Check if the breakpoints used for software single stepping
10989 were inserted or not. */
10992 single_step_breakpoints_inserted (void)
10994 return (single_step_breakpoints
[0] != NULL
10995 || single_step_breakpoints
[1] != NULL
);
10998 /* Remove and delete any breakpoints used for software single step. */
11001 remove_single_step_breakpoints (void)
11003 gdb_assert (single_step_breakpoints
[0] != NULL
);
11005 /* See insert_single_step_breakpoint for more about this deprecated
11007 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
11008 single_step_breakpoints
[0]);
11009 single_step_gdbarch
[0] = NULL
;
11010 single_step_breakpoints
[0] = NULL
;
11012 if (single_step_breakpoints
[1] != NULL
)
11014 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
11015 single_step_breakpoints
[1]);
11016 single_step_gdbarch
[1] = NULL
;
11017 single_step_breakpoints
[1] = NULL
;
11021 /* Delete software single step breakpoints without removing them from
11022 the inferior. This is intended to be used if the inferior's address
11023 space where they were inserted is already gone, e.g. after exit or
11027 cancel_single_step_breakpoints (void)
11031 for (i
= 0; i
< 2; i
++)
11032 if (single_step_breakpoints
[i
])
11034 xfree (single_step_breakpoints
[i
]);
11035 single_step_breakpoints
[i
] = NULL
;
11036 single_step_gdbarch
[i
] = NULL
;
11040 /* Detach software single-step breakpoints from INFERIOR_PTID without
11044 detach_single_step_breakpoints (void)
11048 for (i
= 0; i
< 2; i
++)
11049 if (single_step_breakpoints
[i
])
11050 target_remove_breakpoint (single_step_gdbarch
[i
],
11051 single_step_breakpoints
[i
]);
11054 /* Check whether a software single-step breakpoint is inserted at PC. */
11057 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
11062 for (i
= 0; i
< 2; i
++)
11064 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
11066 && breakpoint_address_match (bp_tgt
->placed_address_space
,
11067 bp_tgt
->placed_address
,
11075 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11076 non-zero otherwise. */
11078 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
11080 if (syscall_catchpoint_p (bp
)
11081 && bp
->enable_state
!= bp_disabled
11082 && bp
->enable_state
!= bp_call_disabled
)
11089 catch_syscall_enabled (void)
11091 struct inferior
*inf
= current_inferior ();
11093 return inf
->total_syscalls_count
!= 0;
11097 catching_syscall_number (int syscall_number
)
11099 struct breakpoint
*bp
;
11101 ALL_BREAKPOINTS (bp
)
11102 if (is_syscall_catchpoint_enabled (bp
))
11104 if (bp
->syscalls_to_be_caught
)
11108 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
11110 if (syscall_number
== iter
)
11120 /* Complete syscall names. Used by "catch syscall". */
11122 catch_syscall_completer (struct cmd_list_element
*cmd
,
11123 char *text
, char *word
)
11125 const char **list
= get_syscall_names ();
11127 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
11130 /* Tracepoint-specific operations. */
11132 /* Set tracepoint count to NUM. */
11134 set_tracepoint_count (int num
)
11136 tracepoint_count
= num
;
11137 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11141 trace_command (char *arg
, int from_tty
)
11143 if (create_breakpoint (get_current_arch (),
11145 NULL
, 0, 1 /* parse arg */,
11147 bp_tracepoint
/* type_wanted */,
11148 0 /* Ignore count */,
11149 pending_break_support
,
11154 set_tracepoint_count (breakpoint_count
);
11158 ftrace_command (char *arg
, int from_tty
)
11160 if (create_breakpoint (get_current_arch (),
11162 NULL
, 0, 1 /* parse arg */,
11164 bp_fast_tracepoint
/* type_wanted */,
11165 0 /* Ignore count */,
11166 pending_break_support
,
11171 set_tracepoint_count (breakpoint_count
);
11174 /* strace command implementation. Creates a static tracepoint. */
11177 strace_command (char *arg
, int from_tty
)
11179 if (create_breakpoint (get_current_arch (),
11181 NULL
, 0, 1 /* parse arg */,
11183 bp_static_tracepoint
/* type_wanted */,
11184 0 /* Ignore count */,
11185 pending_break_support
,
11190 set_tracepoint_count (breakpoint_count
);
11193 /* Set up a fake reader function that gets command lines from a linked
11194 list that was acquired during tracepoint uploading. */
11196 static struct uploaded_tp
*this_utp
;
11197 static int next_cmd
;
11200 read_uploaded_action (void)
11204 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11211 /* Given information about a tracepoint as recorded on a target (which
11212 can be either a live system or a trace file), attempt to create an
11213 equivalent GDB tracepoint. This is not a reliable process, since
11214 the target does not necessarily have all the information used when
11215 the tracepoint was originally defined. */
11217 struct breakpoint
*
11218 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11220 char *addr_str
, small_buf
[100];
11221 struct breakpoint
*tp
;
11223 if (utp
->at_string
)
11224 addr_str
= utp
->at_string
;
11227 /* In the absence of a source location, fall back to raw
11228 address. Since there is no way to confirm that the address
11229 means the same thing as when the trace was started, warn the
11231 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
11233 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11234 addr_str
= small_buf
;
11237 /* There's not much we can do with a sequence of bytecodes. */
11238 if (utp
->cond
&& !utp
->cond_string
)
11239 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
11242 if (!create_breakpoint (get_current_arch (),
11244 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11246 utp
->type
/* type_wanted */,
11247 0 /* Ignore count */,
11248 pending_break_support
,
11251 utp
->enabled
/* enabled */,
11255 set_tracepoint_count (breakpoint_count
);
11257 /* Get the tracepoint we just created. */
11258 tp
= get_tracepoint (tracepoint_count
);
11259 gdb_assert (tp
!= NULL
);
11263 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11265 trace_pass_command (small_buf
, 0);
11268 /* If we have uploaded versions of the original commands, set up a
11269 special-purpose "reader" function and call the usual command line
11270 reader, then pass the result to the breakpoint command-setting
11272 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11274 struct command_line
*cmd_list
;
11279 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11281 breakpoint_set_commands (tp
, cmd_list
);
11283 else if (!VEC_empty (char_ptr
, utp
->actions
)
11284 || !VEC_empty (char_ptr
, utp
->step_actions
))
11285 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
11291 /* Print information on tracepoint number TPNUM_EXP, or all if
11295 tracepoints_info (char *tpnum_exp
, int from_tty
)
11297 int tpnum
= -1, num_printed
;
11300 tpnum
= parse_and_eval_long (tpnum_exp
);
11302 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
11304 if (num_printed
== 0)
11307 ui_out_message (uiout
, 0, "No tracepoints.\n");
11309 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
11312 default_collect_info ();
11315 /* The 'enable trace' command enables tracepoints.
11316 Not supported by all targets. */
11318 enable_trace_command (char *args
, int from_tty
)
11320 enable_command (args
, from_tty
);
11323 /* The 'disable trace' command disables tracepoints.
11324 Not supported by all targets. */
11326 disable_trace_command (char *args
, int from_tty
)
11328 disable_command (args
, from_tty
);
11331 /* Remove a tracepoint (or all if no argument) */
11333 delete_trace_command (char *arg
, int from_tty
)
11335 struct breakpoint
*b
, *b_tmp
;
11341 int breaks_to_delete
= 0;
11343 /* Delete all breakpoints if no argument.
11344 Do not delete internal or call-dummy breakpoints, these
11345 have to be deleted with an explicit breakpoint number argument. */
11346 ALL_TRACEPOINTS (b
)
11348 if (b
->number
>= 0)
11350 breaks_to_delete
= 1;
11355 /* Ask user only if there are some breakpoints to delete. */
11357 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11359 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11361 if (is_tracepoint (b
)
11363 delete_breakpoint (b
);
11368 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11371 /* Set passcount for tracepoint.
11373 First command argument is passcount, second is tracepoint number.
11374 If tracepoint number omitted, apply to most recently defined.
11375 Also accepts special argument "all". */
11378 trace_pass_command (char *args
, int from_tty
)
11380 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11381 unsigned int count
;
11384 if (args
== 0 || *args
== 0)
11385 error (_("passcount command requires an argument (count + optional TP num)"));
11387 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11389 while (*args
&& isspace ((int) *args
))
11392 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11394 args
+= 3; /* Skip special argument "all". */
11397 error (_("Junk at end of arguments."));
11400 t1
= get_tracepoint_by_number (&args
, 1, 1);
11406 ALL_TRACEPOINTS (t2
)
11407 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11409 t2
->pass_count
= count
;
11410 observer_notify_tracepoint_modified (t2
->number
);
11412 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
11413 t2
->number
, count
);
11415 if (! all
&& *args
)
11416 t1
= get_tracepoint_by_number (&args
, 1, 0);
11422 struct breakpoint
*
11423 get_tracepoint (int num
)
11425 struct breakpoint
*t
;
11427 ALL_TRACEPOINTS (t
)
11428 if (t
->number
== num
)
11434 /* Find the tracepoint with the given target-side number (which may be
11435 different from the tracepoint number after disconnecting and
11438 struct breakpoint
*
11439 get_tracepoint_by_number_on_target (int num
)
11441 struct breakpoint
*t
;
11443 ALL_TRACEPOINTS (t
)
11444 if (t
->number_on_target
== num
)
11450 /* Utility: parse a tracepoint number and look it up in the list.
11451 If MULTI_P is true, there might be a range of tracepoints in ARG.
11452 if OPTIONAL_P is true, then if the argument is missing, the most
11453 recent tracepoint (tracepoint_count) is returned. */
11454 struct breakpoint
*
11455 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11457 extern int tracepoint_count
;
11458 struct breakpoint
*t
;
11460 char *instring
= arg
== NULL
? NULL
: *arg
;
11462 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11465 tpnum
= tracepoint_count
;
11467 error_no_arg (_("tracepoint number"));
11470 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11474 if (instring
&& *instring
)
11475 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11478 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
11482 ALL_TRACEPOINTS (t
)
11483 if (t
->number
== tpnum
)
11488 /* FIXME: if we are in the middle of a range we don't want to give
11489 a message. The current interface to get_number_or_range doesn't
11490 allow us to discover this. */
11491 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11495 /* Save information on user settable breakpoints (watchpoints, etc) to
11496 a new script file named FILENAME. If FILTER is non-NULL, call it
11497 on each breakpoint and only include the ones for which it returns
11501 save_breakpoints (char *filename
, int from_tty
,
11502 int (*filter
) (const struct breakpoint
*))
11504 struct breakpoint
*tp
;
11507 struct cleanup
*cleanup
;
11508 struct ui_file
*fp
;
11509 int extra_trace_bits
= 0;
11511 if (filename
== 0 || *filename
== 0)
11512 error (_("Argument required (file name in which to save)"));
11514 /* See if we have anything to save. */
11515 ALL_BREAKPOINTS (tp
)
11517 /* Skip internal and momentary breakpoints. */
11518 if (!user_settable_breakpoint (tp
) || tp
->number
< 0)
11521 /* If we have a filter, only save the breakpoints it accepts. */
11522 if (filter
&& !filter (tp
))
11527 if (is_tracepoint (tp
))
11529 extra_trace_bits
= 1;
11531 /* We can stop searching. */
11538 warning (_("Nothing to save."));
11542 pathname
= tilde_expand (filename
);
11543 cleanup
= make_cleanup (xfree
, pathname
);
11544 fp
= gdb_fopen (pathname
, "w");
11546 error (_("Unable to open file '%s' for saving (%s)"),
11547 filename
, safe_strerror (errno
));
11548 make_cleanup_ui_file_delete (fp
);
11550 if (extra_trace_bits
)
11551 save_trace_state_variables (fp
);
11553 ALL_BREAKPOINTS (tp
)
11555 /* Skip internal and momentary breakpoints. */
11556 if (!user_settable_breakpoint (tp
) || tp
->number
< 0)
11559 /* If we have a filter, only save the breakpoints it accepts. */
11560 if (filter
&& !filter (tp
))
11563 if (tp
->ops
!= NULL
)
11564 (tp
->ops
->print_recreate
) (tp
, fp
);
11567 if (tp
->type
== bp_fast_tracepoint
)
11568 fprintf_unfiltered (fp
, "ftrace");
11569 if (tp
->type
== bp_static_tracepoint
)
11570 fprintf_unfiltered (fp
, "strace");
11571 else if (tp
->type
== bp_tracepoint
)
11572 fprintf_unfiltered (fp
, "trace");
11573 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11574 fprintf_unfiltered (fp
, "tbreak");
11575 else if (tp
->type
== bp_breakpoint
)
11576 fprintf_unfiltered (fp
, "break");
11577 else if (tp
->type
== bp_hardware_breakpoint
11578 && tp
->disposition
== disp_del
)
11579 fprintf_unfiltered (fp
, "thbreak");
11580 else if (tp
->type
== bp_hardware_breakpoint
)
11581 fprintf_unfiltered (fp
, "hbreak");
11582 else if (tp
->type
== bp_watchpoint
)
11583 fprintf_unfiltered (fp
, "watch");
11584 else if (tp
->type
== bp_hardware_watchpoint
)
11585 fprintf_unfiltered (fp
, "watch");
11586 else if (tp
->type
== bp_read_watchpoint
)
11587 fprintf_unfiltered (fp
, "rwatch");
11588 else if (tp
->type
== bp_access_watchpoint
)
11589 fprintf_unfiltered (fp
, "awatch");
11591 internal_error (__FILE__
, __LINE__
,
11592 _("unhandled breakpoint type %d"), (int) tp
->type
);
11594 if (tp
->exp_string
)
11595 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11596 else if (tp
->addr_string
)
11597 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11602 sprintf_vma (tmp
, tp
->loc
->address
);
11603 fprintf_unfiltered (fp
, " *0x%s", tmp
);
11607 if (tp
->thread
!= -1)
11608 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
11611 fprintf_unfiltered (fp
, " task %d", tp
->task
);
11613 fprintf_unfiltered (fp
, "\n");
11615 /* Note, we can't rely on tp->number for anything, as we can't
11616 assume the recreated breakpoint numbers will match. Use $bpnum
11619 if (tp
->cond_string
)
11620 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
11622 if (tp
->ignore_count
)
11623 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
11625 if (tp
->pass_count
)
11626 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11630 volatile struct gdb_exception ex
;
11632 fprintf_unfiltered (fp
, " commands\n");
11634 ui_out_redirect (uiout
, fp
);
11635 TRY_CATCH (ex
, RETURN_MASK_ALL
)
11637 print_command_lines (uiout
, tp
->commands
->commands
, 2);
11639 ui_out_redirect (uiout
, NULL
);
11642 throw_exception (ex
);
11644 fprintf_unfiltered (fp
, " end\n");
11647 if (tp
->enable_state
== bp_disabled
)
11648 fprintf_unfiltered (fp
, "disable\n");
11650 /* If this is a multi-location breakpoint, check if the locations
11651 should be individually disabled. Watchpoint locations are
11652 special, and not user visible. */
11653 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
11655 struct bp_location
*loc
;
11658 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
11660 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
11664 if (extra_trace_bits
&& *default_collect
)
11665 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
11667 do_cleanups (cleanup
);
11669 printf_filtered (_("Saved to file '%s'.\n"), filename
);
11672 /* The `save breakpoints' command. */
11675 save_breakpoints_command (char *args
, int from_tty
)
11677 save_breakpoints (args
, from_tty
, NULL
);
11680 /* The `save tracepoints' command. */
11683 save_tracepoints_command (char *args
, int from_tty
)
11685 save_breakpoints (args
, from_tty
, is_tracepoint
);
11688 /* Create a vector of all tracepoints. */
11690 VEC(breakpoint_p
) *
11693 VEC(breakpoint_p
) *tp_vec
= 0;
11694 struct breakpoint
*tp
;
11696 ALL_TRACEPOINTS (tp
)
11698 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
11705 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
11706 It is defined as a macro to prevent duplication.
11707 COMMAND should be a string constant containing the name of the command. */
11708 #define BREAK_ARGS_HELP(command) \
11709 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11710 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11711 If a line number is specified, break at start of code for that line.\n\
11712 If a function is specified, break at start of code for that function.\n\
11713 If an address is specified, break at that exact address.\n\
11714 With no LOCATION, uses current execution address of the selected\n\
11715 stack frame. This is useful for breaking on return to a stack frame.\n\
11717 THREADNUM is the number from \"info threads\".\n\
11718 CONDITION is a boolean expression.\n\
11720 Multiple breakpoints at one place are permitted, and useful if their\n\
11721 conditions are different.\n\
11723 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11725 /* List of subcommands for "catch". */
11726 static struct cmd_list_element
*catch_cmdlist
;
11728 /* List of subcommands for "tcatch". */
11729 static struct cmd_list_element
*tcatch_cmdlist
;
11731 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11732 lists, and pass some additional user data to the command function. */
11734 add_catch_command (char *name
, char *docstring
,
11735 void (*sfunc
) (char *args
, int from_tty
,
11736 struct cmd_list_element
*command
),
11737 char **(*completer
) (struct cmd_list_element
*cmd
,
11738 char *text
, char *word
),
11739 void *user_data_catch
,
11740 void *user_data_tcatch
)
11742 struct cmd_list_element
*command
;
11744 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11746 set_cmd_sfunc (command
, sfunc
);
11747 set_cmd_context (command
, user_data_catch
);
11748 set_cmd_completer (command
, completer
);
11750 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11752 set_cmd_sfunc (command
, sfunc
);
11753 set_cmd_context (command
, user_data_tcatch
);
11754 set_cmd_completer (command
, completer
);
11758 clear_syscall_counts (struct inferior
*inf
)
11760 inf
->total_syscalls_count
= 0;
11761 inf
->any_syscall_count
= 0;
11762 VEC_free (int, inf
->syscalls_counts
);
11766 save_command (char *arg
, int from_tty
)
11768 printf_unfiltered (_("\
11769 \"save\" must be followed by the name of a save subcommand.\n"));
11770 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
11773 struct breakpoint
*
11774 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
11777 struct breakpoint
*b
, *b_tmp
;
11779 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11781 if ((*callback
) (b
, data
))
11789 _initialize_breakpoint (void)
11791 struct cmd_list_element
*c
;
11793 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
11794 observer_attach_inferior_exit (clear_syscall_counts
);
11795 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
11797 breakpoint_chain
= 0;
11798 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11799 before a breakpoint is set. */
11800 breakpoint_count
= 0;
11802 tracepoint_count
= 0;
11804 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
11805 Set ignore-count of breakpoint number N to COUNT.\n\
11806 Usage is `ignore N COUNT'."));
11808 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
11810 add_com ("commands", class_breakpoint
, commands_command
, _("\
11811 Set commands to be executed when a breakpoint is hit.\n\
11812 Give breakpoint number as argument after \"commands\".\n\
11813 With no argument, the targeted breakpoint is the last one set.\n\
11814 The commands themselves follow starting on the next line.\n\
11815 Type a line containing \"end\" to indicate the end of them.\n\
11816 Give \"silent\" as the first line to make the breakpoint silent;\n\
11817 then no output is printed when it is hit, except what the commands print."));
11819 add_com ("condition", class_breakpoint
, condition_command
, _("\
11820 Specify breakpoint number N to break only if COND is true.\n\
11821 Usage is `condition N COND', where N is an integer and COND is an\n\
11822 expression to be evaluated whenever breakpoint N is reached."));
11824 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
11825 Set a temporary breakpoint.\n\
11826 Like \"break\" except the breakpoint is only temporary,\n\
11827 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11828 by using \"enable delete\" on the breakpoint number.\n\
11830 BREAK_ARGS_HELP ("tbreak")));
11831 set_cmd_completer (c
, location_completer
);
11833 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
11834 Set a hardware assisted breakpoint.\n\
11835 Like \"break\" except the breakpoint requires hardware support,\n\
11836 some target hardware may not have this support.\n\
11838 BREAK_ARGS_HELP ("hbreak")));
11839 set_cmd_completer (c
, location_completer
);
11841 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
11842 Set a temporary hardware assisted breakpoint.\n\
11843 Like \"hbreak\" except the breakpoint is only temporary,\n\
11844 so it will be deleted when hit.\n\
11846 BREAK_ARGS_HELP ("thbreak")));
11847 set_cmd_completer (c
, location_completer
);
11849 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
11850 Enable some breakpoints.\n\
11851 Give breakpoint numbers (separated by spaces) as arguments.\n\
11852 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11853 This is used to cancel the effect of the \"disable\" command.\n\
11854 With a subcommand you can enable temporarily."),
11855 &enablelist
, "enable ", 1, &cmdlist
);
11857 add_com ("ab", class_breakpoint
, enable_command
, _("\
11858 Enable some breakpoints.\n\
11859 Give breakpoint numbers (separated by spaces) as arguments.\n\
11860 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11861 This is used to cancel the effect of the \"disable\" command.\n\
11862 With a subcommand you can enable temporarily."));
11864 add_com_alias ("en", "enable", class_breakpoint
, 1);
11866 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
11867 Enable some breakpoints.\n\
11868 Give breakpoint numbers (separated by spaces) as arguments.\n\
11869 This is used to cancel the effect of the \"disable\" command.\n\
11870 May be abbreviated to simply \"enable\".\n"),
11871 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
11873 add_cmd ("once", no_class
, enable_once_command
, _("\
11874 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11875 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11878 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11879 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11880 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11883 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11884 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11885 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11888 add_cmd ("once", no_class
, enable_once_command
, _("\
11889 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11890 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11893 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
11894 Disable some breakpoints.\n\
11895 Arguments are breakpoint numbers with spaces in between.\n\
11896 To disable all breakpoints, give no argument.\n\
11897 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11898 &disablelist
, "disable ", 1, &cmdlist
);
11899 add_com_alias ("dis", "disable", class_breakpoint
, 1);
11900 add_com_alias ("disa", "disable", class_breakpoint
, 1);
11902 add_com ("sb", class_breakpoint
, disable_command
, _("\
11903 Disable some breakpoints.\n\
11904 Arguments are breakpoint numbers with spaces in between.\n\
11905 To disable all breakpoints, give no argument.\n\
11906 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11908 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
11909 Disable some breakpoints.\n\
11910 Arguments are breakpoint numbers with spaces in between.\n\
11911 To disable all breakpoints, give no argument.\n\
11912 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11913 This command may be abbreviated \"disable\"."),
11916 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
11917 Delete some breakpoints or auto-display expressions.\n\
11918 Arguments are breakpoint numbers with spaces in between.\n\
11919 To delete all breakpoints, give no argument.\n\
11921 Also a prefix command for deletion of other GDB objects.\n\
11922 The \"unset\" command is also an alias for \"delete\"."),
11923 &deletelist
, "delete ", 1, &cmdlist
);
11924 add_com_alias ("d", "delete", class_breakpoint
, 1);
11925 add_com_alias ("del", "delete", class_breakpoint
, 1);
11927 add_com ("db", class_breakpoint
, delete_command
, _("\
11928 Delete some breakpoints.\n\
11929 Arguments are breakpoint numbers with spaces in between.\n\
11930 To delete all breakpoints, give no argument.\n"));
11932 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
11933 Delete some breakpoints or auto-display expressions.\n\
11934 Arguments are breakpoint numbers with spaces in between.\n\
11935 To delete all breakpoints, give no argument.\n\
11936 This command may be abbreviated \"delete\"."),
11939 add_com ("clear", class_breakpoint
, clear_command
, _("\
11940 Clear breakpoint at specified line or function.\n\
11941 Argument may be line number, function name, or \"*\" and an address.\n\
11942 If line number is specified, all breakpoints in that line are cleared.\n\
11943 If function is specified, breakpoints at beginning of function are cleared.\n\
11944 If an address is specified, breakpoints at that address are cleared.\n\
11946 With no argument, clears all breakpoints in the line that the selected frame\n\
11947 is executing in.\n\
11949 See also the \"delete\" command which clears breakpoints by number."));
11950 add_com_alias ("cl", "clear", class_breakpoint
, 1);
11952 c
= add_com ("break", class_breakpoint
, break_command
, _("\
11953 Set breakpoint at specified line or function.\n"
11954 BREAK_ARGS_HELP ("break")));
11955 set_cmd_completer (c
, location_completer
);
11957 add_com_alias ("b", "break", class_run
, 1);
11958 add_com_alias ("br", "break", class_run
, 1);
11959 add_com_alias ("bre", "break", class_run
, 1);
11960 add_com_alias ("brea", "break", class_run
, 1);
11963 add_com_alias ("ba", "break", class_breakpoint
, 1);
11967 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
11968 Break in function/address or break at a line in the current file."),
11969 &stoplist
, "stop ", 1, &cmdlist
);
11970 add_cmd ("in", class_breakpoint
, stopin_command
,
11971 _("Break in function or address."), &stoplist
);
11972 add_cmd ("at", class_breakpoint
, stopat_command
,
11973 _("Break at a line in the current file."), &stoplist
);
11974 add_com ("status", class_info
, breakpoints_info
, _("\
11975 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11976 The \"Type\" column indicates one of:\n\
11977 \tbreakpoint - normal breakpoint\n\
11978 \twatchpoint - watchpoint\n\
11979 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11980 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11981 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11982 address and file/line number respectively.\n\
11984 Convenience variable \"$_\" and default examine address for \"x\"\n\
11985 are set to the address of the last breakpoint listed unless the command\n\
11986 is prefixed with \"server \".\n\n\
11987 Convenience variable \"$bpnum\" contains the number of the last\n\
11988 breakpoint set."));
11991 add_info ("breakpoints", breakpoints_info
, _("\
11992 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11993 The \"Type\" column indicates one of:\n\
11994 \tbreakpoint - normal breakpoint\n\
11995 \twatchpoint - watchpoint\n\
11996 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11997 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11998 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11999 address and file/line number respectively.\n\
12001 Convenience variable \"$_\" and default examine address for \"x\"\n\
12002 are set to the address of the last breakpoint listed unless the command\n\
12003 is prefixed with \"server \".\n\n\
12004 Convenience variable \"$bpnum\" contains the number of the last\n\
12005 breakpoint set."));
12007 add_info_alias ("b", "breakpoints", 1);
12010 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
12011 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12012 The \"Type\" column indicates one of:\n\
12013 \tbreakpoint - normal breakpoint\n\
12014 \twatchpoint - watchpoint\n\
12015 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12016 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12017 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12018 address and file/line number respectively.\n\
12020 Convenience variable \"$_\" and default examine address for \"x\"\n\
12021 are set to the address of the last breakpoint listed unless the command\n\
12022 is prefixed with \"server \".\n\n\
12023 Convenience variable \"$bpnum\" contains the number of the last\n\
12024 breakpoint set."));
12026 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
12027 Status of all breakpoints, or breakpoint number NUMBER.\n\
12028 The \"Type\" column indicates one of:\n\
12029 \tbreakpoint - normal breakpoint\n\
12030 \twatchpoint - watchpoint\n\
12031 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12032 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12033 \tuntil - internal breakpoint used by the \"until\" command\n\
12034 \tfinish - internal breakpoint used by the \"finish\" command\n\
12035 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12036 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12037 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12038 address and file/line number respectively.\n\
12040 Convenience variable \"$_\" and default examine address for \"x\"\n\
12041 are set to the address of the last breakpoint listed unless the command\n\
12042 is prefixed with \"server \".\n\n\
12043 Convenience variable \"$bpnum\" contains the number of the last\n\
12045 &maintenanceinfolist
);
12047 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
12048 Set catchpoints to catch events."),
12049 &catch_cmdlist
, "catch ",
12050 0/*allow-unknown*/, &cmdlist
);
12052 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
12053 Set temporary catchpoints to catch events."),
12054 &tcatch_cmdlist
, "tcatch ",
12055 0/*allow-unknown*/, &cmdlist
);
12057 /* Add catch and tcatch sub-commands. */
12058 add_catch_command ("catch", _("\
12059 Catch an exception, when caught.\n\
12060 With an argument, catch only exceptions with the given name."),
12061 catch_catch_command
,
12065 add_catch_command ("throw", _("\
12066 Catch an exception, when thrown.\n\
12067 With an argument, catch only exceptions with the given name."),
12068 catch_throw_command
,
12072 add_catch_command ("fork", _("Catch calls to fork."),
12073 catch_fork_command_1
,
12075 (void *) (uintptr_t) catch_fork_permanent
,
12076 (void *) (uintptr_t) catch_fork_temporary
);
12077 add_catch_command ("vfork", _("Catch calls to vfork."),
12078 catch_fork_command_1
,
12080 (void *) (uintptr_t) catch_vfork_permanent
,
12081 (void *) (uintptr_t) catch_vfork_temporary
);
12082 add_catch_command ("exec", _("Catch calls to exec."),
12083 catch_exec_command_1
,
12087 add_catch_command ("syscall", _("\
12088 Catch system calls by their names and/or numbers.\n\
12089 Arguments say which system calls to catch. If no arguments\n\
12090 are given, every system call will be caught.\n\
12091 Arguments, if given, should be one or more system call names\n\
12092 (if your system supports that), or system call numbers."),
12093 catch_syscall_command_1
,
12094 catch_syscall_completer
,
12097 add_catch_command ("exception", _("\
12098 Catch Ada exceptions, when raised.\n\
12099 With an argument, catch only exceptions with the given name."),
12100 catch_ada_exception_command
,
12104 add_catch_command ("assert", _("\
12105 Catch failed Ada assertions, when raised.\n\
12106 With an argument, catch only exceptions with the given name."),
12107 catch_assert_command
,
12112 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
12113 Set a watchpoint for an expression.\n\
12114 Usage: watch [-l|-location] EXPRESSION\n\
12115 A watchpoint stops execution of your program whenever the value of\n\
12116 an expression changes.\n\
12117 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12118 the memory to which it refers."));
12119 set_cmd_completer (c
, expression_completer
);
12121 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
12122 Set a read watchpoint for an expression.\n\
12123 Usage: rwatch [-l|-location] EXPRESSION\n\
12124 A watchpoint stops execution of your program whenever the value of\n\
12125 an expression is read.\n\
12126 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12127 the memory to which it refers."));
12128 set_cmd_completer (c
, expression_completer
);
12130 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
12131 Set a watchpoint for an expression.\n\
12132 Usage: awatch [-l|-location] EXPRESSION\n\
12133 A watchpoint stops execution of your program whenever the value of\n\
12134 an expression is either read or written.\n\
12135 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12136 the memory to which it refers."));
12137 set_cmd_completer (c
, expression_completer
);
12139 add_info ("watchpoints", watchpoints_info
, _("\
12140 Status of watchpoints, or watchpoint number NUMBER."));
12144 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12145 respond to changes - contrary to the description. */
12146 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
12147 &can_use_hw_watchpoints
, _("\
12148 Set debugger's willingness to use watchpoint hardware."), _("\
12149 Show debugger's willingness to use watchpoint hardware."), _("\
12150 If zero, gdb will not use hardware for new watchpoints, even if\n\
12151 such is available. (However, any hardware watchpoints that were\n\
12152 created before setting this to nonzero, will continue to use watchpoint\n\
12155 show_can_use_hw_watchpoints
,
12156 &setlist
, &showlist
);
12158 can_use_hw_watchpoints
= 1;
12160 /* Tracepoint manipulation commands. */
12162 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12163 Set a tracepoint at specified line or function.\n\
12165 BREAK_ARGS_HELP ("trace") "\n\
12166 Do \"help tracepoints\" for info on other tracepoint commands."));
12167 set_cmd_completer (c
, location_completer
);
12169 add_com_alias ("tp", "trace", class_alias
, 0);
12170 add_com_alias ("tr", "trace", class_alias
, 1);
12171 add_com_alias ("tra", "trace", class_alias
, 1);
12172 add_com_alias ("trac", "trace", class_alias
, 1);
12174 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12175 Set a fast tracepoint at specified line or function.\n\
12177 BREAK_ARGS_HELP ("ftrace") "\n\
12178 Do \"help tracepoints\" for info on other tracepoint commands."));
12179 set_cmd_completer (c
, location_completer
);
12181 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12182 Set a static tracepoint at specified line, function or marker.\n\
12184 strace [LOCATION] [if CONDITION]\n\
12185 LOCATION may be a line number, function name, \"*\" and an address,\n\
12186 or -m MARKER_ID.\n\
12187 If a line number is specified, probe the marker at start of code\n\
12188 for that line. If a function is specified, probe the marker at start\n\
12189 of code for that function. If an address is specified, probe the marker\n\
12190 at that exact address. If a marker id is specified, probe the marker\n\
12191 with that name. With no LOCATION, uses current execution address of\n\
12192 the selected stack frame.\n\
12193 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12194 This collects arbitrary user data passed in the probe point call to the\n\
12195 tracing library. You can inspect it when analyzing the trace buffer,\n\
12196 by printing the $_sdata variable like any other convenience variable.\n\
12198 CONDITION is a boolean expression.\n\
12200 Multiple tracepoints at one place are permitted, and useful if their\n\
12201 conditions are different.\n\
12203 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12204 Do \"help tracepoints\" for info on other tracepoint commands."));
12205 set_cmd_completer (c
, location_completer
);
12207 add_info ("tracepoints", tracepoints_info
, _("\
12208 Status of tracepoints, or tracepoint number NUMBER.\n\
12209 Convenience variable \"$tpnum\" contains the number of the\n\
12210 last tracepoint set."));
12212 add_info_alias ("tp", "tracepoints", 1);
12214 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12215 Delete specified tracepoints.\n\
12216 Arguments are tracepoint numbers, separated by spaces.\n\
12217 No argument means delete all tracepoints."),
12220 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12221 Disable specified tracepoints.\n\
12222 Arguments are tracepoint numbers, separated by spaces.\n\
12223 No argument means disable all tracepoints."),
12225 deprecate_cmd (c
, "disable");
12227 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12228 Enable specified tracepoints.\n\
12229 Arguments are tracepoint numbers, separated by spaces.\n\
12230 No argument means enable all tracepoints."),
12232 deprecate_cmd (c
, "enable");
12234 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12235 Set the passcount for a tracepoint.\n\
12236 The trace will end when the tracepoint has been passed 'count' times.\n\
12237 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12238 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12240 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12241 _("Save breakpoint definitions as a script."),
12242 &save_cmdlist
, "save ",
12243 0/*allow-unknown*/, &cmdlist
);
12245 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12246 Save current breakpoint definitions as a script.\n\
12247 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12248 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12249 session to restore them."),
12251 set_cmd_completer (c
, filename_completer
);
12253 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12254 Save current tracepoint definitions as a script.\n\
12255 Use the 'source' command in another debug session to restore them."),
12257 set_cmd_completer (c
, filename_completer
);
12259 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12260 deprecate_cmd (c
, "save tracepoints");
12262 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12263 Breakpoint specific settings\n\
12264 Configure various breakpoint-specific variables such as\n\
12265 pending breakpoint behavior"),
12266 &breakpoint_set_cmdlist
, "set breakpoint ",
12267 0/*allow-unknown*/, &setlist
);
12268 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12269 Breakpoint specific settings\n\
12270 Configure various breakpoint-specific variables such as\n\
12271 pending breakpoint behavior"),
12272 &breakpoint_show_cmdlist
, "show breakpoint ",
12273 0/*allow-unknown*/, &showlist
);
12275 add_setshow_auto_boolean_cmd ("pending", no_class
,
12276 &pending_break_support
, _("\
12277 Set debugger's behavior regarding pending breakpoints."), _("\
12278 Show debugger's behavior regarding pending breakpoints."), _("\
12279 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12280 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12281 an error. If auto, an unrecognized breakpoint location results in a\n\
12282 user-query to see if a pending breakpoint should be created."),
12284 show_pending_break_support
,
12285 &breakpoint_set_cmdlist
,
12286 &breakpoint_show_cmdlist
);
12288 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12290 add_setshow_boolean_cmd ("auto-hw", no_class
,
12291 &automatic_hardware_breakpoints
, _("\
12292 Set automatic usage of hardware breakpoints."), _("\
12293 Show automatic usage of hardware breakpoints."), _("\
12294 If set, the debugger will automatically use hardware breakpoints for\n\
12295 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12296 a warning will be emitted for such breakpoints."),
12298 show_automatic_hardware_breakpoints
,
12299 &breakpoint_set_cmdlist
,
12300 &breakpoint_show_cmdlist
);
12302 add_setshow_enum_cmd ("always-inserted", class_support
,
12303 always_inserted_enums
, &always_inserted_mode
, _("\
12304 Set mode for inserting breakpoints."), _("\
12305 Show mode for inserting breakpoints."), _("\
12306 When this mode is off, breakpoints are inserted in inferior when it is\n\
12307 resumed, and removed when execution stops. When this mode is on,\n\
12308 breakpoints are inserted immediately and removed only when the user\n\
12309 deletes the breakpoint. When this mode is auto (which is the default),\n\
12310 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12311 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12312 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12313 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12315 &show_always_inserted_mode
,
12316 &breakpoint_set_cmdlist
,
12317 &breakpoint_show_cmdlist
);
12319 automatic_hardware_breakpoints
= 1;
12321 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);