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
)
633 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
635 error (_("Junk at end of expression"));
638 breakpoints_changed ();
639 breakpoint_modify_event (b
->number
);
643 error (_("No breakpoint number %d."), bnum
);
647 commands_command (char *arg
, int from_tty
)
649 struct breakpoint
*b
;
652 struct command_line
*l
;
654 /* If we allowed this, we would have problems with when to
655 free the storage, if we change the commands currently
658 if (executing_breakpoint_commands
)
659 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
662 bnum
= get_number (&p
);
665 error (_("Unexpected extra arguments following breakpoint number."));
668 if (b
->number
== bnum
)
670 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
672 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
673 l
= read_command_lines (tmpbuf
, from_tty
);
674 do_cleanups (cleanups
);
675 free_command_lines (&b
->commands
);
677 breakpoints_changed ();
678 breakpoint_modify_event (b
->number
);
681 error (_("No breakpoint number %d."), bnum
);
684 /* Like commands_command, but instead of reading the commands from
685 input stream, takes them from an already parsed command structure.
687 This is used by cli-script.c to DTRT with breakpoint commands
688 that are part of if and while bodies. */
689 enum command_control_type
690 commands_from_control_command (char *arg
, struct command_line
*cmd
)
692 struct breakpoint
*b
;
696 /* If we allowed this, we would have problems with when to
697 free the storage, if we change the commands currently
700 if (executing_breakpoint_commands
)
701 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
703 /* An empty string for the breakpoint number means the last
704 breakpoint, but get_number expects a NULL pointer. */
709 bnum
= get_number (&p
);
712 error (_("Unexpected extra arguments following breakpoint number."));
715 if (b
->number
== bnum
)
717 free_command_lines (&b
->commands
);
718 if (cmd
->body_count
!= 1)
719 error (_("Invalid \"commands\" block structure."));
720 /* We need to copy the commands because if/while will free the
721 list after it finishes execution. */
722 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
723 breakpoints_changed ();
724 breakpoint_modify_event (b
->number
);
725 return simple_control
;
727 error (_("No breakpoint number %d."), bnum
);
730 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
731 by replacing any memory breakpoints with their shadowed contents. */
734 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
736 struct bp_location
*b
;
737 CORE_ADDR bp_addr
= 0;
743 if (b
->owner
->type
== bp_none
)
744 warning (_("reading through apparently deleted breakpoint #%d?"),
747 if (b
->loc_type
!= bp_loc_software_breakpoint
)
751 /* Addresses and length of the part of the breakpoint that
753 bp_addr
= b
->target_info
.placed_address
;
754 bp_size
= b
->target_info
.shadow_len
;
756 /* bp isn't valid, or doesn't shadow memory. */
759 if (bp_addr
+ bp_size
<= memaddr
)
760 /* The breakpoint is entirely before the chunk of memory we
764 if (bp_addr
>= memaddr
+ len
)
765 /* The breakpoint is entirely after the chunk of memory we are
769 /* Offset within shadow_contents. */
770 if (bp_addr
< memaddr
)
772 /* Only copy the second part of the breakpoint. */
773 bp_size
-= memaddr
- bp_addr
;
774 bptoffset
= memaddr
- bp_addr
;
778 if (bp_addr
+ bp_size
> memaddr
+ len
)
780 /* Only copy the first part of the breakpoint. */
781 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
784 memcpy (buf
+ bp_addr
- memaddr
,
785 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
790 /* A wrapper function for inserting catchpoints. */
792 insert_catchpoint (struct ui_out
*uo
, void *args
)
794 struct breakpoint
*b
= (struct breakpoint
*) args
;
800 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
803 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
806 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
809 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
815 is_hardware_watchpoint (struct breakpoint
*bpt
)
817 return (bpt
->type
== bp_hardware_watchpoint
818 || bpt
->type
== bp_read_watchpoint
819 || bpt
->type
== bp_access_watchpoint
);
822 /* Find the current value of a watchpoint on EXP. Return the value in
823 *VALP and *RESULTP and the chain of intermediate and final values
824 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
827 If an error occurs while evaluating the expression, *RESULTP will
828 be set to NULL. *RESULTP may be a lazy value, if the result could
829 not be read from memory. It is used to determine whether a value
830 is user-specified (we should watch the whole value) or intermediate
831 (we should watch only the bit used to locate the final value).
833 If the final value, or any intermediate value, could not be read
834 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
835 set to any referenced values. *VALP will never be a lazy value.
836 This is the value which we store in struct breakpoint.
838 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
839 value chain. The caller must free the values individually. If
840 VAL_CHAIN is NULL, all generated values will be left on the value
844 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
845 struct value
**resultp
, struct value
**val_chain
)
847 struct value
*mark
, *new_mark
, *result
;
855 /* Evaluate the expression. */
856 mark
= value_mark ();
858 gdb_evaluate_expression (exp
, &result
);
859 new_mark
= value_mark ();
860 if (mark
== new_mark
)
865 /* Make sure it's not lazy, so that after the target stops again we
866 have a non-lazy previous value to compare with. */
868 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
873 /* Return the chain of intermediate values. We use this to
874 decide which addresses to watch. */
875 *val_chain
= new_mark
;
876 value_release_to_mark (mark
);
880 /* Assuming that B is a hardware watchpoint:
881 - Reparse watchpoint expression, is REPARSE is non-zero
882 - Evaluate expression and store the result in B->val
883 - Update the list of values that must be watched in B->loc.
885 If the watchpoint is disabled, do nothing. If this is
886 local watchpoint that is out of scope, delete it. */
888 update_watchpoint (struct breakpoint
*b
, int reparse
)
890 int within_current_scope
;
891 struct frame_id saved_frame_id
;
892 struct bp_location
*loc
;
895 /* We don't free locations. They are stored in
896 bp_location_chain and update_global_locations will
897 eventually delete them and remove breakpoints if
901 if (b
->disposition
== disp_del_at_next_stop
)
904 /* Save the current frame's ID so we can restore it after
905 evaluating the watchpoint expression on its own frame. */
906 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
907 took a frame parameter, so that we didn't have to change the
909 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
911 /* Determine if the watchpoint is within scope. */
912 if (b
->exp_valid_block
== NULL
)
913 within_current_scope
= 1;
916 struct frame_info
*fi
;
917 fi
= frame_find_by_id (b
->watchpoint_frame
);
918 within_current_scope
= (fi
!= NULL
);
919 if (within_current_scope
)
923 if (within_current_scope
&& reparse
)
932 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
933 /* If the meaning of expression itself changed, the old value is
934 no longer relevant. We don't want to report a watchpoint hit
935 to the user when the old value and the new value may actually
936 be completely different objects. */
942 /* If we failed to parse the expression, for example because
943 it refers to a global variable in a not-yet-loaded shared library,
944 don't try to insert watchpoint. We don't automatically delete
945 such watchpoint, though, since failure to parse expression
946 is different from out-of-scope watchpoint. */
947 if (within_current_scope
&& b
->exp
)
949 struct value
*val_chain
, *v
, *result
, *next
;
951 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
953 /* Avoid setting b->val if it's already set. The meaning of
954 b->val is 'the last value' user saw, and we should update
955 it only if we reported that last value to user. As it
956 happens, the code that reports it updates b->val directly. */
963 /* Look at each value on the value chain. */
964 for (v
= val_chain
; v
; v
= next
)
966 /* If it's a memory location, and GDB actually needed
967 its contents to evaluate the expression, then we
968 must watch it. If the first value returned is
969 still lazy, that means an error occurred reading it;
970 watch it anyway in case it becomes readable. */
971 if (VALUE_LVAL (v
) == lval_memory
972 && (v
== val_chain
|| ! value_lazy (v
)))
974 struct type
*vtype
= check_typedef (value_type (v
));
976 /* We only watch structs and arrays if user asked
977 for it explicitly, never if they just happen to
978 appear in the middle of some value chain. */
980 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
981 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
985 struct bp_location
*loc
, **tmp
;
987 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
988 len
= TYPE_LENGTH (value_type (v
));
990 if (b
->type
== bp_read_watchpoint
)
992 else if (b
->type
== bp_access_watchpoint
)
995 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
996 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1001 loc
->watchpoint_type
= type
;
1005 next
= value_next (v
);
1010 /* We just regenerated the list of breakpoint locations.
1011 The new location does not have its condition field set to anything
1012 and therefore, we must always reparse the cond_string, independently
1013 of the value of the reparse flag. */
1014 if (b
->cond_string
!= NULL
)
1016 char *s
= b
->cond_string
;
1017 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1020 else if (!within_current_scope
)
1022 printf_filtered (_("\
1023 Hardware watchpoint %d deleted because the program has left the block \n\
1024 in which its expression is valid.\n"),
1026 if (b
->related_breakpoint
)
1027 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1028 b
->disposition
= disp_del_at_next_stop
;
1031 /* Restore the selected frame. */
1032 select_frame (frame_find_by_id (saved_frame_id
));
1036 /* Returns 1 iff breakpoint location should be
1037 inserted in the inferior. */
1039 should_be_inserted (struct bp_location
*bpt
)
1041 if (!breakpoint_enabled (bpt
->owner
))
1044 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1047 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1053 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1054 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1055 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1057 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1058 method for each breakpoint or catchpoint type. */
1060 insert_bp_location (struct bp_location
*bpt
,
1061 struct ui_file
*tmp_error_stream
,
1062 int *disabled_breaks
, int *process_warning
,
1063 int *hw_breakpoint_error
)
1067 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1070 /* Initialize the target-specific information. */
1071 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1072 bpt
->target_info
.placed_address
= bpt
->address
;
1074 if (bpt
->loc_type
== bp_loc_software_breakpoint
1075 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1077 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1079 /* If the explicitly specified breakpoint type
1080 is not hardware breakpoint, check the memory map to see
1081 if the breakpoint address is in read only memory or not.
1082 Two important cases are:
1083 - location type is not hardware breakpoint, memory
1084 is readonly. We change the type of the location to
1085 hardware breakpoint.
1086 - location type is hardware breakpoint, memory is read-write.
1087 This means we've previously made the location hardware one, but
1088 then the memory map changed, so we undo.
1090 When breakpoints are removed, remove_breakpoints will
1091 use location types we've just set here, the only possible
1092 problem is that memory map has changed during running program,
1093 but it's not going to work anyway with current gdb. */
1094 struct mem_region
*mr
1095 = lookup_mem_region (bpt
->target_info
.placed_address
);
1099 if (automatic_hardware_breakpoints
)
1102 enum bp_loc_type new_type
;
1104 if (mr
->attrib
.mode
!= MEM_RW
)
1105 new_type
= bp_loc_hardware_breakpoint
;
1107 new_type
= bp_loc_software_breakpoint
;
1109 if (new_type
!= bpt
->loc_type
)
1111 static int said
= 0;
1112 bpt
->loc_type
= new_type
;
1115 fprintf_filtered (gdb_stdout
, _("\
1116 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1121 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1122 && mr
->attrib
.mode
!= MEM_RW
)
1123 warning (_("cannot set software breakpoint at readonly address %s"),
1124 paddr (bpt
->address
));
1128 /* First check to see if we have to handle an overlay. */
1129 if (overlay_debugging
== ovly_off
1130 || bpt
->section
== NULL
1131 || !(section_is_overlay (bpt
->section
)))
1133 /* No overlay handling: just set the breakpoint. */
1135 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1136 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1138 val
= target_insert_breakpoint (&bpt
->target_info
);
1142 /* This breakpoint is in an overlay section.
1143 Shall we set a breakpoint at the LMA? */
1144 if (!overlay_events_enabled
)
1146 /* Yes -- overlay event support is not active,
1147 so we must try to set a breakpoint at the LMA.
1148 This will not work for a hardware breakpoint. */
1149 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1150 warning (_("hardware breakpoint %d not supported in overlay!"),
1151 bpt
->owner
->number
);
1154 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1156 /* Set a software (trap) breakpoint at the LMA. */
1157 bpt
->overlay_target_info
= bpt
->target_info
;
1158 bpt
->overlay_target_info
.placed_address
= addr
;
1159 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1161 fprintf_unfiltered (tmp_error_stream
,
1162 "Overlay breakpoint %d failed: in ROM?",
1163 bpt
->owner
->number
);
1166 /* Shall we set a breakpoint at the VMA? */
1167 if (section_is_mapped (bpt
->section
))
1169 /* Yes. This overlay section is mapped into memory. */
1170 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1171 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1173 val
= target_insert_breakpoint (&bpt
->target_info
);
1177 /* No. This breakpoint will not be inserted.
1178 No error, but do not mark the bp as 'inserted'. */
1185 /* Can't set the breakpoint. */
1186 if (solib_address (bpt
->address
))
1188 /* See also: disable_breakpoints_in_shlibs. */
1190 bpt
->shlib_disabled
= 1;
1191 if (!*disabled_breaks
)
1193 fprintf_unfiltered (tmp_error_stream
,
1194 "Cannot insert breakpoint %d.\n",
1195 bpt
->owner
->number
);
1196 fprintf_unfiltered (tmp_error_stream
,
1197 "Temporarily disabling shared library breakpoints:\n");
1199 *disabled_breaks
= 1;
1200 fprintf_unfiltered (tmp_error_stream
,
1201 "breakpoint #%d\n", bpt
->owner
->number
);
1205 #ifdef ONE_PROCESS_WRITETEXT
1206 *process_warning
= 1;
1208 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1210 *hw_breakpoint_error
= 1;
1211 fprintf_unfiltered (tmp_error_stream
,
1212 "Cannot insert hardware breakpoint %d.\n",
1213 bpt
->owner
->number
);
1217 fprintf_unfiltered (tmp_error_stream
,
1218 "Cannot insert breakpoint %d.\n",
1219 bpt
->owner
->number
);
1220 fprintf_filtered (tmp_error_stream
,
1221 "Error accessing memory address ");
1222 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1223 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1224 safe_strerror (val
));
1235 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1236 /* NOTE drow/2003-09-08: This state only exists for removing
1237 watchpoints. It's not clear that it's necessary... */
1238 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1240 val
= target_insert_watchpoint (bpt
->address
,
1242 bpt
->watchpoint_type
);
1243 bpt
->inserted
= (val
!= -1);
1246 else if (bpt
->owner
->type
== bp_catch_fork
1247 || bpt
->owner
->type
== bp_catch_vfork
1248 || bpt
->owner
->type
== bp_catch_exec
)
1250 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1251 bpt
->owner
, RETURN_MASK_ERROR
);
1252 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1253 bpt
->owner
->number
);
1255 bpt
->owner
->enable_state
= bp_disabled
;
1259 /* We've already printed an error message if there was a problem
1260 inserting this catchpoint, and we've disabled the catchpoint,
1261 so just return success. */
1268 /* Make sure all breakpoints are inserted in inferior.
1269 Throws exception on any error.
1270 A breakpoint that is already inserted won't be inserted
1271 again, so calling this function twice is safe. */
1273 insert_breakpoints (void)
1275 struct breakpoint
*bpt
;
1277 ALL_BREAKPOINTS (bpt
)
1278 if (is_hardware_watchpoint (bpt
))
1279 update_watchpoint (bpt
, 0 /* don't reparse. */);
1281 update_global_location_list ();
1283 if (!always_inserted_mode
&& target_has_execution
)
1284 /* update_global_location_list does not insert breakpoints
1285 when always_inserted_mode is not enabled. Explicitly
1287 insert_breakpoint_locations ();
1290 /* insert_breakpoints is used when starting or continuing the program.
1291 remove_breakpoints is used when the program stops.
1292 Both return zero if successful,
1293 or an `errno' value if could not write the inferior. */
1296 insert_breakpoint_locations (void)
1298 struct breakpoint
*bpt
;
1299 struct bp_location
*b
, *temp
;
1302 int disabled_breaks
= 0;
1303 int hw_breakpoint_error
= 0;
1304 int process_warning
= 0;
1306 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1307 make_cleanup_ui_file_delete (tmp_error_stream
);
1309 /* Explicitly mark the warning -- this will only be printed if
1310 there was an error. */
1311 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1313 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1315 if (!should_be_inserted (b
) || b
->inserted
)
1318 /* There is no point inserting thread-specific breakpoints if the
1319 thread no longer exists. */
1320 if (b
->owner
->thread
!= -1
1321 && !valid_thread_id (b
->owner
->thread
))
1324 val
= insert_bp_location (b
, tmp_error_stream
,
1325 &disabled_breaks
, &process_warning
,
1326 &hw_breakpoint_error
);
1331 /* If we failed to insert all locations of a watchpoint,
1332 remove them, as half-inserted watchpoint is of limited use. */
1333 ALL_BREAKPOINTS (bpt
)
1335 int some_failed
= 0;
1336 struct bp_location
*loc
;
1338 if (!is_hardware_watchpoint (bpt
))
1341 if (bpt
->enable_state
!= bp_enabled
)
1344 if (bpt
->disposition
== disp_del_at_next_stop
)
1347 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1355 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1357 remove_breakpoint (loc
, mark_uninserted
);
1359 hw_breakpoint_error
= 1;
1360 fprintf_unfiltered (tmp_error_stream
,
1361 "Could not insert hardware watchpoint %d.\n",
1369 /* If a hardware breakpoint or watchpoint was inserted, add a
1370 message about possibly exhausted resources. */
1371 if (hw_breakpoint_error
)
1373 fprintf_unfiltered (tmp_error_stream
,
1374 "Could not insert hardware breakpoints:\n\
1375 You may have requested too many hardware breakpoints/watchpoints.\n");
1377 #ifdef ONE_PROCESS_WRITETEXT
1378 if (process_warning
)
1379 fprintf_unfiltered (tmp_error_stream
,
1380 "The same program may be running in another process.");
1382 target_terminal_ours_for_output ();
1383 error_stream (tmp_error_stream
);
1388 remove_breakpoints (void)
1390 struct bp_location
*b
;
1393 ALL_BP_LOCATIONS (b
)
1397 val
= remove_breakpoint (b
, mark_uninserted
);
1406 remove_hw_watchpoints (void)
1408 struct bp_location
*b
;
1411 ALL_BP_LOCATIONS (b
)
1413 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1415 val
= remove_breakpoint (b
, mark_uninserted
);
1424 reattach_breakpoints (int pid
)
1426 struct bp_location
*b
;
1428 struct cleanup
*old_chain
= save_inferior_ptid ();
1429 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1430 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1432 make_cleanup_ui_file_delete (tmp_error_stream
);
1434 inferior_ptid
= pid_to_ptid (pid
);
1435 ALL_BP_LOCATIONS (b
)
1440 val
= insert_bp_location (b
, tmp_error_stream
,
1441 &dummy1
, &dummy2
, &dummy3
);
1444 do_cleanups (old_chain
);
1449 do_cleanups (old_chain
);
1454 restore_always_inserted_mode (void *p
)
1456 always_inserted_mode
= (uintptr_t) p
;
1460 update_breakpoints_after_exec (void)
1462 struct breakpoint
*b
;
1463 struct breakpoint
*temp
;
1464 struct cleanup
*cleanup
;
1466 /* Doing this first prevents the badness of having delete_breakpoint()
1467 write a breakpoint's current "shadow contents" to lift the bp. That
1468 shadow is NOT valid after an exec()! */
1469 mark_breakpoints_out ();
1471 /* The binary we used to debug is now gone, and we're updating
1472 breakpoints for the new binary. Until we're done, we should not
1473 try to insert breakpoints. */
1474 cleanup
= make_cleanup (restore_always_inserted_mode
,
1475 (void *) (uintptr_t) always_inserted_mode
);
1476 always_inserted_mode
= 0;
1478 ALL_BREAKPOINTS_SAFE (b
, temp
)
1480 /* Solib breakpoints must be explicitly reset after an exec(). */
1481 if (b
->type
== bp_shlib_event
)
1483 delete_breakpoint (b
);
1487 /* Thread event breakpoints must be set anew after an exec(),
1488 as must overlay event breakpoints. */
1489 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1491 delete_breakpoint (b
);
1495 /* Step-resume breakpoints are meaningless after an exec(). */
1496 if (b
->type
== bp_step_resume
)
1498 delete_breakpoint (b
);
1502 /* Don't delete an exec catchpoint, because else the inferior
1503 won't stop when it ought!
1505 Similarly, we probably ought to keep vfork catchpoints, 'cause
1506 on this target, we may not be able to stop when the vfork is
1507 seen, but only when the subsequent exec is seen. (And because
1508 deleting fork catchpoints here but not vfork catchpoints will
1509 seem mysterious to users, keep those too.) */
1510 if ((b
->type
== bp_catch_exec
) ||
1511 (b
->type
== bp_catch_vfork
) ||
1512 (b
->type
== bp_catch_fork
))
1517 /* bp_finish is a special case. The only way we ought to be able
1518 to see one of these when an exec() has happened, is if the user
1519 caught a vfork, and then said "finish". Ordinarily a finish just
1520 carries them to the call-site of the current callee, by setting
1521 a temporary bp there and resuming. But in this case, the finish
1522 will carry them entirely through the vfork & exec.
1524 We don't want to allow a bp_finish to remain inserted now. But
1525 we can't safely delete it, 'cause finish_command has a handle to
1526 the bp on a bpstat, and will later want to delete it. There's a
1527 chance (and I've seen it happen) that if we delete the bp_finish
1528 here, that its storage will get reused by the time finish_command
1529 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1530 We really must allow finish_command to delete a bp_finish.
1532 In the absense of a general solution for the "how do we know
1533 it's safe to delete something others may have handles to?"
1534 problem, what we'll do here is just uninsert the bp_finish, and
1535 let finish_command delete it.
1537 (We know the bp_finish is "doomed" in the sense that it's
1538 momentary, and will be deleted as soon as finish_command sees
1539 the inferior stopped. So it doesn't matter that the bp's
1540 address is probably bogus in the new a.out, unlike e.g., the
1541 solib breakpoints.) */
1543 if (b
->type
== bp_finish
)
1548 /* Without a symbolic address, we have little hope of the
1549 pre-exec() address meaning the same thing in the post-exec()
1551 if (b
->addr_string
== NULL
)
1553 delete_breakpoint (b
);
1557 /* FIXME what about longjmp breakpoints? Re-create them here? */
1558 create_overlay_event_breakpoint ("_ovly_debug_event");
1559 do_cleanups (cleanup
);
1563 detach_breakpoints (int pid
)
1565 struct bp_location
*b
;
1567 struct cleanup
*old_chain
= save_inferior_ptid ();
1569 if (pid
== PIDGET (inferior_ptid
))
1570 error (_("Cannot detach breakpoints of inferior_ptid"));
1572 /* Set inferior_ptid; remove_breakpoint uses this global. */
1573 inferior_ptid
= pid_to_ptid (pid
);
1574 ALL_BP_LOCATIONS (b
)
1578 val
= remove_breakpoint (b
, mark_inserted
);
1581 do_cleanups (old_chain
);
1586 do_cleanups (old_chain
);
1591 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1595 if (b
->owner
->enable_state
== bp_permanent
)
1596 /* Permanent breakpoints cannot be inserted or removed. */
1599 /* The type of none suggests that owner is actually deleted.
1600 This should not ever happen. */
1601 gdb_assert (b
->owner
->type
!= bp_none
);
1603 if (b
->loc_type
== bp_loc_software_breakpoint
1604 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1606 /* "Normal" instruction breakpoint: either the standard
1607 trap-instruction bp (bp_breakpoint), or a
1608 bp_hardware_breakpoint. */
1610 /* First check to see if we have to handle an overlay. */
1611 if (overlay_debugging
== ovly_off
1612 || b
->section
== NULL
1613 || !(section_is_overlay (b
->section
)))
1615 /* No overlay handling: just remove the breakpoint. */
1617 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1618 val
= target_remove_hw_breakpoint (&b
->target_info
);
1620 val
= target_remove_breakpoint (&b
->target_info
);
1624 /* This breakpoint is in an overlay section.
1625 Did we set a breakpoint at the LMA? */
1626 if (!overlay_events_enabled
)
1628 /* Yes -- overlay event support is not active, so we
1629 should have set a breakpoint at the LMA. Remove it.
1631 /* Ignore any failures: if the LMA is in ROM, we will
1632 have already warned when we failed to insert it. */
1633 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1634 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1636 target_remove_breakpoint (&b
->overlay_target_info
);
1638 /* Did we set a breakpoint at the VMA?
1639 If so, we will have marked the breakpoint 'inserted'. */
1642 /* Yes -- remove it. Previously we did not bother to
1643 remove the breakpoint if the section had been
1644 unmapped, but let's not rely on that being safe. We
1645 don't know what the overlay manager might do. */
1646 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1647 val
= target_remove_hw_breakpoint (&b
->target_info
);
1649 /* However, we should remove *software* breakpoints only
1650 if the section is still mapped, or else we overwrite
1651 wrong code with the saved shadow contents. */
1652 else if (section_is_mapped (b
->section
))
1653 val
= target_remove_breakpoint (&b
->target_info
);
1659 /* No -- not inserted, so no need to remove. No error. */
1665 b
->inserted
= (is
== mark_inserted
);
1667 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1672 b
->inserted
= (is
== mark_inserted
);
1673 val
= target_remove_watchpoint (b
->address
, b
->length
,
1674 b
->watchpoint_type
);
1676 /* Failure to remove any of the hardware watchpoints comes here. */
1677 if ((is
== mark_uninserted
) && (b
->inserted
))
1678 warning (_("Could not remove hardware watchpoint %d."),
1681 else if ((b
->owner
->type
== bp_catch_fork
||
1682 b
->owner
->type
== bp_catch_vfork
||
1683 b
->owner
->type
== bp_catch_exec
)
1684 && breakpoint_enabled (b
->owner
)
1688 switch (b
->owner
->type
)
1691 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1693 case bp_catch_vfork
:
1694 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1697 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1700 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1705 b
->inserted
= (is
== mark_inserted
);
1711 /* Clear the "inserted" flag in all breakpoints. */
1714 mark_breakpoints_out (void)
1716 struct bp_location
*bpt
;
1718 ALL_BP_LOCATIONS (bpt
)
1722 /* Clear the "inserted" flag in all breakpoints and delete any
1723 breakpoints which should go away between runs of the program.
1725 Plus other such housekeeping that has to be done for breakpoints
1728 Note: this function gets called at the end of a run (by
1729 generic_mourn_inferior) and when a run begins (by
1730 init_wait_for_inferior). */
1735 breakpoint_init_inferior (enum inf_context context
)
1737 struct breakpoint
*b
, *temp
;
1738 struct bp_location
*bpt
;
1740 ALL_BP_LOCATIONS (bpt
)
1743 ALL_BREAKPOINTS_SAFE (b
, temp
)
1748 case bp_watchpoint_scope
:
1750 /* If the call dummy breakpoint is at the entry point it will
1751 cause problems when the inferior is rerun, so we better
1754 Also get rid of scope breakpoints. */
1755 delete_breakpoint (b
);
1759 case bp_hardware_watchpoint
:
1760 case bp_read_watchpoint
:
1761 case bp_access_watchpoint
:
1763 /* Likewise for watchpoints on local expressions. */
1764 if (b
->exp_valid_block
!= NULL
)
1765 delete_breakpoint (b
);
1766 else if (context
== inf_starting
)
1768 /* Reset val field to force reread of starting value
1769 in insert_breakpoints. */
1771 value_free (b
->val
);
1782 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1783 exists at PC. It returns ordinary_breakpoint_here if it's an
1784 ordinary breakpoint, or permanent_breakpoint_here if it's a
1785 permanent breakpoint.
1786 - When continuing from a location with an ordinary breakpoint, we
1787 actually single step once before calling insert_breakpoints.
1788 - When continuing from a localion with a permanent breakpoint, we
1789 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1790 the target, to advance the PC past the breakpoint. */
1792 enum breakpoint_here
1793 breakpoint_here_p (CORE_ADDR pc
)
1795 const struct bp_location
*bpt
;
1796 int any_breakpoint_here
= 0;
1798 ALL_BP_LOCATIONS (bpt
)
1800 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1801 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1804 if ((breakpoint_enabled (bpt
->owner
)
1805 || bpt
->owner
->enable_state
== bp_permanent
)
1806 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1808 if (overlay_debugging
1809 && section_is_overlay (bpt
->section
)
1810 && !section_is_mapped (bpt
->section
))
1811 continue; /* unmapped overlay -- can't be a match */
1812 else if (bpt
->owner
->enable_state
== bp_permanent
)
1813 return permanent_breakpoint_here
;
1815 any_breakpoint_here
= 1;
1819 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1823 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1824 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1825 This does not check for single-step breakpoints, which are
1826 inserted and removed using direct target manipulation. */
1829 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1831 const struct bp_location
*bpt
;
1833 ALL_BP_LOCATIONS (bpt
)
1835 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1836 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1840 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1842 if (overlay_debugging
1843 && section_is_overlay (bpt
->section
)
1844 && !section_is_mapped (bpt
->section
))
1845 continue; /* unmapped overlay -- can't be a match */
1853 /* Returns non-zero iff there's either regular breakpoint
1854 or a single step breakpoint inserted at PC. */
1857 breakpoint_inserted_here_p (CORE_ADDR pc
)
1859 if (regular_breakpoint_inserted_here_p (pc
))
1862 if (single_step_breakpoint_inserted_here_p (pc
))
1868 /* This function returns non-zero iff there is a software breakpoint
1872 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1874 const struct bp_location
*bpt
;
1875 int any_breakpoint_here
= 0;
1877 ALL_BP_LOCATIONS (bpt
)
1879 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1883 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1885 if (overlay_debugging
1886 && section_is_overlay (bpt
->section
)
1887 && !section_is_mapped (bpt
->section
))
1888 continue; /* unmapped overlay -- can't be a match */
1894 /* Also check for software single-step breakpoints. */
1895 if (single_step_breakpoint_inserted_here_p (pc
))
1901 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1902 PC is valid for process/thread PTID. */
1905 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1907 const struct bp_location
*bpt
;
1910 thread
= pid_to_thread_id (ptid
);
1912 ALL_BP_LOCATIONS (bpt
)
1914 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1915 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1918 if ((breakpoint_enabled (bpt
->owner
)
1919 || bpt
->owner
->enable_state
== bp_permanent
)
1920 && bpt
->address
== pc
1921 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1923 if (overlay_debugging
1924 && section_is_overlay (bpt
->section
)
1925 && !section_is_mapped (bpt
->section
))
1926 continue; /* unmapped overlay -- can't be a match */
1936 /* bpstat stuff. External routines' interfaces are documented
1940 ep_is_catchpoint (struct breakpoint
*ep
)
1943 (ep
->type
== bp_catch_load
)
1944 || (ep
->type
== bp_catch_unload
)
1945 || (ep
->type
== bp_catch_fork
)
1946 || (ep
->type
== bp_catch_vfork
)
1947 || (ep
->type
== bp_catch_exec
);
1949 /* ??rehrauer: Add more kinds here, as are implemented... */
1953 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1956 (ep
->type
== bp_catch_load
)
1957 || (ep
->type
== bp_catch_unload
);
1961 bpstat_free (bpstat bs
)
1963 if (bs
->old_val
!= NULL
)
1964 value_free (bs
->old_val
);
1965 free_command_lines (&bs
->commands
);
1969 /* Clear a bpstat so that it says we are not at any breakpoint.
1970 Also free any storage that is part of a bpstat. */
1973 bpstat_clear (bpstat
*bsp
)
1990 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1991 is part of the bpstat is copied as well. */
1994 bpstat_copy (bpstat bs
)
1998 bpstat retval
= NULL
;
2003 for (; bs
!= NULL
; bs
= bs
->next
)
2005 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2006 memcpy (tmp
, bs
, sizeof (*tmp
));
2007 if (bs
->commands
!= NULL
)
2008 tmp
->commands
= copy_command_lines (bs
->commands
);
2009 if (bs
->old_val
!= NULL
)
2010 tmp
->old_val
= value_copy (bs
->old_val
);
2013 /* This is the first thing in the chain. */
2023 /* Find the bpstat associated with this breakpoint */
2026 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2031 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2033 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2039 /* Find a step_resume breakpoint associated with this bpstat.
2040 (If there are multiple step_resume bp's on the list, this function
2041 will arbitrarily pick one.)
2043 It is an error to use this function if BPSTAT doesn't contain a
2044 step_resume breakpoint.
2046 See wait_for_inferior's use of this function. */
2048 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2052 gdb_assert (bsp
!= NULL
);
2054 current_thread
= pid_to_thread_id (inferior_ptid
);
2056 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2058 if ((bsp
->breakpoint_at
!= NULL
) &&
2059 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2060 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2061 bsp
->breakpoint_at
->owner
->thread
== -1))
2062 return bsp
->breakpoint_at
->owner
;
2065 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2069 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2070 at. *BSP upon return is a bpstat which points to the remaining
2071 breakpoints stopped at (but which is not guaranteed to be good for
2072 anything but further calls to bpstat_num).
2073 Return 0 if passed a bpstat which does not indicate any breakpoints.
2074 Return -1 if stopped at a breakpoint that has been deleted since
2076 Return 1 otherwise. */
2079 bpstat_num (bpstat
*bsp
, int *num
)
2081 struct breakpoint
*b
;
2084 return 0; /* No more breakpoint values */
2086 /* We assume we'll never have several bpstats that
2087 correspond to a single breakpoint -- otherwise,
2088 this function might return the same number more
2089 than once and this will look ugly. */
2090 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2091 *bsp
= (*bsp
)->next
;
2093 return -1; /* breakpoint that's been deleted since */
2095 *num
= b
->number
; /* We have its number */
2099 /* Modify BS so that the actions will not be performed. */
2102 bpstat_clear_actions (bpstat bs
)
2104 for (; bs
!= NULL
; bs
= bs
->next
)
2106 free_command_lines (&bs
->commands
);
2107 if (bs
->old_val
!= NULL
)
2109 value_free (bs
->old_val
);
2115 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2117 cleanup_executing_breakpoints (void *ignore
)
2119 executing_breakpoint_commands
= 0;
2122 /* Execute all the commands associated with all the breakpoints at this
2123 location. Any of these commands could cause the process to proceed
2124 beyond this point, etc. We look out for such changes by checking
2125 the global "breakpoint_proceeded" after each command. */
2128 bpstat_do_actions (bpstat
*bsp
)
2131 struct cleanup
*old_chain
;
2133 /* Avoid endless recursion if a `source' command is contained
2135 if (executing_breakpoint_commands
)
2138 executing_breakpoint_commands
= 1;
2139 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2142 /* Note that (as of this writing), our callers all appear to
2143 be passing us the address of global stop_bpstat. And, if
2144 our calls to execute_control_command cause the inferior to
2145 proceed, that global (and hence, *bsp) will change.
2147 We must be careful to not touch *bsp unless the inferior
2148 has not proceeded. */
2150 /* This pointer will iterate over the list of bpstat's. */
2153 breakpoint_proceeded
= 0;
2154 for (; bs
!= NULL
; bs
= bs
->next
)
2156 struct command_line
*cmd
;
2157 struct cleanup
*this_cmd_tree_chain
;
2159 /* Take ownership of the BSP's command tree, if it has one.
2161 The command tree could legitimately contain commands like
2162 'step' and 'next', which call clear_proceed_status, which
2163 frees stop_bpstat's command tree. To make sure this doesn't
2164 free the tree we're executing out from under us, we need to
2165 take ownership of the tree ourselves. Since a given bpstat's
2166 commands are only executed once, we don't need to copy it; we
2167 can clear the pointer in the bpstat, and make sure we free
2168 the tree when we're done. */
2171 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2175 execute_control_command (cmd
);
2177 if (breakpoint_proceeded
)
2183 /* We can free this command tree now. */
2184 do_cleanups (this_cmd_tree_chain
);
2186 if (breakpoint_proceeded
)
2188 if (target_can_async_p ())
2189 /* If we are in async mode, then the target might
2190 be still running, not stopped at any breakpoint,
2191 so nothing for us to do here -- just return to
2195 /* In sync mode, when execute_control_command returns
2196 we're already standing on the next breakpoint.
2197 Breakpoint commands for that stop were not run,
2198 since execute_command does not run breakpoint
2199 commands -- only command_line_handler does, but
2200 that one is not involved in execution of breakpoint
2201 commands. So, we can now execute breakpoint commands.
2202 There's an implicit assumption that we're called with
2203 stop_bpstat, so our parameter is the new bpstat to
2205 It should be noted that making execute_command do
2206 bpstat actions is not an option -- in this case we'll
2207 have recursive invocation of bpstat for each breakpoint
2208 with a command, and can easily blow up GDB stack. */
2212 do_cleanups (old_chain
);
2215 /* Print out the (old or new) value associated with a watchpoint. */
2218 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2221 fprintf_unfiltered (stream
, _("<unreadable>"));
2223 value_print (val
, stream
, 0, Val_pretty_default
);
2226 /* This is the normal print function for a bpstat. In the future,
2227 much of this logic could (should?) be moved to bpstat_stop_status,
2228 by having it set different print_it values.
2230 Current scheme: When we stop, bpstat_print() is called. It loops
2231 through the bpstat list of things causing this stop, calling the
2232 print_bp_stop_message function on each one. The behavior of the
2233 print_bp_stop_message function depends on the print_it field of
2234 bpstat. If such field so indicates, call this function here.
2236 Return values from this routine (ultimately used by bpstat_print()
2237 and normal_stop() to decide what to do):
2238 PRINT_NOTHING: Means we already printed all we needed to print,
2239 don't print anything else.
2240 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2241 that something to be followed by a location.
2242 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2243 that something to be followed by a location.
2244 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2247 static enum print_stop_action
2248 print_it_typical (bpstat bs
)
2250 struct cleanup
*old_chain
, *ui_out_chain
;
2251 struct breakpoint
*b
;
2252 const struct bp_location
*bl
;
2253 struct ui_stream
*stb
;
2255 stb
= ui_out_stream_new (uiout
);
2256 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2257 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2258 which has since been deleted. */
2259 if (bs
->breakpoint_at
== NULL
)
2260 return PRINT_UNKNOWN
;
2261 bl
= bs
->breakpoint_at
;
2267 case bp_hardware_breakpoint
:
2268 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2269 if (bl
->address
!= bl
->requested_address
)
2270 breakpoint_adjustment_warning (bl
->requested_address
,
2273 annotate_breakpoint (b
->number
);
2275 ui_out_text (uiout
, "\nTemporary breakpoint ");
2277 ui_out_text (uiout
, "\nBreakpoint ");
2278 if (ui_out_is_mi_like_p (uiout
))
2280 ui_out_field_string (uiout
, "reason",
2281 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2282 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2284 ui_out_field_int (uiout
, "bkptno", b
->number
);
2285 ui_out_text (uiout
, ", ");
2286 return PRINT_SRC_AND_LOC
;
2289 case bp_shlib_event
:
2290 /* Did we stop because the user set the stop_on_solib_events
2291 variable? (If so, we report this as a generic, "Stopped due
2292 to shlib event" message.) */
2293 printf_filtered (_("Stopped due to shared library event\n"));
2294 return PRINT_NOTHING
;
2297 case bp_thread_event
:
2298 /* Not sure how we will get here.
2299 GDB should not stop for these breakpoints. */
2300 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2301 return PRINT_NOTHING
;
2304 case bp_overlay_event
:
2305 /* By analogy with the thread event, GDB should not stop for these. */
2306 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2307 return PRINT_NOTHING
;
2311 annotate_catchpoint (b
->number
);
2312 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2314 b
->triggered_dll_pathname
);
2315 return PRINT_SRC_AND_LOC
;
2318 case bp_catch_unload
:
2319 annotate_catchpoint (b
->number
);
2320 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2322 b
->triggered_dll_pathname
);
2323 return PRINT_SRC_AND_LOC
;
2327 annotate_catchpoint (b
->number
);
2328 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2330 b
->forked_inferior_pid
);
2331 return PRINT_SRC_AND_LOC
;
2334 case bp_catch_vfork
:
2335 annotate_catchpoint (b
->number
);
2336 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2338 b
->forked_inferior_pid
);
2339 return PRINT_SRC_AND_LOC
;
2343 annotate_catchpoint (b
->number
);
2344 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2347 return PRINT_SRC_AND_LOC
;
2351 case bp_hardware_watchpoint
:
2352 annotate_watchpoint (b
->number
);
2353 if (ui_out_is_mi_like_p (uiout
))
2356 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2358 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2359 ui_out_text (uiout
, "\nOld value = ");
2360 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2361 ui_out_field_stream (uiout
, "old", stb
);
2362 ui_out_text (uiout
, "\nNew value = ");
2363 watchpoint_value_print (b
->val
, stb
->stream
);
2364 ui_out_field_stream (uiout
, "new", stb
);
2365 do_cleanups (ui_out_chain
);
2366 ui_out_text (uiout
, "\n");
2367 /* More than one watchpoint may have been triggered. */
2368 return PRINT_UNKNOWN
;
2371 case bp_read_watchpoint
:
2372 if (ui_out_is_mi_like_p (uiout
))
2375 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2377 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2378 ui_out_text (uiout
, "\nValue = ");
2379 watchpoint_value_print (b
->val
, stb
->stream
);
2380 ui_out_field_stream (uiout
, "value", stb
);
2381 do_cleanups (ui_out_chain
);
2382 ui_out_text (uiout
, "\n");
2383 return PRINT_UNKNOWN
;
2386 case bp_access_watchpoint
:
2387 if (bs
->old_val
!= NULL
)
2389 annotate_watchpoint (b
->number
);
2390 if (ui_out_is_mi_like_p (uiout
))
2393 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2395 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2396 ui_out_text (uiout
, "\nOld value = ");
2397 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2398 ui_out_field_stream (uiout
, "old", stb
);
2399 ui_out_text (uiout
, "\nNew value = ");
2404 if (ui_out_is_mi_like_p (uiout
))
2407 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2408 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2409 ui_out_text (uiout
, "\nValue = ");
2411 watchpoint_value_print (b
->val
, stb
->stream
);
2412 ui_out_field_stream (uiout
, "new", stb
);
2413 do_cleanups (ui_out_chain
);
2414 ui_out_text (uiout
, "\n");
2415 return PRINT_UNKNOWN
;
2418 /* Fall through, we don't deal with these types of breakpoints
2422 if (ui_out_is_mi_like_p (uiout
))
2425 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2426 return PRINT_UNKNOWN
;
2430 if (ui_out_is_mi_like_p (uiout
))
2433 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2434 return PRINT_UNKNOWN
;
2439 case bp_longjmp_resume
:
2440 case bp_step_resume
:
2441 case bp_watchpoint_scope
:
2444 return PRINT_UNKNOWN
;
2448 /* Generic routine for printing messages indicating why we
2449 stopped. The behavior of this function depends on the value
2450 'print_it' in the bpstat structure. Under some circumstances we
2451 may decide not to print anything here and delegate the task to
2454 static enum print_stop_action
2455 print_bp_stop_message (bpstat bs
)
2457 switch (bs
->print_it
)
2460 /* Nothing should be printed for this bpstat entry. */
2461 return PRINT_UNKNOWN
;
2465 /* We still want to print the frame, but we already printed the
2466 relevant messages. */
2467 return PRINT_SRC_AND_LOC
;
2470 case print_it_normal
:
2472 const struct bp_location
*bl
= bs
->breakpoint_at
;
2473 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2475 /* Normal case. Call the breakpoint's print_it method, or
2476 print_it_typical. */
2477 /* FIXME: how breakpoint can ever be NULL here? */
2478 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2479 return b
->ops
->print_it (b
);
2481 return print_it_typical (bs
);
2486 internal_error (__FILE__
, __LINE__
,
2487 _("print_bp_stop_message: unrecognized enum value"));
2492 /* Print a message indicating what happened. This is called from
2493 normal_stop(). The input to this routine is the head of the bpstat
2494 list - a list of the eventpoints that caused this stop. This
2495 routine calls the generic print routine for printing a message
2496 about reasons for stopping. This will print (for example) the
2497 "Breakpoint n," part of the output. The return value of this
2500 PRINT_UNKNOWN: Means we printed nothing
2501 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2502 code to print the location. An example is
2503 "Breakpoint 1, " which should be followed by
2505 PRINT_SRC_ONLY: Means we printed something, but there is no need
2506 to also print the location part of the message.
2507 An example is the catch/throw messages, which
2508 don't require a location appended to the end.
2509 PRINT_NOTHING: We have done some printing and we don't need any
2510 further info to be printed.*/
2512 enum print_stop_action
2513 bpstat_print (bpstat bs
)
2517 /* Maybe another breakpoint in the chain caused us to stop.
2518 (Currently all watchpoints go on the bpstat whether hit or not.
2519 That probably could (should) be changed, provided care is taken
2520 with respect to bpstat_explains_signal). */
2521 for (; bs
; bs
= bs
->next
)
2523 val
= print_bp_stop_message (bs
);
2524 if (val
== PRINT_SRC_ONLY
2525 || val
== PRINT_SRC_AND_LOC
2526 || val
== PRINT_NOTHING
)
2530 /* We reached the end of the chain, or we got a null BS to start
2531 with and nothing was printed. */
2532 return PRINT_UNKNOWN
;
2535 /* Evaluate the expression EXP and return 1 if value is zero.
2536 This is used inside a catch_errors to evaluate the breakpoint condition.
2537 The argument is a "struct expression *" that has been cast to char * to
2538 make it pass through catch_errors. */
2541 breakpoint_cond_eval (void *exp
)
2543 struct value
*mark
= value_mark ();
2544 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2545 value_free_to_mark (mark
);
2549 /* Allocate a new bpstat and chain it to the current one. */
2552 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2556 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2558 bs
->breakpoint_at
= bl
;
2559 /* If the condition is false, etc., don't do the commands. */
2560 bs
->commands
= NULL
;
2562 bs
->print_it
= print_it_normal
;
2566 /* The target has stopped with waitstatus WS. Check if any hardware
2567 watchpoints have triggered, according to the target. */
2570 watchpoints_triggered (struct target_waitstatus
*ws
)
2572 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2574 struct breakpoint
*b
;
2576 if (!stopped_by_watchpoint
)
2578 /* We were not stopped by a watchpoint. Mark all watchpoints
2579 as not triggered. */
2581 if (b
->type
== bp_hardware_watchpoint
2582 || b
->type
== bp_read_watchpoint
2583 || b
->type
== bp_access_watchpoint
)
2584 b
->watchpoint_triggered
= watch_triggered_no
;
2589 if (!target_stopped_data_address (¤t_target
, &addr
))
2591 /* We were stopped by a watchpoint, but we don't know where.
2592 Mark all watchpoints as unknown. */
2594 if (b
->type
== bp_hardware_watchpoint
2595 || b
->type
== bp_read_watchpoint
2596 || b
->type
== bp_access_watchpoint
)
2597 b
->watchpoint_triggered
= watch_triggered_unknown
;
2599 return stopped_by_watchpoint
;
2602 /* The target could report the data address. Mark watchpoints
2603 affected by this data address as triggered, and all others as not
2607 if (b
->type
== bp_hardware_watchpoint
2608 || b
->type
== bp_read_watchpoint
2609 || b
->type
== bp_access_watchpoint
)
2611 struct bp_location
*loc
;
2614 b
->watchpoint_triggered
= watch_triggered_no
;
2615 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2616 /* Exact match not required. Within range is
2618 if (addr
>= loc
->address
2619 && addr
< loc
->address
+ loc
->length
)
2621 b
->watchpoint_triggered
= watch_triggered_yes
;
2629 /* Possible return values for watchpoint_check (this can't be an enum
2630 because of check_errors). */
2631 /* The watchpoint has been deleted. */
2632 #define WP_DELETED 1
2633 /* The value has changed. */
2634 #define WP_VALUE_CHANGED 2
2635 /* The value has not changed. */
2636 #define WP_VALUE_NOT_CHANGED 3
2638 #define BP_TEMPFLAG 1
2639 #define BP_HARDWAREFLAG 2
2641 /* Check watchpoint condition. */
2644 watchpoint_check (void *p
)
2646 bpstat bs
= (bpstat
) p
;
2647 struct breakpoint
*b
;
2648 struct frame_info
*fr
;
2649 int within_current_scope
;
2651 b
= bs
->breakpoint_at
->owner
;
2653 if (b
->exp_valid_block
== NULL
)
2654 within_current_scope
= 1;
2657 /* There is no current frame at this moment. If we're going to have
2658 any chance of handling watchpoints on local variables, we'll need
2659 the frame chain (so we can determine if we're in scope). */
2660 reinit_frame_cache ();
2661 fr
= frame_find_by_id (b
->watchpoint_frame
);
2662 within_current_scope
= (fr
!= NULL
);
2664 /* If we've gotten confused in the unwinder, we might have
2665 returned a frame that can't describe this variable. */
2666 if (within_current_scope
2667 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2668 within_current_scope
= 0;
2670 /* in_function_epilogue_p() returns a non-zero value if we're still
2671 in the function but the stack frame has already been invalidated.
2672 Since we can't rely on the values of local variables after the
2673 stack has been destroyed, we are treating the watchpoint in that
2674 state as `not changed' without further checking.
2676 vinschen/2003-09-04: The former implementation left out the case
2677 that the watchpoint frame couldn't be found by frame_find_by_id()
2678 because the current PC is currently in an epilogue. Calling
2679 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2680 if ((!within_current_scope
|| fr
== get_current_frame ())
2681 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2682 return WP_VALUE_NOT_CHANGED
;
2683 if (fr
&& within_current_scope
)
2684 /* If we end up stopping, the current frame will get selected
2685 in normal_stop. So this call to select_frame won't affect
2690 if (within_current_scope
)
2692 /* We use value_{,free_to_}mark because it could be a
2693 *long* time before we return to the command level and
2694 call free_all_values. We can't call free_all_values because
2695 we might be in the middle of evaluating a function call. */
2697 struct value
*mark
= value_mark ();
2698 struct value
*new_val
;
2700 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2701 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2702 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2704 if (new_val
!= NULL
)
2706 release_value (new_val
);
2707 value_free_to_mark (mark
);
2709 bs
->old_val
= b
->val
;
2712 /* We will stop here */
2713 return WP_VALUE_CHANGED
;
2717 /* Nothing changed, don't do anything. */
2718 value_free_to_mark (mark
);
2719 /* We won't stop here */
2720 return WP_VALUE_NOT_CHANGED
;
2725 /* This seems like the only logical thing to do because
2726 if we temporarily ignored the watchpoint, then when
2727 we reenter the block in which it is valid it contains
2728 garbage (in the case of a function, it may have two
2729 garbage values, one before and one after the prologue).
2730 So we can't even detect the first assignment to it and
2731 watch after that (since the garbage may or may not equal
2732 the first value assigned). */
2733 /* We print all the stop information in print_it_typical(), but
2734 in this case, by the time we call print_it_typical() this bp
2735 will be deleted already. So we have no choice but print the
2736 information here. */
2737 if (ui_out_is_mi_like_p (uiout
))
2739 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2740 ui_out_text (uiout
, "\nWatchpoint ");
2741 ui_out_field_int (uiout
, "wpnum", b
->number
);
2742 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2743 which its expression is valid.\n");
2745 if (b
->related_breakpoint
)
2746 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2747 b
->disposition
= disp_del_at_next_stop
;
2753 /* Return true if it looks like target has stopped due to hitting
2754 breakpoint location BL. This function does not check if we
2755 should stop, only if BL explains the stop. */
2757 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2759 struct breakpoint
*b
= bl
->owner
;
2761 if (b
->type
!= bp_watchpoint
2762 && b
->type
!= bp_hardware_watchpoint
2763 && b
->type
!= bp_read_watchpoint
2764 && b
->type
!= bp_access_watchpoint
2765 && b
->type
!= bp_hardware_breakpoint
2766 && b
->type
!= bp_catch_fork
2767 && b
->type
!= bp_catch_vfork
2768 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2770 if (bl
->address
!= bp_addr
) /* address doesn't match */
2772 if (overlay_debugging
/* unmapped overlay section */
2773 && section_is_overlay (bl
->section
)
2774 && !section_is_mapped (bl
->section
))
2778 /* Continuable hardware watchpoints are treated as non-existent if the
2779 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2780 some data address). Otherwise gdb won't stop on a break instruction
2781 in the code (not from a breakpoint) when a hardware watchpoint has
2782 been defined. Also skip watchpoints which we know did not trigger
2783 (did not match the data address). */
2785 if ((b
->type
== bp_hardware_watchpoint
2786 || b
->type
== bp_read_watchpoint
2787 || b
->type
== bp_access_watchpoint
)
2788 && b
->watchpoint_triggered
== watch_triggered_no
)
2791 if (b
->type
== bp_hardware_breakpoint
)
2793 if (bl
->address
!= bp_addr
)
2795 if (overlay_debugging
/* unmapped overlay section */
2796 && section_is_overlay (bl
->section
)
2797 && !section_is_mapped (bl
->section
))
2801 /* Is this a catchpoint of a load or unload? If so, did we
2802 get a load or unload of the specified library? If not,
2804 if ((b
->type
== bp_catch_load
)
2805 #if defined(SOLIB_HAVE_LOAD_EVENT)
2806 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2807 || ((b
->dll_pathname
!= NULL
)
2808 && (strcmp (b
->dll_pathname
,
2809 SOLIB_LOADED_LIBRARY_PATHNAME (
2810 PIDGET (inferior_ptid
)))
2816 if ((b
->type
== bp_catch_unload
)
2817 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2818 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2819 || ((b
->dll_pathname
!= NULL
)
2820 && (strcmp (b
->dll_pathname
,
2821 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2822 PIDGET (inferior_ptid
)))
2828 if ((b
->type
== bp_catch_fork
)
2829 && !inferior_has_forked (PIDGET (inferior_ptid
),
2830 &b
->forked_inferior_pid
))
2833 if ((b
->type
== bp_catch_vfork
)
2834 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2835 &b
->forked_inferior_pid
))
2838 if ((b
->type
== bp_catch_exec
)
2839 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2845 /* If BS refers to a watchpoint, determine if the watched values
2846 has actually changed, and we should stop. If not, set BS->stop
2849 bpstat_check_watchpoint (bpstat bs
)
2851 const struct bp_location
*bl
= bs
->breakpoint_at
;
2852 struct breakpoint
*b
= bl
->owner
;
2854 if (b
->type
== bp_watchpoint
2855 || b
->type
== bp_read_watchpoint
2856 || b
->type
== bp_access_watchpoint
2857 || b
->type
== bp_hardware_watchpoint
)
2861 int must_check_value
= 0;
2863 if (b
->type
== bp_watchpoint
)
2864 /* For a software watchpoint, we must always check the
2866 must_check_value
= 1;
2867 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2868 /* We have a hardware watchpoint (read, write, or access)
2869 and the target earlier reported an address watched by
2871 must_check_value
= 1;
2872 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2873 && b
->type
== bp_hardware_watchpoint
)
2874 /* We were stopped by a hardware watchpoint, but the target could
2875 not report the data address. We must check the watchpoint's
2876 value. Access and read watchpoints are out of luck; without
2877 a data address, we can't figure it out. */
2878 must_check_value
= 1;
2880 if (must_check_value
)
2882 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2884 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2885 int e
= catch_errors (watchpoint_check
, bs
, message
,
2887 do_cleanups (cleanups
);
2891 /* We've already printed what needs to be printed. */
2892 bs
->print_it
= print_it_done
;
2895 case WP_VALUE_CHANGED
:
2896 if (b
->type
== bp_read_watchpoint
)
2898 /* Don't stop: read watchpoints shouldn't fire if
2899 the value has changed. This is for targets
2900 which cannot set read-only watchpoints. */
2901 bs
->print_it
= print_it_noop
;
2905 case WP_VALUE_NOT_CHANGED
:
2906 if (b
->type
== bp_hardware_watchpoint
2907 || b
->type
== bp_watchpoint
)
2909 /* Don't stop: write watchpoints shouldn't fire if
2910 the value hasn't changed. */
2911 bs
->print_it
= print_it_noop
;
2919 /* Error from catch_errors. */
2920 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2921 if (b
->related_breakpoint
)
2922 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2923 b
->disposition
= disp_del_at_next_stop
;
2924 /* We've already printed what needs to be printed. */
2925 bs
->print_it
= print_it_done
;
2929 else /* must_check_value == 0 */
2931 /* This is a case where some watchpoint(s) triggered, but
2932 not at the address of this watchpoint, or else no
2933 watchpoint triggered after all. So don't print
2934 anything for this watchpoint. */
2935 bs
->print_it
= print_it_noop
;
2942 /* Check conditions (condition proper, frame, thread and ignore count)
2943 of breakpoint referred to by BS. If we should not stop for this
2944 breakpoint, set BS->stop to 0. */
2946 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2948 int thread_id
= pid_to_thread_id (ptid
);
2949 const struct bp_location
*bl
= bs
->breakpoint_at
;
2950 struct breakpoint
*b
= bl
->owner
;
2952 if (frame_id_p (b
->frame_id
)
2953 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2957 int value_is_zero
= 0;
2959 /* If this is a scope breakpoint, mark the associated
2960 watchpoint as triggered so that we will handle the
2961 out-of-scope event. We'll get to the watchpoint next
2963 if (b
->type
== bp_watchpoint_scope
)
2964 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2966 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2968 /* Need to select the frame, with all that implies
2969 so that the conditions will have the right context. */
2970 select_frame (get_current_frame ());
2972 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2973 "Error in testing breakpoint condition:\n",
2975 /* FIXME-someday, should give breakpoint # */
2978 if (bl
->cond
&& value_is_zero
)
2982 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2986 else if (b
->ignore_count
> 0)
2989 annotate_ignore_count_change ();
2991 /* Increase the hit count even though we don't
2999 /* Get a bpstat associated with having just stopped at address
3000 BP_ADDR in thread PTID.
3002 Determine whether we stopped at a breakpoint, etc, or whether we
3003 don't understand this stop. Result is a chain of bpstat's such that:
3005 if we don't understand the stop, the result is a null pointer.
3007 if we understand why we stopped, the result is not null.
3009 Each element of the chain refers to a particular breakpoint or
3010 watchpoint at which we have stopped. (We may have stopped for
3011 several reasons concurrently.)
3013 Each element of the chain has valid next, breakpoint_at,
3014 commands, FIXME??? fields. */
3017 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3019 struct breakpoint
*b
= NULL
;
3020 const struct bp_location
*bl
;
3021 /* Root of the chain of bpstat's */
3022 struct bpstats root_bs
[1];
3023 /* Pointer to the last thing in the chain currently. */
3024 bpstat bs
= root_bs
;
3026 ALL_BP_LOCATIONS (bl
)
3030 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3033 /* For hardware watchpoints, we look only at the first location.
3034 The watchpoint_check function will work on entire expression,
3035 not the individual locations. For read watchopints, the
3036 watchpoints_triggered function have checked all locations
3039 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3042 if (!bpstat_check_location (bl
, bp_addr
))
3045 /* Come here if it's a watchpoint, or if the break address matches */
3047 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3049 /* Assume we stop. Should we find watchpoint that is not actually
3050 triggered, or if condition of breakpoint is false, we'll reset
3055 bpstat_check_watchpoint (bs
);
3059 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3060 /* We do not stop for these. */
3063 bpstat_check_breakpoint_conditions (bs
, ptid
);
3069 /* We will stop here */
3070 if (b
->disposition
== disp_disable
)
3072 b
->enable_state
= bp_disabled
;
3073 update_global_location_list ();
3077 bs
->commands
= b
->commands
;
3079 (strcmp ("silent", bs
->commands
->line
) == 0
3080 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3082 bs
->commands
= bs
->commands
->next
;
3085 bs
->commands
= copy_command_lines (bs
->commands
);
3088 /* Print nothing for this entry if we dont stop or if we dont print. */
3089 if (bs
->stop
== 0 || bs
->print
== 0)
3090 bs
->print_it
= print_it_noop
;
3093 bs
->next
= NULL
; /* Terminate the chain */
3094 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3096 /* If we aren't stopping, the value of some hardware watchpoint may
3097 not have changed, but the intermediate memory locations we are
3098 watching may have. Don't bother if we're stopping; this will get
3100 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3105 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3107 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3108 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3109 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3111 /* remove/insert can invalidate bs->breakpoint_at, if this
3112 location is no longer used by the watchpoint. Prevent
3113 further code from trying to use it. */
3114 bs
->breakpoint_at
= NULL
;
3115 remove_breakpoints ();
3116 insert_breakpoints ();
3120 return root_bs
->next
;
3123 /* Tell what to do about this bpstat. */
3125 bpstat_what (bpstat bs
)
3127 /* Classify each bpstat as one of the following. */
3130 /* This bpstat element has no effect on the main_action. */
3133 /* There was a watchpoint, stop but don't print. */
3136 /* There was a watchpoint, stop and print. */
3139 /* There was a breakpoint but we're not stopping. */
3142 /* There was a breakpoint, stop but don't print. */
3145 /* There was a breakpoint, stop and print. */
3148 /* We hit the longjmp breakpoint. */
3151 /* We hit the longjmp_resume breakpoint. */
3154 /* We hit the step_resume breakpoint. */
3157 /* We hit the shared library event breakpoint. */
3160 /* We caught a shared library event. */
3163 /* This is just used to count how many enums there are. */
3167 /* Here is the table which drives this routine. So that we can
3168 format it pretty, we define some abbreviations for the
3169 enum bpstat_what codes. */
3170 #define kc BPSTAT_WHAT_KEEP_CHECKING
3171 #define ss BPSTAT_WHAT_STOP_SILENT
3172 #define sn BPSTAT_WHAT_STOP_NOISY
3173 #define sgl BPSTAT_WHAT_SINGLE
3174 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3175 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3176 #define sr BPSTAT_WHAT_STEP_RESUME
3177 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3178 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3180 /* "Can't happen." Might want to print an error message.
3181 abort() is not out of the question, but chances are GDB is just
3182 a bit confused, not unusable. */
3183 #define err BPSTAT_WHAT_STOP_NOISY
3185 /* Given an old action and a class, come up with a new action. */
3186 /* One interesting property of this table is that wp_silent is the same
3187 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3188 after stopping, the check for whether to step over a breakpoint
3189 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3190 reference to how we stopped. We retain separate wp_silent and
3191 bp_silent codes in case we want to change that someday.
3193 Another possibly interesting property of this table is that
3194 there's a partial ordering, priority-like, of the actions. Once
3195 you've decided that some action is appropriate, you'll never go
3196 back and decide something of a lower priority is better. The
3199 kc < clr sgl shl shlr slr sn sr ss
3200 sgl < shl shlr slr sn sr ss
3201 slr < err shl shlr sn sr ss
3202 clr < err shl shlr sn sr ss
3209 What I think this means is that we don't need a damned table
3210 here. If you just put the rows and columns in the right order,
3211 it'd look awfully regular. We could simply walk the bpstat list
3212 and choose the highest priority action we find, with a little
3213 logic to handle the 'err' cases. */
3215 /* step_resume entries: a step resume breakpoint overrides another
3216 breakpoint of signal handling (see comment in wait_for_inferior
3217 at where we set the step_resume breakpoint). */
3219 static const enum bpstat_what_main_action
3220 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3223 /* kc ss sn sgl slr clr sr shl shlr
3226 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3228 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3230 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3232 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3234 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3236 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3238 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3240 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3242 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3244 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3246 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3260 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3261 struct bpstat_what retval
;
3263 retval
.call_dummy
= 0;
3264 for (; bs
!= NULL
; bs
= bs
->next
)
3266 enum class bs_class
= no_effect
;
3267 if (bs
->breakpoint_at
== NULL
)
3268 /* I suspect this can happen if it was a momentary breakpoint
3269 which has since been deleted. */
3271 switch (bs
->breakpoint_at
->owner
->type
)
3277 case bp_hardware_breakpoint
:
3283 bs_class
= bp_noisy
;
3285 bs_class
= bp_silent
;
3288 bs_class
= bp_nostop
;
3291 case bp_hardware_watchpoint
:
3292 case bp_read_watchpoint
:
3293 case bp_access_watchpoint
:
3297 bs_class
= wp_noisy
;
3299 bs_class
= wp_silent
;
3302 /* There was a watchpoint, but we're not stopping.
3303 This requires no further action. */
3304 bs_class
= no_effect
;
3307 bs_class
= long_jump
;
3309 case bp_longjmp_resume
:
3310 bs_class
= long_resume
;
3312 case bp_step_resume
:
3315 bs_class
= step_resume
;
3318 /* It is for the wrong frame. */
3319 bs_class
= bp_nostop
;
3321 case bp_watchpoint_scope
:
3322 bs_class
= bp_nostop
;
3324 case bp_shlib_event
:
3325 bs_class
= shlib_event
;
3327 case bp_thread_event
:
3328 case bp_overlay_event
:
3329 bs_class
= bp_nostop
;
3332 case bp_catch_unload
:
3333 /* Only if this catchpoint triggered should we cause the
3334 step-out-of-dld behaviour. Otherwise, we ignore this
3337 bs_class
= catch_shlib_event
;
3339 bs_class
= no_effect
;
3342 case bp_catch_vfork
:
3347 bs_class
= bp_noisy
;
3349 bs_class
= bp_silent
;
3352 /* There was a catchpoint, but we're not stopping.
3353 This requires no further action. */
3354 bs_class
= no_effect
;
3357 /* Make sure the action is stop (silent or noisy),
3358 so infrun.c pops the dummy frame. */
3359 bs_class
= bp_silent
;
3360 retval
.call_dummy
= 1;
3363 current_action
= table
[(int) bs_class
][(int) current_action
];
3365 retval
.main_action
= current_action
;
3369 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3370 without hardware support). This isn't related to a specific bpstat,
3371 just to things like whether watchpoints are set. */
3374 bpstat_should_step (void)
3376 struct breakpoint
*b
;
3378 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3385 /* Given a bpstat that records zero or more triggered eventpoints, this
3386 function returns another bpstat which contains only the catchpoints
3387 on that first list, if any. */
3389 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3391 struct bpstats root_bs
[1];
3392 bpstat bs
= root_bs
;
3393 struct breakpoint
*ep
;
3396 bpstat_clear (cp_list
);
3397 root_bs
->next
= NULL
;
3399 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3401 /* Is this eventpoint a catchpoint? If not, ignore it. */
3402 ep
= ep_list
->breakpoint_at
->owner
;
3405 if ((ep
->type
!= bp_catch_load
) &&
3406 (ep
->type
!= bp_catch_unload
))
3407 /* pai: (temp) ADD fork/vfork here!! */
3410 /* Yes; add it to the list. */
3411 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3416 #if defined(SOLIB_ADD)
3417 /* Also, for each triggered catchpoint, tag it with the name of
3418 the library that caused this trigger. (We copy the name now,
3419 because it's only guaranteed to be available NOW, when the
3420 catchpoint triggers. Clients who may wish to know the name
3421 later must get it from the catchpoint itself.) */
3422 if (ep
->triggered_dll_pathname
!= NULL
)
3423 xfree (ep
->triggered_dll_pathname
);
3424 if (ep
->type
== bp_catch_load
)
3425 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3426 PIDGET (inferior_ptid
));
3428 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3429 PIDGET (inferior_ptid
));
3431 dll_pathname
= NULL
;
3435 ep
->triggered_dll_pathname
= (char *)
3436 xmalloc (strlen (dll_pathname
) + 1);
3437 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3440 ep
->triggered_dll_pathname
= NULL
;
3446 static void print_breakpoint_location (struct breakpoint
*b
,
3447 struct bp_location
*loc
,
3449 struct ui_stream
*stb
)
3454 = find_pc_sect_function (loc
->address
, loc
->section
);
3457 ui_out_text (uiout
, "in ");
3458 ui_out_field_string (uiout
, "func",
3459 SYMBOL_PRINT_NAME (sym
));
3460 ui_out_wrap_hint (uiout
, wrap_indent
);
3461 ui_out_text (uiout
, " at ");
3463 ui_out_field_string (uiout
, "file", b
->source_file
);
3464 ui_out_text (uiout
, ":");
3466 if (ui_out_is_mi_like_p (uiout
))
3468 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3469 char *fullname
= symtab_to_fullname (sal
.symtab
);
3472 ui_out_field_string (uiout
, "fullname", fullname
);
3475 ui_out_field_int (uiout
, "line", b
->line_number
);
3479 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3483 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3484 ui_out_field_stream (uiout
, "at", stb
);
3488 /* Print B to gdb_stdout. */
3490 print_one_breakpoint_location (struct breakpoint
*b
,
3491 struct bp_location
*loc
,
3493 CORE_ADDR
*last_addr
)
3495 struct command_line
*l
;
3497 struct ep_type_description
3502 static struct ep_type_description bptypes
[] =
3504 {bp_none
, "?deleted?"},
3505 {bp_breakpoint
, "breakpoint"},
3506 {bp_hardware_breakpoint
, "hw breakpoint"},
3507 {bp_until
, "until"},
3508 {bp_finish
, "finish"},
3509 {bp_watchpoint
, "watchpoint"},
3510 {bp_hardware_watchpoint
, "hw watchpoint"},
3511 {bp_read_watchpoint
, "read watchpoint"},
3512 {bp_access_watchpoint
, "acc watchpoint"},
3513 {bp_longjmp
, "longjmp"},
3514 {bp_longjmp_resume
, "longjmp resume"},
3515 {bp_step_resume
, "step resume"},
3516 {bp_watchpoint_scope
, "watchpoint scope"},
3517 {bp_call_dummy
, "call dummy"},
3518 {bp_shlib_event
, "shlib events"},
3519 {bp_thread_event
, "thread events"},
3520 {bp_overlay_event
, "overlay events"},
3521 {bp_catch_load
, "catch load"},
3522 {bp_catch_unload
, "catch unload"},
3523 {bp_catch_fork
, "catch fork"},
3524 {bp_catch_vfork
, "catch vfork"},
3525 {bp_catch_exec
, "catch exec"}
3528 static char bpenables
[] = "nynny";
3529 char wrap_indent
[80];
3530 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3531 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3532 struct cleanup
*bkpt_chain
;
3534 int header_of_multiple
= 0;
3535 int part_of_multiple
= (loc
!= NULL
);
3537 gdb_assert (!loc
|| loc_number
!= 0);
3538 /* See comment in print_one_breakpoint concerning
3539 treatment of breakpoints with single disabled
3543 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3544 header_of_multiple
= 1;
3549 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3553 if (part_of_multiple
)
3556 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3557 ui_out_field_string (uiout
, "number", formatted
);
3562 ui_out_field_int (uiout
, "number", b
->number
);
3567 if (part_of_multiple
)
3568 ui_out_field_skip (uiout
, "type");
3571 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3572 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3573 internal_error (__FILE__
, __LINE__
,
3574 _("bptypes table does not describe type #%d."),
3576 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3581 if (part_of_multiple
)
3582 ui_out_field_skip (uiout
, "disp");
3584 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3589 if (part_of_multiple
)
3590 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3592 ui_out_field_fmt (uiout
, "enabled", "%c",
3593 bpenables
[(int) b
->enable_state
]);
3594 ui_out_spaces (uiout
, 2);
3598 strcpy (wrap_indent
, " ");
3601 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3602 strcat (wrap_indent
, " ");
3604 strcat (wrap_indent
, " ");
3607 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3609 /* Although the print_one can possibly print
3610 all locations, calling it here is not likely
3611 to get any nice result. So, make sure there's
3612 just one location. */
3613 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3614 b
->ops
->print_one (b
, last_addr
);
3620 internal_error (__FILE__
, __LINE__
,
3621 _("print_one_breakpoint: bp_none encountered\n"));
3625 case bp_hardware_watchpoint
:
3626 case bp_read_watchpoint
:
3627 case bp_access_watchpoint
:
3628 /* Field 4, the address, is omitted (which makes the columns
3629 not line up too nicely with the headers, but the effect
3630 is relatively readable). */
3632 ui_out_field_skip (uiout
, "addr");
3634 print_expression (b
->exp
, stb
->stream
);
3635 ui_out_field_stream (uiout
, "what", stb
);
3639 case bp_catch_unload
:
3640 /* Field 4, the address, is omitted (which makes the columns
3641 not line up too nicely with the headers, but the effect
3642 is relatively readable). */
3644 ui_out_field_skip (uiout
, "addr");
3646 if (b
->dll_pathname
== NULL
)
3648 ui_out_field_string (uiout
, "what", "<any library>");
3649 ui_out_spaces (uiout
, 1);
3653 ui_out_text (uiout
, "library \"");
3654 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3655 ui_out_text (uiout
, "\" ");
3660 case bp_catch_vfork
:
3661 /* Field 4, the address, is omitted (which makes the columns
3662 not line up too nicely with the headers, but the effect
3663 is relatively readable). */
3665 ui_out_field_skip (uiout
, "addr");
3667 if (b
->forked_inferior_pid
!= 0)
3669 ui_out_text (uiout
, "process ");
3670 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3671 ui_out_spaces (uiout
, 1);
3676 /* Field 4, the address, is omitted (which makes the columns
3677 not line up too nicely with the headers, but the effect
3678 is relatively readable). */
3680 ui_out_field_skip (uiout
, "addr");
3682 if (b
->exec_pathname
!= NULL
)
3684 ui_out_text (uiout
, "program \"");
3685 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3686 ui_out_text (uiout
, "\" ");
3691 case bp_hardware_breakpoint
:
3695 case bp_longjmp_resume
:
3696 case bp_step_resume
:
3697 case bp_watchpoint_scope
:
3699 case bp_shlib_event
:
3700 case bp_thread_event
:
3701 case bp_overlay_event
:
3705 if (header_of_multiple
)
3706 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3707 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3708 ui_out_field_string (uiout
, "addr", "<PENDING>");
3710 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3713 if (!header_of_multiple
)
3714 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3716 *last_addr
= b
->loc
->address
;
3720 if (!part_of_multiple
&& b
->thread
!= -1)
3722 /* FIXME: This seems to be redundant and lost here; see the
3723 "stop only in" line a little further down. */
3724 ui_out_text (uiout
, " thread ");
3725 ui_out_field_int (uiout
, "thread", b
->thread
);
3728 ui_out_text (uiout
, "\n");
3730 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3733 ui_out_text (uiout
, "\tstop only in stack frame at ");
3734 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3736 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3737 ui_out_text (uiout
, "\n");
3740 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3742 /* We do not print the condition for Ada exception catchpoints
3743 because the condition is an internal implementation detail
3744 that we do not want to expose to the user. */
3746 ui_out_text (uiout
, "\tstop only if ");
3747 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3748 ui_out_text (uiout
, "\n");
3751 if (!part_of_multiple
&& b
->thread
!= -1)
3753 /* FIXME should make an annotation for this */
3754 ui_out_text (uiout
, "\tstop only in thread ");
3755 ui_out_field_int (uiout
, "thread", b
->thread
);
3756 ui_out_text (uiout
, "\n");
3759 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3761 /* FIXME should make an annotation for this */
3762 if (ep_is_catchpoint (b
))
3763 ui_out_text (uiout
, "\tcatchpoint");
3765 ui_out_text (uiout
, "\tbreakpoint");
3766 ui_out_text (uiout
, " already hit ");
3767 ui_out_field_int (uiout
, "times", b
->hit_count
);
3768 if (b
->hit_count
== 1)
3769 ui_out_text (uiout
, " time\n");
3771 ui_out_text (uiout
, " times\n");
3774 /* Output the count also if it is zero, but only if this is
3775 mi. FIXME: Should have a better test for this. */
3776 if (ui_out_is_mi_like_p (uiout
))
3777 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3778 ui_out_field_int (uiout
, "times", b
->hit_count
);
3780 if (!part_of_multiple
&& b
->ignore_count
)
3783 ui_out_text (uiout
, "\tignore next ");
3784 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3785 ui_out_text (uiout
, " hits\n");
3788 if (!part_of_multiple
&& (l
= b
->commands
))
3790 struct cleanup
*script_chain
;
3793 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3794 print_command_lines (uiout
, l
, 4);
3795 do_cleanups (script_chain
);
3798 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3801 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3802 else if (b
->exp_string
)
3803 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3806 do_cleanups (bkpt_chain
);
3807 do_cleanups (old_chain
);
3811 print_one_breakpoint (struct breakpoint
*b
,
3812 CORE_ADDR
*last_addr
)
3814 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3816 /* If this breakpoint has custom print function,
3817 it's already printed. Otherwise, print individual
3818 locations, if any. */
3819 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3821 /* If breakpoint has a single location that is
3822 disabled, we print it as if it had
3823 several locations, since otherwise it's hard to
3824 represent "breakpoint enabled, location disabled"
3826 Note that while hardware watchpoints have
3827 several locations internally, that's no a property
3830 && !is_hardware_watchpoint (b
)
3831 && (b
->loc
->next
|| !b
->loc
->enabled
)
3832 && !ui_out_is_mi_like_p (uiout
))
3834 struct bp_location
*loc
;
3836 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3837 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3843 struct captured_breakpoint_query_args
3849 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3851 struct captured_breakpoint_query_args
*args
= data
;
3852 struct breakpoint
*b
;
3853 CORE_ADDR dummy_addr
= 0;
3856 if (args
->bnum
== b
->number
)
3858 print_one_breakpoint (b
, &dummy_addr
);
3866 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3868 struct captured_breakpoint_query_args args
;
3870 /* For the moment we don't trust print_one_breakpoint() to not throw
3872 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3873 error_message
, RETURN_MASK_ALL
) < 0)
3879 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3880 catchpoints, et.al.). */
3883 user_settable_breakpoint (const struct breakpoint
*b
)
3885 return (b
->type
== bp_breakpoint
3886 || b
->type
== bp_catch_load
3887 || b
->type
== bp_catch_unload
3888 || b
->type
== bp_catch_fork
3889 || b
->type
== bp_catch_vfork
3890 || b
->type
== bp_catch_exec
3891 || b
->type
== bp_hardware_breakpoint
3892 || b
->type
== bp_watchpoint
3893 || b
->type
== bp_read_watchpoint
3894 || b
->type
== bp_access_watchpoint
3895 || b
->type
== bp_hardware_watchpoint
);
3898 /* Print information on user settable breakpoint (watchpoint, etc)
3899 number BNUM. If BNUM is -1 print all user settable breakpoints.
3900 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3903 breakpoint_1 (int bnum
, int allflag
)
3905 struct breakpoint
*b
;
3906 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3907 int nr_printable_breakpoints
;
3908 struct cleanup
*bkpttbl_chain
;
3910 /* Compute the number of rows in the table. */
3911 nr_printable_breakpoints
= 0;
3914 || bnum
== b
->number
)
3916 if (allflag
|| user_settable_breakpoint (b
))
3917 nr_printable_breakpoints
++;
3922 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3926 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3929 if (nr_printable_breakpoints
> 0)
3930 annotate_breakpoints_headers ();
3931 if (nr_printable_breakpoints
> 0)
3933 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3934 if (nr_printable_breakpoints
> 0)
3936 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3937 if (nr_printable_breakpoints
> 0)
3939 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3940 if (nr_printable_breakpoints
> 0)
3942 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3945 if (nr_printable_breakpoints
> 0)
3947 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3948 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3950 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3952 if (nr_printable_breakpoints
> 0)
3954 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3955 ui_out_table_body (uiout
);
3956 if (nr_printable_breakpoints
> 0)
3957 annotate_breakpoints_table ();
3961 || bnum
== b
->number
)
3963 /* We only print out user settable breakpoints unless the
3965 if (allflag
|| user_settable_breakpoint (b
))
3966 print_one_breakpoint (b
, &last_addr
);
3969 do_cleanups (bkpttbl_chain
);
3971 if (nr_printable_breakpoints
== 0)
3974 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3976 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3981 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3982 that a comparison of an unsigned with -1 is always false. */
3983 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3984 set_next_address (last_addr
);
3987 /* FIXME? Should this be moved up so that it is only called when
3988 there have been breakpoints? */
3989 annotate_breakpoints_table_end ();
3993 breakpoints_info (char *bnum_exp
, int from_tty
)
3998 bnum
= parse_and_eval_long (bnum_exp
);
4000 breakpoint_1 (bnum
, 0);
4004 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4009 bnum
= parse_and_eval_long (bnum_exp
);
4011 breakpoint_1 (bnum
, 1);
4015 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4017 struct bp_location
*bl
= b
->loc
;
4018 for (; bl
; bl
= bl
->next
)
4020 if (bl
->address
== pc
4021 && (!overlay_debugging
|| bl
->section
== section
))
4027 /* Print a message describing any breakpoints set at PC. */
4030 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4033 struct breakpoint
*b
;
4036 others
+= breakpoint_has_pc (b
, pc
, section
);
4040 printf_filtered (_("Note: breakpoint "));
4041 else /* if (others == ???) */
4042 printf_filtered (_("Note: breakpoints "));
4044 if (breakpoint_has_pc (b
, pc
, section
))
4047 printf_filtered ("%d", b
->number
);
4048 if (b
->thread
== -1 && thread
!= -1)
4049 printf_filtered (" (all threads)");
4050 else if (b
->thread
!= -1)
4051 printf_filtered (" (thread %d)", b
->thread
);
4052 printf_filtered ("%s%s ",
4053 ((b
->enable_state
== bp_disabled
||
4054 b
->enable_state
== bp_call_disabled
)
4056 : b
->enable_state
== bp_permanent
4060 : ((others
== 1) ? " and" : ""));
4062 printf_filtered (_("also set at pc "));
4063 fputs_filtered (paddress (pc
), gdb_stdout
);
4064 printf_filtered (".\n");
4068 /* Set the default place to put a breakpoint
4069 for the `break' command with no arguments. */
4072 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4075 default_breakpoint_valid
= valid
;
4076 default_breakpoint_address
= addr
;
4077 default_breakpoint_symtab
= symtab
;
4078 default_breakpoint_line
= line
;
4081 /* Return true iff it is meaningful to use the address member of
4082 BPT. For some breakpoint types, the address member is irrelevant
4083 and it makes no sense to attempt to compare it to other addresses
4084 (or use it for any other purpose either).
4086 More specifically, each of the following breakpoint types will always
4087 have a zero valued address and we don't want check_duplicates() to mark
4088 breakpoints of any of these types to be a duplicate of an actual
4089 breakpoint at address zero:
4092 bp_hardware_watchpoint
4094 bp_access_watchpoint
4101 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4103 enum bptype type
= bpt
->type
;
4105 return (type
!= bp_watchpoint
4106 && type
!= bp_hardware_watchpoint
4107 && type
!= bp_read_watchpoint
4108 && type
!= bp_access_watchpoint
4109 && type
!= bp_catch_exec
4110 && type
!= bp_longjmp_resume
4111 && type
!= bp_catch_fork
4112 && type
!= bp_catch_vfork
);
4115 /* Rescan breakpoints at the same address and section as BPT,
4116 marking the first one as "first" and any others as "duplicates".
4117 This is so that the bpt instruction is only inserted once.
4118 If we have a permanent breakpoint at the same place as BPT, make
4119 that one the official one, and the rest as duplicates. */
4122 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4124 struct bp_location
*b
;
4126 struct bp_location
*perm_bp
= 0;
4128 ALL_BP_LOCATIONS (b
)
4129 if (b
->owner
->enable_state
!= bp_disabled
4130 && b
->owner
->enable_state
!= bp_call_disabled
4132 && !b
->shlib_disabled
4133 && b
->address
== address
/* address / overlay match */
4134 && (!overlay_debugging
|| b
->section
== section
)
4135 && breakpoint_address_is_meaningful (b
->owner
))
4137 /* Have we found a permanent breakpoint? */
4138 if (b
->owner
->enable_state
== bp_permanent
)
4145 b
->duplicate
= count
> 1;
4148 /* If we found a permanent breakpoint at this address, go over the
4149 list again and declare all the other breakpoints there to be the
4153 perm_bp
->duplicate
= 0;
4155 /* Permanent breakpoint should always be inserted. */
4156 if (! perm_bp
->inserted
)
4157 internal_error (__FILE__
, __LINE__
,
4158 _("allegedly permanent breakpoint is not "
4159 "actually inserted"));
4161 ALL_BP_LOCATIONS (b
)
4164 if (b
->owner
->enable_state
!= bp_disabled
4165 && b
->owner
->enable_state
!= bp_call_disabled
4166 && b
->enabled
&& !b
->shlib_disabled
4167 && b
->address
== address
/* address / overlay match */
4168 && (!overlay_debugging
|| b
->section
== section
)
4169 && breakpoint_address_is_meaningful (b
->owner
))
4172 internal_error (__FILE__
, __LINE__
,
4173 _("another breakpoint was inserted on top of "
4174 "a permanent breakpoint"));
4183 check_duplicates (struct breakpoint
*bpt
)
4185 struct bp_location
*bl
= bpt
->loc
;
4187 if (! breakpoint_address_is_meaningful (bpt
))
4190 for (; bl
; bl
= bl
->next
)
4191 check_duplicates_for (bl
->address
, bl
->section
);
4195 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4196 int bnum
, int have_bnum
)
4201 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4202 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4204 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4205 bnum
, astr1
, astr2
);
4207 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4210 /* Adjust a breakpoint's address to account for architectural constraints
4211 on breakpoint placement. Return the adjusted address. Note: Very
4212 few targets require this kind of adjustment. For most targets,
4213 this function is simply the identity function. */
4216 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4218 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4220 /* Very few targets need any kind of breakpoint adjustment. */
4223 else if (bptype
== bp_watchpoint
4224 || bptype
== bp_hardware_watchpoint
4225 || bptype
== bp_read_watchpoint
4226 || bptype
== bp_access_watchpoint
4227 || bptype
== bp_catch_fork
4228 || bptype
== bp_catch_vfork
4229 || bptype
== bp_catch_exec
)
4231 /* Watchpoints and the various bp_catch_* eventpoints should not
4232 have their addresses modified. */
4237 CORE_ADDR adjusted_bpaddr
;
4239 /* Some targets have architectural constraints on the placement
4240 of breakpoint instructions. Obtain the adjusted address. */
4241 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4244 /* An adjusted breakpoint address can significantly alter
4245 a user's expectations. Print a warning if an adjustment
4247 if (adjusted_bpaddr
!= bpaddr
)
4248 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4250 return adjusted_bpaddr
;
4254 /* Allocate a struct bp_location. */
4256 static struct bp_location
*
4257 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4259 struct bp_location
*loc
, *loc_p
;
4261 loc
= xmalloc (sizeof (struct bp_location
));
4262 memset (loc
, 0, sizeof (*loc
));
4266 loc
->shlib_disabled
= 0;
4275 case bp_longjmp_resume
:
4276 case bp_step_resume
:
4277 case bp_watchpoint_scope
:
4279 case bp_shlib_event
:
4280 case bp_thread_event
:
4281 case bp_overlay_event
:
4283 case bp_catch_unload
:
4284 loc
->loc_type
= bp_loc_software_breakpoint
;
4286 case bp_hardware_breakpoint
:
4287 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4289 case bp_hardware_watchpoint
:
4290 case bp_read_watchpoint
:
4291 case bp_access_watchpoint
:
4292 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4296 case bp_catch_vfork
:
4298 loc
->loc_type
= bp_loc_other
;
4301 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4307 static void free_bp_location (struct bp_location
*loc
)
4312 if (loc
->function_name
)
4313 xfree (loc
->function_name
);
4318 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4319 that has type BPTYPE and has no locations as yet. */
4321 static struct breakpoint
*
4322 set_raw_breakpoint_without_location (enum bptype bptype
)
4324 struct breakpoint
*b
, *b1
;
4326 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4327 memset (b
, 0, sizeof (*b
));
4330 b
->language
= current_language
->la_language
;
4331 b
->input_radix
= input_radix
;
4333 b
->enable_state
= bp_enabled
;
4336 b
->ignore_count
= 0;
4338 b
->frame_id
= null_frame_id
;
4339 b
->dll_pathname
= NULL
;
4340 b
->triggered_dll_pathname
= NULL
;
4341 b
->forked_inferior_pid
= 0;
4342 b
->exec_pathname
= NULL
;
4344 b
->condition_not_parsed
= 0;
4346 /* Add this breakpoint to the end of the chain
4347 so that a list of breakpoints will come out in order
4348 of increasing numbers. */
4350 b1
= breakpoint_chain
;
4352 breakpoint_chain
= b
;
4362 /* Initialize loc->function_name. */
4364 set_breakpoint_location_function (struct bp_location
*loc
)
4366 if (loc
->owner
->type
== bp_breakpoint
4367 || loc
->owner
->type
== bp_hardware_breakpoint
)
4369 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4371 if (loc
->function_name
)
4372 loc
->function_name
= xstrdup (loc
->function_name
);
4376 /* set_raw_breakpoint is a low level routine for allocating and
4377 partially initializing a breakpoint of type BPTYPE. The newly
4378 created breakpoint's address, section, source file name, and line
4379 number are provided by SAL. The newly created and partially
4380 initialized breakpoint is added to the breakpoint chain and
4381 is also returned as the value of this function.
4383 It is expected that the caller will complete the initialization of
4384 the newly created breakpoint struct as well as output any status
4385 information regarding the creation of a new breakpoint. In
4386 particular, set_raw_breakpoint does NOT set the breakpoint
4387 number! Care should be taken to not allow an error to occur
4388 prior to completing the initialization of the breakpoint. If this
4389 should happen, a bogus breakpoint will be left on the chain. */
4392 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4394 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4395 CORE_ADDR adjusted_address
;
4397 /* Adjust the breakpoint's address prior to allocating a location.
4398 Once we call allocate_bp_location(), that mostly uninitialized
4399 location will be placed on the location chain. Adjustment of the
4400 breakpoint may cause target_read_memory() to be called and we do
4401 not want its scan of the location chain to find a breakpoint and
4402 location that's only been partially initialized. */
4403 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4405 b
->loc
= allocate_bp_location (b
, bptype
);
4406 b
->loc
->requested_address
= sal
.pc
;
4407 b
->loc
->address
= adjusted_address
;
4409 if (sal
.symtab
== NULL
)
4410 b
->source_file
= NULL
;
4412 b
->source_file
= savestring (sal
.symtab
->filename
,
4413 strlen (sal
.symtab
->filename
));
4414 b
->loc
->section
= sal
.section
;
4415 b
->line_number
= sal
.line
;
4417 set_breakpoint_location_function (b
->loc
);
4419 breakpoints_changed ();
4425 /* Note that the breakpoint object B describes a permanent breakpoint
4426 instruction, hard-wired into the inferior's code. */
4428 make_breakpoint_permanent (struct breakpoint
*b
)
4430 struct bp_location
*bl
;
4431 b
->enable_state
= bp_permanent
;
4433 /* By definition, permanent breakpoints are already present in the code.
4434 Mark all locations as inserted. For now, make_breakpoint_permanent
4435 is called in just one place, so it's hard to say if it's reasonable
4436 to have permanent breakpoint with multiple locations or not,
4437 but it's easy to implmement. */
4438 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4442 static struct breakpoint
*
4443 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4445 static int internal_breakpoint_number
= -1;
4446 struct symtab_and_line sal
;
4447 struct breakpoint
*b
;
4449 init_sal (&sal
); /* initialize to zeroes */
4452 sal
.section
= find_pc_overlay (sal
.pc
);
4454 b
= set_raw_breakpoint (sal
, type
);
4455 b
->number
= internal_breakpoint_number
--;
4456 b
->disposition
= disp_donttouch
;
4463 create_longjmp_breakpoint (char *func_name
)
4465 struct breakpoint
*b
;
4466 struct minimal_symbol
*m
;
4468 if (func_name
== NULL
)
4469 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4472 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4475 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4478 b
->enable_state
= bp_disabled
;
4481 b
->addr_string
= xstrdup (func_name
);
4482 update_global_location_list ();
4485 /* Call this routine when stepping and nexting to enable a breakpoint
4486 if we do a longjmp(). When we hit that breakpoint, call
4487 set_longjmp_resume_breakpoint() to figure out where we are going. */
4490 enable_longjmp_breakpoint (void)
4492 struct breakpoint
*b
;
4495 if (b
->type
== bp_longjmp
)
4497 b
->enable_state
= bp_enabled
;
4498 update_global_location_list ();
4503 disable_longjmp_breakpoint (void)
4505 struct breakpoint
*b
;
4508 if (b
->type
== bp_longjmp
4509 || b
->type
== bp_longjmp_resume
)
4511 b
->enable_state
= bp_disabled
;
4512 update_global_location_list ();
4517 create_overlay_event_breakpoint (char *func_name
)
4519 struct breakpoint
*b
;
4520 struct minimal_symbol
*m
;
4522 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4525 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4527 b
->addr_string
= xstrdup (func_name
);
4529 if (overlay_debugging
== ovly_auto
)
4531 b
->enable_state
= bp_enabled
;
4532 overlay_events_enabled
= 1;
4536 b
->enable_state
= bp_disabled
;
4537 overlay_events_enabled
= 0;
4539 update_global_location_list ();
4543 enable_overlay_breakpoints (void)
4545 struct breakpoint
*b
;
4548 if (b
->type
== bp_overlay_event
)
4550 b
->enable_state
= bp_enabled
;
4551 update_global_location_list ();
4552 overlay_events_enabled
= 1;
4557 disable_overlay_breakpoints (void)
4559 struct breakpoint
*b
;
4562 if (b
->type
== bp_overlay_event
)
4564 b
->enable_state
= bp_disabled
;
4565 update_global_location_list ();
4566 overlay_events_enabled
= 0;
4571 create_thread_event_breakpoint (CORE_ADDR address
)
4573 struct breakpoint
*b
;
4575 b
= create_internal_breakpoint (address
, bp_thread_event
);
4577 b
->enable_state
= bp_enabled
;
4578 /* addr_string has to be used or breakpoint_re_set will delete me. */
4579 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4581 update_global_location_list_nothrow ();
4587 remove_thread_event_breakpoints (void)
4589 struct breakpoint
*b
, *temp
;
4591 ALL_BREAKPOINTS_SAFE (b
, temp
)
4592 if (b
->type
== bp_thread_event
)
4593 delete_breakpoint (b
);
4596 struct captured_parse_breakpoint_args
4599 struct symtabs_and_lines
*sals_p
;
4600 char ***addr_string_p
;
4604 struct lang_and_radix
4612 remove_solib_event_breakpoints (void)
4614 struct breakpoint
*b
, *temp
;
4616 ALL_BREAKPOINTS_SAFE (b
, temp
)
4617 if (b
->type
== bp_shlib_event
)
4618 delete_breakpoint (b
);
4622 create_solib_event_breakpoint (CORE_ADDR address
)
4624 struct breakpoint
*b
;
4626 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4627 update_global_location_list_nothrow ();
4631 /* Disable any breakpoints that are on code in shared libraries. Only
4632 apply to enabled breakpoints, disabled ones can just stay disabled. */
4635 disable_breakpoints_in_shlibs (void)
4637 struct bp_location
*loc
;
4638 int disabled_shlib_breaks
= 0;
4640 ALL_BP_LOCATIONS (loc
)
4642 struct breakpoint
*b
= loc
->owner
;
4643 /* We apply the check to all breakpoints, including disabled
4644 for those with loc->duplicate set. This is so that when breakpoint
4645 becomes enabled, or the duplicate is removed, gdb will try to insert
4646 all breakpoints. If we don't set shlib_disabled here, we'll try
4647 to insert those breakpoints and fail. */
4648 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4649 && !loc
->shlib_disabled
4651 && PC_SOLIB (loc
->address
)
4653 && solib_address (loc
->address
)
4657 loc
->shlib_disabled
= 1;
4662 /* Disable any breakpoints that are in in an unloaded shared library. Only
4663 apply to enabled breakpoints, disabled ones can just stay disabled. */
4666 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4668 struct bp_location
*loc
;
4669 int disabled_shlib_breaks
= 0;
4671 ALL_BP_LOCATIONS (loc
)
4673 struct breakpoint
*b
= loc
->owner
;
4674 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4675 || loc
->loc_type
== bp_loc_software_breakpoint
)
4676 && !loc
->shlib_disabled
)
4679 char *so_name
= PC_SOLIB (loc
->address
);
4681 char *so_name
= solib_address (loc
->address
);
4683 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4685 loc
->shlib_disabled
= 1;
4686 /* At this point, we cannot rely on remove_breakpoint
4687 succeeding so we must mark the breakpoint as not inserted
4688 to prevent future errors occurring in remove_breakpoints. */
4690 if (!disabled_shlib_breaks
)
4692 target_terminal_ours_for_output ();
4693 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4696 disabled_shlib_breaks
= 1;
4703 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4704 enum bptype bp_kind
)
4706 struct symtab_and_line sal
;
4707 struct breakpoint
*b
;
4708 int thread
= -1; /* All threads. */
4715 b
= set_raw_breakpoint (sal
, bp_kind
);
4716 set_breakpoint_count (breakpoint_count
+ 1);
4717 b
->number
= breakpoint_count
;
4718 b
->cond_string
= (cond_string
== NULL
) ?
4719 NULL
: savestring (cond_string
, strlen (cond_string
));
4721 b
->addr_string
= NULL
;
4722 b
->enable_state
= bp_enabled
;
4723 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4724 b
->forked_inferior_pid
= 0;
4725 update_global_location_list ();
4732 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4734 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4738 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4740 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4744 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4746 struct symtab_and_line sal
;
4747 struct breakpoint
*b
;
4748 int thread
= -1; /* All threads. */
4755 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4756 set_breakpoint_count (breakpoint_count
+ 1);
4757 b
->number
= breakpoint_count
;
4758 b
->cond_string
= (cond_string
== NULL
) ?
4759 NULL
: savestring (cond_string
, strlen (cond_string
));
4761 b
->addr_string
= NULL
;
4762 b
->enable_state
= bp_enabled
;
4763 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4764 update_global_location_list ();
4770 hw_breakpoint_used_count (void)
4772 struct breakpoint
*b
;
4777 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4785 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4787 struct breakpoint
*b
;
4790 *other_type_used
= 0;
4793 if (breakpoint_enabled (b
))
4795 if (b
->type
== type
)
4797 else if ((b
->type
== bp_hardware_watchpoint
||
4798 b
->type
== bp_read_watchpoint
||
4799 b
->type
== bp_access_watchpoint
))
4800 *other_type_used
= 1;
4806 /* Call this after hitting the longjmp() breakpoint. Use this to set
4807 a new breakpoint at the target of the jmp_buf.
4809 FIXME - This ought to be done by setting a temporary breakpoint
4810 that gets deleted automatically... */
4813 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4815 struct breakpoint
*b
;
4818 if (b
->type
== bp_longjmp_resume
)
4820 b
->loc
->requested_address
= pc
;
4821 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4823 b
->enable_state
= bp_enabled
;
4824 b
->frame_id
= frame_id
;
4825 update_global_location_list ();
4831 disable_watchpoints_before_interactive_call_start (void)
4833 struct breakpoint
*b
;
4837 if (((b
->type
== bp_watchpoint
)
4838 || (b
->type
== bp_hardware_watchpoint
)
4839 || (b
->type
== bp_read_watchpoint
)
4840 || (b
->type
== bp_access_watchpoint
))
4841 && breakpoint_enabled (b
))
4843 b
->enable_state
= bp_call_disabled
;
4844 update_global_location_list ();
4850 enable_watchpoints_after_interactive_call_stop (void)
4852 struct breakpoint
*b
;
4856 if (((b
->type
== bp_watchpoint
)
4857 || (b
->type
== bp_hardware_watchpoint
)
4858 || (b
->type
== bp_read_watchpoint
)
4859 || (b
->type
== bp_access_watchpoint
))
4860 && (b
->enable_state
== bp_call_disabled
))
4862 b
->enable_state
= bp_enabled
;
4863 update_global_location_list ();
4869 /* Set a breakpoint that will evaporate an end of command
4870 at address specified by SAL.
4871 Restrict it to frame FRAME if FRAME is nonzero. */
4874 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4877 struct breakpoint
*b
;
4878 b
= set_raw_breakpoint (sal
, type
);
4879 b
->enable_state
= bp_enabled
;
4880 b
->disposition
= disp_donttouch
;
4881 b
->frame_id
= frame_id
;
4883 /* If we're debugging a multi-threaded program, then we
4884 want momentary breakpoints to be active in only a
4885 single thread of control. */
4886 if (in_thread_list (inferior_ptid
))
4887 b
->thread
= pid_to_thread_id (inferior_ptid
);
4889 update_global_location_list_nothrow ();
4895 /* Tell the user we have just set a breakpoint B. */
4898 mention (struct breakpoint
*b
)
4901 struct cleanup
*old_chain
, *ui_out_chain
;
4902 struct ui_stream
*stb
;
4904 stb
= ui_out_stream_new (uiout
);
4905 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4907 /* FIXME: This is misplaced; mention() is called by things (like
4908 hitting a watchpoint) other than breakpoint creation. It should
4909 be possible to clean this up and at the same time replace the
4910 random calls to breakpoint_changed with this hook, as has already
4911 been done for deprecated_delete_breakpoint_hook and so on. */
4912 if (deprecated_create_breakpoint_hook
)
4913 deprecated_create_breakpoint_hook (b
);
4914 breakpoint_create_event (b
->number
);
4916 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4917 b
->ops
->print_mention (b
);
4922 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4925 ui_out_text (uiout
, "Watchpoint ");
4926 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4927 ui_out_field_int (uiout
, "number", b
->number
);
4928 ui_out_text (uiout
, ": ");
4929 print_expression (b
->exp
, stb
->stream
);
4930 ui_out_field_stream (uiout
, "exp", stb
);
4931 do_cleanups (ui_out_chain
);
4933 case bp_hardware_watchpoint
:
4934 ui_out_text (uiout
, "Hardware watchpoint ");
4935 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4936 ui_out_field_int (uiout
, "number", b
->number
);
4937 ui_out_text (uiout
, ": ");
4938 print_expression (b
->exp
, stb
->stream
);
4939 ui_out_field_stream (uiout
, "exp", stb
);
4940 do_cleanups (ui_out_chain
);
4942 case bp_read_watchpoint
:
4943 ui_out_text (uiout
, "Hardware read watchpoint ");
4944 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4945 ui_out_field_int (uiout
, "number", b
->number
);
4946 ui_out_text (uiout
, ": ");
4947 print_expression (b
->exp
, stb
->stream
);
4948 ui_out_field_stream (uiout
, "exp", stb
);
4949 do_cleanups (ui_out_chain
);
4951 case bp_access_watchpoint
:
4952 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4953 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4954 ui_out_field_int (uiout
, "number", b
->number
);
4955 ui_out_text (uiout
, ": ");
4956 print_expression (b
->exp
, stb
->stream
);
4957 ui_out_field_stream (uiout
, "exp", stb
);
4958 do_cleanups (ui_out_chain
);
4961 if (ui_out_is_mi_like_p (uiout
))
4966 if (b
->disposition
== disp_del
)
4967 printf_filtered (_("Temporary breakpoint"));
4969 printf_filtered (_("Breakpoint"));
4970 printf_filtered (_(" %d"), b
->number
);
4973 case bp_hardware_breakpoint
:
4974 if (ui_out_is_mi_like_p (uiout
))
4979 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4983 case bp_catch_unload
:
4984 printf_filtered (_("Catchpoint %d (%s %s)"),
4986 (b
->type
== bp_catch_load
) ? "load" : "unload",
4987 (b
->dll_pathname
!= NULL
) ?
4988 b
->dll_pathname
: "<any library>");
4991 case bp_catch_vfork
:
4992 printf_filtered (_("Catchpoint %d (%s)"),
4994 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4997 printf_filtered (_("Catchpoint %d (exec)"),
5004 case bp_longjmp_resume
:
5005 case bp_step_resume
:
5007 case bp_watchpoint_scope
:
5008 case bp_shlib_event
:
5009 case bp_thread_event
:
5010 case bp_overlay_event
:
5016 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5020 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5024 if (addressprint
|| b
->source_file
== NULL
)
5026 printf_filtered (" at ");
5027 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5030 printf_filtered (": file %s, line %d.",
5031 b
->source_file
, b
->line_number
);
5035 struct bp_location
*loc
= b
->loc
;
5037 for (; loc
; loc
= loc
->next
)
5039 printf_filtered (" (%d locations)", n
);
5044 do_cleanups (old_chain
);
5045 if (ui_out_is_mi_like_p (uiout
))
5047 printf_filtered ("\n");
5051 static struct bp_location
*
5052 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5053 const struct symtab_and_line
*sal
)
5055 struct bp_location
*loc
, **tmp
;
5057 loc
= allocate_bp_location (b
, bptype
);
5058 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5061 loc
->requested_address
= sal
->pc
;
5062 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5064 loc
->section
= sal
->section
;
5066 set_breakpoint_location_function (loc
);
5070 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5071 as textual description of the location, and COND_STRING
5072 as condition expression. */
5075 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5077 enum bptype type
, enum bpdisp disposition
,
5078 int thread
, int ignore_count
, int from_tty
)
5080 struct breakpoint
*b
= NULL
;
5083 if (type
== bp_hardware_breakpoint
)
5085 int i
= hw_breakpoint_used_count ();
5086 int target_resources_ok
=
5087 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5089 if (target_resources_ok
== 0)
5090 error (_("No hardware breakpoint support in the target."));
5091 else if (target_resources_ok
< 0)
5092 error (_("Hardware breakpoints used exceeds limit."));
5095 for (i
= 0; i
< sals
.nelts
; ++i
)
5097 struct symtab_and_line sal
= sals
.sals
[i
];
5098 struct bp_location
*loc
;
5101 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5105 b
= set_raw_breakpoint (sal
, type
);
5106 set_breakpoint_count (breakpoint_count
+ 1);
5107 b
->number
= breakpoint_count
;
5110 b
->cond_string
= cond_string
;
5111 b
->ignore_count
= ignore_count
;
5112 b
->enable_state
= bp_enabled
;
5113 b
->disposition
= disposition
;
5119 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5124 char *arg
= b
->cond_string
;
5125 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5127 error (_("Garbage %s follows condition"), arg
);
5132 b
->addr_string
= addr_string
;
5134 /* addr_string has to be used or breakpoint_re_set will delete
5136 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5141 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5142 elements to fill the void space. */
5143 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5145 int i
= index_to_remove
+1;
5146 int last_index
= sal
->nelts
-1;
5148 for (;i
<= last_index
; ++i
)
5149 sal
->sals
[i
-1] = sal
->sals
[i
];
5154 /* If appropriate, obtains all sals that correspond
5155 to the same file and line as SAL. This is done
5156 only if SAL does not have explicit PC and has
5157 line and file information. If we got just a single
5158 expanded sal, return the original.
5160 Otherwise, if SAL.explicit_line is not set, filter out
5161 all sals for which the name of enclosing function
5162 is different from SAL. This makes sure that if we have
5163 breakpoint originally set in template instantiation, say
5164 foo<int>(), we won't expand SAL to locations at the same
5165 line in all existing instantiations of 'foo'.
5168 struct symtabs_and_lines
5169 expand_line_sal_maybe (struct symtab_and_line sal
)
5171 struct symtabs_and_lines expanded
;
5172 CORE_ADDR original_pc
= sal
.pc
;
5173 char *original_function
= NULL
;
5177 /* If we have explicit pc, don't expand.
5178 If we have no line number, we can't expand. */
5179 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5182 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5183 expanded
.sals
[0] = sal
;
5188 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5190 expanded
= expand_line_sal (sal
);
5191 if (expanded
.nelts
== 1)
5193 /* We had one sal, we got one sal. Without futher
5194 processing, just return the original sal. */
5195 xfree (expanded
.sals
);
5197 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5198 sal
.pc
= original_pc
;
5199 expanded
.sals
[0] = sal
;
5203 if (!sal
.explicit_line
)
5205 CORE_ADDR func_addr
, func_end
;
5206 for (i
= 0; i
< expanded
.nelts
; ++i
)
5208 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5209 char *this_function
;
5210 if (find_pc_partial_function (pc
, &this_function
,
5211 &func_addr
, &func_end
))
5213 if (this_function
&&
5214 strcmp (this_function
, original_function
) != 0)
5216 remove_sal (&expanded
, i
);
5219 else if (func_addr
== pc
)
5221 /* We're at beginning of a function, and should
5223 struct symbol
*sym
= find_pc_function (pc
);
5225 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5228 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5235 if (expanded
.nelts
<= 1)
5237 /* This is un ugly workaround. If we get zero
5238 expanded sals then something is really wrong.
5239 Fix that by returnign the original sal. */
5240 xfree (expanded
.sals
);
5242 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5243 sal
.pc
= original_pc
;
5244 expanded
.sals
[0] = sal
;
5251 for (i
= 0; i
< expanded
.nelts
; ++i
)
5252 if (expanded
.sals
[i
].pc
== original_pc
)
5263 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5264 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5265 value. COND_STRING, if not NULL, specified the condition to be
5266 used for all breakpoints. Essentially the only case where
5267 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5268 function. In that case, it's still not possible to specify
5269 separate conditions for different overloaded functions, so
5270 we take just a single condition string.
5272 NOTE: If the function succeeds, the caller is expected to cleanup
5273 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5274 array contents). If the function fails (error() is called), the
5275 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5276 COND and SALS arrays and each of those arrays contents. */
5279 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5281 enum bptype type
, enum bpdisp disposition
,
5282 int thread
, int ignore_count
, int from_tty
)
5285 for (i
= 0; i
< sals
.nelts
; ++i
)
5287 struct symtabs_and_lines expanded
=
5288 expand_line_sal_maybe (sals
.sals
[i
]);
5290 create_breakpoint (expanded
, addr_string
[i
],
5291 cond_string
, type
, disposition
,
5292 thread
, ignore_count
, from_tty
);
5295 update_global_location_list ();
5298 /* Parse ARG which is assumed to be a SAL specification possibly
5299 followed by conditionals. On return, SALS contains an array of SAL
5300 addresses found. ADDR_STRING contains a vector of (canonical)
5301 address strings. ARG points to the end of the SAL. */
5304 parse_breakpoint_sals (char **address
,
5305 struct symtabs_and_lines
*sals
,
5306 char ***addr_string
,
5309 char *addr_start
= *address
;
5310 *addr_string
= NULL
;
5311 /* If no arg given, or if first arg is 'if ', use the default
5313 if ((*address
) == NULL
5314 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5316 if (default_breakpoint_valid
)
5318 struct symtab_and_line sal
;
5319 init_sal (&sal
); /* initialize to zeroes */
5320 sals
->sals
= (struct symtab_and_line
*)
5321 xmalloc (sizeof (struct symtab_and_line
));
5322 sal
.pc
= default_breakpoint_address
;
5323 sal
.line
= default_breakpoint_line
;
5324 sal
.symtab
= default_breakpoint_symtab
;
5325 sal
.section
= find_pc_overlay (sal
.pc
);
5326 sals
->sals
[0] = sal
;
5330 error (_("No default breakpoint address now."));
5334 /* Force almost all breakpoints to be in terms of the
5335 current_source_symtab (which is decode_line_1's default). This
5336 should produce the results we want almost all of the time while
5337 leaving default_breakpoint_* alone.
5338 ObjC: However, don't match an Objective-C method name which
5339 may have a '+' or '-' succeeded by a '[' */
5341 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5343 if (default_breakpoint_valid
5345 || ((strchr ("+-", (*address
)[0]) != NULL
)
5346 && ((*address
)[1] != '['))))
5347 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5348 default_breakpoint_line
, addr_string
,
5351 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5352 addr_string
, not_found_ptr
);
5354 /* For any SAL that didn't have a canonical string, fill one in. */
5355 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5356 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5357 if (addr_start
!= (*address
))
5360 for (i
= 0; i
< sals
->nelts
; i
++)
5362 /* Add the string if not present. */
5363 if ((*addr_string
)[i
] == NULL
)
5364 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5370 /* Convert each SAL into a real PC. Verify that the PC can be
5371 inserted as a breakpoint. If it can't throw an error. */
5374 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5378 for (i
= 0; i
< sals
->nelts
; i
++)
5379 resolve_sal_pc (&sals
->sals
[i
]);
5383 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5385 struct captured_parse_breakpoint_args
*args
= data
;
5387 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5388 args
->not_found_ptr
);
5391 /* Given TOK, a string specification of condition and thread, as
5392 accepted by the 'break' command, extract the condition
5393 string and thread number and set *COND_STRING and *THREAD.
5394 PC identifies the context at which the condition should be parsed.
5395 If no condition is found, *COND_STRING is set to NULL.
5396 If no thread is found, *THREAD is set to -1. */
5398 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5399 char **cond_string
, int *thread
)
5401 *cond_string
= NULL
;
5407 char *cond_start
= NULL
;
5408 char *cond_end
= NULL
;
5409 while (*tok
== ' ' || *tok
== '\t')
5414 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5417 toklen
= end_tok
- tok
;
5419 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5421 tok
= cond_start
= end_tok
+ 1;
5422 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5424 *cond_string
= savestring (cond_start
,
5425 cond_end
- cond_start
);
5427 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5433 *thread
= strtol (tok
, &tok
, 0);
5435 error (_("Junk after thread keyword."));
5436 if (!valid_thread_id (*thread
))
5437 error (_("Unknown thread %d."), *thread
);
5440 error (_("Junk at end of arguments."));
5444 /* Set a breakpoint. This function is shared between
5445 CLI and MI functions for setting a breakpoint.
5446 This function has two major modes of operations,
5447 selected by the PARSE_CONDITION_AND_THREAD parameter.
5448 If non-zero, the function will parse arg, extracting
5449 breakpoint location, address and thread. Otherwise,
5450 ARG is just the location of breakpoint, with condition
5451 and thread specified by the COND_STRING and THREAD
5455 break_command_really (char *arg
, char *cond_string
, int thread
,
5456 int parse_condition_and_thread
,
5457 int tempflag
, int hardwareflag
,
5459 enum auto_boolean pending_break_support
,
5462 struct gdb_exception e
;
5463 struct symtabs_and_lines sals
;
5464 struct symtab_and_line pending_sal
;
5467 char *addr_start
= arg
;
5469 struct cleanup
*old_chain
;
5470 struct cleanup
*breakpoint_chain
= NULL
;
5471 struct captured_parse_breakpoint_args parse_args
;
5480 parse_args
.arg_p
= &arg
;
5481 parse_args
.sals_p
= &sals
;
5482 parse_args
.addr_string_p
= &addr_string
;
5483 parse_args
.not_found_ptr
= ¬_found
;
5485 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5486 &parse_args
, RETURN_MASK_ALL
);
5488 /* If caller is interested in rc value from parse, set value. */
5492 throw_exception (e
);
5496 case NOT_FOUND_ERROR
:
5498 /* If pending breakpoint support is turned off, throw
5501 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5502 throw_exception (e
);
5504 exception_print (gdb_stderr
, e
);
5506 /* If pending breakpoint support is auto query and the user
5507 selects no, then simply return the error code. */
5508 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5509 !nquery ("Make breakpoint pending on future shared library load? "))
5512 /* At this point, either the user was queried about setting
5513 a pending breakpoint and selected yes, or pending
5514 breakpoint behavior is on and thus a pending breakpoint
5515 is defaulted on behalf of the user. */
5516 copy_arg
= xstrdup (addr_start
);
5517 addr_string
= ©_arg
;
5519 sals
.sals
= &pending_sal
;
5524 throw_exception (e
);
5531 /* Create a chain of things that always need to be cleaned up. */
5532 old_chain
= make_cleanup (null_cleanup
, 0);
5536 /* Make sure that all storage allocated to SALS gets freed. */
5537 make_cleanup (xfree
, sals
.sals
);
5539 /* Cleanup the addr_string array but not its contents. */
5540 make_cleanup (xfree
, addr_string
);
5543 /* ----------------------------- SNIP -----------------------------
5544 Anything added to the cleanup chain beyond this point is assumed
5545 to be part of a breakpoint. If the breakpoint create succeeds
5546 then the memory is not reclaimed. */
5547 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5549 /* Mark the contents of the addr_string for cleanup. These go on
5550 the breakpoint_chain and only occure if the breakpoint create
5552 for (i
= 0; i
< sals
.nelts
; i
++)
5554 if (addr_string
[i
] != NULL
)
5555 make_cleanup (xfree
, addr_string
[i
]);
5558 /* Resolve all line numbers to PC's and verify that the addresses
5559 are ok for the target. */
5561 breakpoint_sals_to_pc (&sals
, addr_start
);
5563 /* Verify that condition can be parsed, before setting any
5564 breakpoints. Allocate a separate condition expression for each
5568 if (parse_condition_and_thread
)
5570 /* Here we only parse 'arg' to separate condition
5571 from thread number, so parsing in context of first
5572 sal is OK. When setting the breakpoint we'll
5573 re-parse it in context of each sal. */
5576 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5578 make_cleanup (xfree
, cond_string
);
5582 /* Create a private copy of condition string. */
5585 cond_string
= xstrdup (cond_string
);
5586 make_cleanup (xfree
, cond_string
);
5589 create_breakpoints (sals
, addr_string
, cond_string
,
5590 hardwareflag
? bp_hardware_breakpoint
5592 tempflag
? disp_del
: disp_donttouch
,
5593 thread
, ignore_count
, from_tty
);
5597 struct symtab_and_line sal
= {0};
5598 struct breakpoint
*b
;
5600 make_cleanup (xfree
, copy_arg
);
5602 b
= set_raw_breakpoint_without_location (hardwareflag
5603 ? bp_hardware_breakpoint
5605 set_breakpoint_count (breakpoint_count
+ 1);
5606 b
->number
= breakpoint_count
;
5608 b
->addr_string
= addr_string
[0];
5609 b
->cond_string
= NULL
;
5610 b
->ignore_count
= ignore_count
;
5611 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5612 b
->condition_not_parsed
= 1;
5614 update_global_location_list ();
5619 warning (_("Multiple breakpoints were set.\n"
5620 "Use the \"delete\" command to delete unwanted breakpoints."));
5621 /* That's it. Discard the cleanups for data inserted into the
5623 discard_cleanups (breakpoint_chain
);
5624 /* But cleanup everything else. */
5625 do_cleanups (old_chain
);
5628 /* Set a breakpoint.
5629 ARG is a string describing breakpoint address,
5630 condition, and thread.
5631 FLAG specifies if a breakpoint is hardware on,
5632 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5636 break_command_1 (char *arg
, int flag
, int from_tty
)
5638 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5639 int tempflag
= flag
& BP_TEMPFLAG
;
5641 break_command_really (arg
,
5642 NULL
, 0, 1 /* parse arg */,
5643 tempflag
, hardwareflag
,
5644 0 /* Ignore count */,
5645 pending_break_support
, from_tty
);
5650 set_breakpoint (char *address
, char *condition
,
5651 int hardwareflag
, int tempflag
,
5652 int thread
, int ignore_count
,
5655 break_command_really (address
, condition
, thread
,
5656 0 /* condition and thread are valid. */,
5657 tempflag
, hardwareflag
,
5660 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5664 /* Adjust SAL to the first instruction past the function prologue.
5665 The end of the prologue is determined using the line table from
5666 the debugging information.
5668 If SAL is already past the prologue, then do nothing. */
5671 skip_prologue_sal (struct symtab_and_line
*sal
)
5673 struct symbol
*sym
= find_pc_function (sal
->pc
);
5674 struct symtab_and_line start_sal
;
5679 start_sal
= find_function_start_sal (sym
, 1);
5680 if (sal
->pc
< start_sal
.pc
)
5684 /* Helper function for break_command_1 and disassemble_command. */
5687 resolve_sal_pc (struct symtab_and_line
*sal
)
5691 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5693 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5694 error (_("No line %d in file \"%s\"."),
5695 sal
->line
, sal
->symtab
->filename
);
5698 /* If this SAL corresponds to a breakpoint inserted using
5699 a line number, then skip the function prologue if necessary. */
5700 if (sal
->explicit_line
)
5701 skip_prologue_sal (sal
);
5704 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5706 struct blockvector
*bv
;
5710 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5713 sym
= block_function (b
);
5716 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5717 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5721 /* It really is worthwhile to have the section, so we'll just
5722 have to look harder. This case can be executed if we have
5723 line numbers but no functions (as can happen in assembly
5726 struct minimal_symbol
*msym
;
5728 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5730 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5737 break_command (char *arg
, int from_tty
)
5739 break_command_1 (arg
, 0, from_tty
);
5743 tbreak_command (char *arg
, int from_tty
)
5745 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5749 hbreak_command (char *arg
, int from_tty
)
5751 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5755 thbreak_command (char *arg
, int from_tty
)
5757 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5761 stop_command (char *arg
, int from_tty
)
5763 printf_filtered (_("Specify the type of breakpoint to set.\n\
5764 Usage: stop in <function | address>\n\
5765 stop at <line>\n"));
5769 stopin_command (char *arg
, int from_tty
)
5773 if (arg
== (char *) NULL
)
5775 else if (*arg
!= '*')
5780 /* look for a ':'. If this is a line number specification, then
5781 say it is bad, otherwise, it should be an address or
5782 function/method name */
5783 while (*argptr
&& !hasColon
)
5785 hasColon
= (*argptr
== ':');
5790 badInput
= (*argptr
!= ':'); /* Not a class::method */
5792 badInput
= isdigit (*arg
); /* a simple line number */
5796 printf_filtered (_("Usage: stop in <function | address>\n"));
5798 break_command_1 (arg
, 0, from_tty
);
5802 stopat_command (char *arg
, int from_tty
)
5806 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5813 /* look for a ':'. If there is a '::' then get out, otherwise
5814 it is probably a line number. */
5815 while (*argptr
&& !hasColon
)
5817 hasColon
= (*argptr
== ':');
5822 badInput
= (*argptr
== ':'); /* we have class::method */
5824 badInput
= !isdigit (*arg
); /* not a line number */
5828 printf_filtered (_("Usage: stop at <line>\n"));
5830 break_command_1 (arg
, 0, from_tty
);
5833 /* accessflag: hw_write: watch write,
5834 hw_read: watch read,
5835 hw_access: watch access (read or write) */
5837 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5839 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5840 struct symtab_and_line sal
;
5841 struct expression
*exp
;
5842 struct block
*exp_valid_block
;
5843 struct value
*val
, *mark
;
5844 struct frame_info
*frame
;
5845 struct frame_info
*prev_frame
= NULL
;
5846 char *exp_start
= NULL
;
5847 char *exp_end
= NULL
;
5848 char *tok
, *id_tok_start
, *end_tok
;
5850 char *cond_start
= NULL
;
5851 char *cond_end
= NULL
;
5852 struct expression
*cond
= NULL
;
5853 int i
, other_type_used
, target_resources_ok
= 0;
5854 enum bptype bp_type
;
5858 init_sal (&sal
); /* initialize to zeroes */
5860 /* Make sure that we actually have parameters to parse. */
5861 if (arg
!= NULL
&& arg
[0] != '\0')
5863 toklen
= strlen (arg
); /* Size of argument list. */
5865 /* Points tok to the end of the argument list. */
5866 tok
= arg
+ toklen
- 1;
5868 /* Go backwards in the parameters list. Skip the last parameter.
5869 If we're expecting a 'thread <thread_num>' parameter, this should
5870 be the thread identifier. */
5871 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5873 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5876 /* Points end_tok to the beginning of the last token. */
5877 id_tok_start
= tok
+ 1;
5879 /* Go backwards in the parameters list. Skip one more parameter.
5880 If we're expecting a 'thread <thread_num>' parameter, we should
5881 reach a "thread" token. */
5882 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5887 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5890 /* Move the pointer forward to skip the whitespace and
5891 calculate the length of the token. */
5893 toklen
= end_tok
- tok
;
5895 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5897 /* At this point we've found a "thread" token, which means
5898 the user is trying to set a watchpoint that triggers
5899 only in a specific thread. */
5902 /* Extract the thread ID from the next token. */
5903 thread
= strtol (id_tok_start
, &endp
, 0);
5905 /* Check if the user provided a valid numeric value for the
5907 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5908 error (_("Invalid thread ID specification %s."), id_tok_start
);
5910 /* Check if the thread actually exists. */
5911 if (!valid_thread_id (thread
))
5912 error (_("Unknown thread %d."), thread
);
5914 /* Truncate the string and get rid of the thread <thread_num>
5915 parameter before the parameter list is parsed by the
5916 evaluate_expression() function. */
5921 /* Parse the rest of the arguments. */
5922 innermost_block
= NULL
;
5924 exp
= parse_exp_1 (&arg
, 0, 0);
5926 exp_valid_block
= innermost_block
;
5927 mark
= value_mark ();
5928 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5930 release_value (val
);
5933 while (*tok
== ' ' || *tok
== '\t')
5937 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5940 toklen
= end_tok
- tok
;
5941 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5943 tok
= cond_start
= end_tok
+ 1;
5944 cond
= parse_exp_1 (&tok
, 0, 0);
5948 error (_("Junk at end of command."));
5950 if (accessflag
== hw_read
)
5951 bp_type
= bp_read_watchpoint
;
5952 else if (accessflag
== hw_access
)
5953 bp_type
= bp_access_watchpoint
;
5955 bp_type
= bp_hardware_watchpoint
;
5957 mem_cnt
= can_use_hardware_watchpoint (val
);
5958 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5959 error (_("Expression cannot be implemented with read/access watchpoint."));
5962 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5963 target_resources_ok
=
5964 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5966 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5967 error (_("Target does not support this type of hardware watchpoint."));
5969 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5970 error (_("Target can only support one kind of HW watchpoint at a time."));
5973 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5974 watchpoint could not be set. */
5975 if (!mem_cnt
|| target_resources_ok
<= 0)
5976 bp_type
= bp_watchpoint
;
5978 frame
= block_innermost_frame (exp_valid_block
);
5980 prev_frame
= get_prev_frame (frame
);
5984 /* If the expression is "local", then set up a "watchpoint scope"
5985 breakpoint at the point where we've left the scope of the watchpoint
5986 expression. Create the scope breakpoint before the watchpoint, so
5987 that we will encounter it first in bpstat_stop_status. */
5988 if (innermost_block
&& prev_frame
)
5990 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5991 bp_watchpoint_scope
);
5993 scope_breakpoint
->enable_state
= bp_enabled
;
5995 /* Automatically delete the breakpoint when it hits. */
5996 scope_breakpoint
->disposition
= disp_del
;
5998 /* Only break in the proper frame (help with recursion). */
5999 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6001 /* Set the address at which we will stop. */
6002 scope_breakpoint
->loc
->requested_address
6003 = get_frame_pc (prev_frame
);
6004 scope_breakpoint
->loc
->address
6005 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6006 scope_breakpoint
->type
);
6009 /* Now set up the breakpoint. */
6010 b
= set_raw_breakpoint (sal
, bp_type
);
6011 set_breakpoint_count (breakpoint_count
+ 1);
6012 b
->number
= breakpoint_count
;
6014 b
->disposition
= disp_donttouch
;
6016 b
->exp_valid_block
= exp_valid_block
;
6017 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6020 b
->loc
->cond
= cond
;
6022 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6027 b
->watchpoint_frame
= get_frame_id (frame
);
6029 b
->watchpoint_frame
= null_frame_id
;
6031 if (scope_breakpoint
!= NULL
)
6033 /* The scope breakpoint is related to the watchpoint. We will
6034 need to act on them together. */
6035 b
->related_breakpoint
= scope_breakpoint
;
6036 scope_breakpoint
->related_breakpoint
= b
;
6039 value_free_to_mark (mark
);
6041 update_global_location_list ();
6044 /* Return count of locations need to be watched and can be handled
6045 in hardware. If the watchpoint can not be handled
6046 in hardware return zero. */
6049 can_use_hardware_watchpoint (struct value
*v
)
6051 int found_memory_cnt
= 0;
6052 struct value
*head
= v
;
6054 /* Did the user specifically forbid us to use hardware watchpoints? */
6055 if (!can_use_hw_watchpoints
)
6058 /* Make sure that the value of the expression depends only upon
6059 memory contents, and values computed from them within GDB. If we
6060 find any register references or function calls, we can't use a
6061 hardware watchpoint.
6063 The idea here is that evaluating an expression generates a series
6064 of values, one holding the value of every subexpression. (The
6065 expression a*b+c has five subexpressions: a, b, a*b, c, and
6066 a*b+c.) GDB's values hold almost enough information to establish
6067 the criteria given above --- they identify memory lvalues,
6068 register lvalues, computed values, etcetera. So we can evaluate
6069 the expression, and then scan the chain of values that leaves
6070 behind to decide whether we can detect any possible change to the
6071 expression's final value using only hardware watchpoints.
6073 However, I don't think that the values returned by inferior
6074 function calls are special in any way. So this function may not
6075 notice that an expression involving an inferior function call
6076 can't be watched with hardware watchpoints. FIXME. */
6077 for (; v
; v
= value_next (v
))
6079 if (VALUE_LVAL (v
) == lval_memory
)
6082 /* A lazy memory lvalue is one that GDB never needed to fetch;
6083 we either just used its address (e.g., `a' in `a.b') or
6084 we never needed it at all (e.g., `a' in `a,b'). */
6088 /* Ahh, memory we actually used! Check if we can cover
6089 it with hardware watchpoints. */
6090 struct type
*vtype
= check_typedef (value_type (v
));
6092 /* We only watch structs and arrays if user asked for it
6093 explicitly, never if they just happen to appear in a
6094 middle of some value chain. */
6096 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6097 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6099 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6100 int len
= TYPE_LENGTH (value_type (v
));
6102 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6109 else if (VALUE_LVAL (v
) != not_lval
6110 && deprecated_value_modifiable (v
) == 0)
6111 return 0; /* ??? What does this represent? */
6112 else if (VALUE_LVAL (v
) == lval_register
)
6113 return 0; /* cannot watch a register with a HW watchpoint */
6116 /* The expression itself looks suitable for using a hardware
6117 watchpoint, but give the target machine a chance to reject it. */
6118 return found_memory_cnt
;
6122 watch_command_wrapper (char *arg
, int from_tty
)
6124 watch_command (arg
, from_tty
);
6128 watch_command (char *arg
, int from_tty
)
6130 watch_command_1 (arg
, hw_write
, from_tty
);
6134 rwatch_command_wrapper (char *arg
, int from_tty
)
6136 rwatch_command (arg
, from_tty
);
6140 rwatch_command (char *arg
, int from_tty
)
6142 watch_command_1 (arg
, hw_read
, from_tty
);
6146 awatch_command_wrapper (char *arg
, int from_tty
)
6148 awatch_command (arg
, from_tty
);
6152 awatch_command (char *arg
, int from_tty
)
6154 watch_command_1 (arg
, hw_access
, from_tty
);
6158 /* Helper routines for the until_command routine in infcmd.c. Here
6159 because it uses the mechanisms of breakpoints. */
6161 /* This function is called by fetch_inferior_event via the
6162 cmd_continuation pointer, to complete the until command. It takes
6163 care of cleaning up the temporary breakpoints set up by the until
6166 until_break_command_continuation (struct continuation_arg
*arg
, int error
)
6168 delete_breakpoint ((struct breakpoint
*)(arg
->data
.pointer
));
6170 delete_breakpoint ((struct breakpoint
*)(arg
->next
->data
.pointer
));
6174 until_break_command (char *arg
, int from_tty
, int anywhere
)
6176 struct symtabs_and_lines sals
;
6177 struct symtab_and_line sal
;
6178 struct frame_info
*frame
= get_selected_frame (NULL
);
6179 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6180 struct breakpoint
*breakpoint
;
6181 struct breakpoint
*breakpoint2
= NULL
;
6182 struct cleanup
*old_chain
;
6183 struct continuation_arg
*arg1
;
6184 struct continuation_arg
*arg2
;
6187 clear_proceed_status ();
6189 /* Set a breakpoint where the user wants it and at return from
6192 if (default_breakpoint_valid
)
6193 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6194 default_breakpoint_line
, (char ***) NULL
, NULL
);
6196 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6197 0, (char ***) NULL
, NULL
);
6199 if (sals
.nelts
!= 1)
6200 error (_("Couldn't get information on specified line."));
6203 xfree (sals
.sals
); /* malloc'd, so freed */
6206 error (_("Junk at end of arguments."));
6208 resolve_sal_pc (&sal
);
6211 /* If the user told us to continue until a specified location,
6212 we don't specify a frame at which we need to stop. */
6213 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6215 /* Otherwise, specify the current frame, because we want to stop only
6216 at the very same frame. */
6217 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6220 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6222 /* Keep within the current frame, or in frames called by the current
6226 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6227 sal
.pc
= get_frame_pc (prev_frame
);
6228 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6230 make_cleanup_delete_breakpoint (breakpoint2
);
6233 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6235 /* If we are running asynchronously, and proceed call above has actually
6236 managed to start the target, arrange for breakpoints to be
6237 deleted when the target stops. Otherwise, we're already stopped and
6238 delete breakpoints via cleanup chain. */
6240 if (target_can_async_p () && target_executing
)
6243 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6245 arg1
->data
.pointer
= breakpoint
;
6249 arg2
= (struct continuation_arg
*)
6250 xmalloc ( sizeof (struct continuation_arg
));
6252 arg2
->data
.pointer
= breakpoint2
;
6256 discard_cleanups (old_chain
);
6257 add_continuation (until_break_command_continuation
, arg1
);
6260 do_cleanups (old_chain
);
6264 ep_skip_leading_whitespace (char **s
)
6266 if ((s
== NULL
) || (*s
== NULL
))
6268 while (isspace (**s
))
6272 /* This function examines a string, and attempts to find a token
6273 that might be an event name in the leading characters. If a
6274 possible match is found, a pointer to the last character of
6275 the token is returned. Else, NULL is returned. */
6278 ep_find_event_name_end (char *arg
)
6281 char *event_name_end
= NULL
;
6283 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6287 /* We break out of the loop when we find a token delimiter.
6288 Basically, we're looking for alphanumerics and underscores;
6289 anything else delimites the token. */
6292 if (!isalnum (*s
) && (*s
!= '_'))
6298 return event_name_end
;
6302 /* This function attempts to parse an optional "if <cond>" clause
6303 from the arg string. If one is not found, it returns NULL.
6305 Else, it returns a pointer to the condition string. (It does not
6306 attempt to evaluate the string against a particular block.) And,
6307 it updates arg to point to the first character following the parsed
6308 if clause in the arg string. */
6311 ep_parse_optional_if_clause (char **arg
)
6315 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6318 /* Skip the "if" keyword. */
6321 /* Skip any extra leading whitespace, and record the start of the
6322 condition string. */
6323 ep_skip_leading_whitespace (arg
);
6326 /* Assume that the condition occupies the remainder of the arg string. */
6327 (*arg
) += strlen (cond_string
);
6332 /* This function attempts to parse an optional filename from the arg
6333 string. If one is not found, it returns NULL.
6335 Else, it returns a pointer to the parsed filename. (This function
6336 makes no attempt to verify that a file of that name exists, or is
6337 accessible.) And, it updates arg to point to the first character
6338 following the parsed filename in the arg string.
6340 Note that clients needing to preserve the returned filename for
6341 future access should copy it to their own buffers. */
6343 ep_parse_optional_filename (char **arg
)
6345 static char filename
[1024];
6350 if ((*arg_p
== '\0') || isspace (*arg_p
))
6368 /* Commands to deal with catching events, such as signals, exceptions,
6369 process start/exit, etc. */
6373 catch_fork
, catch_vfork
6378 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6381 char *cond_string
= NULL
;
6383 ep_skip_leading_whitespace (&arg
);
6385 /* The allowed syntax is:
6387 catch [v]fork if <cond>
6389 First, check if there's an if clause. */
6390 cond_string
= ep_parse_optional_if_clause (&arg
);
6392 if ((*arg
!= '\0') && !isspace (*arg
))
6393 error (_("Junk at end of arguments."));
6395 /* If this target supports it, create a fork or vfork catchpoint
6396 and enable reporting of such events. */
6400 create_fork_event_catchpoint (tempflag
, cond_string
);
6403 create_vfork_event_catchpoint (tempflag
, cond_string
);
6406 error (_("unsupported or unknown fork kind; cannot catch it"));
6412 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6414 char *cond_string
= NULL
;
6416 ep_skip_leading_whitespace (&arg
);
6418 /* The allowed syntax is:
6420 catch exec if <cond>
6422 First, check if there's an if clause. */
6423 cond_string
= ep_parse_optional_if_clause (&arg
);
6425 if ((*arg
!= '\0') && !isspace (*arg
))
6426 error (_("Junk at end of arguments."));
6428 /* If this target supports it, create an exec catchpoint
6429 and enable reporting of such events. */
6430 create_exec_event_catchpoint (tempflag
, cond_string
);
6434 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6436 char *dll_pathname
= NULL
;
6437 char *cond_string
= NULL
;
6439 ep_skip_leading_whitespace (&arg
);
6441 /* The allowed syntax is:
6443 catch load if <cond>
6444 catch load <filename>
6445 catch load <filename> if <cond>
6447 The user is not allowed to specify the <filename> after an
6450 We'll ignore the pathological case of a file named "if".
6452 First, check if there's an if clause. If so, then there
6453 cannot be a filename. */
6454 cond_string
= ep_parse_optional_if_clause (&arg
);
6456 /* If there was an if clause, then there cannot be a filename.
6457 Else, there might be a filename and an if clause. */
6458 if (cond_string
== NULL
)
6460 dll_pathname
= ep_parse_optional_filename (&arg
);
6461 ep_skip_leading_whitespace (&arg
);
6462 cond_string
= ep_parse_optional_if_clause (&arg
);
6465 if ((*arg
!= '\0') && !isspace (*arg
))
6466 error (_("Junk at end of arguments."));
6468 /* Create a load breakpoint that only triggers when a load of
6469 the specified dll (or any dll, if no pathname was specified)
6471 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6472 dll_pathname
, cond_string
);
6476 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6478 char *dll_pathname
= NULL
;
6479 char *cond_string
= NULL
;
6481 ep_skip_leading_whitespace (&arg
);
6483 /* The allowed syntax is:
6485 catch unload if <cond>
6486 catch unload <filename>
6487 catch unload <filename> if <cond>
6489 The user is not allowed to specify the <filename> after an
6492 We'll ignore the pathological case of a file named "if".
6494 First, check if there's an if clause. If so, then there
6495 cannot be a filename. */
6496 cond_string
= ep_parse_optional_if_clause (&arg
);
6498 /* If there was an if clause, then there cannot be a filename.
6499 Else, there might be a filename and an if clause. */
6500 if (cond_string
== NULL
)
6502 dll_pathname
= ep_parse_optional_filename (&arg
);
6503 ep_skip_leading_whitespace (&arg
);
6504 cond_string
= ep_parse_optional_if_clause (&arg
);
6507 if ((*arg
!= '\0') && !isspace (*arg
))
6508 error (_("Junk at end of arguments."));
6510 /* Create an unload breakpoint that only triggers when an unload of
6511 the specified dll (or any dll, if no pathname was specified)
6513 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6514 dll_pathname
, cond_string
);
6517 static enum print_stop_action
6518 print_exception_catchpoint (struct breakpoint
*b
)
6520 annotate_catchpoint (b
->number
);
6522 if (strstr (b
->addr_string
, "throw") != NULL
)
6523 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6526 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6529 return PRINT_SRC_AND_LOC
;
6533 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6538 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6541 *last_addr
= b
->loc
->address
;
6542 if (strstr (b
->addr_string
, "throw") != NULL
)
6543 ui_out_field_string (uiout
, "what", "exception throw");
6545 ui_out_field_string (uiout
, "what", "exception catch");
6549 print_mention_exception_catchpoint (struct breakpoint
*b
)
6551 if (strstr (b
->addr_string
, "throw") != NULL
)
6552 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6554 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6557 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6558 print_exception_catchpoint
,
6559 print_one_exception_catchpoint
,
6560 print_mention_exception_catchpoint
6564 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6565 enum exception_event_kind ex_event
, int from_tty
)
6567 char *trigger_func_name
, *nameptr
;
6568 struct symtabs_and_lines sals
;
6569 struct breakpoint
*b
;
6571 if (ex_event
== EX_EVENT_CATCH
)
6572 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6574 trigger_func_name
= xstrdup ("__cxa_throw");
6576 nameptr
= trigger_func_name
;
6577 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6578 if (sals
.nelts
== 0)
6580 xfree (trigger_func_name
);
6584 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6585 set_breakpoint_count (breakpoint_count
+ 1);
6586 b
->number
= breakpoint_count
;
6587 b
->cond_string
= (cond_string
== NULL
) ?
6588 NULL
: savestring (cond_string
, strlen (cond_string
));
6590 b
->addr_string
= trigger_func_name
;
6591 b
->enable_state
= bp_enabled
;
6592 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6593 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6597 update_global_location_list ();
6601 /* Deal with "catch catch" and "catch throw" commands */
6604 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6605 int tempflag
, int from_tty
)
6607 char *cond_string
= NULL
;
6608 struct symtab_and_line
*sal
= NULL
;
6610 ep_skip_leading_whitespace (&arg
);
6612 cond_string
= ep_parse_optional_if_clause (&arg
);
6614 if ((*arg
!= '\0') && !isspace (*arg
))
6615 error (_("Junk at end of arguments."));
6617 if ((ex_event
!= EX_EVENT_THROW
) &&
6618 (ex_event
!= EX_EVENT_CATCH
))
6619 error (_("Unsupported or unknown exception event; cannot catch it"));
6621 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6624 warning (_("Unsupported with this platform/compiler combination."));
6627 /* Create a breakpoint struct for Ada exception catchpoints. */
6630 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6634 struct expression
*cond
,
6635 struct breakpoint_ops
*ops
,
6639 struct breakpoint
*b
;
6643 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6644 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6645 version for exception catchpoints, because two catchpoints
6646 used for different exception names will use the same address.
6647 In this case, a "breakpoint ... also set at..." warning is
6648 unproductive. Besides. the warning phrasing is also a bit
6649 inapropriate, we should use the word catchpoint, and tell
6650 the user what type of catchpoint it is. The above is good
6651 enough for now, though. */
6654 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6655 set_breakpoint_count (breakpoint_count
+ 1);
6657 b
->enable_state
= bp_enabled
;
6658 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6659 b
->number
= breakpoint_count
;
6660 b
->ignore_count
= 0;
6661 b
->loc
->cond
= cond
;
6662 b
->addr_string
= addr_string
;
6663 b
->language
= language_ada
;
6664 b
->cond_string
= cond_string
;
6665 b
->exp_string
= exp_string
;
6670 update_global_location_list ();
6673 /* Implement the "catch exception" command. */
6676 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6678 struct symtab_and_line sal
;
6680 char *addr_string
= NULL
;
6681 char *exp_string
= NULL
;
6682 char *cond_string
= NULL
;
6683 struct expression
*cond
= NULL
;
6684 struct breakpoint_ops
*ops
= NULL
;
6686 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6687 &cond_string
, &cond
, &ops
);
6688 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6689 cond_string
, cond
, ops
, tempflag
,
6693 /* Implement the "catch assert" command. */
6696 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6698 struct symtab_and_line sal
;
6699 char *addr_string
= NULL
;
6700 struct breakpoint_ops
*ops
= NULL
;
6702 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6703 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6704 tempflag
, from_tty
);
6708 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6711 /* The first argument may be an event name, such as "start" or "load".
6712 If so, then handle it as such. If it doesn't match an event name,
6713 then attempt to interpret it as an exception name. (This latter is
6714 the v4.16-and-earlier GDB meaning of the "catch" command.)
6716 First, try to find the bounds of what might be an event name. */
6717 char *arg1_start
= arg
;
6721 if (arg1_start
== NULL
)
6723 /* Old behaviour was to use pre-v-4.16 syntax */
6724 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6726 /* Now, this is not allowed */
6727 error (_("Catch requires an event name."));
6730 arg1_end
= ep_find_event_name_end (arg1_start
);
6731 if (arg1_end
== NULL
)
6732 error (_("catch requires an event"));
6733 arg1_length
= arg1_end
+ 1 - arg1_start
;
6735 /* Try to match what we found against known event names. */
6736 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6738 error (_("Catch of signal not yet implemented"));
6740 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6742 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6743 tempflag
, from_tty
);
6745 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6747 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6748 tempflag
, from_tty
);
6750 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6752 error (_("Catch of thread_start not yet implemented"));
6754 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6756 error (_("Catch of thread_exit not yet implemented"));
6758 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6760 error (_("Catch of thread_join not yet implemented"));
6762 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6764 error (_("Catch of start not yet implemented"));
6766 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6768 error (_("Catch of exit not yet implemented"));
6770 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6772 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6774 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6776 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6778 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6780 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6782 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6784 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6786 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6788 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6790 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6792 error (_("Catch of stop not yet implemented"));
6794 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6796 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6799 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6801 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6804 /* This doesn't appear to be an event name */
6808 /* Pre-v.4.16 behaviour was to treat the argument
6809 as the name of an exception */
6810 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6811 /* Now this is not allowed */
6812 error (_("Unknown event kind specified for catch"));
6818 catch_command (char *arg
, int from_tty
)
6820 catch_command_1 (arg
, 0, from_tty
);
6825 tcatch_command (char *arg
, int from_tty
)
6827 catch_command_1 (arg
, 1, from_tty
);
6830 /* Delete breakpoints by address or line. */
6833 clear_command (char *arg
, int from_tty
)
6835 struct breakpoint
*b
;
6836 VEC(breakpoint_p
) *found
= 0;
6839 struct symtabs_and_lines sals
;
6840 struct symtab_and_line sal
;
6845 sals
= decode_line_spec (arg
, 1);
6850 sals
.sals
= (struct symtab_and_line
*)
6851 xmalloc (sizeof (struct symtab_and_line
));
6852 make_cleanup (xfree
, sals
.sals
);
6853 init_sal (&sal
); /* initialize to zeroes */
6854 sal
.line
= default_breakpoint_line
;
6855 sal
.symtab
= default_breakpoint_symtab
;
6856 sal
.pc
= default_breakpoint_address
;
6857 if (sal
.symtab
== 0)
6858 error (_("No source file specified."));
6866 /* We don't call resolve_sal_pc here. That's not
6867 as bad as it seems, because all existing breakpoints
6868 typically have both file/line and pc set. So, if
6869 clear is given file/line, we can match this to existing
6870 breakpoint without obtaining pc at all.
6872 We only support clearing given the address explicitly
6873 present in breakpoint table. Say, we've set breakpoint
6874 at file:line. There were several PC values for that file:line,
6875 due to optimization, all in one block.
6876 We've picked one PC value. If "clear" is issued with another
6877 PC corresponding to the same file:line, the breakpoint won't
6878 be cleared. We probably can still clear the breakpoint, but
6879 since the other PC value is never presented to user, user
6880 can only find it by guessing, and it does not seem important
6883 /* For each line spec given, delete bps which correspond
6884 to it. Do it in two passes, solely to preserve the current
6885 behavior that from_tty is forced true if we delete more than
6889 for (i
= 0; i
< sals
.nelts
; i
++)
6891 /* If exact pc given, clear bpts at that pc.
6892 If line given (pc == 0), clear all bpts on specified line.
6893 If defaulting, clear all bpts on default line
6896 defaulting sal.pc != 0 tests to do
6901 1 0 <can't happen> */
6905 /* Find all matching breakpoints and add them to
6910 /* Are we going to delete b? */
6911 if (b
->type
!= bp_none
6912 && b
->type
!= bp_watchpoint
6913 && b
->type
!= bp_hardware_watchpoint
6914 && b
->type
!= bp_read_watchpoint
6915 && b
->type
!= bp_access_watchpoint
)
6917 struct bp_location
*loc
= b
->loc
;
6918 for (; loc
; loc
= loc
->next
)
6920 int pc_match
= sal
.pc
6921 && (loc
->address
== sal
.pc
)
6922 && (!section_is_overlay (loc
->section
)
6923 || loc
->section
== sal
.section
);
6924 int line_match
= ((default_match
|| (0 == sal
.pc
))
6925 && b
->source_file
!= NULL
6926 && sal
.symtab
!= NULL
6927 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6928 && b
->line_number
== sal
.line
);
6929 if (pc_match
|| line_match
)
6938 VEC_safe_push(breakpoint_p
, found
, b
);
6941 /* Now go thru the 'found' chain and delete them. */
6942 if (VEC_empty(breakpoint_p
, found
))
6945 error (_("No breakpoint at %s."), arg
);
6947 error (_("No breakpoint at this line."));
6950 if (VEC_length(breakpoint_p
, found
) > 1)
6951 from_tty
= 1; /* Always report if deleted more than one */
6954 if (VEC_length(breakpoint_p
, found
) == 1)
6955 printf_unfiltered (_("Deleted breakpoint "));
6957 printf_unfiltered (_("Deleted breakpoints "));
6959 breakpoints_changed ();
6961 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6964 printf_unfiltered ("%d ", b
->number
);
6965 delete_breakpoint (b
);
6968 putchar_unfiltered ('\n');
6971 /* Delete breakpoint in BS if they are `delete' breakpoints and
6972 all breakpoints that are marked for deletion, whether hit or not.
6973 This is called after any breakpoint is hit, or after errors. */
6976 breakpoint_auto_delete (bpstat bs
)
6978 struct breakpoint
*b
, *temp
;
6980 for (; bs
; bs
= bs
->next
)
6981 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6983 delete_breakpoint (bs
->breakpoint_at
->owner
);
6985 ALL_BREAKPOINTS_SAFE (b
, temp
)
6987 if (b
->disposition
== disp_del_at_next_stop
)
6988 delete_breakpoint (b
);
6993 update_global_location_list (void)
6995 struct breakpoint
*b
;
6996 struct bp_location
**next
= &bp_location_chain
;
6997 struct bp_location
*loc
;
6998 struct bp_location
*loc2
;
6999 struct gdb_exception e
;
7000 VEC(bp_location_p
) *old_locations
= NULL
;
7004 /* Store old locations for future reference. */
7005 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7006 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7008 bp_location_chain
= NULL
;
7011 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7014 next
= &(loc
->global_next
);
7019 /* Identify bp_location instances that are no longer present in the new
7020 list, and therefore should be freed. Note that it's not necessary that
7021 those locations should be removed from inferior -- if there's another
7022 location at the same address (previously marked as duplicate),
7023 we don't need to remove/insert the location. */
7024 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7026 /* Tells if 'loc' is found amoung the new locations. If not, we
7028 int found_object
= 0;
7029 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7036 /* If this location is no longer present, and inserted, look if there's
7037 maybe a new location at the same address. If so, mark that one
7038 inserted, and don't remove this one. This is needed so that we
7039 don't have a time window where a breakpoint at certain location is not
7044 /* If the location is inserted now, we might have to remove it. */
7047 if (found_object
&& should_be_inserted (loc
))
7049 /* The location is still present in the location list, and still
7050 should be inserted. Don't do anything. */
7055 /* The location is either no longer present, or got disabled.
7056 See if there's another location at the same address, in which
7057 case we don't need to remove this one from the target. */
7058 if (breakpoint_address_is_meaningful (loc
->owner
))
7059 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7061 /* For the sake of should_insert_location. The
7062 call to check_duplicates will fix up this later. */
7063 loc2
->duplicate
= 0;
7064 if (should_be_inserted (loc2
)
7065 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7068 loc2
->target_info
= loc
->target_info
;
7076 if (remove_breakpoint (loc
, mark_uninserted
))
7078 /* This is just about all we can do. We could keep this
7079 location on the global list, and try to remove it next
7080 time, but there's no particular reason why we will
7083 Note that at this point, loc->owner is still valid,
7084 as delete_breakpoint frees the breakpoint only
7085 after calling us. */
7086 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7087 loc
->owner
->number
);
7092 free_bp_location (loc
);
7097 check_duplicates (b
);
7100 if (always_inserted_mode
&& target_has_execution
)
7101 insert_breakpoint_locations ();
7105 update_global_location_list_nothrow (void)
7107 struct gdb_exception e
;
7108 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7109 update_global_location_list ();
7112 /* Delete a breakpoint and clean up all traces of it in the data
7116 delete_breakpoint (struct breakpoint
*bpt
)
7118 struct breakpoint
*b
;
7120 struct bp_location
*loc
, *next
;
7122 gdb_assert (bpt
!= NULL
);
7124 /* Has this bp already been deleted? This can happen because multiple
7125 lists can hold pointers to bp's. bpstat lists are especial culprits.
7127 One example of this happening is a watchpoint's scope bp. When the
7128 scope bp triggers, we notice that the watchpoint is out of scope, and
7129 delete it. We also delete its scope bp. But the scope bp is marked
7130 "auto-deleting", and is already on a bpstat. That bpstat is then
7131 checked for auto-deleting bp's, which are deleted.
7133 A real solution to this problem might involve reference counts in bp's,
7134 and/or giving them pointers back to their referencing bpstat's, and
7135 teaching delete_breakpoint to only free a bp's storage when no more
7136 references were extent. A cheaper bandaid was chosen. */
7137 if (bpt
->type
== bp_none
)
7140 if (deprecated_delete_breakpoint_hook
)
7141 deprecated_delete_breakpoint_hook (bpt
);
7142 breakpoint_delete_event (bpt
->number
);
7144 if (breakpoint_chain
== bpt
)
7145 breakpoint_chain
= bpt
->next
;
7150 b
->next
= bpt
->next
;
7154 free_command_lines (&bpt
->commands
);
7155 if (bpt
->cond_string
!= NULL
)
7156 xfree (bpt
->cond_string
);
7157 if (bpt
->addr_string
!= NULL
)
7158 xfree (bpt
->addr_string
);
7159 if (bpt
->exp
!= NULL
)
7161 if (bpt
->exp_string
!= NULL
)
7162 xfree (bpt
->exp_string
);
7163 if (bpt
->val
!= NULL
)
7164 value_free (bpt
->val
);
7165 if (bpt
->source_file
!= NULL
)
7166 xfree (bpt
->source_file
);
7167 if (bpt
->dll_pathname
!= NULL
)
7168 xfree (bpt
->dll_pathname
);
7169 if (bpt
->triggered_dll_pathname
!= NULL
)
7170 xfree (bpt
->triggered_dll_pathname
);
7171 if (bpt
->exec_pathname
!= NULL
)
7172 xfree (bpt
->exec_pathname
);
7174 /* Be sure no bpstat's are pointing at it after it's been freed. */
7175 /* FIXME, how can we find all bpstat's?
7176 We just check stop_bpstat for now. Note that we cannot just
7177 remove bpstats pointing at bpt from the stop_bpstat list
7178 entirely, as breakpoint commands are associated with the bpstat;
7179 if we remove it here, then the later call to
7180 bpstat_do_actions (&stop_bpstat);
7181 in event-top.c won't do anything, and temporary breakpoints
7182 with commands won't work. */
7183 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7184 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7186 bs
->breakpoint_at
= NULL
;
7188 /* bs->commands will be freed later. */
7191 /* Now that breakpoint is removed from breakpoint
7192 list, update the global location list. This
7193 will remove locations that used to belong to
7194 this breakpoint. Do this before freeing
7195 the breakpoint itself, since remove_breakpoint
7196 looks at location's owner. It might be better
7197 design to have location completely self-contained,
7198 but it's not the case now. */
7199 update_global_location_list ();
7202 /* On the chance that someone will soon try again to delete this same
7203 bp, we mark it as deleted before freeing its storage. */
7204 bpt
->type
= bp_none
;
7210 do_delete_breakpoint_cleanup (void *b
)
7212 delete_breakpoint (b
);
7216 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7218 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7222 delete_command (char *arg
, int from_tty
)
7224 struct breakpoint
*b
, *temp
;
7230 int breaks_to_delete
= 0;
7232 /* Delete all breakpoints if no argument.
7233 Do not delete internal or call-dummy breakpoints, these
7234 have to be deleted with an explicit breakpoint number argument. */
7237 if (b
->type
!= bp_call_dummy
&&
7238 b
->type
!= bp_shlib_event
&&
7239 b
->type
!= bp_thread_event
&&
7240 b
->type
!= bp_overlay_event
&&
7243 breaks_to_delete
= 1;
7248 /* Ask user only if there are some breakpoints to delete. */
7250 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7252 ALL_BREAKPOINTS_SAFE (b
, temp
)
7254 if (b
->type
!= bp_call_dummy
&&
7255 b
->type
!= bp_shlib_event
&&
7256 b
->type
!= bp_thread_event
&&
7257 b
->type
!= bp_overlay_event
&&
7259 delete_breakpoint (b
);
7264 map_breakpoint_numbers (arg
, delete_breakpoint
);
7268 all_locations_are_pending (struct bp_location
*loc
)
7270 for (; loc
; loc
= loc
->next
)
7271 if (!loc
->shlib_disabled
)
7276 /* Subroutine of update_breakpoint_locations to simplify it.
7277 Return non-zero if multiple fns in list LOC have the same name.
7278 Null names are ignored. */
7281 ambiguous_names_p (struct bp_location
*loc
)
7283 struct bp_location
*l
;
7284 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7285 (int (*) (const void *, const void *)) streq
,
7286 NULL
, xcalloc
, xfree
);
7288 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7291 const char *name
= l
->function_name
;
7293 /* Allow for some names to be NULL, ignore them. */
7297 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7299 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7314 update_breakpoint_locations (struct breakpoint
*b
,
7315 struct symtabs_and_lines sals
)
7319 struct bp_location
*existing_locations
= b
->loc
;
7321 /* If there's no new locations, and all existing locations
7322 are pending, don't do anything. This optimizes
7323 the common case where all locations are in the same
7324 shared library, that was unloaded. We'd like to
7325 retain the location, so that when the library
7326 is loaded again, we don't loose the enabled/disabled
7327 status of the individual locations. */
7328 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7333 for (i
= 0; i
< sals
.nelts
; ++i
)
7335 struct bp_location
*new_loc
=
7336 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7338 /* Reparse conditions, they might contain references to the
7340 if (b
->cond_string
!= NULL
)
7342 struct gdb_exception e
;
7345 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7347 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7352 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7353 b
->number
, e
.message
);
7354 new_loc
->enabled
= 0;
7358 if (b
->source_file
!= NULL
)
7359 xfree (b
->source_file
);
7360 if (sals
.sals
[i
].symtab
== NULL
)
7361 b
->source_file
= NULL
;
7364 savestring (sals
.sals
[i
].symtab
->filename
,
7365 strlen (sals
.sals
[i
].symtab
->filename
));
7367 if (b
->line_number
== 0)
7368 b
->line_number
= sals
.sals
[i
].line
;
7371 /* If possible, carry over 'disable' status from existing breakpoints. */
7373 struct bp_location
*e
= existing_locations
;
7374 /* If there are multiple breakpoints with the same function name,
7375 e.g. for inline functions, comparing function names won't work.
7376 Instead compare pc addresses; this is just a heuristic as things
7377 may have moved, but in practice it gives the correct answer
7378 often enough until a better solution is found. */
7379 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7381 for (; e
; e
= e
->next
)
7383 if (!e
->enabled
&& e
->function_name
)
7385 struct bp_location
*l
= b
->loc
;
7386 if (have_ambiguous_names
)
7388 for (; l
; l
= l
->next
)
7389 if (e
->address
== l
->address
)
7397 for (; l
; l
= l
->next
)
7398 if (l
->function_name
7399 && strcmp (e
->function_name
, l
->function_name
) == 0)
7409 update_global_location_list ();
7413 /* Reset a breakpoint given it's struct breakpoint * BINT.
7414 The value we return ends up being the return value from catch_errors.
7415 Unused in this case. */
7418 breakpoint_re_set_one (void *bint
)
7420 /* get past catch_errs */
7421 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7425 int *not_found_ptr
= ¬_found
;
7426 struct symtabs_and_lines sals
= {};
7427 struct symtabs_and_lines expanded
;
7429 enum enable_state save_enable
;
7430 struct gdb_exception e
;
7436 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7440 case bp_hardware_breakpoint
:
7442 case bp_catch_unload
:
7443 if (b
->addr_string
== NULL
)
7445 /* Anything without a string can't be re-set. */
7446 delete_breakpoint (b
);
7450 set_language (b
->language
);
7451 input_radix
= b
->input_radix
;
7453 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7455 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7460 int not_found_and_ok
= 0;
7461 /* For pending breakpoints, it's expected that parsing
7462 will fail until the right shared library is loaded.
7463 User has already told to create pending breakpoints and
7464 don't need extra messages. If breakpoint is in bp_shlib_disabled
7465 state, then user already saw the message about that breakpoint
7466 being disabled, and don't want to see more errors. */
7468 && (b
->condition_not_parsed
7469 || (b
->loc
&& b
->loc
->shlib_disabled
)
7470 || b
->enable_state
== bp_disabled
))
7471 not_found_and_ok
= 1;
7473 if (!not_found_and_ok
)
7475 /* We surely don't want to warn about the same breakpoint
7476 10 times. One solution, implemented here, is disable
7477 the breakpoint on error. Another solution would be to
7478 have separate 'warning emitted' flag. Since this
7479 happens only when a binary has changed, I don't know
7480 which approach is better. */
7481 b
->enable_state
= bp_disabled
;
7482 throw_exception (e
);
7489 gdb_assert (sals
.nelts
== 1);
7490 resolve_sal_pc (&sals
.sals
[0]);
7491 if (b
->condition_not_parsed
&& s
&& s
[0])
7493 char *cond_string
= 0;
7495 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7496 &cond_string
, &thread
);
7498 b
->cond_string
= cond_string
;
7500 b
->condition_not_parsed
= 0;
7502 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7503 update_breakpoint_locations (b
, expanded
);
7509 case bp_hardware_watchpoint
:
7510 case bp_read_watchpoint
:
7511 case bp_access_watchpoint
:
7512 /* Watchpoint can be either on expression using entirely global variables,
7513 or it can be on local variables.
7515 Watchpoints of the first kind are never auto-deleted, and even persist
7516 across program restarts. Since they can use variables from shared
7517 libraries, we need to reparse expression as libraries are loaded
7520 Watchpoints on local variables can also change meaning as result
7521 of solib event. For example, if a watchpoint uses both a local and
7522 a global variables in expression, it's a local watchpoint, but
7523 unloading of a shared library will make the expression invalid.
7524 This is not a very common use case, but we still re-evaluate
7525 expression, to avoid surprises to the user.
7527 Note that for local watchpoints, we re-evaluate it only if
7528 watchpoints frame id is still valid. If it's not, it means
7529 the watchpoint is out of scope and will be deleted soon. In fact,
7530 I'm not sure we'll ever be called in this case.
7532 If a local watchpoint's frame id is still valid, then
7533 b->exp_valid_block is likewise valid, and we can safely use it.
7535 Don't do anything about disabled watchpoints, since they will
7536 be reevaluated again when enabled. */
7537 update_watchpoint (b
, 1 /* reparse */);
7539 /* We needn't really do anything to reset these, since the mask
7540 that requests them is unaffected by e.g., new libraries being
7543 case bp_catch_vfork
:
7548 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7550 /* Delete longjmp and overlay event breakpoints; they will be
7551 reset later by breakpoint_re_set. */
7553 case bp_longjmp_resume
:
7554 case bp_overlay_event
:
7555 delete_breakpoint (b
);
7558 /* This breakpoint is special, it's set up when the inferior
7559 starts and we really don't want to touch it. */
7560 case bp_shlib_event
:
7562 /* Like bp_shlib_event, this breakpoint type is special.
7563 Once it is set up, we do not want to touch it. */
7564 case bp_thread_event
:
7566 /* Keep temporary breakpoints, which can be encountered when we step
7567 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7568 Otherwise these should have been blown away via the cleanup chain
7569 or by breakpoint_init_inferior when we rerun the executable. */
7572 case bp_watchpoint_scope
:
7574 case bp_step_resume
:
7581 /* Re-set all breakpoints after symbols have been re-loaded. */
7583 breakpoint_re_set (void)
7585 struct breakpoint
*b
, *temp
;
7586 enum language save_language
;
7587 int save_input_radix
;
7589 save_language
= current_language
->la_language
;
7590 save_input_radix
= input_radix
;
7591 ALL_BREAKPOINTS_SAFE (b
, temp
)
7593 /* Format possible error msg */
7594 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7596 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7597 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7598 do_cleanups (cleanups
);
7600 set_language (save_language
);
7601 input_radix
= save_input_radix
;
7603 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7605 create_longjmp_breakpoint ("longjmp");
7606 create_longjmp_breakpoint ("_longjmp");
7607 create_longjmp_breakpoint ("siglongjmp");
7608 create_longjmp_breakpoint ("_siglongjmp");
7609 create_longjmp_breakpoint (NULL
);
7612 create_overlay_event_breakpoint ("_ovly_debug_event");
7615 /* Reset the thread number of this breakpoint:
7617 - If the breakpoint is for all threads, leave it as-is.
7618 - Else, reset it to the current thread for inferior_ptid. */
7620 breakpoint_re_set_thread (struct breakpoint
*b
)
7622 if (b
->thread
!= -1)
7624 if (in_thread_list (inferior_ptid
))
7625 b
->thread
= pid_to_thread_id (inferior_ptid
);
7629 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7630 If from_tty is nonzero, it prints a message to that effect,
7631 which ends with a period (no newline). */
7634 set_ignore_count (int bptnum
, int count
, int from_tty
)
7636 struct breakpoint
*b
;
7642 if (b
->number
== bptnum
)
7644 b
->ignore_count
= count
;
7648 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7650 else if (count
== 1)
7651 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7654 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7657 breakpoints_changed ();
7658 breakpoint_modify_event (b
->number
);
7662 error (_("No breakpoint number %d."), bptnum
);
7665 /* Clear the ignore counts of all breakpoints. */
7667 breakpoint_clear_ignore_counts (void)
7669 struct breakpoint
*b
;
7672 b
->ignore_count
= 0;
7675 /* Command to set ignore-count of breakpoint N to COUNT. */
7678 ignore_command (char *args
, int from_tty
)
7684 error_no_arg (_("a breakpoint number"));
7686 num
= get_number (&p
);
7688 error (_("bad breakpoint number: '%s'"), args
);
7690 error (_("Second argument (specified ignore-count) is missing."));
7692 set_ignore_count (num
,
7693 longest_to_int (value_as_long (parse_and_eval (p
))),
7696 printf_filtered ("\n");
7699 /* Call FUNCTION on each of the breakpoints
7700 whose numbers are given in ARGS. */
7703 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7708 struct breakpoint
*b
, *tmp
;
7712 error_no_arg (_("one or more breakpoint numbers"));
7719 num
= get_number_or_range (&p1
);
7722 warning (_("bad breakpoint number at or near '%s'"), p
);
7726 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7727 if (b
->number
== num
)
7729 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7732 if (related_breakpoint
)
7733 function (related_breakpoint
);
7737 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7743 static struct bp_location
*
7744 find_location_by_number (char *number
)
7746 char *dot
= strchr (number
, '.');
7750 struct breakpoint
*b
;
7751 struct bp_location
*loc
;
7756 bp_num
= get_number_or_range (&p1
);
7758 error (_("Bad breakpoint number '%s'"), number
);
7761 if (b
->number
== bp_num
)
7766 if (!b
|| b
->number
!= bp_num
)
7767 error (_("Bad breakpoint number '%s'"), number
);
7770 loc_num
= get_number_or_range (&p1
);
7772 error (_("Bad breakpoint location number '%s'"), number
);
7776 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7779 error (_("Bad breakpoint location number '%s'"), dot
+1);
7785 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7786 If from_tty is nonzero, it prints a message to that effect,
7787 which ends with a period (no newline). */
7790 disable_breakpoint (struct breakpoint
*bpt
)
7792 /* Never disable a watchpoint scope breakpoint; we want to
7793 hit them when we leave scope so we can delete both the
7794 watchpoint and its scope breakpoint at that time. */
7795 if (bpt
->type
== bp_watchpoint_scope
)
7798 /* You can't disable permanent breakpoints. */
7799 if (bpt
->enable_state
== bp_permanent
)
7802 bpt
->enable_state
= bp_disabled
;
7804 update_global_location_list ();
7806 if (deprecated_modify_breakpoint_hook
)
7807 deprecated_modify_breakpoint_hook (bpt
);
7808 breakpoint_modify_event (bpt
->number
);
7812 disable_command (char *args
, int from_tty
)
7814 struct breakpoint
*bpt
;
7816 ALL_BREAKPOINTS (bpt
)
7820 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7825 case bp_catch_unload
:
7827 case bp_catch_vfork
:
7829 case bp_hardware_breakpoint
:
7831 case bp_hardware_watchpoint
:
7832 case bp_read_watchpoint
:
7833 case bp_access_watchpoint
:
7834 disable_breakpoint (bpt
);
7838 else if (strchr (args
, '.'))
7840 struct bp_location
*loc
= find_location_by_number (args
);
7843 update_global_location_list ();
7846 map_breakpoint_numbers (args
, disable_breakpoint
);
7850 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7852 int target_resources_ok
, other_type_used
;
7855 if (bpt
->type
== bp_hardware_breakpoint
)
7858 i
= hw_breakpoint_used_count ();
7859 target_resources_ok
=
7860 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7862 if (target_resources_ok
== 0)
7863 error (_("No hardware breakpoint support in the target."));
7864 else if (target_resources_ok
< 0)
7865 error (_("Hardware breakpoints used exceeds limit."));
7868 if (bpt
->type
== bp_watchpoint
||
7869 bpt
->type
== bp_hardware_watchpoint
||
7870 bpt
->type
== bp_read_watchpoint
||
7871 bpt
->type
== bp_access_watchpoint
)
7873 struct frame_id saved_frame_id
;
7875 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7876 if (bpt
->exp_valid_block
!= NULL
)
7878 struct frame_info
*fr
=
7879 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7882 printf_filtered (_("\
7883 Cannot enable watchpoint %d because the block in which its expression\n\
7884 is valid is not currently in scope.\n"), bpt
->number
);
7891 value_free (bpt
->val
);
7892 mark
= value_mark ();
7893 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7895 release_value (bpt
->val
);
7898 if (bpt
->type
== bp_hardware_watchpoint
||
7899 bpt
->type
== bp_read_watchpoint
||
7900 bpt
->type
== bp_access_watchpoint
)
7902 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7903 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7905 /* Hack around 'unused var' error for some targets here */
7906 (void) mem_cnt
, (void) i
;
7907 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7908 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7909 /* we can consider of type is bp_hardware_watchpoint, convert to
7910 bp_watchpoint in the following condition */
7911 if (target_resources_ok
< 0)
7913 printf_filtered (_("\
7914 Cannot enable watchpoint %d because target watch resources\n\
7915 have been allocated for other watchpoints.\n"), bpt
->number
);
7916 value_free_to_mark (mark
);
7921 select_frame (frame_find_by_id (saved_frame_id
));
7922 value_free_to_mark (mark
);
7925 if (bpt
->enable_state
!= bp_permanent
)
7926 bpt
->enable_state
= bp_enabled
;
7927 bpt
->disposition
= disposition
;
7928 update_global_location_list ();
7929 breakpoints_changed ();
7931 if (deprecated_modify_breakpoint_hook
)
7932 deprecated_modify_breakpoint_hook (bpt
);
7933 breakpoint_modify_event (bpt
->number
);
7938 enable_breakpoint (struct breakpoint
*bpt
)
7940 do_enable_breakpoint (bpt
, bpt
->disposition
);
7943 /* The enable command enables the specified breakpoints (or all defined
7944 breakpoints) so they once again become (or continue to be) effective
7945 in stopping the inferior. */
7948 enable_command (char *args
, int from_tty
)
7950 struct breakpoint
*bpt
;
7952 ALL_BREAKPOINTS (bpt
)
7956 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7961 case bp_catch_unload
:
7963 case bp_catch_vfork
:
7965 case bp_hardware_breakpoint
:
7967 case bp_hardware_watchpoint
:
7968 case bp_read_watchpoint
:
7969 case bp_access_watchpoint
:
7970 enable_breakpoint (bpt
);
7974 else if (strchr (args
, '.'))
7976 struct bp_location
*loc
= find_location_by_number (args
);
7979 update_global_location_list ();
7982 map_breakpoint_numbers (args
, enable_breakpoint
);
7986 enable_once_breakpoint (struct breakpoint
*bpt
)
7988 do_enable_breakpoint (bpt
, disp_disable
);
7992 enable_once_command (char *args
, int from_tty
)
7994 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7998 enable_delete_breakpoint (struct breakpoint
*bpt
)
8000 do_enable_breakpoint (bpt
, disp_del
);
8004 enable_delete_command (char *args
, int from_tty
)
8006 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8010 set_breakpoint_cmd (char *args
, int from_tty
)
8015 show_breakpoint_cmd (char *args
, int from_tty
)
8019 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8021 struct symtabs_and_lines
8022 decode_line_spec_1 (char *string
, int funfirstline
)
8024 struct symtabs_and_lines sals
;
8026 error (_("Empty line specification."));
8027 if (default_breakpoint_valid
)
8028 sals
= decode_line_1 (&string
, funfirstline
,
8029 default_breakpoint_symtab
,
8030 default_breakpoint_line
,
8031 (char ***) NULL
, NULL
);
8033 sals
= decode_line_1 (&string
, funfirstline
,
8034 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8036 error (_("Junk at end of line specification: %s"), string
);
8040 /* Create and insert a raw software breakpoint at PC. Return an
8041 identifier, which should be used to remove the breakpoint later.
8042 In general, places which call this should be using something on the
8043 breakpoint chain instead; this function should be eliminated
8047 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8049 struct bp_target_info
*bp_tgt
;
8051 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8052 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8054 bp_tgt
->placed_address
= pc
;
8055 if (target_insert_breakpoint (bp_tgt
) != 0)
8057 /* Could not insert the breakpoint. */
8065 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8068 deprecated_remove_raw_breakpoint (void *bp
)
8070 struct bp_target_info
*bp_tgt
= bp
;
8073 ret
= target_remove_breakpoint (bp_tgt
);
8079 /* One (or perhaps two) breakpoints used for software single stepping. */
8081 static void *single_step_breakpoints
[2];
8083 /* Create and insert a breakpoint for software single step. */
8086 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8090 if (single_step_breakpoints
[0] == NULL
)
8091 bpt_p
= &single_step_breakpoints
[0];
8094 gdb_assert (single_step_breakpoints
[1] == NULL
);
8095 bpt_p
= &single_step_breakpoints
[1];
8098 /* NOTE drow/2006-04-11: A future improvement to this function would be
8099 to only create the breakpoints once, and actually put them on the
8100 breakpoint chain. That would let us use set_raw_breakpoint. We could
8101 adjust the addresses each time they were needed. Doing this requires
8102 corresponding changes elsewhere where single step breakpoints are
8103 handled, however. So, for now, we use this. */
8105 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8107 error (_("Could not insert single-step breakpoint at 0x%s"),
8108 paddr_nz (next_pc
));
8111 /* Remove and delete any breakpoints used for software single step. */
8114 remove_single_step_breakpoints (void)
8116 gdb_assert (single_step_breakpoints
[0] != NULL
);
8118 /* See insert_single_step_breakpoint for more about this deprecated
8120 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8121 single_step_breakpoints
[0] = NULL
;
8123 if (single_step_breakpoints
[1] != NULL
)
8125 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8126 single_step_breakpoints
[1] = NULL
;
8130 /* Check whether a software single-step breakpoint is inserted at PC. */
8133 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8137 for (i
= 0; i
< 2; i
++)
8139 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8140 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8147 int breakpoints_always_inserted_mode (void)
8149 return always_inserted_mode
;
8153 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8154 It is defined as a macro to prevent duplication.
8155 COMMAND should be a string constant containing the name of the command. */
8156 #define BREAK_ARGS_HELP(command) \
8157 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8158 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8159 If a line number is specified, break at start of code for that line.\n\
8160 If a function is specified, break at start of code for that function.\n\
8161 If an address is specified, break at that exact address.\n\
8162 With no LOCATION, uses current execution address of selected stack frame.\n\
8163 This is useful for breaking on return to a stack frame.\n\
8165 THREADNUM is the number from \"info threads\".\n\
8166 CONDITION is a boolean expression.\n\
8168 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8170 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8173 _initialize_breakpoint (void)
8175 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8176 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8177 struct cmd_list_element
*c
;
8179 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8181 breakpoint_chain
= 0;
8182 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8183 before a breakpoint is set. */
8184 breakpoint_count
= 0;
8186 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8187 Set ignore-count of breakpoint number N to COUNT.\n\
8188 Usage is `ignore N COUNT'."));
8190 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8192 add_com ("commands", class_breakpoint
, commands_command
, _("\
8193 Set commands to be executed when a breakpoint is hit.\n\
8194 Give breakpoint number as argument after \"commands\".\n\
8195 With no argument, the targeted breakpoint is the last one set.\n\
8196 The commands themselves follow starting on the next line.\n\
8197 Type a line containing \"end\" to indicate the end of them.\n\
8198 Give \"silent\" as the first line to make the breakpoint silent;\n\
8199 then no output is printed when it is hit, except what the commands print."));
8201 add_com ("condition", class_breakpoint
, condition_command
, _("\
8202 Specify breakpoint number N to break only if COND is true.\n\
8203 Usage is `condition N COND', where N is an integer and COND is an\n\
8204 expression to be evaluated whenever breakpoint N is reached."));
8206 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8207 Set a temporary breakpoint.\n\
8208 Like \"break\" except the breakpoint is only temporary,\n\
8209 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8210 by using \"enable delete\" on the breakpoint number.\n\
8212 BREAK_ARGS_HELP ("tbreak")));
8213 set_cmd_completer (c
, location_completer
);
8215 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8216 Set a hardware assisted breakpoint.\n\
8217 Like \"break\" except the breakpoint requires hardware support,\n\
8218 some target hardware may not have this support.\n\
8220 BREAK_ARGS_HELP ("hbreak")));
8221 set_cmd_completer (c
, location_completer
);
8223 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8224 Set a temporary hardware assisted breakpoint.\n\
8225 Like \"hbreak\" except the breakpoint is only temporary,\n\
8226 so it will be deleted when hit.\n\
8228 BREAK_ARGS_HELP ("thbreak")));
8229 set_cmd_completer (c
, location_completer
);
8231 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8232 Enable some breakpoints.\n\
8233 Give breakpoint numbers (separated by spaces) as arguments.\n\
8234 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8235 This is used to cancel the effect of the \"disable\" command.\n\
8236 With a subcommand you can enable temporarily."),
8237 &enablelist
, "enable ", 1, &cmdlist
);
8239 add_com ("ab", class_breakpoint
, enable_command
, _("\
8240 Enable some breakpoints.\n\
8241 Give breakpoint numbers (separated by spaces) as arguments.\n\
8242 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8243 This is used to cancel the effect of the \"disable\" command.\n\
8244 With a subcommand you can enable temporarily."));
8246 add_com_alias ("en", "enable", class_breakpoint
, 1);
8248 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8249 Enable some breakpoints.\n\
8250 Give breakpoint numbers (separated by spaces) as arguments.\n\
8251 This is used to cancel the effect of the \"disable\" command.\n\
8252 May be abbreviated to simply \"enable\".\n"),
8253 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8255 add_cmd ("once", no_class
, enable_once_command
, _("\
8256 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8257 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8260 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8261 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8262 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8265 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8266 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8267 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8270 add_cmd ("once", no_class
, enable_once_command
, _("\
8271 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8272 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8275 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8276 Disable some breakpoints.\n\
8277 Arguments are breakpoint numbers with spaces in between.\n\
8278 To disable all breakpoints, give no argument.\n\
8279 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8280 &disablelist
, "disable ", 1, &cmdlist
);
8281 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8282 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8284 add_com ("sb", class_breakpoint
, disable_command
, _("\
8285 Disable some breakpoints.\n\
8286 Arguments are breakpoint numbers with spaces in between.\n\
8287 To disable all breakpoints, give no argument.\n\
8288 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8290 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8291 Disable some breakpoints.\n\
8292 Arguments are breakpoint numbers with spaces in between.\n\
8293 To disable all breakpoints, give no argument.\n\
8294 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8295 This command may be abbreviated \"disable\"."),
8298 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8299 Delete some breakpoints or auto-display expressions.\n\
8300 Arguments are breakpoint numbers with spaces in between.\n\
8301 To delete all breakpoints, give no argument.\n\
8303 Also a prefix command for deletion of other GDB objects.\n\
8304 The \"unset\" command is also an alias for \"delete\"."),
8305 &deletelist
, "delete ", 1, &cmdlist
);
8306 add_com_alias ("d", "delete", class_breakpoint
, 1);
8307 add_com_alias ("del", "delete", class_breakpoint
, 1);
8309 add_com ("db", class_breakpoint
, delete_command
, _("\
8310 Delete some breakpoints.\n\
8311 Arguments are breakpoint numbers with spaces in between.\n\
8312 To delete all breakpoints, give no argument.\n"));
8314 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8315 Delete some breakpoints or auto-display expressions.\n\
8316 Arguments are breakpoint numbers with spaces in between.\n\
8317 To delete all breakpoints, give no argument.\n\
8318 This command may be abbreviated \"delete\"."),
8321 add_com ("clear", class_breakpoint
, clear_command
, _("\
8322 Clear breakpoint at specified line or function.\n\
8323 Argument may be line number, function name, or \"*\" and an address.\n\
8324 If line number is specified, all breakpoints in that line are cleared.\n\
8325 If function is specified, breakpoints at beginning of function are cleared.\n\
8326 If an address is specified, breakpoints at that address are cleared.\n\
8328 With no argument, clears all breakpoints in the line that the selected frame\n\
8331 See also the \"delete\" command which clears breakpoints by number."));
8333 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8334 Set breakpoint at specified line or function.\n"
8335 BREAK_ARGS_HELP ("break")));
8336 set_cmd_completer (c
, location_completer
);
8338 add_com_alias ("b", "break", class_run
, 1);
8339 add_com_alias ("br", "break", class_run
, 1);
8340 add_com_alias ("bre", "break", class_run
, 1);
8341 add_com_alias ("brea", "break", class_run
, 1);
8345 add_com_alias ("ba", "break", class_breakpoint
, 1);
8346 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8351 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8352 Break in function/address or break at a line in the current file."),
8353 &stoplist
, "stop ", 1, &cmdlist
);
8354 add_cmd ("in", class_breakpoint
, stopin_command
,
8355 _("Break in function or address."), &stoplist
);
8356 add_cmd ("at", class_breakpoint
, stopat_command
,
8357 _("Break at a line in the current file."), &stoplist
);
8358 add_com ("status", class_info
, breakpoints_info
, _("\
8359 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8360 The \"Type\" column indicates one of:\n\
8361 \tbreakpoint - normal breakpoint\n\
8362 \twatchpoint - watchpoint\n\
8363 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8364 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8365 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8366 address and file/line number respectively.\n\
8368 Convenience variable \"$_\" and default examine address for \"x\"\n\
8369 are set to the address of the last breakpoint listed unless the command\n\
8370 is prefixed with \"server \".\n\n\
8371 Convenience variable \"$bpnum\" contains the number of the last\n\
8375 add_info ("breakpoints", breakpoints_info
, _("\
8376 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8377 The \"Type\" column indicates one of:\n\
8378 \tbreakpoint - normal breakpoint\n\
8379 \twatchpoint - watchpoint\n\
8380 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8381 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8382 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8383 address and file/line number respectively.\n\
8385 Convenience variable \"$_\" and default examine address for \"x\"\n\
8386 are set to the address of the last breakpoint listed unless the command\n\
8387 is prefixed with \"server \".\n\n\
8388 Convenience variable \"$bpnum\" contains the number of the last\n\
8392 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8393 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8394 The \"Type\" column indicates one of:\n\
8395 \tbreakpoint - normal breakpoint\n\
8396 \twatchpoint - watchpoint\n\
8397 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8398 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8399 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8400 address and file/line number respectively.\n\
8402 Convenience variable \"$_\" and default examine address for \"x\"\n\
8403 are set to the address of the last breakpoint listed unless the command\n\
8404 is prefixed with \"server \".\n\n\
8405 Convenience variable \"$bpnum\" contains the number of the last\n\
8408 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8409 Status of all breakpoints, or breakpoint number NUMBER.\n\
8410 The \"Type\" column indicates one of:\n\
8411 \tbreakpoint - normal breakpoint\n\
8412 \twatchpoint - watchpoint\n\
8413 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8414 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8415 \tuntil - internal breakpoint used by the \"until\" command\n\
8416 \tfinish - internal breakpoint used by the \"finish\" command\n\
8417 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8418 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8419 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8420 address and file/line number respectively.\n\
8422 Convenience variable \"$_\" and default examine address for \"x\"\n\
8423 are set to the address of the last breakpoint listed unless the command\n\
8424 is prefixed with \"server \".\n\n\
8425 Convenience variable \"$bpnum\" contains the number of the last\n\
8427 &maintenanceinfolist
);
8429 add_com ("catch", class_breakpoint
, catch_command
, _("\
8430 Set catchpoints to catch events.\n\
8431 Raised signals may be caught:\n\
8432 \tcatch signal - all signals\n\
8433 \tcatch signal <signame> - a particular signal\n\
8434 Raised exceptions may be caught:\n\
8435 \tcatch throw - all exceptions, when thrown\n\
8436 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8437 \tcatch catch - all exceptions, when caught\n\
8438 \tcatch catch <exceptname> - a particular exception, when caught\n\
8439 Thread or process events may be caught:\n\
8440 \tcatch thread_start - any threads, just after creation\n\
8441 \tcatch thread_exit - any threads, just before expiration\n\
8442 \tcatch thread_join - any threads, just after joins\n\
8443 Process events may be caught:\n\
8444 \tcatch start - any processes, just after creation\n\
8445 \tcatch exit - any processes, just before expiration\n\
8446 \tcatch fork - calls to fork()\n\
8447 \tcatch vfork - calls to vfork()\n\
8448 \tcatch exec - calls to exec()\n\
8449 Dynamically-linked library events may be caught:\n\
8450 \tcatch load - loads of any library\n\
8451 \tcatch load <libname> - loads of a particular library\n\
8452 \tcatch unload - unloads of any library\n\
8453 \tcatch unload <libname> - unloads of a particular library\n\
8454 The act of your program's execution stopping may also be caught:\n\
8456 C++ exceptions may be caught:\n\
8457 \tcatch throw - all exceptions, when thrown\n\
8458 \tcatch catch - all exceptions, when caught\n\
8459 Ada exceptions may be caught:\n\
8460 \tcatch exception - all exceptions, when raised\n\
8461 \tcatch exception <name> - a particular exception, when raised\n\
8462 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8463 \tcatch assert - all failed assertions, when raised\n\
8465 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8466 after a fork or vfork is caught.\n\n\
8467 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8469 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8470 Set temporary catchpoints to catch events.\n\
8471 Args like \"catch\" command.\n\
8472 Like \"catch\" except the catchpoint is only temporary,\n\
8473 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8474 by using \"enable delete\" on the catchpoint number."));
8476 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8477 Set a watchpoint for an expression.\n\
8478 A watchpoint stops execution of your program whenever the value of\n\
8479 an expression changes."));
8480 set_cmd_completer (c
, location_completer
);
8482 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8483 Set a read watchpoint for an expression.\n\
8484 A watchpoint stops execution of your program whenever the value of\n\
8485 an expression is read."));
8486 set_cmd_completer (c
, location_completer
);
8488 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8489 Set a watchpoint for an expression.\n\
8490 A watchpoint stops execution of your program whenever the value of\n\
8491 an expression is either read or written."));
8492 set_cmd_completer (c
, location_completer
);
8494 add_info ("watchpoints", breakpoints_info
,
8495 _("Synonym for ``info breakpoints''."));
8498 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8499 respond to changes - contrary to the description. */
8500 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8501 &can_use_hw_watchpoints
, _("\
8502 Set debugger's willingness to use watchpoint hardware."), _("\
8503 Show debugger's willingness to use watchpoint hardware."), _("\
8504 If zero, gdb will not use hardware for new watchpoints, even if\n\
8505 such is available. (However, any hardware watchpoints that were\n\
8506 created before setting this to nonzero, will continue to use watchpoint\n\
8509 show_can_use_hw_watchpoints
,
8510 &setlist
, &showlist
);
8512 can_use_hw_watchpoints
= 1;
8514 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8515 Breakpoint specific settings\n\
8516 Configure various breakpoint-specific variables such as\n\
8517 pending breakpoint behavior"),
8518 &breakpoint_set_cmdlist
, "set breakpoint ",
8519 0/*allow-unknown*/, &setlist
);
8520 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8521 Breakpoint specific settings\n\
8522 Configure various breakpoint-specific variables such as\n\
8523 pending breakpoint behavior"),
8524 &breakpoint_show_cmdlist
, "show breakpoint ",
8525 0/*allow-unknown*/, &showlist
);
8527 add_setshow_auto_boolean_cmd ("pending", no_class
,
8528 &pending_break_support
, _("\
8529 Set debugger's behavior regarding pending breakpoints."), _("\
8530 Show debugger's behavior regarding pending breakpoints."), _("\
8531 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8532 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8533 an error. If auto, an unrecognized breakpoint location results in a\n\
8534 user-query to see if a pending breakpoint should be created."),
8536 show_pending_break_support
,
8537 &breakpoint_set_cmdlist
,
8538 &breakpoint_show_cmdlist
);
8540 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8542 add_setshow_boolean_cmd ("auto-hw", no_class
,
8543 &automatic_hardware_breakpoints
, _("\
8544 Set automatic usage of hardware breakpoints."), _("\
8545 Show automatic usage of hardware breakpoints."), _("\
8546 If set, the debugger will automatically use hardware breakpoints for\n\
8547 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8548 a warning will be emitted for such breakpoints."),
8550 show_automatic_hardware_breakpoints
,
8551 &breakpoint_set_cmdlist
,
8552 &breakpoint_show_cmdlist
);
8554 add_setshow_boolean_cmd ("always-inserted", class_support
,
8555 &always_inserted_mode
, _("\
8556 Set mode for inserting breakpoints."), _("\
8557 Show mode for inserting breakpoints."), _("\
8558 When this mode is off (which is the default), breakpoints are inserted in\n\
8559 inferior when it is resumed, and removed when execution stops. When this\n\
8560 mode is on, breakpoints are inserted immediately and removed only when\n\
8561 the user deletes the breakpoint."),
8563 &show_always_inserted_mode
,
8564 &breakpoint_set_cmdlist
,
8565 &breakpoint_show_cmdlist
);
8567 automatic_hardware_breakpoints
= 1;