1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
64 #include "parser-defs.h"
66 /* readline include files */
67 #include "readline/readline.h"
68 #include "readline/history.h"
70 /* readline defines this. */
73 #include "mi/mi-common.h"
75 /* Arguments to pass as context to some catch command handlers. */
76 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
77 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void clear_command (char *, int);
99 static void catch_command (char *, int);
101 static int can_use_hardware_watchpoint (struct value
*);
103 static void break_command_1 (char *, int, int);
105 static void mention (struct breakpoint
*);
107 /* This function is used in gdbtk sources and thus can not be made static. */
108 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
109 struct symtab_and_line
,
112 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
114 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
118 static void describe_other_breakpoints (struct gdbarch
*,
119 struct program_space
*, CORE_ADDR
,
120 struct obj_section
*, int);
122 static int breakpoint_address_match (struct address_space
*aspace1
,
124 struct address_space
*aspace2
,
127 static int watchpoint_locations_match (struct bp_location
*loc1
,
128 struct bp_location
*loc2
);
130 static void breakpoints_info (char *, int);
132 static void watchpoints_info (char *, int);
134 static int breakpoint_1 (int, int, int (*) (const struct breakpoint
*));
136 static bpstat
bpstat_alloc (struct bp_location
*, bpstat
);
138 static int breakpoint_cond_eval (void *);
140 static void cleanup_executing_breakpoints (void *);
142 static void commands_command (char *, int);
144 static void condition_command (char *, int);
146 static int get_number_trailer (char **, int);
155 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
156 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
158 static enum print_stop_action
print_it_typical (bpstat
);
160 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
162 static int watchpoint_check (void *);
164 static void maintenance_info_breakpoints (char *, int);
166 static int hw_breakpoint_used_count (void);
168 static int hw_watchpoint_used_count (enum bptype
, int *);
170 static void hbreak_command (char *, int);
172 static void thbreak_command (char *, int);
174 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
176 static void stop_command (char *arg
, int from_tty
);
178 static void stopin_command (char *arg
, int from_tty
);
180 static void stopat_command (char *arg
, int from_tty
);
182 static char *ep_parse_optional_if_clause (char **arg
);
184 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
185 char *arg
, int tempflag
, int from_tty
);
187 static void tcatch_command (char *arg
, int from_tty
);
189 static void ep_skip_leading_whitespace (char **s
);
191 static void detach_single_step_breakpoints (void);
193 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
196 static void free_bp_location (struct bp_location
*loc
);
197 static void incref_bp_location (struct bp_location
*loc
);
198 static void decref_bp_location (struct bp_location
**loc
);
200 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
202 static void update_global_location_list (int);
204 static void update_global_location_list_nothrow (int);
206 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
208 static int is_watchpoint (const struct breakpoint
*bpt
);
210 static void insert_breakpoint_locations (void);
212 static int syscall_catchpoint_p (struct breakpoint
*b
);
214 static void tracepoints_info (char *, int);
216 static void delete_trace_command (char *, int);
218 static void enable_trace_command (char *, int);
220 static void disable_trace_command (char *, int);
222 static void trace_pass_command (char *, int);
224 /* Assuming we're creating a static tracepoint, does S look like a
225 static tracepoint marker spec ("-m MARKER_ID")? */
226 #define is_marker_spec(s) \
227 (strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
229 /* A reference-counted struct command_line. This lets multiple
230 breakpoints share a single command list. */
231 struct counted_command_line
233 /* The reference count. */
236 /* The command list. */
237 struct command_line
*commands
;
240 struct command_line
*
241 breakpoint_commands (struct breakpoint
*b
)
243 return b
->commands
? b
->commands
->commands
: NULL
;
246 /* Flag indicating that a command has proceeded the inferior past the
247 current breakpoint. */
249 static int breakpoint_proceeded
;
252 bpdisp_text (enum bpdisp disp
)
254 /* NOTE: the following values are a part of MI protocol and represent
255 values of 'disp' field returned when inferior stops at a breakpoint. */
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 watchpoint hardware is %s.\n"),
276 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
277 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
278 for unrecognized breakpoint locations.
279 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
280 static enum auto_boolean pending_break_support
;
282 show_pending_break_support (struct ui_file
*file
, int from_tty
,
283 struct cmd_list_element
*c
,
286 fprintf_filtered (file
, _("\
287 Debugger's behavior regarding pending breakpoints is %s.\n"),
291 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
292 set with "break" but falling in read-only memory.
293 If 0, gdb will warn about such breakpoints, but won't automatically
294 use hardware breakpoints. */
295 static int automatic_hardware_breakpoints
;
297 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
298 struct cmd_list_element
*c
,
301 fprintf_filtered (file
, _("\
302 Automatic usage of hardware breakpoints is %s.\n"),
306 /* If on, gdb will keep breakpoints inserted even as inferior is
307 stopped, and immediately insert any new breakpoints. If off, gdb
308 will insert breakpoints into inferior only when resuming it, and
309 will remove breakpoints upon stop. If auto, GDB will behave as ON
310 if in non-stop mode, and as OFF if all-stop mode.*/
312 static const char always_inserted_auto
[] = "auto";
313 static const char always_inserted_on
[] = "on";
314 static const char always_inserted_off
[] = "off";
315 static const char *always_inserted_enums
[] = {
316 always_inserted_auto
,
321 static const char *always_inserted_mode
= always_inserted_auto
;
323 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
324 struct cmd_list_element
*c
, const char *value
)
326 if (always_inserted_mode
== always_inserted_auto
)
327 fprintf_filtered (file
, _("\
328 Always inserted breakpoint mode is %s (currently %s).\n"),
330 breakpoints_always_inserted_mode () ? "on" : "off");
332 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
336 breakpoints_always_inserted_mode (void)
338 return (always_inserted_mode
== always_inserted_on
339 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
342 void _initialize_breakpoint (void);
344 /* Are we executing breakpoint commands? */
345 static int executing_breakpoint_commands
;
347 /* Are overlay event breakpoints enabled? */
348 static int overlay_events_enabled
;
350 /* Walk the following statement or block through all breakpoints.
351 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
354 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
356 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
357 for (B = breakpoint_chain; \
358 B ? (TMP=B->next, 1): 0; \
361 /* Similar iterator for the low-level breakpoints. SAFE variant is not
362 provided so update_global_location_list must not be called while executing
363 the block of ALL_BP_LOCATIONS. */
365 #define ALL_BP_LOCATIONS(B,BP_TMP) \
366 for (BP_TMP = bp_location; \
367 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
370 /* Iterator for tracepoints only. */
372 #define ALL_TRACEPOINTS(B) \
373 for (B = breakpoint_chain; B; B = B->next) \
374 if (is_tracepoint (B))
376 /* Chains of all breakpoints defined. */
378 struct breakpoint
*breakpoint_chain
;
380 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
382 static struct bp_location
**bp_location
;
384 /* Number of elements of BP_LOCATION. */
386 static unsigned bp_location_count
;
388 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
389 for the current elements of BP_LOCATION which get a valid result from
390 bp_location_has_shadow. You can use it for roughly limiting the subrange of
391 BP_LOCATION to scan for shadow bytes for an address you need to read. */
393 static CORE_ADDR bp_location_placed_address_before_address_max
;
395 /* Maximum offset plus alignment between
396 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
397 the current elements of BP_LOCATION which get a valid result from
398 bp_location_has_shadow. You can use it for roughly limiting the subrange of
399 BP_LOCATION to scan for shadow bytes for an address you need to read. */
401 static CORE_ADDR bp_location_shadow_len_after_address_max
;
403 /* The locations that no longer correspond to any breakpoint,
404 unlinked from bp_location array, but for which a hit
405 may still be reported by a target. */
406 VEC(bp_location_p
) *moribund_locations
= NULL
;
408 /* Number of last breakpoint made. */
410 static int breakpoint_count
;
412 /* The value of `breakpoint_count' before the last command that
413 created breakpoints. If the last (break-like) command created more
414 than one breakpoint, then the difference between BREAKPOINT_COUNT
415 and PREV_BREAKPOINT_COUNT is more than one. */
416 static int prev_breakpoint_count
;
418 /* Number of last tracepoint made. */
420 static int tracepoint_count
;
422 static struct cmd_list_element
*breakpoint_set_cmdlist
;
423 static struct cmd_list_element
*breakpoint_show_cmdlist
;
424 struct cmd_list_element
*save_cmdlist
;
426 /* Return whether a breakpoint is an active enabled breakpoint. */
428 breakpoint_enabled (struct breakpoint
*b
)
430 return (b
->enable_state
== bp_enabled
);
433 /* Set breakpoint count to NUM. */
436 set_breakpoint_count (int num
)
438 prev_breakpoint_count
= breakpoint_count
;
439 breakpoint_count
= num
;
440 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
443 /* Used by `start_rbreak_breakpoints' below, to record the current
444 breakpoint count before "rbreak" creates any breakpoint. */
445 static int rbreak_start_breakpoint_count
;
447 /* Called at the start an "rbreak" command to record the first
451 start_rbreak_breakpoints (void)
453 rbreak_start_breakpoint_count
= breakpoint_count
;
456 /* Called at the end of an "rbreak" command to record the last
460 end_rbreak_breakpoints (void)
462 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
465 /* Used in run_command to zero the hit count when a new run starts. */
468 clear_breakpoint_hit_counts (void)
470 struct breakpoint
*b
;
476 /* Allocate a new counted_command_line with reference count of 1.
477 The new structure owns COMMANDS. */
479 static struct counted_command_line
*
480 alloc_counted_command_line (struct command_line
*commands
)
482 struct counted_command_line
*result
483 = xmalloc (sizeof (struct counted_command_line
));
486 result
->commands
= commands
;
490 /* Increment reference count. This does nothing if CMD is NULL. */
493 incref_counted_command_line (struct counted_command_line
*cmd
)
499 /* Decrement reference count. If the reference count reaches 0,
500 destroy the counted_command_line. Sets *CMDP to NULL. This does
501 nothing if *CMDP is NULL. */
504 decref_counted_command_line (struct counted_command_line
**cmdp
)
508 if (--(*cmdp
)->refc
== 0)
510 free_command_lines (&(*cmdp
)->commands
);
517 /* A cleanup function that calls decref_counted_command_line. */
520 do_cleanup_counted_command_line (void *arg
)
522 decref_counted_command_line (arg
);
525 /* Create a cleanup that calls decref_counted_command_line on the
528 static struct cleanup
*
529 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
531 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
534 /* Default address, symtab and line to put a breakpoint at
535 for "break" command with no arg.
536 if default_breakpoint_valid is zero, the other three are
537 not valid, and "break" with no arg is an error.
539 This set by print_stack_frame, which calls set_default_breakpoint. */
541 int default_breakpoint_valid
;
542 CORE_ADDR default_breakpoint_address
;
543 struct symtab
*default_breakpoint_symtab
;
544 int default_breakpoint_line
;
545 struct program_space
*default_breakpoint_pspace
;
548 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
549 Advance *PP after the string and any trailing whitespace.
551 Currently the string can either be a number or "$" followed by the name
552 of a convenience variable. Making it an expression wouldn't work well
553 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
555 If the string is a NULL pointer, that denotes the last breakpoint.
557 TRAILER is a character which can be found after the number; most
558 commonly this is `-'. If you don't want a trailer, use \0. */
560 get_number_trailer (char **pp
, int trailer
)
562 int retval
= 0; /* default */
566 /* Empty line means refer to the last breakpoint. */
567 return breakpoint_count
;
570 /* Make a copy of the name, so we can null-terminate it
571 to pass to lookup_internalvar(). */
576 while (isalnum (*p
) || *p
== '_')
578 varname
= (char *) alloca (p
- start
+ 1);
579 strncpy (varname
, start
, p
- start
);
580 varname
[p
- start
] = '\0';
581 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
585 printf_filtered (_("Convenience variable must have integer value.\n"));
593 while (*p
>= '0' && *p
<= '9')
596 /* There is no number here. (e.g. "cond a == b"). */
598 /* Skip non-numeric token */
599 while (*p
&& !isspace((int) *p
))
601 /* Return zero, which caller must interpret as error. */
607 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
609 /* Trailing junk: return 0 and let caller print error msg. */
610 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
621 /* Like get_number_trailer, but don't allow a trailer. */
623 get_number (char **pp
)
625 return get_number_trailer (pp
, '\0');
628 /* Parse a number or a range.
629 * A number will be of the form handled by get_number.
630 * A range will be of the form <number1> - <number2>, and
631 * will represent all the integers between number1 and number2,
634 * While processing a range, this fuction is called iteratively;
635 * At each call it will return the next value in the range.
637 * At the beginning of parsing a range, the char pointer PP will
638 * be advanced past <number1> and left pointing at the '-' token.
639 * Subsequent calls will not advance the pointer until the range
640 * is completed. The call that completes the range will advance
641 * pointer PP past <number2>.
645 get_number_or_range (char **pp
)
647 static int last_retval
, end_value
;
648 static char *end_ptr
;
649 static int in_range
= 0;
653 /* Default case: pp is pointing either to a solo number,
654 or to the first number of a range. */
655 last_retval
= get_number_trailer (pp
, '-');
660 /* This is the start of a range (<number1> - <number2>).
661 Skip the '-', parse and remember the second number,
662 and also remember the end of the final token. */
666 while (isspace ((int) *end_ptr
))
667 end_ptr
++; /* skip white space */
668 end_value
= get_number (temp
);
669 if (end_value
< last_retval
)
671 error (_("inverted range"));
673 else if (end_value
== last_retval
)
675 /* degenerate range (number1 == number2). Advance the
676 token pointer so that the range will be treated as a
685 error (_("negative value"));
688 /* pp points to the '-' that betokens a range. All
689 number-parsing has already been done. Return the next
690 integer value (one greater than the saved previous value).
691 Do not advance the token pointer 'pp' until the end of range
694 if (++last_retval
== end_value
)
696 /* End of range reached; advance token pointer. */
704 /* Return the breakpoint with the specified number, or NULL
705 if the number does not refer to an existing breakpoint. */
708 get_breakpoint (int num
)
710 struct breakpoint
*b
;
713 if (b
->number
== num
)
722 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
725 struct bp_location
*loc
= b
->loc
;
727 for (; loc
; loc
= loc
->next
)
732 xfree (b
->cond_string
);
733 b
->cond_string
= NULL
;
740 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
746 /* I don't know if it matters whether this is the string the user
747 typed in or the decompiled expression. */
748 b
->cond_string
= xstrdup (arg
);
749 b
->condition_not_parsed
= 0;
751 if (is_watchpoint (b
))
753 innermost_block
= NULL
;
755 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
757 error (_("Junk at end of expression"));
758 b
->cond_exp_valid_block
= innermost_block
;
762 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
766 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
768 error (_("Junk at end of expression"));
772 breakpoints_changed ();
773 observer_notify_breakpoint_modified (b
->number
);
776 /* condition N EXP -- set break condition of breakpoint N to EXP. */
779 condition_command (char *arg
, int from_tty
)
781 struct breakpoint
*b
;
786 error_no_arg (_("breakpoint number"));
789 bnum
= get_number (&p
);
791 error (_("Bad breakpoint argument: '%s'"), arg
);
794 if (b
->number
== bnum
)
796 set_breakpoint_condition (b
, p
, from_tty
);
800 error (_("No breakpoint number %d."), bnum
);
803 /* Check that COMMAND do not contain commands that are suitable
804 only for tracepoints and not suitable for ordinary breakpoints.
805 Throw if any such commands is found.
808 check_no_tracepoint_commands (struct command_line
*commands
)
810 struct command_line
*c
;
812 for (c
= commands
; c
; c
= c
->next
)
816 if (c
->control_type
== while_stepping_control
)
817 error (_("The 'while-stepping' command can only be used for tracepoints"));
819 for (i
= 0; i
< c
->body_count
; ++i
)
820 check_no_tracepoint_commands ((c
->body_list
)[i
]);
822 /* Not that command parsing removes leading whitespace and comment
823 lines and also empty lines. So, we only need to check for
825 if (strstr (c
->line
, "collect ") == c
->line
)
826 error (_("The 'collect' command can only be used for tracepoints"));
828 if (strstr (c
->line
, "teval ") == c
->line
)
829 error (_("The 'teval' command can only be used for tracepoints"));
833 /* Encapsulate tests for different types of tracepoints. */
836 is_tracepoint (const struct breakpoint
*b
)
838 return (b
->type
== bp_tracepoint
839 || b
->type
== bp_fast_tracepoint
840 || b
->type
== bp_static_tracepoint
);
843 /* A helper function that validsates that COMMANDS are valid for a
844 breakpoint. This function will throw an exception if a problem is
848 validate_commands_for_breakpoint (struct breakpoint
*b
,
849 struct command_line
*commands
)
851 if (is_tracepoint (b
))
853 /* We need to verify that each top-level element of commands
854 is valid for tracepoints, that there's at most one while-stepping
855 element, and that while-stepping's body has valid tracing commands
856 excluding nested while-stepping. */
857 struct command_line
*c
;
858 struct command_line
*while_stepping
= 0;
859 for (c
= commands
; c
; c
= c
->next
)
861 if (c
->control_type
== while_stepping_control
)
863 if (b
->type
== bp_fast_tracepoint
)
865 The 'while-stepping' command cannot be used for fast tracepoint"));
866 else if (b
->type
== bp_static_tracepoint
)
868 The 'while-stepping' command cannot be used for static tracepoint"));
871 error (_("The 'while-stepping' command can be used only once"));
878 struct command_line
*c2
;
880 gdb_assert (while_stepping
->body_count
== 1);
881 c2
= while_stepping
->body_list
[0];
882 for (; c2
; c2
= c2
->next
)
884 if (c2
->control_type
== while_stepping_control
)
885 error (_("The 'while-stepping' command cannot be nested"));
891 check_no_tracepoint_commands (commands
);
895 /* Return a vector of all the static tracepoints set at ADDR. The
896 caller is responsible for releasing the vector. */
899 static_tracepoints_here (CORE_ADDR addr
)
901 struct breakpoint
*b
;
902 VEC(breakpoint_p
) *found
= 0;
903 struct bp_location
*loc
;
906 if (b
->type
== bp_static_tracepoint
)
908 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
909 if (loc
->address
== addr
)
910 VEC_safe_push(breakpoint_p
, found
, b
);
916 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
917 validate that only allowed commands are included.
921 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
923 validate_commands_for_breakpoint (b
, commands
);
925 decref_counted_command_line (&b
->commands
);
926 b
->commands
= alloc_counted_command_line (commands
);
927 breakpoints_changed ();
928 observer_notify_breakpoint_modified (b
->number
);
932 check_tracepoint_command (char *line
, void *closure
)
934 struct breakpoint
*b
= closure
;
936 validate_actionline (&line
, b
);
939 /* A structure used to pass information through
940 map_breakpoint_numbers. */
944 /* True if the command was typed at a tty. */
947 /* The breakpoint range spec. */
950 /* Non-NULL if the body of the commands are being read from this
951 already-parsed command. */
952 struct command_line
*control
;
954 /* The command lines read from the user, or NULL if they have not
956 struct counted_command_line
*cmd
;
959 /* A callback for map_breakpoint_numbers that sets the commands for
963 do_map_commands_command (struct breakpoint
*b
, void *data
)
965 struct commands_info
*info
= data
;
967 if (info
->cmd
== NULL
)
969 struct command_line
*l
;
971 if (info
->control
!= NULL
)
972 l
= copy_command_lines (info
->control
->body_list
[0]);
975 struct cleanup
*old_chain
;
978 str
= xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
981 old_chain
= make_cleanup (xfree
, str
);
983 l
= read_command_lines (str
,
986 ? check_tracepoint_command
: 0),
989 do_cleanups (old_chain
);
992 info
->cmd
= alloc_counted_command_line (l
);
995 /* If a breakpoint was on the list more than once, we don't need to
997 if (b
->commands
!= info
->cmd
)
999 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1000 incref_counted_command_line (info
->cmd
);
1001 decref_counted_command_line (&b
->commands
);
1002 b
->commands
= info
->cmd
;
1003 breakpoints_changed ();
1004 observer_notify_breakpoint_modified (b
->number
);
1009 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
1011 struct cleanup
*cleanups
;
1012 struct commands_info info
;
1014 info
.from_tty
= from_tty
;
1015 info
.control
= control
;
1017 /* If we read command lines from the user, then `info' will hold an
1018 extra reference to the commands that we must clean up. */
1019 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1021 if (arg
== NULL
|| !*arg
)
1023 if (breakpoint_count
- prev_breakpoint_count
> 1)
1024 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1, breakpoint_count
);
1025 else if (breakpoint_count
> 0)
1026 arg
= xstrprintf ("%d", breakpoint_count
);
1029 /* So that we don't try to free the incoming non-NULL
1030 argument in the cleanup below. Mapping breakpoint
1031 numbers will fail in this case. */
1036 /* The command loop has some static state, so we need to preserve
1038 arg
= xstrdup (arg
);
1041 make_cleanup (xfree
, arg
);
1045 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1047 if (info
.cmd
== NULL
)
1048 error (_("No breakpoints specified."));
1050 do_cleanups (cleanups
);
1054 commands_command (char *arg
, int from_tty
)
1056 commands_command_1 (arg
, from_tty
, NULL
);
1059 /* Like commands_command, but instead of reading the commands from
1060 input stream, takes them from an already parsed command structure.
1062 This is used by cli-script.c to DTRT with breakpoint commands
1063 that are part of if and while bodies. */
1064 enum command_control_type
1065 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1067 commands_command_1 (arg
, 0, cmd
);
1068 return simple_control
;
1071 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1074 bp_location_has_shadow (struct bp_location
*bl
)
1076 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1080 if (bl
->target_info
.shadow_len
== 0)
1081 /* bp isn't valid, or doesn't shadow memory. */
1086 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1087 by replacing any memory breakpoints with their shadowed contents.
1089 The range of shadowed area by each bp_location is:
1090 b->address - bp_location_placed_address_before_address_max
1091 up to b->address + bp_location_shadow_len_after_address_max
1092 The range we were requested to resolve shadows for is:
1093 memaddr ... memaddr + len
1094 Thus the safe cutoff boundaries for performance optimization are
1095 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1097 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1100 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1102 /* Left boundary, right boundary and median element of our binary search. */
1103 unsigned bc_l
, bc_r
, bc
;
1105 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1106 safe to report lower value but a failure to report higher one. */
1109 bc_r
= bp_location_count
;
1110 while (bc_l
+ 1 < bc_r
)
1112 struct bp_location
*b
;
1114 bc
= (bc_l
+ bc_r
) / 2;
1115 b
= bp_location
[bc
];
1117 /* Check first B->ADDRESS will not overflow due to the added constant.
1118 Then advance the left boundary only if we are sure the BC element can
1119 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1121 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1122 we cannot miss a breakpoint with its shadow range tail still reaching
1125 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1126 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1132 /* Now do full processing of the found relevant range of elements. */
1134 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1136 struct bp_location
*b
= bp_location
[bc
];
1137 CORE_ADDR bp_addr
= 0;
1141 /* bp_location array has B->OWNER always non-NULL. */
1142 if (b
->owner
->type
== bp_none
)
1143 warning (_("reading through apparently deleted breakpoint #%d?"),
1146 /* Performance optimization: any futher element can no longer affect BUF
1149 if (b
->address
>= bp_location_placed_address_before_address_max
1150 && memaddr
+ len
<= b
->address
1151 - bp_location_placed_address_before_address_max
)
1154 if (!bp_location_has_shadow (b
))
1156 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1157 current_program_space
->aspace
, 0))
1160 /* Addresses and length of the part of the breakpoint that
1162 bp_addr
= b
->target_info
.placed_address
;
1163 bp_size
= b
->target_info
.shadow_len
;
1165 if (bp_addr
+ bp_size
<= memaddr
)
1166 /* The breakpoint is entirely before the chunk of memory we
1170 if (bp_addr
>= memaddr
+ len
)
1171 /* The breakpoint is entirely after the chunk of memory we are
1175 /* Offset within shadow_contents. */
1176 if (bp_addr
< memaddr
)
1178 /* Only copy the second part of the breakpoint. */
1179 bp_size
-= memaddr
- bp_addr
;
1180 bptoffset
= memaddr
- bp_addr
;
1184 if (bp_addr
+ bp_size
> memaddr
+ len
)
1186 /* Only copy the first part of the breakpoint. */
1187 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1190 memcpy (buf
+ bp_addr
- memaddr
,
1191 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1196 /* A wrapper function for inserting catchpoints. */
1198 insert_catchpoint (struct ui_out
*uo
, void *args
)
1200 struct breakpoint
*b
= (struct breakpoint
*) args
;
1202 gdb_assert (b
->type
== bp_catchpoint
);
1203 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1208 /* Return true if BPT is of any hardware watchpoint kind. */
1211 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1213 return (bpt
->type
== bp_hardware_watchpoint
1214 || bpt
->type
== bp_read_watchpoint
1215 || bpt
->type
== bp_access_watchpoint
);
1218 /* Return true if BPT is of any watchpoint kind, hardware or
1222 is_watchpoint (const struct breakpoint
*bpt
)
1224 return (is_hardware_watchpoint (bpt
)
1225 || bpt
->type
== bp_watchpoint
);
1228 /* Assuming that B is a watchpoint: returns true if the current thread
1229 and its running state are safe to evaluate or update watchpoint B.
1230 Watchpoints on local expressions need to be evaluated in the
1231 context of the thread that was current when the watchpoint was
1232 created, and, that thread needs to be stopped to be able to select
1233 the correct frame context. Watchpoints on global expressions can
1234 be evaluated on any thread, and in any state. It is presently left
1235 to the target allowing memory accesses when threads are
1239 watchpoint_in_thread_scope (struct breakpoint
*b
)
1241 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1242 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1243 && !is_executing (inferior_ptid
)));
1246 /* Assuming that B is a watchpoint:
1247 - Reparse watchpoint expression, if REPARSE is non-zero
1248 - Evaluate expression and store the result in B->val
1249 - Evaluate the condition if there is one, and store the result
1251 - Update the list of values that must be watched in B->loc.
1253 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1254 If this is local watchpoint that is out of scope, delete it.
1256 Even with `set breakpoint always-inserted on' the watchpoints are removed
1257 + inserted on each stop here. Normal breakpoints must never be removed
1258 because they might be missed by a running thread when debugging in non-stop
1259 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1260 processed here) are specific to each LWP since they are stored in each LWP's
1261 hardware debug registers. Therefore, such LWP must be stopped first in
1262 order to be able to modify its hardware watchpoints.
1264 Hardware watchpoints must be reset exactly once after being presented to the
1265 user. It cannot be done sooner, because it would reset the data used to
1266 present the watchpoint hit to the user. And it must not be done later
1267 because it could display the same single watchpoint hit during multiple GDB
1268 stops. Note that the latter is relevant only to the hardware watchpoint
1269 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1270 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1271 memory content has not changed.
1273 The following constraints influence the location where we can reset hardware
1276 * target_stopped_by_watchpoint and target_stopped_data_address are called
1277 several times when GDB stops.
1280 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1281 stop. GDB only presents one hardware watchpoint hit at a time as the
1282 reason for stopping, and all the other hits are presented later, one after
1283 the other, each time the user requests the execution to be resumed.
1284 Execution is not resumed for the threads still having pending hit event
1285 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1286 the inferior on the first stop the thread hit event is kept being reported
1287 from its cached value by linux_nat_stopped_data_address until the real
1288 thread resume happens after the watchpoint gets presented and thus its
1289 LWP_INFO->STATUS gets reset.
1291 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1292 removal from inferior. */
1295 update_watchpoint (struct breakpoint
*b
, int reparse
)
1297 int within_current_scope
;
1298 struct frame_id saved_frame_id
;
1301 /* If this is a local watchpoint, we only want to check if the
1302 watchpoint frame is in scope if the current thread is the thread
1303 that was used to create the watchpoint. */
1304 if (!watchpoint_in_thread_scope (b
))
1307 /* We don't free locations. They are stored in bp_location array and
1308 update_global_locations will eventually delete them and remove
1309 breakpoints if needed. */
1312 if (b
->disposition
== disp_del_at_next_stop
)
1317 /* Determine if the watchpoint is within scope. */
1318 if (b
->exp_valid_block
== NULL
)
1319 within_current_scope
= 1;
1322 struct frame_info
*fi
;
1324 /* Save the current frame's ID so we can restore it after
1325 evaluating the watchpoint expression on its own frame. */
1326 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1327 took a frame parameter, so that we didn't have to change the
1330 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1332 fi
= frame_find_by_id (b
->watchpoint_frame
);
1333 within_current_scope
= (fi
!= NULL
);
1334 if (within_current_scope
)
1338 if (within_current_scope
&& reparse
)
1347 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1348 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1349 /* If the meaning of expression itself changed, the old value is
1350 no longer relevant. We don't want to report a watchpoint hit
1351 to the user when the old value and the new value may actually
1352 be completely different objects. */
1353 value_free (b
->val
);
1357 /* Note that unlike with breakpoints, the watchpoint's condition
1358 expression is stored in the breakpoint object, not in the
1359 locations (re)created below. */
1360 if (b
->cond_string
!= NULL
)
1362 if (b
->cond_exp
!= NULL
)
1364 xfree (b
->cond_exp
);
1369 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1373 /* If we failed to parse the expression, for example because
1374 it refers to a global variable in a not-yet-loaded shared library,
1375 don't try to insert watchpoint. We don't automatically delete
1376 such watchpoint, though, since failure to parse expression
1377 is different from out-of-scope watchpoint. */
1378 if ( !target_has_execution
)
1380 /* Without execution, memory can't change. No use to try and
1381 set watchpoint locations. The watchpoint will be reset when
1382 the target gains execution, through breakpoint_re_set. */
1384 else if (within_current_scope
&& b
->exp
)
1387 struct value
*val_chain
, *v
, *result
, *next
;
1388 struct program_space
*frame_pspace
;
1390 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1392 /* Avoid setting b->val if it's already set. The meaning of
1393 b->val is 'the last value' user saw, and we should update
1394 it only if we reported that last value to user. As it
1395 happens, the code that reports it updates b->val directly. */
1402 /* Change the type of breakpoint between hardware assisted or an
1403 ordinary watchpoint depending on the hardware support and free
1404 hardware slots. REPARSE is set when the inferior is started. */
1405 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1408 int i
, mem_cnt
, other_type_used
;
1410 /* We need to determine how many resources are already used
1411 for all other hardware watchpoints to see if we still have
1412 enough resources to also fit this watchpoint in as well.
1413 To avoid the hw_watchpoint_used_count call below from counting
1414 this watchpoint, make sure that it is marked as a software
1416 b
->type
= bp_watchpoint
;
1417 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1419 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1422 b
->type
= bp_watchpoint
;
1425 int target_resources_ok
= target_can_use_hardware_watchpoint
1426 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1427 if (target_resources_ok
<= 0)
1428 b
->type
= bp_watchpoint
;
1430 b
->type
= bp_hardware_watchpoint
;
1434 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1436 /* Look at each value on the value chain. */
1437 for (v
= val_chain
; v
; v
= next
)
1439 /* If it's a memory location, and GDB actually needed
1440 its contents to evaluate the expression, then we
1441 must watch it. If the first value returned is
1442 still lazy, that means an error occurred reading it;
1443 watch it anyway in case it becomes readable. */
1444 if (VALUE_LVAL (v
) == lval_memory
1445 && (v
== val_chain
|| ! value_lazy (v
)))
1447 struct type
*vtype
= check_typedef (value_type (v
));
1449 /* We only watch structs and arrays if user asked
1450 for it explicitly, never if they just happen to
1451 appear in the middle of some value chain. */
1453 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1454 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1458 struct bp_location
*loc
, **tmp
;
1460 addr
= value_address (v
);
1461 len
= TYPE_LENGTH (value_type (v
));
1463 if (b
->type
== bp_read_watchpoint
)
1465 else if (b
->type
== bp_access_watchpoint
)
1468 loc
= allocate_bp_location (b
);
1469 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1472 loc
->gdbarch
= get_type_arch (value_type (v
));
1474 loc
->pspace
= frame_pspace
;
1475 loc
->address
= addr
;
1477 loc
->watchpoint_type
= type
;
1481 next
= value_next (v
);
1486 /* If a software watchpoint is not watching any memory, then the
1487 above left it without any location set up. But,
1488 bpstat_stop_status requires a location to be able to report
1489 stops, so make sure there's at least a dummy one. */
1490 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1492 b
->loc
= allocate_bp_location (b
);
1493 b
->loc
->pspace
= frame_pspace
;
1494 b
->loc
->address
= -1;
1495 b
->loc
->length
= -1;
1496 b
->loc
->watchpoint_type
= -1;
1499 else if (!within_current_scope
)
1501 printf_filtered (_("\
1502 Watchpoint %d deleted because the program has left the block\n\
1503 in which its expression is valid.\n"),
1505 if (b
->related_breakpoint
)
1507 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1508 b
->related_breakpoint
->related_breakpoint
= NULL
;
1509 b
->related_breakpoint
= NULL
;
1511 b
->disposition
= disp_del_at_next_stop
;
1514 /* Restore the selected frame. */
1516 select_frame (frame_find_by_id (saved_frame_id
));
1520 /* Returns 1 iff breakpoint location should be
1521 inserted in the inferior. */
1523 should_be_inserted (struct bp_location
*bpt
)
1525 if (bpt
->owner
== NULL
|| !breakpoint_enabled (bpt
->owner
))
1528 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1531 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1534 /* This is set for example, when we're attached to the parent of a
1535 vfork, and have detached from the child. The child is running
1536 free, and we expect it to do an exec or exit, at which point the
1537 OS makes the parent schedulable again (and the target reports
1538 that the vfork is done). Until the child is done with the shared
1539 memory region, do not insert breakpoints in the parent, otherwise
1540 the child could still trip on the parent's breakpoints. Since
1541 the parent is blocked anyway, it won't miss any breakpoint. */
1542 if (bpt
->pspace
->breakpoints_not_allowed
)
1545 /* Tracepoints are inserted by the target at a time of its choosing,
1547 if (is_tracepoint (bpt
->owner
))
1553 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1554 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1555 and HW_BREAKPOINT_ERROR are used to report problems.
1557 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1558 method for each breakpoint or catchpoint type. */
1560 insert_bp_location (struct bp_location
*bpt
,
1561 struct ui_file
*tmp_error_stream
,
1562 int *disabled_breaks
,
1563 int *hw_breakpoint_error
)
1567 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1570 /* Initialize the target-specific information. */
1571 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1572 bpt
->target_info
.placed_address
= bpt
->address
;
1573 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1575 if (bpt
->loc_type
== bp_loc_software_breakpoint
1576 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1578 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1580 /* If the explicitly specified breakpoint type
1581 is not hardware breakpoint, check the memory map to see
1582 if the breakpoint address is in read only memory or not.
1583 Two important cases are:
1584 - location type is not hardware breakpoint, memory
1585 is readonly. We change the type of the location to
1586 hardware breakpoint.
1587 - location type is hardware breakpoint, memory is read-write.
1588 This means we've previously made the location hardware one, but
1589 then the memory map changed, so we undo.
1591 When breakpoints are removed, remove_breakpoints will
1592 use location types we've just set here, the only possible
1593 problem is that memory map has changed during running program,
1594 but it's not going to work anyway with current gdb. */
1595 struct mem_region
*mr
1596 = lookup_mem_region (bpt
->target_info
.placed_address
);
1600 if (automatic_hardware_breakpoints
)
1602 enum bp_loc_type new_type
;
1604 if (mr
->attrib
.mode
!= MEM_RW
)
1605 new_type
= bp_loc_hardware_breakpoint
;
1607 new_type
= bp_loc_software_breakpoint
;
1609 if (new_type
!= bpt
->loc_type
)
1611 static int said
= 0;
1613 bpt
->loc_type
= new_type
;
1616 fprintf_filtered (gdb_stdout
, _("\
1617 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1622 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1623 && mr
->attrib
.mode
!= MEM_RW
)
1624 warning (_("cannot set software breakpoint at readonly address %s"),
1625 paddress (bpt
->gdbarch
, bpt
->address
));
1629 /* First check to see if we have to handle an overlay. */
1630 if (overlay_debugging
== ovly_off
1631 || bpt
->section
== NULL
1632 || !(section_is_overlay (bpt
->section
)))
1634 /* No overlay handling: just set the breakpoint. */
1636 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1637 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1640 val
= target_insert_breakpoint (bpt
->gdbarch
,
1645 /* This breakpoint is in an overlay section.
1646 Shall we set a breakpoint at the LMA? */
1647 if (!overlay_events_enabled
)
1649 /* Yes -- overlay event support is not active,
1650 so we must try to set a breakpoint at the LMA.
1651 This will not work for a hardware breakpoint. */
1652 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1653 warning (_("hardware breakpoint %d not supported in overlay!"),
1654 bpt
->owner
->number
);
1657 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1659 /* Set a software (trap) breakpoint at the LMA. */
1660 bpt
->overlay_target_info
= bpt
->target_info
;
1661 bpt
->overlay_target_info
.placed_address
= addr
;
1662 val
= target_insert_breakpoint (bpt
->gdbarch
,
1663 &bpt
->overlay_target_info
);
1665 fprintf_unfiltered (tmp_error_stream
,
1666 "Overlay breakpoint %d failed: in ROM?\n",
1667 bpt
->owner
->number
);
1670 /* Shall we set a breakpoint at the VMA? */
1671 if (section_is_mapped (bpt
->section
))
1673 /* Yes. This overlay section is mapped into memory. */
1674 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1675 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1678 val
= target_insert_breakpoint (bpt
->gdbarch
,
1683 /* No. This breakpoint will not be inserted.
1684 No error, but do not mark the bp as 'inserted'. */
1691 /* Can't set the breakpoint. */
1692 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1694 /* See also: disable_breakpoints_in_shlibs. */
1696 bpt
->shlib_disabled
= 1;
1697 if (!*disabled_breaks
)
1699 fprintf_unfiltered (tmp_error_stream
,
1700 "Cannot insert breakpoint %d.\n",
1701 bpt
->owner
->number
);
1702 fprintf_unfiltered (tmp_error_stream
,
1703 "Temporarily disabling shared library breakpoints:\n");
1705 *disabled_breaks
= 1;
1706 fprintf_unfiltered (tmp_error_stream
,
1707 "breakpoint #%d\n", bpt
->owner
->number
);
1711 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1713 *hw_breakpoint_error
= 1;
1714 fprintf_unfiltered (tmp_error_stream
,
1715 "Cannot insert hardware breakpoint %d.\n",
1716 bpt
->owner
->number
);
1720 fprintf_unfiltered (tmp_error_stream
,
1721 "Cannot insert breakpoint %d.\n",
1722 bpt
->owner
->number
);
1723 fprintf_filtered (tmp_error_stream
,
1724 "Error accessing memory address ");
1725 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1727 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1728 safe_strerror (val
));
1739 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1740 /* NOTE drow/2003-09-08: This state only exists for removing
1741 watchpoints. It's not clear that it's necessary... */
1742 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1744 val
= target_insert_watchpoint (bpt
->address
,
1746 bpt
->watchpoint_type
,
1747 bpt
->owner
->cond_exp
);
1749 /* If trying to set a read-watchpoint, and it turns out it's not
1750 supported, try emulating one with an access watchpoint. */
1751 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1753 struct bp_location
*loc
, **loc_temp
;
1755 /* But don't try to insert it, if there's already another
1756 hw_access location that would be considered a duplicate
1758 ALL_BP_LOCATIONS (loc
, loc_temp
)
1760 && loc
->watchpoint_type
== hw_access
1761 && watchpoint_locations_match (bpt
, loc
))
1765 bpt
->target_info
= loc
->target_info
;
1766 bpt
->watchpoint_type
= hw_access
;
1773 val
= target_insert_watchpoint (bpt
->address
,
1776 bpt
->owner
->cond_exp
);
1778 bpt
->watchpoint_type
= hw_access
;
1782 bpt
->inserted
= (val
== 0);
1785 else if (bpt
->owner
->type
== bp_catchpoint
)
1787 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1788 bpt
->owner
, RETURN_MASK_ERROR
);
1789 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1790 bpt
->owner
->number
);
1792 bpt
->owner
->enable_state
= bp_disabled
;
1796 /* We've already printed an error message if there was a problem
1797 inserting this catchpoint, and we've disabled the catchpoint,
1798 so just return success. */
1805 /* This function is called when program space PSPACE is about to be
1806 deleted. It takes care of updating breakpoints to not reference
1810 breakpoint_program_space_exit (struct program_space
*pspace
)
1812 struct breakpoint
*b
, *b_temp
;
1813 struct bp_location
*loc
, **loc_temp
;
1815 /* Remove any breakpoint that was set through this program space. */
1816 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1818 if (b
->pspace
== pspace
)
1819 delete_breakpoint (b
);
1822 /* Breakpoints set through other program spaces could have locations
1823 bound to PSPACE as well. Remove those. */
1824 ALL_BP_LOCATIONS (loc
, loc_temp
)
1826 struct bp_location
*tmp
;
1828 if (loc
->pspace
== pspace
)
1830 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1831 if (loc
->owner
->loc
== loc
)
1832 loc
->owner
->loc
= loc
->next
;
1834 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1835 if (tmp
->next
== loc
)
1837 tmp
->next
= loc
->next
;
1843 /* Now update the global location list to permanently delete the
1844 removed locations above. */
1845 update_global_location_list (0);
1848 /* Make sure all breakpoints are inserted in inferior.
1849 Throws exception on any error.
1850 A breakpoint that is already inserted won't be inserted
1851 again, so calling this function twice is safe. */
1853 insert_breakpoints (void)
1855 struct breakpoint
*bpt
;
1857 ALL_BREAKPOINTS (bpt
)
1858 if (is_hardware_watchpoint (bpt
))
1859 update_watchpoint (bpt
, 0 /* don't reparse. */);
1861 update_global_location_list (1);
1863 /* update_global_location_list does not insert breakpoints when
1864 always_inserted_mode is not enabled. Explicitly insert them
1866 if (!breakpoints_always_inserted_mode ())
1867 insert_breakpoint_locations ();
1870 /* insert_breakpoints is used when starting or continuing the program.
1871 remove_breakpoints is used when the program stops.
1872 Both return zero if successful,
1873 or an `errno' value if could not write the inferior. */
1876 insert_breakpoint_locations (void)
1878 struct breakpoint
*bpt
;
1879 struct bp_location
*b
, **bp_tmp
;
1882 int disabled_breaks
= 0;
1883 int hw_breakpoint_error
= 0;
1885 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1886 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1888 /* Explicitly mark the warning -- this will only be printed if
1889 there was an error. */
1890 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1892 save_current_space_and_thread ();
1894 ALL_BP_LOCATIONS (b
, bp_tmp
)
1896 if (!should_be_inserted (b
) || b
->inserted
)
1899 /* There is no point inserting thread-specific breakpoints if the
1900 thread no longer exists. ALL_BP_LOCATIONS bp_location has B->OWNER
1902 if (b
->owner
->thread
!= -1
1903 && !valid_thread_id (b
->owner
->thread
))
1906 switch_to_program_space_and_thread (b
->pspace
);
1908 /* For targets that support global breakpoints, there's no need
1909 to select an inferior to insert breakpoint to. In fact, even
1910 if we aren't attached to any process yet, we should still
1911 insert breakpoints. */
1912 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1913 && ptid_equal (inferior_ptid
, null_ptid
))
1916 val
= insert_bp_location (b
, tmp_error_stream
,
1918 &hw_breakpoint_error
);
1923 /* If we failed to insert all locations of a watchpoint,
1924 remove them, as half-inserted watchpoint is of limited use. */
1925 ALL_BREAKPOINTS (bpt
)
1927 int some_failed
= 0;
1928 struct bp_location
*loc
;
1930 if (!is_hardware_watchpoint (bpt
))
1933 if (!breakpoint_enabled (bpt
))
1936 if (bpt
->disposition
== disp_del_at_next_stop
)
1939 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1940 if (!loc
->inserted
&& should_be_inserted (loc
))
1947 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1949 remove_breakpoint (loc
, mark_uninserted
);
1951 hw_breakpoint_error
= 1;
1952 fprintf_unfiltered (tmp_error_stream
,
1953 "Could not insert hardware watchpoint %d.\n",
1961 /* If a hardware breakpoint or watchpoint was inserted, add a
1962 message about possibly exhausted resources. */
1963 if (hw_breakpoint_error
)
1965 fprintf_unfiltered (tmp_error_stream
,
1966 "Could not insert hardware breakpoints:\n\
1967 You may have requested too many hardware breakpoints/watchpoints.\n");
1969 target_terminal_ours_for_output ();
1970 error_stream (tmp_error_stream
);
1973 do_cleanups (cleanups
);
1977 remove_breakpoints (void)
1979 struct bp_location
*b
, **bp_tmp
;
1982 ALL_BP_LOCATIONS (b
, bp_tmp
)
1985 val
|= remove_breakpoint (b
, mark_uninserted
);
1990 /* Remove breakpoints of process PID. */
1993 remove_breakpoints_pid (int pid
)
1995 struct bp_location
*b
, **b_tmp
;
1997 struct inferior
*inf
= find_inferior_pid (pid
);
1999 ALL_BP_LOCATIONS (b
, b_tmp
)
2001 if (b
->pspace
!= inf
->pspace
)
2006 val
= remove_breakpoint (b
, mark_uninserted
);
2015 remove_hw_watchpoints (void)
2017 struct bp_location
*b
, **bp_tmp
;
2020 ALL_BP_LOCATIONS (b
, bp_tmp
)
2022 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2023 val
|= remove_breakpoint (b
, mark_uninserted
);
2029 reattach_breakpoints (int pid
)
2031 struct cleanup
*old_chain
;
2032 struct bp_location
*b
, **bp_tmp
;
2034 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2035 int dummy1
= 0, dummy2
= 0;
2036 struct inferior
*inf
;
2037 struct thread_info
*tp
;
2039 tp
= any_live_thread_of_process (pid
);
2043 inf
= find_inferior_pid (pid
);
2044 old_chain
= save_inferior_ptid ();
2046 inferior_ptid
= tp
->ptid
;
2048 make_cleanup_ui_file_delete (tmp_error_stream
);
2050 ALL_BP_LOCATIONS (b
, bp_tmp
)
2052 if (b
->pspace
!= inf
->pspace
)
2058 val
= insert_bp_location (b
, tmp_error_stream
,
2062 do_cleanups (old_chain
);
2067 do_cleanups (old_chain
);
2071 static int internal_breakpoint_number
= -1;
2073 static struct breakpoint
*
2074 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2075 CORE_ADDR address
, enum bptype type
)
2077 struct symtab_and_line sal
;
2078 struct breakpoint
*b
;
2080 init_sal (&sal
); /* initialize to zeroes */
2083 sal
.section
= find_pc_overlay (sal
.pc
);
2084 sal
.pspace
= current_program_space
;
2086 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2087 b
->number
= internal_breakpoint_number
--;
2088 b
->disposition
= disp_donttouch
;
2094 create_overlay_event_breakpoint (char *func_name
)
2096 struct objfile
*objfile
;
2098 ALL_OBJFILES (objfile
)
2100 struct breakpoint
*b
;
2101 struct minimal_symbol
*m
;
2103 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2107 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2108 SYMBOL_VALUE_ADDRESS (m
),
2110 b
->addr_string
= xstrdup (func_name
);
2112 if (overlay_debugging
== ovly_auto
)
2114 b
->enable_state
= bp_enabled
;
2115 overlay_events_enabled
= 1;
2119 b
->enable_state
= bp_disabled
;
2120 overlay_events_enabled
= 0;
2123 update_global_location_list (1);
2127 create_longjmp_master_breakpoint (char *func_name
)
2129 struct program_space
*pspace
;
2130 struct objfile
*objfile
;
2131 struct cleanup
*old_chain
;
2133 old_chain
= save_current_program_space ();
2135 ALL_PSPACES (pspace
)
2136 ALL_OBJFILES (objfile
)
2138 struct breakpoint
*b
;
2139 struct minimal_symbol
*m
;
2141 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2144 set_current_program_space (pspace
);
2146 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2150 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2151 SYMBOL_VALUE_ADDRESS (m
),
2153 b
->addr_string
= xstrdup (func_name
);
2154 b
->enable_state
= bp_disabled
;
2156 update_global_location_list (1);
2158 do_cleanups (old_chain
);
2161 /* Create a master std::terminate breakpoint. The actual function
2162 looked for is named FUNC_NAME. */
2164 create_std_terminate_master_breakpoint (const char *func_name
)
2166 struct program_space
*pspace
;
2167 struct objfile
*objfile
;
2168 struct cleanup
*old_chain
;
2170 old_chain
= save_current_program_space ();
2172 ALL_PSPACES (pspace
)
2173 ALL_OBJFILES (objfile
)
2175 struct breakpoint
*b
;
2176 struct minimal_symbol
*m
;
2178 set_current_program_space (pspace
);
2180 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2181 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2182 && MSYMBOL_TYPE (m
) != mst_file_text
))
2185 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2186 SYMBOL_VALUE_ADDRESS (m
),
2187 bp_std_terminate_master
);
2188 b
->addr_string
= xstrdup (func_name
);
2189 b
->enable_state
= bp_disabled
;
2191 update_global_location_list (1);
2193 do_cleanups (old_chain
);
2197 update_breakpoints_after_exec (void)
2199 struct breakpoint
*b
;
2200 struct breakpoint
*temp
;
2201 struct bp_location
*bploc
, **bplocp_tmp
;
2203 /* We're about to delete breakpoints from GDB's lists. If the
2204 INSERTED flag is true, GDB will try to lift the breakpoints by
2205 writing the breakpoints' "shadow contents" back into memory. The
2206 "shadow contents" are NOT valid after an exec, so GDB should not
2207 do that. Instead, the target is responsible from marking
2208 breakpoints out as soon as it detects an exec. We don't do that
2209 here instead, because there may be other attempts to delete
2210 breakpoints after detecting an exec and before reaching here. */
2211 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2212 if (bploc
->pspace
== current_program_space
)
2213 gdb_assert (!bploc
->inserted
);
2215 ALL_BREAKPOINTS_SAFE (b
, temp
)
2217 if (b
->pspace
!= current_program_space
)
2220 /* Solib breakpoints must be explicitly reset after an exec(). */
2221 if (b
->type
== bp_shlib_event
)
2223 delete_breakpoint (b
);
2227 /* JIT breakpoints must be explicitly reset after an exec(). */
2228 if (b
->type
== bp_jit_event
)
2230 delete_breakpoint (b
);
2234 /* Thread event breakpoints must be set anew after an exec(),
2235 as must overlay event and longjmp master breakpoints. */
2236 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2237 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2239 delete_breakpoint (b
);
2243 /* Step-resume breakpoints are meaningless after an exec(). */
2244 if (b
->type
== bp_step_resume
)
2246 delete_breakpoint (b
);
2250 /* Longjmp and longjmp-resume breakpoints are also meaningless
2252 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2254 delete_breakpoint (b
);
2258 if (b
->type
== bp_catchpoint
)
2260 /* For now, none of the bp_catchpoint breakpoints need to
2261 do anything at this point. In the future, if some of
2262 the catchpoints need to something, we will need to add
2263 a new method, and call this method from here. */
2267 /* bp_finish is a special case. The only way we ought to be able
2268 to see one of these when an exec() has happened, is if the user
2269 caught a vfork, and then said "finish". Ordinarily a finish just
2270 carries them to the call-site of the current callee, by setting
2271 a temporary bp there and resuming. But in this case, the finish
2272 will carry them entirely through the vfork & exec.
2274 We don't want to allow a bp_finish to remain inserted now. But
2275 we can't safely delete it, 'cause finish_command has a handle to
2276 the bp on a bpstat, and will later want to delete it. There's a
2277 chance (and I've seen it happen) that if we delete the bp_finish
2278 here, that its storage will get reused by the time finish_command
2279 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2280 We really must allow finish_command to delete a bp_finish.
2282 In the absense of a general solution for the "how do we know
2283 it's safe to delete something others may have handles to?"
2284 problem, what we'll do here is just uninsert the bp_finish, and
2285 let finish_command delete it.
2287 (We know the bp_finish is "doomed" in the sense that it's
2288 momentary, and will be deleted as soon as finish_command sees
2289 the inferior stopped. So it doesn't matter that the bp's
2290 address is probably bogus in the new a.out, unlike e.g., the
2291 solib breakpoints.) */
2293 if (b
->type
== bp_finish
)
2298 /* Without a symbolic address, we have little hope of the
2299 pre-exec() address meaning the same thing in the post-exec()
2301 if (b
->addr_string
== NULL
)
2303 delete_breakpoint (b
);
2307 /* FIXME what about longjmp breakpoints? Re-create them here? */
2308 create_overlay_event_breakpoint ("_ovly_debug_event");
2309 create_longjmp_master_breakpoint ("longjmp");
2310 create_longjmp_master_breakpoint ("_longjmp");
2311 create_longjmp_master_breakpoint ("siglongjmp");
2312 create_longjmp_master_breakpoint ("_siglongjmp");
2313 create_std_terminate_master_breakpoint ("std::terminate()");
2317 detach_breakpoints (int pid
)
2319 struct bp_location
*b
, **bp_tmp
;
2321 struct cleanup
*old_chain
= save_inferior_ptid ();
2322 struct inferior
*inf
= current_inferior ();
2324 if (pid
== PIDGET (inferior_ptid
))
2325 error (_("Cannot detach breakpoints of inferior_ptid"));
2327 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2328 inferior_ptid
= pid_to_ptid (pid
);
2329 ALL_BP_LOCATIONS (b
, bp_tmp
)
2331 if (b
->pspace
!= inf
->pspace
)
2335 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2338 /* Detach single-step breakpoints as well. */
2339 detach_single_step_breakpoints ();
2341 do_cleanups (old_chain
);
2345 /* Remove the breakpoint location B from the current address space.
2346 Note that this is used to detach breakpoints from a child fork.
2347 When we get here, the child isn't in the inferior list, and neither
2348 do we have objects to represent its address space --- we should
2349 *not* look at b->pspace->aspace here. */
2352 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2356 /* B is never in moribund_locations by our callers. */
2357 gdb_assert (b
->owner
!= NULL
);
2359 if (b
->owner
->enable_state
== bp_permanent
)
2360 /* Permanent breakpoints cannot be inserted or removed. */
2363 /* The type of none suggests that owner is actually deleted.
2364 This should not ever happen. */
2365 gdb_assert (b
->owner
->type
!= bp_none
);
2367 if (b
->loc_type
== bp_loc_software_breakpoint
2368 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2370 /* "Normal" instruction breakpoint: either the standard
2371 trap-instruction bp (bp_breakpoint), or a
2372 bp_hardware_breakpoint. */
2374 /* First check to see if we have to handle an overlay. */
2375 if (overlay_debugging
== ovly_off
2376 || b
->section
== NULL
2377 || !(section_is_overlay (b
->section
)))
2379 /* No overlay handling: just remove the breakpoint. */
2381 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2382 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2384 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2388 /* This breakpoint is in an overlay section.
2389 Did we set a breakpoint at the LMA? */
2390 if (!overlay_events_enabled
)
2392 /* Yes -- overlay event support is not active, so we
2393 should have set a breakpoint at the LMA. Remove it.
2395 /* Ignore any failures: if the LMA is in ROM, we will
2396 have already warned when we failed to insert it. */
2397 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2398 target_remove_hw_breakpoint (b
->gdbarch
,
2399 &b
->overlay_target_info
);
2401 target_remove_breakpoint (b
->gdbarch
,
2402 &b
->overlay_target_info
);
2404 /* Did we set a breakpoint at the VMA?
2405 If so, we will have marked the breakpoint 'inserted'. */
2408 /* Yes -- remove it. Previously we did not bother to
2409 remove the breakpoint if the section had been
2410 unmapped, but let's not rely on that being safe. We
2411 don't know what the overlay manager might do. */
2412 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2413 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2416 /* However, we should remove *software* breakpoints only
2417 if the section is still mapped, or else we overwrite
2418 wrong code with the saved shadow contents. */
2419 else if (section_is_mapped (b
->section
))
2420 val
= target_remove_breakpoint (b
->gdbarch
,
2427 /* No -- not inserted, so no need to remove. No error. */
2432 /* In some cases, we might not be able to remove a breakpoint
2433 in a shared library that has already been removed, but we
2434 have not yet processed the shlib unload event. */
2435 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2440 b
->inserted
= (is
== mark_inserted
);
2442 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2444 b
->inserted
= (is
== mark_inserted
);
2445 val
= target_remove_watchpoint (b
->address
, b
->length
,
2446 b
->watchpoint_type
, b
->owner
->cond_exp
);
2448 /* Failure to remove any of the hardware watchpoints comes here. */
2449 if ((is
== mark_uninserted
) && (b
->inserted
))
2450 warning (_("Could not remove hardware watchpoint %d."),
2453 else if (b
->owner
->type
== bp_catchpoint
2454 && breakpoint_enabled (b
->owner
)
2457 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2459 val
= b
->owner
->ops
->remove (b
->owner
);
2462 b
->inserted
= (is
== mark_inserted
);
2469 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2472 struct cleanup
*old_chain
;
2474 /* B is never in moribund_locations by our callers. */
2475 gdb_assert (b
->owner
!= NULL
);
2477 if (b
->owner
->enable_state
== bp_permanent
)
2478 /* Permanent breakpoints cannot be inserted or removed. */
2481 /* The type of none suggests that owner is actually deleted.
2482 This should not ever happen. */
2483 gdb_assert (b
->owner
->type
!= bp_none
);
2485 old_chain
= save_current_space_and_thread ();
2487 switch_to_program_space_and_thread (b
->pspace
);
2489 ret
= remove_breakpoint_1 (b
, is
);
2491 do_cleanups (old_chain
);
2495 /* Clear the "inserted" flag in all breakpoints. */
2498 mark_breakpoints_out (void)
2500 struct bp_location
*bpt
, **bptp_tmp
;
2502 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2503 if (bpt
->pspace
== current_program_space
)
2507 /* Clear the "inserted" flag in all breakpoints and delete any
2508 breakpoints which should go away between runs of the program.
2510 Plus other such housekeeping that has to be done for breakpoints
2513 Note: this function gets called at the end of a run (by
2514 generic_mourn_inferior) and when a run begins (by
2515 init_wait_for_inferior). */
2520 breakpoint_init_inferior (enum inf_context context
)
2522 struct breakpoint
*b
, *temp
;
2523 struct bp_location
*bpt
, **bptp_tmp
;
2525 struct program_space
*pspace
= current_program_space
;
2527 /* If breakpoint locations are shared across processes, then there's
2529 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2532 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2534 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2535 if (bpt
->pspace
== pspace
2536 && bpt
->owner
->enable_state
!= bp_permanent
)
2540 ALL_BREAKPOINTS_SAFE (b
, temp
)
2542 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2549 /* If the call dummy breakpoint is at the entry point it will
2550 cause problems when the inferior is rerun, so we better get
2553 case bp_watchpoint_scope
:
2555 /* Also get rid of scope breakpoints. */
2557 case bp_shlib_event
:
2559 /* Also remove solib event breakpoints. Their addresses may
2560 have changed since the last time we ran the program.
2561 Actually we may now be debugging against different target;
2562 and so the solib backend that installed this breakpoint may
2563 not be used in by the target. E.g.,
2565 (gdb) file prog-linux
2566 (gdb) run # native linux target
2569 (gdb) file prog-win.exe
2570 (gdb) tar rem :9999 # remote Windows gdbserver.
2573 delete_breakpoint (b
);
2577 case bp_hardware_watchpoint
:
2578 case bp_read_watchpoint
:
2579 case bp_access_watchpoint
:
2581 /* Likewise for watchpoints on local expressions. */
2582 if (b
->exp_valid_block
!= NULL
)
2583 delete_breakpoint (b
);
2584 else if (context
== inf_starting
)
2586 /* Reset val field to force reread of starting value
2587 in insert_breakpoints. */
2589 value_free (b
->val
);
2599 /* Get rid of the moribund locations. */
2600 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2601 decref_bp_location (&bpt
);
2602 VEC_free (bp_location_p
, moribund_locations
);
2605 /* These functions concern about actual breakpoints inserted in the
2606 target --- to e.g. check if we need to do decr_pc adjustment or if
2607 we need to hop over the bkpt --- so we check for address space
2608 match, not program space. */
2610 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2611 exists at PC. It returns ordinary_breakpoint_here if it's an
2612 ordinary breakpoint, or permanent_breakpoint_here if it's a
2613 permanent breakpoint.
2614 - When continuing from a location with an ordinary breakpoint, we
2615 actually single step once before calling insert_breakpoints.
2616 - When continuing from a localion with a permanent breakpoint, we
2617 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2618 the target, to advance the PC past the breakpoint. */
2620 enum breakpoint_here
2621 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2623 struct bp_location
*bpt
, **bptp_tmp
;
2624 int any_breakpoint_here
= 0;
2626 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2628 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2629 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2632 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2633 if ((breakpoint_enabled (bpt
->owner
)
2634 || bpt
->owner
->enable_state
== bp_permanent
)
2635 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2638 if (overlay_debugging
2639 && section_is_overlay (bpt
->section
)
2640 && !section_is_mapped (bpt
->section
))
2641 continue; /* unmapped overlay -- can't be a match */
2642 else if (bpt
->owner
->enable_state
== bp_permanent
)
2643 return permanent_breakpoint_here
;
2645 any_breakpoint_here
= 1;
2649 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2652 /* Return true if there's a moribund breakpoint at PC. */
2655 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2657 struct bp_location
*loc
;
2660 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2661 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2668 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2669 inserted using regular breakpoint_chain / bp_location array mechanism.
2670 This does not check for single-step breakpoints, which are
2671 inserted and removed using direct target manipulation. */
2674 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2676 struct bp_location
*bpt
, **bptp_tmp
;
2678 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2680 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2681 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2685 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2688 if (overlay_debugging
2689 && section_is_overlay (bpt
->section
)
2690 && !section_is_mapped (bpt
->section
))
2691 continue; /* unmapped overlay -- can't be a match */
2699 /* Returns non-zero iff there's either regular breakpoint
2700 or a single step breakpoint inserted at PC. */
2703 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2705 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2708 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2714 /* This function returns non-zero iff there is a software breakpoint
2718 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2720 struct bp_location
*bpt
, **bptp_tmp
;
2722 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2724 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2728 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2731 if (overlay_debugging
2732 && section_is_overlay (bpt
->section
)
2733 && !section_is_mapped (bpt
->section
))
2734 continue; /* unmapped overlay -- can't be a match */
2740 /* Also check for software single-step breakpoints. */
2741 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2748 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2749 CORE_ADDR addr
, ULONGEST len
)
2751 struct breakpoint
*bpt
;
2753 ALL_BREAKPOINTS (bpt
)
2755 struct bp_location
*loc
;
2757 if (bpt
->type
!= bp_hardware_watchpoint
2758 && bpt
->type
!= bp_access_watchpoint
)
2761 if (!breakpoint_enabled (bpt
))
2764 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2765 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2769 /* Check for intersection. */
2770 l
= max (loc
->address
, addr
);
2771 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2779 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2780 PC is valid for process/thread PTID. */
2783 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2786 struct bp_location
*bpt
, **bptp_tmp
;
2787 /* The thread and task IDs associated to PTID, computed lazily. */
2791 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2793 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2794 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2797 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2798 if (!breakpoint_enabled (bpt
->owner
)
2799 && bpt
->owner
->enable_state
!= bp_permanent
)
2802 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2806 if (bpt
->owner
->thread
!= -1)
2808 /* This is a thread-specific breakpoint. Check that ptid
2809 matches that thread. If thread hasn't been computed yet,
2810 it is now time to do so. */
2812 thread
= pid_to_thread_id (ptid
);
2813 if (bpt
->owner
->thread
!= thread
)
2817 if (bpt
->owner
->task
!= 0)
2819 /* This is a task-specific breakpoint. Check that ptid
2820 matches that task. If task hasn't been computed yet,
2821 it is now time to do so. */
2823 task
= ada_get_task_number (ptid
);
2824 if (bpt
->owner
->task
!= task
)
2828 if (overlay_debugging
2829 && section_is_overlay (bpt
->section
)
2830 && !section_is_mapped (bpt
->section
))
2831 continue; /* unmapped overlay -- can't be a match */
2840 /* bpstat stuff. External routines' interfaces are documented
2844 ep_is_catchpoint (struct breakpoint
*ep
)
2846 return (ep
->type
== bp_catchpoint
);
2849 /* Frees any storage that is part of a bpstat. Does not walk the
2853 bpstat_free (bpstat bs
)
2855 if (bs
->old_val
!= NULL
)
2856 value_free (bs
->old_val
);
2857 decref_counted_command_line (&bs
->commands
);
2858 decref_bp_location (&bs
->bp_location_at
);
2862 /* Clear a bpstat so that it says we are not at any breakpoint.
2863 Also free any storage that is part of a bpstat. */
2866 bpstat_clear (bpstat
*bsp
)
2883 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2884 is part of the bpstat is copied as well. */
2887 bpstat_copy (bpstat bs
)
2891 bpstat retval
= NULL
;
2896 for (; bs
!= NULL
; bs
= bs
->next
)
2898 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2899 memcpy (tmp
, bs
, sizeof (*tmp
));
2900 incref_counted_command_line (tmp
->commands
);
2901 incref_bp_location (tmp
->bp_location_at
);
2902 if (bs
->old_val
!= NULL
)
2904 tmp
->old_val
= value_copy (bs
->old_val
);
2905 release_value (tmp
->old_val
);
2909 /* This is the first thing in the chain. */
2919 /* Find the bpstat associated with this breakpoint */
2922 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2927 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2929 if (bsp
->breakpoint_at
== breakpoint
)
2935 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2936 at. *BSP upon return is a bpstat which points to the remaining
2937 breakpoints stopped at (but which is not guaranteed to be good for
2938 anything but further calls to bpstat_num).
2939 Return 0 if passed a bpstat which does not indicate any breakpoints.
2940 Return -1 if stopped at a breakpoint that has been deleted since
2942 Return 1 otherwise. */
2945 bpstat_num (bpstat
*bsp
, int *num
)
2947 struct breakpoint
*b
;
2950 return 0; /* No more breakpoint values */
2952 /* We assume we'll never have several bpstats that
2953 correspond to a single breakpoint -- otherwise,
2954 this function might return the same number more
2955 than once and this will look ugly. */
2956 b
= (*bsp
)->breakpoint_at
;
2957 *bsp
= (*bsp
)->next
;
2959 return -1; /* breakpoint that's been deleted since */
2961 *num
= b
->number
; /* We have its number */
2965 /* Modify BS so that the actions will not be performed. */
2968 bpstat_clear_actions (bpstat bs
)
2970 for (; bs
!= NULL
; bs
= bs
->next
)
2972 decref_counted_command_line (&bs
->commands
);
2973 bs
->commands_left
= NULL
;
2974 if (bs
->old_val
!= NULL
)
2976 value_free (bs
->old_val
);
2982 /* Called when a command is about to proceed the inferior. */
2985 breakpoint_about_to_proceed (void)
2987 if (!ptid_equal (inferior_ptid
, null_ptid
))
2989 struct thread_info
*tp
= inferior_thread ();
2991 /* Allow inferior function calls in breakpoint commands to not
2992 interrupt the command list. When the call finishes
2993 successfully, the inferior will be standing at the same
2994 breakpoint as if nothing happened. */
2999 breakpoint_proceeded
= 1;
3002 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3004 cleanup_executing_breakpoints (void *ignore
)
3006 executing_breakpoint_commands
= 0;
3009 /* Execute all the commands associated with all the breakpoints at this
3010 location. Any of these commands could cause the process to proceed
3011 beyond this point, etc. We look out for such changes by checking
3012 the global "breakpoint_proceeded" after each command.
3014 Returns true if a breakpoint command resumed the inferior. In that
3015 case, it is the caller's responsibility to recall it again with the
3016 bpstat of the current thread. */
3019 bpstat_do_actions_1 (bpstat
*bsp
)
3022 struct cleanup
*old_chain
;
3025 /* Avoid endless recursion if a `source' command is contained
3027 if (executing_breakpoint_commands
)
3030 executing_breakpoint_commands
= 1;
3031 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3033 /* This pointer will iterate over the list of bpstat's. */
3036 breakpoint_proceeded
= 0;
3037 for (; bs
!= NULL
; bs
= bs
->next
)
3039 struct counted_command_line
*ccmd
;
3040 struct command_line
*cmd
;
3041 struct cleanup
*this_cmd_tree_chain
;
3043 /* Take ownership of the BSP's command tree, if it has one.
3045 The command tree could legitimately contain commands like
3046 'step' and 'next', which call clear_proceed_status, which
3047 frees stop_bpstat's command tree. To make sure this doesn't
3048 free the tree we're executing out from under us, we need to
3049 take ownership of the tree ourselves. Since a given bpstat's
3050 commands are only executed once, we don't need to copy it; we
3051 can clear the pointer in the bpstat, and make sure we free
3052 the tree when we're done. */
3053 ccmd
= bs
->commands
;
3054 bs
->commands
= NULL
;
3056 = make_cleanup_decref_counted_command_line (&ccmd
);
3057 cmd
= bs
->commands_left
;
3058 bs
->commands_left
= NULL
;
3062 execute_control_command (cmd
);
3064 if (breakpoint_proceeded
)
3070 /* We can free this command tree now. */
3071 do_cleanups (this_cmd_tree_chain
);
3073 if (breakpoint_proceeded
)
3075 if (target_can_async_p ())
3076 /* If we are in async mode, then the target might be still
3077 running, not stopped at any breakpoint, so nothing for
3078 us to do here -- just return to the event loop. */
3081 /* In sync mode, when execute_control_command returns
3082 we're already standing on the next breakpoint.
3083 Breakpoint commands for that stop were not run, since
3084 execute_command does not run breakpoint commands --
3085 only command_line_handler does, but that one is not
3086 involved in execution of breakpoint commands. So, we
3087 can now execute breakpoint commands. It should be
3088 noted that making execute_command do bpstat actions is
3089 not an option -- in this case we'll have recursive
3090 invocation of bpstat for each breakpoint with a
3091 command, and can easily blow up GDB stack. Instead, we
3092 return true, which will trigger the caller to recall us
3093 with the new stop_bpstat. */
3098 do_cleanups (old_chain
);
3103 bpstat_do_actions (void)
3105 /* Do any commands attached to breakpoint we are stopped at. */
3106 while (!ptid_equal (inferior_ptid
, null_ptid
)
3107 && target_has_execution
3108 && !is_exited (inferior_ptid
)
3109 && !is_executing (inferior_ptid
))
3110 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3111 and only return when it is stopped at the next breakpoint, we
3112 keep doing breakpoint actions until it returns false to
3113 indicate the inferior was not resumed. */
3114 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3118 /* Print out the (old or new) value associated with a watchpoint. */
3121 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3124 fprintf_unfiltered (stream
, _("<unreadable>"));
3127 struct value_print_options opts
;
3128 get_user_print_options (&opts
);
3129 value_print (val
, stream
, &opts
);
3133 /* This is the normal print function for a bpstat. In the future,
3134 much of this logic could (should?) be moved to bpstat_stop_status,
3135 by having it set different print_it values.
3137 Current scheme: When we stop, bpstat_print() is called. It loops
3138 through the bpstat list of things causing this stop, calling the
3139 print_bp_stop_message function on each one. The behavior of the
3140 print_bp_stop_message function depends on the print_it field of
3141 bpstat. If such field so indicates, call this function here.
3143 Return values from this routine (ultimately used by bpstat_print()
3144 and normal_stop() to decide what to do):
3145 PRINT_NOTHING: Means we already printed all we needed to print,
3146 don't print anything else.
3147 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3148 that something to be followed by a location.
3149 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3150 that something to be followed by a location.
3151 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3154 static enum print_stop_action
3155 print_it_typical (bpstat bs
)
3157 struct cleanup
*old_chain
;
3158 struct breakpoint
*b
;
3159 const struct bp_location
*bl
;
3160 struct ui_stream
*stb
;
3162 enum print_stop_action result
;
3164 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3165 which has since been deleted. */
3166 if (bs
->breakpoint_at
== NULL
)
3167 return PRINT_UNKNOWN
;
3169 gdb_assert (bs
->bp_location_at
!= NULL
);
3171 bl
= bs
->bp_location_at
;
3172 b
= bs
->breakpoint_at
;
3174 stb
= ui_out_stream_new (uiout
);
3175 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3180 case bp_hardware_breakpoint
:
3181 bp_temp
= b
->disposition
== disp_del
;
3182 if (bl
->address
!= bl
->requested_address
)
3183 breakpoint_adjustment_warning (bl
->requested_address
,
3186 annotate_breakpoint (b
->number
);
3188 ui_out_text (uiout
, "\nTemporary breakpoint ");
3190 ui_out_text (uiout
, "\nBreakpoint ");
3191 if (ui_out_is_mi_like_p (uiout
))
3193 ui_out_field_string (uiout
, "reason",
3194 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3195 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3197 ui_out_field_int (uiout
, "bkptno", b
->number
);
3198 ui_out_text (uiout
, ", ");
3199 result
= PRINT_SRC_AND_LOC
;
3202 case bp_shlib_event
:
3203 /* Did we stop because the user set the stop_on_solib_events
3204 variable? (If so, we report this as a generic, "Stopped due
3205 to shlib event" message.) */
3206 printf_filtered (_("Stopped due to shared library event\n"));
3207 result
= PRINT_NOTHING
;
3210 case bp_thread_event
:
3211 /* Not sure how we will get here.
3212 GDB should not stop for these breakpoints. */
3213 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3214 result
= PRINT_NOTHING
;
3217 case bp_overlay_event
:
3218 /* By analogy with the thread event, GDB should not stop for these. */
3219 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3220 result
= PRINT_NOTHING
;
3223 case bp_longjmp_master
:
3224 /* These should never be enabled. */
3225 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3226 result
= PRINT_NOTHING
;
3229 case bp_std_terminate_master
:
3230 /* These should never be enabled. */
3231 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3232 result
= PRINT_NOTHING
;
3236 case bp_hardware_watchpoint
:
3237 annotate_watchpoint (b
->number
);
3238 if (ui_out_is_mi_like_p (uiout
))
3241 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3243 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3244 ui_out_text (uiout
, "\nOld value = ");
3245 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3246 ui_out_field_stream (uiout
, "old", stb
);
3247 ui_out_text (uiout
, "\nNew value = ");
3248 watchpoint_value_print (b
->val
, stb
->stream
);
3249 ui_out_field_stream (uiout
, "new", stb
);
3250 ui_out_text (uiout
, "\n");
3251 /* More than one watchpoint may have been triggered. */
3252 result
= PRINT_UNKNOWN
;
3255 case bp_read_watchpoint
:
3256 if (ui_out_is_mi_like_p (uiout
))
3259 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3261 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3262 ui_out_text (uiout
, "\nValue = ");
3263 watchpoint_value_print (b
->val
, stb
->stream
);
3264 ui_out_field_stream (uiout
, "value", stb
);
3265 ui_out_text (uiout
, "\n");
3266 result
= PRINT_UNKNOWN
;
3269 case bp_access_watchpoint
:
3270 if (bs
->old_val
!= NULL
)
3272 annotate_watchpoint (b
->number
);
3273 if (ui_out_is_mi_like_p (uiout
))
3276 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3278 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3279 ui_out_text (uiout
, "\nOld value = ");
3280 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3281 ui_out_field_stream (uiout
, "old", stb
);
3282 ui_out_text (uiout
, "\nNew value = ");
3287 if (ui_out_is_mi_like_p (uiout
))
3290 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3291 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3292 ui_out_text (uiout
, "\nValue = ");
3294 watchpoint_value_print (b
->val
, stb
->stream
);
3295 ui_out_field_stream (uiout
, "new", stb
);
3296 ui_out_text (uiout
, "\n");
3297 result
= PRINT_UNKNOWN
;
3300 /* Fall through, we don't deal with these types of breakpoints
3304 if (ui_out_is_mi_like_p (uiout
))
3307 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3308 result
= PRINT_UNKNOWN
;
3312 if (ui_out_is_mi_like_p (uiout
))
3315 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3316 result
= PRINT_UNKNOWN
;
3321 case bp_longjmp_resume
:
3322 case bp_step_resume
:
3323 case bp_watchpoint_scope
:
3325 case bp_std_terminate
:
3327 case bp_fast_tracepoint
:
3330 result
= PRINT_UNKNOWN
;
3334 do_cleanups (old_chain
);
3338 /* Generic routine for printing messages indicating why we
3339 stopped. The behavior of this function depends on the value
3340 'print_it' in the bpstat structure. Under some circumstances we
3341 may decide not to print anything here and delegate the task to
3344 static enum print_stop_action
3345 print_bp_stop_message (bpstat bs
)
3347 switch (bs
->print_it
)
3350 /* Nothing should be printed for this bpstat entry. */
3351 return PRINT_UNKNOWN
;
3355 /* We still want to print the frame, but we already printed the
3356 relevant messages. */
3357 return PRINT_SRC_AND_LOC
;
3360 case print_it_normal
:
3362 struct breakpoint
*b
= bs
->breakpoint_at
;
3364 /* Normal case. Call the breakpoint's print_it method, or
3365 print_it_typical. */
3366 /* FIXME: how breakpoint can ever be NULL here? */
3367 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3368 return b
->ops
->print_it (b
);
3370 return print_it_typical (bs
);
3375 internal_error (__FILE__
, __LINE__
,
3376 _("print_bp_stop_message: unrecognized enum value"));
3381 /* Print a message indicating what happened. This is called from
3382 normal_stop(). The input to this routine is the head of the bpstat
3383 list - a list of the eventpoints that caused this stop. This
3384 routine calls the generic print routine for printing a message
3385 about reasons for stopping. This will print (for example) the
3386 "Breakpoint n," part of the output. The return value of this
3389 PRINT_UNKNOWN: Means we printed nothing
3390 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3391 code to print the location. An example is
3392 "Breakpoint 1, " which should be followed by
3394 PRINT_SRC_ONLY: Means we printed something, but there is no need
3395 to also print the location part of the message.
3396 An example is the catch/throw messages, which
3397 don't require a location appended to the end.
3398 PRINT_NOTHING: We have done some printing and we don't need any
3399 further info to be printed.*/
3401 enum print_stop_action
3402 bpstat_print (bpstat bs
)
3406 /* Maybe another breakpoint in the chain caused us to stop.
3407 (Currently all watchpoints go on the bpstat whether hit or not.
3408 That probably could (should) be changed, provided care is taken
3409 with respect to bpstat_explains_signal). */
3410 for (; bs
; bs
= bs
->next
)
3412 val
= print_bp_stop_message (bs
);
3413 if (val
== PRINT_SRC_ONLY
3414 || val
== PRINT_SRC_AND_LOC
3415 || val
== PRINT_NOTHING
)
3419 /* We reached the end of the chain, or we got a null BS to start
3420 with and nothing was printed. */
3421 return PRINT_UNKNOWN
;
3424 /* Evaluate the expression EXP and return 1 if value is zero.
3425 This is used inside a catch_errors to evaluate the breakpoint condition.
3426 The argument is a "struct expression *" that has been cast to char * to
3427 make it pass through catch_errors. */
3430 breakpoint_cond_eval (void *exp
)
3432 struct value
*mark
= value_mark ();
3433 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3435 value_free_to_mark (mark
);
3439 /* Allocate a new bpstat and chain it to the current one. */
3442 bpstat_alloc (struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3446 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3448 bs
->breakpoint_at
= bl
->owner
;
3449 bs
->bp_location_at
= bl
;
3450 incref_bp_location (bl
);
3451 /* If the condition is false, etc., don't do the commands. */
3452 bs
->commands
= NULL
;
3453 bs
->commands_left
= NULL
;
3455 bs
->print_it
= print_it_normal
;
3459 /* The target has stopped with waitstatus WS. Check if any hardware
3460 watchpoints have triggered, according to the target. */
3463 watchpoints_triggered (struct target_waitstatus
*ws
)
3465 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3467 struct breakpoint
*b
;
3469 if (!stopped_by_watchpoint
)
3471 /* We were not stopped by a watchpoint. Mark all watchpoints
3472 as not triggered. */
3474 if (is_hardware_watchpoint (b
))
3475 b
->watchpoint_triggered
= watch_triggered_no
;
3480 if (!target_stopped_data_address (¤t_target
, &addr
))
3482 /* We were stopped by a watchpoint, but we don't know where.
3483 Mark all watchpoints as unknown. */
3485 if (is_hardware_watchpoint (b
))
3486 b
->watchpoint_triggered
= watch_triggered_unknown
;
3488 return stopped_by_watchpoint
;
3491 /* The target could report the data address. Mark watchpoints
3492 affected by this data address as triggered, and all others as not
3496 if (is_hardware_watchpoint (b
))
3498 struct bp_location
*loc
;
3500 b
->watchpoint_triggered
= watch_triggered_no
;
3501 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3502 /* Exact match not required. Within range is
3504 if (target_watchpoint_addr_within_range (¤t_target
,
3508 b
->watchpoint_triggered
= watch_triggered_yes
;
3516 /* Possible return values for watchpoint_check (this can't be an enum
3517 because of check_errors). */
3518 /* The watchpoint has been deleted. */
3519 #define WP_DELETED 1
3520 /* The value has changed. */
3521 #define WP_VALUE_CHANGED 2
3522 /* The value has not changed. */
3523 #define WP_VALUE_NOT_CHANGED 3
3524 /* Ignore this watchpoint, no matter if the value changed or not. */
3527 #define BP_TEMPFLAG 1
3528 #define BP_HARDWAREFLAG 2
3530 /* Evaluate watchpoint condition expression and check if its value changed.
3532 P should be a pointer to struct bpstat, but is defined as a void *
3533 in order for this function to be usable with catch_errors. */
3536 watchpoint_check (void *p
)
3538 bpstat bs
= (bpstat
) p
;
3539 struct breakpoint
*b
;
3540 struct frame_info
*fr
;
3541 int within_current_scope
;
3543 /* BS is built from an existing struct breakpoint. */
3544 gdb_assert (bs
->breakpoint_at
!= NULL
);
3545 b
= bs
->breakpoint_at
;
3547 /* If this is a local watchpoint, we only want to check if the
3548 watchpoint frame is in scope if the current thread is the thread
3549 that was used to create the watchpoint. */
3550 if (!watchpoint_in_thread_scope (b
))
3553 if (b
->exp_valid_block
== NULL
)
3554 within_current_scope
= 1;
3557 struct frame_info
*frame
= get_current_frame ();
3558 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3559 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3561 /* in_function_epilogue_p() returns a non-zero value if we're still
3562 in the function but the stack frame has already been invalidated.
3563 Since we can't rely on the values of local variables after the
3564 stack has been destroyed, we are treating the watchpoint in that
3565 state as `not changed' without further checking. Don't mark
3566 watchpoints as changed if the current frame is in an epilogue -
3567 even if they are in some other frame, our view of the stack
3568 is likely to be wrong and frame_find_by_id could error out. */
3569 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3572 fr
= frame_find_by_id (b
->watchpoint_frame
);
3573 within_current_scope
= (fr
!= NULL
);
3575 /* If we've gotten confused in the unwinder, we might have
3576 returned a frame that can't describe this variable. */
3577 if (within_current_scope
)
3579 struct symbol
*function
;
3581 function
= get_frame_function (fr
);
3582 if (function
== NULL
3583 || !contained_in (b
->exp_valid_block
,
3584 SYMBOL_BLOCK_VALUE (function
)))
3585 within_current_scope
= 0;
3588 if (within_current_scope
)
3589 /* If we end up stopping, the current frame will get selected
3590 in normal_stop. So this call to select_frame won't affect
3595 if (within_current_scope
)
3597 /* We use value_{,free_to_}mark because it could be a
3598 *long* time before we return to the command level and
3599 call free_all_values. We can't call free_all_values because
3600 we might be in the middle of evaluating a function call. */
3603 struct value
*mark
= value_mark ();
3604 struct value
*new_val
;
3606 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3608 /* We use value_equal_contents instead of value_equal because the latter
3609 coerces an array to a pointer, thus comparing just the address of the
3610 array instead of its contents. This is not what we want. */
3611 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3612 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3614 if (new_val
!= NULL
)
3616 release_value (new_val
);
3617 value_free_to_mark (mark
);
3619 bs
->old_val
= b
->val
;
3622 return WP_VALUE_CHANGED
;
3626 /* Nothing changed. */
3627 value_free_to_mark (mark
);
3628 return WP_VALUE_NOT_CHANGED
;
3633 /* This seems like the only logical thing to do because
3634 if we temporarily ignored the watchpoint, then when
3635 we reenter the block in which it is valid it contains
3636 garbage (in the case of a function, it may have two
3637 garbage values, one before and one after the prologue).
3638 So we can't even detect the first assignment to it and
3639 watch after that (since the garbage may or may not equal
3640 the first value assigned). */
3641 /* We print all the stop information in print_it_typical(), but
3642 in this case, by the time we call print_it_typical() this bp
3643 will be deleted already. So we have no choice but print the
3644 information here. */
3645 if (ui_out_is_mi_like_p (uiout
))
3647 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3648 ui_out_text (uiout
, "\nWatchpoint ");
3649 ui_out_field_int (uiout
, "wpnum", b
->number
);
3650 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3651 which its expression is valid.\n");
3653 if (b
->related_breakpoint
)
3655 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3656 b
->related_breakpoint
->related_breakpoint
= NULL
;
3657 b
->related_breakpoint
= NULL
;
3659 b
->disposition
= disp_del_at_next_stop
;
3665 /* Return true if it looks like target has stopped due to hitting
3666 breakpoint location BL. This function does not check if we
3667 should stop, only if BL explains the stop. */
3669 bpstat_check_location (const struct bp_location
*bl
,
3670 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3672 struct breakpoint
*b
= bl
->owner
;
3674 /* BL is from existing struct breakpoint. */
3675 gdb_assert (b
!= NULL
);
3677 /* By definition, the inferior does not report stops at
3679 if (is_tracepoint (b
))
3682 if (!is_watchpoint (b
)
3683 && b
->type
!= bp_hardware_breakpoint
3684 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3686 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3689 if (overlay_debugging
/* unmapped overlay section */
3690 && section_is_overlay (bl
->section
)
3691 && !section_is_mapped (bl
->section
))
3695 /* Continuable hardware watchpoints are treated as non-existent if the
3696 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3697 some data address). Otherwise gdb won't stop on a break instruction
3698 in the code (not from a breakpoint) when a hardware watchpoint has
3699 been defined. Also skip watchpoints which we know did not trigger
3700 (did not match the data address). */
3702 if (is_hardware_watchpoint (b
)
3703 && b
->watchpoint_triggered
== watch_triggered_no
)
3706 if (b
->type
== bp_hardware_breakpoint
)
3708 if (bl
->address
!= bp_addr
)
3710 if (overlay_debugging
/* unmapped overlay section */
3711 && section_is_overlay (bl
->section
)
3712 && !section_is_mapped (bl
->section
))
3716 if (b
->type
== bp_catchpoint
)
3718 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3719 if (!b
->ops
->breakpoint_hit (b
))
3726 /* If BS refers to a watchpoint, determine if the watched values
3727 has actually changed, and we should stop. If not, set BS->stop
3730 bpstat_check_watchpoint (bpstat bs
)
3732 const struct bp_location
*bl
;
3733 struct breakpoint
*b
;
3735 /* BS is built for existing struct breakpoint. */
3736 bl
= bs
->bp_location_at
;
3737 gdb_assert (bl
!= NULL
);
3738 b
= bs
->breakpoint_at
;
3739 gdb_assert (b
!= NULL
);
3741 if (is_watchpoint (b
))
3743 int must_check_value
= 0;
3745 if (b
->type
== bp_watchpoint
)
3746 /* For a software watchpoint, we must always check the
3748 must_check_value
= 1;
3749 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3750 /* We have a hardware watchpoint (read, write, or access)
3751 and the target earlier reported an address watched by
3753 must_check_value
= 1;
3754 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3755 && b
->type
== bp_hardware_watchpoint
)
3756 /* We were stopped by a hardware watchpoint, but the target could
3757 not report the data address. We must check the watchpoint's
3758 value. Access and read watchpoints are out of luck; without
3759 a data address, we can't figure it out. */
3760 must_check_value
= 1;
3762 if (must_check_value
)
3764 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3766 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3767 int e
= catch_errors (watchpoint_check
, bs
, message
,
3769 do_cleanups (cleanups
);
3773 /* We've already printed what needs to be printed. */
3774 bs
->print_it
= print_it_done
;
3778 bs
->print_it
= print_it_noop
;
3781 case WP_VALUE_CHANGED
:
3782 if (b
->type
== bp_read_watchpoint
)
3784 /* There are two cases to consider here:
3786 1. we're watching the triggered memory for reads.
3787 In that case, trust the target, and always report
3788 the watchpoint hit to the user. Even though
3789 reads don't cause value changes, the value may
3790 have changed since the last time it was read, and
3791 since we're not trapping writes, we will not see
3792 those, and as such we should ignore our notion of
3795 2. we're watching the triggered memory for both
3796 reads and writes. There are two ways this may
3799 2.1. this is a target that can't break on data
3800 reads only, but can break on accesses (reads or
3801 writes), such as e.g., x86. We detect this case
3802 at the time we try to insert read watchpoints.
3804 2.2. otherwise, the target supports read
3805 watchpoints, but, the user set an access or write
3806 watchpoint watching the same memory as this read
3809 If we're watching memory writes as well as reads,
3810 ignore watchpoint hits when we find that the
3811 value hasn't changed, as reads don't cause
3812 changes. This still gives false positives when
3813 the program writes the same value to memory as
3814 what there was already in memory (we will confuse
3815 it for a read), but it's much better than
3818 int other_write_watchpoint
= 0;
3820 if (bl
->watchpoint_type
== hw_read
)
3822 struct breakpoint
*other_b
;
3824 ALL_BREAKPOINTS (other_b
)
3825 if ((other_b
->type
== bp_hardware_watchpoint
3826 || other_b
->type
== bp_access_watchpoint
)
3827 && (other_b
->watchpoint_triggered
3828 == watch_triggered_yes
))
3830 other_write_watchpoint
= 1;
3835 if (other_write_watchpoint
3836 || bl
->watchpoint_type
== hw_access
)
3838 /* We're watching the same memory for writes,
3839 and the value changed since the last time we
3840 updated it, so this trap must be for a write.
3842 bs
->print_it
= print_it_noop
;
3847 case WP_VALUE_NOT_CHANGED
:
3848 if (b
->type
== bp_hardware_watchpoint
3849 || b
->type
== bp_watchpoint
)
3851 /* Don't stop: write watchpoints shouldn't fire if
3852 the value hasn't changed. */
3853 bs
->print_it
= print_it_noop
;
3861 /* Error from catch_errors. */
3862 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3863 if (b
->related_breakpoint
)
3864 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3865 b
->disposition
= disp_del_at_next_stop
;
3866 /* We've already printed what needs to be printed. */
3867 bs
->print_it
= print_it_done
;
3871 else /* must_check_value == 0 */
3873 /* This is a case where some watchpoint(s) triggered, but
3874 not at the address of this watchpoint, or else no
3875 watchpoint triggered after all. So don't print
3876 anything for this watchpoint. */
3877 bs
->print_it
= print_it_noop
;
3884 /* Check conditions (condition proper, frame, thread and ignore count)
3885 of breakpoint referred to by BS. If we should not stop for this
3886 breakpoint, set BS->stop to 0. */
3889 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3891 int thread_id
= pid_to_thread_id (ptid
);
3892 const struct bp_location
*bl
;
3893 struct breakpoint
*b
;
3895 /* BS is built for existing struct breakpoint. */
3896 bl
= bs
->bp_location_at
;
3897 gdb_assert (bl
!= NULL
);
3898 b
= bs
->breakpoint_at
;
3899 gdb_assert (b
!= NULL
);
3901 if (frame_id_p (b
->frame_id
)
3902 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3906 int value_is_zero
= 0;
3907 struct expression
*cond
;
3909 if (is_watchpoint (b
))
3914 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3916 int within_current_scope
= 1;
3918 /* We use value_mark and value_free_to_mark because it could
3919 be a long time before we return to the command level and
3920 call free_all_values. We can't call free_all_values
3921 because we might be in the middle of evaluating a
3923 struct value
*mark
= value_mark ();
3925 /* Need to select the frame, with all that implies so that
3926 the conditions will have the right context. Because we
3927 use the frame, we will not see an inlined function's
3928 variables when we arrive at a breakpoint at the start
3929 of the inlined function; the current frame will be the
3931 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3932 select_frame (get_current_frame ());
3935 struct frame_info
*frame
;
3937 /* For local watchpoint expressions, which particular
3938 instance of a local is being watched matters, so we
3939 keep track of the frame to evaluate the expression
3940 in. To evaluate the condition however, it doesn't
3941 really matter which instantiation of the function
3942 where the condition makes sense triggers the
3943 watchpoint. This allows an expression like "watch
3944 global if q > 10" set in `func', catch writes to
3945 global on all threads that call `func', or catch
3946 writes on all recursive calls of `func' by a single
3947 thread. We simply always evaluate the condition in
3948 the innermost frame that's executing where it makes
3949 sense to evaluate the condition. It seems
3951 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3953 select_frame (frame
);
3955 within_current_scope
= 0;
3957 if (within_current_scope
)
3959 = catch_errors (breakpoint_cond_eval
, cond
,
3960 "Error in testing breakpoint condition:\n",
3964 warning (_("Watchpoint condition cannot be tested "
3965 "in the current scope"));
3966 /* If we failed to set the right context for this
3967 watchpoint, unconditionally report it. */
3970 /* FIXME-someday, should give breakpoint # */
3971 value_free_to_mark (mark
);
3974 if (cond
&& value_is_zero
)
3978 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3982 else if (b
->ignore_count
> 0)
3985 annotate_ignore_count_change ();
3987 /* Increase the hit count even though we don't
3995 /* Get a bpstat associated with having just stopped at address
3996 BP_ADDR in thread PTID.
3998 Determine whether we stopped at a breakpoint, etc, or whether we
3999 don't understand this stop. Result is a chain of bpstat's such that:
4001 if we don't understand the stop, the result is a null pointer.
4003 if we understand why we stopped, the result is not null.
4005 Each element of the chain refers to a particular breakpoint or
4006 watchpoint at which we have stopped. (We may have stopped for
4007 several reasons concurrently.)
4009 Each element of the chain has valid next, breakpoint_at,
4010 commands, FIXME??? fields. */
4013 bpstat_stop_status (struct address_space
*aspace
,
4014 CORE_ADDR bp_addr
, ptid_t ptid
)
4016 struct breakpoint
*b
= NULL
;
4017 struct bp_location
*bl
;
4018 struct bp_location
*loc
;
4019 /* Root of the chain of bpstat's */
4020 struct bpstats root_bs
[1];
4021 /* Pointer to the last thing in the chain currently. */
4022 bpstat bs
= root_bs
;
4024 int need_remove_insert
;
4027 /* First, build the bpstat chain with locations that explain a
4028 target stop, while being careful to not set the target running,
4029 as that may invalidate locations (in particular watchpoint
4030 locations are recreated). Resuming will happen here with
4031 breakpoint conditions or watchpoint expressions that include
4032 inferior function calls. */
4036 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4039 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4041 /* For hardware watchpoints, we look only at the first location.
4042 The watchpoint_check function will work on the entire expression,
4043 not the individual locations. For read watchpoints, the
4044 watchpoints_triggered function has checked all locations
4046 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4049 if (bl
->shlib_disabled
)
4052 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4055 /* Come here if it's a watchpoint, or if the break address matches */
4057 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4059 /* Assume we stop. Should we find a watchpoint that is not
4060 actually triggered, or if the condition of the breakpoint
4061 evaluates as false, we'll reset 'stop' to 0. */
4065 /* If this is a scope breakpoint, mark the associated
4066 watchpoint as triggered so that we will handle the
4067 out-of-scope event. We'll get to the watchpoint next
4069 if (b
->type
== bp_watchpoint_scope
)
4070 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4074 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4076 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4079 bs
= bpstat_alloc (loc
, bs
);
4080 /* For hits of moribund locations, we should just proceed. */
4083 bs
->print_it
= print_it_noop
;
4087 /* Terminate the chain. */
4090 /* Now go through the locations that caused the target to stop, and
4091 check whether we're interested in reporting this stop to higher
4092 layers, or whether we should resume the target transparently. */
4096 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4101 bpstat_check_watchpoint (bs
);
4105 b
= bs
->breakpoint_at
;
4107 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4108 || b
->type
== bp_longjmp_master
4109 || b
->type
== bp_std_terminate_master
)
4110 /* We do not stop for these. */
4113 bpstat_check_breakpoint_conditions (bs
, ptid
);
4119 /* We will stop here */
4120 if (b
->disposition
== disp_disable
)
4122 if (b
->enable_state
!= bp_permanent
)
4123 b
->enable_state
= bp_disabled
;
4128 bs
->commands
= b
->commands
;
4129 incref_counted_command_line (bs
->commands
);
4130 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4131 if (bs
->commands_left
4132 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4135 bs
->commands_left
->line
) == 0)))
4137 bs
->commands_left
= bs
->commands_left
->next
;
4142 /* Print nothing for this entry if we dont stop or dont print. */
4143 if (bs
->stop
== 0 || bs
->print
== 0)
4144 bs
->print_it
= print_it_noop
;
4147 /* If we aren't stopping, the value of some hardware watchpoint may
4148 not have changed, but the intermediate memory locations we are
4149 watching may have. Don't bother if we're stopping; this will get
4151 need_remove_insert
= 0;
4152 if (! bpstat_causes_stop (root_bs
->next
))
4153 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4155 && bs
->breakpoint_at
4156 && is_hardware_watchpoint (bs
->breakpoint_at
))
4158 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4159 need_remove_insert
= 1;
4162 if (need_remove_insert
)
4163 update_global_location_list (1);
4164 else if (removed_any
)
4165 update_global_location_list (0);
4167 return root_bs
->next
;
4171 handle_jit_event (void)
4173 struct frame_info
*frame
;
4174 struct gdbarch
*gdbarch
;
4176 /* Switch terminal for any messages produced by
4177 breakpoint_re_set. */
4178 target_terminal_ours_for_output ();
4180 frame
= get_current_frame ();
4181 gdbarch
= get_frame_arch (frame
);
4183 jit_event_handler (gdbarch
);
4185 target_terminal_inferior ();
4188 /* Prepare WHAT final decision for infrun. */
4190 /* Decide what infrun needs to do with this bpstat. */
4193 bpstat_what (bpstat bs
)
4195 struct bpstat_what retval
;
4196 /* We need to defer calling `solib_add', as adding new symbols
4197 resets breakpoints, which in turn deletes breakpoint locations,
4198 and hence may clear unprocessed entries in the BS chain. */
4199 int shlib_event
= 0;
4202 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4203 retval
.call_dummy
= STOP_NONE
;
4205 for (; bs
!= NULL
; bs
= bs
->next
)
4207 /* Extract this BS's action. After processing each BS, we check
4208 if its action overrides all we've seem so far. */
4209 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4212 if (bs
->breakpoint_at
== NULL
)
4214 /* I suspect this can happen if it was a momentary
4215 breakpoint which has since been deleted. */
4218 else if (bs
->breakpoint_at
== NULL
)
4221 bptype
= bs
->breakpoint_at
->type
;
4228 case bp_hardware_breakpoint
:
4234 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4236 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4239 this_action
= BPSTAT_WHAT_SINGLE
;
4242 case bp_hardware_watchpoint
:
4243 case bp_read_watchpoint
:
4244 case bp_access_watchpoint
:
4248 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4250 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4254 /* There was a watchpoint, but we're not stopping.
4255 This requires no further action. */
4259 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4261 case bp_longjmp_resume
:
4262 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4264 case bp_step_resume
:
4266 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4269 /* It is for the wrong frame. */
4270 this_action
= BPSTAT_WHAT_SINGLE
;
4273 case bp_watchpoint_scope
:
4274 case bp_thread_event
:
4275 case bp_overlay_event
:
4276 case bp_longjmp_master
:
4277 case bp_std_terminate_master
:
4278 this_action
= BPSTAT_WHAT_SINGLE
;
4284 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4286 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4290 /* There was a catchpoint, but we're not stopping.
4291 This requires no further action. */
4294 case bp_shlib_event
:
4297 /* If requested, stop when the dynamic linker notifies GDB
4298 of events. This allows the user to get control and place
4299 breakpoints in initializer routines for dynamically
4300 loaded objects (among other things). */
4301 if (stop_on_solib_events
)
4302 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4304 this_action
= BPSTAT_WHAT_SINGLE
;
4308 this_action
= BPSTAT_WHAT_SINGLE
;
4311 /* Make sure the action is stop (silent or noisy),
4312 so infrun.c pops the dummy frame. */
4313 retval
.call_dummy
= STOP_STACK_DUMMY
;
4314 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4316 case bp_std_terminate
:
4317 /* Make sure the action is stop (silent or noisy),
4318 so infrun.c pops the dummy frame. */
4319 retval
.call_dummy
= STOP_STD_TERMINATE
;
4320 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4323 case bp_fast_tracepoint
:
4324 case bp_static_tracepoint
:
4325 /* Tracepoint hits should not be reported back to GDB, and
4326 if one got through somehow, it should have been filtered
4328 internal_error (__FILE__
, __LINE__
,
4329 _("bpstat_what: tracepoint encountered"));
4331 internal_error (__FILE__
, __LINE__
,
4332 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4335 retval
.main_action
= max (retval
.main_action
, this_action
);
4341 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4343 /* Check for any newly added shared libraries if we're supposed
4344 to be adding them automatically. */
4346 /* Switch terminal for any messages produced by
4347 breakpoint_re_set. */
4348 target_terminal_ours_for_output ();
4351 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4353 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4356 target_terminal_inferior ();
4362 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4364 handle_jit_event ();
4370 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4371 without hardware support). This isn't related to a specific bpstat,
4372 just to things like whether watchpoints are set. */
4375 bpstat_should_step (void)
4377 struct breakpoint
*b
;
4380 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4386 bpstat_causes_stop (bpstat bs
)
4388 for (; bs
!= NULL
; bs
= bs
->next
)
4397 /* Print the LOC location out of the list of B->LOC locations. */
4399 static void print_breakpoint_location (struct breakpoint
*b
,
4400 struct bp_location
*loc
,
4402 struct ui_stream
*stb
)
4404 struct cleanup
*old_chain
= save_current_program_space ();
4406 if (loc
!= NULL
&& loc
->shlib_disabled
)
4410 set_current_program_space (loc
->pspace
);
4412 if (b
->source_file
&& loc
)
4415 = find_pc_sect_function (loc
->address
, loc
->section
);
4418 ui_out_text (uiout
, "in ");
4419 ui_out_field_string (uiout
, "func",
4420 SYMBOL_PRINT_NAME (sym
));
4421 ui_out_wrap_hint (uiout
, wrap_indent
);
4422 ui_out_text (uiout
, " at ");
4424 ui_out_field_string (uiout
, "file", b
->source_file
);
4425 ui_out_text (uiout
, ":");
4427 if (ui_out_is_mi_like_p (uiout
))
4429 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4430 char *fullname
= symtab_to_fullname (sal
.symtab
);
4433 ui_out_field_string (uiout
, "fullname", fullname
);
4436 ui_out_field_int (uiout
, "line", b
->line_number
);
4440 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4442 ui_out_field_stream (uiout
, "at", stb
);
4445 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4447 do_cleanups (old_chain
);
4451 bptype_string (enum bptype type
)
4453 struct ep_type_description
4458 static struct ep_type_description bptypes
[] =
4460 {bp_none
, "?deleted?"},
4461 {bp_breakpoint
, "breakpoint"},
4462 {bp_hardware_breakpoint
, "hw breakpoint"},
4463 {bp_until
, "until"},
4464 {bp_finish
, "finish"},
4465 {bp_watchpoint
, "watchpoint"},
4466 {bp_hardware_watchpoint
, "hw watchpoint"},
4467 {bp_read_watchpoint
, "read watchpoint"},
4468 {bp_access_watchpoint
, "acc watchpoint"},
4469 {bp_longjmp
, "longjmp"},
4470 {bp_longjmp_resume
, "longjmp resume"},
4471 {bp_step_resume
, "step resume"},
4472 {bp_watchpoint_scope
, "watchpoint scope"},
4473 {bp_call_dummy
, "call dummy"},
4474 {bp_std_terminate
, "std::terminate"},
4475 {bp_shlib_event
, "shlib events"},
4476 {bp_thread_event
, "thread events"},
4477 {bp_overlay_event
, "overlay events"},
4478 {bp_longjmp_master
, "longjmp master"},
4479 {bp_std_terminate_master
, "std::terminate master"},
4480 {bp_catchpoint
, "catchpoint"},
4481 {bp_tracepoint
, "tracepoint"},
4482 {bp_fast_tracepoint
, "fast tracepoint"},
4483 {bp_static_tracepoint
, "static tracepoint"},
4484 {bp_jit_event
, "jit events"},
4487 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4488 || ((int) type
!= bptypes
[(int) type
].type
))
4489 internal_error (__FILE__
, __LINE__
,
4490 _("bptypes table does not describe type #%d."),
4493 return bptypes
[(int) type
].description
;
4496 /* Print B to gdb_stdout. */
4499 print_one_breakpoint_location (struct breakpoint
*b
,
4500 struct bp_location
*loc
,
4502 struct bp_location
**last_loc
,
4503 int print_address_bits
,
4506 struct command_line
*l
;
4507 static char bpenables
[] = "nynny";
4508 char wrap_indent
[80];
4509 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4510 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4511 struct cleanup
*bkpt_chain
;
4513 int header_of_multiple
= 0;
4514 int part_of_multiple
= (loc
!= NULL
);
4515 struct value_print_options opts
;
4517 get_user_print_options (&opts
);
4519 gdb_assert (!loc
|| loc_number
!= 0);
4520 /* See comment in print_one_breakpoint concerning
4521 treatment of breakpoints with single disabled
4525 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4526 header_of_multiple
= 1;
4531 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4535 if (part_of_multiple
)
4538 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4539 ui_out_field_string (uiout
, "number", formatted
);
4544 ui_out_field_int (uiout
, "number", b
->number
);
4549 if (part_of_multiple
)
4550 ui_out_field_skip (uiout
, "type");
4552 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4556 if (part_of_multiple
)
4557 ui_out_field_skip (uiout
, "disp");
4559 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4564 if (part_of_multiple
)
4565 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4567 ui_out_field_fmt (uiout
, "enabled", "%c",
4568 bpenables
[(int) b
->enable_state
]);
4569 ui_out_spaces (uiout
, 2);
4573 strcpy (wrap_indent
, " ");
4574 if (opts
.addressprint
)
4576 if (print_address_bits
<= 32)
4577 strcat (wrap_indent
, " ");
4579 strcat (wrap_indent
, " ");
4582 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4584 /* Although the print_one can possibly print
4585 all locations, calling it here is not likely
4586 to get any nice result. So, make sure there's
4587 just one location. */
4588 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4589 b
->ops
->print_one (b
, last_loc
);
4595 internal_error (__FILE__
, __LINE__
,
4596 _("print_one_breakpoint: bp_none encountered\n"));
4600 case bp_hardware_watchpoint
:
4601 case bp_read_watchpoint
:
4602 case bp_access_watchpoint
:
4603 /* Field 4, the address, is omitted (which makes the columns
4604 not line up too nicely with the headers, but the effect
4605 is relatively readable). */
4606 if (opts
.addressprint
)
4607 ui_out_field_skip (uiout
, "addr");
4609 ui_out_field_string (uiout
, "what", b
->exp_string
);
4613 case bp_hardware_breakpoint
:
4617 case bp_longjmp_resume
:
4618 case bp_step_resume
:
4619 case bp_watchpoint_scope
:
4621 case bp_std_terminate
:
4622 case bp_shlib_event
:
4623 case bp_thread_event
:
4624 case bp_overlay_event
:
4625 case bp_longjmp_master
:
4626 case bp_std_terminate_master
:
4628 case bp_fast_tracepoint
:
4629 case bp_static_tracepoint
:
4631 if (opts
.addressprint
)
4634 if (header_of_multiple
)
4635 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4636 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4637 ui_out_field_string (uiout
, "addr", "<PENDING>");
4639 ui_out_field_core_addr (uiout
, "addr",
4640 loc
->gdbarch
, loc
->address
);
4643 if (!header_of_multiple
)
4644 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4651 /* For backward compatibility, don't display inferiors unless there
4654 && !header_of_multiple
4656 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4657 && (number_of_program_spaces () > 1
4658 || number_of_inferiors () > 1)
4659 /* LOC is for existing B, it cannot be in moribund_locations and
4660 thus having NULL OWNER. */
4661 && loc
->owner
->type
!= bp_catchpoint
)))
4663 struct inferior
*inf
;
4666 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4668 if (inf
->pspace
== loc
->pspace
)
4673 ui_out_text (uiout
, " inf ");
4676 ui_out_text (uiout
, ", ");
4677 ui_out_text (uiout
, plongest (inf
->num
));
4682 if (!part_of_multiple
)
4684 if (b
->thread
!= -1)
4686 /* FIXME: This seems to be redundant and lost here; see the
4687 "stop only in" line a little further down. */
4688 ui_out_text (uiout
, " thread ");
4689 ui_out_field_int (uiout
, "thread", b
->thread
);
4691 else if (b
->task
!= 0)
4693 ui_out_text (uiout
, " task ");
4694 ui_out_field_int (uiout
, "task", b
->task
);
4698 ui_out_text (uiout
, "\n");
4700 if (!part_of_multiple
&& b
->static_trace_marker_id
)
4702 gdb_assert (b
->type
== bp_static_tracepoint
);
4704 ui_out_text (uiout
, "\tmarker id is ");
4705 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
4706 b
->static_trace_marker_id
);
4707 ui_out_text (uiout
, "\n");
4710 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4713 ui_out_text (uiout
, "\tstop only in stack frame at ");
4714 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4716 ui_out_field_core_addr (uiout
, "frame",
4717 b
->gdbarch
, b
->frame_id
.stack_addr
);
4718 ui_out_text (uiout
, "\n");
4721 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4723 /* We do not print the condition for Ada exception catchpoints
4724 because the condition is an internal implementation detail
4725 that we do not want to expose to the user. */
4727 if (is_tracepoint (b
))
4728 ui_out_text (uiout
, "\ttrace only if ");
4730 ui_out_text (uiout
, "\tstop only if ");
4731 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4732 ui_out_text (uiout
, "\n");
4735 if (!part_of_multiple
&& b
->thread
!= -1)
4737 /* FIXME should make an annotation for this */
4738 ui_out_text (uiout
, "\tstop only in thread ");
4739 ui_out_field_int (uiout
, "thread", b
->thread
);
4740 ui_out_text (uiout
, "\n");
4743 if (!part_of_multiple
&& b
->hit_count
)
4745 /* FIXME should make an annotation for this */
4746 if (ep_is_catchpoint (b
))
4747 ui_out_text (uiout
, "\tcatchpoint");
4749 ui_out_text (uiout
, "\tbreakpoint");
4750 ui_out_text (uiout
, " already hit ");
4751 ui_out_field_int (uiout
, "times", b
->hit_count
);
4752 if (b
->hit_count
== 1)
4753 ui_out_text (uiout
, " time\n");
4755 ui_out_text (uiout
, " times\n");
4758 /* Output the count also if it is zero, but only if this is
4759 mi. FIXME: Should have a better test for this. */
4760 if (ui_out_is_mi_like_p (uiout
))
4761 if (!part_of_multiple
&& b
->hit_count
== 0)
4762 ui_out_field_int (uiout
, "times", b
->hit_count
);
4764 if (!part_of_multiple
&& b
->ignore_count
)
4767 ui_out_text (uiout
, "\tignore next ");
4768 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4769 ui_out_text (uiout
, " hits\n");
4772 l
= b
->commands
? b
->commands
->commands
: NULL
;
4773 if (!part_of_multiple
&& l
)
4775 struct cleanup
*script_chain
;
4778 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4779 print_command_lines (uiout
, l
, 4);
4780 do_cleanups (script_chain
);
4783 if (!part_of_multiple
&& b
->pass_count
)
4785 annotate_field (10);
4786 ui_out_text (uiout
, "\tpass count ");
4787 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4788 ui_out_text (uiout
, " \n");
4791 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4794 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4795 else if (b
->exp_string
)
4796 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4799 do_cleanups (bkpt_chain
);
4800 do_cleanups (old_chain
);
4804 print_one_breakpoint (struct breakpoint
*b
,
4805 struct bp_location
**last_loc
, int print_address_bits
,
4808 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4809 print_address_bits
, allflag
);
4811 /* If this breakpoint has custom print function,
4812 it's already printed. Otherwise, print individual
4813 locations, if any. */
4814 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4816 /* If breakpoint has a single location that is
4817 disabled, we print it as if it had
4818 several locations, since otherwise it's hard to
4819 represent "breakpoint enabled, location disabled"
4821 Note that while hardware watchpoints have
4822 several locations internally, that's no a property
4825 && !is_hardware_watchpoint (b
)
4826 && (b
->loc
->next
|| !b
->loc
->enabled
)
4827 && !ui_out_is_mi_like_p (uiout
))
4829 struct bp_location
*loc
;
4831 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4832 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4833 print_address_bits
, allflag
);
4839 breakpoint_address_bits (struct breakpoint
*b
)
4841 int print_address_bits
= 0;
4842 struct bp_location
*loc
;
4844 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4848 /* Software watchpoints that aren't watching memory don't have
4849 an address to print. */
4850 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4853 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4854 if (addr_bit
> print_address_bits
)
4855 print_address_bits
= addr_bit
;
4858 return print_address_bits
;
4861 struct captured_breakpoint_query_args
4867 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4869 struct captured_breakpoint_query_args
*args
= data
;
4870 struct breakpoint
*b
;
4871 struct bp_location
*dummy_loc
= NULL
;
4875 if (args
->bnum
== b
->number
)
4877 int print_address_bits
= breakpoint_address_bits (b
);
4879 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4887 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4889 struct captured_breakpoint_query_args args
;
4892 /* For the moment we don't trust print_one_breakpoint() to not throw
4894 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4895 error_message
, RETURN_MASK_ALL
) < 0)
4901 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4902 catchpoints, et.al.). */
4905 user_settable_breakpoint (const struct breakpoint
*b
)
4907 return (b
->type
== bp_breakpoint
4908 || b
->type
== bp_catchpoint
4909 || b
->type
== bp_hardware_breakpoint
4910 || is_tracepoint (b
)
4911 || is_watchpoint (b
));
4914 /* Print information on user settable breakpoint (watchpoint, etc)
4915 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4916 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4917 FILTER is non-NULL, call it on each breakpoint and only include the
4918 ones for which it returns non-zero. Return the total number of
4919 breakpoints listed. */
4922 breakpoint_1 (int bnum
, int allflag
, int (*filter
) (const struct breakpoint
*))
4924 struct breakpoint
*b
;
4925 struct bp_location
*last_loc
= NULL
;
4926 int nr_printable_breakpoints
;
4927 struct cleanup
*bkpttbl_chain
;
4928 struct value_print_options opts
;
4929 int print_address_bits
= 0;
4930 int print_type_col_width
= 14;
4932 get_user_print_options (&opts
);
4934 /* Compute the number of rows in the table, as well as the
4935 size required for address fields. */
4936 nr_printable_breakpoints
= 0;
4939 || bnum
== b
->number
)
4941 /* If we have a filter, only list the breakpoints it accepts. */
4942 if (filter
&& !filter (b
))
4945 if (allflag
|| user_settable_breakpoint (b
))
4947 int addr_bit
, type_len
;
4949 addr_bit
= breakpoint_address_bits (b
);
4950 if (addr_bit
> print_address_bits
)
4951 print_address_bits
= addr_bit
;
4953 type_len
= strlen (bptype_string (b
->type
));
4954 if (type_len
> print_type_col_width
)
4955 print_type_col_width
= type_len
;
4957 nr_printable_breakpoints
++;
4961 if (opts
.addressprint
)
4963 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4967 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4970 if (nr_printable_breakpoints
> 0)
4971 annotate_breakpoints_headers ();
4972 if (nr_printable_breakpoints
> 0)
4974 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4975 if (nr_printable_breakpoints
> 0)
4977 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
4978 "type", "Type"); /* 2 */
4979 if (nr_printable_breakpoints
> 0)
4981 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4982 if (nr_printable_breakpoints
> 0)
4984 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4985 if (opts
.addressprint
)
4987 if (nr_printable_breakpoints
> 0)
4989 if (print_address_bits
<= 32)
4990 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4992 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4994 if (nr_printable_breakpoints
> 0)
4996 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4997 ui_out_table_body (uiout
);
4998 if (nr_printable_breakpoints
> 0)
4999 annotate_breakpoints_table ();
5005 || bnum
== b
->number
)
5007 /* If we have a filter, only list the breakpoints it accepts. */
5008 if (filter
&& !filter (b
))
5011 /* We only print out user settable breakpoints unless the
5013 if (allflag
|| user_settable_breakpoint (b
))
5014 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5018 do_cleanups (bkpttbl_chain
);
5020 if (nr_printable_breakpoints
== 0)
5022 /* If there's a filter, let the caller decide how to report empty list. */
5026 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5028 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5034 if (last_loc
&& !server_command
)
5035 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5038 /* FIXME? Should this be moved up so that it is only called when
5039 there have been breakpoints? */
5040 annotate_breakpoints_table_end ();
5042 return nr_printable_breakpoints
;
5045 /* Display the value of default-collect in a way that is generally
5046 compatible with the breakpoint list. */
5049 default_collect_info (void)
5051 /* If it has no value (which is frequently the case), say nothing; a
5052 message like "No default-collect." gets in user's face when it's
5054 if (!*default_collect
)
5057 /* The following phrase lines up nicely with per-tracepoint collect
5059 ui_out_text (uiout
, "default collect ");
5060 ui_out_field_string (uiout
, "default-collect", default_collect
);
5061 ui_out_text (uiout
, " \n");
5065 breakpoints_info (char *bnum_exp
, int from_tty
)
5070 bnum
= parse_and_eval_long (bnum_exp
);
5072 breakpoint_1 (bnum
, 0, NULL
);
5074 default_collect_info ();
5078 watchpoints_info (char *wpnum_exp
, int from_tty
)
5080 int wpnum
= -1, num_printed
;
5083 wpnum
= parse_and_eval_long (wpnum_exp
);
5085 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5087 if (num_printed
== 0)
5090 ui_out_message (uiout
, 0, "No watchpoints.\n");
5092 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5097 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5102 bnum
= parse_and_eval_long (bnum_exp
);
5104 breakpoint_1 (bnum
, 1, NULL
);
5106 default_collect_info ();
5110 breakpoint_has_pc (struct breakpoint
*b
,
5111 struct program_space
*pspace
,
5112 CORE_ADDR pc
, struct obj_section
*section
)
5114 struct bp_location
*bl
= b
->loc
;
5116 for (; bl
; bl
= bl
->next
)
5118 if (bl
->pspace
== pspace
5119 && bl
->address
== pc
5120 && (!overlay_debugging
|| bl
->section
== section
))
5126 /* Print a message describing any breakpoints set at PC. This
5127 concerns with logical breakpoints, so we match program spaces, not
5131 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5132 struct program_space
*pspace
, CORE_ADDR pc
,
5133 struct obj_section
*section
, int thread
)
5136 struct breakpoint
*b
;
5139 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5143 printf_filtered (_("Note: breakpoint "));
5144 else /* if (others == ???) */
5145 printf_filtered (_("Note: breakpoints "));
5147 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5150 printf_filtered ("%d", b
->number
);
5151 if (b
->thread
== -1 && thread
!= -1)
5152 printf_filtered (" (all threads)");
5153 else if (b
->thread
!= -1)
5154 printf_filtered (" (thread %d)", b
->thread
);
5155 printf_filtered ("%s%s ",
5156 ((b
->enable_state
== bp_disabled
5157 || b
->enable_state
== bp_call_disabled
5158 || b
->enable_state
== bp_startup_disabled
)
5160 : b
->enable_state
== bp_permanent
5164 : ((others
== 1) ? " and" : ""));
5166 printf_filtered (_("also set at pc "));
5167 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5168 printf_filtered (".\n");
5172 /* Set the default place to put a breakpoint
5173 for the `break' command with no arguments. */
5176 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5177 CORE_ADDR addr
, struct symtab
*symtab
,
5180 default_breakpoint_valid
= valid
;
5181 default_breakpoint_pspace
= pspace
;
5182 default_breakpoint_address
= addr
;
5183 default_breakpoint_symtab
= symtab
;
5184 default_breakpoint_line
= line
;
5187 /* Return true iff it is meaningful to use the address member of
5188 BPT. For some breakpoint types, the address member is irrelevant
5189 and it makes no sense to attempt to compare it to other addresses
5190 (or use it for any other purpose either).
5192 More specifically, each of the following breakpoint types will always
5193 have a zero valued address and we don't want to mark breakpoints of any of
5194 these types to be a duplicate of an actual breakpoint at address zero:
5202 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5204 enum bptype type
= bpt
->type
;
5206 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5209 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5210 true if LOC1 and LOC2 represent the same watchpoint location. */
5213 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5215 /* Both of them must not be in moribund_locations. */
5216 gdb_assert (loc1
->owner
!= NULL
);
5217 gdb_assert (loc2
->owner
!= NULL
);
5219 /* If the target can evaluate the condition expression in hardware, then we
5220 we need to insert both watchpoints even if they are at the same place.
5221 Otherwise the watchpoint will only trigger when the condition of whichever
5222 watchpoint was inserted evaluates to true, not giving a chance for GDB to
5223 check the condition of the other watchpoint. */
5224 if ((loc1
->owner
->cond_exp
5225 && target_can_accel_watchpoint_condition (loc1
->address
, loc1
->length
,
5226 loc1
->watchpoint_type
,
5227 loc1
->owner
->cond_exp
))
5228 || (loc2
->owner
->cond_exp
5229 && target_can_accel_watchpoint_condition (loc2
->address
, loc2
->length
,
5230 loc2
->watchpoint_type
,
5231 loc2
->owner
->cond_exp
)))
5234 /* Note that this checks the owner's type, not the location's. In
5235 case the target does not support read watchpoints, but does
5236 support access watchpoints, we'll have bp_read_watchpoint
5237 watchpoints with hw_access locations. Those should be considered
5238 duplicates of hw_read locations. The hw_read locations will
5239 become hw_access locations later. */
5240 return (loc1
->owner
->type
== loc2
->owner
->type
5241 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5242 && loc1
->address
== loc2
->address
5243 && loc1
->length
== loc2
->length
);
5246 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5247 same breakpoint location. In most targets, this can only be true
5248 if ASPACE1 matches ASPACE2. On targets that have global
5249 breakpoints, the address space doesn't really matter. */
5252 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5253 struct address_space
*aspace2
, CORE_ADDR addr2
)
5255 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5256 || aspace1
== aspace2
)
5260 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5261 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5262 represent the same location. */
5265 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5267 int hw_point1
, hw_point2
;
5269 /* Both of them must not be in moribund_locations. */
5270 gdb_assert (loc1
->owner
!= NULL
);
5271 gdb_assert (loc2
->owner
!= NULL
);
5273 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5274 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5276 if (hw_point1
!= hw_point2
)
5279 return watchpoint_locations_match (loc1
, loc2
);
5281 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5282 loc2
->pspace
->aspace
, loc2
->address
);
5286 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5287 int bnum
, int have_bnum
)
5292 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5293 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5295 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5296 bnum
, astr1
, astr2
);
5298 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5301 /* Adjust a breakpoint's address to account for architectural constraints
5302 on breakpoint placement. Return the adjusted address. Note: Very
5303 few targets require this kind of adjustment. For most targets,
5304 this function is simply the identity function. */
5307 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5308 CORE_ADDR bpaddr
, enum bptype bptype
)
5310 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5312 /* Very few targets need any kind of breakpoint adjustment. */
5315 else if (bptype
== bp_watchpoint
5316 || bptype
== bp_hardware_watchpoint
5317 || bptype
== bp_read_watchpoint
5318 || bptype
== bp_access_watchpoint
5319 || bptype
== bp_catchpoint
)
5321 /* Watchpoints and the various bp_catch_* eventpoints should not
5322 have their addresses modified. */
5327 CORE_ADDR adjusted_bpaddr
;
5329 /* Some targets have architectural constraints on the placement
5330 of breakpoint instructions. Obtain the adjusted address. */
5331 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5333 /* An adjusted breakpoint address can significantly alter
5334 a user's expectations. Print a warning if an adjustment
5336 if (adjusted_bpaddr
!= bpaddr
)
5337 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5339 return adjusted_bpaddr
;
5343 /* Allocate a struct bp_location. */
5345 static struct bp_location
*
5346 allocate_bp_location (struct breakpoint
*bpt
)
5348 struct bp_location
*loc
;
5350 loc
= xmalloc (sizeof (struct bp_location
));
5351 memset (loc
, 0, sizeof (*loc
));
5355 loc
->shlib_disabled
= 0;
5364 case bp_longjmp_resume
:
5365 case bp_step_resume
:
5366 case bp_watchpoint_scope
:
5368 case bp_std_terminate
:
5369 case bp_shlib_event
:
5370 case bp_thread_event
:
5371 case bp_overlay_event
:
5373 case bp_longjmp_master
:
5374 case bp_std_terminate_master
:
5375 loc
->loc_type
= bp_loc_software_breakpoint
;
5377 case bp_hardware_breakpoint
:
5378 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5380 case bp_hardware_watchpoint
:
5381 case bp_read_watchpoint
:
5382 case bp_access_watchpoint
:
5383 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5388 case bp_fast_tracepoint
:
5389 case bp_static_tracepoint
:
5390 loc
->loc_type
= bp_loc_other
;
5393 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5401 free_bp_location (struct bp_location
*loc
)
5406 if (loc
->function_name
)
5407 xfree (loc
->function_name
);
5412 /* Increment reference count. */
5415 incref_bp_location (struct bp_location
*bl
)
5420 /* Decrement reference count. If the reference count reaches 0,
5421 destroy the bp_location. Sets *BLP to NULL. */
5424 decref_bp_location (struct bp_location
**blp
)
5426 gdb_assert ((*blp
)->refc
> 0);
5428 if (--(*blp
)->refc
== 0)
5429 free_bp_location (*blp
);
5433 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5434 that has type BPTYPE and has no locations as yet. */
5435 /* This function is used in gdbtk sources and thus can not be made static. */
5437 static struct breakpoint
*
5438 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5441 struct breakpoint
*b
, *b1
;
5443 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5444 memset (b
, 0, sizeof (*b
));
5447 b
->gdbarch
= gdbarch
;
5448 b
->language
= current_language
->la_language
;
5449 b
->input_radix
= input_radix
;
5451 b
->enable_state
= bp_enabled
;
5454 b
->ignore_count
= 0;
5456 b
->frame_id
= null_frame_id
;
5457 b
->forked_inferior_pid
= null_ptid
;
5458 b
->exec_pathname
= NULL
;
5459 b
->syscalls_to_be_caught
= NULL
;
5461 b
->condition_not_parsed
= 0;
5463 /* Add this breakpoint to the end of the chain
5464 so that a list of breakpoints will come out in order
5465 of increasing numbers. */
5467 b1
= breakpoint_chain
;
5469 breakpoint_chain
= b
;
5479 /* Initialize loc->function_name. */
5481 set_breakpoint_location_function (struct bp_location
*loc
)
5483 gdb_assert (loc
->owner
!= NULL
);
5485 if (loc
->owner
->type
== bp_breakpoint
5486 || loc
->owner
->type
== bp_hardware_breakpoint
5487 || is_tracepoint (loc
->owner
))
5489 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5491 if (loc
->function_name
)
5492 loc
->function_name
= xstrdup (loc
->function_name
);
5496 /* Attempt to determine architecture of location identified by SAL. */
5497 static struct gdbarch
*
5498 get_sal_arch (struct symtab_and_line sal
)
5501 return get_objfile_arch (sal
.section
->objfile
);
5503 return get_objfile_arch (sal
.symtab
->objfile
);
5508 /* set_raw_breakpoint is a low level routine for allocating and
5509 partially initializing a breakpoint of type BPTYPE. The newly
5510 created breakpoint's address, section, source file name, and line
5511 number are provided by SAL. The newly created and partially
5512 initialized breakpoint is added to the breakpoint chain and
5513 is also returned as the value of this function.
5515 It is expected that the caller will complete the initialization of
5516 the newly created breakpoint struct as well as output any status
5517 information regarding the creation of a new breakpoint. In
5518 particular, set_raw_breakpoint does NOT set the breakpoint
5519 number! Care should be taken to not allow an error to occur
5520 prior to completing the initialization of the breakpoint. If this
5521 should happen, a bogus breakpoint will be left on the chain. */
5524 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5525 struct symtab_and_line sal
, enum bptype bptype
)
5527 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5528 CORE_ADDR adjusted_address
;
5529 struct gdbarch
*loc_gdbarch
;
5531 loc_gdbarch
= get_sal_arch (sal
);
5533 loc_gdbarch
= b
->gdbarch
;
5535 if (bptype
!= bp_catchpoint
)
5536 gdb_assert (sal
.pspace
!= NULL
);
5538 /* Adjust the breakpoint's address prior to allocating a location.
5539 Once we call allocate_bp_location(), that mostly uninitialized
5540 location will be placed on the location chain. Adjustment of the
5541 breakpoint may cause target_read_memory() to be called and we do
5542 not want its scan of the location chain to find a breakpoint and
5543 location that's only been partially initialized. */
5544 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5546 b
->loc
= allocate_bp_location (b
);
5547 b
->loc
->gdbarch
= loc_gdbarch
;
5548 b
->loc
->requested_address
= sal
.pc
;
5549 b
->loc
->address
= adjusted_address
;
5550 b
->loc
->pspace
= sal
.pspace
;
5552 /* Store the program space that was used to set the breakpoint, for
5553 breakpoint resetting. */
5554 b
->pspace
= sal
.pspace
;
5556 if (sal
.symtab
== NULL
)
5557 b
->source_file
= NULL
;
5559 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5560 b
->loc
->section
= sal
.section
;
5561 b
->line_number
= sal
.line
;
5563 set_breakpoint_location_function (b
->loc
);
5565 breakpoints_changed ();
5571 /* Note that the breakpoint object B describes a permanent breakpoint
5572 instruction, hard-wired into the inferior's code. */
5574 make_breakpoint_permanent (struct breakpoint
*b
)
5576 struct bp_location
*bl
;
5578 b
->enable_state
= bp_permanent
;
5580 /* By definition, permanent breakpoints are already present in the code.
5581 Mark all locations as inserted. For now, make_breakpoint_permanent
5582 is called in just one place, so it's hard to say if it's reasonable
5583 to have permanent breakpoint with multiple locations or not,
5584 but it's easy to implmement. */
5585 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5589 /* Call this routine when stepping and nexting to enable a breakpoint
5590 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5591 set_longjmp_resume_breakpoint() to figure out where we are going. */
5594 set_longjmp_breakpoint (int thread
)
5596 struct breakpoint
*b
, *temp
;
5598 /* To avoid having to rescan all objfile symbols at every step,
5599 we maintain a list of continually-inserted but always disabled
5600 longjmp "master" breakpoints. Here, we simply create momentary
5601 clones of those and enable them for the requested thread. */
5602 ALL_BREAKPOINTS_SAFE (b
, temp
)
5603 if (b
->pspace
== current_program_space
5604 && b
->type
== bp_longjmp_master
)
5606 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5608 clone
->type
= bp_longjmp
;
5609 clone
->thread
= thread
;
5613 /* Delete all longjmp breakpoints from THREAD. */
5615 delete_longjmp_breakpoint (int thread
)
5617 struct breakpoint
*b
, *temp
;
5619 ALL_BREAKPOINTS_SAFE (b
, temp
)
5620 if (b
->type
== bp_longjmp
)
5622 if (b
->thread
== thread
)
5623 delete_breakpoint (b
);
5628 enable_overlay_breakpoints (void)
5630 struct breakpoint
*b
;
5633 if (b
->type
== bp_overlay_event
)
5635 b
->enable_state
= bp_enabled
;
5636 update_global_location_list (1);
5637 overlay_events_enabled
= 1;
5642 disable_overlay_breakpoints (void)
5644 struct breakpoint
*b
;
5647 if (b
->type
== bp_overlay_event
)
5649 b
->enable_state
= bp_disabled
;
5650 update_global_location_list (0);
5651 overlay_events_enabled
= 0;
5655 /* Set an active std::terminate breakpoint for each std::terminate
5656 master breakpoint. */
5658 set_std_terminate_breakpoint (void)
5660 struct breakpoint
*b
, *temp
;
5662 ALL_BREAKPOINTS_SAFE (b
, temp
)
5663 if (b
->pspace
== current_program_space
5664 && b
->type
== bp_std_terminate_master
)
5666 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5667 clone
->type
= bp_std_terminate
;
5671 /* Delete all the std::terminate breakpoints. */
5673 delete_std_terminate_breakpoint (void)
5675 struct breakpoint
*b
, *temp
;
5677 ALL_BREAKPOINTS_SAFE (b
, temp
)
5678 if (b
->type
== bp_std_terminate
)
5679 delete_breakpoint (b
);
5683 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5685 struct breakpoint
*b
;
5687 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5689 b
->enable_state
= bp_enabled
;
5690 /* addr_string has to be used or breakpoint_re_set will delete me. */
5692 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5694 update_global_location_list_nothrow (1);
5700 remove_thread_event_breakpoints (void)
5702 struct breakpoint
*b
, *temp
;
5704 ALL_BREAKPOINTS_SAFE (b
, temp
)
5705 if (b
->type
== bp_thread_event
5706 && b
->loc
->pspace
== current_program_space
)
5707 delete_breakpoint (b
);
5710 struct captured_parse_breakpoint_args
5713 struct symtabs_and_lines
*sals_p
;
5714 char ***addr_string_p
;
5718 struct lang_and_radix
5724 /* Create a breakpoint for JIT code registration and unregistration. */
5727 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5729 struct breakpoint
*b
;
5731 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5732 update_global_location_list_nothrow (1);
5737 remove_solib_event_breakpoints (void)
5739 struct breakpoint
*b
, *temp
;
5741 ALL_BREAKPOINTS_SAFE (b
, temp
)
5742 if (b
->type
== bp_shlib_event
5743 && b
->loc
->pspace
== current_program_space
)
5744 delete_breakpoint (b
);
5748 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5750 struct breakpoint
*b
;
5752 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5753 update_global_location_list_nothrow (1);
5757 /* Disable any breakpoints that are on code in shared libraries. Only
5758 apply to enabled breakpoints, disabled ones can just stay disabled. */
5761 disable_breakpoints_in_shlibs (void)
5763 struct bp_location
*loc
, **locp_tmp
;
5765 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5767 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5768 struct breakpoint
*b
= loc
->owner
;
5770 /* We apply the check to all breakpoints, including disabled
5771 for those with loc->duplicate set. This is so that when breakpoint
5772 becomes enabled, or the duplicate is removed, gdb will try to insert
5773 all breakpoints. If we don't set shlib_disabled here, we'll try
5774 to insert those breakpoints and fail. */
5775 if (((b
->type
== bp_breakpoint
)
5776 || (b
->type
== bp_jit_event
)
5777 || (b
->type
== bp_hardware_breakpoint
)
5778 || (is_tracepoint (b
)))
5779 && loc
->pspace
== current_program_space
5780 && !loc
->shlib_disabled
5782 && PC_SOLIB (loc
->address
)
5784 && solib_name_from_address (loc
->pspace
, loc
->address
)
5788 loc
->shlib_disabled
= 1;
5793 /* Disable any breakpoints that are in in an unloaded shared library. Only
5794 apply to enabled breakpoints, disabled ones can just stay disabled. */
5797 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5799 struct bp_location
*loc
, **locp_tmp
;
5800 int disabled_shlib_breaks
= 0;
5802 /* SunOS a.out shared libraries are always mapped, so do not
5803 disable breakpoints; they will only be reported as unloaded
5804 through clear_solib when GDB discards its shared library
5805 list. See clear_solib for more information. */
5806 if (exec_bfd
!= NULL
5807 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5810 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5812 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5813 struct breakpoint
*b
= loc
->owner
;
5815 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5816 || loc
->loc_type
== bp_loc_software_breakpoint
)
5817 && solib
->pspace
== loc
->pspace
5818 && !loc
->shlib_disabled
5819 && (b
->type
== bp_breakpoint
5820 || b
->type
== bp_jit_event
5821 || b
->type
== bp_hardware_breakpoint
)
5822 && solib_contains_address_p (solib
, loc
->address
))
5824 loc
->shlib_disabled
= 1;
5825 /* At this point, we cannot rely on remove_breakpoint
5826 succeeding so we must mark the breakpoint as not inserted
5827 to prevent future errors occurring in remove_breakpoints. */
5829 if (!disabled_shlib_breaks
)
5831 target_terminal_ours_for_output ();
5832 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5835 disabled_shlib_breaks
= 1;
5840 /* FORK & VFORK catchpoints. */
5842 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5845 insert_catch_fork (struct breakpoint
*b
)
5847 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5850 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5853 remove_catch_fork (struct breakpoint
*b
)
5855 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5858 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5862 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5864 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5867 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5869 static enum print_stop_action
5870 print_it_catch_fork (struct breakpoint
*b
)
5872 annotate_catchpoint (b
->number
);
5873 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5874 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5875 return PRINT_SRC_AND_LOC
;
5878 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5881 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5883 struct value_print_options opts
;
5885 get_user_print_options (&opts
);
5887 /* Field 4, the address, is omitted (which makes the columns
5888 not line up too nicely with the headers, but the effect
5889 is relatively readable). */
5890 if (opts
.addressprint
)
5891 ui_out_field_skip (uiout
, "addr");
5893 ui_out_text (uiout
, "fork");
5894 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5896 ui_out_text (uiout
, ", process ");
5897 ui_out_field_int (uiout
, "what",
5898 ptid_get_pid (b
->forked_inferior_pid
));
5899 ui_out_spaces (uiout
, 1);
5903 /* Implement the "print_mention" breakpoint_ops method for fork
5907 print_mention_catch_fork (struct breakpoint
*b
)
5909 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5912 /* Implement the "print_recreate" breakpoint_ops method for fork
5916 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
5918 fprintf_unfiltered (fp
, "catch fork");
5921 /* The breakpoint_ops structure to be used in fork catchpoints. */
5923 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5927 breakpoint_hit_catch_fork
,
5928 print_it_catch_fork
,
5929 print_one_catch_fork
,
5930 print_mention_catch_fork
,
5931 print_recreate_catch_fork
5934 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5937 insert_catch_vfork (struct breakpoint
*b
)
5939 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5942 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5945 remove_catch_vfork (struct breakpoint
*b
)
5947 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5950 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5954 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5956 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5959 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5961 static enum print_stop_action
5962 print_it_catch_vfork (struct breakpoint
*b
)
5964 annotate_catchpoint (b
->number
);
5965 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5966 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5967 return PRINT_SRC_AND_LOC
;
5970 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5973 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5975 struct value_print_options opts
;
5977 get_user_print_options (&opts
);
5978 /* Field 4, the address, is omitted (which makes the columns
5979 not line up too nicely with the headers, but the effect
5980 is relatively readable). */
5981 if (opts
.addressprint
)
5982 ui_out_field_skip (uiout
, "addr");
5984 ui_out_text (uiout
, "vfork");
5985 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5987 ui_out_text (uiout
, ", process ");
5988 ui_out_field_int (uiout
, "what",
5989 ptid_get_pid (b
->forked_inferior_pid
));
5990 ui_out_spaces (uiout
, 1);
5994 /* Implement the "print_mention" breakpoint_ops method for vfork
5998 print_mention_catch_vfork (struct breakpoint
*b
)
6000 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6003 /* Implement the "print_recreate" breakpoint_ops method for vfork
6007 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6009 fprintf_unfiltered (fp
, "catch vfork");
6012 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6014 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6018 breakpoint_hit_catch_vfork
,
6019 print_it_catch_vfork
,
6020 print_one_catch_vfork
,
6021 print_mention_catch_vfork
,
6022 print_recreate_catch_vfork
6025 /* Implement the "insert" breakpoint_ops method for syscall
6029 insert_catch_syscall (struct breakpoint
*b
)
6031 struct inferior
*inf
= current_inferior ();
6033 ++inf
->total_syscalls_count
;
6034 if (!b
->syscalls_to_be_caught
)
6035 ++inf
->any_syscall_count
;
6041 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6046 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6048 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6049 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
6051 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6052 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6054 memset ((void *) vec_addr
, 0,
6055 (iter
+ 1 - old_size
) * sizeof (int));
6057 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6058 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6062 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6063 inf
->total_syscalls_count
!= 0,
6064 inf
->any_syscall_count
,
6065 VEC_length (int, inf
->syscalls_counts
),
6066 VEC_address (int, inf
->syscalls_counts
));
6069 /* Implement the "remove" breakpoint_ops method for syscall
6073 remove_catch_syscall (struct breakpoint
*b
)
6075 struct inferior
*inf
= current_inferior ();
6077 --inf
->total_syscalls_count
;
6078 if (!b
->syscalls_to_be_caught
)
6079 --inf
->any_syscall_count
;
6085 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6089 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6090 /* Shouldn't happen. */
6092 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6093 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6097 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6098 inf
->total_syscalls_count
!= 0,
6099 inf
->any_syscall_count
,
6100 VEC_length (int, inf
->syscalls_counts
),
6101 VEC_address (int, inf
->syscalls_counts
));
6104 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6108 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6110 /* We must check if we are catching specific syscalls in this breakpoint.
6111 If we are, then we must guarantee that the called syscall is the same
6112 syscall we are catching. */
6113 int syscall_number
= 0;
6115 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6118 /* Now, checking if the syscall is the same. */
6119 if (b
->syscalls_to_be_caught
)
6124 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6126 if (syscall_number
== iter
)
6136 /* Implement the "print_it" breakpoint_ops method for syscall
6139 static enum print_stop_action
6140 print_it_catch_syscall (struct breakpoint
*b
)
6142 /* These are needed because we want to know in which state a
6143 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6144 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6145 must print "called syscall" or "returned from syscall". */
6147 struct target_waitstatus last
;
6149 struct cleanup
*old_chain
;
6152 get_last_target_status (&ptid
, &last
);
6154 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6156 annotate_catchpoint (b
->number
);
6159 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6161 syscall_id
= xstrprintf ("'%s'", s
.name
);
6163 old_chain
= make_cleanup (xfree
, syscall_id
);
6165 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6166 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6167 b
->number
, syscall_id
);
6168 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6169 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6170 b
->number
, syscall_id
);
6172 do_cleanups (old_chain
);
6174 return PRINT_SRC_AND_LOC
;
6177 /* Implement the "print_one" breakpoint_ops method for syscall
6181 print_one_catch_syscall (struct breakpoint
*b
,
6182 struct bp_location
**last_loc
)
6184 struct value_print_options opts
;
6186 get_user_print_options (&opts
);
6187 /* Field 4, the address, is omitted (which makes the columns
6188 not line up too nicely with the headers, but the effect
6189 is relatively readable). */
6190 if (opts
.addressprint
)
6191 ui_out_field_skip (uiout
, "addr");
6194 if (b
->syscalls_to_be_caught
6195 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6196 ui_out_text (uiout
, "syscalls \"");
6198 ui_out_text (uiout
, "syscall \"");
6200 if (b
->syscalls_to_be_caught
)
6203 char *text
= xstrprintf ("%s", "");
6206 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6211 get_syscall_by_number (iter
, &s
);
6214 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6216 text
= xstrprintf ("%s%d, ", text
, iter
);
6218 /* We have to xfree the last 'text' (now stored at 'x')
6219 because xstrprintf dinamically allocates new space for it
6223 /* Remove the last comma. */
6224 text
[strlen (text
) - 2] = '\0';
6225 ui_out_field_string (uiout
, "what", text
);
6228 ui_out_field_string (uiout
, "what", "<any syscall>");
6229 ui_out_text (uiout
, "\" ");
6232 /* Implement the "print_mention" breakpoint_ops method for syscall
6236 print_mention_catch_syscall (struct breakpoint
*b
)
6238 if (b
->syscalls_to_be_caught
)
6242 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6243 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6245 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6248 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6252 get_syscall_by_number (iter
, &s
);
6255 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6257 printf_filtered (" %d", s
.number
);
6259 printf_filtered (")");
6262 printf_filtered (_("Catchpoint %d (any syscall)"),
6266 /* Implement the "print_recreate" breakpoint_ops method for syscall
6270 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6272 fprintf_unfiltered (fp
, "catch syscall");
6274 if (b
->syscalls_to_be_caught
)
6279 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6284 get_syscall_by_number (iter
, &s
);
6286 fprintf_unfiltered (fp
, " %s", s
.name
);
6288 fprintf_unfiltered (fp
, " %d", s
.number
);
6293 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6295 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6297 insert_catch_syscall
,
6298 remove_catch_syscall
,
6299 breakpoint_hit_catch_syscall
,
6300 print_it_catch_syscall
,
6301 print_one_catch_syscall
,
6302 print_mention_catch_syscall
,
6303 print_recreate_catch_syscall
6306 /* Returns non-zero if 'b' is a syscall catchpoint. */
6309 syscall_catchpoint_p (struct breakpoint
*b
)
6311 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6314 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6315 but does NOT mention it nor update the global location list.
6316 This is useful if you need to fill more fields in the
6317 struct breakpoint before calling mention.
6319 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6320 If COND_STRING is not NULL, then store it in the breakpoint.
6321 OPS, if not NULL, is the breakpoint_ops structure associated
6322 to the catchpoint. */
6324 static struct breakpoint
*
6325 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6327 struct breakpoint_ops
*ops
)
6329 struct symtab_and_line sal
;
6330 struct breakpoint
*b
;
6333 sal
.pspace
= current_program_space
;
6335 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6336 set_breakpoint_count (breakpoint_count
+ 1);
6337 b
->number
= breakpoint_count
;
6339 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6341 b
->addr_string
= NULL
;
6342 b
->enable_state
= bp_enabled
;
6343 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6349 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6351 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6352 If COND_STRING is not NULL, then store it in the breakpoint.
6353 OPS, if not NULL, is the breakpoint_ops structure associated
6354 to the catchpoint. */
6356 static struct breakpoint
*
6357 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6358 char *cond_string
, struct breakpoint_ops
*ops
)
6360 struct breakpoint
*b
=
6361 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6364 update_global_location_list (1);
6370 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6371 int tempflag
, char *cond_string
,
6372 struct breakpoint_ops
*ops
)
6374 struct breakpoint
*b
6375 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6377 /* FIXME: We should put this information in a breakpoint private data
6379 b
->forked_inferior_pid
= null_ptid
;
6382 /* Exec catchpoints. */
6385 insert_catch_exec (struct breakpoint
*b
)
6387 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6391 remove_catch_exec (struct breakpoint
*b
)
6393 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6397 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6399 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6402 static enum print_stop_action
6403 print_it_catch_exec (struct breakpoint
*b
)
6405 annotate_catchpoint (b
->number
);
6406 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6408 return PRINT_SRC_AND_LOC
;
6412 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6414 struct value_print_options opts
;
6416 get_user_print_options (&opts
);
6418 /* Field 4, the address, is omitted (which makes the columns
6419 not line up too nicely with the headers, but the effect
6420 is relatively readable). */
6421 if (opts
.addressprint
)
6422 ui_out_field_skip (uiout
, "addr");
6424 ui_out_text (uiout
, "exec");
6425 if (b
->exec_pathname
!= NULL
)
6427 ui_out_text (uiout
, ", program \"");
6428 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6429 ui_out_text (uiout
, "\" ");
6434 print_mention_catch_exec (struct breakpoint
*b
)
6436 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6439 /* Implement the "print_recreate" breakpoint_ops method for exec
6443 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6445 fprintf_unfiltered (fp
, "catch exec");
6448 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6452 breakpoint_hit_catch_exec
,
6453 print_it_catch_exec
,
6454 print_one_catch_exec
,
6455 print_mention_catch_exec
,
6456 print_recreate_catch_exec
6460 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6461 struct breakpoint_ops
*ops
)
6463 struct gdbarch
*gdbarch
= get_current_arch ();
6464 struct breakpoint
*b
=
6465 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6467 b
->syscalls_to_be_caught
= filter
;
6469 /* Now, we have to mention the breakpoint and update the global
6472 update_global_location_list (1);
6476 hw_breakpoint_used_count (void)
6478 struct breakpoint
*b
;
6483 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6491 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6493 struct breakpoint
*b
;
6496 *other_type_used
= 0;
6499 if (breakpoint_enabled (b
))
6501 if (b
->type
== type
)
6503 else if (is_hardware_watchpoint (b
))
6504 *other_type_used
= 1;
6511 disable_watchpoints_before_interactive_call_start (void)
6513 struct breakpoint
*b
;
6517 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6519 b
->enable_state
= bp_call_disabled
;
6520 update_global_location_list (0);
6526 enable_watchpoints_after_interactive_call_stop (void)
6528 struct breakpoint
*b
;
6532 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6534 b
->enable_state
= bp_enabled
;
6535 update_global_location_list (1);
6541 disable_breakpoints_before_startup (void)
6543 struct breakpoint
*b
;
6548 if (b
->pspace
!= current_program_space
)
6551 if ((b
->type
== bp_breakpoint
6552 || b
->type
== bp_hardware_breakpoint
)
6553 && breakpoint_enabled (b
))
6555 b
->enable_state
= bp_startup_disabled
;
6561 update_global_location_list (0);
6563 current_program_space
->executing_startup
= 1;
6567 enable_breakpoints_after_startup (void)
6569 struct breakpoint
*b
;
6572 current_program_space
->executing_startup
= 0;
6576 if (b
->pspace
!= current_program_space
)
6579 if ((b
->type
== bp_breakpoint
6580 || b
->type
== bp_hardware_breakpoint
)
6581 && b
->enable_state
== bp_startup_disabled
)
6583 b
->enable_state
= bp_enabled
;
6589 breakpoint_re_set ();
6593 /* Set a breakpoint that will evaporate an end of command
6594 at address specified by SAL.
6595 Restrict it to frame FRAME if FRAME is nonzero. */
6598 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6599 struct frame_id frame_id
, enum bptype type
)
6601 struct breakpoint
*b
;
6603 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6605 gdb_assert (!frame_id_inlined_p (frame_id
));
6607 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6608 b
->enable_state
= bp_enabled
;
6609 b
->disposition
= disp_donttouch
;
6610 b
->frame_id
= frame_id
;
6612 /* If we're debugging a multi-threaded program, then we
6613 want momentary breakpoints to be active in only a
6614 single thread of control. */
6615 if (in_thread_list (inferior_ptid
))
6616 b
->thread
= pid_to_thread_id (inferior_ptid
);
6618 update_global_location_list_nothrow (1);
6623 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6627 clone_momentary_breakpoint (struct breakpoint
*orig
)
6629 struct breakpoint
*copy
;
6631 /* If there's nothing to clone, then return nothing. */
6635 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6636 copy
->loc
= allocate_bp_location (copy
);
6637 set_breakpoint_location_function (copy
->loc
);
6639 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6640 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6641 copy
->loc
->address
= orig
->loc
->address
;
6642 copy
->loc
->section
= orig
->loc
->section
;
6643 copy
->loc
->pspace
= orig
->loc
->pspace
;
6645 if (orig
->source_file
== NULL
)
6646 copy
->source_file
= NULL
;
6648 copy
->source_file
= xstrdup (orig
->source_file
);
6650 copy
->line_number
= orig
->line_number
;
6651 copy
->frame_id
= orig
->frame_id
;
6652 copy
->thread
= orig
->thread
;
6653 copy
->pspace
= orig
->pspace
;
6655 copy
->enable_state
= bp_enabled
;
6656 copy
->disposition
= disp_donttouch
;
6657 copy
->number
= internal_breakpoint_number
--;
6659 update_global_location_list_nothrow (0);
6664 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6667 struct symtab_and_line sal
;
6669 sal
= find_pc_line (pc
, 0);
6671 sal
.section
= find_pc_overlay (pc
);
6672 sal
.explicit_pc
= 1;
6674 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6678 /* Tell the user we have just set a breakpoint B. */
6681 mention (struct breakpoint
*b
)
6684 struct cleanup
*ui_out_chain
;
6685 struct value_print_options opts
;
6687 get_user_print_options (&opts
);
6689 /* FIXME: This is misplaced; mention() is called by things (like
6690 hitting a watchpoint) other than breakpoint creation. It should
6691 be possible to clean this up and at the same time replace the
6692 random calls to breakpoint_changed with this hook. */
6693 observer_notify_breakpoint_created (b
->number
);
6695 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6696 b
->ops
->print_mention (b
);
6701 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6704 ui_out_text (uiout
, "Watchpoint ");
6705 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6706 ui_out_field_int (uiout
, "number", b
->number
);
6707 ui_out_text (uiout
, ": ");
6708 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6709 do_cleanups (ui_out_chain
);
6711 case bp_hardware_watchpoint
:
6712 ui_out_text (uiout
, "Hardware watchpoint ");
6713 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6714 ui_out_field_int (uiout
, "number", b
->number
);
6715 ui_out_text (uiout
, ": ");
6716 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6717 do_cleanups (ui_out_chain
);
6719 case bp_read_watchpoint
:
6720 ui_out_text (uiout
, "Hardware read watchpoint ");
6721 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6722 ui_out_field_int (uiout
, "number", b
->number
);
6723 ui_out_text (uiout
, ": ");
6724 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6725 do_cleanups (ui_out_chain
);
6727 case bp_access_watchpoint
:
6728 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6729 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6730 ui_out_field_int (uiout
, "number", b
->number
);
6731 ui_out_text (uiout
, ": ");
6732 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6733 do_cleanups (ui_out_chain
);
6736 if (ui_out_is_mi_like_p (uiout
))
6741 if (b
->disposition
== disp_del
)
6742 printf_filtered (_("Temporary breakpoint"));
6744 printf_filtered (_("Breakpoint"));
6745 printf_filtered (_(" %d"), b
->number
);
6748 case bp_hardware_breakpoint
:
6749 if (ui_out_is_mi_like_p (uiout
))
6754 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6758 if (ui_out_is_mi_like_p (uiout
))
6763 printf_filtered (_("Tracepoint"));
6764 printf_filtered (_(" %d"), b
->number
);
6767 case bp_fast_tracepoint
:
6768 if (ui_out_is_mi_like_p (uiout
))
6773 printf_filtered (_("Fast tracepoint"));
6774 printf_filtered (_(" %d"), b
->number
);
6777 case bp_static_tracepoint
:
6778 if (ui_out_is_mi_like_p (uiout
))
6783 printf_filtered (_("Static tracepoint"));
6784 printf_filtered (_(" %d"), b
->number
);
6791 case bp_longjmp_resume
:
6792 case bp_step_resume
:
6794 case bp_std_terminate
:
6795 case bp_watchpoint_scope
:
6796 case bp_shlib_event
:
6797 case bp_thread_event
:
6798 case bp_overlay_event
:
6800 case bp_longjmp_master
:
6801 case bp_std_terminate_master
:
6807 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6811 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6815 if (opts
.addressprint
|| b
->source_file
== NULL
)
6817 printf_filtered (" at ");
6818 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6822 printf_filtered (": file %s, line %d.",
6823 b
->source_file
, b
->line_number
);
6827 struct bp_location
*loc
= b
->loc
;
6829 for (; loc
; loc
= loc
->next
)
6831 printf_filtered (" (%d locations)", n
);
6836 if (ui_out_is_mi_like_p (uiout
))
6838 printf_filtered ("\n");
6842 static struct bp_location
*
6843 add_location_to_breakpoint (struct breakpoint
*b
,
6844 const struct symtab_and_line
*sal
)
6846 struct bp_location
*loc
, **tmp
;
6848 loc
= allocate_bp_location (b
);
6849 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6852 loc
->gdbarch
= get_sal_arch (*sal
);
6854 loc
->gdbarch
= b
->gdbarch
;
6855 loc
->requested_address
= sal
->pc
;
6856 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6857 loc
->requested_address
, b
->type
);
6858 loc
->pspace
= sal
->pspace
;
6859 gdb_assert (loc
->pspace
!= NULL
);
6860 loc
->section
= sal
->section
;
6862 set_breakpoint_location_function (loc
);
6867 /* Return 1 if LOC is pointing to a permanent breakpoint,
6868 return 0 otherwise. */
6871 bp_loc_is_permanent (struct bp_location
*loc
)
6875 const gdb_byte
*brk
;
6876 gdb_byte
*target_mem
;
6877 struct cleanup
*cleanup
;
6880 gdb_assert (loc
!= NULL
);
6882 addr
= loc
->address
;
6883 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6885 /* Software breakpoints unsupported? */
6889 target_mem
= alloca (len
);
6891 /* Enable the automatic memory restoration from breakpoints while
6892 we read the memory. Otherwise we could say about our temporary
6893 breakpoints they are permanent. */
6894 cleanup
= save_current_space_and_thread ();
6896 switch_to_program_space_and_thread (loc
->pspace
);
6897 make_show_memory_breakpoints_cleanup (0);
6899 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6900 && memcmp (target_mem
, brk
, len
) == 0)
6903 do_cleanups (cleanup
);
6910 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6911 as textual description of the location, and COND_STRING
6912 as condition expression. */
6915 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6916 struct symtabs_and_lines sals
, char *addr_string
,
6918 enum bptype type
, enum bpdisp disposition
,
6919 int thread
, int task
, int ignore_count
,
6920 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6922 struct breakpoint
*b
= NULL
;
6925 if (type
== bp_hardware_breakpoint
)
6927 int i
= hw_breakpoint_used_count ();
6928 int target_resources_ok
=
6929 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6931 if (target_resources_ok
== 0)
6932 error (_("No hardware breakpoint support in the target."));
6933 else if (target_resources_ok
< 0)
6934 error (_("Hardware breakpoints used exceeds limit."));
6937 gdb_assert (sals
.nelts
> 0);
6939 for (i
= 0; i
< sals
.nelts
; ++i
)
6941 struct symtab_and_line sal
= sals
.sals
[i
];
6942 struct bp_location
*loc
;
6946 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6948 loc_gdbarch
= gdbarch
;
6950 describe_other_breakpoints (loc_gdbarch
,
6951 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6956 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6957 set_breakpoint_count (breakpoint_count
+ 1);
6958 b
->number
= breakpoint_count
;
6962 b
->cond_string
= cond_string
;
6963 b
->ignore_count
= ignore_count
;
6964 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6965 b
->disposition
= disposition
;
6966 b
->pspace
= sals
.sals
[0].pspace
;
6968 if (type
== bp_static_tracepoint
)
6970 struct static_tracepoint_marker marker
;
6972 if (is_marker_spec (addr_string
))
6974 /* We already know the marker exists, otherwise, we
6975 wouldn't see a sal for it. */
6976 char *p
= &addr_string
[3];
6981 while (*p
== ' ' || *p
== '\t')
6985 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6988 marker_str
= savestring (p
, endp
- p
);
6989 b
->static_trace_marker_id
= marker_str
;
6991 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
6992 b
->static_trace_marker_id
);
6994 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
6996 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
6997 release_static_tracepoint_marker (&marker
);
6999 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
7000 b
->static_trace_marker_id
);
7004 Couldn't determine the static tracepoint marker to probe"));
7007 if (enabled
&& b
->pspace
->executing_startup
7008 && (b
->type
== bp_breakpoint
7009 || b
->type
== bp_hardware_breakpoint
))
7010 b
->enable_state
= bp_startup_disabled
;
7016 loc
= add_location_to_breakpoint (b
, &sal
);
7019 if (bp_loc_is_permanent (loc
))
7020 make_breakpoint_permanent (b
);
7024 char *arg
= b
->cond_string
;
7025 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7027 error (_("Garbage %s follows condition"), arg
);
7032 b
->addr_string
= addr_string
;
7034 /* addr_string has to be used or breakpoint_re_set will delete
7037 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7043 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7044 elements to fill the void space. */
7046 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7048 int i
= index_to_remove
+1;
7049 int last_index
= sal
->nelts
-1;
7051 for (;i
<= last_index
; ++i
)
7052 sal
->sals
[i
-1] = sal
->sals
[i
];
7057 /* If appropriate, obtains all sals that correspond to the same file
7058 and line as SAL, in all program spaces. Users debugging with IDEs,
7059 will want to set a breakpoint at foo.c:line, and not really care
7060 about program spaces. This is done only if SAL does not have
7061 explicit PC and has line and file information. If we got just a
7062 single expanded sal, return the original.
7064 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7065 which the name of enclosing function is different from SAL. This
7066 makes sure that if we have breakpoint originally set in template
7067 instantiation, say foo<int>(), we won't expand SAL to locations at
7068 the same line in all existing instantiations of 'foo'. */
7070 static struct symtabs_and_lines
7071 expand_line_sal_maybe (struct symtab_and_line sal
)
7073 struct symtabs_and_lines expanded
;
7074 CORE_ADDR original_pc
= sal
.pc
;
7075 char *original_function
= NULL
;
7078 struct cleanup
*old_chain
;
7080 /* If we have explicit pc, don't expand.
7081 If we have no line number, we can't expand. */
7082 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7085 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7086 expanded
.sals
[0] = sal
;
7092 old_chain
= save_current_space_and_thread ();
7094 switch_to_program_space_and_thread (sal
.pspace
);
7096 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7098 /* Note that expand_line_sal visits *all* program spaces. */
7099 expanded
= expand_line_sal (sal
);
7101 if (expanded
.nelts
== 1)
7103 /* We had one sal, we got one sal. Return that sal, adjusting it
7104 past the function prologue if necessary. */
7105 xfree (expanded
.sals
);
7107 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7108 sal
.pc
= original_pc
;
7109 expanded
.sals
[0] = sal
;
7110 skip_prologue_sal (&expanded
.sals
[0]);
7111 do_cleanups (old_chain
);
7115 if (!sal
.explicit_line
)
7117 CORE_ADDR func_addr
, func_end
;
7118 for (i
= 0; i
< expanded
.nelts
; ++i
)
7120 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7121 char *this_function
;
7123 /* We need to switch threads as well since we're about to
7125 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7127 if (find_pc_partial_function (pc
, &this_function
,
7128 &func_addr
, &func_end
))
7131 && strcmp (this_function
, original_function
) != 0)
7133 remove_sal (&expanded
, i
);
7140 /* Skip the function prologue if necessary. */
7141 for (i
= 0; i
< expanded
.nelts
; ++i
)
7142 skip_prologue_sal (&expanded
.sals
[i
]);
7144 do_cleanups (old_chain
);
7146 if (expanded
.nelts
<= 1)
7148 /* This is un ugly workaround. If we get zero
7149 expanded sals then something is really wrong.
7150 Fix that by returnign the original sal. */
7151 xfree (expanded
.sals
);
7153 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7154 sal
.pc
= original_pc
;
7155 expanded
.sals
[0] = sal
;
7162 for (i
= 0; i
< expanded
.nelts
; ++i
)
7163 if (expanded
.sals
[i
].pc
== original_pc
)
7174 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7175 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7176 value. COND_STRING, if not NULL, specified the condition to be
7177 used for all breakpoints. Essentially the only case where
7178 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7179 function. In that case, it's still not possible to specify
7180 separate conditions for different overloaded functions, so
7181 we take just a single condition string.
7183 NOTE: If the function succeeds, the caller is expected to cleanup
7184 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7185 array contents). If the function fails (error() is called), the
7186 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7187 COND and SALS arrays and each of those arrays contents. */
7190 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7191 struct symtabs_and_lines sals
, char **addr_string
,
7193 enum bptype type
, enum bpdisp disposition
,
7194 int thread
, int task
, int ignore_count
,
7195 struct breakpoint_ops
*ops
, int from_tty
,
7200 for (i
= 0; i
< sals
.nelts
; ++i
)
7202 struct symtabs_and_lines expanded
=
7203 expand_line_sal_maybe (sals
.sals
[i
]);
7205 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7206 cond_string
, type
, disposition
,
7207 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7211 /* Parse ARG which is assumed to be a SAL specification possibly
7212 followed by conditionals. On return, SALS contains an array of SAL
7213 addresses found. ADDR_STRING contains a vector of (canonical)
7214 address strings. ARG points to the end of the SAL. */
7217 parse_breakpoint_sals (char **address
,
7218 struct symtabs_and_lines
*sals
,
7219 char ***addr_string
,
7222 char *addr_start
= *address
;
7224 *addr_string
= NULL
;
7225 /* If no arg given, or if first arg is 'if ', use the default
7227 if ((*address
) == NULL
7228 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7230 if (default_breakpoint_valid
)
7232 struct symtab_and_line sal
;
7234 init_sal (&sal
); /* initialize to zeroes */
7235 sals
->sals
= (struct symtab_and_line
*)
7236 xmalloc (sizeof (struct symtab_and_line
));
7237 sal
.pc
= default_breakpoint_address
;
7238 sal
.line
= default_breakpoint_line
;
7239 sal
.symtab
= default_breakpoint_symtab
;
7240 sal
.pspace
= default_breakpoint_pspace
;
7241 sal
.section
= find_pc_overlay (sal
.pc
);
7243 /* "break" without arguments is equivalent to "break *PC" where PC is
7244 the default_breakpoint_address. So make sure to set
7245 sal.explicit_pc to prevent GDB from trying to expand the list of
7246 sals to include all other instances with the same symtab and line.
7248 sal
.explicit_pc
= 1;
7250 sals
->sals
[0] = sal
;
7254 error (_("No default breakpoint address now."));
7258 /* Force almost all breakpoints to be in terms of the
7259 current_source_symtab (which is decode_line_1's default). This
7260 should produce the results we want almost all of the time while
7261 leaving default_breakpoint_* alone.
7262 ObjC: However, don't match an Objective-C method name which
7263 may have a '+' or '-' succeeded by a '[' */
7265 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7267 if (default_breakpoint_valid
7269 || ((strchr ("+-", (*address
)[0]) != NULL
)
7270 && ((*address
)[1] != '['))))
7271 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7272 default_breakpoint_line
, addr_string
,
7275 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7276 addr_string
, not_found_ptr
);
7278 /* For any SAL that didn't have a canonical string, fill one in. */
7279 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7280 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7281 if (addr_start
!= (*address
))
7285 for (i
= 0; i
< sals
->nelts
; i
++)
7287 /* Add the string if not present. */
7288 if ((*addr_string
)[i
] == NULL
)
7289 (*addr_string
)[i
] = savestring (addr_start
,
7290 (*address
) - addr_start
);
7296 /* Convert each SAL into a real PC. Verify that the PC can be
7297 inserted as a breakpoint. If it can't throw an error. */
7300 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7304 for (i
= 0; i
< sals
->nelts
; i
++)
7305 resolve_sal_pc (&sals
->sals
[i
]);
7308 /* Fast tracepoints may have restrictions on valid locations. For
7309 instance, a fast tracepoint using a jump instead of a trap will
7310 likely have to overwrite more bytes than a trap would, and so can
7311 only be placed where the instruction is longer than the jump, or a
7312 multi-instruction sequence does not have a jump into the middle of
7316 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7317 struct symtabs_and_lines
*sals
)
7320 struct symtab_and_line
*sal
;
7322 struct cleanup
*old_chain
;
7324 for (i
= 0; i
< sals
->nelts
; i
++)
7326 sal
= &sals
->sals
[i
];
7328 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7330 old_chain
= make_cleanup (xfree
, msg
);
7333 error (_("May not have a fast tracepoint at 0x%s%s"),
7334 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7336 do_cleanups (old_chain
);
7341 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7343 struct captured_parse_breakpoint_args
*args
= data
;
7345 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7346 args
->not_found_ptr
);
7349 /* Given TOK, a string specification of condition and thread, as
7350 accepted by the 'break' command, extract the condition
7351 string and thread number and set *COND_STRING and *THREAD.
7352 PC identifies the context at which the condition should be parsed.
7353 If no condition is found, *COND_STRING is set to NULL.
7354 If no thread is found, *THREAD is set to -1. */
7356 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7357 char **cond_string
, int *thread
, int *task
)
7359 *cond_string
= NULL
;
7365 char *cond_start
= NULL
;
7366 char *cond_end
= NULL
;
7368 while (*tok
== ' ' || *tok
== '\t')
7373 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7376 toklen
= end_tok
- tok
;
7378 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7380 struct expression
*expr
;
7382 tok
= cond_start
= end_tok
+ 1;
7383 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7386 *cond_string
= savestring (cond_start
,
7387 cond_end
- cond_start
);
7389 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7395 *thread
= strtol (tok
, &tok
, 0);
7397 error (_("Junk after thread keyword."));
7398 if (!valid_thread_id (*thread
))
7399 error (_("Unknown thread %d."), *thread
);
7401 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7407 *task
= strtol (tok
, &tok
, 0);
7409 error (_("Junk after task keyword."));
7410 if (!valid_task_id (*task
))
7411 error (_("Unknown task %d."), *task
);
7414 error (_("Junk at end of arguments."));
7418 /* Decode a static tracepoint marker spec. */
7420 static struct symtabs_and_lines
7421 decode_static_tracepoint_spec (char **arg_p
)
7423 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7424 struct symtabs_and_lines sals
;
7425 struct symtab_and_line sal
;
7427 struct cleanup
*old_chain
;
7428 char *p
= &(*arg_p
)[3];
7433 while (*p
== ' ' || *p
== '\t')
7437 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7440 marker_str
= savestring (p
, endp
- p
);
7441 old_chain
= make_cleanup (xfree
, marker_str
);
7443 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7444 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7445 error (_("No known static tracepoint marker named %s"), marker_str
);
7447 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7448 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7450 for (i
= 0; i
< sals
.nelts
; i
++)
7452 struct static_tracepoint_marker
*marker
;
7454 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7456 init_sal (&sals
.sals
[i
]);
7458 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7459 sals
.sals
[i
].pc
= marker
->address
;
7461 release_static_tracepoint_marker (marker
);
7464 do_cleanups (old_chain
);
7470 /* Set a breakpoint. This function is shared between CLI and MI
7471 functions for setting a breakpoint. This function has two major
7472 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7473 parameter. If non-zero, the function will parse arg, extracting
7474 breakpoint location, address and thread. Otherwise, ARG is just the
7475 location of breakpoint, with condition and thread specified by the
7476 COND_STRING and THREAD parameters. Returns true if any breakpoint
7477 was created; false otherwise. */
7480 create_breakpoint (struct gdbarch
*gdbarch
,
7481 char *arg
, char *cond_string
, int thread
,
7482 int parse_condition_and_thread
,
7483 int tempflag
, enum bptype type_wanted
,
7485 enum auto_boolean pending_break_support
,
7486 struct breakpoint_ops
*ops
,
7490 struct gdb_exception e
;
7491 struct symtabs_and_lines sals
;
7492 struct symtab_and_line pending_sal
;
7494 char *addr_start
= arg
;
7496 struct cleanup
*old_chain
;
7497 struct cleanup
*bkpt_chain
= NULL
;
7498 struct captured_parse_breakpoint_args parse_args
;
7503 int prev_bkpt_count
= breakpoint_count
;
7509 parse_args
.arg_p
= &arg
;
7510 parse_args
.sals_p
= &sals
;
7511 parse_args
.addr_string_p
= &addr_string
;
7512 parse_args
.not_found_ptr
= ¬_found
;
7514 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7518 sals
= decode_static_tracepoint_spec (&arg
);
7520 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7521 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7522 for (i
= 0; i
< sals
.nelts
; i
++)
7523 addr_string
[i
] = xstrdup (copy_arg
);
7527 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7528 &parse_args
, RETURN_MASK_ALL
);
7530 /* If caller is interested in rc value from parse, set value. */
7534 throw_exception (e
);
7538 case NOT_FOUND_ERROR
:
7540 /* If pending breakpoint support is turned off, throw
7543 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7544 throw_exception (e
);
7546 exception_print (gdb_stderr
, e
);
7548 /* If pending breakpoint support is auto query and the user
7549 selects no, then simply return the error code. */
7550 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7551 && !nquery ("Make breakpoint pending on future shared library load? "))
7554 /* At this point, either the user was queried about setting
7555 a pending breakpoint and selected yes, or pending
7556 breakpoint behavior is on and thus a pending breakpoint
7557 is defaulted on behalf of the user. */
7558 copy_arg
= xstrdup (addr_start
);
7559 addr_string
= ©_arg
;
7561 sals
.sals
= &pending_sal
;
7566 throw_exception (e
);
7575 /* Create a chain of things that always need to be cleaned up. */
7576 old_chain
= make_cleanup (null_cleanup
, 0);
7580 /* Make sure that all storage allocated to SALS gets freed. */
7581 make_cleanup (xfree
, sals
.sals
);
7583 /* Cleanup the addr_string array but not its contents. */
7584 make_cleanup (xfree
, addr_string
);
7587 /* ----------------------------- SNIP -----------------------------
7588 Anything added to the cleanup chain beyond this point is assumed
7589 to be part of a breakpoint. If the breakpoint create succeeds
7590 then the memory is not reclaimed. */
7591 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7593 /* Mark the contents of the addr_string for cleanup. These go on
7594 the bkpt_chain and only occur if the breakpoint create fails. */
7595 for (i
= 0; i
< sals
.nelts
; i
++)
7597 if (addr_string
[i
] != NULL
)
7598 make_cleanup (xfree
, addr_string
[i
]);
7601 /* Resolve all line numbers to PC's and verify that the addresses
7602 are ok for the target. */
7604 breakpoint_sals_to_pc (&sals
);
7606 /* Fast tracepoints may have additional restrictions on location. */
7607 if (type_wanted
== bp_fast_tracepoint
)
7608 check_fast_tracepoint_sals (gdbarch
, &sals
);
7610 /* Verify that condition can be parsed, before setting any
7611 breakpoints. Allocate a separate condition expression for each
7615 if (parse_condition_and_thread
)
7617 /* Here we only parse 'arg' to separate condition
7618 from thread number, so parsing in context of first
7619 sal is OK. When setting the breakpoint we'll
7620 re-parse it in context of each sal. */
7623 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7626 make_cleanup (xfree
, cond_string
);
7630 /* Create a private copy of condition string. */
7633 cond_string
= xstrdup (cond_string
);
7634 make_cleanup (xfree
, cond_string
);
7638 /* If the user is creating a static tracepoint by marker id
7639 (strace -m MARKER_ID), then store the sals index, so that
7640 breakpoint_re_set can try to match up which of the newly
7641 found markers corresponds to this one, and, don't try to
7642 expand multiple locations for each sal, given than SALS
7643 already should contain all sals for MARKER_ID. */
7644 if (type_wanted
== bp_static_tracepoint
7645 && is_marker_spec (addr_string
[0]))
7649 for (i
= 0; i
< sals
.nelts
; ++i
)
7651 struct symtabs_and_lines expanded
;
7652 struct breakpoint
*tp
;
7653 struct cleanup
*old_chain
;
7656 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7657 expanded
.sals
[0] = sals
.sals
[i
];
7658 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7660 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7661 cond_string
, type_wanted
,
7662 tempflag
? disp_del
: disp_donttouch
,
7663 thread
, task
, ignore_count
, ops
,
7666 do_cleanups (old_chain
);
7668 /* Get the tracepoint we just created. */
7669 tp
= get_breakpoint (breakpoint_count
);
7670 gdb_assert (tp
!= NULL
);
7672 /* Given that its possible to have multiple markers with
7673 the same string id, if the user is creating a static
7674 tracepoint by marker id ("strace -m MARKER_ID"), then
7675 store the sals index, so that breakpoint_re_set can
7676 try to match up which of the newly found markers
7677 corresponds to this one */
7678 tp
->static_trace_marker_id_idx
= i
;
7682 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7683 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7684 thread
, task
, ignore_count
, ops
, from_tty
,
7689 struct breakpoint
*b
;
7691 make_cleanup (xfree
, copy_arg
);
7693 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7694 set_breakpoint_count (breakpoint_count
+ 1);
7695 b
->number
= breakpoint_count
;
7697 b
->addr_string
= addr_string
[0];
7698 b
->cond_string
= NULL
;
7699 b
->ignore_count
= ignore_count
;
7700 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7701 b
->condition_not_parsed
= 1;
7703 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7704 b
->pspace
= current_program_space
;
7706 if (enabled
&& b
->pspace
->executing_startup
7707 && (b
->type
== bp_breakpoint
7708 || b
->type
== bp_hardware_breakpoint
))
7709 b
->enable_state
= bp_startup_disabled
;
7716 warning (_("Multiple breakpoints were set.\n"
7717 "Use the \"delete\" command to delete unwanted breakpoints."));
7718 prev_breakpoint_count
= prev_bkpt_count
;
7721 /* That's it. Discard the cleanups for data inserted into the
7723 discard_cleanups (bkpt_chain
);
7724 /* But cleanup everything else. */
7725 do_cleanups (old_chain
);
7727 /* error call may happen here - have BKPT_CHAIN already discarded. */
7728 update_global_location_list (1);
7733 /* Set a breakpoint.
7734 ARG is a string describing breakpoint address,
7735 condition, and thread.
7736 FLAG specifies if a breakpoint is hardware on,
7737 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7741 break_command_1 (char *arg
, int flag
, int from_tty
)
7743 int tempflag
= flag
& BP_TEMPFLAG
;
7744 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7745 ? bp_hardware_breakpoint
7748 create_breakpoint (get_current_arch (),
7750 NULL
, 0, 1 /* parse arg */,
7751 tempflag
, type_wanted
,
7752 0 /* Ignore count */,
7753 pending_break_support
,
7754 NULL
/* breakpoint_ops */,
7760 /* Helper function for break_command_1 and disassemble_command. */
7763 resolve_sal_pc (struct symtab_and_line
*sal
)
7767 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7769 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7770 error (_("No line %d in file \"%s\"."),
7771 sal
->line
, sal
->symtab
->filename
);
7774 /* If this SAL corresponds to a breakpoint inserted using
7775 a line number, then skip the function prologue if necessary. */
7776 if (sal
->explicit_line
)
7777 skip_prologue_sal (sal
);
7780 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7782 struct blockvector
*bv
;
7786 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7789 sym
= block_linkage_function (b
);
7792 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7793 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7797 /* It really is worthwhile to have the section, so we'll just
7798 have to look harder. This case can be executed if we have
7799 line numbers but no functions (as can happen in assembly
7802 struct minimal_symbol
*msym
;
7803 struct cleanup
*old_chain
= save_current_space_and_thread ();
7805 switch_to_program_space_and_thread (sal
->pspace
);
7807 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7809 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7811 do_cleanups (old_chain
);
7818 break_command (char *arg
, int from_tty
)
7820 break_command_1 (arg
, 0, from_tty
);
7824 tbreak_command (char *arg
, int from_tty
)
7826 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7830 hbreak_command (char *arg
, int from_tty
)
7832 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7836 thbreak_command (char *arg
, int from_tty
)
7838 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7842 stop_command (char *arg
, int from_tty
)
7844 printf_filtered (_("Specify the type of breakpoint to set.\n\
7845 Usage: stop in <function | address>\n\
7846 stop at <line>\n"));
7850 stopin_command (char *arg
, int from_tty
)
7854 if (arg
== (char *) NULL
)
7856 else if (*arg
!= '*')
7861 /* look for a ':'. If this is a line number specification, then
7862 say it is bad, otherwise, it should be an address or
7863 function/method name */
7864 while (*argptr
&& !hasColon
)
7866 hasColon
= (*argptr
== ':');
7871 badInput
= (*argptr
!= ':'); /* Not a class::method */
7873 badInput
= isdigit (*arg
); /* a simple line number */
7877 printf_filtered (_("Usage: stop in <function | address>\n"));
7879 break_command_1 (arg
, 0, from_tty
);
7883 stopat_command (char *arg
, int from_tty
)
7887 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7894 /* look for a ':'. If there is a '::' then get out, otherwise
7895 it is probably a line number. */
7896 while (*argptr
&& !hasColon
)
7898 hasColon
= (*argptr
== ':');
7903 badInput
= (*argptr
== ':'); /* we have class::method */
7905 badInput
= !isdigit (*arg
); /* not a line number */
7909 printf_filtered (_("Usage: stop at <line>\n"));
7911 break_command_1 (arg
, 0, from_tty
);
7914 /* Return non-zero if EXP is verified as constant. Returned zero means EXP is
7915 variable. Also the constant detection may fail for some constant
7916 expressions and in such case still falsely return zero. */
7918 watchpoint_exp_is_const (const struct expression
*exp
)
7926 /* We are only interested in the descriptor of each element. */
7927 operator_length (exp
, i
, &oplenp
, &argsp
);
7930 switch (exp
->elts
[i
].opcode
)
7940 case BINOP_LOGICAL_AND
:
7941 case BINOP_LOGICAL_OR
:
7942 case BINOP_BITWISE_AND
:
7943 case BINOP_BITWISE_IOR
:
7944 case BINOP_BITWISE_XOR
:
7946 case BINOP_NOTEQUAL
:
7962 case TERNOP_SLICE_COUNT
:
7974 case OP_OBJC_NSSTRING
:
7977 case UNOP_LOGICAL_NOT
:
7978 case UNOP_COMPLEMENT
:
7981 /* Unary, binary and ternary operators: We have to check their
7982 operands. If they are constant, then so is the result of
7983 that operation. For instance, if A and B are determined to be
7984 constants, then so is "A + B".
7986 UNOP_IND is one exception to the rule above, because the value
7987 of *ADDR is not necessarily a constant, even when ADDR is. */
7991 /* Check whether the associated symbol is a constant.
7992 We use SYMBOL_CLASS rather than TYPE_CONST because it's
7993 possible that a buggy compiler could mark a variable as constant
7994 even when it is not, and TYPE_CONST would return true in this
7995 case, while SYMBOL_CLASS wouldn't.
7996 We also have to check for function symbols because they are
7999 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8001 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8002 && SYMBOL_CLASS (s
) != LOC_CONST
8003 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8008 /* The default action is to return 0 because we are using
8009 the optimistic approach here: If we don't know something,
8010 then it is not a constant. */
8019 /* accessflag: hw_write: watch write,
8020 hw_read: watch read,
8021 hw_access: watch access (read or write) */
8023 watch_command_1 (char *arg
, int accessflag
, int from_tty
, int just_location
)
8025 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8026 struct expression
*exp
;
8027 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8028 struct value
*val
, *mark
;
8029 struct frame_info
*frame
;
8030 char *exp_start
= NULL
;
8031 char *exp_end
= NULL
;
8032 char *tok
, *id_tok_start
, *end_tok
;
8034 char *cond_start
= NULL
;
8035 char *cond_end
= NULL
;
8036 int i
, other_type_used
, target_resources_ok
= 0;
8037 enum bptype bp_type
;
8042 /* Make sure that we actually have parameters to parse. */
8043 if (arg
!= NULL
&& arg
[0] != '\0')
8045 toklen
= strlen (arg
); /* Size of argument list. */
8047 /* Points tok to the end of the argument list. */
8048 tok
= arg
+ toklen
- 1;
8050 /* Go backwards in the parameters list. Skip the last parameter.
8051 If we're expecting a 'thread <thread_num>' parameter, this should
8052 be the thread identifier. */
8053 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8055 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8058 /* Points end_tok to the beginning of the last token. */
8059 id_tok_start
= tok
+ 1;
8061 /* Go backwards in the parameters list. Skip one more parameter.
8062 If we're expecting a 'thread <thread_num>' parameter, we should
8063 reach a "thread" token. */
8064 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8069 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8072 /* Move the pointer forward to skip the whitespace and
8073 calculate the length of the token. */
8075 toklen
= end_tok
- tok
;
8077 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8079 /* At this point we've found a "thread" token, which means
8080 the user is trying to set a watchpoint that triggers
8081 only in a specific thread. */
8084 /* Extract the thread ID from the next token. */
8085 thread
= strtol (id_tok_start
, &endp
, 0);
8087 /* Check if the user provided a valid numeric value for the
8089 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8090 error (_("Invalid thread ID specification %s."), id_tok_start
);
8092 /* Check if the thread actually exists. */
8093 if (!valid_thread_id (thread
))
8094 error (_("Unknown thread %d."), thread
);
8096 /* Truncate the string and get rid of the thread <thread_num>
8097 parameter before the parameter list is parsed by the
8098 evaluate_expression() function. */
8103 /* Parse the rest of the arguments. */
8104 innermost_block
= NULL
;
8106 exp
= parse_exp_1 (&arg
, 0, 0);
8108 /* Remove trailing whitespace from the expression before saving it.
8109 This makes the eventual display of the expression string a bit
8111 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8114 /* Checking if the expression is not constant. */
8115 if (watchpoint_exp_is_const (exp
))
8119 len
= exp_end
- exp_start
;
8120 while (len
> 0 && isspace (exp_start
[len
- 1]))
8122 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8125 exp_valid_block
= innermost_block
;
8126 mark
= value_mark ();
8127 fetch_subexp_value (exp
, &pc
, &val
, NULL
, NULL
);
8131 exp_valid_block
= NULL
;
8132 val
= value_addr (val
);
8133 release_value (val
);
8134 value_free_to_mark (mark
);
8136 else if (val
!= NULL
)
8137 release_value (val
);
8140 while (*tok
== ' ' || *tok
== '\t')
8144 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
8147 toklen
= end_tok
- tok
;
8148 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8150 struct expression
*cond
;
8152 innermost_block
= NULL
;
8153 tok
= cond_start
= end_tok
+ 1;
8154 cond
= parse_exp_1 (&tok
, 0, 0);
8156 /* The watchpoint expression may not be local, but the condition
8157 may still be. E.g.: `watch global if local > 0'. */
8158 cond_exp_valid_block
= innermost_block
;
8164 error (_("Junk at end of command."));
8166 if (accessflag
== hw_read
)
8167 bp_type
= bp_read_watchpoint
;
8168 else if (accessflag
== hw_access
)
8169 bp_type
= bp_access_watchpoint
;
8171 bp_type
= bp_hardware_watchpoint
;
8173 mem_cnt
= can_use_hardware_watchpoint (val
);
8174 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8175 error (_("Expression cannot be implemented with read/access watchpoint."));
8178 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8179 target_resources_ok
=
8180 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
8182 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8183 error (_("Target does not support this type of hardware watchpoint."));
8185 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8186 error (_("Target can only support one kind of HW watchpoint at a time."));
8189 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
8190 watchpoint could not be set. */
8191 if (!mem_cnt
|| target_resources_ok
<= 0)
8192 bp_type
= bp_watchpoint
;
8194 frame
= block_innermost_frame (exp_valid_block
);
8196 /* If the expression is "local", then set up a "watchpoint scope"
8197 breakpoint at the point where we've left the scope of the watchpoint
8198 expression. Create the scope breakpoint before the watchpoint, so
8199 that we will encounter it first in bpstat_stop_status. */
8200 if (exp_valid_block
&& frame
)
8202 if (frame_id_p (frame_unwind_caller_id (frame
)))
8205 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8206 frame_unwind_caller_pc (frame
),
8207 bp_watchpoint_scope
);
8209 scope_breakpoint
->enable_state
= bp_enabled
;
8211 /* Automatically delete the breakpoint when it hits. */
8212 scope_breakpoint
->disposition
= disp_del
;
8214 /* Only break in the proper frame (help with recursion). */
8215 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8217 /* Set the address at which we will stop. */
8218 scope_breakpoint
->loc
->gdbarch
8219 = frame_unwind_caller_arch (frame
);
8220 scope_breakpoint
->loc
->requested_address
8221 = frame_unwind_caller_pc (frame
);
8222 scope_breakpoint
->loc
->address
8223 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8224 scope_breakpoint
->loc
->requested_address
,
8225 scope_breakpoint
->type
);
8229 /* Now set up the breakpoint. */
8230 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8231 set_breakpoint_count (breakpoint_count
+ 1);
8232 b
->number
= breakpoint_count
;
8234 b
->disposition
= disp_donttouch
;
8236 b
->exp_valid_block
= exp_valid_block
;
8237 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8240 struct type
*t
= value_type (val
);
8241 CORE_ADDR addr
= value_as_address (val
);
8244 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8245 name
= type_to_string (t
);
8247 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8248 core_addr_to_string (addr
));
8251 b
->exp_string
= xstrprintf ("-location: %.*s",
8252 (int) (exp_end
- exp_start
), exp_start
);
8254 /* The above expression is in C. */
8255 b
->language
= language_c
;
8258 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8262 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8268 b
->watchpoint_frame
= get_frame_id (frame
);
8269 b
->watchpoint_thread
= inferior_ptid
;
8273 b
->watchpoint_frame
= null_frame_id
;
8274 b
->watchpoint_thread
= null_ptid
;
8277 if (scope_breakpoint
!= NULL
)
8279 /* The scope breakpoint is related to the watchpoint. We will
8280 need to act on them together. */
8281 b
->related_breakpoint
= scope_breakpoint
;
8282 scope_breakpoint
->related_breakpoint
= b
;
8286 value_free_to_mark (mark
);
8288 /* Finally update the new watchpoint. This creates the locations
8289 that should be inserted. */
8290 update_watchpoint (b
, 1);
8293 update_global_location_list (1);
8296 /* Return count of locations need to be watched and can be handled
8297 in hardware. If the watchpoint can not be handled
8298 in hardware return zero. */
8301 can_use_hardware_watchpoint (struct value
*v
)
8303 int found_memory_cnt
= 0;
8304 struct value
*head
= v
;
8306 /* Did the user specifically forbid us to use hardware watchpoints? */
8307 if (!can_use_hw_watchpoints
)
8310 /* Make sure that the value of the expression depends only upon
8311 memory contents, and values computed from them within GDB. If we
8312 find any register references or function calls, we can't use a
8313 hardware watchpoint.
8315 The idea here is that evaluating an expression generates a series
8316 of values, one holding the value of every subexpression. (The
8317 expression a*b+c has five subexpressions: a, b, a*b, c, and
8318 a*b+c.) GDB's values hold almost enough information to establish
8319 the criteria given above --- they identify memory lvalues,
8320 register lvalues, computed values, etcetera. So we can evaluate
8321 the expression, and then scan the chain of values that leaves
8322 behind to decide whether we can detect any possible change to the
8323 expression's final value using only hardware watchpoints.
8325 However, I don't think that the values returned by inferior
8326 function calls are special in any way. So this function may not
8327 notice that an expression involving an inferior function call
8328 can't be watched with hardware watchpoints. FIXME. */
8329 for (; v
; v
= value_next (v
))
8331 if (VALUE_LVAL (v
) == lval_memory
)
8334 /* A lazy memory lvalue is one that GDB never needed to fetch;
8335 we either just used its address (e.g., `a' in `a.b') or
8336 we never needed it at all (e.g., `a' in `a,b'). */
8340 /* Ahh, memory we actually used! Check if we can cover
8341 it with hardware watchpoints. */
8342 struct type
*vtype
= check_typedef (value_type (v
));
8344 /* We only watch structs and arrays if user asked for it
8345 explicitly, never if they just happen to appear in a
8346 middle of some value chain. */
8348 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8349 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8351 CORE_ADDR vaddr
= value_address (v
);
8352 int len
= TYPE_LENGTH (value_type (v
));
8354 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
8361 else if (VALUE_LVAL (v
) != not_lval
8362 && deprecated_value_modifiable (v
) == 0)
8363 return 0; /* These are values from the history (e.g., $1). */
8364 else if (VALUE_LVAL (v
) == lval_register
)
8365 return 0; /* Cannot watch a register with a HW watchpoint. */
8368 /* The expression itself looks suitable for using a hardware
8369 watchpoint, but give the target machine a chance to reject it. */
8370 return found_memory_cnt
;
8374 watch_command_wrapper (char *arg
, int from_tty
)
8376 watch_command_1 (arg
, hw_write
, from_tty
, 0);
8379 /* A helper function that looks for an argument at the start of a
8380 string. The argument must also either be at the end of the string,
8381 or be followed by whitespace. Returns 1 if it finds the argument,
8382 0 otherwise. If the argument is found, it updates *STR. */
8385 check_for_argument (char **str
, char *arg
, int arg_len
)
8387 if (strncmp (*str
, arg
, arg_len
) == 0
8388 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8396 /* A helper function that looks for the "-location" argument and then
8397 calls watch_command_1. */
8400 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8402 int just_location
= 0;
8405 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8406 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8408 ep_skip_leading_whitespace (&arg
);
8412 watch_command_1 (arg
, accessflag
, from_tty
, just_location
);
8416 watch_command (char *arg
, int from_tty
)
8418 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8422 rwatch_command_wrapper (char *arg
, int from_tty
)
8424 watch_command_1 (arg
, hw_read
, from_tty
, 0);
8428 rwatch_command (char *arg
, int from_tty
)
8430 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8434 awatch_command_wrapper (char *arg
, int from_tty
)
8436 watch_command_1 (arg
, hw_access
, from_tty
, 0);
8440 awatch_command (char *arg
, int from_tty
)
8442 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8446 /* Helper routines for the until_command routine in infcmd.c. Here
8447 because it uses the mechanisms of breakpoints. */
8449 struct until_break_command_continuation_args
8451 struct breakpoint
*breakpoint
;
8452 struct breakpoint
*breakpoint2
;
8455 /* This function is called by fetch_inferior_event via the
8456 cmd_continuation pointer, to complete the until command. It takes
8457 care of cleaning up the temporary breakpoints set up by the until
8460 until_break_command_continuation (void *arg
)
8462 struct until_break_command_continuation_args
*a
= arg
;
8464 delete_breakpoint (a
->breakpoint
);
8466 delete_breakpoint (a
->breakpoint2
);
8470 until_break_command (char *arg
, int from_tty
, int anywhere
)
8472 struct symtabs_and_lines sals
;
8473 struct symtab_and_line sal
;
8474 struct frame_info
*frame
= get_selected_frame (NULL
);
8475 struct breakpoint
*breakpoint
;
8476 struct breakpoint
*breakpoint2
= NULL
;
8477 struct cleanup
*old_chain
;
8479 clear_proceed_status ();
8481 /* Set a breakpoint where the user wants it and at return from
8484 if (default_breakpoint_valid
)
8485 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8486 default_breakpoint_line
, (char ***) NULL
, NULL
);
8488 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8489 0, (char ***) NULL
, NULL
);
8491 if (sals
.nelts
!= 1)
8492 error (_("Couldn't get information on specified line."));
8495 xfree (sals
.sals
); /* malloc'd, so freed */
8498 error (_("Junk at end of arguments."));
8500 resolve_sal_pc (&sal
);
8503 /* If the user told us to continue until a specified location,
8504 we don't specify a frame at which we need to stop. */
8505 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8506 null_frame_id
, bp_until
);
8508 /* Otherwise, specify the selected frame, because we want to stop only
8509 at the very same frame. */
8510 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8511 get_stack_frame_id (frame
),
8514 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8516 /* Keep within the current frame, or in frames called by the current
8519 if (frame_id_p (frame_unwind_caller_id (frame
)))
8521 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8522 sal
.pc
= frame_unwind_caller_pc (frame
);
8523 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8525 frame_unwind_caller_id (frame
),
8527 make_cleanup_delete_breakpoint (breakpoint2
);
8530 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8532 /* If we are running asynchronously, and proceed call above has actually
8533 managed to start the target, arrange for breakpoints to be
8534 deleted when the target stops. Otherwise, we're already stopped and
8535 delete breakpoints via cleanup chain. */
8537 if (target_can_async_p () && is_running (inferior_ptid
))
8539 struct until_break_command_continuation_args
*args
;
8540 args
= xmalloc (sizeof (*args
));
8542 args
->breakpoint
= breakpoint
;
8543 args
->breakpoint2
= breakpoint2
;
8545 discard_cleanups (old_chain
);
8546 add_continuation (inferior_thread (),
8547 until_break_command_continuation
, args
,
8551 do_cleanups (old_chain
);
8555 ep_skip_leading_whitespace (char **s
)
8557 if ((s
== NULL
) || (*s
== NULL
))
8559 while (isspace (**s
))
8563 /* This function attempts to parse an optional "if <cond>" clause
8564 from the arg string. If one is not found, it returns NULL.
8566 Else, it returns a pointer to the condition string. (It does not
8567 attempt to evaluate the string against a particular block.) And,
8568 it updates arg to point to the first character following the parsed
8569 if clause in the arg string. */
8572 ep_parse_optional_if_clause (char **arg
)
8576 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8579 /* Skip the "if" keyword. */
8582 /* Skip any extra leading whitespace, and record the start of the
8583 condition string. */
8584 ep_skip_leading_whitespace (arg
);
8587 /* Assume that the condition occupies the remainder of the arg string. */
8588 (*arg
) += strlen (cond_string
);
8593 /* Commands to deal with catching events, such as signals, exceptions,
8594 process start/exit, etc. */
8598 catch_fork_temporary
, catch_vfork_temporary
,
8599 catch_fork_permanent
, catch_vfork_permanent
8604 catch_fork_command_1 (char *arg
, int from_tty
,
8605 struct cmd_list_element
*command
)
8607 struct gdbarch
*gdbarch
= get_current_arch ();
8608 char *cond_string
= NULL
;
8609 catch_fork_kind fork_kind
;
8612 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8613 tempflag
= (fork_kind
== catch_fork_temporary
8614 || fork_kind
== catch_vfork_temporary
);
8618 ep_skip_leading_whitespace (&arg
);
8620 /* The allowed syntax is:
8622 catch [v]fork if <cond>
8624 First, check if there's an if clause. */
8625 cond_string
= ep_parse_optional_if_clause (&arg
);
8627 if ((*arg
!= '\0') && !isspace (*arg
))
8628 error (_("Junk at end of arguments."));
8630 /* If this target supports it, create a fork or vfork catchpoint
8631 and enable reporting of such events. */
8634 case catch_fork_temporary
:
8635 case catch_fork_permanent
:
8636 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8637 &catch_fork_breakpoint_ops
);
8639 case catch_vfork_temporary
:
8640 case catch_vfork_permanent
:
8641 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8642 &catch_vfork_breakpoint_ops
);
8645 error (_("unsupported or unknown fork kind; cannot catch it"));
8651 catch_exec_command_1 (char *arg
, int from_tty
,
8652 struct cmd_list_element
*command
)
8654 struct gdbarch
*gdbarch
= get_current_arch ();
8656 char *cond_string
= NULL
;
8658 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8662 ep_skip_leading_whitespace (&arg
);
8664 /* The allowed syntax is:
8666 catch exec if <cond>
8668 First, check if there's an if clause. */
8669 cond_string
= ep_parse_optional_if_clause (&arg
);
8671 if ((*arg
!= '\0') && !isspace (*arg
))
8672 error (_("Junk at end of arguments."));
8674 /* If this target supports it, create an exec catchpoint
8675 and enable reporting of such events. */
8676 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8677 &catch_exec_breakpoint_ops
);
8680 static enum print_stop_action
8681 print_exception_catchpoint (struct breakpoint
*b
)
8683 int bp_temp
, bp_throw
;
8685 annotate_catchpoint (b
->number
);
8687 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8688 if (b
->loc
->address
!= b
->loc
->requested_address
)
8689 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8692 bp_temp
= b
->disposition
== disp_del
;
8694 bp_temp
? "Temporary catchpoint "
8696 if (!ui_out_is_mi_like_p (uiout
))
8697 ui_out_field_int (uiout
, "bkptno", b
->number
);
8699 bp_throw
? " (exception thrown), "
8700 : " (exception caught), ");
8701 if (ui_out_is_mi_like_p (uiout
))
8703 ui_out_field_string (uiout
, "reason",
8704 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8705 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8706 ui_out_field_int (uiout
, "bkptno", b
->number
);
8708 return PRINT_SRC_AND_LOC
;
8712 print_one_exception_catchpoint (struct breakpoint
*b
,
8713 struct bp_location
**last_loc
)
8715 struct value_print_options opts
;
8717 get_user_print_options (&opts
);
8718 if (opts
.addressprint
)
8721 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8722 ui_out_field_string (uiout
, "addr", "<PENDING>");
8724 ui_out_field_core_addr (uiout
, "addr",
8725 b
->loc
->gdbarch
, b
->loc
->address
);
8730 if (strstr (b
->addr_string
, "throw") != NULL
)
8731 ui_out_field_string (uiout
, "what", "exception throw");
8733 ui_out_field_string (uiout
, "what", "exception catch");
8737 print_mention_exception_catchpoint (struct breakpoint
*b
)
8742 bp_temp
= b
->disposition
== disp_del
;
8743 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8744 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8745 : _("Catchpoint "));
8746 ui_out_field_int (uiout
, "bkptno", b
->number
);
8747 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8751 /* Implement the "print_recreate" breakpoint_ops method for throw and
8752 catch catchpoints. */
8755 print_recreate_exception_catchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8760 bp_temp
= b
->disposition
== disp_del
;
8761 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8762 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
8763 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
8766 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8769 NULL
, /* breakpoint_hit */
8770 print_exception_catchpoint
,
8771 print_one_exception_catchpoint
,
8772 print_mention_exception_catchpoint
,
8773 print_recreate_exception_catchpoint
8777 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8778 enum exception_event_kind ex_event
, int from_tty
)
8780 char *trigger_func_name
;
8782 if (ex_event
== EX_EVENT_CATCH
)
8783 trigger_func_name
= "__cxa_begin_catch";
8785 trigger_func_name
= "__cxa_throw";
8787 create_breakpoint (get_current_arch (),
8788 trigger_func_name
, cond_string
, -1,
8789 0 /* condition and thread are valid. */,
8790 tempflag
, bp_breakpoint
,
8792 AUTO_BOOLEAN_TRUE
/* pending */,
8793 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8799 /* Deal with "catch catch" and "catch throw" commands */
8802 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8803 int tempflag
, int from_tty
)
8805 char *cond_string
= NULL
;
8809 ep_skip_leading_whitespace (&arg
);
8811 cond_string
= ep_parse_optional_if_clause (&arg
);
8813 if ((*arg
!= '\0') && !isspace (*arg
))
8814 error (_("Junk at end of arguments."));
8816 if (ex_event
!= EX_EVENT_THROW
8817 && ex_event
!= EX_EVENT_CATCH
)
8818 error (_("Unsupported or unknown exception event; cannot catch it"));
8820 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8823 warning (_("Unsupported with this platform/compiler combination."));
8826 /* Implementation of "catch catch" command. */
8829 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8831 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8833 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8836 /* Implementation of "catch throw" command. */
8839 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8841 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8843 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8846 /* Create a breakpoint struct for Ada exception catchpoints. */
8849 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8850 struct symtab_and_line sal
,
8854 struct expression
*cond
,
8855 struct breakpoint_ops
*ops
,
8859 struct breakpoint
*b
;
8863 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8865 loc_gdbarch
= gdbarch
;
8867 describe_other_breakpoints (loc_gdbarch
,
8868 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8869 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8870 version for exception catchpoints, because two catchpoints
8871 used for different exception names will use the same address.
8872 In this case, a "breakpoint ... also set at..." warning is
8873 unproductive. Besides. the warning phrasing is also a bit
8874 inapropriate, we should use the word catchpoint, and tell
8875 the user what type of catchpoint it is. The above is good
8876 enough for now, though. */
8879 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8880 set_breakpoint_count (breakpoint_count
+ 1);
8882 b
->enable_state
= bp_enabled
;
8883 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8884 b
->number
= breakpoint_count
;
8885 b
->ignore_count
= 0;
8886 b
->loc
->cond
= cond
;
8887 b
->addr_string
= addr_string
;
8888 b
->language
= language_ada
;
8889 b
->cond_string
= cond_string
;
8890 b
->exp_string
= exp_string
;
8895 update_global_location_list (1);
8898 /* Implement the "catch exception" command. */
8901 catch_ada_exception_command (char *arg
, int from_tty
,
8902 struct cmd_list_element
*command
)
8904 struct gdbarch
*gdbarch
= get_current_arch ();
8906 struct symtab_and_line sal
;
8907 char *addr_string
= NULL
;
8908 char *exp_string
= NULL
;
8909 char *cond_string
= NULL
;
8910 struct expression
*cond
= NULL
;
8911 struct breakpoint_ops
*ops
= NULL
;
8913 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8917 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8918 &cond_string
, &cond
, &ops
);
8919 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8920 cond_string
, cond
, ops
, tempflag
,
8924 /* Cleanup function for a syscall filter list. */
8926 clean_up_filters (void *arg
)
8928 VEC(int) *iter
= *(VEC(int) **) arg
;
8929 VEC_free (int, iter
);
8932 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8933 filter list, or NULL if no filtering is required. */
8935 catch_syscall_split_args (char *arg
)
8937 VEC(int) *result
= NULL
;
8938 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8940 while (*arg
!= '\0')
8942 int i
, syscall_number
;
8947 /* Skip whitespace. */
8948 while (isspace (*arg
))
8951 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8952 cur_name
[i
] = arg
[i
];
8956 /* Check if the user provided a syscall name or a number. */
8957 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8958 if (*endptr
== '\0')
8959 get_syscall_by_number (syscall_number
, &s
);
8962 /* We have a name. Let's check if it's valid and convert it
8964 get_syscall_by_name (cur_name
, &s
);
8966 if (s
.number
== UNKNOWN_SYSCALL
)
8967 /* Here we have to issue an error instead of a warning, because
8968 GDB cannot do anything useful if there's no syscall number to
8970 error (_("Unknown syscall name '%s'."), cur_name
);
8973 /* Ok, it's valid. */
8974 VEC_safe_push (int, result
, s
.number
);
8977 discard_cleanups (cleanup
);
8981 /* Implement the "catch syscall" command. */
8984 catch_syscall_command_1 (char *arg
, int from_tty
,
8985 struct cmd_list_element
*command
)
8990 struct gdbarch
*gdbarch
= get_current_arch ();
8992 /* Checking if the feature if supported. */
8993 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8994 error (_("The feature 'catch syscall' is not supported on \
8995 this architeture yet."));
8997 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8999 ep_skip_leading_whitespace (&arg
);
9001 /* We need to do this first "dummy" translation in order
9002 to get the syscall XML file loaded or, most important,
9003 to display a warning to the user if there's no XML file
9004 for his/her architecture. */
9005 get_syscall_by_number (0, &s
);
9007 /* The allowed syntax is:
9009 catch syscall <name | number> [<name | number> ... <name | number>]
9011 Let's check if there's a syscall name. */
9014 filter
= catch_syscall_split_args (arg
);
9018 create_syscall_event_catchpoint (tempflag
, filter
,
9019 &catch_syscall_breakpoint_ops
);
9022 /* Implement the "catch assert" command. */
9025 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9027 struct gdbarch
*gdbarch
= get_current_arch ();
9029 struct symtab_and_line sal
;
9030 char *addr_string
= NULL
;
9031 struct breakpoint_ops
*ops
= NULL
;
9033 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9037 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9038 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9039 ops
, tempflag
, from_tty
);
9043 catch_command (char *arg
, int from_tty
)
9045 error (_("Catch requires an event name."));
9050 tcatch_command (char *arg
, int from_tty
)
9052 error (_("Catch requires an event name."));
9055 /* Delete breakpoints by address or line. */
9058 clear_command (char *arg
, int from_tty
)
9060 struct breakpoint
*b
;
9061 VEC(breakpoint_p
) *found
= 0;
9064 struct symtabs_and_lines sals
;
9065 struct symtab_and_line sal
;
9070 sals
= decode_line_spec (arg
, 1);
9075 sals
.sals
= (struct symtab_and_line
*)
9076 xmalloc (sizeof (struct symtab_and_line
));
9077 make_cleanup (xfree
, sals
.sals
);
9078 init_sal (&sal
); /* initialize to zeroes */
9079 sal
.line
= default_breakpoint_line
;
9080 sal
.symtab
= default_breakpoint_symtab
;
9081 sal
.pc
= default_breakpoint_address
;
9082 sal
.pspace
= default_breakpoint_pspace
;
9083 if (sal
.symtab
== 0)
9084 error (_("No source file specified."));
9092 /* We don't call resolve_sal_pc here. That's not
9093 as bad as it seems, because all existing breakpoints
9094 typically have both file/line and pc set. So, if
9095 clear is given file/line, we can match this to existing
9096 breakpoint without obtaining pc at all.
9098 We only support clearing given the address explicitly
9099 present in breakpoint table. Say, we've set breakpoint
9100 at file:line. There were several PC values for that file:line,
9101 due to optimization, all in one block.
9102 We've picked one PC value. If "clear" is issued with another
9103 PC corresponding to the same file:line, the breakpoint won't
9104 be cleared. We probably can still clear the breakpoint, but
9105 since the other PC value is never presented to user, user
9106 can only find it by guessing, and it does not seem important
9109 /* For each line spec given, delete bps which correspond
9110 to it. Do it in two passes, solely to preserve the current
9111 behavior that from_tty is forced true if we delete more than
9115 for (i
= 0; i
< sals
.nelts
; i
++)
9117 /* If exact pc given, clear bpts at that pc.
9118 If line given (pc == 0), clear all bpts on specified line.
9119 If defaulting, clear all bpts on default line
9122 defaulting sal.pc != 0 tests to do
9127 1 0 <can't happen> */
9131 /* Find all matching breakpoints and add them to
9136 /* Are we going to delete b? */
9137 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9139 struct bp_location
*loc
= b
->loc
;
9140 for (; loc
; loc
= loc
->next
)
9142 int pc_match
= sal
.pc
9143 && (loc
->pspace
== sal
.pspace
)
9144 && (loc
->address
== sal
.pc
)
9145 && (!section_is_overlay (loc
->section
)
9146 || loc
->section
== sal
.section
);
9147 int line_match
= ((default_match
|| (0 == sal
.pc
))
9148 && b
->source_file
!= NULL
9149 && sal
.symtab
!= NULL
9150 && sal
.pspace
== loc
->pspace
9151 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
9152 && b
->line_number
== sal
.line
);
9153 if (pc_match
|| line_match
)
9162 VEC_safe_push(breakpoint_p
, found
, b
);
9165 /* Now go thru the 'found' chain and delete them. */
9166 if (VEC_empty(breakpoint_p
, found
))
9169 error (_("No breakpoint at %s."), arg
);
9171 error (_("No breakpoint at this line."));
9174 if (VEC_length(breakpoint_p
, found
) > 1)
9175 from_tty
= 1; /* Always report if deleted more than one */
9178 if (VEC_length(breakpoint_p
, found
) == 1)
9179 printf_unfiltered (_("Deleted breakpoint "));
9181 printf_unfiltered (_("Deleted breakpoints "));
9183 breakpoints_changed ();
9185 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9188 printf_unfiltered ("%d ", b
->number
);
9189 delete_breakpoint (b
);
9192 putchar_unfiltered ('\n');
9195 /* Delete breakpoint in BS if they are `delete' breakpoints and
9196 all breakpoints that are marked for deletion, whether hit or not.
9197 This is called after any breakpoint is hit, or after errors. */
9200 breakpoint_auto_delete (bpstat bs
)
9202 struct breakpoint
*b
, *temp
;
9204 for (; bs
; bs
= bs
->next
)
9205 if (bs
->breakpoint_at
9206 && bs
->breakpoint_at
->disposition
== disp_del
9208 delete_breakpoint (bs
->breakpoint_at
);
9210 ALL_BREAKPOINTS_SAFE (b
, temp
)
9212 if (b
->disposition
== disp_del_at_next_stop
)
9213 delete_breakpoint (b
);
9217 /* A comparison function for bp_location AP and BP being interfaced to qsort.
9218 Sort elements primarily by their ADDRESS (no matter what does
9219 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
9220 first bp_permanent OWNERed elements and terciarily just ensuring the array
9221 is sorted stable way despite qsort being an instable algorithm. */
9224 bp_location_compare (const void *ap
, const void *bp
)
9226 struct bp_location
*a
= *(void **) ap
;
9227 struct bp_location
*b
= *(void **) bp
;
9228 /* A and B come from existing breakpoints having non-NULL OWNER. */
9229 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9230 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9232 if (a
->address
!= b
->address
)
9233 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9235 /* Sort permanent breakpoints first. */
9236 if (a_perm
!= b_perm
)
9237 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9239 /* Make the user-visible order stable across GDB runs. Locations of the same
9240 breakpoint can be sorted in arbitrary order. */
9242 if (a
->owner
->number
!= b
->owner
->number
)
9243 return (a
->owner
->number
> b
->owner
->number
)
9244 - (a
->owner
->number
< b
->owner
->number
);
9246 return (a
> b
) - (a
< b
);
9249 /* Set bp_location_placed_address_before_address_max and
9250 bp_location_shadow_len_after_address_max according to the current content of
9251 the bp_location array. */
9254 bp_location_target_extensions_update (void)
9256 struct bp_location
*bl
, **blp_tmp
;
9258 bp_location_placed_address_before_address_max
= 0;
9259 bp_location_shadow_len_after_address_max
= 0;
9261 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9263 CORE_ADDR start
, end
, addr
;
9265 if (!bp_location_has_shadow (bl
))
9268 start
= bl
->target_info
.placed_address
;
9269 end
= start
+ bl
->target_info
.shadow_len
;
9271 gdb_assert (bl
->address
>= start
);
9272 addr
= bl
->address
- start
;
9273 if (addr
> bp_location_placed_address_before_address_max
)
9274 bp_location_placed_address_before_address_max
= addr
;
9276 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9278 gdb_assert (bl
->address
< end
);
9279 addr
= end
- bl
->address
;
9280 if (addr
> bp_location_shadow_len_after_address_max
)
9281 bp_location_shadow_len_after_address_max
= addr
;
9285 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9286 into the inferior, only remove already-inserted locations that no
9287 longer should be inserted. Functions that delete a breakpoint or
9288 breakpoints should pass false, so that deleting a breakpoint
9289 doesn't have the side effect of inserting the locations of other
9290 breakpoints that are marked not-inserted, but should_be_inserted
9291 returns true on them.
9293 This behaviour is useful is situations close to tear-down -- e.g.,
9294 after an exec, while the target still has execution, but breakpoint
9295 shadows of the previous executable image should *NOT* be restored
9296 to the new image; or before detaching, where the target still has
9297 execution and wants to delete breakpoints from GDB's lists, and all
9298 breakpoints had already been removed from the inferior. */
9301 update_global_location_list (int should_insert
)
9303 struct breakpoint
*b
;
9304 struct bp_location
**locp
, *loc
;
9305 struct cleanup
*cleanups
;
9307 /* Used in the duplicates detection below. When iterating over all
9308 bp_locations, points to the first bp_location of a given address.
9309 Breakpoints and watchpoints of different types are never
9310 duplicates of each other. Keep one pointer for each type of
9311 breakpoint/watchpoint, so we only need to loop over all locations
9313 struct bp_location
*bp_loc_first
; /* breakpoint */
9314 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9315 struct bp_location
*awp_loc_first
; /* access watchpoint */
9316 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9318 /* Saved former bp_location array which we compare against the newly built
9319 bp_location from the current state of ALL_BREAKPOINTS. */
9320 struct bp_location
**old_location
, **old_locp
;
9321 unsigned old_location_count
;
9323 old_location
= bp_location
;
9324 old_location_count
= bp_location_count
;
9326 bp_location_count
= 0;
9327 cleanups
= make_cleanup (xfree
, old_location
);
9330 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9331 bp_location_count
++;
9333 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9336 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9338 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9339 bp_location_compare
);
9341 bp_location_target_extensions_update ();
9343 /* Identify bp_location instances that are no longer present in the new
9344 list, and therefore should be freed. Note that it's not necessary that
9345 those locations should be removed from inferior -- if there's another
9346 location at the same address (previously marked as duplicate),
9347 we don't need to remove/insert the location.
9349 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
9350 former bp_location array state respectively. */
9353 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9356 struct bp_location
*old_loc
= *old_locp
;
9357 struct bp_location
**loc2p
;
9359 /* Tells if 'old_loc' is found amoung the new locations. If not, we
9361 int found_object
= 0;
9362 /* Tells if the location should remain inserted in the target. */
9363 int keep_in_target
= 0;
9366 /* Skip LOCP entries which will definitely never be needed. Stop either
9367 at or being the one matching OLD_LOC. */
9368 while (locp
< bp_location
+ bp_location_count
9369 && (*locp
)->address
< old_loc
->address
)
9373 (loc2p
< bp_location
+ bp_location_count
9374 && (*loc2p
)->address
== old_loc
->address
);
9377 if (*loc2p
== old_loc
)
9384 /* If this location is no longer present, and inserted, look if there's
9385 maybe a new location at the same address. If so, mark that one
9386 inserted, and don't remove this one. This is needed so that we
9387 don't have a time window where a breakpoint at certain location is not
9390 if (old_loc
->inserted
)
9392 /* If the location is inserted now, we might have to remove it. */
9394 if (found_object
&& should_be_inserted (old_loc
))
9396 /* The location is still present in the location list, and still
9397 should be inserted. Don't do anything. */
9402 /* The location is either no longer present, or got disabled.
9403 See if there's another location at the same address, in which
9404 case we don't need to remove this one from the target. */
9406 /* OLD_LOC comes from existing struct breakpoint. */
9407 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9410 (loc2p
< bp_location
+ bp_location_count
9411 && (*loc2p
)->address
== old_loc
->address
);
9414 struct bp_location
*loc2
= *loc2p
;
9416 if (breakpoint_locations_match (loc2
, old_loc
))
9418 /* For the sake of should_be_inserted.
9419 Duplicates check below will fix up this later. */
9420 loc2
->duplicate
= 0;
9422 /* Read watchpoint locations are switched to
9423 access watchpoints, if the former are not
9424 supported, but the latter are. */
9425 if (is_hardware_watchpoint (old_loc
->owner
))
9427 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9428 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9431 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9434 loc2
->target_info
= old_loc
->target_info
;
9443 if (!keep_in_target
)
9445 if (remove_breakpoint (old_loc
, mark_uninserted
))
9447 /* This is just about all we can do. We could keep this
9448 location on the global list, and try to remove it next
9449 time, but there's no particular reason why we will
9452 Note that at this point, old_loc->owner is still valid,
9453 as delete_breakpoint frees the breakpoint only
9454 after calling us. */
9455 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9456 old_loc
->owner
->number
);
9464 if (removed
&& non_stop
9465 && breakpoint_address_is_meaningful (old_loc
->owner
)
9466 && !is_hardware_watchpoint (old_loc
->owner
))
9468 /* This location was removed from the target. In
9469 non-stop mode, a race condition is possible where
9470 we've removed a breakpoint, but stop events for that
9471 breakpoint are already queued and will arrive later.
9472 We apply an heuristic to be able to distinguish such
9473 SIGTRAPs from other random SIGTRAPs: we keep this
9474 breakpoint location for a bit, and will retire it
9475 after we see some number of events. The theory here
9476 is that reporting of events should, "on the average",
9477 be fair, so after a while we'll see events from all
9478 threads that have anything of interest, and no longer
9479 need to keep this breakpoint location around. We
9480 don't hold locations forever so to reduce chances of
9481 mistaking a non-breakpoint SIGTRAP for a breakpoint
9484 The heuristic failing can be disastrous on
9485 decr_pc_after_break targets.
9487 On decr_pc_after_break targets, like e.g., x86-linux,
9488 if we fail to recognize a late breakpoint SIGTRAP,
9489 because events_till_retirement has reached 0 too
9490 soon, we'll fail to do the PC adjustment, and report
9491 a random SIGTRAP to the user. When the user resumes
9492 the inferior, it will most likely immediately crash
9493 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9494 corrupted, because of being resumed e.g., in the
9495 middle of a multi-byte instruction, or skipped a
9496 one-byte instruction. This was actually seen happen
9497 on native x86-linux, and should be less rare on
9498 targets that do not support new thread events, like
9499 remote, due to the heuristic depending on
9502 Mistaking a random SIGTRAP for a breakpoint trap
9503 causes similar symptoms (PC adjustment applied when
9504 it shouldn't), but then again, playing with SIGTRAPs
9505 behind the debugger's back is asking for trouble.
9507 Since hardware watchpoint traps are always
9508 distinguishable from other traps, so we don't need to
9509 apply keep hardware watchpoint moribund locations
9510 around. We simply always ignore hardware watchpoint
9511 traps we can no longer explain. */
9513 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9514 old_loc
->owner
= NULL
;
9516 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9520 old_loc
->owner
= NULL
;
9521 decref_bp_location (&old_loc
);
9526 /* Rescan breakpoints at the same address and section, marking the
9527 first one as "first" and any others as "duplicates". This is so
9528 that the bpt instruction is only inserted once. If we have a
9529 permanent breakpoint at the same place as BPT, make that one the
9530 official one, and the rest as duplicates. Permanent breakpoints
9531 are sorted first for the same address.
9533 Do the same for hardware watchpoints, but also considering the
9534 watchpoint's type (regular/access/read) and length. */
9536 bp_loc_first
= NULL
;
9537 wp_loc_first
= NULL
;
9538 awp_loc_first
= NULL
;
9539 rwp_loc_first
= NULL
;
9540 ALL_BP_LOCATIONS (loc
, locp
)
9542 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
9543 struct breakpoint
*b
= loc
->owner
;
9544 struct bp_location
**loc_first_p
;
9546 if (b
->enable_state
== bp_disabled
9547 || b
->enable_state
== bp_call_disabled
9548 || b
->enable_state
== bp_startup_disabled
9550 || loc
->shlib_disabled
9551 || !breakpoint_address_is_meaningful (b
)
9552 || is_tracepoint (b
))
9555 /* Permanent breakpoint should always be inserted. */
9556 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9557 internal_error (__FILE__
, __LINE__
,
9558 _("allegedly permanent breakpoint is not "
9559 "actually inserted"));
9561 if (b
->type
== bp_hardware_watchpoint
)
9562 loc_first_p
= &wp_loc_first
;
9563 else if (b
->type
== bp_read_watchpoint
)
9564 loc_first_p
= &rwp_loc_first
;
9565 else if (b
->type
== bp_access_watchpoint
)
9566 loc_first_p
= &awp_loc_first
;
9568 loc_first_p
= &bp_loc_first
;
9570 if (*loc_first_p
== NULL
9571 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9572 || !breakpoint_locations_match (loc
, *loc_first_p
))
9581 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9582 && b
->enable_state
!= bp_permanent
)
9583 internal_error (__FILE__
, __LINE__
,
9584 _("another breakpoint was inserted on top of "
9585 "a permanent breakpoint"));
9588 if (breakpoints_always_inserted_mode () && should_insert
9589 && (have_live_inferiors ()
9590 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9591 insert_breakpoint_locations ();
9593 do_cleanups (cleanups
);
9597 breakpoint_retire_moribund (void)
9599 struct bp_location
*loc
;
9602 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9603 if (--(loc
->events_till_retirement
) == 0)
9605 decref_bp_location (&loc
);
9606 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9612 update_global_location_list_nothrow (int inserting
)
9614 struct gdb_exception e
;
9616 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9617 update_global_location_list (inserting
);
9620 /* Clear BKP from a BPS. */
9623 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
9627 for (bs
= bps
; bs
; bs
= bs
->next
)
9628 if (bs
->breakpoint_at
== bpt
)
9630 bs
->breakpoint_at
= NULL
;
9632 /* bs->commands will be freed later. */
9636 /* Callback for iterate_over_threads. */
9638 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9640 struct breakpoint
*bpt
= data
;
9642 bpstat_remove_bp_location (th
->stop_bpstat
, bpt
);
9646 /* Delete a breakpoint and clean up all traces of it in the data
9650 delete_breakpoint (struct breakpoint
*bpt
)
9652 struct breakpoint
*b
;
9654 gdb_assert (bpt
!= NULL
);
9656 /* Has this bp already been deleted? This can happen because multiple
9657 lists can hold pointers to bp's. bpstat lists are especial culprits.
9659 One example of this happening is a watchpoint's scope bp. When the
9660 scope bp triggers, we notice that the watchpoint is out of scope, and
9661 delete it. We also delete its scope bp. But the scope bp is marked
9662 "auto-deleting", and is already on a bpstat. That bpstat is then
9663 checked for auto-deleting bp's, which are deleted.
9665 A real solution to this problem might involve reference counts in bp's,
9666 and/or giving them pointers back to their referencing bpstat's, and
9667 teaching delete_breakpoint to only free a bp's storage when no more
9668 references were extent. A cheaper bandaid was chosen. */
9669 if (bpt
->type
== bp_none
)
9672 /* At least avoid this stale reference until the reference counting of
9673 breakpoints gets resolved. */
9674 if (bpt
->related_breakpoint
!= NULL
)
9676 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9677 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9678 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9679 bpt
->related_breakpoint
= NULL
;
9682 observer_notify_breakpoint_deleted (bpt
->number
);
9684 if (breakpoint_chain
== bpt
)
9685 breakpoint_chain
= bpt
->next
;
9690 b
->next
= bpt
->next
;
9694 decref_counted_command_line (&bpt
->commands
);
9695 xfree (bpt
->cond_string
);
9696 xfree (bpt
->cond_exp
);
9697 xfree (bpt
->addr_string
);
9699 xfree (bpt
->exp_string
);
9700 xfree (bpt
->exp_string_reparse
);
9701 value_free (bpt
->val
);
9702 xfree (bpt
->source_file
);
9703 xfree (bpt
->exec_pathname
);
9704 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9707 /* Be sure no bpstat's are pointing at the breakpoint after it's
9709 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
9710 in all threeds for now. Note that we cannot just remove bpstats
9711 pointing at bpt from the stop_bpstat list entirely, as breakpoint
9712 commands are associated with the bpstat; if we remove it here,
9713 then the later call to bpstat_do_actions (&stop_bpstat); in
9714 event-top.c won't do anything, and temporary breakpoints with
9715 commands won't work. */
9717 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9719 /* Now that breakpoint is removed from breakpoint
9720 list, update the global location list. This
9721 will remove locations that used to belong to
9722 this breakpoint. Do this before freeing
9723 the breakpoint itself, since remove_breakpoint
9724 looks at location's owner. It might be better
9725 design to have location completely self-contained,
9726 but it's not the case now. */
9727 update_global_location_list (0);
9730 /* On the chance that someone will soon try again to delete this same
9731 bp, we mark it as deleted before freeing its storage. */
9732 bpt
->type
= bp_none
;
9738 do_delete_breakpoint_cleanup (void *b
)
9740 delete_breakpoint (b
);
9744 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9746 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9749 /* A callback for map_breakpoint_numbers that calls
9750 delete_breakpoint. */
9753 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9755 delete_breakpoint (b
);
9759 delete_command (char *arg
, int from_tty
)
9761 struct breakpoint
*b
, *temp
;
9767 int breaks_to_delete
= 0;
9769 /* Delete all breakpoints if no argument.
9770 Do not delete internal or call-dummy breakpoints, these
9771 have to be deleted with an explicit breakpoint number argument. */
9774 if (b
->type
!= bp_call_dummy
9775 && b
->type
!= bp_std_terminate
9776 && b
->type
!= bp_shlib_event
9777 && b
->type
!= bp_jit_event
9778 && b
->type
!= bp_thread_event
9779 && b
->type
!= bp_overlay_event
9780 && b
->type
!= bp_longjmp_master
9781 && b
->type
!= bp_std_terminate_master
9784 breaks_to_delete
= 1;
9789 /* Ask user only if there are some breakpoints to delete. */
9791 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9793 ALL_BREAKPOINTS_SAFE (b
, temp
)
9795 if (b
->type
!= bp_call_dummy
9796 && b
->type
!= bp_std_terminate
9797 && b
->type
!= bp_shlib_event
9798 && b
->type
!= bp_thread_event
9799 && b
->type
!= bp_jit_event
9800 && b
->type
!= bp_overlay_event
9801 && b
->type
!= bp_longjmp_master
9802 && b
->type
!= bp_std_terminate_master
9804 delete_breakpoint (b
);
9809 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9813 all_locations_are_pending (struct bp_location
*loc
)
9815 for (; loc
; loc
= loc
->next
)
9816 if (!loc
->shlib_disabled
)
9821 /* Subroutine of update_breakpoint_locations to simplify it.
9822 Return non-zero if multiple fns in list LOC have the same name.
9823 Null names are ignored. */
9826 ambiguous_names_p (struct bp_location
*loc
)
9828 struct bp_location
*l
;
9829 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9830 (int (*) (const void *,
9831 const void *)) streq
,
9832 NULL
, xcalloc
, xfree
);
9834 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9837 const char *name
= l
->function_name
;
9839 /* Allow for some names to be NULL, ignore them. */
9843 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9845 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9859 /* When symbols change, it probably means the sources changed as well,
9860 and it might mean the static tracepoint markers are no longer at
9861 the same address or line numbers they used to be at last we
9862 checked. Losing your static tracepoints whenever you rebuild is
9863 undesirable. This function tries to resync/rematch gdb static
9864 tracepoints with the markers on the target, for static tracepoints
9865 that have not been set by marker id. Static tracepoint that have
9866 been set by marker id are reset by marker id in breakpoint_re_set.
9869 1) For a tracepoint set at a specific address, look for a marker at
9870 the old PC. If one is found there, assume to be the same marker.
9871 If the name / string id of the marker found is different from the
9872 previous known name, assume that means the user renamed the marker
9873 in the sources, and output a warning.
9875 2) For a tracepoint set at a given line number, look for a marker
9876 at the new address of the old line number. If one is found there,
9877 assume to be the same marker. If the name / string id of the
9878 marker found is different from the previous known name, assume that
9879 means the user renamed the marker in the sources, and output a
9882 3) If a marker is no longer found at the same address or line, it
9883 may mean the marker no longer exists. But it may also just mean
9884 the code changed a bit. Maybe the user added a few lines of code
9885 that made the marker move up or down (in line number terms). Ask
9886 the target for info about the marker with the string id as we knew
9887 it. If found, update line number and address in the matching
9888 static tracepoint. This will get confused if there's more than one
9889 marker with the same ID (possible in UST, although unadvised
9890 precisely because it confuses tools). */
9892 static struct symtab_and_line
9893 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
9895 struct static_tracepoint_marker marker
;
9901 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
9903 if (target_static_tracepoint_marker_at (pc
, &marker
))
9905 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
9906 warning (_("static tracepoint %d changed probed marker from %s to %s"),
9908 b
->static_trace_marker_id
, marker
.str_id
);
9910 xfree (b
->static_trace_marker_id
);
9911 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9912 release_static_tracepoint_marker (&marker
);
9917 /* Old marker wasn't found on target at lineno. Try looking it up
9919 if (!sal
.explicit_pc
9921 && sal
.symtab
!= NULL
9922 && b
->static_trace_marker_id
!= NULL
)
9924 VEC(static_tracepoint_marker_p
) *markers
;
9927 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
9929 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
9931 struct symtab_and_line sal
;
9933 struct static_tracepoint_marker
*marker
;
9935 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
9937 xfree (b
->static_trace_marker_id
);
9938 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
9940 warning (_("marker for static tracepoint %d (%s) not "
9941 "found at previous line number"),
9942 b
->number
, b
->static_trace_marker_id
);
9946 sal
.pc
= marker
->address
;
9948 sal
= find_pc_line (marker
->address
, 0);
9949 sym
= find_pc_sect_function (marker
->address
, NULL
);
9950 ui_out_text (uiout
, "Now in ");
9953 ui_out_field_string (uiout
, "func",
9954 SYMBOL_PRINT_NAME (sym
));
9955 ui_out_text (uiout
, " at ");
9957 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
9958 ui_out_text (uiout
, ":");
9960 if (ui_out_is_mi_like_p (uiout
))
9962 char *fullname
= symtab_to_fullname (sal
.symtab
);
9965 ui_out_field_string (uiout
, "fullname", fullname
);
9968 ui_out_field_int (uiout
, "line", sal
.line
);
9969 ui_out_text (uiout
, "\n");
9971 b
->line_number
= sal
.line
;
9973 xfree (b
->source_file
);
9975 b
->source_file
= xstrdup (sal
.symtab
->filename
);
9977 b
->source_file
= NULL
;
9979 xfree (b
->addr_string
);
9980 b
->addr_string
= xstrprintf ("%s:%d",
9981 sal
.symtab
->filename
, b
->line_number
);
9983 /* Might be nice to check if function changed, and warn if
9986 release_static_tracepoint_marker (marker
);
9993 update_breakpoint_locations (struct breakpoint
*b
,
9994 struct symtabs_and_lines sals
)
9998 struct bp_location
*existing_locations
= b
->loc
;
10000 /* If there's no new locations, and all existing locations
10001 are pending, don't do anything. This optimizes
10002 the common case where all locations are in the same
10003 shared library, that was unloaded. We'd like to
10004 retain the location, so that when the library
10005 is loaded again, we don't loose the enabled/disabled
10006 status of the individual locations. */
10007 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10012 for (i
= 0; i
< sals
.nelts
; ++i
)
10014 struct bp_location
*new_loc
=
10015 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10017 /* Reparse conditions, they might contain references to the
10019 if (b
->cond_string
!= NULL
)
10021 struct gdb_exception e
;
10023 s
= b
->cond_string
;
10024 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10026 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10031 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
10032 b
->number
, e
.message
);
10033 new_loc
->enabled
= 0;
10037 if (b
->source_file
!= NULL
)
10038 xfree (b
->source_file
);
10039 if (sals
.sals
[i
].symtab
== NULL
)
10040 b
->source_file
= NULL
;
10042 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10044 if (b
->line_number
== 0)
10045 b
->line_number
= sals
.sals
[i
].line
;
10048 /* Update locations of permanent breakpoints. */
10049 if (b
->enable_state
== bp_permanent
)
10050 make_breakpoint_permanent (b
);
10052 /* If possible, carry over 'disable' status from existing breakpoints. */
10054 struct bp_location
*e
= existing_locations
;
10055 /* If there are multiple breakpoints with the same function name,
10056 e.g. for inline functions, comparing function names won't work.
10057 Instead compare pc addresses; this is just a heuristic as things
10058 may have moved, but in practice it gives the correct answer
10059 often enough until a better solution is found. */
10060 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10062 for (; e
; e
= e
->next
)
10064 if (!e
->enabled
&& e
->function_name
)
10066 struct bp_location
*l
= b
->loc
;
10067 if (have_ambiguous_names
)
10069 for (; l
; l
= l
->next
)
10070 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10071 l
->pspace
->aspace
, l
->address
))
10079 for (; l
; l
= l
->next
)
10080 if (l
->function_name
10081 && strcmp (e
->function_name
, l
->function_name
) == 0)
10091 update_global_location_list (1);
10094 /* Reset a breakpoint given it's struct breakpoint * BINT.
10095 The value we return ends up being the return value from catch_errors.
10096 Unused in this case. */
10099 breakpoint_re_set_one (void *bint
)
10101 /* get past catch_errs */
10102 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10104 int *not_found_ptr
= ¬_found
;
10105 struct symtabs_and_lines sals
= {0};
10106 struct symtabs_and_lines expanded
= {0};
10108 struct gdb_exception e
;
10109 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10110 int marker_spec
= 0;
10115 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10118 case bp_breakpoint
:
10119 case bp_hardware_breakpoint
:
10120 case bp_tracepoint
:
10121 case bp_fast_tracepoint
:
10122 case bp_static_tracepoint
:
10123 /* Do not attempt to re-set breakpoints disabled during startup. */
10124 if (b
->enable_state
== bp_startup_disabled
)
10127 if (b
->addr_string
== NULL
)
10129 /* Anything without a string can't be re-set. */
10130 delete_breakpoint (b
);
10134 input_radix
= b
->input_radix
;
10135 s
= b
->addr_string
;
10137 save_current_space_and_thread ();
10138 switch_to_program_space_and_thread (b
->pspace
);
10140 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10142 set_language (b
->language
);
10143 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10147 sals
= decode_static_tracepoint_spec (&s
);
10148 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10150 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10154 error (_("marker %s not found"), b
->static_trace_marker_id
);
10157 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
10162 int not_found_and_ok
= 0;
10163 /* For pending breakpoints, it's expected that parsing
10164 will fail until the right shared library is loaded.
10165 User has already told to create pending breakpoints and
10166 don't need extra messages. If breakpoint is in bp_shlib_disabled
10167 state, then user already saw the message about that breakpoint
10168 being disabled, and don't want to see more errors. */
10170 && (b
->condition_not_parsed
10171 || (b
->loc
&& b
->loc
->shlib_disabled
)
10172 || b
->enable_state
== bp_disabled
))
10173 not_found_and_ok
= 1;
10175 if (!not_found_and_ok
)
10177 /* We surely don't want to warn about the same breakpoint
10178 10 times. One solution, implemented here, is disable
10179 the breakpoint on error. Another solution would be to
10180 have separate 'warning emitted' flag. Since this
10181 happens only when a binary has changed, I don't know
10182 which approach is better. */
10183 b
->enable_state
= bp_disabled
;
10184 throw_exception (e
);
10190 gdb_assert (sals
.nelts
== 1);
10192 resolve_sal_pc (&sals
.sals
[0]);
10193 if (b
->condition_not_parsed
&& s
&& s
[0])
10195 char *cond_string
= 0;
10199 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10200 &cond_string
, &thread
, &task
);
10202 b
->cond_string
= cond_string
;
10203 b
->thread
= thread
;
10205 b
->condition_not_parsed
= 0;
10208 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10209 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10211 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10214 make_cleanup (xfree
, sals
.sals
);
10215 update_breakpoint_locations (b
, expanded
);
10218 case bp_watchpoint
:
10219 case bp_hardware_watchpoint
:
10220 case bp_read_watchpoint
:
10221 case bp_access_watchpoint
:
10222 /* Watchpoint can be either on expression using entirely global variables,
10223 or it can be on local variables.
10225 Watchpoints of the first kind are never auto-deleted, and even persist
10226 across program restarts. Since they can use variables from shared
10227 libraries, we need to reparse expression as libraries are loaded
10230 Watchpoints on local variables can also change meaning as result
10231 of solib event. For example, if a watchpoint uses both a local and
10232 a global variables in expression, it's a local watchpoint, but
10233 unloading of a shared library will make the expression invalid.
10234 This is not a very common use case, but we still re-evaluate
10235 expression, to avoid surprises to the user.
10237 Note that for local watchpoints, we re-evaluate it only if
10238 watchpoints frame id is still valid. If it's not, it means
10239 the watchpoint is out of scope and will be deleted soon. In fact,
10240 I'm not sure we'll ever be called in this case.
10242 If a local watchpoint's frame id is still valid, then
10243 b->exp_valid_block is likewise valid, and we can safely use it.
10245 Don't do anything about disabled watchpoints, since they will
10246 be reevaluated again when enabled. */
10247 update_watchpoint (b
, 1 /* reparse */);
10249 /* We needn't really do anything to reset these, since the mask
10250 that requests them is unaffected by e.g., new libraries being
10252 case bp_catchpoint
:
10256 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10258 /* Delete overlay event and longjmp master breakpoints; they will be
10259 reset later by breakpoint_re_set. */
10260 case bp_overlay_event
:
10261 case bp_longjmp_master
:
10262 case bp_std_terminate_master
:
10263 delete_breakpoint (b
);
10266 /* This breakpoint is special, it's set up when the inferior
10267 starts and we really don't want to touch it. */
10268 case bp_shlib_event
:
10270 /* Like bp_shlib_event, this breakpoint type is special.
10271 Once it is set up, we do not want to touch it. */
10272 case bp_thread_event
:
10274 /* Keep temporary breakpoints, which can be encountered when we step
10275 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
10276 Otherwise these should have been blown away via the cleanup chain
10277 or by breakpoint_init_inferior when we rerun the executable. */
10280 case bp_watchpoint_scope
:
10281 case bp_call_dummy
:
10282 case bp_std_terminate
:
10283 case bp_step_resume
:
10285 case bp_longjmp_resume
:
10290 do_cleanups (cleanups
);
10294 /* Re-set all breakpoints after symbols have been re-loaded. */
10296 breakpoint_re_set (void)
10298 struct breakpoint
*b
, *temp
;
10299 enum language save_language
;
10300 int save_input_radix
;
10301 struct cleanup
*old_chain
;
10303 save_language
= current_language
->la_language
;
10304 save_input_radix
= input_radix
;
10305 old_chain
= save_current_program_space ();
10307 ALL_BREAKPOINTS_SAFE (b
, temp
)
10309 /* Format possible error msg */
10310 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10312 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10313 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10314 do_cleanups (cleanups
);
10316 set_language (save_language
);
10317 input_radix
= save_input_radix
;
10319 jit_breakpoint_re_set ();
10321 do_cleanups (old_chain
);
10323 create_overlay_event_breakpoint ("_ovly_debug_event");
10324 create_longjmp_master_breakpoint ("longjmp");
10325 create_longjmp_master_breakpoint ("_longjmp");
10326 create_longjmp_master_breakpoint ("siglongjmp");
10327 create_longjmp_master_breakpoint ("_siglongjmp");
10328 create_std_terminate_master_breakpoint ("std::terminate()");
10331 /* Reset the thread number of this breakpoint:
10333 - If the breakpoint is for all threads, leave it as-is.
10334 - Else, reset it to the current thread for inferior_ptid. */
10336 breakpoint_re_set_thread (struct breakpoint
*b
)
10338 if (b
->thread
!= -1)
10340 if (in_thread_list (inferior_ptid
))
10341 b
->thread
= pid_to_thread_id (inferior_ptid
);
10343 /* We're being called after following a fork. The new fork is
10344 selected as current, and unless this was a vfork will have a
10345 different program space from the original thread. Reset that
10347 b
->loc
->pspace
= current_program_space
;
10351 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10352 If from_tty is nonzero, it prints a message to that effect,
10353 which ends with a period (no newline). */
10356 set_ignore_count (int bptnum
, int count
, int from_tty
)
10358 struct breakpoint
*b
;
10363 ALL_BREAKPOINTS (b
)
10364 if (b
->number
== bptnum
)
10366 if (is_tracepoint (b
))
10368 if (from_tty
&& count
!= 0)
10369 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10374 b
->ignore_count
= count
;
10378 printf_filtered (_("Will stop next time breakpoint %d is reached."),
10380 else if (count
== 1)
10381 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10384 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
10387 breakpoints_changed ();
10388 observer_notify_breakpoint_modified (b
->number
);
10392 error (_("No breakpoint number %d."), bptnum
);
10396 make_breakpoint_silent (struct breakpoint
*b
)
10398 /* Silence the breakpoint. */
10402 /* Command to set ignore-count of breakpoint N to COUNT. */
10405 ignore_command (char *args
, int from_tty
)
10411 error_no_arg (_("a breakpoint number"));
10413 num
= get_number (&p
);
10415 error (_("bad breakpoint number: '%s'"), args
);
10417 error (_("Second argument (specified ignore-count) is missing."));
10419 set_ignore_count (num
,
10420 longest_to_int (value_as_long (parse_and_eval (p
))),
10423 printf_filtered ("\n");
10426 /* Call FUNCTION on each of the breakpoints
10427 whose numbers are given in ARGS. */
10430 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10437 struct breakpoint
*b
, *tmp
;
10441 error_no_arg (_("one or more breakpoint numbers"));
10448 num
= get_number_or_range (&p1
);
10451 warning (_("bad breakpoint number at or near '%s'"), p
);
10455 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10456 if (b
->number
== num
)
10458 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10460 function (b
, data
);
10461 if (related_breakpoint
)
10462 function (related_breakpoint
, data
);
10466 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
10472 static struct bp_location
*
10473 find_location_by_number (char *number
)
10475 char *dot
= strchr (number
, '.');
10479 struct breakpoint
*b
;
10480 struct bp_location
*loc
;
10485 bp_num
= get_number_or_range (&p1
);
10487 error (_("Bad breakpoint number '%s'"), number
);
10489 ALL_BREAKPOINTS (b
)
10490 if (b
->number
== bp_num
)
10495 if (!b
|| b
->number
!= bp_num
)
10496 error (_("Bad breakpoint number '%s'"), number
);
10499 loc_num
= get_number_or_range (&p1
);
10501 error (_("Bad breakpoint location number '%s'"), number
);
10505 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
10508 error (_("Bad breakpoint location number '%s'"), dot
+1);
10514 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10515 If from_tty is nonzero, it prints a message to that effect,
10516 which ends with a period (no newline). */
10519 disable_breakpoint (struct breakpoint
*bpt
)
10521 /* Never disable a watchpoint scope breakpoint; we want to
10522 hit them when we leave scope so we can delete both the
10523 watchpoint and its scope breakpoint at that time. */
10524 if (bpt
->type
== bp_watchpoint_scope
)
10527 /* You can't disable permanent breakpoints. */
10528 if (bpt
->enable_state
== bp_permanent
)
10531 bpt
->enable_state
= bp_disabled
;
10533 update_global_location_list (0);
10535 observer_notify_breakpoint_modified (bpt
->number
);
10538 /* A callback for map_breakpoint_numbers that calls
10539 disable_breakpoint. */
10542 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
10544 disable_breakpoint (b
);
10548 disable_command (char *args
, int from_tty
)
10550 struct breakpoint
*bpt
;
10553 ALL_BREAKPOINTS (bpt
)
10557 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10560 case bp_breakpoint
:
10561 case bp_tracepoint
:
10562 case bp_fast_tracepoint
:
10563 case bp_static_tracepoint
:
10564 case bp_catchpoint
:
10565 case bp_hardware_breakpoint
:
10566 case bp_watchpoint
:
10567 case bp_hardware_watchpoint
:
10568 case bp_read_watchpoint
:
10569 case bp_access_watchpoint
:
10570 disable_breakpoint (bpt
);
10574 else if (strchr (args
, '.'))
10576 struct bp_location
*loc
= find_location_by_number (args
);
10579 update_global_location_list (0);
10582 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10586 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10588 int target_resources_ok
;
10590 if (bpt
->type
== bp_hardware_breakpoint
)
10593 i
= hw_breakpoint_used_count ();
10594 target_resources_ok
=
10595 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10597 if (target_resources_ok
== 0)
10598 error (_("No hardware breakpoint support in the target."));
10599 else if (target_resources_ok
< 0)
10600 error (_("Hardware breakpoints used exceeds limit."));
10603 if (is_watchpoint (bpt
))
10605 struct gdb_exception e
;
10607 TRY_CATCH (e
, RETURN_MASK_ALL
)
10609 update_watchpoint (bpt
, 1 /* reparse */);
10613 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10619 if (bpt
->enable_state
!= bp_permanent
)
10620 bpt
->enable_state
= bp_enabled
;
10621 bpt
->disposition
= disposition
;
10622 update_global_location_list (1);
10623 breakpoints_changed ();
10625 observer_notify_breakpoint_modified (bpt
->number
);
10630 enable_breakpoint (struct breakpoint
*bpt
)
10632 do_enable_breakpoint (bpt
, bpt
->disposition
);
10635 /* A callback for map_breakpoint_numbers that calls
10636 enable_breakpoint. */
10639 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10641 enable_breakpoint (b
);
10644 /* The enable command enables the specified breakpoints (or all defined
10645 breakpoints) so they once again become (or continue to be) effective
10646 in stopping the inferior. */
10649 enable_command (char *args
, int from_tty
)
10651 struct breakpoint
*bpt
;
10654 ALL_BREAKPOINTS (bpt
)
10658 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10661 case bp_breakpoint
:
10662 case bp_tracepoint
:
10663 case bp_fast_tracepoint
:
10664 case bp_static_tracepoint
:
10665 case bp_catchpoint
:
10666 case bp_hardware_breakpoint
:
10667 case bp_watchpoint
:
10668 case bp_hardware_watchpoint
:
10669 case bp_read_watchpoint
:
10670 case bp_access_watchpoint
:
10671 enable_breakpoint (bpt
);
10675 else if (strchr (args
, '.'))
10677 struct bp_location
*loc
= find_location_by_number (args
);
10680 update_global_location_list (1);
10683 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10687 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10689 do_enable_breakpoint (bpt
, disp_disable
);
10693 enable_once_command (char *args
, int from_tty
)
10695 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10699 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10701 do_enable_breakpoint (bpt
, disp_del
);
10705 enable_delete_command (char *args
, int from_tty
)
10707 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10711 set_breakpoint_cmd (char *args
, int from_tty
)
10716 show_breakpoint_cmd (char *args
, int from_tty
)
10720 /* Invalidate last known value of any hardware watchpoint if
10721 the memory which that value represents has been written to by
10725 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10726 const bfd_byte
*data
)
10728 struct breakpoint
*bp
;
10730 ALL_BREAKPOINTS (bp
)
10731 if (bp
->enable_state
== bp_enabled
10732 && bp
->type
== bp_hardware_watchpoint
10733 && bp
->val_valid
&& bp
->val
)
10735 struct bp_location
*loc
;
10737 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10738 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10739 && loc
->address
+ loc
->length
> addr
10740 && addr
+ len
> loc
->address
)
10742 value_free (bp
->val
);
10749 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10751 struct symtabs_and_lines
10752 decode_line_spec_1 (char *string
, int funfirstline
)
10754 struct symtabs_and_lines sals
;
10757 error (_("Empty line specification."));
10758 if (default_breakpoint_valid
)
10759 sals
= decode_line_1 (&string
, funfirstline
,
10760 default_breakpoint_symtab
,
10761 default_breakpoint_line
,
10762 (char ***) NULL
, NULL
);
10764 sals
= decode_line_1 (&string
, funfirstline
,
10765 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10767 error (_("Junk at end of line specification: %s"), string
);
10771 /* Create and insert a raw software breakpoint at PC. Return an
10772 identifier, which should be used to remove the breakpoint later.
10773 In general, places which call this should be using something on the
10774 breakpoint chain instead; this function should be eliminated
10778 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10779 struct address_space
*aspace
, CORE_ADDR pc
)
10781 struct bp_target_info
*bp_tgt
;
10783 bp_tgt
= XZALLOC (struct bp_target_info
);
10785 bp_tgt
->placed_address_space
= aspace
;
10786 bp_tgt
->placed_address
= pc
;
10788 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10790 /* Could not insert the breakpoint. */
10798 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10801 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10803 struct bp_target_info
*bp_tgt
= bp
;
10806 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10812 /* One (or perhaps two) breakpoints used for software single stepping. */
10814 static void *single_step_breakpoints
[2];
10815 static struct gdbarch
*single_step_gdbarch
[2];
10817 /* Create and insert a breakpoint for software single step. */
10820 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10821 struct address_space
*aspace
, CORE_ADDR next_pc
)
10825 if (single_step_breakpoints
[0] == NULL
)
10827 bpt_p
= &single_step_breakpoints
[0];
10828 single_step_gdbarch
[0] = gdbarch
;
10832 gdb_assert (single_step_breakpoints
[1] == NULL
);
10833 bpt_p
= &single_step_breakpoints
[1];
10834 single_step_gdbarch
[1] = gdbarch
;
10837 /* NOTE drow/2006-04-11: A future improvement to this function would be
10838 to only create the breakpoints once, and actually put them on the
10839 breakpoint chain. That would let us use set_raw_breakpoint. We could
10840 adjust the addresses each time they were needed. Doing this requires
10841 corresponding changes elsewhere where single step breakpoints are
10842 handled, however. So, for now, we use this. */
10844 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10845 if (*bpt_p
== NULL
)
10846 error (_("Could not insert single-step breakpoint at %s"),
10847 paddress (gdbarch
, next_pc
));
10850 /* Check if the breakpoints used for software single stepping
10851 were inserted or not. */
10854 single_step_breakpoints_inserted (void)
10856 return (single_step_breakpoints
[0] != NULL
10857 || single_step_breakpoints
[1] != NULL
);
10860 /* Remove and delete any breakpoints used for software single step. */
10863 remove_single_step_breakpoints (void)
10865 gdb_assert (single_step_breakpoints
[0] != NULL
);
10867 /* See insert_single_step_breakpoint for more about this deprecated
10869 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10870 single_step_breakpoints
[0]);
10871 single_step_gdbarch
[0] = NULL
;
10872 single_step_breakpoints
[0] = NULL
;
10874 if (single_step_breakpoints
[1] != NULL
)
10876 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10877 single_step_breakpoints
[1]);
10878 single_step_gdbarch
[1] = NULL
;
10879 single_step_breakpoints
[1] = NULL
;
10883 /* Delete software single step breakpoints without removing them from
10884 the inferior. This is intended to be used if the inferior's address
10885 space where they were inserted is already gone, e.g. after exit or
10889 cancel_single_step_breakpoints (void)
10893 for (i
= 0; i
< 2; i
++)
10894 if (single_step_breakpoints
[i
])
10896 xfree (single_step_breakpoints
[i
]);
10897 single_step_breakpoints
[i
] = NULL
;
10898 single_step_gdbarch
[i
] = NULL
;
10902 /* Detach software single-step breakpoints from INFERIOR_PTID without
10906 detach_single_step_breakpoints (void)
10910 for (i
= 0; i
< 2; i
++)
10911 if (single_step_breakpoints
[i
])
10912 target_remove_breakpoint (single_step_gdbarch
[i
],
10913 single_step_breakpoints
[i
]);
10916 /* Check whether a software single-step breakpoint is inserted at PC. */
10919 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
10924 for (i
= 0; i
< 2; i
++)
10926 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10928 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10929 bp_tgt
->placed_address
,
10937 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10938 non-zero otherwise. */
10940 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10942 if (syscall_catchpoint_p (bp
)
10943 && bp
->enable_state
!= bp_disabled
10944 && bp
->enable_state
!= bp_call_disabled
)
10951 catch_syscall_enabled (void)
10953 struct inferior
*inf
= current_inferior ();
10955 return inf
->total_syscalls_count
!= 0;
10959 catching_syscall_number (int syscall_number
)
10961 struct breakpoint
*bp
;
10963 ALL_BREAKPOINTS (bp
)
10964 if (is_syscall_catchpoint_enabled (bp
))
10966 if (bp
->syscalls_to_be_caught
)
10970 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10972 if (syscall_number
== iter
)
10982 /* Complete syscall names. Used by "catch syscall". */
10984 catch_syscall_completer (struct cmd_list_element
*cmd
,
10985 char *text
, char *word
)
10987 const char **list
= get_syscall_names ();
10989 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10992 /* Tracepoint-specific operations. */
10994 /* Set tracepoint count to NUM. */
10996 set_tracepoint_count (int num
)
10998 tracepoint_count
= num
;
10999 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11003 trace_command (char *arg
, int from_tty
)
11005 if (create_breakpoint (get_current_arch (),
11007 NULL
, 0, 1 /* parse arg */,
11009 bp_tracepoint
/* type_wanted */,
11010 0 /* Ignore count */,
11011 pending_break_support
,
11015 set_tracepoint_count (breakpoint_count
);
11019 ftrace_command (char *arg
, int from_tty
)
11021 if (create_breakpoint (get_current_arch (),
11023 NULL
, 0, 1 /* parse arg */,
11025 bp_fast_tracepoint
/* type_wanted */,
11026 0 /* Ignore count */,
11027 pending_break_support
,
11031 set_tracepoint_count (breakpoint_count
);
11034 /* strace command implementation. Creates a static tracepoint. */
11037 strace_command (char *arg
, int from_tty
)
11039 if (create_breakpoint (get_current_arch (),
11041 NULL
, 0, 1 /* parse arg */,
11043 bp_static_tracepoint
/* type_wanted */,
11044 0 /* Ignore count */,
11045 pending_break_support
,
11049 set_tracepoint_count (breakpoint_count
);
11052 /* Set up a fake reader function that gets command lines from a linked
11053 list that was acquired during tracepoint uploading. */
11055 static struct uploaded_tp
*this_utp
;
11056 static int next_cmd
;
11059 read_uploaded_action (void)
11063 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11070 /* Given information about a tracepoint as recorded on a target (which
11071 can be either a live system or a trace file), attempt to create an
11072 equivalent GDB tracepoint. This is not a reliable process, since
11073 the target does not necessarily have all the information used when
11074 the tracepoint was originally defined. */
11076 struct breakpoint
*
11077 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11079 char *addr_str
, small_buf
[100];
11080 struct breakpoint
*tp
;
11082 if (utp
->at_string
)
11083 addr_str
= utp
->at_string
;
11086 /* In the absence of a source location, fall back to raw
11087 address. Since there is no way to confirm that the address
11088 means the same thing as when the trace was started, warn the
11090 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
11092 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11093 addr_str
= small_buf
;
11096 /* There's not much we can do with a sequence of bytecodes. */
11097 if (utp
->cond
&& !utp
->cond_string
)
11098 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
11101 if (!create_breakpoint (get_current_arch (),
11103 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11105 utp
->type
/* type_wanted */,
11106 0 /* Ignore count */,
11107 pending_break_support
,
11110 utp
->enabled
/* enabled */))
11113 set_tracepoint_count (breakpoint_count
);
11115 /* Get the tracepoint we just created. */
11116 tp
= get_tracepoint (tracepoint_count
);
11117 gdb_assert (tp
!= NULL
);
11121 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11123 trace_pass_command (small_buf
, 0);
11126 /* If we have uploaded versions of the original commands, set up a
11127 special-purpose "reader" function and call the usual command line
11128 reader, then pass the result to the breakpoint command-setting
11130 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11132 struct command_line
*cmd_list
;
11137 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11139 breakpoint_set_commands (tp
, cmd_list
);
11141 else if (!VEC_empty (char_ptr
, utp
->actions
)
11142 || !VEC_empty (char_ptr
, utp
->step_actions
))
11143 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
11149 /* Print information on tracepoint number TPNUM_EXP, or all if
11153 tracepoints_info (char *tpnum_exp
, int from_tty
)
11155 int tpnum
= -1, num_printed
;
11158 tpnum
= parse_and_eval_long (tpnum_exp
);
11160 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
11162 if (num_printed
== 0)
11165 ui_out_message (uiout
, 0, "No tracepoints.\n");
11167 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
11170 default_collect_info ();
11173 /* The 'enable trace' command enables tracepoints.
11174 Not supported by all targets. */
11176 enable_trace_command (char *args
, int from_tty
)
11178 enable_command (args
, from_tty
);
11181 /* The 'disable trace' command disables tracepoints.
11182 Not supported by all targets. */
11184 disable_trace_command (char *args
, int from_tty
)
11186 disable_command (args
, from_tty
);
11189 /* Remove a tracepoint (or all if no argument) */
11191 delete_trace_command (char *arg
, int from_tty
)
11193 struct breakpoint
*b
, *temp
;
11199 int breaks_to_delete
= 0;
11201 /* Delete all breakpoints if no argument.
11202 Do not delete internal or call-dummy breakpoints, these
11203 have to be deleted with an explicit breakpoint number argument. */
11204 ALL_TRACEPOINTS (b
)
11206 if (b
->number
>= 0)
11208 breaks_to_delete
= 1;
11213 /* Ask user only if there are some breakpoints to delete. */
11215 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11217 ALL_BREAKPOINTS_SAFE (b
, temp
)
11219 if (is_tracepoint (b
)
11221 delete_breakpoint (b
);
11226 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11229 /* Set passcount for tracepoint.
11231 First command argument is passcount, second is tracepoint number.
11232 If tracepoint number omitted, apply to most recently defined.
11233 Also accepts special argument "all". */
11236 trace_pass_command (char *args
, int from_tty
)
11238 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11239 unsigned int count
;
11242 if (args
== 0 || *args
== 0)
11243 error (_("passcount command requires an argument (count + optional TP num)"));
11245 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11247 while (*args
&& isspace ((int) *args
))
11250 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11252 args
+= 3; /* Skip special argument "all". */
11255 error (_("Junk at end of arguments."));
11258 t1
= get_tracepoint_by_number (&args
, 1, 1);
11264 ALL_TRACEPOINTS (t2
)
11265 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11267 t2
->pass_count
= count
;
11268 observer_notify_tracepoint_modified (t2
->number
);
11270 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
11271 t2
->number
, count
);
11273 if (! all
&& *args
)
11274 t1
= get_tracepoint_by_number (&args
, 1, 0);
11280 struct breakpoint
*
11281 get_tracepoint (int num
)
11283 struct breakpoint
*t
;
11285 ALL_TRACEPOINTS (t
)
11286 if (t
->number
== num
)
11292 /* Find the tracepoint with the given target-side number (which may be
11293 different from the tracepoint number after disconnecting and
11296 struct breakpoint
*
11297 get_tracepoint_by_number_on_target (int num
)
11299 struct breakpoint
*t
;
11301 ALL_TRACEPOINTS (t
)
11302 if (t
->number_on_target
== num
)
11308 /* Utility: parse a tracepoint number and look it up in the list.
11309 If MULTI_P is true, there might be a range of tracepoints in ARG.
11310 if OPTIONAL_P is true, then if the argument is missing, the most
11311 recent tracepoint (tracepoint_count) is returned. */
11312 struct breakpoint
*
11313 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11315 extern int tracepoint_count
;
11316 struct breakpoint
*t
;
11318 char *instring
= arg
== NULL
? NULL
: *arg
;
11320 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11323 tpnum
= tracepoint_count
;
11325 error_no_arg (_("tracepoint number"));
11328 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11332 if (instring
&& *instring
)
11333 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11336 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
11340 ALL_TRACEPOINTS (t
)
11341 if (t
->number
== tpnum
)
11346 /* FIXME: if we are in the middle of a range we don't want to give
11347 a message. The current interface to get_number_or_range doesn't
11348 allow us to discover this. */
11349 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11353 /* Save information on user settable breakpoints (watchpoints, etc) to
11354 a new script file named FILENAME. If FILTER is non-NULL, call it
11355 on each breakpoint and only include the ones for which it returns
11359 save_breakpoints (char *filename
, int from_tty
,
11360 int (*filter
) (const struct breakpoint
*))
11362 struct breakpoint
*tp
;
11365 struct cleanup
*cleanup
;
11366 struct ui_file
*fp
;
11367 int extra_trace_bits
= 0;
11369 if (filename
== 0 || *filename
== 0)
11370 error (_("Argument required (file name in which to save)"));
11372 /* See if we have anything to save. */
11373 ALL_BREAKPOINTS (tp
)
11375 /* Skip internal and momentary breakpoints. */
11376 if (!user_settable_breakpoint (tp
))
11379 /* If we have a filter, only save the breakpoints it accepts. */
11380 if (filter
&& !filter (tp
))
11385 if (is_tracepoint (tp
))
11387 extra_trace_bits
= 1;
11389 /* We can stop searching. */
11396 warning (_("Nothing to save."));
11400 pathname
= tilde_expand (filename
);
11401 cleanup
= make_cleanup (xfree
, pathname
);
11402 fp
= gdb_fopen (pathname
, "w");
11404 error (_("Unable to open file '%s' for saving (%s)"),
11405 filename
, safe_strerror (errno
));
11406 make_cleanup_ui_file_delete (fp
);
11408 if (extra_trace_bits
)
11409 save_trace_state_variables (fp
);
11411 ALL_BREAKPOINTS (tp
)
11413 /* Skip internal and momentary breakpoints. */
11414 if (!user_settable_breakpoint (tp
))
11417 /* If we have a filter, only save the breakpoints it accepts. */
11418 if (filter
&& !filter (tp
))
11421 if (tp
->ops
!= NULL
)
11422 (tp
->ops
->print_recreate
) (tp
, fp
);
11425 if (tp
->type
== bp_fast_tracepoint
)
11426 fprintf_unfiltered (fp
, "ftrace");
11427 if (tp
->type
== bp_static_tracepoint
)
11428 fprintf_unfiltered (fp
, "strace");
11429 else if (tp
->type
== bp_tracepoint
)
11430 fprintf_unfiltered (fp
, "trace");
11431 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11432 fprintf_unfiltered (fp
, "tbreak");
11433 else if (tp
->type
== bp_breakpoint
)
11434 fprintf_unfiltered (fp
, "break");
11435 else if (tp
->type
== bp_hardware_breakpoint
11436 && tp
->disposition
== disp_del
)
11437 fprintf_unfiltered (fp
, "thbreak");
11438 else if (tp
->type
== bp_hardware_breakpoint
)
11439 fprintf_unfiltered (fp
, "hbreak");
11440 else if (tp
->type
== bp_watchpoint
)
11441 fprintf_unfiltered (fp
, "watch");
11442 else if (tp
->type
== bp_hardware_watchpoint
)
11443 fprintf_unfiltered (fp
, "watch");
11444 else if (tp
->type
== bp_read_watchpoint
)
11445 fprintf_unfiltered (fp
, "rwatch");
11446 else if (tp
->type
== bp_access_watchpoint
)
11447 fprintf_unfiltered (fp
, "awatch");
11449 internal_error (__FILE__
, __LINE__
,
11450 _("unhandled breakpoint type %d"), (int) tp
->type
);
11452 if (tp
->exp_string
)
11453 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11454 else if (tp
->addr_string
)
11455 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11460 sprintf_vma (tmp
, tp
->loc
->address
);
11461 fprintf_unfiltered (fp
, " *0x%s", tmp
);
11465 if (tp
->thread
!= -1)
11466 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
11469 fprintf_unfiltered (fp
, " task %d", tp
->task
);
11471 fprintf_unfiltered (fp
, "\n");
11473 /* Note, we can't rely on tp->number for anything, as we can't
11474 assume the recreated breakpoint numbers will match. Use $bpnum
11477 if (tp
->cond_string
)
11478 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
11480 if (tp
->ignore_count
)
11481 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
11483 if (tp
->pass_count
)
11484 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11488 volatile struct gdb_exception ex
;
11490 fprintf_unfiltered (fp
, " commands\n");
11492 ui_out_redirect (uiout
, fp
);
11493 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
11495 print_command_lines (uiout
, tp
->commands
->commands
, 2);
11497 ui_out_redirect (uiout
, NULL
);
11500 throw_exception (ex
);
11502 fprintf_unfiltered (fp
, " end\n");
11505 if (tp
->enable_state
== bp_disabled
)
11506 fprintf_unfiltered (fp
, "disable\n");
11508 /* If this is a multi-location breakpoint, check if the locations
11509 should be individually disabled. Watchpoint locations are
11510 special, and not user visible. */
11511 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
11513 struct bp_location
*loc
;
11516 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
11518 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
11522 if (extra_trace_bits
&& *default_collect
)
11523 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
11525 do_cleanups (cleanup
);
11527 printf_filtered (_("Saved to file '%s'.\n"), filename
);
11530 /* The `save breakpoints' command. */
11533 save_breakpoints_command (char *args
, int from_tty
)
11535 save_breakpoints (args
, from_tty
, NULL
);
11538 /* The `save tracepoints' command. */
11541 save_tracepoints_command (char *args
, int from_tty
)
11543 save_breakpoints (args
, from_tty
, is_tracepoint
);
11546 /* Create a vector of all tracepoints. */
11548 VEC(breakpoint_p
) *
11551 VEC(breakpoint_p
) *tp_vec
= 0;
11552 struct breakpoint
*tp
;
11554 ALL_TRACEPOINTS (tp
)
11556 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
11563 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
11564 It is defined as a macro to prevent duplication.
11565 COMMAND should be a string constant containing the name of the command. */
11566 #define BREAK_ARGS_HELP(command) \
11567 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11568 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11569 If a line number is specified, break at start of code for that line.\n\
11570 If a function is specified, break at start of code for that function.\n\
11571 If an address is specified, break at that exact address.\n\
11572 With no LOCATION, uses current execution address of the selected\n\
11573 stack frame. This is useful for breaking on return to a stack frame.\n\
11575 THREADNUM is the number from \"info threads\".\n\
11576 CONDITION is a boolean expression.\n\
11578 Multiple breakpoints at one place are permitted, and useful if their\n\
11579 conditions are different.\n\
11581 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11583 /* List of subcommands for "catch". */
11584 static struct cmd_list_element
*catch_cmdlist
;
11586 /* List of subcommands for "tcatch". */
11587 static struct cmd_list_element
*tcatch_cmdlist
;
11589 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11590 lists, and pass some additional user data to the command function. */
11592 add_catch_command (char *name
, char *docstring
,
11593 void (*sfunc
) (char *args
, int from_tty
,
11594 struct cmd_list_element
*command
),
11595 char **(*completer
) (struct cmd_list_element
*cmd
,
11596 char *text
, char *word
),
11597 void *user_data_catch
,
11598 void *user_data_tcatch
)
11600 struct cmd_list_element
*command
;
11602 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11604 set_cmd_sfunc (command
, sfunc
);
11605 set_cmd_context (command
, user_data_catch
);
11606 set_cmd_completer (command
, completer
);
11608 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11610 set_cmd_sfunc (command
, sfunc
);
11611 set_cmd_context (command
, user_data_tcatch
);
11612 set_cmd_completer (command
, completer
);
11616 clear_syscall_counts (struct inferior
*inf
)
11618 inf
->total_syscalls_count
= 0;
11619 inf
->any_syscall_count
= 0;
11620 VEC_free (int, inf
->syscalls_counts
);
11624 save_command (char *arg
, int from_tty
)
11626 printf_unfiltered (_("\
11627 \"save\" must be followed by the name of a save subcommand.\n"));
11628 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
11632 _initialize_breakpoint (void)
11634 struct cmd_list_element
*c
;
11636 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
11637 observer_attach_inferior_exit (clear_syscall_counts
);
11638 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
11640 breakpoint_chain
= 0;
11641 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11642 before a breakpoint is set. */
11643 breakpoint_count
= 0;
11645 tracepoint_count
= 0;
11647 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
11648 Set ignore-count of breakpoint number N to COUNT.\n\
11649 Usage is `ignore N COUNT'."));
11651 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
11653 add_com ("commands", class_breakpoint
, commands_command
, _("\
11654 Set commands to be executed when a breakpoint is hit.\n\
11655 Give breakpoint number as argument after \"commands\".\n\
11656 With no argument, the targeted breakpoint is the last one set.\n\
11657 The commands themselves follow starting on the next line.\n\
11658 Type a line containing \"end\" to indicate the end of them.\n\
11659 Give \"silent\" as the first line to make the breakpoint silent;\n\
11660 then no output is printed when it is hit, except what the commands print."));
11662 add_com ("condition", class_breakpoint
, condition_command
, _("\
11663 Specify breakpoint number N to break only if COND is true.\n\
11664 Usage is `condition N COND', where N is an integer and COND is an\n\
11665 expression to be evaluated whenever breakpoint N is reached."));
11667 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
11668 Set a temporary breakpoint.\n\
11669 Like \"break\" except the breakpoint is only temporary,\n\
11670 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11671 by using \"enable delete\" on the breakpoint number.\n\
11673 BREAK_ARGS_HELP ("tbreak")));
11674 set_cmd_completer (c
, location_completer
);
11676 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
11677 Set a hardware assisted breakpoint.\n\
11678 Like \"break\" except the breakpoint requires hardware support,\n\
11679 some target hardware may not have this support.\n\
11681 BREAK_ARGS_HELP ("hbreak")));
11682 set_cmd_completer (c
, location_completer
);
11684 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
11685 Set a temporary hardware assisted breakpoint.\n\
11686 Like \"hbreak\" except the breakpoint is only temporary,\n\
11687 so it will be deleted when hit.\n\
11689 BREAK_ARGS_HELP ("thbreak")));
11690 set_cmd_completer (c
, location_completer
);
11692 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
11693 Enable some breakpoints.\n\
11694 Give breakpoint numbers (separated by spaces) as arguments.\n\
11695 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11696 This is used to cancel the effect of the \"disable\" command.\n\
11697 With a subcommand you can enable temporarily."),
11698 &enablelist
, "enable ", 1, &cmdlist
);
11700 add_com ("ab", class_breakpoint
, enable_command
, _("\
11701 Enable some breakpoints.\n\
11702 Give breakpoint numbers (separated by spaces) as arguments.\n\
11703 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11704 This is used to cancel the effect of the \"disable\" command.\n\
11705 With a subcommand you can enable temporarily."));
11707 add_com_alias ("en", "enable", class_breakpoint
, 1);
11709 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
11710 Enable some breakpoints.\n\
11711 Give breakpoint numbers (separated by spaces) as arguments.\n\
11712 This is used to cancel the effect of the \"disable\" command.\n\
11713 May be abbreviated to simply \"enable\".\n"),
11714 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
11716 add_cmd ("once", no_class
, enable_once_command
, _("\
11717 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11718 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11721 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11722 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11723 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11726 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11727 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11728 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11731 add_cmd ("once", no_class
, enable_once_command
, _("\
11732 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11733 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11736 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
11737 Disable some breakpoints.\n\
11738 Arguments are breakpoint numbers with spaces in between.\n\
11739 To disable all breakpoints, give no argument.\n\
11740 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11741 &disablelist
, "disable ", 1, &cmdlist
);
11742 add_com_alias ("dis", "disable", class_breakpoint
, 1);
11743 add_com_alias ("disa", "disable", class_breakpoint
, 1);
11745 add_com ("sb", class_breakpoint
, disable_command
, _("\
11746 Disable some breakpoints.\n\
11747 Arguments are breakpoint numbers with spaces in between.\n\
11748 To disable all breakpoints, give no argument.\n\
11749 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11751 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
11752 Disable some breakpoints.\n\
11753 Arguments are breakpoint numbers with spaces in between.\n\
11754 To disable all breakpoints, give no argument.\n\
11755 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11756 This command may be abbreviated \"disable\"."),
11759 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
11760 Delete some breakpoints or auto-display expressions.\n\
11761 Arguments are breakpoint numbers with spaces in between.\n\
11762 To delete all breakpoints, give no argument.\n\
11764 Also a prefix command for deletion of other GDB objects.\n\
11765 The \"unset\" command is also an alias for \"delete\"."),
11766 &deletelist
, "delete ", 1, &cmdlist
);
11767 add_com_alias ("d", "delete", class_breakpoint
, 1);
11768 add_com_alias ("del", "delete", class_breakpoint
, 1);
11770 add_com ("db", class_breakpoint
, delete_command
, _("\
11771 Delete some breakpoints.\n\
11772 Arguments are breakpoint numbers with spaces in between.\n\
11773 To delete all breakpoints, give no argument.\n"));
11775 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
11776 Delete some breakpoints or auto-display expressions.\n\
11777 Arguments are breakpoint numbers with spaces in between.\n\
11778 To delete all breakpoints, give no argument.\n\
11779 This command may be abbreviated \"delete\"."),
11782 add_com ("clear", class_breakpoint
, clear_command
, _("\
11783 Clear breakpoint at specified line or function.\n\
11784 Argument may be line number, function name, or \"*\" and an address.\n\
11785 If line number is specified, all breakpoints in that line are cleared.\n\
11786 If function is specified, breakpoints at beginning of function are cleared.\n\
11787 If an address is specified, breakpoints at that address are cleared.\n\
11789 With no argument, clears all breakpoints in the line that the selected frame\n\
11790 is executing in.\n\
11792 See also the \"delete\" command which clears breakpoints by number."));
11793 add_com_alias ("cl", "clear", class_breakpoint
, 1);
11795 c
= add_com ("break", class_breakpoint
, break_command
, _("\
11796 Set breakpoint at specified line or function.\n"
11797 BREAK_ARGS_HELP ("break")));
11798 set_cmd_completer (c
, location_completer
);
11800 add_com_alias ("b", "break", class_run
, 1);
11801 add_com_alias ("br", "break", class_run
, 1);
11802 add_com_alias ("bre", "break", class_run
, 1);
11803 add_com_alias ("brea", "break", class_run
, 1);
11806 add_com_alias ("ba", "break", class_breakpoint
, 1);
11810 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
11811 Break in function/address or break at a line in the current file."),
11812 &stoplist
, "stop ", 1, &cmdlist
);
11813 add_cmd ("in", class_breakpoint
, stopin_command
,
11814 _("Break in function or address."), &stoplist
);
11815 add_cmd ("at", class_breakpoint
, stopat_command
,
11816 _("Break at a line in the current file."), &stoplist
);
11817 add_com ("status", class_info
, breakpoints_info
, _("\
11818 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11819 The \"Type\" column indicates one of:\n\
11820 \tbreakpoint - normal breakpoint\n\
11821 \twatchpoint - watchpoint\n\
11822 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11823 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11824 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11825 address and file/line number respectively.\n\
11827 Convenience variable \"$_\" and default examine address for \"x\"\n\
11828 are set to the address of the last breakpoint listed unless the command\n\
11829 is prefixed with \"server \".\n\n\
11830 Convenience variable \"$bpnum\" contains the number of the last\n\
11831 breakpoint set."));
11834 add_info ("breakpoints", breakpoints_info
, _("\
11835 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11836 The \"Type\" column indicates one of:\n\
11837 \tbreakpoint - normal breakpoint\n\
11838 \twatchpoint - watchpoint\n\
11839 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11840 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11841 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11842 address and file/line number respectively.\n\
11844 Convenience variable \"$_\" and default examine address for \"x\"\n\
11845 are set to the address of the last breakpoint listed unless the command\n\
11846 is prefixed with \"server \".\n\n\
11847 Convenience variable \"$bpnum\" contains the number of the last\n\
11848 breakpoint set."));
11850 add_info_alias ("b", "breakpoints", 1);
11853 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11854 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11855 The \"Type\" column indicates one of:\n\
11856 \tbreakpoint - normal breakpoint\n\
11857 \twatchpoint - watchpoint\n\
11858 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11859 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11860 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11861 address and file/line number respectively.\n\
11863 Convenience variable \"$_\" and default examine address for \"x\"\n\
11864 are set to the address of the last breakpoint listed unless the command\n\
11865 is prefixed with \"server \".\n\n\
11866 Convenience variable \"$bpnum\" contains the number of the last\n\
11867 breakpoint set."));
11869 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11870 Status of all breakpoints, or breakpoint number NUMBER.\n\
11871 The \"Type\" column indicates one of:\n\
11872 \tbreakpoint - normal breakpoint\n\
11873 \twatchpoint - watchpoint\n\
11874 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11875 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11876 \tuntil - internal breakpoint used by the \"until\" command\n\
11877 \tfinish - internal breakpoint used by the \"finish\" command\n\
11878 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11879 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11880 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11881 address and file/line number respectively.\n\
11883 Convenience variable \"$_\" and default examine address for \"x\"\n\
11884 are set to the address of the last breakpoint listed unless the command\n\
11885 is prefixed with \"server \".\n\n\
11886 Convenience variable \"$bpnum\" contains the number of the last\n\
11888 &maintenanceinfolist
);
11890 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11891 Set catchpoints to catch events."),
11892 &catch_cmdlist
, "catch ",
11893 0/*allow-unknown*/, &cmdlist
);
11895 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11896 Set temporary catchpoints to catch events."),
11897 &tcatch_cmdlist
, "tcatch ",
11898 0/*allow-unknown*/, &cmdlist
);
11900 /* Add catch and tcatch sub-commands. */
11901 add_catch_command ("catch", _("\
11902 Catch an exception, when caught.\n\
11903 With an argument, catch only exceptions with the given name."),
11904 catch_catch_command
,
11908 add_catch_command ("throw", _("\
11909 Catch an exception, when thrown.\n\
11910 With an argument, catch only exceptions with the given name."),
11911 catch_throw_command
,
11915 add_catch_command ("fork", _("Catch calls to fork."),
11916 catch_fork_command_1
,
11918 (void *) (uintptr_t) catch_fork_permanent
,
11919 (void *) (uintptr_t) catch_fork_temporary
);
11920 add_catch_command ("vfork", _("Catch calls to vfork."),
11921 catch_fork_command_1
,
11923 (void *) (uintptr_t) catch_vfork_permanent
,
11924 (void *) (uintptr_t) catch_vfork_temporary
);
11925 add_catch_command ("exec", _("Catch calls to exec."),
11926 catch_exec_command_1
,
11930 add_catch_command ("syscall", _("\
11931 Catch system calls by their names and/or numbers.\n\
11932 Arguments say which system calls to catch. If no arguments\n\
11933 are given, every system call will be caught.\n\
11934 Arguments, if given, should be one or more system call names\n\
11935 (if your system supports that), or system call numbers."),
11936 catch_syscall_command_1
,
11937 catch_syscall_completer
,
11940 add_catch_command ("exception", _("\
11941 Catch Ada exceptions, when raised.\n\
11942 With an argument, catch only exceptions with the given name."),
11943 catch_ada_exception_command
,
11947 add_catch_command ("assert", _("\
11948 Catch failed Ada assertions, when raised.\n\
11949 With an argument, catch only exceptions with the given name."),
11950 catch_assert_command
,
11955 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11956 Set a watchpoint for an expression.\n\
11957 Usage: watch [-l|-location] EXPRESSION\n\
11958 A watchpoint stops execution of your program whenever the value of\n\
11959 an expression changes.\n\
11960 If -l or -location is given, this evaluates EXPRESSION and watches\n\
11961 the memory to which it refers."));
11962 set_cmd_completer (c
, expression_completer
);
11964 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11965 Set a read watchpoint for an expression.\n\
11966 Usage: rwatch [-l|-location] EXPRESSION\n\
11967 A watchpoint stops execution of your program whenever the value of\n\
11968 an expression is read.\n\
11969 If -l or -location is given, this evaluates EXPRESSION and watches\n\
11970 the memory to which it refers."));
11971 set_cmd_completer (c
, expression_completer
);
11973 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11974 Set a watchpoint for an expression.\n\
11975 Usage: awatch [-l|-location] EXPRESSION\n\
11976 A watchpoint stops execution of your program whenever the value of\n\
11977 an expression is either read or written.\n\
11978 If -l or -location is given, this evaluates EXPRESSION and watches\n\
11979 the memory to which it refers."));
11980 set_cmd_completer (c
, expression_completer
);
11982 add_info ("watchpoints", watchpoints_info
, _("\
11983 Status of watchpoints, or watchpoint number NUMBER."));
11987 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11988 respond to changes - contrary to the description. */
11989 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11990 &can_use_hw_watchpoints
, _("\
11991 Set debugger's willingness to use watchpoint hardware."), _("\
11992 Show debugger's willingness to use watchpoint hardware."), _("\
11993 If zero, gdb will not use hardware for new watchpoints, even if\n\
11994 such is available. (However, any hardware watchpoints that were\n\
11995 created before setting this to nonzero, will continue to use watchpoint\n\
11998 show_can_use_hw_watchpoints
,
11999 &setlist
, &showlist
);
12001 can_use_hw_watchpoints
= 1;
12003 /* Tracepoint manipulation commands. */
12005 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12006 Set a tracepoint at specified line or function.\n\
12008 BREAK_ARGS_HELP ("trace") "\n\
12009 Do \"help tracepoints\" for info on other tracepoint commands."));
12010 set_cmd_completer (c
, location_completer
);
12012 add_com_alias ("tp", "trace", class_alias
, 0);
12013 add_com_alias ("tr", "trace", class_alias
, 1);
12014 add_com_alias ("tra", "trace", class_alias
, 1);
12015 add_com_alias ("trac", "trace", class_alias
, 1);
12017 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12018 Set a fast tracepoint at specified line or function.\n\
12020 BREAK_ARGS_HELP ("ftrace") "\n\
12021 Do \"help tracepoints\" for info on other tracepoint commands."));
12022 set_cmd_completer (c
, location_completer
);
12024 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12025 Set a static tracepoint at specified line, function or marker.\n\
12027 strace [LOCATION] [if CONDITION]\n\
12028 LOCATION may be a line number, function name, \"*\" and an address,\n\
12029 or -m MARKER_ID.\n\
12030 If a line number is specified, probe the marker at start of code\n\
12031 for that line. If a function is specified, probe the marker at start\n\
12032 of code for that function. If an address is specified, probe the marker\n\
12033 at that exact address. If a marker id is specified, probe the marker\n\
12034 with that name. With no LOCATION, uses current execution address of\n\
12035 the selected stack frame.\n\
12036 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12037 This collects arbitrary user data passed in the probe point call to the\n\
12038 tracing library. You can inspect it when analyzing the trace buffer,\n\
12039 by printing the $_sdata variable like any other convenience variable.\n\
12041 CONDITION is a boolean expression.\n\
12043 Multiple tracepoints at one place are permitted, and useful if their\n\
12044 conditions are different.\n\
12046 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12047 Do \"help tracepoints\" for info on other tracepoint commands."));
12048 set_cmd_completer (c
, location_completer
);
12050 add_info ("tracepoints", tracepoints_info
, _("\
12051 Status of tracepoints, or tracepoint number NUMBER.\n\
12052 Convenience variable \"$tpnum\" contains the number of the\n\
12053 last tracepoint set."));
12055 add_info_alias ("tp", "tracepoints", 1);
12057 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12058 Delete specified tracepoints.\n\
12059 Arguments are tracepoint numbers, separated by spaces.\n\
12060 No argument means delete all tracepoints."),
12063 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12064 Disable specified tracepoints.\n\
12065 Arguments are tracepoint numbers, separated by spaces.\n\
12066 No argument means disable all tracepoints."),
12068 deprecate_cmd (c
, "disable");
12070 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12071 Enable specified tracepoints.\n\
12072 Arguments are tracepoint numbers, separated by spaces.\n\
12073 No argument means enable all tracepoints."),
12075 deprecate_cmd (c
, "enable");
12077 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12078 Set the passcount for a tracepoint.\n\
12079 The trace will end when the tracepoint has been passed 'count' times.\n\
12080 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12081 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12083 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12084 _("Save breakpoint definitions as a script."),
12085 &save_cmdlist
, "save ",
12086 0/*allow-unknown*/, &cmdlist
);
12088 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12089 Save current breakpoint definitions as a script.\n\
12090 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12091 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12092 session to restore them."),
12094 set_cmd_completer (c
, filename_completer
);
12096 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12097 Save current tracepoint definitions as a script.\n\
12098 Use the 'source' command in another debug session to restore them."),
12100 set_cmd_completer (c
, filename_completer
);
12102 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12103 deprecate_cmd (c
, "save tracepoints");
12105 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12106 Breakpoint specific settings\n\
12107 Configure various breakpoint-specific variables such as\n\
12108 pending breakpoint behavior"),
12109 &breakpoint_set_cmdlist
, "set breakpoint ",
12110 0/*allow-unknown*/, &setlist
);
12111 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12112 Breakpoint specific settings\n\
12113 Configure various breakpoint-specific variables such as\n\
12114 pending breakpoint behavior"),
12115 &breakpoint_show_cmdlist
, "show breakpoint ",
12116 0/*allow-unknown*/, &showlist
);
12118 add_setshow_auto_boolean_cmd ("pending", no_class
,
12119 &pending_break_support
, _("\
12120 Set debugger's behavior regarding pending breakpoints."), _("\
12121 Show debugger's behavior regarding pending breakpoints."), _("\
12122 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12123 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12124 an error. If auto, an unrecognized breakpoint location results in a\n\
12125 user-query to see if a pending breakpoint should be created."),
12127 show_pending_break_support
,
12128 &breakpoint_set_cmdlist
,
12129 &breakpoint_show_cmdlist
);
12131 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12133 add_setshow_boolean_cmd ("auto-hw", no_class
,
12134 &automatic_hardware_breakpoints
, _("\
12135 Set automatic usage of hardware breakpoints."), _("\
12136 Show automatic usage of hardware breakpoints."), _("\
12137 If set, the debugger will automatically use hardware breakpoints for\n\
12138 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12139 a warning will be emitted for such breakpoints."),
12141 show_automatic_hardware_breakpoints
,
12142 &breakpoint_set_cmdlist
,
12143 &breakpoint_show_cmdlist
);
12145 add_setshow_enum_cmd ("always-inserted", class_support
,
12146 always_inserted_enums
, &always_inserted_mode
, _("\
12147 Set mode for inserting breakpoints."), _("\
12148 Show mode for inserting breakpoints."), _("\
12149 When this mode is off, breakpoints are inserted in inferior when it is\n\
12150 resumed, and removed when execution stops. When this mode is on,\n\
12151 breakpoints are inserted immediately and removed only when the user\n\
12152 deletes the breakpoint. When this mode is auto (which is the default),\n\
12153 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12154 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12155 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12156 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12158 &show_always_inserted_mode
,
12159 &breakpoint_set_cmdlist
,
12160 &breakpoint_show_cmdlist
);
12162 automatic_hardware_breakpoints
= 1;
12164 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);