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/>. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
44 #include "completer.h"
47 #include "cli/cli-script.h"
48 #include "gdb_assert.h"
53 #include "exceptions.h"
58 #include "gdb-events.h"
59 #include "mi/mi-common.h"
61 /* Prototypes for local functions. */
63 static void until_break_command_continuation (struct continuation_arg
*arg
);
65 static void catch_command_1 (char *, int, int);
67 static void enable_delete_command (char *, int);
69 static void enable_delete_breakpoint (struct breakpoint
*);
71 static void enable_once_command (char *, int);
73 static void enable_once_breakpoint (struct breakpoint
*);
75 static void disable_command (char *, int);
77 static void enable_command (char *, int);
79 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
81 static void ignore_command (char *, int);
83 static int breakpoint_re_set_one (void *);
85 static void clear_command (char *, int);
87 static void catch_command (char *, int);
89 static void watch_command (char *, int);
91 static int can_use_hardware_watchpoint (struct value
*);
93 static void break_command_1 (char *, int, int);
95 static void mention (struct breakpoint
*);
97 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
99 static void check_duplicates (struct breakpoint
*);
101 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
103 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
106 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
108 static void breakpoints_info (char *, int);
110 static void breakpoint_1 (int, int);
112 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
114 static int breakpoint_cond_eval (void *);
116 static void cleanup_executing_breakpoints (void *);
118 static void commands_command (char *, int);
120 static void condition_command (char *, int);
122 static int get_number_trailer (char **, int);
124 void set_breakpoint_count (int);
133 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
135 static enum print_stop_action
print_it_typical (bpstat
);
137 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 enum exception_event_kind kind
;
144 args_for_catchpoint_enable
;
146 static int watchpoint_check (void *);
148 static void maintenance_info_breakpoints (char *, int);
150 static void create_longjmp_breakpoint (char *);
152 static void create_overlay_event_breakpoint (char *);
154 static int hw_breakpoint_used_count (void);
156 static int hw_watchpoint_used_count (enum bptype
, int *);
158 static void hbreak_command (char *, int);
160 static void thbreak_command (char *, int);
162 static void watch_command_1 (char *, int, int);
164 static void rwatch_command (char *, int);
166 static void awatch_command (char *, int);
168 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
170 static void create_fork_vfork_event_catchpoint (int tempflag
,
172 enum bptype bp_kind
);
174 static void stop_command (char *arg
, int from_tty
);
176 static void stopin_command (char *arg
, int from_tty
);
178 static void stopat_command (char *arg
, int from_tty
);
180 static char *ep_find_event_name_end (char *arg
);
182 static char *ep_parse_optional_if_clause (char **arg
);
184 static char *ep_parse_optional_filename (char **arg
);
186 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
187 enum exception_event_kind ex_event
,
188 struct symtab_and_line
*sal
);
190 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
191 char *arg
, int tempflag
, int from_tty
);
193 static void tcatch_command (char *arg
, int from_tty
);
195 static void ep_skip_leading_whitespace (char **s
);
197 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
199 static void free_bp_location (struct bp_location
*loc
);
201 static void mark_breakpoints_out (void);
203 static struct bp_location
*
204 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
207 unlink_locations_from_global_list (struct breakpoint
*bpt
);
210 is_hardware_watchpoint (struct breakpoint
*bpt
);
212 /* Prototypes for exported functions. */
214 /* If FALSE, gdb will not use hardware support for watchpoints, even
215 if such is available. */
216 static int can_use_hw_watchpoints
;
219 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
220 struct cmd_list_element
*c
,
223 fprintf_filtered (file
, _("\
224 Debugger's willingness to use watchpoint hardware is %s.\n"),
228 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
229 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
230 for unrecognized breakpoint locations.
231 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
232 static enum auto_boolean pending_break_support
;
234 show_pending_break_support (struct ui_file
*file
, int from_tty
,
235 struct cmd_list_element
*c
,
238 fprintf_filtered (file
, _("\
239 Debugger's behavior regarding pending breakpoints is %s.\n"),
243 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
244 set with "break" but falling in read-only memory.
245 If 0, gdb will warn about such breakpoints, but won't automatically
246 use hardware breakpoints. */
247 static int automatic_hardware_breakpoints
;
249 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
250 struct cmd_list_element
*c
,
253 fprintf_filtered (file
, _("\
254 Automatic usage of hardware breakpoints is %s.\n"),
259 void _initialize_breakpoint (void);
261 extern int addressprint
; /* Print machine addresses? */
263 /* Are we executing breakpoint commands? */
264 static int executing_breakpoint_commands
;
266 /* Are overlay event breakpoints enabled? */
267 static int overlay_events_enabled
;
269 /* Walk the following statement or block through all breakpoints.
270 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
273 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
275 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
276 for (B = breakpoint_chain; \
277 B ? (TMP=B->next, 1): 0; \
280 /* Similar iterators for the low-level breakpoints. */
282 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
284 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
285 for (B = bp_location_chain; \
286 B ? (TMP=B->global_next, 1): 0; \
289 /* True if breakpoint hit counts should be displayed in breakpoint info. */
291 int show_breakpoint_hit_counts
= 1;
293 /* Chains of all breakpoints defined. */
295 struct breakpoint
*breakpoint_chain
;
297 struct bp_location
*bp_location_chain
;
299 /* Number of last breakpoint made. */
301 int breakpoint_count
;
303 /* Pointer to current exception event record */
304 static struct exception_event_record
*current_exception_event
;
306 /* This function returns a pointer to the string representation of the
307 pathname of the dynamically-linked library that has just been
310 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
311 or undefined results are guaranteed.
313 This string's contents are only valid immediately after the
314 inferior has stopped in the dynamic linker hook, and becomes
315 invalid as soon as the inferior is continued. Clients should make
316 a copy of this string if they wish to continue the inferior and
317 then access the string. */
319 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
320 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
323 /* This function returns a pointer to the string representation of the
324 pathname of the dynamically-linked library that has just been
327 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
328 TRUE, or undefined results are guaranteed.
330 This string's contents are only valid immediately after the
331 inferior has stopped in the dynamic linker hook, and becomes
332 invalid as soon as the inferior is continued. Clients should make
333 a copy of this string if they wish to continue the inferior and
334 then access the string. */
336 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
337 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
340 /* This function is called by the "catch load" command. It allows the
341 debugger to be notified by the dynamic linker when a specified
342 library file (or any library file, if filename is NULL) is loaded. */
344 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
345 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
346 error (_("catch of library loads not yet implemented on this platform"))
349 /* This function is called by the "catch unload" command. It allows
350 the debugger to be notified by the dynamic linker when a specified
351 library file (or any library file, if filename is NULL) is
354 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
355 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
356 error (_("catch of library unloads not yet implemented on this platform"))
359 /* Return whether a breakpoint is an active enabled breakpoint. */
361 breakpoint_enabled (struct breakpoint
*b
)
363 return (b
->enable_state
== bp_enabled
);
366 /* Set breakpoint count to NUM. */
369 set_breakpoint_count (int num
)
371 breakpoint_count
= num
;
372 set_internalvar (lookup_internalvar ("bpnum"),
373 value_from_longest (builtin_type_int
, (LONGEST
) num
));
376 /* Used in run_command to zero the hit count when a new run starts. */
379 clear_breakpoint_hit_counts (void)
381 struct breakpoint
*b
;
387 /* Default address, symtab and line to put a breakpoint at
388 for "break" command with no arg.
389 if default_breakpoint_valid is zero, the other three are
390 not valid, and "break" with no arg is an error.
392 This set by print_stack_frame, which calls set_default_breakpoint. */
394 int default_breakpoint_valid
;
395 CORE_ADDR default_breakpoint_address
;
396 struct symtab
*default_breakpoint_symtab
;
397 int default_breakpoint_line
;
399 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
400 Advance *PP after the string and any trailing whitespace.
402 Currently the string can either be a number or "$" followed by the name
403 of a convenience variable. Making it an expression wouldn't work well
404 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
406 If the string is a NULL pointer, that denotes the last breakpoint.
408 TRAILER is a character which can be found after the number; most
409 commonly this is `-'. If you don't want a trailer, use \0. */
411 get_number_trailer (char **pp
, int trailer
)
413 int retval
= 0; /* default */
417 /* Empty line means refer to the last breakpoint. */
418 return breakpoint_count
;
421 /* Make a copy of the name, so we can null-terminate it
422 to pass to lookup_internalvar(). */
427 while (isalnum (*p
) || *p
== '_')
429 varname
= (char *) alloca (p
- start
+ 1);
430 strncpy (varname
, start
, p
- start
);
431 varname
[p
- start
] = '\0';
432 val
= value_of_internalvar (lookup_internalvar (varname
));
433 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
434 retval
= (int) value_as_long (val
);
437 printf_filtered (_("Convenience variable must have integer value.\n"));
445 while (*p
>= '0' && *p
<= '9')
448 /* There is no number here. (e.g. "cond a == b"). */
450 /* Skip non-numeric token */
451 while (*p
&& !isspace((int) *p
))
453 /* Return zero, which caller must interpret as error. */
459 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
461 /* Trailing junk: return 0 and let caller print error msg. */
462 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
473 /* Like get_number_trailer, but don't allow a trailer. */
475 get_number (char **pp
)
477 return get_number_trailer (pp
, '\0');
480 /* Parse a number or a range.
481 * A number will be of the form handled by get_number.
482 * A range will be of the form <number1> - <number2>, and
483 * will represent all the integers between number1 and number2,
486 * While processing a range, this fuction is called iteratively;
487 * At each call it will return the next value in the range.
489 * At the beginning of parsing a range, the char pointer PP will
490 * be advanced past <number1> and left pointing at the '-' token.
491 * Subsequent calls will not advance the pointer until the range
492 * is completed. The call that completes the range will advance
493 * pointer PP past <number2>.
497 get_number_or_range (char **pp
)
499 static int last_retval
, end_value
;
500 static char *end_ptr
;
501 static int in_range
= 0;
505 /* Default case: pp is pointing either to a solo number,
506 or to the first number of a range. */
507 last_retval
= get_number_trailer (pp
, '-');
512 /* This is the start of a range (<number1> - <number2>).
513 Skip the '-', parse and remember the second number,
514 and also remember the end of the final token. */
518 while (isspace ((int) *end_ptr
))
519 end_ptr
++; /* skip white space */
520 end_value
= get_number (temp
);
521 if (end_value
< last_retval
)
523 error (_("inverted range"));
525 else if (end_value
== last_retval
)
527 /* degenerate range (number1 == number2). Advance the
528 token pointer so that the range will be treated as a
537 error (_("negative value"));
540 /* pp points to the '-' that betokens a range. All
541 number-parsing has already been done. Return the next
542 integer value (one greater than the saved previous value).
543 Do not advance the token pointer 'pp' until the end of range
546 if (++last_retval
== end_value
)
548 /* End of range reached; advance token pointer. */
558 /* condition N EXP -- set break condition of breakpoint N to EXP. */
561 condition_command (char *arg
, int from_tty
)
563 struct breakpoint
*b
;
568 error_no_arg (_("breakpoint number"));
571 bnum
= get_number (&p
);
573 error (_("Bad breakpoint argument: '%s'"), arg
);
576 if (b
->number
== bnum
)
578 struct bp_location
*loc
= b
->loc
;
579 for (; loc
; loc
= loc
->next
)
587 if (b
->cond_string
!= NULL
)
588 xfree (b
->cond_string
);
592 b
->cond_string
= NULL
;
594 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
599 /* I don't know if it matters whether this is the string the user
600 typed in or the decompiled expression. */
601 b
->cond_string
= savestring (arg
, strlen (arg
));
602 b
->condition_not_parsed
= 0;
603 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
606 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
608 error (_("Junk at end of expression"));
611 breakpoints_changed ();
612 breakpoint_modify_event (b
->number
);
616 error (_("No breakpoint number %d."), bnum
);
620 commands_command (char *arg
, int from_tty
)
622 struct breakpoint
*b
;
625 struct command_line
*l
;
627 /* If we allowed this, we would have problems with when to
628 free the storage, if we change the commands currently
631 if (executing_breakpoint_commands
)
632 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
635 bnum
= get_number (&p
);
638 error (_("Unexpected extra arguments following breakpoint number."));
641 if (b
->number
== bnum
)
643 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
645 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
646 l
= read_command_lines (tmpbuf
, from_tty
);
647 do_cleanups (cleanups
);
648 free_command_lines (&b
->commands
);
650 breakpoints_changed ();
651 breakpoint_modify_event (b
->number
);
654 error (_("No breakpoint number %d."), bnum
);
657 /* Like commands_command, but instead of reading the commands from
658 input stream, takes them from an already parsed command structure.
660 This is used by cli-script.c to DTRT with breakpoint commands
661 that are part of if and while bodies. */
662 enum command_control_type
663 commands_from_control_command (char *arg
, struct command_line
*cmd
)
665 struct breakpoint
*b
;
669 /* If we allowed this, we would have problems with when to
670 free the storage, if we change the commands currently
673 if (executing_breakpoint_commands
)
674 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
676 /* An empty string for the breakpoint number means the last
677 breakpoint, but get_number expects a NULL pointer. */
682 bnum
= get_number (&p
);
685 error (_("Unexpected extra arguments following breakpoint number."));
688 if (b
->number
== bnum
)
690 free_command_lines (&b
->commands
);
691 if (cmd
->body_count
!= 1)
692 error (_("Invalid \"commands\" block structure."));
693 /* We need to copy the commands because if/while will free the
694 list after it finishes execution. */
695 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
696 breakpoints_changed ();
697 breakpoint_modify_event (b
->number
);
698 return simple_control
;
700 error (_("No breakpoint number %d."), bnum
);
703 /* Like target_read_memory() but if breakpoints are inserted, return
704 the shadow contents instead of the breakpoints themselves.
706 Read "memory data" from whatever target or inferior we have.
707 Returns zero if successful, errno value if not. EIO is used
708 for address out of bounds. If breakpoints are inserted, returns
709 shadow contents, not the breakpoints themselves. From breakpoint.c. */
712 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
715 const struct bp_location
*b
;
716 CORE_ADDR bp_addr
= 0;
719 if (gdbarch_breakpoint_from_pc (current_gdbarch
, &bp_addr
, &bp_size
) == NULL
)
720 /* No breakpoints on this machine. */
721 return target_read_memory (memaddr
, myaddr
, len
);
725 if (b
->owner
->type
== bp_none
)
726 warning (_("reading through apparently deleted breakpoint #%d?"),
729 if (b
->loc_type
!= bp_loc_software_breakpoint
)
733 /* Addresses and length of the part of the breakpoint that
735 bp_addr
= b
->target_info
.placed_address
;
736 bp_size
= b
->target_info
.shadow_len
;
738 /* bp isn't valid, or doesn't shadow memory. */
740 if (bp_addr
+ bp_size
<= memaddr
)
741 /* The breakpoint is entirely before the chunk of memory we
744 if (bp_addr
>= memaddr
+ len
)
745 /* The breakpoint is entirely after the chunk of memory we are
748 /* Copy the breakpoint from the shadow contents, and recurse for
749 the things before and after. */
751 /* Offset within shadow_contents. */
754 if (bp_addr
< memaddr
)
756 /* Only copy the second part of the breakpoint. */
757 bp_size
-= memaddr
- bp_addr
;
758 bptoffset
= memaddr
- bp_addr
;
762 if (bp_addr
+ bp_size
> memaddr
+ len
)
764 /* Only copy the first part of the breakpoint. */
765 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
768 memcpy (myaddr
+ bp_addr
- memaddr
,
769 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
771 if (bp_addr
> memaddr
)
773 /* Copy the section of memory before the breakpoint. */
774 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
779 if (bp_addr
+ bp_size
< memaddr
+ len
)
781 /* Copy the section of memory after the breakpoint. */
782 status
= read_memory_nobpt (bp_addr
+ bp_size
,
783 myaddr
+ bp_addr
+ bp_size
- memaddr
,
784 memaddr
+ len
- (bp_addr
+ bp_size
));
791 /* Nothing overlaps. Just call read_memory_noerr. */
792 return target_read_memory (memaddr
, myaddr
, len
);
796 /* A wrapper function for inserting catchpoints. */
798 insert_catchpoint (struct ui_out
*uo
, void *args
)
800 struct breakpoint
*b
= (struct breakpoint
*) args
;
806 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
809 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
812 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
815 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
821 is_hardware_watchpoint (struct breakpoint
*bpt
)
823 return (bpt
->type
== bp_hardware_watchpoint
824 || bpt
->type
== bp_read_watchpoint
825 || bpt
->type
== bp_access_watchpoint
);
828 /* Assuming that B is a hardware breakpoint:
829 - Reparse watchpoint expression, is REPARSE is non-zero
830 - Evaluate expression and store the result in B->val
831 - Update the list of values that must be watched in B->loc.
833 If the watchpoint is disabled, do nothing. If this is
834 local watchpoint that is out of scope, delete it. */
836 update_watchpoint (struct breakpoint
*b
, int reparse
)
838 int within_current_scope
;
839 struct value
*mark
= value_mark ();
840 struct frame_id saved_frame_id
;
841 struct bp_location
*loc
;
844 unlink_locations_from_global_list (b
);
845 for (loc
= b
->loc
; loc
;)
847 struct bp_location
*loc_next
= loc
->next
;
848 remove_breakpoint (loc
, mark_uninserted
);
854 if (b
->disposition
== disp_del_at_next_stop
)
857 /* Save the current frame's ID so we can restore it after
858 evaluating the watchpoint expression on its own frame. */
859 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
860 took a frame parameter, so that we didn't have to change the
862 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
864 /* Determine if the watchpoint is within scope. */
865 if (b
->exp_valid_block
== NULL
)
866 within_current_scope
= 1;
869 struct frame_info
*fi
;
870 fi
= frame_find_by_id (b
->watchpoint_frame
);
871 within_current_scope
= (fi
!= NULL
);
872 if (within_current_scope
)
876 if (within_current_scope
&& reparse
)
885 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
886 /* If the meaning of expression itself changed, the old value is
887 no longer relevant. We don't want to report a watchpoint hit
888 to the user when the old value and the new value may actually
889 be completely different objects. */
895 /* If we failed to parse the expression, for example because
896 it refers to a global variable in a not-yet-loaded shared library,
897 don't try to insert watchpoint. We don't automatically delete
898 such watchpoint, though, since failure to parse expression
899 is different from out-of-scope watchpoint. */
900 if (within_current_scope
&& b
->exp
)
902 struct value
*v
, *next
;
904 /* Evaluate the expression and make sure it's not lazy, so that
905 after target stops again, we have a non-lazy previous value
906 to compare with. Also, making the value non-lazy will fetch
907 intermediate values as needed, which we use to decide which
910 The value returned by evaluate_expression is stored in b->val.
911 In addition, we look at all values which were created
912 during evaluation, and set watchoints at addresses as needed.
913 Those values are explicitly deleted here. */
914 v
= evaluate_expression (b
->exp
);
915 /* Avoid setting b->val if it's already set. The meaning of
916 b->val is 'the last value' user saw, and we should update
917 it only if we reported that last value to user. As it
918 happens, the code that reports it updates b->val directly. */
922 value_release_to_mark (mark
);
924 /* Look at each value on the value chain. */
927 /* If it's a memory location, and GDB actually needed
928 its contents to evaluate the expression, then we
930 if (VALUE_LVAL (v
) == lval_memory
933 struct type
*vtype
= check_typedef (value_type (v
));
935 /* We only watch structs and arrays if user asked
936 for it explicitly, never if they just happen to
937 appear in the middle of some value chain. */
939 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
940 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
944 struct bp_location
*loc
, **tmp
;
946 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
947 len
= TYPE_LENGTH (value_type (v
));
949 if (b
->type
== bp_read_watchpoint
)
951 else if (b
->type
== bp_access_watchpoint
)
954 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
955 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
960 loc
->watchpoint_type
= type
;
964 next
= value_next (v
);
969 if (reparse
&& b
->cond_string
!= NULL
)
971 char *s
= b
->cond_string
;
974 xfree (b
->loc
->cond
);
977 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
980 else if (!within_current_scope
)
982 printf_filtered (_("\
983 Hardware watchpoint %d deleted because the program has left the block \n\
984 in which its expression is valid.\n"),
986 if (b
->related_breakpoint
)
987 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
988 b
->disposition
= disp_del_at_next_stop
;
991 /* Restore the selected frame. */
992 select_frame (frame_find_by_id (saved_frame_id
));
996 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
997 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
998 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1000 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1001 method for each breakpoint or catchpoint type. */
1003 insert_bp_location (struct bp_location
*bpt
,
1004 struct ui_file
*tmp_error_stream
,
1005 int *disabled_breaks
, int *process_warning
,
1006 int *hw_breakpoint_error
)
1010 if (!breakpoint_enabled (bpt
->owner
))
1013 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->inserted
|| bpt
->duplicate
)
1016 /* Initialize the target-specific information. */
1017 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1018 bpt
->target_info
.placed_address
= bpt
->address
;
1020 if (bpt
->loc_type
== bp_loc_software_breakpoint
1021 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1023 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1025 /* If the explicitly specified breakpoint type
1026 is not hardware breakpoint, check the memory map to see
1027 if the breakpoint address is in read only memory or not.
1028 Two important cases are:
1029 - location type is not hardware breakpoint, memory
1030 is readonly. We change the type of the location to
1031 hardware breakpoint.
1032 - location type is hardware breakpoint, memory is read-write.
1033 This means we've previously made the location hardware one, but
1034 then the memory map changed, so we undo.
1036 When breakpoints are removed, remove_breakpoints will
1037 use location types we've just set here, the only possible
1038 problem is that memory map has changed during running program,
1039 but it's not going to work anyway with current gdb. */
1040 struct mem_region
*mr
1041 = lookup_mem_region (bpt
->target_info
.placed_address
);
1045 if (automatic_hardware_breakpoints
)
1048 enum bp_loc_type new_type
;
1050 if (mr
->attrib
.mode
!= MEM_RW
)
1051 new_type
= bp_loc_hardware_breakpoint
;
1053 new_type
= bp_loc_software_breakpoint
;
1055 if (new_type
!= bpt
->loc_type
)
1057 static int said
= 0;
1058 bpt
->loc_type
= new_type
;
1061 fprintf_filtered (gdb_stdout
, _("\
1062 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1067 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1068 && mr
->attrib
.mode
!= MEM_RW
)
1069 warning (_("cannot set software breakpoint at readonly address %s"),
1070 paddr (bpt
->address
));
1074 /* First check to see if we have to handle an overlay. */
1075 if (overlay_debugging
== ovly_off
1076 || bpt
->section
== NULL
1077 || !(section_is_overlay (bpt
->section
)))
1079 /* No overlay handling: just set the breakpoint. */
1081 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1082 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1084 val
= target_insert_breakpoint (&bpt
->target_info
);
1088 /* This breakpoint is in an overlay section.
1089 Shall we set a breakpoint at the LMA? */
1090 if (!overlay_events_enabled
)
1092 /* Yes -- overlay event support is not active,
1093 so we must try to set a breakpoint at the LMA.
1094 This will not work for a hardware breakpoint. */
1095 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1096 warning (_("hardware breakpoint %d not supported in overlay!"),
1097 bpt
->owner
->number
);
1100 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1102 /* Set a software (trap) breakpoint at the LMA. */
1103 bpt
->overlay_target_info
= bpt
->target_info
;
1104 bpt
->overlay_target_info
.placed_address
= addr
;
1105 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1107 fprintf_unfiltered (tmp_error_stream
,
1108 "Overlay breakpoint %d failed: in ROM?",
1109 bpt
->owner
->number
);
1112 /* Shall we set a breakpoint at the VMA? */
1113 if (section_is_mapped (bpt
->section
))
1115 /* Yes. This overlay section is mapped into memory. */
1116 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1117 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1119 val
= target_insert_breakpoint (&bpt
->target_info
);
1123 /* No. This breakpoint will not be inserted.
1124 No error, but do not mark the bp as 'inserted'. */
1131 /* Can't set the breakpoint. */
1132 if (solib_address (bpt
->address
))
1134 /* See also: disable_breakpoints_in_shlibs. */
1136 bpt
->shlib_disabled
= 1;
1137 if (!*disabled_breaks
)
1139 fprintf_unfiltered (tmp_error_stream
,
1140 "Cannot insert breakpoint %d.\n",
1141 bpt
->owner
->number
);
1142 fprintf_unfiltered (tmp_error_stream
,
1143 "Temporarily disabling shared library breakpoints:\n");
1145 *disabled_breaks
= 1;
1146 fprintf_unfiltered (tmp_error_stream
,
1147 "breakpoint #%d\n", bpt
->owner
->number
);
1151 #ifdef ONE_PROCESS_WRITETEXT
1152 *process_warning
= 1;
1154 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1156 *hw_breakpoint_error
= 1;
1157 fprintf_unfiltered (tmp_error_stream
,
1158 "Cannot insert hardware breakpoint %d.\n",
1159 bpt
->owner
->number
);
1163 fprintf_unfiltered (tmp_error_stream
,
1164 "Cannot insert breakpoint %d.\n",
1165 bpt
->owner
->number
);
1166 fprintf_filtered (tmp_error_stream
,
1167 "Error accessing memory address ");
1168 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1169 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1170 safe_strerror (val
));
1181 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1182 /* NOTE drow/2003-09-08: This state only exists for removing
1183 watchpoints. It's not clear that it's necessary... */
1184 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1186 val
= target_insert_watchpoint (bpt
->address
,
1188 bpt
->watchpoint_type
);
1189 bpt
->inserted
= (val
!= -1);
1192 else if (bpt
->owner
->type
== bp_catch_fork
1193 || bpt
->owner
->type
== bp_catch_vfork
1194 || bpt
->owner
->type
== bp_catch_exec
)
1196 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1197 bpt
->owner
, RETURN_MASK_ERROR
);
1198 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1199 bpt
->owner
->number
);
1201 bpt
->owner
->enable_state
= bp_disabled
;
1205 /* We've already printed an error message if there was a problem
1206 inserting this catchpoint, and we've disabled the catchpoint,
1207 so just return success. */
1214 /* insert_breakpoints is used when starting or continuing the program.
1215 remove_breakpoints is used when the program stops.
1216 Both return zero if successful,
1217 or an `errno' value if could not write the inferior. */
1220 insert_breakpoints (void)
1222 struct breakpoint
*bpt
;
1223 struct bp_location
*b
, *temp
;
1226 int disabled_breaks
= 0;
1227 int hw_breakpoint_error
= 0;
1228 int process_warning
= 0;
1230 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1231 make_cleanup_ui_file_delete (tmp_error_stream
);
1233 /* Explicitly mark the warning -- this will only be printed if
1234 there was an error. */
1235 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1237 ALL_BREAKPOINTS (bpt
)
1238 if (is_hardware_watchpoint (bpt
))
1239 update_watchpoint (bpt
, 0 /* don't reparse */);
1241 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1243 if (!breakpoint_enabled (b
->owner
))
1246 /* There is no point inserting thread-specific breakpoints if the
1247 thread no longer exists. */
1248 if (b
->owner
->thread
!= -1
1249 && !valid_thread_id (b
->owner
->thread
))
1252 val
= insert_bp_location (b
, tmp_error_stream
,
1253 &disabled_breaks
, &process_warning
,
1254 &hw_breakpoint_error
);
1259 /* If we failed to insert all locations of a watchpoint,
1260 remove them, as half-inserted watchpoint is of limited use. */
1261 ALL_BREAKPOINTS (bpt
)
1263 int some_failed
= 0;
1264 struct bp_location
*loc
;
1266 if (!is_hardware_watchpoint (bpt
))
1269 if (bpt
->enable_state
!= bp_enabled
)
1272 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1280 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1282 remove_breakpoint (loc
, mark_uninserted
);
1284 hw_breakpoint_error
= 1;
1285 fprintf_unfiltered (tmp_error_stream
,
1286 "Could not insert hardware watchpoint %d.\n",
1294 /* If a hardware breakpoint or watchpoint was inserted, add a
1295 message about possibly exhausted resources. */
1296 if (hw_breakpoint_error
)
1298 fprintf_unfiltered (tmp_error_stream
,
1299 "Could not insert hardware breakpoints:\n\
1300 You may have requested too many hardware breakpoints/watchpoints.\n");
1302 #ifdef ONE_PROCESS_WRITETEXT
1303 if (process_warning
)
1304 fprintf_unfiltered (tmp_error_stream
,
1305 "The same program may be running in another process.");
1307 target_terminal_ours_for_output ();
1308 error_stream (tmp_error_stream
);
1313 remove_breakpoints (void)
1315 struct bp_location
*b
;
1318 ALL_BP_LOCATIONS (b
)
1322 val
= remove_breakpoint (b
, mark_uninserted
);
1331 remove_hw_watchpoints (void)
1333 struct bp_location
*b
;
1336 ALL_BP_LOCATIONS (b
)
1338 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1340 val
= remove_breakpoint (b
, mark_uninserted
);
1349 reattach_breakpoints (int pid
)
1351 struct bp_location
*b
;
1353 struct cleanup
*old_chain
= save_inferior_ptid ();
1354 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1355 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1357 make_cleanup_ui_file_delete (tmp_error_stream
);
1359 inferior_ptid
= pid_to_ptid (pid
);
1360 ALL_BP_LOCATIONS (b
)
1365 val
= insert_bp_location (b
, tmp_error_stream
,
1366 &dummy1
, &dummy2
, &dummy3
);
1369 do_cleanups (old_chain
);
1374 do_cleanups (old_chain
);
1379 update_breakpoints_after_exec (void)
1381 struct breakpoint
*b
;
1382 struct breakpoint
*temp
;
1384 /* Doing this first prevents the badness of having delete_breakpoint()
1385 write a breakpoint's current "shadow contents" to lift the bp. That
1386 shadow is NOT valid after an exec()! */
1387 mark_breakpoints_out ();
1389 ALL_BREAKPOINTS_SAFE (b
, temp
)
1391 /* Solib breakpoints must be explicitly reset after an exec(). */
1392 if (b
->type
== bp_shlib_event
)
1394 delete_breakpoint (b
);
1398 /* Thread event breakpoints must be set anew after an exec(),
1399 as must overlay event breakpoints. */
1400 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1402 delete_breakpoint (b
);
1406 /* Step-resume breakpoints are meaningless after an exec(). */
1407 if (b
->type
== bp_step_resume
)
1409 delete_breakpoint (b
);
1413 /* Don't delete an exec catchpoint, because else the inferior
1414 won't stop when it ought!
1416 Similarly, we probably ought to keep vfork catchpoints, 'cause
1417 on this target, we may not be able to stop when the vfork is
1418 seen, but only when the subsequent exec is seen. (And because
1419 deleting fork catchpoints here but not vfork catchpoints will
1420 seem mysterious to users, keep those too.) */
1421 if ((b
->type
== bp_catch_exec
) ||
1422 (b
->type
== bp_catch_vfork
) ||
1423 (b
->type
== bp_catch_fork
))
1428 /* bp_finish is a special case. The only way we ought to be able
1429 to see one of these when an exec() has happened, is if the user
1430 caught a vfork, and then said "finish". Ordinarily a finish just
1431 carries them to the call-site of the current callee, by setting
1432 a temporary bp there and resuming. But in this case, the finish
1433 will carry them entirely through the vfork & exec.
1435 We don't want to allow a bp_finish to remain inserted now. But
1436 we can't safely delete it, 'cause finish_command has a handle to
1437 the bp on a bpstat, and will later want to delete it. There's a
1438 chance (and I've seen it happen) that if we delete the bp_finish
1439 here, that its storage will get reused by the time finish_command
1440 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1441 We really must allow finish_command to delete a bp_finish.
1443 In the absense of a general solution for the "how do we know
1444 it's safe to delete something others may have handles to?"
1445 problem, what we'll do here is just uninsert the bp_finish, and
1446 let finish_command delete it.
1448 (We know the bp_finish is "doomed" in the sense that it's
1449 momentary, and will be deleted as soon as finish_command sees
1450 the inferior stopped. So it doesn't matter that the bp's
1451 address is probably bogus in the new a.out, unlike e.g., the
1452 solib breakpoints.) */
1454 if (b
->type
== bp_finish
)
1459 /* Without a symbolic address, we have little hope of the
1460 pre-exec() address meaning the same thing in the post-exec()
1462 if (b
->addr_string
== NULL
)
1464 delete_breakpoint (b
);
1468 /* FIXME what about longjmp breakpoints? Re-create them here? */
1469 create_overlay_event_breakpoint ("_ovly_debug_event");
1473 detach_breakpoints (int pid
)
1475 struct bp_location
*b
;
1477 struct cleanup
*old_chain
= save_inferior_ptid ();
1479 if (pid
== PIDGET (inferior_ptid
))
1480 error (_("Cannot detach breakpoints of inferior_ptid"));
1482 /* Set inferior_ptid; remove_breakpoint uses this global. */
1483 inferior_ptid
= pid_to_ptid (pid
);
1484 ALL_BP_LOCATIONS (b
)
1488 val
= remove_breakpoint (b
, mark_inserted
);
1491 do_cleanups (old_chain
);
1496 do_cleanups (old_chain
);
1501 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1505 if (b
->owner
->enable_state
== bp_permanent
)
1506 /* Permanent breakpoints cannot be inserted or removed. */
1509 if (b
->owner
->type
== bp_none
)
1510 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1513 if (b
->loc_type
== bp_loc_software_breakpoint
1514 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1516 /* "Normal" instruction breakpoint: either the standard
1517 trap-instruction bp (bp_breakpoint), or a
1518 bp_hardware_breakpoint. */
1520 /* First check to see if we have to handle an overlay. */
1521 if (overlay_debugging
== ovly_off
1522 || b
->section
== NULL
1523 || !(section_is_overlay (b
->section
)))
1525 /* No overlay handling: just remove the breakpoint. */
1527 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1528 val
= target_remove_hw_breakpoint (&b
->target_info
);
1530 val
= target_remove_breakpoint (&b
->target_info
);
1534 /* This breakpoint is in an overlay section.
1535 Did we set a breakpoint at the LMA? */
1536 if (!overlay_events_enabled
)
1538 /* Yes -- overlay event support is not active, so we
1539 should have set a breakpoint at the LMA. Remove it.
1541 /* Ignore any failures: if the LMA is in ROM, we will
1542 have already warned when we failed to insert it. */
1543 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1544 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1546 target_remove_breakpoint (&b
->overlay_target_info
);
1548 /* Did we set a breakpoint at the VMA?
1549 If so, we will have marked the breakpoint 'inserted'. */
1552 /* Yes -- remove it. Previously we did not bother to
1553 remove the breakpoint if the section had been
1554 unmapped, but let's not rely on that being safe. We
1555 don't know what the overlay manager might do. */
1556 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1557 val
= target_remove_hw_breakpoint (&b
->target_info
);
1559 /* However, we should remove *software* breakpoints only
1560 if the section is still mapped, or else we overwrite
1561 wrong code with the saved shadow contents. */
1562 else if (section_is_mapped (b
->section
))
1563 val
= target_remove_breakpoint (&b
->target_info
);
1569 /* No -- not inserted, so no need to remove. No error. */
1575 b
->inserted
= (is
== mark_inserted
);
1577 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1582 b
->inserted
= (is
== mark_inserted
);
1583 val
= target_remove_watchpoint (b
->address
, b
->length
,
1584 b
->watchpoint_type
);
1586 /* Failure to remove any of the hardware watchpoints comes here. */
1587 if ((is
== mark_uninserted
) && (b
->inserted
))
1588 warning (_("Could not remove hardware watchpoint %d."),
1591 else if ((b
->owner
->type
== bp_catch_fork
||
1592 b
->owner
->type
== bp_catch_vfork
||
1593 b
->owner
->type
== bp_catch_exec
)
1594 && breakpoint_enabled (b
->owner
)
1598 switch (b
->owner
->type
)
1601 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1603 case bp_catch_vfork
:
1604 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1607 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1610 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1615 b
->inserted
= (is
== mark_inserted
);
1621 /* Clear the "inserted" flag in all breakpoints. */
1624 mark_breakpoints_out (void)
1626 struct bp_location
*bpt
;
1628 ALL_BP_LOCATIONS (bpt
)
1632 /* Clear the "inserted" flag in all breakpoints and delete any
1633 breakpoints which should go away between runs of the program.
1635 Plus other such housekeeping that has to be done for breakpoints
1638 Note: this function gets called at the end of a run (by
1639 generic_mourn_inferior) and when a run begins (by
1640 init_wait_for_inferior). */
1645 breakpoint_init_inferior (enum inf_context context
)
1647 struct breakpoint
*b
, *temp
;
1648 struct bp_location
*bpt
;
1650 ALL_BP_LOCATIONS (bpt
)
1653 ALL_BREAKPOINTS_SAFE (b
, temp
)
1658 case bp_watchpoint_scope
:
1660 /* If the call dummy breakpoint is at the entry point it will
1661 cause problems when the inferior is rerun, so we better
1664 Also get rid of scope breakpoints. */
1665 delete_breakpoint (b
);
1669 case bp_hardware_watchpoint
:
1670 case bp_read_watchpoint
:
1671 case bp_access_watchpoint
:
1673 /* Likewise for watchpoints on local expressions. */
1674 if (b
->exp_valid_block
!= NULL
)
1675 delete_breakpoint (b
);
1676 else if (context
== inf_starting
)
1678 /* Reset val field to force reread of starting value
1679 in insert_breakpoints. */
1681 value_free (b
->val
);
1691 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1692 exists at PC. It returns ordinary_breakpoint_here if it's an
1693 ordinary breakpoint, or permanent_breakpoint_here if it's a
1694 permanent breakpoint.
1695 - When continuing from a location with an ordinary breakpoint, we
1696 actually single step once before calling insert_breakpoints.
1697 - When continuing from a localion with a permanent breakpoint, we
1698 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1699 the target, to advance the PC past the breakpoint. */
1701 enum breakpoint_here
1702 breakpoint_here_p (CORE_ADDR pc
)
1704 const struct bp_location
*bpt
;
1705 int any_breakpoint_here
= 0;
1707 ALL_BP_LOCATIONS (bpt
)
1709 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1710 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1713 if ((breakpoint_enabled (bpt
->owner
)
1714 || bpt
->owner
->enable_state
== bp_permanent
)
1715 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1717 if (overlay_debugging
1718 && section_is_overlay (bpt
->section
)
1719 && !section_is_mapped (bpt
->section
))
1720 continue; /* unmapped overlay -- can't be a match */
1721 else if (bpt
->owner
->enable_state
== bp_permanent
)
1722 return permanent_breakpoint_here
;
1724 any_breakpoint_here
= 1;
1728 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1732 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1733 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1734 This does not check for single-step breakpoints, which are
1735 inserted and removed using direct target manipulation. */
1738 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1740 const struct bp_location
*bpt
;
1742 ALL_BP_LOCATIONS (bpt
)
1744 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1745 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1749 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1751 if (overlay_debugging
1752 && section_is_overlay (bpt
->section
)
1753 && !section_is_mapped (bpt
->section
))
1754 continue; /* unmapped overlay -- can't be a match */
1762 /* Returns non-zero iff there's either regular breakpoint
1763 or a single step breakpoint inserted at PC. */
1766 breakpoint_inserted_here_p (CORE_ADDR pc
)
1768 if (regular_breakpoint_inserted_here_p (pc
))
1771 if (single_step_breakpoint_inserted_here_p (pc
))
1777 /* This function returns non-zero iff there is a software breakpoint
1781 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1783 const struct bp_location
*bpt
;
1784 int any_breakpoint_here
= 0;
1786 ALL_BP_LOCATIONS (bpt
)
1788 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1792 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1794 if (overlay_debugging
1795 && section_is_overlay (bpt
->section
)
1796 && !section_is_mapped (bpt
->section
))
1797 continue; /* unmapped overlay -- can't be a match */
1803 /* Also check for software single-step breakpoints. */
1804 if (single_step_breakpoint_inserted_here_p (pc
))
1810 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1811 PC is valid for process/thread PTID. */
1814 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1816 const struct bp_location
*bpt
;
1819 thread
= pid_to_thread_id (ptid
);
1821 ALL_BP_LOCATIONS (bpt
)
1823 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1824 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1827 if ((breakpoint_enabled (bpt
->owner
)
1828 || bpt
->owner
->enable_state
== bp_permanent
)
1829 && bpt
->address
== pc
1830 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1832 if (overlay_debugging
1833 && section_is_overlay (bpt
->section
)
1834 && !section_is_mapped (bpt
->section
))
1835 continue; /* unmapped overlay -- can't be a match */
1845 /* bpstat stuff. External routines' interfaces are documented
1849 ep_is_catchpoint (struct breakpoint
*ep
)
1852 (ep
->type
== bp_catch_load
)
1853 || (ep
->type
== bp_catch_unload
)
1854 || (ep
->type
== bp_catch_fork
)
1855 || (ep
->type
== bp_catch_vfork
)
1856 || (ep
->type
== bp_catch_exec
);
1858 /* ??rehrauer: Add more kinds here, as are implemented... */
1862 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1865 (ep
->type
== bp_catch_load
)
1866 || (ep
->type
== bp_catch_unload
);
1870 bpstat_free (bpstat bs
)
1872 if (bs
->old_val
!= NULL
)
1873 value_free (bs
->old_val
);
1874 free_command_lines (&bs
->commands
);
1878 /* Clear a bpstat so that it says we are not at any breakpoint.
1879 Also free any storage that is part of a bpstat. */
1882 bpstat_clear (bpstat
*bsp
)
1899 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1900 is part of the bpstat is copied as well. */
1903 bpstat_copy (bpstat bs
)
1907 bpstat retval
= NULL
;
1912 for (; bs
!= NULL
; bs
= bs
->next
)
1914 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1915 memcpy (tmp
, bs
, sizeof (*tmp
));
1916 if (bs
->commands
!= NULL
)
1917 tmp
->commands
= copy_command_lines (bs
->commands
);
1918 if (bs
->old_val
!= NULL
)
1919 tmp
->old_val
= value_copy (bs
->old_val
);
1922 /* This is the first thing in the chain. */
1932 /* Find the bpstat associated with this breakpoint */
1935 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1940 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1942 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1948 /* Find a step_resume breakpoint associated with this bpstat.
1949 (If there are multiple step_resume bp's on the list, this function
1950 will arbitrarily pick one.)
1952 It is an error to use this function if BPSTAT doesn't contain a
1953 step_resume breakpoint.
1955 See wait_for_inferior's use of this function. */
1957 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1961 gdb_assert (bsp
!= NULL
);
1963 current_thread
= pid_to_thread_id (inferior_ptid
);
1965 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1967 if ((bsp
->breakpoint_at
!= NULL
) &&
1968 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
1969 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
1970 bsp
->breakpoint_at
->owner
->thread
== -1))
1971 return bsp
->breakpoint_at
->owner
;
1974 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
1978 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
1979 at. *BSP upon return is a bpstat which points to the remaining
1980 breakpoints stopped at (but which is not guaranteed to be good for
1981 anything but further calls to bpstat_num).
1982 Return 0 if passed a bpstat which does not indicate any breakpoints.
1983 Return -1 if stopped at a breakpoint that has been deleted since
1985 Return 1 otherwise. */
1988 bpstat_num (bpstat
*bsp
, int *num
)
1990 struct breakpoint
*b
;
1993 return 0; /* No more breakpoint values */
1995 /* We assume we'll never have several bpstats that
1996 correspond to a single breakpoint -- otherwise,
1997 this function might return the same number more
1998 than once and this will look ugly. */
1999 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2000 *bsp
= (*bsp
)->next
;
2002 return -1; /* breakpoint that's been deleted since */
2004 *num
= b
->number
; /* We have its number */
2008 /* Modify BS so that the actions will not be performed. */
2011 bpstat_clear_actions (bpstat bs
)
2013 for (; bs
!= NULL
; bs
= bs
->next
)
2015 free_command_lines (&bs
->commands
);
2016 if (bs
->old_val
!= NULL
)
2018 value_free (bs
->old_val
);
2024 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2026 cleanup_executing_breakpoints (void *ignore
)
2028 executing_breakpoint_commands
= 0;
2031 /* Execute all the commands associated with all the breakpoints at this
2032 location. Any of these commands could cause the process to proceed
2033 beyond this point, etc. We look out for such changes by checking
2034 the global "breakpoint_proceeded" after each command. */
2037 bpstat_do_actions (bpstat
*bsp
)
2040 struct cleanup
*old_chain
;
2042 /* Avoid endless recursion if a `source' command is contained
2044 if (executing_breakpoint_commands
)
2047 executing_breakpoint_commands
= 1;
2048 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2051 /* Note that (as of this writing), our callers all appear to
2052 be passing us the address of global stop_bpstat. And, if
2053 our calls to execute_control_command cause the inferior to
2054 proceed, that global (and hence, *bsp) will change.
2056 We must be careful to not touch *bsp unless the inferior
2057 has not proceeded. */
2059 /* This pointer will iterate over the list of bpstat's. */
2062 breakpoint_proceeded
= 0;
2063 for (; bs
!= NULL
; bs
= bs
->next
)
2065 struct command_line
*cmd
;
2066 struct cleanup
*this_cmd_tree_chain
;
2068 /* Take ownership of the BSP's command tree, if it has one.
2070 The command tree could legitimately contain commands like
2071 'step' and 'next', which call clear_proceed_status, which
2072 frees stop_bpstat's command tree. To make sure this doesn't
2073 free the tree we're executing out from under us, we need to
2074 take ownership of the tree ourselves. Since a given bpstat's
2075 commands are only executed once, we don't need to copy it; we
2076 can clear the pointer in the bpstat, and make sure we free
2077 the tree when we're done. */
2080 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2084 execute_control_command (cmd
);
2086 if (breakpoint_proceeded
)
2092 /* We can free this command tree now. */
2093 do_cleanups (this_cmd_tree_chain
);
2095 if (breakpoint_proceeded
)
2096 /* The inferior is proceeded by the command; bomb out now.
2097 The bpstat chain has been blown away by wait_for_inferior.
2098 But since execution has stopped again, there is a new bpstat
2099 to look at, so start over. */
2102 do_cleanups (old_chain
);
2105 /* This is the normal print function for a bpstat. In the future,
2106 much of this logic could (should?) be moved to bpstat_stop_status,
2107 by having it set different print_it values.
2109 Current scheme: When we stop, bpstat_print() is called. It loops
2110 through the bpstat list of things causing this stop, calling the
2111 print_bp_stop_message function on each one. The behavior of the
2112 print_bp_stop_message function depends on the print_it field of
2113 bpstat. If such field so indicates, call this function here.
2115 Return values from this routine (ultimately used by bpstat_print()
2116 and normal_stop() to decide what to do):
2117 PRINT_NOTHING: Means we already printed all we needed to print,
2118 don't print anything else.
2119 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2120 that something to be followed by a location.
2121 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2122 that something to be followed by a location.
2123 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2126 static enum print_stop_action
2127 print_it_typical (bpstat bs
)
2129 struct cleanup
*old_chain
, *ui_out_chain
;
2130 struct breakpoint
*b
;
2131 const struct bp_location
*bl
;
2132 struct ui_stream
*stb
;
2133 stb
= ui_out_stream_new (uiout
);
2134 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2135 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2136 which has since been deleted. */
2137 if (bs
->breakpoint_at
== NULL
)
2138 return PRINT_UNKNOWN
;
2139 bl
= bs
->breakpoint_at
;
2145 case bp_hardware_breakpoint
:
2146 if (bl
->address
!= bl
->requested_address
)
2147 breakpoint_adjustment_warning (bl
->requested_address
,
2150 annotate_breakpoint (b
->number
);
2151 ui_out_text (uiout
, "\nBreakpoint ");
2152 if (ui_out_is_mi_like_p (uiout
))
2153 ui_out_field_string (uiout
, "reason",
2154 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2155 ui_out_field_int (uiout
, "bkptno", b
->number
);
2156 ui_out_text (uiout
, ", ");
2157 return PRINT_SRC_AND_LOC
;
2160 case bp_shlib_event
:
2161 /* Did we stop because the user set the stop_on_solib_events
2162 variable? (If so, we report this as a generic, "Stopped due
2163 to shlib event" message.) */
2164 printf_filtered (_("Stopped due to shared library event\n"));
2165 return PRINT_NOTHING
;
2168 case bp_thread_event
:
2169 /* Not sure how we will get here.
2170 GDB should not stop for these breakpoints. */
2171 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2172 return PRINT_NOTHING
;
2175 case bp_overlay_event
:
2176 /* By analogy with the thread event, GDB should not stop for these. */
2177 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2178 return PRINT_NOTHING
;
2182 annotate_catchpoint (b
->number
);
2183 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2185 b
->triggered_dll_pathname
);
2186 return PRINT_SRC_AND_LOC
;
2189 case bp_catch_unload
:
2190 annotate_catchpoint (b
->number
);
2191 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2193 b
->triggered_dll_pathname
);
2194 return PRINT_SRC_AND_LOC
;
2198 annotate_catchpoint (b
->number
);
2199 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2201 b
->forked_inferior_pid
);
2202 return PRINT_SRC_AND_LOC
;
2205 case bp_catch_vfork
:
2206 annotate_catchpoint (b
->number
);
2207 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2209 b
->forked_inferior_pid
);
2210 return PRINT_SRC_AND_LOC
;
2214 annotate_catchpoint (b
->number
);
2215 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2218 return PRINT_SRC_AND_LOC
;
2222 case bp_hardware_watchpoint
:
2223 if (bs
->old_val
!= NULL
)
2225 annotate_watchpoint (b
->number
);
2226 if (ui_out_is_mi_like_p (uiout
))
2229 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2231 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2232 ui_out_text (uiout
, "\nOld value = ");
2233 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2234 ui_out_field_stream (uiout
, "old", stb
);
2235 ui_out_text (uiout
, "\nNew value = ");
2236 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2237 ui_out_field_stream (uiout
, "new", stb
);
2238 do_cleanups (ui_out_chain
);
2239 ui_out_text (uiout
, "\n");
2240 value_free (bs
->old_val
);
2243 /* More than one watchpoint may have been triggered. */
2244 return PRINT_UNKNOWN
;
2247 case bp_read_watchpoint
:
2248 if (ui_out_is_mi_like_p (uiout
))
2251 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2253 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2254 ui_out_text (uiout
, "\nValue = ");
2255 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2256 ui_out_field_stream (uiout
, "value", stb
);
2257 do_cleanups (ui_out_chain
);
2258 ui_out_text (uiout
, "\n");
2259 return PRINT_UNKNOWN
;
2262 case bp_access_watchpoint
:
2263 if (bs
->old_val
!= NULL
)
2265 annotate_watchpoint (b
->number
);
2266 if (ui_out_is_mi_like_p (uiout
))
2269 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2271 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2272 ui_out_text (uiout
, "\nOld value = ");
2273 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2274 ui_out_field_stream (uiout
, "old", stb
);
2275 value_free (bs
->old_val
);
2277 ui_out_text (uiout
, "\nNew value = ");
2282 if (ui_out_is_mi_like_p (uiout
))
2285 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2286 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2287 ui_out_text (uiout
, "\nValue = ");
2289 value_print (b
->val
, stb
->stream
, 0,Val_pretty_default
);
2290 ui_out_field_stream (uiout
, "new", stb
);
2291 do_cleanups (ui_out_chain
);
2292 ui_out_text (uiout
, "\n");
2293 return PRINT_UNKNOWN
;
2296 /* Fall through, we don't deal with these types of breakpoints
2300 if (ui_out_is_mi_like_p (uiout
))
2303 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2304 return PRINT_UNKNOWN
;
2308 if (ui_out_is_mi_like_p (uiout
))
2311 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2312 return PRINT_UNKNOWN
;
2317 case bp_longjmp_resume
:
2318 case bp_step_resume
:
2319 case bp_watchpoint_scope
:
2322 return PRINT_UNKNOWN
;
2326 /* Generic routine for printing messages indicating why we
2327 stopped. The behavior of this function depends on the value
2328 'print_it' in the bpstat structure. Under some circumstances we
2329 may decide not to print anything here and delegate the task to
2332 static enum print_stop_action
2333 print_bp_stop_message (bpstat bs
)
2335 switch (bs
->print_it
)
2338 /* Nothing should be printed for this bpstat entry. */
2339 return PRINT_UNKNOWN
;
2343 /* We still want to print the frame, but we already printed the
2344 relevant messages. */
2345 return PRINT_SRC_AND_LOC
;
2348 case print_it_normal
:
2350 const struct bp_location
*bl
= bs
->breakpoint_at
;
2351 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2353 /* Normal case. Call the breakpoint's print_it method, or
2354 print_it_typical. */
2355 /* FIXME: how breakpoint can ever be NULL here? */
2356 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2357 return b
->ops
->print_it (b
);
2359 return print_it_typical (bs
);
2364 internal_error (__FILE__
, __LINE__
,
2365 _("print_bp_stop_message: unrecognized enum value"));
2370 /* Print a message indicating what happened. This is called from
2371 normal_stop(). The input to this routine is the head of the bpstat
2372 list - a list of the eventpoints that caused this stop. This
2373 routine calls the generic print routine for printing a message
2374 about reasons for stopping. This will print (for example) the
2375 "Breakpoint n," part of the output. The return value of this
2378 PRINT_UNKNOWN: Means we printed nothing
2379 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2380 code to print the location. An example is
2381 "Breakpoint 1, " which should be followed by
2383 PRINT_SRC_ONLY: Means we printed something, but there is no need
2384 to also print the location part of the message.
2385 An example is the catch/throw messages, which
2386 don't require a location appended to the end.
2387 PRINT_NOTHING: We have done some printing and we don't need any
2388 further info to be printed.*/
2390 enum print_stop_action
2391 bpstat_print (bpstat bs
)
2395 /* Maybe another breakpoint in the chain caused us to stop.
2396 (Currently all watchpoints go on the bpstat whether hit or not.
2397 That probably could (should) be changed, provided care is taken
2398 with respect to bpstat_explains_signal). */
2399 for (; bs
; bs
= bs
->next
)
2401 val
= print_bp_stop_message (bs
);
2402 if (val
== PRINT_SRC_ONLY
2403 || val
== PRINT_SRC_AND_LOC
2404 || val
== PRINT_NOTHING
)
2408 /* We reached the end of the chain, or we got a null BS to start
2409 with and nothing was printed. */
2410 return PRINT_UNKNOWN
;
2413 /* Evaluate the expression EXP and return 1 if value is zero.
2414 This is used inside a catch_errors to evaluate the breakpoint condition.
2415 The argument is a "struct expression *" that has been cast to char * to
2416 make it pass through catch_errors. */
2419 breakpoint_cond_eval (void *exp
)
2421 struct value
*mark
= value_mark ();
2422 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2423 value_free_to_mark (mark
);
2427 /* Allocate a new bpstat and chain it to the current one. */
2430 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2434 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2436 bs
->breakpoint_at
= bl
;
2437 /* If the condition is false, etc., don't do the commands. */
2438 bs
->commands
= NULL
;
2440 bs
->print_it
= print_it_normal
;
2444 /* The target has stopped with waitstatus WS. Check if any hardware
2445 watchpoints have triggered, according to the target. */
2448 watchpoints_triggered (struct target_waitstatus
*ws
)
2450 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2452 struct breakpoint
*b
;
2454 if (!stopped_by_watchpoint
)
2456 /* We were not stopped by a watchpoint. Mark all watchpoints
2457 as not triggered. */
2459 if (b
->type
== bp_hardware_watchpoint
2460 || b
->type
== bp_read_watchpoint
2461 || b
->type
== bp_access_watchpoint
)
2462 b
->watchpoint_triggered
= watch_triggered_no
;
2467 if (!target_stopped_data_address (¤t_target
, &addr
))
2469 /* We were stopped by a watchpoint, but we don't know where.
2470 Mark all watchpoints as unknown. */
2472 if (b
->type
== bp_hardware_watchpoint
2473 || b
->type
== bp_read_watchpoint
2474 || b
->type
== bp_access_watchpoint
)
2475 b
->watchpoint_triggered
= watch_triggered_unknown
;
2477 return stopped_by_watchpoint
;
2480 /* The target could report the data address. Mark watchpoints
2481 affected by this data address as triggered, and all others as not
2485 if (b
->type
== bp_hardware_watchpoint
2486 || b
->type
== bp_read_watchpoint
2487 || b
->type
== bp_access_watchpoint
)
2489 struct bp_location
*loc
;
2492 b
->watchpoint_triggered
= watch_triggered_no
;
2493 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2494 /* Exact match not required. Within range is
2496 if (addr
>= loc
->address
2497 && addr
< loc
->address
+ loc
->length
)
2499 b
->watchpoint_triggered
= watch_triggered_yes
;
2507 /* Possible return values for watchpoint_check (this can't be an enum
2508 because of check_errors). */
2509 /* The watchpoint has been deleted. */
2510 #define WP_DELETED 1
2511 /* The value has changed. */
2512 #define WP_VALUE_CHANGED 2
2513 /* The value has not changed. */
2514 #define WP_VALUE_NOT_CHANGED 3
2516 #define BP_TEMPFLAG 1
2517 #define BP_HARDWAREFLAG 2
2519 /* Check watchpoint condition. */
2522 watchpoint_check (void *p
)
2524 bpstat bs
= (bpstat
) p
;
2525 struct breakpoint
*b
;
2526 struct frame_info
*fr
;
2527 int within_current_scope
;
2529 b
= bs
->breakpoint_at
->owner
;
2531 if (b
->exp_valid_block
== NULL
)
2532 within_current_scope
= 1;
2535 /* There is no current frame at this moment. If we're going to have
2536 any chance of handling watchpoints on local variables, we'll need
2537 the frame chain (so we can determine if we're in scope). */
2538 reinit_frame_cache ();
2539 fr
= frame_find_by_id (b
->watchpoint_frame
);
2540 within_current_scope
= (fr
!= NULL
);
2542 /* If we've gotten confused in the unwinder, we might have
2543 returned a frame that can't describe this variable. */
2544 if (within_current_scope
2545 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2546 within_current_scope
= 0;
2548 /* in_function_epilogue_p() returns a non-zero value if we're still
2549 in the function but the stack frame has already been invalidated.
2550 Since we can't rely on the values of local variables after the
2551 stack has been destroyed, we are treating the watchpoint in that
2552 state as `not changed' without further checking.
2554 vinschen/2003-09-04: The former implementation left out the case
2555 that the watchpoint frame couldn't be found by frame_find_by_id()
2556 because the current PC is currently in an epilogue. Calling
2557 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2558 if ((!within_current_scope
|| fr
== get_current_frame ())
2559 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2560 return WP_VALUE_NOT_CHANGED
;
2561 if (fr
&& within_current_scope
)
2562 /* If we end up stopping, the current frame will get selected
2563 in normal_stop. So this call to select_frame won't affect
2568 if (within_current_scope
)
2570 /* We use value_{,free_to_}mark because it could be a
2571 *long* time before we return to the command level and
2572 call free_all_values. We can't call free_all_values because
2573 we might be in the middle of evaluating a function call. */
2575 struct value
*mark
= value_mark ();
2576 struct value
*new_val
= evaluate_expression (b
->exp
);
2577 if (!value_equal (b
->val
, new_val
))
2579 release_value (new_val
);
2580 value_free_to_mark (mark
);
2581 bs
->old_val
= b
->val
;
2583 /* We will stop here */
2584 return WP_VALUE_CHANGED
;
2588 /* Nothing changed, don't do anything. */
2589 value_free_to_mark (mark
);
2590 /* We won't stop here */
2591 return WP_VALUE_NOT_CHANGED
;
2596 /* This seems like the only logical thing to do because
2597 if we temporarily ignored the watchpoint, then when
2598 we reenter the block in which it is valid it contains
2599 garbage (in the case of a function, it may have two
2600 garbage values, one before and one after the prologue).
2601 So we can't even detect the first assignment to it and
2602 watch after that (since the garbage may or may not equal
2603 the first value assigned). */
2604 /* We print all the stop information in print_it_typical(), but
2605 in this case, by the time we call print_it_typical() this bp
2606 will be deleted already. So we have no choice but print the
2607 information here. */
2608 if (ui_out_is_mi_like_p (uiout
))
2610 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2611 ui_out_text (uiout
, "\nWatchpoint ");
2612 ui_out_field_int (uiout
, "wpnum", b
->number
);
2613 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2614 which its expression is valid.\n");
2616 if (b
->related_breakpoint
)
2617 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2618 b
->disposition
= disp_del_at_next_stop
;
2624 /* Get a bpstat associated with having just stopped at address
2625 BP_ADDR in thread PTID.
2627 Determine whether we stopped at a breakpoint, etc, or whether we
2628 don't understand this stop. Result is a chain of bpstat's such that:
2630 if we don't understand the stop, the result is a null pointer.
2632 if we understand why we stopped, the result is not null.
2634 Each element of the chain refers to a particular breakpoint or
2635 watchpoint at which we have stopped. (We may have stopped for
2636 several reasons concurrently.)
2638 Each element of the chain has valid next, breakpoint_at,
2639 commands, FIXME??? fields. */
2642 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2644 struct breakpoint
*b
= NULL
;
2645 const struct bp_location
*bl
;
2646 /* Root of the chain of bpstat's */
2647 struct bpstats root_bs
[1];
2648 /* Pointer to the last thing in the chain currently. */
2649 bpstat bs
= root_bs
;
2650 int thread_id
= pid_to_thread_id (ptid
);
2652 ALL_BP_LOCATIONS (bl
)
2656 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2659 if (b
->type
!= bp_watchpoint
2660 && b
->type
!= bp_hardware_watchpoint
2661 && b
->type
!= bp_read_watchpoint
2662 && b
->type
!= bp_access_watchpoint
2663 && b
->type
!= bp_hardware_breakpoint
2664 && b
->type
!= bp_catch_fork
2665 && b
->type
!= bp_catch_vfork
2666 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2668 if (bl
->address
!= bp_addr
) /* address doesn't match */
2670 if (overlay_debugging
/* unmapped overlay section */
2671 && section_is_overlay (bl
->section
)
2672 && !section_is_mapped (bl
->section
))
2676 /* Continuable hardware watchpoints are treated as non-existent if the
2677 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2678 some data address). Otherwise gdb won't stop on a break instruction
2679 in the code (not from a breakpoint) when a hardware watchpoint has
2680 been defined. Also skip watchpoints which we know did not trigger
2681 (did not match the data address). */
2683 if ((b
->type
== bp_hardware_watchpoint
2684 || b
->type
== bp_read_watchpoint
2685 || b
->type
== bp_access_watchpoint
)
2686 && b
->watchpoint_triggered
== watch_triggered_no
)
2689 if (b
->type
== bp_hardware_breakpoint
)
2691 if (bl
->address
!= bp_addr
)
2693 if (overlay_debugging
/* unmapped overlay section */
2694 && section_is_overlay (bl
->section
)
2695 && !section_is_mapped (bl
->section
))
2699 /* Is this a catchpoint of a load or unload? If so, did we
2700 get a load or unload of the specified library? If not,
2702 if ((b
->type
== bp_catch_load
)
2703 #if defined(SOLIB_HAVE_LOAD_EVENT)
2704 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2705 || ((b
->dll_pathname
!= NULL
)
2706 && (strcmp (b
->dll_pathname
,
2707 SOLIB_LOADED_LIBRARY_PATHNAME (
2708 PIDGET (inferior_ptid
)))
2714 if ((b
->type
== bp_catch_unload
)
2715 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2716 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2717 || ((b
->dll_pathname
!= NULL
)
2718 && (strcmp (b
->dll_pathname
,
2719 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2720 PIDGET (inferior_ptid
)))
2726 if ((b
->type
== bp_catch_fork
)
2727 && !inferior_has_forked (PIDGET (inferior_ptid
),
2728 &b
->forked_inferior_pid
))
2731 if ((b
->type
== bp_catch_vfork
)
2732 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2733 &b
->forked_inferior_pid
))
2736 if ((b
->type
== bp_catch_exec
)
2737 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2740 /* For hardware watchpoints, we look only at the first location.
2741 The watchpoint_check function will work on entire expression,
2742 not the individual locations. For read watchopints, the
2743 watchpoints_triggered function have checked all locations
2746 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2749 /* Come here if it's a watchpoint, or if the break address matches */
2751 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2753 /* Watchpoints may change this, if not found to have triggered. */
2757 if (b
->type
== bp_watchpoint
2758 || b
->type
== bp_read_watchpoint
2759 || b
->type
== bp_access_watchpoint
2760 || b
->type
== bp_hardware_watchpoint
)
2764 int must_check_value
= 0;
2766 if (b
->type
== bp_watchpoint
)
2767 /* For a software watchpoint, we must always check the
2769 must_check_value
= 1;
2770 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2771 /* We have a hardware watchpoint (read, write, or access)
2772 and the target earlier reported an address watched by
2774 must_check_value
= 1;
2775 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2776 && b
->type
== bp_hardware_watchpoint
)
2777 /* We were stopped by a hardware watchpoint, but the target could
2778 not report the data address. We must check the watchpoint's
2779 value. Access and read watchpoints are out of luck; without
2780 a data address, we can't figure it out. */
2781 must_check_value
= 1;
2783 if (must_check_value
)
2785 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2787 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2788 int e
= catch_errors (watchpoint_check
, bs
, message
,
2790 do_cleanups (cleanups
);
2794 /* We've already printed what needs to be printed. */
2795 bs
->print_it
= print_it_done
;
2798 case WP_VALUE_CHANGED
:
2799 if (b
->type
== bp_read_watchpoint
)
2801 /* Don't stop: read watchpoints shouldn't fire if
2802 the value has changed. This is for targets
2803 which cannot set read-only watchpoints. */
2804 bs
->print_it
= print_it_noop
;
2810 case WP_VALUE_NOT_CHANGED
:
2811 if (b
->type
== bp_hardware_watchpoint
2812 || b
->type
== bp_watchpoint
)
2814 /* Don't stop: write watchpoints shouldn't fire if
2815 the value hasn't changed. */
2816 bs
->print_it
= print_it_noop
;
2826 /* Error from catch_errors. */
2827 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2828 if (b
->related_breakpoint
)
2829 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2830 b
->disposition
= disp_del_at_next_stop
;
2831 /* We've already printed what needs to be printed. */
2832 bs
->print_it
= print_it_done
;
2836 else /* must_check_value == 0 */
2838 /* This is a case where some watchpoint(s) triggered, but
2839 not at the address of this watchpoint, or else no
2840 watchpoint triggered after all. So don't print
2841 anything for this watchpoint. */
2842 bs
->print_it
= print_it_noop
;
2849 /* By definition, an encountered breakpoint is a triggered
2854 if (frame_id_p (b
->frame_id
)
2855 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2859 int value_is_zero
= 0;
2861 /* If this is a scope breakpoint, mark the associated
2862 watchpoint as triggered so that we will handle the
2863 out-of-scope event. We'll get to the watchpoint next
2865 if (b
->type
== bp_watchpoint_scope
)
2866 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2868 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2870 /* Need to select the frame, with all that implies
2871 so that the conditions will have the right context. */
2872 select_frame (get_current_frame ());
2874 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2875 "Error in testing breakpoint condition:\n",
2877 /* FIXME-someday, should give breakpoint # */
2880 if (bl
->cond
&& value_is_zero
)
2883 /* Don't consider this a hit. */
2886 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2889 /* Don't consider this a hit. */
2892 else if (b
->ignore_count
> 0)
2895 annotate_ignore_count_change ();
2898 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2899 /* We do not stop for these. */
2903 /* We will stop here */
2904 if (b
->disposition
== disp_disable
)
2905 b
->enable_state
= bp_disabled
;
2908 bs
->commands
= b
->commands
;
2910 (strcmp ("silent", bs
->commands
->line
) == 0
2911 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2913 bs
->commands
= bs
->commands
->next
;
2916 bs
->commands
= copy_command_lines (bs
->commands
);
2919 /* Print nothing for this entry if we dont stop or if we dont print. */
2920 if (bs
->stop
== 0 || bs
->print
== 0)
2921 bs
->print_it
= print_it_noop
;
2924 bs
->next
= NULL
; /* Terminate the chain */
2925 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2927 /* If we aren't stopping, the value of some hardware watchpoint may
2928 not have changed, but the intermediate memory locations we are
2929 watching may have. Don't bother if we're stopping; this will get
2931 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2936 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2938 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
2939 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
2940 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
2942 /* remove/insert can invalidate bs->breakpoint_at, if this
2943 location is no longer used by the watchpoint. Prevent
2944 further code from trying to use it. */
2945 bs
->breakpoint_at
= NULL
;
2946 remove_breakpoints ();
2947 insert_breakpoints ();
2951 return root_bs
->next
;
2954 /* Tell what to do about this bpstat. */
2956 bpstat_what (bpstat bs
)
2958 /* Classify each bpstat as one of the following. */
2961 /* This bpstat element has no effect on the main_action. */
2964 /* There was a watchpoint, stop but don't print. */
2967 /* There was a watchpoint, stop and print. */
2970 /* There was a breakpoint but we're not stopping. */
2973 /* There was a breakpoint, stop but don't print. */
2976 /* There was a breakpoint, stop and print. */
2979 /* We hit the longjmp breakpoint. */
2982 /* We hit the longjmp_resume breakpoint. */
2985 /* We hit the step_resume breakpoint. */
2988 /* We hit the shared library event breakpoint. */
2991 /* We caught a shared library event. */
2994 /* This is just used to count how many enums there are. */
2998 /* Here is the table which drives this routine. So that we can
2999 format it pretty, we define some abbreviations for the
3000 enum bpstat_what codes. */
3001 #define kc BPSTAT_WHAT_KEEP_CHECKING
3002 #define ss BPSTAT_WHAT_STOP_SILENT
3003 #define sn BPSTAT_WHAT_STOP_NOISY
3004 #define sgl BPSTAT_WHAT_SINGLE
3005 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3006 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3007 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3008 #define sr BPSTAT_WHAT_STEP_RESUME
3009 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3010 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3012 /* "Can't happen." Might want to print an error message.
3013 abort() is not out of the question, but chances are GDB is just
3014 a bit confused, not unusable. */
3015 #define err BPSTAT_WHAT_STOP_NOISY
3017 /* Given an old action and a class, come up with a new action. */
3018 /* One interesting property of this table is that wp_silent is the same
3019 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3020 after stopping, the check for whether to step over a breakpoint
3021 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3022 reference to how we stopped. We retain separate wp_silent and
3023 bp_silent codes in case we want to change that someday.
3025 Another possibly interesting property of this table is that
3026 there's a partial ordering, priority-like, of the actions. Once
3027 you've decided that some action is appropriate, you'll never go
3028 back and decide something of a lower priority is better. The
3031 kc < clr sgl shl shlr slr sn sr ss
3032 sgl < clrs shl shlr slr sn sr ss
3033 slr < err shl shlr sn sr ss
3034 clr < clrs err shl shlr sn sr ss
3035 clrs < err shl shlr sn sr ss
3042 What I think this means is that we don't need a damned table
3043 here. If you just put the rows and columns in the right order,
3044 it'd look awfully regular. We could simply walk the bpstat list
3045 and choose the highest priority action we find, with a little
3046 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3047 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3048 is messy anyway). */
3050 /* step_resume entries: a step resume breakpoint overrides another
3051 breakpoint of signal handling (see comment in wait_for_inferior
3052 at where we set the step_resume breakpoint). */
3054 static const enum bpstat_what_main_action
3055 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3058 /* kc ss sn sgl slr clr clrs sr shl shlr
3061 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3063 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3065 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3067 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3069 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3071 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3073 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3075 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3077 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3079 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3081 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3096 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3097 struct bpstat_what retval
;
3099 retval
.call_dummy
= 0;
3100 for (; bs
!= NULL
; bs
= bs
->next
)
3102 enum class bs_class
= no_effect
;
3103 if (bs
->breakpoint_at
== NULL
)
3104 /* I suspect this can happen if it was a momentary breakpoint
3105 which has since been deleted. */
3107 switch (bs
->breakpoint_at
->owner
->type
)
3113 case bp_hardware_breakpoint
:
3119 bs_class
= bp_noisy
;
3121 bs_class
= bp_silent
;
3124 bs_class
= bp_nostop
;
3127 case bp_hardware_watchpoint
:
3128 case bp_read_watchpoint
:
3129 case bp_access_watchpoint
:
3133 bs_class
= wp_noisy
;
3135 bs_class
= wp_silent
;
3138 /* There was a watchpoint, but we're not stopping.
3139 This requires no further action. */
3140 bs_class
= no_effect
;
3143 bs_class
= long_jump
;
3145 case bp_longjmp_resume
:
3146 bs_class
= long_resume
;
3148 case bp_step_resume
:
3151 bs_class
= step_resume
;
3154 /* It is for the wrong frame. */
3155 bs_class
= bp_nostop
;
3157 case bp_watchpoint_scope
:
3158 bs_class
= bp_nostop
;
3160 case bp_shlib_event
:
3161 bs_class
= shlib_event
;
3163 case bp_thread_event
:
3164 case bp_overlay_event
:
3165 bs_class
= bp_nostop
;
3168 case bp_catch_unload
:
3169 /* Only if this catchpoint triggered should we cause the
3170 step-out-of-dld behaviour. Otherwise, we ignore this
3173 bs_class
= catch_shlib_event
;
3175 bs_class
= no_effect
;
3178 case bp_catch_vfork
:
3183 bs_class
= bp_noisy
;
3185 bs_class
= bp_silent
;
3188 /* There was a catchpoint, but we're not stopping.
3189 This requires no further action. */
3190 bs_class
= no_effect
;
3193 /* Make sure the action is stop (silent or noisy),
3194 so infrun.c pops the dummy frame. */
3195 bs_class
= bp_silent
;
3196 retval
.call_dummy
= 1;
3199 current_action
= table
[(int) bs_class
][(int) current_action
];
3201 retval
.main_action
= current_action
;
3205 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3206 without hardware support). This isn't related to a specific bpstat,
3207 just to things like whether watchpoints are set. */
3210 bpstat_should_step (void)
3212 struct breakpoint
*b
;
3214 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3221 /* Given a bpstat that records zero or more triggered eventpoints, this
3222 function returns another bpstat which contains only the catchpoints
3223 on that first list, if any. */
3225 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3227 struct bpstats root_bs
[1];
3228 bpstat bs
= root_bs
;
3229 struct breakpoint
*ep
;
3232 bpstat_clear (cp_list
);
3233 root_bs
->next
= NULL
;
3235 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3237 /* Is this eventpoint a catchpoint? If not, ignore it. */
3238 ep
= ep_list
->breakpoint_at
->owner
;
3241 if ((ep
->type
!= bp_catch_load
) &&
3242 (ep
->type
!= bp_catch_unload
))
3243 /* pai: (temp) ADD fork/vfork here!! */
3246 /* Yes; add it to the list. */
3247 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3252 #if defined(SOLIB_ADD)
3253 /* Also, for each triggered catchpoint, tag it with the name of
3254 the library that caused this trigger. (We copy the name now,
3255 because it's only guaranteed to be available NOW, when the
3256 catchpoint triggers. Clients who may wish to know the name
3257 later must get it from the catchpoint itself.) */
3258 if (ep
->triggered_dll_pathname
!= NULL
)
3259 xfree (ep
->triggered_dll_pathname
);
3260 if (ep
->type
== bp_catch_load
)
3261 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3262 PIDGET (inferior_ptid
));
3264 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3265 PIDGET (inferior_ptid
));
3267 dll_pathname
= NULL
;
3271 ep
->triggered_dll_pathname
= (char *)
3272 xmalloc (strlen (dll_pathname
) + 1);
3273 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3276 ep
->triggered_dll_pathname
= NULL
;
3282 static void print_breakpoint_location (struct breakpoint
*b
,
3283 struct bp_location
*loc
,
3285 struct ui_stream
*stb
)
3290 = find_pc_sect_function (loc
->address
, loc
->section
);
3293 ui_out_text (uiout
, "in ");
3294 ui_out_field_string (uiout
, "func",
3295 SYMBOL_PRINT_NAME (sym
));
3296 ui_out_wrap_hint (uiout
, wrap_indent
);
3297 ui_out_text (uiout
, " at ");
3299 ui_out_field_string (uiout
, "file", b
->source_file
);
3300 ui_out_text (uiout
, ":");
3302 if (ui_out_is_mi_like_p (uiout
))
3304 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3305 char *fullname
= symtab_to_fullname (sal
.symtab
);
3308 ui_out_field_string (uiout
, "fullname", fullname
);
3311 ui_out_field_int (uiout
, "line", b
->line_number
);
3315 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3319 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3320 ui_out_field_stream (uiout
, "at", stb
);
3324 /* Print B to gdb_stdout. */
3326 print_one_breakpoint_location (struct breakpoint
*b
,
3327 struct bp_location
*loc
,
3329 CORE_ADDR
*last_addr
)
3331 struct command_line
*l
;
3333 struct ep_type_description
3338 static struct ep_type_description bptypes
[] =
3340 {bp_none
, "?deleted?"},
3341 {bp_breakpoint
, "breakpoint"},
3342 {bp_hardware_breakpoint
, "hw breakpoint"},
3343 {bp_until
, "until"},
3344 {bp_finish
, "finish"},
3345 {bp_watchpoint
, "watchpoint"},
3346 {bp_hardware_watchpoint
, "hw watchpoint"},
3347 {bp_read_watchpoint
, "read watchpoint"},
3348 {bp_access_watchpoint
, "acc watchpoint"},
3349 {bp_longjmp
, "longjmp"},
3350 {bp_longjmp_resume
, "longjmp resume"},
3351 {bp_step_resume
, "step resume"},
3352 {bp_watchpoint_scope
, "watchpoint scope"},
3353 {bp_call_dummy
, "call dummy"},
3354 {bp_shlib_event
, "shlib events"},
3355 {bp_thread_event
, "thread events"},
3356 {bp_overlay_event
, "overlay events"},
3357 {bp_catch_load
, "catch load"},
3358 {bp_catch_unload
, "catch unload"},
3359 {bp_catch_fork
, "catch fork"},
3360 {bp_catch_vfork
, "catch vfork"},
3361 {bp_catch_exec
, "catch exec"}
3364 static char *bpdisps
[] =
3365 {"del", "dstp", "dis", "keep"};
3366 static char bpenables
[] = "nynny";
3367 char wrap_indent
[80];
3368 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3369 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3370 struct cleanup
*bkpt_chain
;
3372 int header_of_multiple
= 0;
3373 int part_of_multiple
= (loc
!= NULL
);
3375 gdb_assert (!loc
|| loc_number
!= 0);
3376 /* See comment in print_one_breakpoint concerning
3377 treatment of breakpoints with single disabled
3381 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3382 header_of_multiple
= 1;
3387 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3391 if (part_of_multiple
)
3394 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3395 ui_out_field_string (uiout
, "number", formatted
);
3400 ui_out_field_int (uiout
, "number", b
->number
);
3405 if (part_of_multiple
)
3406 ui_out_field_skip (uiout
, "type");
3409 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3410 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3411 internal_error (__FILE__
, __LINE__
,
3412 _("bptypes table does not describe type #%d."),
3414 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3419 if (part_of_multiple
)
3420 ui_out_field_skip (uiout
, "disp");
3422 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3427 if (part_of_multiple
)
3428 ui_out_field_string (uiout
, "enabled",
3430 ? (loc
->enabled
? "y(p)" : "n(p)")
3431 : (loc
->enabled
? "y" : "n"));
3434 int pending
= (b
->loc
== NULL
|| b
->loc
->shlib_disabled
);
3435 /* For header of multiple, there's no point showing pending
3436 state -- it will be apparent from the locations. */
3437 if (header_of_multiple
)
3439 ui_out_field_fmt (uiout
, "enabled", "%c%s",
3440 bpenables
[(int) b
->enable_state
],
3441 pending
? "(p)" : "");
3443 ui_out_spaces (uiout
, 3);
3448 strcpy (wrap_indent
, " ");
3451 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3452 strcat (wrap_indent
, " ");
3454 strcat (wrap_indent
, " ");
3457 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3459 /* Although the print_one can possibly print
3460 all locations, calling it here is not likely
3461 to get any nice result. So, make sure there's
3462 just one location. */
3463 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3464 b
->ops
->print_one (b
, last_addr
);
3470 internal_error (__FILE__
, __LINE__
,
3471 _("print_one_breakpoint: bp_none encountered\n"));
3475 case bp_hardware_watchpoint
:
3476 case bp_read_watchpoint
:
3477 case bp_access_watchpoint
:
3478 /* Field 4, the address, is omitted (which makes the columns
3479 not line up too nicely with the headers, but the effect
3480 is relatively readable). */
3482 ui_out_field_skip (uiout
, "addr");
3484 print_expression (b
->exp
, stb
->stream
);
3485 ui_out_field_stream (uiout
, "what", stb
);
3489 case bp_catch_unload
:
3490 /* Field 4, the address, is omitted (which makes the columns
3491 not line up too nicely with the headers, but the effect
3492 is relatively readable). */
3494 ui_out_field_skip (uiout
, "addr");
3496 if (b
->dll_pathname
== NULL
)
3498 ui_out_field_string (uiout
, "what", "<any library>");
3499 ui_out_spaces (uiout
, 1);
3503 ui_out_text (uiout
, "library \"");
3504 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3505 ui_out_text (uiout
, "\" ");
3510 case bp_catch_vfork
:
3511 /* Field 4, the address, is omitted (which makes the columns
3512 not line up too nicely with the headers, but the effect
3513 is relatively readable). */
3515 ui_out_field_skip (uiout
, "addr");
3517 if (b
->forked_inferior_pid
!= 0)
3519 ui_out_text (uiout
, "process ");
3520 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3521 ui_out_spaces (uiout
, 1);
3526 /* Field 4, the address, is omitted (which makes the columns
3527 not line up too nicely with the headers, but the effect
3528 is relatively readable). */
3530 ui_out_field_skip (uiout
, "addr");
3532 if (b
->exec_pathname
!= NULL
)
3534 ui_out_text (uiout
, "program \"");
3535 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3536 ui_out_text (uiout
, "\" ");
3541 case bp_hardware_breakpoint
:
3545 case bp_longjmp_resume
:
3546 case bp_step_resume
:
3547 case bp_watchpoint_scope
:
3549 case bp_shlib_event
:
3550 case bp_thread_event
:
3551 case bp_overlay_event
:
3556 ui_out_field_string (uiout
, "addr", "<PENDING>");
3557 else if (header_of_multiple
)
3558 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3560 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3563 if (!header_of_multiple
)
3564 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3566 *last_addr
= b
->loc
->address
;
3570 if (!part_of_multiple
&& b
->thread
!= -1)
3572 /* FIXME: This seems to be redundant and lost here; see the
3573 "stop only in" line a little further down. */
3574 ui_out_text (uiout
, " thread ");
3575 ui_out_field_int (uiout
, "thread", b
->thread
);
3578 ui_out_text (uiout
, "\n");
3580 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3583 ui_out_text (uiout
, "\tstop only in stack frame at ");
3584 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3586 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3587 ui_out_text (uiout
, "\n");
3590 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3592 /* We do not print the condition for Ada exception catchpoints
3593 because the condition is an internal implementation detail
3594 that we do not want to expose to the user. */
3596 ui_out_text (uiout
, "\tstop only if ");
3597 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3598 ui_out_text (uiout
, "\n");
3601 if (!part_of_multiple
&& b
->thread
!= -1)
3603 /* FIXME should make an annotation for this */
3604 ui_out_text (uiout
, "\tstop only in thread ");
3605 ui_out_field_int (uiout
, "thread", b
->thread
);
3606 ui_out_text (uiout
, "\n");
3609 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3611 /* FIXME should make an annotation for this */
3612 if (ep_is_catchpoint (b
))
3613 ui_out_text (uiout
, "\tcatchpoint");
3615 ui_out_text (uiout
, "\tbreakpoint");
3616 ui_out_text (uiout
, " already hit ");
3617 ui_out_field_int (uiout
, "times", b
->hit_count
);
3618 if (b
->hit_count
== 1)
3619 ui_out_text (uiout
, " time\n");
3621 ui_out_text (uiout
, " times\n");
3624 /* Output the count also if it is zero, but only if this is
3625 mi. FIXME: Should have a better test for this. */
3626 if (ui_out_is_mi_like_p (uiout
))
3627 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3628 ui_out_field_int (uiout
, "times", b
->hit_count
);
3630 if (!part_of_multiple
&& b
->ignore_count
)
3633 ui_out_text (uiout
, "\tignore next ");
3634 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3635 ui_out_text (uiout
, " hits\n");
3638 if (!part_of_multiple
&& (l
= b
->commands
))
3640 struct cleanup
*script_chain
;
3643 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3644 print_command_lines (uiout
, l
, 4);
3645 do_cleanups (script_chain
);
3647 do_cleanups (bkpt_chain
);
3648 do_cleanups (old_chain
);
3652 print_one_breakpoint (struct breakpoint
*b
,
3653 CORE_ADDR
*last_addr
)
3655 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3657 /* If this breakpoint has custom print function,
3658 it's already printed. Otherwise, print individual
3659 locations, if any. */
3660 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3662 /* If breakpoint has a single location that is
3663 disabled, we print it as if it had
3664 several locations, since otherwise it's hard to
3665 represent "breakpoint enabled, location disabled"
3667 Note that while hardware watchpoints have
3668 several locations internally, that's no a property
3671 && !is_hardware_watchpoint (b
)
3672 && (b
->loc
->next
|| !b
->loc
->enabled
)
3673 && !ui_out_is_mi_like_p (uiout
))
3675 struct bp_location
*loc
;
3677 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3678 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3684 struct captured_breakpoint_query_args
3690 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3692 struct captured_breakpoint_query_args
*args
= data
;
3693 struct breakpoint
*b
;
3694 CORE_ADDR dummy_addr
= 0;
3697 if (args
->bnum
== b
->number
)
3699 print_one_breakpoint (b
, &dummy_addr
);
3707 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3709 struct captured_breakpoint_query_args args
;
3711 /* For the moment we don't trust print_one_breakpoint() to not throw
3713 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3714 error_message
, RETURN_MASK_ALL
) < 0)
3720 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3721 catchpoints, et.al.). */
3724 user_settable_breakpoint (const struct breakpoint
*b
)
3726 return (b
->type
== bp_breakpoint
3727 || b
->type
== bp_catch_load
3728 || b
->type
== bp_catch_unload
3729 || b
->type
== bp_catch_fork
3730 || b
->type
== bp_catch_vfork
3731 || b
->type
== bp_catch_exec
3732 || b
->type
== bp_hardware_breakpoint
3733 || b
->type
== bp_watchpoint
3734 || b
->type
== bp_read_watchpoint
3735 || b
->type
== bp_access_watchpoint
3736 || b
->type
== bp_hardware_watchpoint
);
3739 /* Print information on user settable breakpoint (watchpoint, etc)
3740 number BNUM. If BNUM is -1 print all user settable breakpoints.
3741 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3744 breakpoint_1 (int bnum
, int allflag
)
3746 struct breakpoint
*b
;
3747 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3748 int nr_printable_breakpoints
;
3749 struct cleanup
*bkpttbl_chain
;
3751 /* Compute the number of rows in the table. */
3752 nr_printable_breakpoints
= 0;
3755 || bnum
== b
->number
)
3757 if (allflag
|| user_settable_breakpoint (b
))
3758 nr_printable_breakpoints
++;
3763 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3767 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3770 if (nr_printable_breakpoints
> 0)
3771 annotate_breakpoints_headers ();
3772 if (nr_printable_breakpoints
> 0)
3774 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3775 if (nr_printable_breakpoints
> 0)
3777 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3778 if (nr_printable_breakpoints
> 0)
3780 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3781 if (nr_printable_breakpoints
> 0)
3783 ui_out_table_header (uiout
, 4, ui_left
, "enabled", "Enb"); /* 4 */
3786 if (nr_printable_breakpoints
> 0)
3788 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3789 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3791 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3793 if (nr_printable_breakpoints
> 0)
3795 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3796 ui_out_table_body (uiout
);
3797 if (nr_printable_breakpoints
> 0)
3798 annotate_breakpoints_table ();
3802 || bnum
== b
->number
)
3804 /* We only print out user settable breakpoints unless the
3806 if (allflag
|| user_settable_breakpoint (b
))
3807 print_one_breakpoint (b
, &last_addr
);
3810 do_cleanups (bkpttbl_chain
);
3812 if (nr_printable_breakpoints
== 0)
3815 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3817 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3822 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3823 that a comparison of an unsigned with -1 is always false. */
3824 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3825 set_next_address (last_addr
);
3828 /* FIXME? Should this be moved up so that it is only called when
3829 there have been breakpoints? */
3830 annotate_breakpoints_table_end ();
3834 breakpoints_info (char *bnum_exp
, int from_tty
)
3839 bnum
= parse_and_eval_long (bnum_exp
);
3841 breakpoint_1 (bnum
, 0);
3845 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3850 bnum
= parse_and_eval_long (bnum_exp
);
3852 breakpoint_1 (bnum
, 1);
3856 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
3858 struct bp_location
*bl
= b
->loc
;
3859 for (; bl
; bl
= bl
->next
)
3861 if (bl
->address
== pc
3862 && (!overlay_debugging
|| bl
->section
== section
))
3868 /* Print a message describing any breakpoints set at PC. */
3871 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3874 struct breakpoint
*b
;
3877 others
+= breakpoint_has_pc (b
, pc
, section
);
3881 printf_filtered (_("Note: breakpoint "));
3882 else /* if (others == ???) */
3883 printf_filtered (_("Note: breakpoints "));
3885 if (breakpoint_has_pc (b
, pc
, section
))
3888 printf_filtered ("%d", b
->number
);
3889 if (b
->thread
== -1 && thread
!= -1)
3890 printf_filtered (" (all threads)");
3891 else if (b
->thread
!= -1)
3892 printf_filtered (" (thread %d)", b
->thread
);
3893 printf_filtered ("%s%s ",
3894 ((b
->enable_state
== bp_disabled
||
3895 b
->enable_state
== bp_call_disabled
)
3897 : b
->enable_state
== bp_permanent
3901 : ((others
== 1) ? " and" : ""));
3903 printf_filtered (_("also set at pc "));
3904 fputs_filtered (paddress (pc
), gdb_stdout
);
3905 printf_filtered (".\n");
3909 /* Set the default place to put a breakpoint
3910 for the `break' command with no arguments. */
3913 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3916 default_breakpoint_valid
= valid
;
3917 default_breakpoint_address
= addr
;
3918 default_breakpoint_symtab
= symtab
;
3919 default_breakpoint_line
= line
;
3922 /* Return true iff it is meaningful to use the address member of
3923 BPT. For some breakpoint types, the address member is irrelevant
3924 and it makes no sense to attempt to compare it to other addresses
3925 (or use it for any other purpose either).
3927 More specifically, each of the following breakpoint types will always
3928 have a zero valued address and we don't want check_duplicates() to mark
3929 breakpoints of any of these types to be a duplicate of an actual
3930 breakpoint at address zero:
3933 bp_hardware_watchpoint
3935 bp_access_watchpoint
3942 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3944 enum bptype type
= bpt
->type
;
3946 return (type
!= bp_watchpoint
3947 && type
!= bp_hardware_watchpoint
3948 && type
!= bp_read_watchpoint
3949 && type
!= bp_access_watchpoint
3950 && type
!= bp_catch_exec
3951 && type
!= bp_longjmp_resume
3952 && type
!= bp_catch_fork
3953 && type
!= bp_catch_vfork
);
3956 /* Rescan breakpoints at the same address and section as BPT,
3957 marking the first one as "first" and any others as "duplicates".
3958 This is so that the bpt instruction is only inserted once.
3959 If we have a permanent breakpoint at the same place as BPT, make
3960 that one the official one, and the rest as duplicates. */
3963 check_duplicates_for (CORE_ADDR address
, asection
*section
)
3965 struct bp_location
*b
;
3967 struct bp_location
*perm_bp
= 0;
3969 ALL_BP_LOCATIONS (b
)
3970 if (b
->owner
->enable_state
!= bp_disabled
3971 && b
->owner
->enable_state
!= bp_call_disabled
3973 && !b
->shlib_disabled
3974 && b
->address
== address
/* address / overlay match */
3975 && (!overlay_debugging
|| b
->section
== section
)
3976 && breakpoint_address_is_meaningful (b
->owner
))
3978 /* Have we found a permanent breakpoint? */
3979 if (b
->owner
->enable_state
== bp_permanent
)
3986 b
->duplicate
= count
> 1;
3989 /* If we found a permanent breakpoint at this address, go over the
3990 list again and declare all the other breakpoints there to be the
3994 perm_bp
->duplicate
= 0;
3996 /* Permanent breakpoint should always be inserted. */
3997 if (! perm_bp
->inserted
)
3998 internal_error (__FILE__
, __LINE__
,
3999 _("allegedly permanent breakpoint is not "
4000 "actually inserted"));
4002 ALL_BP_LOCATIONS (b
)
4005 if (b
->owner
->enable_state
!= bp_disabled
4006 && b
->owner
->enable_state
!= bp_call_disabled
4007 && b
->enabled
&& !b
->shlib_disabled
4008 && b
->address
== address
/* address / overlay match */
4009 && (!overlay_debugging
|| b
->section
== section
)
4010 && breakpoint_address_is_meaningful (b
->owner
))
4013 internal_error (__FILE__
, __LINE__
,
4014 _("another breakpoint was inserted on top of "
4015 "a permanent breakpoint"));
4024 check_duplicates (struct breakpoint
*bpt
)
4026 struct bp_location
*bl
= bpt
->loc
;
4028 if (! breakpoint_address_is_meaningful (bpt
))
4031 for (; bl
; bl
= bl
->next
)
4032 check_duplicates_for (bl
->address
, bl
->section
);
4036 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4037 int bnum
, int have_bnum
)
4042 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4043 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4045 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4046 bnum
, astr1
, astr2
);
4048 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4051 /* Adjust a breakpoint's address to account for architectural constraints
4052 on breakpoint placement. Return the adjusted address. Note: Very
4053 few targets require this kind of adjustment. For most targets,
4054 this function is simply the identity function. */
4057 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4059 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4061 /* Very few targets need any kind of breakpoint adjustment. */
4064 else if (bptype
== bp_watchpoint
4065 || bptype
== bp_hardware_watchpoint
4066 || bptype
== bp_read_watchpoint
4067 || bptype
== bp_access_watchpoint
4068 || bptype
== bp_catch_fork
4069 || bptype
== bp_catch_vfork
4070 || bptype
== bp_catch_exec
)
4072 /* Watchpoints and the various bp_catch_* eventpoints should not
4073 have their addresses modified. */
4078 CORE_ADDR adjusted_bpaddr
;
4080 /* Some targets have architectural constraints on the placement
4081 of breakpoint instructions. Obtain the adjusted address. */
4082 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4085 /* An adjusted breakpoint address can significantly alter
4086 a user's expectations. Print a warning if an adjustment
4088 if (adjusted_bpaddr
!= bpaddr
)
4089 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4091 return adjusted_bpaddr
;
4095 /* Allocate a struct bp_location. */
4097 static struct bp_location
*
4098 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4100 struct bp_location
*loc
, *loc_p
;
4102 loc
= xmalloc (sizeof (struct bp_location
));
4103 memset (loc
, 0, sizeof (*loc
));
4107 loc
->shlib_disabled
= 0;
4116 case bp_longjmp_resume
:
4117 case bp_step_resume
:
4118 case bp_watchpoint_scope
:
4120 case bp_shlib_event
:
4121 case bp_thread_event
:
4122 case bp_overlay_event
:
4124 case bp_catch_unload
:
4125 loc
->loc_type
= bp_loc_software_breakpoint
;
4127 case bp_hardware_breakpoint
:
4128 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4130 case bp_hardware_watchpoint
:
4131 case bp_read_watchpoint
:
4132 case bp_access_watchpoint
:
4133 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4137 case bp_catch_vfork
:
4139 loc
->loc_type
= bp_loc_other
;
4142 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4145 /* Add this breakpoint to the end of the chain. */
4147 loc_p
= bp_location_chain
;
4149 bp_location_chain
= loc
;
4152 while (loc_p
->global_next
)
4153 loc_p
= loc_p
->global_next
;
4154 loc_p
->global_next
= loc
;
4160 static void free_bp_location (struct bp_location
*loc
)
4167 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4168 that has type BPTYPE and has no locations as yet. */
4170 static struct breakpoint
*
4171 set_raw_breakpoint_without_location (enum bptype bptype
)
4173 struct breakpoint
*b
, *b1
;
4175 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4176 memset (b
, 0, sizeof (*b
));
4179 b
->language
= current_language
->la_language
;
4180 b
->input_radix
= input_radix
;
4182 b
->enable_state
= bp_enabled
;
4185 b
->ignore_count
= 0;
4187 b
->frame_id
= null_frame_id
;
4188 b
->dll_pathname
= NULL
;
4189 b
->triggered_dll_pathname
= NULL
;
4190 b
->forked_inferior_pid
= 0;
4191 b
->exec_pathname
= NULL
;
4193 b
->condition_not_parsed
= 0;
4195 /* Add this breakpoint to the end of the chain
4196 so that a list of breakpoints will come out in order
4197 of increasing numbers. */
4199 b1
= breakpoint_chain
;
4201 breakpoint_chain
= b
;
4211 /* Initialize loc->function_name. */
4213 set_breakpoint_location_function (struct bp_location
*loc
)
4215 if (loc
->owner
->type
== bp_breakpoint
4216 || loc
->owner
->type
== bp_hardware_breakpoint
)
4218 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4220 if (loc
->function_name
)
4221 loc
->function_name
= xstrdup (loc
->function_name
);
4225 /* set_raw_breakpoint is a low level routine for allocating and
4226 partially initializing a breakpoint of type BPTYPE. The newly
4227 created breakpoint's address, section, source file name, and line
4228 number are provided by SAL. The newly created and partially
4229 initialized breakpoint is added to the breakpoint chain and
4230 is also returned as the value of this function.
4232 It is expected that the caller will complete the initialization of
4233 the newly created breakpoint struct as well as output any status
4234 information regarding the creation of a new breakpoint. In
4235 particular, set_raw_breakpoint does NOT set the breakpoint
4236 number! Care should be taken to not allow an error to occur
4237 prior to completing the initialization of the breakpoint. If this
4238 should happen, a bogus breakpoint will be left on the chain. */
4241 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4243 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4244 CORE_ADDR adjusted_address
;
4246 /* Adjust the breakpoint's address prior to allocating a location.
4247 Once we call allocate_bp_location(), that mostly uninitialized
4248 location will be placed on the location chain. Adjustment of the
4249 breakpoint may cause read_memory_nobpt() to be called and we do
4250 not want its scan of the location chain to find a breakpoint and
4251 location that's only been partially initialized. */
4252 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4254 b
->loc
= allocate_bp_location (b
, bptype
);
4255 b
->loc
->requested_address
= sal
.pc
;
4256 b
->loc
->address
= adjusted_address
;
4258 if (sal
.symtab
== NULL
)
4259 b
->source_file
= NULL
;
4261 b
->source_file
= savestring (sal
.symtab
->filename
,
4262 strlen (sal
.symtab
->filename
));
4263 b
->loc
->section
= sal
.section
;
4264 b
->line_number
= sal
.line
;
4266 set_breakpoint_location_function (b
->loc
);
4268 check_duplicates (b
);
4269 breakpoints_changed ();
4275 /* Note that the breakpoint object B describes a permanent breakpoint
4276 instruction, hard-wired into the inferior's code. */
4278 make_breakpoint_permanent (struct breakpoint
*b
)
4280 struct bp_location
*bl
;
4281 b
->enable_state
= bp_permanent
;
4283 /* By definition, permanent breakpoints are already present in the code.
4284 Mark all locations as inserted. For now, make_breakpoint_permanent
4285 is called in just one place, so it's hard to say if it's reasonable
4286 to have permanent breakpoint with multiple locations or not,
4287 but it's easy to implmement. */
4288 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4292 static struct breakpoint
*
4293 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4295 static int internal_breakpoint_number
= -1;
4296 struct symtab_and_line sal
;
4297 struct breakpoint
*b
;
4299 init_sal (&sal
); /* initialize to zeroes */
4302 sal
.section
= find_pc_overlay (sal
.pc
);
4304 b
= set_raw_breakpoint (sal
, type
);
4305 b
->number
= internal_breakpoint_number
--;
4306 b
->disposition
= disp_donttouch
;
4313 create_longjmp_breakpoint (char *func_name
)
4315 struct breakpoint
*b
;
4316 struct minimal_symbol
*m
;
4318 if (func_name
== NULL
)
4319 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4322 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4325 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4328 b
->enable_state
= bp_disabled
;
4331 b
->addr_string
= xstrdup (func_name
);
4334 /* Call this routine when stepping and nexting to enable a breakpoint
4335 if we do a longjmp(). When we hit that breakpoint, call
4336 set_longjmp_resume_breakpoint() to figure out where we are going. */
4339 enable_longjmp_breakpoint (void)
4341 struct breakpoint
*b
;
4344 if (b
->type
== bp_longjmp
)
4346 b
->enable_state
= bp_enabled
;
4347 check_duplicates (b
);
4352 disable_longjmp_breakpoint (void)
4354 struct breakpoint
*b
;
4357 if (b
->type
== bp_longjmp
4358 || b
->type
== bp_longjmp_resume
)
4360 b
->enable_state
= bp_disabled
;
4361 check_duplicates (b
);
4366 create_overlay_event_breakpoint (char *func_name
)
4368 struct breakpoint
*b
;
4369 struct minimal_symbol
*m
;
4371 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4374 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4376 b
->addr_string
= xstrdup (func_name
);
4378 if (overlay_debugging
== ovly_auto
)
4380 b
->enable_state
= bp_enabled
;
4381 overlay_events_enabled
= 1;
4385 b
->enable_state
= bp_disabled
;
4386 overlay_events_enabled
= 0;
4391 enable_overlay_breakpoints (void)
4393 struct breakpoint
*b
;
4396 if (b
->type
== bp_overlay_event
)
4398 b
->enable_state
= bp_enabled
;
4399 check_duplicates (b
);
4400 overlay_events_enabled
= 1;
4405 disable_overlay_breakpoints (void)
4407 struct breakpoint
*b
;
4410 if (b
->type
== bp_overlay_event
)
4412 b
->enable_state
= bp_disabled
;
4413 check_duplicates (b
);
4414 overlay_events_enabled
= 0;
4419 create_thread_event_breakpoint (CORE_ADDR address
)
4421 struct breakpoint
*b
;
4423 b
= create_internal_breakpoint (address
, bp_thread_event
);
4425 b
->enable_state
= bp_enabled
;
4426 /* addr_string has to be used or breakpoint_re_set will delete me. */
4427 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4433 remove_thread_event_breakpoints (void)
4435 struct breakpoint
*b
, *temp
;
4437 ALL_BREAKPOINTS_SAFE (b
, temp
)
4438 if (b
->type
== bp_thread_event
)
4439 delete_breakpoint (b
);
4442 struct captured_parse_breakpoint_args
4445 struct symtabs_and_lines
*sals_p
;
4446 char ***addr_string_p
;
4450 struct lang_and_radix
4458 remove_solib_event_breakpoints (void)
4460 struct breakpoint
*b
, *temp
;
4462 ALL_BREAKPOINTS_SAFE (b
, temp
)
4463 if (b
->type
== bp_shlib_event
)
4464 delete_breakpoint (b
);
4468 create_solib_event_breakpoint (CORE_ADDR address
)
4470 struct breakpoint
*b
;
4472 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4476 /* Disable any breakpoints that are on code in shared libraries. Only
4477 apply to enabled breakpoints, disabled ones can just stay disabled. */
4480 disable_breakpoints_in_shlibs (void)
4482 struct bp_location
*loc
;
4483 int disabled_shlib_breaks
= 0;
4485 ALL_BP_LOCATIONS (loc
)
4487 struct breakpoint
*b
= loc
->owner
;
4488 /* We apply the check to all breakpoints, including disabled
4489 for those with loc->duplicate set. This is so that when breakpoint
4490 becomes enabled, or the duplicate is removed, gdb will try to insert
4491 all breakpoints. If we don't set shlib_disabled here, we'll try
4492 to insert those breakpoints and fail. */
4493 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4494 && !loc
->shlib_disabled
4496 && PC_SOLIB (loc
->address
)
4498 && solib_address (loc
->address
)
4502 loc
->shlib_disabled
= 1;
4507 /* Disable any breakpoints that are in in an unloaded shared library. Only
4508 apply to enabled breakpoints, disabled ones can just stay disabled. */
4511 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4513 struct bp_location
*loc
;
4514 int disabled_shlib_breaks
= 0;
4516 ALL_BP_LOCATIONS (loc
)
4518 struct breakpoint
*b
= loc
->owner
;
4519 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4520 || loc
->loc_type
== bp_loc_software_breakpoint
)
4521 && !loc
->shlib_disabled
)
4524 char *so_name
= PC_SOLIB (loc
->address
);
4526 char *so_name
= solib_address (loc
->address
);
4528 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4530 loc
->shlib_disabled
= 1;
4531 /* At this point, we cannot rely on remove_breakpoint
4532 succeeding so we must mark the breakpoint as not inserted
4533 to prevent future errors occurring in remove_breakpoints. */
4535 if (!disabled_shlib_breaks
)
4537 target_terminal_ours_for_output ();
4538 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4541 disabled_shlib_breaks
= 1;
4548 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4549 enum bptype bp_kind
)
4551 struct symtab_and_line sal
;
4552 struct breakpoint
*b
;
4553 int thread
= -1; /* All threads. */
4560 b
= set_raw_breakpoint (sal
, bp_kind
);
4561 set_breakpoint_count (breakpoint_count
+ 1);
4562 b
->number
= breakpoint_count
;
4563 b
->cond_string
= (cond_string
== NULL
) ?
4564 NULL
: savestring (cond_string
, strlen (cond_string
));
4566 b
->addr_string
= NULL
;
4567 b
->enable_state
= bp_enabled
;
4568 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4569 b
->forked_inferior_pid
= 0;
4575 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4577 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4581 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4583 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4587 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4589 struct symtab_and_line sal
;
4590 struct breakpoint
*b
;
4591 int thread
= -1; /* All threads. */
4598 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4599 set_breakpoint_count (breakpoint_count
+ 1);
4600 b
->number
= breakpoint_count
;
4601 b
->cond_string
= (cond_string
== NULL
) ?
4602 NULL
: savestring (cond_string
, strlen (cond_string
));
4604 b
->addr_string
= NULL
;
4605 b
->enable_state
= bp_enabled
;
4606 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4612 hw_breakpoint_used_count (void)
4614 struct breakpoint
*b
;
4619 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4627 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4629 struct breakpoint
*b
;
4632 *other_type_used
= 0;
4635 if (breakpoint_enabled (b
))
4637 if (b
->type
== type
)
4639 else if ((b
->type
== bp_hardware_watchpoint
||
4640 b
->type
== bp_read_watchpoint
||
4641 b
->type
== bp_access_watchpoint
))
4642 *other_type_used
= 1;
4648 /* Call this after hitting the longjmp() breakpoint. Use this to set
4649 a new breakpoint at the target of the jmp_buf.
4651 FIXME - This ought to be done by setting a temporary breakpoint
4652 that gets deleted automatically... */
4655 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4657 struct breakpoint
*b
;
4660 if (b
->type
== bp_longjmp_resume
)
4662 b
->loc
->requested_address
= pc
;
4663 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4665 b
->enable_state
= bp_enabled
;
4666 b
->frame_id
= frame_id
;
4667 check_duplicates (b
);
4673 disable_watchpoints_before_interactive_call_start (void)
4675 struct breakpoint
*b
;
4679 if (((b
->type
== bp_watchpoint
)
4680 || (b
->type
== bp_hardware_watchpoint
)
4681 || (b
->type
== bp_read_watchpoint
)
4682 || (b
->type
== bp_access_watchpoint
))
4683 && breakpoint_enabled (b
))
4685 b
->enable_state
= bp_call_disabled
;
4686 check_duplicates (b
);
4692 enable_watchpoints_after_interactive_call_stop (void)
4694 struct breakpoint
*b
;
4698 if (((b
->type
== bp_watchpoint
)
4699 || (b
->type
== bp_hardware_watchpoint
)
4700 || (b
->type
== bp_read_watchpoint
)
4701 || (b
->type
== bp_access_watchpoint
))
4702 && (b
->enable_state
== bp_call_disabled
))
4704 b
->enable_state
= bp_enabled
;
4705 check_duplicates (b
);
4711 /* Set a breakpoint that will evaporate an end of command
4712 at address specified by SAL.
4713 Restrict it to frame FRAME if FRAME is nonzero. */
4716 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4719 struct breakpoint
*b
;
4720 b
= set_raw_breakpoint (sal
, type
);
4721 b
->enable_state
= bp_enabled
;
4722 b
->disposition
= disp_donttouch
;
4723 b
->frame_id
= frame_id
;
4725 /* If we're debugging a multi-threaded program, then we
4726 want momentary breakpoints to be active in only a
4727 single thread of control. */
4728 if (in_thread_list (inferior_ptid
))
4729 b
->thread
= pid_to_thread_id (inferior_ptid
);
4735 /* Tell the user we have just set a breakpoint B. */
4738 mention (struct breakpoint
*b
)
4741 struct cleanup
*old_chain
, *ui_out_chain
;
4742 struct ui_stream
*stb
;
4744 stb
= ui_out_stream_new (uiout
);
4745 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4747 /* FIXME: This is misplaced; mention() is called by things (like
4748 hitting a watchpoint) other than breakpoint creation. It should
4749 be possible to clean this up and at the same time replace the
4750 random calls to breakpoint_changed with this hook, as has already
4751 been done for deprecated_delete_breakpoint_hook and so on. */
4752 if (deprecated_create_breakpoint_hook
)
4753 deprecated_create_breakpoint_hook (b
);
4754 breakpoint_create_event (b
->number
);
4756 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4757 b
->ops
->print_mention (b
);
4762 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4765 ui_out_text (uiout
, "Watchpoint ");
4766 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4767 ui_out_field_int (uiout
, "number", b
->number
);
4768 ui_out_text (uiout
, ": ");
4769 print_expression (b
->exp
, stb
->stream
);
4770 ui_out_field_stream (uiout
, "exp", stb
);
4771 do_cleanups (ui_out_chain
);
4773 case bp_hardware_watchpoint
:
4774 ui_out_text (uiout
, "Hardware watchpoint ");
4775 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4776 ui_out_field_int (uiout
, "number", b
->number
);
4777 ui_out_text (uiout
, ": ");
4778 print_expression (b
->exp
, stb
->stream
);
4779 ui_out_field_stream (uiout
, "exp", stb
);
4780 do_cleanups (ui_out_chain
);
4782 case bp_read_watchpoint
:
4783 ui_out_text (uiout
, "Hardware read watchpoint ");
4784 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4785 ui_out_field_int (uiout
, "number", b
->number
);
4786 ui_out_text (uiout
, ": ");
4787 print_expression (b
->exp
, stb
->stream
);
4788 ui_out_field_stream (uiout
, "exp", stb
);
4789 do_cleanups (ui_out_chain
);
4791 case bp_access_watchpoint
:
4792 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4793 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4794 ui_out_field_int (uiout
, "number", b
->number
);
4795 ui_out_text (uiout
, ": ");
4796 print_expression (b
->exp
, stb
->stream
);
4797 ui_out_field_stream (uiout
, "exp", stb
);
4798 do_cleanups (ui_out_chain
);
4801 if (ui_out_is_mi_like_p (uiout
))
4806 printf_filtered (_("Breakpoint %d"), b
->number
);
4809 case bp_hardware_breakpoint
:
4810 if (ui_out_is_mi_like_p (uiout
))
4815 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4819 case bp_catch_unload
:
4820 printf_filtered (_("Catchpoint %d (%s %s)"),
4822 (b
->type
== bp_catch_load
) ? "load" : "unload",
4823 (b
->dll_pathname
!= NULL
) ?
4824 b
->dll_pathname
: "<any library>");
4827 case bp_catch_vfork
:
4828 printf_filtered (_("Catchpoint %d (%s)"),
4830 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4833 printf_filtered (_("Catchpoint %d (exec)"),
4840 case bp_longjmp_resume
:
4841 case bp_step_resume
:
4843 case bp_watchpoint_scope
:
4844 case bp_shlib_event
:
4845 case bp_thread_event
:
4846 case bp_overlay_event
:
4852 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4856 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4860 if (addressprint
|| b
->source_file
== NULL
)
4862 printf_filtered (" at ");
4863 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4866 printf_filtered (": file %s, line %d.",
4867 b
->source_file
, b
->line_number
);
4871 struct bp_location
*loc
= b
->loc
;
4873 for (; loc
; loc
= loc
->next
)
4875 printf_filtered (" (%d locations)", n
);
4880 do_cleanups (old_chain
);
4881 if (ui_out_is_mi_like_p (uiout
))
4883 printf_filtered ("\n");
4887 static struct bp_location
*
4888 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
4889 const struct symtab_and_line
*sal
)
4891 struct bp_location
*loc
, **tmp
;
4893 loc
= allocate_bp_location (b
, bptype
);
4894 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
4897 loc
->requested_address
= sal
->pc
;
4898 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
4900 loc
->section
= sal
->section
;
4902 set_breakpoint_location_function (loc
);
4906 /* Create a breakpoint with SAL as location. Use ADDR_STRING
4907 as textual description of the location, and COND_STRING
4908 as condition expression. */
4911 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
4913 enum bptype type
, enum bpdisp disposition
,
4914 int thread
, int ignore_count
, int from_tty
)
4916 struct breakpoint
*b
= NULL
;
4919 if (type
== bp_hardware_breakpoint
)
4921 int i
= hw_breakpoint_used_count ();
4922 int target_resources_ok
=
4923 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4925 if (target_resources_ok
== 0)
4926 error (_("No hardware breakpoint support in the target."));
4927 else if (target_resources_ok
< 0)
4928 error (_("Hardware breakpoints used exceeds limit."));
4931 for (i
= 0; i
< sals
.nelts
; ++i
)
4933 struct symtab_and_line sal
= sals
.sals
[i
];
4934 struct bp_location
*loc
;
4937 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
4941 b
= set_raw_breakpoint (sal
, type
);
4942 set_breakpoint_count (breakpoint_count
+ 1);
4943 b
->number
= breakpoint_count
;
4946 b
->cond_string
= cond_string
;
4947 b
->ignore_count
= ignore_count
;
4948 b
->enable_state
= bp_enabled
;
4949 b
->disposition
= disposition
;
4955 loc
= add_location_to_breakpoint (b
, type
, &sal
);
4960 char *arg
= b
->cond_string
;
4961 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
4963 error (_("Garbage %s follows condition"), arg
);
4968 b
->addr_string
= addr_string
;
4970 /* addr_string has to be used or breakpoint_re_set will delete
4972 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4977 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
4978 elements to fill the void space. */
4979 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
4981 int i
= index_to_remove
+1;
4982 int last_index
= sal
->nelts
-1;
4984 for (;i
<= last_index
; ++i
)
4985 sal
->sals
[i
-1] = sal
->sals
[i
];
4990 /* If appropriate, obtains all sals that correspond
4991 to the same file and line as SAL. This is done
4992 only if SAL does not have explicit PC and has
4993 line and file information. If we got just a single
4994 expanded sal, return the original.
4996 Otherwise, if SAL.explicit_line is not set, filter out
4997 all sals for which the name of enclosing function
4998 is different from SAL. This makes sure that if we have
4999 breakpoint originally set in template instantiation, say
5000 foo<int>(), we won't expand SAL to locations at the same
5001 line in all existing instantiations of 'foo'.
5004 struct symtabs_and_lines
5005 expand_line_sal_maybe (struct symtab_and_line sal
)
5007 struct symtabs_and_lines expanded
;
5008 CORE_ADDR original_pc
= sal
.pc
;
5009 char *original_function
= NULL
;
5013 /* If we have explicit pc, don't expand.
5014 If we have no line number, we can't expand. */
5015 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5018 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5019 expanded
.sals
[0] = sal
;
5024 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5026 expanded
= expand_line_sal (sal
);
5027 if (expanded
.nelts
== 1)
5029 /* We had one sal, we got one sal. Without futher
5030 processing, just return the original sal. */
5031 xfree (expanded
.sals
);
5033 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5034 sal
.pc
= original_pc
;
5035 expanded
.sals
[0] = sal
;
5039 if (!sal
.explicit_line
)
5041 CORE_ADDR func_addr
, func_end
;
5042 for (i
= 0; i
< expanded
.nelts
; ++i
)
5044 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5045 char *this_function
;
5046 if (find_pc_partial_function (pc
, &this_function
,
5047 &func_addr
, &func_end
))
5049 if (this_function
&&
5050 strcmp (this_function
, original_function
) != 0)
5052 remove_sal (&expanded
, i
);
5055 else if (func_addr
== pc
)
5057 /* We're at beginning of a function, and should
5059 struct symbol
*sym
= find_pc_function (pc
);
5061 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5064 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5071 if (expanded
.nelts
<= 1)
5073 /* This is un ugly workaround. If we get zero
5074 expanded sals then something is really wrong.
5075 Fix that by returnign the original sal. */
5076 xfree (expanded
.sals
);
5078 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5079 sal
.pc
= original_pc
;
5080 expanded
.sals
[0] = sal
;
5087 for (i
= 0; i
< expanded
.nelts
; ++i
)
5088 if (expanded
.sals
[i
].pc
== original_pc
)
5099 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5100 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5101 value. COND_STRING, if not NULL, specified the condition to be
5102 used for all breakpoints. Essentially the only case where
5103 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5104 function. In that case, it's still not possible to specify
5105 separate conditions for different overloaded functions, so
5106 we take just a single condition string.
5108 NOTE: If the function succeeds, the caller is expected to cleanup
5109 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5110 array contents). If the function fails (error() is called), the
5111 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5112 COND and SALS arrays and each of those arrays contents. */
5115 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5117 enum bptype type
, enum bpdisp disposition
,
5118 int thread
, int ignore_count
, int from_tty
)
5121 for (i
= 0; i
< sals
.nelts
; ++i
)
5123 struct symtabs_and_lines expanded
=
5124 expand_line_sal_maybe (sals
.sals
[i
]);
5126 create_breakpoint (expanded
, addr_string
[i
],
5127 cond_string
, type
, disposition
,
5128 thread
, ignore_count
, from_tty
);
5132 /* Parse ARG which is assumed to be a SAL specification possibly
5133 followed by conditionals. On return, SALS contains an array of SAL
5134 addresses found. ADDR_STRING contains a vector of (canonical)
5135 address strings. ARG points to the end of the SAL. */
5138 parse_breakpoint_sals (char **address
,
5139 struct symtabs_and_lines
*sals
,
5140 char ***addr_string
,
5143 char *addr_start
= *address
;
5144 *addr_string
= NULL
;
5145 /* If no arg given, or if first arg is 'if ', use the default
5147 if ((*address
) == NULL
5148 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5150 if (default_breakpoint_valid
)
5152 struct symtab_and_line sal
;
5153 init_sal (&sal
); /* initialize to zeroes */
5154 sals
->sals
= (struct symtab_and_line
*)
5155 xmalloc (sizeof (struct symtab_and_line
));
5156 sal
.pc
= default_breakpoint_address
;
5157 sal
.line
= default_breakpoint_line
;
5158 sal
.symtab
= default_breakpoint_symtab
;
5159 sal
.section
= find_pc_overlay (sal
.pc
);
5160 sals
->sals
[0] = sal
;
5164 error (_("No default breakpoint address now."));
5168 /* Force almost all breakpoints to be in terms of the
5169 current_source_symtab (which is decode_line_1's default). This
5170 should produce the results we want almost all of the time while
5171 leaving default_breakpoint_* alone.
5172 ObjC: However, don't match an Objective-C method name which
5173 may have a '+' or '-' succeeded by a '[' */
5175 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5177 if (default_breakpoint_valid
5179 || ((strchr ("+-", (*address
)[0]) != NULL
)
5180 && ((*address
)[1] != '['))))
5181 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5182 default_breakpoint_line
, addr_string
,
5185 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5186 addr_string
, not_found_ptr
);
5188 /* For any SAL that didn't have a canonical string, fill one in. */
5189 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5190 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5191 if (addr_start
!= (*address
))
5194 for (i
= 0; i
< sals
->nelts
; i
++)
5196 /* Add the string if not present. */
5197 if ((*addr_string
)[i
] == NULL
)
5198 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5204 /* Convert each SAL into a real PC. Verify that the PC can be
5205 inserted as a breakpoint. If it can't throw an error. */
5208 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5212 for (i
= 0; i
< sals
->nelts
; i
++)
5213 resolve_sal_pc (&sals
->sals
[i
]);
5217 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5219 struct captured_parse_breakpoint_args
*args
= data
;
5221 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5222 args
->not_found_ptr
);
5225 /* Given TOK, a string specification of condition and thread, as
5226 accepted by the 'break' command, extract the condition
5227 string and thread number and set *COND_STRING and *THREAD.
5228 PC identifies the context at which the condition should be parsed.
5229 If no condition is found, *COND_STRING is set to NULL.
5230 If no thread is found, *THREAD is set to -1. */
5232 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5233 char **cond_string
, int *thread
)
5235 *cond_string
= NULL
;
5241 char *cond_start
= NULL
;
5242 char *cond_end
= NULL
;
5243 while (*tok
== ' ' || *tok
== '\t')
5248 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5251 toklen
= end_tok
- tok
;
5253 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5255 tok
= cond_start
= end_tok
+ 1;
5256 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5258 *cond_string
= savestring (cond_start
,
5259 cond_end
- cond_start
);
5261 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5267 *thread
= strtol (tok
, &tok
, 0);
5269 error (_("Junk after thread keyword."));
5270 if (!valid_thread_id (*thread
))
5271 error (_("Unknown thread %d."), *thread
);
5274 error (_("Junk at end of arguments."));
5278 /* Set a breakpoint. This function is shared between
5279 CLI and MI functions for setting a breakpoint.
5280 This function has two major modes of operations,
5281 selected by the PARSE_CONDITION_AND_THREAD parameter.
5282 If non-zero, the function will parse arg, extracting
5283 breakpoint location, address and thread. Otherwise,
5284 ARG is just the location of breakpoint, with condition
5285 and thread specified by the COND_STRING and THREAD
5289 break_command_really (char *arg
, char *cond_string
, int thread
,
5290 int parse_condition_and_thread
,
5291 int tempflag
, int hardwareflag
,
5293 enum auto_boolean pending_break_support
,
5296 struct gdb_exception e
;
5297 struct symtabs_and_lines sals
;
5298 struct symtab_and_line pending_sal
;
5301 char *addr_start
= arg
;
5303 struct cleanup
*old_chain
;
5304 struct cleanup
*breakpoint_chain
= NULL
;
5305 struct captured_parse_breakpoint_args parse_args
;
5314 parse_args
.arg_p
= &arg
;
5315 parse_args
.sals_p
= &sals
;
5316 parse_args
.addr_string_p
= &addr_string
;
5317 parse_args
.not_found_ptr
= ¬_found
;
5319 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5320 &parse_args
, RETURN_MASK_ALL
);
5322 /* If caller is interested in rc value from parse, set value. */
5326 throw_exception (e
);
5330 case NOT_FOUND_ERROR
:
5332 /* If pending breakpoint support is turned off, throw
5335 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5336 throw_exception (e
);
5338 exception_print (gdb_stderr
, e
);
5340 /* If pending breakpoint support is auto query and the user
5341 selects no, then simply return the error code. */
5342 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5343 !nquery ("Make breakpoint pending on future shared library load? "))
5346 /* At this point, either the user was queried about setting
5347 a pending breakpoint and selected yes, or pending
5348 breakpoint behavior is on and thus a pending breakpoint
5349 is defaulted on behalf of the user. */
5350 copy_arg
= xstrdup (addr_start
);
5351 addr_string
= ©_arg
;
5353 sals
.sals
= &pending_sal
;
5358 throw_exception (e
);
5365 /* Create a chain of things that always need to be cleaned up. */
5366 old_chain
= make_cleanup (null_cleanup
, 0);
5370 /* Make sure that all storage allocated to SALS gets freed. */
5371 make_cleanup (xfree
, sals
.sals
);
5373 /* Cleanup the addr_string array but not its contents. */
5374 make_cleanup (xfree
, addr_string
);
5377 /* ----------------------------- SNIP -----------------------------
5378 Anything added to the cleanup chain beyond this point is assumed
5379 to be part of a breakpoint. If the breakpoint create succeeds
5380 then the memory is not reclaimed. */
5381 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5383 /* Mark the contents of the addr_string for cleanup. These go on
5384 the breakpoint_chain and only occure if the breakpoint create
5386 for (i
= 0; i
< sals
.nelts
; i
++)
5388 if (addr_string
[i
] != NULL
)
5389 make_cleanup (xfree
, addr_string
[i
]);
5392 /* Resolve all line numbers to PC's and verify that the addresses
5393 are ok for the target. */
5395 breakpoint_sals_to_pc (&sals
, addr_start
);
5397 /* Verify that condition can be parsed, before setting any
5398 breakpoints. Allocate a separate condition expression for each
5402 if (parse_condition_and_thread
)
5404 /* Here we only parse 'arg' to separate condition
5405 from thread number, so parsing in context of first
5406 sal is OK. When setting the breakpoint we'll
5407 re-parse it in context of each sal. */
5410 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5412 make_cleanup (xfree
, cond_string
);
5416 /* Create a private copy of condition string. */
5419 cond_string
= xstrdup (cond_string
);
5420 make_cleanup (xfree
, cond_string
);
5423 create_breakpoints (sals
, addr_string
, cond_string
,
5424 hardwareflag
? bp_hardware_breakpoint
5426 tempflag
? disp_del
: disp_donttouch
,
5427 thread
, ignore_count
, from_tty
);
5431 struct symtab_and_line sal
= {0};
5432 struct breakpoint
*b
;
5434 make_cleanup (xfree
, copy_arg
);
5436 b
= set_raw_breakpoint_without_location (hardwareflag
5437 ? bp_hardware_breakpoint
5439 set_breakpoint_count (breakpoint_count
+ 1);
5440 b
->number
= breakpoint_count
;
5442 b
->addr_string
= addr_string
[0];
5443 b
->cond_string
= NULL
;
5444 b
->ignore_count
= ignore_count
;
5445 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5446 b
->condition_not_parsed
= 1;
5451 warning (_("Multiple breakpoints were set.\n"
5452 "Use the \"delete\" command to delete unwanted breakpoints."));
5453 /* That's it. Discard the cleanups for data inserted into the
5455 discard_cleanups (breakpoint_chain
);
5456 /* But cleanup everything else. */
5457 do_cleanups (old_chain
);
5460 /* Set a breakpoint.
5461 ARG is a string describing breakpoint address,
5462 condition, and thread.
5463 FLAG specifies if a breakpoint is hardware on,
5464 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5468 break_command_1 (char *arg
, int flag
, int from_tty
)
5470 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5471 int tempflag
= flag
& BP_TEMPFLAG
;
5473 break_command_really (arg
,
5474 NULL
, 0, 1 /* parse arg */,
5475 tempflag
, hardwareflag
,
5476 0 /* Ignore count */,
5477 pending_break_support
, from_tty
);
5482 set_breakpoint (char *address
, char *condition
,
5483 int hardwareflag
, int tempflag
,
5484 int thread
, int ignore_count
,
5487 break_command_really (address
, condition
, thread
,
5488 0 /* condition and thread are valid. */,
5489 tempflag
, hardwareflag
,
5492 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5497 /* Helper function for break_command_1 and disassemble_command. */
5500 resolve_sal_pc (struct symtab_and_line
*sal
)
5504 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5506 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5507 error (_("No line %d in file \"%s\"."),
5508 sal
->line
, sal
->symtab
->filename
);
5512 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5514 struct blockvector
*bv
;
5518 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5521 sym
= block_function (b
);
5524 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5525 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5529 /* It really is worthwhile to have the section, so we'll just
5530 have to look harder. This case can be executed if we have
5531 line numbers but no functions (as can happen in assembly
5534 struct minimal_symbol
*msym
;
5536 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5538 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5545 break_command (char *arg
, int from_tty
)
5547 break_command_1 (arg
, 0, from_tty
);
5551 tbreak_command (char *arg
, int from_tty
)
5553 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5557 hbreak_command (char *arg
, int from_tty
)
5559 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5563 thbreak_command (char *arg
, int from_tty
)
5565 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5569 stop_command (char *arg
, int from_tty
)
5571 printf_filtered (_("Specify the type of breakpoint to set.\n\
5572 Usage: stop in <function | address>\n\
5573 stop at <line>\n"));
5577 stopin_command (char *arg
, int from_tty
)
5581 if (arg
== (char *) NULL
)
5583 else if (*arg
!= '*')
5588 /* look for a ':'. If this is a line number specification, then
5589 say it is bad, otherwise, it should be an address or
5590 function/method name */
5591 while (*argptr
&& !hasColon
)
5593 hasColon
= (*argptr
== ':');
5598 badInput
= (*argptr
!= ':'); /* Not a class::method */
5600 badInput
= isdigit (*arg
); /* a simple line number */
5604 printf_filtered (_("Usage: stop in <function | address>\n"));
5606 break_command_1 (arg
, 0, from_tty
);
5610 stopat_command (char *arg
, int from_tty
)
5614 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5621 /* look for a ':'. If there is a '::' then get out, otherwise
5622 it is probably a line number. */
5623 while (*argptr
&& !hasColon
)
5625 hasColon
= (*argptr
== ':');
5630 badInput
= (*argptr
== ':'); /* we have class::method */
5632 badInput
= !isdigit (*arg
); /* not a line number */
5636 printf_filtered (_("Usage: stop at <line>\n"));
5638 break_command_1 (arg
, 0, from_tty
);
5641 /* accessflag: hw_write: watch write,
5642 hw_read: watch read,
5643 hw_access: watch access (read or write) */
5645 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5647 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5648 struct symtab_and_line sal
;
5649 struct expression
*exp
;
5650 struct block
*exp_valid_block
;
5651 struct value
*val
, *mark
;
5652 struct frame_info
*frame
;
5653 struct frame_info
*prev_frame
= NULL
;
5654 char *exp_start
= NULL
;
5655 char *exp_end
= NULL
;
5656 char *tok
, *id_tok_start
, *end_tok
;
5658 char *cond_start
= NULL
;
5659 char *cond_end
= NULL
;
5660 struct expression
*cond
= NULL
;
5661 int i
, other_type_used
, target_resources_ok
= 0;
5662 enum bptype bp_type
;
5666 init_sal (&sal
); /* initialize to zeroes */
5668 /* Make sure that we actually have parameters to parse. */
5669 if (arg
!= NULL
&& arg
[0] != '\0')
5671 toklen
= strlen (arg
); /* Size of argument list. */
5673 /* Points tok to the end of the argument list. */
5674 tok
= arg
+ toklen
- 1;
5676 /* Go backwards in the parameters list. Skip the last parameter.
5677 If we're expecting a 'thread <thread_num>' parameter, this should
5678 be the thread identifier. */
5679 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5681 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5684 /* Points end_tok to the beginning of the last token. */
5685 id_tok_start
= tok
+ 1;
5687 /* Go backwards in the parameters list. Skip one more parameter.
5688 If we're expecting a 'thread <thread_num>' parameter, we should
5689 reach a "thread" token. */
5690 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5695 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5698 /* Move the pointer forward to skip the whitespace and
5699 calculate the length of the token. */
5701 toklen
= end_tok
- tok
;
5703 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5705 /* At this point we've found a "thread" token, which means
5706 the user is trying to set a watchpoint that triggers
5707 only in a specific thread. */
5710 /* Extract the thread ID from the next token. */
5711 thread
= strtol (id_tok_start
, &endp
, 0);
5713 /* Check if the user provided a valid numeric value for the
5715 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5716 error (_("Invalid thread ID specification %s."), id_tok_start
);
5718 /* Check if the thread actually exists. */
5719 if (!valid_thread_id (thread
))
5720 error (_("Unknown thread %d."), thread
);
5722 /* Truncate the string and get rid of the thread <thread_num>
5723 parameter before the parameter list is parsed by the
5724 evaluate_expression() function. */
5729 /* Parse the rest of the arguments. */
5730 innermost_block
= NULL
;
5732 exp
= parse_exp_1 (&arg
, 0, 0);
5734 exp_valid_block
= innermost_block
;
5735 mark
= value_mark ();
5736 val
= evaluate_expression (exp
);
5737 release_value (val
);
5738 if (value_lazy (val
))
5739 value_fetch_lazy (val
);
5742 while (*tok
== ' ' || *tok
== '\t')
5746 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5749 toklen
= end_tok
- tok
;
5750 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5752 tok
= cond_start
= end_tok
+ 1;
5753 cond
= parse_exp_1 (&tok
, 0, 0);
5757 error (_("Junk at end of command."));
5759 if (accessflag
== hw_read
)
5760 bp_type
= bp_read_watchpoint
;
5761 else if (accessflag
== hw_access
)
5762 bp_type
= bp_access_watchpoint
;
5764 bp_type
= bp_hardware_watchpoint
;
5766 mem_cnt
= can_use_hardware_watchpoint (val
);
5767 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5768 error (_("Expression cannot be implemented with read/access watchpoint."));
5771 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5772 target_resources_ok
=
5773 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5775 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5776 error (_("Target does not support this type of hardware watchpoint."));
5778 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5779 error (_("Target can only support one kind of HW watchpoint at a time."));
5782 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5783 watchpoint could not be set. */
5784 if (!mem_cnt
|| target_resources_ok
<= 0)
5785 bp_type
= bp_watchpoint
;
5787 frame
= block_innermost_frame (exp_valid_block
);
5789 prev_frame
= get_prev_frame (frame
);
5793 /* If the expression is "local", then set up a "watchpoint scope"
5794 breakpoint at the point where we've left the scope of the watchpoint
5795 expression. Create the scope breakpoint before the watchpoint, so
5796 that we will encounter it first in bpstat_stop_status. */
5797 if (innermost_block
&& prev_frame
)
5799 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5800 bp_watchpoint_scope
);
5802 scope_breakpoint
->enable_state
= bp_enabled
;
5804 /* Automatically delete the breakpoint when it hits. */
5805 scope_breakpoint
->disposition
= disp_del
;
5807 /* Only break in the proper frame (help with recursion). */
5808 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5810 /* Set the address at which we will stop. */
5811 scope_breakpoint
->loc
->requested_address
5812 = get_frame_pc (prev_frame
);
5813 scope_breakpoint
->loc
->address
5814 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5815 scope_breakpoint
->type
);
5818 /* Now set up the breakpoint. */
5819 b
= set_raw_breakpoint (sal
, bp_type
);
5820 set_breakpoint_count (breakpoint_count
+ 1);
5821 b
->number
= breakpoint_count
;
5823 b
->disposition
= disp_donttouch
;
5825 b
->exp_valid_block
= exp_valid_block
;
5826 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5828 b
->loc
->cond
= cond
;
5830 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5835 b
->watchpoint_frame
= get_frame_id (frame
);
5837 b
->watchpoint_frame
= null_frame_id
;
5839 if (scope_breakpoint
!= NULL
)
5841 /* The scope breakpoint is related to the watchpoint. We will
5842 need to act on them together. */
5843 b
->related_breakpoint
= scope_breakpoint
;
5844 scope_breakpoint
->related_breakpoint
= b
;
5847 value_free_to_mark (mark
);
5851 /* Return count of locations need to be watched and can be handled
5852 in hardware. If the watchpoint can not be handled
5853 in hardware return zero. */
5856 can_use_hardware_watchpoint (struct value
*v
)
5858 int found_memory_cnt
= 0;
5859 struct value
*head
= v
;
5861 /* Did the user specifically forbid us to use hardware watchpoints? */
5862 if (!can_use_hw_watchpoints
)
5865 /* Make sure that the value of the expression depends only upon
5866 memory contents, and values computed from them within GDB. If we
5867 find any register references or function calls, we can't use a
5868 hardware watchpoint.
5870 The idea here is that evaluating an expression generates a series
5871 of values, one holding the value of every subexpression. (The
5872 expression a*b+c has five subexpressions: a, b, a*b, c, and
5873 a*b+c.) GDB's values hold almost enough information to establish
5874 the criteria given above --- they identify memory lvalues,
5875 register lvalues, computed values, etcetera. So we can evaluate
5876 the expression, and then scan the chain of values that leaves
5877 behind to decide whether we can detect any possible change to the
5878 expression's final value using only hardware watchpoints.
5880 However, I don't think that the values returned by inferior
5881 function calls are special in any way. So this function may not
5882 notice that an expression involving an inferior function call
5883 can't be watched with hardware watchpoints. FIXME. */
5884 for (; v
; v
= value_next (v
))
5886 if (VALUE_LVAL (v
) == lval_memory
)
5889 /* A lazy memory lvalue is one that GDB never needed to fetch;
5890 we either just used its address (e.g., `a' in `a.b') or
5891 we never needed it at all (e.g., `a' in `a,b'). */
5895 /* Ahh, memory we actually used! Check if we can cover
5896 it with hardware watchpoints. */
5897 struct type
*vtype
= check_typedef (value_type (v
));
5899 /* We only watch structs and arrays if user asked for it
5900 explicitly, never if they just happen to appear in a
5901 middle of some value chain. */
5903 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5904 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5906 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5907 int len
= TYPE_LENGTH (value_type (v
));
5909 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5916 else if (VALUE_LVAL (v
) != not_lval
5917 && deprecated_value_modifiable (v
) == 0)
5918 return 0; /* ??? What does this represent? */
5919 else if (VALUE_LVAL (v
) == lval_register
)
5920 return 0; /* cannot watch a register with a HW watchpoint */
5923 /* The expression itself looks suitable for using a hardware
5924 watchpoint, but give the target machine a chance to reject it. */
5925 return found_memory_cnt
;
5929 watch_command_wrapper (char *arg
, int from_tty
)
5931 watch_command (arg
, from_tty
);
5935 watch_command (char *arg
, int from_tty
)
5937 watch_command_1 (arg
, hw_write
, from_tty
);
5941 rwatch_command_wrapper (char *arg
, int from_tty
)
5943 rwatch_command (arg
, from_tty
);
5947 rwatch_command (char *arg
, int from_tty
)
5949 watch_command_1 (arg
, hw_read
, from_tty
);
5953 awatch_command_wrapper (char *arg
, int from_tty
)
5955 awatch_command (arg
, from_tty
);
5959 awatch_command (char *arg
, int from_tty
)
5961 watch_command_1 (arg
, hw_access
, from_tty
);
5965 /* Helper routines for the until_command routine in infcmd.c. Here
5966 because it uses the mechanisms of breakpoints. */
5968 /* This function is called by fetch_inferior_event via the
5969 cmd_continuation pointer, to complete the until command. It takes
5970 care of cleaning up the temporary breakpoints set up by the until
5973 until_break_command_continuation (struct continuation_arg
*arg
)
5975 struct cleanup
*cleanups
;
5977 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5978 do_exec_cleanups (cleanups
);
5982 until_break_command (char *arg
, int from_tty
, int anywhere
)
5984 struct symtabs_and_lines sals
;
5985 struct symtab_and_line sal
;
5986 struct frame_info
*frame
= get_selected_frame (NULL
);
5987 struct frame_info
*prev_frame
= get_prev_frame (frame
);
5988 struct breakpoint
*breakpoint
;
5989 struct cleanup
*old_chain
;
5990 struct continuation_arg
*arg1
;
5993 clear_proceed_status ();
5995 /* Set a breakpoint where the user wants it and at return from
5998 if (default_breakpoint_valid
)
5999 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6000 default_breakpoint_line
, (char ***) NULL
, NULL
);
6002 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6003 0, (char ***) NULL
, NULL
);
6005 if (sals
.nelts
!= 1)
6006 error (_("Couldn't get information on specified line."));
6009 xfree (sals
.sals
); /* malloc'd, so freed */
6012 error (_("Junk at end of arguments."));
6014 resolve_sal_pc (&sal
);
6017 /* If the user told us to continue until a specified location,
6018 we don't specify a frame at which we need to stop. */
6019 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6021 /* Otherwise, specify the current frame, because we want to stop only
6022 at the very same frame. */
6023 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6026 if (!target_can_async_p ())
6027 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6029 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6031 /* If we are running asynchronously, and the target supports async
6032 execution, we are not waiting for the target to stop, in the call
6033 tp proceed, below. This means that we cannot delete the
6034 brekpoints until the target has actually stopped. The only place
6035 where we get a chance to do that is in fetch_inferior_event, so
6036 we must set things up for that. */
6038 if (target_can_async_p ())
6040 /* In this case the arg for the continuation is just the point
6041 in the exec_cleanups chain from where to start doing
6042 cleanups, because all the continuation does is the cleanups in
6043 the exec_cleanup_chain. */
6045 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6047 arg1
->data
.pointer
= old_chain
;
6049 add_continuation (until_break_command_continuation
, arg1
);
6052 /* Keep within the current frame, or in frames called by the current
6056 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6057 sal
.pc
= get_frame_pc (prev_frame
);
6058 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6060 if (!target_can_async_p ())
6061 make_cleanup_delete_breakpoint (breakpoint
);
6063 make_exec_cleanup_delete_breakpoint (breakpoint
);
6066 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6067 /* Do the cleanups now, anly if we are not running asynchronously,
6068 of if we are, but the target is still synchronous. */
6069 if (!target_can_async_p ())
6070 do_cleanups (old_chain
);
6074 ep_skip_leading_whitespace (char **s
)
6076 if ((s
== NULL
) || (*s
== NULL
))
6078 while (isspace (**s
))
6082 /* This function examines a string, and attempts to find a token
6083 that might be an event name in the leading characters. If a
6084 possible match is found, a pointer to the last character of
6085 the token is returned. Else, NULL is returned. */
6088 ep_find_event_name_end (char *arg
)
6091 char *event_name_end
= NULL
;
6093 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6097 /* We break out of the loop when we find a token delimiter.
6098 Basically, we're looking for alphanumerics and underscores;
6099 anything else delimites the token. */
6102 if (!isalnum (*s
) && (*s
!= '_'))
6108 return event_name_end
;
6112 /* This function attempts to parse an optional "if <cond>" clause
6113 from the arg string. If one is not found, it returns NULL.
6115 Else, it returns a pointer to the condition string. (It does not
6116 attempt to evaluate the string against a particular block.) And,
6117 it updates arg to point to the first character following the parsed
6118 if clause in the arg string. */
6121 ep_parse_optional_if_clause (char **arg
)
6125 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6128 /* Skip the "if" keyword. */
6131 /* Skip any extra leading whitespace, and record the start of the
6132 condition string. */
6133 ep_skip_leading_whitespace (arg
);
6136 /* Assume that the condition occupies the remainder of the arg string. */
6137 (*arg
) += strlen (cond_string
);
6142 /* This function attempts to parse an optional filename from the arg
6143 string. If one is not found, it returns NULL.
6145 Else, it returns a pointer to the parsed filename. (This function
6146 makes no attempt to verify that a file of that name exists, or is
6147 accessible.) And, it updates arg to point to the first character
6148 following the parsed filename in the arg string.
6150 Note that clients needing to preserve the returned filename for
6151 future access should copy it to their own buffers. */
6153 ep_parse_optional_filename (char **arg
)
6155 static char filename
[1024];
6160 if ((*arg_p
== '\0') || isspace (*arg_p
))
6178 /* Commands to deal with catching events, such as signals, exceptions,
6179 process start/exit, etc. */
6183 catch_fork
, catch_vfork
6188 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6191 char *cond_string
= NULL
;
6193 ep_skip_leading_whitespace (&arg
);
6195 /* The allowed syntax is:
6197 catch [v]fork if <cond>
6199 First, check if there's an if clause. */
6200 cond_string
= ep_parse_optional_if_clause (&arg
);
6202 if ((*arg
!= '\0') && !isspace (*arg
))
6203 error (_("Junk at end of arguments."));
6205 /* If this target supports it, create a fork or vfork catchpoint
6206 and enable reporting of such events. */
6210 create_fork_event_catchpoint (tempflag
, cond_string
);
6213 create_vfork_event_catchpoint (tempflag
, cond_string
);
6216 error (_("unsupported or unknown fork kind; cannot catch it"));
6222 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6224 char *cond_string
= NULL
;
6226 ep_skip_leading_whitespace (&arg
);
6228 /* The allowed syntax is:
6230 catch exec if <cond>
6232 First, check if there's an if clause. */
6233 cond_string
= ep_parse_optional_if_clause (&arg
);
6235 if ((*arg
!= '\0') && !isspace (*arg
))
6236 error (_("Junk at end of arguments."));
6238 /* If this target supports it, create an exec catchpoint
6239 and enable reporting of such events. */
6240 create_exec_event_catchpoint (tempflag
, cond_string
);
6244 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6246 char *dll_pathname
= NULL
;
6247 char *cond_string
= NULL
;
6249 ep_skip_leading_whitespace (&arg
);
6251 /* The allowed syntax is:
6253 catch load if <cond>
6254 catch load <filename>
6255 catch load <filename> if <cond>
6257 The user is not allowed to specify the <filename> after an
6260 We'll ignore the pathological case of a file named "if".
6262 First, check if there's an if clause. If so, then there
6263 cannot be a filename. */
6264 cond_string
= ep_parse_optional_if_clause (&arg
);
6266 /* If there was an if clause, then there cannot be a filename.
6267 Else, there might be a filename and an if clause. */
6268 if (cond_string
== NULL
)
6270 dll_pathname
= ep_parse_optional_filename (&arg
);
6271 ep_skip_leading_whitespace (&arg
);
6272 cond_string
= ep_parse_optional_if_clause (&arg
);
6275 if ((*arg
!= '\0') && !isspace (*arg
))
6276 error (_("Junk at end of arguments."));
6278 /* Create a load breakpoint that only triggers when a load of
6279 the specified dll (or any dll, if no pathname was specified)
6281 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6282 dll_pathname
, cond_string
);
6286 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6288 char *dll_pathname
= NULL
;
6289 char *cond_string
= NULL
;
6291 ep_skip_leading_whitespace (&arg
);
6293 /* The allowed syntax is:
6295 catch unload if <cond>
6296 catch unload <filename>
6297 catch unload <filename> if <cond>
6299 The user is not allowed to specify the <filename> after an
6302 We'll ignore the pathological case of a file named "if".
6304 First, check if there's an if clause. If so, then there
6305 cannot be a filename. */
6306 cond_string
= ep_parse_optional_if_clause (&arg
);
6308 /* If there was an if clause, then there cannot be a filename.
6309 Else, there might be a filename and an if clause. */
6310 if (cond_string
== NULL
)
6312 dll_pathname
= ep_parse_optional_filename (&arg
);
6313 ep_skip_leading_whitespace (&arg
);
6314 cond_string
= ep_parse_optional_if_clause (&arg
);
6317 if ((*arg
!= '\0') && !isspace (*arg
))
6318 error (_("Junk at end of arguments."));
6320 /* Create an unload breakpoint that only triggers when an unload of
6321 the specified dll (or any dll, if no pathname was specified)
6323 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6324 dll_pathname
, cond_string
);
6327 static enum print_stop_action
6328 print_exception_catchpoint (struct breakpoint
*b
)
6330 annotate_catchpoint (b
->number
);
6332 if (strstr (b
->addr_string
, "throw") != NULL
)
6333 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6336 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6339 return PRINT_SRC_AND_LOC
;
6343 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6348 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6351 *last_addr
= b
->loc
->address
;
6352 if (strstr (b
->addr_string
, "throw") != NULL
)
6353 ui_out_field_string (uiout
, "what", "exception throw");
6355 ui_out_field_string (uiout
, "what", "exception catch");
6359 print_mention_exception_catchpoint (struct breakpoint
*b
)
6361 if (strstr (b
->addr_string
, "throw") != NULL
)
6362 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6364 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6367 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6368 print_exception_catchpoint
,
6369 print_one_exception_catchpoint
,
6370 print_mention_exception_catchpoint
6374 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6375 enum exception_event_kind ex_event
, int from_tty
)
6377 char *trigger_func_name
, *nameptr
;
6378 struct symtabs_and_lines sals
;
6379 struct breakpoint
*b
;
6381 if (ex_event
== EX_EVENT_CATCH
)
6382 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6384 trigger_func_name
= xstrdup ("__cxa_throw");
6386 nameptr
= trigger_func_name
;
6387 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6388 if (sals
.nelts
== 0)
6390 xfree (trigger_func_name
);
6394 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6395 set_breakpoint_count (breakpoint_count
+ 1);
6396 b
->number
= breakpoint_count
;
6397 b
->cond_string
= (cond_string
== NULL
) ?
6398 NULL
: savestring (cond_string
, strlen (cond_string
));
6400 b
->addr_string
= trigger_func_name
;
6401 b
->enable_state
= bp_enabled
;
6402 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6403 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6410 /* Deal with "catch catch" and "catch throw" commands */
6413 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6414 int tempflag
, int from_tty
)
6416 char *cond_string
= NULL
;
6417 struct symtab_and_line
*sal
= NULL
;
6419 ep_skip_leading_whitespace (&arg
);
6421 cond_string
= ep_parse_optional_if_clause (&arg
);
6423 if ((*arg
!= '\0') && !isspace (*arg
))
6424 error (_("Junk at end of arguments."));
6426 if ((ex_event
!= EX_EVENT_THROW
) &&
6427 (ex_event
!= EX_EVENT_CATCH
))
6428 error (_("Unsupported or unknown exception event; cannot catch it"));
6430 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6433 warning (_("Unsupported with this platform/compiler combination."));
6436 /* Create a breakpoint struct for Ada exception catchpoints. */
6439 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6443 struct expression
*cond
,
6444 struct breakpoint_ops
*ops
,
6448 struct breakpoint
*b
;
6452 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6453 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6454 version for exception catchpoints, because two catchpoints
6455 used for different exception names will use the same address.
6456 In this case, a "breakpoint ... also set at..." warning is
6457 unproductive. Besides. the warning phrasing is also a bit
6458 inapropriate, we should use the word catchpoint, and tell
6459 the user what type of catchpoint it is. The above is good
6460 enough for now, though. */
6463 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6464 set_breakpoint_count (breakpoint_count
+ 1);
6466 b
->enable_state
= bp_enabled
;
6467 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6468 b
->number
= breakpoint_count
;
6469 b
->ignore_count
= 0;
6470 b
->loc
->cond
= cond
;
6471 b
->addr_string
= addr_string
;
6472 b
->language
= language_ada
;
6473 b
->cond_string
= cond_string
;
6474 b
->exp_string
= exp_string
;
6481 /* Implement the "catch exception" command. */
6484 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6486 struct symtab_and_line sal
;
6488 char *addr_string
= NULL
;
6489 char *exp_string
= NULL
;
6490 char *cond_string
= NULL
;
6491 struct expression
*cond
= NULL
;
6492 struct breakpoint_ops
*ops
= NULL
;
6494 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6495 &cond_string
, &cond
, &ops
);
6496 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6497 cond_string
, cond
, ops
, tempflag
,
6501 /* Implement the "catch assert" command. */
6504 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6506 struct symtab_and_line sal
;
6507 char *addr_string
= NULL
;
6508 struct breakpoint_ops
*ops
= NULL
;
6510 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6511 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6512 tempflag
, from_tty
);
6516 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6519 /* The first argument may be an event name, such as "start" or "load".
6520 If so, then handle it as such. If it doesn't match an event name,
6521 then attempt to interpret it as an exception name. (This latter is
6522 the v4.16-and-earlier GDB meaning of the "catch" command.)
6524 First, try to find the bounds of what might be an event name. */
6525 char *arg1_start
= arg
;
6529 if (arg1_start
== NULL
)
6531 /* Old behaviour was to use pre-v-4.16 syntax */
6532 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6534 /* Now, this is not allowed */
6535 error (_("Catch requires an event name."));
6538 arg1_end
= ep_find_event_name_end (arg1_start
);
6539 if (arg1_end
== NULL
)
6540 error (_("catch requires an event"));
6541 arg1_length
= arg1_end
+ 1 - arg1_start
;
6543 /* Try to match what we found against known event names. */
6544 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6546 error (_("Catch of signal not yet implemented"));
6548 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6550 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6551 tempflag
, from_tty
);
6553 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6555 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6556 tempflag
, from_tty
);
6558 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6560 error (_("Catch of thread_start not yet implemented"));
6562 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6564 error (_("Catch of thread_exit not yet implemented"));
6566 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6568 error (_("Catch of thread_join not yet implemented"));
6570 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6572 error (_("Catch of start not yet implemented"));
6574 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6576 error (_("Catch of exit not yet implemented"));
6578 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6580 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6582 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6584 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6586 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6588 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6590 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6592 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6594 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6596 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6598 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6600 error (_("Catch of stop not yet implemented"));
6602 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6604 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6607 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6609 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6612 /* This doesn't appear to be an event name */
6616 /* Pre-v.4.16 behaviour was to treat the argument
6617 as the name of an exception */
6618 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6619 /* Now this is not allowed */
6620 error (_("Unknown event kind specified for catch"));
6626 catch_command (char *arg
, int from_tty
)
6628 catch_command_1 (arg
, 0, from_tty
);
6633 tcatch_command (char *arg
, int from_tty
)
6635 catch_command_1 (arg
, 1, from_tty
);
6638 /* Delete breakpoints by address or line. */
6641 clear_command (char *arg
, int from_tty
)
6643 struct breakpoint
*b
;
6644 VEC(breakpoint_p
) *found
= 0;
6647 struct symtabs_and_lines sals
;
6648 struct symtab_and_line sal
;
6653 sals
= decode_line_spec (arg
, 1);
6658 sals
.sals
= (struct symtab_and_line
*)
6659 xmalloc (sizeof (struct symtab_and_line
));
6660 make_cleanup (xfree
, sals
.sals
);
6661 init_sal (&sal
); /* initialize to zeroes */
6662 sal
.line
= default_breakpoint_line
;
6663 sal
.symtab
= default_breakpoint_symtab
;
6664 sal
.pc
= default_breakpoint_address
;
6665 if (sal
.symtab
== 0)
6666 error (_("No source file specified."));
6674 /* We don't call resolve_sal_pc here. That's not
6675 as bad as it seems, because all existing breakpoints
6676 typically have both file/line and pc set. So, if
6677 clear is given file/line, we can match this to existing
6678 breakpoint without obtaining pc at all.
6680 We only support clearing given the address explicitly
6681 present in breakpoint table. Say, we've set breakpoint
6682 at file:line. There were several PC values for that file:line,
6683 due to optimization, all in one block.
6684 We've picked one PC value. If "clear" is issued with another
6685 PC corresponding to the same file:line, the breakpoint won't
6686 be cleared. We probably can still clear the breakpoint, but
6687 since the other PC value is never presented to user, user
6688 can only find it by guessing, and it does not seem important
6691 /* For each line spec given, delete bps which correspond
6692 to it. Do it in two passes, solely to preserve the current
6693 behavior that from_tty is forced true if we delete more than
6697 for (i
= 0; i
< sals
.nelts
; i
++)
6699 /* If exact pc given, clear bpts at that pc.
6700 If line given (pc == 0), clear all bpts on specified line.
6701 If defaulting, clear all bpts on default line
6704 defaulting sal.pc != 0 tests to do
6709 1 0 <can't happen> */
6713 /* Find all matching breakpoints and add them to
6718 /* Are we going to delete b? */
6719 if (b
->type
!= bp_none
6720 && b
->type
!= bp_watchpoint
6721 && b
->type
!= bp_hardware_watchpoint
6722 && b
->type
!= bp_read_watchpoint
6723 && b
->type
!= bp_access_watchpoint
)
6725 struct bp_location
*loc
= b
->loc
;
6726 for (; loc
; loc
= loc
->next
)
6728 int pc_match
= sal
.pc
6729 && (loc
->address
== sal
.pc
)
6730 && (!section_is_overlay (loc
->section
)
6731 || loc
->section
== sal
.section
);
6732 int line_match
= ((default_match
|| (0 == sal
.pc
))
6733 && b
->source_file
!= NULL
6734 && sal
.symtab
!= NULL
6735 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6736 && b
->line_number
== sal
.line
);
6737 if (pc_match
|| line_match
)
6746 VEC_safe_push(breakpoint_p
, found
, b
);
6749 /* Now go thru the 'found' chain and delete them. */
6750 if (VEC_empty(breakpoint_p
, found
))
6753 error (_("No breakpoint at %s."), arg
);
6755 error (_("No breakpoint at this line."));
6758 if (VEC_length(breakpoint_p
, found
) > 1)
6759 from_tty
= 1; /* Always report if deleted more than one */
6762 if (VEC_length(breakpoint_p
, found
) == 1)
6763 printf_unfiltered (_("Deleted breakpoint "));
6765 printf_unfiltered (_("Deleted breakpoints "));
6767 breakpoints_changed ();
6769 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6772 printf_unfiltered ("%d ", b
->number
);
6773 delete_breakpoint (b
);
6776 putchar_unfiltered ('\n');
6779 /* Delete breakpoint in BS if they are `delete' breakpoints and
6780 all breakpoints that are marked for deletion, whether hit or not.
6781 This is called after any breakpoint is hit, or after errors. */
6784 breakpoint_auto_delete (bpstat bs
)
6786 struct breakpoint
*b
, *temp
;
6788 for (; bs
; bs
= bs
->next
)
6789 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6791 delete_breakpoint (bs
->breakpoint_at
->owner
);
6793 ALL_BREAKPOINTS_SAFE (b
, temp
)
6795 if (b
->disposition
== disp_del_at_next_stop
)
6796 delete_breakpoint (b
);
6800 /* Remove locations of breakpoint BPT from
6801 the global list of breakpoint locations. */
6804 unlink_locations_from_global_list (struct breakpoint
*bpt
)
6806 /* This code assumes that the locations
6807 of a breakpoint are found in the global list
6808 in the same order, but not necessary adjacent. */
6809 struct bp_location
**tmp
= &bp_location_chain
;
6810 struct bp_location
*here
= bpt
->loc
;
6815 for (; *tmp
&& here
;)
6819 *tmp
= here
->global_next
;
6824 tmp
= &((*tmp
)->global_next
);
6829 /* Delete a breakpoint and clean up all traces of it in the data
6833 delete_breakpoint (struct breakpoint
*bpt
)
6835 struct breakpoint
*b
;
6837 struct bp_location
*loc
;
6839 gdb_assert (bpt
!= NULL
);
6841 /* Has this bp already been deleted? This can happen because multiple
6842 lists can hold pointers to bp's. bpstat lists are especial culprits.
6844 One example of this happening is a watchpoint's scope bp. When the
6845 scope bp triggers, we notice that the watchpoint is out of scope, and
6846 delete it. We also delete its scope bp. But the scope bp is marked
6847 "auto-deleting", and is already on a bpstat. That bpstat is then
6848 checked for auto-deleting bp's, which are deleted.
6850 A real solution to this problem might involve reference counts in bp's,
6851 and/or giving them pointers back to their referencing bpstat's, and
6852 teaching delete_breakpoint to only free a bp's storage when no more
6853 references were extent. A cheaper bandaid was chosen. */
6854 if (bpt
->type
== bp_none
)
6857 if (deprecated_delete_breakpoint_hook
)
6858 deprecated_delete_breakpoint_hook (bpt
);
6859 breakpoint_delete_event (bpt
->number
);
6861 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6864 remove_breakpoint (loc
, mark_inserted
);
6869 if (loc
->function_name
)
6870 xfree (loc
->function_name
);
6873 if (breakpoint_chain
== bpt
)
6874 breakpoint_chain
= bpt
->next
;
6879 b
->next
= bpt
->next
;
6883 unlink_locations_from_global_list (bpt
);
6885 check_duplicates (bpt
);
6887 if (bpt
->type
!= bp_hardware_watchpoint
6888 && bpt
->type
!= bp_read_watchpoint
6889 && bpt
->type
!= bp_access_watchpoint
6890 && bpt
->type
!= bp_catch_fork
6891 && bpt
->type
!= bp_catch_vfork
6892 && bpt
->type
!= bp_catch_exec
)
6893 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6895 /* If this breakpoint location was inserted, and there is
6896 another breakpoint at the same address, we need to
6897 insert the other breakpoint. */
6900 struct bp_location
*loc2
;
6901 ALL_BP_LOCATIONS (loc2
)
6902 if (loc2
->address
== loc
->address
6903 && loc2
->section
== loc
->section
6905 && loc2
->owner
->enable_state
!= bp_disabled
6907 && !loc2
->shlib_disabled
6908 && loc2
->owner
->enable_state
!= bp_call_disabled
)
6912 /* We should never reach this point if there is a permanent
6913 breakpoint at the same address as the one being deleted.
6914 If there is a permanent breakpoint somewhere, it should
6915 always be the only one inserted. */
6916 if (loc2
->owner
->enable_state
== bp_permanent
)
6917 internal_error (__FILE__
, __LINE__
,
6918 _("another breakpoint was inserted on top of "
6919 "a permanent breakpoint"));
6921 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
6922 loc2
->target_info
.placed_address
= loc2
->address
;
6923 if (b
->type
== bp_hardware_breakpoint
)
6924 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
6926 val
= target_insert_breakpoint (&loc2
->target_info
);
6928 /* If there was an error in the insert, print a message, then stop execution. */
6931 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6932 make_cleanup_ui_file_delete (tmp_error_stream
);
6935 if (b
->type
== bp_hardware_breakpoint
)
6937 fprintf_unfiltered (tmp_error_stream
,
6938 "Cannot insert hardware breakpoint %d.\n"
6939 "You may have requested too many hardware breakpoints.\n",
6944 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6945 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6946 fputs_filtered (paddress (loc2
->address
),
6948 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6949 safe_strerror (val
));
6952 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6953 target_terminal_ours_for_output ();
6954 error_stream(tmp_error_stream
);
6962 free_command_lines (&bpt
->commands
);
6963 if (bpt
->cond_string
!= NULL
)
6964 xfree (bpt
->cond_string
);
6965 if (bpt
->addr_string
!= NULL
)
6966 xfree (bpt
->addr_string
);
6967 if (bpt
->exp
!= NULL
)
6969 if (bpt
->exp_string
!= NULL
)
6970 xfree (bpt
->exp_string
);
6971 if (bpt
->val
!= NULL
)
6972 value_free (bpt
->val
);
6973 if (bpt
->source_file
!= NULL
)
6974 xfree (bpt
->source_file
);
6975 if (bpt
->dll_pathname
!= NULL
)
6976 xfree (bpt
->dll_pathname
);
6977 if (bpt
->triggered_dll_pathname
!= NULL
)
6978 xfree (bpt
->triggered_dll_pathname
);
6979 if (bpt
->exec_pathname
!= NULL
)
6980 xfree (bpt
->exec_pathname
);
6982 /* Be sure no bpstat's are pointing at it after it's been freed. */
6983 /* FIXME, how can we find all bpstat's?
6984 We just check stop_bpstat for now. Note that we cannot just
6985 remove bpstats pointing at bpt from the stop_bpstat list
6986 entirely, as breakpoint commands are associated with the bpstat;
6987 if we remove it here, then the later call to
6988 bpstat_do_actions (&stop_bpstat);
6989 in event-top.c won't do anything, and temporary breakpoints
6990 with commands won't work. */
6991 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6992 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
6994 bs
->breakpoint_at
= NULL
;
6996 /* bs->commands will be freed later. */
6998 /* On the chance that someone will soon try again to delete this same
6999 bp, we mark it as deleted before freeing its storage. */
7000 bpt
->type
= bp_none
;
7002 for (loc
= bpt
->loc
; loc
;)
7004 struct bp_location
*loc_next
= loc
->next
;
7012 do_delete_breakpoint_cleanup (void *b
)
7014 delete_breakpoint (b
);
7018 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7020 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7024 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7026 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7030 delete_command (char *arg
, int from_tty
)
7032 struct breakpoint
*b
, *temp
;
7038 int breaks_to_delete
= 0;
7040 /* Delete all breakpoints if no argument.
7041 Do not delete internal or call-dummy breakpoints, these
7042 have to be deleted with an explicit breakpoint number argument. */
7045 if (b
->type
!= bp_call_dummy
&&
7046 b
->type
!= bp_shlib_event
&&
7047 b
->type
!= bp_thread_event
&&
7048 b
->type
!= bp_overlay_event
&&
7051 breaks_to_delete
= 1;
7056 /* Ask user only if there are some breakpoints to delete. */
7058 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7060 ALL_BREAKPOINTS_SAFE (b
, temp
)
7062 if (b
->type
!= bp_call_dummy
&&
7063 b
->type
!= bp_shlib_event
&&
7064 b
->type
!= bp_thread_event
&&
7065 b
->type
!= bp_overlay_event
&&
7067 delete_breakpoint (b
);
7072 map_breakpoint_numbers (arg
, delete_breakpoint
);
7076 all_locations_are_pending (struct bp_location
*loc
)
7078 for (; loc
; loc
= loc
->next
)
7079 if (!loc
->shlib_disabled
)
7085 update_breakpoint_locations (struct breakpoint
*b
,
7086 struct symtabs_and_lines sals
)
7090 struct bp_location
*existing_locations
= b
->loc
;
7092 /* If there's no new locations, and all existing locations
7093 are pending, don't do anything. This optimizes
7094 the common case where all locations are in the same
7095 shared library, that was unloaded. We'd like to
7096 retain the location, so that when the library
7097 is loaded again, we don't loose the enabled/disabled
7098 status of the individual locations. */
7099 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7102 unlink_locations_from_global_list (b
);
7105 for (i
= 0; i
< sals
.nelts
; ++i
)
7107 struct bp_location
*new_loc
=
7108 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7110 /* Reparse conditions, they might contain references to the
7112 if (b
->cond_string
!= NULL
)
7114 struct gdb_exception e
;
7117 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7119 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7124 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7125 b
->number
, e
.message
);
7126 new_loc
->enabled
= 0;
7130 if (b
->source_file
!= NULL
)
7131 xfree (b
->source_file
);
7132 if (sals
.sals
[i
].symtab
== NULL
)
7133 b
->source_file
= NULL
;
7136 savestring (sals
.sals
[i
].symtab
->filename
,
7137 strlen (sals
.sals
[i
].symtab
->filename
));
7139 if (b
->line_number
== 0)
7140 b
->line_number
= sals
.sals
[i
].line
;
7143 /* If possible, carry over 'disable' status from existing breakpoints. */
7145 struct bp_location
*e
= existing_locations
;
7146 for (; e
; e
= e
->next
)
7148 if (!e
->enabled
&& e
->function_name
)
7150 struct bp_location
*l
= b
->loc
;
7151 for (; l
; l
= l
->next
)
7152 if (l
->function_name
7153 && strcmp (e
->function_name
, l
->function_name
) == 0)
7162 while (existing_locations
)
7164 struct bp_location
*next
= existing_locations
->next
;
7165 free_bp_location (existing_locations
);
7166 existing_locations
= next
;
7171 /* Reset a breakpoint given it's struct breakpoint * BINT.
7172 The value we return ends up being the return value from catch_errors.
7173 Unused in this case. */
7176 breakpoint_re_set_one (void *bint
)
7178 /* get past catch_errs */
7179 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7183 int *not_found_ptr
= ¬_found
;
7184 struct symtabs_and_lines sals
= {};
7185 struct symtabs_and_lines expanded
;
7187 enum enable_state save_enable
;
7188 struct gdb_exception e
;
7194 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7198 case bp_hardware_breakpoint
:
7200 case bp_catch_unload
:
7201 if (b
->addr_string
== NULL
)
7203 /* Anything without a string can't be re-set. */
7204 delete_breakpoint (b
);
7208 set_language (b
->language
);
7209 input_radix
= b
->input_radix
;
7211 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7213 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7218 int not_found_and_ok
= 0;
7219 /* For pending breakpoints, it's expected that parsing
7220 will fail until the right shared library is loaded.
7221 User has already told to create pending breakpoints and
7222 don't need extra messages. If breakpoint is in bp_shlib_disabled
7223 state, then user already saw the message about that breakpoint
7224 being disabled, and don't want to see more errors. */
7226 && (b
->condition_not_parsed
7227 || (b
->loc
&& b
->loc
->shlib_disabled
)
7228 || b
->enable_state
== bp_disabled
))
7229 not_found_and_ok
= 1;
7231 if (!not_found_and_ok
)
7233 /* We surely don't want to warn about the same breakpoint
7234 10 times. One solution, implemented here, is disable
7235 the breakpoint on error. Another solution would be to
7236 have separate 'warning emitted' flag. Since this
7237 happens only when a binary has changed, I don't know
7238 which approach is better. */
7239 b
->enable_state
= bp_disabled
;
7240 throw_exception (e
);
7247 gdb_assert (sals
.nelts
== 1);
7248 resolve_sal_pc (&sals
.sals
[0]);
7249 if (b
->condition_not_parsed
&& s
&& s
[0])
7251 char *cond_string
= 0;
7253 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7254 &cond_string
, &thread
);
7256 b
->cond_string
= cond_string
;
7258 b
->condition_not_parsed
= 0;
7260 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7261 update_breakpoint_locations (b
, expanded
);
7263 /* Now that this is re-enabled, check_duplicates
7265 check_duplicates (b
);
7271 case bp_hardware_watchpoint
:
7272 case bp_read_watchpoint
:
7273 case bp_access_watchpoint
:
7274 /* Watchpoint can be either on expression using entirely global variables,
7275 or it can be on local variables.
7277 Watchpoints of the first kind are never auto-deleted, and even persist
7278 across program restarts. Since they can use variables from shared
7279 libraries, we need to reparse expression as libraries are loaded
7282 Watchpoints on local variables can also change meaning as result
7283 of solib event. For example, if a watchpoint uses both a local and
7284 a global variables in expression, it's a local watchpoint, but
7285 unloading of a shared library will make the expression invalid.
7286 This is not a very common use case, but we still re-evaluate
7287 expression, to avoid surprises to the user.
7289 Note that for local watchpoints, we re-evaluate it only if
7290 watchpoints frame id is still valid. If it's not, it means
7291 the watchpoint is out of scope and will be deleted soon. In fact,
7292 I'm not sure we'll ever be called in this case.
7294 If a local watchpoint's frame id is still valid, then
7295 b->exp_valid_block is likewise valid, and we can safely use it.
7297 Don't do anything about disabled watchpoints, since they will
7298 be reevaluated again when enabled. */
7299 update_watchpoint (b
, 1 /* reparse */);
7301 /* We needn't really do anything to reset these, since the mask
7302 that requests them is unaffected by e.g., new libraries being
7305 case bp_catch_vfork
:
7310 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7312 /* Delete longjmp and overlay event breakpoints; they will be
7313 reset later by breakpoint_re_set. */
7315 case bp_longjmp_resume
:
7316 case bp_overlay_event
:
7317 delete_breakpoint (b
);
7320 /* This breakpoint is special, it's set up when the inferior
7321 starts and we really don't want to touch it. */
7322 case bp_shlib_event
:
7324 /* Like bp_shlib_event, this breakpoint type is special.
7325 Once it is set up, we do not want to touch it. */
7326 case bp_thread_event
:
7328 /* Keep temporary breakpoints, which can be encountered when we step
7329 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7330 Otherwise these should have been blown away via the cleanup chain
7331 or by breakpoint_init_inferior when we rerun the executable. */
7334 case bp_watchpoint_scope
:
7336 case bp_step_resume
:
7343 /* Re-set all breakpoints after symbols have been re-loaded. */
7345 breakpoint_re_set (void)
7347 struct breakpoint
*b
, *temp
;
7348 enum language save_language
;
7349 int save_input_radix
;
7351 save_language
= current_language
->la_language
;
7352 save_input_radix
= input_radix
;
7353 ALL_BREAKPOINTS_SAFE (b
, temp
)
7355 /* Format possible error msg */
7356 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7358 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7359 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7360 do_cleanups (cleanups
);
7362 set_language (save_language
);
7363 input_radix
= save_input_radix
;
7365 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7367 create_longjmp_breakpoint ("longjmp");
7368 create_longjmp_breakpoint ("_longjmp");
7369 create_longjmp_breakpoint ("siglongjmp");
7370 create_longjmp_breakpoint ("_siglongjmp");
7371 create_longjmp_breakpoint (NULL
);
7374 create_overlay_event_breakpoint ("_ovly_debug_event");
7377 /* Reset the thread number of this breakpoint:
7379 - If the breakpoint is for all threads, leave it as-is.
7380 - Else, reset it to the current thread for inferior_ptid. */
7382 breakpoint_re_set_thread (struct breakpoint
*b
)
7384 if (b
->thread
!= -1)
7386 if (in_thread_list (inferior_ptid
))
7387 b
->thread
= pid_to_thread_id (inferior_ptid
);
7391 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7392 If from_tty is nonzero, it prints a message to that effect,
7393 which ends with a period (no newline). */
7396 set_ignore_count (int bptnum
, int count
, int from_tty
)
7398 struct breakpoint
*b
;
7404 if (b
->number
== bptnum
)
7406 b
->ignore_count
= count
;
7410 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7412 else if (count
== 1)
7413 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7416 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7419 breakpoints_changed ();
7420 breakpoint_modify_event (b
->number
);
7424 error (_("No breakpoint number %d."), bptnum
);
7427 /* Clear the ignore counts of all breakpoints. */
7429 breakpoint_clear_ignore_counts (void)
7431 struct breakpoint
*b
;
7434 b
->ignore_count
= 0;
7437 /* Command to set ignore-count of breakpoint N to COUNT. */
7440 ignore_command (char *args
, int from_tty
)
7446 error_no_arg (_("a breakpoint number"));
7448 num
= get_number (&p
);
7450 error (_("bad breakpoint number: '%s'"), args
);
7452 error (_("Second argument (specified ignore-count) is missing."));
7454 set_ignore_count (num
,
7455 longest_to_int (value_as_long (parse_and_eval (p
))),
7458 printf_filtered ("\n");
7461 /* Call FUNCTION on each of the breakpoints
7462 whose numbers are given in ARGS. */
7465 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7470 struct breakpoint
*b
, *tmp
;
7474 error_no_arg (_("one or more breakpoint numbers"));
7481 num
= get_number_or_range (&p1
);
7484 warning (_("bad breakpoint number at or near '%s'"), p
);
7488 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7489 if (b
->number
== num
)
7491 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7494 if (related_breakpoint
)
7495 function (related_breakpoint
);
7499 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7505 static struct bp_location
*
7506 find_location_by_number (char *number
)
7508 char *dot
= strchr (number
, '.');
7512 struct breakpoint
*b
;
7513 struct bp_location
*loc
;
7518 bp_num
= get_number_or_range (&p1
);
7520 error (_("Bad breakpoint number '%s'"), number
);
7523 if (b
->number
== bp_num
)
7528 if (!b
|| b
->number
!= bp_num
)
7529 error (_("Bad breakpoint number '%s'"), number
);
7532 loc_num
= get_number_or_range (&p1
);
7534 error (_("Bad breakpoint location number '%s'"), number
);
7538 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7541 error (_("Bad breakpoint location number '%s'"), dot
+1);
7547 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7548 If from_tty is nonzero, it prints a message to that effect,
7549 which ends with a period (no newline). */
7552 disable_breakpoint (struct breakpoint
*bpt
)
7554 /* Never disable a watchpoint scope breakpoint; we want to
7555 hit them when we leave scope so we can delete both the
7556 watchpoint and its scope breakpoint at that time. */
7557 if (bpt
->type
== bp_watchpoint_scope
)
7560 /* You can't disable permanent breakpoints. */
7561 if (bpt
->enable_state
== bp_permanent
)
7564 bpt
->enable_state
= bp_disabled
;
7566 check_duplicates (bpt
);
7568 if (deprecated_modify_breakpoint_hook
)
7569 deprecated_modify_breakpoint_hook (bpt
);
7570 breakpoint_modify_event (bpt
->number
);
7574 disable_command (char *args
, int from_tty
)
7576 struct breakpoint
*bpt
;
7578 ALL_BREAKPOINTS (bpt
)
7582 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7587 case bp_catch_unload
:
7589 case bp_catch_vfork
:
7591 case bp_hardware_breakpoint
:
7593 case bp_hardware_watchpoint
:
7594 case bp_read_watchpoint
:
7595 case bp_access_watchpoint
:
7596 disable_breakpoint (bpt
);
7600 else if (strchr (args
, '.'))
7602 struct bp_location
*loc
= find_location_by_number (args
);
7605 check_duplicates (loc
->owner
);
7608 map_breakpoint_numbers (args
, disable_breakpoint
);
7612 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7614 int target_resources_ok
, other_type_used
;
7617 if (bpt
->type
== bp_hardware_breakpoint
)
7620 i
= hw_breakpoint_used_count ();
7621 target_resources_ok
=
7622 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7624 if (target_resources_ok
== 0)
7625 error (_("No hardware breakpoint support in the target."));
7626 else if (target_resources_ok
< 0)
7627 error (_("Hardware breakpoints used exceeds limit."));
7630 if (bpt
->type
== bp_watchpoint
||
7631 bpt
->type
== bp_hardware_watchpoint
||
7632 bpt
->type
== bp_read_watchpoint
||
7633 bpt
->type
== bp_access_watchpoint
)
7635 struct frame_id saved_frame_id
;
7637 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7638 if (bpt
->exp_valid_block
!= NULL
)
7640 struct frame_info
*fr
=
7641 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7644 printf_filtered (_("\
7645 Cannot enable watchpoint %d because the block in which its expression\n\
7646 is valid is not currently in scope.\n"), bpt
->number
);
7653 value_free (bpt
->val
);
7654 mark
= value_mark ();
7655 bpt
->val
= evaluate_expression (bpt
->exp
);
7656 release_value (bpt
->val
);
7657 if (value_lazy (bpt
->val
))
7658 value_fetch_lazy (bpt
->val
);
7660 if (bpt
->type
== bp_hardware_watchpoint
||
7661 bpt
->type
== bp_read_watchpoint
||
7662 bpt
->type
== bp_access_watchpoint
)
7664 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7665 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7667 /* Hack around 'unused var' error for some targets here */
7668 (void) mem_cnt
, (void) i
;
7669 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7670 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7671 /* we can consider of type is bp_hardware_watchpoint, convert to
7672 bp_watchpoint in the following condition */
7673 if (target_resources_ok
< 0)
7675 printf_filtered (_("\
7676 Cannot enable watchpoint %d because target watch resources\n\
7677 have been allocated for other watchpoints.\n"), bpt
->number
);
7678 value_free_to_mark (mark
);
7683 select_frame (frame_find_by_id (saved_frame_id
));
7684 value_free_to_mark (mark
);
7687 if (bpt
->enable_state
!= bp_permanent
)
7688 bpt
->enable_state
= bp_enabled
;
7689 bpt
->disposition
= disposition
;
7690 check_duplicates (bpt
);
7691 breakpoints_changed ();
7693 if (deprecated_modify_breakpoint_hook
)
7694 deprecated_modify_breakpoint_hook (bpt
);
7695 breakpoint_modify_event (bpt
->number
);
7700 enable_breakpoint (struct breakpoint
*bpt
)
7702 do_enable_breakpoint (bpt
, bpt
->disposition
);
7705 /* The enable command enables the specified breakpoints (or all defined
7706 breakpoints) so they once again become (or continue to be) effective
7707 in stopping the inferior. */
7710 enable_command (char *args
, int from_tty
)
7712 struct breakpoint
*bpt
;
7714 ALL_BREAKPOINTS (bpt
)
7718 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7723 case bp_catch_unload
:
7725 case bp_catch_vfork
:
7727 case bp_hardware_breakpoint
:
7729 case bp_hardware_watchpoint
:
7730 case bp_read_watchpoint
:
7731 case bp_access_watchpoint
:
7732 enable_breakpoint (bpt
);
7736 else if (strchr (args
, '.'))
7738 struct bp_location
*loc
= find_location_by_number (args
);
7741 check_duplicates (loc
->owner
);
7744 map_breakpoint_numbers (args
, enable_breakpoint
);
7748 enable_once_breakpoint (struct breakpoint
*bpt
)
7750 do_enable_breakpoint (bpt
, disp_disable
);
7754 enable_once_command (char *args
, int from_tty
)
7756 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7760 enable_delete_breakpoint (struct breakpoint
*bpt
)
7762 do_enable_breakpoint (bpt
, disp_del
);
7766 enable_delete_command (char *args
, int from_tty
)
7768 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7772 set_breakpoint_cmd (char *args
, int from_tty
)
7777 show_breakpoint_cmd (char *args
, int from_tty
)
7781 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7783 struct symtabs_and_lines
7784 decode_line_spec_1 (char *string
, int funfirstline
)
7786 struct symtabs_and_lines sals
;
7788 error (_("Empty line specification."));
7789 if (default_breakpoint_valid
)
7790 sals
= decode_line_1 (&string
, funfirstline
,
7791 default_breakpoint_symtab
,
7792 default_breakpoint_line
,
7793 (char ***) NULL
, NULL
);
7795 sals
= decode_line_1 (&string
, funfirstline
,
7796 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7798 error (_("Junk at end of line specification: %s"), string
);
7802 /* Create and insert a raw software breakpoint at PC. Return an
7803 identifier, which should be used to remove the breakpoint later.
7804 In general, places which call this should be using something on the
7805 breakpoint chain instead; this function should be eliminated
7809 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7811 struct bp_target_info
*bp_tgt
;
7813 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7814 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7816 bp_tgt
->placed_address
= pc
;
7817 if (target_insert_breakpoint (bp_tgt
) != 0)
7819 /* Could not insert the breakpoint. */
7827 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7830 deprecated_remove_raw_breakpoint (void *bp
)
7832 struct bp_target_info
*bp_tgt
= bp
;
7835 ret
= target_remove_breakpoint (bp_tgt
);
7841 /* One (or perhaps two) breakpoints used for software single stepping. */
7843 static void *single_step_breakpoints
[2];
7845 /* Create and insert a breakpoint for software single step. */
7848 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7852 if (single_step_breakpoints
[0] == NULL
)
7853 bpt_p
= &single_step_breakpoints
[0];
7856 gdb_assert (single_step_breakpoints
[1] == NULL
);
7857 bpt_p
= &single_step_breakpoints
[1];
7860 /* NOTE drow/2006-04-11: A future improvement to this function would be
7861 to only create the breakpoints once, and actually put them on the
7862 breakpoint chain. That would let us use set_raw_breakpoint. We could
7863 adjust the addresses each time they were needed. Doing this requires
7864 corresponding changes elsewhere where single step breakpoints are
7865 handled, however. So, for now, we use this. */
7867 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7869 error (_("Could not insert single-step breakpoint at 0x%s"),
7870 paddr_nz (next_pc
));
7873 /* Remove and delete any breakpoints used for software single step. */
7876 remove_single_step_breakpoints (void)
7878 gdb_assert (single_step_breakpoints
[0] != NULL
);
7880 /* See insert_single_step_breakpoint for more about this deprecated
7882 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7883 single_step_breakpoints
[0] = NULL
;
7885 if (single_step_breakpoints
[1] != NULL
)
7887 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7888 single_step_breakpoints
[1] = NULL
;
7892 /* Check whether a software single-step breakpoint is inserted at PC. */
7895 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
7899 for (i
= 0; i
< 2; i
++)
7901 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
7902 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
7910 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7911 It is defined as a macro to prevent duplication.
7912 COMMAND should be a string constant containing the name of the command. */
7913 #define BREAK_ARGS_HELP(command) \
7914 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7915 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7916 If a line number is specified, break at start of code for that line.\n\
7917 If a function is specified, break at start of code for that function.\n\
7918 If an address is specified, break at that exact address.\n\
7919 With no LOCATION, uses current execution address of selected stack frame.\n\
7920 This is useful for breaking on return to a stack frame.\n\
7922 THREADNUM is the number from \"info threads\".\n\
7923 CONDITION is a boolean expression.\n\
7925 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7927 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7930 _initialize_breakpoint (void)
7932 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7933 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7934 struct cmd_list_element
*c
;
7936 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7938 breakpoint_chain
= 0;
7939 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7940 before a breakpoint is set. */
7941 breakpoint_count
= 0;
7943 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
7944 Set ignore-count of breakpoint number N to COUNT.\n\
7945 Usage is `ignore N COUNT'."));
7947 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7949 add_com ("commands", class_breakpoint
, commands_command
, _("\
7950 Set commands to be executed when a breakpoint is hit.\n\
7951 Give breakpoint number as argument after \"commands\".\n\
7952 With no argument, the targeted breakpoint is the last one set.\n\
7953 The commands themselves follow starting on the next line.\n\
7954 Type a line containing \"end\" to indicate the end of them.\n\
7955 Give \"silent\" as the first line to make the breakpoint silent;\n\
7956 then no output is printed when it is hit, except what the commands print."));
7958 add_com ("condition", class_breakpoint
, condition_command
, _("\
7959 Specify breakpoint number N to break only if COND is true.\n\
7960 Usage is `condition N COND', where N is an integer and COND is an\n\
7961 expression to be evaluated whenever breakpoint N is reached."));
7963 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
7964 Set a temporary breakpoint.\n\
7965 Like \"break\" except the breakpoint is only temporary,\n\
7966 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7967 by using \"enable delete\" on the breakpoint number.\n\
7969 BREAK_ARGS_HELP ("tbreak")));
7970 set_cmd_completer (c
, location_completer
);
7972 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
7973 Set a hardware assisted breakpoint.\n\
7974 Like \"break\" except the breakpoint requires hardware support,\n\
7975 some target hardware may not have this support.\n\
7977 BREAK_ARGS_HELP ("hbreak")));
7978 set_cmd_completer (c
, location_completer
);
7980 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
7981 Set a temporary hardware assisted breakpoint.\n\
7982 Like \"hbreak\" except the breakpoint is only temporary,\n\
7983 so it will be deleted when hit.\n\
7985 BREAK_ARGS_HELP ("thbreak")));
7986 set_cmd_completer (c
, location_completer
);
7988 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
7989 Enable some breakpoints.\n\
7990 Give breakpoint numbers (separated by spaces) as arguments.\n\
7991 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7992 This is used to cancel the effect of the \"disable\" command.\n\
7993 With a subcommand you can enable temporarily."),
7994 &enablelist
, "enable ", 1, &cmdlist
);
7996 add_com ("ab", class_breakpoint
, enable_command
, _("\
7997 Enable some breakpoints.\n\
7998 Give breakpoint numbers (separated by spaces) as arguments.\n\
7999 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8000 This is used to cancel the effect of the \"disable\" command.\n\
8001 With a subcommand you can enable temporarily."));
8003 add_com_alias ("en", "enable", class_breakpoint
, 1);
8005 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8006 Enable some breakpoints.\n\
8007 Give breakpoint numbers (separated by spaces) as arguments.\n\
8008 This is used to cancel the effect of the \"disable\" command.\n\
8009 May be abbreviated to simply \"enable\".\n"),
8010 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8012 add_cmd ("once", no_class
, enable_once_command
, _("\
8013 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8014 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8017 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8018 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8019 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8022 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8023 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8024 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8027 add_cmd ("once", no_class
, enable_once_command
, _("\
8028 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8029 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8032 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8033 Disable some breakpoints.\n\
8034 Arguments are breakpoint numbers with spaces in between.\n\
8035 To disable all breakpoints, give no argument.\n\
8036 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8037 &disablelist
, "disable ", 1, &cmdlist
);
8038 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8039 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8041 add_com ("sb", class_breakpoint
, disable_command
, _("\
8042 Disable some breakpoints.\n\
8043 Arguments are breakpoint numbers with spaces in between.\n\
8044 To disable all breakpoints, give no argument.\n\
8045 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8047 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8048 Disable some breakpoints.\n\
8049 Arguments are breakpoint numbers with spaces in between.\n\
8050 To disable all breakpoints, give no argument.\n\
8051 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8052 This command may be abbreviated \"disable\"."),
8055 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8056 Delete some breakpoints or auto-display expressions.\n\
8057 Arguments are breakpoint numbers with spaces in between.\n\
8058 To delete all breakpoints, give no argument.\n\
8060 Also a prefix command for deletion of other GDB objects.\n\
8061 The \"unset\" command is also an alias for \"delete\"."),
8062 &deletelist
, "delete ", 1, &cmdlist
);
8063 add_com_alias ("d", "delete", class_breakpoint
, 1);
8064 add_com_alias ("del", "delete", class_breakpoint
, 1);
8066 add_com ("db", class_breakpoint
, delete_command
, _("\
8067 Delete some breakpoints.\n\
8068 Arguments are breakpoint numbers with spaces in between.\n\
8069 To delete all breakpoints, give no argument.\n"));
8071 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8072 Delete some breakpoints or auto-display expressions.\n\
8073 Arguments are breakpoint numbers with spaces in between.\n\
8074 To delete all breakpoints, give no argument.\n\
8075 This command may be abbreviated \"delete\"."),
8078 add_com ("clear", class_breakpoint
, clear_command
, _("\
8079 Clear breakpoint at specified line or function.\n\
8080 Argument may be line number, function name, or \"*\" and an address.\n\
8081 If line number is specified, all breakpoints in that line are cleared.\n\
8082 If function is specified, breakpoints at beginning of function are cleared.\n\
8083 If an address is specified, breakpoints at that address are cleared.\n\
8085 With no argument, clears all breakpoints in the line that the selected frame\n\
8088 See also the \"delete\" command which clears breakpoints by number."));
8090 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8091 Set breakpoint at specified line or function.\n"
8092 BREAK_ARGS_HELP ("break")));
8093 set_cmd_completer (c
, location_completer
);
8095 add_com_alias ("b", "break", class_run
, 1);
8096 add_com_alias ("br", "break", class_run
, 1);
8097 add_com_alias ("bre", "break", class_run
, 1);
8098 add_com_alias ("brea", "break", class_run
, 1);
8102 add_com_alias ("ba", "break", class_breakpoint
, 1);
8103 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8108 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8109 Break in function/address or break at a line in the current file."),
8110 &stoplist
, "stop ", 1, &cmdlist
);
8111 add_cmd ("in", class_breakpoint
, stopin_command
,
8112 _("Break in function or address."), &stoplist
);
8113 add_cmd ("at", class_breakpoint
, stopat_command
,
8114 _("Break at a line in the current file."), &stoplist
);
8115 add_com ("status", class_info
, breakpoints_info
, _("\
8116 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8117 The \"Type\" column indicates one of:\n\
8118 \tbreakpoint - normal breakpoint\n\
8119 \twatchpoint - watchpoint\n\
8120 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8121 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8122 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8123 address and file/line number respectively.\n\
8125 Convenience variable \"$_\" and default examine address for \"x\"\n\
8126 are set to the address of the last breakpoint listed unless the command\n\
8127 is prefixed with \"server \".\n\n\
8128 Convenience variable \"$bpnum\" contains the number of the last\n\
8132 add_info ("breakpoints", breakpoints_info
, _("\
8133 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8134 The \"Type\" column indicates one of:\n\
8135 \tbreakpoint - normal breakpoint\n\
8136 \twatchpoint - watchpoint\n\
8137 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8138 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8139 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8140 address and file/line number respectively.\n\
8142 Convenience variable \"$_\" and default examine address for \"x\"\n\
8143 are set to the address of the last breakpoint listed unless the command\n\
8144 is prefixed with \"server \".\n\n\
8145 Convenience variable \"$bpnum\" contains the number of the last\n\
8149 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8150 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8151 The \"Type\" column indicates one of:\n\
8152 \tbreakpoint - normal breakpoint\n\
8153 \twatchpoint - watchpoint\n\
8154 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8155 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8156 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8157 address and file/line number respectively.\n\
8159 Convenience variable \"$_\" and default examine address for \"x\"\n\
8160 are set to the address of the last breakpoint listed unless the command\n\
8161 is prefixed with \"server \".\n\n\
8162 Convenience variable \"$bpnum\" contains the number of the last\n\
8165 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8166 Status of all breakpoints, or breakpoint number NUMBER.\n\
8167 The \"Type\" column indicates one of:\n\
8168 \tbreakpoint - normal breakpoint\n\
8169 \twatchpoint - watchpoint\n\
8170 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8171 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8172 \tuntil - internal breakpoint used by the \"until\" command\n\
8173 \tfinish - internal breakpoint used by the \"finish\" command\n\
8174 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8175 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8176 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8177 address and file/line number respectively.\n\
8179 Convenience variable \"$_\" and default examine address for \"x\"\n\
8180 are set to the address of the last breakpoint listed unless the command\n\
8181 is prefixed with \"server \".\n\n\
8182 Convenience variable \"$bpnum\" contains the number of the last\n\
8184 &maintenanceinfolist
);
8186 add_com ("catch", class_breakpoint
, catch_command
, _("\
8187 Set catchpoints to catch events.\n\
8188 Raised signals may be caught:\n\
8189 \tcatch signal - all signals\n\
8190 \tcatch signal <signame> - a particular signal\n\
8191 Raised exceptions may be caught:\n\
8192 \tcatch throw - all exceptions, when thrown\n\
8193 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8194 \tcatch catch - all exceptions, when caught\n\
8195 \tcatch catch <exceptname> - a particular exception, when caught\n\
8196 Thread or process events may be caught:\n\
8197 \tcatch thread_start - any threads, just after creation\n\
8198 \tcatch thread_exit - any threads, just before expiration\n\
8199 \tcatch thread_join - any threads, just after joins\n\
8200 Process events may be caught:\n\
8201 \tcatch start - any processes, just after creation\n\
8202 \tcatch exit - any processes, just before expiration\n\
8203 \tcatch fork - calls to fork()\n\
8204 \tcatch vfork - calls to vfork()\n\
8205 \tcatch exec - calls to exec()\n\
8206 Dynamically-linked library events may be caught:\n\
8207 \tcatch load - loads of any library\n\
8208 \tcatch load <libname> - loads of a particular library\n\
8209 \tcatch unload - unloads of any library\n\
8210 \tcatch unload <libname> - unloads of a particular library\n\
8211 The act of your program's execution stopping may also be caught:\n\
8213 C++ exceptions may be caught:\n\
8214 \tcatch throw - all exceptions, when thrown\n\
8215 \tcatch catch - all exceptions, when caught\n\
8216 Ada exceptions may be caught:\n\
8217 \tcatch exception - all exceptions, when raised\n\
8218 \tcatch exception <name> - a particular exception, when raised\n\
8219 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8220 \tcatch assert - all failed assertions, when raised\n\
8222 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8223 after a fork or vfork is caught.\n\n\
8224 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8226 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8227 Set temporary catchpoints to catch events.\n\
8228 Args like \"catch\" command.\n\
8229 Like \"catch\" except the catchpoint is only temporary,\n\
8230 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8231 by using \"enable delete\" on the catchpoint number."));
8233 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8234 Set a watchpoint for an expression.\n\
8235 A watchpoint stops execution of your program whenever the value of\n\
8236 an expression changes."));
8237 set_cmd_completer (c
, location_completer
);
8239 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8240 Set a read watchpoint for an expression.\n\
8241 A watchpoint stops execution of your program whenever the value of\n\
8242 an expression is read."));
8243 set_cmd_completer (c
, location_completer
);
8245 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8246 Set a watchpoint for an expression.\n\
8247 A watchpoint stops execution of your program whenever the value of\n\
8248 an expression is either read or written."));
8249 set_cmd_completer (c
, location_completer
);
8251 add_info ("watchpoints", breakpoints_info
,
8252 _("Synonym for ``info breakpoints''."));
8255 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8256 respond to changes - contrary to the description. */
8257 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8258 &can_use_hw_watchpoints
, _("\
8259 Set debugger's willingness to use watchpoint hardware."), _("\
8260 Show debugger's willingness to use watchpoint hardware."), _("\
8261 If zero, gdb will not use hardware for new watchpoints, even if\n\
8262 such is available. (However, any hardware watchpoints that were\n\
8263 created before setting this to nonzero, will continue to use watchpoint\n\
8266 show_can_use_hw_watchpoints
,
8267 &setlist
, &showlist
);
8269 can_use_hw_watchpoints
= 1;
8271 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8272 Breakpoint specific settings\n\
8273 Configure various breakpoint-specific variables such as\n\
8274 pending breakpoint behavior"),
8275 &breakpoint_set_cmdlist
, "set breakpoint ",
8276 0/*allow-unknown*/, &setlist
);
8277 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8278 Breakpoint specific settings\n\
8279 Configure various breakpoint-specific variables such as\n\
8280 pending breakpoint behavior"),
8281 &breakpoint_show_cmdlist
, "show breakpoint ",
8282 0/*allow-unknown*/, &showlist
);
8284 add_setshow_auto_boolean_cmd ("pending", no_class
,
8285 &pending_break_support
, _("\
8286 Set debugger's behavior regarding pending breakpoints."), _("\
8287 Show debugger's behavior regarding pending breakpoints."), _("\
8288 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8289 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8290 an error. If auto, an unrecognized breakpoint location results in a\n\
8291 user-query to see if a pending breakpoint should be created."),
8293 show_pending_break_support
,
8294 &breakpoint_set_cmdlist
,
8295 &breakpoint_show_cmdlist
);
8297 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8299 add_setshow_boolean_cmd ("auto-hw", no_class
,
8300 &automatic_hardware_breakpoints
, _("\
8301 Set automatic usage of hardware breakpoints."), _("\
8302 Show automatic usage of hardware breakpoints."), _("\
8303 If set, the debugger will automatically use hardware breakpoints for\n\
8304 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8305 a warning will be emitted for such breakpoints."),
8307 show_automatic_hardware_breakpoints
,
8308 &breakpoint_set_cmdlist
,
8309 &breakpoint_show_cmdlist
);
8311 automatic_hardware_breakpoints
= 1;