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
);
962 make_cleanup (xfree
, arg
);
965 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
967 if (info
.cmd
== NULL
)
968 error (_("No breakpoints specified."));
970 do_cleanups (cleanups
);
974 commands_command (char *arg
, int from_tty
)
976 commands_command_1 (arg
, from_tty
, NULL
);
979 /* Like commands_command, but instead of reading the commands from
980 input stream, takes them from an already parsed command structure.
982 This is used by cli-script.c to DTRT with breakpoint commands
983 that are part of if and while bodies. */
984 enum command_control_type
985 commands_from_control_command (char *arg
, struct command_line
*cmd
)
987 commands_command_1 (arg
, 0, cmd
);
988 return simple_control
;
991 /* Return non-zero if BL->TARGET_INFO contains valid information. */
994 bp_location_has_shadow (struct bp_location
*bl
)
996 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1000 if (bl
->target_info
.shadow_len
== 0)
1001 /* bp isn't valid, or doesn't shadow memory. */
1006 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1007 by replacing any memory breakpoints with their shadowed contents.
1009 The range of shadowed area by each bp_location is:
1010 b->address - bp_location_placed_address_before_address_max
1011 up to b->address + bp_location_shadow_len_after_address_max
1012 The range we were requested to resolve shadows for is:
1013 memaddr ... memaddr + len
1014 Thus the safe cutoff boundaries for performance optimization are
1015 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1017 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1020 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1022 /* Left boundary, right boundary and median element of our binary search. */
1023 unsigned bc_l
, bc_r
, bc
;
1025 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1026 safe to report lower value but a failure to report higher one. */
1029 bc_r
= bp_location_count
;
1030 while (bc_l
+ 1 < bc_r
)
1032 struct bp_location
*b
;
1034 bc
= (bc_l
+ bc_r
) / 2;
1035 b
= bp_location
[bc
];
1037 /* Check first B->ADDRESS will not overflow due to the added constant.
1038 Then advance the left boundary only if we are sure the BC element can
1039 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1041 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1042 we cannot miss a breakpoint with its shadow range tail still reaching
1045 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1046 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1052 /* Now do full processing of the found relevant range of elements. */
1054 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1056 struct bp_location
*b
= bp_location
[bc
];
1057 CORE_ADDR bp_addr
= 0;
1061 if (b
->owner
->type
== bp_none
)
1062 warning (_("reading through apparently deleted breakpoint #%d?"),
1065 /* Performance optimization: any futher element can no longer affect BUF
1068 if (b
->address
>= bp_location_placed_address_before_address_max
1069 && memaddr
+ len
<= b
->address
1070 - bp_location_placed_address_before_address_max
)
1073 if (!bp_location_has_shadow (b
))
1075 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1076 current_program_space
->aspace
, 0))
1079 /* Addresses and length of the part of the breakpoint that
1081 bp_addr
= b
->target_info
.placed_address
;
1082 bp_size
= b
->target_info
.shadow_len
;
1084 if (bp_addr
+ bp_size
<= memaddr
)
1085 /* The breakpoint is entirely before the chunk of memory we
1089 if (bp_addr
>= memaddr
+ len
)
1090 /* The breakpoint is entirely after the chunk of memory we are
1094 /* Offset within shadow_contents. */
1095 if (bp_addr
< memaddr
)
1097 /* Only copy the second part of the breakpoint. */
1098 bp_size
-= memaddr
- bp_addr
;
1099 bptoffset
= memaddr
- bp_addr
;
1103 if (bp_addr
+ bp_size
> memaddr
+ len
)
1105 /* Only copy the first part of the breakpoint. */
1106 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1109 memcpy (buf
+ bp_addr
- memaddr
,
1110 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1115 /* A wrapper function for inserting catchpoints. */
1117 insert_catchpoint (struct ui_out
*uo
, void *args
)
1119 struct breakpoint
*b
= (struct breakpoint
*) args
;
1122 gdb_assert (b
->type
== bp_catchpoint
);
1123 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1128 /* Return true if BPT is of any hardware watchpoint kind. */
1131 is_hardware_watchpoint (struct breakpoint
*bpt
)
1133 return (bpt
->type
== bp_hardware_watchpoint
1134 || bpt
->type
== bp_read_watchpoint
1135 || bpt
->type
== bp_access_watchpoint
);
1138 /* Return true if BPT is of any watchpoint kind, hardware or
1142 is_watchpoint (struct breakpoint
*bpt
)
1144 return (is_hardware_watchpoint (bpt
)
1145 || bpt
->type
== bp_watchpoint
);
1148 /* Find the current value of a watchpoint on EXP. Return the value in
1149 *VALP and *RESULTP and the chain of intermediate and final values
1150 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1153 If a memory error occurs while evaluating the expression, *RESULTP will
1154 be set to NULL. *RESULTP may be a lazy value, if the result could
1155 not be read from memory. It is used to determine whether a value
1156 is user-specified (we should watch the whole value) or intermediate
1157 (we should watch only the bit used to locate the final value).
1159 If the final value, or any intermediate value, could not be read
1160 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1161 set to any referenced values. *VALP will never be a lazy value.
1162 This is the value which we store in struct breakpoint.
1164 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1165 value chain. The caller must free the values individually. If
1166 VAL_CHAIN is NULL, all generated values will be left on the value
1170 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1171 struct value
**resultp
, struct value
**val_chain
)
1173 struct value
*mark
, *new_mark
, *result
;
1174 volatile struct gdb_exception ex
;
1182 /* Evaluate the expression. */
1183 mark
= value_mark ();
1186 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1188 result
= evaluate_expression (exp
);
1192 /* Ignore memory errors, we want watchpoints pointing at
1193 inaccessible memory to still be created; otherwise, throw the
1194 error to some higher catcher. */
1200 throw_exception (ex
);
1205 new_mark
= value_mark ();
1206 if (mark
== new_mark
)
1211 /* Make sure it's not lazy, so that after the target stops again we
1212 have a non-lazy previous value to compare with. */
1214 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1219 /* Return the chain of intermediate values. We use this to
1220 decide which addresses to watch. */
1221 *val_chain
= new_mark
;
1222 value_release_to_mark (mark
);
1226 /* Assuming that B is a watchpoint: returns true if the current thread
1227 and its running state are safe to evaluate or update watchpoint B.
1228 Watchpoints on local expressions need to be evaluated in the
1229 context of the thread that was current when the watchpoint was
1230 created, and, that thread needs to be stopped to be able to select
1231 the correct frame context. Watchpoints on global expressions can
1232 be evaluated on any thread, and in any state. It is presently left
1233 to the target allowing memory accesses when threads are
1237 watchpoint_in_thread_scope (struct breakpoint
*b
)
1239 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1240 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1241 && !is_executing (inferior_ptid
)));
1244 /* Assuming that B is a watchpoint:
1245 - Reparse watchpoint expression, if REPARSE is non-zero
1246 - Evaluate expression and store the result in B->val
1247 - Evaluate the condition if there is one, and store the result
1249 - Update the list of values that must be watched in B->loc.
1251 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1252 If this is local watchpoint that is out of scope, delete it.
1254 Even with `set breakpoint always-inserted on' the watchpoints are removed
1255 + inserted on each stop here. Normal breakpoints must never be removed
1256 because they might be missed by a running thread when debugging in non-stop
1257 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1258 processed here) are specific to each LWP since they are stored in each LWP's
1259 hardware debug registers. Therefore, such LWP must be stopped first in
1260 order to be able to modify its hardware watchpoints.
1262 Hardware watchpoints must be reset exactly once after being presented to the
1263 user. It cannot be done sooner, because it would reset the data used to
1264 present the watchpoint hit to the user. And it must not be done later
1265 because it could display the same single watchpoint hit during multiple GDB
1266 stops. Note that the latter is relevant only to the hardware watchpoint
1267 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1268 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1269 memory content has not changed.
1271 The following constraints influence the location where we can reset hardware
1274 * target_stopped_by_watchpoint and target_stopped_data_address are called
1275 several times when GDB stops.
1278 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1279 stop. GDB only presents one hardware watchpoint hit at a time as the
1280 reason for stopping, and all the other hits are presented later, one after
1281 the other, each time the user requests the execution to be resumed.
1282 Execution is not resumed for the threads still having pending hit event
1283 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1284 the inferior on the first stop the thread hit event is kept being reported
1285 from its cached value by linux_nat_stopped_data_address until the real
1286 thread resume happens after the watchpoint gets presented and thus its
1287 LWP_INFO->STATUS gets reset.
1289 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1290 removal from inferior. */
1293 update_watchpoint (struct breakpoint
*b
, int reparse
)
1295 int within_current_scope
;
1296 struct frame_id saved_frame_id
;
1297 struct bp_location
*loc
;
1301 /* If this is a local watchpoint, we only want to check if the
1302 watchpoint frame is in scope if the current thread is the thread
1303 that was used to create the watchpoint. */
1304 if (!watchpoint_in_thread_scope (b
))
1307 /* We don't free locations. They are stored in bp_location array and
1308 update_global_locations will eventually delete them and remove
1309 breakpoints if needed. */
1312 if (b
->disposition
== disp_del_at_next_stop
)
1317 /* Determine if the watchpoint is within scope. */
1318 if (b
->exp_valid_block
== NULL
)
1319 within_current_scope
= 1;
1322 struct frame_info
*fi
;
1324 /* Save the current frame's ID so we can restore it after
1325 evaluating the watchpoint expression on its own frame. */
1326 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1327 took a frame parameter, so that we didn't have to change the
1330 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1332 fi
= frame_find_by_id (b
->watchpoint_frame
);
1333 within_current_scope
= (fi
!= NULL
);
1334 if (within_current_scope
)
1338 if (within_current_scope
&& reparse
)
1347 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1348 /* If the meaning of expression itself changed, the old value is
1349 no longer relevant. We don't want to report a watchpoint hit
1350 to the user when the old value and the new value may actually
1351 be completely different objects. */
1352 value_free (b
->val
);
1356 /* Note that unlike with breakpoints, the watchpoint's condition
1357 expression is stored in the breakpoint object, not in the
1358 locations (re)created below. */
1359 if (b
->cond_string
!= NULL
)
1361 if (b
->cond_exp
!= NULL
)
1363 xfree (b
->cond_exp
);
1368 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1372 /* If we failed to parse the expression, for example because
1373 it refers to a global variable in a not-yet-loaded shared library,
1374 don't try to insert watchpoint. We don't automatically delete
1375 such watchpoint, though, since failure to parse expression
1376 is different from out-of-scope watchpoint. */
1377 if ( !target_has_execution
)
1379 /* Without execution, memory can't change. No use to try and
1380 set watchpoint locations. The watchpoint will be reset when
1381 the target gains execution, through breakpoint_re_set. */
1383 else if (within_current_scope
&& b
->exp
)
1385 struct value
*val_chain
, *v
, *result
, *next
;
1386 struct program_space
*frame_pspace
;
1388 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1390 /* Avoid setting b->val if it's already set. The meaning of
1391 b->val is 'the last value' user saw, and we should update
1392 it only if we reported that last value to user. As it
1393 happens, the code that reports it updates b->val directly. */
1400 /* Change the type of breakpoint between hardware assisted or an
1401 ordinary watchpoint depending on the hardware support and free
1402 hardware slots. REPARSE is set when the inferior is started. */
1403 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1406 int i
, mem_cnt
, other_type_used
;
1408 /* We need to determine how many resources are already used
1409 for all other hardware watchpoints to see if we still have
1410 enough resources to also fit this watchpoint in as well.
1411 To avoid the hw_watchpoint_used_count call below from counting
1412 this watchpoint, make sure that it is marked as a software
1414 b
->type
= bp_watchpoint
;
1415 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1417 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1420 b
->type
= bp_watchpoint
;
1423 int target_resources_ok
= target_can_use_hardware_watchpoint
1424 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1425 if (target_resources_ok
<= 0)
1426 b
->type
= bp_watchpoint
;
1428 b
->type
= bp_hardware_watchpoint
;
1432 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1434 /* Look at each value on the value chain. */
1435 for (v
= val_chain
; v
; v
= next
)
1437 /* If it's a memory location, and GDB actually needed
1438 its contents to evaluate the expression, then we
1439 must watch it. If the first value returned is
1440 still lazy, that means an error occurred reading it;
1441 watch it anyway in case it becomes readable. */
1442 if (VALUE_LVAL (v
) == lval_memory
1443 && (v
== val_chain
|| ! value_lazy (v
)))
1445 struct type
*vtype
= check_typedef (value_type (v
));
1447 /* We only watch structs and arrays if user asked
1448 for it explicitly, never if they just happen to
1449 appear in the middle of some value chain. */
1451 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1452 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1456 struct bp_location
*loc
, **tmp
;
1458 addr
= value_address (v
);
1459 len
= TYPE_LENGTH (value_type (v
));
1461 if (b
->type
== bp_read_watchpoint
)
1463 else if (b
->type
== bp_access_watchpoint
)
1466 loc
= allocate_bp_location (b
);
1467 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1470 loc
->gdbarch
= get_type_arch (value_type (v
));
1472 loc
->pspace
= frame_pspace
;
1473 loc
->address
= addr
;
1475 loc
->watchpoint_type
= type
;
1479 next
= value_next (v
);
1484 /* If a software watchpoint is not watching any memory, then the
1485 above left it without any location set up. But,
1486 bpstat_stop_status requires a location to be able to report
1487 stops, so make sure there's at least a dummy one. */
1488 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1490 b
->loc
= allocate_bp_location (b
);
1491 b
->loc
->pspace
= frame_pspace
;
1492 b
->loc
->address
= -1;
1493 b
->loc
->length
= -1;
1494 b
->loc
->watchpoint_type
= -1;
1497 else if (!within_current_scope
)
1499 printf_filtered (_("\
1500 Watchpoint %d deleted because the program has left the block \n\
1501 in which its expression is valid.\n"),
1503 if (b
->related_breakpoint
)
1505 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1506 b
->related_breakpoint
->related_breakpoint
= NULL
;
1507 b
->related_breakpoint
= NULL
;
1509 b
->disposition
= disp_del_at_next_stop
;
1512 /* Restore the selected frame. */
1514 select_frame (frame_find_by_id (saved_frame_id
));
1518 /* Returns 1 iff breakpoint location should be
1519 inserted in the inferior. */
1521 should_be_inserted (struct bp_location
*bpt
)
1523 if (!breakpoint_enabled (bpt
->owner
))
1526 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1529 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1532 /* This is set for example, when we're attached to the parent of a
1533 vfork, and have detached from the child. The child is running
1534 free, and we expect it to do an exec or exit, at which point the
1535 OS makes the parent schedulable again (and the target reports
1536 that the vfork is done). Until the child is done with the shared
1537 memory region, do not insert breakpoints in the parent, otherwise
1538 the child could still trip on the parent's breakpoints. Since
1539 the parent is blocked anyway, it won't miss any breakpoint. */
1540 if (bpt
->pspace
->breakpoints_not_allowed
)
1543 /* Tracepoints are inserted by the target at a time of its choosing,
1545 if (tracepoint_type (bpt
->owner
))
1551 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1552 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1553 and HW_BREAKPOINT_ERROR are used to report problems.
1555 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1556 method for each breakpoint or catchpoint type. */
1558 insert_bp_location (struct bp_location
*bpt
,
1559 struct ui_file
*tmp_error_stream
,
1560 int *disabled_breaks
,
1561 int *hw_breakpoint_error
)
1565 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1568 /* Initialize the target-specific information. */
1569 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1570 bpt
->target_info
.placed_address
= bpt
->address
;
1571 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1573 if (bpt
->loc_type
== bp_loc_software_breakpoint
1574 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1576 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1578 /* If the explicitly specified breakpoint type
1579 is not hardware breakpoint, check the memory map to see
1580 if the breakpoint address is in read only memory or not.
1581 Two important cases are:
1582 - location type is not hardware breakpoint, memory
1583 is readonly. We change the type of the location to
1584 hardware breakpoint.
1585 - location type is hardware breakpoint, memory is read-write.
1586 This means we've previously made the location hardware one, but
1587 then the memory map changed, so we undo.
1589 When breakpoints are removed, remove_breakpoints will
1590 use location types we've just set here, the only possible
1591 problem is that memory map has changed during running program,
1592 but it's not going to work anyway with current gdb. */
1593 struct mem_region
*mr
1594 = lookup_mem_region (bpt
->target_info
.placed_address
);
1598 if (automatic_hardware_breakpoints
)
1601 enum bp_loc_type new_type
;
1603 if (mr
->attrib
.mode
!= MEM_RW
)
1604 new_type
= bp_loc_hardware_breakpoint
;
1606 new_type
= bp_loc_software_breakpoint
;
1608 if (new_type
!= bpt
->loc_type
)
1610 static int said
= 0;
1611 bpt
->loc_type
= new_type
;
1614 fprintf_filtered (gdb_stdout
, _("\
1615 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1620 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1621 && mr
->attrib
.mode
!= MEM_RW
)
1622 warning (_("cannot set software breakpoint at readonly address %s"),
1623 paddress (bpt
->gdbarch
, bpt
->address
));
1627 /* First check to see if we have to handle an overlay. */
1628 if (overlay_debugging
== ovly_off
1629 || bpt
->section
== NULL
1630 || !(section_is_overlay (bpt
->section
)))
1632 /* No overlay handling: just set the breakpoint. */
1634 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1635 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1638 val
= target_insert_breakpoint (bpt
->gdbarch
,
1643 /* This breakpoint is in an overlay section.
1644 Shall we set a breakpoint at the LMA? */
1645 if (!overlay_events_enabled
)
1647 /* Yes -- overlay event support is not active,
1648 so we must try to set a breakpoint at the LMA.
1649 This will not work for a hardware breakpoint. */
1650 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1651 warning (_("hardware breakpoint %d not supported in overlay!"),
1652 bpt
->owner
->number
);
1655 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1657 /* Set a software (trap) breakpoint at the LMA. */
1658 bpt
->overlay_target_info
= bpt
->target_info
;
1659 bpt
->overlay_target_info
.placed_address
= addr
;
1660 val
= target_insert_breakpoint (bpt
->gdbarch
,
1661 &bpt
->overlay_target_info
);
1663 fprintf_unfiltered (tmp_error_stream
,
1664 "Overlay breakpoint %d failed: in ROM?\n",
1665 bpt
->owner
->number
);
1668 /* Shall we set a breakpoint at the VMA? */
1669 if (section_is_mapped (bpt
->section
))
1671 /* Yes. This overlay section is mapped into memory. */
1672 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1673 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1676 val
= target_insert_breakpoint (bpt
->gdbarch
,
1681 /* No. This breakpoint will not be inserted.
1682 No error, but do not mark the bp as 'inserted'. */
1689 /* Can't set the breakpoint. */
1690 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1692 /* See also: disable_breakpoints_in_shlibs. */
1694 bpt
->shlib_disabled
= 1;
1695 if (!*disabled_breaks
)
1697 fprintf_unfiltered (tmp_error_stream
,
1698 "Cannot insert breakpoint %d.\n",
1699 bpt
->owner
->number
);
1700 fprintf_unfiltered (tmp_error_stream
,
1701 "Temporarily disabling shared library breakpoints:\n");
1703 *disabled_breaks
= 1;
1704 fprintf_unfiltered (tmp_error_stream
,
1705 "breakpoint #%d\n", bpt
->owner
->number
);
1709 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1711 *hw_breakpoint_error
= 1;
1712 fprintf_unfiltered (tmp_error_stream
,
1713 "Cannot insert hardware breakpoint %d.\n",
1714 bpt
->owner
->number
);
1718 fprintf_unfiltered (tmp_error_stream
,
1719 "Cannot insert breakpoint %d.\n",
1720 bpt
->owner
->number
);
1721 fprintf_filtered (tmp_error_stream
,
1722 "Error accessing memory address ");
1723 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1725 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1726 safe_strerror (val
));
1737 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1738 /* NOTE drow/2003-09-08: This state only exists for removing
1739 watchpoints. It's not clear that it's necessary... */
1740 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1742 val
= target_insert_watchpoint (bpt
->address
,
1744 bpt
->watchpoint_type
);
1746 /* If trying to set a read-watchpoint, and it turns out it's not
1747 supported, try emulating one with an access watchpoint. */
1748 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1750 struct bp_location
*loc
, **loc_temp
;
1752 /* But don't try to insert it, if there's already another
1753 hw_access location that would be considered a duplicate
1755 ALL_BP_LOCATIONS (loc
, loc_temp
)
1757 && loc
->watchpoint_type
== hw_access
1758 && watchpoint_locations_match (bpt
, loc
))
1762 bpt
->target_info
= loc
->target_info
;
1763 bpt
->watchpoint_type
= hw_access
;
1770 val
= target_insert_watchpoint (bpt
->address
,
1774 bpt
->watchpoint_type
= hw_access
;
1778 bpt
->inserted
= (val
== 0);
1781 else if (bpt
->owner
->type
== bp_catchpoint
)
1783 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1784 bpt
->owner
, RETURN_MASK_ERROR
);
1785 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1786 bpt
->owner
->number
);
1788 bpt
->owner
->enable_state
= bp_disabled
;
1792 /* We've already printed an error message if there was a problem
1793 inserting this catchpoint, and we've disabled the catchpoint,
1794 so just return success. */
1801 /* This function is called when program space PSPACE is about to be
1802 deleted. It takes care of updating breakpoints to not reference
1806 breakpoint_program_space_exit (struct program_space
*pspace
)
1808 struct breakpoint
*b
, *b_temp
;
1809 struct bp_location
*loc
, **loc_temp
;
1811 /* Remove any breakpoint that was set through this program space. */
1812 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1814 if (b
->pspace
== pspace
)
1815 delete_breakpoint (b
);
1818 /* Breakpoints set through other program spaces could have locations
1819 bound to PSPACE as well. Remove those. */
1820 ALL_BP_LOCATIONS (loc
, loc_temp
)
1822 struct bp_location
*tmp
;
1824 if (loc
->pspace
== pspace
)
1826 if (loc
->owner
->loc
== loc
)
1827 loc
->owner
->loc
= loc
->next
;
1829 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1830 if (tmp
->next
== loc
)
1832 tmp
->next
= loc
->next
;
1838 /* Now update the global location list to permanently delete the
1839 removed locations above. */
1840 update_global_location_list (0);
1843 /* Make sure all breakpoints are inserted in inferior.
1844 Throws exception on any error.
1845 A breakpoint that is already inserted won't be inserted
1846 again, so calling this function twice is safe. */
1848 insert_breakpoints (void)
1850 struct breakpoint
*bpt
;
1852 ALL_BREAKPOINTS (bpt
)
1853 if (is_hardware_watchpoint (bpt
))
1854 update_watchpoint (bpt
, 0 /* don't reparse. */);
1856 update_global_location_list (1);
1858 /* update_global_location_list does not insert breakpoints when
1859 always_inserted_mode is not enabled. Explicitly insert them
1861 if (!breakpoints_always_inserted_mode ())
1862 insert_breakpoint_locations ();
1865 /* insert_breakpoints is used when starting or continuing the program.
1866 remove_breakpoints is used when the program stops.
1867 Both return zero if successful,
1868 or an `errno' value if could not write the inferior. */
1871 insert_breakpoint_locations (void)
1873 struct breakpoint
*bpt
;
1874 struct bp_location
*b
, **bp_tmp
;
1877 int disabled_breaks
= 0;
1878 int hw_breakpoint_error
= 0;
1880 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1881 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1883 /* Explicitly mark the warning -- this will only be printed if
1884 there was an error. */
1885 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1887 save_current_space_and_thread ();
1889 ALL_BP_LOCATIONS (b
, bp_tmp
)
1891 struct thread_info
*tp
;
1892 CORE_ADDR last_addr
;
1894 if (!should_be_inserted (b
) || b
->inserted
)
1897 /* There is no point inserting thread-specific breakpoints if the
1898 thread no longer exists. */
1899 if (b
->owner
->thread
!= -1
1900 && !valid_thread_id (b
->owner
->thread
))
1903 switch_to_program_space_and_thread (b
->pspace
);
1905 /* For targets that support global breakpoints, there's no need
1906 to select an inferior to insert breakpoint to. In fact, even
1907 if we aren't attached to any process yet, we should still
1908 insert breakpoints. */
1909 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1910 && ptid_equal (inferior_ptid
, null_ptid
))
1913 val
= insert_bp_location (b
, tmp_error_stream
,
1915 &hw_breakpoint_error
);
1920 /* If we failed to insert all locations of a watchpoint,
1921 remove them, as half-inserted watchpoint is of limited use. */
1922 ALL_BREAKPOINTS (bpt
)
1924 int some_failed
= 0;
1925 struct bp_location
*loc
;
1927 if (!is_hardware_watchpoint (bpt
))
1930 if (!breakpoint_enabled (bpt
))
1933 if (bpt
->disposition
== disp_del_at_next_stop
)
1936 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1937 if (!loc
->inserted
&& should_be_inserted (loc
))
1944 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1946 remove_breakpoint (loc
, mark_uninserted
);
1948 hw_breakpoint_error
= 1;
1949 fprintf_unfiltered (tmp_error_stream
,
1950 "Could not insert hardware watchpoint %d.\n",
1958 /* If a hardware breakpoint or watchpoint was inserted, add a
1959 message about possibly exhausted resources. */
1960 if (hw_breakpoint_error
)
1962 fprintf_unfiltered (tmp_error_stream
,
1963 "Could not insert hardware breakpoints:\n\
1964 You may have requested too many hardware breakpoints/watchpoints.\n");
1966 target_terminal_ours_for_output ();
1967 error_stream (tmp_error_stream
);
1970 do_cleanups (cleanups
);
1974 remove_breakpoints (void)
1976 struct bp_location
*b
, **bp_tmp
;
1979 ALL_BP_LOCATIONS (b
, bp_tmp
)
1982 val
|= remove_breakpoint (b
, mark_uninserted
);
1987 /* Remove breakpoints of process PID. */
1990 remove_breakpoints_pid (int pid
)
1992 struct bp_location
*b
, **b_tmp
;
1994 struct inferior
*inf
= find_inferior_pid (pid
);
1996 ALL_BP_LOCATIONS (b
, b_tmp
)
1998 if (b
->pspace
!= inf
->pspace
)
2003 val
= remove_breakpoint (b
, mark_uninserted
);
2012 remove_hw_watchpoints (void)
2014 struct bp_location
*b
, **bp_tmp
;
2017 ALL_BP_LOCATIONS (b
, bp_tmp
)
2019 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2020 val
|= remove_breakpoint (b
, mark_uninserted
);
2026 reattach_breakpoints (int pid
)
2028 struct cleanup
*old_chain
;
2029 struct bp_location
*b
, **bp_tmp
;
2031 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2032 int dummy1
= 0, dummy2
= 0;
2033 struct inferior
*inf
;
2034 struct thread_info
*tp
;
2036 tp
= any_live_thread_of_process (pid
);
2040 inf
= find_inferior_pid (pid
);
2041 old_chain
= save_inferior_ptid ();
2043 inferior_ptid
= tp
->ptid
;
2045 make_cleanup_ui_file_delete (tmp_error_stream
);
2047 ALL_BP_LOCATIONS (b
, bp_tmp
)
2049 if (b
->pspace
!= inf
->pspace
)
2055 val
= insert_bp_location (b
, tmp_error_stream
,
2059 do_cleanups (old_chain
);
2064 do_cleanups (old_chain
);
2068 static int internal_breakpoint_number
= -1;
2070 static struct breakpoint
*
2071 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2072 CORE_ADDR address
, enum bptype type
)
2074 struct symtab_and_line sal
;
2075 struct breakpoint
*b
;
2077 init_sal (&sal
); /* initialize to zeroes */
2080 sal
.section
= find_pc_overlay (sal
.pc
);
2081 sal
.pspace
= current_program_space
;
2083 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2084 b
->number
= internal_breakpoint_number
--;
2085 b
->disposition
= disp_donttouch
;
2091 create_overlay_event_breakpoint (char *func_name
)
2093 struct objfile
*objfile
;
2095 ALL_OBJFILES (objfile
)
2097 struct breakpoint
*b
;
2098 struct minimal_symbol
*m
;
2100 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2104 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2105 SYMBOL_VALUE_ADDRESS (m
),
2107 b
->addr_string
= xstrdup (func_name
);
2109 if (overlay_debugging
== ovly_auto
)
2111 b
->enable_state
= bp_enabled
;
2112 overlay_events_enabled
= 1;
2116 b
->enable_state
= bp_disabled
;
2117 overlay_events_enabled
= 0;
2120 update_global_location_list (1);
2124 create_longjmp_master_breakpoint (char *func_name
)
2126 struct program_space
*pspace
;
2127 struct objfile
*objfile
;
2128 struct cleanup
*old_chain
;
2130 old_chain
= save_current_program_space ();
2132 ALL_PSPACES (pspace
)
2133 ALL_OBJFILES (objfile
)
2135 struct breakpoint
*b
;
2136 struct minimal_symbol
*m
;
2138 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2141 set_current_program_space (pspace
);
2143 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2147 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2148 SYMBOL_VALUE_ADDRESS (m
),
2150 b
->addr_string
= xstrdup (func_name
);
2151 b
->enable_state
= bp_disabled
;
2153 update_global_location_list (1);
2155 do_cleanups (old_chain
);
2158 /* Create a master std::terminate breakpoint. The actual function
2159 looked for is named FUNC_NAME. */
2161 create_std_terminate_master_breakpoint (const char *func_name
)
2163 struct program_space
*pspace
;
2164 struct objfile
*objfile
;
2165 struct cleanup
*old_chain
;
2167 old_chain
= save_current_program_space ();
2169 ALL_PSPACES (pspace
)
2170 ALL_OBJFILES (objfile
)
2172 struct breakpoint
*b
;
2173 struct minimal_symbol
*m
;
2175 set_current_program_space (pspace
);
2177 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2178 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2179 && MSYMBOL_TYPE (m
) != mst_file_text
))
2182 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2183 SYMBOL_VALUE_ADDRESS (m
),
2184 bp_std_terminate_master
);
2185 b
->addr_string
= xstrdup (func_name
);
2186 b
->enable_state
= bp_disabled
;
2188 update_global_location_list (1);
2190 do_cleanups (old_chain
);
2194 update_breakpoints_after_exec (void)
2196 struct breakpoint
*b
;
2197 struct breakpoint
*temp
;
2198 struct bp_location
*bploc
, **bplocp_tmp
;
2200 /* We're about to delete breakpoints from GDB's lists. If the
2201 INSERTED flag is true, GDB will try to lift the breakpoints by
2202 writing the breakpoints' "shadow contents" back into memory. The
2203 "shadow contents" are NOT valid after an exec, so GDB should not
2204 do that. Instead, the target is responsible from marking
2205 breakpoints out as soon as it detects an exec. We don't do that
2206 here instead, because there may be other attempts to delete
2207 breakpoints after detecting an exec and before reaching here. */
2208 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2209 if (bploc
->pspace
== current_program_space
)
2210 gdb_assert (!bploc
->inserted
);
2212 ALL_BREAKPOINTS_SAFE (b
, temp
)
2214 if (b
->pspace
!= current_program_space
)
2217 /* Solib breakpoints must be explicitly reset after an exec(). */
2218 if (b
->type
== bp_shlib_event
)
2220 delete_breakpoint (b
);
2224 /* JIT breakpoints must be explicitly reset after an exec(). */
2225 if (b
->type
== bp_jit_event
)
2227 delete_breakpoint (b
);
2231 /* Thread event breakpoints must be set anew after an exec(),
2232 as must overlay event and longjmp master breakpoints. */
2233 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2234 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2236 delete_breakpoint (b
);
2240 /* Step-resume breakpoints are meaningless after an exec(). */
2241 if (b
->type
== bp_step_resume
)
2243 delete_breakpoint (b
);
2247 /* Longjmp and longjmp-resume breakpoints are also meaningless
2249 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2251 delete_breakpoint (b
);
2255 if (b
->type
== bp_catchpoint
)
2257 /* For now, none of the bp_catchpoint breakpoints need to
2258 do anything at this point. In the future, if some of
2259 the catchpoints need to something, we will need to add
2260 a new method, and call this method from here. */
2264 /* bp_finish is a special case. The only way we ought to be able
2265 to see one of these when an exec() has happened, is if the user
2266 caught a vfork, and then said "finish". Ordinarily a finish just
2267 carries them to the call-site of the current callee, by setting
2268 a temporary bp there and resuming. But in this case, the finish
2269 will carry them entirely through the vfork & exec.
2271 We don't want to allow a bp_finish to remain inserted now. But
2272 we can't safely delete it, 'cause finish_command has a handle to
2273 the bp on a bpstat, and will later want to delete it. There's a
2274 chance (and I've seen it happen) that if we delete the bp_finish
2275 here, that its storage will get reused by the time finish_command
2276 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2277 We really must allow finish_command to delete a bp_finish.
2279 In the absense of a general solution for the "how do we know
2280 it's safe to delete something others may have handles to?"
2281 problem, what we'll do here is just uninsert the bp_finish, and
2282 let finish_command delete it.
2284 (We know the bp_finish is "doomed" in the sense that it's
2285 momentary, and will be deleted as soon as finish_command sees
2286 the inferior stopped. So it doesn't matter that the bp's
2287 address is probably bogus in the new a.out, unlike e.g., the
2288 solib breakpoints.) */
2290 if (b
->type
== bp_finish
)
2295 /* Without a symbolic address, we have little hope of the
2296 pre-exec() address meaning the same thing in the post-exec()
2298 if (b
->addr_string
== NULL
)
2300 delete_breakpoint (b
);
2304 /* FIXME what about longjmp breakpoints? Re-create them here? */
2305 create_overlay_event_breakpoint ("_ovly_debug_event");
2306 create_longjmp_master_breakpoint ("longjmp");
2307 create_longjmp_master_breakpoint ("_longjmp");
2308 create_longjmp_master_breakpoint ("siglongjmp");
2309 create_longjmp_master_breakpoint ("_siglongjmp");
2310 create_std_terminate_master_breakpoint ("std::terminate()");
2314 detach_breakpoints (int pid
)
2316 struct bp_location
*b
, **bp_tmp
;
2318 struct cleanup
*old_chain
= save_inferior_ptid ();
2319 struct inferior
*inf
= current_inferior ();
2321 if (pid
== PIDGET (inferior_ptid
))
2322 error (_("Cannot detach breakpoints of inferior_ptid"));
2324 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2325 inferior_ptid
= pid_to_ptid (pid
);
2326 ALL_BP_LOCATIONS (b
, bp_tmp
)
2328 if (b
->pspace
!= inf
->pspace
)
2332 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2334 do_cleanups (old_chain
);
2338 /* Remove the breakpoint location B from the current address space.
2339 Note that this is used to detach breakpoints from a child fork.
2340 When we get here, the child isn't in the inferior list, and neither
2341 do we have objects to represent its address space --- we should
2342 *not* look at b->pspace->aspace here. */
2345 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2348 struct cleanup
*old_chain
;
2350 if (b
->owner
->enable_state
== bp_permanent
)
2351 /* Permanent breakpoints cannot be inserted or removed. */
2354 /* The type of none suggests that owner is actually deleted.
2355 This should not ever happen. */
2356 gdb_assert (b
->owner
->type
!= bp_none
);
2358 if (b
->loc_type
== bp_loc_software_breakpoint
2359 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2361 /* "Normal" instruction breakpoint: either the standard
2362 trap-instruction bp (bp_breakpoint), or a
2363 bp_hardware_breakpoint. */
2365 /* First check to see if we have to handle an overlay. */
2366 if (overlay_debugging
== ovly_off
2367 || b
->section
== NULL
2368 || !(section_is_overlay (b
->section
)))
2370 /* No overlay handling: just remove the breakpoint. */
2372 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2373 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2375 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2379 /* This breakpoint is in an overlay section.
2380 Did we set a breakpoint at the LMA? */
2381 if (!overlay_events_enabled
)
2383 /* Yes -- overlay event support is not active, so we
2384 should have set a breakpoint at the LMA. Remove it.
2386 /* Ignore any failures: if the LMA is in ROM, we will
2387 have already warned when we failed to insert it. */
2388 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2389 target_remove_hw_breakpoint (b
->gdbarch
,
2390 &b
->overlay_target_info
);
2392 target_remove_breakpoint (b
->gdbarch
,
2393 &b
->overlay_target_info
);
2395 /* Did we set a breakpoint at the VMA?
2396 If so, we will have marked the breakpoint 'inserted'. */
2399 /* Yes -- remove it. Previously we did not bother to
2400 remove the breakpoint if the section had been
2401 unmapped, but let's not rely on that being safe. We
2402 don't know what the overlay manager might do. */
2403 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2404 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2407 /* However, we should remove *software* breakpoints only
2408 if the section is still mapped, or else we overwrite
2409 wrong code with the saved shadow contents. */
2410 else if (section_is_mapped (b
->section
))
2411 val
= target_remove_breakpoint (b
->gdbarch
,
2418 /* No -- not inserted, so no need to remove. No error. */
2423 /* In some cases, we might not be able to remove a breakpoint
2424 in a shared library that has already been removed, but we
2425 have not yet processed the shlib unload event. */
2426 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2431 b
->inserted
= (is
== mark_inserted
);
2433 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2438 b
->inserted
= (is
== mark_inserted
);
2439 val
= target_remove_watchpoint (b
->address
, b
->length
,
2440 b
->watchpoint_type
);
2442 /* Failure to remove any of the hardware watchpoints comes here. */
2443 if ((is
== mark_uninserted
) && (b
->inserted
))
2444 warning (_("Could not remove hardware watchpoint %d."),
2447 else if (b
->owner
->type
== bp_catchpoint
2448 && breakpoint_enabled (b
->owner
)
2451 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2453 val
= b
->owner
->ops
->remove (b
->owner
);
2456 b
->inserted
= (is
== mark_inserted
);
2463 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2466 struct cleanup
*old_chain
;
2468 if (b
->owner
->enable_state
== bp_permanent
)
2469 /* Permanent breakpoints cannot be inserted or removed. */
2472 /* The type of none suggests that owner is actually deleted.
2473 This should not ever happen. */
2474 gdb_assert (b
->owner
->type
!= bp_none
);
2476 old_chain
= save_current_space_and_thread ();
2478 switch_to_program_space_and_thread (b
->pspace
);
2480 ret
= remove_breakpoint_1 (b
, is
);
2482 do_cleanups (old_chain
);
2486 /* Clear the "inserted" flag in all breakpoints. */
2489 mark_breakpoints_out (void)
2491 struct bp_location
*bpt
, **bptp_tmp
;
2493 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2494 if (bpt
->pspace
== current_program_space
)
2498 /* Clear the "inserted" flag in all breakpoints and delete any
2499 breakpoints which should go away between runs of the program.
2501 Plus other such housekeeping that has to be done for breakpoints
2504 Note: this function gets called at the end of a run (by
2505 generic_mourn_inferior) and when a run begins (by
2506 init_wait_for_inferior). */
2511 breakpoint_init_inferior (enum inf_context context
)
2513 struct breakpoint
*b
, *temp
;
2514 struct bp_location
*bpt
, **bptp_tmp
;
2516 struct program_space
*pspace
= current_program_space
;
2518 /* If breakpoint locations are shared across processes, then there's
2520 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2523 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2525 if (bpt
->pspace
== pspace
2526 && bpt
->owner
->enable_state
!= bp_permanent
)
2530 ALL_BREAKPOINTS_SAFE (b
, temp
)
2532 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2539 /* If the call dummy breakpoint is at the entry point it will
2540 cause problems when the inferior is rerun, so we better get
2543 case bp_watchpoint_scope
:
2545 /* Also get rid of scope breakpoints. */
2547 case bp_shlib_event
:
2549 /* Also remove solib event breakpoints. Their addresses may
2550 have changed since the last time we ran the program.
2551 Actually we may now be debugging against different target;
2552 and so the solib backend that installed this breakpoint may
2553 not be used in by the target. E.g.,
2555 (gdb) file prog-linux
2556 (gdb) run # native linux target
2559 (gdb) file prog-win.exe
2560 (gdb) tar rem :9999 # remote Windows gdbserver.
2563 delete_breakpoint (b
);
2567 case bp_hardware_watchpoint
:
2568 case bp_read_watchpoint
:
2569 case bp_access_watchpoint
:
2571 /* Likewise for watchpoints on local expressions. */
2572 if (b
->exp_valid_block
!= NULL
)
2573 delete_breakpoint (b
);
2574 else if (context
== inf_starting
)
2576 /* Reset val field to force reread of starting value
2577 in insert_breakpoints. */
2579 value_free (b
->val
);
2589 /* Get rid of the moribund locations. */
2590 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2591 free_bp_location (bpt
);
2592 VEC_free (bp_location_p
, moribund_locations
);
2595 /* These functions concern about actual breakpoints inserted in the
2596 target --- to e.g. check if we need to do decr_pc adjustment or if
2597 we need to hop over the bkpt --- so we check for address space
2598 match, not program space. */
2600 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2601 exists at PC. It returns ordinary_breakpoint_here if it's an
2602 ordinary breakpoint, or permanent_breakpoint_here if it's a
2603 permanent breakpoint.
2604 - When continuing from a location with an ordinary breakpoint, we
2605 actually single step once before calling insert_breakpoints.
2606 - When continuing from a localion with a permanent breakpoint, we
2607 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2608 the target, to advance the PC past the breakpoint. */
2610 enum breakpoint_here
2611 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2613 struct bp_location
*bpt
, **bptp_tmp
;
2614 int any_breakpoint_here
= 0;
2616 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2618 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2619 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2622 if ((breakpoint_enabled (bpt
->owner
)
2623 || bpt
->owner
->enable_state
== bp_permanent
)
2624 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2627 if (overlay_debugging
2628 && section_is_overlay (bpt
->section
)
2629 && !section_is_mapped (bpt
->section
))
2630 continue; /* unmapped overlay -- can't be a match */
2631 else if (bpt
->owner
->enable_state
== bp_permanent
)
2632 return permanent_breakpoint_here
;
2634 any_breakpoint_here
= 1;
2638 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2641 /* Return true if there's a moribund breakpoint at PC. */
2644 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2646 struct bp_location
*loc
;
2649 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2650 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2657 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2658 inserted using regular breakpoint_chain / bp_location array mechanism.
2659 This does not check for single-step breakpoints, which are
2660 inserted and removed using direct target manipulation. */
2663 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2665 struct bp_location
*bpt
, **bptp_tmp
;
2667 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2669 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2670 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2674 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2677 if (overlay_debugging
2678 && section_is_overlay (bpt
->section
)
2679 && !section_is_mapped (bpt
->section
))
2680 continue; /* unmapped overlay -- can't be a match */
2688 /* Returns non-zero iff there's either regular breakpoint
2689 or a single step breakpoint inserted at PC. */
2692 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2694 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2697 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2703 /* This function returns non-zero iff there is a software breakpoint
2707 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2709 struct bp_location
*bpt
, **bptp_tmp
;
2710 int any_breakpoint_here
= 0;
2712 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2714 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2718 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2721 if (overlay_debugging
2722 && section_is_overlay (bpt
->section
)
2723 && !section_is_mapped (bpt
->section
))
2724 continue; /* unmapped overlay -- can't be a match */
2730 /* Also check for software single-step breakpoints. */
2731 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2738 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2739 CORE_ADDR addr
, ULONGEST len
)
2741 struct breakpoint
*bpt
;
2743 ALL_BREAKPOINTS (bpt
)
2745 struct bp_location
*loc
;
2747 if (bpt
->type
!= bp_hardware_watchpoint
2748 && bpt
->type
!= bp_access_watchpoint
)
2751 if (!breakpoint_enabled (bpt
))
2754 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2755 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2759 /* Check for intersection. */
2760 l
= max (loc
->address
, addr
);
2761 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2769 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2770 PC is valid for process/thread PTID. */
2773 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2776 struct bp_location
*bpt
, **bptp_tmp
;
2777 /* The thread and task IDs associated to PTID, computed lazily. */
2781 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2783 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2784 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2787 if (!breakpoint_enabled (bpt
->owner
)
2788 && bpt
->owner
->enable_state
!= bp_permanent
)
2791 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2795 if (bpt
->owner
->thread
!= -1)
2797 /* This is a thread-specific breakpoint. Check that ptid
2798 matches that thread. If thread hasn't been computed yet,
2799 it is now time to do so. */
2801 thread
= pid_to_thread_id (ptid
);
2802 if (bpt
->owner
->thread
!= thread
)
2806 if (bpt
->owner
->task
!= 0)
2808 /* This is a task-specific breakpoint. Check that ptid
2809 matches that task. If task hasn't been computed yet,
2810 it is now time to do so. */
2812 task
= ada_get_task_number (ptid
);
2813 if (bpt
->owner
->task
!= task
)
2817 if (overlay_debugging
2818 && section_is_overlay (bpt
->section
)
2819 && !section_is_mapped (bpt
->section
))
2820 continue; /* unmapped overlay -- can't be a match */
2829 /* bpstat stuff. External routines' interfaces are documented
2833 ep_is_catchpoint (struct breakpoint
*ep
)
2835 return (ep
->type
== bp_catchpoint
);
2839 bpstat_free (bpstat bs
)
2841 if (bs
->old_val
!= NULL
)
2842 value_free (bs
->old_val
);
2843 decref_counted_command_line (&bs
->commands
);
2847 /* Clear a bpstat so that it says we are not at any breakpoint.
2848 Also free any storage that is part of a bpstat. */
2851 bpstat_clear (bpstat
*bsp
)
2868 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2869 is part of the bpstat is copied as well. */
2872 bpstat_copy (bpstat bs
)
2876 bpstat retval
= NULL
;
2881 for (; bs
!= NULL
; bs
= bs
->next
)
2883 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2884 memcpy (tmp
, bs
, sizeof (*tmp
));
2885 incref_counted_command_line (tmp
->commands
);
2886 if (bs
->old_val
!= NULL
)
2888 tmp
->old_val
= value_copy (bs
->old_val
);
2889 release_value (tmp
->old_val
);
2893 /* This is the first thing in the chain. */
2903 /* Find the bpstat associated with this breakpoint */
2906 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2911 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2913 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2919 /* Find a step_resume breakpoint associated with this bpstat.
2920 (If there are multiple step_resume bp's on the list, this function
2921 will arbitrarily pick one.)
2923 It is an error to use this function if BPSTAT doesn't contain a
2924 step_resume breakpoint.
2926 See wait_for_inferior's use of this function. */
2928 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2932 gdb_assert (bsp
!= NULL
);
2934 current_thread
= pid_to_thread_id (inferior_ptid
);
2936 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2938 if ((bsp
->breakpoint_at
!= NULL
)
2939 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2940 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2941 || bsp
->breakpoint_at
->owner
->thread
== -1))
2942 return bsp
->breakpoint_at
->owner
;
2945 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2949 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2950 at. *BSP upon return is a bpstat which points to the remaining
2951 breakpoints stopped at (but which is not guaranteed to be good for
2952 anything but further calls to bpstat_num).
2953 Return 0 if passed a bpstat which does not indicate any breakpoints.
2954 Return -1 if stopped at a breakpoint that has been deleted since
2956 Return 1 otherwise. */
2959 bpstat_num (bpstat
*bsp
, int *num
)
2961 struct breakpoint
*b
;
2964 return 0; /* No more breakpoint values */
2966 /* We assume we'll never have several bpstats that
2967 correspond to a single breakpoint -- otherwise,
2968 this function might return the same number more
2969 than once and this will look ugly. */
2970 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2971 *bsp
= (*bsp
)->next
;
2973 return -1; /* breakpoint that's been deleted since */
2975 *num
= b
->number
; /* We have its number */
2979 /* Modify BS so that the actions will not be performed. */
2982 bpstat_clear_actions (bpstat bs
)
2984 for (; bs
!= NULL
; bs
= bs
->next
)
2986 decref_counted_command_line (&bs
->commands
);
2987 bs
->commands_left
= NULL
;
2988 if (bs
->old_val
!= NULL
)
2990 value_free (bs
->old_val
);
2996 /* Called when a command is about to proceed the inferior. */
2999 breakpoint_about_to_proceed (void)
3001 if (!ptid_equal (inferior_ptid
, null_ptid
))
3003 struct thread_info
*tp
= inferior_thread ();
3005 /* Allow inferior function calls in breakpoint commands to not
3006 interrupt the command list. When the call finishes
3007 successfully, the inferior will be standing at the same
3008 breakpoint as if nothing happened. */
3013 breakpoint_proceeded
= 1;
3016 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3018 cleanup_executing_breakpoints (void *ignore
)
3020 executing_breakpoint_commands
= 0;
3023 /* Execute all the commands associated with all the breakpoints at this
3024 location. Any of these commands could cause the process to proceed
3025 beyond this point, etc. We look out for such changes by checking
3026 the global "breakpoint_proceeded" after each command.
3028 Returns true if a breakpoint command resumed the inferior. In that
3029 case, it is the caller's responsibility to recall it again with the
3030 bpstat of the current thread. */
3033 bpstat_do_actions_1 (bpstat
*bsp
)
3036 struct cleanup
*old_chain
;
3039 /* Avoid endless recursion if a `source' command is contained
3041 if (executing_breakpoint_commands
)
3044 executing_breakpoint_commands
= 1;
3045 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3047 /* This pointer will iterate over the list of bpstat's. */
3050 breakpoint_proceeded
= 0;
3051 for (; bs
!= NULL
; bs
= bs
->next
)
3053 struct counted_command_line
*ccmd
;
3054 struct command_line
*cmd
;
3055 struct cleanup
*this_cmd_tree_chain
;
3057 /* Take ownership of the BSP's command tree, if it has one.
3059 The command tree could legitimately contain commands like
3060 'step' and 'next', which call clear_proceed_status, which
3061 frees stop_bpstat's command tree. To make sure this doesn't
3062 free the tree we're executing out from under us, we need to
3063 take ownership of the tree ourselves. Since a given bpstat's
3064 commands are only executed once, we don't need to copy it; we
3065 can clear the pointer in the bpstat, and make sure we free
3066 the tree when we're done. */
3067 ccmd
= bs
->commands
;
3068 bs
->commands
= NULL
;
3070 = make_cleanup_decref_counted_command_line (&ccmd
);
3071 cmd
= bs
->commands_left
;
3072 bs
->commands_left
= NULL
;
3076 execute_control_command (cmd
);
3078 if (breakpoint_proceeded
)
3084 /* We can free this command tree now. */
3085 do_cleanups (this_cmd_tree_chain
);
3087 if (breakpoint_proceeded
)
3089 if (target_can_async_p ())
3090 /* If we are in async mode, then the target might be still
3091 running, not stopped at any breakpoint, so nothing for
3092 us to do here -- just return to the event loop. */
3095 /* In sync mode, when execute_control_command returns
3096 we're already standing on the next breakpoint.
3097 Breakpoint commands for that stop were not run, since
3098 execute_command does not run breakpoint commands --
3099 only command_line_handler does, but that one is not
3100 involved in execution of breakpoint commands. So, we
3101 can now execute breakpoint commands. It should be
3102 noted that making execute_command do bpstat actions is
3103 not an option -- in this case we'll have recursive
3104 invocation of bpstat for each breakpoint with a
3105 command, and can easily blow up GDB stack. Instead, we
3106 return true, which will trigger the caller to recall us
3107 with the new stop_bpstat. */
3112 do_cleanups (old_chain
);
3117 bpstat_do_actions (void)
3119 /* Do any commands attached to breakpoint we are stopped at. */
3120 while (!ptid_equal (inferior_ptid
, null_ptid
)
3121 && target_has_execution
3122 && !is_exited (inferior_ptid
)
3123 && !is_executing (inferior_ptid
))
3124 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3125 and only return when it is stopped at the next breakpoint, we
3126 keep doing breakpoint actions until it returns false to
3127 indicate the inferior was not resumed. */
3128 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3132 /* Print out the (old or new) value associated with a watchpoint. */
3135 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3138 fprintf_unfiltered (stream
, _("<unreadable>"));
3141 struct value_print_options opts
;
3142 get_user_print_options (&opts
);
3143 value_print (val
, stream
, &opts
);
3147 /* This is the normal print function for a bpstat. In the future,
3148 much of this logic could (should?) be moved to bpstat_stop_status,
3149 by having it set different print_it values.
3151 Current scheme: When we stop, bpstat_print() is called. It loops
3152 through the bpstat list of things causing this stop, calling the
3153 print_bp_stop_message function on each one. The behavior of the
3154 print_bp_stop_message function depends on the print_it field of
3155 bpstat. If such field so indicates, call this function here.
3157 Return values from this routine (ultimately used by bpstat_print()
3158 and normal_stop() to decide what to do):
3159 PRINT_NOTHING: Means we already printed all we needed to print,
3160 don't print anything else.
3161 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3162 that something to be followed by a location.
3163 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3164 that something to be followed by a location.
3165 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3168 static enum print_stop_action
3169 print_it_typical (bpstat bs
)
3171 struct cleanup
*old_chain
;
3172 struct breakpoint
*b
;
3173 const struct bp_location
*bl
;
3174 struct ui_stream
*stb
;
3176 enum print_stop_action result
;
3178 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3179 which has since been deleted. */
3180 if (bs
->breakpoint_at
== NULL
)
3181 return PRINT_UNKNOWN
;
3182 bl
= bs
->breakpoint_at
;
3185 stb
= ui_out_stream_new (uiout
);
3186 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3191 case bp_hardware_breakpoint
:
3192 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3193 if (bl
->address
!= bl
->requested_address
)
3194 breakpoint_adjustment_warning (bl
->requested_address
,
3197 annotate_breakpoint (b
->number
);
3199 ui_out_text (uiout
, "\nTemporary breakpoint ");
3201 ui_out_text (uiout
, "\nBreakpoint ");
3202 if (ui_out_is_mi_like_p (uiout
))
3204 ui_out_field_string (uiout
, "reason",
3205 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3206 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3208 ui_out_field_int (uiout
, "bkptno", b
->number
);
3209 ui_out_text (uiout
, ", ");
3210 result
= PRINT_SRC_AND_LOC
;
3213 case bp_shlib_event
:
3214 /* Did we stop because the user set the stop_on_solib_events
3215 variable? (If so, we report this as a generic, "Stopped due
3216 to shlib event" message.) */
3217 printf_filtered (_("Stopped due to shared library event\n"));
3218 result
= PRINT_NOTHING
;
3221 case bp_thread_event
:
3222 /* Not sure how we will get here.
3223 GDB should not stop for these breakpoints. */
3224 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3225 result
= PRINT_NOTHING
;
3228 case bp_overlay_event
:
3229 /* By analogy with the thread event, GDB should not stop for these. */
3230 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3231 result
= PRINT_NOTHING
;
3234 case bp_longjmp_master
:
3235 /* These should never be enabled. */
3236 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3237 result
= PRINT_NOTHING
;
3240 case bp_std_terminate_master
:
3241 /* These should never be enabled. */
3242 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3243 result
= PRINT_NOTHING
;
3247 case bp_hardware_watchpoint
:
3248 annotate_watchpoint (b
->number
);
3249 if (ui_out_is_mi_like_p (uiout
))
3252 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3254 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3255 ui_out_text (uiout
, "\nOld value = ");
3256 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3257 ui_out_field_stream (uiout
, "old", stb
);
3258 ui_out_text (uiout
, "\nNew value = ");
3259 watchpoint_value_print (b
->val
, stb
->stream
);
3260 ui_out_field_stream (uiout
, "new", stb
);
3261 ui_out_text (uiout
, "\n");
3262 /* More than one watchpoint may have been triggered. */
3263 result
= PRINT_UNKNOWN
;
3266 case bp_read_watchpoint
:
3267 if (ui_out_is_mi_like_p (uiout
))
3270 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3272 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3273 ui_out_text (uiout
, "\nValue = ");
3274 watchpoint_value_print (b
->val
, stb
->stream
);
3275 ui_out_field_stream (uiout
, "value", stb
);
3276 ui_out_text (uiout
, "\n");
3277 result
= PRINT_UNKNOWN
;
3280 case bp_access_watchpoint
:
3281 if (bs
->old_val
!= NULL
)
3283 annotate_watchpoint (b
->number
);
3284 if (ui_out_is_mi_like_p (uiout
))
3287 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3289 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3290 ui_out_text (uiout
, "\nOld value = ");
3291 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3292 ui_out_field_stream (uiout
, "old", stb
);
3293 ui_out_text (uiout
, "\nNew value = ");
3298 if (ui_out_is_mi_like_p (uiout
))
3301 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3302 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3303 ui_out_text (uiout
, "\nValue = ");
3305 watchpoint_value_print (b
->val
, stb
->stream
);
3306 ui_out_field_stream (uiout
, "new", stb
);
3307 ui_out_text (uiout
, "\n");
3308 result
= PRINT_UNKNOWN
;
3311 /* Fall through, we don't deal with these types of breakpoints
3315 if (ui_out_is_mi_like_p (uiout
))
3318 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3319 result
= PRINT_UNKNOWN
;
3323 if (ui_out_is_mi_like_p (uiout
))
3326 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3327 result
= PRINT_UNKNOWN
;
3332 case bp_longjmp_resume
:
3333 case bp_step_resume
:
3334 case bp_watchpoint_scope
:
3336 case bp_std_terminate
:
3338 case bp_fast_tracepoint
:
3341 result
= PRINT_UNKNOWN
;
3345 do_cleanups (old_chain
);
3349 /* Generic routine for printing messages indicating why we
3350 stopped. The behavior of this function depends on the value
3351 'print_it' in the bpstat structure. Under some circumstances we
3352 may decide not to print anything here and delegate the task to
3355 static enum print_stop_action
3356 print_bp_stop_message (bpstat bs
)
3358 switch (bs
->print_it
)
3361 /* Nothing should be printed for this bpstat entry. */
3362 return PRINT_UNKNOWN
;
3366 /* We still want to print the frame, but we already printed the
3367 relevant messages. */
3368 return PRINT_SRC_AND_LOC
;
3371 case print_it_normal
:
3373 const struct bp_location
*bl
= bs
->breakpoint_at
;
3374 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3376 /* Normal case. Call the breakpoint's print_it method, or
3377 print_it_typical. */
3378 /* FIXME: how breakpoint can ever be NULL here? */
3379 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3380 return b
->ops
->print_it (b
);
3382 return print_it_typical (bs
);
3387 internal_error (__FILE__
, __LINE__
,
3388 _("print_bp_stop_message: unrecognized enum value"));
3393 /* Print a message indicating what happened. This is called from
3394 normal_stop(). The input to this routine is the head of the bpstat
3395 list - a list of the eventpoints that caused this stop. This
3396 routine calls the generic print routine for printing a message
3397 about reasons for stopping. This will print (for example) the
3398 "Breakpoint n," part of the output. The return value of this
3401 PRINT_UNKNOWN: Means we printed nothing
3402 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3403 code to print the location. An example is
3404 "Breakpoint 1, " which should be followed by
3406 PRINT_SRC_ONLY: Means we printed something, but there is no need
3407 to also print the location part of the message.
3408 An example is the catch/throw messages, which
3409 don't require a location appended to the end.
3410 PRINT_NOTHING: We have done some printing and we don't need any
3411 further info to be printed.*/
3413 enum print_stop_action
3414 bpstat_print (bpstat bs
)
3418 /* Maybe another breakpoint in the chain caused us to stop.
3419 (Currently all watchpoints go on the bpstat whether hit or not.
3420 That probably could (should) be changed, provided care is taken
3421 with respect to bpstat_explains_signal). */
3422 for (; bs
; bs
= bs
->next
)
3424 val
= print_bp_stop_message (bs
);
3425 if (val
== PRINT_SRC_ONLY
3426 || val
== PRINT_SRC_AND_LOC
3427 || val
== PRINT_NOTHING
)
3431 /* We reached the end of the chain, or we got a null BS to start
3432 with and nothing was printed. */
3433 return PRINT_UNKNOWN
;
3436 /* Evaluate the expression EXP and return 1 if value is zero.
3437 This is used inside a catch_errors to evaluate the breakpoint condition.
3438 The argument is a "struct expression *" that has been cast to char * to
3439 make it pass through catch_errors. */
3442 breakpoint_cond_eval (void *exp
)
3444 struct value
*mark
= value_mark ();
3445 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3446 value_free_to_mark (mark
);
3450 /* Allocate a new bpstat and chain it to the current one. */
3453 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3457 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3459 bs
->breakpoint_at
= bl
;
3460 /* If the condition is false, etc., don't do the commands. */
3461 bs
->commands
= NULL
;
3462 bs
->commands_left
= NULL
;
3464 bs
->print_it
= print_it_normal
;
3468 /* The target has stopped with waitstatus WS. Check if any hardware
3469 watchpoints have triggered, according to the target. */
3472 watchpoints_triggered (struct target_waitstatus
*ws
)
3474 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3476 struct breakpoint
*b
;
3478 if (!stopped_by_watchpoint
)
3480 /* We were not stopped by a watchpoint. Mark all watchpoints
3481 as not triggered. */
3483 if (b
->type
== bp_hardware_watchpoint
3484 || b
->type
== bp_read_watchpoint
3485 || b
->type
== bp_access_watchpoint
)
3486 b
->watchpoint_triggered
= watch_triggered_no
;
3491 if (!target_stopped_data_address (¤t_target
, &addr
))
3493 /* We were stopped by a watchpoint, but we don't know where.
3494 Mark all watchpoints as unknown. */
3496 if (b
->type
== bp_hardware_watchpoint
3497 || b
->type
== bp_read_watchpoint
3498 || b
->type
== bp_access_watchpoint
)
3499 b
->watchpoint_triggered
= watch_triggered_unknown
;
3501 return stopped_by_watchpoint
;
3504 /* The target could report the data address. Mark watchpoints
3505 affected by this data address as triggered, and all others as not
3509 if (b
->type
== bp_hardware_watchpoint
3510 || b
->type
== bp_read_watchpoint
3511 || b
->type
== bp_access_watchpoint
)
3513 struct bp_location
*loc
;
3516 b
->watchpoint_triggered
= watch_triggered_no
;
3517 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3518 /* Exact match not required. Within range is
3520 if (target_watchpoint_addr_within_range (¤t_target
,
3524 b
->watchpoint_triggered
= watch_triggered_yes
;
3532 /* Possible return values for watchpoint_check (this can't be an enum
3533 because of check_errors). */
3534 /* The watchpoint has been deleted. */
3535 #define WP_DELETED 1
3536 /* The value has changed. */
3537 #define WP_VALUE_CHANGED 2
3538 /* The value has not changed. */
3539 #define WP_VALUE_NOT_CHANGED 3
3540 /* Ignore this watchpoint, no matter if the value changed or not. */
3543 #define BP_TEMPFLAG 1
3544 #define BP_HARDWAREFLAG 2
3546 /* Evaluate watchpoint condition expression and check if its value changed.
3548 P should be a pointer to struct bpstat, but is defined as a void *
3549 in order for this function to be usable with catch_errors. */
3552 watchpoint_check (void *p
)
3554 bpstat bs
= (bpstat
) p
;
3555 struct breakpoint
*b
;
3556 struct frame_info
*fr
;
3557 int within_current_scope
;
3559 b
= bs
->breakpoint_at
->owner
;
3561 /* If this is a local watchpoint, we only want to check if the
3562 watchpoint frame is in scope if the current thread is the thread
3563 that was used to create the watchpoint. */
3564 if (!watchpoint_in_thread_scope (b
))
3567 if (b
->exp_valid_block
== NULL
)
3568 within_current_scope
= 1;
3571 struct frame_info
*frame
= get_current_frame ();
3572 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3573 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3575 /* in_function_epilogue_p() returns a non-zero value if we're still
3576 in the function but the stack frame has already been invalidated.
3577 Since we can't rely on the values of local variables after the
3578 stack has been destroyed, we are treating the watchpoint in that
3579 state as `not changed' without further checking. Don't mark
3580 watchpoints as changed if the current frame is in an epilogue -
3581 even if they are in some other frame, our view of the stack
3582 is likely to be wrong and frame_find_by_id could error out. */
3583 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3586 fr
= frame_find_by_id (b
->watchpoint_frame
);
3587 within_current_scope
= (fr
!= NULL
);
3589 /* If we've gotten confused in the unwinder, we might have
3590 returned a frame that can't describe this variable. */
3591 if (within_current_scope
)
3593 struct symbol
*function
;
3595 function
= get_frame_function (fr
);
3596 if (function
== NULL
3597 || !contained_in (b
->exp_valid_block
,
3598 SYMBOL_BLOCK_VALUE (function
)))
3599 within_current_scope
= 0;
3602 if (within_current_scope
)
3603 /* If we end up stopping, the current frame will get selected
3604 in normal_stop. So this call to select_frame won't affect
3609 if (within_current_scope
)
3611 /* We use value_{,free_to_}mark because it could be a
3612 *long* time before we return to the command level and
3613 call free_all_values. We can't call free_all_values because
3614 we might be in the middle of evaluating a function call. */
3616 struct value
*mark
= value_mark ();
3617 struct value
*new_val
;
3619 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3621 /* We use value_equal_contents instead of value_equal because the latter
3622 coerces an array to a pointer, thus comparing just the address of the
3623 array instead of its contents. This is not what we want. */
3624 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3625 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3627 if (new_val
!= NULL
)
3629 release_value (new_val
);
3630 value_free_to_mark (mark
);
3632 bs
->old_val
= b
->val
;
3635 return WP_VALUE_CHANGED
;
3639 /* Nothing changed. */
3640 value_free_to_mark (mark
);
3641 return WP_VALUE_NOT_CHANGED
;
3646 /* This seems like the only logical thing to do because
3647 if we temporarily ignored the watchpoint, then when
3648 we reenter the block in which it is valid it contains
3649 garbage (in the case of a function, it may have two
3650 garbage values, one before and one after the prologue).
3651 So we can't even detect the first assignment to it and
3652 watch after that (since the garbage may or may not equal
3653 the first value assigned). */
3654 /* We print all the stop information in print_it_typical(), but
3655 in this case, by the time we call print_it_typical() this bp
3656 will be deleted already. So we have no choice but print the
3657 information here. */
3658 if (ui_out_is_mi_like_p (uiout
))
3660 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3661 ui_out_text (uiout
, "\nWatchpoint ");
3662 ui_out_field_int (uiout
, "wpnum", b
->number
);
3663 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3664 which its expression is valid.\n");
3666 if (b
->related_breakpoint
)
3668 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3669 b
->related_breakpoint
->related_breakpoint
= NULL
;
3670 b
->related_breakpoint
= NULL
;
3672 b
->disposition
= disp_del_at_next_stop
;
3678 /* Return true if it looks like target has stopped due to hitting
3679 breakpoint location BL. This function does not check if we
3680 should stop, only if BL explains the stop. */
3682 bpstat_check_location (const struct bp_location
*bl
,
3683 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3685 struct breakpoint
*b
= bl
->owner
;
3687 /* By definition, the inferior does not report stops at
3689 if (tracepoint_type (b
))
3692 if (b
->type
!= bp_watchpoint
3693 && b
->type
!= bp_hardware_watchpoint
3694 && b
->type
!= bp_read_watchpoint
3695 && b
->type
!= bp_access_watchpoint
3696 && b
->type
!= bp_hardware_breakpoint
3697 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3699 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3702 if (overlay_debugging
/* unmapped overlay section */
3703 && section_is_overlay (bl
->section
)
3704 && !section_is_mapped (bl
->section
))
3708 /* Continuable hardware watchpoints are treated as non-existent if the
3709 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3710 some data address). Otherwise gdb won't stop on a break instruction
3711 in the code (not from a breakpoint) when a hardware watchpoint has
3712 been defined. Also skip watchpoints which we know did not trigger
3713 (did not match the data address). */
3715 if ((b
->type
== bp_hardware_watchpoint
3716 || b
->type
== bp_read_watchpoint
3717 || b
->type
== bp_access_watchpoint
)
3718 && b
->watchpoint_triggered
== watch_triggered_no
)
3721 if (b
->type
== bp_hardware_breakpoint
)
3723 if (bl
->address
!= bp_addr
)
3725 if (overlay_debugging
/* unmapped overlay section */
3726 && section_is_overlay (bl
->section
)
3727 && !section_is_mapped (bl
->section
))
3731 if (b
->type
== bp_catchpoint
)
3733 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3734 if (!b
->ops
->breakpoint_hit (b
))
3741 /* If BS refers to a watchpoint, determine if the watched values
3742 has actually changed, and we should stop. If not, set BS->stop
3745 bpstat_check_watchpoint (bpstat bs
)
3747 const struct bp_location
*bl
= bs
->breakpoint_at
;
3748 struct breakpoint
*b
= bl
->owner
;
3750 if (b
->type
== bp_watchpoint
3751 || b
->type
== bp_read_watchpoint
3752 || b
->type
== bp_access_watchpoint
3753 || b
->type
== bp_hardware_watchpoint
)
3757 int must_check_value
= 0;
3759 if (b
->type
== bp_watchpoint
)
3760 /* For a software watchpoint, we must always check the
3762 must_check_value
= 1;
3763 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3764 /* We have a hardware watchpoint (read, write, or access)
3765 and the target earlier reported an address watched by
3767 must_check_value
= 1;
3768 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3769 && b
->type
== bp_hardware_watchpoint
)
3770 /* We were stopped by a hardware watchpoint, but the target could
3771 not report the data address. We must check the watchpoint's
3772 value. Access and read watchpoints are out of luck; without
3773 a data address, we can't figure it out. */
3774 must_check_value
= 1;
3776 if (must_check_value
)
3778 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3780 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3781 int e
= catch_errors (watchpoint_check
, bs
, message
,
3783 do_cleanups (cleanups
);
3787 /* We've already printed what needs to be printed. */
3788 bs
->print_it
= print_it_done
;
3792 bs
->print_it
= print_it_noop
;
3795 case WP_VALUE_CHANGED
:
3796 if (b
->type
== bp_read_watchpoint
)
3798 /* There are two cases to consider here:
3800 1. we're watching the triggered memory for reads.
3801 In that case, trust the target, and always report
3802 the watchpoint hit to the user. Even though
3803 reads don't cause value changes, the value may
3804 have changed since the last time it was read, and
3805 since we're not trapping writes, we will not see
3806 those, and as such we should ignore our notion of
3809 2. we're watching the triggered memory for both
3810 reads and writes. There are two ways this may
3813 2.1. this is a target that can't break on data
3814 reads only, but can break on accesses (reads or
3815 writes), such as e.g., x86. We detect this case
3816 at the time we try to insert read watchpoints.
3818 2.2. otherwise, the target supports read
3819 watchpoints, but, the user set an access or write
3820 watchpoint watching the same memory as this read
3823 If we're watching memory writes as well as reads,
3824 ignore watchpoint hits when we find that the
3825 value hasn't changed, as reads don't cause
3826 changes. This still gives false positives when
3827 the program writes the same value to memory as
3828 what there was already in memory (we will confuse
3829 it for a read), but it's much better than
3832 int other_write_watchpoint
= 0;
3834 if (bl
->watchpoint_type
== hw_read
)
3836 struct breakpoint
*other_b
;
3838 ALL_BREAKPOINTS (other_b
)
3839 if ((other_b
->type
== bp_hardware_watchpoint
3840 || other_b
->type
== bp_access_watchpoint
)
3841 && (other_b
->watchpoint_triggered
3842 == watch_triggered_yes
))
3844 other_write_watchpoint
= 1;
3849 if (other_write_watchpoint
3850 || bl
->watchpoint_type
== hw_access
)
3852 /* We're watching the same memory for writes,
3853 and the value changed since the last time we
3854 updated it, so this trap must be for a write.
3856 bs
->print_it
= print_it_noop
;
3861 case WP_VALUE_NOT_CHANGED
:
3862 if (b
->type
== bp_hardware_watchpoint
3863 || b
->type
== bp_watchpoint
)
3865 /* Don't stop: write watchpoints shouldn't fire if
3866 the value hasn't changed. */
3867 bs
->print_it
= print_it_noop
;
3875 /* Error from catch_errors. */
3876 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3877 if (b
->related_breakpoint
)
3878 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3879 b
->disposition
= disp_del_at_next_stop
;
3880 /* We've already printed what needs to be printed. */
3881 bs
->print_it
= print_it_done
;
3885 else /* must_check_value == 0 */
3887 /* This is a case where some watchpoint(s) triggered, but
3888 not at the address of this watchpoint, or else no
3889 watchpoint triggered after all. So don't print
3890 anything for this watchpoint. */
3891 bs
->print_it
= print_it_noop
;
3898 /* Check conditions (condition proper, frame, thread and ignore count)
3899 of breakpoint referred to by BS. If we should not stop for this
3900 breakpoint, set BS->stop to 0. */
3902 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3904 int thread_id
= pid_to_thread_id (ptid
);
3905 const struct bp_location
*bl
= bs
->breakpoint_at
;
3906 struct breakpoint
*b
= bl
->owner
;
3908 if (frame_id_p (b
->frame_id
)
3909 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3913 int value_is_zero
= 0;
3914 struct expression
*cond
;
3916 /* If this is a scope breakpoint, mark the associated
3917 watchpoint as triggered so that we will handle the
3918 out-of-scope event. We'll get to the watchpoint next
3920 if (b
->type
== bp_watchpoint_scope
)
3921 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3923 if (is_watchpoint (b
))
3928 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3930 int within_current_scope
= 1;
3932 /* We use value_mark and value_free_to_mark because it could
3933 be a long time before we return to the command level and
3934 call free_all_values. We can't call free_all_values
3935 because we might be in the middle of evaluating a
3937 struct value
*mark
= value_mark ();
3939 /* Need to select the frame, with all that implies so that
3940 the conditions will have the right context. Because we
3941 use the frame, we will not see an inlined function's
3942 variables when we arrive at a breakpoint at the start
3943 of the inlined function; the current frame will be the
3945 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3946 select_frame (get_current_frame ());
3949 struct frame_info
*frame
;
3951 /* For local watchpoint expressions, which particular
3952 instance of a local is being watched matters, so we
3953 keep track of the frame to evaluate the expression
3954 in. To evaluate the condition however, it doesn't
3955 really matter which instantiation of the function
3956 where the condition makes sense triggers the
3957 watchpoint. This allows an expression like "watch
3958 global if q > 10" set in `func', catch writes to
3959 global on all threads that call `func', or catch
3960 writes on all recursive calls of `func' by a single
3961 thread. We simply always evaluate the condition in
3962 the innermost frame that's executing where it makes
3963 sense to evaluate the condition. It seems
3965 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3967 select_frame (frame
);
3969 within_current_scope
= 0;
3971 if (within_current_scope
)
3973 = catch_errors (breakpoint_cond_eval
, cond
,
3974 "Error in testing breakpoint condition:\n",
3978 warning (_("Watchpoint condition cannot be tested "
3979 "in the current scope"));
3980 /* If we failed to set the right context for this
3981 watchpoint, unconditionally report it. */
3984 /* FIXME-someday, should give breakpoint # */
3985 value_free_to_mark (mark
);
3988 if (cond
&& value_is_zero
)
3992 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3996 else if (b
->ignore_count
> 0)
3999 annotate_ignore_count_change ();
4001 /* Increase the hit count even though we don't
4009 /* Get a bpstat associated with having just stopped at address
4010 BP_ADDR in thread PTID.
4012 Determine whether we stopped at a breakpoint, etc, or whether we
4013 don't understand this stop. Result is a chain of bpstat's such that:
4015 if we don't understand the stop, the result is a null pointer.
4017 if we understand why we stopped, the result is not null.
4019 Each element of the chain refers to a particular breakpoint or
4020 watchpoint at which we have stopped. (We may have stopped for
4021 several reasons concurrently.)
4023 Each element of the chain has valid next, breakpoint_at,
4024 commands, FIXME??? fields. */
4027 bpstat_stop_status (struct address_space
*aspace
,
4028 CORE_ADDR bp_addr
, ptid_t ptid
)
4030 struct breakpoint
*b
= NULL
;
4031 struct bp_location
*bl
, **blp_tmp
;
4032 struct bp_location
*loc
;
4033 /* Root of the chain of bpstat's */
4034 struct bpstats root_bs
[1];
4035 /* Pointer to the last thing in the chain currently. */
4036 bpstat bs
= root_bs
;
4038 int need_remove_insert
;
4040 /* ALL_BP_LOCATIONS iteration would break across
4041 update_global_location_list possibly executed by
4042 bpstat_check_breakpoint_conditions's inferior call. */
4046 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4049 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4051 /* For hardware watchpoints, we look only at the first location.
4052 The watchpoint_check function will work on entire expression,
4053 not the individual locations. For read watchopints, the
4054 watchpoints_triggered function have checked all locations
4056 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4059 if (bl
->shlib_disabled
)
4062 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4065 /* Come here if it's a watchpoint, or if the break address matches */
4067 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4069 /* Assume we stop. Should we find watchpoint that is not actually
4070 triggered, or if condition of breakpoint is false, we'll reset
4075 bpstat_check_watchpoint (bs
);
4079 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4080 || b
->type
== bp_longjmp_master
4081 || b
->type
== bp_std_terminate_master
)
4082 /* We do not stop for these. */
4085 bpstat_check_breakpoint_conditions (bs
, ptid
);
4091 /* We will stop here */
4092 if (b
->disposition
== disp_disable
)
4094 if (b
->enable_state
!= bp_permanent
)
4095 b
->enable_state
= bp_disabled
;
4096 update_global_location_list (0);
4100 bs
->commands
= b
->commands
;
4101 incref_counted_command_line (bs
->commands
);
4102 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4103 if (bs
->commands_left
4104 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4107 bs
->commands_left
->line
) == 0)))
4109 bs
->commands_left
= bs
->commands_left
->next
;
4114 /* Print nothing for this entry if we dont stop or dont print. */
4115 if (bs
->stop
== 0 || bs
->print
== 0)
4116 bs
->print_it
= print_it_noop
;
4120 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4122 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4125 bs
= bpstat_alloc (loc
, bs
);
4126 /* For hits of moribund locations, we should just proceed. */
4129 bs
->print_it
= print_it_noop
;
4133 bs
->next
= NULL
; /* Terminate the chain */
4135 /* If we aren't stopping, the value of some hardware watchpoint may
4136 not have changed, but the intermediate memory locations we are
4137 watching may have. Don't bother if we're stopping; this will get
4139 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4143 need_remove_insert
= 0;
4145 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4147 && bs
->breakpoint_at
->owner
4148 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4150 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4151 /* Updating watchpoints invalidates bs->breakpoint_at.
4152 Prevent further code from trying to use it. */
4153 bs
->breakpoint_at
= NULL
;
4154 need_remove_insert
= 1;
4157 if (need_remove_insert
)
4158 update_global_location_list (1);
4160 return root_bs
->next
;
4163 /* Tell what to do about this bpstat. */
4165 bpstat_what (bpstat bs
)
4167 /* Classify each bpstat as one of the following. */
4170 /* This bpstat element has no effect on the main_action. */
4173 /* There was a watchpoint, stop but don't print. */
4176 /* There was a watchpoint, stop and print. */
4179 /* There was a breakpoint but we're not stopping. */
4182 /* There was a breakpoint, stop but don't print. */
4185 /* There was a breakpoint, stop and print. */
4188 /* We hit the longjmp breakpoint. */
4191 /* We hit the longjmp_resume breakpoint. */
4194 /* We hit the step_resume breakpoint. */
4197 /* We hit the shared library event breakpoint. */
4200 /* We hit the jit event breakpoint. */
4203 /* This is just used to count how many enums there are. */
4207 /* Here is the table which drives this routine. So that we can
4208 format it pretty, we define some abbreviations for the
4209 enum bpstat_what codes. */
4210 #define kc BPSTAT_WHAT_KEEP_CHECKING
4211 #define ss BPSTAT_WHAT_STOP_SILENT
4212 #define sn BPSTAT_WHAT_STOP_NOISY
4213 #define sgl BPSTAT_WHAT_SINGLE
4214 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4215 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4216 #define sr BPSTAT_WHAT_STEP_RESUME
4217 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4218 #define jit BPSTAT_WHAT_CHECK_JIT
4220 /* "Can't happen." Might want to print an error message.
4221 abort() is not out of the question, but chances are GDB is just
4222 a bit confused, not unusable. */
4223 #define err BPSTAT_WHAT_STOP_NOISY
4225 /* Given an old action and a class, come up with a new action. */
4226 /* One interesting property of this table is that wp_silent is the same
4227 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4228 after stopping, the check for whether to step over a breakpoint
4229 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4230 reference to how we stopped. We retain separate wp_silent and
4231 bp_silent codes in case we want to change that someday.
4233 Another possibly interesting property of this table is that
4234 there's a partial ordering, priority-like, of the actions. Once
4235 you've decided that some action is appropriate, you'll never go
4236 back and decide something of a lower priority is better. The
4239 kc < jit clr sgl shl slr sn sr ss
4240 sgl < jit shl slr sn sr ss
4241 slr < jit err shl sn sr ss
4242 clr < jit err shl sn sr ss
4249 What I think this means is that we don't need a damned table
4250 here. If you just put the rows and columns in the right order,
4251 it'd look awfully regular. We could simply walk the bpstat list
4252 and choose the highest priority action we find, with a little
4253 logic to handle the 'err' cases. */
4255 /* step_resume entries: a step resume breakpoint overrides another
4256 breakpoint of signal handling (see comment in wait_for_inferior
4257 at where we set the step_resume breakpoint). */
4259 static const enum bpstat_what_main_action
4260 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4263 /* kc ss sn sgl slr clr sr shl jit */
4264 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4265 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4266 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4267 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4268 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4269 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4270 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4271 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4272 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4273 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4274 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4288 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4289 struct bpstat_what retval
;
4291 retval
.call_dummy
= STOP_NONE
;
4292 for (; bs
!= NULL
; bs
= bs
->next
)
4294 enum class bs_class
= no_effect
;
4295 if (bs
->breakpoint_at
== NULL
)
4296 /* I suspect this can happen if it was a momentary breakpoint
4297 which has since been deleted. */
4299 if (bs
->breakpoint_at
->owner
== NULL
)
4300 bs_class
= bp_nostop
;
4302 switch (bs
->breakpoint_at
->owner
->type
)
4308 case bp_hardware_breakpoint
:
4314 bs_class
= bp_noisy
;
4316 bs_class
= bp_silent
;
4319 bs_class
= bp_nostop
;
4322 case bp_hardware_watchpoint
:
4323 case bp_read_watchpoint
:
4324 case bp_access_watchpoint
:
4328 bs_class
= wp_noisy
;
4330 bs_class
= wp_silent
;
4333 /* There was a watchpoint, but we're not stopping.
4334 This requires no further action. */
4335 bs_class
= no_effect
;
4338 bs_class
= long_jump
;
4340 case bp_longjmp_resume
:
4341 bs_class
= long_resume
;
4343 case bp_step_resume
:
4346 bs_class
= step_resume
;
4349 /* It is for the wrong frame. */
4350 bs_class
= bp_nostop
;
4352 case bp_watchpoint_scope
:
4353 bs_class
= bp_nostop
;
4355 case bp_shlib_event
:
4356 bs_class
= shlib_event
;
4359 bs_class
= jit_event
;
4361 case bp_thread_event
:
4362 case bp_overlay_event
:
4363 case bp_longjmp_master
:
4364 case bp_std_terminate_master
:
4365 bs_class
= bp_nostop
;
4371 bs_class
= bp_noisy
;
4373 bs_class
= bp_silent
;
4376 /* There was a catchpoint, but we're not stopping.
4377 This requires no further action. */
4378 bs_class
= no_effect
;
4381 /* Make sure the action is stop (silent or noisy),
4382 so infrun.c pops the dummy frame. */
4383 bs_class
= bp_silent
;
4384 retval
.call_dummy
= STOP_STACK_DUMMY
;
4386 case bp_std_terminate
:
4387 /* Make sure the action is stop (silent or noisy),
4388 so infrun.c pops the dummy frame. */
4389 bs_class
= bp_silent
;
4390 retval
.call_dummy
= STOP_STD_TERMINATE
;
4393 case bp_fast_tracepoint
:
4394 /* Tracepoint hits should not be reported back to GDB, and
4395 if one got through somehow, it should have been filtered
4397 internal_error (__FILE__
, __LINE__
,
4398 _("bpstat_what: tracepoint encountered"));
4401 current_action
= table
[(int) bs_class
][(int) current_action
];
4403 retval
.main_action
= current_action
;
4407 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4408 without hardware support). This isn't related to a specific bpstat,
4409 just to things like whether watchpoints are set. */
4412 bpstat_should_step (void)
4414 struct breakpoint
*b
;
4416 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4422 bpstat_causes_stop (bpstat bs
)
4424 for (; bs
!= NULL
; bs
= bs
->next
)
4433 /* Print the LOC location out of the list of B->LOC locations. */
4435 static void print_breakpoint_location (struct breakpoint
*b
,
4436 struct bp_location
*loc
,
4438 struct ui_stream
*stb
)
4440 struct cleanup
*old_chain
= save_current_program_space ();
4442 if (loc
!= NULL
&& loc
->shlib_disabled
)
4446 set_current_program_space (loc
->pspace
);
4448 if (b
->source_file
&& loc
)
4451 = find_pc_sect_function (loc
->address
, loc
->section
);
4454 ui_out_text (uiout
, "in ");
4455 ui_out_field_string (uiout
, "func",
4456 SYMBOL_PRINT_NAME (sym
));
4457 ui_out_wrap_hint (uiout
, wrap_indent
);
4458 ui_out_text (uiout
, " at ");
4460 ui_out_field_string (uiout
, "file", b
->source_file
);
4461 ui_out_text (uiout
, ":");
4463 if (ui_out_is_mi_like_p (uiout
))
4465 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4466 char *fullname
= symtab_to_fullname (sal
.symtab
);
4469 ui_out_field_string (uiout
, "fullname", fullname
);
4472 ui_out_field_int (uiout
, "line", b
->line_number
);
4476 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4478 ui_out_field_stream (uiout
, "at", stb
);
4481 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4483 do_cleanups (old_chain
);
4486 /* Print B to gdb_stdout. */
4488 print_one_breakpoint_location (struct breakpoint
*b
,
4489 struct bp_location
*loc
,
4491 struct bp_location
**last_loc
,
4492 int print_address_bits
,
4495 struct command_line
*l
;
4497 struct ep_type_description
4502 static struct ep_type_description bptypes
[] =
4504 {bp_none
, "?deleted?"},
4505 {bp_breakpoint
, "breakpoint"},
4506 {bp_hardware_breakpoint
, "hw breakpoint"},
4507 {bp_until
, "until"},
4508 {bp_finish
, "finish"},
4509 {bp_watchpoint
, "watchpoint"},
4510 {bp_hardware_watchpoint
, "hw watchpoint"},
4511 {bp_read_watchpoint
, "read watchpoint"},
4512 {bp_access_watchpoint
, "acc watchpoint"},
4513 {bp_longjmp
, "longjmp"},
4514 {bp_longjmp_resume
, "longjmp resume"},
4515 {bp_step_resume
, "step resume"},
4516 {bp_watchpoint_scope
, "watchpoint scope"},
4517 {bp_call_dummy
, "call dummy"},
4518 {bp_std_terminate
, "std::terminate"},
4519 {bp_shlib_event
, "shlib events"},
4520 {bp_thread_event
, "thread events"},
4521 {bp_overlay_event
, "overlay events"},
4522 {bp_longjmp_master
, "longjmp master"},
4523 {bp_std_terminate_master
, "std::terminate master"},
4524 {bp_catchpoint
, "catchpoint"},
4525 {bp_tracepoint
, "tracepoint"},
4526 {bp_fast_tracepoint
, "fast tracepoint"},
4527 {bp_jit_event
, "jit events"},
4530 static char bpenables
[] = "nynny";
4531 char wrap_indent
[80];
4532 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4533 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4534 struct cleanup
*bkpt_chain
;
4536 int header_of_multiple
= 0;
4537 int part_of_multiple
= (loc
!= NULL
);
4538 struct value_print_options opts
;
4540 get_user_print_options (&opts
);
4542 gdb_assert (!loc
|| loc_number
!= 0);
4543 /* See comment in print_one_breakpoint concerning
4544 treatment of breakpoints with single disabled
4548 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4549 header_of_multiple
= 1;
4554 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4558 if (part_of_multiple
)
4561 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4562 ui_out_field_string (uiout
, "number", formatted
);
4567 ui_out_field_int (uiout
, "number", b
->number
);
4572 if (part_of_multiple
)
4573 ui_out_field_skip (uiout
, "type");
4576 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4577 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4578 internal_error (__FILE__
, __LINE__
,
4579 _("bptypes table does not describe type #%d."),
4581 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4586 if (part_of_multiple
)
4587 ui_out_field_skip (uiout
, "disp");
4589 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4594 if (part_of_multiple
)
4595 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4597 ui_out_field_fmt (uiout
, "enabled", "%c",
4598 bpenables
[(int) b
->enable_state
]);
4599 ui_out_spaces (uiout
, 2);
4603 strcpy (wrap_indent
, " ");
4604 if (opts
.addressprint
)
4606 if (print_address_bits
<= 32)
4607 strcat (wrap_indent
, " ");
4609 strcat (wrap_indent
, " ");
4612 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4614 /* Although the print_one can possibly print
4615 all locations, calling it here is not likely
4616 to get any nice result. So, make sure there's
4617 just one location. */
4618 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4619 b
->ops
->print_one (b
, last_loc
);
4625 internal_error (__FILE__
, __LINE__
,
4626 _("print_one_breakpoint: bp_none encountered\n"));
4630 case bp_hardware_watchpoint
:
4631 case bp_read_watchpoint
:
4632 case bp_access_watchpoint
:
4633 /* Field 4, the address, is omitted (which makes the columns
4634 not line up too nicely with the headers, but the effect
4635 is relatively readable). */
4636 if (opts
.addressprint
)
4637 ui_out_field_skip (uiout
, "addr");
4639 ui_out_field_string (uiout
, "what", b
->exp_string
);
4643 case bp_hardware_breakpoint
:
4647 case bp_longjmp_resume
:
4648 case bp_step_resume
:
4649 case bp_watchpoint_scope
:
4651 case bp_std_terminate
:
4652 case bp_shlib_event
:
4653 case bp_thread_event
:
4654 case bp_overlay_event
:
4655 case bp_longjmp_master
:
4656 case bp_std_terminate_master
:
4658 case bp_fast_tracepoint
:
4660 if (opts
.addressprint
)
4663 if (header_of_multiple
)
4664 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4665 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4666 ui_out_field_string (uiout
, "addr", "<PENDING>");
4668 ui_out_field_core_addr (uiout
, "addr",
4669 loc
->gdbarch
, loc
->address
);
4672 if (!header_of_multiple
)
4673 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4680 /* For backward compatibility, don't display inferiors unless there
4683 && !header_of_multiple
4685 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4686 && (number_of_program_spaces () > 1
4687 || number_of_inferiors () > 1)
4688 && loc
->owner
->type
!= bp_catchpoint
)))
4690 struct inferior
*inf
;
4693 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4695 if (inf
->pspace
== loc
->pspace
)
4700 ui_out_text (uiout
, " inf ");
4703 ui_out_text (uiout
, ", ");
4704 ui_out_text (uiout
, plongest (inf
->num
));
4709 if (!part_of_multiple
)
4711 if (b
->thread
!= -1)
4713 /* FIXME: This seems to be redundant and lost here; see the
4714 "stop only in" line a little further down. */
4715 ui_out_text (uiout
, " thread ");
4716 ui_out_field_int (uiout
, "thread", b
->thread
);
4718 else if (b
->task
!= 0)
4720 ui_out_text (uiout
, " task ");
4721 ui_out_field_int (uiout
, "task", b
->task
);
4725 ui_out_text (uiout
, "\n");
4727 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4730 ui_out_text (uiout
, "\tstop only in stack frame at ");
4731 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4733 ui_out_field_core_addr (uiout
, "frame",
4734 b
->gdbarch
, b
->frame_id
.stack_addr
);
4735 ui_out_text (uiout
, "\n");
4738 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4740 /* We do not print the condition for Ada exception catchpoints
4741 because the condition is an internal implementation detail
4742 that we do not want to expose to the user. */
4744 if (tracepoint_type (b
))
4745 ui_out_text (uiout
, "\ttrace only if ");
4747 ui_out_text (uiout
, "\tstop only if ");
4748 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4749 ui_out_text (uiout
, "\n");
4752 if (!part_of_multiple
&& b
->thread
!= -1)
4754 /* FIXME should make an annotation for this */
4755 ui_out_text (uiout
, "\tstop only in thread ");
4756 ui_out_field_int (uiout
, "thread", b
->thread
);
4757 ui_out_text (uiout
, "\n");
4760 if (!part_of_multiple
&& b
->hit_count
)
4762 /* FIXME should make an annotation for this */
4763 if (ep_is_catchpoint (b
))
4764 ui_out_text (uiout
, "\tcatchpoint");
4766 ui_out_text (uiout
, "\tbreakpoint");
4767 ui_out_text (uiout
, " already hit ");
4768 ui_out_field_int (uiout
, "times", b
->hit_count
);
4769 if (b
->hit_count
== 1)
4770 ui_out_text (uiout
, " time\n");
4772 ui_out_text (uiout
, " times\n");
4775 /* Output the count also if it is zero, but only if this is
4776 mi. FIXME: Should have a better test for this. */
4777 if (ui_out_is_mi_like_p (uiout
))
4778 if (!part_of_multiple
&& b
->hit_count
== 0)
4779 ui_out_field_int (uiout
, "times", b
->hit_count
);
4781 if (!part_of_multiple
&& b
->ignore_count
)
4784 ui_out_text (uiout
, "\tignore next ");
4785 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4786 ui_out_text (uiout
, " hits\n");
4789 l
= b
->commands
? b
->commands
->commands
: NULL
;
4790 if (!part_of_multiple
&& l
)
4792 struct cleanup
*script_chain
;
4795 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4796 print_command_lines (uiout
, l
, 4);
4797 do_cleanups (script_chain
);
4800 if (!part_of_multiple
&& b
->pass_count
)
4802 annotate_field (10);
4803 ui_out_text (uiout
, "\tpass count ");
4804 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4805 ui_out_text (uiout
, " \n");
4808 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4811 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4812 else if (b
->exp_string
)
4813 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4816 do_cleanups (bkpt_chain
);
4817 do_cleanups (old_chain
);
4821 print_one_breakpoint (struct breakpoint
*b
,
4822 struct bp_location
**last_loc
, int print_address_bits
,
4825 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4826 print_address_bits
, allflag
);
4828 /* If this breakpoint has custom print function,
4829 it's already printed. Otherwise, print individual
4830 locations, if any. */
4831 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4833 /* If breakpoint has a single location that is
4834 disabled, we print it as if it had
4835 several locations, since otherwise it's hard to
4836 represent "breakpoint enabled, location disabled"
4838 Note that while hardware watchpoints have
4839 several locations internally, that's no a property
4842 && !is_hardware_watchpoint (b
)
4843 && (b
->loc
->next
|| !b
->loc
->enabled
)
4844 && !ui_out_is_mi_like_p (uiout
))
4846 struct bp_location
*loc
;
4848 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4849 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4850 print_address_bits
, allflag
);
4856 breakpoint_address_bits (struct breakpoint
*b
)
4858 int print_address_bits
= 0;
4859 struct bp_location
*loc
;
4861 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4865 /* Software watchpoints that aren't watching memory don't have
4866 an address to print. */
4867 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4870 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4871 if (addr_bit
> print_address_bits
)
4872 print_address_bits
= addr_bit
;
4875 return print_address_bits
;
4878 struct captured_breakpoint_query_args
4884 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4886 struct captured_breakpoint_query_args
*args
= data
;
4887 struct breakpoint
*b
;
4888 struct bp_location
*dummy_loc
= NULL
;
4891 if (args
->bnum
== b
->number
)
4893 int print_address_bits
= breakpoint_address_bits (b
);
4894 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4902 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4904 struct captured_breakpoint_query_args args
;
4906 /* For the moment we don't trust print_one_breakpoint() to not throw
4908 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4909 error_message
, RETURN_MASK_ALL
) < 0)
4915 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4916 catchpoints, et.al.). */
4919 user_settable_breakpoint (const struct breakpoint
*b
)
4921 return (b
->type
== bp_breakpoint
4922 || b
->type
== bp_catchpoint
4923 || b
->type
== bp_hardware_breakpoint
4924 || tracepoint_type (b
)
4925 || b
->type
== bp_watchpoint
4926 || b
->type
== bp_read_watchpoint
4927 || b
->type
== bp_access_watchpoint
4928 || b
->type
== bp_hardware_watchpoint
);
4931 /* Print information on user settable breakpoint (watchpoint, etc)
4932 number BNUM. If BNUM is -1 print all user settable breakpoints.
4933 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4936 breakpoint_1 (int bnum
, int allflag
)
4938 struct breakpoint
*b
;
4939 struct bp_location
*last_loc
= NULL
;
4940 int nr_printable_breakpoints
;
4941 struct cleanup
*bkpttbl_chain
;
4942 struct value_print_options opts
;
4943 int print_address_bits
= 0;
4945 get_user_print_options (&opts
);
4947 /* Compute the number of rows in the table, as well as the
4948 size required for address fields. */
4949 nr_printable_breakpoints
= 0;
4952 || bnum
== b
->number
)
4954 if (allflag
|| user_settable_breakpoint (b
))
4956 int addr_bit
= breakpoint_address_bits (b
);
4957 if (addr_bit
> print_address_bits
)
4958 print_address_bits
= addr_bit
;
4960 nr_printable_breakpoints
++;
4964 if (opts
.addressprint
)
4966 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4970 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4973 if (nr_printable_breakpoints
> 0)
4974 annotate_breakpoints_headers ();
4975 if (nr_printable_breakpoints
> 0)
4977 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4978 if (nr_printable_breakpoints
> 0)
4980 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4981 if (nr_printable_breakpoints
> 0)
4983 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4984 if (nr_printable_breakpoints
> 0)
4986 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4987 if (opts
.addressprint
)
4989 if (nr_printable_breakpoints
> 0)
4991 if (print_address_bits
<= 32)
4992 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4994 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4996 if (nr_printable_breakpoints
> 0)
4998 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4999 ui_out_table_body (uiout
);
5000 if (nr_printable_breakpoints
> 0)
5001 annotate_breakpoints_table ();
5007 || bnum
== b
->number
)
5009 /* We only print out user settable breakpoints unless the
5011 if (allflag
|| user_settable_breakpoint (b
))
5012 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5016 do_cleanups (bkpttbl_chain
);
5018 if (nr_printable_breakpoints
== 0)
5021 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5023 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5028 if (last_loc
&& !server_command
)
5029 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5032 /* FIXME? Should this be moved up so that it is only called when
5033 there have been breakpoints? */
5034 annotate_breakpoints_table_end ();
5038 breakpoints_info (char *bnum_exp
, int from_tty
)
5043 bnum
= parse_and_eval_long (bnum_exp
);
5045 breakpoint_1 (bnum
, 0);
5049 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5054 bnum
= parse_and_eval_long (bnum_exp
);
5056 breakpoint_1 (bnum
, 1);
5060 breakpoint_has_pc (struct breakpoint
*b
,
5061 struct program_space
*pspace
,
5062 CORE_ADDR pc
, struct obj_section
*section
)
5064 struct bp_location
*bl
= b
->loc
;
5065 for (; bl
; bl
= bl
->next
)
5067 if (bl
->pspace
== pspace
5068 && bl
->address
== pc
5069 && (!overlay_debugging
|| bl
->section
== section
))
5075 /* Print a message describing any breakpoints set at PC. This
5076 concerns with logical breakpoints, so we match program spaces, not
5080 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5081 struct program_space
*pspace
, CORE_ADDR pc
,
5082 struct obj_section
*section
, int thread
)
5085 struct breakpoint
*b
;
5088 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5092 printf_filtered (_("Note: breakpoint "));
5093 else /* if (others == ???) */
5094 printf_filtered (_("Note: breakpoints "));
5096 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5099 printf_filtered ("%d", b
->number
);
5100 if (b
->thread
== -1 && thread
!= -1)
5101 printf_filtered (" (all threads)");
5102 else if (b
->thread
!= -1)
5103 printf_filtered (" (thread %d)", b
->thread
);
5104 printf_filtered ("%s%s ",
5105 ((b
->enable_state
== bp_disabled
5106 || b
->enable_state
== bp_call_disabled
5107 || b
->enable_state
== bp_startup_disabled
)
5109 : b
->enable_state
== bp_permanent
5113 : ((others
== 1) ? " and" : ""));
5115 printf_filtered (_("also set at pc "));
5116 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5117 printf_filtered (".\n");
5121 /* Set the default place to put a breakpoint
5122 for the `break' command with no arguments. */
5125 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5126 CORE_ADDR addr
, struct symtab
*symtab
,
5129 default_breakpoint_valid
= valid
;
5130 default_breakpoint_pspace
= pspace
;
5131 default_breakpoint_address
= addr
;
5132 default_breakpoint_symtab
= symtab
;
5133 default_breakpoint_line
= line
;
5136 /* Return true iff it is meaningful to use the address member of
5137 BPT. For some breakpoint types, the address member is irrelevant
5138 and it makes no sense to attempt to compare it to other addresses
5139 (or use it for any other purpose either).
5141 More specifically, each of the following breakpoint types will always
5142 have a zero valued address and we don't want to mark breakpoints of any of
5143 these types to be a duplicate of an actual breakpoint at address zero:
5151 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5153 enum bptype type
= bpt
->type
;
5155 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5158 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5159 true if LOC1 and LOC2 represent the same watchpoint location. */
5162 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5164 /* Note that this checks the owner's type, not the location's. In
5165 case the target does not support read watchpoints, but does
5166 support access watchpoints, we'll have bp_read_watchpoint
5167 watchpoints with hw_access locations. Those should be considered
5168 duplicates of hw_read locations. The hw_read locations will
5169 become hw_access locations later. */
5170 return (loc1
->owner
->type
== loc2
->owner
->type
5171 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5172 && loc1
->address
== loc2
->address
5173 && loc1
->length
== loc2
->length
);
5176 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5177 same breakpoint location. In most targets, this can only be true
5178 if ASPACE1 matches ASPACE2. On targets that have global
5179 breakpoints, the address space doesn't really matter. */
5182 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5183 struct address_space
*aspace2
, CORE_ADDR addr2
)
5185 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5186 || aspace1
== aspace2
)
5190 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5191 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5192 represent the same location. */
5195 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5197 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5198 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5200 if (hw_point1
!= hw_point2
)
5203 return watchpoint_locations_match (loc1
, loc2
);
5205 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5206 loc2
->pspace
->aspace
, loc2
->address
);
5210 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5211 int bnum
, int have_bnum
)
5216 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5217 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5219 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5220 bnum
, astr1
, astr2
);
5222 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5225 /* Adjust a breakpoint's address to account for architectural constraints
5226 on breakpoint placement. Return the adjusted address. Note: Very
5227 few targets require this kind of adjustment. For most targets,
5228 this function is simply the identity function. */
5231 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5232 CORE_ADDR bpaddr
, enum bptype bptype
)
5234 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5236 /* Very few targets need any kind of breakpoint adjustment. */
5239 else if (bptype
== bp_watchpoint
5240 || bptype
== bp_hardware_watchpoint
5241 || bptype
== bp_read_watchpoint
5242 || bptype
== bp_access_watchpoint
5243 || bptype
== bp_catchpoint
)
5245 /* Watchpoints and the various bp_catch_* eventpoints should not
5246 have their addresses modified. */
5251 CORE_ADDR adjusted_bpaddr
;
5253 /* Some targets have architectural constraints on the placement
5254 of breakpoint instructions. Obtain the adjusted address. */
5255 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5257 /* An adjusted breakpoint address can significantly alter
5258 a user's expectations. Print a warning if an adjustment
5260 if (adjusted_bpaddr
!= bpaddr
)
5261 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5263 return adjusted_bpaddr
;
5267 /* Allocate a struct bp_location. */
5269 static struct bp_location
*
5270 allocate_bp_location (struct breakpoint
*bpt
)
5272 struct bp_location
*loc
, *loc_p
;
5274 loc
= xmalloc (sizeof (struct bp_location
));
5275 memset (loc
, 0, sizeof (*loc
));
5279 loc
->shlib_disabled
= 0;
5288 case bp_longjmp_resume
:
5289 case bp_step_resume
:
5290 case bp_watchpoint_scope
:
5292 case bp_std_terminate
:
5293 case bp_shlib_event
:
5294 case bp_thread_event
:
5295 case bp_overlay_event
:
5297 case bp_longjmp_master
:
5298 case bp_std_terminate_master
:
5299 loc
->loc_type
= bp_loc_software_breakpoint
;
5301 case bp_hardware_breakpoint
:
5302 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5304 case bp_hardware_watchpoint
:
5305 case bp_read_watchpoint
:
5306 case bp_access_watchpoint
:
5307 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5312 case bp_fast_tracepoint
:
5313 loc
->loc_type
= bp_loc_other
;
5316 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5322 static void free_bp_location (struct bp_location
*loc
)
5327 if (loc
->function_name
)
5328 xfree (loc
->function_name
);
5333 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5334 that has type BPTYPE and has no locations as yet. */
5335 /* This function is used in gdbtk sources and thus can not be made static. */
5337 static struct breakpoint
*
5338 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5341 struct breakpoint
*b
, *b1
;
5343 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5344 memset (b
, 0, sizeof (*b
));
5347 b
->gdbarch
= gdbarch
;
5348 b
->language
= current_language
->la_language
;
5349 b
->input_radix
= input_radix
;
5351 b
->enable_state
= bp_enabled
;
5354 b
->ignore_count
= 0;
5356 b
->frame_id
= null_frame_id
;
5357 b
->forked_inferior_pid
= null_ptid
;
5358 b
->exec_pathname
= NULL
;
5359 b
->syscalls_to_be_caught
= NULL
;
5361 b
->condition_not_parsed
= 0;
5363 /* Add this breakpoint to the end of the chain
5364 so that a list of breakpoints will come out in order
5365 of increasing numbers. */
5367 b1
= breakpoint_chain
;
5369 breakpoint_chain
= b
;
5379 /* Initialize loc->function_name. */
5381 set_breakpoint_location_function (struct bp_location
*loc
)
5383 if (loc
->owner
->type
== bp_breakpoint
5384 || loc
->owner
->type
== bp_hardware_breakpoint
5385 || tracepoint_type (loc
->owner
))
5387 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5389 if (loc
->function_name
)
5390 loc
->function_name
= xstrdup (loc
->function_name
);
5394 /* Attempt to determine architecture of location identified by SAL. */
5395 static struct gdbarch
*
5396 get_sal_arch (struct symtab_and_line sal
)
5399 return get_objfile_arch (sal
.section
->objfile
);
5401 return get_objfile_arch (sal
.symtab
->objfile
);
5406 /* set_raw_breakpoint is a low level routine for allocating and
5407 partially initializing a breakpoint of type BPTYPE. The newly
5408 created breakpoint's address, section, source file name, and line
5409 number are provided by SAL. The newly created and partially
5410 initialized breakpoint is added to the breakpoint chain and
5411 is also returned as the value of this function.
5413 It is expected that the caller will complete the initialization of
5414 the newly created breakpoint struct as well as output any status
5415 information regarding the creation of a new breakpoint. In
5416 particular, set_raw_breakpoint does NOT set the breakpoint
5417 number! Care should be taken to not allow an error to occur
5418 prior to completing the initialization of the breakpoint. If this
5419 should happen, a bogus breakpoint will be left on the chain. */
5422 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5423 struct symtab_and_line sal
, enum bptype bptype
)
5425 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5426 CORE_ADDR adjusted_address
;
5427 struct gdbarch
*loc_gdbarch
;
5429 loc_gdbarch
= get_sal_arch (sal
);
5431 loc_gdbarch
= b
->gdbarch
;
5433 if (bptype
!= bp_catchpoint
)
5434 gdb_assert (sal
.pspace
!= NULL
);
5436 /* Adjust the breakpoint's address prior to allocating a location.
5437 Once we call allocate_bp_location(), that mostly uninitialized
5438 location will be placed on the location chain. Adjustment of the
5439 breakpoint may cause target_read_memory() to be called and we do
5440 not want its scan of the location chain to find a breakpoint and
5441 location that's only been partially initialized. */
5442 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5444 b
->loc
= allocate_bp_location (b
);
5445 b
->loc
->gdbarch
= loc_gdbarch
;
5446 b
->loc
->requested_address
= sal
.pc
;
5447 b
->loc
->address
= adjusted_address
;
5448 b
->loc
->pspace
= sal
.pspace
;
5450 /* Store the program space that was used to set the breakpoint, for
5451 breakpoint resetting. */
5452 b
->pspace
= sal
.pspace
;
5454 if (sal
.symtab
== NULL
)
5455 b
->source_file
= NULL
;
5457 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5458 b
->loc
->section
= sal
.section
;
5459 b
->line_number
= sal
.line
;
5461 set_breakpoint_location_function (b
->loc
);
5463 breakpoints_changed ();
5469 /* Note that the breakpoint object B describes a permanent breakpoint
5470 instruction, hard-wired into the inferior's code. */
5472 make_breakpoint_permanent (struct breakpoint
*b
)
5474 struct bp_location
*bl
;
5475 b
->enable_state
= bp_permanent
;
5477 /* By definition, permanent breakpoints are already present in the code.
5478 Mark all locations as inserted. For now, make_breakpoint_permanent
5479 is called in just one place, so it's hard to say if it's reasonable
5480 to have permanent breakpoint with multiple locations or not,
5481 but it's easy to implmement. */
5482 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5486 /* Call this routine when stepping and nexting to enable a breakpoint
5487 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5488 set_longjmp_resume_breakpoint() to figure out where we are going. */
5491 set_longjmp_breakpoint (int thread
)
5493 struct breakpoint
*b
, *temp
;
5495 /* To avoid having to rescan all objfile symbols at every step,
5496 we maintain a list of continually-inserted but always disabled
5497 longjmp "master" breakpoints. Here, we simply create momentary
5498 clones of those and enable them for the requested thread. */
5499 ALL_BREAKPOINTS_SAFE (b
, temp
)
5500 if (b
->pspace
== current_program_space
5501 && b
->type
== bp_longjmp_master
)
5503 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5504 clone
->type
= bp_longjmp
;
5505 clone
->thread
= thread
;
5509 /* Delete all longjmp breakpoints from THREAD. */
5511 delete_longjmp_breakpoint (int thread
)
5513 struct breakpoint
*b
, *temp
;
5515 ALL_BREAKPOINTS_SAFE (b
, temp
)
5516 if (b
->type
== bp_longjmp
)
5518 if (b
->thread
== thread
)
5519 delete_breakpoint (b
);
5524 enable_overlay_breakpoints (void)
5526 struct breakpoint
*b
;
5529 if (b
->type
== bp_overlay_event
)
5531 b
->enable_state
= bp_enabled
;
5532 update_global_location_list (1);
5533 overlay_events_enabled
= 1;
5538 disable_overlay_breakpoints (void)
5540 struct breakpoint
*b
;
5543 if (b
->type
== bp_overlay_event
)
5545 b
->enable_state
= bp_disabled
;
5546 update_global_location_list (0);
5547 overlay_events_enabled
= 0;
5551 /* Set an active std::terminate breakpoint for each std::terminate
5552 master breakpoint. */
5554 set_std_terminate_breakpoint (void)
5556 struct breakpoint
*b
, *temp
;
5558 ALL_BREAKPOINTS_SAFE (b
, temp
)
5559 if (b
->pspace
== current_program_space
5560 && b
->type
== bp_std_terminate_master
)
5562 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5563 clone
->type
= bp_std_terminate
;
5567 /* Delete all the std::terminate breakpoints. */
5569 delete_std_terminate_breakpoint (void)
5571 struct breakpoint
*b
, *temp
;
5573 ALL_BREAKPOINTS_SAFE (b
, temp
)
5574 if (b
->type
== bp_std_terminate
)
5575 delete_breakpoint (b
);
5579 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5581 struct breakpoint
*b
;
5583 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5585 b
->enable_state
= bp_enabled
;
5586 /* addr_string has to be used or breakpoint_re_set will delete me. */
5588 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5590 update_global_location_list_nothrow (1);
5596 remove_thread_event_breakpoints (void)
5598 struct breakpoint
*b
, *temp
;
5600 ALL_BREAKPOINTS_SAFE (b
, temp
)
5601 if (b
->type
== bp_thread_event
5602 && b
->loc
->pspace
== current_program_space
)
5603 delete_breakpoint (b
);
5606 struct captured_parse_breakpoint_args
5609 struct symtabs_and_lines
*sals_p
;
5610 char ***addr_string_p
;
5614 struct lang_and_radix
5620 /* Create a breakpoint for JIT code registration and unregistration. */
5623 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5625 struct breakpoint
*b
;
5627 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5628 update_global_location_list_nothrow (1);
5633 remove_solib_event_breakpoints (void)
5635 struct breakpoint
*b
, *temp
;
5637 ALL_BREAKPOINTS_SAFE (b
, temp
)
5638 if (b
->type
== bp_shlib_event
5639 && b
->loc
->pspace
== current_program_space
)
5640 delete_breakpoint (b
);
5644 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5646 struct breakpoint
*b
;
5648 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5649 update_global_location_list_nothrow (1);
5653 /* Disable any breakpoints that are on code in shared libraries. Only
5654 apply to enabled breakpoints, disabled ones can just stay disabled. */
5657 disable_breakpoints_in_shlibs (void)
5659 struct bp_location
*loc
, **locp_tmp
;
5661 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5663 struct breakpoint
*b
= loc
->owner
;
5664 /* We apply the check to all breakpoints, including disabled
5665 for those with loc->duplicate set. This is so that when breakpoint
5666 becomes enabled, or the duplicate is removed, gdb will try to insert
5667 all breakpoints. If we don't set shlib_disabled here, we'll try
5668 to insert those breakpoints and fail. */
5669 if (((b
->type
== bp_breakpoint
)
5670 || (b
->type
== bp_jit_event
)
5671 || (b
->type
== bp_hardware_breakpoint
)
5672 || (tracepoint_type (b
)))
5673 && loc
->pspace
== current_program_space
5674 && !loc
->shlib_disabled
5676 && PC_SOLIB (loc
->address
)
5678 && solib_name_from_address (loc
->pspace
, loc
->address
)
5682 loc
->shlib_disabled
= 1;
5687 /* Disable any breakpoints that are in in an unloaded shared library. Only
5688 apply to enabled breakpoints, disabled ones can just stay disabled. */
5691 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5693 struct bp_location
*loc
, **locp_tmp
;
5694 int disabled_shlib_breaks
= 0;
5696 /* SunOS a.out shared libraries are always mapped, so do not
5697 disable breakpoints; they will only be reported as unloaded
5698 through clear_solib when GDB discards its shared library
5699 list. See clear_solib for more information. */
5700 if (exec_bfd
!= NULL
5701 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5704 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5706 struct breakpoint
*b
= loc
->owner
;
5707 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5708 || loc
->loc_type
== bp_loc_software_breakpoint
)
5709 && solib
->pspace
== loc
->pspace
5710 && !loc
->shlib_disabled
5711 && (b
->type
== bp_breakpoint
5712 || b
->type
== bp_jit_event
5713 || b
->type
== bp_hardware_breakpoint
)
5714 && solib_contains_address_p (solib
, loc
->address
))
5716 loc
->shlib_disabled
= 1;
5717 /* At this point, we cannot rely on remove_breakpoint
5718 succeeding so we must mark the breakpoint as not inserted
5719 to prevent future errors occurring in remove_breakpoints. */
5721 if (!disabled_shlib_breaks
)
5723 target_terminal_ours_for_output ();
5724 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5727 disabled_shlib_breaks
= 1;
5732 /* FORK & VFORK catchpoints. */
5734 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5737 insert_catch_fork (struct breakpoint
*b
)
5739 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5742 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5745 remove_catch_fork (struct breakpoint
*b
)
5747 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5750 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5754 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5756 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5759 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5761 static enum print_stop_action
5762 print_it_catch_fork (struct breakpoint
*b
)
5764 annotate_catchpoint (b
->number
);
5765 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5766 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5767 return PRINT_SRC_AND_LOC
;
5770 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5773 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5775 struct value_print_options opts
;
5777 get_user_print_options (&opts
);
5779 /* Field 4, the address, is omitted (which makes the columns
5780 not line up too nicely with the headers, but the effect
5781 is relatively readable). */
5782 if (opts
.addressprint
)
5783 ui_out_field_skip (uiout
, "addr");
5785 ui_out_text (uiout
, "fork");
5786 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5788 ui_out_text (uiout
, ", process ");
5789 ui_out_field_int (uiout
, "what",
5790 ptid_get_pid (b
->forked_inferior_pid
));
5791 ui_out_spaces (uiout
, 1);
5795 /* Implement the "print_mention" breakpoint_ops method for fork
5799 print_mention_catch_fork (struct breakpoint
*b
)
5801 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5804 /* The breakpoint_ops structure to be used in fork catchpoints. */
5806 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5810 breakpoint_hit_catch_fork
,
5811 print_it_catch_fork
,
5812 print_one_catch_fork
,
5813 print_mention_catch_fork
5816 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5819 insert_catch_vfork (struct breakpoint
*b
)
5821 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5824 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5827 remove_catch_vfork (struct breakpoint
*b
)
5829 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5832 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5836 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5838 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5841 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5843 static enum print_stop_action
5844 print_it_catch_vfork (struct breakpoint
*b
)
5846 annotate_catchpoint (b
->number
);
5847 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5848 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5849 return PRINT_SRC_AND_LOC
;
5852 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5855 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5857 struct value_print_options opts
;
5859 get_user_print_options (&opts
);
5860 /* Field 4, the address, is omitted (which makes the columns
5861 not line up too nicely with the headers, but the effect
5862 is relatively readable). */
5863 if (opts
.addressprint
)
5864 ui_out_field_skip (uiout
, "addr");
5866 ui_out_text (uiout
, "vfork");
5867 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5869 ui_out_text (uiout
, ", process ");
5870 ui_out_field_int (uiout
, "what",
5871 ptid_get_pid (b
->forked_inferior_pid
));
5872 ui_out_spaces (uiout
, 1);
5876 /* Implement the "print_mention" breakpoint_ops method for vfork
5880 print_mention_catch_vfork (struct breakpoint
*b
)
5882 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5885 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5887 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5891 breakpoint_hit_catch_vfork
,
5892 print_it_catch_vfork
,
5893 print_one_catch_vfork
,
5894 print_mention_catch_vfork
5897 /* Implement the "insert" breakpoint_ops method for syscall
5901 insert_catch_syscall (struct breakpoint
*b
)
5903 struct inferior
*inf
= current_inferior ();
5905 ++inf
->total_syscalls_count
;
5906 if (!b
->syscalls_to_be_caught
)
5907 ++inf
->any_syscall_count
;
5912 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5916 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5918 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5919 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5921 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5922 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5924 memset ((void *) vec_addr
, 0,
5925 (iter
+ 1 - old_size
) * sizeof (int));
5927 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5928 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5932 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5933 inf
->total_syscalls_count
!= 0,
5934 inf
->any_syscall_count
,
5935 VEC_length (int, inf
->syscalls_counts
),
5936 VEC_address (int, inf
->syscalls_counts
));
5939 /* Implement the "remove" breakpoint_ops method for syscall
5943 remove_catch_syscall (struct breakpoint
*b
)
5945 struct inferior
*inf
= current_inferior ();
5947 --inf
->total_syscalls_count
;
5948 if (!b
->syscalls_to_be_caught
)
5949 --inf
->any_syscall_count
;
5954 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5958 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5959 /* Shouldn't happen. */
5961 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5962 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5966 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5967 inf
->total_syscalls_count
!= 0,
5968 inf
->any_syscall_count
,
5969 VEC_length (int, inf
->syscalls_counts
),
5970 VEC_address (int, inf
->syscalls_counts
));
5973 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5977 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5979 /* We must check if we are catching specific syscalls in this breakpoint.
5980 If we are, then we must guarantee that the called syscall is the same
5981 syscall we are catching. */
5982 int syscall_number
= 0;
5984 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5987 /* Now, checking if the syscall is the same. */
5988 if (b
->syscalls_to_be_caught
)
5992 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5994 if (syscall_number
== iter
)
6004 /* Implement the "print_it" breakpoint_ops method for syscall
6007 static enum print_stop_action
6008 print_it_catch_syscall (struct breakpoint
*b
)
6010 /* These are needed because we want to know in which state a
6011 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6012 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6013 must print "called syscall" or "returned from syscall". */
6015 struct target_waitstatus last
;
6017 struct cleanup
*old_chain
;
6020 get_last_target_status (&ptid
, &last
);
6022 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6024 annotate_catchpoint (b
->number
);
6027 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6029 syscall_id
= xstrprintf ("'%s'", s
.name
);
6031 old_chain
= make_cleanup (xfree
, syscall_id
);
6033 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6034 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6035 b
->number
, syscall_id
);
6036 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6037 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6038 b
->number
, syscall_id
);
6040 do_cleanups (old_chain
);
6042 return PRINT_SRC_AND_LOC
;
6045 /* Implement the "print_one" breakpoint_ops method for syscall
6049 print_one_catch_syscall (struct breakpoint
*b
,
6050 struct bp_location
**last_loc
)
6052 struct value_print_options opts
;
6054 get_user_print_options (&opts
);
6055 /* Field 4, the address, is omitted (which makes the columns
6056 not line up too nicely with the headers, but the effect
6057 is relatively readable). */
6058 if (opts
.addressprint
)
6059 ui_out_field_skip (uiout
, "addr");
6062 if (b
->syscalls_to_be_caught
6063 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6064 ui_out_text (uiout
, "syscalls \"");
6066 ui_out_text (uiout
, "syscall \"");
6068 if (b
->syscalls_to_be_caught
)
6071 char *text
= xstrprintf ("%s", "");
6073 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6078 get_syscall_by_number (iter
, &s
);
6081 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6083 text
= xstrprintf ("%s%d, ", text
, iter
);
6085 /* We have to xfree the last 'text' (now stored at 'x')
6086 because xstrprintf dinamically allocates new space for it
6090 /* Remove the last comma. */
6091 text
[strlen (text
) - 2] = '\0';
6092 ui_out_field_string (uiout
, "what", text
);
6095 ui_out_field_string (uiout
, "what", "<any syscall>");
6096 ui_out_text (uiout
, "\" ");
6099 /* Implement the "print_mention" breakpoint_ops method for syscall
6103 print_mention_catch_syscall (struct breakpoint
*b
)
6105 if (b
->syscalls_to_be_caught
)
6109 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6110 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6112 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6115 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6119 get_syscall_by_number (iter
, &s
);
6122 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6124 printf_filtered (" %d", s
.number
);
6126 printf_filtered (")");
6129 printf_filtered (_("Catchpoint %d (any syscall)"),
6133 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6135 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6137 insert_catch_syscall
,
6138 remove_catch_syscall
,
6139 breakpoint_hit_catch_syscall
,
6140 print_it_catch_syscall
,
6141 print_one_catch_syscall
,
6142 print_mention_catch_syscall
6145 /* Returns non-zero if 'b' is a syscall catchpoint. */
6148 syscall_catchpoint_p (struct breakpoint
*b
)
6150 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6153 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6154 but does NOT mention it nor update the global location list.
6155 This is useful if you need to fill more fields in the
6156 struct breakpoint before calling mention.
6158 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6159 If COND_STRING is not NULL, then store it in the breakpoint.
6160 OPS, if not NULL, is the breakpoint_ops structure associated
6161 to the catchpoint. */
6163 static struct breakpoint
*
6164 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6166 struct breakpoint_ops
*ops
)
6168 struct symtab_and_line sal
;
6169 struct breakpoint
*b
;
6172 sal
.pspace
= current_program_space
;
6174 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6175 set_breakpoint_count (breakpoint_count
+ 1);
6176 b
->number
= breakpoint_count
;
6178 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6180 b
->addr_string
= NULL
;
6181 b
->enable_state
= bp_enabled
;
6182 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6188 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6190 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6191 If COND_STRING is not NULL, then store it in the breakpoint.
6192 OPS, if not NULL, is the breakpoint_ops structure associated
6193 to the catchpoint. */
6195 static struct breakpoint
*
6196 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6197 char *cond_string
, struct breakpoint_ops
*ops
)
6199 struct breakpoint
*b
=
6200 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6203 update_global_location_list (1);
6209 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6210 int tempflag
, char *cond_string
,
6211 struct breakpoint_ops
*ops
)
6213 struct breakpoint
*b
6214 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6216 /* FIXME: We should put this information in a breakpoint private data
6218 b
->forked_inferior_pid
= null_ptid
;
6221 /* Exec catchpoints. */
6224 insert_catch_exec (struct breakpoint
*b
)
6226 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6230 remove_catch_exec (struct breakpoint
*b
)
6232 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6236 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6238 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6241 static enum print_stop_action
6242 print_it_catch_exec (struct breakpoint
*b
)
6244 annotate_catchpoint (b
->number
);
6245 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6247 return PRINT_SRC_AND_LOC
;
6251 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6253 struct value_print_options opts
;
6255 get_user_print_options (&opts
);
6257 /* Field 4, the address, is omitted (which makes the columns
6258 not line up too nicely with the headers, but the effect
6259 is relatively readable). */
6260 if (opts
.addressprint
)
6261 ui_out_field_skip (uiout
, "addr");
6263 ui_out_text (uiout
, "exec");
6264 if (b
->exec_pathname
!= NULL
)
6266 ui_out_text (uiout
, ", program \"");
6267 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6268 ui_out_text (uiout
, "\" ");
6273 print_mention_catch_exec (struct breakpoint
*b
)
6275 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6278 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6282 breakpoint_hit_catch_exec
,
6283 print_it_catch_exec
,
6284 print_one_catch_exec
,
6285 print_mention_catch_exec
6289 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6290 struct breakpoint_ops
*ops
)
6292 struct gdbarch
*gdbarch
= get_current_arch ();
6293 struct breakpoint
*b
=
6294 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6296 b
->syscalls_to_be_caught
= filter
;
6298 /* Now, we have to mention the breakpoint and update the global
6301 update_global_location_list (1);
6305 hw_breakpoint_used_count (void)
6307 struct breakpoint
*b
;
6312 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6320 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6322 struct breakpoint
*b
;
6325 *other_type_used
= 0;
6328 if (breakpoint_enabled (b
))
6330 if (b
->type
== type
)
6332 else if ((b
->type
== bp_hardware_watchpoint
6333 || b
->type
== bp_read_watchpoint
6334 || b
->type
== bp_access_watchpoint
))
6335 *other_type_used
= 1;
6342 disable_watchpoints_before_interactive_call_start (void)
6344 struct breakpoint
*b
;
6348 if (((b
->type
== bp_watchpoint
)
6349 || (b
->type
== bp_hardware_watchpoint
)
6350 || (b
->type
== bp_read_watchpoint
)
6351 || (b
->type
== bp_access_watchpoint
))
6352 && breakpoint_enabled (b
))
6354 b
->enable_state
= bp_call_disabled
;
6355 update_global_location_list (0);
6361 enable_watchpoints_after_interactive_call_stop (void)
6363 struct breakpoint
*b
;
6367 if (((b
->type
== bp_watchpoint
)
6368 || (b
->type
== bp_hardware_watchpoint
)
6369 || (b
->type
== bp_read_watchpoint
)
6370 || (b
->type
== bp_access_watchpoint
))
6371 && (b
->enable_state
== bp_call_disabled
))
6373 b
->enable_state
= bp_enabled
;
6374 update_global_location_list (1);
6380 disable_breakpoints_before_startup (void)
6382 struct breakpoint
*b
;
6387 if (b
->pspace
!= current_program_space
)
6390 if ((b
->type
== bp_breakpoint
6391 || b
->type
== bp_hardware_breakpoint
)
6392 && breakpoint_enabled (b
))
6394 b
->enable_state
= bp_startup_disabled
;
6400 update_global_location_list (0);
6402 current_program_space
->executing_startup
= 1;
6406 enable_breakpoints_after_startup (void)
6408 struct breakpoint
*b
;
6411 current_program_space
->executing_startup
= 0;
6415 if (b
->pspace
!= current_program_space
)
6418 if ((b
->type
== bp_breakpoint
6419 || b
->type
== bp_hardware_breakpoint
)
6420 && b
->enable_state
== bp_startup_disabled
)
6422 b
->enable_state
= bp_enabled
;
6428 breakpoint_re_set ();
6432 /* Set a breakpoint that will evaporate an end of command
6433 at address specified by SAL.
6434 Restrict it to frame FRAME if FRAME is nonzero. */
6437 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6438 struct frame_id frame_id
, enum bptype type
)
6440 struct breakpoint
*b
;
6442 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6444 gdb_assert (!frame_id_inlined_p (frame_id
));
6446 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6447 b
->enable_state
= bp_enabled
;
6448 b
->disposition
= disp_donttouch
;
6449 b
->frame_id
= frame_id
;
6451 /* If we're debugging a multi-threaded program, then we
6452 want momentary breakpoints to be active in only a
6453 single thread of control. */
6454 if (in_thread_list (inferior_ptid
))
6455 b
->thread
= pid_to_thread_id (inferior_ptid
);
6457 update_global_location_list_nothrow (1);
6462 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6466 clone_momentary_breakpoint (struct breakpoint
*orig
)
6468 struct breakpoint
*copy
;
6470 /* If there's nothing to clone, then return nothing. */
6474 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6475 copy
->loc
= allocate_bp_location (copy
);
6476 set_breakpoint_location_function (copy
->loc
);
6478 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6479 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6480 copy
->loc
->address
= orig
->loc
->address
;
6481 copy
->loc
->section
= orig
->loc
->section
;
6482 copy
->loc
->pspace
= orig
->loc
->pspace
;
6484 if (orig
->source_file
== NULL
)
6485 copy
->source_file
= NULL
;
6487 copy
->source_file
= xstrdup (orig
->source_file
);
6489 copy
->line_number
= orig
->line_number
;
6490 copy
->frame_id
= orig
->frame_id
;
6491 copy
->thread
= orig
->thread
;
6492 copy
->pspace
= orig
->pspace
;
6494 copy
->enable_state
= bp_enabled
;
6495 copy
->disposition
= disp_donttouch
;
6496 copy
->number
= internal_breakpoint_number
--;
6498 update_global_location_list_nothrow (0);
6503 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6506 struct symtab_and_line sal
;
6508 sal
= find_pc_line (pc
, 0);
6510 sal
.section
= find_pc_overlay (pc
);
6511 sal
.explicit_pc
= 1;
6513 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6517 /* Tell the user we have just set a breakpoint B. */
6520 mention (struct breakpoint
*b
)
6523 struct cleanup
*ui_out_chain
;
6524 struct value_print_options opts
;
6526 get_user_print_options (&opts
);
6528 /* FIXME: This is misplaced; mention() is called by things (like
6529 hitting a watchpoint) other than breakpoint creation. It should
6530 be possible to clean this up and at the same time replace the
6531 random calls to breakpoint_changed with this hook. */
6532 observer_notify_breakpoint_created (b
->number
);
6534 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6535 b
->ops
->print_mention (b
);
6540 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6543 ui_out_text (uiout
, "Watchpoint ");
6544 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6545 ui_out_field_int (uiout
, "number", b
->number
);
6546 ui_out_text (uiout
, ": ");
6547 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6548 do_cleanups (ui_out_chain
);
6550 case bp_hardware_watchpoint
:
6551 ui_out_text (uiout
, "Hardware watchpoint ");
6552 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6553 ui_out_field_int (uiout
, "number", b
->number
);
6554 ui_out_text (uiout
, ": ");
6555 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6556 do_cleanups (ui_out_chain
);
6558 case bp_read_watchpoint
:
6559 ui_out_text (uiout
, "Hardware read watchpoint ");
6560 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6561 ui_out_field_int (uiout
, "number", b
->number
);
6562 ui_out_text (uiout
, ": ");
6563 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6564 do_cleanups (ui_out_chain
);
6566 case bp_access_watchpoint
:
6567 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6568 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6569 ui_out_field_int (uiout
, "number", b
->number
);
6570 ui_out_text (uiout
, ": ");
6571 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6572 do_cleanups (ui_out_chain
);
6575 if (ui_out_is_mi_like_p (uiout
))
6580 if (b
->disposition
== disp_del
)
6581 printf_filtered (_("Temporary breakpoint"));
6583 printf_filtered (_("Breakpoint"));
6584 printf_filtered (_(" %d"), b
->number
);
6587 case bp_hardware_breakpoint
:
6588 if (ui_out_is_mi_like_p (uiout
))
6593 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6597 if (ui_out_is_mi_like_p (uiout
))
6602 printf_filtered (_("Tracepoint"));
6603 printf_filtered (_(" %d"), b
->number
);
6606 case bp_fast_tracepoint
:
6607 if (ui_out_is_mi_like_p (uiout
))
6612 printf_filtered (_("Fast tracepoint"));
6613 printf_filtered (_(" %d"), b
->number
);
6620 case bp_longjmp_resume
:
6621 case bp_step_resume
:
6623 case bp_std_terminate
:
6624 case bp_watchpoint_scope
:
6625 case bp_shlib_event
:
6626 case bp_thread_event
:
6627 case bp_overlay_event
:
6629 case bp_longjmp_master
:
6630 case bp_std_terminate_master
:
6636 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6640 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6644 if (opts
.addressprint
|| b
->source_file
== NULL
)
6646 printf_filtered (" at ");
6647 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6651 printf_filtered (": file %s, line %d.",
6652 b
->source_file
, b
->line_number
);
6656 struct bp_location
*loc
= b
->loc
;
6658 for (; loc
; loc
= loc
->next
)
6660 printf_filtered (" (%d locations)", n
);
6665 if (ui_out_is_mi_like_p (uiout
))
6667 printf_filtered ("\n");
6671 static struct bp_location
*
6672 add_location_to_breakpoint (struct breakpoint
*b
,
6673 const struct symtab_and_line
*sal
)
6675 struct bp_location
*loc
, **tmp
;
6677 loc
= allocate_bp_location (b
);
6678 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6681 loc
->gdbarch
= get_sal_arch (*sal
);
6683 loc
->gdbarch
= b
->gdbarch
;
6684 loc
->requested_address
= sal
->pc
;
6685 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6686 loc
->requested_address
, b
->type
);
6687 loc
->pspace
= sal
->pspace
;
6688 gdb_assert (loc
->pspace
!= NULL
);
6689 loc
->section
= sal
->section
;
6691 set_breakpoint_location_function (loc
);
6696 /* Return 1 if LOC is pointing to a permanent breakpoint,
6697 return 0 otherwise. */
6700 bp_loc_is_permanent (struct bp_location
*loc
)
6704 const gdb_byte
*brk
;
6705 gdb_byte
*target_mem
;
6706 struct cleanup
*cleanup
;
6709 gdb_assert (loc
!= NULL
);
6711 addr
= loc
->address
;
6712 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6714 /* Software breakpoints unsupported? */
6718 target_mem
= alloca (len
);
6720 /* Enable the automatic memory restoration from breakpoints while
6721 we read the memory. Otherwise we could say about our temporary
6722 breakpoints they are permanent. */
6723 cleanup
= save_current_space_and_thread ();
6725 switch_to_program_space_and_thread (loc
->pspace
);
6726 make_show_memory_breakpoints_cleanup (0);
6728 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6729 && memcmp (target_mem
, brk
, len
) == 0)
6732 do_cleanups (cleanup
);
6739 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6740 as textual description of the location, and COND_STRING
6741 as condition expression. */
6744 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6745 struct symtabs_and_lines sals
, char *addr_string
,
6747 enum bptype type
, enum bpdisp disposition
,
6748 int thread
, int task
, int ignore_count
,
6749 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6751 struct breakpoint
*b
= NULL
;
6754 if (type
== bp_hardware_breakpoint
)
6756 int i
= hw_breakpoint_used_count ();
6757 int target_resources_ok
=
6758 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6760 if (target_resources_ok
== 0)
6761 error (_("No hardware breakpoint support in the target."));
6762 else if (target_resources_ok
< 0)
6763 error (_("Hardware breakpoints used exceeds limit."));
6766 gdb_assert (sals
.nelts
> 0);
6768 for (i
= 0; i
< sals
.nelts
; ++i
)
6770 struct symtab_and_line sal
= sals
.sals
[i
];
6771 struct bp_location
*loc
;
6775 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6777 loc_gdbarch
= gdbarch
;
6779 describe_other_breakpoints (loc_gdbarch
,
6780 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6785 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6786 set_breakpoint_count (breakpoint_count
+ 1);
6787 b
->number
= breakpoint_count
;
6791 b
->cond_string
= cond_string
;
6792 b
->ignore_count
= ignore_count
;
6793 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6794 b
->disposition
= disposition
;
6796 b
->pspace
= sals
.sals
[0].pspace
;
6798 if (enabled
&& b
->pspace
->executing_startup
6799 && (b
->type
== bp_breakpoint
6800 || b
->type
== bp_hardware_breakpoint
))
6801 b
->enable_state
= bp_startup_disabled
;
6807 loc
= add_location_to_breakpoint (b
, &sal
);
6810 if (bp_loc_is_permanent (loc
))
6811 make_breakpoint_permanent (b
);
6815 char *arg
= b
->cond_string
;
6816 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6818 error (_("Garbage %s follows condition"), arg
);
6823 b
->addr_string
= addr_string
;
6825 /* addr_string has to be used or breakpoint_re_set will delete
6828 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6834 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6835 elements to fill the void space. */
6837 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6839 int i
= index_to_remove
+1;
6840 int last_index
= sal
->nelts
-1;
6842 for (;i
<= last_index
; ++i
)
6843 sal
->sals
[i
-1] = sal
->sals
[i
];
6848 /* If appropriate, obtains all sals that correspond to the same file
6849 and line as SAL, in all program spaces. Users debugging with IDEs,
6850 will want to set a breakpoint at foo.c:line, and not really care
6851 about program spaces. This is done only if SAL does not have
6852 explicit PC and has line and file information. If we got just a
6853 single expanded sal, return the original.
6855 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6856 which the name of enclosing function is different from SAL. This
6857 makes sure that if we have breakpoint originally set in template
6858 instantiation, say foo<int>(), we won't expand SAL to locations at
6859 the same line in all existing instantiations of 'foo'. */
6861 static struct symtabs_and_lines
6862 expand_line_sal_maybe (struct symtab_and_line sal
)
6864 struct symtabs_and_lines expanded
;
6865 CORE_ADDR original_pc
= sal
.pc
;
6866 char *original_function
= NULL
;
6869 struct cleanup
*old_chain
;
6871 /* If we have explicit pc, don't expand.
6872 If we have no line number, we can't expand. */
6873 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6876 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6877 expanded
.sals
[0] = sal
;
6883 old_chain
= save_current_space_and_thread ();
6885 switch_to_program_space_and_thread (sal
.pspace
);
6887 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6889 /* Note that expand_line_sal visits *all* program spaces. */
6890 expanded
= expand_line_sal (sal
);
6892 if (expanded
.nelts
== 1)
6894 /* We had one sal, we got one sal. Return that sal, adjusting it
6895 past the function prologue if necessary. */
6896 xfree (expanded
.sals
);
6898 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6899 sal
.pc
= original_pc
;
6900 expanded
.sals
[0] = sal
;
6901 skip_prologue_sal (&expanded
.sals
[0]);
6902 do_cleanups (old_chain
);
6906 if (!sal
.explicit_line
)
6908 CORE_ADDR func_addr
, func_end
;
6909 for (i
= 0; i
< expanded
.nelts
; ++i
)
6911 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6912 char *this_function
;
6914 /* We need to switch threads as well since we're about to
6916 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6918 if (find_pc_partial_function (pc
, &this_function
,
6919 &func_addr
, &func_end
))
6922 && strcmp (this_function
, original_function
) != 0)
6924 remove_sal (&expanded
, i
);
6931 /* Skip the function prologue if necessary. */
6932 for (i
= 0; i
< expanded
.nelts
; ++i
)
6933 skip_prologue_sal (&expanded
.sals
[i
]);
6935 do_cleanups (old_chain
);
6937 if (expanded
.nelts
<= 1)
6939 /* This is un ugly workaround. If we get zero
6940 expanded sals then something is really wrong.
6941 Fix that by returnign the original sal. */
6942 xfree (expanded
.sals
);
6944 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6945 sal
.pc
= original_pc
;
6946 expanded
.sals
[0] = sal
;
6953 for (i
= 0; i
< expanded
.nelts
; ++i
)
6954 if (expanded
.sals
[i
].pc
== original_pc
)
6965 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6966 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6967 value. COND_STRING, if not NULL, specified the condition to be
6968 used for all breakpoints. Essentially the only case where
6969 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6970 function. In that case, it's still not possible to specify
6971 separate conditions for different overloaded functions, so
6972 we take just a single condition string.
6974 NOTE: If the function succeeds, the caller is expected to cleanup
6975 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6976 array contents). If the function fails (error() is called), the
6977 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6978 COND and SALS arrays and each of those arrays contents. */
6981 create_breakpoints_sal (struct gdbarch
*gdbarch
,
6982 struct symtabs_and_lines sals
, char **addr_string
,
6984 enum bptype type
, enum bpdisp disposition
,
6985 int thread
, int task
, int ignore_count
,
6986 struct breakpoint_ops
*ops
, int from_tty
,
6990 for (i
= 0; i
< sals
.nelts
; ++i
)
6992 struct symtabs_and_lines expanded
=
6993 expand_line_sal_maybe (sals
.sals
[i
]);
6995 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
6996 cond_string
, type
, disposition
,
6997 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7001 /* Parse ARG which is assumed to be a SAL specification possibly
7002 followed by conditionals. On return, SALS contains an array of SAL
7003 addresses found. ADDR_STRING contains a vector of (canonical)
7004 address strings. ARG points to the end of the SAL. */
7007 parse_breakpoint_sals (char **address
,
7008 struct symtabs_and_lines
*sals
,
7009 char ***addr_string
,
7012 char *addr_start
= *address
;
7013 *addr_string
= NULL
;
7014 /* If no arg given, or if first arg is 'if ', use the default
7016 if ((*address
) == NULL
7017 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7019 if (default_breakpoint_valid
)
7021 struct symtab_and_line sal
;
7022 init_sal (&sal
); /* initialize to zeroes */
7023 sals
->sals
= (struct symtab_and_line
*)
7024 xmalloc (sizeof (struct symtab_and_line
));
7025 sal
.pc
= default_breakpoint_address
;
7026 sal
.line
= default_breakpoint_line
;
7027 sal
.symtab
= default_breakpoint_symtab
;
7028 sal
.pspace
= default_breakpoint_pspace
;
7029 sal
.section
= find_pc_overlay (sal
.pc
);
7031 /* "break" without arguments is equivalent to "break *PC" where PC is
7032 the default_breakpoint_address. So make sure to set
7033 sal.explicit_pc to prevent GDB from trying to expand the list of
7034 sals to include all other instances with the same symtab and line.
7036 sal
.explicit_pc
= 1;
7038 sals
->sals
[0] = sal
;
7042 error (_("No default breakpoint address now."));
7046 /* Force almost all breakpoints to be in terms of the
7047 current_source_symtab (which is decode_line_1's default). This
7048 should produce the results we want almost all of the time while
7049 leaving default_breakpoint_* alone.
7050 ObjC: However, don't match an Objective-C method name which
7051 may have a '+' or '-' succeeded by a '[' */
7053 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7055 if (default_breakpoint_valid
7057 || ((strchr ("+-", (*address
)[0]) != NULL
)
7058 && ((*address
)[1] != '['))))
7059 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7060 default_breakpoint_line
, addr_string
,
7063 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7064 addr_string
, not_found_ptr
);
7066 /* For any SAL that didn't have a canonical string, fill one in. */
7067 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7068 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7069 if (addr_start
!= (*address
))
7072 for (i
= 0; i
< sals
->nelts
; i
++)
7074 /* Add the string if not present. */
7075 if ((*addr_string
)[i
] == NULL
)
7076 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7082 /* Convert each SAL into a real PC. Verify that the PC can be
7083 inserted as a breakpoint. If it can't throw an error. */
7086 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7090 for (i
= 0; i
< sals
->nelts
; i
++)
7091 resolve_sal_pc (&sals
->sals
[i
]);
7094 /* Fast tracepoints may have restrictions on valid locations. For
7095 instance, a fast tracepoint using a jump instead of a trap will
7096 likely have to overwrite more bytes than a trap would, and so can
7097 only be placed where the instruction is longer than the jump, or a
7098 multi-instruction sequence does not have a jump into the middle of
7102 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7103 struct symtabs_and_lines
*sals
)
7106 struct symtab_and_line
*sal
;
7108 struct cleanup
*old_chain
;
7110 for (i
= 0; i
< sals
->nelts
; i
++)
7112 sal
= &sals
->sals
[i
];
7114 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7116 old_chain
= make_cleanup (xfree
, msg
);
7119 error (_("May not have a fast tracepoint at 0x%s%s"),
7120 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7122 do_cleanups (old_chain
);
7127 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7129 struct captured_parse_breakpoint_args
*args
= data
;
7131 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7132 args
->not_found_ptr
);
7135 /* Given TOK, a string specification of condition and thread, as
7136 accepted by the 'break' command, extract the condition
7137 string and thread number and set *COND_STRING and *THREAD.
7138 PC identifies the context at which the condition should be parsed.
7139 If no condition is found, *COND_STRING is set to NULL.
7140 If no thread is found, *THREAD is set to -1. */
7142 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7143 char **cond_string
, int *thread
, int *task
)
7145 *cond_string
= NULL
;
7151 char *cond_start
= NULL
;
7152 char *cond_end
= NULL
;
7153 while (*tok
== ' ' || *tok
== '\t')
7158 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7161 toklen
= end_tok
- tok
;
7163 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7165 struct expression
*expr
;
7167 tok
= cond_start
= end_tok
+ 1;
7168 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7171 *cond_string
= savestring (cond_start
,
7172 cond_end
- cond_start
);
7174 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7180 *thread
= strtol (tok
, &tok
, 0);
7182 error (_("Junk after thread keyword."));
7183 if (!valid_thread_id (*thread
))
7184 error (_("Unknown thread %d."), *thread
);
7186 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7192 *task
= strtol (tok
, &tok
, 0);
7194 error (_("Junk after task keyword."));
7195 if (!valid_task_id (*task
))
7196 error (_("Unknown task %d."), *task
);
7199 error (_("Junk at end of arguments."));
7203 /* Set a breakpoint. This function is shared between CLI and MI
7204 functions for setting a breakpoint. This function has two major
7205 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7206 parameter. If non-zero, the function will parse arg, extracting
7207 breakpoint location, address and thread. Otherwise, ARG is just the
7208 location of breakpoint, with condition and thread specified by the
7209 COND_STRING and THREAD parameters. Returns true if any breakpoint
7210 was created; false otherwise. */
7213 create_breakpoint (struct gdbarch
*gdbarch
,
7214 char *arg
, char *cond_string
, int thread
,
7215 int parse_condition_and_thread
,
7216 int tempflag
, int hardwareflag
, int traceflag
,
7218 enum auto_boolean pending_break_support
,
7219 struct breakpoint_ops
*ops
,
7223 struct gdb_exception e
;
7224 struct symtabs_and_lines sals
;
7225 struct symtab_and_line pending_sal
;
7228 char *addr_start
= arg
;
7230 struct cleanup
*old_chain
;
7231 struct cleanup
*bkpt_chain
= NULL
;
7232 struct captured_parse_breakpoint_args parse_args
;
7236 enum bptype type_wanted
;
7238 int first_bp_set
= breakpoint_count
+ 1;
7244 parse_args
.arg_p
= &arg
;
7245 parse_args
.sals_p
= &sals
;
7246 parse_args
.addr_string_p
= &addr_string
;
7247 parse_args
.not_found_ptr
= ¬_found
;
7249 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7250 &parse_args
, RETURN_MASK_ALL
);
7252 /* If caller is interested in rc value from parse, set value. */
7256 throw_exception (e
);
7260 case NOT_FOUND_ERROR
:
7262 /* If pending breakpoint support is turned off, throw
7265 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7266 throw_exception (e
);
7268 exception_print (gdb_stderr
, e
);
7270 /* If pending breakpoint support is auto query and the user
7271 selects no, then simply return the error code. */
7272 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7273 && !nquery ("Make breakpoint pending on future shared library load? "))
7276 /* At this point, either the user was queried about setting
7277 a pending breakpoint and selected yes, or pending
7278 breakpoint behavior is on and thus a pending breakpoint
7279 is defaulted on behalf of the user. */
7280 copy_arg
= xstrdup (addr_start
);
7281 addr_string
= ©_arg
;
7283 sals
.sals
= &pending_sal
;
7288 throw_exception (e
);
7295 /* Create a chain of things that always need to be cleaned up. */
7296 old_chain
= make_cleanup (null_cleanup
, 0);
7300 /* Make sure that all storage allocated to SALS gets freed. */
7301 make_cleanup (xfree
, sals
.sals
);
7303 /* Cleanup the addr_string array but not its contents. */
7304 make_cleanup (xfree
, addr_string
);
7307 /* ----------------------------- SNIP -----------------------------
7308 Anything added to the cleanup chain beyond this point is assumed
7309 to be part of a breakpoint. If the breakpoint create succeeds
7310 then the memory is not reclaimed. */
7311 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7313 /* Mark the contents of the addr_string for cleanup. These go on
7314 the bkpt_chain and only occur if the breakpoint create fails. */
7315 for (i
= 0; i
< sals
.nelts
; i
++)
7317 if (addr_string
[i
] != NULL
)
7318 make_cleanup (xfree
, addr_string
[i
]);
7321 /* Resolve all line numbers to PC's and verify that the addresses
7322 are ok for the target. */
7324 breakpoint_sals_to_pc (&sals
, addr_start
);
7326 type_wanted
= (traceflag
7327 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7328 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7330 /* Fast tracepoints may have additional restrictions on location. */
7331 if (type_wanted
== bp_fast_tracepoint
)
7332 check_fast_tracepoint_sals (gdbarch
, &sals
);
7334 /* Verify that condition can be parsed, before setting any
7335 breakpoints. Allocate a separate condition expression for each
7339 if (parse_condition_and_thread
)
7341 /* Here we only parse 'arg' to separate condition
7342 from thread number, so parsing in context of first
7343 sal is OK. When setting the breakpoint we'll
7344 re-parse it in context of each sal. */
7347 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7350 make_cleanup (xfree
, cond_string
);
7354 /* Create a private copy of condition string. */
7357 cond_string
= xstrdup (cond_string
);
7358 make_cleanup (xfree
, cond_string
);
7361 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7362 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7363 thread
, task
, ignore_count
, ops
, from_tty
,
7368 struct symtab_and_line sal
= {0};
7369 struct breakpoint
*b
;
7371 make_cleanup (xfree
, copy_arg
);
7373 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7374 set_breakpoint_count (breakpoint_count
+ 1);
7375 b
->number
= breakpoint_count
;
7377 b
->addr_string
= addr_string
[0];
7378 b
->cond_string
= NULL
;
7379 b
->ignore_count
= ignore_count
;
7380 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7381 b
->condition_not_parsed
= 1;
7383 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7384 b
->pspace
= current_program_space
;
7386 if (enabled
&& b
->pspace
->executing_startup
7387 && (b
->type
== bp_breakpoint
7388 || b
->type
== bp_hardware_breakpoint
))
7389 b
->enable_state
= bp_startup_disabled
;
7396 warning (_("Multiple breakpoints were set.\n"
7397 "Use the \"delete\" command to delete unwanted breakpoints."));
7398 multi_start
= first_bp_set
;
7399 multi_end
= breakpoint_count
;
7403 /* That's it. Discard the cleanups for data inserted into the
7405 discard_cleanups (bkpt_chain
);
7406 /* But cleanup everything else. */
7407 do_cleanups (old_chain
);
7409 /* error call may happen here - have BKPT_CHAIN already discarded. */
7410 update_global_location_list (1);
7415 /* Set a breakpoint.
7416 ARG is a string describing breakpoint address,
7417 condition, and thread.
7418 FLAG specifies if a breakpoint is hardware on,
7419 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7423 break_command_1 (char *arg
, int flag
, int from_tty
)
7425 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7426 int tempflag
= flag
& BP_TEMPFLAG
;
7428 create_breakpoint (get_current_arch (),
7430 NULL
, 0, 1 /* parse arg */,
7431 tempflag
, hardwareflag
, 0 /* traceflag */,
7432 0 /* Ignore count */,
7433 pending_break_support
,
7434 NULL
/* breakpoint_ops */,
7441 /* Helper function for break_command_1 and disassemble_command. */
7444 resolve_sal_pc (struct symtab_and_line
*sal
)
7448 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7450 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7451 error (_("No line %d in file \"%s\"."),
7452 sal
->line
, sal
->symtab
->filename
);
7455 /* If this SAL corresponds to a breakpoint inserted using
7456 a line number, then skip the function prologue if necessary. */
7457 if (sal
->explicit_line
)
7458 skip_prologue_sal (sal
);
7461 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7463 struct blockvector
*bv
;
7467 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7470 sym
= block_linkage_function (b
);
7473 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7474 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7478 /* It really is worthwhile to have the section, so we'll just
7479 have to look harder. This case can be executed if we have
7480 line numbers but no functions (as can happen in assembly
7483 struct minimal_symbol
*msym
;
7484 struct cleanup
*old_chain
= save_current_space_and_thread ();
7486 switch_to_program_space_and_thread (sal
->pspace
);
7488 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7490 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7492 do_cleanups (old_chain
);
7499 break_command (char *arg
, int from_tty
)
7501 break_command_1 (arg
, 0, from_tty
);
7505 tbreak_command (char *arg
, int from_tty
)
7507 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7511 hbreak_command (char *arg
, int from_tty
)
7513 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7517 thbreak_command (char *arg
, int from_tty
)
7519 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7523 stop_command (char *arg
, int from_tty
)
7525 printf_filtered (_("Specify the type of breakpoint to set.\n\
7526 Usage: stop in <function | address>\n\
7527 stop at <line>\n"));
7531 stopin_command (char *arg
, int from_tty
)
7535 if (arg
== (char *) NULL
)
7537 else if (*arg
!= '*')
7542 /* look for a ':'. If this is a line number specification, then
7543 say it is bad, otherwise, it should be an address or
7544 function/method name */
7545 while (*argptr
&& !hasColon
)
7547 hasColon
= (*argptr
== ':');
7552 badInput
= (*argptr
!= ':'); /* Not a class::method */
7554 badInput
= isdigit (*arg
); /* a simple line number */
7558 printf_filtered (_("Usage: stop in <function | address>\n"));
7560 break_command_1 (arg
, 0, from_tty
);
7564 stopat_command (char *arg
, int from_tty
)
7568 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7575 /* look for a ':'. If there is a '::' then get out, otherwise
7576 it is probably a line number. */
7577 while (*argptr
&& !hasColon
)
7579 hasColon
= (*argptr
== ':');
7584 badInput
= (*argptr
== ':'); /* we have class::method */
7586 badInput
= !isdigit (*arg
); /* not a line number */
7590 printf_filtered (_("Usage: stop at <line>\n"));
7592 break_command_1 (arg
, 0, from_tty
);
7595 /* accessflag: hw_write: watch write,
7596 hw_read: watch read,
7597 hw_access: watch access (read or write) */
7599 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7601 struct gdbarch
*gdbarch
= get_current_arch ();
7602 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7603 struct expression
*exp
;
7604 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7605 struct value
*val
, *mark
;
7606 struct frame_info
*frame
;
7607 char *exp_start
= NULL
;
7608 char *exp_end
= NULL
;
7609 char *tok
, *id_tok_start
, *end_tok
;
7611 char *cond_start
= NULL
;
7612 char *cond_end
= NULL
;
7613 int i
, other_type_used
, target_resources_ok
= 0;
7614 enum bptype bp_type
;
7618 /* Make sure that we actually have parameters to parse. */
7619 if (arg
!= NULL
&& arg
[0] != '\0')
7621 toklen
= strlen (arg
); /* Size of argument list. */
7623 /* Points tok to the end of the argument list. */
7624 tok
= arg
+ toklen
- 1;
7626 /* Go backwards in the parameters list. Skip the last parameter.
7627 If we're expecting a 'thread <thread_num>' parameter, this should
7628 be the thread identifier. */
7629 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7631 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7634 /* Points end_tok to the beginning of the last token. */
7635 id_tok_start
= tok
+ 1;
7637 /* Go backwards in the parameters list. Skip one more parameter.
7638 If we're expecting a 'thread <thread_num>' parameter, we should
7639 reach a "thread" token. */
7640 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7645 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7648 /* Move the pointer forward to skip the whitespace and
7649 calculate the length of the token. */
7651 toklen
= end_tok
- tok
;
7653 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7655 /* At this point we've found a "thread" token, which means
7656 the user is trying to set a watchpoint that triggers
7657 only in a specific thread. */
7660 /* Extract the thread ID from the next token. */
7661 thread
= strtol (id_tok_start
, &endp
, 0);
7663 /* Check if the user provided a valid numeric value for the
7665 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7666 error (_("Invalid thread ID specification %s."), id_tok_start
);
7668 /* Check if the thread actually exists. */
7669 if (!valid_thread_id (thread
))
7670 error (_("Unknown thread %d."), thread
);
7672 /* Truncate the string and get rid of the thread <thread_num>
7673 parameter before the parameter list is parsed by the
7674 evaluate_expression() function. */
7679 /* Parse the rest of the arguments. */
7680 innermost_block
= NULL
;
7682 exp
= parse_exp_1 (&arg
, 0, 0);
7684 /* Remove trailing whitespace from the expression before saving it.
7685 This makes the eventual display of the expression string a bit
7687 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7690 exp_valid_block
= innermost_block
;
7691 mark
= value_mark ();
7692 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7694 release_value (val
);
7697 while (*tok
== ' ' || *tok
== '\t')
7701 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7704 toklen
= end_tok
- tok
;
7705 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7707 struct expression
*cond
;
7709 innermost_block
= NULL
;
7710 tok
= cond_start
= end_tok
+ 1;
7711 cond
= parse_exp_1 (&tok
, 0, 0);
7713 /* The watchpoint expression may not be local, but the condition
7714 may still be. E.g.: `watch global if local > 0'. */
7715 cond_exp_valid_block
= innermost_block
;
7721 error (_("Junk at end of command."));
7723 if (accessflag
== hw_read
)
7724 bp_type
= bp_read_watchpoint
;
7725 else if (accessflag
== hw_access
)
7726 bp_type
= bp_access_watchpoint
;
7728 bp_type
= bp_hardware_watchpoint
;
7730 mem_cnt
= can_use_hardware_watchpoint (val
);
7731 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7732 error (_("Expression cannot be implemented with read/access watchpoint."));
7735 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7736 target_resources_ok
=
7737 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7739 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7740 error (_("Target does not support this type of hardware watchpoint."));
7742 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7743 error (_("Target can only support one kind of HW watchpoint at a time."));
7746 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7747 watchpoint could not be set. */
7748 if (!mem_cnt
|| target_resources_ok
<= 0)
7749 bp_type
= bp_watchpoint
;
7751 frame
= block_innermost_frame (exp_valid_block
);
7753 /* If the expression is "local", then set up a "watchpoint scope"
7754 breakpoint at the point where we've left the scope of the watchpoint
7755 expression. Create the scope breakpoint before the watchpoint, so
7756 that we will encounter it first in bpstat_stop_status. */
7757 if (exp_valid_block
&& frame
)
7759 if (frame_id_p (frame_unwind_caller_id (frame
)))
7762 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7763 frame_unwind_caller_pc (frame
),
7764 bp_watchpoint_scope
);
7766 scope_breakpoint
->enable_state
= bp_enabled
;
7768 /* Automatically delete the breakpoint when it hits. */
7769 scope_breakpoint
->disposition
= disp_del
;
7771 /* Only break in the proper frame (help with recursion). */
7772 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7774 /* Set the address at which we will stop. */
7775 scope_breakpoint
->loc
->gdbarch
7776 = frame_unwind_caller_arch (frame
);
7777 scope_breakpoint
->loc
->requested_address
7778 = frame_unwind_caller_pc (frame
);
7779 scope_breakpoint
->loc
->address
7780 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7781 scope_breakpoint
->loc
->requested_address
,
7782 scope_breakpoint
->type
);
7786 /* Now set up the breakpoint. */
7787 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7788 set_breakpoint_count (breakpoint_count
+ 1);
7789 b
->number
= breakpoint_count
;
7791 b
->disposition
= disp_donttouch
;
7793 b
->exp_valid_block
= exp_valid_block
;
7794 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7795 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7799 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7805 b
->watchpoint_frame
= get_frame_id (frame
);
7806 b
->watchpoint_thread
= inferior_ptid
;
7810 b
->watchpoint_frame
= null_frame_id
;
7811 b
->watchpoint_thread
= null_ptid
;
7814 if (scope_breakpoint
!= NULL
)
7816 /* The scope breakpoint is related to the watchpoint. We will
7817 need to act on them together. */
7818 b
->related_breakpoint
= scope_breakpoint
;
7819 scope_breakpoint
->related_breakpoint
= b
;
7822 value_free_to_mark (mark
);
7824 /* Finally update the new watchpoint. This creates the locations
7825 that should be inserted. */
7826 update_watchpoint (b
, 1);
7829 update_global_location_list (1);
7832 /* Return count of locations need to be watched and can be handled
7833 in hardware. If the watchpoint can not be handled
7834 in hardware return zero. */
7837 can_use_hardware_watchpoint (struct value
*v
)
7839 int found_memory_cnt
= 0;
7840 struct value
*head
= v
;
7842 /* Did the user specifically forbid us to use hardware watchpoints? */
7843 if (!can_use_hw_watchpoints
)
7846 /* Make sure that the value of the expression depends only upon
7847 memory contents, and values computed from them within GDB. If we
7848 find any register references or function calls, we can't use a
7849 hardware watchpoint.
7851 The idea here is that evaluating an expression generates a series
7852 of values, one holding the value of every subexpression. (The
7853 expression a*b+c has five subexpressions: a, b, a*b, c, and
7854 a*b+c.) GDB's values hold almost enough information to establish
7855 the criteria given above --- they identify memory lvalues,
7856 register lvalues, computed values, etcetera. So we can evaluate
7857 the expression, and then scan the chain of values that leaves
7858 behind to decide whether we can detect any possible change to the
7859 expression's final value using only hardware watchpoints.
7861 However, I don't think that the values returned by inferior
7862 function calls are special in any way. So this function may not
7863 notice that an expression involving an inferior function call
7864 can't be watched with hardware watchpoints. FIXME. */
7865 for (; v
; v
= value_next (v
))
7867 if (VALUE_LVAL (v
) == lval_memory
)
7870 /* A lazy memory lvalue is one that GDB never needed to fetch;
7871 we either just used its address (e.g., `a' in `a.b') or
7872 we never needed it at all (e.g., `a' in `a,b'). */
7876 /* Ahh, memory we actually used! Check if we can cover
7877 it with hardware watchpoints. */
7878 struct type
*vtype
= check_typedef (value_type (v
));
7880 /* We only watch structs and arrays if user asked for it
7881 explicitly, never if they just happen to appear in a
7882 middle of some value chain. */
7884 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7885 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7887 CORE_ADDR vaddr
= value_address (v
);
7888 int len
= TYPE_LENGTH (value_type (v
));
7890 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7897 else if (VALUE_LVAL (v
) != not_lval
7898 && deprecated_value_modifiable (v
) == 0)
7899 return 0; /* ??? What does this represent? */
7900 else if (VALUE_LVAL (v
) == lval_register
)
7901 return 0; /* cannot watch a register with a HW watchpoint */
7904 /* The expression itself looks suitable for using a hardware
7905 watchpoint, but give the target machine a chance to reject it. */
7906 return found_memory_cnt
;
7910 watch_command_wrapper (char *arg
, int from_tty
)
7912 watch_command (arg
, from_tty
);
7916 watch_command (char *arg
, int from_tty
)
7918 watch_command_1 (arg
, hw_write
, from_tty
);
7922 rwatch_command_wrapper (char *arg
, int from_tty
)
7924 rwatch_command (arg
, from_tty
);
7928 rwatch_command (char *arg
, int from_tty
)
7930 watch_command_1 (arg
, hw_read
, from_tty
);
7934 awatch_command_wrapper (char *arg
, int from_tty
)
7936 awatch_command (arg
, from_tty
);
7940 awatch_command (char *arg
, int from_tty
)
7942 watch_command_1 (arg
, hw_access
, from_tty
);
7946 /* Helper routines for the until_command routine in infcmd.c. Here
7947 because it uses the mechanisms of breakpoints. */
7949 struct until_break_command_continuation_args
7951 struct breakpoint
*breakpoint
;
7952 struct breakpoint
*breakpoint2
;
7955 /* This function is called by fetch_inferior_event via the
7956 cmd_continuation pointer, to complete the until command. It takes
7957 care of cleaning up the temporary breakpoints set up by the until
7960 until_break_command_continuation (void *arg
)
7962 struct until_break_command_continuation_args
*a
= arg
;
7964 delete_breakpoint (a
->breakpoint
);
7966 delete_breakpoint (a
->breakpoint2
);
7970 until_break_command (char *arg
, int from_tty
, int anywhere
)
7972 struct symtabs_and_lines sals
;
7973 struct symtab_and_line sal
;
7974 struct frame_info
*frame
= get_selected_frame (NULL
);
7975 struct breakpoint
*breakpoint
;
7976 struct breakpoint
*breakpoint2
= NULL
;
7977 struct cleanup
*old_chain
;
7979 clear_proceed_status ();
7981 /* Set a breakpoint where the user wants it and at return from
7984 if (default_breakpoint_valid
)
7985 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
7986 default_breakpoint_line
, (char ***) NULL
, NULL
);
7988 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
7989 0, (char ***) NULL
, NULL
);
7991 if (sals
.nelts
!= 1)
7992 error (_("Couldn't get information on specified line."));
7995 xfree (sals
.sals
); /* malloc'd, so freed */
7998 error (_("Junk at end of arguments."));
8000 resolve_sal_pc (&sal
);
8003 /* If the user told us to continue until a specified location,
8004 we don't specify a frame at which we need to stop. */
8005 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8006 null_frame_id
, bp_until
);
8008 /* Otherwise, specify the selected frame, because we want to stop only
8009 at the very same frame. */
8010 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8011 get_stack_frame_id (frame
),
8014 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8016 /* Keep within the current frame, or in frames called by the current
8019 if (frame_id_p (frame_unwind_caller_id (frame
)))
8021 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8022 sal
.pc
= frame_unwind_caller_pc (frame
);
8023 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8025 frame_unwind_caller_id (frame
),
8027 make_cleanup_delete_breakpoint (breakpoint2
);
8030 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8032 /* If we are running asynchronously, and proceed call above has actually
8033 managed to start the target, arrange for breakpoints to be
8034 deleted when the target stops. Otherwise, we're already stopped and
8035 delete breakpoints via cleanup chain. */
8037 if (target_can_async_p () && is_running (inferior_ptid
))
8039 struct until_break_command_continuation_args
*args
;
8040 args
= xmalloc (sizeof (*args
));
8042 args
->breakpoint
= breakpoint
;
8043 args
->breakpoint2
= breakpoint2
;
8045 discard_cleanups (old_chain
);
8046 add_continuation (inferior_thread (),
8047 until_break_command_continuation
, args
,
8051 do_cleanups (old_chain
);
8055 ep_skip_leading_whitespace (char **s
)
8057 if ((s
== NULL
) || (*s
== NULL
))
8059 while (isspace (**s
))
8063 /* This function attempts to parse an optional "if <cond>" clause
8064 from the arg string. If one is not found, it returns NULL.
8066 Else, it returns a pointer to the condition string. (It does not
8067 attempt to evaluate the string against a particular block.) And,
8068 it updates arg to point to the first character following the parsed
8069 if clause in the arg string. */
8072 ep_parse_optional_if_clause (char **arg
)
8076 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8079 /* Skip the "if" keyword. */
8082 /* Skip any extra leading whitespace, and record the start of the
8083 condition string. */
8084 ep_skip_leading_whitespace (arg
);
8087 /* Assume that the condition occupies the remainder of the arg string. */
8088 (*arg
) += strlen (cond_string
);
8093 /* Commands to deal with catching events, such as signals, exceptions,
8094 process start/exit, etc. */
8098 catch_fork_temporary
, catch_vfork_temporary
,
8099 catch_fork_permanent
, catch_vfork_permanent
8104 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8106 struct gdbarch
*gdbarch
= get_current_arch ();
8107 char *cond_string
= NULL
;
8108 catch_fork_kind fork_kind
;
8111 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8112 tempflag
= (fork_kind
== catch_fork_temporary
8113 || fork_kind
== catch_vfork_temporary
);
8117 ep_skip_leading_whitespace (&arg
);
8119 /* The allowed syntax is:
8121 catch [v]fork if <cond>
8123 First, check if there's an if clause. */
8124 cond_string
= ep_parse_optional_if_clause (&arg
);
8126 if ((*arg
!= '\0') && !isspace (*arg
))
8127 error (_("Junk at end of arguments."));
8129 /* If this target supports it, create a fork or vfork catchpoint
8130 and enable reporting of such events. */
8133 case catch_fork_temporary
:
8134 case catch_fork_permanent
:
8135 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8136 &catch_fork_breakpoint_ops
);
8138 case catch_vfork_temporary
:
8139 case catch_vfork_permanent
:
8140 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8141 &catch_vfork_breakpoint_ops
);
8144 error (_("unsupported or unknown fork kind; cannot catch it"));
8150 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8152 struct gdbarch
*gdbarch
= get_current_arch ();
8154 char *cond_string
= NULL
;
8156 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8160 ep_skip_leading_whitespace (&arg
);
8162 /* The allowed syntax is:
8164 catch exec if <cond>
8166 First, check if there's an if clause. */
8167 cond_string
= ep_parse_optional_if_clause (&arg
);
8169 if ((*arg
!= '\0') && !isspace (*arg
))
8170 error (_("Junk at end of arguments."));
8172 /* If this target supports it, create an exec catchpoint
8173 and enable reporting of such events. */
8174 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8175 &catch_exec_breakpoint_ops
);
8178 static enum print_stop_action
8179 print_exception_catchpoint (struct breakpoint
*b
)
8181 int bp_temp
, bp_throw
;
8183 annotate_catchpoint (b
->number
);
8185 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8186 if (b
->loc
->address
!= b
->loc
->requested_address
)
8187 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8190 bp_temp
= b
->disposition
== disp_del
;
8192 bp_temp
? "Temporary catchpoint "
8194 if (!ui_out_is_mi_like_p (uiout
))
8195 ui_out_field_int (uiout
, "bkptno", b
->number
);
8197 bp_throw
? " (exception thrown), "
8198 : " (exception caught), ");
8199 if (ui_out_is_mi_like_p (uiout
))
8201 ui_out_field_string (uiout
, "reason",
8202 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8203 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8204 ui_out_field_int (uiout
, "bkptno", b
->number
);
8206 return PRINT_SRC_AND_LOC
;
8210 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8212 struct value_print_options opts
;
8213 get_user_print_options (&opts
);
8214 if (opts
.addressprint
)
8217 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8218 ui_out_field_string (uiout
, "addr", "<PENDING>");
8220 ui_out_field_core_addr (uiout
, "addr",
8221 b
->loc
->gdbarch
, b
->loc
->address
);
8226 if (strstr (b
->addr_string
, "throw") != NULL
)
8227 ui_out_field_string (uiout
, "what", "exception throw");
8229 ui_out_field_string (uiout
, "what", "exception catch");
8233 print_mention_exception_catchpoint (struct breakpoint
*b
)
8238 bp_temp
= b
->disposition
== disp_del
;
8239 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8240 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8241 : _("Catchpoint "));
8242 ui_out_field_int (uiout
, "bkptno", b
->number
);
8243 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8247 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8250 NULL
, /* breakpoint_hit */
8251 print_exception_catchpoint
,
8252 print_one_exception_catchpoint
,
8253 print_mention_exception_catchpoint
8257 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8258 enum exception_event_kind ex_event
, int from_tty
)
8260 char *trigger_func_name
;
8262 if (ex_event
== EX_EVENT_CATCH
)
8263 trigger_func_name
= "__cxa_begin_catch";
8265 trigger_func_name
= "__cxa_throw";
8267 create_breakpoint (get_current_arch (),
8268 trigger_func_name
, cond_string
, -1,
8269 0 /* condition and thread are valid. */,
8272 AUTO_BOOLEAN_TRUE
/* pending */,
8273 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8279 /* Deal with "catch catch" and "catch throw" commands */
8282 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8283 int tempflag
, int from_tty
)
8285 char *cond_string
= NULL
;
8286 struct symtab_and_line
*sal
= NULL
;
8290 ep_skip_leading_whitespace (&arg
);
8292 cond_string
= ep_parse_optional_if_clause (&arg
);
8294 if ((*arg
!= '\0') && !isspace (*arg
))
8295 error (_("Junk at end of arguments."));
8297 if (ex_event
!= EX_EVENT_THROW
8298 && ex_event
!= EX_EVENT_CATCH
)
8299 error (_("Unsupported or unknown exception event; cannot catch it"));
8301 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8304 warning (_("Unsupported with this platform/compiler combination."));
8307 /* Implementation of "catch catch" command. */
8310 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8312 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8313 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8316 /* Implementation of "catch throw" command. */
8319 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8321 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8322 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8325 /* Create a breakpoint struct for Ada exception catchpoints. */
8328 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8329 struct symtab_and_line sal
,
8333 struct expression
*cond
,
8334 struct breakpoint_ops
*ops
,
8338 struct breakpoint
*b
;
8342 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8344 loc_gdbarch
= gdbarch
;
8346 describe_other_breakpoints (loc_gdbarch
,
8347 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8348 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8349 version for exception catchpoints, because two catchpoints
8350 used for different exception names will use the same address.
8351 In this case, a "breakpoint ... also set at..." warning is
8352 unproductive. Besides. the warning phrasing is also a bit
8353 inapropriate, we should use the word catchpoint, and tell
8354 the user what type of catchpoint it is. The above is good
8355 enough for now, though. */
8358 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8359 set_breakpoint_count (breakpoint_count
+ 1);
8361 b
->enable_state
= bp_enabled
;
8362 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8363 b
->number
= breakpoint_count
;
8364 b
->ignore_count
= 0;
8365 b
->loc
->cond
= cond
;
8366 b
->addr_string
= addr_string
;
8367 b
->language
= language_ada
;
8368 b
->cond_string
= cond_string
;
8369 b
->exp_string
= exp_string
;
8374 update_global_location_list (1);
8377 /* Implement the "catch exception" command. */
8380 catch_ada_exception_command (char *arg
, int from_tty
,
8381 struct cmd_list_element
*command
)
8383 struct gdbarch
*gdbarch
= get_current_arch ();
8385 struct symtab_and_line sal
;
8387 char *addr_string
= NULL
;
8388 char *exp_string
= NULL
;
8389 char *cond_string
= NULL
;
8390 struct expression
*cond
= NULL
;
8391 struct breakpoint_ops
*ops
= NULL
;
8393 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8397 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8398 &cond_string
, &cond
, &ops
);
8399 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8400 cond_string
, cond
, ops
, tempflag
,
8404 /* Cleanup function for a syscall filter list. */
8406 clean_up_filters (void *arg
)
8408 VEC(int) *iter
= *(VEC(int) **) arg
;
8409 VEC_free (int, iter
);
8412 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8413 filter list, or NULL if no filtering is required. */
8415 catch_syscall_split_args (char *arg
)
8417 VEC(int) *result
= NULL
;
8418 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8420 while (*arg
!= '\0')
8422 int i
, syscall_number
;
8427 /* Skip whitespace. */
8428 while (isspace (*arg
))
8431 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8432 cur_name
[i
] = arg
[i
];
8436 /* Check if the user provided a syscall name or a number. */
8437 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8438 if (*endptr
== '\0')
8439 get_syscall_by_number (syscall_number
, &s
);
8442 /* We have a name. Let's check if it's valid and convert it
8444 get_syscall_by_name (cur_name
, &s
);
8446 if (s
.number
== UNKNOWN_SYSCALL
)
8447 /* Here we have to issue an error instead of a warning, because
8448 GDB cannot do anything useful if there's no syscall number to
8450 error (_("Unknown syscall name '%s'."), cur_name
);
8453 /* Ok, it's valid. */
8454 VEC_safe_push (int, result
, s
.number
);
8457 discard_cleanups (cleanup
);
8461 /* Implement the "catch syscall" command. */
8464 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8469 struct gdbarch
*gdbarch
= get_current_arch ();
8471 /* Checking if the feature if supported. */
8472 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8473 error (_("The feature 'catch syscall' is not supported on \
8474 this architeture yet."));
8476 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8478 ep_skip_leading_whitespace (&arg
);
8480 /* We need to do this first "dummy" translation in order
8481 to get the syscall XML file loaded or, most important,
8482 to display a warning to the user if there's no XML file
8483 for his/her architecture. */
8484 get_syscall_by_number (0, &s
);
8486 /* The allowed syntax is:
8488 catch syscall <name | number> [<name | number> ... <name | number>]
8490 Let's check if there's a syscall name. */
8493 filter
= catch_syscall_split_args (arg
);
8497 create_syscall_event_catchpoint (tempflag
, filter
,
8498 &catch_syscall_breakpoint_ops
);
8501 /* Implement the "catch assert" command. */
8504 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8506 struct gdbarch
*gdbarch
= get_current_arch ();
8508 struct symtab_and_line sal
;
8509 char *addr_string
= NULL
;
8510 struct breakpoint_ops
*ops
= NULL
;
8512 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8516 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8517 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8518 ops
, tempflag
, from_tty
);
8522 catch_command (char *arg
, int from_tty
)
8524 error (_("Catch requires an event name."));
8529 tcatch_command (char *arg
, int from_tty
)
8531 error (_("Catch requires an event name."));
8534 /* Delete breakpoints by address or line. */
8537 clear_command (char *arg
, int from_tty
)
8539 struct breakpoint
*b
;
8540 VEC(breakpoint_p
) *found
= 0;
8543 struct symtabs_and_lines sals
;
8544 struct symtab_and_line sal
;
8549 sals
= decode_line_spec (arg
, 1);
8554 sals
.sals
= (struct symtab_and_line
*)
8555 xmalloc (sizeof (struct symtab_and_line
));
8556 make_cleanup (xfree
, sals
.sals
);
8557 init_sal (&sal
); /* initialize to zeroes */
8558 sal
.line
= default_breakpoint_line
;
8559 sal
.symtab
= default_breakpoint_symtab
;
8560 sal
.pc
= default_breakpoint_address
;
8561 sal
.pspace
= default_breakpoint_pspace
;
8562 if (sal
.symtab
== 0)
8563 error (_("No source file specified."));
8571 /* We don't call resolve_sal_pc here. That's not
8572 as bad as it seems, because all existing breakpoints
8573 typically have both file/line and pc set. So, if
8574 clear is given file/line, we can match this to existing
8575 breakpoint without obtaining pc at all.
8577 We only support clearing given the address explicitly
8578 present in breakpoint table. Say, we've set breakpoint
8579 at file:line. There were several PC values for that file:line,
8580 due to optimization, all in one block.
8581 We've picked one PC value. If "clear" is issued with another
8582 PC corresponding to the same file:line, the breakpoint won't
8583 be cleared. We probably can still clear the breakpoint, but
8584 since the other PC value is never presented to user, user
8585 can only find it by guessing, and it does not seem important
8588 /* For each line spec given, delete bps which correspond
8589 to it. Do it in two passes, solely to preserve the current
8590 behavior that from_tty is forced true if we delete more than
8594 for (i
= 0; i
< sals
.nelts
; i
++)
8596 /* If exact pc given, clear bpts at that pc.
8597 If line given (pc == 0), clear all bpts on specified line.
8598 If defaulting, clear all bpts on default line
8601 defaulting sal.pc != 0 tests to do
8606 1 0 <can't happen> */
8610 /* Find all matching breakpoints and add them to
8615 /* Are we going to delete b? */
8616 if (b
->type
!= bp_none
8617 && b
->type
!= bp_watchpoint
8618 && b
->type
!= bp_hardware_watchpoint
8619 && b
->type
!= bp_read_watchpoint
8620 && b
->type
!= bp_access_watchpoint
)
8622 struct bp_location
*loc
= b
->loc
;
8623 for (; loc
; loc
= loc
->next
)
8625 int pc_match
= sal
.pc
8626 && (loc
->pspace
== sal
.pspace
)
8627 && (loc
->address
== sal
.pc
)
8628 && (!section_is_overlay (loc
->section
)
8629 || loc
->section
== sal
.section
);
8630 int line_match
= ((default_match
|| (0 == sal
.pc
))
8631 && b
->source_file
!= NULL
8632 && sal
.symtab
!= NULL
8633 && sal
.pspace
== loc
->pspace
8634 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8635 && b
->line_number
== sal
.line
);
8636 if (pc_match
|| line_match
)
8645 VEC_safe_push(breakpoint_p
, found
, b
);
8648 /* Now go thru the 'found' chain and delete them. */
8649 if (VEC_empty(breakpoint_p
, found
))
8652 error (_("No breakpoint at %s."), arg
);
8654 error (_("No breakpoint at this line."));
8657 if (VEC_length(breakpoint_p
, found
) > 1)
8658 from_tty
= 1; /* Always report if deleted more than one */
8661 if (VEC_length(breakpoint_p
, found
) == 1)
8662 printf_unfiltered (_("Deleted breakpoint "));
8664 printf_unfiltered (_("Deleted breakpoints "));
8666 breakpoints_changed ();
8668 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8671 printf_unfiltered ("%d ", b
->number
);
8672 delete_breakpoint (b
);
8675 putchar_unfiltered ('\n');
8678 /* Delete breakpoint in BS if they are `delete' breakpoints and
8679 all breakpoints that are marked for deletion, whether hit or not.
8680 This is called after any breakpoint is hit, or after errors. */
8683 breakpoint_auto_delete (bpstat bs
)
8685 struct breakpoint
*b
, *temp
;
8687 for (; bs
; bs
= bs
->next
)
8688 if (bs
->breakpoint_at
8689 && bs
->breakpoint_at
->owner
8690 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8692 delete_breakpoint (bs
->breakpoint_at
->owner
);
8694 ALL_BREAKPOINTS_SAFE (b
, temp
)
8696 if (b
->disposition
== disp_del_at_next_stop
)
8697 delete_breakpoint (b
);
8701 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8702 Sort elements primarily by their ADDRESS (no matter what does
8703 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8704 first bp_permanent OWNERed elements and terciarily just ensuring the array
8705 is sorted stable way despite qsort being an instable algorithm. */
8708 bp_location_compare (const void *ap
, const void *bp
)
8710 struct bp_location
*a
= *(void **) ap
;
8711 struct bp_location
*b
= *(void **) bp
;
8712 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8713 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8715 if (a
->address
!= b
->address
)
8716 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8718 /* Sort permanent breakpoints first. */
8719 if (a_perm
!= b_perm
)
8720 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8722 /* Make the user-visible order stable across GDB runs. Locations of the same
8723 breakpoint can be sorted in arbitrary order. */
8725 if (a
->owner
->number
!= b
->owner
->number
)
8726 return (a
->owner
->number
> b
->owner
->number
)
8727 - (a
->owner
->number
< b
->owner
->number
);
8729 return (a
> b
) - (a
< b
);
8732 /* Set bp_location_placed_address_before_address_max and
8733 bp_location_shadow_len_after_address_max according to the current content of
8734 the bp_location array. */
8737 bp_location_target_extensions_update (void)
8739 struct bp_location
*bl
, **blp_tmp
;
8741 bp_location_placed_address_before_address_max
= 0;
8742 bp_location_shadow_len_after_address_max
= 0;
8744 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8746 CORE_ADDR start
, end
, addr
;
8748 if (!bp_location_has_shadow (bl
))
8751 start
= bl
->target_info
.placed_address
;
8752 end
= start
+ bl
->target_info
.shadow_len
;
8754 gdb_assert (bl
->address
>= start
);
8755 addr
= bl
->address
- start
;
8756 if (addr
> bp_location_placed_address_before_address_max
)
8757 bp_location_placed_address_before_address_max
= addr
;
8759 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8761 gdb_assert (bl
->address
< end
);
8762 addr
= end
- bl
->address
;
8763 if (addr
> bp_location_shadow_len_after_address_max
)
8764 bp_location_shadow_len_after_address_max
= addr
;
8768 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8769 into the inferior, only remove already-inserted locations that no
8770 longer should be inserted. Functions that delete a breakpoint or
8771 breakpoints should pass false, so that deleting a breakpoint
8772 doesn't have the side effect of inserting the locations of other
8773 breakpoints that are marked not-inserted, but should_be_inserted
8774 returns true on them.
8776 This behaviour is useful is situations close to tear-down -- e.g.,
8777 after an exec, while the target still has execution, but breakpoint
8778 shadows of the previous executable image should *NOT* be restored
8779 to the new image; or before detaching, where the target still has
8780 execution and wants to delete breakpoints from GDB's lists, and all
8781 breakpoints had already been removed from the inferior. */
8784 update_global_location_list (int should_insert
)
8786 struct breakpoint
*b
;
8787 struct bp_location
**locp
, *loc
;
8788 struct cleanup
*cleanups
;
8790 /* Used in the duplicates detection below. When iterating over all
8791 bp_locations, points to the first bp_location of a given address.
8792 Breakpoints and watchpoints of different types are never
8793 duplicates of each other. Keep one pointer for each type of
8794 breakpoint/watchpoint, so we only need to loop over all locations
8796 struct bp_location
*bp_loc_first
; /* breakpoint */
8797 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8798 struct bp_location
*awp_loc_first
; /* access watchpoint */
8799 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8801 /* Saved former bp_location array which we compare against the newly built
8802 bp_location from the current state of ALL_BREAKPOINTS. */
8803 struct bp_location
**old_location
, **old_locp
;
8804 unsigned old_location_count
;
8806 old_location
= bp_location
;
8807 old_location_count
= bp_location_count
;
8809 bp_location_count
= 0;
8810 cleanups
= make_cleanup (xfree
, old_location
);
8813 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8814 bp_location_count
++;
8816 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8819 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8821 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8822 bp_location_compare
);
8824 bp_location_target_extensions_update ();
8826 /* Identify bp_location instances that are no longer present in the new
8827 list, and therefore should be freed. Note that it's not necessary that
8828 those locations should be removed from inferior -- if there's another
8829 location at the same address (previously marked as duplicate),
8830 we don't need to remove/insert the location.
8832 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8833 former bp_location array state respectively. */
8836 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8839 struct bp_location
*old_loc
= *old_locp
;
8840 struct bp_location
**loc2p
;
8842 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8844 int found_object
= 0;
8845 /* Tells if the location should remain inserted in the target. */
8846 int keep_in_target
= 0;
8849 /* Skip LOCP entries which will definitely never be needed. Stop either
8850 at or being the one matching OLD_LOC. */
8851 while (locp
< bp_location
+ bp_location_count
8852 && (*locp
)->address
< old_loc
->address
)
8856 (loc2p
< bp_location
+ bp_location_count
8857 && (*loc2p
)->address
== old_loc
->address
);
8860 if (*loc2p
== old_loc
)
8867 /* If this location is no longer present, and inserted, look if there's
8868 maybe a new location at the same address. If so, mark that one
8869 inserted, and don't remove this one. This is needed so that we
8870 don't have a time window where a breakpoint at certain location is not
8873 if (old_loc
->inserted
)
8875 /* If the location is inserted now, we might have to remove it. */
8877 if (found_object
&& should_be_inserted (old_loc
))
8879 /* The location is still present in the location list, and still
8880 should be inserted. Don't do anything. */
8885 /* The location is either no longer present, or got disabled.
8886 See if there's another location at the same address, in which
8887 case we don't need to remove this one from the target. */
8889 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8892 (loc2p
< bp_location
+ bp_location_count
8893 && (*loc2p
)->address
== old_loc
->address
);
8896 struct bp_location
*loc2
= *loc2p
;
8898 if (breakpoint_locations_match (loc2
, old_loc
))
8900 /* For the sake of should_be_inserted.
8901 Duplicates check below will fix up this later. */
8902 loc2
->duplicate
= 0;
8904 /* Read watchpoint locations are switched to
8905 access watchpoints, if the former are not
8906 supported, but the latter are. */
8907 if (is_hardware_watchpoint (old_loc
->owner
))
8909 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8910 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8913 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8916 loc2
->target_info
= old_loc
->target_info
;
8925 if (!keep_in_target
)
8927 if (remove_breakpoint (old_loc
, mark_uninserted
))
8929 /* This is just about all we can do. We could keep this
8930 location on the global list, and try to remove it next
8931 time, but there's no particular reason why we will
8934 Note that at this point, old_loc->owner is still valid,
8935 as delete_breakpoint frees the breakpoint only
8936 after calling us. */
8937 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8938 old_loc
->owner
->number
);
8946 if (removed
&& non_stop
8947 && breakpoint_address_is_meaningful (old_loc
->owner
)
8948 && !is_hardware_watchpoint (old_loc
->owner
))
8950 /* This location was removed from the target. In
8951 non-stop mode, a race condition is possible where
8952 we've removed a breakpoint, but stop events for that
8953 breakpoint are already queued and will arrive later.
8954 We apply an heuristic to be able to distinguish such
8955 SIGTRAPs from other random SIGTRAPs: we keep this
8956 breakpoint location for a bit, and will retire it
8957 after we see some number of events. The theory here
8958 is that reporting of events should, "on the average",
8959 be fair, so after a while we'll see events from all
8960 threads that have anything of interest, and no longer
8961 need to keep this breakpoint location around. We
8962 don't hold locations forever so to reduce chances of
8963 mistaking a non-breakpoint SIGTRAP for a breakpoint
8966 The heuristic failing can be disastrous on
8967 decr_pc_after_break targets.
8969 On decr_pc_after_break targets, like e.g., x86-linux,
8970 if we fail to recognize a late breakpoint SIGTRAP,
8971 because events_till_retirement has reached 0 too
8972 soon, we'll fail to do the PC adjustment, and report
8973 a random SIGTRAP to the user. When the user resumes
8974 the inferior, it will most likely immediately crash
8975 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
8976 corrupted, because of being resumed e.g., in the
8977 middle of a multi-byte instruction, or skipped a
8978 one-byte instruction. This was actually seen happen
8979 on native x86-linux, and should be less rare on
8980 targets that do not support new thread events, like
8981 remote, due to the heuristic depending on
8984 Mistaking a random SIGTRAP for a breakpoint trap
8985 causes similar symptoms (PC adjustment applied when
8986 it shouldn't), but then again, playing with SIGTRAPs
8987 behind the debugger's back is asking for trouble.
8989 Since hardware watchpoint traps are always
8990 distinguishable from other traps, so we don't need to
8991 apply keep hardware watchpoint moribund locations
8992 around. We simply always ignore hardware watchpoint
8993 traps we can no longer explain. */
8995 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
8996 old_loc
->owner
= NULL
;
8998 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9001 free_bp_location (old_loc
);
9005 /* Rescan breakpoints at the same address and section, marking the
9006 first one as "first" and any others as "duplicates". This is so
9007 that the bpt instruction is only inserted once. If we have a
9008 permanent breakpoint at the same place as BPT, make that one the
9009 official one, and the rest as duplicates. Permanent breakpoints
9010 are sorted first for the same address.
9012 Do the same for hardware watchpoints, but also considering the
9013 watchpoint's type (regular/access/read) and length. */
9015 bp_loc_first
= NULL
;
9016 wp_loc_first
= NULL
;
9017 awp_loc_first
= NULL
;
9018 rwp_loc_first
= NULL
;
9019 ALL_BP_LOCATIONS (loc
, locp
)
9021 struct breakpoint
*b
= loc
->owner
;
9022 struct bp_location
**loc_first_p
;
9024 if (b
->enable_state
== bp_disabled
9025 || b
->enable_state
== bp_call_disabled
9026 || b
->enable_state
== bp_startup_disabled
9028 || loc
->shlib_disabled
9029 || !breakpoint_address_is_meaningful (b
)
9030 || tracepoint_type (b
))
9033 /* Permanent breakpoint should always be inserted. */
9034 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9035 internal_error (__FILE__
, __LINE__
,
9036 _("allegedly permanent breakpoint is not "
9037 "actually inserted"));
9039 if (b
->type
== bp_hardware_watchpoint
)
9040 loc_first_p
= &wp_loc_first
;
9041 else if (b
->type
== bp_read_watchpoint
)
9042 loc_first_p
= &rwp_loc_first
;
9043 else if (b
->type
== bp_access_watchpoint
)
9044 loc_first_p
= &awp_loc_first
;
9046 loc_first_p
= &bp_loc_first
;
9048 if (*loc_first_p
== NULL
9049 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9050 || !breakpoint_locations_match (loc
, *loc_first_p
))
9059 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9060 && b
->enable_state
!= bp_permanent
)
9061 internal_error (__FILE__
, __LINE__
,
9062 _("another breakpoint was inserted on top of "
9063 "a permanent breakpoint"));
9066 if (breakpoints_always_inserted_mode () && should_insert
9067 && (have_live_inferiors ()
9068 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9069 insert_breakpoint_locations ();
9071 do_cleanups (cleanups
);
9075 breakpoint_retire_moribund (void)
9077 struct bp_location
*loc
;
9080 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9081 if (--(loc
->events_till_retirement
) == 0)
9083 free_bp_location (loc
);
9084 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9090 update_global_location_list_nothrow (int inserting
)
9092 struct gdb_exception e
;
9093 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9094 update_global_location_list (inserting
);
9097 /* Clear BPT from a BPS. */
9099 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9102 for (bs
= bps
; bs
; bs
= bs
->next
)
9103 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9105 bs
->breakpoint_at
= NULL
;
9107 /* bs->commands will be freed later. */
9111 /* Callback for iterate_over_threads. */
9113 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9115 struct breakpoint
*bpt
= data
;
9116 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9120 /* Delete a breakpoint and clean up all traces of it in the data
9124 delete_breakpoint (struct breakpoint
*bpt
)
9126 struct breakpoint
*b
;
9127 struct bp_location
*loc
, *next
;
9129 gdb_assert (bpt
!= NULL
);
9131 /* Has this bp already been deleted? This can happen because multiple
9132 lists can hold pointers to bp's. bpstat lists are especial culprits.
9134 One example of this happening is a watchpoint's scope bp. When the
9135 scope bp triggers, we notice that the watchpoint is out of scope, and
9136 delete it. We also delete its scope bp. But the scope bp is marked
9137 "auto-deleting", and is already on a bpstat. That bpstat is then
9138 checked for auto-deleting bp's, which are deleted.
9140 A real solution to this problem might involve reference counts in bp's,
9141 and/or giving them pointers back to their referencing bpstat's, and
9142 teaching delete_breakpoint to only free a bp's storage when no more
9143 references were extent. A cheaper bandaid was chosen. */
9144 if (bpt
->type
== bp_none
)
9147 /* At least avoid this stale reference until the reference counting of
9148 breakpoints gets resolved. */
9149 if (bpt
->related_breakpoint
!= NULL
)
9151 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9152 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9153 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9154 bpt
->related_breakpoint
= NULL
;
9157 observer_notify_breakpoint_deleted (bpt
->number
);
9159 if (breakpoint_chain
== bpt
)
9160 breakpoint_chain
= bpt
->next
;
9165 b
->next
= bpt
->next
;
9169 decref_counted_command_line (&bpt
->commands
);
9170 xfree (bpt
->cond_string
);
9171 xfree (bpt
->cond_exp
);
9172 xfree (bpt
->addr_string
);
9174 xfree (bpt
->exp_string
);
9175 value_free (bpt
->val
);
9176 xfree (bpt
->source_file
);
9177 xfree (bpt
->exec_pathname
);
9178 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9180 /* Be sure no bpstat's are pointing at it after it's been freed. */
9181 /* FIXME, how can we find all bpstat's?
9182 We just check stop_bpstat for now. Note that we cannot just
9183 remove bpstats pointing at bpt from the stop_bpstat list
9184 entirely, as breakpoint commands are associated with the bpstat;
9185 if we remove it here, then the later call to
9186 bpstat_do_actions (&stop_bpstat);
9187 in event-top.c won't do anything, and temporary breakpoints
9188 with commands won't work. */
9190 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9192 /* Now that breakpoint is removed from breakpoint
9193 list, update the global location list. This
9194 will remove locations that used to belong to
9195 this breakpoint. Do this before freeing
9196 the breakpoint itself, since remove_breakpoint
9197 looks at location's owner. It might be better
9198 design to have location completely self-contained,
9199 but it's not the case now. */
9200 update_global_location_list (0);
9203 /* On the chance that someone will soon try again to delete this same
9204 bp, we mark it as deleted before freeing its storage. */
9205 bpt
->type
= bp_none
;
9211 do_delete_breakpoint_cleanup (void *b
)
9213 delete_breakpoint (b
);
9217 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9219 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9222 /* A callback for map_breakpoint_numbers that calls
9223 delete_breakpoint. */
9226 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9228 delete_breakpoint (b
);
9232 delete_command (char *arg
, int from_tty
)
9234 struct breakpoint
*b
, *temp
;
9240 int breaks_to_delete
= 0;
9242 /* Delete all breakpoints if no argument.
9243 Do not delete internal or call-dummy breakpoints, these
9244 have to be deleted with an explicit breakpoint number argument. */
9247 if (b
->type
!= bp_call_dummy
9248 && b
->type
!= bp_std_terminate
9249 && b
->type
!= bp_shlib_event
9250 && b
->type
!= bp_jit_event
9251 && b
->type
!= bp_thread_event
9252 && b
->type
!= bp_overlay_event
9253 && b
->type
!= bp_longjmp_master
9254 && b
->type
!= bp_std_terminate_master
9257 breaks_to_delete
= 1;
9262 /* Ask user only if there are some breakpoints to delete. */
9264 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9266 ALL_BREAKPOINTS_SAFE (b
, temp
)
9268 if (b
->type
!= bp_call_dummy
9269 && b
->type
!= bp_std_terminate
9270 && b
->type
!= bp_shlib_event
9271 && b
->type
!= bp_thread_event
9272 && b
->type
!= bp_jit_event
9273 && b
->type
!= bp_overlay_event
9274 && b
->type
!= bp_longjmp_master
9275 && b
->type
!= bp_std_terminate_master
9277 delete_breakpoint (b
);
9282 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9286 all_locations_are_pending (struct bp_location
*loc
)
9288 for (; loc
; loc
= loc
->next
)
9289 if (!loc
->shlib_disabled
)
9294 /* Subroutine of update_breakpoint_locations to simplify it.
9295 Return non-zero if multiple fns in list LOC have the same name.
9296 Null names are ignored. */
9299 ambiguous_names_p (struct bp_location
*loc
)
9301 struct bp_location
*l
;
9302 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9303 (int (*) (const void *, const void *)) streq
,
9304 NULL
, xcalloc
, xfree
);
9306 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9309 const char *name
= l
->function_name
;
9311 /* Allow for some names to be NULL, ignore them. */
9315 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9317 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9332 update_breakpoint_locations (struct breakpoint
*b
,
9333 struct symtabs_and_lines sals
)
9337 struct bp_location
*existing_locations
= b
->loc
;
9339 /* If there's no new locations, and all existing locations
9340 are pending, don't do anything. This optimizes
9341 the common case where all locations are in the same
9342 shared library, that was unloaded. We'd like to
9343 retain the location, so that when the library
9344 is loaded again, we don't loose the enabled/disabled
9345 status of the individual locations. */
9346 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9351 for (i
= 0; i
< sals
.nelts
; ++i
)
9353 struct bp_location
*new_loc
=
9354 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9356 /* Reparse conditions, they might contain references to the
9358 if (b
->cond_string
!= NULL
)
9360 struct gdb_exception e
;
9363 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9365 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9370 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9371 b
->number
, e
.message
);
9372 new_loc
->enabled
= 0;
9376 if (b
->source_file
!= NULL
)
9377 xfree (b
->source_file
);
9378 if (sals
.sals
[i
].symtab
== NULL
)
9379 b
->source_file
= NULL
;
9381 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9383 if (b
->line_number
== 0)
9384 b
->line_number
= sals
.sals
[i
].line
;
9387 /* Update locations of permanent breakpoints. */
9388 if (b
->enable_state
== bp_permanent
)
9389 make_breakpoint_permanent (b
);
9391 /* If possible, carry over 'disable' status from existing breakpoints. */
9393 struct bp_location
*e
= existing_locations
;
9394 /* If there are multiple breakpoints with the same function name,
9395 e.g. for inline functions, comparing function names won't work.
9396 Instead compare pc addresses; this is just a heuristic as things
9397 may have moved, but in practice it gives the correct answer
9398 often enough until a better solution is found. */
9399 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9401 for (; e
; e
= e
->next
)
9403 if (!e
->enabled
&& e
->function_name
)
9405 struct bp_location
*l
= b
->loc
;
9406 if (have_ambiguous_names
)
9408 for (; l
; l
= l
->next
)
9409 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9410 l
->pspace
->aspace
, l
->address
))
9418 for (; l
; l
= l
->next
)
9419 if (l
->function_name
9420 && strcmp (e
->function_name
, l
->function_name
) == 0)
9430 update_global_location_list (1);
9434 /* Reset a breakpoint given it's struct breakpoint * BINT.
9435 The value we return ends up being the return value from catch_errors.
9436 Unused in this case. */
9439 breakpoint_re_set_one (void *bint
)
9441 /* get past catch_errs */
9442 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9446 int *not_found_ptr
= ¬_found
;
9447 struct symtabs_and_lines sals
= {0};
9448 struct symtabs_and_lines expanded
= {0};
9450 enum enable_state save_enable
;
9451 struct gdb_exception e
;
9452 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9457 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9461 case bp_hardware_breakpoint
:
9463 case bp_fast_tracepoint
:
9464 /* Do not attempt to re-set breakpoints disabled during startup. */
9465 if (b
->enable_state
== bp_startup_disabled
)
9468 if (b
->addr_string
== NULL
)
9470 /* Anything without a string can't be re-set. */
9471 delete_breakpoint (b
);
9475 set_language (b
->language
);
9476 input_radix
= b
->input_radix
;
9479 save_current_space_and_thread ();
9480 switch_to_program_space_and_thread (b
->pspace
);
9482 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9484 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9489 int not_found_and_ok
= 0;
9490 /* For pending breakpoints, it's expected that parsing
9491 will fail until the right shared library is loaded.
9492 User has already told to create pending breakpoints and
9493 don't need extra messages. If breakpoint is in bp_shlib_disabled
9494 state, then user already saw the message about that breakpoint
9495 being disabled, and don't want to see more errors. */
9497 && (b
->condition_not_parsed
9498 || (b
->loc
&& b
->loc
->shlib_disabled
)
9499 || b
->enable_state
== bp_disabled
))
9500 not_found_and_ok
= 1;
9502 if (!not_found_and_ok
)
9504 /* We surely don't want to warn about the same breakpoint
9505 10 times. One solution, implemented here, is disable
9506 the breakpoint on error. Another solution would be to
9507 have separate 'warning emitted' flag. Since this
9508 happens only when a binary has changed, I don't know
9509 which approach is better. */
9510 b
->enable_state
= bp_disabled
;
9511 throw_exception (e
);
9517 gdb_assert (sals
.nelts
== 1);
9519 resolve_sal_pc (&sals
.sals
[0]);
9520 if (b
->condition_not_parsed
&& s
&& s
[0])
9522 char *cond_string
= 0;
9526 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9527 &cond_string
, &thread
, &task
);
9529 b
->cond_string
= cond_string
;
9532 b
->condition_not_parsed
= 0;
9535 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9538 make_cleanup (xfree
, sals
.sals
);
9539 update_breakpoint_locations (b
, expanded
);
9543 case bp_hardware_watchpoint
:
9544 case bp_read_watchpoint
:
9545 case bp_access_watchpoint
:
9546 /* Watchpoint can be either on expression using entirely global variables,
9547 or it can be on local variables.
9549 Watchpoints of the first kind are never auto-deleted, and even persist
9550 across program restarts. Since they can use variables from shared
9551 libraries, we need to reparse expression as libraries are loaded
9554 Watchpoints on local variables can also change meaning as result
9555 of solib event. For example, if a watchpoint uses both a local and
9556 a global variables in expression, it's a local watchpoint, but
9557 unloading of a shared library will make the expression invalid.
9558 This is not a very common use case, but we still re-evaluate
9559 expression, to avoid surprises to the user.
9561 Note that for local watchpoints, we re-evaluate it only if
9562 watchpoints frame id is still valid. If it's not, it means
9563 the watchpoint is out of scope and will be deleted soon. In fact,
9564 I'm not sure we'll ever be called in this case.
9566 If a local watchpoint's frame id is still valid, then
9567 b->exp_valid_block is likewise valid, and we can safely use it.
9569 Don't do anything about disabled watchpoints, since they will
9570 be reevaluated again when enabled. */
9571 update_watchpoint (b
, 1 /* reparse */);
9573 /* We needn't really do anything to reset these, since the mask
9574 that requests them is unaffected by e.g., new libraries being
9580 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9582 /* Delete overlay event and longjmp master breakpoints; they will be
9583 reset later by breakpoint_re_set. */
9584 case bp_overlay_event
:
9585 case bp_longjmp_master
:
9586 case bp_std_terminate_master
:
9587 delete_breakpoint (b
);
9590 /* This breakpoint is special, it's set up when the inferior
9591 starts and we really don't want to touch it. */
9592 case bp_shlib_event
:
9594 /* Like bp_shlib_event, this breakpoint type is special.
9595 Once it is set up, we do not want to touch it. */
9596 case bp_thread_event
:
9598 /* Keep temporary breakpoints, which can be encountered when we step
9599 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9600 Otherwise these should have been blown away via the cleanup chain
9601 or by breakpoint_init_inferior when we rerun the executable. */
9604 case bp_watchpoint_scope
:
9606 case bp_std_terminate
:
9607 case bp_step_resume
:
9609 case bp_longjmp_resume
:
9614 do_cleanups (cleanups
);
9618 /* Re-set all breakpoints after symbols have been re-loaded. */
9620 breakpoint_re_set (void)
9622 struct breakpoint
*b
, *temp
;
9623 enum language save_language
;
9624 int save_input_radix
;
9625 struct cleanup
*old_chain
;
9627 save_language
= current_language
->la_language
;
9628 save_input_radix
= input_radix
;
9629 old_chain
= save_current_program_space ();
9631 ALL_BREAKPOINTS_SAFE (b
, temp
)
9633 /* Format possible error msg */
9634 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9636 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9637 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9638 do_cleanups (cleanups
);
9640 set_language (save_language
);
9641 input_radix
= save_input_radix
;
9643 jit_breakpoint_re_set ();
9645 do_cleanups (old_chain
);
9647 create_overlay_event_breakpoint ("_ovly_debug_event");
9648 create_longjmp_master_breakpoint ("longjmp");
9649 create_longjmp_master_breakpoint ("_longjmp");
9650 create_longjmp_master_breakpoint ("siglongjmp");
9651 create_longjmp_master_breakpoint ("_siglongjmp");
9652 create_std_terminate_master_breakpoint ("std::terminate()");
9655 /* Reset the thread number of this breakpoint:
9657 - If the breakpoint is for all threads, leave it as-is.
9658 - Else, reset it to the current thread for inferior_ptid. */
9660 breakpoint_re_set_thread (struct breakpoint
*b
)
9662 if (b
->thread
!= -1)
9664 if (in_thread_list (inferior_ptid
))
9665 b
->thread
= pid_to_thread_id (inferior_ptid
);
9667 /* We're being called after following a fork. The new fork is
9668 selected as current, and unless this was a vfork will have a
9669 different program space from the original thread. Reset that
9671 b
->loc
->pspace
= current_program_space
;
9675 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9676 If from_tty is nonzero, it prints a message to that effect,
9677 which ends with a period (no newline). */
9680 set_ignore_count (int bptnum
, int count
, int from_tty
)
9682 struct breakpoint
*b
;
9688 if (b
->number
== bptnum
)
9690 b
->ignore_count
= count
;
9694 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9696 else if (count
== 1)
9697 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9700 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9703 breakpoints_changed ();
9704 observer_notify_breakpoint_modified (b
->number
);
9708 error (_("No breakpoint number %d."), bptnum
);
9712 make_breakpoint_silent (struct breakpoint
*b
)
9714 /* Silence the breakpoint. */
9718 /* Command to set ignore-count of breakpoint N to COUNT. */
9721 ignore_command (char *args
, int from_tty
)
9727 error_no_arg (_("a breakpoint number"));
9729 num
= get_number (&p
);
9731 error (_("bad breakpoint number: '%s'"), args
);
9733 error (_("Second argument (specified ignore-count) is missing."));
9735 set_ignore_count (num
,
9736 longest_to_int (value_as_long (parse_and_eval (p
))),
9739 printf_filtered ("\n");
9742 /* Call FUNCTION on each of the breakpoints
9743 whose numbers are given in ARGS. */
9746 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9753 struct breakpoint
*b
, *tmp
;
9757 error_no_arg (_("one or more breakpoint numbers"));
9764 num
= get_number_or_range (&p1
);
9767 warning (_("bad breakpoint number at or near '%s'"), p
);
9771 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9772 if (b
->number
== num
)
9774 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9777 if (related_breakpoint
)
9778 function (related_breakpoint
, data
);
9782 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9788 static struct bp_location
*
9789 find_location_by_number (char *number
)
9791 char *dot
= strchr (number
, '.');
9795 struct breakpoint
*b
;
9796 struct bp_location
*loc
;
9801 bp_num
= get_number_or_range (&p1
);
9803 error (_("Bad breakpoint number '%s'"), number
);
9806 if (b
->number
== bp_num
)
9811 if (!b
|| b
->number
!= bp_num
)
9812 error (_("Bad breakpoint number '%s'"), number
);
9815 loc_num
= get_number_or_range (&p1
);
9817 error (_("Bad breakpoint location number '%s'"), number
);
9821 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9824 error (_("Bad breakpoint location number '%s'"), dot
+1);
9830 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9831 If from_tty is nonzero, it prints a message to that effect,
9832 which ends with a period (no newline). */
9835 disable_breakpoint (struct breakpoint
*bpt
)
9837 /* Never disable a watchpoint scope breakpoint; we want to
9838 hit them when we leave scope so we can delete both the
9839 watchpoint and its scope breakpoint at that time. */
9840 if (bpt
->type
== bp_watchpoint_scope
)
9843 /* You can't disable permanent breakpoints. */
9844 if (bpt
->enable_state
== bp_permanent
)
9847 bpt
->enable_state
= bp_disabled
;
9849 update_global_location_list (0);
9851 observer_notify_breakpoint_modified (bpt
->number
);
9854 /* A callback for map_breakpoint_numbers that calls
9855 disable_breakpoint. */
9858 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9860 disable_breakpoint (b
);
9864 disable_command (char *args
, int from_tty
)
9866 struct breakpoint
*bpt
;
9868 ALL_BREAKPOINTS (bpt
)
9872 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9877 case bp_fast_tracepoint
:
9879 case bp_hardware_breakpoint
:
9881 case bp_hardware_watchpoint
:
9882 case bp_read_watchpoint
:
9883 case bp_access_watchpoint
:
9884 disable_breakpoint (bpt
);
9888 else if (strchr (args
, '.'))
9890 struct bp_location
*loc
= find_location_by_number (args
);
9893 update_global_location_list (0);
9896 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
9900 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9902 int target_resources_ok
, other_type_used
;
9905 if (bpt
->type
== bp_hardware_breakpoint
)
9908 i
= hw_breakpoint_used_count ();
9909 target_resources_ok
=
9910 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9912 if (target_resources_ok
== 0)
9913 error (_("No hardware breakpoint support in the target."));
9914 else if (target_resources_ok
< 0)
9915 error (_("Hardware breakpoints used exceeds limit."));
9918 if (bpt
->type
== bp_watchpoint
9919 || bpt
->type
== bp_hardware_watchpoint
9920 || bpt
->type
== bp_read_watchpoint
9921 || bpt
->type
== bp_access_watchpoint
)
9923 struct gdb_exception e
;
9925 TRY_CATCH (e
, RETURN_MASK_ALL
)
9927 update_watchpoint (bpt
, 1 /* reparse */);
9931 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9937 if (bpt
->enable_state
!= bp_permanent
)
9938 bpt
->enable_state
= bp_enabled
;
9939 bpt
->disposition
= disposition
;
9940 update_global_location_list (1);
9941 breakpoints_changed ();
9943 observer_notify_breakpoint_modified (bpt
->number
);
9948 enable_breakpoint (struct breakpoint
*bpt
)
9950 do_enable_breakpoint (bpt
, bpt
->disposition
);
9953 /* A callback for map_breakpoint_numbers that calls
9954 enable_breakpoint. */
9957 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
9959 enable_breakpoint (b
);
9962 /* The enable command enables the specified breakpoints (or all defined
9963 breakpoints) so they once again become (or continue to be) effective
9964 in stopping the inferior. */
9967 enable_command (char *args
, int from_tty
)
9969 struct breakpoint
*bpt
;
9971 ALL_BREAKPOINTS (bpt
)
9975 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
9980 case bp_fast_tracepoint
:
9982 case bp_hardware_breakpoint
:
9984 case bp_hardware_watchpoint
:
9985 case bp_read_watchpoint
:
9986 case bp_access_watchpoint
:
9987 enable_breakpoint (bpt
);
9991 else if (strchr (args
, '.'))
9993 struct bp_location
*loc
= find_location_by_number (args
);
9996 update_global_location_list (1);
9999 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10003 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10005 do_enable_breakpoint (bpt
, disp_disable
);
10009 enable_once_command (char *args
, int from_tty
)
10011 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10015 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10017 do_enable_breakpoint (bpt
, disp_del
);
10021 enable_delete_command (char *args
, int from_tty
)
10023 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10027 set_breakpoint_cmd (char *args
, int from_tty
)
10032 show_breakpoint_cmd (char *args
, int from_tty
)
10036 /* Invalidate last known value of any hardware watchpoint if
10037 the memory which that value represents has been written to by
10041 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10042 const bfd_byte
*data
)
10044 struct breakpoint
*bp
;
10046 ALL_BREAKPOINTS (bp
)
10047 if (bp
->enable_state
== bp_enabled
10048 && bp
->type
== bp_hardware_watchpoint
10049 && bp
->val_valid
&& bp
->val
)
10051 struct bp_location
*loc
;
10053 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10054 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10055 && loc
->address
+ loc
->length
> addr
10056 && addr
+ len
> loc
->address
)
10058 value_free (bp
->val
);
10065 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10067 struct symtabs_and_lines
10068 decode_line_spec_1 (char *string
, int funfirstline
)
10070 struct symtabs_and_lines sals
;
10072 error (_("Empty line specification."));
10073 if (default_breakpoint_valid
)
10074 sals
= decode_line_1 (&string
, funfirstline
,
10075 default_breakpoint_symtab
,
10076 default_breakpoint_line
,
10077 (char ***) NULL
, NULL
);
10079 sals
= decode_line_1 (&string
, funfirstline
,
10080 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10082 error (_("Junk at end of line specification: %s"), string
);
10086 /* Create and insert a raw software breakpoint at PC. Return an
10087 identifier, which should be used to remove the breakpoint later.
10088 In general, places which call this should be using something on the
10089 breakpoint chain instead; this function should be eliminated
10093 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10094 struct address_space
*aspace
, CORE_ADDR pc
)
10096 struct bp_target_info
*bp_tgt
;
10098 bp_tgt
= XZALLOC (struct bp_target_info
);
10100 bp_tgt
->placed_address_space
= aspace
;
10101 bp_tgt
->placed_address
= pc
;
10103 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10105 /* Could not insert the breakpoint. */
10113 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10116 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10118 struct bp_target_info
*bp_tgt
= bp
;
10121 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10127 /* One (or perhaps two) breakpoints used for software single stepping. */
10129 static void *single_step_breakpoints
[2];
10130 static struct gdbarch
*single_step_gdbarch
[2];
10132 /* Create and insert a breakpoint for software single step. */
10135 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10136 struct address_space
*aspace
, CORE_ADDR next_pc
)
10140 if (single_step_breakpoints
[0] == NULL
)
10142 bpt_p
= &single_step_breakpoints
[0];
10143 single_step_gdbarch
[0] = gdbarch
;
10147 gdb_assert (single_step_breakpoints
[1] == NULL
);
10148 bpt_p
= &single_step_breakpoints
[1];
10149 single_step_gdbarch
[1] = gdbarch
;
10152 /* NOTE drow/2006-04-11: A future improvement to this function would be
10153 to only create the breakpoints once, and actually put them on the
10154 breakpoint chain. That would let us use set_raw_breakpoint. We could
10155 adjust the addresses each time they were needed. Doing this requires
10156 corresponding changes elsewhere where single step breakpoints are
10157 handled, however. So, for now, we use this. */
10159 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10160 if (*bpt_p
== NULL
)
10161 error (_("Could not insert single-step breakpoint at %s"),
10162 paddress (gdbarch
, next_pc
));
10165 /* Remove and delete any breakpoints used for software single step. */
10168 remove_single_step_breakpoints (void)
10170 gdb_assert (single_step_breakpoints
[0] != NULL
);
10172 /* See insert_single_step_breakpoint for more about this deprecated
10174 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10175 single_step_breakpoints
[0]);
10176 single_step_gdbarch
[0] = NULL
;
10177 single_step_breakpoints
[0] = NULL
;
10179 if (single_step_breakpoints
[1] != NULL
)
10181 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10182 single_step_breakpoints
[1]);
10183 single_step_gdbarch
[1] = NULL
;
10184 single_step_breakpoints
[1] = NULL
;
10188 /* Check whether a software single-step breakpoint is inserted at PC. */
10191 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10195 for (i
= 0; i
< 2; i
++)
10197 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10199 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10200 bp_tgt
->placed_address
,
10208 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10209 non-zero otherwise. */
10211 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10213 if (syscall_catchpoint_p (bp
)
10214 && bp
->enable_state
!= bp_disabled
10215 && bp
->enable_state
!= bp_call_disabled
)
10222 catch_syscall_enabled (void)
10224 struct inferior
*inf
= current_inferior ();
10226 return inf
->total_syscalls_count
!= 0;
10230 catching_syscall_number (int syscall_number
)
10232 struct breakpoint
*bp
;
10234 ALL_BREAKPOINTS (bp
)
10235 if (is_syscall_catchpoint_enabled (bp
))
10237 if (bp
->syscalls_to_be_caught
)
10241 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10243 if (syscall_number
== iter
)
10253 /* Complete syscall names. Used by "catch syscall". */
10255 catch_syscall_completer (struct cmd_list_element
*cmd
,
10256 char *text
, char *word
)
10258 const char **list
= get_syscall_names ();
10259 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10262 /* Tracepoint-specific operations. */
10264 /* Set tracepoint count to NUM. */
10266 set_tracepoint_count (int num
)
10268 tracepoint_count
= num
;
10269 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10273 trace_command (char *arg
, int from_tty
)
10275 if (create_breakpoint (get_current_arch (),
10277 NULL
, 0, 1 /* parse arg */,
10278 0 /* tempflag */, 0 /* hardwareflag */,
10280 0 /* Ignore count */,
10281 pending_break_support
,
10285 set_tracepoint_count (breakpoint_count
);
10289 ftrace_command (char *arg
, int from_tty
)
10291 if (create_breakpoint (get_current_arch (),
10293 NULL
, 0, 1 /* parse arg */,
10294 0 /* tempflag */, 1 /* hardwareflag */,
10296 0 /* Ignore count */,
10297 pending_break_support
,
10301 set_tracepoint_count (breakpoint_count
);
10304 /* Given information about a tracepoint as recorded on a target (which
10305 can be either a live system or a trace file), attempt to create an
10306 equivalent GDB tracepoint. This is not a reliable process, since
10307 the target does not necessarily have all the information used when
10308 the tracepoint was originally defined. */
10310 struct breakpoint
*
10311 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10314 struct breakpoint
*tp
;
10316 /* In the absence of a source location, fall back to raw address. */
10317 sprintf (buf
, "*%s", paddress (get_current_arch(), utp
->addr
));
10319 if (!create_breakpoint (get_current_arch (),
10321 NULL
, 0, 1 /* parse arg */,
10323 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10325 0 /* Ignore count */,
10326 pending_break_support
,
10329 utp
->enabled
/* enabled */))
10332 set_tracepoint_count (breakpoint_count
);
10334 tp
= get_tracepoint (tracepoint_count
);
10335 gdb_assert (tp
!= NULL
);
10339 sprintf (buf
, "%d %d", utp
->pass
, tp
->number
);
10341 trace_pass_command (buf
, 0);
10346 printf_filtered ("Want to restore a condition\n");
10349 if (utp
->numactions
> 0)
10351 printf_filtered ("Want to restore action list\n");
10354 if (utp
->num_step_actions
> 0)
10356 printf_filtered ("Want to restore action list\n");
10362 /* Print information on tracepoint number TPNUM_EXP, or all if
10366 tracepoints_info (char *tpnum_exp
, int from_tty
)
10368 struct breakpoint
*b
;
10369 int tps_to_list
= 0;
10371 /* In the no-arguments case, say "No tracepoints" if none found. */
10372 if (tpnum_exp
== 0)
10374 ALL_TRACEPOINTS (b
)
10376 if (b
->number
>= 0)
10384 ui_out_message (uiout
, 0, "No tracepoints.\n");
10389 /* Otherwise be the same as "info break". */
10390 breakpoints_info (tpnum_exp
, from_tty
);
10393 /* The 'enable trace' command enables tracepoints.
10394 Not supported by all targets. */
10396 enable_trace_command (char *args
, int from_tty
)
10398 enable_command (args
, from_tty
);
10401 /* The 'disable trace' command disables tracepoints.
10402 Not supported by all targets. */
10404 disable_trace_command (char *args
, int from_tty
)
10406 disable_command (args
, from_tty
);
10409 /* Remove a tracepoint (or all if no argument) */
10411 delete_trace_command (char *arg
, int from_tty
)
10413 struct breakpoint
*b
, *temp
;
10419 int breaks_to_delete
= 0;
10421 /* Delete all breakpoints if no argument.
10422 Do not delete internal or call-dummy breakpoints, these
10423 have to be deleted with an explicit breakpoint number argument. */
10424 ALL_TRACEPOINTS (b
)
10426 if (b
->number
>= 0)
10428 breaks_to_delete
= 1;
10433 /* Ask user only if there are some breakpoints to delete. */
10435 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10437 ALL_BREAKPOINTS_SAFE (b
, temp
)
10439 if (tracepoint_type (b
)
10441 delete_breakpoint (b
);
10446 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10449 /* Set passcount for tracepoint.
10451 First command argument is passcount, second is tracepoint number.
10452 If tracepoint number omitted, apply to most recently defined.
10453 Also accepts special argument "all". */
10456 trace_pass_command (char *args
, int from_tty
)
10458 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10459 unsigned int count
;
10462 if (args
== 0 || *args
== 0)
10463 error (_("passcount command requires an argument (count + optional TP num)"));
10465 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10467 while (*args
&& isspace ((int) *args
))
10470 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10472 args
+= 3; /* Skip special argument "all". */
10475 error (_("Junk at end of arguments."));
10478 t1
= get_tracepoint_by_number (&args
, 1, 1);
10484 ALL_TRACEPOINTS (t2
)
10485 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10487 t2
->pass_count
= count
;
10488 observer_notify_tracepoint_modified (t2
->number
);
10490 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10491 t2
->number
, count
);
10493 if (! all
&& *args
)
10494 t1
= get_tracepoint_by_number (&args
, 1, 0);
10500 struct breakpoint
*
10501 get_tracepoint (int num
)
10503 struct breakpoint
*t
;
10505 ALL_TRACEPOINTS (t
)
10506 if (t
->number
== num
)
10512 /* Find the tracepoint with the given target-side number (which may be
10513 different from the tracepoint number after disconnecting and
10516 struct breakpoint
*
10517 get_tracepoint_by_number_on_target (int num
)
10519 struct breakpoint
*t
;
10521 ALL_TRACEPOINTS (t
)
10522 if (t
->number_on_target
== num
)
10528 /* Utility: parse a tracepoint number and look it up in the list.
10529 If MULTI_P is true, there might be a range of tracepoints in ARG.
10530 if OPTIONAL_P is true, then if the argument is missing, the most
10531 recent tracepoint (tracepoint_count) is returned. */
10532 struct breakpoint
*
10533 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10535 extern int tracepoint_count
;
10536 struct breakpoint
*t
;
10538 char *instring
= arg
== NULL
? NULL
: *arg
;
10540 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10543 tpnum
= tracepoint_count
;
10545 error_no_arg (_("tracepoint number"));
10548 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10552 if (instring
&& *instring
)
10553 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10556 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10560 ALL_TRACEPOINTS (t
)
10561 if (t
->number
== tpnum
)
10566 /* FIXME: if we are in the middle of a range we don't want to give
10567 a message. The current interface to get_number_or_range doesn't
10568 allow us to discover this. */
10569 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10573 /* save-tracepoints command */
10575 tracepoint_save_command (char *args
, int from_tty
)
10577 struct breakpoint
*tp
;
10579 struct command_line
*line
;
10582 struct cleanup
*cleanup
;
10583 struct ui_file
*fp
;
10585 if (args
== 0 || *args
== 0)
10586 error (_("Argument required (file name in which to save tracepoints)"));
10588 /* See if we have anything to save. */
10589 ALL_TRACEPOINTS (tp
)
10596 warning (_("save-tracepoints: no tracepoints to save."));
10600 pathname
= tilde_expand (args
);
10601 cleanup
= make_cleanup (xfree
, pathname
);
10602 fp
= gdb_fopen (pathname
, "w");
10604 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10605 args
, safe_strerror (errno
));
10606 make_cleanup_ui_file_delete (fp
);
10608 ALL_TRACEPOINTS (tp
)
10610 if (tp
->addr_string
)
10611 fprintf_unfiltered (fp
, "trace %s\n", tp
->addr_string
);
10614 sprintf_vma (tmp
, tp
->loc
->address
);
10615 fprintf_unfiltered (fp
, "trace *0x%s\n", tmp
);
10618 if (tp
->pass_count
)
10619 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10623 volatile struct gdb_exception ex
;
10625 fprintf_unfiltered (fp
, " actions\n");
10627 ui_out_redirect (uiout
, fp
);
10628 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10630 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10632 ui_out_redirect (uiout
, NULL
);
10635 throw_exception (ex
);
10637 fprintf_unfiltered (fp
, " end\n");
10640 do_cleanups (cleanup
);
10642 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10646 /* Create a vector of all tracepoints. */
10648 VEC(breakpoint_p
) *
10651 VEC(breakpoint_p
) *tp_vec
= 0;
10652 struct breakpoint
*tp
;
10654 ALL_TRACEPOINTS (tp
)
10656 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10663 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10664 It is defined as a macro to prevent duplication.
10665 COMMAND should be a string constant containing the name of the command. */
10666 #define BREAK_ARGS_HELP(command) \
10667 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10668 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10669 If a line number is specified, break at start of code for that line.\n\
10670 If a function is specified, break at start of code for that function.\n\
10671 If an address is specified, break at that exact address.\n\
10672 With no LOCATION, uses current execution address of selected stack frame.\n\
10673 This is useful for breaking on return to a stack frame.\n\
10675 THREADNUM is the number from \"info threads\".\n\
10676 CONDITION is a boolean expression.\n\
10678 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10680 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10682 /* List of subcommands for "catch". */
10683 static struct cmd_list_element
*catch_cmdlist
;
10685 /* List of subcommands for "tcatch". */
10686 static struct cmd_list_element
*tcatch_cmdlist
;
10688 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10689 lists, and pass some additional user data to the command function. */
10691 add_catch_command (char *name
, char *docstring
,
10692 void (*sfunc
) (char *args
, int from_tty
,
10693 struct cmd_list_element
*command
),
10694 char **(*completer
) (struct cmd_list_element
*cmd
,
10695 char *text
, char *word
),
10696 void *user_data_catch
,
10697 void *user_data_tcatch
)
10699 struct cmd_list_element
*command
;
10701 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10703 set_cmd_sfunc (command
, sfunc
);
10704 set_cmd_context (command
, user_data_catch
);
10705 set_cmd_completer (command
, completer
);
10707 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10709 set_cmd_sfunc (command
, sfunc
);
10710 set_cmd_context (command
, user_data_tcatch
);
10711 set_cmd_completer (command
, completer
);
10715 clear_syscall_counts (struct inferior
*inf
)
10717 inf
->total_syscalls_count
= 0;
10718 inf
->any_syscall_count
= 0;
10719 VEC_free (int, inf
->syscalls_counts
);
10723 _initialize_breakpoint (void)
10725 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10726 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10727 struct cmd_list_element
*c
;
10729 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10730 observer_attach_inferior_exit (clear_syscall_counts
);
10731 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10733 breakpoint_chain
= 0;
10734 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10735 before a breakpoint is set. */
10736 breakpoint_count
= 0;
10738 tracepoint_count
= 0;
10740 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10741 Set ignore-count of breakpoint number N to COUNT.\n\
10742 Usage is `ignore N COUNT'."));
10744 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10746 add_com ("commands", class_breakpoint
, commands_command
, _("\
10747 Set commands to be executed when a breakpoint is hit.\n\
10748 Give breakpoint number as argument after \"commands\".\n\
10749 With no argument, the targeted breakpoint is the last one set.\n\
10750 The commands themselves follow starting on the next line.\n\
10751 Type a line containing \"end\" to indicate the end of them.\n\
10752 Give \"silent\" as the first line to make the breakpoint silent;\n\
10753 then no output is printed when it is hit, except what the commands print."));
10755 add_com ("condition", class_breakpoint
, condition_command
, _("\
10756 Specify breakpoint number N to break only if COND is true.\n\
10757 Usage is `condition N COND', where N is an integer and COND is an\n\
10758 expression to be evaluated whenever breakpoint N is reached."));
10760 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10761 Set a temporary breakpoint.\n\
10762 Like \"break\" except the breakpoint is only temporary,\n\
10763 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10764 by using \"enable delete\" on the breakpoint number.\n\
10766 BREAK_ARGS_HELP ("tbreak")));
10767 set_cmd_completer (c
, location_completer
);
10769 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10770 Set a hardware assisted breakpoint.\n\
10771 Like \"break\" except the breakpoint requires hardware support,\n\
10772 some target hardware may not have this support.\n\
10774 BREAK_ARGS_HELP ("hbreak")));
10775 set_cmd_completer (c
, location_completer
);
10777 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10778 Set a temporary hardware assisted breakpoint.\n\
10779 Like \"hbreak\" except the breakpoint is only temporary,\n\
10780 so it will be deleted when hit.\n\
10782 BREAK_ARGS_HELP ("thbreak")));
10783 set_cmd_completer (c
, location_completer
);
10785 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10786 Enable some breakpoints.\n\
10787 Give breakpoint numbers (separated by spaces) as arguments.\n\
10788 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10789 This is used to cancel the effect of the \"disable\" command.\n\
10790 With a subcommand you can enable temporarily."),
10791 &enablelist
, "enable ", 1, &cmdlist
);
10793 add_com ("ab", class_breakpoint
, enable_command
, _("\
10794 Enable some breakpoints.\n\
10795 Give breakpoint numbers (separated by spaces) as arguments.\n\
10796 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10797 This is used to cancel the effect of the \"disable\" command.\n\
10798 With a subcommand you can enable temporarily."));
10800 add_com_alias ("en", "enable", class_breakpoint
, 1);
10802 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10803 Enable some breakpoints.\n\
10804 Give breakpoint numbers (separated by spaces) as arguments.\n\
10805 This is used to cancel the effect of the \"disable\" command.\n\
10806 May be abbreviated to simply \"enable\".\n"),
10807 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10809 add_cmd ("once", no_class
, enable_once_command
, _("\
10810 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10811 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10814 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10815 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10816 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10819 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10820 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10821 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10824 add_cmd ("once", no_class
, enable_once_command
, _("\
10825 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10826 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10829 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10830 Disable some breakpoints.\n\
10831 Arguments are breakpoint numbers with spaces in between.\n\
10832 To disable all breakpoints, give no argument.\n\
10833 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10834 &disablelist
, "disable ", 1, &cmdlist
);
10835 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10836 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10838 add_com ("sb", class_breakpoint
, disable_command
, _("\
10839 Disable some breakpoints.\n\
10840 Arguments are breakpoint numbers with spaces in between.\n\
10841 To disable all breakpoints, give no argument.\n\
10842 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10844 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10845 Disable some breakpoints.\n\
10846 Arguments are breakpoint numbers with spaces in between.\n\
10847 To disable all breakpoints, give no argument.\n\
10848 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10849 This command may be abbreviated \"disable\"."),
10852 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10853 Delete some breakpoints or auto-display expressions.\n\
10854 Arguments are breakpoint numbers with spaces in between.\n\
10855 To delete all breakpoints, give no argument.\n\
10857 Also a prefix command for deletion of other GDB objects.\n\
10858 The \"unset\" command is also an alias for \"delete\"."),
10859 &deletelist
, "delete ", 1, &cmdlist
);
10860 add_com_alias ("d", "delete", class_breakpoint
, 1);
10861 add_com_alias ("del", "delete", class_breakpoint
, 1);
10863 add_com ("db", class_breakpoint
, delete_command
, _("\
10864 Delete some breakpoints.\n\
10865 Arguments are breakpoint numbers with spaces in between.\n\
10866 To delete all breakpoints, give no argument.\n"));
10868 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10869 Delete some breakpoints or auto-display expressions.\n\
10870 Arguments are breakpoint numbers with spaces in between.\n\
10871 To delete all breakpoints, give no argument.\n\
10872 This command may be abbreviated \"delete\"."),
10875 add_com ("clear", class_breakpoint
, clear_command
, _("\
10876 Clear breakpoint at specified line or function.\n\
10877 Argument may be line number, function name, or \"*\" and an address.\n\
10878 If line number is specified, all breakpoints in that line are cleared.\n\
10879 If function is specified, breakpoints at beginning of function are cleared.\n\
10880 If an address is specified, breakpoints at that address are cleared.\n\
10882 With no argument, clears all breakpoints in the line that the selected frame\n\
10883 is executing in.\n\
10885 See also the \"delete\" command which clears breakpoints by number."));
10887 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10888 Set breakpoint at specified line or function.\n"
10889 BREAK_ARGS_HELP ("break")));
10890 set_cmd_completer (c
, location_completer
);
10892 add_com_alias ("b", "break", class_run
, 1);
10893 add_com_alias ("br", "break", class_run
, 1);
10894 add_com_alias ("bre", "break", class_run
, 1);
10895 add_com_alias ("brea", "break", class_run
, 1);
10898 add_com_alias ("ba", "break", class_breakpoint
, 1);
10902 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10903 Break in function/address or break at a line in the current file."),
10904 &stoplist
, "stop ", 1, &cmdlist
);
10905 add_cmd ("in", class_breakpoint
, stopin_command
,
10906 _("Break in function or address."), &stoplist
);
10907 add_cmd ("at", class_breakpoint
, stopat_command
,
10908 _("Break at a line in the current file."), &stoplist
);
10909 add_com ("status", class_info
, breakpoints_info
, _("\
10910 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10911 The \"Type\" column indicates one of:\n\
10912 \tbreakpoint - normal breakpoint\n\
10913 \twatchpoint - watchpoint\n\
10914 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10915 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10916 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10917 address and file/line number respectively.\n\
10919 Convenience variable \"$_\" and default examine address for \"x\"\n\
10920 are set to the address of the last breakpoint listed unless the command\n\
10921 is prefixed with \"server \".\n\n\
10922 Convenience variable \"$bpnum\" contains the number of the last\n\
10923 breakpoint set."));
10926 add_info ("breakpoints", breakpoints_info
, _("\
10927 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10928 The \"Type\" column indicates one of:\n\
10929 \tbreakpoint - normal breakpoint\n\
10930 \twatchpoint - watchpoint\n\
10931 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10932 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10933 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10934 address and file/line number respectively.\n\
10936 Convenience variable \"$_\" and default examine address for \"x\"\n\
10937 are set to the address of the last breakpoint listed unless the command\n\
10938 is prefixed with \"server \".\n\n\
10939 Convenience variable \"$bpnum\" contains the number of the last\n\
10940 breakpoint set."));
10942 add_info_alias ("b", "breakpoints", 1);
10945 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
10946 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10947 The \"Type\" column indicates one of:\n\
10948 \tbreakpoint - normal breakpoint\n\
10949 \twatchpoint - watchpoint\n\
10950 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10951 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10952 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10953 address and file/line number respectively.\n\
10955 Convenience variable \"$_\" and default examine address for \"x\"\n\
10956 are set to the address of the last breakpoint listed unless the command\n\
10957 is prefixed with \"server \".\n\n\
10958 Convenience variable \"$bpnum\" contains the number of the last\n\
10959 breakpoint set."));
10961 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
10962 Status of all breakpoints, or breakpoint number NUMBER.\n\
10963 The \"Type\" column indicates one of:\n\
10964 \tbreakpoint - normal breakpoint\n\
10965 \twatchpoint - watchpoint\n\
10966 \tlongjmp - internal breakpoint used to step through longjmp()\n\
10967 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
10968 \tuntil - internal breakpoint used by the \"until\" command\n\
10969 \tfinish - internal breakpoint used by the \"finish\" command\n\
10970 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10971 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10972 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10973 address and file/line number respectively.\n\
10975 Convenience variable \"$_\" and default examine address for \"x\"\n\
10976 are set to the address of the last breakpoint listed unless the command\n\
10977 is prefixed with \"server \".\n\n\
10978 Convenience variable \"$bpnum\" contains the number of the last\n\
10980 &maintenanceinfolist
);
10982 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
10983 Set catchpoints to catch events."),
10984 &catch_cmdlist
, "catch ",
10985 0/*allow-unknown*/, &cmdlist
);
10987 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
10988 Set temporary catchpoints to catch events."),
10989 &tcatch_cmdlist
, "tcatch ",
10990 0/*allow-unknown*/, &cmdlist
);
10992 /* Add catch and tcatch sub-commands. */
10993 add_catch_command ("catch", _("\
10994 Catch an exception, when caught.\n\
10995 With an argument, catch only exceptions with the given name."),
10996 catch_catch_command
,
11000 add_catch_command ("throw", _("\
11001 Catch an exception, when thrown.\n\
11002 With an argument, catch only exceptions with the given name."),
11003 catch_throw_command
,
11007 add_catch_command ("fork", _("Catch calls to fork."),
11008 catch_fork_command_1
,
11010 (void *) (uintptr_t) catch_fork_permanent
,
11011 (void *) (uintptr_t) catch_fork_temporary
);
11012 add_catch_command ("vfork", _("Catch calls to vfork."),
11013 catch_fork_command_1
,
11015 (void *) (uintptr_t) catch_vfork_permanent
,
11016 (void *) (uintptr_t) catch_vfork_temporary
);
11017 add_catch_command ("exec", _("Catch calls to exec."),
11018 catch_exec_command_1
,
11022 add_catch_command ("syscall", _("\
11023 Catch system calls by their names and/or numbers.\n\
11024 Arguments say which system calls to catch. If no arguments\n\
11025 are given, every system call will be caught.\n\
11026 Arguments, if given, should be one or more system call names\n\
11027 (if your system supports that), or system call numbers."),
11028 catch_syscall_command_1
,
11029 catch_syscall_completer
,
11032 add_catch_command ("exception", _("\
11033 Catch Ada exceptions, when raised.\n\
11034 With an argument, catch only exceptions with the given name."),
11035 catch_ada_exception_command
,
11039 add_catch_command ("assert", _("\
11040 Catch failed Ada assertions, when raised.\n\
11041 With an argument, catch only exceptions with the given name."),
11042 catch_assert_command
,
11047 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11048 Set a watchpoint for an expression.\n\
11049 A watchpoint stops execution of your program whenever the value of\n\
11050 an expression changes."));
11051 set_cmd_completer (c
, expression_completer
);
11053 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11054 Set a read watchpoint for an expression.\n\
11055 A watchpoint stops execution of your program whenever the value of\n\
11056 an expression is read."));
11057 set_cmd_completer (c
, expression_completer
);
11059 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11060 Set a watchpoint for an expression.\n\
11061 A watchpoint stops execution of your program whenever the value of\n\
11062 an expression is either read or written."));
11063 set_cmd_completer (c
, expression_completer
);
11065 add_info ("watchpoints", breakpoints_info
,
11066 _("Synonym for ``info breakpoints''."));
11069 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11070 respond to changes - contrary to the description. */
11071 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11072 &can_use_hw_watchpoints
, _("\
11073 Set debugger's willingness to use watchpoint hardware."), _("\
11074 Show debugger's willingness to use watchpoint hardware."), _("\
11075 If zero, gdb will not use hardware for new watchpoints, even if\n\
11076 such is available. (However, any hardware watchpoints that were\n\
11077 created before setting this to nonzero, will continue to use watchpoint\n\
11080 show_can_use_hw_watchpoints
,
11081 &setlist
, &showlist
);
11083 can_use_hw_watchpoints
= 1;
11085 /* Tracepoint manipulation commands. */
11087 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11088 Set a tracepoint at specified line or function.\n\
11090 BREAK_ARGS_HELP ("trace") "\n\
11091 Do \"help tracepoints\" for info on other tracepoint commands."));
11092 set_cmd_completer (c
, location_completer
);
11094 add_com_alias ("tp", "trace", class_alias
, 0);
11095 add_com_alias ("tr", "trace", class_alias
, 1);
11096 add_com_alias ("tra", "trace", class_alias
, 1);
11097 add_com_alias ("trac", "trace", class_alias
, 1);
11099 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11100 Set a fast tracepoint at specified line or function.\n\
11102 BREAK_ARGS_HELP ("ftrace") "\n\
11103 Do \"help tracepoints\" for info on other tracepoint commands."));
11104 set_cmd_completer (c
, location_completer
);
11106 add_info ("tracepoints", tracepoints_info
, _("\
11107 Status of tracepoints, or tracepoint number NUMBER.\n\
11108 Convenience variable \"$tpnum\" contains the number of the\n\
11109 last tracepoint set."));
11111 add_info_alias ("tp", "tracepoints", 1);
11113 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11114 Delete specified tracepoints.\n\
11115 Arguments are tracepoint numbers, separated by spaces.\n\
11116 No argument means delete all tracepoints."),
11119 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11120 Disable specified tracepoints.\n\
11121 Arguments are tracepoint numbers, separated by spaces.\n\
11122 No argument means disable all tracepoints."),
11124 deprecate_cmd (c
, "disable");
11126 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11127 Enable specified tracepoints.\n\
11128 Arguments are tracepoint numbers, separated by spaces.\n\
11129 No argument means enable all tracepoints."),
11131 deprecate_cmd (c
, "enable");
11133 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11134 Set the passcount for a tracepoint.\n\
11135 The trace will end when the tracepoint has been passed 'count' times.\n\
11136 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11137 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11139 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11140 Save current tracepoint definitions as a script.\n\
11141 Use the 'source' command in another debug session to restore them."));
11142 set_cmd_completer (c
, filename_completer
);
11144 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11145 Breakpoint specific settings\n\
11146 Configure various breakpoint-specific variables such as\n\
11147 pending breakpoint behavior"),
11148 &breakpoint_set_cmdlist
, "set breakpoint ",
11149 0/*allow-unknown*/, &setlist
);
11150 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11151 Breakpoint specific settings\n\
11152 Configure various breakpoint-specific variables such as\n\
11153 pending breakpoint behavior"),
11154 &breakpoint_show_cmdlist
, "show breakpoint ",
11155 0/*allow-unknown*/, &showlist
);
11157 add_setshow_auto_boolean_cmd ("pending", no_class
,
11158 &pending_break_support
, _("\
11159 Set debugger's behavior regarding pending breakpoints."), _("\
11160 Show debugger's behavior regarding pending breakpoints."), _("\
11161 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11162 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11163 an error. If auto, an unrecognized breakpoint location results in a\n\
11164 user-query to see if a pending breakpoint should be created."),
11166 show_pending_break_support
,
11167 &breakpoint_set_cmdlist
,
11168 &breakpoint_show_cmdlist
);
11170 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11172 add_setshow_boolean_cmd ("auto-hw", no_class
,
11173 &automatic_hardware_breakpoints
, _("\
11174 Set automatic usage of hardware breakpoints."), _("\
11175 Show automatic usage of hardware breakpoints."), _("\
11176 If set, the debugger will automatically use hardware breakpoints for\n\
11177 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11178 a warning will be emitted for such breakpoints."),
11180 show_automatic_hardware_breakpoints
,
11181 &breakpoint_set_cmdlist
,
11182 &breakpoint_show_cmdlist
);
11184 add_setshow_enum_cmd ("always-inserted", class_support
,
11185 always_inserted_enums
, &always_inserted_mode
, _("\
11186 Set mode for inserting breakpoints."), _("\
11187 Show mode for inserting breakpoints."), _("\
11188 When this mode is off, breakpoints are inserted in inferior when it is\n\
11189 resumed, and removed when execution stops. When this mode is on,\n\
11190 breakpoints are inserted immediately and removed only when the user\n\
11191 deletes the breakpoint. When this mode is auto (which is the default),\n\
11192 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11193 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11194 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11195 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11197 &show_always_inserted_mode
,
11198 &breakpoint_set_cmdlist
,
11199 &breakpoint_show_cmdlist
);
11201 automatic_hardware_breakpoints
= 1;
11203 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);