1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_delete_breakpoint (struct breakpoint
*);
84 static void enable_once_command (char *, int);
86 static void enable_once_breakpoint (struct breakpoint
*);
88 static void disable_command (char *, int);
90 static void enable_command (char *, int);
92 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
94 static void ignore_command (char *, int);
96 static int breakpoint_re_set_one (void *);
98 static void clear_command (char *, int);
100 static void catch_command (char *, int);
102 static void watch_command (char *, int);
104 static int can_use_hardware_watchpoint (struct value
*);
106 static void break_command_1 (char *, int, int);
108 static void mention (struct breakpoint
*);
110 /* This function is used in gdbtk sources and thus can not be made static. */
111 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
112 struct symtab_and_line
,
115 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
117 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
121 static void describe_other_breakpoints (struct gdbarch
*,
122 struct program_space
*, CORE_ADDR
,
123 struct obj_section
*, int);
125 static int breakpoint_address_match (struct address_space
*aspace1
,
127 struct address_space
*aspace2
,
130 static void breakpoints_info (char *, int);
132 static void breakpoint_1 (int, int);
134 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
136 static int breakpoint_cond_eval (void *);
138 static void cleanup_executing_breakpoints (void *);
140 static void commands_command (char *, int);
142 static void condition_command (char *, int);
144 static int get_number_trailer (char **, int);
146 void set_breakpoint_count (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 watch_command_1 (char *, int, int);
176 static void rwatch_command (char *, int);
178 static void awatch_command (char *, int);
180 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
182 static void stop_command (char *arg
, int from_tty
);
184 static void stopin_command (char *arg
, int from_tty
);
186 static void stopat_command (char *arg
, int from_tty
);
188 static char *ep_parse_optional_if_clause (char **arg
);
190 static char *ep_parse_optional_filename (char **arg
);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
193 char *arg
, int tempflag
, int from_tty
);
195 static void tcatch_command (char *arg
, int from_tty
);
197 static void ep_skip_leading_whitespace (char **s
);
199 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
202 static void free_bp_location (struct bp_location
*loc
);
204 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
206 static void update_global_location_list (int);
208 static void update_global_location_list_nothrow (int);
210 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
212 static void insert_breakpoint_locations (void);
214 static int syscall_catchpoint_p (struct breakpoint
*b
);
216 static void tracepoints_info (char *, int);
218 static void delete_trace_command (char *, int);
220 static void enable_trace_command (char *, int);
222 static void disable_trace_command (char *, int);
224 static void trace_pass_command (char *, int);
226 static void skip_prologue_sal (struct symtab_and_line
*sal
);
229 /* Flag indicating that a command has proceeded the inferior past the
230 current breakpoint. */
232 static int breakpoint_proceeded
;
235 bpdisp_text (enum bpdisp disp
)
237 /* NOTE: the following values are a part of MI protocol and represent
238 values of 'disp' field returned when inferior stops at a breakpoint. */
239 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
240 return bpdisps
[(int) disp
];
243 /* Prototypes for exported functions. */
244 /* If FALSE, gdb will not use hardware support for watchpoints, even
245 if such is available. */
246 static int can_use_hw_watchpoints
;
249 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
250 struct cmd_list_element
*c
,
253 fprintf_filtered (file
, _("\
254 Debugger's willingness to use watchpoint hardware is %s.\n"),
258 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
259 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
260 for unrecognized breakpoint locations.
261 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
262 static enum auto_boolean pending_break_support
;
264 show_pending_break_support (struct ui_file
*file
, int from_tty
,
265 struct cmd_list_element
*c
,
268 fprintf_filtered (file
, _("\
269 Debugger's behavior regarding pending breakpoints is %s.\n"),
273 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
274 set with "break" but falling in read-only memory.
275 If 0, gdb will warn about such breakpoints, but won't automatically
276 use hardware breakpoints. */
277 static int automatic_hardware_breakpoints
;
279 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
280 struct cmd_list_element
*c
,
283 fprintf_filtered (file
, _("\
284 Automatic usage of hardware breakpoints is %s.\n"),
288 /* If on, gdb will keep breakpoints inserted even as inferior is
289 stopped, and immediately insert any new breakpoints. If off, gdb
290 will insert breakpoints into inferior only when resuming it, and
291 will remove breakpoints upon stop. If auto, GDB will behave as ON
292 if in non-stop mode, and as OFF if all-stop mode.*/
294 static const char always_inserted_auto
[] = "auto";
295 static const char always_inserted_on
[] = "on";
296 static const char always_inserted_off
[] = "off";
297 static const char *always_inserted_enums
[] = {
298 always_inserted_auto
,
303 static const char *always_inserted_mode
= always_inserted_auto
;
305 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
306 struct cmd_list_element
*c
, const char *value
)
308 if (always_inserted_mode
== always_inserted_auto
)
309 fprintf_filtered (file
, _("\
310 Always inserted breakpoint mode is %s (currently %s).\n"),
312 breakpoints_always_inserted_mode () ? "on" : "off");
314 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
318 breakpoints_always_inserted_mode (void)
320 return (always_inserted_mode
== always_inserted_on
321 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
324 void _initialize_breakpoint (void);
326 /* Are we executing breakpoint commands? */
327 static int executing_breakpoint_commands
;
329 /* Are overlay event breakpoints enabled? */
330 static int overlay_events_enabled
;
332 /* Walk the following statement or block through all breakpoints.
333 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
336 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
338 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
339 for (B = breakpoint_chain; \
340 B ? (TMP=B->next, 1): 0; \
343 /* Similar iterator for the low-level breakpoints. SAFE variant is not
344 provided so update_global_location_list must not be called while executing
345 the block of ALL_BP_LOCATIONS. */
347 #define ALL_BP_LOCATIONS(B,BP_TMP) \
348 for (BP_TMP = bp_location; \
349 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
352 /* Iterator for tracepoints only. */
354 #define ALL_TRACEPOINTS(B) \
355 for (B = breakpoint_chain; B; B = B->next) \
356 if (tracepoint_type (B))
358 /* Chains of all breakpoints defined. */
360 struct breakpoint
*breakpoint_chain
;
362 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
364 static struct bp_location
**bp_location
;
366 /* Number of elements of BP_LOCATION. */
368 static unsigned bp_location_count
;
370 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
371 for the current elements of BP_LOCATION which get a valid result from
372 bp_location_has_shadow. You can use it for roughly limiting the subrange of
373 BP_LOCATION to scan for shadow bytes for an address you need to read. */
375 static CORE_ADDR bp_location_placed_address_before_address_max
;
377 /* Maximum offset plus alignment between
378 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
379 the current elements of BP_LOCATION which get a valid result from
380 bp_location_has_shadow. You can use it for roughly limiting the subrange of
381 BP_LOCATION to scan for shadow bytes for an address you need to read. */
383 static CORE_ADDR bp_location_shadow_len_after_address_max
;
385 /* The locations that no longer correspond to any breakpoint,
386 unlinked from bp_location array, but for which a hit
387 may still be reported by a target. */
388 VEC(bp_location_p
) *moribund_locations
= NULL
;
390 /* Number of last breakpoint made. */
392 int breakpoint_count
;
394 /* Number of last tracepoint made. */
396 int tracepoint_count
;
398 /* Return whether a breakpoint is an active enabled breakpoint. */
400 breakpoint_enabled (struct breakpoint
*b
)
402 return (b
->enable_state
== bp_enabled
);
405 /* Set breakpoint count to NUM. */
408 set_breakpoint_count (int num
)
410 breakpoint_count
= num
;
411 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
414 /* Used in run_command to zero the hit count when a new run starts. */
417 clear_breakpoint_hit_counts (void)
419 struct breakpoint
*b
;
425 /* Encapsulate tests for different types of tracepoints. */
428 tracepoint_type (const struct breakpoint
*b
)
430 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
433 /* Default address, symtab and line to put a breakpoint at
434 for "break" command with no arg.
435 if default_breakpoint_valid is zero, the other three are
436 not valid, and "break" with no arg is an error.
438 This set by print_stack_frame, which calls set_default_breakpoint. */
440 int default_breakpoint_valid
;
441 CORE_ADDR default_breakpoint_address
;
442 struct symtab
*default_breakpoint_symtab
;
443 int default_breakpoint_line
;
444 struct program_space
*default_breakpoint_pspace
;
447 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
448 Advance *PP after the string and any trailing whitespace.
450 Currently the string can either be a number or "$" followed by the name
451 of a convenience variable. Making it an expression wouldn't work well
452 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
454 If the string is a NULL pointer, that denotes the last breakpoint.
456 TRAILER is a character which can be found after the number; most
457 commonly this is `-'. If you don't want a trailer, use \0. */
459 get_number_trailer (char **pp
, int trailer
)
461 int retval
= 0; /* default */
465 /* Empty line means refer to the last breakpoint. */
466 return breakpoint_count
;
469 /* Make a copy of the name, so we can null-terminate it
470 to pass to lookup_internalvar(). */
475 while (isalnum (*p
) || *p
== '_')
477 varname
= (char *) alloca (p
- start
+ 1);
478 strncpy (varname
, start
, p
- start
);
479 varname
[p
- start
] = '\0';
480 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
484 printf_filtered (_("Convenience variable must have integer value.\n"));
492 while (*p
>= '0' && *p
<= '9')
495 /* There is no number here. (e.g. "cond a == b"). */
497 /* Skip non-numeric token */
498 while (*p
&& !isspace((int) *p
))
500 /* Return zero, which caller must interpret as error. */
506 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
508 /* Trailing junk: return 0 and let caller print error msg. */
509 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
520 /* Like get_number_trailer, but don't allow a trailer. */
522 get_number (char **pp
)
524 return get_number_trailer (pp
, '\0');
527 /* Parse a number or a range.
528 * A number will be of the form handled by get_number.
529 * A range will be of the form <number1> - <number2>, and
530 * will represent all the integers between number1 and number2,
533 * While processing a range, this fuction is called iteratively;
534 * At each call it will return the next value in the range.
536 * At the beginning of parsing a range, the char pointer PP will
537 * be advanced past <number1> and left pointing at the '-' token.
538 * Subsequent calls will not advance the pointer until the range
539 * is completed. The call that completes the range will advance
540 * pointer PP past <number2>.
544 get_number_or_range (char **pp
)
546 static int last_retval
, end_value
;
547 static char *end_ptr
;
548 static int in_range
= 0;
552 /* Default case: pp is pointing either to a solo number,
553 or to the first number of a range. */
554 last_retval
= get_number_trailer (pp
, '-');
559 /* This is the start of a range (<number1> - <number2>).
560 Skip the '-', parse and remember the second number,
561 and also remember the end of the final token. */
565 while (isspace ((int) *end_ptr
))
566 end_ptr
++; /* skip white space */
567 end_value
= get_number (temp
);
568 if (end_value
< last_retval
)
570 error (_("inverted range"));
572 else if (end_value
== last_retval
)
574 /* degenerate range (number1 == number2). Advance the
575 token pointer so that the range will be treated as a
584 error (_("negative value"));
587 /* pp points to the '-' that betokens a range. All
588 number-parsing has already been done. Return the next
589 integer value (one greater than the saved previous value).
590 Do not advance the token pointer 'pp' until the end of range
593 if (++last_retval
== end_value
)
595 /* End of range reached; advance token pointer. */
603 /* Return the breakpoint with the specified number, or NULL
604 if the number does not refer to an existing breakpoint. */
607 get_breakpoint (int num
)
609 struct breakpoint
*b
;
612 if (b
->number
== num
)
619 /* condition N EXP -- set break condition of breakpoint N to EXP. */
622 condition_command (char *arg
, int from_tty
)
624 struct breakpoint
*b
;
629 error_no_arg (_("breakpoint number"));
632 bnum
= get_number (&p
);
634 error (_("Bad breakpoint argument: '%s'"), arg
);
637 if (b
->number
== bnum
)
639 struct bp_location
*loc
= b
->loc
;
640 for (; loc
; loc
= loc
->next
)
648 if (b
->cond_string
!= NULL
)
649 xfree (b
->cond_string
);
653 b
->cond_string
= NULL
;
655 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
660 /* I don't know if it matters whether this is the string the user
661 typed in or the decompiled expression. */
662 b
->cond_string
= xstrdup (arg
);
663 b
->condition_not_parsed
= 0;
664 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
668 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
670 error (_("Junk at end of expression"));
673 breakpoints_changed ();
674 observer_notify_breakpoint_modified (b
->number
);
678 error (_("No breakpoint number %d."), bnum
);
681 /* Set the command list of B to COMMANDS. */
684 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
686 free_command_lines (&b
->commands
);
687 b
->commands
= commands
;
688 breakpoints_changed ();
689 observer_notify_breakpoint_modified (b
->number
);
693 commands_command (char *arg
, int from_tty
)
695 struct breakpoint
*b
;
698 struct command_line
*l
;
700 /* If we allowed this, we would have problems with when to
701 free the storage, if we change the commands currently
704 if (executing_breakpoint_commands
)
705 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
708 bnum
= get_number (&p
);
711 error (_("Unexpected extra arguments following breakpoint number."));
714 if (b
->number
== bnum
)
716 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
718 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
719 l
= read_command_lines (tmpbuf
, from_tty
, 1);
720 do_cleanups (cleanups
);
721 breakpoint_set_commands (b
, l
);
724 error (_("No breakpoint number %d."), bnum
);
727 /* Like commands_command, but instead of reading the commands from
728 input stream, takes them from an already parsed command structure.
730 This is used by cli-script.c to DTRT with breakpoint commands
731 that are part of if and while bodies. */
732 enum command_control_type
733 commands_from_control_command (char *arg
, struct command_line
*cmd
)
735 struct breakpoint
*b
;
739 /* If we allowed this, we would have problems with when to
740 free the storage, if we change the commands currently
743 if (executing_breakpoint_commands
)
744 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
746 /* An empty string for the breakpoint number means the last
747 breakpoint, but get_number expects a NULL pointer. */
752 bnum
= get_number (&p
);
755 error (_("Unexpected extra arguments following breakpoint number."));
758 if (b
->number
== bnum
)
760 free_command_lines (&b
->commands
);
761 if (cmd
->body_count
!= 1)
762 error (_("Invalid \"commands\" block structure."));
763 /* We need to copy the commands because if/while will free the
764 list after it finishes execution. */
765 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
766 breakpoints_changed ();
767 observer_notify_breakpoint_modified (b
->number
);
768 return simple_control
;
770 error (_("No breakpoint number %d."), bnum
);
773 /* Return non-zero if BL->TARGET_INFO contains valid information. */
776 bp_location_has_shadow (struct bp_location
*bl
)
778 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
782 if (bl
->target_info
.shadow_len
== 0)
783 /* bp isn't valid, or doesn't shadow memory. */
788 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
789 by replacing any memory breakpoints with their shadowed contents.
791 The range of shadowed area by each bp_location is:
792 b->address - bp_location_placed_address_before_address_max
793 up to b->address + bp_location_shadow_len_after_address_max
794 The range we were requested to resolve shadows for is:
795 memaddr ... memaddr + len
796 Thus the safe cutoff boundaries for performance optimization are
797 memaddr + len <= b->address - bp_location_placed_address_before_address_max
799 b->address + bp_location_shadow_len_after_address_max <= memaddr */
802 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
804 /* Left boundary, right boundary and median element of our binary search. */
805 unsigned bc_l
, bc_r
, bc
;
807 /* Find BC_L which is a leftmost element which may affect BUF content. It is
808 safe to report lower value but a failure to report higher one. */
811 bc_r
= bp_location_count
;
812 while (bc_l
+ 1 < bc_r
)
814 struct bp_location
*b
;
816 bc
= (bc_l
+ bc_r
) / 2;
819 /* Check first B->ADDRESS will not overflow due to the added constant.
820 Then advance the left boundary only if we are sure the BC element can
821 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
823 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
824 we cannot miss a breakpoint with its shadow range tail still reaching
827 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
828 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
834 /* Now do full processing of the found relevant range of elements. */
836 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
838 struct bp_location
*b
= bp_location
[bc
];
839 CORE_ADDR bp_addr
= 0;
843 if (b
->owner
->type
== bp_none
)
844 warning (_("reading through apparently deleted breakpoint #%d?"),
847 /* Performance optimization: any futher element can no longer affect BUF
850 if (b
->address
>= bp_location_placed_address_before_address_max
851 && memaddr
+ len
<= b
->address
852 - bp_location_placed_address_before_address_max
)
855 if (!bp_location_has_shadow (b
))
857 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
858 current_program_space
->aspace
, 0))
861 /* Addresses and length of the part of the breakpoint that
863 bp_addr
= b
->target_info
.placed_address
;
864 bp_size
= b
->target_info
.shadow_len
;
866 if (bp_addr
+ bp_size
<= memaddr
)
867 /* The breakpoint is entirely before the chunk of memory we
871 if (bp_addr
>= memaddr
+ len
)
872 /* The breakpoint is entirely after the chunk of memory we are
876 /* Offset within shadow_contents. */
877 if (bp_addr
< memaddr
)
879 /* Only copy the second part of the breakpoint. */
880 bp_size
-= memaddr
- bp_addr
;
881 bptoffset
= memaddr
- bp_addr
;
885 if (bp_addr
+ bp_size
> memaddr
+ len
)
887 /* Only copy the first part of the breakpoint. */
888 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
891 memcpy (buf
+ bp_addr
- memaddr
,
892 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
897 /* A wrapper function for inserting catchpoints. */
899 insert_catchpoint (struct ui_out
*uo
, void *args
)
901 struct breakpoint
*b
= (struct breakpoint
*) args
;
904 gdb_assert (b
->type
== bp_catchpoint
);
905 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
911 is_hardware_watchpoint (struct breakpoint
*bpt
)
913 return (bpt
->type
== bp_hardware_watchpoint
914 || bpt
->type
== bp_read_watchpoint
915 || bpt
->type
== bp_access_watchpoint
);
918 /* Find the current value of a watchpoint on EXP. Return the value in
919 *VALP and *RESULTP and the chain of intermediate and final values
920 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
923 If a memory error occurs while evaluating the expression, *RESULTP will
924 be set to NULL. *RESULTP may be a lazy value, if the result could
925 not be read from memory. It is used to determine whether a value
926 is user-specified (we should watch the whole value) or intermediate
927 (we should watch only the bit used to locate the final value).
929 If the final value, or any intermediate value, could not be read
930 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
931 set to any referenced values. *VALP will never be a lazy value.
932 This is the value which we store in struct breakpoint.
934 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
935 value chain. The caller must free the values individually. If
936 VAL_CHAIN is NULL, all generated values will be left on the value
940 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
941 struct value
**resultp
, struct value
**val_chain
)
943 struct value
*mark
, *new_mark
, *result
;
944 volatile struct gdb_exception ex
;
952 /* Evaluate the expression. */
953 mark
= value_mark ();
956 TRY_CATCH (ex
, RETURN_MASK_ALL
)
958 result
= evaluate_expression (exp
);
962 /* Ignore memory errors, we want watchpoints pointing at
963 inaccessible memory to still be created; otherwise, throw the
964 error to some higher catcher. */
970 throw_exception (ex
);
975 new_mark
= value_mark ();
976 if (mark
== new_mark
)
981 /* Make sure it's not lazy, so that after the target stops again we
982 have a non-lazy previous value to compare with. */
984 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
989 /* Return the chain of intermediate values. We use this to
990 decide which addresses to watch. */
991 *val_chain
= new_mark
;
992 value_release_to_mark (mark
);
996 /* Assuming that B is a watchpoint: returns true if the current thread
997 and its running state are safe to evaluate or update watchpoint B.
998 Watchpoints on local expressions need to be evaluated in the
999 context of the thread that was current when the watchpoint was
1000 created, and, that thread needs to be stopped to be able to select
1001 the correct frame context. Watchpoints on global expressions can
1002 be evaluated on any thread, and in any state. It is presently left
1003 to the target allowing memory accesses when threads are
1007 watchpoint_in_thread_scope (struct breakpoint
*b
)
1009 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1010 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1011 && !is_executing (inferior_ptid
)));
1014 /* Assuming that B is a watchpoint:
1015 - Reparse watchpoint expression, if REPARSE is non-zero
1016 - Evaluate expression and store the result in B->val
1017 - Evaluate the condition if there is one, and store the result
1019 - Update the list of values that must be watched in B->loc.
1021 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1022 If this is local watchpoint that is out of scope, delete it.
1024 Even with `set breakpoint always-inserted on' the watchpoints are removed
1025 + inserted on each stop here. Normal breakpoints must never be removed
1026 because they might be missed by a running thread when debugging in non-stop
1027 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1028 processed here) are specific to each LWP since they are stored in each LWP's
1029 hardware debug registers. Therefore, such LWP must be stopped first in
1030 order to be able to modify its hardware watchpoints.
1032 Hardware watchpoints must be reset exactly once after being presented to the
1033 user. It cannot be done sooner, because it would reset the data used to
1034 present the watchpoint hit to the user. And it must not be done later
1035 because it could display the same single watchpoint hit during multiple GDB
1036 stops. Note that the latter is relevant only to the hardware watchpoint
1037 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1038 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1039 memory content has not changed.
1041 The following constraints influence the location where we can reset hardware
1044 * target_stopped_by_watchpoint and target_stopped_data_address are called
1045 several times when GDB stops.
1048 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1049 stop. GDB only presents one hardware watchpoint hit at a time as the
1050 reason for stopping, and all the other hits are presented later, one after
1051 the other, each time the user requests the execution to be resumed.
1052 Execution is not resumed for the threads still having pending hit event
1053 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1054 the inferior on the first stop the thread hit event is kept being reported
1055 from its cached value by linux_nat_stopped_data_address until the real
1056 thread resume happens after the watchpoint gets presented and thus its
1057 LWP_INFO->STATUS gets reset.
1059 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1060 removal from inferior. */
1063 update_watchpoint (struct breakpoint
*b
, int reparse
)
1065 int within_current_scope
;
1066 struct frame_id saved_frame_id
;
1067 struct bp_location
*loc
;
1071 /* If this is a local watchpoint, we only want to check if the
1072 watchpoint frame is in scope if the current thread is the thread
1073 that was used to create the watchpoint. */
1074 if (!watchpoint_in_thread_scope (b
))
1077 /* We don't free locations. They are stored in bp_location array and
1078 update_global_locations will eventually delete them and remove
1079 breakpoints if needed. */
1082 if (b
->disposition
== disp_del_at_next_stop
)
1087 /* Determine if the watchpoint is within scope. */
1088 if (b
->exp_valid_block
== NULL
)
1089 within_current_scope
= 1;
1092 struct frame_info
*fi
;
1094 /* Save the current frame's ID so we can restore it after
1095 evaluating the watchpoint expression on its own frame. */
1096 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1097 took a frame parameter, so that we didn't have to change the
1100 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1102 fi
= frame_find_by_id (b
->watchpoint_frame
);
1103 within_current_scope
= (fi
!= NULL
);
1104 if (within_current_scope
)
1108 if (within_current_scope
&& reparse
)
1117 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1118 /* If the meaning of expression itself changed, the old value is
1119 no longer relevant. We don't want to report a watchpoint hit
1120 to the user when the old value and the new value may actually
1121 be completely different objects. */
1122 value_free (b
->val
);
1127 /* If we failed to parse the expression, for example because
1128 it refers to a global variable in a not-yet-loaded shared library,
1129 don't try to insert watchpoint. We don't automatically delete
1130 such watchpoint, though, since failure to parse expression
1131 is different from out-of-scope watchpoint. */
1132 if ( !target_has_execution
)
1134 /* Without execution, memory can't change. No use to try and
1135 set watchpoint locations. The watchpoint will be reset when
1136 the target gains execution, through breakpoint_re_set. */
1138 else if (within_current_scope
&& b
->exp
)
1140 struct value
*val_chain
, *v
, *result
, *next
;
1141 struct program_space
*frame_pspace
;
1143 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1145 /* Avoid setting b->val if it's already set. The meaning of
1146 b->val is 'the last value' user saw, and we should update
1147 it only if we reported that last value to user. As it
1148 happens, the code that reports it updates b->val directly. */
1155 /* Change the type of breakpoint between hardware assisted or an
1156 ordinary watchpoint depending on the hardware support and free
1157 hardware slots. REPARSE is set when the inferior is started. */
1158 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1161 int i
, mem_cnt
, other_type_used
;
1163 /* We need to determine how many resources are already used
1164 for all other hardware watchpoints to see if we still have
1165 enough resources to also fit this watchpoint in as well.
1166 To avoid the hw_watchpoint_used_count call below from counting
1167 this watchpoint, make sure that it is marked as a software
1169 b
->type
= bp_watchpoint
;
1170 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1172 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1175 b
->type
= bp_watchpoint
;
1178 int target_resources_ok
= target_can_use_hardware_watchpoint
1179 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1180 if (target_resources_ok
<= 0)
1181 b
->type
= bp_watchpoint
;
1183 b
->type
= bp_hardware_watchpoint
;
1187 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1189 /* Look at each value on the value chain. */
1190 for (v
= val_chain
; v
; v
= next
)
1192 /* If it's a memory location, and GDB actually needed
1193 its contents to evaluate the expression, then we
1194 must watch it. If the first value returned is
1195 still lazy, that means an error occurred reading it;
1196 watch it anyway in case it becomes readable. */
1197 if (VALUE_LVAL (v
) == lval_memory
1198 && (v
== val_chain
|| ! value_lazy (v
)))
1200 struct type
*vtype
= check_typedef (value_type (v
));
1202 /* We only watch structs and arrays if user asked
1203 for it explicitly, never if they just happen to
1204 appear in the middle of some value chain. */
1206 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1207 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1211 struct bp_location
*loc
, **tmp
;
1213 addr
= value_address (v
);
1214 len
= TYPE_LENGTH (value_type (v
));
1216 if (b
->type
== bp_read_watchpoint
)
1218 else if (b
->type
== bp_access_watchpoint
)
1221 loc
= allocate_bp_location (b
);
1222 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1225 loc
->gdbarch
= get_type_arch (value_type (v
));
1227 loc
->pspace
= frame_pspace
;
1228 loc
->address
= addr
;
1230 loc
->watchpoint_type
= type
;
1234 next
= value_next (v
);
1239 /* We just regenerated the list of breakpoint locations.
1240 The new location does not have its condition field set to anything
1241 and therefore, we must always reparse the cond_string, independently
1242 of the value of the reparse flag. */
1243 if (b
->cond_string
!= NULL
)
1245 char *s
= b
->cond_string
;
1246 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1249 else if (!within_current_scope
)
1251 printf_filtered (_("\
1252 Watchpoint %d deleted because the program has left the block \n\
1253 in which its expression is valid.\n"),
1255 if (b
->related_breakpoint
)
1256 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1257 b
->disposition
= disp_del_at_next_stop
;
1260 /* Restore the selected frame. */
1262 select_frame (frame_find_by_id (saved_frame_id
));
1266 /* Returns 1 iff breakpoint location should be
1267 inserted in the inferior. */
1269 should_be_inserted (struct bp_location
*bpt
)
1271 if (!breakpoint_enabled (bpt
->owner
))
1274 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1277 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1280 /* This is set for example, when we're attached to the parent of a
1281 vfork, and have detached from the child. The child is running
1282 free, and we expect it to do an exec or exit, at which point the
1283 OS makes the parent schedulable again (and the target reports
1284 that the vfork is done). Until the child is done with the shared
1285 memory region, do not insert breakpoints in the parent, otherwise
1286 the child could still trip on the parent's breakpoints. Since
1287 the parent is blocked anyway, it won't miss any breakpoint. */
1288 if (bpt
->pspace
->breakpoints_not_allowed
)
1291 /* Tracepoints are inserted by the target at a time of its choosing,
1293 if (tracepoint_type (bpt
->owner
))
1299 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1300 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1301 and HW_BREAKPOINT_ERROR are used to report problems.
1303 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1304 method for each breakpoint or catchpoint type. */
1306 insert_bp_location (struct bp_location
*bpt
,
1307 struct ui_file
*tmp_error_stream
,
1308 int *disabled_breaks
,
1309 int *hw_breakpoint_error
)
1313 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1316 /* Initialize the target-specific information. */
1317 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1318 bpt
->target_info
.placed_address
= bpt
->address
;
1319 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1321 if (bpt
->loc_type
== bp_loc_software_breakpoint
1322 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1324 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1326 /* If the explicitly specified breakpoint type
1327 is not hardware breakpoint, check the memory map to see
1328 if the breakpoint address is in read only memory or not.
1329 Two important cases are:
1330 - location type is not hardware breakpoint, memory
1331 is readonly. We change the type of the location to
1332 hardware breakpoint.
1333 - location type is hardware breakpoint, memory is read-write.
1334 This means we've previously made the location hardware one, but
1335 then the memory map changed, so we undo.
1337 When breakpoints are removed, remove_breakpoints will
1338 use location types we've just set here, the only possible
1339 problem is that memory map has changed during running program,
1340 but it's not going to work anyway with current gdb. */
1341 struct mem_region
*mr
1342 = lookup_mem_region (bpt
->target_info
.placed_address
);
1346 if (automatic_hardware_breakpoints
)
1349 enum bp_loc_type new_type
;
1351 if (mr
->attrib
.mode
!= MEM_RW
)
1352 new_type
= bp_loc_hardware_breakpoint
;
1354 new_type
= bp_loc_software_breakpoint
;
1356 if (new_type
!= bpt
->loc_type
)
1358 static int said
= 0;
1359 bpt
->loc_type
= new_type
;
1362 fprintf_filtered (gdb_stdout
, _("\
1363 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1368 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1369 && mr
->attrib
.mode
!= MEM_RW
)
1370 warning (_("cannot set software breakpoint at readonly address %s"),
1371 paddress (bpt
->gdbarch
, bpt
->address
));
1375 /* First check to see if we have to handle an overlay. */
1376 if (overlay_debugging
== ovly_off
1377 || bpt
->section
== NULL
1378 || !(section_is_overlay (bpt
->section
)))
1380 /* No overlay handling: just set the breakpoint. */
1382 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1383 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1386 val
= target_insert_breakpoint (bpt
->gdbarch
,
1391 /* This breakpoint is in an overlay section.
1392 Shall we set a breakpoint at the LMA? */
1393 if (!overlay_events_enabled
)
1395 /* Yes -- overlay event support is not active,
1396 so we must try to set a breakpoint at the LMA.
1397 This will not work for a hardware breakpoint. */
1398 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1399 warning (_("hardware breakpoint %d not supported in overlay!"),
1400 bpt
->owner
->number
);
1403 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1405 /* Set a software (trap) breakpoint at the LMA. */
1406 bpt
->overlay_target_info
= bpt
->target_info
;
1407 bpt
->overlay_target_info
.placed_address
= addr
;
1408 val
= target_insert_breakpoint (bpt
->gdbarch
,
1409 &bpt
->overlay_target_info
);
1411 fprintf_unfiltered (tmp_error_stream
,
1412 "Overlay breakpoint %d failed: in ROM?\n",
1413 bpt
->owner
->number
);
1416 /* Shall we set a breakpoint at the VMA? */
1417 if (section_is_mapped (bpt
->section
))
1419 /* Yes. This overlay section is mapped into memory. */
1420 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1421 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1424 val
= target_insert_breakpoint (bpt
->gdbarch
,
1429 /* No. This breakpoint will not be inserted.
1430 No error, but do not mark the bp as 'inserted'. */
1437 /* Can't set the breakpoint. */
1438 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1440 /* See also: disable_breakpoints_in_shlibs. */
1442 bpt
->shlib_disabled
= 1;
1443 if (!*disabled_breaks
)
1445 fprintf_unfiltered (tmp_error_stream
,
1446 "Cannot insert breakpoint %d.\n",
1447 bpt
->owner
->number
);
1448 fprintf_unfiltered (tmp_error_stream
,
1449 "Temporarily disabling shared library breakpoints:\n");
1451 *disabled_breaks
= 1;
1452 fprintf_unfiltered (tmp_error_stream
,
1453 "breakpoint #%d\n", bpt
->owner
->number
);
1457 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1459 *hw_breakpoint_error
= 1;
1460 fprintf_unfiltered (tmp_error_stream
,
1461 "Cannot insert hardware breakpoint %d.\n",
1462 bpt
->owner
->number
);
1466 fprintf_unfiltered (tmp_error_stream
,
1467 "Cannot insert breakpoint %d.\n",
1468 bpt
->owner
->number
);
1469 fprintf_filtered (tmp_error_stream
,
1470 "Error accessing memory address ");
1471 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1473 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1474 safe_strerror (val
));
1485 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1486 /* NOTE drow/2003-09-08: This state only exists for removing
1487 watchpoints. It's not clear that it's necessary... */
1488 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1490 val
= target_insert_watchpoint (bpt
->address
,
1492 bpt
->watchpoint_type
);
1493 bpt
->inserted
= (val
!= -1);
1496 else if (bpt
->owner
->type
== bp_catchpoint
)
1498 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1499 bpt
->owner
, RETURN_MASK_ERROR
);
1500 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1501 bpt
->owner
->number
);
1503 bpt
->owner
->enable_state
= bp_disabled
;
1507 /* We've already printed an error message if there was a problem
1508 inserting this catchpoint, and we've disabled the catchpoint,
1509 so just return success. */
1516 /* This function is called when program space PSPACE is about to be
1517 deleted. It takes care of updating breakpoints to not reference
1521 breakpoint_program_space_exit (struct program_space
*pspace
)
1523 struct breakpoint
*b
, *b_temp
;
1524 struct bp_location
*loc
, **loc_temp
;
1526 /* Remove any breakpoint that was set through this program space. */
1527 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1529 if (b
->pspace
== pspace
)
1530 delete_breakpoint (b
);
1533 /* Breakpoints set through other program spaces could have locations
1534 bound to PSPACE as well. Remove those. */
1535 ALL_BP_LOCATIONS (loc
, loc_temp
)
1537 struct bp_location
*tmp
;
1539 if (loc
->pspace
== pspace
)
1541 if (loc
->owner
->loc
== loc
)
1542 loc
->owner
->loc
= loc
->next
;
1544 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1545 if (tmp
->next
== loc
)
1547 tmp
->next
= loc
->next
;
1553 /* Now update the global location list to permanently delete the
1554 removed locations above. */
1555 update_global_location_list (0);
1558 /* Make sure all breakpoints are inserted in inferior.
1559 Throws exception on any error.
1560 A breakpoint that is already inserted won't be inserted
1561 again, so calling this function twice is safe. */
1563 insert_breakpoints (void)
1565 struct breakpoint
*bpt
;
1567 ALL_BREAKPOINTS (bpt
)
1568 if (is_hardware_watchpoint (bpt
))
1569 update_watchpoint (bpt
, 0 /* don't reparse. */);
1571 update_global_location_list (1);
1573 /* update_global_location_list does not insert breakpoints when
1574 always_inserted_mode is not enabled. Explicitly insert them
1576 if (!breakpoints_always_inserted_mode ())
1577 insert_breakpoint_locations ();
1580 /* insert_breakpoints is used when starting or continuing the program.
1581 remove_breakpoints is used when the program stops.
1582 Both return zero if successful,
1583 or an `errno' value if could not write the inferior. */
1586 insert_breakpoint_locations (void)
1588 struct breakpoint
*bpt
;
1589 struct bp_location
*b
, **bp_tmp
;
1592 int disabled_breaks
= 0;
1593 int hw_breakpoint_error
= 0;
1595 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1596 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1598 /* Explicitly mark the warning -- this will only be printed if
1599 there was an error. */
1600 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1602 save_current_space_and_thread ();
1604 ALL_BP_LOCATIONS (b
, bp_tmp
)
1606 struct thread_info
*tp
;
1607 CORE_ADDR last_addr
;
1609 if (!should_be_inserted (b
) || b
->inserted
)
1612 /* There is no point inserting thread-specific breakpoints if the
1613 thread no longer exists. */
1614 if (b
->owner
->thread
!= -1
1615 && !valid_thread_id (b
->owner
->thread
))
1618 switch_to_program_space_and_thread (b
->pspace
);
1620 /* For targets that support global breakpoints, there's no need
1621 to select an inferior to insert breakpoint to. In fact, even
1622 if we aren't attached to any process yet, we should still
1623 insert breakpoints. */
1624 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1625 && ptid_equal (inferior_ptid
, null_ptid
))
1628 val
= insert_bp_location (b
, tmp_error_stream
,
1630 &hw_breakpoint_error
);
1635 /* If we failed to insert all locations of a watchpoint,
1636 remove them, as half-inserted watchpoint is of limited use. */
1637 ALL_BREAKPOINTS (bpt
)
1639 int some_failed
= 0;
1640 struct bp_location
*loc
;
1642 if (!is_hardware_watchpoint (bpt
))
1645 if (!breakpoint_enabled (bpt
))
1648 if (bpt
->disposition
== disp_del_at_next_stop
)
1651 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1652 if (!loc
->inserted
&& should_be_inserted (loc
))
1659 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1661 remove_breakpoint (loc
, mark_uninserted
);
1663 hw_breakpoint_error
= 1;
1664 fprintf_unfiltered (tmp_error_stream
,
1665 "Could not insert hardware watchpoint %d.\n",
1673 /* If a hardware breakpoint or watchpoint was inserted, add a
1674 message about possibly exhausted resources. */
1675 if (hw_breakpoint_error
)
1677 fprintf_unfiltered (tmp_error_stream
,
1678 "Could not insert hardware breakpoints:\n\
1679 You may have requested too many hardware breakpoints/watchpoints.\n");
1681 target_terminal_ours_for_output ();
1682 error_stream (tmp_error_stream
);
1685 do_cleanups (cleanups
);
1689 remove_breakpoints (void)
1691 struct bp_location
*b
, **bp_tmp
;
1694 ALL_BP_LOCATIONS (b
, bp_tmp
)
1697 val
|= remove_breakpoint (b
, mark_uninserted
);
1702 /* Remove breakpoints of process PID. */
1705 remove_breakpoints_pid (int pid
)
1707 struct bp_location
*b
, **b_tmp
;
1709 struct inferior
*inf
= find_inferior_pid (pid
);
1711 ALL_BP_LOCATIONS (b
, b_tmp
)
1713 if (b
->pspace
!= inf
->pspace
)
1718 val
= remove_breakpoint (b
, mark_uninserted
);
1727 remove_hw_watchpoints (void)
1729 struct bp_location
*b
, **bp_tmp
;
1732 ALL_BP_LOCATIONS (b
, bp_tmp
)
1734 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1735 val
|= remove_breakpoint (b
, mark_uninserted
);
1741 reattach_breakpoints (int pid
)
1743 struct cleanup
*old_chain
;
1744 struct bp_location
*b
, **bp_tmp
;
1746 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1747 int dummy1
= 0, dummy2
= 0;
1748 struct inferior
*inf
;
1749 struct thread_info
*tp
;
1751 tp
= any_live_thread_of_process (pid
);
1755 inf
= find_inferior_pid (pid
);
1756 old_chain
= save_inferior_ptid ();
1758 inferior_ptid
= tp
->ptid
;
1760 make_cleanup_ui_file_delete (tmp_error_stream
);
1762 ALL_BP_LOCATIONS (b
, bp_tmp
)
1764 if (b
->pspace
!= inf
->pspace
)
1770 val
= insert_bp_location (b
, tmp_error_stream
,
1774 do_cleanups (old_chain
);
1779 do_cleanups (old_chain
);
1783 static int internal_breakpoint_number
= -1;
1785 static struct breakpoint
*
1786 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1787 CORE_ADDR address
, enum bptype type
)
1789 struct symtab_and_line sal
;
1790 struct breakpoint
*b
;
1792 init_sal (&sal
); /* initialize to zeroes */
1795 sal
.section
= find_pc_overlay (sal
.pc
);
1796 sal
.pspace
= current_program_space
;
1798 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1799 b
->number
= internal_breakpoint_number
--;
1800 b
->disposition
= disp_donttouch
;
1806 create_overlay_event_breakpoint (char *func_name
)
1808 struct objfile
*objfile
;
1810 ALL_OBJFILES (objfile
)
1812 struct breakpoint
*b
;
1813 struct minimal_symbol
*m
;
1815 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1819 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1820 SYMBOL_VALUE_ADDRESS (m
),
1822 b
->addr_string
= xstrdup (func_name
);
1824 if (overlay_debugging
== ovly_auto
)
1826 b
->enable_state
= bp_enabled
;
1827 overlay_events_enabled
= 1;
1831 b
->enable_state
= bp_disabled
;
1832 overlay_events_enabled
= 0;
1835 update_global_location_list (1);
1839 create_longjmp_master_breakpoint (char *func_name
)
1841 struct program_space
*pspace
;
1842 struct objfile
*objfile
;
1843 struct cleanup
*old_chain
;
1845 old_chain
= save_current_program_space ();
1847 ALL_PSPACES (pspace
)
1848 ALL_OBJFILES (objfile
)
1850 struct breakpoint
*b
;
1851 struct minimal_symbol
*m
;
1853 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1856 set_current_program_space (pspace
);
1858 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1862 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1863 SYMBOL_VALUE_ADDRESS (m
),
1865 b
->addr_string
= xstrdup (func_name
);
1866 b
->enable_state
= bp_disabled
;
1868 update_global_location_list (1);
1870 do_cleanups (old_chain
);
1874 update_breakpoints_after_exec (void)
1876 struct breakpoint
*b
;
1877 struct breakpoint
*temp
;
1878 struct bp_location
*bploc
, **bplocp_tmp
;
1880 /* We're about to delete breakpoints from GDB's lists. If the
1881 INSERTED flag is true, GDB will try to lift the breakpoints by
1882 writing the breakpoints' "shadow contents" back into memory. The
1883 "shadow contents" are NOT valid after an exec, so GDB should not
1884 do that. Instead, the target is responsible from marking
1885 breakpoints out as soon as it detects an exec. We don't do that
1886 here instead, because there may be other attempts to delete
1887 breakpoints after detecting an exec and before reaching here. */
1888 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
1889 if (bploc
->pspace
== current_program_space
)
1890 gdb_assert (!bploc
->inserted
);
1892 ALL_BREAKPOINTS_SAFE (b
, temp
)
1894 if (b
->pspace
!= current_program_space
)
1897 /* Solib breakpoints must be explicitly reset after an exec(). */
1898 if (b
->type
== bp_shlib_event
)
1900 delete_breakpoint (b
);
1904 /* JIT breakpoints must be explicitly reset after an exec(). */
1905 if (b
->type
== bp_jit_event
)
1907 delete_breakpoint (b
);
1911 /* Thread event breakpoints must be set anew after an exec(),
1912 as must overlay event and longjmp master breakpoints. */
1913 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1914 || b
->type
== bp_longjmp_master
)
1916 delete_breakpoint (b
);
1920 /* Step-resume breakpoints are meaningless after an exec(). */
1921 if (b
->type
== bp_step_resume
)
1923 delete_breakpoint (b
);
1927 /* Longjmp and longjmp-resume breakpoints are also meaningless
1929 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1931 delete_breakpoint (b
);
1935 if (b
->type
== bp_catchpoint
)
1937 /* For now, none of the bp_catchpoint breakpoints need to
1938 do anything at this point. In the future, if some of
1939 the catchpoints need to something, we will need to add
1940 a new method, and call this method from here. */
1944 /* bp_finish is a special case. The only way we ought to be able
1945 to see one of these when an exec() has happened, is if the user
1946 caught a vfork, and then said "finish". Ordinarily a finish just
1947 carries them to the call-site of the current callee, by setting
1948 a temporary bp there and resuming. But in this case, the finish
1949 will carry them entirely through the vfork & exec.
1951 We don't want to allow a bp_finish to remain inserted now. But
1952 we can't safely delete it, 'cause finish_command has a handle to
1953 the bp on a bpstat, and will later want to delete it. There's a
1954 chance (and I've seen it happen) that if we delete the bp_finish
1955 here, that its storage will get reused by the time finish_command
1956 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1957 We really must allow finish_command to delete a bp_finish.
1959 In the absense of a general solution for the "how do we know
1960 it's safe to delete something others may have handles to?"
1961 problem, what we'll do here is just uninsert the bp_finish, and
1962 let finish_command delete it.
1964 (We know the bp_finish is "doomed" in the sense that it's
1965 momentary, and will be deleted as soon as finish_command sees
1966 the inferior stopped. So it doesn't matter that the bp's
1967 address is probably bogus in the new a.out, unlike e.g., the
1968 solib breakpoints.) */
1970 if (b
->type
== bp_finish
)
1975 /* Without a symbolic address, we have little hope of the
1976 pre-exec() address meaning the same thing in the post-exec()
1978 if (b
->addr_string
== NULL
)
1980 delete_breakpoint (b
);
1984 /* FIXME what about longjmp breakpoints? Re-create them here? */
1985 create_overlay_event_breakpoint ("_ovly_debug_event");
1986 create_longjmp_master_breakpoint ("longjmp");
1987 create_longjmp_master_breakpoint ("_longjmp");
1988 create_longjmp_master_breakpoint ("siglongjmp");
1989 create_longjmp_master_breakpoint ("_siglongjmp");
1993 detach_breakpoints (int pid
)
1995 struct bp_location
*b
, **bp_tmp
;
1997 struct cleanup
*old_chain
= save_inferior_ptid ();
1998 struct inferior
*inf
= current_inferior ();
2000 if (pid
== PIDGET (inferior_ptid
))
2001 error (_("Cannot detach breakpoints of inferior_ptid"));
2003 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2004 inferior_ptid
= pid_to_ptid (pid
);
2005 ALL_BP_LOCATIONS (b
, bp_tmp
)
2007 if (b
->pspace
!= inf
->pspace
)
2011 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2013 do_cleanups (old_chain
);
2017 /* Remove the breakpoint location B from the current address space.
2018 Note that this is used to detach breakpoints from a child fork.
2019 When we get here, the child isn't in the inferior list, and neither
2020 do we have objects to represent its address space --- we should
2021 *not* look at b->pspace->aspace here. */
2024 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2027 struct cleanup
*old_chain
;
2029 if (b
->owner
->enable_state
== bp_permanent
)
2030 /* Permanent breakpoints cannot be inserted or removed. */
2033 /* The type of none suggests that owner is actually deleted.
2034 This should not ever happen. */
2035 gdb_assert (b
->owner
->type
!= bp_none
);
2037 if (b
->loc_type
== bp_loc_software_breakpoint
2038 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2040 /* "Normal" instruction breakpoint: either the standard
2041 trap-instruction bp (bp_breakpoint), or a
2042 bp_hardware_breakpoint. */
2044 /* First check to see if we have to handle an overlay. */
2045 if (overlay_debugging
== ovly_off
2046 || b
->section
== NULL
2047 || !(section_is_overlay (b
->section
)))
2049 /* No overlay handling: just remove the breakpoint. */
2051 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2052 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2054 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2058 /* This breakpoint is in an overlay section.
2059 Did we set a breakpoint at the LMA? */
2060 if (!overlay_events_enabled
)
2062 /* Yes -- overlay event support is not active, so we
2063 should have set a breakpoint at the LMA. Remove it.
2065 /* Ignore any failures: if the LMA is in ROM, we will
2066 have already warned when we failed to insert it. */
2067 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2068 target_remove_hw_breakpoint (b
->gdbarch
,
2069 &b
->overlay_target_info
);
2071 target_remove_breakpoint (b
->gdbarch
,
2072 &b
->overlay_target_info
);
2074 /* Did we set a breakpoint at the VMA?
2075 If so, we will have marked the breakpoint 'inserted'. */
2078 /* Yes -- remove it. Previously we did not bother to
2079 remove the breakpoint if the section had been
2080 unmapped, but let's not rely on that being safe. We
2081 don't know what the overlay manager might do. */
2082 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2083 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2086 /* However, we should remove *software* breakpoints only
2087 if the section is still mapped, or else we overwrite
2088 wrong code with the saved shadow contents. */
2089 else if (section_is_mapped (b
->section
))
2090 val
= target_remove_breakpoint (b
->gdbarch
,
2097 /* No -- not inserted, so no need to remove. No error. */
2102 /* In some cases, we might not be able to remove a breakpoint
2103 in a shared library that has already been removed, but we
2104 have not yet processed the shlib unload event. */
2105 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2110 b
->inserted
= (is
== mark_inserted
);
2112 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2117 b
->inserted
= (is
== mark_inserted
);
2118 val
= target_remove_watchpoint (b
->address
, b
->length
,
2119 b
->watchpoint_type
);
2121 /* Failure to remove any of the hardware watchpoints comes here. */
2122 if ((is
== mark_uninserted
) && (b
->inserted
))
2123 warning (_("Could not remove hardware watchpoint %d."),
2126 else if (b
->owner
->type
== bp_catchpoint
2127 && breakpoint_enabled (b
->owner
)
2130 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2132 val
= b
->owner
->ops
->remove (b
->owner
);
2135 b
->inserted
= (is
== mark_inserted
);
2142 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2145 struct cleanup
*old_chain
;
2147 if (b
->owner
->enable_state
== bp_permanent
)
2148 /* Permanent breakpoints cannot be inserted or removed. */
2151 /* The type of none suggests that owner is actually deleted.
2152 This should not ever happen. */
2153 gdb_assert (b
->owner
->type
!= bp_none
);
2155 old_chain
= save_current_space_and_thread ();
2157 switch_to_program_space_and_thread (b
->pspace
);
2159 ret
= remove_breakpoint_1 (b
, is
);
2161 do_cleanups (old_chain
);
2165 /* Clear the "inserted" flag in all breakpoints. */
2168 mark_breakpoints_out (void)
2170 struct bp_location
*bpt
, **bptp_tmp
;
2172 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2173 if (bpt
->pspace
== current_program_space
)
2177 /* Clear the "inserted" flag in all breakpoints and delete any
2178 breakpoints which should go away between runs of the program.
2180 Plus other such housekeeping that has to be done for breakpoints
2183 Note: this function gets called at the end of a run (by
2184 generic_mourn_inferior) and when a run begins (by
2185 init_wait_for_inferior). */
2190 breakpoint_init_inferior (enum inf_context context
)
2192 struct breakpoint
*b
, *temp
;
2193 struct bp_location
*bpt
, **bptp_tmp
;
2195 struct program_space
*pspace
= current_program_space
;
2197 /* If breakpoint locations are shared across processes, then there's
2199 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2202 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2204 if (bpt
->pspace
== pspace
2205 && bpt
->owner
->enable_state
!= bp_permanent
)
2209 ALL_BREAKPOINTS_SAFE (b
, temp
)
2211 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2217 case bp_watchpoint_scope
:
2219 /* If the call dummy breakpoint is at the entry point it will
2220 cause problems when the inferior is rerun, so we better
2223 Also get rid of scope breakpoints. */
2224 delete_breakpoint (b
);
2228 case bp_hardware_watchpoint
:
2229 case bp_read_watchpoint
:
2230 case bp_access_watchpoint
:
2232 /* Likewise for watchpoints on local expressions. */
2233 if (b
->exp_valid_block
!= NULL
)
2234 delete_breakpoint (b
);
2235 else if (context
== inf_starting
)
2237 /* Reset val field to force reread of starting value
2238 in insert_breakpoints. */
2240 value_free (b
->val
);
2250 /* Get rid of the moribund locations. */
2251 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2252 free_bp_location (bpt
);
2253 VEC_free (bp_location_p
, moribund_locations
);
2256 /* These functions concern about actual breakpoints inserted in the
2257 target --- to e.g. check if we need to do decr_pc adjustment or if
2258 we need to hop over the bkpt --- so we check for address space
2259 match, not program space. */
2261 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2262 exists at PC. It returns ordinary_breakpoint_here if it's an
2263 ordinary breakpoint, or permanent_breakpoint_here if it's a
2264 permanent breakpoint.
2265 - When continuing from a location with an ordinary breakpoint, we
2266 actually single step once before calling insert_breakpoints.
2267 - When continuing from a localion with a permanent breakpoint, we
2268 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2269 the target, to advance the PC past the breakpoint. */
2271 enum breakpoint_here
2272 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2274 struct bp_location
*bpt
, **bptp_tmp
;
2275 int any_breakpoint_here
= 0;
2277 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2279 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2280 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2283 if ((breakpoint_enabled (bpt
->owner
)
2284 || bpt
->owner
->enable_state
== bp_permanent
)
2285 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2288 if (overlay_debugging
2289 && section_is_overlay (bpt
->section
)
2290 && !section_is_mapped (bpt
->section
))
2291 continue; /* unmapped overlay -- can't be a match */
2292 else if (bpt
->owner
->enable_state
== bp_permanent
)
2293 return permanent_breakpoint_here
;
2295 any_breakpoint_here
= 1;
2299 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2302 /* Return true if there's a moribund breakpoint at PC. */
2305 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2307 struct bp_location
*loc
;
2310 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2311 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2318 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2319 inserted using regular breakpoint_chain / bp_location array mechanism.
2320 This does not check for single-step breakpoints, which are
2321 inserted and removed using direct target manipulation. */
2324 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2326 struct bp_location
*bpt
, **bptp_tmp
;
2328 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2330 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2331 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2335 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2338 if (overlay_debugging
2339 && section_is_overlay (bpt
->section
)
2340 && !section_is_mapped (bpt
->section
))
2341 continue; /* unmapped overlay -- can't be a match */
2349 /* Returns non-zero iff there's either regular breakpoint
2350 or a single step breakpoint inserted at PC. */
2353 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2355 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2358 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2364 /* This function returns non-zero iff there is a software breakpoint
2368 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2370 struct bp_location
*bpt
, **bptp_tmp
;
2371 int any_breakpoint_here
= 0;
2373 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2375 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2379 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2382 if (overlay_debugging
2383 && section_is_overlay (bpt
->section
)
2384 && !section_is_mapped (bpt
->section
))
2385 continue; /* unmapped overlay -- can't be a match */
2391 /* Also check for software single-step breakpoints. */
2392 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2399 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2400 CORE_ADDR addr
, ULONGEST len
)
2402 struct breakpoint
*bpt
;
2404 ALL_BREAKPOINTS (bpt
)
2406 struct bp_location
*loc
;
2408 if (bpt
->type
!= bp_hardware_watchpoint
2409 && bpt
->type
!= bp_access_watchpoint
)
2412 if (!breakpoint_enabled (bpt
))
2415 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2416 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2420 /* Check for intersection. */
2421 l
= max (loc
->address
, addr
);
2422 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2430 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2431 PC is valid for process/thread PTID. */
2434 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2437 struct bp_location
*bpt
, **bptp_tmp
;
2438 /* The thread and task IDs associated to PTID, computed lazily. */
2442 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2444 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2445 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2448 if (!breakpoint_enabled (bpt
->owner
)
2449 && bpt
->owner
->enable_state
!= bp_permanent
)
2452 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2456 if (bpt
->owner
->thread
!= -1)
2458 /* This is a thread-specific breakpoint. Check that ptid
2459 matches that thread. If thread hasn't been computed yet,
2460 it is now time to do so. */
2462 thread
= pid_to_thread_id (ptid
);
2463 if (bpt
->owner
->thread
!= thread
)
2467 if (bpt
->owner
->task
!= 0)
2469 /* This is a task-specific breakpoint. Check that ptid
2470 matches that task. If task hasn't been computed yet,
2471 it is now time to do so. */
2473 task
= ada_get_task_number (ptid
);
2474 if (bpt
->owner
->task
!= task
)
2478 if (overlay_debugging
2479 && section_is_overlay (bpt
->section
)
2480 && !section_is_mapped (bpt
->section
))
2481 continue; /* unmapped overlay -- can't be a match */
2490 /* bpstat stuff. External routines' interfaces are documented
2494 ep_is_catchpoint (struct breakpoint
*ep
)
2496 return (ep
->type
== bp_catchpoint
);
2500 bpstat_free (bpstat bs
)
2502 if (bs
->old_val
!= NULL
)
2503 value_free (bs
->old_val
);
2504 free_command_lines (&bs
->commands
);
2508 /* Clear a bpstat so that it says we are not at any breakpoint.
2509 Also free any storage that is part of a bpstat. */
2512 bpstat_clear (bpstat
*bsp
)
2529 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2530 is part of the bpstat is copied as well. */
2533 bpstat_copy (bpstat bs
)
2537 bpstat retval
= NULL
;
2542 for (; bs
!= NULL
; bs
= bs
->next
)
2544 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2545 memcpy (tmp
, bs
, sizeof (*tmp
));
2546 if (bs
->commands
!= NULL
)
2547 tmp
->commands
= copy_command_lines (bs
->commands
);
2548 if (bs
->old_val
!= NULL
)
2550 tmp
->old_val
= value_copy (bs
->old_val
);
2551 release_value (tmp
->old_val
);
2555 /* This is the first thing in the chain. */
2565 /* Find the bpstat associated with this breakpoint */
2568 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2573 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2575 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2581 /* Find a step_resume breakpoint associated with this bpstat.
2582 (If there are multiple step_resume bp's on the list, this function
2583 will arbitrarily pick one.)
2585 It is an error to use this function if BPSTAT doesn't contain a
2586 step_resume breakpoint.
2588 See wait_for_inferior's use of this function. */
2590 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2594 gdb_assert (bsp
!= NULL
);
2596 current_thread
= pid_to_thread_id (inferior_ptid
);
2598 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2600 if ((bsp
->breakpoint_at
!= NULL
)
2601 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2602 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2603 || bsp
->breakpoint_at
->owner
->thread
== -1))
2604 return bsp
->breakpoint_at
->owner
;
2607 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2611 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2612 at. *BSP upon return is a bpstat which points to the remaining
2613 breakpoints stopped at (but which is not guaranteed to be good for
2614 anything but further calls to bpstat_num).
2615 Return 0 if passed a bpstat which does not indicate any breakpoints.
2616 Return -1 if stopped at a breakpoint that has been deleted since
2618 Return 1 otherwise. */
2621 bpstat_num (bpstat
*bsp
, int *num
)
2623 struct breakpoint
*b
;
2626 return 0; /* No more breakpoint values */
2628 /* We assume we'll never have several bpstats that
2629 correspond to a single breakpoint -- otherwise,
2630 this function might return the same number more
2631 than once and this will look ugly. */
2632 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2633 *bsp
= (*bsp
)->next
;
2635 return -1; /* breakpoint that's been deleted since */
2637 *num
= b
->number
; /* We have its number */
2641 /* Modify BS so that the actions will not be performed. */
2644 bpstat_clear_actions (bpstat bs
)
2646 for (; bs
!= NULL
; bs
= bs
->next
)
2648 free_command_lines (&bs
->commands
);
2649 if (bs
->old_val
!= NULL
)
2651 value_free (bs
->old_val
);
2657 /* Called when a command is about to proceed the inferior. */
2660 breakpoint_about_to_proceed (void)
2662 if (!ptid_equal (inferior_ptid
, null_ptid
))
2664 struct thread_info
*tp
= inferior_thread ();
2666 /* Allow inferior function calls in breakpoint commands to not
2667 interrupt the command list. When the call finishes
2668 successfully, the inferior will be standing at the same
2669 breakpoint as if nothing happened. */
2674 breakpoint_proceeded
= 1;
2677 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2679 cleanup_executing_breakpoints (void *ignore
)
2681 executing_breakpoint_commands
= 0;
2684 /* Execute all the commands associated with all the breakpoints at this
2685 location. Any of these commands could cause the process to proceed
2686 beyond this point, etc. We look out for such changes by checking
2687 the global "breakpoint_proceeded" after each command.
2689 Returns true if a breakpoint command resumed the inferior. In that
2690 case, it is the caller's responsibility to recall it again with the
2691 bpstat of the current thread. */
2694 bpstat_do_actions_1 (bpstat
*bsp
)
2697 struct cleanup
*old_chain
;
2700 /* Avoid endless recursion if a `source' command is contained
2702 if (executing_breakpoint_commands
)
2705 executing_breakpoint_commands
= 1;
2706 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2708 /* This pointer will iterate over the list of bpstat's. */
2711 breakpoint_proceeded
= 0;
2712 for (; bs
!= NULL
; bs
= bs
->next
)
2714 struct command_line
*cmd
;
2715 struct cleanup
*this_cmd_tree_chain
;
2717 /* Take ownership of the BSP's command tree, if it has one.
2719 The command tree could legitimately contain commands like
2720 'step' and 'next', which call clear_proceed_status, which
2721 frees stop_bpstat's command tree. To make sure this doesn't
2722 free the tree we're executing out from under us, we need to
2723 take ownership of the tree ourselves. Since a given bpstat's
2724 commands are only executed once, we don't need to copy it; we
2725 can clear the pointer in the bpstat, and make sure we free
2726 the tree when we're done. */
2729 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2733 execute_control_command (cmd
);
2735 if (breakpoint_proceeded
)
2741 /* We can free this command tree now. */
2742 do_cleanups (this_cmd_tree_chain
);
2744 if (breakpoint_proceeded
)
2746 if (target_can_async_p ())
2747 /* If we are in async mode, then the target might be still
2748 running, not stopped at any breakpoint, so nothing for
2749 us to do here -- just return to the event loop. */
2752 /* In sync mode, when execute_control_command returns
2753 we're already standing on the next breakpoint.
2754 Breakpoint commands for that stop were not run, since
2755 execute_command does not run breakpoint commands --
2756 only command_line_handler does, but that one is not
2757 involved in execution of breakpoint commands. So, we
2758 can now execute breakpoint commands. It should be
2759 noted that making execute_command do bpstat actions is
2760 not an option -- in this case we'll have recursive
2761 invocation of bpstat for each breakpoint with a
2762 command, and can easily blow up GDB stack. Instead, we
2763 return true, which will trigger the caller to recall us
2764 with the new stop_bpstat. */
2769 do_cleanups (old_chain
);
2774 bpstat_do_actions (void)
2776 /* Do any commands attached to breakpoint we are stopped at. */
2777 while (!ptid_equal (inferior_ptid
, null_ptid
)
2778 && target_has_execution
2779 && !is_exited (inferior_ptid
)
2780 && !is_executing (inferior_ptid
))
2781 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2782 and only return when it is stopped at the next breakpoint, we
2783 keep doing breakpoint actions until it returns false to
2784 indicate the inferior was not resumed. */
2785 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2789 /* Print out the (old or new) value associated with a watchpoint. */
2792 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2795 fprintf_unfiltered (stream
, _("<unreadable>"));
2798 struct value_print_options opts
;
2799 get_user_print_options (&opts
);
2800 value_print (val
, stream
, &opts
);
2804 /* This is the normal print function for a bpstat. In the future,
2805 much of this logic could (should?) be moved to bpstat_stop_status,
2806 by having it set different print_it values.
2808 Current scheme: When we stop, bpstat_print() is called. It loops
2809 through the bpstat list of things causing this stop, calling the
2810 print_bp_stop_message function on each one. The behavior of the
2811 print_bp_stop_message function depends on the print_it field of
2812 bpstat. If such field so indicates, call this function here.
2814 Return values from this routine (ultimately used by bpstat_print()
2815 and normal_stop() to decide what to do):
2816 PRINT_NOTHING: Means we already printed all we needed to print,
2817 don't print anything else.
2818 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2819 that something to be followed by a location.
2820 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2821 that something to be followed by a location.
2822 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2825 static enum print_stop_action
2826 print_it_typical (bpstat bs
)
2828 struct cleanup
*old_chain
;
2829 struct breakpoint
*b
;
2830 const struct bp_location
*bl
;
2831 struct ui_stream
*stb
;
2833 enum print_stop_action result
;
2835 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2836 which has since been deleted. */
2837 if (bs
->breakpoint_at
== NULL
)
2838 return PRINT_UNKNOWN
;
2839 bl
= bs
->breakpoint_at
;
2842 stb
= ui_out_stream_new (uiout
);
2843 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2848 case bp_hardware_breakpoint
:
2849 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2850 if (bl
->address
!= bl
->requested_address
)
2851 breakpoint_adjustment_warning (bl
->requested_address
,
2854 annotate_breakpoint (b
->number
);
2856 ui_out_text (uiout
, "\nTemporary breakpoint ");
2858 ui_out_text (uiout
, "\nBreakpoint ");
2859 if (ui_out_is_mi_like_p (uiout
))
2861 ui_out_field_string (uiout
, "reason",
2862 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2863 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2865 ui_out_field_int (uiout
, "bkptno", b
->number
);
2866 ui_out_text (uiout
, ", ");
2867 result
= PRINT_SRC_AND_LOC
;
2870 case bp_shlib_event
:
2871 /* Did we stop because the user set the stop_on_solib_events
2872 variable? (If so, we report this as a generic, "Stopped due
2873 to shlib event" message.) */
2874 printf_filtered (_("Stopped due to shared library event\n"));
2875 result
= PRINT_NOTHING
;
2878 case bp_thread_event
:
2879 /* Not sure how we will get here.
2880 GDB should not stop for these breakpoints. */
2881 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2882 result
= PRINT_NOTHING
;
2885 case bp_overlay_event
:
2886 /* By analogy with the thread event, GDB should not stop for these. */
2887 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2888 result
= PRINT_NOTHING
;
2891 case bp_longjmp_master
:
2892 /* These should never be enabled. */
2893 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2894 result
= PRINT_NOTHING
;
2898 case bp_hardware_watchpoint
:
2899 annotate_watchpoint (b
->number
);
2900 if (ui_out_is_mi_like_p (uiout
))
2903 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2905 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2906 ui_out_text (uiout
, "\nOld value = ");
2907 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2908 ui_out_field_stream (uiout
, "old", stb
);
2909 ui_out_text (uiout
, "\nNew value = ");
2910 watchpoint_value_print (b
->val
, stb
->stream
);
2911 ui_out_field_stream (uiout
, "new", stb
);
2912 ui_out_text (uiout
, "\n");
2913 /* More than one watchpoint may have been triggered. */
2914 result
= PRINT_UNKNOWN
;
2917 case bp_read_watchpoint
:
2918 if (ui_out_is_mi_like_p (uiout
))
2921 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2923 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2924 ui_out_text (uiout
, "\nValue = ");
2925 watchpoint_value_print (b
->val
, stb
->stream
);
2926 ui_out_field_stream (uiout
, "value", stb
);
2927 ui_out_text (uiout
, "\n");
2928 result
= PRINT_UNKNOWN
;
2931 case bp_access_watchpoint
:
2932 if (bs
->old_val
!= NULL
)
2934 annotate_watchpoint (b
->number
);
2935 if (ui_out_is_mi_like_p (uiout
))
2938 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2940 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2941 ui_out_text (uiout
, "\nOld value = ");
2942 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2943 ui_out_field_stream (uiout
, "old", stb
);
2944 ui_out_text (uiout
, "\nNew value = ");
2949 if (ui_out_is_mi_like_p (uiout
))
2952 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2953 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2954 ui_out_text (uiout
, "\nValue = ");
2956 watchpoint_value_print (b
->val
, stb
->stream
);
2957 ui_out_field_stream (uiout
, "new", stb
);
2958 ui_out_text (uiout
, "\n");
2959 result
= PRINT_UNKNOWN
;
2962 /* Fall through, we don't deal with these types of breakpoints
2966 if (ui_out_is_mi_like_p (uiout
))
2969 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2970 result
= PRINT_UNKNOWN
;
2974 if (ui_out_is_mi_like_p (uiout
))
2977 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2978 result
= PRINT_UNKNOWN
;
2983 case bp_longjmp_resume
:
2984 case bp_step_resume
:
2985 case bp_watchpoint_scope
:
2988 case bp_fast_tracepoint
:
2991 result
= PRINT_UNKNOWN
;
2995 do_cleanups (old_chain
);
2999 /* Generic routine for printing messages indicating why we
3000 stopped. The behavior of this function depends on the value
3001 'print_it' in the bpstat structure. Under some circumstances we
3002 may decide not to print anything here and delegate the task to
3005 static enum print_stop_action
3006 print_bp_stop_message (bpstat bs
)
3008 switch (bs
->print_it
)
3011 /* Nothing should be printed for this bpstat entry. */
3012 return PRINT_UNKNOWN
;
3016 /* We still want to print the frame, but we already printed the
3017 relevant messages. */
3018 return PRINT_SRC_AND_LOC
;
3021 case print_it_normal
:
3023 const struct bp_location
*bl
= bs
->breakpoint_at
;
3024 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3026 /* Normal case. Call the breakpoint's print_it method, or
3027 print_it_typical. */
3028 /* FIXME: how breakpoint can ever be NULL here? */
3029 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3030 return b
->ops
->print_it (b
);
3032 return print_it_typical (bs
);
3037 internal_error (__FILE__
, __LINE__
,
3038 _("print_bp_stop_message: unrecognized enum value"));
3043 /* Print a message indicating what happened. This is called from
3044 normal_stop(). The input to this routine is the head of the bpstat
3045 list - a list of the eventpoints that caused this stop. This
3046 routine calls the generic print routine for printing a message
3047 about reasons for stopping. This will print (for example) the
3048 "Breakpoint n," part of the output. The return value of this
3051 PRINT_UNKNOWN: Means we printed nothing
3052 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3053 code to print the location. An example is
3054 "Breakpoint 1, " which should be followed by
3056 PRINT_SRC_ONLY: Means we printed something, but there is no need
3057 to also print the location part of the message.
3058 An example is the catch/throw messages, which
3059 don't require a location appended to the end.
3060 PRINT_NOTHING: We have done some printing and we don't need any
3061 further info to be printed.*/
3063 enum print_stop_action
3064 bpstat_print (bpstat bs
)
3068 /* Maybe another breakpoint in the chain caused us to stop.
3069 (Currently all watchpoints go on the bpstat whether hit or not.
3070 That probably could (should) be changed, provided care is taken
3071 with respect to bpstat_explains_signal). */
3072 for (; bs
; bs
= bs
->next
)
3074 val
= print_bp_stop_message (bs
);
3075 if (val
== PRINT_SRC_ONLY
3076 || val
== PRINT_SRC_AND_LOC
3077 || val
== PRINT_NOTHING
)
3081 /* We reached the end of the chain, or we got a null BS to start
3082 with and nothing was printed. */
3083 return PRINT_UNKNOWN
;
3086 /* Evaluate the expression EXP and return 1 if value is zero.
3087 This is used inside a catch_errors to evaluate the breakpoint condition.
3088 The argument is a "struct expression *" that has been cast to char * to
3089 make it pass through catch_errors. */
3092 breakpoint_cond_eval (void *exp
)
3094 struct value
*mark
= value_mark ();
3095 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3096 value_free_to_mark (mark
);
3100 /* Allocate a new bpstat and chain it to the current one. */
3103 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3107 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3109 bs
->breakpoint_at
= bl
;
3110 /* If the condition is false, etc., don't do the commands. */
3111 bs
->commands
= NULL
;
3113 bs
->print_it
= print_it_normal
;
3117 /* The target has stopped with waitstatus WS. Check if any hardware
3118 watchpoints have triggered, according to the target. */
3121 watchpoints_triggered (struct target_waitstatus
*ws
)
3123 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3125 struct breakpoint
*b
;
3127 if (!stopped_by_watchpoint
)
3129 /* We were not stopped by a watchpoint. Mark all watchpoints
3130 as not triggered. */
3132 if (b
->type
== bp_hardware_watchpoint
3133 || b
->type
== bp_read_watchpoint
3134 || b
->type
== bp_access_watchpoint
)
3135 b
->watchpoint_triggered
= watch_triggered_no
;
3140 if (!target_stopped_data_address (¤t_target
, &addr
))
3142 /* We were stopped by a watchpoint, but we don't know where.
3143 Mark all watchpoints as unknown. */
3145 if (b
->type
== bp_hardware_watchpoint
3146 || b
->type
== bp_read_watchpoint
3147 || b
->type
== bp_access_watchpoint
)
3148 b
->watchpoint_triggered
= watch_triggered_unknown
;
3150 return stopped_by_watchpoint
;
3153 /* The target could report the data address. Mark watchpoints
3154 affected by this data address as triggered, and all others as not
3158 if (b
->type
== bp_hardware_watchpoint
3159 || b
->type
== bp_read_watchpoint
3160 || b
->type
== bp_access_watchpoint
)
3162 struct bp_location
*loc
;
3165 b
->watchpoint_triggered
= watch_triggered_no
;
3166 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3167 /* Exact match not required. Within range is
3169 if (target_watchpoint_addr_within_range (¤t_target
,
3173 b
->watchpoint_triggered
= watch_triggered_yes
;
3181 /* Possible return values for watchpoint_check (this can't be an enum
3182 because of check_errors). */
3183 /* The watchpoint has been deleted. */
3184 #define WP_DELETED 1
3185 /* The value has changed. */
3186 #define WP_VALUE_CHANGED 2
3187 /* The value has not changed. */
3188 #define WP_VALUE_NOT_CHANGED 3
3190 #define BP_TEMPFLAG 1
3191 #define BP_HARDWAREFLAG 2
3193 /* Evaluate watchpoint condition expression and check if its value changed.
3195 P should be a pointer to struct bpstat, but is defined as a void *
3196 in order for this function to be usable with catch_errors. */
3199 watchpoint_check (void *p
)
3201 bpstat bs
= (bpstat
) p
;
3202 struct breakpoint
*b
;
3203 struct frame_info
*fr
;
3204 int within_current_scope
;
3206 b
= bs
->breakpoint_at
->owner
;
3208 /* If this is a local watchpoint, we only want to check if the
3209 watchpoint frame is in scope if the current thread is the thread
3210 that was used to create the watchpoint. */
3211 if (!watchpoint_in_thread_scope (b
))
3212 return WP_VALUE_NOT_CHANGED
;
3214 if (b
->exp_valid_block
== NULL
)
3215 within_current_scope
= 1;
3218 struct frame_info
*frame
= get_current_frame ();
3219 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3220 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3222 fr
= frame_find_by_id (b
->watchpoint_frame
);
3223 within_current_scope
= (fr
!= NULL
);
3225 /* If we've gotten confused in the unwinder, we might have
3226 returned a frame that can't describe this variable. */
3227 if (within_current_scope
)
3229 struct symbol
*function
;
3231 function
= get_frame_function (fr
);
3232 if (function
== NULL
3233 || !contained_in (b
->exp_valid_block
,
3234 SYMBOL_BLOCK_VALUE (function
)))
3235 within_current_scope
= 0;
3238 /* in_function_epilogue_p() returns a non-zero value if we're still
3239 in the function but the stack frame has already been invalidated.
3240 Since we can't rely on the values of local variables after the
3241 stack has been destroyed, we are treating the watchpoint in that
3242 state as `not changed' without further checking. Don't mark
3243 watchpoints as changed if the current frame is in an epilogue -
3244 even if they are in some other frame, our view of the stack
3245 is likely to be wrong. */
3246 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3247 return WP_VALUE_NOT_CHANGED
;
3249 if (within_current_scope
)
3250 /* If we end up stopping, the current frame will get selected
3251 in normal_stop. So this call to select_frame won't affect
3256 if (within_current_scope
)
3258 /* We use value_{,free_to_}mark because it could be a
3259 *long* time before we return to the command level and
3260 call free_all_values. We can't call free_all_values because
3261 we might be in the middle of evaluating a function call. */
3263 struct value
*mark
= value_mark ();
3264 struct value
*new_val
;
3266 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3268 /* We use value_equal_contents instead of value_equal because the latter
3269 coerces an array to a pointer, thus comparing just the address of the
3270 array instead of its contents. This is not what we want. */
3271 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3272 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3274 if (new_val
!= NULL
)
3276 release_value (new_val
);
3277 value_free_to_mark (mark
);
3279 bs
->old_val
= b
->val
;
3282 /* We will stop here */
3283 return WP_VALUE_CHANGED
;
3287 /* Nothing changed, don't do anything. */
3288 value_free_to_mark (mark
);
3289 /* We won't stop here */
3290 return WP_VALUE_NOT_CHANGED
;
3295 /* This seems like the only logical thing to do because
3296 if we temporarily ignored the watchpoint, then when
3297 we reenter the block in which it is valid it contains
3298 garbage (in the case of a function, it may have two
3299 garbage values, one before and one after the prologue).
3300 So we can't even detect the first assignment to it and
3301 watch after that (since the garbage may or may not equal
3302 the first value assigned). */
3303 /* We print all the stop information in print_it_typical(), but
3304 in this case, by the time we call print_it_typical() this bp
3305 will be deleted already. So we have no choice but print the
3306 information here. */
3307 if (ui_out_is_mi_like_p (uiout
))
3309 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3310 ui_out_text (uiout
, "\nWatchpoint ");
3311 ui_out_field_int (uiout
, "wpnum", b
->number
);
3312 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3313 which its expression is valid.\n");
3315 if (b
->related_breakpoint
)
3316 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3317 b
->disposition
= disp_del_at_next_stop
;
3323 /* Return true if it looks like target has stopped due to hitting
3324 breakpoint location BL. This function does not check if we
3325 should stop, only if BL explains the stop. */
3327 bpstat_check_location (const struct bp_location
*bl
,
3328 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3330 struct breakpoint
*b
= bl
->owner
;
3332 /* By definition, the inferior does not report stops at
3334 if (tracepoint_type (b
))
3337 if (b
->type
!= bp_watchpoint
3338 && b
->type
!= bp_hardware_watchpoint
3339 && b
->type
!= bp_read_watchpoint
3340 && b
->type
!= bp_access_watchpoint
3341 && b
->type
!= bp_hardware_breakpoint
3342 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3344 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3347 if (overlay_debugging
/* unmapped overlay section */
3348 && section_is_overlay (bl
->section
)
3349 && !section_is_mapped (bl
->section
))
3353 /* Continuable hardware watchpoints are treated as non-existent if the
3354 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3355 some data address). Otherwise gdb won't stop on a break instruction
3356 in the code (not from a breakpoint) when a hardware watchpoint has
3357 been defined. Also skip watchpoints which we know did not trigger
3358 (did not match the data address). */
3360 if ((b
->type
== bp_hardware_watchpoint
3361 || b
->type
== bp_read_watchpoint
3362 || b
->type
== bp_access_watchpoint
)
3363 && b
->watchpoint_triggered
== watch_triggered_no
)
3366 if (b
->type
== bp_hardware_breakpoint
)
3368 if (bl
->address
!= bp_addr
)
3370 if (overlay_debugging
/* unmapped overlay section */
3371 && section_is_overlay (bl
->section
)
3372 && !section_is_mapped (bl
->section
))
3376 if (b
->type
== bp_catchpoint
)
3378 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3379 if (!b
->ops
->breakpoint_hit (b
))
3386 /* If BS refers to a watchpoint, determine if the watched values
3387 has actually changed, and we should stop. If not, set BS->stop
3390 bpstat_check_watchpoint (bpstat bs
)
3392 const struct bp_location
*bl
= bs
->breakpoint_at
;
3393 struct breakpoint
*b
= bl
->owner
;
3395 if (b
->type
== bp_watchpoint
3396 || b
->type
== bp_read_watchpoint
3397 || b
->type
== bp_access_watchpoint
3398 || b
->type
== bp_hardware_watchpoint
)
3402 int must_check_value
= 0;
3404 if (b
->type
== bp_watchpoint
)
3405 /* For a software watchpoint, we must always check the
3407 must_check_value
= 1;
3408 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3409 /* We have a hardware watchpoint (read, write, or access)
3410 and the target earlier reported an address watched by
3412 must_check_value
= 1;
3413 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3414 && b
->type
== bp_hardware_watchpoint
)
3415 /* We were stopped by a hardware watchpoint, but the target could
3416 not report the data address. We must check the watchpoint's
3417 value. Access and read watchpoints are out of luck; without
3418 a data address, we can't figure it out. */
3419 must_check_value
= 1;
3421 if (must_check_value
)
3423 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3425 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3426 int e
= catch_errors (watchpoint_check
, bs
, message
,
3428 do_cleanups (cleanups
);
3432 /* We've already printed what needs to be printed. */
3433 bs
->print_it
= print_it_done
;
3436 case WP_VALUE_CHANGED
:
3437 if (b
->type
== bp_read_watchpoint
)
3439 /* Don't stop: read watchpoints shouldn't fire if
3440 the value has changed. This is for targets
3441 which cannot set read-only watchpoints. */
3442 bs
->print_it
= print_it_noop
;
3446 case WP_VALUE_NOT_CHANGED
:
3447 if (b
->type
== bp_hardware_watchpoint
3448 || b
->type
== bp_watchpoint
)
3450 /* Don't stop: write watchpoints shouldn't fire if
3451 the value hasn't changed. */
3452 bs
->print_it
= print_it_noop
;
3460 /* Error from catch_errors. */
3461 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3462 if (b
->related_breakpoint
)
3463 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3464 b
->disposition
= disp_del_at_next_stop
;
3465 /* We've already printed what needs to be printed. */
3466 bs
->print_it
= print_it_done
;
3470 else /* must_check_value == 0 */
3472 /* This is a case where some watchpoint(s) triggered, but
3473 not at the address of this watchpoint, or else no
3474 watchpoint triggered after all. So don't print
3475 anything for this watchpoint. */
3476 bs
->print_it
= print_it_noop
;
3483 /* Check conditions (condition proper, frame, thread and ignore count)
3484 of breakpoint referred to by BS. If we should not stop for this
3485 breakpoint, set BS->stop to 0. */
3487 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3489 int thread_id
= pid_to_thread_id (ptid
);
3490 const struct bp_location
*bl
= bs
->breakpoint_at
;
3491 struct breakpoint
*b
= bl
->owner
;
3493 if (frame_id_p (b
->frame_id
)
3494 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3498 int value_is_zero
= 0;
3500 /* If this is a scope breakpoint, mark the associated
3501 watchpoint as triggered so that we will handle the
3502 out-of-scope event. We'll get to the watchpoint next
3504 if (b
->type
== bp_watchpoint_scope
)
3505 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3507 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3509 /* We use value_mark and value_free_to_mark because it could
3510 be a long time before we return to the command level and
3511 call free_all_values. We can't call free_all_values
3512 because we might be in the middle of evaluating a
3514 struct value
*mark
= value_mark ();
3516 /* Need to select the frame, with all that implies so that
3517 the conditions will have the right context. Because we
3518 use the frame, we will not see an inlined function's
3519 variables when we arrive at a breakpoint at the start
3520 of the inlined function; the current frame will be the
3522 select_frame (get_current_frame ());
3524 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3525 "Error in testing breakpoint condition:\n",
3527 /* FIXME-someday, should give breakpoint # */
3528 value_free_to_mark (mark
);
3530 if (bl
->cond
&& value_is_zero
)
3534 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3538 else if (b
->ignore_count
> 0)
3541 annotate_ignore_count_change ();
3543 /* Increase the hit count even though we don't
3551 /* Get a bpstat associated with having just stopped at address
3552 BP_ADDR in thread PTID.
3554 Determine whether we stopped at a breakpoint, etc, or whether we
3555 don't understand this stop. Result is a chain of bpstat's such that:
3557 if we don't understand the stop, the result is a null pointer.
3559 if we understand why we stopped, the result is not null.
3561 Each element of the chain refers to a particular breakpoint or
3562 watchpoint at which we have stopped. (We may have stopped for
3563 several reasons concurrently.)
3565 Each element of the chain has valid next, breakpoint_at,
3566 commands, FIXME??? fields. */
3569 bpstat_stop_status (struct address_space
*aspace
,
3570 CORE_ADDR bp_addr
, ptid_t ptid
)
3572 struct breakpoint
*b
= NULL
;
3573 struct bp_location
*bl
, **blp_tmp
;
3574 struct bp_location
*loc
;
3575 /* Root of the chain of bpstat's */
3576 struct bpstats root_bs
[1];
3577 /* Pointer to the last thing in the chain currently. */
3578 bpstat bs
= root_bs
;
3580 int need_remove_insert
;
3582 /* ALL_BP_LOCATIONS iteration would break across
3583 update_global_location_list possibly executed by
3584 bpstat_check_breakpoint_conditions's inferior call. */
3588 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3591 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
3593 /* For hardware watchpoints, we look only at the first location.
3594 The watchpoint_check function will work on entire expression,
3595 not the individual locations. For read watchopints, the
3596 watchpoints_triggered function have checked all locations
3598 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3601 if (bl
->shlib_disabled
)
3604 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
3607 /* Come here if it's a watchpoint, or if the break address matches */
3609 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3611 /* Assume we stop. Should we find watchpoint that is not actually
3612 triggered, or if condition of breakpoint is false, we'll reset
3617 bpstat_check_watchpoint (bs
);
3621 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3622 || b
->type
== bp_longjmp_master
)
3623 /* We do not stop for these. */
3626 bpstat_check_breakpoint_conditions (bs
, ptid
);
3632 /* We will stop here */
3633 if (b
->disposition
== disp_disable
)
3635 if (b
->enable_state
!= bp_permanent
)
3636 b
->enable_state
= bp_disabled
;
3637 update_global_location_list (0);
3641 bs
->commands
= b
->commands
;
3643 && (strcmp ("silent", bs
->commands
->line
) == 0
3644 || (xdb_commands
&& strcmp ("Q",
3645 bs
->commands
->line
) == 0)))
3647 bs
->commands
= bs
->commands
->next
;
3650 bs
->commands
= copy_command_lines (bs
->commands
);
3653 /* Print nothing for this entry if we dont stop or dont print. */
3654 if (bs
->stop
== 0 || bs
->print
== 0)
3655 bs
->print_it
= print_it_noop
;
3659 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3661 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
3664 bs
= bpstat_alloc (loc
, bs
);
3665 /* For hits of moribund locations, we should just proceed. */
3668 bs
->print_it
= print_it_noop
;
3672 bs
->next
= NULL
; /* Terminate the chain */
3673 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3675 /* If we aren't stopping, the value of some hardware watchpoint may
3676 not have changed, but the intermediate memory locations we are
3677 watching may have. Don't bother if we're stopping; this will get
3679 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3683 need_remove_insert
= 0;
3685 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3687 && bs
->breakpoint_at
->owner
3688 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
3690 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
3691 /* Updating watchpoints invalidates bs->breakpoint_at.
3692 Prevent further code from trying to use it. */
3693 bs
->breakpoint_at
= NULL
;
3694 need_remove_insert
= 1;
3697 if (need_remove_insert
)
3698 update_global_location_list (1);
3700 return root_bs
->next
;
3703 /* Tell what to do about this bpstat. */
3705 bpstat_what (bpstat bs
)
3707 /* Classify each bpstat as one of the following. */
3710 /* This bpstat element has no effect on the main_action. */
3713 /* There was a watchpoint, stop but don't print. */
3716 /* There was a watchpoint, stop and print. */
3719 /* There was a breakpoint but we're not stopping. */
3722 /* There was a breakpoint, stop but don't print. */
3725 /* There was a breakpoint, stop and print. */
3728 /* We hit the longjmp breakpoint. */
3731 /* We hit the longjmp_resume breakpoint. */
3734 /* We hit the step_resume breakpoint. */
3737 /* We hit the shared library event breakpoint. */
3740 /* We hit the jit event breakpoint. */
3743 /* This is just used to count how many enums there are. */
3747 /* Here is the table which drives this routine. So that we can
3748 format it pretty, we define some abbreviations for the
3749 enum bpstat_what codes. */
3750 #define kc BPSTAT_WHAT_KEEP_CHECKING
3751 #define ss BPSTAT_WHAT_STOP_SILENT
3752 #define sn BPSTAT_WHAT_STOP_NOISY
3753 #define sgl BPSTAT_WHAT_SINGLE
3754 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3755 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3756 #define sr BPSTAT_WHAT_STEP_RESUME
3757 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3758 #define jit BPSTAT_WHAT_CHECK_JIT
3760 /* "Can't happen." Might want to print an error message.
3761 abort() is not out of the question, but chances are GDB is just
3762 a bit confused, not unusable. */
3763 #define err BPSTAT_WHAT_STOP_NOISY
3765 /* Given an old action and a class, come up with a new action. */
3766 /* One interesting property of this table is that wp_silent is the same
3767 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3768 after stopping, the check for whether to step over a breakpoint
3769 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3770 reference to how we stopped. We retain separate wp_silent and
3771 bp_silent codes in case we want to change that someday.
3773 Another possibly interesting property of this table is that
3774 there's a partial ordering, priority-like, of the actions. Once
3775 you've decided that some action is appropriate, you'll never go
3776 back and decide something of a lower priority is better. The
3779 kc < jit clr sgl shl slr sn sr ss
3780 sgl < jit shl slr sn sr ss
3781 slr < jit err shl sn sr ss
3782 clr < jit err shl sn sr ss
3789 What I think this means is that we don't need a damned table
3790 here. If you just put the rows and columns in the right order,
3791 it'd look awfully regular. We could simply walk the bpstat list
3792 and choose the highest priority action we find, with a little
3793 logic to handle the 'err' cases. */
3795 /* step_resume entries: a step resume breakpoint overrides another
3796 breakpoint of signal handling (see comment in wait_for_inferior
3797 at where we set the step_resume breakpoint). */
3799 static const enum bpstat_what_main_action
3800 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3803 /* kc ss sn sgl slr clr sr shl jit */
3804 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
3805 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
3806 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
3807 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
3808 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
3809 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
3810 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
3811 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
3812 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3813 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
3814 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
3828 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3829 struct bpstat_what retval
;
3831 retval
.call_dummy
= 0;
3832 for (; bs
!= NULL
; bs
= bs
->next
)
3834 enum class bs_class
= no_effect
;
3835 if (bs
->breakpoint_at
== NULL
)
3836 /* I suspect this can happen if it was a momentary breakpoint
3837 which has since been deleted. */
3839 if (bs
->breakpoint_at
->owner
== NULL
)
3840 bs_class
= bp_nostop
;
3842 switch (bs
->breakpoint_at
->owner
->type
)
3848 case bp_hardware_breakpoint
:
3854 bs_class
= bp_noisy
;
3856 bs_class
= bp_silent
;
3859 bs_class
= bp_nostop
;
3862 case bp_hardware_watchpoint
:
3863 case bp_read_watchpoint
:
3864 case bp_access_watchpoint
:
3868 bs_class
= wp_noisy
;
3870 bs_class
= wp_silent
;
3873 /* There was a watchpoint, but we're not stopping.
3874 This requires no further action. */
3875 bs_class
= no_effect
;
3878 bs_class
= long_jump
;
3880 case bp_longjmp_resume
:
3881 bs_class
= long_resume
;
3883 case bp_step_resume
:
3886 bs_class
= step_resume
;
3889 /* It is for the wrong frame. */
3890 bs_class
= bp_nostop
;
3892 case bp_watchpoint_scope
:
3893 bs_class
= bp_nostop
;
3895 case bp_shlib_event
:
3896 bs_class
= shlib_event
;
3899 bs_class
= jit_event
;
3901 case bp_thread_event
:
3902 case bp_overlay_event
:
3903 case bp_longjmp_master
:
3904 bs_class
= bp_nostop
;
3910 bs_class
= bp_noisy
;
3912 bs_class
= bp_silent
;
3915 /* There was a catchpoint, but we're not stopping.
3916 This requires no further action. */
3917 bs_class
= no_effect
;
3920 /* Make sure the action is stop (silent or noisy),
3921 so infrun.c pops the dummy frame. */
3922 bs_class
= bp_silent
;
3923 retval
.call_dummy
= 1;
3926 case bp_fast_tracepoint
:
3927 /* Tracepoint hits should not be reported back to GDB, and
3928 if one got through somehow, it should have been filtered
3930 internal_error (__FILE__
, __LINE__
,
3931 _("bpstat_what: tracepoint encountered"));
3934 current_action
= table
[(int) bs_class
][(int) current_action
];
3936 retval
.main_action
= current_action
;
3940 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3941 without hardware support). This isn't related to a specific bpstat,
3942 just to things like whether watchpoints are set. */
3945 bpstat_should_step (void)
3947 struct breakpoint
*b
;
3949 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3955 bpstat_causes_stop (bpstat bs
)
3957 for (; bs
!= NULL
; bs
= bs
->next
)
3966 /* Print the LOC location out of the list of B->LOC locations. */
3968 static void print_breakpoint_location (struct breakpoint
*b
,
3969 struct bp_location
*loc
,
3971 struct ui_stream
*stb
)
3973 struct cleanup
*old_chain
= save_current_program_space ();
3975 if (loc
!= NULL
&& loc
->shlib_disabled
)
3979 set_current_program_space (loc
->pspace
);
3981 if (b
->source_file
&& loc
)
3984 = find_pc_sect_function (loc
->address
, loc
->section
);
3987 ui_out_text (uiout
, "in ");
3988 ui_out_field_string (uiout
, "func",
3989 SYMBOL_PRINT_NAME (sym
));
3990 ui_out_wrap_hint (uiout
, wrap_indent
);
3991 ui_out_text (uiout
, " at ");
3993 ui_out_field_string (uiout
, "file", b
->source_file
);
3994 ui_out_text (uiout
, ":");
3996 if (ui_out_is_mi_like_p (uiout
))
3998 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3999 char *fullname
= symtab_to_fullname (sal
.symtab
);
4002 ui_out_field_string (uiout
, "fullname", fullname
);
4005 ui_out_field_int (uiout
, "line", b
->line_number
);
4009 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4011 ui_out_field_stream (uiout
, "at", stb
);
4014 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4016 do_cleanups (old_chain
);
4019 /* Print B to gdb_stdout. */
4021 print_one_breakpoint_location (struct breakpoint
*b
,
4022 struct bp_location
*loc
,
4024 struct bp_location
**last_loc
,
4025 int print_address_bits
,
4028 struct command_line
*l
;
4030 struct ep_type_description
4035 static struct ep_type_description bptypes
[] =
4037 {bp_none
, "?deleted?"},
4038 {bp_breakpoint
, "breakpoint"},
4039 {bp_hardware_breakpoint
, "hw breakpoint"},
4040 {bp_until
, "until"},
4041 {bp_finish
, "finish"},
4042 {bp_watchpoint
, "watchpoint"},
4043 {bp_hardware_watchpoint
, "hw watchpoint"},
4044 {bp_read_watchpoint
, "read watchpoint"},
4045 {bp_access_watchpoint
, "acc watchpoint"},
4046 {bp_longjmp
, "longjmp"},
4047 {bp_longjmp_resume
, "longjmp resume"},
4048 {bp_step_resume
, "step resume"},
4049 {bp_watchpoint_scope
, "watchpoint scope"},
4050 {bp_call_dummy
, "call dummy"},
4051 {bp_shlib_event
, "shlib events"},
4052 {bp_thread_event
, "thread events"},
4053 {bp_overlay_event
, "overlay events"},
4054 {bp_longjmp_master
, "longjmp master"},
4055 {bp_catchpoint
, "catchpoint"},
4056 {bp_tracepoint
, "tracepoint"},
4057 {bp_fast_tracepoint
, "fast tracepoint"},
4058 {bp_jit_event
, "jit events"},
4061 static char bpenables
[] = "nynny";
4062 char wrap_indent
[80];
4063 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4064 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4065 struct cleanup
*bkpt_chain
;
4067 int header_of_multiple
= 0;
4068 int part_of_multiple
= (loc
!= NULL
);
4069 struct value_print_options opts
;
4071 get_user_print_options (&opts
);
4073 gdb_assert (!loc
|| loc_number
!= 0);
4074 /* See comment in print_one_breakpoint concerning
4075 treatment of breakpoints with single disabled
4079 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4080 header_of_multiple
= 1;
4085 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4089 if (part_of_multiple
)
4092 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4093 ui_out_field_string (uiout
, "number", formatted
);
4098 ui_out_field_int (uiout
, "number", b
->number
);
4103 if (part_of_multiple
)
4104 ui_out_field_skip (uiout
, "type");
4107 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4108 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4109 internal_error (__FILE__
, __LINE__
,
4110 _("bptypes table does not describe type #%d."),
4112 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4117 if (part_of_multiple
)
4118 ui_out_field_skip (uiout
, "disp");
4120 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4125 if (part_of_multiple
)
4126 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4128 ui_out_field_fmt (uiout
, "enabled", "%c",
4129 bpenables
[(int) b
->enable_state
]);
4130 ui_out_spaces (uiout
, 2);
4134 strcpy (wrap_indent
, " ");
4135 if (opts
.addressprint
)
4137 if (print_address_bits
<= 32)
4138 strcat (wrap_indent
, " ");
4140 strcat (wrap_indent
, " ");
4143 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4145 /* Although the print_one can possibly print
4146 all locations, calling it here is not likely
4147 to get any nice result. So, make sure there's
4148 just one location. */
4149 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4150 b
->ops
->print_one (b
, last_loc
);
4156 internal_error (__FILE__
, __LINE__
,
4157 _("print_one_breakpoint: bp_none encountered\n"));
4161 case bp_hardware_watchpoint
:
4162 case bp_read_watchpoint
:
4163 case bp_access_watchpoint
:
4164 /* Field 4, the address, is omitted (which makes the columns
4165 not line up too nicely with the headers, but the effect
4166 is relatively readable). */
4167 if (opts
.addressprint
)
4168 ui_out_field_skip (uiout
, "addr");
4170 ui_out_field_string (uiout
, "what", b
->exp_string
);
4174 case bp_hardware_breakpoint
:
4178 case bp_longjmp_resume
:
4179 case bp_step_resume
:
4180 case bp_watchpoint_scope
:
4182 case bp_shlib_event
:
4183 case bp_thread_event
:
4184 case bp_overlay_event
:
4185 case bp_longjmp_master
:
4187 case bp_fast_tracepoint
:
4189 if (opts
.addressprint
)
4192 if (header_of_multiple
)
4193 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4194 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4195 ui_out_field_string (uiout
, "addr", "<PENDING>");
4197 ui_out_field_core_addr (uiout
, "addr",
4198 loc
->gdbarch
, loc
->address
);
4201 if (!header_of_multiple
)
4202 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4209 /* For backward compatibility, don't display inferiors unless there
4212 && !header_of_multiple
4214 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4215 && (number_of_program_spaces () > 1
4216 || number_of_inferiors () > 1)
4217 && loc
->owner
->type
!= bp_catchpoint
)))
4219 struct inferior
*inf
;
4222 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4224 if (inf
->pspace
== loc
->pspace
)
4229 ui_out_text (uiout
, " inf ");
4232 ui_out_text (uiout
, ", ");
4233 ui_out_text (uiout
, plongest (inf
->num
));
4238 if (!part_of_multiple
)
4240 if (b
->thread
!= -1)
4242 /* FIXME: This seems to be redundant and lost here; see the
4243 "stop only in" line a little further down. */
4244 ui_out_text (uiout
, " thread ");
4245 ui_out_field_int (uiout
, "thread", b
->thread
);
4247 else if (b
->task
!= 0)
4249 ui_out_text (uiout
, " task ");
4250 ui_out_field_int (uiout
, "task", b
->task
);
4254 ui_out_text (uiout
, "\n");
4256 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4259 ui_out_text (uiout
, "\tstop only in stack frame at ");
4260 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4262 ui_out_field_core_addr (uiout
, "frame",
4263 b
->gdbarch
, b
->frame_id
.stack_addr
);
4264 ui_out_text (uiout
, "\n");
4267 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4269 /* We do not print the condition for Ada exception catchpoints
4270 because the condition is an internal implementation detail
4271 that we do not want to expose to the user. */
4273 if (tracepoint_type (b
))
4274 ui_out_text (uiout
, "\ttrace only if ");
4276 ui_out_text (uiout
, "\tstop only if ");
4277 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4278 ui_out_text (uiout
, "\n");
4281 if (!part_of_multiple
&& b
->thread
!= -1)
4283 /* FIXME should make an annotation for this */
4284 ui_out_text (uiout
, "\tstop only in thread ");
4285 ui_out_field_int (uiout
, "thread", b
->thread
);
4286 ui_out_text (uiout
, "\n");
4289 if (!part_of_multiple
&& b
->hit_count
)
4291 /* FIXME should make an annotation for this */
4292 if (ep_is_catchpoint (b
))
4293 ui_out_text (uiout
, "\tcatchpoint");
4295 ui_out_text (uiout
, "\tbreakpoint");
4296 ui_out_text (uiout
, " already hit ");
4297 ui_out_field_int (uiout
, "times", b
->hit_count
);
4298 if (b
->hit_count
== 1)
4299 ui_out_text (uiout
, " time\n");
4301 ui_out_text (uiout
, " times\n");
4304 /* Output the count also if it is zero, but only if this is
4305 mi. FIXME: Should have a better test for this. */
4306 if (ui_out_is_mi_like_p (uiout
))
4307 if (!part_of_multiple
&& b
->hit_count
== 0)
4308 ui_out_field_int (uiout
, "times", b
->hit_count
);
4310 if (!part_of_multiple
&& b
->ignore_count
)
4313 ui_out_text (uiout
, "\tignore next ");
4314 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4315 ui_out_text (uiout
, " hits\n");
4319 if (!part_of_multiple
&& l
)
4321 struct cleanup
*script_chain
;
4324 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4325 print_command_lines (uiout
, l
, 4);
4326 do_cleanups (script_chain
);
4329 if (!part_of_multiple
&& b
->pass_count
)
4331 annotate_field (10);
4332 ui_out_text (uiout
, "\tpass count ");
4333 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4334 ui_out_text (uiout
, " \n");
4337 if (!part_of_multiple
&& b
->step_count
)
4339 annotate_field (11);
4340 ui_out_text (uiout
, "\tstep count ");
4341 ui_out_field_int (uiout
, "step", b
->step_count
);
4342 ui_out_text (uiout
, " \n");
4345 if (!part_of_multiple
&& b
->actions
)
4347 struct action_line
*action
;
4348 annotate_field (12);
4349 for (action
= b
->actions
; action
; action
= action
->next
)
4351 ui_out_text (uiout
, " A\t");
4352 ui_out_text (uiout
, action
->action
);
4353 ui_out_text (uiout
, "\n");
4357 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4360 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4361 else if (b
->exp_string
)
4362 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4365 do_cleanups (bkpt_chain
);
4366 do_cleanups (old_chain
);
4370 print_one_breakpoint (struct breakpoint
*b
,
4371 struct bp_location
**last_loc
, int print_address_bits
,
4374 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4375 print_address_bits
, allflag
);
4377 /* If this breakpoint has custom print function,
4378 it's already printed. Otherwise, print individual
4379 locations, if any. */
4380 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4382 /* If breakpoint has a single location that is
4383 disabled, we print it as if it had
4384 several locations, since otherwise it's hard to
4385 represent "breakpoint enabled, location disabled"
4387 Note that while hardware watchpoints have
4388 several locations internally, that's no a property
4391 && !is_hardware_watchpoint (b
)
4392 && (b
->loc
->next
|| !b
->loc
->enabled
)
4393 && !ui_out_is_mi_like_p (uiout
))
4395 struct bp_location
*loc
;
4397 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4398 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4399 print_address_bits
, allflag
);
4405 breakpoint_address_bits (struct breakpoint
*b
)
4407 int print_address_bits
= 0;
4408 struct bp_location
*loc
;
4410 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4412 int addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4413 if (addr_bit
> print_address_bits
)
4414 print_address_bits
= addr_bit
;
4417 return print_address_bits
;
4420 struct captured_breakpoint_query_args
4426 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4428 struct captured_breakpoint_query_args
*args
= data
;
4429 struct breakpoint
*b
;
4430 struct bp_location
*dummy_loc
= NULL
;
4433 if (args
->bnum
== b
->number
)
4435 int print_address_bits
= breakpoint_address_bits (b
);
4436 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4444 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4446 struct captured_breakpoint_query_args args
;
4448 /* For the moment we don't trust print_one_breakpoint() to not throw
4450 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4451 error_message
, RETURN_MASK_ALL
) < 0)
4457 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4458 catchpoints, et.al.). */
4461 user_settable_breakpoint (const struct breakpoint
*b
)
4463 return (b
->type
== bp_breakpoint
4464 || b
->type
== bp_catchpoint
4465 || b
->type
== bp_hardware_breakpoint
4466 || tracepoint_type (b
)
4467 || b
->type
== bp_watchpoint
4468 || b
->type
== bp_read_watchpoint
4469 || b
->type
== bp_access_watchpoint
4470 || b
->type
== bp_hardware_watchpoint
);
4473 /* Print information on user settable breakpoint (watchpoint, etc)
4474 number BNUM. If BNUM is -1 print all user settable breakpoints.
4475 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4478 breakpoint_1 (int bnum
, int allflag
)
4480 struct breakpoint
*b
;
4481 struct bp_location
*last_loc
= NULL
;
4482 int nr_printable_breakpoints
;
4483 struct cleanup
*bkpttbl_chain
;
4484 struct value_print_options opts
;
4485 int print_address_bits
= 0;
4487 get_user_print_options (&opts
);
4489 /* Compute the number of rows in the table, as well as the
4490 size required for address fields. */
4491 nr_printable_breakpoints
= 0;
4494 || bnum
== b
->number
)
4496 if (allflag
|| user_settable_breakpoint (b
))
4498 int addr_bit
= breakpoint_address_bits (b
);
4499 if (addr_bit
> print_address_bits
)
4500 print_address_bits
= addr_bit
;
4502 nr_printable_breakpoints
++;
4506 if (opts
.addressprint
)
4508 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4512 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4515 if (nr_printable_breakpoints
> 0)
4516 annotate_breakpoints_headers ();
4517 if (nr_printable_breakpoints
> 0)
4519 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4520 if (nr_printable_breakpoints
> 0)
4522 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4523 if (nr_printable_breakpoints
> 0)
4525 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4526 if (nr_printable_breakpoints
> 0)
4528 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4529 if (opts
.addressprint
)
4531 if (nr_printable_breakpoints
> 0)
4533 if (print_address_bits
<= 32)
4534 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4536 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4538 if (nr_printable_breakpoints
> 0)
4540 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4541 ui_out_table_body (uiout
);
4542 if (nr_printable_breakpoints
> 0)
4543 annotate_breakpoints_table ();
4547 || bnum
== b
->number
)
4549 /* We only print out user settable breakpoints unless the
4551 if (allflag
|| user_settable_breakpoint (b
))
4552 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
4555 do_cleanups (bkpttbl_chain
);
4557 if (nr_printable_breakpoints
== 0)
4560 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4562 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4567 if (last_loc
&& !server_command
)
4568 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4571 /* FIXME? Should this be moved up so that it is only called when
4572 there have been breakpoints? */
4573 annotate_breakpoints_table_end ();
4577 breakpoints_info (char *bnum_exp
, int from_tty
)
4582 bnum
= parse_and_eval_long (bnum_exp
);
4584 breakpoint_1 (bnum
, 0);
4588 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4593 bnum
= parse_and_eval_long (bnum_exp
);
4595 breakpoint_1 (bnum
, 1);
4599 breakpoint_has_pc (struct breakpoint
*b
,
4600 struct program_space
*pspace
,
4601 CORE_ADDR pc
, struct obj_section
*section
)
4603 struct bp_location
*bl
= b
->loc
;
4604 for (; bl
; bl
= bl
->next
)
4606 if (bl
->pspace
== pspace
4607 && bl
->address
== pc
4608 && (!overlay_debugging
|| bl
->section
== section
))
4614 /* Print a message describing any breakpoints set at PC. This
4615 concerns with logical breakpoints, so we match program spaces, not
4619 describe_other_breakpoints (struct gdbarch
*gdbarch
,
4620 struct program_space
*pspace
, CORE_ADDR pc
,
4621 struct obj_section
*section
, int thread
)
4624 struct breakpoint
*b
;
4627 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
4631 printf_filtered (_("Note: breakpoint "));
4632 else /* if (others == ???) */
4633 printf_filtered (_("Note: breakpoints "));
4635 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
4638 printf_filtered ("%d", b
->number
);
4639 if (b
->thread
== -1 && thread
!= -1)
4640 printf_filtered (" (all threads)");
4641 else if (b
->thread
!= -1)
4642 printf_filtered (" (thread %d)", b
->thread
);
4643 printf_filtered ("%s%s ",
4644 ((b
->enable_state
== bp_disabled
4645 || b
->enable_state
== bp_call_disabled
4646 || b
->enable_state
== bp_startup_disabled
)
4648 : b
->enable_state
== bp_permanent
4652 : ((others
== 1) ? " and" : ""));
4654 printf_filtered (_("also set at pc "));
4655 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4656 printf_filtered (".\n");
4660 /* Set the default place to put a breakpoint
4661 for the `break' command with no arguments. */
4664 set_default_breakpoint (int valid
, struct program_space
*pspace
,
4665 CORE_ADDR addr
, struct symtab
*symtab
,
4668 default_breakpoint_valid
= valid
;
4669 default_breakpoint_pspace
= pspace
;
4670 default_breakpoint_address
= addr
;
4671 default_breakpoint_symtab
= symtab
;
4672 default_breakpoint_line
= line
;
4675 /* Return true iff it is meaningful to use the address member of
4676 BPT. For some breakpoint types, the address member is irrelevant
4677 and it makes no sense to attempt to compare it to other addresses
4678 (or use it for any other purpose either).
4680 More specifically, each of the following breakpoint types will always
4681 have a zero valued address and we don't want to mark breakpoints of any of
4682 these types to be a duplicate of an actual breakpoint at address zero:
4690 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4692 enum bptype type
= bpt
->type
;
4694 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
4697 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
4698 true if LOC1 and LOC2 represent the same watchpoint location. */
4701 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
4703 return (loc1
->owner
->type
== loc2
->owner
->type
4704 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
4705 && loc1
->address
== loc2
->address
4706 && loc1
->length
== loc2
->length
);
4709 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
4710 same breakpoint location. In most targets, this can only be true
4711 if ASPACE1 matches ASPACE2. On targets that have global
4712 breakpoints, the address space doesn't really matter. */
4715 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
4716 struct address_space
*aspace2
, CORE_ADDR addr2
)
4718 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
4719 || aspace1
== aspace2
)
4723 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
4724 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
4725 represent the same location. */
4728 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
4730 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
4731 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
4733 if (hw_point1
!= hw_point2
)
4736 return watchpoint_locations_match (loc1
, loc2
);
4738 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
4739 loc2
->pspace
->aspace
, loc2
->address
);
4743 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4744 int bnum
, int have_bnum
)
4749 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4750 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4752 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4753 bnum
, astr1
, astr2
);
4755 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4758 /* Adjust a breakpoint's address to account for architectural constraints
4759 on breakpoint placement. Return the adjusted address. Note: Very
4760 few targets require this kind of adjustment. For most targets,
4761 this function is simply the identity function. */
4764 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4765 CORE_ADDR bpaddr
, enum bptype bptype
)
4767 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4769 /* Very few targets need any kind of breakpoint adjustment. */
4772 else if (bptype
== bp_watchpoint
4773 || bptype
== bp_hardware_watchpoint
4774 || bptype
== bp_read_watchpoint
4775 || bptype
== bp_access_watchpoint
4776 || bptype
== bp_catchpoint
)
4778 /* Watchpoints and the various bp_catch_* eventpoints should not
4779 have their addresses modified. */
4784 CORE_ADDR adjusted_bpaddr
;
4786 /* Some targets have architectural constraints on the placement
4787 of breakpoint instructions. Obtain the adjusted address. */
4788 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
4790 /* An adjusted breakpoint address can significantly alter
4791 a user's expectations. Print a warning if an adjustment
4793 if (adjusted_bpaddr
!= bpaddr
)
4794 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4796 return adjusted_bpaddr
;
4800 /* Allocate a struct bp_location. */
4802 static struct bp_location
*
4803 allocate_bp_location (struct breakpoint
*bpt
)
4805 struct bp_location
*loc
, *loc_p
;
4807 loc
= xmalloc (sizeof (struct bp_location
));
4808 memset (loc
, 0, sizeof (*loc
));
4812 loc
->shlib_disabled
= 0;
4819 case bp_fast_tracepoint
:
4823 case bp_longjmp_resume
:
4824 case bp_step_resume
:
4825 case bp_watchpoint_scope
:
4827 case bp_shlib_event
:
4828 case bp_thread_event
:
4829 case bp_overlay_event
:
4831 case bp_longjmp_master
:
4832 loc
->loc_type
= bp_loc_software_breakpoint
;
4834 case bp_hardware_breakpoint
:
4835 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4837 case bp_hardware_watchpoint
:
4838 case bp_read_watchpoint
:
4839 case bp_access_watchpoint
:
4840 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4844 loc
->loc_type
= bp_loc_other
;
4847 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4853 static void free_bp_location (struct bp_location
*loc
)
4858 if (loc
->function_name
)
4859 xfree (loc
->function_name
);
4864 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4865 that has type BPTYPE and has no locations as yet. */
4866 /* This function is used in gdbtk sources and thus can not be made static. */
4868 static struct breakpoint
*
4869 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
4872 struct breakpoint
*b
, *b1
;
4874 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4875 memset (b
, 0, sizeof (*b
));
4878 b
->gdbarch
= gdbarch
;
4879 b
->language
= current_language
->la_language
;
4880 b
->input_radix
= input_radix
;
4882 b
->enable_state
= bp_enabled
;
4885 b
->ignore_count
= 0;
4887 b
->frame_id
= null_frame_id
;
4888 b
->forked_inferior_pid
= null_ptid
;
4889 b
->exec_pathname
= NULL
;
4890 b
->syscalls_to_be_caught
= NULL
;
4892 b
->condition_not_parsed
= 0;
4894 /* Add this breakpoint to the end of the chain
4895 so that a list of breakpoints will come out in order
4896 of increasing numbers. */
4898 b1
= breakpoint_chain
;
4900 breakpoint_chain
= b
;
4910 /* Initialize loc->function_name. */
4912 set_breakpoint_location_function (struct bp_location
*loc
)
4914 if (loc
->owner
->type
== bp_breakpoint
4915 || loc
->owner
->type
== bp_hardware_breakpoint
4916 || tracepoint_type (loc
->owner
))
4918 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4920 if (loc
->function_name
)
4921 loc
->function_name
= xstrdup (loc
->function_name
);
4925 /* Attempt to determine architecture of location identified by SAL. */
4926 static struct gdbarch
*
4927 get_sal_arch (struct symtab_and_line sal
)
4930 return get_objfile_arch (sal
.section
->objfile
);
4932 return get_objfile_arch (sal
.symtab
->objfile
);
4937 /* set_raw_breakpoint is a low level routine for allocating and
4938 partially initializing a breakpoint of type BPTYPE. The newly
4939 created breakpoint's address, section, source file name, and line
4940 number are provided by SAL. The newly created and partially
4941 initialized breakpoint is added to the breakpoint chain and
4942 is also returned as the value of this function.
4944 It is expected that the caller will complete the initialization of
4945 the newly created breakpoint struct as well as output any status
4946 information regarding the creation of a new breakpoint. In
4947 particular, set_raw_breakpoint does NOT set the breakpoint
4948 number! Care should be taken to not allow an error to occur
4949 prior to completing the initialization of the breakpoint. If this
4950 should happen, a bogus breakpoint will be left on the chain. */
4953 set_raw_breakpoint (struct gdbarch
*gdbarch
,
4954 struct symtab_and_line sal
, enum bptype bptype
)
4956 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
4957 CORE_ADDR adjusted_address
;
4958 struct gdbarch
*loc_gdbarch
;
4960 loc_gdbarch
= get_sal_arch (sal
);
4962 loc_gdbarch
= b
->gdbarch
;
4964 if (bptype
!= bp_catchpoint
)
4965 gdb_assert (sal
.pspace
!= NULL
);
4967 /* Adjust the breakpoint's address prior to allocating a location.
4968 Once we call allocate_bp_location(), that mostly uninitialized
4969 location will be placed on the location chain. Adjustment of the
4970 breakpoint may cause target_read_memory() to be called and we do
4971 not want its scan of the location chain to find a breakpoint and
4972 location that's only been partially initialized. */
4973 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
4975 b
->loc
= allocate_bp_location (b
);
4976 b
->loc
->gdbarch
= loc_gdbarch
;
4977 b
->loc
->requested_address
= sal
.pc
;
4978 b
->loc
->address
= adjusted_address
;
4979 b
->loc
->pspace
= sal
.pspace
;
4981 /* Store the program space that was used to set the breakpoint, for
4982 breakpoint resetting. */
4983 b
->pspace
= sal
.pspace
;
4985 if (sal
.symtab
== NULL
)
4986 b
->source_file
= NULL
;
4988 b
->source_file
= xstrdup (sal
.symtab
->filename
);
4989 b
->loc
->section
= sal
.section
;
4990 b
->line_number
= sal
.line
;
4992 set_breakpoint_location_function (b
->loc
);
4994 breakpoints_changed ();
5000 /* Note that the breakpoint object B describes a permanent breakpoint
5001 instruction, hard-wired into the inferior's code. */
5003 make_breakpoint_permanent (struct breakpoint
*b
)
5005 struct bp_location
*bl
;
5006 b
->enable_state
= bp_permanent
;
5008 /* By definition, permanent breakpoints are already present in the code.
5009 Mark all locations as inserted. For now, make_breakpoint_permanent
5010 is called in just one place, so it's hard to say if it's reasonable
5011 to have permanent breakpoint with multiple locations or not,
5012 but it's easy to implmement. */
5013 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5017 /* Call this routine when stepping and nexting to enable a breakpoint
5018 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5019 set_longjmp_resume_breakpoint() to figure out where we are going. */
5022 set_longjmp_breakpoint (int thread
)
5024 struct breakpoint
*b
, *temp
;
5026 /* To avoid having to rescan all objfile symbols at every step,
5027 we maintain a list of continually-inserted but always disabled
5028 longjmp "master" breakpoints. Here, we simply create momentary
5029 clones of those and enable them for the requested thread. */
5030 ALL_BREAKPOINTS_SAFE (b
, temp
)
5031 if (b
->pspace
== current_program_space
5032 && b
->type
== bp_longjmp_master
)
5034 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5035 clone
->type
= bp_longjmp
;
5036 clone
->thread
= thread
;
5040 /* Delete all longjmp breakpoints from THREAD. */
5042 delete_longjmp_breakpoint (int thread
)
5044 struct breakpoint
*b
, *temp
;
5046 ALL_BREAKPOINTS_SAFE (b
, temp
)
5047 if (b
->type
== bp_longjmp
)
5049 if (b
->thread
== thread
)
5050 delete_breakpoint (b
);
5055 enable_overlay_breakpoints (void)
5057 struct breakpoint
*b
;
5060 if (b
->type
== bp_overlay_event
)
5062 b
->enable_state
= bp_enabled
;
5063 update_global_location_list (1);
5064 overlay_events_enabled
= 1;
5069 disable_overlay_breakpoints (void)
5071 struct breakpoint
*b
;
5074 if (b
->type
== bp_overlay_event
)
5076 b
->enable_state
= bp_disabled
;
5077 update_global_location_list (0);
5078 overlay_events_enabled
= 0;
5083 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5085 struct breakpoint
*b
;
5087 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5089 b
->enable_state
= bp_enabled
;
5090 /* addr_string has to be used or breakpoint_re_set will delete me. */
5092 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5094 update_global_location_list_nothrow (1);
5100 remove_thread_event_breakpoints (void)
5102 struct breakpoint
*b
, *temp
;
5104 ALL_BREAKPOINTS_SAFE (b
, temp
)
5105 if (b
->type
== bp_thread_event
5106 && b
->loc
->pspace
== current_program_space
)
5107 delete_breakpoint (b
);
5110 struct captured_parse_breakpoint_args
5113 struct symtabs_and_lines
*sals_p
;
5114 char ***addr_string_p
;
5118 struct lang_and_radix
5124 /* Create a breakpoint for JIT code registration and unregistration. */
5127 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5129 struct breakpoint
*b
;
5131 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5132 update_global_location_list_nothrow (1);
5137 remove_solib_event_breakpoints (void)
5139 struct breakpoint
*b
, *temp
;
5141 ALL_BREAKPOINTS_SAFE (b
, temp
)
5142 if (b
->type
== bp_shlib_event
5143 && b
->loc
->pspace
== current_program_space
)
5144 delete_breakpoint (b
);
5148 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5150 struct breakpoint
*b
;
5152 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5153 update_global_location_list_nothrow (1);
5157 /* Disable any breakpoints that are on code in shared libraries. Only
5158 apply to enabled breakpoints, disabled ones can just stay disabled. */
5161 disable_breakpoints_in_shlibs (void)
5163 struct bp_location
*loc
, **locp_tmp
;
5165 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5167 struct breakpoint
*b
= loc
->owner
;
5168 /* We apply the check to all breakpoints, including disabled
5169 for those with loc->duplicate set. This is so that when breakpoint
5170 becomes enabled, or the duplicate is removed, gdb will try to insert
5171 all breakpoints. If we don't set shlib_disabled here, we'll try
5172 to insert those breakpoints and fail. */
5173 if (((b
->type
== bp_breakpoint
)
5174 || (b
->type
== bp_hardware_breakpoint
)
5175 || (tracepoint_type (b
)))
5176 && loc
->pspace
== current_program_space
5177 && !loc
->shlib_disabled
5179 && PC_SOLIB (loc
->address
)
5181 && solib_name_from_address (loc
->pspace
, loc
->address
)
5185 loc
->shlib_disabled
= 1;
5190 /* Disable any breakpoints that are in in an unloaded shared library. Only
5191 apply to enabled breakpoints, disabled ones can just stay disabled. */
5194 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5196 struct bp_location
*loc
, **locp_tmp
;
5197 int disabled_shlib_breaks
= 0;
5199 /* SunOS a.out shared libraries are always mapped, so do not
5200 disable breakpoints; they will only be reported as unloaded
5201 through clear_solib when GDB discards its shared library
5202 list. See clear_solib for more information. */
5203 if (exec_bfd
!= NULL
5204 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5207 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5209 struct breakpoint
*b
= loc
->owner
;
5210 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5211 || loc
->loc_type
== bp_loc_software_breakpoint
)
5212 && solib
->pspace
== loc
->pspace
5213 && !loc
->shlib_disabled
5214 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
5215 && solib_contains_address_p (solib
, loc
->address
))
5217 loc
->shlib_disabled
= 1;
5218 /* At this point, we cannot rely on remove_breakpoint
5219 succeeding so we must mark the breakpoint as not inserted
5220 to prevent future errors occurring in remove_breakpoints. */
5222 if (!disabled_shlib_breaks
)
5224 target_terminal_ours_for_output ();
5225 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5228 disabled_shlib_breaks
= 1;
5233 /* FORK & VFORK catchpoints. */
5235 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5238 insert_catch_fork (struct breakpoint
*b
)
5240 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5243 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5246 remove_catch_fork (struct breakpoint
*b
)
5248 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5251 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5255 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5257 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5260 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5262 static enum print_stop_action
5263 print_it_catch_fork (struct breakpoint
*b
)
5265 annotate_catchpoint (b
->number
);
5266 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5267 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5268 return PRINT_SRC_AND_LOC
;
5271 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5274 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5276 struct value_print_options opts
;
5278 get_user_print_options (&opts
);
5280 /* Field 4, the address, is omitted (which makes the columns
5281 not line up too nicely with the headers, but the effect
5282 is relatively readable). */
5283 if (opts
.addressprint
)
5284 ui_out_field_skip (uiout
, "addr");
5286 ui_out_text (uiout
, "fork");
5287 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5289 ui_out_text (uiout
, ", process ");
5290 ui_out_field_int (uiout
, "what",
5291 ptid_get_pid (b
->forked_inferior_pid
));
5292 ui_out_spaces (uiout
, 1);
5296 /* Implement the "print_mention" breakpoint_ops method for fork
5300 print_mention_catch_fork (struct breakpoint
*b
)
5302 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5305 /* The breakpoint_ops structure to be used in fork catchpoints. */
5307 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5311 breakpoint_hit_catch_fork
,
5312 print_it_catch_fork
,
5313 print_one_catch_fork
,
5314 print_mention_catch_fork
5317 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5320 insert_catch_vfork (struct breakpoint
*b
)
5322 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5325 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5328 remove_catch_vfork (struct breakpoint
*b
)
5330 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5333 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5337 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5339 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5342 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5344 static enum print_stop_action
5345 print_it_catch_vfork (struct breakpoint
*b
)
5347 annotate_catchpoint (b
->number
);
5348 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5349 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5350 return PRINT_SRC_AND_LOC
;
5353 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5356 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5358 struct value_print_options opts
;
5360 get_user_print_options (&opts
);
5361 /* Field 4, the address, is omitted (which makes the columns
5362 not line up too nicely with the headers, but the effect
5363 is relatively readable). */
5364 if (opts
.addressprint
)
5365 ui_out_field_skip (uiout
, "addr");
5367 ui_out_text (uiout
, "vfork");
5368 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5370 ui_out_text (uiout
, ", process ");
5371 ui_out_field_int (uiout
, "what",
5372 ptid_get_pid (b
->forked_inferior_pid
));
5373 ui_out_spaces (uiout
, 1);
5377 /* Implement the "print_mention" breakpoint_ops method for vfork
5381 print_mention_catch_vfork (struct breakpoint
*b
)
5383 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5386 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5388 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5392 breakpoint_hit_catch_vfork
,
5393 print_it_catch_vfork
,
5394 print_one_catch_vfork
,
5395 print_mention_catch_vfork
5398 /* Implement the "insert" breakpoint_ops method for syscall
5402 insert_catch_syscall (struct breakpoint
*b
)
5404 struct inferior
*inf
= current_inferior ();
5406 ++inf
->total_syscalls_count
;
5407 if (!b
->syscalls_to_be_caught
)
5408 ++inf
->any_syscall_count
;
5413 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5417 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5419 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5420 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5422 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5423 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5425 memset ((void *) vec_addr
, 0,
5426 (iter
+ 1 - old_size
) * sizeof (int));
5428 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5429 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5433 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5434 inf
->total_syscalls_count
!= 0,
5435 inf
->any_syscall_count
,
5436 VEC_length (int, inf
->syscalls_counts
),
5437 VEC_address (int, inf
->syscalls_counts
));
5440 /* Implement the "remove" breakpoint_ops method for syscall
5444 remove_catch_syscall (struct breakpoint
*b
)
5446 struct inferior
*inf
= current_inferior ();
5448 --inf
->total_syscalls_count
;
5449 if (!b
->syscalls_to_be_caught
)
5450 --inf
->any_syscall_count
;
5455 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5459 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5460 /* Shouldn't happen. */
5462 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5463 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5467 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5468 inf
->total_syscalls_count
!= 0,
5469 inf
->any_syscall_count
,
5470 VEC_length (int, inf
->syscalls_counts
),
5471 VEC_address (int, inf
->syscalls_counts
));
5474 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5478 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5480 /* We must check if we are catching specific syscalls in this breakpoint.
5481 If we are, then we must guarantee that the called syscall is the same
5482 syscall we are catching. */
5483 int syscall_number
= 0;
5485 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5488 /* Now, checking if the syscall is the same. */
5489 if (b
->syscalls_to_be_caught
)
5493 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5495 if (syscall_number
== iter
)
5505 /* Implement the "print_it" breakpoint_ops method for syscall
5508 static enum print_stop_action
5509 print_it_catch_syscall (struct breakpoint
*b
)
5511 /* These are needed because we want to know in which state a
5512 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
5513 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
5514 must print "called syscall" or "returned from syscall". */
5516 struct target_waitstatus last
;
5518 struct cleanup
*old_chain
;
5521 get_last_target_status (&ptid
, &last
);
5523 get_syscall_by_number (last
.value
.syscall_number
, &s
);
5525 annotate_catchpoint (b
->number
);
5528 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
5530 syscall_id
= xstrprintf ("'%s'", s
.name
);
5532 old_chain
= make_cleanup (xfree
, syscall_id
);
5534 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
5535 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
5536 b
->number
, syscall_id
);
5537 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
5538 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
5539 b
->number
, syscall_id
);
5541 do_cleanups (old_chain
);
5543 return PRINT_SRC_AND_LOC
;
5546 /* Implement the "print_one" breakpoint_ops method for syscall
5550 print_one_catch_syscall (struct breakpoint
*b
,
5551 struct bp_location
**last_loc
)
5553 struct value_print_options opts
;
5555 get_user_print_options (&opts
);
5556 /* Field 4, the address, is omitted (which makes the columns
5557 not line up too nicely with the headers, but the effect
5558 is relatively readable). */
5559 if (opts
.addressprint
)
5560 ui_out_field_skip (uiout
, "addr");
5563 if (b
->syscalls_to_be_caught
5564 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5565 ui_out_text (uiout
, "syscalls \"");
5567 ui_out_text (uiout
, "syscall \"");
5569 if (b
->syscalls_to_be_caught
)
5572 char *text
= xstrprintf ("%s", "");
5574 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5579 get_syscall_by_number (iter
, &s
);
5582 text
= xstrprintf ("%s%s, ", text
, s
.name
);
5584 text
= xstrprintf ("%s%d, ", text
, iter
);
5586 /* We have to xfree the last 'text' (now stored at 'x')
5587 because xstrprintf dinamically allocates new space for it
5591 /* Remove the last comma. */
5592 text
[strlen (text
) - 2] = '\0';
5593 ui_out_field_string (uiout
, "what", text
);
5596 ui_out_field_string (uiout
, "what", "<any syscall>");
5597 ui_out_text (uiout
, "\" ");
5600 /* Implement the "print_mention" breakpoint_ops method for syscall
5604 print_mention_catch_syscall (struct breakpoint
*b
)
5606 if (b
->syscalls_to_be_caught
)
5610 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5611 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
5613 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
5616 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5620 get_syscall_by_number (iter
, &s
);
5623 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
5625 printf_filtered (" %d", s
.number
);
5627 printf_filtered (")");
5630 printf_filtered (_("Catchpoint %d (any syscall)"),
5634 /* The breakpoint_ops structure to be used in syscall catchpoints. */
5636 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
5638 insert_catch_syscall
,
5639 remove_catch_syscall
,
5640 breakpoint_hit_catch_syscall
,
5641 print_it_catch_syscall
,
5642 print_one_catch_syscall
,
5643 print_mention_catch_syscall
5646 /* Returns non-zero if 'b' is a syscall catchpoint. */
5649 syscall_catchpoint_p (struct breakpoint
*b
)
5651 return (b
->ops
== &catch_syscall_breakpoint_ops
);
5654 /* Create a new breakpoint of the bp_catchpoint kind and return it,
5655 but does NOT mention it nor update the global location list.
5656 This is useful if you need to fill more fields in the
5657 struct breakpoint before calling mention.
5659 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5660 If COND_STRING is not NULL, then store it in the breakpoint.
5661 OPS, if not NULL, is the breakpoint_ops structure associated
5662 to the catchpoint. */
5664 static struct breakpoint
*
5665 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
5667 struct breakpoint_ops
*ops
)
5669 struct symtab_and_line sal
;
5670 struct breakpoint
*b
;
5673 sal
.pspace
= current_program_space
;
5675 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
5676 set_breakpoint_count (breakpoint_count
+ 1);
5677 b
->number
= breakpoint_count
;
5679 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
5681 b
->addr_string
= NULL
;
5682 b
->enable_state
= bp_enabled
;
5683 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5689 /* Create a new breakpoint of the bp_catchpoint kind and return it.
5691 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5692 If COND_STRING is not NULL, then store it in the breakpoint.
5693 OPS, if not NULL, is the breakpoint_ops structure associated
5694 to the catchpoint. */
5696 static struct breakpoint
*
5697 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
5698 char *cond_string
, struct breakpoint_ops
*ops
)
5700 struct breakpoint
*b
=
5701 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
5704 update_global_location_list (1);
5710 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
5711 int tempflag
, char *cond_string
,
5712 struct breakpoint_ops
*ops
)
5714 struct breakpoint
*b
5715 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
5717 /* FIXME: We should put this information in a breakpoint private data
5719 b
->forked_inferior_pid
= null_ptid
;
5722 /* Exec catchpoints. */
5725 insert_catch_exec (struct breakpoint
*b
)
5727 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
5731 remove_catch_exec (struct breakpoint
*b
)
5733 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
5737 breakpoint_hit_catch_exec (struct breakpoint
*b
)
5739 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
5742 static enum print_stop_action
5743 print_it_catch_exec (struct breakpoint
*b
)
5745 annotate_catchpoint (b
->number
);
5746 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
5748 return PRINT_SRC_AND_LOC
;
5752 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
5754 struct value_print_options opts
;
5756 get_user_print_options (&opts
);
5758 /* Field 4, the address, is omitted (which makes the columns
5759 not line up too nicely with the headers, but the effect
5760 is relatively readable). */
5761 if (opts
.addressprint
)
5762 ui_out_field_skip (uiout
, "addr");
5764 ui_out_text (uiout
, "exec");
5765 if (b
->exec_pathname
!= NULL
)
5767 ui_out_text (uiout
, ", program \"");
5768 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
5769 ui_out_text (uiout
, "\" ");
5774 print_mention_catch_exec (struct breakpoint
*b
)
5776 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
5779 static struct breakpoint_ops catch_exec_breakpoint_ops
=
5783 breakpoint_hit_catch_exec
,
5784 print_it_catch_exec
,
5785 print_one_catch_exec
,
5786 print_mention_catch_exec
5790 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
5791 struct breakpoint_ops
*ops
)
5793 struct gdbarch
*gdbarch
= get_current_arch ();
5794 struct breakpoint
*b
=
5795 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
5797 b
->syscalls_to_be_caught
= filter
;
5799 /* Now, we have to mention the breakpoint and update the global
5802 update_global_location_list (1);
5806 hw_breakpoint_used_count (void)
5808 struct breakpoint
*b
;
5813 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
5821 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
5823 struct breakpoint
*b
;
5826 *other_type_used
= 0;
5829 if (breakpoint_enabled (b
))
5831 if (b
->type
== type
)
5833 else if ((b
->type
== bp_hardware_watchpoint
5834 || b
->type
== bp_read_watchpoint
5835 || b
->type
== bp_access_watchpoint
))
5836 *other_type_used
= 1;
5843 disable_watchpoints_before_interactive_call_start (void)
5845 struct breakpoint
*b
;
5849 if (((b
->type
== bp_watchpoint
)
5850 || (b
->type
== bp_hardware_watchpoint
)
5851 || (b
->type
== bp_read_watchpoint
)
5852 || (b
->type
== bp_access_watchpoint
))
5853 && breakpoint_enabled (b
))
5855 b
->enable_state
= bp_call_disabled
;
5856 update_global_location_list (0);
5862 enable_watchpoints_after_interactive_call_stop (void)
5864 struct breakpoint
*b
;
5868 if (((b
->type
== bp_watchpoint
)
5869 || (b
->type
== bp_hardware_watchpoint
)
5870 || (b
->type
== bp_read_watchpoint
)
5871 || (b
->type
== bp_access_watchpoint
))
5872 && (b
->enable_state
== bp_call_disabled
))
5874 b
->enable_state
= bp_enabled
;
5875 update_global_location_list (1);
5881 disable_breakpoints_before_startup (void)
5883 struct breakpoint
*b
;
5888 if (b
->pspace
!= current_program_space
)
5891 if ((b
->type
== bp_breakpoint
5892 || b
->type
== bp_hardware_breakpoint
)
5893 && breakpoint_enabled (b
))
5895 b
->enable_state
= bp_startup_disabled
;
5901 update_global_location_list (0);
5903 current_program_space
->executing_startup
= 1;
5907 enable_breakpoints_after_startup (void)
5909 struct breakpoint
*b
;
5912 current_program_space
->executing_startup
= 0;
5916 if (b
->pspace
!= current_program_space
)
5919 if ((b
->type
== bp_breakpoint
5920 || b
->type
== bp_hardware_breakpoint
)
5921 && b
->enable_state
== bp_startup_disabled
)
5923 b
->enable_state
= bp_enabled
;
5929 breakpoint_re_set ();
5933 /* Set a breakpoint that will evaporate an end of command
5934 at address specified by SAL.
5935 Restrict it to frame FRAME if FRAME is nonzero. */
5938 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
5939 struct frame_id frame_id
, enum bptype type
)
5941 struct breakpoint
*b
;
5943 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5945 gdb_assert (!frame_id_inlined_p (frame_id
));
5947 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5948 b
->enable_state
= bp_enabled
;
5949 b
->disposition
= disp_donttouch
;
5950 b
->frame_id
= frame_id
;
5952 /* If we're debugging a multi-threaded program, then we
5953 want momentary breakpoints to be active in only a
5954 single thread of control. */
5955 if (in_thread_list (inferior_ptid
))
5956 b
->thread
= pid_to_thread_id (inferior_ptid
);
5958 update_global_location_list_nothrow (1);
5963 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5967 clone_momentary_breakpoint (struct breakpoint
*orig
)
5969 struct breakpoint
*copy
;
5971 /* If there's nothing to clone, then return nothing. */
5975 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
5976 copy
->loc
= allocate_bp_location (copy
);
5977 set_breakpoint_location_function (copy
->loc
);
5979 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
5980 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
5981 copy
->loc
->address
= orig
->loc
->address
;
5982 copy
->loc
->section
= orig
->loc
->section
;
5983 copy
->loc
->pspace
= orig
->loc
->pspace
;
5985 if (orig
->source_file
== NULL
)
5986 copy
->source_file
= NULL
;
5988 copy
->source_file
= xstrdup (orig
->source_file
);
5990 copy
->line_number
= orig
->line_number
;
5991 copy
->frame_id
= orig
->frame_id
;
5992 copy
->thread
= orig
->thread
;
5993 copy
->pspace
= orig
->pspace
;
5995 copy
->enable_state
= bp_enabled
;
5996 copy
->disposition
= disp_donttouch
;
5997 copy
->number
= internal_breakpoint_number
--;
5999 update_global_location_list_nothrow (0);
6004 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6007 struct symtab_and_line sal
;
6009 sal
= find_pc_line (pc
, 0);
6011 sal
.section
= find_pc_overlay (pc
);
6012 sal
.explicit_pc
= 1;
6014 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6018 /* Tell the user we have just set a breakpoint B. */
6021 mention (struct breakpoint
*b
)
6024 struct cleanup
*ui_out_chain
;
6025 struct value_print_options opts
;
6027 get_user_print_options (&opts
);
6029 /* FIXME: This is misplaced; mention() is called by things (like
6030 hitting a watchpoint) other than breakpoint creation. It should
6031 be possible to clean this up and at the same time replace the
6032 random calls to breakpoint_changed with this hook. */
6033 observer_notify_breakpoint_created (b
->number
);
6035 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6036 b
->ops
->print_mention (b
);
6041 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6044 ui_out_text (uiout
, "Watchpoint ");
6045 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6046 ui_out_field_int (uiout
, "number", b
->number
);
6047 ui_out_text (uiout
, ": ");
6048 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6049 do_cleanups (ui_out_chain
);
6051 case bp_hardware_watchpoint
:
6052 ui_out_text (uiout
, "Hardware watchpoint ");
6053 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6054 ui_out_field_int (uiout
, "number", b
->number
);
6055 ui_out_text (uiout
, ": ");
6056 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6057 do_cleanups (ui_out_chain
);
6059 case bp_read_watchpoint
:
6060 ui_out_text (uiout
, "Hardware read watchpoint ");
6061 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6062 ui_out_field_int (uiout
, "number", b
->number
);
6063 ui_out_text (uiout
, ": ");
6064 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6065 do_cleanups (ui_out_chain
);
6067 case bp_access_watchpoint
:
6068 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6069 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6070 ui_out_field_int (uiout
, "number", b
->number
);
6071 ui_out_text (uiout
, ": ");
6072 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6073 do_cleanups (ui_out_chain
);
6076 if (ui_out_is_mi_like_p (uiout
))
6081 if (b
->disposition
== disp_del
)
6082 printf_filtered (_("Temporary breakpoint"));
6084 printf_filtered (_("Breakpoint"));
6085 printf_filtered (_(" %d"), b
->number
);
6088 case bp_hardware_breakpoint
:
6089 if (ui_out_is_mi_like_p (uiout
))
6094 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6098 if (ui_out_is_mi_like_p (uiout
))
6103 printf_filtered (_("Tracepoint"));
6104 printf_filtered (_(" %d"), b
->number
);
6107 case bp_fast_tracepoint
:
6108 if (ui_out_is_mi_like_p (uiout
))
6113 printf_filtered (_("Fast tracepoint"));
6114 printf_filtered (_(" %d"), b
->number
);
6121 case bp_longjmp_resume
:
6122 case bp_step_resume
:
6124 case bp_watchpoint_scope
:
6125 case bp_shlib_event
:
6126 case bp_thread_event
:
6127 case bp_overlay_event
:
6129 case bp_longjmp_master
:
6135 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6139 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6143 if (opts
.addressprint
|| b
->source_file
== NULL
)
6145 printf_filtered (" at ");
6146 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6150 printf_filtered (": file %s, line %d.",
6151 b
->source_file
, b
->line_number
);
6155 struct bp_location
*loc
= b
->loc
;
6157 for (; loc
; loc
= loc
->next
)
6159 printf_filtered (" (%d locations)", n
);
6164 if (ui_out_is_mi_like_p (uiout
))
6166 printf_filtered ("\n");
6170 static struct bp_location
*
6171 add_location_to_breakpoint (struct breakpoint
*b
,
6172 const struct symtab_and_line
*sal
)
6174 struct bp_location
*loc
, **tmp
;
6176 loc
= allocate_bp_location (b
);
6177 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6180 loc
->gdbarch
= get_sal_arch (*sal
);
6182 loc
->gdbarch
= b
->gdbarch
;
6183 loc
->requested_address
= sal
->pc
;
6184 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6185 loc
->requested_address
, b
->type
);
6186 loc
->pspace
= sal
->pspace
;
6187 gdb_assert (loc
->pspace
!= NULL
);
6188 loc
->section
= sal
->section
;
6190 set_breakpoint_location_function (loc
);
6195 /* Return 1 if LOC is pointing to a permanent breakpoint,
6196 return 0 otherwise. */
6199 bp_loc_is_permanent (struct bp_location
*loc
)
6203 const gdb_byte
*brk
;
6204 gdb_byte
*target_mem
;
6205 struct cleanup
*cleanup
;
6208 gdb_assert (loc
!= NULL
);
6210 addr
= loc
->address
;
6211 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6213 /* Software breakpoints unsupported? */
6217 target_mem
= alloca (len
);
6219 /* Enable the automatic memory restoration from breakpoints while
6220 we read the memory. Otherwise we could say about our temporary
6221 breakpoints they are permanent. */
6222 cleanup
= save_current_space_and_thread ();
6224 switch_to_program_space_and_thread (loc
->pspace
);
6225 make_show_memory_breakpoints_cleanup (0);
6227 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6228 && memcmp (target_mem
, brk
, len
) == 0)
6231 do_cleanups (cleanup
);
6238 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6239 as textual description of the location, and COND_STRING
6240 as condition expression. */
6243 create_breakpoint (struct gdbarch
*gdbarch
,
6244 struct symtabs_and_lines sals
, char *addr_string
,
6246 enum bptype type
, enum bpdisp disposition
,
6247 int thread
, int task
, int ignore_count
,
6248 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6250 struct breakpoint
*b
= NULL
;
6253 if (type
== bp_hardware_breakpoint
)
6255 int i
= hw_breakpoint_used_count ();
6256 int target_resources_ok
=
6257 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6259 if (target_resources_ok
== 0)
6260 error (_("No hardware breakpoint support in the target."));
6261 else if (target_resources_ok
< 0)
6262 error (_("Hardware breakpoints used exceeds limit."));
6265 gdb_assert (sals
.nelts
> 0);
6267 for (i
= 0; i
< sals
.nelts
; ++i
)
6269 struct symtab_and_line sal
= sals
.sals
[i
];
6270 struct bp_location
*loc
;
6274 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6276 loc_gdbarch
= gdbarch
;
6278 describe_other_breakpoints (loc_gdbarch
,
6279 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6284 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6285 set_breakpoint_count (breakpoint_count
+ 1);
6286 b
->number
= breakpoint_count
;
6290 b
->cond_string
= cond_string
;
6291 b
->ignore_count
= ignore_count
;
6292 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6293 b
->disposition
= disposition
;
6295 b
->pspace
= sals
.sals
[0].pspace
;
6297 if (enabled
&& b
->pspace
->executing_startup
6298 && (b
->type
== bp_breakpoint
6299 || b
->type
== bp_hardware_breakpoint
))
6300 b
->enable_state
= bp_startup_disabled
;
6306 loc
= add_location_to_breakpoint (b
, &sal
);
6309 if (bp_loc_is_permanent (loc
))
6310 make_breakpoint_permanent (b
);
6314 char *arg
= b
->cond_string
;
6315 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6317 error (_("Garbage %s follows condition"), arg
);
6322 b
->addr_string
= addr_string
;
6324 /* addr_string has to be used or breakpoint_re_set will delete
6327 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6333 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6334 elements to fill the void space. */
6336 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6338 int i
= index_to_remove
+1;
6339 int last_index
= sal
->nelts
-1;
6341 for (;i
<= last_index
; ++i
)
6342 sal
->sals
[i
-1] = sal
->sals
[i
];
6347 /* If appropriate, obtains all sals that correspond to the same file
6348 and line as SAL, in all program spaces. Users debugging with IDEs,
6349 will want to set a breakpoint at foo.c:line, and not really care
6350 about program spaces. This is done only if SAL does not have
6351 explicit PC and has line and file information. If we got just a
6352 single expanded sal, return the original.
6354 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6355 which the name of enclosing function is different from SAL. This
6356 makes sure that if we have breakpoint originally set in template
6357 instantiation, say foo<int>(), we won't expand SAL to locations at
6358 the same line in all existing instantiations of 'foo'. */
6360 static struct symtabs_and_lines
6361 expand_line_sal_maybe (struct symtab_and_line sal
)
6363 struct symtabs_and_lines expanded
;
6364 CORE_ADDR original_pc
= sal
.pc
;
6365 char *original_function
= NULL
;
6368 struct cleanup
*old_chain
;
6370 /* If we have explicit pc, don't expand.
6371 If we have no line number, we can't expand. */
6372 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6375 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6376 expanded
.sals
[0] = sal
;
6382 old_chain
= save_current_space_and_thread ();
6384 switch_to_program_space_and_thread (sal
.pspace
);
6386 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6388 /* Note that expand_line_sal visits *all* program spaces. */
6389 expanded
= expand_line_sal (sal
);
6391 if (expanded
.nelts
== 1)
6393 /* We had one sal, we got one sal. Return that sal, adjusting it
6394 past the function prologue if necessary. */
6395 xfree (expanded
.sals
);
6397 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6398 sal
.pc
= original_pc
;
6399 expanded
.sals
[0] = sal
;
6400 skip_prologue_sal (&expanded
.sals
[0]);
6401 do_cleanups (old_chain
);
6405 if (!sal
.explicit_line
)
6407 CORE_ADDR func_addr
, func_end
;
6408 for (i
= 0; i
< expanded
.nelts
; ++i
)
6410 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6411 char *this_function
;
6413 /* We need to switch threads as well since we're about to
6415 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6417 if (find_pc_partial_function (pc
, &this_function
,
6418 &func_addr
, &func_end
))
6421 && strcmp (this_function
, original_function
) != 0)
6423 remove_sal (&expanded
, i
);
6426 else if (func_addr
== pc
)
6428 /* We're at beginning of a function, and should
6430 struct symbol
*sym
= find_pc_function (pc
);
6432 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
6435 /* Since find_pc_partial_function returned true,
6436 we should really always find the section here. */
6437 struct obj_section
*section
= find_pc_section (pc
);
6440 struct gdbarch
*gdbarch
6441 = get_objfile_arch (section
->objfile
);
6443 = gdbarch_skip_prologue (gdbarch
, pc
);
6452 for (i
= 0; i
< expanded
.nelts
; ++i
)
6454 /* If this SAL corresponds to a breakpoint inserted using a
6455 line number, then skip the function prologue if necessary. */
6456 skip_prologue_sal (&expanded
.sals
[i
]);
6460 do_cleanups (old_chain
);
6462 if (expanded
.nelts
<= 1)
6464 /* This is un ugly workaround. If we get zero
6465 expanded sals then something is really wrong.
6466 Fix that by returnign the original sal. */
6467 xfree (expanded
.sals
);
6469 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6470 sal
.pc
= original_pc
;
6471 expanded
.sals
[0] = sal
;
6478 for (i
= 0; i
< expanded
.nelts
; ++i
)
6479 if (expanded
.sals
[i
].pc
== original_pc
)
6490 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6491 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6492 value. COND_STRING, if not NULL, specified the condition to be
6493 used for all breakpoints. Essentially the only case where
6494 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6495 function. In that case, it's still not possible to specify
6496 separate conditions for different overloaded functions, so
6497 we take just a single condition string.
6499 NOTE: If the function succeeds, the caller is expected to cleanup
6500 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6501 array contents). If the function fails (error() is called), the
6502 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6503 COND and SALS arrays and each of those arrays contents. */
6506 create_breakpoints (struct gdbarch
*gdbarch
,
6507 struct symtabs_and_lines sals
, char **addr_string
,
6509 enum bptype type
, enum bpdisp disposition
,
6510 int thread
, int task
, int ignore_count
,
6511 struct breakpoint_ops
*ops
, int from_tty
,
6515 for (i
= 0; i
< sals
.nelts
; ++i
)
6517 struct symtabs_and_lines expanded
=
6518 expand_line_sal_maybe (sals
.sals
[i
]);
6520 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
6521 cond_string
, type
, disposition
,
6522 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6526 /* Parse ARG which is assumed to be a SAL specification possibly
6527 followed by conditionals. On return, SALS contains an array of SAL
6528 addresses found. ADDR_STRING contains a vector of (canonical)
6529 address strings. ARG points to the end of the SAL. */
6532 parse_breakpoint_sals (char **address
,
6533 struct symtabs_and_lines
*sals
,
6534 char ***addr_string
,
6537 char *addr_start
= *address
;
6538 *addr_string
= NULL
;
6539 /* If no arg given, or if first arg is 'if ', use the default
6541 if ((*address
) == NULL
6542 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
6544 if (default_breakpoint_valid
)
6546 struct symtab_and_line sal
;
6547 init_sal (&sal
); /* initialize to zeroes */
6548 sals
->sals
= (struct symtab_and_line
*)
6549 xmalloc (sizeof (struct symtab_and_line
));
6550 sal
.pc
= default_breakpoint_address
;
6551 sal
.line
= default_breakpoint_line
;
6552 sal
.symtab
= default_breakpoint_symtab
;
6553 sal
.pspace
= default_breakpoint_pspace
;
6554 sal
.section
= find_pc_overlay (sal
.pc
);
6556 /* "break" without arguments is equivalent to "break *PC" where PC is
6557 the default_breakpoint_address. So make sure to set
6558 sal.explicit_pc to prevent GDB from trying to expand the list of
6559 sals to include all other instances with the same symtab and line.
6561 sal
.explicit_pc
= 1;
6563 sals
->sals
[0] = sal
;
6567 error (_("No default breakpoint address now."));
6571 /* Force almost all breakpoints to be in terms of the
6572 current_source_symtab (which is decode_line_1's default). This
6573 should produce the results we want almost all of the time while
6574 leaving default_breakpoint_* alone.
6575 ObjC: However, don't match an Objective-C method name which
6576 may have a '+' or '-' succeeded by a '[' */
6578 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
6580 if (default_breakpoint_valid
6582 || ((strchr ("+-", (*address
)[0]) != NULL
)
6583 && ((*address
)[1] != '['))))
6584 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
6585 default_breakpoint_line
, addr_string
,
6588 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
6589 addr_string
, not_found_ptr
);
6591 /* For any SAL that didn't have a canonical string, fill one in. */
6592 if (sals
->nelts
> 0 && *addr_string
== NULL
)
6593 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
6594 if (addr_start
!= (*address
))
6597 for (i
= 0; i
< sals
->nelts
; i
++)
6599 /* Add the string if not present. */
6600 if ((*addr_string
)[i
] == NULL
)
6601 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
6607 /* Convert each SAL into a real PC. Verify that the PC can be
6608 inserted as a breakpoint. If it can't throw an error. */
6611 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
6615 for (i
= 0; i
< sals
->nelts
; i
++)
6616 resolve_sal_pc (&sals
->sals
[i
]);
6619 /* Fast tracepoints may have restrictions on valid locations. For
6620 instance, a fast tracepoint using a jump instead of a trap will
6621 likely have to overwrite more bytes than a trap would, and so can
6622 only be placed where the instruction is longer than the jump, or a
6623 multi-instruction sequence does not have a jump into the middle of
6627 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
6628 struct symtabs_and_lines
*sals
)
6631 struct symtab_and_line
*sal
;
6633 struct cleanup
*old_chain
;
6635 for (i
= 0; i
< sals
->nelts
; i
++)
6637 sal
= &sals
->sals
[i
];
6639 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
6641 old_chain
= make_cleanup (xfree
, msg
);
6644 error (_("May not have a fast tracepoint at 0x%s%s"),
6645 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
6647 do_cleanups (old_chain
);
6652 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
6654 struct captured_parse_breakpoint_args
*args
= data
;
6656 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
6657 args
->not_found_ptr
);
6660 /* Given TOK, a string specification of condition and thread, as
6661 accepted by the 'break' command, extract the condition
6662 string and thread number and set *COND_STRING and *THREAD.
6663 PC identifies the context at which the condition should be parsed.
6664 If no condition is found, *COND_STRING is set to NULL.
6665 If no thread is found, *THREAD is set to -1. */
6667 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
6668 char **cond_string
, int *thread
, int *task
)
6670 *cond_string
= NULL
;
6676 char *cond_start
= NULL
;
6677 char *cond_end
= NULL
;
6678 while (*tok
== ' ' || *tok
== '\t')
6683 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6686 toklen
= end_tok
- tok
;
6688 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6690 struct expression
*expr
;
6692 tok
= cond_start
= end_tok
+ 1;
6693 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
6696 *cond_string
= savestring (cond_start
,
6697 cond_end
- cond_start
);
6699 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6705 *thread
= strtol (tok
, &tok
, 0);
6707 error (_("Junk after thread keyword."));
6708 if (!valid_thread_id (*thread
))
6709 error (_("Unknown thread %d."), *thread
);
6711 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
6717 *task
= strtol (tok
, &tok
, 0);
6719 error (_("Junk after task keyword."));
6720 if (!valid_task_id (*task
))
6721 error (_("Unknown task %d."), *task
);
6724 error (_("Junk at end of arguments."));
6728 /* Set a breakpoint. This function is shared between
6729 CLI and MI functions for setting a breakpoint.
6730 This function has two major modes of operations,
6731 selected by the PARSE_CONDITION_AND_THREAD parameter.
6732 If non-zero, the function will parse arg, extracting
6733 breakpoint location, address and thread. Otherwise,
6734 ARG is just the location of breakpoint, with condition
6735 and thread specified by the COND_STRING and THREAD
6739 break_command_really (struct gdbarch
*gdbarch
,
6740 char *arg
, char *cond_string
, int thread
,
6741 int parse_condition_and_thread
,
6742 int tempflag
, int hardwareflag
, int traceflag
,
6744 enum auto_boolean pending_break_support
,
6745 struct breakpoint_ops
*ops
,
6749 struct gdb_exception e
;
6750 struct symtabs_and_lines sals
;
6751 struct symtab_and_line pending_sal
;
6754 char *addr_start
= arg
;
6756 struct cleanup
*old_chain
;
6757 struct cleanup
*bkpt_chain
= NULL
;
6758 struct captured_parse_breakpoint_args parse_args
;
6762 enum bptype type_wanted
;
6769 parse_args
.arg_p
= &arg
;
6770 parse_args
.sals_p
= &sals
;
6771 parse_args
.addr_string_p
= &addr_string
;
6772 parse_args
.not_found_ptr
= ¬_found
;
6774 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
6775 &parse_args
, RETURN_MASK_ALL
);
6777 /* If caller is interested in rc value from parse, set value. */
6781 throw_exception (e
);
6785 case NOT_FOUND_ERROR
:
6787 /* If pending breakpoint support is turned off, throw
6790 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
6791 throw_exception (e
);
6793 exception_print (gdb_stderr
, e
);
6795 /* If pending breakpoint support is auto query and the user
6796 selects no, then simply return the error code. */
6797 if (pending_break_support
== AUTO_BOOLEAN_AUTO
6798 && !nquery ("Make breakpoint pending on future shared library load? "))
6801 /* At this point, either the user was queried about setting
6802 a pending breakpoint and selected yes, or pending
6803 breakpoint behavior is on and thus a pending breakpoint
6804 is defaulted on behalf of the user. */
6805 copy_arg
= xstrdup (addr_start
);
6806 addr_string
= ©_arg
;
6808 sals
.sals
= &pending_sal
;
6813 throw_exception (e
);
6820 /* Create a chain of things that always need to be cleaned up. */
6821 old_chain
= make_cleanup (null_cleanup
, 0);
6825 /* Make sure that all storage allocated to SALS gets freed. */
6826 make_cleanup (xfree
, sals
.sals
);
6828 /* Cleanup the addr_string array but not its contents. */
6829 make_cleanup (xfree
, addr_string
);
6832 /* ----------------------------- SNIP -----------------------------
6833 Anything added to the cleanup chain beyond this point is assumed
6834 to be part of a breakpoint. If the breakpoint create succeeds
6835 then the memory is not reclaimed. */
6836 bkpt_chain
= make_cleanup (null_cleanup
, 0);
6838 /* Mark the contents of the addr_string for cleanup. These go on
6839 the bkpt_chain and only occur if the breakpoint create fails. */
6840 for (i
= 0; i
< sals
.nelts
; i
++)
6842 if (addr_string
[i
] != NULL
)
6843 make_cleanup (xfree
, addr_string
[i
]);
6846 /* Resolve all line numbers to PC's and verify that the addresses
6847 are ok for the target. */
6849 breakpoint_sals_to_pc (&sals
, addr_start
);
6851 type_wanted
= (traceflag
6852 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
6853 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
6855 /* Fast tracepoints may have additional restrictions on location. */
6856 if (type_wanted
== bp_fast_tracepoint
)
6857 check_fast_tracepoint_sals (gdbarch
, &sals
);
6859 /* Verify that condition can be parsed, before setting any
6860 breakpoints. Allocate a separate condition expression for each
6864 if (parse_condition_and_thread
)
6866 /* Here we only parse 'arg' to separate condition
6867 from thread number, so parsing in context of first
6868 sal is OK. When setting the breakpoint we'll
6869 re-parse it in context of each sal. */
6872 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
6875 make_cleanup (xfree
, cond_string
);
6879 /* Create a private copy of condition string. */
6882 cond_string
= xstrdup (cond_string
);
6883 make_cleanup (xfree
, cond_string
);
6886 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
6887 tempflag
? disp_del
: disp_donttouch
,
6888 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6892 struct symtab_and_line sal
= {0};
6893 struct breakpoint
*b
;
6895 make_cleanup (xfree
, copy_arg
);
6897 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
6898 set_breakpoint_count (breakpoint_count
+ 1);
6899 b
->number
= breakpoint_count
;
6901 b
->addr_string
= addr_string
[0];
6902 b
->cond_string
= NULL
;
6903 b
->ignore_count
= ignore_count
;
6904 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6905 b
->condition_not_parsed
= 1;
6907 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6908 b
->pspace
= current_program_space
;
6910 if (enabled
&& b
->pspace
->executing_startup
6911 && (b
->type
== bp_breakpoint
6912 || b
->type
== bp_hardware_breakpoint
))
6913 b
->enable_state
= bp_startup_disabled
;
6919 warning (_("Multiple breakpoints were set.\n"
6920 "Use the \"delete\" command to delete unwanted breakpoints."));
6921 /* That's it. Discard the cleanups for data inserted into the
6923 discard_cleanups (bkpt_chain
);
6924 /* But cleanup everything else. */
6925 do_cleanups (old_chain
);
6927 /* error call may happen here - have BKPT_CHAIN already discarded. */
6928 update_global_location_list (1);
6931 /* Set a breakpoint.
6932 ARG is a string describing breakpoint address,
6933 condition, and thread.
6934 FLAG specifies if a breakpoint is hardware on,
6935 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6939 break_command_1 (char *arg
, int flag
, int from_tty
)
6941 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
6942 int tempflag
= flag
& BP_TEMPFLAG
;
6944 break_command_really (get_current_arch (),
6946 NULL
, 0, 1 /* parse arg */,
6947 tempflag
, hardwareflag
, 0 /* traceflag */,
6948 0 /* Ignore count */,
6949 pending_break_support
,
6950 NULL
/* breakpoint_ops */,
6957 set_breakpoint (struct gdbarch
*gdbarch
,
6958 char *address
, char *condition
,
6959 int hardwareflag
, int tempflag
,
6960 int thread
, int ignore_count
,
6961 int pending
, int enabled
)
6963 break_command_really (gdbarch
,
6964 address
, condition
, thread
,
6965 0 /* condition and thread are valid. */,
6966 tempflag
, hardwareflag
, 0 /* traceflag */,
6969 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
6973 /* Adjust SAL to the first instruction past the function prologue.
6974 The end of the prologue is determined using the line table from
6975 the debugging information. explicit_pc and explicit_line are
6978 If SAL is already past the prologue, then do nothing. */
6981 skip_prologue_sal (struct symtab_and_line
*sal
)
6984 struct symtab_and_line start_sal
;
6985 struct cleanup
*old_chain
;
6987 old_chain
= save_current_space_and_thread ();
6989 sym
= find_pc_function (sal
->pc
);
6992 start_sal
= find_function_start_sal (sym
, 1);
6993 if (sal
->pc
< start_sal
.pc
)
6995 start_sal
.explicit_line
= sal
->explicit_line
;
6996 start_sal
.explicit_pc
= sal
->explicit_pc
;
7001 do_cleanups (old_chain
);
7004 /* Helper function for break_command_1 and disassemble_command. */
7007 resolve_sal_pc (struct symtab_and_line
*sal
)
7011 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7013 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7014 error (_("No line %d in file \"%s\"."),
7015 sal
->line
, sal
->symtab
->filename
);
7018 /* If this SAL corresponds to a breakpoint inserted using
7019 a line number, then skip the function prologue if necessary. */
7020 if (sal
->explicit_line
)
7022 /* Preserve the original line number. */
7023 int saved_line
= sal
->line
;
7024 skip_prologue_sal (sal
);
7025 sal
->line
= saved_line
;
7029 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7031 struct blockvector
*bv
;
7035 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7038 sym
= block_linkage_function (b
);
7041 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7042 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7046 /* It really is worthwhile to have the section, so we'll just
7047 have to look harder. This case can be executed if we have
7048 line numbers but no functions (as can happen in assembly
7051 struct minimal_symbol
*msym
;
7052 struct cleanup
*old_chain
= save_current_space_and_thread ();
7054 switch_to_program_space_and_thread (sal
->pspace
);
7056 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7058 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7060 do_cleanups (old_chain
);
7067 break_command (char *arg
, int from_tty
)
7069 break_command_1 (arg
, 0, from_tty
);
7073 tbreak_command (char *arg
, int from_tty
)
7075 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7079 hbreak_command (char *arg
, int from_tty
)
7081 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7085 thbreak_command (char *arg
, int from_tty
)
7087 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7091 stop_command (char *arg
, int from_tty
)
7093 printf_filtered (_("Specify the type of breakpoint to set.\n\
7094 Usage: stop in <function | address>\n\
7095 stop at <line>\n"));
7099 stopin_command (char *arg
, int from_tty
)
7103 if (arg
== (char *) NULL
)
7105 else if (*arg
!= '*')
7110 /* look for a ':'. If this is a line number specification, then
7111 say it is bad, otherwise, it should be an address or
7112 function/method name */
7113 while (*argptr
&& !hasColon
)
7115 hasColon
= (*argptr
== ':');
7120 badInput
= (*argptr
!= ':'); /* Not a class::method */
7122 badInput
= isdigit (*arg
); /* a simple line number */
7126 printf_filtered (_("Usage: stop in <function | address>\n"));
7128 break_command_1 (arg
, 0, from_tty
);
7132 stopat_command (char *arg
, int from_tty
)
7136 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7143 /* look for a ':'. If there is a '::' then get out, otherwise
7144 it is probably a line number. */
7145 while (*argptr
&& !hasColon
)
7147 hasColon
= (*argptr
== ':');
7152 badInput
= (*argptr
== ':'); /* we have class::method */
7154 badInput
= !isdigit (*arg
); /* not a line number */
7158 printf_filtered (_("Usage: stop at <line>\n"));
7160 break_command_1 (arg
, 0, from_tty
);
7163 /* accessflag: hw_write: watch write,
7164 hw_read: watch read,
7165 hw_access: watch access (read or write) */
7167 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7169 struct gdbarch
*gdbarch
= get_current_arch ();
7170 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7171 struct expression
*exp
;
7172 struct block
*exp_valid_block
;
7173 struct value
*val
, *mark
;
7174 struct frame_info
*frame
;
7175 char *exp_start
= NULL
;
7176 char *exp_end
= NULL
;
7177 char *tok
, *id_tok_start
, *end_tok
;
7179 char *cond_start
= NULL
;
7180 char *cond_end
= NULL
;
7181 int i
, other_type_used
, target_resources_ok
= 0;
7182 enum bptype bp_type
;
7186 /* Make sure that we actually have parameters to parse. */
7187 if (arg
!= NULL
&& arg
[0] != '\0')
7189 toklen
= strlen (arg
); /* Size of argument list. */
7191 /* Points tok to the end of the argument list. */
7192 tok
= arg
+ toklen
- 1;
7194 /* Go backwards in the parameters list. Skip the last parameter.
7195 If we're expecting a 'thread <thread_num>' parameter, this should
7196 be the thread identifier. */
7197 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7199 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7202 /* Points end_tok to the beginning of the last token. */
7203 id_tok_start
= tok
+ 1;
7205 /* Go backwards in the parameters list. Skip one more parameter.
7206 If we're expecting a 'thread <thread_num>' parameter, we should
7207 reach a "thread" token. */
7208 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7213 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7216 /* Move the pointer forward to skip the whitespace and
7217 calculate the length of the token. */
7219 toklen
= end_tok
- tok
;
7221 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7223 /* At this point we've found a "thread" token, which means
7224 the user is trying to set a watchpoint that triggers
7225 only in a specific thread. */
7228 /* Extract the thread ID from the next token. */
7229 thread
= strtol (id_tok_start
, &endp
, 0);
7231 /* Check if the user provided a valid numeric value for the
7233 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7234 error (_("Invalid thread ID specification %s."), id_tok_start
);
7236 /* Check if the thread actually exists. */
7237 if (!valid_thread_id (thread
))
7238 error (_("Unknown thread %d."), thread
);
7240 /* Truncate the string and get rid of the thread <thread_num>
7241 parameter before the parameter list is parsed by the
7242 evaluate_expression() function. */
7247 /* Parse the rest of the arguments. */
7248 innermost_block
= NULL
;
7250 exp
= parse_exp_1 (&arg
, 0, 0);
7252 /* Remove trailing whitespace from the expression before saving it.
7253 This makes the eventual display of the expression string a bit
7255 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7258 exp_valid_block
= innermost_block
;
7259 mark
= value_mark ();
7260 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7262 release_value (val
);
7265 while (*tok
== ' ' || *tok
== '\t')
7269 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7272 toklen
= end_tok
- tok
;
7273 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7275 struct expression
*cond
;
7277 tok
= cond_start
= end_tok
+ 1;
7278 cond
= parse_exp_1 (&tok
, 0, 0);
7283 error (_("Junk at end of command."));
7285 if (accessflag
== hw_read
)
7286 bp_type
= bp_read_watchpoint
;
7287 else if (accessflag
== hw_access
)
7288 bp_type
= bp_access_watchpoint
;
7290 bp_type
= bp_hardware_watchpoint
;
7292 mem_cnt
= can_use_hardware_watchpoint (val
);
7293 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7294 error (_("Expression cannot be implemented with read/access watchpoint."));
7297 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7298 target_resources_ok
=
7299 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7301 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7302 error (_("Target does not support this type of hardware watchpoint."));
7304 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7305 error (_("Target can only support one kind of HW watchpoint at a time."));
7308 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7309 watchpoint could not be set. */
7310 if (!mem_cnt
|| target_resources_ok
<= 0)
7311 bp_type
= bp_watchpoint
;
7313 frame
= block_innermost_frame (exp_valid_block
);
7315 /* If the expression is "local", then set up a "watchpoint scope"
7316 breakpoint at the point where we've left the scope of the watchpoint
7317 expression. Create the scope breakpoint before the watchpoint, so
7318 that we will encounter it first in bpstat_stop_status. */
7319 if (innermost_block
&& frame
)
7321 if (frame_id_p (frame_unwind_caller_id (frame
)))
7324 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7325 frame_unwind_caller_pc (frame
),
7326 bp_watchpoint_scope
);
7328 scope_breakpoint
->enable_state
= bp_enabled
;
7330 /* Automatically delete the breakpoint when it hits. */
7331 scope_breakpoint
->disposition
= disp_del
;
7333 /* Only break in the proper frame (help with recursion). */
7334 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7336 /* Set the address at which we will stop. */
7337 scope_breakpoint
->loc
->gdbarch
7338 = frame_unwind_caller_arch (frame
);
7339 scope_breakpoint
->loc
->requested_address
7340 = frame_unwind_caller_pc (frame
);
7341 scope_breakpoint
->loc
->address
7342 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7343 scope_breakpoint
->loc
->requested_address
,
7344 scope_breakpoint
->type
);
7348 /* Now set up the breakpoint. */
7349 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7350 set_breakpoint_count (breakpoint_count
+ 1);
7351 b
->number
= breakpoint_count
;
7353 b
->disposition
= disp_donttouch
;
7355 b
->exp_valid_block
= exp_valid_block
;
7356 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7360 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7366 b
->watchpoint_frame
= get_frame_id (frame
);
7367 b
->watchpoint_thread
= inferior_ptid
;
7371 b
->watchpoint_frame
= null_frame_id
;
7372 b
->watchpoint_thread
= null_ptid
;
7375 if (scope_breakpoint
!= NULL
)
7377 /* The scope breakpoint is related to the watchpoint. We will
7378 need to act on them together. */
7379 b
->related_breakpoint
= scope_breakpoint
;
7380 scope_breakpoint
->related_breakpoint
= b
;
7383 value_free_to_mark (mark
);
7385 /* Finally update the new watchpoint. This creates the locations
7386 that should be inserted. */
7387 update_watchpoint (b
, 1);
7390 update_global_location_list (1);
7393 /* Return count of locations need to be watched and can be handled
7394 in hardware. If the watchpoint can not be handled
7395 in hardware return zero. */
7398 can_use_hardware_watchpoint (struct value
*v
)
7400 int found_memory_cnt
= 0;
7401 struct value
*head
= v
;
7403 /* Did the user specifically forbid us to use hardware watchpoints? */
7404 if (!can_use_hw_watchpoints
)
7407 /* Make sure that the value of the expression depends only upon
7408 memory contents, and values computed from them within GDB. If we
7409 find any register references or function calls, we can't use a
7410 hardware watchpoint.
7412 The idea here is that evaluating an expression generates a series
7413 of values, one holding the value of every subexpression. (The
7414 expression a*b+c has five subexpressions: a, b, a*b, c, and
7415 a*b+c.) GDB's values hold almost enough information to establish
7416 the criteria given above --- they identify memory lvalues,
7417 register lvalues, computed values, etcetera. So we can evaluate
7418 the expression, and then scan the chain of values that leaves
7419 behind to decide whether we can detect any possible change to the
7420 expression's final value using only hardware watchpoints.
7422 However, I don't think that the values returned by inferior
7423 function calls are special in any way. So this function may not
7424 notice that an expression involving an inferior function call
7425 can't be watched with hardware watchpoints. FIXME. */
7426 for (; v
; v
= value_next (v
))
7428 if (VALUE_LVAL (v
) == lval_memory
)
7431 /* A lazy memory lvalue is one that GDB never needed to fetch;
7432 we either just used its address (e.g., `a' in `a.b') or
7433 we never needed it at all (e.g., `a' in `a,b'). */
7437 /* Ahh, memory we actually used! Check if we can cover
7438 it with hardware watchpoints. */
7439 struct type
*vtype
= check_typedef (value_type (v
));
7441 /* We only watch structs and arrays if user asked for it
7442 explicitly, never if they just happen to appear in a
7443 middle of some value chain. */
7445 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7446 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7448 CORE_ADDR vaddr
= value_address (v
);
7449 int len
= TYPE_LENGTH (value_type (v
));
7451 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7458 else if (VALUE_LVAL (v
) != not_lval
7459 && deprecated_value_modifiable (v
) == 0)
7460 return 0; /* ??? What does this represent? */
7461 else if (VALUE_LVAL (v
) == lval_register
)
7462 return 0; /* cannot watch a register with a HW watchpoint */
7465 /* The expression itself looks suitable for using a hardware
7466 watchpoint, but give the target machine a chance to reject it. */
7467 return found_memory_cnt
;
7471 watch_command_wrapper (char *arg
, int from_tty
)
7473 watch_command (arg
, from_tty
);
7477 watch_command (char *arg
, int from_tty
)
7479 watch_command_1 (arg
, hw_write
, from_tty
);
7483 rwatch_command_wrapper (char *arg
, int from_tty
)
7485 rwatch_command (arg
, from_tty
);
7489 rwatch_command (char *arg
, int from_tty
)
7491 watch_command_1 (arg
, hw_read
, from_tty
);
7495 awatch_command_wrapper (char *arg
, int from_tty
)
7497 awatch_command (arg
, from_tty
);
7501 awatch_command (char *arg
, int from_tty
)
7503 watch_command_1 (arg
, hw_access
, from_tty
);
7507 /* Helper routines for the until_command routine in infcmd.c. Here
7508 because it uses the mechanisms of breakpoints. */
7510 struct until_break_command_continuation_args
7512 struct breakpoint
*breakpoint
;
7513 struct breakpoint
*breakpoint2
;
7516 /* This function is called by fetch_inferior_event via the
7517 cmd_continuation pointer, to complete the until command. It takes
7518 care of cleaning up the temporary breakpoints set up by the until
7521 until_break_command_continuation (void *arg
)
7523 struct until_break_command_continuation_args
*a
= arg
;
7525 delete_breakpoint (a
->breakpoint
);
7527 delete_breakpoint (a
->breakpoint2
);
7531 until_break_command (char *arg
, int from_tty
, int anywhere
)
7533 struct symtabs_and_lines sals
;
7534 struct symtab_and_line sal
;
7535 struct frame_info
*frame
= get_selected_frame (NULL
);
7536 struct breakpoint
*breakpoint
;
7537 struct breakpoint
*breakpoint2
= NULL
;
7538 struct cleanup
*old_chain
;
7540 clear_proceed_status ();
7542 /* Set a breakpoint where the user wants it and at return from
7545 if (default_breakpoint_valid
)
7546 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
7547 default_breakpoint_line
, (char ***) NULL
, NULL
);
7549 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
7550 0, (char ***) NULL
, NULL
);
7552 if (sals
.nelts
!= 1)
7553 error (_("Couldn't get information on specified line."));
7556 xfree (sals
.sals
); /* malloc'd, so freed */
7559 error (_("Junk at end of arguments."));
7561 resolve_sal_pc (&sal
);
7564 /* If the user told us to continue until a specified location,
7565 we don't specify a frame at which we need to stop. */
7566 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7567 null_frame_id
, bp_until
);
7569 /* Otherwise, specify the selected frame, because we want to stop only
7570 at the very same frame. */
7571 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7572 get_stack_frame_id (frame
),
7575 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
7577 /* Keep within the current frame, or in frames called by the current
7580 if (frame_id_p (frame_unwind_caller_id (frame
)))
7582 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
7583 sal
.pc
= frame_unwind_caller_pc (frame
);
7584 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
7586 frame_unwind_caller_id (frame
),
7588 make_cleanup_delete_breakpoint (breakpoint2
);
7591 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
7593 /* If we are running asynchronously, and proceed call above has actually
7594 managed to start the target, arrange for breakpoints to be
7595 deleted when the target stops. Otherwise, we're already stopped and
7596 delete breakpoints via cleanup chain. */
7598 if (target_can_async_p () && is_running (inferior_ptid
))
7600 struct until_break_command_continuation_args
*args
;
7601 args
= xmalloc (sizeof (*args
));
7603 args
->breakpoint
= breakpoint
;
7604 args
->breakpoint2
= breakpoint2
;
7606 discard_cleanups (old_chain
);
7607 add_continuation (inferior_thread (),
7608 until_break_command_continuation
, args
,
7612 do_cleanups (old_chain
);
7616 ep_skip_leading_whitespace (char **s
)
7618 if ((s
== NULL
) || (*s
== NULL
))
7620 while (isspace (**s
))
7624 /* This function attempts to parse an optional "if <cond>" clause
7625 from the arg string. If one is not found, it returns NULL.
7627 Else, it returns a pointer to the condition string. (It does not
7628 attempt to evaluate the string against a particular block.) And,
7629 it updates arg to point to the first character following the parsed
7630 if clause in the arg string. */
7633 ep_parse_optional_if_clause (char **arg
)
7637 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
7640 /* Skip the "if" keyword. */
7643 /* Skip any extra leading whitespace, and record the start of the
7644 condition string. */
7645 ep_skip_leading_whitespace (arg
);
7648 /* Assume that the condition occupies the remainder of the arg string. */
7649 (*arg
) += strlen (cond_string
);
7654 /* This function attempts to parse an optional filename from the arg
7655 string. If one is not found, it returns NULL.
7657 Else, it returns a pointer to the parsed filename. (This function
7658 makes no attempt to verify that a file of that name exists, or is
7659 accessible.) And, it updates arg to point to the first character
7660 following the parsed filename in the arg string.
7662 Note that clients needing to preserve the returned filename for
7663 future access should copy it to their own buffers. */
7665 ep_parse_optional_filename (char **arg
)
7667 static char filename
[1024];
7672 if ((*arg_p
== '\0') || isspace (*arg_p
))
7690 /* Commands to deal with catching events, such as signals, exceptions,
7691 process start/exit, etc. */
7695 catch_fork_temporary
, catch_vfork_temporary
,
7696 catch_fork_permanent
, catch_vfork_permanent
7701 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7703 struct gdbarch
*gdbarch
= get_current_arch ();
7704 char *cond_string
= NULL
;
7705 catch_fork_kind fork_kind
;
7708 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
7709 tempflag
= (fork_kind
== catch_fork_temporary
7710 || fork_kind
== catch_vfork_temporary
);
7714 ep_skip_leading_whitespace (&arg
);
7716 /* The allowed syntax is:
7718 catch [v]fork if <cond>
7720 First, check if there's an if clause. */
7721 cond_string
= ep_parse_optional_if_clause (&arg
);
7723 if ((*arg
!= '\0') && !isspace (*arg
))
7724 error (_("Junk at end of arguments."));
7726 /* If this target supports it, create a fork or vfork catchpoint
7727 and enable reporting of such events. */
7730 case catch_fork_temporary
:
7731 case catch_fork_permanent
:
7732 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
7733 &catch_fork_breakpoint_ops
);
7735 case catch_vfork_temporary
:
7736 case catch_vfork_permanent
:
7737 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
7738 &catch_vfork_breakpoint_ops
);
7741 error (_("unsupported or unknown fork kind; cannot catch it"));
7747 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7749 struct gdbarch
*gdbarch
= get_current_arch ();
7751 char *cond_string
= NULL
;
7753 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7757 ep_skip_leading_whitespace (&arg
);
7759 /* The allowed syntax is:
7761 catch exec if <cond>
7763 First, check if there's an if clause. */
7764 cond_string
= ep_parse_optional_if_clause (&arg
);
7766 if ((*arg
!= '\0') && !isspace (*arg
))
7767 error (_("Junk at end of arguments."));
7769 /* If this target supports it, create an exec catchpoint
7770 and enable reporting of such events. */
7771 create_catchpoint (gdbarch
, tempflag
, cond_string
,
7772 &catch_exec_breakpoint_ops
);
7775 static enum print_stop_action
7776 print_exception_catchpoint (struct breakpoint
*b
)
7778 int bp_temp
, bp_throw
;
7780 annotate_catchpoint (b
->number
);
7782 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
7783 if (b
->loc
->address
!= b
->loc
->requested_address
)
7784 breakpoint_adjustment_warning (b
->loc
->requested_address
,
7787 bp_temp
= b
->disposition
== disp_del
;
7789 bp_temp
? "Temporary catchpoint "
7791 if (!ui_out_is_mi_like_p (uiout
))
7792 ui_out_field_int (uiout
, "bkptno", b
->number
);
7794 bp_throw
? " (exception thrown), "
7795 : " (exception caught), ");
7796 if (ui_out_is_mi_like_p (uiout
))
7798 ui_out_field_string (uiout
, "reason",
7799 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
7800 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7801 ui_out_field_int (uiout
, "bkptno", b
->number
);
7803 return PRINT_SRC_AND_LOC
;
7807 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
7809 struct value_print_options opts
;
7810 get_user_print_options (&opts
);
7811 if (opts
.addressprint
)
7814 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
7815 ui_out_field_string (uiout
, "addr", "<PENDING>");
7817 ui_out_field_core_addr (uiout
, "addr",
7818 b
->loc
->gdbarch
, b
->loc
->address
);
7823 if (strstr (b
->addr_string
, "throw") != NULL
)
7824 ui_out_field_string (uiout
, "what", "exception throw");
7826 ui_out_field_string (uiout
, "what", "exception catch");
7830 print_mention_exception_catchpoint (struct breakpoint
*b
)
7835 bp_temp
= b
->disposition
== disp_del
;
7836 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
7837 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
7838 : _("Catchpoint "));
7839 ui_out_field_int (uiout
, "bkptno", b
->number
);
7840 ui_out_text (uiout
, bp_throw
? _(" (throw)")
7844 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
7847 NULL
, /* breakpoint_hit */
7848 print_exception_catchpoint
,
7849 print_one_exception_catchpoint
,
7850 print_mention_exception_catchpoint
7854 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
7855 enum exception_event_kind ex_event
, int from_tty
)
7857 char *trigger_func_name
;
7859 if (ex_event
== EX_EVENT_CATCH
)
7860 trigger_func_name
= "__cxa_begin_catch";
7862 trigger_func_name
= "__cxa_throw";
7864 break_command_really (get_current_arch (),
7865 trigger_func_name
, cond_string
, -1,
7866 0 /* condition and thread are valid. */,
7869 AUTO_BOOLEAN_TRUE
/* pending */,
7870 &gnu_v3_exception_catchpoint_ops
, from_tty
,
7876 /* Deal with "catch catch" and "catch throw" commands */
7879 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
7880 int tempflag
, int from_tty
)
7882 char *cond_string
= NULL
;
7883 struct symtab_and_line
*sal
= NULL
;
7887 ep_skip_leading_whitespace (&arg
);
7889 cond_string
= ep_parse_optional_if_clause (&arg
);
7891 if ((*arg
!= '\0') && !isspace (*arg
))
7892 error (_("Junk at end of arguments."));
7894 if (ex_event
!= EX_EVENT_THROW
7895 && ex_event
!= EX_EVENT_CATCH
)
7896 error (_("Unsupported or unknown exception event; cannot catch it"));
7898 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
7901 warning (_("Unsupported with this platform/compiler combination."));
7904 /* Implementation of "catch catch" command. */
7907 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7909 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7910 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
7913 /* Implementation of "catch throw" command. */
7916 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7918 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7919 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
7922 /* Create a breakpoint struct for Ada exception catchpoints. */
7925 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
7926 struct symtab_and_line sal
,
7930 struct expression
*cond
,
7931 struct breakpoint_ops
*ops
,
7935 struct breakpoint
*b
;
7939 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7941 loc_gdbarch
= gdbarch
;
7943 describe_other_breakpoints (loc_gdbarch
,
7944 sal
.pspace
, sal
.pc
, sal
.section
, -1);
7945 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7946 version for exception catchpoints, because two catchpoints
7947 used for different exception names will use the same address.
7948 In this case, a "breakpoint ... also set at..." warning is
7949 unproductive. Besides. the warning phrasing is also a bit
7950 inapropriate, we should use the word catchpoint, and tell
7951 the user what type of catchpoint it is. The above is good
7952 enough for now, though. */
7955 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
7956 set_breakpoint_count (breakpoint_count
+ 1);
7958 b
->enable_state
= bp_enabled
;
7959 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7960 b
->number
= breakpoint_count
;
7961 b
->ignore_count
= 0;
7962 b
->loc
->cond
= cond
;
7963 b
->addr_string
= addr_string
;
7964 b
->language
= language_ada
;
7965 b
->cond_string
= cond_string
;
7966 b
->exp_string
= exp_string
;
7971 update_global_location_list (1);
7974 /* Implement the "catch exception" command. */
7977 catch_ada_exception_command (char *arg
, int from_tty
,
7978 struct cmd_list_element
*command
)
7980 struct gdbarch
*gdbarch
= get_current_arch ();
7982 struct symtab_and_line sal
;
7984 char *addr_string
= NULL
;
7985 char *exp_string
= NULL
;
7986 char *cond_string
= NULL
;
7987 struct expression
*cond
= NULL
;
7988 struct breakpoint_ops
*ops
= NULL
;
7990 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7994 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
7995 &cond_string
, &cond
, &ops
);
7996 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
7997 cond_string
, cond
, ops
, tempflag
,
8001 /* Cleanup function for a syscall filter list. */
8003 clean_up_filters (void *arg
)
8005 VEC(int) *iter
= *(VEC(int) **) arg
;
8006 VEC_free (int, iter
);
8009 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8010 filter list, or NULL if no filtering is required. */
8012 catch_syscall_split_args (char *arg
)
8014 VEC(int) *result
= NULL
;
8015 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8017 while (*arg
!= '\0')
8019 int i
, syscall_number
;
8024 /* Skip whitespace. */
8025 while (isspace (*arg
))
8028 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8029 cur_name
[i
] = arg
[i
];
8033 /* Check if the user provided a syscall name or a number. */
8034 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8035 if (*endptr
== '\0')
8036 get_syscall_by_number (syscall_number
, &s
);
8039 /* We have a name. Let's check if it's valid and convert it
8041 get_syscall_by_name (cur_name
, &s
);
8043 if (s
.number
== UNKNOWN_SYSCALL
)
8044 /* Here we have to issue an error instead of a warning, because
8045 GDB cannot do anything useful if there's no syscall number to
8047 error (_("Unknown syscall name '%s'."), cur_name
);
8050 /* Ok, it's valid. */
8051 VEC_safe_push (int, result
, s
.number
);
8054 discard_cleanups (cleanup
);
8058 /* Implement the "catch syscall" command. */
8061 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8066 struct gdbarch
*gdbarch
= get_current_arch ();
8068 /* Checking if the feature if supported. */
8069 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8070 error (_("The feature 'catch syscall' is not supported on \
8071 this architeture yet."));
8073 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8075 ep_skip_leading_whitespace (&arg
);
8077 /* We need to do this first "dummy" translation in order
8078 to get the syscall XML file loaded or, most important,
8079 to display a warning to the user if there's no XML file
8080 for his/her architecture. */
8081 get_syscall_by_number (0, &s
);
8083 /* The allowed syntax is:
8085 catch syscall <name | number> [<name | number> ... <name | number>]
8087 Let's check if there's a syscall name. */
8090 filter
= catch_syscall_split_args (arg
);
8094 create_syscall_event_catchpoint (tempflag
, filter
,
8095 &catch_syscall_breakpoint_ops
);
8098 /* Implement the "catch assert" command. */
8101 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8103 struct gdbarch
*gdbarch
= get_current_arch ();
8105 struct symtab_and_line sal
;
8106 char *addr_string
= NULL
;
8107 struct breakpoint_ops
*ops
= NULL
;
8109 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8113 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8114 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8115 ops
, tempflag
, from_tty
);
8119 catch_command (char *arg
, int from_tty
)
8121 error (_("Catch requires an event name."));
8126 tcatch_command (char *arg
, int from_tty
)
8128 error (_("Catch requires an event name."));
8131 /* Delete breakpoints by address or line. */
8134 clear_command (char *arg
, int from_tty
)
8136 struct breakpoint
*b
;
8137 VEC(breakpoint_p
) *found
= 0;
8140 struct symtabs_and_lines sals
;
8141 struct symtab_and_line sal
;
8146 sals
= decode_line_spec (arg
, 1);
8151 sals
.sals
= (struct symtab_and_line
*)
8152 xmalloc (sizeof (struct symtab_and_line
));
8153 make_cleanup (xfree
, sals
.sals
);
8154 init_sal (&sal
); /* initialize to zeroes */
8155 sal
.line
= default_breakpoint_line
;
8156 sal
.symtab
= default_breakpoint_symtab
;
8157 sal
.pc
= default_breakpoint_address
;
8158 sal
.pspace
= default_breakpoint_pspace
;
8159 if (sal
.symtab
== 0)
8160 error (_("No source file specified."));
8168 /* We don't call resolve_sal_pc here. That's not
8169 as bad as it seems, because all existing breakpoints
8170 typically have both file/line and pc set. So, if
8171 clear is given file/line, we can match this to existing
8172 breakpoint without obtaining pc at all.
8174 We only support clearing given the address explicitly
8175 present in breakpoint table. Say, we've set breakpoint
8176 at file:line. There were several PC values for that file:line,
8177 due to optimization, all in one block.
8178 We've picked one PC value. If "clear" is issued with another
8179 PC corresponding to the same file:line, the breakpoint won't
8180 be cleared. We probably can still clear the breakpoint, but
8181 since the other PC value is never presented to user, user
8182 can only find it by guessing, and it does not seem important
8185 /* For each line spec given, delete bps which correspond
8186 to it. Do it in two passes, solely to preserve the current
8187 behavior that from_tty is forced true if we delete more than
8191 for (i
= 0; i
< sals
.nelts
; i
++)
8193 /* If exact pc given, clear bpts at that pc.
8194 If line given (pc == 0), clear all bpts on specified line.
8195 If defaulting, clear all bpts on default line
8198 defaulting sal.pc != 0 tests to do
8203 1 0 <can't happen> */
8207 /* Find all matching breakpoints and add them to
8212 /* Are we going to delete b? */
8213 if (b
->type
!= bp_none
8214 && b
->type
!= bp_watchpoint
8215 && b
->type
!= bp_hardware_watchpoint
8216 && b
->type
!= bp_read_watchpoint
8217 && b
->type
!= bp_access_watchpoint
)
8219 struct bp_location
*loc
= b
->loc
;
8220 for (; loc
; loc
= loc
->next
)
8222 int pc_match
= sal
.pc
8223 && (loc
->pspace
== sal
.pspace
)
8224 && (loc
->address
== sal
.pc
)
8225 && (!section_is_overlay (loc
->section
)
8226 || loc
->section
== sal
.section
);
8227 int line_match
= ((default_match
|| (0 == sal
.pc
))
8228 && b
->source_file
!= NULL
8229 && sal
.symtab
!= NULL
8230 && sal
.pspace
== loc
->pspace
8231 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8232 && b
->line_number
== sal
.line
);
8233 if (pc_match
|| line_match
)
8242 VEC_safe_push(breakpoint_p
, found
, b
);
8245 /* Now go thru the 'found' chain and delete them. */
8246 if (VEC_empty(breakpoint_p
, found
))
8249 error (_("No breakpoint at %s."), arg
);
8251 error (_("No breakpoint at this line."));
8254 if (VEC_length(breakpoint_p
, found
) > 1)
8255 from_tty
= 1; /* Always report if deleted more than one */
8258 if (VEC_length(breakpoint_p
, found
) == 1)
8259 printf_unfiltered (_("Deleted breakpoint "));
8261 printf_unfiltered (_("Deleted breakpoints "));
8263 breakpoints_changed ();
8265 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8268 printf_unfiltered ("%d ", b
->number
);
8269 delete_breakpoint (b
);
8272 putchar_unfiltered ('\n');
8275 /* Delete breakpoint in BS if they are `delete' breakpoints and
8276 all breakpoints that are marked for deletion, whether hit or not.
8277 This is called after any breakpoint is hit, or after errors. */
8280 breakpoint_auto_delete (bpstat bs
)
8282 struct breakpoint
*b
, *temp
;
8284 for (; bs
; bs
= bs
->next
)
8285 if (bs
->breakpoint_at
8286 && bs
->breakpoint_at
->owner
8287 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8289 delete_breakpoint (bs
->breakpoint_at
->owner
);
8291 ALL_BREAKPOINTS_SAFE (b
, temp
)
8293 if (b
->disposition
== disp_del_at_next_stop
)
8294 delete_breakpoint (b
);
8298 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8299 Sort elements primarily by their ADDRESS (no matter what does
8300 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8301 first bp_permanent OWNERed elements and terciarily just ensuring the array
8302 is sorted stable way despite qsort being an instable algorithm. */
8305 bp_location_compare (const void *ap
, const void *bp
)
8307 struct bp_location
*a
= *(void **) ap
;
8308 struct bp_location
*b
= *(void **) bp
;
8309 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8310 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8312 if (a
->address
!= b
->address
)
8313 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8315 /* Sort permanent breakpoints first. */
8316 if (a_perm
!= b_perm
)
8317 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8319 /* Make the user-visible order stable across GDB runs. Locations of the same
8320 breakpoint can be sorted in arbitrary order. */
8322 if (a
->owner
->number
!= b
->owner
->number
)
8323 return (a
->owner
->number
> b
->owner
->number
)
8324 - (a
->owner
->number
< b
->owner
->number
);
8326 return (a
> b
) - (a
< b
);
8329 /* Set bp_location_placed_address_before_address_max and
8330 bp_location_shadow_len_after_address_max according to the current content of
8331 the bp_location array. */
8334 bp_location_target_extensions_update (void)
8336 struct bp_location
*bl
, **blp_tmp
;
8338 bp_location_placed_address_before_address_max
= 0;
8339 bp_location_shadow_len_after_address_max
= 0;
8341 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8343 CORE_ADDR start
, end
, addr
;
8345 if (!bp_location_has_shadow (bl
))
8348 start
= bl
->target_info
.placed_address
;
8349 end
= start
+ bl
->target_info
.shadow_len
;
8351 gdb_assert (bl
->address
>= start
);
8352 addr
= bl
->address
- start
;
8353 if (addr
> bp_location_placed_address_before_address_max
)
8354 bp_location_placed_address_before_address_max
= addr
;
8356 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8358 gdb_assert (bl
->address
< end
);
8359 addr
= end
- bl
->address
;
8360 if (addr
> bp_location_shadow_len_after_address_max
)
8361 bp_location_shadow_len_after_address_max
= addr
;
8365 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8366 into the inferior, only remove already-inserted locations that no
8367 longer should be inserted. Functions that delete a breakpoint or
8368 breakpoints should pass false, so that deleting a breakpoint
8369 doesn't have the side effect of inserting the locations of other
8370 breakpoints that are marked not-inserted, but should_be_inserted
8371 returns true on them.
8373 This behaviour is useful is situations close to tear-down -- e.g.,
8374 after an exec, while the target still has execution, but breakpoint
8375 shadows of the previous executable image should *NOT* be restored
8376 to the new image; or before detaching, where the target still has
8377 execution and wants to delete breakpoints from GDB's lists, and all
8378 breakpoints had already been removed from the inferior. */
8381 update_global_location_list (int should_insert
)
8383 struct breakpoint
*b
;
8384 struct bp_location
**locp
, *loc
;
8385 struct cleanup
*cleanups
;
8387 /* Used in the duplicates detection below. When iterating over all
8388 bp_locations, points to the first bp_location of a given address.
8389 Breakpoints and watchpoints of different types are never
8390 duplicates of each other. Keep one pointer for each type of
8391 breakpoint/watchpoint, so we only need to loop over all locations
8393 struct bp_location
*bp_loc_first
; /* breakpoint */
8394 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8395 struct bp_location
*awp_loc_first
; /* access watchpoint */
8396 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8398 /* Saved former bp_location array which we compare against the newly built
8399 bp_location from the current state of ALL_BREAKPOINTS. */
8400 struct bp_location
**old_location
, **old_locp
;
8401 unsigned old_location_count
;
8403 old_location
= bp_location
;
8404 old_location_count
= bp_location_count
;
8406 bp_location_count
= 0;
8407 cleanups
= make_cleanup (xfree
, old_location
);
8410 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8411 bp_location_count
++;
8413 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8416 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8418 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8419 bp_location_compare
);
8421 bp_location_target_extensions_update ();
8423 /* Identify bp_location instances that are no longer present in the new
8424 list, and therefore should be freed. Note that it's not necessary that
8425 those locations should be removed from inferior -- if there's another
8426 location at the same address (previously marked as duplicate),
8427 we don't need to remove/insert the location.
8429 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8430 former bp_location array state respectively. */
8433 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8436 struct bp_location
*old_loc
= *old_locp
;
8437 struct bp_location
**loc2p
;
8439 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8441 int found_object
= 0;
8442 /* Tells if the location should remain inserted in the target. */
8443 int keep_in_target
= 0;
8446 /* Skip LOCP entries which will definitely never be needed. Stop either
8447 at or being the one matching OLD_LOC. */
8448 while (locp
< bp_location
+ bp_location_count
8449 && (*locp
)->address
< old_loc
->address
)
8453 (loc2p
< bp_location
+ bp_location_count
8454 && (*loc2p
)->address
== old_loc
->address
);
8457 if (*loc2p
== old_loc
)
8464 /* If this location is no longer present, and inserted, look if there's
8465 maybe a new location at the same address. If so, mark that one
8466 inserted, and don't remove this one. This is needed so that we
8467 don't have a time window where a breakpoint at certain location is not
8470 if (old_loc
->inserted
)
8472 /* If the location is inserted now, we might have to remove it. */
8474 if (found_object
&& should_be_inserted (old_loc
))
8476 /* The location is still present in the location list, and still
8477 should be inserted. Don't do anything. */
8482 /* The location is either no longer present, or got disabled.
8483 See if there's another location at the same address, in which
8484 case we don't need to remove this one from the target. */
8486 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8489 (loc2p
< bp_location
+ bp_location_count
8490 && (*loc2p
)->address
== old_loc
->address
);
8493 struct bp_location
*loc2
= *loc2p
;
8495 if (breakpoint_locations_match (loc2
, old_loc
))
8497 /* For the sake of should_be_inserted.
8498 Duplicates check below will fix up this later. */
8499 loc2
->duplicate
= 0;
8500 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8503 loc2
->target_info
= old_loc
->target_info
;
8512 if (!keep_in_target
)
8514 if (remove_breakpoint (old_loc
, mark_uninserted
))
8516 /* This is just about all we can do. We could keep this
8517 location on the global list, and try to remove it next
8518 time, but there's no particular reason why we will
8521 Note that at this point, old_loc->owner is still valid,
8522 as delete_breakpoint frees the breakpoint only
8523 after calling us. */
8524 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8525 old_loc
->owner
->number
);
8533 if (removed
&& non_stop
8534 && breakpoint_address_is_meaningful (old_loc
->owner
)
8535 && !is_hardware_watchpoint (old_loc
->owner
))
8537 /* This location was removed from the target. In
8538 non-stop mode, a race condition is possible where
8539 we've removed a breakpoint, but stop events for that
8540 breakpoint are already queued and will arrive later.
8541 We apply an heuristic to be able to distinguish such
8542 SIGTRAPs from other random SIGTRAPs: we keep this
8543 breakpoint location for a bit, and will retire it
8544 after we see some number of events. The theory here
8545 is that reporting of events should, "on the average",
8546 be fair, so after a while we'll see events from all
8547 threads that have anything of interest, and no longer
8548 need to keep this breakpoint location around. We
8549 don't hold locations forever so to reduce chances of
8550 mistaking a non-breakpoint SIGTRAP for a breakpoint
8553 The heuristic failing can be disastrous on
8554 decr_pc_after_break targets.
8556 On decr_pc_after_break targets, like e.g., x86-linux,
8557 if we fail to recognize a late breakpoint SIGTRAP,
8558 because events_till_retirement has reached 0 too
8559 soon, we'll fail to do the PC adjustment, and report
8560 a random SIGTRAP to the user. When the user resumes
8561 the inferior, it will most likely immediately crash
8562 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
8563 corrupted, because of being resumed e.g., in the
8564 middle of a multi-byte instruction, or skipped a
8565 one-byte instruction. This was actually seen happen
8566 on native x86-linux, and should be less rare on
8567 targets that do not support new thread events, like
8568 remote, due to the heuristic depending on
8571 Mistaking a random SIGTRAP for a breakpoint trap
8572 causes similar symptoms (PC adjustment applied when
8573 it shouldn't), but then again, playing with SIGTRAPs
8574 behind the debugger's back is asking for trouble.
8576 Since hardware watchpoint traps are always
8577 distinguishable from other traps, so we don't need to
8578 apply keep hardware watchpoint moribund locations
8579 around. We simply always ignore hardware watchpoint
8580 traps we can no longer explain. */
8582 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
8583 old_loc
->owner
= NULL
;
8585 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
8588 free_bp_location (old_loc
);
8592 /* Rescan breakpoints at the same address and section, marking the
8593 first one as "first" and any others as "duplicates". This is so
8594 that the bpt instruction is only inserted once. If we have a
8595 permanent breakpoint at the same place as BPT, make that one the
8596 official one, and the rest as duplicates. Permanent breakpoints
8597 are sorted first for the same address.
8599 Do the same for hardware watchpoints, but also considering the
8600 watchpoint's type (regular/access/read) and length. */
8602 bp_loc_first
= NULL
;
8603 wp_loc_first
= NULL
;
8604 awp_loc_first
= NULL
;
8605 rwp_loc_first
= NULL
;
8606 ALL_BP_LOCATIONS (loc
, locp
)
8608 struct breakpoint
*b
= loc
->owner
;
8609 struct bp_location
**loc_first_p
;
8611 if (b
->enable_state
== bp_disabled
8612 || b
->enable_state
== bp_call_disabled
8613 || b
->enable_state
== bp_startup_disabled
8615 || loc
->shlib_disabled
8616 || !breakpoint_address_is_meaningful (b
))
8619 /* Permanent breakpoint should always be inserted. */
8620 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
8621 internal_error (__FILE__
, __LINE__
,
8622 _("allegedly permanent breakpoint is not "
8623 "actually inserted"));
8625 if (b
->type
== bp_hardware_watchpoint
)
8626 loc_first_p
= &wp_loc_first
;
8627 else if (b
->type
== bp_read_watchpoint
)
8628 loc_first_p
= &rwp_loc_first
;
8629 else if (b
->type
== bp_access_watchpoint
)
8630 loc_first_p
= &awp_loc_first
;
8632 loc_first_p
= &bp_loc_first
;
8634 if (*loc_first_p
== NULL
8635 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
8636 || !breakpoint_locations_match (loc
, *loc_first_p
))
8645 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
8646 && b
->enable_state
!= bp_permanent
)
8647 internal_error (__FILE__
, __LINE__
,
8648 _("another breakpoint was inserted on top of "
8649 "a permanent breakpoint"));
8652 if (breakpoints_always_inserted_mode () && should_insert
8653 && (have_live_inferiors ()
8654 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
8655 insert_breakpoint_locations ();
8657 do_cleanups (cleanups
);
8661 breakpoint_retire_moribund (void)
8663 struct bp_location
*loc
;
8666 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
8667 if (--(loc
->events_till_retirement
) == 0)
8669 free_bp_location (loc
);
8670 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
8676 update_global_location_list_nothrow (int inserting
)
8678 struct gdb_exception e
;
8679 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8680 update_global_location_list (inserting
);
8683 /* Clear BPT from a BPS. */
8685 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
8688 for (bs
= bps
; bs
; bs
= bs
->next
)
8689 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
8691 bs
->breakpoint_at
= NULL
;
8693 /* bs->commands will be freed later. */
8697 /* Callback for iterate_over_threads. */
8699 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
8701 struct breakpoint
*bpt
= data
;
8702 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
8706 /* Delete a breakpoint and clean up all traces of it in the data
8710 delete_breakpoint (struct breakpoint
*bpt
)
8712 struct breakpoint
*b
;
8713 struct bp_location
*loc
, *next
;
8715 gdb_assert (bpt
!= NULL
);
8717 /* Has this bp already been deleted? This can happen because multiple
8718 lists can hold pointers to bp's. bpstat lists are especial culprits.
8720 One example of this happening is a watchpoint's scope bp. When the
8721 scope bp triggers, we notice that the watchpoint is out of scope, and
8722 delete it. We also delete its scope bp. But the scope bp is marked
8723 "auto-deleting", and is already on a bpstat. That bpstat is then
8724 checked for auto-deleting bp's, which are deleted.
8726 A real solution to this problem might involve reference counts in bp's,
8727 and/or giving them pointers back to their referencing bpstat's, and
8728 teaching delete_breakpoint to only free a bp's storage when no more
8729 references were extent. A cheaper bandaid was chosen. */
8730 if (bpt
->type
== bp_none
)
8733 observer_notify_breakpoint_deleted (bpt
->number
);
8735 if (breakpoint_chain
== bpt
)
8736 breakpoint_chain
= bpt
->next
;
8741 b
->next
= bpt
->next
;
8745 free_command_lines (&bpt
->commands
);
8746 if (bpt
->cond_string
!= NULL
)
8747 xfree (bpt
->cond_string
);
8748 if (bpt
->addr_string
!= NULL
)
8749 xfree (bpt
->addr_string
);
8750 if (bpt
->exp
!= NULL
)
8752 if (bpt
->exp_string
!= NULL
)
8753 xfree (bpt
->exp_string
);
8754 if (bpt
->val
!= NULL
)
8755 value_free (bpt
->val
);
8756 if (bpt
->source_file
!= NULL
)
8757 xfree (bpt
->source_file
);
8758 if (bpt
->exec_pathname
!= NULL
)
8759 xfree (bpt
->exec_pathname
);
8760 clean_up_filters (&bpt
->syscalls_to_be_caught
);
8762 /* Be sure no bpstat's are pointing at it after it's been freed. */
8763 /* FIXME, how can we find all bpstat's?
8764 We just check stop_bpstat for now. Note that we cannot just
8765 remove bpstats pointing at bpt from the stop_bpstat list
8766 entirely, as breakpoint commands are associated with the bpstat;
8767 if we remove it here, then the later call to
8768 bpstat_do_actions (&stop_bpstat);
8769 in event-top.c won't do anything, and temporary breakpoints
8770 with commands won't work. */
8772 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
8774 /* Now that breakpoint is removed from breakpoint
8775 list, update the global location list. This
8776 will remove locations that used to belong to
8777 this breakpoint. Do this before freeing
8778 the breakpoint itself, since remove_breakpoint
8779 looks at location's owner. It might be better
8780 design to have location completely self-contained,
8781 but it's not the case now. */
8782 update_global_location_list (0);
8785 /* On the chance that someone will soon try again to delete this same
8786 bp, we mark it as deleted before freeing its storage. */
8787 bpt
->type
= bp_none
;
8793 do_delete_breakpoint_cleanup (void *b
)
8795 delete_breakpoint (b
);
8799 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
8801 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
8805 delete_command (char *arg
, int from_tty
)
8807 struct breakpoint
*b
, *temp
;
8813 int breaks_to_delete
= 0;
8815 /* Delete all breakpoints if no argument.
8816 Do not delete internal or call-dummy breakpoints, these
8817 have to be deleted with an explicit breakpoint number argument. */
8820 if (b
->type
!= bp_call_dummy
8821 && b
->type
!= bp_shlib_event
8822 && b
->type
!= bp_jit_event
8823 && b
->type
!= bp_thread_event
8824 && b
->type
!= bp_overlay_event
8825 && b
->type
!= bp_longjmp_master
8828 breaks_to_delete
= 1;
8833 /* Ask user only if there are some breakpoints to delete. */
8835 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
8837 ALL_BREAKPOINTS_SAFE (b
, temp
)
8839 if (b
->type
!= bp_call_dummy
8840 && b
->type
!= bp_shlib_event
8841 && b
->type
!= bp_thread_event
8842 && b
->type
!= bp_jit_event
8843 && b
->type
!= bp_overlay_event
8844 && b
->type
!= bp_longjmp_master
8846 delete_breakpoint (b
);
8851 map_breakpoint_numbers (arg
, delete_breakpoint
);
8855 all_locations_are_pending (struct bp_location
*loc
)
8857 for (; loc
; loc
= loc
->next
)
8858 if (!loc
->shlib_disabled
)
8863 /* Subroutine of update_breakpoint_locations to simplify it.
8864 Return non-zero if multiple fns in list LOC have the same name.
8865 Null names are ignored. */
8868 ambiguous_names_p (struct bp_location
*loc
)
8870 struct bp_location
*l
;
8871 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
8872 (int (*) (const void *, const void *)) streq
,
8873 NULL
, xcalloc
, xfree
);
8875 for (l
= loc
; l
!= NULL
; l
= l
->next
)
8878 const char *name
= l
->function_name
;
8880 /* Allow for some names to be NULL, ignore them. */
8884 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
8886 /* NOTE: We can assume slot != NULL here because xcalloc never returns
8901 update_breakpoint_locations (struct breakpoint
*b
,
8902 struct symtabs_and_lines sals
)
8906 struct bp_location
*existing_locations
= b
->loc
;
8908 /* If there's no new locations, and all existing locations
8909 are pending, don't do anything. This optimizes
8910 the common case where all locations are in the same
8911 shared library, that was unloaded. We'd like to
8912 retain the location, so that when the library
8913 is loaded again, we don't loose the enabled/disabled
8914 status of the individual locations. */
8915 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
8920 for (i
= 0; i
< sals
.nelts
; ++i
)
8922 struct bp_location
*new_loc
=
8923 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
8925 /* Reparse conditions, they might contain references to the
8927 if (b
->cond_string
!= NULL
)
8929 struct gdb_exception e
;
8932 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8934 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
8939 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
8940 b
->number
, e
.message
);
8941 new_loc
->enabled
= 0;
8945 if (b
->source_file
!= NULL
)
8946 xfree (b
->source_file
);
8947 if (sals
.sals
[i
].symtab
== NULL
)
8948 b
->source_file
= NULL
;
8950 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
8952 if (b
->line_number
== 0)
8953 b
->line_number
= sals
.sals
[i
].line
;
8956 /* Update locations of permanent breakpoints. */
8957 if (b
->enable_state
== bp_permanent
)
8958 make_breakpoint_permanent (b
);
8960 /* If possible, carry over 'disable' status from existing breakpoints. */
8962 struct bp_location
*e
= existing_locations
;
8963 /* If there are multiple breakpoints with the same function name,
8964 e.g. for inline functions, comparing function names won't work.
8965 Instead compare pc addresses; this is just a heuristic as things
8966 may have moved, but in practice it gives the correct answer
8967 often enough until a better solution is found. */
8968 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
8970 for (; e
; e
= e
->next
)
8972 if (!e
->enabled
&& e
->function_name
)
8974 struct bp_location
*l
= b
->loc
;
8975 if (have_ambiguous_names
)
8977 for (; l
; l
= l
->next
)
8978 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
8979 l
->pspace
->aspace
, l
->address
))
8987 for (; l
; l
= l
->next
)
8988 if (l
->function_name
8989 && strcmp (e
->function_name
, l
->function_name
) == 0)
8999 update_global_location_list (1);
9003 /* Reset a breakpoint given it's struct breakpoint * BINT.
9004 The value we return ends up being the return value from catch_errors.
9005 Unused in this case. */
9008 breakpoint_re_set_one (void *bint
)
9010 /* get past catch_errs */
9011 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9015 int *not_found_ptr
= ¬_found
;
9016 struct symtabs_and_lines sals
= {0};
9017 struct symtabs_and_lines expanded
= {0};
9019 enum enable_state save_enable
;
9020 struct gdb_exception e
;
9021 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9026 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9030 case bp_hardware_breakpoint
:
9032 case bp_fast_tracepoint
:
9033 /* Do not attempt to re-set breakpoints disabled during startup. */
9034 if (b
->enable_state
== bp_startup_disabled
)
9037 if (b
->addr_string
== NULL
)
9039 /* Anything without a string can't be re-set. */
9040 delete_breakpoint (b
);
9044 set_language (b
->language
);
9045 input_radix
= b
->input_radix
;
9048 save_current_space_and_thread ();
9049 switch_to_program_space_and_thread (b
->pspace
);
9051 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9053 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9058 int not_found_and_ok
= 0;
9059 /* For pending breakpoints, it's expected that parsing
9060 will fail until the right shared library is loaded.
9061 User has already told to create pending breakpoints and
9062 don't need extra messages. If breakpoint is in bp_shlib_disabled
9063 state, then user already saw the message about that breakpoint
9064 being disabled, and don't want to see more errors. */
9066 && (b
->condition_not_parsed
9067 || (b
->loc
&& b
->loc
->shlib_disabled
)
9068 || b
->enable_state
== bp_disabled
))
9069 not_found_and_ok
= 1;
9071 if (!not_found_and_ok
)
9073 /* We surely don't want to warn about the same breakpoint
9074 10 times. One solution, implemented here, is disable
9075 the breakpoint on error. Another solution would be to
9076 have separate 'warning emitted' flag. Since this
9077 happens only when a binary has changed, I don't know
9078 which approach is better. */
9079 b
->enable_state
= bp_disabled
;
9080 throw_exception (e
);
9086 gdb_assert (sals
.nelts
== 1);
9088 resolve_sal_pc (&sals
.sals
[0]);
9089 if (b
->condition_not_parsed
&& s
&& s
[0])
9091 char *cond_string
= 0;
9095 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9096 &cond_string
, &thread
, &task
);
9098 b
->cond_string
= cond_string
;
9101 b
->condition_not_parsed
= 0;
9104 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9107 make_cleanup (xfree
, sals
.sals
);
9108 update_breakpoint_locations (b
, expanded
);
9112 case bp_hardware_watchpoint
:
9113 case bp_read_watchpoint
:
9114 case bp_access_watchpoint
:
9115 /* Watchpoint can be either on expression using entirely global variables,
9116 or it can be on local variables.
9118 Watchpoints of the first kind are never auto-deleted, and even persist
9119 across program restarts. Since they can use variables from shared
9120 libraries, we need to reparse expression as libraries are loaded
9123 Watchpoints on local variables can also change meaning as result
9124 of solib event. For example, if a watchpoint uses both a local and
9125 a global variables in expression, it's a local watchpoint, but
9126 unloading of a shared library will make the expression invalid.
9127 This is not a very common use case, but we still re-evaluate
9128 expression, to avoid surprises to the user.
9130 Note that for local watchpoints, we re-evaluate it only if
9131 watchpoints frame id is still valid. If it's not, it means
9132 the watchpoint is out of scope and will be deleted soon. In fact,
9133 I'm not sure we'll ever be called in this case.
9135 If a local watchpoint's frame id is still valid, then
9136 b->exp_valid_block is likewise valid, and we can safely use it.
9138 Don't do anything about disabled watchpoints, since they will
9139 be reevaluated again when enabled. */
9140 update_watchpoint (b
, 1 /* reparse */);
9142 /* We needn't really do anything to reset these, since the mask
9143 that requests them is unaffected by e.g., new libraries being
9149 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9151 /* Delete overlay event and longjmp master breakpoints; they will be
9152 reset later by breakpoint_re_set. */
9153 case bp_overlay_event
:
9154 case bp_longjmp_master
:
9155 delete_breakpoint (b
);
9158 /* This breakpoint is special, it's set up when the inferior
9159 starts and we really don't want to touch it. */
9160 case bp_shlib_event
:
9162 /* Like bp_shlib_event, this breakpoint type is special.
9163 Once it is set up, we do not want to touch it. */
9164 case bp_thread_event
:
9166 /* Keep temporary breakpoints, which can be encountered when we step
9167 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9168 Otherwise these should have been blown away via the cleanup chain
9169 or by breakpoint_init_inferior when we rerun the executable. */
9172 case bp_watchpoint_scope
:
9174 case bp_step_resume
:
9176 case bp_longjmp_resume
:
9181 do_cleanups (cleanups
);
9185 /* Re-set all breakpoints after symbols have been re-loaded. */
9187 breakpoint_re_set (void)
9189 struct breakpoint
*b
, *temp
;
9190 enum language save_language
;
9191 int save_input_radix
;
9192 struct cleanup
*old_chain
;
9194 save_language
= current_language
->la_language
;
9195 save_input_radix
= input_radix
;
9196 old_chain
= save_current_program_space ();
9198 ALL_BREAKPOINTS_SAFE (b
, temp
)
9200 /* Format possible error msg */
9201 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9203 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9204 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9205 do_cleanups (cleanups
);
9207 set_language (save_language
);
9208 input_radix
= save_input_radix
;
9210 jit_breakpoint_re_set ();
9212 do_cleanups (old_chain
);
9214 create_overlay_event_breakpoint ("_ovly_debug_event");
9215 create_longjmp_master_breakpoint ("longjmp");
9216 create_longjmp_master_breakpoint ("_longjmp");
9217 create_longjmp_master_breakpoint ("siglongjmp");
9218 create_longjmp_master_breakpoint ("_siglongjmp");
9221 /* Reset the thread number of this breakpoint:
9223 - If the breakpoint is for all threads, leave it as-is.
9224 - Else, reset it to the current thread for inferior_ptid. */
9226 breakpoint_re_set_thread (struct breakpoint
*b
)
9228 if (b
->thread
!= -1)
9230 if (in_thread_list (inferior_ptid
))
9231 b
->thread
= pid_to_thread_id (inferior_ptid
);
9233 /* We're being called after following a fork. The new fork is
9234 selected as current, and unless this was a vfork will have a
9235 different program space from the original thread. Reset that
9237 b
->loc
->pspace
= current_program_space
;
9241 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9242 If from_tty is nonzero, it prints a message to that effect,
9243 which ends with a period (no newline). */
9246 set_ignore_count (int bptnum
, int count
, int from_tty
)
9248 struct breakpoint
*b
;
9254 if (b
->number
== bptnum
)
9256 b
->ignore_count
= count
;
9260 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9262 else if (count
== 1)
9263 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9266 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9269 breakpoints_changed ();
9270 observer_notify_breakpoint_modified (b
->number
);
9274 error (_("No breakpoint number %d."), bptnum
);
9278 make_breakpoint_silent (struct breakpoint
*b
)
9280 /* Silence the breakpoint. */
9284 /* Command to set ignore-count of breakpoint N to COUNT. */
9287 ignore_command (char *args
, int from_tty
)
9293 error_no_arg (_("a breakpoint number"));
9295 num
= get_number (&p
);
9297 error (_("bad breakpoint number: '%s'"), args
);
9299 error (_("Second argument (specified ignore-count) is missing."));
9301 set_ignore_count (num
,
9302 longest_to_int (value_as_long (parse_and_eval (p
))),
9305 printf_filtered ("\n");
9308 /* Call FUNCTION on each of the breakpoints
9309 whose numbers are given in ARGS. */
9312 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
9317 struct breakpoint
*b
, *tmp
;
9321 error_no_arg (_("one or more breakpoint numbers"));
9328 num
= get_number_or_range (&p1
);
9331 warning (_("bad breakpoint number at or near '%s'"), p
);
9335 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9336 if (b
->number
== num
)
9338 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9341 if (related_breakpoint
)
9342 function (related_breakpoint
);
9346 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9352 static struct bp_location
*
9353 find_location_by_number (char *number
)
9355 char *dot
= strchr (number
, '.');
9359 struct breakpoint
*b
;
9360 struct bp_location
*loc
;
9365 bp_num
= get_number_or_range (&p1
);
9367 error (_("Bad breakpoint number '%s'"), number
);
9370 if (b
->number
== bp_num
)
9375 if (!b
|| b
->number
!= bp_num
)
9376 error (_("Bad breakpoint number '%s'"), number
);
9379 loc_num
= get_number_or_range (&p1
);
9381 error (_("Bad breakpoint location number '%s'"), number
);
9385 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9388 error (_("Bad breakpoint location number '%s'"), dot
+1);
9394 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9395 If from_tty is nonzero, it prints a message to that effect,
9396 which ends with a period (no newline). */
9399 disable_breakpoint (struct breakpoint
*bpt
)
9401 /* Never disable a watchpoint scope breakpoint; we want to
9402 hit them when we leave scope so we can delete both the
9403 watchpoint and its scope breakpoint at that time. */
9404 if (bpt
->type
== bp_watchpoint_scope
)
9407 /* You can't disable permanent breakpoints. */
9408 if (bpt
->enable_state
== bp_permanent
)
9411 bpt
->enable_state
= bp_disabled
;
9413 update_global_location_list (0);
9415 observer_notify_breakpoint_modified (bpt
->number
);
9419 disable_command (char *args
, int from_tty
)
9421 struct breakpoint
*bpt
;
9423 ALL_BREAKPOINTS (bpt
)
9427 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9432 case bp_fast_tracepoint
:
9434 case bp_hardware_breakpoint
:
9436 case bp_hardware_watchpoint
:
9437 case bp_read_watchpoint
:
9438 case bp_access_watchpoint
:
9439 disable_breakpoint (bpt
);
9443 else if (strchr (args
, '.'))
9445 struct bp_location
*loc
= find_location_by_number (args
);
9448 update_global_location_list (0);
9451 map_breakpoint_numbers (args
, disable_breakpoint
);
9455 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9457 int target_resources_ok
, other_type_used
;
9460 if (bpt
->type
== bp_hardware_breakpoint
)
9463 i
= hw_breakpoint_used_count ();
9464 target_resources_ok
=
9465 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9467 if (target_resources_ok
== 0)
9468 error (_("No hardware breakpoint support in the target."));
9469 else if (target_resources_ok
< 0)
9470 error (_("Hardware breakpoints used exceeds limit."));
9473 if (bpt
->type
== bp_watchpoint
9474 || bpt
->type
== bp_hardware_watchpoint
9475 || bpt
->type
== bp_read_watchpoint
9476 || bpt
->type
== bp_access_watchpoint
)
9478 struct gdb_exception e
;
9480 TRY_CATCH (e
, RETURN_MASK_ALL
)
9482 update_watchpoint (bpt
, 1 /* reparse */);
9486 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9492 if (bpt
->enable_state
!= bp_permanent
)
9493 bpt
->enable_state
= bp_enabled
;
9494 bpt
->disposition
= disposition
;
9495 update_global_location_list (1);
9496 breakpoints_changed ();
9498 observer_notify_breakpoint_modified (bpt
->number
);
9503 enable_breakpoint (struct breakpoint
*bpt
)
9505 do_enable_breakpoint (bpt
, bpt
->disposition
);
9508 /* The enable command enables the specified breakpoints (or all defined
9509 breakpoints) so they once again become (or continue to be) effective
9510 in stopping the inferior. */
9513 enable_command (char *args
, int from_tty
)
9515 struct breakpoint
*bpt
;
9517 ALL_BREAKPOINTS (bpt
)
9521 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
9526 case bp_fast_tracepoint
:
9528 case bp_hardware_breakpoint
:
9530 case bp_hardware_watchpoint
:
9531 case bp_read_watchpoint
:
9532 case bp_access_watchpoint
:
9533 enable_breakpoint (bpt
);
9537 else if (strchr (args
, '.'))
9539 struct bp_location
*loc
= find_location_by_number (args
);
9542 update_global_location_list (1);
9545 map_breakpoint_numbers (args
, enable_breakpoint
);
9549 enable_once_breakpoint (struct breakpoint
*bpt
)
9551 do_enable_breakpoint (bpt
, disp_disable
);
9555 enable_once_command (char *args
, int from_tty
)
9557 map_breakpoint_numbers (args
, enable_once_breakpoint
);
9561 enable_delete_breakpoint (struct breakpoint
*bpt
)
9563 do_enable_breakpoint (bpt
, disp_del
);
9567 enable_delete_command (char *args
, int from_tty
)
9569 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
9573 set_breakpoint_cmd (char *args
, int from_tty
)
9578 show_breakpoint_cmd (char *args
, int from_tty
)
9582 /* Invalidate last known value of any hardware watchpoint if
9583 the memory which that value represents has been written to by
9587 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
9588 const bfd_byte
*data
)
9590 struct breakpoint
*bp
;
9592 ALL_BREAKPOINTS (bp
)
9593 if (bp
->enable_state
== bp_enabled
9594 && bp
->type
== bp_hardware_watchpoint
9595 && bp
->val_valid
&& bp
->val
)
9597 struct bp_location
*loc
;
9599 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
9600 if (loc
->loc_type
== bp_loc_hardware_watchpoint
9601 && loc
->address
+ loc
->length
> addr
9602 && addr
+ len
> loc
->address
)
9604 value_free (bp
->val
);
9611 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
9613 struct symtabs_and_lines
9614 decode_line_spec_1 (char *string
, int funfirstline
)
9616 struct symtabs_and_lines sals
;
9618 error (_("Empty line specification."));
9619 if (default_breakpoint_valid
)
9620 sals
= decode_line_1 (&string
, funfirstline
,
9621 default_breakpoint_symtab
,
9622 default_breakpoint_line
,
9623 (char ***) NULL
, NULL
);
9625 sals
= decode_line_1 (&string
, funfirstline
,
9626 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
9628 error (_("Junk at end of line specification: %s"), string
);
9632 /* Create and insert a raw software breakpoint at PC. Return an
9633 identifier, which should be used to remove the breakpoint later.
9634 In general, places which call this should be using something on the
9635 breakpoint chain instead; this function should be eliminated
9639 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
9640 struct address_space
*aspace
, CORE_ADDR pc
)
9642 struct bp_target_info
*bp_tgt
;
9644 bp_tgt
= XZALLOC (struct bp_target_info
);
9646 bp_tgt
->placed_address_space
= aspace
;
9647 bp_tgt
->placed_address
= pc
;
9649 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
9651 /* Could not insert the breakpoint. */
9659 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
9662 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
9664 struct bp_target_info
*bp_tgt
= bp
;
9667 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
9673 /* One (or perhaps two) breakpoints used for software single stepping. */
9675 static void *single_step_breakpoints
[2];
9676 static struct gdbarch
*single_step_gdbarch
[2];
9678 /* Create and insert a breakpoint for software single step. */
9681 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
9682 struct address_space
*aspace
, CORE_ADDR next_pc
)
9686 if (single_step_breakpoints
[0] == NULL
)
9688 bpt_p
= &single_step_breakpoints
[0];
9689 single_step_gdbarch
[0] = gdbarch
;
9693 gdb_assert (single_step_breakpoints
[1] == NULL
);
9694 bpt_p
= &single_step_breakpoints
[1];
9695 single_step_gdbarch
[1] = gdbarch
;
9698 /* NOTE drow/2006-04-11: A future improvement to this function would be
9699 to only create the breakpoints once, and actually put them on the
9700 breakpoint chain. That would let us use set_raw_breakpoint. We could
9701 adjust the addresses each time they were needed. Doing this requires
9702 corresponding changes elsewhere where single step breakpoints are
9703 handled, however. So, for now, we use this. */
9705 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
9707 error (_("Could not insert single-step breakpoint at %s"),
9708 paddress (gdbarch
, next_pc
));
9711 /* Remove and delete any breakpoints used for software single step. */
9714 remove_single_step_breakpoints (void)
9716 gdb_assert (single_step_breakpoints
[0] != NULL
);
9718 /* See insert_single_step_breakpoint for more about this deprecated
9720 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
9721 single_step_breakpoints
[0]);
9722 single_step_gdbarch
[0] = NULL
;
9723 single_step_breakpoints
[0] = NULL
;
9725 if (single_step_breakpoints
[1] != NULL
)
9727 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
9728 single_step_breakpoints
[1]);
9729 single_step_gdbarch
[1] = NULL
;
9730 single_step_breakpoints
[1] = NULL
;
9734 /* Check whether a software single-step breakpoint is inserted at PC. */
9737 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
9741 for (i
= 0; i
< 2; i
++)
9743 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
9745 && breakpoint_address_match (bp_tgt
->placed_address_space
,
9746 bp_tgt
->placed_address
,
9754 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
9755 non-zero otherwise. */
9757 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
9759 if (syscall_catchpoint_p (bp
)
9760 && bp
->enable_state
!= bp_disabled
9761 && bp
->enable_state
!= bp_call_disabled
)
9768 catch_syscall_enabled (void)
9770 struct inferior
*inf
= current_inferior ();
9772 return inf
->total_syscalls_count
!= 0;
9776 catching_syscall_number (int syscall_number
)
9778 struct breakpoint
*bp
;
9780 ALL_BREAKPOINTS (bp
)
9781 if (is_syscall_catchpoint_enabled (bp
))
9783 if (bp
->syscalls_to_be_caught
)
9787 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
9789 if (syscall_number
== iter
)
9799 /* Complete syscall names. Used by "catch syscall". */
9801 catch_syscall_completer (struct cmd_list_element
*cmd
,
9802 char *text
, char *word
)
9804 const char **list
= get_syscall_names ();
9805 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
9808 /* Tracepoint-specific operations. */
9810 /* Set tracepoint count to NUM. */
9812 set_tracepoint_count (int num
)
9814 tracepoint_count
= num
;
9815 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
9819 trace_command (char *arg
, int from_tty
)
9821 break_command_really (get_current_arch (),
9823 NULL
, 0, 1 /* parse arg */,
9824 0 /* tempflag */, 0 /* hardwareflag */,
9826 0 /* Ignore count */,
9827 pending_break_support
,
9831 set_tracepoint_count (breakpoint_count
);
9835 ftrace_command (char *arg
, int from_tty
)
9837 break_command_really (get_current_arch (),
9839 NULL
, 0, 1 /* parse arg */,
9840 0 /* tempflag */, 1 /* hardwareflag */,
9842 0 /* Ignore count */,
9843 pending_break_support
,
9847 set_tracepoint_count (breakpoint_count
);
9850 /* Print information on tracepoint number TPNUM_EXP, or all if
9854 tracepoints_info (char *tpnum_exp
, int from_tty
)
9856 struct breakpoint
*b
;
9857 int tps_to_list
= 0;
9859 /* In the no-arguments case, say "No tracepoints" if none found. */
9872 ui_out_message (uiout
, 0, "No tracepoints.\n");
9877 /* Otherwise be the same as "info break". */
9878 breakpoints_info (tpnum_exp
, from_tty
);
9881 /* The 'enable trace' command enables tracepoints.
9882 Not supported by all targets. */
9884 enable_trace_command (char *args
, int from_tty
)
9886 enable_command (args
, from_tty
);
9889 /* The 'disable trace' command disables tracepoints.
9890 Not supported by all targets. */
9892 disable_trace_command (char *args
, int from_tty
)
9894 disable_command (args
, from_tty
);
9897 /* Remove a tracepoint (or all if no argument) */
9899 delete_trace_command (char *arg
, int from_tty
)
9901 struct breakpoint
*b
, *temp
;
9907 int breaks_to_delete
= 0;
9909 /* Delete all breakpoints if no argument.
9910 Do not delete internal or call-dummy breakpoints, these
9911 have to be deleted with an explicit breakpoint number argument. */
9916 breaks_to_delete
= 1;
9921 /* Ask user only if there are some breakpoints to delete. */
9923 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
9925 ALL_BREAKPOINTS_SAFE (b
, temp
)
9927 if (tracepoint_type (b
)
9929 delete_breakpoint (b
);
9934 map_breakpoint_numbers (arg
, delete_breakpoint
);
9937 /* Set passcount for tracepoint.
9939 First command argument is passcount, second is tracepoint number.
9940 If tracepoint number omitted, apply to most recently defined.
9941 Also accepts special argument "all". */
9944 trace_pass_command (char *args
, int from_tty
)
9946 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
9950 if (args
== 0 || *args
== 0)
9951 error (_("passcount command requires an argument (count + optional TP num)"));
9953 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
9955 while (*args
&& isspace ((int) *args
))
9958 if (*args
&& strncasecmp (args
, "all", 3) == 0)
9960 args
+= 3; /* Skip special argument "all". */
9963 error (_("Junk at end of arguments."));
9966 t1
= get_tracepoint_by_number (&args
, 1, 1);
9972 ALL_TRACEPOINTS (t2
)
9973 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
9975 t2
->pass_count
= count
;
9976 observer_notify_tracepoint_modified (t2
->number
);
9978 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
9982 t1
= get_tracepoint_by_number (&args
, 1, 0);
9989 get_tracepoint (int num
)
9991 struct breakpoint
*t
;
9994 if (t
->number
== num
)
10000 /* Utility: parse a tracepoint number and look it up in the list.
10001 If MULTI_P is true, there might be a range of tracepoints in ARG.
10002 if OPTIONAL_P is true, then if the argument is missing, the most
10003 recent tracepoint (tracepoint_count) is returned. */
10004 struct breakpoint
*
10005 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10007 extern int tracepoint_count
;
10008 struct breakpoint
*t
;
10010 char *instring
= arg
== NULL
? NULL
: *arg
;
10012 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10015 tpnum
= tracepoint_count
;
10017 error_no_arg (_("tracepoint number"));
10020 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10024 if (instring
&& *instring
)
10025 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10028 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10032 ALL_TRACEPOINTS (t
)
10033 if (t
->number
== tpnum
)
10038 /* FIXME: if we are in the middle of a range we don't want to give
10039 a message. The current interface to get_number_or_range doesn't
10040 allow us to discover this. */
10041 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10045 /* save-tracepoints command */
10047 tracepoint_save_command (char *args
, int from_tty
)
10049 struct breakpoint
*tp
;
10051 struct action_line
*line
;
10053 char *i1
= " ", *i2
= " ";
10054 char *indent
, *actionline
, *pathname
;
10056 struct cleanup
*cleanup
;
10058 if (args
== 0 || *args
== 0)
10059 error (_("Argument required (file name in which to save tracepoints)"));
10061 /* See if we have anything to save. */
10062 ALL_TRACEPOINTS (tp
)
10069 warning (_("save-tracepoints: no tracepoints to save."));
10073 pathname
= tilde_expand (args
);
10074 cleanup
= make_cleanup (xfree
, pathname
);
10075 fp
= fopen (pathname
, "w");
10077 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10078 args
, safe_strerror (errno
));
10079 make_cleanup_fclose (fp
);
10081 ALL_TRACEPOINTS (tp
)
10083 if (tp
->addr_string
)
10084 fprintf (fp
, "trace %s\n", tp
->addr_string
);
10087 sprintf_vma (tmp
, tp
->loc
->address
);
10088 fprintf (fp
, "trace *0x%s\n", tmp
);
10091 if (tp
->pass_count
)
10092 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
10096 fprintf (fp
, " actions\n");
10098 for (line
= tp
->actions
; line
; line
= line
->next
)
10100 struct cmd_list_element
*cmd
;
10102 QUIT
; /* allow user to bail out with ^C */
10103 actionline
= line
->action
;
10104 while (isspace ((int) *actionline
))
10107 fprintf (fp
, "%s%s\n", indent
, actionline
);
10108 if (*actionline
!= '#') /* skip for comment lines */
10110 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
10112 error (_("Bad action list item: %s"), actionline
);
10113 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
10115 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
10121 do_cleanups (cleanup
);
10123 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10127 /* Create a vector of all tracepoints. */
10129 VEC(breakpoint_p
) *
10132 VEC(breakpoint_p
) *tp_vec
= 0;
10133 struct breakpoint
*tp
;
10135 ALL_TRACEPOINTS (tp
)
10137 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10144 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10145 It is defined as a macro to prevent duplication.
10146 COMMAND should be a string constant containing the name of the command. */
10147 #define BREAK_ARGS_HELP(command) \
10148 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10149 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10150 If a line number is specified, break at start of code for that line.\n\
10151 If a function is specified, break at start of code for that function.\n\
10152 If an address is specified, break at that exact address.\n\
10153 With no LOCATION, uses current execution address of selected stack frame.\n\
10154 This is useful for breaking on return to a stack frame.\n\
10156 THREADNUM is the number from \"info threads\".\n\
10157 CONDITION is a boolean expression.\n\
10159 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10161 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10163 /* List of subcommands for "catch". */
10164 static struct cmd_list_element
*catch_cmdlist
;
10166 /* List of subcommands for "tcatch". */
10167 static struct cmd_list_element
*tcatch_cmdlist
;
10169 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10170 lists, and pass some additional user data to the command function. */
10172 add_catch_command (char *name
, char *docstring
,
10173 void (*sfunc
) (char *args
, int from_tty
,
10174 struct cmd_list_element
*command
),
10175 char **(*completer
) (struct cmd_list_element
*cmd
,
10176 char *text
, char *word
),
10177 void *user_data_catch
,
10178 void *user_data_tcatch
)
10180 struct cmd_list_element
*command
;
10182 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10184 set_cmd_sfunc (command
, sfunc
);
10185 set_cmd_context (command
, user_data_catch
);
10186 set_cmd_completer (command
, completer
);
10188 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10190 set_cmd_sfunc (command
, sfunc
);
10191 set_cmd_context (command
, user_data_tcatch
);
10192 set_cmd_completer (command
, completer
);
10196 clear_syscall_counts (int pid
)
10198 struct inferior
*inf
= find_inferior_pid (pid
);
10200 inf
->total_syscalls_count
= 0;
10201 inf
->any_syscall_count
= 0;
10202 VEC_free (int, inf
->syscalls_counts
);
10206 _initialize_breakpoint (void)
10208 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10209 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10210 struct cmd_list_element
*c
;
10212 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10213 observer_attach_inferior_exit (clear_syscall_counts
);
10214 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10216 breakpoint_chain
= 0;
10217 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10218 before a breakpoint is set. */
10219 breakpoint_count
= 0;
10221 tracepoint_count
= 0;
10223 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10224 Set ignore-count of breakpoint number N to COUNT.\n\
10225 Usage is `ignore N COUNT'."));
10227 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10229 add_com ("commands", class_breakpoint
, commands_command
, _("\
10230 Set commands to be executed when a breakpoint is hit.\n\
10231 Give breakpoint number as argument after \"commands\".\n\
10232 With no argument, the targeted breakpoint is the last one set.\n\
10233 The commands themselves follow starting on the next line.\n\
10234 Type a line containing \"end\" to indicate the end of them.\n\
10235 Give \"silent\" as the first line to make the breakpoint silent;\n\
10236 then no output is printed when it is hit, except what the commands print."));
10238 add_com ("condition", class_breakpoint
, condition_command
, _("\
10239 Specify breakpoint number N to break only if COND is true.\n\
10240 Usage is `condition N COND', where N is an integer and COND is an\n\
10241 expression to be evaluated whenever breakpoint N is reached."));
10243 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10244 Set a temporary breakpoint.\n\
10245 Like \"break\" except the breakpoint is only temporary,\n\
10246 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10247 by using \"enable delete\" on the breakpoint number.\n\
10249 BREAK_ARGS_HELP ("tbreak")));
10250 set_cmd_completer (c
, location_completer
);
10252 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10253 Set a hardware assisted breakpoint.\n\
10254 Like \"break\" except the breakpoint requires hardware support,\n\
10255 some target hardware may not have this support.\n\
10257 BREAK_ARGS_HELP ("hbreak")));
10258 set_cmd_completer (c
, location_completer
);
10260 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10261 Set a temporary hardware assisted breakpoint.\n\
10262 Like \"hbreak\" except the breakpoint is only temporary,\n\
10263 so it will be deleted when hit.\n\
10265 BREAK_ARGS_HELP ("thbreak")));
10266 set_cmd_completer (c
, location_completer
);
10268 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10269 Enable some breakpoints.\n\
10270 Give breakpoint numbers (separated by spaces) as arguments.\n\
10271 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10272 This is used to cancel the effect of the \"disable\" command.\n\
10273 With a subcommand you can enable temporarily."),
10274 &enablelist
, "enable ", 1, &cmdlist
);
10276 add_com ("ab", class_breakpoint
, enable_command
, _("\
10277 Enable some breakpoints.\n\
10278 Give breakpoint numbers (separated by spaces) as arguments.\n\
10279 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10280 This is used to cancel the effect of the \"disable\" command.\n\
10281 With a subcommand you can enable temporarily."));
10283 add_com_alias ("en", "enable", class_breakpoint
, 1);
10285 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10286 Enable some breakpoints.\n\
10287 Give breakpoint numbers (separated by spaces) as arguments.\n\
10288 This is used to cancel the effect of the \"disable\" command.\n\
10289 May be abbreviated to simply \"enable\".\n"),
10290 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10292 add_cmd ("once", no_class
, enable_once_command
, _("\
10293 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10294 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10297 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10298 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10299 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10302 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10303 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10304 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10307 add_cmd ("once", no_class
, enable_once_command
, _("\
10308 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10309 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10312 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10313 Disable some breakpoints.\n\
10314 Arguments are breakpoint numbers with spaces in between.\n\
10315 To disable all breakpoints, give no argument.\n\
10316 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10317 &disablelist
, "disable ", 1, &cmdlist
);
10318 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10319 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10321 add_com ("sb", class_breakpoint
, disable_command
, _("\
10322 Disable some breakpoints.\n\
10323 Arguments are breakpoint numbers with spaces in between.\n\
10324 To disable all breakpoints, give no argument.\n\
10325 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10327 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10328 Disable some breakpoints.\n\
10329 Arguments are breakpoint numbers with spaces in between.\n\
10330 To disable all breakpoints, give no argument.\n\
10331 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10332 This command may be abbreviated \"disable\"."),
10335 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10336 Delete some breakpoints or auto-display expressions.\n\
10337 Arguments are breakpoint numbers with spaces in between.\n\
10338 To delete all breakpoints, give no argument.\n\
10340 Also a prefix command for deletion of other GDB objects.\n\
10341 The \"unset\" command is also an alias for \"delete\"."),
10342 &deletelist
, "delete ", 1, &cmdlist
);
10343 add_com_alias ("d", "delete", class_breakpoint
, 1);
10344 add_com_alias ("del", "delete", class_breakpoint
, 1);
10346 add_com ("db", class_breakpoint
, delete_command
, _("\
10347 Delete some breakpoints.\n\
10348 Arguments are breakpoint numbers with spaces in between.\n\
10349 To delete all breakpoints, give no argument.\n"));
10351 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10352 Delete some breakpoints or auto-display expressions.\n\
10353 Arguments are breakpoint numbers with spaces in between.\n\
10354 To delete all breakpoints, give no argument.\n\
10355 This command may be abbreviated \"delete\"."),
10358 add_com ("clear", class_breakpoint
, clear_command
, _("\
10359 Clear breakpoint at specified line or function.\n\
10360 Argument may be line number, function name, or \"*\" and an address.\n\
10361 If line number is specified, all breakpoints in that line are cleared.\n\
10362 If function is specified, breakpoints at beginning of function are cleared.\n\
10363 If an address is specified, breakpoints at that address are cleared.\n\
10365 With no argument, clears all breakpoints in the line that the selected frame\n\
10366 is executing in.\n\
10368 See also the \"delete\" command which clears breakpoints by number."));
10370 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10371 Set breakpoint at specified line or function.\n"
10372 BREAK_ARGS_HELP ("break")));
10373 set_cmd_completer (c
, location_completer
);
10375 add_com_alias ("b", "break", class_run
, 1);
10376 add_com_alias ("br", "break", class_run
, 1);
10377 add_com_alias ("bre", "break", class_run
, 1);
10378 add_com_alias ("brea", "break", class_run
, 1);
10381 add_com_alias ("ba", "break", class_breakpoint
, 1);
10385 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10386 Break in function/address or break at a line in the current file."),
10387 &stoplist
, "stop ", 1, &cmdlist
);
10388 add_cmd ("in", class_breakpoint
, stopin_command
,
10389 _("Break in function or address."), &stoplist
);
10390 add_cmd ("at", class_breakpoint
, stopat_command
,
10391 _("Break at a line in the current file."), &stoplist
);
10392 add_com ("status", class_info
, breakpoints_info
, _("\
10393 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10394 The \"Type\" column indicates one of:\n\
10395 \tbreakpoint - normal breakpoint\n\
10396 \twatchpoint - watchpoint\n\
10397 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10398 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10399 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10400 address and file/line number respectively.\n\
10402 Convenience variable \"$_\" and default examine address for \"x\"\n\
10403 are set to the address of the last breakpoint listed unless the command\n\
10404 is prefixed with \"server \".\n\n\
10405 Convenience variable \"$bpnum\" contains the number of the last\n\
10406 breakpoint set."));
10409 add_info ("breakpoints", breakpoints_info
, _("\
10410 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10411 The \"Type\" column indicates one of:\n\
10412 \tbreakpoint - normal breakpoint\n\
10413 \twatchpoint - watchpoint\n\
10414 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10415 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10416 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10417 address and file/line number respectively.\n\
10419 Convenience variable \"$_\" and default examine address for \"x\"\n\
10420 are set to the address of the last breakpoint listed unless the command\n\
10421 is prefixed with \"server \".\n\n\
10422 Convenience variable \"$bpnum\" contains the number of the last\n\
10423 breakpoint set."));
10425 add_info_alias ("b", "breakpoints", 1);
10428 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
10429 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10430 The \"Type\" column indicates one of:\n\
10431 \tbreakpoint - normal breakpoint\n\
10432 \twatchpoint - watchpoint\n\
10433 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10434 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10435 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10436 address and file/line number respectively.\n\
10438 Convenience variable \"$_\" and default examine address for \"x\"\n\
10439 are set to the address of the last breakpoint listed unless the command\n\
10440 is prefixed with \"server \".\n\n\
10441 Convenience variable \"$bpnum\" contains the number of the last\n\
10442 breakpoint set."));
10444 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
10445 Status of all breakpoints, or breakpoint number NUMBER.\n\
10446 The \"Type\" column indicates one of:\n\
10447 \tbreakpoint - normal breakpoint\n\
10448 \twatchpoint - watchpoint\n\
10449 \tlongjmp - internal breakpoint used to step through longjmp()\n\
10450 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
10451 \tuntil - internal breakpoint used by the \"until\" command\n\
10452 \tfinish - internal breakpoint used by the \"finish\" command\n\
10453 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10454 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10455 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10456 address and file/line number respectively.\n\
10458 Convenience variable \"$_\" and default examine address for \"x\"\n\
10459 are set to the address of the last breakpoint listed unless the command\n\
10460 is prefixed with \"server \".\n\n\
10461 Convenience variable \"$bpnum\" contains the number of the last\n\
10463 &maintenanceinfolist
);
10465 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
10466 Set catchpoints to catch events."),
10467 &catch_cmdlist
, "catch ",
10468 0/*allow-unknown*/, &cmdlist
);
10470 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
10471 Set temporary catchpoints to catch events."),
10472 &tcatch_cmdlist
, "tcatch ",
10473 0/*allow-unknown*/, &cmdlist
);
10475 /* Add catch and tcatch sub-commands. */
10476 add_catch_command ("catch", _("\
10477 Catch an exception, when caught.\n\
10478 With an argument, catch only exceptions with the given name."),
10479 catch_catch_command
,
10483 add_catch_command ("throw", _("\
10484 Catch an exception, when thrown.\n\
10485 With an argument, catch only exceptions with the given name."),
10486 catch_throw_command
,
10490 add_catch_command ("fork", _("Catch calls to fork."),
10491 catch_fork_command_1
,
10493 (void *) (uintptr_t) catch_fork_permanent
,
10494 (void *) (uintptr_t) catch_fork_temporary
);
10495 add_catch_command ("vfork", _("Catch calls to vfork."),
10496 catch_fork_command_1
,
10498 (void *) (uintptr_t) catch_vfork_permanent
,
10499 (void *) (uintptr_t) catch_vfork_temporary
);
10500 add_catch_command ("exec", _("Catch calls to exec."),
10501 catch_exec_command_1
,
10505 add_catch_command ("syscall", _("\
10506 Catch system calls by their names and/or numbers.\n\
10507 Arguments say which system calls to catch. If no arguments\n\
10508 are given, every system call will be caught.\n\
10509 Arguments, if given, should be one or more system call names\n\
10510 (if your system supports that), or system call numbers."),
10511 catch_syscall_command_1
,
10512 catch_syscall_completer
,
10515 add_catch_command ("exception", _("\
10516 Catch Ada exceptions, when raised.\n\
10517 With an argument, catch only exceptions with the given name."),
10518 catch_ada_exception_command
,
10522 add_catch_command ("assert", _("\
10523 Catch failed Ada assertions, when raised.\n\
10524 With an argument, catch only exceptions with the given name."),
10525 catch_assert_command
,
10530 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
10531 Set a watchpoint for an expression.\n\
10532 A watchpoint stops execution of your program whenever the value of\n\
10533 an expression changes."));
10534 set_cmd_completer (c
, expression_completer
);
10536 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
10537 Set a read watchpoint for an expression.\n\
10538 A watchpoint stops execution of your program whenever the value of\n\
10539 an expression is read."));
10540 set_cmd_completer (c
, expression_completer
);
10542 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
10543 Set a watchpoint for an expression.\n\
10544 A watchpoint stops execution of your program whenever the value of\n\
10545 an expression is either read or written."));
10546 set_cmd_completer (c
, expression_completer
);
10548 add_info ("watchpoints", breakpoints_info
,
10549 _("Synonym for ``info breakpoints''."));
10552 /* XXX: cagney/2005-02-23: This should be a boolean, and should
10553 respond to changes - contrary to the description. */
10554 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
10555 &can_use_hw_watchpoints
, _("\
10556 Set debugger's willingness to use watchpoint hardware."), _("\
10557 Show debugger's willingness to use watchpoint hardware."), _("\
10558 If zero, gdb will not use hardware for new watchpoints, even if\n\
10559 such is available. (However, any hardware watchpoints that were\n\
10560 created before setting this to nonzero, will continue to use watchpoint\n\
10563 show_can_use_hw_watchpoints
,
10564 &setlist
, &showlist
);
10566 can_use_hw_watchpoints
= 1;
10568 /* Tracepoint manipulation commands. */
10570 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
10571 Set a tracepoint at specified line or function.\n\
10573 BREAK_ARGS_HELP ("trace") "\n\
10574 Do \"help tracepoints\" for info on other tracepoint commands."));
10575 set_cmd_completer (c
, location_completer
);
10577 add_com_alias ("tp", "trace", class_alias
, 0);
10578 add_com_alias ("tr", "trace", class_alias
, 1);
10579 add_com_alias ("tra", "trace", class_alias
, 1);
10580 add_com_alias ("trac", "trace", class_alias
, 1);
10582 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
10583 Set a fast tracepoint at specified line or function.\n\
10585 BREAK_ARGS_HELP ("ftrace") "\n\
10586 Do \"help tracepoints\" for info on other tracepoint commands."));
10587 set_cmd_completer (c
, location_completer
);
10589 add_info ("tracepoints", tracepoints_info
, _("\
10590 Status of tracepoints, or tracepoint number NUMBER.\n\
10591 Convenience variable \"$tpnum\" contains the number of the\n\
10592 last tracepoint set."));
10594 add_info_alias ("tp", "tracepoints", 1);
10596 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
10597 Delete specified tracepoints.\n\
10598 Arguments are tracepoint numbers, separated by spaces.\n\
10599 No argument means delete all tracepoints."),
10602 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
10603 Disable specified tracepoints.\n\
10604 Arguments are tracepoint numbers, separated by spaces.\n\
10605 No argument means disable all tracepoints."),
10607 deprecate_cmd (c
, "disable");
10609 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
10610 Enable specified tracepoints.\n\
10611 Arguments are tracepoint numbers, separated by spaces.\n\
10612 No argument means enable all tracepoints."),
10614 deprecate_cmd (c
, "enable");
10616 add_com ("passcount", class_trace
, trace_pass_command
, _("\
10617 Set the passcount for a tracepoint.\n\
10618 The trace will end when the tracepoint has been passed 'count' times.\n\
10619 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
10620 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
10622 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
10623 Save current tracepoint definitions as a script.\n\
10624 Use the 'source' command in another debug session to restore them."));
10625 set_cmd_completer (c
, filename_completer
);
10627 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
10628 Breakpoint specific settings\n\
10629 Configure various breakpoint-specific variables such as\n\
10630 pending breakpoint behavior"),
10631 &breakpoint_set_cmdlist
, "set breakpoint ",
10632 0/*allow-unknown*/, &setlist
);
10633 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
10634 Breakpoint specific settings\n\
10635 Configure various breakpoint-specific variables such as\n\
10636 pending breakpoint behavior"),
10637 &breakpoint_show_cmdlist
, "show breakpoint ",
10638 0/*allow-unknown*/, &showlist
);
10640 add_setshow_auto_boolean_cmd ("pending", no_class
,
10641 &pending_break_support
, _("\
10642 Set debugger's behavior regarding pending breakpoints."), _("\
10643 Show debugger's behavior regarding pending breakpoints."), _("\
10644 If on, an unrecognized breakpoint location will cause gdb to create a\n\
10645 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
10646 an error. If auto, an unrecognized breakpoint location results in a\n\
10647 user-query to see if a pending breakpoint should be created."),
10649 show_pending_break_support
,
10650 &breakpoint_set_cmdlist
,
10651 &breakpoint_show_cmdlist
);
10653 pending_break_support
= AUTO_BOOLEAN_AUTO
;
10655 add_setshow_boolean_cmd ("auto-hw", no_class
,
10656 &automatic_hardware_breakpoints
, _("\
10657 Set automatic usage of hardware breakpoints."), _("\
10658 Show automatic usage of hardware breakpoints."), _("\
10659 If set, the debugger will automatically use hardware breakpoints for\n\
10660 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
10661 a warning will be emitted for such breakpoints."),
10663 show_automatic_hardware_breakpoints
,
10664 &breakpoint_set_cmdlist
,
10665 &breakpoint_show_cmdlist
);
10667 add_setshow_enum_cmd ("always-inserted", class_support
,
10668 always_inserted_enums
, &always_inserted_mode
, _("\
10669 Set mode for inserting breakpoints."), _("\
10670 Show mode for inserting breakpoints."), _("\
10671 When this mode is off, breakpoints are inserted in inferior when it is\n\
10672 resumed, and removed when execution stops. When this mode is on,\n\
10673 breakpoints are inserted immediately and removed only when the user\n\
10674 deletes the breakpoint. When this mode is auto (which is the default),\n\
10675 the behaviour depends on the non-stop setting (see help set non-stop).\n\
10676 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
10677 behaves as if always-inserted mode is on; if gdb is controlling the\n\
10678 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
10680 &show_always_inserted_mode
,
10681 &breakpoint_set_cmdlist
,
10682 &breakpoint_show_cmdlist
);
10684 automatic_hardware_breakpoints
= 1;
10686 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);