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 (addr
>= loc
->address
2620 && addr
< loc
->address
+ loc
->length
)
2622 b
->watchpoint_triggered
= watch_triggered_yes
;
2630 /* Possible return values for watchpoint_check (this can't be an enum
2631 because of check_errors). */
2632 /* The watchpoint has been deleted. */
2633 #define WP_DELETED 1
2634 /* The value has changed. */
2635 #define WP_VALUE_CHANGED 2
2636 /* The value has not changed. */
2637 #define WP_VALUE_NOT_CHANGED 3
2639 #define BP_TEMPFLAG 1
2640 #define BP_HARDWAREFLAG 2
2642 /* Check watchpoint condition. */
2645 watchpoint_check (void *p
)
2647 bpstat bs
= (bpstat
) p
;
2648 struct breakpoint
*b
;
2649 struct frame_info
*fr
;
2650 int within_current_scope
;
2652 b
= bs
->breakpoint_at
->owner
;
2654 if (b
->exp_valid_block
== NULL
)
2655 within_current_scope
= 1;
2658 /* There is no current frame at this moment. If we're going to have
2659 any chance of handling watchpoints on local variables, we'll need
2660 the frame chain (so we can determine if we're in scope). */
2661 reinit_frame_cache ();
2662 fr
= frame_find_by_id (b
->watchpoint_frame
);
2663 within_current_scope
= (fr
!= NULL
);
2665 /* If we've gotten confused in the unwinder, we might have
2666 returned a frame that can't describe this variable. */
2667 if (within_current_scope
2668 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2669 within_current_scope
= 0;
2671 /* in_function_epilogue_p() returns a non-zero value if we're still
2672 in the function but the stack frame has already been invalidated.
2673 Since we can't rely on the values of local variables after the
2674 stack has been destroyed, we are treating the watchpoint in that
2675 state as `not changed' without further checking.
2677 vinschen/2003-09-04: The former implementation left out the case
2678 that the watchpoint frame couldn't be found by frame_find_by_id()
2679 because the current PC is currently in an epilogue. Calling
2680 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2681 if ((!within_current_scope
|| fr
== get_current_frame ())
2682 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2683 return WP_VALUE_NOT_CHANGED
;
2684 if (fr
&& within_current_scope
)
2685 /* If we end up stopping, the current frame will get selected
2686 in normal_stop. So this call to select_frame won't affect
2691 if (within_current_scope
)
2693 /* We use value_{,free_to_}mark because it could be a
2694 *long* time before we return to the command level and
2695 call free_all_values. We can't call free_all_values because
2696 we might be in the middle of evaluating a function call. */
2698 struct value
*mark
= value_mark ();
2699 struct value
*new_val
;
2701 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2702 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2703 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2705 if (new_val
!= NULL
)
2707 release_value (new_val
);
2708 value_free_to_mark (mark
);
2710 bs
->old_val
= b
->val
;
2713 /* We will stop here */
2714 return WP_VALUE_CHANGED
;
2718 /* Nothing changed, don't do anything. */
2719 value_free_to_mark (mark
);
2720 /* We won't stop here */
2721 return WP_VALUE_NOT_CHANGED
;
2726 /* This seems like the only logical thing to do because
2727 if we temporarily ignored the watchpoint, then when
2728 we reenter the block in which it is valid it contains
2729 garbage (in the case of a function, it may have two
2730 garbage values, one before and one after the prologue).
2731 So we can't even detect the first assignment to it and
2732 watch after that (since the garbage may or may not equal
2733 the first value assigned). */
2734 /* We print all the stop information in print_it_typical(), but
2735 in this case, by the time we call print_it_typical() this bp
2736 will be deleted already. So we have no choice but print the
2737 information here. */
2738 if (ui_out_is_mi_like_p (uiout
))
2740 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2741 ui_out_text (uiout
, "\nWatchpoint ");
2742 ui_out_field_int (uiout
, "wpnum", b
->number
);
2743 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2744 which its expression is valid.\n");
2746 if (b
->related_breakpoint
)
2747 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2748 b
->disposition
= disp_del_at_next_stop
;
2754 /* Return true if it looks like target has stopped due to hitting
2755 breakpoint location BL. This function does not check if we
2756 should stop, only if BL explains the stop. */
2758 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2760 struct breakpoint
*b
= bl
->owner
;
2762 if (b
->type
!= bp_watchpoint
2763 && b
->type
!= bp_hardware_watchpoint
2764 && b
->type
!= bp_read_watchpoint
2765 && b
->type
!= bp_access_watchpoint
2766 && b
->type
!= bp_hardware_breakpoint
2767 && b
->type
!= bp_catch_fork
2768 && b
->type
!= bp_catch_vfork
2769 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2771 if (bl
->address
!= bp_addr
) /* address doesn't match */
2773 if (overlay_debugging
/* unmapped overlay section */
2774 && section_is_overlay (bl
->section
)
2775 && !section_is_mapped (bl
->section
))
2779 /* Continuable hardware watchpoints are treated as non-existent if the
2780 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2781 some data address). Otherwise gdb won't stop on a break instruction
2782 in the code (not from a breakpoint) when a hardware watchpoint has
2783 been defined. Also skip watchpoints which we know did not trigger
2784 (did not match the data address). */
2786 if ((b
->type
== bp_hardware_watchpoint
2787 || b
->type
== bp_read_watchpoint
2788 || b
->type
== bp_access_watchpoint
)
2789 && b
->watchpoint_triggered
== watch_triggered_no
)
2792 if (b
->type
== bp_hardware_breakpoint
)
2794 if (bl
->address
!= bp_addr
)
2796 if (overlay_debugging
/* unmapped overlay section */
2797 && section_is_overlay (bl
->section
)
2798 && !section_is_mapped (bl
->section
))
2802 /* Is this a catchpoint of a load or unload? If so, did we
2803 get a load or unload of the specified library? If not,
2805 if ((b
->type
== bp_catch_load
)
2806 #if defined(SOLIB_HAVE_LOAD_EVENT)
2807 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2808 || ((b
->dll_pathname
!= NULL
)
2809 && (strcmp (b
->dll_pathname
,
2810 SOLIB_LOADED_LIBRARY_PATHNAME (
2811 PIDGET (inferior_ptid
)))
2817 if ((b
->type
== bp_catch_unload
)
2818 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2819 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2820 || ((b
->dll_pathname
!= NULL
)
2821 && (strcmp (b
->dll_pathname
,
2822 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2823 PIDGET (inferior_ptid
)))
2829 if ((b
->type
== bp_catch_fork
)
2830 && !inferior_has_forked (PIDGET (inferior_ptid
),
2831 &b
->forked_inferior_pid
))
2834 if ((b
->type
== bp_catch_vfork
)
2835 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2836 &b
->forked_inferior_pid
))
2839 if ((b
->type
== bp_catch_exec
)
2840 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2846 /* If BS refers to a watchpoint, determine if the watched values
2847 has actually changed, and we should stop. If not, set BS->stop
2850 bpstat_check_watchpoint (bpstat bs
)
2852 const struct bp_location
*bl
= bs
->breakpoint_at
;
2853 struct breakpoint
*b
= bl
->owner
;
2855 if (b
->type
== bp_watchpoint
2856 || b
->type
== bp_read_watchpoint
2857 || b
->type
== bp_access_watchpoint
2858 || b
->type
== bp_hardware_watchpoint
)
2862 int must_check_value
= 0;
2864 if (b
->type
== bp_watchpoint
)
2865 /* For a software watchpoint, we must always check the
2867 must_check_value
= 1;
2868 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2869 /* We have a hardware watchpoint (read, write, or access)
2870 and the target earlier reported an address watched by
2872 must_check_value
= 1;
2873 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2874 && b
->type
== bp_hardware_watchpoint
)
2875 /* We were stopped by a hardware watchpoint, but the target could
2876 not report the data address. We must check the watchpoint's
2877 value. Access and read watchpoints are out of luck; without
2878 a data address, we can't figure it out. */
2879 must_check_value
= 1;
2881 if (must_check_value
)
2883 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2885 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2886 int e
= catch_errors (watchpoint_check
, bs
, message
,
2888 do_cleanups (cleanups
);
2892 /* We've already printed what needs to be printed. */
2893 bs
->print_it
= print_it_done
;
2896 case WP_VALUE_CHANGED
:
2897 if (b
->type
== bp_read_watchpoint
)
2899 /* Don't stop: read watchpoints shouldn't fire if
2900 the value has changed. This is for targets
2901 which cannot set read-only watchpoints. */
2902 bs
->print_it
= print_it_noop
;
2906 case WP_VALUE_NOT_CHANGED
:
2907 if (b
->type
== bp_hardware_watchpoint
2908 || b
->type
== bp_watchpoint
)
2910 /* Don't stop: write watchpoints shouldn't fire if
2911 the value hasn't changed. */
2912 bs
->print_it
= print_it_noop
;
2920 /* Error from catch_errors. */
2921 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2922 if (b
->related_breakpoint
)
2923 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2924 b
->disposition
= disp_del_at_next_stop
;
2925 /* We've already printed what needs to be printed. */
2926 bs
->print_it
= print_it_done
;
2930 else /* must_check_value == 0 */
2932 /* This is a case where some watchpoint(s) triggered, but
2933 not at the address of this watchpoint, or else no
2934 watchpoint triggered after all. So don't print
2935 anything for this watchpoint. */
2936 bs
->print_it
= print_it_noop
;
2943 /* Check conditions (condition proper, frame, thread and ignore count)
2944 of breakpoint referred to by BS. If we should not stop for this
2945 breakpoint, set BS->stop to 0. */
2947 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2949 int thread_id
= pid_to_thread_id (ptid
);
2950 const struct bp_location
*bl
= bs
->breakpoint_at
;
2951 struct breakpoint
*b
= bl
->owner
;
2953 if (frame_id_p (b
->frame_id
)
2954 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2958 int value_is_zero
= 0;
2960 /* If this is a scope breakpoint, mark the associated
2961 watchpoint as triggered so that we will handle the
2962 out-of-scope event. We'll get to the watchpoint next
2964 if (b
->type
== bp_watchpoint_scope
)
2965 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2967 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2969 /* Need to select the frame, with all that implies
2970 so that the conditions will have the right context. */
2971 select_frame (get_current_frame ());
2973 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2974 "Error in testing breakpoint condition:\n",
2976 /* FIXME-someday, should give breakpoint # */
2979 if (bl
->cond
&& value_is_zero
)
2983 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2987 else if (b
->ignore_count
> 0)
2990 annotate_ignore_count_change ();
2992 /* Increase the hit count even though we don't
3000 /* Get a bpstat associated with having just stopped at address
3001 BP_ADDR in thread PTID.
3003 Determine whether we stopped at a breakpoint, etc, or whether we
3004 don't understand this stop. Result is a chain of bpstat's such that:
3006 if we don't understand the stop, the result is a null pointer.
3008 if we understand why we stopped, the result is not null.
3010 Each element of the chain refers to a particular breakpoint or
3011 watchpoint at which we have stopped. (We may have stopped for
3012 several reasons concurrently.)
3014 Each element of the chain has valid next, breakpoint_at,
3015 commands, FIXME??? fields. */
3018 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3020 struct breakpoint
*b
= NULL
;
3021 const struct bp_location
*bl
;
3022 /* Root of the chain of bpstat's */
3023 struct bpstats root_bs
[1];
3024 /* Pointer to the last thing in the chain currently. */
3025 bpstat bs
= root_bs
;
3027 ALL_BP_LOCATIONS (bl
)
3031 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3034 /* For hardware watchpoints, we look only at the first location.
3035 The watchpoint_check function will work on entire expression,
3036 not the individual locations. For read watchopints, the
3037 watchpoints_triggered function have checked all locations
3040 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3043 if (!bpstat_check_location (bl
, bp_addr
))
3046 /* Come here if it's a watchpoint, or if the break address matches */
3048 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3050 /* Assume we stop. Should we find watchpoint that is not actually
3051 triggered, or if condition of breakpoint is false, we'll reset
3056 bpstat_check_watchpoint (bs
);
3060 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3061 /* We do not stop for these. */
3064 bpstat_check_breakpoint_conditions (bs
, ptid
);
3070 /* We will stop here */
3071 if (b
->disposition
== disp_disable
)
3073 b
->enable_state
= bp_disabled
;
3074 update_global_location_list ();
3078 bs
->commands
= b
->commands
;
3080 (strcmp ("silent", bs
->commands
->line
) == 0
3081 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3083 bs
->commands
= bs
->commands
->next
;
3086 bs
->commands
= copy_command_lines (bs
->commands
);
3089 /* Print nothing for this entry if we dont stop or if we dont print. */
3090 if (bs
->stop
== 0 || bs
->print
== 0)
3091 bs
->print_it
= print_it_noop
;
3094 bs
->next
= NULL
; /* Terminate the chain */
3095 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3097 /* If we aren't stopping, the value of some hardware watchpoint may
3098 not have changed, but the intermediate memory locations we are
3099 watching may have. Don't bother if we're stopping; this will get
3101 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3106 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3108 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3109 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3110 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3112 /* remove/insert can invalidate bs->breakpoint_at, if this
3113 location is no longer used by the watchpoint. Prevent
3114 further code from trying to use it. */
3115 bs
->breakpoint_at
= NULL
;
3116 remove_breakpoints ();
3117 insert_breakpoints ();
3121 return root_bs
->next
;
3124 /* Tell what to do about this bpstat. */
3126 bpstat_what (bpstat bs
)
3128 /* Classify each bpstat as one of the following. */
3131 /* This bpstat element has no effect on the main_action. */
3134 /* There was a watchpoint, stop but don't print. */
3137 /* There was a watchpoint, stop and print. */
3140 /* There was a breakpoint but we're not stopping. */
3143 /* There was a breakpoint, stop but don't print. */
3146 /* There was a breakpoint, stop and print. */
3149 /* We hit the longjmp breakpoint. */
3152 /* We hit the longjmp_resume breakpoint. */
3155 /* We hit the step_resume breakpoint. */
3158 /* We hit the shared library event breakpoint. */
3161 /* We caught a shared library event. */
3164 /* This is just used to count how many enums there are. */
3168 /* Here is the table which drives this routine. So that we can
3169 format it pretty, we define some abbreviations for the
3170 enum bpstat_what codes. */
3171 #define kc BPSTAT_WHAT_KEEP_CHECKING
3172 #define ss BPSTAT_WHAT_STOP_SILENT
3173 #define sn BPSTAT_WHAT_STOP_NOISY
3174 #define sgl BPSTAT_WHAT_SINGLE
3175 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3176 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3177 #define sr BPSTAT_WHAT_STEP_RESUME
3178 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3179 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3181 /* "Can't happen." Might want to print an error message.
3182 abort() is not out of the question, but chances are GDB is just
3183 a bit confused, not unusable. */
3184 #define err BPSTAT_WHAT_STOP_NOISY
3186 /* Given an old action and a class, come up with a new action. */
3187 /* One interesting property of this table is that wp_silent is the same
3188 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3189 after stopping, the check for whether to step over a breakpoint
3190 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3191 reference to how we stopped. We retain separate wp_silent and
3192 bp_silent codes in case we want to change that someday.
3194 Another possibly interesting property of this table is that
3195 there's a partial ordering, priority-like, of the actions. Once
3196 you've decided that some action is appropriate, you'll never go
3197 back and decide something of a lower priority is better. The
3200 kc < clr sgl shl shlr slr sn sr ss
3201 sgl < shl shlr slr sn sr ss
3202 slr < err shl shlr sn sr ss
3203 clr < err shl shlr sn sr ss
3210 What I think this means is that we don't need a damned table
3211 here. If you just put the rows and columns in the right order,
3212 it'd look awfully regular. We could simply walk the bpstat list
3213 and choose the highest priority action we find, with a little
3214 logic to handle the 'err' cases. */
3216 /* step_resume entries: a step resume breakpoint overrides another
3217 breakpoint of signal handling (see comment in wait_for_inferior
3218 at where we set the step_resume breakpoint). */
3220 static const enum bpstat_what_main_action
3221 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3224 /* kc ss sn sgl slr clr sr shl shlr
3227 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3229 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3231 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3233 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3235 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3237 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3239 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3241 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3243 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3245 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3247 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3261 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3262 struct bpstat_what retval
;
3264 retval
.call_dummy
= 0;
3265 for (; bs
!= NULL
; bs
= bs
->next
)
3267 enum class bs_class
= no_effect
;
3268 if (bs
->breakpoint_at
== NULL
)
3269 /* I suspect this can happen if it was a momentary breakpoint
3270 which has since been deleted. */
3272 switch (bs
->breakpoint_at
->owner
->type
)
3278 case bp_hardware_breakpoint
:
3284 bs_class
= bp_noisy
;
3286 bs_class
= bp_silent
;
3289 bs_class
= bp_nostop
;
3292 case bp_hardware_watchpoint
:
3293 case bp_read_watchpoint
:
3294 case bp_access_watchpoint
:
3298 bs_class
= wp_noisy
;
3300 bs_class
= wp_silent
;
3303 /* There was a watchpoint, but we're not stopping.
3304 This requires no further action. */
3305 bs_class
= no_effect
;
3308 bs_class
= long_jump
;
3310 case bp_longjmp_resume
:
3311 bs_class
= long_resume
;
3313 case bp_step_resume
:
3316 bs_class
= step_resume
;
3319 /* It is for the wrong frame. */
3320 bs_class
= bp_nostop
;
3322 case bp_watchpoint_scope
:
3323 bs_class
= bp_nostop
;
3325 case bp_shlib_event
:
3326 bs_class
= shlib_event
;
3328 case bp_thread_event
:
3329 case bp_overlay_event
:
3330 bs_class
= bp_nostop
;
3333 case bp_catch_unload
:
3334 /* Only if this catchpoint triggered should we cause the
3335 step-out-of-dld behaviour. Otherwise, we ignore this
3338 bs_class
= catch_shlib_event
;
3340 bs_class
= no_effect
;
3343 case bp_catch_vfork
:
3348 bs_class
= bp_noisy
;
3350 bs_class
= bp_silent
;
3353 /* There was a catchpoint, but we're not stopping.
3354 This requires no further action. */
3355 bs_class
= no_effect
;
3358 /* Make sure the action is stop (silent or noisy),
3359 so infrun.c pops the dummy frame. */
3360 bs_class
= bp_silent
;
3361 retval
.call_dummy
= 1;
3364 current_action
= table
[(int) bs_class
][(int) current_action
];
3366 retval
.main_action
= current_action
;
3370 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3371 without hardware support). This isn't related to a specific bpstat,
3372 just to things like whether watchpoints are set. */
3375 bpstat_should_step (void)
3377 struct breakpoint
*b
;
3379 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3386 /* Given a bpstat that records zero or more triggered eventpoints, this
3387 function returns another bpstat which contains only the catchpoints
3388 on that first list, if any. */
3390 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3392 struct bpstats root_bs
[1];
3393 bpstat bs
= root_bs
;
3394 struct breakpoint
*ep
;
3397 bpstat_clear (cp_list
);
3398 root_bs
->next
= NULL
;
3400 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3402 /* Is this eventpoint a catchpoint? If not, ignore it. */
3403 ep
= ep_list
->breakpoint_at
->owner
;
3406 if ((ep
->type
!= bp_catch_load
) &&
3407 (ep
->type
!= bp_catch_unload
))
3408 /* pai: (temp) ADD fork/vfork here!! */
3411 /* Yes; add it to the list. */
3412 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3417 #if defined(SOLIB_ADD)
3418 /* Also, for each triggered catchpoint, tag it with the name of
3419 the library that caused this trigger. (We copy the name now,
3420 because it's only guaranteed to be available NOW, when the
3421 catchpoint triggers. Clients who may wish to know the name
3422 later must get it from the catchpoint itself.) */
3423 if (ep
->triggered_dll_pathname
!= NULL
)
3424 xfree (ep
->triggered_dll_pathname
);
3425 if (ep
->type
== bp_catch_load
)
3426 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3427 PIDGET (inferior_ptid
));
3429 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3430 PIDGET (inferior_ptid
));
3432 dll_pathname
= NULL
;
3436 ep
->triggered_dll_pathname
= (char *)
3437 xmalloc (strlen (dll_pathname
) + 1);
3438 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3441 ep
->triggered_dll_pathname
= NULL
;
3447 static void print_breakpoint_location (struct breakpoint
*b
,
3448 struct bp_location
*loc
,
3450 struct ui_stream
*stb
)
3455 = find_pc_sect_function (loc
->address
, loc
->section
);
3458 ui_out_text (uiout
, "in ");
3459 ui_out_field_string (uiout
, "func",
3460 SYMBOL_PRINT_NAME (sym
));
3461 ui_out_wrap_hint (uiout
, wrap_indent
);
3462 ui_out_text (uiout
, " at ");
3464 ui_out_field_string (uiout
, "file", b
->source_file
);
3465 ui_out_text (uiout
, ":");
3467 if (ui_out_is_mi_like_p (uiout
))
3469 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3470 char *fullname
= symtab_to_fullname (sal
.symtab
);
3473 ui_out_field_string (uiout
, "fullname", fullname
);
3476 ui_out_field_int (uiout
, "line", b
->line_number
);
3480 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3484 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3485 ui_out_field_stream (uiout
, "at", stb
);
3489 /* Print B to gdb_stdout. */
3491 print_one_breakpoint_location (struct breakpoint
*b
,
3492 struct bp_location
*loc
,
3494 CORE_ADDR
*last_addr
)
3496 struct command_line
*l
;
3498 struct ep_type_description
3503 static struct ep_type_description bptypes
[] =
3505 {bp_none
, "?deleted?"},
3506 {bp_breakpoint
, "breakpoint"},
3507 {bp_hardware_breakpoint
, "hw breakpoint"},
3508 {bp_until
, "until"},
3509 {bp_finish
, "finish"},
3510 {bp_watchpoint
, "watchpoint"},
3511 {bp_hardware_watchpoint
, "hw watchpoint"},
3512 {bp_read_watchpoint
, "read watchpoint"},
3513 {bp_access_watchpoint
, "acc watchpoint"},
3514 {bp_longjmp
, "longjmp"},
3515 {bp_longjmp_resume
, "longjmp resume"},
3516 {bp_step_resume
, "step resume"},
3517 {bp_watchpoint_scope
, "watchpoint scope"},
3518 {bp_call_dummy
, "call dummy"},
3519 {bp_shlib_event
, "shlib events"},
3520 {bp_thread_event
, "thread events"},
3521 {bp_overlay_event
, "overlay events"},
3522 {bp_catch_load
, "catch load"},
3523 {bp_catch_unload
, "catch unload"},
3524 {bp_catch_fork
, "catch fork"},
3525 {bp_catch_vfork
, "catch vfork"},
3526 {bp_catch_exec
, "catch exec"}
3529 static char bpenables
[] = "nynny";
3530 char wrap_indent
[80];
3531 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3532 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3533 struct cleanup
*bkpt_chain
;
3535 int header_of_multiple
= 0;
3536 int part_of_multiple
= (loc
!= NULL
);
3538 gdb_assert (!loc
|| loc_number
!= 0);
3539 /* See comment in print_one_breakpoint concerning
3540 treatment of breakpoints with single disabled
3544 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3545 header_of_multiple
= 1;
3550 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3554 if (part_of_multiple
)
3557 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3558 ui_out_field_string (uiout
, "number", formatted
);
3563 ui_out_field_int (uiout
, "number", b
->number
);
3568 if (part_of_multiple
)
3569 ui_out_field_skip (uiout
, "type");
3572 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3573 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3574 internal_error (__FILE__
, __LINE__
,
3575 _("bptypes table does not describe type #%d."),
3577 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3582 if (part_of_multiple
)
3583 ui_out_field_skip (uiout
, "disp");
3585 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3590 if (part_of_multiple
)
3591 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3593 ui_out_field_fmt (uiout
, "enabled", "%c",
3594 bpenables
[(int) b
->enable_state
]);
3595 ui_out_spaces (uiout
, 2);
3599 strcpy (wrap_indent
, " ");
3602 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3603 strcat (wrap_indent
, " ");
3605 strcat (wrap_indent
, " ");
3608 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3610 /* Although the print_one can possibly print
3611 all locations, calling it here is not likely
3612 to get any nice result. So, make sure there's
3613 just one location. */
3614 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3615 b
->ops
->print_one (b
, last_addr
);
3621 internal_error (__FILE__
, __LINE__
,
3622 _("print_one_breakpoint: bp_none encountered\n"));
3626 case bp_hardware_watchpoint
:
3627 case bp_read_watchpoint
:
3628 case bp_access_watchpoint
:
3629 /* Field 4, the address, is omitted (which makes the columns
3630 not line up too nicely with the headers, but the effect
3631 is relatively readable). */
3633 ui_out_field_skip (uiout
, "addr");
3635 print_expression (b
->exp
, stb
->stream
);
3636 ui_out_field_stream (uiout
, "what", stb
);
3640 case bp_catch_unload
:
3641 /* Field 4, the address, is omitted (which makes the columns
3642 not line up too nicely with the headers, but the effect
3643 is relatively readable). */
3645 ui_out_field_skip (uiout
, "addr");
3647 if (b
->dll_pathname
== NULL
)
3649 ui_out_field_string (uiout
, "what", "<any library>");
3650 ui_out_spaces (uiout
, 1);
3654 ui_out_text (uiout
, "library \"");
3655 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3656 ui_out_text (uiout
, "\" ");
3661 case bp_catch_vfork
:
3662 /* Field 4, the address, is omitted (which makes the columns
3663 not line up too nicely with the headers, but the effect
3664 is relatively readable). */
3666 ui_out_field_skip (uiout
, "addr");
3668 if (b
->forked_inferior_pid
!= 0)
3670 ui_out_text (uiout
, "process ");
3671 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3672 ui_out_spaces (uiout
, 1);
3677 /* Field 4, the address, is omitted (which makes the columns
3678 not line up too nicely with the headers, but the effect
3679 is relatively readable). */
3681 ui_out_field_skip (uiout
, "addr");
3683 if (b
->exec_pathname
!= NULL
)
3685 ui_out_text (uiout
, "program \"");
3686 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3687 ui_out_text (uiout
, "\" ");
3692 case bp_hardware_breakpoint
:
3696 case bp_longjmp_resume
:
3697 case bp_step_resume
:
3698 case bp_watchpoint_scope
:
3700 case bp_shlib_event
:
3701 case bp_thread_event
:
3702 case bp_overlay_event
:
3706 if (header_of_multiple
)
3707 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3708 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3709 ui_out_field_string (uiout
, "addr", "<PENDING>");
3711 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3714 if (!header_of_multiple
)
3715 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3717 *last_addr
= b
->loc
->address
;
3721 if (!part_of_multiple
&& b
->thread
!= -1)
3723 /* FIXME: This seems to be redundant and lost here; see the
3724 "stop only in" line a little further down. */
3725 ui_out_text (uiout
, " thread ");
3726 ui_out_field_int (uiout
, "thread", b
->thread
);
3729 ui_out_text (uiout
, "\n");
3731 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3734 ui_out_text (uiout
, "\tstop only in stack frame at ");
3735 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3737 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3738 ui_out_text (uiout
, "\n");
3741 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3743 /* We do not print the condition for Ada exception catchpoints
3744 because the condition is an internal implementation detail
3745 that we do not want to expose to the user. */
3747 ui_out_text (uiout
, "\tstop only if ");
3748 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3749 ui_out_text (uiout
, "\n");
3752 if (!part_of_multiple
&& b
->thread
!= -1)
3754 /* FIXME should make an annotation for this */
3755 ui_out_text (uiout
, "\tstop only in thread ");
3756 ui_out_field_int (uiout
, "thread", b
->thread
);
3757 ui_out_text (uiout
, "\n");
3760 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3762 /* FIXME should make an annotation for this */
3763 if (ep_is_catchpoint (b
))
3764 ui_out_text (uiout
, "\tcatchpoint");
3766 ui_out_text (uiout
, "\tbreakpoint");
3767 ui_out_text (uiout
, " already hit ");
3768 ui_out_field_int (uiout
, "times", b
->hit_count
);
3769 if (b
->hit_count
== 1)
3770 ui_out_text (uiout
, " time\n");
3772 ui_out_text (uiout
, " times\n");
3775 /* Output the count also if it is zero, but only if this is
3776 mi. FIXME: Should have a better test for this. */
3777 if (ui_out_is_mi_like_p (uiout
))
3778 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3779 ui_out_field_int (uiout
, "times", b
->hit_count
);
3781 if (!part_of_multiple
&& b
->ignore_count
)
3784 ui_out_text (uiout
, "\tignore next ");
3785 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3786 ui_out_text (uiout
, " hits\n");
3789 if (!part_of_multiple
&& (l
= b
->commands
))
3791 struct cleanup
*script_chain
;
3794 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3795 print_command_lines (uiout
, l
, 4);
3796 do_cleanups (script_chain
);
3799 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3802 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3803 else if (b
->exp_string
)
3804 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3807 do_cleanups (bkpt_chain
);
3808 do_cleanups (old_chain
);
3812 print_one_breakpoint (struct breakpoint
*b
,
3813 CORE_ADDR
*last_addr
)
3815 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3817 /* If this breakpoint has custom print function,
3818 it's already printed. Otherwise, print individual
3819 locations, if any. */
3820 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3822 /* If breakpoint has a single location that is
3823 disabled, we print it as if it had
3824 several locations, since otherwise it's hard to
3825 represent "breakpoint enabled, location disabled"
3827 Note that while hardware watchpoints have
3828 several locations internally, that's no a property
3831 && !is_hardware_watchpoint (b
)
3832 && (b
->loc
->next
|| !b
->loc
->enabled
)
3833 && !ui_out_is_mi_like_p (uiout
))
3835 struct bp_location
*loc
;
3837 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3838 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3844 struct captured_breakpoint_query_args
3850 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3852 struct captured_breakpoint_query_args
*args
= data
;
3853 struct breakpoint
*b
;
3854 CORE_ADDR dummy_addr
= 0;
3857 if (args
->bnum
== b
->number
)
3859 print_one_breakpoint (b
, &dummy_addr
);
3867 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3869 struct captured_breakpoint_query_args args
;
3871 /* For the moment we don't trust print_one_breakpoint() to not throw
3873 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3874 error_message
, RETURN_MASK_ALL
) < 0)
3880 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3881 catchpoints, et.al.). */
3884 user_settable_breakpoint (const struct breakpoint
*b
)
3886 return (b
->type
== bp_breakpoint
3887 || b
->type
== bp_catch_load
3888 || b
->type
== bp_catch_unload
3889 || b
->type
== bp_catch_fork
3890 || b
->type
== bp_catch_vfork
3891 || b
->type
== bp_catch_exec
3892 || b
->type
== bp_hardware_breakpoint
3893 || b
->type
== bp_watchpoint
3894 || b
->type
== bp_read_watchpoint
3895 || b
->type
== bp_access_watchpoint
3896 || b
->type
== bp_hardware_watchpoint
);
3899 /* Print information on user settable breakpoint (watchpoint, etc)
3900 number BNUM. If BNUM is -1 print all user settable breakpoints.
3901 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3904 breakpoint_1 (int bnum
, int allflag
)
3906 struct breakpoint
*b
;
3907 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3908 int nr_printable_breakpoints
;
3909 struct cleanup
*bkpttbl_chain
;
3911 /* Compute the number of rows in the table. */
3912 nr_printable_breakpoints
= 0;
3915 || bnum
== b
->number
)
3917 if (allflag
|| user_settable_breakpoint (b
))
3918 nr_printable_breakpoints
++;
3923 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3927 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3930 if (nr_printable_breakpoints
> 0)
3931 annotate_breakpoints_headers ();
3932 if (nr_printable_breakpoints
> 0)
3934 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3935 if (nr_printable_breakpoints
> 0)
3937 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3938 if (nr_printable_breakpoints
> 0)
3940 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3941 if (nr_printable_breakpoints
> 0)
3943 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3946 if (nr_printable_breakpoints
> 0)
3948 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3949 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3951 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3953 if (nr_printable_breakpoints
> 0)
3955 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3956 ui_out_table_body (uiout
);
3957 if (nr_printable_breakpoints
> 0)
3958 annotate_breakpoints_table ();
3962 || bnum
== b
->number
)
3964 /* We only print out user settable breakpoints unless the
3966 if (allflag
|| user_settable_breakpoint (b
))
3967 print_one_breakpoint (b
, &last_addr
);
3970 do_cleanups (bkpttbl_chain
);
3972 if (nr_printable_breakpoints
== 0)
3975 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3977 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3982 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3983 that a comparison of an unsigned with -1 is always false. */
3984 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3985 set_next_address (last_addr
);
3988 /* FIXME? Should this be moved up so that it is only called when
3989 there have been breakpoints? */
3990 annotate_breakpoints_table_end ();
3994 breakpoints_info (char *bnum_exp
, int from_tty
)
3999 bnum
= parse_and_eval_long (bnum_exp
);
4001 breakpoint_1 (bnum
, 0);
4005 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4010 bnum
= parse_and_eval_long (bnum_exp
);
4012 breakpoint_1 (bnum
, 1);
4016 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4018 struct bp_location
*bl
= b
->loc
;
4019 for (; bl
; bl
= bl
->next
)
4021 if (bl
->address
== pc
4022 && (!overlay_debugging
|| bl
->section
== section
))
4028 /* Print a message describing any breakpoints set at PC. */
4031 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4034 struct breakpoint
*b
;
4037 others
+= breakpoint_has_pc (b
, pc
, section
);
4041 printf_filtered (_("Note: breakpoint "));
4042 else /* if (others == ???) */
4043 printf_filtered (_("Note: breakpoints "));
4045 if (breakpoint_has_pc (b
, pc
, section
))
4048 printf_filtered ("%d", b
->number
);
4049 if (b
->thread
== -1 && thread
!= -1)
4050 printf_filtered (" (all threads)");
4051 else if (b
->thread
!= -1)
4052 printf_filtered (" (thread %d)", b
->thread
);
4053 printf_filtered ("%s%s ",
4054 ((b
->enable_state
== bp_disabled
||
4055 b
->enable_state
== bp_call_disabled
)
4057 : b
->enable_state
== bp_permanent
4061 : ((others
== 1) ? " and" : ""));
4063 printf_filtered (_("also set at pc "));
4064 fputs_filtered (paddress (pc
), gdb_stdout
);
4065 printf_filtered (".\n");
4069 /* Set the default place to put a breakpoint
4070 for the `break' command with no arguments. */
4073 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4076 default_breakpoint_valid
= valid
;
4077 default_breakpoint_address
= addr
;
4078 default_breakpoint_symtab
= symtab
;
4079 default_breakpoint_line
= line
;
4082 /* Return true iff it is meaningful to use the address member of
4083 BPT. For some breakpoint types, the address member is irrelevant
4084 and it makes no sense to attempt to compare it to other addresses
4085 (or use it for any other purpose either).
4087 More specifically, each of the following breakpoint types will always
4088 have a zero valued address and we don't want check_duplicates() to mark
4089 breakpoints of any of these types to be a duplicate of an actual
4090 breakpoint at address zero:
4093 bp_hardware_watchpoint
4095 bp_access_watchpoint
4102 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4104 enum bptype type
= bpt
->type
;
4106 return (type
!= bp_watchpoint
4107 && type
!= bp_hardware_watchpoint
4108 && type
!= bp_read_watchpoint
4109 && type
!= bp_access_watchpoint
4110 && type
!= bp_catch_exec
4111 && type
!= bp_longjmp_resume
4112 && type
!= bp_catch_fork
4113 && type
!= bp_catch_vfork
);
4116 /* Rescan breakpoints at the same address and section as BPT,
4117 marking the first one as "first" and any others as "duplicates".
4118 This is so that the bpt instruction is only inserted once.
4119 If we have a permanent breakpoint at the same place as BPT, make
4120 that one the official one, and the rest as duplicates. */
4123 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4125 struct bp_location
*b
;
4127 struct bp_location
*perm_bp
= 0;
4129 ALL_BP_LOCATIONS (b
)
4130 if (b
->owner
->enable_state
!= bp_disabled
4131 && b
->owner
->enable_state
!= bp_call_disabled
4133 && !b
->shlib_disabled
4134 && b
->address
== address
/* address / overlay match */
4135 && (!overlay_debugging
|| b
->section
== section
)
4136 && breakpoint_address_is_meaningful (b
->owner
))
4138 /* Have we found a permanent breakpoint? */
4139 if (b
->owner
->enable_state
== bp_permanent
)
4146 b
->duplicate
= count
> 1;
4149 /* If we found a permanent breakpoint at this address, go over the
4150 list again and declare all the other breakpoints there to be the
4154 perm_bp
->duplicate
= 0;
4156 /* Permanent breakpoint should always be inserted. */
4157 if (! perm_bp
->inserted
)
4158 internal_error (__FILE__
, __LINE__
,
4159 _("allegedly permanent breakpoint is not "
4160 "actually inserted"));
4162 ALL_BP_LOCATIONS (b
)
4165 if (b
->owner
->enable_state
!= bp_disabled
4166 && b
->owner
->enable_state
!= bp_call_disabled
4167 && b
->enabled
&& !b
->shlib_disabled
4168 && b
->address
== address
/* address / overlay match */
4169 && (!overlay_debugging
|| b
->section
== section
)
4170 && breakpoint_address_is_meaningful (b
->owner
))
4173 internal_error (__FILE__
, __LINE__
,
4174 _("another breakpoint was inserted on top of "
4175 "a permanent breakpoint"));
4184 check_duplicates (struct breakpoint
*bpt
)
4186 struct bp_location
*bl
= bpt
->loc
;
4188 if (! breakpoint_address_is_meaningful (bpt
))
4191 for (; bl
; bl
= bl
->next
)
4192 check_duplicates_for (bl
->address
, bl
->section
);
4196 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4197 int bnum
, int have_bnum
)
4202 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4203 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4205 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4206 bnum
, astr1
, astr2
);
4208 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4211 /* Adjust a breakpoint's address to account for architectural constraints
4212 on breakpoint placement. Return the adjusted address. Note: Very
4213 few targets require this kind of adjustment. For most targets,
4214 this function is simply the identity function. */
4217 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4219 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4221 /* Very few targets need any kind of breakpoint adjustment. */
4224 else if (bptype
== bp_watchpoint
4225 || bptype
== bp_hardware_watchpoint
4226 || bptype
== bp_read_watchpoint
4227 || bptype
== bp_access_watchpoint
4228 || bptype
== bp_catch_fork
4229 || bptype
== bp_catch_vfork
4230 || bptype
== bp_catch_exec
)
4232 /* Watchpoints and the various bp_catch_* eventpoints should not
4233 have their addresses modified. */
4238 CORE_ADDR adjusted_bpaddr
;
4240 /* Some targets have architectural constraints on the placement
4241 of breakpoint instructions. Obtain the adjusted address. */
4242 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4245 /* An adjusted breakpoint address can significantly alter
4246 a user's expectations. Print a warning if an adjustment
4248 if (adjusted_bpaddr
!= bpaddr
)
4249 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4251 return adjusted_bpaddr
;
4255 /* Allocate a struct bp_location. */
4257 static struct bp_location
*
4258 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4260 struct bp_location
*loc
, *loc_p
;
4262 loc
= xmalloc (sizeof (struct bp_location
));
4263 memset (loc
, 0, sizeof (*loc
));
4267 loc
->shlib_disabled
= 0;
4276 case bp_longjmp_resume
:
4277 case bp_step_resume
:
4278 case bp_watchpoint_scope
:
4280 case bp_shlib_event
:
4281 case bp_thread_event
:
4282 case bp_overlay_event
:
4284 case bp_catch_unload
:
4285 loc
->loc_type
= bp_loc_software_breakpoint
;
4287 case bp_hardware_breakpoint
:
4288 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4290 case bp_hardware_watchpoint
:
4291 case bp_read_watchpoint
:
4292 case bp_access_watchpoint
:
4293 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4297 case bp_catch_vfork
:
4299 loc
->loc_type
= bp_loc_other
;
4302 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4308 static void free_bp_location (struct bp_location
*loc
)
4313 if (loc
->function_name
)
4314 xfree (loc
->function_name
);
4319 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4320 that has type BPTYPE and has no locations as yet. */
4322 static struct breakpoint
*
4323 set_raw_breakpoint_without_location (enum bptype bptype
)
4325 struct breakpoint
*b
, *b1
;
4327 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4328 memset (b
, 0, sizeof (*b
));
4331 b
->language
= current_language
->la_language
;
4332 b
->input_radix
= input_radix
;
4334 b
->enable_state
= bp_enabled
;
4337 b
->ignore_count
= 0;
4339 b
->frame_id
= null_frame_id
;
4340 b
->dll_pathname
= NULL
;
4341 b
->triggered_dll_pathname
= NULL
;
4342 b
->forked_inferior_pid
= 0;
4343 b
->exec_pathname
= NULL
;
4345 b
->condition_not_parsed
= 0;
4347 /* Add this breakpoint to the end of the chain
4348 so that a list of breakpoints will come out in order
4349 of increasing numbers. */
4351 b1
= breakpoint_chain
;
4353 breakpoint_chain
= b
;
4363 /* Initialize loc->function_name. */
4365 set_breakpoint_location_function (struct bp_location
*loc
)
4367 if (loc
->owner
->type
== bp_breakpoint
4368 || loc
->owner
->type
== bp_hardware_breakpoint
)
4370 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4372 if (loc
->function_name
)
4373 loc
->function_name
= xstrdup (loc
->function_name
);
4377 /* set_raw_breakpoint is a low level routine for allocating and
4378 partially initializing a breakpoint of type BPTYPE. The newly
4379 created breakpoint's address, section, source file name, and line
4380 number are provided by SAL. The newly created and partially
4381 initialized breakpoint is added to the breakpoint chain and
4382 is also returned as the value of this function.
4384 It is expected that the caller will complete the initialization of
4385 the newly created breakpoint struct as well as output any status
4386 information regarding the creation of a new breakpoint. In
4387 particular, set_raw_breakpoint does NOT set the breakpoint
4388 number! Care should be taken to not allow an error to occur
4389 prior to completing the initialization of the breakpoint. If this
4390 should happen, a bogus breakpoint will be left on the chain. */
4393 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4395 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4396 CORE_ADDR adjusted_address
;
4398 /* Adjust the breakpoint's address prior to allocating a location.
4399 Once we call allocate_bp_location(), that mostly uninitialized
4400 location will be placed on the location chain. Adjustment of the
4401 breakpoint may cause target_read_memory() to be called and we do
4402 not want its scan of the location chain to find a breakpoint and
4403 location that's only been partially initialized. */
4404 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4406 b
->loc
= allocate_bp_location (b
, bptype
);
4407 b
->loc
->requested_address
= sal
.pc
;
4408 b
->loc
->address
= adjusted_address
;
4410 if (sal
.symtab
== NULL
)
4411 b
->source_file
= NULL
;
4413 b
->source_file
= savestring (sal
.symtab
->filename
,
4414 strlen (sal
.symtab
->filename
));
4415 b
->loc
->section
= sal
.section
;
4416 b
->line_number
= sal
.line
;
4418 set_breakpoint_location_function (b
->loc
);
4420 breakpoints_changed ();
4426 /* Note that the breakpoint object B describes a permanent breakpoint
4427 instruction, hard-wired into the inferior's code. */
4429 make_breakpoint_permanent (struct breakpoint
*b
)
4431 struct bp_location
*bl
;
4432 b
->enable_state
= bp_permanent
;
4434 /* By definition, permanent breakpoints are already present in the code.
4435 Mark all locations as inserted. For now, make_breakpoint_permanent
4436 is called in just one place, so it's hard to say if it's reasonable
4437 to have permanent breakpoint with multiple locations or not,
4438 but it's easy to implmement. */
4439 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4443 static struct breakpoint
*
4444 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4446 static int internal_breakpoint_number
= -1;
4447 struct symtab_and_line sal
;
4448 struct breakpoint
*b
;
4450 init_sal (&sal
); /* initialize to zeroes */
4453 sal
.section
= find_pc_overlay (sal
.pc
);
4455 b
= set_raw_breakpoint (sal
, type
);
4456 b
->number
= internal_breakpoint_number
--;
4457 b
->disposition
= disp_donttouch
;
4464 create_longjmp_breakpoint (char *func_name
)
4466 struct breakpoint
*b
;
4467 struct minimal_symbol
*m
;
4469 if (func_name
== NULL
)
4470 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4473 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4476 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4479 b
->enable_state
= bp_disabled
;
4482 b
->addr_string
= xstrdup (func_name
);
4483 update_global_location_list ();
4486 /* Call this routine when stepping and nexting to enable a breakpoint
4487 if we do a longjmp(). When we hit that breakpoint, call
4488 set_longjmp_resume_breakpoint() to figure out where we are going. */
4491 enable_longjmp_breakpoint (void)
4493 struct breakpoint
*b
;
4496 if (b
->type
== bp_longjmp
)
4498 b
->enable_state
= bp_enabled
;
4499 update_global_location_list ();
4504 disable_longjmp_breakpoint (void)
4506 struct breakpoint
*b
;
4509 if (b
->type
== bp_longjmp
4510 || b
->type
== bp_longjmp_resume
)
4512 b
->enable_state
= bp_disabled
;
4513 update_global_location_list ();
4518 create_overlay_event_breakpoint (char *func_name
)
4520 struct breakpoint
*b
;
4521 struct minimal_symbol
*m
;
4523 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4526 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4528 b
->addr_string
= xstrdup (func_name
);
4530 if (overlay_debugging
== ovly_auto
)
4532 b
->enable_state
= bp_enabled
;
4533 overlay_events_enabled
= 1;
4537 b
->enable_state
= bp_disabled
;
4538 overlay_events_enabled
= 0;
4540 update_global_location_list ();
4544 enable_overlay_breakpoints (void)
4546 struct breakpoint
*b
;
4549 if (b
->type
== bp_overlay_event
)
4551 b
->enable_state
= bp_enabled
;
4552 update_global_location_list ();
4553 overlay_events_enabled
= 1;
4558 disable_overlay_breakpoints (void)
4560 struct breakpoint
*b
;
4563 if (b
->type
== bp_overlay_event
)
4565 b
->enable_state
= bp_disabled
;
4566 update_global_location_list ();
4567 overlay_events_enabled
= 0;
4572 create_thread_event_breakpoint (CORE_ADDR address
)
4574 struct breakpoint
*b
;
4576 b
= create_internal_breakpoint (address
, bp_thread_event
);
4578 b
->enable_state
= bp_enabled
;
4579 /* addr_string has to be used or breakpoint_re_set will delete me. */
4580 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4582 update_global_location_list_nothrow ();
4588 remove_thread_event_breakpoints (void)
4590 struct breakpoint
*b
, *temp
;
4592 ALL_BREAKPOINTS_SAFE (b
, temp
)
4593 if (b
->type
== bp_thread_event
)
4594 delete_breakpoint (b
);
4597 struct captured_parse_breakpoint_args
4600 struct symtabs_and_lines
*sals_p
;
4601 char ***addr_string_p
;
4605 struct lang_and_radix
4613 remove_solib_event_breakpoints (void)
4615 struct breakpoint
*b
, *temp
;
4617 ALL_BREAKPOINTS_SAFE (b
, temp
)
4618 if (b
->type
== bp_shlib_event
)
4619 delete_breakpoint (b
);
4623 create_solib_event_breakpoint (CORE_ADDR address
)
4625 struct breakpoint
*b
;
4627 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4628 update_global_location_list_nothrow ();
4632 /* Disable any breakpoints that are on code in shared libraries. Only
4633 apply to enabled breakpoints, disabled ones can just stay disabled. */
4636 disable_breakpoints_in_shlibs (void)
4638 struct bp_location
*loc
;
4639 int disabled_shlib_breaks
= 0;
4641 ALL_BP_LOCATIONS (loc
)
4643 struct breakpoint
*b
= loc
->owner
;
4644 /* We apply the check to all breakpoints, including disabled
4645 for those with loc->duplicate set. This is so that when breakpoint
4646 becomes enabled, or the duplicate is removed, gdb will try to insert
4647 all breakpoints. If we don't set shlib_disabled here, we'll try
4648 to insert those breakpoints and fail. */
4649 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4650 && !loc
->shlib_disabled
4652 && PC_SOLIB (loc
->address
)
4654 && solib_address (loc
->address
)
4658 loc
->shlib_disabled
= 1;
4663 /* Disable any breakpoints that are in in an unloaded shared library. Only
4664 apply to enabled breakpoints, disabled ones can just stay disabled. */
4667 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4669 struct bp_location
*loc
;
4670 int disabled_shlib_breaks
= 0;
4672 ALL_BP_LOCATIONS (loc
)
4674 struct breakpoint
*b
= loc
->owner
;
4675 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4676 || loc
->loc_type
== bp_loc_software_breakpoint
)
4677 && !loc
->shlib_disabled
)
4680 char *so_name
= PC_SOLIB (loc
->address
);
4682 char *so_name
= solib_address (loc
->address
);
4684 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4686 loc
->shlib_disabled
= 1;
4687 /* At this point, we cannot rely on remove_breakpoint
4688 succeeding so we must mark the breakpoint as not inserted
4689 to prevent future errors occurring in remove_breakpoints. */
4691 if (!disabled_shlib_breaks
)
4693 target_terminal_ours_for_output ();
4694 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4697 disabled_shlib_breaks
= 1;
4704 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4705 enum bptype bp_kind
)
4707 struct symtab_and_line sal
;
4708 struct breakpoint
*b
;
4709 int thread
= -1; /* All threads. */
4716 b
= set_raw_breakpoint (sal
, bp_kind
);
4717 set_breakpoint_count (breakpoint_count
+ 1);
4718 b
->number
= breakpoint_count
;
4719 b
->cond_string
= (cond_string
== NULL
) ?
4720 NULL
: savestring (cond_string
, strlen (cond_string
));
4722 b
->addr_string
= NULL
;
4723 b
->enable_state
= bp_enabled
;
4724 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4725 b
->forked_inferior_pid
= 0;
4726 update_global_location_list ();
4733 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4735 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4739 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4741 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4745 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4747 struct symtab_and_line sal
;
4748 struct breakpoint
*b
;
4749 int thread
= -1; /* All threads. */
4756 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4757 set_breakpoint_count (breakpoint_count
+ 1);
4758 b
->number
= breakpoint_count
;
4759 b
->cond_string
= (cond_string
== NULL
) ?
4760 NULL
: savestring (cond_string
, strlen (cond_string
));
4762 b
->addr_string
= NULL
;
4763 b
->enable_state
= bp_enabled
;
4764 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4765 update_global_location_list ();
4771 hw_breakpoint_used_count (void)
4773 struct breakpoint
*b
;
4778 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4786 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4788 struct breakpoint
*b
;
4791 *other_type_used
= 0;
4794 if (breakpoint_enabled (b
))
4796 if (b
->type
== type
)
4798 else if ((b
->type
== bp_hardware_watchpoint
||
4799 b
->type
== bp_read_watchpoint
||
4800 b
->type
== bp_access_watchpoint
))
4801 *other_type_used
= 1;
4807 /* Call this after hitting the longjmp() breakpoint. Use this to set
4808 a new breakpoint at the target of the jmp_buf.
4810 FIXME - This ought to be done by setting a temporary breakpoint
4811 that gets deleted automatically... */
4814 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4816 struct breakpoint
*b
;
4819 if (b
->type
== bp_longjmp_resume
)
4821 b
->loc
->requested_address
= pc
;
4822 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4824 b
->enable_state
= bp_enabled
;
4825 b
->frame_id
= frame_id
;
4826 update_global_location_list ();
4832 disable_watchpoints_before_interactive_call_start (void)
4834 struct breakpoint
*b
;
4838 if (((b
->type
== bp_watchpoint
)
4839 || (b
->type
== bp_hardware_watchpoint
)
4840 || (b
->type
== bp_read_watchpoint
)
4841 || (b
->type
== bp_access_watchpoint
))
4842 && breakpoint_enabled (b
))
4844 b
->enable_state
= bp_call_disabled
;
4845 update_global_location_list ();
4851 enable_watchpoints_after_interactive_call_stop (void)
4853 struct breakpoint
*b
;
4857 if (((b
->type
== bp_watchpoint
)
4858 || (b
->type
== bp_hardware_watchpoint
)
4859 || (b
->type
== bp_read_watchpoint
)
4860 || (b
->type
== bp_access_watchpoint
))
4861 && (b
->enable_state
== bp_call_disabled
))
4863 b
->enable_state
= bp_enabled
;
4864 update_global_location_list ();
4870 /* Set a breakpoint that will evaporate an end of command
4871 at address specified by SAL.
4872 Restrict it to frame FRAME if FRAME is nonzero. */
4875 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4878 struct breakpoint
*b
;
4879 b
= set_raw_breakpoint (sal
, type
);
4880 b
->enable_state
= bp_enabled
;
4881 b
->disposition
= disp_donttouch
;
4882 b
->frame_id
= frame_id
;
4884 /* If we're debugging a multi-threaded program, then we
4885 want momentary breakpoints to be active in only a
4886 single thread of control. */
4887 if (in_thread_list (inferior_ptid
))
4888 b
->thread
= pid_to_thread_id (inferior_ptid
);
4890 update_global_location_list_nothrow ();
4896 /* Tell the user we have just set a breakpoint B. */
4899 mention (struct breakpoint
*b
)
4902 struct cleanup
*old_chain
, *ui_out_chain
;
4903 struct ui_stream
*stb
;
4905 stb
= ui_out_stream_new (uiout
);
4906 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4908 /* FIXME: This is misplaced; mention() is called by things (like
4909 hitting a watchpoint) other than breakpoint creation. It should
4910 be possible to clean this up and at the same time replace the
4911 random calls to breakpoint_changed with this hook, as has already
4912 been done for deprecated_delete_breakpoint_hook and so on. */
4913 if (deprecated_create_breakpoint_hook
)
4914 deprecated_create_breakpoint_hook (b
);
4915 breakpoint_create_event (b
->number
);
4917 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4918 b
->ops
->print_mention (b
);
4923 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4926 ui_out_text (uiout
, "Watchpoint ");
4927 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4928 ui_out_field_int (uiout
, "number", b
->number
);
4929 ui_out_text (uiout
, ": ");
4930 print_expression (b
->exp
, stb
->stream
);
4931 ui_out_field_stream (uiout
, "exp", stb
);
4932 do_cleanups (ui_out_chain
);
4934 case bp_hardware_watchpoint
:
4935 ui_out_text (uiout
, "Hardware watchpoint ");
4936 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4937 ui_out_field_int (uiout
, "number", b
->number
);
4938 ui_out_text (uiout
, ": ");
4939 print_expression (b
->exp
, stb
->stream
);
4940 ui_out_field_stream (uiout
, "exp", stb
);
4941 do_cleanups (ui_out_chain
);
4943 case bp_read_watchpoint
:
4944 ui_out_text (uiout
, "Hardware read watchpoint ");
4945 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4946 ui_out_field_int (uiout
, "number", b
->number
);
4947 ui_out_text (uiout
, ": ");
4948 print_expression (b
->exp
, stb
->stream
);
4949 ui_out_field_stream (uiout
, "exp", stb
);
4950 do_cleanups (ui_out_chain
);
4952 case bp_access_watchpoint
:
4953 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4954 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4955 ui_out_field_int (uiout
, "number", b
->number
);
4956 ui_out_text (uiout
, ": ");
4957 print_expression (b
->exp
, stb
->stream
);
4958 ui_out_field_stream (uiout
, "exp", stb
);
4959 do_cleanups (ui_out_chain
);
4962 if (ui_out_is_mi_like_p (uiout
))
4967 if (b
->disposition
== disp_del
)
4968 printf_filtered (_("Temporary breakpoint"));
4970 printf_filtered (_("Breakpoint"));
4971 printf_filtered (_(" %d"), b
->number
);
4974 case bp_hardware_breakpoint
:
4975 if (ui_out_is_mi_like_p (uiout
))
4980 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4984 case bp_catch_unload
:
4985 printf_filtered (_("Catchpoint %d (%s %s)"),
4987 (b
->type
== bp_catch_load
) ? "load" : "unload",
4988 (b
->dll_pathname
!= NULL
) ?
4989 b
->dll_pathname
: "<any library>");
4992 case bp_catch_vfork
:
4993 printf_filtered (_("Catchpoint %d (%s)"),
4995 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4998 printf_filtered (_("Catchpoint %d (exec)"),
5005 case bp_longjmp_resume
:
5006 case bp_step_resume
:
5008 case bp_watchpoint_scope
:
5009 case bp_shlib_event
:
5010 case bp_thread_event
:
5011 case bp_overlay_event
:
5017 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5021 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5025 if (addressprint
|| b
->source_file
== NULL
)
5027 printf_filtered (" at ");
5028 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5031 printf_filtered (": file %s, line %d.",
5032 b
->source_file
, b
->line_number
);
5036 struct bp_location
*loc
= b
->loc
;
5038 for (; loc
; loc
= loc
->next
)
5040 printf_filtered (" (%d locations)", n
);
5045 do_cleanups (old_chain
);
5046 if (ui_out_is_mi_like_p (uiout
))
5048 printf_filtered ("\n");
5052 static struct bp_location
*
5053 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5054 const struct symtab_and_line
*sal
)
5056 struct bp_location
*loc
, **tmp
;
5058 loc
= allocate_bp_location (b
, bptype
);
5059 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5062 loc
->requested_address
= sal
->pc
;
5063 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5065 loc
->section
= sal
->section
;
5067 set_breakpoint_location_function (loc
);
5071 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5072 as textual description of the location, and COND_STRING
5073 as condition expression. */
5076 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5078 enum bptype type
, enum bpdisp disposition
,
5079 int thread
, int ignore_count
, int from_tty
)
5081 struct breakpoint
*b
= NULL
;
5084 if (type
== bp_hardware_breakpoint
)
5086 int i
= hw_breakpoint_used_count ();
5087 int target_resources_ok
=
5088 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5090 if (target_resources_ok
== 0)
5091 error (_("No hardware breakpoint support in the target."));
5092 else if (target_resources_ok
< 0)
5093 error (_("Hardware breakpoints used exceeds limit."));
5096 for (i
= 0; i
< sals
.nelts
; ++i
)
5098 struct symtab_and_line sal
= sals
.sals
[i
];
5099 struct bp_location
*loc
;
5102 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5106 b
= set_raw_breakpoint (sal
, type
);
5107 set_breakpoint_count (breakpoint_count
+ 1);
5108 b
->number
= breakpoint_count
;
5111 b
->cond_string
= cond_string
;
5112 b
->ignore_count
= ignore_count
;
5113 b
->enable_state
= bp_enabled
;
5114 b
->disposition
= disposition
;
5120 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5125 char *arg
= b
->cond_string
;
5126 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5128 error (_("Garbage %s follows condition"), arg
);
5133 b
->addr_string
= addr_string
;
5135 /* addr_string has to be used or breakpoint_re_set will delete
5137 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5142 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5143 elements to fill the void space. */
5144 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5146 int i
= index_to_remove
+1;
5147 int last_index
= sal
->nelts
-1;
5149 for (;i
<= last_index
; ++i
)
5150 sal
->sals
[i
-1] = sal
->sals
[i
];
5155 /* If appropriate, obtains all sals that correspond
5156 to the same file and line as SAL. This is done
5157 only if SAL does not have explicit PC and has
5158 line and file information. If we got just a single
5159 expanded sal, return the original.
5161 Otherwise, if SAL.explicit_line is not set, filter out
5162 all sals for which the name of enclosing function
5163 is different from SAL. This makes sure that if we have
5164 breakpoint originally set in template instantiation, say
5165 foo<int>(), we won't expand SAL to locations at the same
5166 line in all existing instantiations of 'foo'.
5169 struct symtabs_and_lines
5170 expand_line_sal_maybe (struct symtab_and_line sal
)
5172 struct symtabs_and_lines expanded
;
5173 CORE_ADDR original_pc
= sal
.pc
;
5174 char *original_function
= NULL
;
5178 /* If we have explicit pc, don't expand.
5179 If we have no line number, we can't expand. */
5180 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5183 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5184 expanded
.sals
[0] = sal
;
5189 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5191 expanded
= expand_line_sal (sal
);
5192 if (expanded
.nelts
== 1)
5194 /* We had one sal, we got one sal. Without futher
5195 processing, just return the original sal. */
5196 xfree (expanded
.sals
);
5198 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5199 sal
.pc
= original_pc
;
5200 expanded
.sals
[0] = sal
;
5204 if (!sal
.explicit_line
)
5206 CORE_ADDR func_addr
, func_end
;
5207 for (i
= 0; i
< expanded
.nelts
; ++i
)
5209 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5210 char *this_function
;
5211 if (find_pc_partial_function (pc
, &this_function
,
5212 &func_addr
, &func_end
))
5214 if (this_function
&&
5215 strcmp (this_function
, original_function
) != 0)
5217 remove_sal (&expanded
, i
);
5220 else if (func_addr
== pc
)
5222 /* We're at beginning of a function, and should
5224 struct symbol
*sym
= find_pc_function (pc
);
5226 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5229 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5236 if (expanded
.nelts
<= 1)
5238 /* This is un ugly workaround. If we get zero
5239 expanded sals then something is really wrong.
5240 Fix that by returnign the original sal. */
5241 xfree (expanded
.sals
);
5243 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5244 sal
.pc
= original_pc
;
5245 expanded
.sals
[0] = sal
;
5252 for (i
= 0; i
< expanded
.nelts
; ++i
)
5253 if (expanded
.sals
[i
].pc
== original_pc
)
5264 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5265 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5266 value. COND_STRING, if not NULL, specified the condition to be
5267 used for all breakpoints. Essentially the only case where
5268 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5269 function. In that case, it's still not possible to specify
5270 separate conditions for different overloaded functions, so
5271 we take just a single condition string.
5273 NOTE: If the function succeeds, the caller is expected to cleanup
5274 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5275 array contents). If the function fails (error() is called), the
5276 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5277 COND and SALS arrays and each of those arrays contents. */
5280 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5282 enum bptype type
, enum bpdisp disposition
,
5283 int thread
, int ignore_count
, int from_tty
)
5286 for (i
= 0; i
< sals
.nelts
; ++i
)
5288 struct symtabs_and_lines expanded
=
5289 expand_line_sal_maybe (sals
.sals
[i
]);
5291 create_breakpoint (expanded
, addr_string
[i
],
5292 cond_string
, type
, disposition
,
5293 thread
, ignore_count
, from_tty
);
5296 update_global_location_list ();
5299 /* Parse ARG which is assumed to be a SAL specification possibly
5300 followed by conditionals. On return, SALS contains an array of SAL
5301 addresses found. ADDR_STRING contains a vector of (canonical)
5302 address strings. ARG points to the end of the SAL. */
5305 parse_breakpoint_sals (char **address
,
5306 struct symtabs_and_lines
*sals
,
5307 char ***addr_string
,
5310 char *addr_start
= *address
;
5311 *addr_string
= NULL
;
5312 /* If no arg given, or if first arg is 'if ', use the default
5314 if ((*address
) == NULL
5315 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5317 if (default_breakpoint_valid
)
5319 struct symtab_and_line sal
;
5320 init_sal (&sal
); /* initialize to zeroes */
5321 sals
->sals
= (struct symtab_and_line
*)
5322 xmalloc (sizeof (struct symtab_and_line
));
5323 sal
.pc
= default_breakpoint_address
;
5324 sal
.line
= default_breakpoint_line
;
5325 sal
.symtab
= default_breakpoint_symtab
;
5326 sal
.section
= find_pc_overlay (sal
.pc
);
5327 sals
->sals
[0] = sal
;
5331 error (_("No default breakpoint address now."));
5335 /* Force almost all breakpoints to be in terms of the
5336 current_source_symtab (which is decode_line_1's default). This
5337 should produce the results we want almost all of the time while
5338 leaving default_breakpoint_* alone.
5339 ObjC: However, don't match an Objective-C method name which
5340 may have a '+' or '-' succeeded by a '[' */
5342 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5344 if (default_breakpoint_valid
5346 || ((strchr ("+-", (*address
)[0]) != NULL
)
5347 && ((*address
)[1] != '['))))
5348 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5349 default_breakpoint_line
, addr_string
,
5352 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5353 addr_string
, not_found_ptr
);
5355 /* For any SAL that didn't have a canonical string, fill one in. */
5356 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5357 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5358 if (addr_start
!= (*address
))
5361 for (i
= 0; i
< sals
->nelts
; i
++)
5363 /* Add the string if not present. */
5364 if ((*addr_string
)[i
] == NULL
)
5365 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5371 /* Convert each SAL into a real PC. Verify that the PC can be
5372 inserted as a breakpoint. If it can't throw an error. */
5375 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5379 for (i
= 0; i
< sals
->nelts
; i
++)
5380 resolve_sal_pc (&sals
->sals
[i
]);
5384 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5386 struct captured_parse_breakpoint_args
*args
= data
;
5388 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5389 args
->not_found_ptr
);
5392 /* Given TOK, a string specification of condition and thread, as
5393 accepted by the 'break' command, extract the condition
5394 string and thread number and set *COND_STRING and *THREAD.
5395 PC identifies the context at which the condition should be parsed.
5396 If no condition is found, *COND_STRING is set to NULL.
5397 If no thread is found, *THREAD is set to -1. */
5399 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5400 char **cond_string
, int *thread
)
5402 *cond_string
= NULL
;
5408 char *cond_start
= NULL
;
5409 char *cond_end
= NULL
;
5410 while (*tok
== ' ' || *tok
== '\t')
5415 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5418 toklen
= end_tok
- tok
;
5420 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5422 tok
= cond_start
= end_tok
+ 1;
5423 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5425 *cond_string
= savestring (cond_start
,
5426 cond_end
- cond_start
);
5428 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5434 *thread
= strtol (tok
, &tok
, 0);
5436 error (_("Junk after thread keyword."));
5437 if (!valid_thread_id (*thread
))
5438 error (_("Unknown thread %d."), *thread
);
5441 error (_("Junk at end of arguments."));
5445 /* Set a breakpoint. This function is shared between
5446 CLI and MI functions for setting a breakpoint.
5447 This function has two major modes of operations,
5448 selected by the PARSE_CONDITION_AND_THREAD parameter.
5449 If non-zero, the function will parse arg, extracting
5450 breakpoint location, address and thread. Otherwise,
5451 ARG is just the location of breakpoint, with condition
5452 and thread specified by the COND_STRING and THREAD
5456 break_command_really (char *arg
, char *cond_string
, int thread
,
5457 int parse_condition_and_thread
,
5458 int tempflag
, int hardwareflag
,
5460 enum auto_boolean pending_break_support
,
5463 struct gdb_exception e
;
5464 struct symtabs_and_lines sals
;
5465 struct symtab_and_line pending_sal
;
5468 char *addr_start
= arg
;
5470 struct cleanup
*old_chain
;
5471 struct cleanup
*breakpoint_chain
= NULL
;
5472 struct captured_parse_breakpoint_args parse_args
;
5481 parse_args
.arg_p
= &arg
;
5482 parse_args
.sals_p
= &sals
;
5483 parse_args
.addr_string_p
= &addr_string
;
5484 parse_args
.not_found_ptr
= ¬_found
;
5486 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5487 &parse_args
, RETURN_MASK_ALL
);
5489 /* If caller is interested in rc value from parse, set value. */
5493 throw_exception (e
);
5497 case NOT_FOUND_ERROR
:
5499 /* If pending breakpoint support is turned off, throw
5502 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5503 throw_exception (e
);
5505 exception_print (gdb_stderr
, e
);
5507 /* If pending breakpoint support is auto query and the user
5508 selects no, then simply return the error code. */
5509 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5510 !nquery ("Make breakpoint pending on future shared library load? "))
5513 /* At this point, either the user was queried about setting
5514 a pending breakpoint and selected yes, or pending
5515 breakpoint behavior is on and thus a pending breakpoint
5516 is defaulted on behalf of the user. */
5517 copy_arg
= xstrdup (addr_start
);
5518 addr_string
= ©_arg
;
5520 sals
.sals
= &pending_sal
;
5525 throw_exception (e
);
5532 /* Create a chain of things that always need to be cleaned up. */
5533 old_chain
= make_cleanup (null_cleanup
, 0);
5537 /* Make sure that all storage allocated to SALS gets freed. */
5538 make_cleanup (xfree
, sals
.sals
);
5540 /* Cleanup the addr_string array but not its contents. */
5541 make_cleanup (xfree
, addr_string
);
5544 /* ----------------------------- SNIP -----------------------------
5545 Anything added to the cleanup chain beyond this point is assumed
5546 to be part of a breakpoint. If the breakpoint create succeeds
5547 then the memory is not reclaimed. */
5548 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5550 /* Mark the contents of the addr_string for cleanup. These go on
5551 the breakpoint_chain and only occure if the breakpoint create
5553 for (i
= 0; i
< sals
.nelts
; i
++)
5555 if (addr_string
[i
] != NULL
)
5556 make_cleanup (xfree
, addr_string
[i
]);
5559 /* Resolve all line numbers to PC's and verify that the addresses
5560 are ok for the target. */
5562 breakpoint_sals_to_pc (&sals
, addr_start
);
5564 /* Verify that condition can be parsed, before setting any
5565 breakpoints. Allocate a separate condition expression for each
5569 if (parse_condition_and_thread
)
5571 /* Here we only parse 'arg' to separate condition
5572 from thread number, so parsing in context of first
5573 sal is OK. When setting the breakpoint we'll
5574 re-parse it in context of each sal. */
5577 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5579 make_cleanup (xfree
, cond_string
);
5583 /* Create a private copy of condition string. */
5586 cond_string
= xstrdup (cond_string
);
5587 make_cleanup (xfree
, cond_string
);
5590 create_breakpoints (sals
, addr_string
, cond_string
,
5591 hardwareflag
? bp_hardware_breakpoint
5593 tempflag
? disp_del
: disp_donttouch
,
5594 thread
, ignore_count
, from_tty
);
5598 struct symtab_and_line sal
= {0};
5599 struct breakpoint
*b
;
5601 make_cleanup (xfree
, copy_arg
);
5603 b
= set_raw_breakpoint_without_location (hardwareflag
5604 ? bp_hardware_breakpoint
5606 set_breakpoint_count (breakpoint_count
+ 1);
5607 b
->number
= breakpoint_count
;
5609 b
->addr_string
= addr_string
[0];
5610 b
->cond_string
= NULL
;
5611 b
->ignore_count
= ignore_count
;
5612 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5613 b
->condition_not_parsed
= 1;
5615 update_global_location_list ();
5620 warning (_("Multiple breakpoints were set.\n"
5621 "Use the \"delete\" command to delete unwanted breakpoints."));
5622 /* That's it. Discard the cleanups for data inserted into the
5624 discard_cleanups (breakpoint_chain
);
5625 /* But cleanup everything else. */
5626 do_cleanups (old_chain
);
5629 /* Set a breakpoint.
5630 ARG is a string describing breakpoint address,
5631 condition, and thread.
5632 FLAG specifies if a breakpoint is hardware on,
5633 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5637 break_command_1 (char *arg
, int flag
, int from_tty
)
5639 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5640 int tempflag
= flag
& BP_TEMPFLAG
;
5642 break_command_really (arg
,
5643 NULL
, 0, 1 /* parse arg */,
5644 tempflag
, hardwareflag
,
5645 0 /* Ignore count */,
5646 pending_break_support
, from_tty
);
5651 set_breakpoint (char *address
, char *condition
,
5652 int hardwareflag
, int tempflag
,
5653 int thread
, int ignore_count
,
5656 break_command_really (address
, condition
, thread
,
5657 0 /* condition and thread are valid. */,
5658 tempflag
, hardwareflag
,
5661 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5665 /* Adjust SAL to the first instruction past the function prologue.
5666 The end of the prologue is determined using the line table from
5667 the debugging information.
5669 If SAL is already past the prologue, then do nothing. */
5672 skip_prologue_sal (struct symtab_and_line
*sal
)
5674 struct symbol
*sym
= find_pc_function (sal
->pc
);
5675 struct symtab_and_line start_sal
;
5680 start_sal
= find_function_start_sal (sym
, 1);
5681 if (sal
->pc
< start_sal
.pc
)
5685 /* Helper function for break_command_1 and disassemble_command. */
5688 resolve_sal_pc (struct symtab_and_line
*sal
)
5692 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5694 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5695 error (_("No line %d in file \"%s\"."),
5696 sal
->line
, sal
->symtab
->filename
);
5699 /* If this SAL corresponds to a breakpoint inserted using
5700 a line number, then skip the function prologue if necessary. */
5701 if (sal
->explicit_line
)
5702 skip_prologue_sal (sal
);
5705 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5707 struct blockvector
*bv
;
5711 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5714 sym
= block_function (b
);
5717 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5718 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5722 /* It really is worthwhile to have the section, so we'll just
5723 have to look harder. This case can be executed if we have
5724 line numbers but no functions (as can happen in assembly
5727 struct minimal_symbol
*msym
;
5729 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5731 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5738 break_command (char *arg
, int from_tty
)
5740 break_command_1 (arg
, 0, from_tty
);
5744 tbreak_command (char *arg
, int from_tty
)
5746 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5750 hbreak_command (char *arg
, int from_tty
)
5752 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5756 thbreak_command (char *arg
, int from_tty
)
5758 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5762 stop_command (char *arg
, int from_tty
)
5764 printf_filtered (_("Specify the type of breakpoint to set.\n\
5765 Usage: stop in <function | address>\n\
5766 stop at <line>\n"));
5770 stopin_command (char *arg
, int from_tty
)
5774 if (arg
== (char *) NULL
)
5776 else if (*arg
!= '*')
5781 /* look for a ':'. If this is a line number specification, then
5782 say it is bad, otherwise, it should be an address or
5783 function/method name */
5784 while (*argptr
&& !hasColon
)
5786 hasColon
= (*argptr
== ':');
5791 badInput
= (*argptr
!= ':'); /* Not a class::method */
5793 badInput
= isdigit (*arg
); /* a simple line number */
5797 printf_filtered (_("Usage: stop in <function | address>\n"));
5799 break_command_1 (arg
, 0, from_tty
);
5803 stopat_command (char *arg
, int from_tty
)
5807 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5814 /* look for a ':'. If there is a '::' then get out, otherwise
5815 it is probably a line number. */
5816 while (*argptr
&& !hasColon
)
5818 hasColon
= (*argptr
== ':');
5823 badInput
= (*argptr
== ':'); /* we have class::method */
5825 badInput
= !isdigit (*arg
); /* not a line number */
5829 printf_filtered (_("Usage: stop at <line>\n"));
5831 break_command_1 (arg
, 0, from_tty
);
5834 /* accessflag: hw_write: watch write,
5835 hw_read: watch read,
5836 hw_access: watch access (read or write) */
5838 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5840 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5841 struct symtab_and_line sal
;
5842 struct expression
*exp
;
5843 struct block
*exp_valid_block
;
5844 struct value
*val
, *mark
;
5845 struct frame_info
*frame
;
5846 struct frame_info
*prev_frame
= NULL
;
5847 char *exp_start
= NULL
;
5848 char *exp_end
= NULL
;
5849 char *tok
, *id_tok_start
, *end_tok
;
5851 char *cond_start
= NULL
;
5852 char *cond_end
= NULL
;
5853 struct expression
*cond
= NULL
;
5854 int i
, other_type_used
, target_resources_ok
= 0;
5855 enum bptype bp_type
;
5859 init_sal (&sal
); /* initialize to zeroes */
5861 /* Make sure that we actually have parameters to parse. */
5862 if (arg
!= NULL
&& arg
[0] != '\0')
5864 toklen
= strlen (arg
); /* Size of argument list. */
5866 /* Points tok to the end of the argument list. */
5867 tok
= arg
+ toklen
- 1;
5869 /* Go backwards in the parameters list. Skip the last parameter.
5870 If we're expecting a 'thread <thread_num>' parameter, this should
5871 be the thread identifier. */
5872 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5874 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5877 /* Points end_tok to the beginning of the last token. */
5878 id_tok_start
= tok
+ 1;
5880 /* Go backwards in the parameters list. Skip one more parameter.
5881 If we're expecting a 'thread <thread_num>' parameter, we should
5882 reach a "thread" token. */
5883 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5888 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5891 /* Move the pointer forward to skip the whitespace and
5892 calculate the length of the token. */
5894 toklen
= end_tok
- tok
;
5896 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5898 /* At this point we've found a "thread" token, which means
5899 the user is trying to set a watchpoint that triggers
5900 only in a specific thread. */
5903 /* Extract the thread ID from the next token. */
5904 thread
= strtol (id_tok_start
, &endp
, 0);
5906 /* Check if the user provided a valid numeric value for the
5908 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5909 error (_("Invalid thread ID specification %s."), id_tok_start
);
5911 /* Check if the thread actually exists. */
5912 if (!valid_thread_id (thread
))
5913 error (_("Unknown thread %d."), thread
);
5915 /* Truncate the string and get rid of the thread <thread_num>
5916 parameter before the parameter list is parsed by the
5917 evaluate_expression() function. */
5922 /* Parse the rest of the arguments. */
5923 innermost_block
= NULL
;
5925 exp
= parse_exp_1 (&arg
, 0, 0);
5927 exp_valid_block
= innermost_block
;
5928 mark
= value_mark ();
5929 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5931 release_value (val
);
5934 while (*tok
== ' ' || *tok
== '\t')
5938 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5941 toklen
= end_tok
- tok
;
5942 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5944 tok
= cond_start
= end_tok
+ 1;
5945 cond
= parse_exp_1 (&tok
, 0, 0);
5949 error (_("Junk at end of command."));
5951 if (accessflag
== hw_read
)
5952 bp_type
= bp_read_watchpoint
;
5953 else if (accessflag
== hw_access
)
5954 bp_type
= bp_access_watchpoint
;
5956 bp_type
= bp_hardware_watchpoint
;
5958 mem_cnt
= can_use_hardware_watchpoint (val
);
5959 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5960 error (_("Expression cannot be implemented with read/access watchpoint."));
5963 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5964 target_resources_ok
=
5965 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5967 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5968 error (_("Target does not support this type of hardware watchpoint."));
5970 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5971 error (_("Target can only support one kind of HW watchpoint at a time."));
5974 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5975 watchpoint could not be set. */
5976 if (!mem_cnt
|| target_resources_ok
<= 0)
5977 bp_type
= bp_watchpoint
;
5979 frame
= block_innermost_frame (exp_valid_block
);
5981 prev_frame
= get_prev_frame (frame
);
5985 /* If the expression is "local", then set up a "watchpoint scope"
5986 breakpoint at the point where we've left the scope of the watchpoint
5987 expression. Create the scope breakpoint before the watchpoint, so
5988 that we will encounter it first in bpstat_stop_status. */
5989 if (innermost_block
&& prev_frame
)
5991 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5992 bp_watchpoint_scope
);
5994 scope_breakpoint
->enable_state
= bp_enabled
;
5996 /* Automatically delete the breakpoint when it hits. */
5997 scope_breakpoint
->disposition
= disp_del
;
5999 /* Only break in the proper frame (help with recursion). */
6000 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6002 /* Set the address at which we will stop. */
6003 scope_breakpoint
->loc
->requested_address
6004 = get_frame_pc (prev_frame
);
6005 scope_breakpoint
->loc
->address
6006 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6007 scope_breakpoint
->type
);
6010 /* Now set up the breakpoint. */
6011 b
= set_raw_breakpoint (sal
, bp_type
);
6012 set_breakpoint_count (breakpoint_count
+ 1);
6013 b
->number
= breakpoint_count
;
6015 b
->disposition
= disp_donttouch
;
6017 b
->exp_valid_block
= exp_valid_block
;
6018 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6021 b
->loc
->cond
= cond
;
6023 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6028 b
->watchpoint_frame
= get_frame_id (frame
);
6030 b
->watchpoint_frame
= null_frame_id
;
6032 if (scope_breakpoint
!= NULL
)
6034 /* The scope breakpoint is related to the watchpoint. We will
6035 need to act on them together. */
6036 b
->related_breakpoint
= scope_breakpoint
;
6037 scope_breakpoint
->related_breakpoint
= b
;
6040 value_free_to_mark (mark
);
6042 update_global_location_list ();
6045 /* Return count of locations need to be watched and can be handled
6046 in hardware. If the watchpoint can not be handled
6047 in hardware return zero. */
6050 can_use_hardware_watchpoint (struct value
*v
)
6052 int found_memory_cnt
= 0;
6053 struct value
*head
= v
;
6055 /* Did the user specifically forbid us to use hardware watchpoints? */
6056 if (!can_use_hw_watchpoints
)
6059 /* Make sure that the value of the expression depends only upon
6060 memory contents, and values computed from them within GDB. If we
6061 find any register references or function calls, we can't use a
6062 hardware watchpoint.
6064 The idea here is that evaluating an expression generates a series
6065 of values, one holding the value of every subexpression. (The
6066 expression a*b+c has five subexpressions: a, b, a*b, c, and
6067 a*b+c.) GDB's values hold almost enough information to establish
6068 the criteria given above --- they identify memory lvalues,
6069 register lvalues, computed values, etcetera. So we can evaluate
6070 the expression, and then scan the chain of values that leaves
6071 behind to decide whether we can detect any possible change to the
6072 expression's final value using only hardware watchpoints.
6074 However, I don't think that the values returned by inferior
6075 function calls are special in any way. So this function may not
6076 notice that an expression involving an inferior function call
6077 can't be watched with hardware watchpoints. FIXME. */
6078 for (; v
; v
= value_next (v
))
6080 if (VALUE_LVAL (v
) == lval_memory
)
6083 /* A lazy memory lvalue is one that GDB never needed to fetch;
6084 we either just used its address (e.g., `a' in `a.b') or
6085 we never needed it at all (e.g., `a' in `a,b'). */
6089 /* Ahh, memory we actually used! Check if we can cover
6090 it with hardware watchpoints. */
6091 struct type
*vtype
= check_typedef (value_type (v
));
6093 /* We only watch structs and arrays if user asked for it
6094 explicitly, never if they just happen to appear in a
6095 middle of some value chain. */
6097 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6098 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6100 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6101 int len
= TYPE_LENGTH (value_type (v
));
6103 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6110 else if (VALUE_LVAL (v
) != not_lval
6111 && deprecated_value_modifiable (v
) == 0)
6112 return 0; /* ??? What does this represent? */
6113 else if (VALUE_LVAL (v
) == lval_register
)
6114 return 0; /* cannot watch a register with a HW watchpoint */
6117 /* The expression itself looks suitable for using a hardware
6118 watchpoint, but give the target machine a chance to reject it. */
6119 return found_memory_cnt
;
6123 watch_command_wrapper (char *arg
, int from_tty
)
6125 watch_command (arg
, from_tty
);
6129 watch_command (char *arg
, int from_tty
)
6131 watch_command_1 (arg
, hw_write
, from_tty
);
6135 rwatch_command_wrapper (char *arg
, int from_tty
)
6137 rwatch_command (arg
, from_tty
);
6141 rwatch_command (char *arg
, int from_tty
)
6143 watch_command_1 (arg
, hw_read
, from_tty
);
6147 awatch_command_wrapper (char *arg
, int from_tty
)
6149 awatch_command (arg
, from_tty
);
6153 awatch_command (char *arg
, int from_tty
)
6155 watch_command_1 (arg
, hw_access
, from_tty
);
6159 /* Helper routines for the until_command routine in infcmd.c. Here
6160 because it uses the mechanisms of breakpoints. */
6162 /* This function is called by fetch_inferior_event via the
6163 cmd_continuation pointer, to complete the until command. It takes
6164 care of cleaning up the temporary breakpoints set up by the until
6167 until_break_command_continuation (struct continuation_arg
*arg
, int error
)
6169 delete_breakpoint ((struct breakpoint
*)(arg
->data
.pointer
));
6171 delete_breakpoint ((struct breakpoint
*)(arg
->next
->data
.pointer
));
6175 until_break_command (char *arg
, int from_tty
, int anywhere
)
6177 struct symtabs_and_lines sals
;
6178 struct symtab_and_line sal
;
6179 struct frame_info
*frame
= get_selected_frame (NULL
);
6180 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6181 struct breakpoint
*breakpoint
;
6182 struct breakpoint
*breakpoint2
= NULL
;
6183 struct cleanup
*old_chain
;
6184 struct continuation_arg
*arg1
;
6185 struct continuation_arg
*arg2
;
6188 clear_proceed_status ();
6190 /* Set a breakpoint where the user wants it and at return from
6193 if (default_breakpoint_valid
)
6194 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6195 default_breakpoint_line
, (char ***) NULL
, NULL
);
6197 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6198 0, (char ***) NULL
, NULL
);
6200 if (sals
.nelts
!= 1)
6201 error (_("Couldn't get information on specified line."));
6204 xfree (sals
.sals
); /* malloc'd, so freed */
6207 error (_("Junk at end of arguments."));
6209 resolve_sal_pc (&sal
);
6212 /* If the user told us to continue until a specified location,
6213 we don't specify a frame at which we need to stop. */
6214 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6216 /* Otherwise, specify the current frame, because we want to stop only
6217 at the very same frame. */
6218 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6221 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6223 /* Keep within the current frame, or in frames called by the current
6227 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6228 sal
.pc
= get_frame_pc (prev_frame
);
6229 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6231 make_cleanup_delete_breakpoint (breakpoint2
);
6234 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6236 /* If we are running asynchronously, and proceed call above has actually
6237 managed to start the target, arrange for breakpoints to be
6238 deleted when the target stops. Otherwise, we're already stopped and
6239 delete breakpoints via cleanup chain. */
6241 if (target_can_async_p () && target_executing
)
6244 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6246 arg1
->data
.pointer
= breakpoint
;
6250 arg2
= (struct continuation_arg
*)
6251 xmalloc ( sizeof (struct continuation_arg
));
6253 arg2
->data
.pointer
= breakpoint2
;
6257 discard_cleanups (old_chain
);
6258 add_continuation (until_break_command_continuation
, arg1
);
6261 do_cleanups (old_chain
);
6265 ep_skip_leading_whitespace (char **s
)
6267 if ((s
== NULL
) || (*s
== NULL
))
6269 while (isspace (**s
))
6273 /* This function examines a string, and attempts to find a token
6274 that might be an event name in the leading characters. If a
6275 possible match is found, a pointer to the last character of
6276 the token is returned. Else, NULL is returned. */
6279 ep_find_event_name_end (char *arg
)
6282 char *event_name_end
= NULL
;
6284 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6288 /* We break out of the loop when we find a token delimiter.
6289 Basically, we're looking for alphanumerics and underscores;
6290 anything else delimites the token. */
6293 if (!isalnum (*s
) && (*s
!= '_'))
6299 return event_name_end
;
6303 /* This function attempts to parse an optional "if <cond>" clause
6304 from the arg string. If one is not found, it returns NULL.
6306 Else, it returns a pointer to the condition string. (It does not
6307 attempt to evaluate the string against a particular block.) And,
6308 it updates arg to point to the first character following the parsed
6309 if clause in the arg string. */
6312 ep_parse_optional_if_clause (char **arg
)
6316 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6319 /* Skip the "if" keyword. */
6322 /* Skip any extra leading whitespace, and record the start of the
6323 condition string. */
6324 ep_skip_leading_whitespace (arg
);
6327 /* Assume that the condition occupies the remainder of the arg string. */
6328 (*arg
) += strlen (cond_string
);
6333 /* This function attempts to parse an optional filename from the arg
6334 string. If one is not found, it returns NULL.
6336 Else, it returns a pointer to the parsed filename. (This function
6337 makes no attempt to verify that a file of that name exists, or is
6338 accessible.) And, it updates arg to point to the first character
6339 following the parsed filename in the arg string.
6341 Note that clients needing to preserve the returned filename for
6342 future access should copy it to their own buffers. */
6344 ep_parse_optional_filename (char **arg
)
6346 static char filename
[1024];
6351 if ((*arg_p
== '\0') || isspace (*arg_p
))
6369 /* Commands to deal with catching events, such as signals, exceptions,
6370 process start/exit, etc. */
6374 catch_fork
, catch_vfork
6379 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6382 char *cond_string
= NULL
;
6384 ep_skip_leading_whitespace (&arg
);
6386 /* The allowed syntax is:
6388 catch [v]fork if <cond>
6390 First, check if there's an if clause. */
6391 cond_string
= ep_parse_optional_if_clause (&arg
);
6393 if ((*arg
!= '\0') && !isspace (*arg
))
6394 error (_("Junk at end of arguments."));
6396 /* If this target supports it, create a fork or vfork catchpoint
6397 and enable reporting of such events. */
6401 create_fork_event_catchpoint (tempflag
, cond_string
);
6404 create_vfork_event_catchpoint (tempflag
, cond_string
);
6407 error (_("unsupported or unknown fork kind; cannot catch it"));
6413 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6415 char *cond_string
= NULL
;
6417 ep_skip_leading_whitespace (&arg
);
6419 /* The allowed syntax is:
6421 catch exec if <cond>
6423 First, check if there's an if clause. */
6424 cond_string
= ep_parse_optional_if_clause (&arg
);
6426 if ((*arg
!= '\0') && !isspace (*arg
))
6427 error (_("Junk at end of arguments."));
6429 /* If this target supports it, create an exec catchpoint
6430 and enable reporting of such events. */
6431 create_exec_event_catchpoint (tempflag
, cond_string
);
6435 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6437 char *dll_pathname
= NULL
;
6438 char *cond_string
= NULL
;
6440 ep_skip_leading_whitespace (&arg
);
6442 /* The allowed syntax is:
6444 catch load if <cond>
6445 catch load <filename>
6446 catch load <filename> if <cond>
6448 The user is not allowed to specify the <filename> after an
6451 We'll ignore the pathological case of a file named "if".
6453 First, check if there's an if clause. If so, then there
6454 cannot be a filename. */
6455 cond_string
= ep_parse_optional_if_clause (&arg
);
6457 /* If there was an if clause, then there cannot be a filename.
6458 Else, there might be a filename and an if clause. */
6459 if (cond_string
== NULL
)
6461 dll_pathname
= ep_parse_optional_filename (&arg
);
6462 ep_skip_leading_whitespace (&arg
);
6463 cond_string
= ep_parse_optional_if_clause (&arg
);
6466 if ((*arg
!= '\0') && !isspace (*arg
))
6467 error (_("Junk at end of arguments."));
6469 /* Create a load breakpoint that only triggers when a load of
6470 the specified dll (or any dll, if no pathname was specified)
6472 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6473 dll_pathname
, cond_string
);
6477 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6479 char *dll_pathname
= NULL
;
6480 char *cond_string
= NULL
;
6482 ep_skip_leading_whitespace (&arg
);
6484 /* The allowed syntax is:
6486 catch unload if <cond>
6487 catch unload <filename>
6488 catch unload <filename> if <cond>
6490 The user is not allowed to specify the <filename> after an
6493 We'll ignore the pathological case of a file named "if".
6495 First, check if there's an if clause. If so, then there
6496 cannot be a filename. */
6497 cond_string
= ep_parse_optional_if_clause (&arg
);
6499 /* If there was an if clause, then there cannot be a filename.
6500 Else, there might be a filename and an if clause. */
6501 if (cond_string
== NULL
)
6503 dll_pathname
= ep_parse_optional_filename (&arg
);
6504 ep_skip_leading_whitespace (&arg
);
6505 cond_string
= ep_parse_optional_if_clause (&arg
);
6508 if ((*arg
!= '\0') && !isspace (*arg
))
6509 error (_("Junk at end of arguments."));
6511 /* Create an unload breakpoint that only triggers when an unload of
6512 the specified dll (or any dll, if no pathname was specified)
6514 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6515 dll_pathname
, cond_string
);
6518 static enum print_stop_action
6519 print_exception_catchpoint (struct breakpoint
*b
)
6521 annotate_catchpoint (b
->number
);
6523 if (strstr (b
->addr_string
, "throw") != NULL
)
6524 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6527 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6530 return PRINT_SRC_AND_LOC
;
6534 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6539 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6542 *last_addr
= b
->loc
->address
;
6543 if (strstr (b
->addr_string
, "throw") != NULL
)
6544 ui_out_field_string (uiout
, "what", "exception throw");
6546 ui_out_field_string (uiout
, "what", "exception catch");
6550 print_mention_exception_catchpoint (struct breakpoint
*b
)
6552 if (strstr (b
->addr_string
, "throw") != NULL
)
6553 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6555 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6558 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6559 print_exception_catchpoint
,
6560 print_one_exception_catchpoint
,
6561 print_mention_exception_catchpoint
6565 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6566 enum exception_event_kind ex_event
, int from_tty
)
6568 char *trigger_func_name
, *nameptr
;
6569 struct symtabs_and_lines sals
;
6570 struct breakpoint
*b
;
6572 if (ex_event
== EX_EVENT_CATCH
)
6573 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6575 trigger_func_name
= xstrdup ("__cxa_throw");
6577 nameptr
= trigger_func_name
;
6578 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6579 if (sals
.nelts
== 0)
6581 xfree (trigger_func_name
);
6585 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6586 set_breakpoint_count (breakpoint_count
+ 1);
6587 b
->number
= breakpoint_count
;
6588 b
->cond_string
= (cond_string
== NULL
) ?
6589 NULL
: savestring (cond_string
, strlen (cond_string
));
6591 b
->addr_string
= trigger_func_name
;
6592 b
->enable_state
= bp_enabled
;
6593 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6594 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6598 update_global_location_list ();
6602 /* Deal with "catch catch" and "catch throw" commands */
6605 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6606 int tempflag
, int from_tty
)
6608 char *cond_string
= NULL
;
6609 struct symtab_and_line
*sal
= NULL
;
6611 ep_skip_leading_whitespace (&arg
);
6613 cond_string
= ep_parse_optional_if_clause (&arg
);
6615 if ((*arg
!= '\0') && !isspace (*arg
))
6616 error (_("Junk at end of arguments."));
6618 if ((ex_event
!= EX_EVENT_THROW
) &&
6619 (ex_event
!= EX_EVENT_CATCH
))
6620 error (_("Unsupported or unknown exception event; cannot catch it"));
6622 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6625 warning (_("Unsupported with this platform/compiler combination."));
6628 /* Create a breakpoint struct for Ada exception catchpoints. */
6631 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6635 struct expression
*cond
,
6636 struct breakpoint_ops
*ops
,
6640 struct breakpoint
*b
;
6644 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6645 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6646 version for exception catchpoints, because two catchpoints
6647 used for different exception names will use the same address.
6648 In this case, a "breakpoint ... also set at..." warning is
6649 unproductive. Besides. the warning phrasing is also a bit
6650 inapropriate, we should use the word catchpoint, and tell
6651 the user what type of catchpoint it is. The above is good
6652 enough for now, though. */
6655 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6656 set_breakpoint_count (breakpoint_count
+ 1);
6658 b
->enable_state
= bp_enabled
;
6659 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6660 b
->number
= breakpoint_count
;
6661 b
->ignore_count
= 0;
6662 b
->loc
->cond
= cond
;
6663 b
->addr_string
= addr_string
;
6664 b
->language
= language_ada
;
6665 b
->cond_string
= cond_string
;
6666 b
->exp_string
= exp_string
;
6671 update_global_location_list ();
6674 /* Implement the "catch exception" command. */
6677 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6679 struct symtab_and_line sal
;
6681 char *addr_string
= NULL
;
6682 char *exp_string
= NULL
;
6683 char *cond_string
= NULL
;
6684 struct expression
*cond
= NULL
;
6685 struct breakpoint_ops
*ops
= NULL
;
6687 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6688 &cond_string
, &cond
, &ops
);
6689 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6690 cond_string
, cond
, ops
, tempflag
,
6694 /* Implement the "catch assert" command. */
6697 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6699 struct symtab_and_line sal
;
6700 char *addr_string
= NULL
;
6701 struct breakpoint_ops
*ops
= NULL
;
6703 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6704 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6705 tempflag
, from_tty
);
6709 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6712 /* The first argument may be an event name, such as "start" or "load".
6713 If so, then handle it as such. If it doesn't match an event name,
6714 then attempt to interpret it as an exception name. (This latter is
6715 the v4.16-and-earlier GDB meaning of the "catch" command.)
6717 First, try to find the bounds of what might be an event name. */
6718 char *arg1_start
= arg
;
6722 if (arg1_start
== NULL
)
6724 /* Old behaviour was to use pre-v-4.16 syntax */
6725 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6727 /* Now, this is not allowed */
6728 error (_("Catch requires an event name."));
6731 arg1_end
= ep_find_event_name_end (arg1_start
);
6732 if (arg1_end
== NULL
)
6733 error (_("catch requires an event"));
6734 arg1_length
= arg1_end
+ 1 - arg1_start
;
6736 /* Try to match what we found against known event names. */
6737 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6739 error (_("Catch of signal not yet implemented"));
6741 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6743 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6744 tempflag
, from_tty
);
6746 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6748 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6749 tempflag
, from_tty
);
6751 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6753 error (_("Catch of thread_start not yet implemented"));
6755 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6757 error (_("Catch of thread_exit not yet implemented"));
6759 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6761 error (_("Catch of thread_join not yet implemented"));
6763 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6765 error (_("Catch of start not yet implemented"));
6767 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6769 error (_("Catch of exit not yet implemented"));
6771 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6773 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6775 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6777 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6779 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6781 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6783 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6785 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6787 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6789 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6791 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6793 error (_("Catch of stop not yet implemented"));
6795 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6797 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6800 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6802 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6805 /* This doesn't appear to be an event name */
6809 /* Pre-v.4.16 behaviour was to treat the argument
6810 as the name of an exception */
6811 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6812 /* Now this is not allowed */
6813 error (_("Unknown event kind specified for catch"));
6819 catch_command (char *arg
, int from_tty
)
6821 catch_command_1 (arg
, 0, from_tty
);
6826 tcatch_command (char *arg
, int from_tty
)
6828 catch_command_1 (arg
, 1, from_tty
);
6831 /* Delete breakpoints by address or line. */
6834 clear_command (char *arg
, int from_tty
)
6836 struct breakpoint
*b
;
6837 VEC(breakpoint_p
) *found
= 0;
6840 struct symtabs_and_lines sals
;
6841 struct symtab_and_line sal
;
6846 sals
= decode_line_spec (arg
, 1);
6851 sals
.sals
= (struct symtab_and_line
*)
6852 xmalloc (sizeof (struct symtab_and_line
));
6853 make_cleanup (xfree
, sals
.sals
);
6854 init_sal (&sal
); /* initialize to zeroes */
6855 sal
.line
= default_breakpoint_line
;
6856 sal
.symtab
= default_breakpoint_symtab
;
6857 sal
.pc
= default_breakpoint_address
;
6858 if (sal
.symtab
== 0)
6859 error (_("No source file specified."));
6867 /* We don't call resolve_sal_pc here. That's not
6868 as bad as it seems, because all existing breakpoints
6869 typically have both file/line and pc set. So, if
6870 clear is given file/line, we can match this to existing
6871 breakpoint without obtaining pc at all.
6873 We only support clearing given the address explicitly
6874 present in breakpoint table. Say, we've set breakpoint
6875 at file:line. There were several PC values for that file:line,
6876 due to optimization, all in one block.
6877 We've picked one PC value. If "clear" is issued with another
6878 PC corresponding to the same file:line, the breakpoint won't
6879 be cleared. We probably can still clear the breakpoint, but
6880 since the other PC value is never presented to user, user
6881 can only find it by guessing, and it does not seem important
6884 /* For each line spec given, delete bps which correspond
6885 to it. Do it in two passes, solely to preserve the current
6886 behavior that from_tty is forced true if we delete more than
6890 for (i
= 0; i
< sals
.nelts
; i
++)
6892 /* If exact pc given, clear bpts at that pc.
6893 If line given (pc == 0), clear all bpts on specified line.
6894 If defaulting, clear all bpts on default line
6897 defaulting sal.pc != 0 tests to do
6902 1 0 <can't happen> */
6906 /* Find all matching breakpoints and add them to
6911 /* Are we going to delete b? */
6912 if (b
->type
!= bp_none
6913 && b
->type
!= bp_watchpoint
6914 && b
->type
!= bp_hardware_watchpoint
6915 && b
->type
!= bp_read_watchpoint
6916 && b
->type
!= bp_access_watchpoint
)
6918 struct bp_location
*loc
= b
->loc
;
6919 for (; loc
; loc
= loc
->next
)
6921 int pc_match
= sal
.pc
6922 && (loc
->address
== sal
.pc
)
6923 && (!section_is_overlay (loc
->section
)
6924 || loc
->section
== sal
.section
);
6925 int line_match
= ((default_match
|| (0 == sal
.pc
))
6926 && b
->source_file
!= NULL
6927 && sal
.symtab
!= NULL
6928 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6929 && b
->line_number
== sal
.line
);
6930 if (pc_match
|| line_match
)
6939 VEC_safe_push(breakpoint_p
, found
, b
);
6942 /* Now go thru the 'found' chain and delete them. */
6943 if (VEC_empty(breakpoint_p
, found
))
6946 error (_("No breakpoint at %s."), arg
);
6948 error (_("No breakpoint at this line."));
6951 if (VEC_length(breakpoint_p
, found
) > 1)
6952 from_tty
= 1; /* Always report if deleted more than one */
6955 if (VEC_length(breakpoint_p
, found
) == 1)
6956 printf_unfiltered (_("Deleted breakpoint "));
6958 printf_unfiltered (_("Deleted breakpoints "));
6960 breakpoints_changed ();
6962 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6965 printf_unfiltered ("%d ", b
->number
);
6966 delete_breakpoint (b
);
6969 putchar_unfiltered ('\n');
6972 /* Delete breakpoint in BS if they are `delete' breakpoints and
6973 all breakpoints that are marked for deletion, whether hit or not.
6974 This is called after any breakpoint is hit, or after errors. */
6977 breakpoint_auto_delete (bpstat bs
)
6979 struct breakpoint
*b
, *temp
;
6981 for (; bs
; bs
= bs
->next
)
6982 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6984 delete_breakpoint (bs
->breakpoint_at
->owner
);
6986 ALL_BREAKPOINTS_SAFE (b
, temp
)
6988 if (b
->disposition
== disp_del_at_next_stop
)
6989 delete_breakpoint (b
);
6994 update_global_location_list (void)
6996 struct breakpoint
*b
;
6997 struct bp_location
**next
= &bp_location_chain
;
6998 struct bp_location
*loc
;
6999 struct bp_location
*loc2
;
7000 struct gdb_exception e
;
7001 VEC(bp_location_p
) *old_locations
= NULL
;
7005 /* Store old locations for future reference. */
7006 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7007 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7009 bp_location_chain
= NULL
;
7012 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7015 next
= &(loc
->global_next
);
7020 /* Identify bp_location instances that are no longer present in the new
7021 list, and therefore should be freed. Note that it's not necessary that
7022 those locations should be removed from inferior -- if there's another
7023 location at the same address (previously marked as duplicate),
7024 we don't need to remove/insert the location. */
7025 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7027 /* Tells if 'loc' is found amoung the new locations. If not, we
7029 int found_object
= 0;
7030 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7037 /* If this location is no longer present, and inserted, look if there's
7038 maybe a new location at the same address. If so, mark that one
7039 inserted, and don't remove this one. This is needed so that we
7040 don't have a time window where a breakpoint at certain location is not
7045 /* If the location is inserted now, we might have to remove it. */
7048 if (found_object
&& should_be_inserted (loc
))
7050 /* The location is still present in the location list, and still
7051 should be inserted. Don't do anything. */
7056 /* The location is either no longer present, or got disabled.
7057 See if there's another location at the same address, in which
7058 case we don't need to remove this one from the target. */
7059 if (breakpoint_address_is_meaningful (loc
->owner
))
7060 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7062 /* For the sake of should_insert_location. The
7063 call to check_duplicates will fix up this later. */
7064 loc2
->duplicate
= 0;
7065 if (should_be_inserted (loc2
)
7066 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7069 loc2
->target_info
= loc
->target_info
;
7077 if (remove_breakpoint (loc
, mark_uninserted
))
7079 /* This is just about all we can do. We could keep this
7080 location on the global list, and try to remove it next
7081 time, but there's no particular reason why we will
7084 Note that at this point, loc->owner is still valid,
7085 as delete_breakpoint frees the breakpoint only
7086 after calling us. */
7087 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7088 loc
->owner
->number
);
7093 free_bp_location (loc
);
7098 check_duplicates (b
);
7101 if (always_inserted_mode
&& target_has_execution
)
7102 insert_breakpoint_locations ();
7106 update_global_location_list_nothrow (void)
7108 struct gdb_exception e
;
7109 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7110 update_global_location_list ();
7113 /* Delete a breakpoint and clean up all traces of it in the data
7117 delete_breakpoint (struct breakpoint
*bpt
)
7119 struct breakpoint
*b
;
7121 struct bp_location
*loc
, *next
;
7123 gdb_assert (bpt
!= NULL
);
7125 /* Has this bp already been deleted? This can happen because multiple
7126 lists can hold pointers to bp's. bpstat lists are especial culprits.
7128 One example of this happening is a watchpoint's scope bp. When the
7129 scope bp triggers, we notice that the watchpoint is out of scope, and
7130 delete it. We also delete its scope bp. But the scope bp is marked
7131 "auto-deleting", and is already on a bpstat. That bpstat is then
7132 checked for auto-deleting bp's, which are deleted.
7134 A real solution to this problem might involve reference counts in bp's,
7135 and/or giving them pointers back to their referencing bpstat's, and
7136 teaching delete_breakpoint to only free a bp's storage when no more
7137 references were extent. A cheaper bandaid was chosen. */
7138 if (bpt
->type
== bp_none
)
7141 if (deprecated_delete_breakpoint_hook
)
7142 deprecated_delete_breakpoint_hook (bpt
);
7143 breakpoint_delete_event (bpt
->number
);
7145 if (breakpoint_chain
== bpt
)
7146 breakpoint_chain
= bpt
->next
;
7151 b
->next
= bpt
->next
;
7155 free_command_lines (&bpt
->commands
);
7156 if (bpt
->cond_string
!= NULL
)
7157 xfree (bpt
->cond_string
);
7158 if (bpt
->addr_string
!= NULL
)
7159 xfree (bpt
->addr_string
);
7160 if (bpt
->exp
!= NULL
)
7162 if (bpt
->exp_string
!= NULL
)
7163 xfree (bpt
->exp_string
);
7164 if (bpt
->val
!= NULL
)
7165 value_free (bpt
->val
);
7166 if (bpt
->source_file
!= NULL
)
7167 xfree (bpt
->source_file
);
7168 if (bpt
->dll_pathname
!= NULL
)
7169 xfree (bpt
->dll_pathname
);
7170 if (bpt
->triggered_dll_pathname
!= NULL
)
7171 xfree (bpt
->triggered_dll_pathname
);
7172 if (bpt
->exec_pathname
!= NULL
)
7173 xfree (bpt
->exec_pathname
);
7175 /* Be sure no bpstat's are pointing at it after it's been freed. */
7176 /* FIXME, how can we find all bpstat's?
7177 We just check stop_bpstat for now. Note that we cannot just
7178 remove bpstats pointing at bpt from the stop_bpstat list
7179 entirely, as breakpoint commands are associated with the bpstat;
7180 if we remove it here, then the later call to
7181 bpstat_do_actions (&stop_bpstat);
7182 in event-top.c won't do anything, and temporary breakpoints
7183 with commands won't work. */
7184 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7185 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7187 bs
->breakpoint_at
= NULL
;
7189 /* bs->commands will be freed later. */
7192 /* Now that breakpoint is removed from breakpoint
7193 list, update the global location list. This
7194 will remove locations that used to belong to
7195 this breakpoint. Do this before freeing
7196 the breakpoint itself, since remove_breakpoint
7197 looks at location's owner. It might be better
7198 design to have location completely self-contained,
7199 but it's not the case now. */
7200 update_global_location_list ();
7203 /* On the chance that someone will soon try again to delete this same
7204 bp, we mark it as deleted before freeing its storage. */
7205 bpt
->type
= bp_none
;
7211 do_delete_breakpoint_cleanup (void *b
)
7213 delete_breakpoint (b
);
7217 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7219 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7223 delete_command (char *arg
, int from_tty
)
7225 struct breakpoint
*b
, *temp
;
7231 int breaks_to_delete
= 0;
7233 /* Delete all breakpoints if no argument.
7234 Do not delete internal or call-dummy breakpoints, these
7235 have to be deleted with an explicit breakpoint number argument. */
7238 if (b
->type
!= bp_call_dummy
&&
7239 b
->type
!= bp_shlib_event
&&
7240 b
->type
!= bp_thread_event
&&
7241 b
->type
!= bp_overlay_event
&&
7244 breaks_to_delete
= 1;
7249 /* Ask user only if there are some breakpoints to delete. */
7251 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7253 ALL_BREAKPOINTS_SAFE (b
, temp
)
7255 if (b
->type
!= bp_call_dummy
&&
7256 b
->type
!= bp_shlib_event
&&
7257 b
->type
!= bp_thread_event
&&
7258 b
->type
!= bp_overlay_event
&&
7260 delete_breakpoint (b
);
7265 map_breakpoint_numbers (arg
, delete_breakpoint
);
7269 all_locations_are_pending (struct bp_location
*loc
)
7271 for (; loc
; loc
= loc
->next
)
7272 if (!loc
->shlib_disabled
)
7277 /* Subroutine of update_breakpoint_locations to simplify it.
7278 Return non-zero if multiple fns in list LOC have the same name.
7279 Null names are ignored. */
7282 ambiguous_names_p (struct bp_location
*loc
)
7284 struct bp_location
*l
;
7285 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7286 (int (*) (const void *, const void *)) streq
,
7287 NULL
, xcalloc
, xfree
);
7289 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7292 const char *name
= l
->function_name
;
7294 /* Allow for some names to be NULL, ignore them. */
7298 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7300 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7315 update_breakpoint_locations (struct breakpoint
*b
,
7316 struct symtabs_and_lines sals
)
7320 struct bp_location
*existing_locations
= b
->loc
;
7322 /* If there's no new locations, and all existing locations
7323 are pending, don't do anything. This optimizes
7324 the common case where all locations are in the same
7325 shared library, that was unloaded. We'd like to
7326 retain the location, so that when the library
7327 is loaded again, we don't loose the enabled/disabled
7328 status of the individual locations. */
7329 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7334 for (i
= 0; i
< sals
.nelts
; ++i
)
7336 struct bp_location
*new_loc
=
7337 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7339 /* Reparse conditions, they might contain references to the
7341 if (b
->cond_string
!= NULL
)
7343 struct gdb_exception e
;
7346 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7348 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7353 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7354 b
->number
, e
.message
);
7355 new_loc
->enabled
= 0;
7359 if (b
->source_file
!= NULL
)
7360 xfree (b
->source_file
);
7361 if (sals
.sals
[i
].symtab
== NULL
)
7362 b
->source_file
= NULL
;
7365 savestring (sals
.sals
[i
].symtab
->filename
,
7366 strlen (sals
.sals
[i
].symtab
->filename
));
7368 if (b
->line_number
== 0)
7369 b
->line_number
= sals
.sals
[i
].line
;
7372 /* If possible, carry over 'disable' status from existing breakpoints. */
7374 struct bp_location
*e
= existing_locations
;
7375 /* If there are multiple breakpoints with the same function name,
7376 e.g. for inline functions, comparing function names won't work.
7377 Instead compare pc addresses; this is just a heuristic as things
7378 may have moved, but in practice it gives the correct answer
7379 often enough until a better solution is found. */
7380 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7382 for (; e
; e
= e
->next
)
7384 if (!e
->enabled
&& e
->function_name
)
7386 struct bp_location
*l
= b
->loc
;
7387 if (have_ambiguous_names
)
7389 for (; l
; l
= l
->next
)
7390 if (e
->address
== l
->address
)
7398 for (; l
; l
= l
->next
)
7399 if (l
->function_name
7400 && strcmp (e
->function_name
, l
->function_name
) == 0)
7410 update_global_location_list ();
7414 /* Reset a breakpoint given it's struct breakpoint * BINT.
7415 The value we return ends up being the return value from catch_errors.
7416 Unused in this case. */
7419 breakpoint_re_set_one (void *bint
)
7421 /* get past catch_errs */
7422 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7426 int *not_found_ptr
= ¬_found
;
7427 struct symtabs_and_lines sals
= {};
7428 struct symtabs_and_lines expanded
;
7430 enum enable_state save_enable
;
7431 struct gdb_exception e
;
7437 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7441 case bp_hardware_breakpoint
:
7443 case bp_catch_unload
:
7444 if (b
->addr_string
== NULL
)
7446 /* Anything without a string can't be re-set. */
7447 delete_breakpoint (b
);
7451 set_language (b
->language
);
7452 input_radix
= b
->input_radix
;
7454 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7456 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7461 int not_found_and_ok
= 0;
7462 /* For pending breakpoints, it's expected that parsing
7463 will fail until the right shared library is loaded.
7464 User has already told to create pending breakpoints and
7465 don't need extra messages. If breakpoint is in bp_shlib_disabled
7466 state, then user already saw the message about that breakpoint
7467 being disabled, and don't want to see more errors. */
7469 && (b
->condition_not_parsed
7470 || (b
->loc
&& b
->loc
->shlib_disabled
)
7471 || b
->enable_state
== bp_disabled
))
7472 not_found_and_ok
= 1;
7474 if (!not_found_and_ok
)
7476 /* We surely don't want to warn about the same breakpoint
7477 10 times. One solution, implemented here, is disable
7478 the breakpoint on error. Another solution would be to
7479 have separate 'warning emitted' flag. Since this
7480 happens only when a binary has changed, I don't know
7481 which approach is better. */
7482 b
->enable_state
= bp_disabled
;
7483 throw_exception (e
);
7490 gdb_assert (sals
.nelts
== 1);
7491 resolve_sal_pc (&sals
.sals
[0]);
7492 if (b
->condition_not_parsed
&& s
&& s
[0])
7494 char *cond_string
= 0;
7496 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7497 &cond_string
, &thread
);
7499 b
->cond_string
= cond_string
;
7501 b
->condition_not_parsed
= 0;
7503 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7504 update_breakpoint_locations (b
, expanded
);
7510 case bp_hardware_watchpoint
:
7511 case bp_read_watchpoint
:
7512 case bp_access_watchpoint
:
7513 /* Watchpoint can be either on expression using entirely global variables,
7514 or it can be on local variables.
7516 Watchpoints of the first kind are never auto-deleted, and even persist
7517 across program restarts. Since they can use variables from shared
7518 libraries, we need to reparse expression as libraries are loaded
7521 Watchpoints on local variables can also change meaning as result
7522 of solib event. For example, if a watchpoint uses both a local and
7523 a global variables in expression, it's a local watchpoint, but
7524 unloading of a shared library will make the expression invalid.
7525 This is not a very common use case, but we still re-evaluate
7526 expression, to avoid surprises to the user.
7528 Note that for local watchpoints, we re-evaluate it only if
7529 watchpoints frame id is still valid. If it's not, it means
7530 the watchpoint is out of scope and will be deleted soon. In fact,
7531 I'm not sure we'll ever be called in this case.
7533 If a local watchpoint's frame id is still valid, then
7534 b->exp_valid_block is likewise valid, and we can safely use it.
7536 Don't do anything about disabled watchpoints, since they will
7537 be reevaluated again when enabled. */
7538 update_watchpoint (b
, 1 /* reparse */);
7540 /* We needn't really do anything to reset these, since the mask
7541 that requests them is unaffected by e.g., new libraries being
7544 case bp_catch_vfork
:
7549 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7551 /* Delete longjmp and overlay event breakpoints; they will be
7552 reset later by breakpoint_re_set. */
7554 case bp_longjmp_resume
:
7555 case bp_overlay_event
:
7556 delete_breakpoint (b
);
7559 /* This breakpoint is special, it's set up when the inferior
7560 starts and we really don't want to touch it. */
7561 case bp_shlib_event
:
7563 /* Like bp_shlib_event, this breakpoint type is special.
7564 Once it is set up, we do not want to touch it. */
7565 case bp_thread_event
:
7567 /* Keep temporary breakpoints, which can be encountered when we step
7568 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7569 Otherwise these should have been blown away via the cleanup chain
7570 or by breakpoint_init_inferior when we rerun the executable. */
7573 case bp_watchpoint_scope
:
7575 case bp_step_resume
:
7582 /* Re-set all breakpoints after symbols have been re-loaded. */
7584 breakpoint_re_set (void)
7586 struct breakpoint
*b
, *temp
;
7587 enum language save_language
;
7588 int save_input_radix
;
7590 save_language
= current_language
->la_language
;
7591 save_input_radix
= input_radix
;
7592 ALL_BREAKPOINTS_SAFE (b
, temp
)
7594 /* Format possible error msg */
7595 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7597 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7598 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7599 do_cleanups (cleanups
);
7601 set_language (save_language
);
7602 input_radix
= save_input_radix
;
7604 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7606 create_longjmp_breakpoint ("longjmp");
7607 create_longjmp_breakpoint ("_longjmp");
7608 create_longjmp_breakpoint ("siglongjmp");
7609 create_longjmp_breakpoint ("_siglongjmp");
7610 create_longjmp_breakpoint (NULL
);
7613 create_overlay_event_breakpoint ("_ovly_debug_event");
7616 /* Reset the thread number of this breakpoint:
7618 - If the breakpoint is for all threads, leave it as-is.
7619 - Else, reset it to the current thread for inferior_ptid. */
7621 breakpoint_re_set_thread (struct breakpoint
*b
)
7623 if (b
->thread
!= -1)
7625 if (in_thread_list (inferior_ptid
))
7626 b
->thread
= pid_to_thread_id (inferior_ptid
);
7630 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7631 If from_tty is nonzero, it prints a message to that effect,
7632 which ends with a period (no newline). */
7635 set_ignore_count (int bptnum
, int count
, int from_tty
)
7637 struct breakpoint
*b
;
7643 if (b
->number
== bptnum
)
7645 b
->ignore_count
= count
;
7649 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7651 else if (count
== 1)
7652 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7655 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7658 breakpoints_changed ();
7659 breakpoint_modify_event (b
->number
);
7663 error (_("No breakpoint number %d."), bptnum
);
7666 /* Clear the ignore counts of all breakpoints. */
7668 breakpoint_clear_ignore_counts (void)
7670 struct breakpoint
*b
;
7673 b
->ignore_count
= 0;
7676 /* Command to set ignore-count of breakpoint N to COUNT. */
7679 ignore_command (char *args
, int from_tty
)
7685 error_no_arg (_("a breakpoint number"));
7687 num
= get_number (&p
);
7689 error (_("bad breakpoint number: '%s'"), args
);
7691 error (_("Second argument (specified ignore-count) is missing."));
7693 set_ignore_count (num
,
7694 longest_to_int (value_as_long (parse_and_eval (p
))),
7697 printf_filtered ("\n");
7700 /* Call FUNCTION on each of the breakpoints
7701 whose numbers are given in ARGS. */
7704 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7709 struct breakpoint
*b
, *tmp
;
7713 error_no_arg (_("one or more breakpoint numbers"));
7720 num
= get_number_or_range (&p1
);
7723 warning (_("bad breakpoint number at or near '%s'"), p
);
7727 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7728 if (b
->number
== num
)
7730 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7733 if (related_breakpoint
)
7734 function (related_breakpoint
);
7738 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7744 static struct bp_location
*
7745 find_location_by_number (char *number
)
7747 char *dot
= strchr (number
, '.');
7751 struct breakpoint
*b
;
7752 struct bp_location
*loc
;
7757 bp_num
= get_number_or_range (&p1
);
7759 error (_("Bad breakpoint number '%s'"), number
);
7762 if (b
->number
== bp_num
)
7767 if (!b
|| b
->number
!= bp_num
)
7768 error (_("Bad breakpoint number '%s'"), number
);
7771 loc_num
= get_number_or_range (&p1
);
7773 error (_("Bad breakpoint location number '%s'"), number
);
7777 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7780 error (_("Bad breakpoint location number '%s'"), dot
+1);
7786 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7787 If from_tty is nonzero, it prints a message to that effect,
7788 which ends with a period (no newline). */
7791 disable_breakpoint (struct breakpoint
*bpt
)
7793 /* Never disable a watchpoint scope breakpoint; we want to
7794 hit them when we leave scope so we can delete both the
7795 watchpoint and its scope breakpoint at that time. */
7796 if (bpt
->type
== bp_watchpoint_scope
)
7799 /* You can't disable permanent breakpoints. */
7800 if (bpt
->enable_state
== bp_permanent
)
7803 bpt
->enable_state
= bp_disabled
;
7805 update_global_location_list ();
7807 if (deprecated_modify_breakpoint_hook
)
7808 deprecated_modify_breakpoint_hook (bpt
);
7809 breakpoint_modify_event (bpt
->number
);
7813 disable_command (char *args
, int from_tty
)
7815 struct breakpoint
*bpt
;
7817 ALL_BREAKPOINTS (bpt
)
7821 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7826 case bp_catch_unload
:
7828 case bp_catch_vfork
:
7830 case bp_hardware_breakpoint
:
7832 case bp_hardware_watchpoint
:
7833 case bp_read_watchpoint
:
7834 case bp_access_watchpoint
:
7835 disable_breakpoint (bpt
);
7839 else if (strchr (args
, '.'))
7841 struct bp_location
*loc
= find_location_by_number (args
);
7844 update_global_location_list ();
7847 map_breakpoint_numbers (args
, disable_breakpoint
);
7851 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7853 int target_resources_ok
, other_type_used
;
7856 if (bpt
->type
== bp_hardware_breakpoint
)
7859 i
= hw_breakpoint_used_count ();
7860 target_resources_ok
=
7861 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7863 if (target_resources_ok
== 0)
7864 error (_("No hardware breakpoint support in the target."));
7865 else if (target_resources_ok
< 0)
7866 error (_("Hardware breakpoints used exceeds limit."));
7869 if (bpt
->type
== bp_watchpoint
||
7870 bpt
->type
== bp_hardware_watchpoint
||
7871 bpt
->type
== bp_read_watchpoint
||
7872 bpt
->type
== bp_access_watchpoint
)
7874 struct frame_id saved_frame_id
;
7876 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7877 if (bpt
->exp_valid_block
!= NULL
)
7879 struct frame_info
*fr
=
7880 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7883 printf_filtered (_("\
7884 Cannot enable watchpoint %d because the block in which its expression\n\
7885 is valid is not currently in scope.\n"), bpt
->number
);
7892 value_free (bpt
->val
);
7893 mark
= value_mark ();
7894 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7896 release_value (bpt
->val
);
7899 if (bpt
->type
== bp_hardware_watchpoint
||
7900 bpt
->type
== bp_read_watchpoint
||
7901 bpt
->type
== bp_access_watchpoint
)
7903 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7904 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7906 /* Hack around 'unused var' error for some targets here */
7907 (void) mem_cnt
, (void) i
;
7908 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7909 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7910 /* we can consider of type is bp_hardware_watchpoint, convert to
7911 bp_watchpoint in the following condition */
7912 if (target_resources_ok
< 0)
7914 printf_filtered (_("\
7915 Cannot enable watchpoint %d because target watch resources\n\
7916 have been allocated for other watchpoints.\n"), bpt
->number
);
7917 value_free_to_mark (mark
);
7922 select_frame (frame_find_by_id (saved_frame_id
));
7923 value_free_to_mark (mark
);
7926 if (bpt
->enable_state
!= bp_permanent
)
7927 bpt
->enable_state
= bp_enabled
;
7928 bpt
->disposition
= disposition
;
7929 update_global_location_list ();
7930 breakpoints_changed ();
7932 if (deprecated_modify_breakpoint_hook
)
7933 deprecated_modify_breakpoint_hook (bpt
);
7934 breakpoint_modify_event (bpt
->number
);
7939 enable_breakpoint (struct breakpoint
*bpt
)
7941 do_enable_breakpoint (bpt
, bpt
->disposition
);
7944 /* The enable command enables the specified breakpoints (or all defined
7945 breakpoints) so they once again become (or continue to be) effective
7946 in stopping the inferior. */
7949 enable_command (char *args
, int from_tty
)
7951 struct breakpoint
*bpt
;
7953 ALL_BREAKPOINTS (bpt
)
7957 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7962 case bp_catch_unload
:
7964 case bp_catch_vfork
:
7966 case bp_hardware_breakpoint
:
7968 case bp_hardware_watchpoint
:
7969 case bp_read_watchpoint
:
7970 case bp_access_watchpoint
:
7971 enable_breakpoint (bpt
);
7975 else if (strchr (args
, '.'))
7977 struct bp_location
*loc
= find_location_by_number (args
);
7980 update_global_location_list ();
7983 map_breakpoint_numbers (args
, enable_breakpoint
);
7987 enable_once_breakpoint (struct breakpoint
*bpt
)
7989 do_enable_breakpoint (bpt
, disp_disable
);
7993 enable_once_command (char *args
, int from_tty
)
7995 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7999 enable_delete_breakpoint (struct breakpoint
*bpt
)
8001 do_enable_breakpoint (bpt
, disp_del
);
8005 enable_delete_command (char *args
, int from_tty
)
8007 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8011 set_breakpoint_cmd (char *args
, int from_tty
)
8016 show_breakpoint_cmd (char *args
, int from_tty
)
8020 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8022 struct symtabs_and_lines
8023 decode_line_spec_1 (char *string
, int funfirstline
)
8025 struct symtabs_and_lines sals
;
8027 error (_("Empty line specification."));
8028 if (default_breakpoint_valid
)
8029 sals
= decode_line_1 (&string
, funfirstline
,
8030 default_breakpoint_symtab
,
8031 default_breakpoint_line
,
8032 (char ***) NULL
, NULL
);
8034 sals
= decode_line_1 (&string
, funfirstline
,
8035 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8037 error (_("Junk at end of line specification: %s"), string
);
8041 /* Create and insert a raw software breakpoint at PC. Return an
8042 identifier, which should be used to remove the breakpoint later.
8043 In general, places which call this should be using something on the
8044 breakpoint chain instead; this function should be eliminated
8048 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8050 struct bp_target_info
*bp_tgt
;
8052 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8053 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8055 bp_tgt
->placed_address
= pc
;
8056 if (target_insert_breakpoint (bp_tgt
) != 0)
8058 /* Could not insert the breakpoint. */
8066 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8069 deprecated_remove_raw_breakpoint (void *bp
)
8071 struct bp_target_info
*bp_tgt
= bp
;
8074 ret
= target_remove_breakpoint (bp_tgt
);
8080 /* One (or perhaps two) breakpoints used for software single stepping. */
8082 static void *single_step_breakpoints
[2];
8084 /* Create and insert a breakpoint for software single step. */
8087 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8091 if (single_step_breakpoints
[0] == NULL
)
8092 bpt_p
= &single_step_breakpoints
[0];
8095 gdb_assert (single_step_breakpoints
[1] == NULL
);
8096 bpt_p
= &single_step_breakpoints
[1];
8099 /* NOTE drow/2006-04-11: A future improvement to this function would be
8100 to only create the breakpoints once, and actually put them on the
8101 breakpoint chain. That would let us use set_raw_breakpoint. We could
8102 adjust the addresses each time they were needed. Doing this requires
8103 corresponding changes elsewhere where single step breakpoints are
8104 handled, however. So, for now, we use this. */
8106 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8108 error (_("Could not insert single-step breakpoint at 0x%s"),
8109 paddr_nz (next_pc
));
8112 /* Remove and delete any breakpoints used for software single step. */
8115 remove_single_step_breakpoints (void)
8117 gdb_assert (single_step_breakpoints
[0] != NULL
);
8119 /* See insert_single_step_breakpoint for more about this deprecated
8121 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8122 single_step_breakpoints
[0] = NULL
;
8124 if (single_step_breakpoints
[1] != NULL
)
8126 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8127 single_step_breakpoints
[1] = NULL
;
8131 /* Check whether a software single-step breakpoint is inserted at PC. */
8134 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8138 for (i
= 0; i
< 2; i
++)
8140 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8141 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8148 int breakpoints_always_inserted_mode (void)
8150 return always_inserted_mode
;
8154 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8155 It is defined as a macro to prevent duplication.
8156 COMMAND should be a string constant containing the name of the command. */
8157 #define BREAK_ARGS_HELP(command) \
8158 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8159 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8160 If a line number is specified, break at start of code for that line.\n\
8161 If a function is specified, break at start of code for that function.\n\
8162 If an address is specified, break at that exact address.\n\
8163 With no LOCATION, uses current execution address of selected stack frame.\n\
8164 This is useful for breaking on return to a stack frame.\n\
8166 THREADNUM is the number from \"info threads\".\n\
8167 CONDITION is a boolean expression.\n\
8169 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8171 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8174 _initialize_breakpoint (void)
8176 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8177 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8178 struct cmd_list_element
*c
;
8180 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8182 breakpoint_chain
= 0;
8183 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8184 before a breakpoint is set. */
8185 breakpoint_count
= 0;
8187 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8188 Set ignore-count of breakpoint number N to COUNT.\n\
8189 Usage is `ignore N COUNT'."));
8191 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8193 add_com ("commands", class_breakpoint
, commands_command
, _("\
8194 Set commands to be executed when a breakpoint is hit.\n\
8195 Give breakpoint number as argument after \"commands\".\n\
8196 With no argument, the targeted breakpoint is the last one set.\n\
8197 The commands themselves follow starting on the next line.\n\
8198 Type a line containing \"end\" to indicate the end of them.\n\
8199 Give \"silent\" as the first line to make the breakpoint silent;\n\
8200 then no output is printed when it is hit, except what the commands print."));
8202 add_com ("condition", class_breakpoint
, condition_command
, _("\
8203 Specify breakpoint number N to break only if COND is true.\n\
8204 Usage is `condition N COND', where N is an integer and COND is an\n\
8205 expression to be evaluated whenever breakpoint N is reached."));
8207 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8208 Set a temporary breakpoint.\n\
8209 Like \"break\" except the breakpoint is only temporary,\n\
8210 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8211 by using \"enable delete\" on the breakpoint number.\n\
8213 BREAK_ARGS_HELP ("tbreak")));
8214 set_cmd_completer (c
, location_completer
);
8216 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8217 Set a hardware assisted breakpoint.\n\
8218 Like \"break\" except the breakpoint requires hardware support,\n\
8219 some target hardware may not have this support.\n\
8221 BREAK_ARGS_HELP ("hbreak")));
8222 set_cmd_completer (c
, location_completer
);
8224 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8225 Set a temporary hardware assisted breakpoint.\n\
8226 Like \"hbreak\" except the breakpoint is only temporary,\n\
8227 so it will be deleted when hit.\n\
8229 BREAK_ARGS_HELP ("thbreak")));
8230 set_cmd_completer (c
, location_completer
);
8232 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8233 Enable some breakpoints.\n\
8234 Give breakpoint numbers (separated by spaces) as arguments.\n\
8235 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8236 This is used to cancel the effect of the \"disable\" command.\n\
8237 With a subcommand you can enable temporarily."),
8238 &enablelist
, "enable ", 1, &cmdlist
);
8240 add_com ("ab", class_breakpoint
, enable_command
, _("\
8241 Enable some breakpoints.\n\
8242 Give breakpoint numbers (separated by spaces) as arguments.\n\
8243 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8244 This is used to cancel the effect of the \"disable\" command.\n\
8245 With a subcommand you can enable temporarily."));
8247 add_com_alias ("en", "enable", class_breakpoint
, 1);
8249 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8250 Enable some breakpoints.\n\
8251 Give breakpoint numbers (separated by spaces) as arguments.\n\
8252 This is used to cancel the effect of the \"disable\" command.\n\
8253 May be abbreviated to simply \"enable\".\n"),
8254 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8256 add_cmd ("once", no_class
, enable_once_command
, _("\
8257 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8258 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
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 ("delete", no_class
, enable_delete_command
, _("\
8267 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8268 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8271 add_cmd ("once", no_class
, enable_once_command
, _("\
8272 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8273 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8276 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8277 Disable some breakpoints.\n\
8278 Arguments are breakpoint numbers with spaces in between.\n\
8279 To disable all breakpoints, give no argument.\n\
8280 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8281 &disablelist
, "disable ", 1, &cmdlist
);
8282 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8283 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8285 add_com ("sb", class_breakpoint
, disable_command
, _("\
8286 Disable some breakpoints.\n\
8287 Arguments are breakpoint numbers with spaces in between.\n\
8288 To disable all breakpoints, give no argument.\n\
8289 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8291 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8292 Disable some breakpoints.\n\
8293 Arguments are breakpoint numbers with spaces in between.\n\
8294 To disable all breakpoints, give no argument.\n\
8295 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8296 This command may be abbreviated \"disable\"."),
8299 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8300 Delete some breakpoints or auto-display expressions.\n\
8301 Arguments are breakpoint numbers with spaces in between.\n\
8302 To delete all breakpoints, give no argument.\n\
8304 Also a prefix command for deletion of other GDB objects.\n\
8305 The \"unset\" command is also an alias for \"delete\"."),
8306 &deletelist
, "delete ", 1, &cmdlist
);
8307 add_com_alias ("d", "delete", class_breakpoint
, 1);
8308 add_com_alias ("del", "delete", class_breakpoint
, 1);
8310 add_com ("db", class_breakpoint
, delete_command
, _("\
8311 Delete some breakpoints.\n\
8312 Arguments are breakpoint numbers with spaces in between.\n\
8313 To delete all breakpoints, give no argument.\n"));
8315 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8316 Delete some breakpoints or auto-display expressions.\n\
8317 Arguments are breakpoint numbers with spaces in between.\n\
8318 To delete all breakpoints, give no argument.\n\
8319 This command may be abbreviated \"delete\"."),
8322 add_com ("clear", class_breakpoint
, clear_command
, _("\
8323 Clear breakpoint at specified line or function.\n\
8324 Argument may be line number, function name, or \"*\" and an address.\n\
8325 If line number is specified, all breakpoints in that line are cleared.\n\
8326 If function is specified, breakpoints at beginning of function are cleared.\n\
8327 If an address is specified, breakpoints at that address are cleared.\n\
8329 With no argument, clears all breakpoints in the line that the selected frame\n\
8332 See also the \"delete\" command which clears breakpoints by number."));
8334 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8335 Set breakpoint at specified line or function.\n"
8336 BREAK_ARGS_HELP ("break")));
8337 set_cmd_completer (c
, location_completer
);
8339 add_com_alias ("b", "break", class_run
, 1);
8340 add_com_alias ("br", "break", class_run
, 1);
8341 add_com_alias ("bre", "break", class_run
, 1);
8342 add_com_alias ("brea", "break", class_run
, 1);
8346 add_com_alias ("ba", "break", class_breakpoint
, 1);
8347 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8352 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8353 Break in function/address or break at a line in the current file."),
8354 &stoplist
, "stop ", 1, &cmdlist
);
8355 add_cmd ("in", class_breakpoint
, stopin_command
,
8356 _("Break in function or address."), &stoplist
);
8357 add_cmd ("at", class_breakpoint
, stopat_command
,
8358 _("Break at a line in the current file."), &stoplist
);
8359 add_com ("status", class_info
, breakpoints_info
, _("\
8360 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8361 The \"Type\" column indicates one of:\n\
8362 \tbreakpoint - normal breakpoint\n\
8363 \twatchpoint - watchpoint\n\
8364 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8365 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8366 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8367 address and file/line number respectively.\n\
8369 Convenience variable \"$_\" and default examine address for \"x\"\n\
8370 are set to the address of the last breakpoint listed unless the command\n\
8371 is prefixed with \"server \".\n\n\
8372 Convenience variable \"$bpnum\" contains the number of the last\n\
8376 add_info ("breakpoints", breakpoints_info
, _("\
8377 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8378 The \"Type\" column indicates one of:\n\
8379 \tbreakpoint - normal breakpoint\n\
8380 \twatchpoint - watchpoint\n\
8381 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8382 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8383 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8384 address and file/line number respectively.\n\
8386 Convenience variable \"$_\" and default examine address for \"x\"\n\
8387 are set to the address of the last breakpoint listed unless the command\n\
8388 is prefixed with \"server \".\n\n\
8389 Convenience variable \"$bpnum\" contains the number of the last\n\
8393 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8394 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8395 The \"Type\" column indicates one of:\n\
8396 \tbreakpoint - normal breakpoint\n\
8397 \twatchpoint - watchpoint\n\
8398 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8399 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8400 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8401 address and file/line number respectively.\n\
8403 Convenience variable \"$_\" and default examine address for \"x\"\n\
8404 are set to the address of the last breakpoint listed unless the command\n\
8405 is prefixed with \"server \".\n\n\
8406 Convenience variable \"$bpnum\" contains the number of the last\n\
8409 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8410 Status of all breakpoints, or breakpoint number NUMBER.\n\
8411 The \"Type\" column indicates one of:\n\
8412 \tbreakpoint - normal breakpoint\n\
8413 \twatchpoint - watchpoint\n\
8414 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8415 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8416 \tuntil - internal breakpoint used by the \"until\" command\n\
8417 \tfinish - internal breakpoint used by the \"finish\" command\n\
8418 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8419 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8420 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8421 address and file/line number respectively.\n\
8423 Convenience variable \"$_\" and default examine address for \"x\"\n\
8424 are set to the address of the last breakpoint listed unless the command\n\
8425 is prefixed with \"server \".\n\n\
8426 Convenience variable \"$bpnum\" contains the number of the last\n\
8428 &maintenanceinfolist
);
8430 add_com ("catch", class_breakpoint
, catch_command
, _("\
8431 Set catchpoints to catch events.\n\
8432 Raised signals may be caught:\n\
8433 \tcatch signal - all signals\n\
8434 \tcatch signal <signame> - a particular signal\n\
8435 Raised exceptions may be caught:\n\
8436 \tcatch throw - all exceptions, when thrown\n\
8437 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8438 \tcatch catch - all exceptions, when caught\n\
8439 \tcatch catch <exceptname> - a particular exception, when caught\n\
8440 Thread or process events may be caught:\n\
8441 \tcatch thread_start - any threads, just after creation\n\
8442 \tcatch thread_exit - any threads, just before expiration\n\
8443 \tcatch thread_join - any threads, just after joins\n\
8444 Process events may be caught:\n\
8445 \tcatch start - any processes, just after creation\n\
8446 \tcatch exit - any processes, just before expiration\n\
8447 \tcatch fork - calls to fork()\n\
8448 \tcatch vfork - calls to vfork()\n\
8449 \tcatch exec - calls to exec()\n\
8450 Dynamically-linked library events may be caught:\n\
8451 \tcatch load - loads of any library\n\
8452 \tcatch load <libname> - loads of a particular library\n\
8453 \tcatch unload - unloads of any library\n\
8454 \tcatch unload <libname> - unloads of a particular library\n\
8455 The act of your program's execution stopping may also be caught:\n\
8457 C++ exceptions may be caught:\n\
8458 \tcatch throw - all exceptions, when thrown\n\
8459 \tcatch catch - all exceptions, when caught\n\
8460 Ada exceptions may be caught:\n\
8461 \tcatch exception - all exceptions, when raised\n\
8462 \tcatch exception <name> - a particular exception, when raised\n\
8463 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8464 \tcatch assert - all failed assertions, when raised\n\
8466 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8467 after a fork or vfork is caught.\n\n\
8468 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8470 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8471 Set temporary catchpoints to catch events.\n\
8472 Args like \"catch\" command.\n\
8473 Like \"catch\" except the catchpoint is only temporary,\n\
8474 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8475 by using \"enable delete\" on the catchpoint number."));
8477 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8478 Set a watchpoint for an expression.\n\
8479 A watchpoint stops execution of your program whenever the value of\n\
8480 an expression changes."));
8481 set_cmd_completer (c
, location_completer
);
8483 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8484 Set a read watchpoint for an expression.\n\
8485 A watchpoint stops execution of your program whenever the value of\n\
8486 an expression is read."));
8487 set_cmd_completer (c
, location_completer
);
8489 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8490 Set a watchpoint for an expression.\n\
8491 A watchpoint stops execution of your program whenever the value of\n\
8492 an expression is either read or written."));
8493 set_cmd_completer (c
, location_completer
);
8495 add_info ("watchpoints", breakpoints_info
,
8496 _("Synonym for ``info breakpoints''."));
8499 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8500 respond to changes - contrary to the description. */
8501 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8502 &can_use_hw_watchpoints
, _("\
8503 Set debugger's willingness to use watchpoint hardware."), _("\
8504 Show debugger's willingness to use watchpoint hardware."), _("\
8505 If zero, gdb will not use hardware for new watchpoints, even if\n\
8506 such is available. (However, any hardware watchpoints that were\n\
8507 created before setting this to nonzero, will continue to use watchpoint\n\
8510 show_can_use_hw_watchpoints
,
8511 &setlist
, &showlist
);
8513 can_use_hw_watchpoints
= 1;
8515 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8516 Breakpoint specific settings\n\
8517 Configure various breakpoint-specific variables such as\n\
8518 pending breakpoint behavior"),
8519 &breakpoint_set_cmdlist
, "set breakpoint ",
8520 0/*allow-unknown*/, &setlist
);
8521 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8522 Breakpoint specific settings\n\
8523 Configure various breakpoint-specific variables such as\n\
8524 pending breakpoint behavior"),
8525 &breakpoint_show_cmdlist
, "show breakpoint ",
8526 0/*allow-unknown*/, &showlist
);
8528 add_setshow_auto_boolean_cmd ("pending", no_class
,
8529 &pending_break_support
, _("\
8530 Set debugger's behavior regarding pending breakpoints."), _("\
8531 Show debugger's behavior regarding pending breakpoints."), _("\
8532 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8533 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8534 an error. If auto, an unrecognized breakpoint location results in a\n\
8535 user-query to see if a pending breakpoint should be created."),
8537 show_pending_break_support
,
8538 &breakpoint_set_cmdlist
,
8539 &breakpoint_show_cmdlist
);
8541 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8543 add_setshow_boolean_cmd ("auto-hw", no_class
,
8544 &automatic_hardware_breakpoints
, _("\
8545 Set automatic usage of hardware breakpoints."), _("\
8546 Show automatic usage of hardware breakpoints."), _("\
8547 If set, the debugger will automatically use hardware breakpoints for\n\
8548 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8549 a warning will be emitted for such breakpoints."),
8551 show_automatic_hardware_breakpoints
,
8552 &breakpoint_set_cmdlist
,
8553 &breakpoint_show_cmdlist
);
8555 add_setshow_boolean_cmd ("always-inserted", class_support
,
8556 &always_inserted_mode
, _("\
8557 Set mode for inserting breakpoints."), _("\
8558 Show mode for inserting breakpoints."), _("\
8559 When this mode is off (which is the default), breakpoints are inserted in\n\
8560 inferior when it is resumed, and removed when execution stops. When this\n\
8561 mode is on, breakpoints are inserted immediately and removed only when\n\
8562 the user deletes the breakpoint."),
8564 &show_always_inserted_mode
,
8565 &breakpoint_set_cmdlist
,
8566 &breakpoint_show_cmdlist
);
8568 automatic_hardware_breakpoints
= 1;