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"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_once_command (char *, int);
84 static void disable_command (char *, int);
86 static void enable_command (char *, int);
88 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
92 static void ignore_command (char *, int);
94 static int breakpoint_re_set_one (void *);
96 static void clear_command (char *, int);
98 static void catch_command (char *, int);
100 static void watch_command (char *, int);
102 static int can_use_hardware_watchpoint (struct value
*);
104 static void break_command_1 (char *, int, int);
106 static void mention (struct breakpoint
*);
108 /* This function is used in gdbtk sources and thus can not be made static. */
109 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
110 struct symtab_and_line
,
113 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
115 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
119 static void describe_other_breakpoints (struct gdbarch
*,
120 struct program_space
*, CORE_ADDR
,
121 struct obj_section
*, int);
123 static int breakpoint_address_match (struct address_space
*aspace1
,
125 struct address_space
*aspace2
,
128 static int watchpoint_locations_match (struct bp_location
*loc1
,
129 struct bp_location
*loc2
);
131 static void breakpoints_info (char *, int);
133 static void breakpoint_1 (int, int);
135 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
137 static int breakpoint_cond_eval (void *);
139 static void cleanup_executing_breakpoints (void *);
141 static void commands_command (char *, int);
143 static void condition_command (char *, int);
145 static int get_number_trailer (char **, int);
154 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
155 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
157 static enum print_stop_action
print_it_typical (bpstat
);
159 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
161 static int watchpoint_check (void *);
163 static void maintenance_info_breakpoints (char *, int);
165 static int hw_breakpoint_used_count (void);
167 static int hw_watchpoint_used_count (enum bptype
, int *);
169 static void hbreak_command (char *, int);
171 static void thbreak_command (char *, int);
173 static void watch_command_1 (char *, int, int);
175 static void rwatch_command (char *, int);
177 static void awatch_command (char *, int);
179 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
181 static void stop_command (char *arg
, int from_tty
);
183 static void stopin_command (char *arg
, int from_tty
);
185 static void stopat_command (char *arg
, int from_tty
);
187 static char *ep_parse_optional_if_clause (char **arg
);
189 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
190 char *arg
, int tempflag
, int from_tty
);
192 static void tcatch_command (char *arg
, int from_tty
);
194 static void ep_skip_leading_whitespace (char **s
);
196 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
199 static void free_bp_location (struct bp_location
*loc
);
201 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
203 static void update_global_location_list (int);
205 static void update_global_location_list_nothrow (int);
207 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
209 static int is_watchpoint (struct breakpoint
*bpt
);
211 static void insert_breakpoint_locations (void);
213 static int syscall_catchpoint_p (struct breakpoint
*b
);
215 static void tracepoints_info (char *, int);
217 static void delete_trace_command (char *, int);
219 static void enable_trace_command (char *, int);
221 static void disable_trace_command (char *, int);
223 static void trace_pass_command (char *, int);
226 /* Flag indicating that a command has proceeded the inferior past the
227 current breakpoint. */
229 static int breakpoint_proceeded
;
232 bpdisp_text (enum bpdisp disp
)
234 /* NOTE: the following values are a part of MI protocol and represent
235 values of 'disp' field returned when inferior stops at a breakpoint. */
236 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
237 return bpdisps
[(int) disp
];
240 /* Prototypes for exported functions. */
241 /* If FALSE, gdb will not use hardware support for watchpoints, even
242 if such is available. */
243 static int can_use_hw_watchpoints
;
246 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
247 struct cmd_list_element
*c
,
250 fprintf_filtered (file
, _("\
251 Debugger's willingness to use watchpoint hardware is %s.\n"),
255 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
256 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
257 for unrecognized breakpoint locations.
258 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
259 static enum auto_boolean pending_break_support
;
261 show_pending_break_support (struct ui_file
*file
, int from_tty
,
262 struct cmd_list_element
*c
,
265 fprintf_filtered (file
, _("\
266 Debugger's behavior regarding pending breakpoints is %s.\n"),
270 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
271 set with "break" but falling in read-only memory.
272 If 0, gdb will warn about such breakpoints, but won't automatically
273 use hardware breakpoints. */
274 static int automatic_hardware_breakpoints
;
276 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
277 struct cmd_list_element
*c
,
280 fprintf_filtered (file
, _("\
281 Automatic usage of hardware breakpoints is %s.\n"),
285 /* If on, gdb will keep breakpoints inserted even as inferior is
286 stopped, and immediately insert any new breakpoints. If off, gdb
287 will insert breakpoints into inferior only when resuming it, and
288 will remove breakpoints upon stop. If auto, GDB will behave as ON
289 if in non-stop mode, and as OFF if all-stop mode.*/
291 static const char always_inserted_auto
[] = "auto";
292 static const char always_inserted_on
[] = "on";
293 static const char always_inserted_off
[] = "off";
294 static const char *always_inserted_enums
[] = {
295 always_inserted_auto
,
300 static const char *always_inserted_mode
= always_inserted_auto
;
302 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
303 struct cmd_list_element
*c
, const char *value
)
305 if (always_inserted_mode
== always_inserted_auto
)
306 fprintf_filtered (file
, _("\
307 Always inserted breakpoint mode is %s (currently %s).\n"),
309 breakpoints_always_inserted_mode () ? "on" : "off");
311 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
315 breakpoints_always_inserted_mode (void)
317 return (always_inserted_mode
== always_inserted_on
318 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
321 void _initialize_breakpoint (void);
323 /* Are we executing breakpoint commands? */
324 static int executing_breakpoint_commands
;
326 /* Are overlay event breakpoints enabled? */
327 static int overlay_events_enabled
;
329 /* Walk the following statement or block through all breakpoints.
330 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
333 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
335 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
336 for (B = breakpoint_chain; \
337 B ? (TMP=B->next, 1): 0; \
340 /* Similar iterator for the low-level breakpoints. SAFE variant is not
341 provided so update_global_location_list must not be called while executing
342 the block of ALL_BP_LOCATIONS. */
344 #define ALL_BP_LOCATIONS(B,BP_TMP) \
345 for (BP_TMP = bp_location; \
346 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
349 /* Iterator for tracepoints only. */
351 #define ALL_TRACEPOINTS(B) \
352 for (B = breakpoint_chain; B; B = B->next) \
353 if (tracepoint_type (B))
355 /* Chains of all breakpoints defined. */
357 struct breakpoint
*breakpoint_chain
;
359 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
361 static struct bp_location
**bp_location
;
363 /* Number of elements of BP_LOCATION. */
365 static unsigned bp_location_count
;
367 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
368 for the current elements of BP_LOCATION which get a valid result from
369 bp_location_has_shadow. You can use it for roughly limiting the subrange of
370 BP_LOCATION to scan for shadow bytes for an address you need to read. */
372 static CORE_ADDR bp_location_placed_address_before_address_max
;
374 /* Maximum offset plus alignment between
375 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
376 the current elements of BP_LOCATION which get a valid result from
377 bp_location_has_shadow. You can use it for roughly limiting the subrange of
378 BP_LOCATION to scan for shadow bytes for an address you need to read. */
380 static CORE_ADDR bp_location_shadow_len_after_address_max
;
382 /* The locations that no longer correspond to any breakpoint,
383 unlinked from bp_location array, but for which a hit
384 may still be reported by a target. */
385 VEC(bp_location_p
) *moribund_locations
= NULL
;
387 /* Number of last breakpoint made. */
389 static int breakpoint_count
;
391 /* The value of `breakpoint_count' before the last command that
392 created breakpoints. If the last (break-like) command created more
393 than one breakpoint, then the difference between BREAKPOINT_COUNT
394 and PREV_BREAKPOINT_COUNT is more than one. */
395 static int prev_breakpoint_count
;
397 /* Number of last tracepoint made. */
399 static int tracepoint_count
;
401 /* Return whether a breakpoint is an active enabled breakpoint. */
403 breakpoint_enabled (struct breakpoint
*b
)
405 return (b
->enable_state
== bp_enabled
);
408 /* Set breakpoint count to NUM. */
411 set_breakpoint_count (int num
)
413 prev_breakpoint_count
= breakpoint_count
;
414 breakpoint_count
= num
;
415 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
418 /* Used by `start_rbreak_breakpoints' below, to record the current
419 breakpoint count before "rbreak" creates any breakpoint. */
420 static int rbreak_start_breakpoint_count
;
422 /* Called at the start an "rbreak" command to record the first
426 start_rbreak_breakpoints (void)
428 rbreak_start_breakpoint_count
= breakpoint_count
;
431 /* Called at the end of an "rbreak" command to record the last
435 end_rbreak_breakpoints (void)
437 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
440 /* Used in run_command to zero the hit count when a new run starts. */
443 clear_breakpoint_hit_counts (void)
445 struct breakpoint
*b
;
451 /* Encapsulate tests for different types of tracepoints. */
454 tracepoint_type (const struct breakpoint
*b
)
456 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
459 /* Allocate a new counted_command_line with reference count of 1.
460 The new structure owns COMMANDS. */
462 static struct counted_command_line
*
463 alloc_counted_command_line (struct command_line
*commands
)
465 struct counted_command_line
*result
466 = xmalloc (sizeof (struct counted_command_line
));
468 result
->commands
= commands
;
472 /* Increment reference count. This does nothing if CMD is NULL. */
475 incref_counted_command_line (struct counted_command_line
*cmd
)
481 /* Decrement reference count. If the reference count reaches 0,
482 destroy the counted_command_line. Sets *CMDP to NULL. This does
483 nothing if *CMDP is NULL. */
486 decref_counted_command_line (struct counted_command_line
**cmdp
)
490 if (--(*cmdp
)->refc
== 0)
492 free_command_lines (&(*cmdp
)->commands
);
499 /* A cleanup function that calls decref_counted_command_line. */
502 do_cleanup_counted_command_line (void *arg
)
504 decref_counted_command_line (arg
);
507 /* Create a cleanup that calls decref_counted_command_line on the
510 static struct cleanup
*
511 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
513 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
516 /* Default address, symtab and line to put a breakpoint at
517 for "break" command with no arg.
518 if default_breakpoint_valid is zero, the other three are
519 not valid, and "break" with no arg is an error.
521 This set by print_stack_frame, which calls set_default_breakpoint. */
523 int default_breakpoint_valid
;
524 CORE_ADDR default_breakpoint_address
;
525 struct symtab
*default_breakpoint_symtab
;
526 int default_breakpoint_line
;
527 struct program_space
*default_breakpoint_pspace
;
530 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
531 Advance *PP after the string and any trailing whitespace.
533 Currently the string can either be a number or "$" followed by the name
534 of a convenience variable. Making it an expression wouldn't work well
535 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
537 If the string is a NULL pointer, that denotes the last breakpoint.
539 TRAILER is a character which can be found after the number; most
540 commonly this is `-'. If you don't want a trailer, use \0. */
542 get_number_trailer (char **pp
, int trailer
)
544 int retval
= 0; /* default */
548 /* Empty line means refer to the last breakpoint. */
549 return breakpoint_count
;
552 /* Make a copy of the name, so we can null-terminate it
553 to pass to lookup_internalvar(). */
558 while (isalnum (*p
) || *p
== '_')
560 varname
= (char *) alloca (p
- start
+ 1);
561 strncpy (varname
, start
, p
- start
);
562 varname
[p
- start
] = '\0';
563 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
567 printf_filtered (_("Convenience variable must have integer value.\n"));
575 while (*p
>= '0' && *p
<= '9')
578 /* There is no number here. (e.g. "cond a == b"). */
580 /* Skip non-numeric token */
581 while (*p
&& !isspace((int) *p
))
583 /* Return zero, which caller must interpret as error. */
589 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
591 /* Trailing junk: return 0 and let caller print error msg. */
592 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
603 /* Like get_number_trailer, but don't allow a trailer. */
605 get_number (char **pp
)
607 return get_number_trailer (pp
, '\0');
610 /* Parse a number or a range.
611 * A number will be of the form handled by get_number.
612 * A range will be of the form <number1> - <number2>, and
613 * will represent all the integers between number1 and number2,
616 * While processing a range, this fuction is called iteratively;
617 * At each call it will return the next value in the range.
619 * At the beginning of parsing a range, the char pointer PP will
620 * be advanced past <number1> and left pointing at the '-' token.
621 * Subsequent calls will not advance the pointer until the range
622 * is completed. The call that completes the range will advance
623 * pointer PP past <number2>.
627 get_number_or_range (char **pp
)
629 static int last_retval
, end_value
;
630 static char *end_ptr
;
631 static int in_range
= 0;
635 /* Default case: pp is pointing either to a solo number,
636 or to the first number of a range. */
637 last_retval
= get_number_trailer (pp
, '-');
642 /* This is the start of a range (<number1> - <number2>).
643 Skip the '-', parse and remember the second number,
644 and also remember the end of the final token. */
648 while (isspace ((int) *end_ptr
))
649 end_ptr
++; /* skip white space */
650 end_value
= get_number (temp
);
651 if (end_value
< last_retval
)
653 error (_("inverted range"));
655 else if (end_value
== last_retval
)
657 /* degenerate range (number1 == number2). Advance the
658 token pointer so that the range will be treated as a
667 error (_("negative value"));
670 /* pp points to the '-' that betokens a range. All
671 number-parsing has already been done. Return the next
672 integer value (one greater than the saved previous value).
673 Do not advance the token pointer 'pp' until the end of range
676 if (++last_retval
== end_value
)
678 /* End of range reached; advance token pointer. */
686 /* Return the breakpoint with the specified number, or NULL
687 if the number does not refer to an existing breakpoint. */
690 get_breakpoint (int num
)
692 struct breakpoint
*b
;
695 if (b
->number
== num
)
702 /* condition N EXP -- set break condition of breakpoint N to EXP. */
705 condition_command (char *arg
, int from_tty
)
707 struct breakpoint
*b
;
712 error_no_arg (_("breakpoint number"));
715 bnum
= get_number (&p
);
717 error (_("Bad breakpoint argument: '%s'"), arg
);
720 if (b
->number
== bnum
)
722 struct bp_location
*loc
= b
->loc
;
723 for (; loc
; loc
= loc
->next
)
728 xfree (b
->cond_string
);
729 b
->cond_string
= NULL
;
736 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
741 /* I don't know if it matters whether this is the string the user
742 typed in or the decompiled expression. */
743 b
->cond_string
= xstrdup (arg
);
744 b
->condition_not_parsed
= 0;
746 if (is_watchpoint (b
))
748 innermost_block
= NULL
;
750 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
752 error (_("Junk at end of expression"));
753 b
->cond_exp_valid_block
= innermost_block
;
757 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
761 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
763 error (_("Junk at end of expression"));
767 breakpoints_changed ();
768 observer_notify_breakpoint_modified (b
->number
);
772 error (_("No breakpoint number %d."), bnum
);
775 /* Check that COMMAND do not contain commands that are suitable
776 only for tracepoints and not suitable for ordinary breakpoints.
777 Throw if any such commands is found.
780 check_no_tracepoint_commands (struct command_line
*commands
)
782 struct command_line
*c
;
783 for (c
= commands
; c
; c
= c
->next
)
787 if (c
->control_type
== while_stepping_control
)
788 error (_("The 'while-stepping' command can only be used for tracepoints"));
790 for (i
= 0; i
< c
->body_count
; ++i
)
791 check_no_tracepoint_commands ((c
->body_list
)[i
]);
793 /* Not that command parsing removes leading whitespace and comment
794 lines and also empty lines. So, we only need to check for
796 if (strstr (c
->line
, "collect ") == c
->line
)
797 error (_("The 'collect' command can only be used for tracepoints"));
799 if (strstr (c
->line
, "teval ") == c
->line
)
800 error (_("The 'teval' command can only be used for tracepoints"));
805 breakpoint_is_tracepoint (const struct breakpoint
*b
)
810 case bp_fast_tracepoint
:
818 /* A helper function that validsates that COMMANDS are valid for a
819 breakpoint. This function will throw an exception if a problem is
823 validate_commands_for_breakpoint (struct breakpoint
*b
,
824 struct command_line
*commands
)
826 if (breakpoint_is_tracepoint (b
))
828 /* We need to verify that each top-level element of commands
829 is valid for tracepoints, that there's at most one while-stepping
830 element, and that while-stepping's body has valid tracing commands
831 excluding nested while-stepping. */
832 struct command_line
*c
;
833 struct command_line
*while_stepping
= 0;
834 for (c
= commands
; c
; c
= c
->next
)
837 if (c
->control_type
== while_stepping_control
)
839 if (b
->type
== bp_fast_tracepoint
)
840 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
843 error (_("The 'while-stepping' command can be used only once"));
850 struct command_line
*c2
;
852 gdb_assert (while_stepping
->body_count
== 1);
853 c2
= while_stepping
->body_list
[0];
854 for (; c2
; c2
= c2
->next
)
857 if (c2
->control_type
== while_stepping_control
)
858 error (_("The 'while-stepping' command cannot be nested"));
864 check_no_tracepoint_commands (commands
);
868 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
869 validate that only allowed commands are included.
873 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
875 validate_commands_for_breakpoint (b
, commands
);
877 decref_counted_command_line (&b
->commands
);
878 b
->commands
= alloc_counted_command_line (commands
);
879 breakpoints_changed ();
880 observer_notify_breakpoint_modified (b
->number
);
884 check_tracepoint_command (char *line
, void *closure
)
886 struct breakpoint
*b
= closure
;
887 validate_actionline (&line
, b
);
890 /* A structure used to pass information through
891 map_breakpoint_numbers. */
895 /* True if the command was typed at a tty. */
898 /* The breakpoint range spec. */
901 /* Non-NULL if the body of the commands are being read from this
902 already-parsed command. */
903 struct command_line
*control
;
905 /* The command lines read from the user, or NULL if they have not
907 struct counted_command_line
*cmd
;
910 /* A callback for map_breakpoint_numbers that sets the commands for
914 do_map_commands_command (struct breakpoint
*b
, void *data
)
916 struct commands_info
*info
= data
;
918 if (info
->cmd
== NULL
)
920 struct command_line
*l
;
922 if (info
->control
!= NULL
)
923 l
= copy_command_lines (info
->control
->body_list
[0]);
926 struct cleanup
*old_chain
;
929 str
= xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
932 old_chain
= make_cleanup (xfree
, str
);
934 l
= read_command_lines (str
,
936 (breakpoint_is_tracepoint (b
)
937 ? check_tracepoint_command
: 0),
940 do_cleanups (old_chain
);
943 info
->cmd
= alloc_counted_command_line (l
);
946 /* If a breakpoint was on the list more than once, we don't need to
948 if (b
->commands
!= info
->cmd
)
950 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
951 incref_counted_command_line (info
->cmd
);
952 decref_counted_command_line (&b
->commands
);
953 b
->commands
= info
->cmd
;
954 breakpoints_changed ();
955 observer_notify_breakpoint_modified (b
->number
);
960 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
962 struct cleanup
*cleanups
;
963 struct commands_info info
;
965 info
.from_tty
= from_tty
;
966 info
.control
= control
;
968 /* If we read command lines from the user, then `info' will hold an
969 extra reference to the commands that we must clean up. */
970 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
972 if (arg
== NULL
|| !*arg
)
974 if (breakpoint_count
- prev_breakpoint_count
> 1)
975 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1, breakpoint_count
);
976 else if (breakpoint_count
> 0)
977 arg
= xstrprintf ("%d", breakpoint_count
);
980 /* So that we don't try to free the incoming non-NULL
981 argument in the cleanup below. Mapping breakpoint
982 numbers will fail in this case. */
987 /* The command loop has some static state, so we need to preserve
992 make_cleanup (xfree
, arg
);
996 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
998 if (info
.cmd
== NULL
)
999 error (_("No breakpoints specified."));
1001 do_cleanups (cleanups
);
1005 commands_command (char *arg
, int from_tty
)
1007 commands_command_1 (arg
, from_tty
, NULL
);
1010 /* Like commands_command, but instead of reading the commands from
1011 input stream, takes them from an already parsed command structure.
1013 This is used by cli-script.c to DTRT with breakpoint commands
1014 that are part of if and while bodies. */
1015 enum command_control_type
1016 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1018 commands_command_1 (arg
, 0, cmd
);
1019 return simple_control
;
1022 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1025 bp_location_has_shadow (struct bp_location
*bl
)
1027 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1031 if (bl
->target_info
.shadow_len
== 0)
1032 /* bp isn't valid, or doesn't shadow memory. */
1037 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1038 by replacing any memory breakpoints with their shadowed contents.
1040 The range of shadowed area by each bp_location is:
1041 b->address - bp_location_placed_address_before_address_max
1042 up to b->address + bp_location_shadow_len_after_address_max
1043 The range we were requested to resolve shadows for is:
1044 memaddr ... memaddr + len
1045 Thus the safe cutoff boundaries for performance optimization are
1046 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1048 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1051 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1053 /* Left boundary, right boundary and median element of our binary search. */
1054 unsigned bc_l
, bc_r
, bc
;
1056 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1057 safe to report lower value but a failure to report higher one. */
1060 bc_r
= bp_location_count
;
1061 while (bc_l
+ 1 < bc_r
)
1063 struct bp_location
*b
;
1065 bc
= (bc_l
+ bc_r
) / 2;
1066 b
= bp_location
[bc
];
1068 /* Check first B->ADDRESS will not overflow due to the added constant.
1069 Then advance the left boundary only if we are sure the BC element can
1070 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1072 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1073 we cannot miss a breakpoint with its shadow range tail still reaching
1076 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1077 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1083 /* Now do full processing of the found relevant range of elements. */
1085 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1087 struct bp_location
*b
= bp_location
[bc
];
1088 CORE_ADDR bp_addr
= 0;
1092 if (b
->owner
->type
== bp_none
)
1093 warning (_("reading through apparently deleted breakpoint #%d?"),
1096 /* Performance optimization: any futher element can no longer affect BUF
1099 if (b
->address
>= bp_location_placed_address_before_address_max
1100 && memaddr
+ len
<= b
->address
1101 - bp_location_placed_address_before_address_max
)
1104 if (!bp_location_has_shadow (b
))
1106 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1107 current_program_space
->aspace
, 0))
1110 /* Addresses and length of the part of the breakpoint that
1112 bp_addr
= b
->target_info
.placed_address
;
1113 bp_size
= b
->target_info
.shadow_len
;
1115 if (bp_addr
+ bp_size
<= memaddr
)
1116 /* The breakpoint is entirely before the chunk of memory we
1120 if (bp_addr
>= memaddr
+ len
)
1121 /* The breakpoint is entirely after the chunk of memory we are
1125 /* Offset within shadow_contents. */
1126 if (bp_addr
< memaddr
)
1128 /* Only copy the second part of the breakpoint. */
1129 bp_size
-= memaddr
- bp_addr
;
1130 bptoffset
= memaddr
- bp_addr
;
1134 if (bp_addr
+ bp_size
> memaddr
+ len
)
1136 /* Only copy the first part of the breakpoint. */
1137 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1140 memcpy (buf
+ bp_addr
- memaddr
,
1141 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1146 /* A wrapper function for inserting catchpoints. */
1148 insert_catchpoint (struct ui_out
*uo
, void *args
)
1150 struct breakpoint
*b
= (struct breakpoint
*) args
;
1153 gdb_assert (b
->type
== bp_catchpoint
);
1154 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1159 /* Return true if BPT is of any hardware watchpoint kind. */
1162 is_hardware_watchpoint (struct breakpoint
*bpt
)
1164 return (bpt
->type
== bp_hardware_watchpoint
1165 || bpt
->type
== bp_read_watchpoint
1166 || bpt
->type
== bp_access_watchpoint
);
1169 /* Return true if BPT is of any watchpoint kind, hardware or
1173 is_watchpoint (struct breakpoint
*bpt
)
1175 return (is_hardware_watchpoint (bpt
)
1176 || bpt
->type
== bp_watchpoint
);
1179 /* Find the current value of a watchpoint on EXP. Return the value in
1180 *VALP and *RESULTP and the chain of intermediate and final values
1181 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1184 If a memory error occurs while evaluating the expression, *RESULTP will
1185 be set to NULL. *RESULTP may be a lazy value, if the result could
1186 not be read from memory. It is used to determine whether a value
1187 is user-specified (we should watch the whole value) or intermediate
1188 (we should watch only the bit used to locate the final value).
1190 If the final value, or any intermediate value, could not be read
1191 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1192 set to any referenced values. *VALP will never be a lazy value.
1193 This is the value which we store in struct breakpoint.
1195 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1196 value chain. The caller must free the values individually. If
1197 VAL_CHAIN is NULL, all generated values will be left on the value
1201 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1202 struct value
**resultp
, struct value
**val_chain
)
1204 struct value
*mark
, *new_mark
, *result
;
1205 volatile struct gdb_exception ex
;
1213 /* Evaluate the expression. */
1214 mark
= value_mark ();
1217 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1219 result
= evaluate_expression (exp
);
1223 /* Ignore memory errors, we want watchpoints pointing at
1224 inaccessible memory to still be created; otherwise, throw the
1225 error to some higher catcher. */
1231 throw_exception (ex
);
1236 new_mark
= value_mark ();
1237 if (mark
== new_mark
)
1242 /* Make sure it's not lazy, so that after the target stops again we
1243 have a non-lazy previous value to compare with. */
1245 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1250 /* Return the chain of intermediate values. We use this to
1251 decide which addresses to watch. */
1252 *val_chain
= new_mark
;
1253 value_release_to_mark (mark
);
1257 /* Assuming that B is a watchpoint: returns true if the current thread
1258 and its running state are safe to evaluate or update watchpoint B.
1259 Watchpoints on local expressions need to be evaluated in the
1260 context of the thread that was current when the watchpoint was
1261 created, and, that thread needs to be stopped to be able to select
1262 the correct frame context. Watchpoints on global expressions can
1263 be evaluated on any thread, and in any state. It is presently left
1264 to the target allowing memory accesses when threads are
1268 watchpoint_in_thread_scope (struct breakpoint
*b
)
1270 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1271 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1272 && !is_executing (inferior_ptid
)));
1275 /* Assuming that B is a watchpoint:
1276 - Reparse watchpoint expression, if REPARSE is non-zero
1277 - Evaluate expression and store the result in B->val
1278 - Evaluate the condition if there is one, and store the result
1280 - Update the list of values that must be watched in B->loc.
1282 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1283 If this is local watchpoint that is out of scope, delete it.
1285 Even with `set breakpoint always-inserted on' the watchpoints are removed
1286 + inserted on each stop here. Normal breakpoints must never be removed
1287 because they might be missed by a running thread when debugging in non-stop
1288 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1289 processed here) are specific to each LWP since they are stored in each LWP's
1290 hardware debug registers. Therefore, such LWP must be stopped first in
1291 order to be able to modify its hardware watchpoints.
1293 Hardware watchpoints must be reset exactly once after being presented to the
1294 user. It cannot be done sooner, because it would reset the data used to
1295 present the watchpoint hit to the user. And it must not be done later
1296 because it could display the same single watchpoint hit during multiple GDB
1297 stops. Note that the latter is relevant only to the hardware watchpoint
1298 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1299 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1300 memory content has not changed.
1302 The following constraints influence the location where we can reset hardware
1305 * target_stopped_by_watchpoint and target_stopped_data_address are called
1306 several times when GDB stops.
1309 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1310 stop. GDB only presents one hardware watchpoint hit at a time as the
1311 reason for stopping, and all the other hits are presented later, one after
1312 the other, each time the user requests the execution to be resumed.
1313 Execution is not resumed for the threads still having pending hit event
1314 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1315 the inferior on the first stop the thread hit event is kept being reported
1316 from its cached value by linux_nat_stopped_data_address until the real
1317 thread resume happens after the watchpoint gets presented and thus its
1318 LWP_INFO->STATUS gets reset.
1320 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1321 removal from inferior. */
1324 update_watchpoint (struct breakpoint
*b
, int reparse
)
1326 int within_current_scope
;
1327 struct frame_id saved_frame_id
;
1328 struct bp_location
*loc
;
1332 /* If this is a local watchpoint, we only want to check if the
1333 watchpoint frame is in scope if the current thread is the thread
1334 that was used to create the watchpoint. */
1335 if (!watchpoint_in_thread_scope (b
))
1338 /* We don't free locations. They are stored in bp_location array and
1339 update_global_locations will eventually delete them and remove
1340 breakpoints if needed. */
1343 if (b
->disposition
== disp_del_at_next_stop
)
1348 /* Determine if the watchpoint is within scope. */
1349 if (b
->exp_valid_block
== NULL
)
1350 within_current_scope
= 1;
1353 struct frame_info
*fi
;
1355 /* Save the current frame's ID so we can restore it after
1356 evaluating the watchpoint expression on its own frame. */
1357 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1358 took a frame parameter, so that we didn't have to change the
1361 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1363 fi
= frame_find_by_id (b
->watchpoint_frame
);
1364 within_current_scope
= (fi
!= NULL
);
1365 if (within_current_scope
)
1369 if (within_current_scope
&& reparse
)
1378 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1379 /* If the meaning of expression itself changed, the old value is
1380 no longer relevant. We don't want to report a watchpoint hit
1381 to the user when the old value and the new value may actually
1382 be completely different objects. */
1383 value_free (b
->val
);
1387 /* Note that unlike with breakpoints, the watchpoint's condition
1388 expression is stored in the breakpoint object, not in the
1389 locations (re)created below. */
1390 if (b
->cond_string
!= NULL
)
1392 if (b
->cond_exp
!= NULL
)
1394 xfree (b
->cond_exp
);
1399 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1403 /* If we failed to parse the expression, for example because
1404 it refers to a global variable in a not-yet-loaded shared library,
1405 don't try to insert watchpoint. We don't automatically delete
1406 such watchpoint, though, since failure to parse expression
1407 is different from out-of-scope watchpoint. */
1408 if ( !target_has_execution
)
1410 /* Without execution, memory can't change. No use to try and
1411 set watchpoint locations. The watchpoint will be reset when
1412 the target gains execution, through breakpoint_re_set. */
1414 else if (within_current_scope
&& b
->exp
)
1416 struct value
*val_chain
, *v
, *result
, *next
;
1417 struct program_space
*frame_pspace
;
1419 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1421 /* Avoid setting b->val if it's already set. The meaning of
1422 b->val is 'the last value' user saw, and we should update
1423 it only if we reported that last value to user. As it
1424 happens, the code that reports it updates b->val directly. */
1431 /* Change the type of breakpoint between hardware assisted or an
1432 ordinary watchpoint depending on the hardware support and free
1433 hardware slots. REPARSE is set when the inferior is started. */
1434 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1437 int i
, mem_cnt
, other_type_used
;
1439 /* We need to determine how many resources are already used
1440 for all other hardware watchpoints to see if we still have
1441 enough resources to also fit this watchpoint in as well.
1442 To avoid the hw_watchpoint_used_count call below from counting
1443 this watchpoint, make sure that it is marked as a software
1445 b
->type
= bp_watchpoint
;
1446 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1448 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1451 b
->type
= bp_watchpoint
;
1454 int target_resources_ok
= target_can_use_hardware_watchpoint
1455 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1456 if (target_resources_ok
<= 0)
1457 b
->type
= bp_watchpoint
;
1459 b
->type
= bp_hardware_watchpoint
;
1463 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1465 /* Look at each value on the value chain. */
1466 for (v
= val_chain
; v
; v
= next
)
1468 /* If it's a memory location, and GDB actually needed
1469 its contents to evaluate the expression, then we
1470 must watch it. If the first value returned is
1471 still lazy, that means an error occurred reading it;
1472 watch it anyway in case it becomes readable. */
1473 if (VALUE_LVAL (v
) == lval_memory
1474 && (v
== val_chain
|| ! value_lazy (v
)))
1476 struct type
*vtype
= check_typedef (value_type (v
));
1478 /* We only watch structs and arrays if user asked
1479 for it explicitly, never if they just happen to
1480 appear in the middle of some value chain. */
1482 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1483 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1487 struct bp_location
*loc
, **tmp
;
1489 addr
= value_address (v
);
1490 len
= TYPE_LENGTH (value_type (v
));
1492 if (b
->type
== bp_read_watchpoint
)
1494 else if (b
->type
== bp_access_watchpoint
)
1497 loc
= allocate_bp_location (b
);
1498 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1501 loc
->gdbarch
= get_type_arch (value_type (v
));
1503 loc
->pspace
= frame_pspace
;
1504 loc
->address
= addr
;
1506 loc
->watchpoint_type
= type
;
1510 next
= value_next (v
);
1515 /* If a software watchpoint is not watching any memory, then the
1516 above left it without any location set up. But,
1517 bpstat_stop_status requires a location to be able to report
1518 stops, so make sure there's at least a dummy one. */
1519 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1521 b
->loc
= allocate_bp_location (b
);
1522 b
->loc
->pspace
= frame_pspace
;
1523 b
->loc
->address
= -1;
1524 b
->loc
->length
= -1;
1525 b
->loc
->watchpoint_type
= -1;
1528 else if (!within_current_scope
)
1530 printf_filtered (_("\
1531 Watchpoint %d deleted because the program has left the block \n\
1532 in which its expression is valid.\n"),
1534 if (b
->related_breakpoint
)
1536 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1537 b
->related_breakpoint
->related_breakpoint
= NULL
;
1538 b
->related_breakpoint
= NULL
;
1540 b
->disposition
= disp_del_at_next_stop
;
1543 /* Restore the selected frame. */
1545 select_frame (frame_find_by_id (saved_frame_id
));
1549 /* Returns 1 iff breakpoint location should be
1550 inserted in the inferior. */
1552 should_be_inserted (struct bp_location
*bpt
)
1554 if (!breakpoint_enabled (bpt
->owner
))
1557 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1560 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1563 /* This is set for example, when we're attached to the parent of a
1564 vfork, and have detached from the child. The child is running
1565 free, and we expect it to do an exec or exit, at which point the
1566 OS makes the parent schedulable again (and the target reports
1567 that the vfork is done). Until the child is done with the shared
1568 memory region, do not insert breakpoints in the parent, otherwise
1569 the child could still trip on the parent's breakpoints. Since
1570 the parent is blocked anyway, it won't miss any breakpoint. */
1571 if (bpt
->pspace
->breakpoints_not_allowed
)
1574 /* Tracepoints are inserted by the target at a time of its choosing,
1576 if (tracepoint_type (bpt
->owner
))
1582 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1583 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1584 and HW_BREAKPOINT_ERROR are used to report problems.
1586 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1587 method for each breakpoint or catchpoint type. */
1589 insert_bp_location (struct bp_location
*bpt
,
1590 struct ui_file
*tmp_error_stream
,
1591 int *disabled_breaks
,
1592 int *hw_breakpoint_error
)
1596 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1599 /* Initialize the target-specific information. */
1600 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1601 bpt
->target_info
.placed_address
= bpt
->address
;
1602 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1604 if (bpt
->loc_type
== bp_loc_software_breakpoint
1605 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1607 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1609 /* If the explicitly specified breakpoint type
1610 is not hardware breakpoint, check the memory map to see
1611 if the breakpoint address is in read only memory or not.
1612 Two important cases are:
1613 - location type is not hardware breakpoint, memory
1614 is readonly. We change the type of the location to
1615 hardware breakpoint.
1616 - location type is hardware breakpoint, memory is read-write.
1617 This means we've previously made the location hardware one, but
1618 then the memory map changed, so we undo.
1620 When breakpoints are removed, remove_breakpoints will
1621 use location types we've just set here, the only possible
1622 problem is that memory map has changed during running program,
1623 but it's not going to work anyway with current gdb. */
1624 struct mem_region
*mr
1625 = lookup_mem_region (bpt
->target_info
.placed_address
);
1629 if (automatic_hardware_breakpoints
)
1632 enum bp_loc_type new_type
;
1634 if (mr
->attrib
.mode
!= MEM_RW
)
1635 new_type
= bp_loc_hardware_breakpoint
;
1637 new_type
= bp_loc_software_breakpoint
;
1639 if (new_type
!= bpt
->loc_type
)
1641 static int said
= 0;
1642 bpt
->loc_type
= new_type
;
1645 fprintf_filtered (gdb_stdout
, _("\
1646 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1651 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1652 && mr
->attrib
.mode
!= MEM_RW
)
1653 warning (_("cannot set software breakpoint at readonly address %s"),
1654 paddress (bpt
->gdbarch
, bpt
->address
));
1658 /* First check to see if we have to handle an overlay. */
1659 if (overlay_debugging
== ovly_off
1660 || bpt
->section
== NULL
1661 || !(section_is_overlay (bpt
->section
)))
1663 /* No overlay handling: just set the breakpoint. */
1665 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1666 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1669 val
= target_insert_breakpoint (bpt
->gdbarch
,
1674 /* This breakpoint is in an overlay section.
1675 Shall we set a breakpoint at the LMA? */
1676 if (!overlay_events_enabled
)
1678 /* Yes -- overlay event support is not active,
1679 so we must try to set a breakpoint at the LMA.
1680 This will not work for a hardware breakpoint. */
1681 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1682 warning (_("hardware breakpoint %d not supported in overlay!"),
1683 bpt
->owner
->number
);
1686 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1688 /* Set a software (trap) breakpoint at the LMA. */
1689 bpt
->overlay_target_info
= bpt
->target_info
;
1690 bpt
->overlay_target_info
.placed_address
= addr
;
1691 val
= target_insert_breakpoint (bpt
->gdbarch
,
1692 &bpt
->overlay_target_info
);
1694 fprintf_unfiltered (tmp_error_stream
,
1695 "Overlay breakpoint %d failed: in ROM?\n",
1696 bpt
->owner
->number
);
1699 /* Shall we set a breakpoint at the VMA? */
1700 if (section_is_mapped (bpt
->section
))
1702 /* Yes. This overlay section is mapped into memory. */
1703 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1704 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1707 val
= target_insert_breakpoint (bpt
->gdbarch
,
1712 /* No. This breakpoint will not be inserted.
1713 No error, but do not mark the bp as 'inserted'. */
1720 /* Can't set the breakpoint. */
1721 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1723 /* See also: disable_breakpoints_in_shlibs. */
1725 bpt
->shlib_disabled
= 1;
1726 if (!*disabled_breaks
)
1728 fprintf_unfiltered (tmp_error_stream
,
1729 "Cannot insert breakpoint %d.\n",
1730 bpt
->owner
->number
);
1731 fprintf_unfiltered (tmp_error_stream
,
1732 "Temporarily disabling shared library breakpoints:\n");
1734 *disabled_breaks
= 1;
1735 fprintf_unfiltered (tmp_error_stream
,
1736 "breakpoint #%d\n", bpt
->owner
->number
);
1740 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1742 *hw_breakpoint_error
= 1;
1743 fprintf_unfiltered (tmp_error_stream
,
1744 "Cannot insert hardware breakpoint %d.\n",
1745 bpt
->owner
->number
);
1749 fprintf_unfiltered (tmp_error_stream
,
1750 "Cannot insert breakpoint %d.\n",
1751 bpt
->owner
->number
);
1752 fprintf_filtered (tmp_error_stream
,
1753 "Error accessing memory address ");
1754 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1756 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1757 safe_strerror (val
));
1768 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1769 /* NOTE drow/2003-09-08: This state only exists for removing
1770 watchpoints. It's not clear that it's necessary... */
1771 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1773 val
= target_insert_watchpoint (bpt
->address
,
1775 bpt
->watchpoint_type
);
1777 /* If trying to set a read-watchpoint, and it turns out it's not
1778 supported, try emulating one with an access watchpoint. */
1779 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1781 struct bp_location
*loc
, **loc_temp
;
1783 /* But don't try to insert it, if there's already another
1784 hw_access location that would be considered a duplicate
1786 ALL_BP_LOCATIONS (loc
, loc_temp
)
1788 && loc
->watchpoint_type
== hw_access
1789 && watchpoint_locations_match (bpt
, loc
))
1793 bpt
->target_info
= loc
->target_info
;
1794 bpt
->watchpoint_type
= hw_access
;
1801 val
= target_insert_watchpoint (bpt
->address
,
1805 bpt
->watchpoint_type
= hw_access
;
1809 bpt
->inserted
= (val
== 0);
1812 else if (bpt
->owner
->type
== bp_catchpoint
)
1814 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1815 bpt
->owner
, RETURN_MASK_ERROR
);
1816 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1817 bpt
->owner
->number
);
1819 bpt
->owner
->enable_state
= bp_disabled
;
1823 /* We've already printed an error message if there was a problem
1824 inserting this catchpoint, and we've disabled the catchpoint,
1825 so just return success. */
1832 /* This function is called when program space PSPACE is about to be
1833 deleted. It takes care of updating breakpoints to not reference
1837 breakpoint_program_space_exit (struct program_space
*pspace
)
1839 struct breakpoint
*b
, *b_temp
;
1840 struct bp_location
*loc
, **loc_temp
;
1842 /* Remove any breakpoint that was set through this program space. */
1843 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1845 if (b
->pspace
== pspace
)
1846 delete_breakpoint (b
);
1849 /* Breakpoints set through other program spaces could have locations
1850 bound to PSPACE as well. Remove those. */
1851 ALL_BP_LOCATIONS (loc
, loc_temp
)
1853 struct bp_location
*tmp
;
1855 if (loc
->pspace
== pspace
)
1857 if (loc
->owner
->loc
== loc
)
1858 loc
->owner
->loc
= loc
->next
;
1860 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1861 if (tmp
->next
== loc
)
1863 tmp
->next
= loc
->next
;
1869 /* Now update the global location list to permanently delete the
1870 removed locations above. */
1871 update_global_location_list (0);
1874 /* Make sure all breakpoints are inserted in inferior.
1875 Throws exception on any error.
1876 A breakpoint that is already inserted won't be inserted
1877 again, so calling this function twice is safe. */
1879 insert_breakpoints (void)
1881 struct breakpoint
*bpt
;
1883 ALL_BREAKPOINTS (bpt
)
1884 if (is_hardware_watchpoint (bpt
))
1885 update_watchpoint (bpt
, 0 /* don't reparse. */);
1887 update_global_location_list (1);
1889 /* update_global_location_list does not insert breakpoints when
1890 always_inserted_mode is not enabled. Explicitly insert them
1892 if (!breakpoints_always_inserted_mode ())
1893 insert_breakpoint_locations ();
1896 /* insert_breakpoints is used when starting or continuing the program.
1897 remove_breakpoints is used when the program stops.
1898 Both return zero if successful,
1899 or an `errno' value if could not write the inferior. */
1902 insert_breakpoint_locations (void)
1904 struct breakpoint
*bpt
;
1905 struct bp_location
*b
, **bp_tmp
;
1908 int disabled_breaks
= 0;
1909 int hw_breakpoint_error
= 0;
1911 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1912 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1914 /* Explicitly mark the warning -- this will only be printed if
1915 there was an error. */
1916 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1918 save_current_space_and_thread ();
1920 ALL_BP_LOCATIONS (b
, bp_tmp
)
1922 struct thread_info
*tp
;
1923 CORE_ADDR last_addr
;
1925 if (!should_be_inserted (b
) || b
->inserted
)
1928 /* There is no point inserting thread-specific breakpoints if the
1929 thread no longer exists. */
1930 if (b
->owner
->thread
!= -1
1931 && !valid_thread_id (b
->owner
->thread
))
1934 switch_to_program_space_and_thread (b
->pspace
);
1936 /* For targets that support global breakpoints, there's no need
1937 to select an inferior to insert breakpoint to. In fact, even
1938 if we aren't attached to any process yet, we should still
1939 insert breakpoints. */
1940 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1941 && ptid_equal (inferior_ptid
, null_ptid
))
1944 val
= insert_bp_location (b
, tmp_error_stream
,
1946 &hw_breakpoint_error
);
1951 /* If we failed to insert all locations of a watchpoint,
1952 remove them, as half-inserted watchpoint is of limited use. */
1953 ALL_BREAKPOINTS (bpt
)
1955 int some_failed
= 0;
1956 struct bp_location
*loc
;
1958 if (!is_hardware_watchpoint (bpt
))
1961 if (!breakpoint_enabled (bpt
))
1964 if (bpt
->disposition
== disp_del_at_next_stop
)
1967 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1968 if (!loc
->inserted
&& should_be_inserted (loc
))
1975 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1977 remove_breakpoint (loc
, mark_uninserted
);
1979 hw_breakpoint_error
= 1;
1980 fprintf_unfiltered (tmp_error_stream
,
1981 "Could not insert hardware watchpoint %d.\n",
1989 /* If a hardware breakpoint or watchpoint was inserted, add a
1990 message about possibly exhausted resources. */
1991 if (hw_breakpoint_error
)
1993 fprintf_unfiltered (tmp_error_stream
,
1994 "Could not insert hardware breakpoints:\n\
1995 You may have requested too many hardware breakpoints/watchpoints.\n");
1997 target_terminal_ours_for_output ();
1998 error_stream (tmp_error_stream
);
2001 do_cleanups (cleanups
);
2005 remove_breakpoints (void)
2007 struct bp_location
*b
, **bp_tmp
;
2010 ALL_BP_LOCATIONS (b
, bp_tmp
)
2013 val
|= remove_breakpoint (b
, mark_uninserted
);
2018 /* Remove breakpoints of process PID. */
2021 remove_breakpoints_pid (int pid
)
2023 struct bp_location
*b
, **b_tmp
;
2025 struct inferior
*inf
= find_inferior_pid (pid
);
2027 ALL_BP_LOCATIONS (b
, b_tmp
)
2029 if (b
->pspace
!= inf
->pspace
)
2034 val
= remove_breakpoint (b
, mark_uninserted
);
2043 remove_hw_watchpoints (void)
2045 struct bp_location
*b
, **bp_tmp
;
2048 ALL_BP_LOCATIONS (b
, bp_tmp
)
2050 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2051 val
|= remove_breakpoint (b
, mark_uninserted
);
2057 reattach_breakpoints (int pid
)
2059 struct cleanup
*old_chain
;
2060 struct bp_location
*b
, **bp_tmp
;
2062 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2063 int dummy1
= 0, dummy2
= 0;
2064 struct inferior
*inf
;
2065 struct thread_info
*tp
;
2067 tp
= any_live_thread_of_process (pid
);
2071 inf
= find_inferior_pid (pid
);
2072 old_chain
= save_inferior_ptid ();
2074 inferior_ptid
= tp
->ptid
;
2076 make_cleanup_ui_file_delete (tmp_error_stream
);
2078 ALL_BP_LOCATIONS (b
, bp_tmp
)
2080 if (b
->pspace
!= inf
->pspace
)
2086 val
= insert_bp_location (b
, tmp_error_stream
,
2090 do_cleanups (old_chain
);
2095 do_cleanups (old_chain
);
2099 static int internal_breakpoint_number
= -1;
2101 static struct breakpoint
*
2102 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2103 CORE_ADDR address
, enum bptype type
)
2105 struct symtab_and_line sal
;
2106 struct breakpoint
*b
;
2108 init_sal (&sal
); /* initialize to zeroes */
2111 sal
.section
= find_pc_overlay (sal
.pc
);
2112 sal
.pspace
= current_program_space
;
2114 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2115 b
->number
= internal_breakpoint_number
--;
2116 b
->disposition
= disp_donttouch
;
2122 create_overlay_event_breakpoint (char *func_name
)
2124 struct objfile
*objfile
;
2126 ALL_OBJFILES (objfile
)
2128 struct breakpoint
*b
;
2129 struct minimal_symbol
*m
;
2131 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2135 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2136 SYMBOL_VALUE_ADDRESS (m
),
2138 b
->addr_string
= xstrdup (func_name
);
2140 if (overlay_debugging
== ovly_auto
)
2142 b
->enable_state
= bp_enabled
;
2143 overlay_events_enabled
= 1;
2147 b
->enable_state
= bp_disabled
;
2148 overlay_events_enabled
= 0;
2151 update_global_location_list (1);
2155 create_longjmp_master_breakpoint (char *func_name
)
2157 struct program_space
*pspace
;
2158 struct objfile
*objfile
;
2159 struct cleanup
*old_chain
;
2161 old_chain
= save_current_program_space ();
2163 ALL_PSPACES (pspace
)
2164 ALL_OBJFILES (objfile
)
2166 struct breakpoint
*b
;
2167 struct minimal_symbol
*m
;
2169 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2172 set_current_program_space (pspace
);
2174 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2178 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2179 SYMBOL_VALUE_ADDRESS (m
),
2181 b
->addr_string
= xstrdup (func_name
);
2182 b
->enable_state
= bp_disabled
;
2184 update_global_location_list (1);
2186 do_cleanups (old_chain
);
2189 /* Create a master std::terminate breakpoint. The actual function
2190 looked for is named FUNC_NAME. */
2192 create_std_terminate_master_breakpoint (const char *func_name
)
2194 struct program_space
*pspace
;
2195 struct objfile
*objfile
;
2196 struct cleanup
*old_chain
;
2198 old_chain
= save_current_program_space ();
2200 ALL_PSPACES (pspace
)
2201 ALL_OBJFILES (objfile
)
2203 struct breakpoint
*b
;
2204 struct minimal_symbol
*m
;
2206 set_current_program_space (pspace
);
2208 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2209 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2210 && MSYMBOL_TYPE (m
) != mst_file_text
))
2213 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2214 SYMBOL_VALUE_ADDRESS (m
),
2215 bp_std_terminate_master
);
2216 b
->addr_string
= xstrdup (func_name
);
2217 b
->enable_state
= bp_disabled
;
2219 update_global_location_list (1);
2221 do_cleanups (old_chain
);
2225 update_breakpoints_after_exec (void)
2227 struct breakpoint
*b
;
2228 struct breakpoint
*temp
;
2229 struct bp_location
*bploc
, **bplocp_tmp
;
2231 /* We're about to delete breakpoints from GDB's lists. If the
2232 INSERTED flag is true, GDB will try to lift the breakpoints by
2233 writing the breakpoints' "shadow contents" back into memory. The
2234 "shadow contents" are NOT valid after an exec, so GDB should not
2235 do that. Instead, the target is responsible from marking
2236 breakpoints out as soon as it detects an exec. We don't do that
2237 here instead, because there may be other attempts to delete
2238 breakpoints after detecting an exec and before reaching here. */
2239 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2240 if (bploc
->pspace
== current_program_space
)
2241 gdb_assert (!bploc
->inserted
);
2243 ALL_BREAKPOINTS_SAFE (b
, temp
)
2245 if (b
->pspace
!= current_program_space
)
2248 /* Solib breakpoints must be explicitly reset after an exec(). */
2249 if (b
->type
== bp_shlib_event
)
2251 delete_breakpoint (b
);
2255 /* JIT breakpoints must be explicitly reset after an exec(). */
2256 if (b
->type
== bp_jit_event
)
2258 delete_breakpoint (b
);
2262 /* Thread event breakpoints must be set anew after an exec(),
2263 as must overlay event and longjmp master breakpoints. */
2264 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2265 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2267 delete_breakpoint (b
);
2271 /* Step-resume breakpoints are meaningless after an exec(). */
2272 if (b
->type
== bp_step_resume
)
2274 delete_breakpoint (b
);
2278 /* Longjmp and longjmp-resume breakpoints are also meaningless
2280 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2282 delete_breakpoint (b
);
2286 if (b
->type
== bp_catchpoint
)
2288 /* For now, none of the bp_catchpoint breakpoints need to
2289 do anything at this point. In the future, if some of
2290 the catchpoints need to something, we will need to add
2291 a new method, and call this method from here. */
2295 /* bp_finish is a special case. The only way we ought to be able
2296 to see one of these when an exec() has happened, is if the user
2297 caught a vfork, and then said "finish". Ordinarily a finish just
2298 carries them to the call-site of the current callee, by setting
2299 a temporary bp there and resuming. But in this case, the finish
2300 will carry them entirely through the vfork & exec.
2302 We don't want to allow a bp_finish to remain inserted now. But
2303 we can't safely delete it, 'cause finish_command has a handle to
2304 the bp on a bpstat, and will later want to delete it. There's a
2305 chance (and I've seen it happen) that if we delete the bp_finish
2306 here, that its storage will get reused by the time finish_command
2307 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2308 We really must allow finish_command to delete a bp_finish.
2310 In the absense of a general solution for the "how do we know
2311 it's safe to delete something others may have handles to?"
2312 problem, what we'll do here is just uninsert the bp_finish, and
2313 let finish_command delete it.
2315 (We know the bp_finish is "doomed" in the sense that it's
2316 momentary, and will be deleted as soon as finish_command sees
2317 the inferior stopped. So it doesn't matter that the bp's
2318 address is probably bogus in the new a.out, unlike e.g., the
2319 solib breakpoints.) */
2321 if (b
->type
== bp_finish
)
2326 /* Without a symbolic address, we have little hope of the
2327 pre-exec() address meaning the same thing in the post-exec()
2329 if (b
->addr_string
== NULL
)
2331 delete_breakpoint (b
);
2335 /* FIXME what about longjmp breakpoints? Re-create them here? */
2336 create_overlay_event_breakpoint ("_ovly_debug_event");
2337 create_longjmp_master_breakpoint ("longjmp");
2338 create_longjmp_master_breakpoint ("_longjmp");
2339 create_longjmp_master_breakpoint ("siglongjmp");
2340 create_longjmp_master_breakpoint ("_siglongjmp");
2341 create_std_terminate_master_breakpoint ("std::terminate()");
2345 detach_breakpoints (int pid
)
2347 struct bp_location
*b
, **bp_tmp
;
2349 struct cleanup
*old_chain
= save_inferior_ptid ();
2350 struct inferior
*inf
= current_inferior ();
2352 if (pid
== PIDGET (inferior_ptid
))
2353 error (_("Cannot detach breakpoints of inferior_ptid"));
2355 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2356 inferior_ptid
= pid_to_ptid (pid
);
2357 ALL_BP_LOCATIONS (b
, bp_tmp
)
2359 if (b
->pspace
!= inf
->pspace
)
2363 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2365 do_cleanups (old_chain
);
2369 /* Remove the breakpoint location B from the current address space.
2370 Note that this is used to detach breakpoints from a child fork.
2371 When we get here, the child isn't in the inferior list, and neither
2372 do we have objects to represent its address space --- we should
2373 *not* look at b->pspace->aspace here. */
2376 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2379 struct cleanup
*old_chain
;
2381 if (b
->owner
->enable_state
== bp_permanent
)
2382 /* Permanent breakpoints cannot be inserted or removed. */
2385 /* The type of none suggests that owner is actually deleted.
2386 This should not ever happen. */
2387 gdb_assert (b
->owner
->type
!= bp_none
);
2389 if (b
->loc_type
== bp_loc_software_breakpoint
2390 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2392 /* "Normal" instruction breakpoint: either the standard
2393 trap-instruction bp (bp_breakpoint), or a
2394 bp_hardware_breakpoint. */
2396 /* First check to see if we have to handle an overlay. */
2397 if (overlay_debugging
== ovly_off
2398 || b
->section
== NULL
2399 || !(section_is_overlay (b
->section
)))
2401 /* No overlay handling: just remove the breakpoint. */
2403 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2404 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2406 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2410 /* This breakpoint is in an overlay section.
2411 Did we set a breakpoint at the LMA? */
2412 if (!overlay_events_enabled
)
2414 /* Yes -- overlay event support is not active, so we
2415 should have set a breakpoint at the LMA. Remove it.
2417 /* Ignore any failures: if the LMA is in ROM, we will
2418 have already warned when we failed to insert it. */
2419 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2420 target_remove_hw_breakpoint (b
->gdbarch
,
2421 &b
->overlay_target_info
);
2423 target_remove_breakpoint (b
->gdbarch
,
2424 &b
->overlay_target_info
);
2426 /* Did we set a breakpoint at the VMA?
2427 If so, we will have marked the breakpoint 'inserted'. */
2430 /* Yes -- remove it. Previously we did not bother to
2431 remove the breakpoint if the section had been
2432 unmapped, but let's not rely on that being safe. We
2433 don't know what the overlay manager might do. */
2434 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2435 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2438 /* However, we should remove *software* breakpoints only
2439 if the section is still mapped, or else we overwrite
2440 wrong code with the saved shadow contents. */
2441 else if (section_is_mapped (b
->section
))
2442 val
= target_remove_breakpoint (b
->gdbarch
,
2449 /* No -- not inserted, so no need to remove. No error. */
2454 /* In some cases, we might not be able to remove a breakpoint
2455 in a shared library that has already been removed, but we
2456 have not yet processed the shlib unload event. */
2457 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2462 b
->inserted
= (is
== mark_inserted
);
2464 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2469 b
->inserted
= (is
== mark_inserted
);
2470 val
= target_remove_watchpoint (b
->address
, b
->length
,
2471 b
->watchpoint_type
);
2473 /* Failure to remove any of the hardware watchpoints comes here. */
2474 if ((is
== mark_uninserted
) && (b
->inserted
))
2475 warning (_("Could not remove hardware watchpoint %d."),
2478 else if (b
->owner
->type
== bp_catchpoint
2479 && breakpoint_enabled (b
->owner
)
2482 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2484 val
= b
->owner
->ops
->remove (b
->owner
);
2487 b
->inserted
= (is
== mark_inserted
);
2494 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2497 struct cleanup
*old_chain
;
2499 if (b
->owner
->enable_state
== bp_permanent
)
2500 /* Permanent breakpoints cannot be inserted or removed. */
2503 /* The type of none suggests that owner is actually deleted.
2504 This should not ever happen. */
2505 gdb_assert (b
->owner
->type
!= bp_none
);
2507 old_chain
= save_current_space_and_thread ();
2509 switch_to_program_space_and_thread (b
->pspace
);
2511 ret
= remove_breakpoint_1 (b
, is
);
2513 do_cleanups (old_chain
);
2517 /* Clear the "inserted" flag in all breakpoints. */
2520 mark_breakpoints_out (void)
2522 struct bp_location
*bpt
, **bptp_tmp
;
2524 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2525 if (bpt
->pspace
== current_program_space
)
2529 /* Clear the "inserted" flag in all breakpoints and delete any
2530 breakpoints which should go away between runs of the program.
2532 Plus other such housekeeping that has to be done for breakpoints
2535 Note: this function gets called at the end of a run (by
2536 generic_mourn_inferior) and when a run begins (by
2537 init_wait_for_inferior). */
2542 breakpoint_init_inferior (enum inf_context context
)
2544 struct breakpoint
*b
, *temp
;
2545 struct bp_location
*bpt
, **bptp_tmp
;
2547 struct program_space
*pspace
= current_program_space
;
2549 /* If breakpoint locations are shared across processes, then there's
2551 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2554 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2556 if (bpt
->pspace
== pspace
2557 && bpt
->owner
->enable_state
!= bp_permanent
)
2561 ALL_BREAKPOINTS_SAFE (b
, temp
)
2563 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2570 /* If the call dummy breakpoint is at the entry point it will
2571 cause problems when the inferior is rerun, so we better get
2574 case bp_watchpoint_scope
:
2576 /* Also get rid of scope breakpoints. */
2578 case bp_shlib_event
:
2580 /* Also remove solib event breakpoints. Their addresses may
2581 have changed since the last time we ran the program.
2582 Actually we may now be debugging against different target;
2583 and so the solib backend that installed this breakpoint may
2584 not be used in by the target. E.g.,
2586 (gdb) file prog-linux
2587 (gdb) run # native linux target
2590 (gdb) file prog-win.exe
2591 (gdb) tar rem :9999 # remote Windows gdbserver.
2594 delete_breakpoint (b
);
2598 case bp_hardware_watchpoint
:
2599 case bp_read_watchpoint
:
2600 case bp_access_watchpoint
:
2602 /* Likewise for watchpoints on local expressions. */
2603 if (b
->exp_valid_block
!= NULL
)
2604 delete_breakpoint (b
);
2605 else if (context
== inf_starting
)
2607 /* Reset val field to force reread of starting value
2608 in insert_breakpoints. */
2610 value_free (b
->val
);
2620 /* Get rid of the moribund locations. */
2621 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2622 free_bp_location (bpt
);
2623 VEC_free (bp_location_p
, moribund_locations
);
2626 /* These functions concern about actual breakpoints inserted in the
2627 target --- to e.g. check if we need to do decr_pc adjustment or if
2628 we need to hop over the bkpt --- so we check for address space
2629 match, not program space. */
2631 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2632 exists at PC. It returns ordinary_breakpoint_here if it's an
2633 ordinary breakpoint, or permanent_breakpoint_here if it's a
2634 permanent breakpoint.
2635 - When continuing from a location with an ordinary breakpoint, we
2636 actually single step once before calling insert_breakpoints.
2637 - When continuing from a localion with a permanent breakpoint, we
2638 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2639 the target, to advance the PC past the breakpoint. */
2641 enum breakpoint_here
2642 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2644 struct bp_location
*bpt
, **bptp_tmp
;
2645 int any_breakpoint_here
= 0;
2647 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2649 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2650 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2653 if ((breakpoint_enabled (bpt
->owner
)
2654 || bpt
->owner
->enable_state
== bp_permanent
)
2655 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2658 if (overlay_debugging
2659 && section_is_overlay (bpt
->section
)
2660 && !section_is_mapped (bpt
->section
))
2661 continue; /* unmapped overlay -- can't be a match */
2662 else if (bpt
->owner
->enable_state
== bp_permanent
)
2663 return permanent_breakpoint_here
;
2665 any_breakpoint_here
= 1;
2669 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2672 /* Return true if there's a moribund breakpoint at PC. */
2675 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2677 struct bp_location
*loc
;
2680 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2681 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2688 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2689 inserted using regular breakpoint_chain / bp_location array mechanism.
2690 This does not check for single-step breakpoints, which are
2691 inserted and removed using direct target manipulation. */
2694 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2696 struct bp_location
*bpt
, **bptp_tmp
;
2698 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2700 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2701 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2705 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2708 if (overlay_debugging
2709 && section_is_overlay (bpt
->section
)
2710 && !section_is_mapped (bpt
->section
))
2711 continue; /* unmapped overlay -- can't be a match */
2719 /* Returns non-zero iff there's either regular breakpoint
2720 or a single step breakpoint inserted at PC. */
2723 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2725 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2728 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2734 /* This function returns non-zero iff there is a software breakpoint
2738 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2740 struct bp_location
*bpt
, **bptp_tmp
;
2741 int any_breakpoint_here
= 0;
2743 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2745 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2749 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2752 if (overlay_debugging
2753 && section_is_overlay (bpt
->section
)
2754 && !section_is_mapped (bpt
->section
))
2755 continue; /* unmapped overlay -- can't be a match */
2761 /* Also check for software single-step breakpoints. */
2762 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2769 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2770 CORE_ADDR addr
, ULONGEST len
)
2772 struct breakpoint
*bpt
;
2774 ALL_BREAKPOINTS (bpt
)
2776 struct bp_location
*loc
;
2778 if (bpt
->type
!= bp_hardware_watchpoint
2779 && bpt
->type
!= bp_access_watchpoint
)
2782 if (!breakpoint_enabled (bpt
))
2785 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2786 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2790 /* Check for intersection. */
2791 l
= max (loc
->address
, addr
);
2792 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2800 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2801 PC is valid for process/thread PTID. */
2804 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2807 struct bp_location
*bpt
, **bptp_tmp
;
2808 /* The thread and task IDs associated to PTID, computed lazily. */
2812 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2814 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2815 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2818 if (!breakpoint_enabled (bpt
->owner
)
2819 && bpt
->owner
->enable_state
!= bp_permanent
)
2822 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2826 if (bpt
->owner
->thread
!= -1)
2828 /* This is a thread-specific breakpoint. Check that ptid
2829 matches that thread. If thread hasn't been computed yet,
2830 it is now time to do so. */
2832 thread
= pid_to_thread_id (ptid
);
2833 if (bpt
->owner
->thread
!= thread
)
2837 if (bpt
->owner
->task
!= 0)
2839 /* This is a task-specific breakpoint. Check that ptid
2840 matches that task. If task hasn't been computed yet,
2841 it is now time to do so. */
2843 task
= ada_get_task_number (ptid
);
2844 if (bpt
->owner
->task
!= task
)
2848 if (overlay_debugging
2849 && section_is_overlay (bpt
->section
)
2850 && !section_is_mapped (bpt
->section
))
2851 continue; /* unmapped overlay -- can't be a match */
2860 /* bpstat stuff. External routines' interfaces are documented
2864 ep_is_catchpoint (struct breakpoint
*ep
)
2866 return (ep
->type
== bp_catchpoint
);
2870 bpstat_free (bpstat bs
)
2872 if (bs
->old_val
!= NULL
)
2873 value_free (bs
->old_val
);
2874 decref_counted_command_line (&bs
->commands
);
2878 /* Clear a bpstat so that it says we are not at any breakpoint.
2879 Also free any storage that is part of a bpstat. */
2882 bpstat_clear (bpstat
*bsp
)
2899 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2900 is part of the bpstat is copied as well. */
2903 bpstat_copy (bpstat bs
)
2907 bpstat retval
= NULL
;
2912 for (; bs
!= NULL
; bs
= bs
->next
)
2914 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2915 memcpy (tmp
, bs
, sizeof (*tmp
));
2916 incref_counted_command_line (tmp
->commands
);
2917 if (bs
->old_val
!= NULL
)
2919 tmp
->old_val
= value_copy (bs
->old_val
);
2920 release_value (tmp
->old_val
);
2924 /* This is the first thing in the chain. */
2934 /* Find the bpstat associated with this breakpoint */
2937 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2942 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2944 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2950 /* Find a step_resume breakpoint associated with this bpstat.
2951 (If there are multiple step_resume bp's on the list, this function
2952 will arbitrarily pick one.)
2954 It is an error to use this function if BPSTAT doesn't contain a
2955 step_resume breakpoint.
2957 See wait_for_inferior's use of this function. */
2959 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2963 gdb_assert (bsp
!= NULL
);
2965 current_thread
= pid_to_thread_id (inferior_ptid
);
2967 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2969 if ((bsp
->breakpoint_at
!= NULL
)
2970 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2971 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2972 || bsp
->breakpoint_at
->owner
->thread
== -1))
2973 return bsp
->breakpoint_at
->owner
;
2976 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2980 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2981 at. *BSP upon return is a bpstat which points to the remaining
2982 breakpoints stopped at (but which is not guaranteed to be good for
2983 anything but further calls to bpstat_num).
2984 Return 0 if passed a bpstat which does not indicate any breakpoints.
2985 Return -1 if stopped at a breakpoint that has been deleted since
2987 Return 1 otherwise. */
2990 bpstat_num (bpstat
*bsp
, int *num
)
2992 struct breakpoint
*b
;
2995 return 0; /* No more breakpoint values */
2997 /* We assume we'll never have several bpstats that
2998 correspond to a single breakpoint -- otherwise,
2999 this function might return the same number more
3000 than once and this will look ugly. */
3001 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
3002 *bsp
= (*bsp
)->next
;
3004 return -1; /* breakpoint that's been deleted since */
3006 *num
= b
->number
; /* We have its number */
3010 /* Modify BS so that the actions will not be performed. */
3013 bpstat_clear_actions (bpstat bs
)
3015 for (; bs
!= NULL
; bs
= bs
->next
)
3017 decref_counted_command_line (&bs
->commands
);
3018 bs
->commands_left
= NULL
;
3019 if (bs
->old_val
!= NULL
)
3021 value_free (bs
->old_val
);
3027 /* Called when a command is about to proceed the inferior. */
3030 breakpoint_about_to_proceed (void)
3032 if (!ptid_equal (inferior_ptid
, null_ptid
))
3034 struct thread_info
*tp
= inferior_thread ();
3036 /* Allow inferior function calls in breakpoint commands to not
3037 interrupt the command list. When the call finishes
3038 successfully, the inferior will be standing at the same
3039 breakpoint as if nothing happened. */
3044 breakpoint_proceeded
= 1;
3047 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3049 cleanup_executing_breakpoints (void *ignore
)
3051 executing_breakpoint_commands
= 0;
3054 /* Execute all the commands associated with all the breakpoints at this
3055 location. Any of these commands could cause the process to proceed
3056 beyond this point, etc. We look out for such changes by checking
3057 the global "breakpoint_proceeded" after each command.
3059 Returns true if a breakpoint command resumed the inferior. In that
3060 case, it is the caller's responsibility to recall it again with the
3061 bpstat of the current thread. */
3064 bpstat_do_actions_1 (bpstat
*bsp
)
3067 struct cleanup
*old_chain
;
3070 /* Avoid endless recursion if a `source' command is contained
3072 if (executing_breakpoint_commands
)
3075 executing_breakpoint_commands
= 1;
3076 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3078 /* This pointer will iterate over the list of bpstat's. */
3081 breakpoint_proceeded
= 0;
3082 for (; bs
!= NULL
; bs
= bs
->next
)
3084 struct counted_command_line
*ccmd
;
3085 struct command_line
*cmd
;
3086 struct cleanup
*this_cmd_tree_chain
;
3088 /* Take ownership of the BSP's command tree, if it has one.
3090 The command tree could legitimately contain commands like
3091 'step' and 'next', which call clear_proceed_status, which
3092 frees stop_bpstat's command tree. To make sure this doesn't
3093 free the tree we're executing out from under us, we need to
3094 take ownership of the tree ourselves. Since a given bpstat's
3095 commands are only executed once, we don't need to copy it; we
3096 can clear the pointer in the bpstat, and make sure we free
3097 the tree when we're done. */
3098 ccmd
= bs
->commands
;
3099 bs
->commands
= NULL
;
3101 = make_cleanup_decref_counted_command_line (&ccmd
);
3102 cmd
= bs
->commands_left
;
3103 bs
->commands_left
= NULL
;
3107 execute_control_command (cmd
);
3109 if (breakpoint_proceeded
)
3115 /* We can free this command tree now. */
3116 do_cleanups (this_cmd_tree_chain
);
3118 if (breakpoint_proceeded
)
3120 if (target_can_async_p ())
3121 /* If we are in async mode, then the target might be still
3122 running, not stopped at any breakpoint, so nothing for
3123 us to do here -- just return to the event loop. */
3126 /* In sync mode, when execute_control_command returns
3127 we're already standing on the next breakpoint.
3128 Breakpoint commands for that stop were not run, since
3129 execute_command does not run breakpoint commands --
3130 only command_line_handler does, but that one is not
3131 involved in execution of breakpoint commands. So, we
3132 can now execute breakpoint commands. It should be
3133 noted that making execute_command do bpstat actions is
3134 not an option -- in this case we'll have recursive
3135 invocation of bpstat for each breakpoint with a
3136 command, and can easily blow up GDB stack. Instead, we
3137 return true, which will trigger the caller to recall us
3138 with the new stop_bpstat. */
3143 do_cleanups (old_chain
);
3148 bpstat_do_actions (void)
3150 /* Do any commands attached to breakpoint we are stopped at. */
3151 while (!ptid_equal (inferior_ptid
, null_ptid
)
3152 && target_has_execution
3153 && !is_exited (inferior_ptid
)
3154 && !is_executing (inferior_ptid
))
3155 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3156 and only return when it is stopped at the next breakpoint, we
3157 keep doing breakpoint actions until it returns false to
3158 indicate the inferior was not resumed. */
3159 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3163 /* Print out the (old or new) value associated with a watchpoint. */
3166 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3169 fprintf_unfiltered (stream
, _("<unreadable>"));
3172 struct value_print_options opts
;
3173 get_user_print_options (&opts
);
3174 value_print (val
, stream
, &opts
);
3178 /* This is the normal print function for a bpstat. In the future,
3179 much of this logic could (should?) be moved to bpstat_stop_status,
3180 by having it set different print_it values.
3182 Current scheme: When we stop, bpstat_print() is called. It loops
3183 through the bpstat list of things causing this stop, calling the
3184 print_bp_stop_message function on each one. The behavior of the
3185 print_bp_stop_message function depends on the print_it field of
3186 bpstat. If such field so indicates, call this function here.
3188 Return values from this routine (ultimately used by bpstat_print()
3189 and normal_stop() to decide what to do):
3190 PRINT_NOTHING: Means we already printed all we needed to print,
3191 don't print anything else.
3192 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3193 that something to be followed by a location.
3194 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3195 that something to be followed by a location.
3196 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3199 static enum print_stop_action
3200 print_it_typical (bpstat bs
)
3202 struct cleanup
*old_chain
;
3203 struct breakpoint
*b
;
3204 const struct bp_location
*bl
;
3205 struct ui_stream
*stb
;
3207 enum print_stop_action result
;
3209 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3210 which has since been deleted. */
3211 if (bs
->breakpoint_at
== NULL
)
3212 return PRINT_UNKNOWN
;
3213 bl
= bs
->breakpoint_at
;
3216 stb
= ui_out_stream_new (uiout
);
3217 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3222 case bp_hardware_breakpoint
:
3223 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3224 if (bl
->address
!= bl
->requested_address
)
3225 breakpoint_adjustment_warning (bl
->requested_address
,
3228 annotate_breakpoint (b
->number
);
3230 ui_out_text (uiout
, "\nTemporary breakpoint ");
3232 ui_out_text (uiout
, "\nBreakpoint ");
3233 if (ui_out_is_mi_like_p (uiout
))
3235 ui_out_field_string (uiout
, "reason",
3236 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3237 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3239 ui_out_field_int (uiout
, "bkptno", b
->number
);
3240 ui_out_text (uiout
, ", ");
3241 result
= PRINT_SRC_AND_LOC
;
3244 case bp_shlib_event
:
3245 /* Did we stop because the user set the stop_on_solib_events
3246 variable? (If so, we report this as a generic, "Stopped due
3247 to shlib event" message.) */
3248 printf_filtered (_("Stopped due to shared library event\n"));
3249 result
= PRINT_NOTHING
;
3252 case bp_thread_event
:
3253 /* Not sure how we will get here.
3254 GDB should not stop for these breakpoints. */
3255 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3256 result
= PRINT_NOTHING
;
3259 case bp_overlay_event
:
3260 /* By analogy with the thread event, GDB should not stop for these. */
3261 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3262 result
= PRINT_NOTHING
;
3265 case bp_longjmp_master
:
3266 /* These should never be enabled. */
3267 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3268 result
= PRINT_NOTHING
;
3271 case bp_std_terminate_master
:
3272 /* These should never be enabled. */
3273 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3274 result
= PRINT_NOTHING
;
3278 case bp_hardware_watchpoint
:
3279 annotate_watchpoint (b
->number
);
3280 if (ui_out_is_mi_like_p (uiout
))
3283 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3285 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3286 ui_out_text (uiout
, "\nOld value = ");
3287 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3288 ui_out_field_stream (uiout
, "old", stb
);
3289 ui_out_text (uiout
, "\nNew value = ");
3290 watchpoint_value_print (b
->val
, stb
->stream
);
3291 ui_out_field_stream (uiout
, "new", stb
);
3292 ui_out_text (uiout
, "\n");
3293 /* More than one watchpoint may have been triggered. */
3294 result
= PRINT_UNKNOWN
;
3297 case bp_read_watchpoint
:
3298 if (ui_out_is_mi_like_p (uiout
))
3301 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3303 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3304 ui_out_text (uiout
, "\nValue = ");
3305 watchpoint_value_print (b
->val
, stb
->stream
);
3306 ui_out_field_stream (uiout
, "value", stb
);
3307 ui_out_text (uiout
, "\n");
3308 result
= PRINT_UNKNOWN
;
3311 case bp_access_watchpoint
:
3312 if (bs
->old_val
!= NULL
)
3314 annotate_watchpoint (b
->number
);
3315 if (ui_out_is_mi_like_p (uiout
))
3318 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3320 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3321 ui_out_text (uiout
, "\nOld value = ");
3322 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3323 ui_out_field_stream (uiout
, "old", stb
);
3324 ui_out_text (uiout
, "\nNew value = ");
3329 if (ui_out_is_mi_like_p (uiout
))
3332 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3333 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3334 ui_out_text (uiout
, "\nValue = ");
3336 watchpoint_value_print (b
->val
, stb
->stream
);
3337 ui_out_field_stream (uiout
, "new", stb
);
3338 ui_out_text (uiout
, "\n");
3339 result
= PRINT_UNKNOWN
;
3342 /* Fall through, we don't deal with these types of breakpoints
3346 if (ui_out_is_mi_like_p (uiout
))
3349 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3350 result
= PRINT_UNKNOWN
;
3354 if (ui_out_is_mi_like_p (uiout
))
3357 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3358 result
= PRINT_UNKNOWN
;
3363 case bp_longjmp_resume
:
3364 case bp_step_resume
:
3365 case bp_watchpoint_scope
:
3367 case bp_std_terminate
:
3369 case bp_fast_tracepoint
:
3372 result
= PRINT_UNKNOWN
;
3376 do_cleanups (old_chain
);
3380 /* Generic routine for printing messages indicating why we
3381 stopped. The behavior of this function depends on the value
3382 'print_it' in the bpstat structure. Under some circumstances we
3383 may decide not to print anything here and delegate the task to
3386 static enum print_stop_action
3387 print_bp_stop_message (bpstat bs
)
3389 switch (bs
->print_it
)
3392 /* Nothing should be printed for this bpstat entry. */
3393 return PRINT_UNKNOWN
;
3397 /* We still want to print the frame, but we already printed the
3398 relevant messages. */
3399 return PRINT_SRC_AND_LOC
;
3402 case print_it_normal
:
3404 const struct bp_location
*bl
= bs
->breakpoint_at
;
3405 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3407 /* Normal case. Call the breakpoint's print_it method, or
3408 print_it_typical. */
3409 /* FIXME: how breakpoint can ever be NULL here? */
3410 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3411 return b
->ops
->print_it (b
);
3413 return print_it_typical (bs
);
3418 internal_error (__FILE__
, __LINE__
,
3419 _("print_bp_stop_message: unrecognized enum value"));
3424 /* Print a message indicating what happened. This is called from
3425 normal_stop(). The input to this routine is the head of the bpstat
3426 list - a list of the eventpoints that caused this stop. This
3427 routine calls the generic print routine for printing a message
3428 about reasons for stopping. This will print (for example) the
3429 "Breakpoint n," part of the output. The return value of this
3432 PRINT_UNKNOWN: Means we printed nothing
3433 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3434 code to print the location. An example is
3435 "Breakpoint 1, " which should be followed by
3437 PRINT_SRC_ONLY: Means we printed something, but there is no need
3438 to also print the location part of the message.
3439 An example is the catch/throw messages, which
3440 don't require a location appended to the end.
3441 PRINT_NOTHING: We have done some printing and we don't need any
3442 further info to be printed.*/
3444 enum print_stop_action
3445 bpstat_print (bpstat bs
)
3449 /* Maybe another breakpoint in the chain caused us to stop.
3450 (Currently all watchpoints go on the bpstat whether hit or not.
3451 That probably could (should) be changed, provided care is taken
3452 with respect to bpstat_explains_signal). */
3453 for (; bs
; bs
= bs
->next
)
3455 val
= print_bp_stop_message (bs
);
3456 if (val
== PRINT_SRC_ONLY
3457 || val
== PRINT_SRC_AND_LOC
3458 || val
== PRINT_NOTHING
)
3462 /* We reached the end of the chain, or we got a null BS to start
3463 with and nothing was printed. */
3464 return PRINT_UNKNOWN
;
3467 /* Evaluate the expression EXP and return 1 if value is zero.
3468 This is used inside a catch_errors to evaluate the breakpoint condition.
3469 The argument is a "struct expression *" that has been cast to char * to
3470 make it pass through catch_errors. */
3473 breakpoint_cond_eval (void *exp
)
3475 struct value
*mark
= value_mark ();
3476 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3477 value_free_to_mark (mark
);
3481 /* Allocate a new bpstat and chain it to the current one. */
3484 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3488 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3490 bs
->breakpoint_at
= bl
;
3491 /* If the condition is false, etc., don't do the commands. */
3492 bs
->commands
= NULL
;
3493 bs
->commands_left
= NULL
;
3495 bs
->print_it
= print_it_normal
;
3499 /* The target has stopped with waitstatus WS. Check if any hardware
3500 watchpoints have triggered, according to the target. */
3503 watchpoints_triggered (struct target_waitstatus
*ws
)
3505 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3507 struct breakpoint
*b
;
3509 if (!stopped_by_watchpoint
)
3511 /* We were not stopped by a watchpoint. Mark all watchpoints
3512 as not triggered. */
3514 if (b
->type
== bp_hardware_watchpoint
3515 || b
->type
== bp_read_watchpoint
3516 || b
->type
== bp_access_watchpoint
)
3517 b
->watchpoint_triggered
= watch_triggered_no
;
3522 if (!target_stopped_data_address (¤t_target
, &addr
))
3524 /* We were stopped by a watchpoint, but we don't know where.
3525 Mark all watchpoints as unknown. */
3527 if (b
->type
== bp_hardware_watchpoint
3528 || b
->type
== bp_read_watchpoint
3529 || b
->type
== bp_access_watchpoint
)
3530 b
->watchpoint_triggered
= watch_triggered_unknown
;
3532 return stopped_by_watchpoint
;
3535 /* The target could report the data address. Mark watchpoints
3536 affected by this data address as triggered, and all others as not
3540 if (b
->type
== bp_hardware_watchpoint
3541 || b
->type
== bp_read_watchpoint
3542 || b
->type
== bp_access_watchpoint
)
3544 struct bp_location
*loc
;
3547 b
->watchpoint_triggered
= watch_triggered_no
;
3548 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3549 /* Exact match not required. Within range is
3551 if (target_watchpoint_addr_within_range (¤t_target
,
3555 b
->watchpoint_triggered
= watch_triggered_yes
;
3563 /* Possible return values for watchpoint_check (this can't be an enum
3564 because of check_errors). */
3565 /* The watchpoint has been deleted. */
3566 #define WP_DELETED 1
3567 /* The value has changed. */
3568 #define WP_VALUE_CHANGED 2
3569 /* The value has not changed. */
3570 #define WP_VALUE_NOT_CHANGED 3
3571 /* Ignore this watchpoint, no matter if the value changed or not. */
3574 #define BP_TEMPFLAG 1
3575 #define BP_HARDWAREFLAG 2
3577 /* Evaluate watchpoint condition expression and check if its value changed.
3579 P should be a pointer to struct bpstat, but is defined as a void *
3580 in order for this function to be usable with catch_errors. */
3583 watchpoint_check (void *p
)
3585 bpstat bs
= (bpstat
) p
;
3586 struct breakpoint
*b
;
3587 struct frame_info
*fr
;
3588 int within_current_scope
;
3590 b
= bs
->breakpoint_at
->owner
;
3592 /* If this is a local watchpoint, we only want to check if the
3593 watchpoint frame is in scope if the current thread is the thread
3594 that was used to create the watchpoint. */
3595 if (!watchpoint_in_thread_scope (b
))
3598 if (b
->exp_valid_block
== NULL
)
3599 within_current_scope
= 1;
3602 struct frame_info
*frame
= get_current_frame ();
3603 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3604 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3606 /* in_function_epilogue_p() returns a non-zero value if we're still
3607 in the function but the stack frame has already been invalidated.
3608 Since we can't rely on the values of local variables after the
3609 stack has been destroyed, we are treating the watchpoint in that
3610 state as `not changed' without further checking. Don't mark
3611 watchpoints as changed if the current frame is in an epilogue -
3612 even if they are in some other frame, our view of the stack
3613 is likely to be wrong and frame_find_by_id could error out. */
3614 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3617 fr
= frame_find_by_id (b
->watchpoint_frame
);
3618 within_current_scope
= (fr
!= NULL
);
3620 /* If we've gotten confused in the unwinder, we might have
3621 returned a frame that can't describe this variable. */
3622 if (within_current_scope
)
3624 struct symbol
*function
;
3626 function
= get_frame_function (fr
);
3627 if (function
== NULL
3628 || !contained_in (b
->exp_valid_block
,
3629 SYMBOL_BLOCK_VALUE (function
)))
3630 within_current_scope
= 0;
3633 if (within_current_scope
)
3634 /* If we end up stopping, the current frame will get selected
3635 in normal_stop. So this call to select_frame won't affect
3640 if (within_current_scope
)
3642 /* We use value_{,free_to_}mark because it could be a
3643 *long* time before we return to the command level and
3644 call free_all_values. We can't call free_all_values because
3645 we might be in the middle of evaluating a function call. */
3647 struct value
*mark
= value_mark ();
3648 struct value
*new_val
;
3650 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3652 /* We use value_equal_contents instead of value_equal because the latter
3653 coerces an array to a pointer, thus comparing just the address of the
3654 array instead of its contents. This is not what we want. */
3655 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3656 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3658 if (new_val
!= NULL
)
3660 release_value (new_val
);
3661 value_free_to_mark (mark
);
3663 bs
->old_val
= b
->val
;
3666 return WP_VALUE_CHANGED
;
3670 /* Nothing changed. */
3671 value_free_to_mark (mark
);
3672 return WP_VALUE_NOT_CHANGED
;
3677 /* This seems like the only logical thing to do because
3678 if we temporarily ignored the watchpoint, then when
3679 we reenter the block in which it is valid it contains
3680 garbage (in the case of a function, it may have two
3681 garbage values, one before and one after the prologue).
3682 So we can't even detect the first assignment to it and
3683 watch after that (since the garbage may or may not equal
3684 the first value assigned). */
3685 /* We print all the stop information in print_it_typical(), but
3686 in this case, by the time we call print_it_typical() this bp
3687 will be deleted already. So we have no choice but print the
3688 information here. */
3689 if (ui_out_is_mi_like_p (uiout
))
3691 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3692 ui_out_text (uiout
, "\nWatchpoint ");
3693 ui_out_field_int (uiout
, "wpnum", b
->number
);
3694 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3695 which its expression is valid.\n");
3697 if (b
->related_breakpoint
)
3699 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3700 b
->related_breakpoint
->related_breakpoint
= NULL
;
3701 b
->related_breakpoint
= NULL
;
3703 b
->disposition
= disp_del_at_next_stop
;
3709 /* Return true if it looks like target has stopped due to hitting
3710 breakpoint location BL. This function does not check if we
3711 should stop, only if BL explains the stop. */
3713 bpstat_check_location (const struct bp_location
*bl
,
3714 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3716 struct breakpoint
*b
= bl
->owner
;
3718 /* By definition, the inferior does not report stops at
3720 if (tracepoint_type (b
))
3723 if (b
->type
!= bp_watchpoint
3724 && b
->type
!= bp_hardware_watchpoint
3725 && b
->type
!= bp_read_watchpoint
3726 && b
->type
!= bp_access_watchpoint
3727 && b
->type
!= bp_hardware_breakpoint
3728 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3730 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3733 if (overlay_debugging
/* unmapped overlay section */
3734 && section_is_overlay (bl
->section
)
3735 && !section_is_mapped (bl
->section
))
3739 /* Continuable hardware watchpoints are treated as non-existent if the
3740 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3741 some data address). Otherwise gdb won't stop on a break instruction
3742 in the code (not from a breakpoint) when a hardware watchpoint has
3743 been defined. Also skip watchpoints which we know did not trigger
3744 (did not match the data address). */
3746 if ((b
->type
== bp_hardware_watchpoint
3747 || b
->type
== bp_read_watchpoint
3748 || b
->type
== bp_access_watchpoint
)
3749 && b
->watchpoint_triggered
== watch_triggered_no
)
3752 if (b
->type
== bp_hardware_breakpoint
)
3754 if (bl
->address
!= bp_addr
)
3756 if (overlay_debugging
/* unmapped overlay section */
3757 && section_is_overlay (bl
->section
)
3758 && !section_is_mapped (bl
->section
))
3762 if (b
->type
== bp_catchpoint
)
3764 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3765 if (!b
->ops
->breakpoint_hit (b
))
3772 /* If BS refers to a watchpoint, determine if the watched values
3773 has actually changed, and we should stop. If not, set BS->stop
3776 bpstat_check_watchpoint (bpstat bs
)
3778 const struct bp_location
*bl
= bs
->breakpoint_at
;
3779 struct breakpoint
*b
= bl
->owner
;
3781 if (b
->type
== bp_watchpoint
3782 || b
->type
== bp_read_watchpoint
3783 || b
->type
== bp_access_watchpoint
3784 || b
->type
== bp_hardware_watchpoint
)
3788 int must_check_value
= 0;
3790 if (b
->type
== bp_watchpoint
)
3791 /* For a software watchpoint, we must always check the
3793 must_check_value
= 1;
3794 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3795 /* We have a hardware watchpoint (read, write, or access)
3796 and the target earlier reported an address watched by
3798 must_check_value
= 1;
3799 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3800 && b
->type
== bp_hardware_watchpoint
)
3801 /* We were stopped by a hardware watchpoint, but the target could
3802 not report the data address. We must check the watchpoint's
3803 value. Access and read watchpoints are out of luck; without
3804 a data address, we can't figure it out. */
3805 must_check_value
= 1;
3807 if (must_check_value
)
3809 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3811 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3812 int e
= catch_errors (watchpoint_check
, bs
, message
,
3814 do_cleanups (cleanups
);
3818 /* We've already printed what needs to be printed. */
3819 bs
->print_it
= print_it_done
;
3823 bs
->print_it
= print_it_noop
;
3826 case WP_VALUE_CHANGED
:
3827 if (b
->type
== bp_read_watchpoint
)
3829 /* There are two cases to consider here:
3831 1. we're watching the triggered memory for reads.
3832 In that case, trust the target, and always report
3833 the watchpoint hit to the user. Even though
3834 reads don't cause value changes, the value may
3835 have changed since the last time it was read, and
3836 since we're not trapping writes, we will not see
3837 those, and as such we should ignore our notion of
3840 2. we're watching the triggered memory for both
3841 reads and writes. There are two ways this may
3844 2.1. this is a target that can't break on data
3845 reads only, but can break on accesses (reads or
3846 writes), such as e.g., x86. We detect this case
3847 at the time we try to insert read watchpoints.
3849 2.2. otherwise, the target supports read
3850 watchpoints, but, the user set an access or write
3851 watchpoint watching the same memory as this read
3854 If we're watching memory writes as well as reads,
3855 ignore watchpoint hits when we find that the
3856 value hasn't changed, as reads don't cause
3857 changes. This still gives false positives when
3858 the program writes the same value to memory as
3859 what there was already in memory (we will confuse
3860 it for a read), but it's much better than
3863 int other_write_watchpoint
= 0;
3865 if (bl
->watchpoint_type
== hw_read
)
3867 struct breakpoint
*other_b
;
3869 ALL_BREAKPOINTS (other_b
)
3870 if ((other_b
->type
== bp_hardware_watchpoint
3871 || other_b
->type
== bp_access_watchpoint
)
3872 && (other_b
->watchpoint_triggered
3873 == watch_triggered_yes
))
3875 other_write_watchpoint
= 1;
3880 if (other_write_watchpoint
3881 || bl
->watchpoint_type
== hw_access
)
3883 /* We're watching the same memory for writes,
3884 and the value changed since the last time we
3885 updated it, so this trap must be for a write.
3887 bs
->print_it
= print_it_noop
;
3892 case WP_VALUE_NOT_CHANGED
:
3893 if (b
->type
== bp_hardware_watchpoint
3894 || b
->type
== bp_watchpoint
)
3896 /* Don't stop: write watchpoints shouldn't fire if
3897 the value hasn't changed. */
3898 bs
->print_it
= print_it_noop
;
3906 /* Error from catch_errors. */
3907 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3908 if (b
->related_breakpoint
)
3909 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3910 b
->disposition
= disp_del_at_next_stop
;
3911 /* We've already printed what needs to be printed. */
3912 bs
->print_it
= print_it_done
;
3916 else /* must_check_value == 0 */
3918 /* This is a case where some watchpoint(s) triggered, but
3919 not at the address of this watchpoint, or else no
3920 watchpoint triggered after all. So don't print
3921 anything for this watchpoint. */
3922 bs
->print_it
= print_it_noop
;
3929 /* Check conditions (condition proper, frame, thread and ignore count)
3930 of breakpoint referred to by BS. If we should not stop for this
3931 breakpoint, set BS->stop to 0. */
3933 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3935 int thread_id
= pid_to_thread_id (ptid
);
3936 const struct bp_location
*bl
= bs
->breakpoint_at
;
3937 struct breakpoint
*b
= bl
->owner
;
3939 if (frame_id_p (b
->frame_id
)
3940 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3944 int value_is_zero
= 0;
3945 struct expression
*cond
;
3947 /* If this is a scope breakpoint, mark the associated
3948 watchpoint as triggered so that we will handle the
3949 out-of-scope event. We'll get to the watchpoint next
3951 if (b
->type
== bp_watchpoint_scope
)
3952 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3954 if (is_watchpoint (b
))
3959 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3961 int within_current_scope
= 1;
3963 /* We use value_mark and value_free_to_mark because it could
3964 be a long time before we return to the command level and
3965 call free_all_values. We can't call free_all_values
3966 because we might be in the middle of evaluating a
3968 struct value
*mark
= value_mark ();
3970 /* Need to select the frame, with all that implies so that
3971 the conditions will have the right context. Because we
3972 use the frame, we will not see an inlined function's
3973 variables when we arrive at a breakpoint at the start
3974 of the inlined function; the current frame will be the
3976 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3977 select_frame (get_current_frame ());
3980 struct frame_info
*frame
;
3982 /* For local watchpoint expressions, which particular
3983 instance of a local is being watched matters, so we
3984 keep track of the frame to evaluate the expression
3985 in. To evaluate the condition however, it doesn't
3986 really matter which instantiation of the function
3987 where the condition makes sense triggers the
3988 watchpoint. This allows an expression like "watch
3989 global if q > 10" set in `func', catch writes to
3990 global on all threads that call `func', or catch
3991 writes on all recursive calls of `func' by a single
3992 thread. We simply always evaluate the condition in
3993 the innermost frame that's executing where it makes
3994 sense to evaluate the condition. It seems
3996 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3998 select_frame (frame
);
4000 within_current_scope
= 0;
4002 if (within_current_scope
)
4004 = catch_errors (breakpoint_cond_eval
, cond
,
4005 "Error in testing breakpoint condition:\n",
4009 warning (_("Watchpoint condition cannot be tested "
4010 "in the current scope"));
4011 /* If we failed to set the right context for this
4012 watchpoint, unconditionally report it. */
4015 /* FIXME-someday, should give breakpoint # */
4016 value_free_to_mark (mark
);
4019 if (cond
&& value_is_zero
)
4023 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4027 else if (b
->ignore_count
> 0)
4030 annotate_ignore_count_change ();
4032 /* Increase the hit count even though we don't
4040 /* Get a bpstat associated with having just stopped at address
4041 BP_ADDR in thread PTID.
4043 Determine whether we stopped at a breakpoint, etc, or whether we
4044 don't understand this stop. Result is a chain of bpstat's such that:
4046 if we don't understand the stop, the result is a null pointer.
4048 if we understand why we stopped, the result is not null.
4050 Each element of the chain refers to a particular breakpoint or
4051 watchpoint at which we have stopped. (We may have stopped for
4052 several reasons concurrently.)
4054 Each element of the chain has valid next, breakpoint_at,
4055 commands, FIXME??? fields. */
4058 bpstat_stop_status (struct address_space
*aspace
,
4059 CORE_ADDR bp_addr
, ptid_t ptid
)
4061 struct breakpoint
*b
= NULL
;
4062 struct bp_location
*bl
, **blp_tmp
;
4063 struct bp_location
*loc
;
4064 /* Root of the chain of bpstat's */
4065 struct bpstats root_bs
[1];
4066 /* Pointer to the last thing in the chain currently. */
4067 bpstat bs
= root_bs
;
4069 int need_remove_insert
;
4071 /* ALL_BP_LOCATIONS iteration would break across
4072 update_global_location_list possibly executed by
4073 bpstat_check_breakpoint_conditions's inferior call. */
4077 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4080 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4082 /* For hardware watchpoints, we look only at the first location.
4083 The watchpoint_check function will work on entire expression,
4084 not the individual locations. For read watchopints, the
4085 watchpoints_triggered function have checked all locations
4087 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4090 if (bl
->shlib_disabled
)
4093 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4096 /* Come here if it's a watchpoint, or if the break address matches */
4098 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4100 /* Assume we stop. Should we find watchpoint that is not actually
4101 triggered, or if condition of breakpoint is false, we'll reset
4106 bpstat_check_watchpoint (bs
);
4110 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4111 || b
->type
== bp_longjmp_master
4112 || b
->type
== bp_std_terminate_master
)
4113 /* We do not stop for these. */
4116 bpstat_check_breakpoint_conditions (bs
, ptid
);
4122 /* We will stop here */
4123 if (b
->disposition
== disp_disable
)
4125 if (b
->enable_state
!= bp_permanent
)
4126 b
->enable_state
= bp_disabled
;
4127 update_global_location_list (0);
4131 bs
->commands
= b
->commands
;
4132 incref_counted_command_line (bs
->commands
);
4133 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4134 if (bs
->commands_left
4135 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4138 bs
->commands_left
->line
) == 0)))
4140 bs
->commands_left
= bs
->commands_left
->next
;
4145 /* Print nothing for this entry if we dont stop or dont print. */
4146 if (bs
->stop
== 0 || bs
->print
== 0)
4147 bs
->print_it
= print_it_noop
;
4151 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4153 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4156 bs
= bpstat_alloc (loc
, bs
);
4157 /* For hits of moribund locations, we should just proceed. */
4160 bs
->print_it
= print_it_noop
;
4164 bs
->next
= NULL
; /* Terminate the chain */
4166 /* If we aren't stopping, the value of some hardware watchpoint may
4167 not have changed, but the intermediate memory locations we are
4168 watching may have. Don't bother if we're stopping; this will get
4170 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4174 need_remove_insert
= 0;
4176 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4178 && bs
->breakpoint_at
->owner
4179 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4181 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4182 /* Updating watchpoints invalidates bs->breakpoint_at.
4183 Prevent further code from trying to use it. */
4184 bs
->breakpoint_at
= NULL
;
4185 need_remove_insert
= 1;
4188 if (need_remove_insert
)
4189 update_global_location_list (1);
4191 return root_bs
->next
;
4194 /* Tell what to do about this bpstat. */
4196 bpstat_what (bpstat bs
)
4198 /* Classify each bpstat as one of the following. */
4201 /* This bpstat element has no effect on the main_action. */
4204 /* There was a watchpoint, stop but don't print. */
4207 /* There was a watchpoint, stop and print. */
4210 /* There was a breakpoint but we're not stopping. */
4213 /* There was a breakpoint, stop but don't print. */
4216 /* There was a breakpoint, stop and print. */
4219 /* We hit the longjmp breakpoint. */
4222 /* We hit the longjmp_resume breakpoint. */
4225 /* We hit the step_resume breakpoint. */
4228 /* We hit the shared library event breakpoint. */
4231 /* We hit the jit event breakpoint. */
4234 /* This is just used to count how many enums there are. */
4238 /* Here is the table which drives this routine. So that we can
4239 format it pretty, we define some abbreviations for the
4240 enum bpstat_what codes. */
4241 #define kc BPSTAT_WHAT_KEEP_CHECKING
4242 #define ss BPSTAT_WHAT_STOP_SILENT
4243 #define sn BPSTAT_WHAT_STOP_NOISY
4244 #define sgl BPSTAT_WHAT_SINGLE
4245 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4246 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4247 #define sr BPSTAT_WHAT_STEP_RESUME
4248 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4249 #define jit BPSTAT_WHAT_CHECK_JIT
4251 /* "Can't happen." Might want to print an error message.
4252 abort() is not out of the question, but chances are GDB is just
4253 a bit confused, not unusable. */
4254 #define err BPSTAT_WHAT_STOP_NOISY
4256 /* Given an old action and a class, come up with a new action. */
4257 /* One interesting property of this table is that wp_silent is the same
4258 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4259 after stopping, the check for whether to step over a breakpoint
4260 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4261 reference to how we stopped. We retain separate wp_silent and
4262 bp_silent codes in case we want to change that someday.
4264 Another possibly interesting property of this table is that
4265 there's a partial ordering, priority-like, of the actions. Once
4266 you've decided that some action is appropriate, you'll never go
4267 back and decide something of a lower priority is better. The
4270 kc < jit clr sgl shl slr sn sr ss
4271 sgl < jit shl slr sn sr ss
4272 slr < jit err shl sn sr ss
4273 clr < jit err shl sn sr ss
4280 What I think this means is that we don't need a damned table
4281 here. If you just put the rows and columns in the right order,
4282 it'd look awfully regular. We could simply walk the bpstat list
4283 and choose the highest priority action we find, with a little
4284 logic to handle the 'err' cases. */
4286 /* step_resume entries: a step resume breakpoint overrides another
4287 breakpoint of signal handling (see comment in wait_for_inferior
4288 at where we set the step_resume breakpoint). */
4290 static const enum bpstat_what_main_action
4291 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4294 /* kc ss sn sgl slr clr sr shl jit */
4295 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4296 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4297 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4298 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4299 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4300 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4301 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4302 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4303 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4304 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4305 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4319 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4320 struct bpstat_what retval
;
4322 retval
.call_dummy
= STOP_NONE
;
4323 for (; bs
!= NULL
; bs
= bs
->next
)
4325 enum class bs_class
= no_effect
;
4326 if (bs
->breakpoint_at
== NULL
)
4327 /* I suspect this can happen if it was a momentary breakpoint
4328 which has since been deleted. */
4330 if (bs
->breakpoint_at
->owner
== NULL
)
4331 bs_class
= bp_nostop
;
4333 switch (bs
->breakpoint_at
->owner
->type
)
4339 case bp_hardware_breakpoint
:
4345 bs_class
= bp_noisy
;
4347 bs_class
= bp_silent
;
4350 bs_class
= bp_nostop
;
4353 case bp_hardware_watchpoint
:
4354 case bp_read_watchpoint
:
4355 case bp_access_watchpoint
:
4359 bs_class
= wp_noisy
;
4361 bs_class
= wp_silent
;
4364 /* There was a watchpoint, but we're not stopping.
4365 This requires no further action. */
4366 bs_class
= no_effect
;
4369 bs_class
= long_jump
;
4371 case bp_longjmp_resume
:
4372 bs_class
= long_resume
;
4374 case bp_step_resume
:
4377 bs_class
= step_resume
;
4380 /* It is for the wrong frame. */
4381 bs_class
= bp_nostop
;
4383 case bp_watchpoint_scope
:
4384 bs_class
= bp_nostop
;
4386 case bp_shlib_event
:
4387 bs_class
= shlib_event
;
4390 bs_class
= jit_event
;
4392 case bp_thread_event
:
4393 case bp_overlay_event
:
4394 case bp_longjmp_master
:
4395 case bp_std_terminate_master
:
4396 bs_class
= bp_nostop
;
4402 bs_class
= bp_noisy
;
4404 bs_class
= bp_silent
;
4407 /* There was a catchpoint, but we're not stopping.
4408 This requires no further action. */
4409 bs_class
= no_effect
;
4412 /* Make sure the action is stop (silent or noisy),
4413 so infrun.c pops the dummy frame. */
4414 bs_class
= bp_silent
;
4415 retval
.call_dummy
= STOP_STACK_DUMMY
;
4417 case bp_std_terminate
:
4418 /* Make sure the action is stop (silent or noisy),
4419 so infrun.c pops the dummy frame. */
4420 bs_class
= bp_silent
;
4421 retval
.call_dummy
= STOP_STD_TERMINATE
;
4424 case bp_fast_tracepoint
:
4425 /* Tracepoint hits should not be reported back to GDB, and
4426 if one got through somehow, it should have been filtered
4428 internal_error (__FILE__
, __LINE__
,
4429 _("bpstat_what: tracepoint encountered"));
4432 current_action
= table
[(int) bs_class
][(int) current_action
];
4434 retval
.main_action
= current_action
;
4438 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4439 without hardware support). This isn't related to a specific bpstat,
4440 just to things like whether watchpoints are set. */
4443 bpstat_should_step (void)
4445 struct breakpoint
*b
;
4447 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4453 bpstat_causes_stop (bpstat bs
)
4455 for (; bs
!= NULL
; bs
= bs
->next
)
4464 /* Print the LOC location out of the list of B->LOC locations. */
4466 static void print_breakpoint_location (struct breakpoint
*b
,
4467 struct bp_location
*loc
,
4469 struct ui_stream
*stb
)
4471 struct cleanup
*old_chain
= save_current_program_space ();
4473 if (loc
!= NULL
&& loc
->shlib_disabled
)
4477 set_current_program_space (loc
->pspace
);
4479 if (b
->source_file
&& loc
)
4482 = find_pc_sect_function (loc
->address
, loc
->section
);
4485 ui_out_text (uiout
, "in ");
4486 ui_out_field_string (uiout
, "func",
4487 SYMBOL_PRINT_NAME (sym
));
4488 ui_out_wrap_hint (uiout
, wrap_indent
);
4489 ui_out_text (uiout
, " at ");
4491 ui_out_field_string (uiout
, "file", b
->source_file
);
4492 ui_out_text (uiout
, ":");
4494 if (ui_out_is_mi_like_p (uiout
))
4496 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4497 char *fullname
= symtab_to_fullname (sal
.symtab
);
4500 ui_out_field_string (uiout
, "fullname", fullname
);
4503 ui_out_field_int (uiout
, "line", b
->line_number
);
4507 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4509 ui_out_field_stream (uiout
, "at", stb
);
4512 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4514 do_cleanups (old_chain
);
4517 /* Print B to gdb_stdout. */
4519 print_one_breakpoint_location (struct breakpoint
*b
,
4520 struct bp_location
*loc
,
4522 struct bp_location
**last_loc
,
4523 int print_address_bits
,
4526 struct command_line
*l
;
4528 struct ep_type_description
4533 static struct ep_type_description bptypes
[] =
4535 {bp_none
, "?deleted?"},
4536 {bp_breakpoint
, "breakpoint"},
4537 {bp_hardware_breakpoint
, "hw breakpoint"},
4538 {bp_until
, "until"},
4539 {bp_finish
, "finish"},
4540 {bp_watchpoint
, "watchpoint"},
4541 {bp_hardware_watchpoint
, "hw watchpoint"},
4542 {bp_read_watchpoint
, "read watchpoint"},
4543 {bp_access_watchpoint
, "acc watchpoint"},
4544 {bp_longjmp
, "longjmp"},
4545 {bp_longjmp_resume
, "longjmp resume"},
4546 {bp_step_resume
, "step resume"},
4547 {bp_watchpoint_scope
, "watchpoint scope"},
4548 {bp_call_dummy
, "call dummy"},
4549 {bp_std_terminate
, "std::terminate"},
4550 {bp_shlib_event
, "shlib events"},
4551 {bp_thread_event
, "thread events"},
4552 {bp_overlay_event
, "overlay events"},
4553 {bp_longjmp_master
, "longjmp master"},
4554 {bp_std_terminate_master
, "std::terminate master"},
4555 {bp_catchpoint
, "catchpoint"},
4556 {bp_tracepoint
, "tracepoint"},
4557 {bp_fast_tracepoint
, "fast tracepoint"},
4558 {bp_jit_event
, "jit events"},
4561 static char bpenables
[] = "nynny";
4562 char wrap_indent
[80];
4563 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4564 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4565 struct cleanup
*bkpt_chain
;
4567 int header_of_multiple
= 0;
4568 int part_of_multiple
= (loc
!= NULL
);
4569 struct value_print_options opts
;
4571 get_user_print_options (&opts
);
4573 gdb_assert (!loc
|| loc_number
!= 0);
4574 /* See comment in print_one_breakpoint concerning
4575 treatment of breakpoints with single disabled
4579 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4580 header_of_multiple
= 1;
4585 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4589 if (part_of_multiple
)
4592 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4593 ui_out_field_string (uiout
, "number", formatted
);
4598 ui_out_field_int (uiout
, "number", b
->number
);
4603 if (part_of_multiple
)
4604 ui_out_field_skip (uiout
, "type");
4607 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4608 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4609 internal_error (__FILE__
, __LINE__
,
4610 _("bptypes table does not describe type #%d."),
4612 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4617 if (part_of_multiple
)
4618 ui_out_field_skip (uiout
, "disp");
4620 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4625 if (part_of_multiple
)
4626 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4628 ui_out_field_fmt (uiout
, "enabled", "%c",
4629 bpenables
[(int) b
->enable_state
]);
4630 ui_out_spaces (uiout
, 2);
4634 strcpy (wrap_indent
, " ");
4635 if (opts
.addressprint
)
4637 if (print_address_bits
<= 32)
4638 strcat (wrap_indent
, " ");
4640 strcat (wrap_indent
, " ");
4643 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4645 /* Although the print_one can possibly print
4646 all locations, calling it here is not likely
4647 to get any nice result. So, make sure there's
4648 just one location. */
4649 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4650 b
->ops
->print_one (b
, last_loc
);
4656 internal_error (__FILE__
, __LINE__
,
4657 _("print_one_breakpoint: bp_none encountered\n"));
4661 case bp_hardware_watchpoint
:
4662 case bp_read_watchpoint
:
4663 case bp_access_watchpoint
:
4664 /* Field 4, the address, is omitted (which makes the columns
4665 not line up too nicely with the headers, but the effect
4666 is relatively readable). */
4667 if (opts
.addressprint
)
4668 ui_out_field_skip (uiout
, "addr");
4670 ui_out_field_string (uiout
, "what", b
->exp_string
);
4674 case bp_hardware_breakpoint
:
4678 case bp_longjmp_resume
:
4679 case bp_step_resume
:
4680 case bp_watchpoint_scope
:
4682 case bp_std_terminate
:
4683 case bp_shlib_event
:
4684 case bp_thread_event
:
4685 case bp_overlay_event
:
4686 case bp_longjmp_master
:
4687 case bp_std_terminate_master
:
4689 case bp_fast_tracepoint
:
4691 if (opts
.addressprint
)
4694 if (header_of_multiple
)
4695 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4696 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4697 ui_out_field_string (uiout
, "addr", "<PENDING>");
4699 ui_out_field_core_addr (uiout
, "addr",
4700 loc
->gdbarch
, loc
->address
);
4703 if (!header_of_multiple
)
4704 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4711 /* For backward compatibility, don't display inferiors unless there
4714 && !header_of_multiple
4716 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4717 && (number_of_program_spaces () > 1
4718 || number_of_inferiors () > 1)
4719 && loc
->owner
->type
!= bp_catchpoint
)))
4721 struct inferior
*inf
;
4724 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4726 if (inf
->pspace
== loc
->pspace
)
4731 ui_out_text (uiout
, " inf ");
4734 ui_out_text (uiout
, ", ");
4735 ui_out_text (uiout
, plongest (inf
->num
));
4740 if (!part_of_multiple
)
4742 if (b
->thread
!= -1)
4744 /* FIXME: This seems to be redundant and lost here; see the
4745 "stop only in" line a little further down. */
4746 ui_out_text (uiout
, " thread ");
4747 ui_out_field_int (uiout
, "thread", b
->thread
);
4749 else if (b
->task
!= 0)
4751 ui_out_text (uiout
, " task ");
4752 ui_out_field_int (uiout
, "task", b
->task
);
4756 ui_out_text (uiout
, "\n");
4758 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4761 ui_out_text (uiout
, "\tstop only in stack frame at ");
4762 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4764 ui_out_field_core_addr (uiout
, "frame",
4765 b
->gdbarch
, b
->frame_id
.stack_addr
);
4766 ui_out_text (uiout
, "\n");
4769 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4771 /* We do not print the condition for Ada exception catchpoints
4772 because the condition is an internal implementation detail
4773 that we do not want to expose to the user. */
4775 if (tracepoint_type (b
))
4776 ui_out_text (uiout
, "\ttrace only if ");
4778 ui_out_text (uiout
, "\tstop only if ");
4779 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4780 ui_out_text (uiout
, "\n");
4783 if (!part_of_multiple
&& b
->thread
!= -1)
4785 /* FIXME should make an annotation for this */
4786 ui_out_text (uiout
, "\tstop only in thread ");
4787 ui_out_field_int (uiout
, "thread", b
->thread
);
4788 ui_out_text (uiout
, "\n");
4791 if (!part_of_multiple
&& b
->hit_count
)
4793 /* FIXME should make an annotation for this */
4794 if (ep_is_catchpoint (b
))
4795 ui_out_text (uiout
, "\tcatchpoint");
4797 ui_out_text (uiout
, "\tbreakpoint");
4798 ui_out_text (uiout
, " already hit ");
4799 ui_out_field_int (uiout
, "times", b
->hit_count
);
4800 if (b
->hit_count
== 1)
4801 ui_out_text (uiout
, " time\n");
4803 ui_out_text (uiout
, " times\n");
4806 /* Output the count also if it is zero, but only if this is
4807 mi. FIXME: Should have a better test for this. */
4808 if (ui_out_is_mi_like_p (uiout
))
4809 if (!part_of_multiple
&& b
->hit_count
== 0)
4810 ui_out_field_int (uiout
, "times", b
->hit_count
);
4812 if (!part_of_multiple
&& b
->ignore_count
)
4815 ui_out_text (uiout
, "\tignore next ");
4816 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4817 ui_out_text (uiout
, " hits\n");
4820 l
= b
->commands
? b
->commands
->commands
: NULL
;
4821 if (!part_of_multiple
&& l
)
4823 struct cleanup
*script_chain
;
4826 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4827 print_command_lines (uiout
, l
, 4);
4828 do_cleanups (script_chain
);
4831 if (!part_of_multiple
&& b
->pass_count
)
4833 annotate_field (10);
4834 ui_out_text (uiout
, "\tpass count ");
4835 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4836 ui_out_text (uiout
, " \n");
4839 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4842 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4843 else if (b
->exp_string
)
4844 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4847 do_cleanups (bkpt_chain
);
4848 do_cleanups (old_chain
);
4852 print_one_breakpoint (struct breakpoint
*b
,
4853 struct bp_location
**last_loc
, int print_address_bits
,
4856 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4857 print_address_bits
, allflag
);
4859 /* If this breakpoint has custom print function,
4860 it's already printed. Otherwise, print individual
4861 locations, if any. */
4862 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4864 /* If breakpoint has a single location that is
4865 disabled, we print it as if it had
4866 several locations, since otherwise it's hard to
4867 represent "breakpoint enabled, location disabled"
4869 Note that while hardware watchpoints have
4870 several locations internally, that's no a property
4873 && !is_hardware_watchpoint (b
)
4874 && (b
->loc
->next
|| !b
->loc
->enabled
)
4875 && !ui_out_is_mi_like_p (uiout
))
4877 struct bp_location
*loc
;
4879 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4880 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4881 print_address_bits
, allflag
);
4887 breakpoint_address_bits (struct breakpoint
*b
)
4889 int print_address_bits
= 0;
4890 struct bp_location
*loc
;
4892 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4896 /* Software watchpoints that aren't watching memory don't have
4897 an address to print. */
4898 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4901 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4902 if (addr_bit
> print_address_bits
)
4903 print_address_bits
= addr_bit
;
4906 return print_address_bits
;
4909 struct captured_breakpoint_query_args
4915 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4917 struct captured_breakpoint_query_args
*args
= data
;
4918 struct breakpoint
*b
;
4919 struct bp_location
*dummy_loc
= NULL
;
4922 if (args
->bnum
== b
->number
)
4924 int print_address_bits
= breakpoint_address_bits (b
);
4925 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4933 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4935 struct captured_breakpoint_query_args args
;
4937 /* For the moment we don't trust print_one_breakpoint() to not throw
4939 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4940 error_message
, RETURN_MASK_ALL
) < 0)
4946 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4947 catchpoints, et.al.). */
4950 user_settable_breakpoint (const struct breakpoint
*b
)
4952 return (b
->type
== bp_breakpoint
4953 || b
->type
== bp_catchpoint
4954 || b
->type
== bp_hardware_breakpoint
4955 || tracepoint_type (b
)
4956 || b
->type
== bp_watchpoint
4957 || b
->type
== bp_read_watchpoint
4958 || b
->type
== bp_access_watchpoint
4959 || b
->type
== bp_hardware_watchpoint
);
4962 /* Print information on user settable breakpoint (watchpoint, etc)
4963 number BNUM. If BNUM is -1 print all user settable breakpoints.
4964 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4967 breakpoint_1 (int bnum
, int allflag
)
4969 struct breakpoint
*b
;
4970 struct bp_location
*last_loc
= NULL
;
4971 int nr_printable_breakpoints
;
4972 struct cleanup
*bkpttbl_chain
;
4973 struct value_print_options opts
;
4974 int print_address_bits
= 0;
4976 get_user_print_options (&opts
);
4978 /* Compute the number of rows in the table, as well as the
4979 size required for address fields. */
4980 nr_printable_breakpoints
= 0;
4983 || bnum
== b
->number
)
4985 if (allflag
|| user_settable_breakpoint (b
))
4987 int addr_bit
= breakpoint_address_bits (b
);
4988 if (addr_bit
> print_address_bits
)
4989 print_address_bits
= addr_bit
;
4991 nr_printable_breakpoints
++;
4995 if (opts
.addressprint
)
4997 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
5001 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
5004 if (nr_printable_breakpoints
> 0)
5005 annotate_breakpoints_headers ();
5006 if (nr_printable_breakpoints
> 0)
5008 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5009 if (nr_printable_breakpoints
> 0)
5011 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
5012 if (nr_printable_breakpoints
> 0)
5014 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5015 if (nr_printable_breakpoints
> 0)
5017 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5018 if (opts
.addressprint
)
5020 if (nr_printable_breakpoints
> 0)
5022 if (print_address_bits
<= 32)
5023 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
5025 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
5027 if (nr_printable_breakpoints
> 0)
5029 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5030 ui_out_table_body (uiout
);
5031 if (nr_printable_breakpoints
> 0)
5032 annotate_breakpoints_table ();
5038 || bnum
== b
->number
)
5040 /* We only print out user settable breakpoints unless the
5042 if (allflag
|| user_settable_breakpoint (b
))
5043 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5047 do_cleanups (bkpttbl_chain
);
5049 if (nr_printable_breakpoints
== 0)
5052 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5054 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5059 if (last_loc
&& !server_command
)
5060 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5063 /* FIXME? Should this be moved up so that it is only called when
5064 there have been breakpoints? */
5065 annotate_breakpoints_table_end ();
5069 breakpoints_info (char *bnum_exp
, int from_tty
)
5074 bnum
= parse_and_eval_long (bnum_exp
);
5076 breakpoint_1 (bnum
, 0);
5080 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5085 bnum
= parse_and_eval_long (bnum_exp
);
5087 breakpoint_1 (bnum
, 1);
5091 breakpoint_has_pc (struct breakpoint
*b
,
5092 struct program_space
*pspace
,
5093 CORE_ADDR pc
, struct obj_section
*section
)
5095 struct bp_location
*bl
= b
->loc
;
5096 for (; bl
; bl
= bl
->next
)
5098 if (bl
->pspace
== pspace
5099 && bl
->address
== pc
5100 && (!overlay_debugging
|| bl
->section
== section
))
5106 /* Print a message describing any breakpoints set at PC. This
5107 concerns with logical breakpoints, so we match program spaces, not
5111 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5112 struct program_space
*pspace
, CORE_ADDR pc
,
5113 struct obj_section
*section
, int thread
)
5116 struct breakpoint
*b
;
5119 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5123 printf_filtered (_("Note: breakpoint "));
5124 else /* if (others == ???) */
5125 printf_filtered (_("Note: breakpoints "));
5127 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5130 printf_filtered ("%d", b
->number
);
5131 if (b
->thread
== -1 && thread
!= -1)
5132 printf_filtered (" (all threads)");
5133 else if (b
->thread
!= -1)
5134 printf_filtered (" (thread %d)", b
->thread
);
5135 printf_filtered ("%s%s ",
5136 ((b
->enable_state
== bp_disabled
5137 || b
->enable_state
== bp_call_disabled
5138 || b
->enable_state
== bp_startup_disabled
)
5140 : b
->enable_state
== bp_permanent
5144 : ((others
== 1) ? " and" : ""));
5146 printf_filtered (_("also set at pc "));
5147 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5148 printf_filtered (".\n");
5152 /* Set the default place to put a breakpoint
5153 for the `break' command with no arguments. */
5156 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5157 CORE_ADDR addr
, struct symtab
*symtab
,
5160 default_breakpoint_valid
= valid
;
5161 default_breakpoint_pspace
= pspace
;
5162 default_breakpoint_address
= addr
;
5163 default_breakpoint_symtab
= symtab
;
5164 default_breakpoint_line
= line
;
5167 /* Return true iff it is meaningful to use the address member of
5168 BPT. For some breakpoint types, the address member is irrelevant
5169 and it makes no sense to attempt to compare it to other addresses
5170 (or use it for any other purpose either).
5172 More specifically, each of the following breakpoint types will always
5173 have a zero valued address and we don't want to mark breakpoints of any of
5174 these types to be a duplicate of an actual breakpoint at address zero:
5182 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5184 enum bptype type
= bpt
->type
;
5186 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5189 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5190 true if LOC1 and LOC2 represent the same watchpoint location. */
5193 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5195 /* Note that this checks the owner's type, not the location's. In
5196 case the target does not support read watchpoints, but does
5197 support access watchpoints, we'll have bp_read_watchpoint
5198 watchpoints with hw_access locations. Those should be considered
5199 duplicates of hw_read locations. The hw_read locations will
5200 become hw_access locations later. */
5201 return (loc1
->owner
->type
== loc2
->owner
->type
5202 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5203 && loc1
->address
== loc2
->address
5204 && loc1
->length
== loc2
->length
);
5207 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5208 same breakpoint location. In most targets, this can only be true
5209 if ASPACE1 matches ASPACE2. On targets that have global
5210 breakpoints, the address space doesn't really matter. */
5213 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5214 struct address_space
*aspace2
, CORE_ADDR addr2
)
5216 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5217 || aspace1
== aspace2
)
5221 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5222 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5223 represent the same location. */
5226 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5228 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5229 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5231 if (hw_point1
!= hw_point2
)
5234 return watchpoint_locations_match (loc1
, loc2
);
5236 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5237 loc2
->pspace
->aspace
, loc2
->address
);
5241 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5242 int bnum
, int have_bnum
)
5247 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5248 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5250 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5251 bnum
, astr1
, astr2
);
5253 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5256 /* Adjust a breakpoint's address to account for architectural constraints
5257 on breakpoint placement. Return the adjusted address. Note: Very
5258 few targets require this kind of adjustment. For most targets,
5259 this function is simply the identity function. */
5262 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5263 CORE_ADDR bpaddr
, enum bptype bptype
)
5265 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5267 /* Very few targets need any kind of breakpoint adjustment. */
5270 else if (bptype
== bp_watchpoint
5271 || bptype
== bp_hardware_watchpoint
5272 || bptype
== bp_read_watchpoint
5273 || bptype
== bp_access_watchpoint
5274 || bptype
== bp_catchpoint
)
5276 /* Watchpoints and the various bp_catch_* eventpoints should not
5277 have their addresses modified. */
5282 CORE_ADDR adjusted_bpaddr
;
5284 /* Some targets have architectural constraints on the placement
5285 of breakpoint instructions. Obtain the adjusted address. */
5286 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5288 /* An adjusted breakpoint address can significantly alter
5289 a user's expectations. Print a warning if an adjustment
5291 if (adjusted_bpaddr
!= bpaddr
)
5292 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5294 return adjusted_bpaddr
;
5298 /* Allocate a struct bp_location. */
5300 static struct bp_location
*
5301 allocate_bp_location (struct breakpoint
*bpt
)
5303 struct bp_location
*loc
, *loc_p
;
5305 loc
= xmalloc (sizeof (struct bp_location
));
5306 memset (loc
, 0, sizeof (*loc
));
5310 loc
->shlib_disabled
= 0;
5319 case bp_longjmp_resume
:
5320 case bp_step_resume
:
5321 case bp_watchpoint_scope
:
5323 case bp_std_terminate
:
5324 case bp_shlib_event
:
5325 case bp_thread_event
:
5326 case bp_overlay_event
:
5328 case bp_longjmp_master
:
5329 case bp_std_terminate_master
:
5330 loc
->loc_type
= bp_loc_software_breakpoint
;
5332 case bp_hardware_breakpoint
:
5333 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5335 case bp_hardware_watchpoint
:
5336 case bp_read_watchpoint
:
5337 case bp_access_watchpoint
:
5338 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5343 case bp_fast_tracepoint
:
5344 loc
->loc_type
= bp_loc_other
;
5347 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5353 static void free_bp_location (struct bp_location
*loc
)
5358 if (loc
->function_name
)
5359 xfree (loc
->function_name
);
5364 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5365 that has type BPTYPE and has no locations as yet. */
5366 /* This function is used in gdbtk sources and thus can not be made static. */
5368 static struct breakpoint
*
5369 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5372 struct breakpoint
*b
, *b1
;
5374 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5375 memset (b
, 0, sizeof (*b
));
5378 b
->gdbarch
= gdbarch
;
5379 b
->language
= current_language
->la_language
;
5380 b
->input_radix
= input_radix
;
5382 b
->enable_state
= bp_enabled
;
5385 b
->ignore_count
= 0;
5387 b
->frame_id
= null_frame_id
;
5388 b
->forked_inferior_pid
= null_ptid
;
5389 b
->exec_pathname
= NULL
;
5390 b
->syscalls_to_be_caught
= NULL
;
5392 b
->condition_not_parsed
= 0;
5394 /* Add this breakpoint to the end of the chain
5395 so that a list of breakpoints will come out in order
5396 of increasing numbers. */
5398 b1
= breakpoint_chain
;
5400 breakpoint_chain
= b
;
5410 /* Initialize loc->function_name. */
5412 set_breakpoint_location_function (struct bp_location
*loc
)
5414 if (loc
->owner
->type
== bp_breakpoint
5415 || loc
->owner
->type
== bp_hardware_breakpoint
5416 || tracepoint_type (loc
->owner
))
5418 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5420 if (loc
->function_name
)
5421 loc
->function_name
= xstrdup (loc
->function_name
);
5425 /* Attempt to determine architecture of location identified by SAL. */
5426 static struct gdbarch
*
5427 get_sal_arch (struct symtab_and_line sal
)
5430 return get_objfile_arch (sal
.section
->objfile
);
5432 return get_objfile_arch (sal
.symtab
->objfile
);
5437 /* set_raw_breakpoint is a low level routine for allocating and
5438 partially initializing a breakpoint of type BPTYPE. The newly
5439 created breakpoint's address, section, source file name, and line
5440 number are provided by SAL. The newly created and partially
5441 initialized breakpoint is added to the breakpoint chain and
5442 is also returned as the value of this function.
5444 It is expected that the caller will complete the initialization of
5445 the newly created breakpoint struct as well as output any status
5446 information regarding the creation of a new breakpoint. In
5447 particular, set_raw_breakpoint does NOT set the breakpoint
5448 number! Care should be taken to not allow an error to occur
5449 prior to completing the initialization of the breakpoint. If this
5450 should happen, a bogus breakpoint will be left on the chain. */
5453 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5454 struct symtab_and_line sal
, enum bptype bptype
)
5456 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5457 CORE_ADDR adjusted_address
;
5458 struct gdbarch
*loc_gdbarch
;
5460 loc_gdbarch
= get_sal_arch (sal
);
5462 loc_gdbarch
= b
->gdbarch
;
5464 if (bptype
!= bp_catchpoint
)
5465 gdb_assert (sal
.pspace
!= NULL
);
5467 /* Adjust the breakpoint's address prior to allocating a location.
5468 Once we call allocate_bp_location(), that mostly uninitialized
5469 location will be placed on the location chain. Adjustment of the
5470 breakpoint may cause target_read_memory() to be called and we do
5471 not want its scan of the location chain to find a breakpoint and
5472 location that's only been partially initialized. */
5473 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5475 b
->loc
= allocate_bp_location (b
);
5476 b
->loc
->gdbarch
= loc_gdbarch
;
5477 b
->loc
->requested_address
= sal
.pc
;
5478 b
->loc
->address
= adjusted_address
;
5479 b
->loc
->pspace
= sal
.pspace
;
5481 /* Store the program space that was used to set the breakpoint, for
5482 breakpoint resetting. */
5483 b
->pspace
= sal
.pspace
;
5485 if (sal
.symtab
== NULL
)
5486 b
->source_file
= NULL
;
5488 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5489 b
->loc
->section
= sal
.section
;
5490 b
->line_number
= sal
.line
;
5492 set_breakpoint_location_function (b
->loc
);
5494 breakpoints_changed ();
5500 /* Note that the breakpoint object B describes a permanent breakpoint
5501 instruction, hard-wired into the inferior's code. */
5503 make_breakpoint_permanent (struct breakpoint
*b
)
5505 struct bp_location
*bl
;
5506 b
->enable_state
= bp_permanent
;
5508 /* By definition, permanent breakpoints are already present in the code.
5509 Mark all locations as inserted. For now, make_breakpoint_permanent
5510 is called in just one place, so it's hard to say if it's reasonable
5511 to have permanent breakpoint with multiple locations or not,
5512 but it's easy to implmement. */
5513 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5517 /* Call this routine when stepping and nexting to enable a breakpoint
5518 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5519 set_longjmp_resume_breakpoint() to figure out where we are going. */
5522 set_longjmp_breakpoint (int thread
)
5524 struct breakpoint
*b
, *temp
;
5526 /* To avoid having to rescan all objfile symbols at every step,
5527 we maintain a list of continually-inserted but always disabled
5528 longjmp "master" breakpoints. Here, we simply create momentary
5529 clones of those and enable them for the requested thread. */
5530 ALL_BREAKPOINTS_SAFE (b
, temp
)
5531 if (b
->pspace
== current_program_space
5532 && b
->type
== bp_longjmp_master
)
5534 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5535 clone
->type
= bp_longjmp
;
5536 clone
->thread
= thread
;
5540 /* Delete all longjmp breakpoints from THREAD. */
5542 delete_longjmp_breakpoint (int thread
)
5544 struct breakpoint
*b
, *temp
;
5546 ALL_BREAKPOINTS_SAFE (b
, temp
)
5547 if (b
->type
== bp_longjmp
)
5549 if (b
->thread
== thread
)
5550 delete_breakpoint (b
);
5555 enable_overlay_breakpoints (void)
5557 struct breakpoint
*b
;
5560 if (b
->type
== bp_overlay_event
)
5562 b
->enable_state
= bp_enabled
;
5563 update_global_location_list (1);
5564 overlay_events_enabled
= 1;
5569 disable_overlay_breakpoints (void)
5571 struct breakpoint
*b
;
5574 if (b
->type
== bp_overlay_event
)
5576 b
->enable_state
= bp_disabled
;
5577 update_global_location_list (0);
5578 overlay_events_enabled
= 0;
5582 /* Set an active std::terminate breakpoint for each std::terminate
5583 master breakpoint. */
5585 set_std_terminate_breakpoint (void)
5587 struct breakpoint
*b
, *temp
;
5589 ALL_BREAKPOINTS_SAFE (b
, temp
)
5590 if (b
->pspace
== current_program_space
5591 && b
->type
== bp_std_terminate_master
)
5593 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5594 clone
->type
= bp_std_terminate
;
5598 /* Delete all the std::terminate breakpoints. */
5600 delete_std_terminate_breakpoint (void)
5602 struct breakpoint
*b
, *temp
;
5604 ALL_BREAKPOINTS_SAFE (b
, temp
)
5605 if (b
->type
== bp_std_terminate
)
5606 delete_breakpoint (b
);
5610 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5612 struct breakpoint
*b
;
5614 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5616 b
->enable_state
= bp_enabled
;
5617 /* addr_string has to be used or breakpoint_re_set will delete me. */
5619 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5621 update_global_location_list_nothrow (1);
5627 remove_thread_event_breakpoints (void)
5629 struct breakpoint
*b
, *temp
;
5631 ALL_BREAKPOINTS_SAFE (b
, temp
)
5632 if (b
->type
== bp_thread_event
5633 && b
->loc
->pspace
== current_program_space
)
5634 delete_breakpoint (b
);
5637 struct captured_parse_breakpoint_args
5640 struct symtabs_and_lines
*sals_p
;
5641 char ***addr_string_p
;
5645 struct lang_and_radix
5651 /* Create a breakpoint for JIT code registration and unregistration. */
5654 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5656 struct breakpoint
*b
;
5658 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5659 update_global_location_list_nothrow (1);
5664 remove_solib_event_breakpoints (void)
5666 struct breakpoint
*b
, *temp
;
5668 ALL_BREAKPOINTS_SAFE (b
, temp
)
5669 if (b
->type
== bp_shlib_event
5670 && b
->loc
->pspace
== current_program_space
)
5671 delete_breakpoint (b
);
5675 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5677 struct breakpoint
*b
;
5679 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5680 update_global_location_list_nothrow (1);
5684 /* Disable any breakpoints that are on code in shared libraries. Only
5685 apply to enabled breakpoints, disabled ones can just stay disabled. */
5688 disable_breakpoints_in_shlibs (void)
5690 struct bp_location
*loc
, **locp_tmp
;
5692 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5694 struct breakpoint
*b
= loc
->owner
;
5695 /* We apply the check to all breakpoints, including disabled
5696 for those with loc->duplicate set. This is so that when breakpoint
5697 becomes enabled, or the duplicate is removed, gdb will try to insert
5698 all breakpoints. If we don't set shlib_disabled here, we'll try
5699 to insert those breakpoints and fail. */
5700 if (((b
->type
== bp_breakpoint
)
5701 || (b
->type
== bp_jit_event
)
5702 || (b
->type
== bp_hardware_breakpoint
)
5703 || (tracepoint_type (b
)))
5704 && loc
->pspace
== current_program_space
5705 && !loc
->shlib_disabled
5707 && PC_SOLIB (loc
->address
)
5709 && solib_name_from_address (loc
->pspace
, loc
->address
)
5713 loc
->shlib_disabled
= 1;
5718 /* Disable any breakpoints that are in in an unloaded shared library. Only
5719 apply to enabled breakpoints, disabled ones can just stay disabled. */
5722 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5724 struct bp_location
*loc
, **locp_tmp
;
5725 int disabled_shlib_breaks
= 0;
5727 /* SunOS a.out shared libraries are always mapped, so do not
5728 disable breakpoints; they will only be reported as unloaded
5729 through clear_solib when GDB discards its shared library
5730 list. See clear_solib for more information. */
5731 if (exec_bfd
!= NULL
5732 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5735 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5737 struct breakpoint
*b
= loc
->owner
;
5738 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5739 || loc
->loc_type
== bp_loc_software_breakpoint
)
5740 && solib
->pspace
== loc
->pspace
5741 && !loc
->shlib_disabled
5742 && (b
->type
== bp_breakpoint
5743 || b
->type
== bp_jit_event
5744 || b
->type
== bp_hardware_breakpoint
)
5745 && solib_contains_address_p (solib
, loc
->address
))
5747 loc
->shlib_disabled
= 1;
5748 /* At this point, we cannot rely on remove_breakpoint
5749 succeeding so we must mark the breakpoint as not inserted
5750 to prevent future errors occurring in remove_breakpoints. */
5752 if (!disabled_shlib_breaks
)
5754 target_terminal_ours_for_output ();
5755 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5758 disabled_shlib_breaks
= 1;
5763 /* FORK & VFORK catchpoints. */
5765 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5768 insert_catch_fork (struct breakpoint
*b
)
5770 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5773 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5776 remove_catch_fork (struct breakpoint
*b
)
5778 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5781 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5785 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5787 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5790 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5792 static enum print_stop_action
5793 print_it_catch_fork (struct breakpoint
*b
)
5795 annotate_catchpoint (b
->number
);
5796 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5797 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5798 return PRINT_SRC_AND_LOC
;
5801 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5804 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5806 struct value_print_options opts
;
5808 get_user_print_options (&opts
);
5810 /* Field 4, the address, is omitted (which makes the columns
5811 not line up too nicely with the headers, but the effect
5812 is relatively readable). */
5813 if (opts
.addressprint
)
5814 ui_out_field_skip (uiout
, "addr");
5816 ui_out_text (uiout
, "fork");
5817 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5819 ui_out_text (uiout
, ", process ");
5820 ui_out_field_int (uiout
, "what",
5821 ptid_get_pid (b
->forked_inferior_pid
));
5822 ui_out_spaces (uiout
, 1);
5826 /* Implement the "print_mention" breakpoint_ops method for fork
5830 print_mention_catch_fork (struct breakpoint
*b
)
5832 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5835 /* The breakpoint_ops structure to be used in fork catchpoints. */
5837 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5841 breakpoint_hit_catch_fork
,
5842 print_it_catch_fork
,
5843 print_one_catch_fork
,
5844 print_mention_catch_fork
5847 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5850 insert_catch_vfork (struct breakpoint
*b
)
5852 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5855 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5858 remove_catch_vfork (struct breakpoint
*b
)
5860 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5863 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5867 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5869 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5872 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5874 static enum print_stop_action
5875 print_it_catch_vfork (struct breakpoint
*b
)
5877 annotate_catchpoint (b
->number
);
5878 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5879 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5880 return PRINT_SRC_AND_LOC
;
5883 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5886 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5888 struct value_print_options opts
;
5890 get_user_print_options (&opts
);
5891 /* Field 4, the address, is omitted (which makes the columns
5892 not line up too nicely with the headers, but the effect
5893 is relatively readable). */
5894 if (opts
.addressprint
)
5895 ui_out_field_skip (uiout
, "addr");
5897 ui_out_text (uiout
, "vfork");
5898 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5900 ui_out_text (uiout
, ", process ");
5901 ui_out_field_int (uiout
, "what",
5902 ptid_get_pid (b
->forked_inferior_pid
));
5903 ui_out_spaces (uiout
, 1);
5907 /* Implement the "print_mention" breakpoint_ops method for vfork
5911 print_mention_catch_vfork (struct breakpoint
*b
)
5913 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5916 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5918 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5922 breakpoint_hit_catch_vfork
,
5923 print_it_catch_vfork
,
5924 print_one_catch_vfork
,
5925 print_mention_catch_vfork
5928 /* Implement the "insert" breakpoint_ops method for syscall
5932 insert_catch_syscall (struct breakpoint
*b
)
5934 struct inferior
*inf
= current_inferior ();
5936 ++inf
->total_syscalls_count
;
5937 if (!b
->syscalls_to_be_caught
)
5938 ++inf
->any_syscall_count
;
5943 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5947 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5949 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5950 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5952 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5953 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5955 memset ((void *) vec_addr
, 0,
5956 (iter
+ 1 - old_size
) * sizeof (int));
5958 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5959 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5963 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5964 inf
->total_syscalls_count
!= 0,
5965 inf
->any_syscall_count
,
5966 VEC_length (int, inf
->syscalls_counts
),
5967 VEC_address (int, inf
->syscalls_counts
));
5970 /* Implement the "remove" breakpoint_ops method for syscall
5974 remove_catch_syscall (struct breakpoint
*b
)
5976 struct inferior
*inf
= current_inferior ();
5978 --inf
->total_syscalls_count
;
5979 if (!b
->syscalls_to_be_caught
)
5980 --inf
->any_syscall_count
;
5985 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5989 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5990 /* Shouldn't happen. */
5992 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5993 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5997 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5998 inf
->total_syscalls_count
!= 0,
5999 inf
->any_syscall_count
,
6000 VEC_length (int, inf
->syscalls_counts
),
6001 VEC_address (int, inf
->syscalls_counts
));
6004 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6008 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6010 /* We must check if we are catching specific syscalls in this breakpoint.
6011 If we are, then we must guarantee that the called syscall is the same
6012 syscall we are catching. */
6013 int syscall_number
= 0;
6015 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6018 /* Now, checking if the syscall is the same. */
6019 if (b
->syscalls_to_be_caught
)
6023 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6025 if (syscall_number
== iter
)
6035 /* Implement the "print_it" breakpoint_ops method for syscall
6038 static enum print_stop_action
6039 print_it_catch_syscall (struct breakpoint
*b
)
6041 /* These are needed because we want to know in which state a
6042 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6043 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6044 must print "called syscall" or "returned from syscall". */
6046 struct target_waitstatus last
;
6048 struct cleanup
*old_chain
;
6051 get_last_target_status (&ptid
, &last
);
6053 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6055 annotate_catchpoint (b
->number
);
6058 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6060 syscall_id
= xstrprintf ("'%s'", s
.name
);
6062 old_chain
= make_cleanup (xfree
, syscall_id
);
6064 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6065 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6066 b
->number
, syscall_id
);
6067 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6068 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6069 b
->number
, syscall_id
);
6071 do_cleanups (old_chain
);
6073 return PRINT_SRC_AND_LOC
;
6076 /* Implement the "print_one" breakpoint_ops method for syscall
6080 print_one_catch_syscall (struct breakpoint
*b
,
6081 struct bp_location
**last_loc
)
6083 struct value_print_options opts
;
6085 get_user_print_options (&opts
);
6086 /* Field 4, the address, is omitted (which makes the columns
6087 not line up too nicely with the headers, but the effect
6088 is relatively readable). */
6089 if (opts
.addressprint
)
6090 ui_out_field_skip (uiout
, "addr");
6093 if (b
->syscalls_to_be_caught
6094 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6095 ui_out_text (uiout
, "syscalls \"");
6097 ui_out_text (uiout
, "syscall \"");
6099 if (b
->syscalls_to_be_caught
)
6102 char *text
= xstrprintf ("%s", "");
6104 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6109 get_syscall_by_number (iter
, &s
);
6112 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6114 text
= xstrprintf ("%s%d, ", text
, iter
);
6116 /* We have to xfree the last 'text' (now stored at 'x')
6117 because xstrprintf dinamically allocates new space for it
6121 /* Remove the last comma. */
6122 text
[strlen (text
) - 2] = '\0';
6123 ui_out_field_string (uiout
, "what", text
);
6126 ui_out_field_string (uiout
, "what", "<any syscall>");
6127 ui_out_text (uiout
, "\" ");
6130 /* Implement the "print_mention" breakpoint_ops method for syscall
6134 print_mention_catch_syscall (struct breakpoint
*b
)
6136 if (b
->syscalls_to_be_caught
)
6140 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6141 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6143 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6146 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6150 get_syscall_by_number (iter
, &s
);
6153 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6155 printf_filtered (" %d", s
.number
);
6157 printf_filtered (")");
6160 printf_filtered (_("Catchpoint %d (any syscall)"),
6164 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6166 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6168 insert_catch_syscall
,
6169 remove_catch_syscall
,
6170 breakpoint_hit_catch_syscall
,
6171 print_it_catch_syscall
,
6172 print_one_catch_syscall
,
6173 print_mention_catch_syscall
6176 /* Returns non-zero if 'b' is a syscall catchpoint. */
6179 syscall_catchpoint_p (struct breakpoint
*b
)
6181 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6184 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6185 but does NOT mention it nor update the global location list.
6186 This is useful if you need to fill more fields in the
6187 struct breakpoint before calling mention.
6189 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6190 If COND_STRING is not NULL, then store it in the breakpoint.
6191 OPS, if not NULL, is the breakpoint_ops structure associated
6192 to the catchpoint. */
6194 static struct breakpoint
*
6195 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6197 struct breakpoint_ops
*ops
)
6199 struct symtab_and_line sal
;
6200 struct breakpoint
*b
;
6203 sal
.pspace
= current_program_space
;
6205 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6206 set_breakpoint_count (breakpoint_count
+ 1);
6207 b
->number
= breakpoint_count
;
6209 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6211 b
->addr_string
= NULL
;
6212 b
->enable_state
= bp_enabled
;
6213 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6219 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6221 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6222 If COND_STRING is not NULL, then store it in the breakpoint.
6223 OPS, if not NULL, is the breakpoint_ops structure associated
6224 to the catchpoint. */
6226 static struct breakpoint
*
6227 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6228 char *cond_string
, struct breakpoint_ops
*ops
)
6230 struct breakpoint
*b
=
6231 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6234 update_global_location_list (1);
6240 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6241 int tempflag
, char *cond_string
,
6242 struct breakpoint_ops
*ops
)
6244 struct breakpoint
*b
6245 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6247 /* FIXME: We should put this information in a breakpoint private data
6249 b
->forked_inferior_pid
= null_ptid
;
6252 /* Exec catchpoints. */
6255 insert_catch_exec (struct breakpoint
*b
)
6257 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6261 remove_catch_exec (struct breakpoint
*b
)
6263 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6267 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6269 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6272 static enum print_stop_action
6273 print_it_catch_exec (struct breakpoint
*b
)
6275 annotate_catchpoint (b
->number
);
6276 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6278 return PRINT_SRC_AND_LOC
;
6282 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6284 struct value_print_options opts
;
6286 get_user_print_options (&opts
);
6288 /* Field 4, the address, is omitted (which makes the columns
6289 not line up too nicely with the headers, but the effect
6290 is relatively readable). */
6291 if (opts
.addressprint
)
6292 ui_out_field_skip (uiout
, "addr");
6294 ui_out_text (uiout
, "exec");
6295 if (b
->exec_pathname
!= NULL
)
6297 ui_out_text (uiout
, ", program \"");
6298 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6299 ui_out_text (uiout
, "\" ");
6304 print_mention_catch_exec (struct breakpoint
*b
)
6306 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6309 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6313 breakpoint_hit_catch_exec
,
6314 print_it_catch_exec
,
6315 print_one_catch_exec
,
6316 print_mention_catch_exec
6320 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6321 struct breakpoint_ops
*ops
)
6323 struct gdbarch
*gdbarch
= get_current_arch ();
6324 struct breakpoint
*b
=
6325 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6327 b
->syscalls_to_be_caught
= filter
;
6329 /* Now, we have to mention the breakpoint and update the global
6332 update_global_location_list (1);
6336 hw_breakpoint_used_count (void)
6338 struct breakpoint
*b
;
6343 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6351 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6353 struct breakpoint
*b
;
6356 *other_type_used
= 0;
6359 if (breakpoint_enabled (b
))
6361 if (b
->type
== type
)
6363 else if ((b
->type
== bp_hardware_watchpoint
6364 || b
->type
== bp_read_watchpoint
6365 || b
->type
== bp_access_watchpoint
))
6366 *other_type_used
= 1;
6373 disable_watchpoints_before_interactive_call_start (void)
6375 struct breakpoint
*b
;
6379 if (((b
->type
== bp_watchpoint
)
6380 || (b
->type
== bp_hardware_watchpoint
)
6381 || (b
->type
== bp_read_watchpoint
)
6382 || (b
->type
== bp_access_watchpoint
))
6383 && breakpoint_enabled (b
))
6385 b
->enable_state
= bp_call_disabled
;
6386 update_global_location_list (0);
6392 enable_watchpoints_after_interactive_call_stop (void)
6394 struct breakpoint
*b
;
6398 if (((b
->type
== bp_watchpoint
)
6399 || (b
->type
== bp_hardware_watchpoint
)
6400 || (b
->type
== bp_read_watchpoint
)
6401 || (b
->type
== bp_access_watchpoint
))
6402 && (b
->enable_state
== bp_call_disabled
))
6404 b
->enable_state
= bp_enabled
;
6405 update_global_location_list (1);
6411 disable_breakpoints_before_startup (void)
6413 struct breakpoint
*b
;
6418 if (b
->pspace
!= current_program_space
)
6421 if ((b
->type
== bp_breakpoint
6422 || b
->type
== bp_hardware_breakpoint
)
6423 && breakpoint_enabled (b
))
6425 b
->enable_state
= bp_startup_disabled
;
6431 update_global_location_list (0);
6433 current_program_space
->executing_startup
= 1;
6437 enable_breakpoints_after_startup (void)
6439 struct breakpoint
*b
;
6442 current_program_space
->executing_startup
= 0;
6446 if (b
->pspace
!= current_program_space
)
6449 if ((b
->type
== bp_breakpoint
6450 || b
->type
== bp_hardware_breakpoint
)
6451 && b
->enable_state
== bp_startup_disabled
)
6453 b
->enable_state
= bp_enabled
;
6459 breakpoint_re_set ();
6463 /* Set a breakpoint that will evaporate an end of command
6464 at address specified by SAL.
6465 Restrict it to frame FRAME if FRAME is nonzero. */
6468 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6469 struct frame_id frame_id
, enum bptype type
)
6471 struct breakpoint
*b
;
6473 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6475 gdb_assert (!frame_id_inlined_p (frame_id
));
6477 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6478 b
->enable_state
= bp_enabled
;
6479 b
->disposition
= disp_donttouch
;
6480 b
->frame_id
= frame_id
;
6482 /* If we're debugging a multi-threaded program, then we
6483 want momentary breakpoints to be active in only a
6484 single thread of control. */
6485 if (in_thread_list (inferior_ptid
))
6486 b
->thread
= pid_to_thread_id (inferior_ptid
);
6488 update_global_location_list_nothrow (1);
6493 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6497 clone_momentary_breakpoint (struct breakpoint
*orig
)
6499 struct breakpoint
*copy
;
6501 /* If there's nothing to clone, then return nothing. */
6505 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6506 copy
->loc
= allocate_bp_location (copy
);
6507 set_breakpoint_location_function (copy
->loc
);
6509 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6510 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6511 copy
->loc
->address
= orig
->loc
->address
;
6512 copy
->loc
->section
= orig
->loc
->section
;
6513 copy
->loc
->pspace
= orig
->loc
->pspace
;
6515 if (orig
->source_file
== NULL
)
6516 copy
->source_file
= NULL
;
6518 copy
->source_file
= xstrdup (orig
->source_file
);
6520 copy
->line_number
= orig
->line_number
;
6521 copy
->frame_id
= orig
->frame_id
;
6522 copy
->thread
= orig
->thread
;
6523 copy
->pspace
= orig
->pspace
;
6525 copy
->enable_state
= bp_enabled
;
6526 copy
->disposition
= disp_donttouch
;
6527 copy
->number
= internal_breakpoint_number
--;
6529 update_global_location_list_nothrow (0);
6534 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6537 struct symtab_and_line sal
;
6539 sal
= find_pc_line (pc
, 0);
6541 sal
.section
= find_pc_overlay (pc
);
6542 sal
.explicit_pc
= 1;
6544 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6548 /* Tell the user we have just set a breakpoint B. */
6551 mention (struct breakpoint
*b
)
6554 struct cleanup
*ui_out_chain
;
6555 struct value_print_options opts
;
6557 get_user_print_options (&opts
);
6559 /* FIXME: This is misplaced; mention() is called by things (like
6560 hitting a watchpoint) other than breakpoint creation. It should
6561 be possible to clean this up and at the same time replace the
6562 random calls to breakpoint_changed with this hook. */
6563 observer_notify_breakpoint_created (b
->number
);
6565 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6566 b
->ops
->print_mention (b
);
6571 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6574 ui_out_text (uiout
, "Watchpoint ");
6575 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6576 ui_out_field_int (uiout
, "number", b
->number
);
6577 ui_out_text (uiout
, ": ");
6578 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6579 do_cleanups (ui_out_chain
);
6581 case bp_hardware_watchpoint
:
6582 ui_out_text (uiout
, "Hardware watchpoint ");
6583 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6584 ui_out_field_int (uiout
, "number", b
->number
);
6585 ui_out_text (uiout
, ": ");
6586 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6587 do_cleanups (ui_out_chain
);
6589 case bp_read_watchpoint
:
6590 ui_out_text (uiout
, "Hardware read watchpoint ");
6591 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6592 ui_out_field_int (uiout
, "number", b
->number
);
6593 ui_out_text (uiout
, ": ");
6594 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6595 do_cleanups (ui_out_chain
);
6597 case bp_access_watchpoint
:
6598 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6599 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6600 ui_out_field_int (uiout
, "number", b
->number
);
6601 ui_out_text (uiout
, ": ");
6602 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6603 do_cleanups (ui_out_chain
);
6606 if (ui_out_is_mi_like_p (uiout
))
6611 if (b
->disposition
== disp_del
)
6612 printf_filtered (_("Temporary breakpoint"));
6614 printf_filtered (_("Breakpoint"));
6615 printf_filtered (_(" %d"), b
->number
);
6618 case bp_hardware_breakpoint
:
6619 if (ui_out_is_mi_like_p (uiout
))
6624 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6628 if (ui_out_is_mi_like_p (uiout
))
6633 printf_filtered (_("Tracepoint"));
6634 printf_filtered (_(" %d"), b
->number
);
6637 case bp_fast_tracepoint
:
6638 if (ui_out_is_mi_like_p (uiout
))
6643 printf_filtered (_("Fast tracepoint"));
6644 printf_filtered (_(" %d"), b
->number
);
6651 case bp_longjmp_resume
:
6652 case bp_step_resume
:
6654 case bp_std_terminate
:
6655 case bp_watchpoint_scope
:
6656 case bp_shlib_event
:
6657 case bp_thread_event
:
6658 case bp_overlay_event
:
6660 case bp_longjmp_master
:
6661 case bp_std_terminate_master
:
6667 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6671 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6675 if (opts
.addressprint
|| b
->source_file
== NULL
)
6677 printf_filtered (" at ");
6678 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6682 printf_filtered (": file %s, line %d.",
6683 b
->source_file
, b
->line_number
);
6687 struct bp_location
*loc
= b
->loc
;
6689 for (; loc
; loc
= loc
->next
)
6691 printf_filtered (" (%d locations)", n
);
6696 if (ui_out_is_mi_like_p (uiout
))
6698 printf_filtered ("\n");
6702 static struct bp_location
*
6703 add_location_to_breakpoint (struct breakpoint
*b
,
6704 const struct symtab_and_line
*sal
)
6706 struct bp_location
*loc
, **tmp
;
6708 loc
= allocate_bp_location (b
);
6709 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6712 loc
->gdbarch
= get_sal_arch (*sal
);
6714 loc
->gdbarch
= b
->gdbarch
;
6715 loc
->requested_address
= sal
->pc
;
6716 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6717 loc
->requested_address
, b
->type
);
6718 loc
->pspace
= sal
->pspace
;
6719 gdb_assert (loc
->pspace
!= NULL
);
6720 loc
->section
= sal
->section
;
6722 set_breakpoint_location_function (loc
);
6727 /* Return 1 if LOC is pointing to a permanent breakpoint,
6728 return 0 otherwise. */
6731 bp_loc_is_permanent (struct bp_location
*loc
)
6735 const gdb_byte
*brk
;
6736 gdb_byte
*target_mem
;
6737 struct cleanup
*cleanup
;
6740 gdb_assert (loc
!= NULL
);
6742 addr
= loc
->address
;
6743 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6745 /* Software breakpoints unsupported? */
6749 target_mem
= alloca (len
);
6751 /* Enable the automatic memory restoration from breakpoints while
6752 we read the memory. Otherwise we could say about our temporary
6753 breakpoints they are permanent. */
6754 cleanup
= save_current_space_and_thread ();
6756 switch_to_program_space_and_thread (loc
->pspace
);
6757 make_show_memory_breakpoints_cleanup (0);
6759 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6760 && memcmp (target_mem
, brk
, len
) == 0)
6763 do_cleanups (cleanup
);
6770 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6771 as textual description of the location, and COND_STRING
6772 as condition expression. */
6775 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6776 struct symtabs_and_lines sals
, char *addr_string
,
6778 enum bptype type
, enum bpdisp disposition
,
6779 int thread
, int task
, int ignore_count
,
6780 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6782 struct breakpoint
*b
= NULL
;
6785 if (type
== bp_hardware_breakpoint
)
6787 int i
= hw_breakpoint_used_count ();
6788 int target_resources_ok
=
6789 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6791 if (target_resources_ok
== 0)
6792 error (_("No hardware breakpoint support in the target."));
6793 else if (target_resources_ok
< 0)
6794 error (_("Hardware breakpoints used exceeds limit."));
6797 gdb_assert (sals
.nelts
> 0);
6799 for (i
= 0; i
< sals
.nelts
; ++i
)
6801 struct symtab_and_line sal
= sals
.sals
[i
];
6802 struct bp_location
*loc
;
6806 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6808 loc_gdbarch
= gdbarch
;
6810 describe_other_breakpoints (loc_gdbarch
,
6811 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6816 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6817 set_breakpoint_count (breakpoint_count
+ 1);
6818 b
->number
= breakpoint_count
;
6822 b
->cond_string
= cond_string
;
6823 b
->ignore_count
= ignore_count
;
6824 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6825 b
->disposition
= disposition
;
6827 b
->pspace
= sals
.sals
[0].pspace
;
6829 if (enabled
&& b
->pspace
->executing_startup
6830 && (b
->type
== bp_breakpoint
6831 || b
->type
== bp_hardware_breakpoint
))
6832 b
->enable_state
= bp_startup_disabled
;
6838 loc
= add_location_to_breakpoint (b
, &sal
);
6841 if (bp_loc_is_permanent (loc
))
6842 make_breakpoint_permanent (b
);
6846 char *arg
= b
->cond_string
;
6847 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6849 error (_("Garbage %s follows condition"), arg
);
6854 b
->addr_string
= addr_string
;
6856 /* addr_string has to be used or breakpoint_re_set will delete
6859 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6865 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6866 elements to fill the void space. */
6868 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6870 int i
= index_to_remove
+1;
6871 int last_index
= sal
->nelts
-1;
6873 for (;i
<= last_index
; ++i
)
6874 sal
->sals
[i
-1] = sal
->sals
[i
];
6879 /* If appropriate, obtains all sals that correspond to the same file
6880 and line as SAL, in all program spaces. Users debugging with IDEs,
6881 will want to set a breakpoint at foo.c:line, and not really care
6882 about program spaces. This is done only if SAL does not have
6883 explicit PC and has line and file information. If we got just a
6884 single expanded sal, return the original.
6886 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6887 which the name of enclosing function is different from SAL. This
6888 makes sure that if we have breakpoint originally set in template
6889 instantiation, say foo<int>(), we won't expand SAL to locations at
6890 the same line in all existing instantiations of 'foo'. */
6892 static struct symtabs_and_lines
6893 expand_line_sal_maybe (struct symtab_and_line sal
)
6895 struct symtabs_and_lines expanded
;
6896 CORE_ADDR original_pc
= sal
.pc
;
6897 char *original_function
= NULL
;
6900 struct cleanup
*old_chain
;
6902 /* If we have explicit pc, don't expand.
6903 If we have no line number, we can't expand. */
6904 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6907 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6908 expanded
.sals
[0] = sal
;
6914 old_chain
= save_current_space_and_thread ();
6916 switch_to_program_space_and_thread (sal
.pspace
);
6918 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6920 /* Note that expand_line_sal visits *all* program spaces. */
6921 expanded
= expand_line_sal (sal
);
6923 if (expanded
.nelts
== 1)
6925 /* We had one sal, we got one sal. Return that sal, adjusting it
6926 past the function prologue if necessary. */
6927 xfree (expanded
.sals
);
6929 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6930 sal
.pc
= original_pc
;
6931 expanded
.sals
[0] = sal
;
6932 skip_prologue_sal (&expanded
.sals
[0]);
6933 do_cleanups (old_chain
);
6937 if (!sal
.explicit_line
)
6939 CORE_ADDR func_addr
, func_end
;
6940 for (i
= 0; i
< expanded
.nelts
; ++i
)
6942 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6943 char *this_function
;
6945 /* We need to switch threads as well since we're about to
6947 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6949 if (find_pc_partial_function (pc
, &this_function
,
6950 &func_addr
, &func_end
))
6953 && strcmp (this_function
, original_function
) != 0)
6955 remove_sal (&expanded
, i
);
6962 /* Skip the function prologue if necessary. */
6963 for (i
= 0; i
< expanded
.nelts
; ++i
)
6964 skip_prologue_sal (&expanded
.sals
[i
]);
6966 do_cleanups (old_chain
);
6968 if (expanded
.nelts
<= 1)
6970 /* This is un ugly workaround. If we get zero
6971 expanded sals then something is really wrong.
6972 Fix that by returnign the original sal. */
6973 xfree (expanded
.sals
);
6975 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6976 sal
.pc
= original_pc
;
6977 expanded
.sals
[0] = sal
;
6984 for (i
= 0; i
< expanded
.nelts
; ++i
)
6985 if (expanded
.sals
[i
].pc
== original_pc
)
6996 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6997 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6998 value. COND_STRING, if not NULL, specified the condition to be
6999 used for all breakpoints. Essentially the only case where
7000 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7001 function. In that case, it's still not possible to specify
7002 separate conditions for different overloaded functions, so
7003 we take just a single condition string.
7005 NOTE: If the function succeeds, the caller is expected to cleanup
7006 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7007 array contents). If the function fails (error() is called), the
7008 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7009 COND and SALS arrays and each of those arrays contents. */
7012 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7013 struct symtabs_and_lines sals
, char **addr_string
,
7015 enum bptype type
, enum bpdisp disposition
,
7016 int thread
, int task
, int ignore_count
,
7017 struct breakpoint_ops
*ops
, int from_tty
,
7021 for (i
= 0; i
< sals
.nelts
; ++i
)
7023 struct symtabs_and_lines expanded
=
7024 expand_line_sal_maybe (sals
.sals
[i
]);
7026 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7027 cond_string
, type
, disposition
,
7028 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7032 /* Parse ARG which is assumed to be a SAL specification possibly
7033 followed by conditionals. On return, SALS contains an array of SAL
7034 addresses found. ADDR_STRING contains a vector of (canonical)
7035 address strings. ARG points to the end of the SAL. */
7038 parse_breakpoint_sals (char **address
,
7039 struct symtabs_and_lines
*sals
,
7040 char ***addr_string
,
7043 char *addr_start
= *address
;
7044 *addr_string
= NULL
;
7045 /* If no arg given, or if first arg is 'if ', use the default
7047 if ((*address
) == NULL
7048 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7050 if (default_breakpoint_valid
)
7052 struct symtab_and_line sal
;
7053 init_sal (&sal
); /* initialize to zeroes */
7054 sals
->sals
= (struct symtab_and_line
*)
7055 xmalloc (sizeof (struct symtab_and_line
));
7056 sal
.pc
= default_breakpoint_address
;
7057 sal
.line
= default_breakpoint_line
;
7058 sal
.symtab
= default_breakpoint_symtab
;
7059 sal
.pspace
= default_breakpoint_pspace
;
7060 sal
.section
= find_pc_overlay (sal
.pc
);
7062 /* "break" without arguments is equivalent to "break *PC" where PC is
7063 the default_breakpoint_address. So make sure to set
7064 sal.explicit_pc to prevent GDB from trying to expand the list of
7065 sals to include all other instances with the same symtab and line.
7067 sal
.explicit_pc
= 1;
7069 sals
->sals
[0] = sal
;
7073 error (_("No default breakpoint address now."));
7077 /* Force almost all breakpoints to be in terms of the
7078 current_source_symtab (which is decode_line_1's default). This
7079 should produce the results we want almost all of the time while
7080 leaving default_breakpoint_* alone.
7081 ObjC: However, don't match an Objective-C method name which
7082 may have a '+' or '-' succeeded by a '[' */
7084 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7086 if (default_breakpoint_valid
7088 || ((strchr ("+-", (*address
)[0]) != NULL
)
7089 && ((*address
)[1] != '['))))
7090 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7091 default_breakpoint_line
, addr_string
,
7094 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7095 addr_string
, not_found_ptr
);
7097 /* For any SAL that didn't have a canonical string, fill one in. */
7098 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7099 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7100 if (addr_start
!= (*address
))
7103 for (i
= 0; i
< sals
->nelts
; i
++)
7105 /* Add the string if not present. */
7106 if ((*addr_string
)[i
] == NULL
)
7107 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7113 /* Convert each SAL into a real PC. Verify that the PC can be
7114 inserted as a breakpoint. If it can't throw an error. */
7117 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7121 for (i
= 0; i
< sals
->nelts
; i
++)
7122 resolve_sal_pc (&sals
->sals
[i
]);
7125 /* Fast tracepoints may have restrictions on valid locations. For
7126 instance, a fast tracepoint using a jump instead of a trap will
7127 likely have to overwrite more bytes than a trap would, and so can
7128 only be placed where the instruction is longer than the jump, or a
7129 multi-instruction sequence does not have a jump into the middle of
7133 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7134 struct symtabs_and_lines
*sals
)
7137 struct symtab_and_line
*sal
;
7139 struct cleanup
*old_chain
;
7141 for (i
= 0; i
< sals
->nelts
; i
++)
7143 sal
= &sals
->sals
[i
];
7145 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7147 old_chain
= make_cleanup (xfree
, msg
);
7150 error (_("May not have a fast tracepoint at 0x%s%s"),
7151 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7153 do_cleanups (old_chain
);
7158 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7160 struct captured_parse_breakpoint_args
*args
= data
;
7162 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7163 args
->not_found_ptr
);
7166 /* Given TOK, a string specification of condition and thread, as
7167 accepted by the 'break' command, extract the condition
7168 string and thread number and set *COND_STRING and *THREAD.
7169 PC identifies the context at which the condition should be parsed.
7170 If no condition is found, *COND_STRING is set to NULL.
7171 If no thread is found, *THREAD is set to -1. */
7173 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7174 char **cond_string
, int *thread
, int *task
)
7176 *cond_string
= NULL
;
7182 char *cond_start
= NULL
;
7183 char *cond_end
= NULL
;
7184 while (*tok
== ' ' || *tok
== '\t')
7189 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7192 toklen
= end_tok
- tok
;
7194 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7196 struct expression
*expr
;
7198 tok
= cond_start
= end_tok
+ 1;
7199 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7202 *cond_string
= savestring (cond_start
,
7203 cond_end
- cond_start
);
7205 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7211 *thread
= strtol (tok
, &tok
, 0);
7213 error (_("Junk after thread keyword."));
7214 if (!valid_thread_id (*thread
))
7215 error (_("Unknown thread %d."), *thread
);
7217 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7223 *task
= strtol (tok
, &tok
, 0);
7225 error (_("Junk after task keyword."));
7226 if (!valid_task_id (*task
))
7227 error (_("Unknown task %d."), *task
);
7230 error (_("Junk at end of arguments."));
7234 /* Set a breakpoint. This function is shared between CLI and MI
7235 functions for setting a breakpoint. This function has two major
7236 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7237 parameter. If non-zero, the function will parse arg, extracting
7238 breakpoint location, address and thread. Otherwise, ARG is just the
7239 location of breakpoint, with condition and thread specified by the
7240 COND_STRING and THREAD parameters. Returns true if any breakpoint
7241 was created; false otherwise. */
7244 create_breakpoint (struct gdbarch
*gdbarch
,
7245 char *arg
, char *cond_string
, int thread
,
7246 int parse_condition_and_thread
,
7247 int tempflag
, int hardwareflag
, int traceflag
,
7249 enum auto_boolean pending_break_support
,
7250 struct breakpoint_ops
*ops
,
7254 struct gdb_exception e
;
7255 struct symtabs_and_lines sals
;
7256 struct symtab_and_line pending_sal
;
7259 char *addr_start
= arg
;
7261 struct cleanup
*old_chain
;
7262 struct cleanup
*bkpt_chain
= NULL
;
7263 struct captured_parse_breakpoint_args parse_args
;
7267 enum bptype type_wanted
;
7269 int prev_bkpt_count
= breakpoint_count
;
7275 parse_args
.arg_p
= &arg
;
7276 parse_args
.sals_p
= &sals
;
7277 parse_args
.addr_string_p
= &addr_string
;
7278 parse_args
.not_found_ptr
= ¬_found
;
7280 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7281 &parse_args
, RETURN_MASK_ALL
);
7283 /* If caller is interested in rc value from parse, set value. */
7287 throw_exception (e
);
7291 case NOT_FOUND_ERROR
:
7293 /* If pending breakpoint support is turned off, throw
7296 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7297 throw_exception (e
);
7299 exception_print (gdb_stderr
, e
);
7301 /* If pending breakpoint support is auto query and the user
7302 selects no, then simply return the error code. */
7303 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7304 && !nquery ("Make breakpoint pending on future shared library load? "))
7307 /* At this point, either the user was queried about setting
7308 a pending breakpoint and selected yes, or pending
7309 breakpoint behavior is on and thus a pending breakpoint
7310 is defaulted on behalf of the user. */
7311 copy_arg
= xstrdup (addr_start
);
7312 addr_string
= ©_arg
;
7314 sals
.sals
= &pending_sal
;
7319 throw_exception (e
);
7326 /* Create a chain of things that always need to be cleaned up. */
7327 old_chain
= make_cleanup (null_cleanup
, 0);
7331 /* Make sure that all storage allocated to SALS gets freed. */
7332 make_cleanup (xfree
, sals
.sals
);
7334 /* Cleanup the addr_string array but not its contents. */
7335 make_cleanup (xfree
, addr_string
);
7338 /* ----------------------------- SNIP -----------------------------
7339 Anything added to the cleanup chain beyond this point is assumed
7340 to be part of a breakpoint. If the breakpoint create succeeds
7341 then the memory is not reclaimed. */
7342 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7344 /* Mark the contents of the addr_string for cleanup. These go on
7345 the bkpt_chain and only occur if the breakpoint create fails. */
7346 for (i
= 0; i
< sals
.nelts
; i
++)
7348 if (addr_string
[i
] != NULL
)
7349 make_cleanup (xfree
, addr_string
[i
]);
7352 /* Resolve all line numbers to PC's and verify that the addresses
7353 are ok for the target. */
7355 breakpoint_sals_to_pc (&sals
, addr_start
);
7357 type_wanted
= (traceflag
7358 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7359 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7361 /* Fast tracepoints may have additional restrictions on location. */
7362 if (type_wanted
== bp_fast_tracepoint
)
7363 check_fast_tracepoint_sals (gdbarch
, &sals
);
7365 /* Verify that condition can be parsed, before setting any
7366 breakpoints. Allocate a separate condition expression for each
7370 if (parse_condition_and_thread
)
7372 /* Here we only parse 'arg' to separate condition
7373 from thread number, so parsing in context of first
7374 sal is OK. When setting the breakpoint we'll
7375 re-parse it in context of each sal. */
7378 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7381 make_cleanup (xfree
, cond_string
);
7385 /* Create a private copy of condition string. */
7388 cond_string
= xstrdup (cond_string
);
7389 make_cleanup (xfree
, cond_string
);
7392 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7393 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7394 thread
, task
, ignore_count
, ops
, from_tty
,
7399 struct symtab_and_line sal
= {0};
7400 struct breakpoint
*b
;
7402 make_cleanup (xfree
, copy_arg
);
7404 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7405 set_breakpoint_count (breakpoint_count
+ 1);
7406 b
->number
= breakpoint_count
;
7408 b
->addr_string
= addr_string
[0];
7409 b
->cond_string
= NULL
;
7410 b
->ignore_count
= ignore_count
;
7411 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7412 b
->condition_not_parsed
= 1;
7414 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7415 b
->pspace
= current_program_space
;
7417 if (enabled
&& b
->pspace
->executing_startup
7418 && (b
->type
== bp_breakpoint
7419 || b
->type
== bp_hardware_breakpoint
))
7420 b
->enable_state
= bp_startup_disabled
;
7427 warning (_("Multiple breakpoints were set.\n"
7428 "Use the \"delete\" command to delete unwanted breakpoints."));
7429 prev_breakpoint_count
= prev_bkpt_count
;
7432 /* That's it. Discard the cleanups for data inserted into the
7434 discard_cleanups (bkpt_chain
);
7435 /* But cleanup everything else. */
7436 do_cleanups (old_chain
);
7438 /* error call may happen here - have BKPT_CHAIN already discarded. */
7439 update_global_location_list (1);
7444 /* Set a breakpoint.
7445 ARG is a string describing breakpoint address,
7446 condition, and thread.
7447 FLAG specifies if a breakpoint is hardware on,
7448 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7452 break_command_1 (char *arg
, int flag
, int from_tty
)
7454 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7455 int tempflag
= flag
& BP_TEMPFLAG
;
7457 create_breakpoint (get_current_arch (),
7459 NULL
, 0, 1 /* parse arg */,
7460 tempflag
, hardwareflag
, 0 /* traceflag */,
7461 0 /* Ignore count */,
7462 pending_break_support
,
7463 NULL
/* breakpoint_ops */,
7470 /* Helper function for break_command_1 and disassemble_command. */
7473 resolve_sal_pc (struct symtab_and_line
*sal
)
7477 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7479 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7480 error (_("No line %d in file \"%s\"."),
7481 sal
->line
, sal
->symtab
->filename
);
7484 /* If this SAL corresponds to a breakpoint inserted using
7485 a line number, then skip the function prologue if necessary. */
7486 if (sal
->explicit_line
)
7487 skip_prologue_sal (sal
);
7490 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7492 struct blockvector
*bv
;
7496 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7499 sym
= block_linkage_function (b
);
7502 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7503 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7507 /* It really is worthwhile to have the section, so we'll just
7508 have to look harder. This case can be executed if we have
7509 line numbers but no functions (as can happen in assembly
7512 struct minimal_symbol
*msym
;
7513 struct cleanup
*old_chain
= save_current_space_and_thread ();
7515 switch_to_program_space_and_thread (sal
->pspace
);
7517 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7519 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7521 do_cleanups (old_chain
);
7528 break_command (char *arg
, int from_tty
)
7530 break_command_1 (arg
, 0, from_tty
);
7534 tbreak_command (char *arg
, int from_tty
)
7536 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7540 hbreak_command (char *arg
, int from_tty
)
7542 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7546 thbreak_command (char *arg
, int from_tty
)
7548 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7552 stop_command (char *arg
, int from_tty
)
7554 printf_filtered (_("Specify the type of breakpoint to set.\n\
7555 Usage: stop in <function | address>\n\
7556 stop at <line>\n"));
7560 stopin_command (char *arg
, int from_tty
)
7564 if (arg
== (char *) NULL
)
7566 else if (*arg
!= '*')
7571 /* look for a ':'. If this is a line number specification, then
7572 say it is bad, otherwise, it should be an address or
7573 function/method name */
7574 while (*argptr
&& !hasColon
)
7576 hasColon
= (*argptr
== ':');
7581 badInput
= (*argptr
!= ':'); /* Not a class::method */
7583 badInput
= isdigit (*arg
); /* a simple line number */
7587 printf_filtered (_("Usage: stop in <function | address>\n"));
7589 break_command_1 (arg
, 0, from_tty
);
7593 stopat_command (char *arg
, int from_tty
)
7597 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7604 /* look for a ':'. If there is a '::' then get out, otherwise
7605 it is probably a line number. */
7606 while (*argptr
&& !hasColon
)
7608 hasColon
= (*argptr
== ':');
7613 badInput
= (*argptr
== ':'); /* we have class::method */
7615 badInput
= !isdigit (*arg
); /* not a line number */
7619 printf_filtered (_("Usage: stop at <line>\n"));
7621 break_command_1 (arg
, 0, from_tty
);
7624 /* accessflag: hw_write: watch write,
7625 hw_read: watch read,
7626 hw_access: watch access (read or write) */
7628 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7630 struct gdbarch
*gdbarch
= get_current_arch ();
7631 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7632 struct expression
*exp
;
7633 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7634 struct value
*val
, *mark
;
7635 struct frame_info
*frame
;
7636 char *exp_start
= NULL
;
7637 char *exp_end
= NULL
;
7638 char *tok
, *id_tok_start
, *end_tok
;
7640 char *cond_start
= NULL
;
7641 char *cond_end
= NULL
;
7642 int i
, other_type_used
, target_resources_ok
= 0;
7643 enum bptype bp_type
;
7647 /* Make sure that we actually have parameters to parse. */
7648 if (arg
!= NULL
&& arg
[0] != '\0')
7650 toklen
= strlen (arg
); /* Size of argument list. */
7652 /* Points tok to the end of the argument list. */
7653 tok
= arg
+ toklen
- 1;
7655 /* Go backwards in the parameters list. Skip the last parameter.
7656 If we're expecting a 'thread <thread_num>' parameter, this should
7657 be the thread identifier. */
7658 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7660 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7663 /* Points end_tok to the beginning of the last token. */
7664 id_tok_start
= tok
+ 1;
7666 /* Go backwards in the parameters list. Skip one more parameter.
7667 If we're expecting a 'thread <thread_num>' parameter, we should
7668 reach a "thread" token. */
7669 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7674 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7677 /* Move the pointer forward to skip the whitespace and
7678 calculate the length of the token. */
7680 toklen
= end_tok
- tok
;
7682 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7684 /* At this point we've found a "thread" token, which means
7685 the user is trying to set a watchpoint that triggers
7686 only in a specific thread. */
7689 /* Extract the thread ID from the next token. */
7690 thread
= strtol (id_tok_start
, &endp
, 0);
7692 /* Check if the user provided a valid numeric value for the
7694 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7695 error (_("Invalid thread ID specification %s."), id_tok_start
);
7697 /* Check if the thread actually exists. */
7698 if (!valid_thread_id (thread
))
7699 error (_("Unknown thread %d."), thread
);
7701 /* Truncate the string and get rid of the thread <thread_num>
7702 parameter before the parameter list is parsed by the
7703 evaluate_expression() function. */
7708 /* Parse the rest of the arguments. */
7709 innermost_block
= NULL
;
7711 exp
= parse_exp_1 (&arg
, 0, 0);
7713 /* Remove trailing whitespace from the expression before saving it.
7714 This makes the eventual display of the expression string a bit
7716 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7719 exp_valid_block
= innermost_block
;
7720 mark
= value_mark ();
7721 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7723 release_value (val
);
7726 while (*tok
== ' ' || *tok
== '\t')
7730 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7733 toklen
= end_tok
- tok
;
7734 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7736 struct expression
*cond
;
7738 innermost_block
= NULL
;
7739 tok
= cond_start
= end_tok
+ 1;
7740 cond
= parse_exp_1 (&tok
, 0, 0);
7742 /* The watchpoint expression may not be local, but the condition
7743 may still be. E.g.: `watch global if local > 0'. */
7744 cond_exp_valid_block
= innermost_block
;
7750 error (_("Junk at end of command."));
7752 if (accessflag
== hw_read
)
7753 bp_type
= bp_read_watchpoint
;
7754 else if (accessflag
== hw_access
)
7755 bp_type
= bp_access_watchpoint
;
7757 bp_type
= bp_hardware_watchpoint
;
7759 mem_cnt
= can_use_hardware_watchpoint (val
);
7760 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7761 error (_("Expression cannot be implemented with read/access watchpoint."));
7764 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7765 target_resources_ok
=
7766 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7768 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7769 error (_("Target does not support this type of hardware watchpoint."));
7771 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7772 error (_("Target can only support one kind of HW watchpoint at a time."));
7775 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7776 watchpoint could not be set. */
7777 if (!mem_cnt
|| target_resources_ok
<= 0)
7778 bp_type
= bp_watchpoint
;
7780 frame
= block_innermost_frame (exp_valid_block
);
7782 /* If the expression is "local", then set up a "watchpoint scope"
7783 breakpoint at the point where we've left the scope of the watchpoint
7784 expression. Create the scope breakpoint before the watchpoint, so
7785 that we will encounter it first in bpstat_stop_status. */
7786 if (exp_valid_block
&& frame
)
7788 if (frame_id_p (frame_unwind_caller_id (frame
)))
7791 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7792 frame_unwind_caller_pc (frame
),
7793 bp_watchpoint_scope
);
7795 scope_breakpoint
->enable_state
= bp_enabled
;
7797 /* Automatically delete the breakpoint when it hits. */
7798 scope_breakpoint
->disposition
= disp_del
;
7800 /* Only break in the proper frame (help with recursion). */
7801 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7803 /* Set the address at which we will stop. */
7804 scope_breakpoint
->loc
->gdbarch
7805 = frame_unwind_caller_arch (frame
);
7806 scope_breakpoint
->loc
->requested_address
7807 = frame_unwind_caller_pc (frame
);
7808 scope_breakpoint
->loc
->address
7809 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7810 scope_breakpoint
->loc
->requested_address
,
7811 scope_breakpoint
->type
);
7815 /* Now set up the breakpoint. */
7816 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7817 set_breakpoint_count (breakpoint_count
+ 1);
7818 b
->number
= breakpoint_count
;
7820 b
->disposition
= disp_donttouch
;
7822 b
->exp_valid_block
= exp_valid_block
;
7823 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7824 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7828 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7834 b
->watchpoint_frame
= get_frame_id (frame
);
7835 b
->watchpoint_thread
= inferior_ptid
;
7839 b
->watchpoint_frame
= null_frame_id
;
7840 b
->watchpoint_thread
= null_ptid
;
7843 if (scope_breakpoint
!= NULL
)
7845 /* The scope breakpoint is related to the watchpoint. We will
7846 need to act on them together. */
7847 b
->related_breakpoint
= scope_breakpoint
;
7848 scope_breakpoint
->related_breakpoint
= b
;
7851 value_free_to_mark (mark
);
7853 /* Finally update the new watchpoint. This creates the locations
7854 that should be inserted. */
7855 update_watchpoint (b
, 1);
7858 update_global_location_list (1);
7861 /* Return count of locations need to be watched and can be handled
7862 in hardware. If the watchpoint can not be handled
7863 in hardware return zero. */
7866 can_use_hardware_watchpoint (struct value
*v
)
7868 int found_memory_cnt
= 0;
7869 struct value
*head
= v
;
7871 /* Did the user specifically forbid us to use hardware watchpoints? */
7872 if (!can_use_hw_watchpoints
)
7875 /* Make sure that the value of the expression depends only upon
7876 memory contents, and values computed from them within GDB. If we
7877 find any register references or function calls, we can't use a
7878 hardware watchpoint.
7880 The idea here is that evaluating an expression generates a series
7881 of values, one holding the value of every subexpression. (The
7882 expression a*b+c has five subexpressions: a, b, a*b, c, and
7883 a*b+c.) GDB's values hold almost enough information to establish
7884 the criteria given above --- they identify memory lvalues,
7885 register lvalues, computed values, etcetera. So we can evaluate
7886 the expression, and then scan the chain of values that leaves
7887 behind to decide whether we can detect any possible change to the
7888 expression's final value using only hardware watchpoints.
7890 However, I don't think that the values returned by inferior
7891 function calls are special in any way. So this function may not
7892 notice that an expression involving an inferior function call
7893 can't be watched with hardware watchpoints. FIXME. */
7894 for (; v
; v
= value_next (v
))
7896 if (VALUE_LVAL (v
) == lval_memory
)
7899 /* A lazy memory lvalue is one that GDB never needed to fetch;
7900 we either just used its address (e.g., `a' in `a.b') or
7901 we never needed it at all (e.g., `a' in `a,b'). */
7905 /* Ahh, memory we actually used! Check if we can cover
7906 it with hardware watchpoints. */
7907 struct type
*vtype
= check_typedef (value_type (v
));
7909 /* We only watch structs and arrays if user asked for it
7910 explicitly, never if they just happen to appear in a
7911 middle of some value chain. */
7913 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7914 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7916 CORE_ADDR vaddr
= value_address (v
);
7917 int len
= TYPE_LENGTH (value_type (v
));
7919 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7926 else if (VALUE_LVAL (v
) != not_lval
7927 && deprecated_value_modifiable (v
) == 0)
7928 return 0; /* ??? What does this represent? */
7929 else if (VALUE_LVAL (v
) == lval_register
)
7930 return 0; /* cannot watch a register with a HW watchpoint */
7933 /* The expression itself looks suitable for using a hardware
7934 watchpoint, but give the target machine a chance to reject it. */
7935 return found_memory_cnt
;
7939 watch_command_wrapper (char *arg
, int from_tty
)
7941 watch_command (arg
, from_tty
);
7945 watch_command (char *arg
, int from_tty
)
7947 watch_command_1 (arg
, hw_write
, from_tty
);
7951 rwatch_command_wrapper (char *arg
, int from_tty
)
7953 rwatch_command (arg
, from_tty
);
7957 rwatch_command (char *arg
, int from_tty
)
7959 watch_command_1 (arg
, hw_read
, from_tty
);
7963 awatch_command_wrapper (char *arg
, int from_tty
)
7965 awatch_command (arg
, from_tty
);
7969 awatch_command (char *arg
, int from_tty
)
7971 watch_command_1 (arg
, hw_access
, from_tty
);
7975 /* Helper routines for the until_command routine in infcmd.c. Here
7976 because it uses the mechanisms of breakpoints. */
7978 struct until_break_command_continuation_args
7980 struct breakpoint
*breakpoint
;
7981 struct breakpoint
*breakpoint2
;
7984 /* This function is called by fetch_inferior_event via the
7985 cmd_continuation pointer, to complete the until command. It takes
7986 care of cleaning up the temporary breakpoints set up by the until
7989 until_break_command_continuation (void *arg
)
7991 struct until_break_command_continuation_args
*a
= arg
;
7993 delete_breakpoint (a
->breakpoint
);
7995 delete_breakpoint (a
->breakpoint2
);
7999 until_break_command (char *arg
, int from_tty
, int anywhere
)
8001 struct symtabs_and_lines sals
;
8002 struct symtab_and_line sal
;
8003 struct frame_info
*frame
= get_selected_frame (NULL
);
8004 struct breakpoint
*breakpoint
;
8005 struct breakpoint
*breakpoint2
= NULL
;
8006 struct cleanup
*old_chain
;
8008 clear_proceed_status ();
8010 /* Set a breakpoint where the user wants it and at return from
8013 if (default_breakpoint_valid
)
8014 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8015 default_breakpoint_line
, (char ***) NULL
, NULL
);
8017 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8018 0, (char ***) NULL
, NULL
);
8020 if (sals
.nelts
!= 1)
8021 error (_("Couldn't get information on specified line."));
8024 xfree (sals
.sals
); /* malloc'd, so freed */
8027 error (_("Junk at end of arguments."));
8029 resolve_sal_pc (&sal
);
8032 /* If the user told us to continue until a specified location,
8033 we don't specify a frame at which we need to stop. */
8034 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8035 null_frame_id
, bp_until
);
8037 /* Otherwise, specify the selected frame, because we want to stop only
8038 at the very same frame. */
8039 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8040 get_stack_frame_id (frame
),
8043 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8045 /* Keep within the current frame, or in frames called by the current
8048 if (frame_id_p (frame_unwind_caller_id (frame
)))
8050 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8051 sal
.pc
= frame_unwind_caller_pc (frame
);
8052 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8054 frame_unwind_caller_id (frame
),
8056 make_cleanup_delete_breakpoint (breakpoint2
);
8059 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8061 /* If we are running asynchronously, and proceed call above has actually
8062 managed to start the target, arrange for breakpoints to be
8063 deleted when the target stops. Otherwise, we're already stopped and
8064 delete breakpoints via cleanup chain. */
8066 if (target_can_async_p () && is_running (inferior_ptid
))
8068 struct until_break_command_continuation_args
*args
;
8069 args
= xmalloc (sizeof (*args
));
8071 args
->breakpoint
= breakpoint
;
8072 args
->breakpoint2
= breakpoint2
;
8074 discard_cleanups (old_chain
);
8075 add_continuation (inferior_thread (),
8076 until_break_command_continuation
, args
,
8080 do_cleanups (old_chain
);
8084 ep_skip_leading_whitespace (char **s
)
8086 if ((s
== NULL
) || (*s
== NULL
))
8088 while (isspace (**s
))
8092 /* This function attempts to parse an optional "if <cond>" clause
8093 from the arg string. If one is not found, it returns NULL.
8095 Else, it returns a pointer to the condition string. (It does not
8096 attempt to evaluate the string against a particular block.) And,
8097 it updates arg to point to the first character following the parsed
8098 if clause in the arg string. */
8101 ep_parse_optional_if_clause (char **arg
)
8105 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8108 /* Skip the "if" keyword. */
8111 /* Skip any extra leading whitespace, and record the start of the
8112 condition string. */
8113 ep_skip_leading_whitespace (arg
);
8116 /* Assume that the condition occupies the remainder of the arg string. */
8117 (*arg
) += strlen (cond_string
);
8122 /* Commands to deal with catching events, such as signals, exceptions,
8123 process start/exit, etc. */
8127 catch_fork_temporary
, catch_vfork_temporary
,
8128 catch_fork_permanent
, catch_vfork_permanent
8133 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8135 struct gdbarch
*gdbarch
= get_current_arch ();
8136 char *cond_string
= NULL
;
8137 catch_fork_kind fork_kind
;
8140 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8141 tempflag
= (fork_kind
== catch_fork_temporary
8142 || fork_kind
== catch_vfork_temporary
);
8146 ep_skip_leading_whitespace (&arg
);
8148 /* The allowed syntax is:
8150 catch [v]fork if <cond>
8152 First, check if there's an if clause. */
8153 cond_string
= ep_parse_optional_if_clause (&arg
);
8155 if ((*arg
!= '\0') && !isspace (*arg
))
8156 error (_("Junk at end of arguments."));
8158 /* If this target supports it, create a fork or vfork catchpoint
8159 and enable reporting of such events. */
8162 case catch_fork_temporary
:
8163 case catch_fork_permanent
:
8164 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8165 &catch_fork_breakpoint_ops
);
8167 case catch_vfork_temporary
:
8168 case catch_vfork_permanent
:
8169 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8170 &catch_vfork_breakpoint_ops
);
8173 error (_("unsupported or unknown fork kind; cannot catch it"));
8179 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8181 struct gdbarch
*gdbarch
= get_current_arch ();
8183 char *cond_string
= NULL
;
8185 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8189 ep_skip_leading_whitespace (&arg
);
8191 /* The allowed syntax is:
8193 catch exec if <cond>
8195 First, check if there's an if clause. */
8196 cond_string
= ep_parse_optional_if_clause (&arg
);
8198 if ((*arg
!= '\0') && !isspace (*arg
))
8199 error (_("Junk at end of arguments."));
8201 /* If this target supports it, create an exec catchpoint
8202 and enable reporting of such events. */
8203 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8204 &catch_exec_breakpoint_ops
);
8207 static enum print_stop_action
8208 print_exception_catchpoint (struct breakpoint
*b
)
8210 int bp_temp
, bp_throw
;
8212 annotate_catchpoint (b
->number
);
8214 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8215 if (b
->loc
->address
!= b
->loc
->requested_address
)
8216 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8219 bp_temp
= b
->disposition
== disp_del
;
8221 bp_temp
? "Temporary catchpoint "
8223 if (!ui_out_is_mi_like_p (uiout
))
8224 ui_out_field_int (uiout
, "bkptno", b
->number
);
8226 bp_throw
? " (exception thrown), "
8227 : " (exception caught), ");
8228 if (ui_out_is_mi_like_p (uiout
))
8230 ui_out_field_string (uiout
, "reason",
8231 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8232 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8233 ui_out_field_int (uiout
, "bkptno", b
->number
);
8235 return PRINT_SRC_AND_LOC
;
8239 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8241 struct value_print_options opts
;
8242 get_user_print_options (&opts
);
8243 if (opts
.addressprint
)
8246 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8247 ui_out_field_string (uiout
, "addr", "<PENDING>");
8249 ui_out_field_core_addr (uiout
, "addr",
8250 b
->loc
->gdbarch
, b
->loc
->address
);
8255 if (strstr (b
->addr_string
, "throw") != NULL
)
8256 ui_out_field_string (uiout
, "what", "exception throw");
8258 ui_out_field_string (uiout
, "what", "exception catch");
8262 print_mention_exception_catchpoint (struct breakpoint
*b
)
8267 bp_temp
= b
->disposition
== disp_del
;
8268 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8269 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8270 : _("Catchpoint "));
8271 ui_out_field_int (uiout
, "bkptno", b
->number
);
8272 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8276 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8279 NULL
, /* breakpoint_hit */
8280 print_exception_catchpoint
,
8281 print_one_exception_catchpoint
,
8282 print_mention_exception_catchpoint
8286 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8287 enum exception_event_kind ex_event
, int from_tty
)
8289 char *trigger_func_name
;
8291 if (ex_event
== EX_EVENT_CATCH
)
8292 trigger_func_name
= "__cxa_begin_catch";
8294 trigger_func_name
= "__cxa_throw";
8296 create_breakpoint (get_current_arch (),
8297 trigger_func_name
, cond_string
, -1,
8298 0 /* condition and thread are valid. */,
8301 AUTO_BOOLEAN_TRUE
/* pending */,
8302 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8308 /* Deal with "catch catch" and "catch throw" commands */
8311 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8312 int tempflag
, int from_tty
)
8314 char *cond_string
= NULL
;
8315 struct symtab_and_line
*sal
= NULL
;
8319 ep_skip_leading_whitespace (&arg
);
8321 cond_string
= ep_parse_optional_if_clause (&arg
);
8323 if ((*arg
!= '\0') && !isspace (*arg
))
8324 error (_("Junk at end of arguments."));
8326 if (ex_event
!= EX_EVENT_THROW
8327 && ex_event
!= EX_EVENT_CATCH
)
8328 error (_("Unsupported or unknown exception event; cannot catch it"));
8330 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8333 warning (_("Unsupported with this platform/compiler combination."));
8336 /* Implementation of "catch catch" command. */
8339 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8341 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8342 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8345 /* Implementation of "catch throw" command. */
8348 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8350 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8351 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8354 /* Create a breakpoint struct for Ada exception catchpoints. */
8357 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8358 struct symtab_and_line sal
,
8362 struct expression
*cond
,
8363 struct breakpoint_ops
*ops
,
8367 struct breakpoint
*b
;
8371 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8373 loc_gdbarch
= gdbarch
;
8375 describe_other_breakpoints (loc_gdbarch
,
8376 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8377 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8378 version for exception catchpoints, because two catchpoints
8379 used for different exception names will use the same address.
8380 In this case, a "breakpoint ... also set at..." warning is
8381 unproductive. Besides. the warning phrasing is also a bit
8382 inapropriate, we should use the word catchpoint, and tell
8383 the user what type of catchpoint it is. The above is good
8384 enough for now, though. */
8387 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8388 set_breakpoint_count (breakpoint_count
+ 1);
8390 b
->enable_state
= bp_enabled
;
8391 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8392 b
->number
= breakpoint_count
;
8393 b
->ignore_count
= 0;
8394 b
->loc
->cond
= cond
;
8395 b
->addr_string
= addr_string
;
8396 b
->language
= language_ada
;
8397 b
->cond_string
= cond_string
;
8398 b
->exp_string
= exp_string
;
8403 update_global_location_list (1);
8406 /* Implement the "catch exception" command. */
8409 catch_ada_exception_command (char *arg
, int from_tty
,
8410 struct cmd_list_element
*command
)
8412 struct gdbarch
*gdbarch
= get_current_arch ();
8414 struct symtab_and_line sal
;
8416 char *addr_string
= NULL
;
8417 char *exp_string
= NULL
;
8418 char *cond_string
= NULL
;
8419 struct expression
*cond
= NULL
;
8420 struct breakpoint_ops
*ops
= NULL
;
8422 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8426 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8427 &cond_string
, &cond
, &ops
);
8428 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8429 cond_string
, cond
, ops
, tempflag
,
8433 /* Cleanup function for a syscall filter list. */
8435 clean_up_filters (void *arg
)
8437 VEC(int) *iter
= *(VEC(int) **) arg
;
8438 VEC_free (int, iter
);
8441 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8442 filter list, or NULL if no filtering is required. */
8444 catch_syscall_split_args (char *arg
)
8446 VEC(int) *result
= NULL
;
8447 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8449 while (*arg
!= '\0')
8451 int i
, syscall_number
;
8456 /* Skip whitespace. */
8457 while (isspace (*arg
))
8460 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8461 cur_name
[i
] = arg
[i
];
8465 /* Check if the user provided a syscall name or a number. */
8466 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8467 if (*endptr
== '\0')
8468 get_syscall_by_number (syscall_number
, &s
);
8471 /* We have a name. Let's check if it's valid and convert it
8473 get_syscall_by_name (cur_name
, &s
);
8475 if (s
.number
== UNKNOWN_SYSCALL
)
8476 /* Here we have to issue an error instead of a warning, because
8477 GDB cannot do anything useful if there's no syscall number to
8479 error (_("Unknown syscall name '%s'."), cur_name
);
8482 /* Ok, it's valid. */
8483 VEC_safe_push (int, result
, s
.number
);
8486 discard_cleanups (cleanup
);
8490 /* Implement the "catch syscall" command. */
8493 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8498 struct gdbarch
*gdbarch
= get_current_arch ();
8500 /* Checking if the feature if supported. */
8501 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8502 error (_("The feature 'catch syscall' is not supported on \
8503 this architeture yet."));
8505 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8507 ep_skip_leading_whitespace (&arg
);
8509 /* We need to do this first "dummy" translation in order
8510 to get the syscall XML file loaded or, most important,
8511 to display a warning to the user if there's no XML file
8512 for his/her architecture. */
8513 get_syscall_by_number (0, &s
);
8515 /* The allowed syntax is:
8517 catch syscall <name | number> [<name | number> ... <name | number>]
8519 Let's check if there's a syscall name. */
8522 filter
= catch_syscall_split_args (arg
);
8526 create_syscall_event_catchpoint (tempflag
, filter
,
8527 &catch_syscall_breakpoint_ops
);
8530 /* Implement the "catch assert" command. */
8533 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8535 struct gdbarch
*gdbarch
= get_current_arch ();
8537 struct symtab_and_line sal
;
8538 char *addr_string
= NULL
;
8539 struct breakpoint_ops
*ops
= NULL
;
8541 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8545 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8546 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8547 ops
, tempflag
, from_tty
);
8551 catch_command (char *arg
, int from_tty
)
8553 error (_("Catch requires an event name."));
8558 tcatch_command (char *arg
, int from_tty
)
8560 error (_("Catch requires an event name."));
8563 /* Delete breakpoints by address or line. */
8566 clear_command (char *arg
, int from_tty
)
8568 struct breakpoint
*b
;
8569 VEC(breakpoint_p
) *found
= 0;
8572 struct symtabs_and_lines sals
;
8573 struct symtab_and_line sal
;
8578 sals
= decode_line_spec (arg
, 1);
8583 sals
.sals
= (struct symtab_and_line
*)
8584 xmalloc (sizeof (struct symtab_and_line
));
8585 make_cleanup (xfree
, sals
.sals
);
8586 init_sal (&sal
); /* initialize to zeroes */
8587 sal
.line
= default_breakpoint_line
;
8588 sal
.symtab
= default_breakpoint_symtab
;
8589 sal
.pc
= default_breakpoint_address
;
8590 sal
.pspace
= default_breakpoint_pspace
;
8591 if (sal
.symtab
== 0)
8592 error (_("No source file specified."));
8600 /* We don't call resolve_sal_pc here. That's not
8601 as bad as it seems, because all existing breakpoints
8602 typically have both file/line and pc set. So, if
8603 clear is given file/line, we can match this to existing
8604 breakpoint without obtaining pc at all.
8606 We only support clearing given the address explicitly
8607 present in breakpoint table. Say, we've set breakpoint
8608 at file:line. There were several PC values for that file:line,
8609 due to optimization, all in one block.
8610 We've picked one PC value. If "clear" is issued with another
8611 PC corresponding to the same file:line, the breakpoint won't
8612 be cleared. We probably can still clear the breakpoint, but
8613 since the other PC value is never presented to user, user
8614 can only find it by guessing, and it does not seem important
8617 /* For each line spec given, delete bps which correspond
8618 to it. Do it in two passes, solely to preserve the current
8619 behavior that from_tty is forced true if we delete more than
8623 for (i
= 0; i
< sals
.nelts
; i
++)
8625 /* If exact pc given, clear bpts at that pc.
8626 If line given (pc == 0), clear all bpts on specified line.
8627 If defaulting, clear all bpts on default line
8630 defaulting sal.pc != 0 tests to do
8635 1 0 <can't happen> */
8639 /* Find all matching breakpoints and add them to
8644 /* Are we going to delete b? */
8645 if (b
->type
!= bp_none
8646 && b
->type
!= bp_watchpoint
8647 && b
->type
!= bp_hardware_watchpoint
8648 && b
->type
!= bp_read_watchpoint
8649 && b
->type
!= bp_access_watchpoint
)
8651 struct bp_location
*loc
= b
->loc
;
8652 for (; loc
; loc
= loc
->next
)
8654 int pc_match
= sal
.pc
8655 && (loc
->pspace
== sal
.pspace
)
8656 && (loc
->address
== sal
.pc
)
8657 && (!section_is_overlay (loc
->section
)
8658 || loc
->section
== sal
.section
);
8659 int line_match
= ((default_match
|| (0 == sal
.pc
))
8660 && b
->source_file
!= NULL
8661 && sal
.symtab
!= NULL
8662 && sal
.pspace
== loc
->pspace
8663 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8664 && b
->line_number
== sal
.line
);
8665 if (pc_match
|| line_match
)
8674 VEC_safe_push(breakpoint_p
, found
, b
);
8677 /* Now go thru the 'found' chain and delete them. */
8678 if (VEC_empty(breakpoint_p
, found
))
8681 error (_("No breakpoint at %s."), arg
);
8683 error (_("No breakpoint at this line."));
8686 if (VEC_length(breakpoint_p
, found
) > 1)
8687 from_tty
= 1; /* Always report if deleted more than one */
8690 if (VEC_length(breakpoint_p
, found
) == 1)
8691 printf_unfiltered (_("Deleted breakpoint "));
8693 printf_unfiltered (_("Deleted breakpoints "));
8695 breakpoints_changed ();
8697 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8700 printf_unfiltered ("%d ", b
->number
);
8701 delete_breakpoint (b
);
8704 putchar_unfiltered ('\n');
8707 /* Delete breakpoint in BS if they are `delete' breakpoints and
8708 all breakpoints that are marked for deletion, whether hit or not.
8709 This is called after any breakpoint is hit, or after errors. */
8712 breakpoint_auto_delete (bpstat bs
)
8714 struct breakpoint
*b
, *temp
;
8716 for (; bs
; bs
= bs
->next
)
8717 if (bs
->breakpoint_at
8718 && bs
->breakpoint_at
->owner
8719 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8721 delete_breakpoint (bs
->breakpoint_at
->owner
);
8723 ALL_BREAKPOINTS_SAFE (b
, temp
)
8725 if (b
->disposition
== disp_del_at_next_stop
)
8726 delete_breakpoint (b
);
8730 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8731 Sort elements primarily by their ADDRESS (no matter what does
8732 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8733 first bp_permanent OWNERed elements and terciarily just ensuring the array
8734 is sorted stable way despite qsort being an instable algorithm. */
8737 bp_location_compare (const void *ap
, const void *bp
)
8739 struct bp_location
*a
= *(void **) ap
;
8740 struct bp_location
*b
= *(void **) bp
;
8741 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8742 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8744 if (a
->address
!= b
->address
)
8745 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8747 /* Sort permanent breakpoints first. */
8748 if (a_perm
!= b_perm
)
8749 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8751 /* Make the user-visible order stable across GDB runs. Locations of the same
8752 breakpoint can be sorted in arbitrary order. */
8754 if (a
->owner
->number
!= b
->owner
->number
)
8755 return (a
->owner
->number
> b
->owner
->number
)
8756 - (a
->owner
->number
< b
->owner
->number
);
8758 return (a
> b
) - (a
< b
);
8761 /* Set bp_location_placed_address_before_address_max and
8762 bp_location_shadow_len_after_address_max according to the current content of
8763 the bp_location array. */
8766 bp_location_target_extensions_update (void)
8768 struct bp_location
*bl
, **blp_tmp
;
8770 bp_location_placed_address_before_address_max
= 0;
8771 bp_location_shadow_len_after_address_max
= 0;
8773 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8775 CORE_ADDR start
, end
, addr
;
8777 if (!bp_location_has_shadow (bl
))
8780 start
= bl
->target_info
.placed_address
;
8781 end
= start
+ bl
->target_info
.shadow_len
;
8783 gdb_assert (bl
->address
>= start
);
8784 addr
= bl
->address
- start
;
8785 if (addr
> bp_location_placed_address_before_address_max
)
8786 bp_location_placed_address_before_address_max
= addr
;
8788 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8790 gdb_assert (bl
->address
< end
);
8791 addr
= end
- bl
->address
;
8792 if (addr
> bp_location_shadow_len_after_address_max
)
8793 bp_location_shadow_len_after_address_max
= addr
;
8797 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8798 into the inferior, only remove already-inserted locations that no
8799 longer should be inserted. Functions that delete a breakpoint or
8800 breakpoints should pass false, so that deleting a breakpoint
8801 doesn't have the side effect of inserting the locations of other
8802 breakpoints that are marked not-inserted, but should_be_inserted
8803 returns true on them.
8805 This behaviour is useful is situations close to tear-down -- e.g.,
8806 after an exec, while the target still has execution, but breakpoint
8807 shadows of the previous executable image should *NOT* be restored
8808 to the new image; or before detaching, where the target still has
8809 execution and wants to delete breakpoints from GDB's lists, and all
8810 breakpoints had already been removed from the inferior. */
8813 update_global_location_list (int should_insert
)
8815 struct breakpoint
*b
;
8816 struct bp_location
**locp
, *loc
;
8817 struct cleanup
*cleanups
;
8819 /* Used in the duplicates detection below. When iterating over all
8820 bp_locations, points to the first bp_location of a given address.
8821 Breakpoints and watchpoints of different types are never
8822 duplicates of each other. Keep one pointer for each type of
8823 breakpoint/watchpoint, so we only need to loop over all locations
8825 struct bp_location
*bp_loc_first
; /* breakpoint */
8826 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8827 struct bp_location
*awp_loc_first
; /* access watchpoint */
8828 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8830 /* Saved former bp_location array which we compare against the newly built
8831 bp_location from the current state of ALL_BREAKPOINTS. */
8832 struct bp_location
**old_location
, **old_locp
;
8833 unsigned old_location_count
;
8835 old_location
= bp_location
;
8836 old_location_count
= bp_location_count
;
8838 bp_location_count
= 0;
8839 cleanups
= make_cleanup (xfree
, old_location
);
8842 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8843 bp_location_count
++;
8845 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8848 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8850 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8851 bp_location_compare
);
8853 bp_location_target_extensions_update ();
8855 /* Identify bp_location instances that are no longer present in the new
8856 list, and therefore should be freed. Note that it's not necessary that
8857 those locations should be removed from inferior -- if there's another
8858 location at the same address (previously marked as duplicate),
8859 we don't need to remove/insert the location.
8861 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8862 former bp_location array state respectively. */
8865 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8868 struct bp_location
*old_loc
= *old_locp
;
8869 struct bp_location
**loc2p
;
8871 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8873 int found_object
= 0;
8874 /* Tells if the location should remain inserted in the target. */
8875 int keep_in_target
= 0;
8878 /* Skip LOCP entries which will definitely never be needed. Stop either
8879 at or being the one matching OLD_LOC. */
8880 while (locp
< bp_location
+ bp_location_count
8881 && (*locp
)->address
< old_loc
->address
)
8885 (loc2p
< bp_location
+ bp_location_count
8886 && (*loc2p
)->address
== old_loc
->address
);
8889 if (*loc2p
== old_loc
)
8896 /* If this location is no longer present, and inserted, look if there's
8897 maybe a new location at the same address. If so, mark that one
8898 inserted, and don't remove this one. This is needed so that we
8899 don't have a time window where a breakpoint at certain location is not
8902 if (old_loc
->inserted
)
8904 /* If the location is inserted now, we might have to remove it. */
8906 if (found_object
&& should_be_inserted (old_loc
))
8908 /* The location is still present in the location list, and still
8909 should be inserted. Don't do anything. */
8914 /* The location is either no longer present, or got disabled.
8915 See if there's another location at the same address, in which
8916 case we don't need to remove this one from the target. */
8918 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8921 (loc2p
< bp_location
+ bp_location_count
8922 && (*loc2p
)->address
== old_loc
->address
);
8925 struct bp_location
*loc2
= *loc2p
;
8927 if (breakpoint_locations_match (loc2
, old_loc
))
8929 /* For the sake of should_be_inserted.
8930 Duplicates check below will fix up this later. */
8931 loc2
->duplicate
= 0;
8933 /* Read watchpoint locations are switched to
8934 access watchpoints, if the former are not
8935 supported, but the latter are. */
8936 if (is_hardware_watchpoint (old_loc
->owner
))
8938 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8939 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8942 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8945 loc2
->target_info
= old_loc
->target_info
;
8954 if (!keep_in_target
)
8956 if (remove_breakpoint (old_loc
, mark_uninserted
))
8958 /* This is just about all we can do. We could keep this
8959 location on the global list, and try to remove it next
8960 time, but there's no particular reason why we will
8963 Note that at this point, old_loc->owner is still valid,
8964 as delete_breakpoint frees the breakpoint only
8965 after calling us. */
8966 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8967 old_loc
->owner
->number
);
8975 if (removed
&& non_stop
8976 && breakpoint_address_is_meaningful (old_loc
->owner
)
8977 && !is_hardware_watchpoint (old_loc
->owner
))
8979 /* This location was removed from the target. In
8980 non-stop mode, a race condition is possible where
8981 we've removed a breakpoint, but stop events for that
8982 breakpoint are already queued and will arrive later.
8983 We apply an heuristic to be able to distinguish such
8984 SIGTRAPs from other random SIGTRAPs: we keep this
8985 breakpoint location for a bit, and will retire it
8986 after we see some number of events. The theory here
8987 is that reporting of events should, "on the average",
8988 be fair, so after a while we'll see events from all
8989 threads that have anything of interest, and no longer
8990 need to keep this breakpoint location around. We
8991 don't hold locations forever so to reduce chances of
8992 mistaking a non-breakpoint SIGTRAP for a breakpoint
8995 The heuristic failing can be disastrous on
8996 decr_pc_after_break targets.
8998 On decr_pc_after_break targets, like e.g., x86-linux,
8999 if we fail to recognize a late breakpoint SIGTRAP,
9000 because events_till_retirement has reached 0 too
9001 soon, we'll fail to do the PC adjustment, and report
9002 a random SIGTRAP to the user. When the user resumes
9003 the inferior, it will most likely immediately crash
9004 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
9005 corrupted, because of being resumed e.g., in the
9006 middle of a multi-byte instruction, or skipped a
9007 one-byte instruction. This was actually seen happen
9008 on native x86-linux, and should be less rare on
9009 targets that do not support new thread events, like
9010 remote, due to the heuristic depending on
9013 Mistaking a random SIGTRAP for a breakpoint trap
9014 causes similar symptoms (PC adjustment applied when
9015 it shouldn't), but then again, playing with SIGTRAPs
9016 behind the debugger's back is asking for trouble.
9018 Since hardware watchpoint traps are always
9019 distinguishable from other traps, so we don't need to
9020 apply keep hardware watchpoint moribund locations
9021 around. We simply always ignore hardware watchpoint
9022 traps we can no longer explain. */
9024 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9025 old_loc
->owner
= NULL
;
9027 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9030 free_bp_location (old_loc
);
9034 /* Rescan breakpoints at the same address and section, marking the
9035 first one as "first" and any others as "duplicates". This is so
9036 that the bpt instruction is only inserted once. If we have a
9037 permanent breakpoint at the same place as BPT, make that one the
9038 official one, and the rest as duplicates. Permanent breakpoints
9039 are sorted first for the same address.
9041 Do the same for hardware watchpoints, but also considering the
9042 watchpoint's type (regular/access/read) and length. */
9044 bp_loc_first
= NULL
;
9045 wp_loc_first
= NULL
;
9046 awp_loc_first
= NULL
;
9047 rwp_loc_first
= NULL
;
9048 ALL_BP_LOCATIONS (loc
, locp
)
9050 struct breakpoint
*b
= loc
->owner
;
9051 struct bp_location
**loc_first_p
;
9053 if (b
->enable_state
== bp_disabled
9054 || b
->enable_state
== bp_call_disabled
9055 || b
->enable_state
== bp_startup_disabled
9057 || loc
->shlib_disabled
9058 || !breakpoint_address_is_meaningful (b
)
9059 || tracepoint_type (b
))
9062 /* Permanent breakpoint should always be inserted. */
9063 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9064 internal_error (__FILE__
, __LINE__
,
9065 _("allegedly permanent breakpoint is not "
9066 "actually inserted"));
9068 if (b
->type
== bp_hardware_watchpoint
)
9069 loc_first_p
= &wp_loc_first
;
9070 else if (b
->type
== bp_read_watchpoint
)
9071 loc_first_p
= &rwp_loc_first
;
9072 else if (b
->type
== bp_access_watchpoint
)
9073 loc_first_p
= &awp_loc_first
;
9075 loc_first_p
= &bp_loc_first
;
9077 if (*loc_first_p
== NULL
9078 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9079 || !breakpoint_locations_match (loc
, *loc_first_p
))
9088 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9089 && b
->enable_state
!= bp_permanent
)
9090 internal_error (__FILE__
, __LINE__
,
9091 _("another breakpoint was inserted on top of "
9092 "a permanent breakpoint"));
9095 if (breakpoints_always_inserted_mode () && should_insert
9096 && (have_live_inferiors ()
9097 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9098 insert_breakpoint_locations ();
9100 do_cleanups (cleanups
);
9104 breakpoint_retire_moribund (void)
9106 struct bp_location
*loc
;
9109 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9110 if (--(loc
->events_till_retirement
) == 0)
9112 free_bp_location (loc
);
9113 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9119 update_global_location_list_nothrow (int inserting
)
9121 struct gdb_exception e
;
9122 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9123 update_global_location_list (inserting
);
9126 /* Clear BPT from a BPS. */
9128 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9131 for (bs
= bps
; bs
; bs
= bs
->next
)
9132 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9134 bs
->breakpoint_at
= NULL
;
9136 /* bs->commands will be freed later. */
9140 /* Callback for iterate_over_threads. */
9142 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9144 struct breakpoint
*bpt
= data
;
9145 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9149 /* Delete a breakpoint and clean up all traces of it in the data
9153 delete_breakpoint (struct breakpoint
*bpt
)
9155 struct breakpoint
*b
;
9156 struct bp_location
*loc
, *next
;
9158 gdb_assert (bpt
!= NULL
);
9160 /* Has this bp already been deleted? This can happen because multiple
9161 lists can hold pointers to bp's. bpstat lists are especial culprits.
9163 One example of this happening is a watchpoint's scope bp. When the
9164 scope bp triggers, we notice that the watchpoint is out of scope, and
9165 delete it. We also delete its scope bp. But the scope bp is marked
9166 "auto-deleting", and is already on a bpstat. That bpstat is then
9167 checked for auto-deleting bp's, which are deleted.
9169 A real solution to this problem might involve reference counts in bp's,
9170 and/or giving them pointers back to their referencing bpstat's, and
9171 teaching delete_breakpoint to only free a bp's storage when no more
9172 references were extent. A cheaper bandaid was chosen. */
9173 if (bpt
->type
== bp_none
)
9176 /* At least avoid this stale reference until the reference counting of
9177 breakpoints gets resolved. */
9178 if (bpt
->related_breakpoint
!= NULL
)
9180 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9181 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9182 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9183 bpt
->related_breakpoint
= NULL
;
9186 observer_notify_breakpoint_deleted (bpt
->number
);
9188 if (breakpoint_chain
== bpt
)
9189 breakpoint_chain
= bpt
->next
;
9194 b
->next
= bpt
->next
;
9198 decref_counted_command_line (&bpt
->commands
);
9199 xfree (bpt
->cond_string
);
9200 xfree (bpt
->cond_exp
);
9201 xfree (bpt
->addr_string
);
9203 xfree (bpt
->exp_string
);
9204 value_free (bpt
->val
);
9205 xfree (bpt
->source_file
);
9206 xfree (bpt
->exec_pathname
);
9207 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9209 /* Be sure no bpstat's are pointing at it after it's been freed. */
9210 /* FIXME, how can we find all bpstat's?
9211 We just check stop_bpstat for now. Note that we cannot just
9212 remove bpstats pointing at bpt from the stop_bpstat list
9213 entirely, as breakpoint commands are associated with the bpstat;
9214 if we remove it here, then the later call to
9215 bpstat_do_actions (&stop_bpstat);
9216 in event-top.c won't do anything, and temporary breakpoints
9217 with commands won't work. */
9219 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9221 /* Now that breakpoint is removed from breakpoint
9222 list, update the global location list. This
9223 will remove locations that used to belong to
9224 this breakpoint. Do this before freeing
9225 the breakpoint itself, since remove_breakpoint
9226 looks at location's owner. It might be better
9227 design to have location completely self-contained,
9228 but it's not the case now. */
9229 update_global_location_list (0);
9232 /* On the chance that someone will soon try again to delete this same
9233 bp, we mark it as deleted before freeing its storage. */
9234 bpt
->type
= bp_none
;
9240 do_delete_breakpoint_cleanup (void *b
)
9242 delete_breakpoint (b
);
9246 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9248 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9251 /* A callback for map_breakpoint_numbers that calls
9252 delete_breakpoint. */
9255 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9257 delete_breakpoint (b
);
9261 delete_command (char *arg
, int from_tty
)
9263 struct breakpoint
*b
, *temp
;
9269 int breaks_to_delete
= 0;
9271 /* Delete all breakpoints if no argument.
9272 Do not delete internal or call-dummy breakpoints, these
9273 have to be deleted with an explicit breakpoint number argument. */
9276 if (b
->type
!= bp_call_dummy
9277 && b
->type
!= bp_std_terminate
9278 && b
->type
!= bp_shlib_event
9279 && b
->type
!= bp_jit_event
9280 && b
->type
!= bp_thread_event
9281 && b
->type
!= bp_overlay_event
9282 && b
->type
!= bp_longjmp_master
9283 && b
->type
!= bp_std_terminate_master
9286 breaks_to_delete
= 1;
9291 /* Ask user only if there are some breakpoints to delete. */
9293 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9295 ALL_BREAKPOINTS_SAFE (b
, temp
)
9297 if (b
->type
!= bp_call_dummy
9298 && b
->type
!= bp_std_terminate
9299 && b
->type
!= bp_shlib_event
9300 && b
->type
!= bp_thread_event
9301 && b
->type
!= bp_jit_event
9302 && b
->type
!= bp_overlay_event
9303 && b
->type
!= bp_longjmp_master
9304 && b
->type
!= bp_std_terminate_master
9306 delete_breakpoint (b
);
9311 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9315 all_locations_are_pending (struct bp_location
*loc
)
9317 for (; loc
; loc
= loc
->next
)
9318 if (!loc
->shlib_disabled
)
9323 /* Subroutine of update_breakpoint_locations to simplify it.
9324 Return non-zero if multiple fns in list LOC have the same name.
9325 Null names are ignored. */
9328 ambiguous_names_p (struct bp_location
*loc
)
9330 struct bp_location
*l
;
9331 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9332 (int (*) (const void *, const void *)) streq
,
9333 NULL
, xcalloc
, xfree
);
9335 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9338 const char *name
= l
->function_name
;
9340 /* Allow for some names to be NULL, ignore them. */
9344 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9346 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9361 update_breakpoint_locations (struct breakpoint
*b
,
9362 struct symtabs_and_lines sals
)
9366 struct bp_location
*existing_locations
= b
->loc
;
9368 /* If there's no new locations, and all existing locations
9369 are pending, don't do anything. This optimizes
9370 the common case where all locations are in the same
9371 shared library, that was unloaded. We'd like to
9372 retain the location, so that when the library
9373 is loaded again, we don't loose the enabled/disabled
9374 status of the individual locations. */
9375 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9380 for (i
= 0; i
< sals
.nelts
; ++i
)
9382 struct bp_location
*new_loc
=
9383 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9385 /* Reparse conditions, they might contain references to the
9387 if (b
->cond_string
!= NULL
)
9389 struct gdb_exception e
;
9392 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9394 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9399 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9400 b
->number
, e
.message
);
9401 new_loc
->enabled
= 0;
9405 if (b
->source_file
!= NULL
)
9406 xfree (b
->source_file
);
9407 if (sals
.sals
[i
].symtab
== NULL
)
9408 b
->source_file
= NULL
;
9410 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9412 if (b
->line_number
== 0)
9413 b
->line_number
= sals
.sals
[i
].line
;
9416 /* Update locations of permanent breakpoints. */
9417 if (b
->enable_state
== bp_permanent
)
9418 make_breakpoint_permanent (b
);
9420 /* If possible, carry over 'disable' status from existing breakpoints. */
9422 struct bp_location
*e
= existing_locations
;
9423 /* If there are multiple breakpoints with the same function name,
9424 e.g. for inline functions, comparing function names won't work.
9425 Instead compare pc addresses; this is just a heuristic as things
9426 may have moved, but in practice it gives the correct answer
9427 often enough until a better solution is found. */
9428 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9430 for (; e
; e
= e
->next
)
9432 if (!e
->enabled
&& e
->function_name
)
9434 struct bp_location
*l
= b
->loc
;
9435 if (have_ambiguous_names
)
9437 for (; l
; l
= l
->next
)
9438 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9439 l
->pspace
->aspace
, l
->address
))
9447 for (; l
; l
= l
->next
)
9448 if (l
->function_name
9449 && strcmp (e
->function_name
, l
->function_name
) == 0)
9459 update_global_location_list (1);
9463 /* Reset a breakpoint given it's struct breakpoint * BINT.
9464 The value we return ends up being the return value from catch_errors.
9465 Unused in this case. */
9468 breakpoint_re_set_one (void *bint
)
9470 /* get past catch_errs */
9471 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9475 int *not_found_ptr
= ¬_found
;
9476 struct symtabs_and_lines sals
= {0};
9477 struct symtabs_and_lines expanded
= {0};
9479 enum enable_state save_enable
;
9480 struct gdb_exception e
;
9481 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9486 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9490 case bp_hardware_breakpoint
:
9492 case bp_fast_tracepoint
:
9493 /* Do not attempt to re-set breakpoints disabled during startup. */
9494 if (b
->enable_state
== bp_startup_disabled
)
9497 if (b
->addr_string
== NULL
)
9499 /* Anything without a string can't be re-set. */
9500 delete_breakpoint (b
);
9504 set_language (b
->language
);
9505 input_radix
= b
->input_radix
;
9508 save_current_space_and_thread ();
9509 switch_to_program_space_and_thread (b
->pspace
);
9511 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9513 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9518 int not_found_and_ok
= 0;
9519 /* For pending breakpoints, it's expected that parsing
9520 will fail until the right shared library is loaded.
9521 User has already told to create pending breakpoints and
9522 don't need extra messages. If breakpoint is in bp_shlib_disabled
9523 state, then user already saw the message about that breakpoint
9524 being disabled, and don't want to see more errors. */
9526 && (b
->condition_not_parsed
9527 || (b
->loc
&& b
->loc
->shlib_disabled
)
9528 || b
->enable_state
== bp_disabled
))
9529 not_found_and_ok
= 1;
9531 if (!not_found_and_ok
)
9533 /* We surely don't want to warn about the same breakpoint
9534 10 times. One solution, implemented here, is disable
9535 the breakpoint on error. Another solution would be to
9536 have separate 'warning emitted' flag. Since this
9537 happens only when a binary has changed, I don't know
9538 which approach is better. */
9539 b
->enable_state
= bp_disabled
;
9540 throw_exception (e
);
9546 gdb_assert (sals
.nelts
== 1);
9548 resolve_sal_pc (&sals
.sals
[0]);
9549 if (b
->condition_not_parsed
&& s
&& s
[0])
9551 char *cond_string
= 0;
9555 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9556 &cond_string
, &thread
, &task
);
9558 b
->cond_string
= cond_string
;
9561 b
->condition_not_parsed
= 0;
9564 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9567 make_cleanup (xfree
, sals
.sals
);
9568 update_breakpoint_locations (b
, expanded
);
9572 case bp_hardware_watchpoint
:
9573 case bp_read_watchpoint
:
9574 case bp_access_watchpoint
:
9575 /* Watchpoint can be either on expression using entirely global variables,
9576 or it can be on local variables.
9578 Watchpoints of the first kind are never auto-deleted, and even persist
9579 across program restarts. Since they can use variables from shared
9580 libraries, we need to reparse expression as libraries are loaded
9583 Watchpoints on local variables can also change meaning as result
9584 of solib event. For example, if a watchpoint uses both a local and
9585 a global variables in expression, it's a local watchpoint, but
9586 unloading of a shared library will make the expression invalid.
9587 This is not a very common use case, but we still re-evaluate
9588 expression, to avoid surprises to the user.
9590 Note that for local watchpoints, we re-evaluate it only if
9591 watchpoints frame id is still valid. If it's not, it means
9592 the watchpoint is out of scope and will be deleted soon. In fact,
9593 I'm not sure we'll ever be called in this case.
9595 If a local watchpoint's frame id is still valid, then
9596 b->exp_valid_block is likewise valid, and we can safely use it.
9598 Don't do anything about disabled watchpoints, since they will
9599 be reevaluated again when enabled. */
9600 update_watchpoint (b
, 1 /* reparse */);
9602 /* We needn't really do anything to reset these, since the mask
9603 that requests them is unaffected by e.g., new libraries being
9609 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9611 /* Delete overlay event and longjmp master breakpoints; they will be
9612 reset later by breakpoint_re_set. */
9613 case bp_overlay_event
:
9614 case bp_longjmp_master
:
9615 case bp_std_terminate_master
:
9616 delete_breakpoint (b
);
9619 /* This breakpoint is special, it's set up when the inferior
9620 starts and we really don't want to touch it. */
9621 case bp_shlib_event
:
9623 /* Like bp_shlib_event, this breakpoint type is special.
9624 Once it is set up, we do not want to touch it. */
9625 case bp_thread_event
:
9627 /* Keep temporary breakpoints, which can be encountered when we step
9628 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9629 Otherwise these should have been blown away via the cleanup chain
9630 or by breakpoint_init_inferior when we rerun the executable. */
9633 case bp_watchpoint_scope
:
9635 case bp_std_terminate
:
9636 case bp_step_resume
:
9638 case bp_longjmp_resume
:
9643 do_cleanups (cleanups
);
9647 /* Re-set all breakpoints after symbols have been re-loaded. */
9649 breakpoint_re_set (void)
9651 struct breakpoint
*b
, *temp
;
9652 enum language save_language
;
9653 int save_input_radix
;
9654 struct cleanup
*old_chain
;
9656 save_language
= current_language
->la_language
;
9657 save_input_radix
= input_radix
;
9658 old_chain
= save_current_program_space ();
9660 ALL_BREAKPOINTS_SAFE (b
, temp
)
9662 /* Format possible error msg */
9663 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9665 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9666 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9667 do_cleanups (cleanups
);
9669 set_language (save_language
);
9670 input_radix
= save_input_radix
;
9672 jit_breakpoint_re_set ();
9674 do_cleanups (old_chain
);
9676 create_overlay_event_breakpoint ("_ovly_debug_event");
9677 create_longjmp_master_breakpoint ("longjmp");
9678 create_longjmp_master_breakpoint ("_longjmp");
9679 create_longjmp_master_breakpoint ("siglongjmp");
9680 create_longjmp_master_breakpoint ("_siglongjmp");
9681 create_std_terminate_master_breakpoint ("std::terminate()");
9684 /* Reset the thread number of this breakpoint:
9686 - If the breakpoint is for all threads, leave it as-is.
9687 - Else, reset it to the current thread for inferior_ptid. */
9689 breakpoint_re_set_thread (struct breakpoint
*b
)
9691 if (b
->thread
!= -1)
9693 if (in_thread_list (inferior_ptid
))
9694 b
->thread
= pid_to_thread_id (inferior_ptid
);
9696 /* We're being called after following a fork. The new fork is
9697 selected as current, and unless this was a vfork will have a
9698 different program space from the original thread. Reset that
9700 b
->loc
->pspace
= current_program_space
;
9704 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9705 If from_tty is nonzero, it prints a message to that effect,
9706 which ends with a period (no newline). */
9709 set_ignore_count (int bptnum
, int count
, int from_tty
)
9711 struct breakpoint
*b
;
9717 if (b
->number
== bptnum
)
9719 b
->ignore_count
= count
;
9723 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9725 else if (count
== 1)
9726 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9729 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9732 breakpoints_changed ();
9733 observer_notify_breakpoint_modified (b
->number
);
9737 error (_("No breakpoint number %d."), bptnum
);
9741 make_breakpoint_silent (struct breakpoint
*b
)
9743 /* Silence the breakpoint. */
9747 /* Command to set ignore-count of breakpoint N to COUNT. */
9750 ignore_command (char *args
, int from_tty
)
9756 error_no_arg (_("a breakpoint number"));
9758 num
= get_number (&p
);
9760 error (_("bad breakpoint number: '%s'"), args
);
9762 error (_("Second argument (specified ignore-count) is missing."));
9764 set_ignore_count (num
,
9765 longest_to_int (value_as_long (parse_and_eval (p
))),
9768 printf_filtered ("\n");
9771 /* Call FUNCTION on each of the breakpoints
9772 whose numbers are given in ARGS. */
9775 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9782 struct breakpoint
*b
, *tmp
;
9786 error_no_arg (_("one or more breakpoint numbers"));
9793 num
= get_number_or_range (&p1
);
9796 warning (_("bad breakpoint number at or near '%s'"), p
);
9800 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9801 if (b
->number
== num
)
9803 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9806 if (related_breakpoint
)
9807 function (related_breakpoint
, data
);
9811 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9817 static struct bp_location
*
9818 find_location_by_number (char *number
)
9820 char *dot
= strchr (number
, '.');
9824 struct breakpoint
*b
;
9825 struct bp_location
*loc
;
9830 bp_num
= get_number_or_range (&p1
);
9832 error (_("Bad breakpoint number '%s'"), number
);
9835 if (b
->number
== bp_num
)
9840 if (!b
|| b
->number
!= bp_num
)
9841 error (_("Bad breakpoint number '%s'"), number
);
9844 loc_num
= get_number_or_range (&p1
);
9846 error (_("Bad breakpoint location number '%s'"), number
);
9850 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9853 error (_("Bad breakpoint location number '%s'"), dot
+1);
9859 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9860 If from_tty is nonzero, it prints a message to that effect,
9861 which ends with a period (no newline). */
9864 disable_breakpoint (struct breakpoint
*bpt
)
9866 /* Never disable a watchpoint scope breakpoint; we want to
9867 hit them when we leave scope so we can delete both the
9868 watchpoint and its scope breakpoint at that time. */
9869 if (bpt
->type
== bp_watchpoint_scope
)
9872 /* You can't disable permanent breakpoints. */
9873 if (bpt
->enable_state
== bp_permanent
)
9876 bpt
->enable_state
= bp_disabled
;
9878 update_global_location_list (0);
9880 observer_notify_breakpoint_modified (bpt
->number
);
9883 /* A callback for map_breakpoint_numbers that calls
9884 disable_breakpoint. */
9887 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9889 disable_breakpoint (b
);
9893 disable_command (char *args
, int from_tty
)
9895 struct breakpoint
*bpt
;
9897 ALL_BREAKPOINTS (bpt
)
9901 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9906 case bp_fast_tracepoint
:
9908 case bp_hardware_breakpoint
:
9910 case bp_hardware_watchpoint
:
9911 case bp_read_watchpoint
:
9912 case bp_access_watchpoint
:
9913 disable_breakpoint (bpt
);
9917 else if (strchr (args
, '.'))
9919 struct bp_location
*loc
= find_location_by_number (args
);
9922 update_global_location_list (0);
9925 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
9929 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9931 int target_resources_ok
, other_type_used
;
9934 if (bpt
->type
== bp_hardware_breakpoint
)
9937 i
= hw_breakpoint_used_count ();
9938 target_resources_ok
=
9939 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9941 if (target_resources_ok
== 0)
9942 error (_("No hardware breakpoint support in the target."));
9943 else if (target_resources_ok
< 0)
9944 error (_("Hardware breakpoints used exceeds limit."));
9947 if (bpt
->type
== bp_watchpoint
9948 || bpt
->type
== bp_hardware_watchpoint
9949 || bpt
->type
== bp_read_watchpoint
9950 || bpt
->type
== bp_access_watchpoint
)
9952 struct gdb_exception e
;
9954 TRY_CATCH (e
, RETURN_MASK_ALL
)
9956 update_watchpoint (bpt
, 1 /* reparse */);
9960 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9966 if (bpt
->enable_state
!= bp_permanent
)
9967 bpt
->enable_state
= bp_enabled
;
9968 bpt
->disposition
= disposition
;
9969 update_global_location_list (1);
9970 breakpoints_changed ();
9972 observer_notify_breakpoint_modified (bpt
->number
);
9977 enable_breakpoint (struct breakpoint
*bpt
)
9979 do_enable_breakpoint (bpt
, bpt
->disposition
);
9982 /* A callback for map_breakpoint_numbers that calls
9983 enable_breakpoint. */
9986 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
9988 enable_breakpoint (b
);
9991 /* The enable command enables the specified breakpoints (or all defined
9992 breakpoints) so they once again become (or continue to be) effective
9993 in stopping the inferior. */
9996 enable_command (char *args
, int from_tty
)
9998 struct breakpoint
*bpt
;
10000 ALL_BREAKPOINTS (bpt
)
10004 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10007 case bp_breakpoint
:
10008 case bp_tracepoint
:
10009 case bp_fast_tracepoint
:
10010 case bp_catchpoint
:
10011 case bp_hardware_breakpoint
:
10012 case bp_watchpoint
:
10013 case bp_hardware_watchpoint
:
10014 case bp_read_watchpoint
:
10015 case bp_access_watchpoint
:
10016 enable_breakpoint (bpt
);
10020 else if (strchr (args
, '.'))
10022 struct bp_location
*loc
= find_location_by_number (args
);
10025 update_global_location_list (1);
10028 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10032 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10034 do_enable_breakpoint (bpt
, disp_disable
);
10038 enable_once_command (char *args
, int from_tty
)
10040 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10044 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10046 do_enable_breakpoint (bpt
, disp_del
);
10050 enable_delete_command (char *args
, int from_tty
)
10052 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10056 set_breakpoint_cmd (char *args
, int from_tty
)
10061 show_breakpoint_cmd (char *args
, int from_tty
)
10065 /* Invalidate last known value of any hardware watchpoint if
10066 the memory which that value represents has been written to by
10070 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10071 const bfd_byte
*data
)
10073 struct breakpoint
*bp
;
10075 ALL_BREAKPOINTS (bp
)
10076 if (bp
->enable_state
== bp_enabled
10077 && bp
->type
== bp_hardware_watchpoint
10078 && bp
->val_valid
&& bp
->val
)
10080 struct bp_location
*loc
;
10082 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10083 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10084 && loc
->address
+ loc
->length
> addr
10085 && addr
+ len
> loc
->address
)
10087 value_free (bp
->val
);
10094 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10096 struct symtabs_and_lines
10097 decode_line_spec_1 (char *string
, int funfirstline
)
10099 struct symtabs_and_lines sals
;
10101 error (_("Empty line specification."));
10102 if (default_breakpoint_valid
)
10103 sals
= decode_line_1 (&string
, funfirstline
,
10104 default_breakpoint_symtab
,
10105 default_breakpoint_line
,
10106 (char ***) NULL
, NULL
);
10108 sals
= decode_line_1 (&string
, funfirstline
,
10109 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10111 error (_("Junk at end of line specification: %s"), string
);
10115 /* Create and insert a raw software breakpoint at PC. Return an
10116 identifier, which should be used to remove the breakpoint later.
10117 In general, places which call this should be using something on the
10118 breakpoint chain instead; this function should be eliminated
10122 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10123 struct address_space
*aspace
, CORE_ADDR pc
)
10125 struct bp_target_info
*bp_tgt
;
10127 bp_tgt
= XZALLOC (struct bp_target_info
);
10129 bp_tgt
->placed_address_space
= aspace
;
10130 bp_tgt
->placed_address
= pc
;
10132 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10134 /* Could not insert the breakpoint. */
10142 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10145 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10147 struct bp_target_info
*bp_tgt
= bp
;
10150 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10156 /* One (or perhaps two) breakpoints used for software single stepping. */
10158 static void *single_step_breakpoints
[2];
10159 static struct gdbarch
*single_step_gdbarch
[2];
10161 /* Create and insert a breakpoint for software single step. */
10164 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10165 struct address_space
*aspace
, CORE_ADDR next_pc
)
10169 if (single_step_breakpoints
[0] == NULL
)
10171 bpt_p
= &single_step_breakpoints
[0];
10172 single_step_gdbarch
[0] = gdbarch
;
10176 gdb_assert (single_step_breakpoints
[1] == NULL
);
10177 bpt_p
= &single_step_breakpoints
[1];
10178 single_step_gdbarch
[1] = gdbarch
;
10181 /* NOTE drow/2006-04-11: A future improvement to this function would be
10182 to only create the breakpoints once, and actually put them on the
10183 breakpoint chain. That would let us use set_raw_breakpoint. We could
10184 adjust the addresses each time they were needed. Doing this requires
10185 corresponding changes elsewhere where single step breakpoints are
10186 handled, however. So, for now, we use this. */
10188 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10189 if (*bpt_p
== NULL
)
10190 error (_("Could not insert single-step breakpoint at %s"),
10191 paddress (gdbarch
, next_pc
));
10194 /* Remove and delete any breakpoints used for software single step. */
10197 remove_single_step_breakpoints (void)
10199 gdb_assert (single_step_breakpoints
[0] != NULL
);
10201 /* See insert_single_step_breakpoint for more about this deprecated
10203 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10204 single_step_breakpoints
[0]);
10205 single_step_gdbarch
[0] = NULL
;
10206 single_step_breakpoints
[0] = NULL
;
10208 if (single_step_breakpoints
[1] != NULL
)
10210 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10211 single_step_breakpoints
[1]);
10212 single_step_gdbarch
[1] = NULL
;
10213 single_step_breakpoints
[1] = NULL
;
10217 /* Check whether a software single-step breakpoint is inserted at PC. */
10220 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10224 for (i
= 0; i
< 2; i
++)
10226 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10228 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10229 bp_tgt
->placed_address
,
10237 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10238 non-zero otherwise. */
10240 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10242 if (syscall_catchpoint_p (bp
)
10243 && bp
->enable_state
!= bp_disabled
10244 && bp
->enable_state
!= bp_call_disabled
)
10251 catch_syscall_enabled (void)
10253 struct inferior
*inf
= current_inferior ();
10255 return inf
->total_syscalls_count
!= 0;
10259 catching_syscall_number (int syscall_number
)
10261 struct breakpoint
*bp
;
10263 ALL_BREAKPOINTS (bp
)
10264 if (is_syscall_catchpoint_enabled (bp
))
10266 if (bp
->syscalls_to_be_caught
)
10270 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10272 if (syscall_number
== iter
)
10282 /* Complete syscall names. Used by "catch syscall". */
10284 catch_syscall_completer (struct cmd_list_element
*cmd
,
10285 char *text
, char *word
)
10287 const char **list
= get_syscall_names ();
10288 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10291 /* Tracepoint-specific operations. */
10293 /* Set tracepoint count to NUM. */
10295 set_tracepoint_count (int num
)
10297 tracepoint_count
= num
;
10298 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10302 trace_command (char *arg
, int from_tty
)
10304 if (create_breakpoint (get_current_arch (),
10306 NULL
, 0, 1 /* parse arg */,
10307 0 /* tempflag */, 0 /* hardwareflag */,
10309 0 /* Ignore count */,
10310 pending_break_support
,
10314 set_tracepoint_count (breakpoint_count
);
10318 ftrace_command (char *arg
, int from_tty
)
10320 if (create_breakpoint (get_current_arch (),
10322 NULL
, 0, 1 /* parse arg */,
10323 0 /* tempflag */, 1 /* hardwareflag */,
10325 0 /* Ignore count */,
10326 pending_break_support
,
10330 set_tracepoint_count (breakpoint_count
);
10333 /* Set up a fake reader function that gets command lines from a linked
10334 list that was acquired during tracepoint uploading. */
10336 static struct uploaded_tp
*this_utp
;
10337 static struct uploaded_string
*next_cmd
;
10340 read_uploaded_action (void)
10347 rslt
= next_cmd
->str
;
10348 next_cmd
= next_cmd
->next
;
10353 /* Given information about a tracepoint as recorded on a target (which
10354 can be either a live system or a trace file), attempt to create an
10355 equivalent GDB tracepoint. This is not a reliable process, since
10356 the target does not necessarily have all the information used when
10357 the tracepoint was originally defined. */
10359 struct breakpoint
*
10360 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10362 char *addr_str
, small_buf
[100];
10363 struct breakpoint
*tp
;
10365 if (utp
->at_string
)
10366 addr_str
= utp
->at_string
;
10369 /* In the absence of a source location, fall back to raw
10370 address. Since there is no way to confirm that the address
10371 means the same thing as when the trace was started, warn the
10373 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10375 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
10376 addr_str
= small_buf
;
10379 /* There's not much we can do with a sequence of bytecodes. */
10380 if (utp
->cond
&& !utp
->cond_string
)
10381 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10384 if (!create_breakpoint (get_current_arch (),
10386 utp
->cond_string
, -1, 0 /* parse cond/thread */,
10388 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10390 0 /* Ignore count */,
10391 pending_break_support
,
10394 utp
->enabled
/* enabled */))
10397 set_tracepoint_count (breakpoint_count
);
10399 /* Get the tracepoint we just created. */
10400 tp
= get_tracepoint (tracepoint_count
);
10401 gdb_assert (tp
!= NULL
);
10405 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
10407 trace_pass_command (small_buf
, 0);
10410 /* If we have uploaded versions of the original commands, set up a
10411 special-purpose "reader" function and call the usual command line
10412 reader, then pass the result to the breakpoint command-setting
10414 if (utp
->cmd_strings
)
10416 struct command_line
*cmd_list
;
10419 next_cmd
= utp
->cmd_strings
;
10421 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
10423 breakpoint_set_commands (tp
, cmd_list
);
10425 else if (utp
->numactions
> 0 || utp
->num_step_actions
> 0)
10426 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10432 /* Print information on tracepoint number TPNUM_EXP, or all if
10436 tracepoints_info (char *tpnum_exp
, int from_tty
)
10438 struct breakpoint
*b
;
10439 int tps_to_list
= 0;
10441 /* In the no-arguments case, say "No tracepoints" if none found. */
10442 if (tpnum_exp
== 0)
10444 ALL_TRACEPOINTS (b
)
10446 if (b
->number
>= 0)
10454 ui_out_message (uiout
, 0, "No tracepoints.\n");
10459 /* Otherwise be the same as "info break". */
10460 breakpoints_info (tpnum_exp
, from_tty
);
10463 /* The 'enable trace' command enables tracepoints.
10464 Not supported by all targets. */
10466 enable_trace_command (char *args
, int from_tty
)
10468 enable_command (args
, from_tty
);
10471 /* The 'disable trace' command disables tracepoints.
10472 Not supported by all targets. */
10474 disable_trace_command (char *args
, int from_tty
)
10476 disable_command (args
, from_tty
);
10479 /* Remove a tracepoint (or all if no argument) */
10481 delete_trace_command (char *arg
, int from_tty
)
10483 struct breakpoint
*b
, *temp
;
10489 int breaks_to_delete
= 0;
10491 /* Delete all breakpoints if no argument.
10492 Do not delete internal or call-dummy breakpoints, these
10493 have to be deleted with an explicit breakpoint number argument. */
10494 ALL_TRACEPOINTS (b
)
10496 if (b
->number
>= 0)
10498 breaks_to_delete
= 1;
10503 /* Ask user only if there are some breakpoints to delete. */
10505 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10507 ALL_BREAKPOINTS_SAFE (b
, temp
)
10509 if (tracepoint_type (b
)
10511 delete_breakpoint (b
);
10516 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10519 /* Set passcount for tracepoint.
10521 First command argument is passcount, second is tracepoint number.
10522 If tracepoint number omitted, apply to most recently defined.
10523 Also accepts special argument "all". */
10526 trace_pass_command (char *args
, int from_tty
)
10528 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10529 unsigned int count
;
10532 if (args
== 0 || *args
== 0)
10533 error (_("passcount command requires an argument (count + optional TP num)"));
10535 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10537 while (*args
&& isspace ((int) *args
))
10540 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10542 args
+= 3; /* Skip special argument "all". */
10545 error (_("Junk at end of arguments."));
10548 t1
= get_tracepoint_by_number (&args
, 1, 1);
10554 ALL_TRACEPOINTS (t2
)
10555 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10557 t2
->pass_count
= count
;
10558 observer_notify_tracepoint_modified (t2
->number
);
10560 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10561 t2
->number
, count
);
10563 if (! all
&& *args
)
10564 t1
= get_tracepoint_by_number (&args
, 1, 0);
10570 struct breakpoint
*
10571 get_tracepoint (int num
)
10573 struct breakpoint
*t
;
10575 ALL_TRACEPOINTS (t
)
10576 if (t
->number
== num
)
10582 /* Find the tracepoint with the given target-side number (which may be
10583 different from the tracepoint number after disconnecting and
10586 struct breakpoint
*
10587 get_tracepoint_by_number_on_target (int num
)
10589 struct breakpoint
*t
;
10591 ALL_TRACEPOINTS (t
)
10592 if (t
->number_on_target
== num
)
10598 /* Utility: parse a tracepoint number and look it up in the list.
10599 If MULTI_P is true, there might be a range of tracepoints in ARG.
10600 if OPTIONAL_P is true, then if the argument is missing, the most
10601 recent tracepoint (tracepoint_count) is returned. */
10602 struct breakpoint
*
10603 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10605 extern int tracepoint_count
;
10606 struct breakpoint
*t
;
10608 char *instring
= arg
== NULL
? NULL
: *arg
;
10610 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10613 tpnum
= tracepoint_count
;
10615 error_no_arg (_("tracepoint number"));
10618 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10622 if (instring
&& *instring
)
10623 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10626 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10630 ALL_TRACEPOINTS (t
)
10631 if (t
->number
== tpnum
)
10636 /* FIXME: if we are in the middle of a range we don't want to give
10637 a message. The current interface to get_number_or_range doesn't
10638 allow us to discover this. */
10639 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10643 /* save-tracepoints command */
10645 tracepoint_save_command (char *args
, int from_tty
)
10647 struct breakpoint
*tp
;
10649 struct command_line
*line
;
10652 struct cleanup
*cleanup
;
10653 struct ui_file
*fp
;
10655 if (args
== 0 || *args
== 0)
10656 error (_("Argument required (file name in which to save tracepoints)"));
10658 /* See if we have anything to save. */
10659 ALL_TRACEPOINTS (tp
)
10666 warning (_("save-tracepoints: no tracepoints to save."));
10670 pathname
= tilde_expand (args
);
10671 cleanup
= make_cleanup (xfree
, pathname
);
10672 fp
= gdb_fopen (pathname
, "w");
10674 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10675 args
, safe_strerror (errno
));
10676 make_cleanup_ui_file_delete (fp
);
10678 save_trace_state_variables (fp
);
10680 ALL_TRACEPOINTS (tp
)
10682 if (tp
->type
== bp_fast_tracepoint
)
10683 fprintf_unfiltered (fp
, "ftrace");
10685 fprintf_unfiltered (fp
, "trace");
10687 if (tp
->addr_string
)
10688 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10691 sprintf_vma (tmp
, tp
->loc
->address
);
10692 fprintf_unfiltered (fp
, " *0x%s", tmp
);
10695 if (tp
->cond_string
)
10696 fprintf_unfiltered (fp
, " if %s", tp
->cond_string
);
10698 fprintf_unfiltered (fp
, "\n");
10700 if (tp
->pass_count
)
10701 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10705 volatile struct gdb_exception ex
;
10707 fprintf_unfiltered (fp
, " actions\n");
10709 ui_out_redirect (uiout
, fp
);
10710 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10712 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10714 ui_out_redirect (uiout
, NULL
);
10717 throw_exception (ex
);
10719 fprintf_unfiltered (fp
, " end\n");
10723 if (*default_collect
)
10724 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
10726 do_cleanups (cleanup
);
10728 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10732 /* Create a vector of all tracepoints. */
10734 VEC(breakpoint_p
) *
10737 VEC(breakpoint_p
) *tp_vec
= 0;
10738 struct breakpoint
*tp
;
10740 ALL_TRACEPOINTS (tp
)
10742 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10749 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10750 It is defined as a macro to prevent duplication.
10751 COMMAND should be a string constant containing the name of the command. */
10752 #define BREAK_ARGS_HELP(command) \
10753 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10754 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10755 If a line number is specified, break at start of code for that line.\n\
10756 If a function is specified, break at start of code for that function.\n\
10757 If an address is specified, break at that exact address.\n\
10758 With no LOCATION, uses current execution address of selected stack frame.\n\
10759 This is useful for breaking on return to a stack frame.\n\
10761 THREADNUM is the number from \"info threads\".\n\
10762 CONDITION is a boolean expression.\n\
10764 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10766 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10768 /* List of subcommands for "catch". */
10769 static struct cmd_list_element
*catch_cmdlist
;
10771 /* List of subcommands for "tcatch". */
10772 static struct cmd_list_element
*tcatch_cmdlist
;
10774 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10775 lists, and pass some additional user data to the command function. */
10777 add_catch_command (char *name
, char *docstring
,
10778 void (*sfunc
) (char *args
, int from_tty
,
10779 struct cmd_list_element
*command
),
10780 char **(*completer
) (struct cmd_list_element
*cmd
,
10781 char *text
, char *word
),
10782 void *user_data_catch
,
10783 void *user_data_tcatch
)
10785 struct cmd_list_element
*command
;
10787 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10789 set_cmd_sfunc (command
, sfunc
);
10790 set_cmd_context (command
, user_data_catch
);
10791 set_cmd_completer (command
, completer
);
10793 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10795 set_cmd_sfunc (command
, sfunc
);
10796 set_cmd_context (command
, user_data_tcatch
);
10797 set_cmd_completer (command
, completer
);
10801 clear_syscall_counts (struct inferior
*inf
)
10803 inf
->total_syscalls_count
= 0;
10804 inf
->any_syscall_count
= 0;
10805 VEC_free (int, inf
->syscalls_counts
);
10809 _initialize_breakpoint (void)
10811 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10812 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10813 struct cmd_list_element
*c
;
10815 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10816 observer_attach_inferior_exit (clear_syscall_counts
);
10817 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10819 breakpoint_chain
= 0;
10820 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10821 before a breakpoint is set. */
10822 breakpoint_count
= 0;
10824 tracepoint_count
= 0;
10826 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10827 Set ignore-count of breakpoint number N to COUNT.\n\
10828 Usage is `ignore N COUNT'."));
10830 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10832 add_com ("commands", class_breakpoint
, commands_command
, _("\
10833 Set commands to be executed when a breakpoint is hit.\n\
10834 Give breakpoint number as argument after \"commands\".\n\
10835 With no argument, the targeted breakpoint is the last one set.\n\
10836 The commands themselves follow starting on the next line.\n\
10837 Type a line containing \"end\" to indicate the end of them.\n\
10838 Give \"silent\" as the first line to make the breakpoint silent;\n\
10839 then no output is printed when it is hit, except what the commands print."));
10841 add_com ("condition", class_breakpoint
, condition_command
, _("\
10842 Specify breakpoint number N to break only if COND is true.\n\
10843 Usage is `condition N COND', where N is an integer and COND is an\n\
10844 expression to be evaluated whenever breakpoint N is reached."));
10846 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10847 Set a temporary breakpoint.\n\
10848 Like \"break\" except the breakpoint is only temporary,\n\
10849 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10850 by using \"enable delete\" on the breakpoint number.\n\
10852 BREAK_ARGS_HELP ("tbreak")));
10853 set_cmd_completer (c
, location_completer
);
10855 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10856 Set a hardware assisted breakpoint.\n\
10857 Like \"break\" except the breakpoint requires hardware support,\n\
10858 some target hardware may not have this support.\n\
10860 BREAK_ARGS_HELP ("hbreak")));
10861 set_cmd_completer (c
, location_completer
);
10863 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10864 Set a temporary hardware assisted breakpoint.\n\
10865 Like \"hbreak\" except the breakpoint is only temporary,\n\
10866 so it will be deleted when hit.\n\
10868 BREAK_ARGS_HELP ("thbreak")));
10869 set_cmd_completer (c
, location_completer
);
10871 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10872 Enable some breakpoints.\n\
10873 Give breakpoint numbers (separated by spaces) as arguments.\n\
10874 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10875 This is used to cancel the effect of the \"disable\" command.\n\
10876 With a subcommand you can enable temporarily."),
10877 &enablelist
, "enable ", 1, &cmdlist
);
10879 add_com ("ab", class_breakpoint
, enable_command
, _("\
10880 Enable some breakpoints.\n\
10881 Give breakpoint numbers (separated by spaces) as arguments.\n\
10882 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10883 This is used to cancel the effect of the \"disable\" command.\n\
10884 With a subcommand you can enable temporarily."));
10886 add_com_alias ("en", "enable", class_breakpoint
, 1);
10888 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10889 Enable some breakpoints.\n\
10890 Give breakpoint numbers (separated by spaces) as arguments.\n\
10891 This is used to cancel the effect of the \"disable\" command.\n\
10892 May be abbreviated to simply \"enable\".\n"),
10893 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10895 add_cmd ("once", no_class
, enable_once_command
, _("\
10896 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10897 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10900 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10901 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10902 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10905 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10906 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10907 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10910 add_cmd ("once", no_class
, enable_once_command
, _("\
10911 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10912 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10915 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10916 Disable some breakpoints.\n\
10917 Arguments are breakpoint numbers with spaces in between.\n\
10918 To disable all breakpoints, give no argument.\n\
10919 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10920 &disablelist
, "disable ", 1, &cmdlist
);
10921 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10922 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10924 add_com ("sb", class_breakpoint
, disable_command
, _("\
10925 Disable some breakpoints.\n\
10926 Arguments are breakpoint numbers with spaces in between.\n\
10927 To disable all breakpoints, give no argument.\n\
10928 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10930 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10931 Disable some breakpoints.\n\
10932 Arguments are breakpoint numbers with spaces in between.\n\
10933 To disable all breakpoints, give no argument.\n\
10934 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10935 This command may be abbreviated \"disable\"."),
10938 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10939 Delete some breakpoints or auto-display expressions.\n\
10940 Arguments are breakpoint numbers with spaces in between.\n\
10941 To delete all breakpoints, give no argument.\n\
10943 Also a prefix command for deletion of other GDB objects.\n\
10944 The \"unset\" command is also an alias for \"delete\"."),
10945 &deletelist
, "delete ", 1, &cmdlist
);
10946 add_com_alias ("d", "delete", class_breakpoint
, 1);
10947 add_com_alias ("del", "delete", class_breakpoint
, 1);
10949 add_com ("db", class_breakpoint
, delete_command
, _("\
10950 Delete some breakpoints.\n\
10951 Arguments are breakpoint numbers with spaces in between.\n\
10952 To delete all breakpoints, give no argument.\n"));
10954 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10955 Delete some breakpoints or auto-display expressions.\n\
10956 Arguments are breakpoint numbers with spaces in between.\n\
10957 To delete all breakpoints, give no argument.\n\
10958 This command may be abbreviated \"delete\"."),
10961 add_com ("clear", class_breakpoint
, clear_command
, _("\
10962 Clear breakpoint at specified line or function.\n\
10963 Argument may be line number, function name, or \"*\" and an address.\n\
10964 If line number is specified, all breakpoints in that line are cleared.\n\
10965 If function is specified, breakpoints at beginning of function are cleared.\n\
10966 If an address is specified, breakpoints at that address are cleared.\n\
10968 With no argument, clears all breakpoints in the line that the selected frame\n\
10969 is executing in.\n\
10971 See also the \"delete\" command which clears breakpoints by number."));
10973 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10974 Set breakpoint at specified line or function.\n"
10975 BREAK_ARGS_HELP ("break")));
10976 set_cmd_completer (c
, location_completer
);
10978 add_com_alias ("b", "break", class_run
, 1);
10979 add_com_alias ("br", "break", class_run
, 1);
10980 add_com_alias ("bre", "break", class_run
, 1);
10981 add_com_alias ("brea", "break", class_run
, 1);
10984 add_com_alias ("ba", "break", class_breakpoint
, 1);
10988 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10989 Break in function/address or break at a line in the current file."),
10990 &stoplist
, "stop ", 1, &cmdlist
);
10991 add_cmd ("in", class_breakpoint
, stopin_command
,
10992 _("Break in function or address."), &stoplist
);
10993 add_cmd ("at", class_breakpoint
, stopat_command
,
10994 _("Break at a line in the current file."), &stoplist
);
10995 add_com ("status", class_info
, breakpoints_info
, _("\
10996 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10997 The \"Type\" column indicates one of:\n\
10998 \tbreakpoint - normal breakpoint\n\
10999 \twatchpoint - watchpoint\n\
11000 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11001 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11002 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11003 address and file/line number respectively.\n\
11005 Convenience variable \"$_\" and default examine address for \"x\"\n\
11006 are set to the address of the last breakpoint listed unless the command\n\
11007 is prefixed with \"server \".\n\n\
11008 Convenience variable \"$bpnum\" contains the number of the last\n\
11009 breakpoint set."));
11012 add_info ("breakpoints", breakpoints_info
, _("\
11013 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11014 The \"Type\" column indicates one of:\n\
11015 \tbreakpoint - normal breakpoint\n\
11016 \twatchpoint - watchpoint\n\
11017 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11018 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11019 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11020 address and file/line number respectively.\n\
11022 Convenience variable \"$_\" and default examine address for \"x\"\n\
11023 are set to the address of the last breakpoint listed unless the command\n\
11024 is prefixed with \"server \".\n\n\
11025 Convenience variable \"$bpnum\" contains the number of the last\n\
11026 breakpoint set."));
11028 add_info_alias ("b", "breakpoints", 1);
11031 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11032 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11033 The \"Type\" column indicates one of:\n\
11034 \tbreakpoint - normal breakpoint\n\
11035 \twatchpoint - watchpoint\n\
11036 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11037 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11038 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11039 address and file/line number respectively.\n\
11041 Convenience variable \"$_\" and default examine address for \"x\"\n\
11042 are set to the address of the last breakpoint listed unless the command\n\
11043 is prefixed with \"server \".\n\n\
11044 Convenience variable \"$bpnum\" contains the number of the last\n\
11045 breakpoint set."));
11047 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11048 Status of all breakpoints, or breakpoint number NUMBER.\n\
11049 The \"Type\" column indicates one of:\n\
11050 \tbreakpoint - normal breakpoint\n\
11051 \twatchpoint - watchpoint\n\
11052 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11053 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11054 \tuntil - internal breakpoint used by the \"until\" command\n\
11055 \tfinish - internal breakpoint used by the \"finish\" command\n\
11056 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11057 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11058 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11059 address and file/line number respectively.\n\
11061 Convenience variable \"$_\" and default examine address for \"x\"\n\
11062 are set to the address of the last breakpoint listed unless the command\n\
11063 is prefixed with \"server \".\n\n\
11064 Convenience variable \"$bpnum\" contains the number of the last\n\
11066 &maintenanceinfolist
);
11068 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11069 Set catchpoints to catch events."),
11070 &catch_cmdlist
, "catch ",
11071 0/*allow-unknown*/, &cmdlist
);
11073 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11074 Set temporary catchpoints to catch events."),
11075 &tcatch_cmdlist
, "tcatch ",
11076 0/*allow-unknown*/, &cmdlist
);
11078 /* Add catch and tcatch sub-commands. */
11079 add_catch_command ("catch", _("\
11080 Catch an exception, when caught.\n\
11081 With an argument, catch only exceptions with the given name."),
11082 catch_catch_command
,
11086 add_catch_command ("throw", _("\
11087 Catch an exception, when thrown.\n\
11088 With an argument, catch only exceptions with the given name."),
11089 catch_throw_command
,
11093 add_catch_command ("fork", _("Catch calls to fork."),
11094 catch_fork_command_1
,
11096 (void *) (uintptr_t) catch_fork_permanent
,
11097 (void *) (uintptr_t) catch_fork_temporary
);
11098 add_catch_command ("vfork", _("Catch calls to vfork."),
11099 catch_fork_command_1
,
11101 (void *) (uintptr_t) catch_vfork_permanent
,
11102 (void *) (uintptr_t) catch_vfork_temporary
);
11103 add_catch_command ("exec", _("Catch calls to exec."),
11104 catch_exec_command_1
,
11108 add_catch_command ("syscall", _("\
11109 Catch system calls by their names and/or numbers.\n\
11110 Arguments say which system calls to catch. If no arguments\n\
11111 are given, every system call will be caught.\n\
11112 Arguments, if given, should be one or more system call names\n\
11113 (if your system supports that), or system call numbers."),
11114 catch_syscall_command_1
,
11115 catch_syscall_completer
,
11118 add_catch_command ("exception", _("\
11119 Catch Ada exceptions, when raised.\n\
11120 With an argument, catch only exceptions with the given name."),
11121 catch_ada_exception_command
,
11125 add_catch_command ("assert", _("\
11126 Catch failed Ada assertions, when raised.\n\
11127 With an argument, catch only exceptions with the given name."),
11128 catch_assert_command
,
11133 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11134 Set a watchpoint for an expression.\n\
11135 A watchpoint stops execution of your program whenever the value of\n\
11136 an expression changes."));
11137 set_cmd_completer (c
, expression_completer
);
11139 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11140 Set a read watchpoint for an expression.\n\
11141 A watchpoint stops execution of your program whenever the value of\n\
11142 an expression is read."));
11143 set_cmd_completer (c
, expression_completer
);
11145 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11146 Set a watchpoint for an expression.\n\
11147 A watchpoint stops execution of your program whenever the value of\n\
11148 an expression is either read or written."));
11149 set_cmd_completer (c
, expression_completer
);
11151 add_info ("watchpoints", breakpoints_info
,
11152 _("Synonym for ``info breakpoints''."));
11155 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11156 respond to changes - contrary to the description. */
11157 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11158 &can_use_hw_watchpoints
, _("\
11159 Set debugger's willingness to use watchpoint hardware."), _("\
11160 Show debugger's willingness to use watchpoint hardware."), _("\
11161 If zero, gdb will not use hardware for new watchpoints, even if\n\
11162 such is available. (However, any hardware watchpoints that were\n\
11163 created before setting this to nonzero, will continue to use watchpoint\n\
11166 show_can_use_hw_watchpoints
,
11167 &setlist
, &showlist
);
11169 can_use_hw_watchpoints
= 1;
11171 /* Tracepoint manipulation commands. */
11173 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11174 Set a tracepoint at specified line or function.\n\
11176 BREAK_ARGS_HELP ("trace") "\n\
11177 Do \"help tracepoints\" for info on other tracepoint commands."));
11178 set_cmd_completer (c
, location_completer
);
11180 add_com_alias ("tp", "trace", class_alias
, 0);
11181 add_com_alias ("tr", "trace", class_alias
, 1);
11182 add_com_alias ("tra", "trace", class_alias
, 1);
11183 add_com_alias ("trac", "trace", class_alias
, 1);
11185 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11186 Set a fast tracepoint at specified line or function.\n\
11188 BREAK_ARGS_HELP ("ftrace") "\n\
11189 Do \"help tracepoints\" for info on other tracepoint commands."));
11190 set_cmd_completer (c
, location_completer
);
11192 add_info ("tracepoints", tracepoints_info
, _("\
11193 Status of tracepoints, or tracepoint number NUMBER.\n\
11194 Convenience variable \"$tpnum\" contains the number of the\n\
11195 last tracepoint set."));
11197 add_info_alias ("tp", "tracepoints", 1);
11199 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11200 Delete specified tracepoints.\n\
11201 Arguments are tracepoint numbers, separated by spaces.\n\
11202 No argument means delete all tracepoints."),
11205 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11206 Disable specified tracepoints.\n\
11207 Arguments are tracepoint numbers, separated by spaces.\n\
11208 No argument means disable all tracepoints."),
11210 deprecate_cmd (c
, "disable");
11212 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11213 Enable specified tracepoints.\n\
11214 Arguments are tracepoint numbers, separated by spaces.\n\
11215 No argument means enable all tracepoints."),
11217 deprecate_cmd (c
, "enable");
11219 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11220 Set the passcount for a tracepoint.\n\
11221 The trace will end when the tracepoint has been passed 'count' times.\n\
11222 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11223 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11225 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11226 Save current tracepoint definitions as a script.\n\
11227 Use the 'source' command in another debug session to restore them."));
11228 set_cmd_completer (c
, filename_completer
);
11230 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11231 Breakpoint specific settings\n\
11232 Configure various breakpoint-specific variables such as\n\
11233 pending breakpoint behavior"),
11234 &breakpoint_set_cmdlist
, "set breakpoint ",
11235 0/*allow-unknown*/, &setlist
);
11236 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11237 Breakpoint specific settings\n\
11238 Configure various breakpoint-specific variables such as\n\
11239 pending breakpoint behavior"),
11240 &breakpoint_show_cmdlist
, "show breakpoint ",
11241 0/*allow-unknown*/, &showlist
);
11243 add_setshow_auto_boolean_cmd ("pending", no_class
,
11244 &pending_break_support
, _("\
11245 Set debugger's behavior regarding pending breakpoints."), _("\
11246 Show debugger's behavior regarding pending breakpoints."), _("\
11247 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11248 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11249 an error. If auto, an unrecognized breakpoint location results in a\n\
11250 user-query to see if a pending breakpoint should be created."),
11252 show_pending_break_support
,
11253 &breakpoint_set_cmdlist
,
11254 &breakpoint_show_cmdlist
);
11256 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11258 add_setshow_boolean_cmd ("auto-hw", no_class
,
11259 &automatic_hardware_breakpoints
, _("\
11260 Set automatic usage of hardware breakpoints."), _("\
11261 Show automatic usage of hardware breakpoints."), _("\
11262 If set, the debugger will automatically use hardware breakpoints for\n\
11263 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11264 a warning will be emitted for such breakpoints."),
11266 show_automatic_hardware_breakpoints
,
11267 &breakpoint_set_cmdlist
,
11268 &breakpoint_show_cmdlist
);
11270 add_setshow_enum_cmd ("always-inserted", class_support
,
11271 always_inserted_enums
, &always_inserted_mode
, _("\
11272 Set mode for inserting breakpoints."), _("\
11273 Show mode for inserting breakpoints."), _("\
11274 When this mode is off, breakpoints are inserted in inferior when it is\n\
11275 resumed, and removed when execution stops. When this mode is on,\n\
11276 breakpoints are inserted immediately and removed only when the user\n\
11277 deletes the breakpoint. When this mode is auto (which is the default),\n\
11278 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11279 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11280 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11281 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11283 &show_always_inserted_mode
,
11284 &breakpoint_set_cmdlist
,
11285 &breakpoint_show_cmdlist
);
11287 automatic_hardware_breakpoints
= 1;
11289 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);