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"
61 #include "mi/mi-common.h"
63 /* Arguments to pass as context to some catch command handlers. */
64 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
65 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
67 /* Prototypes for local functions. */
69 static void enable_delete_command (char *, int);
71 static void enable_delete_breakpoint (struct breakpoint
*);
73 static void enable_once_command (char *, int);
75 static void enable_once_breakpoint (struct breakpoint
*);
77 static void disable_command (char *, int);
79 static void enable_command (char *, int);
81 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
83 static void ignore_command (char *, int);
85 static int breakpoint_re_set_one (void *);
87 static void clear_command (char *, int);
89 static void catch_command (char *, int);
91 static void watch_command (char *, int);
93 static int can_use_hardware_watchpoint (struct value
*);
95 static void break_command_1 (char *, int, int);
97 static void mention (struct breakpoint
*);
99 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
101 static void check_duplicates (struct breakpoint
*);
103 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
105 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
108 static void describe_other_breakpoints (CORE_ADDR
, struct obj_section
*, int);
110 static void breakpoints_info (char *, int);
112 static void breakpoint_1 (int, int);
114 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
116 static int breakpoint_cond_eval (void *);
118 static void cleanup_executing_breakpoints (void *);
120 static void commands_command (char *, int);
122 static void condition_command (char *, int);
124 static int get_number_trailer (char **, int);
126 void set_breakpoint_count (int);
135 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
137 static enum print_stop_action
print_it_typical (bpstat
);
139 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 static int watchpoint_check (void *);
143 static void maintenance_info_breakpoints (char *, int);
145 static void create_overlay_event_breakpoint (char *);
147 static int hw_breakpoint_used_count (void);
149 static int hw_watchpoint_used_count (enum bptype
, int *);
151 static void hbreak_command (char *, int);
153 static void thbreak_command (char *, int);
155 static void watch_command_1 (char *, int, int);
157 static void rwatch_command (char *, int);
159 static void awatch_command (char *, int);
161 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
163 static void stop_command (char *arg
, int from_tty
);
165 static void stopin_command (char *arg
, int from_tty
);
167 static void stopat_command (char *arg
, int from_tty
);
169 static char *ep_parse_optional_if_clause (char **arg
);
171 static char *ep_parse_optional_filename (char **arg
);
173 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
174 char *arg
, int tempflag
, int from_tty
);
176 static void tcatch_command (char *arg
, int from_tty
);
178 static void ep_skip_leading_whitespace (char **s
);
180 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
182 static void free_bp_location (struct bp_location
*loc
);
184 static struct bp_location
*
185 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
187 static void update_global_location_list (int);
189 static void update_global_location_list_nothrow (int);
191 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
193 static void insert_breakpoint_locations (void);
196 bpdisp_text (enum bpdisp disp
)
198 /* NOTE: the following values are a part of MI protocol and represent
199 values of 'disp' field returned when inferior stops at a breakpoint. */
200 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
201 return bpdisps
[(int) disp
];
204 /* Prototypes for exported functions. */
205 /* If FALSE, gdb will not use hardware support for watchpoints, even
206 if such is available. */
207 static int can_use_hw_watchpoints
;
210 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
211 struct cmd_list_element
*c
,
214 fprintf_filtered (file
, _("\
215 Debugger's willingness to use watchpoint hardware is %s.\n"),
219 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
220 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
221 for unrecognized breakpoint locations.
222 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
223 static enum auto_boolean pending_break_support
;
225 show_pending_break_support (struct ui_file
*file
, int from_tty
,
226 struct cmd_list_element
*c
,
229 fprintf_filtered (file
, _("\
230 Debugger's behavior regarding pending breakpoints is %s.\n"),
234 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
235 set with "break" but falling in read-only memory.
236 If 0, gdb will warn about such breakpoints, but won't automatically
237 use hardware breakpoints. */
238 static int automatic_hardware_breakpoints
;
240 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
241 struct cmd_list_element
*c
,
244 fprintf_filtered (file
, _("\
245 Automatic usage of hardware breakpoints is %s.\n"),
249 /* If on, gdb will keep breakpoints inserted even as inferior is
250 stopped, and immediately insert any new breakpoints. If off, gdb
251 will insert breakpoints into inferior only when resuming it, and
252 will remove breakpoints upon stop. If auto, GDB will behave as ON
253 if in non-stop mode, and as OFF if all-stop mode.*/
255 static const char always_inserted_auto
[] = "auto";
256 static const char always_inserted_on
[] = "on";
257 static const char always_inserted_off
[] = "off";
258 static const char *always_inserted_enums
[] = {
259 always_inserted_auto
,
264 static const char *always_inserted_mode
= always_inserted_auto
;
266 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
267 struct cmd_list_element
*c
, const char *value
)
269 if (always_inserted_mode
== always_inserted_auto
)
270 fprintf_filtered (file
, _("\
271 Always inserted breakpoint mode is %s (currently %s).\n"),
273 breakpoints_always_inserted_mode () ? "on" : "off");
275 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
279 breakpoints_always_inserted_mode (void)
281 return (always_inserted_mode
== always_inserted_on
282 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
285 void _initialize_breakpoint (void);
287 /* Are we executing breakpoint commands? */
288 static int executing_breakpoint_commands
;
290 /* Are overlay event breakpoints enabled? */
291 static int overlay_events_enabled
;
293 /* Walk the following statement or block through all breakpoints.
294 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
297 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
299 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
300 for (B = breakpoint_chain; \
301 B ? (TMP=B->next, 1): 0; \
304 /* Similar iterators for the low-level breakpoints. */
306 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
308 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
309 for (B = bp_location_chain; \
310 B ? (TMP=B->global_next, 1): 0; \
313 /* Chains of all breakpoints defined. */
315 struct breakpoint
*breakpoint_chain
;
317 struct bp_location
*bp_location_chain
;
319 /* The locations that no longer correspond to any breakpoint,
320 unlinked from bp_location_chain, but for which a hit
321 may still be reported by a target. */
322 VEC(bp_location_p
) *moribund_locations
= NULL
;
324 /* Number of last breakpoint made. */
326 int breakpoint_count
;
328 /* Return whether a breakpoint is an active enabled breakpoint. */
330 breakpoint_enabled (struct breakpoint
*b
)
332 return (b
->enable_state
== bp_enabled
);
335 /* Set breakpoint count to NUM. */
338 set_breakpoint_count (int num
)
340 breakpoint_count
= num
;
341 set_internalvar (lookup_internalvar ("bpnum"),
342 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
345 /* Used in run_command to zero the hit count when a new run starts. */
348 clear_breakpoint_hit_counts (void)
350 struct breakpoint
*b
;
356 /* Default address, symtab and line to put a breakpoint at
357 for "break" command with no arg.
358 if default_breakpoint_valid is zero, the other three are
359 not valid, and "break" with no arg is an error.
361 This set by print_stack_frame, which calls set_default_breakpoint. */
363 int default_breakpoint_valid
;
364 CORE_ADDR default_breakpoint_address
;
365 struct symtab
*default_breakpoint_symtab
;
366 int default_breakpoint_line
;
368 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
369 Advance *PP after the string and any trailing whitespace.
371 Currently the string can either be a number or "$" followed by the name
372 of a convenience variable. Making it an expression wouldn't work well
373 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
375 If the string is a NULL pointer, that denotes the last breakpoint.
377 TRAILER is a character which can be found after the number; most
378 commonly this is `-'. If you don't want a trailer, use \0. */
380 get_number_trailer (char **pp
, int trailer
)
382 int retval
= 0; /* default */
386 /* Empty line means refer to the last breakpoint. */
387 return breakpoint_count
;
390 /* Make a copy of the name, so we can null-terminate it
391 to pass to lookup_internalvar(). */
396 while (isalnum (*p
) || *p
== '_')
398 varname
= (char *) alloca (p
- start
+ 1);
399 strncpy (varname
, start
, p
- start
);
400 varname
[p
- start
] = '\0';
401 val
= value_of_internalvar (lookup_internalvar (varname
));
402 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
403 retval
= (int) value_as_long (val
);
406 printf_filtered (_("Convenience variable must have integer value.\n"));
414 while (*p
>= '0' && *p
<= '9')
417 /* There is no number here. (e.g. "cond a == b"). */
419 /* Skip non-numeric token */
420 while (*p
&& !isspace((int) *p
))
422 /* Return zero, which caller must interpret as error. */
428 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
430 /* Trailing junk: return 0 and let caller print error msg. */
431 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
442 /* Like get_number_trailer, but don't allow a trailer. */
444 get_number (char **pp
)
446 return get_number_trailer (pp
, '\0');
449 /* Parse a number or a range.
450 * A number will be of the form handled by get_number.
451 * A range will be of the form <number1> - <number2>, and
452 * will represent all the integers between number1 and number2,
455 * While processing a range, this fuction is called iteratively;
456 * At each call it will return the next value in the range.
458 * At the beginning of parsing a range, the char pointer PP will
459 * be advanced past <number1> and left pointing at the '-' token.
460 * Subsequent calls will not advance the pointer until the range
461 * is completed. The call that completes the range will advance
462 * pointer PP past <number2>.
466 get_number_or_range (char **pp
)
468 static int last_retval
, end_value
;
469 static char *end_ptr
;
470 static int in_range
= 0;
474 /* Default case: pp is pointing either to a solo number,
475 or to the first number of a range. */
476 last_retval
= get_number_trailer (pp
, '-');
481 /* This is the start of a range (<number1> - <number2>).
482 Skip the '-', parse and remember the second number,
483 and also remember the end of the final token. */
487 while (isspace ((int) *end_ptr
))
488 end_ptr
++; /* skip white space */
489 end_value
= get_number (temp
);
490 if (end_value
< last_retval
)
492 error (_("inverted range"));
494 else if (end_value
== last_retval
)
496 /* degenerate range (number1 == number2). Advance the
497 token pointer so that the range will be treated as a
506 error (_("negative value"));
509 /* pp points to the '-' that betokens a range. All
510 number-parsing has already been done. Return the next
511 integer value (one greater than the saved previous value).
512 Do not advance the token pointer 'pp' until the end of range
515 if (++last_retval
== end_value
)
517 /* End of range reached; advance token pointer. */
527 /* condition N EXP -- set break condition of breakpoint N to EXP. */
530 condition_command (char *arg
, int from_tty
)
532 struct breakpoint
*b
;
537 error_no_arg (_("breakpoint number"));
540 bnum
= get_number (&p
);
542 error (_("Bad breakpoint argument: '%s'"), arg
);
545 if (b
->number
== bnum
)
547 struct bp_location
*loc
= b
->loc
;
548 for (; loc
; loc
= loc
->next
)
556 if (b
->cond_string
!= NULL
)
557 xfree (b
->cond_string
);
561 b
->cond_string
= NULL
;
563 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
568 /* I don't know if it matters whether this is the string the user
569 typed in or the decompiled expression. */
570 b
->cond_string
= savestring (arg
, strlen (arg
));
571 b
->condition_not_parsed
= 0;
572 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
576 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
578 error (_("Junk at end of expression"));
581 breakpoints_changed ();
582 observer_notify_breakpoint_modified (b
->number
);
586 error (_("No breakpoint number %d."), bnum
);
590 commands_command (char *arg
, int from_tty
)
592 struct breakpoint
*b
;
595 struct command_line
*l
;
597 /* If we allowed this, we would have problems with when to
598 free the storage, if we change the commands currently
601 if (executing_breakpoint_commands
)
602 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
605 bnum
= get_number (&p
);
608 error (_("Unexpected extra arguments following breakpoint number."));
611 if (b
->number
== bnum
)
613 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
615 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
616 l
= read_command_lines (tmpbuf
, from_tty
, 1);
617 do_cleanups (cleanups
);
618 free_command_lines (&b
->commands
);
620 breakpoints_changed ();
621 observer_notify_breakpoint_modified (b
->number
);
624 error (_("No breakpoint number %d."), bnum
);
627 /* Like commands_command, but instead of reading the commands from
628 input stream, takes them from an already parsed command structure.
630 This is used by cli-script.c to DTRT with breakpoint commands
631 that are part of if and while bodies. */
632 enum command_control_type
633 commands_from_control_command (char *arg
, struct command_line
*cmd
)
635 struct breakpoint
*b
;
639 /* If we allowed this, we would have problems with when to
640 free the storage, if we change the commands currently
643 if (executing_breakpoint_commands
)
644 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
646 /* An empty string for the breakpoint number means the last
647 breakpoint, but get_number expects a NULL pointer. */
652 bnum
= get_number (&p
);
655 error (_("Unexpected extra arguments following breakpoint number."));
658 if (b
->number
== bnum
)
660 free_command_lines (&b
->commands
);
661 if (cmd
->body_count
!= 1)
662 error (_("Invalid \"commands\" block structure."));
663 /* We need to copy the commands because if/while will free the
664 list after it finishes execution. */
665 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
666 breakpoints_changed ();
667 observer_notify_breakpoint_modified (b
->number
);
668 return simple_control
;
670 error (_("No breakpoint number %d."), bnum
);
673 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
674 by replacing any memory breakpoints with their shadowed contents. */
677 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
679 struct bp_location
*b
;
680 CORE_ADDR bp_addr
= 0;
686 if (b
->owner
->type
== bp_none
)
687 warning (_("reading through apparently deleted breakpoint #%d?"),
690 if (b
->loc_type
!= bp_loc_software_breakpoint
)
694 /* Addresses and length of the part of the breakpoint that
696 bp_addr
= b
->target_info
.placed_address
;
697 bp_size
= b
->target_info
.shadow_len
;
699 /* bp isn't valid, or doesn't shadow memory. */
702 if (bp_addr
+ bp_size
<= memaddr
)
703 /* The breakpoint is entirely before the chunk of memory we
707 if (bp_addr
>= memaddr
+ len
)
708 /* The breakpoint is entirely after the chunk of memory we are
712 /* Offset within shadow_contents. */
713 if (bp_addr
< memaddr
)
715 /* Only copy the second part of the breakpoint. */
716 bp_size
-= memaddr
- bp_addr
;
717 bptoffset
= memaddr
- bp_addr
;
721 if (bp_addr
+ bp_size
> memaddr
+ len
)
723 /* Only copy the first part of the breakpoint. */
724 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
727 memcpy (buf
+ bp_addr
- memaddr
,
728 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
733 /* A wrapper function for inserting catchpoints. */
735 insert_catchpoint (struct ui_out
*uo
, void *args
)
737 struct breakpoint
*b
= (struct breakpoint
*) args
;
740 gdb_assert (b
->type
== bp_catchpoint
);
741 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
747 is_hardware_watchpoint (struct breakpoint
*bpt
)
749 return (bpt
->type
== bp_hardware_watchpoint
750 || bpt
->type
== bp_read_watchpoint
751 || bpt
->type
== bp_access_watchpoint
);
754 /* Find the current value of a watchpoint on EXP. Return the value in
755 *VALP and *RESULTP and the chain of intermediate and final values
756 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
759 If an error occurs while evaluating the expression, *RESULTP will
760 be set to NULL. *RESULTP may be a lazy value, if the result could
761 not be read from memory. It is used to determine whether a value
762 is user-specified (we should watch the whole value) or intermediate
763 (we should watch only the bit used to locate the final value).
765 If the final value, or any intermediate value, could not be read
766 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
767 set to any referenced values. *VALP will never be a lazy value.
768 This is the value which we store in struct breakpoint.
770 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
771 value chain. The caller must free the values individually. If
772 VAL_CHAIN is NULL, all generated values will be left on the value
776 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
777 struct value
**resultp
, struct value
**val_chain
)
779 struct value
*mark
, *new_mark
, *result
;
787 /* Evaluate the expression. */
788 mark
= value_mark ();
790 gdb_evaluate_expression (exp
, &result
);
791 new_mark
= value_mark ();
792 if (mark
== new_mark
)
797 /* Make sure it's not lazy, so that after the target stops again we
798 have a non-lazy previous value to compare with. */
800 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
805 /* Return the chain of intermediate values. We use this to
806 decide which addresses to watch. */
807 *val_chain
= new_mark
;
808 value_release_to_mark (mark
);
812 /* Assuming that B is a hardware watchpoint:
813 - Reparse watchpoint expression, is REPARSE is non-zero
814 - Evaluate expression and store the result in B->val
815 - Update the list of values that must be watched in B->loc.
817 If the watchpoint is disabled, do nothing. If this is
818 local watchpoint that is out of scope, delete it. */
820 update_watchpoint (struct breakpoint
*b
, int reparse
)
822 int within_current_scope
;
823 struct frame_id saved_frame_id
;
824 struct bp_location
*loc
;
827 /* We don't free locations. They are stored in
828 bp_location_chain and update_global_locations will
829 eventually delete them and remove breakpoints if
833 if (b
->disposition
== disp_del_at_next_stop
)
836 /* Save the current frame's ID so we can restore it after
837 evaluating the watchpoint expression on its own frame. */
838 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
839 took a frame parameter, so that we didn't have to change the
841 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
843 /* Determine if the watchpoint is within scope. */
844 if (b
->exp_valid_block
== NULL
)
845 within_current_scope
= 1;
848 struct frame_info
*fi
;
849 fi
= frame_find_by_id (b
->watchpoint_frame
);
850 within_current_scope
= (fi
!= NULL
);
851 if (within_current_scope
)
855 if (within_current_scope
&& reparse
)
864 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
865 /* If the meaning of expression itself changed, the old value is
866 no longer relevant. We don't want to report a watchpoint hit
867 to the user when the old value and the new value may actually
868 be completely different objects. */
874 /* If we failed to parse the expression, for example because
875 it refers to a global variable in a not-yet-loaded shared library,
876 don't try to insert watchpoint. We don't automatically delete
877 such watchpoint, though, since failure to parse expression
878 is different from out-of-scope watchpoint. */
879 if (within_current_scope
&& b
->exp
)
881 struct value
*val_chain
, *v
, *result
, *next
;
883 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
885 /* Avoid setting b->val if it's already set. The meaning of
886 b->val is 'the last value' user saw, and we should update
887 it only if we reported that last value to user. As it
888 happens, the code that reports it updates b->val directly. */
895 /* Look at each value on the value chain. */
896 for (v
= val_chain
; v
; v
= next
)
898 /* If it's a memory location, and GDB actually needed
899 its contents to evaluate the expression, then we
900 must watch it. If the first value returned is
901 still lazy, that means an error occurred reading it;
902 watch it anyway in case it becomes readable. */
903 if (VALUE_LVAL (v
) == lval_memory
904 && (v
== val_chain
|| ! value_lazy (v
)))
906 struct type
*vtype
= check_typedef (value_type (v
));
908 /* We only watch structs and arrays if user asked
909 for it explicitly, never if they just happen to
910 appear in the middle of some value chain. */
912 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
913 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
917 struct bp_location
*loc
, **tmp
;
919 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
920 len
= TYPE_LENGTH (value_type (v
));
922 if (b
->type
== bp_read_watchpoint
)
924 else if (b
->type
== bp_access_watchpoint
)
927 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
928 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
933 loc
->watchpoint_type
= type
;
937 next
= value_next (v
);
942 /* We just regenerated the list of breakpoint locations.
943 The new location does not have its condition field set to anything
944 and therefore, we must always reparse the cond_string, independently
945 of the value of the reparse flag. */
946 if (b
->cond_string
!= NULL
)
948 char *s
= b
->cond_string
;
949 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
952 else if (!within_current_scope
)
954 printf_filtered (_("\
955 Hardware watchpoint %d deleted because the program has left the block \n\
956 in which its expression is valid.\n"),
958 if (b
->related_breakpoint
)
959 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
960 b
->disposition
= disp_del_at_next_stop
;
963 /* Restore the selected frame. */
964 select_frame (frame_find_by_id (saved_frame_id
));
968 /* Returns 1 iff breakpoint location should be
969 inserted in the inferior. */
971 should_be_inserted (struct bp_location
*bpt
)
973 if (!breakpoint_enabled (bpt
->owner
))
976 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
979 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
985 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
986 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
987 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
989 NOTE drow/2003-09-09: This routine could be broken down to an object-style
990 method for each breakpoint or catchpoint type. */
992 insert_bp_location (struct bp_location
*bpt
,
993 struct ui_file
*tmp_error_stream
,
994 int *disabled_breaks
, int *process_warning
,
995 int *hw_breakpoint_error
)
999 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1002 /* Initialize the target-specific information. */
1003 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1004 bpt
->target_info
.placed_address
= bpt
->address
;
1006 if (bpt
->loc_type
== bp_loc_software_breakpoint
1007 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1009 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1011 /* If the explicitly specified breakpoint type
1012 is not hardware breakpoint, check the memory map to see
1013 if the breakpoint address is in read only memory or not.
1014 Two important cases are:
1015 - location type is not hardware breakpoint, memory
1016 is readonly. We change the type of the location to
1017 hardware breakpoint.
1018 - location type is hardware breakpoint, memory is read-write.
1019 This means we've previously made the location hardware one, but
1020 then the memory map changed, so we undo.
1022 When breakpoints are removed, remove_breakpoints will
1023 use location types we've just set here, the only possible
1024 problem is that memory map has changed during running program,
1025 but it's not going to work anyway with current gdb. */
1026 struct mem_region
*mr
1027 = lookup_mem_region (bpt
->target_info
.placed_address
);
1031 if (automatic_hardware_breakpoints
)
1034 enum bp_loc_type new_type
;
1036 if (mr
->attrib
.mode
!= MEM_RW
)
1037 new_type
= bp_loc_hardware_breakpoint
;
1039 new_type
= bp_loc_software_breakpoint
;
1041 if (new_type
!= bpt
->loc_type
)
1043 static int said
= 0;
1044 bpt
->loc_type
= new_type
;
1047 fprintf_filtered (gdb_stdout
, _("\
1048 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1053 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1054 && mr
->attrib
.mode
!= MEM_RW
)
1055 warning (_("cannot set software breakpoint at readonly address %s"),
1056 paddr (bpt
->address
));
1060 /* First check to see if we have to handle an overlay. */
1061 if (overlay_debugging
== ovly_off
1062 || bpt
->section
== NULL
1063 || !(section_is_overlay (bpt
->section
)))
1065 /* No overlay handling: just set the breakpoint. */
1067 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1068 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1070 val
= target_insert_breakpoint (&bpt
->target_info
);
1074 /* This breakpoint is in an overlay section.
1075 Shall we set a breakpoint at the LMA? */
1076 if (!overlay_events_enabled
)
1078 /* Yes -- overlay event support is not active,
1079 so we must try to set a breakpoint at the LMA.
1080 This will not work for a hardware breakpoint. */
1081 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1082 warning (_("hardware breakpoint %d not supported in overlay!"),
1083 bpt
->owner
->number
);
1086 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1088 /* Set a software (trap) breakpoint at the LMA. */
1089 bpt
->overlay_target_info
= bpt
->target_info
;
1090 bpt
->overlay_target_info
.placed_address
= addr
;
1091 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1093 fprintf_unfiltered (tmp_error_stream
,
1094 "Overlay breakpoint %d failed: in ROM?",
1095 bpt
->owner
->number
);
1098 /* Shall we set a breakpoint at the VMA? */
1099 if (section_is_mapped (bpt
->section
))
1101 /* Yes. This overlay section is mapped into memory. */
1102 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1103 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1105 val
= target_insert_breakpoint (&bpt
->target_info
);
1109 /* No. This breakpoint will not be inserted.
1110 No error, but do not mark the bp as 'inserted'. */
1117 /* Can't set the breakpoint. */
1118 if (solib_address (bpt
->address
))
1120 /* See also: disable_breakpoints_in_shlibs. */
1122 bpt
->shlib_disabled
= 1;
1123 if (!*disabled_breaks
)
1125 fprintf_unfiltered (tmp_error_stream
,
1126 "Cannot insert breakpoint %d.\n",
1127 bpt
->owner
->number
);
1128 fprintf_unfiltered (tmp_error_stream
,
1129 "Temporarily disabling shared library breakpoints:\n");
1131 *disabled_breaks
= 1;
1132 fprintf_unfiltered (tmp_error_stream
,
1133 "breakpoint #%d\n", bpt
->owner
->number
);
1137 #ifdef ONE_PROCESS_WRITETEXT
1138 *process_warning
= 1;
1140 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1142 *hw_breakpoint_error
= 1;
1143 fprintf_unfiltered (tmp_error_stream
,
1144 "Cannot insert hardware breakpoint %d.\n",
1145 bpt
->owner
->number
);
1149 fprintf_unfiltered (tmp_error_stream
,
1150 "Cannot insert breakpoint %d.\n",
1151 bpt
->owner
->number
);
1152 fprintf_filtered (tmp_error_stream
,
1153 "Error accessing memory address ");
1154 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1155 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1156 safe_strerror (val
));
1167 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1168 /* NOTE drow/2003-09-08: This state only exists for removing
1169 watchpoints. It's not clear that it's necessary... */
1170 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1172 val
= target_insert_watchpoint (bpt
->address
,
1174 bpt
->watchpoint_type
);
1175 bpt
->inserted
= (val
!= -1);
1178 else if (bpt
->owner
->type
== bp_catchpoint
)
1180 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1181 bpt
->owner
, RETURN_MASK_ERROR
);
1182 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1183 bpt
->owner
->number
);
1185 bpt
->owner
->enable_state
= bp_disabled
;
1189 /* We've already printed an error message if there was a problem
1190 inserting this catchpoint, and we've disabled the catchpoint,
1191 so just return success. */
1198 /* Make sure all breakpoints are inserted in inferior.
1199 Throws exception on any error.
1200 A breakpoint that is already inserted won't be inserted
1201 again, so calling this function twice is safe. */
1203 insert_breakpoints (void)
1205 struct breakpoint
*bpt
;
1207 ALL_BREAKPOINTS (bpt
)
1208 if (is_hardware_watchpoint (bpt
))
1209 update_watchpoint (bpt
, 0 /* don't reparse. */);
1211 update_global_location_list (1);
1213 if (!breakpoints_always_inserted_mode ()
1214 && (target_has_execution
1215 || (gdbarch_has_global_solist (target_gdbarch
)
1216 && target_supports_multi_process ())))
1217 /* update_global_location_list does not insert breakpoints
1218 when always_inserted_mode is not enabled. Explicitly
1220 insert_breakpoint_locations ();
1223 /* insert_breakpoints is used when starting or continuing the program.
1224 remove_breakpoints is used when the program stops.
1225 Both return zero if successful,
1226 or an `errno' value if could not write the inferior. */
1229 insert_breakpoint_locations (void)
1231 struct breakpoint
*bpt
;
1232 struct bp_location
*b
, *temp
;
1235 int disabled_breaks
= 0;
1236 int hw_breakpoint_error
= 0;
1237 int process_warning
= 0;
1239 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1240 make_cleanup_ui_file_delete (tmp_error_stream
);
1242 /* Explicitly mark the warning -- this will only be printed if
1243 there was an error. */
1244 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1246 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1248 if (!should_be_inserted (b
) || b
->inserted
)
1251 /* There is no point inserting thread-specific breakpoints if the
1252 thread no longer exists. */
1253 if (b
->owner
->thread
!= -1
1254 && !valid_thread_id (b
->owner
->thread
))
1257 val
= insert_bp_location (b
, tmp_error_stream
,
1258 &disabled_breaks
, &process_warning
,
1259 &hw_breakpoint_error
);
1264 /* If we failed to insert all locations of a watchpoint,
1265 remove them, as half-inserted watchpoint is of limited use. */
1266 ALL_BREAKPOINTS (bpt
)
1268 int some_failed
= 0;
1269 struct bp_location
*loc
;
1271 if (!is_hardware_watchpoint (bpt
))
1274 if (!breakpoint_enabled (bpt
))
1277 if (bpt
->disposition
== disp_del_at_next_stop
)
1280 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1288 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1290 remove_breakpoint (loc
, mark_uninserted
);
1292 hw_breakpoint_error
= 1;
1293 fprintf_unfiltered (tmp_error_stream
,
1294 "Could not insert hardware watchpoint %d.\n",
1302 /* If a hardware breakpoint or watchpoint was inserted, add a
1303 message about possibly exhausted resources. */
1304 if (hw_breakpoint_error
)
1306 fprintf_unfiltered (tmp_error_stream
,
1307 "Could not insert hardware breakpoints:\n\
1308 You may have requested too many hardware breakpoints/watchpoints.\n");
1310 #ifdef ONE_PROCESS_WRITETEXT
1311 if (process_warning
)
1312 fprintf_unfiltered (tmp_error_stream
,
1313 "The same program may be running in another process.");
1315 target_terminal_ours_for_output ();
1316 error_stream (tmp_error_stream
);
1321 remove_breakpoints (void)
1323 struct bp_location
*b
;
1326 ALL_BP_LOCATIONS (b
)
1330 val
= remove_breakpoint (b
, mark_uninserted
);
1339 remove_hw_watchpoints (void)
1341 struct bp_location
*b
;
1344 ALL_BP_LOCATIONS (b
)
1346 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1348 val
= remove_breakpoint (b
, mark_uninserted
);
1357 reattach_breakpoints (int pid
)
1359 struct bp_location
*b
;
1361 struct cleanup
*old_chain
= save_inferior_ptid ();
1362 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1363 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1365 make_cleanup_ui_file_delete (tmp_error_stream
);
1367 inferior_ptid
= pid_to_ptid (pid
);
1368 ALL_BP_LOCATIONS (b
)
1373 val
= insert_bp_location (b
, tmp_error_stream
,
1374 &dummy1
, &dummy2
, &dummy3
);
1377 do_cleanups (old_chain
);
1382 do_cleanups (old_chain
);
1387 update_breakpoints_after_exec (void)
1389 struct breakpoint
*b
;
1390 struct breakpoint
*temp
;
1391 struct bp_location
*bploc
;
1393 /* We're about to delete breakpoints from GDB's lists. If the
1394 INSERTED flag is true, GDB will try to lift the breakpoints by
1395 writing the breakpoints' "shadow contents" back into memory. The
1396 "shadow contents" are NOT valid after an exec, so GDB should not
1397 do that. Instead, the target is responsible from marking
1398 breakpoints out as soon as it detects an exec. We don't do that
1399 here instead, because there may be other attempts to delete
1400 breakpoints after detecting an exec and before reaching here. */
1401 ALL_BP_LOCATIONS (bploc
)
1402 gdb_assert (!bploc
->inserted
);
1404 ALL_BREAKPOINTS_SAFE (b
, temp
)
1406 /* Solib breakpoints must be explicitly reset after an exec(). */
1407 if (b
->type
== bp_shlib_event
)
1409 delete_breakpoint (b
);
1413 /* Thread event breakpoints must be set anew after an exec(),
1414 as must overlay event breakpoints. */
1415 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1417 delete_breakpoint (b
);
1421 /* Step-resume breakpoints are meaningless after an exec(). */
1422 if (b
->type
== bp_step_resume
)
1424 delete_breakpoint (b
);
1428 /* Longjmp and longjmp-resume breakpoints are also meaningless
1430 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1432 delete_breakpoint (b
);
1436 if (b
->type
== bp_catchpoint
)
1438 /* For now, none of the bp_catchpoint breakpoints need to
1439 do anything at this point. In the future, if some of
1440 the catchpoints need to something, we will need to add
1441 a new method, and call this method from here. */
1445 /* bp_finish is a special case. The only way we ought to be able
1446 to see one of these when an exec() has happened, is if the user
1447 caught a vfork, and then said "finish". Ordinarily a finish just
1448 carries them to the call-site of the current callee, by setting
1449 a temporary bp there and resuming. But in this case, the finish
1450 will carry them entirely through the vfork & exec.
1452 We don't want to allow a bp_finish to remain inserted now. But
1453 we can't safely delete it, 'cause finish_command has a handle to
1454 the bp on a bpstat, and will later want to delete it. There's a
1455 chance (and I've seen it happen) that if we delete the bp_finish
1456 here, that its storage will get reused by the time finish_command
1457 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1458 We really must allow finish_command to delete a bp_finish.
1460 In the absense of a general solution for the "how do we know
1461 it's safe to delete something others may have handles to?"
1462 problem, what we'll do here is just uninsert the bp_finish, and
1463 let finish_command delete it.
1465 (We know the bp_finish is "doomed" in the sense that it's
1466 momentary, and will be deleted as soon as finish_command sees
1467 the inferior stopped. So it doesn't matter that the bp's
1468 address is probably bogus in the new a.out, unlike e.g., the
1469 solib breakpoints.) */
1471 if (b
->type
== bp_finish
)
1476 /* Without a symbolic address, we have little hope of the
1477 pre-exec() address meaning the same thing in the post-exec()
1479 if (b
->addr_string
== NULL
)
1481 delete_breakpoint (b
);
1485 /* FIXME what about longjmp breakpoints? Re-create them here? */
1486 create_overlay_event_breakpoint ("_ovly_debug_event");
1490 detach_breakpoints (int pid
)
1492 struct bp_location
*b
;
1494 struct cleanup
*old_chain
= save_inferior_ptid ();
1496 if (pid
== PIDGET (inferior_ptid
))
1497 error (_("Cannot detach breakpoints of inferior_ptid"));
1499 /* Set inferior_ptid; remove_breakpoint uses this global. */
1500 inferior_ptid
= pid_to_ptid (pid
);
1501 ALL_BP_LOCATIONS (b
)
1505 val
= remove_breakpoint (b
, mark_inserted
);
1508 do_cleanups (old_chain
);
1513 do_cleanups (old_chain
);
1518 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1522 if (b
->owner
->enable_state
== bp_permanent
)
1523 /* Permanent breakpoints cannot be inserted or removed. */
1526 /* The type of none suggests that owner is actually deleted.
1527 This should not ever happen. */
1528 gdb_assert (b
->owner
->type
!= bp_none
);
1530 if (b
->loc_type
== bp_loc_software_breakpoint
1531 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1533 /* "Normal" instruction breakpoint: either the standard
1534 trap-instruction bp (bp_breakpoint), or a
1535 bp_hardware_breakpoint. */
1537 /* First check to see if we have to handle an overlay. */
1538 if (overlay_debugging
== ovly_off
1539 || b
->section
== NULL
1540 || !(section_is_overlay (b
->section
)))
1542 /* No overlay handling: just remove the breakpoint. */
1544 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1545 val
= target_remove_hw_breakpoint (&b
->target_info
);
1547 val
= target_remove_breakpoint (&b
->target_info
);
1551 /* This breakpoint is in an overlay section.
1552 Did we set a breakpoint at the LMA? */
1553 if (!overlay_events_enabled
)
1555 /* Yes -- overlay event support is not active, so we
1556 should have set a breakpoint at the LMA. Remove it.
1558 /* Ignore any failures: if the LMA is in ROM, we will
1559 have already warned when we failed to insert it. */
1560 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1561 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1563 target_remove_breakpoint (&b
->overlay_target_info
);
1565 /* Did we set a breakpoint at the VMA?
1566 If so, we will have marked the breakpoint 'inserted'. */
1569 /* Yes -- remove it. Previously we did not bother to
1570 remove the breakpoint if the section had been
1571 unmapped, but let's not rely on that being safe. We
1572 don't know what the overlay manager might do. */
1573 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1574 val
= target_remove_hw_breakpoint (&b
->target_info
);
1576 /* However, we should remove *software* breakpoints only
1577 if the section is still mapped, or else we overwrite
1578 wrong code with the saved shadow contents. */
1579 else if (section_is_mapped (b
->section
))
1580 val
= target_remove_breakpoint (&b
->target_info
);
1586 /* No -- not inserted, so no need to remove. No error. */
1591 /* In some cases, we might not be able to remove a breakpoint
1592 in a shared library that has already been removed, but we
1593 have not yet processed the shlib unload event. */
1594 if (val
&& solib_address (b
->address
))
1599 b
->inserted
= (is
== mark_inserted
);
1601 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1606 b
->inserted
= (is
== mark_inserted
);
1607 val
= target_remove_watchpoint (b
->address
, b
->length
,
1608 b
->watchpoint_type
);
1610 /* Failure to remove any of the hardware watchpoints comes here. */
1611 if ((is
== mark_uninserted
) && (b
->inserted
))
1612 warning (_("Could not remove hardware watchpoint %d."),
1615 else if (b
->owner
->type
== bp_catchpoint
1616 && breakpoint_enabled (b
->owner
)
1619 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1621 val
= b
->owner
->ops
->remove (b
->owner
);
1624 b
->inserted
= (is
== mark_inserted
);
1630 /* Clear the "inserted" flag in all breakpoints. */
1633 mark_breakpoints_out (void)
1635 struct bp_location
*bpt
;
1637 ALL_BP_LOCATIONS (bpt
)
1641 /* Clear the "inserted" flag in all breakpoints and delete any
1642 breakpoints which should go away between runs of the program.
1644 Plus other such housekeeping that has to be done for breakpoints
1647 Note: this function gets called at the end of a run (by
1648 generic_mourn_inferior) and when a run begins (by
1649 init_wait_for_inferior). */
1654 breakpoint_init_inferior (enum inf_context context
)
1656 struct breakpoint
*b
, *temp
;
1657 struct bp_location
*bpt
;
1660 /* If breakpoint locations are shared across processes, then there's
1662 if (gdbarch_has_global_solist (target_gdbarch
))
1665 ALL_BP_LOCATIONS (bpt
)
1666 if (bpt
->owner
->enable_state
!= bp_permanent
)
1669 ALL_BREAKPOINTS_SAFE (b
, temp
)
1674 case bp_watchpoint_scope
:
1676 /* If the call dummy breakpoint is at the entry point it will
1677 cause problems when the inferior is rerun, so we better
1680 Also get rid of scope breakpoints. */
1681 delete_breakpoint (b
);
1685 case bp_hardware_watchpoint
:
1686 case bp_read_watchpoint
:
1687 case bp_access_watchpoint
:
1689 /* Likewise for watchpoints on local expressions. */
1690 if (b
->exp_valid_block
!= NULL
)
1691 delete_breakpoint (b
);
1692 else if (context
== inf_starting
)
1694 /* Reset val field to force reread of starting value
1695 in insert_breakpoints. */
1697 value_free (b
->val
);
1707 /* Get rid of the moribund locations. */
1708 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1709 free_bp_location (bpt
);
1710 VEC_free (bp_location_p
, moribund_locations
);
1713 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1714 exists at PC. It returns ordinary_breakpoint_here if it's an
1715 ordinary breakpoint, or permanent_breakpoint_here if it's a
1716 permanent breakpoint.
1717 - When continuing from a location with an ordinary breakpoint, we
1718 actually single step once before calling insert_breakpoints.
1719 - When continuing from a localion with a permanent breakpoint, we
1720 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1721 the target, to advance the PC past the breakpoint. */
1723 enum breakpoint_here
1724 breakpoint_here_p (CORE_ADDR pc
)
1726 const struct bp_location
*bpt
;
1727 int any_breakpoint_here
= 0;
1729 ALL_BP_LOCATIONS (bpt
)
1731 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1732 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1735 if ((breakpoint_enabled (bpt
->owner
)
1736 || bpt
->owner
->enable_state
== bp_permanent
)
1737 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1739 if (overlay_debugging
1740 && section_is_overlay (bpt
->section
)
1741 && !section_is_mapped (bpt
->section
))
1742 continue; /* unmapped overlay -- can't be a match */
1743 else if (bpt
->owner
->enable_state
== bp_permanent
)
1744 return permanent_breakpoint_here
;
1746 any_breakpoint_here
= 1;
1750 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1753 /* Return true if there's a moribund breakpoint at PC. */
1756 moribund_breakpoint_here_p (CORE_ADDR pc
)
1758 struct bp_location
*loc
;
1761 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1762 if (loc
->address
== pc
)
1768 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1769 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1770 This does not check for single-step breakpoints, which are
1771 inserted and removed using direct target manipulation. */
1774 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1776 const struct bp_location
*bpt
;
1778 ALL_BP_LOCATIONS (bpt
)
1780 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1781 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1785 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1787 if (overlay_debugging
1788 && section_is_overlay (bpt
->section
)
1789 && !section_is_mapped (bpt
->section
))
1790 continue; /* unmapped overlay -- can't be a match */
1798 /* Returns non-zero iff there's either regular breakpoint
1799 or a single step breakpoint inserted at PC. */
1802 breakpoint_inserted_here_p (CORE_ADDR pc
)
1804 if (regular_breakpoint_inserted_here_p (pc
))
1807 if (single_step_breakpoint_inserted_here_p (pc
))
1813 /* This function returns non-zero iff there is a software breakpoint
1817 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1819 const struct bp_location
*bpt
;
1820 int any_breakpoint_here
= 0;
1822 ALL_BP_LOCATIONS (bpt
)
1824 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1828 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1830 if (overlay_debugging
1831 && section_is_overlay (bpt
->section
)
1832 && !section_is_mapped (bpt
->section
))
1833 continue; /* unmapped overlay -- can't be a match */
1839 /* Also check for software single-step breakpoints. */
1840 if (single_step_breakpoint_inserted_here_p (pc
))
1846 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1847 PC is valid for process/thread PTID. */
1850 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1852 const struct bp_location
*bpt
;
1855 thread
= pid_to_thread_id (ptid
);
1857 ALL_BP_LOCATIONS (bpt
)
1859 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1860 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1863 if ((breakpoint_enabled (bpt
->owner
)
1864 || bpt
->owner
->enable_state
== bp_permanent
)
1865 && bpt
->address
== pc
1866 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1868 if (overlay_debugging
1869 && section_is_overlay (bpt
->section
)
1870 && !section_is_mapped (bpt
->section
))
1871 continue; /* unmapped overlay -- can't be a match */
1881 /* bpstat stuff. External routines' interfaces are documented
1885 ep_is_catchpoint (struct breakpoint
*ep
)
1887 return (ep
->type
== bp_catchpoint
);
1891 bpstat_free (bpstat bs
)
1893 if (bs
->old_val
!= NULL
)
1894 value_free (bs
->old_val
);
1895 free_command_lines (&bs
->commands
);
1899 /* Clear a bpstat so that it says we are not at any breakpoint.
1900 Also free any storage that is part of a bpstat. */
1903 bpstat_clear (bpstat
*bsp
)
1920 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1921 is part of the bpstat is copied as well. */
1924 bpstat_copy (bpstat bs
)
1928 bpstat retval
= NULL
;
1933 for (; bs
!= NULL
; bs
= bs
->next
)
1935 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1936 memcpy (tmp
, bs
, sizeof (*tmp
));
1937 if (bs
->commands
!= NULL
)
1938 tmp
->commands
= copy_command_lines (bs
->commands
);
1939 if (bs
->old_val
!= NULL
)
1941 tmp
->old_val
= value_copy (bs
->old_val
);
1942 release_value (tmp
->old_val
);
1946 /* This is the first thing in the chain. */
1956 /* Find the bpstat associated with this breakpoint */
1959 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1964 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1966 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1972 /* Find a step_resume breakpoint associated with this bpstat.
1973 (If there are multiple step_resume bp's on the list, this function
1974 will arbitrarily pick one.)
1976 It is an error to use this function if BPSTAT doesn't contain a
1977 step_resume breakpoint.
1979 See wait_for_inferior's use of this function. */
1981 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1985 gdb_assert (bsp
!= NULL
);
1987 current_thread
= pid_to_thread_id (inferior_ptid
);
1989 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1991 if ((bsp
->breakpoint_at
!= NULL
) &&
1992 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
1993 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
1994 bsp
->breakpoint_at
->owner
->thread
== -1))
1995 return bsp
->breakpoint_at
->owner
;
1998 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2002 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2003 at. *BSP upon return is a bpstat which points to the remaining
2004 breakpoints stopped at (but which is not guaranteed to be good for
2005 anything but further calls to bpstat_num).
2006 Return 0 if passed a bpstat which does not indicate any breakpoints.
2007 Return -1 if stopped at a breakpoint that has been deleted since
2009 Return 1 otherwise. */
2012 bpstat_num (bpstat
*bsp
, int *num
)
2014 struct breakpoint
*b
;
2017 return 0; /* No more breakpoint values */
2019 /* We assume we'll never have several bpstats that
2020 correspond to a single breakpoint -- otherwise,
2021 this function might return the same number more
2022 than once and this will look ugly. */
2023 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2024 *bsp
= (*bsp
)->next
;
2026 return -1; /* breakpoint that's been deleted since */
2028 *num
= b
->number
; /* We have its number */
2032 /* Modify BS so that the actions will not be performed. */
2035 bpstat_clear_actions (bpstat bs
)
2037 for (; bs
!= NULL
; bs
= bs
->next
)
2039 free_command_lines (&bs
->commands
);
2040 if (bs
->old_val
!= NULL
)
2042 value_free (bs
->old_val
);
2048 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2050 cleanup_executing_breakpoints (void *ignore
)
2052 executing_breakpoint_commands
= 0;
2055 /* Execute all the commands associated with all the breakpoints at this
2056 location. Any of these commands could cause the process to proceed
2057 beyond this point, etc. We look out for such changes by checking
2058 the global "breakpoint_proceeded" after each command.
2060 Returns true if a breakpoint command resumed the inferior. In that
2061 case, it is the caller's responsibility to recall it again with the
2062 bpstat of the current thread. */
2065 bpstat_do_actions_1 (bpstat
*bsp
)
2068 struct cleanup
*old_chain
;
2071 /* Avoid endless recursion if a `source' command is contained
2073 if (executing_breakpoint_commands
)
2076 executing_breakpoint_commands
= 1;
2077 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2079 /* This pointer will iterate over the list of bpstat's. */
2082 breakpoint_proceeded
= 0;
2083 for (; bs
!= NULL
; bs
= bs
->next
)
2085 struct command_line
*cmd
;
2086 struct cleanup
*this_cmd_tree_chain
;
2088 /* Take ownership of the BSP's command tree, if it has one.
2090 The command tree could legitimately contain commands like
2091 'step' and 'next', which call clear_proceed_status, which
2092 frees stop_bpstat's command tree. To make sure this doesn't
2093 free the tree we're executing out from under us, we need to
2094 take ownership of the tree ourselves. Since a given bpstat's
2095 commands are only executed once, we don't need to copy it; we
2096 can clear the pointer in the bpstat, and make sure we free
2097 the tree when we're done. */
2100 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2104 execute_control_command (cmd
);
2106 if (breakpoint_proceeded
)
2112 /* We can free this command tree now. */
2113 do_cleanups (this_cmd_tree_chain
);
2115 if (breakpoint_proceeded
)
2117 if (target_can_async_p ())
2118 /* If we are in async mode, then the target might be still
2119 running, not stopped at any breakpoint, so nothing for
2120 us to do here -- just return to the event loop. */
2123 /* In sync mode, when execute_control_command returns
2124 we're already standing on the next breakpoint.
2125 Breakpoint commands for that stop were not run, since
2126 execute_command does not run breakpoint commands --
2127 only command_line_handler does, but that one is not
2128 involved in execution of breakpoint commands. So, we
2129 can now execute breakpoint commands. It should be
2130 noted that making execute_command do bpstat actions is
2131 not an option -- in this case we'll have recursive
2132 invocation of bpstat for each breakpoint with a
2133 command, and can easily blow up GDB stack. Instead, we
2134 return true, which will trigger the caller to recall us
2135 with the new stop_bpstat. */
2140 do_cleanups (old_chain
);
2145 bpstat_do_actions (void)
2147 /* Do any commands attached to breakpoint we are stopped at. */
2148 while (!ptid_equal (inferior_ptid
, null_ptid
)
2149 && target_has_execution
2150 && !is_exited (inferior_ptid
)
2151 && !is_executing (inferior_ptid
))
2152 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2153 and only return when it is stopped at the next breakpoint, we
2154 keep doing breakpoint actions until it returns false to
2155 indicate the inferior was not resumed. */
2156 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2160 /* Print out the (old or new) value associated with a watchpoint. */
2163 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2166 fprintf_unfiltered (stream
, _("<unreadable>"));
2169 struct value_print_options opts
;
2170 get_user_print_options (&opts
);
2171 value_print (val
, stream
, &opts
);
2175 /* This is the normal print function for a bpstat. In the future,
2176 much of this logic could (should?) be moved to bpstat_stop_status,
2177 by having it set different print_it values.
2179 Current scheme: When we stop, bpstat_print() is called. It loops
2180 through the bpstat list of things causing this stop, calling the
2181 print_bp_stop_message function on each one. The behavior of the
2182 print_bp_stop_message function depends on the print_it field of
2183 bpstat. If such field so indicates, call this function here.
2185 Return values from this routine (ultimately used by bpstat_print()
2186 and normal_stop() to decide what to do):
2187 PRINT_NOTHING: Means we already printed all we needed to print,
2188 don't print anything else.
2189 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2190 that something to be followed by a location.
2191 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2192 that something to be followed by a location.
2193 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2196 static enum print_stop_action
2197 print_it_typical (bpstat bs
)
2199 struct cleanup
*old_chain
, *ui_out_chain
;
2200 struct breakpoint
*b
;
2201 const struct bp_location
*bl
;
2202 struct ui_stream
*stb
;
2204 stb
= ui_out_stream_new (uiout
);
2205 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2206 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2207 which has since been deleted. */
2208 if (bs
->breakpoint_at
== NULL
)
2209 return PRINT_UNKNOWN
;
2210 bl
= bs
->breakpoint_at
;
2216 case bp_hardware_breakpoint
:
2217 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2218 if (bl
->address
!= bl
->requested_address
)
2219 breakpoint_adjustment_warning (bl
->requested_address
,
2222 annotate_breakpoint (b
->number
);
2224 ui_out_text (uiout
, "\nTemporary breakpoint ");
2226 ui_out_text (uiout
, "\nBreakpoint ");
2227 if (ui_out_is_mi_like_p (uiout
))
2229 ui_out_field_string (uiout
, "reason",
2230 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2231 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2233 ui_out_field_int (uiout
, "bkptno", b
->number
);
2234 ui_out_text (uiout
, ", ");
2235 return PRINT_SRC_AND_LOC
;
2238 case bp_shlib_event
:
2239 /* Did we stop because the user set the stop_on_solib_events
2240 variable? (If so, we report this as a generic, "Stopped due
2241 to shlib event" message.) */
2242 printf_filtered (_("Stopped due to shared library event\n"));
2243 return PRINT_NOTHING
;
2246 case bp_thread_event
:
2247 /* Not sure how we will get here.
2248 GDB should not stop for these breakpoints. */
2249 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2250 return PRINT_NOTHING
;
2253 case bp_overlay_event
:
2254 /* By analogy with the thread event, GDB should not stop for these. */
2255 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2256 return PRINT_NOTHING
;
2260 case bp_hardware_watchpoint
:
2261 annotate_watchpoint (b
->number
);
2262 if (ui_out_is_mi_like_p (uiout
))
2265 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2267 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2268 ui_out_text (uiout
, "\nOld value = ");
2269 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2270 ui_out_field_stream (uiout
, "old", stb
);
2271 ui_out_text (uiout
, "\nNew value = ");
2272 watchpoint_value_print (b
->val
, stb
->stream
);
2273 ui_out_field_stream (uiout
, "new", stb
);
2274 do_cleanups (ui_out_chain
);
2275 ui_out_text (uiout
, "\n");
2276 /* More than one watchpoint may have been triggered. */
2277 return PRINT_UNKNOWN
;
2280 case bp_read_watchpoint
:
2281 if (ui_out_is_mi_like_p (uiout
))
2284 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2286 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2287 ui_out_text (uiout
, "\nValue = ");
2288 watchpoint_value_print (b
->val
, stb
->stream
);
2289 ui_out_field_stream (uiout
, "value", stb
);
2290 do_cleanups (ui_out_chain
);
2291 ui_out_text (uiout
, "\n");
2292 return PRINT_UNKNOWN
;
2295 case bp_access_watchpoint
:
2296 if (bs
->old_val
!= NULL
)
2298 annotate_watchpoint (b
->number
);
2299 if (ui_out_is_mi_like_p (uiout
))
2302 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2304 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2305 ui_out_text (uiout
, "\nOld value = ");
2306 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2307 ui_out_field_stream (uiout
, "old", stb
);
2308 ui_out_text (uiout
, "\nNew value = ");
2313 if (ui_out_is_mi_like_p (uiout
))
2316 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2317 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2318 ui_out_text (uiout
, "\nValue = ");
2320 watchpoint_value_print (b
->val
, stb
->stream
);
2321 ui_out_field_stream (uiout
, "new", stb
);
2322 do_cleanups (ui_out_chain
);
2323 ui_out_text (uiout
, "\n");
2324 return PRINT_UNKNOWN
;
2327 /* Fall through, we don't deal with these types of breakpoints
2331 if (ui_out_is_mi_like_p (uiout
))
2334 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2335 return PRINT_UNKNOWN
;
2339 if (ui_out_is_mi_like_p (uiout
))
2342 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2343 return PRINT_UNKNOWN
;
2348 case bp_longjmp_resume
:
2349 case bp_step_resume
:
2350 case bp_watchpoint_scope
:
2353 return PRINT_UNKNOWN
;
2357 /* Generic routine for printing messages indicating why we
2358 stopped. The behavior of this function depends on the value
2359 'print_it' in the bpstat structure. Under some circumstances we
2360 may decide not to print anything here and delegate the task to
2363 static enum print_stop_action
2364 print_bp_stop_message (bpstat bs
)
2366 switch (bs
->print_it
)
2369 /* Nothing should be printed for this bpstat entry. */
2370 return PRINT_UNKNOWN
;
2374 /* We still want to print the frame, but we already printed the
2375 relevant messages. */
2376 return PRINT_SRC_AND_LOC
;
2379 case print_it_normal
:
2381 const struct bp_location
*bl
= bs
->breakpoint_at
;
2382 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2384 /* Normal case. Call the breakpoint's print_it method, or
2385 print_it_typical. */
2386 /* FIXME: how breakpoint can ever be NULL here? */
2387 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2388 return b
->ops
->print_it (b
);
2390 return print_it_typical (bs
);
2395 internal_error (__FILE__
, __LINE__
,
2396 _("print_bp_stop_message: unrecognized enum value"));
2401 /* Print a message indicating what happened. This is called from
2402 normal_stop(). The input to this routine is the head of the bpstat
2403 list - a list of the eventpoints that caused this stop. This
2404 routine calls the generic print routine for printing a message
2405 about reasons for stopping. This will print (for example) the
2406 "Breakpoint n," part of the output. The return value of this
2409 PRINT_UNKNOWN: Means we printed nothing
2410 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2411 code to print the location. An example is
2412 "Breakpoint 1, " which should be followed by
2414 PRINT_SRC_ONLY: Means we printed something, but there is no need
2415 to also print the location part of the message.
2416 An example is the catch/throw messages, which
2417 don't require a location appended to the end.
2418 PRINT_NOTHING: We have done some printing and we don't need any
2419 further info to be printed.*/
2421 enum print_stop_action
2422 bpstat_print (bpstat bs
)
2426 /* Maybe another breakpoint in the chain caused us to stop.
2427 (Currently all watchpoints go on the bpstat whether hit or not.
2428 That probably could (should) be changed, provided care is taken
2429 with respect to bpstat_explains_signal). */
2430 for (; bs
; bs
= bs
->next
)
2432 val
= print_bp_stop_message (bs
);
2433 if (val
== PRINT_SRC_ONLY
2434 || val
== PRINT_SRC_AND_LOC
2435 || val
== PRINT_NOTHING
)
2439 /* We reached the end of the chain, or we got a null BS to start
2440 with and nothing was printed. */
2441 return PRINT_UNKNOWN
;
2444 /* Evaluate the expression EXP and return 1 if value is zero.
2445 This is used inside a catch_errors to evaluate the breakpoint condition.
2446 The argument is a "struct expression *" that has been cast to char * to
2447 make it pass through catch_errors. */
2450 breakpoint_cond_eval (void *exp
)
2452 struct value
*mark
= value_mark ();
2453 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2454 value_free_to_mark (mark
);
2458 /* Allocate a new bpstat and chain it to the current one. */
2461 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2465 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2467 bs
->breakpoint_at
= bl
;
2468 /* If the condition is false, etc., don't do the commands. */
2469 bs
->commands
= NULL
;
2471 bs
->print_it
= print_it_normal
;
2475 /* The target has stopped with waitstatus WS. Check if any hardware
2476 watchpoints have triggered, according to the target. */
2479 watchpoints_triggered (struct target_waitstatus
*ws
)
2481 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2483 struct breakpoint
*b
;
2485 if (!stopped_by_watchpoint
)
2487 /* We were not stopped by a watchpoint. Mark all watchpoints
2488 as not triggered. */
2490 if (b
->type
== bp_hardware_watchpoint
2491 || b
->type
== bp_read_watchpoint
2492 || b
->type
== bp_access_watchpoint
)
2493 b
->watchpoint_triggered
= watch_triggered_no
;
2498 if (!target_stopped_data_address (¤t_target
, &addr
))
2500 /* We were stopped by a watchpoint, but we don't know where.
2501 Mark all watchpoints as unknown. */
2503 if (b
->type
== bp_hardware_watchpoint
2504 || b
->type
== bp_read_watchpoint
2505 || b
->type
== bp_access_watchpoint
)
2506 b
->watchpoint_triggered
= watch_triggered_unknown
;
2508 return stopped_by_watchpoint
;
2511 /* The target could report the data address. Mark watchpoints
2512 affected by this data address as triggered, and all others as not
2516 if (b
->type
== bp_hardware_watchpoint
2517 || b
->type
== bp_read_watchpoint
2518 || b
->type
== bp_access_watchpoint
)
2520 struct bp_location
*loc
;
2523 b
->watchpoint_triggered
= watch_triggered_no
;
2524 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2525 /* Exact match not required. Within range is
2527 if (target_watchpoint_addr_within_range (¤t_target
,
2531 b
->watchpoint_triggered
= watch_triggered_yes
;
2539 /* Possible return values for watchpoint_check (this can't be an enum
2540 because of check_errors). */
2541 /* The watchpoint has been deleted. */
2542 #define WP_DELETED 1
2543 /* The value has changed. */
2544 #define WP_VALUE_CHANGED 2
2545 /* The value has not changed. */
2546 #define WP_VALUE_NOT_CHANGED 3
2548 #define BP_TEMPFLAG 1
2549 #define BP_HARDWAREFLAG 2
2551 /* Check watchpoint condition. */
2554 watchpoint_check (void *p
)
2556 bpstat bs
= (bpstat
) p
;
2557 struct breakpoint
*b
;
2558 struct frame_info
*fr
;
2559 int within_current_scope
;
2561 b
= bs
->breakpoint_at
->owner
;
2563 if (b
->exp_valid_block
== NULL
)
2564 within_current_scope
= 1;
2567 /* There is no current frame at this moment. If we're going to have
2568 any chance of handling watchpoints on local variables, we'll need
2569 the frame chain (so we can determine if we're in scope). */
2570 reinit_frame_cache ();
2571 fr
= frame_find_by_id (b
->watchpoint_frame
);
2572 within_current_scope
= (fr
!= NULL
);
2574 /* If we've gotten confused in the unwinder, we might have
2575 returned a frame that can't describe this variable. */
2576 if (within_current_scope
2577 && (block_linkage_function (b
->exp_valid_block
)
2578 != get_frame_function (fr
)))
2579 within_current_scope
= 0;
2581 /* in_function_epilogue_p() returns a non-zero value if we're still
2582 in the function but the stack frame has already been invalidated.
2583 Since we can't rely on the values of local variables after the
2584 stack has been destroyed, we are treating the watchpoint in that
2585 state as `not changed' without further checking.
2587 vinschen/2003-09-04: The former implementation left out the case
2588 that the watchpoint frame couldn't be found by frame_find_by_id()
2589 because the current PC is currently in an epilogue. Calling
2590 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2591 if ((!within_current_scope
|| fr
== get_current_frame ())
2592 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2593 return WP_VALUE_NOT_CHANGED
;
2594 if (fr
&& within_current_scope
)
2595 /* If we end up stopping, the current frame will get selected
2596 in normal_stop. So this call to select_frame won't affect
2601 if (within_current_scope
)
2603 /* We use value_{,free_to_}mark because it could be a
2604 *long* time before we return to the command level and
2605 call free_all_values. We can't call free_all_values because
2606 we might be in the middle of evaluating a function call. */
2608 struct value
*mark
= value_mark ();
2609 struct value
*new_val
;
2611 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2612 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2613 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2615 if (new_val
!= NULL
)
2617 release_value (new_val
);
2618 value_free_to_mark (mark
);
2620 bs
->old_val
= b
->val
;
2623 /* We will stop here */
2624 return WP_VALUE_CHANGED
;
2628 /* Nothing changed, don't do anything. */
2629 value_free_to_mark (mark
);
2630 /* We won't stop here */
2631 return WP_VALUE_NOT_CHANGED
;
2636 /* This seems like the only logical thing to do because
2637 if we temporarily ignored the watchpoint, then when
2638 we reenter the block in which it is valid it contains
2639 garbage (in the case of a function, it may have two
2640 garbage values, one before and one after the prologue).
2641 So we can't even detect the first assignment to it and
2642 watch after that (since the garbage may or may not equal
2643 the first value assigned). */
2644 /* We print all the stop information in print_it_typical(), but
2645 in this case, by the time we call print_it_typical() this bp
2646 will be deleted already. So we have no choice but print the
2647 information here. */
2648 if (ui_out_is_mi_like_p (uiout
))
2650 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2651 ui_out_text (uiout
, "\nWatchpoint ");
2652 ui_out_field_int (uiout
, "wpnum", b
->number
);
2653 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2654 which its expression is valid.\n");
2656 if (b
->related_breakpoint
)
2657 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2658 b
->disposition
= disp_del_at_next_stop
;
2664 /* Return true if it looks like target has stopped due to hitting
2665 breakpoint location BL. This function does not check if we
2666 should stop, only if BL explains the stop. */
2668 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2670 struct breakpoint
*b
= bl
->owner
;
2672 if (b
->type
!= bp_watchpoint
2673 && b
->type
!= bp_hardware_watchpoint
2674 && b
->type
!= bp_read_watchpoint
2675 && b
->type
!= bp_access_watchpoint
2676 && b
->type
!= bp_hardware_breakpoint
2677 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2679 if (bl
->address
!= bp_addr
) /* address doesn't match */
2681 if (overlay_debugging
/* unmapped overlay section */
2682 && section_is_overlay (bl
->section
)
2683 && !section_is_mapped (bl
->section
))
2687 /* Continuable hardware watchpoints are treated as non-existent if the
2688 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2689 some data address). Otherwise gdb won't stop on a break instruction
2690 in the code (not from a breakpoint) when a hardware watchpoint has
2691 been defined. Also skip watchpoints which we know did not trigger
2692 (did not match the data address). */
2694 if ((b
->type
== bp_hardware_watchpoint
2695 || b
->type
== bp_read_watchpoint
2696 || b
->type
== bp_access_watchpoint
)
2697 && b
->watchpoint_triggered
== watch_triggered_no
)
2700 if (b
->type
== bp_hardware_breakpoint
)
2702 if (bl
->address
!= bp_addr
)
2704 if (overlay_debugging
/* unmapped overlay section */
2705 && section_is_overlay (bl
->section
)
2706 && !section_is_mapped (bl
->section
))
2710 if (b
->type
== bp_catchpoint
)
2712 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2713 if (!b
->ops
->breakpoint_hit (b
))
2720 /* If BS refers to a watchpoint, determine if the watched values
2721 has actually changed, and we should stop. If not, set BS->stop
2724 bpstat_check_watchpoint (bpstat bs
)
2726 const struct bp_location
*bl
= bs
->breakpoint_at
;
2727 struct breakpoint
*b
= bl
->owner
;
2729 if (b
->type
== bp_watchpoint
2730 || b
->type
== bp_read_watchpoint
2731 || b
->type
== bp_access_watchpoint
2732 || b
->type
== bp_hardware_watchpoint
)
2736 int must_check_value
= 0;
2738 if (b
->type
== bp_watchpoint
)
2739 /* For a software watchpoint, we must always check the
2741 must_check_value
= 1;
2742 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2743 /* We have a hardware watchpoint (read, write, or access)
2744 and the target earlier reported an address watched by
2746 must_check_value
= 1;
2747 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2748 && b
->type
== bp_hardware_watchpoint
)
2749 /* We were stopped by a hardware watchpoint, but the target could
2750 not report the data address. We must check the watchpoint's
2751 value. Access and read watchpoints are out of luck; without
2752 a data address, we can't figure it out. */
2753 must_check_value
= 1;
2755 if (must_check_value
)
2757 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2759 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2760 int e
= catch_errors (watchpoint_check
, bs
, message
,
2762 do_cleanups (cleanups
);
2766 /* We've already printed what needs to be printed. */
2767 bs
->print_it
= print_it_done
;
2770 case WP_VALUE_CHANGED
:
2771 if (b
->type
== bp_read_watchpoint
)
2773 /* Don't stop: read watchpoints shouldn't fire if
2774 the value has changed. This is for targets
2775 which cannot set read-only watchpoints. */
2776 bs
->print_it
= print_it_noop
;
2780 case WP_VALUE_NOT_CHANGED
:
2781 if (b
->type
== bp_hardware_watchpoint
2782 || b
->type
== bp_watchpoint
)
2784 /* Don't stop: write watchpoints shouldn't fire if
2785 the value hasn't changed. */
2786 bs
->print_it
= print_it_noop
;
2794 /* Error from catch_errors. */
2795 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2796 if (b
->related_breakpoint
)
2797 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2798 b
->disposition
= disp_del_at_next_stop
;
2799 /* We've already printed what needs to be printed. */
2800 bs
->print_it
= print_it_done
;
2804 else /* must_check_value == 0 */
2806 /* This is a case where some watchpoint(s) triggered, but
2807 not at the address of this watchpoint, or else no
2808 watchpoint triggered after all. So don't print
2809 anything for this watchpoint. */
2810 bs
->print_it
= print_it_noop
;
2817 /* Check conditions (condition proper, frame, thread and ignore count)
2818 of breakpoint referred to by BS. If we should not stop for this
2819 breakpoint, set BS->stop to 0. */
2821 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2823 int thread_id
= pid_to_thread_id (ptid
);
2824 const struct bp_location
*bl
= bs
->breakpoint_at
;
2825 struct breakpoint
*b
= bl
->owner
;
2827 if (frame_id_p (b
->frame_id
)
2828 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2832 int value_is_zero
= 0;
2834 /* If this is a scope breakpoint, mark the associated
2835 watchpoint as triggered so that we will handle the
2836 out-of-scope event. We'll get to the watchpoint next
2838 if (b
->type
== bp_watchpoint_scope
)
2839 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2841 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2843 /* Need to select the frame, with all that implies
2844 so that the conditions will have the right context. */
2845 select_frame (get_current_frame ());
2847 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2848 "Error in testing breakpoint condition:\n",
2850 /* FIXME-someday, should give breakpoint # */
2853 if (bl
->cond
&& value_is_zero
)
2857 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2861 else if (b
->ignore_count
> 0)
2864 annotate_ignore_count_change ();
2866 /* Increase the hit count even though we don't
2874 /* Get a bpstat associated with having just stopped at address
2875 BP_ADDR in thread PTID.
2877 Determine whether we stopped at a breakpoint, etc, or whether we
2878 don't understand this stop. Result is a chain of bpstat's such that:
2880 if we don't understand the stop, the result is a null pointer.
2882 if we understand why we stopped, the result is not null.
2884 Each element of the chain refers to a particular breakpoint or
2885 watchpoint at which we have stopped. (We may have stopped for
2886 several reasons concurrently.)
2888 Each element of the chain has valid next, breakpoint_at,
2889 commands, FIXME??? fields. */
2892 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2894 struct breakpoint
*b
= NULL
;
2895 const struct bp_location
*bl
;
2896 struct bp_location
*loc
;
2897 /* Root of the chain of bpstat's */
2898 struct bpstats root_bs
[1];
2899 /* Pointer to the last thing in the chain currently. */
2900 bpstat bs
= root_bs
;
2902 int need_remove_insert
;
2904 ALL_BP_LOCATIONS (bl
)
2908 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2911 /* For hardware watchpoints, we look only at the first location.
2912 The watchpoint_check function will work on entire expression,
2913 not the individual locations. For read watchopints, the
2914 watchpoints_triggered function have checked all locations
2917 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2920 if (!bpstat_check_location (bl
, bp_addr
))
2923 /* Come here if it's a watchpoint, or if the break address matches */
2925 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2927 /* Assume we stop. Should we find watchpoint that is not actually
2928 triggered, or if condition of breakpoint is false, we'll reset
2933 bpstat_check_watchpoint (bs
);
2937 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2938 /* We do not stop for these. */
2941 bpstat_check_breakpoint_conditions (bs
, ptid
);
2947 /* We will stop here */
2948 if (b
->disposition
== disp_disable
)
2950 if (b
->enable_state
!= bp_permanent
)
2951 b
->enable_state
= bp_disabled
;
2952 update_global_location_list (0);
2956 bs
->commands
= b
->commands
;
2958 (strcmp ("silent", bs
->commands
->line
) == 0
2959 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2961 bs
->commands
= bs
->commands
->next
;
2964 bs
->commands
= copy_command_lines (bs
->commands
);
2967 /* Print nothing for this entry if we dont stop or if we dont print. */
2968 if (bs
->stop
== 0 || bs
->print
== 0)
2969 bs
->print_it
= print_it_noop
;
2972 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2974 if (loc
->address
== bp_addr
)
2976 bs
= bpstat_alloc (loc
, bs
);
2977 /* For hits of moribund locations, we should just proceed. */
2980 bs
->print_it
= print_it_noop
;
2984 bs
->next
= NULL
; /* Terminate the chain */
2985 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2987 /* If we aren't stopping, the value of some hardware watchpoint may
2988 not have changed, but the intermediate memory locations we are
2989 watching may have. Don't bother if we're stopping; this will get
2991 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2995 need_remove_insert
= 0;
2997 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2999 && bs
->breakpoint_at
->owner
3000 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3001 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3002 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3004 /* remove/insert can invalidate bs->breakpoint_at, if this
3005 location is no longer used by the watchpoint. Prevent
3006 further code from trying to use it. */
3007 bs
->breakpoint_at
= NULL
;
3008 need_remove_insert
= 1;
3011 if (need_remove_insert
)
3013 remove_breakpoints ();
3014 insert_breakpoints ();
3017 return root_bs
->next
;
3020 /* Tell what to do about this bpstat. */
3022 bpstat_what (bpstat bs
)
3024 /* Classify each bpstat as one of the following. */
3027 /* This bpstat element has no effect on the main_action. */
3030 /* There was a watchpoint, stop but don't print. */
3033 /* There was a watchpoint, stop and print. */
3036 /* There was a breakpoint but we're not stopping. */
3039 /* There was a breakpoint, stop but don't print. */
3042 /* There was a breakpoint, stop and print. */
3045 /* We hit the longjmp breakpoint. */
3048 /* We hit the longjmp_resume breakpoint. */
3051 /* We hit the step_resume breakpoint. */
3054 /* We hit the shared library event breakpoint. */
3057 /* This is just used to count how many enums there are. */
3061 /* Here is the table which drives this routine. So that we can
3062 format it pretty, we define some abbreviations for the
3063 enum bpstat_what codes. */
3064 #define kc BPSTAT_WHAT_KEEP_CHECKING
3065 #define ss BPSTAT_WHAT_STOP_SILENT
3066 #define sn BPSTAT_WHAT_STOP_NOISY
3067 #define sgl BPSTAT_WHAT_SINGLE
3068 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3069 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3070 #define sr BPSTAT_WHAT_STEP_RESUME
3071 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3073 /* "Can't happen." Might want to print an error message.
3074 abort() is not out of the question, but chances are GDB is just
3075 a bit confused, not unusable. */
3076 #define err BPSTAT_WHAT_STOP_NOISY
3078 /* Given an old action and a class, come up with a new action. */
3079 /* One interesting property of this table is that wp_silent is the same
3080 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3081 after stopping, the check for whether to step over a breakpoint
3082 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3083 reference to how we stopped. We retain separate wp_silent and
3084 bp_silent codes in case we want to change that someday.
3086 Another possibly interesting property of this table is that
3087 there's a partial ordering, priority-like, of the actions. Once
3088 you've decided that some action is appropriate, you'll never go
3089 back and decide something of a lower priority is better. The
3092 kc < clr sgl shl slr sn sr ss
3093 sgl < shl slr sn sr ss
3094 slr < err shl sn sr ss
3095 clr < err shl sn sr ss
3101 What I think this means is that we don't need a damned table
3102 here. If you just put the rows and columns in the right order,
3103 it'd look awfully regular. We could simply walk the bpstat list
3104 and choose the highest priority action we find, with a little
3105 logic to handle the 'err' cases. */
3107 /* step_resume entries: a step resume breakpoint overrides another
3108 breakpoint of signal handling (see comment in wait_for_inferior
3109 at where we set the step_resume breakpoint). */
3111 static const enum bpstat_what_main_action
3112 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3115 /* kc ss sn sgl slr clr sr shl
3118 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3120 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3122 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3124 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3126 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3128 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3130 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3132 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3134 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3136 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3149 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3150 struct bpstat_what retval
;
3152 retval
.call_dummy
= 0;
3153 for (; bs
!= NULL
; bs
= bs
->next
)
3155 enum class bs_class
= no_effect
;
3156 if (bs
->breakpoint_at
== NULL
)
3157 /* I suspect this can happen if it was a momentary breakpoint
3158 which has since been deleted. */
3160 if (bs
->breakpoint_at
->owner
== NULL
)
3161 bs_class
= bp_nostop
;
3163 switch (bs
->breakpoint_at
->owner
->type
)
3169 case bp_hardware_breakpoint
:
3175 bs_class
= bp_noisy
;
3177 bs_class
= bp_silent
;
3180 bs_class
= bp_nostop
;
3183 case bp_hardware_watchpoint
:
3184 case bp_read_watchpoint
:
3185 case bp_access_watchpoint
:
3189 bs_class
= wp_noisy
;
3191 bs_class
= wp_silent
;
3194 /* There was a watchpoint, but we're not stopping.
3195 This requires no further action. */
3196 bs_class
= no_effect
;
3199 bs_class
= long_jump
;
3201 case bp_longjmp_resume
:
3202 bs_class
= long_resume
;
3204 case bp_step_resume
:
3207 bs_class
= step_resume
;
3210 /* It is for the wrong frame. */
3211 bs_class
= bp_nostop
;
3213 case bp_watchpoint_scope
:
3214 bs_class
= bp_nostop
;
3216 case bp_shlib_event
:
3217 bs_class
= shlib_event
;
3219 case bp_thread_event
:
3220 case bp_overlay_event
:
3221 bs_class
= bp_nostop
;
3227 bs_class
= bp_noisy
;
3229 bs_class
= bp_silent
;
3232 /* There was a catchpoint, but we're not stopping.
3233 This requires no further action. */
3234 bs_class
= no_effect
;
3237 /* Make sure the action is stop (silent or noisy),
3238 so infrun.c pops the dummy frame. */
3239 bs_class
= bp_silent
;
3240 retval
.call_dummy
= 1;
3243 current_action
= table
[(int) bs_class
][(int) current_action
];
3245 retval
.main_action
= current_action
;
3249 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3250 without hardware support). This isn't related to a specific bpstat,
3251 just to things like whether watchpoints are set. */
3254 bpstat_should_step (void)
3256 struct breakpoint
*b
;
3258 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3265 static void print_breakpoint_location (struct breakpoint
*b
,
3266 struct bp_location
*loc
,
3268 struct ui_stream
*stb
)
3273 = find_pc_sect_function (loc
->address
, loc
->section
);
3276 ui_out_text (uiout
, "in ");
3277 ui_out_field_string (uiout
, "func",
3278 SYMBOL_PRINT_NAME (sym
));
3279 ui_out_wrap_hint (uiout
, wrap_indent
);
3280 ui_out_text (uiout
, " at ");
3282 ui_out_field_string (uiout
, "file", b
->source_file
);
3283 ui_out_text (uiout
, ":");
3285 if (ui_out_is_mi_like_p (uiout
))
3287 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3288 char *fullname
= symtab_to_fullname (sal
.symtab
);
3291 ui_out_field_string (uiout
, "fullname", fullname
);
3294 ui_out_field_int (uiout
, "line", b
->line_number
);
3298 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3302 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3303 ui_out_field_stream (uiout
, "at", stb
);
3307 /* Print B to gdb_stdout. */
3309 print_one_breakpoint_location (struct breakpoint
*b
,
3310 struct bp_location
*loc
,
3312 CORE_ADDR
*last_addr
)
3314 struct command_line
*l
;
3316 struct ep_type_description
3321 static struct ep_type_description bptypes
[] =
3323 {bp_none
, "?deleted?"},
3324 {bp_breakpoint
, "breakpoint"},
3325 {bp_hardware_breakpoint
, "hw breakpoint"},
3326 {bp_until
, "until"},
3327 {bp_finish
, "finish"},
3328 {bp_watchpoint
, "watchpoint"},
3329 {bp_hardware_watchpoint
, "hw watchpoint"},
3330 {bp_read_watchpoint
, "read watchpoint"},
3331 {bp_access_watchpoint
, "acc watchpoint"},
3332 {bp_longjmp
, "longjmp"},
3333 {bp_longjmp_resume
, "longjmp resume"},
3334 {bp_step_resume
, "step resume"},
3335 {bp_watchpoint_scope
, "watchpoint scope"},
3336 {bp_call_dummy
, "call dummy"},
3337 {bp_shlib_event
, "shlib events"},
3338 {bp_thread_event
, "thread events"},
3339 {bp_overlay_event
, "overlay events"},
3340 {bp_catchpoint
, "catchpoint"},
3343 static char bpenables
[] = "nynny";
3344 char wrap_indent
[80];
3345 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3346 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3347 struct cleanup
*bkpt_chain
;
3349 int header_of_multiple
= 0;
3350 int part_of_multiple
= (loc
!= NULL
);
3351 struct value_print_options opts
;
3353 get_user_print_options (&opts
);
3355 gdb_assert (!loc
|| loc_number
!= 0);
3356 /* See comment in print_one_breakpoint concerning
3357 treatment of breakpoints with single disabled
3361 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3362 header_of_multiple
= 1;
3367 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3371 if (part_of_multiple
)
3374 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3375 ui_out_field_string (uiout
, "number", formatted
);
3380 ui_out_field_int (uiout
, "number", b
->number
);
3385 if (part_of_multiple
)
3386 ui_out_field_skip (uiout
, "type");
3389 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3390 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3391 internal_error (__FILE__
, __LINE__
,
3392 _("bptypes table does not describe type #%d."),
3394 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3399 if (part_of_multiple
)
3400 ui_out_field_skip (uiout
, "disp");
3402 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3407 if (part_of_multiple
)
3408 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3410 ui_out_field_fmt (uiout
, "enabled", "%c",
3411 bpenables
[(int) b
->enable_state
]);
3412 ui_out_spaces (uiout
, 2);
3416 strcpy (wrap_indent
, " ");
3417 if (opts
.addressprint
)
3419 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3420 strcat (wrap_indent
, " ");
3422 strcat (wrap_indent
, " ");
3425 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3427 /* Although the print_one can possibly print
3428 all locations, calling it here is not likely
3429 to get any nice result. So, make sure there's
3430 just one location. */
3431 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3432 b
->ops
->print_one (b
, last_addr
);
3438 internal_error (__FILE__
, __LINE__
,
3439 _("print_one_breakpoint: bp_none encountered\n"));
3443 case bp_hardware_watchpoint
:
3444 case bp_read_watchpoint
:
3445 case bp_access_watchpoint
:
3446 /* Field 4, the address, is omitted (which makes the columns
3447 not line up too nicely with the headers, but the effect
3448 is relatively readable). */
3449 if (opts
.addressprint
)
3450 ui_out_field_skip (uiout
, "addr");
3452 print_expression (b
->exp
, stb
->stream
);
3453 ui_out_field_stream (uiout
, "what", stb
);
3457 case bp_hardware_breakpoint
:
3461 case bp_longjmp_resume
:
3462 case bp_step_resume
:
3463 case bp_watchpoint_scope
:
3465 case bp_shlib_event
:
3466 case bp_thread_event
:
3467 case bp_overlay_event
:
3468 if (opts
.addressprint
)
3471 if (header_of_multiple
)
3472 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3473 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3474 ui_out_field_string (uiout
, "addr", "<PENDING>");
3476 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3479 if (!header_of_multiple
)
3480 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3482 *last_addr
= b
->loc
->address
;
3486 if (!part_of_multiple
&& b
->thread
!= -1)
3488 /* FIXME: This seems to be redundant and lost here; see the
3489 "stop only in" line a little further down. */
3490 ui_out_text (uiout
, " thread ");
3491 ui_out_field_int (uiout
, "thread", b
->thread
);
3494 ui_out_text (uiout
, "\n");
3496 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3499 ui_out_text (uiout
, "\tstop only in stack frame at ");
3500 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3502 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3503 ui_out_text (uiout
, "\n");
3506 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3508 /* We do not print the condition for Ada exception catchpoints
3509 because the condition is an internal implementation detail
3510 that we do not want to expose to the user. */
3512 ui_out_text (uiout
, "\tstop only if ");
3513 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3514 ui_out_text (uiout
, "\n");
3517 if (!part_of_multiple
&& b
->thread
!= -1)
3519 /* FIXME should make an annotation for this */
3520 ui_out_text (uiout
, "\tstop only in thread ");
3521 ui_out_field_int (uiout
, "thread", b
->thread
);
3522 ui_out_text (uiout
, "\n");
3525 if (!part_of_multiple
&& b
->hit_count
)
3527 /* FIXME should make an annotation for this */
3528 if (ep_is_catchpoint (b
))
3529 ui_out_text (uiout
, "\tcatchpoint");
3531 ui_out_text (uiout
, "\tbreakpoint");
3532 ui_out_text (uiout
, " already hit ");
3533 ui_out_field_int (uiout
, "times", b
->hit_count
);
3534 if (b
->hit_count
== 1)
3535 ui_out_text (uiout
, " time\n");
3537 ui_out_text (uiout
, " times\n");
3540 /* Output the count also if it is zero, but only if this is
3541 mi. FIXME: Should have a better test for this. */
3542 if (ui_out_is_mi_like_p (uiout
))
3543 if (!part_of_multiple
&& b
->hit_count
== 0)
3544 ui_out_field_int (uiout
, "times", b
->hit_count
);
3546 if (!part_of_multiple
&& b
->ignore_count
)
3549 ui_out_text (uiout
, "\tignore next ");
3550 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3551 ui_out_text (uiout
, " hits\n");
3554 if (!part_of_multiple
&& (l
= b
->commands
))
3556 struct cleanup
*script_chain
;
3559 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3560 print_command_lines (uiout
, l
, 4);
3561 do_cleanups (script_chain
);
3564 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3567 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3568 else if (b
->exp_string
)
3569 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3572 do_cleanups (bkpt_chain
);
3573 do_cleanups (old_chain
);
3577 print_one_breakpoint (struct breakpoint
*b
,
3578 CORE_ADDR
*last_addr
)
3580 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3582 /* If this breakpoint has custom print function,
3583 it's already printed. Otherwise, print individual
3584 locations, if any. */
3585 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3587 /* If breakpoint has a single location that is
3588 disabled, we print it as if it had
3589 several locations, since otherwise it's hard to
3590 represent "breakpoint enabled, location disabled"
3592 Note that while hardware watchpoints have
3593 several locations internally, that's no a property
3596 && !is_hardware_watchpoint (b
)
3597 && (b
->loc
->next
|| !b
->loc
->enabled
)
3598 && !ui_out_is_mi_like_p (uiout
))
3600 struct bp_location
*loc
;
3602 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3603 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3609 struct captured_breakpoint_query_args
3615 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3617 struct captured_breakpoint_query_args
*args
= data
;
3618 struct breakpoint
*b
;
3619 CORE_ADDR dummy_addr
= 0;
3622 if (args
->bnum
== b
->number
)
3624 print_one_breakpoint (b
, &dummy_addr
);
3632 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3634 struct captured_breakpoint_query_args args
;
3636 /* For the moment we don't trust print_one_breakpoint() to not throw
3638 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3639 error_message
, RETURN_MASK_ALL
) < 0)
3645 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3646 catchpoints, et.al.). */
3649 user_settable_breakpoint (const struct breakpoint
*b
)
3651 return (b
->type
== bp_breakpoint
3652 || b
->type
== bp_catchpoint
3653 || b
->type
== bp_hardware_breakpoint
3654 || b
->type
== bp_watchpoint
3655 || b
->type
== bp_read_watchpoint
3656 || b
->type
== bp_access_watchpoint
3657 || b
->type
== bp_hardware_watchpoint
);
3660 /* Print information on user settable breakpoint (watchpoint, etc)
3661 number BNUM. If BNUM is -1 print all user settable breakpoints.
3662 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3665 breakpoint_1 (int bnum
, int allflag
)
3667 struct breakpoint
*b
;
3668 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3669 int nr_printable_breakpoints
;
3670 struct cleanup
*bkpttbl_chain
;
3671 struct value_print_options opts
;
3673 get_user_print_options (&opts
);
3675 /* Compute the number of rows in the table. */
3676 nr_printable_breakpoints
= 0;
3679 || bnum
== b
->number
)
3681 if (allflag
|| user_settable_breakpoint (b
))
3682 nr_printable_breakpoints
++;
3685 if (opts
.addressprint
)
3687 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3691 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3694 if (nr_printable_breakpoints
> 0)
3695 annotate_breakpoints_headers ();
3696 if (nr_printable_breakpoints
> 0)
3698 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3699 if (nr_printable_breakpoints
> 0)
3701 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3702 if (nr_printable_breakpoints
> 0)
3704 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3705 if (nr_printable_breakpoints
> 0)
3707 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3708 if (opts
.addressprint
)
3710 if (nr_printable_breakpoints
> 0)
3712 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3713 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3715 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3717 if (nr_printable_breakpoints
> 0)
3719 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3720 ui_out_table_body (uiout
);
3721 if (nr_printable_breakpoints
> 0)
3722 annotate_breakpoints_table ();
3726 || bnum
== b
->number
)
3728 /* We only print out user settable breakpoints unless the
3730 if (allflag
|| user_settable_breakpoint (b
))
3731 print_one_breakpoint (b
, &last_addr
);
3734 do_cleanups (bkpttbl_chain
);
3736 if (nr_printable_breakpoints
== 0)
3739 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3741 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3746 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3747 that a comparison of an unsigned with -1 is always false. */
3748 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3749 set_next_address (current_gdbarch
, last_addr
);
3752 /* FIXME? Should this be moved up so that it is only called when
3753 there have been breakpoints? */
3754 annotate_breakpoints_table_end ();
3758 breakpoints_info (char *bnum_exp
, int from_tty
)
3763 bnum
= parse_and_eval_long (bnum_exp
);
3765 breakpoint_1 (bnum
, 0);
3769 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3774 bnum
= parse_and_eval_long (bnum_exp
);
3776 breakpoint_1 (bnum
, 1);
3780 breakpoint_has_pc (struct breakpoint
*b
,
3781 CORE_ADDR pc
, struct obj_section
*section
)
3783 struct bp_location
*bl
= b
->loc
;
3784 for (; bl
; bl
= bl
->next
)
3786 if (bl
->address
== pc
3787 && (!overlay_debugging
|| bl
->section
== section
))
3793 /* Print a message describing any breakpoints set at PC. */
3796 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3800 struct breakpoint
*b
;
3803 others
+= breakpoint_has_pc (b
, pc
, section
);
3807 printf_filtered (_("Note: breakpoint "));
3808 else /* if (others == ???) */
3809 printf_filtered (_("Note: breakpoints "));
3811 if (breakpoint_has_pc (b
, pc
, section
))
3814 printf_filtered ("%d", b
->number
);
3815 if (b
->thread
== -1 && thread
!= -1)
3816 printf_filtered (" (all threads)");
3817 else if (b
->thread
!= -1)
3818 printf_filtered (" (thread %d)", b
->thread
);
3819 printf_filtered ("%s%s ",
3820 ((b
->enable_state
== bp_disabled
||
3821 b
->enable_state
== bp_call_disabled
)
3823 : b
->enable_state
== bp_permanent
3827 : ((others
== 1) ? " and" : ""));
3829 printf_filtered (_("also set at pc "));
3830 fputs_filtered (paddress (pc
), gdb_stdout
);
3831 printf_filtered (".\n");
3835 /* Set the default place to put a breakpoint
3836 for the `break' command with no arguments. */
3839 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3842 default_breakpoint_valid
= valid
;
3843 default_breakpoint_address
= addr
;
3844 default_breakpoint_symtab
= symtab
;
3845 default_breakpoint_line
= line
;
3848 /* Return true iff it is meaningful to use the address member of
3849 BPT. For some breakpoint types, the address member is irrelevant
3850 and it makes no sense to attempt to compare it to other addresses
3851 (or use it for any other purpose either).
3853 More specifically, each of the following breakpoint types will always
3854 have a zero valued address and we don't want check_duplicates() to mark
3855 breakpoints of any of these types to be a duplicate of an actual
3856 breakpoint at address zero:
3859 bp_hardware_watchpoint
3861 bp_access_watchpoint
3865 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3867 enum bptype type
= bpt
->type
;
3869 return (type
!= bp_watchpoint
3870 && type
!= bp_hardware_watchpoint
3871 && type
!= bp_read_watchpoint
3872 && type
!= bp_access_watchpoint
3873 && type
!= bp_catchpoint
);
3876 /* Rescan breakpoints at the same address and section as BPT,
3877 marking the first one as "first" and any others as "duplicates".
3878 This is so that the bpt instruction is only inserted once.
3879 If we have a permanent breakpoint at the same place as BPT, make
3880 that one the official one, and the rest as duplicates. */
3883 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
3885 struct bp_location
*b
;
3887 struct bp_location
*perm_bp
= 0;
3889 ALL_BP_LOCATIONS (b
)
3890 if (b
->owner
->enable_state
!= bp_disabled
3891 && b
->owner
->enable_state
!= bp_call_disabled
3893 && !b
->shlib_disabled
3894 && b
->address
== address
/* address / overlay match */
3895 && (!overlay_debugging
|| b
->section
== section
)
3896 && breakpoint_address_is_meaningful (b
->owner
))
3898 /* Have we found a permanent breakpoint? */
3899 if (b
->owner
->enable_state
== bp_permanent
)
3906 b
->duplicate
= count
> 1;
3909 /* If we found a permanent breakpoint at this address, go over the
3910 list again and declare all the other breakpoints there to be the
3914 perm_bp
->duplicate
= 0;
3916 /* Permanent breakpoint should always be inserted. */
3917 if (! perm_bp
->inserted
)
3918 internal_error (__FILE__
, __LINE__
,
3919 _("allegedly permanent breakpoint is not "
3920 "actually inserted"));
3922 ALL_BP_LOCATIONS (b
)
3925 if (b
->owner
->enable_state
!= bp_disabled
3926 && b
->owner
->enable_state
!= bp_call_disabled
3927 && b
->enabled
&& !b
->shlib_disabled
3928 && b
->address
== address
/* address / overlay match */
3929 && (!overlay_debugging
|| b
->section
== section
)
3930 && breakpoint_address_is_meaningful (b
->owner
))
3933 internal_error (__FILE__
, __LINE__
,
3934 _("another breakpoint was inserted on top of "
3935 "a permanent breakpoint"));
3944 check_duplicates (struct breakpoint
*bpt
)
3946 struct bp_location
*bl
= bpt
->loc
;
3948 if (! breakpoint_address_is_meaningful (bpt
))
3951 for (; bl
; bl
= bl
->next
)
3952 check_duplicates_for (bl
->address
, bl
->section
);
3956 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3957 int bnum
, int have_bnum
)
3962 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
3963 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
3965 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
3966 bnum
, astr1
, astr2
);
3968 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
3971 /* Adjust a breakpoint's address to account for architectural constraints
3972 on breakpoint placement. Return the adjusted address. Note: Very
3973 few targets require this kind of adjustment. For most targets,
3974 this function is simply the identity function. */
3977 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
3979 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3981 /* Very few targets need any kind of breakpoint adjustment. */
3984 else if (bptype
== bp_watchpoint
3985 || bptype
== bp_hardware_watchpoint
3986 || bptype
== bp_read_watchpoint
3987 || bptype
== bp_access_watchpoint
3988 || bptype
== bp_catchpoint
)
3990 /* Watchpoints and the various bp_catch_* eventpoints should not
3991 have their addresses modified. */
3996 CORE_ADDR adjusted_bpaddr
;
3998 /* Some targets have architectural constraints on the placement
3999 of breakpoint instructions. Obtain the adjusted address. */
4000 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4003 /* An adjusted breakpoint address can significantly alter
4004 a user's expectations. Print a warning if an adjustment
4006 if (adjusted_bpaddr
!= bpaddr
)
4007 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4009 return adjusted_bpaddr
;
4013 /* Allocate a struct bp_location. */
4015 static struct bp_location
*
4016 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4018 struct bp_location
*loc
, *loc_p
;
4020 loc
= xmalloc (sizeof (struct bp_location
));
4021 memset (loc
, 0, sizeof (*loc
));
4025 loc
->shlib_disabled
= 0;
4034 case bp_longjmp_resume
:
4035 case bp_step_resume
:
4036 case bp_watchpoint_scope
:
4038 case bp_shlib_event
:
4039 case bp_thread_event
:
4040 case bp_overlay_event
:
4041 loc
->loc_type
= bp_loc_software_breakpoint
;
4043 case bp_hardware_breakpoint
:
4044 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4046 case bp_hardware_watchpoint
:
4047 case bp_read_watchpoint
:
4048 case bp_access_watchpoint
:
4049 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4053 loc
->loc_type
= bp_loc_other
;
4056 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4062 static void free_bp_location (struct bp_location
*loc
)
4067 if (loc
->function_name
)
4068 xfree (loc
->function_name
);
4073 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4074 that has type BPTYPE and has no locations as yet. */
4076 static struct breakpoint
*
4077 set_raw_breakpoint_without_location (enum bptype bptype
)
4079 struct breakpoint
*b
, *b1
;
4081 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4082 memset (b
, 0, sizeof (*b
));
4085 b
->language
= current_language
->la_language
;
4086 b
->input_radix
= input_radix
;
4088 b
->enable_state
= bp_enabled
;
4091 b
->ignore_count
= 0;
4093 b
->frame_id
= null_frame_id
;
4094 b
->forked_inferior_pid
= null_ptid
;
4095 b
->exec_pathname
= NULL
;
4097 b
->condition_not_parsed
= 0;
4099 /* Add this breakpoint to the end of the chain
4100 so that a list of breakpoints will come out in order
4101 of increasing numbers. */
4103 b1
= breakpoint_chain
;
4105 breakpoint_chain
= b
;
4115 /* Initialize loc->function_name. */
4117 set_breakpoint_location_function (struct bp_location
*loc
)
4119 if (loc
->owner
->type
== bp_breakpoint
4120 || loc
->owner
->type
== bp_hardware_breakpoint
)
4122 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4124 if (loc
->function_name
)
4125 loc
->function_name
= xstrdup (loc
->function_name
);
4129 /* set_raw_breakpoint is a low level routine for allocating and
4130 partially initializing a breakpoint of type BPTYPE. The newly
4131 created breakpoint's address, section, source file name, and line
4132 number are provided by SAL. The newly created and partially
4133 initialized breakpoint is added to the breakpoint chain and
4134 is also returned as the value of this function.
4136 It is expected that the caller will complete the initialization of
4137 the newly created breakpoint struct as well as output any status
4138 information regarding the creation of a new breakpoint. In
4139 particular, set_raw_breakpoint does NOT set the breakpoint
4140 number! Care should be taken to not allow an error to occur
4141 prior to completing the initialization of the breakpoint. If this
4142 should happen, a bogus breakpoint will be left on the chain. */
4145 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4147 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4148 CORE_ADDR adjusted_address
;
4150 /* Adjust the breakpoint's address prior to allocating a location.
4151 Once we call allocate_bp_location(), that mostly uninitialized
4152 location will be placed on the location chain. Adjustment of the
4153 breakpoint may cause target_read_memory() to be called and we do
4154 not want its scan of the location chain to find a breakpoint and
4155 location that's only been partially initialized. */
4156 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4158 b
->loc
= allocate_bp_location (b
, bptype
);
4159 b
->loc
->requested_address
= sal
.pc
;
4160 b
->loc
->address
= adjusted_address
;
4162 if (sal
.symtab
== NULL
)
4163 b
->source_file
= NULL
;
4165 b
->source_file
= savestring (sal
.symtab
->filename
,
4166 strlen (sal
.symtab
->filename
));
4167 b
->loc
->section
= sal
.section
;
4168 b
->line_number
= sal
.line
;
4170 set_breakpoint_location_function (b
->loc
);
4172 breakpoints_changed ();
4178 /* Note that the breakpoint object B describes a permanent breakpoint
4179 instruction, hard-wired into the inferior's code. */
4181 make_breakpoint_permanent (struct breakpoint
*b
)
4183 struct bp_location
*bl
;
4184 b
->enable_state
= bp_permanent
;
4186 /* By definition, permanent breakpoints are already present in the code.
4187 Mark all locations as inserted. For now, make_breakpoint_permanent
4188 is called in just one place, so it's hard to say if it's reasonable
4189 to have permanent breakpoint with multiple locations or not,
4190 but it's easy to implmement. */
4191 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4195 static struct breakpoint
*
4196 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4198 static int internal_breakpoint_number
= -1;
4199 struct symtab_and_line sal
;
4200 struct breakpoint
*b
;
4202 init_sal (&sal
); /* initialize to zeroes */
4205 sal
.section
= find_pc_overlay (sal
.pc
);
4207 b
= set_raw_breakpoint (sal
, type
);
4208 b
->number
= internal_breakpoint_number
--;
4209 b
->disposition
= disp_donttouch
;
4216 create_longjmp_breakpoint (char *func_name
)
4218 struct minimal_symbol
*m
;
4220 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4222 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4223 update_global_location_list (1);
4226 /* Call this routine when stepping and nexting to enable a breakpoint
4227 if we do a longjmp(). When we hit that breakpoint, call
4228 set_longjmp_resume_breakpoint() to figure out where we are going. */
4231 set_longjmp_breakpoint (void)
4233 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4235 create_longjmp_breakpoint ("longjmp");
4236 create_longjmp_breakpoint ("_longjmp");
4237 create_longjmp_breakpoint ("siglongjmp");
4238 create_longjmp_breakpoint ("_siglongjmp");
4242 /* Delete all longjmp breakpoints from THREAD. */
4244 delete_longjmp_breakpoint (int thread
)
4246 struct breakpoint
*b
, *temp
;
4248 ALL_BREAKPOINTS_SAFE (b
, temp
)
4249 if (b
->type
== bp_longjmp
)
4251 if (b
->thread
== thread
)
4252 delete_breakpoint (b
);
4257 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4259 struct breakpoint
*b
;
4260 struct minimal_symbol
*m
;
4262 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4265 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4267 b
->addr_string
= xstrdup (func_name
);
4269 if (overlay_debugging
== ovly_auto
)
4271 b
->enable_state
= bp_enabled
;
4272 overlay_events_enabled
= 1;
4276 b
->enable_state
= bp_disabled
;
4277 overlay_events_enabled
= 0;
4279 update_global_location_list (1);
4283 create_overlay_event_breakpoint (char *func_name
)
4285 struct objfile
*objfile
;
4286 ALL_OBJFILES (objfile
)
4287 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4291 enable_overlay_breakpoints (void)
4293 struct breakpoint
*b
;
4296 if (b
->type
== bp_overlay_event
)
4298 b
->enable_state
= bp_enabled
;
4299 update_global_location_list (1);
4300 overlay_events_enabled
= 1;
4305 disable_overlay_breakpoints (void)
4307 struct breakpoint
*b
;
4310 if (b
->type
== bp_overlay_event
)
4312 b
->enable_state
= bp_disabled
;
4313 update_global_location_list (0);
4314 overlay_events_enabled
= 0;
4319 create_thread_event_breakpoint (CORE_ADDR address
)
4321 struct breakpoint
*b
;
4323 b
= create_internal_breakpoint (address
, bp_thread_event
);
4325 b
->enable_state
= bp_enabled
;
4326 /* addr_string has to be used or breakpoint_re_set will delete me. */
4327 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4329 update_global_location_list_nothrow (1);
4335 remove_thread_event_breakpoints (void)
4337 struct breakpoint
*b
, *temp
;
4339 ALL_BREAKPOINTS_SAFE (b
, temp
)
4340 if (b
->type
== bp_thread_event
)
4341 delete_breakpoint (b
);
4344 struct captured_parse_breakpoint_args
4347 struct symtabs_and_lines
*sals_p
;
4348 char ***addr_string_p
;
4352 struct lang_and_radix
4360 remove_solib_event_breakpoints (void)
4362 struct breakpoint
*b
, *temp
;
4364 ALL_BREAKPOINTS_SAFE (b
, temp
)
4365 if (b
->type
== bp_shlib_event
)
4366 delete_breakpoint (b
);
4370 create_solib_event_breakpoint (CORE_ADDR address
)
4372 struct breakpoint
*b
;
4374 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4375 update_global_location_list_nothrow (1);
4379 /* Disable any breakpoints that are on code in shared libraries. Only
4380 apply to enabled breakpoints, disabled ones can just stay disabled. */
4383 disable_breakpoints_in_shlibs (void)
4385 struct bp_location
*loc
;
4386 int disabled_shlib_breaks
= 0;
4388 ALL_BP_LOCATIONS (loc
)
4390 struct breakpoint
*b
= loc
->owner
;
4391 /* We apply the check to all breakpoints, including disabled
4392 for those with loc->duplicate set. This is so that when breakpoint
4393 becomes enabled, or the duplicate is removed, gdb will try to insert
4394 all breakpoints. If we don't set shlib_disabled here, we'll try
4395 to insert those breakpoints and fail. */
4396 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4397 && !loc
->shlib_disabled
4399 && PC_SOLIB (loc
->address
)
4401 && solib_address (loc
->address
)
4405 loc
->shlib_disabled
= 1;
4410 /* Disable any breakpoints that are in in an unloaded shared library. Only
4411 apply to enabled breakpoints, disabled ones can just stay disabled. */
4414 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4416 struct bp_location
*loc
;
4417 int disabled_shlib_breaks
= 0;
4419 ALL_BP_LOCATIONS (loc
)
4421 struct breakpoint
*b
= loc
->owner
;
4422 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4423 || loc
->loc_type
== bp_loc_software_breakpoint
)
4424 && !loc
->shlib_disabled
)
4427 char *so_name
= PC_SOLIB (loc
->address
);
4429 char *so_name
= solib_address (loc
->address
);
4431 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4433 loc
->shlib_disabled
= 1;
4434 /* At this point, we cannot rely on remove_breakpoint
4435 succeeding so we must mark the breakpoint as not inserted
4436 to prevent future errors occurring in remove_breakpoints. */
4438 if (!disabled_shlib_breaks
)
4440 target_terminal_ours_for_output ();
4441 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4444 disabled_shlib_breaks
= 1;
4450 /* FORK & VFORK catchpoints. */
4452 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4455 insert_catch_fork (struct breakpoint
*b
)
4457 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4460 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4463 remove_catch_fork (struct breakpoint
*b
)
4465 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4468 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4472 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4474 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4477 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4479 static enum print_stop_action
4480 print_it_catch_fork (struct breakpoint
*b
)
4482 annotate_catchpoint (b
->number
);
4483 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4484 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4485 return PRINT_SRC_AND_LOC
;
4488 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4491 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4493 struct value_print_options opts
;
4495 get_user_print_options (&opts
);
4497 /* Field 4, the address, is omitted (which makes the columns
4498 not line up too nicely with the headers, but the effect
4499 is relatively readable). */
4500 if (opts
.addressprint
)
4501 ui_out_field_skip (uiout
, "addr");
4503 ui_out_text (uiout
, "fork");
4504 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4506 ui_out_text (uiout
, ", process ");
4507 ui_out_field_int (uiout
, "what",
4508 ptid_get_pid (b
->forked_inferior_pid
));
4509 ui_out_spaces (uiout
, 1);
4513 /* Implement the "print_mention" breakpoint_ops method for fork
4517 print_mention_catch_fork (struct breakpoint
*b
)
4519 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4522 /* The breakpoint_ops structure to be used in fork catchpoints. */
4524 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4528 breakpoint_hit_catch_fork
,
4529 print_it_catch_fork
,
4530 print_one_catch_fork
,
4531 print_mention_catch_fork
4534 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4537 insert_catch_vfork (struct breakpoint
*b
)
4539 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4542 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4545 remove_catch_vfork (struct breakpoint
*b
)
4547 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4550 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4554 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4556 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4559 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4561 static enum print_stop_action
4562 print_it_catch_vfork (struct breakpoint
*b
)
4564 annotate_catchpoint (b
->number
);
4565 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4566 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4567 return PRINT_SRC_AND_LOC
;
4570 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4573 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4575 struct value_print_options opts
;
4577 get_user_print_options (&opts
);
4578 /* Field 4, the address, is omitted (which makes the columns
4579 not line up too nicely with the headers, but the effect
4580 is relatively readable). */
4581 if (opts
.addressprint
)
4582 ui_out_field_skip (uiout
, "addr");
4584 ui_out_text (uiout
, "vfork");
4585 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4587 ui_out_text (uiout
, ", process ");
4588 ui_out_field_int (uiout
, "what",
4589 ptid_get_pid (b
->forked_inferior_pid
));
4590 ui_out_spaces (uiout
, 1);
4594 /* Implement the "print_mention" breakpoint_ops method for vfork
4598 print_mention_catch_vfork (struct breakpoint
*b
)
4600 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4603 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4605 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4609 breakpoint_hit_catch_vfork
,
4610 print_it_catch_vfork
,
4611 print_one_catch_vfork
,
4612 print_mention_catch_vfork
4615 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4617 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4618 If COND_STRING is not NULL, then store it in the breakpoint.
4619 OPS, if not NULL, is the breakpoint_ops structure associated
4620 to the catchpoint. */
4622 static struct breakpoint
*
4623 create_catchpoint (int tempflag
, char *cond_string
,
4624 struct breakpoint_ops
*ops
)
4626 struct symtab_and_line sal
;
4627 struct breakpoint
*b
;
4634 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4635 set_breakpoint_count (breakpoint_count
+ 1);
4636 b
->number
= breakpoint_count
;
4638 b
->cond_string
= (cond_string
== NULL
) ?
4639 NULL
: savestring (cond_string
, strlen (cond_string
));
4641 b
->addr_string
= NULL
;
4642 b
->enable_state
= bp_enabled
;
4643 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4647 update_global_location_list (1);
4653 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4654 struct breakpoint_ops
*ops
)
4656 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4658 /* FIXME: We should put this information in a breakpoint private data
4660 b
->forked_inferior_pid
= null_ptid
;
4663 /* Exec catchpoints. */
4666 insert_catch_exec (struct breakpoint
*b
)
4668 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4672 remove_catch_exec (struct breakpoint
*b
)
4674 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4678 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4680 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4683 static enum print_stop_action
4684 print_it_catch_exec (struct breakpoint
*b
)
4686 annotate_catchpoint (b
->number
);
4687 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4689 return PRINT_SRC_AND_LOC
;
4693 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4695 struct value_print_options opts
;
4697 get_user_print_options (&opts
);
4699 /* Field 4, the address, is omitted (which makes the columns
4700 not line up too nicely with the headers, but the effect
4701 is relatively readable). */
4702 if (opts
.addressprint
)
4703 ui_out_field_skip (uiout
, "addr");
4705 ui_out_text (uiout
, "exec");
4706 if (b
->exec_pathname
!= NULL
)
4708 ui_out_text (uiout
, ", program \"");
4709 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4710 ui_out_text (uiout
, "\" ");
4715 print_mention_catch_exec (struct breakpoint
*b
)
4717 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4720 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4724 breakpoint_hit_catch_exec
,
4725 print_it_catch_exec
,
4726 print_one_catch_exec
,
4727 print_mention_catch_exec
4731 hw_breakpoint_used_count (void)
4733 struct breakpoint
*b
;
4738 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4746 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4748 struct breakpoint
*b
;
4751 *other_type_used
= 0;
4754 if (breakpoint_enabled (b
))
4756 if (b
->type
== type
)
4758 else if ((b
->type
== bp_hardware_watchpoint
||
4759 b
->type
== bp_read_watchpoint
||
4760 b
->type
== bp_access_watchpoint
))
4761 *other_type_used
= 1;
4768 disable_watchpoints_before_interactive_call_start (void)
4770 struct breakpoint
*b
;
4774 if (((b
->type
== bp_watchpoint
)
4775 || (b
->type
== bp_hardware_watchpoint
)
4776 || (b
->type
== bp_read_watchpoint
)
4777 || (b
->type
== bp_access_watchpoint
))
4778 && breakpoint_enabled (b
))
4780 b
->enable_state
= bp_call_disabled
;
4781 update_global_location_list (0);
4787 enable_watchpoints_after_interactive_call_stop (void)
4789 struct breakpoint
*b
;
4793 if (((b
->type
== bp_watchpoint
)
4794 || (b
->type
== bp_hardware_watchpoint
)
4795 || (b
->type
== bp_read_watchpoint
)
4796 || (b
->type
== bp_access_watchpoint
))
4797 && (b
->enable_state
== bp_call_disabled
))
4799 b
->enable_state
= bp_enabled
;
4800 update_global_location_list (1);
4806 /* Set a breakpoint that will evaporate an end of command
4807 at address specified by SAL.
4808 Restrict it to frame FRAME if FRAME is nonzero. */
4811 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4814 struct breakpoint
*b
;
4815 b
= set_raw_breakpoint (sal
, type
);
4816 b
->enable_state
= bp_enabled
;
4817 b
->disposition
= disp_donttouch
;
4818 b
->frame_id
= frame_id
;
4820 /* If we're debugging a multi-threaded program, then we
4821 want momentary breakpoints to be active in only a
4822 single thread of control. */
4823 if (in_thread_list (inferior_ptid
))
4824 b
->thread
= pid_to_thread_id (inferior_ptid
);
4826 update_global_location_list_nothrow (1);
4832 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4834 struct symtab_and_line sal
;
4836 sal
= find_pc_line (pc
, 0);
4838 sal
.section
= find_pc_overlay (pc
);
4839 sal
.explicit_pc
= 1;
4841 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4845 /* Tell the user we have just set a breakpoint B. */
4848 mention (struct breakpoint
*b
)
4851 struct cleanup
*old_chain
, *ui_out_chain
;
4852 struct ui_stream
*stb
;
4853 struct value_print_options opts
;
4855 get_user_print_options (&opts
);
4857 stb
= ui_out_stream_new (uiout
);
4858 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4860 /* FIXME: This is misplaced; mention() is called by things (like
4861 hitting a watchpoint) other than breakpoint creation. It should
4862 be possible to clean this up and at the same time replace the
4863 random calls to breakpoint_changed with this hook. */
4864 observer_notify_breakpoint_created (b
->number
);
4866 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4867 b
->ops
->print_mention (b
);
4872 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4875 ui_out_text (uiout
, "Watchpoint ");
4876 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4877 ui_out_field_int (uiout
, "number", b
->number
);
4878 ui_out_text (uiout
, ": ");
4879 print_expression (b
->exp
, stb
->stream
);
4880 ui_out_field_stream (uiout
, "exp", stb
);
4881 do_cleanups (ui_out_chain
);
4883 case bp_hardware_watchpoint
:
4884 ui_out_text (uiout
, "Hardware watchpoint ");
4885 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4886 ui_out_field_int (uiout
, "number", b
->number
);
4887 ui_out_text (uiout
, ": ");
4888 print_expression (b
->exp
, stb
->stream
);
4889 ui_out_field_stream (uiout
, "exp", stb
);
4890 do_cleanups (ui_out_chain
);
4892 case bp_read_watchpoint
:
4893 ui_out_text (uiout
, "Hardware read watchpoint ");
4894 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4895 ui_out_field_int (uiout
, "number", b
->number
);
4896 ui_out_text (uiout
, ": ");
4897 print_expression (b
->exp
, stb
->stream
);
4898 ui_out_field_stream (uiout
, "exp", stb
);
4899 do_cleanups (ui_out_chain
);
4901 case bp_access_watchpoint
:
4902 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4903 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4904 ui_out_field_int (uiout
, "number", b
->number
);
4905 ui_out_text (uiout
, ": ");
4906 print_expression (b
->exp
, stb
->stream
);
4907 ui_out_field_stream (uiout
, "exp", stb
);
4908 do_cleanups (ui_out_chain
);
4911 if (ui_out_is_mi_like_p (uiout
))
4916 if (b
->disposition
== disp_del
)
4917 printf_filtered (_("Temporary breakpoint"));
4919 printf_filtered (_("Breakpoint"));
4920 printf_filtered (_(" %d"), b
->number
);
4923 case bp_hardware_breakpoint
:
4924 if (ui_out_is_mi_like_p (uiout
))
4929 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4936 case bp_longjmp_resume
:
4937 case bp_step_resume
:
4939 case bp_watchpoint_scope
:
4940 case bp_shlib_event
:
4941 case bp_thread_event
:
4942 case bp_overlay_event
:
4948 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4952 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4956 if (opts
.addressprint
|| b
->source_file
== NULL
)
4958 printf_filtered (" at ");
4959 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4962 printf_filtered (": file %s, line %d.",
4963 b
->source_file
, b
->line_number
);
4967 struct bp_location
*loc
= b
->loc
;
4969 for (; loc
; loc
= loc
->next
)
4971 printf_filtered (" (%d locations)", n
);
4976 do_cleanups (old_chain
);
4977 if (ui_out_is_mi_like_p (uiout
))
4979 printf_filtered ("\n");
4983 static struct bp_location
*
4984 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
4985 const struct symtab_and_line
*sal
)
4987 struct bp_location
*loc
, **tmp
;
4989 loc
= allocate_bp_location (b
, bptype
);
4990 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
4993 loc
->requested_address
= sal
->pc
;
4994 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
4996 loc
->section
= sal
->section
;
4998 set_breakpoint_location_function (loc
);
5003 /* Return 1 if LOC is pointing to a permanent breakpoint,
5004 return 0 otherwise. */
5007 bp_loc_is_permanent (struct bp_location
*loc
)
5011 const gdb_byte
*brk
;
5012 gdb_byte
*target_mem
;
5014 gdb_assert (loc
!= NULL
);
5016 addr
= loc
->address
;
5017 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5019 target_mem
= alloca (len
);
5021 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5022 && memcmp (target_mem
, brk
, len
) == 0)
5030 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5031 as textual description of the location, and COND_STRING
5032 as condition expression. */
5035 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5037 enum bptype type
, enum bpdisp disposition
,
5038 int thread
, int ignore_count
,
5039 struct breakpoint_ops
*ops
, int from_tty
)
5041 struct breakpoint
*b
= NULL
;
5044 if (type
== bp_hardware_breakpoint
)
5046 int i
= hw_breakpoint_used_count ();
5047 int target_resources_ok
=
5048 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5050 if (target_resources_ok
== 0)
5051 error (_("No hardware breakpoint support in the target."));
5052 else if (target_resources_ok
< 0)
5053 error (_("Hardware breakpoints used exceeds limit."));
5056 for (i
= 0; i
< sals
.nelts
; ++i
)
5058 struct symtab_and_line sal
= sals
.sals
[i
];
5059 struct bp_location
*loc
;
5062 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5066 b
= set_raw_breakpoint (sal
, type
);
5067 set_breakpoint_count (breakpoint_count
+ 1);
5068 b
->number
= breakpoint_count
;
5071 b
->cond_string
= cond_string
;
5072 b
->ignore_count
= ignore_count
;
5073 b
->enable_state
= bp_enabled
;
5074 b
->disposition
= disposition
;
5080 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5083 if (bp_loc_is_permanent (loc
))
5084 make_breakpoint_permanent (b
);
5088 char *arg
= b
->cond_string
;
5089 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5091 error (_("Garbage %s follows condition"), arg
);
5096 b
->addr_string
= addr_string
;
5098 /* addr_string has to be used or breakpoint_re_set will delete
5100 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5106 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5107 elements to fill the void space. */
5108 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5110 int i
= index_to_remove
+1;
5111 int last_index
= sal
->nelts
-1;
5113 for (;i
<= last_index
; ++i
)
5114 sal
->sals
[i
-1] = sal
->sals
[i
];
5119 /* If appropriate, obtains all sals that correspond
5120 to the same file and line as SAL. This is done
5121 only if SAL does not have explicit PC and has
5122 line and file information. If we got just a single
5123 expanded sal, return the original.
5125 Otherwise, if SAL.explicit_line is not set, filter out
5126 all sals for which the name of enclosing function
5127 is different from SAL. This makes sure that if we have
5128 breakpoint originally set in template instantiation, say
5129 foo<int>(), we won't expand SAL to locations at the same
5130 line in all existing instantiations of 'foo'.
5133 struct symtabs_and_lines
5134 expand_line_sal_maybe (struct symtab_and_line sal
)
5136 struct symtabs_and_lines expanded
;
5137 CORE_ADDR original_pc
= sal
.pc
;
5138 char *original_function
= NULL
;
5142 /* If we have explicit pc, don't expand.
5143 If we have no line number, we can't expand. */
5144 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5147 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5148 expanded
.sals
[0] = sal
;
5153 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5155 expanded
= expand_line_sal (sal
);
5156 if (expanded
.nelts
== 1)
5158 /* We had one sal, we got one sal. Without futher
5159 processing, just return the original sal. */
5160 xfree (expanded
.sals
);
5162 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5163 sal
.pc
= original_pc
;
5164 expanded
.sals
[0] = sal
;
5168 if (!sal
.explicit_line
)
5170 CORE_ADDR func_addr
, func_end
;
5171 for (i
= 0; i
< expanded
.nelts
; ++i
)
5173 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5174 char *this_function
;
5175 if (find_pc_partial_function (pc
, &this_function
,
5176 &func_addr
, &func_end
))
5178 if (this_function
&&
5179 strcmp (this_function
, original_function
) != 0)
5181 remove_sal (&expanded
, i
);
5184 else if (func_addr
== pc
)
5186 /* We're at beginning of a function, and should
5188 struct symbol
*sym
= find_pc_function (pc
);
5190 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5193 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5200 if (expanded
.nelts
<= 1)
5202 /* This is un ugly workaround. If we get zero
5203 expanded sals then something is really wrong.
5204 Fix that by returnign the original sal. */
5205 xfree (expanded
.sals
);
5207 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5208 sal
.pc
= original_pc
;
5209 expanded
.sals
[0] = sal
;
5216 for (i
= 0; i
< expanded
.nelts
; ++i
)
5217 if (expanded
.sals
[i
].pc
== original_pc
)
5228 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5229 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5230 value. COND_STRING, if not NULL, specified the condition to be
5231 used for all breakpoints. Essentially the only case where
5232 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5233 function. In that case, it's still not possible to specify
5234 separate conditions for different overloaded functions, so
5235 we take just a single condition string.
5237 NOTE: If the function succeeds, the caller is expected to cleanup
5238 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5239 array contents). If the function fails (error() is called), the
5240 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5241 COND and SALS arrays and each of those arrays contents. */
5244 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5246 enum bptype type
, enum bpdisp disposition
,
5247 int thread
, int ignore_count
,
5248 struct breakpoint_ops
*ops
, int from_tty
)
5251 for (i
= 0; i
< sals
.nelts
; ++i
)
5253 struct symtabs_and_lines expanded
=
5254 expand_line_sal_maybe (sals
.sals
[i
]);
5256 create_breakpoint (expanded
, addr_string
[i
],
5257 cond_string
, type
, disposition
,
5258 thread
, ignore_count
, ops
, from_tty
);
5261 update_global_location_list (1);
5264 /* Parse ARG which is assumed to be a SAL specification possibly
5265 followed by conditionals. On return, SALS contains an array of SAL
5266 addresses found. ADDR_STRING contains a vector of (canonical)
5267 address strings. ARG points to the end of the SAL. */
5270 parse_breakpoint_sals (char **address
,
5271 struct symtabs_and_lines
*sals
,
5272 char ***addr_string
,
5275 char *addr_start
= *address
;
5276 *addr_string
= NULL
;
5277 /* If no arg given, or if first arg is 'if ', use the default
5279 if ((*address
) == NULL
5280 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5282 if (default_breakpoint_valid
)
5284 struct symtab_and_line sal
;
5285 init_sal (&sal
); /* initialize to zeroes */
5286 sals
->sals
= (struct symtab_and_line
*)
5287 xmalloc (sizeof (struct symtab_and_line
));
5288 sal
.pc
= default_breakpoint_address
;
5289 sal
.line
= default_breakpoint_line
;
5290 sal
.symtab
= default_breakpoint_symtab
;
5291 sal
.section
= find_pc_overlay (sal
.pc
);
5292 sals
->sals
[0] = sal
;
5296 error (_("No default breakpoint address now."));
5300 /* Force almost all breakpoints to be in terms of the
5301 current_source_symtab (which is decode_line_1's default). This
5302 should produce the results we want almost all of the time while
5303 leaving default_breakpoint_* alone.
5304 ObjC: However, don't match an Objective-C method name which
5305 may have a '+' or '-' succeeded by a '[' */
5307 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5309 if (default_breakpoint_valid
5311 || ((strchr ("+-", (*address
)[0]) != NULL
)
5312 && ((*address
)[1] != '['))))
5313 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5314 default_breakpoint_line
, addr_string
,
5317 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5318 addr_string
, not_found_ptr
);
5320 /* For any SAL that didn't have a canonical string, fill one in. */
5321 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5322 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5323 if (addr_start
!= (*address
))
5326 for (i
= 0; i
< sals
->nelts
; i
++)
5328 /* Add the string if not present. */
5329 if ((*addr_string
)[i
] == NULL
)
5330 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5336 /* Convert each SAL into a real PC. Verify that the PC can be
5337 inserted as a breakpoint. If it can't throw an error. */
5340 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5344 for (i
= 0; i
< sals
->nelts
; i
++)
5345 resolve_sal_pc (&sals
->sals
[i
]);
5349 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5351 struct captured_parse_breakpoint_args
*args
= data
;
5353 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5354 args
->not_found_ptr
);
5357 /* Given TOK, a string specification of condition and thread, as
5358 accepted by the 'break' command, extract the condition
5359 string and thread number and set *COND_STRING and *THREAD.
5360 PC identifies the context at which the condition should be parsed.
5361 If no condition is found, *COND_STRING is set to NULL.
5362 If no thread is found, *THREAD is set to -1. */
5364 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5365 char **cond_string
, int *thread
)
5367 *cond_string
= NULL
;
5373 char *cond_start
= NULL
;
5374 char *cond_end
= NULL
;
5375 while (*tok
== ' ' || *tok
== '\t')
5380 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5383 toklen
= end_tok
- tok
;
5385 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5387 tok
= cond_start
= end_tok
+ 1;
5388 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5390 *cond_string
= savestring (cond_start
,
5391 cond_end
- cond_start
);
5393 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5399 *thread
= strtol (tok
, &tok
, 0);
5401 error (_("Junk after thread keyword."));
5402 if (!valid_thread_id (*thread
))
5403 error (_("Unknown thread %d."), *thread
);
5406 error (_("Junk at end of arguments."));
5410 /* Set a breakpoint. This function is shared between
5411 CLI and MI functions for setting a breakpoint.
5412 This function has two major modes of operations,
5413 selected by the PARSE_CONDITION_AND_THREAD parameter.
5414 If non-zero, the function will parse arg, extracting
5415 breakpoint location, address and thread. Otherwise,
5416 ARG is just the location of breakpoint, with condition
5417 and thread specified by the COND_STRING and THREAD
5421 break_command_really (char *arg
, char *cond_string
, int thread
,
5422 int parse_condition_and_thread
,
5423 int tempflag
, int hardwareflag
,
5425 enum auto_boolean pending_break_support
,
5426 struct breakpoint_ops
*ops
,
5429 struct gdb_exception e
;
5430 struct symtabs_and_lines sals
;
5431 struct symtab_and_line pending_sal
;
5434 char *addr_start
= arg
;
5436 struct cleanup
*old_chain
;
5437 struct cleanup
*breakpoint_chain
= NULL
;
5438 struct captured_parse_breakpoint_args parse_args
;
5447 parse_args
.arg_p
= &arg
;
5448 parse_args
.sals_p
= &sals
;
5449 parse_args
.addr_string_p
= &addr_string
;
5450 parse_args
.not_found_ptr
= ¬_found
;
5452 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5453 &parse_args
, RETURN_MASK_ALL
);
5455 /* If caller is interested in rc value from parse, set value. */
5459 throw_exception (e
);
5463 case NOT_FOUND_ERROR
:
5465 /* If pending breakpoint support is turned off, throw
5468 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5469 throw_exception (e
);
5471 exception_print (gdb_stderr
, e
);
5473 /* If pending breakpoint support is auto query and the user
5474 selects no, then simply return the error code. */
5475 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5476 !nquery ("Make breakpoint pending on future shared library load? "))
5479 /* At this point, either the user was queried about setting
5480 a pending breakpoint and selected yes, or pending
5481 breakpoint behavior is on and thus a pending breakpoint
5482 is defaulted on behalf of the user. */
5483 copy_arg
= xstrdup (addr_start
);
5484 addr_string
= ©_arg
;
5486 sals
.sals
= &pending_sal
;
5491 throw_exception (e
);
5498 /* Create a chain of things that always need to be cleaned up. */
5499 old_chain
= make_cleanup (null_cleanup
, 0);
5503 /* Make sure that all storage allocated to SALS gets freed. */
5504 make_cleanup (xfree
, sals
.sals
);
5506 /* Cleanup the addr_string array but not its contents. */
5507 make_cleanup (xfree
, addr_string
);
5510 /* ----------------------------- SNIP -----------------------------
5511 Anything added to the cleanup chain beyond this point is assumed
5512 to be part of a breakpoint. If the breakpoint create succeeds
5513 then the memory is not reclaimed. */
5514 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5516 /* Mark the contents of the addr_string for cleanup. These go on
5517 the breakpoint_chain and only occure if the breakpoint create
5519 for (i
= 0; i
< sals
.nelts
; i
++)
5521 if (addr_string
[i
] != NULL
)
5522 make_cleanup (xfree
, addr_string
[i
]);
5525 /* Resolve all line numbers to PC's and verify that the addresses
5526 are ok for the target. */
5528 breakpoint_sals_to_pc (&sals
, addr_start
);
5530 /* Verify that condition can be parsed, before setting any
5531 breakpoints. Allocate a separate condition expression for each
5535 if (parse_condition_and_thread
)
5537 /* Here we only parse 'arg' to separate condition
5538 from thread number, so parsing in context of first
5539 sal is OK. When setting the breakpoint we'll
5540 re-parse it in context of each sal. */
5543 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5545 make_cleanup (xfree
, cond_string
);
5549 /* Create a private copy of condition string. */
5552 cond_string
= xstrdup (cond_string
);
5553 make_cleanup (xfree
, cond_string
);
5556 create_breakpoints (sals
, addr_string
, cond_string
,
5557 hardwareflag
? bp_hardware_breakpoint
5559 tempflag
? disp_del
: disp_donttouch
,
5560 thread
, ignore_count
, ops
, from_tty
);
5564 struct symtab_and_line sal
= {0};
5565 struct breakpoint
*b
;
5567 make_cleanup (xfree
, copy_arg
);
5569 b
= set_raw_breakpoint_without_location (hardwareflag
5570 ? bp_hardware_breakpoint
5572 set_breakpoint_count (breakpoint_count
+ 1);
5573 b
->number
= breakpoint_count
;
5575 b
->addr_string
= addr_string
[0];
5576 b
->cond_string
= NULL
;
5577 b
->ignore_count
= ignore_count
;
5578 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5579 b
->condition_not_parsed
= 1;
5582 update_global_location_list (1);
5587 warning (_("Multiple breakpoints were set.\n"
5588 "Use the \"delete\" command to delete unwanted breakpoints."));
5589 /* That's it. Discard the cleanups for data inserted into the
5591 discard_cleanups (breakpoint_chain
);
5592 /* But cleanup everything else. */
5593 do_cleanups (old_chain
);
5596 /* Set a breakpoint.
5597 ARG is a string describing breakpoint address,
5598 condition, and thread.
5599 FLAG specifies if a breakpoint is hardware on,
5600 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5604 break_command_1 (char *arg
, int flag
, int from_tty
)
5606 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5607 int tempflag
= flag
& BP_TEMPFLAG
;
5609 break_command_really (arg
,
5610 NULL
, 0, 1 /* parse arg */,
5611 tempflag
, hardwareflag
,
5612 0 /* Ignore count */,
5613 pending_break_support
,
5614 NULL
/* breakpoint_ops */,
5620 set_breakpoint (char *address
, char *condition
,
5621 int hardwareflag
, int tempflag
,
5622 int thread
, int ignore_count
,
5625 break_command_really (address
, condition
, thread
,
5626 0 /* condition and thread are valid. */,
5627 tempflag
, hardwareflag
,
5630 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5634 /* Adjust SAL to the first instruction past the function prologue.
5635 The end of the prologue is determined using the line table from
5636 the debugging information.
5638 If SAL is already past the prologue, then do nothing. */
5641 skip_prologue_sal (struct symtab_and_line
*sal
)
5643 struct symbol
*sym
= find_pc_function (sal
->pc
);
5644 struct symtab_and_line start_sal
;
5649 start_sal
= find_function_start_sal (sym
, 1);
5650 if (sal
->pc
< start_sal
.pc
)
5654 /* Helper function for break_command_1 and disassemble_command. */
5657 resolve_sal_pc (struct symtab_and_line
*sal
)
5661 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5663 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5664 error (_("No line %d in file \"%s\"."),
5665 sal
->line
, sal
->symtab
->filename
);
5668 /* If this SAL corresponds to a breakpoint inserted using
5669 a line number, then skip the function prologue if necessary. */
5670 if (sal
->explicit_line
)
5671 skip_prologue_sal (sal
);
5674 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5676 struct blockvector
*bv
;
5680 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5683 sym
= block_linkage_function (b
);
5686 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5687 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5691 /* It really is worthwhile to have the section, so we'll just
5692 have to look harder. This case can be executed if we have
5693 line numbers but no functions (as can happen in assembly
5696 struct minimal_symbol
*msym
;
5698 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5700 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5707 break_command (char *arg
, int from_tty
)
5709 break_command_1 (arg
, 0, from_tty
);
5713 tbreak_command (char *arg
, int from_tty
)
5715 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5719 hbreak_command (char *arg
, int from_tty
)
5721 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5725 thbreak_command (char *arg
, int from_tty
)
5727 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5731 stop_command (char *arg
, int from_tty
)
5733 printf_filtered (_("Specify the type of breakpoint to set.\n\
5734 Usage: stop in <function | address>\n\
5735 stop at <line>\n"));
5739 stopin_command (char *arg
, int from_tty
)
5743 if (arg
== (char *) NULL
)
5745 else if (*arg
!= '*')
5750 /* look for a ':'. If this is a line number specification, then
5751 say it is bad, otherwise, it should be an address or
5752 function/method name */
5753 while (*argptr
&& !hasColon
)
5755 hasColon
= (*argptr
== ':');
5760 badInput
= (*argptr
!= ':'); /* Not a class::method */
5762 badInput
= isdigit (*arg
); /* a simple line number */
5766 printf_filtered (_("Usage: stop in <function | address>\n"));
5768 break_command_1 (arg
, 0, from_tty
);
5772 stopat_command (char *arg
, int from_tty
)
5776 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5783 /* look for a ':'. If there is a '::' then get out, otherwise
5784 it is probably a line number. */
5785 while (*argptr
&& !hasColon
)
5787 hasColon
= (*argptr
== ':');
5792 badInput
= (*argptr
== ':'); /* we have class::method */
5794 badInput
= !isdigit (*arg
); /* not a line number */
5798 printf_filtered (_("Usage: stop at <line>\n"));
5800 break_command_1 (arg
, 0, from_tty
);
5803 /* accessflag: hw_write: watch write,
5804 hw_read: watch read,
5805 hw_access: watch access (read or write) */
5807 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5809 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5810 struct symtab_and_line sal
;
5811 struct expression
*exp
;
5812 struct block
*exp_valid_block
;
5813 struct value
*val
, *mark
;
5814 struct frame_info
*frame
;
5815 struct frame_info
*prev_frame
= NULL
;
5816 char *exp_start
= NULL
;
5817 char *exp_end
= NULL
;
5818 char *tok
, *id_tok_start
, *end_tok
;
5820 char *cond_start
= NULL
;
5821 char *cond_end
= NULL
;
5822 struct expression
*cond
= NULL
;
5823 int i
, other_type_used
, target_resources_ok
= 0;
5824 enum bptype bp_type
;
5828 init_sal (&sal
); /* initialize to zeroes */
5830 /* Make sure that we actually have parameters to parse. */
5831 if (arg
!= NULL
&& arg
[0] != '\0')
5833 toklen
= strlen (arg
); /* Size of argument list. */
5835 /* Points tok to the end of the argument list. */
5836 tok
= arg
+ toklen
- 1;
5838 /* Go backwards in the parameters list. Skip the last parameter.
5839 If we're expecting a 'thread <thread_num>' parameter, this should
5840 be the thread identifier. */
5841 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5843 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5846 /* Points end_tok to the beginning of the last token. */
5847 id_tok_start
= tok
+ 1;
5849 /* Go backwards in the parameters list. Skip one more parameter.
5850 If we're expecting a 'thread <thread_num>' parameter, we should
5851 reach a "thread" token. */
5852 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5857 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5860 /* Move the pointer forward to skip the whitespace and
5861 calculate the length of the token. */
5863 toklen
= end_tok
- tok
;
5865 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5867 /* At this point we've found a "thread" token, which means
5868 the user is trying to set a watchpoint that triggers
5869 only in a specific thread. */
5872 /* Extract the thread ID from the next token. */
5873 thread
= strtol (id_tok_start
, &endp
, 0);
5875 /* Check if the user provided a valid numeric value for the
5877 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5878 error (_("Invalid thread ID specification %s."), id_tok_start
);
5880 /* Check if the thread actually exists. */
5881 if (!valid_thread_id (thread
))
5882 error (_("Unknown thread %d."), thread
);
5884 /* Truncate the string and get rid of the thread <thread_num>
5885 parameter before the parameter list is parsed by the
5886 evaluate_expression() function. */
5891 /* Parse the rest of the arguments. */
5892 innermost_block
= NULL
;
5894 exp
= parse_exp_1 (&arg
, 0, 0);
5896 exp_valid_block
= innermost_block
;
5897 mark
= value_mark ();
5898 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5900 release_value (val
);
5903 while (*tok
== ' ' || *tok
== '\t')
5907 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5910 toklen
= end_tok
- tok
;
5911 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5913 tok
= cond_start
= end_tok
+ 1;
5914 cond
= parse_exp_1 (&tok
, 0, 0);
5918 error (_("Junk at end of command."));
5920 if (accessflag
== hw_read
)
5921 bp_type
= bp_read_watchpoint
;
5922 else if (accessflag
== hw_access
)
5923 bp_type
= bp_access_watchpoint
;
5925 bp_type
= bp_hardware_watchpoint
;
5927 mem_cnt
= can_use_hardware_watchpoint (val
);
5928 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5929 error (_("Expression cannot be implemented with read/access watchpoint."));
5932 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5933 target_resources_ok
=
5934 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5936 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5937 error (_("Target does not support this type of hardware watchpoint."));
5939 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5940 error (_("Target can only support one kind of HW watchpoint at a time."));
5943 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5944 watchpoint could not be set. */
5945 if (!mem_cnt
|| target_resources_ok
<= 0)
5946 bp_type
= bp_watchpoint
;
5948 frame
= block_innermost_frame (exp_valid_block
);
5950 prev_frame
= get_prev_frame (frame
);
5954 /* If the expression is "local", then set up a "watchpoint scope"
5955 breakpoint at the point where we've left the scope of the watchpoint
5956 expression. Create the scope breakpoint before the watchpoint, so
5957 that we will encounter it first in bpstat_stop_status. */
5958 if (innermost_block
&& prev_frame
)
5960 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5961 bp_watchpoint_scope
);
5963 scope_breakpoint
->enable_state
= bp_enabled
;
5965 /* Automatically delete the breakpoint when it hits. */
5966 scope_breakpoint
->disposition
= disp_del
;
5968 /* Only break in the proper frame (help with recursion). */
5969 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5971 /* Set the address at which we will stop. */
5972 scope_breakpoint
->loc
->requested_address
5973 = get_frame_pc (prev_frame
);
5974 scope_breakpoint
->loc
->address
5975 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5976 scope_breakpoint
->type
);
5979 /* Now set up the breakpoint. */
5980 b
= set_raw_breakpoint (sal
, bp_type
);
5981 set_breakpoint_count (breakpoint_count
+ 1);
5982 b
->number
= breakpoint_count
;
5984 b
->disposition
= disp_donttouch
;
5986 b
->exp_valid_block
= exp_valid_block
;
5987 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5990 b
->loc
->cond
= cond
;
5992 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5997 b
->watchpoint_frame
= get_frame_id (frame
);
5999 b
->watchpoint_frame
= null_frame_id
;
6001 if (scope_breakpoint
!= NULL
)
6003 /* The scope breakpoint is related to the watchpoint. We will
6004 need to act on them together. */
6005 b
->related_breakpoint
= scope_breakpoint
;
6006 scope_breakpoint
->related_breakpoint
= b
;
6009 value_free_to_mark (mark
);
6011 update_global_location_list (1);
6014 /* Return count of locations need to be watched and can be handled
6015 in hardware. If the watchpoint can not be handled
6016 in hardware return zero. */
6019 can_use_hardware_watchpoint (struct value
*v
)
6021 int found_memory_cnt
= 0;
6022 struct value
*head
= v
;
6024 /* Did the user specifically forbid us to use hardware watchpoints? */
6025 if (!can_use_hw_watchpoints
)
6028 /* Make sure that the value of the expression depends only upon
6029 memory contents, and values computed from them within GDB. If we
6030 find any register references or function calls, we can't use a
6031 hardware watchpoint.
6033 The idea here is that evaluating an expression generates a series
6034 of values, one holding the value of every subexpression. (The
6035 expression a*b+c has five subexpressions: a, b, a*b, c, and
6036 a*b+c.) GDB's values hold almost enough information to establish
6037 the criteria given above --- they identify memory lvalues,
6038 register lvalues, computed values, etcetera. So we can evaluate
6039 the expression, and then scan the chain of values that leaves
6040 behind to decide whether we can detect any possible change to the
6041 expression's final value using only hardware watchpoints.
6043 However, I don't think that the values returned by inferior
6044 function calls are special in any way. So this function may not
6045 notice that an expression involving an inferior function call
6046 can't be watched with hardware watchpoints. FIXME. */
6047 for (; v
; v
= value_next (v
))
6049 if (VALUE_LVAL (v
) == lval_memory
)
6052 /* A lazy memory lvalue is one that GDB never needed to fetch;
6053 we either just used its address (e.g., `a' in `a.b') or
6054 we never needed it at all (e.g., `a' in `a,b'). */
6058 /* Ahh, memory we actually used! Check if we can cover
6059 it with hardware watchpoints. */
6060 struct type
*vtype
= check_typedef (value_type (v
));
6062 /* We only watch structs and arrays if user asked for it
6063 explicitly, never if they just happen to appear in a
6064 middle of some value chain. */
6066 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6067 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6069 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6070 int len
= TYPE_LENGTH (value_type (v
));
6072 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6079 else if (VALUE_LVAL (v
) != not_lval
6080 && deprecated_value_modifiable (v
) == 0)
6081 return 0; /* ??? What does this represent? */
6082 else if (VALUE_LVAL (v
) == lval_register
)
6083 return 0; /* cannot watch a register with a HW watchpoint */
6086 /* The expression itself looks suitable for using a hardware
6087 watchpoint, but give the target machine a chance to reject it. */
6088 return found_memory_cnt
;
6092 watch_command_wrapper (char *arg
, int from_tty
)
6094 watch_command (arg
, from_tty
);
6098 watch_command (char *arg
, int from_tty
)
6100 watch_command_1 (arg
, hw_write
, from_tty
);
6104 rwatch_command_wrapper (char *arg
, int from_tty
)
6106 rwatch_command (arg
, from_tty
);
6110 rwatch_command (char *arg
, int from_tty
)
6112 watch_command_1 (arg
, hw_read
, from_tty
);
6116 awatch_command_wrapper (char *arg
, int from_tty
)
6118 awatch_command (arg
, from_tty
);
6122 awatch_command (char *arg
, int from_tty
)
6124 watch_command_1 (arg
, hw_access
, from_tty
);
6128 /* Helper routines for the until_command routine in infcmd.c. Here
6129 because it uses the mechanisms of breakpoints. */
6131 struct until_break_command_continuation_args
6133 struct breakpoint
*breakpoint
;
6134 struct breakpoint
*breakpoint2
;
6137 /* This function is called by fetch_inferior_event via the
6138 cmd_continuation pointer, to complete the until command. It takes
6139 care of cleaning up the temporary breakpoints set up by the until
6142 until_break_command_continuation (void *arg
)
6144 struct until_break_command_continuation_args
*a
= arg
;
6146 delete_breakpoint (a
->breakpoint
);
6148 delete_breakpoint (a
->breakpoint2
);
6152 until_break_command (char *arg
, int from_tty
, int anywhere
)
6154 struct symtabs_and_lines sals
;
6155 struct symtab_and_line sal
;
6156 struct frame_info
*frame
= get_selected_frame (NULL
);
6157 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6158 struct breakpoint
*breakpoint
;
6159 struct breakpoint
*breakpoint2
= NULL
;
6160 struct cleanup
*old_chain
;
6162 clear_proceed_status ();
6164 /* Set a breakpoint where the user wants it and at return from
6167 if (default_breakpoint_valid
)
6168 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6169 default_breakpoint_line
, (char ***) NULL
, NULL
);
6171 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6172 0, (char ***) NULL
, NULL
);
6174 if (sals
.nelts
!= 1)
6175 error (_("Couldn't get information on specified line."));
6178 xfree (sals
.sals
); /* malloc'd, so freed */
6181 error (_("Junk at end of arguments."));
6183 resolve_sal_pc (&sal
);
6186 /* If the user told us to continue until a specified location,
6187 we don't specify a frame at which we need to stop. */
6188 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6190 /* Otherwise, specify the current frame, because we want to stop only
6191 at the very same frame. */
6192 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6195 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6197 /* Keep within the current frame, or in frames called by the current
6201 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6202 sal
.pc
= get_frame_pc (prev_frame
);
6203 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6205 make_cleanup_delete_breakpoint (breakpoint2
);
6208 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6210 /* If we are running asynchronously, and proceed call above has actually
6211 managed to start the target, arrange for breakpoints to be
6212 deleted when the target stops. Otherwise, we're already stopped and
6213 delete breakpoints via cleanup chain. */
6215 if (target_can_async_p () && is_running (inferior_ptid
))
6217 struct until_break_command_continuation_args
*args
;
6218 args
= xmalloc (sizeof (*args
));
6220 args
->breakpoint
= breakpoint
;
6221 args
->breakpoint2
= breakpoint2
;
6223 discard_cleanups (old_chain
);
6224 add_continuation (inferior_thread (),
6225 until_break_command_continuation
, args
,
6229 do_cleanups (old_chain
);
6233 ep_skip_leading_whitespace (char **s
)
6235 if ((s
== NULL
) || (*s
== NULL
))
6237 while (isspace (**s
))
6241 /* This function attempts to parse an optional "if <cond>" clause
6242 from the arg string. If one is not found, it returns NULL.
6244 Else, it returns a pointer to the condition string. (It does not
6245 attempt to evaluate the string against a particular block.) And,
6246 it updates arg to point to the first character following the parsed
6247 if clause in the arg string. */
6250 ep_parse_optional_if_clause (char **arg
)
6254 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6257 /* Skip the "if" keyword. */
6260 /* Skip any extra leading whitespace, and record the start of the
6261 condition string. */
6262 ep_skip_leading_whitespace (arg
);
6265 /* Assume that the condition occupies the remainder of the arg string. */
6266 (*arg
) += strlen (cond_string
);
6271 /* This function attempts to parse an optional filename from the arg
6272 string. If one is not found, it returns NULL.
6274 Else, it returns a pointer to the parsed filename. (This function
6275 makes no attempt to verify that a file of that name exists, or is
6276 accessible.) And, it updates arg to point to the first character
6277 following the parsed filename in the arg string.
6279 Note that clients needing to preserve the returned filename for
6280 future access should copy it to their own buffers. */
6282 ep_parse_optional_filename (char **arg
)
6284 static char filename
[1024];
6289 if ((*arg_p
== '\0') || isspace (*arg_p
))
6307 /* Commands to deal with catching events, such as signals, exceptions,
6308 process start/exit, etc. */
6312 catch_fork_temporary
, catch_vfork_temporary
,
6313 catch_fork_permanent
, catch_vfork_permanent
6318 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6320 char *cond_string
= NULL
;
6321 catch_fork_kind fork_kind
;
6324 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6325 tempflag
= (fork_kind
== catch_fork_temporary
6326 || fork_kind
== catch_vfork_temporary
);
6330 ep_skip_leading_whitespace (&arg
);
6332 /* The allowed syntax is:
6334 catch [v]fork if <cond>
6336 First, check if there's an if clause. */
6337 cond_string
= ep_parse_optional_if_clause (&arg
);
6339 if ((*arg
!= '\0') && !isspace (*arg
))
6340 error (_("Junk at end of arguments."));
6342 /* If this target supports it, create a fork or vfork catchpoint
6343 and enable reporting of such events. */
6346 case catch_fork_temporary
:
6347 case catch_fork_permanent
:
6348 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6349 &catch_fork_breakpoint_ops
);
6351 case catch_vfork_temporary
:
6352 case catch_vfork_permanent
:
6353 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6354 &catch_vfork_breakpoint_ops
);
6357 error (_("unsupported or unknown fork kind; cannot catch it"));
6363 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6366 char *cond_string
= NULL
;
6368 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6372 ep_skip_leading_whitespace (&arg
);
6374 /* The allowed syntax is:
6376 catch exec if <cond>
6378 First, check if there's an if clause. */
6379 cond_string
= ep_parse_optional_if_clause (&arg
);
6381 if ((*arg
!= '\0') && !isspace (*arg
))
6382 error (_("Junk at end of arguments."));
6384 /* If this target supports it, create an exec catchpoint
6385 and enable reporting of such events. */
6386 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6389 static enum print_stop_action
6390 print_exception_catchpoint (struct breakpoint
*b
)
6392 int bp_temp
, bp_throw
;
6394 annotate_catchpoint (b
->number
);
6396 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6397 if (b
->loc
->address
!= b
->loc
->requested_address
)
6398 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6401 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6403 bp_temp
? "Temporary catchpoint "
6405 if (!ui_out_is_mi_like_p (uiout
))
6406 ui_out_field_int (uiout
, "bkptno", b
->number
);
6408 bp_throw
? " (exception thrown), "
6409 : " (exception caught), ");
6410 if (ui_out_is_mi_like_p (uiout
))
6412 ui_out_field_string (uiout
, "reason",
6413 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6414 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6415 ui_out_field_int (uiout
, "bkptno", b
->number
);
6417 return PRINT_SRC_AND_LOC
;
6421 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6423 struct value_print_options opts
;
6424 get_user_print_options (&opts
);
6425 if (opts
.addressprint
)
6428 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6429 ui_out_field_string (uiout
, "addr", "<PENDING>");
6431 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6435 *last_addr
= b
->loc
->address
;
6436 if (strstr (b
->addr_string
, "throw") != NULL
)
6437 ui_out_field_string (uiout
, "what", "exception throw");
6439 ui_out_field_string (uiout
, "what", "exception catch");
6443 print_mention_exception_catchpoint (struct breakpoint
*b
)
6448 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6449 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6450 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6451 : _("Catchpoint "));
6452 ui_out_field_int (uiout
, "bkptno", b
->number
);
6453 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6457 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6460 NULL
, /* breakpoint_hit */
6461 print_exception_catchpoint
,
6462 print_one_exception_catchpoint
,
6463 print_mention_exception_catchpoint
6467 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6468 enum exception_event_kind ex_event
, int from_tty
)
6470 char *trigger_func_name
;
6472 if (ex_event
== EX_EVENT_CATCH
)
6473 trigger_func_name
= "__cxa_begin_catch";
6475 trigger_func_name
= "__cxa_throw";
6477 break_command_really (trigger_func_name
, cond_string
, -1,
6478 0 /* condition and thread are valid. */,
6481 AUTO_BOOLEAN_TRUE
/* pending */,
6482 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6487 /* Deal with "catch catch" and "catch throw" commands */
6490 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6491 int tempflag
, int from_tty
)
6493 char *cond_string
= NULL
;
6494 struct symtab_and_line
*sal
= NULL
;
6498 ep_skip_leading_whitespace (&arg
);
6500 cond_string
= ep_parse_optional_if_clause (&arg
);
6502 if ((*arg
!= '\0') && !isspace (*arg
))
6503 error (_("Junk at end of arguments."));
6505 if ((ex_event
!= EX_EVENT_THROW
) &&
6506 (ex_event
!= EX_EVENT_CATCH
))
6507 error (_("Unsupported or unknown exception event; cannot catch it"));
6509 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6512 warning (_("Unsupported with this platform/compiler combination."));
6515 /* Implementation of "catch catch" command. */
6518 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6520 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6521 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6524 /* Implementation of "catch throw" command. */
6527 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6529 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6530 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6533 /* Create a breakpoint struct for Ada exception catchpoints. */
6536 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6540 struct expression
*cond
,
6541 struct breakpoint_ops
*ops
,
6545 struct breakpoint
*b
;
6549 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6550 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6551 version for exception catchpoints, because two catchpoints
6552 used for different exception names will use the same address.
6553 In this case, a "breakpoint ... also set at..." warning is
6554 unproductive. Besides. the warning phrasing is also a bit
6555 inapropriate, we should use the word catchpoint, and tell
6556 the user what type of catchpoint it is. The above is good
6557 enough for now, though. */
6560 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6561 set_breakpoint_count (breakpoint_count
+ 1);
6563 b
->enable_state
= bp_enabled
;
6564 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6565 b
->number
= breakpoint_count
;
6566 b
->ignore_count
= 0;
6567 b
->loc
->cond
= cond
;
6568 b
->addr_string
= addr_string
;
6569 b
->language
= language_ada
;
6570 b
->cond_string
= cond_string
;
6571 b
->exp_string
= exp_string
;
6576 update_global_location_list (1);
6579 /* Implement the "catch exception" command. */
6582 catch_ada_exception_command (char *arg
, int from_tty
,
6583 struct cmd_list_element
*command
)
6586 struct symtab_and_line sal
;
6588 char *addr_string
= NULL
;
6589 char *exp_string
= NULL
;
6590 char *cond_string
= NULL
;
6591 struct expression
*cond
= NULL
;
6592 struct breakpoint_ops
*ops
= NULL
;
6594 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6598 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6599 &cond_string
, &cond
, &ops
);
6600 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6601 cond_string
, cond
, ops
, tempflag
,
6605 /* Implement the "catch assert" command. */
6608 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6611 struct symtab_and_line sal
;
6612 char *addr_string
= NULL
;
6613 struct breakpoint_ops
*ops
= NULL
;
6615 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6619 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6620 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6621 tempflag
, from_tty
);
6625 catch_command (char *arg
, int from_tty
)
6627 error (_("Catch requires an event name."));
6632 tcatch_command (char *arg
, int from_tty
)
6634 error (_("Catch requires an event name."));
6637 /* Delete breakpoints by address or line. */
6640 clear_command (char *arg
, int from_tty
)
6642 struct breakpoint
*b
;
6643 VEC(breakpoint_p
) *found
= 0;
6646 struct symtabs_and_lines sals
;
6647 struct symtab_and_line sal
;
6652 sals
= decode_line_spec (arg
, 1);
6657 sals
.sals
= (struct symtab_and_line
*)
6658 xmalloc (sizeof (struct symtab_and_line
));
6659 make_cleanup (xfree
, sals
.sals
);
6660 init_sal (&sal
); /* initialize to zeroes */
6661 sal
.line
= default_breakpoint_line
;
6662 sal
.symtab
= default_breakpoint_symtab
;
6663 sal
.pc
= default_breakpoint_address
;
6664 if (sal
.symtab
== 0)
6665 error (_("No source file specified."));
6673 /* We don't call resolve_sal_pc here. That's not
6674 as bad as it seems, because all existing breakpoints
6675 typically have both file/line and pc set. So, if
6676 clear is given file/line, we can match this to existing
6677 breakpoint without obtaining pc at all.
6679 We only support clearing given the address explicitly
6680 present in breakpoint table. Say, we've set breakpoint
6681 at file:line. There were several PC values for that file:line,
6682 due to optimization, all in one block.
6683 We've picked one PC value. If "clear" is issued with another
6684 PC corresponding to the same file:line, the breakpoint won't
6685 be cleared. We probably can still clear the breakpoint, but
6686 since the other PC value is never presented to user, user
6687 can only find it by guessing, and it does not seem important
6690 /* For each line spec given, delete bps which correspond
6691 to it. Do it in two passes, solely to preserve the current
6692 behavior that from_tty is forced true if we delete more than
6696 for (i
= 0; i
< sals
.nelts
; i
++)
6698 /* If exact pc given, clear bpts at that pc.
6699 If line given (pc == 0), clear all bpts on specified line.
6700 If defaulting, clear all bpts on default line
6703 defaulting sal.pc != 0 tests to do
6708 1 0 <can't happen> */
6712 /* Find all matching breakpoints and add them to
6717 /* Are we going to delete b? */
6718 if (b
->type
!= bp_none
6719 && b
->type
!= bp_watchpoint
6720 && b
->type
!= bp_hardware_watchpoint
6721 && b
->type
!= bp_read_watchpoint
6722 && b
->type
!= bp_access_watchpoint
)
6724 struct bp_location
*loc
= b
->loc
;
6725 for (; loc
; loc
= loc
->next
)
6727 int pc_match
= sal
.pc
6728 && (loc
->address
== sal
.pc
)
6729 && (!section_is_overlay (loc
->section
)
6730 || loc
->section
== sal
.section
);
6731 int line_match
= ((default_match
|| (0 == sal
.pc
))
6732 && b
->source_file
!= NULL
6733 && sal
.symtab
!= NULL
6734 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6735 && b
->line_number
== sal
.line
);
6736 if (pc_match
|| line_match
)
6745 VEC_safe_push(breakpoint_p
, found
, b
);
6748 /* Now go thru the 'found' chain and delete them. */
6749 if (VEC_empty(breakpoint_p
, found
))
6752 error (_("No breakpoint at %s."), arg
);
6754 error (_("No breakpoint at this line."));
6757 if (VEC_length(breakpoint_p
, found
) > 1)
6758 from_tty
= 1; /* Always report if deleted more than one */
6761 if (VEC_length(breakpoint_p
, found
) == 1)
6762 printf_unfiltered (_("Deleted breakpoint "));
6764 printf_unfiltered (_("Deleted breakpoints "));
6766 breakpoints_changed ();
6768 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6771 printf_unfiltered ("%d ", b
->number
);
6772 delete_breakpoint (b
);
6775 putchar_unfiltered ('\n');
6778 /* Delete breakpoint in BS if they are `delete' breakpoints and
6779 all breakpoints that are marked for deletion, whether hit or not.
6780 This is called after any breakpoint is hit, or after errors. */
6783 breakpoint_auto_delete (bpstat bs
)
6785 struct breakpoint
*b
, *temp
;
6787 for (; bs
; bs
= bs
->next
)
6788 if (bs
->breakpoint_at
6789 && bs
->breakpoint_at
->owner
6790 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6792 delete_breakpoint (bs
->breakpoint_at
->owner
);
6794 ALL_BREAKPOINTS_SAFE (b
, temp
)
6796 if (b
->disposition
== disp_del_at_next_stop
)
6797 delete_breakpoint (b
);
6801 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
6802 into the inferior, only remove already-inserted locations that no
6803 longer should be inserted. Functions that delete a breakpoint or
6804 breakpoints should pass false, so that deleting a breakpoint
6805 doesn't have the side effect of inserting the locations of other
6806 breakpoints that are marked not-inserted, but should_be_inserted
6807 returns true on them.
6809 This behaviour is useful is situations close to tear-down -- e.g.,
6810 after an exec, while the target still has execution, but breakpoint
6811 shadows of the previous executable image should *NOT* be restored
6812 to the new image; or before detaching, where the target still has
6813 execution and wants to delete breakpoints from GDB's lists, and all
6814 breakpoints had already been removed from the inferior. */
6817 update_global_location_list (int should_insert
)
6819 struct breakpoint
*b
;
6820 struct bp_location
**next
= &bp_location_chain
;
6821 struct bp_location
*loc
;
6822 struct bp_location
*loc2
;
6823 struct gdb_exception e
;
6824 VEC(bp_location_p
) *old_locations
= NULL
;
6828 /* Store old locations for future reference. */
6829 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6830 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6832 bp_location_chain
= NULL
;
6835 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6838 next
= &(loc
->global_next
);
6843 /* Identify bp_location instances that are no longer present in the new
6844 list, and therefore should be freed. Note that it's not necessary that
6845 those locations should be removed from inferior -- if there's another
6846 location at the same address (previously marked as duplicate),
6847 we don't need to remove/insert the location. */
6848 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6850 /* Tells if 'loc' is found amoung the new locations. If not, we
6852 int found_object
= 0;
6853 /* Tells if the location should remain inserted in the target. */
6854 int keep_in_target
= 0;
6856 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6863 /* If this location is no longer present, and inserted, look if there's
6864 maybe a new location at the same address. If so, mark that one
6865 inserted, and don't remove this one. This is needed so that we
6866 don't have a time window where a breakpoint at certain location is not
6871 /* If the location is inserted now, we might have to remove it. */
6873 if (found_object
&& should_be_inserted (loc
))
6875 /* The location is still present in the location list, and still
6876 should be inserted. Don't do anything. */
6881 /* The location is either no longer present, or got disabled.
6882 See if there's another location at the same address, in which
6883 case we don't need to remove this one from the target. */
6884 if (breakpoint_address_is_meaningful (loc
->owner
))
6885 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6887 /* For the sake of should_insert_location. The
6888 call to check_duplicates will fix up this later. */
6889 loc2
->duplicate
= 0;
6890 if (should_be_inserted (loc2
)
6891 && loc2
!= loc
&& loc2
->address
== loc
->address
)
6894 loc2
->target_info
= loc
->target_info
;
6901 if (!keep_in_target
)
6903 if (remove_breakpoint (loc
, mark_uninserted
))
6905 /* This is just about all we can do. We could keep this
6906 location on the global list, and try to remove it next
6907 time, but there's no particular reason why we will
6910 Note that at this point, loc->owner is still valid,
6911 as delete_breakpoint frees the breakpoint only
6912 after calling us. */
6913 printf_filtered (_("warning: Error removing breakpoint %d\n"),
6914 loc
->owner
->number
);
6922 if (removed
&& non_stop
)
6924 /* This location was removed from the targets. In non-stop mode,
6925 a race condition is possible where we've removed a breakpoint,
6926 but stop events for that breakpoint are already queued and will
6927 arrive later. To suppress spurious SIGTRAPs reported to user,
6928 we keep this breakpoint location for a bit, and will retire it
6929 after we see 3 * thread_count events.
6930 The theory here is that reporting of events should,
6931 "on the average", be fair, so after that many event we'll see
6932 events from all threads that have anything of interest, and no
6933 longer need to keep this breakpoint. This is just a
6934 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
6935 which is usability issue, but not a correctness problem. */
6936 loc
->events_till_retirement
= 3 * (thread_count () + 1);
6939 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
6942 free_bp_location (loc
);
6948 check_duplicates (b
);
6951 if (breakpoints_always_inserted_mode () && should_insert
6952 && (target_has_execution
6953 || (gdbarch_has_global_solist (target_gdbarch
)
6954 && target_supports_multi_process ())))
6955 insert_breakpoint_locations ();
6959 breakpoint_retire_moribund (void)
6961 struct bp_location
*loc
;
6964 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
6965 if (--(loc
->events_till_retirement
) == 0)
6967 free_bp_location (loc
);
6968 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
6974 update_global_location_list_nothrow (int inserting
)
6976 struct gdb_exception e
;
6977 TRY_CATCH (e
, RETURN_MASK_ERROR
)
6978 update_global_location_list (inserting
);
6981 /* Clear BPT from a BPS. */
6983 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
6986 for (bs
= bps
; bs
; bs
= bs
->next
)
6987 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
6989 bs
->breakpoint_at
= NULL
;
6991 /* bs->commands will be freed later. */
6995 /* Callback for iterate_over_threads. */
6997 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
6999 struct breakpoint
*bpt
= data
;
7000 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7004 /* Delete a breakpoint and clean up all traces of it in the data
7008 delete_breakpoint (struct breakpoint
*bpt
)
7010 struct breakpoint
*b
;
7011 struct bp_location
*loc
, *next
;
7013 gdb_assert (bpt
!= NULL
);
7015 /* Has this bp already been deleted? This can happen because multiple
7016 lists can hold pointers to bp's. bpstat lists are especial culprits.
7018 One example of this happening is a watchpoint's scope bp. When the
7019 scope bp triggers, we notice that the watchpoint is out of scope, and
7020 delete it. We also delete its scope bp. But the scope bp is marked
7021 "auto-deleting", and is already on a bpstat. That bpstat is then
7022 checked for auto-deleting bp's, which are deleted.
7024 A real solution to this problem might involve reference counts in bp's,
7025 and/or giving them pointers back to their referencing bpstat's, and
7026 teaching delete_breakpoint to only free a bp's storage when no more
7027 references were extent. A cheaper bandaid was chosen. */
7028 if (bpt
->type
== bp_none
)
7031 observer_notify_breakpoint_deleted (bpt
->number
);
7033 if (breakpoint_chain
== bpt
)
7034 breakpoint_chain
= bpt
->next
;
7039 b
->next
= bpt
->next
;
7043 free_command_lines (&bpt
->commands
);
7044 if (bpt
->cond_string
!= NULL
)
7045 xfree (bpt
->cond_string
);
7046 if (bpt
->addr_string
!= NULL
)
7047 xfree (bpt
->addr_string
);
7048 if (bpt
->exp
!= NULL
)
7050 if (bpt
->exp_string
!= NULL
)
7051 xfree (bpt
->exp_string
);
7052 if (bpt
->val
!= NULL
)
7053 value_free (bpt
->val
);
7054 if (bpt
->source_file
!= NULL
)
7055 xfree (bpt
->source_file
);
7056 if (bpt
->exec_pathname
!= NULL
)
7057 xfree (bpt
->exec_pathname
);
7059 /* Be sure no bpstat's are pointing at it after it's been freed. */
7060 /* FIXME, how can we find all bpstat's?
7061 We just check stop_bpstat for now. Note that we cannot just
7062 remove bpstats pointing at bpt from the stop_bpstat list
7063 entirely, as breakpoint commands are associated with the bpstat;
7064 if we remove it here, then the later call to
7065 bpstat_do_actions (&stop_bpstat);
7066 in event-top.c won't do anything, and temporary breakpoints
7067 with commands won't work. */
7069 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7071 /* Now that breakpoint is removed from breakpoint
7072 list, update the global location list. This
7073 will remove locations that used to belong to
7074 this breakpoint. Do this before freeing
7075 the breakpoint itself, since remove_breakpoint
7076 looks at location's owner. It might be better
7077 design to have location completely self-contained,
7078 but it's not the case now. */
7079 update_global_location_list (0);
7082 /* On the chance that someone will soon try again to delete this same
7083 bp, we mark it as deleted before freeing its storage. */
7084 bpt
->type
= bp_none
;
7090 do_delete_breakpoint_cleanup (void *b
)
7092 delete_breakpoint (b
);
7096 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7098 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7102 delete_command (char *arg
, int from_tty
)
7104 struct breakpoint
*b
, *temp
;
7110 int breaks_to_delete
= 0;
7112 /* Delete all breakpoints if no argument.
7113 Do not delete internal or call-dummy breakpoints, these
7114 have to be deleted with an explicit breakpoint number argument. */
7117 if (b
->type
!= bp_call_dummy
&&
7118 b
->type
!= bp_shlib_event
&&
7119 b
->type
!= bp_thread_event
&&
7120 b
->type
!= bp_overlay_event
&&
7123 breaks_to_delete
= 1;
7128 /* Ask user only if there are some breakpoints to delete. */
7130 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7132 ALL_BREAKPOINTS_SAFE (b
, temp
)
7134 if (b
->type
!= bp_call_dummy
&&
7135 b
->type
!= bp_shlib_event
&&
7136 b
->type
!= bp_thread_event
&&
7137 b
->type
!= bp_overlay_event
&&
7139 delete_breakpoint (b
);
7144 map_breakpoint_numbers (arg
, delete_breakpoint
);
7148 all_locations_are_pending (struct bp_location
*loc
)
7150 for (; loc
; loc
= loc
->next
)
7151 if (!loc
->shlib_disabled
)
7156 /* Subroutine of update_breakpoint_locations to simplify it.
7157 Return non-zero if multiple fns in list LOC have the same name.
7158 Null names are ignored. */
7161 ambiguous_names_p (struct bp_location
*loc
)
7163 struct bp_location
*l
;
7164 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7165 (int (*) (const void *, const void *)) streq
,
7166 NULL
, xcalloc
, xfree
);
7168 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7171 const char *name
= l
->function_name
;
7173 /* Allow for some names to be NULL, ignore them. */
7177 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7179 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7194 update_breakpoint_locations (struct breakpoint
*b
,
7195 struct symtabs_and_lines sals
)
7199 struct bp_location
*existing_locations
= b
->loc
;
7201 /* If there's no new locations, and all existing locations
7202 are pending, don't do anything. This optimizes
7203 the common case where all locations are in the same
7204 shared library, that was unloaded. We'd like to
7205 retain the location, so that when the library
7206 is loaded again, we don't loose the enabled/disabled
7207 status of the individual locations. */
7208 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7213 for (i
= 0; i
< sals
.nelts
; ++i
)
7215 struct bp_location
*new_loc
=
7216 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7218 /* Reparse conditions, they might contain references to the
7220 if (b
->cond_string
!= NULL
)
7222 struct gdb_exception e
;
7225 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7227 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7232 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7233 b
->number
, e
.message
);
7234 new_loc
->enabled
= 0;
7238 if (b
->source_file
!= NULL
)
7239 xfree (b
->source_file
);
7240 if (sals
.sals
[i
].symtab
== NULL
)
7241 b
->source_file
= NULL
;
7244 savestring (sals
.sals
[i
].symtab
->filename
,
7245 strlen (sals
.sals
[i
].symtab
->filename
));
7247 if (b
->line_number
== 0)
7248 b
->line_number
= sals
.sals
[i
].line
;
7251 /* Update locations of permanent breakpoints. */
7252 if (b
->enable_state
== bp_permanent
)
7253 make_breakpoint_permanent (b
);
7255 /* If possible, carry over 'disable' status from existing breakpoints. */
7257 struct bp_location
*e
= existing_locations
;
7258 /* If there are multiple breakpoints with the same function name,
7259 e.g. for inline functions, comparing function names won't work.
7260 Instead compare pc addresses; this is just a heuristic as things
7261 may have moved, but in practice it gives the correct answer
7262 often enough until a better solution is found. */
7263 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7265 for (; e
; e
= e
->next
)
7267 if (!e
->enabled
&& e
->function_name
)
7269 struct bp_location
*l
= b
->loc
;
7270 if (have_ambiguous_names
)
7272 for (; l
; l
= l
->next
)
7273 if (e
->address
== l
->address
)
7281 for (; l
; l
= l
->next
)
7282 if (l
->function_name
7283 && strcmp (e
->function_name
, l
->function_name
) == 0)
7293 update_global_location_list (1);
7297 /* Reset a breakpoint given it's struct breakpoint * BINT.
7298 The value we return ends up being the return value from catch_errors.
7299 Unused in this case. */
7302 breakpoint_re_set_one (void *bint
)
7304 /* get past catch_errs */
7305 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7309 int *not_found_ptr
= ¬_found
;
7310 struct symtabs_and_lines sals
= {};
7311 struct symtabs_and_lines expanded
;
7313 enum enable_state save_enable
;
7314 struct gdb_exception e
;
7320 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7324 case bp_hardware_breakpoint
:
7325 if (b
->addr_string
== NULL
)
7327 /* Anything without a string can't be re-set. */
7328 delete_breakpoint (b
);
7332 set_language (b
->language
);
7333 input_radix
= b
->input_radix
;
7335 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7337 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7342 int not_found_and_ok
= 0;
7343 /* For pending breakpoints, it's expected that parsing
7344 will fail until the right shared library is loaded.
7345 User has already told to create pending breakpoints and
7346 don't need extra messages. If breakpoint is in bp_shlib_disabled
7347 state, then user already saw the message about that breakpoint
7348 being disabled, and don't want to see more errors. */
7350 && (b
->condition_not_parsed
7351 || (b
->loc
&& b
->loc
->shlib_disabled
)
7352 || b
->enable_state
== bp_disabled
))
7353 not_found_and_ok
= 1;
7355 if (!not_found_and_ok
)
7357 /* We surely don't want to warn about the same breakpoint
7358 10 times. One solution, implemented here, is disable
7359 the breakpoint on error. Another solution would be to
7360 have separate 'warning emitted' flag. Since this
7361 happens only when a binary has changed, I don't know
7362 which approach is better. */
7363 b
->enable_state
= bp_disabled
;
7364 throw_exception (e
);
7371 gdb_assert (sals
.nelts
== 1);
7372 resolve_sal_pc (&sals
.sals
[0]);
7373 if (b
->condition_not_parsed
&& s
&& s
[0])
7375 char *cond_string
= 0;
7377 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7378 &cond_string
, &thread
);
7380 b
->cond_string
= cond_string
;
7382 b
->condition_not_parsed
= 0;
7384 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7385 update_breakpoint_locations (b
, expanded
);
7391 case bp_hardware_watchpoint
:
7392 case bp_read_watchpoint
:
7393 case bp_access_watchpoint
:
7394 /* Watchpoint can be either on expression using entirely global variables,
7395 or it can be on local variables.
7397 Watchpoints of the first kind are never auto-deleted, and even persist
7398 across program restarts. Since they can use variables from shared
7399 libraries, we need to reparse expression as libraries are loaded
7402 Watchpoints on local variables can also change meaning as result
7403 of solib event. For example, if a watchpoint uses both a local and
7404 a global variables in expression, it's a local watchpoint, but
7405 unloading of a shared library will make the expression invalid.
7406 This is not a very common use case, but we still re-evaluate
7407 expression, to avoid surprises to the user.
7409 Note that for local watchpoints, we re-evaluate it only if
7410 watchpoints frame id is still valid. If it's not, it means
7411 the watchpoint is out of scope and will be deleted soon. In fact,
7412 I'm not sure we'll ever be called in this case.
7414 If a local watchpoint's frame id is still valid, then
7415 b->exp_valid_block is likewise valid, and we can safely use it.
7417 Don't do anything about disabled watchpoints, since they will
7418 be reevaluated again when enabled. */
7419 update_watchpoint (b
, 1 /* reparse */);
7421 /* We needn't really do anything to reset these, since the mask
7422 that requests them is unaffected by e.g., new libraries being
7428 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7430 /* Delete overlay event breakpoints; they will be reset later by
7431 breakpoint_re_set. */
7432 case bp_overlay_event
:
7433 delete_breakpoint (b
);
7436 /* This breakpoint is special, it's set up when the inferior
7437 starts and we really don't want to touch it. */
7438 case bp_shlib_event
:
7440 /* Like bp_shlib_event, this breakpoint type is special.
7441 Once it is set up, we do not want to touch it. */
7442 case bp_thread_event
:
7444 /* Keep temporary breakpoints, which can be encountered when we step
7445 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7446 Otherwise these should have been blown away via the cleanup chain
7447 or by breakpoint_init_inferior when we rerun the executable. */
7450 case bp_watchpoint_scope
:
7452 case bp_step_resume
:
7454 case bp_longjmp_resume
:
7461 /* Re-set all breakpoints after symbols have been re-loaded. */
7463 breakpoint_re_set (void)
7465 struct breakpoint
*b
, *temp
;
7466 enum language save_language
;
7467 int save_input_radix
;
7469 save_language
= current_language
->la_language
;
7470 save_input_radix
= input_radix
;
7471 ALL_BREAKPOINTS_SAFE (b
, temp
)
7473 /* Format possible error msg */
7474 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7476 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7477 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7478 do_cleanups (cleanups
);
7480 set_language (save_language
);
7481 input_radix
= save_input_radix
;
7483 create_overlay_event_breakpoint ("_ovly_debug_event");
7486 /* Reset the thread number of this breakpoint:
7488 - If the breakpoint is for all threads, leave it as-is.
7489 - Else, reset it to the current thread for inferior_ptid. */
7491 breakpoint_re_set_thread (struct breakpoint
*b
)
7493 if (b
->thread
!= -1)
7495 if (in_thread_list (inferior_ptid
))
7496 b
->thread
= pid_to_thread_id (inferior_ptid
);
7500 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7501 If from_tty is nonzero, it prints a message to that effect,
7502 which ends with a period (no newline). */
7505 set_ignore_count (int bptnum
, int count
, int from_tty
)
7507 struct breakpoint
*b
;
7513 if (b
->number
== bptnum
)
7515 b
->ignore_count
= count
;
7519 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7521 else if (count
== 1)
7522 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7525 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7528 breakpoints_changed ();
7529 observer_notify_breakpoint_modified (b
->number
);
7533 error (_("No breakpoint number %d."), bptnum
);
7537 make_breakpoint_silent (struct breakpoint
*b
)
7539 /* Silence the breakpoint. */
7543 /* Command to set ignore-count of breakpoint N to COUNT. */
7546 ignore_command (char *args
, int from_tty
)
7552 error_no_arg (_("a breakpoint number"));
7554 num
= get_number (&p
);
7556 error (_("bad breakpoint number: '%s'"), args
);
7558 error (_("Second argument (specified ignore-count) is missing."));
7560 set_ignore_count (num
,
7561 longest_to_int (value_as_long (parse_and_eval (p
))),
7564 printf_filtered ("\n");
7567 /* Call FUNCTION on each of the breakpoints
7568 whose numbers are given in ARGS. */
7571 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7576 struct breakpoint
*b
, *tmp
;
7580 error_no_arg (_("one or more breakpoint numbers"));
7587 num
= get_number_or_range (&p1
);
7590 warning (_("bad breakpoint number at or near '%s'"), p
);
7594 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7595 if (b
->number
== num
)
7597 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7600 if (related_breakpoint
)
7601 function (related_breakpoint
);
7605 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7611 static struct bp_location
*
7612 find_location_by_number (char *number
)
7614 char *dot
= strchr (number
, '.');
7618 struct breakpoint
*b
;
7619 struct bp_location
*loc
;
7624 bp_num
= get_number_or_range (&p1
);
7626 error (_("Bad breakpoint number '%s'"), number
);
7629 if (b
->number
== bp_num
)
7634 if (!b
|| b
->number
!= bp_num
)
7635 error (_("Bad breakpoint number '%s'"), number
);
7638 loc_num
= get_number_or_range (&p1
);
7640 error (_("Bad breakpoint location number '%s'"), number
);
7644 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7647 error (_("Bad breakpoint location number '%s'"), dot
+1);
7653 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7654 If from_tty is nonzero, it prints a message to that effect,
7655 which ends with a period (no newline). */
7658 disable_breakpoint (struct breakpoint
*bpt
)
7660 /* Never disable a watchpoint scope breakpoint; we want to
7661 hit them when we leave scope so we can delete both the
7662 watchpoint and its scope breakpoint at that time. */
7663 if (bpt
->type
== bp_watchpoint_scope
)
7666 /* You can't disable permanent breakpoints. */
7667 if (bpt
->enable_state
== bp_permanent
)
7670 bpt
->enable_state
= bp_disabled
;
7672 update_global_location_list (0);
7674 observer_notify_breakpoint_modified (bpt
->number
);
7678 disable_command (char *args
, int from_tty
)
7680 struct breakpoint
*bpt
;
7682 ALL_BREAKPOINTS (bpt
)
7686 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7691 case bp_hardware_breakpoint
:
7693 case bp_hardware_watchpoint
:
7694 case bp_read_watchpoint
:
7695 case bp_access_watchpoint
:
7696 disable_breakpoint (bpt
);
7700 else if (strchr (args
, '.'))
7702 struct bp_location
*loc
= find_location_by_number (args
);
7705 update_global_location_list (0);
7708 map_breakpoint_numbers (args
, disable_breakpoint
);
7712 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7714 int target_resources_ok
, other_type_used
;
7717 if (bpt
->type
== bp_hardware_breakpoint
)
7720 i
= hw_breakpoint_used_count ();
7721 target_resources_ok
=
7722 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7724 if (target_resources_ok
== 0)
7725 error (_("No hardware breakpoint support in the target."));
7726 else if (target_resources_ok
< 0)
7727 error (_("Hardware breakpoints used exceeds limit."));
7730 if (bpt
->type
== bp_watchpoint
||
7731 bpt
->type
== bp_hardware_watchpoint
||
7732 bpt
->type
== bp_read_watchpoint
||
7733 bpt
->type
== bp_access_watchpoint
)
7735 struct frame_id saved_frame_id
;
7737 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7738 if (bpt
->exp_valid_block
!= NULL
)
7740 struct frame_info
*fr
=
7741 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7744 printf_filtered (_("\
7745 Cannot enable watchpoint %d because the block in which its expression\n\
7746 is valid is not currently in scope.\n"), bpt
->number
);
7753 value_free (bpt
->val
);
7754 mark
= value_mark ();
7755 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7757 release_value (bpt
->val
);
7760 if (bpt
->type
== bp_hardware_watchpoint
||
7761 bpt
->type
== bp_read_watchpoint
||
7762 bpt
->type
== bp_access_watchpoint
)
7764 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7765 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7767 /* Hack around 'unused var' error for some targets here */
7768 (void) mem_cnt
, (void) i
;
7769 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7770 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7771 /* we can consider of type is bp_hardware_watchpoint, convert to
7772 bp_watchpoint in the following condition */
7773 if (target_resources_ok
< 0)
7775 printf_filtered (_("\
7776 Cannot enable watchpoint %d because target watch resources\n\
7777 have been allocated for other watchpoints.\n"), bpt
->number
);
7778 value_free_to_mark (mark
);
7783 select_frame (frame_find_by_id (saved_frame_id
));
7784 value_free_to_mark (mark
);
7787 if (bpt
->enable_state
!= bp_permanent
)
7788 bpt
->enable_state
= bp_enabled
;
7789 bpt
->disposition
= disposition
;
7790 update_global_location_list (1);
7791 breakpoints_changed ();
7793 observer_notify_breakpoint_modified (bpt
->number
);
7798 enable_breakpoint (struct breakpoint
*bpt
)
7800 do_enable_breakpoint (bpt
, bpt
->disposition
);
7803 /* The enable command enables the specified breakpoints (or all defined
7804 breakpoints) so they once again become (or continue to be) effective
7805 in stopping the inferior. */
7808 enable_command (char *args
, int from_tty
)
7810 struct breakpoint
*bpt
;
7812 ALL_BREAKPOINTS (bpt
)
7816 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7821 case bp_hardware_breakpoint
:
7823 case bp_hardware_watchpoint
:
7824 case bp_read_watchpoint
:
7825 case bp_access_watchpoint
:
7826 enable_breakpoint (bpt
);
7830 else if (strchr (args
, '.'))
7832 struct bp_location
*loc
= find_location_by_number (args
);
7835 update_global_location_list (1);
7838 map_breakpoint_numbers (args
, enable_breakpoint
);
7842 enable_once_breakpoint (struct breakpoint
*bpt
)
7844 do_enable_breakpoint (bpt
, disp_disable
);
7848 enable_once_command (char *args
, int from_tty
)
7850 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7854 enable_delete_breakpoint (struct breakpoint
*bpt
)
7856 do_enable_breakpoint (bpt
, disp_del
);
7860 enable_delete_command (char *args
, int from_tty
)
7862 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7866 set_breakpoint_cmd (char *args
, int from_tty
)
7871 show_breakpoint_cmd (char *args
, int from_tty
)
7875 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7877 struct symtabs_and_lines
7878 decode_line_spec_1 (char *string
, int funfirstline
)
7880 struct symtabs_and_lines sals
;
7882 error (_("Empty line specification."));
7883 if (default_breakpoint_valid
)
7884 sals
= decode_line_1 (&string
, funfirstline
,
7885 default_breakpoint_symtab
,
7886 default_breakpoint_line
,
7887 (char ***) NULL
, NULL
);
7889 sals
= decode_line_1 (&string
, funfirstline
,
7890 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7892 error (_("Junk at end of line specification: %s"), string
);
7896 /* Create and insert a raw software breakpoint at PC. Return an
7897 identifier, which should be used to remove the breakpoint later.
7898 In general, places which call this should be using something on the
7899 breakpoint chain instead; this function should be eliminated
7903 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7905 struct bp_target_info
*bp_tgt
;
7907 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7908 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7910 bp_tgt
->placed_address
= pc
;
7911 if (target_insert_breakpoint (bp_tgt
) != 0)
7913 /* Could not insert the breakpoint. */
7921 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7924 deprecated_remove_raw_breakpoint (void *bp
)
7926 struct bp_target_info
*bp_tgt
= bp
;
7929 ret
= target_remove_breakpoint (bp_tgt
);
7935 /* One (or perhaps two) breakpoints used for software single stepping. */
7937 static void *single_step_breakpoints
[2];
7939 /* Create and insert a breakpoint for software single step. */
7942 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7946 if (single_step_breakpoints
[0] == NULL
)
7947 bpt_p
= &single_step_breakpoints
[0];
7950 gdb_assert (single_step_breakpoints
[1] == NULL
);
7951 bpt_p
= &single_step_breakpoints
[1];
7954 /* NOTE drow/2006-04-11: A future improvement to this function would be
7955 to only create the breakpoints once, and actually put them on the
7956 breakpoint chain. That would let us use set_raw_breakpoint. We could
7957 adjust the addresses each time they were needed. Doing this requires
7958 corresponding changes elsewhere where single step breakpoints are
7959 handled, however. So, for now, we use this. */
7961 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7963 error (_("Could not insert single-step breakpoint at 0x%s"),
7964 paddr_nz (next_pc
));
7967 /* Remove and delete any breakpoints used for software single step. */
7970 remove_single_step_breakpoints (void)
7972 gdb_assert (single_step_breakpoints
[0] != NULL
);
7974 /* See insert_single_step_breakpoint for more about this deprecated
7976 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7977 single_step_breakpoints
[0] = NULL
;
7979 if (single_step_breakpoints
[1] != NULL
)
7981 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7982 single_step_breakpoints
[1] = NULL
;
7986 /* Check whether a software single-step breakpoint is inserted at PC. */
7989 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
7993 for (i
= 0; i
< 2; i
++)
7995 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
7996 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8004 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8005 It is defined as a macro to prevent duplication.
8006 COMMAND should be a string constant containing the name of the command. */
8007 #define BREAK_ARGS_HELP(command) \
8008 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8009 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8010 If a line number is specified, break at start of code for that line.\n\
8011 If a function is specified, break at start of code for that function.\n\
8012 If an address is specified, break at that exact address.\n\
8013 With no LOCATION, uses current execution address of selected stack frame.\n\
8014 This is useful for breaking on return to a stack frame.\n\
8016 THREADNUM is the number from \"info threads\".\n\
8017 CONDITION is a boolean expression.\n\
8019 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8021 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8023 /* List of subcommands for "catch". */
8024 static struct cmd_list_element
*catch_cmdlist
;
8026 /* List of subcommands for "tcatch". */
8027 static struct cmd_list_element
*tcatch_cmdlist
;
8029 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8030 lists, and pass some additional user data to the command function. */
8032 add_catch_command (char *name
, char *docstring
,
8033 void (*sfunc
) (char *args
, int from_tty
,
8034 struct cmd_list_element
*command
),
8035 void *user_data_catch
,
8036 void *user_data_tcatch
)
8038 struct cmd_list_element
*command
;
8040 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8042 set_cmd_sfunc (command
, sfunc
);
8043 set_cmd_context (command
, user_data_catch
);
8045 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8047 set_cmd_sfunc (command
, sfunc
);
8048 set_cmd_context (command
, user_data_tcatch
);
8052 _initialize_breakpoint (void)
8054 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8055 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8056 struct cmd_list_element
*c
;
8058 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8060 breakpoint_chain
= 0;
8061 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8062 before a breakpoint is set. */
8063 breakpoint_count
= 0;
8065 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8066 Set ignore-count of breakpoint number N to COUNT.\n\
8067 Usage is `ignore N COUNT'."));
8069 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8071 add_com ("commands", class_breakpoint
, commands_command
, _("\
8072 Set commands to be executed when a breakpoint is hit.\n\
8073 Give breakpoint number as argument after \"commands\".\n\
8074 With no argument, the targeted breakpoint is the last one set.\n\
8075 The commands themselves follow starting on the next line.\n\
8076 Type a line containing \"end\" to indicate the end of them.\n\
8077 Give \"silent\" as the first line to make the breakpoint silent;\n\
8078 then no output is printed when it is hit, except what the commands print."));
8080 add_com ("condition", class_breakpoint
, condition_command
, _("\
8081 Specify breakpoint number N to break only if COND is true.\n\
8082 Usage is `condition N COND', where N is an integer and COND is an\n\
8083 expression to be evaluated whenever breakpoint N is reached."));
8085 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8086 Set a temporary breakpoint.\n\
8087 Like \"break\" except the breakpoint is only temporary,\n\
8088 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8089 by using \"enable delete\" on the breakpoint number.\n\
8091 BREAK_ARGS_HELP ("tbreak")));
8092 set_cmd_completer (c
, location_completer
);
8094 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8095 Set a hardware assisted breakpoint.\n\
8096 Like \"break\" except the breakpoint requires hardware support,\n\
8097 some target hardware may not have this support.\n\
8099 BREAK_ARGS_HELP ("hbreak")));
8100 set_cmd_completer (c
, location_completer
);
8102 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8103 Set a temporary hardware assisted breakpoint.\n\
8104 Like \"hbreak\" except the breakpoint is only temporary,\n\
8105 so it will be deleted when hit.\n\
8107 BREAK_ARGS_HELP ("thbreak")));
8108 set_cmd_completer (c
, location_completer
);
8110 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8111 Enable some breakpoints.\n\
8112 Give breakpoint numbers (separated by spaces) as arguments.\n\
8113 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8114 This is used to cancel the effect of the \"disable\" command.\n\
8115 With a subcommand you can enable temporarily."),
8116 &enablelist
, "enable ", 1, &cmdlist
);
8118 add_com ("ab", class_breakpoint
, enable_command
, _("\
8119 Enable some breakpoints.\n\
8120 Give breakpoint numbers (separated by spaces) as arguments.\n\
8121 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8122 This is used to cancel the effect of the \"disable\" command.\n\
8123 With a subcommand you can enable temporarily."));
8125 add_com_alias ("en", "enable", class_breakpoint
, 1);
8127 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8128 Enable some breakpoints.\n\
8129 Give breakpoint numbers (separated by spaces) as arguments.\n\
8130 This is used to cancel the effect of the \"disable\" command.\n\
8131 May be abbreviated to simply \"enable\".\n"),
8132 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8134 add_cmd ("once", no_class
, enable_once_command
, _("\
8135 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8136 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8139 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8140 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8141 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8144 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8145 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8146 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8149 add_cmd ("once", no_class
, enable_once_command
, _("\
8150 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8151 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8154 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8155 Disable some breakpoints.\n\
8156 Arguments are breakpoint numbers with spaces in between.\n\
8157 To disable all breakpoints, give no argument.\n\
8158 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8159 &disablelist
, "disable ", 1, &cmdlist
);
8160 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8161 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8163 add_com ("sb", class_breakpoint
, disable_command
, _("\
8164 Disable some breakpoints.\n\
8165 Arguments are breakpoint numbers with spaces in between.\n\
8166 To disable all breakpoints, give no argument.\n\
8167 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8169 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8170 Disable some breakpoints.\n\
8171 Arguments are breakpoint numbers with spaces in between.\n\
8172 To disable all breakpoints, give no argument.\n\
8173 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8174 This command may be abbreviated \"disable\"."),
8177 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8178 Delete some breakpoints or auto-display expressions.\n\
8179 Arguments are breakpoint numbers with spaces in between.\n\
8180 To delete all breakpoints, give no argument.\n\
8182 Also a prefix command for deletion of other GDB objects.\n\
8183 The \"unset\" command is also an alias for \"delete\"."),
8184 &deletelist
, "delete ", 1, &cmdlist
);
8185 add_com_alias ("d", "delete", class_breakpoint
, 1);
8186 add_com_alias ("del", "delete", class_breakpoint
, 1);
8188 add_com ("db", class_breakpoint
, delete_command
, _("\
8189 Delete some breakpoints.\n\
8190 Arguments are breakpoint numbers with spaces in between.\n\
8191 To delete all breakpoints, give no argument.\n"));
8193 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8194 Delete some breakpoints or auto-display expressions.\n\
8195 Arguments are breakpoint numbers with spaces in between.\n\
8196 To delete all breakpoints, give no argument.\n\
8197 This command may be abbreviated \"delete\"."),
8200 add_com ("clear", class_breakpoint
, clear_command
, _("\
8201 Clear breakpoint at specified line or function.\n\
8202 Argument may be line number, function name, or \"*\" and an address.\n\
8203 If line number is specified, all breakpoints in that line are cleared.\n\
8204 If function is specified, breakpoints at beginning of function are cleared.\n\
8205 If an address is specified, breakpoints at that address are cleared.\n\
8207 With no argument, clears all breakpoints in the line that the selected frame\n\
8210 See also the \"delete\" command which clears breakpoints by number."));
8212 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8213 Set breakpoint at specified line or function.\n"
8214 BREAK_ARGS_HELP ("break")));
8215 set_cmd_completer (c
, location_completer
);
8217 add_com_alias ("b", "break", class_run
, 1);
8218 add_com_alias ("br", "break", class_run
, 1);
8219 add_com_alias ("bre", "break", class_run
, 1);
8220 add_com_alias ("brea", "break", class_run
, 1);
8224 add_com_alias ("ba", "break", class_breakpoint
, 1);
8225 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8230 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8231 Break in function/address or break at a line in the current file."),
8232 &stoplist
, "stop ", 1, &cmdlist
);
8233 add_cmd ("in", class_breakpoint
, stopin_command
,
8234 _("Break in function or address."), &stoplist
);
8235 add_cmd ("at", class_breakpoint
, stopat_command
,
8236 _("Break at a line in the current file."), &stoplist
);
8237 add_com ("status", class_info
, breakpoints_info
, _("\
8238 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8239 The \"Type\" column indicates one of:\n\
8240 \tbreakpoint - normal breakpoint\n\
8241 \twatchpoint - watchpoint\n\
8242 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8243 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8244 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8245 address and file/line number respectively.\n\
8247 Convenience variable \"$_\" and default examine address for \"x\"\n\
8248 are set to the address of the last breakpoint listed unless the command\n\
8249 is prefixed with \"server \".\n\n\
8250 Convenience variable \"$bpnum\" contains the number of the last\n\
8254 add_info ("breakpoints", breakpoints_info
, _("\
8255 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8256 The \"Type\" column indicates one of:\n\
8257 \tbreakpoint - normal breakpoint\n\
8258 \twatchpoint - watchpoint\n\
8259 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8260 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8261 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8262 address and file/line number respectively.\n\
8264 Convenience variable \"$_\" and default examine address for \"x\"\n\
8265 are set to the address of the last breakpoint listed unless the command\n\
8266 is prefixed with \"server \".\n\n\
8267 Convenience variable \"$bpnum\" contains the number of the last\n\
8271 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8272 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8273 The \"Type\" column indicates one of:\n\
8274 \tbreakpoint - normal breakpoint\n\
8275 \twatchpoint - watchpoint\n\
8276 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8277 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8278 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8279 address and file/line number respectively.\n\
8281 Convenience variable \"$_\" and default examine address for \"x\"\n\
8282 are set to the address of the last breakpoint listed unless the command\n\
8283 is prefixed with \"server \".\n\n\
8284 Convenience variable \"$bpnum\" contains the number of the last\n\
8287 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8288 Status of all breakpoints, or breakpoint number NUMBER.\n\
8289 The \"Type\" column indicates one of:\n\
8290 \tbreakpoint - normal breakpoint\n\
8291 \twatchpoint - watchpoint\n\
8292 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8293 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8294 \tuntil - internal breakpoint used by the \"until\" command\n\
8295 \tfinish - internal breakpoint used by the \"finish\" command\n\
8296 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8297 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8298 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8299 address and file/line number respectively.\n\
8301 Convenience variable \"$_\" and default examine address for \"x\"\n\
8302 are set to the address of the last breakpoint listed unless the command\n\
8303 is prefixed with \"server \".\n\n\
8304 Convenience variable \"$bpnum\" contains the number of the last\n\
8306 &maintenanceinfolist
);
8308 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8309 Set catchpoints to catch events."),
8310 &catch_cmdlist
, "catch ",
8311 0/*allow-unknown*/, &cmdlist
);
8313 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8314 Set temporary catchpoints to catch events."),
8315 &tcatch_cmdlist
, "tcatch ",
8316 0/*allow-unknown*/, &cmdlist
);
8318 /* Add catch and tcatch sub-commands. */
8319 add_catch_command ("catch", _("\
8320 Catch an exception, when caught.\n\
8321 With an argument, catch only exceptions with the given name."),
8322 catch_catch_command
,
8325 add_catch_command ("throw", _("\
8326 Catch an exception, when thrown.\n\
8327 With an argument, catch only exceptions with the given name."),
8328 catch_throw_command
,
8331 add_catch_command ("fork", _("Catch calls to fork."),
8332 catch_fork_command_1
,
8333 (void *) (uintptr_t) catch_fork_permanent
,
8334 (void *) (uintptr_t) catch_fork_temporary
);
8335 add_catch_command ("vfork", _("Catch calls to vfork."),
8336 catch_fork_command_1
,
8337 (void *) (uintptr_t) catch_vfork_permanent
,
8338 (void *) (uintptr_t) catch_vfork_temporary
);
8339 add_catch_command ("exec", _("Catch calls to exec."),
8340 catch_exec_command_1
,
8343 add_catch_command ("exception", _("\
8344 Catch Ada exceptions, when raised.\n\
8345 With an argument, catch only exceptions with the given name."),
8346 catch_ada_exception_command
,
8349 add_catch_command ("assert", _("\
8350 Catch failed Ada assertions, when raised.\n\
8351 With an argument, catch only exceptions with the given name."),
8352 catch_assert_command
,
8356 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8357 Set a watchpoint for an expression.\n\
8358 A watchpoint stops execution of your program whenever the value of\n\
8359 an expression changes."));
8360 set_cmd_completer (c
, expression_completer
);
8362 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8363 Set a read watchpoint for an expression.\n\
8364 A watchpoint stops execution of your program whenever the value of\n\
8365 an expression is read."));
8366 set_cmd_completer (c
, expression_completer
);
8368 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8369 Set a watchpoint for an expression.\n\
8370 A watchpoint stops execution of your program whenever the value of\n\
8371 an expression is either read or written."));
8372 set_cmd_completer (c
, expression_completer
);
8374 add_info ("watchpoints", breakpoints_info
,
8375 _("Synonym for ``info breakpoints''."));
8378 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8379 respond to changes - contrary to the description. */
8380 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8381 &can_use_hw_watchpoints
, _("\
8382 Set debugger's willingness to use watchpoint hardware."), _("\
8383 Show debugger's willingness to use watchpoint hardware."), _("\
8384 If zero, gdb will not use hardware for new watchpoints, even if\n\
8385 such is available. (However, any hardware watchpoints that were\n\
8386 created before setting this to nonzero, will continue to use watchpoint\n\
8389 show_can_use_hw_watchpoints
,
8390 &setlist
, &showlist
);
8392 can_use_hw_watchpoints
= 1;
8394 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8395 Breakpoint specific settings\n\
8396 Configure various breakpoint-specific variables such as\n\
8397 pending breakpoint behavior"),
8398 &breakpoint_set_cmdlist
, "set breakpoint ",
8399 0/*allow-unknown*/, &setlist
);
8400 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8401 Breakpoint specific settings\n\
8402 Configure various breakpoint-specific variables such as\n\
8403 pending breakpoint behavior"),
8404 &breakpoint_show_cmdlist
, "show breakpoint ",
8405 0/*allow-unknown*/, &showlist
);
8407 add_setshow_auto_boolean_cmd ("pending", no_class
,
8408 &pending_break_support
, _("\
8409 Set debugger's behavior regarding pending breakpoints."), _("\
8410 Show debugger's behavior regarding pending breakpoints."), _("\
8411 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8412 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8413 an error. If auto, an unrecognized breakpoint location results in a\n\
8414 user-query to see if a pending breakpoint should be created."),
8416 show_pending_break_support
,
8417 &breakpoint_set_cmdlist
,
8418 &breakpoint_show_cmdlist
);
8420 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8422 add_setshow_boolean_cmd ("auto-hw", no_class
,
8423 &automatic_hardware_breakpoints
, _("\
8424 Set automatic usage of hardware breakpoints."), _("\
8425 Show automatic usage of hardware breakpoints."), _("\
8426 If set, the debugger will automatically use hardware breakpoints for\n\
8427 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8428 a warning will be emitted for such breakpoints."),
8430 show_automatic_hardware_breakpoints
,
8431 &breakpoint_set_cmdlist
,
8432 &breakpoint_show_cmdlist
);
8434 add_setshow_enum_cmd ("always-inserted", class_support
,
8435 always_inserted_enums
, &always_inserted_mode
, _("\
8436 Set mode for inserting breakpoints."), _("\
8437 Show mode for inserting breakpoints."), _("\
8438 When this mode is off, breakpoints are inserted in inferior when it is\n\
8439 resumed, and removed when execution stops. When this mode is on,\n\
8440 breakpoints are inserted immediately and removed only when the user\n\
8441 deletes the breakpoint. When this mode is auto (which is the default),\n\
8442 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8443 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8444 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8445 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8447 &show_always_inserted_mode
,
8448 &breakpoint_set_cmdlist
,
8449 &breakpoint_show_cmdlist
);
8451 automatic_hardware_breakpoints
= 1;