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
;
1896 /* The thread ID associated to PTID, computed lazily. */
1899 ALL_BP_LOCATIONS (bpt
)
1901 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1902 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1905 if (!breakpoint_enabled (bpt
->owner
)
1906 && bpt
->owner
->enable_state
!= bp_permanent
)
1909 if (bpt
->address
!= pc
)
1912 if (bpt
->owner
->thread
!= -1)
1914 /* This is a thread-specific breakpoint. Check that ptid
1915 matches that thread. If thread hasn't been computed yet,
1916 it is now time to do so. */
1918 thread
= pid_to_thread_id (ptid
);
1919 if (bpt
->owner
->thread
!= thread
)
1923 if (overlay_debugging
1924 && section_is_overlay (bpt
->section
)
1925 && !section_is_mapped (bpt
->section
))
1926 continue; /* unmapped overlay -- can't be a match */
1935 /* bpstat stuff. External routines' interfaces are documented
1939 ep_is_catchpoint (struct breakpoint
*ep
)
1941 return (ep
->type
== bp_catchpoint
);
1945 bpstat_free (bpstat bs
)
1947 if (bs
->old_val
!= NULL
)
1948 value_free (bs
->old_val
);
1949 free_command_lines (&bs
->commands
);
1953 /* Clear a bpstat so that it says we are not at any breakpoint.
1954 Also free any storage that is part of a bpstat. */
1957 bpstat_clear (bpstat
*bsp
)
1974 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1975 is part of the bpstat is copied as well. */
1978 bpstat_copy (bpstat bs
)
1982 bpstat retval
= NULL
;
1987 for (; bs
!= NULL
; bs
= bs
->next
)
1989 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1990 memcpy (tmp
, bs
, sizeof (*tmp
));
1991 if (bs
->commands
!= NULL
)
1992 tmp
->commands
= copy_command_lines (bs
->commands
);
1993 if (bs
->old_val
!= NULL
)
1995 tmp
->old_val
= value_copy (bs
->old_val
);
1996 release_value (tmp
->old_val
);
2000 /* This is the first thing in the chain. */
2010 /* Find the bpstat associated with this breakpoint */
2013 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2018 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2020 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2026 /* Find a step_resume breakpoint associated with this bpstat.
2027 (If there are multiple step_resume bp's on the list, this function
2028 will arbitrarily pick one.)
2030 It is an error to use this function if BPSTAT doesn't contain a
2031 step_resume breakpoint.
2033 See wait_for_inferior's use of this function. */
2035 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2039 gdb_assert (bsp
!= NULL
);
2041 current_thread
= pid_to_thread_id (inferior_ptid
);
2043 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2045 if ((bsp
->breakpoint_at
!= NULL
) &&
2046 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2047 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2048 bsp
->breakpoint_at
->owner
->thread
== -1))
2049 return bsp
->breakpoint_at
->owner
;
2052 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2056 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2057 at. *BSP upon return is a bpstat which points to the remaining
2058 breakpoints stopped at (but which is not guaranteed to be good for
2059 anything but further calls to bpstat_num).
2060 Return 0 if passed a bpstat which does not indicate any breakpoints.
2061 Return -1 if stopped at a breakpoint that has been deleted since
2063 Return 1 otherwise. */
2066 bpstat_num (bpstat
*bsp
, int *num
)
2068 struct breakpoint
*b
;
2071 return 0; /* No more breakpoint values */
2073 /* We assume we'll never have several bpstats that
2074 correspond to a single breakpoint -- otherwise,
2075 this function might return the same number more
2076 than once and this will look ugly. */
2077 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2078 *bsp
= (*bsp
)->next
;
2080 return -1; /* breakpoint that's been deleted since */
2082 *num
= b
->number
; /* We have its number */
2086 /* Modify BS so that the actions will not be performed. */
2089 bpstat_clear_actions (bpstat bs
)
2091 for (; bs
!= NULL
; bs
= bs
->next
)
2093 free_command_lines (&bs
->commands
);
2094 if (bs
->old_val
!= NULL
)
2096 value_free (bs
->old_val
);
2102 /* Called when a command is about to proceed the inferior. */
2105 breakpoint_about_to_proceed (void)
2107 if (!ptid_equal (inferior_ptid
, null_ptid
))
2109 struct thread_info
*tp
= inferior_thread ();
2111 /* Allow inferior function calls in breakpoint commands to not
2112 interrupt the command list. When the call finishes
2113 successfully, the inferior will be standing at the same
2114 breakpoint as if nothing happened. */
2119 breakpoint_proceeded
= 1;
2122 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2124 cleanup_executing_breakpoints (void *ignore
)
2126 executing_breakpoint_commands
= 0;
2129 /* Execute all the commands associated with all the breakpoints at this
2130 location. Any of these commands could cause the process to proceed
2131 beyond this point, etc. We look out for such changes by checking
2132 the global "breakpoint_proceeded" after each command.
2134 Returns true if a breakpoint command resumed the inferior. In that
2135 case, it is the caller's responsibility to recall it again with the
2136 bpstat of the current thread. */
2139 bpstat_do_actions_1 (bpstat
*bsp
)
2142 struct cleanup
*old_chain
;
2145 /* Avoid endless recursion if a `source' command is contained
2147 if (executing_breakpoint_commands
)
2150 executing_breakpoint_commands
= 1;
2151 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2153 /* This pointer will iterate over the list of bpstat's. */
2156 breakpoint_proceeded
= 0;
2157 for (; bs
!= NULL
; bs
= bs
->next
)
2159 struct command_line
*cmd
;
2160 struct cleanup
*this_cmd_tree_chain
;
2162 /* Take ownership of the BSP's command tree, if it has one.
2164 The command tree could legitimately contain commands like
2165 'step' and 'next', which call clear_proceed_status, which
2166 frees stop_bpstat's command tree. To make sure this doesn't
2167 free the tree we're executing out from under us, we need to
2168 take ownership of the tree ourselves. Since a given bpstat's
2169 commands are only executed once, we don't need to copy it; we
2170 can clear the pointer in the bpstat, and make sure we free
2171 the tree when we're done. */
2174 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2178 execute_control_command (cmd
);
2180 if (breakpoint_proceeded
)
2186 /* We can free this command tree now. */
2187 do_cleanups (this_cmd_tree_chain
);
2189 if (breakpoint_proceeded
)
2191 if (target_can_async_p ())
2192 /* If we are in async mode, then the target might be still
2193 running, not stopped at any breakpoint, so nothing for
2194 us to do here -- just return to the event loop. */
2197 /* In sync mode, when execute_control_command returns
2198 we're already standing on the next breakpoint.
2199 Breakpoint commands for that stop were not run, since
2200 execute_command does not run breakpoint commands --
2201 only command_line_handler does, but that one is not
2202 involved in execution of breakpoint commands. So, we
2203 can now execute breakpoint commands. It should be
2204 noted that making execute_command do bpstat actions is
2205 not an option -- in this case we'll have recursive
2206 invocation of bpstat for each breakpoint with a
2207 command, and can easily blow up GDB stack. Instead, we
2208 return true, which will trigger the caller to recall us
2209 with the new stop_bpstat. */
2214 do_cleanups (old_chain
);
2219 bpstat_do_actions (void)
2221 /* Do any commands attached to breakpoint we are stopped at. */
2222 while (!ptid_equal (inferior_ptid
, null_ptid
)
2223 && target_has_execution
2224 && !is_exited (inferior_ptid
)
2225 && !is_executing (inferior_ptid
))
2226 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2227 and only return when it is stopped at the next breakpoint, we
2228 keep doing breakpoint actions until it returns false to
2229 indicate the inferior was not resumed. */
2230 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2234 /* Print out the (old or new) value associated with a watchpoint. */
2237 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2240 fprintf_unfiltered (stream
, _("<unreadable>"));
2243 struct value_print_options opts
;
2244 get_user_print_options (&opts
);
2245 value_print (val
, stream
, &opts
);
2249 /* This is the normal print function for a bpstat. In the future,
2250 much of this logic could (should?) be moved to bpstat_stop_status,
2251 by having it set different print_it values.
2253 Current scheme: When we stop, bpstat_print() is called. It loops
2254 through the bpstat list of things causing this stop, calling the
2255 print_bp_stop_message function on each one. The behavior of the
2256 print_bp_stop_message function depends on the print_it field of
2257 bpstat. If such field so indicates, call this function here.
2259 Return values from this routine (ultimately used by bpstat_print()
2260 and normal_stop() to decide what to do):
2261 PRINT_NOTHING: Means we already printed all we needed to print,
2262 don't print anything else.
2263 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2264 that something to be followed by a location.
2265 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2266 that something to be followed by a location.
2267 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2270 static enum print_stop_action
2271 print_it_typical (bpstat bs
)
2273 struct cleanup
*old_chain
;
2274 struct breakpoint
*b
;
2275 const struct bp_location
*bl
;
2276 struct ui_stream
*stb
;
2278 enum print_stop_action result
;
2280 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2281 which has since been deleted. */
2282 if (bs
->breakpoint_at
== NULL
)
2283 return PRINT_UNKNOWN
;
2284 bl
= bs
->breakpoint_at
;
2287 stb
= ui_out_stream_new (uiout
);
2288 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2293 case bp_hardware_breakpoint
:
2294 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2295 if (bl
->address
!= bl
->requested_address
)
2296 breakpoint_adjustment_warning (bl
->requested_address
,
2299 annotate_breakpoint (b
->number
);
2301 ui_out_text (uiout
, "\nTemporary breakpoint ");
2303 ui_out_text (uiout
, "\nBreakpoint ");
2304 if (ui_out_is_mi_like_p (uiout
))
2306 ui_out_field_string (uiout
, "reason",
2307 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2308 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2310 ui_out_field_int (uiout
, "bkptno", b
->number
);
2311 ui_out_text (uiout
, ", ");
2312 result
= PRINT_SRC_AND_LOC
;
2315 case bp_shlib_event
:
2316 /* Did we stop because the user set the stop_on_solib_events
2317 variable? (If so, we report this as a generic, "Stopped due
2318 to shlib event" message.) */
2319 printf_filtered (_("Stopped due to shared library event\n"));
2320 result
= PRINT_NOTHING
;
2323 case bp_thread_event
:
2324 /* Not sure how we will get here.
2325 GDB should not stop for these breakpoints. */
2326 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2327 result
= PRINT_NOTHING
;
2330 case bp_overlay_event
:
2331 /* By analogy with the thread event, GDB should not stop for these. */
2332 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2333 result
= PRINT_NOTHING
;
2337 case bp_hardware_watchpoint
:
2338 annotate_watchpoint (b
->number
);
2339 if (ui_out_is_mi_like_p (uiout
))
2342 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2344 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2345 ui_out_text (uiout
, "\nOld value = ");
2346 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2347 ui_out_field_stream (uiout
, "old", stb
);
2348 ui_out_text (uiout
, "\nNew value = ");
2349 watchpoint_value_print (b
->val
, stb
->stream
);
2350 ui_out_field_stream (uiout
, "new", stb
);
2351 ui_out_text (uiout
, "\n");
2352 /* More than one watchpoint may have been triggered. */
2353 result
= PRINT_UNKNOWN
;
2356 case bp_read_watchpoint
:
2357 if (ui_out_is_mi_like_p (uiout
))
2360 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2362 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2363 ui_out_text (uiout
, "\nValue = ");
2364 watchpoint_value_print (b
->val
, stb
->stream
);
2365 ui_out_field_stream (uiout
, "value", stb
);
2366 ui_out_text (uiout
, "\n");
2367 result
= PRINT_UNKNOWN
;
2370 case bp_access_watchpoint
:
2371 if (bs
->old_val
!= NULL
)
2373 annotate_watchpoint (b
->number
);
2374 if (ui_out_is_mi_like_p (uiout
))
2377 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2379 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2380 ui_out_text (uiout
, "\nOld value = ");
2381 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2382 ui_out_field_stream (uiout
, "old", stb
);
2383 ui_out_text (uiout
, "\nNew value = ");
2388 if (ui_out_is_mi_like_p (uiout
))
2391 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2392 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2393 ui_out_text (uiout
, "\nValue = ");
2395 watchpoint_value_print (b
->val
, stb
->stream
);
2396 ui_out_field_stream (uiout
, "new", stb
);
2397 ui_out_text (uiout
, "\n");
2398 result
= PRINT_UNKNOWN
;
2401 /* Fall through, we don't deal with these types of breakpoints
2405 if (ui_out_is_mi_like_p (uiout
))
2408 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2409 result
= PRINT_UNKNOWN
;
2413 if (ui_out_is_mi_like_p (uiout
))
2416 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2417 result
= PRINT_UNKNOWN
;
2422 case bp_longjmp_resume
:
2423 case bp_step_resume
:
2424 case bp_watchpoint_scope
:
2427 result
= PRINT_UNKNOWN
;
2431 do_cleanups (old_chain
);
2435 /* Generic routine for printing messages indicating why we
2436 stopped. The behavior of this function depends on the value
2437 'print_it' in the bpstat structure. Under some circumstances we
2438 may decide not to print anything here and delegate the task to
2441 static enum print_stop_action
2442 print_bp_stop_message (bpstat bs
)
2444 switch (bs
->print_it
)
2447 /* Nothing should be printed for this bpstat entry. */
2448 return PRINT_UNKNOWN
;
2452 /* We still want to print the frame, but we already printed the
2453 relevant messages. */
2454 return PRINT_SRC_AND_LOC
;
2457 case print_it_normal
:
2459 const struct bp_location
*bl
= bs
->breakpoint_at
;
2460 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2462 /* Normal case. Call the breakpoint's print_it method, or
2463 print_it_typical. */
2464 /* FIXME: how breakpoint can ever be NULL here? */
2465 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2466 return b
->ops
->print_it (b
);
2468 return print_it_typical (bs
);
2473 internal_error (__FILE__
, __LINE__
,
2474 _("print_bp_stop_message: unrecognized enum value"));
2479 /* Print a message indicating what happened. This is called from
2480 normal_stop(). The input to this routine is the head of the bpstat
2481 list - a list of the eventpoints that caused this stop. This
2482 routine calls the generic print routine for printing a message
2483 about reasons for stopping. This will print (for example) the
2484 "Breakpoint n," part of the output. The return value of this
2487 PRINT_UNKNOWN: Means we printed nothing
2488 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2489 code to print the location. An example is
2490 "Breakpoint 1, " which should be followed by
2492 PRINT_SRC_ONLY: Means we printed something, but there is no need
2493 to also print the location part of the message.
2494 An example is the catch/throw messages, which
2495 don't require a location appended to the end.
2496 PRINT_NOTHING: We have done some printing and we don't need any
2497 further info to be printed.*/
2499 enum print_stop_action
2500 bpstat_print (bpstat bs
)
2504 /* Maybe another breakpoint in the chain caused us to stop.
2505 (Currently all watchpoints go on the bpstat whether hit or not.
2506 That probably could (should) be changed, provided care is taken
2507 with respect to bpstat_explains_signal). */
2508 for (; bs
; bs
= bs
->next
)
2510 val
= print_bp_stop_message (bs
);
2511 if (val
== PRINT_SRC_ONLY
2512 || val
== PRINT_SRC_AND_LOC
2513 || val
== PRINT_NOTHING
)
2517 /* We reached the end of the chain, or we got a null BS to start
2518 with and nothing was printed. */
2519 return PRINT_UNKNOWN
;
2522 /* Evaluate the expression EXP and return 1 if value is zero.
2523 This is used inside a catch_errors to evaluate the breakpoint condition.
2524 The argument is a "struct expression *" that has been cast to char * to
2525 make it pass through catch_errors. */
2528 breakpoint_cond_eval (void *exp
)
2530 struct value
*mark
= value_mark ();
2531 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2532 value_free_to_mark (mark
);
2536 /* Allocate a new bpstat and chain it to the current one. */
2539 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2543 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2545 bs
->breakpoint_at
= bl
;
2546 /* If the condition is false, etc., don't do the commands. */
2547 bs
->commands
= NULL
;
2549 bs
->print_it
= print_it_normal
;
2553 /* The target has stopped with waitstatus WS. Check if any hardware
2554 watchpoints have triggered, according to the target. */
2557 watchpoints_triggered (struct target_waitstatus
*ws
)
2559 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2561 struct breakpoint
*b
;
2563 if (!stopped_by_watchpoint
)
2565 /* We were not stopped by a watchpoint. Mark all watchpoints
2566 as not triggered. */
2568 if (b
->type
== bp_hardware_watchpoint
2569 || b
->type
== bp_read_watchpoint
2570 || b
->type
== bp_access_watchpoint
)
2571 b
->watchpoint_triggered
= watch_triggered_no
;
2576 if (!target_stopped_data_address (¤t_target
, &addr
))
2578 /* We were stopped by a watchpoint, but we don't know where.
2579 Mark all watchpoints as unknown. */
2581 if (b
->type
== bp_hardware_watchpoint
2582 || b
->type
== bp_read_watchpoint
2583 || b
->type
== bp_access_watchpoint
)
2584 b
->watchpoint_triggered
= watch_triggered_unknown
;
2586 return stopped_by_watchpoint
;
2589 /* The target could report the data address. Mark watchpoints
2590 affected by this data address as triggered, and all others as not
2594 if (b
->type
== bp_hardware_watchpoint
2595 || b
->type
== bp_read_watchpoint
2596 || b
->type
== bp_access_watchpoint
)
2598 struct bp_location
*loc
;
2601 b
->watchpoint_triggered
= watch_triggered_no
;
2602 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2603 /* Exact match not required. Within range is
2605 if (target_watchpoint_addr_within_range (¤t_target
,
2609 b
->watchpoint_triggered
= watch_triggered_yes
;
2617 /* Possible return values for watchpoint_check (this can't be an enum
2618 because of check_errors). */
2619 /* The watchpoint has been deleted. */
2620 #define WP_DELETED 1
2621 /* The value has changed. */
2622 #define WP_VALUE_CHANGED 2
2623 /* The value has not changed. */
2624 #define WP_VALUE_NOT_CHANGED 3
2626 #define BP_TEMPFLAG 1
2627 #define BP_HARDWAREFLAG 2
2629 /* Check watchpoint condition. */
2632 watchpoint_check (void *p
)
2634 bpstat bs
= (bpstat
) p
;
2635 struct breakpoint
*b
;
2636 struct frame_info
*fr
;
2637 int within_current_scope
;
2639 b
= bs
->breakpoint_at
->owner
;
2641 if (b
->exp_valid_block
== NULL
)
2642 within_current_scope
= 1;
2645 /* There is no current frame at this moment. If we're going to have
2646 any chance of handling watchpoints on local variables, we'll need
2647 the frame chain (so we can determine if we're in scope). */
2648 reinit_frame_cache ();
2649 fr
= frame_find_by_id (b
->watchpoint_frame
);
2650 within_current_scope
= (fr
!= NULL
);
2652 /* If we've gotten confused in the unwinder, we might have
2653 returned a frame that can't describe this variable. */
2654 if (within_current_scope
2655 && (block_linkage_function (b
->exp_valid_block
)
2656 != get_frame_function (fr
)))
2657 within_current_scope
= 0;
2659 /* in_function_epilogue_p() returns a non-zero value if we're still
2660 in the function but the stack frame has already been invalidated.
2661 Since we can't rely on the values of local variables after the
2662 stack has been destroyed, we are treating the watchpoint in that
2663 state as `not changed' without further checking.
2665 vinschen/2003-09-04: The former implementation left out the case
2666 that the watchpoint frame couldn't be found by frame_find_by_id()
2667 because the current PC is currently in an epilogue. Calling
2668 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2669 if ((!within_current_scope
|| fr
== get_current_frame ())
2670 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2671 return WP_VALUE_NOT_CHANGED
;
2672 if (fr
&& within_current_scope
)
2673 /* If we end up stopping, the current frame will get selected
2674 in normal_stop. So this call to select_frame won't affect
2679 if (within_current_scope
)
2681 /* We use value_{,free_to_}mark because it could be a
2682 *long* time before we return to the command level and
2683 call free_all_values. We can't call free_all_values because
2684 we might be in the middle of evaluating a function call. */
2686 struct value
*mark
= value_mark ();
2687 struct value
*new_val
;
2689 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2690 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2691 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2693 if (new_val
!= NULL
)
2695 release_value (new_val
);
2696 value_free_to_mark (mark
);
2698 bs
->old_val
= b
->val
;
2701 /* We will stop here */
2702 return WP_VALUE_CHANGED
;
2706 /* Nothing changed, don't do anything. */
2707 value_free_to_mark (mark
);
2708 /* We won't stop here */
2709 return WP_VALUE_NOT_CHANGED
;
2714 /* This seems like the only logical thing to do because
2715 if we temporarily ignored the watchpoint, then when
2716 we reenter the block in which it is valid it contains
2717 garbage (in the case of a function, it may have two
2718 garbage values, one before and one after the prologue).
2719 So we can't even detect the first assignment to it and
2720 watch after that (since the garbage may or may not equal
2721 the first value assigned). */
2722 /* We print all the stop information in print_it_typical(), but
2723 in this case, by the time we call print_it_typical() this bp
2724 will be deleted already. So we have no choice but print the
2725 information here. */
2726 if (ui_out_is_mi_like_p (uiout
))
2728 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2729 ui_out_text (uiout
, "\nWatchpoint ");
2730 ui_out_field_int (uiout
, "wpnum", b
->number
);
2731 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2732 which its expression is valid.\n");
2734 if (b
->related_breakpoint
)
2735 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2736 b
->disposition
= disp_del_at_next_stop
;
2742 /* Return true if it looks like target has stopped due to hitting
2743 breakpoint location BL. This function does not check if we
2744 should stop, only if BL explains the stop. */
2746 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2748 struct breakpoint
*b
= bl
->owner
;
2750 if (b
->type
!= bp_watchpoint
2751 && b
->type
!= bp_hardware_watchpoint
2752 && b
->type
!= bp_read_watchpoint
2753 && b
->type
!= bp_access_watchpoint
2754 && b
->type
!= bp_hardware_breakpoint
2755 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2757 if (bl
->address
!= bp_addr
) /* address doesn't match */
2759 if (overlay_debugging
/* unmapped overlay section */
2760 && section_is_overlay (bl
->section
)
2761 && !section_is_mapped (bl
->section
))
2765 /* Continuable hardware watchpoints are treated as non-existent if the
2766 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2767 some data address). Otherwise gdb won't stop on a break instruction
2768 in the code (not from a breakpoint) when a hardware watchpoint has
2769 been defined. Also skip watchpoints which we know did not trigger
2770 (did not match the data address). */
2772 if ((b
->type
== bp_hardware_watchpoint
2773 || b
->type
== bp_read_watchpoint
2774 || b
->type
== bp_access_watchpoint
)
2775 && b
->watchpoint_triggered
== watch_triggered_no
)
2778 if (b
->type
== bp_hardware_breakpoint
)
2780 if (bl
->address
!= bp_addr
)
2782 if (overlay_debugging
/* unmapped overlay section */
2783 && section_is_overlay (bl
->section
)
2784 && !section_is_mapped (bl
->section
))
2788 if (b
->type
== bp_catchpoint
)
2790 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2791 if (!b
->ops
->breakpoint_hit (b
))
2798 /* If BS refers to a watchpoint, determine if the watched values
2799 has actually changed, and we should stop. If not, set BS->stop
2802 bpstat_check_watchpoint (bpstat bs
)
2804 const struct bp_location
*bl
= bs
->breakpoint_at
;
2805 struct breakpoint
*b
= bl
->owner
;
2807 if (b
->type
== bp_watchpoint
2808 || b
->type
== bp_read_watchpoint
2809 || b
->type
== bp_access_watchpoint
2810 || b
->type
== bp_hardware_watchpoint
)
2814 int must_check_value
= 0;
2816 if (b
->type
== bp_watchpoint
)
2817 /* For a software watchpoint, we must always check the
2819 must_check_value
= 1;
2820 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2821 /* We have a hardware watchpoint (read, write, or access)
2822 and the target earlier reported an address watched by
2824 must_check_value
= 1;
2825 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2826 && b
->type
== bp_hardware_watchpoint
)
2827 /* We were stopped by a hardware watchpoint, but the target could
2828 not report the data address. We must check the watchpoint's
2829 value. Access and read watchpoints are out of luck; without
2830 a data address, we can't figure it out. */
2831 must_check_value
= 1;
2833 if (must_check_value
)
2835 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2837 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2838 int e
= catch_errors (watchpoint_check
, bs
, message
,
2840 do_cleanups (cleanups
);
2844 /* We've already printed what needs to be printed. */
2845 bs
->print_it
= print_it_done
;
2848 case WP_VALUE_CHANGED
:
2849 if (b
->type
== bp_read_watchpoint
)
2851 /* Don't stop: read watchpoints shouldn't fire if
2852 the value has changed. This is for targets
2853 which cannot set read-only watchpoints. */
2854 bs
->print_it
= print_it_noop
;
2858 case WP_VALUE_NOT_CHANGED
:
2859 if (b
->type
== bp_hardware_watchpoint
2860 || b
->type
== bp_watchpoint
)
2862 /* Don't stop: write watchpoints shouldn't fire if
2863 the value hasn't changed. */
2864 bs
->print_it
= print_it_noop
;
2872 /* Error from catch_errors. */
2873 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2874 if (b
->related_breakpoint
)
2875 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2876 b
->disposition
= disp_del_at_next_stop
;
2877 /* We've already printed what needs to be printed. */
2878 bs
->print_it
= print_it_done
;
2882 else /* must_check_value == 0 */
2884 /* This is a case where some watchpoint(s) triggered, but
2885 not at the address of this watchpoint, or else no
2886 watchpoint triggered after all. So don't print
2887 anything for this watchpoint. */
2888 bs
->print_it
= print_it_noop
;
2895 /* Check conditions (condition proper, frame, thread and ignore count)
2896 of breakpoint referred to by BS. If we should not stop for this
2897 breakpoint, set BS->stop to 0. */
2899 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2901 int thread_id
= pid_to_thread_id (ptid
);
2902 const struct bp_location
*bl
= bs
->breakpoint_at
;
2903 struct breakpoint
*b
= bl
->owner
;
2905 if (frame_id_p (b
->frame_id
)
2906 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2910 int value_is_zero
= 0;
2912 /* If this is a scope breakpoint, mark the associated
2913 watchpoint as triggered so that we will handle the
2914 out-of-scope event. We'll get to the watchpoint next
2916 if (b
->type
== bp_watchpoint_scope
)
2917 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2919 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2921 /* We use value_mark and value_free_to_mark because it could
2922 be a long time before we return to the command level and
2923 call free_all_values. We can't call free_all_values
2924 because we might be in the middle of evaluating a
2926 struct value
*mark
= value_mark ();
2928 /* Need to select the frame, with all that implies
2929 so that the conditions will have the right context. */
2930 select_frame (get_current_frame ());
2932 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2933 "Error in testing breakpoint condition:\n",
2935 /* FIXME-someday, should give breakpoint # */
2936 value_free_to_mark (mark
);
2938 if (bl
->cond
&& value_is_zero
)
2942 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2946 else if (b
->ignore_count
> 0)
2949 annotate_ignore_count_change ();
2951 /* Increase the hit count even though we don't
2959 /* Get a bpstat associated with having just stopped at address
2960 BP_ADDR in thread PTID.
2962 Determine whether we stopped at a breakpoint, etc, or whether we
2963 don't understand this stop. Result is a chain of bpstat's such that:
2965 if we don't understand the stop, the result is a null pointer.
2967 if we understand why we stopped, the result is not null.
2969 Each element of the chain refers to a particular breakpoint or
2970 watchpoint at which we have stopped. (We may have stopped for
2971 several reasons concurrently.)
2973 Each element of the chain has valid next, breakpoint_at,
2974 commands, FIXME??? fields. */
2977 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2979 struct breakpoint
*b
= NULL
;
2980 const struct bp_location
*bl
;
2981 struct bp_location
*loc
;
2982 /* Root of the chain of bpstat's */
2983 struct bpstats root_bs
[1];
2984 /* Pointer to the last thing in the chain currently. */
2985 bpstat bs
= root_bs
;
2987 int need_remove_insert
;
2989 ALL_BP_LOCATIONS (bl
)
2993 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2996 /* For hardware watchpoints, we look only at the first location.
2997 The watchpoint_check function will work on entire expression,
2998 not the individual locations. For read watchopints, the
2999 watchpoints_triggered function have checked all locations
3002 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3005 if (!bpstat_check_location (bl
, bp_addr
))
3008 /* Come here if it's a watchpoint, or if the break address matches */
3010 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3012 /* Assume we stop. Should we find watchpoint that is not actually
3013 triggered, or if condition of breakpoint is false, we'll reset
3018 bpstat_check_watchpoint (bs
);
3022 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3023 /* We do not stop for these. */
3026 bpstat_check_breakpoint_conditions (bs
, ptid
);
3032 /* We will stop here */
3033 if (b
->disposition
== disp_disable
)
3035 if (b
->enable_state
!= bp_permanent
)
3036 b
->enable_state
= bp_disabled
;
3037 update_global_location_list (0);
3041 bs
->commands
= b
->commands
;
3043 (strcmp ("silent", bs
->commands
->line
) == 0
3044 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3046 bs
->commands
= bs
->commands
->next
;
3049 bs
->commands
= copy_command_lines (bs
->commands
);
3052 /* Print nothing for this entry if we dont stop or if we dont print. */
3053 if (bs
->stop
== 0 || bs
->print
== 0)
3054 bs
->print_it
= print_it_noop
;
3057 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3059 if (loc
->address
== bp_addr
)
3061 bs
= bpstat_alloc (loc
, bs
);
3062 /* For hits of moribund locations, we should just proceed. */
3065 bs
->print_it
= print_it_noop
;
3069 bs
->next
= NULL
; /* Terminate the chain */
3070 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3072 /* If we aren't stopping, the value of some hardware watchpoint may
3073 not have changed, but the intermediate memory locations we are
3074 watching may have. Don't bother if we're stopping; this will get
3076 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3080 need_remove_insert
= 0;
3082 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3084 && bs
->breakpoint_at
->owner
3085 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3086 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3087 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3089 /* remove/insert can invalidate bs->breakpoint_at, if this
3090 location is no longer used by the watchpoint. Prevent
3091 further code from trying to use it. */
3092 bs
->breakpoint_at
= NULL
;
3093 need_remove_insert
= 1;
3096 if (need_remove_insert
)
3098 remove_breakpoints ();
3099 insert_breakpoints ();
3102 return root_bs
->next
;
3105 /* Tell what to do about this bpstat. */
3107 bpstat_what (bpstat bs
)
3109 /* Classify each bpstat as one of the following. */
3112 /* This bpstat element has no effect on the main_action. */
3115 /* There was a watchpoint, stop but don't print. */
3118 /* There was a watchpoint, stop and print. */
3121 /* There was a breakpoint but we're not stopping. */
3124 /* There was a breakpoint, stop but don't print. */
3127 /* There was a breakpoint, stop and print. */
3130 /* We hit the longjmp breakpoint. */
3133 /* We hit the longjmp_resume breakpoint. */
3136 /* We hit the step_resume breakpoint. */
3139 /* We hit the shared library event breakpoint. */
3142 /* This is just used to count how many enums there are. */
3146 /* Here is the table which drives this routine. So that we can
3147 format it pretty, we define some abbreviations for the
3148 enum bpstat_what codes. */
3149 #define kc BPSTAT_WHAT_KEEP_CHECKING
3150 #define ss BPSTAT_WHAT_STOP_SILENT
3151 #define sn BPSTAT_WHAT_STOP_NOISY
3152 #define sgl BPSTAT_WHAT_SINGLE
3153 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3154 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3155 #define sr BPSTAT_WHAT_STEP_RESUME
3156 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3158 /* "Can't happen." Might want to print an error message.
3159 abort() is not out of the question, but chances are GDB is just
3160 a bit confused, not unusable. */
3161 #define err BPSTAT_WHAT_STOP_NOISY
3163 /* Given an old action and a class, come up with a new action. */
3164 /* One interesting property of this table is that wp_silent is the same
3165 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3166 after stopping, the check for whether to step over a breakpoint
3167 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3168 reference to how we stopped. We retain separate wp_silent and
3169 bp_silent codes in case we want to change that someday.
3171 Another possibly interesting property of this table is that
3172 there's a partial ordering, priority-like, of the actions. Once
3173 you've decided that some action is appropriate, you'll never go
3174 back and decide something of a lower priority is better. The
3177 kc < clr sgl shl slr sn sr ss
3178 sgl < shl slr sn sr ss
3179 slr < err shl sn sr ss
3180 clr < err shl sn sr ss
3186 What I think this means is that we don't need a damned table
3187 here. If you just put the rows and columns in the right order,
3188 it'd look awfully regular. We could simply walk the bpstat list
3189 and choose the highest priority action we find, with a little
3190 logic to handle the 'err' cases. */
3192 /* step_resume entries: a step resume breakpoint overrides another
3193 breakpoint of signal handling (see comment in wait_for_inferior
3194 at where we set the step_resume breakpoint). */
3196 static const enum bpstat_what_main_action
3197 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3200 /* kc ss sn sgl slr clr sr shl
3203 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3205 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3207 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3209 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3211 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3213 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3215 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3217 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3219 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3221 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3234 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3235 struct bpstat_what retval
;
3237 retval
.call_dummy
= 0;
3238 for (; bs
!= NULL
; bs
= bs
->next
)
3240 enum class bs_class
= no_effect
;
3241 if (bs
->breakpoint_at
== NULL
)
3242 /* I suspect this can happen if it was a momentary breakpoint
3243 which has since been deleted. */
3245 if (bs
->breakpoint_at
->owner
== NULL
)
3246 bs_class
= bp_nostop
;
3248 switch (bs
->breakpoint_at
->owner
->type
)
3254 case bp_hardware_breakpoint
:
3260 bs_class
= bp_noisy
;
3262 bs_class
= bp_silent
;
3265 bs_class
= bp_nostop
;
3268 case bp_hardware_watchpoint
:
3269 case bp_read_watchpoint
:
3270 case bp_access_watchpoint
:
3274 bs_class
= wp_noisy
;
3276 bs_class
= wp_silent
;
3279 /* There was a watchpoint, but we're not stopping.
3280 This requires no further action. */
3281 bs_class
= no_effect
;
3284 bs_class
= long_jump
;
3286 case bp_longjmp_resume
:
3287 bs_class
= long_resume
;
3289 case bp_step_resume
:
3292 bs_class
= step_resume
;
3295 /* It is for the wrong frame. */
3296 bs_class
= bp_nostop
;
3298 case bp_watchpoint_scope
:
3299 bs_class
= bp_nostop
;
3301 case bp_shlib_event
:
3302 bs_class
= shlib_event
;
3304 case bp_thread_event
:
3305 case bp_overlay_event
:
3306 bs_class
= bp_nostop
;
3312 bs_class
= bp_noisy
;
3314 bs_class
= bp_silent
;
3317 /* There was a catchpoint, but we're not stopping.
3318 This requires no further action. */
3319 bs_class
= no_effect
;
3322 /* Make sure the action is stop (silent or noisy),
3323 so infrun.c pops the dummy frame. */
3324 bs_class
= bp_silent
;
3325 retval
.call_dummy
= 1;
3328 current_action
= table
[(int) bs_class
][(int) current_action
];
3330 retval
.main_action
= current_action
;
3334 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3335 without hardware support). This isn't related to a specific bpstat,
3336 just to things like whether watchpoints are set. */
3339 bpstat_should_step (void)
3341 struct breakpoint
*b
;
3343 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3350 static void print_breakpoint_location (struct breakpoint
*b
,
3351 struct bp_location
*loc
,
3353 struct ui_stream
*stb
)
3358 = find_pc_sect_function (loc
->address
, loc
->section
);
3361 ui_out_text (uiout
, "in ");
3362 ui_out_field_string (uiout
, "func",
3363 SYMBOL_PRINT_NAME (sym
));
3364 ui_out_wrap_hint (uiout
, wrap_indent
);
3365 ui_out_text (uiout
, " at ");
3367 ui_out_field_string (uiout
, "file", b
->source_file
);
3368 ui_out_text (uiout
, ":");
3370 if (ui_out_is_mi_like_p (uiout
))
3372 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3373 char *fullname
= symtab_to_fullname (sal
.symtab
);
3376 ui_out_field_string (uiout
, "fullname", fullname
);
3379 ui_out_field_int (uiout
, "line", b
->line_number
);
3383 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3387 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3388 ui_out_field_stream (uiout
, "at", stb
);
3392 /* Print B to gdb_stdout. */
3394 print_one_breakpoint_location (struct breakpoint
*b
,
3395 struct bp_location
*loc
,
3397 CORE_ADDR
*last_addr
)
3399 struct command_line
*l
;
3401 struct ep_type_description
3406 static struct ep_type_description bptypes
[] =
3408 {bp_none
, "?deleted?"},
3409 {bp_breakpoint
, "breakpoint"},
3410 {bp_hardware_breakpoint
, "hw breakpoint"},
3411 {bp_until
, "until"},
3412 {bp_finish
, "finish"},
3413 {bp_watchpoint
, "watchpoint"},
3414 {bp_hardware_watchpoint
, "hw watchpoint"},
3415 {bp_read_watchpoint
, "read watchpoint"},
3416 {bp_access_watchpoint
, "acc watchpoint"},
3417 {bp_longjmp
, "longjmp"},
3418 {bp_longjmp_resume
, "longjmp resume"},
3419 {bp_step_resume
, "step resume"},
3420 {bp_watchpoint_scope
, "watchpoint scope"},
3421 {bp_call_dummy
, "call dummy"},
3422 {bp_shlib_event
, "shlib events"},
3423 {bp_thread_event
, "thread events"},
3424 {bp_overlay_event
, "overlay events"},
3425 {bp_catchpoint
, "catchpoint"},
3428 static char bpenables
[] = "nynny";
3429 char wrap_indent
[80];
3430 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3431 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3432 struct cleanup
*bkpt_chain
;
3434 int header_of_multiple
= 0;
3435 int part_of_multiple
= (loc
!= NULL
);
3436 struct value_print_options opts
;
3438 get_user_print_options (&opts
);
3440 gdb_assert (!loc
|| loc_number
!= 0);
3441 /* See comment in print_one_breakpoint concerning
3442 treatment of breakpoints with single disabled
3446 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3447 header_of_multiple
= 1;
3452 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3456 if (part_of_multiple
)
3459 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3460 ui_out_field_string (uiout
, "number", formatted
);
3465 ui_out_field_int (uiout
, "number", b
->number
);
3470 if (part_of_multiple
)
3471 ui_out_field_skip (uiout
, "type");
3474 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3475 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3476 internal_error (__FILE__
, __LINE__
,
3477 _("bptypes table does not describe type #%d."),
3479 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3484 if (part_of_multiple
)
3485 ui_out_field_skip (uiout
, "disp");
3487 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3492 if (part_of_multiple
)
3493 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3495 ui_out_field_fmt (uiout
, "enabled", "%c",
3496 bpenables
[(int) b
->enable_state
]);
3497 ui_out_spaces (uiout
, 2);
3501 strcpy (wrap_indent
, " ");
3502 if (opts
.addressprint
)
3504 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3505 strcat (wrap_indent
, " ");
3507 strcat (wrap_indent
, " ");
3510 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3512 /* Although the print_one can possibly print
3513 all locations, calling it here is not likely
3514 to get any nice result. So, make sure there's
3515 just one location. */
3516 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3517 b
->ops
->print_one (b
, last_addr
);
3523 internal_error (__FILE__
, __LINE__
,
3524 _("print_one_breakpoint: bp_none encountered\n"));
3528 case bp_hardware_watchpoint
:
3529 case bp_read_watchpoint
:
3530 case bp_access_watchpoint
:
3531 /* Field 4, the address, is omitted (which makes the columns
3532 not line up too nicely with the headers, but the effect
3533 is relatively readable). */
3534 if (opts
.addressprint
)
3535 ui_out_field_skip (uiout
, "addr");
3537 ui_out_field_string (uiout
, "what", b
->exp_string
);
3541 case bp_hardware_breakpoint
:
3545 case bp_longjmp_resume
:
3546 case bp_step_resume
:
3547 case bp_watchpoint_scope
:
3549 case bp_shlib_event
:
3550 case bp_thread_event
:
3551 case bp_overlay_event
:
3552 if (opts
.addressprint
)
3555 if (header_of_multiple
)
3556 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3557 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3558 ui_out_field_string (uiout
, "addr", "<PENDING>");
3560 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3563 if (!header_of_multiple
)
3564 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3566 *last_addr
= b
->loc
->address
;
3570 if (!part_of_multiple
&& b
->thread
!= -1)
3572 /* FIXME: This seems to be redundant and lost here; see the
3573 "stop only in" line a little further down. */
3574 ui_out_text (uiout
, " thread ");
3575 ui_out_field_int (uiout
, "thread", b
->thread
);
3578 ui_out_text (uiout
, "\n");
3580 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3583 ui_out_text (uiout
, "\tstop only in stack frame at ");
3584 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3586 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3587 ui_out_text (uiout
, "\n");
3590 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3592 /* We do not print the condition for Ada exception catchpoints
3593 because the condition is an internal implementation detail
3594 that we do not want to expose to the user. */
3596 ui_out_text (uiout
, "\tstop only if ");
3597 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3598 ui_out_text (uiout
, "\n");
3601 if (!part_of_multiple
&& b
->thread
!= -1)
3603 /* FIXME should make an annotation for this */
3604 ui_out_text (uiout
, "\tstop only in thread ");
3605 ui_out_field_int (uiout
, "thread", b
->thread
);
3606 ui_out_text (uiout
, "\n");
3609 if (!part_of_multiple
&& b
->hit_count
)
3611 /* FIXME should make an annotation for this */
3612 if (ep_is_catchpoint (b
))
3613 ui_out_text (uiout
, "\tcatchpoint");
3615 ui_out_text (uiout
, "\tbreakpoint");
3616 ui_out_text (uiout
, " already hit ");
3617 ui_out_field_int (uiout
, "times", b
->hit_count
);
3618 if (b
->hit_count
== 1)
3619 ui_out_text (uiout
, " time\n");
3621 ui_out_text (uiout
, " times\n");
3624 /* Output the count also if it is zero, but only if this is
3625 mi. FIXME: Should have a better test for this. */
3626 if (ui_out_is_mi_like_p (uiout
))
3627 if (!part_of_multiple
&& b
->hit_count
== 0)
3628 ui_out_field_int (uiout
, "times", b
->hit_count
);
3630 if (!part_of_multiple
&& b
->ignore_count
)
3633 ui_out_text (uiout
, "\tignore next ");
3634 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3635 ui_out_text (uiout
, " hits\n");
3638 if (!part_of_multiple
&& (l
= b
->commands
))
3640 struct cleanup
*script_chain
;
3643 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3644 print_command_lines (uiout
, l
, 4);
3645 do_cleanups (script_chain
);
3648 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3651 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3652 else if (b
->exp_string
)
3653 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3656 do_cleanups (bkpt_chain
);
3657 do_cleanups (old_chain
);
3661 print_one_breakpoint (struct breakpoint
*b
,
3662 CORE_ADDR
*last_addr
)
3664 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3666 /* If this breakpoint has custom print function,
3667 it's already printed. Otherwise, print individual
3668 locations, if any. */
3669 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3671 /* If breakpoint has a single location that is
3672 disabled, we print it as if it had
3673 several locations, since otherwise it's hard to
3674 represent "breakpoint enabled, location disabled"
3676 Note that while hardware watchpoints have
3677 several locations internally, that's no a property
3680 && !is_hardware_watchpoint (b
)
3681 && (b
->loc
->next
|| !b
->loc
->enabled
)
3682 && !ui_out_is_mi_like_p (uiout
))
3684 struct bp_location
*loc
;
3686 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3687 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3693 struct captured_breakpoint_query_args
3699 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3701 struct captured_breakpoint_query_args
*args
= data
;
3702 struct breakpoint
*b
;
3703 CORE_ADDR dummy_addr
= 0;
3706 if (args
->bnum
== b
->number
)
3708 print_one_breakpoint (b
, &dummy_addr
);
3716 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3718 struct captured_breakpoint_query_args args
;
3720 /* For the moment we don't trust print_one_breakpoint() to not throw
3722 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3723 error_message
, RETURN_MASK_ALL
) < 0)
3729 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3730 catchpoints, et.al.). */
3733 user_settable_breakpoint (const struct breakpoint
*b
)
3735 return (b
->type
== bp_breakpoint
3736 || b
->type
== bp_catchpoint
3737 || b
->type
== bp_hardware_breakpoint
3738 || b
->type
== bp_watchpoint
3739 || b
->type
== bp_read_watchpoint
3740 || b
->type
== bp_access_watchpoint
3741 || b
->type
== bp_hardware_watchpoint
);
3744 /* Print information on user settable breakpoint (watchpoint, etc)
3745 number BNUM. If BNUM is -1 print all user settable breakpoints.
3746 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3749 breakpoint_1 (int bnum
, int allflag
)
3751 struct breakpoint
*b
;
3752 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3753 int nr_printable_breakpoints
;
3754 struct cleanup
*bkpttbl_chain
;
3755 struct value_print_options opts
;
3757 get_user_print_options (&opts
);
3759 /* Compute the number of rows in the table. */
3760 nr_printable_breakpoints
= 0;
3763 || bnum
== b
->number
)
3765 if (allflag
|| user_settable_breakpoint (b
))
3766 nr_printable_breakpoints
++;
3769 if (opts
.addressprint
)
3771 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3775 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3778 if (nr_printable_breakpoints
> 0)
3779 annotate_breakpoints_headers ();
3780 if (nr_printable_breakpoints
> 0)
3782 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3783 if (nr_printable_breakpoints
> 0)
3785 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3786 if (nr_printable_breakpoints
> 0)
3788 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3789 if (nr_printable_breakpoints
> 0)
3791 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3792 if (opts
.addressprint
)
3794 if (nr_printable_breakpoints
> 0)
3796 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3797 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3799 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3801 if (nr_printable_breakpoints
> 0)
3803 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3804 ui_out_table_body (uiout
);
3805 if (nr_printable_breakpoints
> 0)
3806 annotate_breakpoints_table ();
3810 || bnum
== b
->number
)
3812 /* We only print out user settable breakpoints unless the
3814 if (allflag
|| user_settable_breakpoint (b
))
3815 print_one_breakpoint (b
, &last_addr
);
3818 do_cleanups (bkpttbl_chain
);
3820 if (nr_printable_breakpoints
== 0)
3823 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3825 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3830 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3831 that a comparison of an unsigned with -1 is always false. */
3832 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3833 set_next_address (current_gdbarch
, last_addr
);
3836 /* FIXME? Should this be moved up so that it is only called when
3837 there have been breakpoints? */
3838 annotate_breakpoints_table_end ();
3842 breakpoints_info (char *bnum_exp
, int from_tty
)
3847 bnum
= parse_and_eval_long (bnum_exp
);
3849 breakpoint_1 (bnum
, 0);
3853 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3858 bnum
= parse_and_eval_long (bnum_exp
);
3860 breakpoint_1 (bnum
, 1);
3864 breakpoint_has_pc (struct breakpoint
*b
,
3865 CORE_ADDR pc
, struct obj_section
*section
)
3867 struct bp_location
*bl
= b
->loc
;
3868 for (; bl
; bl
= bl
->next
)
3870 if (bl
->address
== pc
3871 && (!overlay_debugging
|| bl
->section
== section
))
3877 /* Print a message describing any breakpoints set at PC. */
3880 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3884 struct breakpoint
*b
;
3887 others
+= breakpoint_has_pc (b
, pc
, section
);
3891 printf_filtered (_("Note: breakpoint "));
3892 else /* if (others == ???) */
3893 printf_filtered (_("Note: breakpoints "));
3895 if (breakpoint_has_pc (b
, pc
, section
))
3898 printf_filtered ("%d", b
->number
);
3899 if (b
->thread
== -1 && thread
!= -1)
3900 printf_filtered (" (all threads)");
3901 else if (b
->thread
!= -1)
3902 printf_filtered (" (thread %d)", b
->thread
);
3903 printf_filtered ("%s%s ",
3904 ((b
->enable_state
== bp_disabled
||
3905 b
->enable_state
== bp_call_disabled
)
3907 : b
->enable_state
== bp_permanent
3911 : ((others
== 1) ? " and" : ""));
3913 printf_filtered (_("also set at pc "));
3914 fputs_filtered (paddress (pc
), gdb_stdout
);
3915 printf_filtered (".\n");
3919 /* Set the default place to put a breakpoint
3920 for the `break' command with no arguments. */
3923 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3926 default_breakpoint_valid
= valid
;
3927 default_breakpoint_address
= addr
;
3928 default_breakpoint_symtab
= symtab
;
3929 default_breakpoint_line
= line
;
3932 /* Return true iff it is meaningful to use the address member of
3933 BPT. For some breakpoint types, the address member is irrelevant
3934 and it makes no sense to attempt to compare it to other addresses
3935 (or use it for any other purpose either).
3937 More specifically, each of the following breakpoint types will always
3938 have a zero valued address and we don't want check_duplicates() to mark
3939 breakpoints of any of these types to be a duplicate of an actual
3940 breakpoint at address zero:
3943 bp_hardware_watchpoint
3945 bp_access_watchpoint
3949 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3951 enum bptype type
= bpt
->type
;
3953 return (type
!= bp_watchpoint
3954 && type
!= bp_hardware_watchpoint
3955 && type
!= bp_read_watchpoint
3956 && type
!= bp_access_watchpoint
3957 && type
!= bp_catchpoint
);
3960 /* Rescan breakpoints at the same address and section as BPT,
3961 marking the first one as "first" and any others as "duplicates".
3962 This is so that the bpt instruction is only inserted once.
3963 If we have a permanent breakpoint at the same place as BPT, make
3964 that one the official one, and the rest as duplicates. */
3967 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
3969 struct bp_location
*b
;
3971 struct bp_location
*perm_bp
= 0;
3973 ALL_BP_LOCATIONS (b
)
3974 if (b
->owner
->enable_state
!= bp_disabled
3975 && b
->owner
->enable_state
!= bp_call_disabled
3977 && !b
->shlib_disabled
3978 && b
->address
== address
/* address / overlay match */
3979 && (!overlay_debugging
|| b
->section
== section
)
3980 && breakpoint_address_is_meaningful (b
->owner
))
3982 /* Have we found a permanent breakpoint? */
3983 if (b
->owner
->enable_state
== bp_permanent
)
3990 b
->duplicate
= count
> 1;
3993 /* If we found a permanent breakpoint at this address, go over the
3994 list again and declare all the other breakpoints there (except
3995 other permanent breakpoints) to be the duplicates. */
3998 perm_bp
->duplicate
= 0;
4000 /* Permanent breakpoint should always be inserted. */
4001 if (! perm_bp
->inserted
)
4002 internal_error (__FILE__
, __LINE__
,
4003 _("allegedly permanent breakpoint is not "
4004 "actually inserted"));
4006 ALL_BP_LOCATIONS (b
)
4009 if (b
->owner
->enable_state
!= bp_permanent
4010 && b
->owner
->enable_state
!= bp_disabled
4011 && b
->owner
->enable_state
!= bp_call_disabled
4012 && b
->enabled
&& !b
->shlib_disabled
4013 && b
->address
== address
/* address / overlay match */
4014 && (!overlay_debugging
|| b
->section
== section
)
4015 && breakpoint_address_is_meaningful (b
->owner
))
4018 internal_error (__FILE__
, __LINE__
,
4019 _("another breakpoint was inserted on top of "
4020 "a permanent breakpoint"));
4029 check_duplicates (struct breakpoint
*bpt
)
4031 struct bp_location
*bl
= bpt
->loc
;
4033 if (! breakpoint_address_is_meaningful (bpt
))
4036 for (; bl
; bl
= bl
->next
)
4037 check_duplicates_for (bl
->address
, bl
->section
);
4041 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4042 int bnum
, int have_bnum
)
4047 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4048 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4050 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4051 bnum
, astr1
, astr2
);
4053 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4056 /* Adjust a breakpoint's address to account for architectural constraints
4057 on breakpoint placement. Return the adjusted address. Note: Very
4058 few targets require this kind of adjustment. For most targets,
4059 this function is simply the identity function. */
4062 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4064 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4066 /* Very few targets need any kind of breakpoint adjustment. */
4069 else if (bptype
== bp_watchpoint
4070 || bptype
== bp_hardware_watchpoint
4071 || bptype
== bp_read_watchpoint
4072 || bptype
== bp_access_watchpoint
4073 || bptype
== bp_catchpoint
)
4075 /* Watchpoints and the various bp_catch_* eventpoints should not
4076 have their addresses modified. */
4081 CORE_ADDR adjusted_bpaddr
;
4083 /* Some targets have architectural constraints on the placement
4084 of breakpoint instructions. Obtain the adjusted address. */
4085 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4088 /* An adjusted breakpoint address can significantly alter
4089 a user's expectations. Print a warning if an adjustment
4091 if (adjusted_bpaddr
!= bpaddr
)
4092 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4094 return adjusted_bpaddr
;
4098 /* Allocate a struct bp_location. */
4100 static struct bp_location
*
4101 allocate_bp_location (struct breakpoint
*bpt
)
4103 struct bp_location
*loc
, *loc_p
;
4105 loc
= xmalloc (sizeof (struct bp_location
));
4106 memset (loc
, 0, sizeof (*loc
));
4110 loc
->shlib_disabled
= 0;
4119 case bp_longjmp_resume
:
4120 case bp_step_resume
:
4121 case bp_watchpoint_scope
:
4123 case bp_shlib_event
:
4124 case bp_thread_event
:
4125 case bp_overlay_event
:
4126 loc
->loc_type
= bp_loc_software_breakpoint
;
4128 case bp_hardware_breakpoint
:
4129 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4131 case bp_hardware_watchpoint
:
4132 case bp_read_watchpoint
:
4133 case bp_access_watchpoint
:
4134 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4138 loc
->loc_type
= bp_loc_other
;
4141 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4147 static void free_bp_location (struct bp_location
*loc
)
4152 if (loc
->function_name
)
4153 xfree (loc
->function_name
);
4158 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4159 that has type BPTYPE and has no locations as yet. */
4161 static struct breakpoint
*
4162 set_raw_breakpoint_without_location (enum bptype bptype
)
4164 struct breakpoint
*b
, *b1
;
4166 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4167 memset (b
, 0, sizeof (*b
));
4170 b
->language
= current_language
->la_language
;
4171 b
->input_radix
= input_radix
;
4173 b
->enable_state
= bp_enabled
;
4176 b
->ignore_count
= 0;
4178 b
->frame_id
= null_frame_id
;
4179 b
->forked_inferior_pid
= null_ptid
;
4180 b
->exec_pathname
= NULL
;
4182 b
->condition_not_parsed
= 0;
4184 /* Add this breakpoint to the end of the chain
4185 so that a list of breakpoints will come out in order
4186 of increasing numbers. */
4188 b1
= breakpoint_chain
;
4190 breakpoint_chain
= b
;
4200 /* Initialize loc->function_name. */
4202 set_breakpoint_location_function (struct bp_location
*loc
)
4204 if (loc
->owner
->type
== bp_breakpoint
4205 || loc
->owner
->type
== bp_hardware_breakpoint
)
4207 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4209 if (loc
->function_name
)
4210 loc
->function_name
= xstrdup (loc
->function_name
);
4214 /* set_raw_breakpoint is a low level routine for allocating and
4215 partially initializing a breakpoint of type BPTYPE. The newly
4216 created breakpoint's address, section, source file name, and line
4217 number are provided by SAL. The newly created and partially
4218 initialized breakpoint is added to the breakpoint chain and
4219 is also returned as the value of this function.
4221 It is expected that the caller will complete the initialization of
4222 the newly created breakpoint struct as well as output any status
4223 information regarding the creation of a new breakpoint. In
4224 particular, set_raw_breakpoint does NOT set the breakpoint
4225 number! Care should be taken to not allow an error to occur
4226 prior to completing the initialization of the breakpoint. If this
4227 should happen, a bogus breakpoint will be left on the chain. */
4230 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4232 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4233 CORE_ADDR adjusted_address
;
4235 /* Adjust the breakpoint's address prior to allocating a location.
4236 Once we call allocate_bp_location(), that mostly uninitialized
4237 location will be placed on the location chain. Adjustment of the
4238 breakpoint may cause target_read_memory() to be called and we do
4239 not want its scan of the location chain to find a breakpoint and
4240 location that's only been partially initialized. */
4241 adjusted_address
= adjust_breakpoint_address (sal
.pc
, b
->type
);
4243 b
->loc
= allocate_bp_location (b
);
4244 b
->loc
->requested_address
= sal
.pc
;
4245 b
->loc
->address
= adjusted_address
;
4247 if (sal
.symtab
== NULL
)
4248 b
->source_file
= NULL
;
4250 b
->source_file
= savestring (sal
.symtab
->filename
,
4251 strlen (sal
.symtab
->filename
));
4252 b
->loc
->section
= sal
.section
;
4253 b
->line_number
= sal
.line
;
4255 set_breakpoint_location_function (b
->loc
);
4257 breakpoints_changed ();
4263 /* Note that the breakpoint object B describes a permanent breakpoint
4264 instruction, hard-wired into the inferior's code. */
4266 make_breakpoint_permanent (struct breakpoint
*b
)
4268 struct bp_location
*bl
;
4269 b
->enable_state
= bp_permanent
;
4271 /* By definition, permanent breakpoints are already present in the code.
4272 Mark all locations as inserted. For now, make_breakpoint_permanent
4273 is called in just one place, so it's hard to say if it's reasonable
4274 to have permanent breakpoint with multiple locations or not,
4275 but it's easy to implmement. */
4276 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4280 static struct breakpoint
*
4281 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4283 static int internal_breakpoint_number
= -1;
4284 struct symtab_and_line sal
;
4285 struct breakpoint
*b
;
4287 init_sal (&sal
); /* initialize to zeroes */
4290 sal
.section
= find_pc_overlay (sal
.pc
);
4292 b
= set_raw_breakpoint (sal
, type
);
4293 b
->number
= internal_breakpoint_number
--;
4294 b
->disposition
= disp_donttouch
;
4301 create_longjmp_breakpoint (char *func_name
)
4303 struct minimal_symbol
*m
;
4305 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4307 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4308 update_global_location_list (1);
4311 /* Call this routine when stepping and nexting to enable a breakpoint
4312 if we do a longjmp(). When we hit that breakpoint, call
4313 set_longjmp_resume_breakpoint() to figure out where we are going. */
4316 set_longjmp_breakpoint (void)
4318 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4320 create_longjmp_breakpoint ("longjmp");
4321 create_longjmp_breakpoint ("_longjmp");
4322 create_longjmp_breakpoint ("siglongjmp");
4323 create_longjmp_breakpoint ("_siglongjmp");
4327 /* Delete all longjmp breakpoints from THREAD. */
4329 delete_longjmp_breakpoint (int thread
)
4331 struct breakpoint
*b
, *temp
;
4333 ALL_BREAKPOINTS_SAFE (b
, temp
)
4334 if (b
->type
== bp_longjmp
)
4336 if (b
->thread
== thread
)
4337 delete_breakpoint (b
);
4342 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4344 struct breakpoint
*b
;
4345 struct minimal_symbol
*m
;
4347 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4350 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4352 b
->addr_string
= xstrdup (func_name
);
4354 if (overlay_debugging
== ovly_auto
)
4356 b
->enable_state
= bp_enabled
;
4357 overlay_events_enabled
= 1;
4361 b
->enable_state
= bp_disabled
;
4362 overlay_events_enabled
= 0;
4364 update_global_location_list (1);
4368 create_overlay_event_breakpoint (char *func_name
)
4370 struct objfile
*objfile
;
4371 ALL_OBJFILES (objfile
)
4372 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4376 enable_overlay_breakpoints (void)
4378 struct breakpoint
*b
;
4381 if (b
->type
== bp_overlay_event
)
4383 b
->enable_state
= bp_enabled
;
4384 update_global_location_list (1);
4385 overlay_events_enabled
= 1;
4390 disable_overlay_breakpoints (void)
4392 struct breakpoint
*b
;
4395 if (b
->type
== bp_overlay_event
)
4397 b
->enable_state
= bp_disabled
;
4398 update_global_location_list (0);
4399 overlay_events_enabled
= 0;
4404 create_thread_event_breakpoint (CORE_ADDR address
)
4406 struct breakpoint
*b
;
4408 b
= create_internal_breakpoint (address
, bp_thread_event
);
4410 b
->enable_state
= bp_enabled
;
4411 /* addr_string has to be used or breakpoint_re_set will delete me. */
4412 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4414 update_global_location_list_nothrow (1);
4420 remove_thread_event_breakpoints (void)
4422 struct breakpoint
*b
, *temp
;
4424 ALL_BREAKPOINTS_SAFE (b
, temp
)
4425 if (b
->type
== bp_thread_event
)
4426 delete_breakpoint (b
);
4429 struct captured_parse_breakpoint_args
4432 struct symtabs_and_lines
*sals_p
;
4433 char ***addr_string_p
;
4437 struct lang_and_radix
4445 remove_solib_event_breakpoints (void)
4447 struct breakpoint
*b
, *temp
;
4449 ALL_BREAKPOINTS_SAFE (b
, temp
)
4450 if (b
->type
== bp_shlib_event
)
4451 delete_breakpoint (b
);
4455 create_solib_event_breakpoint (CORE_ADDR address
)
4457 struct breakpoint
*b
;
4459 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4460 update_global_location_list_nothrow (1);
4464 /* Disable any breakpoints that are on code in shared libraries. Only
4465 apply to enabled breakpoints, disabled ones can just stay disabled. */
4468 disable_breakpoints_in_shlibs (void)
4470 struct bp_location
*loc
;
4472 ALL_BP_LOCATIONS (loc
)
4474 struct breakpoint
*b
= loc
->owner
;
4475 /* We apply the check to all breakpoints, including disabled
4476 for those with loc->duplicate set. This is so that when breakpoint
4477 becomes enabled, or the duplicate is removed, gdb will try to insert
4478 all breakpoints. If we don't set shlib_disabled here, we'll try
4479 to insert those breakpoints and fail. */
4480 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4481 && !loc
->shlib_disabled
4483 && PC_SOLIB (loc
->address
)
4485 && solib_name_from_address (loc
->address
)
4489 loc
->shlib_disabled
= 1;
4494 /* Disable any breakpoints that are in in an unloaded shared library. Only
4495 apply to enabled breakpoints, disabled ones can just stay disabled. */
4498 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4500 struct bp_location
*loc
;
4501 int disabled_shlib_breaks
= 0;
4503 /* SunOS a.out shared libraries are always mapped, so do not
4504 disable breakpoints; they will only be reported as unloaded
4505 through clear_solib when GDB discards its shared library
4506 list. See clear_solib for more information. */
4507 if (exec_bfd
!= NULL
4508 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4511 ALL_BP_LOCATIONS (loc
)
4513 struct breakpoint
*b
= loc
->owner
;
4514 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4515 || loc
->loc_type
== bp_loc_software_breakpoint
)
4516 && !loc
->shlib_disabled
4517 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4518 && solib_contains_address_p (solib
, loc
->address
))
4520 loc
->shlib_disabled
= 1;
4521 /* At this point, we cannot rely on remove_breakpoint
4522 succeeding so we must mark the breakpoint as not inserted
4523 to prevent future errors occurring in remove_breakpoints. */
4525 if (!disabled_shlib_breaks
)
4527 target_terminal_ours_for_output ();
4528 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4531 disabled_shlib_breaks
= 1;
4536 /* FORK & VFORK catchpoints. */
4538 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4541 insert_catch_fork (struct breakpoint
*b
)
4543 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4546 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4549 remove_catch_fork (struct breakpoint
*b
)
4551 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4554 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4558 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4560 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4563 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4565 static enum print_stop_action
4566 print_it_catch_fork (struct breakpoint
*b
)
4568 annotate_catchpoint (b
->number
);
4569 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4570 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4571 return PRINT_SRC_AND_LOC
;
4574 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4577 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4579 struct value_print_options opts
;
4581 get_user_print_options (&opts
);
4583 /* Field 4, the address, is omitted (which makes the columns
4584 not line up too nicely with the headers, but the effect
4585 is relatively readable). */
4586 if (opts
.addressprint
)
4587 ui_out_field_skip (uiout
, "addr");
4589 ui_out_text (uiout
, "fork");
4590 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4592 ui_out_text (uiout
, ", process ");
4593 ui_out_field_int (uiout
, "what",
4594 ptid_get_pid (b
->forked_inferior_pid
));
4595 ui_out_spaces (uiout
, 1);
4599 /* Implement the "print_mention" breakpoint_ops method for fork
4603 print_mention_catch_fork (struct breakpoint
*b
)
4605 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4608 /* The breakpoint_ops structure to be used in fork catchpoints. */
4610 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4614 breakpoint_hit_catch_fork
,
4615 print_it_catch_fork
,
4616 print_one_catch_fork
,
4617 print_mention_catch_fork
4620 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4623 insert_catch_vfork (struct breakpoint
*b
)
4625 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4628 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4631 remove_catch_vfork (struct breakpoint
*b
)
4633 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4636 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4640 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4642 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4645 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4647 static enum print_stop_action
4648 print_it_catch_vfork (struct breakpoint
*b
)
4650 annotate_catchpoint (b
->number
);
4651 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4652 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4653 return PRINT_SRC_AND_LOC
;
4656 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4659 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4661 struct value_print_options opts
;
4663 get_user_print_options (&opts
);
4664 /* Field 4, the address, is omitted (which makes the columns
4665 not line up too nicely with the headers, but the effect
4666 is relatively readable). */
4667 if (opts
.addressprint
)
4668 ui_out_field_skip (uiout
, "addr");
4670 ui_out_text (uiout
, "vfork");
4671 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4673 ui_out_text (uiout
, ", process ");
4674 ui_out_field_int (uiout
, "what",
4675 ptid_get_pid (b
->forked_inferior_pid
));
4676 ui_out_spaces (uiout
, 1);
4680 /* Implement the "print_mention" breakpoint_ops method for vfork
4684 print_mention_catch_vfork (struct breakpoint
*b
)
4686 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4689 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4691 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4695 breakpoint_hit_catch_vfork
,
4696 print_it_catch_vfork
,
4697 print_one_catch_vfork
,
4698 print_mention_catch_vfork
4701 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4703 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4704 If COND_STRING is not NULL, then store it in the breakpoint.
4705 OPS, if not NULL, is the breakpoint_ops structure associated
4706 to the catchpoint. */
4708 static struct breakpoint
*
4709 create_catchpoint (int tempflag
, char *cond_string
,
4710 struct breakpoint_ops
*ops
)
4712 struct symtab_and_line sal
;
4713 struct breakpoint
*b
;
4720 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4721 set_breakpoint_count (breakpoint_count
+ 1);
4722 b
->number
= breakpoint_count
;
4724 b
->cond_string
= (cond_string
== NULL
) ?
4725 NULL
: savestring (cond_string
, strlen (cond_string
));
4727 b
->addr_string
= NULL
;
4728 b
->enable_state
= bp_enabled
;
4729 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4733 update_global_location_list (1);
4739 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4740 struct breakpoint_ops
*ops
)
4742 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4744 /* FIXME: We should put this information in a breakpoint private data
4746 b
->forked_inferior_pid
= null_ptid
;
4749 /* Exec catchpoints. */
4752 insert_catch_exec (struct breakpoint
*b
)
4754 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4758 remove_catch_exec (struct breakpoint
*b
)
4760 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4764 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4766 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4769 static enum print_stop_action
4770 print_it_catch_exec (struct breakpoint
*b
)
4772 annotate_catchpoint (b
->number
);
4773 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4775 return PRINT_SRC_AND_LOC
;
4779 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4781 struct value_print_options opts
;
4783 get_user_print_options (&opts
);
4785 /* Field 4, the address, is omitted (which makes the columns
4786 not line up too nicely with the headers, but the effect
4787 is relatively readable). */
4788 if (opts
.addressprint
)
4789 ui_out_field_skip (uiout
, "addr");
4791 ui_out_text (uiout
, "exec");
4792 if (b
->exec_pathname
!= NULL
)
4794 ui_out_text (uiout
, ", program \"");
4795 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4796 ui_out_text (uiout
, "\" ");
4801 print_mention_catch_exec (struct breakpoint
*b
)
4803 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4806 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4810 breakpoint_hit_catch_exec
,
4811 print_it_catch_exec
,
4812 print_one_catch_exec
,
4813 print_mention_catch_exec
4817 hw_breakpoint_used_count (void)
4819 struct breakpoint
*b
;
4824 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4832 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4834 struct breakpoint
*b
;
4837 *other_type_used
= 0;
4840 if (breakpoint_enabled (b
))
4842 if (b
->type
== type
)
4844 else if ((b
->type
== bp_hardware_watchpoint
||
4845 b
->type
== bp_read_watchpoint
||
4846 b
->type
== bp_access_watchpoint
))
4847 *other_type_used
= 1;
4854 disable_watchpoints_before_interactive_call_start (void)
4856 struct breakpoint
*b
;
4860 if (((b
->type
== bp_watchpoint
)
4861 || (b
->type
== bp_hardware_watchpoint
)
4862 || (b
->type
== bp_read_watchpoint
)
4863 || (b
->type
== bp_access_watchpoint
))
4864 && breakpoint_enabled (b
))
4866 b
->enable_state
= bp_call_disabled
;
4867 update_global_location_list (0);
4873 enable_watchpoints_after_interactive_call_stop (void)
4875 struct breakpoint
*b
;
4879 if (((b
->type
== bp_watchpoint
)
4880 || (b
->type
== bp_hardware_watchpoint
)
4881 || (b
->type
== bp_read_watchpoint
)
4882 || (b
->type
== bp_access_watchpoint
))
4883 && (b
->enable_state
== bp_call_disabled
))
4885 b
->enable_state
= bp_enabled
;
4886 update_global_location_list (1);
4892 /* Set a breakpoint that will evaporate an end of command
4893 at address specified by SAL.
4894 Restrict it to frame FRAME if FRAME is nonzero. */
4897 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4900 struct breakpoint
*b
;
4901 b
= set_raw_breakpoint (sal
, type
);
4902 b
->enable_state
= bp_enabled
;
4903 b
->disposition
= disp_donttouch
;
4904 b
->frame_id
= frame_id
;
4906 /* If we're debugging a multi-threaded program, then we
4907 want momentary breakpoints to be active in only a
4908 single thread of control. */
4909 if (in_thread_list (inferior_ptid
))
4910 b
->thread
= pid_to_thread_id (inferior_ptid
);
4912 update_global_location_list_nothrow (1);
4918 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4920 struct symtab_and_line sal
;
4922 sal
= find_pc_line (pc
, 0);
4924 sal
.section
= find_pc_overlay (pc
);
4925 sal
.explicit_pc
= 1;
4927 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4931 /* Tell the user we have just set a breakpoint B. */
4934 mention (struct breakpoint
*b
)
4937 struct cleanup
*ui_out_chain
;
4938 struct value_print_options opts
;
4940 get_user_print_options (&opts
);
4942 /* FIXME: This is misplaced; mention() is called by things (like
4943 hitting a watchpoint) other than breakpoint creation. It should
4944 be possible to clean this up and at the same time replace the
4945 random calls to breakpoint_changed with this hook. */
4946 observer_notify_breakpoint_created (b
->number
);
4948 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4949 b
->ops
->print_mention (b
);
4954 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4957 ui_out_text (uiout
, "Watchpoint ");
4958 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4959 ui_out_field_int (uiout
, "number", b
->number
);
4960 ui_out_text (uiout
, ": ");
4961 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4962 do_cleanups (ui_out_chain
);
4964 case bp_hardware_watchpoint
:
4965 ui_out_text (uiout
, "Hardware watchpoint ");
4966 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4967 ui_out_field_int (uiout
, "number", b
->number
);
4968 ui_out_text (uiout
, ": ");
4969 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4970 do_cleanups (ui_out_chain
);
4972 case bp_read_watchpoint
:
4973 ui_out_text (uiout
, "Hardware read watchpoint ");
4974 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4975 ui_out_field_int (uiout
, "number", b
->number
);
4976 ui_out_text (uiout
, ": ");
4977 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4978 do_cleanups (ui_out_chain
);
4980 case bp_access_watchpoint
:
4981 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4982 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4983 ui_out_field_int (uiout
, "number", b
->number
);
4984 ui_out_text (uiout
, ": ");
4985 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4986 do_cleanups (ui_out_chain
);
4989 if (ui_out_is_mi_like_p (uiout
))
4994 if (b
->disposition
== disp_del
)
4995 printf_filtered (_("Temporary breakpoint"));
4997 printf_filtered (_("Breakpoint"));
4998 printf_filtered (_(" %d"), b
->number
);
5001 case bp_hardware_breakpoint
:
5002 if (ui_out_is_mi_like_p (uiout
))
5007 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5014 case bp_longjmp_resume
:
5015 case bp_step_resume
:
5017 case bp_watchpoint_scope
:
5018 case bp_shlib_event
:
5019 case bp_thread_event
:
5020 case bp_overlay_event
:
5026 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5030 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5034 if (opts
.addressprint
|| b
->source_file
== NULL
)
5036 printf_filtered (" at ");
5037 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5040 printf_filtered (": file %s, line %d.",
5041 b
->source_file
, b
->line_number
);
5045 struct bp_location
*loc
= b
->loc
;
5047 for (; loc
; loc
= loc
->next
)
5049 printf_filtered (" (%d locations)", n
);
5054 if (ui_out_is_mi_like_p (uiout
))
5056 printf_filtered ("\n");
5060 static struct bp_location
*
5061 add_location_to_breakpoint (struct breakpoint
*b
,
5062 const struct symtab_and_line
*sal
)
5064 struct bp_location
*loc
, **tmp
;
5066 loc
= allocate_bp_location (b
);
5067 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5070 loc
->requested_address
= sal
->pc
;
5071 loc
->address
= adjust_breakpoint_address (loc
->requested_address
, b
->type
);
5072 loc
->section
= sal
->section
;
5074 set_breakpoint_location_function (loc
);
5079 /* Return 1 if LOC is pointing to a permanent breakpoint,
5080 return 0 otherwise. */
5083 bp_loc_is_permanent (struct bp_location
*loc
)
5087 const gdb_byte
*brk
;
5088 gdb_byte
*target_mem
;
5089 struct cleanup
*cleanup
;
5092 gdb_assert (loc
!= NULL
);
5094 addr
= loc
->address
;
5095 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5097 /* Software breakpoints unsupported? */
5101 target_mem
= alloca (len
);
5103 /* Enable the automatic memory restoration from breakpoints while
5104 we read the memory. Otherwise we could say about our temporary
5105 breakpoints they are permanent. */
5106 cleanup
= make_show_memory_breakpoints_cleanup (0);
5108 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5109 && memcmp (target_mem
, brk
, len
) == 0)
5112 do_cleanups (cleanup
);
5119 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5120 as textual description of the location, and COND_STRING
5121 as condition expression. */
5124 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5126 enum bptype type
, enum bpdisp disposition
,
5127 int thread
, int ignore_count
,
5128 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5130 struct breakpoint
*b
= NULL
;
5133 if (type
== bp_hardware_breakpoint
)
5135 int i
= hw_breakpoint_used_count ();
5136 int target_resources_ok
=
5137 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5139 if (target_resources_ok
== 0)
5140 error (_("No hardware breakpoint support in the target."));
5141 else if (target_resources_ok
< 0)
5142 error (_("Hardware breakpoints used exceeds limit."));
5145 for (i
= 0; i
< sals
.nelts
; ++i
)
5147 struct symtab_and_line sal
= sals
.sals
[i
];
5148 struct bp_location
*loc
;
5151 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5155 b
= set_raw_breakpoint (sal
, type
);
5156 set_breakpoint_count (breakpoint_count
+ 1);
5157 b
->number
= breakpoint_count
;
5160 b
->cond_string
= cond_string
;
5161 b
->ignore_count
= ignore_count
;
5162 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5163 b
->disposition
= disposition
;
5169 loc
= add_location_to_breakpoint (b
, &sal
);
5172 if (bp_loc_is_permanent (loc
))
5173 make_breakpoint_permanent (b
);
5177 char *arg
= b
->cond_string
;
5178 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5180 error (_("Garbage %s follows condition"), arg
);
5185 b
->addr_string
= addr_string
;
5187 /* addr_string has to be used or breakpoint_re_set will delete
5189 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5195 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5196 elements to fill the void space. */
5198 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5200 int i
= index_to_remove
+1;
5201 int last_index
= sal
->nelts
-1;
5203 for (;i
<= last_index
; ++i
)
5204 sal
->sals
[i
-1] = sal
->sals
[i
];
5209 /* If appropriate, obtains all sals that correspond
5210 to the same file and line as SAL. This is done
5211 only if SAL does not have explicit PC and has
5212 line and file information. If we got just a single
5213 expanded sal, return the original.
5215 Otherwise, if SAL.explicit_line is not set, filter out
5216 all sals for which the name of enclosing function
5217 is different from SAL. This makes sure that if we have
5218 breakpoint originally set in template instantiation, say
5219 foo<int>(), we won't expand SAL to locations at the same
5220 line in all existing instantiations of 'foo'.
5223 static struct symtabs_and_lines
5224 expand_line_sal_maybe (struct symtab_and_line sal
)
5226 struct symtabs_and_lines expanded
;
5227 CORE_ADDR original_pc
= sal
.pc
;
5228 char *original_function
= NULL
;
5232 /* If we have explicit pc, don't expand.
5233 If we have no line number, we can't expand. */
5234 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5237 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5238 expanded
.sals
[0] = sal
;
5243 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5245 expanded
= expand_line_sal (sal
);
5246 if (expanded
.nelts
== 1)
5248 /* We had one sal, we got one sal. Without futher
5249 processing, just return the original sal. */
5250 xfree (expanded
.sals
);
5252 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5253 sal
.pc
= original_pc
;
5254 expanded
.sals
[0] = sal
;
5258 if (!sal
.explicit_line
)
5260 CORE_ADDR func_addr
, func_end
;
5261 for (i
= 0; i
< expanded
.nelts
; ++i
)
5263 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5264 char *this_function
;
5265 if (find_pc_partial_function (pc
, &this_function
,
5266 &func_addr
, &func_end
))
5268 if (this_function
&&
5269 strcmp (this_function
, original_function
) != 0)
5271 remove_sal (&expanded
, i
);
5274 else if (func_addr
== pc
)
5276 /* We're at beginning of a function, and should
5278 struct symbol
*sym
= find_pc_function (pc
);
5280 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5283 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5290 if (expanded
.nelts
<= 1)
5292 /* This is un ugly workaround. If we get zero
5293 expanded sals then something is really wrong.
5294 Fix that by returnign the original sal. */
5295 xfree (expanded
.sals
);
5297 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5298 sal
.pc
= original_pc
;
5299 expanded
.sals
[0] = sal
;
5306 for (i
= 0; i
< expanded
.nelts
; ++i
)
5307 if (expanded
.sals
[i
].pc
== original_pc
)
5318 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5319 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5320 value. COND_STRING, if not NULL, specified the condition to be
5321 used for all breakpoints. Essentially the only case where
5322 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5323 function. In that case, it's still not possible to specify
5324 separate conditions for different overloaded functions, so
5325 we take just a single condition string.
5327 NOTE: If the function succeeds, the caller is expected to cleanup
5328 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5329 array contents). If the function fails (error() is called), the
5330 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5331 COND and SALS arrays and each of those arrays contents. */
5334 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5336 enum bptype type
, enum bpdisp disposition
,
5337 int thread
, int ignore_count
,
5338 struct breakpoint_ops
*ops
, int from_tty
,
5342 for (i
= 0; i
< sals
.nelts
; ++i
)
5344 struct symtabs_and_lines expanded
=
5345 expand_line_sal_maybe (sals
.sals
[i
]);
5347 create_breakpoint (expanded
, addr_string
[i
],
5348 cond_string
, type
, disposition
,
5349 thread
, ignore_count
, ops
, from_tty
, enabled
);
5352 update_global_location_list (1);
5355 /* Parse ARG which is assumed to be a SAL specification possibly
5356 followed by conditionals. On return, SALS contains an array of SAL
5357 addresses found. ADDR_STRING contains a vector of (canonical)
5358 address strings. ARG points to the end of the SAL. */
5361 parse_breakpoint_sals (char **address
,
5362 struct symtabs_and_lines
*sals
,
5363 char ***addr_string
,
5366 char *addr_start
= *address
;
5367 *addr_string
= NULL
;
5368 /* If no arg given, or if first arg is 'if ', use the default
5370 if ((*address
) == NULL
5371 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5373 if (default_breakpoint_valid
)
5375 struct symtab_and_line sal
;
5376 init_sal (&sal
); /* initialize to zeroes */
5377 sals
->sals
= (struct symtab_and_line
*)
5378 xmalloc (sizeof (struct symtab_and_line
));
5379 sal
.pc
= default_breakpoint_address
;
5380 sal
.line
= default_breakpoint_line
;
5381 sal
.symtab
= default_breakpoint_symtab
;
5382 sal
.section
= find_pc_overlay (sal
.pc
);
5383 sals
->sals
[0] = sal
;
5387 error (_("No default breakpoint address now."));
5391 /* Force almost all breakpoints to be in terms of the
5392 current_source_symtab (which is decode_line_1's default). This
5393 should produce the results we want almost all of the time while
5394 leaving default_breakpoint_* alone.
5395 ObjC: However, don't match an Objective-C method name which
5396 may have a '+' or '-' succeeded by a '[' */
5398 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5400 if (default_breakpoint_valid
5402 || ((strchr ("+-", (*address
)[0]) != NULL
)
5403 && ((*address
)[1] != '['))))
5404 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5405 default_breakpoint_line
, addr_string
,
5408 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5409 addr_string
, not_found_ptr
);
5411 /* For any SAL that didn't have a canonical string, fill one in. */
5412 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5413 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5414 if (addr_start
!= (*address
))
5417 for (i
= 0; i
< sals
->nelts
; i
++)
5419 /* Add the string if not present. */
5420 if ((*addr_string
)[i
] == NULL
)
5421 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5427 /* Convert each SAL into a real PC. Verify that the PC can be
5428 inserted as a breakpoint. If it can't throw an error. */
5431 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5435 for (i
= 0; i
< sals
->nelts
; i
++)
5436 resolve_sal_pc (&sals
->sals
[i
]);
5440 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5442 struct captured_parse_breakpoint_args
*args
= data
;
5444 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5445 args
->not_found_ptr
);
5448 /* Given TOK, a string specification of condition and thread, as
5449 accepted by the 'break' command, extract the condition
5450 string and thread number and set *COND_STRING and *THREAD.
5451 PC identifies the context at which the condition should be parsed.
5452 If no condition is found, *COND_STRING is set to NULL.
5453 If no thread is found, *THREAD is set to -1. */
5455 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5456 char **cond_string
, int *thread
)
5458 *cond_string
= NULL
;
5464 char *cond_start
= NULL
;
5465 char *cond_end
= NULL
;
5466 while (*tok
== ' ' || *tok
== '\t')
5471 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5474 toklen
= end_tok
- tok
;
5476 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5478 struct expression
*expr
;
5480 tok
= cond_start
= end_tok
+ 1;
5481 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5484 *cond_string
= savestring (cond_start
,
5485 cond_end
- cond_start
);
5487 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5493 *thread
= strtol (tok
, &tok
, 0);
5495 error (_("Junk after thread keyword."));
5496 if (!valid_thread_id (*thread
))
5497 error (_("Unknown thread %d."), *thread
);
5500 error (_("Junk at end of arguments."));
5504 /* Set a breakpoint. This function is shared between
5505 CLI and MI functions for setting a breakpoint.
5506 This function has two major modes of operations,
5507 selected by the PARSE_CONDITION_AND_THREAD parameter.
5508 If non-zero, the function will parse arg, extracting
5509 breakpoint location, address and thread. Otherwise,
5510 ARG is just the location of breakpoint, with condition
5511 and thread specified by the COND_STRING and THREAD
5515 break_command_really (char *arg
, char *cond_string
, int thread
,
5516 int parse_condition_and_thread
,
5517 int tempflag
, int hardwareflag
,
5519 enum auto_boolean pending_break_support
,
5520 struct breakpoint_ops
*ops
,
5524 struct gdb_exception e
;
5525 struct symtabs_and_lines sals
;
5526 struct symtab_and_line pending_sal
;
5529 char *addr_start
= arg
;
5531 struct cleanup
*old_chain
;
5532 struct cleanup
*breakpoint_chain
= NULL
;
5533 struct captured_parse_breakpoint_args parse_args
;
5542 parse_args
.arg_p
= &arg
;
5543 parse_args
.sals_p
= &sals
;
5544 parse_args
.addr_string_p
= &addr_string
;
5545 parse_args
.not_found_ptr
= ¬_found
;
5547 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5548 &parse_args
, RETURN_MASK_ALL
);
5550 /* If caller is interested in rc value from parse, set value. */
5554 throw_exception (e
);
5558 case NOT_FOUND_ERROR
:
5560 /* If pending breakpoint support is turned off, throw
5563 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5564 throw_exception (e
);
5566 exception_print (gdb_stderr
, e
);
5568 /* If pending breakpoint support is auto query and the user
5569 selects no, then simply return the error code. */
5570 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5571 !nquery ("Make breakpoint pending on future shared library load? "))
5574 /* At this point, either the user was queried about setting
5575 a pending breakpoint and selected yes, or pending
5576 breakpoint behavior is on and thus a pending breakpoint
5577 is defaulted on behalf of the user. */
5578 copy_arg
= xstrdup (addr_start
);
5579 addr_string
= ©_arg
;
5581 sals
.sals
= &pending_sal
;
5586 throw_exception (e
);
5593 /* Create a chain of things that always need to be cleaned up. */
5594 old_chain
= make_cleanup (null_cleanup
, 0);
5598 /* Make sure that all storage allocated to SALS gets freed. */
5599 make_cleanup (xfree
, sals
.sals
);
5601 /* Cleanup the addr_string array but not its contents. */
5602 make_cleanup (xfree
, addr_string
);
5605 /* ----------------------------- SNIP -----------------------------
5606 Anything added to the cleanup chain beyond this point is assumed
5607 to be part of a breakpoint. If the breakpoint create succeeds
5608 then the memory is not reclaimed. */
5609 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5611 /* Mark the contents of the addr_string for cleanup. These go on
5612 the breakpoint_chain and only occure if the breakpoint create
5614 for (i
= 0; i
< sals
.nelts
; i
++)
5616 if (addr_string
[i
] != NULL
)
5617 make_cleanup (xfree
, addr_string
[i
]);
5620 /* Resolve all line numbers to PC's and verify that the addresses
5621 are ok for the target. */
5623 breakpoint_sals_to_pc (&sals
, addr_start
);
5625 /* Verify that condition can be parsed, before setting any
5626 breakpoints. Allocate a separate condition expression for each
5630 if (parse_condition_and_thread
)
5632 /* Here we only parse 'arg' to separate condition
5633 from thread number, so parsing in context of first
5634 sal is OK. When setting the breakpoint we'll
5635 re-parse it in context of each sal. */
5638 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5640 make_cleanup (xfree
, cond_string
);
5644 /* Create a private copy of condition string. */
5647 cond_string
= xstrdup (cond_string
);
5648 make_cleanup (xfree
, cond_string
);
5651 create_breakpoints (sals
, addr_string
, cond_string
,
5652 hardwareflag
? bp_hardware_breakpoint
5654 tempflag
? disp_del
: disp_donttouch
,
5655 thread
, ignore_count
, ops
, from_tty
, enabled
);
5659 struct symtab_and_line sal
= {0};
5660 struct breakpoint
*b
;
5662 make_cleanup (xfree
, copy_arg
);
5664 b
= set_raw_breakpoint_without_location (hardwareflag
5665 ? bp_hardware_breakpoint
5667 set_breakpoint_count (breakpoint_count
+ 1);
5668 b
->number
= breakpoint_count
;
5670 b
->addr_string
= addr_string
[0];
5671 b
->cond_string
= NULL
;
5672 b
->ignore_count
= ignore_count
;
5673 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5674 b
->condition_not_parsed
= 1;
5676 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5678 update_global_location_list (1);
5683 warning (_("Multiple breakpoints were set.\n"
5684 "Use the \"delete\" command to delete unwanted breakpoints."));
5685 /* That's it. Discard the cleanups for data inserted into the
5687 discard_cleanups (breakpoint_chain
);
5688 /* But cleanup everything else. */
5689 do_cleanups (old_chain
);
5692 /* Set a breakpoint.
5693 ARG is a string describing breakpoint address,
5694 condition, and thread.
5695 FLAG specifies if a breakpoint is hardware on,
5696 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5700 break_command_1 (char *arg
, int flag
, int from_tty
)
5702 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5703 int tempflag
= flag
& BP_TEMPFLAG
;
5705 break_command_really (arg
,
5706 NULL
, 0, 1 /* parse arg */,
5707 tempflag
, hardwareflag
,
5708 0 /* Ignore count */,
5709 pending_break_support
,
5710 NULL
/* breakpoint_ops */,
5717 set_breakpoint (char *address
, char *condition
,
5718 int hardwareflag
, int tempflag
,
5719 int thread
, int ignore_count
,
5720 int pending
, int enabled
)
5722 break_command_really (address
, condition
, thread
,
5723 0 /* condition and thread are valid. */,
5724 tempflag
, hardwareflag
,
5727 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5731 /* Adjust SAL to the first instruction past the function prologue.
5732 The end of the prologue is determined using the line table from
5733 the debugging information.
5735 If SAL is already past the prologue, then do nothing. */
5738 skip_prologue_sal (struct symtab_and_line
*sal
)
5740 struct symbol
*sym
= find_pc_function (sal
->pc
);
5741 struct symtab_and_line start_sal
;
5746 start_sal
= find_function_start_sal (sym
, 1);
5747 if (sal
->pc
< start_sal
.pc
)
5751 /* Helper function for break_command_1 and disassemble_command. */
5754 resolve_sal_pc (struct symtab_and_line
*sal
)
5758 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5760 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5761 error (_("No line %d in file \"%s\"."),
5762 sal
->line
, sal
->symtab
->filename
);
5765 /* If this SAL corresponds to a breakpoint inserted using
5766 a line number, then skip the function prologue if necessary. */
5767 if (sal
->explicit_line
)
5768 skip_prologue_sal (sal
);
5771 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5773 struct blockvector
*bv
;
5777 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5780 sym
= block_linkage_function (b
);
5783 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5784 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5788 /* It really is worthwhile to have the section, so we'll just
5789 have to look harder. This case can be executed if we have
5790 line numbers but no functions (as can happen in assembly
5793 struct minimal_symbol
*msym
;
5795 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5797 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5804 break_command (char *arg
, int from_tty
)
5806 break_command_1 (arg
, 0, from_tty
);
5810 tbreak_command (char *arg
, int from_tty
)
5812 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5816 hbreak_command (char *arg
, int from_tty
)
5818 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5822 thbreak_command (char *arg
, int from_tty
)
5824 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5828 stop_command (char *arg
, int from_tty
)
5830 printf_filtered (_("Specify the type of breakpoint to set.\n\
5831 Usage: stop in <function | address>\n\
5832 stop at <line>\n"));
5836 stopin_command (char *arg
, int from_tty
)
5840 if (arg
== (char *) NULL
)
5842 else if (*arg
!= '*')
5847 /* look for a ':'. If this is a line number specification, then
5848 say it is bad, otherwise, it should be an address or
5849 function/method name */
5850 while (*argptr
&& !hasColon
)
5852 hasColon
= (*argptr
== ':');
5857 badInput
= (*argptr
!= ':'); /* Not a class::method */
5859 badInput
= isdigit (*arg
); /* a simple line number */
5863 printf_filtered (_("Usage: stop in <function | address>\n"));
5865 break_command_1 (arg
, 0, from_tty
);
5869 stopat_command (char *arg
, int from_tty
)
5873 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5880 /* look for a ':'. If there is a '::' then get out, otherwise
5881 it is probably a line number. */
5882 while (*argptr
&& !hasColon
)
5884 hasColon
= (*argptr
== ':');
5889 badInput
= (*argptr
== ':'); /* we have class::method */
5891 badInput
= !isdigit (*arg
); /* not a line number */
5895 printf_filtered (_("Usage: stop at <line>\n"));
5897 break_command_1 (arg
, 0, from_tty
);
5900 /* accessflag: hw_write: watch write,
5901 hw_read: watch read,
5902 hw_access: watch access (read or write) */
5904 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5906 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5907 struct symtab_and_line sal
;
5908 struct expression
*exp
;
5909 struct block
*exp_valid_block
;
5910 struct value
*val
, *mark
;
5911 struct frame_info
*frame
;
5912 struct frame_info
*prev_frame
= NULL
;
5913 char *exp_start
= NULL
;
5914 char *exp_end
= NULL
;
5915 char *tok
, *id_tok_start
, *end_tok
;
5917 char *cond_start
= NULL
;
5918 char *cond_end
= NULL
;
5919 struct expression
*cond
= NULL
;
5920 int i
, other_type_used
, target_resources_ok
= 0;
5921 enum bptype bp_type
;
5925 init_sal (&sal
); /* initialize to zeroes */
5927 /* Make sure that we actually have parameters to parse. */
5928 if (arg
!= NULL
&& arg
[0] != '\0')
5930 toklen
= strlen (arg
); /* Size of argument list. */
5932 /* Points tok to the end of the argument list. */
5933 tok
= arg
+ toklen
- 1;
5935 /* Go backwards in the parameters list. Skip the last parameter.
5936 If we're expecting a 'thread <thread_num>' parameter, this should
5937 be the thread identifier. */
5938 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5940 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5943 /* Points end_tok to the beginning of the last token. */
5944 id_tok_start
= tok
+ 1;
5946 /* Go backwards in the parameters list. Skip one more parameter.
5947 If we're expecting a 'thread <thread_num>' parameter, we should
5948 reach a "thread" token. */
5949 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5954 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5957 /* Move the pointer forward to skip the whitespace and
5958 calculate the length of the token. */
5960 toklen
= end_tok
- tok
;
5962 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5964 /* At this point we've found a "thread" token, which means
5965 the user is trying to set a watchpoint that triggers
5966 only in a specific thread. */
5969 /* Extract the thread ID from the next token. */
5970 thread
= strtol (id_tok_start
, &endp
, 0);
5972 /* Check if the user provided a valid numeric value for the
5974 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5975 error (_("Invalid thread ID specification %s."), id_tok_start
);
5977 /* Check if the thread actually exists. */
5978 if (!valid_thread_id (thread
))
5979 error (_("Unknown thread %d."), thread
);
5981 /* Truncate the string and get rid of the thread <thread_num>
5982 parameter before the parameter list is parsed by the
5983 evaluate_expression() function. */
5988 /* Parse the rest of the arguments. */
5989 innermost_block
= NULL
;
5991 exp
= parse_exp_1 (&arg
, 0, 0);
5993 /* Remove trailing whitespace from the expression before saving it.
5994 This makes the eventual display of the expression string a bit
5996 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
5999 exp_valid_block
= innermost_block
;
6000 mark
= value_mark ();
6001 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6003 release_value (val
);
6006 while (*tok
== ' ' || *tok
== '\t')
6010 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6013 toklen
= end_tok
- tok
;
6014 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6016 tok
= cond_start
= end_tok
+ 1;
6017 cond
= parse_exp_1 (&tok
, 0, 0);
6021 error (_("Junk at end of command."));
6023 if (accessflag
== hw_read
)
6024 bp_type
= bp_read_watchpoint
;
6025 else if (accessflag
== hw_access
)
6026 bp_type
= bp_access_watchpoint
;
6028 bp_type
= bp_hardware_watchpoint
;
6030 mem_cnt
= can_use_hardware_watchpoint (val
);
6031 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6032 error (_("Expression cannot be implemented with read/access watchpoint."));
6035 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6036 target_resources_ok
=
6037 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6039 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6040 error (_("Target does not support this type of hardware watchpoint."));
6042 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6043 error (_("Target can only support one kind of HW watchpoint at a time."));
6046 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6047 watchpoint could not be set. */
6048 if (!mem_cnt
|| target_resources_ok
<= 0)
6049 bp_type
= bp_watchpoint
;
6051 frame
= block_innermost_frame (exp_valid_block
);
6053 prev_frame
= get_prev_frame (frame
);
6057 /* If the expression is "local", then set up a "watchpoint scope"
6058 breakpoint at the point where we've left the scope of the watchpoint
6059 expression. Create the scope breakpoint before the watchpoint, so
6060 that we will encounter it first in bpstat_stop_status. */
6061 if (innermost_block
&& prev_frame
)
6063 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6064 bp_watchpoint_scope
);
6066 scope_breakpoint
->enable_state
= bp_enabled
;
6068 /* Automatically delete the breakpoint when it hits. */
6069 scope_breakpoint
->disposition
= disp_del
;
6071 /* Only break in the proper frame (help with recursion). */
6072 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6074 /* Set the address at which we will stop. */
6075 scope_breakpoint
->loc
->requested_address
6076 = get_frame_pc (prev_frame
);
6077 scope_breakpoint
->loc
->address
6078 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6079 scope_breakpoint
->type
);
6082 /* Now set up the breakpoint. */
6083 b
= set_raw_breakpoint (sal
, bp_type
);
6084 set_breakpoint_count (breakpoint_count
+ 1);
6085 b
->number
= breakpoint_count
;
6087 b
->disposition
= disp_donttouch
;
6089 b
->exp_valid_block
= exp_valid_block
;
6090 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6093 b
->loc
->cond
= cond
;
6095 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6100 b
->watchpoint_frame
= get_frame_id (frame
);
6102 b
->watchpoint_frame
= null_frame_id
;
6104 if (scope_breakpoint
!= NULL
)
6106 /* The scope breakpoint is related to the watchpoint. We will
6107 need to act on them together. */
6108 b
->related_breakpoint
= scope_breakpoint
;
6109 scope_breakpoint
->related_breakpoint
= b
;
6112 value_free_to_mark (mark
);
6114 update_global_location_list (1);
6117 /* Return count of locations need to be watched and can be handled
6118 in hardware. If the watchpoint can not be handled
6119 in hardware return zero. */
6122 can_use_hardware_watchpoint (struct value
*v
)
6124 int found_memory_cnt
= 0;
6125 struct value
*head
= v
;
6127 /* Did the user specifically forbid us to use hardware watchpoints? */
6128 if (!can_use_hw_watchpoints
)
6131 /* Make sure that the value of the expression depends only upon
6132 memory contents, and values computed from them within GDB. If we
6133 find any register references or function calls, we can't use a
6134 hardware watchpoint.
6136 The idea here is that evaluating an expression generates a series
6137 of values, one holding the value of every subexpression. (The
6138 expression a*b+c has five subexpressions: a, b, a*b, c, and
6139 a*b+c.) GDB's values hold almost enough information to establish
6140 the criteria given above --- they identify memory lvalues,
6141 register lvalues, computed values, etcetera. So we can evaluate
6142 the expression, and then scan the chain of values that leaves
6143 behind to decide whether we can detect any possible change to the
6144 expression's final value using only hardware watchpoints.
6146 However, I don't think that the values returned by inferior
6147 function calls are special in any way. So this function may not
6148 notice that an expression involving an inferior function call
6149 can't be watched with hardware watchpoints. FIXME. */
6150 for (; v
; v
= value_next (v
))
6152 if (VALUE_LVAL (v
) == lval_memory
)
6155 /* A lazy memory lvalue is one that GDB never needed to fetch;
6156 we either just used its address (e.g., `a' in `a.b') or
6157 we never needed it at all (e.g., `a' in `a,b'). */
6161 /* Ahh, memory we actually used! Check if we can cover
6162 it with hardware watchpoints. */
6163 struct type
*vtype
= check_typedef (value_type (v
));
6165 /* We only watch structs and arrays if user asked for it
6166 explicitly, never if they just happen to appear in a
6167 middle of some value chain. */
6169 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6170 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6172 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6173 int len
= TYPE_LENGTH (value_type (v
));
6175 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6182 else if (VALUE_LVAL (v
) != not_lval
6183 && deprecated_value_modifiable (v
) == 0)
6184 return 0; /* ??? What does this represent? */
6185 else if (VALUE_LVAL (v
) == lval_register
)
6186 return 0; /* cannot watch a register with a HW watchpoint */
6189 /* The expression itself looks suitable for using a hardware
6190 watchpoint, but give the target machine a chance to reject it. */
6191 return found_memory_cnt
;
6195 watch_command_wrapper (char *arg
, int from_tty
)
6197 watch_command (arg
, from_tty
);
6201 watch_command (char *arg
, int from_tty
)
6203 watch_command_1 (arg
, hw_write
, from_tty
);
6207 rwatch_command_wrapper (char *arg
, int from_tty
)
6209 rwatch_command (arg
, from_tty
);
6213 rwatch_command (char *arg
, int from_tty
)
6215 watch_command_1 (arg
, hw_read
, from_tty
);
6219 awatch_command_wrapper (char *arg
, int from_tty
)
6221 awatch_command (arg
, from_tty
);
6225 awatch_command (char *arg
, int from_tty
)
6227 watch_command_1 (arg
, hw_access
, from_tty
);
6231 /* Helper routines for the until_command routine in infcmd.c. Here
6232 because it uses the mechanisms of breakpoints. */
6234 struct until_break_command_continuation_args
6236 struct breakpoint
*breakpoint
;
6237 struct breakpoint
*breakpoint2
;
6240 /* This function is called by fetch_inferior_event via the
6241 cmd_continuation pointer, to complete the until command. It takes
6242 care of cleaning up the temporary breakpoints set up by the until
6245 until_break_command_continuation (void *arg
)
6247 struct until_break_command_continuation_args
*a
= arg
;
6249 delete_breakpoint (a
->breakpoint
);
6251 delete_breakpoint (a
->breakpoint2
);
6255 until_break_command (char *arg
, int from_tty
, int anywhere
)
6257 struct symtabs_and_lines sals
;
6258 struct symtab_and_line sal
;
6259 struct frame_info
*frame
= get_selected_frame (NULL
);
6260 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6261 struct breakpoint
*breakpoint
;
6262 struct breakpoint
*breakpoint2
= NULL
;
6263 struct cleanup
*old_chain
;
6265 clear_proceed_status ();
6267 /* Set a breakpoint where the user wants it and at return from
6270 if (default_breakpoint_valid
)
6271 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6272 default_breakpoint_line
, (char ***) NULL
, NULL
);
6274 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6275 0, (char ***) NULL
, NULL
);
6277 if (sals
.nelts
!= 1)
6278 error (_("Couldn't get information on specified line."));
6281 xfree (sals
.sals
); /* malloc'd, so freed */
6284 error (_("Junk at end of arguments."));
6286 resolve_sal_pc (&sal
);
6289 /* If the user told us to continue until a specified location,
6290 we don't specify a frame at which we need to stop. */
6291 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6293 /* Otherwise, specify the current frame, because we want to stop only
6294 at the very same frame. */
6295 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6298 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6300 /* Keep within the current frame, or in frames called by the current
6304 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6305 sal
.pc
= get_frame_pc (prev_frame
);
6306 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6308 make_cleanup_delete_breakpoint (breakpoint2
);
6311 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6313 /* If we are running asynchronously, and proceed call above has actually
6314 managed to start the target, arrange for breakpoints to be
6315 deleted when the target stops. Otherwise, we're already stopped and
6316 delete breakpoints via cleanup chain. */
6318 if (target_can_async_p () && is_running (inferior_ptid
))
6320 struct until_break_command_continuation_args
*args
;
6321 args
= xmalloc (sizeof (*args
));
6323 args
->breakpoint
= breakpoint
;
6324 args
->breakpoint2
= breakpoint2
;
6326 discard_cleanups (old_chain
);
6327 add_continuation (inferior_thread (),
6328 until_break_command_continuation
, args
,
6332 do_cleanups (old_chain
);
6336 ep_skip_leading_whitespace (char **s
)
6338 if ((s
== NULL
) || (*s
== NULL
))
6340 while (isspace (**s
))
6344 /* This function attempts to parse an optional "if <cond>" clause
6345 from the arg string. If one is not found, it returns NULL.
6347 Else, it returns a pointer to the condition string. (It does not
6348 attempt to evaluate the string against a particular block.) And,
6349 it updates arg to point to the first character following the parsed
6350 if clause in the arg string. */
6353 ep_parse_optional_if_clause (char **arg
)
6357 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6360 /* Skip the "if" keyword. */
6363 /* Skip any extra leading whitespace, and record the start of the
6364 condition string. */
6365 ep_skip_leading_whitespace (arg
);
6368 /* Assume that the condition occupies the remainder of the arg string. */
6369 (*arg
) += strlen (cond_string
);
6374 /* This function attempts to parse an optional filename from the arg
6375 string. If one is not found, it returns NULL.
6377 Else, it returns a pointer to the parsed filename. (This function
6378 makes no attempt to verify that a file of that name exists, or is
6379 accessible.) And, it updates arg to point to the first character
6380 following the parsed filename in the arg string.
6382 Note that clients needing to preserve the returned filename for
6383 future access should copy it to their own buffers. */
6385 ep_parse_optional_filename (char **arg
)
6387 static char filename
[1024];
6392 if ((*arg_p
== '\0') || isspace (*arg_p
))
6410 /* Commands to deal with catching events, such as signals, exceptions,
6411 process start/exit, etc. */
6415 catch_fork_temporary
, catch_vfork_temporary
,
6416 catch_fork_permanent
, catch_vfork_permanent
6421 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6423 char *cond_string
= NULL
;
6424 catch_fork_kind fork_kind
;
6427 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6428 tempflag
= (fork_kind
== catch_fork_temporary
6429 || fork_kind
== catch_vfork_temporary
);
6433 ep_skip_leading_whitespace (&arg
);
6435 /* The allowed syntax is:
6437 catch [v]fork if <cond>
6439 First, check if there's an if clause. */
6440 cond_string
= ep_parse_optional_if_clause (&arg
);
6442 if ((*arg
!= '\0') && !isspace (*arg
))
6443 error (_("Junk at end of arguments."));
6445 /* If this target supports it, create a fork or vfork catchpoint
6446 and enable reporting of such events. */
6449 case catch_fork_temporary
:
6450 case catch_fork_permanent
:
6451 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6452 &catch_fork_breakpoint_ops
);
6454 case catch_vfork_temporary
:
6455 case catch_vfork_permanent
:
6456 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6457 &catch_vfork_breakpoint_ops
);
6460 error (_("unsupported or unknown fork kind; cannot catch it"));
6466 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6469 char *cond_string
= NULL
;
6471 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6475 ep_skip_leading_whitespace (&arg
);
6477 /* The allowed syntax is:
6479 catch exec if <cond>
6481 First, check if there's an if clause. */
6482 cond_string
= ep_parse_optional_if_clause (&arg
);
6484 if ((*arg
!= '\0') && !isspace (*arg
))
6485 error (_("Junk at end of arguments."));
6487 /* If this target supports it, create an exec catchpoint
6488 and enable reporting of such events. */
6489 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6492 static enum print_stop_action
6493 print_exception_catchpoint (struct breakpoint
*b
)
6495 int bp_temp
, bp_throw
;
6497 annotate_catchpoint (b
->number
);
6499 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6500 if (b
->loc
->address
!= b
->loc
->requested_address
)
6501 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6504 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6506 bp_temp
? "Temporary catchpoint "
6508 if (!ui_out_is_mi_like_p (uiout
))
6509 ui_out_field_int (uiout
, "bkptno", b
->number
);
6511 bp_throw
? " (exception thrown), "
6512 : " (exception caught), ");
6513 if (ui_out_is_mi_like_p (uiout
))
6515 ui_out_field_string (uiout
, "reason",
6516 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6517 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6518 ui_out_field_int (uiout
, "bkptno", b
->number
);
6520 return PRINT_SRC_AND_LOC
;
6524 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6526 struct value_print_options opts
;
6527 get_user_print_options (&opts
);
6528 if (opts
.addressprint
)
6531 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6532 ui_out_field_string (uiout
, "addr", "<PENDING>");
6534 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6538 *last_addr
= b
->loc
->address
;
6539 if (strstr (b
->addr_string
, "throw") != NULL
)
6540 ui_out_field_string (uiout
, "what", "exception throw");
6542 ui_out_field_string (uiout
, "what", "exception catch");
6546 print_mention_exception_catchpoint (struct breakpoint
*b
)
6551 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6552 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6553 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6554 : _("Catchpoint "));
6555 ui_out_field_int (uiout
, "bkptno", b
->number
);
6556 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6560 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6563 NULL
, /* breakpoint_hit */
6564 print_exception_catchpoint
,
6565 print_one_exception_catchpoint
,
6566 print_mention_exception_catchpoint
6570 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6571 enum exception_event_kind ex_event
, int from_tty
)
6573 char *trigger_func_name
;
6575 if (ex_event
== EX_EVENT_CATCH
)
6576 trigger_func_name
= "__cxa_begin_catch";
6578 trigger_func_name
= "__cxa_throw";
6580 break_command_really (trigger_func_name
, cond_string
, -1,
6581 0 /* condition and thread are valid. */,
6584 AUTO_BOOLEAN_TRUE
/* pending */,
6585 &gnu_v3_exception_catchpoint_ops
, from_tty
,
6591 /* Deal with "catch catch" and "catch throw" commands */
6594 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6595 int tempflag
, int from_tty
)
6597 char *cond_string
= NULL
;
6598 struct symtab_and_line
*sal
= NULL
;
6602 ep_skip_leading_whitespace (&arg
);
6604 cond_string
= ep_parse_optional_if_clause (&arg
);
6606 if ((*arg
!= '\0') && !isspace (*arg
))
6607 error (_("Junk at end of arguments."));
6609 if ((ex_event
!= EX_EVENT_THROW
) &&
6610 (ex_event
!= EX_EVENT_CATCH
))
6611 error (_("Unsupported or unknown exception event; cannot catch it"));
6613 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6616 warning (_("Unsupported with this platform/compiler combination."));
6619 /* Implementation of "catch catch" command. */
6622 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6624 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6625 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6628 /* Implementation of "catch throw" command. */
6631 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6633 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6634 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6637 /* Create a breakpoint struct for Ada exception catchpoints. */
6640 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6644 struct expression
*cond
,
6645 struct breakpoint_ops
*ops
,
6649 struct breakpoint
*b
;
6653 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6654 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6655 version for exception catchpoints, because two catchpoints
6656 used for different exception names will use the same address.
6657 In this case, a "breakpoint ... also set at..." warning is
6658 unproductive. Besides. the warning phrasing is also a bit
6659 inapropriate, we should use the word catchpoint, and tell
6660 the user what type of catchpoint it is. The above is good
6661 enough for now, though. */
6664 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6665 set_breakpoint_count (breakpoint_count
+ 1);
6667 b
->enable_state
= bp_enabled
;
6668 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6669 b
->number
= breakpoint_count
;
6670 b
->ignore_count
= 0;
6671 b
->loc
->cond
= cond
;
6672 b
->addr_string
= addr_string
;
6673 b
->language
= language_ada
;
6674 b
->cond_string
= cond_string
;
6675 b
->exp_string
= exp_string
;
6680 update_global_location_list (1);
6683 /* Implement the "catch exception" command. */
6686 catch_ada_exception_command (char *arg
, int from_tty
,
6687 struct cmd_list_element
*command
)
6690 struct symtab_and_line sal
;
6692 char *addr_string
= NULL
;
6693 char *exp_string
= NULL
;
6694 char *cond_string
= NULL
;
6695 struct expression
*cond
= NULL
;
6696 struct breakpoint_ops
*ops
= NULL
;
6698 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6702 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6703 &cond_string
, &cond
, &ops
);
6704 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6705 cond_string
, cond
, ops
, tempflag
,
6709 /* Implement the "catch assert" command. */
6712 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6715 struct symtab_and_line sal
;
6716 char *addr_string
= NULL
;
6717 struct breakpoint_ops
*ops
= NULL
;
6719 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6723 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6724 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6725 tempflag
, from_tty
);
6729 catch_command (char *arg
, int from_tty
)
6731 error (_("Catch requires an event name."));
6736 tcatch_command (char *arg
, int from_tty
)
6738 error (_("Catch requires an event name."));
6741 /* Delete breakpoints by address or line. */
6744 clear_command (char *arg
, int from_tty
)
6746 struct breakpoint
*b
;
6747 VEC(breakpoint_p
) *found
= 0;
6750 struct symtabs_and_lines sals
;
6751 struct symtab_and_line sal
;
6756 sals
= decode_line_spec (arg
, 1);
6761 sals
.sals
= (struct symtab_and_line
*)
6762 xmalloc (sizeof (struct symtab_and_line
));
6763 make_cleanup (xfree
, sals
.sals
);
6764 init_sal (&sal
); /* initialize to zeroes */
6765 sal
.line
= default_breakpoint_line
;
6766 sal
.symtab
= default_breakpoint_symtab
;
6767 sal
.pc
= default_breakpoint_address
;
6768 if (sal
.symtab
== 0)
6769 error (_("No source file specified."));
6777 /* We don't call resolve_sal_pc here. That's not
6778 as bad as it seems, because all existing breakpoints
6779 typically have both file/line and pc set. So, if
6780 clear is given file/line, we can match this to existing
6781 breakpoint without obtaining pc at all.
6783 We only support clearing given the address explicitly
6784 present in breakpoint table. Say, we've set breakpoint
6785 at file:line. There were several PC values for that file:line,
6786 due to optimization, all in one block.
6787 We've picked one PC value. If "clear" is issued with another
6788 PC corresponding to the same file:line, the breakpoint won't
6789 be cleared. We probably can still clear the breakpoint, but
6790 since the other PC value is never presented to user, user
6791 can only find it by guessing, and it does not seem important
6794 /* For each line spec given, delete bps which correspond
6795 to it. Do it in two passes, solely to preserve the current
6796 behavior that from_tty is forced true if we delete more than
6800 for (i
= 0; i
< sals
.nelts
; i
++)
6802 /* If exact pc given, clear bpts at that pc.
6803 If line given (pc == 0), clear all bpts on specified line.
6804 If defaulting, clear all bpts on default line
6807 defaulting sal.pc != 0 tests to do
6812 1 0 <can't happen> */
6816 /* Find all matching breakpoints and add them to
6821 /* Are we going to delete b? */
6822 if (b
->type
!= bp_none
6823 && b
->type
!= bp_watchpoint
6824 && b
->type
!= bp_hardware_watchpoint
6825 && b
->type
!= bp_read_watchpoint
6826 && b
->type
!= bp_access_watchpoint
)
6828 struct bp_location
*loc
= b
->loc
;
6829 for (; loc
; loc
= loc
->next
)
6831 int pc_match
= sal
.pc
6832 && (loc
->address
== sal
.pc
)
6833 && (!section_is_overlay (loc
->section
)
6834 || loc
->section
== sal
.section
);
6835 int line_match
= ((default_match
|| (0 == sal
.pc
))
6836 && b
->source_file
!= NULL
6837 && sal
.symtab
!= NULL
6838 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6839 && b
->line_number
== sal
.line
);
6840 if (pc_match
|| line_match
)
6849 VEC_safe_push(breakpoint_p
, found
, b
);
6852 /* Now go thru the 'found' chain and delete them. */
6853 if (VEC_empty(breakpoint_p
, found
))
6856 error (_("No breakpoint at %s."), arg
);
6858 error (_("No breakpoint at this line."));
6861 if (VEC_length(breakpoint_p
, found
) > 1)
6862 from_tty
= 1; /* Always report if deleted more than one */
6865 if (VEC_length(breakpoint_p
, found
) == 1)
6866 printf_unfiltered (_("Deleted breakpoint "));
6868 printf_unfiltered (_("Deleted breakpoints "));
6870 breakpoints_changed ();
6872 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6875 printf_unfiltered ("%d ", b
->number
);
6876 delete_breakpoint (b
);
6879 putchar_unfiltered ('\n');
6882 /* Delete breakpoint in BS if they are `delete' breakpoints and
6883 all breakpoints that are marked for deletion, whether hit or not.
6884 This is called after any breakpoint is hit, or after errors. */
6887 breakpoint_auto_delete (bpstat bs
)
6889 struct breakpoint
*b
, *temp
;
6891 for (; bs
; bs
= bs
->next
)
6892 if (bs
->breakpoint_at
6893 && bs
->breakpoint_at
->owner
6894 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6896 delete_breakpoint (bs
->breakpoint_at
->owner
);
6898 ALL_BREAKPOINTS_SAFE (b
, temp
)
6900 if (b
->disposition
== disp_del_at_next_stop
)
6901 delete_breakpoint (b
);
6905 /* A cleanup function which destroys a vector. */
6908 do_vec_free (void *p
)
6910 VEC(bp_location_p
) **vec
= p
;
6912 VEC_free (bp_location_p
, *vec
);
6915 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
6916 into the inferior, only remove already-inserted locations that no
6917 longer should be inserted. Functions that delete a breakpoint or
6918 breakpoints should pass false, so that deleting a breakpoint
6919 doesn't have the side effect of inserting the locations of other
6920 breakpoints that are marked not-inserted, but should_be_inserted
6921 returns true on them.
6923 This behaviour is useful is situations close to tear-down -- e.g.,
6924 after an exec, while the target still has execution, but breakpoint
6925 shadows of the previous executable image should *NOT* be restored
6926 to the new image; or before detaching, where the target still has
6927 execution and wants to delete breakpoints from GDB's lists, and all
6928 breakpoints had already been removed from the inferior. */
6931 update_global_location_list (int should_insert
)
6933 struct breakpoint
*b
;
6934 struct bp_location
**next
= &bp_location_chain
;
6935 struct bp_location
*loc
;
6936 struct bp_location
*loc2
;
6937 VEC(bp_location_p
) *old_locations
= NULL
;
6940 struct cleanup
*cleanups
;
6942 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
6943 /* Store old locations for future reference. */
6944 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6945 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6947 bp_location_chain
= NULL
;
6950 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6953 next
= &(loc
->global_next
);
6958 /* Identify bp_location instances that are no longer present in the new
6959 list, and therefore should be freed. Note that it's not necessary that
6960 those locations should be removed from inferior -- if there's another
6961 location at the same address (previously marked as duplicate),
6962 we don't need to remove/insert the location. */
6963 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6965 /* Tells if 'loc' is found amoung the new locations. If not, we
6967 int found_object
= 0;
6968 /* Tells if the location should remain inserted in the target. */
6969 int keep_in_target
= 0;
6971 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6978 /* If this location is no longer present, and inserted, look if there's
6979 maybe a new location at the same address. If so, mark that one
6980 inserted, and don't remove this one. This is needed so that we
6981 don't have a time window where a breakpoint at certain location is not
6986 /* If the location is inserted now, we might have to remove it. */
6988 if (found_object
&& should_be_inserted (loc
))
6990 /* The location is still present in the location list, and still
6991 should be inserted. Don't do anything. */
6996 /* The location is either no longer present, or got disabled.
6997 See if there's another location at the same address, in which
6998 case we don't need to remove this one from the target. */
6999 if (breakpoint_address_is_meaningful (loc
->owner
))
7000 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7002 /* For the sake of should_insert_location. The
7003 call to check_duplicates will fix up this later. */
7004 loc2
->duplicate
= 0;
7005 if (should_be_inserted (loc2
)
7006 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7009 loc2
->target_info
= loc
->target_info
;
7016 if (!keep_in_target
)
7018 if (remove_breakpoint (loc
, mark_uninserted
))
7020 /* This is just about all we can do. We could keep this
7021 location on the global list, and try to remove it next
7022 time, but there's no particular reason why we will
7025 Note that at this point, loc->owner is still valid,
7026 as delete_breakpoint frees the breakpoint only
7027 after calling us. */
7028 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7029 loc
->owner
->number
);
7037 if (removed
&& non_stop
)
7039 /* This location was removed from the targets. In non-stop mode,
7040 a race condition is possible where we've removed a breakpoint,
7041 but stop events for that breakpoint are already queued and will
7042 arrive later. To suppress spurious SIGTRAPs reported to user,
7043 we keep this breakpoint location for a bit, and will retire it
7044 after we see 3 * thread_count events.
7045 The theory here is that reporting of events should,
7046 "on the average", be fair, so after that many event we'll see
7047 events from all threads that have anything of interest, and no
7048 longer need to keep this breakpoint. This is just a
7049 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7050 which is usability issue, but not a correctness problem. */
7051 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7054 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7057 free_bp_location (loc
);
7063 check_duplicates (b
);
7066 if (breakpoints_always_inserted_mode () && should_insert
7067 && (target_has_execution
7068 || (gdbarch_has_global_solist (target_gdbarch
)
7069 && target_supports_multi_process ())))
7070 insert_breakpoint_locations ();
7072 do_cleanups (cleanups
);
7076 breakpoint_retire_moribund (void)
7078 struct bp_location
*loc
;
7081 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7082 if (--(loc
->events_till_retirement
) == 0)
7084 free_bp_location (loc
);
7085 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7091 update_global_location_list_nothrow (int inserting
)
7093 struct gdb_exception e
;
7094 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7095 update_global_location_list (inserting
);
7098 /* Clear BPT from a BPS. */
7100 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7103 for (bs
= bps
; bs
; bs
= bs
->next
)
7104 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7106 bs
->breakpoint_at
= NULL
;
7108 /* bs->commands will be freed later. */
7112 /* Callback for iterate_over_threads. */
7114 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7116 struct breakpoint
*bpt
= data
;
7117 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7121 /* Delete a breakpoint and clean up all traces of it in the data
7125 delete_breakpoint (struct breakpoint
*bpt
)
7127 struct breakpoint
*b
;
7128 struct bp_location
*loc
, *next
;
7130 gdb_assert (bpt
!= NULL
);
7132 /* Has this bp already been deleted? This can happen because multiple
7133 lists can hold pointers to bp's. bpstat lists are especial culprits.
7135 One example of this happening is a watchpoint's scope bp. When the
7136 scope bp triggers, we notice that the watchpoint is out of scope, and
7137 delete it. We also delete its scope bp. But the scope bp is marked
7138 "auto-deleting", and is already on a bpstat. That bpstat is then
7139 checked for auto-deleting bp's, which are deleted.
7141 A real solution to this problem might involve reference counts in bp's,
7142 and/or giving them pointers back to their referencing bpstat's, and
7143 teaching delete_breakpoint to only free a bp's storage when no more
7144 references were extent. A cheaper bandaid was chosen. */
7145 if (bpt
->type
== bp_none
)
7148 observer_notify_breakpoint_deleted (bpt
->number
);
7150 if (breakpoint_chain
== bpt
)
7151 breakpoint_chain
= bpt
->next
;
7156 b
->next
= bpt
->next
;
7160 free_command_lines (&bpt
->commands
);
7161 if (bpt
->cond_string
!= NULL
)
7162 xfree (bpt
->cond_string
);
7163 if (bpt
->addr_string
!= NULL
)
7164 xfree (bpt
->addr_string
);
7165 if (bpt
->exp
!= NULL
)
7167 if (bpt
->exp_string
!= NULL
)
7168 xfree (bpt
->exp_string
);
7169 if (bpt
->val
!= NULL
)
7170 value_free (bpt
->val
);
7171 if (bpt
->source_file
!= NULL
)
7172 xfree (bpt
->source_file
);
7173 if (bpt
->exec_pathname
!= NULL
)
7174 xfree (bpt
->exec_pathname
);
7176 /* Be sure no bpstat's are pointing at it after it's been freed. */
7177 /* FIXME, how can we find all bpstat's?
7178 We just check stop_bpstat for now. Note that we cannot just
7179 remove bpstats pointing at bpt from the stop_bpstat list
7180 entirely, as breakpoint commands are associated with the bpstat;
7181 if we remove it here, then the later call to
7182 bpstat_do_actions (&stop_bpstat);
7183 in event-top.c won't do anything, and temporary breakpoints
7184 with commands won't work. */
7186 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7188 /* Now that breakpoint is removed from breakpoint
7189 list, update the global location list. This
7190 will remove locations that used to belong to
7191 this breakpoint. Do this before freeing
7192 the breakpoint itself, since remove_breakpoint
7193 looks at location's owner. It might be better
7194 design to have location completely self-contained,
7195 but it's not the case now. */
7196 update_global_location_list (0);
7199 /* On the chance that someone will soon try again to delete this same
7200 bp, we mark it as deleted before freeing its storage. */
7201 bpt
->type
= bp_none
;
7207 do_delete_breakpoint_cleanup (void *b
)
7209 delete_breakpoint (b
);
7213 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7215 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7219 delete_command (char *arg
, int from_tty
)
7221 struct breakpoint
*b
, *temp
;
7227 int breaks_to_delete
= 0;
7229 /* Delete all breakpoints if no argument.
7230 Do not delete internal or call-dummy breakpoints, these
7231 have to be deleted with an explicit breakpoint number argument. */
7234 if (b
->type
!= bp_call_dummy
&&
7235 b
->type
!= bp_shlib_event
&&
7236 b
->type
!= bp_thread_event
&&
7237 b
->type
!= bp_overlay_event
&&
7240 breaks_to_delete
= 1;
7245 /* Ask user only if there are some breakpoints to delete. */
7247 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7249 ALL_BREAKPOINTS_SAFE (b
, temp
)
7251 if (b
->type
!= bp_call_dummy
&&
7252 b
->type
!= bp_shlib_event
&&
7253 b
->type
!= bp_thread_event
&&
7254 b
->type
!= bp_overlay_event
&&
7256 delete_breakpoint (b
);
7261 map_breakpoint_numbers (arg
, delete_breakpoint
);
7265 all_locations_are_pending (struct bp_location
*loc
)
7267 for (; loc
; loc
= loc
->next
)
7268 if (!loc
->shlib_disabled
)
7273 /* Subroutine of update_breakpoint_locations to simplify it.
7274 Return non-zero if multiple fns in list LOC have the same name.
7275 Null names are ignored. */
7278 ambiguous_names_p (struct bp_location
*loc
)
7280 struct bp_location
*l
;
7281 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7282 (int (*) (const void *, const void *)) streq
,
7283 NULL
, xcalloc
, xfree
);
7285 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7288 const char *name
= l
->function_name
;
7290 /* Allow for some names to be NULL, ignore them. */
7294 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7296 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7311 update_breakpoint_locations (struct breakpoint
*b
,
7312 struct symtabs_and_lines sals
)
7316 struct bp_location
*existing_locations
= b
->loc
;
7318 /* If there's no new locations, and all existing locations
7319 are pending, don't do anything. This optimizes
7320 the common case where all locations are in the same
7321 shared library, that was unloaded. We'd like to
7322 retain the location, so that when the library
7323 is loaded again, we don't loose the enabled/disabled
7324 status of the individual locations. */
7325 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7330 for (i
= 0; i
< sals
.nelts
; ++i
)
7332 struct bp_location
*new_loc
=
7333 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7335 /* Reparse conditions, they might contain references to the
7337 if (b
->cond_string
!= NULL
)
7339 struct gdb_exception e
;
7342 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7344 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7349 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7350 b
->number
, e
.message
);
7351 new_loc
->enabled
= 0;
7355 if (b
->source_file
!= NULL
)
7356 xfree (b
->source_file
);
7357 if (sals
.sals
[i
].symtab
== NULL
)
7358 b
->source_file
= NULL
;
7361 savestring (sals
.sals
[i
].symtab
->filename
,
7362 strlen (sals
.sals
[i
].symtab
->filename
));
7364 if (b
->line_number
== 0)
7365 b
->line_number
= sals
.sals
[i
].line
;
7368 /* Update locations of permanent breakpoints. */
7369 if (b
->enable_state
== bp_permanent
)
7370 make_breakpoint_permanent (b
);
7372 /* If possible, carry over 'disable' status from existing breakpoints. */
7374 struct bp_location
*e
= existing_locations
;
7375 /* If there are multiple breakpoints with the same function name,
7376 e.g. for inline functions, comparing function names won't work.
7377 Instead compare pc addresses; this is just a heuristic as things
7378 may have moved, but in practice it gives the correct answer
7379 often enough until a better solution is found. */
7380 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7382 for (; e
; e
= e
->next
)
7384 if (!e
->enabled
&& e
->function_name
)
7386 struct bp_location
*l
= b
->loc
;
7387 if (have_ambiguous_names
)
7389 for (; l
; l
= l
->next
)
7390 if (e
->address
== l
->address
)
7398 for (; l
; l
= l
->next
)
7399 if (l
->function_name
7400 && strcmp (e
->function_name
, l
->function_name
) == 0)
7410 update_global_location_list (1);
7414 /* Reset a breakpoint given it's struct breakpoint * BINT.
7415 The value we return ends up being the return value from catch_errors.
7416 Unused in this case. */
7419 breakpoint_re_set_one (void *bint
)
7421 /* get past catch_errs */
7422 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7426 int *not_found_ptr
= ¬_found
;
7427 struct symtabs_and_lines sals
= {};
7428 struct symtabs_and_lines expanded
;
7430 enum enable_state save_enable
;
7431 struct gdb_exception e
;
7432 struct cleanup
*cleanups
;
7437 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7441 case bp_hardware_breakpoint
:
7442 if (b
->addr_string
== NULL
)
7444 /* Anything without a string can't be re-set. */
7445 delete_breakpoint (b
);
7449 set_language (b
->language
);
7450 input_radix
= b
->input_radix
;
7452 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7454 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7459 int not_found_and_ok
= 0;
7460 /* For pending breakpoints, it's expected that parsing
7461 will fail until the right shared library is loaded.
7462 User has already told to create pending breakpoints and
7463 don't need extra messages. If breakpoint is in bp_shlib_disabled
7464 state, then user already saw the message about that breakpoint
7465 being disabled, and don't want to see more errors. */
7467 && (b
->condition_not_parsed
7468 || (b
->loc
&& b
->loc
->shlib_disabled
)
7469 || b
->enable_state
== bp_disabled
))
7470 not_found_and_ok
= 1;
7472 if (!not_found_and_ok
)
7474 /* We surely don't want to warn about the same breakpoint
7475 10 times. One solution, implemented here, is disable
7476 the breakpoint on error. Another solution would be to
7477 have separate 'warning emitted' flag. Since this
7478 happens only when a binary has changed, I don't know
7479 which approach is better. */
7480 b
->enable_state
= bp_disabled
;
7481 throw_exception (e
);
7488 gdb_assert (sals
.nelts
== 1);
7489 resolve_sal_pc (&sals
.sals
[0]);
7490 if (b
->condition_not_parsed
&& s
&& s
[0])
7492 char *cond_string
= 0;
7494 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7495 &cond_string
, &thread
);
7497 b
->cond_string
= cond_string
;
7499 b
->condition_not_parsed
= 0;
7501 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7502 cleanups
= make_cleanup (xfree
, sals
.sals
);
7503 update_breakpoint_locations (b
, expanded
);
7504 do_cleanups (cleanups
);
7508 case bp_hardware_watchpoint
:
7509 case bp_read_watchpoint
:
7510 case bp_access_watchpoint
:
7511 /* Watchpoint can be either on expression using entirely global variables,
7512 or it can be on local variables.
7514 Watchpoints of the first kind are never auto-deleted, and even persist
7515 across program restarts. Since they can use variables from shared
7516 libraries, we need to reparse expression as libraries are loaded
7519 Watchpoints on local variables can also change meaning as result
7520 of solib event. For example, if a watchpoint uses both a local and
7521 a global variables in expression, it's a local watchpoint, but
7522 unloading of a shared library will make the expression invalid.
7523 This is not a very common use case, but we still re-evaluate
7524 expression, to avoid surprises to the user.
7526 Note that for local watchpoints, we re-evaluate it only if
7527 watchpoints frame id is still valid. If it's not, it means
7528 the watchpoint is out of scope and will be deleted soon. In fact,
7529 I'm not sure we'll ever be called in this case.
7531 If a local watchpoint's frame id is still valid, then
7532 b->exp_valid_block is likewise valid, and we can safely use it.
7534 Don't do anything about disabled watchpoints, since they will
7535 be reevaluated again when enabled. */
7536 update_watchpoint (b
, 1 /* reparse */);
7538 /* We needn't really do anything to reset these, since the mask
7539 that requests them is unaffected by e.g., new libraries being
7545 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7547 /* Delete overlay event breakpoints; they will be reset later by
7548 breakpoint_re_set. */
7549 case bp_overlay_event
:
7550 delete_breakpoint (b
);
7553 /* This breakpoint is special, it's set up when the inferior
7554 starts and we really don't want to touch it. */
7555 case bp_shlib_event
:
7557 /* Like bp_shlib_event, this breakpoint type is special.
7558 Once it is set up, we do not want to touch it. */
7559 case bp_thread_event
:
7561 /* Keep temporary breakpoints, which can be encountered when we step
7562 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7563 Otherwise these should have been blown away via the cleanup chain
7564 or by breakpoint_init_inferior when we rerun the executable. */
7567 case bp_watchpoint_scope
:
7569 case bp_step_resume
:
7571 case bp_longjmp_resume
:
7578 /* Re-set all breakpoints after symbols have been re-loaded. */
7580 breakpoint_re_set (void)
7582 struct breakpoint
*b
, *temp
;
7583 enum language save_language
;
7584 int save_input_radix
;
7586 save_language
= current_language
->la_language
;
7587 save_input_radix
= input_radix
;
7588 ALL_BREAKPOINTS_SAFE (b
, temp
)
7590 /* Format possible error msg */
7591 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7593 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7594 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7595 do_cleanups (cleanups
);
7597 set_language (save_language
);
7598 input_radix
= save_input_radix
;
7600 create_overlay_event_breakpoint ("_ovly_debug_event");
7603 /* Reset the thread number of this breakpoint:
7605 - If the breakpoint is for all threads, leave it as-is.
7606 - Else, reset it to the current thread for inferior_ptid. */
7608 breakpoint_re_set_thread (struct breakpoint
*b
)
7610 if (b
->thread
!= -1)
7612 if (in_thread_list (inferior_ptid
))
7613 b
->thread
= pid_to_thread_id (inferior_ptid
);
7617 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7618 If from_tty is nonzero, it prints a message to that effect,
7619 which ends with a period (no newline). */
7622 set_ignore_count (int bptnum
, int count
, int from_tty
)
7624 struct breakpoint
*b
;
7630 if (b
->number
== bptnum
)
7632 b
->ignore_count
= count
;
7636 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7638 else if (count
== 1)
7639 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7642 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7645 breakpoints_changed ();
7646 observer_notify_breakpoint_modified (b
->number
);
7650 error (_("No breakpoint number %d."), bptnum
);
7654 make_breakpoint_silent (struct breakpoint
*b
)
7656 /* Silence the breakpoint. */
7660 /* Command to set ignore-count of breakpoint N to COUNT. */
7663 ignore_command (char *args
, int from_tty
)
7669 error_no_arg (_("a breakpoint number"));
7671 num
= get_number (&p
);
7673 error (_("bad breakpoint number: '%s'"), args
);
7675 error (_("Second argument (specified ignore-count) is missing."));
7677 set_ignore_count (num
,
7678 longest_to_int (value_as_long (parse_and_eval (p
))),
7681 printf_filtered ("\n");
7684 /* Call FUNCTION on each of the breakpoints
7685 whose numbers are given in ARGS. */
7688 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7693 struct breakpoint
*b
, *tmp
;
7697 error_no_arg (_("one or more breakpoint numbers"));
7704 num
= get_number_or_range (&p1
);
7707 warning (_("bad breakpoint number at or near '%s'"), p
);
7711 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7712 if (b
->number
== num
)
7714 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7717 if (related_breakpoint
)
7718 function (related_breakpoint
);
7722 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7728 static struct bp_location
*
7729 find_location_by_number (char *number
)
7731 char *dot
= strchr (number
, '.');
7735 struct breakpoint
*b
;
7736 struct bp_location
*loc
;
7741 bp_num
= get_number_or_range (&p1
);
7743 error (_("Bad breakpoint number '%s'"), number
);
7746 if (b
->number
== bp_num
)
7751 if (!b
|| b
->number
!= bp_num
)
7752 error (_("Bad breakpoint number '%s'"), number
);
7755 loc_num
= get_number_or_range (&p1
);
7757 error (_("Bad breakpoint location number '%s'"), number
);
7761 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7764 error (_("Bad breakpoint location number '%s'"), dot
+1);
7770 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7771 If from_tty is nonzero, it prints a message to that effect,
7772 which ends with a period (no newline). */
7775 disable_breakpoint (struct breakpoint
*bpt
)
7777 /* Never disable a watchpoint scope breakpoint; we want to
7778 hit them when we leave scope so we can delete both the
7779 watchpoint and its scope breakpoint at that time. */
7780 if (bpt
->type
== bp_watchpoint_scope
)
7783 /* You can't disable permanent breakpoints. */
7784 if (bpt
->enable_state
== bp_permanent
)
7787 bpt
->enable_state
= bp_disabled
;
7789 update_global_location_list (0);
7791 observer_notify_breakpoint_modified (bpt
->number
);
7795 disable_command (char *args
, int from_tty
)
7797 struct breakpoint
*bpt
;
7799 ALL_BREAKPOINTS (bpt
)
7803 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7808 case bp_hardware_breakpoint
:
7810 case bp_hardware_watchpoint
:
7811 case bp_read_watchpoint
:
7812 case bp_access_watchpoint
:
7813 disable_breakpoint (bpt
);
7817 else if (strchr (args
, '.'))
7819 struct bp_location
*loc
= find_location_by_number (args
);
7822 update_global_location_list (0);
7825 map_breakpoint_numbers (args
, disable_breakpoint
);
7829 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7831 int target_resources_ok
, other_type_used
;
7834 if (bpt
->type
== bp_hardware_breakpoint
)
7837 i
= hw_breakpoint_used_count ();
7838 target_resources_ok
=
7839 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7841 if (target_resources_ok
== 0)
7842 error (_("No hardware breakpoint support in the target."));
7843 else if (target_resources_ok
< 0)
7844 error (_("Hardware breakpoints used exceeds limit."));
7847 if (bpt
->type
== bp_watchpoint
||
7848 bpt
->type
== bp_hardware_watchpoint
||
7849 bpt
->type
== bp_read_watchpoint
||
7850 bpt
->type
== bp_access_watchpoint
)
7852 struct gdb_exception e
;
7854 TRY_CATCH (e
, RETURN_MASK_ALL
)
7856 update_watchpoint (bpt
, 1 /* reparse */);
7860 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
7866 if (bpt
->enable_state
!= bp_permanent
)
7867 bpt
->enable_state
= bp_enabled
;
7868 bpt
->disposition
= disposition
;
7869 update_global_location_list (1);
7870 breakpoints_changed ();
7872 observer_notify_breakpoint_modified (bpt
->number
);
7877 enable_breakpoint (struct breakpoint
*bpt
)
7879 do_enable_breakpoint (bpt
, bpt
->disposition
);
7882 /* The enable command enables the specified breakpoints (or all defined
7883 breakpoints) so they once again become (or continue to be) effective
7884 in stopping the inferior. */
7887 enable_command (char *args
, int from_tty
)
7889 struct breakpoint
*bpt
;
7891 ALL_BREAKPOINTS (bpt
)
7895 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7900 case bp_hardware_breakpoint
:
7902 case bp_hardware_watchpoint
:
7903 case bp_read_watchpoint
:
7904 case bp_access_watchpoint
:
7905 enable_breakpoint (bpt
);
7909 else if (strchr (args
, '.'))
7911 struct bp_location
*loc
= find_location_by_number (args
);
7914 update_global_location_list (1);
7917 map_breakpoint_numbers (args
, enable_breakpoint
);
7921 enable_once_breakpoint (struct breakpoint
*bpt
)
7923 do_enable_breakpoint (bpt
, disp_disable
);
7927 enable_once_command (char *args
, int from_tty
)
7929 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7933 enable_delete_breakpoint (struct breakpoint
*bpt
)
7935 do_enable_breakpoint (bpt
, disp_del
);
7939 enable_delete_command (char *args
, int from_tty
)
7941 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7945 set_breakpoint_cmd (char *args
, int from_tty
)
7950 show_breakpoint_cmd (char *args
, int from_tty
)
7954 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7956 struct symtabs_and_lines
7957 decode_line_spec_1 (char *string
, int funfirstline
)
7959 struct symtabs_and_lines sals
;
7961 error (_("Empty line specification."));
7962 if (default_breakpoint_valid
)
7963 sals
= decode_line_1 (&string
, funfirstline
,
7964 default_breakpoint_symtab
,
7965 default_breakpoint_line
,
7966 (char ***) NULL
, NULL
);
7968 sals
= decode_line_1 (&string
, funfirstline
,
7969 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7971 error (_("Junk at end of line specification: %s"), string
);
7975 /* Create and insert a raw software breakpoint at PC. Return an
7976 identifier, which should be used to remove the breakpoint later.
7977 In general, places which call this should be using something on the
7978 breakpoint chain instead; this function should be eliminated
7982 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7984 struct bp_target_info
*bp_tgt
;
7986 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7987 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7989 bp_tgt
->placed_address
= pc
;
7990 if (target_insert_breakpoint (bp_tgt
) != 0)
7992 /* Could not insert the breakpoint. */
8000 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8003 deprecated_remove_raw_breakpoint (void *bp
)
8005 struct bp_target_info
*bp_tgt
= bp
;
8008 ret
= target_remove_breakpoint (bp_tgt
);
8014 /* One (or perhaps two) breakpoints used for software single stepping. */
8016 static void *single_step_breakpoints
[2];
8018 /* Create and insert a breakpoint for software single step. */
8021 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8025 if (single_step_breakpoints
[0] == NULL
)
8026 bpt_p
= &single_step_breakpoints
[0];
8029 gdb_assert (single_step_breakpoints
[1] == NULL
);
8030 bpt_p
= &single_step_breakpoints
[1];
8033 /* NOTE drow/2006-04-11: A future improvement to this function would be
8034 to only create the breakpoints once, and actually put them on the
8035 breakpoint chain. That would let us use set_raw_breakpoint. We could
8036 adjust the addresses each time they were needed. Doing this requires
8037 corresponding changes elsewhere where single step breakpoints are
8038 handled, however. So, for now, we use this. */
8040 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8042 error (_("Could not insert single-step breakpoint at 0x%s"),
8043 paddr_nz (next_pc
));
8046 /* Remove and delete any breakpoints used for software single step. */
8049 remove_single_step_breakpoints (void)
8051 gdb_assert (single_step_breakpoints
[0] != NULL
);
8053 /* See insert_single_step_breakpoint for more about this deprecated
8055 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8056 single_step_breakpoints
[0] = NULL
;
8058 if (single_step_breakpoints
[1] != NULL
)
8060 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8061 single_step_breakpoints
[1] = NULL
;
8065 /* Check whether a software single-step breakpoint is inserted at PC. */
8068 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8072 for (i
= 0; i
< 2; i
++)
8074 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8075 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8083 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8084 It is defined as a macro to prevent duplication.
8085 COMMAND should be a string constant containing the name of the command. */
8086 #define BREAK_ARGS_HELP(command) \
8087 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8088 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8089 If a line number is specified, break at start of code for that line.\n\
8090 If a function is specified, break at start of code for that function.\n\
8091 If an address is specified, break at that exact address.\n\
8092 With no LOCATION, uses current execution address of selected stack frame.\n\
8093 This is useful for breaking on return to a stack frame.\n\
8095 THREADNUM is the number from \"info threads\".\n\
8096 CONDITION is a boolean expression.\n\
8098 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8100 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8102 /* List of subcommands for "catch". */
8103 static struct cmd_list_element
*catch_cmdlist
;
8105 /* List of subcommands for "tcatch". */
8106 static struct cmd_list_element
*tcatch_cmdlist
;
8108 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8109 lists, and pass some additional user data to the command function. */
8111 add_catch_command (char *name
, char *docstring
,
8112 void (*sfunc
) (char *args
, int from_tty
,
8113 struct cmd_list_element
*command
),
8114 void *user_data_catch
,
8115 void *user_data_tcatch
)
8117 struct cmd_list_element
*command
;
8119 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8121 set_cmd_sfunc (command
, sfunc
);
8122 set_cmd_context (command
, user_data_catch
);
8124 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8126 set_cmd_sfunc (command
, sfunc
);
8127 set_cmd_context (command
, user_data_tcatch
);
8131 _initialize_breakpoint (void)
8133 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8134 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8135 struct cmd_list_element
*c
;
8137 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8139 breakpoint_chain
= 0;
8140 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8141 before a breakpoint is set. */
8142 breakpoint_count
= 0;
8144 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8145 Set ignore-count of breakpoint number N to COUNT.\n\
8146 Usage is `ignore N COUNT'."));
8148 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8150 add_com ("commands", class_breakpoint
, commands_command
, _("\
8151 Set commands to be executed when a breakpoint is hit.\n\
8152 Give breakpoint number as argument after \"commands\".\n\
8153 With no argument, the targeted breakpoint is the last one set.\n\
8154 The commands themselves follow starting on the next line.\n\
8155 Type a line containing \"end\" to indicate the end of them.\n\
8156 Give \"silent\" as the first line to make the breakpoint silent;\n\
8157 then no output is printed when it is hit, except what the commands print."));
8159 add_com ("condition", class_breakpoint
, condition_command
, _("\
8160 Specify breakpoint number N to break only if COND is true.\n\
8161 Usage is `condition N COND', where N is an integer and COND is an\n\
8162 expression to be evaluated whenever breakpoint N is reached."));
8164 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8165 Set a temporary breakpoint.\n\
8166 Like \"break\" except the breakpoint is only temporary,\n\
8167 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8168 by using \"enable delete\" on the breakpoint number.\n\
8170 BREAK_ARGS_HELP ("tbreak")));
8171 set_cmd_completer (c
, location_completer
);
8173 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8174 Set a hardware assisted breakpoint.\n\
8175 Like \"break\" except the breakpoint requires hardware support,\n\
8176 some target hardware may not have this support.\n\
8178 BREAK_ARGS_HELP ("hbreak")));
8179 set_cmd_completer (c
, location_completer
);
8181 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8182 Set a temporary hardware assisted breakpoint.\n\
8183 Like \"hbreak\" except the breakpoint is only temporary,\n\
8184 so it will be deleted when hit.\n\
8186 BREAK_ARGS_HELP ("thbreak")));
8187 set_cmd_completer (c
, location_completer
);
8189 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8190 Enable some breakpoints.\n\
8191 Give breakpoint numbers (separated by spaces) as arguments.\n\
8192 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8193 This is used to cancel the effect of the \"disable\" command.\n\
8194 With a subcommand you can enable temporarily."),
8195 &enablelist
, "enable ", 1, &cmdlist
);
8197 add_com ("ab", class_breakpoint
, enable_command
, _("\
8198 Enable some breakpoints.\n\
8199 Give breakpoint numbers (separated by spaces) as arguments.\n\
8200 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8201 This is used to cancel the effect of the \"disable\" command.\n\
8202 With a subcommand you can enable temporarily."));
8204 add_com_alias ("en", "enable", class_breakpoint
, 1);
8206 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8207 Enable some breakpoints.\n\
8208 Give breakpoint numbers (separated by spaces) as arguments.\n\
8209 This is used to cancel the effect of the \"disable\" command.\n\
8210 May be abbreviated to simply \"enable\".\n"),
8211 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8213 add_cmd ("once", no_class
, enable_once_command
, _("\
8214 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8215 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8218 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8219 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8220 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8223 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8224 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8225 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8228 add_cmd ("once", no_class
, enable_once_command
, _("\
8229 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8230 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8233 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8234 Disable some breakpoints.\n\
8235 Arguments are breakpoint numbers with spaces in between.\n\
8236 To disable all breakpoints, give no argument.\n\
8237 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8238 &disablelist
, "disable ", 1, &cmdlist
);
8239 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8240 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8242 add_com ("sb", class_breakpoint
, disable_command
, _("\
8243 Disable some breakpoints.\n\
8244 Arguments are breakpoint numbers with spaces in between.\n\
8245 To disable all breakpoints, give no argument.\n\
8246 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8248 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8249 Disable some breakpoints.\n\
8250 Arguments are breakpoint numbers with spaces in between.\n\
8251 To disable all breakpoints, give no argument.\n\
8252 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8253 This command may be abbreviated \"disable\"."),
8256 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8257 Delete some breakpoints or auto-display expressions.\n\
8258 Arguments are breakpoint numbers with spaces in between.\n\
8259 To delete all breakpoints, give no argument.\n\
8261 Also a prefix command for deletion of other GDB objects.\n\
8262 The \"unset\" command is also an alias for \"delete\"."),
8263 &deletelist
, "delete ", 1, &cmdlist
);
8264 add_com_alias ("d", "delete", class_breakpoint
, 1);
8265 add_com_alias ("del", "delete", class_breakpoint
, 1);
8267 add_com ("db", class_breakpoint
, delete_command
, _("\
8268 Delete some breakpoints.\n\
8269 Arguments are breakpoint numbers with spaces in between.\n\
8270 To delete all breakpoints, give no argument.\n"));
8272 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8273 Delete some breakpoints or auto-display expressions.\n\
8274 Arguments are breakpoint numbers with spaces in between.\n\
8275 To delete all breakpoints, give no argument.\n\
8276 This command may be abbreviated \"delete\"."),
8279 add_com ("clear", class_breakpoint
, clear_command
, _("\
8280 Clear breakpoint at specified line or function.\n\
8281 Argument may be line number, function name, or \"*\" and an address.\n\
8282 If line number is specified, all breakpoints in that line are cleared.\n\
8283 If function is specified, breakpoints at beginning of function are cleared.\n\
8284 If an address is specified, breakpoints at that address are cleared.\n\
8286 With no argument, clears all breakpoints in the line that the selected frame\n\
8289 See also the \"delete\" command which clears breakpoints by number."));
8291 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8292 Set breakpoint at specified line or function.\n"
8293 BREAK_ARGS_HELP ("break")));
8294 set_cmd_completer (c
, location_completer
);
8296 add_com_alias ("b", "break", class_run
, 1);
8297 add_com_alias ("br", "break", class_run
, 1);
8298 add_com_alias ("bre", "break", class_run
, 1);
8299 add_com_alias ("brea", "break", class_run
, 1);
8303 add_com_alias ("ba", "break", class_breakpoint
, 1);
8304 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8309 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8310 Break in function/address or break at a line in the current file."),
8311 &stoplist
, "stop ", 1, &cmdlist
);
8312 add_cmd ("in", class_breakpoint
, stopin_command
,
8313 _("Break in function or address."), &stoplist
);
8314 add_cmd ("at", class_breakpoint
, stopat_command
,
8315 _("Break at a line in the current file."), &stoplist
);
8316 add_com ("status", class_info
, breakpoints_info
, _("\
8317 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8318 The \"Type\" column indicates one of:\n\
8319 \tbreakpoint - normal breakpoint\n\
8320 \twatchpoint - watchpoint\n\
8321 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8322 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8323 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8324 address and file/line number respectively.\n\
8326 Convenience variable \"$_\" and default examine address for \"x\"\n\
8327 are set to the address of the last breakpoint listed unless the command\n\
8328 is prefixed with \"server \".\n\n\
8329 Convenience variable \"$bpnum\" contains the number of the last\n\
8333 add_info ("breakpoints", breakpoints_info
, _("\
8334 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8335 The \"Type\" column indicates one of:\n\
8336 \tbreakpoint - normal breakpoint\n\
8337 \twatchpoint - watchpoint\n\
8338 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8339 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8340 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8341 address and file/line number respectively.\n\
8343 Convenience variable \"$_\" and default examine address for \"x\"\n\
8344 are set to the address of the last breakpoint listed unless the command\n\
8345 is prefixed with \"server \".\n\n\
8346 Convenience variable \"$bpnum\" contains the number of the last\n\
8350 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8351 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8352 The \"Type\" column indicates one of:\n\
8353 \tbreakpoint - normal breakpoint\n\
8354 \twatchpoint - watchpoint\n\
8355 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8356 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8357 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8358 address and file/line number respectively.\n\
8360 Convenience variable \"$_\" and default examine address for \"x\"\n\
8361 are set to the address of the last breakpoint listed unless the command\n\
8362 is prefixed with \"server \".\n\n\
8363 Convenience variable \"$bpnum\" contains the number of the last\n\
8366 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8367 Status of all breakpoints, or breakpoint number NUMBER.\n\
8368 The \"Type\" column indicates one of:\n\
8369 \tbreakpoint - normal breakpoint\n\
8370 \twatchpoint - watchpoint\n\
8371 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8372 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8373 \tuntil - internal breakpoint used by the \"until\" command\n\
8374 \tfinish - internal breakpoint used by the \"finish\" command\n\
8375 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8376 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8377 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8378 address and file/line number respectively.\n\
8380 Convenience variable \"$_\" and default examine address for \"x\"\n\
8381 are set to the address of the last breakpoint listed unless the command\n\
8382 is prefixed with \"server \".\n\n\
8383 Convenience variable \"$bpnum\" contains the number of the last\n\
8385 &maintenanceinfolist
);
8387 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8388 Set catchpoints to catch events."),
8389 &catch_cmdlist
, "catch ",
8390 0/*allow-unknown*/, &cmdlist
);
8392 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8393 Set temporary catchpoints to catch events."),
8394 &tcatch_cmdlist
, "tcatch ",
8395 0/*allow-unknown*/, &cmdlist
);
8397 /* Add catch and tcatch sub-commands. */
8398 add_catch_command ("catch", _("\
8399 Catch an exception, when caught.\n\
8400 With an argument, catch only exceptions with the given name."),
8401 catch_catch_command
,
8404 add_catch_command ("throw", _("\
8405 Catch an exception, when thrown.\n\
8406 With an argument, catch only exceptions with the given name."),
8407 catch_throw_command
,
8410 add_catch_command ("fork", _("Catch calls to fork."),
8411 catch_fork_command_1
,
8412 (void *) (uintptr_t) catch_fork_permanent
,
8413 (void *) (uintptr_t) catch_fork_temporary
);
8414 add_catch_command ("vfork", _("Catch calls to vfork."),
8415 catch_fork_command_1
,
8416 (void *) (uintptr_t) catch_vfork_permanent
,
8417 (void *) (uintptr_t) catch_vfork_temporary
);
8418 add_catch_command ("exec", _("Catch calls to exec."),
8419 catch_exec_command_1
,
8422 add_catch_command ("exception", _("\
8423 Catch Ada exceptions, when raised.\n\
8424 With an argument, catch only exceptions with the given name."),
8425 catch_ada_exception_command
,
8428 add_catch_command ("assert", _("\
8429 Catch failed Ada assertions, when raised.\n\
8430 With an argument, catch only exceptions with the given name."),
8431 catch_assert_command
,
8435 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8436 Set a watchpoint for an expression.\n\
8437 A watchpoint stops execution of your program whenever the value of\n\
8438 an expression changes."));
8439 set_cmd_completer (c
, expression_completer
);
8441 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8442 Set a read watchpoint for an expression.\n\
8443 A watchpoint stops execution of your program whenever the value of\n\
8444 an expression is read."));
8445 set_cmd_completer (c
, expression_completer
);
8447 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8448 Set a watchpoint for an expression.\n\
8449 A watchpoint stops execution of your program whenever the value of\n\
8450 an expression is either read or written."));
8451 set_cmd_completer (c
, expression_completer
);
8453 add_info ("watchpoints", breakpoints_info
,
8454 _("Synonym for ``info breakpoints''."));
8457 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8458 respond to changes - contrary to the description. */
8459 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8460 &can_use_hw_watchpoints
, _("\
8461 Set debugger's willingness to use watchpoint hardware."), _("\
8462 Show debugger's willingness to use watchpoint hardware."), _("\
8463 If zero, gdb will not use hardware for new watchpoints, even if\n\
8464 such is available. (However, any hardware watchpoints that were\n\
8465 created before setting this to nonzero, will continue to use watchpoint\n\
8468 show_can_use_hw_watchpoints
,
8469 &setlist
, &showlist
);
8471 can_use_hw_watchpoints
= 1;
8473 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8474 Breakpoint specific settings\n\
8475 Configure various breakpoint-specific variables such as\n\
8476 pending breakpoint behavior"),
8477 &breakpoint_set_cmdlist
, "set breakpoint ",
8478 0/*allow-unknown*/, &setlist
);
8479 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8480 Breakpoint specific settings\n\
8481 Configure various breakpoint-specific variables such as\n\
8482 pending breakpoint behavior"),
8483 &breakpoint_show_cmdlist
, "show breakpoint ",
8484 0/*allow-unknown*/, &showlist
);
8486 add_setshow_auto_boolean_cmd ("pending", no_class
,
8487 &pending_break_support
, _("\
8488 Set debugger's behavior regarding pending breakpoints."), _("\
8489 Show debugger's behavior regarding pending breakpoints."), _("\
8490 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8491 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8492 an error. If auto, an unrecognized breakpoint location results in a\n\
8493 user-query to see if a pending breakpoint should be created."),
8495 show_pending_break_support
,
8496 &breakpoint_set_cmdlist
,
8497 &breakpoint_show_cmdlist
);
8499 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8501 add_setshow_boolean_cmd ("auto-hw", no_class
,
8502 &automatic_hardware_breakpoints
, _("\
8503 Set automatic usage of hardware breakpoints."), _("\
8504 Show automatic usage of hardware breakpoints."), _("\
8505 If set, the debugger will automatically use hardware breakpoints for\n\
8506 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8507 a warning will be emitted for such breakpoints."),
8509 show_automatic_hardware_breakpoints
,
8510 &breakpoint_set_cmdlist
,
8511 &breakpoint_show_cmdlist
);
8513 add_setshow_enum_cmd ("always-inserted", class_support
,
8514 always_inserted_enums
, &always_inserted_mode
, _("\
8515 Set mode for inserting breakpoints."), _("\
8516 Show mode for inserting breakpoints."), _("\
8517 When this mode is off, breakpoints are inserted in inferior when it is\n\
8518 resumed, and removed when execution stops. When this mode is on,\n\
8519 breakpoints are inserted immediately and removed only when the user\n\
8520 deletes the breakpoint. When this mode is auto (which is the default),\n\
8521 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8522 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8523 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8524 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8526 &show_always_inserted_mode
,
8527 &breakpoint_set_cmdlist
,
8528 &breakpoint_show_cmdlist
);
8530 automatic_hardware_breakpoints
= 1;
8532 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);