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 /* If the last command to create a breakpoint created multiple
392 breakpoints, this holds the start and end breakpoint numbers. */
393 static int multi_start
;
394 static int multi_end
;
395 /* True if the last breakpoint set was part of a group set with a
396 single command, e.g., "rbreak". */
397 static int last_was_multi
;
399 /* Number of last tracepoint made. */
401 static int tracepoint_count
;
403 /* Return whether a breakpoint is an active enabled breakpoint. */
405 breakpoint_enabled (struct breakpoint
*b
)
407 return (b
->enable_state
== bp_enabled
);
410 /* Set breakpoint count to NUM. */
413 set_breakpoint_count (int num
)
415 breakpoint_count
= num
;
417 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
420 /* Called at the start an "rbreak" command to record the first
423 start_rbreak_breakpoints (void)
425 multi_start
= breakpoint_count
+ 1;
428 /* Called at the end of an "rbreak" command to record the last
431 end_rbreak_breakpoints (void)
433 if (breakpoint_count
>= multi_start
)
435 multi_end
= 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. */
897 /* Non-NULL if the body of the commands are being read from this
898 already-parsed command. */
899 struct command_line
*control
;
900 /* The command lines read from the user, or NULL if they have not
902 struct counted_command_line
*cmd
;
905 /* A callback for map_breakpoint_numbers that sets the commands for
909 do_map_commands_command (struct breakpoint
*b
, void *data
)
911 struct commands_info
*info
= data
;
913 if (info
->cmd
== NULL
)
915 struct command_line
*l
;
917 if (info
->control
!= NULL
)
918 l
= copy_command_lines (info
->control
->body_list
[0]);
921 l
= read_command_lines (_("Type commands for all specified breakpoints"),
923 (breakpoint_is_tracepoint (b
)
924 ? check_tracepoint_command
: 0),
927 info
->cmd
= alloc_counted_command_line (l
);
930 /* If a breakpoint was on the list more than once, we don't need to
932 if (b
->commands
!= info
->cmd
)
934 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
935 incref_counted_command_line (info
->cmd
);
936 decref_counted_command_line (&b
->commands
);
937 b
->commands
= info
->cmd
;
938 breakpoints_changed ();
939 observer_notify_breakpoint_modified (b
->number
);
944 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
946 struct cleanup
*cleanups
;
947 struct commands_info info
;
949 info
.from_tty
= from_tty
;
950 info
.control
= control
;
952 /* If we read command lines from the user, then `info' will hold an
953 extra reference to the commands that we must clean up. */
954 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
956 if (arg
== NULL
|| !*arg
)
959 arg
= xstrprintf ("%d-%d", multi_start
, multi_end
);
960 else if (breakpoint_count
> 0)
961 arg
= xstrprintf ("%d", breakpoint_count
);
964 /* The command loop has some static state, so we need to preserve
967 make_cleanup (xfree
, arg
);
969 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
971 if (info
.cmd
== NULL
)
972 error (_("No breakpoints specified."));
974 do_cleanups (cleanups
);
978 commands_command (char *arg
, int from_tty
)
980 commands_command_1 (arg
, from_tty
, NULL
);
983 /* Like commands_command, but instead of reading the commands from
984 input stream, takes them from an already parsed command structure.
986 This is used by cli-script.c to DTRT with breakpoint commands
987 that are part of if and while bodies. */
988 enum command_control_type
989 commands_from_control_command (char *arg
, struct command_line
*cmd
)
991 commands_command_1 (arg
, 0, cmd
);
992 return simple_control
;
995 /* Return non-zero if BL->TARGET_INFO contains valid information. */
998 bp_location_has_shadow (struct bp_location
*bl
)
1000 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1004 if (bl
->target_info
.shadow_len
== 0)
1005 /* bp isn't valid, or doesn't shadow memory. */
1010 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1011 by replacing any memory breakpoints with their shadowed contents.
1013 The range of shadowed area by each bp_location is:
1014 b->address - bp_location_placed_address_before_address_max
1015 up to b->address + bp_location_shadow_len_after_address_max
1016 The range we were requested to resolve shadows for is:
1017 memaddr ... memaddr + len
1018 Thus the safe cutoff boundaries for performance optimization are
1019 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1021 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1024 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1026 /* Left boundary, right boundary and median element of our binary search. */
1027 unsigned bc_l
, bc_r
, bc
;
1029 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1030 safe to report lower value but a failure to report higher one. */
1033 bc_r
= bp_location_count
;
1034 while (bc_l
+ 1 < bc_r
)
1036 struct bp_location
*b
;
1038 bc
= (bc_l
+ bc_r
) / 2;
1039 b
= bp_location
[bc
];
1041 /* Check first B->ADDRESS will not overflow due to the added constant.
1042 Then advance the left boundary only if we are sure the BC element can
1043 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1045 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1046 we cannot miss a breakpoint with its shadow range tail still reaching
1049 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1050 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1056 /* Now do full processing of the found relevant range of elements. */
1058 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1060 struct bp_location
*b
= bp_location
[bc
];
1061 CORE_ADDR bp_addr
= 0;
1065 if (b
->owner
->type
== bp_none
)
1066 warning (_("reading through apparently deleted breakpoint #%d?"),
1069 /* Performance optimization: any futher element can no longer affect BUF
1072 if (b
->address
>= bp_location_placed_address_before_address_max
1073 && memaddr
+ len
<= b
->address
1074 - bp_location_placed_address_before_address_max
)
1077 if (!bp_location_has_shadow (b
))
1079 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1080 current_program_space
->aspace
, 0))
1083 /* Addresses and length of the part of the breakpoint that
1085 bp_addr
= b
->target_info
.placed_address
;
1086 bp_size
= b
->target_info
.shadow_len
;
1088 if (bp_addr
+ bp_size
<= memaddr
)
1089 /* The breakpoint is entirely before the chunk of memory we
1093 if (bp_addr
>= memaddr
+ len
)
1094 /* The breakpoint is entirely after the chunk of memory we are
1098 /* Offset within shadow_contents. */
1099 if (bp_addr
< memaddr
)
1101 /* Only copy the second part of the breakpoint. */
1102 bp_size
-= memaddr
- bp_addr
;
1103 bptoffset
= memaddr
- bp_addr
;
1107 if (bp_addr
+ bp_size
> memaddr
+ len
)
1109 /* Only copy the first part of the breakpoint. */
1110 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1113 memcpy (buf
+ bp_addr
- memaddr
,
1114 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1119 /* A wrapper function for inserting catchpoints. */
1121 insert_catchpoint (struct ui_out
*uo
, void *args
)
1123 struct breakpoint
*b
= (struct breakpoint
*) args
;
1126 gdb_assert (b
->type
== bp_catchpoint
);
1127 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1132 /* Return true if BPT is of any hardware watchpoint kind. */
1135 is_hardware_watchpoint (struct breakpoint
*bpt
)
1137 return (bpt
->type
== bp_hardware_watchpoint
1138 || bpt
->type
== bp_read_watchpoint
1139 || bpt
->type
== bp_access_watchpoint
);
1142 /* Return true if BPT is of any watchpoint kind, hardware or
1146 is_watchpoint (struct breakpoint
*bpt
)
1148 return (is_hardware_watchpoint (bpt
)
1149 || bpt
->type
== bp_watchpoint
);
1152 /* Find the current value of a watchpoint on EXP. Return the value in
1153 *VALP and *RESULTP and the chain of intermediate and final values
1154 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1157 If a memory error occurs while evaluating the expression, *RESULTP will
1158 be set to NULL. *RESULTP may be a lazy value, if the result could
1159 not be read from memory. It is used to determine whether a value
1160 is user-specified (we should watch the whole value) or intermediate
1161 (we should watch only the bit used to locate the final value).
1163 If the final value, or any intermediate value, could not be read
1164 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1165 set to any referenced values. *VALP will never be a lazy value.
1166 This is the value which we store in struct breakpoint.
1168 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1169 value chain. The caller must free the values individually. If
1170 VAL_CHAIN is NULL, all generated values will be left on the value
1174 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1175 struct value
**resultp
, struct value
**val_chain
)
1177 struct value
*mark
, *new_mark
, *result
;
1178 volatile struct gdb_exception ex
;
1186 /* Evaluate the expression. */
1187 mark
= value_mark ();
1190 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1192 result
= evaluate_expression (exp
);
1196 /* Ignore memory errors, we want watchpoints pointing at
1197 inaccessible memory to still be created; otherwise, throw the
1198 error to some higher catcher. */
1204 throw_exception (ex
);
1209 new_mark
= value_mark ();
1210 if (mark
== new_mark
)
1215 /* Make sure it's not lazy, so that after the target stops again we
1216 have a non-lazy previous value to compare with. */
1218 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1223 /* Return the chain of intermediate values. We use this to
1224 decide which addresses to watch. */
1225 *val_chain
= new_mark
;
1226 value_release_to_mark (mark
);
1230 /* Assuming that B is a watchpoint: returns true if the current thread
1231 and its running state are safe to evaluate or update watchpoint B.
1232 Watchpoints on local expressions need to be evaluated in the
1233 context of the thread that was current when the watchpoint was
1234 created, and, that thread needs to be stopped to be able to select
1235 the correct frame context. Watchpoints on global expressions can
1236 be evaluated on any thread, and in any state. It is presently left
1237 to the target allowing memory accesses when threads are
1241 watchpoint_in_thread_scope (struct breakpoint
*b
)
1243 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1244 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1245 && !is_executing (inferior_ptid
)));
1248 /* Assuming that B is a watchpoint:
1249 - Reparse watchpoint expression, if REPARSE is non-zero
1250 - Evaluate expression and store the result in B->val
1251 - Evaluate the condition if there is one, and store the result
1253 - Update the list of values that must be watched in B->loc.
1255 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1256 If this is local watchpoint that is out of scope, delete it.
1258 Even with `set breakpoint always-inserted on' the watchpoints are removed
1259 + inserted on each stop here. Normal breakpoints must never be removed
1260 because they might be missed by a running thread when debugging in non-stop
1261 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1262 processed here) are specific to each LWP since they are stored in each LWP's
1263 hardware debug registers. Therefore, such LWP must be stopped first in
1264 order to be able to modify its hardware watchpoints.
1266 Hardware watchpoints must be reset exactly once after being presented to the
1267 user. It cannot be done sooner, because it would reset the data used to
1268 present the watchpoint hit to the user. And it must not be done later
1269 because it could display the same single watchpoint hit during multiple GDB
1270 stops. Note that the latter is relevant only to the hardware watchpoint
1271 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1272 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1273 memory content has not changed.
1275 The following constraints influence the location where we can reset hardware
1278 * target_stopped_by_watchpoint and target_stopped_data_address are called
1279 several times when GDB stops.
1282 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1283 stop. GDB only presents one hardware watchpoint hit at a time as the
1284 reason for stopping, and all the other hits are presented later, one after
1285 the other, each time the user requests the execution to be resumed.
1286 Execution is not resumed for the threads still having pending hit event
1287 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1288 the inferior on the first stop the thread hit event is kept being reported
1289 from its cached value by linux_nat_stopped_data_address until the real
1290 thread resume happens after the watchpoint gets presented and thus its
1291 LWP_INFO->STATUS gets reset.
1293 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1294 removal from inferior. */
1297 update_watchpoint (struct breakpoint
*b
, int reparse
)
1299 int within_current_scope
;
1300 struct frame_id saved_frame_id
;
1301 struct bp_location
*loc
;
1305 /* If this is a local watchpoint, we only want to check if the
1306 watchpoint frame is in scope if the current thread is the thread
1307 that was used to create the watchpoint. */
1308 if (!watchpoint_in_thread_scope (b
))
1311 /* We don't free locations. They are stored in bp_location array and
1312 update_global_locations will eventually delete them and remove
1313 breakpoints if needed. */
1316 if (b
->disposition
== disp_del_at_next_stop
)
1321 /* Determine if the watchpoint is within scope. */
1322 if (b
->exp_valid_block
== NULL
)
1323 within_current_scope
= 1;
1326 struct frame_info
*fi
;
1328 /* Save the current frame's ID so we can restore it after
1329 evaluating the watchpoint expression on its own frame. */
1330 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1331 took a frame parameter, so that we didn't have to change the
1334 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1336 fi
= frame_find_by_id (b
->watchpoint_frame
);
1337 within_current_scope
= (fi
!= NULL
);
1338 if (within_current_scope
)
1342 if (within_current_scope
&& reparse
)
1351 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1352 /* If the meaning of expression itself changed, the old value is
1353 no longer relevant. We don't want to report a watchpoint hit
1354 to the user when the old value and the new value may actually
1355 be completely different objects. */
1356 value_free (b
->val
);
1360 /* Note that unlike with breakpoints, the watchpoint's condition
1361 expression is stored in the breakpoint object, not in the
1362 locations (re)created below. */
1363 if (b
->cond_string
!= NULL
)
1365 if (b
->cond_exp
!= NULL
)
1367 xfree (b
->cond_exp
);
1372 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1376 /* If we failed to parse the expression, for example because
1377 it refers to a global variable in a not-yet-loaded shared library,
1378 don't try to insert watchpoint. We don't automatically delete
1379 such watchpoint, though, since failure to parse expression
1380 is different from out-of-scope watchpoint. */
1381 if ( !target_has_execution
)
1383 /* Without execution, memory can't change. No use to try and
1384 set watchpoint locations. The watchpoint will be reset when
1385 the target gains execution, through breakpoint_re_set. */
1387 else if (within_current_scope
&& b
->exp
)
1389 struct value
*val_chain
, *v
, *result
, *next
;
1390 struct program_space
*frame_pspace
;
1392 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1394 /* Avoid setting b->val if it's already set. The meaning of
1395 b->val is 'the last value' user saw, and we should update
1396 it only if we reported that last value to user. As it
1397 happens, the code that reports it updates b->val directly. */
1404 /* Change the type of breakpoint between hardware assisted or an
1405 ordinary watchpoint depending on the hardware support and free
1406 hardware slots. REPARSE is set when the inferior is started. */
1407 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1410 int i
, mem_cnt
, other_type_used
;
1412 /* We need to determine how many resources are already used
1413 for all other hardware watchpoints to see if we still have
1414 enough resources to also fit this watchpoint in as well.
1415 To avoid the hw_watchpoint_used_count call below from counting
1416 this watchpoint, make sure that it is marked as a software
1418 b
->type
= bp_watchpoint
;
1419 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1421 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1424 b
->type
= bp_watchpoint
;
1427 int target_resources_ok
= target_can_use_hardware_watchpoint
1428 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1429 if (target_resources_ok
<= 0)
1430 b
->type
= bp_watchpoint
;
1432 b
->type
= bp_hardware_watchpoint
;
1436 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1438 /* Look at each value on the value chain. */
1439 for (v
= val_chain
; v
; v
= next
)
1441 /* If it's a memory location, and GDB actually needed
1442 its contents to evaluate the expression, then we
1443 must watch it. If the first value returned is
1444 still lazy, that means an error occurred reading it;
1445 watch it anyway in case it becomes readable. */
1446 if (VALUE_LVAL (v
) == lval_memory
1447 && (v
== val_chain
|| ! value_lazy (v
)))
1449 struct type
*vtype
= check_typedef (value_type (v
));
1451 /* We only watch structs and arrays if user asked
1452 for it explicitly, never if they just happen to
1453 appear in the middle of some value chain. */
1455 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1456 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1460 struct bp_location
*loc
, **tmp
;
1462 addr
= value_address (v
);
1463 len
= TYPE_LENGTH (value_type (v
));
1465 if (b
->type
== bp_read_watchpoint
)
1467 else if (b
->type
== bp_access_watchpoint
)
1470 loc
= allocate_bp_location (b
);
1471 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1474 loc
->gdbarch
= get_type_arch (value_type (v
));
1476 loc
->pspace
= frame_pspace
;
1477 loc
->address
= addr
;
1479 loc
->watchpoint_type
= type
;
1483 next
= value_next (v
);
1488 /* If a software watchpoint is not watching any memory, then the
1489 above left it without any location set up. But,
1490 bpstat_stop_status requires a location to be able to report
1491 stops, so make sure there's at least a dummy one. */
1492 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1494 b
->loc
= allocate_bp_location (b
);
1495 b
->loc
->pspace
= frame_pspace
;
1496 b
->loc
->address
= -1;
1497 b
->loc
->length
= -1;
1498 b
->loc
->watchpoint_type
= -1;
1501 else if (!within_current_scope
)
1503 printf_filtered (_("\
1504 Watchpoint %d deleted because the program has left the block \n\
1505 in which its expression is valid.\n"),
1507 if (b
->related_breakpoint
)
1509 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1510 b
->related_breakpoint
->related_breakpoint
= NULL
;
1511 b
->related_breakpoint
= NULL
;
1513 b
->disposition
= disp_del_at_next_stop
;
1516 /* Restore the selected frame. */
1518 select_frame (frame_find_by_id (saved_frame_id
));
1522 /* Returns 1 iff breakpoint location should be
1523 inserted in the inferior. */
1525 should_be_inserted (struct bp_location
*bpt
)
1527 if (!breakpoint_enabled (bpt
->owner
))
1530 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1533 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1536 /* This is set for example, when we're attached to the parent of a
1537 vfork, and have detached from the child. The child is running
1538 free, and we expect it to do an exec or exit, at which point the
1539 OS makes the parent schedulable again (and the target reports
1540 that the vfork is done). Until the child is done with the shared
1541 memory region, do not insert breakpoints in the parent, otherwise
1542 the child could still trip on the parent's breakpoints. Since
1543 the parent is blocked anyway, it won't miss any breakpoint. */
1544 if (bpt
->pspace
->breakpoints_not_allowed
)
1547 /* Tracepoints are inserted by the target at a time of its choosing,
1549 if (tracepoint_type (bpt
->owner
))
1555 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1556 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1557 and HW_BREAKPOINT_ERROR are used to report problems.
1559 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1560 method for each breakpoint or catchpoint type. */
1562 insert_bp_location (struct bp_location
*bpt
,
1563 struct ui_file
*tmp_error_stream
,
1564 int *disabled_breaks
,
1565 int *hw_breakpoint_error
)
1569 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1572 /* Initialize the target-specific information. */
1573 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1574 bpt
->target_info
.placed_address
= bpt
->address
;
1575 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1577 if (bpt
->loc_type
== bp_loc_software_breakpoint
1578 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1580 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1582 /* If the explicitly specified breakpoint type
1583 is not hardware breakpoint, check the memory map to see
1584 if the breakpoint address is in read only memory or not.
1585 Two important cases are:
1586 - location type is not hardware breakpoint, memory
1587 is readonly. We change the type of the location to
1588 hardware breakpoint.
1589 - location type is hardware breakpoint, memory is read-write.
1590 This means we've previously made the location hardware one, but
1591 then the memory map changed, so we undo.
1593 When breakpoints are removed, remove_breakpoints will
1594 use location types we've just set here, the only possible
1595 problem is that memory map has changed during running program,
1596 but it's not going to work anyway with current gdb. */
1597 struct mem_region
*mr
1598 = lookup_mem_region (bpt
->target_info
.placed_address
);
1602 if (automatic_hardware_breakpoints
)
1605 enum bp_loc_type new_type
;
1607 if (mr
->attrib
.mode
!= MEM_RW
)
1608 new_type
= bp_loc_hardware_breakpoint
;
1610 new_type
= bp_loc_software_breakpoint
;
1612 if (new_type
!= bpt
->loc_type
)
1614 static int said
= 0;
1615 bpt
->loc_type
= new_type
;
1618 fprintf_filtered (gdb_stdout
, _("\
1619 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1624 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1625 && mr
->attrib
.mode
!= MEM_RW
)
1626 warning (_("cannot set software breakpoint at readonly address %s"),
1627 paddress (bpt
->gdbarch
, bpt
->address
));
1631 /* First check to see if we have to handle an overlay. */
1632 if (overlay_debugging
== ovly_off
1633 || bpt
->section
== NULL
1634 || !(section_is_overlay (bpt
->section
)))
1636 /* No overlay handling: just set the breakpoint. */
1638 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1639 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1642 val
= target_insert_breakpoint (bpt
->gdbarch
,
1647 /* This breakpoint is in an overlay section.
1648 Shall we set a breakpoint at the LMA? */
1649 if (!overlay_events_enabled
)
1651 /* Yes -- overlay event support is not active,
1652 so we must try to set a breakpoint at the LMA.
1653 This will not work for a hardware breakpoint. */
1654 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1655 warning (_("hardware breakpoint %d not supported in overlay!"),
1656 bpt
->owner
->number
);
1659 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1661 /* Set a software (trap) breakpoint at the LMA. */
1662 bpt
->overlay_target_info
= bpt
->target_info
;
1663 bpt
->overlay_target_info
.placed_address
= addr
;
1664 val
= target_insert_breakpoint (bpt
->gdbarch
,
1665 &bpt
->overlay_target_info
);
1667 fprintf_unfiltered (tmp_error_stream
,
1668 "Overlay breakpoint %d failed: in ROM?\n",
1669 bpt
->owner
->number
);
1672 /* Shall we set a breakpoint at the VMA? */
1673 if (section_is_mapped (bpt
->section
))
1675 /* Yes. This overlay section is mapped into memory. */
1676 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1677 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1680 val
= target_insert_breakpoint (bpt
->gdbarch
,
1685 /* No. This breakpoint will not be inserted.
1686 No error, but do not mark the bp as 'inserted'. */
1693 /* Can't set the breakpoint. */
1694 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1696 /* See also: disable_breakpoints_in_shlibs. */
1698 bpt
->shlib_disabled
= 1;
1699 if (!*disabled_breaks
)
1701 fprintf_unfiltered (tmp_error_stream
,
1702 "Cannot insert breakpoint %d.\n",
1703 bpt
->owner
->number
);
1704 fprintf_unfiltered (tmp_error_stream
,
1705 "Temporarily disabling shared library breakpoints:\n");
1707 *disabled_breaks
= 1;
1708 fprintf_unfiltered (tmp_error_stream
,
1709 "breakpoint #%d\n", bpt
->owner
->number
);
1713 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1715 *hw_breakpoint_error
= 1;
1716 fprintf_unfiltered (tmp_error_stream
,
1717 "Cannot insert hardware breakpoint %d.\n",
1718 bpt
->owner
->number
);
1722 fprintf_unfiltered (tmp_error_stream
,
1723 "Cannot insert breakpoint %d.\n",
1724 bpt
->owner
->number
);
1725 fprintf_filtered (tmp_error_stream
,
1726 "Error accessing memory address ");
1727 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1729 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1730 safe_strerror (val
));
1741 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1742 /* NOTE drow/2003-09-08: This state only exists for removing
1743 watchpoints. It's not clear that it's necessary... */
1744 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1746 val
= target_insert_watchpoint (bpt
->address
,
1748 bpt
->watchpoint_type
);
1750 /* If trying to set a read-watchpoint, and it turns out it's not
1751 supported, try emulating one with an access watchpoint. */
1752 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1754 struct bp_location
*loc
, **loc_temp
;
1756 /* But don't try to insert it, if there's already another
1757 hw_access location that would be considered a duplicate
1759 ALL_BP_LOCATIONS (loc
, loc_temp
)
1761 && loc
->watchpoint_type
== hw_access
1762 && watchpoint_locations_match (bpt
, loc
))
1766 bpt
->target_info
= loc
->target_info
;
1767 bpt
->watchpoint_type
= hw_access
;
1774 val
= target_insert_watchpoint (bpt
->address
,
1778 bpt
->watchpoint_type
= hw_access
;
1782 bpt
->inserted
= (val
== 0);
1785 else if (bpt
->owner
->type
== bp_catchpoint
)
1787 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1788 bpt
->owner
, RETURN_MASK_ERROR
);
1789 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1790 bpt
->owner
->number
);
1792 bpt
->owner
->enable_state
= bp_disabled
;
1796 /* We've already printed an error message if there was a problem
1797 inserting this catchpoint, and we've disabled the catchpoint,
1798 so just return success. */
1805 /* This function is called when program space PSPACE is about to be
1806 deleted. It takes care of updating breakpoints to not reference
1810 breakpoint_program_space_exit (struct program_space
*pspace
)
1812 struct breakpoint
*b
, *b_temp
;
1813 struct bp_location
*loc
, **loc_temp
;
1815 /* Remove any breakpoint that was set through this program space. */
1816 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1818 if (b
->pspace
== pspace
)
1819 delete_breakpoint (b
);
1822 /* Breakpoints set through other program spaces could have locations
1823 bound to PSPACE as well. Remove those. */
1824 ALL_BP_LOCATIONS (loc
, loc_temp
)
1826 struct bp_location
*tmp
;
1828 if (loc
->pspace
== pspace
)
1830 if (loc
->owner
->loc
== loc
)
1831 loc
->owner
->loc
= loc
->next
;
1833 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1834 if (tmp
->next
== loc
)
1836 tmp
->next
= loc
->next
;
1842 /* Now update the global location list to permanently delete the
1843 removed locations above. */
1844 update_global_location_list (0);
1847 /* Make sure all breakpoints are inserted in inferior.
1848 Throws exception on any error.
1849 A breakpoint that is already inserted won't be inserted
1850 again, so calling this function twice is safe. */
1852 insert_breakpoints (void)
1854 struct breakpoint
*bpt
;
1856 ALL_BREAKPOINTS (bpt
)
1857 if (is_hardware_watchpoint (bpt
))
1858 update_watchpoint (bpt
, 0 /* don't reparse. */);
1860 update_global_location_list (1);
1862 /* update_global_location_list does not insert breakpoints when
1863 always_inserted_mode is not enabled. Explicitly insert them
1865 if (!breakpoints_always_inserted_mode ())
1866 insert_breakpoint_locations ();
1869 /* insert_breakpoints is used when starting or continuing the program.
1870 remove_breakpoints is used when the program stops.
1871 Both return zero if successful,
1872 or an `errno' value if could not write the inferior. */
1875 insert_breakpoint_locations (void)
1877 struct breakpoint
*bpt
;
1878 struct bp_location
*b
, **bp_tmp
;
1881 int disabled_breaks
= 0;
1882 int hw_breakpoint_error
= 0;
1884 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1885 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1887 /* Explicitly mark the warning -- this will only be printed if
1888 there was an error. */
1889 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1891 save_current_space_and_thread ();
1893 ALL_BP_LOCATIONS (b
, bp_tmp
)
1895 struct thread_info
*tp
;
1896 CORE_ADDR last_addr
;
1898 if (!should_be_inserted (b
) || b
->inserted
)
1901 /* There is no point inserting thread-specific breakpoints if the
1902 thread no longer exists. */
1903 if (b
->owner
->thread
!= -1
1904 && !valid_thread_id (b
->owner
->thread
))
1907 switch_to_program_space_and_thread (b
->pspace
);
1909 /* For targets that support global breakpoints, there's no need
1910 to select an inferior to insert breakpoint to. In fact, even
1911 if we aren't attached to any process yet, we should still
1912 insert breakpoints. */
1913 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1914 && ptid_equal (inferior_ptid
, null_ptid
))
1917 val
= insert_bp_location (b
, tmp_error_stream
,
1919 &hw_breakpoint_error
);
1924 /* If we failed to insert all locations of a watchpoint,
1925 remove them, as half-inserted watchpoint is of limited use. */
1926 ALL_BREAKPOINTS (bpt
)
1928 int some_failed
= 0;
1929 struct bp_location
*loc
;
1931 if (!is_hardware_watchpoint (bpt
))
1934 if (!breakpoint_enabled (bpt
))
1937 if (bpt
->disposition
== disp_del_at_next_stop
)
1940 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1941 if (!loc
->inserted
&& should_be_inserted (loc
))
1948 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1950 remove_breakpoint (loc
, mark_uninserted
);
1952 hw_breakpoint_error
= 1;
1953 fprintf_unfiltered (tmp_error_stream
,
1954 "Could not insert hardware watchpoint %d.\n",
1962 /* If a hardware breakpoint or watchpoint was inserted, add a
1963 message about possibly exhausted resources. */
1964 if (hw_breakpoint_error
)
1966 fprintf_unfiltered (tmp_error_stream
,
1967 "Could not insert hardware breakpoints:\n\
1968 You may have requested too many hardware breakpoints/watchpoints.\n");
1970 target_terminal_ours_for_output ();
1971 error_stream (tmp_error_stream
);
1974 do_cleanups (cleanups
);
1978 remove_breakpoints (void)
1980 struct bp_location
*b
, **bp_tmp
;
1983 ALL_BP_LOCATIONS (b
, bp_tmp
)
1986 val
|= remove_breakpoint (b
, mark_uninserted
);
1991 /* Remove breakpoints of process PID. */
1994 remove_breakpoints_pid (int pid
)
1996 struct bp_location
*b
, **b_tmp
;
1998 struct inferior
*inf
= find_inferior_pid (pid
);
2000 ALL_BP_LOCATIONS (b
, b_tmp
)
2002 if (b
->pspace
!= inf
->pspace
)
2007 val
= remove_breakpoint (b
, mark_uninserted
);
2016 remove_hw_watchpoints (void)
2018 struct bp_location
*b
, **bp_tmp
;
2021 ALL_BP_LOCATIONS (b
, bp_tmp
)
2023 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2024 val
|= remove_breakpoint (b
, mark_uninserted
);
2030 reattach_breakpoints (int pid
)
2032 struct cleanup
*old_chain
;
2033 struct bp_location
*b
, **bp_tmp
;
2035 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2036 int dummy1
= 0, dummy2
= 0;
2037 struct inferior
*inf
;
2038 struct thread_info
*tp
;
2040 tp
= any_live_thread_of_process (pid
);
2044 inf
= find_inferior_pid (pid
);
2045 old_chain
= save_inferior_ptid ();
2047 inferior_ptid
= tp
->ptid
;
2049 make_cleanup_ui_file_delete (tmp_error_stream
);
2051 ALL_BP_LOCATIONS (b
, bp_tmp
)
2053 if (b
->pspace
!= inf
->pspace
)
2059 val
= insert_bp_location (b
, tmp_error_stream
,
2063 do_cleanups (old_chain
);
2068 do_cleanups (old_chain
);
2072 static int internal_breakpoint_number
= -1;
2074 static struct breakpoint
*
2075 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2076 CORE_ADDR address
, enum bptype type
)
2078 struct symtab_and_line sal
;
2079 struct breakpoint
*b
;
2081 init_sal (&sal
); /* initialize to zeroes */
2084 sal
.section
= find_pc_overlay (sal
.pc
);
2085 sal
.pspace
= current_program_space
;
2087 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2088 b
->number
= internal_breakpoint_number
--;
2089 b
->disposition
= disp_donttouch
;
2095 create_overlay_event_breakpoint (char *func_name
)
2097 struct objfile
*objfile
;
2099 ALL_OBJFILES (objfile
)
2101 struct breakpoint
*b
;
2102 struct minimal_symbol
*m
;
2104 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2108 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2109 SYMBOL_VALUE_ADDRESS (m
),
2111 b
->addr_string
= xstrdup (func_name
);
2113 if (overlay_debugging
== ovly_auto
)
2115 b
->enable_state
= bp_enabled
;
2116 overlay_events_enabled
= 1;
2120 b
->enable_state
= bp_disabled
;
2121 overlay_events_enabled
= 0;
2124 update_global_location_list (1);
2128 create_longjmp_master_breakpoint (char *func_name
)
2130 struct program_space
*pspace
;
2131 struct objfile
*objfile
;
2132 struct cleanup
*old_chain
;
2134 old_chain
= save_current_program_space ();
2136 ALL_PSPACES (pspace
)
2137 ALL_OBJFILES (objfile
)
2139 struct breakpoint
*b
;
2140 struct minimal_symbol
*m
;
2142 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2145 set_current_program_space (pspace
);
2147 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2151 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2152 SYMBOL_VALUE_ADDRESS (m
),
2154 b
->addr_string
= xstrdup (func_name
);
2155 b
->enable_state
= bp_disabled
;
2157 update_global_location_list (1);
2159 do_cleanups (old_chain
);
2162 /* Create a master std::terminate breakpoint. The actual function
2163 looked for is named FUNC_NAME. */
2165 create_std_terminate_master_breakpoint (const char *func_name
)
2167 struct program_space
*pspace
;
2168 struct objfile
*objfile
;
2169 struct cleanup
*old_chain
;
2171 old_chain
= save_current_program_space ();
2173 ALL_PSPACES (pspace
)
2174 ALL_OBJFILES (objfile
)
2176 struct breakpoint
*b
;
2177 struct minimal_symbol
*m
;
2179 set_current_program_space (pspace
);
2181 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2182 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2183 && MSYMBOL_TYPE (m
) != mst_file_text
))
2186 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2187 SYMBOL_VALUE_ADDRESS (m
),
2188 bp_std_terminate_master
);
2189 b
->addr_string
= xstrdup (func_name
);
2190 b
->enable_state
= bp_disabled
;
2192 update_global_location_list (1);
2194 do_cleanups (old_chain
);
2198 update_breakpoints_after_exec (void)
2200 struct breakpoint
*b
;
2201 struct breakpoint
*temp
;
2202 struct bp_location
*bploc
, **bplocp_tmp
;
2204 /* We're about to delete breakpoints from GDB's lists. If the
2205 INSERTED flag is true, GDB will try to lift the breakpoints by
2206 writing the breakpoints' "shadow contents" back into memory. The
2207 "shadow contents" are NOT valid after an exec, so GDB should not
2208 do that. Instead, the target is responsible from marking
2209 breakpoints out as soon as it detects an exec. We don't do that
2210 here instead, because there may be other attempts to delete
2211 breakpoints after detecting an exec and before reaching here. */
2212 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2213 if (bploc
->pspace
== current_program_space
)
2214 gdb_assert (!bploc
->inserted
);
2216 ALL_BREAKPOINTS_SAFE (b
, temp
)
2218 if (b
->pspace
!= current_program_space
)
2221 /* Solib breakpoints must be explicitly reset after an exec(). */
2222 if (b
->type
== bp_shlib_event
)
2224 delete_breakpoint (b
);
2228 /* JIT breakpoints must be explicitly reset after an exec(). */
2229 if (b
->type
== bp_jit_event
)
2231 delete_breakpoint (b
);
2235 /* Thread event breakpoints must be set anew after an exec(),
2236 as must overlay event and longjmp master breakpoints. */
2237 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2238 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2240 delete_breakpoint (b
);
2244 /* Step-resume breakpoints are meaningless after an exec(). */
2245 if (b
->type
== bp_step_resume
)
2247 delete_breakpoint (b
);
2251 /* Longjmp and longjmp-resume breakpoints are also meaningless
2253 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2255 delete_breakpoint (b
);
2259 if (b
->type
== bp_catchpoint
)
2261 /* For now, none of the bp_catchpoint breakpoints need to
2262 do anything at this point. In the future, if some of
2263 the catchpoints need to something, we will need to add
2264 a new method, and call this method from here. */
2268 /* bp_finish is a special case. The only way we ought to be able
2269 to see one of these when an exec() has happened, is if the user
2270 caught a vfork, and then said "finish". Ordinarily a finish just
2271 carries them to the call-site of the current callee, by setting
2272 a temporary bp there and resuming. But in this case, the finish
2273 will carry them entirely through the vfork & exec.
2275 We don't want to allow a bp_finish to remain inserted now. But
2276 we can't safely delete it, 'cause finish_command has a handle to
2277 the bp on a bpstat, and will later want to delete it. There's a
2278 chance (and I've seen it happen) that if we delete the bp_finish
2279 here, that its storage will get reused by the time finish_command
2280 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2281 We really must allow finish_command to delete a bp_finish.
2283 In the absense of a general solution for the "how do we know
2284 it's safe to delete something others may have handles to?"
2285 problem, what we'll do here is just uninsert the bp_finish, and
2286 let finish_command delete it.
2288 (We know the bp_finish is "doomed" in the sense that it's
2289 momentary, and will be deleted as soon as finish_command sees
2290 the inferior stopped. So it doesn't matter that the bp's
2291 address is probably bogus in the new a.out, unlike e.g., the
2292 solib breakpoints.) */
2294 if (b
->type
== bp_finish
)
2299 /* Without a symbolic address, we have little hope of the
2300 pre-exec() address meaning the same thing in the post-exec()
2302 if (b
->addr_string
== NULL
)
2304 delete_breakpoint (b
);
2308 /* FIXME what about longjmp breakpoints? Re-create them here? */
2309 create_overlay_event_breakpoint ("_ovly_debug_event");
2310 create_longjmp_master_breakpoint ("longjmp");
2311 create_longjmp_master_breakpoint ("_longjmp");
2312 create_longjmp_master_breakpoint ("siglongjmp");
2313 create_longjmp_master_breakpoint ("_siglongjmp");
2314 create_std_terminate_master_breakpoint ("std::terminate()");
2318 detach_breakpoints (int pid
)
2320 struct bp_location
*b
, **bp_tmp
;
2322 struct cleanup
*old_chain
= save_inferior_ptid ();
2323 struct inferior
*inf
= current_inferior ();
2325 if (pid
== PIDGET (inferior_ptid
))
2326 error (_("Cannot detach breakpoints of inferior_ptid"));
2328 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2329 inferior_ptid
= pid_to_ptid (pid
);
2330 ALL_BP_LOCATIONS (b
, bp_tmp
)
2332 if (b
->pspace
!= inf
->pspace
)
2336 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2338 do_cleanups (old_chain
);
2342 /* Remove the breakpoint location B from the current address space.
2343 Note that this is used to detach breakpoints from a child fork.
2344 When we get here, the child isn't in the inferior list, and neither
2345 do we have objects to represent its address space --- we should
2346 *not* look at b->pspace->aspace here. */
2349 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2352 struct cleanup
*old_chain
;
2354 if (b
->owner
->enable_state
== bp_permanent
)
2355 /* Permanent breakpoints cannot be inserted or removed. */
2358 /* The type of none suggests that owner is actually deleted.
2359 This should not ever happen. */
2360 gdb_assert (b
->owner
->type
!= bp_none
);
2362 if (b
->loc_type
== bp_loc_software_breakpoint
2363 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2365 /* "Normal" instruction breakpoint: either the standard
2366 trap-instruction bp (bp_breakpoint), or a
2367 bp_hardware_breakpoint. */
2369 /* First check to see if we have to handle an overlay. */
2370 if (overlay_debugging
== ovly_off
2371 || b
->section
== NULL
2372 || !(section_is_overlay (b
->section
)))
2374 /* No overlay handling: just remove the breakpoint. */
2376 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2377 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2379 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2383 /* This breakpoint is in an overlay section.
2384 Did we set a breakpoint at the LMA? */
2385 if (!overlay_events_enabled
)
2387 /* Yes -- overlay event support is not active, so we
2388 should have set a breakpoint at the LMA. Remove it.
2390 /* Ignore any failures: if the LMA is in ROM, we will
2391 have already warned when we failed to insert it. */
2392 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2393 target_remove_hw_breakpoint (b
->gdbarch
,
2394 &b
->overlay_target_info
);
2396 target_remove_breakpoint (b
->gdbarch
,
2397 &b
->overlay_target_info
);
2399 /* Did we set a breakpoint at the VMA?
2400 If so, we will have marked the breakpoint 'inserted'. */
2403 /* Yes -- remove it. Previously we did not bother to
2404 remove the breakpoint if the section had been
2405 unmapped, but let's not rely on that being safe. We
2406 don't know what the overlay manager might do. */
2407 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2408 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2411 /* However, we should remove *software* breakpoints only
2412 if the section is still mapped, or else we overwrite
2413 wrong code with the saved shadow contents. */
2414 else if (section_is_mapped (b
->section
))
2415 val
= target_remove_breakpoint (b
->gdbarch
,
2422 /* No -- not inserted, so no need to remove. No error. */
2427 /* In some cases, we might not be able to remove a breakpoint
2428 in a shared library that has already been removed, but we
2429 have not yet processed the shlib unload event. */
2430 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2435 b
->inserted
= (is
== mark_inserted
);
2437 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2442 b
->inserted
= (is
== mark_inserted
);
2443 val
= target_remove_watchpoint (b
->address
, b
->length
,
2444 b
->watchpoint_type
);
2446 /* Failure to remove any of the hardware watchpoints comes here. */
2447 if ((is
== mark_uninserted
) && (b
->inserted
))
2448 warning (_("Could not remove hardware watchpoint %d."),
2451 else if (b
->owner
->type
== bp_catchpoint
2452 && breakpoint_enabled (b
->owner
)
2455 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2457 val
= b
->owner
->ops
->remove (b
->owner
);
2460 b
->inserted
= (is
== mark_inserted
);
2467 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2470 struct cleanup
*old_chain
;
2472 if (b
->owner
->enable_state
== bp_permanent
)
2473 /* Permanent breakpoints cannot be inserted or removed. */
2476 /* The type of none suggests that owner is actually deleted.
2477 This should not ever happen. */
2478 gdb_assert (b
->owner
->type
!= bp_none
);
2480 old_chain
= save_current_space_and_thread ();
2482 switch_to_program_space_and_thread (b
->pspace
);
2484 ret
= remove_breakpoint_1 (b
, is
);
2486 do_cleanups (old_chain
);
2490 /* Clear the "inserted" flag in all breakpoints. */
2493 mark_breakpoints_out (void)
2495 struct bp_location
*bpt
, **bptp_tmp
;
2497 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2498 if (bpt
->pspace
== current_program_space
)
2502 /* Clear the "inserted" flag in all breakpoints and delete any
2503 breakpoints which should go away between runs of the program.
2505 Plus other such housekeeping that has to be done for breakpoints
2508 Note: this function gets called at the end of a run (by
2509 generic_mourn_inferior) and when a run begins (by
2510 init_wait_for_inferior). */
2515 breakpoint_init_inferior (enum inf_context context
)
2517 struct breakpoint
*b
, *temp
;
2518 struct bp_location
*bpt
, **bptp_tmp
;
2520 struct program_space
*pspace
= current_program_space
;
2522 /* If breakpoint locations are shared across processes, then there's
2524 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2527 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2529 if (bpt
->pspace
== pspace
2530 && bpt
->owner
->enable_state
!= bp_permanent
)
2534 ALL_BREAKPOINTS_SAFE (b
, temp
)
2536 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2543 /* If the call dummy breakpoint is at the entry point it will
2544 cause problems when the inferior is rerun, so we better get
2547 case bp_watchpoint_scope
:
2549 /* Also get rid of scope breakpoints. */
2551 case bp_shlib_event
:
2553 /* Also remove solib event breakpoints. Their addresses may
2554 have changed since the last time we ran the program.
2555 Actually we may now be debugging against different target;
2556 and so the solib backend that installed this breakpoint may
2557 not be used in by the target. E.g.,
2559 (gdb) file prog-linux
2560 (gdb) run # native linux target
2563 (gdb) file prog-win.exe
2564 (gdb) tar rem :9999 # remote Windows gdbserver.
2567 delete_breakpoint (b
);
2571 case bp_hardware_watchpoint
:
2572 case bp_read_watchpoint
:
2573 case bp_access_watchpoint
:
2575 /* Likewise for watchpoints on local expressions. */
2576 if (b
->exp_valid_block
!= NULL
)
2577 delete_breakpoint (b
);
2578 else if (context
== inf_starting
)
2580 /* Reset val field to force reread of starting value
2581 in insert_breakpoints. */
2583 value_free (b
->val
);
2593 /* Get rid of the moribund locations. */
2594 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2595 free_bp_location (bpt
);
2596 VEC_free (bp_location_p
, moribund_locations
);
2599 /* These functions concern about actual breakpoints inserted in the
2600 target --- to e.g. check if we need to do decr_pc adjustment or if
2601 we need to hop over the bkpt --- so we check for address space
2602 match, not program space. */
2604 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2605 exists at PC. It returns ordinary_breakpoint_here if it's an
2606 ordinary breakpoint, or permanent_breakpoint_here if it's a
2607 permanent breakpoint.
2608 - When continuing from a location with an ordinary breakpoint, we
2609 actually single step once before calling insert_breakpoints.
2610 - When continuing from a localion with a permanent breakpoint, we
2611 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2612 the target, to advance the PC past the breakpoint. */
2614 enum breakpoint_here
2615 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2617 struct bp_location
*bpt
, **bptp_tmp
;
2618 int any_breakpoint_here
= 0;
2620 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2622 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2623 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2626 if ((breakpoint_enabled (bpt
->owner
)
2627 || bpt
->owner
->enable_state
== bp_permanent
)
2628 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2631 if (overlay_debugging
2632 && section_is_overlay (bpt
->section
)
2633 && !section_is_mapped (bpt
->section
))
2634 continue; /* unmapped overlay -- can't be a match */
2635 else if (bpt
->owner
->enable_state
== bp_permanent
)
2636 return permanent_breakpoint_here
;
2638 any_breakpoint_here
= 1;
2642 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2645 /* Return true if there's a moribund breakpoint at PC. */
2648 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2650 struct bp_location
*loc
;
2653 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2654 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2661 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2662 inserted using regular breakpoint_chain / bp_location array mechanism.
2663 This does not check for single-step breakpoints, which are
2664 inserted and removed using direct target manipulation. */
2667 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2669 struct bp_location
*bpt
, **bptp_tmp
;
2671 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2673 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2674 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2678 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2681 if (overlay_debugging
2682 && section_is_overlay (bpt
->section
)
2683 && !section_is_mapped (bpt
->section
))
2684 continue; /* unmapped overlay -- can't be a match */
2692 /* Returns non-zero iff there's either regular breakpoint
2693 or a single step breakpoint inserted at PC. */
2696 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2698 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2701 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2707 /* This function returns non-zero iff there is a software breakpoint
2711 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2713 struct bp_location
*bpt
, **bptp_tmp
;
2714 int any_breakpoint_here
= 0;
2716 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2718 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2722 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2725 if (overlay_debugging
2726 && section_is_overlay (bpt
->section
)
2727 && !section_is_mapped (bpt
->section
))
2728 continue; /* unmapped overlay -- can't be a match */
2734 /* Also check for software single-step breakpoints. */
2735 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2742 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2743 CORE_ADDR addr
, ULONGEST len
)
2745 struct breakpoint
*bpt
;
2747 ALL_BREAKPOINTS (bpt
)
2749 struct bp_location
*loc
;
2751 if (bpt
->type
!= bp_hardware_watchpoint
2752 && bpt
->type
!= bp_access_watchpoint
)
2755 if (!breakpoint_enabled (bpt
))
2758 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2759 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2763 /* Check for intersection. */
2764 l
= max (loc
->address
, addr
);
2765 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2773 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2774 PC is valid for process/thread PTID. */
2777 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2780 struct bp_location
*bpt
, **bptp_tmp
;
2781 /* The thread and task IDs associated to PTID, computed lazily. */
2785 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2787 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2788 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2791 if (!breakpoint_enabled (bpt
->owner
)
2792 && bpt
->owner
->enable_state
!= bp_permanent
)
2795 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2799 if (bpt
->owner
->thread
!= -1)
2801 /* This is a thread-specific breakpoint. Check that ptid
2802 matches that thread. If thread hasn't been computed yet,
2803 it is now time to do so. */
2805 thread
= pid_to_thread_id (ptid
);
2806 if (bpt
->owner
->thread
!= thread
)
2810 if (bpt
->owner
->task
!= 0)
2812 /* This is a task-specific breakpoint. Check that ptid
2813 matches that task. If task hasn't been computed yet,
2814 it is now time to do so. */
2816 task
= ada_get_task_number (ptid
);
2817 if (bpt
->owner
->task
!= task
)
2821 if (overlay_debugging
2822 && section_is_overlay (bpt
->section
)
2823 && !section_is_mapped (bpt
->section
))
2824 continue; /* unmapped overlay -- can't be a match */
2833 /* bpstat stuff. External routines' interfaces are documented
2837 ep_is_catchpoint (struct breakpoint
*ep
)
2839 return (ep
->type
== bp_catchpoint
);
2843 bpstat_free (bpstat bs
)
2845 if (bs
->old_val
!= NULL
)
2846 value_free (bs
->old_val
);
2847 decref_counted_command_line (&bs
->commands
);
2851 /* Clear a bpstat so that it says we are not at any breakpoint.
2852 Also free any storage that is part of a bpstat. */
2855 bpstat_clear (bpstat
*bsp
)
2872 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2873 is part of the bpstat is copied as well. */
2876 bpstat_copy (bpstat bs
)
2880 bpstat retval
= NULL
;
2885 for (; bs
!= NULL
; bs
= bs
->next
)
2887 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2888 memcpy (tmp
, bs
, sizeof (*tmp
));
2889 incref_counted_command_line (tmp
->commands
);
2890 if (bs
->old_val
!= NULL
)
2892 tmp
->old_val
= value_copy (bs
->old_val
);
2893 release_value (tmp
->old_val
);
2897 /* This is the first thing in the chain. */
2907 /* Find the bpstat associated with this breakpoint */
2910 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2915 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2917 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2923 /* Find a step_resume breakpoint associated with this bpstat.
2924 (If there are multiple step_resume bp's on the list, this function
2925 will arbitrarily pick one.)
2927 It is an error to use this function if BPSTAT doesn't contain a
2928 step_resume breakpoint.
2930 See wait_for_inferior's use of this function. */
2932 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2936 gdb_assert (bsp
!= NULL
);
2938 current_thread
= pid_to_thread_id (inferior_ptid
);
2940 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2942 if ((bsp
->breakpoint_at
!= NULL
)
2943 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2944 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2945 || bsp
->breakpoint_at
->owner
->thread
== -1))
2946 return bsp
->breakpoint_at
->owner
;
2949 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2953 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2954 at. *BSP upon return is a bpstat which points to the remaining
2955 breakpoints stopped at (but which is not guaranteed to be good for
2956 anything but further calls to bpstat_num).
2957 Return 0 if passed a bpstat which does not indicate any breakpoints.
2958 Return -1 if stopped at a breakpoint that has been deleted since
2960 Return 1 otherwise. */
2963 bpstat_num (bpstat
*bsp
, int *num
)
2965 struct breakpoint
*b
;
2968 return 0; /* No more breakpoint values */
2970 /* We assume we'll never have several bpstats that
2971 correspond to a single breakpoint -- otherwise,
2972 this function might return the same number more
2973 than once and this will look ugly. */
2974 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2975 *bsp
= (*bsp
)->next
;
2977 return -1; /* breakpoint that's been deleted since */
2979 *num
= b
->number
; /* We have its number */
2983 /* Modify BS so that the actions will not be performed. */
2986 bpstat_clear_actions (bpstat bs
)
2988 for (; bs
!= NULL
; bs
= bs
->next
)
2990 decref_counted_command_line (&bs
->commands
);
2991 bs
->commands_left
= NULL
;
2992 if (bs
->old_val
!= NULL
)
2994 value_free (bs
->old_val
);
3000 /* Called when a command is about to proceed the inferior. */
3003 breakpoint_about_to_proceed (void)
3005 if (!ptid_equal (inferior_ptid
, null_ptid
))
3007 struct thread_info
*tp
= inferior_thread ();
3009 /* Allow inferior function calls in breakpoint commands to not
3010 interrupt the command list. When the call finishes
3011 successfully, the inferior will be standing at the same
3012 breakpoint as if nothing happened. */
3017 breakpoint_proceeded
= 1;
3020 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3022 cleanup_executing_breakpoints (void *ignore
)
3024 executing_breakpoint_commands
= 0;
3027 /* Execute all the commands associated with all the breakpoints at this
3028 location. Any of these commands could cause the process to proceed
3029 beyond this point, etc. We look out for such changes by checking
3030 the global "breakpoint_proceeded" after each command.
3032 Returns true if a breakpoint command resumed the inferior. In that
3033 case, it is the caller's responsibility to recall it again with the
3034 bpstat of the current thread. */
3037 bpstat_do_actions_1 (bpstat
*bsp
)
3040 struct cleanup
*old_chain
;
3043 /* Avoid endless recursion if a `source' command is contained
3045 if (executing_breakpoint_commands
)
3048 executing_breakpoint_commands
= 1;
3049 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3051 /* This pointer will iterate over the list of bpstat's. */
3054 breakpoint_proceeded
= 0;
3055 for (; bs
!= NULL
; bs
= bs
->next
)
3057 struct counted_command_line
*ccmd
;
3058 struct command_line
*cmd
;
3059 struct cleanup
*this_cmd_tree_chain
;
3061 /* Take ownership of the BSP's command tree, if it has one.
3063 The command tree could legitimately contain commands like
3064 'step' and 'next', which call clear_proceed_status, which
3065 frees stop_bpstat's command tree. To make sure this doesn't
3066 free the tree we're executing out from under us, we need to
3067 take ownership of the tree ourselves. Since a given bpstat's
3068 commands are only executed once, we don't need to copy it; we
3069 can clear the pointer in the bpstat, and make sure we free
3070 the tree when we're done. */
3071 ccmd
= bs
->commands
;
3072 bs
->commands
= NULL
;
3074 = make_cleanup_decref_counted_command_line (&ccmd
);
3075 cmd
= bs
->commands_left
;
3076 bs
->commands_left
= NULL
;
3080 execute_control_command (cmd
);
3082 if (breakpoint_proceeded
)
3088 /* We can free this command tree now. */
3089 do_cleanups (this_cmd_tree_chain
);
3091 if (breakpoint_proceeded
)
3093 if (target_can_async_p ())
3094 /* If we are in async mode, then the target might be still
3095 running, not stopped at any breakpoint, so nothing for
3096 us to do here -- just return to the event loop. */
3099 /* In sync mode, when execute_control_command returns
3100 we're already standing on the next breakpoint.
3101 Breakpoint commands for that stop were not run, since
3102 execute_command does not run breakpoint commands --
3103 only command_line_handler does, but that one is not
3104 involved in execution of breakpoint commands. So, we
3105 can now execute breakpoint commands. It should be
3106 noted that making execute_command do bpstat actions is
3107 not an option -- in this case we'll have recursive
3108 invocation of bpstat for each breakpoint with a
3109 command, and can easily blow up GDB stack. Instead, we
3110 return true, which will trigger the caller to recall us
3111 with the new stop_bpstat. */
3116 do_cleanups (old_chain
);
3121 bpstat_do_actions (void)
3123 /* Do any commands attached to breakpoint we are stopped at. */
3124 while (!ptid_equal (inferior_ptid
, null_ptid
)
3125 && target_has_execution
3126 && !is_exited (inferior_ptid
)
3127 && !is_executing (inferior_ptid
))
3128 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3129 and only return when it is stopped at the next breakpoint, we
3130 keep doing breakpoint actions until it returns false to
3131 indicate the inferior was not resumed. */
3132 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3136 /* Print out the (old or new) value associated with a watchpoint. */
3139 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3142 fprintf_unfiltered (stream
, _("<unreadable>"));
3145 struct value_print_options opts
;
3146 get_user_print_options (&opts
);
3147 value_print (val
, stream
, &opts
);
3151 /* This is the normal print function for a bpstat. In the future,
3152 much of this logic could (should?) be moved to bpstat_stop_status,
3153 by having it set different print_it values.
3155 Current scheme: When we stop, bpstat_print() is called. It loops
3156 through the bpstat list of things causing this stop, calling the
3157 print_bp_stop_message function on each one. The behavior of the
3158 print_bp_stop_message function depends on the print_it field of
3159 bpstat. If such field so indicates, call this function here.
3161 Return values from this routine (ultimately used by bpstat_print()
3162 and normal_stop() to decide what to do):
3163 PRINT_NOTHING: Means we already printed all we needed to print,
3164 don't print anything else.
3165 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3166 that something to be followed by a location.
3167 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3168 that something to be followed by a location.
3169 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3172 static enum print_stop_action
3173 print_it_typical (bpstat bs
)
3175 struct cleanup
*old_chain
;
3176 struct breakpoint
*b
;
3177 const struct bp_location
*bl
;
3178 struct ui_stream
*stb
;
3180 enum print_stop_action result
;
3182 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3183 which has since been deleted. */
3184 if (bs
->breakpoint_at
== NULL
)
3185 return PRINT_UNKNOWN
;
3186 bl
= bs
->breakpoint_at
;
3189 stb
= ui_out_stream_new (uiout
);
3190 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3195 case bp_hardware_breakpoint
:
3196 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3197 if (bl
->address
!= bl
->requested_address
)
3198 breakpoint_adjustment_warning (bl
->requested_address
,
3201 annotate_breakpoint (b
->number
);
3203 ui_out_text (uiout
, "\nTemporary breakpoint ");
3205 ui_out_text (uiout
, "\nBreakpoint ");
3206 if (ui_out_is_mi_like_p (uiout
))
3208 ui_out_field_string (uiout
, "reason",
3209 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3210 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3212 ui_out_field_int (uiout
, "bkptno", b
->number
);
3213 ui_out_text (uiout
, ", ");
3214 result
= PRINT_SRC_AND_LOC
;
3217 case bp_shlib_event
:
3218 /* Did we stop because the user set the stop_on_solib_events
3219 variable? (If so, we report this as a generic, "Stopped due
3220 to shlib event" message.) */
3221 printf_filtered (_("Stopped due to shared library event\n"));
3222 result
= PRINT_NOTHING
;
3225 case bp_thread_event
:
3226 /* Not sure how we will get here.
3227 GDB should not stop for these breakpoints. */
3228 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3229 result
= PRINT_NOTHING
;
3232 case bp_overlay_event
:
3233 /* By analogy with the thread event, GDB should not stop for these. */
3234 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3235 result
= PRINT_NOTHING
;
3238 case bp_longjmp_master
:
3239 /* These should never be enabled. */
3240 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3241 result
= PRINT_NOTHING
;
3244 case bp_std_terminate_master
:
3245 /* These should never be enabled. */
3246 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3247 result
= PRINT_NOTHING
;
3251 case bp_hardware_watchpoint
:
3252 annotate_watchpoint (b
->number
);
3253 if (ui_out_is_mi_like_p (uiout
))
3256 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3258 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3259 ui_out_text (uiout
, "\nOld value = ");
3260 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3261 ui_out_field_stream (uiout
, "old", stb
);
3262 ui_out_text (uiout
, "\nNew value = ");
3263 watchpoint_value_print (b
->val
, stb
->stream
);
3264 ui_out_field_stream (uiout
, "new", stb
);
3265 ui_out_text (uiout
, "\n");
3266 /* More than one watchpoint may have been triggered. */
3267 result
= PRINT_UNKNOWN
;
3270 case bp_read_watchpoint
:
3271 if (ui_out_is_mi_like_p (uiout
))
3274 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3276 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3277 ui_out_text (uiout
, "\nValue = ");
3278 watchpoint_value_print (b
->val
, stb
->stream
);
3279 ui_out_field_stream (uiout
, "value", stb
);
3280 ui_out_text (uiout
, "\n");
3281 result
= PRINT_UNKNOWN
;
3284 case bp_access_watchpoint
:
3285 if (bs
->old_val
!= NULL
)
3287 annotate_watchpoint (b
->number
);
3288 if (ui_out_is_mi_like_p (uiout
))
3291 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3293 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3294 ui_out_text (uiout
, "\nOld value = ");
3295 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3296 ui_out_field_stream (uiout
, "old", stb
);
3297 ui_out_text (uiout
, "\nNew value = ");
3302 if (ui_out_is_mi_like_p (uiout
))
3305 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3306 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3307 ui_out_text (uiout
, "\nValue = ");
3309 watchpoint_value_print (b
->val
, stb
->stream
);
3310 ui_out_field_stream (uiout
, "new", stb
);
3311 ui_out_text (uiout
, "\n");
3312 result
= PRINT_UNKNOWN
;
3315 /* Fall through, we don't deal with these types of breakpoints
3319 if (ui_out_is_mi_like_p (uiout
))
3322 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3323 result
= PRINT_UNKNOWN
;
3327 if (ui_out_is_mi_like_p (uiout
))
3330 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3331 result
= PRINT_UNKNOWN
;
3336 case bp_longjmp_resume
:
3337 case bp_step_resume
:
3338 case bp_watchpoint_scope
:
3340 case bp_std_terminate
:
3342 case bp_fast_tracepoint
:
3345 result
= PRINT_UNKNOWN
;
3349 do_cleanups (old_chain
);
3353 /* Generic routine for printing messages indicating why we
3354 stopped. The behavior of this function depends on the value
3355 'print_it' in the bpstat structure. Under some circumstances we
3356 may decide not to print anything here and delegate the task to
3359 static enum print_stop_action
3360 print_bp_stop_message (bpstat bs
)
3362 switch (bs
->print_it
)
3365 /* Nothing should be printed for this bpstat entry. */
3366 return PRINT_UNKNOWN
;
3370 /* We still want to print the frame, but we already printed the
3371 relevant messages. */
3372 return PRINT_SRC_AND_LOC
;
3375 case print_it_normal
:
3377 const struct bp_location
*bl
= bs
->breakpoint_at
;
3378 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3380 /* Normal case. Call the breakpoint's print_it method, or
3381 print_it_typical. */
3382 /* FIXME: how breakpoint can ever be NULL here? */
3383 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3384 return b
->ops
->print_it (b
);
3386 return print_it_typical (bs
);
3391 internal_error (__FILE__
, __LINE__
,
3392 _("print_bp_stop_message: unrecognized enum value"));
3397 /* Print a message indicating what happened. This is called from
3398 normal_stop(). The input to this routine is the head of the bpstat
3399 list - a list of the eventpoints that caused this stop. This
3400 routine calls the generic print routine for printing a message
3401 about reasons for stopping. This will print (for example) the
3402 "Breakpoint n," part of the output. The return value of this
3405 PRINT_UNKNOWN: Means we printed nothing
3406 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3407 code to print the location. An example is
3408 "Breakpoint 1, " which should be followed by
3410 PRINT_SRC_ONLY: Means we printed something, but there is no need
3411 to also print the location part of the message.
3412 An example is the catch/throw messages, which
3413 don't require a location appended to the end.
3414 PRINT_NOTHING: We have done some printing and we don't need any
3415 further info to be printed.*/
3417 enum print_stop_action
3418 bpstat_print (bpstat bs
)
3422 /* Maybe another breakpoint in the chain caused us to stop.
3423 (Currently all watchpoints go on the bpstat whether hit or not.
3424 That probably could (should) be changed, provided care is taken
3425 with respect to bpstat_explains_signal). */
3426 for (; bs
; bs
= bs
->next
)
3428 val
= print_bp_stop_message (bs
);
3429 if (val
== PRINT_SRC_ONLY
3430 || val
== PRINT_SRC_AND_LOC
3431 || val
== PRINT_NOTHING
)
3435 /* We reached the end of the chain, or we got a null BS to start
3436 with and nothing was printed. */
3437 return PRINT_UNKNOWN
;
3440 /* Evaluate the expression EXP and return 1 if value is zero.
3441 This is used inside a catch_errors to evaluate the breakpoint condition.
3442 The argument is a "struct expression *" that has been cast to char * to
3443 make it pass through catch_errors. */
3446 breakpoint_cond_eval (void *exp
)
3448 struct value
*mark
= value_mark ();
3449 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3450 value_free_to_mark (mark
);
3454 /* Allocate a new bpstat and chain it to the current one. */
3457 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3461 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3463 bs
->breakpoint_at
= bl
;
3464 /* If the condition is false, etc., don't do the commands. */
3465 bs
->commands
= NULL
;
3466 bs
->commands_left
= NULL
;
3468 bs
->print_it
= print_it_normal
;
3472 /* The target has stopped with waitstatus WS. Check if any hardware
3473 watchpoints have triggered, according to the target. */
3476 watchpoints_triggered (struct target_waitstatus
*ws
)
3478 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3480 struct breakpoint
*b
;
3482 if (!stopped_by_watchpoint
)
3484 /* We were not stopped by a watchpoint. Mark all watchpoints
3485 as not triggered. */
3487 if (b
->type
== bp_hardware_watchpoint
3488 || b
->type
== bp_read_watchpoint
3489 || b
->type
== bp_access_watchpoint
)
3490 b
->watchpoint_triggered
= watch_triggered_no
;
3495 if (!target_stopped_data_address (¤t_target
, &addr
))
3497 /* We were stopped by a watchpoint, but we don't know where.
3498 Mark all watchpoints as unknown. */
3500 if (b
->type
== bp_hardware_watchpoint
3501 || b
->type
== bp_read_watchpoint
3502 || b
->type
== bp_access_watchpoint
)
3503 b
->watchpoint_triggered
= watch_triggered_unknown
;
3505 return stopped_by_watchpoint
;
3508 /* The target could report the data address. Mark watchpoints
3509 affected by this data address as triggered, and all others as not
3513 if (b
->type
== bp_hardware_watchpoint
3514 || b
->type
== bp_read_watchpoint
3515 || b
->type
== bp_access_watchpoint
)
3517 struct bp_location
*loc
;
3520 b
->watchpoint_triggered
= watch_triggered_no
;
3521 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3522 /* Exact match not required. Within range is
3524 if (target_watchpoint_addr_within_range (¤t_target
,
3528 b
->watchpoint_triggered
= watch_triggered_yes
;
3536 /* Possible return values for watchpoint_check (this can't be an enum
3537 because of check_errors). */
3538 /* The watchpoint has been deleted. */
3539 #define WP_DELETED 1
3540 /* The value has changed. */
3541 #define WP_VALUE_CHANGED 2
3542 /* The value has not changed. */
3543 #define WP_VALUE_NOT_CHANGED 3
3544 /* Ignore this watchpoint, no matter if the value changed or not. */
3547 #define BP_TEMPFLAG 1
3548 #define BP_HARDWAREFLAG 2
3550 /* Evaluate watchpoint condition expression and check if its value changed.
3552 P should be a pointer to struct bpstat, but is defined as a void *
3553 in order for this function to be usable with catch_errors. */
3556 watchpoint_check (void *p
)
3558 bpstat bs
= (bpstat
) p
;
3559 struct breakpoint
*b
;
3560 struct frame_info
*fr
;
3561 int within_current_scope
;
3563 b
= bs
->breakpoint_at
->owner
;
3565 /* If this is a local watchpoint, we only want to check if the
3566 watchpoint frame is in scope if the current thread is the thread
3567 that was used to create the watchpoint. */
3568 if (!watchpoint_in_thread_scope (b
))
3571 if (b
->exp_valid_block
== NULL
)
3572 within_current_scope
= 1;
3575 struct frame_info
*frame
= get_current_frame ();
3576 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3577 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3579 /* in_function_epilogue_p() returns a non-zero value if we're still
3580 in the function but the stack frame has already been invalidated.
3581 Since we can't rely on the values of local variables after the
3582 stack has been destroyed, we are treating the watchpoint in that
3583 state as `not changed' without further checking. Don't mark
3584 watchpoints as changed if the current frame is in an epilogue -
3585 even if they are in some other frame, our view of the stack
3586 is likely to be wrong and frame_find_by_id could error out. */
3587 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3590 fr
= frame_find_by_id (b
->watchpoint_frame
);
3591 within_current_scope
= (fr
!= NULL
);
3593 /* If we've gotten confused in the unwinder, we might have
3594 returned a frame that can't describe this variable. */
3595 if (within_current_scope
)
3597 struct symbol
*function
;
3599 function
= get_frame_function (fr
);
3600 if (function
== NULL
3601 || !contained_in (b
->exp_valid_block
,
3602 SYMBOL_BLOCK_VALUE (function
)))
3603 within_current_scope
= 0;
3606 if (within_current_scope
)
3607 /* If we end up stopping, the current frame will get selected
3608 in normal_stop. So this call to select_frame won't affect
3613 if (within_current_scope
)
3615 /* We use value_{,free_to_}mark because it could be a
3616 *long* time before we return to the command level and
3617 call free_all_values. We can't call free_all_values because
3618 we might be in the middle of evaluating a function call. */
3620 struct value
*mark
= value_mark ();
3621 struct value
*new_val
;
3623 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3625 /* We use value_equal_contents instead of value_equal because the latter
3626 coerces an array to a pointer, thus comparing just the address of the
3627 array instead of its contents. This is not what we want. */
3628 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3629 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3631 if (new_val
!= NULL
)
3633 release_value (new_val
);
3634 value_free_to_mark (mark
);
3636 bs
->old_val
= b
->val
;
3639 return WP_VALUE_CHANGED
;
3643 /* Nothing changed. */
3644 value_free_to_mark (mark
);
3645 return WP_VALUE_NOT_CHANGED
;
3650 /* This seems like the only logical thing to do because
3651 if we temporarily ignored the watchpoint, then when
3652 we reenter the block in which it is valid it contains
3653 garbage (in the case of a function, it may have two
3654 garbage values, one before and one after the prologue).
3655 So we can't even detect the first assignment to it and
3656 watch after that (since the garbage may or may not equal
3657 the first value assigned). */
3658 /* We print all the stop information in print_it_typical(), but
3659 in this case, by the time we call print_it_typical() this bp
3660 will be deleted already. So we have no choice but print the
3661 information here. */
3662 if (ui_out_is_mi_like_p (uiout
))
3664 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3665 ui_out_text (uiout
, "\nWatchpoint ");
3666 ui_out_field_int (uiout
, "wpnum", b
->number
);
3667 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3668 which its expression is valid.\n");
3670 if (b
->related_breakpoint
)
3672 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3673 b
->related_breakpoint
->related_breakpoint
= NULL
;
3674 b
->related_breakpoint
= NULL
;
3676 b
->disposition
= disp_del_at_next_stop
;
3682 /* Return true if it looks like target has stopped due to hitting
3683 breakpoint location BL. This function does not check if we
3684 should stop, only if BL explains the stop. */
3686 bpstat_check_location (const struct bp_location
*bl
,
3687 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3689 struct breakpoint
*b
= bl
->owner
;
3691 /* By definition, the inferior does not report stops at
3693 if (tracepoint_type (b
))
3696 if (b
->type
!= bp_watchpoint
3697 && b
->type
!= bp_hardware_watchpoint
3698 && b
->type
!= bp_read_watchpoint
3699 && b
->type
!= bp_access_watchpoint
3700 && b
->type
!= bp_hardware_breakpoint
3701 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3703 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3706 if (overlay_debugging
/* unmapped overlay section */
3707 && section_is_overlay (bl
->section
)
3708 && !section_is_mapped (bl
->section
))
3712 /* Continuable hardware watchpoints are treated as non-existent if the
3713 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3714 some data address). Otherwise gdb won't stop on a break instruction
3715 in the code (not from a breakpoint) when a hardware watchpoint has
3716 been defined. Also skip watchpoints which we know did not trigger
3717 (did not match the data address). */
3719 if ((b
->type
== bp_hardware_watchpoint
3720 || b
->type
== bp_read_watchpoint
3721 || b
->type
== bp_access_watchpoint
)
3722 && b
->watchpoint_triggered
== watch_triggered_no
)
3725 if (b
->type
== bp_hardware_breakpoint
)
3727 if (bl
->address
!= bp_addr
)
3729 if (overlay_debugging
/* unmapped overlay section */
3730 && section_is_overlay (bl
->section
)
3731 && !section_is_mapped (bl
->section
))
3735 if (b
->type
== bp_catchpoint
)
3737 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3738 if (!b
->ops
->breakpoint_hit (b
))
3745 /* If BS refers to a watchpoint, determine if the watched values
3746 has actually changed, and we should stop. If not, set BS->stop
3749 bpstat_check_watchpoint (bpstat bs
)
3751 const struct bp_location
*bl
= bs
->breakpoint_at
;
3752 struct breakpoint
*b
= bl
->owner
;
3754 if (b
->type
== bp_watchpoint
3755 || b
->type
== bp_read_watchpoint
3756 || b
->type
== bp_access_watchpoint
3757 || b
->type
== bp_hardware_watchpoint
)
3761 int must_check_value
= 0;
3763 if (b
->type
== bp_watchpoint
)
3764 /* For a software watchpoint, we must always check the
3766 must_check_value
= 1;
3767 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3768 /* We have a hardware watchpoint (read, write, or access)
3769 and the target earlier reported an address watched by
3771 must_check_value
= 1;
3772 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3773 && b
->type
== bp_hardware_watchpoint
)
3774 /* We were stopped by a hardware watchpoint, but the target could
3775 not report the data address. We must check the watchpoint's
3776 value. Access and read watchpoints are out of luck; without
3777 a data address, we can't figure it out. */
3778 must_check_value
= 1;
3780 if (must_check_value
)
3782 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3784 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3785 int e
= catch_errors (watchpoint_check
, bs
, message
,
3787 do_cleanups (cleanups
);
3791 /* We've already printed what needs to be printed. */
3792 bs
->print_it
= print_it_done
;
3796 bs
->print_it
= print_it_noop
;
3799 case WP_VALUE_CHANGED
:
3800 if (b
->type
== bp_read_watchpoint
)
3802 /* There are two cases to consider here:
3804 1. we're watching the triggered memory for reads.
3805 In that case, trust the target, and always report
3806 the watchpoint hit to the user. Even though
3807 reads don't cause value changes, the value may
3808 have changed since the last time it was read, and
3809 since we're not trapping writes, we will not see
3810 those, and as such we should ignore our notion of
3813 2. we're watching the triggered memory for both
3814 reads and writes. There are two ways this may
3817 2.1. this is a target that can't break on data
3818 reads only, but can break on accesses (reads or
3819 writes), such as e.g., x86. We detect this case
3820 at the time we try to insert read watchpoints.
3822 2.2. otherwise, the target supports read
3823 watchpoints, but, the user set an access or write
3824 watchpoint watching the same memory as this read
3827 If we're watching memory writes as well as reads,
3828 ignore watchpoint hits when we find that the
3829 value hasn't changed, as reads don't cause
3830 changes. This still gives false positives when
3831 the program writes the same value to memory as
3832 what there was already in memory (we will confuse
3833 it for a read), but it's much better than
3836 int other_write_watchpoint
= 0;
3838 if (bl
->watchpoint_type
== hw_read
)
3840 struct breakpoint
*other_b
;
3842 ALL_BREAKPOINTS (other_b
)
3843 if ((other_b
->type
== bp_hardware_watchpoint
3844 || other_b
->type
== bp_access_watchpoint
)
3845 && (other_b
->watchpoint_triggered
3846 == watch_triggered_yes
))
3848 other_write_watchpoint
= 1;
3853 if (other_write_watchpoint
3854 || bl
->watchpoint_type
== hw_access
)
3856 /* We're watching the same memory for writes,
3857 and the value changed since the last time we
3858 updated it, so this trap must be for a write.
3860 bs
->print_it
= print_it_noop
;
3865 case WP_VALUE_NOT_CHANGED
:
3866 if (b
->type
== bp_hardware_watchpoint
3867 || b
->type
== bp_watchpoint
)
3869 /* Don't stop: write watchpoints shouldn't fire if
3870 the value hasn't changed. */
3871 bs
->print_it
= print_it_noop
;
3879 /* Error from catch_errors. */
3880 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3881 if (b
->related_breakpoint
)
3882 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3883 b
->disposition
= disp_del_at_next_stop
;
3884 /* We've already printed what needs to be printed. */
3885 bs
->print_it
= print_it_done
;
3889 else /* must_check_value == 0 */
3891 /* This is a case where some watchpoint(s) triggered, but
3892 not at the address of this watchpoint, or else no
3893 watchpoint triggered after all. So don't print
3894 anything for this watchpoint. */
3895 bs
->print_it
= print_it_noop
;
3902 /* Check conditions (condition proper, frame, thread and ignore count)
3903 of breakpoint referred to by BS. If we should not stop for this
3904 breakpoint, set BS->stop to 0. */
3906 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3908 int thread_id
= pid_to_thread_id (ptid
);
3909 const struct bp_location
*bl
= bs
->breakpoint_at
;
3910 struct breakpoint
*b
= bl
->owner
;
3912 if (frame_id_p (b
->frame_id
)
3913 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3917 int value_is_zero
= 0;
3918 struct expression
*cond
;
3920 /* If this is a scope breakpoint, mark the associated
3921 watchpoint as triggered so that we will handle the
3922 out-of-scope event. We'll get to the watchpoint next
3924 if (b
->type
== bp_watchpoint_scope
)
3925 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3927 if (is_watchpoint (b
))
3932 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3934 int within_current_scope
= 1;
3936 /* We use value_mark and value_free_to_mark because it could
3937 be a long time before we return to the command level and
3938 call free_all_values. We can't call free_all_values
3939 because we might be in the middle of evaluating a
3941 struct value
*mark
= value_mark ();
3943 /* Need to select the frame, with all that implies so that
3944 the conditions will have the right context. Because we
3945 use the frame, we will not see an inlined function's
3946 variables when we arrive at a breakpoint at the start
3947 of the inlined function; the current frame will be the
3949 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3950 select_frame (get_current_frame ());
3953 struct frame_info
*frame
;
3955 /* For local watchpoint expressions, which particular
3956 instance of a local is being watched matters, so we
3957 keep track of the frame to evaluate the expression
3958 in. To evaluate the condition however, it doesn't
3959 really matter which instantiation of the function
3960 where the condition makes sense triggers the
3961 watchpoint. This allows an expression like "watch
3962 global if q > 10" set in `func', catch writes to
3963 global on all threads that call `func', or catch
3964 writes on all recursive calls of `func' by a single
3965 thread. We simply always evaluate the condition in
3966 the innermost frame that's executing where it makes
3967 sense to evaluate the condition. It seems
3969 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3971 select_frame (frame
);
3973 within_current_scope
= 0;
3975 if (within_current_scope
)
3977 = catch_errors (breakpoint_cond_eval
, cond
,
3978 "Error in testing breakpoint condition:\n",
3982 warning (_("Watchpoint condition cannot be tested "
3983 "in the current scope"));
3984 /* If we failed to set the right context for this
3985 watchpoint, unconditionally report it. */
3988 /* FIXME-someday, should give breakpoint # */
3989 value_free_to_mark (mark
);
3992 if (cond
&& value_is_zero
)
3996 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4000 else if (b
->ignore_count
> 0)
4003 annotate_ignore_count_change ();
4005 /* Increase the hit count even though we don't
4013 /* Get a bpstat associated with having just stopped at address
4014 BP_ADDR in thread PTID.
4016 Determine whether we stopped at a breakpoint, etc, or whether we
4017 don't understand this stop. Result is a chain of bpstat's such that:
4019 if we don't understand the stop, the result is a null pointer.
4021 if we understand why we stopped, the result is not null.
4023 Each element of the chain refers to a particular breakpoint or
4024 watchpoint at which we have stopped. (We may have stopped for
4025 several reasons concurrently.)
4027 Each element of the chain has valid next, breakpoint_at,
4028 commands, FIXME??? fields. */
4031 bpstat_stop_status (struct address_space
*aspace
,
4032 CORE_ADDR bp_addr
, ptid_t ptid
)
4034 struct breakpoint
*b
= NULL
;
4035 struct bp_location
*bl
, **blp_tmp
;
4036 struct bp_location
*loc
;
4037 /* Root of the chain of bpstat's */
4038 struct bpstats root_bs
[1];
4039 /* Pointer to the last thing in the chain currently. */
4040 bpstat bs
= root_bs
;
4042 int need_remove_insert
;
4044 /* ALL_BP_LOCATIONS iteration would break across
4045 update_global_location_list possibly executed by
4046 bpstat_check_breakpoint_conditions's inferior call. */
4050 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4053 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4055 /* For hardware watchpoints, we look only at the first location.
4056 The watchpoint_check function will work on entire expression,
4057 not the individual locations. For read watchopints, the
4058 watchpoints_triggered function have checked all locations
4060 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4063 if (bl
->shlib_disabled
)
4066 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4069 /* Come here if it's a watchpoint, or if the break address matches */
4071 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4073 /* Assume we stop. Should we find watchpoint that is not actually
4074 triggered, or if condition of breakpoint is false, we'll reset
4079 bpstat_check_watchpoint (bs
);
4083 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4084 || b
->type
== bp_longjmp_master
4085 || b
->type
== bp_std_terminate_master
)
4086 /* We do not stop for these. */
4089 bpstat_check_breakpoint_conditions (bs
, ptid
);
4095 /* We will stop here */
4096 if (b
->disposition
== disp_disable
)
4098 if (b
->enable_state
!= bp_permanent
)
4099 b
->enable_state
= bp_disabled
;
4100 update_global_location_list (0);
4104 bs
->commands
= b
->commands
;
4105 incref_counted_command_line (bs
->commands
);
4106 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4107 if (bs
->commands_left
4108 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4111 bs
->commands_left
->line
) == 0)))
4113 bs
->commands_left
= bs
->commands_left
->next
;
4118 /* Print nothing for this entry if we dont stop or dont print. */
4119 if (bs
->stop
== 0 || bs
->print
== 0)
4120 bs
->print_it
= print_it_noop
;
4124 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4126 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4129 bs
= bpstat_alloc (loc
, bs
);
4130 /* For hits of moribund locations, we should just proceed. */
4133 bs
->print_it
= print_it_noop
;
4137 bs
->next
= NULL
; /* Terminate the chain */
4139 /* If we aren't stopping, the value of some hardware watchpoint may
4140 not have changed, but the intermediate memory locations we are
4141 watching may have. Don't bother if we're stopping; this will get
4143 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4147 need_remove_insert
= 0;
4149 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4151 && bs
->breakpoint_at
->owner
4152 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4154 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4155 /* Updating watchpoints invalidates bs->breakpoint_at.
4156 Prevent further code from trying to use it. */
4157 bs
->breakpoint_at
= NULL
;
4158 need_remove_insert
= 1;
4161 if (need_remove_insert
)
4162 update_global_location_list (1);
4164 return root_bs
->next
;
4167 /* Tell what to do about this bpstat. */
4169 bpstat_what (bpstat bs
)
4171 /* Classify each bpstat as one of the following. */
4174 /* This bpstat element has no effect on the main_action. */
4177 /* There was a watchpoint, stop but don't print. */
4180 /* There was a watchpoint, stop and print. */
4183 /* There was a breakpoint but we're not stopping. */
4186 /* There was a breakpoint, stop but don't print. */
4189 /* There was a breakpoint, stop and print. */
4192 /* We hit the longjmp breakpoint. */
4195 /* We hit the longjmp_resume breakpoint. */
4198 /* We hit the step_resume breakpoint. */
4201 /* We hit the shared library event breakpoint. */
4204 /* We hit the jit event breakpoint. */
4207 /* This is just used to count how many enums there are. */
4211 /* Here is the table which drives this routine. So that we can
4212 format it pretty, we define some abbreviations for the
4213 enum bpstat_what codes. */
4214 #define kc BPSTAT_WHAT_KEEP_CHECKING
4215 #define ss BPSTAT_WHAT_STOP_SILENT
4216 #define sn BPSTAT_WHAT_STOP_NOISY
4217 #define sgl BPSTAT_WHAT_SINGLE
4218 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4219 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4220 #define sr BPSTAT_WHAT_STEP_RESUME
4221 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4222 #define jit BPSTAT_WHAT_CHECK_JIT
4224 /* "Can't happen." Might want to print an error message.
4225 abort() is not out of the question, but chances are GDB is just
4226 a bit confused, not unusable. */
4227 #define err BPSTAT_WHAT_STOP_NOISY
4229 /* Given an old action and a class, come up with a new action. */
4230 /* One interesting property of this table is that wp_silent is the same
4231 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4232 after stopping, the check for whether to step over a breakpoint
4233 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4234 reference to how we stopped. We retain separate wp_silent and
4235 bp_silent codes in case we want to change that someday.
4237 Another possibly interesting property of this table is that
4238 there's a partial ordering, priority-like, of the actions. Once
4239 you've decided that some action is appropriate, you'll never go
4240 back and decide something of a lower priority is better. The
4243 kc < jit clr sgl shl slr sn sr ss
4244 sgl < jit shl slr sn sr ss
4245 slr < jit err shl sn sr ss
4246 clr < jit err shl sn sr ss
4253 What I think this means is that we don't need a damned table
4254 here. If you just put the rows and columns in the right order,
4255 it'd look awfully regular. We could simply walk the bpstat list
4256 and choose the highest priority action we find, with a little
4257 logic to handle the 'err' cases. */
4259 /* step_resume entries: a step resume breakpoint overrides another
4260 breakpoint of signal handling (see comment in wait_for_inferior
4261 at where we set the step_resume breakpoint). */
4263 static const enum bpstat_what_main_action
4264 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4267 /* kc ss sn sgl slr clr sr shl jit */
4268 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4269 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4270 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4271 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4272 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4273 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4274 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4275 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4276 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4277 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4278 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4292 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4293 struct bpstat_what retval
;
4295 retval
.call_dummy
= STOP_NONE
;
4296 for (; bs
!= NULL
; bs
= bs
->next
)
4298 enum class bs_class
= no_effect
;
4299 if (bs
->breakpoint_at
== NULL
)
4300 /* I suspect this can happen if it was a momentary breakpoint
4301 which has since been deleted. */
4303 if (bs
->breakpoint_at
->owner
== NULL
)
4304 bs_class
= bp_nostop
;
4306 switch (bs
->breakpoint_at
->owner
->type
)
4312 case bp_hardware_breakpoint
:
4318 bs_class
= bp_noisy
;
4320 bs_class
= bp_silent
;
4323 bs_class
= bp_nostop
;
4326 case bp_hardware_watchpoint
:
4327 case bp_read_watchpoint
:
4328 case bp_access_watchpoint
:
4332 bs_class
= wp_noisy
;
4334 bs_class
= wp_silent
;
4337 /* There was a watchpoint, but we're not stopping.
4338 This requires no further action. */
4339 bs_class
= no_effect
;
4342 bs_class
= long_jump
;
4344 case bp_longjmp_resume
:
4345 bs_class
= long_resume
;
4347 case bp_step_resume
:
4350 bs_class
= step_resume
;
4353 /* It is for the wrong frame. */
4354 bs_class
= bp_nostop
;
4356 case bp_watchpoint_scope
:
4357 bs_class
= bp_nostop
;
4359 case bp_shlib_event
:
4360 bs_class
= shlib_event
;
4363 bs_class
= jit_event
;
4365 case bp_thread_event
:
4366 case bp_overlay_event
:
4367 case bp_longjmp_master
:
4368 case bp_std_terminate_master
:
4369 bs_class
= bp_nostop
;
4375 bs_class
= bp_noisy
;
4377 bs_class
= bp_silent
;
4380 /* There was a catchpoint, but we're not stopping.
4381 This requires no further action. */
4382 bs_class
= no_effect
;
4385 /* Make sure the action is stop (silent or noisy),
4386 so infrun.c pops the dummy frame. */
4387 bs_class
= bp_silent
;
4388 retval
.call_dummy
= STOP_STACK_DUMMY
;
4390 case bp_std_terminate
:
4391 /* Make sure the action is stop (silent or noisy),
4392 so infrun.c pops the dummy frame. */
4393 bs_class
= bp_silent
;
4394 retval
.call_dummy
= STOP_STD_TERMINATE
;
4397 case bp_fast_tracepoint
:
4398 /* Tracepoint hits should not be reported back to GDB, and
4399 if one got through somehow, it should have been filtered
4401 internal_error (__FILE__
, __LINE__
,
4402 _("bpstat_what: tracepoint encountered"));
4405 current_action
= table
[(int) bs_class
][(int) current_action
];
4407 retval
.main_action
= current_action
;
4411 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4412 without hardware support). This isn't related to a specific bpstat,
4413 just to things like whether watchpoints are set. */
4416 bpstat_should_step (void)
4418 struct breakpoint
*b
;
4420 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4426 bpstat_causes_stop (bpstat bs
)
4428 for (; bs
!= NULL
; bs
= bs
->next
)
4437 /* Print the LOC location out of the list of B->LOC locations. */
4439 static void print_breakpoint_location (struct breakpoint
*b
,
4440 struct bp_location
*loc
,
4442 struct ui_stream
*stb
)
4444 struct cleanup
*old_chain
= save_current_program_space ();
4446 if (loc
!= NULL
&& loc
->shlib_disabled
)
4450 set_current_program_space (loc
->pspace
);
4452 if (b
->source_file
&& loc
)
4455 = find_pc_sect_function (loc
->address
, loc
->section
);
4458 ui_out_text (uiout
, "in ");
4459 ui_out_field_string (uiout
, "func",
4460 SYMBOL_PRINT_NAME (sym
));
4461 ui_out_wrap_hint (uiout
, wrap_indent
);
4462 ui_out_text (uiout
, " at ");
4464 ui_out_field_string (uiout
, "file", b
->source_file
);
4465 ui_out_text (uiout
, ":");
4467 if (ui_out_is_mi_like_p (uiout
))
4469 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4470 char *fullname
= symtab_to_fullname (sal
.symtab
);
4473 ui_out_field_string (uiout
, "fullname", fullname
);
4476 ui_out_field_int (uiout
, "line", b
->line_number
);
4480 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4482 ui_out_field_stream (uiout
, "at", stb
);
4485 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4487 do_cleanups (old_chain
);
4490 /* Print B to gdb_stdout. */
4492 print_one_breakpoint_location (struct breakpoint
*b
,
4493 struct bp_location
*loc
,
4495 struct bp_location
**last_loc
,
4496 int print_address_bits
,
4499 struct command_line
*l
;
4501 struct ep_type_description
4506 static struct ep_type_description bptypes
[] =
4508 {bp_none
, "?deleted?"},
4509 {bp_breakpoint
, "breakpoint"},
4510 {bp_hardware_breakpoint
, "hw breakpoint"},
4511 {bp_until
, "until"},
4512 {bp_finish
, "finish"},
4513 {bp_watchpoint
, "watchpoint"},
4514 {bp_hardware_watchpoint
, "hw watchpoint"},
4515 {bp_read_watchpoint
, "read watchpoint"},
4516 {bp_access_watchpoint
, "acc watchpoint"},
4517 {bp_longjmp
, "longjmp"},
4518 {bp_longjmp_resume
, "longjmp resume"},
4519 {bp_step_resume
, "step resume"},
4520 {bp_watchpoint_scope
, "watchpoint scope"},
4521 {bp_call_dummy
, "call dummy"},
4522 {bp_std_terminate
, "std::terminate"},
4523 {bp_shlib_event
, "shlib events"},
4524 {bp_thread_event
, "thread events"},
4525 {bp_overlay_event
, "overlay events"},
4526 {bp_longjmp_master
, "longjmp master"},
4527 {bp_std_terminate_master
, "std::terminate master"},
4528 {bp_catchpoint
, "catchpoint"},
4529 {bp_tracepoint
, "tracepoint"},
4530 {bp_fast_tracepoint
, "fast tracepoint"},
4531 {bp_jit_event
, "jit events"},
4534 static char bpenables
[] = "nynny";
4535 char wrap_indent
[80];
4536 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4537 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4538 struct cleanup
*bkpt_chain
;
4540 int header_of_multiple
= 0;
4541 int part_of_multiple
= (loc
!= NULL
);
4542 struct value_print_options opts
;
4544 get_user_print_options (&opts
);
4546 gdb_assert (!loc
|| loc_number
!= 0);
4547 /* See comment in print_one_breakpoint concerning
4548 treatment of breakpoints with single disabled
4552 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4553 header_of_multiple
= 1;
4558 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4562 if (part_of_multiple
)
4565 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4566 ui_out_field_string (uiout
, "number", formatted
);
4571 ui_out_field_int (uiout
, "number", b
->number
);
4576 if (part_of_multiple
)
4577 ui_out_field_skip (uiout
, "type");
4580 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4581 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4582 internal_error (__FILE__
, __LINE__
,
4583 _("bptypes table does not describe type #%d."),
4585 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4590 if (part_of_multiple
)
4591 ui_out_field_skip (uiout
, "disp");
4593 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4598 if (part_of_multiple
)
4599 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4601 ui_out_field_fmt (uiout
, "enabled", "%c",
4602 bpenables
[(int) b
->enable_state
]);
4603 ui_out_spaces (uiout
, 2);
4607 strcpy (wrap_indent
, " ");
4608 if (opts
.addressprint
)
4610 if (print_address_bits
<= 32)
4611 strcat (wrap_indent
, " ");
4613 strcat (wrap_indent
, " ");
4616 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4618 /* Although the print_one can possibly print
4619 all locations, calling it here is not likely
4620 to get any nice result. So, make sure there's
4621 just one location. */
4622 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4623 b
->ops
->print_one (b
, last_loc
);
4629 internal_error (__FILE__
, __LINE__
,
4630 _("print_one_breakpoint: bp_none encountered\n"));
4634 case bp_hardware_watchpoint
:
4635 case bp_read_watchpoint
:
4636 case bp_access_watchpoint
:
4637 /* Field 4, the address, is omitted (which makes the columns
4638 not line up too nicely with the headers, but the effect
4639 is relatively readable). */
4640 if (opts
.addressprint
)
4641 ui_out_field_skip (uiout
, "addr");
4643 ui_out_field_string (uiout
, "what", b
->exp_string
);
4647 case bp_hardware_breakpoint
:
4651 case bp_longjmp_resume
:
4652 case bp_step_resume
:
4653 case bp_watchpoint_scope
:
4655 case bp_std_terminate
:
4656 case bp_shlib_event
:
4657 case bp_thread_event
:
4658 case bp_overlay_event
:
4659 case bp_longjmp_master
:
4660 case bp_std_terminate_master
:
4662 case bp_fast_tracepoint
:
4664 if (opts
.addressprint
)
4667 if (header_of_multiple
)
4668 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4669 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4670 ui_out_field_string (uiout
, "addr", "<PENDING>");
4672 ui_out_field_core_addr (uiout
, "addr",
4673 loc
->gdbarch
, loc
->address
);
4676 if (!header_of_multiple
)
4677 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4684 /* For backward compatibility, don't display inferiors unless there
4687 && !header_of_multiple
4689 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4690 && (number_of_program_spaces () > 1
4691 || number_of_inferiors () > 1)
4692 && loc
->owner
->type
!= bp_catchpoint
)))
4694 struct inferior
*inf
;
4697 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4699 if (inf
->pspace
== loc
->pspace
)
4704 ui_out_text (uiout
, " inf ");
4707 ui_out_text (uiout
, ", ");
4708 ui_out_text (uiout
, plongest (inf
->num
));
4713 if (!part_of_multiple
)
4715 if (b
->thread
!= -1)
4717 /* FIXME: This seems to be redundant and lost here; see the
4718 "stop only in" line a little further down. */
4719 ui_out_text (uiout
, " thread ");
4720 ui_out_field_int (uiout
, "thread", b
->thread
);
4722 else if (b
->task
!= 0)
4724 ui_out_text (uiout
, " task ");
4725 ui_out_field_int (uiout
, "task", b
->task
);
4729 ui_out_text (uiout
, "\n");
4731 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4734 ui_out_text (uiout
, "\tstop only in stack frame at ");
4735 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4737 ui_out_field_core_addr (uiout
, "frame",
4738 b
->gdbarch
, b
->frame_id
.stack_addr
);
4739 ui_out_text (uiout
, "\n");
4742 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4744 /* We do not print the condition for Ada exception catchpoints
4745 because the condition is an internal implementation detail
4746 that we do not want to expose to the user. */
4748 if (tracepoint_type (b
))
4749 ui_out_text (uiout
, "\ttrace only if ");
4751 ui_out_text (uiout
, "\tstop only if ");
4752 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4753 ui_out_text (uiout
, "\n");
4756 if (!part_of_multiple
&& b
->thread
!= -1)
4758 /* FIXME should make an annotation for this */
4759 ui_out_text (uiout
, "\tstop only in thread ");
4760 ui_out_field_int (uiout
, "thread", b
->thread
);
4761 ui_out_text (uiout
, "\n");
4764 if (!part_of_multiple
&& b
->hit_count
)
4766 /* FIXME should make an annotation for this */
4767 if (ep_is_catchpoint (b
))
4768 ui_out_text (uiout
, "\tcatchpoint");
4770 ui_out_text (uiout
, "\tbreakpoint");
4771 ui_out_text (uiout
, " already hit ");
4772 ui_out_field_int (uiout
, "times", b
->hit_count
);
4773 if (b
->hit_count
== 1)
4774 ui_out_text (uiout
, " time\n");
4776 ui_out_text (uiout
, " times\n");
4779 /* Output the count also if it is zero, but only if this is
4780 mi. FIXME: Should have a better test for this. */
4781 if (ui_out_is_mi_like_p (uiout
))
4782 if (!part_of_multiple
&& b
->hit_count
== 0)
4783 ui_out_field_int (uiout
, "times", b
->hit_count
);
4785 if (!part_of_multiple
&& b
->ignore_count
)
4788 ui_out_text (uiout
, "\tignore next ");
4789 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4790 ui_out_text (uiout
, " hits\n");
4793 l
= b
->commands
? b
->commands
->commands
: NULL
;
4794 if (!part_of_multiple
&& l
)
4796 struct cleanup
*script_chain
;
4799 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4800 print_command_lines (uiout
, l
, 4);
4801 do_cleanups (script_chain
);
4804 if (!part_of_multiple
&& b
->pass_count
)
4806 annotate_field (10);
4807 ui_out_text (uiout
, "\tpass count ");
4808 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4809 ui_out_text (uiout
, " \n");
4812 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4815 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4816 else if (b
->exp_string
)
4817 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4820 do_cleanups (bkpt_chain
);
4821 do_cleanups (old_chain
);
4825 print_one_breakpoint (struct breakpoint
*b
,
4826 struct bp_location
**last_loc
, int print_address_bits
,
4829 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4830 print_address_bits
, allflag
);
4832 /* If this breakpoint has custom print function,
4833 it's already printed. Otherwise, print individual
4834 locations, if any. */
4835 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4837 /* If breakpoint has a single location that is
4838 disabled, we print it as if it had
4839 several locations, since otherwise it's hard to
4840 represent "breakpoint enabled, location disabled"
4842 Note that while hardware watchpoints have
4843 several locations internally, that's no a property
4846 && !is_hardware_watchpoint (b
)
4847 && (b
->loc
->next
|| !b
->loc
->enabled
)
4848 && !ui_out_is_mi_like_p (uiout
))
4850 struct bp_location
*loc
;
4852 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4853 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4854 print_address_bits
, allflag
);
4860 breakpoint_address_bits (struct breakpoint
*b
)
4862 int print_address_bits
= 0;
4863 struct bp_location
*loc
;
4865 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4869 /* Software watchpoints that aren't watching memory don't have
4870 an address to print. */
4871 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4874 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4875 if (addr_bit
> print_address_bits
)
4876 print_address_bits
= addr_bit
;
4879 return print_address_bits
;
4882 struct captured_breakpoint_query_args
4888 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4890 struct captured_breakpoint_query_args
*args
= data
;
4891 struct breakpoint
*b
;
4892 struct bp_location
*dummy_loc
= NULL
;
4895 if (args
->bnum
== b
->number
)
4897 int print_address_bits
= breakpoint_address_bits (b
);
4898 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4906 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4908 struct captured_breakpoint_query_args args
;
4910 /* For the moment we don't trust print_one_breakpoint() to not throw
4912 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4913 error_message
, RETURN_MASK_ALL
) < 0)
4919 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4920 catchpoints, et.al.). */
4923 user_settable_breakpoint (const struct breakpoint
*b
)
4925 return (b
->type
== bp_breakpoint
4926 || b
->type
== bp_catchpoint
4927 || b
->type
== bp_hardware_breakpoint
4928 || tracepoint_type (b
)
4929 || b
->type
== bp_watchpoint
4930 || b
->type
== bp_read_watchpoint
4931 || b
->type
== bp_access_watchpoint
4932 || b
->type
== bp_hardware_watchpoint
);
4935 /* Print information on user settable breakpoint (watchpoint, etc)
4936 number BNUM. If BNUM is -1 print all user settable breakpoints.
4937 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4940 breakpoint_1 (int bnum
, int allflag
)
4942 struct breakpoint
*b
;
4943 struct bp_location
*last_loc
= NULL
;
4944 int nr_printable_breakpoints
;
4945 struct cleanup
*bkpttbl_chain
;
4946 struct value_print_options opts
;
4947 int print_address_bits
= 0;
4949 get_user_print_options (&opts
);
4951 /* Compute the number of rows in the table, as well as the
4952 size required for address fields. */
4953 nr_printable_breakpoints
= 0;
4956 || bnum
== b
->number
)
4958 if (allflag
|| user_settable_breakpoint (b
))
4960 int addr_bit
= breakpoint_address_bits (b
);
4961 if (addr_bit
> print_address_bits
)
4962 print_address_bits
= addr_bit
;
4964 nr_printable_breakpoints
++;
4968 if (opts
.addressprint
)
4970 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4974 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4977 if (nr_printable_breakpoints
> 0)
4978 annotate_breakpoints_headers ();
4979 if (nr_printable_breakpoints
> 0)
4981 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4982 if (nr_printable_breakpoints
> 0)
4984 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4985 if (nr_printable_breakpoints
> 0)
4987 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4988 if (nr_printable_breakpoints
> 0)
4990 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4991 if (opts
.addressprint
)
4993 if (nr_printable_breakpoints
> 0)
4995 if (print_address_bits
<= 32)
4996 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4998 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
5000 if (nr_printable_breakpoints
> 0)
5002 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5003 ui_out_table_body (uiout
);
5004 if (nr_printable_breakpoints
> 0)
5005 annotate_breakpoints_table ();
5011 || bnum
== b
->number
)
5013 /* We only print out user settable breakpoints unless the
5015 if (allflag
|| user_settable_breakpoint (b
))
5016 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5020 do_cleanups (bkpttbl_chain
);
5022 if (nr_printable_breakpoints
== 0)
5025 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5027 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5032 if (last_loc
&& !server_command
)
5033 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5036 /* FIXME? Should this be moved up so that it is only called when
5037 there have been breakpoints? */
5038 annotate_breakpoints_table_end ();
5042 breakpoints_info (char *bnum_exp
, int from_tty
)
5047 bnum
= parse_and_eval_long (bnum_exp
);
5049 breakpoint_1 (bnum
, 0);
5053 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5058 bnum
= parse_and_eval_long (bnum_exp
);
5060 breakpoint_1 (bnum
, 1);
5064 breakpoint_has_pc (struct breakpoint
*b
,
5065 struct program_space
*pspace
,
5066 CORE_ADDR pc
, struct obj_section
*section
)
5068 struct bp_location
*bl
= b
->loc
;
5069 for (; bl
; bl
= bl
->next
)
5071 if (bl
->pspace
== pspace
5072 && bl
->address
== pc
5073 && (!overlay_debugging
|| bl
->section
== section
))
5079 /* Print a message describing any breakpoints set at PC. This
5080 concerns with logical breakpoints, so we match program spaces, not
5084 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5085 struct program_space
*pspace
, CORE_ADDR pc
,
5086 struct obj_section
*section
, int thread
)
5089 struct breakpoint
*b
;
5092 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5096 printf_filtered (_("Note: breakpoint "));
5097 else /* if (others == ???) */
5098 printf_filtered (_("Note: breakpoints "));
5100 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5103 printf_filtered ("%d", b
->number
);
5104 if (b
->thread
== -1 && thread
!= -1)
5105 printf_filtered (" (all threads)");
5106 else if (b
->thread
!= -1)
5107 printf_filtered (" (thread %d)", b
->thread
);
5108 printf_filtered ("%s%s ",
5109 ((b
->enable_state
== bp_disabled
5110 || b
->enable_state
== bp_call_disabled
5111 || b
->enable_state
== bp_startup_disabled
)
5113 : b
->enable_state
== bp_permanent
5117 : ((others
== 1) ? " and" : ""));
5119 printf_filtered (_("also set at pc "));
5120 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5121 printf_filtered (".\n");
5125 /* Set the default place to put a breakpoint
5126 for the `break' command with no arguments. */
5129 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5130 CORE_ADDR addr
, struct symtab
*symtab
,
5133 default_breakpoint_valid
= valid
;
5134 default_breakpoint_pspace
= pspace
;
5135 default_breakpoint_address
= addr
;
5136 default_breakpoint_symtab
= symtab
;
5137 default_breakpoint_line
= line
;
5140 /* Return true iff it is meaningful to use the address member of
5141 BPT. For some breakpoint types, the address member is irrelevant
5142 and it makes no sense to attempt to compare it to other addresses
5143 (or use it for any other purpose either).
5145 More specifically, each of the following breakpoint types will always
5146 have a zero valued address and we don't want to mark breakpoints of any of
5147 these types to be a duplicate of an actual breakpoint at address zero:
5155 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5157 enum bptype type
= bpt
->type
;
5159 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5162 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5163 true if LOC1 and LOC2 represent the same watchpoint location. */
5166 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5168 /* Note that this checks the owner's type, not the location's. In
5169 case the target does not support read watchpoints, but does
5170 support access watchpoints, we'll have bp_read_watchpoint
5171 watchpoints with hw_access locations. Those should be considered
5172 duplicates of hw_read locations. The hw_read locations will
5173 become hw_access locations later. */
5174 return (loc1
->owner
->type
== loc2
->owner
->type
5175 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5176 && loc1
->address
== loc2
->address
5177 && loc1
->length
== loc2
->length
);
5180 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5181 same breakpoint location. In most targets, this can only be true
5182 if ASPACE1 matches ASPACE2. On targets that have global
5183 breakpoints, the address space doesn't really matter. */
5186 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5187 struct address_space
*aspace2
, CORE_ADDR addr2
)
5189 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5190 || aspace1
== aspace2
)
5194 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5195 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5196 represent the same location. */
5199 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5201 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5202 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5204 if (hw_point1
!= hw_point2
)
5207 return watchpoint_locations_match (loc1
, loc2
);
5209 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5210 loc2
->pspace
->aspace
, loc2
->address
);
5214 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5215 int bnum
, int have_bnum
)
5220 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5221 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5223 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5224 bnum
, astr1
, astr2
);
5226 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5229 /* Adjust a breakpoint's address to account for architectural constraints
5230 on breakpoint placement. Return the adjusted address. Note: Very
5231 few targets require this kind of adjustment. For most targets,
5232 this function is simply the identity function. */
5235 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5236 CORE_ADDR bpaddr
, enum bptype bptype
)
5238 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5240 /* Very few targets need any kind of breakpoint adjustment. */
5243 else if (bptype
== bp_watchpoint
5244 || bptype
== bp_hardware_watchpoint
5245 || bptype
== bp_read_watchpoint
5246 || bptype
== bp_access_watchpoint
5247 || bptype
== bp_catchpoint
)
5249 /* Watchpoints and the various bp_catch_* eventpoints should not
5250 have their addresses modified. */
5255 CORE_ADDR adjusted_bpaddr
;
5257 /* Some targets have architectural constraints on the placement
5258 of breakpoint instructions. Obtain the adjusted address. */
5259 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5261 /* An adjusted breakpoint address can significantly alter
5262 a user's expectations. Print a warning if an adjustment
5264 if (adjusted_bpaddr
!= bpaddr
)
5265 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5267 return adjusted_bpaddr
;
5271 /* Allocate a struct bp_location. */
5273 static struct bp_location
*
5274 allocate_bp_location (struct breakpoint
*bpt
)
5276 struct bp_location
*loc
, *loc_p
;
5278 loc
= xmalloc (sizeof (struct bp_location
));
5279 memset (loc
, 0, sizeof (*loc
));
5283 loc
->shlib_disabled
= 0;
5292 case bp_longjmp_resume
:
5293 case bp_step_resume
:
5294 case bp_watchpoint_scope
:
5296 case bp_std_terminate
:
5297 case bp_shlib_event
:
5298 case bp_thread_event
:
5299 case bp_overlay_event
:
5301 case bp_longjmp_master
:
5302 case bp_std_terminate_master
:
5303 loc
->loc_type
= bp_loc_software_breakpoint
;
5305 case bp_hardware_breakpoint
:
5306 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5308 case bp_hardware_watchpoint
:
5309 case bp_read_watchpoint
:
5310 case bp_access_watchpoint
:
5311 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5316 case bp_fast_tracepoint
:
5317 loc
->loc_type
= bp_loc_other
;
5320 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5326 static void free_bp_location (struct bp_location
*loc
)
5331 if (loc
->function_name
)
5332 xfree (loc
->function_name
);
5337 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5338 that has type BPTYPE and has no locations as yet. */
5339 /* This function is used in gdbtk sources and thus can not be made static. */
5341 static struct breakpoint
*
5342 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5345 struct breakpoint
*b
, *b1
;
5347 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5348 memset (b
, 0, sizeof (*b
));
5351 b
->gdbarch
= gdbarch
;
5352 b
->language
= current_language
->la_language
;
5353 b
->input_radix
= input_radix
;
5355 b
->enable_state
= bp_enabled
;
5358 b
->ignore_count
= 0;
5360 b
->frame_id
= null_frame_id
;
5361 b
->forked_inferior_pid
= null_ptid
;
5362 b
->exec_pathname
= NULL
;
5363 b
->syscalls_to_be_caught
= NULL
;
5365 b
->condition_not_parsed
= 0;
5367 /* Add this breakpoint to the end of the chain
5368 so that a list of breakpoints will come out in order
5369 of increasing numbers. */
5371 b1
= breakpoint_chain
;
5373 breakpoint_chain
= b
;
5383 /* Initialize loc->function_name. */
5385 set_breakpoint_location_function (struct bp_location
*loc
)
5387 if (loc
->owner
->type
== bp_breakpoint
5388 || loc
->owner
->type
== bp_hardware_breakpoint
5389 || tracepoint_type (loc
->owner
))
5391 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5393 if (loc
->function_name
)
5394 loc
->function_name
= xstrdup (loc
->function_name
);
5398 /* Attempt to determine architecture of location identified by SAL. */
5399 static struct gdbarch
*
5400 get_sal_arch (struct symtab_and_line sal
)
5403 return get_objfile_arch (sal
.section
->objfile
);
5405 return get_objfile_arch (sal
.symtab
->objfile
);
5410 /* set_raw_breakpoint is a low level routine for allocating and
5411 partially initializing a breakpoint of type BPTYPE. The newly
5412 created breakpoint's address, section, source file name, and line
5413 number are provided by SAL. The newly created and partially
5414 initialized breakpoint is added to the breakpoint chain and
5415 is also returned as the value of this function.
5417 It is expected that the caller will complete the initialization of
5418 the newly created breakpoint struct as well as output any status
5419 information regarding the creation of a new breakpoint. In
5420 particular, set_raw_breakpoint does NOT set the breakpoint
5421 number! Care should be taken to not allow an error to occur
5422 prior to completing the initialization of the breakpoint. If this
5423 should happen, a bogus breakpoint will be left on the chain. */
5426 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5427 struct symtab_and_line sal
, enum bptype bptype
)
5429 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5430 CORE_ADDR adjusted_address
;
5431 struct gdbarch
*loc_gdbarch
;
5433 loc_gdbarch
= get_sal_arch (sal
);
5435 loc_gdbarch
= b
->gdbarch
;
5437 if (bptype
!= bp_catchpoint
)
5438 gdb_assert (sal
.pspace
!= NULL
);
5440 /* Adjust the breakpoint's address prior to allocating a location.
5441 Once we call allocate_bp_location(), that mostly uninitialized
5442 location will be placed on the location chain. Adjustment of the
5443 breakpoint may cause target_read_memory() to be called and we do
5444 not want its scan of the location chain to find a breakpoint and
5445 location that's only been partially initialized. */
5446 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5448 b
->loc
= allocate_bp_location (b
);
5449 b
->loc
->gdbarch
= loc_gdbarch
;
5450 b
->loc
->requested_address
= sal
.pc
;
5451 b
->loc
->address
= adjusted_address
;
5452 b
->loc
->pspace
= sal
.pspace
;
5454 /* Store the program space that was used to set the breakpoint, for
5455 breakpoint resetting. */
5456 b
->pspace
= sal
.pspace
;
5458 if (sal
.symtab
== NULL
)
5459 b
->source_file
= NULL
;
5461 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5462 b
->loc
->section
= sal
.section
;
5463 b
->line_number
= sal
.line
;
5465 set_breakpoint_location_function (b
->loc
);
5467 breakpoints_changed ();
5473 /* Note that the breakpoint object B describes a permanent breakpoint
5474 instruction, hard-wired into the inferior's code. */
5476 make_breakpoint_permanent (struct breakpoint
*b
)
5478 struct bp_location
*bl
;
5479 b
->enable_state
= bp_permanent
;
5481 /* By definition, permanent breakpoints are already present in the code.
5482 Mark all locations as inserted. For now, make_breakpoint_permanent
5483 is called in just one place, so it's hard to say if it's reasonable
5484 to have permanent breakpoint with multiple locations or not,
5485 but it's easy to implmement. */
5486 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5490 /* Call this routine when stepping and nexting to enable a breakpoint
5491 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5492 set_longjmp_resume_breakpoint() to figure out where we are going. */
5495 set_longjmp_breakpoint (int thread
)
5497 struct breakpoint
*b
, *temp
;
5499 /* To avoid having to rescan all objfile symbols at every step,
5500 we maintain a list of continually-inserted but always disabled
5501 longjmp "master" breakpoints. Here, we simply create momentary
5502 clones of those and enable them for the requested thread. */
5503 ALL_BREAKPOINTS_SAFE (b
, temp
)
5504 if (b
->pspace
== current_program_space
5505 && b
->type
== bp_longjmp_master
)
5507 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5508 clone
->type
= bp_longjmp
;
5509 clone
->thread
= thread
;
5513 /* Delete all longjmp breakpoints from THREAD. */
5515 delete_longjmp_breakpoint (int thread
)
5517 struct breakpoint
*b
, *temp
;
5519 ALL_BREAKPOINTS_SAFE (b
, temp
)
5520 if (b
->type
== bp_longjmp
)
5522 if (b
->thread
== thread
)
5523 delete_breakpoint (b
);
5528 enable_overlay_breakpoints (void)
5530 struct breakpoint
*b
;
5533 if (b
->type
== bp_overlay_event
)
5535 b
->enable_state
= bp_enabled
;
5536 update_global_location_list (1);
5537 overlay_events_enabled
= 1;
5542 disable_overlay_breakpoints (void)
5544 struct breakpoint
*b
;
5547 if (b
->type
== bp_overlay_event
)
5549 b
->enable_state
= bp_disabled
;
5550 update_global_location_list (0);
5551 overlay_events_enabled
= 0;
5555 /* Set an active std::terminate breakpoint for each std::terminate
5556 master breakpoint. */
5558 set_std_terminate_breakpoint (void)
5560 struct breakpoint
*b
, *temp
;
5562 ALL_BREAKPOINTS_SAFE (b
, temp
)
5563 if (b
->pspace
== current_program_space
5564 && b
->type
== bp_std_terminate_master
)
5566 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5567 clone
->type
= bp_std_terminate
;
5571 /* Delete all the std::terminate breakpoints. */
5573 delete_std_terminate_breakpoint (void)
5575 struct breakpoint
*b
, *temp
;
5577 ALL_BREAKPOINTS_SAFE (b
, temp
)
5578 if (b
->type
== bp_std_terminate
)
5579 delete_breakpoint (b
);
5583 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5585 struct breakpoint
*b
;
5587 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5589 b
->enable_state
= bp_enabled
;
5590 /* addr_string has to be used or breakpoint_re_set will delete me. */
5592 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5594 update_global_location_list_nothrow (1);
5600 remove_thread_event_breakpoints (void)
5602 struct breakpoint
*b
, *temp
;
5604 ALL_BREAKPOINTS_SAFE (b
, temp
)
5605 if (b
->type
== bp_thread_event
5606 && b
->loc
->pspace
== current_program_space
)
5607 delete_breakpoint (b
);
5610 struct captured_parse_breakpoint_args
5613 struct symtabs_and_lines
*sals_p
;
5614 char ***addr_string_p
;
5618 struct lang_and_radix
5624 /* Create a breakpoint for JIT code registration and unregistration. */
5627 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5629 struct breakpoint
*b
;
5631 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5632 update_global_location_list_nothrow (1);
5637 remove_solib_event_breakpoints (void)
5639 struct breakpoint
*b
, *temp
;
5641 ALL_BREAKPOINTS_SAFE (b
, temp
)
5642 if (b
->type
== bp_shlib_event
5643 && b
->loc
->pspace
== current_program_space
)
5644 delete_breakpoint (b
);
5648 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5650 struct breakpoint
*b
;
5652 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5653 update_global_location_list_nothrow (1);
5657 /* Disable any breakpoints that are on code in shared libraries. Only
5658 apply to enabled breakpoints, disabled ones can just stay disabled. */
5661 disable_breakpoints_in_shlibs (void)
5663 struct bp_location
*loc
, **locp_tmp
;
5665 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5667 struct breakpoint
*b
= loc
->owner
;
5668 /* We apply the check to all breakpoints, including disabled
5669 for those with loc->duplicate set. This is so that when breakpoint
5670 becomes enabled, or the duplicate is removed, gdb will try to insert
5671 all breakpoints. If we don't set shlib_disabled here, we'll try
5672 to insert those breakpoints and fail. */
5673 if (((b
->type
== bp_breakpoint
)
5674 || (b
->type
== bp_jit_event
)
5675 || (b
->type
== bp_hardware_breakpoint
)
5676 || (tracepoint_type (b
)))
5677 && loc
->pspace
== current_program_space
5678 && !loc
->shlib_disabled
5680 && PC_SOLIB (loc
->address
)
5682 && solib_name_from_address (loc
->pspace
, loc
->address
)
5686 loc
->shlib_disabled
= 1;
5691 /* Disable any breakpoints that are in in an unloaded shared library. Only
5692 apply to enabled breakpoints, disabled ones can just stay disabled. */
5695 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5697 struct bp_location
*loc
, **locp_tmp
;
5698 int disabled_shlib_breaks
= 0;
5700 /* SunOS a.out shared libraries are always mapped, so do not
5701 disable breakpoints; they will only be reported as unloaded
5702 through clear_solib when GDB discards its shared library
5703 list. See clear_solib for more information. */
5704 if (exec_bfd
!= NULL
5705 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5708 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5710 struct breakpoint
*b
= loc
->owner
;
5711 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5712 || loc
->loc_type
== bp_loc_software_breakpoint
)
5713 && solib
->pspace
== loc
->pspace
5714 && !loc
->shlib_disabled
5715 && (b
->type
== bp_breakpoint
5716 || b
->type
== bp_jit_event
5717 || b
->type
== bp_hardware_breakpoint
)
5718 && solib_contains_address_p (solib
, loc
->address
))
5720 loc
->shlib_disabled
= 1;
5721 /* At this point, we cannot rely on remove_breakpoint
5722 succeeding so we must mark the breakpoint as not inserted
5723 to prevent future errors occurring in remove_breakpoints. */
5725 if (!disabled_shlib_breaks
)
5727 target_terminal_ours_for_output ();
5728 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5731 disabled_shlib_breaks
= 1;
5736 /* FORK & VFORK catchpoints. */
5738 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5741 insert_catch_fork (struct breakpoint
*b
)
5743 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5746 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5749 remove_catch_fork (struct breakpoint
*b
)
5751 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5754 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5758 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5760 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5763 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5765 static enum print_stop_action
5766 print_it_catch_fork (struct breakpoint
*b
)
5768 annotate_catchpoint (b
->number
);
5769 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5770 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5771 return PRINT_SRC_AND_LOC
;
5774 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5777 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5779 struct value_print_options opts
;
5781 get_user_print_options (&opts
);
5783 /* Field 4, the address, is omitted (which makes the columns
5784 not line up too nicely with the headers, but the effect
5785 is relatively readable). */
5786 if (opts
.addressprint
)
5787 ui_out_field_skip (uiout
, "addr");
5789 ui_out_text (uiout
, "fork");
5790 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5792 ui_out_text (uiout
, ", process ");
5793 ui_out_field_int (uiout
, "what",
5794 ptid_get_pid (b
->forked_inferior_pid
));
5795 ui_out_spaces (uiout
, 1);
5799 /* Implement the "print_mention" breakpoint_ops method for fork
5803 print_mention_catch_fork (struct breakpoint
*b
)
5805 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5808 /* The breakpoint_ops structure to be used in fork catchpoints. */
5810 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5814 breakpoint_hit_catch_fork
,
5815 print_it_catch_fork
,
5816 print_one_catch_fork
,
5817 print_mention_catch_fork
5820 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5823 insert_catch_vfork (struct breakpoint
*b
)
5825 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5828 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5831 remove_catch_vfork (struct breakpoint
*b
)
5833 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5836 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5840 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5842 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5845 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5847 static enum print_stop_action
5848 print_it_catch_vfork (struct breakpoint
*b
)
5850 annotate_catchpoint (b
->number
);
5851 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5852 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5853 return PRINT_SRC_AND_LOC
;
5856 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5859 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5861 struct value_print_options opts
;
5863 get_user_print_options (&opts
);
5864 /* Field 4, the address, is omitted (which makes the columns
5865 not line up too nicely with the headers, but the effect
5866 is relatively readable). */
5867 if (opts
.addressprint
)
5868 ui_out_field_skip (uiout
, "addr");
5870 ui_out_text (uiout
, "vfork");
5871 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5873 ui_out_text (uiout
, ", process ");
5874 ui_out_field_int (uiout
, "what",
5875 ptid_get_pid (b
->forked_inferior_pid
));
5876 ui_out_spaces (uiout
, 1);
5880 /* Implement the "print_mention" breakpoint_ops method for vfork
5884 print_mention_catch_vfork (struct breakpoint
*b
)
5886 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5889 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5891 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5895 breakpoint_hit_catch_vfork
,
5896 print_it_catch_vfork
,
5897 print_one_catch_vfork
,
5898 print_mention_catch_vfork
5901 /* Implement the "insert" breakpoint_ops method for syscall
5905 insert_catch_syscall (struct breakpoint
*b
)
5907 struct inferior
*inf
= current_inferior ();
5909 ++inf
->total_syscalls_count
;
5910 if (!b
->syscalls_to_be_caught
)
5911 ++inf
->any_syscall_count
;
5916 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5920 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5922 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5923 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5925 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5926 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5928 memset ((void *) vec_addr
, 0,
5929 (iter
+ 1 - old_size
) * sizeof (int));
5931 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5932 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5936 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5937 inf
->total_syscalls_count
!= 0,
5938 inf
->any_syscall_count
,
5939 VEC_length (int, inf
->syscalls_counts
),
5940 VEC_address (int, inf
->syscalls_counts
));
5943 /* Implement the "remove" breakpoint_ops method for syscall
5947 remove_catch_syscall (struct breakpoint
*b
)
5949 struct inferior
*inf
= current_inferior ();
5951 --inf
->total_syscalls_count
;
5952 if (!b
->syscalls_to_be_caught
)
5953 --inf
->any_syscall_count
;
5958 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5962 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5963 /* Shouldn't happen. */
5965 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5966 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5970 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5971 inf
->total_syscalls_count
!= 0,
5972 inf
->any_syscall_count
,
5973 VEC_length (int, inf
->syscalls_counts
),
5974 VEC_address (int, inf
->syscalls_counts
));
5977 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5981 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5983 /* We must check if we are catching specific syscalls in this breakpoint.
5984 If we are, then we must guarantee that the called syscall is the same
5985 syscall we are catching. */
5986 int syscall_number
= 0;
5988 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5991 /* Now, checking if the syscall is the same. */
5992 if (b
->syscalls_to_be_caught
)
5996 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5998 if (syscall_number
== iter
)
6008 /* Implement the "print_it" breakpoint_ops method for syscall
6011 static enum print_stop_action
6012 print_it_catch_syscall (struct breakpoint
*b
)
6014 /* These are needed because we want to know in which state a
6015 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6016 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6017 must print "called syscall" or "returned from syscall". */
6019 struct target_waitstatus last
;
6021 struct cleanup
*old_chain
;
6024 get_last_target_status (&ptid
, &last
);
6026 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6028 annotate_catchpoint (b
->number
);
6031 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6033 syscall_id
= xstrprintf ("'%s'", s
.name
);
6035 old_chain
= make_cleanup (xfree
, syscall_id
);
6037 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6038 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6039 b
->number
, syscall_id
);
6040 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6041 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6042 b
->number
, syscall_id
);
6044 do_cleanups (old_chain
);
6046 return PRINT_SRC_AND_LOC
;
6049 /* Implement the "print_one" breakpoint_ops method for syscall
6053 print_one_catch_syscall (struct breakpoint
*b
,
6054 struct bp_location
**last_loc
)
6056 struct value_print_options opts
;
6058 get_user_print_options (&opts
);
6059 /* Field 4, the address, is omitted (which makes the columns
6060 not line up too nicely with the headers, but the effect
6061 is relatively readable). */
6062 if (opts
.addressprint
)
6063 ui_out_field_skip (uiout
, "addr");
6066 if (b
->syscalls_to_be_caught
6067 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6068 ui_out_text (uiout
, "syscalls \"");
6070 ui_out_text (uiout
, "syscall \"");
6072 if (b
->syscalls_to_be_caught
)
6075 char *text
= xstrprintf ("%s", "");
6077 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6082 get_syscall_by_number (iter
, &s
);
6085 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6087 text
= xstrprintf ("%s%d, ", text
, iter
);
6089 /* We have to xfree the last 'text' (now stored at 'x')
6090 because xstrprintf dinamically allocates new space for it
6094 /* Remove the last comma. */
6095 text
[strlen (text
) - 2] = '\0';
6096 ui_out_field_string (uiout
, "what", text
);
6099 ui_out_field_string (uiout
, "what", "<any syscall>");
6100 ui_out_text (uiout
, "\" ");
6103 /* Implement the "print_mention" breakpoint_ops method for syscall
6107 print_mention_catch_syscall (struct breakpoint
*b
)
6109 if (b
->syscalls_to_be_caught
)
6113 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6114 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6116 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6119 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6123 get_syscall_by_number (iter
, &s
);
6126 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6128 printf_filtered (" %d", s
.number
);
6130 printf_filtered (")");
6133 printf_filtered (_("Catchpoint %d (any syscall)"),
6137 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6139 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6141 insert_catch_syscall
,
6142 remove_catch_syscall
,
6143 breakpoint_hit_catch_syscall
,
6144 print_it_catch_syscall
,
6145 print_one_catch_syscall
,
6146 print_mention_catch_syscall
6149 /* Returns non-zero if 'b' is a syscall catchpoint. */
6152 syscall_catchpoint_p (struct breakpoint
*b
)
6154 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6157 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6158 but does NOT mention it nor update the global location list.
6159 This is useful if you need to fill more fields in the
6160 struct breakpoint before calling mention.
6162 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6163 If COND_STRING is not NULL, then store it in the breakpoint.
6164 OPS, if not NULL, is the breakpoint_ops structure associated
6165 to the catchpoint. */
6167 static struct breakpoint
*
6168 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6170 struct breakpoint_ops
*ops
)
6172 struct symtab_and_line sal
;
6173 struct breakpoint
*b
;
6176 sal
.pspace
= current_program_space
;
6178 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6179 set_breakpoint_count (breakpoint_count
+ 1);
6180 b
->number
= breakpoint_count
;
6182 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6184 b
->addr_string
= NULL
;
6185 b
->enable_state
= bp_enabled
;
6186 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6192 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6194 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6195 If COND_STRING is not NULL, then store it in the breakpoint.
6196 OPS, if not NULL, is the breakpoint_ops structure associated
6197 to the catchpoint. */
6199 static struct breakpoint
*
6200 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6201 char *cond_string
, struct breakpoint_ops
*ops
)
6203 struct breakpoint
*b
=
6204 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6207 update_global_location_list (1);
6213 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6214 int tempflag
, char *cond_string
,
6215 struct breakpoint_ops
*ops
)
6217 struct breakpoint
*b
6218 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6220 /* FIXME: We should put this information in a breakpoint private data
6222 b
->forked_inferior_pid
= null_ptid
;
6225 /* Exec catchpoints. */
6228 insert_catch_exec (struct breakpoint
*b
)
6230 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6234 remove_catch_exec (struct breakpoint
*b
)
6236 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6240 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6242 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6245 static enum print_stop_action
6246 print_it_catch_exec (struct breakpoint
*b
)
6248 annotate_catchpoint (b
->number
);
6249 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6251 return PRINT_SRC_AND_LOC
;
6255 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6257 struct value_print_options opts
;
6259 get_user_print_options (&opts
);
6261 /* Field 4, the address, is omitted (which makes the columns
6262 not line up too nicely with the headers, but the effect
6263 is relatively readable). */
6264 if (opts
.addressprint
)
6265 ui_out_field_skip (uiout
, "addr");
6267 ui_out_text (uiout
, "exec");
6268 if (b
->exec_pathname
!= NULL
)
6270 ui_out_text (uiout
, ", program \"");
6271 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6272 ui_out_text (uiout
, "\" ");
6277 print_mention_catch_exec (struct breakpoint
*b
)
6279 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6282 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6286 breakpoint_hit_catch_exec
,
6287 print_it_catch_exec
,
6288 print_one_catch_exec
,
6289 print_mention_catch_exec
6293 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6294 struct breakpoint_ops
*ops
)
6296 struct gdbarch
*gdbarch
= get_current_arch ();
6297 struct breakpoint
*b
=
6298 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6300 b
->syscalls_to_be_caught
= filter
;
6302 /* Now, we have to mention the breakpoint and update the global
6305 update_global_location_list (1);
6309 hw_breakpoint_used_count (void)
6311 struct breakpoint
*b
;
6316 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6324 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6326 struct breakpoint
*b
;
6329 *other_type_used
= 0;
6332 if (breakpoint_enabled (b
))
6334 if (b
->type
== type
)
6336 else if ((b
->type
== bp_hardware_watchpoint
6337 || b
->type
== bp_read_watchpoint
6338 || b
->type
== bp_access_watchpoint
))
6339 *other_type_used
= 1;
6346 disable_watchpoints_before_interactive_call_start (void)
6348 struct breakpoint
*b
;
6352 if (((b
->type
== bp_watchpoint
)
6353 || (b
->type
== bp_hardware_watchpoint
)
6354 || (b
->type
== bp_read_watchpoint
)
6355 || (b
->type
== bp_access_watchpoint
))
6356 && breakpoint_enabled (b
))
6358 b
->enable_state
= bp_call_disabled
;
6359 update_global_location_list (0);
6365 enable_watchpoints_after_interactive_call_stop (void)
6367 struct breakpoint
*b
;
6371 if (((b
->type
== bp_watchpoint
)
6372 || (b
->type
== bp_hardware_watchpoint
)
6373 || (b
->type
== bp_read_watchpoint
)
6374 || (b
->type
== bp_access_watchpoint
))
6375 && (b
->enable_state
== bp_call_disabled
))
6377 b
->enable_state
= bp_enabled
;
6378 update_global_location_list (1);
6384 disable_breakpoints_before_startup (void)
6386 struct breakpoint
*b
;
6391 if (b
->pspace
!= current_program_space
)
6394 if ((b
->type
== bp_breakpoint
6395 || b
->type
== bp_hardware_breakpoint
)
6396 && breakpoint_enabled (b
))
6398 b
->enable_state
= bp_startup_disabled
;
6404 update_global_location_list (0);
6406 current_program_space
->executing_startup
= 1;
6410 enable_breakpoints_after_startup (void)
6412 struct breakpoint
*b
;
6415 current_program_space
->executing_startup
= 0;
6419 if (b
->pspace
!= current_program_space
)
6422 if ((b
->type
== bp_breakpoint
6423 || b
->type
== bp_hardware_breakpoint
)
6424 && b
->enable_state
== bp_startup_disabled
)
6426 b
->enable_state
= bp_enabled
;
6432 breakpoint_re_set ();
6436 /* Set a breakpoint that will evaporate an end of command
6437 at address specified by SAL.
6438 Restrict it to frame FRAME if FRAME is nonzero. */
6441 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6442 struct frame_id frame_id
, enum bptype type
)
6444 struct breakpoint
*b
;
6446 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6448 gdb_assert (!frame_id_inlined_p (frame_id
));
6450 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6451 b
->enable_state
= bp_enabled
;
6452 b
->disposition
= disp_donttouch
;
6453 b
->frame_id
= frame_id
;
6455 /* If we're debugging a multi-threaded program, then we
6456 want momentary breakpoints to be active in only a
6457 single thread of control. */
6458 if (in_thread_list (inferior_ptid
))
6459 b
->thread
= pid_to_thread_id (inferior_ptid
);
6461 update_global_location_list_nothrow (1);
6466 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6470 clone_momentary_breakpoint (struct breakpoint
*orig
)
6472 struct breakpoint
*copy
;
6474 /* If there's nothing to clone, then return nothing. */
6478 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6479 copy
->loc
= allocate_bp_location (copy
);
6480 set_breakpoint_location_function (copy
->loc
);
6482 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6483 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6484 copy
->loc
->address
= orig
->loc
->address
;
6485 copy
->loc
->section
= orig
->loc
->section
;
6486 copy
->loc
->pspace
= orig
->loc
->pspace
;
6488 if (orig
->source_file
== NULL
)
6489 copy
->source_file
= NULL
;
6491 copy
->source_file
= xstrdup (orig
->source_file
);
6493 copy
->line_number
= orig
->line_number
;
6494 copy
->frame_id
= orig
->frame_id
;
6495 copy
->thread
= orig
->thread
;
6496 copy
->pspace
= orig
->pspace
;
6498 copy
->enable_state
= bp_enabled
;
6499 copy
->disposition
= disp_donttouch
;
6500 copy
->number
= internal_breakpoint_number
--;
6502 update_global_location_list_nothrow (0);
6507 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6510 struct symtab_and_line sal
;
6512 sal
= find_pc_line (pc
, 0);
6514 sal
.section
= find_pc_overlay (pc
);
6515 sal
.explicit_pc
= 1;
6517 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6521 /* Tell the user we have just set a breakpoint B. */
6524 mention (struct breakpoint
*b
)
6527 struct cleanup
*ui_out_chain
;
6528 struct value_print_options opts
;
6530 get_user_print_options (&opts
);
6532 /* FIXME: This is misplaced; mention() is called by things (like
6533 hitting a watchpoint) other than breakpoint creation. It should
6534 be possible to clean this up and at the same time replace the
6535 random calls to breakpoint_changed with this hook. */
6536 observer_notify_breakpoint_created (b
->number
);
6538 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6539 b
->ops
->print_mention (b
);
6544 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6547 ui_out_text (uiout
, "Watchpoint ");
6548 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6549 ui_out_field_int (uiout
, "number", b
->number
);
6550 ui_out_text (uiout
, ": ");
6551 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6552 do_cleanups (ui_out_chain
);
6554 case bp_hardware_watchpoint
:
6555 ui_out_text (uiout
, "Hardware watchpoint ");
6556 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6557 ui_out_field_int (uiout
, "number", b
->number
);
6558 ui_out_text (uiout
, ": ");
6559 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6560 do_cleanups (ui_out_chain
);
6562 case bp_read_watchpoint
:
6563 ui_out_text (uiout
, "Hardware read watchpoint ");
6564 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6565 ui_out_field_int (uiout
, "number", b
->number
);
6566 ui_out_text (uiout
, ": ");
6567 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6568 do_cleanups (ui_out_chain
);
6570 case bp_access_watchpoint
:
6571 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6572 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6573 ui_out_field_int (uiout
, "number", b
->number
);
6574 ui_out_text (uiout
, ": ");
6575 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6576 do_cleanups (ui_out_chain
);
6579 if (ui_out_is_mi_like_p (uiout
))
6584 if (b
->disposition
== disp_del
)
6585 printf_filtered (_("Temporary breakpoint"));
6587 printf_filtered (_("Breakpoint"));
6588 printf_filtered (_(" %d"), b
->number
);
6591 case bp_hardware_breakpoint
:
6592 if (ui_out_is_mi_like_p (uiout
))
6597 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6601 if (ui_out_is_mi_like_p (uiout
))
6606 printf_filtered (_("Tracepoint"));
6607 printf_filtered (_(" %d"), b
->number
);
6610 case bp_fast_tracepoint
:
6611 if (ui_out_is_mi_like_p (uiout
))
6616 printf_filtered (_("Fast tracepoint"));
6617 printf_filtered (_(" %d"), b
->number
);
6624 case bp_longjmp_resume
:
6625 case bp_step_resume
:
6627 case bp_std_terminate
:
6628 case bp_watchpoint_scope
:
6629 case bp_shlib_event
:
6630 case bp_thread_event
:
6631 case bp_overlay_event
:
6633 case bp_longjmp_master
:
6634 case bp_std_terminate_master
:
6640 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6644 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6648 if (opts
.addressprint
|| b
->source_file
== NULL
)
6650 printf_filtered (" at ");
6651 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6655 printf_filtered (": file %s, line %d.",
6656 b
->source_file
, b
->line_number
);
6660 struct bp_location
*loc
= b
->loc
;
6662 for (; loc
; loc
= loc
->next
)
6664 printf_filtered (" (%d locations)", n
);
6669 if (ui_out_is_mi_like_p (uiout
))
6671 printf_filtered ("\n");
6675 static struct bp_location
*
6676 add_location_to_breakpoint (struct breakpoint
*b
,
6677 const struct symtab_and_line
*sal
)
6679 struct bp_location
*loc
, **tmp
;
6681 loc
= allocate_bp_location (b
);
6682 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6685 loc
->gdbarch
= get_sal_arch (*sal
);
6687 loc
->gdbarch
= b
->gdbarch
;
6688 loc
->requested_address
= sal
->pc
;
6689 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6690 loc
->requested_address
, b
->type
);
6691 loc
->pspace
= sal
->pspace
;
6692 gdb_assert (loc
->pspace
!= NULL
);
6693 loc
->section
= sal
->section
;
6695 set_breakpoint_location_function (loc
);
6700 /* Return 1 if LOC is pointing to a permanent breakpoint,
6701 return 0 otherwise. */
6704 bp_loc_is_permanent (struct bp_location
*loc
)
6708 const gdb_byte
*brk
;
6709 gdb_byte
*target_mem
;
6710 struct cleanup
*cleanup
;
6713 gdb_assert (loc
!= NULL
);
6715 addr
= loc
->address
;
6716 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6718 /* Software breakpoints unsupported? */
6722 target_mem
= alloca (len
);
6724 /* Enable the automatic memory restoration from breakpoints while
6725 we read the memory. Otherwise we could say about our temporary
6726 breakpoints they are permanent. */
6727 cleanup
= save_current_space_and_thread ();
6729 switch_to_program_space_and_thread (loc
->pspace
);
6730 make_show_memory_breakpoints_cleanup (0);
6732 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6733 && memcmp (target_mem
, brk
, len
) == 0)
6736 do_cleanups (cleanup
);
6743 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6744 as textual description of the location, and COND_STRING
6745 as condition expression. */
6748 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6749 struct symtabs_and_lines sals
, char *addr_string
,
6751 enum bptype type
, enum bpdisp disposition
,
6752 int thread
, int task
, int ignore_count
,
6753 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6755 struct breakpoint
*b
= NULL
;
6758 if (type
== bp_hardware_breakpoint
)
6760 int i
= hw_breakpoint_used_count ();
6761 int target_resources_ok
=
6762 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6764 if (target_resources_ok
== 0)
6765 error (_("No hardware breakpoint support in the target."));
6766 else if (target_resources_ok
< 0)
6767 error (_("Hardware breakpoints used exceeds limit."));
6770 gdb_assert (sals
.nelts
> 0);
6772 for (i
= 0; i
< sals
.nelts
; ++i
)
6774 struct symtab_and_line sal
= sals
.sals
[i
];
6775 struct bp_location
*loc
;
6779 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6781 loc_gdbarch
= gdbarch
;
6783 describe_other_breakpoints (loc_gdbarch
,
6784 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6789 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6790 set_breakpoint_count (breakpoint_count
+ 1);
6791 b
->number
= breakpoint_count
;
6795 b
->cond_string
= cond_string
;
6796 b
->ignore_count
= ignore_count
;
6797 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6798 b
->disposition
= disposition
;
6800 b
->pspace
= sals
.sals
[0].pspace
;
6802 if (enabled
&& b
->pspace
->executing_startup
6803 && (b
->type
== bp_breakpoint
6804 || b
->type
== bp_hardware_breakpoint
))
6805 b
->enable_state
= bp_startup_disabled
;
6811 loc
= add_location_to_breakpoint (b
, &sal
);
6814 if (bp_loc_is_permanent (loc
))
6815 make_breakpoint_permanent (b
);
6819 char *arg
= b
->cond_string
;
6820 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6822 error (_("Garbage %s follows condition"), arg
);
6827 b
->addr_string
= addr_string
;
6829 /* addr_string has to be used or breakpoint_re_set will delete
6832 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6838 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6839 elements to fill the void space. */
6841 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6843 int i
= index_to_remove
+1;
6844 int last_index
= sal
->nelts
-1;
6846 for (;i
<= last_index
; ++i
)
6847 sal
->sals
[i
-1] = sal
->sals
[i
];
6852 /* If appropriate, obtains all sals that correspond to the same file
6853 and line as SAL, in all program spaces. Users debugging with IDEs,
6854 will want to set a breakpoint at foo.c:line, and not really care
6855 about program spaces. This is done only if SAL does not have
6856 explicit PC and has line and file information. If we got just a
6857 single expanded sal, return the original.
6859 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6860 which the name of enclosing function is different from SAL. This
6861 makes sure that if we have breakpoint originally set in template
6862 instantiation, say foo<int>(), we won't expand SAL to locations at
6863 the same line in all existing instantiations of 'foo'. */
6865 static struct symtabs_and_lines
6866 expand_line_sal_maybe (struct symtab_and_line sal
)
6868 struct symtabs_and_lines expanded
;
6869 CORE_ADDR original_pc
= sal
.pc
;
6870 char *original_function
= NULL
;
6873 struct cleanup
*old_chain
;
6875 /* If we have explicit pc, don't expand.
6876 If we have no line number, we can't expand. */
6877 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6880 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6881 expanded
.sals
[0] = sal
;
6887 old_chain
= save_current_space_and_thread ();
6889 switch_to_program_space_and_thread (sal
.pspace
);
6891 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6893 /* Note that expand_line_sal visits *all* program spaces. */
6894 expanded
= expand_line_sal (sal
);
6896 if (expanded
.nelts
== 1)
6898 /* We had one sal, we got one sal. Return that sal, adjusting it
6899 past the function prologue if necessary. */
6900 xfree (expanded
.sals
);
6902 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6903 sal
.pc
= original_pc
;
6904 expanded
.sals
[0] = sal
;
6905 skip_prologue_sal (&expanded
.sals
[0]);
6906 do_cleanups (old_chain
);
6910 if (!sal
.explicit_line
)
6912 CORE_ADDR func_addr
, func_end
;
6913 for (i
= 0; i
< expanded
.nelts
; ++i
)
6915 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6916 char *this_function
;
6918 /* We need to switch threads as well since we're about to
6920 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6922 if (find_pc_partial_function (pc
, &this_function
,
6923 &func_addr
, &func_end
))
6926 && strcmp (this_function
, original_function
) != 0)
6928 remove_sal (&expanded
, i
);
6935 /* Skip the function prologue if necessary. */
6936 for (i
= 0; i
< expanded
.nelts
; ++i
)
6937 skip_prologue_sal (&expanded
.sals
[i
]);
6939 do_cleanups (old_chain
);
6941 if (expanded
.nelts
<= 1)
6943 /* This is un ugly workaround. If we get zero
6944 expanded sals then something is really wrong.
6945 Fix that by returnign the original sal. */
6946 xfree (expanded
.sals
);
6948 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6949 sal
.pc
= original_pc
;
6950 expanded
.sals
[0] = sal
;
6957 for (i
= 0; i
< expanded
.nelts
; ++i
)
6958 if (expanded
.sals
[i
].pc
== original_pc
)
6969 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6970 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6971 value. COND_STRING, if not NULL, specified the condition to be
6972 used for all breakpoints. Essentially the only case where
6973 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6974 function. In that case, it's still not possible to specify
6975 separate conditions for different overloaded functions, so
6976 we take just a single condition string.
6978 NOTE: If the function succeeds, the caller is expected to cleanup
6979 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6980 array contents). If the function fails (error() is called), the
6981 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6982 COND and SALS arrays and each of those arrays contents. */
6985 create_breakpoints_sal (struct gdbarch
*gdbarch
,
6986 struct symtabs_and_lines sals
, char **addr_string
,
6988 enum bptype type
, enum bpdisp disposition
,
6989 int thread
, int task
, int ignore_count
,
6990 struct breakpoint_ops
*ops
, int from_tty
,
6994 for (i
= 0; i
< sals
.nelts
; ++i
)
6996 struct symtabs_and_lines expanded
=
6997 expand_line_sal_maybe (sals
.sals
[i
]);
6999 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7000 cond_string
, type
, disposition
,
7001 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7005 /* Parse ARG which is assumed to be a SAL specification possibly
7006 followed by conditionals. On return, SALS contains an array of SAL
7007 addresses found. ADDR_STRING contains a vector of (canonical)
7008 address strings. ARG points to the end of the SAL. */
7011 parse_breakpoint_sals (char **address
,
7012 struct symtabs_and_lines
*sals
,
7013 char ***addr_string
,
7016 char *addr_start
= *address
;
7017 *addr_string
= NULL
;
7018 /* If no arg given, or if first arg is 'if ', use the default
7020 if ((*address
) == NULL
7021 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7023 if (default_breakpoint_valid
)
7025 struct symtab_and_line sal
;
7026 init_sal (&sal
); /* initialize to zeroes */
7027 sals
->sals
= (struct symtab_and_line
*)
7028 xmalloc (sizeof (struct symtab_and_line
));
7029 sal
.pc
= default_breakpoint_address
;
7030 sal
.line
= default_breakpoint_line
;
7031 sal
.symtab
= default_breakpoint_symtab
;
7032 sal
.pspace
= default_breakpoint_pspace
;
7033 sal
.section
= find_pc_overlay (sal
.pc
);
7035 /* "break" without arguments is equivalent to "break *PC" where PC is
7036 the default_breakpoint_address. So make sure to set
7037 sal.explicit_pc to prevent GDB from trying to expand the list of
7038 sals to include all other instances with the same symtab and line.
7040 sal
.explicit_pc
= 1;
7042 sals
->sals
[0] = sal
;
7046 error (_("No default breakpoint address now."));
7050 /* Force almost all breakpoints to be in terms of the
7051 current_source_symtab (which is decode_line_1's default). This
7052 should produce the results we want almost all of the time while
7053 leaving default_breakpoint_* alone.
7054 ObjC: However, don't match an Objective-C method name which
7055 may have a '+' or '-' succeeded by a '[' */
7057 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7059 if (default_breakpoint_valid
7061 || ((strchr ("+-", (*address
)[0]) != NULL
)
7062 && ((*address
)[1] != '['))))
7063 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7064 default_breakpoint_line
, addr_string
,
7067 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7068 addr_string
, not_found_ptr
);
7070 /* For any SAL that didn't have a canonical string, fill one in. */
7071 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7072 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7073 if (addr_start
!= (*address
))
7076 for (i
= 0; i
< sals
->nelts
; i
++)
7078 /* Add the string if not present. */
7079 if ((*addr_string
)[i
] == NULL
)
7080 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7086 /* Convert each SAL into a real PC. Verify that the PC can be
7087 inserted as a breakpoint. If it can't throw an error. */
7090 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7094 for (i
= 0; i
< sals
->nelts
; i
++)
7095 resolve_sal_pc (&sals
->sals
[i
]);
7098 /* Fast tracepoints may have restrictions on valid locations. For
7099 instance, a fast tracepoint using a jump instead of a trap will
7100 likely have to overwrite more bytes than a trap would, and so can
7101 only be placed where the instruction is longer than the jump, or a
7102 multi-instruction sequence does not have a jump into the middle of
7106 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7107 struct symtabs_and_lines
*sals
)
7110 struct symtab_and_line
*sal
;
7112 struct cleanup
*old_chain
;
7114 for (i
= 0; i
< sals
->nelts
; i
++)
7116 sal
= &sals
->sals
[i
];
7118 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7120 old_chain
= make_cleanup (xfree
, msg
);
7123 error (_("May not have a fast tracepoint at 0x%s%s"),
7124 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7126 do_cleanups (old_chain
);
7131 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7133 struct captured_parse_breakpoint_args
*args
= data
;
7135 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7136 args
->not_found_ptr
);
7139 /* Given TOK, a string specification of condition and thread, as
7140 accepted by the 'break' command, extract the condition
7141 string and thread number and set *COND_STRING and *THREAD.
7142 PC identifies the context at which the condition should be parsed.
7143 If no condition is found, *COND_STRING is set to NULL.
7144 If no thread is found, *THREAD is set to -1. */
7146 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7147 char **cond_string
, int *thread
, int *task
)
7149 *cond_string
= NULL
;
7155 char *cond_start
= NULL
;
7156 char *cond_end
= NULL
;
7157 while (*tok
== ' ' || *tok
== '\t')
7162 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7165 toklen
= end_tok
- tok
;
7167 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7169 struct expression
*expr
;
7171 tok
= cond_start
= end_tok
+ 1;
7172 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7175 *cond_string
= savestring (cond_start
,
7176 cond_end
- cond_start
);
7178 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7184 *thread
= strtol (tok
, &tok
, 0);
7186 error (_("Junk after thread keyword."));
7187 if (!valid_thread_id (*thread
))
7188 error (_("Unknown thread %d."), *thread
);
7190 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7196 *task
= strtol (tok
, &tok
, 0);
7198 error (_("Junk after task keyword."));
7199 if (!valid_task_id (*task
))
7200 error (_("Unknown task %d."), *task
);
7203 error (_("Junk at end of arguments."));
7207 /* Set a breakpoint. This function is shared between CLI and MI
7208 functions for setting a breakpoint. This function has two major
7209 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7210 parameter. If non-zero, the function will parse arg, extracting
7211 breakpoint location, address and thread. Otherwise, ARG is just the
7212 location of breakpoint, with condition and thread specified by the
7213 COND_STRING and THREAD parameters. Returns true if any breakpoint
7214 was created; false otherwise. */
7217 create_breakpoint (struct gdbarch
*gdbarch
,
7218 char *arg
, char *cond_string
, int thread
,
7219 int parse_condition_and_thread
,
7220 int tempflag
, int hardwareflag
, int traceflag
,
7222 enum auto_boolean pending_break_support
,
7223 struct breakpoint_ops
*ops
,
7227 struct gdb_exception e
;
7228 struct symtabs_and_lines sals
;
7229 struct symtab_and_line pending_sal
;
7232 char *addr_start
= arg
;
7234 struct cleanup
*old_chain
;
7235 struct cleanup
*bkpt_chain
= NULL
;
7236 struct captured_parse_breakpoint_args parse_args
;
7240 enum bptype type_wanted
;
7242 int first_bp_set
= breakpoint_count
+ 1;
7248 parse_args
.arg_p
= &arg
;
7249 parse_args
.sals_p
= &sals
;
7250 parse_args
.addr_string_p
= &addr_string
;
7251 parse_args
.not_found_ptr
= ¬_found
;
7253 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7254 &parse_args
, RETURN_MASK_ALL
);
7256 /* If caller is interested in rc value from parse, set value. */
7260 throw_exception (e
);
7264 case NOT_FOUND_ERROR
:
7266 /* If pending breakpoint support is turned off, throw
7269 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7270 throw_exception (e
);
7272 exception_print (gdb_stderr
, e
);
7274 /* If pending breakpoint support is auto query and the user
7275 selects no, then simply return the error code. */
7276 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7277 && !nquery ("Make breakpoint pending on future shared library load? "))
7280 /* At this point, either the user was queried about setting
7281 a pending breakpoint and selected yes, or pending
7282 breakpoint behavior is on and thus a pending breakpoint
7283 is defaulted on behalf of the user. */
7284 copy_arg
= xstrdup (addr_start
);
7285 addr_string
= ©_arg
;
7287 sals
.sals
= &pending_sal
;
7292 throw_exception (e
);
7299 /* Create a chain of things that always need to be cleaned up. */
7300 old_chain
= make_cleanup (null_cleanup
, 0);
7304 /* Make sure that all storage allocated to SALS gets freed. */
7305 make_cleanup (xfree
, sals
.sals
);
7307 /* Cleanup the addr_string array but not its contents. */
7308 make_cleanup (xfree
, addr_string
);
7311 /* ----------------------------- SNIP -----------------------------
7312 Anything added to the cleanup chain beyond this point is assumed
7313 to be part of a breakpoint. If the breakpoint create succeeds
7314 then the memory is not reclaimed. */
7315 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7317 /* Mark the contents of the addr_string for cleanup. These go on
7318 the bkpt_chain and only occur if the breakpoint create fails. */
7319 for (i
= 0; i
< sals
.nelts
; i
++)
7321 if (addr_string
[i
] != NULL
)
7322 make_cleanup (xfree
, addr_string
[i
]);
7325 /* Resolve all line numbers to PC's and verify that the addresses
7326 are ok for the target. */
7328 breakpoint_sals_to_pc (&sals
, addr_start
);
7330 type_wanted
= (traceflag
7331 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7332 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7334 /* Fast tracepoints may have additional restrictions on location. */
7335 if (type_wanted
== bp_fast_tracepoint
)
7336 check_fast_tracepoint_sals (gdbarch
, &sals
);
7338 /* Verify that condition can be parsed, before setting any
7339 breakpoints. Allocate a separate condition expression for each
7343 if (parse_condition_and_thread
)
7345 /* Here we only parse 'arg' to separate condition
7346 from thread number, so parsing in context of first
7347 sal is OK. When setting the breakpoint we'll
7348 re-parse it in context of each sal. */
7351 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7354 make_cleanup (xfree
, cond_string
);
7358 /* Create a private copy of condition string. */
7361 cond_string
= xstrdup (cond_string
);
7362 make_cleanup (xfree
, cond_string
);
7365 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7366 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7367 thread
, task
, ignore_count
, ops
, from_tty
,
7372 struct symtab_and_line sal
= {0};
7373 struct breakpoint
*b
;
7375 make_cleanup (xfree
, copy_arg
);
7377 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7378 set_breakpoint_count (breakpoint_count
+ 1);
7379 b
->number
= breakpoint_count
;
7381 b
->addr_string
= addr_string
[0];
7382 b
->cond_string
= NULL
;
7383 b
->ignore_count
= ignore_count
;
7384 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7385 b
->condition_not_parsed
= 1;
7387 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7388 b
->pspace
= current_program_space
;
7390 if (enabled
&& b
->pspace
->executing_startup
7391 && (b
->type
== bp_breakpoint
7392 || b
->type
== bp_hardware_breakpoint
))
7393 b
->enable_state
= bp_startup_disabled
;
7400 warning (_("Multiple breakpoints were set.\n"
7401 "Use the \"delete\" command to delete unwanted breakpoints."));
7402 multi_start
= first_bp_set
;
7403 multi_end
= breakpoint_count
;
7407 /* That's it. Discard the cleanups for data inserted into the
7409 discard_cleanups (bkpt_chain
);
7410 /* But cleanup everything else. */
7411 do_cleanups (old_chain
);
7413 /* error call may happen here - have BKPT_CHAIN already discarded. */
7414 update_global_location_list (1);
7419 /* Set a breakpoint.
7420 ARG is a string describing breakpoint address,
7421 condition, and thread.
7422 FLAG specifies if a breakpoint is hardware on,
7423 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7427 break_command_1 (char *arg
, int flag
, int from_tty
)
7429 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7430 int tempflag
= flag
& BP_TEMPFLAG
;
7432 create_breakpoint (get_current_arch (),
7434 NULL
, 0, 1 /* parse arg */,
7435 tempflag
, hardwareflag
, 0 /* traceflag */,
7436 0 /* Ignore count */,
7437 pending_break_support
,
7438 NULL
/* breakpoint_ops */,
7445 /* Helper function for break_command_1 and disassemble_command. */
7448 resolve_sal_pc (struct symtab_and_line
*sal
)
7452 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7454 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7455 error (_("No line %d in file \"%s\"."),
7456 sal
->line
, sal
->symtab
->filename
);
7459 /* If this SAL corresponds to a breakpoint inserted using
7460 a line number, then skip the function prologue if necessary. */
7461 if (sal
->explicit_line
)
7462 skip_prologue_sal (sal
);
7465 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7467 struct blockvector
*bv
;
7471 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7474 sym
= block_linkage_function (b
);
7477 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7478 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7482 /* It really is worthwhile to have the section, so we'll just
7483 have to look harder. This case can be executed if we have
7484 line numbers but no functions (as can happen in assembly
7487 struct minimal_symbol
*msym
;
7488 struct cleanup
*old_chain
= save_current_space_and_thread ();
7490 switch_to_program_space_and_thread (sal
->pspace
);
7492 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7494 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7496 do_cleanups (old_chain
);
7503 break_command (char *arg
, int from_tty
)
7505 break_command_1 (arg
, 0, from_tty
);
7509 tbreak_command (char *arg
, int from_tty
)
7511 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7515 hbreak_command (char *arg
, int from_tty
)
7517 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7521 thbreak_command (char *arg
, int from_tty
)
7523 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7527 stop_command (char *arg
, int from_tty
)
7529 printf_filtered (_("Specify the type of breakpoint to set.\n\
7530 Usage: stop in <function | address>\n\
7531 stop at <line>\n"));
7535 stopin_command (char *arg
, int from_tty
)
7539 if (arg
== (char *) NULL
)
7541 else if (*arg
!= '*')
7546 /* look for a ':'. If this is a line number specification, then
7547 say it is bad, otherwise, it should be an address or
7548 function/method name */
7549 while (*argptr
&& !hasColon
)
7551 hasColon
= (*argptr
== ':');
7556 badInput
= (*argptr
!= ':'); /* Not a class::method */
7558 badInput
= isdigit (*arg
); /* a simple line number */
7562 printf_filtered (_("Usage: stop in <function | address>\n"));
7564 break_command_1 (arg
, 0, from_tty
);
7568 stopat_command (char *arg
, int from_tty
)
7572 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7579 /* look for a ':'. If there is a '::' then get out, otherwise
7580 it is probably a line number. */
7581 while (*argptr
&& !hasColon
)
7583 hasColon
= (*argptr
== ':');
7588 badInput
= (*argptr
== ':'); /* we have class::method */
7590 badInput
= !isdigit (*arg
); /* not a line number */
7594 printf_filtered (_("Usage: stop at <line>\n"));
7596 break_command_1 (arg
, 0, from_tty
);
7599 /* accessflag: hw_write: watch write,
7600 hw_read: watch read,
7601 hw_access: watch access (read or write) */
7603 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7605 struct gdbarch
*gdbarch
= get_current_arch ();
7606 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7607 struct expression
*exp
;
7608 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7609 struct value
*val
, *mark
;
7610 struct frame_info
*frame
;
7611 char *exp_start
= NULL
;
7612 char *exp_end
= NULL
;
7613 char *tok
, *id_tok_start
, *end_tok
;
7615 char *cond_start
= NULL
;
7616 char *cond_end
= NULL
;
7617 int i
, other_type_used
, target_resources_ok
= 0;
7618 enum bptype bp_type
;
7622 /* Make sure that we actually have parameters to parse. */
7623 if (arg
!= NULL
&& arg
[0] != '\0')
7625 toklen
= strlen (arg
); /* Size of argument list. */
7627 /* Points tok to the end of the argument list. */
7628 tok
= arg
+ toklen
- 1;
7630 /* Go backwards in the parameters list. Skip the last parameter.
7631 If we're expecting a 'thread <thread_num>' parameter, this should
7632 be the thread identifier. */
7633 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7635 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7638 /* Points end_tok to the beginning of the last token. */
7639 id_tok_start
= tok
+ 1;
7641 /* Go backwards in the parameters list. Skip one more parameter.
7642 If we're expecting a 'thread <thread_num>' parameter, we should
7643 reach a "thread" token. */
7644 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7649 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7652 /* Move the pointer forward to skip the whitespace and
7653 calculate the length of the token. */
7655 toklen
= end_tok
- tok
;
7657 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7659 /* At this point we've found a "thread" token, which means
7660 the user is trying to set a watchpoint that triggers
7661 only in a specific thread. */
7664 /* Extract the thread ID from the next token. */
7665 thread
= strtol (id_tok_start
, &endp
, 0);
7667 /* Check if the user provided a valid numeric value for the
7669 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7670 error (_("Invalid thread ID specification %s."), id_tok_start
);
7672 /* Check if the thread actually exists. */
7673 if (!valid_thread_id (thread
))
7674 error (_("Unknown thread %d."), thread
);
7676 /* Truncate the string and get rid of the thread <thread_num>
7677 parameter before the parameter list is parsed by the
7678 evaluate_expression() function. */
7683 /* Parse the rest of the arguments. */
7684 innermost_block
= NULL
;
7686 exp
= parse_exp_1 (&arg
, 0, 0);
7688 /* Remove trailing whitespace from the expression before saving it.
7689 This makes the eventual display of the expression string a bit
7691 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7694 exp_valid_block
= innermost_block
;
7695 mark
= value_mark ();
7696 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7698 release_value (val
);
7701 while (*tok
== ' ' || *tok
== '\t')
7705 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7708 toklen
= end_tok
- tok
;
7709 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7711 struct expression
*cond
;
7713 innermost_block
= NULL
;
7714 tok
= cond_start
= end_tok
+ 1;
7715 cond
= parse_exp_1 (&tok
, 0, 0);
7717 /* The watchpoint expression may not be local, but the condition
7718 may still be. E.g.: `watch global if local > 0'. */
7719 cond_exp_valid_block
= innermost_block
;
7725 error (_("Junk at end of command."));
7727 if (accessflag
== hw_read
)
7728 bp_type
= bp_read_watchpoint
;
7729 else if (accessflag
== hw_access
)
7730 bp_type
= bp_access_watchpoint
;
7732 bp_type
= bp_hardware_watchpoint
;
7734 mem_cnt
= can_use_hardware_watchpoint (val
);
7735 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7736 error (_("Expression cannot be implemented with read/access watchpoint."));
7739 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7740 target_resources_ok
=
7741 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7743 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7744 error (_("Target does not support this type of hardware watchpoint."));
7746 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7747 error (_("Target can only support one kind of HW watchpoint at a time."));
7750 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7751 watchpoint could not be set. */
7752 if (!mem_cnt
|| target_resources_ok
<= 0)
7753 bp_type
= bp_watchpoint
;
7755 frame
= block_innermost_frame (exp_valid_block
);
7757 /* If the expression is "local", then set up a "watchpoint scope"
7758 breakpoint at the point where we've left the scope of the watchpoint
7759 expression. Create the scope breakpoint before the watchpoint, so
7760 that we will encounter it first in bpstat_stop_status. */
7761 if (exp_valid_block
&& frame
)
7763 if (frame_id_p (frame_unwind_caller_id (frame
)))
7766 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7767 frame_unwind_caller_pc (frame
),
7768 bp_watchpoint_scope
);
7770 scope_breakpoint
->enable_state
= bp_enabled
;
7772 /* Automatically delete the breakpoint when it hits. */
7773 scope_breakpoint
->disposition
= disp_del
;
7775 /* Only break in the proper frame (help with recursion). */
7776 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7778 /* Set the address at which we will stop. */
7779 scope_breakpoint
->loc
->gdbarch
7780 = frame_unwind_caller_arch (frame
);
7781 scope_breakpoint
->loc
->requested_address
7782 = frame_unwind_caller_pc (frame
);
7783 scope_breakpoint
->loc
->address
7784 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7785 scope_breakpoint
->loc
->requested_address
,
7786 scope_breakpoint
->type
);
7790 /* Now set up the breakpoint. */
7791 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7792 set_breakpoint_count (breakpoint_count
+ 1);
7793 b
->number
= breakpoint_count
;
7795 b
->disposition
= disp_donttouch
;
7797 b
->exp_valid_block
= exp_valid_block
;
7798 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7799 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7803 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7809 b
->watchpoint_frame
= get_frame_id (frame
);
7810 b
->watchpoint_thread
= inferior_ptid
;
7814 b
->watchpoint_frame
= null_frame_id
;
7815 b
->watchpoint_thread
= null_ptid
;
7818 if (scope_breakpoint
!= NULL
)
7820 /* The scope breakpoint is related to the watchpoint. We will
7821 need to act on them together. */
7822 b
->related_breakpoint
= scope_breakpoint
;
7823 scope_breakpoint
->related_breakpoint
= b
;
7826 value_free_to_mark (mark
);
7828 /* Finally update the new watchpoint. This creates the locations
7829 that should be inserted. */
7830 update_watchpoint (b
, 1);
7833 update_global_location_list (1);
7836 /* Return count of locations need to be watched and can be handled
7837 in hardware. If the watchpoint can not be handled
7838 in hardware return zero. */
7841 can_use_hardware_watchpoint (struct value
*v
)
7843 int found_memory_cnt
= 0;
7844 struct value
*head
= v
;
7846 /* Did the user specifically forbid us to use hardware watchpoints? */
7847 if (!can_use_hw_watchpoints
)
7850 /* Make sure that the value of the expression depends only upon
7851 memory contents, and values computed from them within GDB. If we
7852 find any register references or function calls, we can't use a
7853 hardware watchpoint.
7855 The idea here is that evaluating an expression generates a series
7856 of values, one holding the value of every subexpression. (The
7857 expression a*b+c has five subexpressions: a, b, a*b, c, and
7858 a*b+c.) GDB's values hold almost enough information to establish
7859 the criteria given above --- they identify memory lvalues,
7860 register lvalues, computed values, etcetera. So we can evaluate
7861 the expression, and then scan the chain of values that leaves
7862 behind to decide whether we can detect any possible change to the
7863 expression's final value using only hardware watchpoints.
7865 However, I don't think that the values returned by inferior
7866 function calls are special in any way. So this function may not
7867 notice that an expression involving an inferior function call
7868 can't be watched with hardware watchpoints. FIXME. */
7869 for (; v
; v
= value_next (v
))
7871 if (VALUE_LVAL (v
) == lval_memory
)
7874 /* A lazy memory lvalue is one that GDB never needed to fetch;
7875 we either just used its address (e.g., `a' in `a.b') or
7876 we never needed it at all (e.g., `a' in `a,b'). */
7880 /* Ahh, memory we actually used! Check if we can cover
7881 it with hardware watchpoints. */
7882 struct type
*vtype
= check_typedef (value_type (v
));
7884 /* We only watch structs and arrays if user asked for it
7885 explicitly, never if they just happen to appear in a
7886 middle of some value chain. */
7888 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7889 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7891 CORE_ADDR vaddr
= value_address (v
);
7892 int len
= TYPE_LENGTH (value_type (v
));
7894 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7901 else if (VALUE_LVAL (v
) != not_lval
7902 && deprecated_value_modifiable (v
) == 0)
7903 return 0; /* ??? What does this represent? */
7904 else if (VALUE_LVAL (v
) == lval_register
)
7905 return 0; /* cannot watch a register with a HW watchpoint */
7908 /* The expression itself looks suitable for using a hardware
7909 watchpoint, but give the target machine a chance to reject it. */
7910 return found_memory_cnt
;
7914 watch_command_wrapper (char *arg
, int from_tty
)
7916 watch_command (arg
, from_tty
);
7920 watch_command (char *arg
, int from_tty
)
7922 watch_command_1 (arg
, hw_write
, from_tty
);
7926 rwatch_command_wrapper (char *arg
, int from_tty
)
7928 rwatch_command (arg
, from_tty
);
7932 rwatch_command (char *arg
, int from_tty
)
7934 watch_command_1 (arg
, hw_read
, from_tty
);
7938 awatch_command_wrapper (char *arg
, int from_tty
)
7940 awatch_command (arg
, from_tty
);
7944 awatch_command (char *arg
, int from_tty
)
7946 watch_command_1 (arg
, hw_access
, from_tty
);
7950 /* Helper routines for the until_command routine in infcmd.c. Here
7951 because it uses the mechanisms of breakpoints. */
7953 struct until_break_command_continuation_args
7955 struct breakpoint
*breakpoint
;
7956 struct breakpoint
*breakpoint2
;
7959 /* This function is called by fetch_inferior_event via the
7960 cmd_continuation pointer, to complete the until command. It takes
7961 care of cleaning up the temporary breakpoints set up by the until
7964 until_break_command_continuation (void *arg
)
7966 struct until_break_command_continuation_args
*a
= arg
;
7968 delete_breakpoint (a
->breakpoint
);
7970 delete_breakpoint (a
->breakpoint2
);
7974 until_break_command (char *arg
, int from_tty
, int anywhere
)
7976 struct symtabs_and_lines sals
;
7977 struct symtab_and_line sal
;
7978 struct frame_info
*frame
= get_selected_frame (NULL
);
7979 struct breakpoint
*breakpoint
;
7980 struct breakpoint
*breakpoint2
= NULL
;
7981 struct cleanup
*old_chain
;
7983 clear_proceed_status ();
7985 /* Set a breakpoint where the user wants it and at return from
7988 if (default_breakpoint_valid
)
7989 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
7990 default_breakpoint_line
, (char ***) NULL
, NULL
);
7992 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
7993 0, (char ***) NULL
, NULL
);
7995 if (sals
.nelts
!= 1)
7996 error (_("Couldn't get information on specified line."));
7999 xfree (sals
.sals
); /* malloc'd, so freed */
8002 error (_("Junk at end of arguments."));
8004 resolve_sal_pc (&sal
);
8007 /* If the user told us to continue until a specified location,
8008 we don't specify a frame at which we need to stop. */
8009 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8010 null_frame_id
, bp_until
);
8012 /* Otherwise, specify the selected frame, because we want to stop only
8013 at the very same frame. */
8014 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8015 get_stack_frame_id (frame
),
8018 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8020 /* Keep within the current frame, or in frames called by the current
8023 if (frame_id_p (frame_unwind_caller_id (frame
)))
8025 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8026 sal
.pc
= frame_unwind_caller_pc (frame
);
8027 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8029 frame_unwind_caller_id (frame
),
8031 make_cleanup_delete_breakpoint (breakpoint2
);
8034 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8036 /* If we are running asynchronously, and proceed call above has actually
8037 managed to start the target, arrange for breakpoints to be
8038 deleted when the target stops. Otherwise, we're already stopped and
8039 delete breakpoints via cleanup chain. */
8041 if (target_can_async_p () && is_running (inferior_ptid
))
8043 struct until_break_command_continuation_args
*args
;
8044 args
= xmalloc (sizeof (*args
));
8046 args
->breakpoint
= breakpoint
;
8047 args
->breakpoint2
= breakpoint2
;
8049 discard_cleanups (old_chain
);
8050 add_continuation (inferior_thread (),
8051 until_break_command_continuation
, args
,
8055 do_cleanups (old_chain
);
8059 ep_skip_leading_whitespace (char **s
)
8061 if ((s
== NULL
) || (*s
== NULL
))
8063 while (isspace (**s
))
8067 /* This function attempts to parse an optional "if <cond>" clause
8068 from the arg string. If one is not found, it returns NULL.
8070 Else, it returns a pointer to the condition string. (It does not
8071 attempt to evaluate the string against a particular block.) And,
8072 it updates arg to point to the first character following the parsed
8073 if clause in the arg string. */
8076 ep_parse_optional_if_clause (char **arg
)
8080 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8083 /* Skip the "if" keyword. */
8086 /* Skip any extra leading whitespace, and record the start of the
8087 condition string. */
8088 ep_skip_leading_whitespace (arg
);
8091 /* Assume that the condition occupies the remainder of the arg string. */
8092 (*arg
) += strlen (cond_string
);
8097 /* Commands to deal with catching events, such as signals, exceptions,
8098 process start/exit, etc. */
8102 catch_fork_temporary
, catch_vfork_temporary
,
8103 catch_fork_permanent
, catch_vfork_permanent
8108 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8110 struct gdbarch
*gdbarch
= get_current_arch ();
8111 char *cond_string
= NULL
;
8112 catch_fork_kind fork_kind
;
8115 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8116 tempflag
= (fork_kind
== catch_fork_temporary
8117 || fork_kind
== catch_vfork_temporary
);
8121 ep_skip_leading_whitespace (&arg
);
8123 /* The allowed syntax is:
8125 catch [v]fork if <cond>
8127 First, check if there's an if clause. */
8128 cond_string
= ep_parse_optional_if_clause (&arg
);
8130 if ((*arg
!= '\0') && !isspace (*arg
))
8131 error (_("Junk at end of arguments."));
8133 /* If this target supports it, create a fork or vfork catchpoint
8134 and enable reporting of such events. */
8137 case catch_fork_temporary
:
8138 case catch_fork_permanent
:
8139 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8140 &catch_fork_breakpoint_ops
);
8142 case catch_vfork_temporary
:
8143 case catch_vfork_permanent
:
8144 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8145 &catch_vfork_breakpoint_ops
);
8148 error (_("unsupported or unknown fork kind; cannot catch it"));
8154 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8156 struct gdbarch
*gdbarch
= get_current_arch ();
8158 char *cond_string
= NULL
;
8160 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8164 ep_skip_leading_whitespace (&arg
);
8166 /* The allowed syntax is:
8168 catch exec if <cond>
8170 First, check if there's an if clause. */
8171 cond_string
= ep_parse_optional_if_clause (&arg
);
8173 if ((*arg
!= '\0') && !isspace (*arg
))
8174 error (_("Junk at end of arguments."));
8176 /* If this target supports it, create an exec catchpoint
8177 and enable reporting of such events. */
8178 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8179 &catch_exec_breakpoint_ops
);
8182 static enum print_stop_action
8183 print_exception_catchpoint (struct breakpoint
*b
)
8185 int bp_temp
, bp_throw
;
8187 annotate_catchpoint (b
->number
);
8189 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8190 if (b
->loc
->address
!= b
->loc
->requested_address
)
8191 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8194 bp_temp
= b
->disposition
== disp_del
;
8196 bp_temp
? "Temporary catchpoint "
8198 if (!ui_out_is_mi_like_p (uiout
))
8199 ui_out_field_int (uiout
, "bkptno", b
->number
);
8201 bp_throw
? " (exception thrown), "
8202 : " (exception caught), ");
8203 if (ui_out_is_mi_like_p (uiout
))
8205 ui_out_field_string (uiout
, "reason",
8206 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8207 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8208 ui_out_field_int (uiout
, "bkptno", b
->number
);
8210 return PRINT_SRC_AND_LOC
;
8214 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8216 struct value_print_options opts
;
8217 get_user_print_options (&opts
);
8218 if (opts
.addressprint
)
8221 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8222 ui_out_field_string (uiout
, "addr", "<PENDING>");
8224 ui_out_field_core_addr (uiout
, "addr",
8225 b
->loc
->gdbarch
, b
->loc
->address
);
8230 if (strstr (b
->addr_string
, "throw") != NULL
)
8231 ui_out_field_string (uiout
, "what", "exception throw");
8233 ui_out_field_string (uiout
, "what", "exception catch");
8237 print_mention_exception_catchpoint (struct breakpoint
*b
)
8242 bp_temp
= b
->disposition
== disp_del
;
8243 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8244 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8245 : _("Catchpoint "));
8246 ui_out_field_int (uiout
, "bkptno", b
->number
);
8247 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8251 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8254 NULL
, /* breakpoint_hit */
8255 print_exception_catchpoint
,
8256 print_one_exception_catchpoint
,
8257 print_mention_exception_catchpoint
8261 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8262 enum exception_event_kind ex_event
, int from_tty
)
8264 char *trigger_func_name
;
8266 if (ex_event
== EX_EVENT_CATCH
)
8267 trigger_func_name
= "__cxa_begin_catch";
8269 trigger_func_name
= "__cxa_throw";
8271 create_breakpoint (get_current_arch (),
8272 trigger_func_name
, cond_string
, -1,
8273 0 /* condition and thread are valid. */,
8276 AUTO_BOOLEAN_TRUE
/* pending */,
8277 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8283 /* Deal with "catch catch" and "catch throw" commands */
8286 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8287 int tempflag
, int from_tty
)
8289 char *cond_string
= NULL
;
8290 struct symtab_and_line
*sal
= NULL
;
8294 ep_skip_leading_whitespace (&arg
);
8296 cond_string
= ep_parse_optional_if_clause (&arg
);
8298 if ((*arg
!= '\0') && !isspace (*arg
))
8299 error (_("Junk at end of arguments."));
8301 if (ex_event
!= EX_EVENT_THROW
8302 && ex_event
!= EX_EVENT_CATCH
)
8303 error (_("Unsupported or unknown exception event; cannot catch it"));
8305 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8308 warning (_("Unsupported with this platform/compiler combination."));
8311 /* Implementation of "catch catch" command. */
8314 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8316 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8317 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8320 /* Implementation of "catch throw" command. */
8323 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8325 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8326 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8329 /* Create a breakpoint struct for Ada exception catchpoints. */
8332 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8333 struct symtab_and_line sal
,
8337 struct expression
*cond
,
8338 struct breakpoint_ops
*ops
,
8342 struct breakpoint
*b
;
8346 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8348 loc_gdbarch
= gdbarch
;
8350 describe_other_breakpoints (loc_gdbarch
,
8351 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8352 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8353 version for exception catchpoints, because two catchpoints
8354 used for different exception names will use the same address.
8355 In this case, a "breakpoint ... also set at..." warning is
8356 unproductive. Besides. the warning phrasing is also a bit
8357 inapropriate, we should use the word catchpoint, and tell
8358 the user what type of catchpoint it is. The above is good
8359 enough for now, though. */
8362 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8363 set_breakpoint_count (breakpoint_count
+ 1);
8365 b
->enable_state
= bp_enabled
;
8366 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8367 b
->number
= breakpoint_count
;
8368 b
->ignore_count
= 0;
8369 b
->loc
->cond
= cond
;
8370 b
->addr_string
= addr_string
;
8371 b
->language
= language_ada
;
8372 b
->cond_string
= cond_string
;
8373 b
->exp_string
= exp_string
;
8378 update_global_location_list (1);
8381 /* Implement the "catch exception" command. */
8384 catch_ada_exception_command (char *arg
, int from_tty
,
8385 struct cmd_list_element
*command
)
8387 struct gdbarch
*gdbarch
= get_current_arch ();
8389 struct symtab_and_line sal
;
8391 char *addr_string
= NULL
;
8392 char *exp_string
= NULL
;
8393 char *cond_string
= NULL
;
8394 struct expression
*cond
= NULL
;
8395 struct breakpoint_ops
*ops
= NULL
;
8397 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8401 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8402 &cond_string
, &cond
, &ops
);
8403 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8404 cond_string
, cond
, ops
, tempflag
,
8408 /* Cleanup function for a syscall filter list. */
8410 clean_up_filters (void *arg
)
8412 VEC(int) *iter
= *(VEC(int) **) arg
;
8413 VEC_free (int, iter
);
8416 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8417 filter list, or NULL if no filtering is required. */
8419 catch_syscall_split_args (char *arg
)
8421 VEC(int) *result
= NULL
;
8422 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8424 while (*arg
!= '\0')
8426 int i
, syscall_number
;
8431 /* Skip whitespace. */
8432 while (isspace (*arg
))
8435 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8436 cur_name
[i
] = arg
[i
];
8440 /* Check if the user provided a syscall name or a number. */
8441 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8442 if (*endptr
== '\0')
8443 get_syscall_by_number (syscall_number
, &s
);
8446 /* We have a name. Let's check if it's valid and convert it
8448 get_syscall_by_name (cur_name
, &s
);
8450 if (s
.number
== UNKNOWN_SYSCALL
)
8451 /* Here we have to issue an error instead of a warning, because
8452 GDB cannot do anything useful if there's no syscall number to
8454 error (_("Unknown syscall name '%s'."), cur_name
);
8457 /* Ok, it's valid. */
8458 VEC_safe_push (int, result
, s
.number
);
8461 discard_cleanups (cleanup
);
8465 /* Implement the "catch syscall" command. */
8468 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8473 struct gdbarch
*gdbarch
= get_current_arch ();
8475 /* Checking if the feature if supported. */
8476 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8477 error (_("The feature 'catch syscall' is not supported on \
8478 this architeture yet."));
8480 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8482 ep_skip_leading_whitespace (&arg
);
8484 /* We need to do this first "dummy" translation in order
8485 to get the syscall XML file loaded or, most important,
8486 to display a warning to the user if there's no XML file
8487 for his/her architecture. */
8488 get_syscall_by_number (0, &s
);
8490 /* The allowed syntax is:
8492 catch syscall <name | number> [<name | number> ... <name | number>]
8494 Let's check if there's a syscall name. */
8497 filter
= catch_syscall_split_args (arg
);
8501 create_syscall_event_catchpoint (tempflag
, filter
,
8502 &catch_syscall_breakpoint_ops
);
8505 /* Implement the "catch assert" command. */
8508 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8510 struct gdbarch
*gdbarch
= get_current_arch ();
8512 struct symtab_and_line sal
;
8513 char *addr_string
= NULL
;
8514 struct breakpoint_ops
*ops
= NULL
;
8516 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8520 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8521 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8522 ops
, tempflag
, from_tty
);
8526 catch_command (char *arg
, int from_tty
)
8528 error (_("Catch requires an event name."));
8533 tcatch_command (char *arg
, int from_tty
)
8535 error (_("Catch requires an event name."));
8538 /* Delete breakpoints by address or line. */
8541 clear_command (char *arg
, int from_tty
)
8543 struct breakpoint
*b
;
8544 VEC(breakpoint_p
) *found
= 0;
8547 struct symtabs_and_lines sals
;
8548 struct symtab_and_line sal
;
8553 sals
= decode_line_spec (arg
, 1);
8558 sals
.sals
= (struct symtab_and_line
*)
8559 xmalloc (sizeof (struct symtab_and_line
));
8560 make_cleanup (xfree
, sals
.sals
);
8561 init_sal (&sal
); /* initialize to zeroes */
8562 sal
.line
= default_breakpoint_line
;
8563 sal
.symtab
= default_breakpoint_symtab
;
8564 sal
.pc
= default_breakpoint_address
;
8565 sal
.pspace
= default_breakpoint_pspace
;
8566 if (sal
.symtab
== 0)
8567 error (_("No source file specified."));
8575 /* We don't call resolve_sal_pc here. That's not
8576 as bad as it seems, because all existing breakpoints
8577 typically have both file/line and pc set. So, if
8578 clear is given file/line, we can match this to existing
8579 breakpoint without obtaining pc at all.
8581 We only support clearing given the address explicitly
8582 present in breakpoint table. Say, we've set breakpoint
8583 at file:line. There were several PC values for that file:line,
8584 due to optimization, all in one block.
8585 We've picked one PC value. If "clear" is issued with another
8586 PC corresponding to the same file:line, the breakpoint won't
8587 be cleared. We probably can still clear the breakpoint, but
8588 since the other PC value is never presented to user, user
8589 can only find it by guessing, and it does not seem important
8592 /* For each line spec given, delete bps which correspond
8593 to it. Do it in two passes, solely to preserve the current
8594 behavior that from_tty is forced true if we delete more than
8598 for (i
= 0; i
< sals
.nelts
; i
++)
8600 /* If exact pc given, clear bpts at that pc.
8601 If line given (pc == 0), clear all bpts on specified line.
8602 If defaulting, clear all bpts on default line
8605 defaulting sal.pc != 0 tests to do
8610 1 0 <can't happen> */
8614 /* Find all matching breakpoints and add them to
8619 /* Are we going to delete b? */
8620 if (b
->type
!= bp_none
8621 && b
->type
!= bp_watchpoint
8622 && b
->type
!= bp_hardware_watchpoint
8623 && b
->type
!= bp_read_watchpoint
8624 && b
->type
!= bp_access_watchpoint
)
8626 struct bp_location
*loc
= b
->loc
;
8627 for (; loc
; loc
= loc
->next
)
8629 int pc_match
= sal
.pc
8630 && (loc
->pspace
== sal
.pspace
)
8631 && (loc
->address
== sal
.pc
)
8632 && (!section_is_overlay (loc
->section
)
8633 || loc
->section
== sal
.section
);
8634 int line_match
= ((default_match
|| (0 == sal
.pc
))
8635 && b
->source_file
!= NULL
8636 && sal
.symtab
!= NULL
8637 && sal
.pspace
== loc
->pspace
8638 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8639 && b
->line_number
== sal
.line
);
8640 if (pc_match
|| line_match
)
8649 VEC_safe_push(breakpoint_p
, found
, b
);
8652 /* Now go thru the 'found' chain and delete them. */
8653 if (VEC_empty(breakpoint_p
, found
))
8656 error (_("No breakpoint at %s."), arg
);
8658 error (_("No breakpoint at this line."));
8661 if (VEC_length(breakpoint_p
, found
) > 1)
8662 from_tty
= 1; /* Always report if deleted more than one */
8665 if (VEC_length(breakpoint_p
, found
) == 1)
8666 printf_unfiltered (_("Deleted breakpoint "));
8668 printf_unfiltered (_("Deleted breakpoints "));
8670 breakpoints_changed ();
8672 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8675 printf_unfiltered ("%d ", b
->number
);
8676 delete_breakpoint (b
);
8679 putchar_unfiltered ('\n');
8682 /* Delete breakpoint in BS if they are `delete' breakpoints and
8683 all breakpoints that are marked for deletion, whether hit or not.
8684 This is called after any breakpoint is hit, or after errors. */
8687 breakpoint_auto_delete (bpstat bs
)
8689 struct breakpoint
*b
, *temp
;
8691 for (; bs
; bs
= bs
->next
)
8692 if (bs
->breakpoint_at
8693 && bs
->breakpoint_at
->owner
8694 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8696 delete_breakpoint (bs
->breakpoint_at
->owner
);
8698 ALL_BREAKPOINTS_SAFE (b
, temp
)
8700 if (b
->disposition
== disp_del_at_next_stop
)
8701 delete_breakpoint (b
);
8705 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8706 Sort elements primarily by their ADDRESS (no matter what does
8707 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8708 first bp_permanent OWNERed elements and terciarily just ensuring the array
8709 is sorted stable way despite qsort being an instable algorithm. */
8712 bp_location_compare (const void *ap
, const void *bp
)
8714 struct bp_location
*a
= *(void **) ap
;
8715 struct bp_location
*b
= *(void **) bp
;
8716 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8717 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8719 if (a
->address
!= b
->address
)
8720 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8722 /* Sort permanent breakpoints first. */
8723 if (a_perm
!= b_perm
)
8724 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8726 /* Make the user-visible order stable across GDB runs. Locations of the same
8727 breakpoint can be sorted in arbitrary order. */
8729 if (a
->owner
->number
!= b
->owner
->number
)
8730 return (a
->owner
->number
> b
->owner
->number
)
8731 - (a
->owner
->number
< b
->owner
->number
);
8733 return (a
> b
) - (a
< b
);
8736 /* Set bp_location_placed_address_before_address_max and
8737 bp_location_shadow_len_after_address_max according to the current content of
8738 the bp_location array. */
8741 bp_location_target_extensions_update (void)
8743 struct bp_location
*bl
, **blp_tmp
;
8745 bp_location_placed_address_before_address_max
= 0;
8746 bp_location_shadow_len_after_address_max
= 0;
8748 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8750 CORE_ADDR start
, end
, addr
;
8752 if (!bp_location_has_shadow (bl
))
8755 start
= bl
->target_info
.placed_address
;
8756 end
= start
+ bl
->target_info
.shadow_len
;
8758 gdb_assert (bl
->address
>= start
);
8759 addr
= bl
->address
- start
;
8760 if (addr
> bp_location_placed_address_before_address_max
)
8761 bp_location_placed_address_before_address_max
= addr
;
8763 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8765 gdb_assert (bl
->address
< end
);
8766 addr
= end
- bl
->address
;
8767 if (addr
> bp_location_shadow_len_after_address_max
)
8768 bp_location_shadow_len_after_address_max
= addr
;
8772 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8773 into the inferior, only remove already-inserted locations that no
8774 longer should be inserted. Functions that delete a breakpoint or
8775 breakpoints should pass false, so that deleting a breakpoint
8776 doesn't have the side effect of inserting the locations of other
8777 breakpoints that are marked not-inserted, but should_be_inserted
8778 returns true on them.
8780 This behaviour is useful is situations close to tear-down -- e.g.,
8781 after an exec, while the target still has execution, but breakpoint
8782 shadows of the previous executable image should *NOT* be restored
8783 to the new image; or before detaching, where the target still has
8784 execution and wants to delete breakpoints from GDB's lists, and all
8785 breakpoints had already been removed from the inferior. */
8788 update_global_location_list (int should_insert
)
8790 struct breakpoint
*b
;
8791 struct bp_location
**locp
, *loc
;
8792 struct cleanup
*cleanups
;
8794 /* Used in the duplicates detection below. When iterating over all
8795 bp_locations, points to the first bp_location of a given address.
8796 Breakpoints and watchpoints of different types are never
8797 duplicates of each other. Keep one pointer for each type of
8798 breakpoint/watchpoint, so we only need to loop over all locations
8800 struct bp_location
*bp_loc_first
; /* breakpoint */
8801 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8802 struct bp_location
*awp_loc_first
; /* access watchpoint */
8803 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8805 /* Saved former bp_location array which we compare against the newly built
8806 bp_location from the current state of ALL_BREAKPOINTS. */
8807 struct bp_location
**old_location
, **old_locp
;
8808 unsigned old_location_count
;
8810 old_location
= bp_location
;
8811 old_location_count
= bp_location_count
;
8813 bp_location_count
= 0;
8814 cleanups
= make_cleanup (xfree
, old_location
);
8817 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8818 bp_location_count
++;
8820 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8823 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8825 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8826 bp_location_compare
);
8828 bp_location_target_extensions_update ();
8830 /* Identify bp_location instances that are no longer present in the new
8831 list, and therefore should be freed. Note that it's not necessary that
8832 those locations should be removed from inferior -- if there's another
8833 location at the same address (previously marked as duplicate),
8834 we don't need to remove/insert the location.
8836 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8837 former bp_location array state respectively. */
8840 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8843 struct bp_location
*old_loc
= *old_locp
;
8844 struct bp_location
**loc2p
;
8846 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8848 int found_object
= 0;
8849 /* Tells if the location should remain inserted in the target. */
8850 int keep_in_target
= 0;
8853 /* Skip LOCP entries which will definitely never be needed. Stop either
8854 at or being the one matching OLD_LOC. */
8855 while (locp
< bp_location
+ bp_location_count
8856 && (*locp
)->address
< old_loc
->address
)
8860 (loc2p
< bp_location
+ bp_location_count
8861 && (*loc2p
)->address
== old_loc
->address
);
8864 if (*loc2p
== old_loc
)
8871 /* If this location is no longer present, and inserted, look if there's
8872 maybe a new location at the same address. If so, mark that one
8873 inserted, and don't remove this one. This is needed so that we
8874 don't have a time window where a breakpoint at certain location is not
8877 if (old_loc
->inserted
)
8879 /* If the location is inserted now, we might have to remove it. */
8881 if (found_object
&& should_be_inserted (old_loc
))
8883 /* The location is still present in the location list, and still
8884 should be inserted. Don't do anything. */
8889 /* The location is either no longer present, or got disabled.
8890 See if there's another location at the same address, in which
8891 case we don't need to remove this one from the target. */
8893 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8896 (loc2p
< bp_location
+ bp_location_count
8897 && (*loc2p
)->address
== old_loc
->address
);
8900 struct bp_location
*loc2
= *loc2p
;
8902 if (breakpoint_locations_match (loc2
, old_loc
))
8904 /* For the sake of should_be_inserted.
8905 Duplicates check below will fix up this later. */
8906 loc2
->duplicate
= 0;
8908 /* Read watchpoint locations are switched to
8909 access watchpoints, if the former are not
8910 supported, but the latter are. */
8911 if (is_hardware_watchpoint (old_loc
->owner
))
8913 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8914 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8917 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8920 loc2
->target_info
= old_loc
->target_info
;
8929 if (!keep_in_target
)
8931 if (remove_breakpoint (old_loc
, mark_uninserted
))
8933 /* This is just about all we can do. We could keep this
8934 location on the global list, and try to remove it next
8935 time, but there's no particular reason why we will
8938 Note that at this point, old_loc->owner is still valid,
8939 as delete_breakpoint frees the breakpoint only
8940 after calling us. */
8941 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8942 old_loc
->owner
->number
);
8950 if (removed
&& non_stop
8951 && breakpoint_address_is_meaningful (old_loc
->owner
)
8952 && !is_hardware_watchpoint (old_loc
->owner
))
8954 /* This location was removed from the target. In
8955 non-stop mode, a race condition is possible where
8956 we've removed a breakpoint, but stop events for that
8957 breakpoint are already queued and will arrive later.
8958 We apply an heuristic to be able to distinguish such
8959 SIGTRAPs from other random SIGTRAPs: we keep this
8960 breakpoint location for a bit, and will retire it
8961 after we see some number of events. The theory here
8962 is that reporting of events should, "on the average",
8963 be fair, so after a while we'll see events from all
8964 threads that have anything of interest, and no longer
8965 need to keep this breakpoint location around. We
8966 don't hold locations forever so to reduce chances of
8967 mistaking a non-breakpoint SIGTRAP for a breakpoint
8970 The heuristic failing can be disastrous on
8971 decr_pc_after_break targets.
8973 On decr_pc_after_break targets, like e.g., x86-linux,
8974 if we fail to recognize a late breakpoint SIGTRAP,
8975 because events_till_retirement has reached 0 too
8976 soon, we'll fail to do the PC adjustment, and report
8977 a random SIGTRAP to the user. When the user resumes
8978 the inferior, it will most likely immediately crash
8979 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
8980 corrupted, because of being resumed e.g., in the
8981 middle of a multi-byte instruction, or skipped a
8982 one-byte instruction. This was actually seen happen
8983 on native x86-linux, and should be less rare on
8984 targets that do not support new thread events, like
8985 remote, due to the heuristic depending on
8988 Mistaking a random SIGTRAP for a breakpoint trap
8989 causes similar symptoms (PC adjustment applied when
8990 it shouldn't), but then again, playing with SIGTRAPs
8991 behind the debugger's back is asking for trouble.
8993 Since hardware watchpoint traps are always
8994 distinguishable from other traps, so we don't need to
8995 apply keep hardware watchpoint moribund locations
8996 around. We simply always ignore hardware watchpoint
8997 traps we can no longer explain. */
8999 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9000 old_loc
->owner
= NULL
;
9002 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9005 free_bp_location (old_loc
);
9009 /* Rescan breakpoints at the same address and section, marking the
9010 first one as "first" and any others as "duplicates". This is so
9011 that the bpt instruction is only inserted once. If we have a
9012 permanent breakpoint at the same place as BPT, make that one the
9013 official one, and the rest as duplicates. Permanent breakpoints
9014 are sorted first for the same address.
9016 Do the same for hardware watchpoints, but also considering the
9017 watchpoint's type (regular/access/read) and length. */
9019 bp_loc_first
= NULL
;
9020 wp_loc_first
= NULL
;
9021 awp_loc_first
= NULL
;
9022 rwp_loc_first
= NULL
;
9023 ALL_BP_LOCATIONS (loc
, locp
)
9025 struct breakpoint
*b
= loc
->owner
;
9026 struct bp_location
**loc_first_p
;
9028 if (b
->enable_state
== bp_disabled
9029 || b
->enable_state
== bp_call_disabled
9030 || b
->enable_state
== bp_startup_disabled
9032 || loc
->shlib_disabled
9033 || !breakpoint_address_is_meaningful (b
)
9034 || tracepoint_type (b
))
9037 /* Permanent breakpoint should always be inserted. */
9038 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9039 internal_error (__FILE__
, __LINE__
,
9040 _("allegedly permanent breakpoint is not "
9041 "actually inserted"));
9043 if (b
->type
== bp_hardware_watchpoint
)
9044 loc_first_p
= &wp_loc_first
;
9045 else if (b
->type
== bp_read_watchpoint
)
9046 loc_first_p
= &rwp_loc_first
;
9047 else if (b
->type
== bp_access_watchpoint
)
9048 loc_first_p
= &awp_loc_first
;
9050 loc_first_p
= &bp_loc_first
;
9052 if (*loc_first_p
== NULL
9053 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9054 || !breakpoint_locations_match (loc
, *loc_first_p
))
9063 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9064 && b
->enable_state
!= bp_permanent
)
9065 internal_error (__FILE__
, __LINE__
,
9066 _("another breakpoint was inserted on top of "
9067 "a permanent breakpoint"));
9070 if (breakpoints_always_inserted_mode () && should_insert
9071 && (have_live_inferiors ()
9072 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9073 insert_breakpoint_locations ();
9075 do_cleanups (cleanups
);
9079 breakpoint_retire_moribund (void)
9081 struct bp_location
*loc
;
9084 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9085 if (--(loc
->events_till_retirement
) == 0)
9087 free_bp_location (loc
);
9088 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9094 update_global_location_list_nothrow (int inserting
)
9096 struct gdb_exception e
;
9097 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9098 update_global_location_list (inserting
);
9101 /* Clear BPT from a BPS. */
9103 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9106 for (bs
= bps
; bs
; bs
= bs
->next
)
9107 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9109 bs
->breakpoint_at
= NULL
;
9111 /* bs->commands will be freed later. */
9115 /* Callback for iterate_over_threads. */
9117 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9119 struct breakpoint
*bpt
= data
;
9120 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9124 /* Delete a breakpoint and clean up all traces of it in the data
9128 delete_breakpoint (struct breakpoint
*bpt
)
9130 struct breakpoint
*b
;
9131 struct bp_location
*loc
, *next
;
9133 gdb_assert (bpt
!= NULL
);
9135 /* Has this bp already been deleted? This can happen because multiple
9136 lists can hold pointers to bp's. bpstat lists are especial culprits.
9138 One example of this happening is a watchpoint's scope bp. When the
9139 scope bp triggers, we notice that the watchpoint is out of scope, and
9140 delete it. We also delete its scope bp. But the scope bp is marked
9141 "auto-deleting", and is already on a bpstat. That bpstat is then
9142 checked for auto-deleting bp's, which are deleted.
9144 A real solution to this problem might involve reference counts in bp's,
9145 and/or giving them pointers back to their referencing bpstat's, and
9146 teaching delete_breakpoint to only free a bp's storage when no more
9147 references were extent. A cheaper bandaid was chosen. */
9148 if (bpt
->type
== bp_none
)
9151 /* At least avoid this stale reference until the reference counting of
9152 breakpoints gets resolved. */
9153 if (bpt
->related_breakpoint
!= NULL
)
9155 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9156 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9157 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9158 bpt
->related_breakpoint
= NULL
;
9161 observer_notify_breakpoint_deleted (bpt
->number
);
9163 if (breakpoint_chain
== bpt
)
9164 breakpoint_chain
= bpt
->next
;
9169 b
->next
= bpt
->next
;
9173 decref_counted_command_line (&bpt
->commands
);
9174 xfree (bpt
->cond_string
);
9175 xfree (bpt
->cond_exp
);
9176 xfree (bpt
->addr_string
);
9178 xfree (bpt
->exp_string
);
9179 value_free (bpt
->val
);
9180 xfree (bpt
->source_file
);
9181 xfree (bpt
->exec_pathname
);
9182 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9184 /* Be sure no bpstat's are pointing at it after it's been freed. */
9185 /* FIXME, how can we find all bpstat's?
9186 We just check stop_bpstat for now. Note that we cannot just
9187 remove bpstats pointing at bpt from the stop_bpstat list
9188 entirely, as breakpoint commands are associated with the bpstat;
9189 if we remove it here, then the later call to
9190 bpstat_do_actions (&stop_bpstat);
9191 in event-top.c won't do anything, and temporary breakpoints
9192 with commands won't work. */
9194 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9196 /* Now that breakpoint is removed from breakpoint
9197 list, update the global location list. This
9198 will remove locations that used to belong to
9199 this breakpoint. Do this before freeing
9200 the breakpoint itself, since remove_breakpoint
9201 looks at location's owner. It might be better
9202 design to have location completely self-contained,
9203 but it's not the case now. */
9204 update_global_location_list (0);
9207 /* On the chance that someone will soon try again to delete this same
9208 bp, we mark it as deleted before freeing its storage. */
9209 bpt
->type
= bp_none
;
9215 do_delete_breakpoint_cleanup (void *b
)
9217 delete_breakpoint (b
);
9221 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9223 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9226 /* A callback for map_breakpoint_numbers that calls
9227 delete_breakpoint. */
9230 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9232 delete_breakpoint (b
);
9236 delete_command (char *arg
, int from_tty
)
9238 struct breakpoint
*b
, *temp
;
9244 int breaks_to_delete
= 0;
9246 /* Delete all breakpoints if no argument.
9247 Do not delete internal or call-dummy breakpoints, these
9248 have to be deleted with an explicit breakpoint number argument. */
9251 if (b
->type
!= bp_call_dummy
9252 && b
->type
!= bp_std_terminate
9253 && b
->type
!= bp_shlib_event
9254 && b
->type
!= bp_jit_event
9255 && b
->type
!= bp_thread_event
9256 && b
->type
!= bp_overlay_event
9257 && b
->type
!= bp_longjmp_master
9258 && b
->type
!= bp_std_terminate_master
9261 breaks_to_delete
= 1;
9266 /* Ask user only if there are some breakpoints to delete. */
9268 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9270 ALL_BREAKPOINTS_SAFE (b
, temp
)
9272 if (b
->type
!= bp_call_dummy
9273 && b
->type
!= bp_std_terminate
9274 && b
->type
!= bp_shlib_event
9275 && b
->type
!= bp_thread_event
9276 && b
->type
!= bp_jit_event
9277 && b
->type
!= bp_overlay_event
9278 && b
->type
!= bp_longjmp_master
9279 && b
->type
!= bp_std_terminate_master
9281 delete_breakpoint (b
);
9286 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9290 all_locations_are_pending (struct bp_location
*loc
)
9292 for (; loc
; loc
= loc
->next
)
9293 if (!loc
->shlib_disabled
)
9298 /* Subroutine of update_breakpoint_locations to simplify it.
9299 Return non-zero if multiple fns in list LOC have the same name.
9300 Null names are ignored. */
9303 ambiguous_names_p (struct bp_location
*loc
)
9305 struct bp_location
*l
;
9306 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9307 (int (*) (const void *, const void *)) streq
,
9308 NULL
, xcalloc
, xfree
);
9310 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9313 const char *name
= l
->function_name
;
9315 /* Allow for some names to be NULL, ignore them. */
9319 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9321 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9336 update_breakpoint_locations (struct breakpoint
*b
,
9337 struct symtabs_and_lines sals
)
9341 struct bp_location
*existing_locations
= b
->loc
;
9343 /* If there's no new locations, and all existing locations
9344 are pending, don't do anything. This optimizes
9345 the common case where all locations are in the same
9346 shared library, that was unloaded. We'd like to
9347 retain the location, so that when the library
9348 is loaded again, we don't loose the enabled/disabled
9349 status of the individual locations. */
9350 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9355 for (i
= 0; i
< sals
.nelts
; ++i
)
9357 struct bp_location
*new_loc
=
9358 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9360 /* Reparse conditions, they might contain references to the
9362 if (b
->cond_string
!= NULL
)
9364 struct gdb_exception e
;
9367 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9369 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9374 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9375 b
->number
, e
.message
);
9376 new_loc
->enabled
= 0;
9380 if (b
->source_file
!= NULL
)
9381 xfree (b
->source_file
);
9382 if (sals
.sals
[i
].symtab
== NULL
)
9383 b
->source_file
= NULL
;
9385 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9387 if (b
->line_number
== 0)
9388 b
->line_number
= sals
.sals
[i
].line
;
9391 /* Update locations of permanent breakpoints. */
9392 if (b
->enable_state
== bp_permanent
)
9393 make_breakpoint_permanent (b
);
9395 /* If possible, carry over 'disable' status from existing breakpoints. */
9397 struct bp_location
*e
= existing_locations
;
9398 /* If there are multiple breakpoints with the same function name,
9399 e.g. for inline functions, comparing function names won't work.
9400 Instead compare pc addresses; this is just a heuristic as things
9401 may have moved, but in practice it gives the correct answer
9402 often enough until a better solution is found. */
9403 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9405 for (; e
; e
= e
->next
)
9407 if (!e
->enabled
&& e
->function_name
)
9409 struct bp_location
*l
= b
->loc
;
9410 if (have_ambiguous_names
)
9412 for (; l
; l
= l
->next
)
9413 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9414 l
->pspace
->aspace
, l
->address
))
9422 for (; l
; l
= l
->next
)
9423 if (l
->function_name
9424 && strcmp (e
->function_name
, l
->function_name
) == 0)
9434 update_global_location_list (1);
9438 /* Reset a breakpoint given it's struct breakpoint * BINT.
9439 The value we return ends up being the return value from catch_errors.
9440 Unused in this case. */
9443 breakpoint_re_set_one (void *bint
)
9445 /* get past catch_errs */
9446 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9450 int *not_found_ptr
= ¬_found
;
9451 struct symtabs_and_lines sals
= {0};
9452 struct symtabs_and_lines expanded
= {0};
9454 enum enable_state save_enable
;
9455 struct gdb_exception e
;
9456 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9461 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9465 case bp_hardware_breakpoint
:
9467 case bp_fast_tracepoint
:
9468 /* Do not attempt to re-set breakpoints disabled during startup. */
9469 if (b
->enable_state
== bp_startup_disabled
)
9472 if (b
->addr_string
== NULL
)
9474 /* Anything without a string can't be re-set. */
9475 delete_breakpoint (b
);
9479 set_language (b
->language
);
9480 input_radix
= b
->input_radix
;
9483 save_current_space_and_thread ();
9484 switch_to_program_space_and_thread (b
->pspace
);
9486 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9488 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9493 int not_found_and_ok
= 0;
9494 /* For pending breakpoints, it's expected that parsing
9495 will fail until the right shared library is loaded.
9496 User has already told to create pending breakpoints and
9497 don't need extra messages. If breakpoint is in bp_shlib_disabled
9498 state, then user already saw the message about that breakpoint
9499 being disabled, and don't want to see more errors. */
9501 && (b
->condition_not_parsed
9502 || (b
->loc
&& b
->loc
->shlib_disabled
)
9503 || b
->enable_state
== bp_disabled
))
9504 not_found_and_ok
= 1;
9506 if (!not_found_and_ok
)
9508 /* We surely don't want to warn about the same breakpoint
9509 10 times. One solution, implemented here, is disable
9510 the breakpoint on error. Another solution would be to
9511 have separate 'warning emitted' flag. Since this
9512 happens only when a binary has changed, I don't know
9513 which approach is better. */
9514 b
->enable_state
= bp_disabled
;
9515 throw_exception (e
);
9521 gdb_assert (sals
.nelts
== 1);
9523 resolve_sal_pc (&sals
.sals
[0]);
9524 if (b
->condition_not_parsed
&& s
&& s
[0])
9526 char *cond_string
= 0;
9530 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9531 &cond_string
, &thread
, &task
);
9533 b
->cond_string
= cond_string
;
9536 b
->condition_not_parsed
= 0;
9539 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9542 make_cleanup (xfree
, sals
.sals
);
9543 update_breakpoint_locations (b
, expanded
);
9547 case bp_hardware_watchpoint
:
9548 case bp_read_watchpoint
:
9549 case bp_access_watchpoint
:
9550 /* Watchpoint can be either on expression using entirely global variables,
9551 or it can be on local variables.
9553 Watchpoints of the first kind are never auto-deleted, and even persist
9554 across program restarts. Since they can use variables from shared
9555 libraries, we need to reparse expression as libraries are loaded
9558 Watchpoints on local variables can also change meaning as result
9559 of solib event. For example, if a watchpoint uses both a local and
9560 a global variables in expression, it's a local watchpoint, but
9561 unloading of a shared library will make the expression invalid.
9562 This is not a very common use case, but we still re-evaluate
9563 expression, to avoid surprises to the user.
9565 Note that for local watchpoints, we re-evaluate it only if
9566 watchpoints frame id is still valid. If it's not, it means
9567 the watchpoint is out of scope and will be deleted soon. In fact,
9568 I'm not sure we'll ever be called in this case.
9570 If a local watchpoint's frame id is still valid, then
9571 b->exp_valid_block is likewise valid, and we can safely use it.
9573 Don't do anything about disabled watchpoints, since they will
9574 be reevaluated again when enabled. */
9575 update_watchpoint (b
, 1 /* reparse */);
9577 /* We needn't really do anything to reset these, since the mask
9578 that requests them is unaffected by e.g., new libraries being
9584 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9586 /* Delete overlay event and longjmp master breakpoints; they will be
9587 reset later by breakpoint_re_set. */
9588 case bp_overlay_event
:
9589 case bp_longjmp_master
:
9590 case bp_std_terminate_master
:
9591 delete_breakpoint (b
);
9594 /* This breakpoint is special, it's set up when the inferior
9595 starts and we really don't want to touch it. */
9596 case bp_shlib_event
:
9598 /* Like bp_shlib_event, this breakpoint type is special.
9599 Once it is set up, we do not want to touch it. */
9600 case bp_thread_event
:
9602 /* Keep temporary breakpoints, which can be encountered when we step
9603 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9604 Otherwise these should have been blown away via the cleanup chain
9605 or by breakpoint_init_inferior when we rerun the executable. */
9608 case bp_watchpoint_scope
:
9610 case bp_std_terminate
:
9611 case bp_step_resume
:
9613 case bp_longjmp_resume
:
9618 do_cleanups (cleanups
);
9622 /* Re-set all breakpoints after symbols have been re-loaded. */
9624 breakpoint_re_set (void)
9626 struct breakpoint
*b
, *temp
;
9627 enum language save_language
;
9628 int save_input_radix
;
9629 struct cleanup
*old_chain
;
9631 save_language
= current_language
->la_language
;
9632 save_input_radix
= input_radix
;
9633 old_chain
= save_current_program_space ();
9635 ALL_BREAKPOINTS_SAFE (b
, temp
)
9637 /* Format possible error msg */
9638 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9640 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9641 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9642 do_cleanups (cleanups
);
9644 set_language (save_language
);
9645 input_radix
= save_input_radix
;
9647 jit_breakpoint_re_set ();
9649 do_cleanups (old_chain
);
9651 create_overlay_event_breakpoint ("_ovly_debug_event");
9652 create_longjmp_master_breakpoint ("longjmp");
9653 create_longjmp_master_breakpoint ("_longjmp");
9654 create_longjmp_master_breakpoint ("siglongjmp");
9655 create_longjmp_master_breakpoint ("_siglongjmp");
9656 create_std_terminate_master_breakpoint ("std::terminate()");
9659 /* Reset the thread number of this breakpoint:
9661 - If the breakpoint is for all threads, leave it as-is.
9662 - Else, reset it to the current thread for inferior_ptid. */
9664 breakpoint_re_set_thread (struct breakpoint
*b
)
9666 if (b
->thread
!= -1)
9668 if (in_thread_list (inferior_ptid
))
9669 b
->thread
= pid_to_thread_id (inferior_ptid
);
9671 /* We're being called after following a fork. The new fork is
9672 selected as current, and unless this was a vfork will have a
9673 different program space from the original thread. Reset that
9675 b
->loc
->pspace
= current_program_space
;
9679 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9680 If from_tty is nonzero, it prints a message to that effect,
9681 which ends with a period (no newline). */
9684 set_ignore_count (int bptnum
, int count
, int from_tty
)
9686 struct breakpoint
*b
;
9692 if (b
->number
== bptnum
)
9694 b
->ignore_count
= count
;
9698 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9700 else if (count
== 1)
9701 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9704 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9707 breakpoints_changed ();
9708 observer_notify_breakpoint_modified (b
->number
);
9712 error (_("No breakpoint number %d."), bptnum
);
9716 make_breakpoint_silent (struct breakpoint
*b
)
9718 /* Silence the breakpoint. */
9722 /* Command to set ignore-count of breakpoint N to COUNT. */
9725 ignore_command (char *args
, int from_tty
)
9731 error_no_arg (_("a breakpoint number"));
9733 num
= get_number (&p
);
9735 error (_("bad breakpoint number: '%s'"), args
);
9737 error (_("Second argument (specified ignore-count) is missing."));
9739 set_ignore_count (num
,
9740 longest_to_int (value_as_long (parse_and_eval (p
))),
9743 printf_filtered ("\n");
9746 /* Call FUNCTION on each of the breakpoints
9747 whose numbers are given in ARGS. */
9750 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9757 struct breakpoint
*b
, *tmp
;
9761 error_no_arg (_("one or more breakpoint numbers"));
9768 num
= get_number_or_range (&p1
);
9771 warning (_("bad breakpoint number at or near '%s'"), p
);
9775 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9776 if (b
->number
== num
)
9778 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9781 if (related_breakpoint
)
9782 function (related_breakpoint
, data
);
9786 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9792 static struct bp_location
*
9793 find_location_by_number (char *number
)
9795 char *dot
= strchr (number
, '.');
9799 struct breakpoint
*b
;
9800 struct bp_location
*loc
;
9805 bp_num
= get_number_or_range (&p1
);
9807 error (_("Bad breakpoint number '%s'"), number
);
9810 if (b
->number
== bp_num
)
9815 if (!b
|| b
->number
!= bp_num
)
9816 error (_("Bad breakpoint number '%s'"), number
);
9819 loc_num
= get_number_or_range (&p1
);
9821 error (_("Bad breakpoint location number '%s'"), number
);
9825 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9828 error (_("Bad breakpoint location number '%s'"), dot
+1);
9834 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9835 If from_tty is nonzero, it prints a message to that effect,
9836 which ends with a period (no newline). */
9839 disable_breakpoint (struct breakpoint
*bpt
)
9841 /* Never disable a watchpoint scope breakpoint; we want to
9842 hit them when we leave scope so we can delete both the
9843 watchpoint and its scope breakpoint at that time. */
9844 if (bpt
->type
== bp_watchpoint_scope
)
9847 /* You can't disable permanent breakpoints. */
9848 if (bpt
->enable_state
== bp_permanent
)
9851 bpt
->enable_state
= bp_disabled
;
9853 update_global_location_list (0);
9855 observer_notify_breakpoint_modified (bpt
->number
);
9858 /* A callback for map_breakpoint_numbers that calls
9859 disable_breakpoint. */
9862 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9864 disable_breakpoint (b
);
9868 disable_command (char *args
, int from_tty
)
9870 struct breakpoint
*bpt
;
9872 ALL_BREAKPOINTS (bpt
)
9876 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9881 case bp_fast_tracepoint
:
9883 case bp_hardware_breakpoint
:
9885 case bp_hardware_watchpoint
:
9886 case bp_read_watchpoint
:
9887 case bp_access_watchpoint
:
9888 disable_breakpoint (bpt
);
9892 else if (strchr (args
, '.'))
9894 struct bp_location
*loc
= find_location_by_number (args
);
9897 update_global_location_list (0);
9900 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
9904 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9906 int target_resources_ok
, other_type_used
;
9909 if (bpt
->type
== bp_hardware_breakpoint
)
9912 i
= hw_breakpoint_used_count ();
9913 target_resources_ok
=
9914 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9916 if (target_resources_ok
== 0)
9917 error (_("No hardware breakpoint support in the target."));
9918 else if (target_resources_ok
< 0)
9919 error (_("Hardware breakpoints used exceeds limit."));
9922 if (bpt
->type
== bp_watchpoint
9923 || bpt
->type
== bp_hardware_watchpoint
9924 || bpt
->type
== bp_read_watchpoint
9925 || bpt
->type
== bp_access_watchpoint
)
9927 struct gdb_exception e
;
9929 TRY_CATCH (e
, RETURN_MASK_ALL
)
9931 update_watchpoint (bpt
, 1 /* reparse */);
9935 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9941 if (bpt
->enable_state
!= bp_permanent
)
9942 bpt
->enable_state
= bp_enabled
;
9943 bpt
->disposition
= disposition
;
9944 update_global_location_list (1);
9945 breakpoints_changed ();
9947 observer_notify_breakpoint_modified (bpt
->number
);
9952 enable_breakpoint (struct breakpoint
*bpt
)
9954 do_enable_breakpoint (bpt
, bpt
->disposition
);
9957 /* A callback for map_breakpoint_numbers that calls
9958 enable_breakpoint. */
9961 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
9963 enable_breakpoint (b
);
9966 /* The enable command enables the specified breakpoints (or all defined
9967 breakpoints) so they once again become (or continue to be) effective
9968 in stopping the inferior. */
9971 enable_command (char *args
, int from_tty
)
9973 struct breakpoint
*bpt
;
9975 ALL_BREAKPOINTS (bpt
)
9979 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
9984 case bp_fast_tracepoint
:
9986 case bp_hardware_breakpoint
:
9988 case bp_hardware_watchpoint
:
9989 case bp_read_watchpoint
:
9990 case bp_access_watchpoint
:
9991 enable_breakpoint (bpt
);
9995 else if (strchr (args
, '.'))
9997 struct bp_location
*loc
= find_location_by_number (args
);
10000 update_global_location_list (1);
10003 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10007 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10009 do_enable_breakpoint (bpt
, disp_disable
);
10013 enable_once_command (char *args
, int from_tty
)
10015 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10019 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10021 do_enable_breakpoint (bpt
, disp_del
);
10025 enable_delete_command (char *args
, int from_tty
)
10027 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10031 set_breakpoint_cmd (char *args
, int from_tty
)
10036 show_breakpoint_cmd (char *args
, int from_tty
)
10040 /* Invalidate last known value of any hardware watchpoint if
10041 the memory which that value represents has been written to by
10045 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10046 const bfd_byte
*data
)
10048 struct breakpoint
*bp
;
10050 ALL_BREAKPOINTS (bp
)
10051 if (bp
->enable_state
== bp_enabled
10052 && bp
->type
== bp_hardware_watchpoint
10053 && bp
->val_valid
&& bp
->val
)
10055 struct bp_location
*loc
;
10057 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10058 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10059 && loc
->address
+ loc
->length
> addr
10060 && addr
+ len
> loc
->address
)
10062 value_free (bp
->val
);
10069 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10071 struct symtabs_and_lines
10072 decode_line_spec_1 (char *string
, int funfirstline
)
10074 struct symtabs_and_lines sals
;
10076 error (_("Empty line specification."));
10077 if (default_breakpoint_valid
)
10078 sals
= decode_line_1 (&string
, funfirstline
,
10079 default_breakpoint_symtab
,
10080 default_breakpoint_line
,
10081 (char ***) NULL
, NULL
);
10083 sals
= decode_line_1 (&string
, funfirstline
,
10084 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10086 error (_("Junk at end of line specification: %s"), string
);
10090 /* Create and insert a raw software breakpoint at PC. Return an
10091 identifier, which should be used to remove the breakpoint later.
10092 In general, places which call this should be using something on the
10093 breakpoint chain instead; this function should be eliminated
10097 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10098 struct address_space
*aspace
, CORE_ADDR pc
)
10100 struct bp_target_info
*bp_tgt
;
10102 bp_tgt
= XZALLOC (struct bp_target_info
);
10104 bp_tgt
->placed_address_space
= aspace
;
10105 bp_tgt
->placed_address
= pc
;
10107 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10109 /* Could not insert the breakpoint. */
10117 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10120 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10122 struct bp_target_info
*bp_tgt
= bp
;
10125 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10131 /* One (or perhaps two) breakpoints used for software single stepping. */
10133 static void *single_step_breakpoints
[2];
10134 static struct gdbarch
*single_step_gdbarch
[2];
10136 /* Create and insert a breakpoint for software single step. */
10139 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10140 struct address_space
*aspace
, CORE_ADDR next_pc
)
10144 if (single_step_breakpoints
[0] == NULL
)
10146 bpt_p
= &single_step_breakpoints
[0];
10147 single_step_gdbarch
[0] = gdbarch
;
10151 gdb_assert (single_step_breakpoints
[1] == NULL
);
10152 bpt_p
= &single_step_breakpoints
[1];
10153 single_step_gdbarch
[1] = gdbarch
;
10156 /* NOTE drow/2006-04-11: A future improvement to this function would be
10157 to only create the breakpoints once, and actually put them on the
10158 breakpoint chain. That would let us use set_raw_breakpoint. We could
10159 adjust the addresses each time they were needed. Doing this requires
10160 corresponding changes elsewhere where single step breakpoints are
10161 handled, however. So, for now, we use this. */
10163 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10164 if (*bpt_p
== NULL
)
10165 error (_("Could not insert single-step breakpoint at %s"),
10166 paddress (gdbarch
, next_pc
));
10169 /* Remove and delete any breakpoints used for software single step. */
10172 remove_single_step_breakpoints (void)
10174 gdb_assert (single_step_breakpoints
[0] != NULL
);
10176 /* See insert_single_step_breakpoint for more about this deprecated
10178 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10179 single_step_breakpoints
[0]);
10180 single_step_gdbarch
[0] = NULL
;
10181 single_step_breakpoints
[0] = NULL
;
10183 if (single_step_breakpoints
[1] != NULL
)
10185 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10186 single_step_breakpoints
[1]);
10187 single_step_gdbarch
[1] = NULL
;
10188 single_step_breakpoints
[1] = NULL
;
10192 /* Check whether a software single-step breakpoint is inserted at PC. */
10195 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10199 for (i
= 0; i
< 2; i
++)
10201 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10203 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10204 bp_tgt
->placed_address
,
10212 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10213 non-zero otherwise. */
10215 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10217 if (syscall_catchpoint_p (bp
)
10218 && bp
->enable_state
!= bp_disabled
10219 && bp
->enable_state
!= bp_call_disabled
)
10226 catch_syscall_enabled (void)
10228 struct inferior
*inf
= current_inferior ();
10230 return inf
->total_syscalls_count
!= 0;
10234 catching_syscall_number (int syscall_number
)
10236 struct breakpoint
*bp
;
10238 ALL_BREAKPOINTS (bp
)
10239 if (is_syscall_catchpoint_enabled (bp
))
10241 if (bp
->syscalls_to_be_caught
)
10245 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10247 if (syscall_number
== iter
)
10257 /* Complete syscall names. Used by "catch syscall". */
10259 catch_syscall_completer (struct cmd_list_element
*cmd
,
10260 char *text
, char *word
)
10262 const char **list
= get_syscall_names ();
10263 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10266 /* Tracepoint-specific operations. */
10268 /* Set tracepoint count to NUM. */
10270 set_tracepoint_count (int num
)
10272 tracepoint_count
= num
;
10273 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10277 trace_command (char *arg
, int from_tty
)
10279 if (create_breakpoint (get_current_arch (),
10281 NULL
, 0, 1 /* parse arg */,
10282 0 /* tempflag */, 0 /* hardwareflag */,
10284 0 /* Ignore count */,
10285 pending_break_support
,
10289 set_tracepoint_count (breakpoint_count
);
10293 ftrace_command (char *arg
, int from_tty
)
10295 if (create_breakpoint (get_current_arch (),
10297 NULL
, 0, 1 /* parse arg */,
10298 0 /* tempflag */, 1 /* hardwareflag */,
10300 0 /* Ignore count */,
10301 pending_break_support
,
10305 set_tracepoint_count (breakpoint_count
);
10308 /* Set up a fake reader function that gets command lines from a linked
10309 list that was acquired during tracepoint uploading. */
10311 static struct uploaded_tp
*this_utp
;
10312 static struct uploaded_string
*next_cmd
;
10315 read_uploaded_action (void)
10322 rslt
= next_cmd
->str
;
10323 next_cmd
= next_cmd
->next
;
10328 /* Given information about a tracepoint as recorded on a target (which
10329 can be either a live system or a trace file), attempt to create an
10330 equivalent GDB tracepoint. This is not a reliable process, since
10331 the target does not necessarily have all the information used when
10332 the tracepoint was originally defined. */
10334 struct breakpoint
*
10335 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10337 char *addr_str
, small_buf
[100];
10338 struct breakpoint
*tp
;
10340 if (utp
->at_string
)
10341 addr_str
= utp
->at_string
;
10344 /* In the absence of a source location, fall back to raw
10345 address. Since there is no way to confirm that the address
10346 means the same thing as when the trace was started, warn the
10348 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10350 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
10351 addr_str
= small_buf
;
10354 /* There's not much we can do with a sequence of bytecodes. */
10355 if (utp
->cond
&& !utp
->cond_string
)
10356 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10359 if (!create_breakpoint (get_current_arch (),
10361 utp
->cond_string
, -1, 0 /* parse cond/thread */,
10363 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10365 0 /* Ignore count */,
10366 pending_break_support
,
10369 utp
->enabled
/* enabled */))
10372 set_tracepoint_count (breakpoint_count
);
10374 /* Get the tracepoint we just created. */
10375 tp
= get_tracepoint (tracepoint_count
);
10376 gdb_assert (tp
!= NULL
);
10380 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
10382 trace_pass_command (small_buf
, 0);
10385 /* If we have uploaded versions of the original commands, set up a
10386 special-purpose "reader" function and call the usual command line
10387 reader, then pass the result to the breakpoint command-setting
10389 if (utp
->cmd_strings
)
10391 struct command_line
*cmd_list
;
10394 next_cmd
= utp
->cmd_strings
;
10396 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
10398 breakpoint_set_commands (tp
, cmd_list
);
10400 else if (utp
->numactions
> 0 || utp
->num_step_actions
> 0)
10401 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10407 /* Print information on tracepoint number TPNUM_EXP, or all if
10411 tracepoints_info (char *tpnum_exp
, int from_tty
)
10413 struct breakpoint
*b
;
10414 int tps_to_list
= 0;
10416 /* In the no-arguments case, say "No tracepoints" if none found. */
10417 if (tpnum_exp
== 0)
10419 ALL_TRACEPOINTS (b
)
10421 if (b
->number
>= 0)
10429 ui_out_message (uiout
, 0, "No tracepoints.\n");
10434 /* Otherwise be the same as "info break". */
10435 breakpoints_info (tpnum_exp
, from_tty
);
10438 /* The 'enable trace' command enables tracepoints.
10439 Not supported by all targets. */
10441 enable_trace_command (char *args
, int from_tty
)
10443 enable_command (args
, from_tty
);
10446 /* The 'disable trace' command disables tracepoints.
10447 Not supported by all targets. */
10449 disable_trace_command (char *args
, int from_tty
)
10451 disable_command (args
, from_tty
);
10454 /* Remove a tracepoint (or all if no argument) */
10456 delete_trace_command (char *arg
, int from_tty
)
10458 struct breakpoint
*b
, *temp
;
10464 int breaks_to_delete
= 0;
10466 /* Delete all breakpoints if no argument.
10467 Do not delete internal or call-dummy breakpoints, these
10468 have to be deleted with an explicit breakpoint number argument. */
10469 ALL_TRACEPOINTS (b
)
10471 if (b
->number
>= 0)
10473 breaks_to_delete
= 1;
10478 /* Ask user only if there are some breakpoints to delete. */
10480 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10482 ALL_BREAKPOINTS_SAFE (b
, temp
)
10484 if (tracepoint_type (b
)
10486 delete_breakpoint (b
);
10491 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10494 /* Set passcount for tracepoint.
10496 First command argument is passcount, second is tracepoint number.
10497 If tracepoint number omitted, apply to most recently defined.
10498 Also accepts special argument "all". */
10501 trace_pass_command (char *args
, int from_tty
)
10503 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10504 unsigned int count
;
10507 if (args
== 0 || *args
== 0)
10508 error (_("passcount command requires an argument (count + optional TP num)"));
10510 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10512 while (*args
&& isspace ((int) *args
))
10515 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10517 args
+= 3; /* Skip special argument "all". */
10520 error (_("Junk at end of arguments."));
10523 t1
= get_tracepoint_by_number (&args
, 1, 1);
10529 ALL_TRACEPOINTS (t2
)
10530 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10532 t2
->pass_count
= count
;
10533 observer_notify_tracepoint_modified (t2
->number
);
10535 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10536 t2
->number
, count
);
10538 if (! all
&& *args
)
10539 t1
= get_tracepoint_by_number (&args
, 1, 0);
10545 struct breakpoint
*
10546 get_tracepoint (int num
)
10548 struct breakpoint
*t
;
10550 ALL_TRACEPOINTS (t
)
10551 if (t
->number
== num
)
10557 /* Find the tracepoint with the given target-side number (which may be
10558 different from the tracepoint number after disconnecting and
10561 struct breakpoint
*
10562 get_tracepoint_by_number_on_target (int num
)
10564 struct breakpoint
*t
;
10566 ALL_TRACEPOINTS (t
)
10567 if (t
->number_on_target
== num
)
10573 /* Utility: parse a tracepoint number and look it up in the list.
10574 If MULTI_P is true, there might be a range of tracepoints in ARG.
10575 if OPTIONAL_P is true, then if the argument is missing, the most
10576 recent tracepoint (tracepoint_count) is returned. */
10577 struct breakpoint
*
10578 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10580 extern int tracepoint_count
;
10581 struct breakpoint
*t
;
10583 char *instring
= arg
== NULL
? NULL
: *arg
;
10585 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10588 tpnum
= tracepoint_count
;
10590 error_no_arg (_("tracepoint number"));
10593 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10597 if (instring
&& *instring
)
10598 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10601 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10605 ALL_TRACEPOINTS (t
)
10606 if (t
->number
== tpnum
)
10611 /* FIXME: if we are in the middle of a range we don't want to give
10612 a message. The current interface to get_number_or_range doesn't
10613 allow us to discover this. */
10614 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10618 /* save-tracepoints command */
10620 tracepoint_save_command (char *args
, int from_tty
)
10622 struct breakpoint
*tp
;
10624 struct command_line
*line
;
10627 struct cleanup
*cleanup
;
10628 struct ui_file
*fp
;
10630 if (args
== 0 || *args
== 0)
10631 error (_("Argument required (file name in which to save tracepoints)"));
10633 /* See if we have anything to save. */
10634 ALL_TRACEPOINTS (tp
)
10641 warning (_("save-tracepoints: no tracepoints to save."));
10645 pathname
= tilde_expand (args
);
10646 cleanup
= make_cleanup (xfree
, pathname
);
10647 fp
= gdb_fopen (pathname
, "w");
10649 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10650 args
, safe_strerror (errno
));
10651 make_cleanup_ui_file_delete (fp
);
10653 ALL_TRACEPOINTS (tp
)
10655 if (tp
->addr_string
)
10656 fprintf_unfiltered (fp
, "trace %s\n", tp
->addr_string
);
10659 sprintf_vma (tmp
, tp
->loc
->address
);
10660 fprintf_unfiltered (fp
, "trace *0x%s\n", tmp
);
10663 if (tp
->pass_count
)
10664 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10668 volatile struct gdb_exception ex
;
10670 fprintf_unfiltered (fp
, " actions\n");
10672 ui_out_redirect (uiout
, fp
);
10673 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10675 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10677 ui_out_redirect (uiout
, NULL
);
10680 throw_exception (ex
);
10682 fprintf_unfiltered (fp
, " end\n");
10685 do_cleanups (cleanup
);
10687 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10691 /* Create a vector of all tracepoints. */
10693 VEC(breakpoint_p
) *
10696 VEC(breakpoint_p
) *tp_vec
= 0;
10697 struct breakpoint
*tp
;
10699 ALL_TRACEPOINTS (tp
)
10701 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10708 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10709 It is defined as a macro to prevent duplication.
10710 COMMAND should be a string constant containing the name of the command. */
10711 #define BREAK_ARGS_HELP(command) \
10712 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10713 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10714 If a line number is specified, break at start of code for that line.\n\
10715 If a function is specified, break at start of code for that function.\n\
10716 If an address is specified, break at that exact address.\n\
10717 With no LOCATION, uses current execution address of selected stack frame.\n\
10718 This is useful for breaking on return to a stack frame.\n\
10720 THREADNUM is the number from \"info threads\".\n\
10721 CONDITION is a boolean expression.\n\
10723 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10725 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10727 /* List of subcommands for "catch". */
10728 static struct cmd_list_element
*catch_cmdlist
;
10730 /* List of subcommands for "tcatch". */
10731 static struct cmd_list_element
*tcatch_cmdlist
;
10733 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10734 lists, and pass some additional user data to the command function. */
10736 add_catch_command (char *name
, char *docstring
,
10737 void (*sfunc
) (char *args
, int from_tty
,
10738 struct cmd_list_element
*command
),
10739 char **(*completer
) (struct cmd_list_element
*cmd
,
10740 char *text
, char *word
),
10741 void *user_data_catch
,
10742 void *user_data_tcatch
)
10744 struct cmd_list_element
*command
;
10746 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10748 set_cmd_sfunc (command
, sfunc
);
10749 set_cmd_context (command
, user_data_catch
);
10750 set_cmd_completer (command
, completer
);
10752 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10754 set_cmd_sfunc (command
, sfunc
);
10755 set_cmd_context (command
, user_data_tcatch
);
10756 set_cmd_completer (command
, completer
);
10760 clear_syscall_counts (struct inferior
*inf
)
10762 inf
->total_syscalls_count
= 0;
10763 inf
->any_syscall_count
= 0;
10764 VEC_free (int, inf
->syscalls_counts
);
10768 _initialize_breakpoint (void)
10770 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10771 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10772 struct cmd_list_element
*c
;
10774 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10775 observer_attach_inferior_exit (clear_syscall_counts
);
10776 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10778 breakpoint_chain
= 0;
10779 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10780 before a breakpoint is set. */
10781 breakpoint_count
= 0;
10783 tracepoint_count
= 0;
10785 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10786 Set ignore-count of breakpoint number N to COUNT.\n\
10787 Usage is `ignore N COUNT'."));
10789 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10791 add_com ("commands", class_breakpoint
, commands_command
, _("\
10792 Set commands to be executed when a breakpoint is hit.\n\
10793 Give breakpoint number as argument after \"commands\".\n\
10794 With no argument, the targeted breakpoint is the last one set.\n\
10795 The commands themselves follow starting on the next line.\n\
10796 Type a line containing \"end\" to indicate the end of them.\n\
10797 Give \"silent\" as the first line to make the breakpoint silent;\n\
10798 then no output is printed when it is hit, except what the commands print."));
10800 add_com ("condition", class_breakpoint
, condition_command
, _("\
10801 Specify breakpoint number N to break only if COND is true.\n\
10802 Usage is `condition N COND', where N is an integer and COND is an\n\
10803 expression to be evaluated whenever breakpoint N is reached."));
10805 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10806 Set a temporary breakpoint.\n\
10807 Like \"break\" except the breakpoint is only temporary,\n\
10808 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10809 by using \"enable delete\" on the breakpoint number.\n\
10811 BREAK_ARGS_HELP ("tbreak")));
10812 set_cmd_completer (c
, location_completer
);
10814 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10815 Set a hardware assisted breakpoint.\n\
10816 Like \"break\" except the breakpoint requires hardware support,\n\
10817 some target hardware may not have this support.\n\
10819 BREAK_ARGS_HELP ("hbreak")));
10820 set_cmd_completer (c
, location_completer
);
10822 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10823 Set a temporary hardware assisted breakpoint.\n\
10824 Like \"hbreak\" except the breakpoint is only temporary,\n\
10825 so it will be deleted when hit.\n\
10827 BREAK_ARGS_HELP ("thbreak")));
10828 set_cmd_completer (c
, location_completer
);
10830 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10831 Enable some breakpoints.\n\
10832 Give breakpoint numbers (separated by spaces) as arguments.\n\
10833 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10834 This is used to cancel the effect of the \"disable\" command.\n\
10835 With a subcommand you can enable temporarily."),
10836 &enablelist
, "enable ", 1, &cmdlist
);
10838 add_com ("ab", class_breakpoint
, enable_command
, _("\
10839 Enable some breakpoints.\n\
10840 Give breakpoint numbers (separated by spaces) as arguments.\n\
10841 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10842 This is used to cancel the effect of the \"disable\" command.\n\
10843 With a subcommand you can enable temporarily."));
10845 add_com_alias ("en", "enable", class_breakpoint
, 1);
10847 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10848 Enable some breakpoints.\n\
10849 Give breakpoint numbers (separated by spaces) as arguments.\n\
10850 This is used to cancel the effect of the \"disable\" command.\n\
10851 May be abbreviated to simply \"enable\".\n"),
10852 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10854 add_cmd ("once", no_class
, enable_once_command
, _("\
10855 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10856 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10859 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10860 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10861 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10864 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10865 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10866 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10869 add_cmd ("once", no_class
, enable_once_command
, _("\
10870 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10871 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10874 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10875 Disable some breakpoints.\n\
10876 Arguments are breakpoint numbers with spaces in between.\n\
10877 To disable all breakpoints, give no argument.\n\
10878 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10879 &disablelist
, "disable ", 1, &cmdlist
);
10880 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10881 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10883 add_com ("sb", class_breakpoint
, disable_command
, _("\
10884 Disable some breakpoints.\n\
10885 Arguments are breakpoint numbers with spaces in between.\n\
10886 To disable all breakpoints, give no argument.\n\
10887 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10889 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10890 Disable some breakpoints.\n\
10891 Arguments are breakpoint numbers with spaces in between.\n\
10892 To disable all breakpoints, give no argument.\n\
10893 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10894 This command may be abbreviated \"disable\"."),
10897 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10898 Delete some breakpoints or auto-display expressions.\n\
10899 Arguments are breakpoint numbers with spaces in between.\n\
10900 To delete all breakpoints, give no argument.\n\
10902 Also a prefix command for deletion of other GDB objects.\n\
10903 The \"unset\" command is also an alias for \"delete\"."),
10904 &deletelist
, "delete ", 1, &cmdlist
);
10905 add_com_alias ("d", "delete", class_breakpoint
, 1);
10906 add_com_alias ("del", "delete", class_breakpoint
, 1);
10908 add_com ("db", class_breakpoint
, delete_command
, _("\
10909 Delete some breakpoints.\n\
10910 Arguments are breakpoint numbers with spaces in between.\n\
10911 To delete all breakpoints, give no argument.\n"));
10913 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10914 Delete some breakpoints or auto-display expressions.\n\
10915 Arguments are breakpoint numbers with spaces in between.\n\
10916 To delete all breakpoints, give no argument.\n\
10917 This command may be abbreviated \"delete\"."),
10920 add_com ("clear", class_breakpoint
, clear_command
, _("\
10921 Clear breakpoint at specified line or function.\n\
10922 Argument may be line number, function name, or \"*\" and an address.\n\
10923 If line number is specified, all breakpoints in that line are cleared.\n\
10924 If function is specified, breakpoints at beginning of function are cleared.\n\
10925 If an address is specified, breakpoints at that address are cleared.\n\
10927 With no argument, clears all breakpoints in the line that the selected frame\n\
10928 is executing in.\n\
10930 See also the \"delete\" command which clears breakpoints by number."));
10932 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10933 Set breakpoint at specified line or function.\n"
10934 BREAK_ARGS_HELP ("break")));
10935 set_cmd_completer (c
, location_completer
);
10937 add_com_alias ("b", "break", class_run
, 1);
10938 add_com_alias ("br", "break", class_run
, 1);
10939 add_com_alias ("bre", "break", class_run
, 1);
10940 add_com_alias ("brea", "break", class_run
, 1);
10943 add_com_alias ("ba", "break", class_breakpoint
, 1);
10947 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10948 Break in function/address or break at a line in the current file."),
10949 &stoplist
, "stop ", 1, &cmdlist
);
10950 add_cmd ("in", class_breakpoint
, stopin_command
,
10951 _("Break in function or address."), &stoplist
);
10952 add_cmd ("at", class_breakpoint
, stopat_command
,
10953 _("Break at a line in the current file."), &stoplist
);
10954 add_com ("status", class_info
, breakpoints_info
, _("\
10955 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10956 The \"Type\" column indicates one of:\n\
10957 \tbreakpoint - normal breakpoint\n\
10958 \twatchpoint - watchpoint\n\
10959 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10960 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10961 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10962 address and file/line number respectively.\n\
10964 Convenience variable \"$_\" and default examine address for \"x\"\n\
10965 are set to the address of the last breakpoint listed unless the command\n\
10966 is prefixed with \"server \".\n\n\
10967 Convenience variable \"$bpnum\" contains the number of the last\n\
10968 breakpoint set."));
10971 add_info ("breakpoints", breakpoints_info
, _("\
10972 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10973 The \"Type\" column indicates one of:\n\
10974 \tbreakpoint - normal breakpoint\n\
10975 \twatchpoint - watchpoint\n\
10976 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10977 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10978 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10979 address and file/line number respectively.\n\
10981 Convenience variable \"$_\" and default examine address for \"x\"\n\
10982 are set to the address of the last breakpoint listed unless the command\n\
10983 is prefixed with \"server \".\n\n\
10984 Convenience variable \"$bpnum\" contains the number of the last\n\
10985 breakpoint set."));
10987 add_info_alias ("b", "breakpoints", 1);
10990 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
10991 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10992 The \"Type\" column indicates one of:\n\
10993 \tbreakpoint - normal breakpoint\n\
10994 \twatchpoint - watchpoint\n\
10995 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10996 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10997 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10998 address and file/line number respectively.\n\
11000 Convenience variable \"$_\" and default examine address for \"x\"\n\
11001 are set to the address of the last breakpoint listed unless the command\n\
11002 is prefixed with \"server \".\n\n\
11003 Convenience variable \"$bpnum\" contains the number of the last\n\
11004 breakpoint set."));
11006 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11007 Status of all breakpoints, or breakpoint number NUMBER.\n\
11008 The \"Type\" column indicates one of:\n\
11009 \tbreakpoint - normal breakpoint\n\
11010 \twatchpoint - watchpoint\n\
11011 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11012 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11013 \tuntil - internal breakpoint used by the \"until\" command\n\
11014 \tfinish - internal breakpoint used by the \"finish\" command\n\
11015 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11016 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11017 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11018 address and file/line number respectively.\n\
11020 Convenience variable \"$_\" and default examine address for \"x\"\n\
11021 are set to the address of the last breakpoint listed unless the command\n\
11022 is prefixed with \"server \".\n\n\
11023 Convenience variable \"$bpnum\" contains the number of the last\n\
11025 &maintenanceinfolist
);
11027 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11028 Set catchpoints to catch events."),
11029 &catch_cmdlist
, "catch ",
11030 0/*allow-unknown*/, &cmdlist
);
11032 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11033 Set temporary catchpoints to catch events."),
11034 &tcatch_cmdlist
, "tcatch ",
11035 0/*allow-unknown*/, &cmdlist
);
11037 /* Add catch and tcatch sub-commands. */
11038 add_catch_command ("catch", _("\
11039 Catch an exception, when caught.\n\
11040 With an argument, catch only exceptions with the given name."),
11041 catch_catch_command
,
11045 add_catch_command ("throw", _("\
11046 Catch an exception, when thrown.\n\
11047 With an argument, catch only exceptions with the given name."),
11048 catch_throw_command
,
11052 add_catch_command ("fork", _("Catch calls to fork."),
11053 catch_fork_command_1
,
11055 (void *) (uintptr_t) catch_fork_permanent
,
11056 (void *) (uintptr_t) catch_fork_temporary
);
11057 add_catch_command ("vfork", _("Catch calls to vfork."),
11058 catch_fork_command_1
,
11060 (void *) (uintptr_t) catch_vfork_permanent
,
11061 (void *) (uintptr_t) catch_vfork_temporary
);
11062 add_catch_command ("exec", _("Catch calls to exec."),
11063 catch_exec_command_1
,
11067 add_catch_command ("syscall", _("\
11068 Catch system calls by their names and/or numbers.\n\
11069 Arguments say which system calls to catch. If no arguments\n\
11070 are given, every system call will be caught.\n\
11071 Arguments, if given, should be one or more system call names\n\
11072 (if your system supports that), or system call numbers."),
11073 catch_syscall_command_1
,
11074 catch_syscall_completer
,
11077 add_catch_command ("exception", _("\
11078 Catch Ada exceptions, when raised.\n\
11079 With an argument, catch only exceptions with the given name."),
11080 catch_ada_exception_command
,
11084 add_catch_command ("assert", _("\
11085 Catch failed Ada assertions, when raised.\n\
11086 With an argument, catch only exceptions with the given name."),
11087 catch_assert_command
,
11092 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11093 Set a watchpoint for an expression.\n\
11094 A watchpoint stops execution of your program whenever the value of\n\
11095 an expression changes."));
11096 set_cmd_completer (c
, expression_completer
);
11098 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11099 Set a read watchpoint for an expression.\n\
11100 A watchpoint stops execution of your program whenever the value of\n\
11101 an expression is read."));
11102 set_cmd_completer (c
, expression_completer
);
11104 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11105 Set a watchpoint for an expression.\n\
11106 A watchpoint stops execution of your program whenever the value of\n\
11107 an expression is either read or written."));
11108 set_cmd_completer (c
, expression_completer
);
11110 add_info ("watchpoints", breakpoints_info
,
11111 _("Synonym for ``info breakpoints''."));
11114 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11115 respond to changes - contrary to the description. */
11116 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11117 &can_use_hw_watchpoints
, _("\
11118 Set debugger's willingness to use watchpoint hardware."), _("\
11119 Show debugger's willingness to use watchpoint hardware."), _("\
11120 If zero, gdb will not use hardware for new watchpoints, even if\n\
11121 such is available. (However, any hardware watchpoints that were\n\
11122 created before setting this to nonzero, will continue to use watchpoint\n\
11125 show_can_use_hw_watchpoints
,
11126 &setlist
, &showlist
);
11128 can_use_hw_watchpoints
= 1;
11130 /* Tracepoint manipulation commands. */
11132 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11133 Set a tracepoint at specified line or function.\n\
11135 BREAK_ARGS_HELP ("trace") "\n\
11136 Do \"help tracepoints\" for info on other tracepoint commands."));
11137 set_cmd_completer (c
, location_completer
);
11139 add_com_alias ("tp", "trace", class_alias
, 0);
11140 add_com_alias ("tr", "trace", class_alias
, 1);
11141 add_com_alias ("tra", "trace", class_alias
, 1);
11142 add_com_alias ("trac", "trace", class_alias
, 1);
11144 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11145 Set a fast tracepoint at specified line or function.\n\
11147 BREAK_ARGS_HELP ("ftrace") "\n\
11148 Do \"help tracepoints\" for info on other tracepoint commands."));
11149 set_cmd_completer (c
, location_completer
);
11151 add_info ("tracepoints", tracepoints_info
, _("\
11152 Status of tracepoints, or tracepoint number NUMBER.\n\
11153 Convenience variable \"$tpnum\" contains the number of the\n\
11154 last tracepoint set."));
11156 add_info_alias ("tp", "tracepoints", 1);
11158 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11159 Delete specified tracepoints.\n\
11160 Arguments are tracepoint numbers, separated by spaces.\n\
11161 No argument means delete all tracepoints."),
11164 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11165 Disable specified tracepoints.\n\
11166 Arguments are tracepoint numbers, separated by spaces.\n\
11167 No argument means disable all tracepoints."),
11169 deprecate_cmd (c
, "disable");
11171 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11172 Enable specified tracepoints.\n\
11173 Arguments are tracepoint numbers, separated by spaces.\n\
11174 No argument means enable all tracepoints."),
11176 deprecate_cmd (c
, "enable");
11178 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11179 Set the passcount for a tracepoint.\n\
11180 The trace will end when the tracepoint has been passed 'count' times.\n\
11181 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11182 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11184 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11185 Save current tracepoint definitions as a script.\n\
11186 Use the 'source' command in another debug session to restore them."));
11187 set_cmd_completer (c
, filename_completer
);
11189 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11190 Breakpoint specific settings\n\
11191 Configure various breakpoint-specific variables such as\n\
11192 pending breakpoint behavior"),
11193 &breakpoint_set_cmdlist
, "set breakpoint ",
11194 0/*allow-unknown*/, &setlist
);
11195 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11196 Breakpoint specific settings\n\
11197 Configure various breakpoint-specific variables such as\n\
11198 pending breakpoint behavior"),
11199 &breakpoint_show_cmdlist
, "show breakpoint ",
11200 0/*allow-unknown*/, &showlist
);
11202 add_setshow_auto_boolean_cmd ("pending", no_class
,
11203 &pending_break_support
, _("\
11204 Set debugger's behavior regarding pending breakpoints."), _("\
11205 Show debugger's behavior regarding pending breakpoints."), _("\
11206 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11207 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11208 an error. If auto, an unrecognized breakpoint location results in a\n\
11209 user-query to see if a pending breakpoint should be created."),
11211 show_pending_break_support
,
11212 &breakpoint_set_cmdlist
,
11213 &breakpoint_show_cmdlist
);
11215 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11217 add_setshow_boolean_cmd ("auto-hw", no_class
,
11218 &automatic_hardware_breakpoints
, _("\
11219 Set automatic usage of hardware breakpoints."), _("\
11220 Show automatic usage of hardware breakpoints."), _("\
11221 If set, the debugger will automatically use hardware breakpoints for\n\
11222 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11223 a warning will be emitted for such breakpoints."),
11225 show_automatic_hardware_breakpoints
,
11226 &breakpoint_set_cmdlist
,
11227 &breakpoint_show_cmdlist
);
11229 add_setshow_enum_cmd ("always-inserted", class_support
,
11230 always_inserted_enums
, &always_inserted_mode
, _("\
11231 Set mode for inserting breakpoints."), _("\
11232 Show mode for inserting breakpoints."), _("\
11233 When this mode is off, breakpoints are inserted in inferior when it is\n\
11234 resumed, and removed when execution stops. When this mode is on,\n\
11235 breakpoints are inserted immediately and removed only when the user\n\
11236 deletes the breakpoint. When this mode is auto (which is the default),\n\
11237 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11238 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11239 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11240 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11242 &show_always_inserted_mode
,
11243 &breakpoint_set_cmdlist
,
11244 &breakpoint_show_cmdlist
);
11246 automatic_hardware_breakpoints
= 1;
11248 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);