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 "mi/mi-common.h"
62 /* Arguments to pass as context to some catch command handlers. */
63 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
64 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
66 /* Prototypes for local functions. */
68 static void enable_delete_command (char *, int);
70 static void enable_delete_breakpoint (struct breakpoint
*);
72 static void enable_once_command (char *, int);
74 static void enable_once_breakpoint (struct breakpoint
*);
76 static void disable_command (char *, int);
78 static void enable_command (char *, int);
80 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
82 static void ignore_command (char *, int);
84 static int breakpoint_re_set_one (void *);
86 static void clear_command (char *, int);
88 static void catch_command (char *, int);
90 static void watch_command (char *, int);
92 static int can_use_hardware_watchpoint (struct value
*);
94 static void break_command_1 (char *, int, int);
96 static void mention (struct breakpoint
*);
98 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
100 static void check_duplicates (struct breakpoint
*);
102 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
104 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
107 static void describe_other_breakpoints (CORE_ADDR
, struct obj_section
*, int);
109 static void breakpoints_info (char *, int);
111 static void breakpoint_1 (int, int);
113 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
115 static int breakpoint_cond_eval (void *);
117 static void cleanup_executing_breakpoints (void *);
119 static void commands_command (char *, int);
121 static void condition_command (char *, int);
123 static int get_number_trailer (char **, int);
125 void set_breakpoint_count (int);
134 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
136 static enum print_stop_action
print_it_typical (bpstat
);
138 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
140 static int watchpoint_check (void *);
142 static void maintenance_info_breakpoints (char *, int);
144 static void create_overlay_event_breakpoint (char *);
146 static int hw_breakpoint_used_count (void);
148 static int hw_watchpoint_used_count (enum bptype
, int *);
150 static void hbreak_command (char *, int);
152 static void thbreak_command (char *, int);
154 static void watch_command_1 (char *, int, int);
156 static void rwatch_command (char *, int);
158 static void awatch_command (char *, int);
160 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
162 static void create_fork_vfork_event_catchpoint (int tempflag
,
164 enum bptype bp_kind
);
166 static void stop_command (char *arg
, int from_tty
);
168 static void stopin_command (char *arg
, int from_tty
);
170 static void stopat_command (char *arg
, int from_tty
);
172 static char *ep_parse_optional_if_clause (char **arg
);
174 static char *ep_parse_optional_filename (char **arg
);
176 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
177 char *arg
, int tempflag
, int from_tty
);
179 static void tcatch_command (char *arg
, int from_tty
);
181 static void ep_skip_leading_whitespace (char **s
);
183 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
185 static void free_bp_location (struct bp_location
*loc
);
187 static struct bp_location
*
188 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
190 static void update_global_location_list (int);
192 static void update_global_location_list_nothrow (int);
194 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
196 static void insert_breakpoint_locations (void);
199 bpdisp_text (enum bpdisp disp
)
201 /* NOTE: the following values are a part of MI protocol and represent
202 values of 'disp' field returned when inferior stops at a breakpoint. */
203 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
204 return bpdisps
[(int) disp
];
207 /* Prototypes for exported functions. */
208 /* If FALSE, gdb will not use hardware support for watchpoints, even
209 if such is available. */
210 static int can_use_hw_watchpoints
;
213 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
214 struct cmd_list_element
*c
,
217 fprintf_filtered (file
, _("\
218 Debugger's willingness to use watchpoint hardware is %s.\n"),
222 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
223 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
224 for unrecognized breakpoint locations.
225 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
226 static enum auto_boolean pending_break_support
;
228 show_pending_break_support (struct ui_file
*file
, int from_tty
,
229 struct cmd_list_element
*c
,
232 fprintf_filtered (file
, _("\
233 Debugger's behavior regarding pending breakpoints is %s.\n"),
237 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
238 set with "break" but falling in read-only memory.
239 If 0, gdb will warn about such breakpoints, but won't automatically
240 use hardware breakpoints. */
241 static int automatic_hardware_breakpoints
;
243 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
244 struct cmd_list_element
*c
,
247 fprintf_filtered (file
, _("\
248 Automatic usage of hardware breakpoints is %s.\n"),
252 /* If on, gdb will keep breakpoints inserted even as inferior is
253 stopped, and immediately insert any new breakpoints. If off, gdb
254 will insert breakpoints into inferior only when resuming it, and
255 will remove breakpoints upon stop. If auto, GDB will behave as ON
256 if in non-stop mode, and as OFF if all-stop mode.*/
258 static const char always_inserted_auto
[] = "auto";
259 static const char always_inserted_on
[] = "on";
260 static const char always_inserted_off
[] = "off";
261 static const char *always_inserted_enums
[] = {
262 always_inserted_auto
,
267 static const char *always_inserted_mode
= always_inserted_auto
;
269 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
270 struct cmd_list_element
*c
, const char *value
)
272 if (always_inserted_mode
== always_inserted_auto
)
273 fprintf_filtered (file
, _("\
274 Always inserted breakpoint mode is %s (currently %s).\n"),
276 breakpoints_always_inserted_mode () ? "on" : "off");
278 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
282 breakpoints_always_inserted_mode (void)
284 return (always_inserted_mode
== always_inserted_on
285 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
288 void _initialize_breakpoint (void);
290 extern int addressprint
; /* Print machine addresses? */
292 /* Are we executing breakpoint commands? */
293 static int executing_breakpoint_commands
;
295 /* Are overlay event breakpoints enabled? */
296 static int overlay_events_enabled
;
298 /* Walk the following statement or block through all breakpoints.
299 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
302 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
304 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
305 for (B = breakpoint_chain; \
306 B ? (TMP=B->next, 1): 0; \
309 /* Similar iterators for the low-level breakpoints. */
311 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
313 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
314 for (B = bp_location_chain; \
315 B ? (TMP=B->global_next, 1): 0; \
318 /* Chains of all breakpoints defined. */
320 struct breakpoint
*breakpoint_chain
;
322 struct bp_location
*bp_location_chain
;
324 /* The locations that no longer correspond to any breakpoint,
325 unlinked from bp_location_chain, but for which a hit
326 may still be reported by a target. */
327 VEC(bp_location_p
) *moribund_locations
= NULL
;
329 /* Number of last breakpoint made. */
331 int breakpoint_count
;
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_int32
, (LONGEST
) num
));
403 /* Used in run_command to zero the hit count when a new run starts. */
406 clear_breakpoint_hit_counts (void)
408 struct breakpoint
*b
;
414 /* Default address, symtab and line to put a breakpoint at
415 for "break" command with no arg.
416 if default_breakpoint_valid is zero, the other three are
417 not valid, and "break" with no arg is an error.
419 This set by print_stack_frame, which calls set_default_breakpoint. */
421 int default_breakpoint_valid
;
422 CORE_ADDR default_breakpoint_address
;
423 struct symtab
*default_breakpoint_symtab
;
424 int default_breakpoint_line
;
426 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
427 Advance *PP after the string and any trailing whitespace.
429 Currently the string can either be a number or "$" followed by the name
430 of a convenience variable. Making it an expression wouldn't work well
431 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
433 If the string is a NULL pointer, that denotes the last breakpoint.
435 TRAILER is a character which can be found after the number; most
436 commonly this is `-'. If you don't want a trailer, use \0. */
438 get_number_trailer (char **pp
, int trailer
)
440 int retval
= 0; /* default */
444 /* Empty line means refer to the last breakpoint. */
445 return breakpoint_count
;
448 /* Make a copy of the name, so we can null-terminate it
449 to pass to lookup_internalvar(). */
454 while (isalnum (*p
) || *p
== '_')
456 varname
= (char *) alloca (p
- start
+ 1);
457 strncpy (varname
, start
, p
- start
);
458 varname
[p
- start
] = '\0';
459 val
= value_of_internalvar (lookup_internalvar (varname
));
460 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
461 retval
= (int) value_as_long (val
);
464 printf_filtered (_("Convenience variable must have integer value.\n"));
472 while (*p
>= '0' && *p
<= '9')
475 /* There is no number here. (e.g. "cond a == b"). */
477 /* Skip non-numeric token */
478 while (*p
&& !isspace((int) *p
))
480 /* Return zero, which caller must interpret as error. */
486 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
488 /* Trailing junk: return 0 and let caller print error msg. */
489 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
500 /* Like get_number_trailer, but don't allow a trailer. */
502 get_number (char **pp
)
504 return get_number_trailer (pp
, '\0');
507 /* Parse a number or a range.
508 * A number will be of the form handled by get_number.
509 * A range will be of the form <number1> - <number2>, and
510 * will represent all the integers between number1 and number2,
513 * While processing a range, this fuction is called iteratively;
514 * At each call it will return the next value in the range.
516 * At the beginning of parsing a range, the char pointer PP will
517 * be advanced past <number1> and left pointing at the '-' token.
518 * Subsequent calls will not advance the pointer until the range
519 * is completed. The call that completes the range will advance
520 * pointer PP past <number2>.
524 get_number_or_range (char **pp
)
526 static int last_retval
, end_value
;
527 static char *end_ptr
;
528 static int in_range
= 0;
532 /* Default case: pp is pointing either to a solo number,
533 or to the first number of a range. */
534 last_retval
= get_number_trailer (pp
, '-');
539 /* This is the start of a range (<number1> - <number2>).
540 Skip the '-', parse and remember the second number,
541 and also remember the end of the final token. */
545 while (isspace ((int) *end_ptr
))
546 end_ptr
++; /* skip white space */
547 end_value
= get_number (temp
);
548 if (end_value
< last_retval
)
550 error (_("inverted range"));
552 else if (end_value
== last_retval
)
554 /* degenerate range (number1 == number2). Advance the
555 token pointer so that the range will be treated as a
564 error (_("negative value"));
567 /* pp points to the '-' that betokens a range. All
568 number-parsing has already been done. Return the next
569 integer value (one greater than the saved previous value).
570 Do not advance the token pointer 'pp' until the end of range
573 if (++last_retval
== end_value
)
575 /* End of range reached; advance token pointer. */
585 /* condition N EXP -- set break condition of breakpoint N to EXP. */
588 condition_command (char *arg
, int from_tty
)
590 struct breakpoint
*b
;
595 error_no_arg (_("breakpoint number"));
598 bnum
= get_number (&p
);
600 error (_("Bad breakpoint argument: '%s'"), arg
);
603 if (b
->number
== bnum
)
605 struct bp_location
*loc
= b
->loc
;
606 for (; loc
; loc
= loc
->next
)
614 if (b
->cond_string
!= NULL
)
615 xfree (b
->cond_string
);
619 b
->cond_string
= NULL
;
621 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
626 /* I don't know if it matters whether this is the string the user
627 typed in or the decompiled expression. */
628 b
->cond_string
= savestring (arg
, strlen (arg
));
629 b
->condition_not_parsed
= 0;
630 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
634 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
636 error (_("Junk at end of expression"));
639 breakpoints_changed ();
640 observer_notify_breakpoint_modified (b
->number
);
644 error (_("No breakpoint number %d."), bnum
);
648 commands_command (char *arg
, int from_tty
)
650 struct breakpoint
*b
;
653 struct command_line
*l
;
655 /* If we allowed this, we would have problems with when to
656 free the storage, if we change the commands currently
659 if (executing_breakpoint_commands
)
660 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
663 bnum
= get_number (&p
);
666 error (_("Unexpected extra arguments following breakpoint number."));
669 if (b
->number
== bnum
)
671 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
673 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
674 l
= read_command_lines (tmpbuf
, from_tty
, 1);
675 do_cleanups (cleanups
);
676 free_command_lines (&b
->commands
);
678 breakpoints_changed ();
679 observer_notify_breakpoint_modified (b
->number
);
682 error (_("No breakpoint number %d."), bnum
);
685 /* Like commands_command, but instead of reading the commands from
686 input stream, takes them from an already parsed command structure.
688 This is used by cli-script.c to DTRT with breakpoint commands
689 that are part of if and while bodies. */
690 enum command_control_type
691 commands_from_control_command (char *arg
, struct command_line
*cmd
)
693 struct breakpoint
*b
;
697 /* If we allowed this, we would have problems with when to
698 free the storage, if we change the commands currently
701 if (executing_breakpoint_commands
)
702 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
704 /* An empty string for the breakpoint number means the last
705 breakpoint, but get_number expects a NULL pointer. */
710 bnum
= get_number (&p
);
713 error (_("Unexpected extra arguments following breakpoint number."));
716 if (b
->number
== bnum
)
718 free_command_lines (&b
->commands
);
719 if (cmd
->body_count
!= 1)
720 error (_("Invalid \"commands\" block structure."));
721 /* We need to copy the commands because if/while will free the
722 list after it finishes execution. */
723 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
724 breakpoints_changed ();
725 observer_notify_breakpoint_modified (b
->number
);
726 return simple_control
;
728 error (_("No breakpoint number %d."), bnum
);
731 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
732 by replacing any memory breakpoints with their shadowed contents. */
735 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
737 struct bp_location
*b
;
738 CORE_ADDR bp_addr
= 0;
744 if (b
->owner
->type
== bp_none
)
745 warning (_("reading through apparently deleted breakpoint #%d?"),
748 if (b
->loc_type
!= bp_loc_software_breakpoint
)
752 /* Addresses and length of the part of the breakpoint that
754 bp_addr
= b
->target_info
.placed_address
;
755 bp_size
= b
->target_info
.shadow_len
;
757 /* bp isn't valid, or doesn't shadow memory. */
760 if (bp_addr
+ bp_size
<= memaddr
)
761 /* The breakpoint is entirely before the chunk of memory we
765 if (bp_addr
>= memaddr
+ len
)
766 /* The breakpoint is entirely after the chunk of memory we are
770 /* Offset within shadow_contents. */
771 if (bp_addr
< memaddr
)
773 /* Only copy the second part of the breakpoint. */
774 bp_size
-= memaddr
- bp_addr
;
775 bptoffset
= memaddr
- bp_addr
;
779 if (bp_addr
+ bp_size
> memaddr
+ len
)
781 /* Only copy the first part of the breakpoint. */
782 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
785 memcpy (buf
+ bp_addr
- memaddr
,
786 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
791 /* A wrapper function for inserting catchpoints. */
793 insert_catchpoint (struct ui_out
*uo
, void *args
)
795 struct breakpoint
*b
= (struct breakpoint
*) args
;
801 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
804 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
807 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
810 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
816 is_hardware_watchpoint (struct breakpoint
*bpt
)
818 return (bpt
->type
== bp_hardware_watchpoint
819 || bpt
->type
== bp_read_watchpoint
820 || bpt
->type
== bp_access_watchpoint
);
823 /* Find the current value of a watchpoint on EXP. Return the value in
824 *VALP and *RESULTP and the chain of intermediate and final values
825 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
828 If an error occurs while evaluating the expression, *RESULTP will
829 be set to NULL. *RESULTP may be a lazy value, if the result could
830 not be read from memory. It is used to determine whether a value
831 is user-specified (we should watch the whole value) or intermediate
832 (we should watch only the bit used to locate the final value).
834 If the final value, or any intermediate value, could not be read
835 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
836 set to any referenced values. *VALP will never be a lazy value.
837 This is the value which we store in struct breakpoint.
839 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
840 value chain. The caller must free the values individually. If
841 VAL_CHAIN is NULL, all generated values will be left on the value
845 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
846 struct value
**resultp
, struct value
**val_chain
)
848 struct value
*mark
, *new_mark
, *result
;
856 /* Evaluate the expression. */
857 mark
= value_mark ();
859 gdb_evaluate_expression (exp
, &result
);
860 new_mark
= value_mark ();
861 if (mark
== new_mark
)
866 /* Make sure it's not lazy, so that after the target stops again we
867 have a non-lazy previous value to compare with. */
869 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
874 /* Return the chain of intermediate values. We use this to
875 decide which addresses to watch. */
876 *val_chain
= new_mark
;
877 value_release_to_mark (mark
);
881 /* Assuming that B is a hardware watchpoint:
882 - Reparse watchpoint expression, is REPARSE is non-zero
883 - Evaluate expression and store the result in B->val
884 - Update the list of values that must be watched in B->loc.
886 If the watchpoint is disabled, do nothing. If this is
887 local watchpoint that is out of scope, delete it. */
889 update_watchpoint (struct breakpoint
*b
, int reparse
)
891 int within_current_scope
;
892 struct frame_id saved_frame_id
;
893 struct bp_location
*loc
;
896 /* We don't free locations. They are stored in
897 bp_location_chain and update_global_locations will
898 eventually delete them and remove breakpoints if
902 if (b
->disposition
== disp_del_at_next_stop
)
905 /* Save the current frame's ID so we can restore it after
906 evaluating the watchpoint expression on its own frame. */
907 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
908 took a frame parameter, so that we didn't have to change the
910 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
912 /* Determine if the watchpoint is within scope. */
913 if (b
->exp_valid_block
== NULL
)
914 within_current_scope
= 1;
917 struct frame_info
*fi
;
918 fi
= frame_find_by_id (b
->watchpoint_frame
);
919 within_current_scope
= (fi
!= NULL
);
920 if (within_current_scope
)
924 if (within_current_scope
&& reparse
)
933 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
934 /* If the meaning of expression itself changed, the old value is
935 no longer relevant. We don't want to report a watchpoint hit
936 to the user when the old value and the new value may actually
937 be completely different objects. */
943 /* If we failed to parse the expression, for example because
944 it refers to a global variable in a not-yet-loaded shared library,
945 don't try to insert watchpoint. We don't automatically delete
946 such watchpoint, though, since failure to parse expression
947 is different from out-of-scope watchpoint. */
948 if (within_current_scope
&& b
->exp
)
950 struct value
*val_chain
, *v
, *result
, *next
;
952 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
954 /* Avoid setting b->val if it's already set. The meaning of
955 b->val is 'the last value' user saw, and we should update
956 it only if we reported that last value to user. As it
957 happens, the code that reports it updates b->val directly. */
964 /* Look at each value on the value chain. */
965 for (v
= val_chain
; v
; v
= next
)
967 /* If it's a memory location, and GDB actually needed
968 its contents to evaluate the expression, then we
969 must watch it. If the first value returned is
970 still lazy, that means an error occurred reading it;
971 watch it anyway in case it becomes readable. */
972 if (VALUE_LVAL (v
) == lval_memory
973 && (v
== val_chain
|| ! value_lazy (v
)))
975 struct type
*vtype
= check_typedef (value_type (v
));
977 /* We only watch structs and arrays if user asked
978 for it explicitly, never if they just happen to
979 appear in the middle of some value chain. */
981 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
982 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
986 struct bp_location
*loc
, **tmp
;
988 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
989 len
= TYPE_LENGTH (value_type (v
));
991 if (b
->type
== bp_read_watchpoint
)
993 else if (b
->type
== bp_access_watchpoint
)
996 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
997 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1000 loc
->address
= addr
;
1002 loc
->watchpoint_type
= type
;
1006 next
= value_next (v
);
1011 /* We just regenerated the list of breakpoint locations.
1012 The new location does not have its condition field set to anything
1013 and therefore, we must always reparse the cond_string, independently
1014 of the value of the reparse flag. */
1015 if (b
->cond_string
!= NULL
)
1017 char *s
= b
->cond_string
;
1018 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1021 else if (!within_current_scope
)
1023 printf_filtered (_("\
1024 Hardware watchpoint %d deleted because the program has left the block \n\
1025 in which its expression is valid.\n"),
1027 if (b
->related_breakpoint
)
1028 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1029 b
->disposition
= disp_del_at_next_stop
;
1032 /* Restore the selected frame. */
1033 select_frame (frame_find_by_id (saved_frame_id
));
1037 /* Returns 1 iff breakpoint location should be
1038 inserted in the inferior. */
1040 should_be_inserted (struct bp_location
*bpt
)
1042 if (!breakpoint_enabled (bpt
->owner
))
1045 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1048 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1054 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1055 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1056 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1058 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1059 method for each breakpoint or catchpoint type. */
1061 insert_bp_location (struct bp_location
*bpt
,
1062 struct ui_file
*tmp_error_stream
,
1063 int *disabled_breaks
, int *process_warning
,
1064 int *hw_breakpoint_error
)
1068 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1071 /* Initialize the target-specific information. */
1072 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1073 bpt
->target_info
.placed_address
= bpt
->address
;
1075 if (bpt
->loc_type
== bp_loc_software_breakpoint
1076 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1078 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1080 /* If the explicitly specified breakpoint type
1081 is not hardware breakpoint, check the memory map to see
1082 if the breakpoint address is in read only memory or not.
1083 Two important cases are:
1084 - location type is not hardware breakpoint, memory
1085 is readonly. We change the type of the location to
1086 hardware breakpoint.
1087 - location type is hardware breakpoint, memory is read-write.
1088 This means we've previously made the location hardware one, but
1089 then the memory map changed, so we undo.
1091 When breakpoints are removed, remove_breakpoints will
1092 use location types we've just set here, the only possible
1093 problem is that memory map has changed during running program,
1094 but it's not going to work anyway with current gdb. */
1095 struct mem_region
*mr
1096 = lookup_mem_region (bpt
->target_info
.placed_address
);
1100 if (automatic_hardware_breakpoints
)
1103 enum bp_loc_type new_type
;
1105 if (mr
->attrib
.mode
!= MEM_RW
)
1106 new_type
= bp_loc_hardware_breakpoint
;
1108 new_type
= bp_loc_software_breakpoint
;
1110 if (new_type
!= bpt
->loc_type
)
1112 static int said
= 0;
1113 bpt
->loc_type
= new_type
;
1116 fprintf_filtered (gdb_stdout
, _("\
1117 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1122 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1123 && mr
->attrib
.mode
!= MEM_RW
)
1124 warning (_("cannot set software breakpoint at readonly address %s"),
1125 paddr (bpt
->address
));
1129 /* First check to see if we have to handle an overlay. */
1130 if (overlay_debugging
== ovly_off
1131 || bpt
->section
== NULL
1132 || !(section_is_overlay (bpt
->section
)))
1134 /* No overlay handling: just set the breakpoint. */
1136 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1137 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1139 val
= target_insert_breakpoint (&bpt
->target_info
);
1143 /* This breakpoint is in an overlay section.
1144 Shall we set a breakpoint at the LMA? */
1145 if (!overlay_events_enabled
)
1147 /* Yes -- overlay event support is not active,
1148 so we must try to set a breakpoint at the LMA.
1149 This will not work for a hardware breakpoint. */
1150 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1151 warning (_("hardware breakpoint %d not supported in overlay!"),
1152 bpt
->owner
->number
);
1155 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1157 /* Set a software (trap) breakpoint at the LMA. */
1158 bpt
->overlay_target_info
= bpt
->target_info
;
1159 bpt
->overlay_target_info
.placed_address
= addr
;
1160 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1162 fprintf_unfiltered (tmp_error_stream
,
1163 "Overlay breakpoint %d failed: in ROM?",
1164 bpt
->owner
->number
);
1167 /* Shall we set a breakpoint at the VMA? */
1168 if (section_is_mapped (bpt
->section
))
1170 /* Yes. This overlay section is mapped into memory. */
1171 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1172 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1174 val
= target_insert_breakpoint (&bpt
->target_info
);
1178 /* No. This breakpoint will not be inserted.
1179 No error, but do not mark the bp as 'inserted'. */
1186 /* Can't set the breakpoint. */
1187 if (solib_address (bpt
->address
))
1189 /* See also: disable_breakpoints_in_shlibs. */
1191 bpt
->shlib_disabled
= 1;
1192 if (!*disabled_breaks
)
1194 fprintf_unfiltered (tmp_error_stream
,
1195 "Cannot insert breakpoint %d.\n",
1196 bpt
->owner
->number
);
1197 fprintf_unfiltered (tmp_error_stream
,
1198 "Temporarily disabling shared library breakpoints:\n");
1200 *disabled_breaks
= 1;
1201 fprintf_unfiltered (tmp_error_stream
,
1202 "breakpoint #%d\n", bpt
->owner
->number
);
1206 #ifdef ONE_PROCESS_WRITETEXT
1207 *process_warning
= 1;
1209 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1211 *hw_breakpoint_error
= 1;
1212 fprintf_unfiltered (tmp_error_stream
,
1213 "Cannot insert hardware breakpoint %d.\n",
1214 bpt
->owner
->number
);
1218 fprintf_unfiltered (tmp_error_stream
,
1219 "Cannot insert breakpoint %d.\n",
1220 bpt
->owner
->number
);
1221 fprintf_filtered (tmp_error_stream
,
1222 "Error accessing memory address ");
1223 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1224 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1225 safe_strerror (val
));
1236 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1237 /* NOTE drow/2003-09-08: This state only exists for removing
1238 watchpoints. It's not clear that it's necessary... */
1239 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1241 val
= target_insert_watchpoint (bpt
->address
,
1243 bpt
->watchpoint_type
);
1244 bpt
->inserted
= (val
!= -1);
1247 else if (bpt
->owner
->type
== bp_catch_fork
1248 || bpt
->owner
->type
== bp_catch_vfork
1249 || bpt
->owner
->type
== bp_catch_exec
)
1251 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1252 bpt
->owner
, RETURN_MASK_ERROR
);
1253 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1254 bpt
->owner
->number
);
1256 bpt
->owner
->enable_state
= bp_disabled
;
1260 /* We've already printed an error message if there was a problem
1261 inserting this catchpoint, and we've disabled the catchpoint,
1262 so just return success. */
1269 /* Make sure all breakpoints are inserted in inferior.
1270 Throws exception on any error.
1271 A breakpoint that is already inserted won't be inserted
1272 again, so calling this function twice is safe. */
1274 insert_breakpoints (void)
1276 struct breakpoint
*bpt
;
1278 ALL_BREAKPOINTS (bpt
)
1279 if (is_hardware_watchpoint (bpt
))
1280 update_watchpoint (bpt
, 0 /* don't reparse. */);
1282 update_global_location_list (1);
1284 if (!breakpoints_always_inserted_mode () && target_has_execution
)
1285 /* update_global_location_list does not insert breakpoints
1286 when always_inserted_mode is not enabled. Explicitly
1288 insert_breakpoint_locations ();
1291 /* insert_breakpoints is used when starting or continuing the program.
1292 remove_breakpoints is used when the program stops.
1293 Both return zero if successful,
1294 or an `errno' value if could not write the inferior. */
1297 insert_breakpoint_locations (void)
1299 struct breakpoint
*bpt
;
1300 struct bp_location
*b
, *temp
;
1303 int disabled_breaks
= 0;
1304 int hw_breakpoint_error
= 0;
1305 int process_warning
= 0;
1307 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1308 make_cleanup_ui_file_delete (tmp_error_stream
);
1310 /* Explicitly mark the warning -- this will only be printed if
1311 there was an error. */
1312 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1314 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1316 if (!should_be_inserted (b
) || b
->inserted
)
1319 /* There is no point inserting thread-specific breakpoints if the
1320 thread no longer exists. */
1321 if (b
->owner
->thread
!= -1
1322 && !valid_thread_id (b
->owner
->thread
))
1325 val
= insert_bp_location (b
, tmp_error_stream
,
1326 &disabled_breaks
, &process_warning
,
1327 &hw_breakpoint_error
);
1332 /* If we failed to insert all locations of a watchpoint,
1333 remove them, as half-inserted watchpoint is of limited use. */
1334 ALL_BREAKPOINTS (bpt
)
1336 int some_failed
= 0;
1337 struct bp_location
*loc
;
1339 if (!is_hardware_watchpoint (bpt
))
1342 if (!breakpoint_enabled (bpt
))
1345 if (bpt
->disposition
== disp_del_at_next_stop
)
1348 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1356 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1358 remove_breakpoint (loc
, mark_uninserted
);
1360 hw_breakpoint_error
= 1;
1361 fprintf_unfiltered (tmp_error_stream
,
1362 "Could not insert hardware watchpoint %d.\n",
1370 /* If a hardware breakpoint or watchpoint was inserted, add a
1371 message about possibly exhausted resources. */
1372 if (hw_breakpoint_error
)
1374 fprintf_unfiltered (tmp_error_stream
,
1375 "Could not insert hardware breakpoints:\n\
1376 You may have requested too many hardware breakpoints/watchpoints.\n");
1378 #ifdef ONE_PROCESS_WRITETEXT
1379 if (process_warning
)
1380 fprintf_unfiltered (tmp_error_stream
,
1381 "The same program may be running in another process.");
1383 target_terminal_ours_for_output ();
1384 error_stream (tmp_error_stream
);
1389 remove_breakpoints (void)
1391 struct bp_location
*b
;
1394 ALL_BP_LOCATIONS (b
)
1398 val
= remove_breakpoint (b
, mark_uninserted
);
1407 remove_hw_watchpoints (void)
1409 struct bp_location
*b
;
1412 ALL_BP_LOCATIONS (b
)
1414 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1416 val
= remove_breakpoint (b
, mark_uninserted
);
1425 reattach_breakpoints (int pid
)
1427 struct bp_location
*b
;
1429 struct cleanup
*old_chain
= save_inferior_ptid ();
1430 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1431 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1433 make_cleanup_ui_file_delete (tmp_error_stream
);
1435 inferior_ptid
= pid_to_ptid (pid
);
1436 ALL_BP_LOCATIONS (b
)
1441 val
= insert_bp_location (b
, tmp_error_stream
,
1442 &dummy1
, &dummy2
, &dummy3
);
1445 do_cleanups (old_chain
);
1450 do_cleanups (old_chain
);
1455 update_breakpoints_after_exec (void)
1457 struct breakpoint
*b
;
1458 struct breakpoint
*temp
;
1459 struct bp_location
*bploc
;
1461 /* We're about to delete breakpoints from GDB's lists. If the
1462 INSERTED flag is true, GDB will try to lift the breakpoints by
1463 writing the breakpoints' "shadow contents" back into memory. The
1464 "shadow contents" are NOT valid after an exec, so GDB should not
1465 do that. Instead, the target is responsible from marking
1466 breakpoints out as soon as it detects an exec. We don't do that
1467 here instead, because there may be other attempts to delete
1468 breakpoints after detecting an exec and before reaching here. */
1469 ALL_BP_LOCATIONS (bploc
)
1470 gdb_assert (!bploc
->inserted
);
1472 ALL_BREAKPOINTS_SAFE (b
, temp
)
1474 /* Solib breakpoints must be explicitly reset after an exec(). */
1475 if (b
->type
== bp_shlib_event
)
1477 delete_breakpoint (b
);
1481 /* Thread event breakpoints must be set anew after an exec(),
1482 as must overlay event breakpoints. */
1483 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1485 delete_breakpoint (b
);
1489 /* Step-resume breakpoints are meaningless after an exec(). */
1490 if (b
->type
== bp_step_resume
)
1492 delete_breakpoint (b
);
1496 /* Longjmp and longjmp-resume breakpoints are also meaningless
1498 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1500 delete_breakpoint (b
);
1504 /* Don't delete an exec catchpoint, because else the inferior
1505 won't stop when it ought!
1507 Similarly, we probably ought to keep vfork catchpoints, 'cause
1508 on this target, we may not be able to stop when the vfork is
1509 seen, but only when the subsequent exec is seen. (And because
1510 deleting fork catchpoints here but not vfork catchpoints will
1511 seem mysterious to users, keep those too.) */
1512 if ((b
->type
== bp_catch_exec
) ||
1513 (b
->type
== bp_catch_vfork
) ||
1514 (b
->type
== bp_catch_fork
))
1519 /* bp_finish is a special case. The only way we ought to be able
1520 to see one of these when an exec() has happened, is if the user
1521 caught a vfork, and then said "finish". Ordinarily a finish just
1522 carries them to the call-site of the current callee, by setting
1523 a temporary bp there and resuming. But in this case, the finish
1524 will carry them entirely through the vfork & exec.
1526 We don't want to allow a bp_finish to remain inserted now. But
1527 we can't safely delete it, 'cause finish_command has a handle to
1528 the bp on a bpstat, and will later want to delete it. There's a
1529 chance (and I've seen it happen) that if we delete the bp_finish
1530 here, that its storage will get reused by the time finish_command
1531 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1532 We really must allow finish_command to delete a bp_finish.
1534 In the absense of a general solution for the "how do we know
1535 it's safe to delete something others may have handles to?"
1536 problem, what we'll do here is just uninsert the bp_finish, and
1537 let finish_command delete it.
1539 (We know the bp_finish is "doomed" in the sense that it's
1540 momentary, and will be deleted as soon as finish_command sees
1541 the inferior stopped. So it doesn't matter that the bp's
1542 address is probably bogus in the new a.out, unlike e.g., the
1543 solib breakpoints.) */
1545 if (b
->type
== bp_finish
)
1550 /* Without a symbolic address, we have little hope of the
1551 pre-exec() address meaning the same thing in the post-exec()
1553 if (b
->addr_string
== NULL
)
1555 delete_breakpoint (b
);
1559 /* FIXME what about longjmp breakpoints? Re-create them here? */
1560 create_overlay_event_breakpoint ("_ovly_debug_event");
1564 detach_breakpoints (int pid
)
1566 struct bp_location
*b
;
1568 struct cleanup
*old_chain
= save_inferior_ptid ();
1570 if (pid
== PIDGET (inferior_ptid
))
1571 error (_("Cannot detach breakpoints of inferior_ptid"));
1573 /* Set inferior_ptid; remove_breakpoint uses this global. */
1574 inferior_ptid
= pid_to_ptid (pid
);
1575 ALL_BP_LOCATIONS (b
)
1579 val
= remove_breakpoint (b
, mark_inserted
);
1582 do_cleanups (old_chain
);
1587 do_cleanups (old_chain
);
1592 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1596 if (b
->owner
->enable_state
== bp_permanent
)
1597 /* Permanent breakpoints cannot be inserted or removed. */
1600 /* The type of none suggests that owner is actually deleted.
1601 This should not ever happen. */
1602 gdb_assert (b
->owner
->type
!= bp_none
);
1604 if (b
->loc_type
== bp_loc_software_breakpoint
1605 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1607 /* "Normal" instruction breakpoint: either the standard
1608 trap-instruction bp (bp_breakpoint), or a
1609 bp_hardware_breakpoint. */
1611 /* First check to see if we have to handle an overlay. */
1612 if (overlay_debugging
== ovly_off
1613 || b
->section
== NULL
1614 || !(section_is_overlay (b
->section
)))
1616 /* No overlay handling: just remove the breakpoint. */
1618 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1619 val
= target_remove_hw_breakpoint (&b
->target_info
);
1621 val
= target_remove_breakpoint (&b
->target_info
);
1625 /* This breakpoint is in an overlay section.
1626 Did we set a breakpoint at the LMA? */
1627 if (!overlay_events_enabled
)
1629 /* Yes -- overlay event support is not active, so we
1630 should have set a breakpoint at the LMA. Remove it.
1632 /* Ignore any failures: if the LMA is in ROM, we will
1633 have already warned when we failed to insert it. */
1634 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1635 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1637 target_remove_breakpoint (&b
->overlay_target_info
);
1639 /* Did we set a breakpoint at the VMA?
1640 If so, we will have marked the breakpoint 'inserted'. */
1643 /* Yes -- remove it. Previously we did not bother to
1644 remove the breakpoint if the section had been
1645 unmapped, but let's not rely on that being safe. We
1646 don't know what the overlay manager might do. */
1647 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1648 val
= target_remove_hw_breakpoint (&b
->target_info
);
1650 /* However, we should remove *software* breakpoints only
1651 if the section is still mapped, or else we overwrite
1652 wrong code with the saved shadow contents. */
1653 else if (section_is_mapped (b
->section
))
1654 val
= target_remove_breakpoint (&b
->target_info
);
1660 /* No -- not inserted, so no need to remove. No error. */
1665 /* In some cases, we might not be able to remove a breakpoint
1666 in a shared library that has already been removed, but we
1667 have not yet processed the shlib unload event. */
1668 if (val
&& solib_address (b
->address
))
1673 b
->inserted
= (is
== mark_inserted
);
1675 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1680 b
->inserted
= (is
== mark_inserted
);
1681 val
= target_remove_watchpoint (b
->address
, b
->length
,
1682 b
->watchpoint_type
);
1684 /* Failure to remove any of the hardware watchpoints comes here. */
1685 if ((is
== mark_uninserted
) && (b
->inserted
))
1686 warning (_("Could not remove hardware watchpoint %d."),
1689 else if ((b
->owner
->type
== bp_catch_fork
||
1690 b
->owner
->type
== bp_catch_vfork
||
1691 b
->owner
->type
== bp_catch_exec
)
1692 && breakpoint_enabled (b
->owner
)
1696 switch (b
->owner
->type
)
1699 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1701 case bp_catch_vfork
:
1702 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1705 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1708 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1713 b
->inserted
= (is
== mark_inserted
);
1719 /* Clear the "inserted" flag in all breakpoints. */
1722 mark_breakpoints_out (void)
1724 struct bp_location
*bpt
;
1726 ALL_BP_LOCATIONS (bpt
)
1730 /* Clear the "inserted" flag in all breakpoints and delete any
1731 breakpoints which should go away between runs of the program.
1733 Plus other such housekeeping that has to be done for breakpoints
1736 Note: this function gets called at the end of a run (by
1737 generic_mourn_inferior) and when a run begins (by
1738 init_wait_for_inferior). */
1743 breakpoint_init_inferior (enum inf_context context
)
1745 struct breakpoint
*b
, *temp
;
1746 struct bp_location
*bpt
;
1748 ALL_BP_LOCATIONS (bpt
)
1749 if (bpt
->owner
->enable_state
!= bp_permanent
)
1752 ALL_BREAKPOINTS_SAFE (b
, temp
)
1757 case bp_watchpoint_scope
:
1759 /* If the call dummy breakpoint is at the entry point it will
1760 cause problems when the inferior is rerun, so we better
1763 Also get rid of scope breakpoints. */
1764 delete_breakpoint (b
);
1768 case bp_hardware_watchpoint
:
1769 case bp_read_watchpoint
:
1770 case bp_access_watchpoint
:
1772 /* Likewise for watchpoints on local expressions. */
1773 if (b
->exp_valid_block
!= NULL
)
1774 delete_breakpoint (b
);
1775 else if (context
== inf_starting
)
1777 /* Reset val field to force reread of starting value
1778 in insert_breakpoints. */
1780 value_free (b
->val
);
1791 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1792 exists at PC. It returns ordinary_breakpoint_here if it's an
1793 ordinary breakpoint, or permanent_breakpoint_here if it's a
1794 permanent breakpoint.
1795 - When continuing from a location with an ordinary breakpoint, we
1796 actually single step once before calling insert_breakpoints.
1797 - When continuing from a localion with a permanent breakpoint, we
1798 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1799 the target, to advance the PC past the breakpoint. */
1801 enum breakpoint_here
1802 breakpoint_here_p (CORE_ADDR pc
)
1804 const struct bp_location
*bpt
;
1805 int any_breakpoint_here
= 0;
1807 ALL_BP_LOCATIONS (bpt
)
1809 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1810 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1813 if ((breakpoint_enabled (bpt
->owner
)
1814 || bpt
->owner
->enable_state
== bp_permanent
)
1815 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1817 if (overlay_debugging
1818 && section_is_overlay (bpt
->section
)
1819 && !section_is_mapped (bpt
->section
))
1820 continue; /* unmapped overlay -- can't be a match */
1821 else if (bpt
->owner
->enable_state
== bp_permanent
)
1822 return permanent_breakpoint_here
;
1824 any_breakpoint_here
= 1;
1828 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1832 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1833 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1834 This does not check for single-step breakpoints, which are
1835 inserted and removed using direct target manipulation. */
1838 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1840 const struct bp_location
*bpt
;
1842 ALL_BP_LOCATIONS (bpt
)
1844 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1845 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1849 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1851 if (overlay_debugging
1852 && section_is_overlay (bpt
->section
)
1853 && !section_is_mapped (bpt
->section
))
1854 continue; /* unmapped overlay -- can't be a match */
1862 /* Returns non-zero iff there's either regular breakpoint
1863 or a single step breakpoint inserted at PC. */
1866 breakpoint_inserted_here_p (CORE_ADDR pc
)
1868 if (regular_breakpoint_inserted_here_p (pc
))
1871 if (single_step_breakpoint_inserted_here_p (pc
))
1877 /* This function returns non-zero iff there is a software breakpoint
1881 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1883 const struct bp_location
*bpt
;
1884 int any_breakpoint_here
= 0;
1886 ALL_BP_LOCATIONS (bpt
)
1888 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1892 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1894 if (overlay_debugging
1895 && section_is_overlay (bpt
->section
)
1896 && !section_is_mapped (bpt
->section
))
1897 continue; /* unmapped overlay -- can't be a match */
1903 /* Also check for software single-step breakpoints. */
1904 if (single_step_breakpoint_inserted_here_p (pc
))
1910 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1911 PC is valid for process/thread PTID. */
1914 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1916 const struct bp_location
*bpt
;
1919 thread
= pid_to_thread_id (ptid
);
1921 ALL_BP_LOCATIONS (bpt
)
1923 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1924 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1927 if ((breakpoint_enabled (bpt
->owner
)
1928 || bpt
->owner
->enable_state
== bp_permanent
)
1929 && bpt
->address
== pc
1930 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1932 if (overlay_debugging
1933 && section_is_overlay (bpt
->section
)
1934 && !section_is_mapped (bpt
->section
))
1935 continue; /* unmapped overlay -- can't be a match */
1945 /* bpstat stuff. External routines' interfaces are documented
1949 ep_is_catchpoint (struct breakpoint
*ep
)
1952 (ep
->type
== bp_catch_load
)
1953 || (ep
->type
== bp_catch_unload
)
1954 || (ep
->type
== bp_catch_fork
)
1955 || (ep
->type
== bp_catch_vfork
)
1956 || (ep
->type
== bp_catch_exec
);
1958 /* ??rehrauer: Add more kinds here, as are implemented... */
1962 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1965 (ep
->type
== bp_catch_load
)
1966 || (ep
->type
== bp_catch_unload
);
1970 bpstat_free (bpstat bs
)
1972 if (bs
->old_val
!= NULL
)
1973 value_free (bs
->old_val
);
1974 free_command_lines (&bs
->commands
);
1978 /* Clear a bpstat so that it says we are not at any breakpoint.
1979 Also free any storage that is part of a bpstat. */
1982 bpstat_clear (bpstat
*bsp
)
1999 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2000 is part of the bpstat is copied as well. */
2003 bpstat_copy (bpstat bs
)
2007 bpstat retval
= NULL
;
2012 for (; bs
!= NULL
; bs
= bs
->next
)
2014 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2015 memcpy (tmp
, bs
, sizeof (*tmp
));
2016 if (bs
->commands
!= NULL
)
2017 tmp
->commands
= copy_command_lines (bs
->commands
);
2018 if (bs
->old_val
!= NULL
)
2020 tmp
->old_val
= value_copy (bs
->old_val
);
2021 release_value (tmp
->old_val
);
2025 /* This is the first thing in the chain. */
2035 /* Find the bpstat associated with this breakpoint */
2038 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2043 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2045 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2051 /* Find a step_resume breakpoint associated with this bpstat.
2052 (If there are multiple step_resume bp's on the list, this function
2053 will arbitrarily pick one.)
2055 It is an error to use this function if BPSTAT doesn't contain a
2056 step_resume breakpoint.
2058 See wait_for_inferior's use of this function. */
2060 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2064 gdb_assert (bsp
!= NULL
);
2066 current_thread
= pid_to_thread_id (inferior_ptid
);
2068 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2070 if ((bsp
->breakpoint_at
!= NULL
) &&
2071 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2072 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2073 bsp
->breakpoint_at
->owner
->thread
== -1))
2074 return bsp
->breakpoint_at
->owner
;
2077 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2081 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2082 at. *BSP upon return is a bpstat which points to the remaining
2083 breakpoints stopped at (but which is not guaranteed to be good for
2084 anything but further calls to bpstat_num).
2085 Return 0 if passed a bpstat which does not indicate any breakpoints.
2086 Return -1 if stopped at a breakpoint that has been deleted since
2088 Return 1 otherwise. */
2091 bpstat_num (bpstat
*bsp
, int *num
)
2093 struct breakpoint
*b
;
2096 return 0; /* No more breakpoint values */
2098 /* We assume we'll never have several bpstats that
2099 correspond to a single breakpoint -- otherwise,
2100 this function might return the same number more
2101 than once and this will look ugly. */
2102 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2103 *bsp
= (*bsp
)->next
;
2105 return -1; /* breakpoint that's been deleted since */
2107 *num
= b
->number
; /* We have its number */
2111 /* Modify BS so that the actions will not be performed. */
2114 bpstat_clear_actions (bpstat bs
)
2116 for (; bs
!= NULL
; bs
= bs
->next
)
2118 free_command_lines (&bs
->commands
);
2119 if (bs
->old_val
!= NULL
)
2121 value_free (bs
->old_val
);
2127 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2129 cleanup_executing_breakpoints (void *ignore
)
2131 executing_breakpoint_commands
= 0;
2134 /* Execute all the commands associated with all the breakpoints at this
2135 location. Any of these commands could cause the process to proceed
2136 beyond this point, etc. We look out for such changes by checking
2137 the global "breakpoint_proceeded" after each command.
2139 Returns true if a breakpoint command resumed the inferior. In that
2140 case, it is the caller's responsibility to recall it again with the
2141 bpstat of the current thread. */
2144 bpstat_do_actions_1 (bpstat
*bsp
)
2147 struct cleanup
*old_chain
;
2150 /* Avoid endless recursion if a `source' command is contained
2152 if (executing_breakpoint_commands
)
2155 executing_breakpoint_commands
= 1;
2156 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2158 /* This pointer will iterate over the list of bpstat's. */
2161 breakpoint_proceeded
= 0;
2162 for (; bs
!= NULL
; bs
= bs
->next
)
2164 struct command_line
*cmd
;
2165 struct cleanup
*this_cmd_tree_chain
;
2167 /* Take ownership of the BSP's command tree, if it has one.
2169 The command tree could legitimately contain commands like
2170 'step' and 'next', which call clear_proceed_status, which
2171 frees stop_bpstat's command tree. To make sure this doesn't
2172 free the tree we're executing out from under us, we need to
2173 take ownership of the tree ourselves. Since a given bpstat's
2174 commands are only executed once, we don't need to copy it; we
2175 can clear the pointer in the bpstat, and make sure we free
2176 the tree when we're done. */
2179 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2183 execute_control_command (cmd
);
2185 if (breakpoint_proceeded
)
2191 /* We can free this command tree now. */
2192 do_cleanups (this_cmd_tree_chain
);
2194 if (breakpoint_proceeded
)
2196 if (target_can_async_p ())
2197 /* If we are in async mode, then the target might be still
2198 running, not stopped at any breakpoint, so nothing for
2199 us to do here -- just return to the event loop. */
2202 /* In sync mode, when execute_control_command returns
2203 we're already standing on the next breakpoint.
2204 Breakpoint commands for that stop were not run, since
2205 execute_command does not run breakpoint commands --
2206 only command_line_handler does, but that one is not
2207 involved in execution of breakpoint commands. So, we
2208 can now execute breakpoint commands. It should be
2209 noted that making execute_command do bpstat actions is
2210 not an option -- in this case we'll have recursive
2211 invocation of bpstat for each breakpoint with a
2212 command, and can easily blow up GDB stack. Instead, we
2213 return true, which will trigger the caller to recall us
2214 with the new stop_bpstat. */
2219 do_cleanups (old_chain
);
2224 bpstat_do_actions (void)
2226 /* Do any commands attached to breakpoint we are stopped at. */
2227 while (!ptid_equal (inferior_ptid
, null_ptid
)
2228 && target_has_execution
2229 && !is_exited (inferior_ptid
)
2230 && !is_executing (inferior_ptid
))
2231 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2232 and only return when it is stopped at the next breakpoint, we
2233 keep doing breakpoint actions until it returns false to
2234 indicate the inferior was not resumed. */
2235 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2239 /* Print out the (old or new) value associated with a watchpoint. */
2242 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2245 fprintf_unfiltered (stream
, _("<unreadable>"));
2247 value_print (val
, stream
, 0, Val_pretty_default
);
2250 /* This is the normal print function for a bpstat. In the future,
2251 much of this logic could (should?) be moved to bpstat_stop_status,
2252 by having it set different print_it values.
2254 Current scheme: When we stop, bpstat_print() is called. It loops
2255 through the bpstat list of things causing this stop, calling the
2256 print_bp_stop_message function on each one. The behavior of the
2257 print_bp_stop_message function depends on the print_it field of
2258 bpstat. If such field so indicates, call this function here.
2260 Return values from this routine (ultimately used by bpstat_print()
2261 and normal_stop() to decide what to do):
2262 PRINT_NOTHING: Means we already printed all we needed to print,
2263 don't print anything else.
2264 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2265 that something to be followed by a location.
2266 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2267 that something to be followed by a location.
2268 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2271 static enum print_stop_action
2272 print_it_typical (bpstat bs
)
2274 struct cleanup
*old_chain
, *ui_out_chain
;
2275 struct breakpoint
*b
;
2276 const struct bp_location
*bl
;
2277 struct ui_stream
*stb
;
2279 stb
= ui_out_stream_new (uiout
);
2280 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2281 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2282 which has since been deleted. */
2283 if (bs
->breakpoint_at
== NULL
)
2284 return PRINT_UNKNOWN
;
2285 bl
= bs
->breakpoint_at
;
2291 case bp_hardware_breakpoint
:
2292 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2293 if (bl
->address
!= bl
->requested_address
)
2294 breakpoint_adjustment_warning (bl
->requested_address
,
2297 annotate_breakpoint (b
->number
);
2299 ui_out_text (uiout
, "\nTemporary breakpoint ");
2301 ui_out_text (uiout
, "\nBreakpoint ");
2302 if (ui_out_is_mi_like_p (uiout
))
2304 ui_out_field_string (uiout
, "reason",
2305 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2306 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2308 ui_out_field_int (uiout
, "bkptno", b
->number
);
2309 ui_out_text (uiout
, ", ");
2310 return PRINT_SRC_AND_LOC
;
2313 case bp_shlib_event
:
2314 /* Did we stop because the user set the stop_on_solib_events
2315 variable? (If so, we report this as a generic, "Stopped due
2316 to shlib event" message.) */
2317 printf_filtered (_("Stopped due to shared library event\n"));
2318 return PRINT_NOTHING
;
2321 case bp_thread_event
:
2322 /* Not sure how we will get here.
2323 GDB should not stop for these breakpoints. */
2324 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2325 return PRINT_NOTHING
;
2328 case bp_overlay_event
:
2329 /* By analogy with the thread event, GDB should not stop for these. */
2330 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2331 return PRINT_NOTHING
;
2335 annotate_catchpoint (b
->number
);
2336 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2338 b
->triggered_dll_pathname
);
2339 return PRINT_SRC_AND_LOC
;
2342 case bp_catch_unload
:
2343 annotate_catchpoint (b
->number
);
2344 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2346 b
->triggered_dll_pathname
);
2347 return PRINT_SRC_AND_LOC
;
2351 annotate_catchpoint (b
->number
);
2352 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2354 ptid_get_pid (b
->forked_inferior_pid
));
2355 return PRINT_SRC_AND_LOC
;
2358 case bp_catch_vfork
:
2359 annotate_catchpoint (b
->number
);
2360 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2362 ptid_get_pid (b
->forked_inferior_pid
));
2363 return PRINT_SRC_AND_LOC
;
2367 annotate_catchpoint (b
->number
);
2368 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2371 return PRINT_SRC_AND_LOC
;
2375 case bp_hardware_watchpoint
:
2376 annotate_watchpoint (b
->number
);
2377 if (ui_out_is_mi_like_p (uiout
))
2380 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2382 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2383 ui_out_text (uiout
, "\nOld value = ");
2384 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2385 ui_out_field_stream (uiout
, "old", stb
);
2386 ui_out_text (uiout
, "\nNew value = ");
2387 watchpoint_value_print (b
->val
, stb
->stream
);
2388 ui_out_field_stream (uiout
, "new", stb
);
2389 do_cleanups (ui_out_chain
);
2390 ui_out_text (uiout
, "\n");
2391 /* More than one watchpoint may have been triggered. */
2392 return PRINT_UNKNOWN
;
2395 case bp_read_watchpoint
:
2396 if (ui_out_is_mi_like_p (uiout
))
2399 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2401 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2402 ui_out_text (uiout
, "\nValue = ");
2403 watchpoint_value_print (b
->val
, stb
->stream
);
2404 ui_out_field_stream (uiout
, "value", stb
);
2405 do_cleanups (ui_out_chain
);
2406 ui_out_text (uiout
, "\n");
2407 return PRINT_UNKNOWN
;
2410 case bp_access_watchpoint
:
2411 if (bs
->old_val
!= NULL
)
2413 annotate_watchpoint (b
->number
);
2414 if (ui_out_is_mi_like_p (uiout
))
2417 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2419 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2420 ui_out_text (uiout
, "\nOld value = ");
2421 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2422 ui_out_field_stream (uiout
, "old", stb
);
2423 ui_out_text (uiout
, "\nNew value = ");
2428 if (ui_out_is_mi_like_p (uiout
))
2431 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2432 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2433 ui_out_text (uiout
, "\nValue = ");
2435 watchpoint_value_print (b
->val
, stb
->stream
);
2436 ui_out_field_stream (uiout
, "new", stb
);
2437 do_cleanups (ui_out_chain
);
2438 ui_out_text (uiout
, "\n");
2439 return PRINT_UNKNOWN
;
2442 /* Fall through, we don't deal with these types of breakpoints
2446 if (ui_out_is_mi_like_p (uiout
))
2449 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2450 return PRINT_UNKNOWN
;
2454 if (ui_out_is_mi_like_p (uiout
))
2457 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2458 return PRINT_UNKNOWN
;
2463 case bp_longjmp_resume
:
2464 case bp_step_resume
:
2465 case bp_watchpoint_scope
:
2468 return PRINT_UNKNOWN
;
2472 /* Generic routine for printing messages indicating why we
2473 stopped. The behavior of this function depends on the value
2474 'print_it' in the bpstat structure. Under some circumstances we
2475 may decide not to print anything here and delegate the task to
2478 static enum print_stop_action
2479 print_bp_stop_message (bpstat bs
)
2481 switch (bs
->print_it
)
2484 /* Nothing should be printed for this bpstat entry. */
2485 return PRINT_UNKNOWN
;
2489 /* We still want to print the frame, but we already printed the
2490 relevant messages. */
2491 return PRINT_SRC_AND_LOC
;
2494 case print_it_normal
:
2496 const struct bp_location
*bl
= bs
->breakpoint_at
;
2497 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2499 /* Normal case. Call the breakpoint's print_it method, or
2500 print_it_typical. */
2501 /* FIXME: how breakpoint can ever be NULL here? */
2502 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2503 return b
->ops
->print_it (b
);
2505 return print_it_typical (bs
);
2510 internal_error (__FILE__
, __LINE__
,
2511 _("print_bp_stop_message: unrecognized enum value"));
2516 /* Print a message indicating what happened. This is called from
2517 normal_stop(). The input to this routine is the head of the bpstat
2518 list - a list of the eventpoints that caused this stop. This
2519 routine calls the generic print routine for printing a message
2520 about reasons for stopping. This will print (for example) the
2521 "Breakpoint n," part of the output. The return value of this
2524 PRINT_UNKNOWN: Means we printed nothing
2525 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2526 code to print the location. An example is
2527 "Breakpoint 1, " which should be followed by
2529 PRINT_SRC_ONLY: Means we printed something, but there is no need
2530 to also print the location part of the message.
2531 An example is the catch/throw messages, which
2532 don't require a location appended to the end.
2533 PRINT_NOTHING: We have done some printing and we don't need any
2534 further info to be printed.*/
2536 enum print_stop_action
2537 bpstat_print (bpstat bs
)
2541 /* Maybe another breakpoint in the chain caused us to stop.
2542 (Currently all watchpoints go on the bpstat whether hit or not.
2543 That probably could (should) be changed, provided care is taken
2544 with respect to bpstat_explains_signal). */
2545 for (; bs
; bs
= bs
->next
)
2547 val
= print_bp_stop_message (bs
);
2548 if (val
== PRINT_SRC_ONLY
2549 || val
== PRINT_SRC_AND_LOC
2550 || val
== PRINT_NOTHING
)
2554 /* We reached the end of the chain, or we got a null BS to start
2555 with and nothing was printed. */
2556 return PRINT_UNKNOWN
;
2559 /* Evaluate the expression EXP and return 1 if value is zero.
2560 This is used inside a catch_errors to evaluate the breakpoint condition.
2561 The argument is a "struct expression *" that has been cast to char * to
2562 make it pass through catch_errors. */
2565 breakpoint_cond_eval (void *exp
)
2567 struct value
*mark
= value_mark ();
2568 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2569 value_free_to_mark (mark
);
2573 /* Allocate a new bpstat and chain it to the current one. */
2576 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2580 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2582 bs
->breakpoint_at
= bl
;
2583 /* If the condition is false, etc., don't do the commands. */
2584 bs
->commands
= NULL
;
2586 bs
->print_it
= print_it_normal
;
2590 /* The target has stopped with waitstatus WS. Check if any hardware
2591 watchpoints have triggered, according to the target. */
2594 watchpoints_triggered (struct target_waitstatus
*ws
)
2596 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2598 struct breakpoint
*b
;
2600 if (!stopped_by_watchpoint
)
2602 /* We were not stopped by a watchpoint. Mark all watchpoints
2603 as not triggered. */
2605 if (b
->type
== bp_hardware_watchpoint
2606 || b
->type
== bp_read_watchpoint
2607 || b
->type
== bp_access_watchpoint
)
2608 b
->watchpoint_triggered
= watch_triggered_no
;
2613 if (!target_stopped_data_address (¤t_target
, &addr
))
2615 /* We were stopped by a watchpoint, but we don't know where.
2616 Mark all watchpoints as unknown. */
2618 if (b
->type
== bp_hardware_watchpoint
2619 || b
->type
== bp_read_watchpoint
2620 || b
->type
== bp_access_watchpoint
)
2621 b
->watchpoint_triggered
= watch_triggered_unknown
;
2623 return stopped_by_watchpoint
;
2626 /* The target could report the data address. Mark watchpoints
2627 affected by this data address as triggered, and all others as not
2631 if (b
->type
== bp_hardware_watchpoint
2632 || b
->type
== bp_read_watchpoint
2633 || b
->type
== bp_access_watchpoint
)
2635 struct bp_location
*loc
;
2638 b
->watchpoint_triggered
= watch_triggered_no
;
2639 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2640 /* Exact match not required. Within range is
2642 if (target_watchpoint_addr_within_range (¤t_target
,
2646 b
->watchpoint_triggered
= watch_triggered_yes
;
2654 /* Possible return values for watchpoint_check (this can't be an enum
2655 because of check_errors). */
2656 /* The watchpoint has been deleted. */
2657 #define WP_DELETED 1
2658 /* The value has changed. */
2659 #define WP_VALUE_CHANGED 2
2660 /* The value has not changed. */
2661 #define WP_VALUE_NOT_CHANGED 3
2663 #define BP_TEMPFLAG 1
2664 #define BP_HARDWAREFLAG 2
2666 /* Check watchpoint condition. */
2669 watchpoint_check (void *p
)
2671 bpstat bs
= (bpstat
) p
;
2672 struct breakpoint
*b
;
2673 struct frame_info
*fr
;
2674 int within_current_scope
;
2676 b
= bs
->breakpoint_at
->owner
;
2678 if (b
->exp_valid_block
== NULL
)
2679 within_current_scope
= 1;
2682 /* There is no current frame at this moment. If we're going to have
2683 any chance of handling watchpoints on local variables, we'll need
2684 the frame chain (so we can determine if we're in scope). */
2685 reinit_frame_cache ();
2686 fr
= frame_find_by_id (b
->watchpoint_frame
);
2687 within_current_scope
= (fr
!= NULL
);
2689 /* If we've gotten confused in the unwinder, we might have
2690 returned a frame that can't describe this variable. */
2691 if (within_current_scope
2692 && (block_linkage_function (b
->exp_valid_block
)
2693 != get_frame_function (fr
)))
2694 within_current_scope
= 0;
2696 /* in_function_epilogue_p() returns a non-zero value if we're still
2697 in the function but the stack frame has already been invalidated.
2698 Since we can't rely on the values of local variables after the
2699 stack has been destroyed, we are treating the watchpoint in that
2700 state as `not changed' without further checking.
2702 vinschen/2003-09-04: The former implementation left out the case
2703 that the watchpoint frame couldn't be found by frame_find_by_id()
2704 because the current PC is currently in an epilogue. Calling
2705 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2706 if ((!within_current_scope
|| fr
== get_current_frame ())
2707 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2708 return WP_VALUE_NOT_CHANGED
;
2709 if (fr
&& within_current_scope
)
2710 /* If we end up stopping, the current frame will get selected
2711 in normal_stop. So this call to select_frame won't affect
2716 if (within_current_scope
)
2718 /* We use value_{,free_to_}mark because it could be a
2719 *long* time before we return to the command level and
2720 call free_all_values. We can't call free_all_values because
2721 we might be in the middle of evaluating a function call. */
2723 struct value
*mark
= value_mark ();
2724 struct value
*new_val
;
2726 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2727 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2728 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2730 if (new_val
!= NULL
)
2732 release_value (new_val
);
2733 value_free_to_mark (mark
);
2735 bs
->old_val
= b
->val
;
2738 /* We will stop here */
2739 return WP_VALUE_CHANGED
;
2743 /* Nothing changed, don't do anything. */
2744 value_free_to_mark (mark
);
2745 /* We won't stop here */
2746 return WP_VALUE_NOT_CHANGED
;
2751 /* This seems like the only logical thing to do because
2752 if we temporarily ignored the watchpoint, then when
2753 we reenter the block in which it is valid it contains
2754 garbage (in the case of a function, it may have two
2755 garbage values, one before and one after the prologue).
2756 So we can't even detect the first assignment to it and
2757 watch after that (since the garbage may or may not equal
2758 the first value assigned). */
2759 /* We print all the stop information in print_it_typical(), but
2760 in this case, by the time we call print_it_typical() this bp
2761 will be deleted already. So we have no choice but print the
2762 information here. */
2763 if (ui_out_is_mi_like_p (uiout
))
2765 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2766 ui_out_text (uiout
, "\nWatchpoint ");
2767 ui_out_field_int (uiout
, "wpnum", b
->number
);
2768 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2769 which its expression is valid.\n");
2771 if (b
->related_breakpoint
)
2772 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2773 b
->disposition
= disp_del_at_next_stop
;
2779 /* Return true if it looks like target has stopped due to hitting
2780 breakpoint location BL. This function does not check if we
2781 should stop, only if BL explains the stop. */
2783 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2785 struct breakpoint
*b
= bl
->owner
;
2787 if (b
->type
!= bp_watchpoint
2788 && b
->type
!= bp_hardware_watchpoint
2789 && b
->type
!= bp_read_watchpoint
2790 && b
->type
!= bp_access_watchpoint
2791 && b
->type
!= bp_hardware_breakpoint
2792 && b
->type
!= bp_catch_fork
2793 && b
->type
!= bp_catch_vfork
2794 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2796 if (bl
->address
!= bp_addr
) /* address doesn't match */
2798 if (overlay_debugging
/* unmapped overlay section */
2799 && section_is_overlay (bl
->section
)
2800 && !section_is_mapped (bl
->section
))
2804 /* Continuable hardware watchpoints are treated as non-existent if the
2805 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2806 some data address). Otherwise gdb won't stop on a break instruction
2807 in the code (not from a breakpoint) when a hardware watchpoint has
2808 been defined. Also skip watchpoints which we know did not trigger
2809 (did not match the data address). */
2811 if ((b
->type
== bp_hardware_watchpoint
2812 || b
->type
== bp_read_watchpoint
2813 || b
->type
== bp_access_watchpoint
)
2814 && b
->watchpoint_triggered
== watch_triggered_no
)
2817 if (b
->type
== bp_hardware_breakpoint
)
2819 if (bl
->address
!= bp_addr
)
2821 if (overlay_debugging
/* unmapped overlay section */
2822 && section_is_overlay (bl
->section
)
2823 && !section_is_mapped (bl
->section
))
2827 /* Is this a catchpoint of a load or unload? If so, did we
2828 get a load or unload of the specified library? If not,
2830 if ((b
->type
== bp_catch_load
)
2831 #if defined(SOLIB_HAVE_LOAD_EVENT)
2832 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2833 || ((b
->dll_pathname
!= NULL
)
2834 && (strcmp (b
->dll_pathname
,
2835 SOLIB_LOADED_LIBRARY_PATHNAME (
2836 PIDGET (inferior_ptid
)))
2842 if ((b
->type
== bp_catch_unload
)
2843 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2844 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2845 || ((b
->dll_pathname
!= NULL
)
2846 && (strcmp (b
->dll_pathname
,
2847 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2848 PIDGET (inferior_ptid
)))
2854 if ((b
->type
== bp_catch_fork
)
2855 && !inferior_has_forked (inferior_ptid
,
2856 &b
->forked_inferior_pid
))
2859 if ((b
->type
== bp_catch_vfork
)
2860 && !inferior_has_vforked (inferior_ptid
,
2861 &b
->forked_inferior_pid
))
2864 if ((b
->type
== bp_catch_exec
)
2865 && !inferior_has_execd (inferior_ptid
, &b
->exec_pathname
))
2871 /* If BS refers to a watchpoint, determine if the watched values
2872 has actually changed, and we should stop. If not, set BS->stop
2875 bpstat_check_watchpoint (bpstat bs
)
2877 const struct bp_location
*bl
= bs
->breakpoint_at
;
2878 struct breakpoint
*b
= bl
->owner
;
2880 if (b
->type
== bp_watchpoint
2881 || b
->type
== bp_read_watchpoint
2882 || b
->type
== bp_access_watchpoint
2883 || b
->type
== bp_hardware_watchpoint
)
2887 int must_check_value
= 0;
2889 if (b
->type
== bp_watchpoint
)
2890 /* For a software watchpoint, we must always check the
2892 must_check_value
= 1;
2893 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2894 /* We have a hardware watchpoint (read, write, or access)
2895 and the target earlier reported an address watched by
2897 must_check_value
= 1;
2898 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2899 && b
->type
== bp_hardware_watchpoint
)
2900 /* We were stopped by a hardware watchpoint, but the target could
2901 not report the data address. We must check the watchpoint's
2902 value. Access and read watchpoints are out of luck; without
2903 a data address, we can't figure it out. */
2904 must_check_value
= 1;
2906 if (must_check_value
)
2908 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2910 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2911 int e
= catch_errors (watchpoint_check
, bs
, message
,
2913 do_cleanups (cleanups
);
2917 /* We've already printed what needs to be printed. */
2918 bs
->print_it
= print_it_done
;
2921 case WP_VALUE_CHANGED
:
2922 if (b
->type
== bp_read_watchpoint
)
2924 /* Don't stop: read watchpoints shouldn't fire if
2925 the value has changed. This is for targets
2926 which cannot set read-only watchpoints. */
2927 bs
->print_it
= print_it_noop
;
2931 case WP_VALUE_NOT_CHANGED
:
2932 if (b
->type
== bp_hardware_watchpoint
2933 || b
->type
== bp_watchpoint
)
2935 /* Don't stop: write watchpoints shouldn't fire if
2936 the value hasn't changed. */
2937 bs
->print_it
= print_it_noop
;
2945 /* Error from catch_errors. */
2946 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2947 if (b
->related_breakpoint
)
2948 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2949 b
->disposition
= disp_del_at_next_stop
;
2950 /* We've already printed what needs to be printed. */
2951 bs
->print_it
= print_it_done
;
2955 else /* must_check_value == 0 */
2957 /* This is a case where some watchpoint(s) triggered, but
2958 not at the address of this watchpoint, or else no
2959 watchpoint triggered after all. So don't print
2960 anything for this watchpoint. */
2961 bs
->print_it
= print_it_noop
;
2968 /* Check conditions (condition proper, frame, thread and ignore count)
2969 of breakpoint referred to by BS. If we should not stop for this
2970 breakpoint, set BS->stop to 0. */
2972 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2974 int thread_id
= pid_to_thread_id (ptid
);
2975 const struct bp_location
*bl
= bs
->breakpoint_at
;
2976 struct breakpoint
*b
= bl
->owner
;
2978 if (frame_id_p (b
->frame_id
)
2979 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2983 int value_is_zero
= 0;
2985 /* If this is a scope breakpoint, mark the associated
2986 watchpoint as triggered so that we will handle the
2987 out-of-scope event. We'll get to the watchpoint next
2989 if (b
->type
== bp_watchpoint_scope
)
2990 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2992 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2994 /* Need to select the frame, with all that implies
2995 so that the conditions will have the right context. */
2996 select_frame (get_current_frame ());
2998 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2999 "Error in testing breakpoint condition:\n",
3001 /* FIXME-someday, should give breakpoint # */
3004 if (bl
->cond
&& value_is_zero
)
3008 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3012 else if (b
->ignore_count
> 0)
3015 annotate_ignore_count_change ();
3017 /* Increase the hit count even though we don't
3025 /* Get a bpstat associated with having just stopped at address
3026 BP_ADDR in thread PTID.
3028 Determine whether we stopped at a breakpoint, etc, or whether we
3029 don't understand this stop. Result is a chain of bpstat's such that:
3031 if we don't understand the stop, the result is a null pointer.
3033 if we understand why we stopped, the result is not null.
3035 Each element of the chain refers to a particular breakpoint or
3036 watchpoint at which we have stopped. (We may have stopped for
3037 several reasons concurrently.)
3039 Each element of the chain has valid next, breakpoint_at,
3040 commands, FIXME??? fields. */
3043 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3045 struct breakpoint
*b
= NULL
;
3046 const struct bp_location
*bl
;
3047 struct bp_location
*loc
;
3048 /* Root of the chain of bpstat's */
3049 struct bpstats root_bs
[1];
3050 /* Pointer to the last thing in the chain currently. */
3051 bpstat bs
= root_bs
;
3053 int need_remove_insert
;
3055 ALL_BP_LOCATIONS (bl
)
3059 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3062 /* For hardware watchpoints, we look only at the first location.
3063 The watchpoint_check function will work on entire expression,
3064 not the individual locations. For read watchopints, the
3065 watchpoints_triggered function have checked all locations
3068 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3071 if (!bpstat_check_location (bl
, bp_addr
))
3074 /* Come here if it's a watchpoint, or if the break address matches */
3076 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3078 /* Assume we stop. Should we find watchpoint that is not actually
3079 triggered, or if condition of breakpoint is false, we'll reset
3084 bpstat_check_watchpoint (bs
);
3088 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3089 /* We do not stop for these. */
3092 bpstat_check_breakpoint_conditions (bs
, ptid
);
3098 /* We will stop here */
3099 if (b
->disposition
== disp_disable
)
3101 if (b
->enable_state
!= bp_permanent
)
3102 b
->enable_state
= bp_disabled
;
3103 update_global_location_list (0);
3107 bs
->commands
= b
->commands
;
3109 (strcmp ("silent", bs
->commands
->line
) == 0
3110 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3112 bs
->commands
= bs
->commands
->next
;
3115 bs
->commands
= copy_command_lines (bs
->commands
);
3118 /* Print nothing for this entry if we dont stop or if we dont print. */
3119 if (bs
->stop
== 0 || bs
->print
== 0)
3120 bs
->print_it
= print_it_noop
;
3123 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3125 if (loc
->address
== bp_addr
)
3127 bs
= bpstat_alloc (loc
, bs
);
3128 /* For hits of moribund locations, we should just proceed. */
3131 bs
->print_it
= print_it_noop
;
3135 bs
->next
= NULL
; /* Terminate the chain */
3136 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3138 /* If we aren't stopping, the value of some hardware watchpoint may
3139 not have changed, but the intermediate memory locations we are
3140 watching may have. Don't bother if we're stopping; this will get
3142 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3146 need_remove_insert
= 0;
3148 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3150 && bs
->breakpoint_at
->owner
3151 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3152 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3153 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3155 /* remove/insert can invalidate bs->breakpoint_at, if this
3156 location is no longer used by the watchpoint. Prevent
3157 further code from trying to use it. */
3158 bs
->breakpoint_at
= NULL
;
3159 need_remove_insert
= 1;
3162 if (need_remove_insert
)
3164 remove_breakpoints ();
3165 insert_breakpoints ();
3168 return root_bs
->next
;
3171 /* Tell what to do about this bpstat. */
3173 bpstat_what (bpstat bs
)
3175 /* Classify each bpstat as one of the following. */
3178 /* This bpstat element has no effect on the main_action. */
3181 /* There was a watchpoint, stop but don't print. */
3184 /* There was a watchpoint, stop and print. */
3187 /* There was a breakpoint but we're not stopping. */
3190 /* There was a breakpoint, stop but don't print. */
3193 /* There was a breakpoint, stop and print. */
3196 /* We hit the longjmp breakpoint. */
3199 /* We hit the longjmp_resume breakpoint. */
3202 /* We hit the step_resume breakpoint. */
3205 /* We hit the shared library event breakpoint. */
3208 /* We caught a shared library event. */
3211 /* This is just used to count how many enums there are. */
3215 /* Here is the table which drives this routine. So that we can
3216 format it pretty, we define some abbreviations for the
3217 enum bpstat_what codes. */
3218 #define kc BPSTAT_WHAT_KEEP_CHECKING
3219 #define ss BPSTAT_WHAT_STOP_SILENT
3220 #define sn BPSTAT_WHAT_STOP_NOISY
3221 #define sgl BPSTAT_WHAT_SINGLE
3222 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3223 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3224 #define sr BPSTAT_WHAT_STEP_RESUME
3225 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3226 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3228 /* "Can't happen." Might want to print an error message.
3229 abort() is not out of the question, but chances are GDB is just
3230 a bit confused, not unusable. */
3231 #define err BPSTAT_WHAT_STOP_NOISY
3233 /* Given an old action and a class, come up with a new action. */
3234 /* One interesting property of this table is that wp_silent is the same
3235 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3236 after stopping, the check for whether to step over a breakpoint
3237 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3238 reference to how we stopped. We retain separate wp_silent and
3239 bp_silent codes in case we want to change that someday.
3241 Another possibly interesting property of this table is that
3242 there's a partial ordering, priority-like, of the actions. Once
3243 you've decided that some action is appropriate, you'll never go
3244 back and decide something of a lower priority is better. The
3247 kc < clr sgl shl shlr slr sn sr ss
3248 sgl < shl shlr slr sn sr ss
3249 slr < err shl shlr sn sr ss
3250 clr < err shl shlr sn sr ss
3257 What I think this means is that we don't need a damned table
3258 here. If you just put the rows and columns in the right order,
3259 it'd look awfully regular. We could simply walk the bpstat list
3260 and choose the highest priority action we find, with a little
3261 logic to handle the 'err' cases. */
3263 /* step_resume entries: a step resume breakpoint overrides another
3264 breakpoint of signal handling (see comment in wait_for_inferior
3265 at where we set the step_resume breakpoint). */
3267 static const enum bpstat_what_main_action
3268 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3271 /* kc ss sn sgl slr clr sr shl shlr
3274 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3276 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3278 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3280 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3282 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3284 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3286 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3288 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3290 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3292 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3294 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3308 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3309 struct bpstat_what retval
;
3311 retval
.call_dummy
= 0;
3312 for (; bs
!= NULL
; bs
= bs
->next
)
3314 enum class bs_class
= no_effect
;
3315 if (bs
->breakpoint_at
== NULL
)
3316 /* I suspect this can happen if it was a momentary breakpoint
3317 which has since been deleted. */
3319 if (bs
->breakpoint_at
->owner
== NULL
)
3320 bs_class
= bp_nostop
;
3322 switch (bs
->breakpoint_at
->owner
->type
)
3328 case bp_hardware_breakpoint
:
3334 bs_class
= bp_noisy
;
3336 bs_class
= bp_silent
;
3339 bs_class
= bp_nostop
;
3342 case bp_hardware_watchpoint
:
3343 case bp_read_watchpoint
:
3344 case bp_access_watchpoint
:
3348 bs_class
= wp_noisy
;
3350 bs_class
= wp_silent
;
3353 /* There was a watchpoint, but we're not stopping.
3354 This requires no further action. */
3355 bs_class
= no_effect
;
3358 bs_class
= long_jump
;
3360 case bp_longjmp_resume
:
3361 bs_class
= long_resume
;
3363 case bp_step_resume
:
3366 bs_class
= step_resume
;
3369 /* It is for the wrong frame. */
3370 bs_class
= bp_nostop
;
3372 case bp_watchpoint_scope
:
3373 bs_class
= bp_nostop
;
3375 case bp_shlib_event
:
3376 bs_class
= shlib_event
;
3378 case bp_thread_event
:
3379 case bp_overlay_event
:
3380 bs_class
= bp_nostop
;
3383 case bp_catch_unload
:
3384 /* Only if this catchpoint triggered should we cause the
3385 step-out-of-dld behaviour. Otherwise, we ignore this
3388 bs_class
= catch_shlib_event
;
3390 bs_class
= no_effect
;
3393 case bp_catch_vfork
:
3398 bs_class
= bp_noisy
;
3400 bs_class
= bp_silent
;
3403 /* There was a catchpoint, but we're not stopping.
3404 This requires no further action. */
3405 bs_class
= no_effect
;
3408 /* Make sure the action is stop (silent or noisy),
3409 so infrun.c pops the dummy frame. */
3410 bs_class
= bp_silent
;
3411 retval
.call_dummy
= 1;
3414 current_action
= table
[(int) bs_class
][(int) current_action
];
3416 retval
.main_action
= current_action
;
3420 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3421 without hardware support). This isn't related to a specific bpstat,
3422 just to things like whether watchpoints are set. */
3425 bpstat_should_step (void)
3427 struct breakpoint
*b
;
3429 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3436 /* Given a bpstat that records zero or more triggered eventpoints, this
3437 function returns another bpstat which contains only the catchpoints
3438 on that first list, if any. */
3440 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3442 struct bpstats root_bs
[1];
3443 bpstat bs
= root_bs
;
3444 struct breakpoint
*ep
;
3447 bpstat_clear (cp_list
);
3448 root_bs
->next
= NULL
;
3450 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3452 /* Is this eventpoint a catchpoint? If not, ignore it. */
3453 ep
= ep_list
->breakpoint_at
->owner
;
3456 if ((ep
->type
!= bp_catch_load
) &&
3457 (ep
->type
!= bp_catch_unload
))
3458 /* pai: (temp) ADD fork/vfork here!! */
3461 /* Yes; add it to the list. */
3462 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3467 #if defined(SOLIB_ADD)
3468 /* Also, for each triggered catchpoint, tag it with the name of
3469 the library that caused this trigger. (We copy the name now,
3470 because it's only guaranteed to be available NOW, when the
3471 catchpoint triggers. Clients who may wish to know the name
3472 later must get it from the catchpoint itself.) */
3473 if (ep
->triggered_dll_pathname
!= NULL
)
3474 xfree (ep
->triggered_dll_pathname
);
3475 if (ep
->type
== bp_catch_load
)
3476 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3477 PIDGET (inferior_ptid
));
3479 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3480 PIDGET (inferior_ptid
));
3482 dll_pathname
= NULL
;
3486 ep
->triggered_dll_pathname
= (char *)
3487 xmalloc (strlen (dll_pathname
) + 1);
3488 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3491 ep
->triggered_dll_pathname
= NULL
;
3497 static void print_breakpoint_location (struct breakpoint
*b
,
3498 struct bp_location
*loc
,
3500 struct ui_stream
*stb
)
3505 = find_pc_sect_function (loc
->address
, loc
->section
);
3508 ui_out_text (uiout
, "in ");
3509 ui_out_field_string (uiout
, "func",
3510 SYMBOL_PRINT_NAME (sym
));
3511 ui_out_wrap_hint (uiout
, wrap_indent
);
3512 ui_out_text (uiout
, " at ");
3514 ui_out_field_string (uiout
, "file", b
->source_file
);
3515 ui_out_text (uiout
, ":");
3517 if (ui_out_is_mi_like_p (uiout
))
3519 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3520 char *fullname
= symtab_to_fullname (sal
.symtab
);
3523 ui_out_field_string (uiout
, "fullname", fullname
);
3526 ui_out_field_int (uiout
, "line", b
->line_number
);
3530 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3534 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3535 ui_out_field_stream (uiout
, "at", stb
);
3539 /* Print B to gdb_stdout. */
3541 print_one_breakpoint_location (struct breakpoint
*b
,
3542 struct bp_location
*loc
,
3544 CORE_ADDR
*last_addr
)
3546 struct command_line
*l
;
3548 struct ep_type_description
3553 static struct ep_type_description bptypes
[] =
3555 {bp_none
, "?deleted?"},
3556 {bp_breakpoint
, "breakpoint"},
3557 {bp_hardware_breakpoint
, "hw breakpoint"},
3558 {bp_until
, "until"},
3559 {bp_finish
, "finish"},
3560 {bp_watchpoint
, "watchpoint"},
3561 {bp_hardware_watchpoint
, "hw watchpoint"},
3562 {bp_read_watchpoint
, "read watchpoint"},
3563 {bp_access_watchpoint
, "acc watchpoint"},
3564 {bp_longjmp
, "longjmp"},
3565 {bp_longjmp_resume
, "longjmp resume"},
3566 {bp_step_resume
, "step resume"},
3567 {bp_watchpoint_scope
, "watchpoint scope"},
3568 {bp_call_dummy
, "call dummy"},
3569 {bp_shlib_event
, "shlib events"},
3570 {bp_thread_event
, "thread events"},
3571 {bp_overlay_event
, "overlay events"},
3572 {bp_catch_load
, "catch load"},
3573 {bp_catch_unload
, "catch unload"},
3574 {bp_catch_fork
, "catch fork"},
3575 {bp_catch_vfork
, "catch vfork"},
3576 {bp_catch_exec
, "catch exec"}
3579 static char bpenables
[] = "nynny";
3580 char wrap_indent
[80];
3581 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3582 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3583 struct cleanup
*bkpt_chain
;
3585 int header_of_multiple
= 0;
3586 int part_of_multiple
= (loc
!= NULL
);
3588 gdb_assert (!loc
|| loc_number
!= 0);
3589 /* See comment in print_one_breakpoint concerning
3590 treatment of breakpoints with single disabled
3594 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3595 header_of_multiple
= 1;
3600 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3604 if (part_of_multiple
)
3607 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3608 ui_out_field_string (uiout
, "number", formatted
);
3613 ui_out_field_int (uiout
, "number", b
->number
);
3618 if (part_of_multiple
)
3619 ui_out_field_skip (uiout
, "type");
3622 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3623 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3624 internal_error (__FILE__
, __LINE__
,
3625 _("bptypes table does not describe type #%d."),
3627 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3632 if (part_of_multiple
)
3633 ui_out_field_skip (uiout
, "disp");
3635 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3640 if (part_of_multiple
)
3641 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3643 ui_out_field_fmt (uiout
, "enabled", "%c",
3644 bpenables
[(int) b
->enable_state
]);
3645 ui_out_spaces (uiout
, 2);
3649 strcpy (wrap_indent
, " ");
3652 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3653 strcat (wrap_indent
, " ");
3655 strcat (wrap_indent
, " ");
3658 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3660 /* Although the print_one can possibly print
3661 all locations, calling it here is not likely
3662 to get any nice result. So, make sure there's
3663 just one location. */
3664 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3665 b
->ops
->print_one (b
, last_addr
);
3671 internal_error (__FILE__
, __LINE__
,
3672 _("print_one_breakpoint: bp_none encountered\n"));
3676 case bp_hardware_watchpoint
:
3677 case bp_read_watchpoint
:
3678 case bp_access_watchpoint
:
3679 /* Field 4, the address, is omitted (which makes the columns
3680 not line up too nicely with the headers, but the effect
3681 is relatively readable). */
3683 ui_out_field_skip (uiout
, "addr");
3685 print_expression (b
->exp
, stb
->stream
);
3686 ui_out_field_stream (uiout
, "what", stb
);
3690 case bp_catch_unload
:
3691 /* Field 4, the address, is omitted (which makes the columns
3692 not line up too nicely with the headers, but the effect
3693 is relatively readable). */
3695 ui_out_field_skip (uiout
, "addr");
3697 if (b
->dll_pathname
== NULL
)
3699 ui_out_field_string (uiout
, "what", "<any library>");
3700 ui_out_spaces (uiout
, 1);
3704 ui_out_text (uiout
, "library \"");
3705 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3706 ui_out_text (uiout
, "\" ");
3711 case bp_catch_vfork
:
3712 /* Field 4, the address, is omitted (which makes the columns
3713 not line up too nicely with the headers, but the effect
3714 is relatively readable). */
3716 ui_out_field_skip (uiout
, "addr");
3718 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
3720 ui_out_text (uiout
, "process ");
3721 ui_out_field_int (uiout
, "what",
3722 ptid_get_pid (b
->forked_inferior_pid
));
3723 ui_out_spaces (uiout
, 1);
3728 /* Field 4, the address, is omitted (which makes the columns
3729 not line up too nicely with the headers, but the effect
3730 is relatively readable). */
3732 ui_out_field_skip (uiout
, "addr");
3734 if (b
->exec_pathname
!= NULL
)
3736 ui_out_text (uiout
, "program \"");
3737 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3738 ui_out_text (uiout
, "\" ");
3743 case bp_hardware_breakpoint
:
3747 case bp_longjmp_resume
:
3748 case bp_step_resume
:
3749 case bp_watchpoint_scope
:
3751 case bp_shlib_event
:
3752 case bp_thread_event
:
3753 case bp_overlay_event
:
3757 if (header_of_multiple
)
3758 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3759 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3760 ui_out_field_string (uiout
, "addr", "<PENDING>");
3762 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3765 if (!header_of_multiple
)
3766 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3768 *last_addr
= b
->loc
->address
;
3772 if (!part_of_multiple
&& b
->thread
!= -1)
3774 /* FIXME: This seems to be redundant and lost here; see the
3775 "stop only in" line a little further down. */
3776 ui_out_text (uiout
, " thread ");
3777 ui_out_field_int (uiout
, "thread", b
->thread
);
3780 ui_out_text (uiout
, "\n");
3782 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3785 ui_out_text (uiout
, "\tstop only in stack frame at ");
3786 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3788 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3789 ui_out_text (uiout
, "\n");
3792 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3794 /* We do not print the condition for Ada exception catchpoints
3795 because the condition is an internal implementation detail
3796 that we do not want to expose to the user. */
3798 ui_out_text (uiout
, "\tstop only if ");
3799 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3800 ui_out_text (uiout
, "\n");
3803 if (!part_of_multiple
&& b
->thread
!= -1)
3805 /* FIXME should make an annotation for this */
3806 ui_out_text (uiout
, "\tstop only in thread ");
3807 ui_out_field_int (uiout
, "thread", b
->thread
);
3808 ui_out_text (uiout
, "\n");
3811 if (!part_of_multiple
&& b
->hit_count
)
3813 /* FIXME should make an annotation for this */
3814 if (ep_is_catchpoint (b
))
3815 ui_out_text (uiout
, "\tcatchpoint");
3817 ui_out_text (uiout
, "\tbreakpoint");
3818 ui_out_text (uiout
, " already hit ");
3819 ui_out_field_int (uiout
, "times", b
->hit_count
);
3820 if (b
->hit_count
== 1)
3821 ui_out_text (uiout
, " time\n");
3823 ui_out_text (uiout
, " times\n");
3826 /* Output the count also if it is zero, but only if this is
3827 mi. FIXME: Should have a better test for this. */
3828 if (ui_out_is_mi_like_p (uiout
))
3829 if (!part_of_multiple
&& b
->hit_count
== 0)
3830 ui_out_field_int (uiout
, "times", b
->hit_count
);
3832 if (!part_of_multiple
&& b
->ignore_count
)
3835 ui_out_text (uiout
, "\tignore next ");
3836 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3837 ui_out_text (uiout
, " hits\n");
3840 if (!part_of_multiple
&& (l
= b
->commands
))
3842 struct cleanup
*script_chain
;
3845 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3846 print_command_lines (uiout
, l
, 4);
3847 do_cleanups (script_chain
);
3850 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3853 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3854 else if (b
->exp_string
)
3855 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3858 do_cleanups (bkpt_chain
);
3859 do_cleanups (old_chain
);
3863 print_one_breakpoint (struct breakpoint
*b
,
3864 CORE_ADDR
*last_addr
)
3866 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3868 /* If this breakpoint has custom print function,
3869 it's already printed. Otherwise, print individual
3870 locations, if any. */
3871 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3873 /* If breakpoint has a single location that is
3874 disabled, we print it as if it had
3875 several locations, since otherwise it's hard to
3876 represent "breakpoint enabled, location disabled"
3878 Note that while hardware watchpoints have
3879 several locations internally, that's no a property
3882 && !is_hardware_watchpoint (b
)
3883 && (b
->loc
->next
|| !b
->loc
->enabled
)
3884 && !ui_out_is_mi_like_p (uiout
))
3886 struct bp_location
*loc
;
3888 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3889 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3895 struct captured_breakpoint_query_args
3901 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3903 struct captured_breakpoint_query_args
*args
= data
;
3904 struct breakpoint
*b
;
3905 CORE_ADDR dummy_addr
= 0;
3908 if (args
->bnum
== b
->number
)
3910 print_one_breakpoint (b
, &dummy_addr
);
3918 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3920 struct captured_breakpoint_query_args args
;
3922 /* For the moment we don't trust print_one_breakpoint() to not throw
3924 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3925 error_message
, RETURN_MASK_ALL
) < 0)
3931 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3932 catchpoints, et.al.). */
3935 user_settable_breakpoint (const struct breakpoint
*b
)
3937 return (b
->type
== bp_breakpoint
3938 || b
->type
== bp_catch_load
3939 || b
->type
== bp_catch_unload
3940 || b
->type
== bp_catch_fork
3941 || b
->type
== bp_catch_vfork
3942 || b
->type
== bp_catch_exec
3943 || b
->type
== bp_hardware_breakpoint
3944 || b
->type
== bp_watchpoint
3945 || b
->type
== bp_read_watchpoint
3946 || b
->type
== bp_access_watchpoint
3947 || b
->type
== bp_hardware_watchpoint
);
3950 /* Print information on user settable breakpoint (watchpoint, etc)
3951 number BNUM. If BNUM is -1 print all user settable breakpoints.
3952 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3955 breakpoint_1 (int bnum
, int allflag
)
3957 struct breakpoint
*b
;
3958 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3959 int nr_printable_breakpoints
;
3960 struct cleanup
*bkpttbl_chain
;
3962 /* Compute the number of rows in the table. */
3963 nr_printable_breakpoints
= 0;
3966 || bnum
== b
->number
)
3968 if (allflag
|| user_settable_breakpoint (b
))
3969 nr_printable_breakpoints
++;
3974 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3978 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3981 if (nr_printable_breakpoints
> 0)
3982 annotate_breakpoints_headers ();
3983 if (nr_printable_breakpoints
> 0)
3985 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3986 if (nr_printable_breakpoints
> 0)
3988 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3989 if (nr_printable_breakpoints
> 0)
3991 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3992 if (nr_printable_breakpoints
> 0)
3994 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3997 if (nr_printable_breakpoints
> 0)
3999 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
4000 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4002 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4004 if (nr_printable_breakpoints
> 0)
4006 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4007 ui_out_table_body (uiout
);
4008 if (nr_printable_breakpoints
> 0)
4009 annotate_breakpoints_table ();
4013 || bnum
== b
->number
)
4015 /* We only print out user settable breakpoints unless the
4017 if (allflag
|| user_settable_breakpoint (b
))
4018 print_one_breakpoint (b
, &last_addr
);
4021 do_cleanups (bkpttbl_chain
);
4023 if (nr_printable_breakpoints
== 0)
4026 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4028 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4033 /* Compare against (CORE_ADDR)-1 in case some compiler decides
4034 that a comparison of an unsigned with -1 is always false. */
4035 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
4036 set_next_address (current_gdbarch
, last_addr
);
4039 /* FIXME? Should this be moved up so that it is only called when
4040 there have been breakpoints? */
4041 annotate_breakpoints_table_end ();
4045 breakpoints_info (char *bnum_exp
, int from_tty
)
4050 bnum
= parse_and_eval_long (bnum_exp
);
4052 breakpoint_1 (bnum
, 0);
4056 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4061 bnum
= parse_and_eval_long (bnum_exp
);
4063 breakpoint_1 (bnum
, 1);
4067 breakpoint_has_pc (struct breakpoint
*b
,
4068 CORE_ADDR pc
, struct obj_section
*section
)
4070 struct bp_location
*bl
= b
->loc
;
4071 for (; bl
; bl
= bl
->next
)
4073 if (bl
->address
== pc
4074 && (!overlay_debugging
|| bl
->section
== section
))
4080 /* Print a message describing any breakpoints set at PC. */
4083 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
4087 struct breakpoint
*b
;
4090 others
+= breakpoint_has_pc (b
, pc
, section
);
4094 printf_filtered (_("Note: breakpoint "));
4095 else /* if (others == ???) */
4096 printf_filtered (_("Note: breakpoints "));
4098 if (breakpoint_has_pc (b
, pc
, section
))
4101 printf_filtered ("%d", b
->number
);
4102 if (b
->thread
== -1 && thread
!= -1)
4103 printf_filtered (" (all threads)");
4104 else if (b
->thread
!= -1)
4105 printf_filtered (" (thread %d)", b
->thread
);
4106 printf_filtered ("%s%s ",
4107 ((b
->enable_state
== bp_disabled
||
4108 b
->enable_state
== bp_call_disabled
)
4110 : b
->enable_state
== bp_permanent
4114 : ((others
== 1) ? " and" : ""));
4116 printf_filtered (_("also set at pc "));
4117 fputs_filtered (paddress (pc
), gdb_stdout
);
4118 printf_filtered (".\n");
4122 /* Set the default place to put a breakpoint
4123 for the `break' command with no arguments. */
4126 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4129 default_breakpoint_valid
= valid
;
4130 default_breakpoint_address
= addr
;
4131 default_breakpoint_symtab
= symtab
;
4132 default_breakpoint_line
= line
;
4135 /* Return true iff it is meaningful to use the address member of
4136 BPT. For some breakpoint types, the address member is irrelevant
4137 and it makes no sense to attempt to compare it to other addresses
4138 (or use it for any other purpose either).
4140 More specifically, each of the following breakpoint types will always
4141 have a zero valued address and we don't want check_duplicates() to mark
4142 breakpoints of any of these types to be a duplicate of an actual
4143 breakpoint at address zero:
4146 bp_hardware_watchpoint
4148 bp_access_watchpoint
4154 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4156 enum bptype type
= bpt
->type
;
4158 return (type
!= bp_watchpoint
4159 && type
!= bp_hardware_watchpoint
4160 && type
!= bp_read_watchpoint
4161 && type
!= bp_access_watchpoint
4162 && type
!= bp_catch_exec
4163 && type
!= bp_catch_fork
4164 && type
!= bp_catch_vfork
);
4167 /* Rescan breakpoints at the same address and section as BPT,
4168 marking the first one as "first" and any others as "duplicates".
4169 This is so that the bpt instruction is only inserted once.
4170 If we have a permanent breakpoint at the same place as BPT, make
4171 that one the official one, and the rest as duplicates. */
4174 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4176 struct bp_location
*b
;
4178 struct bp_location
*perm_bp
= 0;
4180 ALL_BP_LOCATIONS (b
)
4181 if (b
->owner
->enable_state
!= bp_disabled
4182 && b
->owner
->enable_state
!= bp_call_disabled
4184 && !b
->shlib_disabled
4185 && b
->address
== address
/* address / overlay match */
4186 && (!overlay_debugging
|| b
->section
== section
)
4187 && breakpoint_address_is_meaningful (b
->owner
))
4189 /* Have we found a permanent breakpoint? */
4190 if (b
->owner
->enable_state
== bp_permanent
)
4197 b
->duplicate
= count
> 1;
4200 /* If we found a permanent breakpoint at this address, go over the
4201 list again and declare all the other breakpoints there to be the
4205 perm_bp
->duplicate
= 0;
4207 /* Permanent breakpoint should always be inserted. */
4208 if (! perm_bp
->inserted
)
4209 internal_error (__FILE__
, __LINE__
,
4210 _("allegedly permanent breakpoint is not "
4211 "actually inserted"));
4213 ALL_BP_LOCATIONS (b
)
4216 if (b
->owner
->enable_state
!= bp_disabled
4217 && b
->owner
->enable_state
!= bp_call_disabled
4218 && b
->enabled
&& !b
->shlib_disabled
4219 && b
->address
== address
/* address / overlay match */
4220 && (!overlay_debugging
|| b
->section
== section
)
4221 && breakpoint_address_is_meaningful (b
->owner
))
4224 internal_error (__FILE__
, __LINE__
,
4225 _("another breakpoint was inserted on top of "
4226 "a permanent breakpoint"));
4235 check_duplicates (struct breakpoint
*bpt
)
4237 struct bp_location
*bl
= bpt
->loc
;
4239 if (! breakpoint_address_is_meaningful (bpt
))
4242 for (; bl
; bl
= bl
->next
)
4243 check_duplicates_for (bl
->address
, bl
->section
);
4247 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4248 int bnum
, int have_bnum
)
4253 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4254 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4256 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4257 bnum
, astr1
, astr2
);
4259 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4262 /* Adjust a breakpoint's address to account for architectural constraints
4263 on breakpoint placement. Return the adjusted address. Note: Very
4264 few targets require this kind of adjustment. For most targets,
4265 this function is simply the identity function. */
4268 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4270 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4272 /* Very few targets need any kind of breakpoint adjustment. */
4275 else if (bptype
== bp_watchpoint
4276 || bptype
== bp_hardware_watchpoint
4277 || bptype
== bp_read_watchpoint
4278 || bptype
== bp_access_watchpoint
4279 || bptype
== bp_catch_fork
4280 || bptype
== bp_catch_vfork
4281 || bptype
== bp_catch_exec
)
4283 /* Watchpoints and the various bp_catch_* eventpoints should not
4284 have their addresses modified. */
4289 CORE_ADDR adjusted_bpaddr
;
4291 /* Some targets have architectural constraints on the placement
4292 of breakpoint instructions. Obtain the adjusted address. */
4293 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4296 /* An adjusted breakpoint address can significantly alter
4297 a user's expectations. Print a warning if an adjustment
4299 if (adjusted_bpaddr
!= bpaddr
)
4300 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4302 return adjusted_bpaddr
;
4306 /* Allocate a struct bp_location. */
4308 static struct bp_location
*
4309 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4311 struct bp_location
*loc
, *loc_p
;
4313 loc
= xmalloc (sizeof (struct bp_location
));
4314 memset (loc
, 0, sizeof (*loc
));
4318 loc
->shlib_disabled
= 0;
4327 case bp_longjmp_resume
:
4328 case bp_step_resume
:
4329 case bp_watchpoint_scope
:
4331 case bp_shlib_event
:
4332 case bp_thread_event
:
4333 case bp_overlay_event
:
4335 case bp_catch_unload
:
4336 loc
->loc_type
= bp_loc_software_breakpoint
;
4338 case bp_hardware_breakpoint
:
4339 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4341 case bp_hardware_watchpoint
:
4342 case bp_read_watchpoint
:
4343 case bp_access_watchpoint
:
4344 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4348 case bp_catch_vfork
:
4350 loc
->loc_type
= bp_loc_other
;
4353 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4359 static void free_bp_location (struct bp_location
*loc
)
4364 if (loc
->function_name
)
4365 xfree (loc
->function_name
);
4370 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4371 that has type BPTYPE and has no locations as yet. */
4373 static struct breakpoint
*
4374 set_raw_breakpoint_without_location (enum bptype bptype
)
4376 struct breakpoint
*b
, *b1
;
4378 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4379 memset (b
, 0, sizeof (*b
));
4382 b
->language
= current_language
->la_language
;
4383 b
->input_radix
= input_radix
;
4385 b
->enable_state
= bp_enabled
;
4388 b
->ignore_count
= 0;
4390 b
->frame_id
= null_frame_id
;
4391 b
->dll_pathname
= NULL
;
4392 b
->triggered_dll_pathname
= NULL
;
4393 b
->forked_inferior_pid
= null_ptid
;
4394 b
->exec_pathname
= NULL
;
4396 b
->condition_not_parsed
= 0;
4398 /* Add this breakpoint to the end of the chain
4399 so that a list of breakpoints will come out in order
4400 of increasing numbers. */
4402 b1
= breakpoint_chain
;
4404 breakpoint_chain
= b
;
4414 /* Initialize loc->function_name. */
4416 set_breakpoint_location_function (struct bp_location
*loc
)
4418 if (loc
->owner
->type
== bp_breakpoint
4419 || loc
->owner
->type
== bp_hardware_breakpoint
)
4421 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4423 if (loc
->function_name
)
4424 loc
->function_name
= xstrdup (loc
->function_name
);
4428 /* set_raw_breakpoint is a low level routine for allocating and
4429 partially initializing a breakpoint of type BPTYPE. The newly
4430 created breakpoint's address, section, source file name, and line
4431 number are provided by SAL. The newly created and partially
4432 initialized breakpoint is added to the breakpoint chain and
4433 is also returned as the value of this function.
4435 It is expected that the caller will complete the initialization of
4436 the newly created breakpoint struct as well as output any status
4437 information regarding the creation of a new breakpoint. In
4438 particular, set_raw_breakpoint does NOT set the breakpoint
4439 number! Care should be taken to not allow an error to occur
4440 prior to completing the initialization of the breakpoint. If this
4441 should happen, a bogus breakpoint will be left on the chain. */
4444 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4446 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4447 CORE_ADDR adjusted_address
;
4449 /* Adjust the breakpoint's address prior to allocating a location.
4450 Once we call allocate_bp_location(), that mostly uninitialized
4451 location will be placed on the location chain. Adjustment of the
4452 breakpoint may cause target_read_memory() to be called and we do
4453 not want its scan of the location chain to find a breakpoint and
4454 location that's only been partially initialized. */
4455 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4457 b
->loc
= allocate_bp_location (b
, bptype
);
4458 b
->loc
->requested_address
= sal
.pc
;
4459 b
->loc
->address
= adjusted_address
;
4461 if (sal
.symtab
== NULL
)
4462 b
->source_file
= NULL
;
4464 b
->source_file
= savestring (sal
.symtab
->filename
,
4465 strlen (sal
.symtab
->filename
));
4466 b
->loc
->section
= sal
.section
;
4467 b
->line_number
= sal
.line
;
4469 set_breakpoint_location_function (b
->loc
);
4471 breakpoints_changed ();
4477 /* Note that the breakpoint object B describes a permanent breakpoint
4478 instruction, hard-wired into the inferior's code. */
4480 make_breakpoint_permanent (struct breakpoint
*b
)
4482 struct bp_location
*bl
;
4483 b
->enable_state
= bp_permanent
;
4485 /* By definition, permanent breakpoints are already present in the code.
4486 Mark all locations as inserted. For now, make_breakpoint_permanent
4487 is called in just one place, so it's hard to say if it's reasonable
4488 to have permanent breakpoint with multiple locations or not,
4489 but it's easy to implmement. */
4490 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4494 static struct breakpoint
*
4495 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4497 static int internal_breakpoint_number
= -1;
4498 struct symtab_and_line sal
;
4499 struct breakpoint
*b
;
4501 init_sal (&sal
); /* initialize to zeroes */
4504 sal
.section
= find_pc_overlay (sal
.pc
);
4506 b
= set_raw_breakpoint (sal
, type
);
4507 b
->number
= internal_breakpoint_number
--;
4508 b
->disposition
= disp_donttouch
;
4515 create_longjmp_breakpoint (char *func_name
)
4517 struct minimal_symbol
*m
;
4519 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4521 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4522 update_global_location_list (1);
4525 /* Call this routine when stepping and nexting to enable a breakpoint
4526 if we do a longjmp(). When we hit that breakpoint, call
4527 set_longjmp_resume_breakpoint() to figure out where we are going. */
4530 set_longjmp_breakpoint (void)
4532 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4534 create_longjmp_breakpoint ("longjmp");
4535 create_longjmp_breakpoint ("_longjmp");
4536 create_longjmp_breakpoint ("siglongjmp");
4537 create_longjmp_breakpoint ("_siglongjmp");
4541 /* Delete all longjmp breakpoints from THREAD. */
4543 delete_longjmp_breakpoint (int thread
)
4545 struct breakpoint
*b
, *temp
;
4547 ALL_BREAKPOINTS_SAFE (b
, temp
)
4548 if (b
->type
== bp_longjmp
)
4550 if (b
->thread
== thread
)
4551 delete_breakpoint (b
);
4556 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4558 struct breakpoint
*b
;
4559 struct minimal_symbol
*m
;
4561 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4564 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4566 b
->addr_string
= xstrdup (func_name
);
4568 if (overlay_debugging
== ovly_auto
)
4570 b
->enable_state
= bp_enabled
;
4571 overlay_events_enabled
= 1;
4575 b
->enable_state
= bp_disabled
;
4576 overlay_events_enabled
= 0;
4578 update_global_location_list (1);
4582 create_overlay_event_breakpoint (char *func_name
)
4584 struct objfile
*objfile
;
4585 ALL_OBJFILES (objfile
)
4586 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4590 enable_overlay_breakpoints (void)
4592 struct breakpoint
*b
;
4595 if (b
->type
== bp_overlay_event
)
4597 b
->enable_state
= bp_enabled
;
4598 update_global_location_list (1);
4599 overlay_events_enabled
= 1;
4604 disable_overlay_breakpoints (void)
4606 struct breakpoint
*b
;
4609 if (b
->type
== bp_overlay_event
)
4611 b
->enable_state
= bp_disabled
;
4612 update_global_location_list (0);
4613 overlay_events_enabled
= 0;
4618 create_thread_event_breakpoint (CORE_ADDR address
)
4620 struct breakpoint
*b
;
4622 b
= create_internal_breakpoint (address
, bp_thread_event
);
4624 b
->enable_state
= bp_enabled
;
4625 /* addr_string has to be used or breakpoint_re_set will delete me. */
4626 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4628 update_global_location_list_nothrow (1);
4634 remove_thread_event_breakpoints (void)
4636 struct breakpoint
*b
, *temp
;
4638 ALL_BREAKPOINTS_SAFE (b
, temp
)
4639 if (b
->type
== bp_thread_event
)
4640 delete_breakpoint (b
);
4643 struct captured_parse_breakpoint_args
4646 struct symtabs_and_lines
*sals_p
;
4647 char ***addr_string_p
;
4651 struct lang_and_radix
4659 remove_solib_event_breakpoints (void)
4661 struct breakpoint
*b
, *temp
;
4663 ALL_BREAKPOINTS_SAFE (b
, temp
)
4664 if (b
->type
== bp_shlib_event
)
4665 delete_breakpoint (b
);
4669 create_solib_event_breakpoint (CORE_ADDR address
)
4671 struct breakpoint
*b
;
4673 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4674 update_global_location_list_nothrow (1);
4678 /* Disable any breakpoints that are on code in shared libraries. Only
4679 apply to enabled breakpoints, disabled ones can just stay disabled. */
4682 disable_breakpoints_in_shlibs (void)
4684 struct bp_location
*loc
;
4685 int disabled_shlib_breaks
= 0;
4687 ALL_BP_LOCATIONS (loc
)
4689 struct breakpoint
*b
= loc
->owner
;
4690 /* We apply the check to all breakpoints, including disabled
4691 for those with loc->duplicate set. This is so that when breakpoint
4692 becomes enabled, or the duplicate is removed, gdb will try to insert
4693 all breakpoints. If we don't set shlib_disabled here, we'll try
4694 to insert those breakpoints and fail. */
4695 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4696 && !loc
->shlib_disabled
4698 && PC_SOLIB (loc
->address
)
4700 && solib_address (loc
->address
)
4704 loc
->shlib_disabled
= 1;
4709 /* Disable any breakpoints that are in in an unloaded shared library. Only
4710 apply to enabled breakpoints, disabled ones can just stay disabled. */
4713 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4715 struct bp_location
*loc
;
4716 int disabled_shlib_breaks
= 0;
4718 ALL_BP_LOCATIONS (loc
)
4720 struct breakpoint
*b
= loc
->owner
;
4721 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4722 || loc
->loc_type
== bp_loc_software_breakpoint
)
4723 && !loc
->shlib_disabled
)
4726 char *so_name
= PC_SOLIB (loc
->address
);
4728 char *so_name
= solib_address (loc
->address
);
4730 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4732 loc
->shlib_disabled
= 1;
4733 /* At this point, we cannot rely on remove_breakpoint
4734 succeeding so we must mark the breakpoint as not inserted
4735 to prevent future errors occurring in remove_breakpoints. */
4737 if (!disabled_shlib_breaks
)
4739 target_terminal_ours_for_output ();
4740 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4743 disabled_shlib_breaks
= 1;
4750 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4751 enum bptype bp_kind
)
4753 struct symtab_and_line sal
;
4754 struct breakpoint
*b
;
4755 int thread
= -1; /* All threads. */
4762 b
= set_raw_breakpoint (sal
, bp_kind
);
4763 set_breakpoint_count (breakpoint_count
+ 1);
4764 b
->number
= breakpoint_count
;
4765 b
->cond_string
= (cond_string
== NULL
) ?
4766 NULL
: savestring (cond_string
, strlen (cond_string
));
4768 b
->addr_string
= NULL
;
4769 b
->enable_state
= bp_enabled
;
4770 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4771 b
->forked_inferior_pid
= null_ptid
;
4772 update_global_location_list (1);
4779 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4781 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4785 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4787 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4791 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4793 struct symtab_and_line sal
;
4794 struct breakpoint
*b
;
4795 int thread
= -1; /* All threads. */
4802 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4803 set_breakpoint_count (breakpoint_count
+ 1);
4804 b
->number
= breakpoint_count
;
4805 b
->cond_string
= (cond_string
== NULL
) ?
4806 NULL
: savestring (cond_string
, strlen (cond_string
));
4808 b
->addr_string
= NULL
;
4809 b
->enable_state
= bp_enabled
;
4810 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4811 update_global_location_list (1);
4817 hw_breakpoint_used_count (void)
4819 struct breakpoint
*b
;
4824 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4832 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4834 struct breakpoint
*b
;
4837 *other_type_used
= 0;
4840 if (breakpoint_enabled (b
))
4842 if (b
->type
== type
)
4844 else if ((b
->type
== bp_hardware_watchpoint
||
4845 b
->type
== bp_read_watchpoint
||
4846 b
->type
== bp_access_watchpoint
))
4847 *other_type_used
= 1;
4854 disable_watchpoints_before_interactive_call_start (void)
4856 struct breakpoint
*b
;
4860 if (((b
->type
== bp_watchpoint
)
4861 || (b
->type
== bp_hardware_watchpoint
)
4862 || (b
->type
== bp_read_watchpoint
)
4863 || (b
->type
== bp_access_watchpoint
))
4864 && breakpoint_enabled (b
))
4866 b
->enable_state
= bp_call_disabled
;
4867 update_global_location_list (0);
4873 enable_watchpoints_after_interactive_call_stop (void)
4875 struct breakpoint
*b
;
4879 if (((b
->type
== bp_watchpoint
)
4880 || (b
->type
== bp_hardware_watchpoint
)
4881 || (b
->type
== bp_read_watchpoint
)
4882 || (b
->type
== bp_access_watchpoint
))
4883 && (b
->enable_state
== bp_call_disabled
))
4885 b
->enable_state
= bp_enabled
;
4886 update_global_location_list (1);
4892 /* Set a breakpoint that will evaporate an end of command
4893 at address specified by SAL.
4894 Restrict it to frame FRAME if FRAME is nonzero. */
4897 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4900 struct breakpoint
*b
;
4901 b
= set_raw_breakpoint (sal
, type
);
4902 b
->enable_state
= bp_enabled
;
4903 b
->disposition
= disp_donttouch
;
4904 b
->frame_id
= frame_id
;
4906 /* If we're debugging a multi-threaded program, then we
4907 want momentary breakpoints to be active in only a
4908 single thread of control. */
4909 if (in_thread_list (inferior_ptid
))
4910 b
->thread
= pid_to_thread_id (inferior_ptid
);
4912 update_global_location_list_nothrow (1);
4918 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4920 struct symtab_and_line sal
;
4922 sal
= find_pc_line (pc
, 0);
4924 sal
.section
= find_pc_overlay (pc
);
4925 sal
.explicit_pc
= 1;
4927 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4931 /* Tell the user we have just set a breakpoint B. */
4934 mention (struct breakpoint
*b
)
4937 struct cleanup
*old_chain
, *ui_out_chain
;
4938 struct ui_stream
*stb
;
4940 stb
= ui_out_stream_new (uiout
);
4941 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4943 /* FIXME: This is misplaced; mention() is called by things (like
4944 hitting a watchpoint) other than breakpoint creation. It should
4945 be possible to clean this up and at the same time replace the
4946 random calls to breakpoint_changed with this hook. */
4947 observer_notify_breakpoint_created (b
->number
);
4949 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4950 b
->ops
->print_mention (b
);
4955 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4958 ui_out_text (uiout
, "Watchpoint ");
4959 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4960 ui_out_field_int (uiout
, "number", b
->number
);
4961 ui_out_text (uiout
, ": ");
4962 print_expression (b
->exp
, stb
->stream
);
4963 ui_out_field_stream (uiout
, "exp", stb
);
4964 do_cleanups (ui_out_chain
);
4966 case bp_hardware_watchpoint
:
4967 ui_out_text (uiout
, "Hardware watchpoint ");
4968 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4969 ui_out_field_int (uiout
, "number", b
->number
);
4970 ui_out_text (uiout
, ": ");
4971 print_expression (b
->exp
, stb
->stream
);
4972 ui_out_field_stream (uiout
, "exp", stb
);
4973 do_cleanups (ui_out_chain
);
4975 case bp_read_watchpoint
:
4976 ui_out_text (uiout
, "Hardware read watchpoint ");
4977 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4978 ui_out_field_int (uiout
, "number", b
->number
);
4979 ui_out_text (uiout
, ": ");
4980 print_expression (b
->exp
, stb
->stream
);
4981 ui_out_field_stream (uiout
, "exp", stb
);
4982 do_cleanups (ui_out_chain
);
4984 case bp_access_watchpoint
:
4985 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4986 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4987 ui_out_field_int (uiout
, "number", b
->number
);
4988 ui_out_text (uiout
, ": ");
4989 print_expression (b
->exp
, stb
->stream
);
4990 ui_out_field_stream (uiout
, "exp", stb
);
4991 do_cleanups (ui_out_chain
);
4994 if (ui_out_is_mi_like_p (uiout
))
4999 if (b
->disposition
== disp_del
)
5000 printf_filtered (_("Temporary breakpoint"));
5002 printf_filtered (_("Breakpoint"));
5003 printf_filtered (_(" %d"), b
->number
);
5006 case bp_hardware_breakpoint
:
5007 if (ui_out_is_mi_like_p (uiout
))
5012 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5016 case bp_catch_unload
:
5017 printf_filtered (_("Catchpoint %d (%s %s)"),
5019 (b
->type
== bp_catch_load
) ? "load" : "unload",
5020 (b
->dll_pathname
!= NULL
) ?
5021 b
->dll_pathname
: "<any library>");
5024 case bp_catch_vfork
:
5025 printf_filtered (_("Catchpoint %d (%s)"),
5027 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
5030 printf_filtered (_("Catchpoint %d (exec)"),
5037 case bp_longjmp_resume
:
5038 case bp_step_resume
:
5040 case bp_watchpoint_scope
:
5041 case bp_shlib_event
:
5042 case bp_thread_event
:
5043 case bp_overlay_event
:
5049 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5053 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5057 if (addressprint
|| b
->source_file
== NULL
)
5059 printf_filtered (" at ");
5060 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5063 printf_filtered (": file %s, line %d.",
5064 b
->source_file
, b
->line_number
);
5068 struct bp_location
*loc
= b
->loc
;
5070 for (; loc
; loc
= loc
->next
)
5072 printf_filtered (" (%d locations)", n
);
5077 do_cleanups (old_chain
);
5078 if (ui_out_is_mi_like_p (uiout
))
5080 printf_filtered ("\n");
5084 static struct bp_location
*
5085 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5086 const struct symtab_and_line
*sal
)
5088 struct bp_location
*loc
, **tmp
;
5090 loc
= allocate_bp_location (b
, bptype
);
5091 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5094 loc
->requested_address
= sal
->pc
;
5095 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5097 loc
->section
= sal
->section
;
5099 set_breakpoint_location_function (loc
);
5104 /* Return 1 if LOC is pointing to a permanent breakpoint,
5105 return 0 otherwise. */
5108 bp_loc_is_permanent (struct bp_location
*loc
)
5112 const gdb_byte
*brk
;
5113 gdb_byte
*target_mem
;
5115 gdb_assert (loc
!= NULL
);
5117 addr
= loc
->address
;
5118 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5120 target_mem
= alloca (len
);
5122 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5123 && memcmp (target_mem
, brk
, len
) == 0)
5131 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5132 as textual description of the location, and COND_STRING
5133 as condition expression. */
5136 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5138 enum bptype type
, enum bpdisp disposition
,
5139 int thread
, int ignore_count
,
5140 struct breakpoint_ops
*ops
, int from_tty
)
5142 struct breakpoint
*b
= NULL
;
5145 if (type
== bp_hardware_breakpoint
)
5147 int i
= hw_breakpoint_used_count ();
5148 int target_resources_ok
=
5149 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5151 if (target_resources_ok
== 0)
5152 error (_("No hardware breakpoint support in the target."));
5153 else if (target_resources_ok
< 0)
5154 error (_("Hardware breakpoints used exceeds limit."));
5157 for (i
= 0; i
< sals
.nelts
; ++i
)
5159 struct symtab_and_line sal
= sals
.sals
[i
];
5160 struct bp_location
*loc
;
5163 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5167 b
= set_raw_breakpoint (sal
, type
);
5168 set_breakpoint_count (breakpoint_count
+ 1);
5169 b
->number
= breakpoint_count
;
5172 b
->cond_string
= cond_string
;
5173 b
->ignore_count
= ignore_count
;
5174 b
->enable_state
= bp_enabled
;
5175 b
->disposition
= disposition
;
5181 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5184 if (bp_loc_is_permanent (loc
))
5185 make_breakpoint_permanent (b
);
5189 char *arg
= b
->cond_string
;
5190 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5192 error (_("Garbage %s follows condition"), arg
);
5197 b
->addr_string
= addr_string
;
5199 /* addr_string has to be used or breakpoint_re_set will delete
5201 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5207 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5208 elements to fill the void space. */
5209 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5211 int i
= index_to_remove
+1;
5212 int last_index
= sal
->nelts
-1;
5214 for (;i
<= last_index
; ++i
)
5215 sal
->sals
[i
-1] = sal
->sals
[i
];
5220 /* If appropriate, obtains all sals that correspond
5221 to the same file and line as SAL. This is done
5222 only if SAL does not have explicit PC and has
5223 line and file information. If we got just a single
5224 expanded sal, return the original.
5226 Otherwise, if SAL.explicit_line is not set, filter out
5227 all sals for which the name of enclosing function
5228 is different from SAL. This makes sure that if we have
5229 breakpoint originally set in template instantiation, say
5230 foo<int>(), we won't expand SAL to locations at the same
5231 line in all existing instantiations of 'foo'.
5234 struct symtabs_and_lines
5235 expand_line_sal_maybe (struct symtab_and_line sal
)
5237 struct symtabs_and_lines expanded
;
5238 CORE_ADDR original_pc
= sal
.pc
;
5239 char *original_function
= NULL
;
5243 /* If we have explicit pc, don't expand.
5244 If we have no line number, we can't expand. */
5245 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5248 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5249 expanded
.sals
[0] = sal
;
5254 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5256 expanded
= expand_line_sal (sal
);
5257 if (expanded
.nelts
== 1)
5259 /* We had one sal, we got one sal. Without futher
5260 processing, just return the original sal. */
5261 xfree (expanded
.sals
);
5263 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5264 sal
.pc
= original_pc
;
5265 expanded
.sals
[0] = sal
;
5269 if (!sal
.explicit_line
)
5271 CORE_ADDR func_addr
, func_end
;
5272 for (i
= 0; i
< expanded
.nelts
; ++i
)
5274 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5275 char *this_function
;
5276 if (find_pc_partial_function (pc
, &this_function
,
5277 &func_addr
, &func_end
))
5279 if (this_function
&&
5280 strcmp (this_function
, original_function
) != 0)
5282 remove_sal (&expanded
, i
);
5285 else if (func_addr
== pc
)
5287 /* We're at beginning of a function, and should
5289 struct symbol
*sym
= find_pc_function (pc
);
5291 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5294 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5301 if (expanded
.nelts
<= 1)
5303 /* This is un ugly workaround. If we get zero
5304 expanded sals then something is really wrong.
5305 Fix that by returnign the original sal. */
5306 xfree (expanded
.sals
);
5308 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5309 sal
.pc
= original_pc
;
5310 expanded
.sals
[0] = sal
;
5317 for (i
= 0; i
< expanded
.nelts
; ++i
)
5318 if (expanded
.sals
[i
].pc
== original_pc
)
5329 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5330 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5331 value. COND_STRING, if not NULL, specified the condition to be
5332 used for all breakpoints. Essentially the only case where
5333 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5334 function. In that case, it's still not possible to specify
5335 separate conditions for different overloaded functions, so
5336 we take just a single condition string.
5338 NOTE: If the function succeeds, the caller is expected to cleanup
5339 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5340 array contents). If the function fails (error() is called), the
5341 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5342 COND and SALS arrays and each of those arrays contents. */
5345 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5347 enum bptype type
, enum bpdisp disposition
,
5348 int thread
, int ignore_count
,
5349 struct breakpoint_ops
*ops
, int from_tty
)
5352 for (i
= 0; i
< sals
.nelts
; ++i
)
5354 struct symtabs_and_lines expanded
=
5355 expand_line_sal_maybe (sals
.sals
[i
]);
5357 create_breakpoint (expanded
, addr_string
[i
],
5358 cond_string
, type
, disposition
,
5359 thread
, ignore_count
, ops
, from_tty
);
5362 update_global_location_list (1);
5365 /* Parse ARG which is assumed to be a SAL specification possibly
5366 followed by conditionals. On return, SALS contains an array of SAL
5367 addresses found. ADDR_STRING contains a vector of (canonical)
5368 address strings. ARG points to the end of the SAL. */
5371 parse_breakpoint_sals (char **address
,
5372 struct symtabs_and_lines
*sals
,
5373 char ***addr_string
,
5376 char *addr_start
= *address
;
5377 *addr_string
= NULL
;
5378 /* If no arg given, or if first arg is 'if ', use the default
5380 if ((*address
) == NULL
5381 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5383 if (default_breakpoint_valid
)
5385 struct symtab_and_line sal
;
5386 init_sal (&sal
); /* initialize to zeroes */
5387 sals
->sals
= (struct symtab_and_line
*)
5388 xmalloc (sizeof (struct symtab_and_line
));
5389 sal
.pc
= default_breakpoint_address
;
5390 sal
.line
= default_breakpoint_line
;
5391 sal
.symtab
= default_breakpoint_symtab
;
5392 sal
.section
= find_pc_overlay (sal
.pc
);
5393 sals
->sals
[0] = sal
;
5397 error (_("No default breakpoint address now."));
5401 /* Force almost all breakpoints to be in terms of the
5402 current_source_symtab (which is decode_line_1's default). This
5403 should produce the results we want almost all of the time while
5404 leaving default_breakpoint_* alone.
5405 ObjC: However, don't match an Objective-C method name which
5406 may have a '+' or '-' succeeded by a '[' */
5408 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5410 if (default_breakpoint_valid
5412 || ((strchr ("+-", (*address
)[0]) != NULL
)
5413 && ((*address
)[1] != '['))))
5414 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5415 default_breakpoint_line
, addr_string
,
5418 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5419 addr_string
, not_found_ptr
);
5421 /* For any SAL that didn't have a canonical string, fill one in. */
5422 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5423 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5424 if (addr_start
!= (*address
))
5427 for (i
= 0; i
< sals
->nelts
; i
++)
5429 /* Add the string if not present. */
5430 if ((*addr_string
)[i
] == NULL
)
5431 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5437 /* Convert each SAL into a real PC. Verify that the PC can be
5438 inserted as a breakpoint. If it can't throw an error. */
5441 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5445 for (i
= 0; i
< sals
->nelts
; i
++)
5446 resolve_sal_pc (&sals
->sals
[i
]);
5450 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5452 struct captured_parse_breakpoint_args
*args
= data
;
5454 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5455 args
->not_found_ptr
);
5458 /* Given TOK, a string specification of condition and thread, as
5459 accepted by the 'break' command, extract the condition
5460 string and thread number and set *COND_STRING and *THREAD.
5461 PC identifies the context at which the condition should be parsed.
5462 If no condition is found, *COND_STRING is set to NULL.
5463 If no thread is found, *THREAD is set to -1. */
5465 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5466 char **cond_string
, int *thread
)
5468 *cond_string
= NULL
;
5474 char *cond_start
= NULL
;
5475 char *cond_end
= NULL
;
5476 while (*tok
== ' ' || *tok
== '\t')
5481 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5484 toklen
= end_tok
- tok
;
5486 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5488 tok
= cond_start
= end_tok
+ 1;
5489 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5491 *cond_string
= savestring (cond_start
,
5492 cond_end
- cond_start
);
5494 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5500 *thread
= strtol (tok
, &tok
, 0);
5502 error (_("Junk after thread keyword."));
5503 if (!valid_thread_id (*thread
))
5504 error (_("Unknown thread %d."), *thread
);
5507 error (_("Junk at end of arguments."));
5511 /* Set a breakpoint. This function is shared between
5512 CLI and MI functions for setting a breakpoint.
5513 This function has two major modes of operations,
5514 selected by the PARSE_CONDITION_AND_THREAD parameter.
5515 If non-zero, the function will parse arg, extracting
5516 breakpoint location, address and thread. Otherwise,
5517 ARG is just the location of breakpoint, with condition
5518 and thread specified by the COND_STRING and THREAD
5522 break_command_really (char *arg
, char *cond_string
, int thread
,
5523 int parse_condition_and_thread
,
5524 int tempflag
, int hardwareflag
,
5526 enum auto_boolean pending_break_support
,
5527 struct breakpoint_ops
*ops
,
5530 struct gdb_exception e
;
5531 struct symtabs_and_lines sals
;
5532 struct symtab_and_line pending_sal
;
5535 char *addr_start
= arg
;
5537 struct cleanup
*old_chain
;
5538 struct cleanup
*breakpoint_chain
= NULL
;
5539 struct captured_parse_breakpoint_args parse_args
;
5548 parse_args
.arg_p
= &arg
;
5549 parse_args
.sals_p
= &sals
;
5550 parse_args
.addr_string_p
= &addr_string
;
5551 parse_args
.not_found_ptr
= ¬_found
;
5553 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5554 &parse_args
, RETURN_MASK_ALL
);
5556 /* If caller is interested in rc value from parse, set value. */
5560 throw_exception (e
);
5564 case NOT_FOUND_ERROR
:
5566 /* If pending breakpoint support is turned off, throw
5569 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5570 throw_exception (e
);
5572 exception_print (gdb_stderr
, e
);
5574 /* If pending breakpoint support is auto query and the user
5575 selects no, then simply return the error code. */
5576 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5577 !nquery ("Make breakpoint pending on future shared library load? "))
5580 /* At this point, either the user was queried about setting
5581 a pending breakpoint and selected yes, or pending
5582 breakpoint behavior is on and thus a pending breakpoint
5583 is defaulted on behalf of the user. */
5584 copy_arg
= xstrdup (addr_start
);
5585 addr_string
= ©_arg
;
5587 sals
.sals
= &pending_sal
;
5592 throw_exception (e
);
5599 /* Create a chain of things that always need to be cleaned up. */
5600 old_chain
= make_cleanup (null_cleanup
, 0);
5604 /* Make sure that all storage allocated to SALS gets freed. */
5605 make_cleanup (xfree
, sals
.sals
);
5607 /* Cleanup the addr_string array but not its contents. */
5608 make_cleanup (xfree
, addr_string
);
5611 /* ----------------------------- SNIP -----------------------------
5612 Anything added to the cleanup chain beyond this point is assumed
5613 to be part of a breakpoint. If the breakpoint create succeeds
5614 then the memory is not reclaimed. */
5615 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5617 /* Mark the contents of the addr_string for cleanup. These go on
5618 the breakpoint_chain and only occure if the breakpoint create
5620 for (i
= 0; i
< sals
.nelts
; i
++)
5622 if (addr_string
[i
] != NULL
)
5623 make_cleanup (xfree
, addr_string
[i
]);
5626 /* Resolve all line numbers to PC's and verify that the addresses
5627 are ok for the target. */
5629 breakpoint_sals_to_pc (&sals
, addr_start
);
5631 /* Verify that condition can be parsed, before setting any
5632 breakpoints. Allocate a separate condition expression for each
5636 if (parse_condition_and_thread
)
5638 /* Here we only parse 'arg' to separate condition
5639 from thread number, so parsing in context of first
5640 sal is OK. When setting the breakpoint we'll
5641 re-parse it in context of each sal. */
5644 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5646 make_cleanup (xfree
, cond_string
);
5650 /* Create a private copy of condition string. */
5653 cond_string
= xstrdup (cond_string
);
5654 make_cleanup (xfree
, cond_string
);
5657 create_breakpoints (sals
, addr_string
, cond_string
,
5658 hardwareflag
? bp_hardware_breakpoint
5660 tempflag
? disp_del
: disp_donttouch
,
5661 thread
, ignore_count
, ops
, from_tty
);
5665 struct symtab_and_line sal
= {0};
5666 struct breakpoint
*b
;
5668 make_cleanup (xfree
, copy_arg
);
5670 b
= set_raw_breakpoint_without_location (hardwareflag
5671 ? bp_hardware_breakpoint
5673 set_breakpoint_count (breakpoint_count
+ 1);
5674 b
->number
= breakpoint_count
;
5676 b
->addr_string
= addr_string
[0];
5677 b
->cond_string
= NULL
;
5678 b
->ignore_count
= ignore_count
;
5679 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5680 b
->condition_not_parsed
= 1;
5683 update_global_location_list (1);
5688 warning (_("Multiple breakpoints were set.\n"
5689 "Use the \"delete\" command to delete unwanted breakpoints."));
5690 /* That's it. Discard the cleanups for data inserted into the
5692 discard_cleanups (breakpoint_chain
);
5693 /* But cleanup everything else. */
5694 do_cleanups (old_chain
);
5697 /* Set a breakpoint.
5698 ARG is a string describing breakpoint address,
5699 condition, and thread.
5700 FLAG specifies if a breakpoint is hardware on,
5701 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5705 break_command_1 (char *arg
, int flag
, int from_tty
)
5707 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5708 int tempflag
= flag
& BP_TEMPFLAG
;
5710 break_command_really (arg
,
5711 NULL
, 0, 1 /* parse arg */,
5712 tempflag
, hardwareflag
,
5713 0 /* Ignore count */,
5714 pending_break_support
,
5715 NULL
/* breakpoint_ops */,
5721 set_breakpoint (char *address
, char *condition
,
5722 int hardwareflag
, int tempflag
,
5723 int thread
, int ignore_count
,
5726 break_command_really (address
, condition
, thread
,
5727 0 /* condition and thread are valid. */,
5728 tempflag
, hardwareflag
,
5731 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5735 /* Adjust SAL to the first instruction past the function prologue.
5736 The end of the prologue is determined using the line table from
5737 the debugging information.
5739 If SAL is already past the prologue, then do nothing. */
5742 skip_prologue_sal (struct symtab_and_line
*sal
)
5744 struct symbol
*sym
= find_pc_function (sal
->pc
);
5745 struct symtab_and_line start_sal
;
5750 start_sal
= find_function_start_sal (sym
, 1);
5751 if (sal
->pc
< start_sal
.pc
)
5755 /* Helper function for break_command_1 and disassemble_command. */
5758 resolve_sal_pc (struct symtab_and_line
*sal
)
5762 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5764 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5765 error (_("No line %d in file \"%s\"."),
5766 sal
->line
, sal
->symtab
->filename
);
5769 /* If this SAL corresponds to a breakpoint inserted using
5770 a line number, then skip the function prologue if necessary. */
5771 if (sal
->explicit_line
)
5772 skip_prologue_sal (sal
);
5775 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5777 struct blockvector
*bv
;
5781 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5784 sym
= block_linkage_function (b
);
5787 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5788 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5792 /* It really is worthwhile to have the section, so we'll just
5793 have to look harder. This case can be executed if we have
5794 line numbers but no functions (as can happen in assembly
5797 struct minimal_symbol
*msym
;
5799 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5801 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5808 break_command (char *arg
, int from_tty
)
5810 break_command_1 (arg
, 0, from_tty
);
5814 tbreak_command (char *arg
, int from_tty
)
5816 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5820 hbreak_command (char *arg
, int from_tty
)
5822 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5826 thbreak_command (char *arg
, int from_tty
)
5828 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5832 stop_command (char *arg
, int from_tty
)
5834 printf_filtered (_("Specify the type of breakpoint to set.\n\
5835 Usage: stop in <function | address>\n\
5836 stop at <line>\n"));
5840 stopin_command (char *arg
, int from_tty
)
5844 if (arg
== (char *) NULL
)
5846 else if (*arg
!= '*')
5851 /* look for a ':'. If this is a line number specification, then
5852 say it is bad, otherwise, it should be an address or
5853 function/method name */
5854 while (*argptr
&& !hasColon
)
5856 hasColon
= (*argptr
== ':');
5861 badInput
= (*argptr
!= ':'); /* Not a class::method */
5863 badInput
= isdigit (*arg
); /* a simple line number */
5867 printf_filtered (_("Usage: stop in <function | address>\n"));
5869 break_command_1 (arg
, 0, from_tty
);
5873 stopat_command (char *arg
, int from_tty
)
5877 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5884 /* look for a ':'. If there is a '::' then get out, otherwise
5885 it is probably a line number. */
5886 while (*argptr
&& !hasColon
)
5888 hasColon
= (*argptr
== ':');
5893 badInput
= (*argptr
== ':'); /* we have class::method */
5895 badInput
= !isdigit (*arg
); /* not a line number */
5899 printf_filtered (_("Usage: stop at <line>\n"));
5901 break_command_1 (arg
, 0, from_tty
);
5904 /* accessflag: hw_write: watch write,
5905 hw_read: watch read,
5906 hw_access: watch access (read or write) */
5908 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5910 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5911 struct symtab_and_line sal
;
5912 struct expression
*exp
;
5913 struct block
*exp_valid_block
;
5914 struct value
*val
, *mark
;
5915 struct frame_info
*frame
;
5916 struct frame_info
*prev_frame
= NULL
;
5917 char *exp_start
= NULL
;
5918 char *exp_end
= NULL
;
5919 char *tok
, *id_tok_start
, *end_tok
;
5921 char *cond_start
= NULL
;
5922 char *cond_end
= NULL
;
5923 struct expression
*cond
= NULL
;
5924 int i
, other_type_used
, target_resources_ok
= 0;
5925 enum bptype bp_type
;
5929 init_sal (&sal
); /* initialize to zeroes */
5931 /* Make sure that we actually have parameters to parse. */
5932 if (arg
!= NULL
&& arg
[0] != '\0')
5934 toklen
= strlen (arg
); /* Size of argument list. */
5936 /* Points tok to the end of the argument list. */
5937 tok
= arg
+ toklen
- 1;
5939 /* Go backwards in the parameters list. Skip the last parameter.
5940 If we're expecting a 'thread <thread_num>' parameter, this should
5941 be the thread identifier. */
5942 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5944 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5947 /* Points end_tok to the beginning of the last token. */
5948 id_tok_start
= tok
+ 1;
5950 /* Go backwards in the parameters list. Skip one more parameter.
5951 If we're expecting a 'thread <thread_num>' parameter, we should
5952 reach a "thread" token. */
5953 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5958 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5961 /* Move the pointer forward to skip the whitespace and
5962 calculate the length of the token. */
5964 toklen
= end_tok
- tok
;
5966 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5968 /* At this point we've found a "thread" token, which means
5969 the user is trying to set a watchpoint that triggers
5970 only in a specific thread. */
5973 /* Extract the thread ID from the next token. */
5974 thread
= strtol (id_tok_start
, &endp
, 0);
5976 /* Check if the user provided a valid numeric value for the
5978 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5979 error (_("Invalid thread ID specification %s."), id_tok_start
);
5981 /* Check if the thread actually exists. */
5982 if (!valid_thread_id (thread
))
5983 error (_("Unknown thread %d."), thread
);
5985 /* Truncate the string and get rid of the thread <thread_num>
5986 parameter before the parameter list is parsed by the
5987 evaluate_expression() function. */
5992 /* Parse the rest of the arguments. */
5993 innermost_block
= NULL
;
5995 exp
= parse_exp_1 (&arg
, 0, 0);
5997 exp_valid_block
= innermost_block
;
5998 mark
= value_mark ();
5999 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6001 release_value (val
);
6004 while (*tok
== ' ' || *tok
== '\t')
6008 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6011 toklen
= end_tok
- tok
;
6012 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6014 tok
= cond_start
= end_tok
+ 1;
6015 cond
= parse_exp_1 (&tok
, 0, 0);
6019 error (_("Junk at end of command."));
6021 if (accessflag
== hw_read
)
6022 bp_type
= bp_read_watchpoint
;
6023 else if (accessflag
== hw_access
)
6024 bp_type
= bp_access_watchpoint
;
6026 bp_type
= bp_hardware_watchpoint
;
6028 mem_cnt
= can_use_hardware_watchpoint (val
);
6029 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6030 error (_("Expression cannot be implemented with read/access watchpoint."));
6033 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6034 target_resources_ok
=
6035 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6037 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6038 error (_("Target does not support this type of hardware watchpoint."));
6040 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6041 error (_("Target can only support one kind of HW watchpoint at a time."));
6044 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6045 watchpoint could not be set. */
6046 if (!mem_cnt
|| target_resources_ok
<= 0)
6047 bp_type
= bp_watchpoint
;
6049 frame
= block_innermost_frame (exp_valid_block
);
6051 prev_frame
= get_prev_frame (frame
);
6055 /* If the expression is "local", then set up a "watchpoint scope"
6056 breakpoint at the point where we've left the scope of the watchpoint
6057 expression. Create the scope breakpoint before the watchpoint, so
6058 that we will encounter it first in bpstat_stop_status. */
6059 if (innermost_block
&& prev_frame
)
6061 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6062 bp_watchpoint_scope
);
6064 scope_breakpoint
->enable_state
= bp_enabled
;
6066 /* Automatically delete the breakpoint when it hits. */
6067 scope_breakpoint
->disposition
= disp_del
;
6069 /* Only break in the proper frame (help with recursion). */
6070 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6072 /* Set the address at which we will stop. */
6073 scope_breakpoint
->loc
->requested_address
6074 = get_frame_pc (prev_frame
);
6075 scope_breakpoint
->loc
->address
6076 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6077 scope_breakpoint
->type
);
6080 /* Now set up the breakpoint. */
6081 b
= set_raw_breakpoint (sal
, bp_type
);
6082 set_breakpoint_count (breakpoint_count
+ 1);
6083 b
->number
= breakpoint_count
;
6085 b
->disposition
= disp_donttouch
;
6087 b
->exp_valid_block
= exp_valid_block
;
6088 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6091 b
->loc
->cond
= cond
;
6093 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6098 b
->watchpoint_frame
= get_frame_id (frame
);
6100 b
->watchpoint_frame
= null_frame_id
;
6102 if (scope_breakpoint
!= NULL
)
6104 /* The scope breakpoint is related to the watchpoint. We will
6105 need to act on them together. */
6106 b
->related_breakpoint
= scope_breakpoint
;
6107 scope_breakpoint
->related_breakpoint
= b
;
6110 value_free_to_mark (mark
);
6112 update_global_location_list (1);
6115 /* Return count of locations need to be watched and can be handled
6116 in hardware. If the watchpoint can not be handled
6117 in hardware return zero. */
6120 can_use_hardware_watchpoint (struct value
*v
)
6122 int found_memory_cnt
= 0;
6123 struct value
*head
= v
;
6125 /* Did the user specifically forbid us to use hardware watchpoints? */
6126 if (!can_use_hw_watchpoints
)
6129 /* Make sure that the value of the expression depends only upon
6130 memory contents, and values computed from them within GDB. If we
6131 find any register references or function calls, we can't use a
6132 hardware watchpoint.
6134 The idea here is that evaluating an expression generates a series
6135 of values, one holding the value of every subexpression. (The
6136 expression a*b+c has five subexpressions: a, b, a*b, c, and
6137 a*b+c.) GDB's values hold almost enough information to establish
6138 the criteria given above --- they identify memory lvalues,
6139 register lvalues, computed values, etcetera. So we can evaluate
6140 the expression, and then scan the chain of values that leaves
6141 behind to decide whether we can detect any possible change to the
6142 expression's final value using only hardware watchpoints.
6144 However, I don't think that the values returned by inferior
6145 function calls are special in any way. So this function may not
6146 notice that an expression involving an inferior function call
6147 can't be watched with hardware watchpoints. FIXME. */
6148 for (; v
; v
= value_next (v
))
6150 if (VALUE_LVAL (v
) == lval_memory
)
6153 /* A lazy memory lvalue is one that GDB never needed to fetch;
6154 we either just used its address (e.g., `a' in `a.b') or
6155 we never needed it at all (e.g., `a' in `a,b'). */
6159 /* Ahh, memory we actually used! Check if we can cover
6160 it with hardware watchpoints. */
6161 struct type
*vtype
= check_typedef (value_type (v
));
6163 /* We only watch structs and arrays if user asked for it
6164 explicitly, never if they just happen to appear in a
6165 middle of some value chain. */
6167 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6168 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6170 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6171 int len
= TYPE_LENGTH (value_type (v
));
6173 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6180 else if (VALUE_LVAL (v
) != not_lval
6181 && deprecated_value_modifiable (v
) == 0)
6182 return 0; /* ??? What does this represent? */
6183 else if (VALUE_LVAL (v
) == lval_register
)
6184 return 0; /* cannot watch a register with a HW watchpoint */
6187 /* The expression itself looks suitable for using a hardware
6188 watchpoint, but give the target machine a chance to reject it. */
6189 return found_memory_cnt
;
6193 watch_command_wrapper (char *arg
, int from_tty
)
6195 watch_command (arg
, from_tty
);
6199 watch_command (char *arg
, int from_tty
)
6201 watch_command_1 (arg
, hw_write
, from_tty
);
6205 rwatch_command_wrapper (char *arg
, int from_tty
)
6207 rwatch_command (arg
, from_tty
);
6211 rwatch_command (char *arg
, int from_tty
)
6213 watch_command_1 (arg
, hw_read
, from_tty
);
6217 awatch_command_wrapper (char *arg
, int from_tty
)
6219 awatch_command (arg
, from_tty
);
6223 awatch_command (char *arg
, int from_tty
)
6225 watch_command_1 (arg
, hw_access
, from_tty
);
6229 /* Helper routines for the until_command routine in infcmd.c. Here
6230 because it uses the mechanisms of breakpoints. */
6232 struct until_break_command_continuation_args
6234 struct breakpoint
*breakpoint
;
6235 struct breakpoint
*breakpoint2
;
6238 /* This function is called by fetch_inferior_event via the
6239 cmd_continuation pointer, to complete the until command. It takes
6240 care of cleaning up the temporary breakpoints set up by the until
6243 until_break_command_continuation (void *arg
)
6245 struct until_break_command_continuation_args
*a
= arg
;
6247 delete_breakpoint (a
->breakpoint
);
6249 delete_breakpoint (a
->breakpoint2
);
6253 until_break_command (char *arg
, int from_tty
, int anywhere
)
6255 struct symtabs_and_lines sals
;
6256 struct symtab_and_line sal
;
6257 struct frame_info
*frame
= get_selected_frame (NULL
);
6258 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6259 struct breakpoint
*breakpoint
;
6260 struct breakpoint
*breakpoint2
= NULL
;
6261 struct cleanup
*old_chain
;
6263 clear_proceed_status ();
6265 /* Set a breakpoint where the user wants it and at return from
6268 if (default_breakpoint_valid
)
6269 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6270 default_breakpoint_line
, (char ***) NULL
, NULL
);
6272 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6273 0, (char ***) NULL
, NULL
);
6275 if (sals
.nelts
!= 1)
6276 error (_("Couldn't get information on specified line."));
6279 xfree (sals
.sals
); /* malloc'd, so freed */
6282 error (_("Junk at end of arguments."));
6284 resolve_sal_pc (&sal
);
6287 /* If the user told us to continue until a specified location,
6288 we don't specify a frame at which we need to stop. */
6289 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6291 /* Otherwise, specify the current frame, because we want to stop only
6292 at the very same frame. */
6293 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6296 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6298 /* Keep within the current frame, or in frames called by the current
6302 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6303 sal
.pc
= get_frame_pc (prev_frame
);
6304 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6306 make_cleanup_delete_breakpoint (breakpoint2
);
6309 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6311 /* If we are running asynchronously, and proceed call above has actually
6312 managed to start the target, arrange for breakpoints to be
6313 deleted when the target stops. Otherwise, we're already stopped and
6314 delete breakpoints via cleanup chain. */
6316 if (target_can_async_p () && is_running (inferior_ptid
))
6318 struct until_break_command_continuation_args
*args
;
6319 args
= xmalloc (sizeof (*args
));
6321 args
->breakpoint
= breakpoint
;
6322 args
->breakpoint2
= breakpoint2
;
6324 discard_cleanups (old_chain
);
6325 add_continuation (inferior_thread (),
6326 until_break_command_continuation
, args
,
6330 do_cleanups (old_chain
);
6334 ep_skip_leading_whitespace (char **s
)
6336 if ((s
== NULL
) || (*s
== NULL
))
6338 while (isspace (**s
))
6342 /* This function attempts to parse an optional "if <cond>" clause
6343 from the arg string. If one is not found, it returns NULL.
6345 Else, it returns a pointer to the condition string. (It does not
6346 attempt to evaluate the string against a particular block.) And,
6347 it updates arg to point to the first character following the parsed
6348 if clause in the arg string. */
6351 ep_parse_optional_if_clause (char **arg
)
6355 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6358 /* Skip the "if" keyword. */
6361 /* Skip any extra leading whitespace, and record the start of the
6362 condition string. */
6363 ep_skip_leading_whitespace (arg
);
6366 /* Assume that the condition occupies the remainder of the arg string. */
6367 (*arg
) += strlen (cond_string
);
6372 /* This function attempts to parse an optional filename from the arg
6373 string. If one is not found, it returns NULL.
6375 Else, it returns a pointer to the parsed filename. (This function
6376 makes no attempt to verify that a file of that name exists, or is
6377 accessible.) And, it updates arg to point to the first character
6378 following the parsed filename in the arg string.
6380 Note that clients needing to preserve the returned filename for
6381 future access should copy it to their own buffers. */
6383 ep_parse_optional_filename (char **arg
)
6385 static char filename
[1024];
6390 if ((*arg_p
== '\0') || isspace (*arg_p
))
6408 /* Commands to deal with catching events, such as signals, exceptions,
6409 process start/exit, etc. */
6413 catch_fork_temporary
, catch_vfork_temporary
,
6414 catch_fork_permanent
, catch_vfork_permanent
6419 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6421 char *cond_string
= NULL
;
6422 catch_fork_kind fork_kind
;
6425 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6426 tempflag
= (fork_kind
== catch_fork_temporary
6427 || fork_kind
== catch_vfork_temporary
);
6431 ep_skip_leading_whitespace (&arg
);
6433 /* The allowed syntax is:
6435 catch [v]fork if <cond>
6437 First, check if there's an if clause. */
6438 cond_string
= ep_parse_optional_if_clause (&arg
);
6440 if ((*arg
!= '\0') && !isspace (*arg
))
6441 error (_("Junk at end of arguments."));
6443 /* If this target supports it, create a fork or vfork catchpoint
6444 and enable reporting of such events. */
6447 case catch_fork_temporary
:
6448 case catch_fork_permanent
:
6449 create_fork_event_catchpoint (tempflag
, cond_string
);
6451 case catch_vfork_temporary
:
6452 case catch_vfork_permanent
:
6453 create_vfork_event_catchpoint (tempflag
, cond_string
);
6456 error (_("unsupported or unknown fork kind; cannot catch it"));
6462 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6465 char *cond_string
= NULL
;
6467 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6471 ep_skip_leading_whitespace (&arg
);
6473 /* The allowed syntax is:
6475 catch exec if <cond>
6477 First, check if there's an if clause. */
6478 cond_string
= ep_parse_optional_if_clause (&arg
);
6480 if ((*arg
!= '\0') && !isspace (*arg
))
6481 error (_("Junk at end of arguments."));
6483 /* If this target supports it, create an exec catchpoint
6484 and enable reporting of such events. */
6485 create_exec_event_catchpoint (tempflag
, cond_string
);
6489 catch_load_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6492 char *dll_pathname
= NULL
;
6493 char *cond_string
= NULL
;
6495 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6499 ep_skip_leading_whitespace (&arg
);
6501 /* The allowed syntax is:
6503 catch load if <cond>
6504 catch load <filename>
6505 catch load <filename> if <cond>
6507 The user is not allowed to specify the <filename> after an
6510 We'll ignore the pathological case of a file named "if".
6512 First, check if there's an if clause. If so, then there
6513 cannot be a filename. */
6514 cond_string
= ep_parse_optional_if_clause (&arg
);
6516 /* If there was an if clause, then there cannot be a filename.
6517 Else, there might be a filename and an if clause. */
6518 if (cond_string
== NULL
)
6520 dll_pathname
= ep_parse_optional_filename (&arg
);
6521 ep_skip_leading_whitespace (&arg
);
6522 cond_string
= ep_parse_optional_if_clause (&arg
);
6525 if ((*arg
!= '\0') && !isspace (*arg
))
6526 error (_("Junk at end of arguments."));
6528 /* Create a load breakpoint that only triggers when a load of
6529 the specified dll (or any dll, if no pathname was specified)
6531 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6532 dll_pathname
, cond_string
);
6536 catch_unload_command_1 (char *arg
, int from_tty
,
6537 struct cmd_list_element
*command
)
6540 char *dll_pathname
= NULL
;
6541 char *cond_string
= NULL
;
6543 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6547 ep_skip_leading_whitespace (&arg
);
6549 /* The allowed syntax is:
6551 catch unload if <cond>
6552 catch unload <filename>
6553 catch unload <filename> if <cond>
6555 The user is not allowed to specify the <filename> after an
6558 We'll ignore the pathological case of a file named "if".
6560 First, check if there's an if clause. If so, then there
6561 cannot be a filename. */
6562 cond_string
= ep_parse_optional_if_clause (&arg
);
6564 /* If there was an if clause, then there cannot be a filename.
6565 Else, there might be a filename and an if clause. */
6566 if (cond_string
== NULL
)
6568 dll_pathname
= ep_parse_optional_filename (&arg
);
6569 ep_skip_leading_whitespace (&arg
);
6570 cond_string
= ep_parse_optional_if_clause (&arg
);
6573 if ((*arg
!= '\0') && !isspace (*arg
))
6574 error (_("Junk at end of arguments."));
6576 /* Create an unload breakpoint that only triggers when an unload of
6577 the specified dll (or any dll, if no pathname was specified)
6579 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6580 dll_pathname
, cond_string
);
6583 static enum print_stop_action
6584 print_exception_catchpoint (struct breakpoint
*b
)
6586 int bp_temp
, bp_throw
;
6588 annotate_catchpoint (b
->number
);
6590 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6591 if (b
->loc
->address
!= b
->loc
->requested_address
)
6592 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6595 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6597 bp_temp
? "Temporary catchpoint "
6599 if (!ui_out_is_mi_like_p (uiout
))
6600 ui_out_field_int (uiout
, "bkptno", b
->number
);
6602 bp_throw
? " (exception thrown), "
6603 : " (exception caught), ");
6604 if (ui_out_is_mi_like_p (uiout
))
6606 ui_out_field_string (uiout
, "reason",
6607 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6608 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6609 ui_out_field_int (uiout
, "bkptno", b
->number
);
6611 return PRINT_SRC_AND_LOC
;
6615 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6620 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6621 ui_out_field_string (uiout
, "addr", "<PENDING>");
6623 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6627 *last_addr
= b
->loc
->address
;
6628 if (strstr (b
->addr_string
, "throw") != NULL
)
6629 ui_out_field_string (uiout
, "what", "exception throw");
6631 ui_out_field_string (uiout
, "what", "exception catch");
6635 print_mention_exception_catchpoint (struct breakpoint
*b
)
6640 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6641 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6642 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6643 : _("Catchpoint "));
6644 ui_out_field_int (uiout
, "bkptno", b
->number
);
6645 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6649 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6650 print_exception_catchpoint
,
6651 print_one_exception_catchpoint
,
6652 print_mention_exception_catchpoint
6656 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6657 enum exception_event_kind ex_event
, int from_tty
)
6659 char *trigger_func_name
;
6661 if (ex_event
== EX_EVENT_CATCH
)
6662 trigger_func_name
= "__cxa_begin_catch";
6664 trigger_func_name
= "__cxa_throw";
6666 break_command_really (trigger_func_name
, cond_string
, -1,
6667 0 /* condition and thread are valid. */,
6670 AUTO_BOOLEAN_TRUE
/* pending */,
6671 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6676 /* Deal with "catch catch" and "catch throw" commands */
6679 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6680 int tempflag
, int from_tty
)
6682 char *cond_string
= NULL
;
6683 struct symtab_and_line
*sal
= NULL
;
6687 ep_skip_leading_whitespace (&arg
);
6689 cond_string
= ep_parse_optional_if_clause (&arg
);
6691 if ((*arg
!= '\0') && !isspace (*arg
))
6692 error (_("Junk at end of arguments."));
6694 if ((ex_event
!= EX_EVENT_THROW
) &&
6695 (ex_event
!= EX_EVENT_CATCH
))
6696 error (_("Unsupported or unknown exception event; cannot catch it"));
6698 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6701 warning (_("Unsupported with this platform/compiler combination."));
6704 /* Implementation of "catch catch" command. */
6707 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6709 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6710 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6713 /* Implementation of "catch throw" command. */
6716 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6718 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6719 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6722 /* Create a breakpoint struct for Ada exception catchpoints. */
6725 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6729 struct expression
*cond
,
6730 struct breakpoint_ops
*ops
,
6734 struct breakpoint
*b
;
6738 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6739 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6740 version for exception catchpoints, because two catchpoints
6741 used for different exception names will use the same address.
6742 In this case, a "breakpoint ... also set at..." warning is
6743 unproductive. Besides. the warning phrasing is also a bit
6744 inapropriate, we should use the word catchpoint, and tell
6745 the user what type of catchpoint it is. The above is good
6746 enough for now, though. */
6749 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6750 set_breakpoint_count (breakpoint_count
+ 1);
6752 b
->enable_state
= bp_enabled
;
6753 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6754 b
->number
= breakpoint_count
;
6755 b
->ignore_count
= 0;
6756 b
->loc
->cond
= cond
;
6757 b
->addr_string
= addr_string
;
6758 b
->language
= language_ada
;
6759 b
->cond_string
= cond_string
;
6760 b
->exp_string
= exp_string
;
6765 update_global_location_list (1);
6768 /* Implement the "catch exception" command. */
6771 catch_ada_exception_command (char *arg
, int from_tty
,
6772 struct cmd_list_element
*command
)
6775 struct symtab_and_line sal
;
6777 char *addr_string
= NULL
;
6778 char *exp_string
= NULL
;
6779 char *cond_string
= NULL
;
6780 struct expression
*cond
= NULL
;
6781 struct breakpoint_ops
*ops
= NULL
;
6783 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6787 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6788 &cond_string
, &cond
, &ops
);
6789 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6790 cond_string
, cond
, ops
, tempflag
,
6794 /* Implement the "catch assert" command. */
6797 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6800 struct symtab_and_line sal
;
6801 char *addr_string
= NULL
;
6802 struct breakpoint_ops
*ops
= NULL
;
6804 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6808 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6809 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6810 tempflag
, from_tty
);
6814 catch_command (char *arg
, int from_tty
)
6816 error (_("Catch requires an event name."));
6821 tcatch_command (char *arg
, int from_tty
)
6823 error (_("Catch requires an event name."));
6826 /* Delete breakpoints by address or line. */
6829 clear_command (char *arg
, int from_tty
)
6831 struct breakpoint
*b
;
6832 VEC(breakpoint_p
) *found
= 0;
6835 struct symtabs_and_lines sals
;
6836 struct symtab_and_line sal
;
6841 sals
= decode_line_spec (arg
, 1);
6846 sals
.sals
= (struct symtab_and_line
*)
6847 xmalloc (sizeof (struct symtab_and_line
));
6848 make_cleanup (xfree
, sals
.sals
);
6849 init_sal (&sal
); /* initialize to zeroes */
6850 sal
.line
= default_breakpoint_line
;
6851 sal
.symtab
= default_breakpoint_symtab
;
6852 sal
.pc
= default_breakpoint_address
;
6853 if (sal
.symtab
== 0)
6854 error (_("No source file specified."));
6862 /* We don't call resolve_sal_pc here. That's not
6863 as bad as it seems, because all existing breakpoints
6864 typically have both file/line and pc set. So, if
6865 clear is given file/line, we can match this to existing
6866 breakpoint without obtaining pc at all.
6868 We only support clearing given the address explicitly
6869 present in breakpoint table. Say, we've set breakpoint
6870 at file:line. There were several PC values for that file:line,
6871 due to optimization, all in one block.
6872 We've picked one PC value. If "clear" is issued with another
6873 PC corresponding to the same file:line, the breakpoint won't
6874 be cleared. We probably can still clear the breakpoint, but
6875 since the other PC value is never presented to user, user
6876 can only find it by guessing, and it does not seem important
6879 /* For each line spec given, delete bps which correspond
6880 to it. Do it in two passes, solely to preserve the current
6881 behavior that from_tty is forced true if we delete more than
6885 for (i
= 0; i
< sals
.nelts
; i
++)
6887 /* If exact pc given, clear bpts at that pc.
6888 If line given (pc == 0), clear all bpts on specified line.
6889 If defaulting, clear all bpts on default line
6892 defaulting sal.pc != 0 tests to do
6897 1 0 <can't happen> */
6901 /* Find all matching breakpoints and add them to
6906 /* Are we going to delete b? */
6907 if (b
->type
!= bp_none
6908 && b
->type
!= bp_watchpoint
6909 && b
->type
!= bp_hardware_watchpoint
6910 && b
->type
!= bp_read_watchpoint
6911 && b
->type
!= bp_access_watchpoint
)
6913 struct bp_location
*loc
= b
->loc
;
6914 for (; loc
; loc
= loc
->next
)
6916 int pc_match
= sal
.pc
6917 && (loc
->address
== sal
.pc
)
6918 && (!section_is_overlay (loc
->section
)
6919 || loc
->section
== sal
.section
);
6920 int line_match
= ((default_match
|| (0 == sal
.pc
))
6921 && b
->source_file
!= NULL
6922 && sal
.symtab
!= NULL
6923 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6924 && b
->line_number
== sal
.line
);
6925 if (pc_match
|| line_match
)
6934 VEC_safe_push(breakpoint_p
, found
, b
);
6937 /* Now go thru the 'found' chain and delete them. */
6938 if (VEC_empty(breakpoint_p
, found
))
6941 error (_("No breakpoint at %s."), arg
);
6943 error (_("No breakpoint at this line."));
6946 if (VEC_length(breakpoint_p
, found
) > 1)
6947 from_tty
= 1; /* Always report if deleted more than one */
6950 if (VEC_length(breakpoint_p
, found
) == 1)
6951 printf_unfiltered (_("Deleted breakpoint "));
6953 printf_unfiltered (_("Deleted breakpoints "));
6955 breakpoints_changed ();
6957 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6960 printf_unfiltered ("%d ", b
->number
);
6961 delete_breakpoint (b
);
6964 putchar_unfiltered ('\n');
6967 /* Delete breakpoint in BS if they are `delete' breakpoints and
6968 all breakpoints that are marked for deletion, whether hit or not.
6969 This is called after any breakpoint is hit, or after errors. */
6972 breakpoint_auto_delete (bpstat bs
)
6974 struct breakpoint
*b
, *temp
;
6976 for (; bs
; bs
= bs
->next
)
6977 if (bs
->breakpoint_at
6978 && bs
->breakpoint_at
->owner
6979 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6981 delete_breakpoint (bs
->breakpoint_at
->owner
);
6983 ALL_BREAKPOINTS_SAFE (b
, temp
)
6985 if (b
->disposition
== disp_del_at_next_stop
)
6986 delete_breakpoint (b
);
6990 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
6991 into the inferior, only remove already-inserted locations that no
6992 longer should be inserted. Functions that delete a breakpoint or
6993 breakpoints should pass false, so that deleting a breakpoint
6994 doesn't have the side effect of inserting the locations of other
6995 breakpoints that are marked not-inserted, but should_be_inserted
6996 returns true on them.
6998 This behaviour is useful is situations close to tear-down -- e.g.,
6999 after an exec, while the target still has execution, but breakpoint
7000 shadows of the previous executable image should *NOT* be restored
7001 to the new image; or before detaching, where the target still has
7002 execution and wants to delete breakpoints from GDB's lists, and all
7003 breakpoints had already been removed from the inferior. */
7006 update_global_location_list (int should_insert
)
7008 struct breakpoint
*b
;
7009 struct bp_location
**next
= &bp_location_chain
;
7010 struct bp_location
*loc
;
7011 struct bp_location
*loc2
;
7012 struct gdb_exception e
;
7013 VEC(bp_location_p
) *old_locations
= NULL
;
7017 /* Store old locations for future reference. */
7018 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7019 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7021 bp_location_chain
= NULL
;
7024 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7027 next
= &(loc
->global_next
);
7032 /* Identify bp_location instances that are no longer present in the new
7033 list, and therefore should be freed. Note that it's not necessary that
7034 those locations should be removed from inferior -- if there's another
7035 location at the same address (previously marked as duplicate),
7036 we don't need to remove/insert the location. */
7037 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7039 /* Tells if 'loc' is found amoung the new locations. If not, we
7041 int found_object
= 0;
7042 /* Tells if the location should remain inserted in the target. */
7043 int keep_in_target
= 0;
7045 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7052 /* If this location is no longer present, and inserted, look if there's
7053 maybe a new location at the same address. If so, mark that one
7054 inserted, and don't remove this one. This is needed so that we
7055 don't have a time window where a breakpoint at certain location is not
7060 /* If the location is inserted now, we might have to remove it. */
7062 if (found_object
&& should_be_inserted (loc
))
7064 /* The location is still present in the location list, and still
7065 should be inserted. Don't do anything. */
7070 /* The location is either no longer present, or got disabled.
7071 See if there's another location at the same address, in which
7072 case we don't need to remove this one from the target. */
7073 if (breakpoint_address_is_meaningful (loc
->owner
))
7074 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7076 /* For the sake of should_insert_location. The
7077 call to check_duplicates will fix up this later. */
7078 loc2
->duplicate
= 0;
7079 if (should_be_inserted (loc2
)
7080 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7083 loc2
->target_info
= loc
->target_info
;
7090 if (!keep_in_target
)
7092 if (remove_breakpoint (loc
, mark_uninserted
))
7094 /* This is just about all we can do. We could keep this
7095 location on the global list, and try to remove it next
7096 time, but there's no particular reason why we will
7099 Note that at this point, loc->owner is still valid,
7100 as delete_breakpoint frees the breakpoint only
7101 after calling us. */
7102 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7103 loc
->owner
->number
);
7113 /* This location was removed from the targets. In non-stop mode,
7114 a race condition is possible where we've removed a breakpoint,
7115 but stop events for that breakpoint are already queued and will
7116 arrive later. To suppress spurious SIGTRAPs reported to user,
7117 we keep this breakpoint location for a bit, and will retire it
7118 after we see 3 * thread_count events.
7119 The theory here is that reporting of events should,
7120 "on the average", be fair, so after that many event we'll see
7121 events from all threads that have anything of interest, and no
7122 longer need to keep this breakpoint. This is just a
7123 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7124 which is usability issue, but not a correctness problem. */
7125 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7129 free_bp_location (loc
);
7135 check_duplicates (b
);
7138 if (breakpoints_always_inserted_mode ()
7140 && target_has_execution
)
7141 insert_breakpoint_locations ();
7145 breakpoint_retire_moribund (void)
7147 struct bp_location
*loc
;
7150 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7151 if (--(loc
->events_till_retirement
) == 0)
7153 free_bp_location (loc
);
7154 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7160 update_global_location_list_nothrow (int inserting
)
7162 struct gdb_exception e
;
7163 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7164 update_global_location_list (inserting
);
7167 /* Clear BPT from a BPS. */
7169 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7172 for (bs
= bps
; bs
; bs
= bs
->next
)
7173 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7175 bs
->breakpoint_at
= NULL
;
7177 /* bs->commands will be freed later. */
7181 /* Callback for iterate_over_threads. */
7183 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7185 struct breakpoint
*bpt
= data
;
7186 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7190 /* Delete a breakpoint and clean up all traces of it in the data
7194 delete_breakpoint (struct breakpoint
*bpt
)
7196 struct breakpoint
*b
;
7197 struct bp_location
*loc
, *next
;
7199 gdb_assert (bpt
!= NULL
);
7201 /* Has this bp already been deleted? This can happen because multiple
7202 lists can hold pointers to bp's. bpstat lists are especial culprits.
7204 One example of this happening is a watchpoint's scope bp. When the
7205 scope bp triggers, we notice that the watchpoint is out of scope, and
7206 delete it. We also delete its scope bp. But the scope bp is marked
7207 "auto-deleting", and is already on a bpstat. That bpstat is then
7208 checked for auto-deleting bp's, which are deleted.
7210 A real solution to this problem might involve reference counts in bp's,
7211 and/or giving them pointers back to their referencing bpstat's, and
7212 teaching delete_breakpoint to only free a bp's storage when no more
7213 references were extent. A cheaper bandaid was chosen. */
7214 if (bpt
->type
== bp_none
)
7217 observer_notify_breakpoint_deleted (bpt
->number
);
7219 if (breakpoint_chain
== bpt
)
7220 breakpoint_chain
= bpt
->next
;
7225 b
->next
= bpt
->next
;
7229 free_command_lines (&bpt
->commands
);
7230 if (bpt
->cond_string
!= NULL
)
7231 xfree (bpt
->cond_string
);
7232 if (bpt
->addr_string
!= NULL
)
7233 xfree (bpt
->addr_string
);
7234 if (bpt
->exp
!= NULL
)
7236 if (bpt
->exp_string
!= NULL
)
7237 xfree (bpt
->exp_string
);
7238 if (bpt
->val
!= NULL
)
7239 value_free (bpt
->val
);
7240 if (bpt
->source_file
!= NULL
)
7241 xfree (bpt
->source_file
);
7242 if (bpt
->dll_pathname
!= NULL
)
7243 xfree (bpt
->dll_pathname
);
7244 if (bpt
->triggered_dll_pathname
!= NULL
)
7245 xfree (bpt
->triggered_dll_pathname
);
7246 if (bpt
->exec_pathname
!= NULL
)
7247 xfree (bpt
->exec_pathname
);
7249 /* Be sure no bpstat's are pointing at it after it's been freed. */
7250 /* FIXME, how can we find all bpstat's?
7251 We just check stop_bpstat for now. Note that we cannot just
7252 remove bpstats pointing at bpt from the stop_bpstat list
7253 entirely, as breakpoint commands are associated with the bpstat;
7254 if we remove it here, then the later call to
7255 bpstat_do_actions (&stop_bpstat);
7256 in event-top.c won't do anything, and temporary breakpoints
7257 with commands won't work. */
7259 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7261 /* Now that breakpoint is removed from breakpoint
7262 list, update the global location list. This
7263 will remove locations that used to belong to
7264 this breakpoint. Do this before freeing
7265 the breakpoint itself, since remove_breakpoint
7266 looks at location's owner. It might be better
7267 design to have location completely self-contained,
7268 but it's not the case now. */
7269 update_global_location_list (0);
7272 /* On the chance that someone will soon try again to delete this same
7273 bp, we mark it as deleted before freeing its storage. */
7274 bpt
->type
= bp_none
;
7280 do_delete_breakpoint_cleanup (void *b
)
7282 delete_breakpoint (b
);
7286 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7288 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7292 delete_command (char *arg
, int from_tty
)
7294 struct breakpoint
*b
, *temp
;
7300 int breaks_to_delete
= 0;
7302 /* Delete all breakpoints if no argument.
7303 Do not delete internal or call-dummy breakpoints, these
7304 have to be deleted with an explicit breakpoint number argument. */
7307 if (b
->type
!= bp_call_dummy
&&
7308 b
->type
!= bp_shlib_event
&&
7309 b
->type
!= bp_thread_event
&&
7310 b
->type
!= bp_overlay_event
&&
7313 breaks_to_delete
= 1;
7318 /* Ask user only if there are some breakpoints to delete. */
7320 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7322 ALL_BREAKPOINTS_SAFE (b
, temp
)
7324 if (b
->type
!= bp_call_dummy
&&
7325 b
->type
!= bp_shlib_event
&&
7326 b
->type
!= bp_thread_event
&&
7327 b
->type
!= bp_overlay_event
&&
7329 delete_breakpoint (b
);
7334 map_breakpoint_numbers (arg
, delete_breakpoint
);
7338 all_locations_are_pending (struct bp_location
*loc
)
7340 for (; loc
; loc
= loc
->next
)
7341 if (!loc
->shlib_disabled
)
7346 /* Subroutine of update_breakpoint_locations to simplify it.
7347 Return non-zero if multiple fns in list LOC have the same name.
7348 Null names are ignored. */
7351 ambiguous_names_p (struct bp_location
*loc
)
7353 struct bp_location
*l
;
7354 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7355 (int (*) (const void *, const void *)) streq
,
7356 NULL
, xcalloc
, xfree
);
7358 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7361 const char *name
= l
->function_name
;
7363 /* Allow for some names to be NULL, ignore them. */
7367 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7369 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7384 update_breakpoint_locations (struct breakpoint
*b
,
7385 struct symtabs_and_lines sals
)
7389 struct bp_location
*existing_locations
= b
->loc
;
7391 /* If there's no new locations, and all existing locations
7392 are pending, don't do anything. This optimizes
7393 the common case where all locations are in the same
7394 shared library, that was unloaded. We'd like to
7395 retain the location, so that when the library
7396 is loaded again, we don't loose the enabled/disabled
7397 status of the individual locations. */
7398 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7403 for (i
= 0; i
< sals
.nelts
; ++i
)
7405 struct bp_location
*new_loc
=
7406 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7408 /* Reparse conditions, they might contain references to the
7410 if (b
->cond_string
!= NULL
)
7412 struct gdb_exception e
;
7415 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7417 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7422 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7423 b
->number
, e
.message
);
7424 new_loc
->enabled
= 0;
7428 if (b
->source_file
!= NULL
)
7429 xfree (b
->source_file
);
7430 if (sals
.sals
[i
].symtab
== NULL
)
7431 b
->source_file
= NULL
;
7434 savestring (sals
.sals
[i
].symtab
->filename
,
7435 strlen (sals
.sals
[i
].symtab
->filename
));
7437 if (b
->line_number
== 0)
7438 b
->line_number
= sals
.sals
[i
].line
;
7441 /* Update locations of permanent breakpoints. */
7442 if (b
->enable_state
== bp_permanent
)
7443 make_breakpoint_permanent (b
);
7445 /* If possible, carry over 'disable' status from existing breakpoints. */
7447 struct bp_location
*e
= existing_locations
;
7448 /* If there are multiple breakpoints with the same function name,
7449 e.g. for inline functions, comparing function names won't work.
7450 Instead compare pc addresses; this is just a heuristic as things
7451 may have moved, but in practice it gives the correct answer
7452 often enough until a better solution is found. */
7453 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7455 for (; e
; e
= e
->next
)
7457 if (!e
->enabled
&& e
->function_name
)
7459 struct bp_location
*l
= b
->loc
;
7460 if (have_ambiguous_names
)
7462 for (; l
; l
= l
->next
)
7463 if (e
->address
== l
->address
)
7471 for (; l
; l
= l
->next
)
7472 if (l
->function_name
7473 && strcmp (e
->function_name
, l
->function_name
) == 0)
7483 update_global_location_list (1);
7487 /* Reset a breakpoint given it's struct breakpoint * BINT.
7488 The value we return ends up being the return value from catch_errors.
7489 Unused in this case. */
7492 breakpoint_re_set_one (void *bint
)
7494 /* get past catch_errs */
7495 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7499 int *not_found_ptr
= ¬_found
;
7500 struct symtabs_and_lines sals
= {};
7501 struct symtabs_and_lines expanded
;
7503 enum enable_state save_enable
;
7504 struct gdb_exception e
;
7510 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7514 case bp_hardware_breakpoint
:
7516 case bp_catch_unload
:
7517 if (b
->addr_string
== NULL
)
7519 /* Anything without a string can't be re-set. */
7520 delete_breakpoint (b
);
7524 set_language (b
->language
);
7525 input_radix
= b
->input_radix
;
7527 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7529 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7534 int not_found_and_ok
= 0;
7535 /* For pending breakpoints, it's expected that parsing
7536 will fail until the right shared library is loaded.
7537 User has already told to create pending breakpoints and
7538 don't need extra messages. If breakpoint is in bp_shlib_disabled
7539 state, then user already saw the message about that breakpoint
7540 being disabled, and don't want to see more errors. */
7542 && (b
->condition_not_parsed
7543 || (b
->loc
&& b
->loc
->shlib_disabled
)
7544 || b
->enable_state
== bp_disabled
))
7545 not_found_and_ok
= 1;
7547 if (!not_found_and_ok
)
7549 /* We surely don't want to warn about the same breakpoint
7550 10 times. One solution, implemented here, is disable
7551 the breakpoint on error. Another solution would be to
7552 have separate 'warning emitted' flag. Since this
7553 happens only when a binary has changed, I don't know
7554 which approach is better. */
7555 b
->enable_state
= bp_disabled
;
7556 throw_exception (e
);
7563 gdb_assert (sals
.nelts
== 1);
7564 resolve_sal_pc (&sals
.sals
[0]);
7565 if (b
->condition_not_parsed
&& s
&& s
[0])
7567 char *cond_string
= 0;
7569 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7570 &cond_string
, &thread
);
7572 b
->cond_string
= cond_string
;
7574 b
->condition_not_parsed
= 0;
7576 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7577 update_breakpoint_locations (b
, expanded
);
7583 case bp_hardware_watchpoint
:
7584 case bp_read_watchpoint
:
7585 case bp_access_watchpoint
:
7586 /* Watchpoint can be either on expression using entirely global variables,
7587 or it can be on local variables.
7589 Watchpoints of the first kind are never auto-deleted, and even persist
7590 across program restarts. Since they can use variables from shared
7591 libraries, we need to reparse expression as libraries are loaded
7594 Watchpoints on local variables can also change meaning as result
7595 of solib event. For example, if a watchpoint uses both a local and
7596 a global variables in expression, it's a local watchpoint, but
7597 unloading of a shared library will make the expression invalid.
7598 This is not a very common use case, but we still re-evaluate
7599 expression, to avoid surprises to the user.
7601 Note that for local watchpoints, we re-evaluate it only if
7602 watchpoints frame id is still valid. If it's not, it means
7603 the watchpoint is out of scope and will be deleted soon. In fact,
7604 I'm not sure we'll ever be called in this case.
7606 If a local watchpoint's frame id is still valid, then
7607 b->exp_valid_block is likewise valid, and we can safely use it.
7609 Don't do anything about disabled watchpoints, since they will
7610 be reevaluated again when enabled. */
7611 update_watchpoint (b
, 1 /* reparse */);
7613 /* We needn't really do anything to reset these, since the mask
7614 that requests them is unaffected by e.g., new libraries being
7617 case bp_catch_vfork
:
7622 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7624 /* Delete overlay event breakpoints; they will be reset later by
7625 breakpoint_re_set. */
7626 case bp_overlay_event
:
7627 delete_breakpoint (b
);
7630 /* This breakpoint is special, it's set up when the inferior
7631 starts and we really don't want to touch it. */
7632 case bp_shlib_event
:
7634 /* Like bp_shlib_event, this breakpoint type is special.
7635 Once it is set up, we do not want to touch it. */
7636 case bp_thread_event
:
7638 /* Keep temporary breakpoints, which can be encountered when we step
7639 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7640 Otherwise these should have been blown away via the cleanup chain
7641 or by breakpoint_init_inferior when we rerun the executable. */
7644 case bp_watchpoint_scope
:
7646 case bp_step_resume
:
7648 case bp_longjmp_resume
:
7655 /* Re-set all breakpoints after symbols have been re-loaded. */
7657 breakpoint_re_set (void)
7659 struct breakpoint
*b
, *temp
;
7660 enum language save_language
;
7661 int save_input_radix
;
7663 save_language
= current_language
->la_language
;
7664 save_input_radix
= input_radix
;
7665 ALL_BREAKPOINTS_SAFE (b
, temp
)
7667 /* Format possible error msg */
7668 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7670 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7671 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7672 do_cleanups (cleanups
);
7674 set_language (save_language
);
7675 input_radix
= save_input_radix
;
7677 create_overlay_event_breakpoint ("_ovly_debug_event");
7680 /* Reset the thread number of this breakpoint:
7682 - If the breakpoint is for all threads, leave it as-is.
7683 - Else, reset it to the current thread for inferior_ptid. */
7685 breakpoint_re_set_thread (struct breakpoint
*b
)
7687 if (b
->thread
!= -1)
7689 if (in_thread_list (inferior_ptid
))
7690 b
->thread
= pid_to_thread_id (inferior_ptid
);
7694 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7695 If from_tty is nonzero, it prints a message to that effect,
7696 which ends with a period (no newline). */
7699 set_ignore_count (int bptnum
, int count
, int from_tty
)
7701 struct breakpoint
*b
;
7707 if (b
->number
== bptnum
)
7709 b
->ignore_count
= count
;
7713 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7715 else if (count
== 1)
7716 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7719 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7722 breakpoints_changed ();
7723 observer_notify_breakpoint_modified (b
->number
);
7727 error (_("No breakpoint number %d."), bptnum
);
7730 /* Command to set ignore-count of breakpoint N to COUNT. */
7733 ignore_command (char *args
, int from_tty
)
7739 error_no_arg (_("a breakpoint number"));
7741 num
= get_number (&p
);
7743 error (_("bad breakpoint number: '%s'"), args
);
7745 error (_("Second argument (specified ignore-count) is missing."));
7747 set_ignore_count (num
,
7748 longest_to_int (value_as_long (parse_and_eval (p
))),
7751 printf_filtered ("\n");
7754 /* Call FUNCTION on each of the breakpoints
7755 whose numbers are given in ARGS. */
7758 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7763 struct breakpoint
*b
, *tmp
;
7767 error_no_arg (_("one or more breakpoint numbers"));
7774 num
= get_number_or_range (&p1
);
7777 warning (_("bad breakpoint number at or near '%s'"), p
);
7781 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7782 if (b
->number
== num
)
7784 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7787 if (related_breakpoint
)
7788 function (related_breakpoint
);
7792 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7798 static struct bp_location
*
7799 find_location_by_number (char *number
)
7801 char *dot
= strchr (number
, '.');
7805 struct breakpoint
*b
;
7806 struct bp_location
*loc
;
7811 bp_num
= get_number_or_range (&p1
);
7813 error (_("Bad breakpoint number '%s'"), number
);
7816 if (b
->number
== bp_num
)
7821 if (!b
|| b
->number
!= bp_num
)
7822 error (_("Bad breakpoint number '%s'"), number
);
7825 loc_num
= get_number_or_range (&p1
);
7827 error (_("Bad breakpoint location number '%s'"), number
);
7831 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7834 error (_("Bad breakpoint location number '%s'"), dot
+1);
7840 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7841 If from_tty is nonzero, it prints a message to that effect,
7842 which ends with a period (no newline). */
7845 disable_breakpoint (struct breakpoint
*bpt
)
7847 /* Never disable a watchpoint scope breakpoint; we want to
7848 hit them when we leave scope so we can delete both the
7849 watchpoint and its scope breakpoint at that time. */
7850 if (bpt
->type
== bp_watchpoint_scope
)
7853 /* You can't disable permanent breakpoints. */
7854 if (bpt
->enable_state
== bp_permanent
)
7857 bpt
->enable_state
= bp_disabled
;
7859 update_global_location_list (0);
7861 observer_notify_breakpoint_modified (bpt
->number
);
7865 disable_command (char *args
, int from_tty
)
7867 struct breakpoint
*bpt
;
7869 ALL_BREAKPOINTS (bpt
)
7873 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7878 case bp_catch_unload
:
7880 case bp_catch_vfork
:
7882 case bp_hardware_breakpoint
:
7884 case bp_hardware_watchpoint
:
7885 case bp_read_watchpoint
:
7886 case bp_access_watchpoint
:
7887 disable_breakpoint (bpt
);
7891 else if (strchr (args
, '.'))
7893 struct bp_location
*loc
= find_location_by_number (args
);
7896 update_global_location_list (0);
7899 map_breakpoint_numbers (args
, disable_breakpoint
);
7903 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7905 int target_resources_ok
, other_type_used
;
7908 if (bpt
->type
== bp_hardware_breakpoint
)
7911 i
= hw_breakpoint_used_count ();
7912 target_resources_ok
=
7913 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7915 if (target_resources_ok
== 0)
7916 error (_("No hardware breakpoint support in the target."));
7917 else if (target_resources_ok
< 0)
7918 error (_("Hardware breakpoints used exceeds limit."));
7921 if (bpt
->type
== bp_watchpoint
||
7922 bpt
->type
== bp_hardware_watchpoint
||
7923 bpt
->type
== bp_read_watchpoint
||
7924 bpt
->type
== bp_access_watchpoint
)
7926 struct frame_id saved_frame_id
;
7928 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7929 if (bpt
->exp_valid_block
!= NULL
)
7931 struct frame_info
*fr
=
7932 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7935 printf_filtered (_("\
7936 Cannot enable watchpoint %d because the block in which its expression\n\
7937 is valid is not currently in scope.\n"), bpt
->number
);
7944 value_free (bpt
->val
);
7945 mark
= value_mark ();
7946 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7948 release_value (bpt
->val
);
7951 if (bpt
->type
== bp_hardware_watchpoint
||
7952 bpt
->type
== bp_read_watchpoint
||
7953 bpt
->type
== bp_access_watchpoint
)
7955 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7956 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7958 /* Hack around 'unused var' error for some targets here */
7959 (void) mem_cnt
, (void) i
;
7960 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7961 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7962 /* we can consider of type is bp_hardware_watchpoint, convert to
7963 bp_watchpoint in the following condition */
7964 if (target_resources_ok
< 0)
7966 printf_filtered (_("\
7967 Cannot enable watchpoint %d because target watch resources\n\
7968 have been allocated for other watchpoints.\n"), bpt
->number
);
7969 value_free_to_mark (mark
);
7974 select_frame (frame_find_by_id (saved_frame_id
));
7975 value_free_to_mark (mark
);
7978 if (bpt
->enable_state
!= bp_permanent
)
7979 bpt
->enable_state
= bp_enabled
;
7980 bpt
->disposition
= disposition
;
7981 update_global_location_list (1);
7982 breakpoints_changed ();
7984 observer_notify_breakpoint_modified (bpt
->number
);
7989 enable_breakpoint (struct breakpoint
*bpt
)
7991 do_enable_breakpoint (bpt
, bpt
->disposition
);
7994 /* The enable command enables the specified breakpoints (or all defined
7995 breakpoints) so they once again become (or continue to be) effective
7996 in stopping the inferior. */
7999 enable_command (char *args
, int from_tty
)
8001 struct breakpoint
*bpt
;
8003 ALL_BREAKPOINTS (bpt
)
8007 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8012 case bp_catch_unload
:
8014 case bp_catch_vfork
:
8016 case bp_hardware_breakpoint
:
8018 case bp_hardware_watchpoint
:
8019 case bp_read_watchpoint
:
8020 case bp_access_watchpoint
:
8021 enable_breakpoint (bpt
);
8025 else if (strchr (args
, '.'))
8027 struct bp_location
*loc
= find_location_by_number (args
);
8030 update_global_location_list (1);
8033 map_breakpoint_numbers (args
, enable_breakpoint
);
8037 enable_once_breakpoint (struct breakpoint
*bpt
)
8039 do_enable_breakpoint (bpt
, disp_disable
);
8043 enable_once_command (char *args
, int from_tty
)
8045 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8049 enable_delete_breakpoint (struct breakpoint
*bpt
)
8051 do_enable_breakpoint (bpt
, disp_del
);
8055 enable_delete_command (char *args
, int from_tty
)
8057 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8061 set_breakpoint_cmd (char *args
, int from_tty
)
8066 show_breakpoint_cmd (char *args
, int from_tty
)
8070 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8072 struct symtabs_and_lines
8073 decode_line_spec_1 (char *string
, int funfirstline
)
8075 struct symtabs_and_lines sals
;
8077 error (_("Empty line specification."));
8078 if (default_breakpoint_valid
)
8079 sals
= decode_line_1 (&string
, funfirstline
,
8080 default_breakpoint_symtab
,
8081 default_breakpoint_line
,
8082 (char ***) NULL
, NULL
);
8084 sals
= decode_line_1 (&string
, funfirstline
,
8085 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8087 error (_("Junk at end of line specification: %s"), string
);
8091 /* Create and insert a raw software breakpoint at PC. Return an
8092 identifier, which should be used to remove the breakpoint later.
8093 In general, places which call this should be using something on the
8094 breakpoint chain instead; this function should be eliminated
8098 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8100 struct bp_target_info
*bp_tgt
;
8102 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8103 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8105 bp_tgt
->placed_address
= pc
;
8106 if (target_insert_breakpoint (bp_tgt
) != 0)
8108 /* Could not insert the breakpoint. */
8116 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8119 deprecated_remove_raw_breakpoint (void *bp
)
8121 struct bp_target_info
*bp_tgt
= bp
;
8124 ret
= target_remove_breakpoint (bp_tgt
);
8130 /* One (or perhaps two) breakpoints used for software single stepping. */
8132 static void *single_step_breakpoints
[2];
8134 /* Create and insert a breakpoint for software single step. */
8137 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8141 if (single_step_breakpoints
[0] == NULL
)
8142 bpt_p
= &single_step_breakpoints
[0];
8145 gdb_assert (single_step_breakpoints
[1] == NULL
);
8146 bpt_p
= &single_step_breakpoints
[1];
8149 /* NOTE drow/2006-04-11: A future improvement to this function would be
8150 to only create the breakpoints once, and actually put them on the
8151 breakpoint chain. That would let us use set_raw_breakpoint. We could
8152 adjust the addresses each time they were needed. Doing this requires
8153 corresponding changes elsewhere where single step breakpoints are
8154 handled, however. So, for now, we use this. */
8156 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8158 error (_("Could not insert single-step breakpoint at 0x%s"),
8159 paddr_nz (next_pc
));
8162 /* Remove and delete any breakpoints used for software single step. */
8165 remove_single_step_breakpoints (void)
8167 gdb_assert (single_step_breakpoints
[0] != NULL
);
8169 /* See insert_single_step_breakpoint for more about this deprecated
8171 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8172 single_step_breakpoints
[0] = NULL
;
8174 if (single_step_breakpoints
[1] != NULL
)
8176 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8177 single_step_breakpoints
[1] = NULL
;
8181 /* Check whether a software single-step breakpoint is inserted at PC. */
8184 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8188 for (i
= 0; i
< 2; i
++)
8190 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8191 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8199 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8200 It is defined as a macro to prevent duplication.
8201 COMMAND should be a string constant containing the name of the command. */
8202 #define BREAK_ARGS_HELP(command) \
8203 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8204 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8205 If a line number is specified, break at start of code for that line.\n\
8206 If a function is specified, break at start of code for that function.\n\
8207 If an address is specified, break at that exact address.\n\
8208 With no LOCATION, uses current execution address of selected stack frame.\n\
8209 This is useful for breaking on return to a stack frame.\n\
8211 THREADNUM is the number from \"info threads\".\n\
8212 CONDITION is a boolean expression.\n\
8214 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8216 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8218 /* List of subcommands for "catch". */
8219 static struct cmd_list_element
*catch_cmdlist
;
8221 /* List of subcommands for "tcatch". */
8222 static struct cmd_list_element
*tcatch_cmdlist
;
8224 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8225 lists, and pass some additional user data to the command function. */
8227 add_catch_command (char *name
, char *docstring
,
8228 void (*sfunc
) (char *args
, int from_tty
,
8229 struct cmd_list_element
*command
),
8230 void *user_data_catch
,
8231 void *user_data_tcatch
)
8233 struct cmd_list_element
*command
;
8235 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8237 set_cmd_sfunc (command
, sfunc
);
8238 set_cmd_context (command
, user_data_catch
);
8240 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8242 set_cmd_sfunc (command
, sfunc
);
8243 set_cmd_context (command
, user_data_tcatch
);
8247 _initialize_breakpoint (void)
8249 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8250 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8251 struct cmd_list_element
*c
;
8253 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8255 breakpoint_chain
= 0;
8256 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8257 before a breakpoint is set. */
8258 breakpoint_count
= 0;
8260 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8261 Set ignore-count of breakpoint number N to COUNT.\n\
8262 Usage is `ignore N COUNT'."));
8264 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8266 add_com ("commands", class_breakpoint
, commands_command
, _("\
8267 Set commands to be executed when a breakpoint is hit.\n\
8268 Give breakpoint number as argument after \"commands\".\n\
8269 With no argument, the targeted breakpoint is the last one set.\n\
8270 The commands themselves follow starting on the next line.\n\
8271 Type a line containing \"end\" to indicate the end of them.\n\
8272 Give \"silent\" as the first line to make the breakpoint silent;\n\
8273 then no output is printed when it is hit, except what the commands print."));
8275 add_com ("condition", class_breakpoint
, condition_command
, _("\
8276 Specify breakpoint number N to break only if COND is true.\n\
8277 Usage is `condition N COND', where N is an integer and COND is an\n\
8278 expression to be evaluated whenever breakpoint N is reached."));
8280 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8281 Set a temporary breakpoint.\n\
8282 Like \"break\" except the breakpoint is only temporary,\n\
8283 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8284 by using \"enable delete\" on the breakpoint number.\n\
8286 BREAK_ARGS_HELP ("tbreak")));
8287 set_cmd_completer (c
, location_completer
);
8289 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8290 Set a hardware assisted breakpoint.\n\
8291 Like \"break\" except the breakpoint requires hardware support,\n\
8292 some target hardware may not have this support.\n\
8294 BREAK_ARGS_HELP ("hbreak")));
8295 set_cmd_completer (c
, location_completer
);
8297 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8298 Set a temporary hardware assisted breakpoint.\n\
8299 Like \"hbreak\" except the breakpoint is only temporary,\n\
8300 so it will be deleted when hit.\n\
8302 BREAK_ARGS_HELP ("thbreak")));
8303 set_cmd_completer (c
, location_completer
);
8305 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8306 Enable some breakpoints.\n\
8307 Give breakpoint numbers (separated by spaces) as arguments.\n\
8308 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8309 This is used to cancel the effect of the \"disable\" command.\n\
8310 With a subcommand you can enable temporarily."),
8311 &enablelist
, "enable ", 1, &cmdlist
);
8313 add_com ("ab", class_breakpoint
, enable_command
, _("\
8314 Enable some breakpoints.\n\
8315 Give breakpoint numbers (separated by spaces) as arguments.\n\
8316 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8317 This is used to cancel the effect of the \"disable\" command.\n\
8318 With a subcommand you can enable temporarily."));
8320 add_com_alias ("en", "enable", class_breakpoint
, 1);
8322 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8323 Enable some breakpoints.\n\
8324 Give breakpoint numbers (separated by spaces) as arguments.\n\
8325 This is used to cancel the effect of the \"disable\" command.\n\
8326 May be abbreviated to simply \"enable\".\n"),
8327 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8329 add_cmd ("once", no_class
, enable_once_command
, _("\
8330 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8331 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8334 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8335 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8336 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8339 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8340 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8341 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8344 add_cmd ("once", no_class
, enable_once_command
, _("\
8345 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8346 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8349 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8350 Disable some breakpoints.\n\
8351 Arguments are breakpoint numbers with spaces in between.\n\
8352 To disable all breakpoints, give no argument.\n\
8353 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8354 &disablelist
, "disable ", 1, &cmdlist
);
8355 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8356 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8358 add_com ("sb", class_breakpoint
, disable_command
, _("\
8359 Disable some breakpoints.\n\
8360 Arguments are breakpoint numbers with spaces in between.\n\
8361 To disable all breakpoints, give no argument.\n\
8362 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8364 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8365 Disable some breakpoints.\n\
8366 Arguments are breakpoint numbers with spaces in between.\n\
8367 To disable all breakpoints, give no argument.\n\
8368 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8369 This command may be abbreviated \"disable\"."),
8372 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8373 Delete some breakpoints or auto-display expressions.\n\
8374 Arguments are breakpoint numbers with spaces in between.\n\
8375 To delete all breakpoints, give no argument.\n\
8377 Also a prefix command for deletion of other GDB objects.\n\
8378 The \"unset\" command is also an alias for \"delete\"."),
8379 &deletelist
, "delete ", 1, &cmdlist
);
8380 add_com_alias ("d", "delete", class_breakpoint
, 1);
8381 add_com_alias ("del", "delete", class_breakpoint
, 1);
8383 add_com ("db", class_breakpoint
, delete_command
, _("\
8384 Delete some breakpoints.\n\
8385 Arguments are breakpoint numbers with spaces in between.\n\
8386 To delete all breakpoints, give no argument.\n"));
8388 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8389 Delete some breakpoints or auto-display expressions.\n\
8390 Arguments are breakpoint numbers with spaces in between.\n\
8391 To delete all breakpoints, give no argument.\n\
8392 This command may be abbreviated \"delete\"."),
8395 add_com ("clear", class_breakpoint
, clear_command
, _("\
8396 Clear breakpoint at specified line or function.\n\
8397 Argument may be line number, function name, or \"*\" and an address.\n\
8398 If line number is specified, all breakpoints in that line are cleared.\n\
8399 If function is specified, breakpoints at beginning of function are cleared.\n\
8400 If an address is specified, breakpoints at that address are cleared.\n\
8402 With no argument, clears all breakpoints in the line that the selected frame\n\
8405 See also the \"delete\" command which clears breakpoints by number."));
8407 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8408 Set breakpoint at specified line or function.\n"
8409 BREAK_ARGS_HELP ("break")));
8410 set_cmd_completer (c
, location_completer
);
8412 add_com_alias ("b", "break", class_run
, 1);
8413 add_com_alias ("br", "break", class_run
, 1);
8414 add_com_alias ("bre", "break", class_run
, 1);
8415 add_com_alias ("brea", "break", class_run
, 1);
8419 add_com_alias ("ba", "break", class_breakpoint
, 1);
8420 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8425 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8426 Break in function/address or break at a line in the current file."),
8427 &stoplist
, "stop ", 1, &cmdlist
);
8428 add_cmd ("in", class_breakpoint
, stopin_command
,
8429 _("Break in function or address."), &stoplist
);
8430 add_cmd ("at", class_breakpoint
, stopat_command
,
8431 _("Break at a line in the current file."), &stoplist
);
8432 add_com ("status", class_info
, breakpoints_info
, _("\
8433 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8434 The \"Type\" column indicates one of:\n\
8435 \tbreakpoint - normal breakpoint\n\
8436 \twatchpoint - watchpoint\n\
8437 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8438 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8439 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8440 address and file/line number respectively.\n\
8442 Convenience variable \"$_\" and default examine address for \"x\"\n\
8443 are set to the address of the last breakpoint listed unless the command\n\
8444 is prefixed with \"server \".\n\n\
8445 Convenience variable \"$bpnum\" contains the number of the last\n\
8449 add_info ("breakpoints", breakpoints_info
, _("\
8450 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8451 The \"Type\" column indicates one of:\n\
8452 \tbreakpoint - normal breakpoint\n\
8453 \twatchpoint - watchpoint\n\
8454 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8455 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8456 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8457 address and file/line number respectively.\n\
8459 Convenience variable \"$_\" and default examine address for \"x\"\n\
8460 are set to the address of the last breakpoint listed unless the command\n\
8461 is prefixed with \"server \".\n\n\
8462 Convenience variable \"$bpnum\" contains the number of the last\n\
8466 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8467 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8468 The \"Type\" column indicates one of:\n\
8469 \tbreakpoint - normal breakpoint\n\
8470 \twatchpoint - watchpoint\n\
8471 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8472 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8473 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8474 address and file/line number respectively.\n\
8476 Convenience variable \"$_\" and default examine address for \"x\"\n\
8477 are set to the address of the last breakpoint listed unless the command\n\
8478 is prefixed with \"server \".\n\n\
8479 Convenience variable \"$bpnum\" contains the number of the last\n\
8482 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8483 Status of all breakpoints, or breakpoint number NUMBER.\n\
8484 The \"Type\" column indicates one of:\n\
8485 \tbreakpoint - normal breakpoint\n\
8486 \twatchpoint - watchpoint\n\
8487 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8488 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8489 \tuntil - internal breakpoint used by the \"until\" command\n\
8490 \tfinish - internal breakpoint used by the \"finish\" command\n\
8491 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8492 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8493 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8494 address and file/line number respectively.\n\
8496 Convenience variable \"$_\" and default examine address for \"x\"\n\
8497 are set to the address of the last breakpoint listed unless the command\n\
8498 is prefixed with \"server \".\n\n\
8499 Convenience variable \"$bpnum\" contains the number of the last\n\
8501 &maintenanceinfolist
);
8503 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8504 Set catchpoints to catch events."),
8505 &catch_cmdlist
, "catch ",
8506 0/*allow-unknown*/, &cmdlist
);
8508 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8509 Set temporary catchpoints to catch events."),
8510 &tcatch_cmdlist
, "tcatch ",
8511 0/*allow-unknown*/, &cmdlist
);
8513 /* Add catch and tcatch sub-commands. */
8514 add_catch_command ("catch", _("\
8515 Catch an exception, when caught.\n\
8516 With an argument, catch only exceptions with the given name."),
8517 catch_catch_command
,
8520 add_catch_command ("throw", _("\
8521 Catch an exception, when thrown.\n\
8522 With an argument, catch only exceptions with the given name."),
8523 catch_throw_command
,
8526 add_catch_command ("fork", _("Catch calls to fork."),
8527 catch_fork_command_1
,
8528 (void *) (uintptr_t) catch_fork_permanent
,
8529 (void *) (uintptr_t) catch_fork_temporary
);
8530 add_catch_command ("vfork", _("Catch calls to vfork."),
8531 catch_fork_command_1
,
8532 (void *) (uintptr_t) catch_vfork_permanent
,
8533 (void *) (uintptr_t) catch_vfork_temporary
);
8534 add_catch_command ("exec", _("Catch calls to exec."),
8535 catch_exec_command_1
,
8538 add_catch_command ("load", _("\
8539 Catch library loads.\n\
8540 With an argument, catch only loads of that library."),
8541 catch_load_command_1
,
8544 add_catch_command ("unload", _("\
8545 Catch library unloads.\n\
8546 With an argument, catch only unloads of that library."),
8547 catch_unload_command_1
,
8550 add_catch_command ("exception", _("\
8551 Catch Ada exceptions, when raised.\n\
8552 With an argument, catch only exceptions with the given name."),
8553 catch_ada_exception_command
,
8556 add_catch_command ("assert", _("\
8557 Catch failed Ada assertions, when raised.\n\
8558 With an argument, catch only exceptions with the given name."),
8559 catch_assert_command
,
8563 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8564 Set a watchpoint for an expression.\n\
8565 A watchpoint stops execution of your program whenever the value of\n\
8566 an expression changes."));
8567 set_cmd_completer (c
, expression_completer
);
8569 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8570 Set a read watchpoint for an expression.\n\
8571 A watchpoint stops execution of your program whenever the value of\n\
8572 an expression is read."));
8573 set_cmd_completer (c
, expression_completer
);
8575 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8576 Set a watchpoint for an expression.\n\
8577 A watchpoint stops execution of your program whenever the value of\n\
8578 an expression is either read or written."));
8579 set_cmd_completer (c
, expression_completer
);
8581 add_info ("watchpoints", breakpoints_info
,
8582 _("Synonym for ``info breakpoints''."));
8585 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8586 respond to changes - contrary to the description. */
8587 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8588 &can_use_hw_watchpoints
, _("\
8589 Set debugger's willingness to use watchpoint hardware."), _("\
8590 Show debugger's willingness to use watchpoint hardware."), _("\
8591 If zero, gdb will not use hardware for new watchpoints, even if\n\
8592 such is available. (However, any hardware watchpoints that were\n\
8593 created before setting this to nonzero, will continue to use watchpoint\n\
8596 show_can_use_hw_watchpoints
,
8597 &setlist
, &showlist
);
8599 can_use_hw_watchpoints
= 1;
8601 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8602 Breakpoint specific settings\n\
8603 Configure various breakpoint-specific variables such as\n\
8604 pending breakpoint behavior"),
8605 &breakpoint_set_cmdlist
, "set breakpoint ",
8606 0/*allow-unknown*/, &setlist
);
8607 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8608 Breakpoint specific settings\n\
8609 Configure various breakpoint-specific variables such as\n\
8610 pending breakpoint behavior"),
8611 &breakpoint_show_cmdlist
, "show breakpoint ",
8612 0/*allow-unknown*/, &showlist
);
8614 add_setshow_auto_boolean_cmd ("pending", no_class
,
8615 &pending_break_support
, _("\
8616 Set debugger's behavior regarding pending breakpoints."), _("\
8617 Show debugger's behavior regarding pending breakpoints."), _("\
8618 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8619 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8620 an error. If auto, an unrecognized breakpoint location results in a\n\
8621 user-query to see if a pending breakpoint should be created."),
8623 show_pending_break_support
,
8624 &breakpoint_set_cmdlist
,
8625 &breakpoint_show_cmdlist
);
8627 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8629 add_setshow_boolean_cmd ("auto-hw", no_class
,
8630 &automatic_hardware_breakpoints
, _("\
8631 Set automatic usage of hardware breakpoints."), _("\
8632 Show automatic usage of hardware breakpoints."), _("\
8633 If set, the debugger will automatically use hardware breakpoints for\n\
8634 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8635 a warning will be emitted for such breakpoints."),
8637 show_automatic_hardware_breakpoints
,
8638 &breakpoint_set_cmdlist
,
8639 &breakpoint_show_cmdlist
);
8641 add_setshow_enum_cmd ("always-inserted", class_support
,
8642 always_inserted_enums
, &always_inserted_mode
, _("\
8643 Set mode for inserting breakpoints."), _("\
8644 Show mode for inserting breakpoints."), _("\
8645 When this mode is off, breakpoints are inserted in inferior when it is\n\
8646 resumed, and removed when execution stops. When this mode is on,\n\
8647 breakpoints are inserted immediately and removed only when the user\n\
8648 deletes the breakpoint. When this mode is auto (which is the default),\n\
8649 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8650 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8651 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8652 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8654 &show_always_inserted_mode
,
8655 &breakpoint_set_cmdlist
,
8656 &breakpoint_show_cmdlist
);
8658 automatic_hardware_breakpoints
= 1;