1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
60 #include "gdb-events.h"
61 #include "mi/mi-common.h"
63 /* Prototypes for local functions. */
65 static void until_break_command_continuation (struct continuation_arg
*arg
);
67 static void catch_command_1 (char *, int, int);
69 static void enable_delete_command (char *, int);
71 static void enable_delete_breakpoint (struct breakpoint
*);
73 static void enable_once_command (char *, int);
75 static void enable_once_breakpoint (struct breakpoint
*);
77 static void disable_command (char *, int);
79 static void enable_command (char *, int);
81 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
83 static void ignore_command (char *, int);
85 static int breakpoint_re_set_one (void *);
87 static void clear_command (char *, int);
89 static void catch_command (char *, int);
91 static void watch_command (char *, int);
93 static int can_use_hardware_watchpoint (struct value
*);
95 static void break_command_1 (char *, int, int);
97 static void mention (struct breakpoint
*);
99 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
101 static void check_duplicates (struct breakpoint
*);
103 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
105 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
108 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
110 static void breakpoints_info (char *, int);
112 static void breakpoint_1 (int, int);
114 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
116 static int breakpoint_cond_eval (void *);
118 static void cleanup_executing_breakpoints (void *);
120 static void commands_command (char *, int);
122 static void condition_command (char *, int);
124 static int get_number_trailer (char **, int);
126 void set_breakpoint_count (int);
135 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
137 static enum print_stop_action
print_it_typical (bpstat
);
139 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
143 enum exception_event_kind kind
;
146 args_for_catchpoint_enable
;
148 static int watchpoint_check (void *);
150 static void maintenance_info_breakpoints (char *, int);
152 static void create_longjmp_breakpoint (char *);
154 static void create_overlay_event_breakpoint (char *);
156 static int hw_breakpoint_used_count (void);
158 static int hw_watchpoint_used_count (enum bptype
, int *);
160 static void hbreak_command (char *, int);
162 static void thbreak_command (char *, int);
164 static void watch_command_1 (char *, int, int);
166 static void rwatch_command (char *, int);
168 static void awatch_command (char *, int);
170 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
172 static void create_fork_vfork_event_catchpoint (int tempflag
,
174 enum bptype bp_kind
);
176 static void stop_command (char *arg
, int from_tty
);
178 static void stopin_command (char *arg
, int from_tty
);
180 static void stopat_command (char *arg
, int from_tty
);
182 static char *ep_find_event_name_end (char *arg
);
184 static char *ep_parse_optional_if_clause (char **arg
);
186 static char *ep_parse_optional_filename (char **arg
);
188 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
189 enum exception_event_kind ex_event
,
190 struct symtab_and_line
*sal
);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
193 char *arg
, int tempflag
, int from_tty
);
195 static void tcatch_command (char *arg
, int from_tty
);
197 static void ep_skip_leading_whitespace (char **s
);
199 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
201 static void free_bp_location (struct bp_location
*loc
);
203 static void mark_breakpoints_out (void);
205 static struct bp_location
*
206 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
209 unlink_locations_from_global_list (struct breakpoint
*bpt
);
212 is_hardware_watchpoint (struct breakpoint
*bpt
);
215 bpdisp_text (enum bpdisp disp
)
217 /* NOTE: the following values are a part of MI protocol and represent
218 values of 'disp' field returned when inferior stops at a breakpoint. */
219 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
220 return bpdisps
[(int) disp
];
223 /* Prototypes for exported functions. */
224 /* If FALSE, gdb will not use hardware support for watchpoints, even
225 if such is available. */
226 static int can_use_hw_watchpoints
;
229 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
230 struct cmd_list_element
*c
,
233 fprintf_filtered (file
, _("\
234 Debugger's willingness to use watchpoint hardware is %s.\n"),
238 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
239 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
240 for unrecognized breakpoint locations.
241 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
242 static enum auto_boolean pending_break_support
;
244 show_pending_break_support (struct ui_file
*file
, int from_tty
,
245 struct cmd_list_element
*c
,
248 fprintf_filtered (file
, _("\
249 Debugger's behavior regarding pending breakpoints is %s.\n"),
253 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
254 set with "break" but falling in read-only memory.
255 If 0, gdb will warn about such breakpoints, but won't automatically
256 use hardware breakpoints. */
257 static int automatic_hardware_breakpoints
;
259 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
260 struct cmd_list_element
*c
,
263 fprintf_filtered (file
, _("\
264 Automatic usage of hardware breakpoints is %s.\n"),
269 void _initialize_breakpoint (void);
271 extern int addressprint
; /* Print machine addresses? */
273 /* Are we executing breakpoint commands? */
274 static int executing_breakpoint_commands
;
276 /* Are overlay event breakpoints enabled? */
277 static int overlay_events_enabled
;
279 /* Walk the following statement or block through all breakpoints.
280 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
283 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
285 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
286 for (B = breakpoint_chain; \
287 B ? (TMP=B->next, 1): 0; \
290 /* Similar iterators for the low-level breakpoints. */
292 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
294 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
295 for (B = bp_location_chain; \
296 B ? (TMP=B->global_next, 1): 0; \
299 /* True if breakpoint hit counts should be displayed in breakpoint info. */
301 int show_breakpoint_hit_counts
= 1;
303 /* Chains of all breakpoints defined. */
305 struct breakpoint
*breakpoint_chain
;
307 struct bp_location
*bp_location_chain
;
309 /* Number of last breakpoint made. */
311 int breakpoint_count
;
313 /* Pointer to current exception event record */
314 static struct exception_event_record
*current_exception_event
;
316 /* This function returns a pointer to the string representation of the
317 pathname of the dynamically-linked library that has just been
320 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
321 or undefined results are guaranteed.
323 This string's contents are only valid immediately after the
324 inferior has stopped in the dynamic linker hook, and becomes
325 invalid as soon as the inferior is continued. Clients should make
326 a copy of this string if they wish to continue the inferior and
327 then access the string. */
329 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
330 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
333 /* This function returns a pointer to the string representation of the
334 pathname of the dynamically-linked library that has just been
337 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
338 TRUE, or undefined results are guaranteed.
340 This string's contents are only valid immediately after the
341 inferior has stopped in the dynamic linker hook, and becomes
342 invalid as soon as the inferior is continued. Clients should make
343 a copy of this string if they wish to continue the inferior and
344 then access the string. */
346 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
347 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
350 /* This function is called by the "catch load" command. It allows the
351 debugger to be notified by the dynamic linker when a specified
352 library file (or any library file, if filename is NULL) is loaded. */
354 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
355 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
356 error (_("catch of library loads not yet implemented on this platform"))
359 /* This function is called by the "catch unload" command. It allows
360 the debugger to be notified by the dynamic linker when a specified
361 library file (or any library file, if filename is NULL) is
364 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
365 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
366 error (_("catch of library unloads not yet implemented on this platform"))
369 /* Return whether a breakpoint is an active enabled breakpoint. */
371 breakpoint_enabled (struct breakpoint
*b
)
373 return (b
->enable_state
== bp_enabled
);
376 /* Set breakpoint count to NUM. */
379 set_breakpoint_count (int num
)
381 breakpoint_count
= num
;
382 set_internalvar (lookup_internalvar ("bpnum"),
383 value_from_longest (builtin_type_int
, (LONGEST
) num
));
386 /* Used in run_command to zero the hit count when a new run starts. */
389 clear_breakpoint_hit_counts (void)
391 struct breakpoint
*b
;
397 /* Default address, symtab and line to put a breakpoint at
398 for "break" command with no arg.
399 if default_breakpoint_valid is zero, the other three are
400 not valid, and "break" with no arg is an error.
402 This set by print_stack_frame, which calls set_default_breakpoint. */
404 int default_breakpoint_valid
;
405 CORE_ADDR default_breakpoint_address
;
406 struct symtab
*default_breakpoint_symtab
;
407 int default_breakpoint_line
;
409 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
410 Advance *PP after the string and any trailing whitespace.
412 Currently the string can either be a number or "$" followed by the name
413 of a convenience variable. Making it an expression wouldn't work well
414 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
416 If the string is a NULL pointer, that denotes the last breakpoint.
418 TRAILER is a character which can be found after the number; most
419 commonly this is `-'. If you don't want a trailer, use \0. */
421 get_number_trailer (char **pp
, int trailer
)
423 int retval
= 0; /* default */
427 /* Empty line means refer to the last breakpoint. */
428 return breakpoint_count
;
431 /* Make a copy of the name, so we can null-terminate it
432 to pass to lookup_internalvar(). */
437 while (isalnum (*p
) || *p
== '_')
439 varname
= (char *) alloca (p
- start
+ 1);
440 strncpy (varname
, start
, p
- start
);
441 varname
[p
- start
] = '\0';
442 val
= value_of_internalvar (lookup_internalvar (varname
));
443 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
444 retval
= (int) value_as_long (val
);
447 printf_filtered (_("Convenience variable must have integer value.\n"));
455 while (*p
>= '0' && *p
<= '9')
458 /* There is no number here. (e.g. "cond a == b"). */
460 /* Skip non-numeric token */
461 while (*p
&& !isspace((int) *p
))
463 /* Return zero, which caller must interpret as error. */
469 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
471 /* Trailing junk: return 0 and let caller print error msg. */
472 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
483 /* Like get_number_trailer, but don't allow a trailer. */
485 get_number (char **pp
)
487 return get_number_trailer (pp
, '\0');
490 /* Parse a number or a range.
491 * A number will be of the form handled by get_number.
492 * A range will be of the form <number1> - <number2>, and
493 * will represent all the integers between number1 and number2,
496 * While processing a range, this fuction is called iteratively;
497 * At each call it will return the next value in the range.
499 * At the beginning of parsing a range, the char pointer PP will
500 * be advanced past <number1> and left pointing at the '-' token.
501 * Subsequent calls will not advance the pointer until the range
502 * is completed. The call that completes the range will advance
503 * pointer PP past <number2>.
507 get_number_or_range (char **pp
)
509 static int last_retval
, end_value
;
510 static char *end_ptr
;
511 static int in_range
= 0;
515 /* Default case: pp is pointing either to a solo number,
516 or to the first number of a range. */
517 last_retval
= get_number_trailer (pp
, '-');
522 /* This is the start of a range (<number1> - <number2>).
523 Skip the '-', parse and remember the second number,
524 and also remember the end of the final token. */
528 while (isspace ((int) *end_ptr
))
529 end_ptr
++; /* skip white space */
530 end_value
= get_number (temp
);
531 if (end_value
< last_retval
)
533 error (_("inverted range"));
535 else if (end_value
== last_retval
)
537 /* degenerate range (number1 == number2). Advance the
538 token pointer so that the range will be treated as a
547 error (_("negative value"));
550 /* pp points to the '-' that betokens a range. All
551 number-parsing has already been done. Return the next
552 integer value (one greater than the saved previous value).
553 Do not advance the token pointer 'pp' until the end of range
556 if (++last_retval
== end_value
)
558 /* End of range reached; advance token pointer. */
568 /* condition N EXP -- set break condition of breakpoint N to EXP. */
571 condition_command (char *arg
, int from_tty
)
573 struct breakpoint
*b
;
578 error_no_arg (_("breakpoint number"));
581 bnum
= get_number (&p
);
583 error (_("Bad breakpoint argument: '%s'"), arg
);
586 if (b
->number
== bnum
)
588 struct bp_location
*loc
= b
->loc
;
589 for (; loc
; loc
= loc
->next
)
597 if (b
->cond_string
!= NULL
)
598 xfree (b
->cond_string
);
602 b
->cond_string
= NULL
;
604 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
609 /* I don't know if it matters whether this is the string the user
610 typed in or the decompiled expression. */
611 b
->cond_string
= savestring (arg
, strlen (arg
));
612 b
->condition_not_parsed
= 0;
613 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
616 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
618 error (_("Junk at end of expression"));
621 breakpoints_changed ();
622 breakpoint_modify_event (b
->number
);
626 error (_("No breakpoint number %d."), bnum
);
630 commands_command (char *arg
, int from_tty
)
632 struct breakpoint
*b
;
635 struct command_line
*l
;
637 /* If we allowed this, we would have problems with when to
638 free the storage, if we change the commands currently
641 if (executing_breakpoint_commands
)
642 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
645 bnum
= get_number (&p
);
648 error (_("Unexpected extra arguments following breakpoint number."));
651 if (b
->number
== bnum
)
653 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
655 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
656 l
= read_command_lines (tmpbuf
, from_tty
);
657 do_cleanups (cleanups
);
658 free_command_lines (&b
->commands
);
660 breakpoints_changed ();
661 breakpoint_modify_event (b
->number
);
664 error (_("No breakpoint number %d."), bnum
);
667 /* Like commands_command, but instead of reading the commands from
668 input stream, takes them from an already parsed command structure.
670 This is used by cli-script.c to DTRT with breakpoint commands
671 that are part of if and while bodies. */
672 enum command_control_type
673 commands_from_control_command (char *arg
, struct command_line
*cmd
)
675 struct breakpoint
*b
;
679 /* If we allowed this, we would have problems with when to
680 free the storage, if we change the commands currently
683 if (executing_breakpoint_commands
)
684 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
686 /* An empty string for the breakpoint number means the last
687 breakpoint, but get_number expects a NULL pointer. */
692 bnum
= get_number (&p
);
695 error (_("Unexpected extra arguments following breakpoint number."));
698 if (b
->number
== bnum
)
700 free_command_lines (&b
->commands
);
701 if (cmd
->body_count
!= 1)
702 error (_("Invalid \"commands\" block structure."));
703 /* We need to copy the commands because if/while will free the
704 list after it finishes execution. */
705 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
706 breakpoints_changed ();
707 breakpoint_modify_event (b
->number
);
708 return simple_control
;
710 error (_("No breakpoint number %d."), bnum
);
713 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
714 by replacing any memory breakpoints with their shadowed contents. */
717 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
719 struct bp_location
*b
;
720 CORE_ADDR bp_addr
= 0;
726 if (b
->owner
->type
== bp_none
)
727 warning (_("reading through apparently deleted breakpoint #%d?"),
730 if (b
->loc_type
!= bp_loc_software_breakpoint
)
734 /* Addresses and length of the part of the breakpoint that
736 bp_addr
= b
->target_info
.placed_address
;
737 bp_size
= b
->target_info
.shadow_len
;
739 /* bp isn't valid, or doesn't shadow memory. */
742 if (bp_addr
+ bp_size
<= memaddr
)
743 /* The breakpoint is entirely before the chunk of memory we
747 if (bp_addr
>= memaddr
+ len
)
748 /* The breakpoint is entirely after the chunk of memory we are
752 /* Offset within shadow_contents. */
753 if (bp_addr
< memaddr
)
755 /* Only copy the second part of the breakpoint. */
756 bp_size
-= memaddr
- bp_addr
;
757 bptoffset
= memaddr
- bp_addr
;
761 if (bp_addr
+ bp_size
> memaddr
+ len
)
763 /* Only copy the first part of the breakpoint. */
764 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
767 memcpy (buf
+ bp_addr
- memaddr
,
768 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
773 /* A wrapper function for inserting catchpoints. */
775 insert_catchpoint (struct ui_out
*uo
, void *args
)
777 struct breakpoint
*b
= (struct breakpoint
*) args
;
783 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
786 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
789 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
792 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
798 is_hardware_watchpoint (struct breakpoint
*bpt
)
800 return (bpt
->type
== bp_hardware_watchpoint
801 || bpt
->type
== bp_read_watchpoint
802 || bpt
->type
== bp_access_watchpoint
);
805 /* Find the current value of a watchpoint on EXP. Return the value in
806 *VALP and *RESULTP and the chain of intermediate and final values
807 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
810 If an error occurs while evaluating the expression, *RESULTP will
811 be set to NULL. *RESULTP may be a lazy value, if the result could
812 not be read from memory. It is used to determine whether a value
813 is user-specified (we should watch the whole value) or intermediate
814 (we should watch only the bit used to locate the final value).
816 If the final value, or any intermediate value, could not be read
817 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
818 set to any referenced values. *VALP will never be a lazy value.
819 This is the value which we store in struct breakpoint.
821 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
822 value chain. The caller must free the values individually. If
823 VAL_CHAIN is NULL, all generated values will be left on the value
827 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
828 struct value
**resultp
, struct value
**val_chain
)
830 struct value
*mark
, *new_mark
, *result
;
838 /* Evaluate the expression. */
839 mark
= value_mark ();
841 gdb_evaluate_expression (exp
, &result
);
842 new_mark
= value_mark ();
843 if (mark
== new_mark
)
848 /* Make sure it's not lazy, so that after the target stops again we
849 have a non-lazy previous value to compare with. */
851 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
856 /* Return the chain of intermediate values. We use this to
857 decide which addresses to watch. */
858 *val_chain
= new_mark
;
859 value_release_to_mark (mark
);
863 /* Assuming that B is a hardware watchpoint:
864 - Reparse watchpoint expression, is REPARSE is non-zero
865 - Evaluate expression and store the result in B->val
866 - Update the list of values that must be watched in B->loc.
868 If the watchpoint is disabled, do nothing. If this is
869 local watchpoint that is out of scope, delete it. */
871 update_watchpoint (struct breakpoint
*b
, int reparse
)
873 int within_current_scope
;
874 struct frame_id saved_frame_id
;
875 struct bp_location
*loc
;
878 unlink_locations_from_global_list (b
);
879 for (loc
= b
->loc
; loc
;)
881 struct bp_location
*loc_next
= loc
->next
;
882 remove_breakpoint (loc
, mark_uninserted
);
888 if (b
->disposition
== disp_del_at_next_stop
)
891 /* Save the current frame's ID so we can restore it after
892 evaluating the watchpoint expression on its own frame. */
893 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
894 took a frame parameter, so that we didn't have to change the
896 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
898 /* Determine if the watchpoint is within scope. */
899 if (b
->exp_valid_block
== NULL
)
900 within_current_scope
= 1;
903 struct frame_info
*fi
;
904 fi
= frame_find_by_id (b
->watchpoint_frame
);
905 within_current_scope
= (fi
!= NULL
);
906 if (within_current_scope
)
910 if (within_current_scope
&& reparse
)
919 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
920 /* If the meaning of expression itself changed, the old value is
921 no longer relevant. We don't want to report a watchpoint hit
922 to the user when the old value and the new value may actually
923 be completely different objects. */
929 /* If we failed to parse the expression, for example because
930 it refers to a global variable in a not-yet-loaded shared library,
931 don't try to insert watchpoint. We don't automatically delete
932 such watchpoint, though, since failure to parse expression
933 is different from out-of-scope watchpoint. */
934 if (within_current_scope
&& b
->exp
)
936 struct value
*val_chain
, *v
, *result
, *next
;
938 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
940 /* Avoid setting b->val if it's already set. The meaning of
941 b->val is 'the last value' user saw, and we should update
942 it only if we reported that last value to user. As it
943 happens, the code that reports it updates b->val directly. */
950 /* Look at each value on the value chain. */
951 for (v
= val_chain
; v
; v
= next
)
953 /* If it's a memory location, and GDB actually needed
954 its contents to evaluate the expression, then we
955 must watch it. If the first value returned is
956 still lazy, that means an error occurred reading it;
957 watch it anyway in case it becomes readable. */
958 if (VALUE_LVAL (v
) == lval_memory
959 && (v
== val_chain
|| ! value_lazy (v
)))
961 struct type
*vtype
= check_typedef (value_type (v
));
963 /* We only watch structs and arrays if user asked
964 for it explicitly, never if they just happen to
965 appear in the middle of some value chain. */
967 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
968 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
972 struct bp_location
*loc
, **tmp
;
974 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
975 len
= TYPE_LENGTH (value_type (v
));
977 if (b
->type
== bp_read_watchpoint
)
979 else if (b
->type
== bp_access_watchpoint
)
982 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
983 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
988 loc
->watchpoint_type
= type
;
992 next
= value_next (v
);
997 /* We just regenerated the list of breakpoint locations.
998 The new location does not have its condition field set to anything
999 and therefore, we must always reparse the cond_string, independently
1000 of the value of the reparse flag. */
1001 if (b
->cond_string
!= NULL
)
1003 char *s
= b
->cond_string
;
1004 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1007 else if (!within_current_scope
)
1009 printf_filtered (_("\
1010 Hardware watchpoint %d deleted because the program has left the block \n\
1011 in which its expression is valid.\n"),
1013 if (b
->related_breakpoint
)
1014 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1015 b
->disposition
= disp_del_at_next_stop
;
1018 /* Restore the selected frame. */
1019 select_frame (frame_find_by_id (saved_frame_id
));
1023 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1024 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1025 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1027 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1028 method for each breakpoint or catchpoint type. */
1030 insert_bp_location (struct bp_location
*bpt
,
1031 struct ui_file
*tmp_error_stream
,
1032 int *disabled_breaks
, int *process_warning
,
1033 int *hw_breakpoint_error
)
1037 if (!breakpoint_enabled (bpt
->owner
))
1040 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->inserted
|| bpt
->duplicate
)
1043 /* Initialize the target-specific information. */
1044 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1045 bpt
->target_info
.placed_address
= bpt
->address
;
1047 if (bpt
->loc_type
== bp_loc_software_breakpoint
1048 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1050 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1052 /* If the explicitly specified breakpoint type
1053 is not hardware breakpoint, check the memory map to see
1054 if the breakpoint address is in read only memory or not.
1055 Two important cases are:
1056 - location type is not hardware breakpoint, memory
1057 is readonly. We change the type of the location to
1058 hardware breakpoint.
1059 - location type is hardware breakpoint, memory is read-write.
1060 This means we've previously made the location hardware one, but
1061 then the memory map changed, so we undo.
1063 When breakpoints are removed, remove_breakpoints will
1064 use location types we've just set here, the only possible
1065 problem is that memory map has changed during running program,
1066 but it's not going to work anyway with current gdb. */
1067 struct mem_region
*mr
1068 = lookup_mem_region (bpt
->target_info
.placed_address
);
1072 if (automatic_hardware_breakpoints
)
1075 enum bp_loc_type new_type
;
1077 if (mr
->attrib
.mode
!= MEM_RW
)
1078 new_type
= bp_loc_hardware_breakpoint
;
1080 new_type
= bp_loc_software_breakpoint
;
1082 if (new_type
!= bpt
->loc_type
)
1084 static int said
= 0;
1085 bpt
->loc_type
= new_type
;
1088 fprintf_filtered (gdb_stdout
, _("\
1089 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1094 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1095 && mr
->attrib
.mode
!= MEM_RW
)
1096 warning (_("cannot set software breakpoint at readonly address %s"),
1097 paddr (bpt
->address
));
1101 /* First check to see if we have to handle an overlay. */
1102 if (overlay_debugging
== ovly_off
1103 || bpt
->section
== NULL
1104 || !(section_is_overlay (bpt
->section
)))
1106 /* No overlay handling: just set the breakpoint. */
1108 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1109 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1111 val
= target_insert_breakpoint (&bpt
->target_info
);
1115 /* This breakpoint is in an overlay section.
1116 Shall we set a breakpoint at the LMA? */
1117 if (!overlay_events_enabled
)
1119 /* Yes -- overlay event support is not active,
1120 so we must try to set a breakpoint at the LMA.
1121 This will not work for a hardware breakpoint. */
1122 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1123 warning (_("hardware breakpoint %d not supported in overlay!"),
1124 bpt
->owner
->number
);
1127 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1129 /* Set a software (trap) breakpoint at the LMA. */
1130 bpt
->overlay_target_info
= bpt
->target_info
;
1131 bpt
->overlay_target_info
.placed_address
= addr
;
1132 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1134 fprintf_unfiltered (tmp_error_stream
,
1135 "Overlay breakpoint %d failed: in ROM?",
1136 bpt
->owner
->number
);
1139 /* Shall we set a breakpoint at the VMA? */
1140 if (section_is_mapped (bpt
->section
))
1142 /* Yes. This overlay section is mapped into memory. */
1143 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1144 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1146 val
= target_insert_breakpoint (&bpt
->target_info
);
1150 /* No. This breakpoint will not be inserted.
1151 No error, but do not mark the bp as 'inserted'. */
1158 /* Can't set the breakpoint. */
1159 if (solib_address (bpt
->address
))
1161 /* See also: disable_breakpoints_in_shlibs. */
1163 bpt
->shlib_disabled
= 1;
1164 if (!*disabled_breaks
)
1166 fprintf_unfiltered (tmp_error_stream
,
1167 "Cannot insert breakpoint %d.\n",
1168 bpt
->owner
->number
);
1169 fprintf_unfiltered (tmp_error_stream
,
1170 "Temporarily disabling shared library breakpoints:\n");
1172 *disabled_breaks
= 1;
1173 fprintf_unfiltered (tmp_error_stream
,
1174 "breakpoint #%d\n", bpt
->owner
->number
);
1178 #ifdef ONE_PROCESS_WRITETEXT
1179 *process_warning
= 1;
1181 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1183 *hw_breakpoint_error
= 1;
1184 fprintf_unfiltered (tmp_error_stream
,
1185 "Cannot insert hardware breakpoint %d.\n",
1186 bpt
->owner
->number
);
1190 fprintf_unfiltered (tmp_error_stream
,
1191 "Cannot insert breakpoint %d.\n",
1192 bpt
->owner
->number
);
1193 fprintf_filtered (tmp_error_stream
,
1194 "Error accessing memory address ");
1195 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1196 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1197 safe_strerror (val
));
1208 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1209 /* NOTE drow/2003-09-08: This state only exists for removing
1210 watchpoints. It's not clear that it's necessary... */
1211 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1213 val
= target_insert_watchpoint (bpt
->address
,
1215 bpt
->watchpoint_type
);
1216 bpt
->inserted
= (val
!= -1);
1219 else if (bpt
->owner
->type
== bp_catch_fork
1220 || bpt
->owner
->type
== bp_catch_vfork
1221 || bpt
->owner
->type
== bp_catch_exec
)
1223 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1224 bpt
->owner
, RETURN_MASK_ERROR
);
1225 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1226 bpt
->owner
->number
);
1228 bpt
->owner
->enable_state
= bp_disabled
;
1232 /* We've already printed an error message if there was a problem
1233 inserting this catchpoint, and we've disabled the catchpoint,
1234 so just return success. */
1241 /* insert_breakpoints is used when starting or continuing the program.
1242 remove_breakpoints is used when the program stops.
1243 Both return zero if successful,
1244 or an `errno' value if could not write the inferior. */
1247 insert_breakpoints (void)
1249 struct breakpoint
*bpt
;
1250 struct bp_location
*b
, *temp
;
1253 int disabled_breaks
= 0;
1254 int hw_breakpoint_error
= 0;
1255 int process_warning
= 0;
1257 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1258 make_cleanup_ui_file_delete (tmp_error_stream
);
1260 /* Explicitly mark the warning -- this will only be printed if
1261 there was an error. */
1262 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1264 ALL_BREAKPOINTS (bpt
)
1265 if (is_hardware_watchpoint (bpt
))
1266 update_watchpoint (bpt
, 0 /* don't reparse */);
1268 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1270 if (!breakpoint_enabled (b
->owner
))
1273 /* There is no point inserting thread-specific breakpoints if the
1274 thread no longer exists. */
1275 if (b
->owner
->thread
!= -1
1276 && !valid_thread_id (b
->owner
->thread
))
1279 val
= insert_bp_location (b
, tmp_error_stream
,
1280 &disabled_breaks
, &process_warning
,
1281 &hw_breakpoint_error
);
1286 /* If we failed to insert all locations of a watchpoint,
1287 remove them, as half-inserted watchpoint is of limited use. */
1288 ALL_BREAKPOINTS (bpt
)
1290 int some_failed
= 0;
1291 struct bp_location
*loc
;
1293 if (!is_hardware_watchpoint (bpt
))
1296 if (bpt
->enable_state
!= bp_enabled
)
1299 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1307 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1309 remove_breakpoint (loc
, mark_uninserted
);
1311 hw_breakpoint_error
= 1;
1312 fprintf_unfiltered (tmp_error_stream
,
1313 "Could not insert hardware watchpoint %d.\n",
1321 /* If a hardware breakpoint or watchpoint was inserted, add a
1322 message about possibly exhausted resources. */
1323 if (hw_breakpoint_error
)
1325 fprintf_unfiltered (tmp_error_stream
,
1326 "Could not insert hardware breakpoints:\n\
1327 You may have requested too many hardware breakpoints/watchpoints.\n");
1329 #ifdef ONE_PROCESS_WRITETEXT
1330 if (process_warning
)
1331 fprintf_unfiltered (tmp_error_stream
,
1332 "The same program may be running in another process.");
1334 target_terminal_ours_for_output ();
1335 error_stream (tmp_error_stream
);
1340 remove_breakpoints (void)
1342 struct bp_location
*b
;
1345 ALL_BP_LOCATIONS (b
)
1349 val
= remove_breakpoint (b
, mark_uninserted
);
1358 remove_hw_watchpoints (void)
1360 struct bp_location
*b
;
1363 ALL_BP_LOCATIONS (b
)
1365 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1367 val
= remove_breakpoint (b
, mark_uninserted
);
1376 reattach_breakpoints (int pid
)
1378 struct bp_location
*b
;
1380 struct cleanup
*old_chain
= save_inferior_ptid ();
1381 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1382 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1384 make_cleanup_ui_file_delete (tmp_error_stream
);
1386 inferior_ptid
= pid_to_ptid (pid
);
1387 ALL_BP_LOCATIONS (b
)
1392 val
= insert_bp_location (b
, tmp_error_stream
,
1393 &dummy1
, &dummy2
, &dummy3
);
1396 do_cleanups (old_chain
);
1401 do_cleanups (old_chain
);
1406 update_breakpoints_after_exec (void)
1408 struct breakpoint
*b
;
1409 struct breakpoint
*temp
;
1411 /* Doing this first prevents the badness of having delete_breakpoint()
1412 write a breakpoint's current "shadow contents" to lift the bp. That
1413 shadow is NOT valid after an exec()! */
1414 mark_breakpoints_out ();
1416 ALL_BREAKPOINTS_SAFE (b
, temp
)
1418 /* Solib breakpoints must be explicitly reset after an exec(). */
1419 if (b
->type
== bp_shlib_event
)
1421 delete_breakpoint (b
);
1425 /* Thread event breakpoints must be set anew after an exec(),
1426 as must overlay event breakpoints. */
1427 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1429 delete_breakpoint (b
);
1433 /* Step-resume breakpoints are meaningless after an exec(). */
1434 if (b
->type
== bp_step_resume
)
1436 delete_breakpoint (b
);
1440 /* Don't delete an exec catchpoint, because else the inferior
1441 won't stop when it ought!
1443 Similarly, we probably ought to keep vfork catchpoints, 'cause
1444 on this target, we may not be able to stop when the vfork is
1445 seen, but only when the subsequent exec is seen. (And because
1446 deleting fork catchpoints here but not vfork catchpoints will
1447 seem mysterious to users, keep those too.) */
1448 if ((b
->type
== bp_catch_exec
) ||
1449 (b
->type
== bp_catch_vfork
) ||
1450 (b
->type
== bp_catch_fork
))
1455 /* bp_finish is a special case. The only way we ought to be able
1456 to see one of these when an exec() has happened, is if the user
1457 caught a vfork, and then said "finish". Ordinarily a finish just
1458 carries them to the call-site of the current callee, by setting
1459 a temporary bp there and resuming. But in this case, the finish
1460 will carry them entirely through the vfork & exec.
1462 We don't want to allow a bp_finish to remain inserted now. But
1463 we can't safely delete it, 'cause finish_command has a handle to
1464 the bp on a bpstat, and will later want to delete it. There's a
1465 chance (and I've seen it happen) that if we delete the bp_finish
1466 here, that its storage will get reused by the time finish_command
1467 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1468 We really must allow finish_command to delete a bp_finish.
1470 In the absense of a general solution for the "how do we know
1471 it's safe to delete something others may have handles to?"
1472 problem, what we'll do here is just uninsert the bp_finish, and
1473 let finish_command delete it.
1475 (We know the bp_finish is "doomed" in the sense that it's
1476 momentary, and will be deleted as soon as finish_command sees
1477 the inferior stopped. So it doesn't matter that the bp's
1478 address is probably bogus in the new a.out, unlike e.g., the
1479 solib breakpoints.) */
1481 if (b
->type
== bp_finish
)
1486 /* Without a symbolic address, we have little hope of the
1487 pre-exec() address meaning the same thing in the post-exec()
1489 if (b
->addr_string
== NULL
)
1491 delete_breakpoint (b
);
1495 /* FIXME what about longjmp breakpoints? Re-create them here? */
1496 create_overlay_event_breakpoint ("_ovly_debug_event");
1500 detach_breakpoints (int pid
)
1502 struct bp_location
*b
;
1504 struct cleanup
*old_chain
= save_inferior_ptid ();
1506 if (pid
== PIDGET (inferior_ptid
))
1507 error (_("Cannot detach breakpoints of inferior_ptid"));
1509 /* Set inferior_ptid; remove_breakpoint uses this global. */
1510 inferior_ptid
= pid_to_ptid (pid
);
1511 ALL_BP_LOCATIONS (b
)
1515 val
= remove_breakpoint (b
, mark_inserted
);
1518 do_cleanups (old_chain
);
1523 do_cleanups (old_chain
);
1528 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1532 if (b
->owner
->enable_state
== bp_permanent
)
1533 /* Permanent breakpoints cannot be inserted or removed. */
1536 if (b
->owner
->type
== bp_none
)
1537 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1540 if (b
->loc_type
== bp_loc_software_breakpoint
1541 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1543 /* "Normal" instruction breakpoint: either the standard
1544 trap-instruction bp (bp_breakpoint), or a
1545 bp_hardware_breakpoint. */
1547 /* First check to see if we have to handle an overlay. */
1548 if (overlay_debugging
== ovly_off
1549 || b
->section
== NULL
1550 || !(section_is_overlay (b
->section
)))
1552 /* No overlay handling: just remove the breakpoint. */
1554 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1555 val
= target_remove_hw_breakpoint (&b
->target_info
);
1557 val
= target_remove_breakpoint (&b
->target_info
);
1561 /* This breakpoint is in an overlay section.
1562 Did we set a breakpoint at the LMA? */
1563 if (!overlay_events_enabled
)
1565 /* Yes -- overlay event support is not active, so we
1566 should have set a breakpoint at the LMA. Remove it.
1568 /* Ignore any failures: if the LMA is in ROM, we will
1569 have already warned when we failed to insert it. */
1570 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1571 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1573 target_remove_breakpoint (&b
->overlay_target_info
);
1575 /* Did we set a breakpoint at the VMA?
1576 If so, we will have marked the breakpoint 'inserted'. */
1579 /* Yes -- remove it. Previously we did not bother to
1580 remove the breakpoint if the section had been
1581 unmapped, but let's not rely on that being safe. We
1582 don't know what the overlay manager might do. */
1583 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1584 val
= target_remove_hw_breakpoint (&b
->target_info
);
1586 /* However, we should remove *software* breakpoints only
1587 if the section is still mapped, or else we overwrite
1588 wrong code with the saved shadow contents. */
1589 else if (section_is_mapped (b
->section
))
1590 val
= target_remove_breakpoint (&b
->target_info
);
1596 /* No -- not inserted, so no need to remove. No error. */
1602 b
->inserted
= (is
== mark_inserted
);
1604 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1609 b
->inserted
= (is
== mark_inserted
);
1610 val
= target_remove_watchpoint (b
->address
, b
->length
,
1611 b
->watchpoint_type
);
1613 /* Failure to remove any of the hardware watchpoints comes here. */
1614 if ((is
== mark_uninserted
) && (b
->inserted
))
1615 warning (_("Could not remove hardware watchpoint %d."),
1618 else if ((b
->owner
->type
== bp_catch_fork
||
1619 b
->owner
->type
== bp_catch_vfork
||
1620 b
->owner
->type
== bp_catch_exec
)
1621 && breakpoint_enabled (b
->owner
)
1625 switch (b
->owner
->type
)
1628 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1630 case bp_catch_vfork
:
1631 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1634 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1637 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1642 b
->inserted
= (is
== mark_inserted
);
1648 /* Clear the "inserted" flag in all breakpoints. */
1651 mark_breakpoints_out (void)
1653 struct bp_location
*bpt
;
1655 ALL_BP_LOCATIONS (bpt
)
1659 /* Clear the "inserted" flag in all breakpoints and delete any
1660 breakpoints which should go away between runs of the program.
1662 Plus other such housekeeping that has to be done for breakpoints
1665 Note: this function gets called at the end of a run (by
1666 generic_mourn_inferior) and when a run begins (by
1667 init_wait_for_inferior). */
1672 breakpoint_init_inferior (enum inf_context context
)
1674 struct breakpoint
*b
, *temp
;
1675 struct bp_location
*bpt
;
1677 ALL_BP_LOCATIONS (bpt
)
1680 ALL_BREAKPOINTS_SAFE (b
, temp
)
1685 case bp_watchpoint_scope
:
1687 /* If the call dummy breakpoint is at the entry point it will
1688 cause problems when the inferior is rerun, so we better
1691 Also get rid of scope breakpoints. */
1692 delete_breakpoint (b
);
1696 case bp_hardware_watchpoint
:
1697 case bp_read_watchpoint
:
1698 case bp_access_watchpoint
:
1700 /* Likewise for watchpoints on local expressions. */
1701 if (b
->exp_valid_block
!= NULL
)
1702 delete_breakpoint (b
);
1703 else if (context
== inf_starting
)
1705 /* Reset val field to force reread of starting value
1706 in insert_breakpoints. */
1708 value_free (b
->val
);
1719 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1720 exists at PC. It returns ordinary_breakpoint_here if it's an
1721 ordinary breakpoint, or permanent_breakpoint_here if it's a
1722 permanent breakpoint.
1723 - When continuing from a location with an ordinary breakpoint, we
1724 actually single step once before calling insert_breakpoints.
1725 - When continuing from a localion with a permanent breakpoint, we
1726 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1727 the target, to advance the PC past the breakpoint. */
1729 enum breakpoint_here
1730 breakpoint_here_p (CORE_ADDR pc
)
1732 const struct bp_location
*bpt
;
1733 int any_breakpoint_here
= 0;
1735 ALL_BP_LOCATIONS (bpt
)
1737 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1738 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1741 if ((breakpoint_enabled (bpt
->owner
)
1742 || bpt
->owner
->enable_state
== bp_permanent
)
1743 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1745 if (overlay_debugging
1746 && section_is_overlay (bpt
->section
)
1747 && !section_is_mapped (bpt
->section
))
1748 continue; /* unmapped overlay -- can't be a match */
1749 else if (bpt
->owner
->enable_state
== bp_permanent
)
1750 return permanent_breakpoint_here
;
1752 any_breakpoint_here
= 1;
1756 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1760 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1761 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1762 This does not check for single-step breakpoints, which are
1763 inserted and removed using direct target manipulation. */
1766 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1768 const struct bp_location
*bpt
;
1770 ALL_BP_LOCATIONS (bpt
)
1772 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1773 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1777 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1779 if (overlay_debugging
1780 && section_is_overlay (bpt
->section
)
1781 && !section_is_mapped (bpt
->section
))
1782 continue; /* unmapped overlay -- can't be a match */
1790 /* Returns non-zero iff there's either regular breakpoint
1791 or a single step breakpoint inserted at PC. */
1794 breakpoint_inserted_here_p (CORE_ADDR pc
)
1796 if (regular_breakpoint_inserted_here_p (pc
))
1799 if (single_step_breakpoint_inserted_here_p (pc
))
1805 /* This function returns non-zero iff there is a software breakpoint
1809 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1811 const struct bp_location
*bpt
;
1812 int any_breakpoint_here
= 0;
1814 ALL_BP_LOCATIONS (bpt
)
1816 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1820 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1822 if (overlay_debugging
1823 && section_is_overlay (bpt
->section
)
1824 && !section_is_mapped (bpt
->section
))
1825 continue; /* unmapped overlay -- can't be a match */
1831 /* Also check for software single-step breakpoints. */
1832 if (single_step_breakpoint_inserted_here_p (pc
))
1838 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1839 PC is valid for process/thread PTID. */
1842 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1844 const struct bp_location
*bpt
;
1847 thread
= pid_to_thread_id (ptid
);
1849 ALL_BP_LOCATIONS (bpt
)
1851 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1852 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1855 if ((breakpoint_enabled (bpt
->owner
)
1856 || bpt
->owner
->enable_state
== bp_permanent
)
1857 && bpt
->address
== pc
1858 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1860 if (overlay_debugging
1861 && section_is_overlay (bpt
->section
)
1862 && !section_is_mapped (bpt
->section
))
1863 continue; /* unmapped overlay -- can't be a match */
1873 /* bpstat stuff. External routines' interfaces are documented
1877 ep_is_catchpoint (struct breakpoint
*ep
)
1880 (ep
->type
== bp_catch_load
)
1881 || (ep
->type
== bp_catch_unload
)
1882 || (ep
->type
== bp_catch_fork
)
1883 || (ep
->type
== bp_catch_vfork
)
1884 || (ep
->type
== bp_catch_exec
);
1886 /* ??rehrauer: Add more kinds here, as are implemented... */
1890 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1893 (ep
->type
== bp_catch_load
)
1894 || (ep
->type
== bp_catch_unload
);
1898 bpstat_free (bpstat bs
)
1900 if (bs
->old_val
!= NULL
)
1901 value_free (bs
->old_val
);
1902 free_command_lines (&bs
->commands
);
1906 /* Clear a bpstat so that it says we are not at any breakpoint.
1907 Also free any storage that is part of a bpstat. */
1910 bpstat_clear (bpstat
*bsp
)
1927 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1928 is part of the bpstat is copied as well. */
1931 bpstat_copy (bpstat bs
)
1935 bpstat retval
= NULL
;
1940 for (; bs
!= NULL
; bs
= bs
->next
)
1942 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1943 memcpy (tmp
, bs
, sizeof (*tmp
));
1944 if (bs
->commands
!= NULL
)
1945 tmp
->commands
= copy_command_lines (bs
->commands
);
1946 if (bs
->old_val
!= NULL
)
1947 tmp
->old_val
= value_copy (bs
->old_val
);
1950 /* This is the first thing in the chain. */
1960 /* Find the bpstat associated with this breakpoint */
1963 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1968 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1970 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1976 /* Find a step_resume breakpoint associated with this bpstat.
1977 (If there are multiple step_resume bp's on the list, this function
1978 will arbitrarily pick one.)
1980 It is an error to use this function if BPSTAT doesn't contain a
1981 step_resume breakpoint.
1983 See wait_for_inferior's use of this function. */
1985 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1989 gdb_assert (bsp
!= NULL
);
1991 current_thread
= pid_to_thread_id (inferior_ptid
);
1993 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1995 if ((bsp
->breakpoint_at
!= NULL
) &&
1996 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
1997 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
1998 bsp
->breakpoint_at
->owner
->thread
== -1))
1999 return bsp
->breakpoint_at
->owner
;
2002 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2006 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2007 at. *BSP upon return is a bpstat which points to the remaining
2008 breakpoints stopped at (but which is not guaranteed to be good for
2009 anything but further calls to bpstat_num).
2010 Return 0 if passed a bpstat which does not indicate any breakpoints.
2011 Return -1 if stopped at a breakpoint that has been deleted since
2013 Return 1 otherwise. */
2016 bpstat_num (bpstat
*bsp
, int *num
)
2018 struct breakpoint
*b
;
2021 return 0; /* No more breakpoint values */
2023 /* We assume we'll never have several bpstats that
2024 correspond to a single breakpoint -- otherwise,
2025 this function might return the same number more
2026 than once and this will look ugly. */
2027 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2028 *bsp
= (*bsp
)->next
;
2030 return -1; /* breakpoint that's been deleted since */
2032 *num
= b
->number
; /* We have its number */
2036 /* Modify BS so that the actions will not be performed. */
2039 bpstat_clear_actions (bpstat bs
)
2041 for (; bs
!= NULL
; bs
= bs
->next
)
2043 free_command_lines (&bs
->commands
);
2044 if (bs
->old_val
!= NULL
)
2046 value_free (bs
->old_val
);
2052 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2054 cleanup_executing_breakpoints (void *ignore
)
2056 executing_breakpoint_commands
= 0;
2059 /* Execute all the commands associated with all the breakpoints at this
2060 location. Any of these commands could cause the process to proceed
2061 beyond this point, etc. We look out for such changes by checking
2062 the global "breakpoint_proceeded" after each command. */
2065 bpstat_do_actions (bpstat
*bsp
)
2068 struct cleanup
*old_chain
;
2070 /* Avoid endless recursion if a `source' command is contained
2072 if (executing_breakpoint_commands
)
2075 executing_breakpoint_commands
= 1;
2076 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2079 /* Note that (as of this writing), our callers all appear to
2080 be passing us the address of global stop_bpstat. And, if
2081 our calls to execute_control_command cause the inferior to
2082 proceed, that global (and hence, *bsp) will change.
2084 We must be careful to not touch *bsp unless the inferior
2085 has not proceeded. */
2087 /* This pointer will iterate over the list of bpstat's. */
2090 breakpoint_proceeded
= 0;
2091 for (; bs
!= NULL
; bs
= bs
->next
)
2093 struct command_line
*cmd
;
2094 struct cleanup
*this_cmd_tree_chain
;
2096 /* Take ownership of the BSP's command tree, if it has one.
2098 The command tree could legitimately contain commands like
2099 'step' and 'next', which call clear_proceed_status, which
2100 frees stop_bpstat's command tree. To make sure this doesn't
2101 free the tree we're executing out from under us, we need to
2102 take ownership of the tree ourselves. Since a given bpstat's
2103 commands are only executed once, we don't need to copy it; we
2104 can clear the pointer in the bpstat, and make sure we free
2105 the tree when we're done. */
2108 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2112 execute_control_command (cmd
);
2114 if (breakpoint_proceeded
)
2120 /* We can free this command tree now. */
2121 do_cleanups (this_cmd_tree_chain
);
2123 if (breakpoint_proceeded
)
2125 if (target_can_async_p ())
2126 /* If we are in async mode, then the target might
2127 be still running, not stopped at any breakpoint,
2128 so nothing for us to do here -- just return to
2132 /* In sync mode, when execute_control_command returns
2133 we're already standing on the next breakpoint.
2134 Breakpoint commands for that stop were not run,
2135 since execute_command does not run breakpoint
2136 commands -- only command_line_handler does, but
2137 that one is not involved in execution of breakpoint
2138 commands. So, we can now execute breakpoint commands.
2139 There's an implicit assumption that we're called with
2140 stop_bpstat, so our parameter is the new bpstat to
2142 It should be noted that making execute_command do
2143 bpstat actions is not an option -- in this case we'll
2144 have recursive invocation of bpstat for each breakpoint
2145 with a command, and can easily blow up GDB stack. */
2149 do_cleanups (old_chain
);
2152 /* Print out the (old or new) value associated with a watchpoint. */
2155 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2158 fprintf_unfiltered (stream
, _("<unreadable>"));
2160 value_print (val
, stream
, 0, Val_pretty_default
);
2163 /* This is the normal print function for a bpstat. In the future,
2164 much of this logic could (should?) be moved to bpstat_stop_status,
2165 by having it set different print_it values.
2167 Current scheme: When we stop, bpstat_print() is called. It loops
2168 through the bpstat list of things causing this stop, calling the
2169 print_bp_stop_message function on each one. The behavior of the
2170 print_bp_stop_message function depends on the print_it field of
2171 bpstat. If such field so indicates, call this function here.
2173 Return values from this routine (ultimately used by bpstat_print()
2174 and normal_stop() to decide what to do):
2175 PRINT_NOTHING: Means we already printed all we needed to print,
2176 don't print anything else.
2177 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2178 that something to be followed by a location.
2179 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2180 that something to be followed by a location.
2181 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2184 static enum print_stop_action
2185 print_it_typical (bpstat bs
)
2187 struct cleanup
*old_chain
, *ui_out_chain
;
2188 struct breakpoint
*b
;
2189 const struct bp_location
*bl
;
2190 struct ui_stream
*stb
;
2192 stb
= ui_out_stream_new (uiout
);
2193 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2194 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2195 which has since been deleted. */
2196 if (bs
->breakpoint_at
== NULL
)
2197 return PRINT_UNKNOWN
;
2198 bl
= bs
->breakpoint_at
;
2204 case bp_hardware_breakpoint
:
2205 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2206 if (bl
->address
!= bl
->requested_address
)
2207 breakpoint_adjustment_warning (bl
->requested_address
,
2210 annotate_breakpoint (b
->number
);
2212 ui_out_text (uiout
, "\nTemporary breakpoint ");
2214 ui_out_text (uiout
, "\nBreakpoint ");
2215 if (ui_out_is_mi_like_p (uiout
))
2217 ui_out_field_string (uiout
, "reason",
2218 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2219 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2221 ui_out_field_int (uiout
, "bkptno", b
->number
);
2222 ui_out_text (uiout
, ", ");
2223 return PRINT_SRC_AND_LOC
;
2226 case bp_shlib_event
:
2227 /* Did we stop because the user set the stop_on_solib_events
2228 variable? (If so, we report this as a generic, "Stopped due
2229 to shlib event" message.) */
2230 printf_filtered (_("Stopped due to shared library event\n"));
2231 return PRINT_NOTHING
;
2234 case bp_thread_event
:
2235 /* Not sure how we will get here.
2236 GDB should not stop for these breakpoints. */
2237 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2238 return PRINT_NOTHING
;
2241 case bp_overlay_event
:
2242 /* By analogy with the thread event, GDB should not stop for these. */
2243 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2244 return PRINT_NOTHING
;
2248 annotate_catchpoint (b
->number
);
2249 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2251 b
->triggered_dll_pathname
);
2252 return PRINT_SRC_AND_LOC
;
2255 case bp_catch_unload
:
2256 annotate_catchpoint (b
->number
);
2257 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2259 b
->triggered_dll_pathname
);
2260 return PRINT_SRC_AND_LOC
;
2264 annotate_catchpoint (b
->number
);
2265 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2267 b
->forked_inferior_pid
);
2268 return PRINT_SRC_AND_LOC
;
2271 case bp_catch_vfork
:
2272 annotate_catchpoint (b
->number
);
2273 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2275 b
->forked_inferior_pid
);
2276 return PRINT_SRC_AND_LOC
;
2280 annotate_catchpoint (b
->number
);
2281 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2284 return PRINT_SRC_AND_LOC
;
2288 case bp_hardware_watchpoint
:
2289 annotate_watchpoint (b
->number
);
2290 if (ui_out_is_mi_like_p (uiout
))
2293 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2295 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2296 ui_out_text (uiout
, "\nOld value = ");
2297 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2298 ui_out_field_stream (uiout
, "old", stb
);
2299 ui_out_text (uiout
, "\nNew value = ");
2300 watchpoint_value_print (b
->val
, stb
->stream
);
2301 ui_out_field_stream (uiout
, "new", stb
);
2302 do_cleanups (ui_out_chain
);
2303 ui_out_text (uiout
, "\n");
2304 /* More than one watchpoint may have been triggered. */
2305 return PRINT_UNKNOWN
;
2308 case bp_read_watchpoint
:
2309 if (ui_out_is_mi_like_p (uiout
))
2312 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2314 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2315 ui_out_text (uiout
, "\nValue = ");
2316 watchpoint_value_print (b
->val
, stb
->stream
);
2317 ui_out_field_stream (uiout
, "value", stb
);
2318 do_cleanups (ui_out_chain
);
2319 ui_out_text (uiout
, "\n");
2320 return PRINT_UNKNOWN
;
2323 case bp_access_watchpoint
:
2324 if (bs
->old_val
!= NULL
)
2326 annotate_watchpoint (b
->number
);
2327 if (ui_out_is_mi_like_p (uiout
))
2330 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2332 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2333 ui_out_text (uiout
, "\nOld value = ");
2334 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2335 ui_out_field_stream (uiout
, "old", stb
);
2336 ui_out_text (uiout
, "\nNew value = ");
2341 if (ui_out_is_mi_like_p (uiout
))
2344 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2345 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2346 ui_out_text (uiout
, "\nValue = ");
2348 watchpoint_value_print (b
->val
, stb
->stream
);
2349 ui_out_field_stream (uiout
, "new", stb
);
2350 do_cleanups (ui_out_chain
);
2351 ui_out_text (uiout
, "\n");
2352 return PRINT_UNKNOWN
;
2355 /* Fall through, we don't deal with these types of breakpoints
2359 if (ui_out_is_mi_like_p (uiout
))
2362 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2363 return PRINT_UNKNOWN
;
2367 if (ui_out_is_mi_like_p (uiout
))
2370 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2371 return PRINT_UNKNOWN
;
2376 case bp_longjmp_resume
:
2377 case bp_step_resume
:
2378 case bp_watchpoint_scope
:
2381 return PRINT_UNKNOWN
;
2385 /* Generic routine for printing messages indicating why we
2386 stopped. The behavior of this function depends on the value
2387 'print_it' in the bpstat structure. Under some circumstances we
2388 may decide not to print anything here and delegate the task to
2391 static enum print_stop_action
2392 print_bp_stop_message (bpstat bs
)
2394 switch (bs
->print_it
)
2397 /* Nothing should be printed for this bpstat entry. */
2398 return PRINT_UNKNOWN
;
2402 /* We still want to print the frame, but we already printed the
2403 relevant messages. */
2404 return PRINT_SRC_AND_LOC
;
2407 case print_it_normal
:
2409 const struct bp_location
*bl
= bs
->breakpoint_at
;
2410 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2412 /* Normal case. Call the breakpoint's print_it method, or
2413 print_it_typical. */
2414 /* FIXME: how breakpoint can ever be NULL here? */
2415 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2416 return b
->ops
->print_it (b
);
2418 return print_it_typical (bs
);
2423 internal_error (__FILE__
, __LINE__
,
2424 _("print_bp_stop_message: unrecognized enum value"));
2429 /* Print a message indicating what happened. This is called from
2430 normal_stop(). The input to this routine is the head of the bpstat
2431 list - a list of the eventpoints that caused this stop. This
2432 routine calls the generic print routine for printing a message
2433 about reasons for stopping. This will print (for example) the
2434 "Breakpoint n," part of the output. The return value of this
2437 PRINT_UNKNOWN: Means we printed nothing
2438 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2439 code to print the location. An example is
2440 "Breakpoint 1, " which should be followed by
2442 PRINT_SRC_ONLY: Means we printed something, but there is no need
2443 to also print the location part of the message.
2444 An example is the catch/throw messages, which
2445 don't require a location appended to the end.
2446 PRINT_NOTHING: We have done some printing and we don't need any
2447 further info to be printed.*/
2449 enum print_stop_action
2450 bpstat_print (bpstat bs
)
2454 /* Maybe another breakpoint in the chain caused us to stop.
2455 (Currently all watchpoints go on the bpstat whether hit or not.
2456 That probably could (should) be changed, provided care is taken
2457 with respect to bpstat_explains_signal). */
2458 for (; bs
; bs
= bs
->next
)
2460 val
= print_bp_stop_message (bs
);
2461 if (val
== PRINT_SRC_ONLY
2462 || val
== PRINT_SRC_AND_LOC
2463 || val
== PRINT_NOTHING
)
2467 /* We reached the end of the chain, or we got a null BS to start
2468 with and nothing was printed. */
2469 return PRINT_UNKNOWN
;
2472 /* Evaluate the expression EXP and return 1 if value is zero.
2473 This is used inside a catch_errors to evaluate the breakpoint condition.
2474 The argument is a "struct expression *" that has been cast to char * to
2475 make it pass through catch_errors. */
2478 breakpoint_cond_eval (void *exp
)
2480 struct value
*mark
= value_mark ();
2481 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2482 value_free_to_mark (mark
);
2486 /* Allocate a new bpstat and chain it to the current one. */
2489 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2493 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2495 bs
->breakpoint_at
= bl
;
2496 /* If the condition is false, etc., don't do the commands. */
2497 bs
->commands
= NULL
;
2499 bs
->print_it
= print_it_normal
;
2503 /* The target has stopped with waitstatus WS. Check if any hardware
2504 watchpoints have triggered, according to the target. */
2507 watchpoints_triggered (struct target_waitstatus
*ws
)
2509 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2511 struct breakpoint
*b
;
2513 if (!stopped_by_watchpoint
)
2515 /* We were not stopped by a watchpoint. Mark all watchpoints
2516 as not triggered. */
2518 if (b
->type
== bp_hardware_watchpoint
2519 || b
->type
== bp_read_watchpoint
2520 || b
->type
== bp_access_watchpoint
)
2521 b
->watchpoint_triggered
= watch_triggered_no
;
2526 if (!target_stopped_data_address (¤t_target
, &addr
))
2528 /* We were stopped by a watchpoint, but we don't know where.
2529 Mark all watchpoints as unknown. */
2531 if (b
->type
== bp_hardware_watchpoint
2532 || b
->type
== bp_read_watchpoint
2533 || b
->type
== bp_access_watchpoint
)
2534 b
->watchpoint_triggered
= watch_triggered_unknown
;
2536 return stopped_by_watchpoint
;
2539 /* The target could report the data address. Mark watchpoints
2540 affected by this data address as triggered, and all others as not
2544 if (b
->type
== bp_hardware_watchpoint
2545 || b
->type
== bp_read_watchpoint
2546 || b
->type
== bp_access_watchpoint
)
2548 struct bp_location
*loc
;
2551 b
->watchpoint_triggered
= watch_triggered_no
;
2552 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2553 /* Exact match not required. Within range is
2555 if (addr
>= loc
->address
2556 && addr
< loc
->address
+ loc
->length
)
2558 b
->watchpoint_triggered
= watch_triggered_yes
;
2566 /* Possible return values for watchpoint_check (this can't be an enum
2567 because of check_errors). */
2568 /* The watchpoint has been deleted. */
2569 #define WP_DELETED 1
2570 /* The value has changed. */
2571 #define WP_VALUE_CHANGED 2
2572 /* The value has not changed. */
2573 #define WP_VALUE_NOT_CHANGED 3
2575 #define BP_TEMPFLAG 1
2576 #define BP_HARDWAREFLAG 2
2578 /* Check watchpoint condition. */
2581 watchpoint_check (void *p
)
2583 bpstat bs
= (bpstat
) p
;
2584 struct breakpoint
*b
;
2585 struct frame_info
*fr
;
2586 int within_current_scope
;
2588 b
= bs
->breakpoint_at
->owner
;
2590 if (b
->exp_valid_block
== NULL
)
2591 within_current_scope
= 1;
2594 /* There is no current frame at this moment. If we're going to have
2595 any chance of handling watchpoints on local variables, we'll need
2596 the frame chain (so we can determine if we're in scope). */
2597 reinit_frame_cache ();
2598 fr
= frame_find_by_id (b
->watchpoint_frame
);
2599 within_current_scope
= (fr
!= NULL
);
2601 /* If we've gotten confused in the unwinder, we might have
2602 returned a frame that can't describe this variable. */
2603 if (within_current_scope
2604 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2605 within_current_scope
= 0;
2607 /* in_function_epilogue_p() returns a non-zero value if we're still
2608 in the function but the stack frame has already been invalidated.
2609 Since we can't rely on the values of local variables after the
2610 stack has been destroyed, we are treating the watchpoint in that
2611 state as `not changed' without further checking.
2613 vinschen/2003-09-04: The former implementation left out the case
2614 that the watchpoint frame couldn't be found by frame_find_by_id()
2615 because the current PC is currently in an epilogue. Calling
2616 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2617 if ((!within_current_scope
|| fr
== get_current_frame ())
2618 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2619 return WP_VALUE_NOT_CHANGED
;
2620 if (fr
&& within_current_scope
)
2621 /* If we end up stopping, the current frame will get selected
2622 in normal_stop. So this call to select_frame won't affect
2627 if (within_current_scope
)
2629 /* We use value_{,free_to_}mark because it could be a
2630 *long* time before we return to the command level and
2631 call free_all_values. We can't call free_all_values because
2632 we might be in the middle of evaluating a function call. */
2634 struct value
*mark
= value_mark ();
2635 struct value
*new_val
;
2637 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2638 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2639 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2641 if (new_val
!= NULL
)
2643 release_value (new_val
);
2644 value_free_to_mark (mark
);
2646 bs
->old_val
= b
->val
;
2649 /* We will stop here */
2650 return WP_VALUE_CHANGED
;
2654 /* Nothing changed, don't do anything. */
2655 value_free_to_mark (mark
);
2656 /* We won't stop here */
2657 return WP_VALUE_NOT_CHANGED
;
2662 /* This seems like the only logical thing to do because
2663 if we temporarily ignored the watchpoint, then when
2664 we reenter the block in which it is valid it contains
2665 garbage (in the case of a function, it may have two
2666 garbage values, one before and one after the prologue).
2667 So we can't even detect the first assignment to it and
2668 watch after that (since the garbage may or may not equal
2669 the first value assigned). */
2670 /* We print all the stop information in print_it_typical(), but
2671 in this case, by the time we call print_it_typical() this bp
2672 will be deleted already. So we have no choice but print the
2673 information here. */
2674 if (ui_out_is_mi_like_p (uiout
))
2676 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2677 ui_out_text (uiout
, "\nWatchpoint ");
2678 ui_out_field_int (uiout
, "wpnum", b
->number
);
2679 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2680 which its expression is valid.\n");
2682 if (b
->related_breakpoint
)
2683 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2684 b
->disposition
= disp_del_at_next_stop
;
2690 /* Get a bpstat associated with having just stopped at address
2691 BP_ADDR in thread PTID.
2693 Determine whether we stopped at a breakpoint, etc, or whether we
2694 don't understand this stop. Result is a chain of bpstat's such that:
2696 if we don't understand the stop, the result is a null pointer.
2698 if we understand why we stopped, the result is not null.
2700 Each element of the chain refers to a particular breakpoint or
2701 watchpoint at which we have stopped. (We may have stopped for
2702 several reasons concurrently.)
2704 Each element of the chain has valid next, breakpoint_at,
2705 commands, FIXME??? fields. */
2708 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2710 struct breakpoint
*b
= NULL
;
2711 const struct bp_location
*bl
;
2712 /* Root of the chain of bpstat's */
2713 struct bpstats root_bs
[1];
2714 /* Pointer to the last thing in the chain currently. */
2715 bpstat bs
= root_bs
;
2716 int thread_id
= pid_to_thread_id (ptid
);
2718 ALL_BP_LOCATIONS (bl
)
2722 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2725 if (b
->type
!= bp_watchpoint
2726 && b
->type
!= bp_hardware_watchpoint
2727 && b
->type
!= bp_read_watchpoint
2728 && b
->type
!= bp_access_watchpoint
2729 && b
->type
!= bp_hardware_breakpoint
2730 && b
->type
!= bp_catch_fork
2731 && b
->type
!= bp_catch_vfork
2732 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2734 if (bl
->address
!= bp_addr
) /* address doesn't match */
2736 if (overlay_debugging
/* unmapped overlay section */
2737 && section_is_overlay (bl
->section
)
2738 && !section_is_mapped (bl
->section
))
2742 /* Continuable hardware watchpoints are treated as non-existent if the
2743 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2744 some data address). Otherwise gdb won't stop on a break instruction
2745 in the code (not from a breakpoint) when a hardware watchpoint has
2746 been defined. Also skip watchpoints which we know did not trigger
2747 (did not match the data address). */
2749 if ((b
->type
== bp_hardware_watchpoint
2750 || b
->type
== bp_read_watchpoint
2751 || b
->type
== bp_access_watchpoint
)
2752 && b
->watchpoint_triggered
== watch_triggered_no
)
2755 if (b
->type
== bp_hardware_breakpoint
)
2757 if (bl
->address
!= bp_addr
)
2759 if (overlay_debugging
/* unmapped overlay section */
2760 && section_is_overlay (bl
->section
)
2761 && !section_is_mapped (bl
->section
))
2765 /* Is this a catchpoint of a load or unload? If so, did we
2766 get a load or unload of the specified library? If not,
2768 if ((b
->type
== bp_catch_load
)
2769 #if defined(SOLIB_HAVE_LOAD_EVENT)
2770 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2771 || ((b
->dll_pathname
!= NULL
)
2772 && (strcmp (b
->dll_pathname
,
2773 SOLIB_LOADED_LIBRARY_PATHNAME (
2774 PIDGET (inferior_ptid
)))
2780 if ((b
->type
== bp_catch_unload
)
2781 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2782 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2783 || ((b
->dll_pathname
!= NULL
)
2784 && (strcmp (b
->dll_pathname
,
2785 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2786 PIDGET (inferior_ptid
)))
2792 if ((b
->type
== bp_catch_fork
)
2793 && !inferior_has_forked (PIDGET (inferior_ptid
),
2794 &b
->forked_inferior_pid
))
2797 if ((b
->type
== bp_catch_vfork
)
2798 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2799 &b
->forked_inferior_pid
))
2802 if ((b
->type
== bp_catch_exec
)
2803 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2806 /* For hardware watchpoints, we look only at the first location.
2807 The watchpoint_check function will work on entire expression,
2808 not the individual locations. For read watchopints, the
2809 watchpoints_triggered function have checked all locations
2812 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2815 /* Come here if it's a watchpoint, or if the break address matches */
2817 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2819 /* Watchpoints may change this, if not found to have triggered. */
2823 if (b
->type
== bp_watchpoint
2824 || b
->type
== bp_read_watchpoint
2825 || b
->type
== bp_access_watchpoint
2826 || b
->type
== bp_hardware_watchpoint
)
2830 int must_check_value
= 0;
2832 if (b
->type
== bp_watchpoint
)
2833 /* For a software watchpoint, we must always check the
2835 must_check_value
= 1;
2836 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2837 /* We have a hardware watchpoint (read, write, or access)
2838 and the target earlier reported an address watched by
2840 must_check_value
= 1;
2841 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2842 && b
->type
== bp_hardware_watchpoint
)
2843 /* We were stopped by a hardware watchpoint, but the target could
2844 not report the data address. We must check the watchpoint's
2845 value. Access and read watchpoints are out of luck; without
2846 a data address, we can't figure it out. */
2847 must_check_value
= 1;
2849 if (must_check_value
)
2851 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2853 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2854 int e
= catch_errors (watchpoint_check
, bs
, message
,
2856 do_cleanups (cleanups
);
2860 /* We've already printed what needs to be printed. */
2861 bs
->print_it
= print_it_done
;
2864 case WP_VALUE_CHANGED
:
2865 if (b
->type
== bp_read_watchpoint
)
2867 /* Don't stop: read watchpoints shouldn't fire if
2868 the value has changed. This is for targets
2869 which cannot set read-only watchpoints. */
2870 bs
->print_it
= print_it_noop
;
2876 case WP_VALUE_NOT_CHANGED
:
2877 if (b
->type
== bp_hardware_watchpoint
2878 || b
->type
== bp_watchpoint
)
2880 /* Don't stop: write watchpoints shouldn't fire if
2881 the value hasn't changed. */
2882 bs
->print_it
= print_it_noop
;
2892 /* Error from catch_errors. */
2893 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2894 if (b
->related_breakpoint
)
2895 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2896 b
->disposition
= disp_del_at_next_stop
;
2897 /* We've already printed what needs to be printed. */
2898 bs
->print_it
= print_it_done
;
2902 else /* must_check_value == 0 */
2904 /* This is a case where some watchpoint(s) triggered, but
2905 not at the address of this watchpoint, or else no
2906 watchpoint triggered after all. So don't print
2907 anything for this watchpoint. */
2908 bs
->print_it
= print_it_noop
;
2915 /* By definition, an encountered breakpoint is a triggered
2920 if (frame_id_p (b
->frame_id
)
2921 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2925 int value_is_zero
= 0;
2927 /* If this is a scope breakpoint, mark the associated
2928 watchpoint as triggered so that we will handle the
2929 out-of-scope event. We'll get to the watchpoint next
2931 if (b
->type
== bp_watchpoint_scope
)
2932 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2934 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2936 /* Need to select the frame, with all that implies
2937 so that the conditions will have the right context. */
2938 select_frame (get_current_frame ());
2940 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2941 "Error in testing breakpoint condition:\n",
2943 /* FIXME-someday, should give breakpoint # */
2946 if (bl
->cond
&& value_is_zero
)
2949 /* Don't consider this a hit. */
2952 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2955 /* Don't consider this a hit. */
2958 else if (b
->ignore_count
> 0)
2961 annotate_ignore_count_change ();
2964 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2965 /* We do not stop for these. */
2969 /* We will stop here */
2970 if (b
->disposition
== disp_disable
)
2971 b
->enable_state
= bp_disabled
;
2974 bs
->commands
= b
->commands
;
2976 (strcmp ("silent", bs
->commands
->line
) == 0
2977 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2979 bs
->commands
= bs
->commands
->next
;
2982 bs
->commands
= copy_command_lines (bs
->commands
);
2985 /* Print nothing for this entry if we dont stop or if we dont print. */
2986 if (bs
->stop
== 0 || bs
->print
== 0)
2987 bs
->print_it
= print_it_noop
;
2990 bs
->next
= NULL
; /* Terminate the chain */
2991 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2993 /* If we aren't stopping, the value of some hardware watchpoint may
2994 not have changed, but the intermediate memory locations we are
2995 watching may have. Don't bother if we're stopping; this will get
2997 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3002 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3004 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3005 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3006 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3008 /* remove/insert can invalidate bs->breakpoint_at, if this
3009 location is no longer used by the watchpoint. Prevent
3010 further code from trying to use it. */
3011 bs
->breakpoint_at
= NULL
;
3012 remove_breakpoints ();
3013 insert_breakpoints ();
3017 return root_bs
->next
;
3020 /* Tell what to do about this bpstat. */
3022 bpstat_what (bpstat bs
)
3024 /* Classify each bpstat as one of the following. */
3027 /* This bpstat element has no effect on the main_action. */
3030 /* There was a watchpoint, stop but don't print. */
3033 /* There was a watchpoint, stop and print. */
3036 /* There was a breakpoint but we're not stopping. */
3039 /* There was a breakpoint, stop but don't print. */
3042 /* There was a breakpoint, stop and print. */
3045 /* We hit the longjmp breakpoint. */
3048 /* We hit the longjmp_resume breakpoint. */
3051 /* We hit the step_resume breakpoint. */
3054 /* We hit the shared library event breakpoint. */
3057 /* We caught a shared library event. */
3060 /* This is just used to count how many enums there are. */
3064 /* Here is the table which drives this routine. So that we can
3065 format it pretty, we define some abbreviations for the
3066 enum bpstat_what codes. */
3067 #define kc BPSTAT_WHAT_KEEP_CHECKING
3068 #define ss BPSTAT_WHAT_STOP_SILENT
3069 #define sn BPSTAT_WHAT_STOP_NOISY
3070 #define sgl BPSTAT_WHAT_SINGLE
3071 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3072 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3073 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3074 #define sr BPSTAT_WHAT_STEP_RESUME
3075 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3076 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3078 /* "Can't happen." Might want to print an error message.
3079 abort() is not out of the question, but chances are GDB is just
3080 a bit confused, not unusable. */
3081 #define err BPSTAT_WHAT_STOP_NOISY
3083 /* Given an old action and a class, come up with a new action. */
3084 /* One interesting property of this table is that wp_silent is the same
3085 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3086 after stopping, the check for whether to step over a breakpoint
3087 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3088 reference to how we stopped. We retain separate wp_silent and
3089 bp_silent codes in case we want to change that someday.
3091 Another possibly interesting property of this table is that
3092 there's a partial ordering, priority-like, of the actions. Once
3093 you've decided that some action is appropriate, you'll never go
3094 back and decide something of a lower priority is better. The
3097 kc < clr sgl shl shlr slr sn sr ss
3098 sgl < clrs shl shlr slr sn sr ss
3099 slr < err shl shlr sn sr ss
3100 clr < clrs err shl shlr sn sr ss
3101 clrs < err shl shlr sn sr ss
3108 What I think this means is that we don't need a damned table
3109 here. If you just put the rows and columns in the right order,
3110 it'd look awfully regular. We could simply walk the bpstat list
3111 and choose the highest priority action we find, with a little
3112 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3113 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3114 is messy anyway). */
3116 /* step_resume entries: a step resume breakpoint overrides another
3117 breakpoint of signal handling (see comment in wait_for_inferior
3118 at where we set the step_resume breakpoint). */
3120 static const enum bpstat_what_main_action
3121 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3124 /* kc ss sn sgl slr clr clrs sr shl shlr
3127 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3129 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3131 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3133 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3135 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3137 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3139 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3141 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3143 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3145 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3147 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3162 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3163 struct bpstat_what retval
;
3165 retval
.call_dummy
= 0;
3166 for (; bs
!= NULL
; bs
= bs
->next
)
3168 enum class bs_class
= no_effect
;
3169 if (bs
->breakpoint_at
== NULL
)
3170 /* I suspect this can happen if it was a momentary breakpoint
3171 which has since been deleted. */
3173 switch (bs
->breakpoint_at
->owner
->type
)
3179 case bp_hardware_breakpoint
:
3185 bs_class
= bp_noisy
;
3187 bs_class
= bp_silent
;
3190 bs_class
= bp_nostop
;
3193 case bp_hardware_watchpoint
:
3194 case bp_read_watchpoint
:
3195 case bp_access_watchpoint
:
3199 bs_class
= wp_noisy
;
3201 bs_class
= wp_silent
;
3204 /* There was a watchpoint, but we're not stopping.
3205 This requires no further action. */
3206 bs_class
= no_effect
;
3209 bs_class
= long_jump
;
3211 case bp_longjmp_resume
:
3212 bs_class
= long_resume
;
3214 case bp_step_resume
:
3217 bs_class
= step_resume
;
3220 /* It is for the wrong frame. */
3221 bs_class
= bp_nostop
;
3223 case bp_watchpoint_scope
:
3224 bs_class
= bp_nostop
;
3226 case bp_shlib_event
:
3227 bs_class
= shlib_event
;
3229 case bp_thread_event
:
3230 case bp_overlay_event
:
3231 bs_class
= bp_nostop
;
3234 case bp_catch_unload
:
3235 /* Only if this catchpoint triggered should we cause the
3236 step-out-of-dld behaviour. Otherwise, we ignore this
3239 bs_class
= catch_shlib_event
;
3241 bs_class
= no_effect
;
3244 case bp_catch_vfork
:
3249 bs_class
= bp_noisy
;
3251 bs_class
= bp_silent
;
3254 /* There was a catchpoint, but we're not stopping.
3255 This requires no further action. */
3256 bs_class
= no_effect
;
3259 /* Make sure the action is stop (silent or noisy),
3260 so infrun.c pops the dummy frame. */
3261 bs_class
= bp_silent
;
3262 retval
.call_dummy
= 1;
3265 current_action
= table
[(int) bs_class
][(int) current_action
];
3267 retval
.main_action
= current_action
;
3271 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3272 without hardware support). This isn't related to a specific bpstat,
3273 just to things like whether watchpoints are set. */
3276 bpstat_should_step (void)
3278 struct breakpoint
*b
;
3280 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3287 /* Given a bpstat that records zero or more triggered eventpoints, this
3288 function returns another bpstat which contains only the catchpoints
3289 on that first list, if any. */
3291 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3293 struct bpstats root_bs
[1];
3294 bpstat bs
= root_bs
;
3295 struct breakpoint
*ep
;
3298 bpstat_clear (cp_list
);
3299 root_bs
->next
= NULL
;
3301 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3303 /* Is this eventpoint a catchpoint? If not, ignore it. */
3304 ep
= ep_list
->breakpoint_at
->owner
;
3307 if ((ep
->type
!= bp_catch_load
) &&
3308 (ep
->type
!= bp_catch_unload
))
3309 /* pai: (temp) ADD fork/vfork here!! */
3312 /* Yes; add it to the list. */
3313 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3318 #if defined(SOLIB_ADD)
3319 /* Also, for each triggered catchpoint, tag it with the name of
3320 the library that caused this trigger. (We copy the name now,
3321 because it's only guaranteed to be available NOW, when the
3322 catchpoint triggers. Clients who may wish to know the name
3323 later must get it from the catchpoint itself.) */
3324 if (ep
->triggered_dll_pathname
!= NULL
)
3325 xfree (ep
->triggered_dll_pathname
);
3326 if (ep
->type
== bp_catch_load
)
3327 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3328 PIDGET (inferior_ptid
));
3330 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3331 PIDGET (inferior_ptid
));
3333 dll_pathname
= NULL
;
3337 ep
->triggered_dll_pathname
= (char *)
3338 xmalloc (strlen (dll_pathname
) + 1);
3339 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3342 ep
->triggered_dll_pathname
= NULL
;
3348 static void print_breakpoint_location (struct breakpoint
*b
,
3349 struct bp_location
*loc
,
3351 struct ui_stream
*stb
)
3356 = find_pc_sect_function (loc
->address
, loc
->section
);
3359 ui_out_text (uiout
, "in ");
3360 ui_out_field_string (uiout
, "func",
3361 SYMBOL_PRINT_NAME (sym
));
3362 ui_out_wrap_hint (uiout
, wrap_indent
);
3363 ui_out_text (uiout
, " at ");
3365 ui_out_field_string (uiout
, "file", b
->source_file
);
3366 ui_out_text (uiout
, ":");
3368 if (ui_out_is_mi_like_p (uiout
))
3370 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3371 char *fullname
= symtab_to_fullname (sal
.symtab
);
3374 ui_out_field_string (uiout
, "fullname", fullname
);
3377 ui_out_field_int (uiout
, "line", b
->line_number
);
3381 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3385 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3386 ui_out_field_stream (uiout
, "at", stb
);
3390 /* Print B to gdb_stdout. */
3392 print_one_breakpoint_location (struct breakpoint
*b
,
3393 struct bp_location
*loc
,
3395 CORE_ADDR
*last_addr
)
3397 struct command_line
*l
;
3399 struct ep_type_description
3404 static struct ep_type_description bptypes
[] =
3406 {bp_none
, "?deleted?"},
3407 {bp_breakpoint
, "breakpoint"},
3408 {bp_hardware_breakpoint
, "hw breakpoint"},
3409 {bp_until
, "until"},
3410 {bp_finish
, "finish"},
3411 {bp_watchpoint
, "watchpoint"},
3412 {bp_hardware_watchpoint
, "hw watchpoint"},
3413 {bp_read_watchpoint
, "read watchpoint"},
3414 {bp_access_watchpoint
, "acc watchpoint"},
3415 {bp_longjmp
, "longjmp"},
3416 {bp_longjmp_resume
, "longjmp resume"},
3417 {bp_step_resume
, "step resume"},
3418 {bp_watchpoint_scope
, "watchpoint scope"},
3419 {bp_call_dummy
, "call dummy"},
3420 {bp_shlib_event
, "shlib events"},
3421 {bp_thread_event
, "thread events"},
3422 {bp_overlay_event
, "overlay events"},
3423 {bp_catch_load
, "catch load"},
3424 {bp_catch_unload
, "catch unload"},
3425 {bp_catch_fork
, "catch fork"},
3426 {bp_catch_vfork
, "catch vfork"},
3427 {bp_catch_exec
, "catch exec"}
3430 static char bpenables
[] = "nynny";
3431 char wrap_indent
[80];
3432 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3433 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3434 struct cleanup
*bkpt_chain
;
3436 int header_of_multiple
= 0;
3437 int part_of_multiple
= (loc
!= NULL
);
3439 gdb_assert (!loc
|| loc_number
!= 0);
3440 /* See comment in print_one_breakpoint concerning
3441 treatment of breakpoints with single disabled
3445 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3446 header_of_multiple
= 1;
3451 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3455 if (part_of_multiple
)
3458 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3459 ui_out_field_string (uiout
, "number", formatted
);
3464 ui_out_field_int (uiout
, "number", b
->number
);
3469 if (part_of_multiple
)
3470 ui_out_field_skip (uiout
, "type");
3473 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3474 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3475 internal_error (__FILE__
, __LINE__
,
3476 _("bptypes table does not describe type #%d."),
3478 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3483 if (part_of_multiple
)
3484 ui_out_field_skip (uiout
, "disp");
3486 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3491 if (part_of_multiple
)
3492 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3494 ui_out_field_fmt (uiout
, "enabled", "%c",
3495 bpenables
[(int) b
->enable_state
]);
3496 ui_out_spaces (uiout
, 2);
3500 strcpy (wrap_indent
, " ");
3503 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3504 strcat (wrap_indent
, " ");
3506 strcat (wrap_indent
, " ");
3509 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3511 /* Although the print_one can possibly print
3512 all locations, calling it here is not likely
3513 to get any nice result. So, make sure there's
3514 just one location. */
3515 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3516 b
->ops
->print_one (b
, last_addr
);
3522 internal_error (__FILE__
, __LINE__
,
3523 _("print_one_breakpoint: bp_none encountered\n"));
3527 case bp_hardware_watchpoint
:
3528 case bp_read_watchpoint
:
3529 case bp_access_watchpoint
:
3530 /* Field 4, the address, is omitted (which makes the columns
3531 not line up too nicely with the headers, but the effect
3532 is relatively readable). */
3534 ui_out_field_skip (uiout
, "addr");
3536 print_expression (b
->exp
, stb
->stream
);
3537 ui_out_field_stream (uiout
, "what", stb
);
3541 case bp_catch_unload
:
3542 /* Field 4, the address, is omitted (which makes the columns
3543 not line up too nicely with the headers, but the effect
3544 is relatively readable). */
3546 ui_out_field_skip (uiout
, "addr");
3548 if (b
->dll_pathname
== NULL
)
3550 ui_out_field_string (uiout
, "what", "<any library>");
3551 ui_out_spaces (uiout
, 1);
3555 ui_out_text (uiout
, "library \"");
3556 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3557 ui_out_text (uiout
, "\" ");
3562 case bp_catch_vfork
:
3563 /* Field 4, the address, is omitted (which makes the columns
3564 not line up too nicely with the headers, but the effect
3565 is relatively readable). */
3567 ui_out_field_skip (uiout
, "addr");
3569 if (b
->forked_inferior_pid
!= 0)
3571 ui_out_text (uiout
, "process ");
3572 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3573 ui_out_spaces (uiout
, 1);
3578 /* Field 4, the address, is omitted (which makes the columns
3579 not line up too nicely with the headers, but the effect
3580 is relatively readable). */
3582 ui_out_field_skip (uiout
, "addr");
3584 if (b
->exec_pathname
!= NULL
)
3586 ui_out_text (uiout
, "program \"");
3587 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3588 ui_out_text (uiout
, "\" ");
3593 case bp_hardware_breakpoint
:
3597 case bp_longjmp_resume
:
3598 case bp_step_resume
:
3599 case bp_watchpoint_scope
:
3601 case bp_shlib_event
:
3602 case bp_thread_event
:
3603 case bp_overlay_event
:
3607 if (header_of_multiple
)
3608 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3609 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3610 ui_out_field_string (uiout
, "addr", "<PENDING>");
3612 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3615 if (!header_of_multiple
)
3616 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3618 *last_addr
= b
->loc
->address
;
3622 if (!part_of_multiple
&& b
->thread
!= -1)
3624 /* FIXME: This seems to be redundant and lost here; see the
3625 "stop only in" line a little further down. */
3626 ui_out_text (uiout
, " thread ");
3627 ui_out_field_int (uiout
, "thread", b
->thread
);
3630 ui_out_text (uiout
, "\n");
3632 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3635 ui_out_text (uiout
, "\tstop only in stack frame at ");
3636 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3638 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3639 ui_out_text (uiout
, "\n");
3642 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3644 /* We do not print the condition for Ada exception catchpoints
3645 because the condition is an internal implementation detail
3646 that we do not want to expose to the user. */
3648 ui_out_text (uiout
, "\tstop only if ");
3649 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3650 ui_out_text (uiout
, "\n");
3653 if (!part_of_multiple
&& b
->thread
!= -1)
3655 /* FIXME should make an annotation for this */
3656 ui_out_text (uiout
, "\tstop only in thread ");
3657 ui_out_field_int (uiout
, "thread", b
->thread
);
3658 ui_out_text (uiout
, "\n");
3661 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3663 /* FIXME should make an annotation for this */
3664 if (ep_is_catchpoint (b
))
3665 ui_out_text (uiout
, "\tcatchpoint");
3667 ui_out_text (uiout
, "\tbreakpoint");
3668 ui_out_text (uiout
, " already hit ");
3669 ui_out_field_int (uiout
, "times", b
->hit_count
);
3670 if (b
->hit_count
== 1)
3671 ui_out_text (uiout
, " time\n");
3673 ui_out_text (uiout
, " times\n");
3676 /* Output the count also if it is zero, but only if this is
3677 mi. FIXME: Should have a better test for this. */
3678 if (ui_out_is_mi_like_p (uiout
))
3679 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3680 ui_out_field_int (uiout
, "times", b
->hit_count
);
3682 if (!part_of_multiple
&& b
->ignore_count
)
3685 ui_out_text (uiout
, "\tignore next ");
3686 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3687 ui_out_text (uiout
, " hits\n");
3690 if (!part_of_multiple
&& (l
= b
->commands
))
3692 struct cleanup
*script_chain
;
3695 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3696 print_command_lines (uiout
, l
, 4);
3697 do_cleanups (script_chain
);
3699 do_cleanups (bkpt_chain
);
3700 do_cleanups (old_chain
);
3704 print_one_breakpoint (struct breakpoint
*b
,
3705 CORE_ADDR
*last_addr
)
3707 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3709 /* If this breakpoint has custom print function,
3710 it's already printed. Otherwise, print individual
3711 locations, if any. */
3712 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3714 /* If breakpoint has a single location that is
3715 disabled, we print it as if it had
3716 several locations, since otherwise it's hard to
3717 represent "breakpoint enabled, location disabled"
3719 Note that while hardware watchpoints have
3720 several locations internally, that's no a property
3723 && !is_hardware_watchpoint (b
)
3724 && (b
->loc
->next
|| !b
->loc
->enabled
)
3725 && !ui_out_is_mi_like_p (uiout
))
3727 struct bp_location
*loc
;
3729 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3730 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3736 struct captured_breakpoint_query_args
3742 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3744 struct captured_breakpoint_query_args
*args
= data
;
3745 struct breakpoint
*b
;
3746 CORE_ADDR dummy_addr
= 0;
3749 if (args
->bnum
== b
->number
)
3751 print_one_breakpoint (b
, &dummy_addr
);
3759 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3761 struct captured_breakpoint_query_args args
;
3763 /* For the moment we don't trust print_one_breakpoint() to not throw
3765 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3766 error_message
, RETURN_MASK_ALL
) < 0)
3772 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3773 catchpoints, et.al.). */
3776 user_settable_breakpoint (const struct breakpoint
*b
)
3778 return (b
->type
== bp_breakpoint
3779 || b
->type
== bp_catch_load
3780 || b
->type
== bp_catch_unload
3781 || b
->type
== bp_catch_fork
3782 || b
->type
== bp_catch_vfork
3783 || b
->type
== bp_catch_exec
3784 || b
->type
== bp_hardware_breakpoint
3785 || b
->type
== bp_watchpoint
3786 || b
->type
== bp_read_watchpoint
3787 || b
->type
== bp_access_watchpoint
3788 || b
->type
== bp_hardware_watchpoint
);
3791 /* Print information on user settable breakpoint (watchpoint, etc)
3792 number BNUM. If BNUM is -1 print all user settable breakpoints.
3793 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3796 breakpoint_1 (int bnum
, int allflag
)
3798 struct breakpoint
*b
;
3799 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3800 int nr_printable_breakpoints
;
3801 struct cleanup
*bkpttbl_chain
;
3803 /* Compute the number of rows in the table. */
3804 nr_printable_breakpoints
= 0;
3807 || bnum
== b
->number
)
3809 if (allflag
|| user_settable_breakpoint (b
))
3810 nr_printable_breakpoints
++;
3815 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3819 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3822 if (nr_printable_breakpoints
> 0)
3823 annotate_breakpoints_headers ();
3824 if (nr_printable_breakpoints
> 0)
3826 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3827 if (nr_printable_breakpoints
> 0)
3829 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3830 if (nr_printable_breakpoints
> 0)
3832 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3833 if (nr_printable_breakpoints
> 0)
3835 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3838 if (nr_printable_breakpoints
> 0)
3840 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3841 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3843 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3845 if (nr_printable_breakpoints
> 0)
3847 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3848 ui_out_table_body (uiout
);
3849 if (nr_printable_breakpoints
> 0)
3850 annotate_breakpoints_table ();
3854 || bnum
== b
->number
)
3856 /* We only print out user settable breakpoints unless the
3858 if (allflag
|| user_settable_breakpoint (b
))
3859 print_one_breakpoint (b
, &last_addr
);
3862 do_cleanups (bkpttbl_chain
);
3864 if (nr_printable_breakpoints
== 0)
3867 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3869 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3874 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3875 that a comparison of an unsigned with -1 is always false. */
3876 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3877 set_next_address (last_addr
);
3880 /* FIXME? Should this be moved up so that it is only called when
3881 there have been breakpoints? */
3882 annotate_breakpoints_table_end ();
3886 breakpoints_info (char *bnum_exp
, int from_tty
)
3891 bnum
= parse_and_eval_long (bnum_exp
);
3893 breakpoint_1 (bnum
, 0);
3897 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3902 bnum
= parse_and_eval_long (bnum_exp
);
3904 breakpoint_1 (bnum
, 1);
3908 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
3910 struct bp_location
*bl
= b
->loc
;
3911 for (; bl
; bl
= bl
->next
)
3913 if (bl
->address
== pc
3914 && (!overlay_debugging
|| bl
->section
== section
))
3920 /* Print a message describing any breakpoints set at PC. */
3923 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3926 struct breakpoint
*b
;
3929 others
+= breakpoint_has_pc (b
, pc
, section
);
3933 printf_filtered (_("Note: breakpoint "));
3934 else /* if (others == ???) */
3935 printf_filtered (_("Note: breakpoints "));
3937 if (breakpoint_has_pc (b
, pc
, section
))
3940 printf_filtered ("%d", b
->number
);
3941 if (b
->thread
== -1 && thread
!= -1)
3942 printf_filtered (" (all threads)");
3943 else if (b
->thread
!= -1)
3944 printf_filtered (" (thread %d)", b
->thread
);
3945 printf_filtered ("%s%s ",
3946 ((b
->enable_state
== bp_disabled
||
3947 b
->enable_state
== bp_call_disabled
)
3949 : b
->enable_state
== bp_permanent
3953 : ((others
== 1) ? " and" : ""));
3955 printf_filtered (_("also set at pc "));
3956 fputs_filtered (paddress (pc
), gdb_stdout
);
3957 printf_filtered (".\n");
3961 /* Set the default place to put a breakpoint
3962 for the `break' command with no arguments. */
3965 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3968 default_breakpoint_valid
= valid
;
3969 default_breakpoint_address
= addr
;
3970 default_breakpoint_symtab
= symtab
;
3971 default_breakpoint_line
= line
;
3974 /* Return true iff it is meaningful to use the address member of
3975 BPT. For some breakpoint types, the address member is irrelevant
3976 and it makes no sense to attempt to compare it to other addresses
3977 (or use it for any other purpose either).
3979 More specifically, each of the following breakpoint types will always
3980 have a zero valued address and we don't want check_duplicates() to mark
3981 breakpoints of any of these types to be a duplicate of an actual
3982 breakpoint at address zero:
3985 bp_hardware_watchpoint
3987 bp_access_watchpoint
3994 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3996 enum bptype type
= bpt
->type
;
3998 return (type
!= bp_watchpoint
3999 && type
!= bp_hardware_watchpoint
4000 && type
!= bp_read_watchpoint
4001 && type
!= bp_access_watchpoint
4002 && type
!= bp_catch_exec
4003 && type
!= bp_longjmp_resume
4004 && type
!= bp_catch_fork
4005 && type
!= bp_catch_vfork
);
4008 /* Rescan breakpoints at the same address and section as BPT,
4009 marking the first one as "first" and any others as "duplicates".
4010 This is so that the bpt instruction is only inserted once.
4011 If we have a permanent breakpoint at the same place as BPT, make
4012 that one the official one, and the rest as duplicates. */
4015 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4017 struct bp_location
*b
;
4019 struct bp_location
*perm_bp
= 0;
4021 ALL_BP_LOCATIONS (b
)
4022 if (b
->owner
->enable_state
!= bp_disabled
4023 && b
->owner
->enable_state
!= bp_call_disabled
4025 && !b
->shlib_disabled
4026 && b
->address
== address
/* address / overlay match */
4027 && (!overlay_debugging
|| b
->section
== section
)
4028 && breakpoint_address_is_meaningful (b
->owner
))
4030 /* Have we found a permanent breakpoint? */
4031 if (b
->owner
->enable_state
== bp_permanent
)
4038 b
->duplicate
= count
> 1;
4041 /* If we found a permanent breakpoint at this address, go over the
4042 list again and declare all the other breakpoints there to be the
4046 perm_bp
->duplicate
= 0;
4048 /* Permanent breakpoint should always be inserted. */
4049 if (! perm_bp
->inserted
)
4050 internal_error (__FILE__
, __LINE__
,
4051 _("allegedly permanent breakpoint is not "
4052 "actually inserted"));
4054 ALL_BP_LOCATIONS (b
)
4057 if (b
->owner
->enable_state
!= bp_disabled
4058 && b
->owner
->enable_state
!= bp_call_disabled
4059 && b
->enabled
&& !b
->shlib_disabled
4060 && b
->address
== address
/* address / overlay match */
4061 && (!overlay_debugging
|| b
->section
== section
)
4062 && breakpoint_address_is_meaningful (b
->owner
))
4065 internal_error (__FILE__
, __LINE__
,
4066 _("another breakpoint was inserted on top of "
4067 "a permanent breakpoint"));
4076 check_duplicates (struct breakpoint
*bpt
)
4078 struct bp_location
*bl
= bpt
->loc
;
4080 if (! breakpoint_address_is_meaningful (bpt
))
4083 for (; bl
; bl
= bl
->next
)
4084 check_duplicates_for (bl
->address
, bl
->section
);
4088 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4089 int bnum
, int have_bnum
)
4094 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4095 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4097 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4098 bnum
, astr1
, astr2
);
4100 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4103 /* Adjust a breakpoint's address to account for architectural constraints
4104 on breakpoint placement. Return the adjusted address. Note: Very
4105 few targets require this kind of adjustment. For most targets,
4106 this function is simply the identity function. */
4109 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4111 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4113 /* Very few targets need any kind of breakpoint adjustment. */
4116 else if (bptype
== bp_watchpoint
4117 || bptype
== bp_hardware_watchpoint
4118 || bptype
== bp_read_watchpoint
4119 || bptype
== bp_access_watchpoint
4120 || bptype
== bp_catch_fork
4121 || bptype
== bp_catch_vfork
4122 || bptype
== bp_catch_exec
)
4124 /* Watchpoints and the various bp_catch_* eventpoints should not
4125 have their addresses modified. */
4130 CORE_ADDR adjusted_bpaddr
;
4132 /* Some targets have architectural constraints on the placement
4133 of breakpoint instructions. Obtain the adjusted address. */
4134 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4137 /* An adjusted breakpoint address can significantly alter
4138 a user's expectations. Print a warning if an adjustment
4140 if (adjusted_bpaddr
!= bpaddr
)
4141 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4143 return adjusted_bpaddr
;
4147 /* Allocate a struct bp_location. */
4149 static struct bp_location
*
4150 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4152 struct bp_location
*loc
, *loc_p
;
4154 loc
= xmalloc (sizeof (struct bp_location
));
4155 memset (loc
, 0, sizeof (*loc
));
4159 loc
->shlib_disabled
= 0;
4168 case bp_longjmp_resume
:
4169 case bp_step_resume
:
4170 case bp_watchpoint_scope
:
4172 case bp_shlib_event
:
4173 case bp_thread_event
:
4174 case bp_overlay_event
:
4176 case bp_catch_unload
:
4177 loc
->loc_type
= bp_loc_software_breakpoint
;
4179 case bp_hardware_breakpoint
:
4180 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4182 case bp_hardware_watchpoint
:
4183 case bp_read_watchpoint
:
4184 case bp_access_watchpoint
:
4185 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4189 case bp_catch_vfork
:
4191 loc
->loc_type
= bp_loc_other
;
4194 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4197 /* Add this breakpoint to the end of the chain. */
4199 loc_p
= bp_location_chain
;
4201 bp_location_chain
= loc
;
4204 while (loc_p
->global_next
)
4205 loc_p
= loc_p
->global_next
;
4206 loc_p
->global_next
= loc
;
4212 static void free_bp_location (struct bp_location
*loc
)
4219 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4220 that has type BPTYPE and has no locations as yet. */
4222 static struct breakpoint
*
4223 set_raw_breakpoint_without_location (enum bptype bptype
)
4225 struct breakpoint
*b
, *b1
;
4227 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4228 memset (b
, 0, sizeof (*b
));
4231 b
->language
= current_language
->la_language
;
4232 b
->input_radix
= input_radix
;
4234 b
->enable_state
= bp_enabled
;
4237 b
->ignore_count
= 0;
4239 b
->frame_id
= null_frame_id
;
4240 b
->dll_pathname
= NULL
;
4241 b
->triggered_dll_pathname
= NULL
;
4242 b
->forked_inferior_pid
= 0;
4243 b
->exec_pathname
= NULL
;
4245 b
->condition_not_parsed
= 0;
4247 /* Add this breakpoint to the end of the chain
4248 so that a list of breakpoints will come out in order
4249 of increasing numbers. */
4251 b1
= breakpoint_chain
;
4253 breakpoint_chain
= b
;
4263 /* Initialize loc->function_name. */
4265 set_breakpoint_location_function (struct bp_location
*loc
)
4267 if (loc
->owner
->type
== bp_breakpoint
4268 || loc
->owner
->type
== bp_hardware_breakpoint
)
4270 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4272 if (loc
->function_name
)
4273 loc
->function_name
= xstrdup (loc
->function_name
);
4277 /* set_raw_breakpoint is a low level routine for allocating and
4278 partially initializing a breakpoint of type BPTYPE. The newly
4279 created breakpoint's address, section, source file name, and line
4280 number are provided by SAL. The newly created and partially
4281 initialized breakpoint is added to the breakpoint chain and
4282 is also returned as the value of this function.
4284 It is expected that the caller will complete the initialization of
4285 the newly created breakpoint struct as well as output any status
4286 information regarding the creation of a new breakpoint. In
4287 particular, set_raw_breakpoint does NOT set the breakpoint
4288 number! Care should be taken to not allow an error to occur
4289 prior to completing the initialization of the breakpoint. If this
4290 should happen, a bogus breakpoint will be left on the chain. */
4293 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4295 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4296 CORE_ADDR adjusted_address
;
4298 /* Adjust the breakpoint's address prior to allocating a location.
4299 Once we call allocate_bp_location(), that mostly uninitialized
4300 location will be placed on the location chain. Adjustment of the
4301 breakpoint may cause target_read_memory() to be called and we do
4302 not want its scan of the location chain to find a breakpoint and
4303 location that's only been partially initialized. */
4304 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4306 b
->loc
= allocate_bp_location (b
, bptype
);
4307 b
->loc
->requested_address
= sal
.pc
;
4308 b
->loc
->address
= adjusted_address
;
4310 if (sal
.symtab
== NULL
)
4311 b
->source_file
= NULL
;
4313 b
->source_file
= savestring (sal
.symtab
->filename
,
4314 strlen (sal
.symtab
->filename
));
4315 b
->loc
->section
= sal
.section
;
4316 b
->line_number
= sal
.line
;
4318 set_breakpoint_location_function (b
->loc
);
4320 check_duplicates (b
);
4321 breakpoints_changed ();
4327 /* Note that the breakpoint object B describes a permanent breakpoint
4328 instruction, hard-wired into the inferior's code. */
4330 make_breakpoint_permanent (struct breakpoint
*b
)
4332 struct bp_location
*bl
;
4333 b
->enable_state
= bp_permanent
;
4335 /* By definition, permanent breakpoints are already present in the code.
4336 Mark all locations as inserted. For now, make_breakpoint_permanent
4337 is called in just one place, so it's hard to say if it's reasonable
4338 to have permanent breakpoint with multiple locations or not,
4339 but it's easy to implmement. */
4340 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4344 static struct breakpoint
*
4345 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4347 static int internal_breakpoint_number
= -1;
4348 struct symtab_and_line sal
;
4349 struct breakpoint
*b
;
4351 init_sal (&sal
); /* initialize to zeroes */
4354 sal
.section
= find_pc_overlay (sal
.pc
);
4356 b
= set_raw_breakpoint (sal
, type
);
4357 b
->number
= internal_breakpoint_number
--;
4358 b
->disposition
= disp_donttouch
;
4365 create_longjmp_breakpoint (char *func_name
)
4367 struct breakpoint
*b
;
4368 struct minimal_symbol
*m
;
4370 if (func_name
== NULL
)
4371 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4374 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4377 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4380 b
->enable_state
= bp_disabled
;
4383 b
->addr_string
= xstrdup (func_name
);
4386 /* Call this routine when stepping and nexting to enable a breakpoint
4387 if we do a longjmp(). When we hit that breakpoint, call
4388 set_longjmp_resume_breakpoint() to figure out where we are going. */
4391 enable_longjmp_breakpoint (void)
4393 struct breakpoint
*b
;
4396 if (b
->type
== bp_longjmp
)
4398 b
->enable_state
= bp_enabled
;
4399 check_duplicates (b
);
4404 disable_longjmp_breakpoint (void)
4406 struct breakpoint
*b
;
4409 if (b
->type
== bp_longjmp
4410 || b
->type
== bp_longjmp_resume
)
4412 b
->enable_state
= bp_disabled
;
4413 check_duplicates (b
);
4418 create_overlay_event_breakpoint (char *func_name
)
4420 struct breakpoint
*b
;
4421 struct minimal_symbol
*m
;
4423 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4426 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4428 b
->addr_string
= xstrdup (func_name
);
4430 if (overlay_debugging
== ovly_auto
)
4432 b
->enable_state
= bp_enabled
;
4433 overlay_events_enabled
= 1;
4437 b
->enable_state
= bp_disabled
;
4438 overlay_events_enabled
= 0;
4443 enable_overlay_breakpoints (void)
4445 struct breakpoint
*b
;
4448 if (b
->type
== bp_overlay_event
)
4450 b
->enable_state
= bp_enabled
;
4451 check_duplicates (b
);
4452 overlay_events_enabled
= 1;
4457 disable_overlay_breakpoints (void)
4459 struct breakpoint
*b
;
4462 if (b
->type
== bp_overlay_event
)
4464 b
->enable_state
= bp_disabled
;
4465 check_duplicates (b
);
4466 overlay_events_enabled
= 0;
4471 create_thread_event_breakpoint (CORE_ADDR address
)
4473 struct breakpoint
*b
;
4475 b
= create_internal_breakpoint (address
, bp_thread_event
);
4477 b
->enable_state
= bp_enabled
;
4478 /* addr_string has to be used or breakpoint_re_set will delete me. */
4479 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4485 remove_thread_event_breakpoints (void)
4487 struct breakpoint
*b
, *temp
;
4489 ALL_BREAKPOINTS_SAFE (b
, temp
)
4490 if (b
->type
== bp_thread_event
)
4491 delete_breakpoint (b
);
4494 struct captured_parse_breakpoint_args
4497 struct symtabs_and_lines
*sals_p
;
4498 char ***addr_string_p
;
4502 struct lang_and_radix
4510 remove_solib_event_breakpoints (void)
4512 struct breakpoint
*b
, *temp
;
4514 ALL_BREAKPOINTS_SAFE (b
, temp
)
4515 if (b
->type
== bp_shlib_event
)
4516 delete_breakpoint (b
);
4520 create_solib_event_breakpoint (CORE_ADDR address
)
4522 struct breakpoint
*b
;
4524 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4528 /* Disable any breakpoints that are on code in shared libraries. Only
4529 apply to enabled breakpoints, disabled ones can just stay disabled. */
4532 disable_breakpoints_in_shlibs (void)
4534 struct bp_location
*loc
;
4535 int disabled_shlib_breaks
= 0;
4537 ALL_BP_LOCATIONS (loc
)
4539 struct breakpoint
*b
= loc
->owner
;
4540 /* We apply the check to all breakpoints, including disabled
4541 for those with loc->duplicate set. This is so that when breakpoint
4542 becomes enabled, or the duplicate is removed, gdb will try to insert
4543 all breakpoints. If we don't set shlib_disabled here, we'll try
4544 to insert those breakpoints and fail. */
4545 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4546 && !loc
->shlib_disabled
4548 && PC_SOLIB (loc
->address
)
4550 && solib_address (loc
->address
)
4554 loc
->shlib_disabled
= 1;
4559 /* Disable any breakpoints that are in in an unloaded shared library. Only
4560 apply to enabled breakpoints, disabled ones can just stay disabled. */
4563 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4565 struct bp_location
*loc
;
4566 int disabled_shlib_breaks
= 0;
4568 ALL_BP_LOCATIONS (loc
)
4570 struct breakpoint
*b
= loc
->owner
;
4571 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4572 || loc
->loc_type
== bp_loc_software_breakpoint
)
4573 && !loc
->shlib_disabled
)
4576 char *so_name
= PC_SOLIB (loc
->address
);
4578 char *so_name
= solib_address (loc
->address
);
4580 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4582 loc
->shlib_disabled
= 1;
4583 /* At this point, we cannot rely on remove_breakpoint
4584 succeeding so we must mark the breakpoint as not inserted
4585 to prevent future errors occurring in remove_breakpoints. */
4587 if (!disabled_shlib_breaks
)
4589 target_terminal_ours_for_output ();
4590 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4593 disabled_shlib_breaks
= 1;
4600 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4601 enum bptype bp_kind
)
4603 struct symtab_and_line sal
;
4604 struct breakpoint
*b
;
4605 int thread
= -1; /* All threads. */
4612 b
= set_raw_breakpoint (sal
, bp_kind
);
4613 set_breakpoint_count (breakpoint_count
+ 1);
4614 b
->number
= breakpoint_count
;
4615 b
->cond_string
= (cond_string
== NULL
) ?
4616 NULL
: savestring (cond_string
, strlen (cond_string
));
4618 b
->addr_string
= NULL
;
4619 b
->enable_state
= bp_enabled
;
4620 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4621 b
->forked_inferior_pid
= 0;
4627 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4629 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4633 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4635 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4639 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4641 struct symtab_and_line sal
;
4642 struct breakpoint
*b
;
4643 int thread
= -1; /* All threads. */
4650 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4651 set_breakpoint_count (breakpoint_count
+ 1);
4652 b
->number
= breakpoint_count
;
4653 b
->cond_string
= (cond_string
== NULL
) ?
4654 NULL
: savestring (cond_string
, strlen (cond_string
));
4656 b
->addr_string
= NULL
;
4657 b
->enable_state
= bp_enabled
;
4658 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4664 hw_breakpoint_used_count (void)
4666 struct breakpoint
*b
;
4671 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4679 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4681 struct breakpoint
*b
;
4684 *other_type_used
= 0;
4687 if (breakpoint_enabled (b
))
4689 if (b
->type
== type
)
4691 else if ((b
->type
== bp_hardware_watchpoint
||
4692 b
->type
== bp_read_watchpoint
||
4693 b
->type
== bp_access_watchpoint
))
4694 *other_type_used
= 1;
4700 /* Call this after hitting the longjmp() breakpoint. Use this to set
4701 a new breakpoint at the target of the jmp_buf.
4703 FIXME - This ought to be done by setting a temporary breakpoint
4704 that gets deleted automatically... */
4707 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4709 struct breakpoint
*b
;
4712 if (b
->type
== bp_longjmp_resume
)
4714 b
->loc
->requested_address
= pc
;
4715 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4717 b
->enable_state
= bp_enabled
;
4718 b
->frame_id
= frame_id
;
4719 check_duplicates (b
);
4725 disable_watchpoints_before_interactive_call_start (void)
4727 struct breakpoint
*b
;
4731 if (((b
->type
== bp_watchpoint
)
4732 || (b
->type
== bp_hardware_watchpoint
)
4733 || (b
->type
== bp_read_watchpoint
)
4734 || (b
->type
== bp_access_watchpoint
))
4735 && breakpoint_enabled (b
))
4737 b
->enable_state
= bp_call_disabled
;
4738 check_duplicates (b
);
4744 enable_watchpoints_after_interactive_call_stop (void)
4746 struct breakpoint
*b
;
4750 if (((b
->type
== bp_watchpoint
)
4751 || (b
->type
== bp_hardware_watchpoint
)
4752 || (b
->type
== bp_read_watchpoint
)
4753 || (b
->type
== bp_access_watchpoint
))
4754 && (b
->enable_state
== bp_call_disabled
))
4756 b
->enable_state
= bp_enabled
;
4757 check_duplicates (b
);
4763 /* Set a breakpoint that will evaporate an end of command
4764 at address specified by SAL.
4765 Restrict it to frame FRAME if FRAME is nonzero. */
4768 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4771 struct breakpoint
*b
;
4772 b
= set_raw_breakpoint (sal
, type
);
4773 b
->enable_state
= bp_enabled
;
4774 b
->disposition
= disp_donttouch
;
4775 b
->frame_id
= frame_id
;
4777 /* If we're debugging a multi-threaded program, then we
4778 want momentary breakpoints to be active in only a
4779 single thread of control. */
4780 if (in_thread_list (inferior_ptid
))
4781 b
->thread
= pid_to_thread_id (inferior_ptid
);
4787 /* Tell the user we have just set a breakpoint B. */
4790 mention (struct breakpoint
*b
)
4793 struct cleanup
*old_chain
, *ui_out_chain
;
4794 struct ui_stream
*stb
;
4796 stb
= ui_out_stream_new (uiout
);
4797 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4799 /* FIXME: This is misplaced; mention() is called by things (like
4800 hitting a watchpoint) other than breakpoint creation. It should
4801 be possible to clean this up and at the same time replace the
4802 random calls to breakpoint_changed with this hook, as has already
4803 been done for deprecated_delete_breakpoint_hook and so on. */
4804 if (deprecated_create_breakpoint_hook
)
4805 deprecated_create_breakpoint_hook (b
);
4806 breakpoint_create_event (b
->number
);
4808 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4809 b
->ops
->print_mention (b
);
4814 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4817 ui_out_text (uiout
, "Watchpoint ");
4818 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4819 ui_out_field_int (uiout
, "number", b
->number
);
4820 ui_out_text (uiout
, ": ");
4821 print_expression (b
->exp
, stb
->stream
);
4822 ui_out_field_stream (uiout
, "exp", stb
);
4823 do_cleanups (ui_out_chain
);
4825 case bp_hardware_watchpoint
:
4826 ui_out_text (uiout
, "Hardware watchpoint ");
4827 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4828 ui_out_field_int (uiout
, "number", b
->number
);
4829 ui_out_text (uiout
, ": ");
4830 print_expression (b
->exp
, stb
->stream
);
4831 ui_out_field_stream (uiout
, "exp", stb
);
4832 do_cleanups (ui_out_chain
);
4834 case bp_read_watchpoint
:
4835 ui_out_text (uiout
, "Hardware read watchpoint ");
4836 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4837 ui_out_field_int (uiout
, "number", b
->number
);
4838 ui_out_text (uiout
, ": ");
4839 print_expression (b
->exp
, stb
->stream
);
4840 ui_out_field_stream (uiout
, "exp", stb
);
4841 do_cleanups (ui_out_chain
);
4843 case bp_access_watchpoint
:
4844 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4845 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4846 ui_out_field_int (uiout
, "number", b
->number
);
4847 ui_out_text (uiout
, ": ");
4848 print_expression (b
->exp
, stb
->stream
);
4849 ui_out_field_stream (uiout
, "exp", stb
);
4850 do_cleanups (ui_out_chain
);
4853 if (ui_out_is_mi_like_p (uiout
))
4858 if (b
->disposition
== disp_del
)
4859 printf_filtered (_("Temporary breakpoint"));
4861 printf_filtered (_("Breakpoint"));
4862 printf_filtered (_(" %d"), b
->number
);
4865 case bp_hardware_breakpoint
:
4866 if (ui_out_is_mi_like_p (uiout
))
4871 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4875 case bp_catch_unload
:
4876 printf_filtered (_("Catchpoint %d (%s %s)"),
4878 (b
->type
== bp_catch_load
) ? "load" : "unload",
4879 (b
->dll_pathname
!= NULL
) ?
4880 b
->dll_pathname
: "<any library>");
4883 case bp_catch_vfork
:
4884 printf_filtered (_("Catchpoint %d (%s)"),
4886 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4889 printf_filtered (_("Catchpoint %d (exec)"),
4896 case bp_longjmp_resume
:
4897 case bp_step_resume
:
4899 case bp_watchpoint_scope
:
4900 case bp_shlib_event
:
4901 case bp_thread_event
:
4902 case bp_overlay_event
:
4908 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4912 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4916 if (addressprint
|| b
->source_file
== NULL
)
4918 printf_filtered (" at ");
4919 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4922 printf_filtered (": file %s, line %d.",
4923 b
->source_file
, b
->line_number
);
4927 struct bp_location
*loc
= b
->loc
;
4929 for (; loc
; loc
= loc
->next
)
4931 printf_filtered (" (%d locations)", n
);
4936 do_cleanups (old_chain
);
4937 if (ui_out_is_mi_like_p (uiout
))
4939 printf_filtered ("\n");
4943 static struct bp_location
*
4944 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
4945 const struct symtab_and_line
*sal
)
4947 struct bp_location
*loc
, **tmp
;
4949 loc
= allocate_bp_location (b
, bptype
);
4950 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
4953 loc
->requested_address
= sal
->pc
;
4954 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
4956 loc
->section
= sal
->section
;
4958 set_breakpoint_location_function (loc
);
4962 /* Create a breakpoint with SAL as location. Use ADDR_STRING
4963 as textual description of the location, and COND_STRING
4964 as condition expression. */
4967 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
4969 enum bptype type
, enum bpdisp disposition
,
4970 int thread
, int ignore_count
, int from_tty
)
4972 struct breakpoint
*b
= NULL
;
4975 if (type
== bp_hardware_breakpoint
)
4977 int i
= hw_breakpoint_used_count ();
4978 int target_resources_ok
=
4979 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4981 if (target_resources_ok
== 0)
4982 error (_("No hardware breakpoint support in the target."));
4983 else if (target_resources_ok
< 0)
4984 error (_("Hardware breakpoints used exceeds limit."));
4987 for (i
= 0; i
< sals
.nelts
; ++i
)
4989 struct symtab_and_line sal
= sals
.sals
[i
];
4990 struct bp_location
*loc
;
4993 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
4997 b
= set_raw_breakpoint (sal
, type
);
4998 set_breakpoint_count (breakpoint_count
+ 1);
4999 b
->number
= breakpoint_count
;
5002 b
->cond_string
= cond_string
;
5003 b
->ignore_count
= ignore_count
;
5004 b
->enable_state
= bp_enabled
;
5005 b
->disposition
= disposition
;
5011 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5016 char *arg
= b
->cond_string
;
5017 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5019 error (_("Garbage %s follows condition"), arg
);
5024 b
->addr_string
= addr_string
;
5026 /* addr_string has to be used or breakpoint_re_set will delete
5028 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5033 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5034 elements to fill the void space. */
5035 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5037 int i
= index_to_remove
+1;
5038 int last_index
= sal
->nelts
-1;
5040 for (;i
<= last_index
; ++i
)
5041 sal
->sals
[i
-1] = sal
->sals
[i
];
5046 /* If appropriate, obtains all sals that correspond
5047 to the same file and line as SAL. This is done
5048 only if SAL does not have explicit PC and has
5049 line and file information. If we got just a single
5050 expanded sal, return the original.
5052 Otherwise, if SAL.explicit_line is not set, filter out
5053 all sals for which the name of enclosing function
5054 is different from SAL. This makes sure that if we have
5055 breakpoint originally set in template instantiation, say
5056 foo<int>(), we won't expand SAL to locations at the same
5057 line in all existing instantiations of 'foo'.
5060 struct symtabs_and_lines
5061 expand_line_sal_maybe (struct symtab_and_line sal
)
5063 struct symtabs_and_lines expanded
;
5064 CORE_ADDR original_pc
= sal
.pc
;
5065 char *original_function
= NULL
;
5069 /* If we have explicit pc, don't expand.
5070 If we have no line number, we can't expand. */
5071 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5074 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5075 expanded
.sals
[0] = sal
;
5080 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5082 expanded
= expand_line_sal (sal
);
5083 if (expanded
.nelts
== 1)
5085 /* We had one sal, we got one sal. Without futher
5086 processing, just return the original sal. */
5087 xfree (expanded
.sals
);
5089 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5090 sal
.pc
= original_pc
;
5091 expanded
.sals
[0] = sal
;
5095 if (!sal
.explicit_line
)
5097 CORE_ADDR func_addr
, func_end
;
5098 for (i
= 0; i
< expanded
.nelts
; ++i
)
5100 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5101 char *this_function
;
5102 if (find_pc_partial_function (pc
, &this_function
,
5103 &func_addr
, &func_end
))
5105 if (this_function
&&
5106 strcmp (this_function
, original_function
) != 0)
5108 remove_sal (&expanded
, i
);
5111 else if (func_addr
== pc
)
5113 /* We're at beginning of a function, and should
5115 struct symbol
*sym
= find_pc_function (pc
);
5117 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5120 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5127 if (expanded
.nelts
<= 1)
5129 /* This is un ugly workaround. If we get zero
5130 expanded sals then something is really wrong.
5131 Fix that by returnign the original sal. */
5132 xfree (expanded
.sals
);
5134 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5135 sal
.pc
= original_pc
;
5136 expanded
.sals
[0] = sal
;
5143 for (i
= 0; i
< expanded
.nelts
; ++i
)
5144 if (expanded
.sals
[i
].pc
== original_pc
)
5155 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5156 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5157 value. COND_STRING, if not NULL, specified the condition to be
5158 used for all breakpoints. Essentially the only case where
5159 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5160 function. In that case, it's still not possible to specify
5161 separate conditions for different overloaded functions, so
5162 we take just a single condition string.
5164 NOTE: If the function succeeds, the caller is expected to cleanup
5165 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5166 array contents). If the function fails (error() is called), the
5167 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5168 COND and SALS arrays and each of those arrays contents. */
5171 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5173 enum bptype type
, enum bpdisp disposition
,
5174 int thread
, int ignore_count
, int from_tty
)
5177 for (i
= 0; i
< sals
.nelts
; ++i
)
5179 struct symtabs_and_lines expanded
=
5180 expand_line_sal_maybe (sals
.sals
[i
]);
5182 create_breakpoint (expanded
, addr_string
[i
],
5183 cond_string
, type
, disposition
,
5184 thread
, ignore_count
, from_tty
);
5188 /* Parse ARG which is assumed to be a SAL specification possibly
5189 followed by conditionals. On return, SALS contains an array of SAL
5190 addresses found. ADDR_STRING contains a vector of (canonical)
5191 address strings. ARG points to the end of the SAL. */
5194 parse_breakpoint_sals (char **address
,
5195 struct symtabs_and_lines
*sals
,
5196 char ***addr_string
,
5199 char *addr_start
= *address
;
5200 *addr_string
= NULL
;
5201 /* If no arg given, or if first arg is 'if ', use the default
5203 if ((*address
) == NULL
5204 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5206 if (default_breakpoint_valid
)
5208 struct symtab_and_line sal
;
5209 init_sal (&sal
); /* initialize to zeroes */
5210 sals
->sals
= (struct symtab_and_line
*)
5211 xmalloc (sizeof (struct symtab_and_line
));
5212 sal
.pc
= default_breakpoint_address
;
5213 sal
.line
= default_breakpoint_line
;
5214 sal
.symtab
= default_breakpoint_symtab
;
5215 sal
.section
= find_pc_overlay (sal
.pc
);
5216 sals
->sals
[0] = sal
;
5220 error (_("No default breakpoint address now."));
5224 /* Force almost all breakpoints to be in terms of the
5225 current_source_symtab (which is decode_line_1's default). This
5226 should produce the results we want almost all of the time while
5227 leaving default_breakpoint_* alone.
5228 ObjC: However, don't match an Objective-C method name which
5229 may have a '+' or '-' succeeded by a '[' */
5231 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5233 if (default_breakpoint_valid
5235 || ((strchr ("+-", (*address
)[0]) != NULL
)
5236 && ((*address
)[1] != '['))))
5237 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5238 default_breakpoint_line
, addr_string
,
5241 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5242 addr_string
, not_found_ptr
);
5244 /* For any SAL that didn't have a canonical string, fill one in. */
5245 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5246 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5247 if (addr_start
!= (*address
))
5250 for (i
= 0; i
< sals
->nelts
; i
++)
5252 /* Add the string if not present. */
5253 if ((*addr_string
)[i
] == NULL
)
5254 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5260 /* Convert each SAL into a real PC. Verify that the PC can be
5261 inserted as a breakpoint. If it can't throw an error. */
5264 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5268 for (i
= 0; i
< sals
->nelts
; i
++)
5269 resolve_sal_pc (&sals
->sals
[i
]);
5273 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5275 struct captured_parse_breakpoint_args
*args
= data
;
5277 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5278 args
->not_found_ptr
);
5281 /* Given TOK, a string specification of condition and thread, as
5282 accepted by the 'break' command, extract the condition
5283 string and thread number and set *COND_STRING and *THREAD.
5284 PC identifies the context at which the condition should be parsed.
5285 If no condition is found, *COND_STRING is set to NULL.
5286 If no thread is found, *THREAD is set to -1. */
5288 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5289 char **cond_string
, int *thread
)
5291 *cond_string
= NULL
;
5297 char *cond_start
= NULL
;
5298 char *cond_end
= NULL
;
5299 while (*tok
== ' ' || *tok
== '\t')
5304 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5307 toklen
= end_tok
- tok
;
5309 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5311 tok
= cond_start
= end_tok
+ 1;
5312 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5314 *cond_string
= savestring (cond_start
,
5315 cond_end
- cond_start
);
5317 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5323 *thread
= strtol (tok
, &tok
, 0);
5325 error (_("Junk after thread keyword."));
5326 if (!valid_thread_id (*thread
))
5327 error (_("Unknown thread %d."), *thread
);
5330 error (_("Junk at end of arguments."));
5334 /* Set a breakpoint. This function is shared between
5335 CLI and MI functions for setting a breakpoint.
5336 This function has two major modes of operations,
5337 selected by the PARSE_CONDITION_AND_THREAD parameter.
5338 If non-zero, the function will parse arg, extracting
5339 breakpoint location, address and thread. Otherwise,
5340 ARG is just the location of breakpoint, with condition
5341 and thread specified by the COND_STRING and THREAD
5345 break_command_really (char *arg
, char *cond_string
, int thread
,
5346 int parse_condition_and_thread
,
5347 int tempflag
, int hardwareflag
,
5349 enum auto_boolean pending_break_support
,
5352 struct gdb_exception e
;
5353 struct symtabs_and_lines sals
;
5354 struct symtab_and_line pending_sal
;
5357 char *addr_start
= arg
;
5359 struct cleanup
*old_chain
;
5360 struct cleanup
*breakpoint_chain
= NULL
;
5361 struct captured_parse_breakpoint_args parse_args
;
5370 parse_args
.arg_p
= &arg
;
5371 parse_args
.sals_p
= &sals
;
5372 parse_args
.addr_string_p
= &addr_string
;
5373 parse_args
.not_found_ptr
= ¬_found
;
5375 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5376 &parse_args
, RETURN_MASK_ALL
);
5378 /* If caller is interested in rc value from parse, set value. */
5382 throw_exception (e
);
5386 case NOT_FOUND_ERROR
:
5388 /* If pending breakpoint support is turned off, throw
5391 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5392 throw_exception (e
);
5394 exception_print (gdb_stderr
, e
);
5396 /* If pending breakpoint support is auto query and the user
5397 selects no, then simply return the error code. */
5398 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5399 !nquery ("Make breakpoint pending on future shared library load? "))
5402 /* At this point, either the user was queried about setting
5403 a pending breakpoint and selected yes, or pending
5404 breakpoint behavior is on and thus a pending breakpoint
5405 is defaulted on behalf of the user. */
5406 copy_arg
= xstrdup (addr_start
);
5407 addr_string
= ©_arg
;
5409 sals
.sals
= &pending_sal
;
5414 throw_exception (e
);
5421 /* Create a chain of things that always need to be cleaned up. */
5422 old_chain
= make_cleanup (null_cleanup
, 0);
5426 /* Make sure that all storage allocated to SALS gets freed. */
5427 make_cleanup (xfree
, sals
.sals
);
5429 /* Cleanup the addr_string array but not its contents. */
5430 make_cleanup (xfree
, addr_string
);
5433 /* ----------------------------- SNIP -----------------------------
5434 Anything added to the cleanup chain beyond this point is assumed
5435 to be part of a breakpoint. If the breakpoint create succeeds
5436 then the memory is not reclaimed. */
5437 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5439 /* Mark the contents of the addr_string for cleanup. These go on
5440 the breakpoint_chain and only occure if the breakpoint create
5442 for (i
= 0; i
< sals
.nelts
; i
++)
5444 if (addr_string
[i
] != NULL
)
5445 make_cleanup (xfree
, addr_string
[i
]);
5448 /* Resolve all line numbers to PC's and verify that the addresses
5449 are ok for the target. */
5451 breakpoint_sals_to_pc (&sals
, addr_start
);
5453 /* Verify that condition can be parsed, before setting any
5454 breakpoints. Allocate a separate condition expression for each
5458 if (parse_condition_and_thread
)
5460 /* Here we only parse 'arg' to separate condition
5461 from thread number, so parsing in context of first
5462 sal is OK. When setting the breakpoint we'll
5463 re-parse it in context of each sal. */
5466 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5468 make_cleanup (xfree
, cond_string
);
5472 /* Create a private copy of condition string. */
5475 cond_string
= xstrdup (cond_string
);
5476 make_cleanup (xfree
, cond_string
);
5479 create_breakpoints (sals
, addr_string
, cond_string
,
5480 hardwareflag
? bp_hardware_breakpoint
5482 tempflag
? disp_del
: disp_donttouch
,
5483 thread
, ignore_count
, from_tty
);
5487 struct symtab_and_line sal
= {0};
5488 struct breakpoint
*b
;
5490 make_cleanup (xfree
, copy_arg
);
5492 b
= set_raw_breakpoint_without_location (hardwareflag
5493 ? bp_hardware_breakpoint
5495 set_breakpoint_count (breakpoint_count
+ 1);
5496 b
->number
= breakpoint_count
;
5498 b
->addr_string
= addr_string
[0];
5499 b
->cond_string
= NULL
;
5500 b
->ignore_count
= ignore_count
;
5501 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5502 b
->condition_not_parsed
= 1;
5507 warning (_("Multiple breakpoints were set.\n"
5508 "Use the \"delete\" command to delete unwanted breakpoints."));
5509 /* That's it. Discard the cleanups for data inserted into the
5511 discard_cleanups (breakpoint_chain
);
5512 /* But cleanup everything else. */
5513 do_cleanups (old_chain
);
5516 /* Set a breakpoint.
5517 ARG is a string describing breakpoint address,
5518 condition, and thread.
5519 FLAG specifies if a breakpoint is hardware on,
5520 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5524 break_command_1 (char *arg
, int flag
, int from_tty
)
5526 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5527 int tempflag
= flag
& BP_TEMPFLAG
;
5529 break_command_really (arg
,
5530 NULL
, 0, 1 /* parse arg */,
5531 tempflag
, hardwareflag
,
5532 0 /* Ignore count */,
5533 pending_break_support
, from_tty
);
5538 set_breakpoint (char *address
, char *condition
,
5539 int hardwareflag
, int tempflag
,
5540 int thread
, int ignore_count
,
5543 break_command_really (address
, condition
, thread
,
5544 0 /* condition and thread are valid. */,
5545 tempflag
, hardwareflag
,
5548 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5552 /* Adjust SAL to the first instruction past the function prologue.
5553 The end of the prologue is determined using the line table from
5554 the debugging information.
5556 If SAL is already past the prologue, then do nothing. */
5559 skip_prologue_sal (struct symtab_and_line
*sal
)
5561 struct symbol
*sym
= find_pc_function (sal
->pc
);
5562 struct symtab_and_line start_sal
;
5567 start_sal
= find_function_start_sal (sym
, 1);
5568 if (sal
->pc
< start_sal
.pc
)
5572 /* Helper function for break_command_1 and disassemble_command. */
5575 resolve_sal_pc (struct symtab_and_line
*sal
)
5579 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5581 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5582 error (_("No line %d in file \"%s\"."),
5583 sal
->line
, sal
->symtab
->filename
);
5586 /* If this SAL corresponds to a breakpoint inserted using
5587 a line number, then skip the function prologue if necessary. */
5588 if (sal
->explicit_line
)
5589 skip_prologue_sal (sal
);
5592 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5594 struct blockvector
*bv
;
5598 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5601 sym
= block_function (b
);
5604 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5605 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5609 /* It really is worthwhile to have the section, so we'll just
5610 have to look harder. This case can be executed if we have
5611 line numbers but no functions (as can happen in assembly
5614 struct minimal_symbol
*msym
;
5616 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5618 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5625 break_command (char *arg
, int from_tty
)
5627 break_command_1 (arg
, 0, from_tty
);
5631 tbreak_command (char *arg
, int from_tty
)
5633 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5637 hbreak_command (char *arg
, int from_tty
)
5639 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5643 thbreak_command (char *arg
, int from_tty
)
5645 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5649 stop_command (char *arg
, int from_tty
)
5651 printf_filtered (_("Specify the type of breakpoint to set.\n\
5652 Usage: stop in <function | address>\n\
5653 stop at <line>\n"));
5657 stopin_command (char *arg
, int from_tty
)
5661 if (arg
== (char *) NULL
)
5663 else if (*arg
!= '*')
5668 /* look for a ':'. If this is a line number specification, then
5669 say it is bad, otherwise, it should be an address or
5670 function/method name */
5671 while (*argptr
&& !hasColon
)
5673 hasColon
= (*argptr
== ':');
5678 badInput
= (*argptr
!= ':'); /* Not a class::method */
5680 badInput
= isdigit (*arg
); /* a simple line number */
5684 printf_filtered (_("Usage: stop in <function | address>\n"));
5686 break_command_1 (arg
, 0, from_tty
);
5690 stopat_command (char *arg
, int from_tty
)
5694 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5701 /* look for a ':'. If there is a '::' then get out, otherwise
5702 it is probably a line number. */
5703 while (*argptr
&& !hasColon
)
5705 hasColon
= (*argptr
== ':');
5710 badInput
= (*argptr
== ':'); /* we have class::method */
5712 badInput
= !isdigit (*arg
); /* not a line number */
5716 printf_filtered (_("Usage: stop at <line>\n"));
5718 break_command_1 (arg
, 0, from_tty
);
5721 /* accessflag: hw_write: watch write,
5722 hw_read: watch read,
5723 hw_access: watch access (read or write) */
5725 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5727 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5728 struct symtab_and_line sal
;
5729 struct expression
*exp
;
5730 struct block
*exp_valid_block
;
5731 struct value
*val
, *mark
;
5732 struct frame_info
*frame
;
5733 struct frame_info
*prev_frame
= NULL
;
5734 char *exp_start
= NULL
;
5735 char *exp_end
= NULL
;
5736 char *tok
, *id_tok_start
, *end_tok
;
5738 char *cond_start
= NULL
;
5739 char *cond_end
= NULL
;
5740 struct expression
*cond
= NULL
;
5741 int i
, other_type_used
, target_resources_ok
= 0;
5742 enum bptype bp_type
;
5746 init_sal (&sal
); /* initialize to zeroes */
5748 /* Make sure that we actually have parameters to parse. */
5749 if (arg
!= NULL
&& arg
[0] != '\0')
5751 toklen
= strlen (arg
); /* Size of argument list. */
5753 /* Points tok to the end of the argument list. */
5754 tok
= arg
+ toklen
- 1;
5756 /* Go backwards in the parameters list. Skip the last parameter.
5757 If we're expecting a 'thread <thread_num>' parameter, this should
5758 be the thread identifier. */
5759 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5761 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5764 /* Points end_tok to the beginning of the last token. */
5765 id_tok_start
= tok
+ 1;
5767 /* Go backwards in the parameters list. Skip one more parameter.
5768 If we're expecting a 'thread <thread_num>' parameter, we should
5769 reach a "thread" token. */
5770 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5775 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5778 /* Move the pointer forward to skip the whitespace and
5779 calculate the length of the token. */
5781 toklen
= end_tok
- tok
;
5783 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5785 /* At this point we've found a "thread" token, which means
5786 the user is trying to set a watchpoint that triggers
5787 only in a specific thread. */
5790 /* Extract the thread ID from the next token. */
5791 thread
= strtol (id_tok_start
, &endp
, 0);
5793 /* Check if the user provided a valid numeric value for the
5795 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5796 error (_("Invalid thread ID specification %s."), id_tok_start
);
5798 /* Check if the thread actually exists. */
5799 if (!valid_thread_id (thread
))
5800 error (_("Unknown thread %d."), thread
);
5802 /* Truncate the string and get rid of the thread <thread_num>
5803 parameter before the parameter list is parsed by the
5804 evaluate_expression() function. */
5809 /* Parse the rest of the arguments. */
5810 innermost_block
= NULL
;
5812 exp
= parse_exp_1 (&arg
, 0, 0);
5814 exp_valid_block
= innermost_block
;
5815 mark
= value_mark ();
5816 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5818 release_value (val
);
5821 while (*tok
== ' ' || *tok
== '\t')
5825 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5828 toklen
= end_tok
- tok
;
5829 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5831 tok
= cond_start
= end_tok
+ 1;
5832 cond
= parse_exp_1 (&tok
, 0, 0);
5836 error (_("Junk at end of command."));
5838 if (accessflag
== hw_read
)
5839 bp_type
= bp_read_watchpoint
;
5840 else if (accessflag
== hw_access
)
5841 bp_type
= bp_access_watchpoint
;
5843 bp_type
= bp_hardware_watchpoint
;
5845 mem_cnt
= can_use_hardware_watchpoint (val
);
5846 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5847 error (_("Expression cannot be implemented with read/access watchpoint."));
5850 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5851 target_resources_ok
=
5852 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5854 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5855 error (_("Target does not support this type of hardware watchpoint."));
5857 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5858 error (_("Target can only support one kind of HW watchpoint at a time."));
5861 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5862 watchpoint could not be set. */
5863 if (!mem_cnt
|| target_resources_ok
<= 0)
5864 bp_type
= bp_watchpoint
;
5866 frame
= block_innermost_frame (exp_valid_block
);
5868 prev_frame
= get_prev_frame (frame
);
5872 /* If the expression is "local", then set up a "watchpoint scope"
5873 breakpoint at the point where we've left the scope of the watchpoint
5874 expression. Create the scope breakpoint before the watchpoint, so
5875 that we will encounter it first in bpstat_stop_status. */
5876 if (innermost_block
&& prev_frame
)
5878 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5879 bp_watchpoint_scope
);
5881 scope_breakpoint
->enable_state
= bp_enabled
;
5883 /* Automatically delete the breakpoint when it hits. */
5884 scope_breakpoint
->disposition
= disp_del
;
5886 /* Only break in the proper frame (help with recursion). */
5887 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5889 /* Set the address at which we will stop. */
5890 scope_breakpoint
->loc
->requested_address
5891 = get_frame_pc (prev_frame
);
5892 scope_breakpoint
->loc
->address
5893 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5894 scope_breakpoint
->type
);
5897 /* Now set up the breakpoint. */
5898 b
= set_raw_breakpoint (sal
, bp_type
);
5899 set_breakpoint_count (breakpoint_count
+ 1);
5900 b
->number
= breakpoint_count
;
5902 b
->disposition
= disp_donttouch
;
5904 b
->exp_valid_block
= exp_valid_block
;
5905 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5908 b
->loc
->cond
= cond
;
5910 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5915 b
->watchpoint_frame
= get_frame_id (frame
);
5917 b
->watchpoint_frame
= null_frame_id
;
5919 if (scope_breakpoint
!= NULL
)
5921 /* The scope breakpoint is related to the watchpoint. We will
5922 need to act on them together. */
5923 b
->related_breakpoint
= scope_breakpoint
;
5924 scope_breakpoint
->related_breakpoint
= b
;
5927 value_free_to_mark (mark
);
5931 /* Return count of locations need to be watched and can be handled
5932 in hardware. If the watchpoint can not be handled
5933 in hardware return zero. */
5936 can_use_hardware_watchpoint (struct value
*v
)
5938 int found_memory_cnt
= 0;
5939 struct value
*head
= v
;
5941 /* Did the user specifically forbid us to use hardware watchpoints? */
5942 if (!can_use_hw_watchpoints
)
5945 /* Make sure that the value of the expression depends only upon
5946 memory contents, and values computed from them within GDB. If we
5947 find any register references or function calls, we can't use a
5948 hardware watchpoint.
5950 The idea here is that evaluating an expression generates a series
5951 of values, one holding the value of every subexpression. (The
5952 expression a*b+c has five subexpressions: a, b, a*b, c, and
5953 a*b+c.) GDB's values hold almost enough information to establish
5954 the criteria given above --- they identify memory lvalues,
5955 register lvalues, computed values, etcetera. So we can evaluate
5956 the expression, and then scan the chain of values that leaves
5957 behind to decide whether we can detect any possible change to the
5958 expression's final value using only hardware watchpoints.
5960 However, I don't think that the values returned by inferior
5961 function calls are special in any way. So this function may not
5962 notice that an expression involving an inferior function call
5963 can't be watched with hardware watchpoints. FIXME. */
5964 for (; v
; v
= value_next (v
))
5966 if (VALUE_LVAL (v
) == lval_memory
)
5969 /* A lazy memory lvalue is one that GDB never needed to fetch;
5970 we either just used its address (e.g., `a' in `a.b') or
5971 we never needed it at all (e.g., `a' in `a,b'). */
5975 /* Ahh, memory we actually used! Check if we can cover
5976 it with hardware watchpoints. */
5977 struct type
*vtype
= check_typedef (value_type (v
));
5979 /* We only watch structs and arrays if user asked for it
5980 explicitly, never if they just happen to appear in a
5981 middle of some value chain. */
5983 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5984 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5986 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5987 int len
= TYPE_LENGTH (value_type (v
));
5989 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5996 else if (VALUE_LVAL (v
) != not_lval
5997 && deprecated_value_modifiable (v
) == 0)
5998 return 0; /* ??? What does this represent? */
5999 else if (VALUE_LVAL (v
) == lval_register
)
6000 return 0; /* cannot watch a register with a HW watchpoint */
6003 /* The expression itself looks suitable for using a hardware
6004 watchpoint, but give the target machine a chance to reject it. */
6005 return found_memory_cnt
;
6009 watch_command_wrapper (char *arg
, int from_tty
)
6011 watch_command (arg
, from_tty
);
6015 watch_command (char *arg
, int from_tty
)
6017 watch_command_1 (arg
, hw_write
, from_tty
);
6021 rwatch_command_wrapper (char *arg
, int from_tty
)
6023 rwatch_command (arg
, from_tty
);
6027 rwatch_command (char *arg
, int from_tty
)
6029 watch_command_1 (arg
, hw_read
, from_tty
);
6033 awatch_command_wrapper (char *arg
, int from_tty
)
6035 awatch_command (arg
, from_tty
);
6039 awatch_command (char *arg
, int from_tty
)
6041 watch_command_1 (arg
, hw_access
, from_tty
);
6045 /* Helper routines for the until_command routine in infcmd.c. Here
6046 because it uses the mechanisms of breakpoints. */
6048 /* This function is called by fetch_inferior_event via the
6049 cmd_continuation pointer, to complete the until command. It takes
6050 care of cleaning up the temporary breakpoints set up by the until
6053 until_break_command_continuation (struct continuation_arg
*arg
)
6055 struct cleanup
*cleanups
;
6057 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6058 do_exec_cleanups (cleanups
);
6062 until_break_command (char *arg
, int from_tty
, int anywhere
)
6064 struct symtabs_and_lines sals
;
6065 struct symtab_and_line sal
;
6066 struct frame_info
*frame
= get_selected_frame (NULL
);
6067 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6068 struct breakpoint
*breakpoint
;
6069 struct cleanup
*old_chain
;
6070 struct continuation_arg
*arg1
;
6073 clear_proceed_status ();
6075 /* Set a breakpoint where the user wants it and at return from
6078 if (default_breakpoint_valid
)
6079 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6080 default_breakpoint_line
, (char ***) NULL
, NULL
);
6082 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6083 0, (char ***) NULL
, NULL
);
6085 if (sals
.nelts
!= 1)
6086 error (_("Couldn't get information on specified line."));
6089 xfree (sals
.sals
); /* malloc'd, so freed */
6092 error (_("Junk at end of arguments."));
6094 resolve_sal_pc (&sal
);
6097 /* If the user told us to continue until a specified location,
6098 we don't specify a frame at which we need to stop. */
6099 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6101 /* Otherwise, specify the current frame, because we want to stop only
6102 at the very same frame. */
6103 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6106 if (!target_can_async_p ())
6107 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6109 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6111 /* If we are running asynchronously, and the target supports async
6112 execution, we are not waiting for the target to stop, in the call
6113 tp proceed, below. This means that we cannot delete the
6114 brekpoints until the target has actually stopped. The only place
6115 where we get a chance to do that is in fetch_inferior_event, so
6116 we must set things up for that. */
6118 if (target_can_async_p ())
6120 /* In this case the arg for the continuation is just the point
6121 in the exec_cleanups chain from where to start doing
6122 cleanups, because all the continuation does is the cleanups in
6123 the exec_cleanup_chain. */
6125 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6127 arg1
->data
.pointer
= old_chain
;
6129 add_continuation (until_break_command_continuation
, arg1
);
6132 /* Keep within the current frame, or in frames called by the current
6136 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6137 sal
.pc
= get_frame_pc (prev_frame
);
6138 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6140 if (!target_can_async_p ())
6141 make_cleanup_delete_breakpoint (breakpoint
);
6143 make_exec_cleanup_delete_breakpoint (breakpoint
);
6146 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6147 /* Do the cleanups now, anly if we are not running asynchronously,
6148 of if we are, but the target is still synchronous. */
6149 if (!target_can_async_p ())
6150 do_cleanups (old_chain
);
6154 ep_skip_leading_whitespace (char **s
)
6156 if ((s
== NULL
) || (*s
== NULL
))
6158 while (isspace (**s
))
6162 /* This function examines a string, and attempts to find a token
6163 that might be an event name in the leading characters. If a
6164 possible match is found, a pointer to the last character of
6165 the token is returned. Else, NULL is returned. */
6168 ep_find_event_name_end (char *arg
)
6171 char *event_name_end
= NULL
;
6173 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6177 /* We break out of the loop when we find a token delimiter.
6178 Basically, we're looking for alphanumerics and underscores;
6179 anything else delimites the token. */
6182 if (!isalnum (*s
) && (*s
!= '_'))
6188 return event_name_end
;
6192 /* This function attempts to parse an optional "if <cond>" clause
6193 from the arg string. If one is not found, it returns NULL.
6195 Else, it returns a pointer to the condition string. (It does not
6196 attempt to evaluate the string against a particular block.) And,
6197 it updates arg to point to the first character following the parsed
6198 if clause in the arg string. */
6201 ep_parse_optional_if_clause (char **arg
)
6205 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6208 /* Skip the "if" keyword. */
6211 /* Skip any extra leading whitespace, and record the start of the
6212 condition string. */
6213 ep_skip_leading_whitespace (arg
);
6216 /* Assume that the condition occupies the remainder of the arg string. */
6217 (*arg
) += strlen (cond_string
);
6222 /* This function attempts to parse an optional filename from the arg
6223 string. If one is not found, it returns NULL.
6225 Else, it returns a pointer to the parsed filename. (This function
6226 makes no attempt to verify that a file of that name exists, or is
6227 accessible.) And, it updates arg to point to the first character
6228 following the parsed filename in the arg string.
6230 Note that clients needing to preserve the returned filename for
6231 future access should copy it to their own buffers. */
6233 ep_parse_optional_filename (char **arg
)
6235 static char filename
[1024];
6240 if ((*arg_p
== '\0') || isspace (*arg_p
))
6258 /* Commands to deal with catching events, such as signals, exceptions,
6259 process start/exit, etc. */
6263 catch_fork
, catch_vfork
6268 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6271 char *cond_string
= NULL
;
6273 ep_skip_leading_whitespace (&arg
);
6275 /* The allowed syntax is:
6277 catch [v]fork if <cond>
6279 First, check if there's an if clause. */
6280 cond_string
= ep_parse_optional_if_clause (&arg
);
6282 if ((*arg
!= '\0') && !isspace (*arg
))
6283 error (_("Junk at end of arguments."));
6285 /* If this target supports it, create a fork or vfork catchpoint
6286 and enable reporting of such events. */
6290 create_fork_event_catchpoint (tempflag
, cond_string
);
6293 create_vfork_event_catchpoint (tempflag
, cond_string
);
6296 error (_("unsupported or unknown fork kind; cannot catch it"));
6302 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6304 char *cond_string
= NULL
;
6306 ep_skip_leading_whitespace (&arg
);
6308 /* The allowed syntax is:
6310 catch exec if <cond>
6312 First, check if there's an if clause. */
6313 cond_string
= ep_parse_optional_if_clause (&arg
);
6315 if ((*arg
!= '\0') && !isspace (*arg
))
6316 error (_("Junk at end of arguments."));
6318 /* If this target supports it, create an exec catchpoint
6319 and enable reporting of such events. */
6320 create_exec_event_catchpoint (tempflag
, cond_string
);
6324 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6326 char *dll_pathname
= NULL
;
6327 char *cond_string
= NULL
;
6329 ep_skip_leading_whitespace (&arg
);
6331 /* The allowed syntax is:
6333 catch load if <cond>
6334 catch load <filename>
6335 catch load <filename> if <cond>
6337 The user is not allowed to specify the <filename> after an
6340 We'll ignore the pathological case of a file named "if".
6342 First, check if there's an if clause. If so, then there
6343 cannot be a filename. */
6344 cond_string
= ep_parse_optional_if_clause (&arg
);
6346 /* If there was an if clause, then there cannot be a filename.
6347 Else, there might be a filename and an if clause. */
6348 if (cond_string
== NULL
)
6350 dll_pathname
= ep_parse_optional_filename (&arg
);
6351 ep_skip_leading_whitespace (&arg
);
6352 cond_string
= ep_parse_optional_if_clause (&arg
);
6355 if ((*arg
!= '\0') && !isspace (*arg
))
6356 error (_("Junk at end of arguments."));
6358 /* Create a load breakpoint that only triggers when a load of
6359 the specified dll (or any dll, if no pathname was specified)
6361 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6362 dll_pathname
, cond_string
);
6366 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6368 char *dll_pathname
= NULL
;
6369 char *cond_string
= NULL
;
6371 ep_skip_leading_whitespace (&arg
);
6373 /* The allowed syntax is:
6375 catch unload if <cond>
6376 catch unload <filename>
6377 catch unload <filename> if <cond>
6379 The user is not allowed to specify the <filename> after an
6382 We'll ignore the pathological case of a file named "if".
6384 First, check if there's an if clause. If so, then there
6385 cannot be a filename. */
6386 cond_string
= ep_parse_optional_if_clause (&arg
);
6388 /* If there was an if clause, then there cannot be a filename.
6389 Else, there might be a filename and an if clause. */
6390 if (cond_string
== NULL
)
6392 dll_pathname
= ep_parse_optional_filename (&arg
);
6393 ep_skip_leading_whitespace (&arg
);
6394 cond_string
= ep_parse_optional_if_clause (&arg
);
6397 if ((*arg
!= '\0') && !isspace (*arg
))
6398 error (_("Junk at end of arguments."));
6400 /* Create an unload breakpoint that only triggers when an unload of
6401 the specified dll (or any dll, if no pathname was specified)
6403 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6404 dll_pathname
, cond_string
);
6407 static enum print_stop_action
6408 print_exception_catchpoint (struct breakpoint
*b
)
6410 annotate_catchpoint (b
->number
);
6412 if (strstr (b
->addr_string
, "throw") != NULL
)
6413 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6416 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6419 return PRINT_SRC_AND_LOC
;
6423 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6428 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6431 *last_addr
= b
->loc
->address
;
6432 if (strstr (b
->addr_string
, "throw") != NULL
)
6433 ui_out_field_string (uiout
, "what", "exception throw");
6435 ui_out_field_string (uiout
, "what", "exception catch");
6439 print_mention_exception_catchpoint (struct breakpoint
*b
)
6441 if (strstr (b
->addr_string
, "throw") != NULL
)
6442 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6444 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6447 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6448 print_exception_catchpoint
,
6449 print_one_exception_catchpoint
,
6450 print_mention_exception_catchpoint
6454 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6455 enum exception_event_kind ex_event
, int from_tty
)
6457 char *trigger_func_name
, *nameptr
;
6458 struct symtabs_and_lines sals
;
6459 struct breakpoint
*b
;
6461 if (ex_event
== EX_EVENT_CATCH
)
6462 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6464 trigger_func_name
= xstrdup ("__cxa_throw");
6466 nameptr
= trigger_func_name
;
6467 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6468 if (sals
.nelts
== 0)
6470 xfree (trigger_func_name
);
6474 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6475 set_breakpoint_count (breakpoint_count
+ 1);
6476 b
->number
= breakpoint_count
;
6477 b
->cond_string
= (cond_string
== NULL
) ?
6478 NULL
: savestring (cond_string
, strlen (cond_string
));
6480 b
->addr_string
= trigger_func_name
;
6481 b
->enable_state
= bp_enabled
;
6482 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6483 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6490 /* Deal with "catch catch" and "catch throw" commands */
6493 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6494 int tempflag
, int from_tty
)
6496 char *cond_string
= NULL
;
6497 struct symtab_and_line
*sal
= NULL
;
6499 ep_skip_leading_whitespace (&arg
);
6501 cond_string
= ep_parse_optional_if_clause (&arg
);
6503 if ((*arg
!= '\0') && !isspace (*arg
))
6504 error (_("Junk at end of arguments."));
6506 if ((ex_event
!= EX_EVENT_THROW
) &&
6507 (ex_event
!= EX_EVENT_CATCH
))
6508 error (_("Unsupported or unknown exception event; cannot catch it"));
6510 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6513 warning (_("Unsupported with this platform/compiler combination."));
6516 /* Create a breakpoint struct for Ada exception catchpoints. */
6519 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6523 struct expression
*cond
,
6524 struct breakpoint_ops
*ops
,
6528 struct breakpoint
*b
;
6532 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6533 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6534 version for exception catchpoints, because two catchpoints
6535 used for different exception names will use the same address.
6536 In this case, a "breakpoint ... also set at..." warning is
6537 unproductive. Besides. the warning phrasing is also a bit
6538 inapropriate, we should use the word catchpoint, and tell
6539 the user what type of catchpoint it is. The above is good
6540 enough for now, though. */
6543 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6544 set_breakpoint_count (breakpoint_count
+ 1);
6546 b
->enable_state
= bp_enabled
;
6547 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6548 b
->number
= breakpoint_count
;
6549 b
->ignore_count
= 0;
6550 b
->loc
->cond
= cond
;
6551 b
->addr_string
= addr_string
;
6552 b
->language
= language_ada
;
6553 b
->cond_string
= cond_string
;
6554 b
->exp_string
= exp_string
;
6561 /* Implement the "catch exception" command. */
6564 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6566 struct symtab_and_line sal
;
6568 char *addr_string
= NULL
;
6569 char *exp_string
= NULL
;
6570 char *cond_string
= NULL
;
6571 struct expression
*cond
= NULL
;
6572 struct breakpoint_ops
*ops
= NULL
;
6574 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6575 &cond_string
, &cond
, &ops
);
6576 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6577 cond_string
, cond
, ops
, tempflag
,
6581 /* Implement the "catch assert" command. */
6584 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6586 struct symtab_and_line sal
;
6587 char *addr_string
= NULL
;
6588 struct breakpoint_ops
*ops
= NULL
;
6590 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6591 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6592 tempflag
, from_tty
);
6596 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6599 /* The first argument may be an event name, such as "start" or "load".
6600 If so, then handle it as such. If it doesn't match an event name,
6601 then attempt to interpret it as an exception name. (This latter is
6602 the v4.16-and-earlier GDB meaning of the "catch" command.)
6604 First, try to find the bounds of what might be an event name. */
6605 char *arg1_start
= arg
;
6609 if (arg1_start
== NULL
)
6611 /* Old behaviour was to use pre-v-4.16 syntax */
6612 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6614 /* Now, this is not allowed */
6615 error (_("Catch requires an event name."));
6618 arg1_end
= ep_find_event_name_end (arg1_start
);
6619 if (arg1_end
== NULL
)
6620 error (_("catch requires an event"));
6621 arg1_length
= arg1_end
+ 1 - arg1_start
;
6623 /* Try to match what we found against known event names. */
6624 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6626 error (_("Catch of signal not yet implemented"));
6628 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6630 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6631 tempflag
, from_tty
);
6633 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6635 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6636 tempflag
, from_tty
);
6638 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6640 error (_("Catch of thread_start not yet implemented"));
6642 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6644 error (_("Catch of thread_exit not yet implemented"));
6646 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6648 error (_("Catch of thread_join not yet implemented"));
6650 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6652 error (_("Catch of start not yet implemented"));
6654 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6656 error (_("Catch of exit not yet implemented"));
6658 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6660 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6662 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6664 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6666 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6668 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6670 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6672 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6674 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6676 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6678 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6680 error (_("Catch of stop not yet implemented"));
6682 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6684 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6687 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6689 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6692 /* This doesn't appear to be an event name */
6696 /* Pre-v.4.16 behaviour was to treat the argument
6697 as the name of an exception */
6698 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6699 /* Now this is not allowed */
6700 error (_("Unknown event kind specified for catch"));
6706 catch_command (char *arg
, int from_tty
)
6708 catch_command_1 (arg
, 0, from_tty
);
6713 tcatch_command (char *arg
, int from_tty
)
6715 catch_command_1 (arg
, 1, from_tty
);
6718 /* Delete breakpoints by address or line. */
6721 clear_command (char *arg
, int from_tty
)
6723 struct breakpoint
*b
;
6724 VEC(breakpoint_p
) *found
= 0;
6727 struct symtabs_and_lines sals
;
6728 struct symtab_and_line sal
;
6733 sals
= decode_line_spec (arg
, 1);
6738 sals
.sals
= (struct symtab_and_line
*)
6739 xmalloc (sizeof (struct symtab_and_line
));
6740 make_cleanup (xfree
, sals
.sals
);
6741 init_sal (&sal
); /* initialize to zeroes */
6742 sal
.line
= default_breakpoint_line
;
6743 sal
.symtab
= default_breakpoint_symtab
;
6744 sal
.pc
= default_breakpoint_address
;
6745 if (sal
.symtab
== 0)
6746 error (_("No source file specified."));
6754 /* We don't call resolve_sal_pc here. That's not
6755 as bad as it seems, because all existing breakpoints
6756 typically have both file/line and pc set. So, if
6757 clear is given file/line, we can match this to existing
6758 breakpoint without obtaining pc at all.
6760 We only support clearing given the address explicitly
6761 present in breakpoint table. Say, we've set breakpoint
6762 at file:line. There were several PC values for that file:line,
6763 due to optimization, all in one block.
6764 We've picked one PC value. If "clear" is issued with another
6765 PC corresponding to the same file:line, the breakpoint won't
6766 be cleared. We probably can still clear the breakpoint, but
6767 since the other PC value is never presented to user, user
6768 can only find it by guessing, and it does not seem important
6771 /* For each line spec given, delete bps which correspond
6772 to it. Do it in two passes, solely to preserve the current
6773 behavior that from_tty is forced true if we delete more than
6777 for (i
= 0; i
< sals
.nelts
; i
++)
6779 /* If exact pc given, clear bpts at that pc.
6780 If line given (pc == 0), clear all bpts on specified line.
6781 If defaulting, clear all bpts on default line
6784 defaulting sal.pc != 0 tests to do
6789 1 0 <can't happen> */
6793 /* Find all matching breakpoints and add them to
6798 /* Are we going to delete b? */
6799 if (b
->type
!= bp_none
6800 && b
->type
!= bp_watchpoint
6801 && b
->type
!= bp_hardware_watchpoint
6802 && b
->type
!= bp_read_watchpoint
6803 && b
->type
!= bp_access_watchpoint
)
6805 struct bp_location
*loc
= b
->loc
;
6806 for (; loc
; loc
= loc
->next
)
6808 int pc_match
= sal
.pc
6809 && (loc
->address
== sal
.pc
)
6810 && (!section_is_overlay (loc
->section
)
6811 || loc
->section
== sal
.section
);
6812 int line_match
= ((default_match
|| (0 == sal
.pc
))
6813 && b
->source_file
!= NULL
6814 && sal
.symtab
!= NULL
6815 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6816 && b
->line_number
== sal
.line
);
6817 if (pc_match
|| line_match
)
6826 VEC_safe_push(breakpoint_p
, found
, b
);
6829 /* Now go thru the 'found' chain and delete them. */
6830 if (VEC_empty(breakpoint_p
, found
))
6833 error (_("No breakpoint at %s."), arg
);
6835 error (_("No breakpoint at this line."));
6838 if (VEC_length(breakpoint_p
, found
) > 1)
6839 from_tty
= 1; /* Always report if deleted more than one */
6842 if (VEC_length(breakpoint_p
, found
) == 1)
6843 printf_unfiltered (_("Deleted breakpoint "));
6845 printf_unfiltered (_("Deleted breakpoints "));
6847 breakpoints_changed ();
6849 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6852 printf_unfiltered ("%d ", b
->number
);
6853 delete_breakpoint (b
);
6856 putchar_unfiltered ('\n');
6859 /* Delete breakpoint in BS if they are `delete' breakpoints and
6860 all breakpoints that are marked for deletion, whether hit or not.
6861 This is called after any breakpoint is hit, or after errors. */
6864 breakpoint_auto_delete (bpstat bs
)
6866 struct breakpoint
*b
, *temp
;
6868 for (; bs
; bs
= bs
->next
)
6869 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6871 delete_breakpoint (bs
->breakpoint_at
->owner
);
6873 ALL_BREAKPOINTS_SAFE (b
, temp
)
6875 if (b
->disposition
== disp_del_at_next_stop
)
6876 delete_breakpoint (b
);
6880 /* Remove locations of breakpoint BPT from
6881 the global list of breakpoint locations. */
6884 unlink_locations_from_global_list (struct breakpoint
*bpt
)
6886 /* This code assumes that the locations
6887 of a breakpoint are found in the global list
6888 in the same order, but not necessary adjacent. */
6889 struct bp_location
**tmp
= &bp_location_chain
;
6890 struct bp_location
*here
= bpt
->loc
;
6895 for (; *tmp
&& here
;)
6899 *tmp
= here
->global_next
;
6904 tmp
= &((*tmp
)->global_next
);
6909 /* Delete a breakpoint and clean up all traces of it in the data
6913 delete_breakpoint (struct breakpoint
*bpt
)
6915 struct breakpoint
*b
;
6917 struct bp_location
*loc
;
6919 gdb_assert (bpt
!= NULL
);
6921 /* Has this bp already been deleted? This can happen because multiple
6922 lists can hold pointers to bp's. bpstat lists are especial culprits.
6924 One example of this happening is a watchpoint's scope bp. When the
6925 scope bp triggers, we notice that the watchpoint is out of scope, and
6926 delete it. We also delete its scope bp. But the scope bp is marked
6927 "auto-deleting", and is already on a bpstat. That bpstat is then
6928 checked for auto-deleting bp's, which are deleted.
6930 A real solution to this problem might involve reference counts in bp's,
6931 and/or giving them pointers back to their referencing bpstat's, and
6932 teaching delete_breakpoint to only free a bp's storage when no more
6933 references were extent. A cheaper bandaid was chosen. */
6934 if (bpt
->type
== bp_none
)
6937 if (deprecated_delete_breakpoint_hook
)
6938 deprecated_delete_breakpoint_hook (bpt
);
6939 breakpoint_delete_event (bpt
->number
);
6941 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6944 remove_breakpoint (loc
, mark_inserted
);
6949 if (loc
->function_name
)
6950 xfree (loc
->function_name
);
6953 if (breakpoint_chain
== bpt
)
6954 breakpoint_chain
= bpt
->next
;
6959 b
->next
= bpt
->next
;
6963 unlink_locations_from_global_list (bpt
);
6965 check_duplicates (bpt
);
6967 if (bpt
->type
!= bp_hardware_watchpoint
6968 && bpt
->type
!= bp_read_watchpoint
6969 && bpt
->type
!= bp_access_watchpoint
6970 && bpt
->type
!= bp_catch_fork
6971 && bpt
->type
!= bp_catch_vfork
6972 && bpt
->type
!= bp_catch_exec
)
6973 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6975 /* If this breakpoint location was inserted, and there is
6976 another breakpoint at the same address, we need to
6977 insert the other breakpoint. */
6980 struct bp_location
*loc2
;
6981 ALL_BP_LOCATIONS (loc2
)
6982 if (loc2
->address
== loc
->address
6983 && loc2
->section
== loc
->section
6985 && loc2
->owner
->enable_state
!= bp_disabled
6987 && !loc2
->shlib_disabled
6988 && loc2
->owner
->enable_state
!= bp_call_disabled
)
6992 /* We should never reach this point if there is a permanent
6993 breakpoint at the same address as the one being deleted.
6994 If there is a permanent breakpoint somewhere, it should
6995 always be the only one inserted. */
6996 if (loc2
->owner
->enable_state
== bp_permanent
)
6997 internal_error (__FILE__
, __LINE__
,
6998 _("another breakpoint was inserted on top of "
6999 "a permanent breakpoint"));
7001 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
7002 loc2
->target_info
.placed_address
= loc2
->address
;
7003 if (b
->type
== bp_hardware_breakpoint
)
7004 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
7006 val
= target_insert_breakpoint (&loc2
->target_info
);
7008 /* If there was an error in the insert, print a message, then stop execution. */
7011 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7012 make_cleanup_ui_file_delete (tmp_error_stream
);
7015 if (b
->type
== bp_hardware_breakpoint
)
7017 fprintf_unfiltered (tmp_error_stream
,
7018 "Cannot insert hardware breakpoint %d.\n"
7019 "You may have requested too many hardware breakpoints.\n",
7024 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7025 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7026 fputs_filtered (paddress (loc2
->address
),
7028 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7029 safe_strerror (val
));
7032 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7033 target_terminal_ours_for_output ();
7034 error_stream(tmp_error_stream
);
7042 free_command_lines (&bpt
->commands
);
7043 if (bpt
->cond_string
!= NULL
)
7044 xfree (bpt
->cond_string
);
7045 if (bpt
->addr_string
!= NULL
)
7046 xfree (bpt
->addr_string
);
7047 if (bpt
->exp
!= NULL
)
7049 if (bpt
->exp_string
!= NULL
)
7050 xfree (bpt
->exp_string
);
7051 if (bpt
->val
!= NULL
)
7052 value_free (bpt
->val
);
7053 if (bpt
->source_file
!= NULL
)
7054 xfree (bpt
->source_file
);
7055 if (bpt
->dll_pathname
!= NULL
)
7056 xfree (bpt
->dll_pathname
);
7057 if (bpt
->triggered_dll_pathname
!= NULL
)
7058 xfree (bpt
->triggered_dll_pathname
);
7059 if (bpt
->exec_pathname
!= NULL
)
7060 xfree (bpt
->exec_pathname
);
7062 /* Be sure no bpstat's are pointing at it after it's been freed. */
7063 /* FIXME, how can we find all bpstat's?
7064 We just check stop_bpstat for now. Note that we cannot just
7065 remove bpstats pointing at bpt from the stop_bpstat list
7066 entirely, as breakpoint commands are associated with the bpstat;
7067 if we remove it here, then the later call to
7068 bpstat_do_actions (&stop_bpstat);
7069 in event-top.c won't do anything, and temporary breakpoints
7070 with commands won't work. */
7071 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7072 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7074 bs
->breakpoint_at
= NULL
;
7076 /* bs->commands will be freed later. */
7078 /* On the chance that someone will soon try again to delete this same
7079 bp, we mark it as deleted before freeing its storage. */
7080 bpt
->type
= bp_none
;
7082 for (loc
= bpt
->loc
; loc
;)
7084 struct bp_location
*loc_next
= loc
->next
;
7092 do_delete_breakpoint_cleanup (void *b
)
7094 delete_breakpoint (b
);
7098 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7100 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7104 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7106 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7110 delete_command (char *arg
, int from_tty
)
7112 struct breakpoint
*b
, *temp
;
7118 int breaks_to_delete
= 0;
7120 /* Delete all breakpoints if no argument.
7121 Do not delete internal or call-dummy breakpoints, these
7122 have to be deleted with an explicit breakpoint number argument. */
7125 if (b
->type
!= bp_call_dummy
&&
7126 b
->type
!= bp_shlib_event
&&
7127 b
->type
!= bp_thread_event
&&
7128 b
->type
!= bp_overlay_event
&&
7131 breaks_to_delete
= 1;
7136 /* Ask user only if there are some breakpoints to delete. */
7138 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7140 ALL_BREAKPOINTS_SAFE (b
, temp
)
7142 if (b
->type
!= bp_call_dummy
&&
7143 b
->type
!= bp_shlib_event
&&
7144 b
->type
!= bp_thread_event
&&
7145 b
->type
!= bp_overlay_event
&&
7147 delete_breakpoint (b
);
7152 map_breakpoint_numbers (arg
, delete_breakpoint
);
7156 all_locations_are_pending (struct bp_location
*loc
)
7158 for (; loc
; loc
= loc
->next
)
7159 if (!loc
->shlib_disabled
)
7164 /* Subroutine of update_breakpoint_locations to simplify it.
7165 Return non-zero if multiple fns in list LOC have the same name.
7166 Null names are ignored. */
7169 ambiguous_names_p (struct bp_location
*loc
)
7171 struct bp_location
*l
;
7172 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7173 (int (*) (const void *, const void *)) streq
,
7174 NULL
, xcalloc
, xfree
);
7176 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7179 const char *name
= l
->function_name
;
7181 /* Allow for some names to be NULL, ignore them. */
7185 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7187 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7202 update_breakpoint_locations (struct breakpoint
*b
,
7203 struct symtabs_and_lines sals
)
7207 struct bp_location
*existing_locations
= b
->loc
;
7209 /* If there's no new locations, and all existing locations
7210 are pending, don't do anything. This optimizes
7211 the common case where all locations are in the same
7212 shared library, that was unloaded. We'd like to
7213 retain the location, so that when the library
7214 is loaded again, we don't loose the enabled/disabled
7215 status of the individual locations. */
7216 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7219 unlink_locations_from_global_list (b
);
7222 for (i
= 0; i
< sals
.nelts
; ++i
)
7224 struct bp_location
*new_loc
=
7225 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7227 /* Reparse conditions, they might contain references to the
7229 if (b
->cond_string
!= NULL
)
7231 struct gdb_exception e
;
7234 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7236 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7241 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7242 b
->number
, e
.message
);
7243 new_loc
->enabled
= 0;
7247 if (b
->source_file
!= NULL
)
7248 xfree (b
->source_file
);
7249 if (sals
.sals
[i
].symtab
== NULL
)
7250 b
->source_file
= NULL
;
7253 savestring (sals
.sals
[i
].symtab
->filename
,
7254 strlen (sals
.sals
[i
].symtab
->filename
));
7256 if (b
->line_number
== 0)
7257 b
->line_number
= sals
.sals
[i
].line
;
7260 /* If possible, carry over 'disable' status from existing breakpoints. */
7262 struct bp_location
*e
= existing_locations
;
7263 /* If there are multiple breakpoints with the same function name,
7264 e.g. for inline functions, comparing function names won't work.
7265 Instead compare pc addresses; this is just a heuristic as things
7266 may have moved, but in practice it gives the correct answer
7267 often enough until a better solution is found. */
7268 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7270 for (; e
; e
= e
->next
)
7272 if (!e
->enabled
&& e
->function_name
)
7274 struct bp_location
*l
= b
->loc
;
7275 if (have_ambiguous_names
)
7277 for (; l
; l
= l
->next
)
7278 if (e
->address
== l
->address
)
7286 for (; l
; l
= l
->next
)
7287 if (l
->function_name
7288 && strcmp (e
->function_name
, l
->function_name
) == 0)
7298 while (existing_locations
)
7300 struct bp_location
*next
= existing_locations
->next
;
7301 free_bp_location (existing_locations
);
7302 existing_locations
= next
;
7307 /* Reset a breakpoint given it's struct breakpoint * BINT.
7308 The value we return ends up being the return value from catch_errors.
7309 Unused in this case. */
7312 breakpoint_re_set_one (void *bint
)
7314 /* get past catch_errs */
7315 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7319 int *not_found_ptr
= ¬_found
;
7320 struct symtabs_and_lines sals
= {};
7321 struct symtabs_and_lines expanded
;
7323 enum enable_state save_enable
;
7324 struct gdb_exception e
;
7330 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7334 case bp_hardware_breakpoint
:
7336 case bp_catch_unload
:
7337 if (b
->addr_string
== NULL
)
7339 /* Anything without a string can't be re-set. */
7340 delete_breakpoint (b
);
7344 set_language (b
->language
);
7345 input_radix
= b
->input_radix
;
7347 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7349 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7354 int not_found_and_ok
= 0;
7355 /* For pending breakpoints, it's expected that parsing
7356 will fail until the right shared library is loaded.
7357 User has already told to create pending breakpoints and
7358 don't need extra messages. If breakpoint is in bp_shlib_disabled
7359 state, then user already saw the message about that breakpoint
7360 being disabled, and don't want to see more errors. */
7362 && (b
->condition_not_parsed
7363 || (b
->loc
&& b
->loc
->shlib_disabled
)
7364 || b
->enable_state
== bp_disabled
))
7365 not_found_and_ok
= 1;
7367 if (!not_found_and_ok
)
7369 /* We surely don't want to warn about the same breakpoint
7370 10 times. One solution, implemented here, is disable
7371 the breakpoint on error. Another solution would be to
7372 have separate 'warning emitted' flag. Since this
7373 happens only when a binary has changed, I don't know
7374 which approach is better. */
7375 b
->enable_state
= bp_disabled
;
7376 throw_exception (e
);
7383 gdb_assert (sals
.nelts
== 1);
7384 resolve_sal_pc (&sals
.sals
[0]);
7385 if (b
->condition_not_parsed
&& s
&& s
[0])
7387 char *cond_string
= 0;
7389 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7390 &cond_string
, &thread
);
7392 b
->cond_string
= cond_string
;
7394 b
->condition_not_parsed
= 0;
7396 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7397 update_breakpoint_locations (b
, expanded
);
7399 /* Now that this is re-enabled, check_duplicates
7401 check_duplicates (b
);
7407 case bp_hardware_watchpoint
:
7408 case bp_read_watchpoint
:
7409 case bp_access_watchpoint
:
7410 /* Watchpoint can be either on expression using entirely global variables,
7411 or it can be on local variables.
7413 Watchpoints of the first kind are never auto-deleted, and even persist
7414 across program restarts. Since they can use variables from shared
7415 libraries, we need to reparse expression as libraries are loaded
7418 Watchpoints on local variables can also change meaning as result
7419 of solib event. For example, if a watchpoint uses both a local and
7420 a global variables in expression, it's a local watchpoint, but
7421 unloading of a shared library will make the expression invalid.
7422 This is not a very common use case, but we still re-evaluate
7423 expression, to avoid surprises to the user.
7425 Note that for local watchpoints, we re-evaluate it only if
7426 watchpoints frame id is still valid. If it's not, it means
7427 the watchpoint is out of scope and will be deleted soon. In fact,
7428 I'm not sure we'll ever be called in this case.
7430 If a local watchpoint's frame id is still valid, then
7431 b->exp_valid_block is likewise valid, and we can safely use it.
7433 Don't do anything about disabled watchpoints, since they will
7434 be reevaluated again when enabled. */
7435 update_watchpoint (b
, 1 /* reparse */);
7437 /* We needn't really do anything to reset these, since the mask
7438 that requests them is unaffected by e.g., new libraries being
7441 case bp_catch_vfork
:
7446 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7448 /* Delete longjmp and overlay event breakpoints; they will be
7449 reset later by breakpoint_re_set. */
7451 case bp_longjmp_resume
:
7452 case bp_overlay_event
:
7453 delete_breakpoint (b
);
7456 /* This breakpoint is special, it's set up when the inferior
7457 starts and we really don't want to touch it. */
7458 case bp_shlib_event
:
7460 /* Like bp_shlib_event, this breakpoint type is special.
7461 Once it is set up, we do not want to touch it. */
7462 case bp_thread_event
:
7464 /* Keep temporary breakpoints, which can be encountered when we step
7465 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7466 Otherwise these should have been blown away via the cleanup chain
7467 or by breakpoint_init_inferior when we rerun the executable. */
7470 case bp_watchpoint_scope
:
7472 case bp_step_resume
:
7479 /* Re-set all breakpoints after symbols have been re-loaded. */
7481 breakpoint_re_set (void)
7483 struct breakpoint
*b
, *temp
;
7484 enum language save_language
;
7485 int save_input_radix
;
7487 save_language
= current_language
->la_language
;
7488 save_input_radix
= input_radix
;
7489 ALL_BREAKPOINTS_SAFE (b
, temp
)
7491 /* Format possible error msg */
7492 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7494 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7495 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7496 do_cleanups (cleanups
);
7498 set_language (save_language
);
7499 input_radix
= save_input_radix
;
7501 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7503 create_longjmp_breakpoint ("longjmp");
7504 create_longjmp_breakpoint ("_longjmp");
7505 create_longjmp_breakpoint ("siglongjmp");
7506 create_longjmp_breakpoint ("_siglongjmp");
7507 create_longjmp_breakpoint (NULL
);
7510 create_overlay_event_breakpoint ("_ovly_debug_event");
7513 /* Reset the thread number of this breakpoint:
7515 - If the breakpoint is for all threads, leave it as-is.
7516 - Else, reset it to the current thread for inferior_ptid. */
7518 breakpoint_re_set_thread (struct breakpoint
*b
)
7520 if (b
->thread
!= -1)
7522 if (in_thread_list (inferior_ptid
))
7523 b
->thread
= pid_to_thread_id (inferior_ptid
);
7527 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7528 If from_tty is nonzero, it prints a message to that effect,
7529 which ends with a period (no newline). */
7532 set_ignore_count (int bptnum
, int count
, int from_tty
)
7534 struct breakpoint
*b
;
7540 if (b
->number
== bptnum
)
7542 b
->ignore_count
= count
;
7546 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7548 else if (count
== 1)
7549 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7552 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7555 breakpoints_changed ();
7556 breakpoint_modify_event (b
->number
);
7560 error (_("No breakpoint number %d."), bptnum
);
7563 /* Clear the ignore counts of all breakpoints. */
7565 breakpoint_clear_ignore_counts (void)
7567 struct breakpoint
*b
;
7570 b
->ignore_count
= 0;
7573 /* Command to set ignore-count of breakpoint N to COUNT. */
7576 ignore_command (char *args
, int from_tty
)
7582 error_no_arg (_("a breakpoint number"));
7584 num
= get_number (&p
);
7586 error (_("bad breakpoint number: '%s'"), args
);
7588 error (_("Second argument (specified ignore-count) is missing."));
7590 set_ignore_count (num
,
7591 longest_to_int (value_as_long (parse_and_eval (p
))),
7594 printf_filtered ("\n");
7597 /* Call FUNCTION on each of the breakpoints
7598 whose numbers are given in ARGS. */
7601 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7606 struct breakpoint
*b
, *tmp
;
7610 error_no_arg (_("one or more breakpoint numbers"));
7617 num
= get_number_or_range (&p1
);
7620 warning (_("bad breakpoint number at or near '%s'"), p
);
7624 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7625 if (b
->number
== num
)
7627 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7630 if (related_breakpoint
)
7631 function (related_breakpoint
);
7635 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7641 static struct bp_location
*
7642 find_location_by_number (char *number
)
7644 char *dot
= strchr (number
, '.');
7648 struct breakpoint
*b
;
7649 struct bp_location
*loc
;
7654 bp_num
= get_number_or_range (&p1
);
7656 error (_("Bad breakpoint number '%s'"), number
);
7659 if (b
->number
== bp_num
)
7664 if (!b
|| b
->number
!= bp_num
)
7665 error (_("Bad breakpoint number '%s'"), number
);
7668 loc_num
= get_number_or_range (&p1
);
7670 error (_("Bad breakpoint location number '%s'"), number
);
7674 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7677 error (_("Bad breakpoint location number '%s'"), dot
+1);
7683 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7684 If from_tty is nonzero, it prints a message to that effect,
7685 which ends with a period (no newline). */
7688 disable_breakpoint (struct breakpoint
*bpt
)
7690 /* Never disable a watchpoint scope breakpoint; we want to
7691 hit them when we leave scope so we can delete both the
7692 watchpoint and its scope breakpoint at that time. */
7693 if (bpt
->type
== bp_watchpoint_scope
)
7696 /* You can't disable permanent breakpoints. */
7697 if (bpt
->enable_state
== bp_permanent
)
7700 bpt
->enable_state
= bp_disabled
;
7702 check_duplicates (bpt
);
7704 if (deprecated_modify_breakpoint_hook
)
7705 deprecated_modify_breakpoint_hook (bpt
);
7706 breakpoint_modify_event (bpt
->number
);
7710 disable_command (char *args
, int from_tty
)
7712 struct breakpoint
*bpt
;
7714 ALL_BREAKPOINTS (bpt
)
7718 warning (_("attempted to disable 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 disable_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
, disable_breakpoint
);
7748 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7750 int target_resources_ok
, other_type_used
;
7753 if (bpt
->type
== bp_hardware_breakpoint
)
7756 i
= hw_breakpoint_used_count ();
7757 target_resources_ok
=
7758 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7760 if (target_resources_ok
== 0)
7761 error (_("No hardware breakpoint support in the target."));
7762 else if (target_resources_ok
< 0)
7763 error (_("Hardware breakpoints used exceeds limit."));
7766 if (bpt
->type
== bp_watchpoint
||
7767 bpt
->type
== bp_hardware_watchpoint
||
7768 bpt
->type
== bp_read_watchpoint
||
7769 bpt
->type
== bp_access_watchpoint
)
7771 struct frame_id saved_frame_id
;
7773 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7774 if (bpt
->exp_valid_block
!= NULL
)
7776 struct frame_info
*fr
=
7777 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7780 printf_filtered (_("\
7781 Cannot enable watchpoint %d because the block in which its expression\n\
7782 is valid is not currently in scope.\n"), bpt
->number
);
7789 value_free (bpt
->val
);
7790 mark
= value_mark ();
7791 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7793 release_value (bpt
->val
);
7796 if (bpt
->type
== bp_hardware_watchpoint
||
7797 bpt
->type
== bp_read_watchpoint
||
7798 bpt
->type
== bp_access_watchpoint
)
7800 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7801 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7803 /* Hack around 'unused var' error for some targets here */
7804 (void) mem_cnt
, (void) i
;
7805 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7806 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7807 /* we can consider of type is bp_hardware_watchpoint, convert to
7808 bp_watchpoint in the following condition */
7809 if (target_resources_ok
< 0)
7811 printf_filtered (_("\
7812 Cannot enable watchpoint %d because target watch resources\n\
7813 have been allocated for other watchpoints.\n"), bpt
->number
);
7814 value_free_to_mark (mark
);
7819 select_frame (frame_find_by_id (saved_frame_id
));
7820 value_free_to_mark (mark
);
7823 if (bpt
->enable_state
!= bp_permanent
)
7824 bpt
->enable_state
= bp_enabled
;
7825 bpt
->disposition
= disposition
;
7826 check_duplicates (bpt
);
7827 breakpoints_changed ();
7829 if (deprecated_modify_breakpoint_hook
)
7830 deprecated_modify_breakpoint_hook (bpt
);
7831 breakpoint_modify_event (bpt
->number
);
7836 enable_breakpoint (struct breakpoint
*bpt
)
7838 do_enable_breakpoint (bpt
, bpt
->disposition
);
7841 /* The enable command enables the specified breakpoints (or all defined
7842 breakpoints) so they once again become (or continue to be) effective
7843 in stopping the inferior. */
7846 enable_command (char *args
, int from_tty
)
7848 struct breakpoint
*bpt
;
7850 ALL_BREAKPOINTS (bpt
)
7854 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7859 case bp_catch_unload
:
7861 case bp_catch_vfork
:
7863 case bp_hardware_breakpoint
:
7865 case bp_hardware_watchpoint
:
7866 case bp_read_watchpoint
:
7867 case bp_access_watchpoint
:
7868 enable_breakpoint (bpt
);
7872 else if (strchr (args
, '.'))
7874 struct bp_location
*loc
= find_location_by_number (args
);
7877 check_duplicates (loc
->owner
);
7880 map_breakpoint_numbers (args
, enable_breakpoint
);
7884 enable_once_breakpoint (struct breakpoint
*bpt
)
7886 do_enable_breakpoint (bpt
, disp_disable
);
7890 enable_once_command (char *args
, int from_tty
)
7892 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7896 enable_delete_breakpoint (struct breakpoint
*bpt
)
7898 do_enable_breakpoint (bpt
, disp_del
);
7902 enable_delete_command (char *args
, int from_tty
)
7904 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7908 set_breakpoint_cmd (char *args
, int from_tty
)
7913 show_breakpoint_cmd (char *args
, int from_tty
)
7917 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7919 struct symtabs_and_lines
7920 decode_line_spec_1 (char *string
, int funfirstline
)
7922 struct symtabs_and_lines sals
;
7924 error (_("Empty line specification."));
7925 if (default_breakpoint_valid
)
7926 sals
= decode_line_1 (&string
, funfirstline
,
7927 default_breakpoint_symtab
,
7928 default_breakpoint_line
,
7929 (char ***) NULL
, NULL
);
7931 sals
= decode_line_1 (&string
, funfirstline
,
7932 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7934 error (_("Junk at end of line specification: %s"), string
);
7938 /* Create and insert a raw software breakpoint at PC. Return an
7939 identifier, which should be used to remove the breakpoint later.
7940 In general, places which call this should be using something on the
7941 breakpoint chain instead; this function should be eliminated
7945 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7947 struct bp_target_info
*bp_tgt
;
7949 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7950 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7952 bp_tgt
->placed_address
= pc
;
7953 if (target_insert_breakpoint (bp_tgt
) != 0)
7955 /* Could not insert the breakpoint. */
7963 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7966 deprecated_remove_raw_breakpoint (void *bp
)
7968 struct bp_target_info
*bp_tgt
= bp
;
7971 ret
= target_remove_breakpoint (bp_tgt
);
7977 /* One (or perhaps two) breakpoints used for software single stepping. */
7979 static void *single_step_breakpoints
[2];
7981 /* Create and insert a breakpoint for software single step. */
7984 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7988 if (single_step_breakpoints
[0] == NULL
)
7989 bpt_p
= &single_step_breakpoints
[0];
7992 gdb_assert (single_step_breakpoints
[1] == NULL
);
7993 bpt_p
= &single_step_breakpoints
[1];
7996 /* NOTE drow/2006-04-11: A future improvement to this function would be
7997 to only create the breakpoints once, and actually put them on the
7998 breakpoint chain. That would let us use set_raw_breakpoint. We could
7999 adjust the addresses each time they were needed. Doing this requires
8000 corresponding changes elsewhere where single step breakpoints are
8001 handled, however. So, for now, we use this. */
8003 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8005 error (_("Could not insert single-step breakpoint at 0x%s"),
8006 paddr_nz (next_pc
));
8009 /* Remove and delete any breakpoints used for software single step. */
8012 remove_single_step_breakpoints (void)
8014 gdb_assert (single_step_breakpoints
[0] != NULL
);
8016 /* See insert_single_step_breakpoint for more about this deprecated
8018 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8019 single_step_breakpoints
[0] = NULL
;
8021 if (single_step_breakpoints
[1] != NULL
)
8023 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8024 single_step_breakpoints
[1] = NULL
;
8028 /* Check whether a software single-step breakpoint is inserted at PC. */
8031 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8035 for (i
= 0; i
< 2; i
++)
8037 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8038 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8046 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8047 It is defined as a macro to prevent duplication.
8048 COMMAND should be a string constant containing the name of the command. */
8049 #define BREAK_ARGS_HELP(command) \
8050 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8051 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8052 If a line number is specified, break at start of code for that line.\n\
8053 If a function is specified, break at start of code for that function.\n\
8054 If an address is specified, break at that exact address.\n\
8055 With no LOCATION, uses current execution address of selected stack frame.\n\
8056 This is useful for breaking on return to a stack frame.\n\
8058 THREADNUM is the number from \"info threads\".\n\
8059 CONDITION is a boolean expression.\n\
8061 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8063 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8066 _initialize_breakpoint (void)
8068 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8069 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8070 struct cmd_list_element
*c
;
8072 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8074 breakpoint_chain
= 0;
8075 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8076 before a breakpoint is set. */
8077 breakpoint_count
= 0;
8079 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8080 Set ignore-count of breakpoint number N to COUNT.\n\
8081 Usage is `ignore N COUNT'."));
8083 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8085 add_com ("commands", class_breakpoint
, commands_command
, _("\
8086 Set commands to be executed when a breakpoint is hit.\n\
8087 Give breakpoint number as argument after \"commands\".\n\
8088 With no argument, the targeted breakpoint is the last one set.\n\
8089 The commands themselves follow starting on the next line.\n\
8090 Type a line containing \"end\" to indicate the end of them.\n\
8091 Give \"silent\" as the first line to make the breakpoint silent;\n\
8092 then no output is printed when it is hit, except what the commands print."));
8094 add_com ("condition", class_breakpoint
, condition_command
, _("\
8095 Specify breakpoint number N to break only if COND is true.\n\
8096 Usage is `condition N COND', where N is an integer and COND is an\n\
8097 expression to be evaluated whenever breakpoint N is reached."));
8099 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8100 Set a temporary breakpoint.\n\
8101 Like \"break\" except the breakpoint is only temporary,\n\
8102 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8103 by using \"enable delete\" on the breakpoint number.\n\
8105 BREAK_ARGS_HELP ("tbreak")));
8106 set_cmd_completer (c
, location_completer
);
8108 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8109 Set a hardware assisted breakpoint.\n\
8110 Like \"break\" except the breakpoint requires hardware support,\n\
8111 some target hardware may not have this support.\n\
8113 BREAK_ARGS_HELP ("hbreak")));
8114 set_cmd_completer (c
, location_completer
);
8116 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8117 Set a temporary hardware assisted breakpoint.\n\
8118 Like \"hbreak\" except the breakpoint is only temporary,\n\
8119 so it will be deleted when hit.\n\
8121 BREAK_ARGS_HELP ("thbreak")));
8122 set_cmd_completer (c
, location_completer
);
8124 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8125 Enable some breakpoints.\n\
8126 Give breakpoint numbers (separated by spaces) as arguments.\n\
8127 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8128 This is used to cancel the effect of the \"disable\" command.\n\
8129 With a subcommand you can enable temporarily."),
8130 &enablelist
, "enable ", 1, &cmdlist
);
8132 add_com ("ab", class_breakpoint
, enable_command
, _("\
8133 Enable some breakpoints.\n\
8134 Give breakpoint numbers (separated by spaces) as arguments.\n\
8135 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8136 This is used to cancel the effect of the \"disable\" command.\n\
8137 With a subcommand you can enable temporarily."));
8139 add_com_alias ("en", "enable", class_breakpoint
, 1);
8141 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8142 Enable some breakpoints.\n\
8143 Give breakpoint numbers (separated by spaces) as arguments.\n\
8144 This is used to cancel the effect of the \"disable\" command.\n\
8145 May be abbreviated to simply \"enable\".\n"),
8146 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8148 add_cmd ("once", no_class
, enable_once_command
, _("\
8149 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8150 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8153 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8154 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8155 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8158 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8159 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8160 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8163 add_cmd ("once", no_class
, enable_once_command
, _("\
8164 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8165 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8168 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8169 Disable some breakpoints.\n\
8170 Arguments are breakpoint numbers with spaces in between.\n\
8171 To disable all breakpoints, give no argument.\n\
8172 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8173 &disablelist
, "disable ", 1, &cmdlist
);
8174 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8175 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8177 add_com ("sb", class_breakpoint
, disable_command
, _("\
8178 Disable some breakpoints.\n\
8179 Arguments are breakpoint numbers with spaces in between.\n\
8180 To disable all breakpoints, give no argument.\n\
8181 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8183 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8184 Disable some breakpoints.\n\
8185 Arguments are breakpoint numbers with spaces in between.\n\
8186 To disable all breakpoints, give no argument.\n\
8187 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8188 This command may be abbreviated \"disable\"."),
8191 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8192 Delete some breakpoints or auto-display expressions.\n\
8193 Arguments are breakpoint numbers with spaces in between.\n\
8194 To delete all breakpoints, give no argument.\n\
8196 Also a prefix command for deletion of other GDB objects.\n\
8197 The \"unset\" command is also an alias for \"delete\"."),
8198 &deletelist
, "delete ", 1, &cmdlist
);
8199 add_com_alias ("d", "delete", class_breakpoint
, 1);
8200 add_com_alias ("del", "delete", class_breakpoint
, 1);
8202 add_com ("db", class_breakpoint
, delete_command
, _("\
8203 Delete some breakpoints.\n\
8204 Arguments are breakpoint numbers with spaces in between.\n\
8205 To delete all breakpoints, give no argument.\n"));
8207 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8208 Delete some breakpoints or auto-display expressions.\n\
8209 Arguments are breakpoint numbers with spaces in between.\n\
8210 To delete all breakpoints, give no argument.\n\
8211 This command may be abbreviated \"delete\"."),
8214 add_com ("clear", class_breakpoint
, clear_command
, _("\
8215 Clear breakpoint at specified line or function.\n\
8216 Argument may be line number, function name, or \"*\" and an address.\n\
8217 If line number is specified, all breakpoints in that line are cleared.\n\
8218 If function is specified, breakpoints at beginning of function are cleared.\n\
8219 If an address is specified, breakpoints at that address are cleared.\n\
8221 With no argument, clears all breakpoints in the line that the selected frame\n\
8224 See also the \"delete\" command which clears breakpoints by number."));
8226 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8227 Set breakpoint at specified line or function.\n"
8228 BREAK_ARGS_HELP ("break")));
8229 set_cmd_completer (c
, location_completer
);
8231 add_com_alias ("b", "break", class_run
, 1);
8232 add_com_alias ("br", "break", class_run
, 1);
8233 add_com_alias ("bre", "break", class_run
, 1);
8234 add_com_alias ("brea", "break", class_run
, 1);
8238 add_com_alias ("ba", "break", class_breakpoint
, 1);
8239 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8244 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8245 Break in function/address or break at a line in the current file."),
8246 &stoplist
, "stop ", 1, &cmdlist
);
8247 add_cmd ("in", class_breakpoint
, stopin_command
,
8248 _("Break in function or address."), &stoplist
);
8249 add_cmd ("at", class_breakpoint
, stopat_command
,
8250 _("Break at a line in the current file."), &stoplist
);
8251 add_com ("status", class_info
, breakpoints_info
, _("\
8252 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8253 The \"Type\" column indicates one of:\n\
8254 \tbreakpoint - normal breakpoint\n\
8255 \twatchpoint - watchpoint\n\
8256 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8257 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8258 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8259 address and file/line number respectively.\n\
8261 Convenience variable \"$_\" and default examine address for \"x\"\n\
8262 are set to the address of the last breakpoint listed unless the command\n\
8263 is prefixed with \"server \".\n\n\
8264 Convenience variable \"$bpnum\" contains the number of the last\n\
8268 add_info ("breakpoints", breakpoints_info
, _("\
8269 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8270 The \"Type\" column indicates one of:\n\
8271 \tbreakpoint - normal breakpoint\n\
8272 \twatchpoint - watchpoint\n\
8273 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8274 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8275 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8276 address and file/line number respectively.\n\
8278 Convenience variable \"$_\" and default examine address for \"x\"\n\
8279 are set to the address of the last breakpoint listed unless the command\n\
8280 is prefixed with \"server \".\n\n\
8281 Convenience variable \"$bpnum\" contains the number of the last\n\
8285 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8286 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8287 The \"Type\" column indicates one of:\n\
8288 \tbreakpoint - normal breakpoint\n\
8289 \twatchpoint - watchpoint\n\
8290 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8291 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8292 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8293 address and file/line number respectively.\n\
8295 Convenience variable \"$_\" and default examine address for \"x\"\n\
8296 are set to the address of the last breakpoint listed unless the command\n\
8297 is prefixed with \"server \".\n\n\
8298 Convenience variable \"$bpnum\" contains the number of the last\n\
8301 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8302 Status of all breakpoints, or breakpoint number NUMBER.\n\
8303 The \"Type\" column indicates one of:\n\
8304 \tbreakpoint - normal breakpoint\n\
8305 \twatchpoint - watchpoint\n\
8306 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8307 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8308 \tuntil - internal breakpoint used by the \"until\" command\n\
8309 \tfinish - internal breakpoint used by the \"finish\" command\n\
8310 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8311 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8312 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8313 address and file/line number respectively.\n\
8315 Convenience variable \"$_\" and default examine address for \"x\"\n\
8316 are set to the address of the last breakpoint listed unless the command\n\
8317 is prefixed with \"server \".\n\n\
8318 Convenience variable \"$bpnum\" contains the number of the last\n\
8320 &maintenanceinfolist
);
8322 add_com ("catch", class_breakpoint
, catch_command
, _("\
8323 Set catchpoints to catch events.\n\
8324 Raised signals may be caught:\n\
8325 \tcatch signal - all signals\n\
8326 \tcatch signal <signame> - a particular signal\n\
8327 Raised exceptions may be caught:\n\
8328 \tcatch throw - all exceptions, when thrown\n\
8329 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8330 \tcatch catch - all exceptions, when caught\n\
8331 \tcatch catch <exceptname> - a particular exception, when caught\n\
8332 Thread or process events may be caught:\n\
8333 \tcatch thread_start - any threads, just after creation\n\
8334 \tcatch thread_exit - any threads, just before expiration\n\
8335 \tcatch thread_join - any threads, just after joins\n\
8336 Process events may be caught:\n\
8337 \tcatch start - any processes, just after creation\n\
8338 \tcatch exit - any processes, just before expiration\n\
8339 \tcatch fork - calls to fork()\n\
8340 \tcatch vfork - calls to vfork()\n\
8341 \tcatch exec - calls to exec()\n\
8342 Dynamically-linked library events may be caught:\n\
8343 \tcatch load - loads of any library\n\
8344 \tcatch load <libname> - loads of a particular library\n\
8345 \tcatch unload - unloads of any library\n\
8346 \tcatch unload <libname> - unloads of a particular library\n\
8347 The act of your program's execution stopping may also be caught:\n\
8349 C++ exceptions may be caught:\n\
8350 \tcatch throw - all exceptions, when thrown\n\
8351 \tcatch catch - all exceptions, when caught\n\
8352 Ada exceptions may be caught:\n\
8353 \tcatch exception - all exceptions, when raised\n\
8354 \tcatch exception <name> - a particular exception, when raised\n\
8355 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8356 \tcatch assert - all failed assertions, when raised\n\
8358 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8359 after a fork or vfork is caught.\n\n\
8360 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8362 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8363 Set temporary catchpoints to catch events.\n\
8364 Args like \"catch\" command.\n\
8365 Like \"catch\" except the catchpoint is only temporary,\n\
8366 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8367 by using \"enable delete\" on the catchpoint number."));
8369 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8370 Set a watchpoint for an expression.\n\
8371 A watchpoint stops execution of your program whenever the value of\n\
8372 an expression changes."));
8373 set_cmd_completer (c
, location_completer
);
8375 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8376 Set a read watchpoint for an expression.\n\
8377 A watchpoint stops execution of your program whenever the value of\n\
8378 an expression is read."));
8379 set_cmd_completer (c
, location_completer
);
8381 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8382 Set a watchpoint for an expression.\n\
8383 A watchpoint stops execution of your program whenever the value of\n\
8384 an expression is either read or written."));
8385 set_cmd_completer (c
, location_completer
);
8387 add_info ("watchpoints", breakpoints_info
,
8388 _("Synonym for ``info breakpoints''."));
8391 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8392 respond to changes - contrary to the description. */
8393 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8394 &can_use_hw_watchpoints
, _("\
8395 Set debugger's willingness to use watchpoint hardware."), _("\
8396 Show debugger's willingness to use watchpoint hardware."), _("\
8397 If zero, gdb will not use hardware for new watchpoints, even if\n\
8398 such is available. (However, any hardware watchpoints that were\n\
8399 created before setting this to nonzero, will continue to use watchpoint\n\
8402 show_can_use_hw_watchpoints
,
8403 &setlist
, &showlist
);
8405 can_use_hw_watchpoints
= 1;
8407 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8408 Breakpoint specific settings\n\
8409 Configure various breakpoint-specific variables such as\n\
8410 pending breakpoint behavior"),
8411 &breakpoint_set_cmdlist
, "set breakpoint ",
8412 0/*allow-unknown*/, &setlist
);
8413 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8414 Breakpoint specific settings\n\
8415 Configure various breakpoint-specific variables such as\n\
8416 pending breakpoint behavior"),
8417 &breakpoint_show_cmdlist
, "show breakpoint ",
8418 0/*allow-unknown*/, &showlist
);
8420 add_setshow_auto_boolean_cmd ("pending", no_class
,
8421 &pending_break_support
, _("\
8422 Set debugger's behavior regarding pending breakpoints."), _("\
8423 Show debugger's behavior regarding pending breakpoints."), _("\
8424 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8425 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8426 an error. If auto, an unrecognized breakpoint location results in a\n\
8427 user-query to see if a pending breakpoint should be created."),
8429 show_pending_break_support
,
8430 &breakpoint_set_cmdlist
,
8431 &breakpoint_show_cmdlist
);
8433 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8435 add_setshow_boolean_cmd ("auto-hw", no_class
,
8436 &automatic_hardware_breakpoints
, _("\
8437 Set automatic usage of hardware breakpoints."), _("\
8438 Show automatic usage of hardware breakpoints."), _("\
8439 If set, the debugger will automatically use hardware breakpoints for\n\
8440 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8441 a warning will be emitted for such breakpoints."),
8443 show_automatic_hardware_breakpoints
,
8444 &breakpoint_set_cmdlist
,
8445 &breakpoint_show_cmdlist
);
8447 automatic_hardware_breakpoints
= 1;