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
;
1749 ALL_BP_LOCATIONS (bpt
)
1750 if (bpt
->owner
->enable_state
!= bp_permanent
)
1753 ALL_BREAKPOINTS_SAFE (b
, temp
)
1758 case bp_watchpoint_scope
:
1760 /* If the call dummy breakpoint is at the entry point it will
1761 cause problems when the inferior is rerun, so we better
1764 Also get rid of scope breakpoints. */
1765 delete_breakpoint (b
);
1769 case bp_hardware_watchpoint
:
1770 case bp_read_watchpoint
:
1771 case bp_access_watchpoint
:
1773 /* Likewise for watchpoints on local expressions. */
1774 if (b
->exp_valid_block
!= NULL
)
1775 delete_breakpoint (b
);
1776 else if (context
== inf_starting
)
1778 /* Reset val field to force reread of starting value
1779 in insert_breakpoints. */
1781 value_free (b
->val
);
1791 /* Get rid of the moribund locations. */
1792 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1793 free_bp_location (bpt
);
1794 VEC_free (bp_location_p
, moribund_locations
);
1797 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1798 exists at PC. It returns ordinary_breakpoint_here if it's an
1799 ordinary breakpoint, or permanent_breakpoint_here if it's a
1800 permanent breakpoint.
1801 - When continuing from a location with an ordinary breakpoint, we
1802 actually single step once before calling insert_breakpoints.
1803 - When continuing from a localion with a permanent breakpoint, we
1804 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1805 the target, to advance the PC past the breakpoint. */
1807 enum breakpoint_here
1808 breakpoint_here_p (CORE_ADDR pc
)
1810 const struct bp_location
*bpt
;
1811 int any_breakpoint_here
= 0;
1813 ALL_BP_LOCATIONS (bpt
)
1815 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1816 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1819 if ((breakpoint_enabled (bpt
->owner
)
1820 || bpt
->owner
->enable_state
== bp_permanent
)
1821 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1823 if (overlay_debugging
1824 && section_is_overlay (bpt
->section
)
1825 && !section_is_mapped (bpt
->section
))
1826 continue; /* unmapped overlay -- can't be a match */
1827 else if (bpt
->owner
->enable_state
== bp_permanent
)
1828 return permanent_breakpoint_here
;
1830 any_breakpoint_here
= 1;
1834 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1837 /* Return true if there's a moribund breakpoint at PC. */
1840 moribund_breakpoint_here_p (CORE_ADDR pc
)
1842 struct bp_location
*loc
;
1845 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1846 if (loc
->address
== pc
)
1852 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1853 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1854 This does not check for single-step breakpoints, which are
1855 inserted and removed using direct target manipulation. */
1858 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1860 const struct bp_location
*bpt
;
1862 ALL_BP_LOCATIONS (bpt
)
1864 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1865 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1869 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1871 if (overlay_debugging
1872 && section_is_overlay (bpt
->section
)
1873 && !section_is_mapped (bpt
->section
))
1874 continue; /* unmapped overlay -- can't be a match */
1882 /* Returns non-zero iff there's either regular breakpoint
1883 or a single step breakpoint inserted at PC. */
1886 breakpoint_inserted_here_p (CORE_ADDR pc
)
1888 if (regular_breakpoint_inserted_here_p (pc
))
1891 if (single_step_breakpoint_inserted_here_p (pc
))
1897 /* This function returns non-zero iff there is a software breakpoint
1901 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1903 const struct bp_location
*bpt
;
1904 int any_breakpoint_here
= 0;
1906 ALL_BP_LOCATIONS (bpt
)
1908 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1912 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1914 if (overlay_debugging
1915 && section_is_overlay (bpt
->section
)
1916 && !section_is_mapped (bpt
->section
))
1917 continue; /* unmapped overlay -- can't be a match */
1923 /* Also check for software single-step breakpoints. */
1924 if (single_step_breakpoint_inserted_here_p (pc
))
1930 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1931 PC is valid for process/thread PTID. */
1934 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1936 const struct bp_location
*bpt
;
1939 thread
= pid_to_thread_id (ptid
);
1941 ALL_BP_LOCATIONS (bpt
)
1943 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1944 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1947 if ((breakpoint_enabled (bpt
->owner
)
1948 || bpt
->owner
->enable_state
== bp_permanent
)
1949 && bpt
->address
== pc
1950 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1952 if (overlay_debugging
1953 && section_is_overlay (bpt
->section
)
1954 && !section_is_mapped (bpt
->section
))
1955 continue; /* unmapped overlay -- can't be a match */
1965 /* bpstat stuff. External routines' interfaces are documented
1969 ep_is_catchpoint (struct breakpoint
*ep
)
1972 (ep
->type
== bp_catch_load
)
1973 || (ep
->type
== bp_catch_unload
)
1974 || (ep
->type
== bp_catch_fork
)
1975 || (ep
->type
== bp_catch_vfork
)
1976 || (ep
->type
== bp_catch_exec
);
1978 /* ??rehrauer: Add more kinds here, as are implemented... */
1982 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1985 (ep
->type
== bp_catch_load
)
1986 || (ep
->type
== bp_catch_unload
);
1990 bpstat_free (bpstat bs
)
1992 if (bs
->old_val
!= NULL
)
1993 value_free (bs
->old_val
);
1994 free_command_lines (&bs
->commands
);
1998 /* Clear a bpstat so that it says we are not at any breakpoint.
1999 Also free any storage that is part of a bpstat. */
2002 bpstat_clear (bpstat
*bsp
)
2019 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2020 is part of the bpstat is copied as well. */
2023 bpstat_copy (bpstat bs
)
2027 bpstat retval
= NULL
;
2032 for (; bs
!= NULL
; bs
= bs
->next
)
2034 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2035 memcpy (tmp
, bs
, sizeof (*tmp
));
2036 if (bs
->commands
!= NULL
)
2037 tmp
->commands
= copy_command_lines (bs
->commands
);
2038 if (bs
->old_val
!= NULL
)
2040 tmp
->old_val
= value_copy (bs
->old_val
);
2041 release_value (tmp
->old_val
);
2045 /* This is the first thing in the chain. */
2055 /* Find the bpstat associated with this breakpoint */
2058 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2063 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2065 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2071 /* Find a step_resume breakpoint associated with this bpstat.
2072 (If there are multiple step_resume bp's on the list, this function
2073 will arbitrarily pick one.)
2075 It is an error to use this function if BPSTAT doesn't contain a
2076 step_resume breakpoint.
2078 See wait_for_inferior's use of this function. */
2080 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2084 gdb_assert (bsp
!= NULL
);
2086 current_thread
= pid_to_thread_id (inferior_ptid
);
2088 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2090 if ((bsp
->breakpoint_at
!= NULL
) &&
2091 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2092 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2093 bsp
->breakpoint_at
->owner
->thread
== -1))
2094 return bsp
->breakpoint_at
->owner
;
2097 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2101 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2102 at. *BSP upon return is a bpstat which points to the remaining
2103 breakpoints stopped at (but which is not guaranteed to be good for
2104 anything but further calls to bpstat_num).
2105 Return 0 if passed a bpstat which does not indicate any breakpoints.
2106 Return -1 if stopped at a breakpoint that has been deleted since
2108 Return 1 otherwise. */
2111 bpstat_num (bpstat
*bsp
, int *num
)
2113 struct breakpoint
*b
;
2116 return 0; /* No more breakpoint values */
2118 /* We assume we'll never have several bpstats that
2119 correspond to a single breakpoint -- otherwise,
2120 this function might return the same number more
2121 than once and this will look ugly. */
2122 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2123 *bsp
= (*bsp
)->next
;
2125 return -1; /* breakpoint that's been deleted since */
2127 *num
= b
->number
; /* We have its number */
2131 /* Modify BS so that the actions will not be performed. */
2134 bpstat_clear_actions (bpstat bs
)
2136 for (; bs
!= NULL
; bs
= bs
->next
)
2138 free_command_lines (&bs
->commands
);
2139 if (bs
->old_val
!= NULL
)
2141 value_free (bs
->old_val
);
2147 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2149 cleanup_executing_breakpoints (void *ignore
)
2151 executing_breakpoint_commands
= 0;
2154 /* Execute all the commands associated with all the breakpoints at this
2155 location. Any of these commands could cause the process to proceed
2156 beyond this point, etc. We look out for such changes by checking
2157 the global "breakpoint_proceeded" after each command.
2159 Returns true if a breakpoint command resumed the inferior. In that
2160 case, it is the caller's responsibility to recall it again with the
2161 bpstat of the current thread. */
2164 bpstat_do_actions_1 (bpstat
*bsp
)
2167 struct cleanup
*old_chain
;
2170 /* Avoid endless recursion if a `source' command is contained
2172 if (executing_breakpoint_commands
)
2175 executing_breakpoint_commands
= 1;
2176 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2178 /* This pointer will iterate over the list of bpstat's. */
2181 breakpoint_proceeded
= 0;
2182 for (; bs
!= NULL
; bs
= bs
->next
)
2184 struct command_line
*cmd
;
2185 struct cleanup
*this_cmd_tree_chain
;
2187 /* Take ownership of the BSP's command tree, if it has one.
2189 The command tree could legitimately contain commands like
2190 'step' and 'next', which call clear_proceed_status, which
2191 frees stop_bpstat's command tree. To make sure this doesn't
2192 free the tree we're executing out from under us, we need to
2193 take ownership of the tree ourselves. Since a given bpstat's
2194 commands are only executed once, we don't need to copy it; we
2195 can clear the pointer in the bpstat, and make sure we free
2196 the tree when we're done. */
2199 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2203 execute_control_command (cmd
);
2205 if (breakpoint_proceeded
)
2211 /* We can free this command tree now. */
2212 do_cleanups (this_cmd_tree_chain
);
2214 if (breakpoint_proceeded
)
2216 if (target_can_async_p ())
2217 /* If we are in async mode, then the target might be still
2218 running, not stopped at any breakpoint, so nothing for
2219 us to do here -- just return to the event loop. */
2222 /* In sync mode, when execute_control_command returns
2223 we're already standing on the next breakpoint.
2224 Breakpoint commands for that stop were not run, since
2225 execute_command does not run breakpoint commands --
2226 only command_line_handler does, but that one is not
2227 involved in execution of breakpoint commands. So, we
2228 can now execute breakpoint commands. It should be
2229 noted that making execute_command do bpstat actions is
2230 not an option -- in this case we'll have recursive
2231 invocation of bpstat for each breakpoint with a
2232 command, and can easily blow up GDB stack. Instead, we
2233 return true, which will trigger the caller to recall us
2234 with the new stop_bpstat. */
2239 do_cleanups (old_chain
);
2244 bpstat_do_actions (void)
2246 /* Do any commands attached to breakpoint we are stopped at. */
2247 while (!ptid_equal (inferior_ptid
, null_ptid
)
2248 && target_has_execution
2249 && !is_exited (inferior_ptid
)
2250 && !is_executing (inferior_ptid
))
2251 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2252 and only return when it is stopped at the next breakpoint, we
2253 keep doing breakpoint actions until it returns false to
2254 indicate the inferior was not resumed. */
2255 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2259 /* Print out the (old or new) value associated with a watchpoint. */
2262 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2265 fprintf_unfiltered (stream
, _("<unreadable>"));
2267 value_print (val
, stream
, 0, Val_pretty_default
);
2270 /* This is the normal print function for a bpstat. In the future,
2271 much of this logic could (should?) be moved to bpstat_stop_status,
2272 by having it set different print_it values.
2274 Current scheme: When we stop, bpstat_print() is called. It loops
2275 through the bpstat list of things causing this stop, calling the
2276 print_bp_stop_message function on each one. The behavior of the
2277 print_bp_stop_message function depends on the print_it field of
2278 bpstat. If such field so indicates, call this function here.
2280 Return values from this routine (ultimately used by bpstat_print()
2281 and normal_stop() to decide what to do):
2282 PRINT_NOTHING: Means we already printed all we needed to print,
2283 don't print anything else.
2284 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2285 that something to be followed by a location.
2286 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2287 that something to be followed by a location.
2288 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2291 static enum print_stop_action
2292 print_it_typical (bpstat bs
)
2294 struct cleanup
*old_chain
, *ui_out_chain
;
2295 struct breakpoint
*b
;
2296 const struct bp_location
*bl
;
2297 struct ui_stream
*stb
;
2299 stb
= ui_out_stream_new (uiout
);
2300 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2301 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2302 which has since been deleted. */
2303 if (bs
->breakpoint_at
== NULL
)
2304 return PRINT_UNKNOWN
;
2305 bl
= bs
->breakpoint_at
;
2311 case bp_hardware_breakpoint
:
2312 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2313 if (bl
->address
!= bl
->requested_address
)
2314 breakpoint_adjustment_warning (bl
->requested_address
,
2317 annotate_breakpoint (b
->number
);
2319 ui_out_text (uiout
, "\nTemporary breakpoint ");
2321 ui_out_text (uiout
, "\nBreakpoint ");
2322 if (ui_out_is_mi_like_p (uiout
))
2324 ui_out_field_string (uiout
, "reason",
2325 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2326 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2328 ui_out_field_int (uiout
, "bkptno", b
->number
);
2329 ui_out_text (uiout
, ", ");
2330 return PRINT_SRC_AND_LOC
;
2333 case bp_shlib_event
:
2334 /* Did we stop because the user set the stop_on_solib_events
2335 variable? (If so, we report this as a generic, "Stopped due
2336 to shlib event" message.) */
2337 printf_filtered (_("Stopped due to shared library event\n"));
2338 return PRINT_NOTHING
;
2341 case bp_thread_event
:
2342 /* Not sure how we will get here.
2343 GDB should not stop for these breakpoints. */
2344 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2345 return PRINT_NOTHING
;
2348 case bp_overlay_event
:
2349 /* By analogy with the thread event, GDB should not stop for these. */
2350 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2351 return PRINT_NOTHING
;
2355 annotate_catchpoint (b
->number
);
2356 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2358 b
->triggered_dll_pathname
);
2359 return PRINT_SRC_AND_LOC
;
2362 case bp_catch_unload
:
2363 annotate_catchpoint (b
->number
);
2364 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2366 b
->triggered_dll_pathname
);
2367 return PRINT_SRC_AND_LOC
;
2371 annotate_catchpoint (b
->number
);
2372 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2374 ptid_get_pid (b
->forked_inferior_pid
));
2375 return PRINT_SRC_AND_LOC
;
2378 case bp_catch_vfork
:
2379 annotate_catchpoint (b
->number
);
2380 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2382 ptid_get_pid (b
->forked_inferior_pid
));
2383 return PRINT_SRC_AND_LOC
;
2387 annotate_catchpoint (b
->number
);
2388 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2391 return PRINT_SRC_AND_LOC
;
2395 case bp_hardware_watchpoint
:
2396 annotate_watchpoint (b
->number
);
2397 if (ui_out_is_mi_like_p (uiout
))
2400 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2402 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2403 ui_out_text (uiout
, "\nOld value = ");
2404 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2405 ui_out_field_stream (uiout
, "old", stb
);
2406 ui_out_text (uiout
, "\nNew value = ");
2407 watchpoint_value_print (b
->val
, stb
->stream
);
2408 ui_out_field_stream (uiout
, "new", stb
);
2409 do_cleanups (ui_out_chain
);
2410 ui_out_text (uiout
, "\n");
2411 /* More than one watchpoint may have been triggered. */
2412 return PRINT_UNKNOWN
;
2415 case bp_read_watchpoint
:
2416 if (ui_out_is_mi_like_p (uiout
))
2419 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2421 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2422 ui_out_text (uiout
, "\nValue = ");
2423 watchpoint_value_print (b
->val
, stb
->stream
);
2424 ui_out_field_stream (uiout
, "value", stb
);
2425 do_cleanups (ui_out_chain
);
2426 ui_out_text (uiout
, "\n");
2427 return PRINT_UNKNOWN
;
2430 case bp_access_watchpoint
:
2431 if (bs
->old_val
!= NULL
)
2433 annotate_watchpoint (b
->number
);
2434 if (ui_out_is_mi_like_p (uiout
))
2437 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2439 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2440 ui_out_text (uiout
, "\nOld value = ");
2441 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2442 ui_out_field_stream (uiout
, "old", stb
);
2443 ui_out_text (uiout
, "\nNew value = ");
2448 if (ui_out_is_mi_like_p (uiout
))
2451 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2452 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2453 ui_out_text (uiout
, "\nValue = ");
2455 watchpoint_value_print (b
->val
, stb
->stream
);
2456 ui_out_field_stream (uiout
, "new", stb
);
2457 do_cleanups (ui_out_chain
);
2458 ui_out_text (uiout
, "\n");
2459 return PRINT_UNKNOWN
;
2462 /* Fall through, we don't deal with these types of breakpoints
2466 if (ui_out_is_mi_like_p (uiout
))
2469 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2470 return PRINT_UNKNOWN
;
2474 if (ui_out_is_mi_like_p (uiout
))
2477 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2478 return PRINT_UNKNOWN
;
2483 case bp_longjmp_resume
:
2484 case bp_step_resume
:
2485 case bp_watchpoint_scope
:
2488 return PRINT_UNKNOWN
;
2492 /* Generic routine for printing messages indicating why we
2493 stopped. The behavior of this function depends on the value
2494 'print_it' in the bpstat structure. Under some circumstances we
2495 may decide not to print anything here and delegate the task to
2498 static enum print_stop_action
2499 print_bp_stop_message (bpstat bs
)
2501 switch (bs
->print_it
)
2504 /* Nothing should be printed for this bpstat entry. */
2505 return PRINT_UNKNOWN
;
2509 /* We still want to print the frame, but we already printed the
2510 relevant messages. */
2511 return PRINT_SRC_AND_LOC
;
2514 case print_it_normal
:
2516 const struct bp_location
*bl
= bs
->breakpoint_at
;
2517 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2519 /* Normal case. Call the breakpoint's print_it method, or
2520 print_it_typical. */
2521 /* FIXME: how breakpoint can ever be NULL here? */
2522 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2523 return b
->ops
->print_it (b
);
2525 return print_it_typical (bs
);
2530 internal_error (__FILE__
, __LINE__
,
2531 _("print_bp_stop_message: unrecognized enum value"));
2536 /* Print a message indicating what happened. This is called from
2537 normal_stop(). The input to this routine is the head of the bpstat
2538 list - a list of the eventpoints that caused this stop. This
2539 routine calls the generic print routine for printing a message
2540 about reasons for stopping. This will print (for example) the
2541 "Breakpoint n," part of the output. The return value of this
2544 PRINT_UNKNOWN: Means we printed nothing
2545 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2546 code to print the location. An example is
2547 "Breakpoint 1, " which should be followed by
2549 PRINT_SRC_ONLY: Means we printed something, but there is no need
2550 to also print the location part of the message.
2551 An example is the catch/throw messages, which
2552 don't require a location appended to the end.
2553 PRINT_NOTHING: We have done some printing and we don't need any
2554 further info to be printed.*/
2556 enum print_stop_action
2557 bpstat_print (bpstat bs
)
2561 /* Maybe another breakpoint in the chain caused us to stop.
2562 (Currently all watchpoints go on the bpstat whether hit or not.
2563 That probably could (should) be changed, provided care is taken
2564 with respect to bpstat_explains_signal). */
2565 for (; bs
; bs
= bs
->next
)
2567 val
= print_bp_stop_message (bs
);
2568 if (val
== PRINT_SRC_ONLY
2569 || val
== PRINT_SRC_AND_LOC
2570 || val
== PRINT_NOTHING
)
2574 /* We reached the end of the chain, or we got a null BS to start
2575 with and nothing was printed. */
2576 return PRINT_UNKNOWN
;
2579 /* Evaluate the expression EXP and return 1 if value is zero.
2580 This is used inside a catch_errors to evaluate the breakpoint condition.
2581 The argument is a "struct expression *" that has been cast to char * to
2582 make it pass through catch_errors. */
2585 breakpoint_cond_eval (void *exp
)
2587 struct value
*mark
= value_mark ();
2588 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2589 value_free_to_mark (mark
);
2593 /* Allocate a new bpstat and chain it to the current one. */
2596 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2600 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2602 bs
->breakpoint_at
= bl
;
2603 /* If the condition is false, etc., don't do the commands. */
2604 bs
->commands
= NULL
;
2606 bs
->print_it
= print_it_normal
;
2610 /* The target has stopped with waitstatus WS. Check if any hardware
2611 watchpoints have triggered, according to the target. */
2614 watchpoints_triggered (struct target_waitstatus
*ws
)
2616 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2618 struct breakpoint
*b
;
2620 if (!stopped_by_watchpoint
)
2622 /* We were not stopped by a watchpoint. Mark all watchpoints
2623 as not triggered. */
2625 if (b
->type
== bp_hardware_watchpoint
2626 || b
->type
== bp_read_watchpoint
2627 || b
->type
== bp_access_watchpoint
)
2628 b
->watchpoint_triggered
= watch_triggered_no
;
2633 if (!target_stopped_data_address (¤t_target
, &addr
))
2635 /* We were stopped by a watchpoint, but we don't know where.
2636 Mark all watchpoints as unknown. */
2638 if (b
->type
== bp_hardware_watchpoint
2639 || b
->type
== bp_read_watchpoint
2640 || b
->type
== bp_access_watchpoint
)
2641 b
->watchpoint_triggered
= watch_triggered_unknown
;
2643 return stopped_by_watchpoint
;
2646 /* The target could report the data address. Mark watchpoints
2647 affected by this data address as triggered, and all others as not
2651 if (b
->type
== bp_hardware_watchpoint
2652 || b
->type
== bp_read_watchpoint
2653 || b
->type
== bp_access_watchpoint
)
2655 struct bp_location
*loc
;
2658 b
->watchpoint_triggered
= watch_triggered_no
;
2659 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2660 /* Exact match not required. Within range is
2662 if (target_watchpoint_addr_within_range (¤t_target
,
2666 b
->watchpoint_triggered
= watch_triggered_yes
;
2674 /* Possible return values for watchpoint_check (this can't be an enum
2675 because of check_errors). */
2676 /* The watchpoint has been deleted. */
2677 #define WP_DELETED 1
2678 /* The value has changed. */
2679 #define WP_VALUE_CHANGED 2
2680 /* The value has not changed. */
2681 #define WP_VALUE_NOT_CHANGED 3
2683 #define BP_TEMPFLAG 1
2684 #define BP_HARDWAREFLAG 2
2686 /* Check watchpoint condition. */
2689 watchpoint_check (void *p
)
2691 bpstat bs
= (bpstat
) p
;
2692 struct breakpoint
*b
;
2693 struct frame_info
*fr
;
2694 int within_current_scope
;
2696 b
= bs
->breakpoint_at
->owner
;
2698 if (b
->exp_valid_block
== NULL
)
2699 within_current_scope
= 1;
2702 /* There is no current frame at this moment. If we're going to have
2703 any chance of handling watchpoints on local variables, we'll need
2704 the frame chain (so we can determine if we're in scope). */
2705 reinit_frame_cache ();
2706 fr
= frame_find_by_id (b
->watchpoint_frame
);
2707 within_current_scope
= (fr
!= NULL
);
2709 /* If we've gotten confused in the unwinder, we might have
2710 returned a frame that can't describe this variable. */
2711 if (within_current_scope
2712 && (block_linkage_function (b
->exp_valid_block
)
2713 != get_frame_function (fr
)))
2714 within_current_scope
= 0;
2716 /* in_function_epilogue_p() returns a non-zero value if we're still
2717 in the function but the stack frame has already been invalidated.
2718 Since we can't rely on the values of local variables after the
2719 stack has been destroyed, we are treating the watchpoint in that
2720 state as `not changed' without further checking.
2722 vinschen/2003-09-04: The former implementation left out the case
2723 that the watchpoint frame couldn't be found by frame_find_by_id()
2724 because the current PC is currently in an epilogue. Calling
2725 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2726 if ((!within_current_scope
|| fr
== get_current_frame ())
2727 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2728 return WP_VALUE_NOT_CHANGED
;
2729 if (fr
&& within_current_scope
)
2730 /* If we end up stopping, the current frame will get selected
2731 in normal_stop. So this call to select_frame won't affect
2736 if (within_current_scope
)
2738 /* We use value_{,free_to_}mark because it could be a
2739 *long* time before we return to the command level and
2740 call free_all_values. We can't call free_all_values because
2741 we might be in the middle of evaluating a function call. */
2743 struct value
*mark
= value_mark ();
2744 struct value
*new_val
;
2746 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2747 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2748 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2750 if (new_val
!= NULL
)
2752 release_value (new_val
);
2753 value_free_to_mark (mark
);
2755 bs
->old_val
= b
->val
;
2758 /* We will stop here */
2759 return WP_VALUE_CHANGED
;
2763 /* Nothing changed, don't do anything. */
2764 value_free_to_mark (mark
);
2765 /* We won't stop here */
2766 return WP_VALUE_NOT_CHANGED
;
2771 /* This seems like the only logical thing to do because
2772 if we temporarily ignored the watchpoint, then when
2773 we reenter the block in which it is valid it contains
2774 garbage (in the case of a function, it may have two
2775 garbage values, one before and one after the prologue).
2776 So we can't even detect the first assignment to it and
2777 watch after that (since the garbage may or may not equal
2778 the first value assigned). */
2779 /* We print all the stop information in print_it_typical(), but
2780 in this case, by the time we call print_it_typical() this bp
2781 will be deleted already. So we have no choice but print the
2782 information here. */
2783 if (ui_out_is_mi_like_p (uiout
))
2785 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2786 ui_out_text (uiout
, "\nWatchpoint ");
2787 ui_out_field_int (uiout
, "wpnum", b
->number
);
2788 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2789 which its expression is valid.\n");
2791 if (b
->related_breakpoint
)
2792 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2793 b
->disposition
= disp_del_at_next_stop
;
2799 /* Return true if it looks like target has stopped due to hitting
2800 breakpoint location BL. This function does not check if we
2801 should stop, only if BL explains the stop. */
2803 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2805 struct breakpoint
*b
= bl
->owner
;
2807 if (b
->type
!= bp_watchpoint
2808 && b
->type
!= bp_hardware_watchpoint
2809 && b
->type
!= bp_read_watchpoint
2810 && b
->type
!= bp_access_watchpoint
2811 && b
->type
!= bp_hardware_breakpoint
2812 && b
->type
!= bp_catch_fork
2813 && b
->type
!= bp_catch_vfork
2814 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2816 if (bl
->address
!= bp_addr
) /* address doesn't match */
2818 if (overlay_debugging
/* unmapped overlay section */
2819 && section_is_overlay (bl
->section
)
2820 && !section_is_mapped (bl
->section
))
2824 /* Continuable hardware watchpoints are treated as non-existent if the
2825 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2826 some data address). Otherwise gdb won't stop on a break instruction
2827 in the code (not from a breakpoint) when a hardware watchpoint has
2828 been defined. Also skip watchpoints which we know did not trigger
2829 (did not match the data address). */
2831 if ((b
->type
== bp_hardware_watchpoint
2832 || b
->type
== bp_read_watchpoint
2833 || b
->type
== bp_access_watchpoint
)
2834 && b
->watchpoint_triggered
== watch_triggered_no
)
2837 if (b
->type
== bp_hardware_breakpoint
)
2839 if (bl
->address
!= bp_addr
)
2841 if (overlay_debugging
/* unmapped overlay section */
2842 && section_is_overlay (bl
->section
)
2843 && !section_is_mapped (bl
->section
))
2847 /* Is this a catchpoint of a load or unload? If so, did we
2848 get a load or unload of the specified library? If not,
2850 if ((b
->type
== bp_catch_load
)
2851 #if defined(SOLIB_HAVE_LOAD_EVENT)
2852 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2853 || ((b
->dll_pathname
!= NULL
)
2854 && (strcmp (b
->dll_pathname
,
2855 SOLIB_LOADED_LIBRARY_PATHNAME (
2856 PIDGET (inferior_ptid
)))
2862 if ((b
->type
== bp_catch_unload
)
2863 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2864 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2865 || ((b
->dll_pathname
!= NULL
)
2866 && (strcmp (b
->dll_pathname
,
2867 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2868 PIDGET (inferior_ptid
)))
2874 if ((b
->type
== bp_catch_fork
)
2875 && !inferior_has_forked (inferior_ptid
,
2876 &b
->forked_inferior_pid
))
2879 if ((b
->type
== bp_catch_vfork
)
2880 && !inferior_has_vforked (inferior_ptid
,
2881 &b
->forked_inferior_pid
))
2884 if ((b
->type
== bp_catch_exec
)
2885 && !inferior_has_execd (inferior_ptid
, &b
->exec_pathname
))
2891 /* If BS refers to a watchpoint, determine if the watched values
2892 has actually changed, and we should stop. If not, set BS->stop
2895 bpstat_check_watchpoint (bpstat bs
)
2897 const struct bp_location
*bl
= bs
->breakpoint_at
;
2898 struct breakpoint
*b
= bl
->owner
;
2900 if (b
->type
== bp_watchpoint
2901 || b
->type
== bp_read_watchpoint
2902 || b
->type
== bp_access_watchpoint
2903 || b
->type
== bp_hardware_watchpoint
)
2907 int must_check_value
= 0;
2909 if (b
->type
== bp_watchpoint
)
2910 /* For a software watchpoint, we must always check the
2912 must_check_value
= 1;
2913 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2914 /* We have a hardware watchpoint (read, write, or access)
2915 and the target earlier reported an address watched by
2917 must_check_value
= 1;
2918 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2919 && b
->type
== bp_hardware_watchpoint
)
2920 /* We were stopped by a hardware watchpoint, but the target could
2921 not report the data address. We must check the watchpoint's
2922 value. Access and read watchpoints are out of luck; without
2923 a data address, we can't figure it out. */
2924 must_check_value
= 1;
2926 if (must_check_value
)
2928 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2930 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2931 int e
= catch_errors (watchpoint_check
, bs
, message
,
2933 do_cleanups (cleanups
);
2937 /* We've already printed what needs to be printed. */
2938 bs
->print_it
= print_it_done
;
2941 case WP_VALUE_CHANGED
:
2942 if (b
->type
== bp_read_watchpoint
)
2944 /* Don't stop: read watchpoints shouldn't fire if
2945 the value has changed. This is for targets
2946 which cannot set read-only watchpoints. */
2947 bs
->print_it
= print_it_noop
;
2951 case WP_VALUE_NOT_CHANGED
:
2952 if (b
->type
== bp_hardware_watchpoint
2953 || b
->type
== bp_watchpoint
)
2955 /* Don't stop: write watchpoints shouldn't fire if
2956 the value hasn't changed. */
2957 bs
->print_it
= print_it_noop
;
2965 /* Error from catch_errors. */
2966 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2967 if (b
->related_breakpoint
)
2968 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2969 b
->disposition
= disp_del_at_next_stop
;
2970 /* We've already printed what needs to be printed. */
2971 bs
->print_it
= print_it_done
;
2975 else /* must_check_value == 0 */
2977 /* This is a case where some watchpoint(s) triggered, but
2978 not at the address of this watchpoint, or else no
2979 watchpoint triggered after all. So don't print
2980 anything for this watchpoint. */
2981 bs
->print_it
= print_it_noop
;
2988 /* Check conditions (condition proper, frame, thread and ignore count)
2989 of breakpoint referred to by BS. If we should not stop for this
2990 breakpoint, set BS->stop to 0. */
2992 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2994 int thread_id
= pid_to_thread_id (ptid
);
2995 const struct bp_location
*bl
= bs
->breakpoint_at
;
2996 struct breakpoint
*b
= bl
->owner
;
2998 if (frame_id_p (b
->frame_id
)
2999 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
3003 int value_is_zero
= 0;
3005 /* If this is a scope breakpoint, mark the associated
3006 watchpoint as triggered so that we will handle the
3007 out-of-scope event. We'll get to the watchpoint next
3009 if (b
->type
== bp_watchpoint_scope
)
3010 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3012 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3014 /* Need to select the frame, with all that implies
3015 so that the conditions will have the right context. */
3016 select_frame (get_current_frame ());
3018 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3019 "Error in testing breakpoint condition:\n",
3021 /* FIXME-someday, should give breakpoint # */
3024 if (bl
->cond
&& value_is_zero
)
3028 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3032 else if (b
->ignore_count
> 0)
3035 annotate_ignore_count_change ();
3037 /* Increase the hit count even though we don't
3045 /* Get a bpstat associated with having just stopped at address
3046 BP_ADDR in thread PTID.
3048 Determine whether we stopped at a breakpoint, etc, or whether we
3049 don't understand this stop. Result is a chain of bpstat's such that:
3051 if we don't understand the stop, the result is a null pointer.
3053 if we understand why we stopped, the result is not null.
3055 Each element of the chain refers to a particular breakpoint or
3056 watchpoint at which we have stopped. (We may have stopped for
3057 several reasons concurrently.)
3059 Each element of the chain has valid next, breakpoint_at,
3060 commands, FIXME??? fields. */
3063 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3065 struct breakpoint
*b
= NULL
;
3066 const struct bp_location
*bl
;
3067 struct bp_location
*loc
;
3068 /* Root of the chain of bpstat's */
3069 struct bpstats root_bs
[1];
3070 /* Pointer to the last thing in the chain currently. */
3071 bpstat bs
= root_bs
;
3073 int need_remove_insert
;
3075 ALL_BP_LOCATIONS (bl
)
3079 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3082 /* For hardware watchpoints, we look only at the first location.
3083 The watchpoint_check function will work on entire expression,
3084 not the individual locations. For read watchopints, the
3085 watchpoints_triggered function have checked all locations
3088 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3091 if (!bpstat_check_location (bl
, bp_addr
))
3094 /* Come here if it's a watchpoint, or if the break address matches */
3096 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3098 /* Assume we stop. Should we find watchpoint that is not actually
3099 triggered, or if condition of breakpoint is false, we'll reset
3104 bpstat_check_watchpoint (bs
);
3108 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3109 /* We do not stop for these. */
3112 bpstat_check_breakpoint_conditions (bs
, ptid
);
3118 /* We will stop here */
3119 if (b
->disposition
== disp_disable
)
3121 if (b
->enable_state
!= bp_permanent
)
3122 b
->enable_state
= bp_disabled
;
3123 update_global_location_list (0);
3127 bs
->commands
= b
->commands
;
3129 (strcmp ("silent", bs
->commands
->line
) == 0
3130 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3132 bs
->commands
= bs
->commands
->next
;
3135 bs
->commands
= copy_command_lines (bs
->commands
);
3138 /* Print nothing for this entry if we dont stop or if we dont print. */
3139 if (bs
->stop
== 0 || bs
->print
== 0)
3140 bs
->print_it
= print_it_noop
;
3143 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3145 if (loc
->address
== bp_addr
)
3147 bs
= bpstat_alloc (loc
, bs
);
3148 /* For hits of moribund locations, we should just proceed. */
3151 bs
->print_it
= print_it_noop
;
3155 bs
->next
= NULL
; /* Terminate the chain */
3156 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3158 /* If we aren't stopping, the value of some hardware watchpoint may
3159 not have changed, but the intermediate memory locations we are
3160 watching may have. Don't bother if we're stopping; this will get
3162 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3166 need_remove_insert
= 0;
3168 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3170 && bs
->breakpoint_at
->owner
3171 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3172 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3173 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3175 /* remove/insert can invalidate bs->breakpoint_at, if this
3176 location is no longer used by the watchpoint. Prevent
3177 further code from trying to use it. */
3178 bs
->breakpoint_at
= NULL
;
3179 need_remove_insert
= 1;
3182 if (need_remove_insert
)
3184 remove_breakpoints ();
3185 insert_breakpoints ();
3188 return root_bs
->next
;
3191 /* Tell what to do about this bpstat. */
3193 bpstat_what (bpstat bs
)
3195 /* Classify each bpstat as one of the following. */
3198 /* This bpstat element has no effect on the main_action. */
3201 /* There was a watchpoint, stop but don't print. */
3204 /* There was a watchpoint, stop and print. */
3207 /* There was a breakpoint but we're not stopping. */
3210 /* There was a breakpoint, stop but don't print. */
3213 /* There was a breakpoint, stop and print. */
3216 /* We hit the longjmp breakpoint. */
3219 /* We hit the longjmp_resume breakpoint. */
3222 /* We hit the step_resume breakpoint. */
3225 /* We hit the shared library event breakpoint. */
3228 /* We caught a shared library event. */
3231 /* This is just used to count how many enums there are. */
3235 /* Here is the table which drives this routine. So that we can
3236 format it pretty, we define some abbreviations for the
3237 enum bpstat_what codes. */
3238 #define kc BPSTAT_WHAT_KEEP_CHECKING
3239 #define ss BPSTAT_WHAT_STOP_SILENT
3240 #define sn BPSTAT_WHAT_STOP_NOISY
3241 #define sgl BPSTAT_WHAT_SINGLE
3242 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3243 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3244 #define sr BPSTAT_WHAT_STEP_RESUME
3245 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3246 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3248 /* "Can't happen." Might want to print an error message.
3249 abort() is not out of the question, but chances are GDB is just
3250 a bit confused, not unusable. */
3251 #define err BPSTAT_WHAT_STOP_NOISY
3253 /* Given an old action and a class, come up with a new action. */
3254 /* One interesting property of this table is that wp_silent is the same
3255 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3256 after stopping, the check for whether to step over a breakpoint
3257 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3258 reference to how we stopped. We retain separate wp_silent and
3259 bp_silent codes in case we want to change that someday.
3261 Another possibly interesting property of this table is that
3262 there's a partial ordering, priority-like, of the actions. Once
3263 you've decided that some action is appropriate, you'll never go
3264 back and decide something of a lower priority is better. The
3267 kc < clr sgl shl shlr slr sn sr ss
3268 sgl < shl shlr slr sn sr ss
3269 slr < err shl shlr sn sr ss
3270 clr < err shl shlr sn sr ss
3277 What I think this means is that we don't need a damned table
3278 here. If you just put the rows and columns in the right order,
3279 it'd look awfully regular. We could simply walk the bpstat list
3280 and choose the highest priority action we find, with a little
3281 logic to handle the 'err' cases. */
3283 /* step_resume entries: a step resume breakpoint overrides another
3284 breakpoint of signal handling (see comment in wait_for_inferior
3285 at where we set the step_resume breakpoint). */
3287 static const enum bpstat_what_main_action
3288 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3291 /* kc ss sn sgl slr clr sr shl shlr
3294 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3296 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3298 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3300 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3302 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3304 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3306 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3308 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3310 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3312 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3314 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3328 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3329 struct bpstat_what retval
;
3331 retval
.call_dummy
= 0;
3332 for (; bs
!= NULL
; bs
= bs
->next
)
3334 enum class bs_class
= no_effect
;
3335 if (bs
->breakpoint_at
== NULL
)
3336 /* I suspect this can happen if it was a momentary breakpoint
3337 which has since been deleted. */
3339 if (bs
->breakpoint_at
->owner
== NULL
)
3340 bs_class
= bp_nostop
;
3342 switch (bs
->breakpoint_at
->owner
->type
)
3348 case bp_hardware_breakpoint
:
3354 bs_class
= bp_noisy
;
3356 bs_class
= bp_silent
;
3359 bs_class
= bp_nostop
;
3362 case bp_hardware_watchpoint
:
3363 case bp_read_watchpoint
:
3364 case bp_access_watchpoint
:
3368 bs_class
= wp_noisy
;
3370 bs_class
= wp_silent
;
3373 /* There was a watchpoint, but we're not stopping.
3374 This requires no further action. */
3375 bs_class
= no_effect
;
3378 bs_class
= long_jump
;
3380 case bp_longjmp_resume
:
3381 bs_class
= long_resume
;
3383 case bp_step_resume
:
3386 bs_class
= step_resume
;
3389 /* It is for the wrong frame. */
3390 bs_class
= bp_nostop
;
3392 case bp_watchpoint_scope
:
3393 bs_class
= bp_nostop
;
3395 case bp_shlib_event
:
3396 bs_class
= shlib_event
;
3398 case bp_thread_event
:
3399 case bp_overlay_event
:
3400 bs_class
= bp_nostop
;
3403 case bp_catch_unload
:
3404 /* Only if this catchpoint triggered should we cause the
3405 step-out-of-dld behaviour. Otherwise, we ignore this
3408 bs_class
= catch_shlib_event
;
3410 bs_class
= no_effect
;
3413 case bp_catch_vfork
:
3418 bs_class
= bp_noisy
;
3420 bs_class
= bp_silent
;
3423 /* There was a catchpoint, but we're not stopping.
3424 This requires no further action. */
3425 bs_class
= no_effect
;
3428 /* Make sure the action is stop (silent or noisy),
3429 so infrun.c pops the dummy frame. */
3430 bs_class
= bp_silent
;
3431 retval
.call_dummy
= 1;
3434 current_action
= table
[(int) bs_class
][(int) current_action
];
3436 retval
.main_action
= current_action
;
3440 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3441 without hardware support). This isn't related to a specific bpstat,
3442 just to things like whether watchpoints are set. */
3445 bpstat_should_step (void)
3447 struct breakpoint
*b
;
3449 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3456 /* Given a bpstat that records zero or more triggered eventpoints, this
3457 function returns another bpstat which contains only the catchpoints
3458 on that first list, if any. */
3460 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3462 struct bpstats root_bs
[1];
3463 bpstat bs
= root_bs
;
3464 struct breakpoint
*ep
;
3467 bpstat_clear (cp_list
);
3468 root_bs
->next
= NULL
;
3470 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3472 /* Is this eventpoint a catchpoint? If not, ignore it. */
3473 ep
= ep_list
->breakpoint_at
->owner
;
3476 if ((ep
->type
!= bp_catch_load
) &&
3477 (ep
->type
!= bp_catch_unload
))
3478 /* pai: (temp) ADD fork/vfork here!! */
3481 /* Yes; add it to the list. */
3482 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3487 #if defined(SOLIB_ADD)
3488 /* Also, for each triggered catchpoint, tag it with the name of
3489 the library that caused this trigger. (We copy the name now,
3490 because it's only guaranteed to be available NOW, when the
3491 catchpoint triggers. Clients who may wish to know the name
3492 later must get it from the catchpoint itself.) */
3493 if (ep
->triggered_dll_pathname
!= NULL
)
3494 xfree (ep
->triggered_dll_pathname
);
3495 if (ep
->type
== bp_catch_load
)
3496 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3497 PIDGET (inferior_ptid
));
3499 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3500 PIDGET (inferior_ptid
));
3502 dll_pathname
= NULL
;
3506 ep
->triggered_dll_pathname
= (char *)
3507 xmalloc (strlen (dll_pathname
) + 1);
3508 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3511 ep
->triggered_dll_pathname
= NULL
;
3517 static void print_breakpoint_location (struct breakpoint
*b
,
3518 struct bp_location
*loc
,
3520 struct ui_stream
*stb
)
3525 = find_pc_sect_function (loc
->address
, loc
->section
);
3528 ui_out_text (uiout
, "in ");
3529 ui_out_field_string (uiout
, "func",
3530 SYMBOL_PRINT_NAME (sym
));
3531 ui_out_wrap_hint (uiout
, wrap_indent
);
3532 ui_out_text (uiout
, " at ");
3534 ui_out_field_string (uiout
, "file", b
->source_file
);
3535 ui_out_text (uiout
, ":");
3537 if (ui_out_is_mi_like_p (uiout
))
3539 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3540 char *fullname
= symtab_to_fullname (sal
.symtab
);
3543 ui_out_field_string (uiout
, "fullname", fullname
);
3546 ui_out_field_int (uiout
, "line", b
->line_number
);
3550 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3554 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3555 ui_out_field_stream (uiout
, "at", stb
);
3559 /* Print B to gdb_stdout. */
3561 print_one_breakpoint_location (struct breakpoint
*b
,
3562 struct bp_location
*loc
,
3564 CORE_ADDR
*last_addr
)
3566 struct command_line
*l
;
3568 struct ep_type_description
3573 static struct ep_type_description bptypes
[] =
3575 {bp_none
, "?deleted?"},
3576 {bp_breakpoint
, "breakpoint"},
3577 {bp_hardware_breakpoint
, "hw breakpoint"},
3578 {bp_until
, "until"},
3579 {bp_finish
, "finish"},
3580 {bp_watchpoint
, "watchpoint"},
3581 {bp_hardware_watchpoint
, "hw watchpoint"},
3582 {bp_read_watchpoint
, "read watchpoint"},
3583 {bp_access_watchpoint
, "acc watchpoint"},
3584 {bp_longjmp
, "longjmp"},
3585 {bp_longjmp_resume
, "longjmp resume"},
3586 {bp_step_resume
, "step resume"},
3587 {bp_watchpoint_scope
, "watchpoint scope"},
3588 {bp_call_dummy
, "call dummy"},
3589 {bp_shlib_event
, "shlib events"},
3590 {bp_thread_event
, "thread events"},
3591 {bp_overlay_event
, "overlay events"},
3592 {bp_catch_load
, "catch load"},
3593 {bp_catch_unload
, "catch unload"},
3594 {bp_catch_fork
, "catch fork"},
3595 {bp_catch_vfork
, "catch vfork"},
3596 {bp_catch_exec
, "catch exec"}
3599 static char bpenables
[] = "nynny";
3600 char wrap_indent
[80];
3601 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3602 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3603 struct cleanup
*bkpt_chain
;
3605 int header_of_multiple
= 0;
3606 int part_of_multiple
= (loc
!= NULL
);
3608 gdb_assert (!loc
|| loc_number
!= 0);
3609 /* See comment in print_one_breakpoint concerning
3610 treatment of breakpoints with single disabled
3614 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3615 header_of_multiple
= 1;
3620 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3624 if (part_of_multiple
)
3627 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3628 ui_out_field_string (uiout
, "number", formatted
);
3633 ui_out_field_int (uiout
, "number", b
->number
);
3638 if (part_of_multiple
)
3639 ui_out_field_skip (uiout
, "type");
3642 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3643 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3644 internal_error (__FILE__
, __LINE__
,
3645 _("bptypes table does not describe type #%d."),
3647 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3652 if (part_of_multiple
)
3653 ui_out_field_skip (uiout
, "disp");
3655 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3660 if (part_of_multiple
)
3661 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3663 ui_out_field_fmt (uiout
, "enabled", "%c",
3664 bpenables
[(int) b
->enable_state
]);
3665 ui_out_spaces (uiout
, 2);
3669 strcpy (wrap_indent
, " ");
3672 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3673 strcat (wrap_indent
, " ");
3675 strcat (wrap_indent
, " ");
3678 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3680 /* Although the print_one can possibly print
3681 all locations, calling it here is not likely
3682 to get any nice result. So, make sure there's
3683 just one location. */
3684 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3685 b
->ops
->print_one (b
, last_addr
);
3691 internal_error (__FILE__
, __LINE__
,
3692 _("print_one_breakpoint: bp_none encountered\n"));
3696 case bp_hardware_watchpoint
:
3697 case bp_read_watchpoint
:
3698 case bp_access_watchpoint
:
3699 /* Field 4, the address, is omitted (which makes the columns
3700 not line up too nicely with the headers, but the effect
3701 is relatively readable). */
3703 ui_out_field_skip (uiout
, "addr");
3705 print_expression (b
->exp
, stb
->stream
);
3706 ui_out_field_stream (uiout
, "what", stb
);
3710 case bp_catch_unload
:
3711 /* Field 4, the address, is omitted (which makes the columns
3712 not line up too nicely with the headers, but the effect
3713 is relatively readable). */
3715 ui_out_field_skip (uiout
, "addr");
3717 if (b
->dll_pathname
== NULL
)
3719 ui_out_field_string (uiout
, "what", "<any library>");
3720 ui_out_spaces (uiout
, 1);
3724 ui_out_text (uiout
, "library \"");
3725 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3726 ui_out_text (uiout
, "\" ");
3731 case bp_catch_vfork
:
3732 /* Field 4, the address, is omitted (which makes the columns
3733 not line up too nicely with the headers, but the effect
3734 is relatively readable). */
3736 ui_out_field_skip (uiout
, "addr");
3738 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
3740 ui_out_text (uiout
, "process ");
3741 ui_out_field_int (uiout
, "what",
3742 ptid_get_pid (b
->forked_inferior_pid
));
3743 ui_out_spaces (uiout
, 1);
3748 /* Field 4, the address, is omitted (which makes the columns
3749 not line up too nicely with the headers, but the effect
3750 is relatively readable). */
3752 ui_out_field_skip (uiout
, "addr");
3754 if (b
->exec_pathname
!= NULL
)
3756 ui_out_text (uiout
, "program \"");
3757 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3758 ui_out_text (uiout
, "\" ");
3763 case bp_hardware_breakpoint
:
3767 case bp_longjmp_resume
:
3768 case bp_step_resume
:
3769 case bp_watchpoint_scope
:
3771 case bp_shlib_event
:
3772 case bp_thread_event
:
3773 case bp_overlay_event
:
3777 if (header_of_multiple
)
3778 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3779 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3780 ui_out_field_string (uiout
, "addr", "<PENDING>");
3782 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3785 if (!header_of_multiple
)
3786 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3788 *last_addr
= b
->loc
->address
;
3792 if (!part_of_multiple
&& b
->thread
!= -1)
3794 /* FIXME: This seems to be redundant and lost here; see the
3795 "stop only in" line a little further down. */
3796 ui_out_text (uiout
, " thread ");
3797 ui_out_field_int (uiout
, "thread", b
->thread
);
3800 ui_out_text (uiout
, "\n");
3802 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3805 ui_out_text (uiout
, "\tstop only in stack frame at ");
3806 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3808 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3809 ui_out_text (uiout
, "\n");
3812 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3814 /* We do not print the condition for Ada exception catchpoints
3815 because the condition is an internal implementation detail
3816 that we do not want to expose to the user. */
3818 ui_out_text (uiout
, "\tstop only if ");
3819 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3820 ui_out_text (uiout
, "\n");
3823 if (!part_of_multiple
&& b
->thread
!= -1)
3825 /* FIXME should make an annotation for this */
3826 ui_out_text (uiout
, "\tstop only in thread ");
3827 ui_out_field_int (uiout
, "thread", b
->thread
);
3828 ui_out_text (uiout
, "\n");
3831 if (!part_of_multiple
&& b
->hit_count
)
3833 /* FIXME should make an annotation for this */
3834 if (ep_is_catchpoint (b
))
3835 ui_out_text (uiout
, "\tcatchpoint");
3837 ui_out_text (uiout
, "\tbreakpoint");
3838 ui_out_text (uiout
, " already hit ");
3839 ui_out_field_int (uiout
, "times", b
->hit_count
);
3840 if (b
->hit_count
== 1)
3841 ui_out_text (uiout
, " time\n");
3843 ui_out_text (uiout
, " times\n");
3846 /* Output the count also if it is zero, but only if this is
3847 mi. FIXME: Should have a better test for this. */
3848 if (ui_out_is_mi_like_p (uiout
))
3849 if (!part_of_multiple
&& b
->hit_count
== 0)
3850 ui_out_field_int (uiout
, "times", b
->hit_count
);
3852 if (!part_of_multiple
&& b
->ignore_count
)
3855 ui_out_text (uiout
, "\tignore next ");
3856 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3857 ui_out_text (uiout
, " hits\n");
3860 if (!part_of_multiple
&& (l
= b
->commands
))
3862 struct cleanup
*script_chain
;
3865 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3866 print_command_lines (uiout
, l
, 4);
3867 do_cleanups (script_chain
);
3870 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3873 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3874 else if (b
->exp_string
)
3875 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3878 do_cleanups (bkpt_chain
);
3879 do_cleanups (old_chain
);
3883 print_one_breakpoint (struct breakpoint
*b
,
3884 CORE_ADDR
*last_addr
)
3886 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3888 /* If this breakpoint has custom print function,
3889 it's already printed. Otherwise, print individual
3890 locations, if any. */
3891 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3893 /* If breakpoint has a single location that is
3894 disabled, we print it as if it had
3895 several locations, since otherwise it's hard to
3896 represent "breakpoint enabled, location disabled"
3898 Note that while hardware watchpoints have
3899 several locations internally, that's no a property
3902 && !is_hardware_watchpoint (b
)
3903 && (b
->loc
->next
|| !b
->loc
->enabled
)
3904 && !ui_out_is_mi_like_p (uiout
))
3906 struct bp_location
*loc
;
3908 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3909 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3915 struct captured_breakpoint_query_args
3921 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3923 struct captured_breakpoint_query_args
*args
= data
;
3924 struct breakpoint
*b
;
3925 CORE_ADDR dummy_addr
= 0;
3928 if (args
->bnum
== b
->number
)
3930 print_one_breakpoint (b
, &dummy_addr
);
3938 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3940 struct captured_breakpoint_query_args args
;
3942 /* For the moment we don't trust print_one_breakpoint() to not throw
3944 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3945 error_message
, RETURN_MASK_ALL
) < 0)
3951 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3952 catchpoints, et.al.). */
3955 user_settable_breakpoint (const struct breakpoint
*b
)
3957 return (b
->type
== bp_breakpoint
3958 || b
->type
== bp_catch_load
3959 || b
->type
== bp_catch_unload
3960 || b
->type
== bp_catch_fork
3961 || b
->type
== bp_catch_vfork
3962 || b
->type
== bp_catch_exec
3963 || b
->type
== bp_hardware_breakpoint
3964 || b
->type
== bp_watchpoint
3965 || b
->type
== bp_read_watchpoint
3966 || b
->type
== bp_access_watchpoint
3967 || b
->type
== bp_hardware_watchpoint
);
3970 /* Print information on user settable breakpoint (watchpoint, etc)
3971 number BNUM. If BNUM is -1 print all user settable breakpoints.
3972 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3975 breakpoint_1 (int bnum
, int allflag
)
3977 struct breakpoint
*b
;
3978 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3979 int nr_printable_breakpoints
;
3980 struct cleanup
*bkpttbl_chain
;
3982 /* Compute the number of rows in the table. */
3983 nr_printable_breakpoints
= 0;
3986 || bnum
== b
->number
)
3988 if (allflag
|| user_settable_breakpoint (b
))
3989 nr_printable_breakpoints
++;
3994 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3998 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4001 if (nr_printable_breakpoints
> 0)
4002 annotate_breakpoints_headers ();
4003 if (nr_printable_breakpoints
> 0)
4005 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4006 if (nr_printable_breakpoints
> 0)
4008 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4009 if (nr_printable_breakpoints
> 0)
4011 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4012 if (nr_printable_breakpoints
> 0)
4014 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4017 if (nr_printable_breakpoints
> 0)
4019 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
4020 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4022 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4024 if (nr_printable_breakpoints
> 0)
4026 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4027 ui_out_table_body (uiout
);
4028 if (nr_printable_breakpoints
> 0)
4029 annotate_breakpoints_table ();
4033 || bnum
== b
->number
)
4035 /* We only print out user settable breakpoints unless the
4037 if (allflag
|| user_settable_breakpoint (b
))
4038 print_one_breakpoint (b
, &last_addr
);
4041 do_cleanups (bkpttbl_chain
);
4043 if (nr_printable_breakpoints
== 0)
4046 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4048 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4053 /* Compare against (CORE_ADDR)-1 in case some compiler decides
4054 that a comparison of an unsigned with -1 is always false. */
4055 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
4056 set_next_address (current_gdbarch
, last_addr
);
4059 /* FIXME? Should this be moved up so that it is only called when
4060 there have been breakpoints? */
4061 annotate_breakpoints_table_end ();
4065 breakpoints_info (char *bnum_exp
, int from_tty
)
4070 bnum
= parse_and_eval_long (bnum_exp
);
4072 breakpoint_1 (bnum
, 0);
4076 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4081 bnum
= parse_and_eval_long (bnum_exp
);
4083 breakpoint_1 (bnum
, 1);
4087 breakpoint_has_pc (struct breakpoint
*b
,
4088 CORE_ADDR pc
, struct obj_section
*section
)
4090 struct bp_location
*bl
= b
->loc
;
4091 for (; bl
; bl
= bl
->next
)
4093 if (bl
->address
== pc
4094 && (!overlay_debugging
|| bl
->section
== section
))
4100 /* Print a message describing any breakpoints set at PC. */
4103 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
4107 struct breakpoint
*b
;
4110 others
+= breakpoint_has_pc (b
, pc
, section
);
4114 printf_filtered (_("Note: breakpoint "));
4115 else /* if (others == ???) */
4116 printf_filtered (_("Note: breakpoints "));
4118 if (breakpoint_has_pc (b
, pc
, section
))
4121 printf_filtered ("%d", b
->number
);
4122 if (b
->thread
== -1 && thread
!= -1)
4123 printf_filtered (" (all threads)");
4124 else if (b
->thread
!= -1)
4125 printf_filtered (" (thread %d)", b
->thread
);
4126 printf_filtered ("%s%s ",
4127 ((b
->enable_state
== bp_disabled
||
4128 b
->enable_state
== bp_call_disabled
)
4130 : b
->enable_state
== bp_permanent
4134 : ((others
== 1) ? " and" : ""));
4136 printf_filtered (_("also set at pc "));
4137 fputs_filtered (paddress (pc
), gdb_stdout
);
4138 printf_filtered (".\n");
4142 /* Set the default place to put a breakpoint
4143 for the `break' command with no arguments. */
4146 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4149 default_breakpoint_valid
= valid
;
4150 default_breakpoint_address
= addr
;
4151 default_breakpoint_symtab
= symtab
;
4152 default_breakpoint_line
= line
;
4155 /* Return true iff it is meaningful to use the address member of
4156 BPT. For some breakpoint types, the address member is irrelevant
4157 and it makes no sense to attempt to compare it to other addresses
4158 (or use it for any other purpose either).
4160 More specifically, each of the following breakpoint types will always
4161 have a zero valued address and we don't want check_duplicates() to mark
4162 breakpoints of any of these types to be a duplicate of an actual
4163 breakpoint at address zero:
4166 bp_hardware_watchpoint
4168 bp_access_watchpoint
4174 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4176 enum bptype type
= bpt
->type
;
4178 return (type
!= bp_watchpoint
4179 && type
!= bp_hardware_watchpoint
4180 && type
!= bp_read_watchpoint
4181 && type
!= bp_access_watchpoint
4182 && type
!= bp_catch_exec
4183 && type
!= bp_catch_fork
4184 && type
!= bp_catch_vfork
);
4187 /* Rescan breakpoints at the same address and section as BPT,
4188 marking the first one as "first" and any others as "duplicates".
4189 This is so that the bpt instruction is only inserted once.
4190 If we have a permanent breakpoint at the same place as BPT, make
4191 that one the official one, and the rest as duplicates. */
4194 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4196 struct bp_location
*b
;
4198 struct bp_location
*perm_bp
= 0;
4200 ALL_BP_LOCATIONS (b
)
4201 if (b
->owner
->enable_state
!= bp_disabled
4202 && b
->owner
->enable_state
!= bp_call_disabled
4204 && !b
->shlib_disabled
4205 && b
->address
== address
/* address / overlay match */
4206 && (!overlay_debugging
|| b
->section
== section
)
4207 && breakpoint_address_is_meaningful (b
->owner
))
4209 /* Have we found a permanent breakpoint? */
4210 if (b
->owner
->enable_state
== bp_permanent
)
4217 b
->duplicate
= count
> 1;
4220 /* If we found a permanent breakpoint at this address, go over the
4221 list again and declare all the other breakpoints there to be the
4225 perm_bp
->duplicate
= 0;
4227 /* Permanent breakpoint should always be inserted. */
4228 if (! perm_bp
->inserted
)
4229 internal_error (__FILE__
, __LINE__
,
4230 _("allegedly permanent breakpoint is not "
4231 "actually inserted"));
4233 ALL_BP_LOCATIONS (b
)
4236 if (b
->owner
->enable_state
!= bp_disabled
4237 && b
->owner
->enable_state
!= bp_call_disabled
4238 && b
->enabled
&& !b
->shlib_disabled
4239 && b
->address
== address
/* address / overlay match */
4240 && (!overlay_debugging
|| b
->section
== section
)
4241 && breakpoint_address_is_meaningful (b
->owner
))
4244 internal_error (__FILE__
, __LINE__
,
4245 _("another breakpoint was inserted on top of "
4246 "a permanent breakpoint"));
4255 check_duplicates (struct breakpoint
*bpt
)
4257 struct bp_location
*bl
= bpt
->loc
;
4259 if (! breakpoint_address_is_meaningful (bpt
))
4262 for (; bl
; bl
= bl
->next
)
4263 check_duplicates_for (bl
->address
, bl
->section
);
4267 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4268 int bnum
, int have_bnum
)
4273 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4274 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4276 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4277 bnum
, astr1
, astr2
);
4279 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4282 /* Adjust a breakpoint's address to account for architectural constraints
4283 on breakpoint placement. Return the adjusted address. Note: Very
4284 few targets require this kind of adjustment. For most targets,
4285 this function is simply the identity function. */
4288 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4290 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4292 /* Very few targets need any kind of breakpoint adjustment. */
4295 else if (bptype
== bp_watchpoint
4296 || bptype
== bp_hardware_watchpoint
4297 || bptype
== bp_read_watchpoint
4298 || bptype
== bp_access_watchpoint
4299 || bptype
== bp_catch_fork
4300 || bptype
== bp_catch_vfork
4301 || bptype
== bp_catch_exec
)
4303 /* Watchpoints and the various bp_catch_* eventpoints should not
4304 have their addresses modified. */
4309 CORE_ADDR adjusted_bpaddr
;
4311 /* Some targets have architectural constraints on the placement
4312 of breakpoint instructions. Obtain the adjusted address. */
4313 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4316 /* An adjusted breakpoint address can significantly alter
4317 a user's expectations. Print a warning if an adjustment
4319 if (adjusted_bpaddr
!= bpaddr
)
4320 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4322 return adjusted_bpaddr
;
4326 /* Allocate a struct bp_location. */
4328 static struct bp_location
*
4329 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4331 struct bp_location
*loc
, *loc_p
;
4333 loc
= xmalloc (sizeof (struct bp_location
));
4334 memset (loc
, 0, sizeof (*loc
));
4338 loc
->shlib_disabled
= 0;
4347 case bp_longjmp_resume
:
4348 case bp_step_resume
:
4349 case bp_watchpoint_scope
:
4351 case bp_shlib_event
:
4352 case bp_thread_event
:
4353 case bp_overlay_event
:
4355 case bp_catch_unload
:
4356 loc
->loc_type
= bp_loc_software_breakpoint
;
4358 case bp_hardware_breakpoint
:
4359 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4361 case bp_hardware_watchpoint
:
4362 case bp_read_watchpoint
:
4363 case bp_access_watchpoint
:
4364 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4368 case bp_catch_vfork
:
4370 loc
->loc_type
= bp_loc_other
;
4373 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4379 static void free_bp_location (struct bp_location
*loc
)
4384 if (loc
->function_name
)
4385 xfree (loc
->function_name
);
4390 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4391 that has type BPTYPE and has no locations as yet. */
4393 static struct breakpoint
*
4394 set_raw_breakpoint_without_location (enum bptype bptype
)
4396 struct breakpoint
*b
, *b1
;
4398 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4399 memset (b
, 0, sizeof (*b
));
4402 b
->language
= current_language
->la_language
;
4403 b
->input_radix
= input_radix
;
4405 b
->enable_state
= bp_enabled
;
4408 b
->ignore_count
= 0;
4410 b
->frame_id
= null_frame_id
;
4411 b
->dll_pathname
= NULL
;
4412 b
->triggered_dll_pathname
= NULL
;
4413 b
->forked_inferior_pid
= null_ptid
;
4414 b
->exec_pathname
= NULL
;
4416 b
->condition_not_parsed
= 0;
4418 /* Add this breakpoint to the end of the chain
4419 so that a list of breakpoints will come out in order
4420 of increasing numbers. */
4422 b1
= breakpoint_chain
;
4424 breakpoint_chain
= b
;
4434 /* Initialize loc->function_name. */
4436 set_breakpoint_location_function (struct bp_location
*loc
)
4438 if (loc
->owner
->type
== bp_breakpoint
4439 || loc
->owner
->type
== bp_hardware_breakpoint
)
4441 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4443 if (loc
->function_name
)
4444 loc
->function_name
= xstrdup (loc
->function_name
);
4448 /* set_raw_breakpoint is a low level routine for allocating and
4449 partially initializing a breakpoint of type BPTYPE. The newly
4450 created breakpoint's address, section, source file name, and line
4451 number are provided by SAL. The newly created and partially
4452 initialized breakpoint is added to the breakpoint chain and
4453 is also returned as the value of this function.
4455 It is expected that the caller will complete the initialization of
4456 the newly created breakpoint struct as well as output any status
4457 information regarding the creation of a new breakpoint. In
4458 particular, set_raw_breakpoint does NOT set the breakpoint
4459 number! Care should be taken to not allow an error to occur
4460 prior to completing the initialization of the breakpoint. If this
4461 should happen, a bogus breakpoint will be left on the chain. */
4464 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4466 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4467 CORE_ADDR adjusted_address
;
4469 /* Adjust the breakpoint's address prior to allocating a location.
4470 Once we call allocate_bp_location(), that mostly uninitialized
4471 location will be placed on the location chain. Adjustment of the
4472 breakpoint may cause target_read_memory() to be called and we do
4473 not want its scan of the location chain to find a breakpoint and
4474 location that's only been partially initialized. */
4475 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4477 b
->loc
= allocate_bp_location (b
, bptype
);
4478 b
->loc
->requested_address
= sal
.pc
;
4479 b
->loc
->address
= adjusted_address
;
4481 if (sal
.symtab
== NULL
)
4482 b
->source_file
= NULL
;
4484 b
->source_file
= savestring (sal
.symtab
->filename
,
4485 strlen (sal
.symtab
->filename
));
4486 b
->loc
->section
= sal
.section
;
4487 b
->line_number
= sal
.line
;
4489 set_breakpoint_location_function (b
->loc
);
4491 breakpoints_changed ();
4497 /* Note that the breakpoint object B describes a permanent breakpoint
4498 instruction, hard-wired into the inferior's code. */
4500 make_breakpoint_permanent (struct breakpoint
*b
)
4502 struct bp_location
*bl
;
4503 b
->enable_state
= bp_permanent
;
4505 /* By definition, permanent breakpoints are already present in the code.
4506 Mark all locations as inserted. For now, make_breakpoint_permanent
4507 is called in just one place, so it's hard to say if it's reasonable
4508 to have permanent breakpoint with multiple locations or not,
4509 but it's easy to implmement. */
4510 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4514 static struct breakpoint
*
4515 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4517 static int internal_breakpoint_number
= -1;
4518 struct symtab_and_line sal
;
4519 struct breakpoint
*b
;
4521 init_sal (&sal
); /* initialize to zeroes */
4524 sal
.section
= find_pc_overlay (sal
.pc
);
4526 b
= set_raw_breakpoint (sal
, type
);
4527 b
->number
= internal_breakpoint_number
--;
4528 b
->disposition
= disp_donttouch
;
4535 create_longjmp_breakpoint (char *func_name
)
4537 struct minimal_symbol
*m
;
4539 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4541 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4542 update_global_location_list (1);
4545 /* Call this routine when stepping and nexting to enable a breakpoint
4546 if we do a longjmp(). When we hit that breakpoint, call
4547 set_longjmp_resume_breakpoint() to figure out where we are going. */
4550 set_longjmp_breakpoint (void)
4552 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4554 create_longjmp_breakpoint ("longjmp");
4555 create_longjmp_breakpoint ("_longjmp");
4556 create_longjmp_breakpoint ("siglongjmp");
4557 create_longjmp_breakpoint ("_siglongjmp");
4561 /* Delete all longjmp breakpoints from THREAD. */
4563 delete_longjmp_breakpoint (int thread
)
4565 struct breakpoint
*b
, *temp
;
4567 ALL_BREAKPOINTS_SAFE (b
, temp
)
4568 if (b
->type
== bp_longjmp
)
4570 if (b
->thread
== thread
)
4571 delete_breakpoint (b
);
4576 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4578 struct breakpoint
*b
;
4579 struct minimal_symbol
*m
;
4581 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4584 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4586 b
->addr_string
= xstrdup (func_name
);
4588 if (overlay_debugging
== ovly_auto
)
4590 b
->enable_state
= bp_enabled
;
4591 overlay_events_enabled
= 1;
4595 b
->enable_state
= bp_disabled
;
4596 overlay_events_enabled
= 0;
4598 update_global_location_list (1);
4602 create_overlay_event_breakpoint (char *func_name
)
4604 struct objfile
*objfile
;
4605 ALL_OBJFILES (objfile
)
4606 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4610 enable_overlay_breakpoints (void)
4612 struct breakpoint
*b
;
4615 if (b
->type
== bp_overlay_event
)
4617 b
->enable_state
= bp_enabled
;
4618 update_global_location_list (1);
4619 overlay_events_enabled
= 1;
4624 disable_overlay_breakpoints (void)
4626 struct breakpoint
*b
;
4629 if (b
->type
== bp_overlay_event
)
4631 b
->enable_state
= bp_disabled
;
4632 update_global_location_list (0);
4633 overlay_events_enabled
= 0;
4638 create_thread_event_breakpoint (CORE_ADDR address
)
4640 struct breakpoint
*b
;
4642 b
= create_internal_breakpoint (address
, bp_thread_event
);
4644 b
->enable_state
= bp_enabled
;
4645 /* addr_string has to be used or breakpoint_re_set will delete me. */
4646 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4648 update_global_location_list_nothrow (1);
4654 remove_thread_event_breakpoints (void)
4656 struct breakpoint
*b
, *temp
;
4658 ALL_BREAKPOINTS_SAFE (b
, temp
)
4659 if (b
->type
== bp_thread_event
)
4660 delete_breakpoint (b
);
4663 struct captured_parse_breakpoint_args
4666 struct symtabs_and_lines
*sals_p
;
4667 char ***addr_string_p
;
4671 struct lang_and_radix
4679 remove_solib_event_breakpoints (void)
4681 struct breakpoint
*b
, *temp
;
4683 ALL_BREAKPOINTS_SAFE (b
, temp
)
4684 if (b
->type
== bp_shlib_event
)
4685 delete_breakpoint (b
);
4689 create_solib_event_breakpoint (CORE_ADDR address
)
4691 struct breakpoint
*b
;
4693 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4694 update_global_location_list_nothrow (1);
4698 /* Disable any breakpoints that are on code in shared libraries. Only
4699 apply to enabled breakpoints, disabled ones can just stay disabled. */
4702 disable_breakpoints_in_shlibs (void)
4704 struct bp_location
*loc
;
4705 int disabled_shlib_breaks
= 0;
4707 ALL_BP_LOCATIONS (loc
)
4709 struct breakpoint
*b
= loc
->owner
;
4710 /* We apply the check to all breakpoints, including disabled
4711 for those with loc->duplicate set. This is so that when breakpoint
4712 becomes enabled, or the duplicate is removed, gdb will try to insert
4713 all breakpoints. If we don't set shlib_disabled here, we'll try
4714 to insert those breakpoints and fail. */
4715 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4716 && !loc
->shlib_disabled
4718 && PC_SOLIB (loc
->address
)
4720 && solib_address (loc
->address
)
4724 loc
->shlib_disabled
= 1;
4729 /* Disable any breakpoints that are in in an unloaded shared library. Only
4730 apply to enabled breakpoints, disabled ones can just stay disabled. */
4733 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4735 struct bp_location
*loc
;
4736 int disabled_shlib_breaks
= 0;
4738 ALL_BP_LOCATIONS (loc
)
4740 struct breakpoint
*b
= loc
->owner
;
4741 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4742 || loc
->loc_type
== bp_loc_software_breakpoint
)
4743 && !loc
->shlib_disabled
)
4746 char *so_name
= PC_SOLIB (loc
->address
);
4748 char *so_name
= solib_address (loc
->address
);
4750 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4752 loc
->shlib_disabled
= 1;
4753 /* At this point, we cannot rely on remove_breakpoint
4754 succeeding so we must mark the breakpoint as not inserted
4755 to prevent future errors occurring in remove_breakpoints. */
4757 if (!disabled_shlib_breaks
)
4759 target_terminal_ours_for_output ();
4760 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4763 disabled_shlib_breaks
= 1;
4770 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4771 enum bptype bp_kind
)
4773 struct symtab_and_line sal
;
4774 struct breakpoint
*b
;
4775 int thread
= -1; /* All threads. */
4782 b
= set_raw_breakpoint (sal
, bp_kind
);
4783 set_breakpoint_count (breakpoint_count
+ 1);
4784 b
->number
= breakpoint_count
;
4785 b
->cond_string
= (cond_string
== NULL
) ?
4786 NULL
: savestring (cond_string
, strlen (cond_string
));
4788 b
->addr_string
= NULL
;
4789 b
->enable_state
= bp_enabled
;
4790 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4791 b
->forked_inferior_pid
= null_ptid
;
4792 update_global_location_list (1);
4799 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4801 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4805 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4807 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4811 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4813 struct symtab_and_line sal
;
4814 struct breakpoint
*b
;
4815 int thread
= -1; /* All threads. */
4822 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4823 set_breakpoint_count (breakpoint_count
+ 1);
4824 b
->number
= breakpoint_count
;
4825 b
->cond_string
= (cond_string
== NULL
) ?
4826 NULL
: savestring (cond_string
, strlen (cond_string
));
4828 b
->addr_string
= NULL
;
4829 b
->enable_state
= bp_enabled
;
4830 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4831 update_global_location_list (1);
4837 hw_breakpoint_used_count (void)
4839 struct breakpoint
*b
;
4844 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4852 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4854 struct breakpoint
*b
;
4857 *other_type_used
= 0;
4860 if (breakpoint_enabled (b
))
4862 if (b
->type
== type
)
4864 else if ((b
->type
== bp_hardware_watchpoint
||
4865 b
->type
== bp_read_watchpoint
||
4866 b
->type
== bp_access_watchpoint
))
4867 *other_type_used
= 1;
4874 disable_watchpoints_before_interactive_call_start (void)
4876 struct breakpoint
*b
;
4880 if (((b
->type
== bp_watchpoint
)
4881 || (b
->type
== bp_hardware_watchpoint
)
4882 || (b
->type
== bp_read_watchpoint
)
4883 || (b
->type
== bp_access_watchpoint
))
4884 && breakpoint_enabled (b
))
4886 b
->enable_state
= bp_call_disabled
;
4887 update_global_location_list (0);
4893 enable_watchpoints_after_interactive_call_stop (void)
4895 struct breakpoint
*b
;
4899 if (((b
->type
== bp_watchpoint
)
4900 || (b
->type
== bp_hardware_watchpoint
)
4901 || (b
->type
== bp_read_watchpoint
)
4902 || (b
->type
== bp_access_watchpoint
))
4903 && (b
->enable_state
== bp_call_disabled
))
4905 b
->enable_state
= bp_enabled
;
4906 update_global_location_list (1);
4912 /* Set a breakpoint that will evaporate an end of command
4913 at address specified by SAL.
4914 Restrict it to frame FRAME if FRAME is nonzero. */
4917 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4920 struct breakpoint
*b
;
4921 b
= set_raw_breakpoint (sal
, type
);
4922 b
->enable_state
= bp_enabled
;
4923 b
->disposition
= disp_donttouch
;
4924 b
->frame_id
= frame_id
;
4926 /* If we're debugging a multi-threaded program, then we
4927 want momentary breakpoints to be active in only a
4928 single thread of control. */
4929 if (in_thread_list (inferior_ptid
))
4930 b
->thread
= pid_to_thread_id (inferior_ptid
);
4932 update_global_location_list_nothrow (1);
4938 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4940 struct symtab_and_line sal
;
4942 sal
= find_pc_line (pc
, 0);
4944 sal
.section
= find_pc_overlay (pc
);
4945 sal
.explicit_pc
= 1;
4947 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4951 /* Tell the user we have just set a breakpoint B. */
4954 mention (struct breakpoint
*b
)
4957 struct cleanup
*old_chain
, *ui_out_chain
;
4958 struct ui_stream
*stb
;
4960 stb
= ui_out_stream_new (uiout
);
4961 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4963 /* FIXME: This is misplaced; mention() is called by things (like
4964 hitting a watchpoint) other than breakpoint creation. It should
4965 be possible to clean this up and at the same time replace the
4966 random calls to breakpoint_changed with this hook. */
4967 observer_notify_breakpoint_created (b
->number
);
4969 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4970 b
->ops
->print_mention (b
);
4975 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4978 ui_out_text (uiout
, "Watchpoint ");
4979 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4980 ui_out_field_int (uiout
, "number", b
->number
);
4981 ui_out_text (uiout
, ": ");
4982 print_expression (b
->exp
, stb
->stream
);
4983 ui_out_field_stream (uiout
, "exp", stb
);
4984 do_cleanups (ui_out_chain
);
4986 case bp_hardware_watchpoint
:
4987 ui_out_text (uiout
, "Hardware watchpoint ");
4988 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4989 ui_out_field_int (uiout
, "number", b
->number
);
4990 ui_out_text (uiout
, ": ");
4991 print_expression (b
->exp
, stb
->stream
);
4992 ui_out_field_stream (uiout
, "exp", stb
);
4993 do_cleanups (ui_out_chain
);
4995 case bp_read_watchpoint
:
4996 ui_out_text (uiout
, "Hardware read watchpoint ");
4997 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4998 ui_out_field_int (uiout
, "number", b
->number
);
4999 ui_out_text (uiout
, ": ");
5000 print_expression (b
->exp
, stb
->stream
);
5001 ui_out_field_stream (uiout
, "exp", stb
);
5002 do_cleanups (ui_out_chain
);
5004 case bp_access_watchpoint
:
5005 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5006 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5007 ui_out_field_int (uiout
, "number", b
->number
);
5008 ui_out_text (uiout
, ": ");
5009 print_expression (b
->exp
, stb
->stream
);
5010 ui_out_field_stream (uiout
, "exp", stb
);
5011 do_cleanups (ui_out_chain
);
5014 if (ui_out_is_mi_like_p (uiout
))
5019 if (b
->disposition
== disp_del
)
5020 printf_filtered (_("Temporary breakpoint"));
5022 printf_filtered (_("Breakpoint"));
5023 printf_filtered (_(" %d"), b
->number
);
5026 case bp_hardware_breakpoint
:
5027 if (ui_out_is_mi_like_p (uiout
))
5032 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5036 case bp_catch_unload
:
5037 printf_filtered (_("Catchpoint %d (%s %s)"),
5039 (b
->type
== bp_catch_load
) ? "load" : "unload",
5040 (b
->dll_pathname
!= NULL
) ?
5041 b
->dll_pathname
: "<any library>");
5044 case bp_catch_vfork
:
5045 printf_filtered (_("Catchpoint %d (%s)"),
5047 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
5050 printf_filtered (_("Catchpoint %d (exec)"),
5057 case bp_longjmp_resume
:
5058 case bp_step_resume
:
5060 case bp_watchpoint_scope
:
5061 case bp_shlib_event
:
5062 case bp_thread_event
:
5063 case bp_overlay_event
:
5069 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5073 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5077 if (addressprint
|| b
->source_file
== NULL
)
5079 printf_filtered (" at ");
5080 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5083 printf_filtered (": file %s, line %d.",
5084 b
->source_file
, b
->line_number
);
5088 struct bp_location
*loc
= b
->loc
;
5090 for (; loc
; loc
= loc
->next
)
5092 printf_filtered (" (%d locations)", n
);
5097 do_cleanups (old_chain
);
5098 if (ui_out_is_mi_like_p (uiout
))
5100 printf_filtered ("\n");
5104 static struct bp_location
*
5105 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5106 const struct symtab_and_line
*sal
)
5108 struct bp_location
*loc
, **tmp
;
5110 loc
= allocate_bp_location (b
, bptype
);
5111 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5114 loc
->requested_address
= sal
->pc
;
5115 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5117 loc
->section
= sal
->section
;
5119 set_breakpoint_location_function (loc
);
5124 /* Return 1 if LOC is pointing to a permanent breakpoint,
5125 return 0 otherwise. */
5128 bp_loc_is_permanent (struct bp_location
*loc
)
5132 const gdb_byte
*brk
;
5133 gdb_byte
*target_mem
;
5135 gdb_assert (loc
!= NULL
);
5137 addr
= loc
->address
;
5138 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5140 target_mem
= alloca (len
);
5142 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5143 && memcmp (target_mem
, brk
, len
) == 0)
5151 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5152 as textual description of the location, and COND_STRING
5153 as condition expression. */
5156 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5158 enum bptype type
, enum bpdisp disposition
,
5159 int thread
, int ignore_count
,
5160 struct breakpoint_ops
*ops
, int from_tty
)
5162 struct breakpoint
*b
= NULL
;
5165 if (type
== bp_hardware_breakpoint
)
5167 int i
= hw_breakpoint_used_count ();
5168 int target_resources_ok
=
5169 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5171 if (target_resources_ok
== 0)
5172 error (_("No hardware breakpoint support in the target."));
5173 else if (target_resources_ok
< 0)
5174 error (_("Hardware breakpoints used exceeds limit."));
5177 for (i
= 0; i
< sals
.nelts
; ++i
)
5179 struct symtab_and_line sal
= sals
.sals
[i
];
5180 struct bp_location
*loc
;
5183 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5187 b
= set_raw_breakpoint (sal
, type
);
5188 set_breakpoint_count (breakpoint_count
+ 1);
5189 b
->number
= breakpoint_count
;
5192 b
->cond_string
= cond_string
;
5193 b
->ignore_count
= ignore_count
;
5194 b
->enable_state
= bp_enabled
;
5195 b
->disposition
= disposition
;
5201 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5204 if (bp_loc_is_permanent (loc
))
5205 make_breakpoint_permanent (b
);
5209 char *arg
= b
->cond_string
;
5210 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5212 error (_("Garbage %s follows condition"), arg
);
5217 b
->addr_string
= addr_string
;
5219 /* addr_string has to be used or breakpoint_re_set will delete
5221 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5227 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5228 elements to fill the void space. */
5229 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5231 int i
= index_to_remove
+1;
5232 int last_index
= sal
->nelts
-1;
5234 for (;i
<= last_index
; ++i
)
5235 sal
->sals
[i
-1] = sal
->sals
[i
];
5240 /* If appropriate, obtains all sals that correspond
5241 to the same file and line as SAL. This is done
5242 only if SAL does not have explicit PC and has
5243 line and file information. If we got just a single
5244 expanded sal, return the original.
5246 Otherwise, if SAL.explicit_line is not set, filter out
5247 all sals for which the name of enclosing function
5248 is different from SAL. This makes sure that if we have
5249 breakpoint originally set in template instantiation, say
5250 foo<int>(), we won't expand SAL to locations at the same
5251 line in all existing instantiations of 'foo'.
5254 struct symtabs_and_lines
5255 expand_line_sal_maybe (struct symtab_and_line sal
)
5257 struct symtabs_and_lines expanded
;
5258 CORE_ADDR original_pc
= sal
.pc
;
5259 char *original_function
= NULL
;
5263 /* If we have explicit pc, don't expand.
5264 If we have no line number, we can't expand. */
5265 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5268 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5269 expanded
.sals
[0] = sal
;
5274 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5276 expanded
= expand_line_sal (sal
);
5277 if (expanded
.nelts
== 1)
5279 /* We had one sal, we got one sal. Without futher
5280 processing, just return the original sal. */
5281 xfree (expanded
.sals
);
5283 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5284 sal
.pc
= original_pc
;
5285 expanded
.sals
[0] = sal
;
5289 if (!sal
.explicit_line
)
5291 CORE_ADDR func_addr
, func_end
;
5292 for (i
= 0; i
< expanded
.nelts
; ++i
)
5294 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5295 char *this_function
;
5296 if (find_pc_partial_function (pc
, &this_function
,
5297 &func_addr
, &func_end
))
5299 if (this_function
&&
5300 strcmp (this_function
, original_function
) != 0)
5302 remove_sal (&expanded
, i
);
5305 else if (func_addr
== pc
)
5307 /* We're at beginning of a function, and should
5309 struct symbol
*sym
= find_pc_function (pc
);
5311 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5314 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5321 if (expanded
.nelts
<= 1)
5323 /* This is un ugly workaround. If we get zero
5324 expanded sals then something is really wrong.
5325 Fix that by returnign the original sal. */
5326 xfree (expanded
.sals
);
5328 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5329 sal
.pc
= original_pc
;
5330 expanded
.sals
[0] = sal
;
5337 for (i
= 0; i
< expanded
.nelts
; ++i
)
5338 if (expanded
.sals
[i
].pc
== original_pc
)
5349 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5350 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5351 value. COND_STRING, if not NULL, specified the condition to be
5352 used for all breakpoints. Essentially the only case where
5353 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5354 function. In that case, it's still not possible to specify
5355 separate conditions for different overloaded functions, so
5356 we take just a single condition string.
5358 NOTE: If the function succeeds, the caller is expected to cleanup
5359 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5360 array contents). If the function fails (error() is called), the
5361 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5362 COND and SALS arrays and each of those arrays contents. */
5365 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5367 enum bptype type
, enum bpdisp disposition
,
5368 int thread
, int ignore_count
,
5369 struct breakpoint_ops
*ops
, int from_tty
)
5372 for (i
= 0; i
< sals
.nelts
; ++i
)
5374 struct symtabs_and_lines expanded
=
5375 expand_line_sal_maybe (sals
.sals
[i
]);
5377 create_breakpoint (expanded
, addr_string
[i
],
5378 cond_string
, type
, disposition
,
5379 thread
, ignore_count
, ops
, from_tty
);
5382 update_global_location_list (1);
5385 /* Parse ARG which is assumed to be a SAL specification possibly
5386 followed by conditionals. On return, SALS contains an array of SAL
5387 addresses found. ADDR_STRING contains a vector of (canonical)
5388 address strings. ARG points to the end of the SAL. */
5391 parse_breakpoint_sals (char **address
,
5392 struct symtabs_and_lines
*sals
,
5393 char ***addr_string
,
5396 char *addr_start
= *address
;
5397 *addr_string
= NULL
;
5398 /* If no arg given, or if first arg is 'if ', use the default
5400 if ((*address
) == NULL
5401 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5403 if (default_breakpoint_valid
)
5405 struct symtab_and_line sal
;
5406 init_sal (&sal
); /* initialize to zeroes */
5407 sals
->sals
= (struct symtab_and_line
*)
5408 xmalloc (sizeof (struct symtab_and_line
));
5409 sal
.pc
= default_breakpoint_address
;
5410 sal
.line
= default_breakpoint_line
;
5411 sal
.symtab
= default_breakpoint_symtab
;
5412 sal
.section
= find_pc_overlay (sal
.pc
);
5413 sals
->sals
[0] = sal
;
5417 error (_("No default breakpoint address now."));
5421 /* Force almost all breakpoints to be in terms of the
5422 current_source_symtab (which is decode_line_1's default). This
5423 should produce the results we want almost all of the time while
5424 leaving default_breakpoint_* alone.
5425 ObjC: However, don't match an Objective-C method name which
5426 may have a '+' or '-' succeeded by a '[' */
5428 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5430 if (default_breakpoint_valid
5432 || ((strchr ("+-", (*address
)[0]) != NULL
)
5433 && ((*address
)[1] != '['))))
5434 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5435 default_breakpoint_line
, addr_string
,
5438 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5439 addr_string
, not_found_ptr
);
5441 /* For any SAL that didn't have a canonical string, fill one in. */
5442 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5443 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5444 if (addr_start
!= (*address
))
5447 for (i
= 0; i
< sals
->nelts
; i
++)
5449 /* Add the string if not present. */
5450 if ((*addr_string
)[i
] == NULL
)
5451 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5457 /* Convert each SAL into a real PC. Verify that the PC can be
5458 inserted as a breakpoint. If it can't throw an error. */
5461 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5465 for (i
= 0; i
< sals
->nelts
; i
++)
5466 resolve_sal_pc (&sals
->sals
[i
]);
5470 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5472 struct captured_parse_breakpoint_args
*args
= data
;
5474 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5475 args
->not_found_ptr
);
5478 /* Given TOK, a string specification of condition and thread, as
5479 accepted by the 'break' command, extract the condition
5480 string and thread number and set *COND_STRING and *THREAD.
5481 PC identifies the context at which the condition should be parsed.
5482 If no condition is found, *COND_STRING is set to NULL.
5483 If no thread is found, *THREAD is set to -1. */
5485 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5486 char **cond_string
, int *thread
)
5488 *cond_string
= NULL
;
5494 char *cond_start
= NULL
;
5495 char *cond_end
= NULL
;
5496 while (*tok
== ' ' || *tok
== '\t')
5501 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5504 toklen
= end_tok
- tok
;
5506 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5508 tok
= cond_start
= end_tok
+ 1;
5509 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5511 *cond_string
= savestring (cond_start
,
5512 cond_end
- cond_start
);
5514 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5520 *thread
= strtol (tok
, &tok
, 0);
5522 error (_("Junk after thread keyword."));
5523 if (!valid_thread_id (*thread
))
5524 error (_("Unknown thread %d."), *thread
);
5527 error (_("Junk at end of arguments."));
5531 /* Set a breakpoint. This function is shared between
5532 CLI and MI functions for setting a breakpoint.
5533 This function has two major modes of operations,
5534 selected by the PARSE_CONDITION_AND_THREAD parameter.
5535 If non-zero, the function will parse arg, extracting
5536 breakpoint location, address and thread. Otherwise,
5537 ARG is just the location of breakpoint, with condition
5538 and thread specified by the COND_STRING and THREAD
5542 break_command_really (char *arg
, char *cond_string
, int thread
,
5543 int parse_condition_and_thread
,
5544 int tempflag
, int hardwareflag
,
5546 enum auto_boolean pending_break_support
,
5547 struct breakpoint_ops
*ops
,
5550 struct gdb_exception e
;
5551 struct symtabs_and_lines sals
;
5552 struct symtab_and_line pending_sal
;
5555 char *addr_start
= arg
;
5557 struct cleanup
*old_chain
;
5558 struct cleanup
*breakpoint_chain
= NULL
;
5559 struct captured_parse_breakpoint_args parse_args
;
5568 parse_args
.arg_p
= &arg
;
5569 parse_args
.sals_p
= &sals
;
5570 parse_args
.addr_string_p
= &addr_string
;
5571 parse_args
.not_found_ptr
= ¬_found
;
5573 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5574 &parse_args
, RETURN_MASK_ALL
);
5576 /* If caller is interested in rc value from parse, set value. */
5580 throw_exception (e
);
5584 case NOT_FOUND_ERROR
:
5586 /* If pending breakpoint support is turned off, throw
5589 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5590 throw_exception (e
);
5592 exception_print (gdb_stderr
, e
);
5594 /* If pending breakpoint support is auto query and the user
5595 selects no, then simply return the error code. */
5596 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5597 !nquery ("Make breakpoint pending on future shared library load? "))
5600 /* At this point, either the user was queried about setting
5601 a pending breakpoint and selected yes, or pending
5602 breakpoint behavior is on and thus a pending breakpoint
5603 is defaulted on behalf of the user. */
5604 copy_arg
= xstrdup (addr_start
);
5605 addr_string
= ©_arg
;
5607 sals
.sals
= &pending_sal
;
5612 throw_exception (e
);
5619 /* Create a chain of things that always need to be cleaned up. */
5620 old_chain
= make_cleanup (null_cleanup
, 0);
5624 /* Make sure that all storage allocated to SALS gets freed. */
5625 make_cleanup (xfree
, sals
.sals
);
5627 /* Cleanup the addr_string array but not its contents. */
5628 make_cleanup (xfree
, addr_string
);
5631 /* ----------------------------- SNIP -----------------------------
5632 Anything added to the cleanup chain beyond this point is assumed
5633 to be part of a breakpoint. If the breakpoint create succeeds
5634 then the memory is not reclaimed. */
5635 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5637 /* Mark the contents of the addr_string for cleanup. These go on
5638 the breakpoint_chain and only occure if the breakpoint create
5640 for (i
= 0; i
< sals
.nelts
; i
++)
5642 if (addr_string
[i
] != NULL
)
5643 make_cleanup (xfree
, addr_string
[i
]);
5646 /* Resolve all line numbers to PC's and verify that the addresses
5647 are ok for the target. */
5649 breakpoint_sals_to_pc (&sals
, addr_start
);
5651 /* Verify that condition can be parsed, before setting any
5652 breakpoints. Allocate a separate condition expression for each
5656 if (parse_condition_and_thread
)
5658 /* Here we only parse 'arg' to separate condition
5659 from thread number, so parsing in context of first
5660 sal is OK. When setting the breakpoint we'll
5661 re-parse it in context of each sal. */
5664 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5666 make_cleanup (xfree
, cond_string
);
5670 /* Create a private copy of condition string. */
5673 cond_string
= xstrdup (cond_string
);
5674 make_cleanup (xfree
, cond_string
);
5677 create_breakpoints (sals
, addr_string
, cond_string
,
5678 hardwareflag
? bp_hardware_breakpoint
5680 tempflag
? disp_del
: disp_donttouch
,
5681 thread
, ignore_count
, ops
, from_tty
);
5685 struct symtab_and_line sal
= {0};
5686 struct breakpoint
*b
;
5688 make_cleanup (xfree
, copy_arg
);
5690 b
= set_raw_breakpoint_without_location (hardwareflag
5691 ? bp_hardware_breakpoint
5693 set_breakpoint_count (breakpoint_count
+ 1);
5694 b
->number
= breakpoint_count
;
5696 b
->addr_string
= addr_string
[0];
5697 b
->cond_string
= NULL
;
5698 b
->ignore_count
= ignore_count
;
5699 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5700 b
->condition_not_parsed
= 1;
5703 update_global_location_list (1);
5708 warning (_("Multiple breakpoints were set.\n"
5709 "Use the \"delete\" command to delete unwanted breakpoints."));
5710 /* That's it. Discard the cleanups for data inserted into the
5712 discard_cleanups (breakpoint_chain
);
5713 /* But cleanup everything else. */
5714 do_cleanups (old_chain
);
5717 /* Set a breakpoint.
5718 ARG is a string describing breakpoint address,
5719 condition, and thread.
5720 FLAG specifies if a breakpoint is hardware on,
5721 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5725 break_command_1 (char *arg
, int flag
, int from_tty
)
5727 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5728 int tempflag
= flag
& BP_TEMPFLAG
;
5730 break_command_really (arg
,
5731 NULL
, 0, 1 /* parse arg */,
5732 tempflag
, hardwareflag
,
5733 0 /* Ignore count */,
5734 pending_break_support
,
5735 NULL
/* breakpoint_ops */,
5741 set_breakpoint (char *address
, char *condition
,
5742 int hardwareflag
, int tempflag
,
5743 int thread
, int ignore_count
,
5746 break_command_really (address
, condition
, thread
,
5747 0 /* condition and thread are valid. */,
5748 tempflag
, hardwareflag
,
5751 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5755 /* Adjust SAL to the first instruction past the function prologue.
5756 The end of the prologue is determined using the line table from
5757 the debugging information.
5759 If SAL is already past the prologue, then do nothing. */
5762 skip_prologue_sal (struct symtab_and_line
*sal
)
5764 struct symbol
*sym
= find_pc_function (sal
->pc
);
5765 struct symtab_and_line start_sal
;
5770 start_sal
= find_function_start_sal (sym
, 1);
5771 if (sal
->pc
< start_sal
.pc
)
5775 /* Helper function for break_command_1 and disassemble_command. */
5778 resolve_sal_pc (struct symtab_and_line
*sal
)
5782 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5784 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5785 error (_("No line %d in file \"%s\"."),
5786 sal
->line
, sal
->symtab
->filename
);
5789 /* If this SAL corresponds to a breakpoint inserted using
5790 a line number, then skip the function prologue if necessary. */
5791 if (sal
->explicit_line
)
5792 skip_prologue_sal (sal
);
5795 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5797 struct blockvector
*bv
;
5801 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5804 sym
= block_linkage_function (b
);
5807 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5808 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5812 /* It really is worthwhile to have the section, so we'll just
5813 have to look harder. This case can be executed if we have
5814 line numbers but no functions (as can happen in assembly
5817 struct minimal_symbol
*msym
;
5819 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5821 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5828 break_command (char *arg
, int from_tty
)
5830 break_command_1 (arg
, 0, from_tty
);
5834 tbreak_command (char *arg
, int from_tty
)
5836 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5840 hbreak_command (char *arg
, int from_tty
)
5842 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5846 thbreak_command (char *arg
, int from_tty
)
5848 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5852 stop_command (char *arg
, int from_tty
)
5854 printf_filtered (_("Specify the type of breakpoint to set.\n\
5855 Usage: stop in <function | address>\n\
5856 stop at <line>\n"));
5860 stopin_command (char *arg
, int from_tty
)
5864 if (arg
== (char *) NULL
)
5866 else if (*arg
!= '*')
5871 /* look for a ':'. If this is a line number specification, then
5872 say it is bad, otherwise, it should be an address or
5873 function/method name */
5874 while (*argptr
&& !hasColon
)
5876 hasColon
= (*argptr
== ':');
5881 badInput
= (*argptr
!= ':'); /* Not a class::method */
5883 badInput
= isdigit (*arg
); /* a simple line number */
5887 printf_filtered (_("Usage: stop in <function | address>\n"));
5889 break_command_1 (arg
, 0, from_tty
);
5893 stopat_command (char *arg
, int from_tty
)
5897 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5904 /* look for a ':'. If there is a '::' then get out, otherwise
5905 it is probably a line number. */
5906 while (*argptr
&& !hasColon
)
5908 hasColon
= (*argptr
== ':');
5913 badInput
= (*argptr
== ':'); /* we have class::method */
5915 badInput
= !isdigit (*arg
); /* not a line number */
5919 printf_filtered (_("Usage: stop at <line>\n"));
5921 break_command_1 (arg
, 0, from_tty
);
5924 /* accessflag: hw_write: watch write,
5925 hw_read: watch read,
5926 hw_access: watch access (read or write) */
5928 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5930 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5931 struct symtab_and_line sal
;
5932 struct expression
*exp
;
5933 struct block
*exp_valid_block
;
5934 struct value
*val
, *mark
;
5935 struct frame_info
*frame
;
5936 struct frame_info
*prev_frame
= NULL
;
5937 char *exp_start
= NULL
;
5938 char *exp_end
= NULL
;
5939 char *tok
, *id_tok_start
, *end_tok
;
5941 char *cond_start
= NULL
;
5942 char *cond_end
= NULL
;
5943 struct expression
*cond
= NULL
;
5944 int i
, other_type_used
, target_resources_ok
= 0;
5945 enum bptype bp_type
;
5949 init_sal (&sal
); /* initialize to zeroes */
5951 /* Make sure that we actually have parameters to parse. */
5952 if (arg
!= NULL
&& arg
[0] != '\0')
5954 toklen
= strlen (arg
); /* Size of argument list. */
5956 /* Points tok to the end of the argument list. */
5957 tok
= arg
+ toklen
- 1;
5959 /* Go backwards in the parameters list. Skip the last parameter.
5960 If we're expecting a 'thread <thread_num>' parameter, this should
5961 be the thread identifier. */
5962 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5964 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5967 /* Points end_tok to the beginning of the last token. */
5968 id_tok_start
= tok
+ 1;
5970 /* Go backwards in the parameters list. Skip one more parameter.
5971 If we're expecting a 'thread <thread_num>' parameter, we should
5972 reach a "thread" token. */
5973 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5978 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5981 /* Move the pointer forward to skip the whitespace and
5982 calculate the length of the token. */
5984 toklen
= end_tok
- tok
;
5986 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5988 /* At this point we've found a "thread" token, which means
5989 the user is trying to set a watchpoint that triggers
5990 only in a specific thread. */
5993 /* Extract the thread ID from the next token. */
5994 thread
= strtol (id_tok_start
, &endp
, 0);
5996 /* Check if the user provided a valid numeric value for the
5998 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5999 error (_("Invalid thread ID specification %s."), id_tok_start
);
6001 /* Check if the thread actually exists. */
6002 if (!valid_thread_id (thread
))
6003 error (_("Unknown thread %d."), thread
);
6005 /* Truncate the string and get rid of the thread <thread_num>
6006 parameter before the parameter list is parsed by the
6007 evaluate_expression() function. */
6012 /* Parse the rest of the arguments. */
6013 innermost_block
= NULL
;
6015 exp
= parse_exp_1 (&arg
, 0, 0);
6017 exp_valid_block
= innermost_block
;
6018 mark
= value_mark ();
6019 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6021 release_value (val
);
6024 while (*tok
== ' ' || *tok
== '\t')
6028 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6031 toklen
= end_tok
- tok
;
6032 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6034 tok
= cond_start
= end_tok
+ 1;
6035 cond
= parse_exp_1 (&tok
, 0, 0);
6039 error (_("Junk at end of command."));
6041 if (accessflag
== hw_read
)
6042 bp_type
= bp_read_watchpoint
;
6043 else if (accessflag
== hw_access
)
6044 bp_type
= bp_access_watchpoint
;
6046 bp_type
= bp_hardware_watchpoint
;
6048 mem_cnt
= can_use_hardware_watchpoint (val
);
6049 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6050 error (_("Expression cannot be implemented with read/access watchpoint."));
6053 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6054 target_resources_ok
=
6055 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6057 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6058 error (_("Target does not support this type of hardware watchpoint."));
6060 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6061 error (_("Target can only support one kind of HW watchpoint at a time."));
6064 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6065 watchpoint could not be set. */
6066 if (!mem_cnt
|| target_resources_ok
<= 0)
6067 bp_type
= bp_watchpoint
;
6069 frame
= block_innermost_frame (exp_valid_block
);
6071 prev_frame
= get_prev_frame (frame
);
6075 /* If the expression is "local", then set up a "watchpoint scope"
6076 breakpoint at the point where we've left the scope of the watchpoint
6077 expression. Create the scope breakpoint before the watchpoint, so
6078 that we will encounter it first in bpstat_stop_status. */
6079 if (innermost_block
&& prev_frame
)
6081 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6082 bp_watchpoint_scope
);
6084 scope_breakpoint
->enable_state
= bp_enabled
;
6086 /* Automatically delete the breakpoint when it hits. */
6087 scope_breakpoint
->disposition
= disp_del
;
6089 /* Only break in the proper frame (help with recursion). */
6090 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6092 /* Set the address at which we will stop. */
6093 scope_breakpoint
->loc
->requested_address
6094 = get_frame_pc (prev_frame
);
6095 scope_breakpoint
->loc
->address
6096 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6097 scope_breakpoint
->type
);
6100 /* Now set up the breakpoint. */
6101 b
= set_raw_breakpoint (sal
, bp_type
);
6102 set_breakpoint_count (breakpoint_count
+ 1);
6103 b
->number
= breakpoint_count
;
6105 b
->disposition
= disp_donttouch
;
6107 b
->exp_valid_block
= exp_valid_block
;
6108 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6111 b
->loc
->cond
= cond
;
6113 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6118 b
->watchpoint_frame
= get_frame_id (frame
);
6120 b
->watchpoint_frame
= null_frame_id
;
6122 if (scope_breakpoint
!= NULL
)
6124 /* The scope breakpoint is related to the watchpoint. We will
6125 need to act on them together. */
6126 b
->related_breakpoint
= scope_breakpoint
;
6127 scope_breakpoint
->related_breakpoint
= b
;
6130 value_free_to_mark (mark
);
6132 update_global_location_list (1);
6135 /* Return count of locations need to be watched and can be handled
6136 in hardware. If the watchpoint can not be handled
6137 in hardware return zero. */
6140 can_use_hardware_watchpoint (struct value
*v
)
6142 int found_memory_cnt
= 0;
6143 struct value
*head
= v
;
6145 /* Did the user specifically forbid us to use hardware watchpoints? */
6146 if (!can_use_hw_watchpoints
)
6149 /* Make sure that the value of the expression depends only upon
6150 memory contents, and values computed from them within GDB. If we
6151 find any register references or function calls, we can't use a
6152 hardware watchpoint.
6154 The idea here is that evaluating an expression generates a series
6155 of values, one holding the value of every subexpression. (The
6156 expression a*b+c has five subexpressions: a, b, a*b, c, and
6157 a*b+c.) GDB's values hold almost enough information to establish
6158 the criteria given above --- they identify memory lvalues,
6159 register lvalues, computed values, etcetera. So we can evaluate
6160 the expression, and then scan the chain of values that leaves
6161 behind to decide whether we can detect any possible change to the
6162 expression's final value using only hardware watchpoints.
6164 However, I don't think that the values returned by inferior
6165 function calls are special in any way. So this function may not
6166 notice that an expression involving an inferior function call
6167 can't be watched with hardware watchpoints. FIXME. */
6168 for (; v
; v
= value_next (v
))
6170 if (VALUE_LVAL (v
) == lval_memory
)
6173 /* A lazy memory lvalue is one that GDB never needed to fetch;
6174 we either just used its address (e.g., `a' in `a.b') or
6175 we never needed it at all (e.g., `a' in `a,b'). */
6179 /* Ahh, memory we actually used! Check if we can cover
6180 it with hardware watchpoints. */
6181 struct type
*vtype
= check_typedef (value_type (v
));
6183 /* We only watch structs and arrays if user asked for it
6184 explicitly, never if they just happen to appear in a
6185 middle of some value chain. */
6187 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6188 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6190 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6191 int len
= TYPE_LENGTH (value_type (v
));
6193 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6200 else if (VALUE_LVAL (v
) != not_lval
6201 && deprecated_value_modifiable (v
) == 0)
6202 return 0; /* ??? What does this represent? */
6203 else if (VALUE_LVAL (v
) == lval_register
)
6204 return 0; /* cannot watch a register with a HW watchpoint */
6207 /* The expression itself looks suitable for using a hardware
6208 watchpoint, but give the target machine a chance to reject it. */
6209 return found_memory_cnt
;
6213 watch_command_wrapper (char *arg
, int from_tty
)
6215 watch_command (arg
, from_tty
);
6219 watch_command (char *arg
, int from_tty
)
6221 watch_command_1 (arg
, hw_write
, from_tty
);
6225 rwatch_command_wrapper (char *arg
, int from_tty
)
6227 rwatch_command (arg
, from_tty
);
6231 rwatch_command (char *arg
, int from_tty
)
6233 watch_command_1 (arg
, hw_read
, from_tty
);
6237 awatch_command_wrapper (char *arg
, int from_tty
)
6239 awatch_command (arg
, from_tty
);
6243 awatch_command (char *arg
, int from_tty
)
6245 watch_command_1 (arg
, hw_access
, from_tty
);
6249 /* Helper routines for the until_command routine in infcmd.c. Here
6250 because it uses the mechanisms of breakpoints. */
6252 struct until_break_command_continuation_args
6254 struct breakpoint
*breakpoint
;
6255 struct breakpoint
*breakpoint2
;
6258 /* This function is called by fetch_inferior_event via the
6259 cmd_continuation pointer, to complete the until command. It takes
6260 care of cleaning up the temporary breakpoints set up by the until
6263 until_break_command_continuation (void *arg
)
6265 struct until_break_command_continuation_args
*a
= arg
;
6267 delete_breakpoint (a
->breakpoint
);
6269 delete_breakpoint (a
->breakpoint2
);
6273 until_break_command (char *arg
, int from_tty
, int anywhere
)
6275 struct symtabs_and_lines sals
;
6276 struct symtab_and_line sal
;
6277 struct frame_info
*frame
= get_selected_frame (NULL
);
6278 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6279 struct breakpoint
*breakpoint
;
6280 struct breakpoint
*breakpoint2
= NULL
;
6281 struct cleanup
*old_chain
;
6283 clear_proceed_status ();
6285 /* Set a breakpoint where the user wants it and at return from
6288 if (default_breakpoint_valid
)
6289 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6290 default_breakpoint_line
, (char ***) NULL
, NULL
);
6292 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6293 0, (char ***) NULL
, NULL
);
6295 if (sals
.nelts
!= 1)
6296 error (_("Couldn't get information on specified line."));
6299 xfree (sals
.sals
); /* malloc'd, so freed */
6302 error (_("Junk at end of arguments."));
6304 resolve_sal_pc (&sal
);
6307 /* If the user told us to continue until a specified location,
6308 we don't specify a frame at which we need to stop. */
6309 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6311 /* Otherwise, specify the current frame, because we want to stop only
6312 at the very same frame. */
6313 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6316 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6318 /* Keep within the current frame, or in frames called by the current
6322 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6323 sal
.pc
= get_frame_pc (prev_frame
);
6324 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6326 make_cleanup_delete_breakpoint (breakpoint2
);
6329 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6331 /* If we are running asynchronously, and proceed call above has actually
6332 managed to start the target, arrange for breakpoints to be
6333 deleted when the target stops. Otherwise, we're already stopped and
6334 delete breakpoints via cleanup chain. */
6336 if (target_can_async_p () && is_running (inferior_ptid
))
6338 struct until_break_command_continuation_args
*args
;
6339 args
= xmalloc (sizeof (*args
));
6341 args
->breakpoint
= breakpoint
;
6342 args
->breakpoint2
= breakpoint2
;
6344 discard_cleanups (old_chain
);
6345 add_continuation (inferior_thread (),
6346 until_break_command_continuation
, args
,
6350 do_cleanups (old_chain
);
6354 ep_skip_leading_whitespace (char **s
)
6356 if ((s
== NULL
) || (*s
== NULL
))
6358 while (isspace (**s
))
6362 /* This function attempts to parse an optional "if <cond>" clause
6363 from the arg string. If one is not found, it returns NULL.
6365 Else, it returns a pointer to the condition string. (It does not
6366 attempt to evaluate the string against a particular block.) And,
6367 it updates arg to point to the first character following the parsed
6368 if clause in the arg string. */
6371 ep_parse_optional_if_clause (char **arg
)
6375 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6378 /* Skip the "if" keyword. */
6381 /* Skip any extra leading whitespace, and record the start of the
6382 condition string. */
6383 ep_skip_leading_whitespace (arg
);
6386 /* Assume that the condition occupies the remainder of the arg string. */
6387 (*arg
) += strlen (cond_string
);
6392 /* This function attempts to parse an optional filename from the arg
6393 string. If one is not found, it returns NULL.
6395 Else, it returns a pointer to the parsed filename. (This function
6396 makes no attempt to verify that a file of that name exists, or is
6397 accessible.) And, it updates arg to point to the first character
6398 following the parsed filename in the arg string.
6400 Note that clients needing to preserve the returned filename for
6401 future access should copy it to their own buffers. */
6403 ep_parse_optional_filename (char **arg
)
6405 static char filename
[1024];
6410 if ((*arg_p
== '\0') || isspace (*arg_p
))
6428 /* Commands to deal with catching events, such as signals, exceptions,
6429 process start/exit, etc. */
6433 catch_fork_temporary
, catch_vfork_temporary
,
6434 catch_fork_permanent
, catch_vfork_permanent
6439 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6441 char *cond_string
= NULL
;
6442 catch_fork_kind fork_kind
;
6445 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6446 tempflag
= (fork_kind
== catch_fork_temporary
6447 || fork_kind
== catch_vfork_temporary
);
6451 ep_skip_leading_whitespace (&arg
);
6453 /* The allowed syntax is:
6455 catch [v]fork if <cond>
6457 First, check if there's an if clause. */
6458 cond_string
= ep_parse_optional_if_clause (&arg
);
6460 if ((*arg
!= '\0') && !isspace (*arg
))
6461 error (_("Junk at end of arguments."));
6463 /* If this target supports it, create a fork or vfork catchpoint
6464 and enable reporting of such events. */
6467 case catch_fork_temporary
:
6468 case catch_fork_permanent
:
6469 create_fork_event_catchpoint (tempflag
, cond_string
);
6471 case catch_vfork_temporary
:
6472 case catch_vfork_permanent
:
6473 create_vfork_event_catchpoint (tempflag
, cond_string
);
6476 error (_("unsupported or unknown fork kind; cannot catch it"));
6482 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6485 char *cond_string
= NULL
;
6487 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6491 ep_skip_leading_whitespace (&arg
);
6493 /* The allowed syntax is:
6495 catch exec if <cond>
6497 First, check if there's an if clause. */
6498 cond_string
= ep_parse_optional_if_clause (&arg
);
6500 if ((*arg
!= '\0') && !isspace (*arg
))
6501 error (_("Junk at end of arguments."));
6503 /* If this target supports it, create an exec catchpoint
6504 and enable reporting of such events. */
6505 create_exec_event_catchpoint (tempflag
, cond_string
);
6509 catch_load_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6512 char *dll_pathname
= NULL
;
6513 char *cond_string
= NULL
;
6515 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6519 ep_skip_leading_whitespace (&arg
);
6521 /* The allowed syntax is:
6523 catch load if <cond>
6524 catch load <filename>
6525 catch load <filename> if <cond>
6527 The user is not allowed to specify the <filename> after an
6530 We'll ignore the pathological case of a file named "if".
6532 First, check if there's an if clause. If so, then there
6533 cannot be a filename. */
6534 cond_string
= ep_parse_optional_if_clause (&arg
);
6536 /* If there was an if clause, then there cannot be a filename.
6537 Else, there might be a filename and an if clause. */
6538 if (cond_string
== NULL
)
6540 dll_pathname
= ep_parse_optional_filename (&arg
);
6541 ep_skip_leading_whitespace (&arg
);
6542 cond_string
= ep_parse_optional_if_clause (&arg
);
6545 if ((*arg
!= '\0') && !isspace (*arg
))
6546 error (_("Junk at end of arguments."));
6548 /* Create a load breakpoint that only triggers when a load of
6549 the specified dll (or any dll, if no pathname was specified)
6551 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6552 dll_pathname
, cond_string
);
6556 catch_unload_command_1 (char *arg
, int from_tty
,
6557 struct cmd_list_element
*command
)
6560 char *dll_pathname
= NULL
;
6561 char *cond_string
= NULL
;
6563 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6567 ep_skip_leading_whitespace (&arg
);
6569 /* The allowed syntax is:
6571 catch unload if <cond>
6572 catch unload <filename>
6573 catch unload <filename> if <cond>
6575 The user is not allowed to specify the <filename> after an
6578 We'll ignore the pathological case of a file named "if".
6580 First, check if there's an if clause. If so, then there
6581 cannot be a filename. */
6582 cond_string
= ep_parse_optional_if_clause (&arg
);
6584 /* If there was an if clause, then there cannot be a filename.
6585 Else, there might be a filename and an if clause. */
6586 if (cond_string
== NULL
)
6588 dll_pathname
= ep_parse_optional_filename (&arg
);
6589 ep_skip_leading_whitespace (&arg
);
6590 cond_string
= ep_parse_optional_if_clause (&arg
);
6593 if ((*arg
!= '\0') && !isspace (*arg
))
6594 error (_("Junk at end of arguments."));
6596 /* Create an unload breakpoint that only triggers when an unload of
6597 the specified dll (or any dll, if no pathname was specified)
6599 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6600 dll_pathname
, cond_string
);
6603 static enum print_stop_action
6604 print_exception_catchpoint (struct breakpoint
*b
)
6606 int bp_temp
, bp_throw
;
6608 annotate_catchpoint (b
->number
);
6610 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6611 if (b
->loc
->address
!= b
->loc
->requested_address
)
6612 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6615 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6617 bp_temp
? "Temporary catchpoint "
6619 if (!ui_out_is_mi_like_p (uiout
))
6620 ui_out_field_int (uiout
, "bkptno", b
->number
);
6622 bp_throw
? " (exception thrown), "
6623 : " (exception caught), ");
6624 if (ui_out_is_mi_like_p (uiout
))
6626 ui_out_field_string (uiout
, "reason",
6627 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6628 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6629 ui_out_field_int (uiout
, "bkptno", b
->number
);
6631 return PRINT_SRC_AND_LOC
;
6635 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6640 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6641 ui_out_field_string (uiout
, "addr", "<PENDING>");
6643 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6647 *last_addr
= b
->loc
->address
;
6648 if (strstr (b
->addr_string
, "throw") != NULL
)
6649 ui_out_field_string (uiout
, "what", "exception throw");
6651 ui_out_field_string (uiout
, "what", "exception catch");
6655 print_mention_exception_catchpoint (struct breakpoint
*b
)
6660 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6661 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6662 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6663 : _("Catchpoint "));
6664 ui_out_field_int (uiout
, "bkptno", b
->number
);
6665 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6669 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6670 print_exception_catchpoint
,
6671 print_one_exception_catchpoint
,
6672 print_mention_exception_catchpoint
6676 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6677 enum exception_event_kind ex_event
, int from_tty
)
6679 char *trigger_func_name
;
6681 if (ex_event
== EX_EVENT_CATCH
)
6682 trigger_func_name
= "__cxa_begin_catch";
6684 trigger_func_name
= "__cxa_throw";
6686 break_command_really (trigger_func_name
, cond_string
, -1,
6687 0 /* condition and thread are valid. */,
6690 AUTO_BOOLEAN_TRUE
/* pending */,
6691 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6696 /* Deal with "catch catch" and "catch throw" commands */
6699 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6700 int tempflag
, int from_tty
)
6702 char *cond_string
= NULL
;
6703 struct symtab_and_line
*sal
= NULL
;
6707 ep_skip_leading_whitespace (&arg
);
6709 cond_string
= ep_parse_optional_if_clause (&arg
);
6711 if ((*arg
!= '\0') && !isspace (*arg
))
6712 error (_("Junk at end of arguments."));
6714 if ((ex_event
!= EX_EVENT_THROW
) &&
6715 (ex_event
!= EX_EVENT_CATCH
))
6716 error (_("Unsupported or unknown exception event; cannot catch it"));
6718 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6721 warning (_("Unsupported with this platform/compiler combination."));
6724 /* Implementation of "catch catch" command. */
6727 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6729 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6730 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6733 /* Implementation of "catch throw" command. */
6736 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6738 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6739 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6742 /* Create a breakpoint struct for Ada exception catchpoints. */
6745 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6749 struct expression
*cond
,
6750 struct breakpoint_ops
*ops
,
6754 struct breakpoint
*b
;
6758 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6759 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6760 version for exception catchpoints, because two catchpoints
6761 used for different exception names will use the same address.
6762 In this case, a "breakpoint ... also set at..." warning is
6763 unproductive. Besides. the warning phrasing is also a bit
6764 inapropriate, we should use the word catchpoint, and tell
6765 the user what type of catchpoint it is. The above is good
6766 enough for now, though. */
6769 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6770 set_breakpoint_count (breakpoint_count
+ 1);
6772 b
->enable_state
= bp_enabled
;
6773 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6774 b
->number
= breakpoint_count
;
6775 b
->ignore_count
= 0;
6776 b
->loc
->cond
= cond
;
6777 b
->addr_string
= addr_string
;
6778 b
->language
= language_ada
;
6779 b
->cond_string
= cond_string
;
6780 b
->exp_string
= exp_string
;
6785 update_global_location_list (1);
6788 /* Implement the "catch exception" command. */
6791 catch_ada_exception_command (char *arg
, int from_tty
,
6792 struct cmd_list_element
*command
)
6795 struct symtab_and_line sal
;
6797 char *addr_string
= NULL
;
6798 char *exp_string
= NULL
;
6799 char *cond_string
= NULL
;
6800 struct expression
*cond
= NULL
;
6801 struct breakpoint_ops
*ops
= NULL
;
6803 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6807 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6808 &cond_string
, &cond
, &ops
);
6809 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6810 cond_string
, cond
, ops
, tempflag
,
6814 /* Implement the "catch assert" command. */
6817 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6820 struct symtab_and_line sal
;
6821 char *addr_string
= NULL
;
6822 struct breakpoint_ops
*ops
= NULL
;
6824 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6828 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6829 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6830 tempflag
, from_tty
);
6834 catch_command (char *arg
, int from_tty
)
6836 error (_("Catch requires an event name."));
6841 tcatch_command (char *arg
, int from_tty
)
6843 error (_("Catch requires an event name."));
6846 /* Delete breakpoints by address or line. */
6849 clear_command (char *arg
, int from_tty
)
6851 struct breakpoint
*b
;
6852 VEC(breakpoint_p
) *found
= 0;
6855 struct symtabs_and_lines sals
;
6856 struct symtab_and_line sal
;
6861 sals
= decode_line_spec (arg
, 1);
6866 sals
.sals
= (struct symtab_and_line
*)
6867 xmalloc (sizeof (struct symtab_and_line
));
6868 make_cleanup (xfree
, sals
.sals
);
6869 init_sal (&sal
); /* initialize to zeroes */
6870 sal
.line
= default_breakpoint_line
;
6871 sal
.symtab
= default_breakpoint_symtab
;
6872 sal
.pc
= default_breakpoint_address
;
6873 if (sal
.symtab
== 0)
6874 error (_("No source file specified."));
6882 /* We don't call resolve_sal_pc here. That's not
6883 as bad as it seems, because all existing breakpoints
6884 typically have both file/line and pc set. So, if
6885 clear is given file/line, we can match this to existing
6886 breakpoint without obtaining pc at all.
6888 We only support clearing given the address explicitly
6889 present in breakpoint table. Say, we've set breakpoint
6890 at file:line. There were several PC values for that file:line,
6891 due to optimization, all in one block.
6892 We've picked one PC value. If "clear" is issued with another
6893 PC corresponding to the same file:line, the breakpoint won't
6894 be cleared. We probably can still clear the breakpoint, but
6895 since the other PC value is never presented to user, user
6896 can only find it by guessing, and it does not seem important
6899 /* For each line spec given, delete bps which correspond
6900 to it. Do it in two passes, solely to preserve the current
6901 behavior that from_tty is forced true if we delete more than
6905 for (i
= 0; i
< sals
.nelts
; i
++)
6907 /* If exact pc given, clear bpts at that pc.
6908 If line given (pc == 0), clear all bpts on specified line.
6909 If defaulting, clear all bpts on default line
6912 defaulting sal.pc != 0 tests to do
6917 1 0 <can't happen> */
6921 /* Find all matching breakpoints and add them to
6926 /* Are we going to delete b? */
6927 if (b
->type
!= bp_none
6928 && b
->type
!= bp_watchpoint
6929 && b
->type
!= bp_hardware_watchpoint
6930 && b
->type
!= bp_read_watchpoint
6931 && b
->type
!= bp_access_watchpoint
)
6933 struct bp_location
*loc
= b
->loc
;
6934 for (; loc
; loc
= loc
->next
)
6936 int pc_match
= sal
.pc
6937 && (loc
->address
== sal
.pc
)
6938 && (!section_is_overlay (loc
->section
)
6939 || loc
->section
== sal
.section
);
6940 int line_match
= ((default_match
|| (0 == sal
.pc
))
6941 && b
->source_file
!= NULL
6942 && sal
.symtab
!= NULL
6943 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6944 && b
->line_number
== sal
.line
);
6945 if (pc_match
|| line_match
)
6954 VEC_safe_push(breakpoint_p
, found
, b
);
6957 /* Now go thru the 'found' chain and delete them. */
6958 if (VEC_empty(breakpoint_p
, found
))
6961 error (_("No breakpoint at %s."), arg
);
6963 error (_("No breakpoint at this line."));
6966 if (VEC_length(breakpoint_p
, found
) > 1)
6967 from_tty
= 1; /* Always report if deleted more than one */
6970 if (VEC_length(breakpoint_p
, found
) == 1)
6971 printf_unfiltered (_("Deleted breakpoint "));
6973 printf_unfiltered (_("Deleted breakpoints "));
6975 breakpoints_changed ();
6977 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6980 printf_unfiltered ("%d ", b
->number
);
6981 delete_breakpoint (b
);
6984 putchar_unfiltered ('\n');
6987 /* Delete breakpoint in BS if they are `delete' breakpoints and
6988 all breakpoints that are marked for deletion, whether hit or not.
6989 This is called after any breakpoint is hit, or after errors. */
6992 breakpoint_auto_delete (bpstat bs
)
6994 struct breakpoint
*b
, *temp
;
6996 for (; bs
; bs
= bs
->next
)
6997 if (bs
->breakpoint_at
6998 && bs
->breakpoint_at
->owner
6999 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7001 delete_breakpoint (bs
->breakpoint_at
->owner
);
7003 ALL_BREAKPOINTS_SAFE (b
, temp
)
7005 if (b
->disposition
== disp_del_at_next_stop
)
7006 delete_breakpoint (b
);
7010 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
7011 into the inferior, only remove already-inserted locations that no
7012 longer should be inserted. Functions that delete a breakpoint or
7013 breakpoints should pass false, so that deleting a breakpoint
7014 doesn't have the side effect of inserting the locations of other
7015 breakpoints that are marked not-inserted, but should_be_inserted
7016 returns true on them.
7018 This behaviour is useful is situations close to tear-down -- e.g.,
7019 after an exec, while the target still has execution, but breakpoint
7020 shadows of the previous executable image should *NOT* be restored
7021 to the new image; or before detaching, where the target still has
7022 execution and wants to delete breakpoints from GDB's lists, and all
7023 breakpoints had already been removed from the inferior. */
7026 update_global_location_list (int should_insert
)
7028 struct breakpoint
*b
;
7029 struct bp_location
**next
= &bp_location_chain
;
7030 struct bp_location
*loc
;
7031 struct bp_location
*loc2
;
7032 struct gdb_exception e
;
7033 VEC(bp_location_p
) *old_locations
= NULL
;
7037 /* Store old locations for future reference. */
7038 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7039 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7041 bp_location_chain
= NULL
;
7044 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7047 next
= &(loc
->global_next
);
7052 /* Identify bp_location instances that are no longer present in the new
7053 list, and therefore should be freed. Note that it's not necessary that
7054 those locations should be removed from inferior -- if there's another
7055 location at the same address (previously marked as duplicate),
7056 we don't need to remove/insert the location. */
7057 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7059 /* Tells if 'loc' is found amoung the new locations. If not, we
7061 int found_object
= 0;
7062 /* Tells if the location should remain inserted in the target. */
7063 int keep_in_target
= 0;
7065 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7072 /* If this location is no longer present, and inserted, look if there's
7073 maybe a new location at the same address. If so, mark that one
7074 inserted, and don't remove this one. This is needed so that we
7075 don't have a time window where a breakpoint at certain location is not
7080 /* If the location is inserted now, we might have to remove it. */
7082 if (found_object
&& should_be_inserted (loc
))
7084 /* The location is still present in the location list, and still
7085 should be inserted. Don't do anything. */
7090 /* The location is either no longer present, or got disabled.
7091 See if there's another location at the same address, in which
7092 case we don't need to remove this one from the target. */
7093 if (breakpoint_address_is_meaningful (loc
->owner
))
7094 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7096 /* For the sake of should_insert_location. The
7097 call to check_duplicates will fix up this later. */
7098 loc2
->duplicate
= 0;
7099 if (should_be_inserted (loc2
)
7100 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7103 loc2
->target_info
= loc
->target_info
;
7110 if (!keep_in_target
)
7112 if (remove_breakpoint (loc
, mark_uninserted
))
7114 /* This is just about all we can do. We could keep this
7115 location on the global list, and try to remove it next
7116 time, but there's no particular reason why we will
7119 Note that at this point, loc->owner is still valid,
7120 as delete_breakpoint frees the breakpoint only
7121 after calling us. */
7122 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7123 loc
->owner
->number
);
7131 if (removed
&& non_stop
)
7133 /* This location was removed from the targets. In non-stop mode,
7134 a race condition is possible where we've removed a breakpoint,
7135 but stop events for that breakpoint are already queued and will
7136 arrive later. To suppress spurious SIGTRAPs reported to user,
7137 we keep this breakpoint location for a bit, and will retire it
7138 after we see 3 * thread_count events.
7139 The theory here is that reporting of events should,
7140 "on the average", be fair, so after that many event we'll see
7141 events from all threads that have anything of interest, and no
7142 longer need to keep this breakpoint. This is just a
7143 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7144 which is usability issue, but not a correctness problem. */
7145 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7148 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7151 free_bp_location (loc
);
7157 check_duplicates (b
);
7160 if (breakpoints_always_inserted_mode ()
7162 && target_has_execution
)
7163 insert_breakpoint_locations ();
7167 breakpoint_retire_moribund (void)
7169 struct bp_location
*loc
;
7172 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7173 if (--(loc
->events_till_retirement
) == 0)
7175 free_bp_location (loc
);
7176 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7182 update_global_location_list_nothrow (int inserting
)
7184 struct gdb_exception e
;
7185 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7186 update_global_location_list (inserting
);
7189 /* Clear BPT from a BPS. */
7191 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7194 for (bs
= bps
; bs
; bs
= bs
->next
)
7195 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7197 bs
->breakpoint_at
= NULL
;
7199 /* bs->commands will be freed later. */
7203 /* Callback for iterate_over_threads. */
7205 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7207 struct breakpoint
*bpt
= data
;
7208 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7212 /* Delete a breakpoint and clean up all traces of it in the data
7216 delete_breakpoint (struct breakpoint
*bpt
)
7218 struct breakpoint
*b
;
7219 struct bp_location
*loc
, *next
;
7221 gdb_assert (bpt
!= NULL
);
7223 /* Has this bp already been deleted? This can happen because multiple
7224 lists can hold pointers to bp's. bpstat lists are especial culprits.
7226 One example of this happening is a watchpoint's scope bp. When the
7227 scope bp triggers, we notice that the watchpoint is out of scope, and
7228 delete it. We also delete its scope bp. But the scope bp is marked
7229 "auto-deleting", and is already on a bpstat. That bpstat is then
7230 checked for auto-deleting bp's, which are deleted.
7232 A real solution to this problem might involve reference counts in bp's,
7233 and/or giving them pointers back to their referencing bpstat's, and
7234 teaching delete_breakpoint to only free a bp's storage when no more
7235 references were extent. A cheaper bandaid was chosen. */
7236 if (bpt
->type
== bp_none
)
7239 observer_notify_breakpoint_deleted (bpt
->number
);
7241 if (breakpoint_chain
== bpt
)
7242 breakpoint_chain
= bpt
->next
;
7247 b
->next
= bpt
->next
;
7251 free_command_lines (&bpt
->commands
);
7252 if (bpt
->cond_string
!= NULL
)
7253 xfree (bpt
->cond_string
);
7254 if (bpt
->addr_string
!= NULL
)
7255 xfree (bpt
->addr_string
);
7256 if (bpt
->exp
!= NULL
)
7258 if (bpt
->exp_string
!= NULL
)
7259 xfree (bpt
->exp_string
);
7260 if (bpt
->val
!= NULL
)
7261 value_free (bpt
->val
);
7262 if (bpt
->source_file
!= NULL
)
7263 xfree (bpt
->source_file
);
7264 if (bpt
->dll_pathname
!= NULL
)
7265 xfree (bpt
->dll_pathname
);
7266 if (bpt
->triggered_dll_pathname
!= NULL
)
7267 xfree (bpt
->triggered_dll_pathname
);
7268 if (bpt
->exec_pathname
!= NULL
)
7269 xfree (bpt
->exec_pathname
);
7271 /* Be sure no bpstat's are pointing at it after it's been freed. */
7272 /* FIXME, how can we find all bpstat's?
7273 We just check stop_bpstat for now. Note that we cannot just
7274 remove bpstats pointing at bpt from the stop_bpstat list
7275 entirely, as breakpoint commands are associated with the bpstat;
7276 if we remove it here, then the later call to
7277 bpstat_do_actions (&stop_bpstat);
7278 in event-top.c won't do anything, and temporary breakpoints
7279 with commands won't work. */
7281 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7283 /* Now that breakpoint is removed from breakpoint
7284 list, update the global location list. This
7285 will remove locations that used to belong to
7286 this breakpoint. Do this before freeing
7287 the breakpoint itself, since remove_breakpoint
7288 looks at location's owner. It might be better
7289 design to have location completely self-contained,
7290 but it's not the case now. */
7291 update_global_location_list (0);
7294 /* On the chance that someone will soon try again to delete this same
7295 bp, we mark it as deleted before freeing its storage. */
7296 bpt
->type
= bp_none
;
7302 do_delete_breakpoint_cleanup (void *b
)
7304 delete_breakpoint (b
);
7308 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7310 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7314 delete_command (char *arg
, int from_tty
)
7316 struct breakpoint
*b
, *temp
;
7322 int breaks_to_delete
= 0;
7324 /* Delete all breakpoints if no argument.
7325 Do not delete internal or call-dummy breakpoints, these
7326 have to be deleted with an explicit breakpoint number argument. */
7329 if (b
->type
!= bp_call_dummy
&&
7330 b
->type
!= bp_shlib_event
&&
7331 b
->type
!= bp_thread_event
&&
7332 b
->type
!= bp_overlay_event
&&
7335 breaks_to_delete
= 1;
7340 /* Ask user only if there are some breakpoints to delete. */
7342 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7344 ALL_BREAKPOINTS_SAFE (b
, temp
)
7346 if (b
->type
!= bp_call_dummy
&&
7347 b
->type
!= bp_shlib_event
&&
7348 b
->type
!= bp_thread_event
&&
7349 b
->type
!= bp_overlay_event
&&
7351 delete_breakpoint (b
);
7356 map_breakpoint_numbers (arg
, delete_breakpoint
);
7360 all_locations_are_pending (struct bp_location
*loc
)
7362 for (; loc
; loc
= loc
->next
)
7363 if (!loc
->shlib_disabled
)
7368 /* Subroutine of update_breakpoint_locations to simplify it.
7369 Return non-zero if multiple fns in list LOC have the same name.
7370 Null names are ignored. */
7373 ambiguous_names_p (struct bp_location
*loc
)
7375 struct bp_location
*l
;
7376 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7377 (int (*) (const void *, const void *)) streq
,
7378 NULL
, xcalloc
, xfree
);
7380 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7383 const char *name
= l
->function_name
;
7385 /* Allow for some names to be NULL, ignore them. */
7389 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7391 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7406 update_breakpoint_locations (struct breakpoint
*b
,
7407 struct symtabs_and_lines sals
)
7411 struct bp_location
*existing_locations
= b
->loc
;
7413 /* If there's no new locations, and all existing locations
7414 are pending, don't do anything. This optimizes
7415 the common case where all locations are in the same
7416 shared library, that was unloaded. We'd like to
7417 retain the location, so that when the library
7418 is loaded again, we don't loose the enabled/disabled
7419 status of the individual locations. */
7420 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7425 for (i
= 0; i
< sals
.nelts
; ++i
)
7427 struct bp_location
*new_loc
=
7428 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7430 /* Reparse conditions, they might contain references to the
7432 if (b
->cond_string
!= NULL
)
7434 struct gdb_exception e
;
7437 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7439 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7444 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7445 b
->number
, e
.message
);
7446 new_loc
->enabled
= 0;
7450 if (b
->source_file
!= NULL
)
7451 xfree (b
->source_file
);
7452 if (sals
.sals
[i
].symtab
== NULL
)
7453 b
->source_file
= NULL
;
7456 savestring (sals
.sals
[i
].symtab
->filename
,
7457 strlen (sals
.sals
[i
].symtab
->filename
));
7459 if (b
->line_number
== 0)
7460 b
->line_number
= sals
.sals
[i
].line
;
7463 /* Update locations of permanent breakpoints. */
7464 if (b
->enable_state
== bp_permanent
)
7465 make_breakpoint_permanent (b
);
7467 /* If possible, carry over 'disable' status from existing breakpoints. */
7469 struct bp_location
*e
= existing_locations
;
7470 /* If there are multiple breakpoints with the same function name,
7471 e.g. for inline functions, comparing function names won't work.
7472 Instead compare pc addresses; this is just a heuristic as things
7473 may have moved, but in practice it gives the correct answer
7474 often enough until a better solution is found. */
7475 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7477 for (; e
; e
= e
->next
)
7479 if (!e
->enabled
&& e
->function_name
)
7481 struct bp_location
*l
= b
->loc
;
7482 if (have_ambiguous_names
)
7484 for (; l
; l
= l
->next
)
7485 if (e
->address
== l
->address
)
7493 for (; l
; l
= l
->next
)
7494 if (l
->function_name
7495 && strcmp (e
->function_name
, l
->function_name
) == 0)
7505 update_global_location_list (1);
7509 /* Reset a breakpoint given it's struct breakpoint * BINT.
7510 The value we return ends up being the return value from catch_errors.
7511 Unused in this case. */
7514 breakpoint_re_set_one (void *bint
)
7516 /* get past catch_errs */
7517 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7521 int *not_found_ptr
= ¬_found
;
7522 struct symtabs_and_lines sals
= {};
7523 struct symtabs_and_lines expanded
;
7525 enum enable_state save_enable
;
7526 struct gdb_exception e
;
7532 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7536 case bp_hardware_breakpoint
:
7538 case bp_catch_unload
:
7539 if (b
->addr_string
== NULL
)
7541 /* Anything without a string can't be re-set. */
7542 delete_breakpoint (b
);
7546 set_language (b
->language
);
7547 input_radix
= b
->input_radix
;
7549 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7551 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7556 int not_found_and_ok
= 0;
7557 /* For pending breakpoints, it's expected that parsing
7558 will fail until the right shared library is loaded.
7559 User has already told to create pending breakpoints and
7560 don't need extra messages. If breakpoint is in bp_shlib_disabled
7561 state, then user already saw the message about that breakpoint
7562 being disabled, and don't want to see more errors. */
7564 && (b
->condition_not_parsed
7565 || (b
->loc
&& b
->loc
->shlib_disabled
)
7566 || b
->enable_state
== bp_disabled
))
7567 not_found_and_ok
= 1;
7569 if (!not_found_and_ok
)
7571 /* We surely don't want to warn about the same breakpoint
7572 10 times. One solution, implemented here, is disable
7573 the breakpoint on error. Another solution would be to
7574 have separate 'warning emitted' flag. Since this
7575 happens only when a binary has changed, I don't know
7576 which approach is better. */
7577 b
->enable_state
= bp_disabled
;
7578 throw_exception (e
);
7585 gdb_assert (sals
.nelts
== 1);
7586 resolve_sal_pc (&sals
.sals
[0]);
7587 if (b
->condition_not_parsed
&& s
&& s
[0])
7589 char *cond_string
= 0;
7591 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7592 &cond_string
, &thread
);
7594 b
->cond_string
= cond_string
;
7596 b
->condition_not_parsed
= 0;
7598 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7599 update_breakpoint_locations (b
, expanded
);
7605 case bp_hardware_watchpoint
:
7606 case bp_read_watchpoint
:
7607 case bp_access_watchpoint
:
7608 /* Watchpoint can be either on expression using entirely global variables,
7609 or it can be on local variables.
7611 Watchpoints of the first kind are never auto-deleted, and even persist
7612 across program restarts. Since they can use variables from shared
7613 libraries, we need to reparse expression as libraries are loaded
7616 Watchpoints on local variables can also change meaning as result
7617 of solib event. For example, if a watchpoint uses both a local and
7618 a global variables in expression, it's a local watchpoint, but
7619 unloading of a shared library will make the expression invalid.
7620 This is not a very common use case, but we still re-evaluate
7621 expression, to avoid surprises to the user.
7623 Note that for local watchpoints, we re-evaluate it only if
7624 watchpoints frame id is still valid. If it's not, it means
7625 the watchpoint is out of scope and will be deleted soon. In fact,
7626 I'm not sure we'll ever be called in this case.
7628 If a local watchpoint's frame id is still valid, then
7629 b->exp_valid_block is likewise valid, and we can safely use it.
7631 Don't do anything about disabled watchpoints, since they will
7632 be reevaluated again when enabled. */
7633 update_watchpoint (b
, 1 /* reparse */);
7635 /* We needn't really do anything to reset these, since the mask
7636 that requests them is unaffected by e.g., new libraries being
7639 case bp_catch_vfork
:
7644 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7646 /* Delete overlay event breakpoints; they will be reset later by
7647 breakpoint_re_set. */
7648 case bp_overlay_event
:
7649 delete_breakpoint (b
);
7652 /* This breakpoint is special, it's set up when the inferior
7653 starts and we really don't want to touch it. */
7654 case bp_shlib_event
:
7656 /* Like bp_shlib_event, this breakpoint type is special.
7657 Once it is set up, we do not want to touch it. */
7658 case bp_thread_event
:
7660 /* Keep temporary breakpoints, which can be encountered when we step
7661 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7662 Otherwise these should have been blown away via the cleanup chain
7663 or by breakpoint_init_inferior when we rerun the executable. */
7666 case bp_watchpoint_scope
:
7668 case bp_step_resume
:
7670 case bp_longjmp_resume
:
7677 /* Re-set all breakpoints after symbols have been re-loaded. */
7679 breakpoint_re_set (void)
7681 struct breakpoint
*b
, *temp
;
7682 enum language save_language
;
7683 int save_input_radix
;
7685 save_language
= current_language
->la_language
;
7686 save_input_radix
= input_radix
;
7687 ALL_BREAKPOINTS_SAFE (b
, temp
)
7689 /* Format possible error msg */
7690 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7692 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7693 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7694 do_cleanups (cleanups
);
7696 set_language (save_language
);
7697 input_radix
= save_input_radix
;
7699 create_overlay_event_breakpoint ("_ovly_debug_event");
7702 /* Reset the thread number of this breakpoint:
7704 - If the breakpoint is for all threads, leave it as-is.
7705 - Else, reset it to the current thread for inferior_ptid. */
7707 breakpoint_re_set_thread (struct breakpoint
*b
)
7709 if (b
->thread
!= -1)
7711 if (in_thread_list (inferior_ptid
))
7712 b
->thread
= pid_to_thread_id (inferior_ptid
);
7716 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7717 If from_tty is nonzero, it prints a message to that effect,
7718 which ends with a period (no newline). */
7721 set_ignore_count (int bptnum
, int count
, int from_tty
)
7723 struct breakpoint
*b
;
7729 if (b
->number
== bptnum
)
7731 b
->ignore_count
= count
;
7735 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7737 else if (count
== 1)
7738 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7741 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7744 breakpoints_changed ();
7745 observer_notify_breakpoint_modified (b
->number
);
7749 error (_("No breakpoint number %d."), bptnum
);
7752 /* Command to set ignore-count of breakpoint N to COUNT. */
7755 ignore_command (char *args
, int from_tty
)
7761 error_no_arg (_("a breakpoint number"));
7763 num
= get_number (&p
);
7765 error (_("bad breakpoint number: '%s'"), args
);
7767 error (_("Second argument (specified ignore-count) is missing."));
7769 set_ignore_count (num
,
7770 longest_to_int (value_as_long (parse_and_eval (p
))),
7773 printf_filtered ("\n");
7776 /* Call FUNCTION on each of the breakpoints
7777 whose numbers are given in ARGS. */
7780 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7785 struct breakpoint
*b
, *tmp
;
7789 error_no_arg (_("one or more breakpoint numbers"));
7796 num
= get_number_or_range (&p1
);
7799 warning (_("bad breakpoint number at or near '%s'"), p
);
7803 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7804 if (b
->number
== num
)
7806 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7809 if (related_breakpoint
)
7810 function (related_breakpoint
);
7814 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7820 static struct bp_location
*
7821 find_location_by_number (char *number
)
7823 char *dot
= strchr (number
, '.');
7827 struct breakpoint
*b
;
7828 struct bp_location
*loc
;
7833 bp_num
= get_number_or_range (&p1
);
7835 error (_("Bad breakpoint number '%s'"), number
);
7838 if (b
->number
== bp_num
)
7843 if (!b
|| b
->number
!= bp_num
)
7844 error (_("Bad breakpoint number '%s'"), number
);
7847 loc_num
= get_number_or_range (&p1
);
7849 error (_("Bad breakpoint location number '%s'"), number
);
7853 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7856 error (_("Bad breakpoint location number '%s'"), dot
+1);
7862 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7863 If from_tty is nonzero, it prints a message to that effect,
7864 which ends with a period (no newline). */
7867 disable_breakpoint (struct breakpoint
*bpt
)
7869 /* Never disable a watchpoint scope breakpoint; we want to
7870 hit them when we leave scope so we can delete both the
7871 watchpoint and its scope breakpoint at that time. */
7872 if (bpt
->type
== bp_watchpoint_scope
)
7875 /* You can't disable permanent breakpoints. */
7876 if (bpt
->enable_state
== bp_permanent
)
7879 bpt
->enable_state
= bp_disabled
;
7881 update_global_location_list (0);
7883 observer_notify_breakpoint_modified (bpt
->number
);
7887 disable_command (char *args
, int from_tty
)
7889 struct breakpoint
*bpt
;
7891 ALL_BREAKPOINTS (bpt
)
7895 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7900 case bp_catch_unload
:
7902 case bp_catch_vfork
:
7904 case bp_hardware_breakpoint
:
7906 case bp_hardware_watchpoint
:
7907 case bp_read_watchpoint
:
7908 case bp_access_watchpoint
:
7909 disable_breakpoint (bpt
);
7913 else if (strchr (args
, '.'))
7915 struct bp_location
*loc
= find_location_by_number (args
);
7918 update_global_location_list (0);
7921 map_breakpoint_numbers (args
, disable_breakpoint
);
7925 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7927 int target_resources_ok
, other_type_used
;
7930 if (bpt
->type
== bp_hardware_breakpoint
)
7933 i
= hw_breakpoint_used_count ();
7934 target_resources_ok
=
7935 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7937 if (target_resources_ok
== 0)
7938 error (_("No hardware breakpoint support in the target."));
7939 else if (target_resources_ok
< 0)
7940 error (_("Hardware breakpoints used exceeds limit."));
7943 if (bpt
->type
== bp_watchpoint
||
7944 bpt
->type
== bp_hardware_watchpoint
||
7945 bpt
->type
== bp_read_watchpoint
||
7946 bpt
->type
== bp_access_watchpoint
)
7948 struct frame_id saved_frame_id
;
7950 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7951 if (bpt
->exp_valid_block
!= NULL
)
7953 struct frame_info
*fr
=
7954 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7957 printf_filtered (_("\
7958 Cannot enable watchpoint %d because the block in which its expression\n\
7959 is valid is not currently in scope.\n"), bpt
->number
);
7966 value_free (bpt
->val
);
7967 mark
= value_mark ();
7968 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7970 release_value (bpt
->val
);
7973 if (bpt
->type
== bp_hardware_watchpoint
||
7974 bpt
->type
== bp_read_watchpoint
||
7975 bpt
->type
== bp_access_watchpoint
)
7977 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7978 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7980 /* Hack around 'unused var' error for some targets here */
7981 (void) mem_cnt
, (void) i
;
7982 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7983 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7984 /* we can consider of type is bp_hardware_watchpoint, convert to
7985 bp_watchpoint in the following condition */
7986 if (target_resources_ok
< 0)
7988 printf_filtered (_("\
7989 Cannot enable watchpoint %d because target watch resources\n\
7990 have been allocated for other watchpoints.\n"), bpt
->number
);
7991 value_free_to_mark (mark
);
7996 select_frame (frame_find_by_id (saved_frame_id
));
7997 value_free_to_mark (mark
);
8000 if (bpt
->enable_state
!= bp_permanent
)
8001 bpt
->enable_state
= bp_enabled
;
8002 bpt
->disposition
= disposition
;
8003 update_global_location_list (1);
8004 breakpoints_changed ();
8006 observer_notify_breakpoint_modified (bpt
->number
);
8011 enable_breakpoint (struct breakpoint
*bpt
)
8013 do_enable_breakpoint (bpt
, bpt
->disposition
);
8016 /* The enable command enables the specified breakpoints (or all defined
8017 breakpoints) so they once again become (or continue to be) effective
8018 in stopping the inferior. */
8021 enable_command (char *args
, int from_tty
)
8023 struct breakpoint
*bpt
;
8025 ALL_BREAKPOINTS (bpt
)
8029 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8034 case bp_catch_unload
:
8036 case bp_catch_vfork
:
8038 case bp_hardware_breakpoint
:
8040 case bp_hardware_watchpoint
:
8041 case bp_read_watchpoint
:
8042 case bp_access_watchpoint
:
8043 enable_breakpoint (bpt
);
8047 else if (strchr (args
, '.'))
8049 struct bp_location
*loc
= find_location_by_number (args
);
8052 update_global_location_list (1);
8055 map_breakpoint_numbers (args
, enable_breakpoint
);
8059 enable_once_breakpoint (struct breakpoint
*bpt
)
8061 do_enable_breakpoint (bpt
, disp_disable
);
8065 enable_once_command (char *args
, int from_tty
)
8067 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8071 enable_delete_breakpoint (struct breakpoint
*bpt
)
8073 do_enable_breakpoint (bpt
, disp_del
);
8077 enable_delete_command (char *args
, int from_tty
)
8079 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8083 set_breakpoint_cmd (char *args
, int from_tty
)
8088 show_breakpoint_cmd (char *args
, int from_tty
)
8092 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8094 struct symtabs_and_lines
8095 decode_line_spec_1 (char *string
, int funfirstline
)
8097 struct symtabs_and_lines sals
;
8099 error (_("Empty line specification."));
8100 if (default_breakpoint_valid
)
8101 sals
= decode_line_1 (&string
, funfirstline
,
8102 default_breakpoint_symtab
,
8103 default_breakpoint_line
,
8104 (char ***) NULL
, NULL
);
8106 sals
= decode_line_1 (&string
, funfirstline
,
8107 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8109 error (_("Junk at end of line specification: %s"), string
);
8113 /* Create and insert a raw software breakpoint at PC. Return an
8114 identifier, which should be used to remove the breakpoint later.
8115 In general, places which call this should be using something on the
8116 breakpoint chain instead; this function should be eliminated
8120 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8122 struct bp_target_info
*bp_tgt
;
8124 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8125 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8127 bp_tgt
->placed_address
= pc
;
8128 if (target_insert_breakpoint (bp_tgt
) != 0)
8130 /* Could not insert the breakpoint. */
8138 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8141 deprecated_remove_raw_breakpoint (void *bp
)
8143 struct bp_target_info
*bp_tgt
= bp
;
8146 ret
= target_remove_breakpoint (bp_tgt
);
8152 /* One (or perhaps two) breakpoints used for software single stepping. */
8154 static void *single_step_breakpoints
[2];
8156 /* Create and insert a breakpoint for software single step. */
8159 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8163 if (single_step_breakpoints
[0] == NULL
)
8164 bpt_p
= &single_step_breakpoints
[0];
8167 gdb_assert (single_step_breakpoints
[1] == NULL
);
8168 bpt_p
= &single_step_breakpoints
[1];
8171 /* NOTE drow/2006-04-11: A future improvement to this function would be
8172 to only create the breakpoints once, and actually put them on the
8173 breakpoint chain. That would let us use set_raw_breakpoint. We could
8174 adjust the addresses each time they were needed. Doing this requires
8175 corresponding changes elsewhere where single step breakpoints are
8176 handled, however. So, for now, we use this. */
8178 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8180 error (_("Could not insert single-step breakpoint at 0x%s"),
8181 paddr_nz (next_pc
));
8184 /* Remove and delete any breakpoints used for software single step. */
8187 remove_single_step_breakpoints (void)
8189 gdb_assert (single_step_breakpoints
[0] != NULL
);
8191 /* See insert_single_step_breakpoint for more about this deprecated
8193 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8194 single_step_breakpoints
[0] = NULL
;
8196 if (single_step_breakpoints
[1] != NULL
)
8198 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8199 single_step_breakpoints
[1] = NULL
;
8203 /* Check whether a software single-step breakpoint is inserted at PC. */
8206 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8210 for (i
= 0; i
< 2; i
++)
8212 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8213 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8221 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8222 It is defined as a macro to prevent duplication.
8223 COMMAND should be a string constant containing the name of the command. */
8224 #define BREAK_ARGS_HELP(command) \
8225 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8226 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8227 If a line number is specified, break at start of code for that line.\n\
8228 If a function is specified, break at start of code for that function.\n\
8229 If an address is specified, break at that exact address.\n\
8230 With no LOCATION, uses current execution address of selected stack frame.\n\
8231 This is useful for breaking on return to a stack frame.\n\
8233 THREADNUM is the number from \"info threads\".\n\
8234 CONDITION is a boolean expression.\n\
8236 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8238 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8240 /* List of subcommands for "catch". */
8241 static struct cmd_list_element
*catch_cmdlist
;
8243 /* List of subcommands for "tcatch". */
8244 static struct cmd_list_element
*tcatch_cmdlist
;
8246 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8247 lists, and pass some additional user data to the command function. */
8249 add_catch_command (char *name
, char *docstring
,
8250 void (*sfunc
) (char *args
, int from_tty
,
8251 struct cmd_list_element
*command
),
8252 void *user_data_catch
,
8253 void *user_data_tcatch
)
8255 struct cmd_list_element
*command
;
8257 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8259 set_cmd_sfunc (command
, sfunc
);
8260 set_cmd_context (command
, user_data_catch
);
8262 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8264 set_cmd_sfunc (command
, sfunc
);
8265 set_cmd_context (command
, user_data_tcatch
);
8269 _initialize_breakpoint (void)
8271 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8272 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8273 struct cmd_list_element
*c
;
8275 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8277 breakpoint_chain
= 0;
8278 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8279 before a breakpoint is set. */
8280 breakpoint_count
= 0;
8282 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8283 Set ignore-count of breakpoint number N to COUNT.\n\
8284 Usage is `ignore N COUNT'."));
8286 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8288 add_com ("commands", class_breakpoint
, commands_command
, _("\
8289 Set commands to be executed when a breakpoint is hit.\n\
8290 Give breakpoint number as argument after \"commands\".\n\
8291 With no argument, the targeted breakpoint is the last one set.\n\
8292 The commands themselves follow starting on the next line.\n\
8293 Type a line containing \"end\" to indicate the end of them.\n\
8294 Give \"silent\" as the first line to make the breakpoint silent;\n\
8295 then no output is printed when it is hit, except what the commands print."));
8297 add_com ("condition", class_breakpoint
, condition_command
, _("\
8298 Specify breakpoint number N to break only if COND is true.\n\
8299 Usage is `condition N COND', where N is an integer and COND is an\n\
8300 expression to be evaluated whenever breakpoint N is reached."));
8302 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8303 Set a temporary breakpoint.\n\
8304 Like \"break\" except the breakpoint is only temporary,\n\
8305 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8306 by using \"enable delete\" on the breakpoint number.\n\
8308 BREAK_ARGS_HELP ("tbreak")));
8309 set_cmd_completer (c
, location_completer
);
8311 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8312 Set a hardware assisted breakpoint.\n\
8313 Like \"break\" except the breakpoint requires hardware support,\n\
8314 some target hardware may not have this support.\n\
8316 BREAK_ARGS_HELP ("hbreak")));
8317 set_cmd_completer (c
, location_completer
);
8319 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8320 Set a temporary hardware assisted breakpoint.\n\
8321 Like \"hbreak\" except the breakpoint is only temporary,\n\
8322 so it will be deleted when hit.\n\
8324 BREAK_ARGS_HELP ("thbreak")));
8325 set_cmd_completer (c
, location_completer
);
8327 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8328 Enable some breakpoints.\n\
8329 Give breakpoint numbers (separated by spaces) as arguments.\n\
8330 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8331 This is used to cancel the effect of the \"disable\" command.\n\
8332 With a subcommand you can enable temporarily."),
8333 &enablelist
, "enable ", 1, &cmdlist
);
8335 add_com ("ab", class_breakpoint
, enable_command
, _("\
8336 Enable some breakpoints.\n\
8337 Give breakpoint numbers (separated by spaces) as arguments.\n\
8338 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8339 This is used to cancel the effect of the \"disable\" command.\n\
8340 With a subcommand you can enable temporarily."));
8342 add_com_alias ("en", "enable", class_breakpoint
, 1);
8344 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8345 Enable some breakpoints.\n\
8346 Give breakpoint numbers (separated by spaces) as arguments.\n\
8347 This is used to cancel the effect of the \"disable\" command.\n\
8348 May be abbreviated to simply \"enable\".\n"),
8349 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8351 add_cmd ("once", no_class
, enable_once_command
, _("\
8352 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8353 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8356 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8357 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8358 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8361 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8362 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8363 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8366 add_cmd ("once", no_class
, enable_once_command
, _("\
8367 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8368 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8371 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8372 Disable some breakpoints.\n\
8373 Arguments are breakpoint numbers with spaces in between.\n\
8374 To disable all breakpoints, give no argument.\n\
8375 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8376 &disablelist
, "disable ", 1, &cmdlist
);
8377 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8378 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8380 add_com ("sb", class_breakpoint
, disable_command
, _("\
8381 Disable some breakpoints.\n\
8382 Arguments are breakpoint numbers with spaces in between.\n\
8383 To disable all breakpoints, give no argument.\n\
8384 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8386 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8387 Disable some breakpoints.\n\
8388 Arguments are breakpoint numbers with spaces in between.\n\
8389 To disable all breakpoints, give no argument.\n\
8390 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8391 This command may be abbreviated \"disable\"."),
8394 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8395 Delete some breakpoints or auto-display expressions.\n\
8396 Arguments are breakpoint numbers with spaces in between.\n\
8397 To delete all breakpoints, give no argument.\n\
8399 Also a prefix command for deletion of other GDB objects.\n\
8400 The \"unset\" command is also an alias for \"delete\"."),
8401 &deletelist
, "delete ", 1, &cmdlist
);
8402 add_com_alias ("d", "delete", class_breakpoint
, 1);
8403 add_com_alias ("del", "delete", class_breakpoint
, 1);
8405 add_com ("db", class_breakpoint
, delete_command
, _("\
8406 Delete some breakpoints.\n\
8407 Arguments are breakpoint numbers with spaces in between.\n\
8408 To delete all breakpoints, give no argument.\n"));
8410 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8411 Delete some breakpoints or auto-display expressions.\n\
8412 Arguments are breakpoint numbers with spaces in between.\n\
8413 To delete all breakpoints, give no argument.\n\
8414 This command may be abbreviated \"delete\"."),
8417 add_com ("clear", class_breakpoint
, clear_command
, _("\
8418 Clear breakpoint at specified line or function.\n\
8419 Argument may be line number, function name, or \"*\" and an address.\n\
8420 If line number is specified, all breakpoints in that line are cleared.\n\
8421 If function is specified, breakpoints at beginning of function are cleared.\n\
8422 If an address is specified, breakpoints at that address are cleared.\n\
8424 With no argument, clears all breakpoints in the line that the selected frame\n\
8427 See also the \"delete\" command which clears breakpoints by number."));
8429 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8430 Set breakpoint at specified line or function.\n"
8431 BREAK_ARGS_HELP ("break")));
8432 set_cmd_completer (c
, location_completer
);
8434 add_com_alias ("b", "break", class_run
, 1);
8435 add_com_alias ("br", "break", class_run
, 1);
8436 add_com_alias ("bre", "break", class_run
, 1);
8437 add_com_alias ("brea", "break", class_run
, 1);
8441 add_com_alias ("ba", "break", class_breakpoint
, 1);
8442 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8447 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8448 Break in function/address or break at a line in the current file."),
8449 &stoplist
, "stop ", 1, &cmdlist
);
8450 add_cmd ("in", class_breakpoint
, stopin_command
,
8451 _("Break in function or address."), &stoplist
);
8452 add_cmd ("at", class_breakpoint
, stopat_command
,
8453 _("Break at a line in the current file."), &stoplist
);
8454 add_com ("status", class_info
, breakpoints_info
, _("\
8455 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8456 The \"Type\" column indicates one of:\n\
8457 \tbreakpoint - normal breakpoint\n\
8458 \twatchpoint - watchpoint\n\
8459 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8460 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8461 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8462 address and file/line number respectively.\n\
8464 Convenience variable \"$_\" and default examine address for \"x\"\n\
8465 are set to the address of the last breakpoint listed unless the command\n\
8466 is prefixed with \"server \".\n\n\
8467 Convenience variable \"$bpnum\" contains the number of the last\n\
8471 add_info ("breakpoints", breakpoints_info
, _("\
8472 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8473 The \"Type\" column indicates one of:\n\
8474 \tbreakpoint - normal breakpoint\n\
8475 \twatchpoint - watchpoint\n\
8476 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8477 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8478 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8479 address and file/line number respectively.\n\
8481 Convenience variable \"$_\" and default examine address for \"x\"\n\
8482 are set to the address of the last breakpoint listed unless the command\n\
8483 is prefixed with \"server \".\n\n\
8484 Convenience variable \"$bpnum\" contains the number of the last\n\
8488 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8489 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8490 The \"Type\" column indicates one of:\n\
8491 \tbreakpoint - normal breakpoint\n\
8492 \twatchpoint - watchpoint\n\
8493 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8494 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8495 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8496 address and file/line number respectively.\n\
8498 Convenience variable \"$_\" and default examine address for \"x\"\n\
8499 are set to the address of the last breakpoint listed unless the command\n\
8500 is prefixed with \"server \".\n\n\
8501 Convenience variable \"$bpnum\" contains the number of the last\n\
8504 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8505 Status of all breakpoints, or breakpoint number NUMBER.\n\
8506 The \"Type\" column indicates one of:\n\
8507 \tbreakpoint - normal breakpoint\n\
8508 \twatchpoint - watchpoint\n\
8509 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8510 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8511 \tuntil - internal breakpoint used by the \"until\" command\n\
8512 \tfinish - internal breakpoint used by the \"finish\" command\n\
8513 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8514 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8515 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8516 address and file/line number respectively.\n\
8518 Convenience variable \"$_\" and default examine address for \"x\"\n\
8519 are set to the address of the last breakpoint listed unless the command\n\
8520 is prefixed with \"server \".\n\n\
8521 Convenience variable \"$bpnum\" contains the number of the last\n\
8523 &maintenanceinfolist
);
8525 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8526 Set catchpoints to catch events."),
8527 &catch_cmdlist
, "catch ",
8528 0/*allow-unknown*/, &cmdlist
);
8530 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8531 Set temporary catchpoints to catch events."),
8532 &tcatch_cmdlist
, "tcatch ",
8533 0/*allow-unknown*/, &cmdlist
);
8535 /* Add catch and tcatch sub-commands. */
8536 add_catch_command ("catch", _("\
8537 Catch an exception, when caught.\n\
8538 With an argument, catch only exceptions with the given name."),
8539 catch_catch_command
,
8542 add_catch_command ("throw", _("\
8543 Catch an exception, when thrown.\n\
8544 With an argument, catch only exceptions with the given name."),
8545 catch_throw_command
,
8548 add_catch_command ("fork", _("Catch calls to fork."),
8549 catch_fork_command_1
,
8550 (void *) (uintptr_t) catch_fork_permanent
,
8551 (void *) (uintptr_t) catch_fork_temporary
);
8552 add_catch_command ("vfork", _("Catch calls to vfork."),
8553 catch_fork_command_1
,
8554 (void *) (uintptr_t) catch_vfork_permanent
,
8555 (void *) (uintptr_t) catch_vfork_temporary
);
8556 add_catch_command ("exec", _("Catch calls to exec."),
8557 catch_exec_command_1
,
8560 add_catch_command ("load", _("\
8561 Catch library loads.\n\
8562 With an argument, catch only loads of that library."),
8563 catch_load_command_1
,
8566 add_catch_command ("unload", _("\
8567 Catch library unloads.\n\
8568 With an argument, catch only unloads of that library."),
8569 catch_unload_command_1
,
8572 add_catch_command ("exception", _("\
8573 Catch Ada exceptions, when raised.\n\
8574 With an argument, catch only exceptions with the given name."),
8575 catch_ada_exception_command
,
8578 add_catch_command ("assert", _("\
8579 Catch failed Ada assertions, when raised.\n\
8580 With an argument, catch only exceptions with the given name."),
8581 catch_assert_command
,
8585 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8586 Set a watchpoint for an expression.\n\
8587 A watchpoint stops execution of your program whenever the value of\n\
8588 an expression changes."));
8589 set_cmd_completer (c
, expression_completer
);
8591 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8592 Set a read watchpoint for an expression.\n\
8593 A watchpoint stops execution of your program whenever the value of\n\
8594 an expression is read."));
8595 set_cmd_completer (c
, expression_completer
);
8597 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8598 Set a watchpoint for an expression.\n\
8599 A watchpoint stops execution of your program whenever the value of\n\
8600 an expression is either read or written."));
8601 set_cmd_completer (c
, expression_completer
);
8603 add_info ("watchpoints", breakpoints_info
,
8604 _("Synonym for ``info breakpoints''."));
8607 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8608 respond to changes - contrary to the description. */
8609 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8610 &can_use_hw_watchpoints
, _("\
8611 Set debugger's willingness to use watchpoint hardware."), _("\
8612 Show debugger's willingness to use watchpoint hardware."), _("\
8613 If zero, gdb will not use hardware for new watchpoints, even if\n\
8614 such is available. (However, any hardware watchpoints that were\n\
8615 created before setting this to nonzero, will continue to use watchpoint\n\
8618 show_can_use_hw_watchpoints
,
8619 &setlist
, &showlist
);
8621 can_use_hw_watchpoints
= 1;
8623 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8624 Breakpoint specific settings\n\
8625 Configure various breakpoint-specific variables such as\n\
8626 pending breakpoint behavior"),
8627 &breakpoint_set_cmdlist
, "set breakpoint ",
8628 0/*allow-unknown*/, &setlist
);
8629 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8630 Breakpoint specific settings\n\
8631 Configure various breakpoint-specific variables such as\n\
8632 pending breakpoint behavior"),
8633 &breakpoint_show_cmdlist
, "show breakpoint ",
8634 0/*allow-unknown*/, &showlist
);
8636 add_setshow_auto_boolean_cmd ("pending", no_class
,
8637 &pending_break_support
, _("\
8638 Set debugger's behavior regarding pending breakpoints."), _("\
8639 Show debugger's behavior regarding pending breakpoints."), _("\
8640 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8641 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8642 an error. If auto, an unrecognized breakpoint location results in a\n\
8643 user-query to see if a pending breakpoint should be created."),
8645 show_pending_break_support
,
8646 &breakpoint_set_cmdlist
,
8647 &breakpoint_show_cmdlist
);
8649 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8651 add_setshow_boolean_cmd ("auto-hw", no_class
,
8652 &automatic_hardware_breakpoints
, _("\
8653 Set automatic usage of hardware breakpoints."), _("\
8654 Show automatic usage of hardware breakpoints."), _("\
8655 If set, the debugger will automatically use hardware breakpoints for\n\
8656 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8657 a warning will be emitted for such breakpoints."),
8659 show_automatic_hardware_breakpoints
,
8660 &breakpoint_set_cmdlist
,
8661 &breakpoint_show_cmdlist
);
8663 add_setshow_enum_cmd ("always-inserted", class_support
,
8664 always_inserted_enums
, &always_inserted_mode
, _("\
8665 Set mode for inserting breakpoints."), _("\
8666 Show mode for inserting breakpoints."), _("\
8667 When this mode is off, breakpoints are inserted in inferior when it is\n\
8668 resumed, and removed when execution stops. When this mode is on,\n\
8669 breakpoints are inserted immediately and removed only when the user\n\
8670 deletes the breakpoint. When this mode is auto (which is the default),\n\
8671 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8672 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8673 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8674 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8676 &show_always_inserted_mode
,
8677 &breakpoint_set_cmdlist
,
8678 &breakpoint_show_cmdlist
);
8680 automatic_hardware_breakpoints
= 1;