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
,
68 static void catch_command_1 (char *, int, int);
70 static void enable_delete_command (char *, int);
72 static void enable_delete_breakpoint (struct breakpoint
*);
74 static void enable_once_command (char *, int);
76 static void enable_once_breakpoint (struct breakpoint
*);
78 static void disable_command (char *, int);
80 static void enable_command (char *, int);
82 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
84 static void ignore_command (char *, int);
86 static int breakpoint_re_set_one (void *);
88 static void clear_command (char *, int);
90 static void catch_command (char *, int);
92 static void watch_command (char *, int);
94 static int can_use_hardware_watchpoint (struct value
*);
96 static void break_command_1 (char *, int, int);
98 static void mention (struct breakpoint
*);
100 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
102 static void check_duplicates (struct breakpoint
*);
104 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
106 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
109 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
111 static void breakpoints_info (char *, int);
113 static void breakpoint_1 (int, int);
115 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
117 static int breakpoint_cond_eval (void *);
119 static void cleanup_executing_breakpoints (void *);
121 static void commands_command (char *, int);
123 static void condition_command (char *, int);
125 static int get_number_trailer (char **, int);
127 void set_breakpoint_count (int);
136 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
138 static enum print_stop_action
print_it_typical (bpstat
);
140 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
142 static int watchpoint_check (void *);
144 static void maintenance_info_breakpoints (char *, int);
146 static void create_overlay_event_breakpoint (char *);
148 static int hw_breakpoint_used_count (void);
150 static int hw_watchpoint_used_count (enum bptype
, int *);
152 static void hbreak_command (char *, int);
154 static void thbreak_command (char *, int);
156 static void watch_command_1 (char *, int, int);
158 static void rwatch_command (char *, int);
160 static void awatch_command (char *, int);
162 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
164 static void create_fork_vfork_event_catchpoint (int tempflag
,
166 enum bptype bp_kind
);
168 static void stop_command (char *arg
, int from_tty
);
170 static void stopin_command (char *arg
, int from_tty
);
172 static void stopat_command (char *arg
, int from_tty
);
174 static char *ep_find_event_name_end (char *arg
);
176 static char *ep_parse_optional_if_clause (char **arg
);
178 static char *ep_parse_optional_filename (char **arg
);
180 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
181 char *arg
, int tempflag
, int from_tty
);
183 static void tcatch_command (char *arg
, int from_tty
);
185 static void ep_skip_leading_whitespace (char **s
);
187 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
189 static void free_bp_location (struct bp_location
*loc
);
191 static struct bp_location
*
192 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
194 static void update_global_location_list (int);
196 static void update_global_location_list_nothrow (int);
198 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
200 static void insert_breakpoint_locations (void);
203 bpdisp_text (enum bpdisp disp
)
205 /* NOTE: the following values are a part of MI protocol and represent
206 values of 'disp' field returned when inferior stops at a breakpoint. */
207 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
208 return bpdisps
[(int) disp
];
211 /* Prototypes for exported functions. */
212 /* If FALSE, gdb will not use hardware support for watchpoints, even
213 if such is available. */
214 static int can_use_hw_watchpoints
;
217 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
218 struct cmd_list_element
*c
,
221 fprintf_filtered (file
, _("\
222 Debugger's willingness to use watchpoint hardware is %s.\n"),
226 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
227 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
228 for unrecognized breakpoint locations.
229 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
230 static enum auto_boolean pending_break_support
;
232 show_pending_break_support (struct ui_file
*file
, int from_tty
,
233 struct cmd_list_element
*c
,
236 fprintf_filtered (file
, _("\
237 Debugger's behavior regarding pending breakpoints is %s.\n"),
241 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
242 set with "break" but falling in read-only memory.
243 If 0, gdb will warn about such breakpoints, but won't automatically
244 use hardware breakpoints. */
245 static int automatic_hardware_breakpoints
;
247 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
248 struct cmd_list_element
*c
,
251 fprintf_filtered (file
, _("\
252 Automatic usage of hardware breakpoints is %s.\n"),
256 /* If 1, gdb will keep breakpoints inserted even as inferior is stopped,
257 and immediately insert any new breakpoints. If 0, gdb will insert
258 breakpoints into inferior only when resuming it, and will remove
259 breakpoints upon stop. */
260 static int always_inserted_mode
= 0;
262 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
263 struct cmd_list_element
*c
, const char *value
)
265 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
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 /* The locations that no longer correspond to any breakpoint,
310 unlinked from bp_location_chain, but for which a hit
311 may still be reported by a target. */
312 VEC(bp_location_p
) *moribund_locations
= NULL
;
314 /* Number of last breakpoint made. */
316 int breakpoint_count
;
318 /* This function returns a pointer to the string representation of the
319 pathname of the dynamically-linked library that has just been
322 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
323 or undefined results are guaranteed.
325 This string's contents are only valid immediately after the
326 inferior has stopped in the dynamic linker hook, and becomes
327 invalid as soon as the inferior is continued. Clients should make
328 a copy of this string if they wish to continue the inferior and
329 then access the string. */
331 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
332 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
335 /* This function returns a pointer to the string representation of the
336 pathname of the dynamically-linked library that has just been
339 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
340 TRUE, or undefined results are guaranteed.
342 This string's contents are only valid immediately after the
343 inferior has stopped in the dynamic linker hook, and becomes
344 invalid as soon as the inferior is continued. Clients should make
345 a copy of this string if they wish to continue the inferior and
346 then access the string. */
348 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
349 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
352 /* This function is called by the "catch load" command. It allows the
353 debugger to be notified by the dynamic linker when a specified
354 library file (or any library file, if filename is NULL) is loaded. */
356 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
357 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
358 error (_("catch of library loads not yet implemented on this platform"))
361 /* This function is called by the "catch unload" command. It allows
362 the debugger to be notified by the dynamic linker when a specified
363 library file (or any library file, if filename is NULL) is
366 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
367 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
368 error (_("catch of library unloads not yet implemented on this platform"))
371 /* Return whether a breakpoint is an active enabled breakpoint. */
373 breakpoint_enabled (struct breakpoint
*b
)
375 return (b
->enable_state
== bp_enabled
);
378 /* Set breakpoint count to NUM. */
381 set_breakpoint_count (int num
)
383 breakpoint_count
= num
;
384 set_internalvar (lookup_internalvar ("bpnum"),
385 value_from_longest (builtin_type_int
, (LONGEST
) num
));
388 /* Used in run_command to zero the hit count when a new run starts. */
391 clear_breakpoint_hit_counts (void)
393 struct breakpoint
*b
;
399 /* Default address, symtab and line to put a breakpoint at
400 for "break" command with no arg.
401 if default_breakpoint_valid is zero, the other three are
402 not valid, and "break" with no arg is an error.
404 This set by print_stack_frame, which calls set_default_breakpoint. */
406 int default_breakpoint_valid
;
407 CORE_ADDR default_breakpoint_address
;
408 struct symtab
*default_breakpoint_symtab
;
409 int default_breakpoint_line
;
411 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
412 Advance *PP after the string and any trailing whitespace.
414 Currently the string can either be a number or "$" followed by the name
415 of a convenience variable. Making it an expression wouldn't work well
416 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
418 If the string is a NULL pointer, that denotes the last breakpoint.
420 TRAILER is a character which can be found after the number; most
421 commonly this is `-'. If you don't want a trailer, use \0. */
423 get_number_trailer (char **pp
, int trailer
)
425 int retval
= 0; /* default */
429 /* Empty line means refer to the last breakpoint. */
430 return breakpoint_count
;
433 /* Make a copy of the name, so we can null-terminate it
434 to pass to lookup_internalvar(). */
439 while (isalnum (*p
) || *p
== '_')
441 varname
= (char *) alloca (p
- start
+ 1);
442 strncpy (varname
, start
, p
- start
);
443 varname
[p
- start
] = '\0';
444 val
= value_of_internalvar (lookup_internalvar (varname
));
445 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
446 retval
= (int) value_as_long (val
);
449 printf_filtered (_("Convenience variable must have integer value.\n"));
457 while (*p
>= '0' && *p
<= '9')
460 /* There is no number here. (e.g. "cond a == b"). */
462 /* Skip non-numeric token */
463 while (*p
&& !isspace((int) *p
))
465 /* Return zero, which caller must interpret as error. */
471 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
473 /* Trailing junk: return 0 and let caller print error msg. */
474 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
485 /* Like get_number_trailer, but don't allow a trailer. */
487 get_number (char **pp
)
489 return get_number_trailer (pp
, '\0');
492 /* Parse a number or a range.
493 * A number will be of the form handled by get_number.
494 * A range will be of the form <number1> - <number2>, and
495 * will represent all the integers between number1 and number2,
498 * While processing a range, this fuction is called iteratively;
499 * At each call it will return the next value in the range.
501 * At the beginning of parsing a range, the char pointer PP will
502 * be advanced past <number1> and left pointing at the '-' token.
503 * Subsequent calls will not advance the pointer until the range
504 * is completed. The call that completes the range will advance
505 * pointer PP past <number2>.
509 get_number_or_range (char **pp
)
511 static int last_retval
, end_value
;
512 static char *end_ptr
;
513 static int in_range
= 0;
517 /* Default case: pp is pointing either to a solo number,
518 or to the first number of a range. */
519 last_retval
= get_number_trailer (pp
, '-');
524 /* This is the start of a range (<number1> - <number2>).
525 Skip the '-', parse and remember the second number,
526 and also remember the end of the final token. */
530 while (isspace ((int) *end_ptr
))
531 end_ptr
++; /* skip white space */
532 end_value
= get_number (temp
);
533 if (end_value
< last_retval
)
535 error (_("inverted range"));
537 else if (end_value
== last_retval
)
539 /* degenerate range (number1 == number2). Advance the
540 token pointer so that the range will be treated as a
549 error (_("negative value"));
552 /* pp points to the '-' that betokens a range. All
553 number-parsing has already been done. Return the next
554 integer value (one greater than the saved previous value).
555 Do not advance the token pointer 'pp' until the end of range
558 if (++last_retval
== end_value
)
560 /* End of range reached; advance token pointer. */
570 /* condition N EXP -- set break condition of breakpoint N to EXP. */
573 condition_command (char *arg
, int from_tty
)
575 struct breakpoint
*b
;
580 error_no_arg (_("breakpoint number"));
583 bnum
= get_number (&p
);
585 error (_("Bad breakpoint argument: '%s'"), arg
);
588 if (b
->number
== bnum
)
590 struct bp_location
*loc
= b
->loc
;
591 for (; loc
; loc
= loc
->next
)
599 if (b
->cond_string
!= NULL
)
600 xfree (b
->cond_string
);
604 b
->cond_string
= NULL
;
606 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
611 /* I don't know if it matters whether this is the string the user
612 typed in or the decompiled expression. */
613 b
->cond_string
= savestring (arg
, strlen (arg
));
614 b
->condition_not_parsed
= 0;
615 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
619 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
621 error (_("Junk at end of expression"));
624 breakpoints_changed ();
625 breakpoint_modify_event (b
->number
);
629 error (_("No breakpoint number %d."), bnum
);
633 commands_command (char *arg
, int from_tty
)
635 struct breakpoint
*b
;
638 struct command_line
*l
;
640 /* If we allowed this, we would have problems with when to
641 free the storage, if we change the commands currently
644 if (executing_breakpoint_commands
)
645 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
648 bnum
= get_number (&p
);
651 error (_("Unexpected extra arguments following breakpoint number."));
654 if (b
->number
== bnum
)
656 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
658 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
659 l
= read_command_lines (tmpbuf
, from_tty
);
660 do_cleanups (cleanups
);
661 free_command_lines (&b
->commands
);
663 breakpoints_changed ();
664 breakpoint_modify_event (b
->number
);
667 error (_("No breakpoint number %d."), bnum
);
670 /* Like commands_command, but instead of reading the commands from
671 input stream, takes them from an already parsed command structure.
673 This is used by cli-script.c to DTRT with breakpoint commands
674 that are part of if and while bodies. */
675 enum command_control_type
676 commands_from_control_command (char *arg
, struct command_line
*cmd
)
678 struct breakpoint
*b
;
682 /* If we allowed this, we would have problems with when to
683 free the storage, if we change the commands currently
686 if (executing_breakpoint_commands
)
687 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
689 /* An empty string for the breakpoint number means the last
690 breakpoint, but get_number expects a NULL pointer. */
695 bnum
= get_number (&p
);
698 error (_("Unexpected extra arguments following breakpoint number."));
701 if (b
->number
== bnum
)
703 free_command_lines (&b
->commands
);
704 if (cmd
->body_count
!= 1)
705 error (_("Invalid \"commands\" block structure."));
706 /* We need to copy the commands because if/while will free the
707 list after it finishes execution. */
708 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
709 breakpoints_changed ();
710 breakpoint_modify_event (b
->number
);
711 return simple_control
;
713 error (_("No breakpoint number %d."), bnum
);
716 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
717 by replacing any memory breakpoints with their shadowed contents. */
720 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
722 struct bp_location
*b
;
723 CORE_ADDR bp_addr
= 0;
729 if (b
->owner
->type
== bp_none
)
730 warning (_("reading through apparently deleted breakpoint #%d?"),
733 if (b
->loc_type
!= bp_loc_software_breakpoint
)
737 /* Addresses and length of the part of the breakpoint that
739 bp_addr
= b
->target_info
.placed_address
;
740 bp_size
= b
->target_info
.shadow_len
;
742 /* bp isn't valid, or doesn't shadow memory. */
745 if (bp_addr
+ bp_size
<= memaddr
)
746 /* The breakpoint is entirely before the chunk of memory we
750 if (bp_addr
>= memaddr
+ len
)
751 /* The breakpoint is entirely after the chunk of memory we are
755 /* Offset within shadow_contents. */
756 if (bp_addr
< memaddr
)
758 /* Only copy the second part of the breakpoint. */
759 bp_size
-= memaddr
- bp_addr
;
760 bptoffset
= memaddr
- bp_addr
;
764 if (bp_addr
+ bp_size
> memaddr
+ len
)
766 /* Only copy the first part of the breakpoint. */
767 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
770 memcpy (buf
+ bp_addr
- memaddr
,
771 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
776 /* A wrapper function for inserting catchpoints. */
778 insert_catchpoint (struct ui_out
*uo
, void *args
)
780 struct breakpoint
*b
= (struct breakpoint
*) args
;
786 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
789 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
792 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
795 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
801 is_hardware_watchpoint (struct breakpoint
*bpt
)
803 return (bpt
->type
== bp_hardware_watchpoint
804 || bpt
->type
== bp_read_watchpoint
805 || bpt
->type
== bp_access_watchpoint
);
808 /* Find the current value of a watchpoint on EXP. Return the value in
809 *VALP and *RESULTP and the chain of intermediate and final values
810 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
813 If an error occurs while evaluating the expression, *RESULTP will
814 be set to NULL. *RESULTP may be a lazy value, if the result could
815 not be read from memory. It is used to determine whether a value
816 is user-specified (we should watch the whole value) or intermediate
817 (we should watch only the bit used to locate the final value).
819 If the final value, or any intermediate value, could not be read
820 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
821 set to any referenced values. *VALP will never be a lazy value.
822 This is the value which we store in struct breakpoint.
824 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
825 value chain. The caller must free the values individually. If
826 VAL_CHAIN is NULL, all generated values will be left on the value
830 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
831 struct value
**resultp
, struct value
**val_chain
)
833 struct value
*mark
, *new_mark
, *result
;
841 /* Evaluate the expression. */
842 mark
= value_mark ();
844 gdb_evaluate_expression (exp
, &result
);
845 new_mark
= value_mark ();
846 if (mark
== new_mark
)
851 /* Make sure it's not lazy, so that after the target stops again we
852 have a non-lazy previous value to compare with. */
854 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
859 /* Return the chain of intermediate values. We use this to
860 decide which addresses to watch. */
861 *val_chain
= new_mark
;
862 value_release_to_mark (mark
);
866 /* Assuming that B is a hardware watchpoint:
867 - Reparse watchpoint expression, is REPARSE is non-zero
868 - Evaluate expression and store the result in B->val
869 - Update the list of values that must be watched in B->loc.
871 If the watchpoint is disabled, do nothing. If this is
872 local watchpoint that is out of scope, delete it. */
874 update_watchpoint (struct breakpoint
*b
, int reparse
)
876 int within_current_scope
;
877 struct frame_id saved_frame_id
;
878 struct bp_location
*loc
;
881 /* We don't free locations. They are stored in
882 bp_location_chain and update_global_locations will
883 eventually delete them and remove breakpoints if
887 if (b
->disposition
== disp_del_at_next_stop
)
890 /* Save the current frame's ID so we can restore it after
891 evaluating the watchpoint expression on its own frame. */
892 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
893 took a frame parameter, so that we didn't have to change the
895 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
897 /* Determine if the watchpoint is within scope. */
898 if (b
->exp_valid_block
== NULL
)
899 within_current_scope
= 1;
902 struct frame_info
*fi
;
903 fi
= frame_find_by_id (b
->watchpoint_frame
);
904 within_current_scope
= (fi
!= NULL
);
905 if (within_current_scope
)
909 if (within_current_scope
&& reparse
)
918 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
919 /* If the meaning of expression itself changed, the old value is
920 no longer relevant. We don't want to report a watchpoint hit
921 to the user when the old value and the new value may actually
922 be completely different objects. */
928 /* If we failed to parse the expression, for example because
929 it refers to a global variable in a not-yet-loaded shared library,
930 don't try to insert watchpoint. We don't automatically delete
931 such watchpoint, though, since failure to parse expression
932 is different from out-of-scope watchpoint. */
933 if (within_current_scope
&& b
->exp
)
935 struct value
*val_chain
, *v
, *result
, *next
;
937 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
939 /* Avoid setting b->val if it's already set. The meaning of
940 b->val is 'the last value' user saw, and we should update
941 it only if we reported that last value to user. As it
942 happens, the code that reports it updates b->val directly. */
949 /* Look at each value on the value chain. */
950 for (v
= val_chain
; v
; v
= next
)
952 /* If it's a memory location, and GDB actually needed
953 its contents to evaluate the expression, then we
954 must watch it. If the first value returned is
955 still lazy, that means an error occurred reading it;
956 watch it anyway in case it becomes readable. */
957 if (VALUE_LVAL (v
) == lval_memory
958 && (v
== val_chain
|| ! value_lazy (v
)))
960 struct type
*vtype
= check_typedef (value_type (v
));
962 /* We only watch structs and arrays if user asked
963 for it explicitly, never if they just happen to
964 appear in the middle of some value chain. */
966 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
967 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
971 struct bp_location
*loc
, **tmp
;
973 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
974 len
= TYPE_LENGTH (value_type (v
));
976 if (b
->type
== bp_read_watchpoint
)
978 else if (b
->type
== bp_access_watchpoint
)
981 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
982 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
987 loc
->watchpoint_type
= type
;
991 next
= value_next (v
);
996 /* We just regenerated the list of breakpoint locations.
997 The new location does not have its condition field set to anything
998 and therefore, we must always reparse the cond_string, independently
999 of the value of the reparse flag. */
1000 if (b
->cond_string
!= NULL
)
1002 char *s
= b
->cond_string
;
1003 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1006 else if (!within_current_scope
)
1008 printf_filtered (_("\
1009 Hardware watchpoint %d deleted because the program has left the block \n\
1010 in which its expression is valid.\n"),
1012 if (b
->related_breakpoint
)
1013 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1014 b
->disposition
= disp_del_at_next_stop
;
1017 /* Restore the selected frame. */
1018 select_frame (frame_find_by_id (saved_frame_id
));
1022 /* Returns 1 iff breakpoint location should be
1023 inserted in the inferior. */
1025 should_be_inserted (struct bp_location
*bpt
)
1027 if (!breakpoint_enabled (bpt
->owner
))
1030 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1033 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1039 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1040 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1041 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1043 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1044 method for each breakpoint or catchpoint type. */
1046 insert_bp_location (struct bp_location
*bpt
,
1047 struct ui_file
*tmp_error_stream
,
1048 int *disabled_breaks
, int *process_warning
,
1049 int *hw_breakpoint_error
)
1053 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1056 /* Initialize the target-specific information. */
1057 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1058 bpt
->target_info
.placed_address
= bpt
->address
;
1060 if (bpt
->loc_type
== bp_loc_software_breakpoint
1061 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1063 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1065 /* If the explicitly specified breakpoint type
1066 is not hardware breakpoint, check the memory map to see
1067 if the breakpoint address is in read only memory or not.
1068 Two important cases are:
1069 - location type is not hardware breakpoint, memory
1070 is readonly. We change the type of the location to
1071 hardware breakpoint.
1072 - location type is hardware breakpoint, memory is read-write.
1073 This means we've previously made the location hardware one, but
1074 then the memory map changed, so we undo.
1076 When breakpoints are removed, remove_breakpoints will
1077 use location types we've just set here, the only possible
1078 problem is that memory map has changed during running program,
1079 but it's not going to work anyway with current gdb. */
1080 struct mem_region
*mr
1081 = lookup_mem_region (bpt
->target_info
.placed_address
);
1085 if (automatic_hardware_breakpoints
)
1088 enum bp_loc_type new_type
;
1090 if (mr
->attrib
.mode
!= MEM_RW
)
1091 new_type
= bp_loc_hardware_breakpoint
;
1093 new_type
= bp_loc_software_breakpoint
;
1095 if (new_type
!= bpt
->loc_type
)
1097 static int said
= 0;
1098 bpt
->loc_type
= new_type
;
1101 fprintf_filtered (gdb_stdout
, _("\
1102 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1107 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1108 && mr
->attrib
.mode
!= MEM_RW
)
1109 warning (_("cannot set software breakpoint at readonly address %s"),
1110 paddr (bpt
->address
));
1114 /* First check to see if we have to handle an overlay. */
1115 if (overlay_debugging
== ovly_off
1116 || bpt
->section
== NULL
1117 || !(section_is_overlay (bpt
->section
)))
1119 /* No overlay handling: just set the breakpoint. */
1121 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1122 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1124 val
= target_insert_breakpoint (&bpt
->target_info
);
1128 /* This breakpoint is in an overlay section.
1129 Shall we set a breakpoint at the LMA? */
1130 if (!overlay_events_enabled
)
1132 /* Yes -- overlay event support is not active,
1133 so we must try to set a breakpoint at the LMA.
1134 This will not work for a hardware breakpoint. */
1135 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1136 warning (_("hardware breakpoint %d not supported in overlay!"),
1137 bpt
->owner
->number
);
1140 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1142 /* Set a software (trap) breakpoint at the LMA. */
1143 bpt
->overlay_target_info
= bpt
->target_info
;
1144 bpt
->overlay_target_info
.placed_address
= addr
;
1145 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1147 fprintf_unfiltered (tmp_error_stream
,
1148 "Overlay breakpoint %d failed: in ROM?",
1149 bpt
->owner
->number
);
1152 /* Shall we set a breakpoint at the VMA? */
1153 if (section_is_mapped (bpt
->section
))
1155 /* Yes. This overlay section is mapped into memory. */
1156 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1157 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1159 val
= target_insert_breakpoint (&bpt
->target_info
);
1163 /* No. This breakpoint will not be inserted.
1164 No error, but do not mark the bp as 'inserted'. */
1171 /* Can't set the breakpoint. */
1172 if (solib_address (bpt
->address
))
1174 /* See also: disable_breakpoints_in_shlibs. */
1176 bpt
->shlib_disabled
= 1;
1177 if (!*disabled_breaks
)
1179 fprintf_unfiltered (tmp_error_stream
,
1180 "Cannot insert breakpoint %d.\n",
1181 bpt
->owner
->number
);
1182 fprintf_unfiltered (tmp_error_stream
,
1183 "Temporarily disabling shared library breakpoints:\n");
1185 *disabled_breaks
= 1;
1186 fprintf_unfiltered (tmp_error_stream
,
1187 "breakpoint #%d\n", bpt
->owner
->number
);
1191 #ifdef ONE_PROCESS_WRITETEXT
1192 *process_warning
= 1;
1194 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1196 *hw_breakpoint_error
= 1;
1197 fprintf_unfiltered (tmp_error_stream
,
1198 "Cannot insert hardware breakpoint %d.\n",
1199 bpt
->owner
->number
);
1203 fprintf_unfiltered (tmp_error_stream
,
1204 "Cannot insert breakpoint %d.\n",
1205 bpt
->owner
->number
);
1206 fprintf_filtered (tmp_error_stream
,
1207 "Error accessing memory address ");
1208 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1209 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1210 safe_strerror (val
));
1221 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1222 /* NOTE drow/2003-09-08: This state only exists for removing
1223 watchpoints. It's not clear that it's necessary... */
1224 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1226 val
= target_insert_watchpoint (bpt
->address
,
1228 bpt
->watchpoint_type
);
1229 bpt
->inserted
= (val
!= -1);
1232 else if (bpt
->owner
->type
== bp_catch_fork
1233 || bpt
->owner
->type
== bp_catch_vfork
1234 || bpt
->owner
->type
== bp_catch_exec
)
1236 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1237 bpt
->owner
, RETURN_MASK_ERROR
);
1238 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1239 bpt
->owner
->number
);
1241 bpt
->owner
->enable_state
= bp_disabled
;
1245 /* We've already printed an error message if there was a problem
1246 inserting this catchpoint, and we've disabled the catchpoint,
1247 so just return success. */
1254 /* Make sure all breakpoints are inserted in inferior.
1255 Throws exception on any error.
1256 A breakpoint that is already inserted won't be inserted
1257 again, so calling this function twice is safe. */
1259 insert_breakpoints (void)
1261 struct breakpoint
*bpt
;
1263 ALL_BREAKPOINTS (bpt
)
1264 if (is_hardware_watchpoint (bpt
))
1265 update_watchpoint (bpt
, 0 /* don't reparse. */);
1267 update_global_location_list (1);
1269 if (!always_inserted_mode
&& target_has_execution
)
1270 /* update_global_location_list does not insert breakpoints
1271 when always_inserted_mode is not enabled. Explicitly
1273 insert_breakpoint_locations ();
1276 /* insert_breakpoints is used when starting or continuing the program.
1277 remove_breakpoints is used when the program stops.
1278 Both return zero if successful,
1279 or an `errno' value if could not write the inferior. */
1282 insert_breakpoint_locations (void)
1284 struct breakpoint
*bpt
;
1285 struct bp_location
*b
, *temp
;
1288 int disabled_breaks
= 0;
1289 int hw_breakpoint_error
= 0;
1290 int process_warning
= 0;
1292 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1293 make_cleanup_ui_file_delete (tmp_error_stream
);
1295 /* Explicitly mark the warning -- this will only be printed if
1296 there was an error. */
1297 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1299 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1301 if (!should_be_inserted (b
) || b
->inserted
)
1304 /* There is no point inserting thread-specific breakpoints if the
1305 thread no longer exists. */
1306 if (b
->owner
->thread
!= -1
1307 && !valid_thread_id (b
->owner
->thread
))
1310 val
= insert_bp_location (b
, tmp_error_stream
,
1311 &disabled_breaks
, &process_warning
,
1312 &hw_breakpoint_error
);
1317 /* If we failed to insert all locations of a watchpoint,
1318 remove them, as half-inserted watchpoint is of limited use. */
1319 ALL_BREAKPOINTS (bpt
)
1321 int some_failed
= 0;
1322 struct bp_location
*loc
;
1324 if (!is_hardware_watchpoint (bpt
))
1327 if (bpt
->enable_state
!= bp_enabled
)
1330 if (bpt
->disposition
== disp_del_at_next_stop
)
1333 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1341 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1343 remove_breakpoint (loc
, mark_uninserted
);
1345 hw_breakpoint_error
= 1;
1346 fprintf_unfiltered (tmp_error_stream
,
1347 "Could not insert hardware watchpoint %d.\n",
1355 /* If a hardware breakpoint or watchpoint was inserted, add a
1356 message about possibly exhausted resources. */
1357 if (hw_breakpoint_error
)
1359 fprintf_unfiltered (tmp_error_stream
,
1360 "Could not insert hardware breakpoints:\n\
1361 You may have requested too many hardware breakpoints/watchpoints.\n");
1363 #ifdef ONE_PROCESS_WRITETEXT
1364 if (process_warning
)
1365 fprintf_unfiltered (tmp_error_stream
,
1366 "The same program may be running in another process.");
1368 target_terminal_ours_for_output ();
1369 error_stream (tmp_error_stream
);
1374 remove_breakpoints (void)
1376 struct bp_location
*b
;
1379 ALL_BP_LOCATIONS (b
)
1383 val
= remove_breakpoint (b
, mark_uninserted
);
1392 remove_hw_watchpoints (void)
1394 struct bp_location
*b
;
1397 ALL_BP_LOCATIONS (b
)
1399 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1401 val
= remove_breakpoint (b
, mark_uninserted
);
1410 reattach_breakpoints (int pid
)
1412 struct bp_location
*b
;
1414 struct cleanup
*old_chain
= save_inferior_ptid ();
1415 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1416 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1418 make_cleanup_ui_file_delete (tmp_error_stream
);
1420 inferior_ptid
= pid_to_ptid (pid
);
1421 ALL_BP_LOCATIONS (b
)
1426 val
= insert_bp_location (b
, tmp_error_stream
,
1427 &dummy1
, &dummy2
, &dummy3
);
1430 do_cleanups (old_chain
);
1435 do_cleanups (old_chain
);
1440 update_breakpoints_after_exec (void)
1442 struct breakpoint
*b
;
1443 struct breakpoint
*temp
;
1444 struct bp_location
*bploc
;
1446 /* We're about to delete breakpoints from GDB's lists. If the
1447 INSERTED flag is true, GDB will try to lift the breakpoints by
1448 writing the breakpoints' "shadow contents" back into memory. The
1449 "shadow contents" are NOT valid after an exec, so GDB should not
1450 do that. Instead, the target is responsible from marking
1451 breakpoints out as soon as it detects an exec. We don't do that
1452 here instead, because there may be other attempts to delete
1453 breakpoints after detecting an exec and before reaching here. */
1454 ALL_BP_LOCATIONS (bploc
)
1455 gdb_assert (!bploc
->inserted
);
1457 ALL_BREAKPOINTS_SAFE (b
, temp
)
1459 /* Solib breakpoints must be explicitly reset after an exec(). */
1460 if (b
->type
== bp_shlib_event
)
1462 delete_breakpoint (b
);
1466 /* Thread event breakpoints must be set anew after an exec(),
1467 as must overlay event breakpoints. */
1468 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1470 delete_breakpoint (b
);
1474 /* Step-resume breakpoints are meaningless after an exec(). */
1475 if (b
->type
== bp_step_resume
)
1477 delete_breakpoint (b
);
1481 /* Longjmp and longjmp-resume breakpoints are also meaningless
1483 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1485 delete_breakpoint (b
);
1489 /* Don't delete an exec catchpoint, because else the inferior
1490 won't stop when it ought!
1492 Similarly, we probably ought to keep vfork catchpoints, 'cause
1493 on this target, we may not be able to stop when the vfork is
1494 seen, but only when the subsequent exec is seen. (And because
1495 deleting fork catchpoints here but not vfork catchpoints will
1496 seem mysterious to users, keep those too.) */
1497 if ((b
->type
== bp_catch_exec
) ||
1498 (b
->type
== bp_catch_vfork
) ||
1499 (b
->type
== bp_catch_fork
))
1504 /* bp_finish is a special case. The only way we ought to be able
1505 to see one of these when an exec() has happened, is if the user
1506 caught a vfork, and then said "finish". Ordinarily a finish just
1507 carries them to the call-site of the current callee, by setting
1508 a temporary bp there and resuming. But in this case, the finish
1509 will carry them entirely through the vfork & exec.
1511 We don't want to allow a bp_finish to remain inserted now. But
1512 we can't safely delete it, 'cause finish_command has a handle to
1513 the bp on a bpstat, and will later want to delete it. There's a
1514 chance (and I've seen it happen) that if we delete the bp_finish
1515 here, that its storage will get reused by the time finish_command
1516 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1517 We really must allow finish_command to delete a bp_finish.
1519 In the absense of a general solution for the "how do we know
1520 it's safe to delete something others may have handles to?"
1521 problem, what we'll do here is just uninsert the bp_finish, and
1522 let finish_command delete it.
1524 (We know the bp_finish is "doomed" in the sense that it's
1525 momentary, and will be deleted as soon as finish_command sees
1526 the inferior stopped. So it doesn't matter that the bp's
1527 address is probably bogus in the new a.out, unlike e.g., the
1528 solib breakpoints.) */
1530 if (b
->type
== bp_finish
)
1535 /* Without a symbolic address, we have little hope of the
1536 pre-exec() address meaning the same thing in the post-exec()
1538 if (b
->addr_string
== NULL
)
1540 delete_breakpoint (b
);
1544 /* FIXME what about longjmp breakpoints? Re-create them here? */
1545 create_overlay_event_breakpoint ("_ovly_debug_event");
1549 detach_breakpoints (int pid
)
1551 struct bp_location
*b
;
1553 struct cleanup
*old_chain
= save_inferior_ptid ();
1555 if (pid
== PIDGET (inferior_ptid
))
1556 error (_("Cannot detach breakpoints of inferior_ptid"));
1558 /* Set inferior_ptid; remove_breakpoint uses this global. */
1559 inferior_ptid
= pid_to_ptid (pid
);
1560 ALL_BP_LOCATIONS (b
)
1564 val
= remove_breakpoint (b
, mark_inserted
);
1567 do_cleanups (old_chain
);
1572 do_cleanups (old_chain
);
1577 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1581 if (b
->owner
->enable_state
== bp_permanent
)
1582 /* Permanent breakpoints cannot be inserted or removed. */
1585 /* The type of none suggests that owner is actually deleted.
1586 This should not ever happen. */
1587 gdb_assert (b
->owner
->type
!= bp_none
);
1589 if (b
->loc_type
== bp_loc_software_breakpoint
1590 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1592 /* "Normal" instruction breakpoint: either the standard
1593 trap-instruction bp (bp_breakpoint), or a
1594 bp_hardware_breakpoint. */
1596 /* First check to see if we have to handle an overlay. */
1597 if (overlay_debugging
== ovly_off
1598 || b
->section
== NULL
1599 || !(section_is_overlay (b
->section
)))
1601 /* No overlay handling: just remove the breakpoint. */
1603 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1604 val
= target_remove_hw_breakpoint (&b
->target_info
);
1606 val
= target_remove_breakpoint (&b
->target_info
);
1610 /* This breakpoint is in an overlay section.
1611 Did we set a breakpoint at the LMA? */
1612 if (!overlay_events_enabled
)
1614 /* Yes -- overlay event support is not active, so we
1615 should have set a breakpoint at the LMA. Remove it.
1617 /* Ignore any failures: if the LMA is in ROM, we will
1618 have already warned when we failed to insert it. */
1619 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1620 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1622 target_remove_breakpoint (&b
->overlay_target_info
);
1624 /* Did we set a breakpoint at the VMA?
1625 If so, we will have marked the breakpoint 'inserted'. */
1628 /* Yes -- remove it. Previously we did not bother to
1629 remove the breakpoint if the section had been
1630 unmapped, but let's not rely on that being safe. We
1631 don't know what the overlay manager might do. */
1632 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1633 val
= target_remove_hw_breakpoint (&b
->target_info
);
1635 /* However, we should remove *software* breakpoints only
1636 if the section is still mapped, or else we overwrite
1637 wrong code with the saved shadow contents. */
1638 else if (section_is_mapped (b
->section
))
1639 val
= target_remove_breakpoint (&b
->target_info
);
1645 /* No -- not inserted, so no need to remove. No error. */
1651 b
->inserted
= (is
== mark_inserted
);
1653 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1658 b
->inserted
= (is
== mark_inserted
);
1659 val
= target_remove_watchpoint (b
->address
, b
->length
,
1660 b
->watchpoint_type
);
1662 /* Failure to remove any of the hardware watchpoints comes here. */
1663 if ((is
== mark_uninserted
) && (b
->inserted
))
1664 warning (_("Could not remove hardware watchpoint %d."),
1667 else if ((b
->owner
->type
== bp_catch_fork
||
1668 b
->owner
->type
== bp_catch_vfork
||
1669 b
->owner
->type
== bp_catch_exec
)
1670 && breakpoint_enabled (b
->owner
)
1674 switch (b
->owner
->type
)
1677 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1679 case bp_catch_vfork
:
1680 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1683 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1686 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1691 b
->inserted
= (is
== mark_inserted
);
1697 /* Clear the "inserted" flag in all breakpoints. */
1700 mark_breakpoints_out (void)
1702 struct bp_location
*bpt
;
1704 ALL_BP_LOCATIONS (bpt
)
1708 /* Clear the "inserted" flag in all breakpoints and delete any
1709 breakpoints which should go away between runs of the program.
1711 Plus other such housekeeping that has to be done for breakpoints
1714 Note: this function gets called at the end of a run (by
1715 generic_mourn_inferior) and when a run begins (by
1716 init_wait_for_inferior). */
1721 breakpoint_init_inferior (enum inf_context context
)
1723 struct breakpoint
*b
, *temp
;
1724 struct bp_location
*bpt
;
1726 ALL_BP_LOCATIONS (bpt
)
1729 ALL_BREAKPOINTS_SAFE (b
, temp
)
1734 case bp_watchpoint_scope
:
1736 /* If the call dummy breakpoint is at the entry point it will
1737 cause problems when the inferior is rerun, so we better
1740 Also get rid of scope breakpoints. */
1741 delete_breakpoint (b
);
1745 case bp_hardware_watchpoint
:
1746 case bp_read_watchpoint
:
1747 case bp_access_watchpoint
:
1749 /* Likewise for watchpoints on local expressions. */
1750 if (b
->exp_valid_block
!= NULL
)
1751 delete_breakpoint (b
);
1752 else if (context
== inf_starting
)
1754 /* Reset val field to force reread of starting value
1755 in insert_breakpoints. */
1757 value_free (b
->val
);
1768 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1769 exists at PC. It returns ordinary_breakpoint_here if it's an
1770 ordinary breakpoint, or permanent_breakpoint_here if it's a
1771 permanent breakpoint.
1772 - When continuing from a location with an ordinary breakpoint, we
1773 actually single step once before calling insert_breakpoints.
1774 - When continuing from a localion with a permanent breakpoint, we
1775 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1776 the target, to advance the PC past the breakpoint. */
1778 enum breakpoint_here
1779 breakpoint_here_p (CORE_ADDR pc
)
1781 const struct bp_location
*bpt
;
1782 int any_breakpoint_here
= 0;
1784 ALL_BP_LOCATIONS (bpt
)
1786 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1787 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1790 if ((breakpoint_enabled (bpt
->owner
)
1791 || bpt
->owner
->enable_state
== bp_permanent
)
1792 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1794 if (overlay_debugging
1795 && section_is_overlay (bpt
->section
)
1796 && !section_is_mapped (bpt
->section
))
1797 continue; /* unmapped overlay -- can't be a match */
1798 else if (bpt
->owner
->enable_state
== bp_permanent
)
1799 return permanent_breakpoint_here
;
1801 any_breakpoint_here
= 1;
1805 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1809 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1810 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1811 This does not check for single-step breakpoints, which are
1812 inserted and removed using direct target manipulation. */
1815 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1817 const struct bp_location
*bpt
;
1819 ALL_BP_LOCATIONS (bpt
)
1821 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1822 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1826 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1828 if (overlay_debugging
1829 && section_is_overlay (bpt
->section
)
1830 && !section_is_mapped (bpt
->section
))
1831 continue; /* unmapped overlay -- can't be a match */
1839 /* Returns non-zero iff there's either regular breakpoint
1840 or a single step breakpoint inserted at PC. */
1843 breakpoint_inserted_here_p (CORE_ADDR pc
)
1845 if (regular_breakpoint_inserted_here_p (pc
))
1848 if (single_step_breakpoint_inserted_here_p (pc
))
1854 /* This function returns non-zero iff there is a software breakpoint
1858 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1860 const struct bp_location
*bpt
;
1861 int any_breakpoint_here
= 0;
1863 ALL_BP_LOCATIONS (bpt
)
1865 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1869 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1871 if (overlay_debugging
1872 && section_is_overlay (bpt
->section
)
1873 && !section_is_mapped (bpt
->section
))
1874 continue; /* unmapped overlay -- can't be a match */
1880 /* Also check for software single-step breakpoints. */
1881 if (single_step_breakpoint_inserted_here_p (pc
))
1887 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1888 PC is valid for process/thread PTID. */
1891 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1893 const struct bp_location
*bpt
;
1896 thread
= pid_to_thread_id (ptid
);
1898 ALL_BP_LOCATIONS (bpt
)
1900 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1901 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1904 if ((breakpoint_enabled (bpt
->owner
)
1905 || bpt
->owner
->enable_state
== bp_permanent
)
1906 && bpt
->address
== pc
1907 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1909 if (overlay_debugging
1910 && section_is_overlay (bpt
->section
)
1911 && !section_is_mapped (bpt
->section
))
1912 continue; /* unmapped overlay -- can't be a match */
1922 /* bpstat stuff. External routines' interfaces are documented
1926 ep_is_catchpoint (struct breakpoint
*ep
)
1929 (ep
->type
== bp_catch_load
)
1930 || (ep
->type
== bp_catch_unload
)
1931 || (ep
->type
== bp_catch_fork
)
1932 || (ep
->type
== bp_catch_vfork
)
1933 || (ep
->type
== bp_catch_exec
);
1935 /* ??rehrauer: Add more kinds here, as are implemented... */
1939 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1942 (ep
->type
== bp_catch_load
)
1943 || (ep
->type
== bp_catch_unload
);
1947 bpstat_free (bpstat bs
)
1949 if (bs
->old_val
!= NULL
)
1950 value_free (bs
->old_val
);
1951 free_command_lines (&bs
->commands
);
1955 /* Clear a bpstat so that it says we are not at any breakpoint.
1956 Also free any storage that is part of a bpstat. */
1959 bpstat_clear (bpstat
*bsp
)
1976 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1977 is part of the bpstat is copied as well. */
1980 bpstat_copy (bpstat bs
)
1984 bpstat retval
= NULL
;
1989 for (; bs
!= NULL
; bs
= bs
->next
)
1991 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1992 memcpy (tmp
, bs
, sizeof (*tmp
));
1993 if (bs
->commands
!= NULL
)
1994 tmp
->commands
= copy_command_lines (bs
->commands
);
1995 if (bs
->old_val
!= NULL
)
1997 tmp
->old_val
= value_copy (bs
->old_val
);
1998 release_value (tmp
->old_val
);
2002 /* This is the first thing in the chain. */
2012 /* Find the bpstat associated with this breakpoint */
2015 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2020 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2022 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2028 /* Find a step_resume breakpoint associated with this bpstat.
2029 (If there are multiple step_resume bp's on the list, this function
2030 will arbitrarily pick one.)
2032 It is an error to use this function if BPSTAT doesn't contain a
2033 step_resume breakpoint.
2035 See wait_for_inferior's use of this function. */
2037 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2041 gdb_assert (bsp
!= NULL
);
2043 current_thread
= pid_to_thread_id (inferior_ptid
);
2045 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2047 if ((bsp
->breakpoint_at
!= NULL
) &&
2048 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2049 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2050 bsp
->breakpoint_at
->owner
->thread
== -1))
2051 return bsp
->breakpoint_at
->owner
;
2054 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2058 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2059 at. *BSP upon return is a bpstat which points to the remaining
2060 breakpoints stopped at (but which is not guaranteed to be good for
2061 anything but further calls to bpstat_num).
2062 Return 0 if passed a bpstat which does not indicate any breakpoints.
2063 Return -1 if stopped at a breakpoint that has been deleted since
2065 Return 1 otherwise. */
2068 bpstat_num (bpstat
*bsp
, int *num
)
2070 struct breakpoint
*b
;
2073 return 0; /* No more breakpoint values */
2075 /* We assume we'll never have several bpstats that
2076 correspond to a single breakpoint -- otherwise,
2077 this function might return the same number more
2078 than once and this will look ugly. */
2079 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2080 *bsp
= (*bsp
)->next
;
2082 return -1; /* breakpoint that's been deleted since */
2084 *num
= b
->number
; /* We have its number */
2088 /* Modify BS so that the actions will not be performed. */
2091 bpstat_clear_actions (bpstat bs
)
2093 for (; bs
!= NULL
; bs
= bs
->next
)
2095 free_command_lines (&bs
->commands
);
2096 if (bs
->old_val
!= NULL
)
2098 value_free (bs
->old_val
);
2104 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2106 cleanup_executing_breakpoints (void *ignore
)
2108 executing_breakpoint_commands
= 0;
2111 /* Execute all the commands associated with all the breakpoints at this
2112 location. Any of these commands could cause the process to proceed
2113 beyond this point, etc. We look out for such changes by checking
2114 the global "breakpoint_proceeded" after each command. */
2117 bpstat_do_actions (bpstat
*bsp
)
2120 struct cleanup
*old_chain
;
2122 /* Avoid endless recursion if a `source' command is contained
2124 if (executing_breakpoint_commands
)
2127 executing_breakpoint_commands
= 1;
2128 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2131 /* Note that (as of this writing), our callers all appear to
2132 be passing us the address of global stop_bpstat. And, if
2133 our calls to execute_control_command cause the inferior to
2134 proceed, that global (and hence, *bsp) will change.
2136 We must be careful to not touch *bsp unless the inferior
2137 has not proceeded. */
2139 /* This pointer will iterate over the list of bpstat's. */
2142 breakpoint_proceeded
= 0;
2143 for (; bs
!= NULL
; bs
= bs
->next
)
2145 struct command_line
*cmd
;
2146 struct cleanup
*this_cmd_tree_chain
;
2148 /* Take ownership of the BSP's command tree, if it has one.
2150 The command tree could legitimately contain commands like
2151 'step' and 'next', which call clear_proceed_status, which
2152 frees stop_bpstat's command tree. To make sure this doesn't
2153 free the tree we're executing out from under us, we need to
2154 take ownership of the tree ourselves. Since a given bpstat's
2155 commands are only executed once, we don't need to copy it; we
2156 can clear the pointer in the bpstat, and make sure we free
2157 the tree when we're done. */
2160 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2164 execute_control_command (cmd
);
2166 if (breakpoint_proceeded
)
2172 /* We can free this command tree now. */
2173 do_cleanups (this_cmd_tree_chain
);
2175 if (breakpoint_proceeded
)
2177 if (target_can_async_p ())
2178 /* If we are in async mode, then the target might
2179 be still running, not stopped at any breakpoint,
2180 so nothing for us to do here -- just return to
2184 /* In sync mode, when execute_control_command returns
2185 we're already standing on the next breakpoint.
2186 Breakpoint commands for that stop were not run,
2187 since execute_command does not run breakpoint
2188 commands -- only command_line_handler does, but
2189 that one is not involved in execution of breakpoint
2190 commands. So, we can now execute breakpoint commands.
2191 There's an implicit assumption that we're called with
2192 stop_bpstat, so our parameter is the new bpstat to
2194 It should be noted that making execute_command do
2195 bpstat actions is not an option -- in this case we'll
2196 have recursive invocation of bpstat for each breakpoint
2197 with a command, and can easily blow up GDB stack. */
2201 do_cleanups (old_chain
);
2204 /* Print out the (old or new) value associated with a watchpoint. */
2207 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2210 fprintf_unfiltered (stream
, _("<unreadable>"));
2212 value_print (val
, stream
, 0, Val_pretty_default
);
2215 /* This is the normal print function for a bpstat. In the future,
2216 much of this logic could (should?) be moved to bpstat_stop_status,
2217 by having it set different print_it values.
2219 Current scheme: When we stop, bpstat_print() is called. It loops
2220 through the bpstat list of things causing this stop, calling the
2221 print_bp_stop_message function on each one. The behavior of the
2222 print_bp_stop_message function depends on the print_it field of
2223 bpstat. If such field so indicates, call this function here.
2225 Return values from this routine (ultimately used by bpstat_print()
2226 and normal_stop() to decide what to do):
2227 PRINT_NOTHING: Means we already printed all we needed to print,
2228 don't print anything else.
2229 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2230 that something to be followed by a location.
2231 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2232 that something to be followed by a location.
2233 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2236 static enum print_stop_action
2237 print_it_typical (bpstat bs
)
2239 struct cleanup
*old_chain
, *ui_out_chain
;
2240 struct breakpoint
*b
;
2241 const struct bp_location
*bl
;
2242 struct ui_stream
*stb
;
2244 stb
= ui_out_stream_new (uiout
);
2245 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2246 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2247 which has since been deleted. */
2248 if (bs
->breakpoint_at
== NULL
)
2249 return PRINT_UNKNOWN
;
2250 bl
= bs
->breakpoint_at
;
2256 case bp_hardware_breakpoint
:
2257 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2258 if (bl
->address
!= bl
->requested_address
)
2259 breakpoint_adjustment_warning (bl
->requested_address
,
2262 annotate_breakpoint (b
->number
);
2264 ui_out_text (uiout
, "\nTemporary breakpoint ");
2266 ui_out_text (uiout
, "\nBreakpoint ");
2267 if (ui_out_is_mi_like_p (uiout
))
2269 ui_out_field_string (uiout
, "reason",
2270 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2271 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2273 ui_out_field_int (uiout
, "bkptno", b
->number
);
2274 ui_out_text (uiout
, ", ");
2275 return PRINT_SRC_AND_LOC
;
2278 case bp_shlib_event
:
2279 /* Did we stop because the user set the stop_on_solib_events
2280 variable? (If so, we report this as a generic, "Stopped due
2281 to shlib event" message.) */
2282 printf_filtered (_("Stopped due to shared library event\n"));
2283 return PRINT_NOTHING
;
2286 case bp_thread_event
:
2287 /* Not sure how we will get here.
2288 GDB should not stop for these breakpoints. */
2289 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2290 return PRINT_NOTHING
;
2293 case bp_overlay_event
:
2294 /* By analogy with the thread event, GDB should not stop for these. */
2295 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2296 return PRINT_NOTHING
;
2300 annotate_catchpoint (b
->number
);
2301 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2303 b
->triggered_dll_pathname
);
2304 return PRINT_SRC_AND_LOC
;
2307 case bp_catch_unload
:
2308 annotate_catchpoint (b
->number
);
2309 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2311 b
->triggered_dll_pathname
);
2312 return PRINT_SRC_AND_LOC
;
2316 annotate_catchpoint (b
->number
);
2317 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2319 ptid_get_pid (b
->forked_inferior_pid
));
2320 return PRINT_SRC_AND_LOC
;
2323 case bp_catch_vfork
:
2324 annotate_catchpoint (b
->number
);
2325 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2327 ptid_get_pid (b
->forked_inferior_pid
));
2328 return PRINT_SRC_AND_LOC
;
2332 annotate_catchpoint (b
->number
);
2333 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2336 return PRINT_SRC_AND_LOC
;
2340 case bp_hardware_watchpoint
:
2341 annotate_watchpoint (b
->number
);
2342 if (ui_out_is_mi_like_p (uiout
))
2345 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2347 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2348 ui_out_text (uiout
, "\nOld value = ");
2349 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2350 ui_out_field_stream (uiout
, "old", stb
);
2351 ui_out_text (uiout
, "\nNew value = ");
2352 watchpoint_value_print (b
->val
, stb
->stream
);
2353 ui_out_field_stream (uiout
, "new", stb
);
2354 do_cleanups (ui_out_chain
);
2355 ui_out_text (uiout
, "\n");
2356 /* More than one watchpoint may have been triggered. */
2357 return PRINT_UNKNOWN
;
2360 case bp_read_watchpoint
:
2361 if (ui_out_is_mi_like_p (uiout
))
2364 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2366 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2367 ui_out_text (uiout
, "\nValue = ");
2368 watchpoint_value_print (b
->val
, stb
->stream
);
2369 ui_out_field_stream (uiout
, "value", stb
);
2370 do_cleanups (ui_out_chain
);
2371 ui_out_text (uiout
, "\n");
2372 return PRINT_UNKNOWN
;
2375 case bp_access_watchpoint
:
2376 if (bs
->old_val
!= NULL
)
2378 annotate_watchpoint (b
->number
);
2379 if (ui_out_is_mi_like_p (uiout
))
2382 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2384 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2385 ui_out_text (uiout
, "\nOld value = ");
2386 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2387 ui_out_field_stream (uiout
, "old", stb
);
2388 ui_out_text (uiout
, "\nNew value = ");
2393 if (ui_out_is_mi_like_p (uiout
))
2396 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2397 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2398 ui_out_text (uiout
, "\nValue = ");
2400 watchpoint_value_print (b
->val
, stb
->stream
);
2401 ui_out_field_stream (uiout
, "new", stb
);
2402 do_cleanups (ui_out_chain
);
2403 ui_out_text (uiout
, "\n");
2404 return PRINT_UNKNOWN
;
2407 /* Fall through, we don't deal with these types of breakpoints
2411 if (ui_out_is_mi_like_p (uiout
))
2414 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2415 return PRINT_UNKNOWN
;
2419 if (ui_out_is_mi_like_p (uiout
))
2422 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2423 return PRINT_UNKNOWN
;
2428 case bp_longjmp_resume
:
2429 case bp_step_resume
:
2430 case bp_watchpoint_scope
:
2433 return PRINT_UNKNOWN
;
2437 /* Generic routine for printing messages indicating why we
2438 stopped. The behavior of this function depends on the value
2439 'print_it' in the bpstat structure. Under some circumstances we
2440 may decide not to print anything here and delegate the task to
2443 static enum print_stop_action
2444 print_bp_stop_message (bpstat bs
)
2446 switch (bs
->print_it
)
2449 /* Nothing should be printed for this bpstat entry. */
2450 return PRINT_UNKNOWN
;
2454 /* We still want to print the frame, but we already printed the
2455 relevant messages. */
2456 return PRINT_SRC_AND_LOC
;
2459 case print_it_normal
:
2461 const struct bp_location
*bl
= bs
->breakpoint_at
;
2462 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2464 /* Normal case. Call the breakpoint's print_it method, or
2465 print_it_typical. */
2466 /* FIXME: how breakpoint can ever be NULL here? */
2467 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2468 return b
->ops
->print_it (b
);
2470 return print_it_typical (bs
);
2475 internal_error (__FILE__
, __LINE__
,
2476 _("print_bp_stop_message: unrecognized enum value"));
2481 /* Print a message indicating what happened. This is called from
2482 normal_stop(). The input to this routine is the head of the bpstat
2483 list - a list of the eventpoints that caused this stop. This
2484 routine calls the generic print routine for printing a message
2485 about reasons for stopping. This will print (for example) the
2486 "Breakpoint n," part of the output. The return value of this
2489 PRINT_UNKNOWN: Means we printed nothing
2490 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2491 code to print the location. An example is
2492 "Breakpoint 1, " which should be followed by
2494 PRINT_SRC_ONLY: Means we printed something, but there is no need
2495 to also print the location part of the message.
2496 An example is the catch/throw messages, which
2497 don't require a location appended to the end.
2498 PRINT_NOTHING: We have done some printing and we don't need any
2499 further info to be printed.*/
2501 enum print_stop_action
2502 bpstat_print (bpstat bs
)
2506 /* Maybe another breakpoint in the chain caused us to stop.
2507 (Currently all watchpoints go on the bpstat whether hit or not.
2508 That probably could (should) be changed, provided care is taken
2509 with respect to bpstat_explains_signal). */
2510 for (; bs
; bs
= bs
->next
)
2512 val
= print_bp_stop_message (bs
);
2513 if (val
== PRINT_SRC_ONLY
2514 || val
== PRINT_SRC_AND_LOC
2515 || val
== PRINT_NOTHING
)
2519 /* We reached the end of the chain, or we got a null BS to start
2520 with and nothing was printed. */
2521 return PRINT_UNKNOWN
;
2524 /* Evaluate the expression EXP and return 1 if value is zero.
2525 This is used inside a catch_errors to evaluate the breakpoint condition.
2526 The argument is a "struct expression *" that has been cast to char * to
2527 make it pass through catch_errors. */
2530 breakpoint_cond_eval (void *exp
)
2532 struct value
*mark
= value_mark ();
2533 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2534 value_free_to_mark (mark
);
2538 /* Allocate a new bpstat and chain it to the current one. */
2541 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2545 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2547 bs
->breakpoint_at
= bl
;
2548 /* If the condition is false, etc., don't do the commands. */
2549 bs
->commands
= NULL
;
2551 bs
->print_it
= print_it_normal
;
2555 /* The target has stopped with waitstatus WS. Check if any hardware
2556 watchpoints have triggered, according to the target. */
2559 watchpoints_triggered (struct target_waitstatus
*ws
)
2561 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2563 struct breakpoint
*b
;
2565 if (!stopped_by_watchpoint
)
2567 /* We were not stopped by a watchpoint. Mark all watchpoints
2568 as not triggered. */
2570 if (b
->type
== bp_hardware_watchpoint
2571 || b
->type
== bp_read_watchpoint
2572 || b
->type
== bp_access_watchpoint
)
2573 b
->watchpoint_triggered
= watch_triggered_no
;
2578 if (!target_stopped_data_address (¤t_target
, &addr
))
2580 /* We were stopped by a watchpoint, but we don't know where.
2581 Mark all watchpoints as unknown. */
2583 if (b
->type
== bp_hardware_watchpoint
2584 || b
->type
== bp_read_watchpoint
2585 || b
->type
== bp_access_watchpoint
)
2586 b
->watchpoint_triggered
= watch_triggered_unknown
;
2588 return stopped_by_watchpoint
;
2591 /* The target could report the data address. Mark watchpoints
2592 affected by this data address as triggered, and all others as not
2596 if (b
->type
== bp_hardware_watchpoint
2597 || b
->type
== bp_read_watchpoint
2598 || b
->type
== bp_access_watchpoint
)
2600 struct bp_location
*loc
;
2603 b
->watchpoint_triggered
= watch_triggered_no
;
2604 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2605 /* Exact match not required. Within range is
2607 if (target_watchpoint_addr_within_range (¤t_target
,
2611 b
->watchpoint_triggered
= watch_triggered_yes
;
2619 /* Possible return values for watchpoint_check (this can't be an enum
2620 because of check_errors). */
2621 /* The watchpoint has been deleted. */
2622 #define WP_DELETED 1
2623 /* The value has changed. */
2624 #define WP_VALUE_CHANGED 2
2625 /* The value has not changed. */
2626 #define WP_VALUE_NOT_CHANGED 3
2628 #define BP_TEMPFLAG 1
2629 #define BP_HARDWAREFLAG 2
2631 /* Check watchpoint condition. */
2634 watchpoint_check (void *p
)
2636 bpstat bs
= (bpstat
) p
;
2637 struct breakpoint
*b
;
2638 struct frame_info
*fr
;
2639 int within_current_scope
;
2641 b
= bs
->breakpoint_at
->owner
;
2643 if (b
->exp_valid_block
== NULL
)
2644 within_current_scope
= 1;
2647 /* There is no current frame at this moment. If we're going to have
2648 any chance of handling watchpoints on local variables, we'll need
2649 the frame chain (so we can determine if we're in scope). */
2650 reinit_frame_cache ();
2651 fr
= frame_find_by_id (b
->watchpoint_frame
);
2652 within_current_scope
= (fr
!= NULL
);
2654 /* If we've gotten confused in the unwinder, we might have
2655 returned a frame that can't describe this variable. */
2656 if (within_current_scope
2657 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2658 within_current_scope
= 0;
2660 /* in_function_epilogue_p() returns a non-zero value if we're still
2661 in the function but the stack frame has already been invalidated.
2662 Since we can't rely on the values of local variables after the
2663 stack has been destroyed, we are treating the watchpoint in that
2664 state as `not changed' without further checking.
2666 vinschen/2003-09-04: The former implementation left out the case
2667 that the watchpoint frame couldn't be found by frame_find_by_id()
2668 because the current PC is currently in an epilogue. Calling
2669 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2670 if ((!within_current_scope
|| fr
== get_current_frame ())
2671 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2672 return WP_VALUE_NOT_CHANGED
;
2673 if (fr
&& within_current_scope
)
2674 /* If we end up stopping, the current frame will get selected
2675 in normal_stop. So this call to select_frame won't affect
2680 if (within_current_scope
)
2682 /* We use value_{,free_to_}mark because it could be a
2683 *long* time before we return to the command level and
2684 call free_all_values. We can't call free_all_values because
2685 we might be in the middle of evaluating a function call. */
2687 struct value
*mark
= value_mark ();
2688 struct value
*new_val
;
2690 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2691 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2692 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2694 if (new_val
!= NULL
)
2696 release_value (new_val
);
2697 value_free_to_mark (mark
);
2699 bs
->old_val
= b
->val
;
2702 /* We will stop here */
2703 return WP_VALUE_CHANGED
;
2707 /* Nothing changed, don't do anything. */
2708 value_free_to_mark (mark
);
2709 /* We won't stop here */
2710 return WP_VALUE_NOT_CHANGED
;
2715 /* This seems like the only logical thing to do because
2716 if we temporarily ignored the watchpoint, then when
2717 we reenter the block in which it is valid it contains
2718 garbage (in the case of a function, it may have two
2719 garbage values, one before and one after the prologue).
2720 So we can't even detect the first assignment to it and
2721 watch after that (since the garbage may or may not equal
2722 the first value assigned). */
2723 /* We print all the stop information in print_it_typical(), but
2724 in this case, by the time we call print_it_typical() this bp
2725 will be deleted already. So we have no choice but print the
2726 information here. */
2727 if (ui_out_is_mi_like_p (uiout
))
2729 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2730 ui_out_text (uiout
, "\nWatchpoint ");
2731 ui_out_field_int (uiout
, "wpnum", b
->number
);
2732 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2733 which its expression is valid.\n");
2735 if (b
->related_breakpoint
)
2736 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2737 b
->disposition
= disp_del_at_next_stop
;
2743 /* Return true if it looks like target has stopped due to hitting
2744 breakpoint location BL. This function does not check if we
2745 should stop, only if BL explains the stop. */
2747 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2749 struct breakpoint
*b
= bl
->owner
;
2751 if (b
->type
!= bp_watchpoint
2752 && b
->type
!= bp_hardware_watchpoint
2753 && b
->type
!= bp_read_watchpoint
2754 && b
->type
!= bp_access_watchpoint
2755 && b
->type
!= bp_hardware_breakpoint
2756 && b
->type
!= bp_catch_fork
2757 && b
->type
!= bp_catch_vfork
2758 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2760 if (bl
->address
!= bp_addr
) /* address doesn't match */
2762 if (overlay_debugging
/* unmapped overlay section */
2763 && section_is_overlay (bl
->section
)
2764 && !section_is_mapped (bl
->section
))
2768 /* Continuable hardware watchpoints are treated as non-existent if the
2769 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2770 some data address). Otherwise gdb won't stop on a break instruction
2771 in the code (not from a breakpoint) when a hardware watchpoint has
2772 been defined. Also skip watchpoints which we know did not trigger
2773 (did not match the data address). */
2775 if ((b
->type
== bp_hardware_watchpoint
2776 || b
->type
== bp_read_watchpoint
2777 || b
->type
== bp_access_watchpoint
)
2778 && b
->watchpoint_triggered
== watch_triggered_no
)
2781 if (b
->type
== bp_hardware_breakpoint
)
2783 if (bl
->address
!= bp_addr
)
2785 if (overlay_debugging
/* unmapped overlay section */
2786 && section_is_overlay (bl
->section
)
2787 && !section_is_mapped (bl
->section
))
2791 /* Is this a catchpoint of a load or unload? If so, did we
2792 get a load or unload of the specified library? If not,
2794 if ((b
->type
== bp_catch_load
)
2795 #if defined(SOLIB_HAVE_LOAD_EVENT)
2796 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2797 || ((b
->dll_pathname
!= NULL
)
2798 && (strcmp (b
->dll_pathname
,
2799 SOLIB_LOADED_LIBRARY_PATHNAME (
2800 PIDGET (inferior_ptid
)))
2806 if ((b
->type
== bp_catch_unload
)
2807 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2808 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2809 || ((b
->dll_pathname
!= NULL
)
2810 && (strcmp (b
->dll_pathname
,
2811 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2812 PIDGET (inferior_ptid
)))
2818 if ((b
->type
== bp_catch_fork
)
2819 && !inferior_has_forked (inferior_ptid
,
2820 &b
->forked_inferior_pid
))
2823 if ((b
->type
== bp_catch_vfork
)
2824 && !inferior_has_vforked (inferior_ptid
,
2825 &b
->forked_inferior_pid
))
2828 if ((b
->type
== bp_catch_exec
)
2829 && !inferior_has_execd (inferior_ptid
, &b
->exec_pathname
))
2835 /* If BS refers to a watchpoint, determine if the watched values
2836 has actually changed, and we should stop. If not, set BS->stop
2839 bpstat_check_watchpoint (bpstat bs
)
2841 const struct bp_location
*bl
= bs
->breakpoint_at
;
2842 struct breakpoint
*b
= bl
->owner
;
2844 if (b
->type
== bp_watchpoint
2845 || b
->type
== bp_read_watchpoint
2846 || b
->type
== bp_access_watchpoint
2847 || b
->type
== bp_hardware_watchpoint
)
2851 int must_check_value
= 0;
2853 if (b
->type
== bp_watchpoint
)
2854 /* For a software watchpoint, we must always check the
2856 must_check_value
= 1;
2857 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2858 /* We have a hardware watchpoint (read, write, or access)
2859 and the target earlier reported an address watched by
2861 must_check_value
= 1;
2862 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2863 && b
->type
== bp_hardware_watchpoint
)
2864 /* We were stopped by a hardware watchpoint, but the target could
2865 not report the data address. We must check the watchpoint's
2866 value. Access and read watchpoints are out of luck; without
2867 a data address, we can't figure it out. */
2868 must_check_value
= 1;
2870 if (must_check_value
)
2872 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2874 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2875 int e
= catch_errors (watchpoint_check
, bs
, message
,
2877 do_cleanups (cleanups
);
2881 /* We've already printed what needs to be printed. */
2882 bs
->print_it
= print_it_done
;
2885 case WP_VALUE_CHANGED
:
2886 if (b
->type
== bp_read_watchpoint
)
2888 /* Don't stop: read watchpoints shouldn't fire if
2889 the value has changed. This is for targets
2890 which cannot set read-only watchpoints. */
2891 bs
->print_it
= print_it_noop
;
2895 case WP_VALUE_NOT_CHANGED
:
2896 if (b
->type
== bp_hardware_watchpoint
2897 || b
->type
== bp_watchpoint
)
2899 /* Don't stop: write watchpoints shouldn't fire if
2900 the value hasn't changed. */
2901 bs
->print_it
= print_it_noop
;
2909 /* Error from catch_errors. */
2910 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2911 if (b
->related_breakpoint
)
2912 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2913 b
->disposition
= disp_del_at_next_stop
;
2914 /* We've already printed what needs to be printed. */
2915 bs
->print_it
= print_it_done
;
2919 else /* must_check_value == 0 */
2921 /* This is a case where some watchpoint(s) triggered, but
2922 not at the address of this watchpoint, or else no
2923 watchpoint triggered after all. So don't print
2924 anything for this watchpoint. */
2925 bs
->print_it
= print_it_noop
;
2932 /* Check conditions (condition proper, frame, thread and ignore count)
2933 of breakpoint referred to by BS. If we should not stop for this
2934 breakpoint, set BS->stop to 0. */
2936 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2938 int thread_id
= pid_to_thread_id (ptid
);
2939 const struct bp_location
*bl
= bs
->breakpoint_at
;
2940 struct breakpoint
*b
= bl
->owner
;
2942 if (frame_id_p (b
->frame_id
)
2943 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2947 int value_is_zero
= 0;
2949 /* If this is a scope breakpoint, mark the associated
2950 watchpoint as triggered so that we will handle the
2951 out-of-scope event. We'll get to the watchpoint next
2953 if (b
->type
== bp_watchpoint_scope
)
2954 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2956 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2958 /* Need to select the frame, with all that implies
2959 so that the conditions will have the right context. */
2960 select_frame (get_current_frame ());
2962 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2963 "Error in testing breakpoint condition:\n",
2965 /* FIXME-someday, should give breakpoint # */
2968 if (bl
->cond
&& value_is_zero
)
2972 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2976 else if (b
->ignore_count
> 0)
2979 annotate_ignore_count_change ();
2981 /* Increase the hit count even though we don't
2989 /* Get a bpstat associated with having just stopped at address
2990 BP_ADDR in thread PTID.
2992 Determine whether we stopped at a breakpoint, etc, or whether we
2993 don't understand this stop. Result is a chain of bpstat's such that:
2995 if we don't understand the stop, the result is a null pointer.
2997 if we understand why we stopped, the result is not null.
2999 Each element of the chain refers to a particular breakpoint or
3000 watchpoint at which we have stopped. (We may have stopped for
3001 several reasons concurrently.)
3003 Each element of the chain has valid next, breakpoint_at,
3004 commands, FIXME??? fields. */
3007 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3009 struct breakpoint
*b
= NULL
;
3010 const struct bp_location
*bl
;
3011 struct bp_location
*loc
;
3012 /* Root of the chain of bpstat's */
3013 struct bpstats root_bs
[1];
3014 /* Pointer to the last thing in the chain currently. */
3015 bpstat bs
= root_bs
;
3018 ALL_BP_LOCATIONS (bl
)
3022 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3025 /* For hardware watchpoints, we look only at the first location.
3026 The watchpoint_check function will work on entire expression,
3027 not the individual locations. For read watchopints, the
3028 watchpoints_triggered function have checked all locations
3031 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3034 if (!bpstat_check_location (bl
, bp_addr
))
3037 /* Come here if it's a watchpoint, or if the break address matches */
3039 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3041 /* Assume we stop. Should we find watchpoint that is not actually
3042 triggered, or if condition of breakpoint is false, we'll reset
3047 bpstat_check_watchpoint (bs
);
3051 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3052 /* We do not stop for these. */
3055 bpstat_check_breakpoint_conditions (bs
, ptid
);
3061 /* We will stop here */
3062 if (b
->disposition
== disp_disable
)
3064 b
->enable_state
= bp_disabled
;
3065 update_global_location_list (0);
3069 bs
->commands
= b
->commands
;
3071 (strcmp ("silent", bs
->commands
->line
) == 0
3072 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3074 bs
->commands
= bs
->commands
->next
;
3077 bs
->commands
= copy_command_lines (bs
->commands
);
3080 /* Print nothing for this entry if we dont stop or if we dont print. */
3081 if (bs
->stop
== 0 || bs
->print
== 0)
3082 bs
->print_it
= print_it_noop
;
3085 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3087 if (loc
->address
== bp_addr
)
3089 bs
= bpstat_alloc (loc
, bs
);
3090 /* For hits of moribund locations, we should just proceed. */
3093 bs
->print_it
= print_it_noop
;
3097 bs
->next
= NULL
; /* Terminate the chain */
3098 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3100 /* If we aren't stopping, the value of some hardware watchpoint may
3101 not have changed, but the intermediate memory locations we are
3102 watching may have. Don't bother if we're stopping; this will get
3104 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3109 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3111 && bs
->breakpoint_at
->owner
3112 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3113 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3114 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3116 /* remove/insert can invalidate bs->breakpoint_at, if this
3117 location is no longer used by the watchpoint. Prevent
3118 further code from trying to use it. */
3119 bs
->breakpoint_at
= NULL
;
3120 remove_breakpoints ();
3121 insert_breakpoints ();
3125 return root_bs
->next
;
3128 /* Tell what to do about this bpstat. */
3130 bpstat_what (bpstat bs
)
3132 /* Classify each bpstat as one of the following. */
3135 /* This bpstat element has no effect on the main_action. */
3138 /* There was a watchpoint, stop but don't print. */
3141 /* There was a watchpoint, stop and print. */
3144 /* There was a breakpoint but we're not stopping. */
3147 /* There was a breakpoint, stop but don't print. */
3150 /* There was a breakpoint, stop and print. */
3153 /* We hit the longjmp breakpoint. */
3156 /* We hit the longjmp_resume breakpoint. */
3159 /* We hit the step_resume breakpoint. */
3162 /* We hit the shared library event breakpoint. */
3165 /* We caught a shared library event. */
3168 /* This is just used to count how many enums there are. */
3172 /* Here is the table which drives this routine. So that we can
3173 format it pretty, we define some abbreviations for the
3174 enum bpstat_what codes. */
3175 #define kc BPSTAT_WHAT_KEEP_CHECKING
3176 #define ss BPSTAT_WHAT_STOP_SILENT
3177 #define sn BPSTAT_WHAT_STOP_NOISY
3178 #define sgl BPSTAT_WHAT_SINGLE
3179 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3180 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3181 #define sr BPSTAT_WHAT_STEP_RESUME
3182 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3183 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3185 /* "Can't happen." Might want to print an error message.
3186 abort() is not out of the question, but chances are GDB is just
3187 a bit confused, not unusable. */
3188 #define err BPSTAT_WHAT_STOP_NOISY
3190 /* Given an old action and a class, come up with a new action. */
3191 /* One interesting property of this table is that wp_silent is the same
3192 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3193 after stopping, the check for whether to step over a breakpoint
3194 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3195 reference to how we stopped. We retain separate wp_silent and
3196 bp_silent codes in case we want to change that someday.
3198 Another possibly interesting property of this table is that
3199 there's a partial ordering, priority-like, of the actions. Once
3200 you've decided that some action is appropriate, you'll never go
3201 back and decide something of a lower priority is better. The
3204 kc < clr sgl shl shlr slr sn sr ss
3205 sgl < shl shlr slr sn sr ss
3206 slr < err shl shlr sn sr ss
3207 clr < err shl shlr sn sr ss
3214 What I think this means is that we don't need a damned table
3215 here. If you just put the rows and columns in the right order,
3216 it'd look awfully regular. We could simply walk the bpstat list
3217 and choose the highest priority action we find, with a little
3218 logic to handle the 'err' cases. */
3220 /* step_resume entries: a step resume breakpoint overrides another
3221 breakpoint of signal handling (see comment in wait_for_inferior
3222 at where we set the step_resume breakpoint). */
3224 static const enum bpstat_what_main_action
3225 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3228 /* kc ss sn sgl slr clr sr shl shlr
3231 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3233 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3235 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3237 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3239 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3241 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3243 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3245 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3247 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3249 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3251 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3265 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3266 struct bpstat_what retval
;
3268 retval
.call_dummy
= 0;
3269 for (; bs
!= NULL
; bs
= bs
->next
)
3271 enum class bs_class
= no_effect
;
3272 if (bs
->breakpoint_at
== NULL
)
3273 /* I suspect this can happen if it was a momentary breakpoint
3274 which has since been deleted. */
3276 if (bs
->breakpoint_at
->owner
== NULL
)
3277 bs_class
= bp_nostop
;
3279 switch (bs
->breakpoint_at
->owner
->type
)
3285 case bp_hardware_breakpoint
:
3291 bs_class
= bp_noisy
;
3293 bs_class
= bp_silent
;
3296 bs_class
= bp_nostop
;
3299 case bp_hardware_watchpoint
:
3300 case bp_read_watchpoint
:
3301 case bp_access_watchpoint
:
3305 bs_class
= wp_noisy
;
3307 bs_class
= wp_silent
;
3310 /* There was a watchpoint, but we're not stopping.
3311 This requires no further action. */
3312 bs_class
= no_effect
;
3315 bs_class
= long_jump
;
3317 case bp_longjmp_resume
:
3318 bs_class
= long_resume
;
3320 case bp_step_resume
:
3323 bs_class
= step_resume
;
3326 /* It is for the wrong frame. */
3327 bs_class
= bp_nostop
;
3329 case bp_watchpoint_scope
:
3330 bs_class
= bp_nostop
;
3332 case bp_shlib_event
:
3333 bs_class
= shlib_event
;
3335 case bp_thread_event
:
3336 case bp_overlay_event
:
3337 bs_class
= bp_nostop
;
3340 case bp_catch_unload
:
3341 /* Only if this catchpoint triggered should we cause the
3342 step-out-of-dld behaviour. Otherwise, we ignore this
3345 bs_class
= catch_shlib_event
;
3347 bs_class
= no_effect
;
3350 case bp_catch_vfork
:
3355 bs_class
= bp_noisy
;
3357 bs_class
= bp_silent
;
3360 /* There was a catchpoint, but we're not stopping.
3361 This requires no further action. */
3362 bs_class
= no_effect
;
3365 /* Make sure the action is stop (silent or noisy),
3366 so infrun.c pops the dummy frame. */
3367 bs_class
= bp_silent
;
3368 retval
.call_dummy
= 1;
3371 current_action
= table
[(int) bs_class
][(int) current_action
];
3373 retval
.main_action
= current_action
;
3377 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3378 without hardware support). This isn't related to a specific bpstat,
3379 just to things like whether watchpoints are set. */
3382 bpstat_should_step (void)
3384 struct breakpoint
*b
;
3386 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3393 /* Given a bpstat that records zero or more triggered eventpoints, this
3394 function returns another bpstat which contains only the catchpoints
3395 on that first list, if any. */
3397 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3399 struct bpstats root_bs
[1];
3400 bpstat bs
= root_bs
;
3401 struct breakpoint
*ep
;
3404 bpstat_clear (cp_list
);
3405 root_bs
->next
= NULL
;
3407 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3409 /* Is this eventpoint a catchpoint? If not, ignore it. */
3410 ep
= ep_list
->breakpoint_at
->owner
;
3413 if ((ep
->type
!= bp_catch_load
) &&
3414 (ep
->type
!= bp_catch_unload
))
3415 /* pai: (temp) ADD fork/vfork here!! */
3418 /* Yes; add it to the list. */
3419 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3424 #if defined(SOLIB_ADD)
3425 /* Also, for each triggered catchpoint, tag it with the name of
3426 the library that caused this trigger. (We copy the name now,
3427 because it's only guaranteed to be available NOW, when the
3428 catchpoint triggers. Clients who may wish to know the name
3429 later must get it from the catchpoint itself.) */
3430 if (ep
->triggered_dll_pathname
!= NULL
)
3431 xfree (ep
->triggered_dll_pathname
);
3432 if (ep
->type
== bp_catch_load
)
3433 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3434 PIDGET (inferior_ptid
));
3436 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3437 PIDGET (inferior_ptid
));
3439 dll_pathname
= NULL
;
3443 ep
->triggered_dll_pathname
= (char *)
3444 xmalloc (strlen (dll_pathname
) + 1);
3445 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3448 ep
->triggered_dll_pathname
= NULL
;
3454 static void print_breakpoint_location (struct breakpoint
*b
,
3455 struct bp_location
*loc
,
3457 struct ui_stream
*stb
)
3462 = find_pc_sect_function (loc
->address
, loc
->section
);
3465 ui_out_text (uiout
, "in ");
3466 ui_out_field_string (uiout
, "func",
3467 SYMBOL_PRINT_NAME (sym
));
3468 ui_out_wrap_hint (uiout
, wrap_indent
);
3469 ui_out_text (uiout
, " at ");
3471 ui_out_field_string (uiout
, "file", b
->source_file
);
3472 ui_out_text (uiout
, ":");
3474 if (ui_out_is_mi_like_p (uiout
))
3476 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3477 char *fullname
= symtab_to_fullname (sal
.symtab
);
3480 ui_out_field_string (uiout
, "fullname", fullname
);
3483 ui_out_field_int (uiout
, "line", b
->line_number
);
3487 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3491 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3492 ui_out_field_stream (uiout
, "at", stb
);
3496 /* Print B to gdb_stdout. */
3498 print_one_breakpoint_location (struct breakpoint
*b
,
3499 struct bp_location
*loc
,
3501 CORE_ADDR
*last_addr
)
3503 struct command_line
*l
;
3505 struct ep_type_description
3510 static struct ep_type_description bptypes
[] =
3512 {bp_none
, "?deleted?"},
3513 {bp_breakpoint
, "breakpoint"},
3514 {bp_hardware_breakpoint
, "hw breakpoint"},
3515 {bp_until
, "until"},
3516 {bp_finish
, "finish"},
3517 {bp_watchpoint
, "watchpoint"},
3518 {bp_hardware_watchpoint
, "hw watchpoint"},
3519 {bp_read_watchpoint
, "read watchpoint"},
3520 {bp_access_watchpoint
, "acc watchpoint"},
3521 {bp_longjmp
, "longjmp"},
3522 {bp_longjmp_resume
, "longjmp resume"},
3523 {bp_step_resume
, "step resume"},
3524 {bp_watchpoint_scope
, "watchpoint scope"},
3525 {bp_call_dummy
, "call dummy"},
3526 {bp_shlib_event
, "shlib events"},
3527 {bp_thread_event
, "thread events"},
3528 {bp_overlay_event
, "overlay events"},
3529 {bp_catch_load
, "catch load"},
3530 {bp_catch_unload
, "catch unload"},
3531 {bp_catch_fork
, "catch fork"},
3532 {bp_catch_vfork
, "catch vfork"},
3533 {bp_catch_exec
, "catch exec"}
3536 static char bpenables
[] = "nynny";
3537 char wrap_indent
[80];
3538 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3539 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3540 struct cleanup
*bkpt_chain
;
3542 int header_of_multiple
= 0;
3543 int part_of_multiple
= (loc
!= NULL
);
3545 gdb_assert (!loc
|| loc_number
!= 0);
3546 /* See comment in print_one_breakpoint concerning
3547 treatment of breakpoints with single disabled
3551 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3552 header_of_multiple
= 1;
3557 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3561 if (part_of_multiple
)
3564 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3565 ui_out_field_string (uiout
, "number", formatted
);
3570 ui_out_field_int (uiout
, "number", b
->number
);
3575 if (part_of_multiple
)
3576 ui_out_field_skip (uiout
, "type");
3579 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3580 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3581 internal_error (__FILE__
, __LINE__
,
3582 _("bptypes table does not describe type #%d."),
3584 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3589 if (part_of_multiple
)
3590 ui_out_field_skip (uiout
, "disp");
3592 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3597 if (part_of_multiple
)
3598 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3600 ui_out_field_fmt (uiout
, "enabled", "%c",
3601 bpenables
[(int) b
->enable_state
]);
3602 ui_out_spaces (uiout
, 2);
3606 strcpy (wrap_indent
, " ");
3609 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3610 strcat (wrap_indent
, " ");
3612 strcat (wrap_indent
, " ");
3615 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3617 /* Although the print_one can possibly print
3618 all locations, calling it here is not likely
3619 to get any nice result. So, make sure there's
3620 just one location. */
3621 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3622 b
->ops
->print_one (b
, last_addr
);
3628 internal_error (__FILE__
, __LINE__
,
3629 _("print_one_breakpoint: bp_none encountered\n"));
3633 case bp_hardware_watchpoint
:
3634 case bp_read_watchpoint
:
3635 case bp_access_watchpoint
:
3636 /* Field 4, the address, is omitted (which makes the columns
3637 not line up too nicely with the headers, but the effect
3638 is relatively readable). */
3640 ui_out_field_skip (uiout
, "addr");
3642 print_expression (b
->exp
, stb
->stream
);
3643 ui_out_field_stream (uiout
, "what", stb
);
3647 case bp_catch_unload
:
3648 /* Field 4, the address, is omitted (which makes the columns
3649 not line up too nicely with the headers, but the effect
3650 is relatively readable). */
3652 ui_out_field_skip (uiout
, "addr");
3654 if (b
->dll_pathname
== NULL
)
3656 ui_out_field_string (uiout
, "what", "<any library>");
3657 ui_out_spaces (uiout
, 1);
3661 ui_out_text (uiout
, "library \"");
3662 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3663 ui_out_text (uiout
, "\" ");
3668 case bp_catch_vfork
:
3669 /* Field 4, the address, is omitted (which makes the columns
3670 not line up too nicely with the headers, but the effect
3671 is relatively readable). */
3673 ui_out_field_skip (uiout
, "addr");
3675 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
3677 ui_out_text (uiout
, "process ");
3678 ui_out_field_int (uiout
, "what",
3679 ptid_get_pid (b
->forked_inferior_pid
));
3680 ui_out_spaces (uiout
, 1);
3685 /* Field 4, the address, is omitted (which makes the columns
3686 not line up too nicely with the headers, but the effect
3687 is relatively readable). */
3689 ui_out_field_skip (uiout
, "addr");
3691 if (b
->exec_pathname
!= NULL
)
3693 ui_out_text (uiout
, "program \"");
3694 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3695 ui_out_text (uiout
, "\" ");
3700 case bp_hardware_breakpoint
:
3704 case bp_longjmp_resume
:
3705 case bp_step_resume
:
3706 case bp_watchpoint_scope
:
3708 case bp_shlib_event
:
3709 case bp_thread_event
:
3710 case bp_overlay_event
:
3714 if (header_of_multiple
)
3715 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3716 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3717 ui_out_field_string (uiout
, "addr", "<PENDING>");
3719 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3722 if (!header_of_multiple
)
3723 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3725 *last_addr
= b
->loc
->address
;
3729 if (!part_of_multiple
&& b
->thread
!= -1)
3731 /* FIXME: This seems to be redundant and lost here; see the
3732 "stop only in" line a little further down. */
3733 ui_out_text (uiout
, " thread ");
3734 ui_out_field_int (uiout
, "thread", b
->thread
);
3737 ui_out_text (uiout
, "\n");
3739 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3742 ui_out_text (uiout
, "\tstop only in stack frame at ");
3743 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3745 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3746 ui_out_text (uiout
, "\n");
3749 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3751 /* We do not print the condition for Ada exception catchpoints
3752 because the condition is an internal implementation detail
3753 that we do not want to expose to the user. */
3755 ui_out_text (uiout
, "\tstop only if ");
3756 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3757 ui_out_text (uiout
, "\n");
3760 if (!part_of_multiple
&& b
->thread
!= -1)
3762 /* FIXME should make an annotation for this */
3763 ui_out_text (uiout
, "\tstop only in thread ");
3764 ui_out_field_int (uiout
, "thread", b
->thread
);
3765 ui_out_text (uiout
, "\n");
3768 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3770 /* FIXME should make an annotation for this */
3771 if (ep_is_catchpoint (b
))
3772 ui_out_text (uiout
, "\tcatchpoint");
3774 ui_out_text (uiout
, "\tbreakpoint");
3775 ui_out_text (uiout
, " already hit ");
3776 ui_out_field_int (uiout
, "times", b
->hit_count
);
3777 if (b
->hit_count
== 1)
3778 ui_out_text (uiout
, " time\n");
3780 ui_out_text (uiout
, " times\n");
3783 /* Output the count also if it is zero, but only if this is
3784 mi. FIXME: Should have a better test for this. */
3785 if (ui_out_is_mi_like_p (uiout
))
3786 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3787 ui_out_field_int (uiout
, "times", b
->hit_count
);
3789 if (!part_of_multiple
&& b
->ignore_count
)
3792 ui_out_text (uiout
, "\tignore next ");
3793 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3794 ui_out_text (uiout
, " hits\n");
3797 if (!part_of_multiple
&& (l
= b
->commands
))
3799 struct cleanup
*script_chain
;
3802 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3803 print_command_lines (uiout
, l
, 4);
3804 do_cleanups (script_chain
);
3807 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3810 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3811 else if (b
->exp_string
)
3812 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3815 do_cleanups (bkpt_chain
);
3816 do_cleanups (old_chain
);
3820 print_one_breakpoint (struct breakpoint
*b
,
3821 CORE_ADDR
*last_addr
)
3823 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3825 /* If this breakpoint has custom print function,
3826 it's already printed. Otherwise, print individual
3827 locations, if any. */
3828 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3830 /* If breakpoint has a single location that is
3831 disabled, we print it as if it had
3832 several locations, since otherwise it's hard to
3833 represent "breakpoint enabled, location disabled"
3835 Note that while hardware watchpoints have
3836 several locations internally, that's no a property
3839 && !is_hardware_watchpoint (b
)
3840 && (b
->loc
->next
|| !b
->loc
->enabled
)
3841 && !ui_out_is_mi_like_p (uiout
))
3843 struct bp_location
*loc
;
3845 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3846 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3852 struct captured_breakpoint_query_args
3858 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3860 struct captured_breakpoint_query_args
*args
= data
;
3861 struct breakpoint
*b
;
3862 CORE_ADDR dummy_addr
= 0;
3865 if (args
->bnum
== b
->number
)
3867 print_one_breakpoint (b
, &dummy_addr
);
3875 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3877 struct captured_breakpoint_query_args args
;
3879 /* For the moment we don't trust print_one_breakpoint() to not throw
3881 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3882 error_message
, RETURN_MASK_ALL
) < 0)
3888 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3889 catchpoints, et.al.). */
3892 user_settable_breakpoint (const struct breakpoint
*b
)
3894 return (b
->type
== bp_breakpoint
3895 || b
->type
== bp_catch_load
3896 || b
->type
== bp_catch_unload
3897 || b
->type
== bp_catch_fork
3898 || b
->type
== bp_catch_vfork
3899 || b
->type
== bp_catch_exec
3900 || b
->type
== bp_hardware_breakpoint
3901 || b
->type
== bp_watchpoint
3902 || b
->type
== bp_read_watchpoint
3903 || b
->type
== bp_access_watchpoint
3904 || b
->type
== bp_hardware_watchpoint
);
3907 /* Print information on user settable breakpoint (watchpoint, etc)
3908 number BNUM. If BNUM is -1 print all user settable breakpoints.
3909 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3912 breakpoint_1 (int bnum
, int allflag
)
3914 struct breakpoint
*b
;
3915 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3916 int nr_printable_breakpoints
;
3917 struct cleanup
*bkpttbl_chain
;
3919 /* Compute the number of rows in the table. */
3920 nr_printable_breakpoints
= 0;
3923 || bnum
== b
->number
)
3925 if (allflag
|| user_settable_breakpoint (b
))
3926 nr_printable_breakpoints
++;
3931 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3935 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3938 if (nr_printable_breakpoints
> 0)
3939 annotate_breakpoints_headers ();
3940 if (nr_printable_breakpoints
> 0)
3942 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3943 if (nr_printable_breakpoints
> 0)
3945 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3946 if (nr_printable_breakpoints
> 0)
3948 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3949 if (nr_printable_breakpoints
> 0)
3951 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3954 if (nr_printable_breakpoints
> 0)
3956 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3957 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3959 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3961 if (nr_printable_breakpoints
> 0)
3963 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3964 ui_out_table_body (uiout
);
3965 if (nr_printable_breakpoints
> 0)
3966 annotate_breakpoints_table ();
3970 || bnum
== b
->number
)
3972 /* We only print out user settable breakpoints unless the
3974 if (allflag
|| user_settable_breakpoint (b
))
3975 print_one_breakpoint (b
, &last_addr
);
3978 do_cleanups (bkpttbl_chain
);
3980 if (nr_printable_breakpoints
== 0)
3983 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3985 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3990 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3991 that a comparison of an unsigned with -1 is always false. */
3992 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3993 set_next_address (last_addr
);
3996 /* FIXME? Should this be moved up so that it is only called when
3997 there have been breakpoints? */
3998 annotate_breakpoints_table_end ();
4002 breakpoints_info (char *bnum_exp
, int from_tty
)
4007 bnum
= parse_and_eval_long (bnum_exp
);
4009 breakpoint_1 (bnum
, 0);
4013 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4018 bnum
= parse_and_eval_long (bnum_exp
);
4020 breakpoint_1 (bnum
, 1);
4024 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4026 struct bp_location
*bl
= b
->loc
;
4027 for (; bl
; bl
= bl
->next
)
4029 if (bl
->address
== pc
4030 && (!overlay_debugging
|| bl
->section
== section
))
4036 /* Print a message describing any breakpoints set at PC. */
4039 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4042 struct breakpoint
*b
;
4045 others
+= breakpoint_has_pc (b
, pc
, section
);
4049 printf_filtered (_("Note: breakpoint "));
4050 else /* if (others == ???) */
4051 printf_filtered (_("Note: breakpoints "));
4053 if (breakpoint_has_pc (b
, pc
, section
))
4056 printf_filtered ("%d", b
->number
);
4057 if (b
->thread
== -1 && thread
!= -1)
4058 printf_filtered (" (all threads)");
4059 else if (b
->thread
!= -1)
4060 printf_filtered (" (thread %d)", b
->thread
);
4061 printf_filtered ("%s%s ",
4062 ((b
->enable_state
== bp_disabled
||
4063 b
->enable_state
== bp_call_disabled
)
4065 : b
->enable_state
== bp_permanent
4069 : ((others
== 1) ? " and" : ""));
4071 printf_filtered (_("also set at pc "));
4072 fputs_filtered (paddress (pc
), gdb_stdout
);
4073 printf_filtered (".\n");
4077 /* Set the default place to put a breakpoint
4078 for the `break' command with no arguments. */
4081 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4084 default_breakpoint_valid
= valid
;
4085 default_breakpoint_address
= addr
;
4086 default_breakpoint_symtab
= symtab
;
4087 default_breakpoint_line
= line
;
4090 /* Return true iff it is meaningful to use the address member of
4091 BPT. For some breakpoint types, the address member is irrelevant
4092 and it makes no sense to attempt to compare it to other addresses
4093 (or use it for any other purpose either).
4095 More specifically, each of the following breakpoint types will always
4096 have a zero valued address and we don't want check_duplicates() to mark
4097 breakpoints of any of these types to be a duplicate of an actual
4098 breakpoint at address zero:
4101 bp_hardware_watchpoint
4103 bp_access_watchpoint
4109 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4111 enum bptype type
= bpt
->type
;
4113 return (type
!= bp_watchpoint
4114 && type
!= bp_hardware_watchpoint
4115 && type
!= bp_read_watchpoint
4116 && type
!= bp_access_watchpoint
4117 && type
!= bp_catch_exec
4118 && type
!= bp_catch_fork
4119 && type
!= bp_catch_vfork
);
4122 /* Rescan breakpoints at the same address and section as BPT,
4123 marking the first one as "first" and any others as "duplicates".
4124 This is so that the bpt instruction is only inserted once.
4125 If we have a permanent breakpoint at the same place as BPT, make
4126 that one the official one, and the rest as duplicates. */
4129 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4131 struct bp_location
*b
;
4133 struct bp_location
*perm_bp
= 0;
4135 ALL_BP_LOCATIONS (b
)
4136 if (b
->owner
->enable_state
!= bp_disabled
4137 && b
->owner
->enable_state
!= bp_call_disabled
4139 && !b
->shlib_disabled
4140 && b
->address
== address
/* address / overlay match */
4141 && (!overlay_debugging
|| b
->section
== section
)
4142 && breakpoint_address_is_meaningful (b
->owner
))
4144 /* Have we found a permanent breakpoint? */
4145 if (b
->owner
->enable_state
== bp_permanent
)
4152 b
->duplicate
= count
> 1;
4155 /* If we found a permanent breakpoint at this address, go over the
4156 list again and declare all the other breakpoints there to be the
4160 perm_bp
->duplicate
= 0;
4162 /* Permanent breakpoint should always be inserted. */
4163 if (! perm_bp
->inserted
)
4164 internal_error (__FILE__
, __LINE__
,
4165 _("allegedly permanent breakpoint is not "
4166 "actually inserted"));
4168 ALL_BP_LOCATIONS (b
)
4171 if (b
->owner
->enable_state
!= bp_disabled
4172 && b
->owner
->enable_state
!= bp_call_disabled
4173 && b
->enabled
&& !b
->shlib_disabled
4174 && b
->address
== address
/* address / overlay match */
4175 && (!overlay_debugging
|| b
->section
== section
)
4176 && breakpoint_address_is_meaningful (b
->owner
))
4179 internal_error (__FILE__
, __LINE__
,
4180 _("another breakpoint was inserted on top of "
4181 "a permanent breakpoint"));
4190 check_duplicates (struct breakpoint
*bpt
)
4192 struct bp_location
*bl
= bpt
->loc
;
4194 if (! breakpoint_address_is_meaningful (bpt
))
4197 for (; bl
; bl
= bl
->next
)
4198 check_duplicates_for (bl
->address
, bl
->section
);
4202 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4203 int bnum
, int have_bnum
)
4208 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4209 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4211 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4212 bnum
, astr1
, astr2
);
4214 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4217 /* Adjust a breakpoint's address to account for architectural constraints
4218 on breakpoint placement. Return the adjusted address. Note: Very
4219 few targets require this kind of adjustment. For most targets,
4220 this function is simply the identity function. */
4223 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4225 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4227 /* Very few targets need any kind of breakpoint adjustment. */
4230 else if (bptype
== bp_watchpoint
4231 || bptype
== bp_hardware_watchpoint
4232 || bptype
== bp_read_watchpoint
4233 || bptype
== bp_access_watchpoint
4234 || bptype
== bp_catch_fork
4235 || bptype
== bp_catch_vfork
4236 || bptype
== bp_catch_exec
)
4238 /* Watchpoints and the various bp_catch_* eventpoints should not
4239 have their addresses modified. */
4244 CORE_ADDR adjusted_bpaddr
;
4246 /* Some targets have architectural constraints on the placement
4247 of breakpoint instructions. Obtain the adjusted address. */
4248 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4251 /* An adjusted breakpoint address can significantly alter
4252 a user's expectations. Print a warning if an adjustment
4254 if (adjusted_bpaddr
!= bpaddr
)
4255 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4257 return adjusted_bpaddr
;
4261 /* Allocate a struct bp_location. */
4263 static struct bp_location
*
4264 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4266 struct bp_location
*loc
, *loc_p
;
4268 loc
= xmalloc (sizeof (struct bp_location
));
4269 memset (loc
, 0, sizeof (*loc
));
4273 loc
->shlib_disabled
= 0;
4282 case bp_longjmp_resume
:
4283 case bp_step_resume
:
4284 case bp_watchpoint_scope
:
4286 case bp_shlib_event
:
4287 case bp_thread_event
:
4288 case bp_overlay_event
:
4290 case bp_catch_unload
:
4291 loc
->loc_type
= bp_loc_software_breakpoint
;
4293 case bp_hardware_breakpoint
:
4294 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4296 case bp_hardware_watchpoint
:
4297 case bp_read_watchpoint
:
4298 case bp_access_watchpoint
:
4299 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4303 case bp_catch_vfork
:
4305 loc
->loc_type
= bp_loc_other
;
4308 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4314 static void free_bp_location (struct bp_location
*loc
)
4319 if (loc
->function_name
)
4320 xfree (loc
->function_name
);
4325 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4326 that has type BPTYPE and has no locations as yet. */
4328 static struct breakpoint
*
4329 set_raw_breakpoint_without_location (enum bptype bptype
)
4331 struct breakpoint
*b
, *b1
;
4333 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4334 memset (b
, 0, sizeof (*b
));
4337 b
->language
= current_language
->la_language
;
4338 b
->input_radix
= input_radix
;
4340 b
->enable_state
= bp_enabled
;
4343 b
->ignore_count
= 0;
4345 b
->frame_id
= null_frame_id
;
4346 b
->dll_pathname
= NULL
;
4347 b
->triggered_dll_pathname
= NULL
;
4348 b
->forked_inferior_pid
= null_ptid
;
4349 b
->exec_pathname
= NULL
;
4351 b
->condition_not_parsed
= 0;
4353 /* Add this breakpoint to the end of the chain
4354 so that a list of breakpoints will come out in order
4355 of increasing numbers. */
4357 b1
= breakpoint_chain
;
4359 breakpoint_chain
= b
;
4369 /* Initialize loc->function_name. */
4371 set_breakpoint_location_function (struct bp_location
*loc
)
4373 if (loc
->owner
->type
== bp_breakpoint
4374 || loc
->owner
->type
== bp_hardware_breakpoint
)
4376 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4378 if (loc
->function_name
)
4379 loc
->function_name
= xstrdup (loc
->function_name
);
4383 /* set_raw_breakpoint is a low level routine for allocating and
4384 partially initializing a breakpoint of type BPTYPE. The newly
4385 created breakpoint's address, section, source file name, and line
4386 number are provided by SAL. The newly created and partially
4387 initialized breakpoint is added to the breakpoint chain and
4388 is also returned as the value of this function.
4390 It is expected that the caller will complete the initialization of
4391 the newly created breakpoint struct as well as output any status
4392 information regarding the creation of a new breakpoint. In
4393 particular, set_raw_breakpoint does NOT set the breakpoint
4394 number! Care should be taken to not allow an error to occur
4395 prior to completing the initialization of the breakpoint. If this
4396 should happen, a bogus breakpoint will be left on the chain. */
4399 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4401 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4402 CORE_ADDR adjusted_address
;
4404 /* Adjust the breakpoint's address prior to allocating a location.
4405 Once we call allocate_bp_location(), that mostly uninitialized
4406 location will be placed on the location chain. Adjustment of the
4407 breakpoint may cause target_read_memory() to be called and we do
4408 not want its scan of the location chain to find a breakpoint and
4409 location that's only been partially initialized. */
4410 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4412 b
->loc
= allocate_bp_location (b
, bptype
);
4413 b
->loc
->requested_address
= sal
.pc
;
4414 b
->loc
->address
= adjusted_address
;
4416 if (sal
.symtab
== NULL
)
4417 b
->source_file
= NULL
;
4419 b
->source_file
= savestring (sal
.symtab
->filename
,
4420 strlen (sal
.symtab
->filename
));
4421 b
->loc
->section
= sal
.section
;
4422 b
->line_number
= sal
.line
;
4424 set_breakpoint_location_function (b
->loc
);
4426 breakpoints_changed ();
4432 /* Note that the breakpoint object B describes a permanent breakpoint
4433 instruction, hard-wired into the inferior's code. */
4435 make_breakpoint_permanent (struct breakpoint
*b
)
4437 struct bp_location
*bl
;
4438 b
->enable_state
= bp_permanent
;
4440 /* By definition, permanent breakpoints are already present in the code.
4441 Mark all locations as inserted. For now, make_breakpoint_permanent
4442 is called in just one place, so it's hard to say if it's reasonable
4443 to have permanent breakpoint with multiple locations or not,
4444 but it's easy to implmement. */
4445 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4449 static struct breakpoint
*
4450 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4452 static int internal_breakpoint_number
= -1;
4453 struct symtab_and_line sal
;
4454 struct breakpoint
*b
;
4456 init_sal (&sal
); /* initialize to zeroes */
4459 sal
.section
= find_pc_overlay (sal
.pc
);
4461 b
= set_raw_breakpoint (sal
, type
);
4462 b
->number
= internal_breakpoint_number
--;
4463 b
->disposition
= disp_donttouch
;
4470 create_longjmp_breakpoint (char *func_name
)
4472 struct breakpoint
*b
;
4473 struct minimal_symbol
*m
;
4475 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4477 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4478 update_global_location_list (1);
4481 /* Call this routine when stepping and nexting to enable a breakpoint
4482 if we do a longjmp(). When we hit that breakpoint, call
4483 set_longjmp_resume_breakpoint() to figure out where we are going. */
4486 set_longjmp_breakpoint (void)
4488 struct breakpoint
*b
;
4490 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4492 create_longjmp_breakpoint ("longjmp");
4493 create_longjmp_breakpoint ("_longjmp");
4494 create_longjmp_breakpoint ("siglongjmp");
4495 create_longjmp_breakpoint ("_siglongjmp");
4499 /* Delete all longjmp breakpoints from THREAD. */
4501 delete_longjmp_breakpoint (int thread
)
4503 struct breakpoint
*b
, *temp
;
4505 ALL_BREAKPOINTS_SAFE (b
, temp
)
4506 if (b
->type
== bp_longjmp
)
4508 if (b
->thread
== thread
)
4509 delete_breakpoint (b
);
4514 create_overlay_event_breakpoint (char *func_name
)
4516 struct breakpoint
*b
;
4517 struct minimal_symbol
*m
;
4519 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4522 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4524 b
->addr_string
= xstrdup (func_name
);
4526 if (overlay_debugging
== ovly_auto
)
4528 b
->enable_state
= bp_enabled
;
4529 overlay_events_enabled
= 1;
4533 b
->enable_state
= bp_disabled
;
4534 overlay_events_enabled
= 0;
4536 update_global_location_list (1);
4540 enable_overlay_breakpoints (void)
4542 struct breakpoint
*b
;
4545 if (b
->type
== bp_overlay_event
)
4547 b
->enable_state
= bp_enabled
;
4548 update_global_location_list (1);
4549 overlay_events_enabled
= 1;
4554 disable_overlay_breakpoints (void)
4556 struct breakpoint
*b
;
4559 if (b
->type
== bp_overlay_event
)
4561 b
->enable_state
= bp_disabled
;
4562 update_global_location_list (0);
4563 overlay_events_enabled
= 0;
4568 create_thread_event_breakpoint (CORE_ADDR address
)
4570 struct breakpoint
*b
;
4572 b
= create_internal_breakpoint (address
, bp_thread_event
);
4574 b
->enable_state
= bp_enabled
;
4575 /* addr_string has to be used or breakpoint_re_set will delete me. */
4576 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4578 update_global_location_list_nothrow (1);
4584 remove_thread_event_breakpoints (void)
4586 struct breakpoint
*b
, *temp
;
4588 ALL_BREAKPOINTS_SAFE (b
, temp
)
4589 if (b
->type
== bp_thread_event
)
4590 delete_breakpoint (b
);
4593 struct captured_parse_breakpoint_args
4596 struct symtabs_and_lines
*sals_p
;
4597 char ***addr_string_p
;
4601 struct lang_and_radix
4609 remove_solib_event_breakpoints (void)
4611 struct breakpoint
*b
, *temp
;
4613 ALL_BREAKPOINTS_SAFE (b
, temp
)
4614 if (b
->type
== bp_shlib_event
)
4615 delete_breakpoint (b
);
4619 create_solib_event_breakpoint (CORE_ADDR address
)
4621 struct breakpoint
*b
;
4623 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4624 update_global_location_list_nothrow (1);
4628 /* Disable any breakpoints that are on code in shared libraries. Only
4629 apply to enabled breakpoints, disabled ones can just stay disabled. */
4632 disable_breakpoints_in_shlibs (void)
4634 struct bp_location
*loc
;
4635 int disabled_shlib_breaks
= 0;
4637 ALL_BP_LOCATIONS (loc
)
4639 struct breakpoint
*b
= loc
->owner
;
4640 /* We apply the check to all breakpoints, including disabled
4641 for those with loc->duplicate set. This is so that when breakpoint
4642 becomes enabled, or the duplicate is removed, gdb will try to insert
4643 all breakpoints. If we don't set shlib_disabled here, we'll try
4644 to insert those breakpoints and fail. */
4645 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4646 && !loc
->shlib_disabled
4648 && PC_SOLIB (loc
->address
)
4650 && solib_address (loc
->address
)
4654 loc
->shlib_disabled
= 1;
4659 /* Disable any breakpoints that are in in an unloaded shared library. Only
4660 apply to enabled breakpoints, disabled ones can just stay disabled. */
4663 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4665 struct bp_location
*loc
;
4666 int disabled_shlib_breaks
= 0;
4668 ALL_BP_LOCATIONS (loc
)
4670 struct breakpoint
*b
= loc
->owner
;
4671 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4672 || loc
->loc_type
== bp_loc_software_breakpoint
)
4673 && !loc
->shlib_disabled
)
4676 char *so_name
= PC_SOLIB (loc
->address
);
4678 char *so_name
= solib_address (loc
->address
);
4680 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4682 loc
->shlib_disabled
= 1;
4683 /* At this point, we cannot rely on remove_breakpoint
4684 succeeding so we must mark the breakpoint as not inserted
4685 to prevent future errors occurring in remove_breakpoints. */
4687 if (!disabled_shlib_breaks
)
4689 target_terminal_ours_for_output ();
4690 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4693 disabled_shlib_breaks
= 1;
4700 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4701 enum bptype bp_kind
)
4703 struct symtab_and_line sal
;
4704 struct breakpoint
*b
;
4705 int thread
= -1; /* All threads. */
4712 b
= set_raw_breakpoint (sal
, bp_kind
);
4713 set_breakpoint_count (breakpoint_count
+ 1);
4714 b
->number
= breakpoint_count
;
4715 b
->cond_string
= (cond_string
== NULL
) ?
4716 NULL
: savestring (cond_string
, strlen (cond_string
));
4718 b
->addr_string
= NULL
;
4719 b
->enable_state
= bp_enabled
;
4720 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4721 b
->forked_inferior_pid
= null_ptid
;
4722 update_global_location_list (1);
4729 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4731 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4735 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4737 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4741 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4743 struct symtab_and_line sal
;
4744 struct breakpoint
*b
;
4745 int thread
= -1; /* All threads. */
4752 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4753 set_breakpoint_count (breakpoint_count
+ 1);
4754 b
->number
= breakpoint_count
;
4755 b
->cond_string
= (cond_string
== NULL
) ?
4756 NULL
: savestring (cond_string
, strlen (cond_string
));
4758 b
->addr_string
= NULL
;
4759 b
->enable_state
= bp_enabled
;
4760 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4761 update_global_location_list (1);
4767 hw_breakpoint_used_count (void)
4769 struct breakpoint
*b
;
4774 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4782 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4784 struct breakpoint
*b
;
4787 *other_type_used
= 0;
4790 if (breakpoint_enabled (b
))
4792 if (b
->type
== type
)
4794 else if ((b
->type
== bp_hardware_watchpoint
||
4795 b
->type
== bp_read_watchpoint
||
4796 b
->type
== bp_access_watchpoint
))
4797 *other_type_used
= 1;
4804 disable_watchpoints_before_interactive_call_start (void)
4806 struct breakpoint
*b
;
4810 if (((b
->type
== bp_watchpoint
)
4811 || (b
->type
== bp_hardware_watchpoint
)
4812 || (b
->type
== bp_read_watchpoint
)
4813 || (b
->type
== bp_access_watchpoint
))
4814 && breakpoint_enabled (b
))
4816 b
->enable_state
= bp_call_disabled
;
4817 update_global_location_list (0);
4823 enable_watchpoints_after_interactive_call_stop (void)
4825 struct breakpoint
*b
;
4829 if (((b
->type
== bp_watchpoint
)
4830 || (b
->type
== bp_hardware_watchpoint
)
4831 || (b
->type
== bp_read_watchpoint
)
4832 || (b
->type
== bp_access_watchpoint
))
4833 && (b
->enable_state
== bp_call_disabled
))
4835 b
->enable_state
= bp_enabled
;
4836 update_global_location_list (1);
4842 /* Set a breakpoint that will evaporate an end of command
4843 at address specified by SAL.
4844 Restrict it to frame FRAME if FRAME is nonzero. */
4847 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4850 struct breakpoint
*b
;
4851 b
= set_raw_breakpoint (sal
, type
);
4852 b
->enable_state
= bp_enabled
;
4853 b
->disposition
= disp_donttouch
;
4854 b
->frame_id
= frame_id
;
4856 /* If we're debugging a multi-threaded program, then we
4857 want momentary breakpoints to be active in only a
4858 single thread of control. */
4859 if (in_thread_list (inferior_ptid
))
4860 b
->thread
= pid_to_thread_id (inferior_ptid
);
4862 update_global_location_list_nothrow (1);
4868 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4870 struct symtab_and_line sal
;
4872 sal
= find_pc_line (pc
, 0);
4874 sal
.section
= find_pc_overlay (pc
);
4875 sal
.explicit_pc
= 1;
4877 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4881 /* Tell the user we have just set a breakpoint B. */
4884 mention (struct breakpoint
*b
)
4887 struct cleanup
*old_chain
, *ui_out_chain
;
4888 struct ui_stream
*stb
;
4890 stb
= ui_out_stream_new (uiout
);
4891 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4893 /* FIXME: This is misplaced; mention() is called by things (like
4894 hitting a watchpoint) other than breakpoint creation. It should
4895 be possible to clean this up and at the same time replace the
4896 random calls to breakpoint_changed with this hook, as has already
4897 been done for deprecated_delete_breakpoint_hook and so on. */
4898 if (deprecated_create_breakpoint_hook
)
4899 deprecated_create_breakpoint_hook (b
);
4900 breakpoint_create_event (b
->number
);
4902 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4903 b
->ops
->print_mention (b
);
4908 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4911 ui_out_text (uiout
, "Watchpoint ");
4912 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4913 ui_out_field_int (uiout
, "number", b
->number
);
4914 ui_out_text (uiout
, ": ");
4915 print_expression (b
->exp
, stb
->stream
);
4916 ui_out_field_stream (uiout
, "exp", stb
);
4917 do_cleanups (ui_out_chain
);
4919 case bp_hardware_watchpoint
:
4920 ui_out_text (uiout
, "Hardware watchpoint ");
4921 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4922 ui_out_field_int (uiout
, "number", b
->number
);
4923 ui_out_text (uiout
, ": ");
4924 print_expression (b
->exp
, stb
->stream
);
4925 ui_out_field_stream (uiout
, "exp", stb
);
4926 do_cleanups (ui_out_chain
);
4928 case bp_read_watchpoint
:
4929 ui_out_text (uiout
, "Hardware read watchpoint ");
4930 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4931 ui_out_field_int (uiout
, "number", b
->number
);
4932 ui_out_text (uiout
, ": ");
4933 print_expression (b
->exp
, stb
->stream
);
4934 ui_out_field_stream (uiout
, "exp", stb
);
4935 do_cleanups (ui_out_chain
);
4937 case bp_access_watchpoint
:
4938 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4939 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4940 ui_out_field_int (uiout
, "number", b
->number
);
4941 ui_out_text (uiout
, ": ");
4942 print_expression (b
->exp
, stb
->stream
);
4943 ui_out_field_stream (uiout
, "exp", stb
);
4944 do_cleanups (ui_out_chain
);
4947 if (ui_out_is_mi_like_p (uiout
))
4952 if (b
->disposition
== disp_del
)
4953 printf_filtered (_("Temporary breakpoint"));
4955 printf_filtered (_("Breakpoint"));
4956 printf_filtered (_(" %d"), b
->number
);
4959 case bp_hardware_breakpoint
:
4960 if (ui_out_is_mi_like_p (uiout
))
4965 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4969 case bp_catch_unload
:
4970 printf_filtered (_("Catchpoint %d (%s %s)"),
4972 (b
->type
== bp_catch_load
) ? "load" : "unload",
4973 (b
->dll_pathname
!= NULL
) ?
4974 b
->dll_pathname
: "<any library>");
4977 case bp_catch_vfork
:
4978 printf_filtered (_("Catchpoint %d (%s)"),
4980 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4983 printf_filtered (_("Catchpoint %d (exec)"),
4990 case bp_longjmp_resume
:
4991 case bp_step_resume
:
4993 case bp_watchpoint_scope
:
4994 case bp_shlib_event
:
4995 case bp_thread_event
:
4996 case bp_overlay_event
:
5002 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5006 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5010 if (addressprint
|| b
->source_file
== NULL
)
5012 printf_filtered (" at ");
5013 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5016 printf_filtered (": file %s, line %d.",
5017 b
->source_file
, b
->line_number
);
5021 struct bp_location
*loc
= b
->loc
;
5023 for (; loc
; loc
= loc
->next
)
5025 printf_filtered (" (%d locations)", n
);
5030 do_cleanups (old_chain
);
5031 if (ui_out_is_mi_like_p (uiout
))
5033 printf_filtered ("\n");
5037 static struct bp_location
*
5038 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5039 const struct symtab_and_line
*sal
)
5041 struct bp_location
*loc
, **tmp
;
5043 loc
= allocate_bp_location (b
, bptype
);
5044 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5047 loc
->requested_address
= sal
->pc
;
5048 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5050 loc
->section
= sal
->section
;
5052 set_breakpoint_location_function (loc
);
5056 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5057 as textual description of the location, and COND_STRING
5058 as condition expression. */
5061 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5063 enum bptype type
, enum bpdisp disposition
,
5064 int thread
, int ignore_count
,
5065 struct breakpoint_ops
*ops
, int from_tty
)
5067 struct breakpoint
*b
= NULL
;
5070 if (type
== bp_hardware_breakpoint
)
5072 int i
= hw_breakpoint_used_count ();
5073 int target_resources_ok
=
5074 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5076 if (target_resources_ok
== 0)
5077 error (_("No hardware breakpoint support in the target."));
5078 else if (target_resources_ok
< 0)
5079 error (_("Hardware breakpoints used exceeds limit."));
5082 for (i
= 0; i
< sals
.nelts
; ++i
)
5084 struct symtab_and_line sal
= sals
.sals
[i
];
5085 struct bp_location
*loc
;
5088 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5092 b
= set_raw_breakpoint (sal
, type
);
5093 set_breakpoint_count (breakpoint_count
+ 1);
5094 b
->number
= breakpoint_count
;
5097 b
->cond_string
= cond_string
;
5098 b
->ignore_count
= ignore_count
;
5099 b
->enable_state
= bp_enabled
;
5100 b
->disposition
= disposition
;
5106 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5111 char *arg
= b
->cond_string
;
5112 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5114 error (_("Garbage %s follows condition"), arg
);
5119 b
->addr_string
= addr_string
;
5121 /* addr_string has to be used or breakpoint_re_set will delete
5123 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5129 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5130 elements to fill the void space. */
5131 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5133 int i
= index_to_remove
+1;
5134 int last_index
= sal
->nelts
-1;
5136 for (;i
<= last_index
; ++i
)
5137 sal
->sals
[i
-1] = sal
->sals
[i
];
5142 /* If appropriate, obtains all sals that correspond
5143 to the same file and line as SAL. This is done
5144 only if SAL does not have explicit PC and has
5145 line and file information. If we got just a single
5146 expanded sal, return the original.
5148 Otherwise, if SAL.explicit_line is not set, filter out
5149 all sals for which the name of enclosing function
5150 is different from SAL. This makes sure that if we have
5151 breakpoint originally set in template instantiation, say
5152 foo<int>(), we won't expand SAL to locations at the same
5153 line in all existing instantiations of 'foo'.
5156 struct symtabs_and_lines
5157 expand_line_sal_maybe (struct symtab_and_line sal
)
5159 struct symtabs_and_lines expanded
;
5160 CORE_ADDR original_pc
= sal
.pc
;
5161 char *original_function
= NULL
;
5165 /* If we have explicit pc, don't expand.
5166 If we have no line number, we can't expand. */
5167 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5170 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5171 expanded
.sals
[0] = sal
;
5176 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5178 expanded
= expand_line_sal (sal
);
5179 if (expanded
.nelts
== 1)
5181 /* We had one sal, we got one sal. Without futher
5182 processing, just return the original sal. */
5183 xfree (expanded
.sals
);
5185 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5186 sal
.pc
= original_pc
;
5187 expanded
.sals
[0] = sal
;
5191 if (!sal
.explicit_line
)
5193 CORE_ADDR func_addr
, func_end
;
5194 for (i
= 0; i
< expanded
.nelts
; ++i
)
5196 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5197 char *this_function
;
5198 if (find_pc_partial_function (pc
, &this_function
,
5199 &func_addr
, &func_end
))
5201 if (this_function
&&
5202 strcmp (this_function
, original_function
) != 0)
5204 remove_sal (&expanded
, i
);
5207 else if (func_addr
== pc
)
5209 /* We're at beginning of a function, and should
5211 struct symbol
*sym
= find_pc_function (pc
);
5213 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5216 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5223 if (expanded
.nelts
<= 1)
5225 /* This is un ugly workaround. If we get zero
5226 expanded sals then something is really wrong.
5227 Fix that by returnign the original sal. */
5228 xfree (expanded
.sals
);
5230 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5231 sal
.pc
= original_pc
;
5232 expanded
.sals
[0] = sal
;
5239 for (i
= 0; i
< expanded
.nelts
; ++i
)
5240 if (expanded
.sals
[i
].pc
== original_pc
)
5251 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5252 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5253 value. COND_STRING, if not NULL, specified the condition to be
5254 used for all breakpoints. Essentially the only case where
5255 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5256 function. In that case, it's still not possible to specify
5257 separate conditions for different overloaded functions, so
5258 we take just a single condition string.
5260 NOTE: If the function succeeds, the caller is expected to cleanup
5261 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5262 array contents). If the function fails (error() is called), the
5263 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5264 COND and SALS arrays and each of those arrays contents. */
5267 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5269 enum bptype type
, enum bpdisp disposition
,
5270 int thread
, int ignore_count
,
5271 struct breakpoint_ops
*ops
, int from_tty
)
5274 for (i
= 0; i
< sals
.nelts
; ++i
)
5276 struct symtabs_and_lines expanded
=
5277 expand_line_sal_maybe (sals
.sals
[i
]);
5279 create_breakpoint (expanded
, addr_string
[i
],
5280 cond_string
, type
, disposition
,
5281 thread
, ignore_count
, ops
, from_tty
);
5284 update_global_location_list (1);
5287 /* Parse ARG which is assumed to be a SAL specification possibly
5288 followed by conditionals. On return, SALS contains an array of SAL
5289 addresses found. ADDR_STRING contains a vector of (canonical)
5290 address strings. ARG points to the end of the SAL. */
5293 parse_breakpoint_sals (char **address
,
5294 struct symtabs_and_lines
*sals
,
5295 char ***addr_string
,
5298 char *addr_start
= *address
;
5299 *addr_string
= NULL
;
5300 /* If no arg given, or if first arg is 'if ', use the default
5302 if ((*address
) == NULL
5303 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5305 if (default_breakpoint_valid
)
5307 struct symtab_and_line sal
;
5308 init_sal (&sal
); /* initialize to zeroes */
5309 sals
->sals
= (struct symtab_and_line
*)
5310 xmalloc (sizeof (struct symtab_and_line
));
5311 sal
.pc
= default_breakpoint_address
;
5312 sal
.line
= default_breakpoint_line
;
5313 sal
.symtab
= default_breakpoint_symtab
;
5314 sal
.section
= find_pc_overlay (sal
.pc
);
5315 sals
->sals
[0] = sal
;
5319 error (_("No default breakpoint address now."));
5323 /* Force almost all breakpoints to be in terms of the
5324 current_source_symtab (which is decode_line_1's default). This
5325 should produce the results we want almost all of the time while
5326 leaving default_breakpoint_* alone.
5327 ObjC: However, don't match an Objective-C method name which
5328 may have a '+' or '-' succeeded by a '[' */
5330 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5332 if (default_breakpoint_valid
5334 || ((strchr ("+-", (*address
)[0]) != NULL
)
5335 && ((*address
)[1] != '['))))
5336 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5337 default_breakpoint_line
, addr_string
,
5340 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5341 addr_string
, not_found_ptr
);
5343 /* For any SAL that didn't have a canonical string, fill one in. */
5344 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5345 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5346 if (addr_start
!= (*address
))
5349 for (i
= 0; i
< sals
->nelts
; i
++)
5351 /* Add the string if not present. */
5352 if ((*addr_string
)[i
] == NULL
)
5353 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5359 /* Convert each SAL into a real PC. Verify that the PC can be
5360 inserted as a breakpoint. If it can't throw an error. */
5363 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5367 for (i
= 0; i
< sals
->nelts
; i
++)
5368 resolve_sal_pc (&sals
->sals
[i
]);
5372 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5374 struct captured_parse_breakpoint_args
*args
= data
;
5376 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5377 args
->not_found_ptr
);
5380 /* Given TOK, a string specification of condition and thread, as
5381 accepted by the 'break' command, extract the condition
5382 string and thread number and set *COND_STRING and *THREAD.
5383 PC identifies the context at which the condition should be parsed.
5384 If no condition is found, *COND_STRING is set to NULL.
5385 If no thread is found, *THREAD is set to -1. */
5387 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5388 char **cond_string
, int *thread
)
5390 *cond_string
= NULL
;
5396 char *cond_start
= NULL
;
5397 char *cond_end
= NULL
;
5398 while (*tok
== ' ' || *tok
== '\t')
5403 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5406 toklen
= end_tok
- tok
;
5408 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5410 tok
= cond_start
= end_tok
+ 1;
5411 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5413 *cond_string
= savestring (cond_start
,
5414 cond_end
- cond_start
);
5416 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5422 *thread
= strtol (tok
, &tok
, 0);
5424 error (_("Junk after thread keyword."));
5425 if (!valid_thread_id (*thread
))
5426 error (_("Unknown thread %d."), *thread
);
5429 error (_("Junk at end of arguments."));
5433 /* Set a breakpoint. This function is shared between
5434 CLI and MI functions for setting a breakpoint.
5435 This function has two major modes of operations,
5436 selected by the PARSE_CONDITION_AND_THREAD parameter.
5437 If non-zero, the function will parse arg, extracting
5438 breakpoint location, address and thread. Otherwise,
5439 ARG is just the location of breakpoint, with condition
5440 and thread specified by the COND_STRING and THREAD
5444 break_command_really (char *arg
, char *cond_string
, int thread
,
5445 int parse_condition_and_thread
,
5446 int tempflag
, int hardwareflag
,
5448 enum auto_boolean pending_break_support
,
5449 struct breakpoint_ops
*ops
,
5452 struct gdb_exception e
;
5453 struct symtabs_and_lines sals
;
5454 struct symtab_and_line pending_sal
;
5457 char *addr_start
= arg
;
5459 struct cleanup
*old_chain
;
5460 struct cleanup
*breakpoint_chain
= NULL
;
5461 struct captured_parse_breakpoint_args parse_args
;
5470 parse_args
.arg_p
= &arg
;
5471 parse_args
.sals_p
= &sals
;
5472 parse_args
.addr_string_p
= &addr_string
;
5473 parse_args
.not_found_ptr
= ¬_found
;
5475 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5476 &parse_args
, RETURN_MASK_ALL
);
5478 /* If caller is interested in rc value from parse, set value. */
5482 throw_exception (e
);
5486 case NOT_FOUND_ERROR
:
5488 /* If pending breakpoint support is turned off, throw
5491 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5492 throw_exception (e
);
5494 exception_print (gdb_stderr
, e
);
5496 /* If pending breakpoint support is auto query and the user
5497 selects no, then simply return the error code. */
5498 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5499 !nquery ("Make breakpoint pending on future shared library load? "))
5502 /* At this point, either the user was queried about setting
5503 a pending breakpoint and selected yes, or pending
5504 breakpoint behavior is on and thus a pending breakpoint
5505 is defaulted on behalf of the user. */
5506 copy_arg
= xstrdup (addr_start
);
5507 addr_string
= ©_arg
;
5509 sals
.sals
= &pending_sal
;
5514 throw_exception (e
);
5521 /* Create a chain of things that always need to be cleaned up. */
5522 old_chain
= make_cleanup (null_cleanup
, 0);
5526 /* Make sure that all storage allocated to SALS gets freed. */
5527 make_cleanup (xfree
, sals
.sals
);
5529 /* Cleanup the addr_string array but not its contents. */
5530 make_cleanup (xfree
, addr_string
);
5533 /* ----------------------------- SNIP -----------------------------
5534 Anything added to the cleanup chain beyond this point is assumed
5535 to be part of a breakpoint. If the breakpoint create succeeds
5536 then the memory is not reclaimed. */
5537 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5539 /* Mark the contents of the addr_string for cleanup. These go on
5540 the breakpoint_chain and only occure if the breakpoint create
5542 for (i
= 0; i
< sals
.nelts
; i
++)
5544 if (addr_string
[i
] != NULL
)
5545 make_cleanup (xfree
, addr_string
[i
]);
5548 /* Resolve all line numbers to PC's and verify that the addresses
5549 are ok for the target. */
5551 breakpoint_sals_to_pc (&sals
, addr_start
);
5553 /* Verify that condition can be parsed, before setting any
5554 breakpoints. Allocate a separate condition expression for each
5558 if (parse_condition_and_thread
)
5560 /* Here we only parse 'arg' to separate condition
5561 from thread number, so parsing in context of first
5562 sal is OK. When setting the breakpoint we'll
5563 re-parse it in context of each sal. */
5566 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5568 make_cleanup (xfree
, cond_string
);
5572 /* Create a private copy of condition string. */
5575 cond_string
= xstrdup (cond_string
);
5576 make_cleanup (xfree
, cond_string
);
5579 create_breakpoints (sals
, addr_string
, cond_string
,
5580 hardwareflag
? bp_hardware_breakpoint
5582 tempflag
? disp_del
: disp_donttouch
,
5583 thread
, ignore_count
, ops
, from_tty
);
5587 struct symtab_and_line sal
= {0};
5588 struct breakpoint
*b
;
5590 make_cleanup (xfree
, copy_arg
);
5592 b
= set_raw_breakpoint_without_location (hardwareflag
5593 ? bp_hardware_breakpoint
5595 set_breakpoint_count (breakpoint_count
+ 1);
5596 b
->number
= breakpoint_count
;
5598 b
->addr_string
= addr_string
[0];
5599 b
->cond_string
= NULL
;
5600 b
->ignore_count
= ignore_count
;
5601 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5602 b
->condition_not_parsed
= 1;
5605 update_global_location_list (1);
5610 warning (_("Multiple breakpoints were set.\n"
5611 "Use the \"delete\" command to delete unwanted breakpoints."));
5612 /* That's it. Discard the cleanups for data inserted into the
5614 discard_cleanups (breakpoint_chain
);
5615 /* But cleanup everything else. */
5616 do_cleanups (old_chain
);
5619 /* Set a breakpoint.
5620 ARG is a string describing breakpoint address,
5621 condition, and thread.
5622 FLAG specifies if a breakpoint is hardware on,
5623 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5627 break_command_1 (char *arg
, int flag
, int from_tty
)
5629 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5630 int tempflag
= flag
& BP_TEMPFLAG
;
5632 break_command_really (arg
,
5633 NULL
, 0, 1 /* parse arg */,
5634 tempflag
, hardwareflag
,
5635 0 /* Ignore count */,
5636 pending_break_support
,
5637 NULL
/* breakpoint_ops */,
5643 set_breakpoint (char *address
, char *condition
,
5644 int hardwareflag
, int tempflag
,
5645 int thread
, int ignore_count
,
5648 break_command_really (address
, condition
, thread
,
5649 0 /* condition and thread are valid. */,
5650 tempflag
, hardwareflag
,
5653 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5657 /* Adjust SAL to the first instruction past the function prologue.
5658 The end of the prologue is determined using the line table from
5659 the debugging information.
5661 If SAL is already past the prologue, then do nothing. */
5664 skip_prologue_sal (struct symtab_and_line
*sal
)
5666 struct symbol
*sym
= find_pc_function (sal
->pc
);
5667 struct symtab_and_line start_sal
;
5672 start_sal
= find_function_start_sal (sym
, 1);
5673 if (sal
->pc
< start_sal
.pc
)
5677 /* Helper function for break_command_1 and disassemble_command. */
5680 resolve_sal_pc (struct symtab_and_line
*sal
)
5684 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5686 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5687 error (_("No line %d in file \"%s\"."),
5688 sal
->line
, sal
->symtab
->filename
);
5691 /* If this SAL corresponds to a breakpoint inserted using
5692 a line number, then skip the function prologue if necessary. */
5693 if (sal
->explicit_line
)
5694 skip_prologue_sal (sal
);
5697 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5699 struct blockvector
*bv
;
5703 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5706 sym
= block_function (b
);
5709 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5710 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5714 /* It really is worthwhile to have the section, so we'll just
5715 have to look harder. This case can be executed if we have
5716 line numbers but no functions (as can happen in assembly
5719 struct minimal_symbol
*msym
;
5721 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5723 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5730 break_command (char *arg
, int from_tty
)
5732 break_command_1 (arg
, 0, from_tty
);
5736 tbreak_command (char *arg
, int from_tty
)
5738 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5742 hbreak_command (char *arg
, int from_tty
)
5744 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5748 thbreak_command (char *arg
, int from_tty
)
5750 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5754 stop_command (char *arg
, int from_tty
)
5756 printf_filtered (_("Specify the type of breakpoint to set.\n\
5757 Usage: stop in <function | address>\n\
5758 stop at <line>\n"));
5762 stopin_command (char *arg
, int from_tty
)
5766 if (arg
== (char *) NULL
)
5768 else if (*arg
!= '*')
5773 /* look for a ':'. If this is a line number specification, then
5774 say it is bad, otherwise, it should be an address or
5775 function/method name */
5776 while (*argptr
&& !hasColon
)
5778 hasColon
= (*argptr
== ':');
5783 badInput
= (*argptr
!= ':'); /* Not a class::method */
5785 badInput
= isdigit (*arg
); /* a simple line number */
5789 printf_filtered (_("Usage: stop in <function | address>\n"));
5791 break_command_1 (arg
, 0, from_tty
);
5795 stopat_command (char *arg
, int from_tty
)
5799 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5806 /* look for a ':'. If there is a '::' then get out, otherwise
5807 it is probably a line number. */
5808 while (*argptr
&& !hasColon
)
5810 hasColon
= (*argptr
== ':');
5815 badInput
= (*argptr
== ':'); /* we have class::method */
5817 badInput
= !isdigit (*arg
); /* not a line number */
5821 printf_filtered (_("Usage: stop at <line>\n"));
5823 break_command_1 (arg
, 0, from_tty
);
5826 /* accessflag: hw_write: watch write,
5827 hw_read: watch read,
5828 hw_access: watch access (read or write) */
5830 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5832 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5833 struct symtab_and_line sal
;
5834 struct expression
*exp
;
5835 struct block
*exp_valid_block
;
5836 struct value
*val
, *mark
;
5837 struct frame_info
*frame
;
5838 struct frame_info
*prev_frame
= NULL
;
5839 char *exp_start
= NULL
;
5840 char *exp_end
= NULL
;
5841 char *tok
, *id_tok_start
, *end_tok
;
5843 char *cond_start
= NULL
;
5844 char *cond_end
= NULL
;
5845 struct expression
*cond
= NULL
;
5846 int i
, other_type_used
, target_resources_ok
= 0;
5847 enum bptype bp_type
;
5851 init_sal (&sal
); /* initialize to zeroes */
5853 /* Make sure that we actually have parameters to parse. */
5854 if (arg
!= NULL
&& arg
[0] != '\0')
5856 toklen
= strlen (arg
); /* Size of argument list. */
5858 /* Points tok to the end of the argument list. */
5859 tok
= arg
+ toklen
- 1;
5861 /* Go backwards in the parameters list. Skip the last parameter.
5862 If we're expecting a 'thread <thread_num>' parameter, this should
5863 be the thread identifier. */
5864 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5866 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5869 /* Points end_tok to the beginning of the last token. */
5870 id_tok_start
= tok
+ 1;
5872 /* Go backwards in the parameters list. Skip one more parameter.
5873 If we're expecting a 'thread <thread_num>' parameter, we should
5874 reach a "thread" token. */
5875 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5880 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5883 /* Move the pointer forward to skip the whitespace and
5884 calculate the length of the token. */
5886 toklen
= end_tok
- tok
;
5888 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5890 /* At this point we've found a "thread" token, which means
5891 the user is trying to set a watchpoint that triggers
5892 only in a specific thread. */
5895 /* Extract the thread ID from the next token. */
5896 thread
= strtol (id_tok_start
, &endp
, 0);
5898 /* Check if the user provided a valid numeric value for the
5900 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5901 error (_("Invalid thread ID specification %s."), id_tok_start
);
5903 /* Check if the thread actually exists. */
5904 if (!valid_thread_id (thread
))
5905 error (_("Unknown thread %d."), thread
);
5907 /* Truncate the string and get rid of the thread <thread_num>
5908 parameter before the parameter list is parsed by the
5909 evaluate_expression() function. */
5914 /* Parse the rest of the arguments. */
5915 innermost_block
= NULL
;
5917 exp
= parse_exp_1 (&arg
, 0, 0);
5919 exp_valid_block
= innermost_block
;
5920 mark
= value_mark ();
5921 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5923 release_value (val
);
5926 while (*tok
== ' ' || *tok
== '\t')
5930 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5933 toklen
= end_tok
- tok
;
5934 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5936 tok
= cond_start
= end_tok
+ 1;
5937 cond
= parse_exp_1 (&tok
, 0, 0);
5941 error (_("Junk at end of command."));
5943 if (accessflag
== hw_read
)
5944 bp_type
= bp_read_watchpoint
;
5945 else if (accessflag
== hw_access
)
5946 bp_type
= bp_access_watchpoint
;
5948 bp_type
= bp_hardware_watchpoint
;
5950 mem_cnt
= can_use_hardware_watchpoint (val
);
5951 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5952 error (_("Expression cannot be implemented with read/access watchpoint."));
5955 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5956 target_resources_ok
=
5957 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5959 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5960 error (_("Target does not support this type of hardware watchpoint."));
5962 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5963 error (_("Target can only support one kind of HW watchpoint at a time."));
5966 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5967 watchpoint could not be set. */
5968 if (!mem_cnt
|| target_resources_ok
<= 0)
5969 bp_type
= bp_watchpoint
;
5971 frame
= block_innermost_frame (exp_valid_block
);
5973 prev_frame
= get_prev_frame (frame
);
5977 /* If the expression is "local", then set up a "watchpoint scope"
5978 breakpoint at the point where we've left the scope of the watchpoint
5979 expression. Create the scope breakpoint before the watchpoint, so
5980 that we will encounter it first in bpstat_stop_status. */
5981 if (innermost_block
&& prev_frame
)
5983 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5984 bp_watchpoint_scope
);
5986 scope_breakpoint
->enable_state
= bp_enabled
;
5988 /* Automatically delete the breakpoint when it hits. */
5989 scope_breakpoint
->disposition
= disp_del
;
5991 /* Only break in the proper frame (help with recursion). */
5992 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5994 /* Set the address at which we will stop. */
5995 scope_breakpoint
->loc
->requested_address
5996 = get_frame_pc (prev_frame
);
5997 scope_breakpoint
->loc
->address
5998 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5999 scope_breakpoint
->type
);
6002 /* Now set up the breakpoint. */
6003 b
= set_raw_breakpoint (sal
, bp_type
);
6004 set_breakpoint_count (breakpoint_count
+ 1);
6005 b
->number
= breakpoint_count
;
6007 b
->disposition
= disp_donttouch
;
6009 b
->exp_valid_block
= exp_valid_block
;
6010 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6013 b
->loc
->cond
= cond
;
6015 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6020 b
->watchpoint_frame
= get_frame_id (frame
);
6022 b
->watchpoint_frame
= null_frame_id
;
6024 if (scope_breakpoint
!= NULL
)
6026 /* The scope breakpoint is related to the watchpoint. We will
6027 need to act on them together. */
6028 b
->related_breakpoint
= scope_breakpoint
;
6029 scope_breakpoint
->related_breakpoint
= b
;
6032 value_free_to_mark (mark
);
6034 update_global_location_list (1);
6037 /* Return count of locations need to be watched and can be handled
6038 in hardware. If the watchpoint can not be handled
6039 in hardware return zero. */
6042 can_use_hardware_watchpoint (struct value
*v
)
6044 int found_memory_cnt
= 0;
6045 struct value
*head
= v
;
6047 /* Did the user specifically forbid us to use hardware watchpoints? */
6048 if (!can_use_hw_watchpoints
)
6051 /* Make sure that the value of the expression depends only upon
6052 memory contents, and values computed from them within GDB. If we
6053 find any register references or function calls, we can't use a
6054 hardware watchpoint.
6056 The idea here is that evaluating an expression generates a series
6057 of values, one holding the value of every subexpression. (The
6058 expression a*b+c has five subexpressions: a, b, a*b, c, and
6059 a*b+c.) GDB's values hold almost enough information to establish
6060 the criteria given above --- they identify memory lvalues,
6061 register lvalues, computed values, etcetera. So we can evaluate
6062 the expression, and then scan the chain of values that leaves
6063 behind to decide whether we can detect any possible change to the
6064 expression's final value using only hardware watchpoints.
6066 However, I don't think that the values returned by inferior
6067 function calls are special in any way. So this function may not
6068 notice that an expression involving an inferior function call
6069 can't be watched with hardware watchpoints. FIXME. */
6070 for (; v
; v
= value_next (v
))
6072 if (VALUE_LVAL (v
) == lval_memory
)
6075 /* A lazy memory lvalue is one that GDB never needed to fetch;
6076 we either just used its address (e.g., `a' in `a.b') or
6077 we never needed it at all (e.g., `a' in `a,b'). */
6081 /* Ahh, memory we actually used! Check if we can cover
6082 it with hardware watchpoints. */
6083 struct type
*vtype
= check_typedef (value_type (v
));
6085 /* We only watch structs and arrays if user asked for it
6086 explicitly, never if they just happen to appear in a
6087 middle of some value chain. */
6089 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6090 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6092 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6093 int len
= TYPE_LENGTH (value_type (v
));
6095 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6102 else if (VALUE_LVAL (v
) != not_lval
6103 && deprecated_value_modifiable (v
) == 0)
6104 return 0; /* ??? What does this represent? */
6105 else if (VALUE_LVAL (v
) == lval_register
)
6106 return 0; /* cannot watch a register with a HW watchpoint */
6109 /* The expression itself looks suitable for using a hardware
6110 watchpoint, but give the target machine a chance to reject it. */
6111 return found_memory_cnt
;
6115 watch_command_wrapper (char *arg
, int from_tty
)
6117 watch_command (arg
, from_tty
);
6121 watch_command (char *arg
, int from_tty
)
6123 watch_command_1 (arg
, hw_write
, from_tty
);
6127 rwatch_command_wrapper (char *arg
, int from_tty
)
6129 rwatch_command (arg
, from_tty
);
6133 rwatch_command (char *arg
, int from_tty
)
6135 watch_command_1 (arg
, hw_read
, from_tty
);
6139 awatch_command_wrapper (char *arg
, int from_tty
)
6141 awatch_command (arg
, from_tty
);
6145 awatch_command (char *arg
, int from_tty
)
6147 watch_command_1 (arg
, hw_access
, from_tty
);
6151 /* Helper routines for the until_command routine in infcmd.c. Here
6152 because it uses the mechanisms of breakpoints. */
6154 /* This function is called by fetch_inferior_event via the
6155 cmd_continuation pointer, to complete the until command. It takes
6156 care of cleaning up the temporary breakpoints set up by the until
6159 until_break_command_continuation (struct continuation_arg
*arg
, int error
)
6161 delete_breakpoint ((struct breakpoint
*)(arg
->data
.pointer
));
6163 delete_breakpoint ((struct breakpoint
*)(arg
->next
->data
.pointer
));
6167 until_break_command (char *arg
, int from_tty
, int anywhere
)
6169 struct symtabs_and_lines sals
;
6170 struct symtab_and_line sal
;
6171 struct frame_info
*frame
= get_selected_frame (NULL
);
6172 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6173 struct breakpoint
*breakpoint
;
6174 struct breakpoint
*breakpoint2
= NULL
;
6175 struct cleanup
*old_chain
;
6176 struct continuation_arg
*arg1
;
6177 struct continuation_arg
*arg2
;
6180 clear_proceed_status ();
6182 /* Set a breakpoint where the user wants it and at return from
6185 if (default_breakpoint_valid
)
6186 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6187 default_breakpoint_line
, (char ***) NULL
, NULL
);
6189 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6190 0, (char ***) NULL
, NULL
);
6192 if (sals
.nelts
!= 1)
6193 error (_("Couldn't get information on specified line."));
6196 xfree (sals
.sals
); /* malloc'd, so freed */
6199 error (_("Junk at end of arguments."));
6201 resolve_sal_pc (&sal
);
6204 /* If the user told us to continue until a specified location,
6205 we don't specify a frame at which we need to stop. */
6206 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6208 /* Otherwise, specify the current frame, because we want to stop only
6209 at the very same frame. */
6210 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6213 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6215 /* Keep within the current frame, or in frames called by the current
6219 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6220 sal
.pc
= get_frame_pc (prev_frame
);
6221 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6223 make_cleanup_delete_breakpoint (breakpoint2
);
6226 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6228 /* If we are running asynchronously, and proceed call above has actually
6229 managed to start the target, arrange for breakpoints to be
6230 deleted when the target stops. Otherwise, we're already stopped and
6231 delete breakpoints via cleanup chain. */
6233 if (target_can_async_p () && is_running (inferior_ptid
))
6236 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6238 arg1
->data
.pointer
= breakpoint
;
6242 arg2
= (struct continuation_arg
*)
6243 xmalloc ( sizeof (struct continuation_arg
));
6245 arg2
->data
.pointer
= breakpoint2
;
6249 discard_cleanups (old_chain
);
6250 add_continuation (until_break_command_continuation
, arg1
);
6253 do_cleanups (old_chain
);
6257 ep_skip_leading_whitespace (char **s
)
6259 if ((s
== NULL
) || (*s
== NULL
))
6261 while (isspace (**s
))
6265 /* This function examines a string, and attempts to find a token
6266 that might be an event name in the leading characters. If a
6267 possible match is found, a pointer to the last character of
6268 the token is returned. Else, NULL is returned. */
6271 ep_find_event_name_end (char *arg
)
6274 char *event_name_end
= NULL
;
6276 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6280 /* We break out of the loop when we find a token delimiter.
6281 Basically, we're looking for alphanumerics and underscores;
6282 anything else delimites the token. */
6285 if (!isalnum (*s
) && (*s
!= '_'))
6291 return event_name_end
;
6295 /* This function attempts to parse an optional "if <cond>" clause
6296 from the arg string. If one is not found, it returns NULL.
6298 Else, it returns a pointer to the condition string. (It does not
6299 attempt to evaluate the string against a particular block.) And,
6300 it updates arg to point to the first character following the parsed
6301 if clause in the arg string. */
6304 ep_parse_optional_if_clause (char **arg
)
6308 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6311 /* Skip the "if" keyword. */
6314 /* Skip any extra leading whitespace, and record the start of the
6315 condition string. */
6316 ep_skip_leading_whitespace (arg
);
6319 /* Assume that the condition occupies the remainder of the arg string. */
6320 (*arg
) += strlen (cond_string
);
6325 /* This function attempts to parse an optional filename from the arg
6326 string. If one is not found, it returns NULL.
6328 Else, it returns a pointer to the parsed filename. (This function
6329 makes no attempt to verify that a file of that name exists, or is
6330 accessible.) And, it updates arg to point to the first character
6331 following the parsed filename in the arg string.
6333 Note that clients needing to preserve the returned filename for
6334 future access should copy it to their own buffers. */
6336 ep_parse_optional_filename (char **arg
)
6338 static char filename
[1024];
6343 if ((*arg_p
== '\0') || isspace (*arg_p
))
6361 /* Commands to deal with catching events, such as signals, exceptions,
6362 process start/exit, etc. */
6366 catch_fork
, catch_vfork
6371 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6374 char *cond_string
= NULL
;
6376 ep_skip_leading_whitespace (&arg
);
6378 /* The allowed syntax is:
6380 catch [v]fork if <cond>
6382 First, check if there's an if clause. */
6383 cond_string
= ep_parse_optional_if_clause (&arg
);
6385 if ((*arg
!= '\0') && !isspace (*arg
))
6386 error (_("Junk at end of arguments."));
6388 /* If this target supports it, create a fork or vfork catchpoint
6389 and enable reporting of such events. */
6393 create_fork_event_catchpoint (tempflag
, cond_string
);
6396 create_vfork_event_catchpoint (tempflag
, cond_string
);
6399 error (_("unsupported or unknown fork kind; cannot catch it"));
6405 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6407 char *cond_string
= NULL
;
6409 ep_skip_leading_whitespace (&arg
);
6411 /* The allowed syntax is:
6413 catch exec if <cond>
6415 First, check if there's an if clause. */
6416 cond_string
= ep_parse_optional_if_clause (&arg
);
6418 if ((*arg
!= '\0') && !isspace (*arg
))
6419 error (_("Junk at end of arguments."));
6421 /* If this target supports it, create an exec catchpoint
6422 and enable reporting of such events. */
6423 create_exec_event_catchpoint (tempflag
, cond_string
);
6427 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6429 char *dll_pathname
= NULL
;
6430 char *cond_string
= NULL
;
6432 ep_skip_leading_whitespace (&arg
);
6434 /* The allowed syntax is:
6436 catch load if <cond>
6437 catch load <filename>
6438 catch load <filename> if <cond>
6440 The user is not allowed to specify the <filename> after an
6443 We'll ignore the pathological case of a file named "if".
6445 First, check if there's an if clause. If so, then there
6446 cannot be a filename. */
6447 cond_string
= ep_parse_optional_if_clause (&arg
);
6449 /* If there was an if clause, then there cannot be a filename.
6450 Else, there might be a filename and an if clause. */
6451 if (cond_string
== NULL
)
6453 dll_pathname
= ep_parse_optional_filename (&arg
);
6454 ep_skip_leading_whitespace (&arg
);
6455 cond_string
= ep_parse_optional_if_clause (&arg
);
6458 if ((*arg
!= '\0') && !isspace (*arg
))
6459 error (_("Junk at end of arguments."));
6461 /* Create a load breakpoint that only triggers when a load of
6462 the specified dll (or any dll, if no pathname was specified)
6464 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6465 dll_pathname
, cond_string
);
6469 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6471 char *dll_pathname
= NULL
;
6472 char *cond_string
= NULL
;
6474 ep_skip_leading_whitespace (&arg
);
6476 /* The allowed syntax is:
6478 catch unload if <cond>
6479 catch unload <filename>
6480 catch unload <filename> if <cond>
6482 The user is not allowed to specify the <filename> after an
6485 We'll ignore the pathological case of a file named "if".
6487 First, check if there's an if clause. If so, then there
6488 cannot be a filename. */
6489 cond_string
= ep_parse_optional_if_clause (&arg
);
6491 /* If there was an if clause, then there cannot be a filename.
6492 Else, there might be a filename and an if clause. */
6493 if (cond_string
== NULL
)
6495 dll_pathname
= ep_parse_optional_filename (&arg
);
6496 ep_skip_leading_whitespace (&arg
);
6497 cond_string
= ep_parse_optional_if_clause (&arg
);
6500 if ((*arg
!= '\0') && !isspace (*arg
))
6501 error (_("Junk at end of arguments."));
6503 /* Create an unload breakpoint that only triggers when an unload of
6504 the specified dll (or any dll, if no pathname was specified)
6506 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6507 dll_pathname
, cond_string
);
6510 static enum print_stop_action
6511 print_exception_catchpoint (struct breakpoint
*b
)
6513 int bp_temp
, bp_throw
;
6515 annotate_catchpoint (b
->number
);
6517 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6518 if (b
->loc
->address
!= b
->loc
->requested_address
)
6519 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6522 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6524 bp_temp
? "Temporary catchpoint "
6526 if (!ui_out_is_mi_like_p (uiout
))
6527 ui_out_field_int (uiout
, "bkptno", b
->number
);
6529 bp_throw
? " (exception thrown), "
6530 : " (exception caught), ");
6531 if (ui_out_is_mi_like_p (uiout
))
6533 ui_out_field_string (uiout
, "reason",
6534 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6535 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6536 ui_out_field_int (uiout
, "bkptno", b
->number
);
6538 return PRINT_SRC_AND_LOC
;
6542 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6547 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6548 ui_out_field_string (uiout
, "addr", "<PENDING>");
6550 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6554 *last_addr
= b
->loc
->address
;
6555 if (strstr (b
->addr_string
, "throw") != NULL
)
6556 ui_out_field_string (uiout
, "what", "exception throw");
6558 ui_out_field_string (uiout
, "what", "exception catch");
6562 print_mention_exception_catchpoint (struct breakpoint
*b
)
6567 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6568 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6569 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6570 : _("Catchpoint "));
6571 ui_out_field_int (uiout
, "bkptno", b
->number
);
6572 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6576 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6577 print_exception_catchpoint
,
6578 print_one_exception_catchpoint
,
6579 print_mention_exception_catchpoint
6583 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6584 enum exception_event_kind ex_event
, int from_tty
)
6586 char *trigger_func_name
;
6588 if (ex_event
== EX_EVENT_CATCH
)
6589 trigger_func_name
= "__cxa_begin_catch";
6591 trigger_func_name
= "__cxa_throw";
6593 break_command_really (trigger_func_name
, cond_string
, -1,
6594 0 /* condition and thread are valid. */,
6597 AUTO_BOOLEAN_TRUE
/* pending */,
6598 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6603 /* Deal with "catch catch" and "catch throw" commands */
6606 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6607 int tempflag
, int from_tty
)
6609 char *cond_string
= NULL
;
6610 struct symtab_and_line
*sal
= NULL
;
6612 ep_skip_leading_whitespace (&arg
);
6614 cond_string
= ep_parse_optional_if_clause (&arg
);
6616 if ((*arg
!= '\0') && !isspace (*arg
))
6617 error (_("Junk at end of arguments."));
6619 if ((ex_event
!= EX_EVENT_THROW
) &&
6620 (ex_event
!= EX_EVENT_CATCH
))
6621 error (_("Unsupported or unknown exception event; cannot catch it"));
6623 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6626 warning (_("Unsupported with this platform/compiler combination."));
6629 /* Create a breakpoint struct for Ada exception catchpoints. */
6632 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6636 struct expression
*cond
,
6637 struct breakpoint_ops
*ops
,
6641 struct breakpoint
*b
;
6645 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6646 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6647 version for exception catchpoints, because two catchpoints
6648 used for different exception names will use the same address.
6649 In this case, a "breakpoint ... also set at..." warning is
6650 unproductive. Besides. the warning phrasing is also a bit
6651 inapropriate, we should use the word catchpoint, and tell
6652 the user what type of catchpoint it is. The above is good
6653 enough for now, though. */
6656 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6657 set_breakpoint_count (breakpoint_count
+ 1);
6659 b
->enable_state
= bp_enabled
;
6660 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6661 b
->number
= breakpoint_count
;
6662 b
->ignore_count
= 0;
6663 b
->loc
->cond
= cond
;
6664 b
->addr_string
= addr_string
;
6665 b
->language
= language_ada
;
6666 b
->cond_string
= cond_string
;
6667 b
->exp_string
= exp_string
;
6672 update_global_location_list (1);
6675 /* Implement the "catch exception" command. */
6678 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6680 struct symtab_and_line sal
;
6682 char *addr_string
= NULL
;
6683 char *exp_string
= NULL
;
6684 char *cond_string
= NULL
;
6685 struct expression
*cond
= NULL
;
6686 struct breakpoint_ops
*ops
= NULL
;
6688 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6689 &cond_string
, &cond
, &ops
);
6690 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6691 cond_string
, cond
, ops
, tempflag
,
6695 /* Implement the "catch assert" command. */
6698 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6700 struct symtab_and_line sal
;
6701 char *addr_string
= NULL
;
6702 struct breakpoint_ops
*ops
= NULL
;
6704 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6705 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6706 tempflag
, from_tty
);
6710 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6713 /* The first argument may be an event name, such as "start" or "load".
6714 If so, then handle it as such. If it doesn't match an event name,
6715 then attempt to interpret it as an exception name. (This latter is
6716 the v4.16-and-earlier GDB meaning of the "catch" command.)
6718 First, try to find the bounds of what might be an event name. */
6719 char *arg1_start
= arg
;
6723 if (arg1_start
== NULL
)
6725 /* Old behaviour was to use pre-v-4.16 syntax */
6726 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6728 /* Now, this is not allowed */
6729 error (_("Catch requires an event name."));
6732 arg1_end
= ep_find_event_name_end (arg1_start
);
6733 if (arg1_end
== NULL
)
6734 error (_("catch requires an event"));
6735 arg1_length
= arg1_end
+ 1 - arg1_start
;
6737 /* Try to match what we found against known event names. */
6738 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6740 error (_("Catch of signal not yet implemented"));
6742 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6744 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6745 tempflag
, from_tty
);
6747 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6749 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6750 tempflag
, from_tty
);
6752 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6754 error (_("Catch of thread_start not yet implemented"));
6756 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6758 error (_("Catch of thread_exit not yet implemented"));
6760 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6762 error (_("Catch of thread_join not yet implemented"));
6764 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6766 error (_("Catch of start not yet implemented"));
6768 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6770 error (_("Catch of exit not yet implemented"));
6772 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6774 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6776 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6778 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6780 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6782 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6784 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6786 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6788 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6790 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6792 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6794 error (_("Catch of stop not yet implemented"));
6796 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6798 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6801 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6803 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6806 /* This doesn't appear to be an event name */
6810 /* Pre-v.4.16 behaviour was to treat the argument
6811 as the name of an exception */
6812 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6813 /* Now this is not allowed */
6814 error (_("Unknown event kind specified for catch"));
6820 catch_command (char *arg
, int from_tty
)
6822 catch_command_1 (arg
, 0, from_tty
);
6827 tcatch_command (char *arg
, int from_tty
)
6829 catch_command_1 (arg
, 1, from_tty
);
6832 /* Delete breakpoints by address or line. */
6835 clear_command (char *arg
, int from_tty
)
6837 struct breakpoint
*b
;
6838 VEC(breakpoint_p
) *found
= 0;
6841 struct symtabs_and_lines sals
;
6842 struct symtab_and_line sal
;
6847 sals
= decode_line_spec (arg
, 1);
6852 sals
.sals
= (struct symtab_and_line
*)
6853 xmalloc (sizeof (struct symtab_and_line
));
6854 make_cleanup (xfree
, sals
.sals
);
6855 init_sal (&sal
); /* initialize to zeroes */
6856 sal
.line
= default_breakpoint_line
;
6857 sal
.symtab
= default_breakpoint_symtab
;
6858 sal
.pc
= default_breakpoint_address
;
6859 if (sal
.symtab
== 0)
6860 error (_("No source file specified."));
6868 /* We don't call resolve_sal_pc here. That's not
6869 as bad as it seems, because all existing breakpoints
6870 typically have both file/line and pc set. So, if
6871 clear is given file/line, we can match this to existing
6872 breakpoint without obtaining pc at all.
6874 We only support clearing given the address explicitly
6875 present in breakpoint table. Say, we've set breakpoint
6876 at file:line. There were several PC values for that file:line,
6877 due to optimization, all in one block.
6878 We've picked one PC value. If "clear" is issued with another
6879 PC corresponding to the same file:line, the breakpoint won't
6880 be cleared. We probably can still clear the breakpoint, but
6881 since the other PC value is never presented to user, user
6882 can only find it by guessing, and it does not seem important
6885 /* For each line spec given, delete bps which correspond
6886 to it. Do it in two passes, solely to preserve the current
6887 behavior that from_tty is forced true if we delete more than
6891 for (i
= 0; i
< sals
.nelts
; i
++)
6893 /* If exact pc given, clear bpts at that pc.
6894 If line given (pc == 0), clear all bpts on specified line.
6895 If defaulting, clear all bpts on default line
6898 defaulting sal.pc != 0 tests to do
6903 1 0 <can't happen> */
6907 /* Find all matching breakpoints and add them to
6912 /* Are we going to delete b? */
6913 if (b
->type
!= bp_none
6914 && b
->type
!= bp_watchpoint
6915 && b
->type
!= bp_hardware_watchpoint
6916 && b
->type
!= bp_read_watchpoint
6917 && b
->type
!= bp_access_watchpoint
)
6919 struct bp_location
*loc
= b
->loc
;
6920 for (; loc
; loc
= loc
->next
)
6922 int pc_match
= sal
.pc
6923 && (loc
->address
== sal
.pc
)
6924 && (!section_is_overlay (loc
->section
)
6925 || loc
->section
== sal
.section
);
6926 int line_match
= ((default_match
|| (0 == sal
.pc
))
6927 && b
->source_file
!= NULL
6928 && sal
.symtab
!= NULL
6929 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6930 && b
->line_number
== sal
.line
);
6931 if (pc_match
|| line_match
)
6940 VEC_safe_push(breakpoint_p
, found
, b
);
6943 /* Now go thru the 'found' chain and delete them. */
6944 if (VEC_empty(breakpoint_p
, found
))
6947 error (_("No breakpoint at %s."), arg
);
6949 error (_("No breakpoint at this line."));
6952 if (VEC_length(breakpoint_p
, found
) > 1)
6953 from_tty
= 1; /* Always report if deleted more than one */
6956 if (VEC_length(breakpoint_p
, found
) == 1)
6957 printf_unfiltered (_("Deleted breakpoint "));
6959 printf_unfiltered (_("Deleted breakpoints "));
6961 breakpoints_changed ();
6963 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6966 printf_unfiltered ("%d ", b
->number
);
6967 delete_breakpoint (b
);
6970 putchar_unfiltered ('\n');
6973 /* Delete breakpoint in BS if they are `delete' breakpoints and
6974 all breakpoints that are marked for deletion, whether hit or not.
6975 This is called after any breakpoint is hit, or after errors. */
6978 breakpoint_auto_delete (bpstat bs
)
6980 struct breakpoint
*b
, *temp
;
6982 for (; bs
; bs
= bs
->next
)
6983 if (bs
->breakpoint_at
6984 && bs
->breakpoint_at
->owner
6985 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6987 delete_breakpoint (bs
->breakpoint_at
->owner
);
6989 ALL_BREAKPOINTS_SAFE (b
, temp
)
6991 if (b
->disposition
== disp_del_at_next_stop
)
6992 delete_breakpoint (b
);
6996 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
6997 into the inferior, only remove already-inserted locations that no
6998 longer should be inserted. Functions that delete a breakpoint or
6999 breakpoints should pass false, so that deleting a breakpoint
7000 doesn't have the side effect of inserting the locations of other
7001 breakpoints that are marked not-inserted, but should_be_inserted
7002 returns true on them.
7004 This behaviour is useful is situations close to tear-down -- e.g.,
7005 after an exec, while the target still has execution, but breakpoint
7006 shadows of the previous executable image should *NOT* be restored
7007 to the new image; or before detaching, where the target still has
7008 execution and wants to delete breakpoints from GDB's lists, and all
7009 breakpoints had already been removed from the inferior. */
7012 update_global_location_list (int should_insert
)
7014 struct breakpoint
*b
;
7015 struct bp_location
**next
= &bp_location_chain
;
7016 struct bp_location
*loc
;
7017 struct bp_location
*loc2
;
7018 struct gdb_exception e
;
7019 VEC(bp_location_p
) *old_locations
= NULL
;
7023 /* Store old locations for future reference. */
7024 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7025 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7027 bp_location_chain
= NULL
;
7030 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7033 next
= &(loc
->global_next
);
7038 /* Identify bp_location instances that are no longer present in the new
7039 list, and therefore should be freed. Note that it's not necessary that
7040 those locations should be removed from inferior -- if there's another
7041 location at the same address (previously marked as duplicate),
7042 we don't need to remove/insert the location. */
7043 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7045 /* Tells if 'loc' is found amoung the new locations. If not, we
7047 int found_object
= 0;
7048 /* Tells if the location should remain inserted in the target. */
7049 int keep_in_target
= 0;
7051 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7058 /* If this location is no longer present, and inserted, look if there's
7059 maybe a new location at the same address. If so, mark that one
7060 inserted, and don't remove this one. This is needed so that we
7061 don't have a time window where a breakpoint at certain location is not
7066 /* If the location is inserted now, we might have to remove it. */
7068 if (found_object
&& should_be_inserted (loc
))
7070 /* The location is still present in the location list, and still
7071 should be inserted. Don't do anything. */
7076 /* The location is either no longer present, or got disabled.
7077 See if there's another location at the same address, in which
7078 case we don't need to remove this one from the target. */
7079 if (breakpoint_address_is_meaningful (loc
->owner
))
7080 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7082 /* For the sake of should_insert_location. The
7083 call to check_duplicates will fix up this later. */
7084 loc2
->duplicate
= 0;
7085 if (should_be_inserted (loc2
)
7086 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7089 loc2
->target_info
= loc
->target_info
;
7096 if (!keep_in_target
)
7098 if (remove_breakpoint (loc
, mark_uninserted
))
7100 /* This is just about all we can do. We could keep this
7101 location on the global list, and try to remove it next
7102 time, but there's no particular reason why we will
7105 Note that at this point, loc->owner is still valid,
7106 as delete_breakpoint frees the breakpoint only
7107 after calling us. */
7108 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7109 loc
->owner
->number
);
7119 /* This location was removed from the targets. In non-stop mode,
7120 a race condition is possible where we've removed a breakpoint,
7121 but stop events for that breakpoint are already queued and will
7122 arrive later. To suppress spurious SIGTRAPs reported to user,
7123 we keep this breakpoint location for a bit, and will retire it
7124 after we see 3 * thread_count events.
7125 The theory here is that reporting of events should,
7126 "on the average", be fair, so after that many event we'll see
7127 events from all threads that have anything of interest, and no
7128 longer need to keep this breakpoint. This is just a
7129 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7130 which is usability issue, but not a correctness problem. */
7131 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7135 free_bp_location (loc
);
7141 check_duplicates (b
);
7144 if (always_inserted_mode
&& should_insert
&& target_has_execution
)
7145 insert_breakpoint_locations ();
7149 breakpoint_retire_moribund (void)
7151 struct bp_location
*loc
;
7154 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7155 if (--(loc
->events_till_retirement
) == 0)
7157 free_bp_location (loc
);
7158 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7164 update_global_location_list_nothrow (int inserting
)
7166 struct gdb_exception e
;
7167 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7168 update_global_location_list (inserting
);
7171 /* Clear BPT from a BPS. */
7173 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7176 for (bs
= bps
; bs
; bs
= bs
->next
)
7177 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7179 bs
->breakpoint_at
= NULL
;
7181 /* bs->commands will be freed later. */
7185 /* Callback for iterate_over_threads. */
7187 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7189 struct breakpoint
*bpt
= data
;
7190 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7194 /* Delete a breakpoint and clean up all traces of it in the data
7198 delete_breakpoint (struct breakpoint
*bpt
)
7200 struct breakpoint
*b
;
7201 struct bp_location
*loc
, *next
;
7203 gdb_assert (bpt
!= NULL
);
7205 /* Has this bp already been deleted? This can happen because multiple
7206 lists can hold pointers to bp's. bpstat lists are especial culprits.
7208 One example of this happening is a watchpoint's scope bp. When the
7209 scope bp triggers, we notice that the watchpoint is out of scope, and
7210 delete it. We also delete its scope bp. But the scope bp is marked
7211 "auto-deleting", and is already on a bpstat. That bpstat is then
7212 checked for auto-deleting bp's, which are deleted.
7214 A real solution to this problem might involve reference counts in bp's,
7215 and/or giving them pointers back to their referencing bpstat's, and
7216 teaching delete_breakpoint to only free a bp's storage when no more
7217 references were extent. A cheaper bandaid was chosen. */
7218 if (bpt
->type
== bp_none
)
7221 if (deprecated_delete_breakpoint_hook
)
7222 deprecated_delete_breakpoint_hook (bpt
);
7223 breakpoint_delete_event (bpt
->number
);
7225 if (breakpoint_chain
== bpt
)
7226 breakpoint_chain
= bpt
->next
;
7231 b
->next
= bpt
->next
;
7235 free_command_lines (&bpt
->commands
);
7236 if (bpt
->cond_string
!= NULL
)
7237 xfree (bpt
->cond_string
);
7238 if (bpt
->addr_string
!= NULL
)
7239 xfree (bpt
->addr_string
);
7240 if (bpt
->exp
!= NULL
)
7242 if (bpt
->exp_string
!= NULL
)
7243 xfree (bpt
->exp_string
);
7244 if (bpt
->val
!= NULL
)
7245 value_free (bpt
->val
);
7246 if (bpt
->source_file
!= NULL
)
7247 xfree (bpt
->source_file
);
7248 if (bpt
->dll_pathname
!= NULL
)
7249 xfree (bpt
->dll_pathname
);
7250 if (bpt
->triggered_dll_pathname
!= NULL
)
7251 xfree (bpt
->triggered_dll_pathname
);
7252 if (bpt
->exec_pathname
!= NULL
)
7253 xfree (bpt
->exec_pathname
);
7255 /* Be sure no bpstat's are pointing at it after it's been freed. */
7256 /* FIXME, how can we find all bpstat's?
7257 We just check stop_bpstat for now. Note that we cannot just
7258 remove bpstats pointing at bpt from the stop_bpstat list
7259 entirely, as breakpoint commands are associated with the bpstat;
7260 if we remove it here, then the later call to
7261 bpstat_do_actions (&stop_bpstat);
7262 in event-top.c won't do anything, and temporary breakpoints
7263 with commands won't work. */
7265 /* Clear the current context. */
7266 bpstat_remove_breakpoint (stop_bpstat
, bpt
);
7267 /* And from all threads. */
7268 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7270 /* Now that breakpoint is removed from breakpoint
7271 list, update the global location list. This
7272 will remove locations that used to belong to
7273 this breakpoint. Do this before freeing
7274 the breakpoint itself, since remove_breakpoint
7275 looks at location's owner. It might be better
7276 design to have location completely self-contained,
7277 but it's not the case now. */
7278 update_global_location_list (0);
7281 /* On the chance that someone will soon try again to delete this same
7282 bp, we mark it as deleted before freeing its storage. */
7283 bpt
->type
= bp_none
;
7289 do_delete_breakpoint_cleanup (void *b
)
7291 delete_breakpoint (b
);
7295 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7297 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7301 delete_command (char *arg
, int from_tty
)
7303 struct breakpoint
*b
, *temp
;
7309 int breaks_to_delete
= 0;
7311 /* Delete all breakpoints if no argument.
7312 Do not delete internal or call-dummy breakpoints, these
7313 have to be deleted with an explicit breakpoint number argument. */
7316 if (b
->type
!= bp_call_dummy
&&
7317 b
->type
!= bp_shlib_event
&&
7318 b
->type
!= bp_thread_event
&&
7319 b
->type
!= bp_overlay_event
&&
7322 breaks_to_delete
= 1;
7327 /* Ask user only if there are some breakpoints to delete. */
7329 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7331 ALL_BREAKPOINTS_SAFE (b
, temp
)
7333 if (b
->type
!= bp_call_dummy
&&
7334 b
->type
!= bp_shlib_event
&&
7335 b
->type
!= bp_thread_event
&&
7336 b
->type
!= bp_overlay_event
&&
7338 delete_breakpoint (b
);
7343 map_breakpoint_numbers (arg
, delete_breakpoint
);
7347 all_locations_are_pending (struct bp_location
*loc
)
7349 for (; loc
; loc
= loc
->next
)
7350 if (!loc
->shlib_disabled
)
7355 /* Subroutine of update_breakpoint_locations to simplify it.
7356 Return non-zero if multiple fns in list LOC have the same name.
7357 Null names are ignored. */
7360 ambiguous_names_p (struct bp_location
*loc
)
7362 struct bp_location
*l
;
7363 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7364 (int (*) (const void *, const void *)) streq
,
7365 NULL
, xcalloc
, xfree
);
7367 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7370 const char *name
= l
->function_name
;
7372 /* Allow for some names to be NULL, ignore them. */
7376 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7378 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7393 update_breakpoint_locations (struct breakpoint
*b
,
7394 struct symtabs_and_lines sals
)
7398 struct bp_location
*existing_locations
= b
->loc
;
7400 /* If there's no new locations, and all existing locations
7401 are pending, don't do anything. This optimizes
7402 the common case where all locations are in the same
7403 shared library, that was unloaded. We'd like to
7404 retain the location, so that when the library
7405 is loaded again, we don't loose the enabled/disabled
7406 status of the individual locations. */
7407 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7412 for (i
= 0; i
< sals
.nelts
; ++i
)
7414 struct bp_location
*new_loc
=
7415 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7417 /* Reparse conditions, they might contain references to the
7419 if (b
->cond_string
!= NULL
)
7421 struct gdb_exception e
;
7424 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7426 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7431 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7432 b
->number
, e
.message
);
7433 new_loc
->enabled
= 0;
7437 if (b
->source_file
!= NULL
)
7438 xfree (b
->source_file
);
7439 if (sals
.sals
[i
].symtab
== NULL
)
7440 b
->source_file
= NULL
;
7443 savestring (sals
.sals
[i
].symtab
->filename
,
7444 strlen (sals
.sals
[i
].symtab
->filename
));
7446 if (b
->line_number
== 0)
7447 b
->line_number
= sals
.sals
[i
].line
;
7450 /* If possible, carry over 'disable' status from existing breakpoints. */
7452 struct bp_location
*e
= existing_locations
;
7453 /* If there are multiple breakpoints with the same function name,
7454 e.g. for inline functions, comparing function names won't work.
7455 Instead compare pc addresses; this is just a heuristic as things
7456 may have moved, but in practice it gives the correct answer
7457 often enough until a better solution is found. */
7458 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7460 for (; e
; e
= e
->next
)
7462 if (!e
->enabled
&& e
->function_name
)
7464 struct bp_location
*l
= b
->loc
;
7465 if (have_ambiguous_names
)
7467 for (; l
; l
= l
->next
)
7468 if (e
->address
== l
->address
)
7476 for (; l
; l
= l
->next
)
7477 if (l
->function_name
7478 && strcmp (e
->function_name
, l
->function_name
) == 0)
7488 update_global_location_list (1);
7492 /* Reset a breakpoint given it's struct breakpoint * BINT.
7493 The value we return ends up being the return value from catch_errors.
7494 Unused in this case. */
7497 breakpoint_re_set_one (void *bint
)
7499 /* get past catch_errs */
7500 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7504 int *not_found_ptr
= ¬_found
;
7505 struct symtabs_and_lines sals
= {};
7506 struct symtabs_and_lines expanded
;
7508 enum enable_state save_enable
;
7509 struct gdb_exception e
;
7515 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7519 case bp_hardware_breakpoint
:
7521 case bp_catch_unload
:
7522 if (b
->addr_string
== NULL
)
7524 /* Anything without a string can't be re-set. */
7525 delete_breakpoint (b
);
7529 set_language (b
->language
);
7530 input_radix
= b
->input_radix
;
7532 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7534 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7539 int not_found_and_ok
= 0;
7540 /* For pending breakpoints, it's expected that parsing
7541 will fail until the right shared library is loaded.
7542 User has already told to create pending breakpoints and
7543 don't need extra messages. If breakpoint is in bp_shlib_disabled
7544 state, then user already saw the message about that breakpoint
7545 being disabled, and don't want to see more errors. */
7547 && (b
->condition_not_parsed
7548 || (b
->loc
&& b
->loc
->shlib_disabled
)
7549 || b
->enable_state
== bp_disabled
))
7550 not_found_and_ok
= 1;
7552 if (!not_found_and_ok
)
7554 /* We surely don't want to warn about the same breakpoint
7555 10 times. One solution, implemented here, is disable
7556 the breakpoint on error. Another solution would be to
7557 have separate 'warning emitted' flag. Since this
7558 happens only when a binary has changed, I don't know
7559 which approach is better. */
7560 b
->enable_state
= bp_disabled
;
7561 throw_exception (e
);
7568 gdb_assert (sals
.nelts
== 1);
7569 resolve_sal_pc (&sals
.sals
[0]);
7570 if (b
->condition_not_parsed
&& s
&& s
[0])
7572 char *cond_string
= 0;
7574 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7575 &cond_string
, &thread
);
7577 b
->cond_string
= cond_string
;
7579 b
->condition_not_parsed
= 0;
7581 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7582 update_breakpoint_locations (b
, expanded
);
7588 case bp_hardware_watchpoint
:
7589 case bp_read_watchpoint
:
7590 case bp_access_watchpoint
:
7591 /* Watchpoint can be either on expression using entirely global variables,
7592 or it can be on local variables.
7594 Watchpoints of the first kind are never auto-deleted, and even persist
7595 across program restarts. Since they can use variables from shared
7596 libraries, we need to reparse expression as libraries are loaded
7599 Watchpoints on local variables can also change meaning as result
7600 of solib event. For example, if a watchpoint uses both a local and
7601 a global variables in expression, it's a local watchpoint, but
7602 unloading of a shared library will make the expression invalid.
7603 This is not a very common use case, but we still re-evaluate
7604 expression, to avoid surprises to the user.
7606 Note that for local watchpoints, we re-evaluate it only if
7607 watchpoints frame id is still valid. If it's not, it means
7608 the watchpoint is out of scope and will be deleted soon. In fact,
7609 I'm not sure we'll ever be called in this case.
7611 If a local watchpoint's frame id is still valid, then
7612 b->exp_valid_block is likewise valid, and we can safely use it.
7614 Don't do anything about disabled watchpoints, since they will
7615 be reevaluated again when enabled. */
7616 update_watchpoint (b
, 1 /* reparse */);
7618 /* We needn't really do anything to reset these, since the mask
7619 that requests them is unaffected by e.g., new libraries being
7622 case bp_catch_vfork
:
7627 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7629 /* Delete overlay event breakpoints; they will be reset later by
7630 breakpoint_re_set. */
7631 case bp_overlay_event
:
7632 delete_breakpoint (b
);
7635 /* This breakpoint is special, it's set up when the inferior
7636 starts and we really don't want to touch it. */
7637 case bp_shlib_event
:
7639 /* Like bp_shlib_event, this breakpoint type is special.
7640 Once it is set up, we do not want to touch it. */
7641 case bp_thread_event
:
7643 /* Keep temporary breakpoints, which can be encountered when we step
7644 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7645 Otherwise these should have been blown away via the cleanup chain
7646 or by breakpoint_init_inferior when we rerun the executable. */
7649 case bp_watchpoint_scope
:
7651 case bp_step_resume
:
7653 case bp_longjmp_resume
:
7660 /* Re-set all breakpoints after symbols have been re-loaded. */
7662 breakpoint_re_set (void)
7664 struct breakpoint
*b
, *temp
;
7665 enum language save_language
;
7666 int save_input_radix
;
7668 save_language
= current_language
->la_language
;
7669 save_input_radix
= input_radix
;
7670 ALL_BREAKPOINTS_SAFE (b
, temp
)
7672 /* Format possible error msg */
7673 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7675 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7676 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7677 do_cleanups (cleanups
);
7679 set_language (save_language
);
7680 input_radix
= save_input_radix
;
7682 create_overlay_event_breakpoint ("_ovly_debug_event");
7685 /* Reset the thread number of this breakpoint:
7687 - If the breakpoint is for all threads, leave it as-is.
7688 - Else, reset it to the current thread for inferior_ptid. */
7690 breakpoint_re_set_thread (struct breakpoint
*b
)
7692 if (b
->thread
!= -1)
7694 if (in_thread_list (inferior_ptid
))
7695 b
->thread
= pid_to_thread_id (inferior_ptid
);
7699 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7700 If from_tty is nonzero, it prints a message to that effect,
7701 which ends with a period (no newline). */
7704 set_ignore_count (int bptnum
, int count
, int from_tty
)
7706 struct breakpoint
*b
;
7712 if (b
->number
== bptnum
)
7714 b
->ignore_count
= count
;
7718 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7720 else if (count
== 1)
7721 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7724 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7727 breakpoints_changed ();
7728 breakpoint_modify_event (b
->number
);
7732 error (_("No breakpoint number %d."), bptnum
);
7735 /* Clear the ignore counts of all breakpoints. */
7737 breakpoint_clear_ignore_counts (void)
7739 struct breakpoint
*b
;
7742 b
->ignore_count
= 0;
7745 /* Command to set ignore-count of breakpoint N to COUNT. */
7748 ignore_command (char *args
, int from_tty
)
7754 error_no_arg (_("a breakpoint number"));
7756 num
= get_number (&p
);
7758 error (_("bad breakpoint number: '%s'"), args
);
7760 error (_("Second argument (specified ignore-count) is missing."));
7762 set_ignore_count (num
,
7763 longest_to_int (value_as_long (parse_and_eval (p
))),
7766 printf_filtered ("\n");
7769 /* Call FUNCTION on each of the breakpoints
7770 whose numbers are given in ARGS. */
7773 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7778 struct breakpoint
*b
, *tmp
;
7782 error_no_arg (_("one or more breakpoint numbers"));
7789 num
= get_number_or_range (&p1
);
7792 warning (_("bad breakpoint number at or near '%s'"), p
);
7796 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7797 if (b
->number
== num
)
7799 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7802 if (related_breakpoint
)
7803 function (related_breakpoint
);
7807 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7813 static struct bp_location
*
7814 find_location_by_number (char *number
)
7816 char *dot
= strchr (number
, '.');
7820 struct breakpoint
*b
;
7821 struct bp_location
*loc
;
7826 bp_num
= get_number_or_range (&p1
);
7828 error (_("Bad breakpoint number '%s'"), number
);
7831 if (b
->number
== bp_num
)
7836 if (!b
|| b
->number
!= bp_num
)
7837 error (_("Bad breakpoint number '%s'"), number
);
7840 loc_num
= get_number_or_range (&p1
);
7842 error (_("Bad breakpoint location number '%s'"), number
);
7846 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7849 error (_("Bad breakpoint location number '%s'"), dot
+1);
7855 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7856 If from_tty is nonzero, it prints a message to that effect,
7857 which ends with a period (no newline). */
7860 disable_breakpoint (struct breakpoint
*bpt
)
7862 /* Never disable a watchpoint scope breakpoint; we want to
7863 hit them when we leave scope so we can delete both the
7864 watchpoint and its scope breakpoint at that time. */
7865 if (bpt
->type
== bp_watchpoint_scope
)
7868 /* You can't disable permanent breakpoints. */
7869 if (bpt
->enable_state
== bp_permanent
)
7872 bpt
->enable_state
= bp_disabled
;
7874 update_global_location_list (0);
7876 if (deprecated_modify_breakpoint_hook
)
7877 deprecated_modify_breakpoint_hook (bpt
);
7878 breakpoint_modify_event (bpt
->number
);
7882 disable_command (char *args
, int from_tty
)
7884 struct breakpoint
*bpt
;
7886 ALL_BREAKPOINTS (bpt
)
7890 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7895 case bp_catch_unload
:
7897 case bp_catch_vfork
:
7899 case bp_hardware_breakpoint
:
7901 case bp_hardware_watchpoint
:
7902 case bp_read_watchpoint
:
7903 case bp_access_watchpoint
:
7904 disable_breakpoint (bpt
);
7908 else if (strchr (args
, '.'))
7910 struct bp_location
*loc
= find_location_by_number (args
);
7913 update_global_location_list (0);
7916 map_breakpoint_numbers (args
, disable_breakpoint
);
7920 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7922 int target_resources_ok
, other_type_used
;
7925 if (bpt
->type
== bp_hardware_breakpoint
)
7928 i
= hw_breakpoint_used_count ();
7929 target_resources_ok
=
7930 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7932 if (target_resources_ok
== 0)
7933 error (_("No hardware breakpoint support in the target."));
7934 else if (target_resources_ok
< 0)
7935 error (_("Hardware breakpoints used exceeds limit."));
7938 if (bpt
->type
== bp_watchpoint
||
7939 bpt
->type
== bp_hardware_watchpoint
||
7940 bpt
->type
== bp_read_watchpoint
||
7941 bpt
->type
== bp_access_watchpoint
)
7943 struct frame_id saved_frame_id
;
7945 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7946 if (bpt
->exp_valid_block
!= NULL
)
7948 struct frame_info
*fr
=
7949 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7952 printf_filtered (_("\
7953 Cannot enable watchpoint %d because the block in which its expression\n\
7954 is valid is not currently in scope.\n"), bpt
->number
);
7961 value_free (bpt
->val
);
7962 mark
= value_mark ();
7963 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7965 release_value (bpt
->val
);
7968 if (bpt
->type
== bp_hardware_watchpoint
||
7969 bpt
->type
== bp_read_watchpoint
||
7970 bpt
->type
== bp_access_watchpoint
)
7972 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7973 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7975 /* Hack around 'unused var' error for some targets here */
7976 (void) mem_cnt
, (void) i
;
7977 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7978 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7979 /* we can consider of type is bp_hardware_watchpoint, convert to
7980 bp_watchpoint in the following condition */
7981 if (target_resources_ok
< 0)
7983 printf_filtered (_("\
7984 Cannot enable watchpoint %d because target watch resources\n\
7985 have been allocated for other watchpoints.\n"), bpt
->number
);
7986 value_free_to_mark (mark
);
7991 select_frame (frame_find_by_id (saved_frame_id
));
7992 value_free_to_mark (mark
);
7995 if (bpt
->enable_state
!= bp_permanent
)
7996 bpt
->enable_state
= bp_enabled
;
7997 bpt
->disposition
= disposition
;
7998 update_global_location_list (1);
7999 breakpoints_changed ();
8001 if (deprecated_modify_breakpoint_hook
)
8002 deprecated_modify_breakpoint_hook (bpt
);
8003 breakpoint_modify_event (bpt
->number
);
8008 enable_breakpoint (struct breakpoint
*bpt
)
8010 do_enable_breakpoint (bpt
, bpt
->disposition
);
8013 /* The enable command enables the specified breakpoints (or all defined
8014 breakpoints) so they once again become (or continue to be) effective
8015 in stopping the inferior. */
8018 enable_command (char *args
, int from_tty
)
8020 struct breakpoint
*bpt
;
8022 ALL_BREAKPOINTS (bpt
)
8026 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8031 case bp_catch_unload
:
8033 case bp_catch_vfork
:
8035 case bp_hardware_breakpoint
:
8037 case bp_hardware_watchpoint
:
8038 case bp_read_watchpoint
:
8039 case bp_access_watchpoint
:
8040 enable_breakpoint (bpt
);
8044 else if (strchr (args
, '.'))
8046 struct bp_location
*loc
= find_location_by_number (args
);
8049 update_global_location_list (1);
8052 map_breakpoint_numbers (args
, enable_breakpoint
);
8056 enable_once_breakpoint (struct breakpoint
*bpt
)
8058 do_enable_breakpoint (bpt
, disp_disable
);
8062 enable_once_command (char *args
, int from_tty
)
8064 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8068 enable_delete_breakpoint (struct breakpoint
*bpt
)
8070 do_enable_breakpoint (bpt
, disp_del
);
8074 enable_delete_command (char *args
, int from_tty
)
8076 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8080 set_breakpoint_cmd (char *args
, int from_tty
)
8085 show_breakpoint_cmd (char *args
, int from_tty
)
8089 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8091 struct symtabs_and_lines
8092 decode_line_spec_1 (char *string
, int funfirstline
)
8094 struct symtabs_and_lines sals
;
8096 error (_("Empty line specification."));
8097 if (default_breakpoint_valid
)
8098 sals
= decode_line_1 (&string
, funfirstline
,
8099 default_breakpoint_symtab
,
8100 default_breakpoint_line
,
8101 (char ***) NULL
, NULL
);
8103 sals
= decode_line_1 (&string
, funfirstline
,
8104 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8106 error (_("Junk at end of line specification: %s"), string
);
8110 /* Create and insert a raw software breakpoint at PC. Return an
8111 identifier, which should be used to remove the breakpoint later.
8112 In general, places which call this should be using something on the
8113 breakpoint chain instead; this function should be eliminated
8117 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8119 struct bp_target_info
*bp_tgt
;
8121 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8122 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8124 bp_tgt
->placed_address
= pc
;
8125 if (target_insert_breakpoint (bp_tgt
) != 0)
8127 /* Could not insert the breakpoint. */
8135 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8138 deprecated_remove_raw_breakpoint (void *bp
)
8140 struct bp_target_info
*bp_tgt
= bp
;
8143 ret
= target_remove_breakpoint (bp_tgt
);
8149 /* One (or perhaps two) breakpoints used for software single stepping. */
8151 static void *single_step_breakpoints
[2];
8153 /* Create and insert a breakpoint for software single step. */
8156 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8160 if (single_step_breakpoints
[0] == NULL
)
8161 bpt_p
= &single_step_breakpoints
[0];
8164 gdb_assert (single_step_breakpoints
[1] == NULL
);
8165 bpt_p
= &single_step_breakpoints
[1];
8168 /* NOTE drow/2006-04-11: A future improvement to this function would be
8169 to only create the breakpoints once, and actually put them on the
8170 breakpoint chain. That would let us use set_raw_breakpoint. We could
8171 adjust the addresses each time they were needed. Doing this requires
8172 corresponding changes elsewhere where single step breakpoints are
8173 handled, however. So, for now, we use this. */
8175 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8177 error (_("Could not insert single-step breakpoint at 0x%s"),
8178 paddr_nz (next_pc
));
8181 /* Remove and delete any breakpoints used for software single step. */
8184 remove_single_step_breakpoints (void)
8186 gdb_assert (single_step_breakpoints
[0] != NULL
);
8188 /* See insert_single_step_breakpoint for more about this deprecated
8190 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8191 single_step_breakpoints
[0] = NULL
;
8193 if (single_step_breakpoints
[1] != NULL
)
8195 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8196 single_step_breakpoints
[1] = NULL
;
8200 /* Check whether a software single-step breakpoint is inserted at PC. */
8203 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8207 for (i
= 0; i
< 2; i
++)
8209 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8210 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8217 int breakpoints_always_inserted_mode (void)
8219 return always_inserted_mode
;
8223 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8224 It is defined as a macro to prevent duplication.
8225 COMMAND should be a string constant containing the name of the command. */
8226 #define BREAK_ARGS_HELP(command) \
8227 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8228 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8229 If a line number is specified, break at start of code for that line.\n\
8230 If a function is specified, break at start of code for that function.\n\
8231 If an address is specified, break at that exact address.\n\
8232 With no LOCATION, uses current execution address of selected stack frame.\n\
8233 This is useful for breaking on return to a stack frame.\n\
8235 THREADNUM is the number from \"info threads\".\n\
8236 CONDITION is a boolean expression.\n\
8238 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8240 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8243 _initialize_breakpoint (void)
8245 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8246 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8247 struct cmd_list_element
*c
;
8249 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8251 breakpoint_chain
= 0;
8252 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8253 before a breakpoint is set. */
8254 breakpoint_count
= 0;
8256 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8257 Set ignore-count of breakpoint number N to COUNT.\n\
8258 Usage is `ignore N COUNT'."));
8260 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8262 add_com ("commands", class_breakpoint
, commands_command
, _("\
8263 Set commands to be executed when a breakpoint is hit.\n\
8264 Give breakpoint number as argument after \"commands\".\n\
8265 With no argument, the targeted breakpoint is the last one set.\n\
8266 The commands themselves follow starting on the next line.\n\
8267 Type a line containing \"end\" to indicate the end of them.\n\
8268 Give \"silent\" as the first line to make the breakpoint silent;\n\
8269 then no output is printed when it is hit, except what the commands print."));
8271 add_com ("condition", class_breakpoint
, condition_command
, _("\
8272 Specify breakpoint number N to break only if COND is true.\n\
8273 Usage is `condition N COND', where N is an integer and COND is an\n\
8274 expression to be evaluated whenever breakpoint N is reached."));
8276 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8277 Set a temporary breakpoint.\n\
8278 Like \"break\" except the breakpoint is only temporary,\n\
8279 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8280 by using \"enable delete\" on the breakpoint number.\n\
8282 BREAK_ARGS_HELP ("tbreak")));
8283 set_cmd_completer (c
, location_completer
);
8285 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8286 Set a hardware assisted breakpoint.\n\
8287 Like \"break\" except the breakpoint requires hardware support,\n\
8288 some target hardware may not have this support.\n\
8290 BREAK_ARGS_HELP ("hbreak")));
8291 set_cmd_completer (c
, location_completer
);
8293 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8294 Set a temporary hardware assisted breakpoint.\n\
8295 Like \"hbreak\" except the breakpoint is only temporary,\n\
8296 so it will be deleted when hit.\n\
8298 BREAK_ARGS_HELP ("thbreak")));
8299 set_cmd_completer (c
, location_completer
);
8301 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8302 Enable some breakpoints.\n\
8303 Give breakpoint numbers (separated by spaces) as arguments.\n\
8304 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8305 This is used to cancel the effect of the \"disable\" command.\n\
8306 With a subcommand you can enable temporarily."),
8307 &enablelist
, "enable ", 1, &cmdlist
);
8309 add_com ("ab", class_breakpoint
, enable_command
, _("\
8310 Enable some breakpoints.\n\
8311 Give breakpoint numbers (separated by spaces) as arguments.\n\
8312 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8313 This is used to cancel the effect of the \"disable\" command.\n\
8314 With a subcommand you can enable temporarily."));
8316 add_com_alias ("en", "enable", class_breakpoint
, 1);
8318 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8319 Enable some breakpoints.\n\
8320 Give breakpoint numbers (separated by spaces) as arguments.\n\
8321 This is used to cancel the effect of the \"disable\" command.\n\
8322 May be abbreviated to simply \"enable\".\n"),
8323 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8325 add_cmd ("once", no_class
, enable_once_command
, _("\
8326 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8327 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8330 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8331 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8332 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8335 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8336 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8337 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8340 add_cmd ("once", no_class
, enable_once_command
, _("\
8341 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8342 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8345 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8346 Disable some breakpoints.\n\
8347 Arguments are breakpoint numbers with spaces in between.\n\
8348 To disable all breakpoints, give no argument.\n\
8349 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8350 &disablelist
, "disable ", 1, &cmdlist
);
8351 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8352 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8354 add_com ("sb", class_breakpoint
, disable_command
, _("\
8355 Disable some breakpoints.\n\
8356 Arguments are breakpoint numbers with spaces in between.\n\
8357 To disable all breakpoints, give no argument.\n\
8358 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8360 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8361 Disable some breakpoints.\n\
8362 Arguments are breakpoint numbers with spaces in between.\n\
8363 To disable all breakpoints, give no argument.\n\
8364 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8365 This command may be abbreviated \"disable\"."),
8368 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8369 Delete some breakpoints or auto-display expressions.\n\
8370 Arguments are breakpoint numbers with spaces in between.\n\
8371 To delete all breakpoints, give no argument.\n\
8373 Also a prefix command for deletion of other GDB objects.\n\
8374 The \"unset\" command is also an alias for \"delete\"."),
8375 &deletelist
, "delete ", 1, &cmdlist
);
8376 add_com_alias ("d", "delete", class_breakpoint
, 1);
8377 add_com_alias ("del", "delete", class_breakpoint
, 1);
8379 add_com ("db", class_breakpoint
, delete_command
, _("\
8380 Delete some breakpoints.\n\
8381 Arguments are breakpoint numbers with spaces in between.\n\
8382 To delete all breakpoints, give no argument.\n"));
8384 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8385 Delete some breakpoints or auto-display expressions.\n\
8386 Arguments are breakpoint numbers with spaces in between.\n\
8387 To delete all breakpoints, give no argument.\n\
8388 This command may be abbreviated \"delete\"."),
8391 add_com ("clear", class_breakpoint
, clear_command
, _("\
8392 Clear breakpoint at specified line or function.\n\
8393 Argument may be line number, function name, or \"*\" and an address.\n\
8394 If line number is specified, all breakpoints in that line are cleared.\n\
8395 If function is specified, breakpoints at beginning of function are cleared.\n\
8396 If an address is specified, breakpoints at that address are cleared.\n\
8398 With no argument, clears all breakpoints in the line that the selected frame\n\
8401 See also the \"delete\" command which clears breakpoints by number."));
8403 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8404 Set breakpoint at specified line or function.\n"
8405 BREAK_ARGS_HELP ("break")));
8406 set_cmd_completer (c
, location_completer
);
8408 add_com_alias ("b", "break", class_run
, 1);
8409 add_com_alias ("br", "break", class_run
, 1);
8410 add_com_alias ("bre", "break", class_run
, 1);
8411 add_com_alias ("brea", "break", class_run
, 1);
8415 add_com_alias ("ba", "break", class_breakpoint
, 1);
8416 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8421 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8422 Break in function/address or break at a line in the current file."),
8423 &stoplist
, "stop ", 1, &cmdlist
);
8424 add_cmd ("in", class_breakpoint
, stopin_command
,
8425 _("Break in function or address."), &stoplist
);
8426 add_cmd ("at", class_breakpoint
, stopat_command
,
8427 _("Break at a line in the current file."), &stoplist
);
8428 add_com ("status", class_info
, breakpoints_info
, _("\
8429 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8430 The \"Type\" column indicates one of:\n\
8431 \tbreakpoint - normal breakpoint\n\
8432 \twatchpoint - watchpoint\n\
8433 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8434 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8435 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8436 address and file/line number respectively.\n\
8438 Convenience variable \"$_\" and default examine address for \"x\"\n\
8439 are set to the address of the last breakpoint listed unless the command\n\
8440 is prefixed with \"server \".\n\n\
8441 Convenience variable \"$bpnum\" contains the number of the last\n\
8445 add_info ("breakpoints", breakpoints_info
, _("\
8446 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8447 The \"Type\" column indicates one of:\n\
8448 \tbreakpoint - normal breakpoint\n\
8449 \twatchpoint - watchpoint\n\
8450 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8451 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8452 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8453 address and file/line number respectively.\n\
8455 Convenience variable \"$_\" and default examine address for \"x\"\n\
8456 are set to the address of the last breakpoint listed unless the command\n\
8457 is prefixed with \"server \".\n\n\
8458 Convenience variable \"$bpnum\" contains the number of the last\n\
8462 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8463 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8464 The \"Type\" column indicates one of:\n\
8465 \tbreakpoint - normal breakpoint\n\
8466 \twatchpoint - watchpoint\n\
8467 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8468 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8469 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8470 address and file/line number respectively.\n\
8472 Convenience variable \"$_\" and default examine address for \"x\"\n\
8473 are set to the address of the last breakpoint listed unless the command\n\
8474 is prefixed with \"server \".\n\n\
8475 Convenience variable \"$bpnum\" contains the number of the last\n\
8478 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8479 Status of all breakpoints, or breakpoint number NUMBER.\n\
8480 The \"Type\" column indicates one of:\n\
8481 \tbreakpoint - normal breakpoint\n\
8482 \twatchpoint - watchpoint\n\
8483 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8484 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8485 \tuntil - internal breakpoint used by the \"until\" command\n\
8486 \tfinish - internal breakpoint used by the \"finish\" command\n\
8487 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8488 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8489 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8490 address and file/line number respectively.\n\
8492 Convenience variable \"$_\" and default examine address for \"x\"\n\
8493 are set to the address of the last breakpoint listed unless the command\n\
8494 is prefixed with \"server \".\n\n\
8495 Convenience variable \"$bpnum\" contains the number of the last\n\
8497 &maintenanceinfolist
);
8499 add_com ("catch", class_breakpoint
, catch_command
, _("\
8500 Set catchpoints to catch events.\n\
8501 Raised signals may be caught:\n\
8502 \tcatch signal - all signals\n\
8503 \tcatch signal <signame> - a particular signal\n\
8504 Raised exceptions may be caught:\n\
8505 \tcatch throw - all exceptions, when thrown\n\
8506 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8507 \tcatch catch - all exceptions, when caught\n\
8508 \tcatch catch <exceptname> - a particular exception, when caught\n\
8509 Thread or process events may be caught:\n\
8510 \tcatch thread_start - any threads, just after creation\n\
8511 \tcatch thread_exit - any threads, just before expiration\n\
8512 \tcatch thread_join - any threads, just after joins\n\
8513 Process events may be caught:\n\
8514 \tcatch start - any processes, just after creation\n\
8515 \tcatch exit - any processes, just before expiration\n\
8516 \tcatch fork - calls to fork()\n\
8517 \tcatch vfork - calls to vfork()\n\
8518 \tcatch exec - calls to exec()\n\
8519 Dynamically-linked library events may be caught:\n\
8520 \tcatch load - loads of any library\n\
8521 \tcatch load <libname> - loads of a particular library\n\
8522 \tcatch unload - unloads of any library\n\
8523 \tcatch unload <libname> - unloads of a particular library\n\
8524 The act of your program's execution stopping may also be caught:\n\
8526 C++ exceptions may be caught:\n\
8527 \tcatch throw - all exceptions, when thrown\n\
8528 \tcatch catch - all exceptions, when caught\n\
8529 Ada exceptions may be caught:\n\
8530 \tcatch exception - all exceptions, when raised\n\
8531 \tcatch exception <name> - a particular exception, when raised\n\
8532 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8533 \tcatch assert - all failed assertions, when raised\n\
8535 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8536 after a fork or vfork is caught.\n\n\
8537 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8539 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8540 Set temporary catchpoints to catch events.\n\
8541 Args like \"catch\" command.\n\
8542 Like \"catch\" except the catchpoint is only temporary,\n\
8543 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8544 by using \"enable delete\" on the catchpoint number."));
8546 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8547 Set a watchpoint for an expression.\n\
8548 A watchpoint stops execution of your program whenever the value of\n\
8549 an expression changes."));
8550 set_cmd_completer (c
, expression_completer
);
8552 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8553 Set a read watchpoint for an expression.\n\
8554 A watchpoint stops execution of your program whenever the value of\n\
8555 an expression is read."));
8556 set_cmd_completer (c
, expression_completer
);
8558 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8559 Set a watchpoint for an expression.\n\
8560 A watchpoint stops execution of your program whenever the value of\n\
8561 an expression is either read or written."));
8562 set_cmd_completer (c
, expression_completer
);
8564 add_info ("watchpoints", breakpoints_info
,
8565 _("Synonym for ``info breakpoints''."));
8568 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8569 respond to changes - contrary to the description. */
8570 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8571 &can_use_hw_watchpoints
, _("\
8572 Set debugger's willingness to use watchpoint hardware."), _("\
8573 Show debugger's willingness to use watchpoint hardware."), _("\
8574 If zero, gdb will not use hardware for new watchpoints, even if\n\
8575 such is available. (However, any hardware watchpoints that were\n\
8576 created before setting this to nonzero, will continue to use watchpoint\n\
8579 show_can_use_hw_watchpoints
,
8580 &setlist
, &showlist
);
8582 can_use_hw_watchpoints
= 1;
8584 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8585 Breakpoint specific settings\n\
8586 Configure various breakpoint-specific variables such as\n\
8587 pending breakpoint behavior"),
8588 &breakpoint_set_cmdlist
, "set breakpoint ",
8589 0/*allow-unknown*/, &setlist
);
8590 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8591 Breakpoint specific settings\n\
8592 Configure various breakpoint-specific variables such as\n\
8593 pending breakpoint behavior"),
8594 &breakpoint_show_cmdlist
, "show breakpoint ",
8595 0/*allow-unknown*/, &showlist
);
8597 add_setshow_auto_boolean_cmd ("pending", no_class
,
8598 &pending_break_support
, _("\
8599 Set debugger's behavior regarding pending breakpoints."), _("\
8600 Show debugger's behavior regarding pending breakpoints."), _("\
8601 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8602 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8603 an error. If auto, an unrecognized breakpoint location results in a\n\
8604 user-query to see if a pending breakpoint should be created."),
8606 show_pending_break_support
,
8607 &breakpoint_set_cmdlist
,
8608 &breakpoint_show_cmdlist
);
8610 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8612 add_setshow_boolean_cmd ("auto-hw", no_class
,
8613 &automatic_hardware_breakpoints
, _("\
8614 Set automatic usage of hardware breakpoints."), _("\
8615 Show automatic usage of hardware breakpoints."), _("\
8616 If set, the debugger will automatically use hardware breakpoints for\n\
8617 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8618 a warning will be emitted for such breakpoints."),
8620 show_automatic_hardware_breakpoints
,
8621 &breakpoint_set_cmdlist
,
8622 &breakpoint_show_cmdlist
);
8624 add_setshow_boolean_cmd ("always-inserted", class_support
,
8625 &always_inserted_mode
, _("\
8626 Set mode for inserting breakpoints."), _("\
8627 Show mode for inserting breakpoints."), _("\
8628 When this mode is off (which is the default), breakpoints are inserted in\n\
8629 inferior when it is resumed, and removed when execution stops. When this\n\
8630 mode is on, breakpoints are inserted immediately and removed only when\n\
8631 the user deletes the breakpoint."),
8633 &show_always_inserted_mode
,
8634 &breakpoint_set_cmdlist
,
8635 &breakpoint_show_cmdlist
);
8637 automatic_hardware_breakpoints
= 1;