1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
64 #include "parser-defs.h"
66 /* readline include files */
67 #include "readline/readline.h"
68 #include "readline/history.h"
70 /* readline defines this. */
73 #include "mi/mi-common.h"
75 /* Arguments to pass as context to some catch command handlers. */
76 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
77 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void clear_command (char *, int);
99 static void catch_command (char *, int);
101 static int can_use_hardware_watchpoint (struct value
*);
103 static void break_command_1 (char *, int, int);
105 static void mention (struct breakpoint
*);
107 /* This function is used in gdbtk sources and thus can not be made
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 watchpoints_info (char *, int);
135 static int breakpoint_1 (int, int, int (*) (const struct breakpoint
*));
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 do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
175 static void stop_command (char *arg
, int from_tty
);
177 static void stopin_command (char *arg
, int from_tty
);
179 static void stopat_command (char *arg
, int from_tty
);
181 static char *ep_parse_optional_if_clause (char **arg
);
183 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
184 char *arg
, int tempflag
, int from_tty
);
186 static void tcatch_command (char *arg
, int from_tty
);
188 static void ep_skip_leading_whitespace (char **s
);
190 static void detach_single_step_breakpoints (void);
192 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
195 static void free_bp_location (struct bp_location
*loc
);
196 static void incref_bp_location (struct bp_location
*loc
);
197 static void decref_bp_location (struct bp_location
**loc
);
199 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
201 static void update_global_location_list (int);
203 static void update_global_location_list_nothrow (int);
205 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
207 static int is_watchpoint (const struct breakpoint
*bpt
);
209 static void insert_breakpoint_locations (void);
211 static int syscall_catchpoint_p (struct breakpoint
*b
);
213 static void tracepoints_info (char *, int);
215 static void delete_trace_command (char *, int);
217 static void enable_trace_command (char *, int);
219 static void disable_trace_command (char *, int);
221 static void trace_pass_command (char *, int);
223 /* Assuming we're creating a static tracepoint, does S look like a
224 static tracepoint marker spec ("-m MARKER_ID")? */
225 #define is_marker_spec(s) \
226 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
228 /* A reference-counted struct command_line. This lets multiple
229 breakpoints share a single command list. */
230 struct counted_command_line
232 /* The reference count. */
235 /* The command list. */
236 struct command_line
*commands
;
239 struct command_line
*
240 breakpoint_commands (struct breakpoint
*b
)
242 return b
->commands
? b
->commands
->commands
: NULL
;
245 /* Flag indicating that a command has proceeded the inferior past the
246 current breakpoint. */
248 static int breakpoint_proceeded
;
251 bpdisp_text (enum bpdisp disp
)
253 /* NOTE: the following values are a part of MI protocol and
254 represent values of 'disp' field returned when inferior stops at
256 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
258 return bpdisps
[(int) disp
];
261 /* Prototypes for exported functions. */
262 /* If FALSE, gdb will not use hardware support for watchpoints, even
263 if such is available. */
264 static int can_use_hw_watchpoints
;
267 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
268 struct cmd_list_element
*c
,
271 fprintf_filtered (file
,
272 _("Debugger's willingness to use "
273 "watchpoint hardware is %s.\n"),
277 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
278 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
279 for unrecognized breakpoint locations.
280 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
281 static enum auto_boolean pending_break_support
;
283 show_pending_break_support (struct ui_file
*file
, int from_tty
,
284 struct cmd_list_element
*c
,
287 fprintf_filtered (file
,
288 _("Debugger's behavior regarding "
289 "pending breakpoints is %s.\n"),
293 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
294 set with "break" but falling in read-only memory.
295 If 0, gdb will warn about such breakpoints, but won't automatically
296 use hardware breakpoints. */
297 static int automatic_hardware_breakpoints
;
299 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
300 struct cmd_list_element
*c
,
303 fprintf_filtered (file
,
304 _("Automatic usage of hardware breakpoints is %s.\n"),
308 /* If on, gdb will keep breakpoints inserted even as inferior is
309 stopped, and immediately insert any new breakpoints. If off, gdb
310 will insert breakpoints into inferior only when resuming it, and
311 will remove breakpoints upon stop. If auto, GDB will behave as ON
312 if in non-stop mode, and as OFF if all-stop mode.*/
314 static const char always_inserted_auto
[] = "auto";
315 static const char always_inserted_on
[] = "on";
316 static const char always_inserted_off
[] = "off";
317 static const char *always_inserted_enums
[] = {
318 always_inserted_auto
,
323 static const char *always_inserted_mode
= always_inserted_auto
;
325 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
326 struct cmd_list_element
*c
, const char *value
)
328 if (always_inserted_mode
== always_inserted_auto
)
329 fprintf_filtered (file
,
330 _("Always inserted breakpoint "
331 "mode is %s (currently %s).\n"),
333 breakpoints_always_inserted_mode () ? "on" : "off");
335 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
340 breakpoints_always_inserted_mode (void)
342 return (always_inserted_mode
== always_inserted_on
343 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
346 void _initialize_breakpoint (void);
348 /* Are we executing breakpoint commands? */
349 static int executing_breakpoint_commands
;
351 /* Are overlay event breakpoints enabled? */
352 static int overlay_events_enabled
;
354 /* Walk the following statement or block through all breakpoints.
355 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the
356 current breakpoint. */
358 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
360 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
361 for (B = breakpoint_chain; \
362 B ? (TMP=B->next, 1): 0; \
365 /* Similar iterator for the low-level breakpoints. SAFE variant is
366 not provided so update_global_location_list must not be called
367 while executing the block of ALL_BP_LOCATIONS. */
369 #define ALL_BP_LOCATIONS(B,BP_TMP) \
370 for (BP_TMP = bp_location; \
371 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
374 /* Iterator for tracepoints only. */
376 #define ALL_TRACEPOINTS(B) \
377 for (B = breakpoint_chain; B; B = B->next) \
378 if (is_tracepoint (B))
380 /* Chains of all breakpoints defined. */
382 struct breakpoint
*breakpoint_chain
;
384 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
386 static struct bp_location
**bp_location
;
388 /* Number of elements of BP_LOCATION. */
390 static unsigned bp_location_count
;
392 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
393 ADDRESS for the current elements of BP_LOCATION which get a valid
394 result from bp_location_has_shadow. You can use it for roughly
395 limiting the subrange of BP_LOCATION to scan for shadow bytes for
396 an address you need to read. */
398 static CORE_ADDR bp_location_placed_address_before_address_max
;
400 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
401 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
402 BP_LOCATION which get a valid result from bp_location_has_shadow.
403 You can use it for roughly limiting the subrange of BP_LOCATION to
404 scan for shadow bytes for an address you need to read. */
406 static CORE_ADDR bp_location_shadow_len_after_address_max
;
408 /* The locations that no longer correspond to any breakpoint, unlinked
409 from bp_location array, but for which a hit may still be reported
411 VEC(bp_location_p
) *moribund_locations
= NULL
;
413 /* Number of last breakpoint made. */
415 static int breakpoint_count
;
417 /* The value of `breakpoint_count' before the last command that
418 created breakpoints. If the last (break-like) command created more
419 than one breakpoint, then the difference between BREAKPOINT_COUNT
420 and PREV_BREAKPOINT_COUNT is more than one. */
421 static int prev_breakpoint_count
;
423 /* Number of last tracepoint made. */
425 static int tracepoint_count
;
427 static struct cmd_list_element
*breakpoint_set_cmdlist
;
428 static struct cmd_list_element
*breakpoint_show_cmdlist
;
429 struct cmd_list_element
*save_cmdlist
;
431 /* Return whether a breakpoint is an active enabled breakpoint. */
433 breakpoint_enabled (struct breakpoint
*b
)
435 return (b
->enable_state
== bp_enabled
);
438 /* Set breakpoint count to NUM. */
441 set_breakpoint_count (int num
)
443 prev_breakpoint_count
= breakpoint_count
;
444 breakpoint_count
= num
;
445 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
448 /* Used by `start_rbreak_breakpoints' below, to record the current
449 breakpoint count before "rbreak" creates any breakpoint. */
450 static int rbreak_start_breakpoint_count
;
452 /* Called at the start an "rbreak" command to record the first
456 start_rbreak_breakpoints (void)
458 rbreak_start_breakpoint_count
= breakpoint_count
;
461 /* Called at the end of an "rbreak" command to record the last
465 end_rbreak_breakpoints (void)
467 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
470 /* Used in run_command to zero the hit count when a new run starts. */
473 clear_breakpoint_hit_counts (void)
475 struct breakpoint
*b
;
481 /* Allocate a new counted_command_line with reference count of 1.
482 The new structure owns COMMANDS. */
484 static struct counted_command_line
*
485 alloc_counted_command_line (struct command_line
*commands
)
487 struct counted_command_line
*result
488 = xmalloc (sizeof (struct counted_command_line
));
491 result
->commands
= commands
;
495 /* Increment reference count. This does nothing if CMD is NULL. */
498 incref_counted_command_line (struct counted_command_line
*cmd
)
504 /* Decrement reference count. If the reference count reaches 0,
505 destroy the counted_command_line. Sets *CMDP to NULL. This does
506 nothing if *CMDP is NULL. */
509 decref_counted_command_line (struct counted_command_line
**cmdp
)
513 if (--(*cmdp
)->refc
== 0)
515 free_command_lines (&(*cmdp
)->commands
);
522 /* A cleanup function that calls decref_counted_command_line. */
525 do_cleanup_counted_command_line (void *arg
)
527 decref_counted_command_line (arg
);
530 /* Create a cleanup that calls decref_counted_command_line on the
533 static struct cleanup
*
534 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
536 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
539 /* Default address, symtab and line to put a breakpoint at
540 for "break" command with no arg.
541 If default_breakpoint_valid is zero, the other three are
542 not valid, and "break" with no arg is an error.
544 This set by print_stack_frame, which calls set_default_breakpoint. */
546 int default_breakpoint_valid
;
547 CORE_ADDR default_breakpoint_address
;
548 struct symtab
*default_breakpoint_symtab
;
549 int default_breakpoint_line
;
550 struct program_space
*default_breakpoint_pspace
;
553 /* *PP is a string denoting a breakpoint. Get the number of the
554 breakpoint. Advance *PP after the string and any trailing
557 Currently the string can either be a number or "$" followed by the
558 name of a convenience variable. Making it an expression wouldn't
559 work well for map_breakpoint_numbers (e.g. "4 + 5 + 6").
561 If the string is a NULL pointer, that denotes the last breakpoint.
563 TRAILER is a character which can be found after the number; most
564 commonly this is `-'. If you don't want a trailer, use \0. */
567 get_number_trailer (char **pp
, int trailer
)
569 int retval
= 0; /* default */
573 /* Empty line means refer to the last breakpoint. */
574 return breakpoint_count
;
577 /* Make a copy of the name, so we can null-terminate it
578 to pass to lookup_internalvar(). */
583 while (isalnum (*p
) || *p
== '_')
585 varname
= (char *) alloca (p
- start
+ 1);
586 strncpy (varname
, start
, p
- start
);
587 varname
[p
- start
] = '\0';
588 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
592 printf_filtered (_("Convenience variable must "
593 "have integer value.\n"));
601 while (*p
>= '0' && *p
<= '9')
604 /* There is no number here. (e.g. "cond a == b"). */
606 /* Skip non-numeric token. */
607 while (*p
&& !isspace((int) *p
))
609 /* Return zero, which caller must interpret as error. */
615 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
617 /* Trailing junk: return 0 and let caller print error msg. */
618 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
629 /* Like get_number_trailer, but don't allow a trailer. */
631 get_number (char **pp
)
633 return get_number_trailer (pp
, '\0');
636 /* Parse a number or a range.
637 A number will be of the form handled by get_number.
638 A range will be of the form <number1> - <number2>, and
639 will represent all the integers between number1 and number2,
642 While processing a range, this fuction is called iteratively;
643 At each call it will return the next value in the range.
645 At the beginning of parsing a range, the char pointer PP will
646 be advanced past <number1> and left pointing at the '-' token.
647 Subsequent calls will not advance the pointer until the range
648 is completed. The call that completes the range will advance
649 pointer PP past <number2>. */
652 get_number_or_range (char **pp
)
654 static int last_retval
, end_value
;
655 static char *end_ptr
;
656 static int in_range
= 0;
660 /* Default case: pp is pointing either to a solo number,
661 or to the first number of a range. */
662 last_retval
= get_number_trailer (pp
, '-');
667 /* This is the start of a range (<number1> - <number2>).
668 Skip the '-', parse and remember the second number,
669 and also remember the end of the final token. */
673 while (isspace ((int) *end_ptr
))
674 end_ptr
++; /* skip white space */
675 end_value
= get_number (temp
);
676 if (end_value
< last_retval
)
678 error (_("inverted range"));
680 else if (end_value
== last_retval
)
682 /* Degenerate range (number1 == number2). Advance the
683 token pointer so that the range will be treated as a
692 error (_("negative value"));
695 /* pp points to the '-' that betokens a range. All
696 number-parsing has already been done. Return the next
697 integer value (one greater than the saved previous value).
698 Do not advance the token pointer 'pp' until the end of range
701 if (++last_retval
== end_value
)
703 /* End of range reached; advance token pointer. */
711 /* Return the breakpoint with the specified number, or NULL
712 if the number does not refer to an existing breakpoint. */
715 get_breakpoint (int num
)
717 struct breakpoint
*b
;
720 if (b
->number
== num
)
729 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
732 struct bp_location
*loc
= b
->loc
;
734 for (; loc
; loc
= loc
->next
)
739 xfree (b
->cond_string
);
740 b
->cond_string
= NULL
;
747 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
753 /* I don't know if it matters whether this is the string the user
754 typed in or the decompiled expression. */
755 b
->cond_string
= xstrdup (arg
);
756 b
->condition_not_parsed
= 0;
758 if (is_watchpoint (b
))
760 innermost_block
= NULL
;
762 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
764 error (_("Junk at end of expression"));
765 b
->cond_exp_valid_block
= innermost_block
;
769 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
773 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
775 error (_("Junk at end of expression"));
779 breakpoints_changed ();
780 observer_notify_breakpoint_modified (b
->number
);
783 /* condition N EXP -- set break condition of breakpoint N to EXP. */
786 condition_command (char *arg
, int from_tty
)
788 struct breakpoint
*b
;
793 error_no_arg (_("breakpoint number"));
796 bnum
= get_number (&p
);
798 error (_("Bad breakpoint argument: '%s'"), arg
);
801 if (b
->number
== bnum
)
803 set_breakpoint_condition (b
, p
, from_tty
);
807 error (_("No breakpoint number %d."), bnum
);
810 /* Check that COMMAND do not contain commands that are suitable
811 only for tracepoints and not suitable for ordinary breakpoints.
812 Throw if any such commands is found. */
815 check_no_tracepoint_commands (struct command_line
*commands
)
817 struct command_line
*c
;
819 for (c
= commands
; c
; c
= c
->next
)
823 if (c
->control_type
== while_stepping_control
)
824 error (_("The 'while-stepping' command can "
825 "only be used for tracepoints"));
827 for (i
= 0; i
< c
->body_count
; ++i
)
828 check_no_tracepoint_commands ((c
->body_list
)[i
]);
830 /* Not that command parsing removes leading whitespace and comment
831 lines and also empty lines. So, we only need to check for
833 if (strstr (c
->line
, "collect ") == c
->line
)
834 error (_("The 'collect' command can only be used for tracepoints"));
836 if (strstr (c
->line
, "teval ") == c
->line
)
837 error (_("The 'teval' command can only be used for tracepoints"));
841 /* Encapsulate tests for different types of tracepoints. */
844 is_tracepoint (const struct breakpoint
*b
)
846 return (b
->type
== bp_tracepoint
847 || b
->type
== bp_fast_tracepoint
848 || b
->type
== bp_static_tracepoint
);
851 /* A helper function that validsates that COMMANDS are valid for a
852 breakpoint. This function will throw an exception if a problem is
856 validate_commands_for_breakpoint (struct breakpoint
*b
,
857 struct command_line
*commands
)
859 if (is_tracepoint (b
))
861 /* We need to verify that each top-level element of commands is
862 valid for tracepoints, that there's at most one
863 while-stepping element, and that while-stepping's body has
864 valid tracing commands excluding nested while-stepping. */
865 struct command_line
*c
;
866 struct command_line
*while_stepping
= 0;
867 for (c
= commands
; c
; c
= c
->next
)
869 if (c
->control_type
== while_stepping_control
)
871 if (b
->type
== bp_fast_tracepoint
)
872 error (_("The 'while-stepping' command "
873 "cannot be used for fast tracepoint"));
874 else if (b
->type
== bp_static_tracepoint
)
875 error (_("The 'while-stepping' command "
876 "cannot be used for static tracepoint"));
879 error (_("The 'while-stepping' command "
880 "can be used only once"));
887 struct command_line
*c2
;
889 gdb_assert (while_stepping
->body_count
== 1);
890 c2
= while_stepping
->body_list
[0];
891 for (; c2
; c2
= c2
->next
)
893 if (c2
->control_type
== while_stepping_control
)
894 error (_("The 'while-stepping' command cannot be nested"));
900 check_no_tracepoint_commands (commands
);
904 /* Return a vector of all the static tracepoints set at ADDR. The
905 caller is responsible for releasing the vector. */
908 static_tracepoints_here (CORE_ADDR addr
)
910 struct breakpoint
*b
;
911 VEC(breakpoint_p
) *found
= 0;
912 struct bp_location
*loc
;
915 if (b
->type
== bp_static_tracepoint
)
917 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
918 if (loc
->address
== addr
)
919 VEC_safe_push(breakpoint_p
, found
, b
);
925 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
926 validate that only allowed commands are included. */
929 breakpoint_set_commands (struct breakpoint
*b
,
930 struct command_line
*commands
)
932 validate_commands_for_breakpoint (b
, commands
);
934 decref_counted_command_line (&b
->commands
);
935 b
->commands
= alloc_counted_command_line (commands
);
936 breakpoints_changed ();
937 observer_notify_breakpoint_modified (b
->number
);
941 check_tracepoint_command (char *line
, void *closure
)
943 struct breakpoint
*b
= closure
;
945 validate_actionline (&line
, b
);
948 /* A structure used to pass information through
949 map_breakpoint_numbers. */
953 /* True if the command was typed at a tty. */
956 /* The breakpoint range spec. */
959 /* Non-NULL if the body of the commands are being read from this
960 already-parsed command. */
961 struct command_line
*control
;
963 /* The command lines read from the user, or NULL if they have not
965 struct counted_command_line
*cmd
;
968 /* A callback for map_breakpoint_numbers that sets the commands for
972 do_map_commands_command (struct breakpoint
*b
, void *data
)
974 struct commands_info
*info
= data
;
976 if (info
->cmd
== NULL
)
978 struct command_line
*l
;
980 if (info
->control
!= NULL
)
981 l
= copy_command_lines (info
->control
->body_list
[0]);
984 struct cleanup
*old_chain
;
987 str
= xstrprintf (_("Type commands for breakpoint(s) "
988 "%s, one per line."),
991 old_chain
= make_cleanup (xfree
, str
);
993 l
= read_command_lines (str
,
996 ? check_tracepoint_command
: 0),
999 do_cleanups (old_chain
);
1002 info
->cmd
= alloc_counted_command_line (l
);
1005 /* If a breakpoint was on the list more than once, we don't need to
1007 if (b
->commands
!= info
->cmd
)
1009 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1010 incref_counted_command_line (info
->cmd
);
1011 decref_counted_command_line (&b
->commands
);
1012 b
->commands
= info
->cmd
;
1013 breakpoints_changed ();
1014 observer_notify_breakpoint_modified (b
->number
);
1019 commands_command_1 (char *arg
, int from_tty
,
1020 struct command_line
*control
)
1022 struct cleanup
*cleanups
;
1023 struct commands_info info
;
1025 info
.from_tty
= from_tty
;
1026 info
.control
= control
;
1028 /* If we read command lines from the user, then `info' will hold an
1029 extra reference to the commands that we must clean up. */
1030 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1032 if (arg
== NULL
|| !*arg
)
1034 if (breakpoint_count
- prev_breakpoint_count
> 1)
1035 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1037 else if (breakpoint_count
> 0)
1038 arg
= xstrprintf ("%d", breakpoint_count
);
1041 /* So that we don't try to free the incoming non-NULL
1042 argument in the cleanup below. Mapping breakpoint
1043 numbers will fail in this case. */
1048 /* The command loop has some static state, so we need to preserve
1050 arg
= xstrdup (arg
);
1053 make_cleanup (xfree
, arg
);
1057 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1059 if (info
.cmd
== NULL
)
1060 error (_("No breakpoints specified."));
1062 do_cleanups (cleanups
);
1066 commands_command (char *arg
, int from_tty
)
1068 commands_command_1 (arg
, from_tty
, NULL
);
1071 /* Like commands_command, but instead of reading the commands from
1072 input stream, takes them from an already parsed command structure.
1074 This is used by cli-script.c to DTRT with breakpoint commands
1075 that are part of if and while bodies. */
1076 enum command_control_type
1077 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1079 commands_command_1 (arg
, 0, cmd
);
1080 return simple_control
;
1083 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1086 bp_location_has_shadow (struct bp_location
*bl
)
1088 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1092 if (bl
->target_info
.shadow_len
== 0)
1093 /* bp isn't valid, or doesn't shadow memory. */
1098 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1099 by replacing any memory breakpoints with their shadowed contents.
1101 The range of shadowed area by each bp_location is:
1102 bl->address - bp_location_placed_address_before_address_max
1103 up to bl->address + bp_location_shadow_len_after_address_max
1104 The range we were requested to resolve shadows for is:
1105 memaddr ... memaddr + len
1106 Thus the safe cutoff boundaries for performance optimization are
1107 memaddr + len <= (bl->address
1108 - bp_location_placed_address_before_address_max)
1110 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1113 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1115 /* Left boundary, right boundary and median element of our binary
1117 unsigned bc_l
, bc_r
, bc
;
1119 /* Find BC_L which is a leftmost element which may affect BUF
1120 content. It is safe to report lower value but a failure to
1121 report higher one. */
1124 bc_r
= bp_location_count
;
1125 while (bc_l
+ 1 < bc_r
)
1127 struct bp_location
*bl
;
1129 bc
= (bc_l
+ bc_r
) / 2;
1130 bl
= bp_location
[bc
];
1132 /* Check first BL->ADDRESS will not overflow due to the added
1133 constant. Then advance the left boundary only if we are sure
1134 the BC element can in no way affect the BUF content (MEMADDR
1135 to MEMADDR + LEN range).
1137 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1138 offset so that we cannot miss a breakpoint with its shadow
1139 range tail still reaching MEMADDR. */
1141 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1143 && (bl
->address
+ bp_location_shadow_len_after_address_max
1150 /* Due to the binary search above, we need to make sure we pick the
1151 first location that's at BC_L's address. E.g., if there are
1152 multiple locations at the same address, BC_L may end up pointing
1153 at a duplicate location, and miss the "master"/"inserted"
1154 location. Say, given locations L1, L2 and L3 at addresses A and
1157 L1@A, L2@A, L3@B, ...
1159 BC_L could end up pointing at location L2, while the "master"
1160 location could be L1. Since the `loc->inserted' flag is only set
1161 on "master" locations, we'd forget to restore the shadow of L1
1164 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1167 /* Now do full processing of the found relevant range of elements. */
1169 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1171 struct bp_location
*bl
= bp_location
[bc
];
1172 CORE_ADDR bp_addr
= 0;
1176 /* bp_location array has BL->OWNER always non-NULL. */
1177 if (bl
->owner
->type
== bp_none
)
1178 warning (_("reading through apparently deleted breakpoint #%d?"),
1181 /* Performance optimization: any futher element can no longer affect BUF
1184 if (bl
->address
>= bp_location_placed_address_before_address_max
1185 && memaddr
+ len
<= (bl
->address
1186 - bp_location_placed_address_before_address_max
))
1189 if (!bp_location_has_shadow (bl
))
1191 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1192 current_program_space
->aspace
, 0))
1195 /* Addresses and length of the part of the breakpoint that
1197 bp_addr
= bl
->target_info
.placed_address
;
1198 bp_size
= bl
->target_info
.shadow_len
;
1200 if (bp_addr
+ bp_size
<= memaddr
)
1201 /* The breakpoint is entirely before the chunk of memory we
1205 if (bp_addr
>= memaddr
+ len
)
1206 /* The breakpoint is entirely after the chunk of memory we are
1210 /* Offset within shadow_contents. */
1211 if (bp_addr
< memaddr
)
1213 /* Only copy the second part of the breakpoint. */
1214 bp_size
-= memaddr
- bp_addr
;
1215 bptoffset
= memaddr
- bp_addr
;
1219 if (bp_addr
+ bp_size
> memaddr
+ len
)
1221 /* Only copy the first part of the breakpoint. */
1222 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1225 memcpy (buf
+ bp_addr
- memaddr
,
1226 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1231 /* A wrapper function for inserting catchpoints. */
1233 insert_catchpoint (struct ui_out
*uo
, void *args
)
1235 struct breakpoint
*b
= (struct breakpoint
*) args
;
1237 gdb_assert (b
->type
== bp_catchpoint
);
1238 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1243 /* Return true if BPT is of any hardware watchpoint kind. */
1246 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1248 return (bpt
->type
== bp_hardware_watchpoint
1249 || bpt
->type
== bp_read_watchpoint
1250 || bpt
->type
== bp_access_watchpoint
);
1253 /* Return true if BPT is of any watchpoint kind, hardware or
1257 is_watchpoint (const struct breakpoint
*bpt
)
1259 return (is_hardware_watchpoint (bpt
)
1260 || bpt
->type
== bp_watchpoint
);
1263 /* Assuming that B is a watchpoint: returns true if the current thread
1264 and its running state are safe to evaluate or update watchpoint B.
1265 Watchpoints on local expressions need to be evaluated in the
1266 context of the thread that was current when the watchpoint was
1267 created, and, that thread needs to be stopped to be able to select
1268 the correct frame context. Watchpoints on global expressions can
1269 be evaluated on any thread, and in any state. It is presently left
1270 to the target allowing memory accesses when threads are
1274 watchpoint_in_thread_scope (struct breakpoint
*b
)
1276 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1277 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1278 && !is_executing (inferior_ptid
)));
1281 /* Assuming that B is a watchpoint:
1282 - Reparse watchpoint expression, if REPARSE is non-zero
1283 - Evaluate expression and store the result in B->val
1284 - Evaluate the condition if there is one, and store the result
1286 - Update the list of values that must be watched in B->loc.
1288 If the watchpoint disposition is disp_del_at_next_stop, then do
1289 nothing. If this is local watchpoint that is out of scope, delete
1292 Even with `set breakpoint always-inserted on' the watchpoints are
1293 removed + inserted on each stop here. Normal breakpoints must
1294 never be removed because they might be missed by a running thread
1295 when debugging in non-stop mode. On the other hand, hardware
1296 watchpoints (is_hardware_watchpoint; processed here) are specific
1297 to each LWP since they are stored in each LWP's hardware debug
1298 registers. Therefore, such LWP must be stopped first in order to
1299 be able to modify its hardware watchpoints.
1301 Hardware watchpoints must be reset exactly once after being
1302 presented to the user. It cannot be done sooner, because it would
1303 reset the data used to present the watchpoint hit to the user. And
1304 it must not be done later because it could display the same single
1305 watchpoint hit during multiple GDB stops. Note that the latter is
1306 relevant only to the hardware watchpoint types bp_read_watchpoint
1307 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1308 not user-visible - its hit is suppressed if the memory content has
1311 The following constraints influence the location where we can reset
1312 hardware watchpoints:
1314 * target_stopped_by_watchpoint and target_stopped_data_address are
1315 called several times when GDB stops.
1318 * Multiple hardware watchpoints can be hit at the same time,
1319 causing GDB to stop. GDB only presents one hardware watchpoint
1320 hit at a time as the reason for stopping, and all the other hits
1321 are presented later, one after the other, each time the user
1322 requests the execution to be resumed. Execution is not resumed
1323 for the threads still having pending hit event stored in
1324 LWP_INFO->STATUS. While the watchpoint is already removed from
1325 the inferior on the first stop the thread hit event is kept being
1326 reported from its cached value by linux_nat_stopped_data_address
1327 until the real thread resume happens after the watchpoint gets
1328 presented and thus its LWP_INFO->STATUS gets reset.
1330 Therefore the hardware watchpoint hit can get safely reset on the
1331 watchpoint removal from inferior. */
1334 update_watchpoint (struct breakpoint
*b
, int reparse
)
1336 int within_current_scope
;
1337 struct frame_id saved_frame_id
;
1340 /* If this is a local watchpoint, we only want to check if the
1341 watchpoint frame is in scope if the current thread is the thread
1342 that was used to create the watchpoint. */
1343 if (!watchpoint_in_thread_scope (b
))
1346 /* We don't free locations. They are stored in bp_location array
1347 and update_global_locations will eventually delete them and
1348 remove breakpoints if needed. */
1351 if (b
->disposition
== disp_del_at_next_stop
)
1356 /* Determine if the watchpoint is within scope. */
1357 if (b
->exp_valid_block
== NULL
)
1358 within_current_scope
= 1;
1361 struct frame_info
*fi
;
1363 /* Save the current frame's ID so we can restore it after
1364 evaluating the watchpoint expression on its own frame. */
1365 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1366 took a frame parameter, so that we didn't have to change the
1369 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1371 fi
= frame_find_by_id (b
->watchpoint_frame
);
1372 within_current_scope
= (fi
!= NULL
);
1373 if (within_current_scope
)
1377 if (within_current_scope
&& reparse
)
1386 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1387 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1388 /* If the meaning of expression itself changed, the old value is
1389 no longer relevant. We don't want to report a watchpoint hit
1390 to the user when the old value and the new value may actually
1391 be completely different objects. */
1392 value_free (b
->val
);
1396 /* Note that unlike with breakpoints, the watchpoint's condition
1397 expression is stored in the breakpoint object, not in the
1398 locations (re)created below. */
1399 if (b
->cond_string
!= NULL
)
1401 if (b
->cond_exp
!= NULL
)
1403 xfree (b
->cond_exp
);
1408 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1412 /* If we failed to parse the expression, for example because
1413 it refers to a global variable in a not-yet-loaded shared library,
1414 don't try to insert watchpoint. We don't automatically delete
1415 such watchpoint, though, since failure to parse expression
1416 is different from out-of-scope watchpoint. */
1417 if ( !target_has_execution
)
1419 /* Without execution, memory can't change. No use to try and
1420 set watchpoint locations. The watchpoint will be reset when
1421 the target gains execution, through breakpoint_re_set. */
1423 else if (within_current_scope
&& b
->exp
)
1426 struct value
*val_chain
, *v
, *result
, *next
;
1427 struct program_space
*frame_pspace
;
1429 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1431 /* Avoid setting b->val if it's already set. The meaning of
1432 b->val is 'the last value' user saw, and we should update
1433 it only if we reported that last value to user. As it
1434 happens, the code that reports it updates b->val directly. */
1441 /* Change the type of breakpoint between hardware assisted or
1442 an ordinary watchpoint depending on the hardware support
1443 and free hardware slots. REPARSE is set when the inferior
1445 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1448 int i
, mem_cnt
, other_type_used
;
1450 /* We need to determine how many resources are already
1451 used for all other hardware watchpoints to see if we
1452 still have enough resources to also fit this watchpoint
1453 in as well. To avoid the hw_watchpoint_used_count call
1454 below from counting this watchpoint, make sure that it
1455 is marked as a software watchpoint. */
1456 b
->type
= bp_watchpoint
;
1457 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1459 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1462 b
->type
= bp_watchpoint
;
1465 int target_resources_ok
= target_can_use_hardware_watchpoint
1466 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1467 if (target_resources_ok
<= 0)
1468 b
->type
= bp_watchpoint
;
1470 b
->type
= bp_hardware_watchpoint
;
1474 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1476 /* Look at each value on the value chain. */
1477 for (v
= val_chain
; v
; v
= next
)
1479 /* If it's a memory location, and GDB actually needed
1480 its contents to evaluate the expression, then we
1481 must watch it. If the first value returned is
1482 still lazy, that means an error occurred reading it;
1483 watch it anyway in case it becomes readable. */
1484 if (VALUE_LVAL (v
) == lval_memory
1485 && (v
== val_chain
|| ! value_lazy (v
)))
1487 struct type
*vtype
= check_typedef (value_type (v
));
1489 /* We only watch structs and arrays if user asked
1490 for it explicitly, never if they just happen to
1491 appear in the middle of some value chain. */
1493 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1494 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1498 struct bp_location
*loc
, **tmp
;
1500 addr
= value_address (v
);
1501 len
= TYPE_LENGTH (value_type (v
));
1503 if (b
->type
== bp_read_watchpoint
)
1505 else if (b
->type
== bp_access_watchpoint
)
1508 loc
= allocate_bp_location (b
);
1509 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1512 loc
->gdbarch
= get_type_arch (value_type (v
));
1514 loc
->pspace
= frame_pspace
;
1515 loc
->address
= addr
;
1517 loc
->watchpoint_type
= type
;
1521 next
= value_next (v
);
1526 /* If a software watchpoint is not watching any memory, then the
1527 above left it without any location set up. But,
1528 bpstat_stop_status requires a location to be able to report
1529 stops, so make sure there's at least a dummy one. */
1530 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1532 b
->loc
= allocate_bp_location (b
);
1533 b
->loc
->pspace
= frame_pspace
;
1534 b
->loc
->address
= -1;
1535 b
->loc
->length
= -1;
1536 b
->loc
->watchpoint_type
= -1;
1539 else if (!within_current_scope
)
1541 printf_filtered (_("\
1542 Watchpoint %d deleted because the program has left the block\n\
1543 in which its expression is valid.\n"),
1545 if (b
->related_breakpoint
)
1547 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1548 b
->related_breakpoint
->related_breakpoint
= NULL
;
1549 b
->related_breakpoint
= NULL
;
1551 b
->disposition
= disp_del_at_next_stop
;
1554 /* Restore the selected frame. */
1556 select_frame (frame_find_by_id (saved_frame_id
));
1560 /* Returns 1 iff breakpoint location should be
1561 inserted in the inferior. */
1563 should_be_inserted (struct bp_location
*bl
)
1565 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1568 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1571 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1574 /* This is set for example, when we're attached to the parent of a
1575 vfork, and have detached from the child. The child is running
1576 free, and we expect it to do an exec or exit, at which point the
1577 OS makes the parent schedulable again (and the target reports
1578 that the vfork is done). Until the child is done with the shared
1579 memory region, do not insert breakpoints in the parent, otherwise
1580 the child could still trip on the parent's breakpoints. Since
1581 the parent is blocked anyway, it won't miss any breakpoint. */
1582 if (bl
->pspace
->breakpoints_not_allowed
)
1585 /* Tracepoints are inserted by the target at a time of its choosing,
1587 if (is_tracepoint (bl
->owner
))
1593 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1594 location. Any error messages are printed to TMP_ERROR_STREAM; and
1595 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1597 NOTE drow/2003-09-09: This routine could be broken down to an
1598 object-style method for each breakpoint or catchpoint type. */
1600 insert_bp_location (struct bp_location
*bl
,
1601 struct ui_file
*tmp_error_stream
,
1602 int *disabled_breaks
,
1603 int *hw_breakpoint_error
)
1607 if (!should_be_inserted (bl
) || bl
->inserted
)
1610 /* Initialize the target-specific information. */
1611 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1612 bl
->target_info
.placed_address
= bl
->address
;
1613 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1615 if (bl
->loc_type
== bp_loc_software_breakpoint
1616 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1618 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1620 /* If the explicitly specified breakpoint type
1621 is not hardware breakpoint, check the memory map to see
1622 if the breakpoint address is in read only memory or not.
1624 Two important cases are:
1625 - location type is not hardware breakpoint, memory
1626 is readonly. We change the type of the location to
1627 hardware breakpoint.
1628 - location type is hardware breakpoint, memory is
1629 read-write. This means we've previously made the
1630 location hardware one, but then the memory map changed,
1633 When breakpoints are removed, remove_breakpoints will use
1634 location types we've just set here, the only possible
1635 problem is that memory map has changed during running
1636 program, but it's not going to work anyway with current
1638 struct mem_region
*mr
1639 = lookup_mem_region (bl
->target_info
.placed_address
);
1643 if (automatic_hardware_breakpoints
)
1645 enum bp_loc_type new_type
;
1647 if (mr
->attrib
.mode
!= MEM_RW
)
1648 new_type
= bp_loc_hardware_breakpoint
;
1650 new_type
= bp_loc_software_breakpoint
;
1652 if (new_type
!= bl
->loc_type
)
1654 static int said
= 0;
1656 bl
->loc_type
= new_type
;
1659 fprintf_filtered (gdb_stdout
,
1660 _("Note: automatically using "
1661 "hardware breakpoints for "
1662 "read-only addresses.\n"));
1667 else if (bl
->loc_type
== bp_loc_software_breakpoint
1668 && mr
->attrib
.mode
!= MEM_RW
)
1669 warning (_("cannot set software breakpoint "
1670 "at readonly address %s"),
1671 paddress (bl
->gdbarch
, bl
->address
));
1675 /* First check to see if we have to handle an overlay. */
1676 if (overlay_debugging
== ovly_off
1677 || bl
->section
== NULL
1678 || !(section_is_overlay (bl
->section
)))
1680 /* No overlay handling: just set the breakpoint. */
1682 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1683 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1686 val
= target_insert_breakpoint (bl
->gdbarch
,
1691 /* This breakpoint is in an overlay section.
1692 Shall we set a breakpoint at the LMA? */
1693 if (!overlay_events_enabled
)
1695 /* Yes -- overlay event support is not active,
1696 so we must try to set a breakpoint at the LMA.
1697 This will not work for a hardware breakpoint. */
1698 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1699 warning (_("hardware breakpoint %d not supported in overlay!"),
1703 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1705 /* Set a software (trap) breakpoint at the LMA. */
1706 bl
->overlay_target_info
= bl
->target_info
;
1707 bl
->overlay_target_info
.placed_address
= addr
;
1708 val
= target_insert_breakpoint (bl
->gdbarch
,
1709 &bl
->overlay_target_info
);
1711 fprintf_unfiltered (tmp_error_stream
,
1712 "Overlay breakpoint %d "
1713 "failed: in ROM?\n",
1717 /* Shall we set a breakpoint at the VMA? */
1718 if (section_is_mapped (bl
->section
))
1720 /* Yes. This overlay section is mapped into memory. */
1721 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1722 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1725 val
= target_insert_breakpoint (bl
->gdbarch
,
1730 /* No. This breakpoint will not be inserted.
1731 No error, but do not mark the bp as 'inserted'. */
1738 /* Can't set the breakpoint. */
1739 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1741 /* See also: disable_breakpoints_in_shlibs. */
1743 bl
->shlib_disabled
= 1;
1744 if (!*disabled_breaks
)
1746 fprintf_unfiltered (tmp_error_stream
,
1747 "Cannot insert breakpoint %d.\n",
1749 fprintf_unfiltered (tmp_error_stream
,
1750 "Temporarily disabling shared "
1751 "library breakpoints:\n");
1753 *disabled_breaks
= 1;
1754 fprintf_unfiltered (tmp_error_stream
,
1755 "breakpoint #%d\n", bl
->owner
->number
);
1759 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1761 *hw_breakpoint_error
= 1;
1762 fprintf_unfiltered (tmp_error_stream
,
1763 "Cannot insert hardware "
1769 fprintf_unfiltered (tmp_error_stream
,
1770 "Cannot insert breakpoint %d.\n",
1772 fprintf_filtered (tmp_error_stream
,
1773 "Error accessing memory address ");
1774 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1776 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1777 safe_strerror (val
));
1788 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1789 /* NOTE drow/2003-09-08: This state only exists for removing
1790 watchpoints. It's not clear that it's necessary... */
1791 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1793 val
= target_insert_watchpoint (bl
->address
,
1795 bl
->watchpoint_type
,
1796 bl
->owner
->cond_exp
);
1798 /* If trying to set a read-watchpoint, and it turns out it's not
1799 supported, try emulating one with an access watchpoint. */
1800 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1802 struct bp_location
*loc
, **loc_temp
;
1804 /* But don't try to insert it, if there's already another
1805 hw_access location that would be considered a duplicate
1807 ALL_BP_LOCATIONS (loc
, loc_temp
)
1809 && loc
->watchpoint_type
== hw_access
1810 && watchpoint_locations_match (bl
, loc
))
1814 bl
->target_info
= loc
->target_info
;
1815 bl
->watchpoint_type
= hw_access
;
1822 val
= target_insert_watchpoint (bl
->address
,
1825 bl
->owner
->cond_exp
);
1827 bl
->watchpoint_type
= hw_access
;
1831 bl
->inserted
= (val
== 0);
1834 else if (bl
->owner
->type
== bp_catchpoint
)
1836 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1837 bl
->owner
, RETURN_MASK_ERROR
);
1838 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1841 bl
->owner
->enable_state
= bp_disabled
;
1845 /* We've already printed an error message if there was a problem
1846 inserting this catchpoint, and we've disabled the catchpoint,
1847 so just return success. */
1854 /* This function is called when program space PSPACE is about to be
1855 deleted. It takes care of updating breakpoints to not reference
1859 breakpoint_program_space_exit (struct program_space
*pspace
)
1861 struct breakpoint
*b
, *b_temp
;
1862 struct bp_location
*loc
, **loc_temp
;
1864 /* Remove any breakpoint that was set through this program space. */
1865 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1867 if (b
->pspace
== pspace
)
1868 delete_breakpoint (b
);
1871 /* Breakpoints set through other program spaces could have locations
1872 bound to PSPACE as well. Remove those. */
1873 ALL_BP_LOCATIONS (loc
, loc_temp
)
1875 struct bp_location
*tmp
;
1877 if (loc
->pspace
== pspace
)
1879 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1880 if (loc
->owner
->loc
== loc
)
1881 loc
->owner
->loc
= loc
->next
;
1883 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1884 if (tmp
->next
== loc
)
1886 tmp
->next
= loc
->next
;
1892 /* Now update the global location list to permanently delete the
1893 removed locations above. */
1894 update_global_location_list (0);
1897 /* Make sure all breakpoints are inserted in inferior.
1898 Throws exception on any error.
1899 A breakpoint that is already inserted won't be inserted
1900 again, so calling this function twice is safe. */
1902 insert_breakpoints (void)
1904 struct breakpoint
*bpt
;
1906 ALL_BREAKPOINTS (bpt
)
1907 if (is_hardware_watchpoint (bpt
))
1908 update_watchpoint (bpt
, 0 /* don't reparse. */);
1910 update_global_location_list (1);
1912 /* update_global_location_list does not insert breakpoints when
1913 always_inserted_mode is not enabled. Explicitly insert them
1915 if (!breakpoints_always_inserted_mode ())
1916 insert_breakpoint_locations ();
1919 /* insert_breakpoints is used when starting or continuing the program.
1920 remove_breakpoints is used when the program stops.
1921 Both return zero if successful,
1922 or an `errno' value if could not write the inferior. */
1925 insert_breakpoint_locations (void)
1927 struct breakpoint
*bpt
;
1928 struct bp_location
*bl
, **blp_tmp
;
1931 int disabled_breaks
= 0;
1932 int hw_breakpoint_error
= 0;
1934 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1935 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1937 /* Explicitly mark the warning -- this will only be printed if
1938 there was an error. */
1939 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1941 save_current_space_and_thread ();
1943 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1945 if (!should_be_inserted (bl
) || bl
->inserted
)
1948 /* There is no point inserting thread-specific breakpoints if
1949 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1950 has BL->OWNER always non-NULL. */
1951 if (bl
->owner
->thread
!= -1
1952 && !valid_thread_id (bl
->owner
->thread
))
1955 switch_to_program_space_and_thread (bl
->pspace
);
1957 /* For targets that support global breakpoints, there's no need
1958 to select an inferior to insert breakpoint to. In fact, even
1959 if we aren't attached to any process yet, we should still
1960 insert breakpoints. */
1961 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1962 && ptid_equal (inferior_ptid
, null_ptid
))
1965 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1966 &hw_breakpoint_error
);
1971 /* If we failed to insert all locations of a watchpoint, remove
1972 them, as half-inserted watchpoint is of limited use. */
1973 ALL_BREAKPOINTS (bpt
)
1975 int some_failed
= 0;
1976 struct bp_location
*loc
;
1978 if (!is_hardware_watchpoint (bpt
))
1981 if (!breakpoint_enabled (bpt
))
1984 if (bpt
->disposition
== disp_del_at_next_stop
)
1987 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1988 if (!loc
->inserted
&& should_be_inserted (loc
))
1995 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1997 remove_breakpoint (loc
, mark_uninserted
);
1999 hw_breakpoint_error
= 1;
2000 fprintf_unfiltered (tmp_error_stream
,
2001 "Could not insert hardware watchpoint %d.\n",
2009 /* If a hardware breakpoint or watchpoint was inserted, add a
2010 message about possibly exhausted resources. */
2011 if (hw_breakpoint_error
)
2013 fprintf_unfiltered (tmp_error_stream
,
2014 "Could not insert hardware breakpoints:\n\
2015 You may have requested too many hardware breakpoints/watchpoints.\n");
2017 target_terminal_ours_for_output ();
2018 error_stream (tmp_error_stream
);
2021 do_cleanups (cleanups
);
2025 remove_breakpoints (void)
2027 struct bp_location
*bl
, **blp_tmp
;
2030 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2033 val
|= remove_breakpoint (bl
, mark_uninserted
);
2038 /* Remove breakpoints of process PID. */
2041 remove_breakpoints_pid (int pid
)
2043 struct bp_location
*bl
, **blp_tmp
;
2045 struct inferior
*inf
= find_inferior_pid (pid
);
2047 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2049 if (bl
->pspace
!= inf
->pspace
)
2054 val
= remove_breakpoint (bl
, mark_uninserted
);
2063 remove_hw_watchpoints (void)
2065 struct bp_location
*bl
, **blp_tmp
;
2068 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2070 if (bl
->inserted
&& bl
->loc_type
== bp_loc_hardware_watchpoint
)
2071 val
|= remove_breakpoint (bl
, mark_uninserted
);
2077 reattach_breakpoints (int pid
)
2079 struct cleanup
*old_chain
;
2080 struct bp_location
*bl
, **blp_tmp
;
2082 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2083 int dummy1
= 0, dummy2
= 0;
2084 struct inferior
*inf
;
2085 struct thread_info
*tp
;
2087 tp
= any_live_thread_of_process (pid
);
2091 inf
= find_inferior_pid (pid
);
2092 old_chain
= save_inferior_ptid ();
2094 inferior_ptid
= tp
->ptid
;
2096 make_cleanup_ui_file_delete (tmp_error_stream
);
2098 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2100 if (bl
->pspace
!= inf
->pspace
)
2106 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2109 do_cleanups (old_chain
);
2114 do_cleanups (old_chain
);
2118 static int internal_breakpoint_number
= -1;
2120 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2121 If INTERNAL is non-zero, the breakpoint number will be populated
2122 from internal_breakpoint_number and that variable decremented.
2123 Otherwis the breakpoint number will be populated from
2124 breakpoint_count and that value incremented. Internal breakpoints
2125 do not set the internal var bpnum. */
2127 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2130 b
->number
= internal_breakpoint_number
--;
2133 set_breakpoint_count (breakpoint_count
+ 1);
2134 b
->number
= breakpoint_count
;
2138 static struct breakpoint
*
2139 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2140 CORE_ADDR address
, enum bptype type
)
2142 struct symtab_and_line sal
;
2143 struct breakpoint
*b
;
2145 init_sal (&sal
); /* Initialize to zeroes. */
2148 sal
.section
= find_pc_overlay (sal
.pc
);
2149 sal
.pspace
= current_program_space
;
2151 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2152 b
->number
= internal_breakpoint_number
--;
2153 b
->disposition
= disp_donttouch
;
2159 create_overlay_event_breakpoint (char *func_name
)
2161 struct objfile
*objfile
;
2163 ALL_OBJFILES (objfile
)
2165 struct breakpoint
*b
;
2166 struct minimal_symbol
*m
;
2168 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2172 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2173 SYMBOL_VALUE_ADDRESS (m
),
2175 b
->addr_string
= xstrdup (func_name
);
2177 if (overlay_debugging
== ovly_auto
)
2179 b
->enable_state
= bp_enabled
;
2180 overlay_events_enabled
= 1;
2184 b
->enable_state
= bp_disabled
;
2185 overlay_events_enabled
= 0;
2188 update_global_location_list (1);
2192 create_longjmp_master_breakpoint (char *func_name
)
2194 struct program_space
*pspace
;
2195 struct objfile
*objfile
;
2196 struct cleanup
*old_chain
;
2198 old_chain
= save_current_program_space ();
2200 ALL_PSPACES (pspace
)
2201 ALL_OBJFILES (objfile
)
2203 struct breakpoint
*b
;
2204 struct minimal_symbol
*m
;
2206 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2209 set_current_program_space (pspace
);
2211 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2215 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2216 SYMBOL_VALUE_ADDRESS (m
),
2218 b
->addr_string
= xstrdup (func_name
);
2219 b
->enable_state
= bp_disabled
;
2221 update_global_location_list (1);
2223 do_cleanups (old_chain
);
2226 /* Create a master std::terminate breakpoint. The actual function
2227 looked for is named FUNC_NAME. */
2229 create_std_terminate_master_breakpoint (const char *func_name
)
2231 struct program_space
*pspace
;
2232 struct objfile
*objfile
;
2233 struct cleanup
*old_chain
;
2235 old_chain
= save_current_program_space ();
2237 ALL_PSPACES (pspace
)
2238 ALL_OBJFILES (objfile
)
2240 struct breakpoint
*b
;
2241 struct minimal_symbol
*m
;
2243 set_current_program_space (pspace
);
2245 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2246 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2247 && MSYMBOL_TYPE (m
) != mst_file_text
))
2250 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2251 SYMBOL_VALUE_ADDRESS (m
),
2252 bp_std_terminate_master
);
2253 b
->addr_string
= xstrdup (func_name
);
2254 b
->enable_state
= bp_disabled
;
2256 update_global_location_list (1);
2258 do_cleanups (old_chain
);
2261 /* Install a master breakpoint on the unwinder's debug hook. */
2264 create_exception_master_breakpoint (void)
2266 struct objfile
*objfile
;
2268 ALL_OBJFILES (objfile
)
2270 struct minimal_symbol
*debug_hook
;
2272 debug_hook
= lookup_minimal_symbol ("_Unwind_DebugHook", NULL
, objfile
);
2273 if (debug_hook
!= NULL
)
2275 struct breakpoint
*b
;
2276 CORE_ADDR addr
= SYMBOL_VALUE_ADDRESS (debug_hook
);
2277 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2279 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2281 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2282 b
->addr_string
= xstrdup ("_Unwind_DebugHook");
2283 b
->enable_state
= bp_disabled
;
2287 update_global_location_list (1);
2291 update_breakpoints_after_exec (void)
2293 struct breakpoint
*b
, *b_tmp
;
2294 struct bp_location
*bploc
, **bplocp_tmp
;
2296 /* We're about to delete breakpoints from GDB's lists. If the
2297 INSERTED flag is true, GDB will try to lift the breakpoints by
2298 writing the breakpoints' "shadow contents" back into memory. The
2299 "shadow contents" are NOT valid after an exec, so GDB should not
2300 do that. Instead, the target is responsible from marking
2301 breakpoints out as soon as it detects an exec. We don't do that
2302 here instead, because there may be other attempts to delete
2303 breakpoints after detecting an exec and before reaching here. */
2304 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2305 if (bploc
->pspace
== current_program_space
)
2306 gdb_assert (!bploc
->inserted
);
2308 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2310 if (b
->pspace
!= current_program_space
)
2313 /* Solib breakpoints must be explicitly reset after an exec(). */
2314 if (b
->type
== bp_shlib_event
)
2316 delete_breakpoint (b
);
2320 /* JIT breakpoints must be explicitly reset after an exec(). */
2321 if (b
->type
== bp_jit_event
)
2323 delete_breakpoint (b
);
2327 /* Thread event breakpoints must be set anew after an exec(),
2328 as must overlay event and longjmp master breakpoints. */
2329 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2330 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2331 || b
->type
== bp_exception_master
)
2333 delete_breakpoint (b
);
2337 /* Step-resume breakpoints are meaningless after an exec(). */
2338 if (b
->type
== bp_step_resume
)
2340 delete_breakpoint (b
);
2344 /* Longjmp and longjmp-resume breakpoints are also meaningless
2346 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2347 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2349 delete_breakpoint (b
);
2353 if (b
->type
== bp_catchpoint
)
2355 /* For now, none of the bp_catchpoint breakpoints need to
2356 do anything at this point. In the future, if some of
2357 the catchpoints need to something, we will need to add
2358 a new method, and call this method from here. */
2362 /* bp_finish is a special case. The only way we ought to be able
2363 to see one of these when an exec() has happened, is if the user
2364 caught a vfork, and then said "finish". Ordinarily a finish just
2365 carries them to the call-site of the current callee, by setting
2366 a temporary bp there and resuming. But in this case, the finish
2367 will carry them entirely through the vfork & exec.
2369 We don't want to allow a bp_finish to remain inserted now. But
2370 we can't safely delete it, 'cause finish_command has a handle to
2371 the bp on a bpstat, and will later want to delete it. There's a
2372 chance (and I've seen it happen) that if we delete the bp_finish
2373 here, that its storage will get reused by the time finish_command
2374 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2375 We really must allow finish_command to delete a bp_finish.
2377 In the absense of a general solution for the "how do we know
2378 it's safe to delete something others may have handles to?"
2379 problem, what we'll do here is just uninsert the bp_finish, and
2380 let finish_command delete it.
2382 (We know the bp_finish is "doomed" in the sense that it's
2383 momentary, and will be deleted as soon as finish_command sees
2384 the inferior stopped. So it doesn't matter that the bp's
2385 address is probably bogus in the new a.out, unlike e.g., the
2386 solib breakpoints.) */
2388 if (b
->type
== bp_finish
)
2393 /* Without a symbolic address, we have little hope of the
2394 pre-exec() address meaning the same thing in the post-exec()
2396 if (b
->addr_string
== NULL
)
2398 delete_breakpoint (b
);
2402 /* FIXME what about longjmp breakpoints? Re-create them here? */
2403 create_overlay_event_breakpoint ("_ovly_debug_event");
2404 create_longjmp_master_breakpoint ("longjmp");
2405 create_longjmp_master_breakpoint ("_longjmp");
2406 create_longjmp_master_breakpoint ("siglongjmp");
2407 create_longjmp_master_breakpoint ("_siglongjmp");
2408 create_std_terminate_master_breakpoint ("std::terminate()");
2409 create_exception_master_breakpoint ();
2413 detach_breakpoints (int pid
)
2415 struct bp_location
*bl
, **blp_tmp
;
2417 struct cleanup
*old_chain
= save_inferior_ptid ();
2418 struct inferior
*inf
= current_inferior ();
2420 if (pid
== PIDGET (inferior_ptid
))
2421 error (_("Cannot detach breakpoints of inferior_ptid"));
2423 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2424 inferior_ptid
= pid_to_ptid (pid
);
2425 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2427 if (bl
->pspace
!= inf
->pspace
)
2431 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2434 /* Detach single-step breakpoints as well. */
2435 detach_single_step_breakpoints ();
2437 do_cleanups (old_chain
);
2441 /* Remove the breakpoint location BL from the current address space.
2442 Note that this is used to detach breakpoints from a child fork.
2443 When we get here, the child isn't in the inferior list, and neither
2444 do we have objects to represent its address space --- we should
2445 *not* look at bl->pspace->aspace here. */
2448 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2452 /* BL is never in moribund_locations by our callers. */
2453 gdb_assert (bl
->owner
!= NULL
);
2455 if (bl
->owner
->enable_state
== bp_permanent
)
2456 /* Permanent breakpoints cannot be inserted or removed. */
2459 /* The type of none suggests that owner is actually deleted.
2460 This should not ever happen. */
2461 gdb_assert (bl
->owner
->type
!= bp_none
);
2463 if (bl
->loc_type
== bp_loc_software_breakpoint
2464 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2466 /* "Normal" instruction breakpoint: either the standard
2467 trap-instruction bp (bp_breakpoint), or a
2468 bp_hardware_breakpoint. */
2470 /* First check to see if we have to handle an overlay. */
2471 if (overlay_debugging
== ovly_off
2472 || bl
->section
== NULL
2473 || !(section_is_overlay (bl
->section
)))
2475 /* No overlay handling: just remove the breakpoint. */
2477 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2478 val
= target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2480 val
= target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2484 /* This breakpoint is in an overlay section.
2485 Did we set a breakpoint at the LMA? */
2486 if (!overlay_events_enabled
)
2488 /* Yes -- overlay event support is not active, so we
2489 should have set a breakpoint at the LMA. Remove it.
2491 /* Ignore any failures: if the LMA is in ROM, we will
2492 have already warned when we failed to insert it. */
2493 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2494 target_remove_hw_breakpoint (bl
->gdbarch
,
2495 &bl
->overlay_target_info
);
2497 target_remove_breakpoint (bl
->gdbarch
,
2498 &bl
->overlay_target_info
);
2500 /* Did we set a breakpoint at the VMA?
2501 If so, we will have marked the breakpoint 'inserted'. */
2504 /* Yes -- remove it. Previously we did not bother to
2505 remove the breakpoint if the section had been
2506 unmapped, but let's not rely on that being safe. We
2507 don't know what the overlay manager might do. */
2508 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2509 val
= target_remove_hw_breakpoint (bl
->gdbarch
,
2512 /* However, we should remove *software* breakpoints only
2513 if the section is still mapped, or else we overwrite
2514 wrong code with the saved shadow contents. */
2515 else if (section_is_mapped (bl
->section
))
2516 val
= target_remove_breakpoint (bl
->gdbarch
,
2523 /* No -- not inserted, so no need to remove. No error. */
2528 /* In some cases, we might not be able to remove a breakpoint
2529 in a shared library that has already been removed, but we
2530 have not yet processed the shlib unload event. */
2531 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2536 bl
->inserted
= (is
== mark_inserted
);
2538 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2540 bl
->inserted
= (is
== mark_inserted
);
2541 val
= target_remove_watchpoint (bl
->address
, bl
->length
,
2542 bl
->watchpoint_type
,
2543 bl
->owner
->cond_exp
);
2545 /* Failure to remove any of the hardware watchpoints comes here. */
2546 if ((is
== mark_uninserted
) && (bl
->inserted
))
2547 warning (_("Could not remove hardware watchpoint %d."),
2550 else if (bl
->owner
->type
== bp_catchpoint
2551 && breakpoint_enabled (bl
->owner
)
2554 gdb_assert (bl
->owner
->ops
!= NULL
&& bl
->owner
->ops
->remove
!= NULL
);
2556 val
= bl
->owner
->ops
->remove (bl
->owner
);
2559 bl
->inserted
= (is
== mark_inserted
);
2566 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2569 struct cleanup
*old_chain
;
2571 /* BL is never in moribund_locations by our callers. */
2572 gdb_assert (bl
->owner
!= NULL
);
2574 if (bl
->owner
->enable_state
== bp_permanent
)
2575 /* Permanent breakpoints cannot be inserted or removed. */
2578 /* The type of none suggests that owner is actually deleted.
2579 This should not ever happen. */
2580 gdb_assert (bl
->owner
->type
!= bp_none
);
2582 old_chain
= save_current_space_and_thread ();
2584 switch_to_program_space_and_thread (bl
->pspace
);
2586 ret
= remove_breakpoint_1 (bl
, is
);
2588 do_cleanups (old_chain
);
2592 /* Clear the "inserted" flag in all breakpoints. */
2595 mark_breakpoints_out (void)
2597 struct bp_location
*bl
, **blp_tmp
;
2599 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2600 if (bl
->pspace
== current_program_space
)
2604 /* Clear the "inserted" flag in all breakpoints and delete any
2605 breakpoints which should go away between runs of the program.
2607 Plus other such housekeeping that has to be done for breakpoints
2610 Note: this function gets called at the end of a run (by
2611 generic_mourn_inferior) and when a run begins (by
2612 init_wait_for_inferior). */
2617 breakpoint_init_inferior (enum inf_context context
)
2619 struct breakpoint
*b
, *b_tmp
;
2620 struct bp_location
*bl
, **blp_tmp
;
2622 struct program_space
*pspace
= current_program_space
;
2624 /* If breakpoint locations are shared across processes, then there's
2626 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2629 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2631 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2632 if (bl
->pspace
== pspace
2633 && bl
->owner
->enable_state
!= bp_permanent
)
2637 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2639 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2646 /* If the call dummy breakpoint is at the entry point it will
2647 cause problems when the inferior is rerun, so we better get
2650 case bp_watchpoint_scope
:
2652 /* Also get rid of scope breakpoints. */
2654 case bp_shlib_event
:
2656 /* Also remove solib event breakpoints. Their addresses may
2657 have changed since the last time we ran the program.
2658 Actually we may now be debugging against different target;
2659 and so the solib backend that installed this breakpoint may
2660 not be used in by the target. E.g.,
2662 (gdb) file prog-linux
2663 (gdb) run # native linux target
2666 (gdb) file prog-win.exe
2667 (gdb) tar rem :9999 # remote Windows gdbserver.
2670 delete_breakpoint (b
);
2674 case bp_hardware_watchpoint
:
2675 case bp_read_watchpoint
:
2676 case bp_access_watchpoint
:
2678 /* Likewise for watchpoints on local expressions. */
2679 if (b
->exp_valid_block
!= NULL
)
2680 delete_breakpoint (b
);
2681 else if (context
== inf_starting
)
2683 /* Reset val field to force reread of starting value in
2684 insert_breakpoints. */
2686 value_free (b
->val
);
2696 /* Get rid of the moribund locations. */
2697 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2698 decref_bp_location (&bl
);
2699 VEC_free (bp_location_p
, moribund_locations
);
2702 /* These functions concern about actual breakpoints inserted in the
2703 target --- to e.g. check if we need to do decr_pc adjustment or if
2704 we need to hop over the bkpt --- so we check for address space
2705 match, not program space. */
2707 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2708 exists at PC. It returns ordinary_breakpoint_here if it's an
2709 ordinary breakpoint, or permanent_breakpoint_here if it's a
2710 permanent breakpoint.
2711 - When continuing from a location with an ordinary breakpoint, we
2712 actually single step once before calling insert_breakpoints.
2713 - When continuing from a localion with a permanent breakpoint, we
2714 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2715 the target, to advance the PC past the breakpoint. */
2717 enum breakpoint_here
2718 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2720 struct bp_location
*bl
, **blp_tmp
;
2721 int any_breakpoint_here
= 0;
2723 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2725 if (bl
->loc_type
!= bp_loc_software_breakpoint
2726 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2729 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2730 if ((breakpoint_enabled (bl
->owner
)
2731 || bl
->owner
->enable_state
== bp_permanent
)
2732 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2735 if (overlay_debugging
2736 && section_is_overlay (bl
->section
)
2737 && !section_is_mapped (bl
->section
))
2738 continue; /* unmapped overlay -- can't be a match */
2739 else if (bl
->owner
->enable_state
== bp_permanent
)
2740 return permanent_breakpoint_here
;
2742 any_breakpoint_here
= 1;
2746 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2749 /* Return true if there's a moribund breakpoint at PC. */
2752 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2754 struct bp_location
*loc
;
2757 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2758 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2765 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2766 inserted using regular breakpoint_chain / bp_location array
2767 mechanism. This does not check for single-step breakpoints, which
2768 are inserted and removed using direct target manipulation. */
2771 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2774 struct bp_location
*bl
, **blp_tmp
;
2776 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2778 if (bl
->loc_type
!= bp_loc_software_breakpoint
2779 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2783 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2786 if (overlay_debugging
2787 && section_is_overlay (bl
->section
)
2788 && !section_is_mapped (bl
->section
))
2789 continue; /* unmapped overlay -- can't be a match */
2797 /* Returns non-zero iff there's either regular breakpoint
2798 or a single step breakpoint inserted at PC. */
2801 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2803 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2806 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2812 /* This function returns non-zero iff there is a software breakpoint
2816 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2819 struct bp_location
*bl
, **blp_tmp
;
2821 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2823 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2827 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2830 if (overlay_debugging
2831 && section_is_overlay (bl
->section
)
2832 && !section_is_mapped (bl
->section
))
2833 continue; /* unmapped overlay -- can't be a match */
2839 /* Also check for software single-step breakpoints. */
2840 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2847 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2848 CORE_ADDR addr
, ULONGEST len
)
2850 struct breakpoint
*bpt
;
2852 ALL_BREAKPOINTS (bpt
)
2854 struct bp_location
*loc
;
2856 if (bpt
->type
!= bp_hardware_watchpoint
2857 && bpt
->type
!= bp_access_watchpoint
)
2860 if (!breakpoint_enabled (bpt
))
2863 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2864 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2868 /* Check for intersection. */
2869 l
= max (loc
->address
, addr
);
2870 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2878 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2879 PC is valid for process/thread PTID. */
2882 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2885 struct bp_location
*bl
, **blp_tmp
;
2886 /* The thread and task IDs associated to PTID, computed lazily. */
2890 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2892 if (bl
->loc_type
!= bp_loc_software_breakpoint
2893 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2896 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2897 if (!breakpoint_enabled (bl
->owner
)
2898 && bl
->owner
->enable_state
!= bp_permanent
)
2901 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2905 if (bl
->owner
->thread
!= -1)
2907 /* This is a thread-specific breakpoint. Check that ptid
2908 matches that thread. If thread hasn't been computed yet,
2909 it is now time to do so. */
2911 thread
= pid_to_thread_id (ptid
);
2912 if (bl
->owner
->thread
!= thread
)
2916 if (bl
->owner
->task
!= 0)
2918 /* This is a task-specific breakpoint. Check that ptid
2919 matches that task. If task hasn't been computed yet,
2920 it is now time to do so. */
2922 task
= ada_get_task_number (ptid
);
2923 if (bl
->owner
->task
!= task
)
2927 if (overlay_debugging
2928 && section_is_overlay (bl
->section
)
2929 && !section_is_mapped (bl
->section
))
2930 continue; /* unmapped overlay -- can't be a match */
2939 /* bpstat stuff. External routines' interfaces are documented
2943 ep_is_catchpoint (struct breakpoint
*ep
)
2945 return (ep
->type
== bp_catchpoint
);
2948 /* Frees any storage that is part of a bpstat. Does not walk the
2952 bpstat_free (bpstat bs
)
2954 if (bs
->old_val
!= NULL
)
2955 value_free (bs
->old_val
);
2956 decref_counted_command_line (&bs
->commands
);
2957 decref_bp_location (&bs
->bp_location_at
);
2961 /* Clear a bpstat so that it says we are not at any breakpoint.
2962 Also free any storage that is part of a bpstat. */
2965 bpstat_clear (bpstat
*bsp
)
2982 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2983 is part of the bpstat is copied as well. */
2986 bpstat_copy (bpstat bs
)
2990 bpstat retval
= NULL
;
2995 for (; bs
!= NULL
; bs
= bs
->next
)
2997 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2998 memcpy (tmp
, bs
, sizeof (*tmp
));
2999 incref_counted_command_line (tmp
->commands
);
3000 incref_bp_location (tmp
->bp_location_at
);
3001 if (bs
->old_val
!= NULL
)
3003 tmp
->old_val
= value_copy (bs
->old_val
);
3004 release_value (tmp
->old_val
);
3008 /* This is the first thing in the chain. */
3018 /* Find the bpstat associated with this breakpoint. */
3021 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3026 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3028 if (bsp
->breakpoint_at
== breakpoint
)
3034 /* Put in *NUM the breakpoint number of the first breakpoint we are
3035 stopped at. *BSP upon return is a bpstat which points to the
3036 remaining breakpoints stopped at (but which is not guaranteed to be
3037 good for anything but further calls to bpstat_num).
3039 Return 0 if passed a bpstat which does not indicate any breakpoints.
3040 Return -1 if stopped at a breakpoint that has been deleted since
3042 Return 1 otherwise. */
3045 bpstat_num (bpstat
*bsp
, int *num
)
3047 struct breakpoint
*b
;
3050 return 0; /* No more breakpoint values */
3052 /* We assume we'll never have several bpstats that correspond to a
3053 single breakpoint -- otherwise, this function might return the
3054 same number more than once and this will look ugly. */
3055 b
= (*bsp
)->breakpoint_at
;
3056 *bsp
= (*bsp
)->next
;
3058 return -1; /* breakpoint that's been deleted since */
3060 *num
= b
->number
; /* We have its number */
3064 /* Modify BS so that the actions will not be performed. */
3067 bpstat_clear_actions (bpstat bs
)
3069 for (; bs
!= NULL
; bs
= bs
->next
)
3071 decref_counted_command_line (&bs
->commands
);
3072 bs
->commands_left
= NULL
;
3073 if (bs
->old_val
!= NULL
)
3075 value_free (bs
->old_val
);
3081 /* Called when a command is about to proceed the inferior. */
3084 breakpoint_about_to_proceed (void)
3086 if (!ptid_equal (inferior_ptid
, null_ptid
))
3088 struct thread_info
*tp
= inferior_thread ();
3090 /* Allow inferior function calls in breakpoint commands to not
3091 interrupt the command list. When the call finishes
3092 successfully, the inferior will be standing at the same
3093 breakpoint as if nothing happened. */
3094 if (tp
->control
.in_infcall
)
3098 breakpoint_proceeded
= 1;
3101 /* Stub for cleaning up our state if we error-out of a breakpoint
3104 cleanup_executing_breakpoints (void *ignore
)
3106 executing_breakpoint_commands
= 0;
3109 /* Execute all the commands associated with all the breakpoints at
3110 this location. Any of these commands could cause the process to
3111 proceed beyond this point, etc. We look out for such changes by
3112 checking the global "breakpoint_proceeded" after each command.
3114 Returns true if a breakpoint command resumed the inferior. In that
3115 case, it is the caller's responsibility to recall it again with the
3116 bpstat of the current thread. */
3119 bpstat_do_actions_1 (bpstat
*bsp
)
3122 struct cleanup
*old_chain
;
3125 /* Avoid endless recursion if a `source' command is contained
3127 if (executing_breakpoint_commands
)
3130 executing_breakpoint_commands
= 1;
3131 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3133 /* This pointer will iterate over the list of bpstat's. */
3136 breakpoint_proceeded
= 0;
3137 for (; bs
!= NULL
; bs
= bs
->next
)
3139 struct counted_command_line
*ccmd
;
3140 struct command_line
*cmd
;
3141 struct cleanup
*this_cmd_tree_chain
;
3143 /* Take ownership of the BSP's command tree, if it has one.
3145 The command tree could legitimately contain commands like
3146 'step' and 'next', which call clear_proceed_status, which
3147 frees stop_bpstat's command tree. To make sure this doesn't
3148 free the tree we're executing out from under us, we need to
3149 take ownership of the tree ourselves. Since a given bpstat's
3150 commands are only executed once, we don't need to copy it; we
3151 can clear the pointer in the bpstat, and make sure we free
3152 the tree when we're done. */
3153 ccmd
= bs
->commands
;
3154 bs
->commands
= NULL
;
3156 = make_cleanup_decref_counted_command_line (&ccmd
);
3157 cmd
= bs
->commands_left
;
3158 bs
->commands_left
= NULL
;
3162 execute_control_command (cmd
);
3164 if (breakpoint_proceeded
)
3170 /* We can free this command tree now. */
3171 do_cleanups (this_cmd_tree_chain
);
3173 if (breakpoint_proceeded
)
3175 if (target_can_async_p ())
3176 /* If we are in async mode, then the target might be still
3177 running, not stopped at any breakpoint, so nothing for
3178 us to do here -- just return to the event loop. */
3181 /* In sync mode, when execute_control_command returns
3182 we're already standing on the next breakpoint.
3183 Breakpoint commands for that stop were not run, since
3184 execute_command does not run breakpoint commands --
3185 only command_line_handler does, but that one is not
3186 involved in execution of breakpoint commands. So, we
3187 can now execute breakpoint commands. It should be
3188 noted that making execute_command do bpstat actions is
3189 not an option -- in this case we'll have recursive
3190 invocation of bpstat for each breakpoint with a
3191 command, and can easily blow up GDB stack. Instead, we
3192 return true, which will trigger the caller to recall us
3193 with the new stop_bpstat. */
3198 do_cleanups (old_chain
);
3203 bpstat_do_actions (void)
3205 /* Do any commands attached to breakpoint we are stopped at. */
3206 while (!ptid_equal (inferior_ptid
, null_ptid
)
3207 && target_has_execution
3208 && !is_exited (inferior_ptid
)
3209 && !is_executing (inferior_ptid
))
3210 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3211 and only return when it is stopped at the next breakpoint, we
3212 keep doing breakpoint actions until it returns false to
3213 indicate the inferior was not resumed. */
3214 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3218 /* Print out the (old or new) value associated with a watchpoint. */
3221 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3224 fprintf_unfiltered (stream
, _("<unreadable>"));
3227 struct value_print_options opts
;
3228 get_user_print_options (&opts
);
3229 value_print (val
, stream
, &opts
);
3233 /* This is the normal print function for a bpstat. In the future,
3234 much of this logic could (should?) be moved to bpstat_stop_status,
3235 by having it set different print_it values.
3237 Current scheme: When we stop, bpstat_print() is called. It loops
3238 through the bpstat list of things causing this stop, calling the
3239 print_bp_stop_message function on each one. The behavior of the
3240 print_bp_stop_message function depends on the print_it field of
3241 bpstat. If such field so indicates, call this function here.
3243 Return values from this routine (ultimately used by bpstat_print()
3244 and normal_stop() to decide what to do):
3245 PRINT_NOTHING: Means we already printed all we needed to print,
3246 don't print anything else.
3247 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3248 that something to be followed by a location.
3249 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3250 that something to be followed by a location.
3251 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3254 static enum print_stop_action
3255 print_it_typical (bpstat bs
)
3257 struct cleanup
*old_chain
;
3258 struct breakpoint
*b
;
3259 const struct bp_location
*bl
;
3260 struct ui_stream
*stb
;
3262 enum print_stop_action result
;
3264 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3265 which has since been deleted. */
3266 if (bs
->breakpoint_at
== NULL
)
3267 return PRINT_UNKNOWN
;
3269 gdb_assert (bs
->bp_location_at
!= NULL
);
3271 bl
= bs
->bp_location_at
;
3272 b
= bs
->breakpoint_at
;
3274 stb
= ui_out_stream_new (uiout
);
3275 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3280 case bp_hardware_breakpoint
:
3281 bp_temp
= b
->disposition
== disp_del
;
3282 if (bl
->address
!= bl
->requested_address
)
3283 breakpoint_adjustment_warning (bl
->requested_address
,
3286 annotate_breakpoint (b
->number
);
3288 ui_out_text (uiout
, "\nTemporary breakpoint ");
3290 ui_out_text (uiout
, "\nBreakpoint ");
3291 if (ui_out_is_mi_like_p (uiout
))
3293 ui_out_field_string (uiout
, "reason",
3294 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3295 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3297 ui_out_field_int (uiout
, "bkptno", b
->number
);
3298 ui_out_text (uiout
, ", ");
3299 result
= PRINT_SRC_AND_LOC
;
3302 case bp_shlib_event
:
3303 /* Did we stop because the user set the stop_on_solib_events
3304 variable? (If so, we report this as a generic, "Stopped due
3305 to shlib event" message.) */
3306 printf_filtered (_("Stopped due to shared library event\n"));
3307 result
= PRINT_NOTHING
;
3310 case bp_thread_event
:
3311 /* Not sure how we will get here.
3312 GDB should not stop for these breakpoints. */
3313 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3314 result
= PRINT_NOTHING
;
3317 case bp_overlay_event
:
3318 /* By analogy with the thread event, GDB should not stop for these. */
3319 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3320 result
= PRINT_NOTHING
;
3323 case bp_longjmp_master
:
3324 /* These should never be enabled. */
3325 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3326 result
= PRINT_NOTHING
;
3329 case bp_std_terminate_master
:
3330 /* These should never be enabled. */
3331 printf_filtered (_("std::terminate Master Breakpoint: "
3332 "gdb should not stop!\n"));
3333 result
= PRINT_NOTHING
;
3336 case bp_exception_master
:
3337 /* These should never be enabled. */
3338 printf_filtered (_("Exception Master Breakpoint: "
3339 "gdb should not stop!\n"));
3340 result
= PRINT_NOTHING
;
3344 case bp_hardware_watchpoint
:
3345 annotate_watchpoint (b
->number
);
3346 if (ui_out_is_mi_like_p (uiout
))
3349 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3351 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3352 ui_out_text (uiout
, "\nOld value = ");
3353 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3354 ui_out_field_stream (uiout
, "old", stb
);
3355 ui_out_text (uiout
, "\nNew value = ");
3356 watchpoint_value_print (b
->val
, stb
->stream
);
3357 ui_out_field_stream (uiout
, "new", stb
);
3358 ui_out_text (uiout
, "\n");
3359 /* More than one watchpoint may have been triggered. */
3360 result
= PRINT_UNKNOWN
;
3363 case bp_read_watchpoint
:
3364 if (ui_out_is_mi_like_p (uiout
))
3367 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3369 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3370 ui_out_text (uiout
, "\nValue = ");
3371 watchpoint_value_print (b
->val
, stb
->stream
);
3372 ui_out_field_stream (uiout
, "value", stb
);
3373 ui_out_text (uiout
, "\n");
3374 result
= PRINT_UNKNOWN
;
3377 case bp_access_watchpoint
:
3378 if (bs
->old_val
!= NULL
)
3380 annotate_watchpoint (b
->number
);
3381 if (ui_out_is_mi_like_p (uiout
))
3384 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3386 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3387 ui_out_text (uiout
, "\nOld value = ");
3388 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3389 ui_out_field_stream (uiout
, "old", stb
);
3390 ui_out_text (uiout
, "\nNew value = ");
3395 if (ui_out_is_mi_like_p (uiout
))
3398 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3399 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3400 ui_out_text (uiout
, "\nValue = ");
3402 watchpoint_value_print (b
->val
, stb
->stream
);
3403 ui_out_field_stream (uiout
, "new", stb
);
3404 ui_out_text (uiout
, "\n");
3405 result
= PRINT_UNKNOWN
;
3408 /* Fall through, we don't deal with these types of breakpoints
3412 if (ui_out_is_mi_like_p (uiout
))
3415 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3416 result
= PRINT_UNKNOWN
;
3420 if (ui_out_is_mi_like_p (uiout
))
3423 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3424 result
= PRINT_UNKNOWN
;
3429 case bp_longjmp_resume
:
3431 case bp_exception_resume
:
3432 case bp_step_resume
:
3433 case bp_watchpoint_scope
:
3435 case bp_std_terminate
:
3437 case bp_fast_tracepoint
:
3440 result
= PRINT_UNKNOWN
;
3444 do_cleanups (old_chain
);
3448 /* Generic routine for printing messages indicating why we
3449 stopped. The behavior of this function depends on the value
3450 'print_it' in the bpstat structure. Under some circumstances we
3451 may decide not to print anything here and delegate the task to
3454 static enum print_stop_action
3455 print_bp_stop_message (bpstat bs
)
3457 switch (bs
->print_it
)
3460 /* Nothing should be printed for this bpstat entry. */
3461 return PRINT_UNKNOWN
;
3465 /* We still want to print the frame, but we already printed the
3466 relevant messages. */
3467 return PRINT_SRC_AND_LOC
;
3470 case print_it_normal
:
3472 struct breakpoint
*b
= bs
->breakpoint_at
;
3474 /* Normal case. Call the breakpoint's print_it method, or
3475 print_it_typical. */
3476 /* FIXME: how breakpoint can ever be NULL here? */
3477 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3478 return b
->ops
->print_it (b
);
3480 return print_it_typical (bs
);
3485 internal_error (__FILE__
, __LINE__
,
3486 _("print_bp_stop_message: unrecognized enum value"));
3491 /* Print a message indicating what happened. This is called from
3492 normal_stop(). The input to this routine is the head of the bpstat
3493 list - a list of the eventpoints that caused this stop. This
3494 routine calls the generic print routine for printing a message
3495 about reasons for stopping. This will print (for example) the
3496 "Breakpoint n," part of the output. The return value of this
3499 PRINT_UNKNOWN: Means we printed nothing.
3500 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3501 code to print the location. An example is
3502 "Breakpoint 1, " which should be followed by
3504 PRINT_SRC_ONLY: Means we printed something, but there is no need
3505 to also print the location part of the message.
3506 An example is the catch/throw messages, which
3507 don't require a location appended to the end.
3508 PRINT_NOTHING: We have done some printing and we don't need any
3509 further info to be printed. */
3511 enum print_stop_action
3512 bpstat_print (bpstat bs
)
3516 /* Maybe another breakpoint in the chain caused us to stop.
3517 (Currently all watchpoints go on the bpstat whether hit or not.
3518 That probably could (should) be changed, provided care is taken
3519 with respect to bpstat_explains_signal). */
3520 for (; bs
; bs
= bs
->next
)
3522 val
= print_bp_stop_message (bs
);
3523 if (val
== PRINT_SRC_ONLY
3524 || val
== PRINT_SRC_AND_LOC
3525 || val
== PRINT_NOTHING
)
3529 /* We reached the end of the chain, or we got a null BS to start
3530 with and nothing was printed. */
3531 return PRINT_UNKNOWN
;
3534 /* Evaluate the expression EXP and return 1 if value is zero. This is
3535 used inside a catch_errors to evaluate the breakpoint condition.
3536 The argument is a "struct expression *" that has been cast to a
3537 "char *" to make it pass through catch_errors. */
3540 breakpoint_cond_eval (void *exp
)
3542 struct value
*mark
= value_mark ();
3543 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3545 value_free_to_mark (mark
);
3549 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3552 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3556 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3558 **bs_link_pointer
= bs
;
3559 *bs_link_pointer
= &bs
->next
;
3560 bs
->breakpoint_at
= bl
->owner
;
3561 bs
->bp_location_at
= bl
;
3562 incref_bp_location (bl
);
3563 /* If the condition is false, etc., don't do the commands. */
3564 bs
->commands
= NULL
;
3565 bs
->commands_left
= NULL
;
3567 bs
->print_it
= print_it_normal
;
3571 /* The target has stopped with waitstatus WS. Check if any hardware
3572 watchpoints have triggered, according to the target. */
3575 watchpoints_triggered (struct target_waitstatus
*ws
)
3577 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3579 struct breakpoint
*b
;
3581 if (!stopped_by_watchpoint
)
3583 /* We were not stopped by a watchpoint. Mark all watchpoints
3584 as not triggered. */
3586 if (is_hardware_watchpoint (b
))
3587 b
->watchpoint_triggered
= watch_triggered_no
;
3592 if (!target_stopped_data_address (¤t_target
, &addr
))
3594 /* We were stopped by a watchpoint, but we don't know where.
3595 Mark all watchpoints as unknown. */
3597 if (is_hardware_watchpoint (b
))
3598 b
->watchpoint_triggered
= watch_triggered_unknown
;
3600 return stopped_by_watchpoint
;
3603 /* The target could report the data address. Mark watchpoints
3604 affected by this data address as triggered, and all others as not
3608 if (is_hardware_watchpoint (b
))
3610 struct bp_location
*loc
;
3612 b
->watchpoint_triggered
= watch_triggered_no
;
3613 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3614 /* Exact match not required. Within range is
3616 if (target_watchpoint_addr_within_range (¤t_target
,
3620 b
->watchpoint_triggered
= watch_triggered_yes
;
3628 /* Possible return values for watchpoint_check (this can't be an enum
3629 because of check_errors). */
3630 /* The watchpoint has been deleted. */
3631 #define WP_DELETED 1
3632 /* The value has changed. */
3633 #define WP_VALUE_CHANGED 2
3634 /* The value has not changed. */
3635 #define WP_VALUE_NOT_CHANGED 3
3636 /* Ignore this watchpoint, no matter if the value changed or not. */
3639 #define BP_TEMPFLAG 1
3640 #define BP_HARDWAREFLAG 2
3642 /* Evaluate watchpoint condition expression and check if its value
3645 P should be a pointer to struct bpstat, but is defined as a void *
3646 in order for this function to be usable with catch_errors. */
3649 watchpoint_check (void *p
)
3651 bpstat bs
= (bpstat
) p
;
3652 struct breakpoint
*b
;
3653 struct frame_info
*fr
;
3654 int within_current_scope
;
3656 /* BS is built from an existing struct breakpoint. */
3657 gdb_assert (bs
->breakpoint_at
!= NULL
);
3658 b
= bs
->breakpoint_at
;
3660 /* If this is a local watchpoint, we only want to check if the
3661 watchpoint frame is in scope if the current thread is the thread
3662 that was used to create the watchpoint. */
3663 if (!watchpoint_in_thread_scope (b
))
3666 if (b
->exp_valid_block
== NULL
)
3667 within_current_scope
= 1;
3670 struct frame_info
*frame
= get_current_frame ();
3671 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3672 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3674 /* in_function_epilogue_p() returns a non-zero value if we're
3675 still in the function but the stack frame has already been
3676 invalidated. Since we can't rely on the values of local
3677 variables after the stack has been destroyed, we are treating
3678 the watchpoint in that state as `not changed' without further
3679 checking. Don't mark watchpoints as changed if the current
3680 frame is in an epilogue - even if they are in some other
3681 frame, our view of the stack is likely to be wrong and
3682 frame_find_by_id could error out. */
3683 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3686 fr
= frame_find_by_id (b
->watchpoint_frame
);
3687 within_current_scope
= (fr
!= NULL
);
3689 /* If we've gotten confused in the unwinder, we might have
3690 returned a frame that can't describe this variable. */
3691 if (within_current_scope
)
3693 struct symbol
*function
;
3695 function
= get_frame_function (fr
);
3696 if (function
== NULL
3697 || !contained_in (b
->exp_valid_block
,
3698 SYMBOL_BLOCK_VALUE (function
)))
3699 within_current_scope
= 0;
3702 if (within_current_scope
)
3703 /* If we end up stopping, the current frame will get selected
3704 in normal_stop. So this call to select_frame won't affect
3709 if (within_current_scope
)
3711 /* We use value_{,free_to_}mark because it could be a *long*
3712 time before we return to the command level and call
3713 free_all_values. We can't call free_all_values because we
3714 might be in the middle of evaluating a function call. */
3717 struct value
*mark
= value_mark ();
3718 struct value
*new_val
;
3720 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3722 /* We use value_equal_contents instead of value_equal because
3723 the latter coerces an array to a pointer, thus comparing just
3724 the address of the array instead of its contents. This is
3725 not what we want. */
3726 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3727 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3729 if (new_val
!= NULL
)
3731 release_value (new_val
);
3732 value_free_to_mark (mark
);
3734 bs
->old_val
= b
->val
;
3737 return WP_VALUE_CHANGED
;
3741 /* Nothing changed. */
3742 value_free_to_mark (mark
);
3743 return WP_VALUE_NOT_CHANGED
;
3748 /* This seems like the only logical thing to do because
3749 if we temporarily ignored the watchpoint, then when
3750 we reenter the block in which it is valid it contains
3751 garbage (in the case of a function, it may have two
3752 garbage values, one before and one after the prologue).
3753 So we can't even detect the first assignment to it and
3754 watch after that (since the garbage may or may not equal
3755 the first value assigned). */
3756 /* We print all the stop information in print_it_typical(), but
3757 in this case, by the time we call print_it_typical() this bp
3758 will be deleted already. So we have no choice but print the
3759 information here. */
3760 if (ui_out_is_mi_like_p (uiout
))
3762 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3763 ui_out_text (uiout
, "\nWatchpoint ");
3764 ui_out_field_int (uiout
, "wpnum", b
->number
);
3766 " deleted because the program has left the block in\n\
3767 which its expression is valid.\n");
3769 if (b
->related_breakpoint
)
3771 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3772 b
->related_breakpoint
->related_breakpoint
= NULL
;
3773 b
->related_breakpoint
= NULL
;
3775 b
->disposition
= disp_del_at_next_stop
;
3781 /* Return true if it looks like target has stopped due to hitting
3782 breakpoint location BL. This function does not check if we
3783 should stop, only if BL explains the stop. */
3785 bpstat_check_location (const struct bp_location
*bl
,
3786 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3788 struct breakpoint
*b
= bl
->owner
;
3790 /* BL is from existing struct breakpoint. */
3791 gdb_assert (b
!= NULL
);
3793 /* By definition, the inferior does not report stops at
3795 if (is_tracepoint (b
))
3798 if (!is_watchpoint (b
)
3799 && b
->type
!= bp_hardware_breakpoint
3800 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3802 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3805 if (overlay_debugging
/* unmapped overlay section */
3806 && section_is_overlay (bl
->section
)
3807 && !section_is_mapped (bl
->section
))
3811 /* Continuable hardware watchpoints are treated as non-existent if the
3812 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3813 some data address). Otherwise gdb won't stop on a break instruction
3814 in the code (not from a breakpoint) when a hardware watchpoint has
3815 been defined. Also skip watchpoints which we know did not trigger
3816 (did not match the data address). */
3818 if (is_hardware_watchpoint (b
)
3819 && b
->watchpoint_triggered
== watch_triggered_no
)
3822 if (b
->type
== bp_hardware_breakpoint
)
3824 if (bl
->address
!= bp_addr
)
3826 if (overlay_debugging
/* unmapped overlay section */
3827 && section_is_overlay (bl
->section
)
3828 && !section_is_mapped (bl
->section
))
3832 if (b
->type
== bp_catchpoint
)
3834 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3835 if (!b
->ops
->breakpoint_hit (b
))
3842 /* If BS refers to a watchpoint, determine if the watched values
3843 has actually changed, and we should stop. If not, set BS->stop
3846 bpstat_check_watchpoint (bpstat bs
)
3848 const struct bp_location
*bl
;
3849 struct breakpoint
*b
;
3851 /* BS is built for existing struct breakpoint. */
3852 bl
= bs
->bp_location_at
;
3853 gdb_assert (bl
!= NULL
);
3854 b
= bs
->breakpoint_at
;
3855 gdb_assert (b
!= NULL
);
3857 if (is_watchpoint (b
))
3859 int must_check_value
= 0;
3861 if (b
->type
== bp_watchpoint
)
3862 /* For a software watchpoint, we must always check the
3864 must_check_value
= 1;
3865 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3866 /* We have a hardware watchpoint (read, write, or access)
3867 and the target earlier reported an address watched by
3869 must_check_value
= 1;
3870 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3871 && b
->type
== bp_hardware_watchpoint
)
3872 /* We were stopped by a hardware watchpoint, but the target could
3873 not report the data address. We must check the watchpoint's
3874 value. Access and read watchpoints are out of luck; without
3875 a data address, we can't figure it out. */
3876 must_check_value
= 1;
3878 if (must_check_value
)
3881 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3883 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3884 int e
= catch_errors (watchpoint_check
, bs
, message
,
3886 do_cleanups (cleanups
);
3890 /* We've already printed what needs to be printed. */
3891 bs
->print_it
= print_it_done
;
3895 bs
->print_it
= print_it_noop
;
3898 case WP_VALUE_CHANGED
:
3899 if (b
->type
== bp_read_watchpoint
)
3901 /* There are two cases to consider here:
3903 1. We're watching the triggered memory for reads.
3904 In that case, trust the target, and always report
3905 the watchpoint hit to the user. Even though
3906 reads don't cause value changes, the value may
3907 have changed since the last time it was read, and
3908 since we're not trapping writes, we will not see
3909 those, and as such we should ignore our notion of
3912 2. We're watching the triggered memory for both
3913 reads and writes. There are two ways this may
3916 2.1. This is a target that can't break on data
3917 reads only, but can break on accesses (reads or
3918 writes), such as e.g., x86. We detect this case
3919 at the time we try to insert read watchpoints.
3921 2.2. Otherwise, the target supports read
3922 watchpoints, but, the user set an access or write
3923 watchpoint watching the same memory as this read
3926 If we're watching memory writes as well as reads,
3927 ignore watchpoint hits when we find that the
3928 value hasn't changed, as reads don't cause
3929 changes. This still gives false positives when
3930 the program writes the same value to memory as
3931 what there was already in memory (we will confuse
3932 it for a read), but it's much better than
3935 int other_write_watchpoint
= 0;
3937 if (bl
->watchpoint_type
== hw_read
)
3939 struct breakpoint
*other_b
;
3941 ALL_BREAKPOINTS (other_b
)
3942 if ((other_b
->type
== bp_hardware_watchpoint
3943 || other_b
->type
== bp_access_watchpoint
)
3944 && (other_b
->watchpoint_triggered
3945 == watch_triggered_yes
))
3947 other_write_watchpoint
= 1;
3952 if (other_write_watchpoint
3953 || bl
->watchpoint_type
== hw_access
)
3955 /* We're watching the same memory for writes,
3956 and the value changed since the last time we
3957 updated it, so this trap must be for a write.
3959 bs
->print_it
= print_it_noop
;
3964 case WP_VALUE_NOT_CHANGED
:
3965 if (b
->type
== bp_hardware_watchpoint
3966 || b
->type
== bp_watchpoint
)
3968 /* Don't stop: write watchpoints shouldn't fire if
3969 the value hasn't changed. */
3970 bs
->print_it
= print_it_noop
;
3978 /* Error from catch_errors. */
3979 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3980 if (b
->related_breakpoint
)
3981 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3982 b
->disposition
= disp_del_at_next_stop
;
3983 /* We've already printed what needs to be printed. */
3984 bs
->print_it
= print_it_done
;
3988 else /* must_check_value == 0 */
3990 /* This is a case where some watchpoint(s) triggered, but
3991 not at the address of this watchpoint, or else no
3992 watchpoint triggered after all. So don't print
3993 anything for this watchpoint. */
3994 bs
->print_it
= print_it_noop
;
4001 /* Check conditions (condition proper, frame, thread and ignore count)
4002 of breakpoint referred to by BS. If we should not stop for this
4003 breakpoint, set BS->stop to 0. */
4006 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4008 int thread_id
= pid_to_thread_id (ptid
);
4009 const struct bp_location
*bl
;
4010 struct breakpoint
*b
;
4012 /* BS is built for existing struct breakpoint. */
4013 bl
= bs
->bp_location_at
;
4014 gdb_assert (bl
!= NULL
);
4015 b
= bs
->breakpoint_at
;
4016 gdb_assert (b
!= NULL
);
4018 if (frame_id_p (b
->frame_id
)
4019 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4023 int value_is_zero
= 0;
4024 struct expression
*cond
;
4026 if (is_watchpoint (b
))
4031 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4033 int within_current_scope
= 1;
4035 /* We use value_mark and value_free_to_mark because it could
4036 be a long time before we return to the command level and
4037 call free_all_values. We can't call free_all_values
4038 because we might be in the middle of evaluating a
4040 struct value
*mark
= value_mark ();
4042 /* Need to select the frame, with all that implies so that
4043 the conditions will have the right context. Because we
4044 use the frame, we will not see an inlined function's
4045 variables when we arrive at a breakpoint at the start
4046 of the inlined function; the current frame will be the
4048 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
4049 select_frame (get_current_frame ());
4052 struct frame_info
*frame
;
4054 /* For local watchpoint expressions, which particular
4055 instance of a local is being watched matters, so we
4056 keep track of the frame to evaluate the expression
4057 in. To evaluate the condition however, it doesn't
4058 really matter which instantiation of the function
4059 where the condition makes sense triggers the
4060 watchpoint. This allows an expression like "watch
4061 global if q > 10" set in `func', catch writes to
4062 global on all threads that call `func', or catch
4063 writes on all recursive calls of `func' by a single
4064 thread. We simply always evaluate the condition in
4065 the innermost frame that's executing where it makes
4066 sense to evaluate the condition. It seems
4068 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
4070 select_frame (frame
);
4072 within_current_scope
= 0;
4074 if (within_current_scope
)
4076 = catch_errors (breakpoint_cond_eval
, cond
,
4077 "Error in testing breakpoint condition:\n",
4081 warning (_("Watchpoint condition cannot be tested "
4082 "in the current scope"));
4083 /* If we failed to set the right context for this
4084 watchpoint, unconditionally report it. */
4087 /* FIXME-someday, should give breakpoint #. */
4088 value_free_to_mark (mark
);
4091 if (cond
&& value_is_zero
)
4095 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4099 else if (b
->ignore_count
> 0)
4102 annotate_ignore_count_change ();
4104 /* Increase the hit count even though we don't stop. */
4111 /* Get a bpstat associated with having just stopped at address
4112 BP_ADDR in thread PTID.
4114 Determine whether we stopped at a breakpoint, etc, or whether we
4115 don't understand this stop. Result is a chain of bpstat's such
4118 if we don't understand the stop, the result is a null pointer.
4120 if we understand why we stopped, the result is not null.
4122 Each element of the chain refers to a particular breakpoint or
4123 watchpoint at which we have stopped. (We may have stopped for
4124 several reasons concurrently.)
4126 Each element of the chain has valid next, breakpoint_at,
4127 commands, FIXME??? fields. */
4130 bpstat_stop_status (struct address_space
*aspace
,
4131 CORE_ADDR bp_addr
, ptid_t ptid
)
4133 struct breakpoint
*b
= NULL
;
4134 struct bp_location
*bl
;
4135 struct bp_location
*loc
;
4136 /* First item of allocated bpstat's. */
4137 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4138 /* Pointer to the last thing in the chain currently. */
4141 int need_remove_insert
;
4144 /* First, build the bpstat chain with locations that explain a
4145 target stop, while being careful to not set the target running,
4146 as that may invalidate locations (in particular watchpoint
4147 locations are recreated). Resuming will happen here with
4148 breakpoint conditions or watchpoint expressions that include
4149 inferior function calls. */
4153 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4156 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4158 /* For hardware watchpoints, we look only at the first
4159 location. The watchpoint_check function will work on the
4160 entire expression, not the individual locations. For
4161 read watchpoints, the watchpoints_triggered function has
4162 checked all locations already. */
4163 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4166 if (bl
->shlib_disabled
)
4169 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4172 /* Come here if it's a watchpoint, or if the break address
4175 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4178 /* Assume we stop. Should we find a watchpoint that is not
4179 actually triggered, or if the condition of the breakpoint
4180 evaluates as false, we'll reset 'stop' to 0. */
4184 /* If this is a scope breakpoint, mark the associated
4185 watchpoint as triggered so that we will handle the
4186 out-of-scope event. We'll get to the watchpoint next
4188 if (b
->type
== bp_watchpoint_scope
)
4189 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4193 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4195 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4198 bs
= bpstat_alloc (loc
, &bs_link
);
4199 /* For hits of moribund locations, we should just proceed. */
4202 bs
->print_it
= print_it_noop
;
4206 /* Now go through the locations that caused the target to stop, and
4207 check whether we're interested in reporting this stop to higher
4208 layers, or whether we should resume the target transparently. */
4212 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4217 bpstat_check_watchpoint (bs
);
4221 b
= bs
->breakpoint_at
;
4223 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4224 || b
->type
== bp_longjmp_master
4225 || b
->type
== bp_std_terminate_master
4226 || b
->type
== bp_exception_master
)
4227 /* We do not stop for these. */
4230 bpstat_check_breakpoint_conditions (bs
, ptid
);
4236 /* We will stop here. */
4237 if (b
->disposition
== disp_disable
)
4239 if (b
->enable_state
!= bp_permanent
)
4240 b
->enable_state
= bp_disabled
;
4245 bs
->commands
= b
->commands
;
4246 incref_counted_command_line (bs
->commands
);
4247 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4248 if (bs
->commands_left
4249 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4252 bs
->commands_left
->line
) == 0)))
4254 bs
->commands_left
= bs
->commands_left
->next
;
4259 /* Print nothing for this entry if we dont stop or dont print. */
4260 if (bs
->stop
== 0 || bs
->print
== 0)
4261 bs
->print_it
= print_it_noop
;
4264 /* If we aren't stopping, the value of some hardware watchpoint may
4265 not have changed, but the intermediate memory locations we are
4266 watching may have. Don't bother if we're stopping; this will get
4268 need_remove_insert
= 0;
4269 if (! bpstat_causes_stop (bs_head
))
4270 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4272 && bs
->breakpoint_at
4273 && is_hardware_watchpoint (bs
->breakpoint_at
))
4275 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4276 need_remove_insert
= 1;
4279 if (need_remove_insert
)
4280 update_global_location_list (1);
4281 else if (removed_any
)
4282 update_global_location_list (0);
4288 handle_jit_event (void)
4290 struct frame_info
*frame
;
4291 struct gdbarch
*gdbarch
;
4293 /* Switch terminal for any messages produced by
4294 breakpoint_re_set. */
4295 target_terminal_ours_for_output ();
4297 frame
= get_current_frame ();
4298 gdbarch
= get_frame_arch (frame
);
4300 jit_event_handler (gdbarch
);
4302 target_terminal_inferior ();
4305 /* Prepare WHAT final decision for infrun. */
4307 /* Decide what infrun needs to do with this bpstat. */
4310 bpstat_what (bpstat bs
)
4312 struct bpstat_what retval
;
4313 /* We need to defer calling `solib_add', as adding new symbols
4314 resets breakpoints, which in turn deletes breakpoint locations,
4315 and hence may clear unprocessed entries in the BS chain. */
4316 int shlib_event
= 0;
4319 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4320 retval
.call_dummy
= STOP_NONE
;
4321 retval
.is_longjmp
= 0;
4323 for (; bs
!= NULL
; bs
= bs
->next
)
4325 /* Extract this BS's action. After processing each BS, we check
4326 if its action overrides all we've seem so far. */
4327 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4330 if (bs
->breakpoint_at
== NULL
)
4332 /* I suspect this can happen if it was a momentary
4333 breakpoint which has since been deleted. */
4336 else if (bs
->breakpoint_at
== NULL
)
4339 bptype
= bs
->breakpoint_at
->type
;
4346 case bp_hardware_breakpoint
:
4352 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4354 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4357 this_action
= BPSTAT_WHAT_SINGLE
;
4360 case bp_hardware_watchpoint
:
4361 case bp_read_watchpoint
:
4362 case bp_access_watchpoint
:
4366 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4368 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4372 /* There was a watchpoint, but we're not stopping.
4373 This requires no further action. */
4378 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4379 retval
.is_longjmp
= bptype
== bp_longjmp
;
4381 case bp_longjmp_resume
:
4382 case bp_exception_resume
:
4383 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4384 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4386 case bp_step_resume
:
4388 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4391 /* It is for the wrong frame. */
4392 this_action
= BPSTAT_WHAT_SINGLE
;
4395 case bp_watchpoint_scope
:
4396 case bp_thread_event
:
4397 case bp_overlay_event
:
4398 case bp_longjmp_master
:
4399 case bp_std_terminate_master
:
4400 case bp_exception_master
:
4401 this_action
= BPSTAT_WHAT_SINGLE
;
4407 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4409 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4413 /* There was a catchpoint, but we're not stopping.
4414 This requires no further action. */
4417 case bp_shlib_event
:
4420 /* If requested, stop when the dynamic linker notifies GDB
4421 of events. This allows the user to get control and place
4422 breakpoints in initializer routines for dynamically
4423 loaded objects (among other things). */
4424 if (stop_on_solib_events
)
4425 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4427 this_action
= BPSTAT_WHAT_SINGLE
;
4431 this_action
= BPSTAT_WHAT_SINGLE
;
4434 /* Make sure the action is stop (silent or noisy),
4435 so infrun.c pops the dummy frame. */
4436 retval
.call_dummy
= STOP_STACK_DUMMY
;
4437 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4439 case bp_std_terminate
:
4440 /* Make sure the action is stop (silent or noisy),
4441 so infrun.c pops the dummy frame. */
4442 retval
.call_dummy
= STOP_STD_TERMINATE
;
4443 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4446 case bp_fast_tracepoint
:
4447 case bp_static_tracepoint
:
4448 /* Tracepoint hits should not be reported back to GDB, and
4449 if one got through somehow, it should have been filtered
4451 internal_error (__FILE__
, __LINE__
,
4452 _("bpstat_what: tracepoint encountered"));
4454 internal_error (__FILE__
, __LINE__
,
4455 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4458 retval
.main_action
= max (retval
.main_action
, this_action
);
4464 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4466 /* Check for any newly added shared libraries if we're supposed
4467 to be adding them automatically. */
4469 /* Switch terminal for any messages produced by
4470 breakpoint_re_set. */
4471 target_terminal_ours_for_output ();
4474 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4476 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4479 target_terminal_inferior ();
4485 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4487 handle_jit_event ();
4493 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4494 without hardware support). This isn't related to a specific bpstat,
4495 just to things like whether watchpoints are set. */
4498 bpstat_should_step (void)
4500 struct breakpoint
*b
;
4503 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4509 bpstat_causes_stop (bpstat bs
)
4511 for (; bs
!= NULL
; bs
= bs
->next
)
4520 /* Print the LOC location out of the list of B->LOC locations. */
4522 static void print_breakpoint_location (struct breakpoint
*b
,
4523 struct bp_location
*loc
,
4525 struct ui_stream
*stb
)
4527 struct cleanup
*old_chain
= save_current_program_space ();
4529 if (loc
!= NULL
&& loc
->shlib_disabled
)
4533 set_current_program_space (loc
->pspace
);
4535 if (b
->source_file
&& loc
)
4538 = find_pc_sect_function (loc
->address
, loc
->section
);
4541 ui_out_text (uiout
, "in ");
4542 ui_out_field_string (uiout
, "func",
4543 SYMBOL_PRINT_NAME (sym
));
4544 ui_out_wrap_hint (uiout
, wrap_indent
);
4545 ui_out_text (uiout
, " at ");
4547 ui_out_field_string (uiout
, "file", b
->source_file
);
4548 ui_out_text (uiout
, ":");
4550 if (ui_out_is_mi_like_p (uiout
))
4552 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4553 char *fullname
= symtab_to_fullname (sal
.symtab
);
4556 ui_out_field_string (uiout
, "fullname", fullname
);
4559 ui_out_field_int (uiout
, "line", b
->line_number
);
4563 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4565 ui_out_field_stream (uiout
, "at", stb
);
4568 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4570 do_cleanups (old_chain
);
4574 bptype_string (enum bptype type
)
4576 struct ep_type_description
4581 static struct ep_type_description bptypes
[] =
4583 {bp_none
, "?deleted?"},
4584 {bp_breakpoint
, "breakpoint"},
4585 {bp_hardware_breakpoint
, "hw breakpoint"},
4586 {bp_until
, "until"},
4587 {bp_finish
, "finish"},
4588 {bp_watchpoint
, "watchpoint"},
4589 {bp_hardware_watchpoint
, "hw watchpoint"},
4590 {bp_read_watchpoint
, "read watchpoint"},
4591 {bp_access_watchpoint
, "acc watchpoint"},
4592 {bp_longjmp
, "longjmp"},
4593 {bp_longjmp_resume
, "longjmp resume"},
4594 {bp_exception
, "exception"},
4595 {bp_exception_resume
, "exception resume"},
4596 {bp_step_resume
, "step resume"},
4597 {bp_watchpoint_scope
, "watchpoint scope"},
4598 {bp_call_dummy
, "call dummy"},
4599 {bp_std_terminate
, "std::terminate"},
4600 {bp_shlib_event
, "shlib events"},
4601 {bp_thread_event
, "thread events"},
4602 {bp_overlay_event
, "overlay events"},
4603 {bp_longjmp_master
, "longjmp master"},
4604 {bp_std_terminate_master
, "std::terminate master"},
4605 {bp_exception_master
, "exception master"},
4606 {bp_catchpoint
, "catchpoint"},
4607 {bp_tracepoint
, "tracepoint"},
4608 {bp_fast_tracepoint
, "fast tracepoint"},
4609 {bp_static_tracepoint
, "static tracepoint"},
4610 {bp_jit_event
, "jit events"},
4613 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4614 || ((int) type
!= bptypes
[(int) type
].type
))
4615 internal_error (__FILE__
, __LINE__
,
4616 _("bptypes table does not describe type #%d."),
4619 return bptypes
[(int) type
].description
;
4622 /* Print B to gdb_stdout. */
4625 print_one_breakpoint_location (struct breakpoint
*b
,
4626 struct bp_location
*loc
,
4628 struct bp_location
**last_loc
,
4629 int print_address_bits
,
4632 struct command_line
*l
;
4633 static char bpenables
[] = "nynny";
4634 char wrap_indent
[80];
4635 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4636 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4637 struct cleanup
*bkpt_chain
;
4639 int header_of_multiple
= 0;
4640 int part_of_multiple
= (loc
!= NULL
);
4641 struct value_print_options opts
;
4643 get_user_print_options (&opts
);
4645 gdb_assert (!loc
|| loc_number
!= 0);
4646 /* See comment in print_one_breakpoint concerning treatment of
4647 breakpoints with single disabled location. */
4650 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4651 header_of_multiple
= 1;
4656 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4660 if (part_of_multiple
)
4663 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4664 ui_out_field_string (uiout
, "number", formatted
);
4669 ui_out_field_int (uiout
, "number", b
->number
);
4674 if (part_of_multiple
)
4675 ui_out_field_skip (uiout
, "type");
4677 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4681 if (part_of_multiple
)
4682 ui_out_field_skip (uiout
, "disp");
4684 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4689 if (part_of_multiple
)
4690 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4692 ui_out_field_fmt (uiout
, "enabled", "%c",
4693 bpenables
[(int) b
->enable_state
]);
4694 ui_out_spaces (uiout
, 2);
4698 strcpy (wrap_indent
, " ");
4699 if (opts
.addressprint
)
4701 if (print_address_bits
<= 32)
4702 strcat (wrap_indent
, " ");
4704 strcat (wrap_indent
, " ");
4707 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4709 /* Although the print_one can possibly print all locations,
4710 calling it here is not likely to get any nice result. So,
4711 make sure there's just one location. */
4712 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4713 b
->ops
->print_one (b
, last_loc
);
4719 internal_error (__FILE__
, __LINE__
,
4720 _("print_one_breakpoint: bp_none encountered\n"));
4724 case bp_hardware_watchpoint
:
4725 case bp_read_watchpoint
:
4726 case bp_access_watchpoint
:
4727 /* Field 4, the address, is omitted (which makes the columns
4728 not line up too nicely with the headers, but the effect
4729 is relatively readable). */
4730 if (opts
.addressprint
)
4731 ui_out_field_skip (uiout
, "addr");
4733 ui_out_field_string (uiout
, "what", b
->exp_string
);
4737 case bp_hardware_breakpoint
:
4741 case bp_longjmp_resume
:
4743 case bp_exception_resume
:
4744 case bp_step_resume
:
4745 case bp_watchpoint_scope
:
4747 case bp_std_terminate
:
4748 case bp_shlib_event
:
4749 case bp_thread_event
:
4750 case bp_overlay_event
:
4751 case bp_longjmp_master
:
4752 case bp_std_terminate_master
:
4753 case bp_exception_master
:
4755 case bp_fast_tracepoint
:
4756 case bp_static_tracepoint
:
4758 if (opts
.addressprint
)
4761 if (header_of_multiple
)
4762 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4763 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4764 ui_out_field_string (uiout
, "addr", "<PENDING>");
4766 ui_out_field_core_addr (uiout
, "addr",
4767 loc
->gdbarch
, loc
->address
);
4770 if (!header_of_multiple
)
4771 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4778 /* For backward compatibility, don't display inferiors unless there
4781 && !header_of_multiple
4783 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4784 && (number_of_program_spaces () > 1
4785 || number_of_inferiors () > 1)
4786 /* LOC is for existing B, it cannot be in
4787 moribund_locations and thus having NULL OWNER. */
4788 && loc
->owner
->type
!= bp_catchpoint
)))
4790 struct inferior
*inf
;
4793 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4795 if (inf
->pspace
== loc
->pspace
)
4800 ui_out_text (uiout
, " inf ");
4803 ui_out_text (uiout
, ", ");
4804 ui_out_text (uiout
, plongest (inf
->num
));
4809 if (!part_of_multiple
)
4811 if (b
->thread
!= -1)
4813 /* FIXME: This seems to be redundant and lost here; see the
4814 "stop only in" line a little further down. */
4815 ui_out_text (uiout
, " thread ");
4816 ui_out_field_int (uiout
, "thread", b
->thread
);
4818 else if (b
->task
!= 0)
4820 ui_out_text (uiout
, " task ");
4821 ui_out_field_int (uiout
, "task", b
->task
);
4825 ui_out_text (uiout
, "\n");
4827 if (!part_of_multiple
&& b
->static_trace_marker_id
)
4829 gdb_assert (b
->type
== bp_static_tracepoint
);
4831 ui_out_text (uiout
, "\tmarker id is ");
4832 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
4833 b
->static_trace_marker_id
);
4834 ui_out_text (uiout
, "\n");
4837 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4840 ui_out_text (uiout
, "\tstop only in stack frame at ");
4841 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4843 ui_out_field_core_addr (uiout
, "frame",
4844 b
->gdbarch
, b
->frame_id
.stack_addr
);
4845 ui_out_text (uiout
, "\n");
4848 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4850 /* We do not print the condition for Ada exception catchpoints
4851 because the condition is an internal implementation detail
4852 that we do not want to expose to the user. */
4854 if (is_tracepoint (b
))
4855 ui_out_text (uiout
, "\ttrace only if ");
4857 ui_out_text (uiout
, "\tstop only if ");
4858 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4859 ui_out_text (uiout
, "\n");
4862 if (!part_of_multiple
&& b
->thread
!= -1)
4864 /* FIXME should make an annotation for this. */
4865 ui_out_text (uiout
, "\tstop only in thread ");
4866 ui_out_field_int (uiout
, "thread", b
->thread
);
4867 ui_out_text (uiout
, "\n");
4870 if (!part_of_multiple
&& b
->hit_count
)
4872 /* FIXME should make an annotation for this. */
4873 if (ep_is_catchpoint (b
))
4874 ui_out_text (uiout
, "\tcatchpoint");
4876 ui_out_text (uiout
, "\tbreakpoint");
4877 ui_out_text (uiout
, " already hit ");
4878 ui_out_field_int (uiout
, "times", b
->hit_count
);
4879 if (b
->hit_count
== 1)
4880 ui_out_text (uiout
, " time\n");
4882 ui_out_text (uiout
, " times\n");
4885 /* Output the count also if it is zero, but only if this is mi.
4886 FIXME: Should have a better test for this. */
4887 if (ui_out_is_mi_like_p (uiout
))
4888 if (!part_of_multiple
&& b
->hit_count
== 0)
4889 ui_out_field_int (uiout
, "times", b
->hit_count
);
4891 if (!part_of_multiple
&& b
->ignore_count
)
4894 ui_out_text (uiout
, "\tignore next ");
4895 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4896 ui_out_text (uiout
, " hits\n");
4899 l
= b
->commands
? b
->commands
->commands
: NULL
;
4900 if (!part_of_multiple
&& l
)
4902 struct cleanup
*script_chain
;
4905 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4906 print_command_lines (uiout
, l
, 4);
4907 do_cleanups (script_chain
);
4910 if (!part_of_multiple
&& b
->pass_count
)
4912 annotate_field (10);
4913 ui_out_text (uiout
, "\tpass count ");
4914 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4915 ui_out_text (uiout
, " \n");
4918 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4921 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4922 else if (b
->exp_string
)
4923 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4926 do_cleanups (bkpt_chain
);
4927 do_cleanups (old_chain
);
4931 print_one_breakpoint (struct breakpoint
*b
,
4932 struct bp_location
**last_loc
,
4933 int print_address_bits
,
4936 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4937 print_address_bits
, allflag
);
4939 /* If this breakpoint has custom print function,
4940 it's already printed. Otherwise, print individual
4941 locations, if any. */
4942 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4944 /* If breakpoint has a single location that is disabled, we
4945 print it as if it had several locations, since otherwise it's
4946 hard to represent "breakpoint enabled, location disabled"
4949 Note that while hardware watchpoints have several locations
4950 internally, that's no a property exposed to user. */
4952 && !is_hardware_watchpoint (b
)
4953 && (b
->loc
->next
|| !b
->loc
->enabled
)
4954 && !ui_out_is_mi_like_p (uiout
))
4956 struct bp_location
*loc
;
4958 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4959 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4960 print_address_bits
, allflag
);
4966 breakpoint_address_bits (struct breakpoint
*b
)
4968 int print_address_bits
= 0;
4969 struct bp_location
*loc
;
4971 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4975 /* Software watchpoints that aren't watching memory don't have
4976 an address to print. */
4977 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4980 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4981 if (addr_bit
> print_address_bits
)
4982 print_address_bits
= addr_bit
;
4985 return print_address_bits
;
4988 struct captured_breakpoint_query_args
4994 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4996 struct captured_breakpoint_query_args
*args
= data
;
4997 struct breakpoint
*b
;
4998 struct bp_location
*dummy_loc
= NULL
;
5002 if (args
->bnum
== b
->number
)
5004 int print_address_bits
= breakpoint_address_bits (b
);
5006 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
5014 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5015 char **error_message
)
5017 struct captured_breakpoint_query_args args
;
5020 /* For the moment we don't trust print_one_breakpoint() to not throw
5022 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5023 error_message
, RETURN_MASK_ALL
) < 0)
5029 /* Return non-zero if B is user settable (breakpoints, watchpoints,
5030 catchpoints, et.al.). */
5033 user_settable_breakpoint (const struct breakpoint
*b
)
5035 return (b
->type
== bp_breakpoint
5036 || b
->type
== bp_catchpoint
5037 || b
->type
== bp_hardware_breakpoint
5038 || is_tracepoint (b
)
5039 || is_watchpoint (b
));
5042 /* Print information on user settable breakpoint (watchpoint, etc)
5043 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5044 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5045 FILTER is non-NULL, call it on each breakpoint and only include the
5046 ones for which it returns non-zero. Return the total number of
5047 breakpoints listed. */
5050 breakpoint_1 (int bnum
, int allflag
,
5051 int (*filter
) (const struct breakpoint
*))
5053 struct breakpoint
*b
;
5054 struct bp_location
*last_loc
= NULL
;
5055 int nr_printable_breakpoints
;
5056 struct cleanup
*bkpttbl_chain
;
5057 struct value_print_options opts
;
5058 int print_address_bits
= 0;
5059 int print_type_col_width
= 14;
5061 get_user_print_options (&opts
);
5063 /* Compute the number of rows in the table, as well as the size
5064 required for address fields. */
5065 nr_printable_breakpoints
= 0;
5068 || bnum
== b
->number
)
5070 /* If we have a filter, only list the breakpoints it accepts. */
5071 if (filter
&& !filter (b
))
5074 if (allflag
|| (user_settable_breakpoint (b
)
5077 int addr_bit
, type_len
;
5079 addr_bit
= breakpoint_address_bits (b
);
5080 if (addr_bit
> print_address_bits
)
5081 print_address_bits
= addr_bit
;
5083 type_len
= strlen (bptype_string (b
->type
));
5084 if (type_len
> print_type_col_width
)
5085 print_type_col_width
= type_len
;
5087 nr_printable_breakpoints
++;
5091 if (opts
.addressprint
)
5093 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5094 nr_printable_breakpoints
,
5098 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5099 nr_printable_breakpoints
,
5102 if (nr_printable_breakpoints
> 0)
5103 annotate_breakpoints_headers ();
5104 if (nr_printable_breakpoints
> 0)
5106 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5107 if (nr_printable_breakpoints
> 0)
5109 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5110 "type", "Type"); /* 2 */
5111 if (nr_printable_breakpoints
> 0)
5113 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5114 if (nr_printable_breakpoints
> 0)
5116 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5117 if (opts
.addressprint
)
5119 if (nr_printable_breakpoints
> 0)
5121 if (print_address_bits
<= 32)
5122 ui_out_table_header (uiout
, 10, ui_left
,
5123 "addr", "Address"); /* 5 */
5125 ui_out_table_header (uiout
, 18, ui_left
,
5126 "addr", "Address"); /* 5 */
5128 if (nr_printable_breakpoints
> 0)
5130 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5131 ui_out_table_body (uiout
);
5132 if (nr_printable_breakpoints
> 0)
5133 annotate_breakpoints_table ();
5139 || bnum
== b
->number
)
5141 /* If we have a filter, only list the breakpoints it accepts. */
5142 if (filter
&& !filter (b
))
5145 /* We only print out user settable breakpoints unless the
5147 if (allflag
|| (user_settable_breakpoint (b
)
5149 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5153 do_cleanups (bkpttbl_chain
);
5155 if (nr_printable_breakpoints
== 0)
5157 /* If there's a filter, let the caller decide how to report
5162 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5164 ui_out_message (uiout
, 0,
5165 "No breakpoint or watchpoint number %d.\n",
5171 if (last_loc
&& !server_command
)
5172 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5175 /* FIXME? Should this be moved up so that it is only called when
5176 there have been breakpoints? */
5177 annotate_breakpoints_table_end ();
5179 return nr_printable_breakpoints
;
5182 /* Display the value of default-collect in a way that is generally
5183 compatible with the breakpoint list. */
5186 default_collect_info (void)
5188 /* If it has no value (which is frequently the case), say nothing; a
5189 message like "No default-collect." gets in user's face when it's
5191 if (!*default_collect
)
5194 /* The following phrase lines up nicely with per-tracepoint collect
5196 ui_out_text (uiout
, "default collect ");
5197 ui_out_field_string (uiout
, "default-collect", default_collect
);
5198 ui_out_text (uiout
, " \n");
5202 breakpoints_info (char *bnum_exp
, int from_tty
)
5207 bnum
= parse_and_eval_long (bnum_exp
);
5209 breakpoint_1 (bnum
, 0, NULL
);
5211 default_collect_info ();
5215 watchpoints_info (char *wpnum_exp
, int from_tty
)
5217 int wpnum
= -1, num_printed
;
5220 wpnum
= parse_and_eval_long (wpnum_exp
);
5222 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5224 if (num_printed
== 0)
5227 ui_out_message (uiout
, 0, "No watchpoints.\n");
5229 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5234 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5239 bnum
= parse_and_eval_long (bnum_exp
);
5241 breakpoint_1 (bnum
, 1, NULL
);
5243 default_collect_info ();
5247 breakpoint_has_pc (struct breakpoint
*b
,
5248 struct program_space
*pspace
,
5249 CORE_ADDR pc
, struct obj_section
*section
)
5251 struct bp_location
*bl
= b
->loc
;
5253 for (; bl
; bl
= bl
->next
)
5255 if (bl
->pspace
== pspace
5256 && bl
->address
== pc
5257 && (!overlay_debugging
|| bl
->section
== section
))
5263 /* Print a message describing any breakpoints set at PC. This
5264 concerns with logical breakpoints, so we match program spaces, not
5268 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5269 struct program_space
*pspace
, CORE_ADDR pc
,
5270 struct obj_section
*section
, int thread
)
5273 struct breakpoint
*b
;
5276 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5280 printf_filtered (_("Note: breakpoint "));
5281 else /* if (others == ???) */
5282 printf_filtered (_("Note: breakpoints "));
5284 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5287 printf_filtered ("%d", b
->number
);
5288 if (b
->thread
== -1 && thread
!= -1)
5289 printf_filtered (" (all threads)");
5290 else if (b
->thread
!= -1)
5291 printf_filtered (" (thread %d)", b
->thread
);
5292 printf_filtered ("%s%s ",
5293 ((b
->enable_state
== bp_disabled
5294 || b
->enable_state
== bp_call_disabled
5295 || b
->enable_state
== bp_startup_disabled
)
5297 : b
->enable_state
== bp_permanent
5301 : ((others
== 1) ? " and" : ""));
5303 printf_filtered (_("also set at pc "));
5304 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5305 printf_filtered (".\n");
5309 /* Set the default place to put a breakpoint
5310 for the `break' command with no arguments. */
5313 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5314 CORE_ADDR addr
, struct symtab
*symtab
,
5317 default_breakpoint_valid
= valid
;
5318 default_breakpoint_pspace
= pspace
;
5319 default_breakpoint_address
= addr
;
5320 default_breakpoint_symtab
= symtab
;
5321 default_breakpoint_line
= line
;
5324 /* Return true iff it is meaningful to use the address member of
5325 BPT. For some breakpoint types, the address member is irrelevant
5326 and it makes no sense to attempt to compare it to other addresses
5327 (or use it for any other purpose either).
5329 More specifically, each of the following breakpoint types will
5330 always have a zero valued address and we don't want to mark
5331 breakpoints of any of these types to be a duplicate of an actual
5332 breakpoint at address zero:
5340 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5342 enum bptype type
= bpt
->type
;
5344 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5347 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5348 true if LOC1 and LOC2 represent the same watchpoint location. */
5351 watchpoint_locations_match (struct bp_location
*loc1
,
5352 struct bp_location
*loc2
)
5354 /* Both of them must not be in moribund_locations. */
5355 gdb_assert (loc1
->owner
!= NULL
);
5356 gdb_assert (loc2
->owner
!= NULL
);
5358 /* If the target can evaluate the condition expression in hardware,
5359 then we we need to insert both watchpoints even if they are at
5360 the same place. Otherwise the watchpoint will only trigger when
5361 the condition of whichever watchpoint was inserted evaluates to
5362 true, not giving a chance for GDB to check the condition of the
5363 other watchpoint. */
5364 if ((loc1
->owner
->cond_exp
5365 && target_can_accel_watchpoint_condition (loc1
->address
,
5367 loc1
->watchpoint_type
,
5368 loc1
->owner
->cond_exp
))
5369 || (loc2
->owner
->cond_exp
5370 && target_can_accel_watchpoint_condition (loc2
->address
,
5372 loc2
->watchpoint_type
,
5373 loc2
->owner
->cond_exp
)))
5376 /* Note that this checks the owner's type, not the location's. In
5377 case the target does not support read watchpoints, but does
5378 support access watchpoints, we'll have bp_read_watchpoint
5379 watchpoints with hw_access locations. Those should be considered
5380 duplicates of hw_read locations. The hw_read locations will
5381 become hw_access locations later. */
5382 return (loc1
->owner
->type
== loc2
->owner
->type
5383 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5384 && loc1
->address
== loc2
->address
5385 && loc1
->length
== loc2
->length
);
5388 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5389 same breakpoint location. In most targets, this can only be true
5390 if ASPACE1 matches ASPACE2. On targets that have global
5391 breakpoints, the address space doesn't really matter. */
5394 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5395 struct address_space
*aspace2
, CORE_ADDR addr2
)
5397 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5398 || aspace1
== aspace2
)
5402 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5403 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5404 represent the same location. */
5407 breakpoint_locations_match (struct bp_location
*loc1
,
5408 struct bp_location
*loc2
)
5410 int hw_point1
, hw_point2
;
5412 /* Both of them must not be in moribund_locations. */
5413 gdb_assert (loc1
->owner
!= NULL
);
5414 gdb_assert (loc2
->owner
!= NULL
);
5416 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5417 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5419 if (hw_point1
!= hw_point2
)
5422 return watchpoint_locations_match (loc1
, loc2
);
5424 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5425 loc2
->pspace
->aspace
, loc2
->address
);
5429 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5430 int bnum
, int have_bnum
)
5435 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5436 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5438 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5439 bnum
, astr1
, astr2
);
5441 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5444 /* Adjust a breakpoint's address to account for architectural
5445 constraints on breakpoint placement. Return the adjusted address.
5446 Note: Very few targets require this kind of adjustment. For most
5447 targets, this function is simply the identity function. */
5450 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5451 CORE_ADDR bpaddr
, enum bptype bptype
)
5453 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5455 /* Very few targets need any kind of breakpoint adjustment. */
5458 else if (bptype
== bp_watchpoint
5459 || bptype
== bp_hardware_watchpoint
5460 || bptype
== bp_read_watchpoint
5461 || bptype
== bp_access_watchpoint
5462 || bptype
== bp_catchpoint
)
5464 /* Watchpoints and the various bp_catch_* eventpoints should not
5465 have their addresses modified. */
5470 CORE_ADDR adjusted_bpaddr
;
5472 /* Some targets have architectural constraints on the placement
5473 of breakpoint instructions. Obtain the adjusted address. */
5474 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5476 /* An adjusted breakpoint address can significantly alter
5477 a user's expectations. Print a warning if an adjustment
5479 if (adjusted_bpaddr
!= bpaddr
)
5480 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5482 return adjusted_bpaddr
;
5486 /* Allocate a struct bp_location. */
5488 static struct bp_location
*
5489 allocate_bp_location (struct breakpoint
*bpt
)
5491 struct bp_location
*loc
;
5493 loc
= xmalloc (sizeof (struct bp_location
));
5494 memset (loc
, 0, sizeof (*loc
));
5498 loc
->shlib_disabled
= 0;
5507 case bp_longjmp_resume
:
5509 case bp_exception_resume
:
5510 case bp_step_resume
:
5511 case bp_watchpoint_scope
:
5513 case bp_std_terminate
:
5514 case bp_shlib_event
:
5515 case bp_thread_event
:
5516 case bp_overlay_event
:
5518 case bp_longjmp_master
:
5519 case bp_std_terminate_master
:
5520 case bp_exception_master
:
5521 loc
->loc_type
= bp_loc_software_breakpoint
;
5523 case bp_hardware_breakpoint
:
5524 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5526 case bp_hardware_watchpoint
:
5527 case bp_read_watchpoint
:
5528 case bp_access_watchpoint
:
5529 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5534 case bp_fast_tracepoint
:
5535 case bp_static_tracepoint
:
5536 loc
->loc_type
= bp_loc_other
;
5539 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5547 free_bp_location (struct bp_location
*loc
)
5552 if (loc
->function_name
)
5553 xfree (loc
->function_name
);
5558 /* Increment reference count. */
5561 incref_bp_location (struct bp_location
*bl
)
5566 /* Decrement reference count. If the reference count reaches 0,
5567 destroy the bp_location. Sets *BLP to NULL. */
5570 decref_bp_location (struct bp_location
**blp
)
5572 gdb_assert ((*blp
)->refc
> 0);
5574 if (--(*blp
)->refc
== 0)
5575 free_bp_location (*blp
);
5579 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5580 type BPTYPE and has no locations as yet. */
5581 /* This function is used in gdbtk sources and thus can not be made
5584 static struct breakpoint
*
5585 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5588 struct breakpoint
*b
, *b1
;
5590 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5591 memset (b
, 0, sizeof (*b
));
5594 b
->gdbarch
= gdbarch
;
5595 b
->language
= current_language
->la_language
;
5596 b
->input_radix
= input_radix
;
5598 b
->enable_state
= bp_enabled
;
5601 b
->ignore_count
= 0;
5603 b
->frame_id
= null_frame_id
;
5604 b
->forked_inferior_pid
= null_ptid
;
5605 b
->exec_pathname
= NULL
;
5606 b
->syscalls_to_be_caught
= NULL
;
5608 b
->condition_not_parsed
= 0;
5609 b
->py_bp_object
= NULL
;
5611 /* Add this breakpoint to the end of the chain so that a list of
5612 breakpoints will come out in order of increasing numbers. */
5614 b1
= breakpoint_chain
;
5616 breakpoint_chain
= b
;
5626 /* Initialize loc->function_name. */
5628 set_breakpoint_location_function (struct bp_location
*loc
)
5630 gdb_assert (loc
->owner
!= NULL
);
5632 if (loc
->owner
->type
== bp_breakpoint
5633 || loc
->owner
->type
== bp_hardware_breakpoint
5634 || is_tracepoint (loc
->owner
))
5636 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5638 if (loc
->function_name
)
5639 loc
->function_name
= xstrdup (loc
->function_name
);
5643 /* Attempt to determine architecture of location identified by SAL. */
5644 static struct gdbarch
*
5645 get_sal_arch (struct symtab_and_line sal
)
5648 return get_objfile_arch (sal
.section
->objfile
);
5650 return get_objfile_arch (sal
.symtab
->objfile
);
5655 /* set_raw_breakpoint is a low level routine for allocating and
5656 partially initializing a breakpoint of type BPTYPE. The newly
5657 created breakpoint's address, section, source file name, and line
5658 number are provided by SAL. The newly created and partially
5659 initialized breakpoint is added to the breakpoint chain and
5660 is also returned as the value of this function.
5662 It is expected that the caller will complete the initialization of
5663 the newly created breakpoint struct as well as output any status
5664 information regarding the creation of a new breakpoint. In
5665 particular, set_raw_breakpoint does NOT set the breakpoint
5666 number! Care should be taken to not allow an error to occur
5667 prior to completing the initialization of the breakpoint. If this
5668 should happen, a bogus breakpoint will be left on the chain. */
5671 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5672 struct symtab_and_line sal
, enum bptype bptype
)
5674 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
,
5676 CORE_ADDR adjusted_address
;
5677 struct gdbarch
*loc_gdbarch
;
5679 loc_gdbarch
= get_sal_arch (sal
);
5681 loc_gdbarch
= b
->gdbarch
;
5683 if (bptype
!= bp_catchpoint
)
5684 gdb_assert (sal
.pspace
!= NULL
);
5686 /* Adjust the breakpoint's address prior to allocating a location.
5687 Once we call allocate_bp_location(), that mostly uninitialized
5688 location will be placed on the location chain. Adjustment of the
5689 breakpoint may cause target_read_memory() to be called and we do
5690 not want its scan of the location chain to find a breakpoint and
5691 location that's only been partially initialized. */
5692 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5695 b
->loc
= allocate_bp_location (b
);
5696 b
->loc
->gdbarch
= loc_gdbarch
;
5697 b
->loc
->requested_address
= sal
.pc
;
5698 b
->loc
->address
= adjusted_address
;
5699 b
->loc
->pspace
= sal
.pspace
;
5701 /* Store the program space that was used to set the breakpoint, for
5702 breakpoint resetting. */
5703 b
->pspace
= sal
.pspace
;
5705 if (sal
.symtab
== NULL
)
5706 b
->source_file
= NULL
;
5708 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5709 b
->loc
->section
= sal
.section
;
5710 b
->line_number
= sal
.line
;
5712 set_breakpoint_location_function (b
->loc
);
5714 breakpoints_changed ();
5720 /* Note that the breakpoint object B describes a permanent breakpoint
5721 instruction, hard-wired into the inferior's code. */
5723 make_breakpoint_permanent (struct breakpoint
*b
)
5725 struct bp_location
*bl
;
5727 b
->enable_state
= bp_permanent
;
5729 /* By definition, permanent breakpoints are already present in the
5730 code. Mark all locations as inserted. For now,
5731 make_breakpoint_permanent is called in just one place, so it's
5732 hard to say if it's reasonable to have permanent breakpoint with
5733 multiple locations or not, but it's easy to implmement. */
5734 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5738 /* Call this routine when stepping and nexting to enable a breakpoint
5739 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5740 initiated the operation. */
5743 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5745 struct breakpoint
*b
, *b_tmp
;
5746 int thread
= tp
->num
;
5748 /* To avoid having to rescan all objfile symbols at every step,
5749 we maintain a list of continually-inserted but always disabled
5750 longjmp "master" breakpoints. Here, we simply create momentary
5751 clones of those and enable them for the requested thread. */
5752 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5753 if (b
->pspace
== current_program_space
5754 && (b
->type
== bp_longjmp_master
5755 || b
->type
== bp_exception_master
))
5757 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5759 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5760 clone
->thread
= thread
;
5763 tp
->initiating_frame
= frame
;
5766 /* Delete all longjmp breakpoints from THREAD. */
5768 delete_longjmp_breakpoint (int thread
)
5770 struct breakpoint
*b
, *b_tmp
;
5772 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5773 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5775 if (b
->thread
== thread
)
5776 delete_breakpoint (b
);
5781 enable_overlay_breakpoints (void)
5783 struct breakpoint
*b
;
5786 if (b
->type
== bp_overlay_event
)
5788 b
->enable_state
= bp_enabled
;
5789 update_global_location_list (1);
5790 overlay_events_enabled
= 1;
5795 disable_overlay_breakpoints (void)
5797 struct breakpoint
*b
;
5800 if (b
->type
== bp_overlay_event
)
5802 b
->enable_state
= bp_disabled
;
5803 update_global_location_list (0);
5804 overlay_events_enabled
= 0;
5808 /* Set an active std::terminate breakpoint for each std::terminate
5809 master breakpoint. */
5811 set_std_terminate_breakpoint (void)
5813 struct breakpoint
*b
, *b_tmp
;
5815 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5816 if (b
->pspace
== current_program_space
5817 && b
->type
== bp_std_terminate_master
)
5819 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5820 clone
->type
= bp_std_terminate
;
5824 /* Delete all the std::terminate breakpoints. */
5826 delete_std_terminate_breakpoint (void)
5828 struct breakpoint
*b
, *b_tmp
;
5830 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5831 if (b
->type
== bp_std_terminate
)
5832 delete_breakpoint (b
);
5836 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5838 struct breakpoint
*b
;
5840 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5842 b
->enable_state
= bp_enabled
;
5843 /* addr_string has to be used or breakpoint_re_set will delete me. */
5845 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5847 update_global_location_list_nothrow (1);
5853 remove_thread_event_breakpoints (void)
5855 struct breakpoint
*b
, *b_tmp
;
5857 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5858 if (b
->type
== bp_thread_event
5859 && b
->loc
->pspace
== current_program_space
)
5860 delete_breakpoint (b
);
5863 struct captured_parse_breakpoint_args
5866 struct symtabs_and_lines
*sals_p
;
5867 char ***addr_string_p
;
5871 struct lang_and_radix
5877 /* Create a breakpoint for JIT code registration and unregistration. */
5880 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5882 struct breakpoint
*b
;
5884 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5885 update_global_location_list_nothrow (1);
5890 remove_solib_event_breakpoints (void)
5892 struct breakpoint
*b
, *b_tmp
;
5894 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5895 if (b
->type
== bp_shlib_event
5896 && b
->loc
->pspace
== current_program_space
)
5897 delete_breakpoint (b
);
5901 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5903 struct breakpoint
*b
;
5905 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5906 update_global_location_list_nothrow (1);
5910 /* Disable any breakpoints that are on code in shared libraries. Only
5911 apply to enabled breakpoints, disabled ones can just stay disabled. */
5914 disable_breakpoints_in_shlibs (void)
5916 struct bp_location
*loc
, **locp_tmp
;
5918 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5920 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5921 struct breakpoint
*b
= loc
->owner
;
5923 /* We apply the check to all breakpoints, including disabled for
5924 those with loc->duplicate set. This is so that when breakpoint
5925 becomes enabled, or the duplicate is removed, gdb will try to
5926 insert all breakpoints. If we don't set shlib_disabled here,
5927 we'll try to insert those breakpoints and fail. */
5928 if (((b
->type
== bp_breakpoint
)
5929 || (b
->type
== bp_jit_event
)
5930 || (b
->type
== bp_hardware_breakpoint
)
5931 || (is_tracepoint (b
)))
5932 && loc
->pspace
== current_program_space
5933 && !loc
->shlib_disabled
5935 && PC_SOLIB (loc
->address
)
5937 && solib_name_from_address (loc
->pspace
, loc
->address
)
5941 loc
->shlib_disabled
= 1;
5946 /* Disable any breakpoints that are in in an unloaded shared library.
5947 Only apply to enabled breakpoints, disabled ones can just stay
5951 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5953 struct bp_location
*loc
, **locp_tmp
;
5954 int disabled_shlib_breaks
= 0;
5956 /* SunOS a.out shared libraries are always mapped, so do not
5957 disable breakpoints; they will only be reported as unloaded
5958 through clear_solib when GDB discards its shared library
5959 list. See clear_solib for more information. */
5960 if (exec_bfd
!= NULL
5961 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5964 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5966 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5967 struct breakpoint
*b
= loc
->owner
;
5969 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5970 || loc
->loc_type
== bp_loc_software_breakpoint
)
5971 && solib
->pspace
== loc
->pspace
5972 && !loc
->shlib_disabled
5973 && (b
->type
== bp_breakpoint
5974 || b
->type
== bp_jit_event
5975 || b
->type
== bp_hardware_breakpoint
)
5976 && solib_contains_address_p (solib
, loc
->address
))
5978 loc
->shlib_disabled
= 1;
5979 /* At this point, we cannot rely on remove_breakpoint
5980 succeeding so we must mark the breakpoint as not inserted
5981 to prevent future errors occurring in remove_breakpoints. */
5983 if (!disabled_shlib_breaks
)
5985 target_terminal_ours_for_output ();
5986 warning (_("Temporarily disabling breakpoints "
5987 "for unloaded shared library \"%s\""),
5990 disabled_shlib_breaks
= 1;
5995 /* FORK & VFORK catchpoints. */
5997 /* Implement the "insert" breakpoint_ops method for fork
6001 insert_catch_fork (struct breakpoint
*b
)
6003 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6006 /* Implement the "remove" breakpoint_ops method for fork
6010 remove_catch_fork (struct breakpoint
*b
)
6012 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6015 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6019 breakpoint_hit_catch_fork (struct breakpoint
*b
)
6021 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
6024 /* Implement the "print_it" breakpoint_ops method for fork
6027 static enum print_stop_action
6028 print_it_catch_fork (struct breakpoint
*b
)
6030 annotate_catchpoint (b
->number
);
6031 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6032 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6033 return PRINT_SRC_AND_LOC
;
6036 /* Implement the "print_one" breakpoint_ops method for fork
6040 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6042 struct value_print_options opts
;
6044 get_user_print_options (&opts
);
6046 /* Field 4, the address, is omitted (which makes the columns not
6047 line up too nicely with the headers, but the effect is relatively
6049 if (opts
.addressprint
)
6050 ui_out_field_skip (uiout
, "addr");
6052 ui_out_text (uiout
, "fork");
6053 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6055 ui_out_text (uiout
, ", process ");
6056 ui_out_field_int (uiout
, "what",
6057 ptid_get_pid (b
->forked_inferior_pid
));
6058 ui_out_spaces (uiout
, 1);
6062 /* Implement the "print_mention" breakpoint_ops method for fork
6066 print_mention_catch_fork (struct breakpoint
*b
)
6068 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6071 /* Implement the "print_recreate" breakpoint_ops method for fork
6075 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6077 fprintf_unfiltered (fp
, "catch fork");
6080 /* The breakpoint_ops structure to be used in fork catchpoints. */
6082 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6086 breakpoint_hit_catch_fork
,
6087 print_it_catch_fork
,
6088 print_one_catch_fork
,
6089 print_mention_catch_fork
,
6090 print_recreate_catch_fork
6093 /* Implement the "insert" breakpoint_ops method for vfork
6097 insert_catch_vfork (struct breakpoint
*b
)
6099 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6102 /* Implement the "remove" breakpoint_ops method for vfork
6106 remove_catch_vfork (struct breakpoint
*b
)
6108 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6111 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6115 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
6117 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
6120 /* Implement the "print_it" breakpoint_ops method for vfork
6123 static enum print_stop_action
6124 print_it_catch_vfork (struct breakpoint
*b
)
6126 annotate_catchpoint (b
->number
);
6127 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6128 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6129 return PRINT_SRC_AND_LOC
;
6132 /* Implement the "print_one" breakpoint_ops method for vfork
6136 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6138 struct value_print_options opts
;
6140 get_user_print_options (&opts
);
6141 /* Field 4, the address, is omitted (which makes the columns not
6142 line up too nicely with the headers, but the effect is relatively
6144 if (opts
.addressprint
)
6145 ui_out_field_skip (uiout
, "addr");
6147 ui_out_text (uiout
, "vfork");
6148 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6150 ui_out_text (uiout
, ", process ");
6151 ui_out_field_int (uiout
, "what",
6152 ptid_get_pid (b
->forked_inferior_pid
));
6153 ui_out_spaces (uiout
, 1);
6157 /* Implement the "print_mention" breakpoint_ops method for vfork
6161 print_mention_catch_vfork (struct breakpoint
*b
)
6163 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6166 /* Implement the "print_recreate" breakpoint_ops method for vfork
6170 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6172 fprintf_unfiltered (fp
, "catch vfork");
6175 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6177 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6181 breakpoint_hit_catch_vfork
,
6182 print_it_catch_vfork
,
6183 print_one_catch_vfork
,
6184 print_mention_catch_vfork
,
6185 print_recreate_catch_vfork
6188 /* Implement the "insert" breakpoint_ops method for syscall
6192 insert_catch_syscall (struct breakpoint
*b
)
6194 struct inferior
*inf
= current_inferior ();
6196 ++inf
->total_syscalls_count
;
6197 if (!b
->syscalls_to_be_caught
)
6198 ++inf
->any_syscall_count
;
6204 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6209 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6211 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6212 uintptr_t vec_addr_offset
6213 = old_size
* ((uintptr_t) sizeof (int));
6215 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6216 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6218 memset ((void *) vec_addr
, 0,
6219 (iter
+ 1 - old_size
) * sizeof (int));
6221 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6222 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6226 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6227 inf
->total_syscalls_count
!= 0,
6228 inf
->any_syscall_count
,
6229 VEC_length (int, inf
->syscalls_counts
),
6230 VEC_address (int, inf
->syscalls_counts
));
6233 /* Implement the "remove" breakpoint_ops method for syscall
6237 remove_catch_syscall (struct breakpoint
*b
)
6239 struct inferior
*inf
= current_inferior ();
6241 --inf
->total_syscalls_count
;
6242 if (!b
->syscalls_to_be_caught
)
6243 --inf
->any_syscall_count
;
6249 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6253 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6254 /* Shouldn't happen. */
6256 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6257 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6261 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6262 inf
->total_syscalls_count
!= 0,
6263 inf
->any_syscall_count
,
6264 VEC_length (int, inf
->syscalls_counts
),
6266 inf
->syscalls_counts
));
6269 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6273 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6275 /* We must check if we are catching specific syscalls in this
6276 breakpoint. If we are, then we must guarantee that the called
6277 syscall is the same syscall we are catching. */
6278 int syscall_number
= 0;
6280 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6283 /* Now, checking if the syscall is the same. */
6284 if (b
->syscalls_to_be_caught
)
6289 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6291 if (syscall_number
== iter
)
6301 /* Implement the "print_it" breakpoint_ops method for syscall
6304 static enum print_stop_action
6305 print_it_catch_syscall (struct breakpoint
*b
)
6307 /* These are needed because we want to know in which state a
6308 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6309 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6310 must print "called syscall" or "returned from syscall". */
6312 struct target_waitstatus last
;
6314 struct cleanup
*old_chain
;
6317 get_last_target_status (&ptid
, &last
);
6319 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6321 annotate_catchpoint (b
->number
);
6324 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6326 syscall_id
= xstrprintf ("'%s'", s
.name
);
6328 old_chain
= make_cleanup (xfree
, syscall_id
);
6330 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6331 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6332 b
->number
, syscall_id
);
6333 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6334 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6335 b
->number
, syscall_id
);
6337 do_cleanups (old_chain
);
6339 return PRINT_SRC_AND_LOC
;
6342 /* Implement the "print_one" breakpoint_ops method for syscall
6346 print_one_catch_syscall (struct breakpoint
*b
,
6347 struct bp_location
**last_loc
)
6349 struct value_print_options opts
;
6351 get_user_print_options (&opts
);
6352 /* Field 4, the address, is omitted (which makes the columns not
6353 line up too nicely with the headers, but the effect is relatively
6355 if (opts
.addressprint
)
6356 ui_out_field_skip (uiout
, "addr");
6359 if (b
->syscalls_to_be_caught
6360 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6361 ui_out_text (uiout
, "syscalls \"");
6363 ui_out_text (uiout
, "syscall \"");
6365 if (b
->syscalls_to_be_caught
)
6368 char *text
= xstrprintf ("%s", "");
6371 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6376 get_syscall_by_number (iter
, &s
);
6379 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6381 text
= xstrprintf ("%s%d, ", text
, iter
);
6383 /* We have to xfree the last 'text' (now stored at 'x')
6384 because xstrprintf dinamically allocates new space for it
6388 /* Remove the last comma. */
6389 text
[strlen (text
) - 2] = '\0';
6390 ui_out_field_string (uiout
, "what", text
);
6393 ui_out_field_string (uiout
, "what", "<any syscall>");
6394 ui_out_text (uiout
, "\" ");
6397 /* Implement the "print_mention" breakpoint_ops method for syscall
6401 print_mention_catch_syscall (struct breakpoint
*b
)
6403 if (b
->syscalls_to_be_caught
)
6407 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6408 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6410 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6413 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6417 get_syscall_by_number (iter
, &s
);
6420 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6422 printf_filtered (" %d", s
.number
);
6424 printf_filtered (")");
6427 printf_filtered (_("Catchpoint %d (any syscall)"),
6431 /* Implement the "print_recreate" breakpoint_ops method for syscall
6435 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6437 fprintf_unfiltered (fp
, "catch syscall");
6439 if (b
->syscalls_to_be_caught
)
6444 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6449 get_syscall_by_number (iter
, &s
);
6451 fprintf_unfiltered (fp
, " %s", s
.name
);
6453 fprintf_unfiltered (fp
, " %d", s
.number
);
6458 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6460 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6462 insert_catch_syscall
,
6463 remove_catch_syscall
,
6464 breakpoint_hit_catch_syscall
,
6465 print_it_catch_syscall
,
6466 print_one_catch_syscall
,
6467 print_mention_catch_syscall
,
6468 print_recreate_catch_syscall
6471 /* Returns non-zero if 'b' is a syscall catchpoint. */
6474 syscall_catchpoint_p (struct breakpoint
*b
)
6476 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6479 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6480 but does NOT mention it nor update the global location list.
6481 This is useful if you need to fill more fields in the
6482 struct breakpoint before calling mention.
6484 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6485 If COND_STRING is not NULL, then store it in the breakpoint.
6486 OPS, if not NULL, is the breakpoint_ops structure associated
6487 to the catchpoint. */
6489 static struct breakpoint
*
6490 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6492 struct breakpoint_ops
*ops
)
6494 struct symtab_and_line sal
;
6495 struct breakpoint
*b
;
6498 sal
.pspace
= current_program_space
;
6500 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6501 set_breakpoint_count (breakpoint_count
+ 1);
6502 b
->number
= breakpoint_count
;
6504 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6506 b
->addr_string
= NULL
;
6507 b
->enable_state
= bp_enabled
;
6508 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6514 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6516 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6517 If COND_STRING is not NULL, then store it in the breakpoint.
6518 OPS, if not NULL, is the breakpoint_ops structure associated
6519 to the catchpoint. */
6521 static struct breakpoint
*
6522 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6523 char *cond_string
, struct breakpoint_ops
*ops
)
6525 struct breakpoint
*b
=
6526 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6529 update_global_location_list (1);
6535 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6536 int tempflag
, char *cond_string
,
6537 struct breakpoint_ops
*ops
)
6539 struct breakpoint
*b
6540 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6542 /* FIXME: We should put this information in a breakpoint private data
6544 b
->forked_inferior_pid
= null_ptid
;
6547 /* Exec catchpoints. */
6550 insert_catch_exec (struct breakpoint
*b
)
6552 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6556 remove_catch_exec (struct breakpoint
*b
)
6558 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6562 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6564 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6567 static enum print_stop_action
6568 print_it_catch_exec (struct breakpoint
*b
)
6570 annotate_catchpoint (b
->number
);
6571 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6573 return PRINT_SRC_AND_LOC
;
6577 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6579 struct value_print_options opts
;
6581 get_user_print_options (&opts
);
6583 /* Field 4, the address, is omitted (which makes the columns
6584 not line up too nicely with the headers, but the effect
6585 is relatively readable). */
6586 if (opts
.addressprint
)
6587 ui_out_field_skip (uiout
, "addr");
6589 ui_out_text (uiout
, "exec");
6590 if (b
->exec_pathname
!= NULL
)
6592 ui_out_text (uiout
, ", program \"");
6593 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6594 ui_out_text (uiout
, "\" ");
6599 print_mention_catch_exec (struct breakpoint
*b
)
6601 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6604 /* Implement the "print_recreate" breakpoint_ops method for exec
6608 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6610 fprintf_unfiltered (fp
, "catch exec");
6613 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6617 breakpoint_hit_catch_exec
,
6618 print_it_catch_exec
,
6619 print_one_catch_exec
,
6620 print_mention_catch_exec
,
6621 print_recreate_catch_exec
6625 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6626 struct breakpoint_ops
*ops
)
6628 struct gdbarch
*gdbarch
= get_current_arch ();
6629 struct breakpoint
*b
=
6630 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6632 b
->syscalls_to_be_caught
= filter
;
6634 /* Now, we have to mention the breakpoint and update the global
6637 update_global_location_list (1);
6641 hw_breakpoint_used_count (void)
6643 struct breakpoint
*b
;
6648 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6656 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6658 struct breakpoint
*b
;
6661 *other_type_used
= 0;
6664 if (breakpoint_enabled (b
))
6666 if (b
->type
== type
)
6668 else if (is_hardware_watchpoint (b
))
6669 *other_type_used
= 1;
6676 disable_watchpoints_before_interactive_call_start (void)
6678 struct breakpoint
*b
;
6682 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6684 b
->enable_state
= bp_call_disabled
;
6685 update_global_location_list (0);
6691 enable_watchpoints_after_interactive_call_stop (void)
6693 struct breakpoint
*b
;
6697 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6699 b
->enable_state
= bp_enabled
;
6700 update_global_location_list (1);
6706 disable_breakpoints_before_startup (void)
6708 struct breakpoint
*b
;
6713 if (b
->pspace
!= current_program_space
)
6716 if ((b
->type
== bp_breakpoint
6717 || b
->type
== bp_hardware_breakpoint
)
6718 && breakpoint_enabled (b
))
6720 b
->enable_state
= bp_startup_disabled
;
6726 update_global_location_list (0);
6728 current_program_space
->executing_startup
= 1;
6732 enable_breakpoints_after_startup (void)
6734 struct breakpoint
*b
;
6737 current_program_space
->executing_startup
= 0;
6741 if (b
->pspace
!= current_program_space
)
6744 if ((b
->type
== bp_breakpoint
6745 || b
->type
== bp_hardware_breakpoint
)
6746 && b
->enable_state
== bp_startup_disabled
)
6748 b
->enable_state
= bp_enabled
;
6754 breakpoint_re_set ();
6758 /* Set a breakpoint that will evaporate an end of command
6759 at address specified by SAL.
6760 Restrict it to frame FRAME if FRAME is nonzero. */
6763 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6764 struct frame_id frame_id
, enum bptype type
)
6766 struct breakpoint
*b
;
6768 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6770 gdb_assert (!frame_id_inlined_p (frame_id
));
6772 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6773 b
->enable_state
= bp_enabled
;
6774 b
->disposition
= disp_donttouch
;
6775 b
->frame_id
= frame_id
;
6777 /* If we're debugging a multi-threaded program, then we want
6778 momentary breakpoints to be active in only a single thread of
6780 if (in_thread_list (inferior_ptid
))
6781 b
->thread
= pid_to_thread_id (inferior_ptid
);
6783 update_global_location_list_nothrow (1);
6788 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6792 clone_momentary_breakpoint (struct breakpoint
*orig
)
6794 struct breakpoint
*copy
;
6796 /* If there's nothing to clone, then return nothing. */
6800 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6801 copy
->loc
= allocate_bp_location (copy
);
6802 set_breakpoint_location_function (copy
->loc
);
6804 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6805 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6806 copy
->loc
->address
= orig
->loc
->address
;
6807 copy
->loc
->section
= orig
->loc
->section
;
6808 copy
->loc
->pspace
= orig
->loc
->pspace
;
6810 if (orig
->source_file
== NULL
)
6811 copy
->source_file
= NULL
;
6813 copy
->source_file
= xstrdup (orig
->source_file
);
6815 copy
->line_number
= orig
->line_number
;
6816 copy
->frame_id
= orig
->frame_id
;
6817 copy
->thread
= orig
->thread
;
6818 copy
->pspace
= orig
->pspace
;
6820 copy
->enable_state
= bp_enabled
;
6821 copy
->disposition
= disp_donttouch
;
6822 copy
->number
= internal_breakpoint_number
--;
6824 update_global_location_list_nothrow (0);
6829 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6832 struct symtab_and_line sal
;
6834 sal
= find_pc_line (pc
, 0);
6836 sal
.section
= find_pc_overlay (pc
);
6837 sal
.explicit_pc
= 1;
6839 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6843 /* Tell the user we have just set a breakpoint B. */
6846 mention (struct breakpoint
*b
)
6849 struct cleanup
*ui_out_chain
;
6850 struct value_print_options opts
;
6852 get_user_print_options (&opts
);
6854 /* FIXME: This is misplaced; mention() is called by things (like
6855 hitting a watchpoint) other than breakpoint creation. It should
6856 be possible to clean this up and at the same time replace the
6857 random calls to breakpoint_changed with this hook. */
6858 observer_notify_breakpoint_created (b
->number
);
6860 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6861 b
->ops
->print_mention (b
);
6866 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
6870 ui_out_text (uiout
, "Watchpoint ");
6871 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6872 ui_out_field_int (uiout
, "number", b
->number
);
6873 ui_out_text (uiout
, ": ");
6874 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6875 do_cleanups (ui_out_chain
);
6877 case bp_hardware_watchpoint
:
6878 ui_out_text (uiout
, "Hardware watchpoint ");
6879 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6880 ui_out_field_int (uiout
, "number", b
->number
);
6881 ui_out_text (uiout
, ": ");
6882 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6883 do_cleanups (ui_out_chain
);
6885 case bp_read_watchpoint
:
6886 ui_out_text (uiout
, "Hardware read watchpoint ");
6887 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6888 ui_out_field_int (uiout
, "number", b
->number
);
6889 ui_out_text (uiout
, ": ");
6890 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6891 do_cleanups (ui_out_chain
);
6893 case bp_access_watchpoint
:
6894 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6895 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6896 ui_out_field_int (uiout
, "number", b
->number
);
6897 ui_out_text (uiout
, ": ");
6898 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6899 do_cleanups (ui_out_chain
);
6902 if (ui_out_is_mi_like_p (uiout
))
6907 if (b
->disposition
== disp_del
)
6908 printf_filtered (_("Temporary breakpoint"));
6910 printf_filtered (_("Breakpoint"));
6911 printf_filtered (_(" %d"), b
->number
);
6914 case bp_hardware_breakpoint
:
6915 if (ui_out_is_mi_like_p (uiout
))
6920 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6924 if (ui_out_is_mi_like_p (uiout
))
6929 printf_filtered (_("Tracepoint"));
6930 printf_filtered (_(" %d"), b
->number
);
6933 case bp_fast_tracepoint
:
6934 if (ui_out_is_mi_like_p (uiout
))
6939 printf_filtered (_("Fast tracepoint"));
6940 printf_filtered (_(" %d"), b
->number
);
6943 case bp_static_tracepoint
:
6944 if (ui_out_is_mi_like_p (uiout
))
6949 printf_filtered (_("Static tracepoint"));
6950 printf_filtered (_(" %d"), b
->number
);
6957 case bp_longjmp_resume
:
6959 case bp_exception_resume
:
6960 case bp_step_resume
:
6962 case bp_std_terminate
:
6963 case bp_watchpoint_scope
:
6964 case bp_shlib_event
:
6965 case bp_thread_event
:
6966 case bp_overlay_event
:
6968 case bp_longjmp_master
:
6969 case bp_std_terminate_master
:
6970 case bp_exception_master
:
6976 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6980 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6984 if (opts
.addressprint
|| b
->source_file
== NULL
)
6986 printf_filtered (" at ");
6987 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6991 printf_filtered (": file %s, line %d.",
6992 b
->source_file
, b
->line_number
);
6996 struct bp_location
*loc
= b
->loc
;
6998 for (; loc
; loc
= loc
->next
)
7000 printf_filtered (" (%d locations)", n
);
7005 if (ui_out_is_mi_like_p (uiout
))
7007 printf_filtered ("\n");
7011 static struct bp_location
*
7012 add_location_to_breakpoint (struct breakpoint
*b
,
7013 const struct symtab_and_line
*sal
)
7015 struct bp_location
*loc
, **tmp
;
7017 loc
= allocate_bp_location (b
);
7018 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7021 loc
->gdbarch
= get_sal_arch (*sal
);
7023 loc
->gdbarch
= b
->gdbarch
;
7024 loc
->requested_address
= sal
->pc
;
7025 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7026 loc
->requested_address
, b
->type
);
7027 loc
->pspace
= sal
->pspace
;
7028 gdb_assert (loc
->pspace
!= NULL
);
7029 loc
->section
= sal
->section
;
7031 set_breakpoint_location_function (loc
);
7036 /* Return 1 if LOC is pointing to a permanent breakpoint,
7037 return 0 otherwise. */
7040 bp_loc_is_permanent (struct bp_location
*loc
)
7044 const gdb_byte
*brk
;
7045 gdb_byte
*target_mem
;
7046 struct cleanup
*cleanup
;
7049 gdb_assert (loc
!= NULL
);
7051 addr
= loc
->address
;
7052 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7054 /* Software breakpoints unsupported? */
7058 target_mem
= alloca (len
);
7060 /* Enable the automatic memory restoration from breakpoints while
7061 we read the memory. Otherwise we could say about our temporary
7062 breakpoints they are permanent. */
7063 cleanup
= save_current_space_and_thread ();
7065 switch_to_program_space_and_thread (loc
->pspace
);
7066 make_show_memory_breakpoints_cleanup (0);
7068 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7069 && memcmp (target_mem
, brk
, len
) == 0)
7072 do_cleanups (cleanup
);
7079 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7080 as textual description of the location, and COND_STRING
7081 as condition expression. */
7084 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7085 struct symtabs_and_lines sals
, char *addr_string
,
7087 enum bptype type
, enum bpdisp disposition
,
7088 int thread
, int task
, int ignore_count
,
7089 struct breakpoint_ops
*ops
, int from_tty
,
7090 int enabled
, int internal
)
7092 struct breakpoint
*b
= NULL
;
7095 if (type
== bp_hardware_breakpoint
)
7097 int i
= hw_breakpoint_used_count ();
7098 int target_resources_ok
=
7099 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7101 if (target_resources_ok
== 0)
7102 error (_("No hardware breakpoint support in the target."));
7103 else if (target_resources_ok
< 0)
7104 error (_("Hardware breakpoints used exceeds limit."));
7107 gdb_assert (sals
.nelts
> 0);
7109 for (i
= 0; i
< sals
.nelts
; ++i
)
7111 struct symtab_and_line sal
= sals
.sals
[i
];
7112 struct bp_location
*loc
;
7116 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7118 loc_gdbarch
= gdbarch
;
7120 describe_other_breakpoints (loc_gdbarch
,
7121 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7126 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7127 set_breakpoint_number (internal
, b
);
7131 b
->cond_string
= cond_string
;
7132 b
->ignore_count
= ignore_count
;
7133 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7134 b
->disposition
= disposition
;
7135 b
->pspace
= sals
.sals
[0].pspace
;
7137 if (type
== bp_static_tracepoint
)
7139 struct static_tracepoint_marker marker
;
7141 if (is_marker_spec (addr_string
))
7143 /* We already know the marker exists, otherwise, we
7144 wouldn't see a sal for it. */
7145 char *p
= &addr_string
[3];
7150 while (*p
== ' ' || *p
== '\t')
7154 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7157 marker_str
= savestring (p
, endp
- p
);
7158 b
->static_trace_marker_id
= marker_str
;
7160 printf_filtered (_("Probed static tracepoint "
7162 b
->static_trace_marker_id
);
7164 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7166 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7167 release_static_tracepoint_marker (&marker
);
7169 printf_filtered (_("Probed static tracepoint "
7171 b
->static_trace_marker_id
);
7174 warning (_("Couldn't determine the static "
7175 "tracepoint marker to probe"));
7178 if (enabled
&& b
->pspace
->executing_startup
7179 && (b
->type
== bp_breakpoint
7180 || b
->type
== bp_hardware_breakpoint
))
7181 b
->enable_state
= bp_startup_disabled
;
7187 loc
= add_location_to_breakpoint (b
, &sal
);
7190 if (bp_loc_is_permanent (loc
))
7191 make_breakpoint_permanent (b
);
7195 char *arg
= b
->cond_string
;
7196 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7198 error (_("Garbage %s follows condition"), arg
);
7203 b
->addr_string
= addr_string
;
7205 /* addr_string has to be used or breakpoint_re_set will delete
7208 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7212 /* Do not mention breakpoints with a negative number, but do
7213 notify observers. */
7214 observer_notify_breakpoint_created (b
->number
);
7219 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7220 elements to fill the void space. */
7222 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7224 int i
= index_to_remove
+1;
7225 int last_index
= sal
->nelts
-1;
7227 for (;i
<= last_index
; ++i
)
7228 sal
->sals
[i
-1] = sal
->sals
[i
];
7233 /* If appropriate, obtains all sals that correspond to the same file
7234 and line as SAL, in all program spaces. Users debugging with IDEs,
7235 will want to set a breakpoint at foo.c:line, and not really care
7236 about program spaces. This is done only if SAL does not have
7237 explicit PC and has line and file information. If we got just a
7238 single expanded sal, return the original.
7240 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7241 which the name of enclosing function is different from SAL. This
7242 makes sure that if we have breakpoint originally set in template
7243 instantiation, say foo<int>(), we won't expand SAL to locations at
7244 the same line in all existing instantiations of 'foo'. */
7246 static struct symtabs_and_lines
7247 expand_line_sal_maybe (struct symtab_and_line sal
)
7249 struct symtabs_and_lines expanded
;
7250 CORE_ADDR original_pc
= sal
.pc
;
7251 char *original_function
= NULL
;
7254 struct cleanup
*old_chain
;
7256 /* If we have explicit pc, don't expand.
7257 If we have no line number, we can't expand. */
7258 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7261 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7262 expanded
.sals
[0] = sal
;
7268 old_chain
= save_current_space_and_thread ();
7270 switch_to_program_space_and_thread (sal
.pspace
);
7272 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7274 /* Note that expand_line_sal visits *all* program spaces. */
7275 expanded
= expand_line_sal (sal
);
7277 if (expanded
.nelts
== 1)
7279 /* We had one sal, we got one sal. Return that sal, adjusting it
7280 past the function prologue if necessary. */
7281 xfree (expanded
.sals
);
7283 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7284 sal
.pc
= original_pc
;
7285 expanded
.sals
[0] = sal
;
7286 skip_prologue_sal (&expanded
.sals
[0]);
7287 do_cleanups (old_chain
);
7291 if (!sal
.explicit_line
)
7293 CORE_ADDR func_addr
, func_end
;
7294 for (i
= 0; i
< expanded
.nelts
; ++i
)
7296 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7297 char *this_function
;
7299 /* We need to switch threads as well since we're about to
7301 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7303 if (find_pc_partial_function (pc
, &this_function
,
7304 &func_addr
, &func_end
))
7307 && strcmp (this_function
, original_function
) != 0)
7309 remove_sal (&expanded
, i
);
7316 /* Skip the function prologue if necessary. */
7317 for (i
= 0; i
< expanded
.nelts
; ++i
)
7318 skip_prologue_sal (&expanded
.sals
[i
]);
7320 do_cleanups (old_chain
);
7322 if (expanded
.nelts
<= 1)
7324 /* This is un ugly workaround. If we get zero expanded sals
7325 then something is really wrong. Fix that by returning the
7328 xfree (expanded
.sals
);
7330 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7331 sal
.pc
= original_pc
;
7332 expanded
.sals
[0] = sal
;
7339 for (i
= 0; i
< expanded
.nelts
; ++i
)
7340 if (expanded
.sals
[i
].pc
== original_pc
)
7351 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7352 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7353 value. COND_STRING, if not NULL, specified the condition to be
7354 used for all breakpoints. Essentially the only case where
7355 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7356 function. In that case, it's still not possible to specify
7357 separate conditions for different overloaded functions, so
7358 we take just a single condition string.
7360 NOTE: If the function succeeds, the caller is expected to cleanup
7361 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7362 array contents). If the function fails (error() is called), the
7363 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7364 COND and SALS arrays and each of those arrays contents. */
7367 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7368 struct symtabs_and_lines sals
, char **addr_string
,
7370 enum bptype type
, enum bpdisp disposition
,
7371 int thread
, int task
, int ignore_count
,
7372 struct breakpoint_ops
*ops
, int from_tty
,
7373 int enabled
, int internal
)
7377 for (i
= 0; i
< sals
.nelts
; ++i
)
7379 struct symtabs_and_lines expanded
=
7380 expand_line_sal_maybe (sals
.sals
[i
]);
7382 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7383 cond_string
, type
, disposition
,
7384 thread
, task
, ignore_count
, ops
,
7385 from_tty
, enabled
, internal
);
7389 /* Parse ARG which is assumed to be a SAL specification possibly
7390 followed by conditionals. On return, SALS contains an array of SAL
7391 addresses found. ADDR_STRING contains a vector of (canonical)
7392 address strings. ARG points to the end of the SAL. */
7395 parse_breakpoint_sals (char **address
,
7396 struct symtabs_and_lines
*sals
,
7397 char ***addr_string
,
7400 char *addr_start
= *address
;
7402 *addr_string
= NULL
;
7403 /* If no arg given, or if first arg is 'if ', use the default
7405 if ((*address
) == NULL
7406 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7408 if (default_breakpoint_valid
)
7410 struct symtab_and_line sal
;
7412 init_sal (&sal
); /* Initialize to zeroes. */
7413 sals
->sals
= (struct symtab_and_line
*)
7414 xmalloc (sizeof (struct symtab_and_line
));
7415 sal
.pc
= default_breakpoint_address
;
7416 sal
.line
= default_breakpoint_line
;
7417 sal
.symtab
= default_breakpoint_symtab
;
7418 sal
.pspace
= default_breakpoint_pspace
;
7419 sal
.section
= find_pc_overlay (sal
.pc
);
7421 /* "break" without arguments is equivalent to "break *PC"
7422 where PC is the default_breakpoint_address. So make sure
7423 to set sal.explicit_pc to prevent GDB from trying to
7424 expand the list of sals to include all other instances
7425 with the same symtab and line. */
7426 sal
.explicit_pc
= 1;
7428 sals
->sals
[0] = sal
;
7432 error (_("No default breakpoint address now."));
7436 /* Force almost all breakpoints to be in terms of the
7437 current_source_symtab (which is decode_line_1's default).
7438 This should produce the results we want almost all of the
7439 time while leaving default_breakpoint_* alone.
7441 ObjC: However, don't match an Objective-C method name which
7442 may have a '+' or '-' succeeded by a '[' */
7444 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7446 if (default_breakpoint_valid
7448 || ((strchr ("+-", (*address
)[0]) != NULL
)
7449 && ((*address
)[1] != '['))))
7450 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7451 default_breakpoint_line
, addr_string
,
7454 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7455 addr_string
, not_found_ptr
);
7457 /* For any SAL that didn't have a canonical string, fill one in. */
7458 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7459 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7460 if (addr_start
!= (*address
))
7464 for (i
= 0; i
< sals
->nelts
; i
++)
7466 /* Add the string if not present. */
7467 if ((*addr_string
)[i
] == NULL
)
7468 (*addr_string
)[i
] = savestring (addr_start
,
7469 (*address
) - addr_start
);
7475 /* Convert each SAL into a real PC. Verify that the PC can be
7476 inserted as a breakpoint. If it can't throw an error. */
7479 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7483 for (i
= 0; i
< sals
->nelts
; i
++)
7484 resolve_sal_pc (&sals
->sals
[i
]);
7487 /* Fast tracepoints may have restrictions on valid locations. For
7488 instance, a fast tracepoint using a jump instead of a trap will
7489 likely have to overwrite more bytes than a trap would, and so can
7490 only be placed where the instruction is longer than the jump, or a
7491 multi-instruction sequence does not have a jump into the middle of
7495 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7496 struct symtabs_and_lines
*sals
)
7499 struct symtab_and_line
*sal
;
7501 struct cleanup
*old_chain
;
7503 for (i
= 0; i
< sals
->nelts
; i
++)
7505 sal
= &sals
->sals
[i
];
7507 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7509 old_chain
= make_cleanup (xfree
, msg
);
7512 error (_("May not have a fast tracepoint at 0x%s%s"),
7513 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7515 do_cleanups (old_chain
);
7520 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7522 struct captured_parse_breakpoint_args
*args
= data
;
7524 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7525 args
->not_found_ptr
);
7528 /* Given TOK, a string specification of condition and thread, as
7529 accepted by the 'break' command, extract the condition
7530 string and thread number and set *COND_STRING and *THREAD.
7531 PC identifies the context at which the condition should be parsed.
7532 If no condition is found, *COND_STRING is set to NULL.
7533 If no thread is found, *THREAD is set to -1. */
7535 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7536 char **cond_string
, int *thread
, int *task
)
7538 *cond_string
= NULL
;
7544 char *cond_start
= NULL
;
7545 char *cond_end
= NULL
;
7547 while (*tok
== ' ' || *tok
== '\t')
7552 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7555 toklen
= end_tok
- tok
;
7557 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7559 struct expression
*expr
;
7561 tok
= cond_start
= end_tok
+ 1;
7562 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7565 *cond_string
= savestring (cond_start
,
7566 cond_end
- cond_start
);
7568 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7574 *thread
= strtol (tok
, &tok
, 0);
7576 error (_("Junk after thread keyword."));
7577 if (!valid_thread_id (*thread
))
7578 error (_("Unknown thread %d."), *thread
);
7580 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7586 *task
= strtol (tok
, &tok
, 0);
7588 error (_("Junk after task keyword."));
7589 if (!valid_task_id (*task
))
7590 error (_("Unknown task %d."), *task
);
7593 error (_("Junk at end of arguments."));
7597 /* Decode a static tracepoint marker spec. */
7599 static struct symtabs_and_lines
7600 decode_static_tracepoint_spec (char **arg_p
)
7602 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7603 struct symtabs_and_lines sals
;
7604 struct symtab_and_line sal
;
7606 struct cleanup
*old_chain
;
7607 char *p
= &(*arg_p
)[3];
7612 while (*p
== ' ' || *p
== '\t')
7616 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7619 marker_str
= savestring (p
, endp
- p
);
7620 old_chain
= make_cleanup (xfree
, marker_str
);
7622 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7623 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7624 error (_("No known static tracepoint marker named %s"), marker_str
);
7626 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7627 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7629 for (i
= 0; i
< sals
.nelts
; i
++)
7631 struct static_tracepoint_marker
*marker
;
7633 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7635 init_sal (&sals
.sals
[i
]);
7637 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7638 sals
.sals
[i
].pc
= marker
->address
;
7640 release_static_tracepoint_marker (marker
);
7643 do_cleanups (old_chain
);
7649 /* Set a breakpoint. This function is shared between CLI and MI
7650 functions for setting a breakpoint. This function has two major
7651 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7652 parameter. If non-zero, the function will parse arg, extracting
7653 breakpoint location, address and thread. Otherwise, ARG is just
7654 the location of breakpoint, with condition and thread specified by
7655 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7656 the breakpoint number will be allocated from the internal
7657 breakpoint count. Returns true if any breakpoint was created;
7661 create_breakpoint (struct gdbarch
*gdbarch
,
7662 char *arg
, char *cond_string
, int thread
,
7663 int parse_condition_and_thread
,
7664 int tempflag
, enum bptype type_wanted
,
7666 enum auto_boolean pending_break_support
,
7667 struct breakpoint_ops
*ops
,
7668 int from_tty
, int enabled
, int internal
)
7670 struct gdb_exception e
;
7671 struct symtabs_and_lines sals
;
7672 struct symtab_and_line pending_sal
;
7674 char *addr_start
= arg
;
7676 struct cleanup
*old_chain
;
7677 struct cleanup
*bkpt_chain
= NULL
;
7678 struct captured_parse_breakpoint_args parse_args
;
7683 int prev_bkpt_count
= breakpoint_count
;
7689 parse_args
.arg_p
= &arg
;
7690 parse_args
.sals_p
= &sals
;
7691 parse_args
.addr_string_p
= &addr_string
;
7692 parse_args
.not_found_ptr
= ¬_found
;
7694 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7698 sals
= decode_static_tracepoint_spec (&arg
);
7700 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7701 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7702 for (i
= 0; i
< sals
.nelts
; i
++)
7703 addr_string
[i
] = xstrdup (copy_arg
);
7707 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7708 &parse_args
, RETURN_MASK_ALL
);
7710 /* If caller is interested in rc value from parse, set value. */
7714 throw_exception (e
);
7718 case NOT_FOUND_ERROR
:
7720 /* If pending breakpoint support is turned off, throw
7723 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7724 throw_exception (e
);
7726 exception_print (gdb_stderr
, e
);
7728 /* If pending breakpoint support is auto query and the user
7729 selects no, then simply return the error code. */
7730 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7731 && !nquery (_("Make breakpoint pending on "
7732 "future shared library load? ")))
7735 /* At this point, either the user was queried about setting
7736 a pending breakpoint and selected yes, or pending
7737 breakpoint behavior is on and thus a pending breakpoint
7738 is defaulted on behalf of the user. */
7739 copy_arg
= xstrdup (addr_start
);
7740 addr_string
= ©_arg
;
7742 sals
.sals
= &pending_sal
;
7747 throw_exception (e
);
7756 /* Create a chain of things that always need to be cleaned up. */
7757 old_chain
= make_cleanup (null_cleanup
, 0);
7761 /* Make sure that all storage allocated to SALS gets freed. */
7762 make_cleanup (xfree
, sals
.sals
);
7764 /* Cleanup the addr_string array but not its contents. */
7765 make_cleanup (xfree
, addr_string
);
7768 /* ----------------------------- SNIP -----------------------------
7769 Anything added to the cleanup chain beyond this point is assumed
7770 to be part of a breakpoint. If the breakpoint create succeeds
7771 then the memory is not reclaimed. */
7772 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7774 /* Mark the contents of the addr_string for cleanup. These go on
7775 the bkpt_chain and only occur if the breakpoint create fails. */
7776 for (i
= 0; i
< sals
.nelts
; i
++)
7778 if (addr_string
[i
] != NULL
)
7779 make_cleanup (xfree
, addr_string
[i
]);
7782 /* Resolve all line numbers to PC's and verify that the addresses
7783 are ok for the target. */
7785 breakpoint_sals_to_pc (&sals
);
7787 /* Fast tracepoints may have additional restrictions on location. */
7788 if (type_wanted
== bp_fast_tracepoint
)
7789 check_fast_tracepoint_sals (gdbarch
, &sals
);
7791 /* Verify that condition can be parsed, before setting any
7792 breakpoints. Allocate a separate condition expression for each
7796 if (parse_condition_and_thread
)
7798 /* Here we only parse 'arg' to separate condition
7799 from thread number, so parsing in context of first
7800 sal is OK. When setting the breakpoint we'll
7801 re-parse it in context of each sal. */
7804 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7807 make_cleanup (xfree
, cond_string
);
7811 /* Create a private copy of condition string. */
7814 cond_string
= xstrdup (cond_string
);
7815 make_cleanup (xfree
, cond_string
);
7819 /* If the user is creating a static tracepoint by marker id
7820 (strace -m MARKER_ID), then store the sals index, so that
7821 breakpoint_re_set can try to match up which of the newly
7822 found markers corresponds to this one, and, don't try to
7823 expand multiple locations for each sal, given than SALS
7824 already should contain all sals for MARKER_ID. */
7825 if (type_wanted
== bp_static_tracepoint
7826 && is_marker_spec (addr_string
[0]))
7830 for (i
= 0; i
< sals
.nelts
; ++i
)
7832 struct symtabs_and_lines expanded
;
7833 struct breakpoint
*tp
;
7834 struct cleanup
*old_chain
;
7837 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7838 expanded
.sals
[0] = sals
.sals
[i
];
7839 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7841 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7842 cond_string
, type_wanted
,
7843 tempflag
? disp_del
: disp_donttouch
,
7844 thread
, task
, ignore_count
, ops
,
7845 from_tty
, enabled
, internal
);
7847 do_cleanups (old_chain
);
7849 /* Get the tracepoint we just created. */
7851 tp
= get_breakpoint (internal_breakpoint_number
);
7853 tp
= get_breakpoint (breakpoint_count
);
7854 gdb_assert (tp
!= NULL
);
7856 /* Given that its possible to have multiple markers with
7857 the same string id, if the user is creating a static
7858 tracepoint by marker id ("strace -m MARKER_ID"), then
7859 store the sals index, so that breakpoint_re_set can
7860 try to match up which of the newly found markers
7861 corresponds to this one */
7862 tp
->static_trace_marker_id_idx
= i
;
7866 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7868 tempflag
? disp_del
: disp_donttouch
,
7869 thread
, task
, ignore_count
, ops
, from_tty
,
7874 struct breakpoint
*b
;
7876 make_cleanup (xfree
, copy_arg
);
7878 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7879 set_breakpoint_number (internal
, b
);
7881 b
->addr_string
= addr_string
[0];
7882 b
->cond_string
= NULL
;
7883 b
->ignore_count
= ignore_count
;
7884 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7885 b
->condition_not_parsed
= 1;
7887 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7888 b
->pspace
= current_program_space
;
7889 b
->py_bp_object
= NULL
;
7891 if (enabled
&& b
->pspace
->executing_startup
7892 && (b
->type
== bp_breakpoint
7893 || b
->type
== bp_hardware_breakpoint
))
7894 b
->enable_state
= bp_startup_disabled
;
7897 /* Do not mention breakpoints with a negative number,
7898 but do notify observers. */
7899 observer_notify_breakpoint_created (b
->number
);
7906 warning (_("Multiple breakpoints were set.\nUse the "
7907 "\"delete\" command to delete unwanted breakpoints."));
7908 prev_breakpoint_count
= prev_bkpt_count
;
7911 /* That's it. Discard the cleanups for data inserted into the
7913 discard_cleanups (bkpt_chain
);
7914 /* But cleanup everything else. */
7915 do_cleanups (old_chain
);
7917 /* error call may happen here - have BKPT_CHAIN already discarded. */
7918 update_global_location_list (1);
7923 /* Set a breakpoint.
7924 ARG is a string describing breakpoint address,
7925 condition, and thread.
7926 FLAG specifies if a breakpoint is hardware on,
7927 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7931 break_command_1 (char *arg
, int flag
, int from_tty
)
7933 int tempflag
= flag
& BP_TEMPFLAG
;
7934 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7935 ? bp_hardware_breakpoint
7938 create_breakpoint (get_current_arch (),
7940 NULL
, 0, 1 /* parse arg */,
7941 tempflag
, type_wanted
,
7942 0 /* Ignore count */,
7943 pending_break_support
,
7944 NULL
/* breakpoint_ops */,
7951 /* Helper function for break_command_1 and disassemble_command. */
7954 resolve_sal_pc (struct symtab_and_line
*sal
)
7958 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7960 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7961 error (_("No line %d in file \"%s\"."),
7962 sal
->line
, sal
->symtab
->filename
);
7965 /* If this SAL corresponds to a breakpoint inserted using a line
7966 number, then skip the function prologue if necessary. */
7967 if (sal
->explicit_line
)
7968 skip_prologue_sal (sal
);
7971 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7973 struct blockvector
*bv
;
7977 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7980 sym
= block_linkage_function (b
);
7983 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7984 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7988 /* It really is worthwhile to have the section, so we'll
7989 just have to look harder. This case can be executed
7990 if we have line numbers but no functions (as can
7991 happen in assembly source). */
7993 struct minimal_symbol
*msym
;
7994 struct cleanup
*old_chain
= save_current_space_and_thread ();
7996 switch_to_program_space_and_thread (sal
->pspace
);
7998 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8000 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8002 do_cleanups (old_chain
);
8009 break_command (char *arg
, int from_tty
)
8011 break_command_1 (arg
, 0, from_tty
);
8015 tbreak_command (char *arg
, int from_tty
)
8017 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8021 hbreak_command (char *arg
, int from_tty
)
8023 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8027 thbreak_command (char *arg
, int from_tty
)
8029 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8033 stop_command (char *arg
, int from_tty
)
8035 printf_filtered (_("Specify the type of breakpoint to set.\n\
8036 Usage: stop in <function | address>\n\
8037 stop at <line>\n"));
8041 stopin_command (char *arg
, int from_tty
)
8045 if (arg
== (char *) NULL
)
8047 else if (*arg
!= '*')
8052 /* Look for a ':'. If this is a line number specification, then
8053 say it is bad, otherwise, it should be an address or
8054 function/method name. */
8055 while (*argptr
&& !hasColon
)
8057 hasColon
= (*argptr
== ':');
8062 badInput
= (*argptr
!= ':'); /* Not a class::method */
8064 badInput
= isdigit (*arg
); /* a simple line number */
8068 printf_filtered (_("Usage: stop in <function | address>\n"));
8070 break_command_1 (arg
, 0, from_tty
);
8074 stopat_command (char *arg
, int from_tty
)
8078 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8085 /* Look for a ':'. If there is a '::' then get out, otherwise
8086 it is probably a line number. */
8087 while (*argptr
&& !hasColon
)
8089 hasColon
= (*argptr
== ':');
8094 badInput
= (*argptr
== ':'); /* we have class::method */
8096 badInput
= !isdigit (*arg
); /* not a line number */
8100 printf_filtered (_("Usage: stop at <line>\n"));
8102 break_command_1 (arg
, 0, from_tty
);
8105 /* Return non-zero if EXP is verified as constant. Returned zero
8106 means EXP is variable. Also the constant detection may fail for
8107 some constant expressions and in such case still falsely return
8110 watchpoint_exp_is_const (const struct expression
*exp
)
8118 /* We are only interested in the descriptor of each element. */
8119 operator_length (exp
, i
, &oplenp
, &argsp
);
8122 switch (exp
->elts
[i
].opcode
)
8132 case BINOP_LOGICAL_AND
:
8133 case BINOP_LOGICAL_OR
:
8134 case BINOP_BITWISE_AND
:
8135 case BINOP_BITWISE_IOR
:
8136 case BINOP_BITWISE_XOR
:
8138 case BINOP_NOTEQUAL
:
8154 case TERNOP_SLICE_COUNT
:
8166 case OP_OBJC_NSSTRING
:
8169 case UNOP_LOGICAL_NOT
:
8170 case UNOP_COMPLEMENT
:
8173 /* Unary, binary and ternary operators: We have to check
8174 their operands. If they are constant, then so is the
8175 result of that operation. For instance, if A and B are
8176 determined to be constants, then so is "A + B".
8178 UNOP_IND is one exception to the rule above, because the
8179 value of *ADDR is not necessarily a constant, even when
8184 /* Check whether the associated symbol is a constant.
8186 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8187 possible that a buggy compiler could mark a variable as
8188 constant even when it is not, and TYPE_CONST would return
8189 true in this case, while SYMBOL_CLASS wouldn't.
8191 We also have to check for function symbols because they
8192 are always constant. */
8194 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8196 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8197 && SYMBOL_CLASS (s
) != LOC_CONST
8198 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8203 /* The default action is to return 0 because we are using
8204 the optimistic approach here: If we don't know something,
8205 then it is not a constant. */
8214 /* accessflag: hw_write: watch write,
8215 hw_read: watch read,
8216 hw_access: watch access (read or write) */
8218 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8219 int just_location
, int internal
)
8221 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8222 struct expression
*exp
;
8223 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8224 struct value
*val
, *mark
, *result
;
8225 struct frame_info
*frame
;
8226 char *exp_start
= NULL
;
8227 char *exp_end
= NULL
;
8228 char *tok
, *id_tok_start
, *end_tok
;
8230 char *cond_start
= NULL
;
8231 char *cond_end
= NULL
;
8232 int i
, other_type_used
, target_resources_ok
= 0;
8233 enum bptype bp_type
;
8238 /* Make sure that we actually have parameters to parse. */
8239 if (arg
!= NULL
&& arg
[0] != '\0')
8241 toklen
= strlen (arg
); /* Size of argument list. */
8243 /* Points tok to the end of the argument list. */
8244 tok
= arg
+ toklen
- 1;
8246 /* Go backwards in the parameters list. Skip the last
8247 parameter. If we're expecting a 'thread <thread_num>'
8248 parameter, this should be the thread identifier. */
8249 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8251 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8254 /* Points end_tok to the beginning of the last token. */
8255 id_tok_start
= tok
+ 1;
8257 /* Go backwards in the parameters list. Skip one more
8258 parameter. If we're expecting a 'thread <thread_num>'
8259 parameter, we should reach a "thread" token. */
8260 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8265 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8268 /* Move the pointer forward to skip the whitespace and
8269 calculate the length of the token. */
8271 toklen
= end_tok
- tok
;
8273 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8275 /* At this point we've found a "thread" token, which means
8276 the user is trying to set a watchpoint that triggers
8277 only in a specific thread. */
8280 /* Extract the thread ID from the next token. */
8281 thread
= strtol (id_tok_start
, &endp
, 0);
8283 /* Check if the user provided a valid numeric value for the
8285 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8286 error (_("Invalid thread ID specification %s."), id_tok_start
);
8288 /* Check if the thread actually exists. */
8289 if (!valid_thread_id (thread
))
8290 error (_("Unknown thread %d."), thread
);
8292 /* Truncate the string and get rid of the thread <thread_num>
8293 parameter before the parameter list is parsed by the
8294 evaluate_expression() function. */
8299 /* Parse the rest of the arguments. */
8300 innermost_block
= NULL
;
8302 exp
= parse_exp_1 (&arg
, 0, 0);
8304 /* Remove trailing whitespace from the expression before saving it.
8305 This makes the eventual display of the expression string a bit
8307 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8310 /* Checking if the expression is not constant. */
8311 if (watchpoint_exp_is_const (exp
))
8315 len
= exp_end
- exp_start
;
8316 while (len
> 0 && isspace (exp_start
[len
- 1]))
8318 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8321 exp_valid_block
= innermost_block
;
8322 mark
= value_mark ();
8323 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8327 exp_valid_block
= NULL
;
8328 val
= value_addr (result
);
8329 release_value (val
);
8330 value_free_to_mark (mark
);
8332 else if (val
!= NULL
)
8333 release_value (val
);
8336 while (*tok
== ' ' || *tok
== '\t')
8340 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
8343 toklen
= end_tok
- tok
;
8344 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8346 struct expression
*cond
;
8348 innermost_block
= NULL
;
8349 tok
= cond_start
= end_tok
+ 1;
8350 cond
= parse_exp_1 (&tok
, 0, 0);
8352 /* The watchpoint expression may not be local, but the condition
8353 may still be. E.g.: `watch global if local > 0'. */
8354 cond_exp_valid_block
= innermost_block
;
8360 error (_("Junk at end of command."));
8362 if (accessflag
== hw_read
)
8363 bp_type
= bp_read_watchpoint
;
8364 else if (accessflag
== hw_access
)
8365 bp_type
= bp_access_watchpoint
;
8367 bp_type
= bp_hardware_watchpoint
;
8369 mem_cnt
= can_use_hardware_watchpoint (val
);
8370 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8371 error (_("Expression cannot be implemented with read/access watchpoint."));
8374 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8375 target_resources_ok
=
8376 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
8378 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8379 error (_("Target does not support this type of hardware watchpoint."));
8381 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8382 error (_("Target can only support one kind "
8383 "of HW watchpoint at a time."));
8386 /* Change the type of breakpoint to an ordinary watchpoint if a
8387 hardware watchpoint could not be set. */
8388 if (!mem_cnt
|| target_resources_ok
<= 0)
8389 bp_type
= bp_watchpoint
;
8391 frame
= block_innermost_frame (exp_valid_block
);
8393 /* If the expression is "local", then set up a "watchpoint scope"
8394 breakpoint at the point where we've left the scope of the watchpoint
8395 expression. Create the scope breakpoint before the watchpoint, so
8396 that we will encounter it first in bpstat_stop_status. */
8397 if (exp_valid_block
&& frame
)
8399 if (frame_id_p (frame_unwind_caller_id (frame
)))
8402 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8403 frame_unwind_caller_pc (frame
),
8404 bp_watchpoint_scope
);
8406 scope_breakpoint
->enable_state
= bp_enabled
;
8408 /* Automatically delete the breakpoint when it hits. */
8409 scope_breakpoint
->disposition
= disp_del
;
8411 /* Only break in the proper frame (help with recursion). */
8412 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8414 /* Set the address at which we will stop. */
8415 scope_breakpoint
->loc
->gdbarch
8416 = frame_unwind_caller_arch (frame
);
8417 scope_breakpoint
->loc
->requested_address
8418 = frame_unwind_caller_pc (frame
);
8419 scope_breakpoint
->loc
->address
8420 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8421 scope_breakpoint
->loc
->requested_address
,
8422 scope_breakpoint
->type
);
8426 /* Now set up the breakpoint. */
8427 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8428 set_breakpoint_number (internal
, b
);
8430 b
->disposition
= disp_donttouch
;
8432 b
->exp_valid_block
= exp_valid_block
;
8433 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8436 struct type
*t
= value_type (val
);
8437 CORE_ADDR addr
= value_as_address (val
);
8440 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8441 name
= type_to_string (t
);
8443 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8444 core_addr_to_string (addr
));
8447 b
->exp_string
= xstrprintf ("-location: %.*s",
8448 (int) (exp_end
- exp_start
), exp_start
);
8450 /* The above expression is in C. */
8451 b
->language
= language_c
;
8454 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8458 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8464 b
->watchpoint_frame
= get_frame_id (frame
);
8465 b
->watchpoint_thread
= inferior_ptid
;
8469 b
->watchpoint_frame
= null_frame_id
;
8470 b
->watchpoint_thread
= null_ptid
;
8473 if (scope_breakpoint
!= NULL
)
8475 /* The scope breakpoint is related to the watchpoint. We will
8476 need to act on them together. */
8477 b
->related_breakpoint
= scope_breakpoint
;
8478 scope_breakpoint
->related_breakpoint
= b
;
8482 value_free_to_mark (mark
);
8484 /* Finally update the new watchpoint. This creates the locations
8485 that should be inserted. */
8486 update_watchpoint (b
, 1);
8488 /* Do not mention breakpoints with a negative number, but do
8489 notify observers. */
8490 observer_notify_breakpoint_created (b
->number
);
8493 update_global_location_list (1);
8496 /* Return count of locations need to be watched and can be handled in
8497 hardware. If the watchpoint can not be handled in hardware return
8501 can_use_hardware_watchpoint (struct value
*v
)
8503 int found_memory_cnt
= 0;
8504 struct value
*head
= v
;
8506 /* Did the user specifically forbid us to use hardware watchpoints? */
8507 if (!can_use_hw_watchpoints
)
8510 /* Make sure that the value of the expression depends only upon
8511 memory contents, and values computed from them within GDB. If we
8512 find any register references or function calls, we can't use a
8513 hardware watchpoint.
8515 The idea here is that evaluating an expression generates a series
8516 of values, one holding the value of every subexpression. (The
8517 expression a*b+c has five subexpressions: a, b, a*b, c, and
8518 a*b+c.) GDB's values hold almost enough information to establish
8519 the criteria given above --- they identify memory lvalues,
8520 register lvalues, computed values, etcetera. So we can evaluate
8521 the expression, and then scan the chain of values that leaves
8522 behind to decide whether we can detect any possible change to the
8523 expression's final value using only hardware watchpoints.
8525 However, I don't think that the values returned by inferior
8526 function calls are special in any way. So this function may not
8527 notice that an expression involving an inferior function call
8528 can't be watched with hardware watchpoints. FIXME. */
8529 for (; v
; v
= value_next (v
))
8531 if (VALUE_LVAL (v
) == lval_memory
)
8533 if (v
!= head
&& value_lazy (v
))
8534 /* A lazy memory lvalue in the chain is one that GDB never
8535 needed to fetch; we either just used its address (e.g.,
8536 `a' in `a.b') or we never needed it at all (e.g., `a'
8537 in `a,b'). This doesn't apply to HEAD; if that is
8538 lazy then it was not readable, but watch it anyway. */
8542 /* Ahh, memory we actually used! Check if we can cover
8543 it with hardware watchpoints. */
8544 struct type
*vtype
= check_typedef (value_type (v
));
8546 /* We only watch structs and arrays if user asked for it
8547 explicitly, never if they just happen to appear in a
8548 middle of some value chain. */
8550 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8551 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8553 CORE_ADDR vaddr
= value_address (v
);
8554 int len
= TYPE_LENGTH (value_type (v
));
8556 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
8563 else if (VALUE_LVAL (v
) != not_lval
8564 && deprecated_value_modifiable (v
) == 0)
8565 return 0; /* These are values from the history (e.g., $1). */
8566 else if (VALUE_LVAL (v
) == lval_register
)
8567 return 0; /* Cannot watch a register with a HW watchpoint. */
8570 /* The expression itself looks suitable for using a hardware
8571 watchpoint, but give the target machine a chance to reject it. */
8572 return found_memory_cnt
;
8576 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
8578 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
8581 /* A helper function that looks for an argument at the start of a
8582 string. The argument must also either be at the end of the string,
8583 or be followed by whitespace. Returns 1 if it finds the argument,
8584 0 otherwise. If the argument is found, it updates *STR. */
8587 check_for_argument (char **str
, char *arg
, int arg_len
)
8589 if (strncmp (*str
, arg
, arg_len
) == 0
8590 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8598 /* A helper function that looks for the "-location" argument and then
8599 calls watch_command_1. */
8602 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8604 int just_location
= 0;
8607 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8608 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8610 ep_skip_leading_whitespace (&arg
);
8614 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
8618 watch_command (char *arg
, int from_tty
)
8620 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8624 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8626 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
8630 rwatch_command (char *arg
, int from_tty
)
8632 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8636 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8638 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
8642 awatch_command (char *arg
, int from_tty
)
8644 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8648 /* Helper routines for the until_command routine in infcmd.c. Here
8649 because it uses the mechanisms of breakpoints. */
8651 struct until_break_command_continuation_args
8653 struct breakpoint
*breakpoint
;
8654 struct breakpoint
*breakpoint2
;
8658 /* This function is called by fetch_inferior_event via the
8659 cmd_continuation pointer, to complete the until command. It takes
8660 care of cleaning up the temporary breakpoints set up by the until
8663 until_break_command_continuation (void *arg
)
8665 struct until_break_command_continuation_args
*a
= arg
;
8667 delete_breakpoint (a
->breakpoint
);
8669 delete_breakpoint (a
->breakpoint2
);
8670 delete_longjmp_breakpoint (a
->thread_num
);
8674 until_break_command (char *arg
, int from_tty
, int anywhere
)
8676 struct symtabs_and_lines sals
;
8677 struct symtab_and_line sal
;
8678 struct frame_info
*frame
= get_selected_frame (NULL
);
8679 struct breakpoint
*breakpoint
;
8680 struct breakpoint
*breakpoint2
= NULL
;
8681 struct cleanup
*old_chain
;
8683 struct thread_info
*tp
;
8685 clear_proceed_status ();
8687 /* Set a breakpoint where the user wants it and at return from
8690 if (default_breakpoint_valid
)
8691 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8692 default_breakpoint_line
, (char ***) NULL
, NULL
);
8694 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8695 0, (char ***) NULL
, NULL
);
8697 if (sals
.nelts
!= 1)
8698 error (_("Couldn't get information on specified line."));
8701 xfree (sals
.sals
); /* malloc'd, so freed. */
8704 error (_("Junk at end of arguments."));
8706 resolve_sal_pc (&sal
);
8709 /* If the user told us to continue until a specified location,
8710 we don't specify a frame at which we need to stop. */
8711 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8712 null_frame_id
, bp_until
);
8714 /* Otherwise, specify the selected frame, because we want to stop
8715 only at the very same frame. */
8716 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8717 get_stack_frame_id (frame
),
8720 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8722 tp
= inferior_thread ();
8725 /* Keep within the current frame, or in frames called by the current
8728 if (frame_id_p (frame_unwind_caller_id (frame
)))
8730 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8731 sal
.pc
= frame_unwind_caller_pc (frame
);
8732 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8734 frame_unwind_caller_id (frame
),
8736 make_cleanup_delete_breakpoint (breakpoint2
);
8738 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
8739 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
8742 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8744 /* If we are running asynchronously, and proceed call above has
8745 actually managed to start the target, arrange for breakpoints to
8746 be deleted when the target stops. Otherwise, we're already
8747 stopped and delete breakpoints via cleanup chain. */
8749 if (target_can_async_p () && is_running (inferior_ptid
))
8751 struct until_break_command_continuation_args
*args
;
8752 args
= xmalloc (sizeof (*args
));
8754 args
->breakpoint
= breakpoint
;
8755 args
->breakpoint2
= breakpoint2
;
8756 args
->thread_num
= thread
;
8758 discard_cleanups (old_chain
);
8759 add_continuation (inferior_thread (),
8760 until_break_command_continuation
, args
,
8764 do_cleanups (old_chain
);
8768 ep_skip_leading_whitespace (char **s
)
8770 if ((s
== NULL
) || (*s
== NULL
))
8772 while (isspace (**s
))
8776 /* This function attempts to parse an optional "if <cond>" clause
8777 from the arg string. If one is not found, it returns NULL.
8779 Else, it returns a pointer to the condition string. (It does not
8780 attempt to evaluate the string against a particular block.) And,
8781 it updates arg to point to the first character following the parsed
8782 if clause in the arg string. */
8785 ep_parse_optional_if_clause (char **arg
)
8789 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8792 /* Skip the "if" keyword. */
8795 /* Skip any extra leading whitespace, and record the start of the
8796 condition string. */
8797 ep_skip_leading_whitespace (arg
);
8800 /* Assume that the condition occupies the remainder of the arg
8802 (*arg
) += strlen (cond_string
);
8807 /* Commands to deal with catching events, such as signals, exceptions,
8808 process start/exit, etc. */
8812 catch_fork_temporary
, catch_vfork_temporary
,
8813 catch_fork_permanent
, catch_vfork_permanent
8818 catch_fork_command_1 (char *arg
, int from_tty
,
8819 struct cmd_list_element
*command
)
8821 struct gdbarch
*gdbarch
= get_current_arch ();
8822 char *cond_string
= NULL
;
8823 catch_fork_kind fork_kind
;
8826 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8827 tempflag
= (fork_kind
== catch_fork_temporary
8828 || fork_kind
== catch_vfork_temporary
);
8832 ep_skip_leading_whitespace (&arg
);
8834 /* The allowed syntax is:
8836 catch [v]fork if <cond>
8838 First, check if there's an if clause. */
8839 cond_string
= ep_parse_optional_if_clause (&arg
);
8841 if ((*arg
!= '\0') && !isspace (*arg
))
8842 error (_("Junk at end of arguments."));
8844 /* If this target supports it, create a fork or vfork catchpoint
8845 and enable reporting of such events. */
8848 case catch_fork_temporary
:
8849 case catch_fork_permanent
:
8850 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8851 &catch_fork_breakpoint_ops
);
8853 case catch_vfork_temporary
:
8854 case catch_vfork_permanent
:
8855 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8856 &catch_vfork_breakpoint_ops
);
8859 error (_("unsupported or unknown fork kind; cannot catch it"));
8865 catch_exec_command_1 (char *arg
, int from_tty
,
8866 struct cmd_list_element
*command
)
8868 struct gdbarch
*gdbarch
= get_current_arch ();
8870 char *cond_string
= NULL
;
8872 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8876 ep_skip_leading_whitespace (&arg
);
8878 /* The allowed syntax is:
8880 catch exec if <cond>
8882 First, check if there's an if clause. */
8883 cond_string
= ep_parse_optional_if_clause (&arg
);
8885 if ((*arg
!= '\0') && !isspace (*arg
))
8886 error (_("Junk at end of arguments."));
8888 /* If this target supports it, create an exec catchpoint
8889 and enable reporting of such events. */
8890 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8891 &catch_exec_breakpoint_ops
);
8894 static enum print_stop_action
8895 print_exception_catchpoint (struct breakpoint
*b
)
8897 int bp_temp
, bp_throw
;
8899 annotate_catchpoint (b
->number
);
8901 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8902 if (b
->loc
->address
!= b
->loc
->requested_address
)
8903 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8906 bp_temp
= b
->disposition
== disp_del
;
8908 bp_temp
? "Temporary catchpoint "
8910 if (!ui_out_is_mi_like_p (uiout
))
8911 ui_out_field_int (uiout
, "bkptno", b
->number
);
8913 bp_throw
? " (exception thrown), "
8914 : " (exception caught), ");
8915 if (ui_out_is_mi_like_p (uiout
))
8917 ui_out_field_string (uiout
, "reason",
8918 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8919 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8920 ui_out_field_int (uiout
, "bkptno", b
->number
);
8922 return PRINT_SRC_AND_LOC
;
8926 print_one_exception_catchpoint (struct breakpoint
*b
,
8927 struct bp_location
**last_loc
)
8929 struct value_print_options opts
;
8931 get_user_print_options (&opts
);
8932 if (opts
.addressprint
)
8935 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8936 ui_out_field_string (uiout
, "addr", "<PENDING>");
8938 ui_out_field_core_addr (uiout
, "addr",
8939 b
->loc
->gdbarch
, b
->loc
->address
);
8944 if (strstr (b
->addr_string
, "throw") != NULL
)
8945 ui_out_field_string (uiout
, "what", "exception throw");
8947 ui_out_field_string (uiout
, "what", "exception catch");
8951 print_mention_exception_catchpoint (struct breakpoint
*b
)
8956 bp_temp
= b
->disposition
== disp_del
;
8957 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8958 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8959 : _("Catchpoint "));
8960 ui_out_field_int (uiout
, "bkptno", b
->number
);
8961 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8965 /* Implement the "print_recreate" breakpoint_ops method for throw and
8966 catch catchpoints. */
8969 print_recreate_exception_catchpoint (struct breakpoint
*b
,
8975 bp_temp
= b
->disposition
== disp_del
;
8976 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8977 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
8978 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
8981 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8984 NULL
, /* breakpoint_hit */
8985 print_exception_catchpoint
,
8986 print_one_exception_catchpoint
,
8987 print_mention_exception_catchpoint
,
8988 print_recreate_exception_catchpoint
8992 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8993 enum exception_event_kind ex_event
, int from_tty
)
8995 char *trigger_func_name
;
8997 if (ex_event
== EX_EVENT_CATCH
)
8998 trigger_func_name
= "__cxa_begin_catch";
9000 trigger_func_name
= "__cxa_throw";
9002 create_breakpoint (get_current_arch (),
9003 trigger_func_name
, cond_string
, -1,
9004 0 /* condition and thread are valid. */,
9005 tempflag
, bp_breakpoint
,
9007 AUTO_BOOLEAN_TRUE
/* pending */,
9008 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9015 /* Deal with "catch catch" and "catch throw" commands. */
9018 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9019 int tempflag
, int from_tty
)
9021 char *cond_string
= NULL
;
9025 ep_skip_leading_whitespace (&arg
);
9027 cond_string
= ep_parse_optional_if_clause (&arg
);
9029 if ((*arg
!= '\0') && !isspace (*arg
))
9030 error (_("Junk at end of arguments."));
9032 if (ex_event
!= EX_EVENT_THROW
9033 && ex_event
!= EX_EVENT_CATCH
)
9034 error (_("Unsupported or unknown exception event; cannot catch it"));
9036 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9039 warning (_("Unsupported with this platform/compiler combination."));
9042 /* Implementation of "catch catch" command. */
9045 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9047 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9049 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9052 /* Implementation of "catch throw" command. */
9055 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9057 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9059 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9062 /* Create a breakpoint struct for Ada exception catchpoints. */
9065 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
9066 struct symtab_and_line sal
,
9070 struct expression
*cond
,
9071 struct breakpoint_ops
*ops
,
9075 struct breakpoint
*b
;
9079 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9081 loc_gdbarch
= gdbarch
;
9083 describe_other_breakpoints (loc_gdbarch
,
9084 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9085 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9086 version for exception catchpoints, because two catchpoints
9087 used for different exception names will use the same address.
9088 In this case, a "breakpoint ... also set at..." warning is
9089 unproductive. Besides, the warning phrasing is also a bit
9090 inapropriate, we should use the word catchpoint, and tell
9091 the user what type of catchpoint it is. The above is good
9092 enough for now, though. */
9095 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9096 set_breakpoint_count (breakpoint_count
+ 1);
9098 b
->enable_state
= bp_enabled
;
9099 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9100 b
->number
= breakpoint_count
;
9101 b
->ignore_count
= 0;
9102 b
->loc
->cond
= cond
;
9103 b
->addr_string
= addr_string
;
9104 b
->language
= language_ada
;
9105 b
->cond_string
= cond_string
;
9106 b
->exp_string
= exp_string
;
9111 update_global_location_list (1);
9114 /* Implement the "catch exception" command. */
9117 catch_ada_exception_command (char *arg
, int from_tty
,
9118 struct cmd_list_element
*command
)
9120 struct gdbarch
*gdbarch
= get_current_arch ();
9122 struct symtab_and_line sal
;
9123 char *addr_string
= NULL
;
9124 char *exp_string
= NULL
;
9125 char *cond_string
= NULL
;
9126 struct expression
*cond
= NULL
;
9127 struct breakpoint_ops
*ops
= NULL
;
9129 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9133 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9134 &cond_string
, &cond
, &ops
);
9135 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9136 cond_string
, cond
, ops
, tempflag
,
9140 /* Cleanup function for a syscall filter list. */
9142 clean_up_filters (void *arg
)
9144 VEC(int) *iter
= *(VEC(int) **) arg
;
9145 VEC_free (int, iter
);
9148 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9149 filter list, or NULL if no filtering is required. */
9151 catch_syscall_split_args (char *arg
)
9153 VEC(int) *result
= NULL
;
9154 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9156 while (*arg
!= '\0')
9158 int i
, syscall_number
;
9163 /* Skip whitespace. */
9164 while (isspace (*arg
))
9167 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9168 cur_name
[i
] = arg
[i
];
9172 /* Check if the user provided a syscall name or a number. */
9173 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9174 if (*endptr
== '\0')
9175 get_syscall_by_number (syscall_number
, &s
);
9178 /* We have a name. Let's check if it's valid and convert it
9180 get_syscall_by_name (cur_name
, &s
);
9182 if (s
.number
== UNKNOWN_SYSCALL
)
9183 /* Here we have to issue an error instead of a warning,
9184 because GDB cannot do anything useful if there's no
9185 syscall number to be caught. */
9186 error (_("Unknown syscall name '%s'."), cur_name
);
9189 /* Ok, it's valid. */
9190 VEC_safe_push (int, result
, s
.number
);
9193 discard_cleanups (cleanup
);
9197 /* Implement the "catch syscall" command. */
9200 catch_syscall_command_1 (char *arg
, int from_tty
,
9201 struct cmd_list_element
*command
)
9206 struct gdbarch
*gdbarch
= get_current_arch ();
9208 /* Checking if the feature if supported. */
9209 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9210 error (_("The feature 'catch syscall' is not supported on \
9211 this architeture yet."));
9213 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9215 ep_skip_leading_whitespace (&arg
);
9217 /* We need to do this first "dummy" translation in order
9218 to get the syscall XML file loaded or, most important,
9219 to display a warning to the user if there's no XML file
9220 for his/her architecture. */
9221 get_syscall_by_number (0, &s
);
9223 /* The allowed syntax is:
9225 catch syscall <name | number> [<name | number> ... <name | number>]
9227 Let's check if there's a syscall name. */
9230 filter
= catch_syscall_split_args (arg
);
9234 create_syscall_event_catchpoint (tempflag
, filter
,
9235 &catch_syscall_breakpoint_ops
);
9238 /* Implement the "catch assert" command. */
9241 catch_assert_command (char *arg
, int from_tty
,
9242 struct cmd_list_element
*command
)
9244 struct gdbarch
*gdbarch
= get_current_arch ();
9246 struct symtab_and_line sal
;
9247 char *addr_string
= NULL
;
9248 struct breakpoint_ops
*ops
= NULL
;
9250 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9254 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9255 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9256 ops
, tempflag
, from_tty
);
9260 catch_command (char *arg
, int from_tty
)
9262 error (_("Catch requires an event name."));
9267 tcatch_command (char *arg
, int from_tty
)
9269 error (_("Catch requires an event name."));
9272 /* Delete breakpoints by address or line. */
9275 clear_command (char *arg
, int from_tty
)
9277 struct breakpoint
*b
;
9278 VEC(breakpoint_p
) *found
= 0;
9281 struct symtabs_and_lines sals
;
9282 struct symtab_and_line sal
;
9287 sals
= decode_line_spec (arg
, 1);
9292 sals
.sals
= (struct symtab_and_line
*)
9293 xmalloc (sizeof (struct symtab_and_line
));
9294 make_cleanup (xfree
, sals
.sals
);
9295 init_sal (&sal
); /* Initialize to zeroes. */
9296 sal
.line
= default_breakpoint_line
;
9297 sal
.symtab
= default_breakpoint_symtab
;
9298 sal
.pc
= default_breakpoint_address
;
9299 sal
.pspace
= default_breakpoint_pspace
;
9300 if (sal
.symtab
== 0)
9301 error (_("No source file specified."));
9309 /* We don't call resolve_sal_pc here. That's not as bad as it
9310 seems, because all existing breakpoints typically have both
9311 file/line and pc set. So, if clear is given file/line, we can
9312 match this to existing breakpoint without obtaining pc at all.
9314 We only support clearing given the address explicitly
9315 present in breakpoint table. Say, we've set breakpoint
9316 at file:line. There were several PC values for that file:line,
9317 due to optimization, all in one block.
9319 We've picked one PC value. If "clear" is issued with another
9320 PC corresponding to the same file:line, the breakpoint won't
9321 be cleared. We probably can still clear the breakpoint, but
9322 since the other PC value is never presented to user, user
9323 can only find it by guessing, and it does not seem important
9326 /* For each line spec given, delete bps which correspond to it. Do
9327 it in two passes, solely to preserve the current behavior that
9328 from_tty is forced true if we delete more than one
9332 for (i
= 0; i
< sals
.nelts
; i
++)
9334 /* If exact pc given, clear bpts at that pc.
9335 If line given (pc == 0), clear all bpts on specified line.
9336 If defaulting, clear all bpts on default line
9339 defaulting sal.pc != 0 tests to do
9344 1 0 <can't happen> */
9348 /* Find all matching breakpoints and add them to 'found'. */
9352 /* Are we going to delete b? */
9353 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9355 struct bp_location
*loc
= b
->loc
;
9356 for (; loc
; loc
= loc
->next
)
9358 int pc_match
= sal
.pc
9359 && (loc
->pspace
== sal
.pspace
)
9360 && (loc
->address
== sal
.pc
)
9361 && (!section_is_overlay (loc
->section
)
9362 || loc
->section
== sal
.section
);
9363 int line_match
= ((default_match
|| (0 == sal
.pc
))
9364 && b
->source_file
!= NULL
9365 && sal
.symtab
!= NULL
9366 && sal
.pspace
== loc
->pspace
9367 && strcmp (b
->source_file
,
9368 sal
.symtab
->filename
) == 0
9369 && b
->line_number
== sal
.line
);
9370 if (pc_match
|| line_match
)
9379 VEC_safe_push(breakpoint_p
, found
, b
);
9382 /* Now go thru the 'found' chain and delete them. */
9383 if (VEC_empty(breakpoint_p
, found
))
9386 error (_("No breakpoint at %s."), arg
);
9388 error (_("No breakpoint at this line."));
9391 if (VEC_length(breakpoint_p
, found
) > 1)
9392 from_tty
= 1; /* Always report if deleted more than one. */
9395 if (VEC_length(breakpoint_p
, found
) == 1)
9396 printf_unfiltered (_("Deleted breakpoint "));
9398 printf_unfiltered (_("Deleted breakpoints "));
9400 breakpoints_changed ();
9402 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9405 printf_unfiltered ("%d ", b
->number
);
9406 delete_breakpoint (b
);
9409 putchar_unfiltered ('\n');
9412 /* Delete breakpoint in BS if they are `delete' breakpoints and
9413 all breakpoints that are marked for deletion, whether hit or not.
9414 This is called after any breakpoint is hit, or after errors. */
9417 breakpoint_auto_delete (bpstat bs
)
9419 struct breakpoint
*b
, *b_tmp
;
9421 for (; bs
; bs
= bs
->next
)
9422 if (bs
->breakpoint_at
9423 && bs
->breakpoint_at
->disposition
== disp_del
9425 delete_breakpoint (bs
->breakpoint_at
);
9427 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9429 if (b
->disposition
== disp_del_at_next_stop
)
9430 delete_breakpoint (b
);
9434 /* A comparison function for bp_location AP and BP being interfaced to
9435 qsort. Sort elements primarily by their ADDRESS (no matter what
9436 does breakpoint_address_is_meaningful say for its OWNER),
9437 secondarily by ordering first bp_permanent OWNERed elements and
9438 terciarily just ensuring the array is sorted stable way despite
9439 qsort being an instable algorithm. */
9442 bp_location_compare (const void *ap
, const void *bp
)
9444 struct bp_location
*a
= *(void **) ap
;
9445 struct bp_location
*b
= *(void **) bp
;
9446 /* A and B come from existing breakpoints having non-NULL OWNER. */
9447 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9448 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9450 if (a
->address
!= b
->address
)
9451 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9453 /* Sort permanent breakpoints first. */
9454 if (a_perm
!= b_perm
)
9455 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9457 /* Make the user-visible order stable across GDB runs. Locations of
9458 the same breakpoint can be sorted in arbitrary order. */
9460 if (a
->owner
->number
!= b
->owner
->number
)
9461 return (a
->owner
->number
> b
->owner
->number
)
9462 - (a
->owner
->number
< b
->owner
->number
);
9464 return (a
> b
) - (a
< b
);
9467 /* Set bp_location_placed_address_before_address_max and
9468 bp_location_shadow_len_after_address_max according to the current
9469 content of the bp_location array. */
9472 bp_location_target_extensions_update (void)
9474 struct bp_location
*bl
, **blp_tmp
;
9476 bp_location_placed_address_before_address_max
= 0;
9477 bp_location_shadow_len_after_address_max
= 0;
9479 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9481 CORE_ADDR start
, end
, addr
;
9483 if (!bp_location_has_shadow (bl
))
9486 start
= bl
->target_info
.placed_address
;
9487 end
= start
+ bl
->target_info
.shadow_len
;
9489 gdb_assert (bl
->address
>= start
);
9490 addr
= bl
->address
- start
;
9491 if (addr
> bp_location_placed_address_before_address_max
)
9492 bp_location_placed_address_before_address_max
= addr
;
9494 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9496 gdb_assert (bl
->address
< end
);
9497 addr
= end
- bl
->address
;
9498 if (addr
> bp_location_shadow_len_after_address_max
)
9499 bp_location_shadow_len_after_address_max
= addr
;
9503 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9504 into the inferior, only remove already-inserted locations that no
9505 longer should be inserted. Functions that delete a breakpoint or
9506 breakpoints should pass false, so that deleting a breakpoint
9507 doesn't have the side effect of inserting the locations of other
9508 breakpoints that are marked not-inserted, but should_be_inserted
9509 returns true on them.
9511 This behaviour is useful is situations close to tear-down -- e.g.,
9512 after an exec, while the target still has execution, but breakpoint
9513 shadows of the previous executable image should *NOT* be restored
9514 to the new image; or before detaching, where the target still has
9515 execution and wants to delete breakpoints from GDB's lists, and all
9516 breakpoints had already been removed from the inferior. */
9519 update_global_location_list (int should_insert
)
9521 struct breakpoint
*b
;
9522 struct bp_location
**locp
, *loc
;
9523 struct cleanup
*cleanups
;
9525 /* Used in the duplicates detection below. When iterating over all
9526 bp_locations, points to the first bp_location of a given address.
9527 Breakpoints and watchpoints of different types are never
9528 duplicates of each other. Keep one pointer for each type of
9529 breakpoint/watchpoint, so we only need to loop over all locations
9531 struct bp_location
*bp_loc_first
; /* breakpoint */
9532 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9533 struct bp_location
*awp_loc_first
; /* access watchpoint */
9534 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9536 /* Saved former bp_location array which we compare against the newly
9537 built bp_location from the current state of ALL_BREAKPOINTS. */
9538 struct bp_location
**old_location
, **old_locp
;
9539 unsigned old_location_count
;
9541 old_location
= bp_location
;
9542 old_location_count
= bp_location_count
;
9544 bp_location_count
= 0;
9545 cleanups
= make_cleanup (xfree
, old_location
);
9548 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9549 bp_location_count
++;
9551 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9554 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9556 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9557 bp_location_compare
);
9559 bp_location_target_extensions_update ();
9561 /* Identify bp_location instances that are no longer present in the
9562 new list, and therefore should be freed. Note that it's not
9563 necessary that those locations should be removed from inferior --
9564 if there's another location at the same address (previously
9565 marked as duplicate), we don't need to remove/insert the
9568 LOCP is kept in sync with OLD_LOCP, each pointing to the current
9569 and former bp_location array state respectively. */
9572 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9575 struct bp_location
*old_loc
= *old_locp
;
9576 struct bp_location
**loc2p
;
9578 /* Tells if 'old_loc' is found amoung the new locations. If
9579 not, we have to free it. */
9580 int found_object
= 0;
9581 /* Tells if the location should remain inserted in the target. */
9582 int keep_in_target
= 0;
9585 /* Skip LOCP entries which will definitely never be needed.
9586 Stop either at or being the one matching OLD_LOC. */
9587 while (locp
< bp_location
+ bp_location_count
9588 && (*locp
)->address
< old_loc
->address
)
9592 (loc2p
< bp_location
+ bp_location_count
9593 && (*loc2p
)->address
== old_loc
->address
);
9596 if (*loc2p
== old_loc
)
9603 /* If this location is no longer present, and inserted, look if
9604 there's maybe a new location at the same address. If so,
9605 mark that one inserted, and don't remove this one. This is
9606 needed so that we don't have a time window where a breakpoint
9607 at certain location is not inserted. */
9609 if (old_loc
->inserted
)
9611 /* If the location is inserted now, we might have to remove
9614 if (found_object
&& should_be_inserted (old_loc
))
9616 /* The location is still present in the location list,
9617 and still should be inserted. Don't do anything. */
9622 /* The location is either no longer present, or got
9623 disabled. See if there's another location at the
9624 same address, in which case we don't need to remove
9625 this one from the target. */
9627 /* OLD_LOC comes from existing struct breakpoint. */
9628 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9631 (loc2p
< bp_location
+ bp_location_count
9632 && (*loc2p
)->address
== old_loc
->address
);
9635 struct bp_location
*loc2
= *loc2p
;
9637 if (breakpoint_locations_match (loc2
, old_loc
))
9639 /* For the sake of should_be_inserted.
9640 Duplicates check below will fix up this
9642 loc2
->duplicate
= 0;
9644 /* Read watchpoint locations are switched to
9645 access watchpoints, if the former are not
9646 supported, but the latter are. */
9647 if (is_hardware_watchpoint (old_loc
->owner
))
9649 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9650 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9653 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9656 loc2
->target_info
= old_loc
->target_info
;
9665 if (!keep_in_target
)
9667 if (remove_breakpoint (old_loc
, mark_uninserted
))
9669 /* This is just about all we can do. We could keep
9670 this location on the global list, and try to
9671 remove it next time, but there's no particular
9672 reason why we will succeed next time.
9674 Note that at this point, old_loc->owner is still
9675 valid, as delete_breakpoint frees the breakpoint
9676 only after calling us. */
9677 printf_filtered (_("warning: Error removing "
9679 old_loc
->owner
->number
);
9687 if (removed
&& non_stop
9688 && breakpoint_address_is_meaningful (old_loc
->owner
)
9689 && !is_hardware_watchpoint (old_loc
->owner
))
9691 /* This location was removed from the target. In
9692 non-stop mode, a race condition is possible where
9693 we've removed a breakpoint, but stop events for that
9694 breakpoint are already queued and will arrive later.
9695 We apply an heuristic to be able to distinguish such
9696 SIGTRAPs from other random SIGTRAPs: we keep this
9697 breakpoint location for a bit, and will retire it
9698 after we see some number of events. The theory here
9699 is that reporting of events should, "on the average",
9700 be fair, so after a while we'll see events from all
9701 threads that have anything of interest, and no longer
9702 need to keep this breakpoint location around. We
9703 don't hold locations forever so to reduce chances of
9704 mistaking a non-breakpoint SIGTRAP for a breakpoint
9707 The heuristic failing can be disastrous on
9708 decr_pc_after_break targets.
9710 On decr_pc_after_break targets, like e.g., x86-linux,
9711 if we fail to recognize a late breakpoint SIGTRAP,
9712 because events_till_retirement has reached 0 too
9713 soon, we'll fail to do the PC adjustment, and report
9714 a random SIGTRAP to the user. When the user resumes
9715 the inferior, it will most likely immediately crash
9716 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9717 corrupted, because of being resumed e.g., in the
9718 middle of a multi-byte instruction, or skipped a
9719 one-byte instruction. This was actually seen happen
9720 on native x86-linux, and should be less rare on
9721 targets that do not support new thread events, like
9722 remote, due to the heuristic depending on
9725 Mistaking a random SIGTRAP for a breakpoint trap
9726 causes similar symptoms (PC adjustment applied when
9727 it shouldn't), but then again, playing with SIGTRAPs
9728 behind the debugger's back is asking for trouble.
9730 Since hardware watchpoint traps are always
9731 distinguishable from other traps, so we don't need to
9732 apply keep hardware watchpoint moribund locations
9733 around. We simply always ignore hardware watchpoint
9734 traps we can no longer explain. */
9736 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9737 old_loc
->owner
= NULL
;
9739 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9743 old_loc
->owner
= NULL
;
9744 decref_bp_location (&old_loc
);
9749 /* Rescan breakpoints at the same address and section, marking the
9750 first one as "first" and any others as "duplicates". This is so
9751 that the bpt instruction is only inserted once. If we have a
9752 permanent breakpoint at the same place as BPT, make that one the
9753 official one, and the rest as duplicates. Permanent breakpoints
9754 are sorted first for the same address.
9756 Do the same for hardware watchpoints, but also considering the
9757 watchpoint's type (regular/access/read) and length. */
9759 bp_loc_first
= NULL
;
9760 wp_loc_first
= NULL
;
9761 awp_loc_first
= NULL
;
9762 rwp_loc_first
= NULL
;
9763 ALL_BP_LOCATIONS (loc
, locp
)
9765 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
9767 struct breakpoint
*b
= loc
->owner
;
9768 struct bp_location
**loc_first_p
;
9770 if (b
->enable_state
== bp_disabled
9771 || b
->enable_state
== bp_call_disabled
9772 || b
->enable_state
== bp_startup_disabled
9774 || loc
->shlib_disabled
9775 || !breakpoint_address_is_meaningful (b
)
9776 || is_tracepoint (b
))
9779 /* Permanent breakpoint should always be inserted. */
9780 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9781 internal_error (__FILE__
, __LINE__
,
9782 _("allegedly permanent breakpoint is not "
9783 "actually inserted"));
9785 if (b
->type
== bp_hardware_watchpoint
)
9786 loc_first_p
= &wp_loc_first
;
9787 else if (b
->type
== bp_read_watchpoint
)
9788 loc_first_p
= &rwp_loc_first
;
9789 else if (b
->type
== bp_access_watchpoint
)
9790 loc_first_p
= &awp_loc_first
;
9792 loc_first_p
= &bp_loc_first
;
9794 if (*loc_first_p
== NULL
9795 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9796 || !breakpoint_locations_match (loc
, *loc_first_p
))
9805 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9806 && b
->enable_state
!= bp_permanent
)
9807 internal_error (__FILE__
, __LINE__
,
9808 _("another breakpoint was inserted on top of "
9809 "a permanent breakpoint"));
9812 if (breakpoints_always_inserted_mode () && should_insert
9813 && (have_live_inferiors ()
9814 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9815 insert_breakpoint_locations ();
9817 do_cleanups (cleanups
);
9821 breakpoint_retire_moribund (void)
9823 struct bp_location
*loc
;
9826 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9827 if (--(loc
->events_till_retirement
) == 0)
9829 decref_bp_location (&loc
);
9830 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9836 update_global_location_list_nothrow (int inserting
)
9838 struct gdb_exception e
;
9840 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9841 update_global_location_list (inserting
);
9844 /* Clear BKP from a BPS. */
9847 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
9851 for (bs
= bps
; bs
; bs
= bs
->next
)
9852 if (bs
->breakpoint_at
== bpt
)
9854 bs
->breakpoint_at
= NULL
;
9856 /* bs->commands will be freed later. */
9860 /* Callback for iterate_over_threads. */
9862 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9864 struct breakpoint
*bpt
= data
;
9866 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
9870 /* Delete a breakpoint and clean up all traces of it in the data
9874 delete_breakpoint (struct breakpoint
*bpt
)
9876 struct breakpoint
*b
;
9878 gdb_assert (bpt
!= NULL
);
9880 /* Has this bp already been deleted? This can happen because
9881 multiple lists can hold pointers to bp's. bpstat lists are
9884 One example of this happening is a watchpoint's scope bp. When
9885 the scope bp triggers, we notice that the watchpoint is out of
9886 scope, and delete it. We also delete its scope bp. But the
9887 scope bp is marked "auto-deleting", and is already on a bpstat.
9888 That bpstat is then checked for auto-deleting bp's, which are
9891 A real solution to this problem might involve reference counts in
9892 bp's, and/or giving them pointers back to their referencing
9893 bpstat's, and teaching delete_breakpoint to only free a bp's
9894 storage when no more references were extent. A cheaper bandaid
9896 if (bpt
->type
== bp_none
)
9899 /* At least avoid this stale reference until the reference counting
9900 of breakpoints gets resolved. */
9901 if (bpt
->related_breakpoint
!= NULL
)
9903 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9904 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9905 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9906 bpt
->related_breakpoint
= NULL
;
9909 observer_notify_breakpoint_deleted (bpt
->number
);
9911 if (breakpoint_chain
== bpt
)
9912 breakpoint_chain
= bpt
->next
;
9917 b
->next
= bpt
->next
;
9921 decref_counted_command_line (&bpt
->commands
);
9922 xfree (bpt
->cond_string
);
9923 xfree (bpt
->cond_exp
);
9924 xfree (bpt
->addr_string
);
9926 xfree (bpt
->exp_string
);
9927 xfree (bpt
->exp_string_reparse
);
9928 value_free (bpt
->val
);
9929 xfree (bpt
->source_file
);
9930 xfree (bpt
->exec_pathname
);
9931 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9934 /* Be sure no bpstat's are pointing at the breakpoint after it's
9936 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
9937 in all threeds for now. Note that we cannot just remove bpstats
9938 pointing at bpt from the stop_bpstat list entirely, as breakpoint
9939 commands are associated with the bpstat; if we remove it here,
9940 then the later call to bpstat_do_actions (&stop_bpstat); in
9941 event-top.c won't do anything, and temporary breakpoints with
9942 commands won't work. */
9944 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9946 /* Now that breakpoint is removed from breakpoint list, update the
9947 global location list. This will remove locations that used to
9948 belong to this breakpoint. Do this before freeing the breakpoint
9949 itself, since remove_breakpoint looks at location's owner. It
9950 might be better design to have location completely
9951 self-contained, but it's not the case now. */
9952 update_global_location_list (0);
9955 /* On the chance that someone will soon try again to delete this
9956 same bp, we mark it as deleted before freeing its storage. */
9957 bpt
->type
= bp_none
;
9963 do_delete_breakpoint_cleanup (void *b
)
9965 delete_breakpoint (b
);
9969 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9971 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9974 /* A callback for map_breakpoint_numbers that calls
9975 delete_breakpoint. */
9978 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9980 delete_breakpoint (b
);
9984 delete_command (char *arg
, int from_tty
)
9986 struct breakpoint
*b
, *b_tmp
;
9992 int breaks_to_delete
= 0;
9994 /* Delete all breakpoints if no argument.
9995 Do not delete internal or call-dummy breakpoints, these have
9996 to be deleted with an explicit breakpoint number argument. */
9999 if (b
->type
!= bp_call_dummy
10000 && b
->type
!= bp_std_terminate
10001 && b
->type
!= bp_shlib_event
10002 && b
->type
!= bp_jit_event
10003 && b
->type
!= bp_thread_event
10004 && b
->type
!= bp_overlay_event
10005 && b
->type
!= bp_longjmp_master
10006 && b
->type
!= bp_std_terminate_master
10007 && b
->type
!= bp_exception_master
10010 breaks_to_delete
= 1;
10015 /* Ask user only if there are some breakpoints to delete. */
10017 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
10019 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10021 if (b
->type
!= bp_call_dummy
10022 && b
->type
!= bp_std_terminate
10023 && b
->type
!= bp_shlib_event
10024 && b
->type
!= bp_thread_event
10025 && b
->type
!= bp_jit_event
10026 && b
->type
!= bp_overlay_event
10027 && b
->type
!= bp_longjmp_master
10028 && b
->type
!= bp_std_terminate_master
10029 && b
->type
!= bp_exception_master
10031 delete_breakpoint (b
);
10036 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10040 all_locations_are_pending (struct bp_location
*loc
)
10042 for (; loc
; loc
= loc
->next
)
10043 if (!loc
->shlib_disabled
)
10048 /* Subroutine of update_breakpoint_locations to simplify it.
10049 Return non-zero if multiple fns in list LOC have the same name.
10050 Null names are ignored. */
10053 ambiguous_names_p (struct bp_location
*loc
)
10055 struct bp_location
*l
;
10056 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
10057 (int (*) (const void *,
10058 const void *)) streq
,
10059 NULL
, xcalloc
, xfree
);
10061 for (l
= loc
; l
!= NULL
; l
= l
->next
)
10064 const char *name
= l
->function_name
;
10066 /* Allow for some names to be NULL, ignore them. */
10070 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
10072 /* NOTE: We can assume slot != NULL here because xcalloc never
10076 htab_delete (htab
);
10082 htab_delete (htab
);
10086 /* When symbols change, it probably means the sources changed as well,
10087 and it might mean the static tracepoint markers are no longer at
10088 the same address or line numbers they used to be at last we
10089 checked. Losing your static tracepoints whenever you rebuild is
10090 undesirable. This function tries to resync/rematch gdb static
10091 tracepoints with the markers on the target, for static tracepoints
10092 that have not been set by marker id. Static tracepoint that have
10093 been set by marker id are reset by marker id in breakpoint_re_set.
10096 1) For a tracepoint set at a specific address, look for a marker at
10097 the old PC. If one is found there, assume to be the same marker.
10098 If the name / string id of the marker found is different from the
10099 previous known name, assume that means the user renamed the marker
10100 in the sources, and output a warning.
10102 2) For a tracepoint set at a given line number, look for a marker
10103 at the new address of the old line number. If one is found there,
10104 assume to be the same marker. If the name / string id of the
10105 marker found is different from the previous known name, assume that
10106 means the user renamed the marker in the sources, and output a
10109 3) If a marker is no longer found at the same address or line, it
10110 may mean the marker no longer exists. But it may also just mean
10111 the code changed a bit. Maybe the user added a few lines of code
10112 that made the marker move up or down (in line number terms). Ask
10113 the target for info about the marker with the string id as we knew
10114 it. If found, update line number and address in the matching
10115 static tracepoint. This will get confused if there's more than one
10116 marker with the same ID (possible in UST, although unadvised
10117 precisely because it confuses tools). */
10119 static struct symtab_and_line
10120 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10122 struct static_tracepoint_marker marker
;
10128 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10130 if (target_static_tracepoint_marker_at (pc
, &marker
))
10132 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10133 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10135 b
->static_trace_marker_id
, marker
.str_id
);
10137 xfree (b
->static_trace_marker_id
);
10138 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10139 release_static_tracepoint_marker (&marker
);
10144 /* Old marker wasn't found on target at lineno. Try looking it up
10146 if (!sal
.explicit_pc
10148 && sal
.symtab
!= NULL
10149 && b
->static_trace_marker_id
!= NULL
)
10151 VEC(static_tracepoint_marker_p
) *markers
;
10154 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10156 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10158 struct symtab_and_line sal
;
10159 struct symbol
*sym
;
10160 struct static_tracepoint_marker
*marker
;
10162 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10164 xfree (b
->static_trace_marker_id
);
10165 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10167 warning (_("marker for static tracepoint %d (%s) not "
10168 "found at previous line number"),
10169 b
->number
, b
->static_trace_marker_id
);
10173 sal
.pc
= marker
->address
;
10175 sal
= find_pc_line (marker
->address
, 0);
10176 sym
= find_pc_sect_function (marker
->address
, NULL
);
10177 ui_out_text (uiout
, "Now in ");
10180 ui_out_field_string (uiout
, "func",
10181 SYMBOL_PRINT_NAME (sym
));
10182 ui_out_text (uiout
, " at ");
10184 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
10185 ui_out_text (uiout
, ":");
10187 if (ui_out_is_mi_like_p (uiout
))
10189 char *fullname
= symtab_to_fullname (sal
.symtab
);
10192 ui_out_field_string (uiout
, "fullname", fullname
);
10195 ui_out_field_int (uiout
, "line", sal
.line
);
10196 ui_out_text (uiout
, "\n");
10198 b
->line_number
= sal
.line
;
10200 xfree (b
->source_file
);
10202 b
->source_file
= xstrdup (sal
.symtab
->filename
);
10204 b
->source_file
= NULL
;
10206 xfree (b
->addr_string
);
10207 b
->addr_string
= xstrprintf ("%s:%d",
10208 sal
.symtab
->filename
, b
->line_number
);
10210 /* Might be nice to check if function changed, and warn if
10213 release_static_tracepoint_marker (marker
);
10220 update_breakpoint_locations (struct breakpoint
*b
,
10221 struct symtabs_and_lines sals
)
10225 struct bp_location
*existing_locations
= b
->loc
;
10227 /* If there's no new locations, and all existing locations are
10228 pending, don't do anything. This optimizes the common case where
10229 all locations are in the same shared library, that was unloaded.
10230 We'd like to retain the location, so that when the library is
10231 loaded again, we don't loose the enabled/disabled status of the
10232 individual locations. */
10233 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10238 for (i
= 0; i
< sals
.nelts
; ++i
)
10240 struct bp_location
*new_loc
=
10241 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10243 /* Reparse conditions, they might contain references to the
10245 if (b
->cond_string
!= NULL
)
10247 struct gdb_exception e
;
10249 s
= b
->cond_string
;
10250 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10252 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10257 warning (_("failed to reevaluate condition "
10258 "for breakpoint %d: %s"),
10259 b
->number
, e
.message
);
10260 new_loc
->enabled
= 0;
10264 if (b
->source_file
!= NULL
)
10265 xfree (b
->source_file
);
10266 if (sals
.sals
[i
].symtab
== NULL
)
10267 b
->source_file
= NULL
;
10269 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10271 if (b
->line_number
== 0)
10272 b
->line_number
= sals
.sals
[i
].line
;
10275 /* Update locations of permanent breakpoints. */
10276 if (b
->enable_state
== bp_permanent
)
10277 make_breakpoint_permanent (b
);
10279 /* If possible, carry over 'disable' status from existing
10282 struct bp_location
*e
= existing_locations
;
10283 /* If there are multiple breakpoints with the same function name,
10284 e.g. for inline functions, comparing function names won't work.
10285 Instead compare pc addresses; this is just a heuristic as things
10286 may have moved, but in practice it gives the correct answer
10287 often enough until a better solution is found. */
10288 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10290 for (; e
; e
= e
->next
)
10292 if (!e
->enabled
&& e
->function_name
)
10294 struct bp_location
*l
= b
->loc
;
10295 if (have_ambiguous_names
)
10297 for (; l
; l
= l
->next
)
10298 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10299 l
->pspace
->aspace
, l
->address
))
10307 for (; l
; l
= l
->next
)
10308 if (l
->function_name
10309 && strcmp (e
->function_name
, l
->function_name
) == 0)
10319 update_global_location_list (1);
10322 /* Reset a breakpoint given it's struct breakpoint * BINT.
10323 The value we return ends up being the return value from catch_errors.
10324 Unused in this case. */
10327 breakpoint_re_set_one (void *bint
)
10329 /* Get past catch_errs. */
10330 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10332 int *not_found_ptr
= ¬_found
;
10333 struct symtabs_and_lines sals
= {0};
10334 struct symtabs_and_lines expanded
= {0};
10336 struct gdb_exception e
;
10337 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10338 int marker_spec
= 0;
10343 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10346 case bp_breakpoint
:
10347 case bp_hardware_breakpoint
:
10348 case bp_tracepoint
:
10349 case bp_fast_tracepoint
:
10350 case bp_static_tracepoint
:
10351 /* Do not attempt to re-set breakpoints disabled during startup. */
10352 if (b
->enable_state
== bp_startup_disabled
)
10355 if (b
->addr_string
== NULL
)
10357 /* Anything without a string can't be re-set. */
10358 delete_breakpoint (b
);
10362 input_radix
= b
->input_radix
;
10363 s
= b
->addr_string
;
10365 save_current_space_and_thread ();
10366 switch_to_program_space_and_thread (b
->pspace
);
10368 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10370 set_language (b
->language
);
10371 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10375 sals
= decode_static_tracepoint_spec (&s
);
10376 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10378 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10382 error (_("marker %s not found"), b
->static_trace_marker_id
);
10385 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0,
10386 (char ***) NULL
, not_found_ptr
);
10390 int not_found_and_ok
= 0;
10391 /* For pending breakpoints, it's expected that parsing will
10392 fail until the right shared library is loaded. User has
10393 already told to create pending breakpoints and don't need
10394 extra messages. If breakpoint is in bp_shlib_disabled
10395 state, then user already saw the message about that
10396 breakpoint being disabled, and don't want to see more
10399 && (b
->condition_not_parsed
10400 || (b
->loc
&& b
->loc
->shlib_disabled
)
10401 || b
->enable_state
== bp_disabled
))
10402 not_found_and_ok
= 1;
10404 if (!not_found_and_ok
)
10406 /* We surely don't want to warn about the same breakpoint
10407 10 times. One solution, implemented here, is disable
10408 the breakpoint on error. Another solution would be to
10409 have separate 'warning emitted' flag. Since this
10410 happens only when a binary has changed, I don't know
10411 which approach is better. */
10412 b
->enable_state
= bp_disabled
;
10413 throw_exception (e
);
10419 gdb_assert (sals
.nelts
== 1);
10421 resolve_sal_pc (&sals
.sals
[0]);
10422 if (b
->condition_not_parsed
&& s
&& s
[0])
10424 char *cond_string
= 0;
10428 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10429 &cond_string
, &thread
, &task
);
10431 b
->cond_string
= cond_string
;
10432 b
->thread
= thread
;
10434 b
->condition_not_parsed
= 0;
10437 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10438 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10440 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10443 make_cleanup (xfree
, sals
.sals
);
10444 update_breakpoint_locations (b
, expanded
);
10447 case bp_watchpoint
:
10448 case bp_hardware_watchpoint
:
10449 case bp_read_watchpoint
:
10450 case bp_access_watchpoint
:
10451 /* Watchpoint can be either on expression using entirely global
10452 variables, or it can be on local variables.
10454 Watchpoints of the first kind are never auto-deleted, and
10455 even persist across program restarts. Since they can use
10456 variables from shared libraries, we need to reparse
10457 expression as libraries are loaded and unloaded.
10459 Watchpoints on local variables can also change meaning as
10460 result of solib event. For example, if a watchpoint uses
10461 both a local and a global variables in expression, it's a
10462 local watchpoint, but unloading of a shared library will make
10463 the expression invalid. This is not a very common use case,
10464 but we still re-evaluate expression, to avoid surprises to
10467 Note that for local watchpoints, we re-evaluate it only if
10468 watchpoints frame id is still valid. If it's not, it means
10469 the watchpoint is out of scope and will be deleted soon. In
10470 fact, I'm not sure we'll ever be called in this case.
10472 If a local watchpoint's frame id is still valid, then
10473 b->exp_valid_block is likewise valid, and we can safely use it.
10475 Don't do anything about disabled watchpoints, since they will
10476 be reevaluated again when enabled. */
10477 update_watchpoint (b
, 1 /* reparse */);
10479 /* We needn't really do anything to reset these, since the mask
10480 that requests them is unaffected by e.g., new libraries being
10482 case bp_catchpoint
:
10486 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10488 /* Delete overlay event and longjmp master breakpoints; they will be
10489 reset later by breakpoint_re_set. */
10490 case bp_overlay_event
:
10491 case bp_longjmp_master
:
10492 case bp_std_terminate_master
:
10493 case bp_exception_master
:
10494 delete_breakpoint (b
);
10497 /* This breakpoint is special, it's set up when the inferior
10498 starts and we really don't want to touch it. */
10499 case bp_shlib_event
:
10501 /* Like bp_shlib_event, this breakpoint type is special.
10502 Once it is set up, we do not want to touch it. */
10503 case bp_thread_event
:
10505 /* Keep temporary breakpoints, which can be encountered when we
10506 step over a dlopen call and SOLIB_ADD is resetting the
10507 breakpoints. Otherwise these should have been blown away via
10508 the cleanup chain or by breakpoint_init_inferior when we
10509 rerun the executable. */
10512 case bp_watchpoint_scope
:
10513 case bp_call_dummy
:
10514 case bp_std_terminate
:
10515 case bp_step_resume
:
10517 case bp_longjmp_resume
:
10519 case bp_exception_resume
:
10524 do_cleanups (cleanups
);
10528 /* Re-set all breakpoints after symbols have been re-loaded. */
10530 breakpoint_re_set (void)
10532 struct breakpoint
*b
, *b_tmp
;
10533 enum language save_language
;
10534 int save_input_radix
;
10535 struct cleanup
*old_chain
;
10537 save_language
= current_language
->la_language
;
10538 save_input_radix
= input_radix
;
10539 old_chain
= save_current_program_space ();
10541 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10543 /* Format possible error msg. */
10544 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10546 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10547 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10548 do_cleanups (cleanups
);
10550 set_language (save_language
);
10551 input_radix
= save_input_radix
;
10553 jit_breakpoint_re_set ();
10555 do_cleanups (old_chain
);
10557 create_overlay_event_breakpoint ("_ovly_debug_event");
10558 create_longjmp_master_breakpoint ("longjmp");
10559 create_longjmp_master_breakpoint ("_longjmp");
10560 create_longjmp_master_breakpoint ("siglongjmp");
10561 create_longjmp_master_breakpoint ("_siglongjmp");
10562 create_std_terminate_master_breakpoint ("std::terminate()");
10563 create_exception_master_breakpoint ();
10566 /* Reset the thread number of this breakpoint:
10568 - If the breakpoint is for all threads, leave it as-is.
10569 - Else, reset it to the current thread for inferior_ptid. */
10571 breakpoint_re_set_thread (struct breakpoint
*b
)
10573 if (b
->thread
!= -1)
10575 if (in_thread_list (inferior_ptid
))
10576 b
->thread
= pid_to_thread_id (inferior_ptid
);
10578 /* We're being called after following a fork. The new fork is
10579 selected as current, and unless this was a vfork will have a
10580 different program space from the original thread. Reset that
10582 b
->loc
->pspace
= current_program_space
;
10586 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10587 If from_tty is nonzero, it prints a message to that effect,
10588 which ends with a period (no newline). */
10591 set_ignore_count (int bptnum
, int count
, int from_tty
)
10593 struct breakpoint
*b
;
10598 ALL_BREAKPOINTS (b
)
10599 if (b
->number
== bptnum
)
10601 if (is_tracepoint (b
))
10603 if (from_tty
&& count
!= 0)
10604 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10609 b
->ignore_count
= count
;
10613 printf_filtered (_("Will stop next time "
10614 "breakpoint %d is reached."),
10616 else if (count
== 1)
10617 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10620 printf_filtered (_("Will ignore next %d "
10621 "crossings of breakpoint %d."),
10624 breakpoints_changed ();
10625 observer_notify_breakpoint_modified (b
->number
);
10629 error (_("No breakpoint number %d."), bptnum
);
10633 make_breakpoint_silent (struct breakpoint
*b
)
10635 /* Silence the breakpoint. */
10639 /* Command to set ignore-count of breakpoint N to COUNT. */
10642 ignore_command (char *args
, int from_tty
)
10648 error_no_arg (_("a breakpoint number"));
10650 num
= get_number (&p
);
10652 error (_("bad breakpoint number: '%s'"), args
);
10654 error (_("Second argument (specified ignore-count) is missing."));
10656 set_ignore_count (num
,
10657 longest_to_int (value_as_long (parse_and_eval (p
))),
10660 printf_filtered ("\n");
10663 /* Call FUNCTION on each of the breakpoints
10664 whose numbers are given in ARGS. */
10667 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10674 struct breakpoint
*b
, *tmp
;
10678 error_no_arg (_("one or more breakpoint numbers"));
10685 num
= get_number_or_range (&p1
);
10688 warning (_("bad breakpoint number at or near '%s'"), p
);
10692 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10693 if (b
->number
== num
)
10695 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10697 function (b
, data
);
10698 if (related_breakpoint
)
10699 function (related_breakpoint
, data
);
10703 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
10709 static struct bp_location
*
10710 find_location_by_number (char *number
)
10712 char *dot
= strchr (number
, '.');
10716 struct breakpoint
*b
;
10717 struct bp_location
*loc
;
10722 bp_num
= get_number_or_range (&p1
);
10724 error (_("Bad breakpoint number '%s'"), number
);
10726 ALL_BREAKPOINTS (b
)
10727 if (b
->number
== bp_num
)
10732 if (!b
|| b
->number
!= bp_num
)
10733 error (_("Bad breakpoint number '%s'"), number
);
10736 loc_num
= get_number_or_range (&p1
);
10738 error (_("Bad breakpoint location number '%s'"), number
);
10742 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
10745 error (_("Bad breakpoint location number '%s'"), dot
+1);
10751 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10752 If from_tty is nonzero, it prints a message to that effect,
10753 which ends with a period (no newline). */
10756 disable_breakpoint (struct breakpoint
*bpt
)
10758 /* Never disable a watchpoint scope breakpoint; we want to
10759 hit them when we leave scope so we can delete both the
10760 watchpoint and its scope breakpoint at that time. */
10761 if (bpt
->type
== bp_watchpoint_scope
)
10764 /* You can't disable permanent breakpoints. */
10765 if (bpt
->enable_state
== bp_permanent
)
10768 bpt
->enable_state
= bp_disabled
;
10770 update_global_location_list (0);
10772 observer_notify_breakpoint_modified (bpt
->number
);
10775 /* A callback for map_breakpoint_numbers that calls
10776 disable_breakpoint. */
10779 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
10781 disable_breakpoint (b
);
10785 disable_command (char *args
, int from_tty
)
10787 struct breakpoint
*bpt
;
10790 ALL_BREAKPOINTS (bpt
)
10794 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10797 case bp_breakpoint
:
10798 case bp_tracepoint
:
10799 case bp_fast_tracepoint
:
10800 case bp_static_tracepoint
:
10801 case bp_catchpoint
:
10802 case bp_hardware_breakpoint
:
10803 case bp_watchpoint
:
10804 case bp_hardware_watchpoint
:
10805 case bp_read_watchpoint
:
10806 case bp_access_watchpoint
:
10807 disable_breakpoint (bpt
);
10811 else if (strchr (args
, '.'))
10813 struct bp_location
*loc
= find_location_by_number (args
);
10816 update_global_location_list (0);
10819 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10823 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10825 int target_resources_ok
;
10827 if (bpt
->type
== bp_hardware_breakpoint
)
10830 i
= hw_breakpoint_used_count ();
10831 target_resources_ok
=
10832 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10834 if (target_resources_ok
== 0)
10835 error (_("No hardware breakpoint support in the target."));
10836 else if (target_resources_ok
< 0)
10837 error (_("Hardware breakpoints used exceeds limit."));
10840 if (is_watchpoint (bpt
))
10842 struct gdb_exception e
;
10844 TRY_CATCH (e
, RETURN_MASK_ALL
)
10846 update_watchpoint (bpt
, 1 /* reparse */);
10850 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10856 if (bpt
->enable_state
!= bp_permanent
)
10857 bpt
->enable_state
= bp_enabled
;
10858 bpt
->disposition
= disposition
;
10859 update_global_location_list (1);
10860 breakpoints_changed ();
10862 observer_notify_breakpoint_modified (bpt
->number
);
10867 enable_breakpoint (struct breakpoint
*bpt
)
10869 do_enable_breakpoint (bpt
, bpt
->disposition
);
10872 /* A callback for map_breakpoint_numbers that calls
10873 enable_breakpoint. */
10876 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10878 enable_breakpoint (b
);
10881 /* The enable command enables the specified breakpoints (or all defined
10882 breakpoints) so they once again become (or continue to be) effective
10883 in stopping the inferior. */
10886 enable_command (char *args
, int from_tty
)
10888 struct breakpoint
*bpt
;
10891 ALL_BREAKPOINTS (bpt
)
10895 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10898 case bp_breakpoint
:
10899 case bp_tracepoint
:
10900 case bp_fast_tracepoint
:
10901 case bp_static_tracepoint
:
10902 case bp_catchpoint
:
10903 case bp_hardware_breakpoint
:
10904 case bp_watchpoint
:
10905 case bp_hardware_watchpoint
:
10906 case bp_read_watchpoint
:
10907 case bp_access_watchpoint
:
10908 enable_breakpoint (bpt
);
10912 else if (strchr (args
, '.'))
10914 struct bp_location
*loc
= find_location_by_number (args
);
10917 update_global_location_list (1);
10920 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10924 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10926 do_enable_breakpoint (bpt
, disp_disable
);
10930 enable_once_command (char *args
, int from_tty
)
10932 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10936 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10938 do_enable_breakpoint (bpt
, disp_del
);
10942 enable_delete_command (char *args
, int from_tty
)
10944 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10948 set_breakpoint_cmd (char *args
, int from_tty
)
10953 show_breakpoint_cmd (char *args
, int from_tty
)
10957 /* Invalidate last known value of any hardware watchpoint if
10958 the memory which that value represents has been written to by
10962 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10963 const bfd_byte
*data
)
10965 struct breakpoint
*bp
;
10967 ALL_BREAKPOINTS (bp
)
10968 if (bp
->enable_state
== bp_enabled
10969 && bp
->type
== bp_hardware_watchpoint
10970 && bp
->val_valid
&& bp
->val
)
10972 struct bp_location
*loc
;
10974 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10975 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10976 && loc
->address
+ loc
->length
> addr
10977 && addr
+ len
> loc
->address
)
10979 value_free (bp
->val
);
10986 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10988 struct symtabs_and_lines
10989 decode_line_spec_1 (char *string
, int funfirstline
)
10991 struct symtabs_and_lines sals
;
10994 error (_("Empty line specification."));
10995 if (default_breakpoint_valid
)
10996 sals
= decode_line_1 (&string
, funfirstline
,
10997 default_breakpoint_symtab
,
10998 default_breakpoint_line
,
10999 (char ***) NULL
, NULL
);
11001 sals
= decode_line_1 (&string
, funfirstline
,
11002 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
11004 error (_("Junk at end of line specification: %s"), string
);
11008 /* Create and insert a raw software breakpoint at PC. Return an
11009 identifier, which should be used to remove the breakpoint later.
11010 In general, places which call this should be using something on the
11011 breakpoint chain instead; this function should be eliminated
11015 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
11016 struct address_space
*aspace
, CORE_ADDR pc
)
11018 struct bp_target_info
*bp_tgt
;
11020 bp_tgt
= XZALLOC (struct bp_target_info
);
11022 bp_tgt
->placed_address_space
= aspace
;
11023 bp_tgt
->placed_address
= pc
;
11025 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
11027 /* Could not insert the breakpoint. */
11035 /* Remove a breakpoint BP inserted by
11036 deprecated_insert_raw_breakpoint. */
11039 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
11041 struct bp_target_info
*bp_tgt
= bp
;
11044 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
11050 /* One (or perhaps two) breakpoints used for software single
11053 static void *single_step_breakpoints
[2];
11054 static struct gdbarch
*single_step_gdbarch
[2];
11056 /* Create and insert a breakpoint for software single step. */
11059 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
11060 struct address_space
*aspace
,
11065 if (single_step_breakpoints
[0] == NULL
)
11067 bpt_p
= &single_step_breakpoints
[0];
11068 single_step_gdbarch
[0] = gdbarch
;
11072 gdb_assert (single_step_breakpoints
[1] == NULL
);
11073 bpt_p
= &single_step_breakpoints
[1];
11074 single_step_gdbarch
[1] = gdbarch
;
11077 /* NOTE drow/2006-04-11: A future improvement to this function would
11078 be to only create the breakpoints once, and actually put them on
11079 the breakpoint chain. That would let us use set_raw_breakpoint.
11080 We could adjust the addresses each time they were needed. Doing
11081 this requires corresponding changes elsewhere where single step
11082 breakpoints are handled, however. So, for now, we use this. */
11084 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
11085 if (*bpt_p
== NULL
)
11086 error (_("Could not insert single-step breakpoint at %s"),
11087 paddress (gdbarch
, next_pc
));
11090 /* Check if the breakpoints used for software single stepping
11091 were inserted or not. */
11094 single_step_breakpoints_inserted (void)
11096 return (single_step_breakpoints
[0] != NULL
11097 || single_step_breakpoints
[1] != NULL
);
11100 /* Remove and delete any breakpoints used for software single step. */
11103 remove_single_step_breakpoints (void)
11105 gdb_assert (single_step_breakpoints
[0] != NULL
);
11107 /* See insert_single_step_breakpoint for more about this deprecated
11109 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
11110 single_step_breakpoints
[0]);
11111 single_step_gdbarch
[0] = NULL
;
11112 single_step_breakpoints
[0] = NULL
;
11114 if (single_step_breakpoints
[1] != NULL
)
11116 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
11117 single_step_breakpoints
[1]);
11118 single_step_gdbarch
[1] = NULL
;
11119 single_step_breakpoints
[1] = NULL
;
11123 /* Delete software single step breakpoints without removing them from
11124 the inferior. This is intended to be used if the inferior's address
11125 space where they were inserted is already gone, e.g. after exit or
11129 cancel_single_step_breakpoints (void)
11133 for (i
= 0; i
< 2; i
++)
11134 if (single_step_breakpoints
[i
])
11136 xfree (single_step_breakpoints
[i
]);
11137 single_step_breakpoints
[i
] = NULL
;
11138 single_step_gdbarch
[i
] = NULL
;
11142 /* Detach software single-step breakpoints from INFERIOR_PTID without
11146 detach_single_step_breakpoints (void)
11150 for (i
= 0; i
< 2; i
++)
11151 if (single_step_breakpoints
[i
])
11152 target_remove_breakpoint (single_step_gdbarch
[i
],
11153 single_step_breakpoints
[i
]);
11156 /* Check whether a software single-step breakpoint is inserted at
11160 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
11165 for (i
= 0; i
< 2; i
++)
11167 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
11169 && breakpoint_address_match (bp_tgt
->placed_address_space
,
11170 bp_tgt
->placed_address
,
11178 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11179 non-zero otherwise. */
11181 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
11183 if (syscall_catchpoint_p (bp
)
11184 && bp
->enable_state
!= bp_disabled
11185 && bp
->enable_state
!= bp_call_disabled
)
11192 catch_syscall_enabled (void)
11194 struct inferior
*inf
= current_inferior ();
11196 return inf
->total_syscalls_count
!= 0;
11200 catching_syscall_number (int syscall_number
)
11202 struct breakpoint
*bp
;
11204 ALL_BREAKPOINTS (bp
)
11205 if (is_syscall_catchpoint_enabled (bp
))
11207 if (bp
->syscalls_to_be_caught
)
11211 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
11213 if (syscall_number
== iter
)
11223 /* Complete syscall names. Used by "catch syscall". */
11225 catch_syscall_completer (struct cmd_list_element
*cmd
,
11226 char *text
, char *word
)
11228 const char **list
= get_syscall_names ();
11230 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
11233 /* Tracepoint-specific operations. */
11235 /* Set tracepoint count to NUM. */
11237 set_tracepoint_count (int num
)
11239 tracepoint_count
= num
;
11240 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11244 trace_command (char *arg
, int from_tty
)
11246 if (create_breakpoint (get_current_arch (),
11248 NULL
, 0, 1 /* parse arg */,
11250 bp_tracepoint
/* type_wanted */,
11251 0 /* Ignore count */,
11252 pending_break_support
,
11257 set_tracepoint_count (breakpoint_count
);
11261 ftrace_command (char *arg
, int from_tty
)
11263 if (create_breakpoint (get_current_arch (),
11265 NULL
, 0, 1 /* parse arg */,
11267 bp_fast_tracepoint
/* type_wanted */,
11268 0 /* Ignore count */,
11269 pending_break_support
,
11274 set_tracepoint_count (breakpoint_count
);
11277 /* strace command implementation. Creates a static tracepoint. */
11280 strace_command (char *arg
, int from_tty
)
11282 if (create_breakpoint (get_current_arch (),
11284 NULL
, 0, 1 /* parse arg */,
11286 bp_static_tracepoint
/* type_wanted */,
11287 0 /* Ignore count */,
11288 pending_break_support
,
11293 set_tracepoint_count (breakpoint_count
);
11296 /* Set up a fake reader function that gets command lines from a linked
11297 list that was acquired during tracepoint uploading. */
11299 static struct uploaded_tp
*this_utp
;
11300 static int next_cmd
;
11303 read_uploaded_action (void)
11307 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11314 /* Given information about a tracepoint as recorded on a target (which
11315 can be either a live system or a trace file), attempt to create an
11316 equivalent GDB tracepoint. This is not a reliable process, since
11317 the target does not necessarily have all the information used when
11318 the tracepoint was originally defined. */
11320 struct breakpoint
*
11321 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11323 char *addr_str
, small_buf
[100];
11324 struct breakpoint
*tp
;
11326 if (utp
->at_string
)
11327 addr_str
= utp
->at_string
;
11330 /* In the absence of a source location, fall back to raw
11331 address. Since there is no way to confirm that the address
11332 means the same thing as when the trace was started, warn the
11334 warning (_("Uploaded tracepoint %d has no "
11335 "source location, using raw address"),
11337 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11338 addr_str
= small_buf
;
11341 /* There's not much we can do with a sequence of bytecodes. */
11342 if (utp
->cond
&& !utp
->cond_string
)
11343 warning (_("Uploaded tracepoint %d condition "
11344 "has no source form, ignoring it"),
11347 if (!create_breakpoint (get_current_arch (),
11349 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11351 utp
->type
/* type_wanted */,
11352 0 /* Ignore count */,
11353 pending_break_support
,
11356 utp
->enabled
/* enabled */,
11360 set_tracepoint_count (breakpoint_count
);
11362 /* Get the tracepoint we just created. */
11363 tp
= get_tracepoint (tracepoint_count
);
11364 gdb_assert (tp
!= NULL
);
11368 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11370 trace_pass_command (small_buf
, 0);
11373 /* If we have uploaded versions of the original commands, set up a
11374 special-purpose "reader" function and call the usual command line
11375 reader, then pass the result to the breakpoint command-setting
11377 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11379 struct command_line
*cmd_list
;
11384 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11386 breakpoint_set_commands (tp
, cmd_list
);
11388 else if (!VEC_empty (char_ptr
, utp
->actions
)
11389 || !VEC_empty (char_ptr
, utp
->step_actions
))
11390 warning (_("Uploaded tracepoint %d actions "
11391 "have no source form, ignoring them"),
11397 /* Print information on tracepoint number TPNUM_EXP, or all if
11401 tracepoints_info (char *tpnum_exp
, int from_tty
)
11403 int tpnum
= -1, num_printed
;
11406 tpnum
= parse_and_eval_long (tpnum_exp
);
11408 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
11410 if (num_printed
== 0)
11413 ui_out_message (uiout
, 0, "No tracepoints.\n");
11415 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
11418 default_collect_info ();
11421 /* The 'enable trace' command enables tracepoints.
11422 Not supported by all targets. */
11424 enable_trace_command (char *args
, int from_tty
)
11426 enable_command (args
, from_tty
);
11429 /* The 'disable trace' command disables tracepoints.
11430 Not supported by all targets. */
11432 disable_trace_command (char *args
, int from_tty
)
11434 disable_command (args
, from_tty
);
11437 /* Remove a tracepoint (or all if no argument). */
11439 delete_trace_command (char *arg
, int from_tty
)
11441 struct breakpoint
*b
, *b_tmp
;
11447 int breaks_to_delete
= 0;
11449 /* Delete all breakpoints if no argument.
11450 Do not delete internal or call-dummy breakpoints, these
11451 have to be deleted with an explicit breakpoint number
11453 ALL_TRACEPOINTS (b
)
11455 if (b
->number
>= 0)
11457 breaks_to_delete
= 1;
11462 /* Ask user only if there are some breakpoints to delete. */
11464 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11466 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11468 if (is_tracepoint (b
)
11470 delete_breakpoint (b
);
11475 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11478 /* Set passcount for tracepoint.
11480 First command argument is passcount, second is tracepoint number.
11481 If tracepoint number omitted, apply to most recently defined.
11482 Also accepts special argument "all". */
11485 trace_pass_command (char *args
, int from_tty
)
11487 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11488 unsigned int count
;
11491 if (args
== 0 || *args
== 0)
11492 error (_("passcount command requires an "
11493 "argument (count + optional TP num)"));
11495 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11497 while (*args
&& isspace ((int) *args
))
11500 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11502 args
+= 3; /* Skip special argument "all". */
11505 error (_("Junk at end of arguments."));
11508 t1
= get_tracepoint_by_number (&args
, 1, 1);
11514 ALL_TRACEPOINTS (t2
)
11515 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11517 t2
->pass_count
= count
;
11518 observer_notify_tracepoint_modified (t2
->number
);
11520 printf_filtered (_("Setting tracepoint %d's "
11521 "passcount to %d\n"),
11522 t2
->number
, count
);
11524 if (! all
&& *args
)
11525 t1
= get_tracepoint_by_number (&args
, 1, 0);
11531 struct breakpoint
*
11532 get_tracepoint (int num
)
11534 struct breakpoint
*t
;
11536 ALL_TRACEPOINTS (t
)
11537 if (t
->number
== num
)
11543 /* Find the tracepoint with the given target-side number (which may be
11544 different from the tracepoint number after disconnecting and
11547 struct breakpoint
*
11548 get_tracepoint_by_number_on_target (int num
)
11550 struct breakpoint
*t
;
11552 ALL_TRACEPOINTS (t
)
11553 if (t
->number_on_target
== num
)
11559 /* Utility: parse a tracepoint number and look it up in the list.
11560 If MULTI_P is true, there might be a range of tracepoints in ARG.
11561 if OPTIONAL_P is true, then if the argument is missing, the most
11562 recent tracepoint (tracepoint_count) is returned. */
11563 struct breakpoint
*
11564 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11566 extern int tracepoint_count
;
11567 struct breakpoint
*t
;
11569 char *instring
= arg
== NULL
? NULL
: *arg
;
11571 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11574 tpnum
= tracepoint_count
;
11576 error_no_arg (_("tracepoint number"));
11579 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11583 if (instring
&& *instring
)
11584 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11587 printf_filtered (_("Tracepoint argument missing "
11588 "and no previous tracepoint\n"));
11592 ALL_TRACEPOINTS (t
)
11593 if (t
->number
== tpnum
)
11598 /* FIXME: if we are in the middle of a range we don't want to give
11599 a message. The current interface to get_number_or_range doesn't
11600 allow us to discover this. */
11601 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11605 /* Save information on user settable breakpoints (watchpoints, etc) to
11606 a new script file named FILENAME. If FILTER is non-NULL, call it
11607 on each breakpoint and only include the ones for which it returns
11611 save_breakpoints (char *filename
, int from_tty
,
11612 int (*filter
) (const struct breakpoint
*))
11614 struct breakpoint
*tp
;
11617 struct cleanup
*cleanup
;
11618 struct ui_file
*fp
;
11619 int extra_trace_bits
= 0;
11621 if (filename
== 0 || *filename
== 0)
11622 error (_("Argument required (file name in which to save)"));
11624 /* See if we have anything to save. */
11625 ALL_BREAKPOINTS (tp
)
11627 /* Skip internal and momentary breakpoints. */
11628 if (!user_settable_breakpoint (tp
) || tp
->number
< 0)
11631 /* If we have a filter, only save the breakpoints it accepts. */
11632 if (filter
&& !filter (tp
))
11637 if (is_tracepoint (tp
))
11639 extra_trace_bits
= 1;
11641 /* We can stop searching. */
11648 warning (_("Nothing to save."));
11652 pathname
= tilde_expand (filename
);
11653 cleanup
= make_cleanup (xfree
, pathname
);
11654 fp
= gdb_fopen (pathname
, "w");
11656 error (_("Unable to open file '%s' for saving (%s)"),
11657 filename
, safe_strerror (errno
));
11658 make_cleanup_ui_file_delete (fp
);
11660 if (extra_trace_bits
)
11661 save_trace_state_variables (fp
);
11663 ALL_BREAKPOINTS (tp
)
11665 /* Skip internal and momentary breakpoints. */
11666 if (!user_settable_breakpoint (tp
) || tp
->number
< 0)
11669 /* If we have a filter, only save the breakpoints it accepts. */
11670 if (filter
&& !filter (tp
))
11673 if (tp
->ops
!= NULL
)
11674 (tp
->ops
->print_recreate
) (tp
, fp
);
11677 if (tp
->type
== bp_fast_tracepoint
)
11678 fprintf_unfiltered (fp
, "ftrace");
11679 if (tp
->type
== bp_static_tracepoint
)
11680 fprintf_unfiltered (fp
, "strace");
11681 else if (tp
->type
== bp_tracepoint
)
11682 fprintf_unfiltered (fp
, "trace");
11683 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11684 fprintf_unfiltered (fp
, "tbreak");
11685 else if (tp
->type
== bp_breakpoint
)
11686 fprintf_unfiltered (fp
, "break");
11687 else if (tp
->type
== bp_hardware_breakpoint
11688 && tp
->disposition
== disp_del
)
11689 fprintf_unfiltered (fp
, "thbreak");
11690 else if (tp
->type
== bp_hardware_breakpoint
)
11691 fprintf_unfiltered (fp
, "hbreak");
11692 else if (tp
->type
== bp_watchpoint
)
11693 fprintf_unfiltered (fp
, "watch");
11694 else if (tp
->type
== bp_hardware_watchpoint
)
11695 fprintf_unfiltered (fp
, "watch");
11696 else if (tp
->type
== bp_read_watchpoint
)
11697 fprintf_unfiltered (fp
, "rwatch");
11698 else if (tp
->type
== bp_access_watchpoint
)
11699 fprintf_unfiltered (fp
, "awatch");
11701 internal_error (__FILE__
, __LINE__
,
11702 _("unhandled breakpoint type %d"), (int) tp
->type
);
11704 if (tp
->exp_string
)
11705 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11706 else if (tp
->addr_string
)
11707 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11712 sprintf_vma (tmp
, tp
->loc
->address
);
11713 fprintf_unfiltered (fp
, " *0x%s", tmp
);
11717 if (tp
->thread
!= -1)
11718 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
11721 fprintf_unfiltered (fp
, " task %d", tp
->task
);
11723 fprintf_unfiltered (fp
, "\n");
11725 /* Note, we can't rely on tp->number for anything, as we can't
11726 assume the recreated breakpoint numbers will match. Use $bpnum
11729 if (tp
->cond_string
)
11730 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
11732 if (tp
->ignore_count
)
11733 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
11735 if (tp
->pass_count
)
11736 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11740 volatile struct gdb_exception ex
;
11742 fprintf_unfiltered (fp
, " commands\n");
11744 ui_out_redirect (uiout
, fp
);
11745 TRY_CATCH (ex
, RETURN_MASK_ALL
)
11747 print_command_lines (uiout
, tp
->commands
->commands
, 2);
11749 ui_out_redirect (uiout
, NULL
);
11752 throw_exception (ex
);
11754 fprintf_unfiltered (fp
, " end\n");
11757 if (tp
->enable_state
== bp_disabled
)
11758 fprintf_unfiltered (fp
, "disable\n");
11760 /* If this is a multi-location breakpoint, check if the locations
11761 should be individually disabled. Watchpoint locations are
11762 special, and not user visible. */
11763 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
11765 struct bp_location
*loc
;
11768 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
11770 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
11774 if (extra_trace_bits
&& *default_collect
)
11775 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
11777 do_cleanups (cleanup
);
11779 printf_filtered (_("Saved to file '%s'.\n"), filename
);
11782 /* The `save breakpoints' command. */
11785 save_breakpoints_command (char *args
, int from_tty
)
11787 save_breakpoints (args
, from_tty
, NULL
);
11790 /* The `save tracepoints' command. */
11793 save_tracepoints_command (char *args
, int from_tty
)
11795 save_breakpoints (args
, from_tty
, is_tracepoint
);
11798 /* Create a vector of all tracepoints. */
11800 VEC(breakpoint_p
) *
11803 VEC(breakpoint_p
) *tp_vec
= 0;
11804 struct breakpoint
*tp
;
11806 ALL_TRACEPOINTS (tp
)
11808 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
11815 /* This help string is used for the break, hbreak, tbreak and thbreak
11816 commands. It is defined as a macro to prevent duplication.
11817 COMMAND should be a string constant containing the name of the
11819 #define BREAK_ARGS_HELP(command) \
11820 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11821 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11822 If a line number is specified, break at start of code for that line.\n\
11823 If a function is specified, break at start of code for that function.\n\
11824 If an address is specified, break at that exact address.\n\
11825 With no LOCATION, uses current execution address of the selected\n\
11826 stack frame. This is useful for breaking on return to a stack frame.\n\
11828 THREADNUM is the number from \"info threads\".\n\
11829 CONDITION is a boolean expression.\n\
11831 Multiple breakpoints at one place are permitted, and useful if their\n\
11832 conditions are different.\n\
11834 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11836 /* List of subcommands for "catch". */
11837 static struct cmd_list_element
*catch_cmdlist
;
11839 /* List of subcommands for "tcatch". */
11840 static struct cmd_list_element
*tcatch_cmdlist
;
11842 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11843 lists, and pass some additional user data to the command function. */
11845 add_catch_command (char *name
, char *docstring
,
11846 void (*sfunc
) (char *args
, int from_tty
,
11847 struct cmd_list_element
*command
),
11848 char **(*completer
) (struct cmd_list_element
*cmd
,
11849 char *text
, char *word
),
11850 void *user_data_catch
,
11851 void *user_data_tcatch
)
11853 struct cmd_list_element
*command
;
11855 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11857 set_cmd_sfunc (command
, sfunc
);
11858 set_cmd_context (command
, user_data_catch
);
11859 set_cmd_completer (command
, completer
);
11861 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11863 set_cmd_sfunc (command
, sfunc
);
11864 set_cmd_context (command
, user_data_tcatch
);
11865 set_cmd_completer (command
, completer
);
11869 clear_syscall_counts (struct inferior
*inf
)
11871 inf
->total_syscalls_count
= 0;
11872 inf
->any_syscall_count
= 0;
11873 VEC_free (int, inf
->syscalls_counts
);
11877 save_command (char *arg
, int from_tty
)
11879 printf_unfiltered (_("\"save\" must be followed by "
11880 "the name of a save subcommand.\n"));
11881 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
11884 struct breakpoint
*
11885 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
11888 struct breakpoint
*b
, *b_tmp
;
11890 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11892 if ((*callback
) (b
, data
))
11900 _initialize_breakpoint (void)
11902 struct cmd_list_element
*c
;
11904 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
11905 observer_attach_inferior_exit (clear_syscall_counts
);
11906 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
11908 breakpoint_chain
= 0;
11909 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11910 before a breakpoint is set. */
11911 breakpoint_count
= 0;
11913 tracepoint_count
= 0;
11915 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
11916 Set ignore-count of breakpoint number N to COUNT.\n\
11917 Usage is `ignore N COUNT'."));
11919 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
11921 add_com ("commands", class_breakpoint
, commands_command
, _("\
11922 Set commands to be executed when a breakpoint is hit.\n\
11923 Give breakpoint number as argument after \"commands\".\n\
11924 With no argument, the targeted breakpoint is the last one set.\n\
11925 The commands themselves follow starting on the next line.\n\
11926 Type a line containing \"end\" to indicate the end of them.\n\
11927 Give \"silent\" as the first line to make the breakpoint silent;\n\
11928 then no output is printed when it is hit, except what the commands print."));
11930 add_com ("condition", class_breakpoint
, condition_command
, _("\
11931 Specify breakpoint number N to break only if COND is true.\n\
11932 Usage is `condition N COND', where N is an integer and COND is an\n\
11933 expression to be evaluated whenever breakpoint N is reached."));
11935 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
11936 Set a temporary breakpoint.\n\
11937 Like \"break\" except the breakpoint is only temporary,\n\
11938 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11939 by using \"enable delete\" on the breakpoint number.\n\
11941 BREAK_ARGS_HELP ("tbreak")));
11942 set_cmd_completer (c
, location_completer
);
11944 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
11945 Set a hardware assisted breakpoint.\n\
11946 Like \"break\" except the breakpoint requires hardware support,\n\
11947 some target hardware may not have this support.\n\
11949 BREAK_ARGS_HELP ("hbreak")));
11950 set_cmd_completer (c
, location_completer
);
11952 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
11953 Set a temporary hardware assisted breakpoint.\n\
11954 Like \"hbreak\" except the breakpoint is only temporary,\n\
11955 so it will be deleted when hit.\n\
11957 BREAK_ARGS_HELP ("thbreak")));
11958 set_cmd_completer (c
, location_completer
);
11960 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
11961 Enable some breakpoints.\n\
11962 Give breakpoint numbers (separated by spaces) as arguments.\n\
11963 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11964 This is used to cancel the effect of the \"disable\" command.\n\
11965 With a subcommand you can enable temporarily."),
11966 &enablelist
, "enable ", 1, &cmdlist
);
11968 add_com ("ab", class_breakpoint
, enable_command
, _("\
11969 Enable some breakpoints.\n\
11970 Give breakpoint numbers (separated by spaces) as arguments.\n\
11971 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11972 This is used to cancel the effect of the \"disable\" command.\n\
11973 With a subcommand you can enable temporarily."));
11975 add_com_alias ("en", "enable", class_breakpoint
, 1);
11977 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
11978 Enable some breakpoints.\n\
11979 Give breakpoint numbers (separated by spaces) as arguments.\n\
11980 This is used to cancel the effect of the \"disable\" command.\n\
11981 May be abbreviated to simply \"enable\".\n"),
11982 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
11984 add_cmd ("once", no_class
, enable_once_command
, _("\
11985 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11986 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11989 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11990 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11991 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11994 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11995 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11996 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11999 add_cmd ("once", no_class
, enable_once_command
, _("\
12000 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12001 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12004 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
12005 Disable some breakpoints.\n\
12006 Arguments are breakpoint numbers with spaces in between.\n\
12007 To disable all breakpoints, give no argument.\n\
12008 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12009 &disablelist
, "disable ", 1, &cmdlist
);
12010 add_com_alias ("dis", "disable", class_breakpoint
, 1);
12011 add_com_alias ("disa", "disable", class_breakpoint
, 1);
12013 add_com ("sb", class_breakpoint
, disable_command
, _("\
12014 Disable some breakpoints.\n\
12015 Arguments are breakpoint numbers with spaces in between.\n\
12016 To disable all breakpoints, give no argument.\n\
12017 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12019 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
12020 Disable some breakpoints.\n\
12021 Arguments are breakpoint numbers with spaces in between.\n\
12022 To disable all breakpoints, give no argument.\n\
12023 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12024 This command may be abbreviated \"disable\"."),
12027 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
12028 Delete some breakpoints or auto-display expressions.\n\
12029 Arguments are breakpoint numbers with spaces in between.\n\
12030 To delete all breakpoints, give no argument.\n\
12032 Also a prefix command for deletion of other GDB objects.\n\
12033 The \"unset\" command is also an alias for \"delete\"."),
12034 &deletelist
, "delete ", 1, &cmdlist
);
12035 add_com_alias ("d", "delete", class_breakpoint
, 1);
12036 add_com_alias ("del", "delete", class_breakpoint
, 1);
12038 add_com ("db", class_breakpoint
, delete_command
, _("\
12039 Delete some breakpoints.\n\
12040 Arguments are breakpoint numbers with spaces in between.\n\
12041 To delete all breakpoints, give no argument.\n"));
12043 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
12044 Delete some breakpoints or auto-display expressions.\n\
12045 Arguments are breakpoint numbers with spaces in between.\n\
12046 To delete all breakpoints, give no argument.\n\
12047 This command may be abbreviated \"delete\"."),
12050 add_com ("clear", class_breakpoint
, clear_command
, _("\
12051 Clear breakpoint at specified line or function.\n\
12052 Argument may be line number, function name, or \"*\" and an address.\n\
12053 If line number is specified, all breakpoints in that line are cleared.\n\
12054 If function is specified, breakpoints at beginning of function are cleared.\n\
12055 If an address is specified, breakpoints at that address are cleared.\n\
12057 With no argument, clears all breakpoints in the line that the selected frame\n\
12058 is executing in.\n\
12060 See also the \"delete\" command which clears breakpoints by number."));
12061 add_com_alias ("cl", "clear", class_breakpoint
, 1);
12063 c
= add_com ("break", class_breakpoint
, break_command
, _("\
12064 Set breakpoint at specified line or function.\n"
12065 BREAK_ARGS_HELP ("break")));
12066 set_cmd_completer (c
, location_completer
);
12068 add_com_alias ("b", "break", class_run
, 1);
12069 add_com_alias ("br", "break", class_run
, 1);
12070 add_com_alias ("bre", "break", class_run
, 1);
12071 add_com_alias ("brea", "break", class_run
, 1);
12074 add_com_alias ("ba", "break", class_breakpoint
, 1);
12078 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
12079 Break in function/address or break at a line in the current file."),
12080 &stoplist
, "stop ", 1, &cmdlist
);
12081 add_cmd ("in", class_breakpoint
, stopin_command
,
12082 _("Break in function or address."), &stoplist
);
12083 add_cmd ("at", class_breakpoint
, stopat_command
,
12084 _("Break at a line in the current file."), &stoplist
);
12085 add_com ("status", class_info
, breakpoints_info
, _("\
12086 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12087 The \"Type\" column indicates one of:\n\
12088 \tbreakpoint - normal breakpoint\n\
12089 \twatchpoint - watchpoint\n\
12090 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12091 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12092 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12093 address and file/line number respectively.\n\
12095 Convenience variable \"$_\" and default examine address for \"x\"\n\
12096 are set to the address of the last breakpoint listed unless the command\n\
12097 is prefixed with \"server \".\n\n\
12098 Convenience variable \"$bpnum\" contains the number of the last\n\
12099 breakpoint set."));
12102 add_info ("breakpoints", breakpoints_info
, _("\
12103 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12104 The \"Type\" column indicates one of:\n\
12105 \tbreakpoint - normal breakpoint\n\
12106 \twatchpoint - watchpoint\n\
12107 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12108 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12109 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12110 address and file/line number respectively.\n\
12112 Convenience variable \"$_\" and default examine address for \"x\"\n\
12113 are set to the address of the last breakpoint listed unless the command\n\
12114 is prefixed with \"server \".\n\n\
12115 Convenience variable \"$bpnum\" contains the number of the last\n\
12116 breakpoint set."));
12118 add_info_alias ("b", "breakpoints", 1);
12121 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
12122 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12123 The \"Type\" column indicates one of:\n\
12124 \tbreakpoint - normal breakpoint\n\
12125 \twatchpoint - watchpoint\n\
12126 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12127 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12128 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12129 address and file/line number respectively.\n\
12131 Convenience variable \"$_\" and default examine address for \"x\"\n\
12132 are set to the address of the last breakpoint listed unless the command\n\
12133 is prefixed with \"server \".\n\n\
12134 Convenience variable \"$bpnum\" contains the number of the last\n\
12135 breakpoint set."));
12137 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
12138 Status of all breakpoints, or breakpoint number NUMBER.\n\
12139 The \"Type\" column indicates one of:\n\
12140 \tbreakpoint - normal breakpoint\n\
12141 \twatchpoint - watchpoint\n\
12142 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12143 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12144 \tuntil - internal breakpoint used by the \"until\" command\n\
12145 \tfinish - internal breakpoint used by the \"finish\" command\n\
12146 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12147 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12148 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12149 address and file/line number respectively.\n\
12151 Convenience variable \"$_\" and default examine address for \"x\"\n\
12152 are set to the address of the last breakpoint listed unless the command\n\
12153 is prefixed with \"server \".\n\n\
12154 Convenience variable \"$bpnum\" contains the number of the last\n\
12156 &maintenanceinfolist
);
12158 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
12159 Set catchpoints to catch events."),
12160 &catch_cmdlist
, "catch ",
12161 0/*allow-unknown*/, &cmdlist
);
12163 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
12164 Set temporary catchpoints to catch events."),
12165 &tcatch_cmdlist
, "tcatch ",
12166 0/*allow-unknown*/, &cmdlist
);
12168 /* Add catch and tcatch sub-commands. */
12169 add_catch_command ("catch", _("\
12170 Catch an exception, when caught.\n\
12171 With an argument, catch only exceptions with the given name."),
12172 catch_catch_command
,
12176 add_catch_command ("throw", _("\
12177 Catch an exception, when thrown.\n\
12178 With an argument, catch only exceptions with the given name."),
12179 catch_throw_command
,
12183 add_catch_command ("fork", _("Catch calls to fork."),
12184 catch_fork_command_1
,
12186 (void *) (uintptr_t) catch_fork_permanent
,
12187 (void *) (uintptr_t) catch_fork_temporary
);
12188 add_catch_command ("vfork", _("Catch calls to vfork."),
12189 catch_fork_command_1
,
12191 (void *) (uintptr_t) catch_vfork_permanent
,
12192 (void *) (uintptr_t) catch_vfork_temporary
);
12193 add_catch_command ("exec", _("Catch calls to exec."),
12194 catch_exec_command_1
,
12198 add_catch_command ("syscall", _("\
12199 Catch system calls by their names and/or numbers.\n\
12200 Arguments say which system calls to catch. If no arguments\n\
12201 are given, every system call will be caught.\n\
12202 Arguments, if given, should be one or more system call names\n\
12203 (if your system supports that), or system call numbers."),
12204 catch_syscall_command_1
,
12205 catch_syscall_completer
,
12208 add_catch_command ("exception", _("\
12209 Catch Ada exceptions, when raised.\n\
12210 With an argument, catch only exceptions with the given name."),
12211 catch_ada_exception_command
,
12215 add_catch_command ("assert", _("\
12216 Catch failed Ada assertions, when raised.\n\
12217 With an argument, catch only exceptions with the given name."),
12218 catch_assert_command
,
12223 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
12224 Set a watchpoint for an expression.\n\
12225 Usage: watch [-l|-location] EXPRESSION\n\
12226 A watchpoint stops execution of your program whenever the value of\n\
12227 an expression changes.\n\
12228 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12229 the memory to which it refers."));
12230 set_cmd_completer (c
, expression_completer
);
12232 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
12233 Set a read watchpoint for an expression.\n\
12234 Usage: rwatch [-l|-location] EXPRESSION\n\
12235 A watchpoint stops execution of your program whenever the value of\n\
12236 an expression is read.\n\
12237 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12238 the memory to which it refers."));
12239 set_cmd_completer (c
, expression_completer
);
12241 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
12242 Set a watchpoint for an expression.\n\
12243 Usage: awatch [-l|-location] EXPRESSION\n\
12244 A watchpoint stops execution of your program whenever the value of\n\
12245 an expression is either read or written.\n\
12246 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12247 the memory to which it refers."));
12248 set_cmd_completer (c
, expression_completer
);
12250 add_info ("watchpoints", watchpoints_info
, _("\
12251 Status of watchpoints, or watchpoint number NUMBER."));
12255 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12256 respond to changes - contrary to the description. */
12257 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
12258 &can_use_hw_watchpoints
, _("\
12259 Set debugger's willingness to use watchpoint hardware."), _("\
12260 Show debugger's willingness to use watchpoint hardware."), _("\
12261 If zero, gdb will not use hardware for new watchpoints, even if\n\
12262 such is available. (However, any hardware watchpoints that were\n\
12263 created before setting this to nonzero, will continue to use watchpoint\n\
12266 show_can_use_hw_watchpoints
,
12267 &setlist
, &showlist
);
12269 can_use_hw_watchpoints
= 1;
12271 /* Tracepoint manipulation commands. */
12273 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12274 Set a tracepoint at specified line or function.\n\
12276 BREAK_ARGS_HELP ("trace") "\n\
12277 Do \"help tracepoints\" for info on other tracepoint commands."));
12278 set_cmd_completer (c
, location_completer
);
12280 add_com_alias ("tp", "trace", class_alias
, 0);
12281 add_com_alias ("tr", "trace", class_alias
, 1);
12282 add_com_alias ("tra", "trace", class_alias
, 1);
12283 add_com_alias ("trac", "trace", class_alias
, 1);
12285 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12286 Set a fast tracepoint at specified line or function.\n\
12288 BREAK_ARGS_HELP ("ftrace") "\n\
12289 Do \"help tracepoints\" for info on other tracepoint commands."));
12290 set_cmd_completer (c
, location_completer
);
12292 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12293 Set a static tracepoint at specified line, function or marker.\n\
12295 strace [LOCATION] [if CONDITION]\n\
12296 LOCATION may be a line number, function name, \"*\" and an address,\n\
12297 or -m MARKER_ID.\n\
12298 If a line number is specified, probe the marker at start of code\n\
12299 for that line. If a function is specified, probe the marker at start\n\
12300 of code for that function. If an address is specified, probe the marker\n\
12301 at that exact address. If a marker id is specified, probe the marker\n\
12302 with that name. With no LOCATION, uses current execution address of\n\
12303 the selected stack frame.\n\
12304 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12305 This collects arbitrary user data passed in the probe point call to the\n\
12306 tracing library. You can inspect it when analyzing the trace buffer,\n\
12307 by printing the $_sdata variable like any other convenience variable.\n\
12309 CONDITION is a boolean expression.\n\
12311 Multiple tracepoints at one place are permitted, and useful if their\n\
12312 conditions are different.\n\
12314 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12315 Do \"help tracepoints\" for info on other tracepoint commands."));
12316 set_cmd_completer (c
, location_completer
);
12318 add_info ("tracepoints", tracepoints_info
, _("\
12319 Status of tracepoints, or tracepoint number NUMBER.\n\
12320 Convenience variable \"$tpnum\" contains the number of the\n\
12321 last tracepoint set."));
12323 add_info_alias ("tp", "tracepoints", 1);
12325 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12326 Delete specified tracepoints.\n\
12327 Arguments are tracepoint numbers, separated by spaces.\n\
12328 No argument means delete all tracepoints."),
12331 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12332 Disable specified tracepoints.\n\
12333 Arguments are tracepoint numbers, separated by spaces.\n\
12334 No argument means disable all tracepoints."),
12336 deprecate_cmd (c
, "disable");
12338 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12339 Enable specified tracepoints.\n\
12340 Arguments are tracepoint numbers, separated by spaces.\n\
12341 No argument means enable all tracepoints."),
12343 deprecate_cmd (c
, "enable");
12345 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12346 Set the passcount for a tracepoint.\n\
12347 The trace will end when the tracepoint has been passed 'count' times.\n\
12348 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12349 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12351 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12352 _("Save breakpoint definitions as a script."),
12353 &save_cmdlist
, "save ",
12354 0/*allow-unknown*/, &cmdlist
);
12356 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12357 Save current breakpoint definitions as a script.\n\
12358 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12359 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12360 session to restore them."),
12362 set_cmd_completer (c
, filename_completer
);
12364 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12365 Save current tracepoint definitions as a script.\n\
12366 Use the 'source' command in another debug session to restore them."),
12368 set_cmd_completer (c
, filename_completer
);
12370 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12371 deprecate_cmd (c
, "save tracepoints");
12373 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12374 Breakpoint specific settings\n\
12375 Configure various breakpoint-specific variables such as\n\
12376 pending breakpoint behavior"),
12377 &breakpoint_set_cmdlist
, "set breakpoint ",
12378 0/*allow-unknown*/, &setlist
);
12379 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12380 Breakpoint specific settings\n\
12381 Configure various breakpoint-specific variables such as\n\
12382 pending breakpoint behavior"),
12383 &breakpoint_show_cmdlist
, "show breakpoint ",
12384 0/*allow-unknown*/, &showlist
);
12386 add_setshow_auto_boolean_cmd ("pending", no_class
,
12387 &pending_break_support
, _("\
12388 Set debugger's behavior regarding pending breakpoints."), _("\
12389 Show debugger's behavior regarding pending breakpoints."), _("\
12390 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12391 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12392 an error. If auto, an unrecognized breakpoint location results in a\n\
12393 user-query to see if a pending breakpoint should be created."),
12395 show_pending_break_support
,
12396 &breakpoint_set_cmdlist
,
12397 &breakpoint_show_cmdlist
);
12399 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12401 add_setshow_boolean_cmd ("auto-hw", no_class
,
12402 &automatic_hardware_breakpoints
, _("\
12403 Set automatic usage of hardware breakpoints."), _("\
12404 Show automatic usage of hardware breakpoints."), _("\
12405 If set, the debugger will automatically use hardware breakpoints for\n\
12406 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12407 a warning will be emitted for such breakpoints."),
12409 show_automatic_hardware_breakpoints
,
12410 &breakpoint_set_cmdlist
,
12411 &breakpoint_show_cmdlist
);
12413 add_setshow_enum_cmd ("always-inserted", class_support
,
12414 always_inserted_enums
, &always_inserted_mode
, _("\
12415 Set mode for inserting breakpoints."), _("\
12416 Show mode for inserting breakpoints."), _("\
12417 When this mode is off, breakpoints are inserted in inferior when it is\n\
12418 resumed, and removed when execution stops. When this mode is on,\n\
12419 breakpoints are inserted immediately and removed only when the user\n\
12420 deletes the breakpoint. When this mode is auto (which is the default),\n\
12421 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12422 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12423 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12424 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12426 &show_always_inserted_mode
,
12427 &breakpoint_set_cmdlist
,
12428 &breakpoint_show_cmdlist
);
12430 automatic_hardware_breakpoints
= 1;
12432 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);