1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
60 #include "mi/mi-common.h"
62 /* Prototypes for local functions. */
64 static void catch_command_1 (char *, int, int);
66 static void enable_delete_command (char *, int);
68 static void enable_delete_breakpoint (struct breakpoint
*);
70 static void enable_once_command (char *, int);
72 static void enable_once_breakpoint (struct breakpoint
*);
74 static void disable_command (char *, int);
76 static void enable_command (char *, int);
78 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
80 static void ignore_command (char *, int);
82 static int breakpoint_re_set_one (void *);
84 static void clear_command (char *, int);
86 static void catch_command (char *, int);
88 static void watch_command (char *, int);
90 static int can_use_hardware_watchpoint (struct value
*);
92 static void break_command_1 (char *, int, int);
94 static void mention (struct breakpoint
*);
96 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
98 static void check_duplicates (struct breakpoint
*);
100 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
102 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
105 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
107 static void breakpoints_info (char *, int);
109 static void breakpoint_1 (int, int);
111 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
113 static int breakpoint_cond_eval (void *);
115 static void cleanup_executing_breakpoints (void *);
117 static void commands_command (char *, int);
119 static void condition_command (char *, int);
121 static int get_number_trailer (char **, int);
123 void set_breakpoint_count (int);
132 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
134 static enum print_stop_action
print_it_typical (bpstat
);
136 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
138 static int watchpoint_check (void *);
140 static void maintenance_info_breakpoints (char *, int);
142 static void create_overlay_event_breakpoint (char *);
144 static int hw_breakpoint_used_count (void);
146 static int hw_watchpoint_used_count (enum bptype
, int *);
148 static void hbreak_command (char *, int);
150 static void thbreak_command (char *, int);
152 static void watch_command_1 (char *, int, int);
154 static void rwatch_command (char *, int);
156 static void awatch_command (char *, int);
158 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
160 static void create_fork_vfork_event_catchpoint (int tempflag
,
162 enum bptype bp_kind
);
164 static void stop_command (char *arg
, int from_tty
);
166 static void stopin_command (char *arg
, int from_tty
);
168 static void stopat_command (char *arg
, int from_tty
);
170 static char *ep_find_event_name_end (char *arg
);
172 static char *ep_parse_optional_if_clause (char **arg
);
174 static char *ep_parse_optional_filename (char **arg
);
176 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
177 char *arg
, int tempflag
, int from_tty
);
179 static void tcatch_command (char *arg
, int from_tty
);
181 static void ep_skip_leading_whitespace (char **s
);
183 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
185 static void free_bp_location (struct bp_location
*loc
);
187 static struct bp_location
*
188 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
190 static void update_global_location_list (int);
192 static void update_global_location_list_nothrow (int);
194 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
196 static void insert_breakpoint_locations (void);
199 bpdisp_text (enum bpdisp disp
)
201 /* NOTE: the following values are a part of MI protocol and represent
202 values of 'disp' field returned when inferior stops at a breakpoint. */
203 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
204 return bpdisps
[(int) disp
];
207 /* Prototypes for exported functions. */
208 /* If FALSE, gdb will not use hardware support for watchpoints, even
209 if such is available. */
210 static int can_use_hw_watchpoints
;
213 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
214 struct cmd_list_element
*c
,
217 fprintf_filtered (file
, _("\
218 Debugger's willingness to use watchpoint hardware is %s.\n"),
222 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
223 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
224 for unrecognized breakpoint locations.
225 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
226 static enum auto_boolean pending_break_support
;
228 show_pending_break_support (struct ui_file
*file
, int from_tty
,
229 struct cmd_list_element
*c
,
232 fprintf_filtered (file
, _("\
233 Debugger's behavior regarding pending breakpoints is %s.\n"),
237 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
238 set with "break" but falling in read-only memory.
239 If 0, gdb will warn about such breakpoints, but won't automatically
240 use hardware breakpoints. */
241 static int automatic_hardware_breakpoints
;
243 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
244 struct cmd_list_element
*c
,
247 fprintf_filtered (file
, _("\
248 Automatic usage of hardware breakpoints is %s.\n"),
252 /* If 1, gdb will keep breakpoints inserted even as inferior is stopped,
253 and immediately insert any new breakpoints. If 0, gdb will insert
254 breakpoints into inferior only when resuming it, and will remove
255 breakpoints upon stop. */
256 static int always_inserted_mode
= 0;
258 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
259 struct cmd_list_element
*c
, const char *value
)
261 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
265 void _initialize_breakpoint (void);
267 extern int addressprint
; /* Print machine addresses? */
269 /* Are we executing breakpoint commands? */
270 static int executing_breakpoint_commands
;
272 /* Are overlay event breakpoints enabled? */
273 static int overlay_events_enabled
;
275 /* Walk the following statement or block through all breakpoints.
276 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
279 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
281 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
282 for (B = breakpoint_chain; \
283 B ? (TMP=B->next, 1): 0; \
286 /* Similar iterators for the low-level breakpoints. */
288 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
290 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
291 for (B = bp_location_chain; \
292 B ? (TMP=B->global_next, 1): 0; \
295 /* True if breakpoint hit counts should be displayed in breakpoint info. */
297 int show_breakpoint_hit_counts
= 1;
299 /* Chains of all breakpoints defined. */
301 struct breakpoint
*breakpoint_chain
;
303 struct bp_location
*bp_location_chain
;
305 /* The locations that no longer correspond to any breakpoint,
306 unlinked from bp_location_chain, but for which a hit
307 may still be reported by a target. */
308 VEC(bp_location_p
) *moribund_locations
= NULL
;
310 /* Number of last breakpoint made. */
312 int breakpoint_count
;
314 /* This function returns a pointer to the string representation of the
315 pathname of the dynamically-linked library that has just been
318 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
319 or undefined results are guaranteed.
321 This string's contents are only valid immediately after the
322 inferior has stopped in the dynamic linker hook, and becomes
323 invalid as soon as the inferior is continued. Clients should make
324 a copy of this string if they wish to continue the inferior and
325 then access the string. */
327 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
328 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
331 /* This function returns a pointer to the string representation of the
332 pathname of the dynamically-linked library that has just been
335 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
336 TRUE, or undefined results are guaranteed.
338 This string's contents are only valid immediately after the
339 inferior has stopped in the dynamic linker hook, and becomes
340 invalid as soon as the inferior is continued. Clients should make
341 a copy of this string if they wish to continue the inferior and
342 then access the string. */
344 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
345 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
348 /* This function is called by the "catch load" command. It allows the
349 debugger to be notified by the dynamic linker when a specified
350 library file (or any library file, if filename is NULL) is loaded. */
352 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
353 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
354 error (_("catch of library loads not yet implemented on this platform"))
357 /* This function is called by the "catch unload" command. It allows
358 the debugger to be notified by the dynamic linker when a specified
359 library file (or any library file, if filename is NULL) is
362 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
363 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
364 error (_("catch of library unloads not yet implemented on this platform"))
367 /* Return whether a breakpoint is an active enabled breakpoint. */
369 breakpoint_enabled (struct breakpoint
*b
)
371 return (b
->enable_state
== bp_enabled
);
374 /* Set breakpoint count to NUM. */
377 set_breakpoint_count (int num
)
379 breakpoint_count
= num
;
380 set_internalvar (lookup_internalvar ("bpnum"),
381 value_from_longest (builtin_type_int
, (LONGEST
) num
));
384 /* Used in run_command to zero the hit count when a new run starts. */
387 clear_breakpoint_hit_counts (void)
389 struct breakpoint
*b
;
395 /* Default address, symtab and line to put a breakpoint at
396 for "break" command with no arg.
397 if default_breakpoint_valid is zero, the other three are
398 not valid, and "break" with no arg is an error.
400 This set by print_stack_frame, which calls set_default_breakpoint. */
402 int default_breakpoint_valid
;
403 CORE_ADDR default_breakpoint_address
;
404 struct symtab
*default_breakpoint_symtab
;
405 int default_breakpoint_line
;
407 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
408 Advance *PP after the string and any trailing whitespace.
410 Currently the string can either be a number or "$" followed by the name
411 of a convenience variable. Making it an expression wouldn't work well
412 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
414 If the string is a NULL pointer, that denotes the last breakpoint.
416 TRAILER is a character which can be found after the number; most
417 commonly this is `-'. If you don't want a trailer, use \0. */
419 get_number_trailer (char **pp
, int trailer
)
421 int retval
= 0; /* default */
425 /* Empty line means refer to the last breakpoint. */
426 return breakpoint_count
;
429 /* Make a copy of the name, so we can null-terminate it
430 to pass to lookup_internalvar(). */
435 while (isalnum (*p
) || *p
== '_')
437 varname
= (char *) alloca (p
- start
+ 1);
438 strncpy (varname
, start
, p
- start
);
439 varname
[p
- start
] = '\0';
440 val
= value_of_internalvar (lookup_internalvar (varname
));
441 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
442 retval
= (int) value_as_long (val
);
445 printf_filtered (_("Convenience variable must have integer value.\n"));
453 while (*p
>= '0' && *p
<= '9')
456 /* There is no number here. (e.g. "cond a == b"). */
458 /* Skip non-numeric token */
459 while (*p
&& !isspace((int) *p
))
461 /* Return zero, which caller must interpret as error. */
467 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
469 /* Trailing junk: return 0 and let caller print error msg. */
470 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
481 /* Like get_number_trailer, but don't allow a trailer. */
483 get_number (char **pp
)
485 return get_number_trailer (pp
, '\0');
488 /* Parse a number or a range.
489 * A number will be of the form handled by get_number.
490 * A range will be of the form <number1> - <number2>, and
491 * will represent all the integers between number1 and number2,
494 * While processing a range, this fuction is called iteratively;
495 * At each call it will return the next value in the range.
497 * At the beginning of parsing a range, the char pointer PP will
498 * be advanced past <number1> and left pointing at the '-' token.
499 * Subsequent calls will not advance the pointer until the range
500 * is completed. The call that completes the range will advance
501 * pointer PP past <number2>.
505 get_number_or_range (char **pp
)
507 static int last_retval
, end_value
;
508 static char *end_ptr
;
509 static int in_range
= 0;
513 /* Default case: pp is pointing either to a solo number,
514 or to the first number of a range. */
515 last_retval
= get_number_trailer (pp
, '-');
520 /* This is the start of a range (<number1> - <number2>).
521 Skip the '-', parse and remember the second number,
522 and also remember the end of the final token. */
526 while (isspace ((int) *end_ptr
))
527 end_ptr
++; /* skip white space */
528 end_value
= get_number (temp
);
529 if (end_value
< last_retval
)
531 error (_("inverted range"));
533 else if (end_value
== last_retval
)
535 /* degenerate range (number1 == number2). Advance the
536 token pointer so that the range will be treated as a
545 error (_("negative value"));
548 /* pp points to the '-' that betokens a range. All
549 number-parsing has already been done. Return the next
550 integer value (one greater than the saved previous value).
551 Do not advance the token pointer 'pp' until the end of range
554 if (++last_retval
== end_value
)
556 /* End of range reached; advance token pointer. */
566 /* condition N EXP -- set break condition of breakpoint N to EXP. */
569 condition_command (char *arg
, int from_tty
)
571 struct breakpoint
*b
;
576 error_no_arg (_("breakpoint number"));
579 bnum
= get_number (&p
);
581 error (_("Bad breakpoint argument: '%s'"), arg
);
584 if (b
->number
== bnum
)
586 struct bp_location
*loc
= b
->loc
;
587 for (; loc
; loc
= loc
->next
)
595 if (b
->cond_string
!= NULL
)
596 xfree (b
->cond_string
);
600 b
->cond_string
= NULL
;
602 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
607 /* I don't know if it matters whether this is the string the user
608 typed in or the decompiled expression. */
609 b
->cond_string
= savestring (arg
, strlen (arg
));
610 b
->condition_not_parsed
= 0;
611 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
615 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
617 error (_("Junk at end of expression"));
620 breakpoints_changed ();
621 observer_notify_breakpoint_modified (b
->number
);
625 error (_("No breakpoint number %d."), bnum
);
629 commands_command (char *arg
, int from_tty
)
631 struct breakpoint
*b
;
634 struct command_line
*l
;
636 /* If we allowed this, we would have problems with when to
637 free the storage, if we change the commands currently
640 if (executing_breakpoint_commands
)
641 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
644 bnum
= get_number (&p
);
647 error (_("Unexpected extra arguments following breakpoint number."));
650 if (b
->number
== bnum
)
652 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
654 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
655 l
= read_command_lines (tmpbuf
, from_tty
);
656 do_cleanups (cleanups
);
657 free_command_lines (&b
->commands
);
659 breakpoints_changed ();
660 observer_notify_breakpoint_modified (b
->number
);
663 error (_("No breakpoint number %d."), bnum
);
666 /* Like commands_command, but instead of reading the commands from
667 input stream, takes them from an already parsed command structure.
669 This is used by cli-script.c to DTRT with breakpoint commands
670 that are part of if and while bodies. */
671 enum command_control_type
672 commands_from_control_command (char *arg
, struct command_line
*cmd
)
674 struct breakpoint
*b
;
678 /* If we allowed this, we would have problems with when to
679 free the storage, if we change the commands currently
682 if (executing_breakpoint_commands
)
683 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
685 /* An empty string for the breakpoint number means the last
686 breakpoint, but get_number expects a NULL pointer. */
691 bnum
= get_number (&p
);
694 error (_("Unexpected extra arguments following breakpoint number."));
697 if (b
->number
== bnum
)
699 free_command_lines (&b
->commands
);
700 if (cmd
->body_count
!= 1)
701 error (_("Invalid \"commands\" block structure."));
702 /* We need to copy the commands because if/while will free the
703 list after it finishes execution. */
704 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
705 breakpoints_changed ();
706 observer_notify_breakpoint_modified (b
->number
);
707 return simple_control
;
709 error (_("No breakpoint number %d."), bnum
);
712 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
713 by replacing any memory breakpoints with their shadowed contents. */
716 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
718 struct bp_location
*b
;
719 CORE_ADDR bp_addr
= 0;
725 if (b
->owner
->type
== bp_none
)
726 warning (_("reading through apparently deleted breakpoint #%d?"),
729 if (b
->loc_type
!= bp_loc_software_breakpoint
)
733 /* Addresses and length of the part of the breakpoint that
735 bp_addr
= b
->target_info
.placed_address
;
736 bp_size
= b
->target_info
.shadow_len
;
738 /* bp isn't valid, or doesn't shadow memory. */
741 if (bp_addr
+ bp_size
<= memaddr
)
742 /* The breakpoint is entirely before the chunk of memory we
746 if (bp_addr
>= memaddr
+ len
)
747 /* The breakpoint is entirely after the chunk of memory we are
751 /* Offset within shadow_contents. */
752 if (bp_addr
< memaddr
)
754 /* Only copy the second part of the breakpoint. */
755 bp_size
-= memaddr
- bp_addr
;
756 bptoffset
= memaddr
- bp_addr
;
760 if (bp_addr
+ bp_size
> memaddr
+ len
)
762 /* Only copy the first part of the breakpoint. */
763 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
766 memcpy (buf
+ bp_addr
- memaddr
,
767 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
772 /* A wrapper function for inserting catchpoints. */
774 insert_catchpoint (struct ui_out
*uo
, void *args
)
776 struct breakpoint
*b
= (struct breakpoint
*) args
;
782 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
785 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
788 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
791 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
797 is_hardware_watchpoint (struct breakpoint
*bpt
)
799 return (bpt
->type
== bp_hardware_watchpoint
800 || bpt
->type
== bp_read_watchpoint
801 || bpt
->type
== bp_access_watchpoint
);
804 /* Find the current value of a watchpoint on EXP. Return the value in
805 *VALP and *RESULTP and the chain of intermediate and final values
806 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
809 If an error occurs while evaluating the expression, *RESULTP will
810 be set to NULL. *RESULTP may be a lazy value, if the result could
811 not be read from memory. It is used to determine whether a value
812 is user-specified (we should watch the whole value) or intermediate
813 (we should watch only the bit used to locate the final value).
815 If the final value, or any intermediate value, could not be read
816 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
817 set to any referenced values. *VALP will never be a lazy value.
818 This is the value which we store in struct breakpoint.
820 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
821 value chain. The caller must free the values individually. If
822 VAL_CHAIN is NULL, all generated values will be left on the value
826 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
827 struct value
**resultp
, struct value
**val_chain
)
829 struct value
*mark
, *new_mark
, *result
;
837 /* Evaluate the expression. */
838 mark
= value_mark ();
840 gdb_evaluate_expression (exp
, &result
);
841 new_mark
= value_mark ();
842 if (mark
== new_mark
)
847 /* Make sure it's not lazy, so that after the target stops again we
848 have a non-lazy previous value to compare with. */
850 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
855 /* Return the chain of intermediate values. We use this to
856 decide which addresses to watch. */
857 *val_chain
= new_mark
;
858 value_release_to_mark (mark
);
862 /* Assuming that B is a hardware watchpoint:
863 - Reparse watchpoint expression, is REPARSE is non-zero
864 - Evaluate expression and store the result in B->val
865 - Update the list of values that must be watched in B->loc.
867 If the watchpoint is disabled, do nothing. If this is
868 local watchpoint that is out of scope, delete it. */
870 update_watchpoint (struct breakpoint
*b
, int reparse
)
872 int within_current_scope
;
873 struct frame_id saved_frame_id
;
874 struct bp_location
*loc
;
877 /* We don't free locations. They are stored in
878 bp_location_chain and update_global_locations will
879 eventually delete them and remove breakpoints if
883 if (b
->disposition
== disp_del_at_next_stop
)
886 /* Save the current frame's ID so we can restore it after
887 evaluating the watchpoint expression on its own frame. */
888 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
889 took a frame parameter, so that we didn't have to change the
891 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
893 /* Determine if the watchpoint is within scope. */
894 if (b
->exp_valid_block
== NULL
)
895 within_current_scope
= 1;
898 struct frame_info
*fi
;
899 fi
= frame_find_by_id (b
->watchpoint_frame
);
900 within_current_scope
= (fi
!= NULL
);
901 if (within_current_scope
)
905 if (within_current_scope
&& reparse
)
914 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
915 /* If the meaning of expression itself changed, the old value is
916 no longer relevant. We don't want to report a watchpoint hit
917 to the user when the old value and the new value may actually
918 be completely different objects. */
924 /* If we failed to parse the expression, for example because
925 it refers to a global variable in a not-yet-loaded shared library,
926 don't try to insert watchpoint. We don't automatically delete
927 such watchpoint, though, since failure to parse expression
928 is different from out-of-scope watchpoint. */
929 if (within_current_scope
&& b
->exp
)
931 struct value
*val_chain
, *v
, *result
, *next
;
933 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
935 /* Avoid setting b->val if it's already set. The meaning of
936 b->val is 'the last value' user saw, and we should update
937 it only if we reported that last value to user. As it
938 happens, the code that reports it updates b->val directly. */
945 /* Look at each value on the value chain. */
946 for (v
= val_chain
; v
; v
= next
)
948 /* If it's a memory location, and GDB actually needed
949 its contents to evaluate the expression, then we
950 must watch it. If the first value returned is
951 still lazy, that means an error occurred reading it;
952 watch it anyway in case it becomes readable. */
953 if (VALUE_LVAL (v
) == lval_memory
954 && (v
== val_chain
|| ! value_lazy (v
)))
956 struct type
*vtype
= check_typedef (value_type (v
));
958 /* We only watch structs and arrays if user asked
959 for it explicitly, never if they just happen to
960 appear in the middle of some value chain. */
962 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
963 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
967 struct bp_location
*loc
, **tmp
;
969 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
970 len
= TYPE_LENGTH (value_type (v
));
972 if (b
->type
== bp_read_watchpoint
)
974 else if (b
->type
== bp_access_watchpoint
)
977 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
978 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
983 loc
->watchpoint_type
= type
;
987 next
= value_next (v
);
992 /* We just regenerated the list of breakpoint locations.
993 The new location does not have its condition field set to anything
994 and therefore, we must always reparse the cond_string, independently
995 of the value of the reparse flag. */
996 if (b
->cond_string
!= NULL
)
998 char *s
= b
->cond_string
;
999 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1002 else if (!within_current_scope
)
1004 printf_filtered (_("\
1005 Hardware watchpoint %d deleted because the program has left the block \n\
1006 in which its expression is valid.\n"),
1008 if (b
->related_breakpoint
)
1009 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1010 b
->disposition
= disp_del_at_next_stop
;
1013 /* Restore the selected frame. */
1014 select_frame (frame_find_by_id (saved_frame_id
));
1018 /* Returns 1 iff breakpoint location should be
1019 inserted in the inferior. */
1021 should_be_inserted (struct bp_location
*bpt
)
1023 if (!breakpoint_enabled (bpt
->owner
))
1026 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1029 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1035 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1036 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1037 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1039 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1040 method for each breakpoint or catchpoint type. */
1042 insert_bp_location (struct bp_location
*bpt
,
1043 struct ui_file
*tmp_error_stream
,
1044 int *disabled_breaks
, int *process_warning
,
1045 int *hw_breakpoint_error
)
1049 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1052 /* Initialize the target-specific information. */
1053 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1054 bpt
->target_info
.placed_address
= bpt
->address
;
1056 if (bpt
->loc_type
== bp_loc_software_breakpoint
1057 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1059 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1061 /* If the explicitly specified breakpoint type
1062 is not hardware breakpoint, check the memory map to see
1063 if the breakpoint address is in read only memory or not.
1064 Two important cases are:
1065 - location type is not hardware breakpoint, memory
1066 is readonly. We change the type of the location to
1067 hardware breakpoint.
1068 - location type is hardware breakpoint, memory is read-write.
1069 This means we've previously made the location hardware one, but
1070 then the memory map changed, so we undo.
1072 When breakpoints are removed, remove_breakpoints will
1073 use location types we've just set here, the only possible
1074 problem is that memory map has changed during running program,
1075 but it's not going to work anyway with current gdb. */
1076 struct mem_region
*mr
1077 = lookup_mem_region (bpt
->target_info
.placed_address
);
1081 if (automatic_hardware_breakpoints
)
1084 enum bp_loc_type new_type
;
1086 if (mr
->attrib
.mode
!= MEM_RW
)
1087 new_type
= bp_loc_hardware_breakpoint
;
1089 new_type
= bp_loc_software_breakpoint
;
1091 if (new_type
!= bpt
->loc_type
)
1093 static int said
= 0;
1094 bpt
->loc_type
= new_type
;
1097 fprintf_filtered (gdb_stdout
, _("\
1098 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1103 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1104 && mr
->attrib
.mode
!= MEM_RW
)
1105 warning (_("cannot set software breakpoint at readonly address %s"),
1106 paddr (bpt
->address
));
1110 /* First check to see if we have to handle an overlay. */
1111 if (overlay_debugging
== ovly_off
1112 || bpt
->section
== NULL
1113 || !(section_is_overlay (bpt
->section
)))
1115 /* No overlay handling: just set the breakpoint. */
1117 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1118 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1120 val
= target_insert_breakpoint (&bpt
->target_info
);
1124 /* This breakpoint is in an overlay section.
1125 Shall we set a breakpoint at the LMA? */
1126 if (!overlay_events_enabled
)
1128 /* Yes -- overlay event support is not active,
1129 so we must try to set a breakpoint at the LMA.
1130 This will not work for a hardware breakpoint. */
1131 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1132 warning (_("hardware breakpoint %d not supported in overlay!"),
1133 bpt
->owner
->number
);
1136 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1138 /* Set a software (trap) breakpoint at the LMA. */
1139 bpt
->overlay_target_info
= bpt
->target_info
;
1140 bpt
->overlay_target_info
.placed_address
= addr
;
1141 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1143 fprintf_unfiltered (tmp_error_stream
,
1144 "Overlay breakpoint %d failed: in ROM?",
1145 bpt
->owner
->number
);
1148 /* Shall we set a breakpoint at the VMA? */
1149 if (section_is_mapped (bpt
->section
))
1151 /* Yes. This overlay section is mapped into memory. */
1152 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1153 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1155 val
= target_insert_breakpoint (&bpt
->target_info
);
1159 /* No. This breakpoint will not be inserted.
1160 No error, but do not mark the bp as 'inserted'. */
1167 /* Can't set the breakpoint. */
1168 if (solib_address (bpt
->address
))
1170 /* See also: disable_breakpoints_in_shlibs. */
1172 bpt
->shlib_disabled
= 1;
1173 if (!*disabled_breaks
)
1175 fprintf_unfiltered (tmp_error_stream
,
1176 "Cannot insert breakpoint %d.\n",
1177 bpt
->owner
->number
);
1178 fprintf_unfiltered (tmp_error_stream
,
1179 "Temporarily disabling shared library breakpoints:\n");
1181 *disabled_breaks
= 1;
1182 fprintf_unfiltered (tmp_error_stream
,
1183 "breakpoint #%d\n", bpt
->owner
->number
);
1187 #ifdef ONE_PROCESS_WRITETEXT
1188 *process_warning
= 1;
1190 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1192 *hw_breakpoint_error
= 1;
1193 fprintf_unfiltered (tmp_error_stream
,
1194 "Cannot insert hardware breakpoint %d.\n",
1195 bpt
->owner
->number
);
1199 fprintf_unfiltered (tmp_error_stream
,
1200 "Cannot insert breakpoint %d.\n",
1201 bpt
->owner
->number
);
1202 fprintf_filtered (tmp_error_stream
,
1203 "Error accessing memory address ");
1204 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1205 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1206 safe_strerror (val
));
1217 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1218 /* NOTE drow/2003-09-08: This state only exists for removing
1219 watchpoints. It's not clear that it's necessary... */
1220 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1222 val
= target_insert_watchpoint (bpt
->address
,
1224 bpt
->watchpoint_type
);
1225 bpt
->inserted
= (val
!= -1);
1228 else if (bpt
->owner
->type
== bp_catch_fork
1229 || bpt
->owner
->type
== bp_catch_vfork
1230 || bpt
->owner
->type
== bp_catch_exec
)
1232 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1233 bpt
->owner
, RETURN_MASK_ERROR
);
1234 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1235 bpt
->owner
->number
);
1237 bpt
->owner
->enable_state
= bp_disabled
;
1241 /* We've already printed an error message if there was a problem
1242 inserting this catchpoint, and we've disabled the catchpoint,
1243 so just return success. */
1250 /* Make sure all breakpoints are inserted in inferior.
1251 Throws exception on any error.
1252 A breakpoint that is already inserted won't be inserted
1253 again, so calling this function twice is safe. */
1255 insert_breakpoints (void)
1257 struct breakpoint
*bpt
;
1259 ALL_BREAKPOINTS (bpt
)
1260 if (is_hardware_watchpoint (bpt
))
1261 update_watchpoint (bpt
, 0 /* don't reparse. */);
1263 update_global_location_list (1);
1265 if (!always_inserted_mode
&& target_has_execution
)
1266 /* update_global_location_list does not insert breakpoints
1267 when always_inserted_mode is not enabled. Explicitly
1269 insert_breakpoint_locations ();
1272 /* insert_breakpoints is used when starting or continuing the program.
1273 remove_breakpoints is used when the program stops.
1274 Both return zero if successful,
1275 or an `errno' value if could not write the inferior. */
1278 insert_breakpoint_locations (void)
1280 struct breakpoint
*bpt
;
1281 struct bp_location
*b
, *temp
;
1284 int disabled_breaks
= 0;
1285 int hw_breakpoint_error
= 0;
1286 int process_warning
= 0;
1288 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1289 make_cleanup_ui_file_delete (tmp_error_stream
);
1291 /* Explicitly mark the warning -- this will only be printed if
1292 there was an error. */
1293 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1295 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1297 if (!should_be_inserted (b
) || b
->inserted
)
1300 /* There is no point inserting thread-specific breakpoints if the
1301 thread no longer exists. */
1302 if (b
->owner
->thread
!= -1
1303 && !valid_thread_id (b
->owner
->thread
))
1306 val
= insert_bp_location (b
, tmp_error_stream
,
1307 &disabled_breaks
, &process_warning
,
1308 &hw_breakpoint_error
);
1313 /* If we failed to insert all locations of a watchpoint,
1314 remove them, as half-inserted watchpoint is of limited use. */
1315 ALL_BREAKPOINTS (bpt
)
1317 int some_failed
= 0;
1318 struct bp_location
*loc
;
1320 if (!is_hardware_watchpoint (bpt
))
1323 if (bpt
->enable_state
!= bp_enabled
)
1326 if (bpt
->disposition
== disp_del_at_next_stop
)
1329 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1337 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1339 remove_breakpoint (loc
, mark_uninserted
);
1341 hw_breakpoint_error
= 1;
1342 fprintf_unfiltered (tmp_error_stream
,
1343 "Could not insert hardware watchpoint %d.\n",
1351 /* If a hardware breakpoint or watchpoint was inserted, add a
1352 message about possibly exhausted resources. */
1353 if (hw_breakpoint_error
)
1355 fprintf_unfiltered (tmp_error_stream
,
1356 "Could not insert hardware breakpoints:\n\
1357 You may have requested too many hardware breakpoints/watchpoints.\n");
1359 #ifdef ONE_PROCESS_WRITETEXT
1360 if (process_warning
)
1361 fprintf_unfiltered (tmp_error_stream
,
1362 "The same program may be running in another process.");
1364 target_terminal_ours_for_output ();
1365 error_stream (tmp_error_stream
);
1370 remove_breakpoints (void)
1372 struct bp_location
*b
;
1375 ALL_BP_LOCATIONS (b
)
1379 val
= remove_breakpoint (b
, mark_uninserted
);
1388 remove_hw_watchpoints (void)
1390 struct bp_location
*b
;
1393 ALL_BP_LOCATIONS (b
)
1395 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1397 val
= remove_breakpoint (b
, mark_uninserted
);
1406 reattach_breakpoints (int pid
)
1408 struct bp_location
*b
;
1410 struct cleanup
*old_chain
= save_inferior_ptid ();
1411 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1412 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1414 make_cleanup_ui_file_delete (tmp_error_stream
);
1416 inferior_ptid
= pid_to_ptid (pid
);
1417 ALL_BP_LOCATIONS (b
)
1422 val
= insert_bp_location (b
, tmp_error_stream
,
1423 &dummy1
, &dummy2
, &dummy3
);
1426 do_cleanups (old_chain
);
1431 do_cleanups (old_chain
);
1436 update_breakpoints_after_exec (void)
1438 struct breakpoint
*b
;
1439 struct breakpoint
*temp
;
1440 struct bp_location
*bploc
;
1442 /* We're about to delete breakpoints from GDB's lists. If the
1443 INSERTED flag is true, GDB will try to lift the breakpoints by
1444 writing the breakpoints' "shadow contents" back into memory. The
1445 "shadow contents" are NOT valid after an exec, so GDB should not
1446 do that. Instead, the target is responsible from marking
1447 breakpoints out as soon as it detects an exec. We don't do that
1448 here instead, because there may be other attempts to delete
1449 breakpoints after detecting an exec and before reaching here. */
1450 ALL_BP_LOCATIONS (bploc
)
1451 gdb_assert (!bploc
->inserted
);
1453 ALL_BREAKPOINTS_SAFE (b
, temp
)
1455 /* Solib breakpoints must be explicitly reset after an exec(). */
1456 if (b
->type
== bp_shlib_event
)
1458 delete_breakpoint (b
);
1462 /* Thread event breakpoints must be set anew after an exec(),
1463 as must overlay event breakpoints. */
1464 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1466 delete_breakpoint (b
);
1470 /* Step-resume breakpoints are meaningless after an exec(). */
1471 if (b
->type
== bp_step_resume
)
1473 delete_breakpoint (b
);
1477 /* Longjmp and longjmp-resume breakpoints are also meaningless
1479 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1481 delete_breakpoint (b
);
1485 /* Don't delete an exec catchpoint, because else the inferior
1486 won't stop when it ought!
1488 Similarly, we probably ought to keep vfork catchpoints, 'cause
1489 on this target, we may not be able to stop when the vfork is
1490 seen, but only when the subsequent exec is seen. (And because
1491 deleting fork catchpoints here but not vfork catchpoints will
1492 seem mysterious to users, keep those too.) */
1493 if ((b
->type
== bp_catch_exec
) ||
1494 (b
->type
== bp_catch_vfork
) ||
1495 (b
->type
== bp_catch_fork
))
1500 /* bp_finish is a special case. The only way we ought to be able
1501 to see one of these when an exec() has happened, is if the user
1502 caught a vfork, and then said "finish". Ordinarily a finish just
1503 carries them to the call-site of the current callee, by setting
1504 a temporary bp there and resuming. But in this case, the finish
1505 will carry them entirely through the vfork & exec.
1507 We don't want to allow a bp_finish to remain inserted now. But
1508 we can't safely delete it, 'cause finish_command has a handle to
1509 the bp on a bpstat, and will later want to delete it. There's a
1510 chance (and I've seen it happen) that if we delete the bp_finish
1511 here, that its storage will get reused by the time finish_command
1512 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1513 We really must allow finish_command to delete a bp_finish.
1515 In the absense of a general solution for the "how do we know
1516 it's safe to delete something others may have handles to?"
1517 problem, what we'll do here is just uninsert the bp_finish, and
1518 let finish_command delete it.
1520 (We know the bp_finish is "doomed" in the sense that it's
1521 momentary, and will be deleted as soon as finish_command sees
1522 the inferior stopped. So it doesn't matter that the bp's
1523 address is probably bogus in the new a.out, unlike e.g., the
1524 solib breakpoints.) */
1526 if (b
->type
== bp_finish
)
1531 /* Without a symbolic address, we have little hope of the
1532 pre-exec() address meaning the same thing in the post-exec()
1534 if (b
->addr_string
== NULL
)
1536 delete_breakpoint (b
);
1540 /* FIXME what about longjmp breakpoints? Re-create them here? */
1541 create_overlay_event_breakpoint ("_ovly_debug_event");
1545 detach_breakpoints (int pid
)
1547 struct bp_location
*b
;
1549 struct cleanup
*old_chain
= save_inferior_ptid ();
1551 if (pid
== PIDGET (inferior_ptid
))
1552 error (_("Cannot detach breakpoints of inferior_ptid"));
1554 /* Set inferior_ptid; remove_breakpoint uses this global. */
1555 inferior_ptid
= pid_to_ptid (pid
);
1556 ALL_BP_LOCATIONS (b
)
1560 val
= remove_breakpoint (b
, mark_inserted
);
1563 do_cleanups (old_chain
);
1568 do_cleanups (old_chain
);
1573 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1577 if (b
->owner
->enable_state
== bp_permanent
)
1578 /* Permanent breakpoints cannot be inserted or removed. */
1581 /* The type of none suggests that owner is actually deleted.
1582 This should not ever happen. */
1583 gdb_assert (b
->owner
->type
!= bp_none
);
1585 if (b
->loc_type
== bp_loc_software_breakpoint
1586 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1588 /* "Normal" instruction breakpoint: either the standard
1589 trap-instruction bp (bp_breakpoint), or a
1590 bp_hardware_breakpoint. */
1592 /* First check to see if we have to handle an overlay. */
1593 if (overlay_debugging
== ovly_off
1594 || b
->section
== NULL
1595 || !(section_is_overlay (b
->section
)))
1597 /* No overlay handling: just remove the breakpoint. */
1599 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1600 val
= target_remove_hw_breakpoint (&b
->target_info
);
1602 val
= target_remove_breakpoint (&b
->target_info
);
1606 /* This breakpoint is in an overlay section.
1607 Did we set a breakpoint at the LMA? */
1608 if (!overlay_events_enabled
)
1610 /* Yes -- overlay event support is not active, so we
1611 should have set a breakpoint at the LMA. Remove it.
1613 /* Ignore any failures: if the LMA is in ROM, we will
1614 have already warned when we failed to insert it. */
1615 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1616 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1618 target_remove_breakpoint (&b
->overlay_target_info
);
1620 /* Did we set a breakpoint at the VMA?
1621 If so, we will have marked the breakpoint 'inserted'. */
1624 /* Yes -- remove it. Previously we did not bother to
1625 remove the breakpoint if the section had been
1626 unmapped, but let's not rely on that being safe. We
1627 don't know what the overlay manager might do. */
1628 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1629 val
= target_remove_hw_breakpoint (&b
->target_info
);
1631 /* However, we should remove *software* breakpoints only
1632 if the section is still mapped, or else we overwrite
1633 wrong code with the saved shadow contents. */
1634 else if (section_is_mapped (b
->section
))
1635 val
= target_remove_breakpoint (&b
->target_info
);
1641 /* No -- not inserted, so no need to remove. No error. */
1647 b
->inserted
= (is
== mark_inserted
);
1649 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1654 b
->inserted
= (is
== mark_inserted
);
1655 val
= target_remove_watchpoint (b
->address
, b
->length
,
1656 b
->watchpoint_type
);
1658 /* Failure to remove any of the hardware watchpoints comes here. */
1659 if ((is
== mark_uninserted
) && (b
->inserted
))
1660 warning (_("Could not remove hardware watchpoint %d."),
1663 else if ((b
->owner
->type
== bp_catch_fork
||
1664 b
->owner
->type
== bp_catch_vfork
||
1665 b
->owner
->type
== bp_catch_exec
)
1666 && breakpoint_enabled (b
->owner
)
1670 switch (b
->owner
->type
)
1673 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1675 case bp_catch_vfork
:
1676 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1679 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1682 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1687 b
->inserted
= (is
== mark_inserted
);
1693 /* Clear the "inserted" flag in all breakpoints. */
1696 mark_breakpoints_out (void)
1698 struct bp_location
*bpt
;
1700 ALL_BP_LOCATIONS (bpt
)
1704 /* Clear the "inserted" flag in all breakpoints and delete any
1705 breakpoints which should go away between runs of the program.
1707 Plus other such housekeeping that has to be done for breakpoints
1710 Note: this function gets called at the end of a run (by
1711 generic_mourn_inferior) and when a run begins (by
1712 init_wait_for_inferior). */
1717 breakpoint_init_inferior (enum inf_context context
)
1719 struct breakpoint
*b
, *temp
;
1720 struct bp_location
*bpt
;
1722 ALL_BP_LOCATIONS (bpt
)
1725 ALL_BREAKPOINTS_SAFE (b
, temp
)
1730 case bp_watchpoint_scope
:
1732 /* If the call dummy breakpoint is at the entry point it will
1733 cause problems when the inferior is rerun, so we better
1736 Also get rid of scope breakpoints. */
1737 delete_breakpoint (b
);
1741 case bp_hardware_watchpoint
:
1742 case bp_read_watchpoint
:
1743 case bp_access_watchpoint
:
1745 /* Likewise for watchpoints on local expressions. */
1746 if (b
->exp_valid_block
!= NULL
)
1747 delete_breakpoint (b
);
1748 else if (context
== inf_starting
)
1750 /* Reset val field to force reread of starting value
1751 in insert_breakpoints. */
1753 value_free (b
->val
);
1764 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1765 exists at PC. It returns ordinary_breakpoint_here if it's an
1766 ordinary breakpoint, or permanent_breakpoint_here if it's a
1767 permanent breakpoint.
1768 - When continuing from a location with an ordinary breakpoint, we
1769 actually single step once before calling insert_breakpoints.
1770 - When continuing from a localion with a permanent breakpoint, we
1771 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1772 the target, to advance the PC past the breakpoint. */
1774 enum breakpoint_here
1775 breakpoint_here_p (CORE_ADDR pc
)
1777 const struct bp_location
*bpt
;
1778 int any_breakpoint_here
= 0;
1780 ALL_BP_LOCATIONS (bpt
)
1782 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1783 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1786 if ((breakpoint_enabled (bpt
->owner
)
1787 || bpt
->owner
->enable_state
== bp_permanent
)
1788 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1790 if (overlay_debugging
1791 && section_is_overlay (bpt
->section
)
1792 && !section_is_mapped (bpt
->section
))
1793 continue; /* unmapped overlay -- can't be a match */
1794 else if (bpt
->owner
->enable_state
== bp_permanent
)
1795 return permanent_breakpoint_here
;
1797 any_breakpoint_here
= 1;
1801 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1805 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1806 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1807 This does not check for single-step breakpoints, which are
1808 inserted and removed using direct target manipulation. */
1811 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1813 const struct bp_location
*bpt
;
1815 ALL_BP_LOCATIONS (bpt
)
1817 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1818 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1822 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1824 if (overlay_debugging
1825 && section_is_overlay (bpt
->section
)
1826 && !section_is_mapped (bpt
->section
))
1827 continue; /* unmapped overlay -- can't be a match */
1835 /* Returns non-zero iff there's either regular breakpoint
1836 or a single step breakpoint inserted at PC. */
1839 breakpoint_inserted_here_p (CORE_ADDR pc
)
1841 if (regular_breakpoint_inserted_here_p (pc
))
1844 if (single_step_breakpoint_inserted_here_p (pc
))
1850 /* This function returns non-zero iff there is a software breakpoint
1854 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1856 const struct bp_location
*bpt
;
1857 int any_breakpoint_here
= 0;
1859 ALL_BP_LOCATIONS (bpt
)
1861 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1865 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1867 if (overlay_debugging
1868 && section_is_overlay (bpt
->section
)
1869 && !section_is_mapped (bpt
->section
))
1870 continue; /* unmapped overlay -- can't be a match */
1876 /* Also check for software single-step breakpoints. */
1877 if (single_step_breakpoint_inserted_here_p (pc
))
1883 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1884 PC is valid for process/thread PTID. */
1887 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1889 const struct bp_location
*bpt
;
1892 thread
= pid_to_thread_id (ptid
);
1894 ALL_BP_LOCATIONS (bpt
)
1896 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1897 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1900 if ((breakpoint_enabled (bpt
->owner
)
1901 || bpt
->owner
->enable_state
== bp_permanent
)
1902 && bpt
->address
== pc
1903 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1905 if (overlay_debugging
1906 && section_is_overlay (bpt
->section
)
1907 && !section_is_mapped (bpt
->section
))
1908 continue; /* unmapped overlay -- can't be a match */
1918 /* bpstat stuff. External routines' interfaces are documented
1922 ep_is_catchpoint (struct breakpoint
*ep
)
1925 (ep
->type
== bp_catch_load
)
1926 || (ep
->type
== bp_catch_unload
)
1927 || (ep
->type
== bp_catch_fork
)
1928 || (ep
->type
== bp_catch_vfork
)
1929 || (ep
->type
== bp_catch_exec
);
1931 /* ??rehrauer: Add more kinds here, as are implemented... */
1935 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1938 (ep
->type
== bp_catch_load
)
1939 || (ep
->type
== bp_catch_unload
);
1943 bpstat_free (bpstat bs
)
1945 if (bs
->old_val
!= NULL
)
1946 value_free (bs
->old_val
);
1947 free_command_lines (&bs
->commands
);
1951 /* Clear a bpstat so that it says we are not at any breakpoint.
1952 Also free any storage that is part of a bpstat. */
1955 bpstat_clear (bpstat
*bsp
)
1972 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1973 is part of the bpstat is copied as well. */
1976 bpstat_copy (bpstat bs
)
1980 bpstat retval
= NULL
;
1985 for (; bs
!= NULL
; bs
= bs
->next
)
1987 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1988 memcpy (tmp
, bs
, sizeof (*tmp
));
1989 if (bs
->commands
!= NULL
)
1990 tmp
->commands
= copy_command_lines (bs
->commands
);
1991 if (bs
->old_val
!= NULL
)
1993 tmp
->old_val
= value_copy (bs
->old_val
);
1994 release_value (tmp
->old_val
);
1998 /* This is the first thing in the chain. */
2008 /* Find the bpstat associated with this breakpoint */
2011 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2016 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2018 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2024 /* Find a step_resume breakpoint associated with this bpstat.
2025 (If there are multiple step_resume bp's on the list, this function
2026 will arbitrarily pick one.)
2028 It is an error to use this function if BPSTAT doesn't contain a
2029 step_resume breakpoint.
2031 See wait_for_inferior's use of this function. */
2033 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2037 gdb_assert (bsp
!= NULL
);
2039 current_thread
= pid_to_thread_id (inferior_ptid
);
2041 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2043 if ((bsp
->breakpoint_at
!= NULL
) &&
2044 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2045 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2046 bsp
->breakpoint_at
->owner
->thread
== -1))
2047 return bsp
->breakpoint_at
->owner
;
2050 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2054 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2055 at. *BSP upon return is a bpstat which points to the remaining
2056 breakpoints stopped at (but which is not guaranteed to be good for
2057 anything but further calls to bpstat_num).
2058 Return 0 if passed a bpstat which does not indicate any breakpoints.
2059 Return -1 if stopped at a breakpoint that has been deleted since
2061 Return 1 otherwise. */
2064 bpstat_num (bpstat
*bsp
, int *num
)
2066 struct breakpoint
*b
;
2069 return 0; /* No more breakpoint values */
2071 /* We assume we'll never have several bpstats that
2072 correspond to a single breakpoint -- otherwise,
2073 this function might return the same number more
2074 than once and this will look ugly. */
2075 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2076 *bsp
= (*bsp
)->next
;
2078 return -1; /* breakpoint that's been deleted since */
2080 *num
= b
->number
; /* We have its number */
2084 /* Modify BS so that the actions will not be performed. */
2087 bpstat_clear_actions (bpstat bs
)
2089 for (; bs
!= NULL
; bs
= bs
->next
)
2091 free_command_lines (&bs
->commands
);
2092 if (bs
->old_val
!= NULL
)
2094 value_free (bs
->old_val
);
2100 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2102 cleanup_executing_breakpoints (void *ignore
)
2104 executing_breakpoint_commands
= 0;
2107 /* Execute all the commands associated with all the breakpoints at this
2108 location. Any of these commands could cause the process to proceed
2109 beyond this point, etc. We look out for such changes by checking
2110 the global "breakpoint_proceeded" after each command. */
2113 bpstat_do_actions (bpstat
*bsp
)
2116 struct cleanup
*old_chain
;
2118 /* Avoid endless recursion if a `source' command is contained
2120 if (executing_breakpoint_commands
)
2123 executing_breakpoint_commands
= 1;
2124 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2127 /* Note that (as of this writing), our callers all appear to
2128 be passing us the address of global stop_bpstat. And, if
2129 our calls to execute_control_command cause the inferior to
2130 proceed, that global (and hence, *bsp) will change.
2132 We must be careful to not touch *bsp unless the inferior
2133 has not proceeded. */
2135 /* This pointer will iterate over the list of bpstat's. */
2138 breakpoint_proceeded
= 0;
2139 for (; bs
!= NULL
; bs
= bs
->next
)
2141 struct command_line
*cmd
;
2142 struct cleanup
*this_cmd_tree_chain
;
2144 /* Take ownership of the BSP's command tree, if it has one.
2146 The command tree could legitimately contain commands like
2147 'step' and 'next', which call clear_proceed_status, which
2148 frees stop_bpstat's command tree. To make sure this doesn't
2149 free the tree we're executing out from under us, we need to
2150 take ownership of the tree ourselves. Since a given bpstat's
2151 commands are only executed once, we don't need to copy it; we
2152 can clear the pointer in the bpstat, and make sure we free
2153 the tree when we're done. */
2156 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2160 execute_control_command (cmd
);
2162 if (breakpoint_proceeded
)
2168 /* We can free this command tree now. */
2169 do_cleanups (this_cmd_tree_chain
);
2171 if (breakpoint_proceeded
)
2173 if (target_can_async_p ())
2174 /* If we are in async mode, then the target might
2175 be still running, not stopped at any breakpoint,
2176 so nothing for us to do here -- just return to
2180 /* In sync mode, when execute_control_command returns
2181 we're already standing on the next breakpoint.
2182 Breakpoint commands for that stop were not run,
2183 since execute_command does not run breakpoint
2184 commands -- only command_line_handler does, but
2185 that one is not involved in execution of breakpoint
2186 commands. So, we can now execute breakpoint commands.
2187 There's an implicit assumption that we're called with
2188 stop_bpstat, so our parameter is the new bpstat to
2190 It should be noted that making execute_command do
2191 bpstat actions is not an option -- in this case we'll
2192 have recursive invocation of bpstat for each breakpoint
2193 with a command, and can easily blow up GDB stack. */
2197 do_cleanups (old_chain
);
2200 /* Print out the (old or new) value associated with a watchpoint. */
2203 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2206 fprintf_unfiltered (stream
, _("<unreadable>"));
2208 value_print (val
, stream
, 0, Val_pretty_default
);
2211 /* This is the normal print function for a bpstat. In the future,
2212 much of this logic could (should?) be moved to bpstat_stop_status,
2213 by having it set different print_it values.
2215 Current scheme: When we stop, bpstat_print() is called. It loops
2216 through the bpstat list of things causing this stop, calling the
2217 print_bp_stop_message function on each one. The behavior of the
2218 print_bp_stop_message function depends on the print_it field of
2219 bpstat. If such field so indicates, call this function here.
2221 Return values from this routine (ultimately used by bpstat_print()
2222 and normal_stop() to decide what to do):
2223 PRINT_NOTHING: Means we already printed all we needed to print,
2224 don't print anything else.
2225 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2226 that something to be followed by a location.
2227 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2228 that something to be followed by a location.
2229 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2232 static enum print_stop_action
2233 print_it_typical (bpstat bs
)
2235 struct cleanup
*old_chain
, *ui_out_chain
;
2236 struct breakpoint
*b
;
2237 const struct bp_location
*bl
;
2238 struct ui_stream
*stb
;
2240 stb
= ui_out_stream_new (uiout
);
2241 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2242 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2243 which has since been deleted. */
2244 if (bs
->breakpoint_at
== NULL
)
2245 return PRINT_UNKNOWN
;
2246 bl
= bs
->breakpoint_at
;
2252 case bp_hardware_breakpoint
:
2253 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2254 if (bl
->address
!= bl
->requested_address
)
2255 breakpoint_adjustment_warning (bl
->requested_address
,
2258 annotate_breakpoint (b
->number
);
2260 ui_out_text (uiout
, "\nTemporary breakpoint ");
2262 ui_out_text (uiout
, "\nBreakpoint ");
2263 if (ui_out_is_mi_like_p (uiout
))
2265 ui_out_field_string (uiout
, "reason",
2266 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2267 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2269 ui_out_field_int (uiout
, "bkptno", b
->number
);
2270 ui_out_text (uiout
, ", ");
2271 return PRINT_SRC_AND_LOC
;
2274 case bp_shlib_event
:
2275 /* Did we stop because the user set the stop_on_solib_events
2276 variable? (If so, we report this as a generic, "Stopped due
2277 to shlib event" message.) */
2278 printf_filtered (_("Stopped due to shared library event\n"));
2279 return PRINT_NOTHING
;
2282 case bp_thread_event
:
2283 /* Not sure how we will get here.
2284 GDB should not stop for these breakpoints. */
2285 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2286 return PRINT_NOTHING
;
2289 case bp_overlay_event
:
2290 /* By analogy with the thread event, GDB should not stop for these. */
2291 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2292 return PRINT_NOTHING
;
2296 annotate_catchpoint (b
->number
);
2297 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2299 b
->triggered_dll_pathname
);
2300 return PRINT_SRC_AND_LOC
;
2303 case bp_catch_unload
:
2304 annotate_catchpoint (b
->number
);
2305 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2307 b
->triggered_dll_pathname
);
2308 return PRINT_SRC_AND_LOC
;
2312 annotate_catchpoint (b
->number
);
2313 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2315 ptid_get_pid (b
->forked_inferior_pid
));
2316 return PRINT_SRC_AND_LOC
;
2319 case bp_catch_vfork
:
2320 annotate_catchpoint (b
->number
);
2321 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2323 ptid_get_pid (b
->forked_inferior_pid
));
2324 return PRINT_SRC_AND_LOC
;
2328 annotate_catchpoint (b
->number
);
2329 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2332 return PRINT_SRC_AND_LOC
;
2336 case bp_hardware_watchpoint
:
2337 annotate_watchpoint (b
->number
);
2338 if (ui_out_is_mi_like_p (uiout
))
2341 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2343 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2344 ui_out_text (uiout
, "\nOld value = ");
2345 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2346 ui_out_field_stream (uiout
, "old", stb
);
2347 ui_out_text (uiout
, "\nNew value = ");
2348 watchpoint_value_print (b
->val
, stb
->stream
);
2349 ui_out_field_stream (uiout
, "new", stb
);
2350 do_cleanups (ui_out_chain
);
2351 ui_out_text (uiout
, "\n");
2352 /* More than one watchpoint may have been triggered. */
2353 return PRINT_UNKNOWN
;
2356 case bp_read_watchpoint
:
2357 if (ui_out_is_mi_like_p (uiout
))
2360 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2362 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2363 ui_out_text (uiout
, "\nValue = ");
2364 watchpoint_value_print (b
->val
, stb
->stream
);
2365 ui_out_field_stream (uiout
, "value", stb
);
2366 do_cleanups (ui_out_chain
);
2367 ui_out_text (uiout
, "\n");
2368 return PRINT_UNKNOWN
;
2371 case bp_access_watchpoint
:
2372 if (bs
->old_val
!= NULL
)
2374 annotate_watchpoint (b
->number
);
2375 if (ui_out_is_mi_like_p (uiout
))
2378 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2380 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2381 ui_out_text (uiout
, "\nOld value = ");
2382 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2383 ui_out_field_stream (uiout
, "old", stb
);
2384 ui_out_text (uiout
, "\nNew value = ");
2389 if (ui_out_is_mi_like_p (uiout
))
2392 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2393 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2394 ui_out_text (uiout
, "\nValue = ");
2396 watchpoint_value_print (b
->val
, stb
->stream
);
2397 ui_out_field_stream (uiout
, "new", stb
);
2398 do_cleanups (ui_out_chain
);
2399 ui_out_text (uiout
, "\n");
2400 return PRINT_UNKNOWN
;
2403 /* Fall through, we don't deal with these types of breakpoints
2407 if (ui_out_is_mi_like_p (uiout
))
2410 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2411 return PRINT_UNKNOWN
;
2415 if (ui_out_is_mi_like_p (uiout
))
2418 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2419 return PRINT_UNKNOWN
;
2424 case bp_longjmp_resume
:
2425 case bp_step_resume
:
2426 case bp_watchpoint_scope
:
2429 return PRINT_UNKNOWN
;
2433 /* Generic routine for printing messages indicating why we
2434 stopped. The behavior of this function depends on the value
2435 'print_it' in the bpstat structure. Under some circumstances we
2436 may decide not to print anything here and delegate the task to
2439 static enum print_stop_action
2440 print_bp_stop_message (bpstat bs
)
2442 switch (bs
->print_it
)
2445 /* Nothing should be printed for this bpstat entry. */
2446 return PRINT_UNKNOWN
;
2450 /* We still want to print the frame, but we already printed the
2451 relevant messages. */
2452 return PRINT_SRC_AND_LOC
;
2455 case print_it_normal
:
2457 const struct bp_location
*bl
= bs
->breakpoint_at
;
2458 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2460 /* Normal case. Call the breakpoint's print_it method, or
2461 print_it_typical. */
2462 /* FIXME: how breakpoint can ever be NULL here? */
2463 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2464 return b
->ops
->print_it (b
);
2466 return print_it_typical (bs
);
2471 internal_error (__FILE__
, __LINE__
,
2472 _("print_bp_stop_message: unrecognized enum value"));
2477 /* Print a message indicating what happened. This is called from
2478 normal_stop(). The input to this routine is the head of the bpstat
2479 list - a list of the eventpoints that caused this stop. This
2480 routine calls the generic print routine for printing a message
2481 about reasons for stopping. This will print (for example) the
2482 "Breakpoint n," part of the output. The return value of this
2485 PRINT_UNKNOWN: Means we printed nothing
2486 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2487 code to print the location. An example is
2488 "Breakpoint 1, " which should be followed by
2490 PRINT_SRC_ONLY: Means we printed something, but there is no need
2491 to also print the location part of the message.
2492 An example is the catch/throw messages, which
2493 don't require a location appended to the end.
2494 PRINT_NOTHING: We have done some printing and we don't need any
2495 further info to be printed.*/
2497 enum print_stop_action
2498 bpstat_print (bpstat bs
)
2502 /* Maybe another breakpoint in the chain caused us to stop.
2503 (Currently all watchpoints go on the bpstat whether hit or not.
2504 That probably could (should) be changed, provided care is taken
2505 with respect to bpstat_explains_signal). */
2506 for (; bs
; bs
= bs
->next
)
2508 val
= print_bp_stop_message (bs
);
2509 if (val
== PRINT_SRC_ONLY
2510 || val
== PRINT_SRC_AND_LOC
2511 || val
== PRINT_NOTHING
)
2515 /* We reached the end of the chain, or we got a null BS to start
2516 with and nothing was printed. */
2517 return PRINT_UNKNOWN
;
2520 /* Evaluate the expression EXP and return 1 if value is zero.
2521 This is used inside a catch_errors to evaluate the breakpoint condition.
2522 The argument is a "struct expression *" that has been cast to char * to
2523 make it pass through catch_errors. */
2526 breakpoint_cond_eval (void *exp
)
2528 struct value
*mark
= value_mark ();
2529 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2530 value_free_to_mark (mark
);
2534 /* Allocate a new bpstat and chain it to the current one. */
2537 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2541 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2543 bs
->breakpoint_at
= bl
;
2544 /* If the condition is false, etc., don't do the commands. */
2545 bs
->commands
= NULL
;
2547 bs
->print_it
= print_it_normal
;
2551 /* The target has stopped with waitstatus WS. Check if any hardware
2552 watchpoints have triggered, according to the target. */
2555 watchpoints_triggered (struct target_waitstatus
*ws
)
2557 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2559 struct breakpoint
*b
;
2561 if (!stopped_by_watchpoint
)
2563 /* We were not stopped by a watchpoint. Mark all watchpoints
2564 as not triggered. */
2566 if (b
->type
== bp_hardware_watchpoint
2567 || b
->type
== bp_read_watchpoint
2568 || b
->type
== bp_access_watchpoint
)
2569 b
->watchpoint_triggered
= watch_triggered_no
;
2574 if (!target_stopped_data_address (¤t_target
, &addr
))
2576 /* We were stopped by a watchpoint, but we don't know where.
2577 Mark all watchpoints as unknown. */
2579 if (b
->type
== bp_hardware_watchpoint
2580 || b
->type
== bp_read_watchpoint
2581 || b
->type
== bp_access_watchpoint
)
2582 b
->watchpoint_triggered
= watch_triggered_unknown
;
2584 return stopped_by_watchpoint
;
2587 /* The target could report the data address. Mark watchpoints
2588 affected by this data address as triggered, and all others as not
2592 if (b
->type
== bp_hardware_watchpoint
2593 || b
->type
== bp_read_watchpoint
2594 || b
->type
== bp_access_watchpoint
)
2596 struct bp_location
*loc
;
2599 b
->watchpoint_triggered
= watch_triggered_no
;
2600 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2601 /* Exact match not required. Within range is
2603 if (target_watchpoint_addr_within_range (¤t_target
,
2607 b
->watchpoint_triggered
= watch_triggered_yes
;
2615 /* Possible return values for watchpoint_check (this can't be an enum
2616 because of check_errors). */
2617 /* The watchpoint has been deleted. */
2618 #define WP_DELETED 1
2619 /* The value has changed. */
2620 #define WP_VALUE_CHANGED 2
2621 /* The value has not changed. */
2622 #define WP_VALUE_NOT_CHANGED 3
2624 #define BP_TEMPFLAG 1
2625 #define BP_HARDWAREFLAG 2
2627 /* Check watchpoint condition. */
2630 watchpoint_check (void *p
)
2632 bpstat bs
= (bpstat
) p
;
2633 struct breakpoint
*b
;
2634 struct frame_info
*fr
;
2635 int within_current_scope
;
2637 b
= bs
->breakpoint_at
->owner
;
2639 if (b
->exp_valid_block
== NULL
)
2640 within_current_scope
= 1;
2643 /* There is no current frame at this moment. If we're going to have
2644 any chance of handling watchpoints on local variables, we'll need
2645 the frame chain (so we can determine if we're in scope). */
2646 reinit_frame_cache ();
2647 fr
= frame_find_by_id (b
->watchpoint_frame
);
2648 within_current_scope
= (fr
!= NULL
);
2650 /* If we've gotten confused in the unwinder, we might have
2651 returned a frame that can't describe this variable. */
2652 if (within_current_scope
2653 && (block_linkage_function (b
->exp_valid_block
)
2654 != get_frame_function (fr
)))
2655 within_current_scope
= 0;
2657 /* in_function_epilogue_p() returns a non-zero value if we're still
2658 in the function but the stack frame has already been invalidated.
2659 Since we can't rely on the values of local variables after the
2660 stack has been destroyed, we are treating the watchpoint in that
2661 state as `not changed' without further checking.
2663 vinschen/2003-09-04: The former implementation left out the case
2664 that the watchpoint frame couldn't be found by frame_find_by_id()
2665 because the current PC is currently in an epilogue. Calling
2666 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2667 if ((!within_current_scope
|| fr
== get_current_frame ())
2668 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2669 return WP_VALUE_NOT_CHANGED
;
2670 if (fr
&& within_current_scope
)
2671 /* If we end up stopping, the current frame will get selected
2672 in normal_stop. So this call to select_frame won't affect
2677 if (within_current_scope
)
2679 /* We use value_{,free_to_}mark because it could be a
2680 *long* time before we return to the command level and
2681 call free_all_values. We can't call free_all_values because
2682 we might be in the middle of evaluating a function call. */
2684 struct value
*mark
= value_mark ();
2685 struct value
*new_val
;
2687 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2688 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2689 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2691 if (new_val
!= NULL
)
2693 release_value (new_val
);
2694 value_free_to_mark (mark
);
2696 bs
->old_val
= b
->val
;
2699 /* We will stop here */
2700 return WP_VALUE_CHANGED
;
2704 /* Nothing changed, don't do anything. */
2705 value_free_to_mark (mark
);
2706 /* We won't stop here */
2707 return WP_VALUE_NOT_CHANGED
;
2712 /* This seems like the only logical thing to do because
2713 if we temporarily ignored the watchpoint, then when
2714 we reenter the block in which it is valid it contains
2715 garbage (in the case of a function, it may have two
2716 garbage values, one before and one after the prologue).
2717 So we can't even detect the first assignment to it and
2718 watch after that (since the garbage may or may not equal
2719 the first value assigned). */
2720 /* We print all the stop information in print_it_typical(), but
2721 in this case, by the time we call print_it_typical() this bp
2722 will be deleted already. So we have no choice but print the
2723 information here. */
2724 if (ui_out_is_mi_like_p (uiout
))
2726 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2727 ui_out_text (uiout
, "\nWatchpoint ");
2728 ui_out_field_int (uiout
, "wpnum", b
->number
);
2729 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2730 which its expression is valid.\n");
2732 if (b
->related_breakpoint
)
2733 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2734 b
->disposition
= disp_del_at_next_stop
;
2740 /* Return true if it looks like target has stopped due to hitting
2741 breakpoint location BL. This function does not check if we
2742 should stop, only if BL explains the stop. */
2744 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2746 struct breakpoint
*b
= bl
->owner
;
2748 if (b
->type
!= bp_watchpoint
2749 && b
->type
!= bp_hardware_watchpoint
2750 && b
->type
!= bp_read_watchpoint
2751 && b
->type
!= bp_access_watchpoint
2752 && b
->type
!= bp_hardware_breakpoint
2753 && b
->type
!= bp_catch_fork
2754 && b
->type
!= bp_catch_vfork
2755 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2757 if (bl
->address
!= bp_addr
) /* address doesn't match */
2759 if (overlay_debugging
/* unmapped overlay section */
2760 && section_is_overlay (bl
->section
)
2761 && !section_is_mapped (bl
->section
))
2765 /* Continuable hardware watchpoints are treated as non-existent if the
2766 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2767 some data address). Otherwise gdb won't stop on a break instruction
2768 in the code (not from a breakpoint) when a hardware watchpoint has
2769 been defined. Also skip watchpoints which we know did not trigger
2770 (did not match the data address). */
2772 if ((b
->type
== bp_hardware_watchpoint
2773 || b
->type
== bp_read_watchpoint
2774 || b
->type
== bp_access_watchpoint
)
2775 && b
->watchpoint_triggered
== watch_triggered_no
)
2778 if (b
->type
== bp_hardware_breakpoint
)
2780 if (bl
->address
!= bp_addr
)
2782 if (overlay_debugging
/* unmapped overlay section */
2783 && section_is_overlay (bl
->section
)
2784 && !section_is_mapped (bl
->section
))
2788 /* Is this a catchpoint of a load or unload? If so, did we
2789 get a load or unload of the specified library? If not,
2791 if ((b
->type
== bp_catch_load
)
2792 #if defined(SOLIB_HAVE_LOAD_EVENT)
2793 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2794 || ((b
->dll_pathname
!= NULL
)
2795 && (strcmp (b
->dll_pathname
,
2796 SOLIB_LOADED_LIBRARY_PATHNAME (
2797 PIDGET (inferior_ptid
)))
2803 if ((b
->type
== bp_catch_unload
)
2804 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2805 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2806 || ((b
->dll_pathname
!= NULL
)
2807 && (strcmp (b
->dll_pathname
,
2808 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2809 PIDGET (inferior_ptid
)))
2815 if ((b
->type
== bp_catch_fork
)
2816 && !inferior_has_forked (inferior_ptid
,
2817 &b
->forked_inferior_pid
))
2820 if ((b
->type
== bp_catch_vfork
)
2821 && !inferior_has_vforked (inferior_ptid
,
2822 &b
->forked_inferior_pid
))
2825 if ((b
->type
== bp_catch_exec
)
2826 && !inferior_has_execd (inferior_ptid
, &b
->exec_pathname
))
2832 /* If BS refers to a watchpoint, determine if the watched values
2833 has actually changed, and we should stop. If not, set BS->stop
2836 bpstat_check_watchpoint (bpstat bs
)
2838 const struct bp_location
*bl
= bs
->breakpoint_at
;
2839 struct breakpoint
*b
= bl
->owner
;
2841 if (b
->type
== bp_watchpoint
2842 || b
->type
== bp_read_watchpoint
2843 || b
->type
== bp_access_watchpoint
2844 || b
->type
== bp_hardware_watchpoint
)
2848 int must_check_value
= 0;
2850 if (b
->type
== bp_watchpoint
)
2851 /* For a software watchpoint, we must always check the
2853 must_check_value
= 1;
2854 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2855 /* We have a hardware watchpoint (read, write, or access)
2856 and the target earlier reported an address watched by
2858 must_check_value
= 1;
2859 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2860 && b
->type
== bp_hardware_watchpoint
)
2861 /* We were stopped by a hardware watchpoint, but the target could
2862 not report the data address. We must check the watchpoint's
2863 value. Access and read watchpoints are out of luck; without
2864 a data address, we can't figure it out. */
2865 must_check_value
= 1;
2867 if (must_check_value
)
2869 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2871 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2872 int e
= catch_errors (watchpoint_check
, bs
, message
,
2874 do_cleanups (cleanups
);
2878 /* We've already printed what needs to be printed. */
2879 bs
->print_it
= print_it_done
;
2882 case WP_VALUE_CHANGED
:
2883 if (b
->type
== bp_read_watchpoint
)
2885 /* Don't stop: read watchpoints shouldn't fire if
2886 the value has changed. This is for targets
2887 which cannot set read-only watchpoints. */
2888 bs
->print_it
= print_it_noop
;
2892 case WP_VALUE_NOT_CHANGED
:
2893 if (b
->type
== bp_hardware_watchpoint
2894 || b
->type
== bp_watchpoint
)
2896 /* Don't stop: write watchpoints shouldn't fire if
2897 the value hasn't changed. */
2898 bs
->print_it
= print_it_noop
;
2906 /* Error from catch_errors. */
2907 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2908 if (b
->related_breakpoint
)
2909 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2910 b
->disposition
= disp_del_at_next_stop
;
2911 /* We've already printed what needs to be printed. */
2912 bs
->print_it
= print_it_done
;
2916 else /* must_check_value == 0 */
2918 /* This is a case where some watchpoint(s) triggered, but
2919 not at the address of this watchpoint, or else no
2920 watchpoint triggered after all. So don't print
2921 anything for this watchpoint. */
2922 bs
->print_it
= print_it_noop
;
2929 /* Check conditions (condition proper, frame, thread and ignore count)
2930 of breakpoint referred to by BS. If we should not stop for this
2931 breakpoint, set BS->stop to 0. */
2933 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2935 int thread_id
= pid_to_thread_id (ptid
);
2936 const struct bp_location
*bl
= bs
->breakpoint_at
;
2937 struct breakpoint
*b
= bl
->owner
;
2939 if (frame_id_p (b
->frame_id
)
2940 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2944 int value_is_zero
= 0;
2946 /* If this is a scope breakpoint, mark the associated
2947 watchpoint as triggered so that we will handle the
2948 out-of-scope event. We'll get to the watchpoint next
2950 if (b
->type
== bp_watchpoint_scope
)
2951 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2953 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2955 /* Need to select the frame, with all that implies
2956 so that the conditions will have the right context. */
2957 select_frame (get_current_frame ());
2959 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2960 "Error in testing breakpoint condition:\n",
2962 /* FIXME-someday, should give breakpoint # */
2965 if (bl
->cond
&& value_is_zero
)
2969 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2973 else if (b
->ignore_count
> 0)
2976 annotate_ignore_count_change ();
2978 /* Increase the hit count even though we don't
2986 /* Get a bpstat associated with having just stopped at address
2987 BP_ADDR in thread PTID.
2989 Determine whether we stopped at a breakpoint, etc, or whether we
2990 don't understand this stop. Result is a chain of bpstat's such that:
2992 if we don't understand the stop, the result is a null pointer.
2994 if we understand why we stopped, the result is not null.
2996 Each element of the chain refers to a particular breakpoint or
2997 watchpoint at which we have stopped. (We may have stopped for
2998 several reasons concurrently.)
3000 Each element of the chain has valid next, breakpoint_at,
3001 commands, FIXME??? fields. */
3004 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3006 struct breakpoint
*b
= NULL
;
3007 const struct bp_location
*bl
;
3008 struct bp_location
*loc
;
3009 /* Root of the chain of bpstat's */
3010 struct bpstats root_bs
[1];
3011 /* Pointer to the last thing in the chain currently. */
3012 bpstat bs
= root_bs
;
3015 ALL_BP_LOCATIONS (bl
)
3019 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3022 /* For hardware watchpoints, we look only at the first location.
3023 The watchpoint_check function will work on entire expression,
3024 not the individual locations. For read watchopints, the
3025 watchpoints_triggered function have checked all locations
3028 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3031 if (!bpstat_check_location (bl
, bp_addr
))
3034 /* Come here if it's a watchpoint, or if the break address matches */
3036 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3038 /* Assume we stop. Should we find watchpoint that is not actually
3039 triggered, or if condition of breakpoint is false, we'll reset
3044 bpstat_check_watchpoint (bs
);
3048 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3049 /* We do not stop for these. */
3052 bpstat_check_breakpoint_conditions (bs
, ptid
);
3058 /* We will stop here */
3059 if (b
->disposition
== disp_disable
)
3061 b
->enable_state
= bp_disabled
;
3062 update_global_location_list (0);
3066 bs
->commands
= b
->commands
;
3068 (strcmp ("silent", bs
->commands
->line
) == 0
3069 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3071 bs
->commands
= bs
->commands
->next
;
3074 bs
->commands
= copy_command_lines (bs
->commands
);
3077 /* Print nothing for this entry if we dont stop or if we dont print. */
3078 if (bs
->stop
== 0 || bs
->print
== 0)
3079 bs
->print_it
= print_it_noop
;
3082 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3084 if (loc
->address
== bp_addr
)
3086 bs
= bpstat_alloc (loc
, bs
);
3087 /* For hits of moribund locations, we should just proceed. */
3090 bs
->print_it
= print_it_noop
;
3094 bs
->next
= NULL
; /* Terminate the chain */
3095 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3097 /* If we aren't stopping, the value of some hardware watchpoint may
3098 not have changed, but the intermediate memory locations we are
3099 watching may have. Don't bother if we're stopping; this will get
3101 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3106 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3108 && bs
->breakpoint_at
->owner
3109 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3110 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3111 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3113 /* remove/insert can invalidate bs->breakpoint_at, if this
3114 location is no longer used by the watchpoint. Prevent
3115 further code from trying to use it. */
3116 bs
->breakpoint_at
= NULL
;
3117 remove_breakpoints ();
3118 insert_breakpoints ();
3122 return root_bs
->next
;
3125 /* Tell what to do about this bpstat. */
3127 bpstat_what (bpstat bs
)
3129 /* Classify each bpstat as one of the following. */
3132 /* This bpstat element has no effect on the main_action. */
3135 /* There was a watchpoint, stop but don't print. */
3138 /* There was a watchpoint, stop and print. */
3141 /* There was a breakpoint but we're not stopping. */
3144 /* There was a breakpoint, stop but don't print. */
3147 /* There was a breakpoint, stop and print. */
3150 /* We hit the longjmp breakpoint. */
3153 /* We hit the longjmp_resume breakpoint. */
3156 /* We hit the step_resume breakpoint. */
3159 /* We hit the shared library event breakpoint. */
3162 /* We caught a shared library event. */
3165 /* This is just used to count how many enums there are. */
3169 /* Here is the table which drives this routine. So that we can
3170 format it pretty, we define some abbreviations for the
3171 enum bpstat_what codes. */
3172 #define kc BPSTAT_WHAT_KEEP_CHECKING
3173 #define ss BPSTAT_WHAT_STOP_SILENT
3174 #define sn BPSTAT_WHAT_STOP_NOISY
3175 #define sgl BPSTAT_WHAT_SINGLE
3176 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3177 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3178 #define sr BPSTAT_WHAT_STEP_RESUME
3179 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3180 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3182 /* "Can't happen." Might want to print an error message.
3183 abort() is not out of the question, but chances are GDB is just
3184 a bit confused, not unusable. */
3185 #define err BPSTAT_WHAT_STOP_NOISY
3187 /* Given an old action and a class, come up with a new action. */
3188 /* One interesting property of this table is that wp_silent is the same
3189 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3190 after stopping, the check for whether to step over a breakpoint
3191 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3192 reference to how we stopped. We retain separate wp_silent and
3193 bp_silent codes in case we want to change that someday.
3195 Another possibly interesting property of this table is that
3196 there's a partial ordering, priority-like, of the actions. Once
3197 you've decided that some action is appropriate, you'll never go
3198 back and decide something of a lower priority is better. The
3201 kc < clr sgl shl shlr slr sn sr ss
3202 sgl < shl shlr slr sn sr ss
3203 slr < err shl shlr sn sr ss
3204 clr < err shl shlr sn sr ss
3211 What I think this means is that we don't need a damned table
3212 here. If you just put the rows and columns in the right order,
3213 it'd look awfully regular. We could simply walk the bpstat list
3214 and choose the highest priority action we find, with a little
3215 logic to handle the 'err' cases. */
3217 /* step_resume entries: a step resume breakpoint overrides another
3218 breakpoint of signal handling (see comment in wait_for_inferior
3219 at where we set the step_resume breakpoint). */
3221 static const enum bpstat_what_main_action
3222 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3225 /* kc ss sn sgl slr clr sr shl shlr
3228 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3230 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3232 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3234 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3236 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3238 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3240 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3242 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3244 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3246 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3248 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3262 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3263 struct bpstat_what retval
;
3265 retval
.call_dummy
= 0;
3266 for (; bs
!= NULL
; bs
= bs
->next
)
3268 enum class bs_class
= no_effect
;
3269 if (bs
->breakpoint_at
== NULL
)
3270 /* I suspect this can happen if it was a momentary breakpoint
3271 which has since been deleted. */
3273 if (bs
->breakpoint_at
->owner
== NULL
)
3274 bs_class
= bp_nostop
;
3276 switch (bs
->breakpoint_at
->owner
->type
)
3282 case bp_hardware_breakpoint
:
3288 bs_class
= bp_noisy
;
3290 bs_class
= bp_silent
;
3293 bs_class
= bp_nostop
;
3296 case bp_hardware_watchpoint
:
3297 case bp_read_watchpoint
:
3298 case bp_access_watchpoint
:
3302 bs_class
= wp_noisy
;
3304 bs_class
= wp_silent
;
3307 /* There was a watchpoint, but we're not stopping.
3308 This requires no further action. */
3309 bs_class
= no_effect
;
3312 bs_class
= long_jump
;
3314 case bp_longjmp_resume
:
3315 bs_class
= long_resume
;
3317 case bp_step_resume
:
3320 bs_class
= step_resume
;
3323 /* It is for the wrong frame. */
3324 bs_class
= bp_nostop
;
3326 case bp_watchpoint_scope
:
3327 bs_class
= bp_nostop
;
3329 case bp_shlib_event
:
3330 bs_class
= shlib_event
;
3332 case bp_thread_event
:
3333 case bp_overlay_event
:
3334 bs_class
= bp_nostop
;
3337 case bp_catch_unload
:
3338 /* Only if this catchpoint triggered should we cause the
3339 step-out-of-dld behaviour. Otherwise, we ignore this
3342 bs_class
= catch_shlib_event
;
3344 bs_class
= no_effect
;
3347 case bp_catch_vfork
:
3352 bs_class
= bp_noisy
;
3354 bs_class
= bp_silent
;
3357 /* There was a catchpoint, but we're not stopping.
3358 This requires no further action. */
3359 bs_class
= no_effect
;
3362 /* Make sure the action is stop (silent or noisy),
3363 so infrun.c pops the dummy frame. */
3364 bs_class
= bp_silent
;
3365 retval
.call_dummy
= 1;
3368 current_action
= table
[(int) bs_class
][(int) current_action
];
3370 retval
.main_action
= current_action
;
3374 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3375 without hardware support). This isn't related to a specific bpstat,
3376 just to things like whether watchpoints are set. */
3379 bpstat_should_step (void)
3381 struct breakpoint
*b
;
3383 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3390 /* Given a bpstat that records zero or more triggered eventpoints, this
3391 function returns another bpstat which contains only the catchpoints
3392 on that first list, if any. */
3394 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3396 struct bpstats root_bs
[1];
3397 bpstat bs
= root_bs
;
3398 struct breakpoint
*ep
;
3401 bpstat_clear (cp_list
);
3402 root_bs
->next
= NULL
;
3404 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3406 /* Is this eventpoint a catchpoint? If not, ignore it. */
3407 ep
= ep_list
->breakpoint_at
->owner
;
3410 if ((ep
->type
!= bp_catch_load
) &&
3411 (ep
->type
!= bp_catch_unload
))
3412 /* pai: (temp) ADD fork/vfork here!! */
3415 /* Yes; add it to the list. */
3416 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3421 #if defined(SOLIB_ADD)
3422 /* Also, for each triggered catchpoint, tag it with the name of
3423 the library that caused this trigger. (We copy the name now,
3424 because it's only guaranteed to be available NOW, when the
3425 catchpoint triggers. Clients who may wish to know the name
3426 later must get it from the catchpoint itself.) */
3427 if (ep
->triggered_dll_pathname
!= NULL
)
3428 xfree (ep
->triggered_dll_pathname
);
3429 if (ep
->type
== bp_catch_load
)
3430 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3431 PIDGET (inferior_ptid
));
3433 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3434 PIDGET (inferior_ptid
));
3436 dll_pathname
= NULL
;
3440 ep
->triggered_dll_pathname
= (char *)
3441 xmalloc (strlen (dll_pathname
) + 1);
3442 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3445 ep
->triggered_dll_pathname
= NULL
;
3451 static void print_breakpoint_location (struct breakpoint
*b
,
3452 struct bp_location
*loc
,
3454 struct ui_stream
*stb
)
3459 = find_pc_sect_function (loc
->address
, loc
->section
);
3462 ui_out_text (uiout
, "in ");
3463 ui_out_field_string (uiout
, "func",
3464 SYMBOL_PRINT_NAME (sym
));
3465 ui_out_wrap_hint (uiout
, wrap_indent
);
3466 ui_out_text (uiout
, " at ");
3468 ui_out_field_string (uiout
, "file", b
->source_file
);
3469 ui_out_text (uiout
, ":");
3471 if (ui_out_is_mi_like_p (uiout
))
3473 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3474 char *fullname
= symtab_to_fullname (sal
.symtab
);
3477 ui_out_field_string (uiout
, "fullname", fullname
);
3480 ui_out_field_int (uiout
, "line", b
->line_number
);
3484 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3488 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3489 ui_out_field_stream (uiout
, "at", stb
);
3493 /* Print B to gdb_stdout. */
3495 print_one_breakpoint_location (struct breakpoint
*b
,
3496 struct bp_location
*loc
,
3498 CORE_ADDR
*last_addr
)
3500 struct command_line
*l
;
3502 struct ep_type_description
3507 static struct ep_type_description bptypes
[] =
3509 {bp_none
, "?deleted?"},
3510 {bp_breakpoint
, "breakpoint"},
3511 {bp_hardware_breakpoint
, "hw breakpoint"},
3512 {bp_until
, "until"},
3513 {bp_finish
, "finish"},
3514 {bp_watchpoint
, "watchpoint"},
3515 {bp_hardware_watchpoint
, "hw watchpoint"},
3516 {bp_read_watchpoint
, "read watchpoint"},
3517 {bp_access_watchpoint
, "acc watchpoint"},
3518 {bp_longjmp
, "longjmp"},
3519 {bp_longjmp_resume
, "longjmp resume"},
3520 {bp_step_resume
, "step resume"},
3521 {bp_watchpoint_scope
, "watchpoint scope"},
3522 {bp_call_dummy
, "call dummy"},
3523 {bp_shlib_event
, "shlib events"},
3524 {bp_thread_event
, "thread events"},
3525 {bp_overlay_event
, "overlay events"},
3526 {bp_catch_load
, "catch load"},
3527 {bp_catch_unload
, "catch unload"},
3528 {bp_catch_fork
, "catch fork"},
3529 {bp_catch_vfork
, "catch vfork"},
3530 {bp_catch_exec
, "catch exec"}
3533 static char bpenables
[] = "nynny";
3534 char wrap_indent
[80];
3535 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3536 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3537 struct cleanup
*bkpt_chain
;
3539 int header_of_multiple
= 0;
3540 int part_of_multiple
= (loc
!= NULL
);
3542 gdb_assert (!loc
|| loc_number
!= 0);
3543 /* See comment in print_one_breakpoint concerning
3544 treatment of breakpoints with single disabled
3548 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3549 header_of_multiple
= 1;
3554 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3558 if (part_of_multiple
)
3561 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3562 ui_out_field_string (uiout
, "number", formatted
);
3567 ui_out_field_int (uiout
, "number", b
->number
);
3572 if (part_of_multiple
)
3573 ui_out_field_skip (uiout
, "type");
3576 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3577 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3578 internal_error (__FILE__
, __LINE__
,
3579 _("bptypes table does not describe type #%d."),
3581 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3586 if (part_of_multiple
)
3587 ui_out_field_skip (uiout
, "disp");
3589 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3594 if (part_of_multiple
)
3595 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3597 ui_out_field_fmt (uiout
, "enabled", "%c",
3598 bpenables
[(int) b
->enable_state
]);
3599 ui_out_spaces (uiout
, 2);
3603 strcpy (wrap_indent
, " ");
3606 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3607 strcat (wrap_indent
, " ");
3609 strcat (wrap_indent
, " ");
3612 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3614 /* Although the print_one can possibly print
3615 all locations, calling it here is not likely
3616 to get any nice result. So, make sure there's
3617 just one location. */
3618 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3619 b
->ops
->print_one (b
, last_addr
);
3625 internal_error (__FILE__
, __LINE__
,
3626 _("print_one_breakpoint: bp_none encountered\n"));
3630 case bp_hardware_watchpoint
:
3631 case bp_read_watchpoint
:
3632 case bp_access_watchpoint
:
3633 /* Field 4, the address, is omitted (which makes the columns
3634 not line up too nicely with the headers, but the effect
3635 is relatively readable). */
3637 ui_out_field_skip (uiout
, "addr");
3639 print_expression (b
->exp
, stb
->stream
);
3640 ui_out_field_stream (uiout
, "what", stb
);
3644 case bp_catch_unload
:
3645 /* Field 4, the address, is omitted (which makes the columns
3646 not line up too nicely with the headers, but the effect
3647 is relatively readable). */
3649 ui_out_field_skip (uiout
, "addr");
3651 if (b
->dll_pathname
== NULL
)
3653 ui_out_field_string (uiout
, "what", "<any library>");
3654 ui_out_spaces (uiout
, 1);
3658 ui_out_text (uiout
, "library \"");
3659 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3660 ui_out_text (uiout
, "\" ");
3665 case bp_catch_vfork
:
3666 /* Field 4, the address, is omitted (which makes the columns
3667 not line up too nicely with the headers, but the effect
3668 is relatively readable). */
3670 ui_out_field_skip (uiout
, "addr");
3672 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
3674 ui_out_text (uiout
, "process ");
3675 ui_out_field_int (uiout
, "what",
3676 ptid_get_pid (b
->forked_inferior_pid
));
3677 ui_out_spaces (uiout
, 1);
3682 /* Field 4, the address, is omitted (which makes the columns
3683 not line up too nicely with the headers, but the effect
3684 is relatively readable). */
3686 ui_out_field_skip (uiout
, "addr");
3688 if (b
->exec_pathname
!= NULL
)
3690 ui_out_text (uiout
, "program \"");
3691 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3692 ui_out_text (uiout
, "\" ");
3697 case bp_hardware_breakpoint
:
3701 case bp_longjmp_resume
:
3702 case bp_step_resume
:
3703 case bp_watchpoint_scope
:
3705 case bp_shlib_event
:
3706 case bp_thread_event
:
3707 case bp_overlay_event
:
3711 if (header_of_multiple
)
3712 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3713 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3714 ui_out_field_string (uiout
, "addr", "<PENDING>");
3716 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3719 if (!header_of_multiple
)
3720 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3722 *last_addr
= b
->loc
->address
;
3726 if (!part_of_multiple
&& b
->thread
!= -1)
3728 /* FIXME: This seems to be redundant and lost here; see the
3729 "stop only in" line a little further down. */
3730 ui_out_text (uiout
, " thread ");
3731 ui_out_field_int (uiout
, "thread", b
->thread
);
3734 ui_out_text (uiout
, "\n");
3736 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3739 ui_out_text (uiout
, "\tstop only in stack frame at ");
3740 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3742 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3743 ui_out_text (uiout
, "\n");
3746 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3748 /* We do not print the condition for Ada exception catchpoints
3749 because the condition is an internal implementation detail
3750 that we do not want to expose to the user. */
3752 ui_out_text (uiout
, "\tstop only if ");
3753 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3754 ui_out_text (uiout
, "\n");
3757 if (!part_of_multiple
&& b
->thread
!= -1)
3759 /* FIXME should make an annotation for this */
3760 ui_out_text (uiout
, "\tstop only in thread ");
3761 ui_out_field_int (uiout
, "thread", b
->thread
);
3762 ui_out_text (uiout
, "\n");
3765 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3767 /* FIXME should make an annotation for this */
3768 if (ep_is_catchpoint (b
))
3769 ui_out_text (uiout
, "\tcatchpoint");
3771 ui_out_text (uiout
, "\tbreakpoint");
3772 ui_out_text (uiout
, " already hit ");
3773 ui_out_field_int (uiout
, "times", b
->hit_count
);
3774 if (b
->hit_count
== 1)
3775 ui_out_text (uiout
, " time\n");
3777 ui_out_text (uiout
, " times\n");
3780 /* Output the count also if it is zero, but only if this is
3781 mi. FIXME: Should have a better test for this. */
3782 if (ui_out_is_mi_like_p (uiout
))
3783 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3784 ui_out_field_int (uiout
, "times", b
->hit_count
);
3786 if (!part_of_multiple
&& b
->ignore_count
)
3789 ui_out_text (uiout
, "\tignore next ");
3790 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3791 ui_out_text (uiout
, " hits\n");
3794 if (!part_of_multiple
&& (l
= b
->commands
))
3796 struct cleanup
*script_chain
;
3799 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3800 print_command_lines (uiout
, l
, 4);
3801 do_cleanups (script_chain
);
3804 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3807 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3808 else if (b
->exp_string
)
3809 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3812 do_cleanups (bkpt_chain
);
3813 do_cleanups (old_chain
);
3817 print_one_breakpoint (struct breakpoint
*b
,
3818 CORE_ADDR
*last_addr
)
3820 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3822 /* If this breakpoint has custom print function,
3823 it's already printed. Otherwise, print individual
3824 locations, if any. */
3825 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3827 /* If breakpoint has a single location that is
3828 disabled, we print it as if it had
3829 several locations, since otherwise it's hard to
3830 represent "breakpoint enabled, location disabled"
3832 Note that while hardware watchpoints have
3833 several locations internally, that's no a property
3836 && !is_hardware_watchpoint (b
)
3837 && (b
->loc
->next
|| !b
->loc
->enabled
)
3838 && !ui_out_is_mi_like_p (uiout
))
3840 struct bp_location
*loc
;
3842 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3843 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3849 struct captured_breakpoint_query_args
3855 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3857 struct captured_breakpoint_query_args
*args
= data
;
3858 struct breakpoint
*b
;
3859 CORE_ADDR dummy_addr
= 0;
3862 if (args
->bnum
== b
->number
)
3864 print_one_breakpoint (b
, &dummy_addr
);
3872 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3874 struct captured_breakpoint_query_args args
;
3876 /* For the moment we don't trust print_one_breakpoint() to not throw
3878 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3879 error_message
, RETURN_MASK_ALL
) < 0)
3885 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3886 catchpoints, et.al.). */
3889 user_settable_breakpoint (const struct breakpoint
*b
)
3891 return (b
->type
== bp_breakpoint
3892 || b
->type
== bp_catch_load
3893 || b
->type
== bp_catch_unload
3894 || b
->type
== bp_catch_fork
3895 || b
->type
== bp_catch_vfork
3896 || b
->type
== bp_catch_exec
3897 || b
->type
== bp_hardware_breakpoint
3898 || b
->type
== bp_watchpoint
3899 || b
->type
== bp_read_watchpoint
3900 || b
->type
== bp_access_watchpoint
3901 || b
->type
== bp_hardware_watchpoint
);
3904 /* Print information on user settable breakpoint (watchpoint, etc)
3905 number BNUM. If BNUM is -1 print all user settable breakpoints.
3906 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3909 breakpoint_1 (int bnum
, int allflag
)
3911 struct breakpoint
*b
;
3912 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3913 int nr_printable_breakpoints
;
3914 struct cleanup
*bkpttbl_chain
;
3916 /* Compute the number of rows in the table. */
3917 nr_printable_breakpoints
= 0;
3920 || bnum
== b
->number
)
3922 if (allflag
|| user_settable_breakpoint (b
))
3923 nr_printable_breakpoints
++;
3928 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3932 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3935 if (nr_printable_breakpoints
> 0)
3936 annotate_breakpoints_headers ();
3937 if (nr_printable_breakpoints
> 0)
3939 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3940 if (nr_printable_breakpoints
> 0)
3942 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3943 if (nr_printable_breakpoints
> 0)
3945 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3946 if (nr_printable_breakpoints
> 0)
3948 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3951 if (nr_printable_breakpoints
> 0)
3953 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3954 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3956 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3958 if (nr_printable_breakpoints
> 0)
3960 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3961 ui_out_table_body (uiout
);
3962 if (nr_printable_breakpoints
> 0)
3963 annotate_breakpoints_table ();
3967 || bnum
== b
->number
)
3969 /* We only print out user settable breakpoints unless the
3971 if (allflag
|| user_settable_breakpoint (b
))
3972 print_one_breakpoint (b
, &last_addr
);
3975 do_cleanups (bkpttbl_chain
);
3977 if (nr_printable_breakpoints
== 0)
3980 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3982 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3987 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3988 that a comparison of an unsigned with -1 is always false. */
3989 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3990 set_next_address (last_addr
);
3993 /* FIXME? Should this be moved up so that it is only called when
3994 there have been breakpoints? */
3995 annotate_breakpoints_table_end ();
3999 breakpoints_info (char *bnum_exp
, int from_tty
)
4004 bnum
= parse_and_eval_long (bnum_exp
);
4006 breakpoint_1 (bnum
, 0);
4010 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4015 bnum
= parse_and_eval_long (bnum_exp
);
4017 breakpoint_1 (bnum
, 1);
4021 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4023 struct bp_location
*bl
= b
->loc
;
4024 for (; bl
; bl
= bl
->next
)
4026 if (bl
->address
== pc
4027 && (!overlay_debugging
|| bl
->section
== section
))
4033 /* Print a message describing any breakpoints set at PC. */
4036 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4039 struct breakpoint
*b
;
4042 others
+= breakpoint_has_pc (b
, pc
, section
);
4046 printf_filtered (_("Note: breakpoint "));
4047 else /* if (others == ???) */
4048 printf_filtered (_("Note: breakpoints "));
4050 if (breakpoint_has_pc (b
, pc
, section
))
4053 printf_filtered ("%d", b
->number
);
4054 if (b
->thread
== -1 && thread
!= -1)
4055 printf_filtered (" (all threads)");
4056 else if (b
->thread
!= -1)
4057 printf_filtered (" (thread %d)", b
->thread
);
4058 printf_filtered ("%s%s ",
4059 ((b
->enable_state
== bp_disabled
||
4060 b
->enable_state
== bp_call_disabled
)
4062 : b
->enable_state
== bp_permanent
4066 : ((others
== 1) ? " and" : ""));
4068 printf_filtered (_("also set at pc "));
4069 fputs_filtered (paddress (pc
), gdb_stdout
);
4070 printf_filtered (".\n");
4074 /* Set the default place to put a breakpoint
4075 for the `break' command with no arguments. */
4078 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4081 default_breakpoint_valid
= valid
;
4082 default_breakpoint_address
= addr
;
4083 default_breakpoint_symtab
= symtab
;
4084 default_breakpoint_line
= line
;
4087 /* Return true iff it is meaningful to use the address member of
4088 BPT. For some breakpoint types, the address member is irrelevant
4089 and it makes no sense to attempt to compare it to other addresses
4090 (or use it for any other purpose either).
4092 More specifically, each of the following breakpoint types will always
4093 have a zero valued address and we don't want check_duplicates() to mark
4094 breakpoints of any of these types to be a duplicate of an actual
4095 breakpoint at address zero:
4098 bp_hardware_watchpoint
4100 bp_access_watchpoint
4106 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4108 enum bptype type
= bpt
->type
;
4110 return (type
!= bp_watchpoint
4111 && type
!= bp_hardware_watchpoint
4112 && type
!= bp_read_watchpoint
4113 && type
!= bp_access_watchpoint
4114 && type
!= bp_catch_exec
4115 && type
!= bp_catch_fork
4116 && type
!= bp_catch_vfork
);
4119 /* Rescan breakpoints at the same address and section as BPT,
4120 marking the first one as "first" and any others as "duplicates".
4121 This is so that the bpt instruction is only inserted once.
4122 If we have a permanent breakpoint at the same place as BPT, make
4123 that one the official one, and the rest as duplicates. */
4126 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4128 struct bp_location
*b
;
4130 struct bp_location
*perm_bp
= 0;
4132 ALL_BP_LOCATIONS (b
)
4133 if (b
->owner
->enable_state
!= bp_disabled
4134 && b
->owner
->enable_state
!= bp_call_disabled
4136 && !b
->shlib_disabled
4137 && b
->address
== address
/* address / overlay match */
4138 && (!overlay_debugging
|| b
->section
== section
)
4139 && breakpoint_address_is_meaningful (b
->owner
))
4141 /* Have we found a permanent breakpoint? */
4142 if (b
->owner
->enable_state
== bp_permanent
)
4149 b
->duplicate
= count
> 1;
4152 /* If we found a permanent breakpoint at this address, go over the
4153 list again and declare all the other breakpoints there to be the
4157 perm_bp
->duplicate
= 0;
4159 /* Permanent breakpoint should always be inserted. */
4160 if (! perm_bp
->inserted
)
4161 internal_error (__FILE__
, __LINE__
,
4162 _("allegedly permanent breakpoint is not "
4163 "actually inserted"));
4165 ALL_BP_LOCATIONS (b
)
4168 if (b
->owner
->enable_state
!= bp_disabled
4169 && b
->owner
->enable_state
!= bp_call_disabled
4170 && b
->enabled
&& !b
->shlib_disabled
4171 && b
->address
== address
/* address / overlay match */
4172 && (!overlay_debugging
|| b
->section
== section
)
4173 && breakpoint_address_is_meaningful (b
->owner
))
4176 internal_error (__FILE__
, __LINE__
,
4177 _("another breakpoint was inserted on top of "
4178 "a permanent breakpoint"));
4187 check_duplicates (struct breakpoint
*bpt
)
4189 struct bp_location
*bl
= bpt
->loc
;
4191 if (! breakpoint_address_is_meaningful (bpt
))
4194 for (; bl
; bl
= bl
->next
)
4195 check_duplicates_for (bl
->address
, bl
->section
);
4199 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4200 int bnum
, int have_bnum
)
4205 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4206 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4208 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4209 bnum
, astr1
, astr2
);
4211 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4214 /* Adjust a breakpoint's address to account for architectural constraints
4215 on breakpoint placement. Return the adjusted address. Note: Very
4216 few targets require this kind of adjustment. For most targets,
4217 this function is simply the identity function. */
4220 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4222 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4224 /* Very few targets need any kind of breakpoint adjustment. */
4227 else if (bptype
== bp_watchpoint
4228 || bptype
== bp_hardware_watchpoint
4229 || bptype
== bp_read_watchpoint
4230 || bptype
== bp_access_watchpoint
4231 || bptype
== bp_catch_fork
4232 || bptype
== bp_catch_vfork
4233 || bptype
== bp_catch_exec
)
4235 /* Watchpoints and the various bp_catch_* eventpoints should not
4236 have their addresses modified. */
4241 CORE_ADDR adjusted_bpaddr
;
4243 /* Some targets have architectural constraints on the placement
4244 of breakpoint instructions. Obtain the adjusted address. */
4245 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4248 /* An adjusted breakpoint address can significantly alter
4249 a user's expectations. Print a warning if an adjustment
4251 if (adjusted_bpaddr
!= bpaddr
)
4252 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4254 return adjusted_bpaddr
;
4258 /* Allocate a struct bp_location. */
4260 static struct bp_location
*
4261 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4263 struct bp_location
*loc
, *loc_p
;
4265 loc
= xmalloc (sizeof (struct bp_location
));
4266 memset (loc
, 0, sizeof (*loc
));
4270 loc
->shlib_disabled
= 0;
4279 case bp_longjmp_resume
:
4280 case bp_step_resume
:
4281 case bp_watchpoint_scope
:
4283 case bp_shlib_event
:
4284 case bp_thread_event
:
4285 case bp_overlay_event
:
4287 case bp_catch_unload
:
4288 loc
->loc_type
= bp_loc_software_breakpoint
;
4290 case bp_hardware_breakpoint
:
4291 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4293 case bp_hardware_watchpoint
:
4294 case bp_read_watchpoint
:
4295 case bp_access_watchpoint
:
4296 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4300 case bp_catch_vfork
:
4302 loc
->loc_type
= bp_loc_other
;
4305 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4311 static void free_bp_location (struct bp_location
*loc
)
4316 if (loc
->function_name
)
4317 xfree (loc
->function_name
);
4322 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4323 that has type BPTYPE and has no locations as yet. */
4325 static struct breakpoint
*
4326 set_raw_breakpoint_without_location (enum bptype bptype
)
4328 struct breakpoint
*b
, *b1
;
4330 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4331 memset (b
, 0, sizeof (*b
));
4334 b
->language
= current_language
->la_language
;
4335 b
->input_radix
= input_radix
;
4337 b
->enable_state
= bp_enabled
;
4340 b
->ignore_count
= 0;
4342 b
->frame_id
= null_frame_id
;
4343 b
->dll_pathname
= NULL
;
4344 b
->triggered_dll_pathname
= NULL
;
4345 b
->forked_inferior_pid
= null_ptid
;
4346 b
->exec_pathname
= NULL
;
4348 b
->condition_not_parsed
= 0;
4350 /* Add this breakpoint to the end of the chain
4351 so that a list of breakpoints will come out in order
4352 of increasing numbers. */
4354 b1
= breakpoint_chain
;
4356 breakpoint_chain
= b
;
4366 /* Initialize loc->function_name. */
4368 set_breakpoint_location_function (struct bp_location
*loc
)
4370 if (loc
->owner
->type
== bp_breakpoint
4371 || loc
->owner
->type
== bp_hardware_breakpoint
)
4373 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4375 if (loc
->function_name
)
4376 loc
->function_name
= xstrdup (loc
->function_name
);
4380 /* set_raw_breakpoint is a low level routine for allocating and
4381 partially initializing a breakpoint of type BPTYPE. The newly
4382 created breakpoint's address, section, source file name, and line
4383 number are provided by SAL. The newly created and partially
4384 initialized breakpoint is added to the breakpoint chain and
4385 is also returned as the value of this function.
4387 It is expected that the caller will complete the initialization of
4388 the newly created breakpoint struct as well as output any status
4389 information regarding the creation of a new breakpoint. In
4390 particular, set_raw_breakpoint does NOT set the breakpoint
4391 number! Care should be taken to not allow an error to occur
4392 prior to completing the initialization of the breakpoint. If this
4393 should happen, a bogus breakpoint will be left on the chain. */
4396 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4398 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4399 CORE_ADDR adjusted_address
;
4401 /* Adjust the breakpoint's address prior to allocating a location.
4402 Once we call allocate_bp_location(), that mostly uninitialized
4403 location will be placed on the location chain. Adjustment of the
4404 breakpoint may cause target_read_memory() to be called and we do
4405 not want its scan of the location chain to find a breakpoint and
4406 location that's only been partially initialized. */
4407 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4409 b
->loc
= allocate_bp_location (b
, bptype
);
4410 b
->loc
->requested_address
= sal
.pc
;
4411 b
->loc
->address
= adjusted_address
;
4413 if (sal
.symtab
== NULL
)
4414 b
->source_file
= NULL
;
4416 b
->source_file
= savestring (sal
.symtab
->filename
,
4417 strlen (sal
.symtab
->filename
));
4418 b
->loc
->section
= sal
.section
;
4419 b
->line_number
= sal
.line
;
4421 set_breakpoint_location_function (b
->loc
);
4423 breakpoints_changed ();
4429 /* Note that the breakpoint object B describes a permanent breakpoint
4430 instruction, hard-wired into the inferior's code. */
4432 make_breakpoint_permanent (struct breakpoint
*b
)
4434 struct bp_location
*bl
;
4435 b
->enable_state
= bp_permanent
;
4437 /* By definition, permanent breakpoints are already present in the code.
4438 Mark all locations as inserted. For now, make_breakpoint_permanent
4439 is called in just one place, so it's hard to say if it's reasonable
4440 to have permanent breakpoint with multiple locations or not,
4441 but it's easy to implmement. */
4442 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4446 static struct breakpoint
*
4447 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4449 static int internal_breakpoint_number
= -1;
4450 struct symtab_and_line sal
;
4451 struct breakpoint
*b
;
4453 init_sal (&sal
); /* initialize to zeroes */
4456 sal
.section
= find_pc_overlay (sal
.pc
);
4458 b
= set_raw_breakpoint (sal
, type
);
4459 b
->number
= internal_breakpoint_number
--;
4460 b
->disposition
= disp_donttouch
;
4467 create_longjmp_breakpoint (char *func_name
)
4469 struct breakpoint
*b
;
4470 struct minimal_symbol
*m
;
4472 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4474 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4475 update_global_location_list (1);
4478 /* Call this routine when stepping and nexting to enable a breakpoint
4479 if we do a longjmp(). When we hit that breakpoint, call
4480 set_longjmp_resume_breakpoint() to figure out where we are going. */
4483 set_longjmp_breakpoint (void)
4485 struct breakpoint
*b
;
4487 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4489 create_longjmp_breakpoint ("longjmp");
4490 create_longjmp_breakpoint ("_longjmp");
4491 create_longjmp_breakpoint ("siglongjmp");
4492 create_longjmp_breakpoint ("_siglongjmp");
4496 /* Delete all longjmp breakpoints from THREAD. */
4498 delete_longjmp_breakpoint (int thread
)
4500 struct breakpoint
*b
, *temp
;
4502 ALL_BREAKPOINTS_SAFE (b
, temp
)
4503 if (b
->type
== bp_longjmp
)
4505 if (b
->thread
== thread
)
4506 delete_breakpoint (b
);
4511 create_overlay_event_breakpoint (char *func_name
)
4513 struct breakpoint
*b
;
4514 struct minimal_symbol
*m
;
4516 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4519 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4521 b
->addr_string
= xstrdup (func_name
);
4523 if (overlay_debugging
== ovly_auto
)
4525 b
->enable_state
= bp_enabled
;
4526 overlay_events_enabled
= 1;
4530 b
->enable_state
= bp_disabled
;
4531 overlay_events_enabled
= 0;
4533 update_global_location_list (1);
4537 enable_overlay_breakpoints (void)
4539 struct breakpoint
*b
;
4542 if (b
->type
== bp_overlay_event
)
4544 b
->enable_state
= bp_enabled
;
4545 update_global_location_list (1);
4546 overlay_events_enabled
= 1;
4551 disable_overlay_breakpoints (void)
4553 struct breakpoint
*b
;
4556 if (b
->type
== bp_overlay_event
)
4558 b
->enable_state
= bp_disabled
;
4559 update_global_location_list (0);
4560 overlay_events_enabled
= 0;
4565 create_thread_event_breakpoint (CORE_ADDR address
)
4567 struct breakpoint
*b
;
4569 b
= create_internal_breakpoint (address
, bp_thread_event
);
4571 b
->enable_state
= bp_enabled
;
4572 /* addr_string has to be used or breakpoint_re_set will delete me. */
4573 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4575 update_global_location_list_nothrow (1);
4581 remove_thread_event_breakpoints (void)
4583 struct breakpoint
*b
, *temp
;
4585 ALL_BREAKPOINTS_SAFE (b
, temp
)
4586 if (b
->type
== bp_thread_event
)
4587 delete_breakpoint (b
);
4590 struct captured_parse_breakpoint_args
4593 struct symtabs_and_lines
*sals_p
;
4594 char ***addr_string_p
;
4598 struct lang_and_radix
4606 remove_solib_event_breakpoints (void)
4608 struct breakpoint
*b
, *temp
;
4610 ALL_BREAKPOINTS_SAFE (b
, temp
)
4611 if (b
->type
== bp_shlib_event
)
4612 delete_breakpoint (b
);
4616 create_solib_event_breakpoint (CORE_ADDR address
)
4618 struct breakpoint
*b
;
4620 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4621 update_global_location_list_nothrow (1);
4625 /* Disable any breakpoints that are on code in shared libraries. Only
4626 apply to enabled breakpoints, disabled ones can just stay disabled. */
4629 disable_breakpoints_in_shlibs (void)
4631 struct bp_location
*loc
;
4632 int disabled_shlib_breaks
= 0;
4634 ALL_BP_LOCATIONS (loc
)
4636 struct breakpoint
*b
= loc
->owner
;
4637 /* We apply the check to all breakpoints, including disabled
4638 for those with loc->duplicate set. This is so that when breakpoint
4639 becomes enabled, or the duplicate is removed, gdb will try to insert
4640 all breakpoints. If we don't set shlib_disabled here, we'll try
4641 to insert those breakpoints and fail. */
4642 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4643 && !loc
->shlib_disabled
4645 && PC_SOLIB (loc
->address
)
4647 && solib_address (loc
->address
)
4651 loc
->shlib_disabled
= 1;
4656 /* Disable any breakpoints that are in in an unloaded shared library. Only
4657 apply to enabled breakpoints, disabled ones can just stay disabled. */
4660 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4662 struct bp_location
*loc
;
4663 int disabled_shlib_breaks
= 0;
4665 ALL_BP_LOCATIONS (loc
)
4667 struct breakpoint
*b
= loc
->owner
;
4668 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4669 || loc
->loc_type
== bp_loc_software_breakpoint
)
4670 && !loc
->shlib_disabled
)
4673 char *so_name
= PC_SOLIB (loc
->address
);
4675 char *so_name
= solib_address (loc
->address
);
4677 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4679 loc
->shlib_disabled
= 1;
4680 /* At this point, we cannot rely on remove_breakpoint
4681 succeeding so we must mark the breakpoint as not inserted
4682 to prevent future errors occurring in remove_breakpoints. */
4684 if (!disabled_shlib_breaks
)
4686 target_terminal_ours_for_output ();
4687 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4690 disabled_shlib_breaks
= 1;
4697 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4698 enum bptype bp_kind
)
4700 struct symtab_and_line sal
;
4701 struct breakpoint
*b
;
4702 int thread
= -1; /* All threads. */
4709 b
= set_raw_breakpoint (sal
, bp_kind
);
4710 set_breakpoint_count (breakpoint_count
+ 1);
4711 b
->number
= breakpoint_count
;
4712 b
->cond_string
= (cond_string
== NULL
) ?
4713 NULL
: savestring (cond_string
, strlen (cond_string
));
4715 b
->addr_string
= NULL
;
4716 b
->enable_state
= bp_enabled
;
4717 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4718 b
->forked_inferior_pid
= null_ptid
;
4719 update_global_location_list (1);
4726 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4728 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4732 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4734 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4738 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4740 struct symtab_and_line sal
;
4741 struct breakpoint
*b
;
4742 int thread
= -1; /* All threads. */
4749 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4750 set_breakpoint_count (breakpoint_count
+ 1);
4751 b
->number
= breakpoint_count
;
4752 b
->cond_string
= (cond_string
== NULL
) ?
4753 NULL
: savestring (cond_string
, strlen (cond_string
));
4755 b
->addr_string
= NULL
;
4756 b
->enable_state
= bp_enabled
;
4757 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4758 update_global_location_list (1);
4764 hw_breakpoint_used_count (void)
4766 struct breakpoint
*b
;
4771 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4779 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4781 struct breakpoint
*b
;
4784 *other_type_used
= 0;
4787 if (breakpoint_enabled (b
))
4789 if (b
->type
== type
)
4791 else if ((b
->type
== bp_hardware_watchpoint
||
4792 b
->type
== bp_read_watchpoint
||
4793 b
->type
== bp_access_watchpoint
))
4794 *other_type_used
= 1;
4801 disable_watchpoints_before_interactive_call_start (void)
4803 struct breakpoint
*b
;
4807 if (((b
->type
== bp_watchpoint
)
4808 || (b
->type
== bp_hardware_watchpoint
)
4809 || (b
->type
== bp_read_watchpoint
)
4810 || (b
->type
== bp_access_watchpoint
))
4811 && breakpoint_enabled (b
))
4813 b
->enable_state
= bp_call_disabled
;
4814 update_global_location_list (0);
4820 enable_watchpoints_after_interactive_call_stop (void)
4822 struct breakpoint
*b
;
4826 if (((b
->type
== bp_watchpoint
)
4827 || (b
->type
== bp_hardware_watchpoint
)
4828 || (b
->type
== bp_read_watchpoint
)
4829 || (b
->type
== bp_access_watchpoint
))
4830 && (b
->enable_state
== bp_call_disabled
))
4832 b
->enable_state
= bp_enabled
;
4833 update_global_location_list (1);
4839 /* Set a breakpoint that will evaporate an end of command
4840 at address specified by SAL.
4841 Restrict it to frame FRAME if FRAME is nonzero. */
4844 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4847 struct breakpoint
*b
;
4848 b
= set_raw_breakpoint (sal
, type
);
4849 b
->enable_state
= bp_enabled
;
4850 b
->disposition
= disp_donttouch
;
4851 b
->frame_id
= frame_id
;
4853 /* If we're debugging a multi-threaded program, then we
4854 want momentary breakpoints to be active in only a
4855 single thread of control. */
4856 if (in_thread_list (inferior_ptid
))
4857 b
->thread
= pid_to_thread_id (inferior_ptid
);
4859 update_global_location_list_nothrow (1);
4865 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4867 struct symtab_and_line sal
;
4869 sal
= find_pc_line (pc
, 0);
4871 sal
.section
= find_pc_overlay (pc
);
4872 sal
.explicit_pc
= 1;
4874 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4878 /* Tell the user we have just set a breakpoint B. */
4881 mention (struct breakpoint
*b
)
4884 struct cleanup
*old_chain
, *ui_out_chain
;
4885 struct ui_stream
*stb
;
4887 stb
= ui_out_stream_new (uiout
);
4888 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4890 /* FIXME: This is misplaced; mention() is called by things (like
4891 hitting a watchpoint) other than breakpoint creation. It should
4892 be possible to clean this up and at the same time replace the
4893 random calls to breakpoint_changed with this hook, as has already
4894 been done for deprecated_delete_breakpoint_hook and so on. */
4895 if (deprecated_create_breakpoint_hook
)
4896 deprecated_create_breakpoint_hook (b
);
4897 observer_notify_breakpoint_created (b
->number
);
4899 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4900 b
->ops
->print_mention (b
);
4905 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4908 ui_out_text (uiout
, "Watchpoint ");
4909 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4910 ui_out_field_int (uiout
, "number", b
->number
);
4911 ui_out_text (uiout
, ": ");
4912 print_expression (b
->exp
, stb
->stream
);
4913 ui_out_field_stream (uiout
, "exp", stb
);
4914 do_cleanups (ui_out_chain
);
4916 case bp_hardware_watchpoint
:
4917 ui_out_text (uiout
, "Hardware watchpoint ");
4918 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4919 ui_out_field_int (uiout
, "number", b
->number
);
4920 ui_out_text (uiout
, ": ");
4921 print_expression (b
->exp
, stb
->stream
);
4922 ui_out_field_stream (uiout
, "exp", stb
);
4923 do_cleanups (ui_out_chain
);
4925 case bp_read_watchpoint
:
4926 ui_out_text (uiout
, "Hardware read watchpoint ");
4927 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4928 ui_out_field_int (uiout
, "number", b
->number
);
4929 ui_out_text (uiout
, ": ");
4930 print_expression (b
->exp
, stb
->stream
);
4931 ui_out_field_stream (uiout
, "exp", stb
);
4932 do_cleanups (ui_out_chain
);
4934 case bp_access_watchpoint
:
4935 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4936 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4937 ui_out_field_int (uiout
, "number", b
->number
);
4938 ui_out_text (uiout
, ": ");
4939 print_expression (b
->exp
, stb
->stream
);
4940 ui_out_field_stream (uiout
, "exp", stb
);
4941 do_cleanups (ui_out_chain
);
4944 if (ui_out_is_mi_like_p (uiout
))
4949 if (b
->disposition
== disp_del
)
4950 printf_filtered (_("Temporary breakpoint"));
4952 printf_filtered (_("Breakpoint"));
4953 printf_filtered (_(" %d"), b
->number
);
4956 case bp_hardware_breakpoint
:
4957 if (ui_out_is_mi_like_p (uiout
))
4962 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4966 case bp_catch_unload
:
4967 printf_filtered (_("Catchpoint %d (%s %s)"),
4969 (b
->type
== bp_catch_load
) ? "load" : "unload",
4970 (b
->dll_pathname
!= NULL
) ?
4971 b
->dll_pathname
: "<any library>");
4974 case bp_catch_vfork
:
4975 printf_filtered (_("Catchpoint %d (%s)"),
4977 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4980 printf_filtered (_("Catchpoint %d (exec)"),
4987 case bp_longjmp_resume
:
4988 case bp_step_resume
:
4990 case bp_watchpoint_scope
:
4991 case bp_shlib_event
:
4992 case bp_thread_event
:
4993 case bp_overlay_event
:
4999 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5003 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5007 if (addressprint
|| b
->source_file
== NULL
)
5009 printf_filtered (" at ");
5010 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5013 printf_filtered (": file %s, line %d.",
5014 b
->source_file
, b
->line_number
);
5018 struct bp_location
*loc
= b
->loc
;
5020 for (; loc
; loc
= loc
->next
)
5022 printf_filtered (" (%d locations)", n
);
5027 do_cleanups (old_chain
);
5028 if (ui_out_is_mi_like_p (uiout
))
5030 printf_filtered ("\n");
5034 static struct bp_location
*
5035 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5036 const struct symtab_and_line
*sal
)
5038 struct bp_location
*loc
, **tmp
;
5040 loc
= allocate_bp_location (b
, bptype
);
5041 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5044 loc
->requested_address
= sal
->pc
;
5045 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5047 loc
->section
= sal
->section
;
5049 set_breakpoint_location_function (loc
);
5053 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5054 as textual description of the location, and COND_STRING
5055 as condition expression. */
5058 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5060 enum bptype type
, enum bpdisp disposition
,
5061 int thread
, int ignore_count
,
5062 struct breakpoint_ops
*ops
, int from_tty
)
5064 struct breakpoint
*b
= NULL
;
5067 if (type
== bp_hardware_breakpoint
)
5069 int i
= hw_breakpoint_used_count ();
5070 int target_resources_ok
=
5071 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5073 if (target_resources_ok
== 0)
5074 error (_("No hardware breakpoint support in the target."));
5075 else if (target_resources_ok
< 0)
5076 error (_("Hardware breakpoints used exceeds limit."));
5079 for (i
= 0; i
< sals
.nelts
; ++i
)
5081 struct symtab_and_line sal
= sals
.sals
[i
];
5082 struct bp_location
*loc
;
5085 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5089 b
= set_raw_breakpoint (sal
, type
);
5090 set_breakpoint_count (breakpoint_count
+ 1);
5091 b
->number
= breakpoint_count
;
5094 b
->cond_string
= cond_string
;
5095 b
->ignore_count
= ignore_count
;
5096 b
->enable_state
= bp_enabled
;
5097 b
->disposition
= disposition
;
5103 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5108 char *arg
= b
->cond_string
;
5109 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5111 error (_("Garbage %s follows condition"), arg
);
5116 b
->addr_string
= addr_string
;
5118 /* addr_string has to be used or breakpoint_re_set will delete
5120 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5126 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5127 elements to fill the void space. */
5128 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5130 int i
= index_to_remove
+1;
5131 int last_index
= sal
->nelts
-1;
5133 for (;i
<= last_index
; ++i
)
5134 sal
->sals
[i
-1] = sal
->sals
[i
];
5139 /* If appropriate, obtains all sals that correspond
5140 to the same file and line as SAL. This is done
5141 only if SAL does not have explicit PC and has
5142 line and file information. If we got just a single
5143 expanded sal, return the original.
5145 Otherwise, if SAL.explicit_line is not set, filter out
5146 all sals for which the name of enclosing function
5147 is different from SAL. This makes sure that if we have
5148 breakpoint originally set in template instantiation, say
5149 foo<int>(), we won't expand SAL to locations at the same
5150 line in all existing instantiations of 'foo'.
5153 struct symtabs_and_lines
5154 expand_line_sal_maybe (struct symtab_and_line sal
)
5156 struct symtabs_and_lines expanded
;
5157 CORE_ADDR original_pc
= sal
.pc
;
5158 char *original_function
= NULL
;
5162 /* If we have explicit pc, don't expand.
5163 If we have no line number, we can't expand. */
5164 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5167 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5168 expanded
.sals
[0] = sal
;
5173 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5175 expanded
= expand_line_sal (sal
);
5176 if (expanded
.nelts
== 1)
5178 /* We had one sal, we got one sal. Without futher
5179 processing, just return the original sal. */
5180 xfree (expanded
.sals
);
5182 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5183 sal
.pc
= original_pc
;
5184 expanded
.sals
[0] = sal
;
5188 if (!sal
.explicit_line
)
5190 CORE_ADDR func_addr
, func_end
;
5191 for (i
= 0; i
< expanded
.nelts
; ++i
)
5193 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5194 char *this_function
;
5195 if (find_pc_partial_function (pc
, &this_function
,
5196 &func_addr
, &func_end
))
5198 if (this_function
&&
5199 strcmp (this_function
, original_function
) != 0)
5201 remove_sal (&expanded
, i
);
5204 else if (func_addr
== pc
)
5206 /* We're at beginning of a function, and should
5208 struct symbol
*sym
= find_pc_function (pc
);
5210 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5213 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5220 if (expanded
.nelts
<= 1)
5222 /* This is un ugly workaround. If we get zero
5223 expanded sals then something is really wrong.
5224 Fix that by returnign the original sal. */
5225 xfree (expanded
.sals
);
5227 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5228 sal
.pc
= original_pc
;
5229 expanded
.sals
[0] = sal
;
5236 for (i
= 0; i
< expanded
.nelts
; ++i
)
5237 if (expanded
.sals
[i
].pc
== original_pc
)
5248 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5249 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5250 value. COND_STRING, if not NULL, specified the condition to be
5251 used for all breakpoints. Essentially the only case where
5252 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5253 function. In that case, it's still not possible to specify
5254 separate conditions for different overloaded functions, so
5255 we take just a single condition string.
5257 NOTE: If the function succeeds, the caller is expected to cleanup
5258 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5259 array contents). If the function fails (error() is called), the
5260 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5261 COND and SALS arrays and each of those arrays contents. */
5264 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5266 enum bptype type
, enum bpdisp disposition
,
5267 int thread
, int ignore_count
,
5268 struct breakpoint_ops
*ops
, int from_tty
)
5271 for (i
= 0; i
< sals
.nelts
; ++i
)
5273 struct symtabs_and_lines expanded
=
5274 expand_line_sal_maybe (sals
.sals
[i
]);
5276 create_breakpoint (expanded
, addr_string
[i
],
5277 cond_string
, type
, disposition
,
5278 thread
, ignore_count
, ops
, from_tty
);
5281 update_global_location_list (1);
5284 /* Parse ARG which is assumed to be a SAL specification possibly
5285 followed by conditionals. On return, SALS contains an array of SAL
5286 addresses found. ADDR_STRING contains a vector of (canonical)
5287 address strings. ARG points to the end of the SAL. */
5290 parse_breakpoint_sals (char **address
,
5291 struct symtabs_and_lines
*sals
,
5292 char ***addr_string
,
5295 char *addr_start
= *address
;
5296 *addr_string
= NULL
;
5297 /* If no arg given, or if first arg is 'if ', use the default
5299 if ((*address
) == NULL
5300 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5302 if (default_breakpoint_valid
)
5304 struct symtab_and_line sal
;
5305 init_sal (&sal
); /* initialize to zeroes */
5306 sals
->sals
= (struct symtab_and_line
*)
5307 xmalloc (sizeof (struct symtab_and_line
));
5308 sal
.pc
= default_breakpoint_address
;
5309 sal
.line
= default_breakpoint_line
;
5310 sal
.symtab
= default_breakpoint_symtab
;
5311 sal
.section
= find_pc_overlay (sal
.pc
);
5312 sals
->sals
[0] = sal
;
5316 error (_("No default breakpoint address now."));
5320 /* Force almost all breakpoints to be in terms of the
5321 current_source_symtab (which is decode_line_1's default). This
5322 should produce the results we want almost all of the time while
5323 leaving default_breakpoint_* alone.
5324 ObjC: However, don't match an Objective-C method name which
5325 may have a '+' or '-' succeeded by a '[' */
5327 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5329 if (default_breakpoint_valid
5331 || ((strchr ("+-", (*address
)[0]) != NULL
)
5332 && ((*address
)[1] != '['))))
5333 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5334 default_breakpoint_line
, addr_string
,
5337 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5338 addr_string
, not_found_ptr
);
5340 /* For any SAL that didn't have a canonical string, fill one in. */
5341 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5342 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5343 if (addr_start
!= (*address
))
5346 for (i
= 0; i
< sals
->nelts
; i
++)
5348 /* Add the string if not present. */
5349 if ((*addr_string
)[i
] == NULL
)
5350 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5356 /* Convert each SAL into a real PC. Verify that the PC can be
5357 inserted as a breakpoint. If it can't throw an error. */
5360 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5364 for (i
= 0; i
< sals
->nelts
; i
++)
5365 resolve_sal_pc (&sals
->sals
[i
]);
5369 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5371 struct captured_parse_breakpoint_args
*args
= data
;
5373 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5374 args
->not_found_ptr
);
5377 /* Given TOK, a string specification of condition and thread, as
5378 accepted by the 'break' command, extract the condition
5379 string and thread number and set *COND_STRING and *THREAD.
5380 PC identifies the context at which the condition should be parsed.
5381 If no condition is found, *COND_STRING is set to NULL.
5382 If no thread is found, *THREAD is set to -1. */
5384 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5385 char **cond_string
, int *thread
)
5387 *cond_string
= NULL
;
5393 char *cond_start
= NULL
;
5394 char *cond_end
= NULL
;
5395 while (*tok
== ' ' || *tok
== '\t')
5400 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5403 toklen
= end_tok
- tok
;
5405 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5407 tok
= cond_start
= end_tok
+ 1;
5408 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5410 *cond_string
= savestring (cond_start
,
5411 cond_end
- cond_start
);
5413 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5419 *thread
= strtol (tok
, &tok
, 0);
5421 error (_("Junk after thread keyword."));
5422 if (!valid_thread_id (*thread
))
5423 error (_("Unknown thread %d."), *thread
);
5426 error (_("Junk at end of arguments."));
5430 /* Set a breakpoint. This function is shared between
5431 CLI and MI functions for setting a breakpoint.
5432 This function has two major modes of operations,
5433 selected by the PARSE_CONDITION_AND_THREAD parameter.
5434 If non-zero, the function will parse arg, extracting
5435 breakpoint location, address and thread. Otherwise,
5436 ARG is just the location of breakpoint, with condition
5437 and thread specified by the COND_STRING and THREAD
5441 break_command_really (char *arg
, char *cond_string
, int thread
,
5442 int parse_condition_and_thread
,
5443 int tempflag
, int hardwareflag
,
5445 enum auto_boolean pending_break_support
,
5446 struct breakpoint_ops
*ops
,
5449 struct gdb_exception e
;
5450 struct symtabs_and_lines sals
;
5451 struct symtab_and_line pending_sal
;
5454 char *addr_start
= arg
;
5456 struct cleanup
*old_chain
;
5457 struct cleanup
*breakpoint_chain
= NULL
;
5458 struct captured_parse_breakpoint_args parse_args
;
5467 parse_args
.arg_p
= &arg
;
5468 parse_args
.sals_p
= &sals
;
5469 parse_args
.addr_string_p
= &addr_string
;
5470 parse_args
.not_found_ptr
= ¬_found
;
5472 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5473 &parse_args
, RETURN_MASK_ALL
);
5475 /* If caller is interested in rc value from parse, set value. */
5479 throw_exception (e
);
5483 case NOT_FOUND_ERROR
:
5485 /* If pending breakpoint support is turned off, throw
5488 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5489 throw_exception (e
);
5491 exception_print (gdb_stderr
, e
);
5493 /* If pending breakpoint support is auto query and the user
5494 selects no, then simply return the error code. */
5495 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5496 !nquery ("Make breakpoint pending on future shared library load? "))
5499 /* At this point, either the user was queried about setting
5500 a pending breakpoint and selected yes, or pending
5501 breakpoint behavior is on and thus a pending breakpoint
5502 is defaulted on behalf of the user. */
5503 copy_arg
= xstrdup (addr_start
);
5504 addr_string
= ©_arg
;
5506 sals
.sals
= &pending_sal
;
5511 throw_exception (e
);
5518 /* Create a chain of things that always need to be cleaned up. */
5519 old_chain
= make_cleanup (null_cleanup
, 0);
5523 /* Make sure that all storage allocated to SALS gets freed. */
5524 make_cleanup (xfree
, sals
.sals
);
5526 /* Cleanup the addr_string array but not its contents. */
5527 make_cleanup (xfree
, addr_string
);
5530 /* ----------------------------- SNIP -----------------------------
5531 Anything added to the cleanup chain beyond this point is assumed
5532 to be part of a breakpoint. If the breakpoint create succeeds
5533 then the memory is not reclaimed. */
5534 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5536 /* Mark the contents of the addr_string for cleanup. These go on
5537 the breakpoint_chain and only occure if the breakpoint create
5539 for (i
= 0; i
< sals
.nelts
; i
++)
5541 if (addr_string
[i
] != NULL
)
5542 make_cleanup (xfree
, addr_string
[i
]);
5545 /* Resolve all line numbers to PC's and verify that the addresses
5546 are ok for the target. */
5548 breakpoint_sals_to_pc (&sals
, addr_start
);
5550 /* Verify that condition can be parsed, before setting any
5551 breakpoints. Allocate a separate condition expression for each
5555 if (parse_condition_and_thread
)
5557 /* Here we only parse 'arg' to separate condition
5558 from thread number, so parsing in context of first
5559 sal is OK. When setting the breakpoint we'll
5560 re-parse it in context of each sal. */
5563 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5565 make_cleanup (xfree
, cond_string
);
5569 /* Create a private copy of condition string. */
5572 cond_string
= xstrdup (cond_string
);
5573 make_cleanup (xfree
, cond_string
);
5576 create_breakpoints (sals
, addr_string
, cond_string
,
5577 hardwareflag
? bp_hardware_breakpoint
5579 tempflag
? disp_del
: disp_donttouch
,
5580 thread
, ignore_count
, ops
, from_tty
);
5584 struct symtab_and_line sal
= {0};
5585 struct breakpoint
*b
;
5587 make_cleanup (xfree
, copy_arg
);
5589 b
= set_raw_breakpoint_without_location (hardwareflag
5590 ? bp_hardware_breakpoint
5592 set_breakpoint_count (breakpoint_count
+ 1);
5593 b
->number
= breakpoint_count
;
5595 b
->addr_string
= addr_string
[0];
5596 b
->cond_string
= NULL
;
5597 b
->ignore_count
= ignore_count
;
5598 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5599 b
->condition_not_parsed
= 1;
5602 update_global_location_list (1);
5607 warning (_("Multiple breakpoints were set.\n"
5608 "Use the \"delete\" command to delete unwanted breakpoints."));
5609 /* That's it. Discard the cleanups for data inserted into the
5611 discard_cleanups (breakpoint_chain
);
5612 /* But cleanup everything else. */
5613 do_cleanups (old_chain
);
5616 /* Set a breakpoint.
5617 ARG is a string describing breakpoint address,
5618 condition, and thread.
5619 FLAG specifies if a breakpoint is hardware on,
5620 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5624 break_command_1 (char *arg
, int flag
, int from_tty
)
5626 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5627 int tempflag
= flag
& BP_TEMPFLAG
;
5629 break_command_really (arg
,
5630 NULL
, 0, 1 /* parse arg */,
5631 tempflag
, hardwareflag
,
5632 0 /* Ignore count */,
5633 pending_break_support
,
5634 NULL
/* breakpoint_ops */,
5640 set_breakpoint (char *address
, char *condition
,
5641 int hardwareflag
, int tempflag
,
5642 int thread
, int ignore_count
,
5645 break_command_really (address
, condition
, thread
,
5646 0 /* condition and thread are valid. */,
5647 tempflag
, hardwareflag
,
5650 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5654 /* Adjust SAL to the first instruction past the function prologue.
5655 The end of the prologue is determined using the line table from
5656 the debugging information.
5658 If SAL is already past the prologue, then do nothing. */
5661 skip_prologue_sal (struct symtab_and_line
*sal
)
5663 struct symbol
*sym
= find_pc_function (sal
->pc
);
5664 struct symtab_and_line start_sal
;
5669 start_sal
= find_function_start_sal (sym
, 1);
5670 if (sal
->pc
< start_sal
.pc
)
5674 /* Helper function for break_command_1 and disassemble_command. */
5677 resolve_sal_pc (struct symtab_and_line
*sal
)
5681 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5683 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5684 error (_("No line %d in file \"%s\"."),
5685 sal
->line
, sal
->symtab
->filename
);
5688 /* If this SAL corresponds to a breakpoint inserted using
5689 a line number, then skip the function prologue if necessary. */
5690 if (sal
->explicit_line
)
5691 skip_prologue_sal (sal
);
5694 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5696 struct blockvector
*bv
;
5700 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5703 sym
= block_linkage_function (b
);
5706 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5707 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5711 /* It really is worthwhile to have the section, so we'll just
5712 have to look harder. This case can be executed if we have
5713 line numbers but no functions (as can happen in assembly
5716 struct minimal_symbol
*msym
;
5718 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5720 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5727 break_command (char *arg
, int from_tty
)
5729 break_command_1 (arg
, 0, from_tty
);
5733 tbreak_command (char *arg
, int from_tty
)
5735 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5739 hbreak_command (char *arg
, int from_tty
)
5741 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5745 thbreak_command (char *arg
, int from_tty
)
5747 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5751 stop_command (char *arg
, int from_tty
)
5753 printf_filtered (_("Specify the type of breakpoint to set.\n\
5754 Usage: stop in <function | address>\n\
5755 stop at <line>\n"));
5759 stopin_command (char *arg
, int from_tty
)
5763 if (arg
== (char *) NULL
)
5765 else if (*arg
!= '*')
5770 /* look for a ':'. If this is a line number specification, then
5771 say it is bad, otherwise, it should be an address or
5772 function/method name */
5773 while (*argptr
&& !hasColon
)
5775 hasColon
= (*argptr
== ':');
5780 badInput
= (*argptr
!= ':'); /* Not a class::method */
5782 badInput
= isdigit (*arg
); /* a simple line number */
5786 printf_filtered (_("Usage: stop in <function | address>\n"));
5788 break_command_1 (arg
, 0, from_tty
);
5792 stopat_command (char *arg
, int from_tty
)
5796 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5803 /* look for a ':'. If there is a '::' then get out, otherwise
5804 it is probably a line number. */
5805 while (*argptr
&& !hasColon
)
5807 hasColon
= (*argptr
== ':');
5812 badInput
= (*argptr
== ':'); /* we have class::method */
5814 badInput
= !isdigit (*arg
); /* not a line number */
5818 printf_filtered (_("Usage: stop at <line>\n"));
5820 break_command_1 (arg
, 0, from_tty
);
5823 /* accessflag: hw_write: watch write,
5824 hw_read: watch read,
5825 hw_access: watch access (read or write) */
5827 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5829 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5830 struct symtab_and_line sal
;
5831 struct expression
*exp
;
5832 struct block
*exp_valid_block
;
5833 struct value
*val
, *mark
;
5834 struct frame_info
*frame
;
5835 struct frame_info
*prev_frame
= NULL
;
5836 char *exp_start
= NULL
;
5837 char *exp_end
= NULL
;
5838 char *tok
, *id_tok_start
, *end_tok
;
5840 char *cond_start
= NULL
;
5841 char *cond_end
= NULL
;
5842 struct expression
*cond
= NULL
;
5843 int i
, other_type_used
, target_resources_ok
= 0;
5844 enum bptype bp_type
;
5848 init_sal (&sal
); /* initialize to zeroes */
5850 /* Make sure that we actually have parameters to parse. */
5851 if (arg
!= NULL
&& arg
[0] != '\0')
5853 toklen
= strlen (arg
); /* Size of argument list. */
5855 /* Points tok to the end of the argument list. */
5856 tok
= arg
+ toklen
- 1;
5858 /* Go backwards in the parameters list. Skip the last parameter.
5859 If we're expecting a 'thread <thread_num>' parameter, this should
5860 be the thread identifier. */
5861 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5863 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5866 /* Points end_tok to the beginning of the last token. */
5867 id_tok_start
= tok
+ 1;
5869 /* Go backwards in the parameters list. Skip one more parameter.
5870 If we're expecting a 'thread <thread_num>' parameter, we should
5871 reach a "thread" token. */
5872 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5877 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5880 /* Move the pointer forward to skip the whitespace and
5881 calculate the length of the token. */
5883 toklen
= end_tok
- tok
;
5885 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5887 /* At this point we've found a "thread" token, which means
5888 the user is trying to set a watchpoint that triggers
5889 only in a specific thread. */
5892 /* Extract the thread ID from the next token. */
5893 thread
= strtol (id_tok_start
, &endp
, 0);
5895 /* Check if the user provided a valid numeric value for the
5897 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5898 error (_("Invalid thread ID specification %s."), id_tok_start
);
5900 /* Check if the thread actually exists. */
5901 if (!valid_thread_id (thread
))
5902 error (_("Unknown thread %d."), thread
);
5904 /* Truncate the string and get rid of the thread <thread_num>
5905 parameter before the parameter list is parsed by the
5906 evaluate_expression() function. */
5911 /* Parse the rest of the arguments. */
5912 innermost_block
= NULL
;
5914 exp
= parse_exp_1 (&arg
, 0, 0);
5916 exp_valid_block
= innermost_block
;
5917 mark
= value_mark ();
5918 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5920 release_value (val
);
5923 while (*tok
== ' ' || *tok
== '\t')
5927 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5930 toklen
= end_tok
- tok
;
5931 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5933 tok
= cond_start
= end_tok
+ 1;
5934 cond
= parse_exp_1 (&tok
, 0, 0);
5938 error (_("Junk at end of command."));
5940 if (accessflag
== hw_read
)
5941 bp_type
= bp_read_watchpoint
;
5942 else if (accessflag
== hw_access
)
5943 bp_type
= bp_access_watchpoint
;
5945 bp_type
= bp_hardware_watchpoint
;
5947 mem_cnt
= can_use_hardware_watchpoint (val
);
5948 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5949 error (_("Expression cannot be implemented with read/access watchpoint."));
5952 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5953 target_resources_ok
=
5954 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5956 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5957 error (_("Target does not support this type of hardware watchpoint."));
5959 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5960 error (_("Target can only support one kind of HW watchpoint at a time."));
5963 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5964 watchpoint could not be set. */
5965 if (!mem_cnt
|| target_resources_ok
<= 0)
5966 bp_type
= bp_watchpoint
;
5968 frame
= block_innermost_frame (exp_valid_block
);
5970 prev_frame
= get_prev_frame (frame
);
5974 /* If the expression is "local", then set up a "watchpoint scope"
5975 breakpoint at the point where we've left the scope of the watchpoint
5976 expression. Create the scope breakpoint before the watchpoint, so
5977 that we will encounter it first in bpstat_stop_status. */
5978 if (innermost_block
&& prev_frame
)
5980 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5981 bp_watchpoint_scope
);
5983 scope_breakpoint
->enable_state
= bp_enabled
;
5985 /* Automatically delete the breakpoint when it hits. */
5986 scope_breakpoint
->disposition
= disp_del
;
5988 /* Only break in the proper frame (help with recursion). */
5989 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5991 /* Set the address at which we will stop. */
5992 scope_breakpoint
->loc
->requested_address
5993 = get_frame_pc (prev_frame
);
5994 scope_breakpoint
->loc
->address
5995 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5996 scope_breakpoint
->type
);
5999 /* Now set up the breakpoint. */
6000 b
= set_raw_breakpoint (sal
, bp_type
);
6001 set_breakpoint_count (breakpoint_count
+ 1);
6002 b
->number
= breakpoint_count
;
6004 b
->disposition
= disp_donttouch
;
6006 b
->exp_valid_block
= exp_valid_block
;
6007 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6010 b
->loc
->cond
= cond
;
6012 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6017 b
->watchpoint_frame
= get_frame_id (frame
);
6019 b
->watchpoint_frame
= null_frame_id
;
6021 if (scope_breakpoint
!= NULL
)
6023 /* The scope breakpoint is related to the watchpoint. We will
6024 need to act on them together. */
6025 b
->related_breakpoint
= scope_breakpoint
;
6026 scope_breakpoint
->related_breakpoint
= b
;
6029 value_free_to_mark (mark
);
6031 update_global_location_list (1);
6034 /* Return count of locations need to be watched and can be handled
6035 in hardware. If the watchpoint can not be handled
6036 in hardware return zero. */
6039 can_use_hardware_watchpoint (struct value
*v
)
6041 int found_memory_cnt
= 0;
6042 struct value
*head
= v
;
6044 /* Did the user specifically forbid us to use hardware watchpoints? */
6045 if (!can_use_hw_watchpoints
)
6048 /* Make sure that the value of the expression depends only upon
6049 memory contents, and values computed from them within GDB. If we
6050 find any register references or function calls, we can't use a
6051 hardware watchpoint.
6053 The idea here is that evaluating an expression generates a series
6054 of values, one holding the value of every subexpression. (The
6055 expression a*b+c has five subexpressions: a, b, a*b, c, and
6056 a*b+c.) GDB's values hold almost enough information to establish
6057 the criteria given above --- they identify memory lvalues,
6058 register lvalues, computed values, etcetera. So we can evaluate
6059 the expression, and then scan the chain of values that leaves
6060 behind to decide whether we can detect any possible change to the
6061 expression's final value using only hardware watchpoints.
6063 However, I don't think that the values returned by inferior
6064 function calls are special in any way. So this function may not
6065 notice that an expression involving an inferior function call
6066 can't be watched with hardware watchpoints. FIXME. */
6067 for (; v
; v
= value_next (v
))
6069 if (VALUE_LVAL (v
) == lval_memory
)
6072 /* A lazy memory lvalue is one that GDB never needed to fetch;
6073 we either just used its address (e.g., `a' in `a.b') or
6074 we never needed it at all (e.g., `a' in `a,b'). */
6078 /* Ahh, memory we actually used! Check if we can cover
6079 it with hardware watchpoints. */
6080 struct type
*vtype
= check_typedef (value_type (v
));
6082 /* We only watch structs and arrays if user asked for it
6083 explicitly, never if they just happen to appear in a
6084 middle of some value chain. */
6086 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6087 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6089 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6090 int len
= TYPE_LENGTH (value_type (v
));
6092 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6099 else if (VALUE_LVAL (v
) != not_lval
6100 && deprecated_value_modifiable (v
) == 0)
6101 return 0; /* ??? What does this represent? */
6102 else if (VALUE_LVAL (v
) == lval_register
)
6103 return 0; /* cannot watch a register with a HW watchpoint */
6106 /* The expression itself looks suitable for using a hardware
6107 watchpoint, but give the target machine a chance to reject it. */
6108 return found_memory_cnt
;
6112 watch_command_wrapper (char *arg
, int from_tty
)
6114 watch_command (arg
, from_tty
);
6118 watch_command (char *arg
, int from_tty
)
6120 watch_command_1 (arg
, hw_write
, from_tty
);
6124 rwatch_command_wrapper (char *arg
, int from_tty
)
6126 rwatch_command (arg
, from_tty
);
6130 rwatch_command (char *arg
, int from_tty
)
6132 watch_command_1 (arg
, hw_read
, from_tty
);
6136 awatch_command_wrapper (char *arg
, int from_tty
)
6138 awatch_command (arg
, from_tty
);
6142 awatch_command (char *arg
, int from_tty
)
6144 watch_command_1 (arg
, hw_access
, from_tty
);
6148 /* Helper routines for the until_command routine in infcmd.c. Here
6149 because it uses the mechanisms of breakpoints. */
6151 struct until_break_command_continuation_args
6153 struct breakpoint
*breakpoint
;
6154 struct breakpoint
*breakpoint2
;
6157 /* This function is called by fetch_inferior_event via the
6158 cmd_continuation pointer, to complete the until command. It takes
6159 care of cleaning up the temporary breakpoints set up by the until
6162 until_break_command_continuation (void *arg
)
6164 struct until_break_command_continuation_args
*a
= arg
;
6166 delete_breakpoint (a
->breakpoint
);
6168 delete_breakpoint (a
->breakpoint2
);
6172 until_break_command (char *arg
, int from_tty
, int anywhere
)
6174 struct symtabs_and_lines sals
;
6175 struct symtab_and_line sal
;
6176 struct frame_info
*frame
= get_selected_frame (NULL
);
6177 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6178 struct breakpoint
*breakpoint
;
6179 struct breakpoint
*breakpoint2
= NULL
;
6180 struct cleanup
*old_chain
;
6182 clear_proceed_status ();
6184 /* Set a breakpoint where the user wants it and at return from
6187 if (default_breakpoint_valid
)
6188 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6189 default_breakpoint_line
, (char ***) NULL
, NULL
);
6191 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6192 0, (char ***) NULL
, NULL
);
6194 if (sals
.nelts
!= 1)
6195 error (_("Couldn't get information on specified line."));
6198 xfree (sals
.sals
); /* malloc'd, so freed */
6201 error (_("Junk at end of arguments."));
6203 resolve_sal_pc (&sal
);
6206 /* If the user told us to continue until a specified location,
6207 we don't specify a frame at which we need to stop. */
6208 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6210 /* Otherwise, specify the current frame, because we want to stop only
6211 at the very same frame. */
6212 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6215 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6217 /* Keep within the current frame, or in frames called by the current
6221 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6222 sal
.pc
= get_frame_pc (prev_frame
);
6223 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6225 make_cleanup_delete_breakpoint (breakpoint2
);
6228 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6230 /* If we are running asynchronously, and proceed call above has actually
6231 managed to start the target, arrange for breakpoints to be
6232 deleted when the target stops. Otherwise, we're already stopped and
6233 delete breakpoints via cleanup chain. */
6235 if (target_can_async_p () && is_running (inferior_ptid
))
6237 struct until_break_command_continuation_args
*args
;
6238 args
= xmalloc (sizeof (*args
));
6240 args
->breakpoint
= breakpoint
;
6241 args
->breakpoint2
= breakpoint2
;
6243 discard_cleanups (old_chain
);
6244 add_continuation (until_break_command_continuation
, args
,
6248 do_cleanups (old_chain
);
6252 ep_skip_leading_whitespace (char **s
)
6254 if ((s
== NULL
) || (*s
== NULL
))
6256 while (isspace (**s
))
6260 /* This function examines a string, and attempts to find a token
6261 that might be an event name in the leading characters. If a
6262 possible match is found, a pointer to the last character of
6263 the token is returned. Else, NULL is returned. */
6266 ep_find_event_name_end (char *arg
)
6269 char *event_name_end
= NULL
;
6271 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6275 /* We break out of the loop when we find a token delimiter.
6276 Basically, we're looking for alphanumerics and underscores;
6277 anything else delimites the token. */
6280 if (!isalnum (*s
) && (*s
!= '_'))
6286 return event_name_end
;
6290 /* This function attempts to parse an optional "if <cond>" clause
6291 from the arg string. If one is not found, it returns NULL.
6293 Else, it returns a pointer to the condition string. (It does not
6294 attempt to evaluate the string against a particular block.) And,
6295 it updates arg to point to the first character following the parsed
6296 if clause in the arg string. */
6299 ep_parse_optional_if_clause (char **arg
)
6303 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6306 /* Skip the "if" keyword. */
6309 /* Skip any extra leading whitespace, and record the start of the
6310 condition string. */
6311 ep_skip_leading_whitespace (arg
);
6314 /* Assume that the condition occupies the remainder of the arg string. */
6315 (*arg
) += strlen (cond_string
);
6320 /* This function attempts to parse an optional filename from the arg
6321 string. If one is not found, it returns NULL.
6323 Else, it returns a pointer to the parsed filename. (This function
6324 makes no attempt to verify that a file of that name exists, or is
6325 accessible.) And, it updates arg to point to the first character
6326 following the parsed filename in the arg string.
6328 Note that clients needing to preserve the returned filename for
6329 future access should copy it to their own buffers. */
6331 ep_parse_optional_filename (char **arg
)
6333 static char filename
[1024];
6338 if ((*arg_p
== '\0') || isspace (*arg_p
))
6356 /* Commands to deal with catching events, such as signals, exceptions,
6357 process start/exit, etc. */
6361 catch_fork
, catch_vfork
6366 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6369 char *cond_string
= NULL
;
6371 ep_skip_leading_whitespace (&arg
);
6373 /* The allowed syntax is:
6375 catch [v]fork if <cond>
6377 First, check if there's an if clause. */
6378 cond_string
= ep_parse_optional_if_clause (&arg
);
6380 if ((*arg
!= '\0') && !isspace (*arg
))
6381 error (_("Junk at end of arguments."));
6383 /* If this target supports it, create a fork or vfork catchpoint
6384 and enable reporting of such events. */
6388 create_fork_event_catchpoint (tempflag
, cond_string
);
6391 create_vfork_event_catchpoint (tempflag
, cond_string
);
6394 error (_("unsupported or unknown fork kind; cannot catch it"));
6400 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6402 char *cond_string
= NULL
;
6404 ep_skip_leading_whitespace (&arg
);
6406 /* The allowed syntax is:
6408 catch exec if <cond>
6410 First, check if there's an if clause. */
6411 cond_string
= ep_parse_optional_if_clause (&arg
);
6413 if ((*arg
!= '\0') && !isspace (*arg
))
6414 error (_("Junk at end of arguments."));
6416 /* If this target supports it, create an exec catchpoint
6417 and enable reporting of such events. */
6418 create_exec_event_catchpoint (tempflag
, cond_string
);
6422 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6424 char *dll_pathname
= NULL
;
6425 char *cond_string
= NULL
;
6427 ep_skip_leading_whitespace (&arg
);
6429 /* The allowed syntax is:
6431 catch load if <cond>
6432 catch load <filename>
6433 catch load <filename> if <cond>
6435 The user is not allowed to specify the <filename> after an
6438 We'll ignore the pathological case of a file named "if".
6440 First, check if there's an if clause. If so, then there
6441 cannot be a filename. */
6442 cond_string
= ep_parse_optional_if_clause (&arg
);
6444 /* If there was an if clause, then there cannot be a filename.
6445 Else, there might be a filename and an if clause. */
6446 if (cond_string
== NULL
)
6448 dll_pathname
= ep_parse_optional_filename (&arg
);
6449 ep_skip_leading_whitespace (&arg
);
6450 cond_string
= ep_parse_optional_if_clause (&arg
);
6453 if ((*arg
!= '\0') && !isspace (*arg
))
6454 error (_("Junk at end of arguments."));
6456 /* Create a load breakpoint that only triggers when a load of
6457 the specified dll (or any dll, if no pathname was specified)
6459 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6460 dll_pathname
, cond_string
);
6464 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6466 char *dll_pathname
= NULL
;
6467 char *cond_string
= NULL
;
6469 ep_skip_leading_whitespace (&arg
);
6471 /* The allowed syntax is:
6473 catch unload if <cond>
6474 catch unload <filename>
6475 catch unload <filename> if <cond>
6477 The user is not allowed to specify the <filename> after an
6480 We'll ignore the pathological case of a file named "if".
6482 First, check if there's an if clause. If so, then there
6483 cannot be a filename. */
6484 cond_string
= ep_parse_optional_if_clause (&arg
);
6486 /* If there was an if clause, then there cannot be a filename.
6487 Else, there might be a filename and an if clause. */
6488 if (cond_string
== NULL
)
6490 dll_pathname
= ep_parse_optional_filename (&arg
);
6491 ep_skip_leading_whitespace (&arg
);
6492 cond_string
= ep_parse_optional_if_clause (&arg
);
6495 if ((*arg
!= '\0') && !isspace (*arg
))
6496 error (_("Junk at end of arguments."));
6498 /* Create an unload breakpoint that only triggers when an unload of
6499 the specified dll (or any dll, if no pathname was specified)
6501 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6502 dll_pathname
, cond_string
);
6505 static enum print_stop_action
6506 print_exception_catchpoint (struct breakpoint
*b
)
6508 int bp_temp
, bp_throw
;
6510 annotate_catchpoint (b
->number
);
6512 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6513 if (b
->loc
->address
!= b
->loc
->requested_address
)
6514 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6517 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6519 bp_temp
? "Temporary catchpoint "
6521 if (!ui_out_is_mi_like_p (uiout
))
6522 ui_out_field_int (uiout
, "bkptno", b
->number
);
6524 bp_throw
? " (exception thrown), "
6525 : " (exception caught), ");
6526 if (ui_out_is_mi_like_p (uiout
))
6528 ui_out_field_string (uiout
, "reason",
6529 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6530 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6531 ui_out_field_int (uiout
, "bkptno", b
->number
);
6533 return PRINT_SRC_AND_LOC
;
6537 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6542 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6543 ui_out_field_string (uiout
, "addr", "<PENDING>");
6545 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6549 *last_addr
= b
->loc
->address
;
6550 if (strstr (b
->addr_string
, "throw") != NULL
)
6551 ui_out_field_string (uiout
, "what", "exception throw");
6553 ui_out_field_string (uiout
, "what", "exception catch");
6557 print_mention_exception_catchpoint (struct breakpoint
*b
)
6562 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6563 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6564 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6565 : _("Catchpoint "));
6566 ui_out_field_int (uiout
, "bkptno", b
->number
);
6567 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6571 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6572 print_exception_catchpoint
,
6573 print_one_exception_catchpoint
,
6574 print_mention_exception_catchpoint
6578 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6579 enum exception_event_kind ex_event
, int from_tty
)
6581 char *trigger_func_name
;
6583 if (ex_event
== EX_EVENT_CATCH
)
6584 trigger_func_name
= "__cxa_begin_catch";
6586 trigger_func_name
= "__cxa_throw";
6588 break_command_really (trigger_func_name
, cond_string
, -1,
6589 0 /* condition and thread are valid. */,
6592 AUTO_BOOLEAN_TRUE
/* pending */,
6593 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6598 /* Deal with "catch catch" and "catch throw" commands */
6601 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6602 int tempflag
, int from_tty
)
6604 char *cond_string
= NULL
;
6605 struct symtab_and_line
*sal
= NULL
;
6607 ep_skip_leading_whitespace (&arg
);
6609 cond_string
= ep_parse_optional_if_clause (&arg
);
6611 if ((*arg
!= '\0') && !isspace (*arg
))
6612 error (_("Junk at end of arguments."));
6614 if ((ex_event
!= EX_EVENT_THROW
) &&
6615 (ex_event
!= EX_EVENT_CATCH
))
6616 error (_("Unsupported or unknown exception event; cannot catch it"));
6618 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6621 warning (_("Unsupported with this platform/compiler combination."));
6624 /* Create a breakpoint struct for Ada exception catchpoints. */
6627 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6631 struct expression
*cond
,
6632 struct breakpoint_ops
*ops
,
6636 struct breakpoint
*b
;
6640 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6641 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6642 version for exception catchpoints, because two catchpoints
6643 used for different exception names will use the same address.
6644 In this case, a "breakpoint ... also set at..." warning is
6645 unproductive. Besides. the warning phrasing is also a bit
6646 inapropriate, we should use the word catchpoint, and tell
6647 the user what type of catchpoint it is. The above is good
6648 enough for now, though. */
6651 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6652 set_breakpoint_count (breakpoint_count
+ 1);
6654 b
->enable_state
= bp_enabled
;
6655 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6656 b
->number
= breakpoint_count
;
6657 b
->ignore_count
= 0;
6658 b
->loc
->cond
= cond
;
6659 b
->addr_string
= addr_string
;
6660 b
->language
= language_ada
;
6661 b
->cond_string
= cond_string
;
6662 b
->exp_string
= exp_string
;
6667 update_global_location_list (1);
6670 /* Implement the "catch exception" command. */
6673 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6675 struct symtab_and_line sal
;
6677 char *addr_string
= NULL
;
6678 char *exp_string
= NULL
;
6679 char *cond_string
= NULL
;
6680 struct expression
*cond
= NULL
;
6681 struct breakpoint_ops
*ops
= NULL
;
6683 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6684 &cond_string
, &cond
, &ops
);
6685 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6686 cond_string
, cond
, ops
, tempflag
,
6690 /* Implement the "catch assert" command. */
6693 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6695 struct symtab_and_line sal
;
6696 char *addr_string
= NULL
;
6697 struct breakpoint_ops
*ops
= NULL
;
6699 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6700 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6701 tempflag
, from_tty
);
6705 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6708 /* The first argument may be an event name, such as "start" or "load".
6709 If so, then handle it as such. If it doesn't match an event name,
6710 then attempt to interpret it as an exception name. (This latter is
6711 the v4.16-and-earlier GDB meaning of the "catch" command.)
6713 First, try to find the bounds of what might be an event name. */
6714 char *arg1_start
= arg
;
6718 if (arg1_start
== NULL
)
6720 /* Old behaviour was to use pre-v-4.16 syntax */
6721 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6723 /* Now, this is not allowed */
6724 error (_("Catch requires an event name."));
6727 arg1_end
= ep_find_event_name_end (arg1_start
);
6728 if (arg1_end
== NULL
)
6729 error (_("catch requires an event"));
6730 arg1_length
= arg1_end
+ 1 - arg1_start
;
6732 /* Try to match what we found against known event names. */
6733 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6735 error (_("Catch of signal not yet implemented"));
6737 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6739 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6740 tempflag
, from_tty
);
6742 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6744 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6745 tempflag
, from_tty
);
6747 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6749 error (_("Catch of thread_start not yet implemented"));
6751 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6753 error (_("Catch of thread_exit not yet implemented"));
6755 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6757 error (_("Catch of thread_join not yet implemented"));
6759 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6761 error (_("Catch of start not yet implemented"));
6763 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6765 error (_("Catch of exit not yet implemented"));
6767 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6769 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6771 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6773 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6775 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6777 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6779 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6781 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6783 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6785 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6787 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6789 error (_("Catch of stop not yet implemented"));
6791 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6793 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6796 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6798 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6801 /* This doesn't appear to be an event name */
6805 /* Pre-v.4.16 behaviour was to treat the argument
6806 as the name of an exception */
6807 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6808 /* Now this is not allowed */
6809 error (_("Unknown event kind specified for catch"));
6815 catch_command (char *arg
, int from_tty
)
6817 catch_command_1 (arg
, 0, from_tty
);
6822 tcatch_command (char *arg
, int from_tty
)
6824 catch_command_1 (arg
, 1, from_tty
);
6827 /* Delete breakpoints by address or line. */
6830 clear_command (char *arg
, int from_tty
)
6832 struct breakpoint
*b
;
6833 VEC(breakpoint_p
) *found
= 0;
6836 struct symtabs_and_lines sals
;
6837 struct symtab_and_line sal
;
6842 sals
= decode_line_spec (arg
, 1);
6847 sals
.sals
= (struct symtab_and_line
*)
6848 xmalloc (sizeof (struct symtab_and_line
));
6849 make_cleanup (xfree
, sals
.sals
);
6850 init_sal (&sal
); /* initialize to zeroes */
6851 sal
.line
= default_breakpoint_line
;
6852 sal
.symtab
= default_breakpoint_symtab
;
6853 sal
.pc
= default_breakpoint_address
;
6854 if (sal
.symtab
== 0)
6855 error (_("No source file specified."));
6863 /* We don't call resolve_sal_pc here. That's not
6864 as bad as it seems, because all existing breakpoints
6865 typically have both file/line and pc set. So, if
6866 clear is given file/line, we can match this to existing
6867 breakpoint without obtaining pc at all.
6869 We only support clearing given the address explicitly
6870 present in breakpoint table. Say, we've set breakpoint
6871 at file:line. There were several PC values for that file:line,
6872 due to optimization, all in one block.
6873 We've picked one PC value. If "clear" is issued with another
6874 PC corresponding to the same file:line, the breakpoint won't
6875 be cleared. We probably can still clear the breakpoint, but
6876 since the other PC value is never presented to user, user
6877 can only find it by guessing, and it does not seem important
6880 /* For each line spec given, delete bps which correspond
6881 to it. Do it in two passes, solely to preserve the current
6882 behavior that from_tty is forced true if we delete more than
6886 for (i
= 0; i
< sals
.nelts
; i
++)
6888 /* If exact pc given, clear bpts at that pc.
6889 If line given (pc == 0), clear all bpts on specified line.
6890 If defaulting, clear all bpts on default line
6893 defaulting sal.pc != 0 tests to do
6898 1 0 <can't happen> */
6902 /* Find all matching breakpoints and add them to
6907 /* Are we going to delete b? */
6908 if (b
->type
!= bp_none
6909 && b
->type
!= bp_watchpoint
6910 && b
->type
!= bp_hardware_watchpoint
6911 && b
->type
!= bp_read_watchpoint
6912 && b
->type
!= bp_access_watchpoint
)
6914 struct bp_location
*loc
= b
->loc
;
6915 for (; loc
; loc
= loc
->next
)
6917 int pc_match
= sal
.pc
6918 && (loc
->address
== sal
.pc
)
6919 && (!section_is_overlay (loc
->section
)
6920 || loc
->section
== sal
.section
);
6921 int line_match
= ((default_match
|| (0 == sal
.pc
))
6922 && b
->source_file
!= NULL
6923 && sal
.symtab
!= NULL
6924 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6925 && b
->line_number
== sal
.line
);
6926 if (pc_match
|| line_match
)
6935 VEC_safe_push(breakpoint_p
, found
, b
);
6938 /* Now go thru the 'found' chain and delete them. */
6939 if (VEC_empty(breakpoint_p
, found
))
6942 error (_("No breakpoint at %s."), arg
);
6944 error (_("No breakpoint at this line."));
6947 if (VEC_length(breakpoint_p
, found
) > 1)
6948 from_tty
= 1; /* Always report if deleted more than one */
6951 if (VEC_length(breakpoint_p
, found
) == 1)
6952 printf_unfiltered (_("Deleted breakpoint "));
6954 printf_unfiltered (_("Deleted breakpoints "));
6956 breakpoints_changed ();
6958 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6961 printf_unfiltered ("%d ", b
->number
);
6962 delete_breakpoint (b
);
6965 putchar_unfiltered ('\n');
6968 /* Delete breakpoint in BS if they are `delete' breakpoints and
6969 all breakpoints that are marked for deletion, whether hit or not.
6970 This is called after any breakpoint is hit, or after errors. */
6973 breakpoint_auto_delete (bpstat bs
)
6975 struct breakpoint
*b
, *temp
;
6977 for (; bs
; bs
= bs
->next
)
6978 if (bs
->breakpoint_at
6979 && bs
->breakpoint_at
->owner
6980 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6982 delete_breakpoint (bs
->breakpoint_at
->owner
);
6984 ALL_BREAKPOINTS_SAFE (b
, temp
)
6986 if (b
->disposition
== disp_del_at_next_stop
)
6987 delete_breakpoint (b
);
6991 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
6992 into the inferior, only remove already-inserted locations that no
6993 longer should be inserted. Functions that delete a breakpoint or
6994 breakpoints should pass false, so that deleting a breakpoint
6995 doesn't have the side effect of inserting the locations of other
6996 breakpoints that are marked not-inserted, but should_be_inserted
6997 returns true on them.
6999 This behaviour is useful is situations close to tear-down -- e.g.,
7000 after an exec, while the target still has execution, but breakpoint
7001 shadows of the previous executable image should *NOT* be restored
7002 to the new image; or before detaching, where the target still has
7003 execution and wants to delete breakpoints from GDB's lists, and all
7004 breakpoints had already been removed from the inferior. */
7007 update_global_location_list (int should_insert
)
7009 struct breakpoint
*b
;
7010 struct bp_location
**next
= &bp_location_chain
;
7011 struct bp_location
*loc
;
7012 struct bp_location
*loc2
;
7013 struct gdb_exception e
;
7014 VEC(bp_location_p
) *old_locations
= NULL
;
7018 /* Store old locations for future reference. */
7019 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7020 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7022 bp_location_chain
= NULL
;
7025 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7028 next
= &(loc
->global_next
);
7033 /* Identify bp_location instances that are no longer present in the new
7034 list, and therefore should be freed. Note that it's not necessary that
7035 those locations should be removed from inferior -- if there's another
7036 location at the same address (previously marked as duplicate),
7037 we don't need to remove/insert the location. */
7038 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7040 /* Tells if 'loc' is found amoung the new locations. If not, we
7042 int found_object
= 0;
7043 /* Tells if the location should remain inserted in the target. */
7044 int keep_in_target
= 0;
7046 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7053 /* If this location is no longer present, and inserted, look if there's
7054 maybe a new location at the same address. If so, mark that one
7055 inserted, and don't remove this one. This is needed so that we
7056 don't have a time window where a breakpoint at certain location is not
7061 /* If the location is inserted now, we might have to remove it. */
7063 if (found_object
&& should_be_inserted (loc
))
7065 /* The location is still present in the location list, and still
7066 should be inserted. Don't do anything. */
7071 /* The location is either no longer present, or got disabled.
7072 See if there's another location at the same address, in which
7073 case we don't need to remove this one from the target. */
7074 if (breakpoint_address_is_meaningful (loc
->owner
))
7075 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7077 /* For the sake of should_insert_location. The
7078 call to check_duplicates will fix up this later. */
7079 loc2
->duplicate
= 0;
7080 if (should_be_inserted (loc2
)
7081 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7084 loc2
->target_info
= loc
->target_info
;
7091 if (!keep_in_target
)
7093 if (remove_breakpoint (loc
, mark_uninserted
))
7095 /* This is just about all we can do. We could keep this
7096 location on the global list, and try to remove it next
7097 time, but there's no particular reason why we will
7100 Note that at this point, loc->owner is still valid,
7101 as delete_breakpoint frees the breakpoint only
7102 after calling us. */
7103 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7104 loc
->owner
->number
);
7114 /* This location was removed from the targets. In non-stop mode,
7115 a race condition is possible where we've removed a breakpoint,
7116 but stop events for that breakpoint are already queued and will
7117 arrive later. To suppress spurious SIGTRAPs reported to user,
7118 we keep this breakpoint location for a bit, and will retire it
7119 after we see 3 * thread_count events.
7120 The theory here is that reporting of events should,
7121 "on the average", be fair, so after that many event we'll see
7122 events from all threads that have anything of interest, and no
7123 longer need to keep this breakpoint. This is just a
7124 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7125 which is usability issue, but not a correctness problem. */
7126 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7130 free_bp_location (loc
);
7136 check_duplicates (b
);
7139 if (always_inserted_mode
&& should_insert
&& target_has_execution
)
7140 insert_breakpoint_locations ();
7144 breakpoint_retire_moribund (void)
7146 struct bp_location
*loc
;
7149 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7150 if (--(loc
->events_till_retirement
) == 0)
7152 free_bp_location (loc
);
7153 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7159 update_global_location_list_nothrow (int inserting
)
7161 struct gdb_exception e
;
7162 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7163 update_global_location_list (inserting
);
7166 /* Clear BPT from a BPS. */
7168 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7171 for (bs
= bps
; bs
; bs
= bs
->next
)
7172 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7174 bs
->breakpoint_at
= NULL
;
7176 /* bs->commands will be freed later. */
7180 /* Callback for iterate_over_threads. */
7182 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7184 struct breakpoint
*bpt
= data
;
7185 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7189 /* Delete a breakpoint and clean up all traces of it in the data
7193 delete_breakpoint (struct breakpoint
*bpt
)
7195 struct breakpoint
*b
;
7196 struct bp_location
*loc
, *next
;
7198 gdb_assert (bpt
!= NULL
);
7200 /* Has this bp already been deleted? This can happen because multiple
7201 lists can hold pointers to bp's. bpstat lists are especial culprits.
7203 One example of this happening is a watchpoint's scope bp. When the
7204 scope bp triggers, we notice that the watchpoint is out of scope, and
7205 delete it. We also delete its scope bp. But the scope bp is marked
7206 "auto-deleting", and is already on a bpstat. That bpstat is then
7207 checked for auto-deleting bp's, which are deleted.
7209 A real solution to this problem might involve reference counts in bp's,
7210 and/or giving them pointers back to their referencing bpstat's, and
7211 teaching delete_breakpoint to only free a bp's storage when no more
7212 references were extent. A cheaper bandaid was chosen. */
7213 if (bpt
->type
== bp_none
)
7216 if (deprecated_delete_breakpoint_hook
)
7217 deprecated_delete_breakpoint_hook (bpt
);
7218 observer_notify_breakpoint_deleted (bpt
->number
);
7220 if (breakpoint_chain
== bpt
)
7221 breakpoint_chain
= bpt
->next
;
7226 b
->next
= bpt
->next
;
7230 free_command_lines (&bpt
->commands
);
7231 if (bpt
->cond_string
!= NULL
)
7232 xfree (bpt
->cond_string
);
7233 if (bpt
->addr_string
!= NULL
)
7234 xfree (bpt
->addr_string
);
7235 if (bpt
->exp
!= NULL
)
7237 if (bpt
->exp_string
!= NULL
)
7238 xfree (bpt
->exp_string
);
7239 if (bpt
->val
!= NULL
)
7240 value_free (bpt
->val
);
7241 if (bpt
->source_file
!= NULL
)
7242 xfree (bpt
->source_file
);
7243 if (bpt
->dll_pathname
!= NULL
)
7244 xfree (bpt
->dll_pathname
);
7245 if (bpt
->triggered_dll_pathname
!= NULL
)
7246 xfree (bpt
->triggered_dll_pathname
);
7247 if (bpt
->exec_pathname
!= NULL
)
7248 xfree (bpt
->exec_pathname
);
7250 /* Be sure no bpstat's are pointing at it after it's been freed. */
7251 /* FIXME, how can we find all bpstat's?
7252 We just check stop_bpstat for now. Note that we cannot just
7253 remove bpstats pointing at bpt from the stop_bpstat list
7254 entirely, as breakpoint commands are associated with the bpstat;
7255 if we remove it here, then the later call to
7256 bpstat_do_actions (&stop_bpstat);
7257 in event-top.c won't do anything, and temporary breakpoints
7258 with commands won't work. */
7260 /* Clear the current context. */
7261 bpstat_remove_breakpoint (stop_bpstat
, bpt
);
7262 /* And from all threads. */
7263 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7265 /* Now that breakpoint is removed from breakpoint
7266 list, update the global location list. This
7267 will remove locations that used to belong to
7268 this breakpoint. Do this before freeing
7269 the breakpoint itself, since remove_breakpoint
7270 looks at location's owner. It might be better
7271 design to have location completely self-contained,
7272 but it's not the case now. */
7273 update_global_location_list (0);
7276 /* On the chance that someone will soon try again to delete this same
7277 bp, we mark it as deleted before freeing its storage. */
7278 bpt
->type
= bp_none
;
7284 do_delete_breakpoint_cleanup (void *b
)
7286 delete_breakpoint (b
);
7290 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7292 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7296 delete_command (char *arg
, int from_tty
)
7298 struct breakpoint
*b
, *temp
;
7304 int breaks_to_delete
= 0;
7306 /* Delete all breakpoints if no argument.
7307 Do not delete internal or call-dummy breakpoints, these
7308 have to be deleted with an explicit breakpoint number argument. */
7311 if (b
->type
!= bp_call_dummy
&&
7312 b
->type
!= bp_shlib_event
&&
7313 b
->type
!= bp_thread_event
&&
7314 b
->type
!= bp_overlay_event
&&
7317 breaks_to_delete
= 1;
7322 /* Ask user only if there are some breakpoints to delete. */
7324 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7326 ALL_BREAKPOINTS_SAFE (b
, temp
)
7328 if (b
->type
!= bp_call_dummy
&&
7329 b
->type
!= bp_shlib_event
&&
7330 b
->type
!= bp_thread_event
&&
7331 b
->type
!= bp_overlay_event
&&
7333 delete_breakpoint (b
);
7338 map_breakpoint_numbers (arg
, delete_breakpoint
);
7342 all_locations_are_pending (struct bp_location
*loc
)
7344 for (; loc
; loc
= loc
->next
)
7345 if (!loc
->shlib_disabled
)
7350 /* Subroutine of update_breakpoint_locations to simplify it.
7351 Return non-zero if multiple fns in list LOC have the same name.
7352 Null names are ignored. */
7355 ambiguous_names_p (struct bp_location
*loc
)
7357 struct bp_location
*l
;
7358 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7359 (int (*) (const void *, const void *)) streq
,
7360 NULL
, xcalloc
, xfree
);
7362 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7365 const char *name
= l
->function_name
;
7367 /* Allow for some names to be NULL, ignore them. */
7371 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7373 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7388 update_breakpoint_locations (struct breakpoint
*b
,
7389 struct symtabs_and_lines sals
)
7393 struct bp_location
*existing_locations
= b
->loc
;
7395 /* If there's no new locations, and all existing locations
7396 are pending, don't do anything. This optimizes
7397 the common case where all locations are in the same
7398 shared library, that was unloaded. We'd like to
7399 retain the location, so that when the library
7400 is loaded again, we don't loose the enabled/disabled
7401 status of the individual locations. */
7402 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7407 for (i
= 0; i
< sals
.nelts
; ++i
)
7409 struct bp_location
*new_loc
=
7410 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7412 /* Reparse conditions, they might contain references to the
7414 if (b
->cond_string
!= NULL
)
7416 struct gdb_exception e
;
7419 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7421 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7426 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7427 b
->number
, e
.message
);
7428 new_loc
->enabled
= 0;
7432 if (b
->source_file
!= NULL
)
7433 xfree (b
->source_file
);
7434 if (sals
.sals
[i
].symtab
== NULL
)
7435 b
->source_file
= NULL
;
7438 savestring (sals
.sals
[i
].symtab
->filename
,
7439 strlen (sals
.sals
[i
].symtab
->filename
));
7441 if (b
->line_number
== 0)
7442 b
->line_number
= sals
.sals
[i
].line
;
7445 /* If possible, carry over 'disable' status from existing breakpoints. */
7447 struct bp_location
*e
= existing_locations
;
7448 /* If there are multiple breakpoints with the same function name,
7449 e.g. for inline functions, comparing function names won't work.
7450 Instead compare pc addresses; this is just a heuristic as things
7451 may have moved, but in practice it gives the correct answer
7452 often enough until a better solution is found. */
7453 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7455 for (; e
; e
= e
->next
)
7457 if (!e
->enabled
&& e
->function_name
)
7459 struct bp_location
*l
= b
->loc
;
7460 if (have_ambiguous_names
)
7462 for (; l
; l
= l
->next
)
7463 if (e
->address
== l
->address
)
7471 for (; l
; l
= l
->next
)
7472 if (l
->function_name
7473 && strcmp (e
->function_name
, l
->function_name
) == 0)
7483 update_global_location_list (1);
7487 /* Reset a breakpoint given it's struct breakpoint * BINT.
7488 The value we return ends up being the return value from catch_errors.
7489 Unused in this case. */
7492 breakpoint_re_set_one (void *bint
)
7494 /* get past catch_errs */
7495 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7499 int *not_found_ptr
= ¬_found
;
7500 struct symtabs_and_lines sals
= {};
7501 struct symtabs_and_lines expanded
;
7503 enum enable_state save_enable
;
7504 struct gdb_exception e
;
7510 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7514 case bp_hardware_breakpoint
:
7516 case bp_catch_unload
:
7517 if (b
->addr_string
== NULL
)
7519 /* Anything without a string can't be re-set. */
7520 delete_breakpoint (b
);
7524 set_language (b
->language
);
7525 input_radix
= b
->input_radix
;
7527 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7529 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7534 int not_found_and_ok
= 0;
7535 /* For pending breakpoints, it's expected that parsing
7536 will fail until the right shared library is loaded.
7537 User has already told to create pending breakpoints and
7538 don't need extra messages. If breakpoint is in bp_shlib_disabled
7539 state, then user already saw the message about that breakpoint
7540 being disabled, and don't want to see more errors. */
7542 && (b
->condition_not_parsed
7543 || (b
->loc
&& b
->loc
->shlib_disabled
)
7544 || b
->enable_state
== bp_disabled
))
7545 not_found_and_ok
= 1;
7547 if (!not_found_and_ok
)
7549 /* We surely don't want to warn about the same breakpoint
7550 10 times. One solution, implemented here, is disable
7551 the breakpoint on error. Another solution would be to
7552 have separate 'warning emitted' flag. Since this
7553 happens only when a binary has changed, I don't know
7554 which approach is better. */
7555 b
->enable_state
= bp_disabled
;
7556 throw_exception (e
);
7563 gdb_assert (sals
.nelts
== 1);
7564 resolve_sal_pc (&sals
.sals
[0]);
7565 if (b
->condition_not_parsed
&& s
&& s
[0])
7567 char *cond_string
= 0;
7569 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7570 &cond_string
, &thread
);
7572 b
->cond_string
= cond_string
;
7574 b
->condition_not_parsed
= 0;
7576 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7577 update_breakpoint_locations (b
, expanded
);
7583 case bp_hardware_watchpoint
:
7584 case bp_read_watchpoint
:
7585 case bp_access_watchpoint
:
7586 /* Watchpoint can be either on expression using entirely global variables,
7587 or it can be on local variables.
7589 Watchpoints of the first kind are never auto-deleted, and even persist
7590 across program restarts. Since they can use variables from shared
7591 libraries, we need to reparse expression as libraries are loaded
7594 Watchpoints on local variables can also change meaning as result
7595 of solib event. For example, if a watchpoint uses both a local and
7596 a global variables in expression, it's a local watchpoint, but
7597 unloading of a shared library will make the expression invalid.
7598 This is not a very common use case, but we still re-evaluate
7599 expression, to avoid surprises to the user.
7601 Note that for local watchpoints, we re-evaluate it only if
7602 watchpoints frame id is still valid. If it's not, it means
7603 the watchpoint is out of scope and will be deleted soon. In fact,
7604 I'm not sure we'll ever be called in this case.
7606 If a local watchpoint's frame id is still valid, then
7607 b->exp_valid_block is likewise valid, and we can safely use it.
7609 Don't do anything about disabled watchpoints, since they will
7610 be reevaluated again when enabled. */
7611 update_watchpoint (b
, 1 /* reparse */);
7613 /* We needn't really do anything to reset these, since the mask
7614 that requests them is unaffected by e.g., new libraries being
7617 case bp_catch_vfork
:
7622 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7624 /* Delete overlay event breakpoints; they will be reset later by
7625 breakpoint_re_set. */
7626 case bp_overlay_event
:
7627 delete_breakpoint (b
);
7630 /* This breakpoint is special, it's set up when the inferior
7631 starts and we really don't want to touch it. */
7632 case bp_shlib_event
:
7634 /* Like bp_shlib_event, this breakpoint type is special.
7635 Once it is set up, we do not want to touch it. */
7636 case bp_thread_event
:
7638 /* Keep temporary breakpoints, which can be encountered when we step
7639 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7640 Otherwise these should have been blown away via the cleanup chain
7641 or by breakpoint_init_inferior when we rerun the executable. */
7644 case bp_watchpoint_scope
:
7646 case bp_step_resume
:
7648 case bp_longjmp_resume
:
7655 /* Re-set all breakpoints after symbols have been re-loaded. */
7657 breakpoint_re_set (void)
7659 struct breakpoint
*b
, *temp
;
7660 enum language save_language
;
7661 int save_input_radix
;
7663 save_language
= current_language
->la_language
;
7664 save_input_radix
= input_radix
;
7665 ALL_BREAKPOINTS_SAFE (b
, temp
)
7667 /* Format possible error msg */
7668 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7670 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7671 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7672 do_cleanups (cleanups
);
7674 set_language (save_language
);
7675 input_radix
= save_input_radix
;
7677 create_overlay_event_breakpoint ("_ovly_debug_event");
7680 /* Reset the thread number of this breakpoint:
7682 - If the breakpoint is for all threads, leave it as-is.
7683 - Else, reset it to the current thread for inferior_ptid. */
7685 breakpoint_re_set_thread (struct breakpoint
*b
)
7687 if (b
->thread
!= -1)
7689 if (in_thread_list (inferior_ptid
))
7690 b
->thread
= pid_to_thread_id (inferior_ptid
);
7694 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7695 If from_tty is nonzero, it prints a message to that effect,
7696 which ends with a period (no newline). */
7699 set_ignore_count (int bptnum
, int count
, int from_tty
)
7701 struct breakpoint
*b
;
7707 if (b
->number
== bptnum
)
7709 b
->ignore_count
= count
;
7713 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7715 else if (count
== 1)
7716 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7719 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7722 breakpoints_changed ();
7723 observer_notify_breakpoint_modified (b
->number
);
7727 error (_("No breakpoint number %d."), bptnum
);
7730 /* Clear the ignore counts of all breakpoints. */
7732 breakpoint_clear_ignore_counts (void)
7734 struct breakpoint
*b
;
7737 b
->ignore_count
= 0;
7740 /* Command to set ignore-count of breakpoint N to COUNT. */
7743 ignore_command (char *args
, int from_tty
)
7749 error_no_arg (_("a breakpoint number"));
7751 num
= get_number (&p
);
7753 error (_("bad breakpoint number: '%s'"), args
);
7755 error (_("Second argument (specified ignore-count) is missing."));
7757 set_ignore_count (num
,
7758 longest_to_int (value_as_long (parse_and_eval (p
))),
7761 printf_filtered ("\n");
7764 /* Call FUNCTION on each of the breakpoints
7765 whose numbers are given in ARGS. */
7768 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7773 struct breakpoint
*b
, *tmp
;
7777 error_no_arg (_("one or more breakpoint numbers"));
7784 num
= get_number_or_range (&p1
);
7787 warning (_("bad breakpoint number at or near '%s'"), p
);
7791 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7792 if (b
->number
== num
)
7794 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7797 if (related_breakpoint
)
7798 function (related_breakpoint
);
7802 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7808 static struct bp_location
*
7809 find_location_by_number (char *number
)
7811 char *dot
= strchr (number
, '.');
7815 struct breakpoint
*b
;
7816 struct bp_location
*loc
;
7821 bp_num
= get_number_or_range (&p1
);
7823 error (_("Bad breakpoint number '%s'"), number
);
7826 if (b
->number
== bp_num
)
7831 if (!b
|| b
->number
!= bp_num
)
7832 error (_("Bad breakpoint number '%s'"), number
);
7835 loc_num
= get_number_or_range (&p1
);
7837 error (_("Bad breakpoint location number '%s'"), number
);
7841 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7844 error (_("Bad breakpoint location number '%s'"), dot
+1);
7850 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7851 If from_tty is nonzero, it prints a message to that effect,
7852 which ends with a period (no newline). */
7855 disable_breakpoint (struct breakpoint
*bpt
)
7857 /* Never disable a watchpoint scope breakpoint; we want to
7858 hit them when we leave scope so we can delete both the
7859 watchpoint and its scope breakpoint at that time. */
7860 if (bpt
->type
== bp_watchpoint_scope
)
7863 /* You can't disable permanent breakpoints. */
7864 if (bpt
->enable_state
== bp_permanent
)
7867 bpt
->enable_state
= bp_disabled
;
7869 update_global_location_list (0);
7871 if (deprecated_modify_breakpoint_hook
)
7872 deprecated_modify_breakpoint_hook (bpt
);
7873 observer_notify_breakpoint_modified (bpt
->number
);
7877 disable_command (char *args
, int from_tty
)
7879 struct breakpoint
*bpt
;
7881 ALL_BREAKPOINTS (bpt
)
7885 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7890 case bp_catch_unload
:
7892 case bp_catch_vfork
:
7894 case bp_hardware_breakpoint
:
7896 case bp_hardware_watchpoint
:
7897 case bp_read_watchpoint
:
7898 case bp_access_watchpoint
:
7899 disable_breakpoint (bpt
);
7903 else if (strchr (args
, '.'))
7905 struct bp_location
*loc
= find_location_by_number (args
);
7908 update_global_location_list (0);
7911 map_breakpoint_numbers (args
, disable_breakpoint
);
7915 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7917 int target_resources_ok
, other_type_used
;
7920 if (bpt
->type
== bp_hardware_breakpoint
)
7923 i
= hw_breakpoint_used_count ();
7924 target_resources_ok
=
7925 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7927 if (target_resources_ok
== 0)
7928 error (_("No hardware breakpoint support in the target."));
7929 else if (target_resources_ok
< 0)
7930 error (_("Hardware breakpoints used exceeds limit."));
7933 if (bpt
->type
== bp_watchpoint
||
7934 bpt
->type
== bp_hardware_watchpoint
||
7935 bpt
->type
== bp_read_watchpoint
||
7936 bpt
->type
== bp_access_watchpoint
)
7938 struct frame_id saved_frame_id
;
7940 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7941 if (bpt
->exp_valid_block
!= NULL
)
7943 struct frame_info
*fr
=
7944 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7947 printf_filtered (_("\
7948 Cannot enable watchpoint %d because the block in which its expression\n\
7949 is valid is not currently in scope.\n"), bpt
->number
);
7956 value_free (bpt
->val
);
7957 mark
= value_mark ();
7958 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7960 release_value (bpt
->val
);
7963 if (bpt
->type
== bp_hardware_watchpoint
||
7964 bpt
->type
== bp_read_watchpoint
||
7965 bpt
->type
== bp_access_watchpoint
)
7967 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7968 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7970 /* Hack around 'unused var' error for some targets here */
7971 (void) mem_cnt
, (void) i
;
7972 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7973 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7974 /* we can consider of type is bp_hardware_watchpoint, convert to
7975 bp_watchpoint in the following condition */
7976 if (target_resources_ok
< 0)
7978 printf_filtered (_("\
7979 Cannot enable watchpoint %d because target watch resources\n\
7980 have been allocated for other watchpoints.\n"), bpt
->number
);
7981 value_free_to_mark (mark
);
7986 select_frame (frame_find_by_id (saved_frame_id
));
7987 value_free_to_mark (mark
);
7990 if (bpt
->enable_state
!= bp_permanent
)
7991 bpt
->enable_state
= bp_enabled
;
7992 bpt
->disposition
= disposition
;
7993 update_global_location_list (1);
7994 breakpoints_changed ();
7996 if (deprecated_modify_breakpoint_hook
)
7997 deprecated_modify_breakpoint_hook (bpt
);
7998 observer_notify_breakpoint_modified (bpt
->number
);
8003 enable_breakpoint (struct breakpoint
*bpt
)
8005 do_enable_breakpoint (bpt
, bpt
->disposition
);
8008 /* The enable command enables the specified breakpoints (or all defined
8009 breakpoints) so they once again become (or continue to be) effective
8010 in stopping the inferior. */
8013 enable_command (char *args
, int from_tty
)
8015 struct breakpoint
*bpt
;
8017 ALL_BREAKPOINTS (bpt
)
8021 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8026 case bp_catch_unload
:
8028 case bp_catch_vfork
:
8030 case bp_hardware_breakpoint
:
8032 case bp_hardware_watchpoint
:
8033 case bp_read_watchpoint
:
8034 case bp_access_watchpoint
:
8035 enable_breakpoint (bpt
);
8039 else if (strchr (args
, '.'))
8041 struct bp_location
*loc
= find_location_by_number (args
);
8044 update_global_location_list (1);
8047 map_breakpoint_numbers (args
, enable_breakpoint
);
8051 enable_once_breakpoint (struct breakpoint
*bpt
)
8053 do_enable_breakpoint (bpt
, disp_disable
);
8057 enable_once_command (char *args
, int from_tty
)
8059 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8063 enable_delete_breakpoint (struct breakpoint
*bpt
)
8065 do_enable_breakpoint (bpt
, disp_del
);
8069 enable_delete_command (char *args
, int from_tty
)
8071 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8075 set_breakpoint_cmd (char *args
, int from_tty
)
8080 show_breakpoint_cmd (char *args
, int from_tty
)
8084 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8086 struct symtabs_and_lines
8087 decode_line_spec_1 (char *string
, int funfirstline
)
8089 struct symtabs_and_lines sals
;
8091 error (_("Empty line specification."));
8092 if (default_breakpoint_valid
)
8093 sals
= decode_line_1 (&string
, funfirstline
,
8094 default_breakpoint_symtab
,
8095 default_breakpoint_line
,
8096 (char ***) NULL
, NULL
);
8098 sals
= decode_line_1 (&string
, funfirstline
,
8099 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8101 error (_("Junk at end of line specification: %s"), string
);
8105 /* Create and insert a raw software breakpoint at PC. Return an
8106 identifier, which should be used to remove the breakpoint later.
8107 In general, places which call this should be using something on the
8108 breakpoint chain instead; this function should be eliminated
8112 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8114 struct bp_target_info
*bp_tgt
;
8116 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8117 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8119 bp_tgt
->placed_address
= pc
;
8120 if (target_insert_breakpoint (bp_tgt
) != 0)
8122 /* Could not insert the breakpoint. */
8130 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8133 deprecated_remove_raw_breakpoint (void *bp
)
8135 struct bp_target_info
*bp_tgt
= bp
;
8138 ret
= target_remove_breakpoint (bp_tgt
);
8144 /* One (or perhaps two) breakpoints used for software single stepping. */
8146 static void *single_step_breakpoints
[2];
8148 /* Create and insert a breakpoint for software single step. */
8151 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8155 if (single_step_breakpoints
[0] == NULL
)
8156 bpt_p
= &single_step_breakpoints
[0];
8159 gdb_assert (single_step_breakpoints
[1] == NULL
);
8160 bpt_p
= &single_step_breakpoints
[1];
8163 /* NOTE drow/2006-04-11: A future improvement to this function would be
8164 to only create the breakpoints once, and actually put them on the
8165 breakpoint chain. That would let us use set_raw_breakpoint. We could
8166 adjust the addresses each time they were needed. Doing this requires
8167 corresponding changes elsewhere where single step breakpoints are
8168 handled, however. So, for now, we use this. */
8170 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8172 error (_("Could not insert single-step breakpoint at 0x%s"),
8173 paddr_nz (next_pc
));
8176 /* Remove and delete any breakpoints used for software single step. */
8179 remove_single_step_breakpoints (void)
8181 gdb_assert (single_step_breakpoints
[0] != NULL
);
8183 /* See insert_single_step_breakpoint for more about this deprecated
8185 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8186 single_step_breakpoints
[0] = NULL
;
8188 if (single_step_breakpoints
[1] != NULL
)
8190 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8191 single_step_breakpoints
[1] = NULL
;
8195 /* Check whether a software single-step breakpoint is inserted at PC. */
8198 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8202 for (i
= 0; i
< 2; i
++)
8204 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8205 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8212 int breakpoints_always_inserted_mode (void)
8214 return always_inserted_mode
;
8218 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8219 It is defined as a macro to prevent duplication.
8220 COMMAND should be a string constant containing the name of the command. */
8221 #define BREAK_ARGS_HELP(command) \
8222 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8223 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8224 If a line number is specified, break at start of code for that line.\n\
8225 If a function is specified, break at start of code for that function.\n\
8226 If an address is specified, break at that exact address.\n\
8227 With no LOCATION, uses current execution address of selected stack frame.\n\
8228 This is useful for breaking on return to a stack frame.\n\
8230 THREADNUM is the number from \"info threads\".\n\
8231 CONDITION is a boolean expression.\n\
8233 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8235 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8238 _initialize_breakpoint (void)
8240 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8241 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8242 struct cmd_list_element
*c
;
8244 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8246 breakpoint_chain
= 0;
8247 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8248 before a breakpoint is set. */
8249 breakpoint_count
= 0;
8251 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8252 Set ignore-count of breakpoint number N to COUNT.\n\
8253 Usage is `ignore N COUNT'."));
8255 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8257 add_com ("commands", class_breakpoint
, commands_command
, _("\
8258 Set commands to be executed when a breakpoint is hit.\n\
8259 Give breakpoint number as argument after \"commands\".\n\
8260 With no argument, the targeted breakpoint is the last one set.\n\
8261 The commands themselves follow starting on the next line.\n\
8262 Type a line containing \"end\" to indicate the end of them.\n\
8263 Give \"silent\" as the first line to make the breakpoint silent;\n\
8264 then no output is printed when it is hit, except what the commands print."));
8266 add_com ("condition", class_breakpoint
, condition_command
, _("\
8267 Specify breakpoint number N to break only if COND is true.\n\
8268 Usage is `condition N COND', where N is an integer and COND is an\n\
8269 expression to be evaluated whenever breakpoint N is reached."));
8271 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8272 Set a temporary breakpoint.\n\
8273 Like \"break\" except the breakpoint is only temporary,\n\
8274 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8275 by using \"enable delete\" on the breakpoint number.\n\
8277 BREAK_ARGS_HELP ("tbreak")));
8278 set_cmd_completer (c
, location_completer
);
8280 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8281 Set a hardware assisted breakpoint.\n\
8282 Like \"break\" except the breakpoint requires hardware support,\n\
8283 some target hardware may not have this support.\n\
8285 BREAK_ARGS_HELP ("hbreak")));
8286 set_cmd_completer (c
, location_completer
);
8288 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8289 Set a temporary hardware assisted breakpoint.\n\
8290 Like \"hbreak\" except the breakpoint is only temporary,\n\
8291 so it will be deleted when hit.\n\
8293 BREAK_ARGS_HELP ("thbreak")));
8294 set_cmd_completer (c
, location_completer
);
8296 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8297 Enable some breakpoints.\n\
8298 Give breakpoint numbers (separated by spaces) as arguments.\n\
8299 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8300 This is used to cancel the effect of the \"disable\" command.\n\
8301 With a subcommand you can enable temporarily."),
8302 &enablelist
, "enable ", 1, &cmdlist
);
8304 add_com ("ab", class_breakpoint
, enable_command
, _("\
8305 Enable some breakpoints.\n\
8306 Give breakpoint numbers (separated by spaces) as arguments.\n\
8307 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8308 This is used to cancel the effect of the \"disable\" command.\n\
8309 With a subcommand you can enable temporarily."));
8311 add_com_alias ("en", "enable", class_breakpoint
, 1);
8313 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8314 Enable some breakpoints.\n\
8315 Give breakpoint numbers (separated by spaces) as arguments.\n\
8316 This is used to cancel the effect of the \"disable\" command.\n\
8317 May be abbreviated to simply \"enable\".\n"),
8318 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8320 add_cmd ("once", no_class
, enable_once_command
, _("\
8321 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8322 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8325 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8326 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8327 If a breakpoint is hit while enabled in this fashion, it is deleted."),
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 ("once", no_class
, enable_once_command
, _("\
8336 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8337 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8340 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8341 Disable some breakpoints.\n\
8342 Arguments are breakpoint numbers with spaces in between.\n\
8343 To disable all breakpoints, give no argument.\n\
8344 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8345 &disablelist
, "disable ", 1, &cmdlist
);
8346 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8347 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8349 add_com ("sb", class_breakpoint
, disable_command
, _("\
8350 Disable some breakpoints.\n\
8351 Arguments are breakpoint numbers with spaces in between.\n\
8352 To disable all breakpoints, give no argument.\n\
8353 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8355 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8356 Disable some breakpoints.\n\
8357 Arguments are breakpoint numbers with spaces in between.\n\
8358 To disable all breakpoints, give no argument.\n\
8359 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8360 This command may be abbreviated \"disable\"."),
8363 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8364 Delete some breakpoints or auto-display expressions.\n\
8365 Arguments are breakpoint numbers with spaces in between.\n\
8366 To delete all breakpoints, give no argument.\n\
8368 Also a prefix command for deletion of other GDB objects.\n\
8369 The \"unset\" command is also an alias for \"delete\"."),
8370 &deletelist
, "delete ", 1, &cmdlist
);
8371 add_com_alias ("d", "delete", class_breakpoint
, 1);
8372 add_com_alias ("del", "delete", class_breakpoint
, 1);
8374 add_com ("db", class_breakpoint
, delete_command
, _("\
8375 Delete some breakpoints.\n\
8376 Arguments are breakpoint numbers with spaces in between.\n\
8377 To delete all breakpoints, give no argument.\n"));
8379 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8380 Delete some breakpoints or auto-display expressions.\n\
8381 Arguments are breakpoint numbers with spaces in between.\n\
8382 To delete all breakpoints, give no argument.\n\
8383 This command may be abbreviated \"delete\"."),
8386 add_com ("clear", class_breakpoint
, clear_command
, _("\
8387 Clear breakpoint at specified line or function.\n\
8388 Argument may be line number, function name, or \"*\" and an address.\n\
8389 If line number is specified, all breakpoints in that line are cleared.\n\
8390 If function is specified, breakpoints at beginning of function are cleared.\n\
8391 If an address is specified, breakpoints at that address are cleared.\n\
8393 With no argument, clears all breakpoints in the line that the selected frame\n\
8396 See also the \"delete\" command which clears breakpoints by number."));
8398 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8399 Set breakpoint at specified line or function.\n"
8400 BREAK_ARGS_HELP ("break")));
8401 set_cmd_completer (c
, location_completer
);
8403 add_com_alias ("b", "break", class_run
, 1);
8404 add_com_alias ("br", "break", class_run
, 1);
8405 add_com_alias ("bre", "break", class_run
, 1);
8406 add_com_alias ("brea", "break", class_run
, 1);
8410 add_com_alias ("ba", "break", class_breakpoint
, 1);
8411 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8416 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8417 Break in function/address or break at a line in the current file."),
8418 &stoplist
, "stop ", 1, &cmdlist
);
8419 add_cmd ("in", class_breakpoint
, stopin_command
,
8420 _("Break in function or address."), &stoplist
);
8421 add_cmd ("at", class_breakpoint
, stopat_command
,
8422 _("Break at a line in the current file."), &stoplist
);
8423 add_com ("status", class_info
, breakpoints_info
, _("\
8424 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8425 The \"Type\" column indicates one of:\n\
8426 \tbreakpoint - normal breakpoint\n\
8427 \twatchpoint - watchpoint\n\
8428 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8429 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8430 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8431 address and file/line number respectively.\n\
8433 Convenience variable \"$_\" and default examine address for \"x\"\n\
8434 are set to the address of the last breakpoint listed unless the command\n\
8435 is prefixed with \"server \".\n\n\
8436 Convenience variable \"$bpnum\" contains the number of the last\n\
8440 add_info ("breakpoints", breakpoints_info
, _("\
8441 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8442 The \"Type\" column indicates one of:\n\
8443 \tbreakpoint - normal breakpoint\n\
8444 \twatchpoint - watchpoint\n\
8445 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8446 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8447 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8448 address and file/line number respectively.\n\
8450 Convenience variable \"$_\" and default examine address for \"x\"\n\
8451 are set to the address of the last breakpoint listed unless the command\n\
8452 is prefixed with \"server \".\n\n\
8453 Convenience variable \"$bpnum\" contains the number of the last\n\
8457 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8458 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8459 The \"Type\" column indicates one of:\n\
8460 \tbreakpoint - normal breakpoint\n\
8461 \twatchpoint - watchpoint\n\
8462 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8463 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8464 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8465 address and file/line number respectively.\n\
8467 Convenience variable \"$_\" and default examine address for \"x\"\n\
8468 are set to the address of the last breakpoint listed unless the command\n\
8469 is prefixed with \"server \".\n\n\
8470 Convenience variable \"$bpnum\" contains the number of the last\n\
8473 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8474 Status of all breakpoints, or breakpoint number NUMBER.\n\
8475 The \"Type\" column indicates one of:\n\
8476 \tbreakpoint - normal breakpoint\n\
8477 \twatchpoint - watchpoint\n\
8478 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8479 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8480 \tuntil - internal breakpoint used by the \"until\" command\n\
8481 \tfinish - internal breakpoint used by the \"finish\" command\n\
8482 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8483 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8484 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8485 address and file/line number respectively.\n\
8487 Convenience variable \"$_\" and default examine address for \"x\"\n\
8488 are set to the address of the last breakpoint listed unless the command\n\
8489 is prefixed with \"server \".\n\n\
8490 Convenience variable \"$bpnum\" contains the number of the last\n\
8492 &maintenanceinfolist
);
8494 add_com ("catch", class_breakpoint
, catch_command
, _("\
8495 Set catchpoints to catch events.\n\
8496 Raised signals may be caught:\n\
8497 \tcatch signal - all signals\n\
8498 \tcatch signal <signame> - a particular signal\n\
8499 Raised exceptions may be caught:\n\
8500 \tcatch throw - all exceptions, when thrown\n\
8501 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8502 \tcatch catch - all exceptions, when caught\n\
8503 \tcatch catch <exceptname> - a particular exception, when caught\n\
8504 Thread or process events may be caught:\n\
8505 \tcatch thread_start - any threads, just after creation\n\
8506 \tcatch thread_exit - any threads, just before expiration\n\
8507 \tcatch thread_join - any threads, just after joins\n\
8508 Process events may be caught:\n\
8509 \tcatch start - any processes, just after creation\n\
8510 \tcatch exit - any processes, just before expiration\n\
8511 \tcatch fork - calls to fork()\n\
8512 \tcatch vfork - calls to vfork()\n\
8513 \tcatch exec - calls to exec()\n\
8514 Dynamically-linked library events may be caught:\n\
8515 \tcatch load - loads of any library\n\
8516 \tcatch load <libname> - loads of a particular library\n\
8517 \tcatch unload - unloads of any library\n\
8518 \tcatch unload <libname> - unloads of a particular library\n\
8519 The act of your program's execution stopping may also be caught:\n\
8521 C++ exceptions may be caught:\n\
8522 \tcatch throw - all exceptions, when thrown\n\
8523 \tcatch catch - all exceptions, when caught\n\
8524 Ada exceptions may be caught:\n\
8525 \tcatch exception - all exceptions, when raised\n\
8526 \tcatch exception <name> - a particular exception, when raised\n\
8527 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8528 \tcatch assert - all failed assertions, when raised\n\
8530 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8531 after a fork or vfork is caught.\n\n\
8532 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8534 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8535 Set temporary catchpoints to catch events.\n\
8536 Args like \"catch\" command.\n\
8537 Like \"catch\" except the catchpoint is only temporary,\n\
8538 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8539 by using \"enable delete\" on the catchpoint number."));
8541 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8542 Set a watchpoint for an expression.\n\
8543 A watchpoint stops execution of your program whenever the value of\n\
8544 an expression changes."));
8545 set_cmd_completer (c
, expression_completer
);
8547 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8548 Set a read watchpoint for an expression.\n\
8549 A watchpoint stops execution of your program whenever the value of\n\
8550 an expression is read."));
8551 set_cmd_completer (c
, expression_completer
);
8553 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8554 Set a watchpoint for an expression.\n\
8555 A watchpoint stops execution of your program whenever the value of\n\
8556 an expression is either read or written."));
8557 set_cmd_completer (c
, expression_completer
);
8559 add_info ("watchpoints", breakpoints_info
,
8560 _("Synonym for ``info breakpoints''."));
8563 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8564 respond to changes - contrary to the description. */
8565 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8566 &can_use_hw_watchpoints
, _("\
8567 Set debugger's willingness to use watchpoint hardware."), _("\
8568 Show debugger's willingness to use watchpoint hardware."), _("\
8569 If zero, gdb will not use hardware for new watchpoints, even if\n\
8570 such is available. (However, any hardware watchpoints that were\n\
8571 created before setting this to nonzero, will continue to use watchpoint\n\
8574 show_can_use_hw_watchpoints
,
8575 &setlist
, &showlist
);
8577 can_use_hw_watchpoints
= 1;
8579 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8580 Breakpoint specific settings\n\
8581 Configure various breakpoint-specific variables such as\n\
8582 pending breakpoint behavior"),
8583 &breakpoint_set_cmdlist
, "set breakpoint ",
8584 0/*allow-unknown*/, &setlist
);
8585 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8586 Breakpoint specific settings\n\
8587 Configure various breakpoint-specific variables such as\n\
8588 pending breakpoint behavior"),
8589 &breakpoint_show_cmdlist
, "show breakpoint ",
8590 0/*allow-unknown*/, &showlist
);
8592 add_setshow_auto_boolean_cmd ("pending", no_class
,
8593 &pending_break_support
, _("\
8594 Set debugger's behavior regarding pending breakpoints."), _("\
8595 Show debugger's behavior regarding pending breakpoints."), _("\
8596 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8597 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8598 an error. If auto, an unrecognized breakpoint location results in a\n\
8599 user-query to see if a pending breakpoint should be created."),
8601 show_pending_break_support
,
8602 &breakpoint_set_cmdlist
,
8603 &breakpoint_show_cmdlist
);
8605 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8607 add_setshow_boolean_cmd ("auto-hw", no_class
,
8608 &automatic_hardware_breakpoints
, _("\
8609 Set automatic usage of hardware breakpoints."), _("\
8610 Show automatic usage of hardware breakpoints."), _("\
8611 If set, the debugger will automatically use hardware breakpoints for\n\
8612 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8613 a warning will be emitted for such breakpoints."),
8615 show_automatic_hardware_breakpoints
,
8616 &breakpoint_set_cmdlist
,
8617 &breakpoint_show_cmdlist
);
8619 add_setshow_boolean_cmd ("always-inserted", class_support
,
8620 &always_inserted_mode
, _("\
8621 Set mode for inserting breakpoints."), _("\
8622 Show mode for inserting breakpoints."), _("\
8623 When this mode is off (which is the default), breakpoints are inserted in\n\
8624 inferior when it is resumed, and removed when execution stops. When this\n\
8625 mode is on, breakpoints are inserted immediately and removed only when\n\
8626 the user deletes the breakpoint."),
8628 &show_always_inserted_mode
,
8629 &breakpoint_set_cmdlist
,
8630 &breakpoint_show_cmdlist
);
8632 automatic_hardware_breakpoints
= 1;