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 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/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
60 #include "gdb-events.h"
61 #include "mi/mi-common.h"
63 #include "gdb_stdint.h"
65 /* Prototypes for local functions. */
67 static void until_break_command_continuation (struct continuation_arg
*arg
,
70 static void catch_command_1 (char *, int, int);
72 static void enable_delete_command (char *, int);
74 static void enable_delete_breakpoint (struct breakpoint
*);
76 static void enable_once_command (char *, int);
78 static void enable_once_breakpoint (struct breakpoint
*);
80 static void disable_command (char *, int);
82 static void enable_command (char *, int);
84 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
86 static void ignore_command (char *, int);
88 static int breakpoint_re_set_one (void *);
90 static void clear_command (char *, int);
92 static void catch_command (char *, int);
94 static void watch_command (char *, int);
96 static int can_use_hardware_watchpoint (struct value
*);
98 static void break_command_1 (char *, int, int);
100 static void mention (struct breakpoint
*);
102 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
104 static void check_duplicates (struct breakpoint
*);
106 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
108 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
111 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
113 static void breakpoints_info (char *, int);
115 static void breakpoint_1 (int, int);
117 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
119 static int breakpoint_cond_eval (void *);
121 static void cleanup_executing_breakpoints (void *);
123 static void commands_command (char *, int);
125 static void condition_command (char *, int);
127 static int get_number_trailer (char **, int);
129 void set_breakpoint_count (int);
138 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
140 static enum print_stop_action
print_it_typical (bpstat
);
142 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
146 enum exception_event_kind kind
;
149 args_for_catchpoint_enable
;
151 static int watchpoint_check (void *);
153 static void maintenance_info_breakpoints (char *, int);
155 static void create_longjmp_breakpoint (char *);
157 static void create_overlay_event_breakpoint (char *);
159 static int hw_breakpoint_used_count (void);
161 static int hw_watchpoint_used_count (enum bptype
, int *);
163 static void hbreak_command (char *, int);
165 static void thbreak_command (char *, int);
167 static void watch_command_1 (char *, int, int);
169 static void rwatch_command (char *, int);
171 static void awatch_command (char *, int);
173 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
175 static void create_fork_vfork_event_catchpoint (int tempflag
,
177 enum bptype bp_kind
);
179 static void stop_command (char *arg
, int from_tty
);
181 static void stopin_command (char *arg
, int from_tty
);
183 static void stopat_command (char *arg
, int from_tty
);
185 static char *ep_find_event_name_end (char *arg
);
187 static char *ep_parse_optional_if_clause (char **arg
);
189 static char *ep_parse_optional_filename (char **arg
);
191 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
192 enum exception_event_kind ex_event
,
193 struct symtab_and_line
*sal
);
195 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
196 char *arg
, int tempflag
, int from_tty
);
198 static void tcatch_command (char *arg
, int from_tty
);
200 static void ep_skip_leading_whitespace (char **s
);
202 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
204 static void free_bp_location (struct bp_location
*loc
);
206 static void mark_breakpoints_out (void);
208 static struct bp_location
*
209 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
211 static void update_global_location_list (void);
213 static void update_global_location_list_nothrow (void);
215 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
217 static void insert_breakpoint_locations (void);
220 bpdisp_text (enum bpdisp disp
)
222 /* NOTE: the following values are a part of MI protocol and represent
223 values of 'disp' field returned when inferior stops at a breakpoint. */
224 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
225 return bpdisps
[(int) disp
];
228 /* Prototypes for exported functions. */
229 /* If FALSE, gdb will not use hardware support for watchpoints, even
230 if such is available. */
231 static int can_use_hw_watchpoints
;
234 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
235 struct cmd_list_element
*c
,
238 fprintf_filtered (file
, _("\
239 Debugger's willingness to use watchpoint hardware is %s.\n"),
243 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
244 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
245 for unrecognized breakpoint locations.
246 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
247 static enum auto_boolean pending_break_support
;
249 show_pending_break_support (struct ui_file
*file
, int from_tty
,
250 struct cmd_list_element
*c
,
253 fprintf_filtered (file
, _("\
254 Debugger's behavior regarding pending breakpoints is %s.\n"),
258 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
259 set with "break" but falling in read-only memory.
260 If 0, gdb will warn about such breakpoints, but won't automatically
261 use hardware breakpoints. */
262 static int automatic_hardware_breakpoints
;
264 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
265 struct cmd_list_element
*c
,
268 fprintf_filtered (file
, _("\
269 Automatic usage of hardware breakpoints is %s.\n"),
273 /* If 1, gdb will keep breakpoints inserted even as inferior is stopped,
274 and immediately insert any new breakpoints. If 0, gdb will insert
275 breakpoints into inferior only when resuming it, and will remove
276 breakpoints upon stop. */
277 static int always_inserted_mode
= 0;
279 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
280 struct cmd_list_element
*c
, const char *value
)
282 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
286 void _initialize_breakpoint (void);
288 extern int addressprint
; /* Print machine addresses? */
290 /* Are we executing breakpoint commands? */
291 static int executing_breakpoint_commands
;
293 /* Are overlay event breakpoints enabled? */
294 static int overlay_events_enabled
;
296 /* Walk the following statement or block through all breakpoints.
297 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
300 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
302 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
303 for (B = breakpoint_chain; \
304 B ? (TMP=B->next, 1): 0; \
307 /* Similar iterators for the low-level breakpoints. */
309 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
311 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
312 for (B = bp_location_chain; \
313 B ? (TMP=B->global_next, 1): 0; \
316 /* True if breakpoint hit counts should be displayed in breakpoint info. */
318 int show_breakpoint_hit_counts
= 1;
320 /* Chains of all breakpoints defined. */
322 struct breakpoint
*breakpoint_chain
;
324 struct bp_location
*bp_location_chain
;
326 /* Number of last breakpoint made. */
328 int breakpoint_count
;
330 /* Pointer to current exception event record */
331 static struct exception_event_record
*current_exception_event
;
333 /* This function returns a pointer to the string representation of the
334 pathname of the dynamically-linked library that has just been
337 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
338 or undefined results are guaranteed.
340 This string's contents are only valid immediately after the
341 inferior has stopped in the dynamic linker hook, and becomes
342 invalid as soon as the inferior is continued. Clients should make
343 a copy of this string if they wish to continue the inferior and
344 then access the string. */
346 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
347 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
350 /* This function returns a pointer to the string representation of the
351 pathname of the dynamically-linked library that has just been
354 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
355 TRUE, or undefined results are guaranteed.
357 This string's contents are only valid immediately after the
358 inferior has stopped in the dynamic linker hook, and becomes
359 invalid as soon as the inferior is continued. Clients should make
360 a copy of this string if they wish to continue the inferior and
361 then access the string. */
363 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
364 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
367 /* This function is called by the "catch load" command. It allows the
368 debugger to be notified by the dynamic linker when a specified
369 library file (or any library file, if filename is NULL) is loaded. */
371 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
372 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
373 error (_("catch of library loads not yet implemented on this platform"))
376 /* This function is called by the "catch unload" command. It allows
377 the debugger to be notified by the dynamic linker when a specified
378 library file (or any library file, if filename is NULL) is
381 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
382 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
383 error (_("catch of library unloads not yet implemented on this platform"))
386 /* Return whether a breakpoint is an active enabled breakpoint. */
388 breakpoint_enabled (struct breakpoint
*b
)
390 return (b
->enable_state
== bp_enabled
);
393 /* Set breakpoint count to NUM. */
396 set_breakpoint_count (int num
)
398 breakpoint_count
= num
;
399 set_internalvar (lookup_internalvar ("bpnum"),
400 value_from_longest (builtin_type_int
, (LONGEST
) num
));
403 /* Used in run_command to zero the hit count when a new run starts. */
406 clear_breakpoint_hit_counts (void)
408 struct breakpoint
*b
;
414 /* Default address, symtab and line to put a breakpoint at
415 for "break" command with no arg.
416 if default_breakpoint_valid is zero, the other three are
417 not valid, and "break" with no arg is an error.
419 This set by print_stack_frame, which calls set_default_breakpoint. */
421 int default_breakpoint_valid
;
422 CORE_ADDR default_breakpoint_address
;
423 struct symtab
*default_breakpoint_symtab
;
424 int default_breakpoint_line
;
426 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
427 Advance *PP after the string and any trailing whitespace.
429 Currently the string can either be a number or "$" followed by the name
430 of a convenience variable. Making it an expression wouldn't work well
431 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
433 If the string is a NULL pointer, that denotes the last breakpoint.
435 TRAILER is a character which can be found after the number; most
436 commonly this is `-'. If you don't want a trailer, use \0. */
438 get_number_trailer (char **pp
, int trailer
)
440 int retval
= 0; /* default */
444 /* Empty line means refer to the last breakpoint. */
445 return breakpoint_count
;
448 /* Make a copy of the name, so we can null-terminate it
449 to pass to lookup_internalvar(). */
454 while (isalnum (*p
) || *p
== '_')
456 varname
= (char *) alloca (p
- start
+ 1);
457 strncpy (varname
, start
, p
- start
);
458 varname
[p
- start
] = '\0';
459 val
= value_of_internalvar (lookup_internalvar (varname
));
460 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
461 retval
= (int) value_as_long (val
);
464 printf_filtered (_("Convenience variable must have integer value.\n"));
472 while (*p
>= '0' && *p
<= '9')
475 /* There is no number here. (e.g. "cond a == b"). */
477 /* Skip non-numeric token */
478 while (*p
&& !isspace((int) *p
))
480 /* Return zero, which caller must interpret as error. */
486 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
488 /* Trailing junk: return 0 and let caller print error msg. */
489 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
500 /* Like get_number_trailer, but don't allow a trailer. */
502 get_number (char **pp
)
504 return get_number_trailer (pp
, '\0');
507 /* Parse a number or a range.
508 * A number will be of the form handled by get_number.
509 * A range will be of the form <number1> - <number2>, and
510 * will represent all the integers between number1 and number2,
513 * While processing a range, this fuction is called iteratively;
514 * At each call it will return the next value in the range.
516 * At the beginning of parsing a range, the char pointer PP will
517 * be advanced past <number1> and left pointing at the '-' token.
518 * Subsequent calls will not advance the pointer until the range
519 * is completed. The call that completes the range will advance
520 * pointer PP past <number2>.
524 get_number_or_range (char **pp
)
526 static int last_retval
, end_value
;
527 static char *end_ptr
;
528 static int in_range
= 0;
532 /* Default case: pp is pointing either to a solo number,
533 or to the first number of a range. */
534 last_retval
= get_number_trailer (pp
, '-');
539 /* This is the start of a range (<number1> - <number2>).
540 Skip the '-', parse and remember the second number,
541 and also remember the end of the final token. */
545 while (isspace ((int) *end_ptr
))
546 end_ptr
++; /* skip white space */
547 end_value
= get_number (temp
);
548 if (end_value
< last_retval
)
550 error (_("inverted range"));
552 else if (end_value
== last_retval
)
554 /* degenerate range (number1 == number2). Advance the
555 token pointer so that the range will be treated as a
564 error (_("negative value"));
567 /* pp points to the '-' that betokens a range. All
568 number-parsing has already been done. Return the next
569 integer value (one greater than the saved previous value).
570 Do not advance the token pointer 'pp' until the end of range
573 if (++last_retval
== end_value
)
575 /* End of range reached; advance token pointer. */
585 /* condition N EXP -- set break condition of breakpoint N to EXP. */
588 condition_command (char *arg
, int from_tty
)
590 struct breakpoint
*b
;
595 error_no_arg (_("breakpoint number"));
598 bnum
= get_number (&p
);
600 error (_("Bad breakpoint argument: '%s'"), arg
);
603 if (b
->number
== bnum
)
605 struct bp_location
*loc
= b
->loc
;
606 for (; loc
; loc
= loc
->next
)
614 if (b
->cond_string
!= NULL
)
615 xfree (b
->cond_string
);
619 b
->cond_string
= NULL
;
621 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
626 /* I don't know if it matters whether this is the string the user
627 typed in or the decompiled expression. */
628 b
->cond_string
= savestring (arg
, strlen (arg
));
629 b
->condition_not_parsed
= 0;
630 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
634 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
636 error (_("Junk at end of expression"));
639 breakpoints_changed ();
640 breakpoint_modify_event (b
->number
);
644 error (_("No breakpoint number %d."), bnum
);
648 commands_command (char *arg
, int from_tty
)
650 struct breakpoint
*b
;
653 struct command_line
*l
;
655 /* If we allowed this, we would have problems with when to
656 free the storage, if we change the commands currently
659 if (executing_breakpoint_commands
)
660 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
663 bnum
= get_number (&p
);
666 error (_("Unexpected extra arguments following breakpoint number."));
669 if (b
->number
== bnum
)
671 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
673 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
674 l
= read_command_lines (tmpbuf
, from_tty
);
675 do_cleanups (cleanups
);
676 free_command_lines (&b
->commands
);
678 breakpoints_changed ();
679 breakpoint_modify_event (b
->number
);
682 error (_("No breakpoint number %d."), bnum
);
685 /* Like commands_command, but instead of reading the commands from
686 input stream, takes them from an already parsed command structure.
688 This is used by cli-script.c to DTRT with breakpoint commands
689 that are part of if and while bodies. */
690 enum command_control_type
691 commands_from_control_command (char *arg
, struct command_line
*cmd
)
693 struct breakpoint
*b
;
697 /* If we allowed this, we would have problems with when to
698 free the storage, if we change the commands currently
701 if (executing_breakpoint_commands
)
702 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
704 /* An empty string for the breakpoint number means the last
705 breakpoint, but get_number expects a NULL pointer. */
710 bnum
= get_number (&p
);
713 error (_("Unexpected extra arguments following breakpoint number."));
716 if (b
->number
== bnum
)
718 free_command_lines (&b
->commands
);
719 if (cmd
->body_count
!= 1)
720 error (_("Invalid \"commands\" block structure."));
721 /* We need to copy the commands because if/while will free the
722 list after it finishes execution. */
723 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
724 breakpoints_changed ();
725 breakpoint_modify_event (b
->number
);
726 return simple_control
;
728 error (_("No breakpoint number %d."), bnum
);
731 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
732 by replacing any memory breakpoints with their shadowed contents. */
735 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
737 struct bp_location
*b
;
738 CORE_ADDR bp_addr
= 0;
744 if (b
->owner
->type
== bp_none
)
745 warning (_("reading through apparently deleted breakpoint #%d?"),
748 if (b
->loc_type
!= bp_loc_software_breakpoint
)
752 /* Addresses and length of the part of the breakpoint that
754 bp_addr
= b
->target_info
.placed_address
;
755 bp_size
= b
->target_info
.shadow_len
;
757 /* bp isn't valid, or doesn't shadow memory. */
760 if (bp_addr
+ bp_size
<= memaddr
)
761 /* The breakpoint is entirely before the chunk of memory we
765 if (bp_addr
>= memaddr
+ len
)
766 /* The breakpoint is entirely after the chunk of memory we are
770 /* Offset within shadow_contents. */
771 if (bp_addr
< memaddr
)
773 /* Only copy the second part of the breakpoint. */
774 bp_size
-= memaddr
- bp_addr
;
775 bptoffset
= memaddr
- bp_addr
;
779 if (bp_addr
+ bp_size
> memaddr
+ len
)
781 /* Only copy the first part of the breakpoint. */
782 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
785 memcpy (buf
+ bp_addr
- memaddr
,
786 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
791 /* A wrapper function for inserting catchpoints. */
793 insert_catchpoint (struct ui_out
*uo
, void *args
)
795 struct breakpoint
*b
= (struct breakpoint
*) args
;
801 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
804 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
807 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
810 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
816 is_hardware_watchpoint (struct breakpoint
*bpt
)
818 return (bpt
->type
== bp_hardware_watchpoint
819 || bpt
->type
== bp_read_watchpoint
820 || bpt
->type
== bp_access_watchpoint
);
823 /* Find the current value of a watchpoint on EXP. Return the value in
824 *VALP and *RESULTP and the chain of intermediate and final values
825 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
828 If an error occurs while evaluating the expression, *RESULTP will
829 be set to NULL. *RESULTP may be a lazy value, if the result could
830 not be read from memory. It is used to determine whether a value
831 is user-specified (we should watch the whole value) or intermediate
832 (we should watch only the bit used to locate the final value).
834 If the final value, or any intermediate value, could not be read
835 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
836 set to any referenced values. *VALP will never be a lazy value.
837 This is the value which we store in struct breakpoint.
839 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
840 value chain. The caller must free the values individually. If
841 VAL_CHAIN is NULL, all generated values will be left on the value
845 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
846 struct value
**resultp
, struct value
**val_chain
)
848 struct value
*mark
, *new_mark
, *result
;
856 /* Evaluate the expression. */
857 mark
= value_mark ();
859 gdb_evaluate_expression (exp
, &result
);
860 new_mark
= value_mark ();
861 if (mark
== new_mark
)
866 /* Make sure it's not lazy, so that after the target stops again we
867 have a non-lazy previous value to compare with. */
869 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
874 /* Return the chain of intermediate values. We use this to
875 decide which addresses to watch. */
876 *val_chain
= new_mark
;
877 value_release_to_mark (mark
);
881 /* Assuming that B is a hardware watchpoint:
882 - Reparse watchpoint expression, is REPARSE is non-zero
883 - Evaluate expression and store the result in B->val
884 - Update the list of values that must be watched in B->loc.
886 If the watchpoint is disabled, do nothing. If this is
887 local watchpoint that is out of scope, delete it. */
889 update_watchpoint (struct breakpoint
*b
, int reparse
)
891 int within_current_scope
;
892 struct frame_id saved_frame_id
;
893 struct bp_location
*loc
;
896 /* We don't free locations. They are stored in
897 bp_location_chain and update_global_locations will
898 eventually delete them and remove breakpoints if
902 if (b
->disposition
== disp_del_at_next_stop
)
905 /* Save the current frame's ID so we can restore it after
906 evaluating the watchpoint expression on its own frame. */
907 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
908 took a frame parameter, so that we didn't have to change the
910 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
912 /* Determine if the watchpoint is within scope. */
913 if (b
->exp_valid_block
== NULL
)
914 within_current_scope
= 1;
917 struct frame_info
*fi
;
918 fi
= frame_find_by_id (b
->watchpoint_frame
);
919 within_current_scope
= (fi
!= NULL
);
920 if (within_current_scope
)
924 if (within_current_scope
&& reparse
)
933 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
934 /* If the meaning of expression itself changed, the old value is
935 no longer relevant. We don't want to report a watchpoint hit
936 to the user when the old value and the new value may actually
937 be completely different objects. */
943 /* If we failed to parse the expression, for example because
944 it refers to a global variable in a not-yet-loaded shared library,
945 don't try to insert watchpoint. We don't automatically delete
946 such watchpoint, though, since failure to parse expression
947 is different from out-of-scope watchpoint. */
948 if (within_current_scope
&& b
->exp
)
950 struct value
*val_chain
, *v
, *result
, *next
;
952 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
954 /* Avoid setting b->val if it's already set. The meaning of
955 b->val is 'the last value' user saw, and we should update
956 it only if we reported that last value to user. As it
957 happens, the code that reports it updates b->val directly. */
964 /* Look at each value on the value chain. */
965 for (v
= val_chain
; v
; v
= next
)
967 /* If it's a memory location, and GDB actually needed
968 its contents to evaluate the expression, then we
969 must watch it. If the first value returned is
970 still lazy, that means an error occurred reading it;
971 watch it anyway in case it becomes readable. */
972 if (VALUE_LVAL (v
) == lval_memory
973 && (v
== val_chain
|| ! value_lazy (v
)))
975 struct type
*vtype
= check_typedef (value_type (v
));
977 /* We only watch structs and arrays if user asked
978 for it explicitly, never if they just happen to
979 appear in the middle of some value chain. */
981 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
982 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
986 struct bp_location
*loc
, **tmp
;
988 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
989 len
= TYPE_LENGTH (value_type (v
));
991 if (b
->type
== bp_read_watchpoint
)
993 else if (b
->type
== bp_access_watchpoint
)
996 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
997 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1000 loc
->address
= addr
;
1002 loc
->watchpoint_type
= type
;
1006 next
= value_next (v
);
1011 /* We just regenerated the list of breakpoint locations.
1012 The new location does not have its condition field set to anything
1013 and therefore, we must always reparse the cond_string, independently
1014 of the value of the reparse flag. */
1015 if (b
->cond_string
!= NULL
)
1017 char *s
= b
->cond_string
;
1018 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1021 else if (!within_current_scope
)
1023 printf_filtered (_("\
1024 Hardware watchpoint %d deleted because the program has left the block \n\
1025 in which its expression is valid.\n"),
1027 if (b
->related_breakpoint
)
1028 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1029 b
->disposition
= disp_del_at_next_stop
;
1032 /* Restore the selected frame. */
1033 select_frame (frame_find_by_id (saved_frame_id
));
1037 /* Returns 1 iff breakpoint location should be
1038 inserted in the inferior. */
1040 should_be_inserted (struct bp_location
*bpt
)
1042 if (!breakpoint_enabled (bpt
->owner
))
1045 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1048 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1054 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1055 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1056 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1058 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1059 method for each breakpoint or catchpoint type. */
1061 insert_bp_location (struct bp_location
*bpt
,
1062 struct ui_file
*tmp_error_stream
,
1063 int *disabled_breaks
, int *process_warning
,
1064 int *hw_breakpoint_error
)
1068 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1071 /* Initialize the target-specific information. */
1072 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1073 bpt
->target_info
.placed_address
= bpt
->address
;
1075 if (bpt
->loc_type
== bp_loc_software_breakpoint
1076 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1078 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1080 /* If the explicitly specified breakpoint type
1081 is not hardware breakpoint, check the memory map to see
1082 if the breakpoint address is in read only memory or not.
1083 Two important cases are:
1084 - location type is not hardware breakpoint, memory
1085 is readonly. We change the type of the location to
1086 hardware breakpoint.
1087 - location type is hardware breakpoint, memory is read-write.
1088 This means we've previously made the location hardware one, but
1089 then the memory map changed, so we undo.
1091 When breakpoints are removed, remove_breakpoints will
1092 use location types we've just set here, the only possible
1093 problem is that memory map has changed during running program,
1094 but it's not going to work anyway with current gdb. */
1095 struct mem_region
*mr
1096 = lookup_mem_region (bpt
->target_info
.placed_address
);
1100 if (automatic_hardware_breakpoints
)
1103 enum bp_loc_type new_type
;
1105 if (mr
->attrib
.mode
!= MEM_RW
)
1106 new_type
= bp_loc_hardware_breakpoint
;
1108 new_type
= bp_loc_software_breakpoint
;
1110 if (new_type
!= bpt
->loc_type
)
1112 static int said
= 0;
1113 bpt
->loc_type
= new_type
;
1116 fprintf_filtered (gdb_stdout
, _("\
1117 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1122 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1123 && mr
->attrib
.mode
!= MEM_RW
)
1124 warning (_("cannot set software breakpoint at readonly address %s"),
1125 paddr (bpt
->address
));
1129 /* First check to see if we have to handle an overlay. */
1130 if (overlay_debugging
== ovly_off
1131 || bpt
->section
== NULL
1132 || !(section_is_overlay (bpt
->section
)))
1134 /* No overlay handling: just set the breakpoint. */
1136 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1137 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1139 val
= target_insert_breakpoint (&bpt
->target_info
);
1143 /* This breakpoint is in an overlay section.
1144 Shall we set a breakpoint at the LMA? */
1145 if (!overlay_events_enabled
)
1147 /* Yes -- overlay event support is not active,
1148 so we must try to set a breakpoint at the LMA.
1149 This will not work for a hardware breakpoint. */
1150 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1151 warning (_("hardware breakpoint %d not supported in overlay!"),
1152 bpt
->owner
->number
);
1155 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1157 /* Set a software (trap) breakpoint at the LMA. */
1158 bpt
->overlay_target_info
= bpt
->target_info
;
1159 bpt
->overlay_target_info
.placed_address
= addr
;
1160 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1162 fprintf_unfiltered (tmp_error_stream
,
1163 "Overlay breakpoint %d failed: in ROM?",
1164 bpt
->owner
->number
);
1167 /* Shall we set a breakpoint at the VMA? */
1168 if (section_is_mapped (bpt
->section
))
1170 /* Yes. This overlay section is mapped into memory. */
1171 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1172 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1174 val
= target_insert_breakpoint (&bpt
->target_info
);
1178 /* No. This breakpoint will not be inserted.
1179 No error, but do not mark the bp as 'inserted'. */
1186 /* Can't set the breakpoint. */
1187 if (solib_address (bpt
->address
))
1189 /* See also: disable_breakpoints_in_shlibs. */
1191 bpt
->shlib_disabled
= 1;
1192 if (!*disabled_breaks
)
1194 fprintf_unfiltered (tmp_error_stream
,
1195 "Cannot insert breakpoint %d.\n",
1196 bpt
->owner
->number
);
1197 fprintf_unfiltered (tmp_error_stream
,
1198 "Temporarily disabling shared library breakpoints:\n");
1200 *disabled_breaks
= 1;
1201 fprintf_unfiltered (tmp_error_stream
,
1202 "breakpoint #%d\n", bpt
->owner
->number
);
1206 #ifdef ONE_PROCESS_WRITETEXT
1207 *process_warning
= 1;
1209 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1211 *hw_breakpoint_error
= 1;
1212 fprintf_unfiltered (tmp_error_stream
,
1213 "Cannot insert hardware breakpoint %d.\n",
1214 bpt
->owner
->number
);
1218 fprintf_unfiltered (tmp_error_stream
,
1219 "Cannot insert breakpoint %d.\n",
1220 bpt
->owner
->number
);
1221 fprintf_filtered (tmp_error_stream
,
1222 "Error accessing memory address ");
1223 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1224 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1225 safe_strerror (val
));
1236 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1237 /* NOTE drow/2003-09-08: This state only exists for removing
1238 watchpoints. It's not clear that it's necessary... */
1239 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1241 val
= target_insert_watchpoint (bpt
->address
,
1243 bpt
->watchpoint_type
);
1244 bpt
->inserted
= (val
!= -1);
1247 else if (bpt
->owner
->type
== bp_catch_fork
1248 || bpt
->owner
->type
== bp_catch_vfork
1249 || bpt
->owner
->type
== bp_catch_exec
)
1251 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1252 bpt
->owner
, RETURN_MASK_ERROR
);
1253 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1254 bpt
->owner
->number
);
1256 bpt
->owner
->enable_state
= bp_disabled
;
1260 /* We've already printed an error message if there was a problem
1261 inserting this catchpoint, and we've disabled the catchpoint,
1262 so just return success. */
1269 /* Make sure all breakpoints are inserted in inferior.
1270 Throws exception on any error.
1271 A breakpoint that is already inserted won't be inserted
1272 again, so calling this function twice is safe. */
1274 insert_breakpoints (void)
1276 struct breakpoint
*bpt
;
1278 ALL_BREAKPOINTS (bpt
)
1279 if (is_hardware_watchpoint (bpt
))
1280 update_watchpoint (bpt
, 0 /* don't reparse. */);
1282 update_global_location_list ();
1284 if (!always_inserted_mode
&& target_has_execution
)
1285 /* update_global_location_list does not insert breakpoints
1286 when always_inserted_mode is not enabled. Explicitly
1288 insert_breakpoint_locations ();
1291 /* insert_breakpoints is used when starting or continuing the program.
1292 remove_breakpoints is used when the program stops.
1293 Both return zero if successful,
1294 or an `errno' value if could not write the inferior. */
1297 insert_breakpoint_locations (void)
1299 struct breakpoint
*bpt
;
1300 struct bp_location
*b
, *temp
;
1303 int disabled_breaks
= 0;
1304 int hw_breakpoint_error
= 0;
1305 int process_warning
= 0;
1307 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1308 make_cleanup_ui_file_delete (tmp_error_stream
);
1310 /* Explicitly mark the warning -- this will only be printed if
1311 there was an error. */
1312 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1314 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1316 if (!should_be_inserted (b
) || b
->inserted
)
1319 /* There is no point inserting thread-specific breakpoints if the
1320 thread no longer exists. */
1321 if (b
->owner
->thread
!= -1
1322 && !valid_thread_id (b
->owner
->thread
))
1325 val
= insert_bp_location (b
, tmp_error_stream
,
1326 &disabled_breaks
, &process_warning
,
1327 &hw_breakpoint_error
);
1332 /* If we failed to insert all locations of a watchpoint,
1333 remove them, as half-inserted watchpoint is of limited use. */
1334 ALL_BREAKPOINTS (bpt
)
1336 int some_failed
= 0;
1337 struct bp_location
*loc
;
1339 if (!is_hardware_watchpoint (bpt
))
1342 if (bpt
->enable_state
!= bp_enabled
)
1345 if (bpt
->disposition
== disp_del_at_next_stop
)
1348 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1356 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1358 remove_breakpoint (loc
, mark_uninserted
);
1360 hw_breakpoint_error
= 1;
1361 fprintf_unfiltered (tmp_error_stream
,
1362 "Could not insert hardware watchpoint %d.\n",
1370 /* If a hardware breakpoint or watchpoint was inserted, add a
1371 message about possibly exhausted resources. */
1372 if (hw_breakpoint_error
)
1374 fprintf_unfiltered (tmp_error_stream
,
1375 "Could not insert hardware breakpoints:\n\
1376 You may have requested too many hardware breakpoints/watchpoints.\n");
1378 #ifdef ONE_PROCESS_WRITETEXT
1379 if (process_warning
)
1380 fprintf_unfiltered (tmp_error_stream
,
1381 "The same program may be running in another process.");
1383 target_terminal_ours_for_output ();
1384 error_stream (tmp_error_stream
);
1389 remove_breakpoints (void)
1391 struct bp_location
*b
;
1394 ALL_BP_LOCATIONS (b
)
1398 val
= remove_breakpoint (b
, mark_uninserted
);
1407 remove_hw_watchpoints (void)
1409 struct bp_location
*b
;
1412 ALL_BP_LOCATIONS (b
)
1414 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1416 val
= remove_breakpoint (b
, mark_uninserted
);
1425 reattach_breakpoints (int pid
)
1427 struct bp_location
*b
;
1429 struct cleanup
*old_chain
= save_inferior_ptid ();
1430 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1431 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1433 make_cleanup_ui_file_delete (tmp_error_stream
);
1435 inferior_ptid
= pid_to_ptid (pid
);
1436 ALL_BP_LOCATIONS (b
)
1441 val
= insert_bp_location (b
, tmp_error_stream
,
1442 &dummy1
, &dummy2
, &dummy3
);
1445 do_cleanups (old_chain
);
1450 do_cleanups (old_chain
);
1455 restore_always_inserted_mode (void *p
)
1457 always_inserted_mode
= (uintptr_t) p
;
1461 update_breakpoints_after_exec (void)
1463 struct breakpoint
*b
;
1464 struct breakpoint
*temp
;
1465 struct cleanup
*cleanup
;
1467 /* Doing this first prevents the badness of having delete_breakpoint()
1468 write a breakpoint's current "shadow contents" to lift the bp. That
1469 shadow is NOT valid after an exec()! */
1470 mark_breakpoints_out ();
1472 /* The binary we used to debug is now gone, and we're updating
1473 breakpoints for the new binary. Until we're done, we should not
1474 try to insert breakpoints. */
1475 cleanup
= make_cleanup (restore_always_inserted_mode
,
1476 (void *) (uintptr_t) always_inserted_mode
);
1477 always_inserted_mode
= 0;
1479 ALL_BREAKPOINTS_SAFE (b
, temp
)
1481 /* Solib breakpoints must be explicitly reset after an exec(). */
1482 if (b
->type
== bp_shlib_event
)
1484 delete_breakpoint (b
);
1488 /* Thread event breakpoints must be set anew after an exec(),
1489 as must overlay event breakpoints. */
1490 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1492 delete_breakpoint (b
);
1496 /* Step-resume breakpoints are meaningless after an exec(). */
1497 if (b
->type
== bp_step_resume
)
1499 delete_breakpoint (b
);
1503 /* Don't delete an exec catchpoint, because else the inferior
1504 won't stop when it ought!
1506 Similarly, we probably ought to keep vfork catchpoints, 'cause
1507 on this target, we may not be able to stop when the vfork is
1508 seen, but only when the subsequent exec is seen. (And because
1509 deleting fork catchpoints here but not vfork catchpoints will
1510 seem mysterious to users, keep those too.) */
1511 if ((b
->type
== bp_catch_exec
) ||
1512 (b
->type
== bp_catch_vfork
) ||
1513 (b
->type
== bp_catch_fork
))
1518 /* bp_finish is a special case. The only way we ought to be able
1519 to see one of these when an exec() has happened, is if the user
1520 caught a vfork, and then said "finish". Ordinarily a finish just
1521 carries them to the call-site of the current callee, by setting
1522 a temporary bp there and resuming. But in this case, the finish
1523 will carry them entirely through the vfork & exec.
1525 We don't want to allow a bp_finish to remain inserted now. But
1526 we can't safely delete it, 'cause finish_command has a handle to
1527 the bp on a bpstat, and will later want to delete it. There's a
1528 chance (and I've seen it happen) that if we delete the bp_finish
1529 here, that its storage will get reused by the time finish_command
1530 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1531 We really must allow finish_command to delete a bp_finish.
1533 In the absense of a general solution for the "how do we know
1534 it's safe to delete something others may have handles to?"
1535 problem, what we'll do here is just uninsert the bp_finish, and
1536 let finish_command delete it.
1538 (We know the bp_finish is "doomed" in the sense that it's
1539 momentary, and will be deleted as soon as finish_command sees
1540 the inferior stopped. So it doesn't matter that the bp's
1541 address is probably bogus in the new a.out, unlike e.g., the
1542 solib breakpoints.) */
1544 if (b
->type
== bp_finish
)
1549 /* Without a symbolic address, we have little hope of the
1550 pre-exec() address meaning the same thing in the post-exec()
1552 if (b
->addr_string
== NULL
)
1554 delete_breakpoint (b
);
1558 /* FIXME what about longjmp breakpoints? Re-create them here? */
1559 create_overlay_event_breakpoint ("_ovly_debug_event");
1560 do_cleanups (cleanup
);
1564 detach_breakpoints (int pid
)
1566 struct bp_location
*b
;
1568 struct cleanup
*old_chain
= save_inferior_ptid ();
1570 if (pid
== PIDGET (inferior_ptid
))
1571 error (_("Cannot detach breakpoints of inferior_ptid"));
1573 /* Set inferior_ptid; remove_breakpoint uses this global. */
1574 inferior_ptid
= pid_to_ptid (pid
);
1575 ALL_BP_LOCATIONS (b
)
1579 val
= remove_breakpoint (b
, mark_inserted
);
1582 do_cleanups (old_chain
);
1587 do_cleanups (old_chain
);
1592 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1596 if (b
->owner
->enable_state
== bp_permanent
)
1597 /* Permanent breakpoints cannot be inserted or removed. */
1600 /* The type of none suggests that owner is actually deleted.
1601 This should not ever happen. */
1602 gdb_assert (b
->owner
->type
!= bp_none
);
1604 if (b
->loc_type
== bp_loc_software_breakpoint
1605 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1607 /* "Normal" instruction breakpoint: either the standard
1608 trap-instruction bp (bp_breakpoint), or a
1609 bp_hardware_breakpoint. */
1611 /* First check to see if we have to handle an overlay. */
1612 if (overlay_debugging
== ovly_off
1613 || b
->section
== NULL
1614 || !(section_is_overlay (b
->section
)))
1616 /* No overlay handling: just remove the breakpoint. */
1618 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1619 val
= target_remove_hw_breakpoint (&b
->target_info
);
1621 val
= target_remove_breakpoint (&b
->target_info
);
1625 /* This breakpoint is in an overlay section.
1626 Did we set a breakpoint at the LMA? */
1627 if (!overlay_events_enabled
)
1629 /* Yes -- overlay event support is not active, so we
1630 should have set a breakpoint at the LMA. Remove it.
1632 /* Ignore any failures: if the LMA is in ROM, we will
1633 have already warned when we failed to insert it. */
1634 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1635 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1637 target_remove_breakpoint (&b
->overlay_target_info
);
1639 /* Did we set a breakpoint at the VMA?
1640 If so, we will have marked the breakpoint 'inserted'. */
1643 /* Yes -- remove it. Previously we did not bother to
1644 remove the breakpoint if the section had been
1645 unmapped, but let's not rely on that being safe. We
1646 don't know what the overlay manager might do. */
1647 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1648 val
= target_remove_hw_breakpoint (&b
->target_info
);
1650 /* However, we should remove *software* breakpoints only
1651 if the section is still mapped, or else we overwrite
1652 wrong code with the saved shadow contents. */
1653 else if (section_is_mapped (b
->section
))
1654 val
= target_remove_breakpoint (&b
->target_info
);
1660 /* No -- not inserted, so no need to remove. No error. */
1666 b
->inserted
= (is
== mark_inserted
);
1668 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1673 b
->inserted
= (is
== mark_inserted
);
1674 val
= target_remove_watchpoint (b
->address
, b
->length
,
1675 b
->watchpoint_type
);
1677 /* Failure to remove any of the hardware watchpoints comes here. */
1678 if ((is
== mark_uninserted
) && (b
->inserted
))
1679 warning (_("Could not remove hardware watchpoint %d."),
1682 else if ((b
->owner
->type
== bp_catch_fork
||
1683 b
->owner
->type
== bp_catch_vfork
||
1684 b
->owner
->type
== bp_catch_exec
)
1685 && breakpoint_enabled (b
->owner
)
1689 switch (b
->owner
->type
)
1692 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1694 case bp_catch_vfork
:
1695 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1698 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1701 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1706 b
->inserted
= (is
== mark_inserted
);
1712 /* Clear the "inserted" flag in all breakpoints. */
1715 mark_breakpoints_out (void)
1717 struct bp_location
*bpt
;
1719 ALL_BP_LOCATIONS (bpt
)
1723 /* Clear the "inserted" flag in all breakpoints and delete any
1724 breakpoints which should go away between runs of the program.
1726 Plus other such housekeeping that has to be done for breakpoints
1729 Note: this function gets called at the end of a run (by
1730 generic_mourn_inferior) and when a run begins (by
1731 init_wait_for_inferior). */
1736 breakpoint_init_inferior (enum inf_context context
)
1738 struct breakpoint
*b
, *temp
;
1739 struct bp_location
*bpt
;
1741 ALL_BP_LOCATIONS (bpt
)
1744 ALL_BREAKPOINTS_SAFE (b
, temp
)
1749 case bp_watchpoint_scope
:
1751 /* If the call dummy breakpoint is at the entry point it will
1752 cause problems when the inferior is rerun, so we better
1755 Also get rid of scope breakpoints. */
1756 delete_breakpoint (b
);
1760 case bp_hardware_watchpoint
:
1761 case bp_read_watchpoint
:
1762 case bp_access_watchpoint
:
1764 /* Likewise for watchpoints on local expressions. */
1765 if (b
->exp_valid_block
!= NULL
)
1766 delete_breakpoint (b
);
1767 else if (context
== inf_starting
)
1769 /* Reset val field to force reread of starting value
1770 in insert_breakpoints. */
1772 value_free (b
->val
);
1783 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1784 exists at PC. It returns ordinary_breakpoint_here if it's an
1785 ordinary breakpoint, or permanent_breakpoint_here if it's a
1786 permanent breakpoint.
1787 - When continuing from a location with an ordinary breakpoint, we
1788 actually single step once before calling insert_breakpoints.
1789 - When continuing from a localion with a permanent breakpoint, we
1790 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1791 the target, to advance the PC past the breakpoint. */
1793 enum breakpoint_here
1794 breakpoint_here_p (CORE_ADDR pc
)
1796 const struct bp_location
*bpt
;
1797 int any_breakpoint_here
= 0;
1799 ALL_BP_LOCATIONS (bpt
)
1801 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1802 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1805 if ((breakpoint_enabled (bpt
->owner
)
1806 || bpt
->owner
->enable_state
== bp_permanent
)
1807 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1809 if (overlay_debugging
1810 && section_is_overlay (bpt
->section
)
1811 && !section_is_mapped (bpt
->section
))
1812 continue; /* unmapped overlay -- can't be a match */
1813 else if (bpt
->owner
->enable_state
== bp_permanent
)
1814 return permanent_breakpoint_here
;
1816 any_breakpoint_here
= 1;
1820 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1824 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1825 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1826 This does not check for single-step breakpoints, which are
1827 inserted and removed using direct target manipulation. */
1830 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1832 const struct bp_location
*bpt
;
1834 ALL_BP_LOCATIONS (bpt
)
1836 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1837 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1841 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1843 if (overlay_debugging
1844 && section_is_overlay (bpt
->section
)
1845 && !section_is_mapped (bpt
->section
))
1846 continue; /* unmapped overlay -- can't be a match */
1854 /* Returns non-zero iff there's either regular breakpoint
1855 or a single step breakpoint inserted at PC. */
1858 breakpoint_inserted_here_p (CORE_ADDR pc
)
1860 if (regular_breakpoint_inserted_here_p (pc
))
1863 if (single_step_breakpoint_inserted_here_p (pc
))
1869 /* This function returns non-zero iff there is a software breakpoint
1873 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1875 const struct bp_location
*bpt
;
1876 int any_breakpoint_here
= 0;
1878 ALL_BP_LOCATIONS (bpt
)
1880 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1884 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1886 if (overlay_debugging
1887 && section_is_overlay (bpt
->section
)
1888 && !section_is_mapped (bpt
->section
))
1889 continue; /* unmapped overlay -- can't be a match */
1895 /* Also check for software single-step breakpoints. */
1896 if (single_step_breakpoint_inserted_here_p (pc
))
1902 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1903 PC is valid for process/thread PTID. */
1906 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1908 const struct bp_location
*bpt
;
1911 thread
= pid_to_thread_id (ptid
);
1913 ALL_BP_LOCATIONS (bpt
)
1915 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1916 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1919 if ((breakpoint_enabled (bpt
->owner
)
1920 || bpt
->owner
->enable_state
== bp_permanent
)
1921 && bpt
->address
== pc
1922 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1924 if (overlay_debugging
1925 && section_is_overlay (bpt
->section
)
1926 && !section_is_mapped (bpt
->section
))
1927 continue; /* unmapped overlay -- can't be a match */
1937 /* bpstat stuff. External routines' interfaces are documented
1941 ep_is_catchpoint (struct breakpoint
*ep
)
1944 (ep
->type
== bp_catch_load
)
1945 || (ep
->type
== bp_catch_unload
)
1946 || (ep
->type
== bp_catch_fork
)
1947 || (ep
->type
== bp_catch_vfork
)
1948 || (ep
->type
== bp_catch_exec
);
1950 /* ??rehrauer: Add more kinds here, as are implemented... */
1954 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1957 (ep
->type
== bp_catch_load
)
1958 || (ep
->type
== bp_catch_unload
);
1962 bpstat_free (bpstat bs
)
1964 if (bs
->old_val
!= NULL
)
1965 value_free (bs
->old_val
);
1966 free_command_lines (&bs
->commands
);
1970 /* Clear a bpstat so that it says we are not at any breakpoint.
1971 Also free any storage that is part of a bpstat. */
1974 bpstat_clear (bpstat
*bsp
)
1991 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1992 is part of the bpstat is copied as well. */
1995 bpstat_copy (bpstat bs
)
1999 bpstat retval
= NULL
;
2004 for (; bs
!= NULL
; bs
= bs
->next
)
2006 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2007 memcpy (tmp
, bs
, sizeof (*tmp
));
2008 if (bs
->commands
!= NULL
)
2009 tmp
->commands
= copy_command_lines (bs
->commands
);
2010 if (bs
->old_val
!= NULL
)
2011 tmp
->old_val
= value_copy (bs
->old_val
);
2014 /* This is the first thing in the chain. */
2024 /* Find the bpstat associated with this breakpoint */
2027 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2032 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2034 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2040 /* Find a step_resume breakpoint associated with this bpstat.
2041 (If there are multiple step_resume bp's on the list, this function
2042 will arbitrarily pick one.)
2044 It is an error to use this function if BPSTAT doesn't contain a
2045 step_resume breakpoint.
2047 See wait_for_inferior's use of this function. */
2049 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2053 gdb_assert (bsp
!= NULL
);
2055 current_thread
= pid_to_thread_id (inferior_ptid
);
2057 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2059 if ((bsp
->breakpoint_at
!= NULL
) &&
2060 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2061 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2062 bsp
->breakpoint_at
->owner
->thread
== -1))
2063 return bsp
->breakpoint_at
->owner
;
2066 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2070 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2071 at. *BSP upon return is a bpstat which points to the remaining
2072 breakpoints stopped at (but which is not guaranteed to be good for
2073 anything but further calls to bpstat_num).
2074 Return 0 if passed a bpstat which does not indicate any breakpoints.
2075 Return -1 if stopped at a breakpoint that has been deleted since
2077 Return 1 otherwise. */
2080 bpstat_num (bpstat
*bsp
, int *num
)
2082 struct breakpoint
*b
;
2085 return 0; /* No more breakpoint values */
2087 /* We assume we'll never have several bpstats that
2088 correspond to a single breakpoint -- otherwise,
2089 this function might return the same number more
2090 than once and this will look ugly. */
2091 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2092 *bsp
= (*bsp
)->next
;
2094 return -1; /* breakpoint that's been deleted since */
2096 *num
= b
->number
; /* We have its number */
2100 /* Modify BS so that the actions will not be performed. */
2103 bpstat_clear_actions (bpstat bs
)
2105 for (; bs
!= NULL
; bs
= bs
->next
)
2107 free_command_lines (&bs
->commands
);
2108 if (bs
->old_val
!= NULL
)
2110 value_free (bs
->old_val
);
2116 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2118 cleanup_executing_breakpoints (void *ignore
)
2120 executing_breakpoint_commands
= 0;
2123 /* Execute all the commands associated with all the breakpoints at this
2124 location. Any of these commands could cause the process to proceed
2125 beyond this point, etc. We look out for such changes by checking
2126 the global "breakpoint_proceeded" after each command. */
2129 bpstat_do_actions (bpstat
*bsp
)
2132 struct cleanup
*old_chain
;
2134 /* Avoid endless recursion if a `source' command is contained
2136 if (executing_breakpoint_commands
)
2139 executing_breakpoint_commands
= 1;
2140 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2143 /* Note that (as of this writing), our callers all appear to
2144 be passing us the address of global stop_bpstat. And, if
2145 our calls to execute_control_command cause the inferior to
2146 proceed, that global (and hence, *bsp) will change.
2148 We must be careful to not touch *bsp unless the inferior
2149 has not proceeded. */
2151 /* This pointer will iterate over the list of bpstat's. */
2154 breakpoint_proceeded
= 0;
2155 for (; bs
!= NULL
; bs
= bs
->next
)
2157 struct command_line
*cmd
;
2158 struct cleanup
*this_cmd_tree_chain
;
2160 /* Take ownership of the BSP's command tree, if it has one.
2162 The command tree could legitimately contain commands like
2163 'step' and 'next', which call clear_proceed_status, which
2164 frees stop_bpstat's command tree. To make sure this doesn't
2165 free the tree we're executing out from under us, we need to
2166 take ownership of the tree ourselves. Since a given bpstat's
2167 commands are only executed once, we don't need to copy it; we
2168 can clear the pointer in the bpstat, and make sure we free
2169 the tree when we're done. */
2172 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2176 execute_control_command (cmd
);
2178 if (breakpoint_proceeded
)
2184 /* We can free this command tree now. */
2185 do_cleanups (this_cmd_tree_chain
);
2187 if (breakpoint_proceeded
)
2189 if (target_can_async_p ())
2190 /* If we are in async mode, then the target might
2191 be still running, not stopped at any breakpoint,
2192 so nothing for us to do here -- just return to
2196 /* In sync mode, when execute_control_command returns
2197 we're already standing on the next breakpoint.
2198 Breakpoint commands for that stop were not run,
2199 since execute_command does not run breakpoint
2200 commands -- only command_line_handler does, but
2201 that one is not involved in execution of breakpoint
2202 commands. So, we can now execute breakpoint commands.
2203 There's an implicit assumption that we're called with
2204 stop_bpstat, so our parameter is the new bpstat to
2206 It should be noted that making execute_command do
2207 bpstat actions is not an option -- in this case we'll
2208 have recursive invocation of bpstat for each breakpoint
2209 with a command, and can easily blow up GDB stack. */
2213 do_cleanups (old_chain
);
2216 /* Print out the (old or new) value associated with a watchpoint. */
2219 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2222 fprintf_unfiltered (stream
, _("<unreadable>"));
2224 value_print (val
, stream
, 0, Val_pretty_default
);
2227 /* This is the normal print function for a bpstat. In the future,
2228 much of this logic could (should?) be moved to bpstat_stop_status,
2229 by having it set different print_it values.
2231 Current scheme: When we stop, bpstat_print() is called. It loops
2232 through the bpstat list of things causing this stop, calling the
2233 print_bp_stop_message function on each one. The behavior of the
2234 print_bp_stop_message function depends on the print_it field of
2235 bpstat. If such field so indicates, call this function here.
2237 Return values from this routine (ultimately used by bpstat_print()
2238 and normal_stop() to decide what to do):
2239 PRINT_NOTHING: Means we already printed all we needed to print,
2240 don't print anything else.
2241 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2242 that something to be followed by a location.
2243 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2244 that something to be followed by a location.
2245 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2248 static enum print_stop_action
2249 print_it_typical (bpstat bs
)
2251 struct cleanup
*old_chain
, *ui_out_chain
;
2252 struct breakpoint
*b
;
2253 const struct bp_location
*bl
;
2254 struct ui_stream
*stb
;
2256 stb
= ui_out_stream_new (uiout
);
2257 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2258 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2259 which has since been deleted. */
2260 if (bs
->breakpoint_at
== NULL
)
2261 return PRINT_UNKNOWN
;
2262 bl
= bs
->breakpoint_at
;
2268 case bp_hardware_breakpoint
:
2269 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2270 if (bl
->address
!= bl
->requested_address
)
2271 breakpoint_adjustment_warning (bl
->requested_address
,
2274 annotate_breakpoint (b
->number
);
2276 ui_out_text (uiout
, "\nTemporary breakpoint ");
2278 ui_out_text (uiout
, "\nBreakpoint ");
2279 if (ui_out_is_mi_like_p (uiout
))
2281 ui_out_field_string (uiout
, "reason",
2282 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2283 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2285 ui_out_field_int (uiout
, "bkptno", b
->number
);
2286 ui_out_text (uiout
, ", ");
2287 return PRINT_SRC_AND_LOC
;
2290 case bp_shlib_event
:
2291 /* Did we stop because the user set the stop_on_solib_events
2292 variable? (If so, we report this as a generic, "Stopped due
2293 to shlib event" message.) */
2294 printf_filtered (_("Stopped due to shared library event\n"));
2295 return PRINT_NOTHING
;
2298 case bp_thread_event
:
2299 /* Not sure how we will get here.
2300 GDB should not stop for these breakpoints. */
2301 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2302 return PRINT_NOTHING
;
2305 case bp_overlay_event
:
2306 /* By analogy with the thread event, GDB should not stop for these. */
2307 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2308 return PRINT_NOTHING
;
2312 annotate_catchpoint (b
->number
);
2313 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2315 b
->triggered_dll_pathname
);
2316 return PRINT_SRC_AND_LOC
;
2319 case bp_catch_unload
:
2320 annotate_catchpoint (b
->number
);
2321 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2323 b
->triggered_dll_pathname
);
2324 return PRINT_SRC_AND_LOC
;
2328 annotate_catchpoint (b
->number
);
2329 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2331 b
->forked_inferior_pid
);
2332 return PRINT_SRC_AND_LOC
;
2335 case bp_catch_vfork
:
2336 annotate_catchpoint (b
->number
);
2337 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2339 b
->forked_inferior_pid
);
2340 return PRINT_SRC_AND_LOC
;
2344 annotate_catchpoint (b
->number
);
2345 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2348 return PRINT_SRC_AND_LOC
;
2352 case bp_hardware_watchpoint
:
2353 annotate_watchpoint (b
->number
);
2354 if (ui_out_is_mi_like_p (uiout
))
2357 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2359 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2360 ui_out_text (uiout
, "\nOld value = ");
2361 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2362 ui_out_field_stream (uiout
, "old", stb
);
2363 ui_out_text (uiout
, "\nNew value = ");
2364 watchpoint_value_print (b
->val
, stb
->stream
);
2365 ui_out_field_stream (uiout
, "new", stb
);
2366 do_cleanups (ui_out_chain
);
2367 ui_out_text (uiout
, "\n");
2368 /* More than one watchpoint may have been triggered. */
2369 return PRINT_UNKNOWN
;
2372 case bp_read_watchpoint
:
2373 if (ui_out_is_mi_like_p (uiout
))
2376 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2378 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2379 ui_out_text (uiout
, "\nValue = ");
2380 watchpoint_value_print (b
->val
, stb
->stream
);
2381 ui_out_field_stream (uiout
, "value", stb
);
2382 do_cleanups (ui_out_chain
);
2383 ui_out_text (uiout
, "\n");
2384 return PRINT_UNKNOWN
;
2387 case bp_access_watchpoint
:
2388 if (bs
->old_val
!= NULL
)
2390 annotate_watchpoint (b
->number
);
2391 if (ui_out_is_mi_like_p (uiout
))
2394 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2396 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2397 ui_out_text (uiout
, "\nOld value = ");
2398 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2399 ui_out_field_stream (uiout
, "old", stb
);
2400 ui_out_text (uiout
, "\nNew value = ");
2405 if (ui_out_is_mi_like_p (uiout
))
2408 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2409 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2410 ui_out_text (uiout
, "\nValue = ");
2412 watchpoint_value_print (b
->val
, stb
->stream
);
2413 ui_out_field_stream (uiout
, "new", stb
);
2414 do_cleanups (ui_out_chain
);
2415 ui_out_text (uiout
, "\n");
2416 return PRINT_UNKNOWN
;
2419 /* Fall through, we don't deal with these types of breakpoints
2423 if (ui_out_is_mi_like_p (uiout
))
2426 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2427 return PRINT_UNKNOWN
;
2431 if (ui_out_is_mi_like_p (uiout
))
2434 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2435 return PRINT_UNKNOWN
;
2440 case bp_longjmp_resume
:
2441 case bp_step_resume
:
2442 case bp_watchpoint_scope
:
2445 return PRINT_UNKNOWN
;
2449 /* Generic routine for printing messages indicating why we
2450 stopped. The behavior of this function depends on the value
2451 'print_it' in the bpstat structure. Under some circumstances we
2452 may decide not to print anything here and delegate the task to
2455 static enum print_stop_action
2456 print_bp_stop_message (bpstat bs
)
2458 switch (bs
->print_it
)
2461 /* Nothing should be printed for this bpstat entry. */
2462 return PRINT_UNKNOWN
;
2466 /* We still want to print the frame, but we already printed the
2467 relevant messages. */
2468 return PRINT_SRC_AND_LOC
;
2471 case print_it_normal
:
2473 const struct bp_location
*bl
= bs
->breakpoint_at
;
2474 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2476 /* Normal case. Call the breakpoint's print_it method, or
2477 print_it_typical. */
2478 /* FIXME: how breakpoint can ever be NULL here? */
2479 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2480 return b
->ops
->print_it (b
);
2482 return print_it_typical (bs
);
2487 internal_error (__FILE__
, __LINE__
,
2488 _("print_bp_stop_message: unrecognized enum value"));
2493 /* Print a message indicating what happened. This is called from
2494 normal_stop(). The input to this routine is the head of the bpstat
2495 list - a list of the eventpoints that caused this stop. This
2496 routine calls the generic print routine for printing a message
2497 about reasons for stopping. This will print (for example) the
2498 "Breakpoint n," part of the output. The return value of this
2501 PRINT_UNKNOWN: Means we printed nothing
2502 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2503 code to print the location. An example is
2504 "Breakpoint 1, " which should be followed by
2506 PRINT_SRC_ONLY: Means we printed something, but there is no need
2507 to also print the location part of the message.
2508 An example is the catch/throw messages, which
2509 don't require a location appended to the end.
2510 PRINT_NOTHING: We have done some printing and we don't need any
2511 further info to be printed.*/
2513 enum print_stop_action
2514 bpstat_print (bpstat bs
)
2518 /* Maybe another breakpoint in the chain caused us to stop.
2519 (Currently all watchpoints go on the bpstat whether hit or not.
2520 That probably could (should) be changed, provided care is taken
2521 with respect to bpstat_explains_signal). */
2522 for (; bs
; bs
= bs
->next
)
2524 val
= print_bp_stop_message (bs
);
2525 if (val
== PRINT_SRC_ONLY
2526 || val
== PRINT_SRC_AND_LOC
2527 || val
== PRINT_NOTHING
)
2531 /* We reached the end of the chain, or we got a null BS to start
2532 with and nothing was printed. */
2533 return PRINT_UNKNOWN
;
2536 /* Evaluate the expression EXP and return 1 if value is zero.
2537 This is used inside a catch_errors to evaluate the breakpoint condition.
2538 The argument is a "struct expression *" that has been cast to char * to
2539 make it pass through catch_errors. */
2542 breakpoint_cond_eval (void *exp
)
2544 struct value
*mark
= value_mark ();
2545 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2546 value_free_to_mark (mark
);
2550 /* Allocate a new bpstat and chain it to the current one. */
2553 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2557 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2559 bs
->breakpoint_at
= bl
;
2560 /* If the condition is false, etc., don't do the commands. */
2561 bs
->commands
= NULL
;
2563 bs
->print_it
= print_it_normal
;
2567 /* The target has stopped with waitstatus WS. Check if any hardware
2568 watchpoints have triggered, according to the target. */
2571 watchpoints_triggered (struct target_waitstatus
*ws
)
2573 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2575 struct breakpoint
*b
;
2577 if (!stopped_by_watchpoint
)
2579 /* We were not stopped by a watchpoint. Mark all watchpoints
2580 as not triggered. */
2582 if (b
->type
== bp_hardware_watchpoint
2583 || b
->type
== bp_read_watchpoint
2584 || b
->type
== bp_access_watchpoint
)
2585 b
->watchpoint_triggered
= watch_triggered_no
;
2590 if (!target_stopped_data_address (¤t_target
, &addr
))
2592 /* We were stopped by a watchpoint, but we don't know where.
2593 Mark all watchpoints as unknown. */
2595 if (b
->type
== bp_hardware_watchpoint
2596 || b
->type
== bp_read_watchpoint
2597 || b
->type
== bp_access_watchpoint
)
2598 b
->watchpoint_triggered
= watch_triggered_unknown
;
2600 return stopped_by_watchpoint
;
2603 /* The target could report the data address. Mark watchpoints
2604 affected by this data address as triggered, and all others as not
2608 if (b
->type
== bp_hardware_watchpoint
2609 || b
->type
== bp_read_watchpoint
2610 || b
->type
== bp_access_watchpoint
)
2612 struct bp_location
*loc
;
2615 b
->watchpoint_triggered
= watch_triggered_no
;
2616 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2617 /* Exact match not required. Within range is
2619 if (target_watchpoint_addr_within_range (¤t_target
,
2623 b
->watchpoint_triggered
= watch_triggered_yes
;
2631 /* Possible return values for watchpoint_check (this can't be an enum
2632 because of check_errors). */
2633 /* The watchpoint has been deleted. */
2634 #define WP_DELETED 1
2635 /* The value has changed. */
2636 #define WP_VALUE_CHANGED 2
2637 /* The value has not changed. */
2638 #define WP_VALUE_NOT_CHANGED 3
2640 #define BP_TEMPFLAG 1
2641 #define BP_HARDWAREFLAG 2
2643 /* Check watchpoint condition. */
2646 watchpoint_check (void *p
)
2648 bpstat bs
= (bpstat
) p
;
2649 struct breakpoint
*b
;
2650 struct frame_info
*fr
;
2651 int within_current_scope
;
2653 b
= bs
->breakpoint_at
->owner
;
2655 if (b
->exp_valid_block
== NULL
)
2656 within_current_scope
= 1;
2659 /* There is no current frame at this moment. If we're going to have
2660 any chance of handling watchpoints on local variables, we'll need
2661 the frame chain (so we can determine if we're in scope). */
2662 reinit_frame_cache ();
2663 fr
= frame_find_by_id (b
->watchpoint_frame
);
2664 within_current_scope
= (fr
!= NULL
);
2666 /* If we've gotten confused in the unwinder, we might have
2667 returned a frame that can't describe this variable. */
2668 if (within_current_scope
2669 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2670 within_current_scope
= 0;
2672 /* in_function_epilogue_p() returns a non-zero value if we're still
2673 in the function but the stack frame has already been invalidated.
2674 Since we can't rely on the values of local variables after the
2675 stack has been destroyed, we are treating the watchpoint in that
2676 state as `not changed' without further checking.
2678 vinschen/2003-09-04: The former implementation left out the case
2679 that the watchpoint frame couldn't be found by frame_find_by_id()
2680 because the current PC is currently in an epilogue. Calling
2681 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2682 if ((!within_current_scope
|| fr
== get_current_frame ())
2683 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2684 return WP_VALUE_NOT_CHANGED
;
2685 if (fr
&& within_current_scope
)
2686 /* If we end up stopping, the current frame will get selected
2687 in normal_stop. So this call to select_frame won't affect
2692 if (within_current_scope
)
2694 /* We use value_{,free_to_}mark because it could be a
2695 *long* time before we return to the command level and
2696 call free_all_values. We can't call free_all_values because
2697 we might be in the middle of evaluating a function call. */
2699 struct value
*mark
= value_mark ();
2700 struct value
*new_val
;
2702 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2703 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2704 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2706 if (new_val
!= NULL
)
2708 release_value (new_val
);
2709 value_free_to_mark (mark
);
2711 bs
->old_val
= b
->val
;
2714 /* We will stop here */
2715 return WP_VALUE_CHANGED
;
2719 /* Nothing changed, don't do anything. */
2720 value_free_to_mark (mark
);
2721 /* We won't stop here */
2722 return WP_VALUE_NOT_CHANGED
;
2727 /* This seems like the only logical thing to do because
2728 if we temporarily ignored the watchpoint, then when
2729 we reenter the block in which it is valid it contains
2730 garbage (in the case of a function, it may have two
2731 garbage values, one before and one after the prologue).
2732 So we can't even detect the first assignment to it and
2733 watch after that (since the garbage may or may not equal
2734 the first value assigned). */
2735 /* We print all the stop information in print_it_typical(), but
2736 in this case, by the time we call print_it_typical() this bp
2737 will be deleted already. So we have no choice but print the
2738 information here. */
2739 if (ui_out_is_mi_like_p (uiout
))
2741 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2742 ui_out_text (uiout
, "\nWatchpoint ");
2743 ui_out_field_int (uiout
, "wpnum", b
->number
);
2744 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2745 which its expression is valid.\n");
2747 if (b
->related_breakpoint
)
2748 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2749 b
->disposition
= disp_del_at_next_stop
;
2755 /* Return true if it looks like target has stopped due to hitting
2756 breakpoint location BL. This function does not check if we
2757 should stop, only if BL explains the stop. */
2759 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2761 struct breakpoint
*b
= bl
->owner
;
2763 if (b
->type
!= bp_watchpoint
2764 && b
->type
!= bp_hardware_watchpoint
2765 && b
->type
!= bp_read_watchpoint
2766 && b
->type
!= bp_access_watchpoint
2767 && b
->type
!= bp_hardware_breakpoint
2768 && b
->type
!= bp_catch_fork
2769 && b
->type
!= bp_catch_vfork
2770 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2772 if (bl
->address
!= bp_addr
) /* address doesn't match */
2774 if (overlay_debugging
/* unmapped overlay section */
2775 && section_is_overlay (bl
->section
)
2776 && !section_is_mapped (bl
->section
))
2780 /* Continuable hardware watchpoints are treated as non-existent if the
2781 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2782 some data address). Otherwise gdb won't stop on a break instruction
2783 in the code (not from a breakpoint) when a hardware watchpoint has
2784 been defined. Also skip watchpoints which we know did not trigger
2785 (did not match the data address). */
2787 if ((b
->type
== bp_hardware_watchpoint
2788 || b
->type
== bp_read_watchpoint
2789 || b
->type
== bp_access_watchpoint
)
2790 && b
->watchpoint_triggered
== watch_triggered_no
)
2793 if (b
->type
== bp_hardware_breakpoint
)
2795 if (bl
->address
!= bp_addr
)
2797 if (overlay_debugging
/* unmapped overlay section */
2798 && section_is_overlay (bl
->section
)
2799 && !section_is_mapped (bl
->section
))
2803 /* Is this a catchpoint of a load or unload? If so, did we
2804 get a load or unload of the specified library? If not,
2806 if ((b
->type
== bp_catch_load
)
2807 #if defined(SOLIB_HAVE_LOAD_EVENT)
2808 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2809 || ((b
->dll_pathname
!= NULL
)
2810 && (strcmp (b
->dll_pathname
,
2811 SOLIB_LOADED_LIBRARY_PATHNAME (
2812 PIDGET (inferior_ptid
)))
2818 if ((b
->type
== bp_catch_unload
)
2819 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2820 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2821 || ((b
->dll_pathname
!= NULL
)
2822 && (strcmp (b
->dll_pathname
,
2823 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2824 PIDGET (inferior_ptid
)))
2830 if ((b
->type
== bp_catch_fork
)
2831 && !inferior_has_forked (PIDGET (inferior_ptid
),
2832 &b
->forked_inferior_pid
))
2835 if ((b
->type
== bp_catch_vfork
)
2836 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2837 &b
->forked_inferior_pid
))
2840 if ((b
->type
== bp_catch_exec
)
2841 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2847 /* If BS refers to a watchpoint, determine if the watched values
2848 has actually changed, and we should stop. If not, set BS->stop
2851 bpstat_check_watchpoint (bpstat bs
)
2853 const struct bp_location
*bl
= bs
->breakpoint_at
;
2854 struct breakpoint
*b
= bl
->owner
;
2856 if (b
->type
== bp_watchpoint
2857 || b
->type
== bp_read_watchpoint
2858 || b
->type
== bp_access_watchpoint
2859 || b
->type
== bp_hardware_watchpoint
)
2863 int must_check_value
= 0;
2865 if (b
->type
== bp_watchpoint
)
2866 /* For a software watchpoint, we must always check the
2868 must_check_value
= 1;
2869 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2870 /* We have a hardware watchpoint (read, write, or access)
2871 and the target earlier reported an address watched by
2873 must_check_value
= 1;
2874 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2875 && b
->type
== bp_hardware_watchpoint
)
2876 /* We were stopped by a hardware watchpoint, but the target could
2877 not report the data address. We must check the watchpoint's
2878 value. Access and read watchpoints are out of luck; without
2879 a data address, we can't figure it out. */
2880 must_check_value
= 1;
2882 if (must_check_value
)
2884 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2886 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2887 int e
= catch_errors (watchpoint_check
, bs
, message
,
2889 do_cleanups (cleanups
);
2893 /* We've already printed what needs to be printed. */
2894 bs
->print_it
= print_it_done
;
2897 case WP_VALUE_CHANGED
:
2898 if (b
->type
== bp_read_watchpoint
)
2900 /* Don't stop: read watchpoints shouldn't fire if
2901 the value has changed. This is for targets
2902 which cannot set read-only watchpoints. */
2903 bs
->print_it
= print_it_noop
;
2907 case WP_VALUE_NOT_CHANGED
:
2908 if (b
->type
== bp_hardware_watchpoint
2909 || b
->type
== bp_watchpoint
)
2911 /* Don't stop: write watchpoints shouldn't fire if
2912 the value hasn't changed. */
2913 bs
->print_it
= print_it_noop
;
2921 /* Error from catch_errors. */
2922 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2923 if (b
->related_breakpoint
)
2924 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2925 b
->disposition
= disp_del_at_next_stop
;
2926 /* We've already printed what needs to be printed. */
2927 bs
->print_it
= print_it_done
;
2931 else /* must_check_value == 0 */
2933 /* This is a case where some watchpoint(s) triggered, but
2934 not at the address of this watchpoint, or else no
2935 watchpoint triggered after all. So don't print
2936 anything for this watchpoint. */
2937 bs
->print_it
= print_it_noop
;
2944 /* Check conditions (condition proper, frame, thread and ignore count)
2945 of breakpoint referred to by BS. If we should not stop for this
2946 breakpoint, set BS->stop to 0. */
2948 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2950 int thread_id
= pid_to_thread_id (ptid
);
2951 const struct bp_location
*bl
= bs
->breakpoint_at
;
2952 struct breakpoint
*b
= bl
->owner
;
2954 if (frame_id_p (b
->frame_id
)
2955 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2959 int value_is_zero
= 0;
2961 /* If this is a scope breakpoint, mark the associated
2962 watchpoint as triggered so that we will handle the
2963 out-of-scope event. We'll get to the watchpoint next
2965 if (b
->type
== bp_watchpoint_scope
)
2966 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2968 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2970 /* Need to select the frame, with all that implies
2971 so that the conditions will have the right context. */
2972 select_frame (get_current_frame ());
2974 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2975 "Error in testing breakpoint condition:\n",
2977 /* FIXME-someday, should give breakpoint # */
2980 if (bl
->cond
&& value_is_zero
)
2984 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2988 else if (b
->ignore_count
> 0)
2991 annotate_ignore_count_change ();
2993 /* Increase the hit count even though we don't
3001 /* Get a bpstat associated with having just stopped at address
3002 BP_ADDR in thread PTID.
3004 Determine whether we stopped at a breakpoint, etc, or whether we
3005 don't understand this stop. Result is a chain of bpstat's such that:
3007 if we don't understand the stop, the result is a null pointer.
3009 if we understand why we stopped, the result is not null.
3011 Each element of the chain refers to a particular breakpoint or
3012 watchpoint at which we have stopped. (We may have stopped for
3013 several reasons concurrently.)
3015 Each element of the chain has valid next, breakpoint_at,
3016 commands, FIXME??? fields. */
3019 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3021 struct breakpoint
*b
= NULL
;
3022 const struct bp_location
*bl
;
3023 /* Root of the chain of bpstat's */
3024 struct bpstats root_bs
[1];
3025 /* Pointer to the last thing in the chain currently. */
3026 bpstat bs
= root_bs
;
3028 ALL_BP_LOCATIONS (bl
)
3032 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3035 /* For hardware watchpoints, we look only at the first location.
3036 The watchpoint_check function will work on entire expression,
3037 not the individual locations. For read watchopints, the
3038 watchpoints_triggered function have checked all locations
3041 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3044 if (!bpstat_check_location (bl
, bp_addr
))
3047 /* Come here if it's a watchpoint, or if the break address matches */
3049 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3051 /* Assume we stop. Should we find watchpoint that is not actually
3052 triggered, or if condition of breakpoint is false, we'll reset
3057 bpstat_check_watchpoint (bs
);
3061 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3062 /* We do not stop for these. */
3065 bpstat_check_breakpoint_conditions (bs
, ptid
);
3071 /* We will stop here */
3072 if (b
->disposition
== disp_disable
)
3074 b
->enable_state
= bp_disabled
;
3075 update_global_location_list ();
3079 bs
->commands
= b
->commands
;
3081 (strcmp ("silent", bs
->commands
->line
) == 0
3082 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3084 bs
->commands
= bs
->commands
->next
;
3087 bs
->commands
= copy_command_lines (bs
->commands
);
3090 /* Print nothing for this entry if we dont stop or if we dont print. */
3091 if (bs
->stop
== 0 || bs
->print
== 0)
3092 bs
->print_it
= print_it_noop
;
3095 bs
->next
= NULL
; /* Terminate the chain */
3096 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3098 /* If we aren't stopping, the value of some hardware watchpoint may
3099 not have changed, but the intermediate memory locations we are
3100 watching may have. Don't bother if we're stopping; this will get
3102 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3107 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3109 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3110 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3111 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3113 /* remove/insert can invalidate bs->breakpoint_at, if this
3114 location is no longer used by the watchpoint. Prevent
3115 further code from trying to use it. */
3116 bs
->breakpoint_at
= NULL
;
3117 remove_breakpoints ();
3118 insert_breakpoints ();
3122 return root_bs
->next
;
3125 /* Tell what to do about this bpstat. */
3127 bpstat_what (bpstat bs
)
3129 /* Classify each bpstat as one of the following. */
3132 /* This bpstat element has no effect on the main_action. */
3135 /* There was a watchpoint, stop but don't print. */
3138 /* There was a watchpoint, stop and print. */
3141 /* There was a breakpoint but we're not stopping. */
3144 /* There was a breakpoint, stop but don't print. */
3147 /* There was a breakpoint, stop and print. */
3150 /* We hit the longjmp breakpoint. */
3153 /* We hit the longjmp_resume breakpoint. */
3156 /* We hit the step_resume breakpoint. */
3159 /* We hit the shared library event breakpoint. */
3162 /* We caught a shared library event. */
3165 /* This is just used to count how many enums there are. */
3169 /* Here is the table which drives this routine. So that we can
3170 format it pretty, we define some abbreviations for the
3171 enum bpstat_what codes. */
3172 #define kc BPSTAT_WHAT_KEEP_CHECKING
3173 #define ss BPSTAT_WHAT_STOP_SILENT
3174 #define sn BPSTAT_WHAT_STOP_NOISY
3175 #define sgl BPSTAT_WHAT_SINGLE
3176 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3177 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3178 #define sr BPSTAT_WHAT_STEP_RESUME
3179 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3180 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3182 /* "Can't happen." Might want to print an error message.
3183 abort() is not out of the question, but chances are GDB is just
3184 a bit confused, not unusable. */
3185 #define err BPSTAT_WHAT_STOP_NOISY
3187 /* Given an old action and a class, come up with a new action. */
3188 /* One interesting property of this table is that wp_silent is the same
3189 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3190 after stopping, the check for whether to step over a breakpoint
3191 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3192 reference to how we stopped. We retain separate wp_silent and
3193 bp_silent codes in case we want to change that someday.
3195 Another possibly interesting property of this table is that
3196 there's a partial ordering, priority-like, of the actions. Once
3197 you've decided that some action is appropriate, you'll never go
3198 back and decide something of a lower priority is better. The
3201 kc < clr sgl shl shlr slr sn sr ss
3202 sgl < shl shlr slr sn sr ss
3203 slr < err shl shlr sn sr ss
3204 clr < err shl shlr sn sr ss
3211 What I think this means is that we don't need a damned table
3212 here. If you just put the rows and columns in the right order,
3213 it'd look awfully regular. We could simply walk the bpstat list
3214 and choose the highest priority action we find, with a little
3215 logic to handle the 'err' cases. */
3217 /* step_resume entries: a step resume breakpoint overrides another
3218 breakpoint of signal handling (see comment in wait_for_inferior
3219 at where we set the step_resume breakpoint). */
3221 static const enum bpstat_what_main_action
3222 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3225 /* kc ss sn sgl slr clr sr shl shlr
3228 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3230 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3232 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3234 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3236 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3238 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3240 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3242 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3244 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3246 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3248 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3262 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3263 struct bpstat_what retval
;
3265 retval
.call_dummy
= 0;
3266 for (; bs
!= NULL
; bs
= bs
->next
)
3268 enum class bs_class
= no_effect
;
3269 if (bs
->breakpoint_at
== NULL
)
3270 /* I suspect this can happen if it was a momentary breakpoint
3271 which has since been deleted. */
3273 switch (bs
->breakpoint_at
->owner
->type
)
3279 case bp_hardware_breakpoint
:
3285 bs_class
= bp_noisy
;
3287 bs_class
= bp_silent
;
3290 bs_class
= bp_nostop
;
3293 case bp_hardware_watchpoint
:
3294 case bp_read_watchpoint
:
3295 case bp_access_watchpoint
:
3299 bs_class
= wp_noisy
;
3301 bs_class
= wp_silent
;
3304 /* There was a watchpoint, but we're not stopping.
3305 This requires no further action. */
3306 bs_class
= no_effect
;
3309 bs_class
= long_jump
;
3311 case bp_longjmp_resume
:
3312 bs_class
= long_resume
;
3314 case bp_step_resume
:
3317 bs_class
= step_resume
;
3320 /* It is for the wrong frame. */
3321 bs_class
= bp_nostop
;
3323 case bp_watchpoint_scope
:
3324 bs_class
= bp_nostop
;
3326 case bp_shlib_event
:
3327 bs_class
= shlib_event
;
3329 case bp_thread_event
:
3330 case bp_overlay_event
:
3331 bs_class
= bp_nostop
;
3334 case bp_catch_unload
:
3335 /* Only if this catchpoint triggered should we cause the
3336 step-out-of-dld behaviour. Otherwise, we ignore this
3339 bs_class
= catch_shlib_event
;
3341 bs_class
= no_effect
;
3344 case bp_catch_vfork
:
3349 bs_class
= bp_noisy
;
3351 bs_class
= bp_silent
;
3354 /* There was a catchpoint, but we're not stopping.
3355 This requires no further action. */
3356 bs_class
= no_effect
;
3359 /* Make sure the action is stop (silent or noisy),
3360 so infrun.c pops the dummy frame. */
3361 bs_class
= bp_silent
;
3362 retval
.call_dummy
= 1;
3365 current_action
= table
[(int) bs_class
][(int) current_action
];
3367 retval
.main_action
= current_action
;
3371 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3372 without hardware support). This isn't related to a specific bpstat,
3373 just to things like whether watchpoints are set. */
3376 bpstat_should_step (void)
3378 struct breakpoint
*b
;
3380 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3387 /* Given a bpstat that records zero or more triggered eventpoints, this
3388 function returns another bpstat which contains only the catchpoints
3389 on that first list, if any. */
3391 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3393 struct bpstats root_bs
[1];
3394 bpstat bs
= root_bs
;
3395 struct breakpoint
*ep
;
3398 bpstat_clear (cp_list
);
3399 root_bs
->next
= NULL
;
3401 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3403 /* Is this eventpoint a catchpoint? If not, ignore it. */
3404 ep
= ep_list
->breakpoint_at
->owner
;
3407 if ((ep
->type
!= bp_catch_load
) &&
3408 (ep
->type
!= bp_catch_unload
))
3409 /* pai: (temp) ADD fork/vfork here!! */
3412 /* Yes; add it to the list. */
3413 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3418 #if defined(SOLIB_ADD)
3419 /* Also, for each triggered catchpoint, tag it with the name of
3420 the library that caused this trigger. (We copy the name now,
3421 because it's only guaranteed to be available NOW, when the
3422 catchpoint triggers. Clients who may wish to know the name
3423 later must get it from the catchpoint itself.) */
3424 if (ep
->triggered_dll_pathname
!= NULL
)
3425 xfree (ep
->triggered_dll_pathname
);
3426 if (ep
->type
== bp_catch_load
)
3427 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3428 PIDGET (inferior_ptid
));
3430 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3431 PIDGET (inferior_ptid
));
3433 dll_pathname
= NULL
;
3437 ep
->triggered_dll_pathname
= (char *)
3438 xmalloc (strlen (dll_pathname
) + 1);
3439 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3442 ep
->triggered_dll_pathname
= NULL
;
3448 static void print_breakpoint_location (struct breakpoint
*b
,
3449 struct bp_location
*loc
,
3451 struct ui_stream
*stb
)
3456 = find_pc_sect_function (loc
->address
, loc
->section
);
3459 ui_out_text (uiout
, "in ");
3460 ui_out_field_string (uiout
, "func",
3461 SYMBOL_PRINT_NAME (sym
));
3462 ui_out_wrap_hint (uiout
, wrap_indent
);
3463 ui_out_text (uiout
, " at ");
3465 ui_out_field_string (uiout
, "file", b
->source_file
);
3466 ui_out_text (uiout
, ":");
3468 if (ui_out_is_mi_like_p (uiout
))
3470 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3471 char *fullname
= symtab_to_fullname (sal
.symtab
);
3474 ui_out_field_string (uiout
, "fullname", fullname
);
3477 ui_out_field_int (uiout
, "line", b
->line_number
);
3481 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3485 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3486 ui_out_field_stream (uiout
, "at", stb
);
3490 /* Print B to gdb_stdout. */
3492 print_one_breakpoint_location (struct breakpoint
*b
,
3493 struct bp_location
*loc
,
3495 CORE_ADDR
*last_addr
)
3497 struct command_line
*l
;
3499 struct ep_type_description
3504 static struct ep_type_description bptypes
[] =
3506 {bp_none
, "?deleted?"},
3507 {bp_breakpoint
, "breakpoint"},
3508 {bp_hardware_breakpoint
, "hw breakpoint"},
3509 {bp_until
, "until"},
3510 {bp_finish
, "finish"},
3511 {bp_watchpoint
, "watchpoint"},
3512 {bp_hardware_watchpoint
, "hw watchpoint"},
3513 {bp_read_watchpoint
, "read watchpoint"},
3514 {bp_access_watchpoint
, "acc watchpoint"},
3515 {bp_longjmp
, "longjmp"},
3516 {bp_longjmp_resume
, "longjmp resume"},
3517 {bp_step_resume
, "step resume"},
3518 {bp_watchpoint_scope
, "watchpoint scope"},
3519 {bp_call_dummy
, "call dummy"},
3520 {bp_shlib_event
, "shlib events"},
3521 {bp_thread_event
, "thread events"},
3522 {bp_overlay_event
, "overlay events"},
3523 {bp_catch_load
, "catch load"},
3524 {bp_catch_unload
, "catch unload"},
3525 {bp_catch_fork
, "catch fork"},
3526 {bp_catch_vfork
, "catch vfork"},
3527 {bp_catch_exec
, "catch exec"}
3530 static char bpenables
[] = "nynny";
3531 char wrap_indent
[80];
3532 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3533 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3534 struct cleanup
*bkpt_chain
;
3536 int header_of_multiple
= 0;
3537 int part_of_multiple
= (loc
!= NULL
);
3539 gdb_assert (!loc
|| loc_number
!= 0);
3540 /* See comment in print_one_breakpoint concerning
3541 treatment of breakpoints with single disabled
3545 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3546 header_of_multiple
= 1;
3551 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3555 if (part_of_multiple
)
3558 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3559 ui_out_field_string (uiout
, "number", formatted
);
3564 ui_out_field_int (uiout
, "number", b
->number
);
3569 if (part_of_multiple
)
3570 ui_out_field_skip (uiout
, "type");
3573 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3574 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3575 internal_error (__FILE__
, __LINE__
,
3576 _("bptypes table does not describe type #%d."),
3578 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3583 if (part_of_multiple
)
3584 ui_out_field_skip (uiout
, "disp");
3586 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3591 if (part_of_multiple
)
3592 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3594 ui_out_field_fmt (uiout
, "enabled", "%c",
3595 bpenables
[(int) b
->enable_state
]);
3596 ui_out_spaces (uiout
, 2);
3600 strcpy (wrap_indent
, " ");
3603 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3604 strcat (wrap_indent
, " ");
3606 strcat (wrap_indent
, " ");
3609 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3611 /* Although the print_one can possibly print
3612 all locations, calling it here is not likely
3613 to get any nice result. So, make sure there's
3614 just one location. */
3615 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3616 b
->ops
->print_one (b
, last_addr
);
3622 internal_error (__FILE__
, __LINE__
,
3623 _("print_one_breakpoint: bp_none encountered\n"));
3627 case bp_hardware_watchpoint
:
3628 case bp_read_watchpoint
:
3629 case bp_access_watchpoint
:
3630 /* Field 4, the address, is omitted (which makes the columns
3631 not line up too nicely with the headers, but the effect
3632 is relatively readable). */
3634 ui_out_field_skip (uiout
, "addr");
3636 print_expression (b
->exp
, stb
->stream
);
3637 ui_out_field_stream (uiout
, "what", stb
);
3641 case bp_catch_unload
:
3642 /* Field 4, the address, is omitted (which makes the columns
3643 not line up too nicely with the headers, but the effect
3644 is relatively readable). */
3646 ui_out_field_skip (uiout
, "addr");
3648 if (b
->dll_pathname
== NULL
)
3650 ui_out_field_string (uiout
, "what", "<any library>");
3651 ui_out_spaces (uiout
, 1);
3655 ui_out_text (uiout
, "library \"");
3656 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3657 ui_out_text (uiout
, "\" ");
3662 case bp_catch_vfork
:
3663 /* Field 4, the address, is omitted (which makes the columns
3664 not line up too nicely with the headers, but the effect
3665 is relatively readable). */
3667 ui_out_field_skip (uiout
, "addr");
3669 if (b
->forked_inferior_pid
!= 0)
3671 ui_out_text (uiout
, "process ");
3672 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3673 ui_out_spaces (uiout
, 1);
3678 /* Field 4, the address, is omitted (which makes the columns
3679 not line up too nicely with the headers, but the effect
3680 is relatively readable). */
3682 ui_out_field_skip (uiout
, "addr");
3684 if (b
->exec_pathname
!= NULL
)
3686 ui_out_text (uiout
, "program \"");
3687 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3688 ui_out_text (uiout
, "\" ");
3693 case bp_hardware_breakpoint
:
3697 case bp_longjmp_resume
:
3698 case bp_step_resume
:
3699 case bp_watchpoint_scope
:
3701 case bp_shlib_event
:
3702 case bp_thread_event
:
3703 case bp_overlay_event
:
3707 if (header_of_multiple
)
3708 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3709 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3710 ui_out_field_string (uiout
, "addr", "<PENDING>");
3712 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3715 if (!header_of_multiple
)
3716 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3718 *last_addr
= b
->loc
->address
;
3722 if (!part_of_multiple
&& b
->thread
!= -1)
3724 /* FIXME: This seems to be redundant and lost here; see the
3725 "stop only in" line a little further down. */
3726 ui_out_text (uiout
, " thread ");
3727 ui_out_field_int (uiout
, "thread", b
->thread
);
3730 ui_out_text (uiout
, "\n");
3732 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3735 ui_out_text (uiout
, "\tstop only in stack frame at ");
3736 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3738 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3739 ui_out_text (uiout
, "\n");
3742 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3744 /* We do not print the condition for Ada exception catchpoints
3745 because the condition is an internal implementation detail
3746 that we do not want to expose to the user. */
3748 ui_out_text (uiout
, "\tstop only if ");
3749 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3750 ui_out_text (uiout
, "\n");
3753 if (!part_of_multiple
&& b
->thread
!= -1)
3755 /* FIXME should make an annotation for this */
3756 ui_out_text (uiout
, "\tstop only in thread ");
3757 ui_out_field_int (uiout
, "thread", b
->thread
);
3758 ui_out_text (uiout
, "\n");
3761 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3763 /* FIXME should make an annotation for this */
3764 if (ep_is_catchpoint (b
))
3765 ui_out_text (uiout
, "\tcatchpoint");
3767 ui_out_text (uiout
, "\tbreakpoint");
3768 ui_out_text (uiout
, " already hit ");
3769 ui_out_field_int (uiout
, "times", b
->hit_count
);
3770 if (b
->hit_count
== 1)
3771 ui_out_text (uiout
, " time\n");
3773 ui_out_text (uiout
, " times\n");
3776 /* Output the count also if it is zero, but only if this is
3777 mi. FIXME: Should have a better test for this. */
3778 if (ui_out_is_mi_like_p (uiout
))
3779 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3780 ui_out_field_int (uiout
, "times", b
->hit_count
);
3782 if (!part_of_multiple
&& b
->ignore_count
)
3785 ui_out_text (uiout
, "\tignore next ");
3786 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3787 ui_out_text (uiout
, " hits\n");
3790 if (!part_of_multiple
&& (l
= b
->commands
))
3792 struct cleanup
*script_chain
;
3795 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3796 print_command_lines (uiout
, l
, 4);
3797 do_cleanups (script_chain
);
3800 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3803 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3804 else if (b
->exp_string
)
3805 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3808 do_cleanups (bkpt_chain
);
3809 do_cleanups (old_chain
);
3813 print_one_breakpoint (struct breakpoint
*b
,
3814 CORE_ADDR
*last_addr
)
3816 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3818 /* If this breakpoint has custom print function,
3819 it's already printed. Otherwise, print individual
3820 locations, if any. */
3821 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3823 /* If breakpoint has a single location that is
3824 disabled, we print it as if it had
3825 several locations, since otherwise it's hard to
3826 represent "breakpoint enabled, location disabled"
3828 Note that while hardware watchpoints have
3829 several locations internally, that's no a property
3832 && !is_hardware_watchpoint (b
)
3833 && (b
->loc
->next
|| !b
->loc
->enabled
)
3834 && !ui_out_is_mi_like_p (uiout
))
3836 struct bp_location
*loc
;
3838 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3839 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3845 struct captured_breakpoint_query_args
3851 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3853 struct captured_breakpoint_query_args
*args
= data
;
3854 struct breakpoint
*b
;
3855 CORE_ADDR dummy_addr
= 0;
3858 if (args
->bnum
== b
->number
)
3860 print_one_breakpoint (b
, &dummy_addr
);
3868 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3870 struct captured_breakpoint_query_args args
;
3872 /* For the moment we don't trust print_one_breakpoint() to not throw
3874 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3875 error_message
, RETURN_MASK_ALL
) < 0)
3881 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3882 catchpoints, et.al.). */
3885 user_settable_breakpoint (const struct breakpoint
*b
)
3887 return (b
->type
== bp_breakpoint
3888 || b
->type
== bp_catch_load
3889 || b
->type
== bp_catch_unload
3890 || b
->type
== bp_catch_fork
3891 || b
->type
== bp_catch_vfork
3892 || b
->type
== bp_catch_exec
3893 || b
->type
== bp_hardware_breakpoint
3894 || b
->type
== bp_watchpoint
3895 || b
->type
== bp_read_watchpoint
3896 || b
->type
== bp_access_watchpoint
3897 || b
->type
== bp_hardware_watchpoint
);
3900 /* Print information on user settable breakpoint (watchpoint, etc)
3901 number BNUM. If BNUM is -1 print all user settable breakpoints.
3902 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3905 breakpoint_1 (int bnum
, int allflag
)
3907 struct breakpoint
*b
;
3908 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3909 int nr_printable_breakpoints
;
3910 struct cleanup
*bkpttbl_chain
;
3912 /* Compute the number of rows in the table. */
3913 nr_printable_breakpoints
= 0;
3916 || bnum
== b
->number
)
3918 if (allflag
|| user_settable_breakpoint (b
))
3919 nr_printable_breakpoints
++;
3924 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3928 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3931 if (nr_printable_breakpoints
> 0)
3932 annotate_breakpoints_headers ();
3933 if (nr_printable_breakpoints
> 0)
3935 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3936 if (nr_printable_breakpoints
> 0)
3938 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3939 if (nr_printable_breakpoints
> 0)
3941 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3942 if (nr_printable_breakpoints
> 0)
3944 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3947 if (nr_printable_breakpoints
> 0)
3949 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3950 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3952 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3954 if (nr_printable_breakpoints
> 0)
3956 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3957 ui_out_table_body (uiout
);
3958 if (nr_printable_breakpoints
> 0)
3959 annotate_breakpoints_table ();
3963 || bnum
== b
->number
)
3965 /* We only print out user settable breakpoints unless the
3967 if (allflag
|| user_settable_breakpoint (b
))
3968 print_one_breakpoint (b
, &last_addr
);
3971 do_cleanups (bkpttbl_chain
);
3973 if (nr_printable_breakpoints
== 0)
3976 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3978 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3983 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3984 that a comparison of an unsigned with -1 is always false. */
3985 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3986 set_next_address (last_addr
);
3989 /* FIXME? Should this be moved up so that it is only called when
3990 there have been breakpoints? */
3991 annotate_breakpoints_table_end ();
3995 breakpoints_info (char *bnum_exp
, int from_tty
)
4000 bnum
= parse_and_eval_long (bnum_exp
);
4002 breakpoint_1 (bnum
, 0);
4006 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4011 bnum
= parse_and_eval_long (bnum_exp
);
4013 breakpoint_1 (bnum
, 1);
4017 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4019 struct bp_location
*bl
= b
->loc
;
4020 for (; bl
; bl
= bl
->next
)
4022 if (bl
->address
== pc
4023 && (!overlay_debugging
|| bl
->section
== section
))
4029 /* Print a message describing any breakpoints set at PC. */
4032 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4035 struct breakpoint
*b
;
4038 others
+= breakpoint_has_pc (b
, pc
, section
);
4042 printf_filtered (_("Note: breakpoint "));
4043 else /* if (others == ???) */
4044 printf_filtered (_("Note: breakpoints "));
4046 if (breakpoint_has_pc (b
, pc
, section
))
4049 printf_filtered ("%d", b
->number
);
4050 if (b
->thread
== -1 && thread
!= -1)
4051 printf_filtered (" (all threads)");
4052 else if (b
->thread
!= -1)
4053 printf_filtered (" (thread %d)", b
->thread
);
4054 printf_filtered ("%s%s ",
4055 ((b
->enable_state
== bp_disabled
||
4056 b
->enable_state
== bp_call_disabled
)
4058 : b
->enable_state
== bp_permanent
4062 : ((others
== 1) ? " and" : ""));
4064 printf_filtered (_("also set at pc "));
4065 fputs_filtered (paddress (pc
), gdb_stdout
);
4066 printf_filtered (".\n");
4070 /* Set the default place to put a breakpoint
4071 for the `break' command with no arguments. */
4074 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4077 default_breakpoint_valid
= valid
;
4078 default_breakpoint_address
= addr
;
4079 default_breakpoint_symtab
= symtab
;
4080 default_breakpoint_line
= line
;
4083 /* Return true iff it is meaningful to use the address member of
4084 BPT. For some breakpoint types, the address member is irrelevant
4085 and it makes no sense to attempt to compare it to other addresses
4086 (or use it for any other purpose either).
4088 More specifically, each of the following breakpoint types will always
4089 have a zero valued address and we don't want check_duplicates() to mark
4090 breakpoints of any of these types to be a duplicate of an actual
4091 breakpoint at address zero:
4094 bp_hardware_watchpoint
4096 bp_access_watchpoint
4103 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4105 enum bptype type
= bpt
->type
;
4107 return (type
!= bp_watchpoint
4108 && type
!= bp_hardware_watchpoint
4109 && type
!= bp_read_watchpoint
4110 && type
!= bp_access_watchpoint
4111 && type
!= bp_catch_exec
4112 && type
!= bp_longjmp_resume
4113 && type
!= bp_catch_fork
4114 && type
!= bp_catch_vfork
);
4117 /* Rescan breakpoints at the same address and section as BPT,
4118 marking the first one as "first" and any others as "duplicates".
4119 This is so that the bpt instruction is only inserted once.
4120 If we have a permanent breakpoint at the same place as BPT, make
4121 that one the official one, and the rest as duplicates. */
4124 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4126 struct bp_location
*b
;
4128 struct bp_location
*perm_bp
= 0;
4130 ALL_BP_LOCATIONS (b
)
4131 if (b
->owner
->enable_state
!= bp_disabled
4132 && b
->owner
->enable_state
!= bp_call_disabled
4134 && !b
->shlib_disabled
4135 && b
->address
== address
/* address / overlay match */
4136 && (!overlay_debugging
|| b
->section
== section
)
4137 && breakpoint_address_is_meaningful (b
->owner
))
4139 /* Have we found a permanent breakpoint? */
4140 if (b
->owner
->enable_state
== bp_permanent
)
4147 b
->duplicate
= count
> 1;
4150 /* If we found a permanent breakpoint at this address, go over the
4151 list again and declare all the other breakpoints there to be the
4155 perm_bp
->duplicate
= 0;
4157 /* Permanent breakpoint should always be inserted. */
4158 if (! perm_bp
->inserted
)
4159 internal_error (__FILE__
, __LINE__
,
4160 _("allegedly permanent breakpoint is not "
4161 "actually inserted"));
4163 ALL_BP_LOCATIONS (b
)
4166 if (b
->owner
->enable_state
!= bp_disabled
4167 && b
->owner
->enable_state
!= bp_call_disabled
4168 && b
->enabled
&& !b
->shlib_disabled
4169 && b
->address
== address
/* address / overlay match */
4170 && (!overlay_debugging
|| b
->section
== section
)
4171 && breakpoint_address_is_meaningful (b
->owner
))
4174 internal_error (__FILE__
, __LINE__
,
4175 _("another breakpoint was inserted on top of "
4176 "a permanent breakpoint"));
4185 check_duplicates (struct breakpoint
*bpt
)
4187 struct bp_location
*bl
= bpt
->loc
;
4189 if (! breakpoint_address_is_meaningful (bpt
))
4192 for (; bl
; bl
= bl
->next
)
4193 check_duplicates_for (bl
->address
, bl
->section
);
4197 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4198 int bnum
, int have_bnum
)
4203 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4204 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4206 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4207 bnum
, astr1
, astr2
);
4209 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4212 /* Adjust a breakpoint's address to account for architectural constraints
4213 on breakpoint placement. Return the adjusted address. Note: Very
4214 few targets require this kind of adjustment. For most targets,
4215 this function is simply the identity function. */
4218 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4220 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4222 /* Very few targets need any kind of breakpoint adjustment. */
4225 else if (bptype
== bp_watchpoint
4226 || bptype
== bp_hardware_watchpoint
4227 || bptype
== bp_read_watchpoint
4228 || bptype
== bp_access_watchpoint
4229 || bptype
== bp_catch_fork
4230 || bptype
== bp_catch_vfork
4231 || bptype
== bp_catch_exec
)
4233 /* Watchpoints and the various bp_catch_* eventpoints should not
4234 have their addresses modified. */
4239 CORE_ADDR adjusted_bpaddr
;
4241 /* Some targets have architectural constraints on the placement
4242 of breakpoint instructions. Obtain the adjusted address. */
4243 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4246 /* An adjusted breakpoint address can significantly alter
4247 a user's expectations. Print a warning if an adjustment
4249 if (adjusted_bpaddr
!= bpaddr
)
4250 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4252 return adjusted_bpaddr
;
4256 /* Allocate a struct bp_location. */
4258 static struct bp_location
*
4259 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4261 struct bp_location
*loc
, *loc_p
;
4263 loc
= xmalloc (sizeof (struct bp_location
));
4264 memset (loc
, 0, sizeof (*loc
));
4268 loc
->shlib_disabled
= 0;
4277 case bp_longjmp_resume
:
4278 case bp_step_resume
:
4279 case bp_watchpoint_scope
:
4281 case bp_shlib_event
:
4282 case bp_thread_event
:
4283 case bp_overlay_event
:
4285 case bp_catch_unload
:
4286 loc
->loc_type
= bp_loc_software_breakpoint
;
4288 case bp_hardware_breakpoint
:
4289 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4291 case bp_hardware_watchpoint
:
4292 case bp_read_watchpoint
:
4293 case bp_access_watchpoint
:
4294 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4298 case bp_catch_vfork
:
4300 loc
->loc_type
= bp_loc_other
;
4303 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4309 static void free_bp_location (struct bp_location
*loc
)
4314 if (loc
->function_name
)
4315 xfree (loc
->function_name
);
4320 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4321 that has type BPTYPE and has no locations as yet. */
4323 static struct breakpoint
*
4324 set_raw_breakpoint_without_location (enum bptype bptype
)
4326 struct breakpoint
*b
, *b1
;
4328 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4329 memset (b
, 0, sizeof (*b
));
4332 b
->language
= current_language
->la_language
;
4333 b
->input_radix
= input_radix
;
4335 b
->enable_state
= bp_enabled
;
4338 b
->ignore_count
= 0;
4340 b
->frame_id
= null_frame_id
;
4341 b
->dll_pathname
= NULL
;
4342 b
->triggered_dll_pathname
= NULL
;
4343 b
->forked_inferior_pid
= 0;
4344 b
->exec_pathname
= NULL
;
4346 b
->condition_not_parsed
= 0;
4348 /* Add this breakpoint to the end of the chain
4349 so that a list of breakpoints will come out in order
4350 of increasing numbers. */
4352 b1
= breakpoint_chain
;
4354 breakpoint_chain
= b
;
4364 /* Initialize loc->function_name. */
4366 set_breakpoint_location_function (struct bp_location
*loc
)
4368 if (loc
->owner
->type
== bp_breakpoint
4369 || loc
->owner
->type
== bp_hardware_breakpoint
)
4371 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4373 if (loc
->function_name
)
4374 loc
->function_name
= xstrdup (loc
->function_name
);
4378 /* set_raw_breakpoint is a low level routine for allocating and
4379 partially initializing a breakpoint of type BPTYPE. The newly
4380 created breakpoint's address, section, source file name, and line
4381 number are provided by SAL. The newly created and partially
4382 initialized breakpoint is added to the breakpoint chain and
4383 is also returned as the value of this function.
4385 It is expected that the caller will complete the initialization of
4386 the newly created breakpoint struct as well as output any status
4387 information regarding the creation of a new breakpoint. In
4388 particular, set_raw_breakpoint does NOT set the breakpoint
4389 number! Care should be taken to not allow an error to occur
4390 prior to completing the initialization of the breakpoint. If this
4391 should happen, a bogus breakpoint will be left on the chain. */
4394 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4396 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4397 CORE_ADDR adjusted_address
;
4399 /* Adjust the breakpoint's address prior to allocating a location.
4400 Once we call allocate_bp_location(), that mostly uninitialized
4401 location will be placed on the location chain. Adjustment of the
4402 breakpoint may cause target_read_memory() to be called and we do
4403 not want its scan of the location chain to find a breakpoint and
4404 location that's only been partially initialized. */
4405 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4407 b
->loc
= allocate_bp_location (b
, bptype
);
4408 b
->loc
->requested_address
= sal
.pc
;
4409 b
->loc
->address
= adjusted_address
;
4411 if (sal
.symtab
== NULL
)
4412 b
->source_file
= NULL
;
4414 b
->source_file
= savestring (sal
.symtab
->filename
,
4415 strlen (sal
.symtab
->filename
));
4416 b
->loc
->section
= sal
.section
;
4417 b
->line_number
= sal
.line
;
4419 set_breakpoint_location_function (b
->loc
);
4421 breakpoints_changed ();
4427 /* Note that the breakpoint object B describes a permanent breakpoint
4428 instruction, hard-wired into the inferior's code. */
4430 make_breakpoint_permanent (struct breakpoint
*b
)
4432 struct bp_location
*bl
;
4433 b
->enable_state
= bp_permanent
;
4435 /* By definition, permanent breakpoints are already present in the code.
4436 Mark all locations as inserted. For now, make_breakpoint_permanent
4437 is called in just one place, so it's hard to say if it's reasonable
4438 to have permanent breakpoint with multiple locations or not,
4439 but it's easy to implmement. */
4440 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4444 static struct breakpoint
*
4445 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4447 static int internal_breakpoint_number
= -1;
4448 struct symtab_and_line sal
;
4449 struct breakpoint
*b
;
4451 init_sal (&sal
); /* initialize to zeroes */
4454 sal
.section
= find_pc_overlay (sal
.pc
);
4456 b
= set_raw_breakpoint (sal
, type
);
4457 b
->number
= internal_breakpoint_number
--;
4458 b
->disposition
= disp_donttouch
;
4465 create_longjmp_breakpoint (char *func_name
)
4467 struct breakpoint
*b
;
4468 struct minimal_symbol
*m
;
4470 if (func_name
== NULL
)
4471 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4474 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4477 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4480 b
->enable_state
= bp_disabled
;
4483 b
->addr_string
= xstrdup (func_name
);
4484 update_global_location_list ();
4487 /* Call this routine when stepping and nexting to enable a breakpoint
4488 if we do a longjmp(). When we hit that breakpoint, call
4489 set_longjmp_resume_breakpoint() to figure out where we are going. */
4492 enable_longjmp_breakpoint (void)
4494 struct breakpoint
*b
;
4497 if (b
->type
== bp_longjmp
)
4499 b
->enable_state
= bp_enabled
;
4500 update_global_location_list ();
4505 disable_longjmp_breakpoint (void)
4507 struct breakpoint
*b
;
4510 if (b
->type
== bp_longjmp
4511 || b
->type
== bp_longjmp_resume
)
4513 b
->enable_state
= bp_disabled
;
4514 update_global_location_list ();
4519 create_overlay_event_breakpoint (char *func_name
)
4521 struct breakpoint
*b
;
4522 struct minimal_symbol
*m
;
4524 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4527 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4529 b
->addr_string
= xstrdup (func_name
);
4531 if (overlay_debugging
== ovly_auto
)
4533 b
->enable_state
= bp_enabled
;
4534 overlay_events_enabled
= 1;
4538 b
->enable_state
= bp_disabled
;
4539 overlay_events_enabled
= 0;
4541 update_global_location_list ();
4545 enable_overlay_breakpoints (void)
4547 struct breakpoint
*b
;
4550 if (b
->type
== bp_overlay_event
)
4552 b
->enable_state
= bp_enabled
;
4553 update_global_location_list ();
4554 overlay_events_enabled
= 1;
4559 disable_overlay_breakpoints (void)
4561 struct breakpoint
*b
;
4564 if (b
->type
== bp_overlay_event
)
4566 b
->enable_state
= bp_disabled
;
4567 update_global_location_list ();
4568 overlay_events_enabled
= 0;
4573 create_thread_event_breakpoint (CORE_ADDR address
)
4575 struct breakpoint
*b
;
4577 b
= create_internal_breakpoint (address
, bp_thread_event
);
4579 b
->enable_state
= bp_enabled
;
4580 /* addr_string has to be used or breakpoint_re_set will delete me. */
4581 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4583 update_global_location_list_nothrow ();
4589 remove_thread_event_breakpoints (void)
4591 struct breakpoint
*b
, *temp
;
4593 ALL_BREAKPOINTS_SAFE (b
, temp
)
4594 if (b
->type
== bp_thread_event
)
4595 delete_breakpoint (b
);
4598 struct captured_parse_breakpoint_args
4601 struct symtabs_and_lines
*sals_p
;
4602 char ***addr_string_p
;
4606 struct lang_and_radix
4614 remove_solib_event_breakpoints (void)
4616 struct breakpoint
*b
, *temp
;
4618 ALL_BREAKPOINTS_SAFE (b
, temp
)
4619 if (b
->type
== bp_shlib_event
)
4620 delete_breakpoint (b
);
4624 create_solib_event_breakpoint (CORE_ADDR address
)
4626 struct breakpoint
*b
;
4628 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4629 update_global_location_list_nothrow ();
4633 /* Disable any breakpoints that are on code in shared libraries. Only
4634 apply to enabled breakpoints, disabled ones can just stay disabled. */
4637 disable_breakpoints_in_shlibs (void)
4639 struct bp_location
*loc
;
4640 int disabled_shlib_breaks
= 0;
4642 ALL_BP_LOCATIONS (loc
)
4644 struct breakpoint
*b
= loc
->owner
;
4645 /* We apply the check to all breakpoints, including disabled
4646 for those with loc->duplicate set. This is so that when breakpoint
4647 becomes enabled, or the duplicate is removed, gdb will try to insert
4648 all breakpoints. If we don't set shlib_disabled here, we'll try
4649 to insert those breakpoints and fail. */
4650 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4651 && !loc
->shlib_disabled
4653 && PC_SOLIB (loc
->address
)
4655 && solib_address (loc
->address
)
4659 loc
->shlib_disabled
= 1;
4664 /* Disable any breakpoints that are in in an unloaded shared library. Only
4665 apply to enabled breakpoints, disabled ones can just stay disabled. */
4668 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4670 struct bp_location
*loc
;
4671 int disabled_shlib_breaks
= 0;
4673 ALL_BP_LOCATIONS (loc
)
4675 struct breakpoint
*b
= loc
->owner
;
4676 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4677 || loc
->loc_type
== bp_loc_software_breakpoint
)
4678 && !loc
->shlib_disabled
)
4681 char *so_name
= PC_SOLIB (loc
->address
);
4683 char *so_name
= solib_address (loc
->address
);
4685 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4687 loc
->shlib_disabled
= 1;
4688 /* At this point, we cannot rely on remove_breakpoint
4689 succeeding so we must mark the breakpoint as not inserted
4690 to prevent future errors occurring in remove_breakpoints. */
4692 if (!disabled_shlib_breaks
)
4694 target_terminal_ours_for_output ();
4695 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4698 disabled_shlib_breaks
= 1;
4705 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4706 enum bptype bp_kind
)
4708 struct symtab_and_line sal
;
4709 struct breakpoint
*b
;
4710 int thread
= -1; /* All threads. */
4717 b
= set_raw_breakpoint (sal
, bp_kind
);
4718 set_breakpoint_count (breakpoint_count
+ 1);
4719 b
->number
= breakpoint_count
;
4720 b
->cond_string
= (cond_string
== NULL
) ?
4721 NULL
: savestring (cond_string
, strlen (cond_string
));
4723 b
->addr_string
= NULL
;
4724 b
->enable_state
= bp_enabled
;
4725 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4726 b
->forked_inferior_pid
= 0;
4727 update_global_location_list ();
4734 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4736 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4740 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4742 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4746 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4748 struct symtab_and_line sal
;
4749 struct breakpoint
*b
;
4750 int thread
= -1; /* All threads. */
4757 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4758 set_breakpoint_count (breakpoint_count
+ 1);
4759 b
->number
= breakpoint_count
;
4760 b
->cond_string
= (cond_string
== NULL
) ?
4761 NULL
: savestring (cond_string
, strlen (cond_string
));
4763 b
->addr_string
= NULL
;
4764 b
->enable_state
= bp_enabled
;
4765 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4766 update_global_location_list ();
4772 hw_breakpoint_used_count (void)
4774 struct breakpoint
*b
;
4779 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4787 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4789 struct breakpoint
*b
;
4792 *other_type_used
= 0;
4795 if (breakpoint_enabled (b
))
4797 if (b
->type
== type
)
4799 else if ((b
->type
== bp_hardware_watchpoint
||
4800 b
->type
== bp_read_watchpoint
||
4801 b
->type
== bp_access_watchpoint
))
4802 *other_type_used
= 1;
4808 /* Call this after hitting the longjmp() breakpoint. Use this to set
4809 a new breakpoint at the target of the jmp_buf.
4811 FIXME - This ought to be done by setting a temporary breakpoint
4812 that gets deleted automatically... */
4815 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4817 struct breakpoint
*b
;
4820 if (b
->type
== bp_longjmp_resume
)
4822 b
->loc
->requested_address
= pc
;
4823 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4825 b
->enable_state
= bp_enabled
;
4826 b
->frame_id
= frame_id
;
4827 update_global_location_list ();
4833 disable_watchpoints_before_interactive_call_start (void)
4835 struct breakpoint
*b
;
4839 if (((b
->type
== bp_watchpoint
)
4840 || (b
->type
== bp_hardware_watchpoint
)
4841 || (b
->type
== bp_read_watchpoint
)
4842 || (b
->type
== bp_access_watchpoint
))
4843 && breakpoint_enabled (b
))
4845 b
->enable_state
= bp_call_disabled
;
4846 update_global_location_list ();
4852 enable_watchpoints_after_interactive_call_stop (void)
4854 struct breakpoint
*b
;
4858 if (((b
->type
== bp_watchpoint
)
4859 || (b
->type
== bp_hardware_watchpoint
)
4860 || (b
->type
== bp_read_watchpoint
)
4861 || (b
->type
== bp_access_watchpoint
))
4862 && (b
->enable_state
== bp_call_disabled
))
4864 b
->enable_state
= bp_enabled
;
4865 update_global_location_list ();
4871 /* Set a breakpoint that will evaporate an end of command
4872 at address specified by SAL.
4873 Restrict it to frame FRAME if FRAME is nonzero. */
4876 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4879 struct breakpoint
*b
;
4880 b
= set_raw_breakpoint (sal
, type
);
4881 b
->enable_state
= bp_enabled
;
4882 b
->disposition
= disp_donttouch
;
4883 b
->frame_id
= frame_id
;
4885 /* If we're debugging a multi-threaded program, then we
4886 want momentary breakpoints to be active in only a
4887 single thread of control. */
4888 if (in_thread_list (inferior_ptid
))
4889 b
->thread
= pid_to_thread_id (inferior_ptid
);
4891 update_global_location_list_nothrow ();
4897 /* Tell the user we have just set a breakpoint B. */
4900 mention (struct breakpoint
*b
)
4903 struct cleanup
*old_chain
, *ui_out_chain
;
4904 struct ui_stream
*stb
;
4906 stb
= ui_out_stream_new (uiout
);
4907 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4909 /* FIXME: This is misplaced; mention() is called by things (like
4910 hitting a watchpoint) other than breakpoint creation. It should
4911 be possible to clean this up and at the same time replace the
4912 random calls to breakpoint_changed with this hook, as has already
4913 been done for deprecated_delete_breakpoint_hook and so on. */
4914 if (deprecated_create_breakpoint_hook
)
4915 deprecated_create_breakpoint_hook (b
);
4916 breakpoint_create_event (b
->number
);
4918 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4919 b
->ops
->print_mention (b
);
4924 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4927 ui_out_text (uiout
, "Watchpoint ");
4928 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4929 ui_out_field_int (uiout
, "number", b
->number
);
4930 ui_out_text (uiout
, ": ");
4931 print_expression (b
->exp
, stb
->stream
);
4932 ui_out_field_stream (uiout
, "exp", stb
);
4933 do_cleanups (ui_out_chain
);
4935 case bp_hardware_watchpoint
:
4936 ui_out_text (uiout
, "Hardware watchpoint ");
4937 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4938 ui_out_field_int (uiout
, "number", b
->number
);
4939 ui_out_text (uiout
, ": ");
4940 print_expression (b
->exp
, stb
->stream
);
4941 ui_out_field_stream (uiout
, "exp", stb
);
4942 do_cleanups (ui_out_chain
);
4944 case bp_read_watchpoint
:
4945 ui_out_text (uiout
, "Hardware read watchpoint ");
4946 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4947 ui_out_field_int (uiout
, "number", b
->number
);
4948 ui_out_text (uiout
, ": ");
4949 print_expression (b
->exp
, stb
->stream
);
4950 ui_out_field_stream (uiout
, "exp", stb
);
4951 do_cleanups (ui_out_chain
);
4953 case bp_access_watchpoint
:
4954 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4955 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4956 ui_out_field_int (uiout
, "number", b
->number
);
4957 ui_out_text (uiout
, ": ");
4958 print_expression (b
->exp
, stb
->stream
);
4959 ui_out_field_stream (uiout
, "exp", stb
);
4960 do_cleanups (ui_out_chain
);
4963 if (ui_out_is_mi_like_p (uiout
))
4968 if (b
->disposition
== disp_del
)
4969 printf_filtered (_("Temporary breakpoint"));
4971 printf_filtered (_("Breakpoint"));
4972 printf_filtered (_(" %d"), b
->number
);
4975 case bp_hardware_breakpoint
:
4976 if (ui_out_is_mi_like_p (uiout
))
4981 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4985 case bp_catch_unload
:
4986 printf_filtered (_("Catchpoint %d (%s %s)"),
4988 (b
->type
== bp_catch_load
) ? "load" : "unload",
4989 (b
->dll_pathname
!= NULL
) ?
4990 b
->dll_pathname
: "<any library>");
4993 case bp_catch_vfork
:
4994 printf_filtered (_("Catchpoint %d (%s)"),
4996 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4999 printf_filtered (_("Catchpoint %d (exec)"),
5006 case bp_longjmp_resume
:
5007 case bp_step_resume
:
5009 case bp_watchpoint_scope
:
5010 case bp_shlib_event
:
5011 case bp_thread_event
:
5012 case bp_overlay_event
:
5018 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5022 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5026 if (addressprint
|| b
->source_file
== NULL
)
5028 printf_filtered (" at ");
5029 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5032 printf_filtered (": file %s, line %d.",
5033 b
->source_file
, b
->line_number
);
5037 struct bp_location
*loc
= b
->loc
;
5039 for (; loc
; loc
= loc
->next
)
5041 printf_filtered (" (%d locations)", n
);
5046 do_cleanups (old_chain
);
5047 if (ui_out_is_mi_like_p (uiout
))
5049 printf_filtered ("\n");
5053 static struct bp_location
*
5054 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5055 const struct symtab_and_line
*sal
)
5057 struct bp_location
*loc
, **tmp
;
5059 loc
= allocate_bp_location (b
, bptype
);
5060 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5063 loc
->requested_address
= sal
->pc
;
5064 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5066 loc
->section
= sal
->section
;
5068 set_breakpoint_location_function (loc
);
5072 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5073 as textual description of the location, and COND_STRING
5074 as condition expression. */
5077 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5079 enum bptype type
, enum bpdisp disposition
,
5080 int thread
, int ignore_count
,
5081 struct breakpoint_ops
*ops
, int from_tty
)
5083 struct breakpoint
*b
= NULL
;
5086 if (type
== bp_hardware_breakpoint
)
5088 int i
= hw_breakpoint_used_count ();
5089 int target_resources_ok
=
5090 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5092 if (target_resources_ok
== 0)
5093 error (_("No hardware breakpoint support in the target."));
5094 else if (target_resources_ok
< 0)
5095 error (_("Hardware breakpoints used exceeds limit."));
5098 for (i
= 0; i
< sals
.nelts
; ++i
)
5100 struct symtab_and_line sal
= sals
.sals
[i
];
5101 struct bp_location
*loc
;
5104 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5108 b
= set_raw_breakpoint (sal
, type
);
5109 set_breakpoint_count (breakpoint_count
+ 1);
5110 b
->number
= breakpoint_count
;
5113 b
->cond_string
= cond_string
;
5114 b
->ignore_count
= ignore_count
;
5115 b
->enable_state
= bp_enabled
;
5116 b
->disposition
= disposition
;
5122 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5127 char *arg
= b
->cond_string
;
5128 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5130 error (_("Garbage %s follows condition"), arg
);
5135 b
->addr_string
= addr_string
;
5137 /* addr_string has to be used or breakpoint_re_set will delete
5139 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5145 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5146 elements to fill the void space. */
5147 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5149 int i
= index_to_remove
+1;
5150 int last_index
= sal
->nelts
-1;
5152 for (;i
<= last_index
; ++i
)
5153 sal
->sals
[i
-1] = sal
->sals
[i
];
5158 /* If appropriate, obtains all sals that correspond
5159 to the same file and line as SAL. This is done
5160 only if SAL does not have explicit PC and has
5161 line and file information. If we got just a single
5162 expanded sal, return the original.
5164 Otherwise, if SAL.explicit_line is not set, filter out
5165 all sals for which the name of enclosing function
5166 is different from SAL. This makes sure that if we have
5167 breakpoint originally set in template instantiation, say
5168 foo<int>(), we won't expand SAL to locations at the same
5169 line in all existing instantiations of 'foo'.
5172 struct symtabs_and_lines
5173 expand_line_sal_maybe (struct symtab_and_line sal
)
5175 struct symtabs_and_lines expanded
;
5176 CORE_ADDR original_pc
= sal
.pc
;
5177 char *original_function
= NULL
;
5181 /* If we have explicit pc, don't expand.
5182 If we have no line number, we can't expand. */
5183 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5186 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5187 expanded
.sals
[0] = sal
;
5192 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5194 expanded
= expand_line_sal (sal
);
5195 if (expanded
.nelts
== 1)
5197 /* We had one sal, we got one sal. Without futher
5198 processing, just return the original sal. */
5199 xfree (expanded
.sals
);
5201 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5202 sal
.pc
= original_pc
;
5203 expanded
.sals
[0] = sal
;
5207 if (!sal
.explicit_line
)
5209 CORE_ADDR func_addr
, func_end
;
5210 for (i
= 0; i
< expanded
.nelts
; ++i
)
5212 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5213 char *this_function
;
5214 if (find_pc_partial_function (pc
, &this_function
,
5215 &func_addr
, &func_end
))
5217 if (this_function
&&
5218 strcmp (this_function
, original_function
) != 0)
5220 remove_sal (&expanded
, i
);
5223 else if (func_addr
== pc
)
5225 /* We're at beginning of a function, and should
5227 struct symbol
*sym
= find_pc_function (pc
);
5229 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5232 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5239 if (expanded
.nelts
<= 1)
5241 /* This is un ugly workaround. If we get zero
5242 expanded sals then something is really wrong.
5243 Fix that by returnign the original sal. */
5244 xfree (expanded
.sals
);
5246 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5247 sal
.pc
= original_pc
;
5248 expanded
.sals
[0] = sal
;
5255 for (i
= 0; i
< expanded
.nelts
; ++i
)
5256 if (expanded
.sals
[i
].pc
== original_pc
)
5267 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5268 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5269 value. COND_STRING, if not NULL, specified the condition to be
5270 used for all breakpoints. Essentially the only case where
5271 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5272 function. In that case, it's still not possible to specify
5273 separate conditions for different overloaded functions, so
5274 we take just a single condition string.
5276 NOTE: If the function succeeds, the caller is expected to cleanup
5277 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5278 array contents). If the function fails (error() is called), the
5279 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5280 COND and SALS arrays and each of those arrays contents. */
5283 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5285 enum bptype type
, enum bpdisp disposition
,
5286 int thread
, int ignore_count
,
5287 struct breakpoint_ops
*ops
, int from_tty
)
5290 for (i
= 0; i
< sals
.nelts
; ++i
)
5292 struct symtabs_and_lines expanded
=
5293 expand_line_sal_maybe (sals
.sals
[i
]);
5295 create_breakpoint (expanded
, addr_string
[i
],
5296 cond_string
, type
, disposition
,
5297 thread
, ignore_count
, ops
, from_tty
);
5300 update_global_location_list ();
5303 /* Parse ARG which is assumed to be a SAL specification possibly
5304 followed by conditionals. On return, SALS contains an array of SAL
5305 addresses found. ADDR_STRING contains a vector of (canonical)
5306 address strings. ARG points to the end of the SAL. */
5309 parse_breakpoint_sals (char **address
,
5310 struct symtabs_and_lines
*sals
,
5311 char ***addr_string
,
5314 char *addr_start
= *address
;
5315 *addr_string
= NULL
;
5316 /* If no arg given, or if first arg is 'if ', use the default
5318 if ((*address
) == NULL
5319 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5321 if (default_breakpoint_valid
)
5323 struct symtab_and_line sal
;
5324 init_sal (&sal
); /* initialize to zeroes */
5325 sals
->sals
= (struct symtab_and_line
*)
5326 xmalloc (sizeof (struct symtab_and_line
));
5327 sal
.pc
= default_breakpoint_address
;
5328 sal
.line
= default_breakpoint_line
;
5329 sal
.symtab
= default_breakpoint_symtab
;
5330 sal
.section
= find_pc_overlay (sal
.pc
);
5331 sals
->sals
[0] = sal
;
5335 error (_("No default breakpoint address now."));
5339 /* Force almost all breakpoints to be in terms of the
5340 current_source_symtab (which is decode_line_1's default). This
5341 should produce the results we want almost all of the time while
5342 leaving default_breakpoint_* alone.
5343 ObjC: However, don't match an Objective-C method name which
5344 may have a '+' or '-' succeeded by a '[' */
5346 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5348 if (default_breakpoint_valid
5350 || ((strchr ("+-", (*address
)[0]) != NULL
)
5351 && ((*address
)[1] != '['))))
5352 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5353 default_breakpoint_line
, addr_string
,
5356 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5357 addr_string
, not_found_ptr
);
5359 /* For any SAL that didn't have a canonical string, fill one in. */
5360 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5361 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5362 if (addr_start
!= (*address
))
5365 for (i
= 0; i
< sals
->nelts
; i
++)
5367 /* Add the string if not present. */
5368 if ((*addr_string
)[i
] == NULL
)
5369 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5375 /* Convert each SAL into a real PC. Verify that the PC can be
5376 inserted as a breakpoint. If it can't throw an error. */
5379 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5383 for (i
= 0; i
< sals
->nelts
; i
++)
5384 resolve_sal_pc (&sals
->sals
[i
]);
5388 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5390 struct captured_parse_breakpoint_args
*args
= data
;
5392 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5393 args
->not_found_ptr
);
5396 /* Given TOK, a string specification of condition and thread, as
5397 accepted by the 'break' command, extract the condition
5398 string and thread number and set *COND_STRING and *THREAD.
5399 PC identifies the context at which the condition should be parsed.
5400 If no condition is found, *COND_STRING is set to NULL.
5401 If no thread is found, *THREAD is set to -1. */
5403 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5404 char **cond_string
, int *thread
)
5406 *cond_string
= NULL
;
5412 char *cond_start
= NULL
;
5413 char *cond_end
= NULL
;
5414 while (*tok
== ' ' || *tok
== '\t')
5419 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5422 toklen
= end_tok
- tok
;
5424 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5426 tok
= cond_start
= end_tok
+ 1;
5427 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5429 *cond_string
= savestring (cond_start
,
5430 cond_end
- cond_start
);
5432 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5438 *thread
= strtol (tok
, &tok
, 0);
5440 error (_("Junk after thread keyword."));
5441 if (!valid_thread_id (*thread
))
5442 error (_("Unknown thread %d."), *thread
);
5445 error (_("Junk at end of arguments."));
5449 /* Set a breakpoint. This function is shared between
5450 CLI and MI functions for setting a breakpoint.
5451 This function has two major modes of operations,
5452 selected by the PARSE_CONDITION_AND_THREAD parameter.
5453 If non-zero, the function will parse arg, extracting
5454 breakpoint location, address and thread. Otherwise,
5455 ARG is just the location of breakpoint, with condition
5456 and thread specified by the COND_STRING and THREAD
5460 break_command_really (char *arg
, char *cond_string
, int thread
,
5461 int parse_condition_and_thread
,
5462 int tempflag
, int hardwareflag
,
5464 enum auto_boolean pending_break_support
,
5465 struct breakpoint_ops
*ops
,
5468 struct gdb_exception e
;
5469 struct symtabs_and_lines sals
;
5470 struct symtab_and_line pending_sal
;
5473 char *addr_start
= arg
;
5475 struct cleanup
*old_chain
;
5476 struct cleanup
*breakpoint_chain
= NULL
;
5477 struct captured_parse_breakpoint_args parse_args
;
5486 parse_args
.arg_p
= &arg
;
5487 parse_args
.sals_p
= &sals
;
5488 parse_args
.addr_string_p
= &addr_string
;
5489 parse_args
.not_found_ptr
= ¬_found
;
5491 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5492 &parse_args
, RETURN_MASK_ALL
);
5494 /* If caller is interested in rc value from parse, set value. */
5498 throw_exception (e
);
5502 case NOT_FOUND_ERROR
:
5504 /* If pending breakpoint support is turned off, throw
5507 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5508 throw_exception (e
);
5510 exception_print (gdb_stderr
, e
);
5512 /* If pending breakpoint support is auto query and the user
5513 selects no, then simply return the error code. */
5514 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5515 !nquery ("Make breakpoint pending on future shared library load? "))
5518 /* At this point, either the user was queried about setting
5519 a pending breakpoint and selected yes, or pending
5520 breakpoint behavior is on and thus a pending breakpoint
5521 is defaulted on behalf of the user. */
5522 copy_arg
= xstrdup (addr_start
);
5523 addr_string
= ©_arg
;
5525 sals
.sals
= &pending_sal
;
5530 throw_exception (e
);
5537 /* Create a chain of things that always need to be cleaned up. */
5538 old_chain
= make_cleanup (null_cleanup
, 0);
5542 /* Make sure that all storage allocated to SALS gets freed. */
5543 make_cleanup (xfree
, sals
.sals
);
5545 /* Cleanup the addr_string array but not its contents. */
5546 make_cleanup (xfree
, addr_string
);
5549 /* ----------------------------- SNIP -----------------------------
5550 Anything added to the cleanup chain beyond this point is assumed
5551 to be part of a breakpoint. If the breakpoint create succeeds
5552 then the memory is not reclaimed. */
5553 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5555 /* Mark the contents of the addr_string for cleanup. These go on
5556 the breakpoint_chain and only occure if the breakpoint create
5558 for (i
= 0; i
< sals
.nelts
; i
++)
5560 if (addr_string
[i
] != NULL
)
5561 make_cleanup (xfree
, addr_string
[i
]);
5564 /* Resolve all line numbers to PC's and verify that the addresses
5565 are ok for the target. */
5567 breakpoint_sals_to_pc (&sals
, addr_start
);
5569 /* Verify that condition can be parsed, before setting any
5570 breakpoints. Allocate a separate condition expression for each
5574 if (parse_condition_and_thread
)
5576 /* Here we only parse 'arg' to separate condition
5577 from thread number, so parsing in context of first
5578 sal is OK. When setting the breakpoint we'll
5579 re-parse it in context of each sal. */
5582 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5584 make_cleanup (xfree
, cond_string
);
5588 /* Create a private copy of condition string. */
5591 cond_string
= xstrdup (cond_string
);
5592 make_cleanup (xfree
, cond_string
);
5595 create_breakpoints (sals
, addr_string
, cond_string
,
5596 hardwareflag
? bp_hardware_breakpoint
5598 tempflag
? disp_del
: disp_donttouch
,
5599 thread
, ignore_count
, ops
, from_tty
);
5603 struct symtab_and_line sal
= {0};
5604 struct breakpoint
*b
;
5606 make_cleanup (xfree
, copy_arg
);
5608 b
= set_raw_breakpoint_without_location (hardwareflag
5609 ? bp_hardware_breakpoint
5611 set_breakpoint_count (breakpoint_count
+ 1);
5612 b
->number
= breakpoint_count
;
5614 b
->addr_string
= addr_string
[0];
5615 b
->cond_string
= NULL
;
5616 b
->ignore_count
= ignore_count
;
5617 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5618 b
->condition_not_parsed
= 1;
5621 update_global_location_list ();
5626 warning (_("Multiple breakpoints were set.\n"
5627 "Use the \"delete\" command to delete unwanted breakpoints."));
5628 /* That's it. Discard the cleanups for data inserted into the
5630 discard_cleanups (breakpoint_chain
);
5631 /* But cleanup everything else. */
5632 do_cleanups (old_chain
);
5635 /* Set a breakpoint.
5636 ARG is a string describing breakpoint address,
5637 condition, and thread.
5638 FLAG specifies if a breakpoint is hardware on,
5639 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5643 break_command_1 (char *arg
, int flag
, int from_tty
)
5645 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5646 int tempflag
= flag
& BP_TEMPFLAG
;
5648 break_command_really (arg
,
5649 NULL
, 0, 1 /* parse arg */,
5650 tempflag
, hardwareflag
,
5651 0 /* Ignore count */,
5652 pending_break_support
,
5653 NULL
/* breakpoint_ops */,
5659 set_breakpoint (char *address
, char *condition
,
5660 int hardwareflag
, int tempflag
,
5661 int thread
, int ignore_count
,
5664 break_command_really (address
, condition
, thread
,
5665 0 /* condition and thread are valid. */,
5666 tempflag
, hardwareflag
,
5669 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5673 /* Adjust SAL to the first instruction past the function prologue.
5674 The end of the prologue is determined using the line table from
5675 the debugging information.
5677 If SAL is already past the prologue, then do nothing. */
5680 skip_prologue_sal (struct symtab_and_line
*sal
)
5682 struct symbol
*sym
= find_pc_function (sal
->pc
);
5683 struct symtab_and_line start_sal
;
5688 start_sal
= find_function_start_sal (sym
, 1);
5689 if (sal
->pc
< start_sal
.pc
)
5693 /* Helper function for break_command_1 and disassemble_command. */
5696 resolve_sal_pc (struct symtab_and_line
*sal
)
5700 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5702 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5703 error (_("No line %d in file \"%s\"."),
5704 sal
->line
, sal
->symtab
->filename
);
5707 /* If this SAL corresponds to a breakpoint inserted using
5708 a line number, then skip the function prologue if necessary. */
5709 if (sal
->explicit_line
)
5710 skip_prologue_sal (sal
);
5713 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5715 struct blockvector
*bv
;
5719 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5722 sym
= block_function (b
);
5725 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5726 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5730 /* It really is worthwhile to have the section, so we'll just
5731 have to look harder. This case can be executed if we have
5732 line numbers but no functions (as can happen in assembly
5735 struct minimal_symbol
*msym
;
5737 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5739 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5746 break_command (char *arg
, int from_tty
)
5748 break_command_1 (arg
, 0, from_tty
);
5752 tbreak_command (char *arg
, int from_tty
)
5754 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5758 hbreak_command (char *arg
, int from_tty
)
5760 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5764 thbreak_command (char *arg
, int from_tty
)
5766 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5770 stop_command (char *arg
, int from_tty
)
5772 printf_filtered (_("Specify the type of breakpoint to set.\n\
5773 Usage: stop in <function | address>\n\
5774 stop at <line>\n"));
5778 stopin_command (char *arg
, int from_tty
)
5782 if (arg
== (char *) NULL
)
5784 else if (*arg
!= '*')
5789 /* look for a ':'. If this is a line number specification, then
5790 say it is bad, otherwise, it should be an address or
5791 function/method name */
5792 while (*argptr
&& !hasColon
)
5794 hasColon
= (*argptr
== ':');
5799 badInput
= (*argptr
!= ':'); /* Not a class::method */
5801 badInput
= isdigit (*arg
); /* a simple line number */
5805 printf_filtered (_("Usage: stop in <function | address>\n"));
5807 break_command_1 (arg
, 0, from_tty
);
5811 stopat_command (char *arg
, int from_tty
)
5815 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5822 /* look for a ':'. If there is a '::' then get out, otherwise
5823 it is probably a line number. */
5824 while (*argptr
&& !hasColon
)
5826 hasColon
= (*argptr
== ':');
5831 badInput
= (*argptr
== ':'); /* we have class::method */
5833 badInput
= !isdigit (*arg
); /* not a line number */
5837 printf_filtered (_("Usage: stop at <line>\n"));
5839 break_command_1 (arg
, 0, from_tty
);
5842 /* accessflag: hw_write: watch write,
5843 hw_read: watch read,
5844 hw_access: watch access (read or write) */
5846 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5848 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5849 struct symtab_and_line sal
;
5850 struct expression
*exp
;
5851 struct block
*exp_valid_block
;
5852 struct value
*val
, *mark
;
5853 struct frame_info
*frame
;
5854 struct frame_info
*prev_frame
= NULL
;
5855 char *exp_start
= NULL
;
5856 char *exp_end
= NULL
;
5857 char *tok
, *id_tok_start
, *end_tok
;
5859 char *cond_start
= NULL
;
5860 char *cond_end
= NULL
;
5861 struct expression
*cond
= NULL
;
5862 int i
, other_type_used
, target_resources_ok
= 0;
5863 enum bptype bp_type
;
5867 init_sal (&sal
); /* initialize to zeroes */
5869 /* Make sure that we actually have parameters to parse. */
5870 if (arg
!= NULL
&& arg
[0] != '\0')
5872 toklen
= strlen (arg
); /* Size of argument list. */
5874 /* Points tok to the end of the argument list. */
5875 tok
= arg
+ toklen
- 1;
5877 /* Go backwards in the parameters list. Skip the last parameter.
5878 If we're expecting a 'thread <thread_num>' parameter, this should
5879 be the thread identifier. */
5880 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5882 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5885 /* Points end_tok to the beginning of the last token. */
5886 id_tok_start
= tok
+ 1;
5888 /* Go backwards in the parameters list. Skip one more parameter.
5889 If we're expecting a 'thread <thread_num>' parameter, we should
5890 reach a "thread" token. */
5891 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5896 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5899 /* Move the pointer forward to skip the whitespace and
5900 calculate the length of the token. */
5902 toklen
= end_tok
- tok
;
5904 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5906 /* At this point we've found a "thread" token, which means
5907 the user is trying to set a watchpoint that triggers
5908 only in a specific thread. */
5911 /* Extract the thread ID from the next token. */
5912 thread
= strtol (id_tok_start
, &endp
, 0);
5914 /* Check if the user provided a valid numeric value for the
5916 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5917 error (_("Invalid thread ID specification %s."), id_tok_start
);
5919 /* Check if the thread actually exists. */
5920 if (!valid_thread_id (thread
))
5921 error (_("Unknown thread %d."), thread
);
5923 /* Truncate the string and get rid of the thread <thread_num>
5924 parameter before the parameter list is parsed by the
5925 evaluate_expression() function. */
5930 /* Parse the rest of the arguments. */
5931 innermost_block
= NULL
;
5933 exp
= parse_exp_1 (&arg
, 0, 0);
5935 exp_valid_block
= innermost_block
;
5936 mark
= value_mark ();
5937 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5939 release_value (val
);
5942 while (*tok
== ' ' || *tok
== '\t')
5946 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5949 toklen
= end_tok
- tok
;
5950 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5952 tok
= cond_start
= end_tok
+ 1;
5953 cond
= parse_exp_1 (&tok
, 0, 0);
5957 error (_("Junk at end of command."));
5959 if (accessflag
== hw_read
)
5960 bp_type
= bp_read_watchpoint
;
5961 else if (accessflag
== hw_access
)
5962 bp_type
= bp_access_watchpoint
;
5964 bp_type
= bp_hardware_watchpoint
;
5966 mem_cnt
= can_use_hardware_watchpoint (val
);
5967 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5968 error (_("Expression cannot be implemented with read/access watchpoint."));
5971 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5972 target_resources_ok
=
5973 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5975 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5976 error (_("Target does not support this type of hardware watchpoint."));
5978 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5979 error (_("Target can only support one kind of HW watchpoint at a time."));
5982 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5983 watchpoint could not be set. */
5984 if (!mem_cnt
|| target_resources_ok
<= 0)
5985 bp_type
= bp_watchpoint
;
5987 frame
= block_innermost_frame (exp_valid_block
);
5989 prev_frame
= get_prev_frame (frame
);
5993 /* If the expression is "local", then set up a "watchpoint scope"
5994 breakpoint at the point where we've left the scope of the watchpoint
5995 expression. Create the scope breakpoint before the watchpoint, so
5996 that we will encounter it first in bpstat_stop_status. */
5997 if (innermost_block
&& prev_frame
)
5999 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6000 bp_watchpoint_scope
);
6002 scope_breakpoint
->enable_state
= bp_enabled
;
6004 /* Automatically delete the breakpoint when it hits. */
6005 scope_breakpoint
->disposition
= disp_del
;
6007 /* Only break in the proper frame (help with recursion). */
6008 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6010 /* Set the address at which we will stop. */
6011 scope_breakpoint
->loc
->requested_address
6012 = get_frame_pc (prev_frame
);
6013 scope_breakpoint
->loc
->address
6014 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6015 scope_breakpoint
->type
);
6018 /* Now set up the breakpoint. */
6019 b
= set_raw_breakpoint (sal
, bp_type
);
6020 set_breakpoint_count (breakpoint_count
+ 1);
6021 b
->number
= breakpoint_count
;
6023 b
->disposition
= disp_donttouch
;
6025 b
->exp_valid_block
= exp_valid_block
;
6026 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6029 b
->loc
->cond
= cond
;
6031 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6036 b
->watchpoint_frame
= get_frame_id (frame
);
6038 b
->watchpoint_frame
= null_frame_id
;
6040 if (scope_breakpoint
!= NULL
)
6042 /* The scope breakpoint is related to the watchpoint. We will
6043 need to act on them together. */
6044 b
->related_breakpoint
= scope_breakpoint
;
6045 scope_breakpoint
->related_breakpoint
= b
;
6048 value_free_to_mark (mark
);
6050 update_global_location_list ();
6053 /* Return count of locations need to be watched and can be handled
6054 in hardware. If the watchpoint can not be handled
6055 in hardware return zero. */
6058 can_use_hardware_watchpoint (struct value
*v
)
6060 int found_memory_cnt
= 0;
6061 struct value
*head
= v
;
6063 /* Did the user specifically forbid us to use hardware watchpoints? */
6064 if (!can_use_hw_watchpoints
)
6067 /* Make sure that the value of the expression depends only upon
6068 memory contents, and values computed from them within GDB. If we
6069 find any register references or function calls, we can't use a
6070 hardware watchpoint.
6072 The idea here is that evaluating an expression generates a series
6073 of values, one holding the value of every subexpression. (The
6074 expression a*b+c has five subexpressions: a, b, a*b, c, and
6075 a*b+c.) GDB's values hold almost enough information to establish
6076 the criteria given above --- they identify memory lvalues,
6077 register lvalues, computed values, etcetera. So we can evaluate
6078 the expression, and then scan the chain of values that leaves
6079 behind to decide whether we can detect any possible change to the
6080 expression's final value using only hardware watchpoints.
6082 However, I don't think that the values returned by inferior
6083 function calls are special in any way. So this function may not
6084 notice that an expression involving an inferior function call
6085 can't be watched with hardware watchpoints. FIXME. */
6086 for (; v
; v
= value_next (v
))
6088 if (VALUE_LVAL (v
) == lval_memory
)
6091 /* A lazy memory lvalue is one that GDB never needed to fetch;
6092 we either just used its address (e.g., `a' in `a.b') or
6093 we never needed it at all (e.g., `a' in `a,b'). */
6097 /* Ahh, memory we actually used! Check if we can cover
6098 it with hardware watchpoints. */
6099 struct type
*vtype
= check_typedef (value_type (v
));
6101 /* We only watch structs and arrays if user asked for it
6102 explicitly, never if they just happen to appear in a
6103 middle of some value chain. */
6105 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6106 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6108 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6109 int len
= TYPE_LENGTH (value_type (v
));
6111 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6118 else if (VALUE_LVAL (v
) != not_lval
6119 && deprecated_value_modifiable (v
) == 0)
6120 return 0; /* ??? What does this represent? */
6121 else if (VALUE_LVAL (v
) == lval_register
)
6122 return 0; /* cannot watch a register with a HW watchpoint */
6125 /* The expression itself looks suitable for using a hardware
6126 watchpoint, but give the target machine a chance to reject it. */
6127 return found_memory_cnt
;
6131 watch_command_wrapper (char *arg
, int from_tty
)
6133 watch_command (arg
, from_tty
);
6137 watch_command (char *arg
, int from_tty
)
6139 watch_command_1 (arg
, hw_write
, from_tty
);
6143 rwatch_command_wrapper (char *arg
, int from_tty
)
6145 rwatch_command (arg
, from_tty
);
6149 rwatch_command (char *arg
, int from_tty
)
6151 watch_command_1 (arg
, hw_read
, from_tty
);
6155 awatch_command_wrapper (char *arg
, int from_tty
)
6157 awatch_command (arg
, from_tty
);
6161 awatch_command (char *arg
, int from_tty
)
6163 watch_command_1 (arg
, hw_access
, from_tty
);
6167 /* Helper routines for the until_command routine in infcmd.c. Here
6168 because it uses the mechanisms of breakpoints. */
6170 /* This function is called by fetch_inferior_event via the
6171 cmd_continuation pointer, to complete the until command. It takes
6172 care of cleaning up the temporary breakpoints set up by the until
6175 until_break_command_continuation (struct continuation_arg
*arg
, int error
)
6177 delete_breakpoint ((struct breakpoint
*)(arg
->data
.pointer
));
6179 delete_breakpoint ((struct breakpoint
*)(arg
->next
->data
.pointer
));
6183 until_break_command (char *arg
, int from_tty
, int anywhere
)
6185 struct symtabs_and_lines sals
;
6186 struct symtab_and_line sal
;
6187 struct frame_info
*frame
= get_selected_frame (NULL
);
6188 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6189 struct breakpoint
*breakpoint
;
6190 struct breakpoint
*breakpoint2
= NULL
;
6191 struct cleanup
*old_chain
;
6192 struct continuation_arg
*arg1
;
6193 struct continuation_arg
*arg2
;
6196 clear_proceed_status ();
6198 /* Set a breakpoint where the user wants it and at return from
6201 if (default_breakpoint_valid
)
6202 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6203 default_breakpoint_line
, (char ***) NULL
, NULL
);
6205 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6206 0, (char ***) NULL
, NULL
);
6208 if (sals
.nelts
!= 1)
6209 error (_("Couldn't get information on specified line."));
6212 xfree (sals
.sals
); /* malloc'd, so freed */
6215 error (_("Junk at end of arguments."));
6217 resolve_sal_pc (&sal
);
6220 /* If the user told us to continue until a specified location,
6221 we don't specify a frame at which we need to stop. */
6222 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6224 /* Otherwise, specify the current frame, because we want to stop only
6225 at the very same frame. */
6226 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6229 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6231 /* Keep within the current frame, or in frames called by the current
6235 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6236 sal
.pc
= get_frame_pc (prev_frame
);
6237 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6239 make_cleanup_delete_breakpoint (breakpoint2
);
6242 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6244 /* If we are running asynchronously, and proceed call above has actually
6245 managed to start the target, arrange for breakpoints to be
6246 deleted when the target stops. Otherwise, we're already stopped and
6247 delete breakpoints via cleanup chain. */
6249 if (target_can_async_p () && target_executing
)
6252 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6254 arg1
->data
.pointer
= breakpoint
;
6258 arg2
= (struct continuation_arg
*)
6259 xmalloc ( sizeof (struct continuation_arg
));
6261 arg2
->data
.pointer
= breakpoint2
;
6265 discard_cleanups (old_chain
);
6266 add_continuation (until_break_command_continuation
, arg1
);
6269 do_cleanups (old_chain
);
6273 ep_skip_leading_whitespace (char **s
)
6275 if ((s
== NULL
) || (*s
== NULL
))
6277 while (isspace (**s
))
6281 /* This function examines a string, and attempts to find a token
6282 that might be an event name in the leading characters. If a
6283 possible match is found, a pointer to the last character of
6284 the token is returned. Else, NULL is returned. */
6287 ep_find_event_name_end (char *arg
)
6290 char *event_name_end
= NULL
;
6292 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6296 /* We break out of the loop when we find a token delimiter.
6297 Basically, we're looking for alphanumerics and underscores;
6298 anything else delimites the token. */
6301 if (!isalnum (*s
) && (*s
!= '_'))
6307 return event_name_end
;
6311 /* This function attempts to parse an optional "if <cond>" clause
6312 from the arg string. If one is not found, it returns NULL.
6314 Else, it returns a pointer to the condition string. (It does not
6315 attempt to evaluate the string against a particular block.) And,
6316 it updates arg to point to the first character following the parsed
6317 if clause in the arg string. */
6320 ep_parse_optional_if_clause (char **arg
)
6324 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6327 /* Skip the "if" keyword. */
6330 /* Skip any extra leading whitespace, and record the start of the
6331 condition string. */
6332 ep_skip_leading_whitespace (arg
);
6335 /* Assume that the condition occupies the remainder of the arg string. */
6336 (*arg
) += strlen (cond_string
);
6341 /* This function attempts to parse an optional filename from the arg
6342 string. If one is not found, it returns NULL.
6344 Else, it returns a pointer to the parsed filename. (This function
6345 makes no attempt to verify that a file of that name exists, or is
6346 accessible.) And, it updates arg to point to the first character
6347 following the parsed filename in the arg string.
6349 Note that clients needing to preserve the returned filename for
6350 future access should copy it to their own buffers. */
6352 ep_parse_optional_filename (char **arg
)
6354 static char filename
[1024];
6359 if ((*arg_p
== '\0') || isspace (*arg_p
))
6377 /* Commands to deal with catching events, such as signals, exceptions,
6378 process start/exit, etc. */
6382 catch_fork
, catch_vfork
6387 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6390 char *cond_string
= NULL
;
6392 ep_skip_leading_whitespace (&arg
);
6394 /* The allowed syntax is:
6396 catch [v]fork if <cond>
6398 First, check if there's an if clause. */
6399 cond_string
= ep_parse_optional_if_clause (&arg
);
6401 if ((*arg
!= '\0') && !isspace (*arg
))
6402 error (_("Junk at end of arguments."));
6404 /* If this target supports it, create a fork or vfork catchpoint
6405 and enable reporting of such events. */
6409 create_fork_event_catchpoint (tempflag
, cond_string
);
6412 create_vfork_event_catchpoint (tempflag
, cond_string
);
6415 error (_("unsupported or unknown fork kind; cannot catch it"));
6421 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6423 char *cond_string
= NULL
;
6425 ep_skip_leading_whitespace (&arg
);
6427 /* The allowed syntax is:
6429 catch exec if <cond>
6431 First, check if there's an if clause. */
6432 cond_string
= ep_parse_optional_if_clause (&arg
);
6434 if ((*arg
!= '\0') && !isspace (*arg
))
6435 error (_("Junk at end of arguments."));
6437 /* If this target supports it, create an exec catchpoint
6438 and enable reporting of such events. */
6439 create_exec_event_catchpoint (tempflag
, cond_string
);
6443 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6445 char *dll_pathname
= NULL
;
6446 char *cond_string
= NULL
;
6448 ep_skip_leading_whitespace (&arg
);
6450 /* The allowed syntax is:
6452 catch load if <cond>
6453 catch load <filename>
6454 catch load <filename> if <cond>
6456 The user is not allowed to specify the <filename> after an
6459 We'll ignore the pathological case of a file named "if".
6461 First, check if there's an if clause. If so, then there
6462 cannot be a filename. */
6463 cond_string
= ep_parse_optional_if_clause (&arg
);
6465 /* If there was an if clause, then there cannot be a filename.
6466 Else, there might be a filename and an if clause. */
6467 if (cond_string
== NULL
)
6469 dll_pathname
= ep_parse_optional_filename (&arg
);
6470 ep_skip_leading_whitespace (&arg
);
6471 cond_string
= ep_parse_optional_if_clause (&arg
);
6474 if ((*arg
!= '\0') && !isspace (*arg
))
6475 error (_("Junk at end of arguments."));
6477 /* Create a load breakpoint that only triggers when a load of
6478 the specified dll (or any dll, if no pathname was specified)
6480 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6481 dll_pathname
, cond_string
);
6485 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6487 char *dll_pathname
= NULL
;
6488 char *cond_string
= NULL
;
6490 ep_skip_leading_whitespace (&arg
);
6492 /* The allowed syntax is:
6494 catch unload if <cond>
6495 catch unload <filename>
6496 catch unload <filename> if <cond>
6498 The user is not allowed to specify the <filename> after an
6501 We'll ignore the pathological case of a file named "if".
6503 First, check if there's an if clause. If so, then there
6504 cannot be a filename. */
6505 cond_string
= ep_parse_optional_if_clause (&arg
);
6507 /* If there was an if clause, then there cannot be a filename.
6508 Else, there might be a filename and an if clause. */
6509 if (cond_string
== NULL
)
6511 dll_pathname
= ep_parse_optional_filename (&arg
);
6512 ep_skip_leading_whitespace (&arg
);
6513 cond_string
= ep_parse_optional_if_clause (&arg
);
6516 if ((*arg
!= '\0') && !isspace (*arg
))
6517 error (_("Junk at end of arguments."));
6519 /* Create an unload breakpoint that only triggers when an unload of
6520 the specified dll (or any dll, if no pathname was specified)
6522 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6523 dll_pathname
, cond_string
);
6526 static enum print_stop_action
6527 print_exception_catchpoint (struct breakpoint
*b
)
6529 annotate_catchpoint (b
->number
);
6531 if (strstr (b
->addr_string
, "throw") != NULL
)
6532 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6535 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6538 return PRINT_SRC_AND_LOC
;
6542 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6547 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6548 ui_out_field_string (uiout
, "addr", "<PENDING>");
6550 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6554 *last_addr
= b
->loc
->address
;
6555 if (strstr (b
->addr_string
, "throw") != NULL
)
6556 ui_out_field_string (uiout
, "what", "exception throw");
6558 ui_out_field_string (uiout
, "what", "exception catch");
6562 print_mention_exception_catchpoint (struct breakpoint
*b
)
6564 if (strstr (b
->addr_string
, "throw") != NULL
)
6565 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6567 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6570 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6571 print_exception_catchpoint
,
6572 print_one_exception_catchpoint
,
6573 print_mention_exception_catchpoint
6577 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6578 enum exception_event_kind ex_event
, int from_tty
)
6580 char *trigger_func_name
;
6582 if (ex_event
== EX_EVENT_CATCH
)
6583 trigger_func_name
= "__cxa_begin_catch";
6585 trigger_func_name
= "__cxa_throw";
6587 break_command_really (trigger_func_name
, cond_string
, -1,
6588 0 /* condition and thread are valid. */,
6591 AUTO_BOOLEAN_TRUE
/* pending */,
6592 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6597 /* Deal with "catch catch" and "catch throw" commands */
6600 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6601 int tempflag
, int from_tty
)
6603 char *cond_string
= NULL
;
6604 struct symtab_and_line
*sal
= NULL
;
6606 ep_skip_leading_whitespace (&arg
);
6608 cond_string
= ep_parse_optional_if_clause (&arg
);
6610 if ((*arg
!= '\0') && !isspace (*arg
))
6611 error (_("Junk at end of arguments."));
6613 if ((ex_event
!= EX_EVENT_THROW
) &&
6614 (ex_event
!= EX_EVENT_CATCH
))
6615 error (_("Unsupported or unknown exception event; cannot catch it"));
6617 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6620 warning (_("Unsupported with this platform/compiler combination."));
6623 /* Create a breakpoint struct for Ada exception catchpoints. */
6626 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6630 struct expression
*cond
,
6631 struct breakpoint_ops
*ops
,
6635 struct breakpoint
*b
;
6639 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6640 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6641 version for exception catchpoints, because two catchpoints
6642 used for different exception names will use the same address.
6643 In this case, a "breakpoint ... also set at..." warning is
6644 unproductive. Besides. the warning phrasing is also a bit
6645 inapropriate, we should use the word catchpoint, and tell
6646 the user what type of catchpoint it is. The above is good
6647 enough for now, though. */
6650 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6651 set_breakpoint_count (breakpoint_count
+ 1);
6653 b
->enable_state
= bp_enabled
;
6654 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6655 b
->number
= breakpoint_count
;
6656 b
->ignore_count
= 0;
6657 b
->loc
->cond
= cond
;
6658 b
->addr_string
= addr_string
;
6659 b
->language
= language_ada
;
6660 b
->cond_string
= cond_string
;
6661 b
->exp_string
= exp_string
;
6666 update_global_location_list ();
6669 /* Implement the "catch exception" command. */
6672 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6674 struct symtab_and_line sal
;
6676 char *addr_string
= NULL
;
6677 char *exp_string
= NULL
;
6678 char *cond_string
= NULL
;
6679 struct expression
*cond
= NULL
;
6680 struct breakpoint_ops
*ops
= NULL
;
6682 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6683 &cond_string
, &cond
, &ops
);
6684 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6685 cond_string
, cond
, ops
, tempflag
,
6689 /* Implement the "catch assert" command. */
6692 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6694 struct symtab_and_line sal
;
6695 char *addr_string
= NULL
;
6696 struct breakpoint_ops
*ops
= NULL
;
6698 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6699 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6700 tempflag
, from_tty
);
6704 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6707 /* The first argument may be an event name, such as "start" or "load".
6708 If so, then handle it as such. If it doesn't match an event name,
6709 then attempt to interpret it as an exception name. (This latter is
6710 the v4.16-and-earlier GDB meaning of the "catch" command.)
6712 First, try to find the bounds of what might be an event name. */
6713 char *arg1_start
= arg
;
6717 if (arg1_start
== NULL
)
6719 /* Old behaviour was to use pre-v-4.16 syntax */
6720 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6722 /* Now, this is not allowed */
6723 error (_("Catch requires an event name."));
6726 arg1_end
= ep_find_event_name_end (arg1_start
);
6727 if (arg1_end
== NULL
)
6728 error (_("catch requires an event"));
6729 arg1_length
= arg1_end
+ 1 - arg1_start
;
6731 /* Try to match what we found against known event names. */
6732 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6734 error (_("Catch of signal not yet implemented"));
6736 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6738 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6739 tempflag
, from_tty
);
6741 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6743 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6744 tempflag
, from_tty
);
6746 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6748 error (_("Catch of thread_start not yet implemented"));
6750 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6752 error (_("Catch of thread_exit not yet implemented"));
6754 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6756 error (_("Catch of thread_join not yet implemented"));
6758 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6760 error (_("Catch of start not yet implemented"));
6762 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6764 error (_("Catch of exit not yet implemented"));
6766 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6768 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6770 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6772 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6774 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6776 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6778 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6780 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6782 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6784 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6786 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6788 error (_("Catch of stop not yet implemented"));
6790 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6792 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6795 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6797 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6800 /* This doesn't appear to be an event name */
6804 /* Pre-v.4.16 behaviour was to treat the argument
6805 as the name of an exception */
6806 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6807 /* Now this is not allowed */
6808 error (_("Unknown event kind specified for catch"));
6814 catch_command (char *arg
, int from_tty
)
6816 catch_command_1 (arg
, 0, from_tty
);
6821 tcatch_command (char *arg
, int from_tty
)
6823 catch_command_1 (arg
, 1, from_tty
);
6826 /* Delete breakpoints by address or line. */
6829 clear_command (char *arg
, int from_tty
)
6831 struct breakpoint
*b
;
6832 VEC(breakpoint_p
) *found
= 0;
6835 struct symtabs_and_lines sals
;
6836 struct symtab_and_line sal
;
6841 sals
= decode_line_spec (arg
, 1);
6846 sals
.sals
= (struct symtab_and_line
*)
6847 xmalloc (sizeof (struct symtab_and_line
));
6848 make_cleanup (xfree
, sals
.sals
);
6849 init_sal (&sal
); /* initialize to zeroes */
6850 sal
.line
= default_breakpoint_line
;
6851 sal
.symtab
= default_breakpoint_symtab
;
6852 sal
.pc
= default_breakpoint_address
;
6853 if (sal
.symtab
== 0)
6854 error (_("No source file specified."));
6862 /* We don't call resolve_sal_pc here. That's not
6863 as bad as it seems, because all existing breakpoints
6864 typically have both file/line and pc set. So, if
6865 clear is given file/line, we can match this to existing
6866 breakpoint without obtaining pc at all.
6868 We only support clearing given the address explicitly
6869 present in breakpoint table. Say, we've set breakpoint
6870 at file:line. There were several PC values for that file:line,
6871 due to optimization, all in one block.
6872 We've picked one PC value. If "clear" is issued with another
6873 PC corresponding to the same file:line, the breakpoint won't
6874 be cleared. We probably can still clear the breakpoint, but
6875 since the other PC value is never presented to user, user
6876 can only find it by guessing, and it does not seem important
6879 /* For each line spec given, delete bps which correspond
6880 to it. Do it in two passes, solely to preserve the current
6881 behavior that from_tty is forced true if we delete more than
6885 for (i
= 0; i
< sals
.nelts
; i
++)
6887 /* If exact pc given, clear bpts at that pc.
6888 If line given (pc == 0), clear all bpts on specified line.
6889 If defaulting, clear all bpts on default line
6892 defaulting sal.pc != 0 tests to do
6897 1 0 <can't happen> */
6901 /* Find all matching breakpoints and add them to
6906 /* Are we going to delete b? */
6907 if (b
->type
!= bp_none
6908 && b
->type
!= bp_watchpoint
6909 && b
->type
!= bp_hardware_watchpoint
6910 && b
->type
!= bp_read_watchpoint
6911 && b
->type
!= bp_access_watchpoint
)
6913 struct bp_location
*loc
= b
->loc
;
6914 for (; loc
; loc
= loc
->next
)
6916 int pc_match
= sal
.pc
6917 && (loc
->address
== sal
.pc
)
6918 && (!section_is_overlay (loc
->section
)
6919 || loc
->section
== sal
.section
);
6920 int line_match
= ((default_match
|| (0 == sal
.pc
))
6921 && b
->source_file
!= NULL
6922 && sal
.symtab
!= NULL
6923 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6924 && b
->line_number
== sal
.line
);
6925 if (pc_match
|| line_match
)
6934 VEC_safe_push(breakpoint_p
, found
, b
);
6937 /* Now go thru the 'found' chain and delete them. */
6938 if (VEC_empty(breakpoint_p
, found
))
6941 error (_("No breakpoint at %s."), arg
);
6943 error (_("No breakpoint at this line."));
6946 if (VEC_length(breakpoint_p
, found
) > 1)
6947 from_tty
= 1; /* Always report if deleted more than one */
6950 if (VEC_length(breakpoint_p
, found
) == 1)
6951 printf_unfiltered (_("Deleted breakpoint "));
6953 printf_unfiltered (_("Deleted breakpoints "));
6955 breakpoints_changed ();
6957 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6960 printf_unfiltered ("%d ", b
->number
);
6961 delete_breakpoint (b
);
6964 putchar_unfiltered ('\n');
6967 /* Delete breakpoint in BS if they are `delete' breakpoints and
6968 all breakpoints that are marked for deletion, whether hit or not.
6969 This is called after any breakpoint is hit, or after errors. */
6972 breakpoint_auto_delete (bpstat bs
)
6974 struct breakpoint
*b
, *temp
;
6976 for (; bs
; bs
= bs
->next
)
6977 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6979 delete_breakpoint (bs
->breakpoint_at
->owner
);
6981 ALL_BREAKPOINTS_SAFE (b
, temp
)
6983 if (b
->disposition
== disp_del_at_next_stop
)
6984 delete_breakpoint (b
);
6989 update_global_location_list (void)
6991 struct breakpoint
*b
;
6992 struct bp_location
**next
= &bp_location_chain
;
6993 struct bp_location
*loc
;
6994 struct bp_location
*loc2
;
6995 struct gdb_exception e
;
6996 VEC(bp_location_p
) *old_locations
= NULL
;
7000 /* Store old locations for future reference. */
7001 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7002 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7004 bp_location_chain
= NULL
;
7007 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7010 next
= &(loc
->global_next
);
7015 /* Identify bp_location instances that are no longer present in the new
7016 list, and therefore should be freed. Note that it's not necessary that
7017 those locations should be removed from inferior -- if there's another
7018 location at the same address (previously marked as duplicate),
7019 we don't need to remove/insert the location. */
7020 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7022 /* Tells if 'loc' is found amoung the new locations. If not, we
7024 int found_object
= 0;
7025 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7032 /* If this location is no longer present, and inserted, look if there's
7033 maybe a new location at the same address. If so, mark that one
7034 inserted, and don't remove this one. This is needed so that we
7035 don't have a time window where a breakpoint at certain location is not
7040 /* If the location is inserted now, we might have to remove it. */
7043 if (found_object
&& should_be_inserted (loc
))
7045 /* The location is still present in the location list, and still
7046 should be inserted. Don't do anything. */
7051 /* The location is either no longer present, or got disabled.
7052 See if there's another location at the same address, in which
7053 case we don't need to remove this one from the target. */
7054 if (breakpoint_address_is_meaningful (loc
->owner
))
7055 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7057 /* For the sake of should_insert_location. The
7058 call to check_duplicates will fix up this later. */
7059 loc2
->duplicate
= 0;
7060 if (should_be_inserted (loc2
)
7061 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7064 loc2
->target_info
= loc
->target_info
;
7072 if (remove_breakpoint (loc
, mark_uninserted
))
7074 /* This is just about all we can do. We could keep this
7075 location on the global list, and try to remove it next
7076 time, but there's no particular reason why we will
7079 Note that at this point, loc->owner is still valid,
7080 as delete_breakpoint frees the breakpoint only
7081 after calling us. */
7082 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7083 loc
->owner
->number
);
7088 free_bp_location (loc
);
7093 check_duplicates (b
);
7096 if (always_inserted_mode
&& target_has_execution
)
7097 insert_breakpoint_locations ();
7101 update_global_location_list_nothrow (void)
7103 struct gdb_exception e
;
7104 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7105 update_global_location_list ();
7108 /* Delete a breakpoint and clean up all traces of it in the data
7112 delete_breakpoint (struct breakpoint
*bpt
)
7114 struct breakpoint
*b
;
7116 struct bp_location
*loc
, *next
;
7118 gdb_assert (bpt
!= NULL
);
7120 /* Has this bp already been deleted? This can happen because multiple
7121 lists can hold pointers to bp's. bpstat lists are especial culprits.
7123 One example of this happening is a watchpoint's scope bp. When the
7124 scope bp triggers, we notice that the watchpoint is out of scope, and
7125 delete it. We also delete its scope bp. But the scope bp is marked
7126 "auto-deleting", and is already on a bpstat. That bpstat is then
7127 checked for auto-deleting bp's, which are deleted.
7129 A real solution to this problem might involve reference counts in bp's,
7130 and/or giving them pointers back to their referencing bpstat's, and
7131 teaching delete_breakpoint to only free a bp's storage when no more
7132 references were extent. A cheaper bandaid was chosen. */
7133 if (bpt
->type
== bp_none
)
7136 if (deprecated_delete_breakpoint_hook
)
7137 deprecated_delete_breakpoint_hook (bpt
);
7138 breakpoint_delete_event (bpt
->number
);
7140 if (breakpoint_chain
== bpt
)
7141 breakpoint_chain
= bpt
->next
;
7146 b
->next
= bpt
->next
;
7150 free_command_lines (&bpt
->commands
);
7151 if (bpt
->cond_string
!= NULL
)
7152 xfree (bpt
->cond_string
);
7153 if (bpt
->addr_string
!= NULL
)
7154 xfree (bpt
->addr_string
);
7155 if (bpt
->exp
!= NULL
)
7157 if (bpt
->exp_string
!= NULL
)
7158 xfree (bpt
->exp_string
);
7159 if (bpt
->val
!= NULL
)
7160 value_free (bpt
->val
);
7161 if (bpt
->source_file
!= NULL
)
7162 xfree (bpt
->source_file
);
7163 if (bpt
->dll_pathname
!= NULL
)
7164 xfree (bpt
->dll_pathname
);
7165 if (bpt
->triggered_dll_pathname
!= NULL
)
7166 xfree (bpt
->triggered_dll_pathname
);
7167 if (bpt
->exec_pathname
!= NULL
)
7168 xfree (bpt
->exec_pathname
);
7170 /* Be sure no bpstat's are pointing at it after it's been freed. */
7171 /* FIXME, how can we find all bpstat's?
7172 We just check stop_bpstat for now. Note that we cannot just
7173 remove bpstats pointing at bpt from the stop_bpstat list
7174 entirely, as breakpoint commands are associated with the bpstat;
7175 if we remove it here, then the later call to
7176 bpstat_do_actions (&stop_bpstat);
7177 in event-top.c won't do anything, and temporary breakpoints
7178 with commands won't work. */
7179 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7180 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7182 bs
->breakpoint_at
= NULL
;
7184 /* bs->commands will be freed later. */
7187 /* Now that breakpoint is removed from breakpoint
7188 list, update the global location list. This
7189 will remove locations that used to belong to
7190 this breakpoint. Do this before freeing
7191 the breakpoint itself, since remove_breakpoint
7192 looks at location's owner. It might be better
7193 design to have location completely self-contained,
7194 but it's not the case now. */
7195 update_global_location_list ();
7198 /* On the chance that someone will soon try again to delete this same
7199 bp, we mark it as deleted before freeing its storage. */
7200 bpt
->type
= bp_none
;
7206 do_delete_breakpoint_cleanup (void *b
)
7208 delete_breakpoint (b
);
7212 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7214 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7218 delete_command (char *arg
, int from_tty
)
7220 struct breakpoint
*b
, *temp
;
7226 int breaks_to_delete
= 0;
7228 /* Delete all breakpoints if no argument.
7229 Do not delete internal or call-dummy breakpoints, these
7230 have to be deleted with an explicit breakpoint number argument. */
7233 if (b
->type
!= bp_call_dummy
&&
7234 b
->type
!= bp_shlib_event
&&
7235 b
->type
!= bp_thread_event
&&
7236 b
->type
!= bp_overlay_event
&&
7239 breaks_to_delete
= 1;
7244 /* Ask user only if there are some breakpoints to delete. */
7246 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7248 ALL_BREAKPOINTS_SAFE (b
, temp
)
7250 if (b
->type
!= bp_call_dummy
&&
7251 b
->type
!= bp_shlib_event
&&
7252 b
->type
!= bp_thread_event
&&
7253 b
->type
!= bp_overlay_event
&&
7255 delete_breakpoint (b
);
7260 map_breakpoint_numbers (arg
, delete_breakpoint
);
7264 all_locations_are_pending (struct bp_location
*loc
)
7266 for (; loc
; loc
= loc
->next
)
7267 if (!loc
->shlib_disabled
)
7272 /* Subroutine of update_breakpoint_locations to simplify it.
7273 Return non-zero if multiple fns in list LOC have the same name.
7274 Null names are ignored. */
7277 ambiguous_names_p (struct bp_location
*loc
)
7279 struct bp_location
*l
;
7280 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7281 (int (*) (const void *, const void *)) streq
,
7282 NULL
, xcalloc
, xfree
);
7284 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7287 const char *name
= l
->function_name
;
7289 /* Allow for some names to be NULL, ignore them. */
7293 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7295 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7310 update_breakpoint_locations (struct breakpoint
*b
,
7311 struct symtabs_and_lines sals
)
7315 struct bp_location
*existing_locations
= b
->loc
;
7317 /* If there's no new locations, and all existing locations
7318 are pending, don't do anything. This optimizes
7319 the common case where all locations are in the same
7320 shared library, that was unloaded. We'd like to
7321 retain the location, so that when the library
7322 is loaded again, we don't loose the enabled/disabled
7323 status of the individual locations. */
7324 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7329 for (i
= 0; i
< sals
.nelts
; ++i
)
7331 struct bp_location
*new_loc
=
7332 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7334 /* Reparse conditions, they might contain references to the
7336 if (b
->cond_string
!= NULL
)
7338 struct gdb_exception e
;
7341 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7343 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7348 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7349 b
->number
, e
.message
);
7350 new_loc
->enabled
= 0;
7354 if (b
->source_file
!= NULL
)
7355 xfree (b
->source_file
);
7356 if (sals
.sals
[i
].symtab
== NULL
)
7357 b
->source_file
= NULL
;
7360 savestring (sals
.sals
[i
].symtab
->filename
,
7361 strlen (sals
.sals
[i
].symtab
->filename
));
7363 if (b
->line_number
== 0)
7364 b
->line_number
= sals
.sals
[i
].line
;
7367 /* If possible, carry over 'disable' status from existing breakpoints. */
7369 struct bp_location
*e
= existing_locations
;
7370 /* If there are multiple breakpoints with the same function name,
7371 e.g. for inline functions, comparing function names won't work.
7372 Instead compare pc addresses; this is just a heuristic as things
7373 may have moved, but in practice it gives the correct answer
7374 often enough until a better solution is found. */
7375 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7377 for (; e
; e
= e
->next
)
7379 if (!e
->enabled
&& e
->function_name
)
7381 struct bp_location
*l
= b
->loc
;
7382 if (have_ambiguous_names
)
7384 for (; l
; l
= l
->next
)
7385 if (e
->address
== l
->address
)
7393 for (; l
; l
= l
->next
)
7394 if (l
->function_name
7395 && strcmp (e
->function_name
, l
->function_name
) == 0)
7405 update_global_location_list ();
7409 /* Reset a breakpoint given it's struct breakpoint * BINT.
7410 The value we return ends up being the return value from catch_errors.
7411 Unused in this case. */
7414 breakpoint_re_set_one (void *bint
)
7416 /* get past catch_errs */
7417 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7421 int *not_found_ptr
= ¬_found
;
7422 struct symtabs_and_lines sals
= {};
7423 struct symtabs_and_lines expanded
;
7425 enum enable_state save_enable
;
7426 struct gdb_exception e
;
7432 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7436 case bp_hardware_breakpoint
:
7438 case bp_catch_unload
:
7439 if (b
->addr_string
== NULL
)
7441 /* Anything without a string can't be re-set. */
7442 delete_breakpoint (b
);
7446 set_language (b
->language
);
7447 input_radix
= b
->input_radix
;
7449 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7451 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7456 int not_found_and_ok
= 0;
7457 /* For pending breakpoints, it's expected that parsing
7458 will fail until the right shared library is loaded.
7459 User has already told to create pending breakpoints and
7460 don't need extra messages. If breakpoint is in bp_shlib_disabled
7461 state, then user already saw the message about that breakpoint
7462 being disabled, and don't want to see more errors. */
7464 && (b
->condition_not_parsed
7465 || (b
->loc
&& b
->loc
->shlib_disabled
)
7466 || b
->enable_state
== bp_disabled
))
7467 not_found_and_ok
= 1;
7469 if (!not_found_and_ok
)
7471 /* We surely don't want to warn about the same breakpoint
7472 10 times. One solution, implemented here, is disable
7473 the breakpoint on error. Another solution would be to
7474 have separate 'warning emitted' flag. Since this
7475 happens only when a binary has changed, I don't know
7476 which approach is better. */
7477 b
->enable_state
= bp_disabled
;
7478 throw_exception (e
);
7485 gdb_assert (sals
.nelts
== 1);
7486 resolve_sal_pc (&sals
.sals
[0]);
7487 if (b
->condition_not_parsed
&& s
&& s
[0])
7489 char *cond_string
= 0;
7491 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7492 &cond_string
, &thread
);
7494 b
->cond_string
= cond_string
;
7496 b
->condition_not_parsed
= 0;
7498 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7499 update_breakpoint_locations (b
, expanded
);
7505 case bp_hardware_watchpoint
:
7506 case bp_read_watchpoint
:
7507 case bp_access_watchpoint
:
7508 /* Watchpoint can be either on expression using entirely global variables,
7509 or it can be on local variables.
7511 Watchpoints of the first kind are never auto-deleted, and even persist
7512 across program restarts. Since they can use variables from shared
7513 libraries, we need to reparse expression as libraries are loaded
7516 Watchpoints on local variables can also change meaning as result
7517 of solib event. For example, if a watchpoint uses both a local and
7518 a global variables in expression, it's a local watchpoint, but
7519 unloading of a shared library will make the expression invalid.
7520 This is not a very common use case, but we still re-evaluate
7521 expression, to avoid surprises to the user.
7523 Note that for local watchpoints, we re-evaluate it only if
7524 watchpoints frame id is still valid. If it's not, it means
7525 the watchpoint is out of scope and will be deleted soon. In fact,
7526 I'm not sure we'll ever be called in this case.
7528 If a local watchpoint's frame id is still valid, then
7529 b->exp_valid_block is likewise valid, and we can safely use it.
7531 Don't do anything about disabled watchpoints, since they will
7532 be reevaluated again when enabled. */
7533 update_watchpoint (b
, 1 /* reparse */);
7535 /* We needn't really do anything to reset these, since the mask
7536 that requests them is unaffected by e.g., new libraries being
7539 case bp_catch_vfork
:
7544 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7546 /* Delete longjmp and overlay event breakpoints; they will be
7547 reset later by breakpoint_re_set. */
7549 case bp_longjmp_resume
:
7550 case bp_overlay_event
:
7551 delete_breakpoint (b
);
7554 /* This breakpoint is special, it's set up when the inferior
7555 starts and we really don't want to touch it. */
7556 case bp_shlib_event
:
7558 /* Like bp_shlib_event, this breakpoint type is special.
7559 Once it is set up, we do not want to touch it. */
7560 case bp_thread_event
:
7562 /* Keep temporary breakpoints, which can be encountered when we step
7563 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7564 Otherwise these should have been blown away via the cleanup chain
7565 or by breakpoint_init_inferior when we rerun the executable. */
7568 case bp_watchpoint_scope
:
7570 case bp_step_resume
:
7577 /* Re-set all breakpoints after symbols have been re-loaded. */
7579 breakpoint_re_set (void)
7581 struct breakpoint
*b
, *temp
;
7582 enum language save_language
;
7583 int save_input_radix
;
7585 save_language
= current_language
->la_language
;
7586 save_input_radix
= input_radix
;
7587 ALL_BREAKPOINTS_SAFE (b
, temp
)
7589 /* Format possible error msg */
7590 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7592 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7593 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7594 do_cleanups (cleanups
);
7596 set_language (save_language
);
7597 input_radix
= save_input_radix
;
7599 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7601 create_longjmp_breakpoint ("longjmp");
7602 create_longjmp_breakpoint ("_longjmp");
7603 create_longjmp_breakpoint ("siglongjmp");
7604 create_longjmp_breakpoint ("_siglongjmp");
7605 create_longjmp_breakpoint (NULL
);
7608 create_overlay_event_breakpoint ("_ovly_debug_event");
7611 /* Reset the thread number of this breakpoint:
7613 - If the breakpoint is for all threads, leave it as-is.
7614 - Else, reset it to the current thread for inferior_ptid. */
7616 breakpoint_re_set_thread (struct breakpoint
*b
)
7618 if (b
->thread
!= -1)
7620 if (in_thread_list (inferior_ptid
))
7621 b
->thread
= pid_to_thread_id (inferior_ptid
);
7625 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7626 If from_tty is nonzero, it prints a message to that effect,
7627 which ends with a period (no newline). */
7630 set_ignore_count (int bptnum
, int count
, int from_tty
)
7632 struct breakpoint
*b
;
7638 if (b
->number
== bptnum
)
7640 b
->ignore_count
= count
;
7644 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7646 else if (count
== 1)
7647 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7650 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7653 breakpoints_changed ();
7654 breakpoint_modify_event (b
->number
);
7658 error (_("No breakpoint number %d."), bptnum
);
7661 /* Clear the ignore counts of all breakpoints. */
7663 breakpoint_clear_ignore_counts (void)
7665 struct breakpoint
*b
;
7668 b
->ignore_count
= 0;
7671 /* Command to set ignore-count of breakpoint N to COUNT. */
7674 ignore_command (char *args
, int from_tty
)
7680 error_no_arg (_("a breakpoint number"));
7682 num
= get_number (&p
);
7684 error (_("bad breakpoint number: '%s'"), args
);
7686 error (_("Second argument (specified ignore-count) is missing."));
7688 set_ignore_count (num
,
7689 longest_to_int (value_as_long (parse_and_eval (p
))),
7692 printf_filtered ("\n");
7695 /* Call FUNCTION on each of the breakpoints
7696 whose numbers are given in ARGS. */
7699 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7704 struct breakpoint
*b
, *tmp
;
7708 error_no_arg (_("one or more breakpoint numbers"));
7715 num
= get_number_or_range (&p1
);
7718 warning (_("bad breakpoint number at or near '%s'"), p
);
7722 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7723 if (b
->number
== num
)
7725 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7728 if (related_breakpoint
)
7729 function (related_breakpoint
);
7733 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7739 static struct bp_location
*
7740 find_location_by_number (char *number
)
7742 char *dot
= strchr (number
, '.');
7746 struct breakpoint
*b
;
7747 struct bp_location
*loc
;
7752 bp_num
= get_number_or_range (&p1
);
7754 error (_("Bad breakpoint number '%s'"), number
);
7757 if (b
->number
== bp_num
)
7762 if (!b
|| b
->number
!= bp_num
)
7763 error (_("Bad breakpoint number '%s'"), number
);
7766 loc_num
= get_number_or_range (&p1
);
7768 error (_("Bad breakpoint location number '%s'"), number
);
7772 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7775 error (_("Bad breakpoint location number '%s'"), dot
+1);
7781 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7782 If from_tty is nonzero, it prints a message to that effect,
7783 which ends with a period (no newline). */
7786 disable_breakpoint (struct breakpoint
*bpt
)
7788 /* Never disable a watchpoint scope breakpoint; we want to
7789 hit them when we leave scope so we can delete both the
7790 watchpoint and its scope breakpoint at that time. */
7791 if (bpt
->type
== bp_watchpoint_scope
)
7794 /* You can't disable permanent breakpoints. */
7795 if (bpt
->enable_state
== bp_permanent
)
7798 bpt
->enable_state
= bp_disabled
;
7800 update_global_location_list ();
7802 if (deprecated_modify_breakpoint_hook
)
7803 deprecated_modify_breakpoint_hook (bpt
);
7804 breakpoint_modify_event (bpt
->number
);
7808 disable_command (char *args
, int from_tty
)
7810 struct breakpoint
*bpt
;
7812 ALL_BREAKPOINTS (bpt
)
7816 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7821 case bp_catch_unload
:
7823 case bp_catch_vfork
:
7825 case bp_hardware_breakpoint
:
7827 case bp_hardware_watchpoint
:
7828 case bp_read_watchpoint
:
7829 case bp_access_watchpoint
:
7830 disable_breakpoint (bpt
);
7834 else if (strchr (args
, '.'))
7836 struct bp_location
*loc
= find_location_by_number (args
);
7839 update_global_location_list ();
7842 map_breakpoint_numbers (args
, disable_breakpoint
);
7846 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7848 int target_resources_ok
, other_type_used
;
7851 if (bpt
->type
== bp_hardware_breakpoint
)
7854 i
= hw_breakpoint_used_count ();
7855 target_resources_ok
=
7856 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7858 if (target_resources_ok
== 0)
7859 error (_("No hardware breakpoint support in the target."));
7860 else if (target_resources_ok
< 0)
7861 error (_("Hardware breakpoints used exceeds limit."));
7864 if (bpt
->type
== bp_watchpoint
||
7865 bpt
->type
== bp_hardware_watchpoint
||
7866 bpt
->type
== bp_read_watchpoint
||
7867 bpt
->type
== bp_access_watchpoint
)
7869 struct frame_id saved_frame_id
;
7871 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7872 if (bpt
->exp_valid_block
!= NULL
)
7874 struct frame_info
*fr
=
7875 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7878 printf_filtered (_("\
7879 Cannot enable watchpoint %d because the block in which its expression\n\
7880 is valid is not currently in scope.\n"), bpt
->number
);
7887 value_free (bpt
->val
);
7888 mark
= value_mark ();
7889 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7891 release_value (bpt
->val
);
7894 if (bpt
->type
== bp_hardware_watchpoint
||
7895 bpt
->type
== bp_read_watchpoint
||
7896 bpt
->type
== bp_access_watchpoint
)
7898 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7899 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7901 /* Hack around 'unused var' error for some targets here */
7902 (void) mem_cnt
, (void) i
;
7903 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7904 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7905 /* we can consider of type is bp_hardware_watchpoint, convert to
7906 bp_watchpoint in the following condition */
7907 if (target_resources_ok
< 0)
7909 printf_filtered (_("\
7910 Cannot enable watchpoint %d because target watch resources\n\
7911 have been allocated for other watchpoints.\n"), bpt
->number
);
7912 value_free_to_mark (mark
);
7917 select_frame (frame_find_by_id (saved_frame_id
));
7918 value_free_to_mark (mark
);
7921 if (bpt
->enable_state
!= bp_permanent
)
7922 bpt
->enable_state
= bp_enabled
;
7923 bpt
->disposition
= disposition
;
7924 update_global_location_list ();
7925 breakpoints_changed ();
7927 if (deprecated_modify_breakpoint_hook
)
7928 deprecated_modify_breakpoint_hook (bpt
);
7929 breakpoint_modify_event (bpt
->number
);
7934 enable_breakpoint (struct breakpoint
*bpt
)
7936 do_enable_breakpoint (bpt
, bpt
->disposition
);
7939 /* The enable command enables the specified breakpoints (or all defined
7940 breakpoints) so they once again become (or continue to be) effective
7941 in stopping the inferior. */
7944 enable_command (char *args
, int from_tty
)
7946 struct breakpoint
*bpt
;
7948 ALL_BREAKPOINTS (bpt
)
7952 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7957 case bp_catch_unload
:
7959 case bp_catch_vfork
:
7961 case bp_hardware_breakpoint
:
7963 case bp_hardware_watchpoint
:
7964 case bp_read_watchpoint
:
7965 case bp_access_watchpoint
:
7966 enable_breakpoint (bpt
);
7970 else if (strchr (args
, '.'))
7972 struct bp_location
*loc
= find_location_by_number (args
);
7975 update_global_location_list ();
7978 map_breakpoint_numbers (args
, enable_breakpoint
);
7982 enable_once_breakpoint (struct breakpoint
*bpt
)
7984 do_enable_breakpoint (bpt
, disp_disable
);
7988 enable_once_command (char *args
, int from_tty
)
7990 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7994 enable_delete_breakpoint (struct breakpoint
*bpt
)
7996 do_enable_breakpoint (bpt
, disp_del
);
8000 enable_delete_command (char *args
, int from_tty
)
8002 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8006 set_breakpoint_cmd (char *args
, int from_tty
)
8011 show_breakpoint_cmd (char *args
, int from_tty
)
8015 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8017 struct symtabs_and_lines
8018 decode_line_spec_1 (char *string
, int funfirstline
)
8020 struct symtabs_and_lines sals
;
8022 error (_("Empty line specification."));
8023 if (default_breakpoint_valid
)
8024 sals
= decode_line_1 (&string
, funfirstline
,
8025 default_breakpoint_symtab
,
8026 default_breakpoint_line
,
8027 (char ***) NULL
, NULL
);
8029 sals
= decode_line_1 (&string
, funfirstline
,
8030 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8032 error (_("Junk at end of line specification: %s"), string
);
8036 /* Create and insert a raw software breakpoint at PC. Return an
8037 identifier, which should be used to remove the breakpoint later.
8038 In general, places which call this should be using something on the
8039 breakpoint chain instead; this function should be eliminated
8043 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8045 struct bp_target_info
*bp_tgt
;
8047 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8048 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8050 bp_tgt
->placed_address
= pc
;
8051 if (target_insert_breakpoint (bp_tgt
) != 0)
8053 /* Could not insert the breakpoint. */
8061 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8064 deprecated_remove_raw_breakpoint (void *bp
)
8066 struct bp_target_info
*bp_tgt
= bp
;
8069 ret
= target_remove_breakpoint (bp_tgt
);
8075 /* One (or perhaps two) breakpoints used for software single stepping. */
8077 static void *single_step_breakpoints
[2];
8079 /* Create and insert a breakpoint for software single step. */
8082 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8086 if (single_step_breakpoints
[0] == NULL
)
8087 bpt_p
= &single_step_breakpoints
[0];
8090 gdb_assert (single_step_breakpoints
[1] == NULL
);
8091 bpt_p
= &single_step_breakpoints
[1];
8094 /* NOTE drow/2006-04-11: A future improvement to this function would be
8095 to only create the breakpoints once, and actually put them on the
8096 breakpoint chain. That would let us use set_raw_breakpoint. We could
8097 adjust the addresses each time they were needed. Doing this requires
8098 corresponding changes elsewhere where single step breakpoints are
8099 handled, however. So, for now, we use this. */
8101 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8103 error (_("Could not insert single-step breakpoint at 0x%s"),
8104 paddr_nz (next_pc
));
8107 /* Remove and delete any breakpoints used for software single step. */
8110 remove_single_step_breakpoints (void)
8112 gdb_assert (single_step_breakpoints
[0] != NULL
);
8114 /* See insert_single_step_breakpoint for more about this deprecated
8116 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8117 single_step_breakpoints
[0] = NULL
;
8119 if (single_step_breakpoints
[1] != NULL
)
8121 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8122 single_step_breakpoints
[1] = NULL
;
8126 /* Check whether a software single-step breakpoint is inserted at PC. */
8129 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8133 for (i
= 0; i
< 2; i
++)
8135 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8136 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8143 int breakpoints_always_inserted_mode (void)
8145 return always_inserted_mode
;
8149 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8150 It is defined as a macro to prevent duplication.
8151 COMMAND should be a string constant containing the name of the command. */
8152 #define BREAK_ARGS_HELP(command) \
8153 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8154 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8155 If a line number is specified, break at start of code for that line.\n\
8156 If a function is specified, break at start of code for that function.\n\
8157 If an address is specified, break at that exact address.\n\
8158 With no LOCATION, uses current execution address of selected stack frame.\n\
8159 This is useful for breaking on return to a stack frame.\n\
8161 THREADNUM is the number from \"info threads\".\n\
8162 CONDITION is a boolean expression.\n\
8164 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8166 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8169 _initialize_breakpoint (void)
8171 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8172 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8173 struct cmd_list_element
*c
;
8175 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8177 breakpoint_chain
= 0;
8178 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8179 before a breakpoint is set. */
8180 breakpoint_count
= 0;
8182 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8183 Set ignore-count of breakpoint number N to COUNT.\n\
8184 Usage is `ignore N COUNT'."));
8186 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8188 add_com ("commands", class_breakpoint
, commands_command
, _("\
8189 Set commands to be executed when a breakpoint is hit.\n\
8190 Give breakpoint number as argument after \"commands\".\n\
8191 With no argument, the targeted breakpoint is the last one set.\n\
8192 The commands themselves follow starting on the next line.\n\
8193 Type a line containing \"end\" to indicate the end of them.\n\
8194 Give \"silent\" as the first line to make the breakpoint silent;\n\
8195 then no output is printed when it is hit, except what the commands print."));
8197 add_com ("condition", class_breakpoint
, condition_command
, _("\
8198 Specify breakpoint number N to break only if COND is true.\n\
8199 Usage is `condition N COND', where N is an integer and COND is an\n\
8200 expression to be evaluated whenever breakpoint N is reached."));
8202 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8203 Set a temporary breakpoint.\n\
8204 Like \"break\" except the breakpoint is only temporary,\n\
8205 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8206 by using \"enable delete\" on the breakpoint number.\n\
8208 BREAK_ARGS_HELP ("tbreak")));
8209 set_cmd_completer (c
, location_completer
);
8211 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8212 Set a hardware assisted breakpoint.\n\
8213 Like \"break\" except the breakpoint requires hardware support,\n\
8214 some target hardware may not have this support.\n\
8216 BREAK_ARGS_HELP ("hbreak")));
8217 set_cmd_completer (c
, location_completer
);
8219 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8220 Set a temporary hardware assisted breakpoint.\n\
8221 Like \"hbreak\" except the breakpoint is only temporary,\n\
8222 so it will be deleted when hit.\n\
8224 BREAK_ARGS_HELP ("thbreak")));
8225 set_cmd_completer (c
, location_completer
);
8227 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8228 Enable some breakpoints.\n\
8229 Give breakpoint numbers (separated by spaces) as arguments.\n\
8230 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8231 This is used to cancel the effect of the \"disable\" command.\n\
8232 With a subcommand you can enable temporarily."),
8233 &enablelist
, "enable ", 1, &cmdlist
);
8235 add_com ("ab", class_breakpoint
, enable_command
, _("\
8236 Enable some breakpoints.\n\
8237 Give breakpoint numbers (separated by spaces) as arguments.\n\
8238 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8239 This is used to cancel the effect of the \"disable\" command.\n\
8240 With a subcommand you can enable temporarily."));
8242 add_com_alias ("en", "enable", class_breakpoint
, 1);
8244 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8245 Enable some breakpoints.\n\
8246 Give breakpoint numbers (separated by spaces) as arguments.\n\
8247 This is used to cancel the effect of the \"disable\" command.\n\
8248 May be abbreviated to simply \"enable\".\n"),
8249 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8251 add_cmd ("once", no_class
, enable_once_command
, _("\
8252 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8253 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8256 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8257 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8258 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8261 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8262 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8263 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8266 add_cmd ("once", no_class
, enable_once_command
, _("\
8267 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8268 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8271 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8272 Disable some breakpoints.\n\
8273 Arguments are breakpoint numbers with spaces in between.\n\
8274 To disable all breakpoints, give no argument.\n\
8275 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8276 &disablelist
, "disable ", 1, &cmdlist
);
8277 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8278 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8280 add_com ("sb", class_breakpoint
, disable_command
, _("\
8281 Disable some breakpoints.\n\
8282 Arguments are breakpoint numbers with spaces in between.\n\
8283 To disable all breakpoints, give no argument.\n\
8284 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8286 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8287 Disable some breakpoints.\n\
8288 Arguments are breakpoint numbers with spaces in between.\n\
8289 To disable all breakpoints, give no argument.\n\
8290 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8291 This command may be abbreviated \"disable\"."),
8294 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8295 Delete some breakpoints or auto-display expressions.\n\
8296 Arguments are breakpoint numbers with spaces in between.\n\
8297 To delete all breakpoints, give no argument.\n\
8299 Also a prefix command for deletion of other GDB objects.\n\
8300 The \"unset\" command is also an alias for \"delete\"."),
8301 &deletelist
, "delete ", 1, &cmdlist
);
8302 add_com_alias ("d", "delete", class_breakpoint
, 1);
8303 add_com_alias ("del", "delete", class_breakpoint
, 1);
8305 add_com ("db", class_breakpoint
, delete_command
, _("\
8306 Delete some breakpoints.\n\
8307 Arguments are breakpoint numbers with spaces in between.\n\
8308 To delete all breakpoints, give no argument.\n"));
8310 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8311 Delete some breakpoints or auto-display expressions.\n\
8312 Arguments are breakpoint numbers with spaces in between.\n\
8313 To delete all breakpoints, give no argument.\n\
8314 This command may be abbreviated \"delete\"."),
8317 add_com ("clear", class_breakpoint
, clear_command
, _("\
8318 Clear breakpoint at specified line or function.\n\
8319 Argument may be line number, function name, or \"*\" and an address.\n\
8320 If line number is specified, all breakpoints in that line are cleared.\n\
8321 If function is specified, breakpoints at beginning of function are cleared.\n\
8322 If an address is specified, breakpoints at that address are cleared.\n\
8324 With no argument, clears all breakpoints in the line that the selected frame\n\
8327 See also the \"delete\" command which clears breakpoints by number."));
8329 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8330 Set breakpoint at specified line or function.\n"
8331 BREAK_ARGS_HELP ("break")));
8332 set_cmd_completer (c
, location_completer
);
8334 add_com_alias ("b", "break", class_run
, 1);
8335 add_com_alias ("br", "break", class_run
, 1);
8336 add_com_alias ("bre", "break", class_run
, 1);
8337 add_com_alias ("brea", "break", class_run
, 1);
8341 add_com_alias ("ba", "break", class_breakpoint
, 1);
8342 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8347 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8348 Break in function/address or break at a line in the current file."),
8349 &stoplist
, "stop ", 1, &cmdlist
);
8350 add_cmd ("in", class_breakpoint
, stopin_command
,
8351 _("Break in function or address."), &stoplist
);
8352 add_cmd ("at", class_breakpoint
, stopat_command
,
8353 _("Break at a line in the current file."), &stoplist
);
8354 add_com ("status", class_info
, breakpoints_info
, _("\
8355 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8356 The \"Type\" column indicates one of:\n\
8357 \tbreakpoint - normal breakpoint\n\
8358 \twatchpoint - watchpoint\n\
8359 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8360 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8361 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8362 address and file/line number respectively.\n\
8364 Convenience variable \"$_\" and default examine address for \"x\"\n\
8365 are set to the address of the last breakpoint listed unless the command\n\
8366 is prefixed with \"server \".\n\n\
8367 Convenience variable \"$bpnum\" contains the number of the last\n\
8371 add_info ("breakpoints", breakpoints_info
, _("\
8372 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8373 The \"Type\" column indicates one of:\n\
8374 \tbreakpoint - normal breakpoint\n\
8375 \twatchpoint - watchpoint\n\
8376 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8377 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8378 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8379 address and file/line number respectively.\n\
8381 Convenience variable \"$_\" and default examine address for \"x\"\n\
8382 are set to the address of the last breakpoint listed unless the command\n\
8383 is prefixed with \"server \".\n\n\
8384 Convenience variable \"$bpnum\" contains the number of the last\n\
8388 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8389 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8390 The \"Type\" column indicates one of:\n\
8391 \tbreakpoint - normal breakpoint\n\
8392 \twatchpoint - watchpoint\n\
8393 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8394 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8395 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8396 address and file/line number respectively.\n\
8398 Convenience variable \"$_\" and default examine address for \"x\"\n\
8399 are set to the address of the last breakpoint listed unless the command\n\
8400 is prefixed with \"server \".\n\n\
8401 Convenience variable \"$bpnum\" contains the number of the last\n\
8404 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8405 Status of all breakpoints, or breakpoint number NUMBER.\n\
8406 The \"Type\" column indicates one of:\n\
8407 \tbreakpoint - normal breakpoint\n\
8408 \twatchpoint - watchpoint\n\
8409 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8410 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8411 \tuntil - internal breakpoint used by the \"until\" command\n\
8412 \tfinish - internal breakpoint used by the \"finish\" command\n\
8413 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8414 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8415 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8416 address and file/line number respectively.\n\
8418 Convenience variable \"$_\" and default examine address for \"x\"\n\
8419 are set to the address of the last breakpoint listed unless the command\n\
8420 is prefixed with \"server \".\n\n\
8421 Convenience variable \"$bpnum\" contains the number of the last\n\
8423 &maintenanceinfolist
);
8425 add_com ("catch", class_breakpoint
, catch_command
, _("\
8426 Set catchpoints to catch events.\n\
8427 Raised signals may be caught:\n\
8428 \tcatch signal - all signals\n\
8429 \tcatch signal <signame> - a particular signal\n\
8430 Raised exceptions may be caught:\n\
8431 \tcatch throw - all exceptions, when thrown\n\
8432 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8433 \tcatch catch - all exceptions, when caught\n\
8434 \tcatch catch <exceptname> - a particular exception, when caught\n\
8435 Thread or process events may be caught:\n\
8436 \tcatch thread_start - any threads, just after creation\n\
8437 \tcatch thread_exit - any threads, just before expiration\n\
8438 \tcatch thread_join - any threads, just after joins\n\
8439 Process events may be caught:\n\
8440 \tcatch start - any processes, just after creation\n\
8441 \tcatch exit - any processes, just before expiration\n\
8442 \tcatch fork - calls to fork()\n\
8443 \tcatch vfork - calls to vfork()\n\
8444 \tcatch exec - calls to exec()\n\
8445 Dynamically-linked library events may be caught:\n\
8446 \tcatch load - loads of any library\n\
8447 \tcatch load <libname> - loads of a particular library\n\
8448 \tcatch unload - unloads of any library\n\
8449 \tcatch unload <libname> - unloads of a particular library\n\
8450 The act of your program's execution stopping may also be caught:\n\
8452 C++ exceptions may be caught:\n\
8453 \tcatch throw - all exceptions, when thrown\n\
8454 \tcatch catch - all exceptions, when caught\n\
8455 Ada exceptions may be caught:\n\
8456 \tcatch exception - all exceptions, when raised\n\
8457 \tcatch exception <name> - a particular exception, when raised\n\
8458 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8459 \tcatch assert - all failed assertions, when raised\n\
8461 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8462 after a fork or vfork is caught.\n\n\
8463 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8465 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8466 Set temporary catchpoints to catch events.\n\
8467 Args like \"catch\" command.\n\
8468 Like \"catch\" except the catchpoint is only temporary,\n\
8469 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8470 by using \"enable delete\" on the catchpoint number."));
8472 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8473 Set a watchpoint for an expression.\n\
8474 A watchpoint stops execution of your program whenever the value of\n\
8475 an expression changes."));
8476 set_cmd_completer (c
, location_completer
);
8478 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8479 Set a read watchpoint for an expression.\n\
8480 A watchpoint stops execution of your program whenever the value of\n\
8481 an expression is read."));
8482 set_cmd_completer (c
, location_completer
);
8484 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8485 Set a watchpoint for an expression.\n\
8486 A watchpoint stops execution of your program whenever the value of\n\
8487 an expression is either read or written."));
8488 set_cmd_completer (c
, location_completer
);
8490 add_info ("watchpoints", breakpoints_info
,
8491 _("Synonym for ``info breakpoints''."));
8494 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8495 respond to changes - contrary to the description. */
8496 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8497 &can_use_hw_watchpoints
, _("\
8498 Set debugger's willingness to use watchpoint hardware."), _("\
8499 Show debugger's willingness to use watchpoint hardware."), _("\
8500 If zero, gdb will not use hardware for new watchpoints, even if\n\
8501 such is available. (However, any hardware watchpoints that were\n\
8502 created before setting this to nonzero, will continue to use watchpoint\n\
8505 show_can_use_hw_watchpoints
,
8506 &setlist
, &showlist
);
8508 can_use_hw_watchpoints
= 1;
8510 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8511 Breakpoint specific settings\n\
8512 Configure various breakpoint-specific variables such as\n\
8513 pending breakpoint behavior"),
8514 &breakpoint_set_cmdlist
, "set breakpoint ",
8515 0/*allow-unknown*/, &setlist
);
8516 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8517 Breakpoint specific settings\n\
8518 Configure various breakpoint-specific variables such as\n\
8519 pending breakpoint behavior"),
8520 &breakpoint_show_cmdlist
, "show breakpoint ",
8521 0/*allow-unknown*/, &showlist
);
8523 add_setshow_auto_boolean_cmd ("pending", no_class
,
8524 &pending_break_support
, _("\
8525 Set debugger's behavior regarding pending breakpoints."), _("\
8526 Show debugger's behavior regarding pending breakpoints."), _("\
8527 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8528 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8529 an error. If auto, an unrecognized breakpoint location results in a\n\
8530 user-query to see if a pending breakpoint should be created."),
8532 show_pending_break_support
,
8533 &breakpoint_set_cmdlist
,
8534 &breakpoint_show_cmdlist
);
8536 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8538 add_setshow_boolean_cmd ("auto-hw", no_class
,
8539 &automatic_hardware_breakpoints
, _("\
8540 Set automatic usage of hardware breakpoints."), _("\
8541 Show automatic usage of hardware breakpoints."), _("\
8542 If set, the debugger will automatically use hardware breakpoints for\n\
8543 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8544 a warning will be emitted for such breakpoints."),
8546 show_automatic_hardware_breakpoints
,
8547 &breakpoint_set_cmdlist
,
8548 &breakpoint_show_cmdlist
);
8550 add_setshow_boolean_cmd ("always-inserted", class_support
,
8551 &always_inserted_mode
, _("\
8552 Set mode for inserting breakpoints."), _("\
8553 Show mode for inserting breakpoints."), _("\
8554 When this mode is off (which is the default), breakpoints are inserted in\n\
8555 inferior when it is resumed, and removed when execution stops. When this\n\
8556 mode is on, breakpoints are inserted immediately and removed only when\n\
8557 the user deletes the breakpoint."),
8559 &show_always_inserted_mode
,
8560 &breakpoint_set_cmdlist
,
8561 &breakpoint_show_cmdlist
);
8563 automatic_hardware_breakpoints
= 1;