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, 2009 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
*allocate_bp_location (struct breakpoint
*bpt
);
186 static void update_global_location_list (int);
188 static void update_global_location_list_nothrow (int);
190 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
192 static void insert_breakpoint_locations (void);
194 /* Flag indicating that a command has proceeded the inferior past the
195 current breakpoint. */
197 static int breakpoint_proceeded
;
200 bpdisp_text (enum bpdisp disp
)
202 /* NOTE: the following values are a part of MI protocol and represent
203 values of 'disp' field returned when inferior stops at a breakpoint. */
204 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
205 return bpdisps
[(int) disp
];
208 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints
;
214 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
215 struct cmd_list_element
*c
,
218 fprintf_filtered (file
, _("\
219 Debugger's willingness to use watchpoint hardware is %s.\n"),
223 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
224 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
225 for unrecognized breakpoint locations.
226 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
227 static enum auto_boolean pending_break_support
;
229 show_pending_break_support (struct ui_file
*file
, int from_tty
,
230 struct cmd_list_element
*c
,
233 fprintf_filtered (file
, _("\
234 Debugger's behavior regarding pending breakpoints is %s.\n"),
238 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
239 set with "break" but falling in read-only memory.
240 If 0, gdb will warn about such breakpoints, but won't automatically
241 use hardware breakpoints. */
242 static int automatic_hardware_breakpoints
;
244 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
245 struct cmd_list_element
*c
,
248 fprintf_filtered (file
, _("\
249 Automatic usage of hardware breakpoints is %s.\n"),
253 /* If on, gdb will keep breakpoints inserted even as inferior is
254 stopped, and immediately insert any new breakpoints. If off, gdb
255 will insert breakpoints into inferior only when resuming it, and
256 will remove breakpoints upon stop. If auto, GDB will behave as ON
257 if in non-stop mode, and as OFF if all-stop mode.*/
259 static const char always_inserted_auto
[] = "auto";
260 static const char always_inserted_on
[] = "on";
261 static const char always_inserted_off
[] = "off";
262 static const char *always_inserted_enums
[] = {
263 always_inserted_auto
,
268 static const char *always_inserted_mode
= always_inserted_auto
;
270 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
271 struct cmd_list_element
*c
, const char *value
)
273 if (always_inserted_mode
== always_inserted_auto
)
274 fprintf_filtered (file
, _("\
275 Always inserted breakpoint mode is %s (currently %s).\n"),
277 breakpoints_always_inserted_mode () ? "on" : "off");
279 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
283 breakpoints_always_inserted_mode (void)
285 return (always_inserted_mode
== always_inserted_on
286 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
289 void _initialize_breakpoint (void);
291 /* Are we executing breakpoint commands? */
292 static int executing_breakpoint_commands
;
294 /* Are overlay event breakpoints enabled? */
295 static int overlay_events_enabled
;
297 /* Walk the following statement or block through all breakpoints.
298 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
301 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
303 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
304 for (B = breakpoint_chain; \
305 B ? (TMP=B->next, 1): 0; \
308 /* Similar iterators for the low-level breakpoints. */
310 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
312 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
313 for (B = bp_location_chain; \
314 B ? (TMP=B->global_next, 1): 0; \
317 /* Chains of all breakpoints defined. */
319 struct breakpoint
*breakpoint_chain
;
321 struct bp_location
*bp_location_chain
;
323 /* The locations that no longer correspond to any breakpoint,
324 unlinked from bp_location_chain, but for which a hit
325 may still be reported by a target. */
326 VEC(bp_location_p
) *moribund_locations
= NULL
;
328 /* Number of last breakpoint made. */
330 int breakpoint_count
;
332 /* Return whether a breakpoint is an active enabled breakpoint. */
334 breakpoint_enabled (struct breakpoint
*b
)
336 return (b
->enable_state
== bp_enabled
);
339 /* Set breakpoint count to NUM. */
342 set_breakpoint_count (int num
)
344 breakpoint_count
= num
;
345 set_internalvar (lookup_internalvar ("bpnum"),
346 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
349 /* Used in run_command to zero the hit count when a new run starts. */
352 clear_breakpoint_hit_counts (void)
354 struct breakpoint
*b
;
360 /* Default address, symtab and line to put a breakpoint at
361 for "break" command with no arg.
362 if default_breakpoint_valid is zero, the other three are
363 not valid, and "break" with no arg is an error.
365 This set by print_stack_frame, which calls set_default_breakpoint. */
367 int default_breakpoint_valid
;
368 CORE_ADDR default_breakpoint_address
;
369 struct symtab
*default_breakpoint_symtab
;
370 int default_breakpoint_line
;
372 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
373 Advance *PP after the string and any trailing whitespace.
375 Currently the string can either be a number or "$" followed by the name
376 of a convenience variable. Making it an expression wouldn't work well
377 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
379 If the string is a NULL pointer, that denotes the last breakpoint.
381 TRAILER is a character which can be found after the number; most
382 commonly this is `-'. If you don't want a trailer, use \0. */
384 get_number_trailer (char **pp
, int trailer
)
386 int retval
= 0; /* default */
390 /* Empty line means refer to the last breakpoint. */
391 return breakpoint_count
;
394 /* Make a copy of the name, so we can null-terminate it
395 to pass to lookup_internalvar(). */
400 while (isalnum (*p
) || *p
== '_')
402 varname
= (char *) alloca (p
- start
+ 1);
403 strncpy (varname
, start
, p
- start
);
404 varname
[p
- start
] = '\0';
405 val
= value_of_internalvar (lookup_internalvar (varname
));
406 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
407 retval
= (int) value_as_long (val
);
410 printf_filtered (_("Convenience variable must have integer value.\n"));
418 while (*p
>= '0' && *p
<= '9')
421 /* There is no number here. (e.g. "cond a == b"). */
423 /* Skip non-numeric token */
424 while (*p
&& !isspace((int) *p
))
426 /* Return zero, which caller must interpret as error. */
432 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
434 /* Trailing junk: return 0 and let caller print error msg. */
435 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
446 /* Like get_number_trailer, but don't allow a trailer. */
448 get_number (char **pp
)
450 return get_number_trailer (pp
, '\0');
453 /* Parse a number or a range.
454 * A number will be of the form handled by get_number.
455 * A range will be of the form <number1> - <number2>, and
456 * will represent all the integers between number1 and number2,
459 * While processing a range, this fuction is called iteratively;
460 * At each call it will return the next value in the range.
462 * At the beginning of parsing a range, the char pointer PP will
463 * be advanced past <number1> and left pointing at the '-' token.
464 * Subsequent calls will not advance the pointer until the range
465 * is completed. The call that completes the range will advance
466 * pointer PP past <number2>.
470 get_number_or_range (char **pp
)
472 static int last_retval
, end_value
;
473 static char *end_ptr
;
474 static int in_range
= 0;
478 /* Default case: pp is pointing either to a solo number,
479 or to the first number of a range. */
480 last_retval
= get_number_trailer (pp
, '-');
485 /* This is the start of a range (<number1> - <number2>).
486 Skip the '-', parse and remember the second number,
487 and also remember the end of the final token. */
491 while (isspace ((int) *end_ptr
))
492 end_ptr
++; /* skip white space */
493 end_value
= get_number (temp
);
494 if (end_value
< last_retval
)
496 error (_("inverted range"));
498 else if (end_value
== last_retval
)
500 /* degenerate range (number1 == number2). Advance the
501 token pointer so that the range will be treated as a
510 error (_("negative value"));
513 /* pp points to the '-' that betokens a range. All
514 number-parsing has already been done. Return the next
515 integer value (one greater than the saved previous value).
516 Do not advance the token pointer 'pp' until the end of range
519 if (++last_retval
== end_value
)
521 /* End of range reached; advance token pointer. */
531 /* condition N EXP -- set break condition of breakpoint N to EXP. */
534 condition_command (char *arg
, int from_tty
)
536 struct breakpoint
*b
;
541 error_no_arg (_("breakpoint number"));
544 bnum
= get_number (&p
);
546 error (_("Bad breakpoint argument: '%s'"), arg
);
549 if (b
->number
== bnum
)
551 struct bp_location
*loc
= b
->loc
;
552 for (; loc
; loc
= loc
->next
)
560 if (b
->cond_string
!= NULL
)
561 xfree (b
->cond_string
);
565 b
->cond_string
= NULL
;
567 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
572 /* I don't know if it matters whether this is the string the user
573 typed in or the decompiled expression. */
574 b
->cond_string
= savestring (arg
, strlen (arg
));
575 b
->condition_not_parsed
= 0;
576 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
580 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
582 error (_("Junk at end of expression"));
585 breakpoints_changed ();
586 observer_notify_breakpoint_modified (b
->number
);
590 error (_("No breakpoint number %d."), bnum
);
594 commands_command (char *arg
, int from_tty
)
596 struct breakpoint
*b
;
599 struct command_line
*l
;
601 /* If we allowed this, we would have problems with when to
602 free the storage, if we change the commands currently
605 if (executing_breakpoint_commands
)
606 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
609 bnum
= get_number (&p
);
612 error (_("Unexpected extra arguments following breakpoint number."));
615 if (b
->number
== bnum
)
617 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
619 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
620 l
= read_command_lines (tmpbuf
, from_tty
, 1);
621 do_cleanups (cleanups
);
622 free_command_lines (&b
->commands
);
624 breakpoints_changed ();
625 observer_notify_breakpoint_modified (b
->number
);
628 error (_("No breakpoint number %d."), bnum
);
631 /* Like commands_command, but instead of reading the commands from
632 input stream, takes them from an already parsed command structure.
634 This is used by cli-script.c to DTRT with breakpoint commands
635 that are part of if and while bodies. */
636 enum command_control_type
637 commands_from_control_command (char *arg
, struct command_line
*cmd
)
639 struct breakpoint
*b
;
643 /* If we allowed this, we would have problems with when to
644 free the storage, if we change the commands currently
647 if (executing_breakpoint_commands
)
648 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
650 /* An empty string for the breakpoint number means the last
651 breakpoint, but get_number expects a NULL pointer. */
656 bnum
= get_number (&p
);
659 error (_("Unexpected extra arguments following breakpoint number."));
662 if (b
->number
== bnum
)
664 free_command_lines (&b
->commands
);
665 if (cmd
->body_count
!= 1)
666 error (_("Invalid \"commands\" block structure."));
667 /* We need to copy the commands because if/while will free the
668 list after it finishes execution. */
669 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
670 breakpoints_changed ();
671 observer_notify_breakpoint_modified (b
->number
);
672 return simple_control
;
674 error (_("No breakpoint number %d."), bnum
);
677 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
678 by replacing any memory breakpoints with their shadowed contents. */
681 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
683 struct bp_location
*b
;
684 CORE_ADDR bp_addr
= 0;
690 if (b
->owner
->type
== bp_none
)
691 warning (_("reading through apparently deleted breakpoint #%d?"),
694 if (b
->loc_type
!= bp_loc_software_breakpoint
)
698 /* Addresses and length of the part of the breakpoint that
700 bp_addr
= b
->target_info
.placed_address
;
701 bp_size
= b
->target_info
.shadow_len
;
703 /* bp isn't valid, or doesn't shadow memory. */
706 if (bp_addr
+ bp_size
<= memaddr
)
707 /* The breakpoint is entirely before the chunk of memory we
711 if (bp_addr
>= memaddr
+ len
)
712 /* The breakpoint is entirely after the chunk of memory we are
716 /* Offset within shadow_contents. */
717 if (bp_addr
< memaddr
)
719 /* Only copy the second part of the breakpoint. */
720 bp_size
-= memaddr
- bp_addr
;
721 bptoffset
= memaddr
- bp_addr
;
725 if (bp_addr
+ bp_size
> memaddr
+ len
)
727 /* Only copy the first part of the breakpoint. */
728 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
731 memcpy (buf
+ bp_addr
- memaddr
,
732 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
737 /* A wrapper function for inserting catchpoints. */
739 insert_catchpoint (struct ui_out
*uo
, void *args
)
741 struct breakpoint
*b
= (struct breakpoint
*) args
;
744 gdb_assert (b
->type
== bp_catchpoint
);
745 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
751 is_hardware_watchpoint (struct breakpoint
*bpt
)
753 return (bpt
->type
== bp_hardware_watchpoint
754 || bpt
->type
== bp_read_watchpoint
755 || bpt
->type
== bp_access_watchpoint
);
758 /* Find the current value of a watchpoint on EXP. Return the value in
759 *VALP and *RESULTP and the chain of intermediate and final values
760 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
763 If a memory error occurs while evaluating the expression, *RESULTP will
764 be set to NULL. *RESULTP may be a lazy value, if the result could
765 not be read from memory. It is used to determine whether a value
766 is user-specified (we should watch the whole value) or intermediate
767 (we should watch only the bit used to locate the final value).
769 If the final value, or any intermediate value, could not be read
770 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
771 set to any referenced values. *VALP will never be a lazy value.
772 This is the value which we store in struct breakpoint.
774 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
775 value chain. The caller must free the values individually. If
776 VAL_CHAIN is NULL, all generated values will be left on the value
780 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
781 struct value
**resultp
, struct value
**val_chain
)
783 struct value
*mark
, *new_mark
, *result
;
784 volatile struct gdb_exception ex
;
792 /* Evaluate the expression. */
793 mark
= value_mark ();
796 TRY_CATCH (ex
, RETURN_MASK_ALL
)
798 result
= evaluate_expression (exp
);
802 /* Ignore memory errors, we want watchpoints pointing at
803 inaccessible memory to still be created; otherwise, throw the
804 error to some higher catcher. */
810 throw_exception (ex
);
815 new_mark
= value_mark ();
816 if (mark
== new_mark
)
821 /* Make sure it's not lazy, so that after the target stops again we
822 have a non-lazy previous value to compare with. */
824 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
829 /* Return the chain of intermediate values. We use this to
830 decide which addresses to watch. */
831 *val_chain
= new_mark
;
832 value_release_to_mark (mark
);
836 /* Assuming that B is a watchpoint:
837 - Reparse watchpoint expression, if REPARSE is non-zero
838 - Evaluate expression and store the result in B->val
839 - Evaluate the condition if there is one, and store the result
841 - Update the list of values that must be watched in B->loc.
843 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
844 If this is local watchpoint that is out of scope, delete it. */
846 update_watchpoint (struct breakpoint
*b
, int reparse
)
848 int within_current_scope
;
849 struct frame_id saved_frame_id
;
850 struct bp_location
*loc
;
853 /* We don't free locations. They are stored in bp_location_chain and
854 update_global_locations will eventually delete them and remove
855 breakpoints if needed. */
858 if (b
->disposition
== disp_del_at_next_stop
)
861 /* Save the current frame's ID so we can restore it after
862 evaluating the watchpoint expression on its own frame. */
863 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
864 took a frame parameter, so that we didn't have to change the
866 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
868 /* Determine if the watchpoint is within scope. */
869 if (b
->exp_valid_block
== NULL
)
870 within_current_scope
= 1;
873 struct frame_info
*fi
;
874 fi
= frame_find_by_id (b
->watchpoint_frame
);
875 within_current_scope
= (fi
!= NULL
);
876 if (within_current_scope
)
880 if (within_current_scope
&& reparse
)
889 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
890 /* If the meaning of expression itself changed, the old value is
891 no longer relevant. We don't want to report a watchpoint hit
892 to the user when the old value and the new value may actually
893 be completely different objects. */
899 /* If we failed to parse the expression, for example because
900 it refers to a global variable in a not-yet-loaded shared library,
901 don't try to insert watchpoint. We don't automatically delete
902 such watchpoint, though, since failure to parse expression
903 is different from out-of-scope watchpoint. */
904 if (within_current_scope
&& b
->exp
)
906 struct value
*val_chain
, *v
, *result
, *next
;
908 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
910 /* Avoid setting b->val if it's already set. The meaning of
911 b->val is 'the last value' user saw, and we should update
912 it only if we reported that last value to user. As it
913 happens, the code that reports it updates b->val directly. */
920 /* Change the type of breakpoint between hardware assisted or an
921 ordinary watchpoint depending on the hardware support and free
922 hardware slots. REPARSE is set when the inferior is started. */
923 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
926 int i
, mem_cnt
, other_type_used
;
928 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
930 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
933 b
->type
= bp_watchpoint
;
936 int target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT
937 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
938 if (target_resources_ok
<= 0)
939 b
->type
= bp_watchpoint
;
941 b
->type
= bp_hardware_watchpoint
;
945 /* Look at each value on the value chain. */
946 for (v
= val_chain
; v
; v
= next
)
948 /* If it's a memory location, and GDB actually needed
949 its contents to evaluate the expression, then we
950 must watch it. If the first value returned is
951 still lazy, that means an error occurred reading it;
952 watch it anyway in case it becomes readable. */
953 if (VALUE_LVAL (v
) == lval_memory
954 && (v
== val_chain
|| ! value_lazy (v
)))
956 struct type
*vtype
= check_typedef (value_type (v
));
958 /* We only watch structs and arrays if user asked
959 for it explicitly, never if they just happen to
960 appear in the middle of some value chain. */
962 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
963 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
967 struct bp_location
*loc
, **tmp
;
969 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
970 len
= TYPE_LENGTH (value_type (v
));
972 if (b
->type
== bp_read_watchpoint
)
974 else if (b
->type
== bp_access_watchpoint
)
977 loc
= allocate_bp_location (b
);
978 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
983 loc
->watchpoint_type
= type
;
987 next
= value_next (v
);
992 /* We just regenerated the list of breakpoint locations.
993 The new location does not have its condition field set to anything
994 and therefore, we must always reparse the cond_string, independently
995 of the value of the reparse flag. */
996 if (b
->cond_string
!= NULL
)
998 char *s
= b
->cond_string
;
999 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1002 else if (!within_current_scope
)
1004 printf_filtered (_("\
1005 Watchpoint %d deleted because the program has left the block \n\
1006 in which its expression is valid.\n"),
1008 if (b
->related_breakpoint
)
1009 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1010 b
->disposition
= disp_del_at_next_stop
;
1013 /* Restore the selected frame. */
1014 select_frame (frame_find_by_id (saved_frame_id
));
1018 /* Returns 1 iff breakpoint location should be
1019 inserted in the inferior. */
1021 should_be_inserted (struct bp_location
*bpt
)
1023 if (!breakpoint_enabled (bpt
->owner
))
1026 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1029 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1035 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1036 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1037 and HW_BREAKPOINT_ERROR are used to report problems.
1039 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1040 method for each breakpoint or catchpoint type. */
1042 insert_bp_location (struct bp_location
*bpt
,
1043 struct ui_file
*tmp_error_stream
,
1044 int *disabled_breaks
,
1045 int *hw_breakpoint_error
)
1049 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1052 /* Initialize the target-specific information. */
1053 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1054 bpt
->target_info
.placed_address
= bpt
->address
;
1056 if (bpt
->loc_type
== bp_loc_software_breakpoint
1057 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1059 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1061 /* If the explicitly specified breakpoint type
1062 is not hardware breakpoint, check the memory map to see
1063 if the breakpoint address is in read only memory or not.
1064 Two important cases are:
1065 - location type is not hardware breakpoint, memory
1066 is readonly. We change the type of the location to
1067 hardware breakpoint.
1068 - location type is hardware breakpoint, memory is read-write.
1069 This means we've previously made the location hardware one, but
1070 then the memory map changed, so we undo.
1072 When breakpoints are removed, remove_breakpoints will
1073 use location types we've just set here, the only possible
1074 problem is that memory map has changed during running program,
1075 but it's not going to work anyway with current gdb. */
1076 struct mem_region
*mr
1077 = lookup_mem_region (bpt
->target_info
.placed_address
);
1081 if (automatic_hardware_breakpoints
)
1084 enum bp_loc_type new_type
;
1086 if (mr
->attrib
.mode
!= MEM_RW
)
1087 new_type
= bp_loc_hardware_breakpoint
;
1089 new_type
= bp_loc_software_breakpoint
;
1091 if (new_type
!= bpt
->loc_type
)
1093 static int said
= 0;
1094 bpt
->loc_type
= new_type
;
1097 fprintf_filtered (gdb_stdout
, _("\
1098 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1103 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1104 && mr
->attrib
.mode
!= MEM_RW
)
1105 warning (_("cannot set software breakpoint at readonly address %s"),
1106 paddr (bpt
->address
));
1110 /* First check to see if we have to handle an overlay. */
1111 if (overlay_debugging
== ovly_off
1112 || bpt
->section
== NULL
1113 || !(section_is_overlay (bpt
->section
)))
1115 /* No overlay handling: just set the breakpoint. */
1117 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1118 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1120 val
= target_insert_breakpoint (&bpt
->target_info
);
1124 /* This breakpoint is in an overlay section.
1125 Shall we set a breakpoint at the LMA? */
1126 if (!overlay_events_enabled
)
1128 /* Yes -- overlay event support is not active,
1129 so we must try to set a breakpoint at the LMA.
1130 This will not work for a hardware breakpoint. */
1131 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1132 warning (_("hardware breakpoint %d not supported in overlay!"),
1133 bpt
->owner
->number
);
1136 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1138 /* Set a software (trap) breakpoint at the LMA. */
1139 bpt
->overlay_target_info
= bpt
->target_info
;
1140 bpt
->overlay_target_info
.placed_address
= addr
;
1141 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1143 fprintf_unfiltered (tmp_error_stream
,
1144 "Overlay breakpoint %d failed: in ROM?\n",
1145 bpt
->owner
->number
);
1148 /* Shall we set a breakpoint at the VMA? */
1149 if (section_is_mapped (bpt
->section
))
1151 /* Yes. This overlay section is mapped into memory. */
1152 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1153 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1155 val
= target_insert_breakpoint (&bpt
->target_info
);
1159 /* No. This breakpoint will not be inserted.
1160 No error, but do not mark the bp as 'inserted'. */
1167 /* Can't set the breakpoint. */
1168 if (solib_name_from_address (bpt
->address
))
1170 /* See also: disable_breakpoints_in_shlibs. */
1172 bpt
->shlib_disabled
= 1;
1173 if (!*disabled_breaks
)
1175 fprintf_unfiltered (tmp_error_stream
,
1176 "Cannot insert breakpoint %d.\n",
1177 bpt
->owner
->number
);
1178 fprintf_unfiltered (tmp_error_stream
,
1179 "Temporarily disabling shared library breakpoints:\n");
1181 *disabled_breaks
= 1;
1182 fprintf_unfiltered (tmp_error_stream
,
1183 "breakpoint #%d\n", bpt
->owner
->number
);
1187 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1189 *hw_breakpoint_error
= 1;
1190 fprintf_unfiltered (tmp_error_stream
,
1191 "Cannot insert hardware breakpoint %d.\n",
1192 bpt
->owner
->number
);
1196 fprintf_unfiltered (tmp_error_stream
,
1197 "Cannot insert breakpoint %d.\n",
1198 bpt
->owner
->number
);
1199 fprintf_filtered (tmp_error_stream
,
1200 "Error accessing memory address ");
1201 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1202 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1203 safe_strerror (val
));
1214 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1215 /* NOTE drow/2003-09-08: This state only exists for removing
1216 watchpoints. It's not clear that it's necessary... */
1217 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1219 val
= target_insert_watchpoint (bpt
->address
,
1221 bpt
->watchpoint_type
);
1222 bpt
->inserted
= (val
!= -1);
1225 else if (bpt
->owner
->type
== bp_catchpoint
)
1227 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1228 bpt
->owner
, RETURN_MASK_ERROR
);
1229 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1230 bpt
->owner
->number
);
1232 bpt
->owner
->enable_state
= bp_disabled
;
1236 /* We've already printed an error message if there was a problem
1237 inserting this catchpoint, and we've disabled the catchpoint,
1238 so just return success. */
1245 /* Make sure all breakpoints are inserted in inferior.
1246 Throws exception on any error.
1247 A breakpoint that is already inserted won't be inserted
1248 again, so calling this function twice is safe. */
1250 insert_breakpoints (void)
1252 struct breakpoint
*bpt
;
1254 ALL_BREAKPOINTS (bpt
)
1255 if (is_hardware_watchpoint (bpt
))
1256 update_watchpoint (bpt
, 0 /* don't reparse. */);
1258 update_global_location_list (1);
1260 if (!breakpoints_always_inserted_mode ()
1261 && (target_has_execution
1262 || (gdbarch_has_global_solist (target_gdbarch
)
1263 && target_supports_multi_process ())))
1264 /* update_global_location_list does not insert breakpoints
1265 when always_inserted_mode is not enabled. Explicitly
1267 insert_breakpoint_locations ();
1270 /* insert_breakpoints is used when starting or continuing the program.
1271 remove_breakpoints is used when the program stops.
1272 Both return zero if successful,
1273 or an `errno' value if could not write the inferior. */
1276 insert_breakpoint_locations (void)
1278 struct breakpoint
*bpt
;
1279 struct bp_location
*b
, *temp
;
1282 int disabled_breaks
= 0;
1283 int hw_breakpoint_error
= 0;
1285 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1286 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1288 /* Explicitly mark the warning -- this will only be printed if
1289 there was an error. */
1290 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1292 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1294 if (!should_be_inserted (b
) || b
->inserted
)
1297 /* There is no point inserting thread-specific breakpoints if the
1298 thread no longer exists. */
1299 if (b
->owner
->thread
!= -1
1300 && !valid_thread_id (b
->owner
->thread
))
1303 val
= insert_bp_location (b
, tmp_error_stream
,
1305 &hw_breakpoint_error
);
1310 /* If we failed to insert all locations of a watchpoint,
1311 remove them, as half-inserted watchpoint is of limited use. */
1312 ALL_BREAKPOINTS (bpt
)
1314 int some_failed
= 0;
1315 struct bp_location
*loc
;
1317 if (!is_hardware_watchpoint (bpt
))
1320 if (!breakpoint_enabled (bpt
))
1323 if (bpt
->disposition
== disp_del_at_next_stop
)
1326 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1334 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1336 remove_breakpoint (loc
, mark_uninserted
);
1338 hw_breakpoint_error
= 1;
1339 fprintf_unfiltered (tmp_error_stream
,
1340 "Could not insert hardware watchpoint %d.\n",
1348 /* If a hardware breakpoint or watchpoint was inserted, add a
1349 message about possibly exhausted resources. */
1350 if (hw_breakpoint_error
)
1352 fprintf_unfiltered (tmp_error_stream
,
1353 "Could not insert hardware breakpoints:\n\
1354 You may have requested too many hardware breakpoints/watchpoints.\n");
1356 target_terminal_ours_for_output ();
1357 error_stream (tmp_error_stream
);
1360 do_cleanups (cleanups
);
1364 remove_breakpoints (void)
1366 struct bp_location
*b
;
1369 ALL_BP_LOCATIONS (b
)
1373 val
= remove_breakpoint (b
, mark_uninserted
);
1382 remove_hw_watchpoints (void)
1384 struct bp_location
*b
;
1387 ALL_BP_LOCATIONS (b
)
1389 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1391 val
= remove_breakpoint (b
, mark_uninserted
);
1400 reattach_breakpoints (int pid
)
1402 struct bp_location
*b
;
1404 struct cleanup
*old_chain
= save_inferior_ptid ();
1405 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1406 int dummy1
= 0, dummy2
= 0;
1408 make_cleanup_ui_file_delete (tmp_error_stream
);
1410 inferior_ptid
= pid_to_ptid (pid
);
1411 ALL_BP_LOCATIONS (b
)
1416 val
= insert_bp_location (b
, tmp_error_stream
,
1420 do_cleanups (old_chain
);
1425 do_cleanups (old_chain
);
1430 update_breakpoints_after_exec (void)
1432 struct breakpoint
*b
;
1433 struct breakpoint
*temp
;
1434 struct bp_location
*bploc
;
1436 /* We're about to delete breakpoints from GDB's lists. If the
1437 INSERTED flag is true, GDB will try to lift the breakpoints by
1438 writing the breakpoints' "shadow contents" back into memory. The
1439 "shadow contents" are NOT valid after an exec, so GDB should not
1440 do that. Instead, the target is responsible from marking
1441 breakpoints out as soon as it detects an exec. We don't do that
1442 here instead, because there may be other attempts to delete
1443 breakpoints after detecting an exec and before reaching here. */
1444 ALL_BP_LOCATIONS (bploc
)
1445 gdb_assert (!bploc
->inserted
);
1447 ALL_BREAKPOINTS_SAFE (b
, temp
)
1449 /* Solib breakpoints must be explicitly reset after an exec(). */
1450 if (b
->type
== bp_shlib_event
)
1452 delete_breakpoint (b
);
1456 /* Thread event breakpoints must be set anew after an exec(),
1457 as must overlay event breakpoints. */
1458 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1460 delete_breakpoint (b
);
1464 /* Step-resume breakpoints are meaningless after an exec(). */
1465 if (b
->type
== bp_step_resume
)
1467 delete_breakpoint (b
);
1471 /* Longjmp and longjmp-resume breakpoints are also meaningless
1473 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1475 delete_breakpoint (b
);
1479 if (b
->type
== bp_catchpoint
)
1481 /* For now, none of the bp_catchpoint breakpoints need to
1482 do anything at this point. In the future, if some of
1483 the catchpoints need to something, we will need to add
1484 a new method, and call this method from here. */
1488 /* bp_finish is a special case. The only way we ought to be able
1489 to see one of these when an exec() has happened, is if the user
1490 caught a vfork, and then said "finish". Ordinarily a finish just
1491 carries them to the call-site of the current callee, by setting
1492 a temporary bp there and resuming. But in this case, the finish
1493 will carry them entirely through the vfork & exec.
1495 We don't want to allow a bp_finish to remain inserted now. But
1496 we can't safely delete it, 'cause finish_command has a handle to
1497 the bp on a bpstat, and will later want to delete it. There's a
1498 chance (and I've seen it happen) that if we delete the bp_finish
1499 here, that its storage will get reused by the time finish_command
1500 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1501 We really must allow finish_command to delete a bp_finish.
1503 In the absense of a general solution for the "how do we know
1504 it's safe to delete something others may have handles to?"
1505 problem, what we'll do here is just uninsert the bp_finish, and
1506 let finish_command delete it.
1508 (We know the bp_finish is "doomed" in the sense that it's
1509 momentary, and will be deleted as soon as finish_command sees
1510 the inferior stopped. So it doesn't matter that the bp's
1511 address is probably bogus in the new a.out, unlike e.g., the
1512 solib breakpoints.) */
1514 if (b
->type
== bp_finish
)
1519 /* Without a symbolic address, we have little hope of the
1520 pre-exec() address meaning the same thing in the post-exec()
1522 if (b
->addr_string
== NULL
)
1524 delete_breakpoint (b
);
1528 /* FIXME what about longjmp breakpoints? Re-create them here? */
1529 create_overlay_event_breakpoint ("_ovly_debug_event");
1533 detach_breakpoints (int pid
)
1535 struct bp_location
*b
;
1537 struct cleanup
*old_chain
= save_inferior_ptid ();
1539 if (pid
== PIDGET (inferior_ptid
))
1540 error (_("Cannot detach breakpoints of inferior_ptid"));
1542 /* Set inferior_ptid; remove_breakpoint uses this global. */
1543 inferior_ptid
= pid_to_ptid (pid
);
1544 ALL_BP_LOCATIONS (b
)
1548 val
= remove_breakpoint (b
, mark_inserted
);
1551 do_cleanups (old_chain
);
1556 do_cleanups (old_chain
);
1561 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1565 if (b
->owner
->enable_state
== bp_permanent
)
1566 /* Permanent breakpoints cannot be inserted or removed. */
1569 /* The type of none suggests that owner is actually deleted.
1570 This should not ever happen. */
1571 gdb_assert (b
->owner
->type
!= bp_none
);
1573 if (b
->loc_type
== bp_loc_software_breakpoint
1574 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1576 /* "Normal" instruction breakpoint: either the standard
1577 trap-instruction bp (bp_breakpoint), or a
1578 bp_hardware_breakpoint. */
1580 /* First check to see if we have to handle an overlay. */
1581 if (overlay_debugging
== ovly_off
1582 || b
->section
== NULL
1583 || !(section_is_overlay (b
->section
)))
1585 /* No overlay handling: just remove the breakpoint. */
1587 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1588 val
= target_remove_hw_breakpoint (&b
->target_info
);
1590 val
= target_remove_breakpoint (&b
->target_info
);
1594 /* This breakpoint is in an overlay section.
1595 Did we set a breakpoint at the LMA? */
1596 if (!overlay_events_enabled
)
1598 /* Yes -- overlay event support is not active, so we
1599 should have set a breakpoint at the LMA. Remove it.
1601 /* Ignore any failures: if the LMA is in ROM, we will
1602 have already warned when we failed to insert it. */
1603 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1604 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1606 target_remove_breakpoint (&b
->overlay_target_info
);
1608 /* Did we set a breakpoint at the VMA?
1609 If so, we will have marked the breakpoint 'inserted'. */
1612 /* Yes -- remove it. Previously we did not bother to
1613 remove the breakpoint if the section had been
1614 unmapped, but let's not rely on that being safe. We
1615 don't know what the overlay manager might do. */
1616 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1617 val
= target_remove_hw_breakpoint (&b
->target_info
);
1619 /* However, we should remove *software* breakpoints only
1620 if the section is still mapped, or else we overwrite
1621 wrong code with the saved shadow contents. */
1622 else if (section_is_mapped (b
->section
))
1623 val
= target_remove_breakpoint (&b
->target_info
);
1629 /* No -- not inserted, so no need to remove. No error. */
1634 /* In some cases, we might not be able to remove a breakpoint
1635 in a shared library that has already been removed, but we
1636 have not yet processed the shlib unload event. */
1637 if (val
&& solib_name_from_address (b
->address
))
1642 b
->inserted
= (is
== mark_inserted
);
1644 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1649 b
->inserted
= (is
== mark_inserted
);
1650 val
= target_remove_watchpoint (b
->address
, b
->length
,
1651 b
->watchpoint_type
);
1653 /* Failure to remove any of the hardware watchpoints comes here. */
1654 if ((is
== mark_uninserted
) && (b
->inserted
))
1655 warning (_("Could not remove hardware watchpoint %d."),
1658 else if (b
->owner
->type
== bp_catchpoint
1659 && breakpoint_enabled (b
->owner
)
1662 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1664 val
= b
->owner
->ops
->remove (b
->owner
);
1667 b
->inserted
= (is
== mark_inserted
);
1673 /* Clear the "inserted" flag in all breakpoints. */
1676 mark_breakpoints_out (void)
1678 struct bp_location
*bpt
;
1680 ALL_BP_LOCATIONS (bpt
)
1684 /* Clear the "inserted" flag in all breakpoints and delete any
1685 breakpoints which should go away between runs of the program.
1687 Plus other such housekeeping that has to be done for breakpoints
1690 Note: this function gets called at the end of a run (by
1691 generic_mourn_inferior) and when a run begins (by
1692 init_wait_for_inferior). */
1697 breakpoint_init_inferior (enum inf_context context
)
1699 struct breakpoint
*b
, *temp
;
1700 struct bp_location
*bpt
;
1703 /* If breakpoint locations are shared across processes, then there's
1705 if (gdbarch_has_global_solist (target_gdbarch
))
1708 ALL_BP_LOCATIONS (bpt
)
1709 if (bpt
->owner
->enable_state
!= bp_permanent
)
1712 ALL_BREAKPOINTS_SAFE (b
, temp
)
1717 case bp_watchpoint_scope
:
1719 /* If the call dummy breakpoint is at the entry point it will
1720 cause problems when the inferior is rerun, so we better
1723 Also get rid of scope breakpoints. */
1724 delete_breakpoint (b
);
1728 case bp_hardware_watchpoint
:
1729 case bp_read_watchpoint
:
1730 case bp_access_watchpoint
:
1732 /* Likewise for watchpoints on local expressions. */
1733 if (b
->exp_valid_block
!= NULL
)
1734 delete_breakpoint (b
);
1735 else if (context
== inf_starting
)
1737 /* Reset val field to force reread of starting value
1738 in insert_breakpoints. */
1740 value_free (b
->val
);
1750 /* Get rid of the moribund locations. */
1751 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1752 free_bp_location (bpt
);
1753 VEC_free (bp_location_p
, moribund_locations
);
1756 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1757 exists at PC. It returns ordinary_breakpoint_here if it's an
1758 ordinary breakpoint, or permanent_breakpoint_here if it's a
1759 permanent breakpoint.
1760 - When continuing from a location with an ordinary breakpoint, we
1761 actually single step once before calling insert_breakpoints.
1762 - When continuing from a localion with a permanent breakpoint, we
1763 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1764 the target, to advance the PC past the breakpoint. */
1766 enum breakpoint_here
1767 breakpoint_here_p (CORE_ADDR pc
)
1769 const struct bp_location
*bpt
;
1770 int any_breakpoint_here
= 0;
1772 ALL_BP_LOCATIONS (bpt
)
1774 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1775 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1778 if ((breakpoint_enabled (bpt
->owner
)
1779 || bpt
->owner
->enable_state
== bp_permanent
)
1780 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1782 if (overlay_debugging
1783 && section_is_overlay (bpt
->section
)
1784 && !section_is_mapped (bpt
->section
))
1785 continue; /* unmapped overlay -- can't be a match */
1786 else if (bpt
->owner
->enable_state
== bp_permanent
)
1787 return permanent_breakpoint_here
;
1789 any_breakpoint_here
= 1;
1793 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1796 /* Return true if there's a moribund breakpoint at PC. */
1799 moribund_breakpoint_here_p (CORE_ADDR pc
)
1801 struct bp_location
*loc
;
1804 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1805 if (loc
->address
== pc
)
1811 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1812 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1813 This does not check for single-step breakpoints, which are
1814 inserted and removed using direct target manipulation. */
1817 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1819 const struct bp_location
*bpt
;
1821 ALL_BP_LOCATIONS (bpt
)
1823 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1824 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1828 && bpt
->address
== pc
) /* bp is inserted 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 */
1841 /* Returns non-zero iff there's either regular breakpoint
1842 or a single step breakpoint inserted at PC. */
1845 breakpoint_inserted_here_p (CORE_ADDR pc
)
1847 if (regular_breakpoint_inserted_here_p (pc
))
1850 if (single_step_breakpoint_inserted_here_p (pc
))
1856 /* This function returns non-zero iff there is a software breakpoint
1860 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1862 const struct bp_location
*bpt
;
1863 int any_breakpoint_here
= 0;
1865 ALL_BP_LOCATIONS (bpt
)
1867 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1871 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1873 if (overlay_debugging
1874 && section_is_overlay (bpt
->section
)
1875 && !section_is_mapped (bpt
->section
))
1876 continue; /* unmapped overlay -- can't be a match */
1882 /* Also check for software single-step breakpoints. */
1883 if (single_step_breakpoint_inserted_here_p (pc
))
1889 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1890 PC is valid for process/thread PTID. */
1893 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1895 const struct bp_location
*bpt
;
1898 thread
= pid_to_thread_id (ptid
);
1900 ALL_BP_LOCATIONS (bpt
)
1902 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1903 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1906 if ((breakpoint_enabled (bpt
->owner
)
1907 || bpt
->owner
->enable_state
== bp_permanent
)
1908 && bpt
->address
== pc
1909 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1911 if (overlay_debugging
1912 && section_is_overlay (bpt
->section
)
1913 && !section_is_mapped (bpt
->section
))
1914 continue; /* unmapped overlay -- can't be a match */
1924 /* bpstat stuff. External routines' interfaces are documented
1928 ep_is_catchpoint (struct breakpoint
*ep
)
1930 return (ep
->type
== bp_catchpoint
);
1934 bpstat_free (bpstat bs
)
1936 if (bs
->old_val
!= NULL
)
1937 value_free (bs
->old_val
);
1938 free_command_lines (&bs
->commands
);
1942 /* Clear a bpstat so that it says we are not at any breakpoint.
1943 Also free any storage that is part of a bpstat. */
1946 bpstat_clear (bpstat
*bsp
)
1963 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1964 is part of the bpstat is copied as well. */
1967 bpstat_copy (bpstat bs
)
1971 bpstat retval
= NULL
;
1976 for (; bs
!= NULL
; bs
= bs
->next
)
1978 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1979 memcpy (tmp
, bs
, sizeof (*tmp
));
1980 if (bs
->commands
!= NULL
)
1981 tmp
->commands
= copy_command_lines (bs
->commands
);
1982 if (bs
->old_val
!= NULL
)
1984 tmp
->old_val
= value_copy (bs
->old_val
);
1985 release_value (tmp
->old_val
);
1989 /* This is the first thing in the chain. */
1999 /* Find the bpstat associated with this breakpoint */
2002 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2007 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2009 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2015 /* Find a step_resume breakpoint associated with this bpstat.
2016 (If there are multiple step_resume bp's on the list, this function
2017 will arbitrarily pick one.)
2019 It is an error to use this function if BPSTAT doesn't contain a
2020 step_resume breakpoint.
2022 See wait_for_inferior's use of this function. */
2024 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2028 gdb_assert (bsp
!= NULL
);
2030 current_thread
= pid_to_thread_id (inferior_ptid
);
2032 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2034 if ((bsp
->breakpoint_at
!= NULL
) &&
2035 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2036 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2037 bsp
->breakpoint_at
->owner
->thread
== -1))
2038 return bsp
->breakpoint_at
->owner
;
2041 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2045 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2046 at. *BSP upon return is a bpstat which points to the remaining
2047 breakpoints stopped at (but which is not guaranteed to be good for
2048 anything but further calls to bpstat_num).
2049 Return 0 if passed a bpstat which does not indicate any breakpoints.
2050 Return -1 if stopped at a breakpoint that has been deleted since
2052 Return 1 otherwise. */
2055 bpstat_num (bpstat
*bsp
, int *num
)
2057 struct breakpoint
*b
;
2060 return 0; /* No more breakpoint values */
2062 /* We assume we'll never have several bpstats that
2063 correspond to a single breakpoint -- otherwise,
2064 this function might return the same number more
2065 than once and this will look ugly. */
2066 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2067 *bsp
= (*bsp
)->next
;
2069 return -1; /* breakpoint that's been deleted since */
2071 *num
= b
->number
; /* We have its number */
2075 /* Modify BS so that the actions will not be performed. */
2078 bpstat_clear_actions (bpstat bs
)
2080 for (; bs
!= NULL
; bs
= bs
->next
)
2082 free_command_lines (&bs
->commands
);
2083 if (bs
->old_val
!= NULL
)
2085 value_free (bs
->old_val
);
2091 /* Called when a command is about to proceed the inferior. */
2094 breakpoint_about_to_proceed (void)
2096 if (!ptid_equal (inferior_ptid
, null_ptid
))
2098 struct thread_info
*tp
= inferior_thread ();
2100 /* Allow inferior function calls in breakpoint commands to not
2101 interrupt the command list. When the call finishes
2102 successfully, the inferior will be standing at the same
2103 breakpoint as if nothing happened. */
2108 breakpoint_proceeded
= 1;
2111 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2113 cleanup_executing_breakpoints (void *ignore
)
2115 executing_breakpoint_commands
= 0;
2118 /* Execute all the commands associated with all the breakpoints at this
2119 location. Any of these commands could cause the process to proceed
2120 beyond this point, etc. We look out for such changes by checking
2121 the global "breakpoint_proceeded" after each command.
2123 Returns true if a breakpoint command resumed the inferior. In that
2124 case, it is the caller's responsibility to recall it again with the
2125 bpstat of the current thread. */
2128 bpstat_do_actions_1 (bpstat
*bsp
)
2131 struct cleanup
*old_chain
;
2134 /* Avoid endless recursion if a `source' command is contained
2136 if (executing_breakpoint_commands
)
2139 executing_breakpoint_commands
= 1;
2140 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2142 /* This pointer will iterate over the list of bpstat's. */
2145 breakpoint_proceeded
= 0;
2146 for (; bs
!= NULL
; bs
= bs
->next
)
2148 struct command_line
*cmd
;
2149 struct cleanup
*this_cmd_tree_chain
;
2151 /* Take ownership of the BSP's command tree, if it has one.
2153 The command tree could legitimately contain commands like
2154 'step' and 'next', which call clear_proceed_status, which
2155 frees stop_bpstat's command tree. To make sure this doesn't
2156 free the tree we're executing out from under us, we need to
2157 take ownership of the tree ourselves. Since a given bpstat's
2158 commands are only executed once, we don't need to copy it; we
2159 can clear the pointer in the bpstat, and make sure we free
2160 the tree when we're done. */
2163 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2167 execute_control_command (cmd
);
2169 if (breakpoint_proceeded
)
2175 /* We can free this command tree now. */
2176 do_cleanups (this_cmd_tree_chain
);
2178 if (breakpoint_proceeded
)
2180 if (target_can_async_p ())
2181 /* If we are in async mode, then the target might be still
2182 running, not stopped at any breakpoint, so nothing for
2183 us to do here -- just return to the event loop. */
2186 /* In sync mode, when execute_control_command returns
2187 we're already standing on the next breakpoint.
2188 Breakpoint commands for that stop were not run, since
2189 execute_command does not run breakpoint commands --
2190 only command_line_handler does, but that one is not
2191 involved in execution of breakpoint commands. So, we
2192 can now execute breakpoint commands. It should be
2193 noted that making execute_command do bpstat actions is
2194 not an option -- in this case we'll have recursive
2195 invocation of bpstat for each breakpoint with a
2196 command, and can easily blow up GDB stack. Instead, we
2197 return true, which will trigger the caller to recall us
2198 with the new stop_bpstat. */
2203 do_cleanups (old_chain
);
2208 bpstat_do_actions (void)
2210 /* Do any commands attached to breakpoint we are stopped at. */
2211 while (!ptid_equal (inferior_ptid
, null_ptid
)
2212 && target_has_execution
2213 && !is_exited (inferior_ptid
)
2214 && !is_executing (inferior_ptid
))
2215 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2216 and only return when it is stopped at the next breakpoint, we
2217 keep doing breakpoint actions until it returns false to
2218 indicate the inferior was not resumed. */
2219 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2223 /* Print out the (old or new) value associated with a watchpoint. */
2226 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2229 fprintf_unfiltered (stream
, _("<unreadable>"));
2232 struct value_print_options opts
;
2233 get_user_print_options (&opts
);
2234 value_print (val
, stream
, &opts
);
2238 /* This is the normal print function for a bpstat. In the future,
2239 much of this logic could (should?) be moved to bpstat_stop_status,
2240 by having it set different print_it values.
2242 Current scheme: When we stop, bpstat_print() is called. It loops
2243 through the bpstat list of things causing this stop, calling the
2244 print_bp_stop_message function on each one. The behavior of the
2245 print_bp_stop_message function depends on the print_it field of
2246 bpstat. If such field so indicates, call this function here.
2248 Return values from this routine (ultimately used by bpstat_print()
2249 and normal_stop() to decide what to do):
2250 PRINT_NOTHING: Means we already printed all we needed to print,
2251 don't print anything else.
2252 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2253 that something to be followed by a location.
2254 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2255 that something to be followed by a location.
2256 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2259 static enum print_stop_action
2260 print_it_typical (bpstat bs
)
2262 struct cleanup
*old_chain
;
2263 struct breakpoint
*b
;
2264 const struct bp_location
*bl
;
2265 struct ui_stream
*stb
;
2267 enum print_stop_action result
;
2269 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2270 which has since been deleted. */
2271 if (bs
->breakpoint_at
== NULL
)
2272 return PRINT_UNKNOWN
;
2273 bl
= bs
->breakpoint_at
;
2276 stb
= ui_out_stream_new (uiout
);
2277 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2282 case bp_hardware_breakpoint
:
2283 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2284 if (bl
->address
!= bl
->requested_address
)
2285 breakpoint_adjustment_warning (bl
->requested_address
,
2288 annotate_breakpoint (b
->number
);
2290 ui_out_text (uiout
, "\nTemporary breakpoint ");
2292 ui_out_text (uiout
, "\nBreakpoint ");
2293 if (ui_out_is_mi_like_p (uiout
))
2295 ui_out_field_string (uiout
, "reason",
2296 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2297 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2299 ui_out_field_int (uiout
, "bkptno", b
->number
);
2300 ui_out_text (uiout
, ", ");
2301 result
= PRINT_SRC_AND_LOC
;
2304 case bp_shlib_event
:
2305 /* Did we stop because the user set the stop_on_solib_events
2306 variable? (If so, we report this as a generic, "Stopped due
2307 to shlib event" message.) */
2308 printf_filtered (_("Stopped due to shared library event\n"));
2309 result
= PRINT_NOTHING
;
2312 case bp_thread_event
:
2313 /* Not sure how we will get here.
2314 GDB should not stop for these breakpoints. */
2315 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2316 result
= PRINT_NOTHING
;
2319 case bp_overlay_event
:
2320 /* By analogy with the thread event, GDB should not stop for these. */
2321 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2322 result
= PRINT_NOTHING
;
2326 case bp_hardware_watchpoint
:
2327 annotate_watchpoint (b
->number
);
2328 if (ui_out_is_mi_like_p (uiout
))
2331 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2333 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2334 ui_out_text (uiout
, "\nOld value = ");
2335 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2336 ui_out_field_stream (uiout
, "old", stb
);
2337 ui_out_text (uiout
, "\nNew value = ");
2338 watchpoint_value_print (b
->val
, stb
->stream
);
2339 ui_out_field_stream (uiout
, "new", stb
);
2340 ui_out_text (uiout
, "\n");
2341 /* More than one watchpoint may have been triggered. */
2342 result
= PRINT_UNKNOWN
;
2345 case bp_read_watchpoint
:
2346 if (ui_out_is_mi_like_p (uiout
))
2349 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2351 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2352 ui_out_text (uiout
, "\nValue = ");
2353 watchpoint_value_print (b
->val
, stb
->stream
);
2354 ui_out_field_stream (uiout
, "value", stb
);
2355 ui_out_text (uiout
, "\n");
2356 result
= PRINT_UNKNOWN
;
2359 case bp_access_watchpoint
:
2360 if (bs
->old_val
!= NULL
)
2362 annotate_watchpoint (b
->number
);
2363 if (ui_out_is_mi_like_p (uiout
))
2366 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2368 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2369 ui_out_text (uiout
, "\nOld value = ");
2370 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2371 ui_out_field_stream (uiout
, "old", stb
);
2372 ui_out_text (uiout
, "\nNew value = ");
2377 if (ui_out_is_mi_like_p (uiout
))
2380 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2381 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2382 ui_out_text (uiout
, "\nValue = ");
2384 watchpoint_value_print (b
->val
, stb
->stream
);
2385 ui_out_field_stream (uiout
, "new", stb
);
2386 ui_out_text (uiout
, "\n");
2387 result
= PRINT_UNKNOWN
;
2390 /* Fall through, we don't deal with these types of breakpoints
2394 if (ui_out_is_mi_like_p (uiout
))
2397 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2398 result
= PRINT_UNKNOWN
;
2402 if (ui_out_is_mi_like_p (uiout
))
2405 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2406 result
= PRINT_UNKNOWN
;
2411 case bp_longjmp_resume
:
2412 case bp_step_resume
:
2413 case bp_watchpoint_scope
:
2416 result
= PRINT_UNKNOWN
;
2420 do_cleanups (old_chain
);
2424 /* Generic routine for printing messages indicating why we
2425 stopped. The behavior of this function depends on the value
2426 'print_it' in the bpstat structure. Under some circumstances we
2427 may decide not to print anything here and delegate the task to
2430 static enum print_stop_action
2431 print_bp_stop_message (bpstat bs
)
2433 switch (bs
->print_it
)
2436 /* Nothing should be printed for this bpstat entry. */
2437 return PRINT_UNKNOWN
;
2441 /* We still want to print the frame, but we already printed the
2442 relevant messages. */
2443 return PRINT_SRC_AND_LOC
;
2446 case print_it_normal
:
2448 const struct bp_location
*bl
= bs
->breakpoint_at
;
2449 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2451 /* Normal case. Call the breakpoint's print_it method, or
2452 print_it_typical. */
2453 /* FIXME: how breakpoint can ever be NULL here? */
2454 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2455 return b
->ops
->print_it (b
);
2457 return print_it_typical (bs
);
2462 internal_error (__FILE__
, __LINE__
,
2463 _("print_bp_stop_message: unrecognized enum value"));
2468 /* Print a message indicating what happened. This is called from
2469 normal_stop(). The input to this routine is the head of the bpstat
2470 list - a list of the eventpoints that caused this stop. This
2471 routine calls the generic print routine for printing a message
2472 about reasons for stopping. This will print (for example) the
2473 "Breakpoint n," part of the output. The return value of this
2476 PRINT_UNKNOWN: Means we printed nothing
2477 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2478 code to print the location. An example is
2479 "Breakpoint 1, " which should be followed by
2481 PRINT_SRC_ONLY: Means we printed something, but there is no need
2482 to also print the location part of the message.
2483 An example is the catch/throw messages, which
2484 don't require a location appended to the end.
2485 PRINT_NOTHING: We have done some printing and we don't need any
2486 further info to be printed.*/
2488 enum print_stop_action
2489 bpstat_print (bpstat bs
)
2493 /* Maybe another breakpoint in the chain caused us to stop.
2494 (Currently all watchpoints go on the bpstat whether hit or not.
2495 That probably could (should) be changed, provided care is taken
2496 with respect to bpstat_explains_signal). */
2497 for (; bs
; bs
= bs
->next
)
2499 val
= print_bp_stop_message (bs
);
2500 if (val
== PRINT_SRC_ONLY
2501 || val
== PRINT_SRC_AND_LOC
2502 || val
== PRINT_NOTHING
)
2506 /* We reached the end of the chain, or we got a null BS to start
2507 with and nothing was printed. */
2508 return PRINT_UNKNOWN
;
2511 /* Evaluate the expression EXP and return 1 if value is zero.
2512 This is used inside a catch_errors to evaluate the breakpoint condition.
2513 The argument is a "struct expression *" that has been cast to char * to
2514 make it pass through catch_errors. */
2517 breakpoint_cond_eval (void *exp
)
2519 struct value
*mark
= value_mark ();
2520 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2521 value_free_to_mark (mark
);
2525 /* Allocate a new bpstat and chain it to the current one. */
2528 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2532 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2534 bs
->breakpoint_at
= bl
;
2535 /* If the condition is false, etc., don't do the commands. */
2536 bs
->commands
= NULL
;
2538 bs
->print_it
= print_it_normal
;
2542 /* The target has stopped with waitstatus WS. Check if any hardware
2543 watchpoints have triggered, according to the target. */
2546 watchpoints_triggered (struct target_waitstatus
*ws
)
2548 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2550 struct breakpoint
*b
;
2552 if (!stopped_by_watchpoint
)
2554 /* We were not stopped by a watchpoint. Mark all watchpoints
2555 as not triggered. */
2557 if (b
->type
== bp_hardware_watchpoint
2558 || b
->type
== bp_read_watchpoint
2559 || b
->type
== bp_access_watchpoint
)
2560 b
->watchpoint_triggered
= watch_triggered_no
;
2565 if (!target_stopped_data_address (¤t_target
, &addr
))
2567 /* We were stopped by a watchpoint, but we don't know where.
2568 Mark all watchpoints as unknown. */
2570 if (b
->type
== bp_hardware_watchpoint
2571 || b
->type
== bp_read_watchpoint
2572 || b
->type
== bp_access_watchpoint
)
2573 b
->watchpoint_triggered
= watch_triggered_unknown
;
2575 return stopped_by_watchpoint
;
2578 /* The target could report the data address. Mark watchpoints
2579 affected by this data address as triggered, and all others as not
2583 if (b
->type
== bp_hardware_watchpoint
2584 || b
->type
== bp_read_watchpoint
2585 || b
->type
== bp_access_watchpoint
)
2587 struct bp_location
*loc
;
2590 b
->watchpoint_triggered
= watch_triggered_no
;
2591 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2592 /* Exact match not required. Within range is
2594 if (target_watchpoint_addr_within_range (¤t_target
,
2598 b
->watchpoint_triggered
= watch_triggered_yes
;
2606 /* Possible return values for watchpoint_check (this can't be an enum
2607 because of check_errors). */
2608 /* The watchpoint has been deleted. */
2609 #define WP_DELETED 1
2610 /* The value has changed. */
2611 #define WP_VALUE_CHANGED 2
2612 /* The value has not changed. */
2613 #define WP_VALUE_NOT_CHANGED 3
2615 #define BP_TEMPFLAG 1
2616 #define BP_HARDWAREFLAG 2
2618 /* Check watchpoint condition. */
2621 watchpoint_check (void *p
)
2623 bpstat bs
= (bpstat
) p
;
2624 struct breakpoint
*b
;
2625 struct frame_info
*fr
;
2626 int within_current_scope
;
2628 b
= bs
->breakpoint_at
->owner
;
2630 if (b
->exp_valid_block
== NULL
)
2631 within_current_scope
= 1;
2634 /* There is no current frame at this moment. If we're going to have
2635 any chance of handling watchpoints on local variables, we'll need
2636 the frame chain (so we can determine if we're in scope). */
2637 reinit_frame_cache ();
2638 fr
= frame_find_by_id (b
->watchpoint_frame
);
2639 within_current_scope
= (fr
!= NULL
);
2641 /* If we've gotten confused in the unwinder, we might have
2642 returned a frame that can't describe this variable. */
2643 if (within_current_scope
2644 && (block_linkage_function (b
->exp_valid_block
)
2645 != get_frame_function (fr
)))
2646 within_current_scope
= 0;
2648 /* in_function_epilogue_p() returns a non-zero value if we're still
2649 in the function but the stack frame has already been invalidated.
2650 Since we can't rely on the values of local variables after the
2651 stack has been destroyed, we are treating the watchpoint in that
2652 state as `not changed' without further checking.
2654 vinschen/2003-09-04: The former implementation left out the case
2655 that the watchpoint frame couldn't be found by frame_find_by_id()
2656 because the current PC is currently in an epilogue. Calling
2657 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2658 if ((!within_current_scope
|| fr
== get_current_frame ())
2659 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2660 return WP_VALUE_NOT_CHANGED
;
2661 if (fr
&& within_current_scope
)
2662 /* If we end up stopping, the current frame will get selected
2663 in normal_stop. So this call to select_frame won't affect
2668 if (within_current_scope
)
2670 /* We use value_{,free_to_}mark because it could be a
2671 *long* time before we return to the command level and
2672 call free_all_values. We can't call free_all_values because
2673 we might be in the middle of evaluating a function call. */
2675 struct value
*mark
= value_mark ();
2676 struct value
*new_val
;
2678 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2679 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2680 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2682 if (new_val
!= NULL
)
2684 release_value (new_val
);
2685 value_free_to_mark (mark
);
2687 bs
->old_val
= b
->val
;
2690 /* We will stop here */
2691 return WP_VALUE_CHANGED
;
2695 /* Nothing changed, don't do anything. */
2696 value_free_to_mark (mark
);
2697 /* We won't stop here */
2698 return WP_VALUE_NOT_CHANGED
;
2703 /* This seems like the only logical thing to do because
2704 if we temporarily ignored the watchpoint, then when
2705 we reenter the block in which it is valid it contains
2706 garbage (in the case of a function, it may have two
2707 garbage values, one before and one after the prologue).
2708 So we can't even detect the first assignment to it and
2709 watch after that (since the garbage may or may not equal
2710 the first value assigned). */
2711 /* We print all the stop information in print_it_typical(), but
2712 in this case, by the time we call print_it_typical() this bp
2713 will be deleted already. So we have no choice but print the
2714 information here. */
2715 if (ui_out_is_mi_like_p (uiout
))
2717 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2718 ui_out_text (uiout
, "\nWatchpoint ");
2719 ui_out_field_int (uiout
, "wpnum", b
->number
);
2720 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2721 which its expression is valid.\n");
2723 if (b
->related_breakpoint
)
2724 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2725 b
->disposition
= disp_del_at_next_stop
;
2731 /* Return true if it looks like target has stopped due to hitting
2732 breakpoint location BL. This function does not check if we
2733 should stop, only if BL explains the stop. */
2735 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2737 struct breakpoint
*b
= bl
->owner
;
2739 if (b
->type
!= bp_watchpoint
2740 && b
->type
!= bp_hardware_watchpoint
2741 && b
->type
!= bp_read_watchpoint
2742 && b
->type
!= bp_access_watchpoint
2743 && b
->type
!= bp_hardware_breakpoint
2744 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2746 if (bl
->address
!= bp_addr
) /* address doesn't match */
2748 if (overlay_debugging
/* unmapped overlay section */
2749 && section_is_overlay (bl
->section
)
2750 && !section_is_mapped (bl
->section
))
2754 /* Continuable hardware watchpoints are treated as non-existent if the
2755 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2756 some data address). Otherwise gdb won't stop on a break instruction
2757 in the code (not from a breakpoint) when a hardware watchpoint has
2758 been defined. Also skip watchpoints which we know did not trigger
2759 (did not match the data address). */
2761 if ((b
->type
== bp_hardware_watchpoint
2762 || b
->type
== bp_read_watchpoint
2763 || b
->type
== bp_access_watchpoint
)
2764 && b
->watchpoint_triggered
== watch_triggered_no
)
2767 if (b
->type
== bp_hardware_breakpoint
)
2769 if (bl
->address
!= bp_addr
)
2771 if (overlay_debugging
/* unmapped overlay section */
2772 && section_is_overlay (bl
->section
)
2773 && !section_is_mapped (bl
->section
))
2777 if (b
->type
== bp_catchpoint
)
2779 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2780 if (!b
->ops
->breakpoint_hit (b
))
2787 /* If BS refers to a watchpoint, determine if the watched values
2788 has actually changed, and we should stop. If not, set BS->stop
2791 bpstat_check_watchpoint (bpstat bs
)
2793 const struct bp_location
*bl
= bs
->breakpoint_at
;
2794 struct breakpoint
*b
= bl
->owner
;
2796 if (b
->type
== bp_watchpoint
2797 || b
->type
== bp_read_watchpoint
2798 || b
->type
== bp_access_watchpoint
2799 || b
->type
== bp_hardware_watchpoint
)
2803 int must_check_value
= 0;
2805 if (b
->type
== bp_watchpoint
)
2806 /* For a software watchpoint, we must always check the
2808 must_check_value
= 1;
2809 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2810 /* We have a hardware watchpoint (read, write, or access)
2811 and the target earlier reported an address watched by
2813 must_check_value
= 1;
2814 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2815 && b
->type
== bp_hardware_watchpoint
)
2816 /* We were stopped by a hardware watchpoint, but the target could
2817 not report the data address. We must check the watchpoint's
2818 value. Access and read watchpoints are out of luck; without
2819 a data address, we can't figure it out. */
2820 must_check_value
= 1;
2822 if (must_check_value
)
2824 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2826 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2827 int e
= catch_errors (watchpoint_check
, bs
, message
,
2829 do_cleanups (cleanups
);
2833 /* We've already printed what needs to be printed. */
2834 bs
->print_it
= print_it_done
;
2837 case WP_VALUE_CHANGED
:
2838 if (b
->type
== bp_read_watchpoint
)
2840 /* Don't stop: read watchpoints shouldn't fire if
2841 the value has changed. This is for targets
2842 which cannot set read-only watchpoints. */
2843 bs
->print_it
= print_it_noop
;
2847 case WP_VALUE_NOT_CHANGED
:
2848 if (b
->type
== bp_hardware_watchpoint
2849 || b
->type
== bp_watchpoint
)
2851 /* Don't stop: write watchpoints shouldn't fire if
2852 the value hasn't changed. */
2853 bs
->print_it
= print_it_noop
;
2861 /* Error from catch_errors. */
2862 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2863 if (b
->related_breakpoint
)
2864 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2865 b
->disposition
= disp_del_at_next_stop
;
2866 /* We've already printed what needs to be printed. */
2867 bs
->print_it
= print_it_done
;
2871 else /* must_check_value == 0 */
2873 /* This is a case where some watchpoint(s) triggered, but
2874 not at the address of this watchpoint, or else no
2875 watchpoint triggered after all. So don't print
2876 anything for this watchpoint. */
2877 bs
->print_it
= print_it_noop
;
2884 /* Check conditions (condition proper, frame, thread and ignore count)
2885 of breakpoint referred to by BS. If we should not stop for this
2886 breakpoint, set BS->stop to 0. */
2888 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2890 int thread_id
= pid_to_thread_id (ptid
);
2891 const struct bp_location
*bl
= bs
->breakpoint_at
;
2892 struct breakpoint
*b
= bl
->owner
;
2894 if (frame_id_p (b
->frame_id
)
2895 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2899 int value_is_zero
= 0;
2901 /* If this is a scope breakpoint, mark the associated
2902 watchpoint as triggered so that we will handle the
2903 out-of-scope event. We'll get to the watchpoint next
2905 if (b
->type
== bp_watchpoint_scope
)
2906 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2908 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2910 /* We use value_mark and value_free_to_mark because it could
2911 be a long time before we return to the command level and
2912 call free_all_values. We can't call free_all_values
2913 because we might be in the middle of evaluating a
2915 struct value
*mark
= value_mark ();
2917 /* Need to select the frame, with all that implies
2918 so that the conditions will have the right context. */
2919 select_frame (get_current_frame ());
2921 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2922 "Error in testing breakpoint condition:\n",
2924 /* FIXME-someday, should give breakpoint # */
2925 value_free_to_mark (mark
);
2927 if (bl
->cond
&& value_is_zero
)
2931 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2935 else if (b
->ignore_count
> 0)
2938 annotate_ignore_count_change ();
2940 /* Increase the hit count even though we don't
2948 /* Get a bpstat associated with having just stopped at address
2949 BP_ADDR in thread PTID.
2951 Determine whether we stopped at a breakpoint, etc, or whether we
2952 don't understand this stop. Result is a chain of bpstat's such that:
2954 if we don't understand the stop, the result is a null pointer.
2956 if we understand why we stopped, the result is not null.
2958 Each element of the chain refers to a particular breakpoint or
2959 watchpoint at which we have stopped. (We may have stopped for
2960 several reasons concurrently.)
2962 Each element of the chain has valid next, breakpoint_at,
2963 commands, FIXME??? fields. */
2966 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2968 struct breakpoint
*b
= NULL
;
2969 const struct bp_location
*bl
;
2970 struct bp_location
*loc
;
2971 /* Root of the chain of bpstat's */
2972 struct bpstats root_bs
[1];
2973 /* Pointer to the last thing in the chain currently. */
2974 bpstat bs
= root_bs
;
2976 int need_remove_insert
;
2978 ALL_BP_LOCATIONS (bl
)
2982 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2985 /* For hardware watchpoints, we look only at the first location.
2986 The watchpoint_check function will work on entire expression,
2987 not the individual locations. For read watchopints, the
2988 watchpoints_triggered function have checked all locations
2991 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2994 if (!bpstat_check_location (bl
, bp_addr
))
2997 /* Come here if it's a watchpoint, or if the break address matches */
2999 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3001 /* Assume we stop. Should we find watchpoint that is not actually
3002 triggered, or if condition of breakpoint is false, we'll reset
3007 bpstat_check_watchpoint (bs
);
3011 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3012 /* We do not stop for these. */
3015 bpstat_check_breakpoint_conditions (bs
, ptid
);
3021 /* We will stop here */
3022 if (b
->disposition
== disp_disable
)
3024 if (b
->enable_state
!= bp_permanent
)
3025 b
->enable_state
= bp_disabled
;
3026 update_global_location_list (0);
3030 bs
->commands
= b
->commands
;
3032 (strcmp ("silent", bs
->commands
->line
) == 0
3033 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3035 bs
->commands
= bs
->commands
->next
;
3038 bs
->commands
= copy_command_lines (bs
->commands
);
3041 /* Print nothing for this entry if we dont stop or if we dont print. */
3042 if (bs
->stop
== 0 || bs
->print
== 0)
3043 bs
->print_it
= print_it_noop
;
3046 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3048 if (loc
->address
== bp_addr
)
3050 bs
= bpstat_alloc (loc
, bs
);
3051 /* For hits of moribund locations, we should just proceed. */
3054 bs
->print_it
= print_it_noop
;
3058 bs
->next
= NULL
; /* Terminate the chain */
3059 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3061 /* If we aren't stopping, the value of some hardware watchpoint may
3062 not have changed, but the intermediate memory locations we are
3063 watching may have. Don't bother if we're stopping; this will get
3065 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3069 need_remove_insert
= 0;
3071 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3073 && bs
->breakpoint_at
->owner
3074 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3075 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3076 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3078 /* remove/insert can invalidate bs->breakpoint_at, if this
3079 location is no longer used by the watchpoint. Prevent
3080 further code from trying to use it. */
3081 bs
->breakpoint_at
= NULL
;
3082 need_remove_insert
= 1;
3085 if (need_remove_insert
)
3087 remove_breakpoints ();
3088 insert_breakpoints ();
3091 return root_bs
->next
;
3094 /* Tell what to do about this bpstat. */
3096 bpstat_what (bpstat bs
)
3098 /* Classify each bpstat as one of the following. */
3101 /* This bpstat element has no effect on the main_action. */
3104 /* There was a watchpoint, stop but don't print. */
3107 /* There was a watchpoint, stop and print. */
3110 /* There was a breakpoint but we're not stopping. */
3113 /* There was a breakpoint, stop but don't print. */
3116 /* There was a breakpoint, stop and print. */
3119 /* We hit the longjmp breakpoint. */
3122 /* We hit the longjmp_resume breakpoint. */
3125 /* We hit the step_resume breakpoint. */
3128 /* We hit the shared library event breakpoint. */
3131 /* This is just used to count how many enums there are. */
3135 /* Here is the table which drives this routine. So that we can
3136 format it pretty, we define some abbreviations for the
3137 enum bpstat_what codes. */
3138 #define kc BPSTAT_WHAT_KEEP_CHECKING
3139 #define ss BPSTAT_WHAT_STOP_SILENT
3140 #define sn BPSTAT_WHAT_STOP_NOISY
3141 #define sgl BPSTAT_WHAT_SINGLE
3142 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3143 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3144 #define sr BPSTAT_WHAT_STEP_RESUME
3145 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3147 /* "Can't happen." Might want to print an error message.
3148 abort() is not out of the question, but chances are GDB is just
3149 a bit confused, not unusable. */
3150 #define err BPSTAT_WHAT_STOP_NOISY
3152 /* Given an old action and a class, come up with a new action. */
3153 /* One interesting property of this table is that wp_silent is the same
3154 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3155 after stopping, the check for whether to step over a breakpoint
3156 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3157 reference to how we stopped. We retain separate wp_silent and
3158 bp_silent codes in case we want to change that someday.
3160 Another possibly interesting property of this table is that
3161 there's a partial ordering, priority-like, of the actions. Once
3162 you've decided that some action is appropriate, you'll never go
3163 back and decide something of a lower priority is better. The
3166 kc < clr sgl shl slr sn sr ss
3167 sgl < shl slr sn sr ss
3168 slr < err shl sn sr ss
3169 clr < err shl sn sr ss
3175 What I think this means is that we don't need a damned table
3176 here. If you just put the rows and columns in the right order,
3177 it'd look awfully regular. We could simply walk the bpstat list
3178 and choose the highest priority action we find, with a little
3179 logic to handle the 'err' cases. */
3181 /* step_resume entries: a step resume breakpoint overrides another
3182 breakpoint of signal handling (see comment in wait_for_inferior
3183 at where we set the step_resume breakpoint). */
3185 static const enum bpstat_what_main_action
3186 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3189 /* kc ss sn sgl slr clr sr shl
3192 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3194 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3196 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3198 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3200 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3202 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3204 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3206 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3208 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3210 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3223 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3224 struct bpstat_what retval
;
3226 retval
.call_dummy
= 0;
3227 for (; bs
!= NULL
; bs
= bs
->next
)
3229 enum class bs_class
= no_effect
;
3230 if (bs
->breakpoint_at
== NULL
)
3231 /* I suspect this can happen if it was a momentary breakpoint
3232 which has since been deleted. */
3234 if (bs
->breakpoint_at
->owner
== NULL
)
3235 bs_class
= bp_nostop
;
3237 switch (bs
->breakpoint_at
->owner
->type
)
3243 case bp_hardware_breakpoint
:
3249 bs_class
= bp_noisy
;
3251 bs_class
= bp_silent
;
3254 bs_class
= bp_nostop
;
3257 case bp_hardware_watchpoint
:
3258 case bp_read_watchpoint
:
3259 case bp_access_watchpoint
:
3263 bs_class
= wp_noisy
;
3265 bs_class
= wp_silent
;
3268 /* There was a watchpoint, but we're not stopping.
3269 This requires no further action. */
3270 bs_class
= no_effect
;
3273 bs_class
= long_jump
;
3275 case bp_longjmp_resume
:
3276 bs_class
= long_resume
;
3278 case bp_step_resume
:
3281 bs_class
= step_resume
;
3284 /* It is for the wrong frame. */
3285 bs_class
= bp_nostop
;
3287 case bp_watchpoint_scope
:
3288 bs_class
= bp_nostop
;
3290 case bp_shlib_event
:
3291 bs_class
= shlib_event
;
3293 case bp_thread_event
:
3294 case bp_overlay_event
:
3295 bs_class
= bp_nostop
;
3301 bs_class
= bp_noisy
;
3303 bs_class
= bp_silent
;
3306 /* There was a catchpoint, but we're not stopping.
3307 This requires no further action. */
3308 bs_class
= no_effect
;
3311 /* Make sure the action is stop (silent or noisy),
3312 so infrun.c pops the dummy frame. */
3313 bs_class
= bp_silent
;
3314 retval
.call_dummy
= 1;
3317 current_action
= table
[(int) bs_class
][(int) current_action
];
3319 retval
.main_action
= current_action
;
3323 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3324 without hardware support). This isn't related to a specific bpstat,
3325 just to things like whether watchpoints are set. */
3328 bpstat_should_step (void)
3330 struct breakpoint
*b
;
3332 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3339 static void print_breakpoint_location (struct breakpoint
*b
,
3340 struct bp_location
*loc
,
3342 struct ui_stream
*stb
)
3347 = find_pc_sect_function (loc
->address
, loc
->section
);
3350 ui_out_text (uiout
, "in ");
3351 ui_out_field_string (uiout
, "func",
3352 SYMBOL_PRINT_NAME (sym
));
3353 ui_out_wrap_hint (uiout
, wrap_indent
);
3354 ui_out_text (uiout
, " at ");
3356 ui_out_field_string (uiout
, "file", b
->source_file
);
3357 ui_out_text (uiout
, ":");
3359 if (ui_out_is_mi_like_p (uiout
))
3361 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3362 char *fullname
= symtab_to_fullname (sal
.symtab
);
3365 ui_out_field_string (uiout
, "fullname", fullname
);
3368 ui_out_field_int (uiout
, "line", b
->line_number
);
3372 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3376 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3377 ui_out_field_stream (uiout
, "at", stb
);
3381 /* Print B to gdb_stdout. */
3383 print_one_breakpoint_location (struct breakpoint
*b
,
3384 struct bp_location
*loc
,
3386 CORE_ADDR
*last_addr
)
3388 struct command_line
*l
;
3390 struct ep_type_description
3395 static struct ep_type_description bptypes
[] =
3397 {bp_none
, "?deleted?"},
3398 {bp_breakpoint
, "breakpoint"},
3399 {bp_hardware_breakpoint
, "hw breakpoint"},
3400 {bp_until
, "until"},
3401 {bp_finish
, "finish"},
3402 {bp_watchpoint
, "watchpoint"},
3403 {bp_hardware_watchpoint
, "hw watchpoint"},
3404 {bp_read_watchpoint
, "read watchpoint"},
3405 {bp_access_watchpoint
, "acc watchpoint"},
3406 {bp_longjmp
, "longjmp"},
3407 {bp_longjmp_resume
, "longjmp resume"},
3408 {bp_step_resume
, "step resume"},
3409 {bp_watchpoint_scope
, "watchpoint scope"},
3410 {bp_call_dummy
, "call dummy"},
3411 {bp_shlib_event
, "shlib events"},
3412 {bp_thread_event
, "thread events"},
3413 {bp_overlay_event
, "overlay events"},
3414 {bp_catchpoint
, "catchpoint"},
3417 static char bpenables
[] = "nynny";
3418 char wrap_indent
[80];
3419 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3420 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3421 struct cleanup
*bkpt_chain
;
3423 int header_of_multiple
= 0;
3424 int part_of_multiple
= (loc
!= NULL
);
3425 struct value_print_options opts
;
3427 get_user_print_options (&opts
);
3429 gdb_assert (!loc
|| loc_number
!= 0);
3430 /* See comment in print_one_breakpoint concerning
3431 treatment of breakpoints with single disabled
3435 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3436 header_of_multiple
= 1;
3441 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3445 if (part_of_multiple
)
3448 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3449 ui_out_field_string (uiout
, "number", formatted
);
3454 ui_out_field_int (uiout
, "number", b
->number
);
3459 if (part_of_multiple
)
3460 ui_out_field_skip (uiout
, "type");
3463 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3464 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3465 internal_error (__FILE__
, __LINE__
,
3466 _("bptypes table does not describe type #%d."),
3468 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3473 if (part_of_multiple
)
3474 ui_out_field_skip (uiout
, "disp");
3476 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3481 if (part_of_multiple
)
3482 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3484 ui_out_field_fmt (uiout
, "enabled", "%c",
3485 bpenables
[(int) b
->enable_state
]);
3486 ui_out_spaces (uiout
, 2);
3490 strcpy (wrap_indent
, " ");
3491 if (opts
.addressprint
)
3493 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3494 strcat (wrap_indent
, " ");
3496 strcat (wrap_indent
, " ");
3499 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3501 /* Although the print_one can possibly print
3502 all locations, calling it here is not likely
3503 to get any nice result. So, make sure there's
3504 just one location. */
3505 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3506 b
->ops
->print_one (b
, last_addr
);
3512 internal_error (__FILE__
, __LINE__
,
3513 _("print_one_breakpoint: bp_none encountered\n"));
3517 case bp_hardware_watchpoint
:
3518 case bp_read_watchpoint
:
3519 case bp_access_watchpoint
:
3520 /* Field 4, the address, is omitted (which makes the columns
3521 not line up too nicely with the headers, but the effect
3522 is relatively readable). */
3523 if (opts
.addressprint
)
3524 ui_out_field_skip (uiout
, "addr");
3526 ui_out_field_string (uiout
, "what", b
->exp_string
);
3530 case bp_hardware_breakpoint
:
3534 case bp_longjmp_resume
:
3535 case bp_step_resume
:
3536 case bp_watchpoint_scope
:
3538 case bp_shlib_event
:
3539 case bp_thread_event
:
3540 case bp_overlay_event
:
3541 if (opts
.addressprint
)
3544 if (header_of_multiple
)
3545 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3546 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3547 ui_out_field_string (uiout
, "addr", "<PENDING>");
3549 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3552 if (!header_of_multiple
)
3553 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3555 *last_addr
= b
->loc
->address
;
3559 if (!part_of_multiple
&& b
->thread
!= -1)
3561 /* FIXME: This seems to be redundant and lost here; see the
3562 "stop only in" line a little further down. */
3563 ui_out_text (uiout
, " thread ");
3564 ui_out_field_int (uiout
, "thread", b
->thread
);
3567 ui_out_text (uiout
, "\n");
3569 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3572 ui_out_text (uiout
, "\tstop only in stack frame at ");
3573 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3575 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3576 ui_out_text (uiout
, "\n");
3579 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3581 /* We do not print the condition for Ada exception catchpoints
3582 because the condition is an internal implementation detail
3583 that we do not want to expose to the user. */
3585 ui_out_text (uiout
, "\tstop only if ");
3586 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3587 ui_out_text (uiout
, "\n");
3590 if (!part_of_multiple
&& b
->thread
!= -1)
3592 /* FIXME should make an annotation for this */
3593 ui_out_text (uiout
, "\tstop only in thread ");
3594 ui_out_field_int (uiout
, "thread", b
->thread
);
3595 ui_out_text (uiout
, "\n");
3598 if (!part_of_multiple
&& b
->hit_count
)
3600 /* FIXME should make an annotation for this */
3601 if (ep_is_catchpoint (b
))
3602 ui_out_text (uiout
, "\tcatchpoint");
3604 ui_out_text (uiout
, "\tbreakpoint");
3605 ui_out_text (uiout
, " already hit ");
3606 ui_out_field_int (uiout
, "times", b
->hit_count
);
3607 if (b
->hit_count
== 1)
3608 ui_out_text (uiout
, " time\n");
3610 ui_out_text (uiout
, " times\n");
3613 /* Output the count also if it is zero, but only if this is
3614 mi. FIXME: Should have a better test for this. */
3615 if (ui_out_is_mi_like_p (uiout
))
3616 if (!part_of_multiple
&& b
->hit_count
== 0)
3617 ui_out_field_int (uiout
, "times", b
->hit_count
);
3619 if (!part_of_multiple
&& b
->ignore_count
)
3622 ui_out_text (uiout
, "\tignore next ");
3623 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3624 ui_out_text (uiout
, " hits\n");
3627 if (!part_of_multiple
&& (l
= b
->commands
))
3629 struct cleanup
*script_chain
;
3632 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3633 print_command_lines (uiout
, l
, 4);
3634 do_cleanups (script_chain
);
3637 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3640 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3641 else if (b
->exp_string
)
3642 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3645 do_cleanups (bkpt_chain
);
3646 do_cleanups (old_chain
);
3650 print_one_breakpoint (struct breakpoint
*b
,
3651 CORE_ADDR
*last_addr
)
3653 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3655 /* If this breakpoint has custom print function,
3656 it's already printed. Otherwise, print individual
3657 locations, if any. */
3658 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3660 /* If breakpoint has a single location that is
3661 disabled, we print it as if it had
3662 several locations, since otherwise it's hard to
3663 represent "breakpoint enabled, location disabled"
3665 Note that while hardware watchpoints have
3666 several locations internally, that's no a property
3669 && !is_hardware_watchpoint (b
)
3670 && (b
->loc
->next
|| !b
->loc
->enabled
)
3671 && !ui_out_is_mi_like_p (uiout
))
3673 struct bp_location
*loc
;
3675 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3676 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3682 struct captured_breakpoint_query_args
3688 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3690 struct captured_breakpoint_query_args
*args
= data
;
3691 struct breakpoint
*b
;
3692 CORE_ADDR dummy_addr
= 0;
3695 if (args
->bnum
== b
->number
)
3697 print_one_breakpoint (b
, &dummy_addr
);
3705 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3707 struct captured_breakpoint_query_args args
;
3709 /* For the moment we don't trust print_one_breakpoint() to not throw
3711 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3712 error_message
, RETURN_MASK_ALL
) < 0)
3718 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3719 catchpoints, et.al.). */
3722 user_settable_breakpoint (const struct breakpoint
*b
)
3724 return (b
->type
== bp_breakpoint
3725 || b
->type
== bp_catchpoint
3726 || b
->type
== bp_hardware_breakpoint
3727 || b
->type
== bp_watchpoint
3728 || b
->type
== bp_read_watchpoint
3729 || b
->type
== bp_access_watchpoint
3730 || b
->type
== bp_hardware_watchpoint
);
3733 /* Print information on user settable breakpoint (watchpoint, etc)
3734 number BNUM. If BNUM is -1 print all user settable breakpoints.
3735 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3738 breakpoint_1 (int bnum
, int allflag
)
3740 struct breakpoint
*b
;
3741 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3742 int nr_printable_breakpoints
;
3743 struct cleanup
*bkpttbl_chain
;
3744 struct value_print_options opts
;
3746 get_user_print_options (&opts
);
3748 /* Compute the number of rows in the table. */
3749 nr_printable_breakpoints
= 0;
3752 || bnum
== b
->number
)
3754 if (allflag
|| user_settable_breakpoint (b
))
3755 nr_printable_breakpoints
++;
3758 if (opts
.addressprint
)
3760 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3764 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3767 if (nr_printable_breakpoints
> 0)
3768 annotate_breakpoints_headers ();
3769 if (nr_printable_breakpoints
> 0)
3771 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3772 if (nr_printable_breakpoints
> 0)
3774 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3775 if (nr_printable_breakpoints
> 0)
3777 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3778 if (nr_printable_breakpoints
> 0)
3780 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3781 if (opts
.addressprint
)
3783 if (nr_printable_breakpoints
> 0)
3785 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3786 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3788 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3790 if (nr_printable_breakpoints
> 0)
3792 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3793 ui_out_table_body (uiout
);
3794 if (nr_printable_breakpoints
> 0)
3795 annotate_breakpoints_table ();
3799 || bnum
== b
->number
)
3801 /* We only print out user settable breakpoints unless the
3803 if (allflag
|| user_settable_breakpoint (b
))
3804 print_one_breakpoint (b
, &last_addr
);
3807 do_cleanups (bkpttbl_chain
);
3809 if (nr_printable_breakpoints
== 0)
3812 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3814 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3819 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3820 that a comparison of an unsigned with -1 is always false. */
3821 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3822 set_next_address (current_gdbarch
, last_addr
);
3825 /* FIXME? Should this be moved up so that it is only called when
3826 there have been breakpoints? */
3827 annotate_breakpoints_table_end ();
3831 breakpoints_info (char *bnum_exp
, int from_tty
)
3836 bnum
= parse_and_eval_long (bnum_exp
);
3838 breakpoint_1 (bnum
, 0);
3842 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3847 bnum
= parse_and_eval_long (bnum_exp
);
3849 breakpoint_1 (bnum
, 1);
3853 breakpoint_has_pc (struct breakpoint
*b
,
3854 CORE_ADDR pc
, struct obj_section
*section
)
3856 struct bp_location
*bl
= b
->loc
;
3857 for (; bl
; bl
= bl
->next
)
3859 if (bl
->address
== pc
3860 && (!overlay_debugging
|| bl
->section
== section
))
3866 /* Print a message describing any breakpoints set at PC. */
3869 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3873 struct breakpoint
*b
;
3876 others
+= breakpoint_has_pc (b
, pc
, section
);
3880 printf_filtered (_("Note: breakpoint "));
3881 else /* if (others == ???) */
3882 printf_filtered (_("Note: breakpoints "));
3884 if (breakpoint_has_pc (b
, pc
, section
))
3887 printf_filtered ("%d", b
->number
);
3888 if (b
->thread
== -1 && thread
!= -1)
3889 printf_filtered (" (all threads)");
3890 else if (b
->thread
!= -1)
3891 printf_filtered (" (thread %d)", b
->thread
);
3892 printf_filtered ("%s%s ",
3893 ((b
->enable_state
== bp_disabled
||
3894 b
->enable_state
== bp_call_disabled
)
3896 : b
->enable_state
== bp_permanent
3900 : ((others
== 1) ? " and" : ""));
3902 printf_filtered (_("also set at pc "));
3903 fputs_filtered (paddress (pc
), gdb_stdout
);
3904 printf_filtered (".\n");
3908 /* Set the default place to put a breakpoint
3909 for the `break' command with no arguments. */
3912 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3915 default_breakpoint_valid
= valid
;
3916 default_breakpoint_address
= addr
;
3917 default_breakpoint_symtab
= symtab
;
3918 default_breakpoint_line
= line
;
3921 /* Return true iff it is meaningful to use the address member of
3922 BPT. For some breakpoint types, the address member is irrelevant
3923 and it makes no sense to attempt to compare it to other addresses
3924 (or use it for any other purpose either).
3926 More specifically, each of the following breakpoint types will always
3927 have a zero valued address and we don't want check_duplicates() to mark
3928 breakpoints of any of these types to be a duplicate of an actual
3929 breakpoint at address zero:
3932 bp_hardware_watchpoint
3934 bp_access_watchpoint
3938 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3940 enum bptype type
= bpt
->type
;
3942 return (type
!= bp_watchpoint
3943 && type
!= bp_hardware_watchpoint
3944 && type
!= bp_read_watchpoint
3945 && type
!= bp_access_watchpoint
3946 && type
!= bp_catchpoint
);
3949 /* Rescan breakpoints at the same address and section as BPT,
3950 marking the first one as "first" and any others as "duplicates".
3951 This is so that the bpt instruction is only inserted once.
3952 If we have a permanent breakpoint at the same place as BPT, make
3953 that one the official one, and the rest as duplicates. */
3956 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
3958 struct bp_location
*b
;
3960 struct bp_location
*perm_bp
= 0;
3962 ALL_BP_LOCATIONS (b
)
3963 if (b
->owner
->enable_state
!= bp_disabled
3964 && b
->owner
->enable_state
!= bp_call_disabled
3966 && !b
->shlib_disabled
3967 && b
->address
== address
/* address / overlay match */
3968 && (!overlay_debugging
|| b
->section
== section
)
3969 && breakpoint_address_is_meaningful (b
->owner
))
3971 /* Have we found a permanent breakpoint? */
3972 if (b
->owner
->enable_state
== bp_permanent
)
3979 b
->duplicate
= count
> 1;
3982 /* If we found a permanent breakpoint at this address, go over the
3983 list again and declare all the other breakpoints there (except
3984 other permanent breakpoints) to be the duplicates. */
3987 perm_bp
->duplicate
= 0;
3989 /* Permanent breakpoint should always be inserted. */
3990 if (! perm_bp
->inserted
)
3991 internal_error (__FILE__
, __LINE__
,
3992 _("allegedly permanent breakpoint is not "
3993 "actually inserted"));
3995 ALL_BP_LOCATIONS (b
)
3998 if (b
->owner
->enable_state
!= bp_permanent
3999 && b
->owner
->enable_state
!= bp_disabled
4000 && b
->owner
->enable_state
!= bp_call_disabled
4001 && b
->enabled
&& !b
->shlib_disabled
4002 && b
->address
== address
/* address / overlay match */
4003 && (!overlay_debugging
|| b
->section
== section
)
4004 && breakpoint_address_is_meaningful (b
->owner
))
4007 internal_error (__FILE__
, __LINE__
,
4008 _("another breakpoint was inserted on top of "
4009 "a permanent breakpoint"));
4018 check_duplicates (struct breakpoint
*bpt
)
4020 struct bp_location
*bl
= bpt
->loc
;
4022 if (! breakpoint_address_is_meaningful (bpt
))
4025 for (; bl
; bl
= bl
->next
)
4026 check_duplicates_for (bl
->address
, bl
->section
);
4030 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4031 int bnum
, int have_bnum
)
4036 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4037 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4039 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4040 bnum
, astr1
, astr2
);
4042 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4045 /* Adjust a breakpoint's address to account for architectural constraints
4046 on breakpoint placement. Return the adjusted address. Note: Very
4047 few targets require this kind of adjustment. For most targets,
4048 this function is simply the identity function. */
4051 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4053 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4055 /* Very few targets need any kind of breakpoint adjustment. */
4058 else if (bptype
== bp_watchpoint
4059 || bptype
== bp_hardware_watchpoint
4060 || bptype
== bp_read_watchpoint
4061 || bptype
== bp_access_watchpoint
4062 || bptype
== bp_catchpoint
)
4064 /* Watchpoints and the various bp_catch_* eventpoints should not
4065 have their addresses modified. */
4070 CORE_ADDR adjusted_bpaddr
;
4072 /* Some targets have architectural constraints on the placement
4073 of breakpoint instructions. Obtain the adjusted address. */
4074 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4077 /* An adjusted breakpoint address can significantly alter
4078 a user's expectations. Print a warning if an adjustment
4080 if (adjusted_bpaddr
!= bpaddr
)
4081 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4083 return adjusted_bpaddr
;
4087 /* Allocate a struct bp_location. */
4089 static struct bp_location
*
4090 allocate_bp_location (struct breakpoint
*bpt
)
4092 struct bp_location
*loc
, *loc_p
;
4094 loc
= xmalloc (sizeof (struct bp_location
));
4095 memset (loc
, 0, sizeof (*loc
));
4099 loc
->shlib_disabled
= 0;
4108 case bp_longjmp_resume
:
4109 case bp_step_resume
:
4110 case bp_watchpoint_scope
:
4112 case bp_shlib_event
:
4113 case bp_thread_event
:
4114 case bp_overlay_event
:
4115 loc
->loc_type
= bp_loc_software_breakpoint
;
4117 case bp_hardware_breakpoint
:
4118 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4120 case bp_hardware_watchpoint
:
4121 case bp_read_watchpoint
:
4122 case bp_access_watchpoint
:
4123 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4127 loc
->loc_type
= bp_loc_other
;
4130 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4136 static void free_bp_location (struct bp_location
*loc
)
4141 if (loc
->function_name
)
4142 xfree (loc
->function_name
);
4147 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4148 that has type BPTYPE and has no locations as yet. */
4150 static struct breakpoint
*
4151 set_raw_breakpoint_without_location (enum bptype bptype
)
4153 struct breakpoint
*b
, *b1
;
4155 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4156 memset (b
, 0, sizeof (*b
));
4159 b
->language
= current_language
->la_language
;
4160 b
->input_radix
= input_radix
;
4162 b
->enable_state
= bp_enabled
;
4165 b
->ignore_count
= 0;
4167 b
->frame_id
= null_frame_id
;
4168 b
->forked_inferior_pid
= null_ptid
;
4169 b
->exec_pathname
= NULL
;
4171 b
->condition_not_parsed
= 0;
4173 /* Add this breakpoint to the end of the chain
4174 so that a list of breakpoints will come out in order
4175 of increasing numbers. */
4177 b1
= breakpoint_chain
;
4179 breakpoint_chain
= b
;
4189 /* Initialize loc->function_name. */
4191 set_breakpoint_location_function (struct bp_location
*loc
)
4193 if (loc
->owner
->type
== bp_breakpoint
4194 || loc
->owner
->type
== bp_hardware_breakpoint
)
4196 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4198 if (loc
->function_name
)
4199 loc
->function_name
= xstrdup (loc
->function_name
);
4203 /* set_raw_breakpoint is a low level routine for allocating and
4204 partially initializing a breakpoint of type BPTYPE. The newly
4205 created breakpoint's address, section, source file name, and line
4206 number are provided by SAL. The newly created and partially
4207 initialized breakpoint is added to the breakpoint chain and
4208 is also returned as the value of this function.
4210 It is expected that the caller will complete the initialization of
4211 the newly created breakpoint struct as well as output any status
4212 information regarding the creation of a new breakpoint. In
4213 particular, set_raw_breakpoint does NOT set the breakpoint
4214 number! Care should be taken to not allow an error to occur
4215 prior to completing the initialization of the breakpoint. If this
4216 should happen, a bogus breakpoint will be left on the chain. */
4219 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4221 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4222 CORE_ADDR adjusted_address
;
4224 /* Adjust the breakpoint's address prior to allocating a location.
4225 Once we call allocate_bp_location(), that mostly uninitialized
4226 location will be placed on the location chain. Adjustment of the
4227 breakpoint may cause target_read_memory() to be called and we do
4228 not want its scan of the location chain to find a breakpoint and
4229 location that's only been partially initialized. */
4230 adjusted_address
= adjust_breakpoint_address (sal
.pc
, b
->type
);
4232 b
->loc
= allocate_bp_location (b
);
4233 b
->loc
->requested_address
= sal
.pc
;
4234 b
->loc
->address
= adjusted_address
;
4236 if (sal
.symtab
== NULL
)
4237 b
->source_file
= NULL
;
4239 b
->source_file
= savestring (sal
.symtab
->filename
,
4240 strlen (sal
.symtab
->filename
));
4241 b
->loc
->section
= sal
.section
;
4242 b
->line_number
= sal
.line
;
4244 set_breakpoint_location_function (b
->loc
);
4246 breakpoints_changed ();
4252 /* Note that the breakpoint object B describes a permanent breakpoint
4253 instruction, hard-wired into the inferior's code. */
4255 make_breakpoint_permanent (struct breakpoint
*b
)
4257 struct bp_location
*bl
;
4258 b
->enable_state
= bp_permanent
;
4260 /* By definition, permanent breakpoints are already present in the code.
4261 Mark all locations as inserted. For now, make_breakpoint_permanent
4262 is called in just one place, so it's hard to say if it's reasonable
4263 to have permanent breakpoint with multiple locations or not,
4264 but it's easy to implmement. */
4265 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4269 static struct breakpoint
*
4270 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4272 static int internal_breakpoint_number
= -1;
4273 struct symtab_and_line sal
;
4274 struct breakpoint
*b
;
4276 init_sal (&sal
); /* initialize to zeroes */
4279 sal
.section
= find_pc_overlay (sal
.pc
);
4281 b
= set_raw_breakpoint (sal
, type
);
4282 b
->number
= internal_breakpoint_number
--;
4283 b
->disposition
= disp_donttouch
;
4290 create_longjmp_breakpoint (char *func_name
)
4292 struct minimal_symbol
*m
;
4294 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4296 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4297 update_global_location_list (1);
4300 /* Call this routine when stepping and nexting to enable a breakpoint
4301 if we do a longjmp(). When we hit that breakpoint, call
4302 set_longjmp_resume_breakpoint() to figure out where we are going. */
4305 set_longjmp_breakpoint (void)
4307 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4309 create_longjmp_breakpoint ("longjmp");
4310 create_longjmp_breakpoint ("_longjmp");
4311 create_longjmp_breakpoint ("siglongjmp");
4312 create_longjmp_breakpoint ("_siglongjmp");
4316 /* Delete all longjmp breakpoints from THREAD. */
4318 delete_longjmp_breakpoint (int thread
)
4320 struct breakpoint
*b
, *temp
;
4322 ALL_BREAKPOINTS_SAFE (b
, temp
)
4323 if (b
->type
== bp_longjmp
)
4325 if (b
->thread
== thread
)
4326 delete_breakpoint (b
);
4331 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4333 struct breakpoint
*b
;
4334 struct minimal_symbol
*m
;
4336 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4339 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4341 b
->addr_string
= xstrdup (func_name
);
4343 if (overlay_debugging
== ovly_auto
)
4345 b
->enable_state
= bp_enabled
;
4346 overlay_events_enabled
= 1;
4350 b
->enable_state
= bp_disabled
;
4351 overlay_events_enabled
= 0;
4353 update_global_location_list (1);
4357 create_overlay_event_breakpoint (char *func_name
)
4359 struct objfile
*objfile
;
4360 ALL_OBJFILES (objfile
)
4361 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4365 enable_overlay_breakpoints (void)
4367 struct breakpoint
*b
;
4370 if (b
->type
== bp_overlay_event
)
4372 b
->enable_state
= bp_enabled
;
4373 update_global_location_list (1);
4374 overlay_events_enabled
= 1;
4379 disable_overlay_breakpoints (void)
4381 struct breakpoint
*b
;
4384 if (b
->type
== bp_overlay_event
)
4386 b
->enable_state
= bp_disabled
;
4387 update_global_location_list (0);
4388 overlay_events_enabled
= 0;
4393 create_thread_event_breakpoint (CORE_ADDR address
)
4395 struct breakpoint
*b
;
4397 b
= create_internal_breakpoint (address
, bp_thread_event
);
4399 b
->enable_state
= bp_enabled
;
4400 /* addr_string has to be used or breakpoint_re_set will delete me. */
4401 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4403 update_global_location_list_nothrow (1);
4409 remove_thread_event_breakpoints (void)
4411 struct breakpoint
*b
, *temp
;
4413 ALL_BREAKPOINTS_SAFE (b
, temp
)
4414 if (b
->type
== bp_thread_event
)
4415 delete_breakpoint (b
);
4418 struct captured_parse_breakpoint_args
4421 struct symtabs_and_lines
*sals_p
;
4422 char ***addr_string_p
;
4426 struct lang_and_radix
4434 remove_solib_event_breakpoints (void)
4436 struct breakpoint
*b
, *temp
;
4438 ALL_BREAKPOINTS_SAFE (b
, temp
)
4439 if (b
->type
== bp_shlib_event
)
4440 delete_breakpoint (b
);
4444 create_solib_event_breakpoint (CORE_ADDR address
)
4446 struct breakpoint
*b
;
4448 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4449 update_global_location_list_nothrow (1);
4453 /* Disable any breakpoints that are on code in shared libraries. Only
4454 apply to enabled breakpoints, disabled ones can just stay disabled. */
4457 disable_breakpoints_in_shlibs (void)
4459 struct bp_location
*loc
;
4461 ALL_BP_LOCATIONS (loc
)
4463 struct breakpoint
*b
= loc
->owner
;
4464 /* We apply the check to all breakpoints, including disabled
4465 for those with loc->duplicate set. This is so that when breakpoint
4466 becomes enabled, or the duplicate is removed, gdb will try to insert
4467 all breakpoints. If we don't set shlib_disabled here, we'll try
4468 to insert those breakpoints and fail. */
4469 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4470 && !loc
->shlib_disabled
4472 && PC_SOLIB (loc
->address
)
4474 && solib_name_from_address (loc
->address
)
4478 loc
->shlib_disabled
= 1;
4483 /* Disable any breakpoints that are in in an unloaded shared library. Only
4484 apply to enabled breakpoints, disabled ones can just stay disabled. */
4487 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4489 struct bp_location
*loc
;
4490 int disabled_shlib_breaks
= 0;
4492 /* SunOS a.out shared libraries are always mapped, so do not
4493 disable breakpoints; they will only be reported as unloaded
4494 through clear_solib when GDB discards its shared library
4495 list. See clear_solib for more information. */
4496 if (exec_bfd
!= NULL
4497 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4500 ALL_BP_LOCATIONS (loc
)
4502 struct breakpoint
*b
= loc
->owner
;
4503 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4504 || loc
->loc_type
== bp_loc_software_breakpoint
)
4505 && !loc
->shlib_disabled
4506 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4507 && solib_contains_address_p (solib
, loc
->address
))
4509 loc
->shlib_disabled
= 1;
4510 /* At this point, we cannot rely on remove_breakpoint
4511 succeeding so we must mark the breakpoint as not inserted
4512 to prevent future errors occurring in remove_breakpoints. */
4514 if (!disabled_shlib_breaks
)
4516 target_terminal_ours_for_output ();
4517 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4520 disabled_shlib_breaks
= 1;
4525 /* FORK & VFORK catchpoints. */
4527 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4530 insert_catch_fork (struct breakpoint
*b
)
4532 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4535 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4538 remove_catch_fork (struct breakpoint
*b
)
4540 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4543 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4547 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4549 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4552 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4554 static enum print_stop_action
4555 print_it_catch_fork (struct breakpoint
*b
)
4557 annotate_catchpoint (b
->number
);
4558 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4559 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4560 return PRINT_SRC_AND_LOC
;
4563 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4566 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4568 struct value_print_options opts
;
4570 get_user_print_options (&opts
);
4572 /* Field 4, the address, is omitted (which makes the columns
4573 not line up too nicely with the headers, but the effect
4574 is relatively readable). */
4575 if (opts
.addressprint
)
4576 ui_out_field_skip (uiout
, "addr");
4578 ui_out_text (uiout
, "fork");
4579 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4581 ui_out_text (uiout
, ", process ");
4582 ui_out_field_int (uiout
, "what",
4583 ptid_get_pid (b
->forked_inferior_pid
));
4584 ui_out_spaces (uiout
, 1);
4588 /* Implement the "print_mention" breakpoint_ops method for fork
4592 print_mention_catch_fork (struct breakpoint
*b
)
4594 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4597 /* The breakpoint_ops structure to be used in fork catchpoints. */
4599 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4603 breakpoint_hit_catch_fork
,
4604 print_it_catch_fork
,
4605 print_one_catch_fork
,
4606 print_mention_catch_fork
4609 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4612 insert_catch_vfork (struct breakpoint
*b
)
4614 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4617 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4620 remove_catch_vfork (struct breakpoint
*b
)
4622 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4625 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4629 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4631 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4634 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4636 static enum print_stop_action
4637 print_it_catch_vfork (struct breakpoint
*b
)
4639 annotate_catchpoint (b
->number
);
4640 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4641 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4642 return PRINT_SRC_AND_LOC
;
4645 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4648 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4650 struct value_print_options opts
;
4652 get_user_print_options (&opts
);
4653 /* Field 4, the address, is omitted (which makes the columns
4654 not line up too nicely with the headers, but the effect
4655 is relatively readable). */
4656 if (opts
.addressprint
)
4657 ui_out_field_skip (uiout
, "addr");
4659 ui_out_text (uiout
, "vfork");
4660 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4662 ui_out_text (uiout
, ", process ");
4663 ui_out_field_int (uiout
, "what",
4664 ptid_get_pid (b
->forked_inferior_pid
));
4665 ui_out_spaces (uiout
, 1);
4669 /* Implement the "print_mention" breakpoint_ops method for vfork
4673 print_mention_catch_vfork (struct breakpoint
*b
)
4675 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4678 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4680 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4684 breakpoint_hit_catch_vfork
,
4685 print_it_catch_vfork
,
4686 print_one_catch_vfork
,
4687 print_mention_catch_vfork
4690 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4692 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4693 If COND_STRING is not NULL, then store it in the breakpoint.
4694 OPS, if not NULL, is the breakpoint_ops structure associated
4695 to the catchpoint. */
4697 static struct breakpoint
*
4698 create_catchpoint (int tempflag
, char *cond_string
,
4699 struct breakpoint_ops
*ops
)
4701 struct symtab_and_line sal
;
4702 struct breakpoint
*b
;
4709 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4710 set_breakpoint_count (breakpoint_count
+ 1);
4711 b
->number
= breakpoint_count
;
4713 b
->cond_string
= (cond_string
== NULL
) ?
4714 NULL
: savestring (cond_string
, strlen (cond_string
));
4716 b
->addr_string
= NULL
;
4717 b
->enable_state
= bp_enabled
;
4718 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4722 update_global_location_list (1);
4728 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4729 struct breakpoint_ops
*ops
)
4731 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4733 /* FIXME: We should put this information in a breakpoint private data
4735 b
->forked_inferior_pid
= null_ptid
;
4738 /* Exec catchpoints. */
4741 insert_catch_exec (struct breakpoint
*b
)
4743 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4747 remove_catch_exec (struct breakpoint
*b
)
4749 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4753 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4755 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4758 static enum print_stop_action
4759 print_it_catch_exec (struct breakpoint
*b
)
4761 annotate_catchpoint (b
->number
);
4762 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4764 return PRINT_SRC_AND_LOC
;
4768 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4770 struct value_print_options opts
;
4772 get_user_print_options (&opts
);
4774 /* Field 4, the address, is omitted (which makes the columns
4775 not line up too nicely with the headers, but the effect
4776 is relatively readable). */
4777 if (opts
.addressprint
)
4778 ui_out_field_skip (uiout
, "addr");
4780 ui_out_text (uiout
, "exec");
4781 if (b
->exec_pathname
!= NULL
)
4783 ui_out_text (uiout
, ", program \"");
4784 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4785 ui_out_text (uiout
, "\" ");
4790 print_mention_catch_exec (struct breakpoint
*b
)
4792 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4795 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4799 breakpoint_hit_catch_exec
,
4800 print_it_catch_exec
,
4801 print_one_catch_exec
,
4802 print_mention_catch_exec
4806 hw_breakpoint_used_count (void)
4808 struct breakpoint
*b
;
4813 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4821 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4823 struct breakpoint
*b
;
4826 *other_type_used
= 0;
4829 if (breakpoint_enabled (b
))
4831 if (b
->type
== type
)
4833 else if ((b
->type
== bp_hardware_watchpoint
||
4834 b
->type
== bp_read_watchpoint
||
4835 b
->type
== bp_access_watchpoint
))
4836 *other_type_used
= 1;
4843 disable_watchpoints_before_interactive_call_start (void)
4845 struct breakpoint
*b
;
4849 if (((b
->type
== bp_watchpoint
)
4850 || (b
->type
== bp_hardware_watchpoint
)
4851 || (b
->type
== bp_read_watchpoint
)
4852 || (b
->type
== bp_access_watchpoint
))
4853 && breakpoint_enabled (b
))
4855 b
->enable_state
= bp_call_disabled
;
4856 update_global_location_list (0);
4862 enable_watchpoints_after_interactive_call_stop (void)
4864 struct breakpoint
*b
;
4868 if (((b
->type
== bp_watchpoint
)
4869 || (b
->type
== bp_hardware_watchpoint
)
4870 || (b
->type
== bp_read_watchpoint
)
4871 || (b
->type
== bp_access_watchpoint
))
4872 && (b
->enable_state
== bp_call_disabled
))
4874 b
->enable_state
= bp_enabled
;
4875 update_global_location_list (1);
4881 /* Set a breakpoint that will evaporate an end of command
4882 at address specified by SAL.
4883 Restrict it to frame FRAME if FRAME is nonzero. */
4886 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4889 struct breakpoint
*b
;
4890 b
= set_raw_breakpoint (sal
, type
);
4891 b
->enable_state
= bp_enabled
;
4892 b
->disposition
= disp_donttouch
;
4893 b
->frame_id
= frame_id
;
4895 /* If we're debugging a multi-threaded program, then we
4896 want momentary breakpoints to be active in only a
4897 single thread of control. */
4898 if (in_thread_list (inferior_ptid
))
4899 b
->thread
= pid_to_thread_id (inferior_ptid
);
4901 update_global_location_list_nothrow (1);
4907 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4909 struct symtab_and_line sal
;
4911 sal
= find_pc_line (pc
, 0);
4913 sal
.section
= find_pc_overlay (pc
);
4914 sal
.explicit_pc
= 1;
4916 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4920 /* Tell the user we have just set a breakpoint B. */
4923 mention (struct breakpoint
*b
)
4926 struct cleanup
*ui_out_chain
;
4927 struct value_print_options opts
;
4929 get_user_print_options (&opts
);
4931 /* FIXME: This is misplaced; mention() is called by things (like
4932 hitting a watchpoint) other than breakpoint creation. It should
4933 be possible to clean this up and at the same time replace the
4934 random calls to breakpoint_changed with this hook. */
4935 observer_notify_breakpoint_created (b
->number
);
4937 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4938 b
->ops
->print_mention (b
);
4943 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4946 ui_out_text (uiout
, "Watchpoint ");
4947 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4948 ui_out_field_int (uiout
, "number", b
->number
);
4949 ui_out_text (uiout
, ": ");
4950 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4951 do_cleanups (ui_out_chain
);
4953 case bp_hardware_watchpoint
:
4954 ui_out_text (uiout
, "Hardware watchpoint ");
4955 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4956 ui_out_field_int (uiout
, "number", b
->number
);
4957 ui_out_text (uiout
, ": ");
4958 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4959 do_cleanups (ui_out_chain
);
4961 case bp_read_watchpoint
:
4962 ui_out_text (uiout
, "Hardware read watchpoint ");
4963 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4964 ui_out_field_int (uiout
, "number", b
->number
);
4965 ui_out_text (uiout
, ": ");
4966 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4967 do_cleanups (ui_out_chain
);
4969 case bp_access_watchpoint
:
4970 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4971 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4972 ui_out_field_int (uiout
, "number", b
->number
);
4973 ui_out_text (uiout
, ": ");
4974 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4975 do_cleanups (ui_out_chain
);
4978 if (ui_out_is_mi_like_p (uiout
))
4983 if (b
->disposition
== disp_del
)
4984 printf_filtered (_("Temporary breakpoint"));
4986 printf_filtered (_("Breakpoint"));
4987 printf_filtered (_(" %d"), b
->number
);
4990 case bp_hardware_breakpoint
:
4991 if (ui_out_is_mi_like_p (uiout
))
4996 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5003 case bp_longjmp_resume
:
5004 case bp_step_resume
:
5006 case bp_watchpoint_scope
:
5007 case bp_shlib_event
:
5008 case bp_thread_event
:
5009 case bp_overlay_event
:
5015 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5019 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5023 if (opts
.addressprint
|| b
->source_file
== NULL
)
5025 printf_filtered (" at ");
5026 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5029 printf_filtered (": file %s, line %d.",
5030 b
->source_file
, b
->line_number
);
5034 struct bp_location
*loc
= b
->loc
;
5036 for (; loc
; loc
= loc
->next
)
5038 printf_filtered (" (%d locations)", n
);
5043 if (ui_out_is_mi_like_p (uiout
))
5045 printf_filtered ("\n");
5049 static struct bp_location
*
5050 add_location_to_breakpoint (struct breakpoint
*b
,
5051 const struct symtab_and_line
*sal
)
5053 struct bp_location
*loc
, **tmp
;
5055 loc
= allocate_bp_location (b
);
5056 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5059 loc
->requested_address
= sal
->pc
;
5060 loc
->address
= adjust_breakpoint_address (loc
->requested_address
, b
->type
);
5061 loc
->section
= sal
->section
;
5063 set_breakpoint_location_function (loc
);
5068 /* Return 1 if LOC is pointing to a permanent breakpoint,
5069 return 0 otherwise. */
5072 bp_loc_is_permanent (struct bp_location
*loc
)
5076 const gdb_byte
*brk
;
5077 gdb_byte
*target_mem
;
5078 struct cleanup
*cleanup
;
5081 gdb_assert (loc
!= NULL
);
5083 addr
= loc
->address
;
5084 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5086 /* Software breakpoints unsupported? */
5090 target_mem
= alloca (len
);
5092 /* Enable the automatic memory restoration from breakpoints while
5093 we read the memory. Otherwise we could say about our temporary
5094 breakpoints they are permanent. */
5095 cleanup
= make_show_memory_breakpoints_cleanup (0);
5097 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5098 && memcmp (target_mem
, brk
, len
) == 0)
5101 do_cleanups (cleanup
);
5108 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5109 as textual description of the location, and COND_STRING
5110 as condition expression. */
5113 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5115 enum bptype type
, enum bpdisp disposition
,
5116 int thread
, int ignore_count
,
5117 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5119 struct breakpoint
*b
= NULL
;
5122 if (type
== bp_hardware_breakpoint
)
5124 int i
= hw_breakpoint_used_count ();
5125 int target_resources_ok
=
5126 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5128 if (target_resources_ok
== 0)
5129 error (_("No hardware breakpoint support in the target."));
5130 else if (target_resources_ok
< 0)
5131 error (_("Hardware breakpoints used exceeds limit."));
5134 for (i
= 0; i
< sals
.nelts
; ++i
)
5136 struct symtab_and_line sal
= sals
.sals
[i
];
5137 struct bp_location
*loc
;
5140 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5144 b
= set_raw_breakpoint (sal
, type
);
5145 set_breakpoint_count (breakpoint_count
+ 1);
5146 b
->number
= breakpoint_count
;
5149 b
->cond_string
= cond_string
;
5150 b
->ignore_count
= ignore_count
;
5151 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5152 b
->disposition
= disposition
;
5158 loc
= add_location_to_breakpoint (b
, &sal
);
5161 if (bp_loc_is_permanent (loc
))
5162 make_breakpoint_permanent (b
);
5166 char *arg
= b
->cond_string
;
5167 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5169 error (_("Garbage %s follows condition"), arg
);
5174 b
->addr_string
= addr_string
;
5176 /* addr_string has to be used or breakpoint_re_set will delete
5178 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5184 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5185 elements to fill the void space. */
5187 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5189 int i
= index_to_remove
+1;
5190 int last_index
= sal
->nelts
-1;
5192 for (;i
<= last_index
; ++i
)
5193 sal
->sals
[i
-1] = sal
->sals
[i
];
5198 /* If appropriate, obtains all sals that correspond
5199 to the same file and line as SAL. This is done
5200 only if SAL does not have explicit PC and has
5201 line and file information. If we got just a single
5202 expanded sal, return the original.
5204 Otherwise, if SAL.explicit_line is not set, filter out
5205 all sals for which the name of enclosing function
5206 is different from SAL. This makes sure that if we have
5207 breakpoint originally set in template instantiation, say
5208 foo<int>(), we won't expand SAL to locations at the same
5209 line in all existing instantiations of 'foo'.
5212 static struct symtabs_and_lines
5213 expand_line_sal_maybe (struct symtab_and_line sal
)
5215 struct symtabs_and_lines expanded
;
5216 CORE_ADDR original_pc
= sal
.pc
;
5217 char *original_function
= NULL
;
5221 /* If we have explicit pc, don't expand.
5222 If we have no line number, we can't expand. */
5223 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5226 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5227 expanded
.sals
[0] = sal
;
5232 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5234 expanded
= expand_line_sal (sal
);
5235 if (expanded
.nelts
== 1)
5237 /* We had one sal, we got one sal. Without futher
5238 processing, just return the original sal. */
5239 xfree (expanded
.sals
);
5241 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5242 sal
.pc
= original_pc
;
5243 expanded
.sals
[0] = sal
;
5247 if (!sal
.explicit_line
)
5249 CORE_ADDR func_addr
, func_end
;
5250 for (i
= 0; i
< expanded
.nelts
; ++i
)
5252 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5253 char *this_function
;
5254 if (find_pc_partial_function (pc
, &this_function
,
5255 &func_addr
, &func_end
))
5257 if (this_function
&&
5258 strcmp (this_function
, original_function
) != 0)
5260 remove_sal (&expanded
, i
);
5263 else if (func_addr
== pc
)
5265 /* We're at beginning of a function, and should
5267 struct symbol
*sym
= find_pc_function (pc
);
5269 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5272 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5279 if (expanded
.nelts
<= 1)
5281 /* This is un ugly workaround. If we get zero
5282 expanded sals then something is really wrong.
5283 Fix that by returnign the original sal. */
5284 xfree (expanded
.sals
);
5286 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5287 sal
.pc
= original_pc
;
5288 expanded
.sals
[0] = sal
;
5295 for (i
= 0; i
< expanded
.nelts
; ++i
)
5296 if (expanded
.sals
[i
].pc
== original_pc
)
5307 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5308 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5309 value. COND_STRING, if not NULL, specified the condition to be
5310 used for all breakpoints. Essentially the only case where
5311 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5312 function. In that case, it's still not possible to specify
5313 separate conditions for different overloaded functions, so
5314 we take just a single condition string.
5316 NOTE: If the function succeeds, the caller is expected to cleanup
5317 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5318 array contents). If the function fails (error() is called), the
5319 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5320 COND and SALS arrays and each of those arrays contents. */
5323 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5325 enum bptype type
, enum bpdisp disposition
,
5326 int thread
, int ignore_count
,
5327 struct breakpoint_ops
*ops
, int from_tty
,
5331 for (i
= 0; i
< sals
.nelts
; ++i
)
5333 struct symtabs_and_lines expanded
=
5334 expand_line_sal_maybe (sals
.sals
[i
]);
5336 create_breakpoint (expanded
, addr_string
[i
],
5337 cond_string
, type
, disposition
,
5338 thread
, ignore_count
, ops
, from_tty
, enabled
);
5341 update_global_location_list (1);
5344 /* Parse ARG which is assumed to be a SAL specification possibly
5345 followed by conditionals. On return, SALS contains an array of SAL
5346 addresses found. ADDR_STRING contains a vector of (canonical)
5347 address strings. ARG points to the end of the SAL. */
5350 parse_breakpoint_sals (char **address
,
5351 struct symtabs_and_lines
*sals
,
5352 char ***addr_string
,
5355 char *addr_start
= *address
;
5356 *addr_string
= NULL
;
5357 /* If no arg given, or if first arg is 'if ', use the default
5359 if ((*address
) == NULL
5360 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5362 if (default_breakpoint_valid
)
5364 struct symtab_and_line sal
;
5365 init_sal (&sal
); /* initialize to zeroes */
5366 sals
->sals
= (struct symtab_and_line
*)
5367 xmalloc (sizeof (struct symtab_and_line
));
5368 sal
.pc
= default_breakpoint_address
;
5369 sal
.line
= default_breakpoint_line
;
5370 sal
.symtab
= default_breakpoint_symtab
;
5371 sal
.section
= find_pc_overlay (sal
.pc
);
5372 sals
->sals
[0] = sal
;
5376 error (_("No default breakpoint address now."));
5380 /* Force almost all breakpoints to be in terms of the
5381 current_source_symtab (which is decode_line_1's default). This
5382 should produce the results we want almost all of the time while
5383 leaving default_breakpoint_* alone.
5384 ObjC: However, don't match an Objective-C method name which
5385 may have a '+' or '-' succeeded by a '[' */
5387 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5389 if (default_breakpoint_valid
5391 || ((strchr ("+-", (*address
)[0]) != NULL
)
5392 && ((*address
)[1] != '['))))
5393 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5394 default_breakpoint_line
, addr_string
,
5397 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5398 addr_string
, not_found_ptr
);
5400 /* For any SAL that didn't have a canonical string, fill one in. */
5401 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5402 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5403 if (addr_start
!= (*address
))
5406 for (i
= 0; i
< sals
->nelts
; i
++)
5408 /* Add the string if not present. */
5409 if ((*addr_string
)[i
] == NULL
)
5410 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5416 /* Convert each SAL into a real PC. Verify that the PC can be
5417 inserted as a breakpoint. If it can't throw an error. */
5420 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5424 for (i
= 0; i
< sals
->nelts
; i
++)
5425 resolve_sal_pc (&sals
->sals
[i
]);
5429 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5431 struct captured_parse_breakpoint_args
*args
= data
;
5433 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5434 args
->not_found_ptr
);
5437 /* Given TOK, a string specification of condition and thread, as
5438 accepted by the 'break' command, extract the condition
5439 string and thread number and set *COND_STRING and *THREAD.
5440 PC identifies the context at which the condition should be parsed.
5441 If no condition is found, *COND_STRING is set to NULL.
5442 If no thread is found, *THREAD is set to -1. */
5444 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5445 char **cond_string
, int *thread
)
5447 *cond_string
= NULL
;
5453 char *cond_start
= NULL
;
5454 char *cond_end
= NULL
;
5455 while (*tok
== ' ' || *tok
== '\t')
5460 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5463 toklen
= end_tok
- tok
;
5465 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5467 struct expression
*expr
;
5469 tok
= cond_start
= end_tok
+ 1;
5470 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5473 *cond_string
= savestring (cond_start
,
5474 cond_end
- cond_start
);
5476 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5482 *thread
= strtol (tok
, &tok
, 0);
5484 error (_("Junk after thread keyword."));
5485 if (!valid_thread_id (*thread
))
5486 error (_("Unknown thread %d."), *thread
);
5489 error (_("Junk at end of arguments."));
5493 /* Set a breakpoint. This function is shared between
5494 CLI and MI functions for setting a breakpoint.
5495 This function has two major modes of operations,
5496 selected by the PARSE_CONDITION_AND_THREAD parameter.
5497 If non-zero, the function will parse arg, extracting
5498 breakpoint location, address and thread. Otherwise,
5499 ARG is just the location of breakpoint, with condition
5500 and thread specified by the COND_STRING and THREAD
5504 break_command_really (char *arg
, char *cond_string
, int thread
,
5505 int parse_condition_and_thread
,
5506 int tempflag
, int hardwareflag
,
5508 enum auto_boolean pending_break_support
,
5509 struct breakpoint_ops
*ops
,
5513 struct gdb_exception e
;
5514 struct symtabs_and_lines sals
;
5515 struct symtab_and_line pending_sal
;
5518 char *addr_start
= arg
;
5520 struct cleanup
*old_chain
;
5521 struct cleanup
*breakpoint_chain
= NULL
;
5522 struct captured_parse_breakpoint_args parse_args
;
5531 parse_args
.arg_p
= &arg
;
5532 parse_args
.sals_p
= &sals
;
5533 parse_args
.addr_string_p
= &addr_string
;
5534 parse_args
.not_found_ptr
= ¬_found
;
5536 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5537 &parse_args
, RETURN_MASK_ALL
);
5539 /* If caller is interested in rc value from parse, set value. */
5543 throw_exception (e
);
5547 case NOT_FOUND_ERROR
:
5549 /* If pending breakpoint support is turned off, throw
5552 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5553 throw_exception (e
);
5555 exception_print (gdb_stderr
, e
);
5557 /* If pending breakpoint support is auto query and the user
5558 selects no, then simply return the error code. */
5559 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5560 !nquery ("Make breakpoint pending on future shared library load? "))
5563 /* At this point, either the user was queried about setting
5564 a pending breakpoint and selected yes, or pending
5565 breakpoint behavior is on and thus a pending breakpoint
5566 is defaulted on behalf of the user. */
5567 copy_arg
= xstrdup (addr_start
);
5568 addr_string
= ©_arg
;
5570 sals
.sals
= &pending_sal
;
5575 throw_exception (e
);
5582 /* Create a chain of things that always need to be cleaned up. */
5583 old_chain
= make_cleanup (null_cleanup
, 0);
5587 /* Make sure that all storage allocated to SALS gets freed. */
5588 make_cleanup (xfree
, sals
.sals
);
5590 /* Cleanup the addr_string array but not its contents. */
5591 make_cleanup (xfree
, addr_string
);
5594 /* ----------------------------- SNIP -----------------------------
5595 Anything added to the cleanup chain beyond this point is assumed
5596 to be part of a breakpoint. If the breakpoint create succeeds
5597 then the memory is not reclaimed. */
5598 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5600 /* Mark the contents of the addr_string for cleanup. These go on
5601 the breakpoint_chain and only occure if the breakpoint create
5603 for (i
= 0; i
< sals
.nelts
; i
++)
5605 if (addr_string
[i
] != NULL
)
5606 make_cleanup (xfree
, addr_string
[i
]);
5609 /* Resolve all line numbers to PC's and verify that the addresses
5610 are ok for the target. */
5612 breakpoint_sals_to_pc (&sals
, addr_start
);
5614 /* Verify that condition can be parsed, before setting any
5615 breakpoints. Allocate a separate condition expression for each
5619 if (parse_condition_and_thread
)
5621 /* Here we only parse 'arg' to separate condition
5622 from thread number, so parsing in context of first
5623 sal is OK. When setting the breakpoint we'll
5624 re-parse it in context of each sal. */
5627 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5629 make_cleanup (xfree
, cond_string
);
5633 /* Create a private copy of condition string. */
5636 cond_string
= xstrdup (cond_string
);
5637 make_cleanup (xfree
, cond_string
);
5640 create_breakpoints (sals
, addr_string
, cond_string
,
5641 hardwareflag
? bp_hardware_breakpoint
5643 tempflag
? disp_del
: disp_donttouch
,
5644 thread
, ignore_count
, ops
, from_tty
, enabled
);
5648 struct symtab_and_line sal
= {0};
5649 struct breakpoint
*b
;
5651 make_cleanup (xfree
, copy_arg
);
5653 b
= set_raw_breakpoint_without_location (hardwareflag
5654 ? bp_hardware_breakpoint
5656 set_breakpoint_count (breakpoint_count
+ 1);
5657 b
->number
= breakpoint_count
;
5659 b
->addr_string
= addr_string
[0];
5660 b
->cond_string
= NULL
;
5661 b
->ignore_count
= ignore_count
;
5662 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5663 b
->condition_not_parsed
= 1;
5665 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5667 update_global_location_list (1);
5672 warning (_("Multiple breakpoints were set.\n"
5673 "Use the \"delete\" command to delete unwanted breakpoints."));
5674 /* That's it. Discard the cleanups for data inserted into the
5676 discard_cleanups (breakpoint_chain
);
5677 /* But cleanup everything else. */
5678 do_cleanups (old_chain
);
5681 /* Set a breakpoint.
5682 ARG is a string describing breakpoint address,
5683 condition, and thread.
5684 FLAG specifies if a breakpoint is hardware on,
5685 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5689 break_command_1 (char *arg
, int flag
, int from_tty
)
5691 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5692 int tempflag
= flag
& BP_TEMPFLAG
;
5694 break_command_really (arg
,
5695 NULL
, 0, 1 /* parse arg */,
5696 tempflag
, hardwareflag
,
5697 0 /* Ignore count */,
5698 pending_break_support
,
5699 NULL
/* breakpoint_ops */,
5706 set_breakpoint (char *address
, char *condition
,
5707 int hardwareflag
, int tempflag
,
5708 int thread
, int ignore_count
,
5709 int pending
, int enabled
)
5711 break_command_really (address
, condition
, thread
,
5712 0 /* condition and thread are valid. */,
5713 tempflag
, hardwareflag
,
5716 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5720 /* Adjust SAL to the first instruction past the function prologue.
5721 The end of the prologue is determined using the line table from
5722 the debugging information.
5724 If SAL is already past the prologue, then do nothing. */
5727 skip_prologue_sal (struct symtab_and_line
*sal
)
5729 struct symbol
*sym
= find_pc_function (sal
->pc
);
5730 struct symtab_and_line start_sal
;
5735 start_sal
= find_function_start_sal (sym
, 1);
5736 if (sal
->pc
< start_sal
.pc
)
5740 /* Helper function for break_command_1 and disassemble_command. */
5743 resolve_sal_pc (struct symtab_and_line
*sal
)
5747 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5749 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5750 error (_("No line %d in file \"%s\"."),
5751 sal
->line
, sal
->symtab
->filename
);
5754 /* If this SAL corresponds to a breakpoint inserted using
5755 a line number, then skip the function prologue if necessary. */
5756 if (sal
->explicit_line
)
5757 skip_prologue_sal (sal
);
5760 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5762 struct blockvector
*bv
;
5766 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5769 sym
= block_linkage_function (b
);
5772 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5773 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5777 /* It really is worthwhile to have the section, so we'll just
5778 have to look harder. This case can be executed if we have
5779 line numbers but no functions (as can happen in assembly
5782 struct minimal_symbol
*msym
;
5784 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5786 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5793 break_command (char *arg
, int from_tty
)
5795 break_command_1 (arg
, 0, from_tty
);
5799 tbreak_command (char *arg
, int from_tty
)
5801 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5805 hbreak_command (char *arg
, int from_tty
)
5807 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5811 thbreak_command (char *arg
, int from_tty
)
5813 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5817 stop_command (char *arg
, int from_tty
)
5819 printf_filtered (_("Specify the type of breakpoint to set.\n\
5820 Usage: stop in <function | address>\n\
5821 stop at <line>\n"));
5825 stopin_command (char *arg
, int from_tty
)
5829 if (arg
== (char *) NULL
)
5831 else if (*arg
!= '*')
5836 /* look for a ':'. If this is a line number specification, then
5837 say it is bad, otherwise, it should be an address or
5838 function/method name */
5839 while (*argptr
&& !hasColon
)
5841 hasColon
= (*argptr
== ':');
5846 badInput
= (*argptr
!= ':'); /* Not a class::method */
5848 badInput
= isdigit (*arg
); /* a simple line number */
5852 printf_filtered (_("Usage: stop in <function | address>\n"));
5854 break_command_1 (arg
, 0, from_tty
);
5858 stopat_command (char *arg
, int from_tty
)
5862 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5869 /* look for a ':'. If there is a '::' then get out, otherwise
5870 it is probably a line number. */
5871 while (*argptr
&& !hasColon
)
5873 hasColon
= (*argptr
== ':');
5878 badInput
= (*argptr
== ':'); /* we have class::method */
5880 badInput
= !isdigit (*arg
); /* not a line number */
5884 printf_filtered (_("Usage: stop at <line>\n"));
5886 break_command_1 (arg
, 0, from_tty
);
5889 /* accessflag: hw_write: watch write,
5890 hw_read: watch read,
5891 hw_access: watch access (read or write) */
5893 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5895 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5896 struct symtab_and_line sal
;
5897 struct expression
*exp
;
5898 struct block
*exp_valid_block
;
5899 struct value
*val
, *mark
;
5900 struct frame_info
*frame
;
5901 struct frame_info
*prev_frame
= NULL
;
5902 char *exp_start
= NULL
;
5903 char *exp_end
= NULL
;
5904 char *tok
, *id_tok_start
, *end_tok
;
5906 char *cond_start
= NULL
;
5907 char *cond_end
= NULL
;
5908 struct expression
*cond
= NULL
;
5909 int i
, other_type_used
, target_resources_ok
= 0;
5910 enum bptype bp_type
;
5914 init_sal (&sal
); /* initialize to zeroes */
5916 /* Make sure that we actually have parameters to parse. */
5917 if (arg
!= NULL
&& arg
[0] != '\0')
5919 toklen
= strlen (arg
); /* Size of argument list. */
5921 /* Points tok to the end of the argument list. */
5922 tok
= arg
+ toklen
- 1;
5924 /* Go backwards in the parameters list. Skip the last parameter.
5925 If we're expecting a 'thread <thread_num>' parameter, this should
5926 be the thread identifier. */
5927 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5929 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5932 /* Points end_tok to the beginning of the last token. */
5933 id_tok_start
= tok
+ 1;
5935 /* Go backwards in the parameters list. Skip one more parameter.
5936 If we're expecting a 'thread <thread_num>' parameter, we should
5937 reach a "thread" token. */
5938 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5943 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5946 /* Move the pointer forward to skip the whitespace and
5947 calculate the length of the token. */
5949 toklen
= end_tok
- tok
;
5951 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5953 /* At this point we've found a "thread" token, which means
5954 the user is trying to set a watchpoint that triggers
5955 only in a specific thread. */
5958 /* Extract the thread ID from the next token. */
5959 thread
= strtol (id_tok_start
, &endp
, 0);
5961 /* Check if the user provided a valid numeric value for the
5963 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5964 error (_("Invalid thread ID specification %s."), id_tok_start
);
5966 /* Check if the thread actually exists. */
5967 if (!valid_thread_id (thread
))
5968 error (_("Unknown thread %d."), thread
);
5970 /* Truncate the string and get rid of the thread <thread_num>
5971 parameter before the parameter list is parsed by the
5972 evaluate_expression() function. */
5977 /* Parse the rest of the arguments. */
5978 innermost_block
= NULL
;
5980 exp
= parse_exp_1 (&arg
, 0, 0);
5982 /* Remove trailing whitespace from the expression before saving it.
5983 This makes the eventual display of the expression string a bit
5985 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
5988 exp_valid_block
= innermost_block
;
5989 mark
= value_mark ();
5990 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5992 release_value (val
);
5995 while (*tok
== ' ' || *tok
== '\t')
5999 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6002 toklen
= end_tok
- tok
;
6003 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6005 tok
= cond_start
= end_tok
+ 1;
6006 cond
= parse_exp_1 (&tok
, 0, 0);
6010 error (_("Junk at end of command."));
6012 if (accessflag
== hw_read
)
6013 bp_type
= bp_read_watchpoint
;
6014 else if (accessflag
== hw_access
)
6015 bp_type
= bp_access_watchpoint
;
6017 bp_type
= bp_hardware_watchpoint
;
6019 mem_cnt
= can_use_hardware_watchpoint (val
);
6020 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6021 error (_("Expression cannot be implemented with read/access watchpoint."));
6024 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6025 target_resources_ok
=
6026 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6028 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6029 error (_("Target does not support this type of hardware watchpoint."));
6031 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6032 error (_("Target can only support one kind of HW watchpoint at a time."));
6035 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6036 watchpoint could not be set. */
6037 if (!mem_cnt
|| target_resources_ok
<= 0)
6038 bp_type
= bp_watchpoint
;
6040 frame
= block_innermost_frame (exp_valid_block
);
6042 prev_frame
= get_prev_frame (frame
);
6046 /* If the expression is "local", then set up a "watchpoint scope"
6047 breakpoint at the point where we've left the scope of the watchpoint
6048 expression. Create the scope breakpoint before the watchpoint, so
6049 that we will encounter it first in bpstat_stop_status. */
6050 if (innermost_block
&& prev_frame
)
6052 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6053 bp_watchpoint_scope
);
6055 scope_breakpoint
->enable_state
= bp_enabled
;
6057 /* Automatically delete the breakpoint when it hits. */
6058 scope_breakpoint
->disposition
= disp_del
;
6060 /* Only break in the proper frame (help with recursion). */
6061 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6063 /* Set the address at which we will stop. */
6064 scope_breakpoint
->loc
->requested_address
6065 = get_frame_pc (prev_frame
);
6066 scope_breakpoint
->loc
->address
6067 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6068 scope_breakpoint
->type
);
6071 /* Now set up the breakpoint. */
6072 b
= set_raw_breakpoint (sal
, bp_type
);
6073 set_breakpoint_count (breakpoint_count
+ 1);
6074 b
->number
= breakpoint_count
;
6076 b
->disposition
= disp_donttouch
;
6078 b
->exp_valid_block
= exp_valid_block
;
6079 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6082 b
->loc
->cond
= cond
;
6084 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6089 b
->watchpoint_frame
= get_frame_id (frame
);
6091 b
->watchpoint_frame
= null_frame_id
;
6093 if (scope_breakpoint
!= NULL
)
6095 /* The scope breakpoint is related to the watchpoint. We will
6096 need to act on them together. */
6097 b
->related_breakpoint
= scope_breakpoint
;
6098 scope_breakpoint
->related_breakpoint
= b
;
6101 value_free_to_mark (mark
);
6103 update_global_location_list (1);
6106 /* Return count of locations need to be watched and can be handled
6107 in hardware. If the watchpoint can not be handled
6108 in hardware return zero. */
6111 can_use_hardware_watchpoint (struct value
*v
)
6113 int found_memory_cnt
= 0;
6114 struct value
*head
= v
;
6116 /* Did the user specifically forbid us to use hardware watchpoints? */
6117 if (!can_use_hw_watchpoints
)
6120 /* Make sure that the value of the expression depends only upon
6121 memory contents, and values computed from them within GDB. If we
6122 find any register references or function calls, we can't use a
6123 hardware watchpoint.
6125 The idea here is that evaluating an expression generates a series
6126 of values, one holding the value of every subexpression. (The
6127 expression a*b+c has five subexpressions: a, b, a*b, c, and
6128 a*b+c.) GDB's values hold almost enough information to establish
6129 the criteria given above --- they identify memory lvalues,
6130 register lvalues, computed values, etcetera. So we can evaluate
6131 the expression, and then scan the chain of values that leaves
6132 behind to decide whether we can detect any possible change to the
6133 expression's final value using only hardware watchpoints.
6135 However, I don't think that the values returned by inferior
6136 function calls are special in any way. So this function may not
6137 notice that an expression involving an inferior function call
6138 can't be watched with hardware watchpoints. FIXME. */
6139 for (; v
; v
= value_next (v
))
6141 if (VALUE_LVAL (v
) == lval_memory
)
6144 /* A lazy memory lvalue is one that GDB never needed to fetch;
6145 we either just used its address (e.g., `a' in `a.b') or
6146 we never needed it at all (e.g., `a' in `a,b'). */
6150 /* Ahh, memory we actually used! Check if we can cover
6151 it with hardware watchpoints. */
6152 struct type
*vtype
= check_typedef (value_type (v
));
6154 /* We only watch structs and arrays if user asked for it
6155 explicitly, never if they just happen to appear in a
6156 middle of some value chain. */
6158 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6159 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6161 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6162 int len
= TYPE_LENGTH (value_type (v
));
6164 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6171 else if (VALUE_LVAL (v
) != not_lval
6172 && deprecated_value_modifiable (v
) == 0)
6173 return 0; /* ??? What does this represent? */
6174 else if (VALUE_LVAL (v
) == lval_register
)
6175 return 0; /* cannot watch a register with a HW watchpoint */
6178 /* The expression itself looks suitable for using a hardware
6179 watchpoint, but give the target machine a chance to reject it. */
6180 return found_memory_cnt
;
6184 watch_command_wrapper (char *arg
, int from_tty
)
6186 watch_command (arg
, from_tty
);
6190 watch_command (char *arg
, int from_tty
)
6192 watch_command_1 (arg
, hw_write
, from_tty
);
6196 rwatch_command_wrapper (char *arg
, int from_tty
)
6198 rwatch_command (arg
, from_tty
);
6202 rwatch_command (char *arg
, int from_tty
)
6204 watch_command_1 (arg
, hw_read
, from_tty
);
6208 awatch_command_wrapper (char *arg
, int from_tty
)
6210 awatch_command (arg
, from_tty
);
6214 awatch_command (char *arg
, int from_tty
)
6216 watch_command_1 (arg
, hw_access
, from_tty
);
6220 /* Helper routines for the until_command routine in infcmd.c. Here
6221 because it uses the mechanisms of breakpoints. */
6223 struct until_break_command_continuation_args
6225 struct breakpoint
*breakpoint
;
6226 struct breakpoint
*breakpoint2
;
6229 /* This function is called by fetch_inferior_event via the
6230 cmd_continuation pointer, to complete the until command. It takes
6231 care of cleaning up the temporary breakpoints set up by the until
6234 until_break_command_continuation (void *arg
)
6236 struct until_break_command_continuation_args
*a
= arg
;
6238 delete_breakpoint (a
->breakpoint
);
6240 delete_breakpoint (a
->breakpoint2
);
6244 until_break_command (char *arg
, int from_tty
, int anywhere
)
6246 struct symtabs_and_lines sals
;
6247 struct symtab_and_line sal
;
6248 struct frame_info
*frame
= get_selected_frame (NULL
);
6249 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6250 struct breakpoint
*breakpoint
;
6251 struct breakpoint
*breakpoint2
= NULL
;
6252 struct cleanup
*old_chain
;
6254 clear_proceed_status ();
6256 /* Set a breakpoint where the user wants it and at return from
6259 if (default_breakpoint_valid
)
6260 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6261 default_breakpoint_line
, (char ***) NULL
, NULL
);
6263 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6264 0, (char ***) NULL
, NULL
);
6266 if (sals
.nelts
!= 1)
6267 error (_("Couldn't get information on specified line."));
6270 xfree (sals
.sals
); /* malloc'd, so freed */
6273 error (_("Junk at end of arguments."));
6275 resolve_sal_pc (&sal
);
6278 /* If the user told us to continue until a specified location,
6279 we don't specify a frame at which we need to stop. */
6280 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6282 /* Otherwise, specify the current frame, because we want to stop only
6283 at the very same frame. */
6284 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6287 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6289 /* Keep within the current frame, or in frames called by the current
6293 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6294 sal
.pc
= get_frame_pc (prev_frame
);
6295 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6297 make_cleanup_delete_breakpoint (breakpoint2
);
6300 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6302 /* If we are running asynchronously, and proceed call above has actually
6303 managed to start the target, arrange for breakpoints to be
6304 deleted when the target stops. Otherwise, we're already stopped and
6305 delete breakpoints via cleanup chain. */
6307 if (target_can_async_p () && is_running (inferior_ptid
))
6309 struct until_break_command_continuation_args
*args
;
6310 args
= xmalloc (sizeof (*args
));
6312 args
->breakpoint
= breakpoint
;
6313 args
->breakpoint2
= breakpoint2
;
6315 discard_cleanups (old_chain
);
6316 add_continuation (inferior_thread (),
6317 until_break_command_continuation
, args
,
6321 do_cleanups (old_chain
);
6325 ep_skip_leading_whitespace (char **s
)
6327 if ((s
== NULL
) || (*s
== NULL
))
6329 while (isspace (**s
))
6333 /* This function attempts to parse an optional "if <cond>" clause
6334 from the arg string. If one is not found, it returns NULL.
6336 Else, it returns a pointer to the condition string. (It does not
6337 attempt to evaluate the string against a particular block.) And,
6338 it updates arg to point to the first character following the parsed
6339 if clause in the arg string. */
6342 ep_parse_optional_if_clause (char **arg
)
6346 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6349 /* Skip the "if" keyword. */
6352 /* Skip any extra leading whitespace, and record the start of the
6353 condition string. */
6354 ep_skip_leading_whitespace (arg
);
6357 /* Assume that the condition occupies the remainder of the arg string. */
6358 (*arg
) += strlen (cond_string
);
6363 /* This function attempts to parse an optional filename from the arg
6364 string. If one is not found, it returns NULL.
6366 Else, it returns a pointer to the parsed filename. (This function
6367 makes no attempt to verify that a file of that name exists, or is
6368 accessible.) And, it updates arg to point to the first character
6369 following the parsed filename in the arg string.
6371 Note that clients needing to preserve the returned filename for
6372 future access should copy it to their own buffers. */
6374 ep_parse_optional_filename (char **arg
)
6376 static char filename
[1024];
6381 if ((*arg_p
== '\0') || isspace (*arg_p
))
6399 /* Commands to deal with catching events, such as signals, exceptions,
6400 process start/exit, etc. */
6404 catch_fork_temporary
, catch_vfork_temporary
,
6405 catch_fork_permanent
, catch_vfork_permanent
6410 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6412 char *cond_string
= NULL
;
6413 catch_fork_kind fork_kind
;
6416 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6417 tempflag
= (fork_kind
== catch_fork_temporary
6418 || fork_kind
== catch_vfork_temporary
);
6422 ep_skip_leading_whitespace (&arg
);
6424 /* The allowed syntax is:
6426 catch [v]fork if <cond>
6428 First, check if there's an if clause. */
6429 cond_string
= ep_parse_optional_if_clause (&arg
);
6431 if ((*arg
!= '\0') && !isspace (*arg
))
6432 error (_("Junk at end of arguments."));
6434 /* If this target supports it, create a fork or vfork catchpoint
6435 and enable reporting of such events. */
6438 case catch_fork_temporary
:
6439 case catch_fork_permanent
:
6440 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6441 &catch_fork_breakpoint_ops
);
6443 case catch_vfork_temporary
:
6444 case catch_vfork_permanent
:
6445 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6446 &catch_vfork_breakpoint_ops
);
6449 error (_("unsupported or unknown fork kind; cannot catch it"));
6455 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6458 char *cond_string
= NULL
;
6460 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6464 ep_skip_leading_whitespace (&arg
);
6466 /* The allowed syntax is:
6468 catch exec if <cond>
6470 First, check if there's an if clause. */
6471 cond_string
= ep_parse_optional_if_clause (&arg
);
6473 if ((*arg
!= '\0') && !isspace (*arg
))
6474 error (_("Junk at end of arguments."));
6476 /* If this target supports it, create an exec catchpoint
6477 and enable reporting of such events. */
6478 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6481 static enum print_stop_action
6482 print_exception_catchpoint (struct breakpoint
*b
)
6484 int bp_temp
, bp_throw
;
6486 annotate_catchpoint (b
->number
);
6488 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6489 if (b
->loc
->address
!= b
->loc
->requested_address
)
6490 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6493 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6495 bp_temp
? "Temporary catchpoint "
6497 if (!ui_out_is_mi_like_p (uiout
))
6498 ui_out_field_int (uiout
, "bkptno", b
->number
);
6500 bp_throw
? " (exception thrown), "
6501 : " (exception caught), ");
6502 if (ui_out_is_mi_like_p (uiout
))
6504 ui_out_field_string (uiout
, "reason",
6505 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6506 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6507 ui_out_field_int (uiout
, "bkptno", b
->number
);
6509 return PRINT_SRC_AND_LOC
;
6513 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6515 struct value_print_options opts
;
6516 get_user_print_options (&opts
);
6517 if (opts
.addressprint
)
6520 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6521 ui_out_field_string (uiout
, "addr", "<PENDING>");
6523 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6527 *last_addr
= b
->loc
->address
;
6528 if (strstr (b
->addr_string
, "throw") != NULL
)
6529 ui_out_field_string (uiout
, "what", "exception throw");
6531 ui_out_field_string (uiout
, "what", "exception catch");
6535 print_mention_exception_catchpoint (struct breakpoint
*b
)
6540 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6541 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6542 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6543 : _("Catchpoint "));
6544 ui_out_field_int (uiout
, "bkptno", b
->number
);
6545 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6549 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6552 NULL
, /* breakpoint_hit */
6553 print_exception_catchpoint
,
6554 print_one_exception_catchpoint
,
6555 print_mention_exception_catchpoint
6559 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6560 enum exception_event_kind ex_event
, int from_tty
)
6562 char *trigger_func_name
;
6564 if (ex_event
== EX_EVENT_CATCH
)
6565 trigger_func_name
= "__cxa_begin_catch";
6567 trigger_func_name
= "__cxa_throw";
6569 break_command_really (trigger_func_name
, cond_string
, -1,
6570 0 /* condition and thread are valid. */,
6573 AUTO_BOOLEAN_TRUE
/* pending */,
6574 &gnu_v3_exception_catchpoint_ops
, from_tty
,
6580 /* Deal with "catch catch" and "catch throw" commands */
6583 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6584 int tempflag
, int from_tty
)
6586 char *cond_string
= NULL
;
6587 struct symtab_and_line
*sal
= NULL
;
6591 ep_skip_leading_whitespace (&arg
);
6593 cond_string
= ep_parse_optional_if_clause (&arg
);
6595 if ((*arg
!= '\0') && !isspace (*arg
))
6596 error (_("Junk at end of arguments."));
6598 if ((ex_event
!= EX_EVENT_THROW
) &&
6599 (ex_event
!= EX_EVENT_CATCH
))
6600 error (_("Unsupported or unknown exception event; cannot catch it"));
6602 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6605 warning (_("Unsupported with this platform/compiler combination."));
6608 /* Implementation of "catch catch" command. */
6611 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6613 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6614 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6617 /* Implementation of "catch throw" command. */
6620 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6622 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6623 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6626 /* Create a breakpoint struct for Ada exception catchpoints. */
6629 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6633 struct expression
*cond
,
6634 struct breakpoint_ops
*ops
,
6638 struct breakpoint
*b
;
6642 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6643 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6644 version for exception catchpoints, because two catchpoints
6645 used for different exception names will use the same address.
6646 In this case, a "breakpoint ... also set at..." warning is
6647 unproductive. Besides. the warning phrasing is also a bit
6648 inapropriate, we should use the word catchpoint, and tell
6649 the user what type of catchpoint it is. The above is good
6650 enough for now, though. */
6653 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6654 set_breakpoint_count (breakpoint_count
+ 1);
6656 b
->enable_state
= bp_enabled
;
6657 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6658 b
->number
= breakpoint_count
;
6659 b
->ignore_count
= 0;
6660 b
->loc
->cond
= cond
;
6661 b
->addr_string
= addr_string
;
6662 b
->language
= language_ada
;
6663 b
->cond_string
= cond_string
;
6664 b
->exp_string
= exp_string
;
6669 update_global_location_list (1);
6672 /* Implement the "catch exception" command. */
6675 catch_ada_exception_command (char *arg
, int from_tty
,
6676 struct cmd_list_element
*command
)
6679 struct symtab_and_line sal
;
6681 char *addr_string
= NULL
;
6682 char *exp_string
= NULL
;
6683 char *cond_string
= NULL
;
6684 struct expression
*cond
= NULL
;
6685 struct breakpoint_ops
*ops
= NULL
;
6687 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6691 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6692 &cond_string
, &cond
, &ops
);
6693 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6694 cond_string
, cond
, ops
, tempflag
,
6698 /* Implement the "catch assert" command. */
6701 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6704 struct symtab_and_line sal
;
6705 char *addr_string
= NULL
;
6706 struct breakpoint_ops
*ops
= NULL
;
6708 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6712 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6713 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6714 tempflag
, from_tty
);
6718 catch_command (char *arg
, int from_tty
)
6720 error (_("Catch requires an event name."));
6725 tcatch_command (char *arg
, int from_tty
)
6727 error (_("Catch requires an event name."));
6730 /* Delete breakpoints by address or line. */
6733 clear_command (char *arg
, int from_tty
)
6735 struct breakpoint
*b
;
6736 VEC(breakpoint_p
) *found
= 0;
6739 struct symtabs_and_lines sals
;
6740 struct symtab_and_line sal
;
6745 sals
= decode_line_spec (arg
, 1);
6750 sals
.sals
= (struct symtab_and_line
*)
6751 xmalloc (sizeof (struct symtab_and_line
));
6752 make_cleanup (xfree
, sals
.sals
);
6753 init_sal (&sal
); /* initialize to zeroes */
6754 sal
.line
= default_breakpoint_line
;
6755 sal
.symtab
= default_breakpoint_symtab
;
6756 sal
.pc
= default_breakpoint_address
;
6757 if (sal
.symtab
== 0)
6758 error (_("No source file specified."));
6766 /* We don't call resolve_sal_pc here. That's not
6767 as bad as it seems, because all existing breakpoints
6768 typically have both file/line and pc set. So, if
6769 clear is given file/line, we can match this to existing
6770 breakpoint without obtaining pc at all.
6772 We only support clearing given the address explicitly
6773 present in breakpoint table. Say, we've set breakpoint
6774 at file:line. There were several PC values for that file:line,
6775 due to optimization, all in one block.
6776 We've picked one PC value. If "clear" is issued with another
6777 PC corresponding to the same file:line, the breakpoint won't
6778 be cleared. We probably can still clear the breakpoint, but
6779 since the other PC value is never presented to user, user
6780 can only find it by guessing, and it does not seem important
6783 /* For each line spec given, delete bps which correspond
6784 to it. Do it in two passes, solely to preserve the current
6785 behavior that from_tty is forced true if we delete more than
6789 for (i
= 0; i
< sals
.nelts
; i
++)
6791 /* If exact pc given, clear bpts at that pc.
6792 If line given (pc == 0), clear all bpts on specified line.
6793 If defaulting, clear all bpts on default line
6796 defaulting sal.pc != 0 tests to do
6801 1 0 <can't happen> */
6805 /* Find all matching breakpoints and add them to
6810 /* Are we going to delete b? */
6811 if (b
->type
!= bp_none
6812 && b
->type
!= bp_watchpoint
6813 && b
->type
!= bp_hardware_watchpoint
6814 && b
->type
!= bp_read_watchpoint
6815 && b
->type
!= bp_access_watchpoint
)
6817 struct bp_location
*loc
= b
->loc
;
6818 for (; loc
; loc
= loc
->next
)
6820 int pc_match
= sal
.pc
6821 && (loc
->address
== sal
.pc
)
6822 && (!section_is_overlay (loc
->section
)
6823 || loc
->section
== sal
.section
);
6824 int line_match
= ((default_match
|| (0 == sal
.pc
))
6825 && b
->source_file
!= NULL
6826 && sal
.symtab
!= NULL
6827 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6828 && b
->line_number
== sal
.line
);
6829 if (pc_match
|| line_match
)
6838 VEC_safe_push(breakpoint_p
, found
, b
);
6841 /* Now go thru the 'found' chain and delete them. */
6842 if (VEC_empty(breakpoint_p
, found
))
6845 error (_("No breakpoint at %s."), arg
);
6847 error (_("No breakpoint at this line."));
6850 if (VEC_length(breakpoint_p
, found
) > 1)
6851 from_tty
= 1; /* Always report if deleted more than one */
6854 if (VEC_length(breakpoint_p
, found
) == 1)
6855 printf_unfiltered (_("Deleted breakpoint "));
6857 printf_unfiltered (_("Deleted breakpoints "));
6859 breakpoints_changed ();
6861 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6864 printf_unfiltered ("%d ", b
->number
);
6865 delete_breakpoint (b
);
6868 putchar_unfiltered ('\n');
6871 /* Delete breakpoint in BS if they are `delete' breakpoints and
6872 all breakpoints that are marked for deletion, whether hit or not.
6873 This is called after any breakpoint is hit, or after errors. */
6876 breakpoint_auto_delete (bpstat bs
)
6878 struct breakpoint
*b
, *temp
;
6880 for (; bs
; bs
= bs
->next
)
6881 if (bs
->breakpoint_at
6882 && bs
->breakpoint_at
->owner
6883 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6885 delete_breakpoint (bs
->breakpoint_at
->owner
);
6887 ALL_BREAKPOINTS_SAFE (b
, temp
)
6889 if (b
->disposition
== disp_del_at_next_stop
)
6890 delete_breakpoint (b
);
6894 /* A cleanup function which destroys a vector. */
6897 do_vec_free (void *p
)
6899 VEC(bp_location_p
) **vec
= p
;
6901 VEC_free (bp_location_p
, *vec
);
6904 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
6905 into the inferior, only remove already-inserted locations that no
6906 longer should be inserted. Functions that delete a breakpoint or
6907 breakpoints should pass false, so that deleting a breakpoint
6908 doesn't have the side effect of inserting the locations of other
6909 breakpoints that are marked not-inserted, but should_be_inserted
6910 returns true on them.
6912 This behaviour is useful is situations close to tear-down -- e.g.,
6913 after an exec, while the target still has execution, but breakpoint
6914 shadows of the previous executable image should *NOT* be restored
6915 to the new image; or before detaching, where the target still has
6916 execution and wants to delete breakpoints from GDB's lists, and all
6917 breakpoints had already been removed from the inferior. */
6920 update_global_location_list (int should_insert
)
6922 struct breakpoint
*b
;
6923 struct bp_location
**next
= &bp_location_chain
;
6924 struct bp_location
*loc
;
6925 struct bp_location
*loc2
;
6926 VEC(bp_location_p
) *old_locations
= NULL
;
6929 struct cleanup
*cleanups
;
6931 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
6932 /* Store old locations for future reference. */
6933 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6934 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6936 bp_location_chain
= NULL
;
6939 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6942 next
= &(loc
->global_next
);
6947 /* Identify bp_location instances that are no longer present in the new
6948 list, and therefore should be freed. Note that it's not necessary that
6949 those locations should be removed from inferior -- if there's another
6950 location at the same address (previously marked as duplicate),
6951 we don't need to remove/insert the location. */
6952 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6954 /* Tells if 'loc' is found amoung the new locations. If not, we
6956 int found_object
= 0;
6957 /* Tells if the location should remain inserted in the target. */
6958 int keep_in_target
= 0;
6960 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6967 /* If this location is no longer present, and inserted, look if there's
6968 maybe a new location at the same address. If so, mark that one
6969 inserted, and don't remove this one. This is needed so that we
6970 don't have a time window where a breakpoint at certain location is not
6975 /* If the location is inserted now, we might have to remove it. */
6977 if (found_object
&& should_be_inserted (loc
))
6979 /* The location is still present in the location list, and still
6980 should be inserted. Don't do anything. */
6985 /* The location is either no longer present, or got disabled.
6986 See if there's another location at the same address, in which
6987 case we don't need to remove this one from the target. */
6988 if (breakpoint_address_is_meaningful (loc
->owner
))
6989 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6991 /* For the sake of should_insert_location. The
6992 call to check_duplicates will fix up this later. */
6993 loc2
->duplicate
= 0;
6994 if (should_be_inserted (loc2
)
6995 && loc2
!= loc
&& loc2
->address
== loc
->address
)
6998 loc2
->target_info
= loc
->target_info
;
7005 if (!keep_in_target
)
7007 if (remove_breakpoint (loc
, mark_uninserted
))
7009 /* This is just about all we can do. We could keep this
7010 location on the global list, and try to remove it next
7011 time, but there's no particular reason why we will
7014 Note that at this point, loc->owner is still valid,
7015 as delete_breakpoint frees the breakpoint only
7016 after calling us. */
7017 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7018 loc
->owner
->number
);
7026 if (removed
&& non_stop
)
7028 /* This location was removed from the targets. In non-stop mode,
7029 a race condition is possible where we've removed a breakpoint,
7030 but stop events for that breakpoint are already queued and will
7031 arrive later. To suppress spurious SIGTRAPs reported to user,
7032 we keep this breakpoint location for a bit, and will retire it
7033 after we see 3 * thread_count events.
7034 The theory here is that reporting of events should,
7035 "on the average", be fair, so after that many event we'll see
7036 events from all threads that have anything of interest, and no
7037 longer need to keep this breakpoint. This is just a
7038 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7039 which is usability issue, but not a correctness problem. */
7040 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7043 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7046 free_bp_location (loc
);
7052 check_duplicates (b
);
7055 if (breakpoints_always_inserted_mode () && should_insert
7056 && (target_has_execution
7057 || (gdbarch_has_global_solist (target_gdbarch
)
7058 && target_supports_multi_process ())))
7059 insert_breakpoint_locations ();
7061 do_cleanups (cleanups
);
7065 breakpoint_retire_moribund (void)
7067 struct bp_location
*loc
;
7070 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7071 if (--(loc
->events_till_retirement
) == 0)
7073 free_bp_location (loc
);
7074 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7080 update_global_location_list_nothrow (int inserting
)
7082 struct gdb_exception e
;
7083 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7084 update_global_location_list (inserting
);
7087 /* Clear BPT from a BPS. */
7089 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7092 for (bs
= bps
; bs
; bs
= bs
->next
)
7093 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7095 bs
->breakpoint_at
= NULL
;
7097 /* bs->commands will be freed later. */
7101 /* Callback for iterate_over_threads. */
7103 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7105 struct breakpoint
*bpt
= data
;
7106 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7110 /* Delete a breakpoint and clean up all traces of it in the data
7114 delete_breakpoint (struct breakpoint
*bpt
)
7116 struct breakpoint
*b
;
7117 struct bp_location
*loc
, *next
;
7119 gdb_assert (bpt
!= NULL
);
7121 /* Has this bp already been deleted? This can happen because multiple
7122 lists can hold pointers to bp's. bpstat lists are especial culprits.
7124 One example of this happening is a watchpoint's scope bp. When the
7125 scope bp triggers, we notice that the watchpoint is out of scope, and
7126 delete it. We also delete its scope bp. But the scope bp is marked
7127 "auto-deleting", and is already on a bpstat. That bpstat is then
7128 checked for auto-deleting bp's, which are deleted.
7130 A real solution to this problem might involve reference counts in bp's,
7131 and/or giving them pointers back to their referencing bpstat's, and
7132 teaching delete_breakpoint to only free a bp's storage when no more
7133 references were extent. A cheaper bandaid was chosen. */
7134 if (bpt
->type
== bp_none
)
7137 observer_notify_breakpoint_deleted (bpt
->number
);
7139 if (breakpoint_chain
== bpt
)
7140 breakpoint_chain
= bpt
->next
;
7145 b
->next
= bpt
->next
;
7149 free_command_lines (&bpt
->commands
);
7150 if (bpt
->cond_string
!= NULL
)
7151 xfree (bpt
->cond_string
);
7152 if (bpt
->addr_string
!= NULL
)
7153 xfree (bpt
->addr_string
);
7154 if (bpt
->exp
!= NULL
)
7156 if (bpt
->exp_string
!= NULL
)
7157 xfree (bpt
->exp_string
);
7158 if (bpt
->val
!= NULL
)
7159 value_free (bpt
->val
);
7160 if (bpt
->source_file
!= NULL
)
7161 xfree (bpt
->source_file
);
7162 if (bpt
->exec_pathname
!= NULL
)
7163 xfree (bpt
->exec_pathname
);
7165 /* Be sure no bpstat's are pointing at it after it's been freed. */
7166 /* FIXME, how can we find all bpstat's?
7167 We just check stop_bpstat for now. Note that we cannot just
7168 remove bpstats pointing at bpt from the stop_bpstat list
7169 entirely, as breakpoint commands are associated with the bpstat;
7170 if we remove it here, then the later call to
7171 bpstat_do_actions (&stop_bpstat);
7172 in event-top.c won't do anything, and temporary breakpoints
7173 with commands won't work. */
7175 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7177 /* Now that breakpoint is removed from breakpoint
7178 list, update the global location list. This
7179 will remove locations that used to belong to
7180 this breakpoint. Do this before freeing
7181 the breakpoint itself, since remove_breakpoint
7182 looks at location's owner. It might be better
7183 design to have location completely self-contained,
7184 but it's not the case now. */
7185 update_global_location_list (0);
7188 /* On the chance that someone will soon try again to delete this same
7189 bp, we mark it as deleted before freeing its storage. */
7190 bpt
->type
= bp_none
;
7196 do_delete_breakpoint_cleanup (void *b
)
7198 delete_breakpoint (b
);
7202 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7204 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7208 delete_command (char *arg
, int from_tty
)
7210 struct breakpoint
*b
, *temp
;
7216 int breaks_to_delete
= 0;
7218 /* Delete all breakpoints if no argument.
7219 Do not delete internal or call-dummy breakpoints, these
7220 have to be deleted with an explicit breakpoint number argument. */
7223 if (b
->type
!= bp_call_dummy
&&
7224 b
->type
!= bp_shlib_event
&&
7225 b
->type
!= bp_thread_event
&&
7226 b
->type
!= bp_overlay_event
&&
7229 breaks_to_delete
= 1;
7234 /* Ask user only if there are some breakpoints to delete. */
7236 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7238 ALL_BREAKPOINTS_SAFE (b
, temp
)
7240 if (b
->type
!= bp_call_dummy
&&
7241 b
->type
!= bp_shlib_event
&&
7242 b
->type
!= bp_thread_event
&&
7243 b
->type
!= bp_overlay_event
&&
7245 delete_breakpoint (b
);
7250 map_breakpoint_numbers (arg
, delete_breakpoint
);
7254 all_locations_are_pending (struct bp_location
*loc
)
7256 for (; loc
; loc
= loc
->next
)
7257 if (!loc
->shlib_disabled
)
7262 /* Subroutine of update_breakpoint_locations to simplify it.
7263 Return non-zero if multiple fns in list LOC have the same name.
7264 Null names are ignored. */
7267 ambiguous_names_p (struct bp_location
*loc
)
7269 struct bp_location
*l
;
7270 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7271 (int (*) (const void *, const void *)) streq
,
7272 NULL
, xcalloc
, xfree
);
7274 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7277 const char *name
= l
->function_name
;
7279 /* Allow for some names to be NULL, ignore them. */
7283 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7285 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7300 update_breakpoint_locations (struct breakpoint
*b
,
7301 struct symtabs_and_lines sals
)
7305 struct bp_location
*existing_locations
= b
->loc
;
7307 /* If there's no new locations, and all existing locations
7308 are pending, don't do anything. This optimizes
7309 the common case where all locations are in the same
7310 shared library, that was unloaded. We'd like to
7311 retain the location, so that when the library
7312 is loaded again, we don't loose the enabled/disabled
7313 status of the individual locations. */
7314 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7319 for (i
= 0; i
< sals
.nelts
; ++i
)
7321 struct bp_location
*new_loc
=
7322 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7324 /* Reparse conditions, they might contain references to the
7326 if (b
->cond_string
!= NULL
)
7328 struct gdb_exception e
;
7331 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7333 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7338 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7339 b
->number
, e
.message
);
7340 new_loc
->enabled
= 0;
7344 if (b
->source_file
!= NULL
)
7345 xfree (b
->source_file
);
7346 if (sals
.sals
[i
].symtab
== NULL
)
7347 b
->source_file
= NULL
;
7350 savestring (sals
.sals
[i
].symtab
->filename
,
7351 strlen (sals
.sals
[i
].symtab
->filename
));
7353 if (b
->line_number
== 0)
7354 b
->line_number
= sals
.sals
[i
].line
;
7357 /* Update locations of permanent breakpoints. */
7358 if (b
->enable_state
== bp_permanent
)
7359 make_breakpoint_permanent (b
);
7361 /* If possible, carry over 'disable' status from existing breakpoints. */
7363 struct bp_location
*e
= existing_locations
;
7364 /* If there are multiple breakpoints with the same function name,
7365 e.g. for inline functions, comparing function names won't work.
7366 Instead compare pc addresses; this is just a heuristic as things
7367 may have moved, but in practice it gives the correct answer
7368 often enough until a better solution is found. */
7369 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7371 for (; e
; e
= e
->next
)
7373 if (!e
->enabled
&& e
->function_name
)
7375 struct bp_location
*l
= b
->loc
;
7376 if (have_ambiguous_names
)
7378 for (; l
; l
= l
->next
)
7379 if (e
->address
== l
->address
)
7387 for (; l
; l
= l
->next
)
7388 if (l
->function_name
7389 && strcmp (e
->function_name
, l
->function_name
) == 0)
7399 update_global_location_list (1);
7403 /* Reset a breakpoint given it's struct breakpoint * BINT.
7404 The value we return ends up being the return value from catch_errors.
7405 Unused in this case. */
7408 breakpoint_re_set_one (void *bint
)
7410 /* get past catch_errs */
7411 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7415 int *not_found_ptr
= ¬_found
;
7416 struct symtabs_and_lines sals
= {};
7417 struct symtabs_and_lines expanded
;
7419 enum enable_state save_enable
;
7420 struct gdb_exception e
;
7421 struct cleanup
*cleanups
;
7426 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7430 case bp_hardware_breakpoint
:
7431 if (b
->addr_string
== NULL
)
7433 /* Anything without a string can't be re-set. */
7434 delete_breakpoint (b
);
7438 set_language (b
->language
);
7439 input_radix
= b
->input_radix
;
7441 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7443 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7448 int not_found_and_ok
= 0;
7449 /* For pending breakpoints, it's expected that parsing
7450 will fail until the right shared library is loaded.
7451 User has already told to create pending breakpoints and
7452 don't need extra messages. If breakpoint is in bp_shlib_disabled
7453 state, then user already saw the message about that breakpoint
7454 being disabled, and don't want to see more errors. */
7456 && (b
->condition_not_parsed
7457 || (b
->loc
&& b
->loc
->shlib_disabled
)
7458 || b
->enable_state
== bp_disabled
))
7459 not_found_and_ok
= 1;
7461 if (!not_found_and_ok
)
7463 /* We surely don't want to warn about the same breakpoint
7464 10 times. One solution, implemented here, is disable
7465 the breakpoint on error. Another solution would be to
7466 have separate 'warning emitted' flag. Since this
7467 happens only when a binary has changed, I don't know
7468 which approach is better. */
7469 b
->enable_state
= bp_disabled
;
7470 throw_exception (e
);
7477 gdb_assert (sals
.nelts
== 1);
7478 resolve_sal_pc (&sals
.sals
[0]);
7479 if (b
->condition_not_parsed
&& s
&& s
[0])
7481 char *cond_string
= 0;
7483 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7484 &cond_string
, &thread
);
7486 b
->cond_string
= cond_string
;
7488 b
->condition_not_parsed
= 0;
7490 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7491 cleanups
= make_cleanup (xfree
, sals
.sals
);
7492 update_breakpoint_locations (b
, expanded
);
7493 do_cleanups (cleanups
);
7497 case bp_hardware_watchpoint
:
7498 case bp_read_watchpoint
:
7499 case bp_access_watchpoint
:
7500 /* Watchpoint can be either on expression using entirely global variables,
7501 or it can be on local variables.
7503 Watchpoints of the first kind are never auto-deleted, and even persist
7504 across program restarts. Since they can use variables from shared
7505 libraries, we need to reparse expression as libraries are loaded
7508 Watchpoints on local variables can also change meaning as result
7509 of solib event. For example, if a watchpoint uses both a local and
7510 a global variables in expression, it's a local watchpoint, but
7511 unloading of a shared library will make the expression invalid.
7512 This is not a very common use case, but we still re-evaluate
7513 expression, to avoid surprises to the user.
7515 Note that for local watchpoints, we re-evaluate it only if
7516 watchpoints frame id is still valid. If it's not, it means
7517 the watchpoint is out of scope and will be deleted soon. In fact,
7518 I'm not sure we'll ever be called in this case.
7520 If a local watchpoint's frame id is still valid, then
7521 b->exp_valid_block is likewise valid, and we can safely use it.
7523 Don't do anything about disabled watchpoints, since they will
7524 be reevaluated again when enabled. */
7525 update_watchpoint (b
, 1 /* reparse */);
7527 /* We needn't really do anything to reset these, since the mask
7528 that requests them is unaffected by e.g., new libraries being
7534 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7536 /* Delete overlay event breakpoints; they will be reset later by
7537 breakpoint_re_set. */
7538 case bp_overlay_event
:
7539 delete_breakpoint (b
);
7542 /* This breakpoint is special, it's set up when the inferior
7543 starts and we really don't want to touch it. */
7544 case bp_shlib_event
:
7546 /* Like bp_shlib_event, this breakpoint type is special.
7547 Once it is set up, we do not want to touch it. */
7548 case bp_thread_event
:
7550 /* Keep temporary breakpoints, which can be encountered when we step
7551 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7552 Otherwise these should have been blown away via the cleanup chain
7553 or by breakpoint_init_inferior when we rerun the executable. */
7556 case bp_watchpoint_scope
:
7558 case bp_step_resume
:
7560 case bp_longjmp_resume
:
7567 /* Re-set all breakpoints after symbols have been re-loaded. */
7569 breakpoint_re_set (void)
7571 struct breakpoint
*b
, *temp
;
7572 enum language save_language
;
7573 int save_input_radix
;
7575 save_language
= current_language
->la_language
;
7576 save_input_radix
= input_radix
;
7577 ALL_BREAKPOINTS_SAFE (b
, temp
)
7579 /* Format possible error msg */
7580 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7582 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7583 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7584 do_cleanups (cleanups
);
7586 set_language (save_language
);
7587 input_radix
= save_input_radix
;
7589 create_overlay_event_breakpoint ("_ovly_debug_event");
7592 /* Reset the thread number of this breakpoint:
7594 - If the breakpoint is for all threads, leave it as-is.
7595 - Else, reset it to the current thread for inferior_ptid. */
7597 breakpoint_re_set_thread (struct breakpoint
*b
)
7599 if (b
->thread
!= -1)
7601 if (in_thread_list (inferior_ptid
))
7602 b
->thread
= pid_to_thread_id (inferior_ptid
);
7606 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7607 If from_tty is nonzero, it prints a message to that effect,
7608 which ends with a period (no newline). */
7611 set_ignore_count (int bptnum
, int count
, int from_tty
)
7613 struct breakpoint
*b
;
7619 if (b
->number
== bptnum
)
7621 b
->ignore_count
= count
;
7625 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7627 else if (count
== 1)
7628 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7631 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7634 breakpoints_changed ();
7635 observer_notify_breakpoint_modified (b
->number
);
7639 error (_("No breakpoint number %d."), bptnum
);
7643 make_breakpoint_silent (struct breakpoint
*b
)
7645 /* Silence the breakpoint. */
7649 /* Command to set ignore-count of breakpoint N to COUNT. */
7652 ignore_command (char *args
, int from_tty
)
7658 error_no_arg (_("a breakpoint number"));
7660 num
= get_number (&p
);
7662 error (_("bad breakpoint number: '%s'"), args
);
7664 error (_("Second argument (specified ignore-count) is missing."));
7666 set_ignore_count (num
,
7667 longest_to_int (value_as_long (parse_and_eval (p
))),
7670 printf_filtered ("\n");
7673 /* Call FUNCTION on each of the breakpoints
7674 whose numbers are given in ARGS. */
7677 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7682 struct breakpoint
*b
, *tmp
;
7686 error_no_arg (_("one or more breakpoint numbers"));
7693 num
= get_number_or_range (&p1
);
7696 warning (_("bad breakpoint number at or near '%s'"), p
);
7700 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7701 if (b
->number
== num
)
7703 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7706 if (related_breakpoint
)
7707 function (related_breakpoint
);
7711 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7717 static struct bp_location
*
7718 find_location_by_number (char *number
)
7720 char *dot
= strchr (number
, '.');
7724 struct breakpoint
*b
;
7725 struct bp_location
*loc
;
7730 bp_num
= get_number_or_range (&p1
);
7732 error (_("Bad breakpoint number '%s'"), number
);
7735 if (b
->number
== bp_num
)
7740 if (!b
|| b
->number
!= bp_num
)
7741 error (_("Bad breakpoint number '%s'"), number
);
7744 loc_num
= get_number_or_range (&p1
);
7746 error (_("Bad breakpoint location number '%s'"), number
);
7750 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7753 error (_("Bad breakpoint location number '%s'"), dot
+1);
7759 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7760 If from_tty is nonzero, it prints a message to that effect,
7761 which ends with a period (no newline). */
7764 disable_breakpoint (struct breakpoint
*bpt
)
7766 /* Never disable a watchpoint scope breakpoint; we want to
7767 hit them when we leave scope so we can delete both the
7768 watchpoint and its scope breakpoint at that time. */
7769 if (bpt
->type
== bp_watchpoint_scope
)
7772 /* You can't disable permanent breakpoints. */
7773 if (bpt
->enable_state
== bp_permanent
)
7776 bpt
->enable_state
= bp_disabled
;
7778 update_global_location_list (0);
7780 observer_notify_breakpoint_modified (bpt
->number
);
7784 disable_command (char *args
, int from_tty
)
7786 struct breakpoint
*bpt
;
7788 ALL_BREAKPOINTS (bpt
)
7792 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7797 case bp_hardware_breakpoint
:
7799 case bp_hardware_watchpoint
:
7800 case bp_read_watchpoint
:
7801 case bp_access_watchpoint
:
7802 disable_breakpoint (bpt
);
7806 else if (strchr (args
, '.'))
7808 struct bp_location
*loc
= find_location_by_number (args
);
7811 update_global_location_list (0);
7814 map_breakpoint_numbers (args
, disable_breakpoint
);
7818 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7820 int target_resources_ok
, other_type_used
;
7823 if (bpt
->type
== bp_hardware_breakpoint
)
7826 i
= hw_breakpoint_used_count ();
7827 target_resources_ok
=
7828 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7830 if (target_resources_ok
== 0)
7831 error (_("No hardware breakpoint support in the target."));
7832 else if (target_resources_ok
< 0)
7833 error (_("Hardware breakpoints used exceeds limit."));
7836 if (bpt
->type
== bp_watchpoint
||
7837 bpt
->type
== bp_hardware_watchpoint
||
7838 bpt
->type
== bp_read_watchpoint
||
7839 bpt
->type
== bp_access_watchpoint
)
7841 struct gdb_exception e
;
7843 TRY_CATCH (e
, RETURN_MASK_ALL
)
7845 update_watchpoint (bpt
, 1 /* reparse */);
7849 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
7855 if (bpt
->enable_state
!= bp_permanent
)
7856 bpt
->enable_state
= bp_enabled
;
7857 bpt
->disposition
= disposition
;
7858 update_global_location_list (1);
7859 breakpoints_changed ();
7861 observer_notify_breakpoint_modified (bpt
->number
);
7866 enable_breakpoint (struct breakpoint
*bpt
)
7868 do_enable_breakpoint (bpt
, bpt
->disposition
);
7871 /* The enable command enables the specified breakpoints (or all defined
7872 breakpoints) so they once again become (or continue to be) effective
7873 in stopping the inferior. */
7876 enable_command (char *args
, int from_tty
)
7878 struct breakpoint
*bpt
;
7880 ALL_BREAKPOINTS (bpt
)
7884 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7889 case bp_hardware_breakpoint
:
7891 case bp_hardware_watchpoint
:
7892 case bp_read_watchpoint
:
7893 case bp_access_watchpoint
:
7894 enable_breakpoint (bpt
);
7898 else if (strchr (args
, '.'))
7900 struct bp_location
*loc
= find_location_by_number (args
);
7903 update_global_location_list (1);
7906 map_breakpoint_numbers (args
, enable_breakpoint
);
7910 enable_once_breakpoint (struct breakpoint
*bpt
)
7912 do_enable_breakpoint (bpt
, disp_disable
);
7916 enable_once_command (char *args
, int from_tty
)
7918 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7922 enable_delete_breakpoint (struct breakpoint
*bpt
)
7924 do_enable_breakpoint (bpt
, disp_del
);
7928 enable_delete_command (char *args
, int from_tty
)
7930 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7934 set_breakpoint_cmd (char *args
, int from_tty
)
7939 show_breakpoint_cmd (char *args
, int from_tty
)
7943 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7945 struct symtabs_and_lines
7946 decode_line_spec_1 (char *string
, int funfirstline
)
7948 struct symtabs_and_lines sals
;
7950 error (_("Empty line specification."));
7951 if (default_breakpoint_valid
)
7952 sals
= decode_line_1 (&string
, funfirstline
,
7953 default_breakpoint_symtab
,
7954 default_breakpoint_line
,
7955 (char ***) NULL
, NULL
);
7957 sals
= decode_line_1 (&string
, funfirstline
,
7958 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7960 error (_("Junk at end of line specification: %s"), string
);
7964 /* Create and insert a raw software breakpoint at PC. Return an
7965 identifier, which should be used to remove the breakpoint later.
7966 In general, places which call this should be using something on the
7967 breakpoint chain instead; this function should be eliminated
7971 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7973 struct bp_target_info
*bp_tgt
;
7975 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7976 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7978 bp_tgt
->placed_address
= pc
;
7979 if (target_insert_breakpoint (bp_tgt
) != 0)
7981 /* Could not insert the breakpoint. */
7989 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7992 deprecated_remove_raw_breakpoint (void *bp
)
7994 struct bp_target_info
*bp_tgt
= bp
;
7997 ret
= target_remove_breakpoint (bp_tgt
);
8003 /* One (or perhaps two) breakpoints used for software single stepping. */
8005 static void *single_step_breakpoints
[2];
8007 /* Create and insert a breakpoint for software single step. */
8010 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8014 if (single_step_breakpoints
[0] == NULL
)
8015 bpt_p
= &single_step_breakpoints
[0];
8018 gdb_assert (single_step_breakpoints
[1] == NULL
);
8019 bpt_p
= &single_step_breakpoints
[1];
8022 /* NOTE drow/2006-04-11: A future improvement to this function would be
8023 to only create the breakpoints once, and actually put them on the
8024 breakpoint chain. That would let us use set_raw_breakpoint. We could
8025 adjust the addresses each time they were needed. Doing this requires
8026 corresponding changes elsewhere where single step breakpoints are
8027 handled, however. So, for now, we use this. */
8029 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8031 error (_("Could not insert single-step breakpoint at 0x%s"),
8032 paddr_nz (next_pc
));
8035 /* Remove and delete any breakpoints used for software single step. */
8038 remove_single_step_breakpoints (void)
8040 gdb_assert (single_step_breakpoints
[0] != NULL
);
8042 /* See insert_single_step_breakpoint for more about this deprecated
8044 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8045 single_step_breakpoints
[0] = NULL
;
8047 if (single_step_breakpoints
[1] != NULL
)
8049 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8050 single_step_breakpoints
[1] = NULL
;
8054 /* Check whether a software single-step breakpoint is inserted at PC. */
8057 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8061 for (i
= 0; i
< 2; i
++)
8063 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8064 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8072 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8073 It is defined as a macro to prevent duplication.
8074 COMMAND should be a string constant containing the name of the command. */
8075 #define BREAK_ARGS_HELP(command) \
8076 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8077 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8078 If a line number is specified, break at start of code for that line.\n\
8079 If a function is specified, break at start of code for that function.\n\
8080 If an address is specified, break at that exact address.\n\
8081 With no LOCATION, uses current execution address of selected stack frame.\n\
8082 This is useful for breaking on return to a stack frame.\n\
8084 THREADNUM is the number from \"info threads\".\n\
8085 CONDITION is a boolean expression.\n\
8087 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8089 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8091 /* List of subcommands for "catch". */
8092 static struct cmd_list_element
*catch_cmdlist
;
8094 /* List of subcommands for "tcatch". */
8095 static struct cmd_list_element
*tcatch_cmdlist
;
8097 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8098 lists, and pass some additional user data to the command function. */
8100 add_catch_command (char *name
, char *docstring
,
8101 void (*sfunc
) (char *args
, int from_tty
,
8102 struct cmd_list_element
*command
),
8103 void *user_data_catch
,
8104 void *user_data_tcatch
)
8106 struct cmd_list_element
*command
;
8108 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8110 set_cmd_sfunc (command
, sfunc
);
8111 set_cmd_context (command
, user_data_catch
);
8113 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8115 set_cmd_sfunc (command
, sfunc
);
8116 set_cmd_context (command
, user_data_tcatch
);
8120 _initialize_breakpoint (void)
8122 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8123 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8124 struct cmd_list_element
*c
;
8126 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8128 breakpoint_chain
= 0;
8129 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8130 before a breakpoint is set. */
8131 breakpoint_count
= 0;
8133 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8134 Set ignore-count of breakpoint number N to COUNT.\n\
8135 Usage is `ignore N COUNT'."));
8137 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8139 add_com ("commands", class_breakpoint
, commands_command
, _("\
8140 Set commands to be executed when a breakpoint is hit.\n\
8141 Give breakpoint number as argument after \"commands\".\n\
8142 With no argument, the targeted breakpoint is the last one set.\n\
8143 The commands themselves follow starting on the next line.\n\
8144 Type a line containing \"end\" to indicate the end of them.\n\
8145 Give \"silent\" as the first line to make the breakpoint silent;\n\
8146 then no output is printed when it is hit, except what the commands print."));
8148 add_com ("condition", class_breakpoint
, condition_command
, _("\
8149 Specify breakpoint number N to break only if COND is true.\n\
8150 Usage is `condition N COND', where N is an integer and COND is an\n\
8151 expression to be evaluated whenever breakpoint N is reached."));
8153 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8154 Set a temporary breakpoint.\n\
8155 Like \"break\" except the breakpoint is only temporary,\n\
8156 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8157 by using \"enable delete\" on the breakpoint number.\n\
8159 BREAK_ARGS_HELP ("tbreak")));
8160 set_cmd_completer (c
, location_completer
);
8162 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8163 Set a hardware assisted breakpoint.\n\
8164 Like \"break\" except the breakpoint requires hardware support,\n\
8165 some target hardware may not have this support.\n\
8167 BREAK_ARGS_HELP ("hbreak")));
8168 set_cmd_completer (c
, location_completer
);
8170 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8171 Set a temporary hardware assisted breakpoint.\n\
8172 Like \"hbreak\" except the breakpoint is only temporary,\n\
8173 so it will be deleted when hit.\n\
8175 BREAK_ARGS_HELP ("thbreak")));
8176 set_cmd_completer (c
, location_completer
);
8178 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8179 Enable some breakpoints.\n\
8180 Give breakpoint numbers (separated by spaces) as arguments.\n\
8181 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8182 This is used to cancel the effect of the \"disable\" command.\n\
8183 With a subcommand you can enable temporarily."),
8184 &enablelist
, "enable ", 1, &cmdlist
);
8186 add_com ("ab", class_breakpoint
, enable_command
, _("\
8187 Enable some breakpoints.\n\
8188 Give breakpoint numbers (separated by spaces) as arguments.\n\
8189 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8190 This is used to cancel the effect of the \"disable\" command.\n\
8191 With a subcommand you can enable temporarily."));
8193 add_com_alias ("en", "enable", class_breakpoint
, 1);
8195 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8196 Enable some breakpoints.\n\
8197 Give breakpoint numbers (separated by spaces) as arguments.\n\
8198 This is used to cancel the effect of the \"disable\" command.\n\
8199 May be abbreviated to simply \"enable\".\n"),
8200 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8202 add_cmd ("once", no_class
, enable_once_command
, _("\
8203 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8204 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8207 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8208 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8209 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8212 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8213 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8214 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8217 add_cmd ("once", no_class
, enable_once_command
, _("\
8218 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8219 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8222 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8223 Disable some breakpoints.\n\
8224 Arguments are breakpoint numbers with spaces in between.\n\
8225 To disable all breakpoints, give no argument.\n\
8226 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8227 &disablelist
, "disable ", 1, &cmdlist
);
8228 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8229 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8231 add_com ("sb", class_breakpoint
, disable_command
, _("\
8232 Disable some breakpoints.\n\
8233 Arguments are breakpoint numbers with spaces in between.\n\
8234 To disable all breakpoints, give no argument.\n\
8235 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8237 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8238 Disable some breakpoints.\n\
8239 Arguments are breakpoint numbers with spaces in between.\n\
8240 To disable all breakpoints, give no argument.\n\
8241 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8242 This command may be abbreviated \"disable\"."),
8245 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8246 Delete some breakpoints or auto-display expressions.\n\
8247 Arguments are breakpoint numbers with spaces in between.\n\
8248 To delete all breakpoints, give no argument.\n\
8250 Also a prefix command for deletion of other GDB objects.\n\
8251 The \"unset\" command is also an alias for \"delete\"."),
8252 &deletelist
, "delete ", 1, &cmdlist
);
8253 add_com_alias ("d", "delete", class_breakpoint
, 1);
8254 add_com_alias ("del", "delete", class_breakpoint
, 1);
8256 add_com ("db", class_breakpoint
, delete_command
, _("\
8257 Delete some breakpoints.\n\
8258 Arguments are breakpoint numbers with spaces in between.\n\
8259 To delete all breakpoints, give no argument.\n"));
8261 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8262 Delete some breakpoints or auto-display expressions.\n\
8263 Arguments are breakpoint numbers with spaces in between.\n\
8264 To delete all breakpoints, give no argument.\n\
8265 This command may be abbreviated \"delete\"."),
8268 add_com ("clear", class_breakpoint
, clear_command
, _("\
8269 Clear breakpoint at specified line or function.\n\
8270 Argument may be line number, function name, or \"*\" and an address.\n\
8271 If line number is specified, all breakpoints in that line are cleared.\n\
8272 If function is specified, breakpoints at beginning of function are cleared.\n\
8273 If an address is specified, breakpoints at that address are cleared.\n\
8275 With no argument, clears all breakpoints in the line that the selected frame\n\
8278 See also the \"delete\" command which clears breakpoints by number."));
8280 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8281 Set breakpoint at specified line or function.\n"
8282 BREAK_ARGS_HELP ("break")));
8283 set_cmd_completer (c
, location_completer
);
8285 add_com_alias ("b", "break", class_run
, 1);
8286 add_com_alias ("br", "break", class_run
, 1);
8287 add_com_alias ("bre", "break", class_run
, 1);
8288 add_com_alias ("brea", "break", class_run
, 1);
8292 add_com_alias ("ba", "break", class_breakpoint
, 1);
8293 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8298 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8299 Break in function/address or break at a line in the current file."),
8300 &stoplist
, "stop ", 1, &cmdlist
);
8301 add_cmd ("in", class_breakpoint
, stopin_command
,
8302 _("Break in function or address."), &stoplist
);
8303 add_cmd ("at", class_breakpoint
, stopat_command
,
8304 _("Break at a line in the current file."), &stoplist
);
8305 add_com ("status", class_info
, breakpoints_info
, _("\
8306 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8307 The \"Type\" column indicates one of:\n\
8308 \tbreakpoint - normal breakpoint\n\
8309 \twatchpoint - watchpoint\n\
8310 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8311 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8312 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8313 address and file/line number respectively.\n\
8315 Convenience variable \"$_\" and default examine address for \"x\"\n\
8316 are set to the address of the last breakpoint listed unless the command\n\
8317 is prefixed with \"server \".\n\n\
8318 Convenience variable \"$bpnum\" contains the number of the last\n\
8322 add_info ("breakpoints", breakpoints_info
, _("\
8323 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8324 The \"Type\" column indicates one of:\n\
8325 \tbreakpoint - normal breakpoint\n\
8326 \twatchpoint - watchpoint\n\
8327 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8328 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8329 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8330 address and file/line number respectively.\n\
8332 Convenience variable \"$_\" and default examine address for \"x\"\n\
8333 are set to the address of the last breakpoint listed unless the command\n\
8334 is prefixed with \"server \".\n\n\
8335 Convenience variable \"$bpnum\" contains the number of the last\n\
8339 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8340 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8341 The \"Type\" column indicates one of:\n\
8342 \tbreakpoint - normal breakpoint\n\
8343 \twatchpoint - watchpoint\n\
8344 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8345 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8346 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8347 address and file/line number respectively.\n\
8349 Convenience variable \"$_\" and default examine address for \"x\"\n\
8350 are set to the address of the last breakpoint listed unless the command\n\
8351 is prefixed with \"server \".\n\n\
8352 Convenience variable \"$bpnum\" contains the number of the last\n\
8355 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8356 Status of all breakpoints, or breakpoint number NUMBER.\n\
8357 The \"Type\" column indicates one of:\n\
8358 \tbreakpoint - normal breakpoint\n\
8359 \twatchpoint - watchpoint\n\
8360 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8361 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8362 \tuntil - internal breakpoint used by the \"until\" command\n\
8363 \tfinish - internal breakpoint used by the \"finish\" command\n\
8364 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8365 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8366 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8367 address and file/line number respectively.\n\
8369 Convenience variable \"$_\" and default examine address for \"x\"\n\
8370 are set to the address of the last breakpoint listed unless the command\n\
8371 is prefixed with \"server \".\n\n\
8372 Convenience variable \"$bpnum\" contains the number of the last\n\
8374 &maintenanceinfolist
);
8376 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8377 Set catchpoints to catch events."),
8378 &catch_cmdlist
, "catch ",
8379 0/*allow-unknown*/, &cmdlist
);
8381 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8382 Set temporary catchpoints to catch events."),
8383 &tcatch_cmdlist
, "tcatch ",
8384 0/*allow-unknown*/, &cmdlist
);
8386 /* Add catch and tcatch sub-commands. */
8387 add_catch_command ("catch", _("\
8388 Catch an exception, when caught.\n\
8389 With an argument, catch only exceptions with the given name."),
8390 catch_catch_command
,
8393 add_catch_command ("throw", _("\
8394 Catch an exception, when thrown.\n\
8395 With an argument, catch only exceptions with the given name."),
8396 catch_throw_command
,
8399 add_catch_command ("fork", _("Catch calls to fork."),
8400 catch_fork_command_1
,
8401 (void *) (uintptr_t) catch_fork_permanent
,
8402 (void *) (uintptr_t) catch_fork_temporary
);
8403 add_catch_command ("vfork", _("Catch calls to vfork."),
8404 catch_fork_command_1
,
8405 (void *) (uintptr_t) catch_vfork_permanent
,
8406 (void *) (uintptr_t) catch_vfork_temporary
);
8407 add_catch_command ("exec", _("Catch calls to exec."),
8408 catch_exec_command_1
,
8411 add_catch_command ("exception", _("\
8412 Catch Ada exceptions, when raised.\n\
8413 With an argument, catch only exceptions with the given name."),
8414 catch_ada_exception_command
,
8417 add_catch_command ("assert", _("\
8418 Catch failed Ada assertions, when raised.\n\
8419 With an argument, catch only exceptions with the given name."),
8420 catch_assert_command
,
8424 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8425 Set a watchpoint for an expression.\n\
8426 A watchpoint stops execution of your program whenever the value of\n\
8427 an expression changes."));
8428 set_cmd_completer (c
, expression_completer
);
8430 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8431 Set a read watchpoint for an expression.\n\
8432 A watchpoint stops execution of your program whenever the value of\n\
8433 an expression is read."));
8434 set_cmd_completer (c
, expression_completer
);
8436 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8437 Set a watchpoint for an expression.\n\
8438 A watchpoint stops execution of your program whenever the value of\n\
8439 an expression is either read or written."));
8440 set_cmd_completer (c
, expression_completer
);
8442 add_info ("watchpoints", breakpoints_info
,
8443 _("Synonym for ``info breakpoints''."));
8446 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8447 respond to changes - contrary to the description. */
8448 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8449 &can_use_hw_watchpoints
, _("\
8450 Set debugger's willingness to use watchpoint hardware."), _("\
8451 Show debugger's willingness to use watchpoint hardware."), _("\
8452 If zero, gdb will not use hardware for new watchpoints, even if\n\
8453 such is available. (However, any hardware watchpoints that were\n\
8454 created before setting this to nonzero, will continue to use watchpoint\n\
8457 show_can_use_hw_watchpoints
,
8458 &setlist
, &showlist
);
8460 can_use_hw_watchpoints
= 1;
8462 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8463 Breakpoint specific settings\n\
8464 Configure various breakpoint-specific variables such as\n\
8465 pending breakpoint behavior"),
8466 &breakpoint_set_cmdlist
, "set breakpoint ",
8467 0/*allow-unknown*/, &setlist
);
8468 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8469 Breakpoint specific settings\n\
8470 Configure various breakpoint-specific variables such as\n\
8471 pending breakpoint behavior"),
8472 &breakpoint_show_cmdlist
, "show breakpoint ",
8473 0/*allow-unknown*/, &showlist
);
8475 add_setshow_auto_boolean_cmd ("pending", no_class
,
8476 &pending_break_support
, _("\
8477 Set debugger's behavior regarding pending breakpoints."), _("\
8478 Show debugger's behavior regarding pending breakpoints."), _("\
8479 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8480 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8481 an error. If auto, an unrecognized breakpoint location results in a\n\
8482 user-query to see if a pending breakpoint should be created."),
8484 show_pending_break_support
,
8485 &breakpoint_set_cmdlist
,
8486 &breakpoint_show_cmdlist
);
8488 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8490 add_setshow_boolean_cmd ("auto-hw", no_class
,
8491 &automatic_hardware_breakpoints
, _("\
8492 Set automatic usage of hardware breakpoints."), _("\
8493 Show automatic usage of hardware breakpoints."), _("\
8494 If set, the debugger will automatically use hardware breakpoints for\n\
8495 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8496 a warning will be emitted for such breakpoints."),
8498 show_automatic_hardware_breakpoints
,
8499 &breakpoint_set_cmdlist
,
8500 &breakpoint_show_cmdlist
);
8502 add_setshow_enum_cmd ("always-inserted", class_support
,
8503 always_inserted_enums
, &always_inserted_mode
, _("\
8504 Set mode for inserting breakpoints."), _("\
8505 Show mode for inserting breakpoints."), _("\
8506 When this mode is off, breakpoints are inserted in inferior when it is\n\
8507 resumed, and removed when execution stops. When this mode is on,\n\
8508 breakpoints are inserted immediately and removed only when the user\n\
8509 deletes the breakpoint. When this mode is auto (which is the default),\n\
8510 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8511 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8512 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8513 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8515 &show_always_inserted_mode
,
8516 &breakpoint_set_cmdlist
,
8517 &breakpoint_show_cmdlist
);
8519 automatic_hardware_breakpoints
= 1;
8521 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);