1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
61 #include "mi/mi-common.h"
63 /* Arguments to pass as context to some catch command handlers. */
64 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
65 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
67 /* Prototypes for local functions. */
69 static void enable_delete_command (char *, int);
71 static void enable_delete_breakpoint (struct breakpoint
*);
73 static void enable_once_command (char *, int);
75 static void enable_once_breakpoint (struct breakpoint
*);
77 static void disable_command (char *, int);
79 static void enable_command (char *, int);
81 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
83 static void ignore_command (char *, int);
85 static int breakpoint_re_set_one (void *);
87 static void clear_command (char *, int);
89 static void catch_command (char *, int);
91 static void watch_command (char *, int);
93 static int can_use_hardware_watchpoint (struct value
*);
95 static void break_command_1 (char *, int, int);
97 static void mention (struct breakpoint
*);
99 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
101 static void check_duplicates (struct breakpoint
*);
103 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
105 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
108 static void describe_other_breakpoints (CORE_ADDR
, struct obj_section
*, int);
110 static void breakpoints_info (char *, int);
112 static void breakpoint_1 (int, int);
114 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
116 static int breakpoint_cond_eval (void *);
118 static void cleanup_executing_breakpoints (void *);
120 static void commands_command (char *, int);
122 static void condition_command (char *, int);
124 static int get_number_trailer (char **, int);
126 void set_breakpoint_count (int);
135 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
137 static enum print_stop_action
print_it_typical (bpstat
);
139 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 static int watchpoint_check (void *);
143 static void maintenance_info_breakpoints (char *, int);
145 static void create_overlay_event_breakpoint (char *);
147 static int hw_breakpoint_used_count (void);
149 static int hw_watchpoint_used_count (enum bptype
, int *);
151 static void hbreak_command (char *, int);
153 static void thbreak_command (char *, int);
155 static void watch_command_1 (char *, int, int);
157 static void rwatch_command (char *, int);
159 static void awatch_command (char *, int);
161 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
163 static void stop_command (char *arg
, int from_tty
);
165 static void stopin_command (char *arg
, int from_tty
);
167 static void stopat_command (char *arg
, int from_tty
);
169 static char *ep_parse_optional_if_clause (char **arg
);
171 static char *ep_parse_optional_filename (char **arg
);
173 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
174 char *arg
, int tempflag
, int from_tty
);
176 static void tcatch_command (char *arg
, int from_tty
);
178 static void ep_skip_leading_whitespace (char **s
);
180 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
182 static void free_bp_location (struct bp_location
*loc
);
184 static struct bp_location
*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);
195 bpdisp_text (enum bpdisp disp
)
197 /* NOTE: the following values are a part of MI protocol and represent
198 values of 'disp' field returned when inferior stops at a breakpoint. */
199 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
200 return bpdisps
[(int) disp
];
203 /* Prototypes for exported functions. */
204 /* If FALSE, gdb will not use hardware support for watchpoints, even
205 if such is available. */
206 static int can_use_hw_watchpoints
;
209 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
210 struct cmd_list_element
*c
,
213 fprintf_filtered (file
, _("\
214 Debugger's willingness to use watchpoint hardware is %s.\n"),
218 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
219 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
220 for unrecognized breakpoint locations.
221 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
222 static enum auto_boolean pending_break_support
;
224 show_pending_break_support (struct ui_file
*file
, int from_tty
,
225 struct cmd_list_element
*c
,
228 fprintf_filtered (file
, _("\
229 Debugger's behavior regarding pending breakpoints is %s.\n"),
233 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
234 set with "break" but falling in read-only memory.
235 If 0, gdb will warn about such breakpoints, but won't automatically
236 use hardware breakpoints. */
237 static int automatic_hardware_breakpoints
;
239 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
240 struct cmd_list_element
*c
,
243 fprintf_filtered (file
, _("\
244 Automatic usage of hardware breakpoints is %s.\n"),
248 /* If on, gdb will keep breakpoints inserted even as inferior is
249 stopped, and immediately insert any new breakpoints. If off, gdb
250 will insert breakpoints into inferior only when resuming it, and
251 will remove breakpoints upon stop. If auto, GDB will behave as ON
252 if in non-stop mode, and as OFF if all-stop mode.*/
254 static const char always_inserted_auto
[] = "auto";
255 static const char always_inserted_on
[] = "on";
256 static const char always_inserted_off
[] = "off";
257 static const char *always_inserted_enums
[] = {
258 always_inserted_auto
,
263 static const char *always_inserted_mode
= always_inserted_auto
;
265 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
266 struct cmd_list_element
*c
, const char *value
)
268 if (always_inserted_mode
== always_inserted_auto
)
269 fprintf_filtered (file
, _("\
270 Always inserted breakpoint mode is %s (currently %s).\n"),
272 breakpoints_always_inserted_mode () ? "on" : "off");
274 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
278 breakpoints_always_inserted_mode (void)
280 return (always_inserted_mode
== always_inserted_on
281 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
284 void _initialize_breakpoint (void);
286 /* Are we executing breakpoint commands? */
287 static int executing_breakpoint_commands
;
289 /* Are overlay event breakpoints enabled? */
290 static int overlay_events_enabled
;
292 /* Walk the following statement or block through all breakpoints.
293 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
296 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
298 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
299 for (B = breakpoint_chain; \
300 B ? (TMP=B->next, 1): 0; \
303 /* Similar iterators for the low-level breakpoints. */
305 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
307 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
308 for (B = bp_location_chain; \
309 B ? (TMP=B->global_next, 1): 0; \
312 /* Chains of all breakpoints defined. */
314 struct breakpoint
*breakpoint_chain
;
316 struct bp_location
*bp_location_chain
;
318 /* The locations that no longer correspond to any breakpoint,
319 unlinked from bp_location_chain, but for which a hit
320 may still be reported by a target. */
321 VEC(bp_location_p
) *moribund_locations
= NULL
;
323 /* Number of last breakpoint made. */
325 int breakpoint_count
;
327 /* Return whether a breakpoint is an active enabled breakpoint. */
329 breakpoint_enabled (struct breakpoint
*b
)
331 return (b
->enable_state
== bp_enabled
);
334 /* Set breakpoint count to NUM. */
337 set_breakpoint_count (int num
)
339 breakpoint_count
= num
;
340 set_internalvar (lookup_internalvar ("bpnum"),
341 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
344 /* Used in run_command to zero the hit count when a new run starts. */
347 clear_breakpoint_hit_counts (void)
349 struct breakpoint
*b
;
355 /* Default address, symtab and line to put a breakpoint at
356 for "break" command with no arg.
357 if default_breakpoint_valid is zero, the other three are
358 not valid, and "break" with no arg is an error.
360 This set by print_stack_frame, which calls set_default_breakpoint. */
362 int default_breakpoint_valid
;
363 CORE_ADDR default_breakpoint_address
;
364 struct symtab
*default_breakpoint_symtab
;
365 int default_breakpoint_line
;
367 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
368 Advance *PP after the string and any trailing whitespace.
370 Currently the string can either be a number or "$" followed by the name
371 of a convenience variable. Making it an expression wouldn't work well
372 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
374 If the string is a NULL pointer, that denotes the last breakpoint.
376 TRAILER is a character which can be found after the number; most
377 commonly this is `-'. If you don't want a trailer, use \0. */
379 get_number_trailer (char **pp
, int trailer
)
381 int retval
= 0; /* default */
385 /* Empty line means refer to the last breakpoint. */
386 return breakpoint_count
;
389 /* Make a copy of the name, so we can null-terminate it
390 to pass to lookup_internalvar(). */
395 while (isalnum (*p
) || *p
== '_')
397 varname
= (char *) alloca (p
- start
+ 1);
398 strncpy (varname
, start
, p
- start
);
399 varname
[p
- start
] = '\0';
400 val
= value_of_internalvar (lookup_internalvar (varname
));
401 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
402 retval
= (int) value_as_long (val
);
405 printf_filtered (_("Convenience variable must have integer value.\n"));
413 while (*p
>= '0' && *p
<= '9')
416 /* There is no number here. (e.g. "cond a == b"). */
418 /* Skip non-numeric token */
419 while (*p
&& !isspace((int) *p
))
421 /* Return zero, which caller must interpret as error. */
427 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
429 /* Trailing junk: return 0 and let caller print error msg. */
430 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
441 /* Like get_number_trailer, but don't allow a trailer. */
443 get_number (char **pp
)
445 return get_number_trailer (pp
, '\0');
448 /* Parse a number or a range.
449 * A number will be of the form handled by get_number.
450 * A range will be of the form <number1> - <number2>, and
451 * will represent all the integers between number1 and number2,
454 * While processing a range, this fuction is called iteratively;
455 * At each call it will return the next value in the range.
457 * At the beginning of parsing a range, the char pointer PP will
458 * be advanced past <number1> and left pointing at the '-' token.
459 * Subsequent calls will not advance the pointer until the range
460 * is completed. The call that completes the range will advance
461 * pointer PP past <number2>.
465 get_number_or_range (char **pp
)
467 static int last_retval
, end_value
;
468 static char *end_ptr
;
469 static int in_range
= 0;
473 /* Default case: pp is pointing either to a solo number,
474 or to the first number of a range. */
475 last_retval
= get_number_trailer (pp
, '-');
480 /* This is the start of a range (<number1> - <number2>).
481 Skip the '-', parse and remember the second number,
482 and also remember the end of the final token. */
486 while (isspace ((int) *end_ptr
))
487 end_ptr
++; /* skip white space */
488 end_value
= get_number (temp
);
489 if (end_value
< last_retval
)
491 error (_("inverted range"));
493 else if (end_value
== last_retval
)
495 /* degenerate range (number1 == number2). Advance the
496 token pointer so that the range will be treated as a
505 error (_("negative value"));
508 /* pp points to the '-' that betokens a range. All
509 number-parsing has already been done. Return the next
510 integer value (one greater than the saved previous value).
511 Do not advance the token pointer 'pp' until the end of range
514 if (++last_retval
== end_value
)
516 /* End of range reached; advance token pointer. */
526 /* condition N EXP -- set break condition of breakpoint N to EXP. */
529 condition_command (char *arg
, int from_tty
)
531 struct breakpoint
*b
;
536 error_no_arg (_("breakpoint number"));
539 bnum
= get_number (&p
);
541 error (_("Bad breakpoint argument: '%s'"), arg
);
544 if (b
->number
== bnum
)
546 struct bp_location
*loc
= b
->loc
;
547 for (; loc
; loc
= loc
->next
)
555 if (b
->cond_string
!= NULL
)
556 xfree (b
->cond_string
);
560 b
->cond_string
= NULL
;
562 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
567 /* I don't know if it matters whether this is the string the user
568 typed in or the decompiled expression. */
569 b
->cond_string
= savestring (arg
, strlen (arg
));
570 b
->condition_not_parsed
= 0;
571 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
575 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
577 error (_("Junk at end of expression"));
580 breakpoints_changed ();
581 observer_notify_breakpoint_modified (b
->number
);
585 error (_("No breakpoint number %d."), bnum
);
589 commands_command (char *arg
, int from_tty
)
591 struct breakpoint
*b
;
594 struct command_line
*l
;
596 /* If we allowed this, we would have problems with when to
597 free the storage, if we change the commands currently
600 if (executing_breakpoint_commands
)
601 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
604 bnum
= get_number (&p
);
607 error (_("Unexpected extra arguments following breakpoint number."));
610 if (b
->number
== bnum
)
612 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
614 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
615 l
= read_command_lines (tmpbuf
, from_tty
, 1);
616 do_cleanups (cleanups
);
617 free_command_lines (&b
->commands
);
619 breakpoints_changed ();
620 observer_notify_breakpoint_modified (b
->number
);
623 error (_("No breakpoint number %d."), bnum
);
626 /* Like commands_command, but instead of reading the commands from
627 input stream, takes them from an already parsed command structure.
629 This is used by cli-script.c to DTRT with breakpoint commands
630 that are part of if and while bodies. */
631 enum command_control_type
632 commands_from_control_command (char *arg
, struct command_line
*cmd
)
634 struct breakpoint
*b
;
638 /* If we allowed this, we would have problems with when to
639 free the storage, if we change the commands currently
642 if (executing_breakpoint_commands
)
643 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
645 /* An empty string for the breakpoint number means the last
646 breakpoint, but get_number expects a NULL pointer. */
651 bnum
= get_number (&p
);
654 error (_("Unexpected extra arguments following breakpoint number."));
657 if (b
->number
== bnum
)
659 free_command_lines (&b
->commands
);
660 if (cmd
->body_count
!= 1)
661 error (_("Invalid \"commands\" block structure."));
662 /* We need to copy the commands because if/while will free the
663 list after it finishes execution. */
664 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
665 breakpoints_changed ();
666 observer_notify_breakpoint_modified (b
->number
);
667 return simple_control
;
669 error (_("No breakpoint number %d."), bnum
);
672 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
673 by replacing any memory breakpoints with their shadowed contents. */
676 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
678 struct bp_location
*b
;
679 CORE_ADDR bp_addr
= 0;
685 if (b
->owner
->type
== bp_none
)
686 warning (_("reading through apparently deleted breakpoint #%d?"),
689 if (b
->loc_type
!= bp_loc_software_breakpoint
)
693 /* Addresses and length of the part of the breakpoint that
695 bp_addr
= b
->target_info
.placed_address
;
696 bp_size
= b
->target_info
.shadow_len
;
698 /* bp isn't valid, or doesn't shadow memory. */
701 if (bp_addr
+ bp_size
<= memaddr
)
702 /* The breakpoint is entirely before the chunk of memory we
706 if (bp_addr
>= memaddr
+ len
)
707 /* The breakpoint is entirely after the chunk of memory we are
711 /* Offset within shadow_contents. */
712 if (bp_addr
< memaddr
)
714 /* Only copy the second part of the breakpoint. */
715 bp_size
-= memaddr
- bp_addr
;
716 bptoffset
= memaddr
- bp_addr
;
720 if (bp_addr
+ bp_size
> memaddr
+ len
)
722 /* Only copy the first part of the breakpoint. */
723 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
726 memcpy (buf
+ bp_addr
- memaddr
,
727 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
732 /* A wrapper function for inserting catchpoints. */
734 insert_catchpoint (struct ui_out
*uo
, void *args
)
736 struct breakpoint
*b
= (struct breakpoint
*) args
;
739 gdb_assert (b
->type
== bp_catchpoint
);
740 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
746 is_hardware_watchpoint (struct breakpoint
*bpt
)
748 return (bpt
->type
== bp_hardware_watchpoint
749 || bpt
->type
== bp_read_watchpoint
750 || bpt
->type
== bp_access_watchpoint
);
753 /* Find the current value of a watchpoint on EXP. Return the value in
754 *VALP and *RESULTP and the chain of intermediate and final values
755 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
758 If an error occurs while evaluating the expression, *RESULTP will
759 be set to NULL. *RESULTP may be a lazy value, if the result could
760 not be read from memory. It is used to determine whether a value
761 is user-specified (we should watch the whole value) or intermediate
762 (we should watch only the bit used to locate the final value).
764 If the final value, or any intermediate value, could not be read
765 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
766 set to any referenced values. *VALP will never be a lazy value.
767 This is the value which we store in struct breakpoint.
769 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
770 value chain. The caller must free the values individually. If
771 VAL_CHAIN is NULL, all generated values will be left on the value
775 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
776 struct value
**resultp
, struct value
**val_chain
)
778 struct value
*mark
, *new_mark
, *result
;
786 /* Evaluate the expression. */
787 mark
= value_mark ();
789 gdb_evaluate_expression (exp
, &result
);
790 new_mark
= value_mark ();
791 if (mark
== new_mark
)
796 /* Make sure it's not lazy, so that after the target stops again we
797 have a non-lazy previous value to compare with. */
799 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
804 /* Return the chain of intermediate values. We use this to
805 decide which addresses to watch. */
806 *val_chain
= new_mark
;
807 value_release_to_mark (mark
);
811 /* Assuming that B is a hardware watchpoint:
812 - Reparse watchpoint expression, is REPARSE is non-zero
813 - Evaluate expression and store the result in B->val
814 - Update the list of values that must be watched in B->loc.
816 If the watchpoint is disabled, do nothing. If this is
817 local watchpoint that is out of scope, delete it. */
819 update_watchpoint (struct breakpoint
*b
, int reparse
)
821 int within_current_scope
;
822 struct frame_id saved_frame_id
;
823 struct bp_location
*loc
;
826 /* We don't free locations. They are stored in
827 bp_location_chain and update_global_locations will
828 eventually delete them and remove breakpoints if
832 if (b
->disposition
== disp_del_at_next_stop
)
835 /* Save the current frame's ID so we can restore it after
836 evaluating the watchpoint expression on its own frame. */
837 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
838 took a frame parameter, so that we didn't have to change the
840 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
842 /* Determine if the watchpoint is within scope. */
843 if (b
->exp_valid_block
== NULL
)
844 within_current_scope
= 1;
847 struct frame_info
*fi
;
848 fi
= frame_find_by_id (b
->watchpoint_frame
);
849 within_current_scope
= (fi
!= NULL
);
850 if (within_current_scope
)
854 if (within_current_scope
&& reparse
)
863 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
864 /* If the meaning of expression itself changed, the old value is
865 no longer relevant. We don't want to report a watchpoint hit
866 to the user when the old value and the new value may actually
867 be completely different objects. */
873 /* If we failed to parse the expression, for example because
874 it refers to a global variable in a not-yet-loaded shared library,
875 don't try to insert watchpoint. We don't automatically delete
876 such watchpoint, though, since failure to parse expression
877 is different from out-of-scope watchpoint. */
878 if (within_current_scope
&& b
->exp
)
880 struct value
*val_chain
, *v
, *result
, *next
;
882 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
884 /* Avoid setting b->val if it's already set. The meaning of
885 b->val is 'the last value' user saw, and we should update
886 it only if we reported that last value to user. As it
887 happens, the code that reports it updates b->val directly. */
894 /* Look at each value on the value chain. */
895 for (v
= val_chain
; v
; v
= next
)
897 /* If it's a memory location, and GDB actually needed
898 its contents to evaluate the expression, then we
899 must watch it. If the first value returned is
900 still lazy, that means an error occurred reading it;
901 watch it anyway in case it becomes readable. */
902 if (VALUE_LVAL (v
) == lval_memory
903 && (v
== val_chain
|| ! value_lazy (v
)))
905 struct type
*vtype
= check_typedef (value_type (v
));
907 /* We only watch structs and arrays if user asked
908 for it explicitly, never if they just happen to
909 appear in the middle of some value chain. */
911 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
912 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
916 struct bp_location
*loc
, **tmp
;
918 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
919 len
= TYPE_LENGTH (value_type (v
));
921 if (b
->type
== bp_read_watchpoint
)
923 else if (b
->type
== bp_access_watchpoint
)
926 loc
= allocate_bp_location (b
);
927 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
932 loc
->watchpoint_type
= type
;
936 next
= value_next (v
);
941 /* We just regenerated the list of breakpoint locations.
942 The new location does not have its condition field set to anything
943 and therefore, we must always reparse the cond_string, independently
944 of the value of the reparse flag. */
945 if (b
->cond_string
!= NULL
)
947 char *s
= b
->cond_string
;
948 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
951 else if (!within_current_scope
)
953 printf_filtered (_("\
954 Hardware watchpoint %d deleted because the program has left the block \n\
955 in which its expression is valid.\n"),
957 if (b
->related_breakpoint
)
958 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
959 b
->disposition
= disp_del_at_next_stop
;
962 /* Restore the selected frame. */
963 select_frame (frame_find_by_id (saved_frame_id
));
967 /* Returns 1 iff breakpoint location should be
968 inserted in the inferior. */
970 should_be_inserted (struct bp_location
*bpt
)
972 if (!breakpoint_enabled (bpt
->owner
))
975 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
978 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
984 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
985 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
986 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
988 NOTE drow/2003-09-09: This routine could be broken down to an object-style
989 method for each breakpoint or catchpoint type. */
991 insert_bp_location (struct bp_location
*bpt
,
992 struct ui_file
*tmp_error_stream
,
993 int *disabled_breaks
, int *process_warning
,
994 int *hw_breakpoint_error
)
998 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1001 /* Initialize the target-specific information. */
1002 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1003 bpt
->target_info
.placed_address
= bpt
->address
;
1005 if (bpt
->loc_type
== bp_loc_software_breakpoint
1006 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1008 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1010 /* If the explicitly specified breakpoint type
1011 is not hardware breakpoint, check the memory map to see
1012 if the breakpoint address is in read only memory or not.
1013 Two important cases are:
1014 - location type is not hardware breakpoint, memory
1015 is readonly. We change the type of the location to
1016 hardware breakpoint.
1017 - location type is hardware breakpoint, memory is read-write.
1018 This means we've previously made the location hardware one, but
1019 then the memory map changed, so we undo.
1021 When breakpoints are removed, remove_breakpoints will
1022 use location types we've just set here, the only possible
1023 problem is that memory map has changed during running program,
1024 but it's not going to work anyway with current gdb. */
1025 struct mem_region
*mr
1026 = lookup_mem_region (bpt
->target_info
.placed_address
);
1030 if (automatic_hardware_breakpoints
)
1033 enum bp_loc_type new_type
;
1035 if (mr
->attrib
.mode
!= MEM_RW
)
1036 new_type
= bp_loc_hardware_breakpoint
;
1038 new_type
= bp_loc_software_breakpoint
;
1040 if (new_type
!= bpt
->loc_type
)
1042 static int said
= 0;
1043 bpt
->loc_type
= new_type
;
1046 fprintf_filtered (gdb_stdout
, _("\
1047 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1052 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1053 && mr
->attrib
.mode
!= MEM_RW
)
1054 warning (_("cannot set software breakpoint at readonly address %s"),
1055 paddr (bpt
->address
));
1059 /* First check to see if we have to handle an overlay. */
1060 if (overlay_debugging
== ovly_off
1061 || bpt
->section
== NULL
1062 || !(section_is_overlay (bpt
->section
)))
1064 /* No overlay handling: just set the breakpoint. */
1066 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1067 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1069 val
= target_insert_breakpoint (&bpt
->target_info
);
1073 /* This breakpoint is in an overlay section.
1074 Shall we set a breakpoint at the LMA? */
1075 if (!overlay_events_enabled
)
1077 /* Yes -- overlay event support is not active,
1078 so we must try to set a breakpoint at the LMA.
1079 This will not work for a hardware breakpoint. */
1080 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1081 warning (_("hardware breakpoint %d not supported in overlay!"),
1082 bpt
->owner
->number
);
1085 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1087 /* Set a software (trap) breakpoint at the LMA. */
1088 bpt
->overlay_target_info
= bpt
->target_info
;
1089 bpt
->overlay_target_info
.placed_address
= addr
;
1090 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1092 fprintf_unfiltered (tmp_error_stream
,
1093 "Overlay breakpoint %d failed: in ROM?",
1094 bpt
->owner
->number
);
1097 /* Shall we set a breakpoint at the VMA? */
1098 if (section_is_mapped (bpt
->section
))
1100 /* Yes. This overlay section is mapped into memory. */
1101 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1102 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1104 val
= target_insert_breakpoint (&bpt
->target_info
);
1108 /* No. This breakpoint will not be inserted.
1109 No error, but do not mark the bp as 'inserted'. */
1116 /* Can't set the breakpoint. */
1117 if (solib_address (bpt
->address
))
1119 /* See also: disable_breakpoints_in_shlibs. */
1121 bpt
->shlib_disabled
= 1;
1122 if (!*disabled_breaks
)
1124 fprintf_unfiltered (tmp_error_stream
,
1125 "Cannot insert breakpoint %d.\n",
1126 bpt
->owner
->number
);
1127 fprintf_unfiltered (tmp_error_stream
,
1128 "Temporarily disabling shared library breakpoints:\n");
1130 *disabled_breaks
= 1;
1131 fprintf_unfiltered (tmp_error_stream
,
1132 "breakpoint #%d\n", bpt
->owner
->number
);
1136 #ifdef ONE_PROCESS_WRITETEXT
1137 *process_warning
= 1;
1139 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1141 *hw_breakpoint_error
= 1;
1142 fprintf_unfiltered (tmp_error_stream
,
1143 "Cannot insert hardware breakpoint %d.\n",
1144 bpt
->owner
->number
);
1148 fprintf_unfiltered (tmp_error_stream
,
1149 "Cannot insert breakpoint %d.\n",
1150 bpt
->owner
->number
);
1151 fprintf_filtered (tmp_error_stream
,
1152 "Error accessing memory address ");
1153 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1154 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1155 safe_strerror (val
));
1166 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1167 /* NOTE drow/2003-09-08: This state only exists for removing
1168 watchpoints. It's not clear that it's necessary... */
1169 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1171 val
= target_insert_watchpoint (bpt
->address
,
1173 bpt
->watchpoint_type
);
1174 bpt
->inserted
= (val
!= -1);
1177 else if (bpt
->owner
->type
== bp_catchpoint
)
1179 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1180 bpt
->owner
, RETURN_MASK_ERROR
);
1181 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1182 bpt
->owner
->number
);
1184 bpt
->owner
->enable_state
= bp_disabled
;
1188 /* We've already printed an error message if there was a problem
1189 inserting this catchpoint, and we've disabled the catchpoint,
1190 so just return success. */
1197 /* Make sure all breakpoints are inserted in inferior.
1198 Throws exception on any error.
1199 A breakpoint that is already inserted won't be inserted
1200 again, so calling this function twice is safe. */
1202 insert_breakpoints (void)
1204 struct breakpoint
*bpt
;
1206 ALL_BREAKPOINTS (bpt
)
1207 if (is_hardware_watchpoint (bpt
))
1208 update_watchpoint (bpt
, 0 /* don't reparse. */);
1210 update_global_location_list (1);
1212 if (!breakpoints_always_inserted_mode ()
1213 && (target_has_execution
1214 || (gdbarch_has_global_solist (target_gdbarch
)
1215 && target_supports_multi_process ())))
1216 /* update_global_location_list does not insert breakpoints
1217 when always_inserted_mode is not enabled. Explicitly
1219 insert_breakpoint_locations ();
1222 /* insert_breakpoints is used when starting or continuing the program.
1223 remove_breakpoints is used when the program stops.
1224 Both return zero if successful,
1225 or an `errno' value if could not write the inferior. */
1228 insert_breakpoint_locations (void)
1230 struct breakpoint
*bpt
;
1231 struct bp_location
*b
, *temp
;
1234 int disabled_breaks
= 0;
1235 int hw_breakpoint_error
= 0;
1236 int process_warning
= 0;
1238 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1239 make_cleanup_ui_file_delete (tmp_error_stream
);
1241 /* Explicitly mark the warning -- this will only be printed if
1242 there was an error. */
1243 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1245 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1247 if (!should_be_inserted (b
) || b
->inserted
)
1250 /* There is no point inserting thread-specific breakpoints if the
1251 thread no longer exists. */
1252 if (b
->owner
->thread
!= -1
1253 && !valid_thread_id (b
->owner
->thread
))
1256 val
= insert_bp_location (b
, tmp_error_stream
,
1257 &disabled_breaks
, &process_warning
,
1258 &hw_breakpoint_error
);
1263 /* If we failed to insert all locations of a watchpoint,
1264 remove them, as half-inserted watchpoint is of limited use. */
1265 ALL_BREAKPOINTS (bpt
)
1267 int some_failed
= 0;
1268 struct bp_location
*loc
;
1270 if (!is_hardware_watchpoint (bpt
))
1273 if (!breakpoint_enabled (bpt
))
1276 if (bpt
->disposition
== disp_del_at_next_stop
)
1279 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1287 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1289 remove_breakpoint (loc
, mark_uninserted
);
1291 hw_breakpoint_error
= 1;
1292 fprintf_unfiltered (tmp_error_stream
,
1293 "Could not insert hardware watchpoint %d.\n",
1301 /* If a hardware breakpoint or watchpoint was inserted, add a
1302 message about possibly exhausted resources. */
1303 if (hw_breakpoint_error
)
1305 fprintf_unfiltered (tmp_error_stream
,
1306 "Could not insert hardware breakpoints:\n\
1307 You may have requested too many hardware breakpoints/watchpoints.\n");
1309 #ifdef ONE_PROCESS_WRITETEXT
1310 if (process_warning
)
1311 fprintf_unfiltered (tmp_error_stream
,
1312 "The same program may be running in another process.");
1314 target_terminal_ours_for_output ();
1315 error_stream (tmp_error_stream
);
1320 remove_breakpoints (void)
1322 struct bp_location
*b
;
1325 ALL_BP_LOCATIONS (b
)
1329 val
= remove_breakpoint (b
, mark_uninserted
);
1338 remove_hw_watchpoints (void)
1340 struct bp_location
*b
;
1343 ALL_BP_LOCATIONS (b
)
1345 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1347 val
= remove_breakpoint (b
, mark_uninserted
);
1356 reattach_breakpoints (int pid
)
1358 struct bp_location
*b
;
1360 struct cleanup
*old_chain
= save_inferior_ptid ();
1361 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1362 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1364 make_cleanup_ui_file_delete (tmp_error_stream
);
1366 inferior_ptid
= pid_to_ptid (pid
);
1367 ALL_BP_LOCATIONS (b
)
1372 val
= insert_bp_location (b
, tmp_error_stream
,
1373 &dummy1
, &dummy2
, &dummy3
);
1376 do_cleanups (old_chain
);
1381 do_cleanups (old_chain
);
1386 update_breakpoints_after_exec (void)
1388 struct breakpoint
*b
;
1389 struct breakpoint
*temp
;
1390 struct bp_location
*bploc
;
1392 /* We're about to delete breakpoints from GDB's lists. If the
1393 INSERTED flag is true, GDB will try to lift the breakpoints by
1394 writing the breakpoints' "shadow contents" back into memory. The
1395 "shadow contents" are NOT valid after an exec, so GDB should not
1396 do that. Instead, the target is responsible from marking
1397 breakpoints out as soon as it detects an exec. We don't do that
1398 here instead, because there may be other attempts to delete
1399 breakpoints after detecting an exec and before reaching here. */
1400 ALL_BP_LOCATIONS (bploc
)
1401 gdb_assert (!bploc
->inserted
);
1403 ALL_BREAKPOINTS_SAFE (b
, temp
)
1405 /* Solib breakpoints must be explicitly reset after an exec(). */
1406 if (b
->type
== bp_shlib_event
)
1408 delete_breakpoint (b
);
1412 /* Thread event breakpoints must be set anew after an exec(),
1413 as must overlay event breakpoints. */
1414 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1416 delete_breakpoint (b
);
1420 /* Step-resume breakpoints are meaningless after an exec(). */
1421 if (b
->type
== bp_step_resume
)
1423 delete_breakpoint (b
);
1427 /* Longjmp and longjmp-resume breakpoints are also meaningless
1429 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1431 delete_breakpoint (b
);
1435 if (b
->type
== bp_catchpoint
)
1437 /* For now, none of the bp_catchpoint breakpoints need to
1438 do anything at this point. In the future, if some of
1439 the catchpoints need to something, we will need to add
1440 a new method, and call this method from here. */
1444 /* bp_finish is a special case. The only way we ought to be able
1445 to see one of these when an exec() has happened, is if the user
1446 caught a vfork, and then said "finish". Ordinarily a finish just
1447 carries them to the call-site of the current callee, by setting
1448 a temporary bp there and resuming. But in this case, the finish
1449 will carry them entirely through the vfork & exec.
1451 We don't want to allow a bp_finish to remain inserted now. But
1452 we can't safely delete it, 'cause finish_command has a handle to
1453 the bp on a bpstat, and will later want to delete it. There's a
1454 chance (and I've seen it happen) that if we delete the bp_finish
1455 here, that its storage will get reused by the time finish_command
1456 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1457 We really must allow finish_command to delete a bp_finish.
1459 In the absense of a general solution for the "how do we know
1460 it's safe to delete something others may have handles to?"
1461 problem, what we'll do here is just uninsert the bp_finish, and
1462 let finish_command delete it.
1464 (We know the bp_finish is "doomed" in the sense that it's
1465 momentary, and will be deleted as soon as finish_command sees
1466 the inferior stopped. So it doesn't matter that the bp's
1467 address is probably bogus in the new a.out, unlike e.g., the
1468 solib breakpoints.) */
1470 if (b
->type
== bp_finish
)
1475 /* Without a symbolic address, we have little hope of the
1476 pre-exec() address meaning the same thing in the post-exec()
1478 if (b
->addr_string
== NULL
)
1480 delete_breakpoint (b
);
1484 /* FIXME what about longjmp breakpoints? Re-create them here? */
1485 create_overlay_event_breakpoint ("_ovly_debug_event");
1489 detach_breakpoints (int pid
)
1491 struct bp_location
*b
;
1493 struct cleanup
*old_chain
= save_inferior_ptid ();
1495 if (pid
== PIDGET (inferior_ptid
))
1496 error (_("Cannot detach breakpoints of inferior_ptid"));
1498 /* Set inferior_ptid; remove_breakpoint uses this global. */
1499 inferior_ptid
= pid_to_ptid (pid
);
1500 ALL_BP_LOCATIONS (b
)
1504 val
= remove_breakpoint (b
, mark_inserted
);
1507 do_cleanups (old_chain
);
1512 do_cleanups (old_chain
);
1517 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1521 if (b
->owner
->enable_state
== bp_permanent
)
1522 /* Permanent breakpoints cannot be inserted or removed. */
1525 /* The type of none suggests that owner is actually deleted.
1526 This should not ever happen. */
1527 gdb_assert (b
->owner
->type
!= bp_none
);
1529 if (b
->loc_type
== bp_loc_software_breakpoint
1530 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1532 /* "Normal" instruction breakpoint: either the standard
1533 trap-instruction bp (bp_breakpoint), or a
1534 bp_hardware_breakpoint. */
1536 /* First check to see if we have to handle an overlay. */
1537 if (overlay_debugging
== ovly_off
1538 || b
->section
== NULL
1539 || !(section_is_overlay (b
->section
)))
1541 /* No overlay handling: just remove the breakpoint. */
1543 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1544 val
= target_remove_hw_breakpoint (&b
->target_info
);
1546 val
= target_remove_breakpoint (&b
->target_info
);
1550 /* This breakpoint is in an overlay section.
1551 Did we set a breakpoint at the LMA? */
1552 if (!overlay_events_enabled
)
1554 /* Yes -- overlay event support is not active, so we
1555 should have set a breakpoint at the LMA. Remove it.
1557 /* Ignore any failures: if the LMA is in ROM, we will
1558 have already warned when we failed to insert it. */
1559 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1560 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1562 target_remove_breakpoint (&b
->overlay_target_info
);
1564 /* Did we set a breakpoint at the VMA?
1565 If so, we will have marked the breakpoint 'inserted'. */
1568 /* Yes -- remove it. Previously we did not bother to
1569 remove the breakpoint if the section had been
1570 unmapped, but let's not rely on that being safe. We
1571 don't know what the overlay manager might do. */
1572 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1573 val
= target_remove_hw_breakpoint (&b
->target_info
);
1575 /* However, we should remove *software* breakpoints only
1576 if the section is still mapped, or else we overwrite
1577 wrong code with the saved shadow contents. */
1578 else if (section_is_mapped (b
->section
))
1579 val
= target_remove_breakpoint (&b
->target_info
);
1585 /* No -- not inserted, so no need to remove. No error. */
1590 /* In some cases, we might not be able to remove a breakpoint
1591 in a shared library that has already been removed, but we
1592 have not yet processed the shlib unload event. */
1593 if (val
&& solib_address (b
->address
))
1598 b
->inserted
= (is
== mark_inserted
);
1600 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1605 b
->inserted
= (is
== mark_inserted
);
1606 val
= target_remove_watchpoint (b
->address
, b
->length
,
1607 b
->watchpoint_type
);
1609 /* Failure to remove any of the hardware watchpoints comes here. */
1610 if ((is
== mark_uninserted
) && (b
->inserted
))
1611 warning (_("Could not remove hardware watchpoint %d."),
1614 else if (b
->owner
->type
== bp_catchpoint
1615 && breakpoint_enabled (b
->owner
)
1618 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1620 val
= b
->owner
->ops
->remove (b
->owner
);
1623 b
->inserted
= (is
== mark_inserted
);
1629 /* Clear the "inserted" flag in all breakpoints. */
1632 mark_breakpoints_out (void)
1634 struct bp_location
*bpt
;
1636 ALL_BP_LOCATIONS (bpt
)
1640 /* Clear the "inserted" flag in all breakpoints and delete any
1641 breakpoints which should go away between runs of the program.
1643 Plus other such housekeeping that has to be done for breakpoints
1646 Note: this function gets called at the end of a run (by
1647 generic_mourn_inferior) and when a run begins (by
1648 init_wait_for_inferior). */
1653 breakpoint_init_inferior (enum inf_context context
)
1655 struct breakpoint
*b
, *temp
;
1656 struct bp_location
*bpt
;
1659 /* If breakpoint locations are shared across processes, then there's
1661 if (gdbarch_has_global_solist (target_gdbarch
))
1664 ALL_BP_LOCATIONS (bpt
)
1665 if (bpt
->owner
->enable_state
!= bp_permanent
)
1668 ALL_BREAKPOINTS_SAFE (b
, temp
)
1673 case bp_watchpoint_scope
:
1675 /* If the call dummy breakpoint is at the entry point it will
1676 cause problems when the inferior is rerun, so we better
1679 Also get rid of scope breakpoints. */
1680 delete_breakpoint (b
);
1684 case bp_hardware_watchpoint
:
1685 case bp_read_watchpoint
:
1686 case bp_access_watchpoint
:
1688 /* Likewise for watchpoints on local expressions. */
1689 if (b
->exp_valid_block
!= NULL
)
1690 delete_breakpoint (b
);
1691 else if (context
== inf_starting
)
1693 /* Reset val field to force reread of starting value
1694 in insert_breakpoints. */
1696 value_free (b
->val
);
1706 /* Get rid of the moribund locations. */
1707 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1708 free_bp_location (bpt
);
1709 VEC_free (bp_location_p
, moribund_locations
);
1712 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1713 exists at PC. It returns ordinary_breakpoint_here if it's an
1714 ordinary breakpoint, or permanent_breakpoint_here if it's a
1715 permanent breakpoint.
1716 - When continuing from a location with an ordinary breakpoint, we
1717 actually single step once before calling insert_breakpoints.
1718 - When continuing from a localion with a permanent breakpoint, we
1719 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1720 the target, to advance the PC past the breakpoint. */
1722 enum breakpoint_here
1723 breakpoint_here_p (CORE_ADDR pc
)
1725 const struct bp_location
*bpt
;
1726 int any_breakpoint_here
= 0;
1728 ALL_BP_LOCATIONS (bpt
)
1730 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1731 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1734 if ((breakpoint_enabled (bpt
->owner
)
1735 || bpt
->owner
->enable_state
== bp_permanent
)
1736 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1738 if (overlay_debugging
1739 && section_is_overlay (bpt
->section
)
1740 && !section_is_mapped (bpt
->section
))
1741 continue; /* unmapped overlay -- can't be a match */
1742 else if (bpt
->owner
->enable_state
== bp_permanent
)
1743 return permanent_breakpoint_here
;
1745 any_breakpoint_here
= 1;
1749 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1752 /* Return true if there's a moribund breakpoint at PC. */
1755 moribund_breakpoint_here_p (CORE_ADDR pc
)
1757 struct bp_location
*loc
;
1760 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1761 if (loc
->address
== pc
)
1767 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1768 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1769 This does not check for single-step breakpoints, which are
1770 inserted and removed using direct target manipulation. */
1773 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1775 const struct bp_location
*bpt
;
1777 ALL_BP_LOCATIONS (bpt
)
1779 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1780 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1784 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1786 if (overlay_debugging
1787 && section_is_overlay (bpt
->section
)
1788 && !section_is_mapped (bpt
->section
))
1789 continue; /* unmapped overlay -- can't be a match */
1797 /* Returns non-zero iff there's either regular breakpoint
1798 or a single step breakpoint inserted at PC. */
1801 breakpoint_inserted_here_p (CORE_ADDR pc
)
1803 if (regular_breakpoint_inserted_here_p (pc
))
1806 if (single_step_breakpoint_inserted_here_p (pc
))
1812 /* This function returns non-zero iff there is a software breakpoint
1816 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1818 const struct bp_location
*bpt
;
1819 int any_breakpoint_here
= 0;
1821 ALL_BP_LOCATIONS (bpt
)
1823 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1827 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1829 if (overlay_debugging
1830 && section_is_overlay (bpt
->section
)
1831 && !section_is_mapped (bpt
->section
))
1832 continue; /* unmapped overlay -- can't be a match */
1838 /* Also check for software single-step breakpoints. */
1839 if (single_step_breakpoint_inserted_here_p (pc
))
1845 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1846 PC is valid for process/thread PTID. */
1849 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1851 const struct bp_location
*bpt
;
1854 thread
= pid_to_thread_id (ptid
);
1856 ALL_BP_LOCATIONS (bpt
)
1858 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1859 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1862 if ((breakpoint_enabled (bpt
->owner
)
1863 || bpt
->owner
->enable_state
== bp_permanent
)
1864 && bpt
->address
== pc
1865 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1867 if (overlay_debugging
1868 && section_is_overlay (bpt
->section
)
1869 && !section_is_mapped (bpt
->section
))
1870 continue; /* unmapped overlay -- can't be a match */
1880 /* bpstat stuff. External routines' interfaces are documented
1884 ep_is_catchpoint (struct breakpoint
*ep
)
1886 return (ep
->type
== bp_catchpoint
);
1890 bpstat_free (bpstat bs
)
1892 if (bs
->old_val
!= NULL
)
1893 value_free (bs
->old_val
);
1894 free_command_lines (&bs
->commands
);
1898 /* Clear a bpstat so that it says we are not at any breakpoint.
1899 Also free any storage that is part of a bpstat. */
1902 bpstat_clear (bpstat
*bsp
)
1919 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1920 is part of the bpstat is copied as well. */
1923 bpstat_copy (bpstat bs
)
1927 bpstat retval
= NULL
;
1932 for (; bs
!= NULL
; bs
= bs
->next
)
1934 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1935 memcpy (tmp
, bs
, sizeof (*tmp
));
1936 if (bs
->commands
!= NULL
)
1937 tmp
->commands
= copy_command_lines (bs
->commands
);
1938 if (bs
->old_val
!= NULL
)
1940 tmp
->old_val
= value_copy (bs
->old_val
);
1941 release_value (tmp
->old_val
);
1945 /* This is the first thing in the chain. */
1955 /* Find the bpstat associated with this breakpoint */
1958 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1963 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1965 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1971 /* Find a step_resume breakpoint associated with this bpstat.
1972 (If there are multiple step_resume bp's on the list, this function
1973 will arbitrarily pick one.)
1975 It is an error to use this function if BPSTAT doesn't contain a
1976 step_resume breakpoint.
1978 See wait_for_inferior's use of this function. */
1980 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1984 gdb_assert (bsp
!= NULL
);
1986 current_thread
= pid_to_thread_id (inferior_ptid
);
1988 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1990 if ((bsp
->breakpoint_at
!= NULL
) &&
1991 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
1992 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
1993 bsp
->breakpoint_at
->owner
->thread
== -1))
1994 return bsp
->breakpoint_at
->owner
;
1997 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2001 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2002 at. *BSP upon return is a bpstat which points to the remaining
2003 breakpoints stopped at (but which is not guaranteed to be good for
2004 anything but further calls to bpstat_num).
2005 Return 0 if passed a bpstat which does not indicate any breakpoints.
2006 Return -1 if stopped at a breakpoint that has been deleted since
2008 Return 1 otherwise. */
2011 bpstat_num (bpstat
*bsp
, int *num
)
2013 struct breakpoint
*b
;
2016 return 0; /* No more breakpoint values */
2018 /* We assume we'll never have several bpstats that
2019 correspond to a single breakpoint -- otherwise,
2020 this function might return the same number more
2021 than once and this will look ugly. */
2022 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2023 *bsp
= (*bsp
)->next
;
2025 return -1; /* breakpoint that's been deleted since */
2027 *num
= b
->number
; /* We have its number */
2031 /* Modify BS so that the actions will not be performed. */
2034 bpstat_clear_actions (bpstat bs
)
2036 for (; bs
!= NULL
; bs
= bs
->next
)
2038 free_command_lines (&bs
->commands
);
2039 if (bs
->old_val
!= NULL
)
2041 value_free (bs
->old_val
);
2047 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2049 cleanup_executing_breakpoints (void *ignore
)
2051 executing_breakpoint_commands
= 0;
2054 /* Execute all the commands associated with all the breakpoints at this
2055 location. Any of these commands could cause the process to proceed
2056 beyond this point, etc. We look out for such changes by checking
2057 the global "breakpoint_proceeded" after each command.
2059 Returns true if a breakpoint command resumed the inferior. In that
2060 case, it is the caller's responsibility to recall it again with the
2061 bpstat of the current thread. */
2064 bpstat_do_actions_1 (bpstat
*bsp
)
2067 struct cleanup
*old_chain
;
2070 /* Avoid endless recursion if a `source' command is contained
2072 if (executing_breakpoint_commands
)
2075 executing_breakpoint_commands
= 1;
2076 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2078 /* This pointer will iterate over the list of bpstat's. */
2081 breakpoint_proceeded
= 0;
2082 for (; bs
!= NULL
; bs
= bs
->next
)
2084 struct command_line
*cmd
;
2085 struct cleanup
*this_cmd_tree_chain
;
2087 /* Take ownership of the BSP's command tree, if it has one.
2089 The command tree could legitimately contain commands like
2090 'step' and 'next', which call clear_proceed_status, which
2091 frees stop_bpstat's command tree. To make sure this doesn't
2092 free the tree we're executing out from under us, we need to
2093 take ownership of the tree ourselves. Since a given bpstat's
2094 commands are only executed once, we don't need to copy it; we
2095 can clear the pointer in the bpstat, and make sure we free
2096 the tree when we're done. */
2099 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2103 execute_control_command (cmd
);
2105 if (breakpoint_proceeded
)
2111 /* We can free this command tree now. */
2112 do_cleanups (this_cmd_tree_chain
);
2114 if (breakpoint_proceeded
)
2116 if (target_can_async_p ())
2117 /* If we are in async mode, then the target might be still
2118 running, not stopped at any breakpoint, so nothing for
2119 us to do here -- just return to the event loop. */
2122 /* In sync mode, when execute_control_command returns
2123 we're already standing on the next breakpoint.
2124 Breakpoint commands for that stop were not run, since
2125 execute_command does not run breakpoint commands --
2126 only command_line_handler does, but that one is not
2127 involved in execution of breakpoint commands. So, we
2128 can now execute breakpoint commands. It should be
2129 noted that making execute_command do bpstat actions is
2130 not an option -- in this case we'll have recursive
2131 invocation of bpstat for each breakpoint with a
2132 command, and can easily blow up GDB stack. Instead, we
2133 return true, which will trigger the caller to recall us
2134 with the new stop_bpstat. */
2139 do_cleanups (old_chain
);
2144 bpstat_do_actions (void)
2146 /* Do any commands attached to breakpoint we are stopped at. */
2147 while (!ptid_equal (inferior_ptid
, null_ptid
)
2148 && target_has_execution
2149 && !is_exited (inferior_ptid
)
2150 && !is_executing (inferior_ptid
))
2151 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2152 and only return when it is stopped at the next breakpoint, we
2153 keep doing breakpoint actions until it returns false to
2154 indicate the inferior was not resumed. */
2155 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2159 /* Print out the (old or new) value associated with a watchpoint. */
2162 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2165 fprintf_unfiltered (stream
, _("<unreadable>"));
2168 struct value_print_options opts
;
2169 get_user_print_options (&opts
);
2170 value_print (val
, stream
, &opts
);
2174 /* This is the normal print function for a bpstat. In the future,
2175 much of this logic could (should?) be moved to bpstat_stop_status,
2176 by having it set different print_it values.
2178 Current scheme: When we stop, bpstat_print() is called. It loops
2179 through the bpstat list of things causing this stop, calling the
2180 print_bp_stop_message function on each one. The behavior of the
2181 print_bp_stop_message function depends on the print_it field of
2182 bpstat. If such field so indicates, call this function here.
2184 Return values from this routine (ultimately used by bpstat_print()
2185 and normal_stop() to decide what to do):
2186 PRINT_NOTHING: Means we already printed all we needed to print,
2187 don't print anything else.
2188 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2189 that something to be followed by a location.
2190 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2191 that something to be followed by a location.
2192 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2195 static enum print_stop_action
2196 print_it_typical (bpstat bs
)
2198 struct cleanup
*old_chain
, *ui_out_chain
;
2199 struct breakpoint
*b
;
2200 const struct bp_location
*bl
;
2201 struct ui_stream
*stb
;
2203 stb
= ui_out_stream_new (uiout
);
2204 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2205 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2206 which has since been deleted. */
2207 if (bs
->breakpoint_at
== NULL
)
2208 return PRINT_UNKNOWN
;
2209 bl
= bs
->breakpoint_at
;
2215 case bp_hardware_breakpoint
:
2216 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2217 if (bl
->address
!= bl
->requested_address
)
2218 breakpoint_adjustment_warning (bl
->requested_address
,
2221 annotate_breakpoint (b
->number
);
2223 ui_out_text (uiout
, "\nTemporary breakpoint ");
2225 ui_out_text (uiout
, "\nBreakpoint ");
2226 if (ui_out_is_mi_like_p (uiout
))
2228 ui_out_field_string (uiout
, "reason",
2229 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2230 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2232 ui_out_field_int (uiout
, "bkptno", b
->number
);
2233 ui_out_text (uiout
, ", ");
2234 return PRINT_SRC_AND_LOC
;
2237 case bp_shlib_event
:
2238 /* Did we stop because the user set the stop_on_solib_events
2239 variable? (If so, we report this as a generic, "Stopped due
2240 to shlib event" message.) */
2241 printf_filtered (_("Stopped due to shared library event\n"));
2242 return PRINT_NOTHING
;
2245 case bp_thread_event
:
2246 /* Not sure how we will get here.
2247 GDB should not stop for these breakpoints. */
2248 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2249 return PRINT_NOTHING
;
2252 case bp_overlay_event
:
2253 /* By analogy with the thread event, GDB should not stop for these. */
2254 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2255 return PRINT_NOTHING
;
2259 case bp_hardware_watchpoint
:
2260 annotate_watchpoint (b
->number
);
2261 if (ui_out_is_mi_like_p (uiout
))
2264 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2266 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2267 ui_out_text (uiout
, "\nOld value = ");
2268 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2269 ui_out_field_stream (uiout
, "old", stb
);
2270 ui_out_text (uiout
, "\nNew value = ");
2271 watchpoint_value_print (b
->val
, stb
->stream
);
2272 ui_out_field_stream (uiout
, "new", stb
);
2273 do_cleanups (ui_out_chain
);
2274 ui_out_text (uiout
, "\n");
2275 /* More than one watchpoint may have been triggered. */
2276 return PRINT_UNKNOWN
;
2279 case bp_read_watchpoint
:
2280 if (ui_out_is_mi_like_p (uiout
))
2283 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2285 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2286 ui_out_text (uiout
, "\nValue = ");
2287 watchpoint_value_print (b
->val
, stb
->stream
);
2288 ui_out_field_stream (uiout
, "value", stb
);
2289 do_cleanups (ui_out_chain
);
2290 ui_out_text (uiout
, "\n");
2291 return PRINT_UNKNOWN
;
2294 case bp_access_watchpoint
:
2295 if (bs
->old_val
!= NULL
)
2297 annotate_watchpoint (b
->number
);
2298 if (ui_out_is_mi_like_p (uiout
))
2301 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2303 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2304 ui_out_text (uiout
, "\nOld value = ");
2305 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2306 ui_out_field_stream (uiout
, "old", stb
);
2307 ui_out_text (uiout
, "\nNew value = ");
2312 if (ui_out_is_mi_like_p (uiout
))
2315 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2316 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2317 ui_out_text (uiout
, "\nValue = ");
2319 watchpoint_value_print (b
->val
, stb
->stream
);
2320 ui_out_field_stream (uiout
, "new", stb
);
2321 do_cleanups (ui_out_chain
);
2322 ui_out_text (uiout
, "\n");
2323 return PRINT_UNKNOWN
;
2326 /* Fall through, we don't deal with these types of breakpoints
2330 if (ui_out_is_mi_like_p (uiout
))
2333 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2334 return PRINT_UNKNOWN
;
2338 if (ui_out_is_mi_like_p (uiout
))
2341 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2342 return PRINT_UNKNOWN
;
2347 case bp_longjmp_resume
:
2348 case bp_step_resume
:
2349 case bp_watchpoint_scope
:
2352 return PRINT_UNKNOWN
;
2356 /* Generic routine for printing messages indicating why we
2357 stopped. The behavior of this function depends on the value
2358 'print_it' in the bpstat structure. Under some circumstances we
2359 may decide not to print anything here and delegate the task to
2362 static enum print_stop_action
2363 print_bp_stop_message (bpstat bs
)
2365 switch (bs
->print_it
)
2368 /* Nothing should be printed for this bpstat entry. */
2369 return PRINT_UNKNOWN
;
2373 /* We still want to print the frame, but we already printed the
2374 relevant messages. */
2375 return PRINT_SRC_AND_LOC
;
2378 case print_it_normal
:
2380 const struct bp_location
*bl
= bs
->breakpoint_at
;
2381 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2383 /* Normal case. Call the breakpoint's print_it method, or
2384 print_it_typical. */
2385 /* FIXME: how breakpoint can ever be NULL here? */
2386 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2387 return b
->ops
->print_it (b
);
2389 return print_it_typical (bs
);
2394 internal_error (__FILE__
, __LINE__
,
2395 _("print_bp_stop_message: unrecognized enum value"));
2400 /* Print a message indicating what happened. This is called from
2401 normal_stop(). The input to this routine is the head of the bpstat
2402 list - a list of the eventpoints that caused this stop. This
2403 routine calls the generic print routine for printing a message
2404 about reasons for stopping. This will print (for example) the
2405 "Breakpoint n," part of the output. The return value of this
2408 PRINT_UNKNOWN: Means we printed nothing
2409 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2410 code to print the location. An example is
2411 "Breakpoint 1, " which should be followed by
2413 PRINT_SRC_ONLY: Means we printed something, but there is no need
2414 to also print the location part of the message.
2415 An example is the catch/throw messages, which
2416 don't require a location appended to the end.
2417 PRINT_NOTHING: We have done some printing and we don't need any
2418 further info to be printed.*/
2420 enum print_stop_action
2421 bpstat_print (bpstat bs
)
2425 /* Maybe another breakpoint in the chain caused us to stop.
2426 (Currently all watchpoints go on the bpstat whether hit or not.
2427 That probably could (should) be changed, provided care is taken
2428 with respect to bpstat_explains_signal). */
2429 for (; bs
; bs
= bs
->next
)
2431 val
= print_bp_stop_message (bs
);
2432 if (val
== PRINT_SRC_ONLY
2433 || val
== PRINT_SRC_AND_LOC
2434 || val
== PRINT_NOTHING
)
2438 /* We reached the end of the chain, or we got a null BS to start
2439 with and nothing was printed. */
2440 return PRINT_UNKNOWN
;
2443 /* Evaluate the expression EXP and return 1 if value is zero.
2444 This is used inside a catch_errors to evaluate the breakpoint condition.
2445 The argument is a "struct expression *" that has been cast to char * to
2446 make it pass through catch_errors. */
2449 breakpoint_cond_eval (void *exp
)
2451 struct value
*mark
= value_mark ();
2452 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2453 value_free_to_mark (mark
);
2457 /* Allocate a new bpstat and chain it to the current one. */
2460 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2464 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2466 bs
->breakpoint_at
= bl
;
2467 /* If the condition is false, etc., don't do the commands. */
2468 bs
->commands
= NULL
;
2470 bs
->print_it
= print_it_normal
;
2474 /* The target has stopped with waitstatus WS. Check if any hardware
2475 watchpoints have triggered, according to the target. */
2478 watchpoints_triggered (struct target_waitstatus
*ws
)
2480 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2482 struct breakpoint
*b
;
2484 if (!stopped_by_watchpoint
)
2486 /* We were not stopped by a watchpoint. Mark all watchpoints
2487 as not triggered. */
2489 if (b
->type
== bp_hardware_watchpoint
2490 || b
->type
== bp_read_watchpoint
2491 || b
->type
== bp_access_watchpoint
)
2492 b
->watchpoint_triggered
= watch_triggered_no
;
2497 if (!target_stopped_data_address (¤t_target
, &addr
))
2499 /* We were stopped by a watchpoint, but we don't know where.
2500 Mark all watchpoints as unknown. */
2502 if (b
->type
== bp_hardware_watchpoint
2503 || b
->type
== bp_read_watchpoint
2504 || b
->type
== bp_access_watchpoint
)
2505 b
->watchpoint_triggered
= watch_triggered_unknown
;
2507 return stopped_by_watchpoint
;
2510 /* The target could report the data address. Mark watchpoints
2511 affected by this data address as triggered, and all others as not
2515 if (b
->type
== bp_hardware_watchpoint
2516 || b
->type
== bp_read_watchpoint
2517 || b
->type
== bp_access_watchpoint
)
2519 struct bp_location
*loc
;
2522 b
->watchpoint_triggered
= watch_triggered_no
;
2523 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2524 /* Exact match not required. Within range is
2526 if (target_watchpoint_addr_within_range (¤t_target
,
2530 b
->watchpoint_triggered
= watch_triggered_yes
;
2538 /* Possible return values for watchpoint_check (this can't be an enum
2539 because of check_errors). */
2540 /* The watchpoint has been deleted. */
2541 #define WP_DELETED 1
2542 /* The value has changed. */
2543 #define WP_VALUE_CHANGED 2
2544 /* The value has not changed. */
2545 #define WP_VALUE_NOT_CHANGED 3
2547 #define BP_TEMPFLAG 1
2548 #define BP_HARDWAREFLAG 2
2550 /* Check watchpoint condition. */
2553 watchpoint_check (void *p
)
2555 bpstat bs
= (bpstat
) p
;
2556 struct breakpoint
*b
;
2557 struct frame_info
*fr
;
2558 int within_current_scope
;
2560 b
= bs
->breakpoint_at
->owner
;
2562 if (b
->exp_valid_block
== NULL
)
2563 within_current_scope
= 1;
2566 /* There is no current frame at this moment. If we're going to have
2567 any chance of handling watchpoints on local variables, we'll need
2568 the frame chain (so we can determine if we're in scope). */
2569 reinit_frame_cache ();
2570 fr
= frame_find_by_id (b
->watchpoint_frame
);
2571 within_current_scope
= (fr
!= NULL
);
2573 /* If we've gotten confused in the unwinder, we might have
2574 returned a frame that can't describe this variable. */
2575 if (within_current_scope
2576 && (block_linkage_function (b
->exp_valid_block
)
2577 != get_frame_function (fr
)))
2578 within_current_scope
= 0;
2580 /* in_function_epilogue_p() returns a non-zero value if we're still
2581 in the function but the stack frame has already been invalidated.
2582 Since we can't rely on the values of local variables after the
2583 stack has been destroyed, we are treating the watchpoint in that
2584 state as `not changed' without further checking.
2586 vinschen/2003-09-04: The former implementation left out the case
2587 that the watchpoint frame couldn't be found by frame_find_by_id()
2588 because the current PC is currently in an epilogue. Calling
2589 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2590 if ((!within_current_scope
|| fr
== get_current_frame ())
2591 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2592 return WP_VALUE_NOT_CHANGED
;
2593 if (fr
&& within_current_scope
)
2594 /* If we end up stopping, the current frame will get selected
2595 in normal_stop. So this call to select_frame won't affect
2600 if (within_current_scope
)
2602 /* We use value_{,free_to_}mark because it could be a
2603 *long* time before we return to the command level and
2604 call free_all_values. We can't call free_all_values because
2605 we might be in the middle of evaluating a function call. */
2607 struct value
*mark
= value_mark ();
2608 struct value
*new_val
;
2610 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2611 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2612 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2614 if (new_val
!= NULL
)
2616 release_value (new_val
);
2617 value_free_to_mark (mark
);
2619 bs
->old_val
= b
->val
;
2622 /* We will stop here */
2623 return WP_VALUE_CHANGED
;
2627 /* Nothing changed, don't do anything. */
2628 value_free_to_mark (mark
);
2629 /* We won't stop here */
2630 return WP_VALUE_NOT_CHANGED
;
2635 /* This seems like the only logical thing to do because
2636 if we temporarily ignored the watchpoint, then when
2637 we reenter the block in which it is valid it contains
2638 garbage (in the case of a function, it may have two
2639 garbage values, one before and one after the prologue).
2640 So we can't even detect the first assignment to it and
2641 watch after that (since the garbage may or may not equal
2642 the first value assigned). */
2643 /* We print all the stop information in print_it_typical(), but
2644 in this case, by the time we call print_it_typical() this bp
2645 will be deleted already. So we have no choice but print the
2646 information here. */
2647 if (ui_out_is_mi_like_p (uiout
))
2649 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2650 ui_out_text (uiout
, "\nWatchpoint ");
2651 ui_out_field_int (uiout
, "wpnum", b
->number
);
2652 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2653 which its expression is valid.\n");
2655 if (b
->related_breakpoint
)
2656 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2657 b
->disposition
= disp_del_at_next_stop
;
2663 /* Return true if it looks like target has stopped due to hitting
2664 breakpoint location BL. This function does not check if we
2665 should stop, only if BL explains the stop. */
2667 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2669 struct breakpoint
*b
= bl
->owner
;
2671 if (b
->type
!= bp_watchpoint
2672 && b
->type
!= bp_hardware_watchpoint
2673 && b
->type
!= bp_read_watchpoint
2674 && b
->type
!= bp_access_watchpoint
2675 && b
->type
!= bp_hardware_breakpoint
2676 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2678 if (bl
->address
!= bp_addr
) /* address doesn't match */
2680 if (overlay_debugging
/* unmapped overlay section */
2681 && section_is_overlay (bl
->section
)
2682 && !section_is_mapped (bl
->section
))
2686 /* Continuable hardware watchpoints are treated as non-existent if the
2687 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2688 some data address). Otherwise gdb won't stop on a break instruction
2689 in the code (not from a breakpoint) when a hardware watchpoint has
2690 been defined. Also skip watchpoints which we know did not trigger
2691 (did not match the data address). */
2693 if ((b
->type
== bp_hardware_watchpoint
2694 || b
->type
== bp_read_watchpoint
2695 || b
->type
== bp_access_watchpoint
)
2696 && b
->watchpoint_triggered
== watch_triggered_no
)
2699 if (b
->type
== bp_hardware_breakpoint
)
2701 if (bl
->address
!= bp_addr
)
2703 if (overlay_debugging
/* unmapped overlay section */
2704 && section_is_overlay (bl
->section
)
2705 && !section_is_mapped (bl
->section
))
2709 if (b
->type
== bp_catchpoint
)
2711 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2712 if (!b
->ops
->breakpoint_hit (b
))
2719 /* If BS refers to a watchpoint, determine if the watched values
2720 has actually changed, and we should stop. If not, set BS->stop
2723 bpstat_check_watchpoint (bpstat bs
)
2725 const struct bp_location
*bl
= bs
->breakpoint_at
;
2726 struct breakpoint
*b
= bl
->owner
;
2728 if (b
->type
== bp_watchpoint
2729 || b
->type
== bp_read_watchpoint
2730 || b
->type
== bp_access_watchpoint
2731 || b
->type
== bp_hardware_watchpoint
)
2735 int must_check_value
= 0;
2737 if (b
->type
== bp_watchpoint
)
2738 /* For a software watchpoint, we must always check the
2740 must_check_value
= 1;
2741 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2742 /* We have a hardware watchpoint (read, write, or access)
2743 and the target earlier reported an address watched by
2745 must_check_value
= 1;
2746 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2747 && b
->type
== bp_hardware_watchpoint
)
2748 /* We were stopped by a hardware watchpoint, but the target could
2749 not report the data address. We must check the watchpoint's
2750 value. Access and read watchpoints are out of luck; without
2751 a data address, we can't figure it out. */
2752 must_check_value
= 1;
2754 if (must_check_value
)
2756 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2758 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2759 int e
= catch_errors (watchpoint_check
, bs
, message
,
2761 do_cleanups (cleanups
);
2765 /* We've already printed what needs to be printed. */
2766 bs
->print_it
= print_it_done
;
2769 case WP_VALUE_CHANGED
:
2770 if (b
->type
== bp_read_watchpoint
)
2772 /* Don't stop: read watchpoints shouldn't fire if
2773 the value has changed. This is for targets
2774 which cannot set read-only watchpoints. */
2775 bs
->print_it
= print_it_noop
;
2779 case WP_VALUE_NOT_CHANGED
:
2780 if (b
->type
== bp_hardware_watchpoint
2781 || b
->type
== bp_watchpoint
)
2783 /* Don't stop: write watchpoints shouldn't fire if
2784 the value hasn't changed. */
2785 bs
->print_it
= print_it_noop
;
2793 /* Error from catch_errors. */
2794 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2795 if (b
->related_breakpoint
)
2796 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2797 b
->disposition
= disp_del_at_next_stop
;
2798 /* We've already printed what needs to be printed. */
2799 bs
->print_it
= print_it_done
;
2803 else /* must_check_value == 0 */
2805 /* This is a case where some watchpoint(s) triggered, but
2806 not at the address of this watchpoint, or else no
2807 watchpoint triggered after all. So don't print
2808 anything for this watchpoint. */
2809 bs
->print_it
= print_it_noop
;
2816 /* Check conditions (condition proper, frame, thread and ignore count)
2817 of breakpoint referred to by BS. If we should not stop for this
2818 breakpoint, set BS->stop to 0. */
2820 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2822 int thread_id
= pid_to_thread_id (ptid
);
2823 const struct bp_location
*bl
= bs
->breakpoint_at
;
2824 struct breakpoint
*b
= bl
->owner
;
2826 if (frame_id_p (b
->frame_id
)
2827 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2831 int value_is_zero
= 0;
2833 /* If this is a scope breakpoint, mark the associated
2834 watchpoint as triggered so that we will handle the
2835 out-of-scope event. We'll get to the watchpoint next
2837 if (b
->type
== bp_watchpoint_scope
)
2838 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2840 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2842 /* Need to select the frame, with all that implies
2843 so that the conditions will have the right context. */
2844 select_frame (get_current_frame ());
2846 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2847 "Error in testing breakpoint condition:\n",
2849 /* FIXME-someday, should give breakpoint # */
2852 if (bl
->cond
&& value_is_zero
)
2856 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2860 else if (b
->ignore_count
> 0)
2863 annotate_ignore_count_change ();
2865 /* Increase the hit count even though we don't
2873 /* Get a bpstat associated with having just stopped at address
2874 BP_ADDR in thread PTID.
2876 Determine whether we stopped at a breakpoint, etc, or whether we
2877 don't understand this stop. Result is a chain of bpstat's such that:
2879 if we don't understand the stop, the result is a null pointer.
2881 if we understand why we stopped, the result is not null.
2883 Each element of the chain refers to a particular breakpoint or
2884 watchpoint at which we have stopped. (We may have stopped for
2885 several reasons concurrently.)
2887 Each element of the chain has valid next, breakpoint_at,
2888 commands, FIXME??? fields. */
2891 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2893 struct breakpoint
*b
= NULL
;
2894 const struct bp_location
*bl
;
2895 struct bp_location
*loc
;
2896 /* Root of the chain of bpstat's */
2897 struct bpstats root_bs
[1];
2898 /* Pointer to the last thing in the chain currently. */
2899 bpstat bs
= root_bs
;
2901 int need_remove_insert
;
2903 ALL_BP_LOCATIONS (bl
)
2907 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2910 /* For hardware watchpoints, we look only at the first location.
2911 The watchpoint_check function will work on entire expression,
2912 not the individual locations. For read watchopints, the
2913 watchpoints_triggered function have checked all locations
2916 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2919 if (!bpstat_check_location (bl
, bp_addr
))
2922 /* Come here if it's a watchpoint, or if the break address matches */
2924 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2926 /* Assume we stop. Should we find watchpoint that is not actually
2927 triggered, or if condition of breakpoint is false, we'll reset
2932 bpstat_check_watchpoint (bs
);
2936 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2937 /* We do not stop for these. */
2940 bpstat_check_breakpoint_conditions (bs
, ptid
);
2946 /* We will stop here */
2947 if (b
->disposition
== disp_disable
)
2949 if (b
->enable_state
!= bp_permanent
)
2950 b
->enable_state
= bp_disabled
;
2951 update_global_location_list (0);
2955 bs
->commands
= b
->commands
;
2957 (strcmp ("silent", bs
->commands
->line
) == 0
2958 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2960 bs
->commands
= bs
->commands
->next
;
2963 bs
->commands
= copy_command_lines (bs
->commands
);
2966 /* Print nothing for this entry if we dont stop or if we dont print. */
2967 if (bs
->stop
== 0 || bs
->print
== 0)
2968 bs
->print_it
= print_it_noop
;
2971 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2973 if (loc
->address
== bp_addr
)
2975 bs
= bpstat_alloc (loc
, bs
);
2976 /* For hits of moribund locations, we should just proceed. */
2979 bs
->print_it
= print_it_noop
;
2983 bs
->next
= NULL
; /* Terminate the chain */
2984 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2986 /* If we aren't stopping, the value of some hardware watchpoint may
2987 not have changed, but the intermediate memory locations we are
2988 watching may have. Don't bother if we're stopping; this will get
2990 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2994 need_remove_insert
= 0;
2996 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2998 && bs
->breakpoint_at
->owner
2999 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3000 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3001 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3003 /* remove/insert can invalidate bs->breakpoint_at, if this
3004 location is no longer used by the watchpoint. Prevent
3005 further code from trying to use it. */
3006 bs
->breakpoint_at
= NULL
;
3007 need_remove_insert
= 1;
3010 if (need_remove_insert
)
3012 remove_breakpoints ();
3013 insert_breakpoints ();
3016 return root_bs
->next
;
3019 /* Tell what to do about this bpstat. */
3021 bpstat_what (bpstat bs
)
3023 /* Classify each bpstat as one of the following. */
3026 /* This bpstat element has no effect on the main_action. */
3029 /* There was a watchpoint, stop but don't print. */
3032 /* There was a watchpoint, stop and print. */
3035 /* There was a breakpoint but we're not stopping. */
3038 /* There was a breakpoint, stop but don't print. */
3041 /* There was a breakpoint, stop and print. */
3044 /* We hit the longjmp breakpoint. */
3047 /* We hit the longjmp_resume breakpoint. */
3050 /* We hit the step_resume breakpoint. */
3053 /* We hit the shared library event breakpoint. */
3056 /* This is just used to count how many enums there are. */
3060 /* Here is the table which drives this routine. So that we can
3061 format it pretty, we define some abbreviations for the
3062 enum bpstat_what codes. */
3063 #define kc BPSTAT_WHAT_KEEP_CHECKING
3064 #define ss BPSTAT_WHAT_STOP_SILENT
3065 #define sn BPSTAT_WHAT_STOP_NOISY
3066 #define sgl BPSTAT_WHAT_SINGLE
3067 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3068 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3069 #define sr BPSTAT_WHAT_STEP_RESUME
3070 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3072 /* "Can't happen." Might want to print an error message.
3073 abort() is not out of the question, but chances are GDB is just
3074 a bit confused, not unusable. */
3075 #define err BPSTAT_WHAT_STOP_NOISY
3077 /* Given an old action and a class, come up with a new action. */
3078 /* One interesting property of this table is that wp_silent is the same
3079 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3080 after stopping, the check for whether to step over a breakpoint
3081 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3082 reference to how we stopped. We retain separate wp_silent and
3083 bp_silent codes in case we want to change that someday.
3085 Another possibly interesting property of this table is that
3086 there's a partial ordering, priority-like, of the actions. Once
3087 you've decided that some action is appropriate, you'll never go
3088 back and decide something of a lower priority is better. The
3091 kc < clr sgl shl slr sn sr ss
3092 sgl < shl slr sn sr ss
3093 slr < err shl sn sr ss
3094 clr < err shl sn sr ss
3100 What I think this means is that we don't need a damned table
3101 here. If you just put the rows and columns in the right order,
3102 it'd look awfully regular. We could simply walk the bpstat list
3103 and choose the highest priority action we find, with a little
3104 logic to handle the 'err' cases. */
3106 /* step_resume entries: a step resume breakpoint overrides another
3107 breakpoint of signal handling (see comment in wait_for_inferior
3108 at where we set the step_resume breakpoint). */
3110 static const enum bpstat_what_main_action
3111 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3114 /* kc ss sn sgl slr clr sr shl
3117 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3119 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3121 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3123 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3125 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3127 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3129 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3131 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3133 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3135 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3148 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3149 struct bpstat_what retval
;
3151 retval
.call_dummy
= 0;
3152 for (; bs
!= NULL
; bs
= bs
->next
)
3154 enum class bs_class
= no_effect
;
3155 if (bs
->breakpoint_at
== NULL
)
3156 /* I suspect this can happen if it was a momentary breakpoint
3157 which has since been deleted. */
3159 if (bs
->breakpoint_at
->owner
== NULL
)
3160 bs_class
= bp_nostop
;
3162 switch (bs
->breakpoint_at
->owner
->type
)
3168 case bp_hardware_breakpoint
:
3174 bs_class
= bp_noisy
;
3176 bs_class
= bp_silent
;
3179 bs_class
= bp_nostop
;
3182 case bp_hardware_watchpoint
:
3183 case bp_read_watchpoint
:
3184 case bp_access_watchpoint
:
3188 bs_class
= wp_noisy
;
3190 bs_class
= wp_silent
;
3193 /* There was a watchpoint, but we're not stopping.
3194 This requires no further action. */
3195 bs_class
= no_effect
;
3198 bs_class
= long_jump
;
3200 case bp_longjmp_resume
:
3201 bs_class
= long_resume
;
3203 case bp_step_resume
:
3206 bs_class
= step_resume
;
3209 /* It is for the wrong frame. */
3210 bs_class
= bp_nostop
;
3212 case bp_watchpoint_scope
:
3213 bs_class
= bp_nostop
;
3215 case bp_shlib_event
:
3216 bs_class
= shlib_event
;
3218 case bp_thread_event
:
3219 case bp_overlay_event
:
3220 bs_class
= bp_nostop
;
3226 bs_class
= bp_noisy
;
3228 bs_class
= bp_silent
;
3231 /* There was a catchpoint, but we're not stopping.
3232 This requires no further action. */
3233 bs_class
= no_effect
;
3236 /* Make sure the action is stop (silent or noisy),
3237 so infrun.c pops the dummy frame. */
3238 bs_class
= bp_silent
;
3239 retval
.call_dummy
= 1;
3242 current_action
= table
[(int) bs_class
][(int) current_action
];
3244 retval
.main_action
= current_action
;
3248 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3249 without hardware support). This isn't related to a specific bpstat,
3250 just to things like whether watchpoints are set. */
3253 bpstat_should_step (void)
3255 struct breakpoint
*b
;
3257 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3264 static void print_breakpoint_location (struct breakpoint
*b
,
3265 struct bp_location
*loc
,
3267 struct ui_stream
*stb
)
3272 = find_pc_sect_function (loc
->address
, loc
->section
);
3275 ui_out_text (uiout
, "in ");
3276 ui_out_field_string (uiout
, "func",
3277 SYMBOL_PRINT_NAME (sym
));
3278 ui_out_wrap_hint (uiout
, wrap_indent
);
3279 ui_out_text (uiout
, " at ");
3281 ui_out_field_string (uiout
, "file", b
->source_file
);
3282 ui_out_text (uiout
, ":");
3284 if (ui_out_is_mi_like_p (uiout
))
3286 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3287 char *fullname
= symtab_to_fullname (sal
.symtab
);
3290 ui_out_field_string (uiout
, "fullname", fullname
);
3293 ui_out_field_int (uiout
, "line", b
->line_number
);
3297 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3301 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3302 ui_out_field_stream (uiout
, "at", stb
);
3306 /* Print B to gdb_stdout. */
3308 print_one_breakpoint_location (struct breakpoint
*b
,
3309 struct bp_location
*loc
,
3311 CORE_ADDR
*last_addr
)
3313 struct command_line
*l
;
3315 struct ep_type_description
3320 static struct ep_type_description bptypes
[] =
3322 {bp_none
, "?deleted?"},
3323 {bp_breakpoint
, "breakpoint"},
3324 {bp_hardware_breakpoint
, "hw breakpoint"},
3325 {bp_until
, "until"},
3326 {bp_finish
, "finish"},
3327 {bp_watchpoint
, "watchpoint"},
3328 {bp_hardware_watchpoint
, "hw watchpoint"},
3329 {bp_read_watchpoint
, "read watchpoint"},
3330 {bp_access_watchpoint
, "acc watchpoint"},
3331 {bp_longjmp
, "longjmp"},
3332 {bp_longjmp_resume
, "longjmp resume"},
3333 {bp_step_resume
, "step resume"},
3334 {bp_watchpoint_scope
, "watchpoint scope"},
3335 {bp_call_dummy
, "call dummy"},
3336 {bp_shlib_event
, "shlib events"},
3337 {bp_thread_event
, "thread events"},
3338 {bp_overlay_event
, "overlay events"},
3339 {bp_catchpoint
, "catchpoint"},
3342 static char bpenables
[] = "nynny";
3343 char wrap_indent
[80];
3344 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3345 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3346 struct cleanup
*bkpt_chain
;
3348 int header_of_multiple
= 0;
3349 int part_of_multiple
= (loc
!= NULL
);
3350 struct value_print_options opts
;
3352 get_user_print_options (&opts
);
3354 gdb_assert (!loc
|| loc_number
!= 0);
3355 /* See comment in print_one_breakpoint concerning
3356 treatment of breakpoints with single disabled
3360 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3361 header_of_multiple
= 1;
3366 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3370 if (part_of_multiple
)
3373 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3374 ui_out_field_string (uiout
, "number", formatted
);
3379 ui_out_field_int (uiout
, "number", b
->number
);
3384 if (part_of_multiple
)
3385 ui_out_field_skip (uiout
, "type");
3388 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3389 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3390 internal_error (__FILE__
, __LINE__
,
3391 _("bptypes table does not describe type #%d."),
3393 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3398 if (part_of_multiple
)
3399 ui_out_field_skip (uiout
, "disp");
3401 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3406 if (part_of_multiple
)
3407 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3409 ui_out_field_fmt (uiout
, "enabled", "%c",
3410 bpenables
[(int) b
->enable_state
]);
3411 ui_out_spaces (uiout
, 2);
3415 strcpy (wrap_indent
, " ");
3416 if (opts
.addressprint
)
3418 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3419 strcat (wrap_indent
, " ");
3421 strcat (wrap_indent
, " ");
3424 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3426 /* Although the print_one can possibly print
3427 all locations, calling it here is not likely
3428 to get any nice result. So, make sure there's
3429 just one location. */
3430 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3431 b
->ops
->print_one (b
, last_addr
);
3437 internal_error (__FILE__
, __LINE__
,
3438 _("print_one_breakpoint: bp_none encountered\n"));
3442 case bp_hardware_watchpoint
:
3443 case bp_read_watchpoint
:
3444 case bp_access_watchpoint
:
3445 /* Field 4, the address, is omitted (which makes the columns
3446 not line up too nicely with the headers, but the effect
3447 is relatively readable). */
3448 if (opts
.addressprint
)
3449 ui_out_field_skip (uiout
, "addr");
3451 print_expression (b
->exp
, stb
->stream
);
3452 ui_out_field_stream (uiout
, "what", stb
);
3456 case bp_hardware_breakpoint
:
3460 case bp_longjmp_resume
:
3461 case bp_step_resume
:
3462 case bp_watchpoint_scope
:
3464 case bp_shlib_event
:
3465 case bp_thread_event
:
3466 case bp_overlay_event
:
3467 if (opts
.addressprint
)
3470 if (header_of_multiple
)
3471 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3472 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3473 ui_out_field_string (uiout
, "addr", "<PENDING>");
3475 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3478 if (!header_of_multiple
)
3479 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3481 *last_addr
= b
->loc
->address
;
3485 if (!part_of_multiple
&& b
->thread
!= -1)
3487 /* FIXME: This seems to be redundant and lost here; see the
3488 "stop only in" line a little further down. */
3489 ui_out_text (uiout
, " thread ");
3490 ui_out_field_int (uiout
, "thread", b
->thread
);
3493 ui_out_text (uiout
, "\n");
3495 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3498 ui_out_text (uiout
, "\tstop only in stack frame at ");
3499 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3501 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3502 ui_out_text (uiout
, "\n");
3505 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3507 /* We do not print the condition for Ada exception catchpoints
3508 because the condition is an internal implementation detail
3509 that we do not want to expose to the user. */
3511 ui_out_text (uiout
, "\tstop only if ");
3512 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3513 ui_out_text (uiout
, "\n");
3516 if (!part_of_multiple
&& b
->thread
!= -1)
3518 /* FIXME should make an annotation for this */
3519 ui_out_text (uiout
, "\tstop only in thread ");
3520 ui_out_field_int (uiout
, "thread", b
->thread
);
3521 ui_out_text (uiout
, "\n");
3524 if (!part_of_multiple
&& b
->hit_count
)
3526 /* FIXME should make an annotation for this */
3527 if (ep_is_catchpoint (b
))
3528 ui_out_text (uiout
, "\tcatchpoint");
3530 ui_out_text (uiout
, "\tbreakpoint");
3531 ui_out_text (uiout
, " already hit ");
3532 ui_out_field_int (uiout
, "times", b
->hit_count
);
3533 if (b
->hit_count
== 1)
3534 ui_out_text (uiout
, " time\n");
3536 ui_out_text (uiout
, " times\n");
3539 /* Output the count also if it is zero, but only if this is
3540 mi. FIXME: Should have a better test for this. */
3541 if (ui_out_is_mi_like_p (uiout
))
3542 if (!part_of_multiple
&& b
->hit_count
== 0)
3543 ui_out_field_int (uiout
, "times", b
->hit_count
);
3545 if (!part_of_multiple
&& b
->ignore_count
)
3548 ui_out_text (uiout
, "\tignore next ");
3549 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3550 ui_out_text (uiout
, " hits\n");
3553 if (!part_of_multiple
&& (l
= b
->commands
))
3555 struct cleanup
*script_chain
;
3558 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3559 print_command_lines (uiout
, l
, 4);
3560 do_cleanups (script_chain
);
3563 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3566 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3567 else if (b
->exp_string
)
3568 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3571 do_cleanups (bkpt_chain
);
3572 do_cleanups (old_chain
);
3576 print_one_breakpoint (struct breakpoint
*b
,
3577 CORE_ADDR
*last_addr
)
3579 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3581 /* If this breakpoint has custom print function,
3582 it's already printed. Otherwise, print individual
3583 locations, if any. */
3584 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3586 /* If breakpoint has a single location that is
3587 disabled, we print it as if it had
3588 several locations, since otherwise it's hard to
3589 represent "breakpoint enabled, location disabled"
3591 Note that while hardware watchpoints have
3592 several locations internally, that's no a property
3595 && !is_hardware_watchpoint (b
)
3596 && (b
->loc
->next
|| !b
->loc
->enabled
)
3597 && !ui_out_is_mi_like_p (uiout
))
3599 struct bp_location
*loc
;
3601 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3602 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3608 struct captured_breakpoint_query_args
3614 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3616 struct captured_breakpoint_query_args
*args
= data
;
3617 struct breakpoint
*b
;
3618 CORE_ADDR dummy_addr
= 0;
3621 if (args
->bnum
== b
->number
)
3623 print_one_breakpoint (b
, &dummy_addr
);
3631 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3633 struct captured_breakpoint_query_args args
;
3635 /* For the moment we don't trust print_one_breakpoint() to not throw
3637 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3638 error_message
, RETURN_MASK_ALL
) < 0)
3644 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3645 catchpoints, et.al.). */
3648 user_settable_breakpoint (const struct breakpoint
*b
)
3650 return (b
->type
== bp_breakpoint
3651 || b
->type
== bp_catchpoint
3652 || b
->type
== bp_hardware_breakpoint
3653 || b
->type
== bp_watchpoint
3654 || b
->type
== bp_read_watchpoint
3655 || b
->type
== bp_access_watchpoint
3656 || b
->type
== bp_hardware_watchpoint
);
3659 /* Print information on user settable breakpoint (watchpoint, etc)
3660 number BNUM. If BNUM is -1 print all user settable breakpoints.
3661 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3664 breakpoint_1 (int bnum
, int allflag
)
3666 struct breakpoint
*b
;
3667 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3668 int nr_printable_breakpoints
;
3669 struct cleanup
*bkpttbl_chain
;
3670 struct value_print_options opts
;
3672 get_user_print_options (&opts
);
3674 /* Compute the number of rows in the table. */
3675 nr_printable_breakpoints
= 0;
3678 || bnum
== b
->number
)
3680 if (allflag
|| user_settable_breakpoint (b
))
3681 nr_printable_breakpoints
++;
3684 if (opts
.addressprint
)
3686 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3690 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3693 if (nr_printable_breakpoints
> 0)
3694 annotate_breakpoints_headers ();
3695 if (nr_printable_breakpoints
> 0)
3697 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3698 if (nr_printable_breakpoints
> 0)
3700 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3701 if (nr_printable_breakpoints
> 0)
3703 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3704 if (nr_printable_breakpoints
> 0)
3706 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3707 if (opts
.addressprint
)
3709 if (nr_printable_breakpoints
> 0)
3711 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3712 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3714 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3716 if (nr_printable_breakpoints
> 0)
3718 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3719 ui_out_table_body (uiout
);
3720 if (nr_printable_breakpoints
> 0)
3721 annotate_breakpoints_table ();
3725 || bnum
== b
->number
)
3727 /* We only print out user settable breakpoints unless the
3729 if (allflag
|| user_settable_breakpoint (b
))
3730 print_one_breakpoint (b
, &last_addr
);
3733 do_cleanups (bkpttbl_chain
);
3735 if (nr_printable_breakpoints
== 0)
3738 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3740 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3745 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3746 that a comparison of an unsigned with -1 is always false. */
3747 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3748 set_next_address (current_gdbarch
, last_addr
);
3751 /* FIXME? Should this be moved up so that it is only called when
3752 there have been breakpoints? */
3753 annotate_breakpoints_table_end ();
3757 breakpoints_info (char *bnum_exp
, int from_tty
)
3762 bnum
= parse_and_eval_long (bnum_exp
);
3764 breakpoint_1 (bnum
, 0);
3768 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3773 bnum
= parse_and_eval_long (bnum_exp
);
3775 breakpoint_1 (bnum
, 1);
3779 breakpoint_has_pc (struct breakpoint
*b
,
3780 CORE_ADDR pc
, struct obj_section
*section
)
3782 struct bp_location
*bl
= b
->loc
;
3783 for (; bl
; bl
= bl
->next
)
3785 if (bl
->address
== pc
3786 && (!overlay_debugging
|| bl
->section
== section
))
3792 /* Print a message describing any breakpoints set at PC. */
3795 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3799 struct breakpoint
*b
;
3802 others
+= breakpoint_has_pc (b
, pc
, section
);
3806 printf_filtered (_("Note: breakpoint "));
3807 else /* if (others == ???) */
3808 printf_filtered (_("Note: breakpoints "));
3810 if (breakpoint_has_pc (b
, pc
, section
))
3813 printf_filtered ("%d", b
->number
);
3814 if (b
->thread
== -1 && thread
!= -1)
3815 printf_filtered (" (all threads)");
3816 else if (b
->thread
!= -1)
3817 printf_filtered (" (thread %d)", b
->thread
);
3818 printf_filtered ("%s%s ",
3819 ((b
->enable_state
== bp_disabled
||
3820 b
->enable_state
== bp_call_disabled
)
3822 : b
->enable_state
== bp_permanent
3826 : ((others
== 1) ? " and" : ""));
3828 printf_filtered (_("also set at pc "));
3829 fputs_filtered (paddress (pc
), gdb_stdout
);
3830 printf_filtered (".\n");
3834 /* Set the default place to put a breakpoint
3835 for the `break' command with no arguments. */
3838 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3841 default_breakpoint_valid
= valid
;
3842 default_breakpoint_address
= addr
;
3843 default_breakpoint_symtab
= symtab
;
3844 default_breakpoint_line
= line
;
3847 /* Return true iff it is meaningful to use the address member of
3848 BPT. For some breakpoint types, the address member is irrelevant
3849 and it makes no sense to attempt to compare it to other addresses
3850 (or use it for any other purpose either).
3852 More specifically, each of the following breakpoint types will always
3853 have a zero valued address and we don't want check_duplicates() to mark
3854 breakpoints of any of these types to be a duplicate of an actual
3855 breakpoint at address zero:
3858 bp_hardware_watchpoint
3860 bp_access_watchpoint
3864 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3866 enum bptype type
= bpt
->type
;
3868 return (type
!= bp_watchpoint
3869 && type
!= bp_hardware_watchpoint
3870 && type
!= bp_read_watchpoint
3871 && type
!= bp_access_watchpoint
3872 && type
!= bp_catchpoint
);
3875 /* Rescan breakpoints at the same address and section as BPT,
3876 marking the first one as "first" and any others as "duplicates".
3877 This is so that the bpt instruction is only inserted once.
3878 If we have a permanent breakpoint at the same place as BPT, make
3879 that one the official one, and the rest as duplicates. */
3882 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
3884 struct bp_location
*b
;
3886 struct bp_location
*perm_bp
= 0;
3888 ALL_BP_LOCATIONS (b
)
3889 if (b
->owner
->enable_state
!= bp_disabled
3890 && b
->owner
->enable_state
!= bp_call_disabled
3892 && !b
->shlib_disabled
3893 && b
->address
== address
/* address / overlay match */
3894 && (!overlay_debugging
|| b
->section
== section
)
3895 && breakpoint_address_is_meaningful (b
->owner
))
3897 /* Have we found a permanent breakpoint? */
3898 if (b
->owner
->enable_state
== bp_permanent
)
3905 b
->duplicate
= count
> 1;
3908 /* If we found a permanent breakpoint at this address, go over the
3909 list again and declare all the other breakpoints there to be the
3913 perm_bp
->duplicate
= 0;
3915 /* Permanent breakpoint should always be inserted. */
3916 if (! perm_bp
->inserted
)
3917 internal_error (__FILE__
, __LINE__
,
3918 _("allegedly permanent breakpoint is not "
3919 "actually inserted"));
3921 ALL_BP_LOCATIONS (b
)
3924 if (b
->owner
->enable_state
!= bp_disabled
3925 && b
->owner
->enable_state
!= bp_call_disabled
3926 && b
->enabled
&& !b
->shlib_disabled
3927 && b
->address
== address
/* address / overlay match */
3928 && (!overlay_debugging
|| b
->section
== section
)
3929 && breakpoint_address_is_meaningful (b
->owner
))
3932 internal_error (__FILE__
, __LINE__
,
3933 _("another breakpoint was inserted on top of "
3934 "a permanent breakpoint"));
3943 check_duplicates (struct breakpoint
*bpt
)
3945 struct bp_location
*bl
= bpt
->loc
;
3947 if (! breakpoint_address_is_meaningful (bpt
))
3950 for (; bl
; bl
= bl
->next
)
3951 check_duplicates_for (bl
->address
, bl
->section
);
3955 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3956 int bnum
, int have_bnum
)
3961 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
3962 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
3964 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
3965 bnum
, astr1
, astr2
);
3967 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
3970 /* Adjust a breakpoint's address to account for architectural constraints
3971 on breakpoint placement. Return the adjusted address. Note: Very
3972 few targets require this kind of adjustment. For most targets,
3973 this function is simply the identity function. */
3976 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
3978 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3980 /* Very few targets need any kind of breakpoint adjustment. */
3983 else if (bptype
== bp_watchpoint
3984 || bptype
== bp_hardware_watchpoint
3985 || bptype
== bp_read_watchpoint
3986 || bptype
== bp_access_watchpoint
3987 || bptype
== bp_catchpoint
)
3989 /* Watchpoints and the various bp_catch_* eventpoints should not
3990 have their addresses modified. */
3995 CORE_ADDR adjusted_bpaddr
;
3997 /* Some targets have architectural constraints on the placement
3998 of breakpoint instructions. Obtain the adjusted address. */
3999 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4002 /* An adjusted breakpoint address can significantly alter
4003 a user's expectations. Print a warning if an adjustment
4005 if (adjusted_bpaddr
!= bpaddr
)
4006 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4008 return adjusted_bpaddr
;
4012 /* Allocate a struct bp_location. */
4014 static struct bp_location
*
4015 allocate_bp_location (struct breakpoint
*bpt
)
4017 struct bp_location
*loc
, *loc_p
;
4019 loc
= xmalloc (sizeof (struct bp_location
));
4020 memset (loc
, 0, sizeof (*loc
));
4024 loc
->shlib_disabled
= 0;
4033 case bp_longjmp_resume
:
4034 case bp_step_resume
:
4035 case bp_watchpoint_scope
:
4037 case bp_shlib_event
:
4038 case bp_thread_event
:
4039 case bp_overlay_event
:
4040 loc
->loc_type
= bp_loc_software_breakpoint
;
4042 case bp_hardware_breakpoint
:
4043 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4045 case bp_hardware_watchpoint
:
4046 case bp_read_watchpoint
:
4047 case bp_access_watchpoint
:
4048 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4052 loc
->loc_type
= bp_loc_other
;
4055 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4061 static void free_bp_location (struct bp_location
*loc
)
4066 if (loc
->function_name
)
4067 xfree (loc
->function_name
);
4072 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4073 that has type BPTYPE and has no locations as yet. */
4075 static struct breakpoint
*
4076 set_raw_breakpoint_without_location (enum bptype bptype
)
4078 struct breakpoint
*b
, *b1
;
4080 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4081 memset (b
, 0, sizeof (*b
));
4084 b
->language
= current_language
->la_language
;
4085 b
->input_radix
= input_radix
;
4087 b
->enable_state
= bp_enabled
;
4090 b
->ignore_count
= 0;
4092 b
->frame_id
= null_frame_id
;
4093 b
->forked_inferior_pid
= null_ptid
;
4094 b
->exec_pathname
= NULL
;
4096 b
->condition_not_parsed
= 0;
4098 /* Add this breakpoint to the end of the chain
4099 so that a list of breakpoints will come out in order
4100 of increasing numbers. */
4102 b1
= breakpoint_chain
;
4104 breakpoint_chain
= b
;
4114 /* Initialize loc->function_name. */
4116 set_breakpoint_location_function (struct bp_location
*loc
)
4118 if (loc
->owner
->type
== bp_breakpoint
4119 || loc
->owner
->type
== bp_hardware_breakpoint
)
4121 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4123 if (loc
->function_name
)
4124 loc
->function_name
= xstrdup (loc
->function_name
);
4128 /* set_raw_breakpoint is a low level routine for allocating and
4129 partially initializing a breakpoint of type BPTYPE. The newly
4130 created breakpoint's address, section, source file name, and line
4131 number are provided by SAL. The newly created and partially
4132 initialized breakpoint is added to the breakpoint chain and
4133 is also returned as the value of this function.
4135 It is expected that the caller will complete the initialization of
4136 the newly created breakpoint struct as well as output any status
4137 information regarding the creation of a new breakpoint. In
4138 particular, set_raw_breakpoint does NOT set the breakpoint
4139 number! Care should be taken to not allow an error to occur
4140 prior to completing the initialization of the breakpoint. If this
4141 should happen, a bogus breakpoint will be left on the chain. */
4144 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4146 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4147 CORE_ADDR adjusted_address
;
4149 /* Adjust the breakpoint's address prior to allocating a location.
4150 Once we call allocate_bp_location(), that mostly uninitialized
4151 location will be placed on the location chain. Adjustment of the
4152 breakpoint may cause target_read_memory() to be called and we do
4153 not want its scan of the location chain to find a breakpoint and
4154 location that's only been partially initialized. */
4155 adjusted_address
= adjust_breakpoint_address (sal
.pc
, b
->type
);
4157 b
->loc
= allocate_bp_location (b
);
4158 b
->loc
->requested_address
= sal
.pc
;
4159 b
->loc
->address
= adjusted_address
;
4161 if (sal
.symtab
== NULL
)
4162 b
->source_file
= NULL
;
4164 b
->source_file
= savestring (sal
.symtab
->filename
,
4165 strlen (sal
.symtab
->filename
));
4166 b
->loc
->section
= sal
.section
;
4167 b
->line_number
= sal
.line
;
4169 set_breakpoint_location_function (b
->loc
);
4171 breakpoints_changed ();
4177 /* Note that the breakpoint object B describes a permanent breakpoint
4178 instruction, hard-wired into the inferior's code. */
4180 make_breakpoint_permanent (struct breakpoint
*b
)
4182 struct bp_location
*bl
;
4183 b
->enable_state
= bp_permanent
;
4185 /* By definition, permanent breakpoints are already present in the code.
4186 Mark all locations as inserted. For now, make_breakpoint_permanent
4187 is called in just one place, so it's hard to say if it's reasonable
4188 to have permanent breakpoint with multiple locations or not,
4189 but it's easy to implmement. */
4190 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4194 static struct breakpoint
*
4195 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4197 static int internal_breakpoint_number
= -1;
4198 struct symtab_and_line sal
;
4199 struct breakpoint
*b
;
4201 init_sal (&sal
); /* initialize to zeroes */
4204 sal
.section
= find_pc_overlay (sal
.pc
);
4206 b
= set_raw_breakpoint (sal
, type
);
4207 b
->number
= internal_breakpoint_number
--;
4208 b
->disposition
= disp_donttouch
;
4215 create_longjmp_breakpoint (char *func_name
)
4217 struct minimal_symbol
*m
;
4219 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4221 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4222 update_global_location_list (1);
4225 /* Call this routine when stepping and nexting to enable a breakpoint
4226 if we do a longjmp(). When we hit that breakpoint, call
4227 set_longjmp_resume_breakpoint() to figure out where we are going. */
4230 set_longjmp_breakpoint (void)
4232 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4234 create_longjmp_breakpoint ("longjmp");
4235 create_longjmp_breakpoint ("_longjmp");
4236 create_longjmp_breakpoint ("siglongjmp");
4237 create_longjmp_breakpoint ("_siglongjmp");
4241 /* Delete all longjmp breakpoints from THREAD. */
4243 delete_longjmp_breakpoint (int thread
)
4245 struct breakpoint
*b
, *temp
;
4247 ALL_BREAKPOINTS_SAFE (b
, temp
)
4248 if (b
->type
== bp_longjmp
)
4250 if (b
->thread
== thread
)
4251 delete_breakpoint (b
);
4256 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4258 struct breakpoint
*b
;
4259 struct minimal_symbol
*m
;
4261 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4264 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4266 b
->addr_string
= xstrdup (func_name
);
4268 if (overlay_debugging
== ovly_auto
)
4270 b
->enable_state
= bp_enabled
;
4271 overlay_events_enabled
= 1;
4275 b
->enable_state
= bp_disabled
;
4276 overlay_events_enabled
= 0;
4278 update_global_location_list (1);
4282 create_overlay_event_breakpoint (char *func_name
)
4284 struct objfile
*objfile
;
4285 ALL_OBJFILES (objfile
)
4286 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4290 enable_overlay_breakpoints (void)
4292 struct breakpoint
*b
;
4295 if (b
->type
== bp_overlay_event
)
4297 b
->enable_state
= bp_enabled
;
4298 update_global_location_list (1);
4299 overlay_events_enabled
= 1;
4304 disable_overlay_breakpoints (void)
4306 struct breakpoint
*b
;
4309 if (b
->type
== bp_overlay_event
)
4311 b
->enable_state
= bp_disabled
;
4312 update_global_location_list (0);
4313 overlay_events_enabled
= 0;
4318 create_thread_event_breakpoint (CORE_ADDR address
)
4320 struct breakpoint
*b
;
4322 b
= create_internal_breakpoint (address
, bp_thread_event
);
4324 b
->enable_state
= bp_enabled
;
4325 /* addr_string has to be used or breakpoint_re_set will delete me. */
4326 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4328 update_global_location_list_nothrow (1);
4334 remove_thread_event_breakpoints (void)
4336 struct breakpoint
*b
, *temp
;
4338 ALL_BREAKPOINTS_SAFE (b
, temp
)
4339 if (b
->type
== bp_thread_event
)
4340 delete_breakpoint (b
);
4343 struct captured_parse_breakpoint_args
4346 struct symtabs_and_lines
*sals_p
;
4347 char ***addr_string_p
;
4351 struct lang_and_radix
4359 remove_solib_event_breakpoints (void)
4361 struct breakpoint
*b
, *temp
;
4363 ALL_BREAKPOINTS_SAFE (b
, temp
)
4364 if (b
->type
== bp_shlib_event
)
4365 delete_breakpoint (b
);
4369 create_solib_event_breakpoint (CORE_ADDR address
)
4371 struct breakpoint
*b
;
4373 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4374 update_global_location_list_nothrow (1);
4378 /* Disable any breakpoints that are on code in shared libraries. Only
4379 apply to enabled breakpoints, disabled ones can just stay disabled. */
4382 disable_breakpoints_in_shlibs (void)
4384 struct bp_location
*loc
;
4385 int disabled_shlib_breaks
= 0;
4387 ALL_BP_LOCATIONS (loc
)
4389 struct breakpoint
*b
= loc
->owner
;
4390 /* We apply the check to all breakpoints, including disabled
4391 for those with loc->duplicate set. This is so that when breakpoint
4392 becomes enabled, or the duplicate is removed, gdb will try to insert
4393 all breakpoints. If we don't set shlib_disabled here, we'll try
4394 to insert those breakpoints and fail. */
4395 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4396 && !loc
->shlib_disabled
4398 && PC_SOLIB (loc
->address
)
4400 && solib_address (loc
->address
)
4404 loc
->shlib_disabled
= 1;
4409 /* Disable any breakpoints that are in in an unloaded shared library. Only
4410 apply to enabled breakpoints, disabled ones can just stay disabled. */
4413 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4415 struct bp_location
*loc
;
4416 int disabled_shlib_breaks
= 0;
4418 ALL_BP_LOCATIONS (loc
)
4420 struct breakpoint
*b
= loc
->owner
;
4421 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4422 || loc
->loc_type
== bp_loc_software_breakpoint
)
4423 && !loc
->shlib_disabled
)
4426 char *so_name
= PC_SOLIB (loc
->address
);
4428 char *so_name
= solib_address (loc
->address
);
4430 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4432 loc
->shlib_disabled
= 1;
4433 /* At this point, we cannot rely on remove_breakpoint
4434 succeeding so we must mark the breakpoint as not inserted
4435 to prevent future errors occurring in remove_breakpoints. */
4437 if (!disabled_shlib_breaks
)
4439 target_terminal_ours_for_output ();
4440 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4443 disabled_shlib_breaks
= 1;
4449 /* FORK & VFORK catchpoints. */
4451 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4454 insert_catch_fork (struct breakpoint
*b
)
4456 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4459 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4462 remove_catch_fork (struct breakpoint
*b
)
4464 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4467 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4471 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4473 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4476 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4478 static enum print_stop_action
4479 print_it_catch_fork (struct breakpoint
*b
)
4481 annotate_catchpoint (b
->number
);
4482 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4483 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4484 return PRINT_SRC_AND_LOC
;
4487 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4490 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4492 struct value_print_options opts
;
4494 get_user_print_options (&opts
);
4496 /* Field 4, the address, is omitted (which makes the columns
4497 not line up too nicely with the headers, but the effect
4498 is relatively readable). */
4499 if (opts
.addressprint
)
4500 ui_out_field_skip (uiout
, "addr");
4502 ui_out_text (uiout
, "fork");
4503 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4505 ui_out_text (uiout
, ", process ");
4506 ui_out_field_int (uiout
, "what",
4507 ptid_get_pid (b
->forked_inferior_pid
));
4508 ui_out_spaces (uiout
, 1);
4512 /* Implement the "print_mention" breakpoint_ops method for fork
4516 print_mention_catch_fork (struct breakpoint
*b
)
4518 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4521 /* The breakpoint_ops structure to be used in fork catchpoints. */
4523 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4527 breakpoint_hit_catch_fork
,
4528 print_it_catch_fork
,
4529 print_one_catch_fork
,
4530 print_mention_catch_fork
4533 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4536 insert_catch_vfork (struct breakpoint
*b
)
4538 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4541 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4544 remove_catch_vfork (struct breakpoint
*b
)
4546 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4549 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4553 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4555 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4558 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4560 static enum print_stop_action
4561 print_it_catch_vfork (struct breakpoint
*b
)
4563 annotate_catchpoint (b
->number
);
4564 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4565 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4566 return PRINT_SRC_AND_LOC
;
4569 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4572 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4574 struct value_print_options opts
;
4576 get_user_print_options (&opts
);
4577 /* Field 4, the address, is omitted (which makes the columns
4578 not line up too nicely with the headers, but the effect
4579 is relatively readable). */
4580 if (opts
.addressprint
)
4581 ui_out_field_skip (uiout
, "addr");
4583 ui_out_text (uiout
, "vfork");
4584 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4586 ui_out_text (uiout
, ", process ");
4587 ui_out_field_int (uiout
, "what",
4588 ptid_get_pid (b
->forked_inferior_pid
));
4589 ui_out_spaces (uiout
, 1);
4593 /* Implement the "print_mention" breakpoint_ops method for vfork
4597 print_mention_catch_vfork (struct breakpoint
*b
)
4599 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4602 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4604 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4608 breakpoint_hit_catch_vfork
,
4609 print_it_catch_vfork
,
4610 print_one_catch_vfork
,
4611 print_mention_catch_vfork
4614 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4616 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4617 If COND_STRING is not NULL, then store it in the breakpoint.
4618 OPS, if not NULL, is the breakpoint_ops structure associated
4619 to the catchpoint. */
4621 static struct breakpoint
*
4622 create_catchpoint (int tempflag
, char *cond_string
,
4623 struct breakpoint_ops
*ops
)
4625 struct symtab_and_line sal
;
4626 struct breakpoint
*b
;
4633 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4634 set_breakpoint_count (breakpoint_count
+ 1);
4635 b
->number
= breakpoint_count
;
4637 b
->cond_string
= (cond_string
== NULL
) ?
4638 NULL
: savestring (cond_string
, strlen (cond_string
));
4640 b
->addr_string
= NULL
;
4641 b
->enable_state
= bp_enabled
;
4642 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4646 update_global_location_list (1);
4652 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4653 struct breakpoint_ops
*ops
)
4655 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4657 /* FIXME: We should put this information in a breakpoint private data
4659 b
->forked_inferior_pid
= null_ptid
;
4662 /* Exec catchpoints. */
4665 insert_catch_exec (struct breakpoint
*b
)
4667 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4671 remove_catch_exec (struct breakpoint
*b
)
4673 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4677 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4679 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4682 static enum print_stop_action
4683 print_it_catch_exec (struct breakpoint
*b
)
4685 annotate_catchpoint (b
->number
);
4686 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4688 return PRINT_SRC_AND_LOC
;
4692 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4694 struct value_print_options opts
;
4696 get_user_print_options (&opts
);
4698 /* Field 4, the address, is omitted (which makes the columns
4699 not line up too nicely with the headers, but the effect
4700 is relatively readable). */
4701 if (opts
.addressprint
)
4702 ui_out_field_skip (uiout
, "addr");
4704 ui_out_text (uiout
, "exec");
4705 if (b
->exec_pathname
!= NULL
)
4707 ui_out_text (uiout
, ", program \"");
4708 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4709 ui_out_text (uiout
, "\" ");
4714 print_mention_catch_exec (struct breakpoint
*b
)
4716 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4719 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4723 breakpoint_hit_catch_exec
,
4724 print_it_catch_exec
,
4725 print_one_catch_exec
,
4726 print_mention_catch_exec
4730 hw_breakpoint_used_count (void)
4732 struct breakpoint
*b
;
4737 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4745 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4747 struct breakpoint
*b
;
4750 *other_type_used
= 0;
4753 if (breakpoint_enabled (b
))
4755 if (b
->type
== type
)
4757 else if ((b
->type
== bp_hardware_watchpoint
||
4758 b
->type
== bp_read_watchpoint
||
4759 b
->type
== bp_access_watchpoint
))
4760 *other_type_used
= 1;
4767 disable_watchpoints_before_interactive_call_start (void)
4769 struct breakpoint
*b
;
4773 if (((b
->type
== bp_watchpoint
)
4774 || (b
->type
== bp_hardware_watchpoint
)
4775 || (b
->type
== bp_read_watchpoint
)
4776 || (b
->type
== bp_access_watchpoint
))
4777 && breakpoint_enabled (b
))
4779 b
->enable_state
= bp_call_disabled
;
4780 update_global_location_list (0);
4786 enable_watchpoints_after_interactive_call_stop (void)
4788 struct breakpoint
*b
;
4792 if (((b
->type
== bp_watchpoint
)
4793 || (b
->type
== bp_hardware_watchpoint
)
4794 || (b
->type
== bp_read_watchpoint
)
4795 || (b
->type
== bp_access_watchpoint
))
4796 && (b
->enable_state
== bp_call_disabled
))
4798 b
->enable_state
= bp_enabled
;
4799 update_global_location_list (1);
4805 /* Set a breakpoint that will evaporate an end of command
4806 at address specified by SAL.
4807 Restrict it to frame FRAME if FRAME is nonzero. */
4810 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4813 struct breakpoint
*b
;
4814 b
= set_raw_breakpoint (sal
, type
);
4815 b
->enable_state
= bp_enabled
;
4816 b
->disposition
= disp_donttouch
;
4817 b
->frame_id
= frame_id
;
4819 /* If we're debugging a multi-threaded program, then we
4820 want momentary breakpoints to be active in only a
4821 single thread of control. */
4822 if (in_thread_list (inferior_ptid
))
4823 b
->thread
= pid_to_thread_id (inferior_ptid
);
4825 update_global_location_list_nothrow (1);
4831 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4833 struct symtab_and_line sal
;
4835 sal
= find_pc_line (pc
, 0);
4837 sal
.section
= find_pc_overlay (pc
);
4838 sal
.explicit_pc
= 1;
4840 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4844 /* Tell the user we have just set a breakpoint B. */
4847 mention (struct breakpoint
*b
)
4850 struct cleanup
*old_chain
, *ui_out_chain
;
4851 struct ui_stream
*stb
;
4852 struct value_print_options opts
;
4854 get_user_print_options (&opts
);
4856 stb
= ui_out_stream_new (uiout
);
4857 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4859 /* FIXME: This is misplaced; mention() is called by things (like
4860 hitting a watchpoint) other than breakpoint creation. It should
4861 be possible to clean this up and at the same time replace the
4862 random calls to breakpoint_changed with this hook. */
4863 observer_notify_breakpoint_created (b
->number
);
4865 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4866 b
->ops
->print_mention (b
);
4871 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4874 ui_out_text (uiout
, "Watchpoint ");
4875 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4876 ui_out_field_int (uiout
, "number", b
->number
);
4877 ui_out_text (uiout
, ": ");
4878 print_expression (b
->exp
, stb
->stream
);
4879 ui_out_field_stream (uiout
, "exp", stb
);
4880 do_cleanups (ui_out_chain
);
4882 case bp_hardware_watchpoint
:
4883 ui_out_text (uiout
, "Hardware watchpoint ");
4884 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4885 ui_out_field_int (uiout
, "number", b
->number
);
4886 ui_out_text (uiout
, ": ");
4887 print_expression (b
->exp
, stb
->stream
);
4888 ui_out_field_stream (uiout
, "exp", stb
);
4889 do_cleanups (ui_out_chain
);
4891 case bp_read_watchpoint
:
4892 ui_out_text (uiout
, "Hardware read watchpoint ");
4893 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4894 ui_out_field_int (uiout
, "number", b
->number
);
4895 ui_out_text (uiout
, ": ");
4896 print_expression (b
->exp
, stb
->stream
);
4897 ui_out_field_stream (uiout
, "exp", stb
);
4898 do_cleanups (ui_out_chain
);
4900 case bp_access_watchpoint
:
4901 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4902 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4903 ui_out_field_int (uiout
, "number", b
->number
);
4904 ui_out_text (uiout
, ": ");
4905 print_expression (b
->exp
, stb
->stream
);
4906 ui_out_field_stream (uiout
, "exp", stb
);
4907 do_cleanups (ui_out_chain
);
4910 if (ui_out_is_mi_like_p (uiout
))
4915 if (b
->disposition
== disp_del
)
4916 printf_filtered (_("Temporary breakpoint"));
4918 printf_filtered (_("Breakpoint"));
4919 printf_filtered (_(" %d"), b
->number
);
4922 case bp_hardware_breakpoint
:
4923 if (ui_out_is_mi_like_p (uiout
))
4928 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4935 case bp_longjmp_resume
:
4936 case bp_step_resume
:
4938 case bp_watchpoint_scope
:
4939 case bp_shlib_event
:
4940 case bp_thread_event
:
4941 case bp_overlay_event
:
4947 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4951 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4955 if (opts
.addressprint
|| b
->source_file
== NULL
)
4957 printf_filtered (" at ");
4958 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4961 printf_filtered (": file %s, line %d.",
4962 b
->source_file
, b
->line_number
);
4966 struct bp_location
*loc
= b
->loc
;
4968 for (; loc
; loc
= loc
->next
)
4970 printf_filtered (" (%d locations)", n
);
4975 do_cleanups (old_chain
);
4976 if (ui_out_is_mi_like_p (uiout
))
4978 printf_filtered ("\n");
4982 static struct bp_location
*
4983 add_location_to_breakpoint (struct breakpoint
*b
,
4984 const struct symtab_and_line
*sal
)
4986 struct bp_location
*loc
, **tmp
;
4988 loc
= allocate_bp_location (b
);
4989 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
4992 loc
->requested_address
= sal
->pc
;
4993 loc
->address
= adjust_breakpoint_address (loc
->requested_address
, b
->type
);
4994 loc
->section
= sal
->section
;
4996 set_breakpoint_location_function (loc
);
5001 /* Return 1 if LOC is pointing to a permanent breakpoint,
5002 return 0 otherwise. */
5005 bp_loc_is_permanent (struct bp_location
*loc
)
5009 const gdb_byte
*brk
;
5010 gdb_byte
*target_mem
;
5011 struct cleanup
*cleanup
;
5014 gdb_assert (loc
!= NULL
);
5016 addr
= loc
->address
;
5017 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5019 /* Software breakpoints unsupported? */
5023 target_mem
= alloca (len
);
5025 /* Enable the automatic memory restoration from breakpoints while
5026 we read the memory. Otherwise we could say about our temporary
5027 breakpoints they are permanent. */
5028 cleanup
= make_show_memory_breakpoints_cleanup (0);
5030 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5031 && memcmp (target_mem
, brk
, len
) == 0)
5034 do_cleanups (cleanup
);
5041 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5042 as textual description of the location, and COND_STRING
5043 as condition expression. */
5046 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5048 enum bptype type
, enum bpdisp disposition
,
5049 int thread
, int ignore_count
,
5050 struct breakpoint_ops
*ops
, int from_tty
)
5052 struct breakpoint
*b
= NULL
;
5055 if (type
== bp_hardware_breakpoint
)
5057 int i
= hw_breakpoint_used_count ();
5058 int target_resources_ok
=
5059 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5061 if (target_resources_ok
== 0)
5062 error (_("No hardware breakpoint support in the target."));
5063 else if (target_resources_ok
< 0)
5064 error (_("Hardware breakpoints used exceeds limit."));
5067 for (i
= 0; i
< sals
.nelts
; ++i
)
5069 struct symtab_and_line sal
= sals
.sals
[i
];
5070 struct bp_location
*loc
;
5073 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5077 b
= set_raw_breakpoint (sal
, type
);
5078 set_breakpoint_count (breakpoint_count
+ 1);
5079 b
->number
= breakpoint_count
;
5082 b
->cond_string
= cond_string
;
5083 b
->ignore_count
= ignore_count
;
5084 b
->enable_state
= bp_enabled
;
5085 b
->disposition
= disposition
;
5091 loc
= add_location_to_breakpoint (b
, &sal
);
5094 if (bp_loc_is_permanent (loc
))
5095 make_breakpoint_permanent (b
);
5099 char *arg
= b
->cond_string
;
5100 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5102 error (_("Garbage %s follows condition"), arg
);
5107 b
->addr_string
= addr_string
;
5109 /* addr_string has to be used or breakpoint_re_set will delete
5111 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5117 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5118 elements to fill the void space. */
5119 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5121 int i
= index_to_remove
+1;
5122 int last_index
= sal
->nelts
-1;
5124 for (;i
<= last_index
; ++i
)
5125 sal
->sals
[i
-1] = sal
->sals
[i
];
5130 /* If appropriate, obtains all sals that correspond
5131 to the same file and line as SAL. This is done
5132 only if SAL does not have explicit PC and has
5133 line and file information. If we got just a single
5134 expanded sal, return the original.
5136 Otherwise, if SAL.explicit_line is not set, filter out
5137 all sals for which the name of enclosing function
5138 is different from SAL. This makes sure that if we have
5139 breakpoint originally set in template instantiation, say
5140 foo<int>(), we won't expand SAL to locations at the same
5141 line in all existing instantiations of 'foo'.
5144 struct symtabs_and_lines
5145 expand_line_sal_maybe (struct symtab_and_line sal
)
5147 struct symtabs_and_lines expanded
;
5148 CORE_ADDR original_pc
= sal
.pc
;
5149 char *original_function
= NULL
;
5153 /* If we have explicit pc, don't expand.
5154 If we have no line number, we can't expand. */
5155 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5158 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5159 expanded
.sals
[0] = sal
;
5164 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5166 expanded
= expand_line_sal (sal
);
5167 if (expanded
.nelts
== 1)
5169 /* We had one sal, we got one sal. Without futher
5170 processing, just return the original sal. */
5171 xfree (expanded
.sals
);
5173 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5174 sal
.pc
= original_pc
;
5175 expanded
.sals
[0] = sal
;
5179 if (!sal
.explicit_line
)
5181 CORE_ADDR func_addr
, func_end
;
5182 for (i
= 0; i
< expanded
.nelts
; ++i
)
5184 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5185 char *this_function
;
5186 if (find_pc_partial_function (pc
, &this_function
,
5187 &func_addr
, &func_end
))
5189 if (this_function
&&
5190 strcmp (this_function
, original_function
) != 0)
5192 remove_sal (&expanded
, i
);
5195 else if (func_addr
== pc
)
5197 /* We're at beginning of a function, and should
5199 struct symbol
*sym
= find_pc_function (pc
);
5201 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5204 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5211 if (expanded
.nelts
<= 1)
5213 /* This is un ugly workaround. If we get zero
5214 expanded sals then something is really wrong.
5215 Fix that by returnign the original sal. */
5216 xfree (expanded
.sals
);
5218 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5219 sal
.pc
= original_pc
;
5220 expanded
.sals
[0] = sal
;
5227 for (i
= 0; i
< expanded
.nelts
; ++i
)
5228 if (expanded
.sals
[i
].pc
== original_pc
)
5239 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5240 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5241 value. COND_STRING, if not NULL, specified the condition to be
5242 used for all breakpoints. Essentially the only case where
5243 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5244 function. In that case, it's still not possible to specify
5245 separate conditions for different overloaded functions, so
5246 we take just a single condition string.
5248 NOTE: If the function succeeds, the caller is expected to cleanup
5249 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5250 array contents). If the function fails (error() is called), the
5251 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5252 COND and SALS arrays and each of those arrays contents. */
5255 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5257 enum bptype type
, enum bpdisp disposition
,
5258 int thread
, int ignore_count
,
5259 struct breakpoint_ops
*ops
, int from_tty
)
5262 for (i
= 0; i
< sals
.nelts
; ++i
)
5264 struct symtabs_and_lines expanded
=
5265 expand_line_sal_maybe (sals
.sals
[i
]);
5267 create_breakpoint (expanded
, addr_string
[i
],
5268 cond_string
, type
, disposition
,
5269 thread
, ignore_count
, ops
, from_tty
);
5272 update_global_location_list (1);
5275 /* Parse ARG which is assumed to be a SAL specification possibly
5276 followed by conditionals. On return, SALS contains an array of SAL
5277 addresses found. ADDR_STRING contains a vector of (canonical)
5278 address strings. ARG points to the end of the SAL. */
5281 parse_breakpoint_sals (char **address
,
5282 struct symtabs_and_lines
*sals
,
5283 char ***addr_string
,
5286 char *addr_start
= *address
;
5287 *addr_string
= NULL
;
5288 /* If no arg given, or if first arg is 'if ', use the default
5290 if ((*address
) == NULL
5291 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5293 if (default_breakpoint_valid
)
5295 struct symtab_and_line sal
;
5296 init_sal (&sal
); /* initialize to zeroes */
5297 sals
->sals
= (struct symtab_and_line
*)
5298 xmalloc (sizeof (struct symtab_and_line
));
5299 sal
.pc
= default_breakpoint_address
;
5300 sal
.line
= default_breakpoint_line
;
5301 sal
.symtab
= default_breakpoint_symtab
;
5302 sal
.section
= find_pc_overlay (sal
.pc
);
5303 sals
->sals
[0] = sal
;
5307 error (_("No default breakpoint address now."));
5311 /* Force almost all breakpoints to be in terms of the
5312 current_source_symtab (which is decode_line_1's default). This
5313 should produce the results we want almost all of the time while
5314 leaving default_breakpoint_* alone.
5315 ObjC: However, don't match an Objective-C method name which
5316 may have a '+' or '-' succeeded by a '[' */
5318 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5320 if (default_breakpoint_valid
5322 || ((strchr ("+-", (*address
)[0]) != NULL
)
5323 && ((*address
)[1] != '['))))
5324 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5325 default_breakpoint_line
, addr_string
,
5328 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5329 addr_string
, not_found_ptr
);
5331 /* For any SAL that didn't have a canonical string, fill one in. */
5332 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5333 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5334 if (addr_start
!= (*address
))
5337 for (i
= 0; i
< sals
->nelts
; i
++)
5339 /* Add the string if not present. */
5340 if ((*addr_string
)[i
] == NULL
)
5341 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5347 /* Convert each SAL into a real PC. Verify that the PC can be
5348 inserted as a breakpoint. If it can't throw an error. */
5351 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5355 for (i
= 0; i
< sals
->nelts
; i
++)
5356 resolve_sal_pc (&sals
->sals
[i
]);
5360 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5362 struct captured_parse_breakpoint_args
*args
= data
;
5364 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5365 args
->not_found_ptr
);
5368 /* Given TOK, a string specification of condition and thread, as
5369 accepted by the 'break' command, extract the condition
5370 string and thread number and set *COND_STRING and *THREAD.
5371 PC identifies the context at which the condition should be parsed.
5372 If no condition is found, *COND_STRING is set to NULL.
5373 If no thread is found, *THREAD is set to -1. */
5375 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5376 char **cond_string
, int *thread
)
5378 *cond_string
= NULL
;
5384 char *cond_start
= NULL
;
5385 char *cond_end
= NULL
;
5386 while (*tok
== ' ' || *tok
== '\t')
5391 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5394 toklen
= end_tok
- tok
;
5396 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5398 tok
= cond_start
= end_tok
+ 1;
5399 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5401 *cond_string
= savestring (cond_start
,
5402 cond_end
- cond_start
);
5404 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5410 *thread
= strtol (tok
, &tok
, 0);
5412 error (_("Junk after thread keyword."));
5413 if (!valid_thread_id (*thread
))
5414 error (_("Unknown thread %d."), *thread
);
5417 error (_("Junk at end of arguments."));
5421 /* Set a breakpoint. This function is shared between
5422 CLI and MI functions for setting a breakpoint.
5423 This function has two major modes of operations,
5424 selected by the PARSE_CONDITION_AND_THREAD parameter.
5425 If non-zero, the function will parse arg, extracting
5426 breakpoint location, address and thread. Otherwise,
5427 ARG is just the location of breakpoint, with condition
5428 and thread specified by the COND_STRING and THREAD
5432 break_command_really (char *arg
, char *cond_string
, int thread
,
5433 int parse_condition_and_thread
,
5434 int tempflag
, int hardwareflag
,
5436 enum auto_boolean pending_break_support
,
5437 struct breakpoint_ops
*ops
,
5440 struct gdb_exception e
;
5441 struct symtabs_and_lines sals
;
5442 struct symtab_and_line pending_sal
;
5445 char *addr_start
= arg
;
5447 struct cleanup
*old_chain
;
5448 struct cleanup
*breakpoint_chain
= NULL
;
5449 struct captured_parse_breakpoint_args parse_args
;
5458 parse_args
.arg_p
= &arg
;
5459 parse_args
.sals_p
= &sals
;
5460 parse_args
.addr_string_p
= &addr_string
;
5461 parse_args
.not_found_ptr
= ¬_found
;
5463 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5464 &parse_args
, RETURN_MASK_ALL
);
5466 /* If caller is interested in rc value from parse, set value. */
5470 throw_exception (e
);
5474 case NOT_FOUND_ERROR
:
5476 /* If pending breakpoint support is turned off, throw
5479 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5480 throw_exception (e
);
5482 exception_print (gdb_stderr
, e
);
5484 /* If pending breakpoint support is auto query and the user
5485 selects no, then simply return the error code. */
5486 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5487 !nquery ("Make breakpoint pending on future shared library load? "))
5490 /* At this point, either the user was queried about setting
5491 a pending breakpoint and selected yes, or pending
5492 breakpoint behavior is on and thus a pending breakpoint
5493 is defaulted on behalf of the user. */
5494 copy_arg
= xstrdup (addr_start
);
5495 addr_string
= ©_arg
;
5497 sals
.sals
= &pending_sal
;
5502 throw_exception (e
);
5509 /* Create a chain of things that always need to be cleaned up. */
5510 old_chain
= make_cleanup (null_cleanup
, 0);
5514 /* Make sure that all storage allocated to SALS gets freed. */
5515 make_cleanup (xfree
, sals
.sals
);
5517 /* Cleanup the addr_string array but not its contents. */
5518 make_cleanup (xfree
, addr_string
);
5521 /* ----------------------------- SNIP -----------------------------
5522 Anything added to the cleanup chain beyond this point is assumed
5523 to be part of a breakpoint. If the breakpoint create succeeds
5524 then the memory is not reclaimed. */
5525 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5527 /* Mark the contents of the addr_string for cleanup. These go on
5528 the breakpoint_chain and only occure if the breakpoint create
5530 for (i
= 0; i
< sals
.nelts
; i
++)
5532 if (addr_string
[i
] != NULL
)
5533 make_cleanup (xfree
, addr_string
[i
]);
5536 /* Resolve all line numbers to PC's and verify that the addresses
5537 are ok for the target. */
5539 breakpoint_sals_to_pc (&sals
, addr_start
);
5541 /* Verify that condition can be parsed, before setting any
5542 breakpoints. Allocate a separate condition expression for each
5546 if (parse_condition_and_thread
)
5548 /* Here we only parse 'arg' to separate condition
5549 from thread number, so parsing in context of first
5550 sal is OK. When setting the breakpoint we'll
5551 re-parse it in context of each sal. */
5554 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5556 make_cleanup (xfree
, cond_string
);
5560 /* Create a private copy of condition string. */
5563 cond_string
= xstrdup (cond_string
);
5564 make_cleanup (xfree
, cond_string
);
5567 create_breakpoints (sals
, addr_string
, cond_string
,
5568 hardwareflag
? bp_hardware_breakpoint
5570 tempflag
? disp_del
: disp_donttouch
,
5571 thread
, ignore_count
, ops
, from_tty
);
5575 struct symtab_and_line sal
= {0};
5576 struct breakpoint
*b
;
5578 make_cleanup (xfree
, copy_arg
);
5580 b
= set_raw_breakpoint_without_location (hardwareflag
5581 ? bp_hardware_breakpoint
5583 set_breakpoint_count (breakpoint_count
+ 1);
5584 b
->number
= breakpoint_count
;
5586 b
->addr_string
= addr_string
[0];
5587 b
->cond_string
= NULL
;
5588 b
->ignore_count
= ignore_count
;
5589 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5590 b
->condition_not_parsed
= 1;
5593 update_global_location_list (1);
5598 warning (_("Multiple breakpoints were set.\n"
5599 "Use the \"delete\" command to delete unwanted breakpoints."));
5600 /* That's it. Discard the cleanups for data inserted into the
5602 discard_cleanups (breakpoint_chain
);
5603 /* But cleanup everything else. */
5604 do_cleanups (old_chain
);
5607 /* Set a breakpoint.
5608 ARG is a string describing breakpoint address,
5609 condition, and thread.
5610 FLAG specifies if a breakpoint is hardware on,
5611 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5615 break_command_1 (char *arg
, int flag
, int from_tty
)
5617 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5618 int tempflag
= flag
& BP_TEMPFLAG
;
5620 break_command_really (arg
,
5621 NULL
, 0, 1 /* parse arg */,
5622 tempflag
, hardwareflag
,
5623 0 /* Ignore count */,
5624 pending_break_support
,
5625 NULL
/* breakpoint_ops */,
5631 set_breakpoint (char *address
, char *condition
,
5632 int hardwareflag
, int tempflag
,
5633 int thread
, int ignore_count
,
5636 break_command_really (address
, condition
, thread
,
5637 0 /* condition and thread are valid. */,
5638 tempflag
, hardwareflag
,
5641 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5645 /* Adjust SAL to the first instruction past the function prologue.
5646 The end of the prologue is determined using the line table from
5647 the debugging information.
5649 If SAL is already past the prologue, then do nothing. */
5652 skip_prologue_sal (struct symtab_and_line
*sal
)
5654 struct symbol
*sym
= find_pc_function (sal
->pc
);
5655 struct symtab_and_line start_sal
;
5660 start_sal
= find_function_start_sal (sym
, 1);
5661 if (sal
->pc
< start_sal
.pc
)
5665 /* Helper function for break_command_1 and disassemble_command. */
5668 resolve_sal_pc (struct symtab_and_line
*sal
)
5672 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5674 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5675 error (_("No line %d in file \"%s\"."),
5676 sal
->line
, sal
->symtab
->filename
);
5679 /* If this SAL corresponds to a breakpoint inserted using
5680 a line number, then skip the function prologue if necessary. */
5681 if (sal
->explicit_line
)
5682 skip_prologue_sal (sal
);
5685 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5687 struct blockvector
*bv
;
5691 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5694 sym
= block_linkage_function (b
);
5697 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5698 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5702 /* It really is worthwhile to have the section, so we'll just
5703 have to look harder. This case can be executed if we have
5704 line numbers but no functions (as can happen in assembly
5707 struct minimal_symbol
*msym
;
5709 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5711 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5718 break_command (char *arg
, int from_tty
)
5720 break_command_1 (arg
, 0, from_tty
);
5724 tbreak_command (char *arg
, int from_tty
)
5726 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5730 hbreak_command (char *arg
, int from_tty
)
5732 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5736 thbreak_command (char *arg
, int from_tty
)
5738 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5742 stop_command (char *arg
, int from_tty
)
5744 printf_filtered (_("Specify the type of breakpoint to set.\n\
5745 Usage: stop in <function | address>\n\
5746 stop at <line>\n"));
5750 stopin_command (char *arg
, int from_tty
)
5754 if (arg
== (char *) NULL
)
5756 else if (*arg
!= '*')
5761 /* look for a ':'. If this is a line number specification, then
5762 say it is bad, otherwise, it should be an address or
5763 function/method name */
5764 while (*argptr
&& !hasColon
)
5766 hasColon
= (*argptr
== ':');
5771 badInput
= (*argptr
!= ':'); /* Not a class::method */
5773 badInput
= isdigit (*arg
); /* a simple line number */
5777 printf_filtered (_("Usage: stop in <function | address>\n"));
5779 break_command_1 (arg
, 0, from_tty
);
5783 stopat_command (char *arg
, int from_tty
)
5787 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5794 /* look for a ':'. If there is a '::' then get out, otherwise
5795 it is probably a line number. */
5796 while (*argptr
&& !hasColon
)
5798 hasColon
= (*argptr
== ':');
5803 badInput
= (*argptr
== ':'); /* we have class::method */
5805 badInput
= !isdigit (*arg
); /* not a line number */
5809 printf_filtered (_("Usage: stop at <line>\n"));
5811 break_command_1 (arg
, 0, from_tty
);
5814 /* accessflag: hw_write: watch write,
5815 hw_read: watch read,
5816 hw_access: watch access (read or write) */
5818 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5820 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5821 struct symtab_and_line sal
;
5822 struct expression
*exp
;
5823 struct block
*exp_valid_block
;
5824 struct value
*val
, *mark
;
5825 struct frame_info
*frame
;
5826 struct frame_info
*prev_frame
= NULL
;
5827 char *exp_start
= NULL
;
5828 char *exp_end
= NULL
;
5829 char *tok
, *id_tok_start
, *end_tok
;
5831 char *cond_start
= NULL
;
5832 char *cond_end
= NULL
;
5833 struct expression
*cond
= NULL
;
5834 int i
, other_type_used
, target_resources_ok
= 0;
5835 enum bptype bp_type
;
5839 init_sal (&sal
); /* initialize to zeroes */
5841 /* Make sure that we actually have parameters to parse. */
5842 if (arg
!= NULL
&& arg
[0] != '\0')
5844 toklen
= strlen (arg
); /* Size of argument list. */
5846 /* Points tok to the end of the argument list. */
5847 tok
= arg
+ toklen
- 1;
5849 /* Go backwards in the parameters list. Skip the last parameter.
5850 If we're expecting a 'thread <thread_num>' parameter, this should
5851 be the thread identifier. */
5852 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5854 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5857 /* Points end_tok to the beginning of the last token. */
5858 id_tok_start
= tok
+ 1;
5860 /* Go backwards in the parameters list. Skip one more parameter.
5861 If we're expecting a 'thread <thread_num>' parameter, we should
5862 reach a "thread" token. */
5863 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5868 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5871 /* Move the pointer forward to skip the whitespace and
5872 calculate the length of the token. */
5874 toklen
= end_tok
- tok
;
5876 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5878 /* At this point we've found a "thread" token, which means
5879 the user is trying to set a watchpoint that triggers
5880 only in a specific thread. */
5883 /* Extract the thread ID from the next token. */
5884 thread
= strtol (id_tok_start
, &endp
, 0);
5886 /* Check if the user provided a valid numeric value for the
5888 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5889 error (_("Invalid thread ID specification %s."), id_tok_start
);
5891 /* Check if the thread actually exists. */
5892 if (!valid_thread_id (thread
))
5893 error (_("Unknown thread %d."), thread
);
5895 /* Truncate the string and get rid of the thread <thread_num>
5896 parameter before the parameter list is parsed by the
5897 evaluate_expression() function. */
5902 /* Parse the rest of the arguments. */
5903 innermost_block
= NULL
;
5905 exp
= parse_exp_1 (&arg
, 0, 0);
5907 exp_valid_block
= innermost_block
;
5908 mark
= value_mark ();
5909 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5911 release_value (val
);
5914 while (*tok
== ' ' || *tok
== '\t')
5918 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5921 toklen
= end_tok
- tok
;
5922 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5924 tok
= cond_start
= end_tok
+ 1;
5925 cond
= parse_exp_1 (&tok
, 0, 0);
5929 error (_("Junk at end of command."));
5931 if (accessflag
== hw_read
)
5932 bp_type
= bp_read_watchpoint
;
5933 else if (accessflag
== hw_access
)
5934 bp_type
= bp_access_watchpoint
;
5936 bp_type
= bp_hardware_watchpoint
;
5938 mem_cnt
= can_use_hardware_watchpoint (val
);
5939 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5940 error (_("Expression cannot be implemented with read/access watchpoint."));
5943 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5944 target_resources_ok
=
5945 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5947 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5948 error (_("Target does not support this type of hardware watchpoint."));
5950 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5951 error (_("Target can only support one kind of HW watchpoint at a time."));
5954 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5955 watchpoint could not be set. */
5956 if (!mem_cnt
|| target_resources_ok
<= 0)
5957 bp_type
= bp_watchpoint
;
5959 frame
= block_innermost_frame (exp_valid_block
);
5961 prev_frame
= get_prev_frame (frame
);
5965 /* If the expression is "local", then set up a "watchpoint scope"
5966 breakpoint at the point where we've left the scope of the watchpoint
5967 expression. Create the scope breakpoint before the watchpoint, so
5968 that we will encounter it first in bpstat_stop_status. */
5969 if (innermost_block
&& prev_frame
)
5971 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5972 bp_watchpoint_scope
);
5974 scope_breakpoint
->enable_state
= bp_enabled
;
5976 /* Automatically delete the breakpoint when it hits. */
5977 scope_breakpoint
->disposition
= disp_del
;
5979 /* Only break in the proper frame (help with recursion). */
5980 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5982 /* Set the address at which we will stop. */
5983 scope_breakpoint
->loc
->requested_address
5984 = get_frame_pc (prev_frame
);
5985 scope_breakpoint
->loc
->address
5986 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5987 scope_breakpoint
->type
);
5990 /* Now set up the breakpoint. */
5991 b
= set_raw_breakpoint (sal
, bp_type
);
5992 set_breakpoint_count (breakpoint_count
+ 1);
5993 b
->number
= breakpoint_count
;
5995 b
->disposition
= disp_donttouch
;
5997 b
->exp_valid_block
= exp_valid_block
;
5998 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6001 b
->loc
->cond
= cond
;
6003 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6008 b
->watchpoint_frame
= get_frame_id (frame
);
6010 b
->watchpoint_frame
= null_frame_id
;
6012 if (scope_breakpoint
!= NULL
)
6014 /* The scope breakpoint is related to the watchpoint. We will
6015 need to act on them together. */
6016 b
->related_breakpoint
= scope_breakpoint
;
6017 scope_breakpoint
->related_breakpoint
= b
;
6020 value_free_to_mark (mark
);
6022 update_global_location_list (1);
6025 /* Return count of locations need to be watched and can be handled
6026 in hardware. If the watchpoint can not be handled
6027 in hardware return zero. */
6030 can_use_hardware_watchpoint (struct value
*v
)
6032 int found_memory_cnt
= 0;
6033 struct value
*head
= v
;
6035 /* Did the user specifically forbid us to use hardware watchpoints? */
6036 if (!can_use_hw_watchpoints
)
6039 /* Make sure that the value of the expression depends only upon
6040 memory contents, and values computed from them within GDB. If we
6041 find any register references or function calls, we can't use a
6042 hardware watchpoint.
6044 The idea here is that evaluating an expression generates a series
6045 of values, one holding the value of every subexpression. (The
6046 expression a*b+c has five subexpressions: a, b, a*b, c, and
6047 a*b+c.) GDB's values hold almost enough information to establish
6048 the criteria given above --- they identify memory lvalues,
6049 register lvalues, computed values, etcetera. So we can evaluate
6050 the expression, and then scan the chain of values that leaves
6051 behind to decide whether we can detect any possible change to the
6052 expression's final value using only hardware watchpoints.
6054 However, I don't think that the values returned by inferior
6055 function calls are special in any way. So this function may not
6056 notice that an expression involving an inferior function call
6057 can't be watched with hardware watchpoints. FIXME. */
6058 for (; v
; v
= value_next (v
))
6060 if (VALUE_LVAL (v
) == lval_memory
)
6063 /* A lazy memory lvalue is one that GDB never needed to fetch;
6064 we either just used its address (e.g., `a' in `a.b') or
6065 we never needed it at all (e.g., `a' in `a,b'). */
6069 /* Ahh, memory we actually used! Check if we can cover
6070 it with hardware watchpoints. */
6071 struct type
*vtype
= check_typedef (value_type (v
));
6073 /* We only watch structs and arrays if user asked for it
6074 explicitly, never if they just happen to appear in a
6075 middle of some value chain. */
6077 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6078 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6080 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6081 int len
= TYPE_LENGTH (value_type (v
));
6083 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6090 else if (VALUE_LVAL (v
) != not_lval
6091 && deprecated_value_modifiable (v
) == 0)
6092 return 0; /* ??? What does this represent? */
6093 else if (VALUE_LVAL (v
) == lval_register
)
6094 return 0; /* cannot watch a register with a HW watchpoint */
6097 /* The expression itself looks suitable for using a hardware
6098 watchpoint, but give the target machine a chance to reject it. */
6099 return found_memory_cnt
;
6103 watch_command_wrapper (char *arg
, int from_tty
)
6105 watch_command (arg
, from_tty
);
6109 watch_command (char *arg
, int from_tty
)
6111 watch_command_1 (arg
, hw_write
, from_tty
);
6115 rwatch_command_wrapper (char *arg
, int from_tty
)
6117 rwatch_command (arg
, from_tty
);
6121 rwatch_command (char *arg
, int from_tty
)
6123 watch_command_1 (arg
, hw_read
, from_tty
);
6127 awatch_command_wrapper (char *arg
, int from_tty
)
6129 awatch_command (arg
, from_tty
);
6133 awatch_command (char *arg
, int from_tty
)
6135 watch_command_1 (arg
, hw_access
, from_tty
);
6139 /* Helper routines for the until_command routine in infcmd.c. Here
6140 because it uses the mechanisms of breakpoints. */
6142 struct until_break_command_continuation_args
6144 struct breakpoint
*breakpoint
;
6145 struct breakpoint
*breakpoint2
;
6148 /* This function is called by fetch_inferior_event via the
6149 cmd_continuation pointer, to complete the until command. It takes
6150 care of cleaning up the temporary breakpoints set up by the until
6153 until_break_command_continuation (void *arg
)
6155 struct until_break_command_continuation_args
*a
= arg
;
6157 delete_breakpoint (a
->breakpoint
);
6159 delete_breakpoint (a
->breakpoint2
);
6163 until_break_command (char *arg
, int from_tty
, int anywhere
)
6165 struct symtabs_and_lines sals
;
6166 struct symtab_and_line sal
;
6167 struct frame_info
*frame
= get_selected_frame (NULL
);
6168 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6169 struct breakpoint
*breakpoint
;
6170 struct breakpoint
*breakpoint2
= NULL
;
6171 struct cleanup
*old_chain
;
6173 clear_proceed_status ();
6175 /* Set a breakpoint where the user wants it and at return from
6178 if (default_breakpoint_valid
)
6179 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6180 default_breakpoint_line
, (char ***) NULL
, NULL
);
6182 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6183 0, (char ***) NULL
, NULL
);
6185 if (sals
.nelts
!= 1)
6186 error (_("Couldn't get information on specified line."));
6189 xfree (sals
.sals
); /* malloc'd, so freed */
6192 error (_("Junk at end of arguments."));
6194 resolve_sal_pc (&sal
);
6197 /* If the user told us to continue until a specified location,
6198 we don't specify a frame at which we need to stop. */
6199 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6201 /* Otherwise, specify the current frame, because we want to stop only
6202 at the very same frame. */
6203 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6206 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6208 /* Keep within the current frame, or in frames called by the current
6212 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6213 sal
.pc
= get_frame_pc (prev_frame
);
6214 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6216 make_cleanup_delete_breakpoint (breakpoint2
);
6219 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6221 /* If we are running asynchronously, and proceed call above has actually
6222 managed to start the target, arrange for breakpoints to be
6223 deleted when the target stops. Otherwise, we're already stopped and
6224 delete breakpoints via cleanup chain. */
6226 if (target_can_async_p () && is_running (inferior_ptid
))
6228 struct until_break_command_continuation_args
*args
;
6229 args
= xmalloc (sizeof (*args
));
6231 args
->breakpoint
= breakpoint
;
6232 args
->breakpoint2
= breakpoint2
;
6234 discard_cleanups (old_chain
);
6235 add_continuation (inferior_thread (),
6236 until_break_command_continuation
, args
,
6240 do_cleanups (old_chain
);
6244 ep_skip_leading_whitespace (char **s
)
6246 if ((s
== NULL
) || (*s
== NULL
))
6248 while (isspace (**s
))
6252 /* This function attempts to parse an optional "if <cond>" clause
6253 from the arg string. If one is not found, it returns NULL.
6255 Else, it returns a pointer to the condition string. (It does not
6256 attempt to evaluate the string against a particular block.) And,
6257 it updates arg to point to the first character following the parsed
6258 if clause in the arg string. */
6261 ep_parse_optional_if_clause (char **arg
)
6265 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6268 /* Skip the "if" keyword. */
6271 /* Skip any extra leading whitespace, and record the start of the
6272 condition string. */
6273 ep_skip_leading_whitespace (arg
);
6276 /* Assume that the condition occupies the remainder of the arg string. */
6277 (*arg
) += strlen (cond_string
);
6282 /* This function attempts to parse an optional filename from the arg
6283 string. If one is not found, it returns NULL.
6285 Else, it returns a pointer to the parsed filename. (This function
6286 makes no attempt to verify that a file of that name exists, or is
6287 accessible.) And, it updates arg to point to the first character
6288 following the parsed filename in the arg string.
6290 Note that clients needing to preserve the returned filename for
6291 future access should copy it to their own buffers. */
6293 ep_parse_optional_filename (char **arg
)
6295 static char filename
[1024];
6300 if ((*arg_p
== '\0') || isspace (*arg_p
))
6318 /* Commands to deal with catching events, such as signals, exceptions,
6319 process start/exit, etc. */
6323 catch_fork_temporary
, catch_vfork_temporary
,
6324 catch_fork_permanent
, catch_vfork_permanent
6329 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6331 char *cond_string
= NULL
;
6332 catch_fork_kind fork_kind
;
6335 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6336 tempflag
= (fork_kind
== catch_fork_temporary
6337 || fork_kind
== catch_vfork_temporary
);
6341 ep_skip_leading_whitespace (&arg
);
6343 /* The allowed syntax is:
6345 catch [v]fork if <cond>
6347 First, check if there's an if clause. */
6348 cond_string
= ep_parse_optional_if_clause (&arg
);
6350 if ((*arg
!= '\0') && !isspace (*arg
))
6351 error (_("Junk at end of arguments."));
6353 /* If this target supports it, create a fork or vfork catchpoint
6354 and enable reporting of such events. */
6357 case catch_fork_temporary
:
6358 case catch_fork_permanent
:
6359 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6360 &catch_fork_breakpoint_ops
);
6362 case catch_vfork_temporary
:
6363 case catch_vfork_permanent
:
6364 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6365 &catch_vfork_breakpoint_ops
);
6368 error (_("unsupported or unknown fork kind; cannot catch it"));
6374 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6377 char *cond_string
= NULL
;
6379 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6383 ep_skip_leading_whitespace (&arg
);
6385 /* The allowed syntax is:
6387 catch exec if <cond>
6389 First, check if there's an if clause. */
6390 cond_string
= ep_parse_optional_if_clause (&arg
);
6392 if ((*arg
!= '\0') && !isspace (*arg
))
6393 error (_("Junk at end of arguments."));
6395 /* If this target supports it, create an exec catchpoint
6396 and enable reporting of such events. */
6397 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6400 static enum print_stop_action
6401 print_exception_catchpoint (struct breakpoint
*b
)
6403 int bp_temp
, bp_throw
;
6405 annotate_catchpoint (b
->number
);
6407 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6408 if (b
->loc
->address
!= b
->loc
->requested_address
)
6409 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6412 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6414 bp_temp
? "Temporary catchpoint "
6416 if (!ui_out_is_mi_like_p (uiout
))
6417 ui_out_field_int (uiout
, "bkptno", b
->number
);
6419 bp_throw
? " (exception thrown), "
6420 : " (exception caught), ");
6421 if (ui_out_is_mi_like_p (uiout
))
6423 ui_out_field_string (uiout
, "reason",
6424 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6425 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6426 ui_out_field_int (uiout
, "bkptno", b
->number
);
6428 return PRINT_SRC_AND_LOC
;
6432 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6434 struct value_print_options opts
;
6435 get_user_print_options (&opts
);
6436 if (opts
.addressprint
)
6439 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6440 ui_out_field_string (uiout
, "addr", "<PENDING>");
6442 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6446 *last_addr
= b
->loc
->address
;
6447 if (strstr (b
->addr_string
, "throw") != NULL
)
6448 ui_out_field_string (uiout
, "what", "exception throw");
6450 ui_out_field_string (uiout
, "what", "exception catch");
6454 print_mention_exception_catchpoint (struct breakpoint
*b
)
6459 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6460 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6461 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6462 : _("Catchpoint "));
6463 ui_out_field_int (uiout
, "bkptno", b
->number
);
6464 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6468 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6471 NULL
, /* breakpoint_hit */
6472 print_exception_catchpoint
,
6473 print_one_exception_catchpoint
,
6474 print_mention_exception_catchpoint
6478 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6479 enum exception_event_kind ex_event
, int from_tty
)
6481 char *trigger_func_name
;
6483 if (ex_event
== EX_EVENT_CATCH
)
6484 trigger_func_name
= "__cxa_begin_catch";
6486 trigger_func_name
= "__cxa_throw";
6488 break_command_really (trigger_func_name
, cond_string
, -1,
6489 0 /* condition and thread are valid. */,
6492 AUTO_BOOLEAN_TRUE
/* pending */,
6493 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6498 /* Deal with "catch catch" and "catch throw" commands */
6501 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6502 int tempflag
, int from_tty
)
6504 char *cond_string
= NULL
;
6505 struct symtab_and_line
*sal
= NULL
;
6509 ep_skip_leading_whitespace (&arg
);
6511 cond_string
= ep_parse_optional_if_clause (&arg
);
6513 if ((*arg
!= '\0') && !isspace (*arg
))
6514 error (_("Junk at end of arguments."));
6516 if ((ex_event
!= EX_EVENT_THROW
) &&
6517 (ex_event
!= EX_EVENT_CATCH
))
6518 error (_("Unsupported or unknown exception event; cannot catch it"));
6520 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6523 warning (_("Unsupported with this platform/compiler combination."));
6526 /* Implementation of "catch catch" command. */
6529 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6531 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6532 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6535 /* Implementation of "catch throw" command. */
6538 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6540 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6541 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6544 /* Create a breakpoint struct for Ada exception catchpoints. */
6547 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6551 struct expression
*cond
,
6552 struct breakpoint_ops
*ops
,
6556 struct breakpoint
*b
;
6560 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6561 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6562 version for exception catchpoints, because two catchpoints
6563 used for different exception names will use the same address.
6564 In this case, a "breakpoint ... also set at..." warning is
6565 unproductive. Besides. the warning phrasing is also a bit
6566 inapropriate, we should use the word catchpoint, and tell
6567 the user what type of catchpoint it is. The above is good
6568 enough for now, though. */
6571 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6572 set_breakpoint_count (breakpoint_count
+ 1);
6574 b
->enable_state
= bp_enabled
;
6575 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6576 b
->number
= breakpoint_count
;
6577 b
->ignore_count
= 0;
6578 b
->loc
->cond
= cond
;
6579 b
->addr_string
= addr_string
;
6580 b
->language
= language_ada
;
6581 b
->cond_string
= cond_string
;
6582 b
->exp_string
= exp_string
;
6587 update_global_location_list (1);
6590 /* Implement the "catch exception" command. */
6593 catch_ada_exception_command (char *arg
, int from_tty
,
6594 struct cmd_list_element
*command
)
6597 struct symtab_and_line sal
;
6599 char *addr_string
= NULL
;
6600 char *exp_string
= NULL
;
6601 char *cond_string
= NULL
;
6602 struct expression
*cond
= NULL
;
6603 struct breakpoint_ops
*ops
= NULL
;
6605 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6609 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6610 &cond_string
, &cond
, &ops
);
6611 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6612 cond_string
, cond
, ops
, tempflag
,
6616 /* Implement the "catch assert" command. */
6619 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6622 struct symtab_and_line sal
;
6623 char *addr_string
= NULL
;
6624 struct breakpoint_ops
*ops
= NULL
;
6626 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6630 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6631 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6632 tempflag
, from_tty
);
6636 catch_command (char *arg
, int from_tty
)
6638 error (_("Catch requires an event name."));
6643 tcatch_command (char *arg
, int from_tty
)
6645 error (_("Catch requires an event name."));
6648 /* Delete breakpoints by address or line. */
6651 clear_command (char *arg
, int from_tty
)
6653 struct breakpoint
*b
;
6654 VEC(breakpoint_p
) *found
= 0;
6657 struct symtabs_and_lines sals
;
6658 struct symtab_and_line sal
;
6663 sals
= decode_line_spec (arg
, 1);
6668 sals
.sals
= (struct symtab_and_line
*)
6669 xmalloc (sizeof (struct symtab_and_line
));
6670 make_cleanup (xfree
, sals
.sals
);
6671 init_sal (&sal
); /* initialize to zeroes */
6672 sal
.line
= default_breakpoint_line
;
6673 sal
.symtab
= default_breakpoint_symtab
;
6674 sal
.pc
= default_breakpoint_address
;
6675 if (sal
.symtab
== 0)
6676 error (_("No source file specified."));
6684 /* We don't call resolve_sal_pc here. That's not
6685 as bad as it seems, because all existing breakpoints
6686 typically have both file/line and pc set. So, if
6687 clear is given file/line, we can match this to existing
6688 breakpoint without obtaining pc at all.
6690 We only support clearing given the address explicitly
6691 present in breakpoint table. Say, we've set breakpoint
6692 at file:line. There were several PC values for that file:line,
6693 due to optimization, all in one block.
6694 We've picked one PC value. If "clear" is issued with another
6695 PC corresponding to the same file:line, the breakpoint won't
6696 be cleared. We probably can still clear the breakpoint, but
6697 since the other PC value is never presented to user, user
6698 can only find it by guessing, and it does not seem important
6701 /* For each line spec given, delete bps which correspond
6702 to it. Do it in two passes, solely to preserve the current
6703 behavior that from_tty is forced true if we delete more than
6707 for (i
= 0; i
< sals
.nelts
; i
++)
6709 /* If exact pc given, clear bpts at that pc.
6710 If line given (pc == 0), clear all bpts on specified line.
6711 If defaulting, clear all bpts on default line
6714 defaulting sal.pc != 0 tests to do
6719 1 0 <can't happen> */
6723 /* Find all matching breakpoints and add them to
6728 /* Are we going to delete b? */
6729 if (b
->type
!= bp_none
6730 && b
->type
!= bp_watchpoint
6731 && b
->type
!= bp_hardware_watchpoint
6732 && b
->type
!= bp_read_watchpoint
6733 && b
->type
!= bp_access_watchpoint
)
6735 struct bp_location
*loc
= b
->loc
;
6736 for (; loc
; loc
= loc
->next
)
6738 int pc_match
= sal
.pc
6739 && (loc
->address
== sal
.pc
)
6740 && (!section_is_overlay (loc
->section
)
6741 || loc
->section
== sal
.section
);
6742 int line_match
= ((default_match
|| (0 == sal
.pc
))
6743 && b
->source_file
!= NULL
6744 && sal
.symtab
!= NULL
6745 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6746 && b
->line_number
== sal
.line
);
6747 if (pc_match
|| line_match
)
6756 VEC_safe_push(breakpoint_p
, found
, b
);
6759 /* Now go thru the 'found' chain and delete them. */
6760 if (VEC_empty(breakpoint_p
, found
))
6763 error (_("No breakpoint at %s."), arg
);
6765 error (_("No breakpoint at this line."));
6768 if (VEC_length(breakpoint_p
, found
) > 1)
6769 from_tty
= 1; /* Always report if deleted more than one */
6772 if (VEC_length(breakpoint_p
, found
) == 1)
6773 printf_unfiltered (_("Deleted breakpoint "));
6775 printf_unfiltered (_("Deleted breakpoints "));
6777 breakpoints_changed ();
6779 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6782 printf_unfiltered ("%d ", b
->number
);
6783 delete_breakpoint (b
);
6786 putchar_unfiltered ('\n');
6789 /* Delete breakpoint in BS if they are `delete' breakpoints and
6790 all breakpoints that are marked for deletion, whether hit or not.
6791 This is called after any breakpoint is hit, or after errors. */
6794 breakpoint_auto_delete (bpstat bs
)
6796 struct breakpoint
*b
, *temp
;
6798 for (; bs
; bs
= bs
->next
)
6799 if (bs
->breakpoint_at
6800 && bs
->breakpoint_at
->owner
6801 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6803 delete_breakpoint (bs
->breakpoint_at
->owner
);
6805 ALL_BREAKPOINTS_SAFE (b
, temp
)
6807 if (b
->disposition
== disp_del_at_next_stop
)
6808 delete_breakpoint (b
);
6812 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
6813 into the inferior, only remove already-inserted locations that no
6814 longer should be inserted. Functions that delete a breakpoint or
6815 breakpoints should pass false, so that deleting a breakpoint
6816 doesn't have the side effect of inserting the locations of other
6817 breakpoints that are marked not-inserted, but should_be_inserted
6818 returns true on them.
6820 This behaviour is useful is situations close to tear-down -- e.g.,
6821 after an exec, while the target still has execution, but breakpoint
6822 shadows of the previous executable image should *NOT* be restored
6823 to the new image; or before detaching, where the target still has
6824 execution and wants to delete breakpoints from GDB's lists, and all
6825 breakpoints had already been removed from the inferior. */
6828 update_global_location_list (int should_insert
)
6830 struct breakpoint
*b
;
6831 struct bp_location
**next
= &bp_location_chain
;
6832 struct bp_location
*loc
;
6833 struct bp_location
*loc2
;
6834 struct gdb_exception e
;
6835 VEC(bp_location_p
) *old_locations
= NULL
;
6839 /* Store old locations for future reference. */
6840 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6841 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6843 bp_location_chain
= NULL
;
6846 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6849 next
= &(loc
->global_next
);
6854 /* Identify bp_location instances that are no longer present in the new
6855 list, and therefore should be freed. Note that it's not necessary that
6856 those locations should be removed from inferior -- if there's another
6857 location at the same address (previously marked as duplicate),
6858 we don't need to remove/insert the location. */
6859 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6861 /* Tells if 'loc' is found amoung the new locations. If not, we
6863 int found_object
= 0;
6864 /* Tells if the location should remain inserted in the target. */
6865 int keep_in_target
= 0;
6867 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6874 /* If this location is no longer present, and inserted, look if there's
6875 maybe a new location at the same address. If so, mark that one
6876 inserted, and don't remove this one. This is needed so that we
6877 don't have a time window where a breakpoint at certain location is not
6882 /* If the location is inserted now, we might have to remove it. */
6884 if (found_object
&& should_be_inserted (loc
))
6886 /* The location is still present in the location list, and still
6887 should be inserted. Don't do anything. */
6892 /* The location is either no longer present, or got disabled.
6893 See if there's another location at the same address, in which
6894 case we don't need to remove this one from the target. */
6895 if (breakpoint_address_is_meaningful (loc
->owner
))
6896 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6898 /* For the sake of should_insert_location. The
6899 call to check_duplicates will fix up this later. */
6900 loc2
->duplicate
= 0;
6901 if (should_be_inserted (loc2
)
6902 && loc2
!= loc
&& loc2
->address
== loc
->address
)
6905 loc2
->target_info
= loc
->target_info
;
6912 if (!keep_in_target
)
6914 if (remove_breakpoint (loc
, mark_uninserted
))
6916 /* This is just about all we can do. We could keep this
6917 location on the global list, and try to remove it next
6918 time, but there's no particular reason why we will
6921 Note that at this point, loc->owner is still valid,
6922 as delete_breakpoint frees the breakpoint only
6923 after calling us. */
6924 printf_filtered (_("warning: Error removing breakpoint %d\n"),
6925 loc
->owner
->number
);
6933 if (removed
&& non_stop
)
6935 /* This location was removed from the targets. In non-stop mode,
6936 a race condition is possible where we've removed a breakpoint,
6937 but stop events for that breakpoint are already queued and will
6938 arrive later. To suppress spurious SIGTRAPs reported to user,
6939 we keep this breakpoint location for a bit, and will retire it
6940 after we see 3 * thread_count events.
6941 The theory here is that reporting of events should,
6942 "on the average", be fair, so after that many event we'll see
6943 events from all threads that have anything of interest, and no
6944 longer need to keep this breakpoint. This is just a
6945 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
6946 which is usability issue, but not a correctness problem. */
6947 loc
->events_till_retirement
= 3 * (thread_count () + 1);
6950 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
6953 free_bp_location (loc
);
6959 check_duplicates (b
);
6962 if (breakpoints_always_inserted_mode () && should_insert
6963 && (target_has_execution
6964 || (gdbarch_has_global_solist (target_gdbarch
)
6965 && target_supports_multi_process ())))
6966 insert_breakpoint_locations ();
6970 breakpoint_retire_moribund (void)
6972 struct bp_location
*loc
;
6975 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
6976 if (--(loc
->events_till_retirement
) == 0)
6978 free_bp_location (loc
);
6979 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
6985 update_global_location_list_nothrow (int inserting
)
6987 struct gdb_exception e
;
6988 TRY_CATCH (e
, RETURN_MASK_ERROR
)
6989 update_global_location_list (inserting
);
6992 /* Clear BPT from a BPS. */
6994 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
6997 for (bs
= bps
; bs
; bs
= bs
->next
)
6998 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7000 bs
->breakpoint_at
= NULL
;
7002 /* bs->commands will be freed later. */
7006 /* Callback for iterate_over_threads. */
7008 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7010 struct breakpoint
*bpt
= data
;
7011 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7015 /* Delete a breakpoint and clean up all traces of it in the data
7019 delete_breakpoint (struct breakpoint
*bpt
)
7021 struct breakpoint
*b
;
7022 struct bp_location
*loc
, *next
;
7024 gdb_assert (bpt
!= NULL
);
7026 /* Has this bp already been deleted? This can happen because multiple
7027 lists can hold pointers to bp's. bpstat lists are especial culprits.
7029 One example of this happening is a watchpoint's scope bp. When the
7030 scope bp triggers, we notice that the watchpoint is out of scope, and
7031 delete it. We also delete its scope bp. But the scope bp is marked
7032 "auto-deleting", and is already on a bpstat. That bpstat is then
7033 checked for auto-deleting bp's, which are deleted.
7035 A real solution to this problem might involve reference counts in bp's,
7036 and/or giving them pointers back to their referencing bpstat's, and
7037 teaching delete_breakpoint to only free a bp's storage when no more
7038 references were extent. A cheaper bandaid was chosen. */
7039 if (bpt
->type
== bp_none
)
7042 observer_notify_breakpoint_deleted (bpt
->number
);
7044 if (breakpoint_chain
== bpt
)
7045 breakpoint_chain
= bpt
->next
;
7050 b
->next
= bpt
->next
;
7054 free_command_lines (&bpt
->commands
);
7055 if (bpt
->cond_string
!= NULL
)
7056 xfree (bpt
->cond_string
);
7057 if (bpt
->addr_string
!= NULL
)
7058 xfree (bpt
->addr_string
);
7059 if (bpt
->exp
!= NULL
)
7061 if (bpt
->exp_string
!= NULL
)
7062 xfree (bpt
->exp_string
);
7063 if (bpt
->val
!= NULL
)
7064 value_free (bpt
->val
);
7065 if (bpt
->source_file
!= NULL
)
7066 xfree (bpt
->source_file
);
7067 if (bpt
->exec_pathname
!= NULL
)
7068 xfree (bpt
->exec_pathname
);
7070 /* Be sure no bpstat's are pointing at it after it's been freed. */
7071 /* FIXME, how can we find all bpstat's?
7072 We just check stop_bpstat for now. Note that we cannot just
7073 remove bpstats pointing at bpt from the stop_bpstat list
7074 entirely, as breakpoint commands are associated with the bpstat;
7075 if we remove it here, then the later call to
7076 bpstat_do_actions (&stop_bpstat);
7077 in event-top.c won't do anything, and temporary breakpoints
7078 with commands won't work. */
7080 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7082 /* Now that breakpoint is removed from breakpoint
7083 list, update the global location list. This
7084 will remove locations that used to belong to
7085 this breakpoint. Do this before freeing
7086 the breakpoint itself, since remove_breakpoint
7087 looks at location's owner. It might be better
7088 design to have location completely self-contained,
7089 but it's not the case now. */
7090 update_global_location_list (0);
7093 /* On the chance that someone will soon try again to delete this same
7094 bp, we mark it as deleted before freeing its storage. */
7095 bpt
->type
= bp_none
;
7101 do_delete_breakpoint_cleanup (void *b
)
7103 delete_breakpoint (b
);
7107 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7109 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7113 delete_command (char *arg
, int from_tty
)
7115 struct breakpoint
*b
, *temp
;
7121 int breaks_to_delete
= 0;
7123 /* Delete all breakpoints if no argument.
7124 Do not delete internal or call-dummy breakpoints, these
7125 have to be deleted with an explicit breakpoint number argument. */
7128 if (b
->type
!= bp_call_dummy
&&
7129 b
->type
!= bp_shlib_event
&&
7130 b
->type
!= bp_thread_event
&&
7131 b
->type
!= bp_overlay_event
&&
7134 breaks_to_delete
= 1;
7139 /* Ask user only if there are some breakpoints to delete. */
7141 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7143 ALL_BREAKPOINTS_SAFE (b
, temp
)
7145 if (b
->type
!= bp_call_dummy
&&
7146 b
->type
!= bp_shlib_event
&&
7147 b
->type
!= bp_thread_event
&&
7148 b
->type
!= bp_overlay_event
&&
7150 delete_breakpoint (b
);
7155 map_breakpoint_numbers (arg
, delete_breakpoint
);
7159 all_locations_are_pending (struct bp_location
*loc
)
7161 for (; loc
; loc
= loc
->next
)
7162 if (!loc
->shlib_disabled
)
7167 /* Subroutine of update_breakpoint_locations to simplify it.
7168 Return non-zero if multiple fns in list LOC have the same name.
7169 Null names are ignored. */
7172 ambiguous_names_p (struct bp_location
*loc
)
7174 struct bp_location
*l
;
7175 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7176 (int (*) (const void *, const void *)) streq
,
7177 NULL
, xcalloc
, xfree
);
7179 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7182 const char *name
= l
->function_name
;
7184 /* Allow for some names to be NULL, ignore them. */
7188 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7190 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7205 update_breakpoint_locations (struct breakpoint
*b
,
7206 struct symtabs_and_lines sals
)
7210 struct bp_location
*existing_locations
= b
->loc
;
7212 /* If there's no new locations, and all existing locations
7213 are pending, don't do anything. This optimizes
7214 the common case where all locations are in the same
7215 shared library, that was unloaded. We'd like to
7216 retain the location, so that when the library
7217 is loaded again, we don't loose the enabled/disabled
7218 status of the individual locations. */
7219 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7224 for (i
= 0; i
< sals
.nelts
; ++i
)
7226 struct bp_location
*new_loc
=
7227 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7229 /* Reparse conditions, they might contain references to the
7231 if (b
->cond_string
!= NULL
)
7233 struct gdb_exception e
;
7236 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7238 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7243 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7244 b
->number
, e
.message
);
7245 new_loc
->enabled
= 0;
7249 if (b
->source_file
!= NULL
)
7250 xfree (b
->source_file
);
7251 if (sals
.sals
[i
].symtab
== NULL
)
7252 b
->source_file
= NULL
;
7255 savestring (sals
.sals
[i
].symtab
->filename
,
7256 strlen (sals
.sals
[i
].symtab
->filename
));
7258 if (b
->line_number
== 0)
7259 b
->line_number
= sals
.sals
[i
].line
;
7262 /* Update locations of permanent breakpoints. */
7263 if (b
->enable_state
== bp_permanent
)
7264 make_breakpoint_permanent (b
);
7266 /* If possible, carry over 'disable' status from existing breakpoints. */
7268 struct bp_location
*e
= existing_locations
;
7269 /* If there are multiple breakpoints with the same function name,
7270 e.g. for inline functions, comparing function names won't work.
7271 Instead compare pc addresses; this is just a heuristic as things
7272 may have moved, but in practice it gives the correct answer
7273 often enough until a better solution is found. */
7274 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7276 for (; e
; e
= e
->next
)
7278 if (!e
->enabled
&& e
->function_name
)
7280 struct bp_location
*l
= b
->loc
;
7281 if (have_ambiguous_names
)
7283 for (; l
; l
= l
->next
)
7284 if (e
->address
== l
->address
)
7292 for (; l
; l
= l
->next
)
7293 if (l
->function_name
7294 && strcmp (e
->function_name
, l
->function_name
) == 0)
7304 update_global_location_list (1);
7308 /* Reset a breakpoint given it's struct breakpoint * BINT.
7309 The value we return ends up being the return value from catch_errors.
7310 Unused in this case. */
7313 breakpoint_re_set_one (void *bint
)
7315 /* get past catch_errs */
7316 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7320 int *not_found_ptr
= ¬_found
;
7321 struct symtabs_and_lines sals
= {};
7322 struct symtabs_and_lines expanded
;
7324 enum enable_state save_enable
;
7325 struct gdb_exception e
;
7331 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7335 case bp_hardware_breakpoint
:
7336 if (b
->addr_string
== NULL
)
7338 /* Anything without a string can't be re-set. */
7339 delete_breakpoint (b
);
7343 set_language (b
->language
);
7344 input_radix
= b
->input_radix
;
7346 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7348 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7353 int not_found_and_ok
= 0;
7354 /* For pending breakpoints, it's expected that parsing
7355 will fail until the right shared library is loaded.
7356 User has already told to create pending breakpoints and
7357 don't need extra messages. If breakpoint is in bp_shlib_disabled
7358 state, then user already saw the message about that breakpoint
7359 being disabled, and don't want to see more errors. */
7361 && (b
->condition_not_parsed
7362 || (b
->loc
&& b
->loc
->shlib_disabled
)
7363 || b
->enable_state
== bp_disabled
))
7364 not_found_and_ok
= 1;
7366 if (!not_found_and_ok
)
7368 /* We surely don't want to warn about the same breakpoint
7369 10 times. One solution, implemented here, is disable
7370 the breakpoint on error. Another solution would be to
7371 have separate 'warning emitted' flag. Since this
7372 happens only when a binary has changed, I don't know
7373 which approach is better. */
7374 b
->enable_state
= bp_disabled
;
7375 throw_exception (e
);
7382 gdb_assert (sals
.nelts
== 1);
7383 resolve_sal_pc (&sals
.sals
[0]);
7384 if (b
->condition_not_parsed
&& s
&& s
[0])
7386 char *cond_string
= 0;
7388 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7389 &cond_string
, &thread
);
7391 b
->cond_string
= cond_string
;
7393 b
->condition_not_parsed
= 0;
7395 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7396 update_breakpoint_locations (b
, expanded
);
7402 case bp_hardware_watchpoint
:
7403 case bp_read_watchpoint
:
7404 case bp_access_watchpoint
:
7405 /* Watchpoint can be either on expression using entirely global variables,
7406 or it can be on local variables.
7408 Watchpoints of the first kind are never auto-deleted, and even persist
7409 across program restarts. Since they can use variables from shared
7410 libraries, we need to reparse expression as libraries are loaded
7413 Watchpoints on local variables can also change meaning as result
7414 of solib event. For example, if a watchpoint uses both a local and
7415 a global variables in expression, it's a local watchpoint, but
7416 unloading of a shared library will make the expression invalid.
7417 This is not a very common use case, but we still re-evaluate
7418 expression, to avoid surprises to the user.
7420 Note that for local watchpoints, we re-evaluate it only if
7421 watchpoints frame id is still valid. If it's not, it means
7422 the watchpoint is out of scope and will be deleted soon. In fact,
7423 I'm not sure we'll ever be called in this case.
7425 If a local watchpoint's frame id is still valid, then
7426 b->exp_valid_block is likewise valid, and we can safely use it.
7428 Don't do anything about disabled watchpoints, since they will
7429 be reevaluated again when enabled. */
7430 update_watchpoint (b
, 1 /* reparse */);
7432 /* We needn't really do anything to reset these, since the mask
7433 that requests them is unaffected by e.g., new libraries being
7439 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7441 /* Delete overlay event breakpoints; they will be reset later by
7442 breakpoint_re_set. */
7443 case bp_overlay_event
:
7444 delete_breakpoint (b
);
7447 /* This breakpoint is special, it's set up when the inferior
7448 starts and we really don't want to touch it. */
7449 case bp_shlib_event
:
7451 /* Like bp_shlib_event, this breakpoint type is special.
7452 Once it is set up, we do not want to touch it. */
7453 case bp_thread_event
:
7455 /* Keep temporary breakpoints, which can be encountered when we step
7456 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7457 Otherwise these should have been blown away via the cleanup chain
7458 or by breakpoint_init_inferior when we rerun the executable. */
7461 case bp_watchpoint_scope
:
7463 case bp_step_resume
:
7465 case bp_longjmp_resume
:
7472 /* Re-set all breakpoints after symbols have been re-loaded. */
7474 breakpoint_re_set (void)
7476 struct breakpoint
*b
, *temp
;
7477 enum language save_language
;
7478 int save_input_radix
;
7480 save_language
= current_language
->la_language
;
7481 save_input_radix
= input_radix
;
7482 ALL_BREAKPOINTS_SAFE (b
, temp
)
7484 /* Format possible error msg */
7485 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7487 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7488 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7489 do_cleanups (cleanups
);
7491 set_language (save_language
);
7492 input_radix
= save_input_radix
;
7494 create_overlay_event_breakpoint ("_ovly_debug_event");
7497 /* Reset the thread number of this breakpoint:
7499 - If the breakpoint is for all threads, leave it as-is.
7500 - Else, reset it to the current thread for inferior_ptid. */
7502 breakpoint_re_set_thread (struct breakpoint
*b
)
7504 if (b
->thread
!= -1)
7506 if (in_thread_list (inferior_ptid
))
7507 b
->thread
= pid_to_thread_id (inferior_ptid
);
7511 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7512 If from_tty is nonzero, it prints a message to that effect,
7513 which ends with a period (no newline). */
7516 set_ignore_count (int bptnum
, int count
, int from_tty
)
7518 struct breakpoint
*b
;
7524 if (b
->number
== bptnum
)
7526 b
->ignore_count
= count
;
7530 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7532 else if (count
== 1)
7533 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7536 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7539 breakpoints_changed ();
7540 observer_notify_breakpoint_modified (b
->number
);
7544 error (_("No breakpoint number %d."), bptnum
);
7548 make_breakpoint_silent (struct breakpoint
*b
)
7550 /* Silence the breakpoint. */
7554 /* Command to set ignore-count of breakpoint N to COUNT. */
7557 ignore_command (char *args
, int from_tty
)
7563 error_no_arg (_("a breakpoint number"));
7565 num
= get_number (&p
);
7567 error (_("bad breakpoint number: '%s'"), args
);
7569 error (_("Second argument (specified ignore-count) is missing."));
7571 set_ignore_count (num
,
7572 longest_to_int (value_as_long (parse_and_eval (p
))),
7575 printf_filtered ("\n");
7578 /* Call FUNCTION on each of the breakpoints
7579 whose numbers are given in ARGS. */
7582 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7587 struct breakpoint
*b
, *tmp
;
7591 error_no_arg (_("one or more breakpoint numbers"));
7598 num
= get_number_or_range (&p1
);
7601 warning (_("bad breakpoint number at or near '%s'"), p
);
7605 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7606 if (b
->number
== num
)
7608 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7611 if (related_breakpoint
)
7612 function (related_breakpoint
);
7616 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7622 static struct bp_location
*
7623 find_location_by_number (char *number
)
7625 char *dot
= strchr (number
, '.');
7629 struct breakpoint
*b
;
7630 struct bp_location
*loc
;
7635 bp_num
= get_number_or_range (&p1
);
7637 error (_("Bad breakpoint number '%s'"), number
);
7640 if (b
->number
== bp_num
)
7645 if (!b
|| b
->number
!= bp_num
)
7646 error (_("Bad breakpoint number '%s'"), number
);
7649 loc_num
= get_number_or_range (&p1
);
7651 error (_("Bad breakpoint location number '%s'"), number
);
7655 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7658 error (_("Bad breakpoint location number '%s'"), dot
+1);
7664 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7665 If from_tty is nonzero, it prints a message to that effect,
7666 which ends with a period (no newline). */
7669 disable_breakpoint (struct breakpoint
*bpt
)
7671 /* Never disable a watchpoint scope breakpoint; we want to
7672 hit them when we leave scope so we can delete both the
7673 watchpoint and its scope breakpoint at that time. */
7674 if (bpt
->type
== bp_watchpoint_scope
)
7677 /* You can't disable permanent breakpoints. */
7678 if (bpt
->enable_state
== bp_permanent
)
7681 bpt
->enable_state
= bp_disabled
;
7683 update_global_location_list (0);
7685 observer_notify_breakpoint_modified (bpt
->number
);
7689 disable_command (char *args
, int from_tty
)
7691 struct breakpoint
*bpt
;
7693 ALL_BREAKPOINTS (bpt
)
7697 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7702 case bp_hardware_breakpoint
:
7704 case bp_hardware_watchpoint
:
7705 case bp_read_watchpoint
:
7706 case bp_access_watchpoint
:
7707 disable_breakpoint (bpt
);
7711 else if (strchr (args
, '.'))
7713 struct bp_location
*loc
= find_location_by_number (args
);
7716 update_global_location_list (0);
7719 map_breakpoint_numbers (args
, disable_breakpoint
);
7723 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7725 int target_resources_ok
, other_type_used
;
7728 if (bpt
->type
== bp_hardware_breakpoint
)
7731 i
= hw_breakpoint_used_count ();
7732 target_resources_ok
=
7733 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7735 if (target_resources_ok
== 0)
7736 error (_("No hardware breakpoint support in the target."));
7737 else if (target_resources_ok
< 0)
7738 error (_("Hardware breakpoints used exceeds limit."));
7741 if (bpt
->type
== bp_watchpoint
||
7742 bpt
->type
== bp_hardware_watchpoint
||
7743 bpt
->type
== bp_read_watchpoint
||
7744 bpt
->type
== bp_access_watchpoint
)
7746 struct frame_id saved_frame_id
;
7748 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7749 if (bpt
->exp_valid_block
!= NULL
)
7751 struct frame_info
*fr
=
7752 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7755 printf_filtered (_("\
7756 Cannot enable watchpoint %d because the block in which its expression\n\
7757 is valid is not currently in scope.\n"), bpt
->number
);
7764 value_free (bpt
->val
);
7765 mark
= value_mark ();
7766 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7768 release_value (bpt
->val
);
7771 if (bpt
->type
== bp_hardware_watchpoint
||
7772 bpt
->type
== bp_read_watchpoint
||
7773 bpt
->type
== bp_access_watchpoint
)
7775 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7776 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7778 /* Hack around 'unused var' error for some targets here */
7779 (void) mem_cnt
, (void) i
;
7780 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7781 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7782 /* we can consider of type is bp_hardware_watchpoint, convert to
7783 bp_watchpoint in the following condition */
7784 if (target_resources_ok
< 0)
7786 printf_filtered (_("\
7787 Cannot enable watchpoint %d because target watch resources\n\
7788 have been allocated for other watchpoints.\n"), bpt
->number
);
7789 value_free_to_mark (mark
);
7794 select_frame (frame_find_by_id (saved_frame_id
));
7795 value_free_to_mark (mark
);
7798 if (bpt
->enable_state
!= bp_permanent
)
7799 bpt
->enable_state
= bp_enabled
;
7800 bpt
->disposition
= disposition
;
7801 update_global_location_list (1);
7802 breakpoints_changed ();
7804 observer_notify_breakpoint_modified (bpt
->number
);
7809 enable_breakpoint (struct breakpoint
*bpt
)
7811 do_enable_breakpoint (bpt
, bpt
->disposition
);
7814 /* The enable command enables the specified breakpoints (or all defined
7815 breakpoints) so they once again become (or continue to be) effective
7816 in stopping the inferior. */
7819 enable_command (char *args
, int from_tty
)
7821 struct breakpoint
*bpt
;
7823 ALL_BREAKPOINTS (bpt
)
7827 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7832 case bp_hardware_breakpoint
:
7834 case bp_hardware_watchpoint
:
7835 case bp_read_watchpoint
:
7836 case bp_access_watchpoint
:
7837 enable_breakpoint (bpt
);
7841 else if (strchr (args
, '.'))
7843 struct bp_location
*loc
= find_location_by_number (args
);
7846 update_global_location_list (1);
7849 map_breakpoint_numbers (args
, enable_breakpoint
);
7853 enable_once_breakpoint (struct breakpoint
*bpt
)
7855 do_enable_breakpoint (bpt
, disp_disable
);
7859 enable_once_command (char *args
, int from_tty
)
7861 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7865 enable_delete_breakpoint (struct breakpoint
*bpt
)
7867 do_enable_breakpoint (bpt
, disp_del
);
7871 enable_delete_command (char *args
, int from_tty
)
7873 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7877 set_breakpoint_cmd (char *args
, int from_tty
)
7882 show_breakpoint_cmd (char *args
, int from_tty
)
7886 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7888 struct symtabs_and_lines
7889 decode_line_spec_1 (char *string
, int funfirstline
)
7891 struct symtabs_and_lines sals
;
7893 error (_("Empty line specification."));
7894 if (default_breakpoint_valid
)
7895 sals
= decode_line_1 (&string
, funfirstline
,
7896 default_breakpoint_symtab
,
7897 default_breakpoint_line
,
7898 (char ***) NULL
, NULL
);
7900 sals
= decode_line_1 (&string
, funfirstline
,
7901 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7903 error (_("Junk at end of line specification: %s"), string
);
7907 /* Create and insert a raw software breakpoint at PC. Return an
7908 identifier, which should be used to remove the breakpoint later.
7909 In general, places which call this should be using something on the
7910 breakpoint chain instead; this function should be eliminated
7914 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7916 struct bp_target_info
*bp_tgt
;
7918 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7919 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7921 bp_tgt
->placed_address
= pc
;
7922 if (target_insert_breakpoint (bp_tgt
) != 0)
7924 /* Could not insert the breakpoint. */
7932 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7935 deprecated_remove_raw_breakpoint (void *bp
)
7937 struct bp_target_info
*bp_tgt
= bp
;
7940 ret
= target_remove_breakpoint (bp_tgt
);
7946 /* One (or perhaps two) breakpoints used for software single stepping. */
7948 static void *single_step_breakpoints
[2];
7950 /* Create and insert a breakpoint for software single step. */
7953 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7957 if (single_step_breakpoints
[0] == NULL
)
7958 bpt_p
= &single_step_breakpoints
[0];
7961 gdb_assert (single_step_breakpoints
[1] == NULL
);
7962 bpt_p
= &single_step_breakpoints
[1];
7965 /* NOTE drow/2006-04-11: A future improvement to this function would be
7966 to only create the breakpoints once, and actually put them on the
7967 breakpoint chain. That would let us use set_raw_breakpoint. We could
7968 adjust the addresses each time they were needed. Doing this requires
7969 corresponding changes elsewhere where single step breakpoints are
7970 handled, however. So, for now, we use this. */
7972 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7974 error (_("Could not insert single-step breakpoint at 0x%s"),
7975 paddr_nz (next_pc
));
7978 /* Remove and delete any breakpoints used for software single step. */
7981 remove_single_step_breakpoints (void)
7983 gdb_assert (single_step_breakpoints
[0] != NULL
);
7985 /* See insert_single_step_breakpoint for more about this deprecated
7987 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7988 single_step_breakpoints
[0] = NULL
;
7990 if (single_step_breakpoints
[1] != NULL
)
7992 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7993 single_step_breakpoints
[1] = NULL
;
7997 /* Check whether a software single-step breakpoint is inserted at PC. */
8000 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8004 for (i
= 0; i
< 2; i
++)
8006 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8007 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8015 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8016 It is defined as a macro to prevent duplication.
8017 COMMAND should be a string constant containing the name of the command. */
8018 #define BREAK_ARGS_HELP(command) \
8019 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8020 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8021 If a line number is specified, break at start of code for that line.\n\
8022 If a function is specified, break at start of code for that function.\n\
8023 If an address is specified, break at that exact address.\n\
8024 With no LOCATION, uses current execution address of selected stack frame.\n\
8025 This is useful for breaking on return to a stack frame.\n\
8027 THREADNUM is the number from \"info threads\".\n\
8028 CONDITION is a boolean expression.\n\
8030 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8032 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8034 /* List of subcommands for "catch". */
8035 static struct cmd_list_element
*catch_cmdlist
;
8037 /* List of subcommands for "tcatch". */
8038 static struct cmd_list_element
*tcatch_cmdlist
;
8040 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8041 lists, and pass some additional user data to the command function. */
8043 add_catch_command (char *name
, char *docstring
,
8044 void (*sfunc
) (char *args
, int from_tty
,
8045 struct cmd_list_element
*command
),
8046 void *user_data_catch
,
8047 void *user_data_tcatch
)
8049 struct cmd_list_element
*command
;
8051 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8053 set_cmd_sfunc (command
, sfunc
);
8054 set_cmd_context (command
, user_data_catch
);
8056 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8058 set_cmd_sfunc (command
, sfunc
);
8059 set_cmd_context (command
, user_data_tcatch
);
8063 _initialize_breakpoint (void)
8065 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8066 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8067 struct cmd_list_element
*c
;
8069 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8071 breakpoint_chain
= 0;
8072 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8073 before a breakpoint is set. */
8074 breakpoint_count
= 0;
8076 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8077 Set ignore-count of breakpoint number N to COUNT.\n\
8078 Usage is `ignore N COUNT'."));
8080 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8082 add_com ("commands", class_breakpoint
, commands_command
, _("\
8083 Set commands to be executed when a breakpoint is hit.\n\
8084 Give breakpoint number as argument after \"commands\".\n\
8085 With no argument, the targeted breakpoint is the last one set.\n\
8086 The commands themselves follow starting on the next line.\n\
8087 Type a line containing \"end\" to indicate the end of them.\n\
8088 Give \"silent\" as the first line to make the breakpoint silent;\n\
8089 then no output is printed when it is hit, except what the commands print."));
8091 add_com ("condition", class_breakpoint
, condition_command
, _("\
8092 Specify breakpoint number N to break only if COND is true.\n\
8093 Usage is `condition N COND', where N is an integer and COND is an\n\
8094 expression to be evaluated whenever breakpoint N is reached."));
8096 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8097 Set a temporary breakpoint.\n\
8098 Like \"break\" except the breakpoint is only temporary,\n\
8099 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8100 by using \"enable delete\" on the breakpoint number.\n\
8102 BREAK_ARGS_HELP ("tbreak")));
8103 set_cmd_completer (c
, location_completer
);
8105 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8106 Set a hardware assisted breakpoint.\n\
8107 Like \"break\" except the breakpoint requires hardware support,\n\
8108 some target hardware may not have this support.\n\
8110 BREAK_ARGS_HELP ("hbreak")));
8111 set_cmd_completer (c
, location_completer
);
8113 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8114 Set a temporary hardware assisted breakpoint.\n\
8115 Like \"hbreak\" except the breakpoint is only temporary,\n\
8116 so it will be deleted when hit.\n\
8118 BREAK_ARGS_HELP ("thbreak")));
8119 set_cmd_completer (c
, location_completer
);
8121 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8122 Enable some breakpoints.\n\
8123 Give breakpoint numbers (separated by spaces) as arguments.\n\
8124 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8125 This is used to cancel the effect of the \"disable\" command.\n\
8126 With a subcommand you can enable temporarily."),
8127 &enablelist
, "enable ", 1, &cmdlist
);
8129 add_com ("ab", class_breakpoint
, enable_command
, _("\
8130 Enable some breakpoints.\n\
8131 Give breakpoint numbers (separated by spaces) as arguments.\n\
8132 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8133 This is used to cancel the effect of the \"disable\" command.\n\
8134 With a subcommand you can enable temporarily."));
8136 add_com_alias ("en", "enable", class_breakpoint
, 1);
8138 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8139 Enable some breakpoints.\n\
8140 Give breakpoint numbers (separated by spaces) as arguments.\n\
8141 This is used to cancel the effect of the \"disable\" command.\n\
8142 May be abbreviated to simply \"enable\".\n"),
8143 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8145 add_cmd ("once", no_class
, enable_once_command
, _("\
8146 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8147 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8150 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8151 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8152 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8155 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8156 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8157 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8160 add_cmd ("once", no_class
, enable_once_command
, _("\
8161 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8162 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8165 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8166 Disable some breakpoints.\n\
8167 Arguments are breakpoint numbers with spaces in between.\n\
8168 To disable all breakpoints, give no argument.\n\
8169 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8170 &disablelist
, "disable ", 1, &cmdlist
);
8171 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8172 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8174 add_com ("sb", class_breakpoint
, disable_command
, _("\
8175 Disable some breakpoints.\n\
8176 Arguments are breakpoint numbers with spaces in between.\n\
8177 To disable all breakpoints, give no argument.\n\
8178 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8180 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8181 Disable some breakpoints.\n\
8182 Arguments are breakpoint numbers with spaces in between.\n\
8183 To disable all breakpoints, give no argument.\n\
8184 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8185 This command may be abbreviated \"disable\"."),
8188 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8189 Delete some breakpoints or auto-display expressions.\n\
8190 Arguments are breakpoint numbers with spaces in between.\n\
8191 To delete all breakpoints, give no argument.\n\
8193 Also a prefix command for deletion of other GDB objects.\n\
8194 The \"unset\" command is also an alias for \"delete\"."),
8195 &deletelist
, "delete ", 1, &cmdlist
);
8196 add_com_alias ("d", "delete", class_breakpoint
, 1);
8197 add_com_alias ("del", "delete", class_breakpoint
, 1);
8199 add_com ("db", class_breakpoint
, delete_command
, _("\
8200 Delete some breakpoints.\n\
8201 Arguments are breakpoint numbers with spaces in between.\n\
8202 To delete all breakpoints, give no argument.\n"));
8204 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8205 Delete some breakpoints or auto-display expressions.\n\
8206 Arguments are breakpoint numbers with spaces in between.\n\
8207 To delete all breakpoints, give no argument.\n\
8208 This command may be abbreviated \"delete\"."),
8211 add_com ("clear", class_breakpoint
, clear_command
, _("\
8212 Clear breakpoint at specified line or function.\n\
8213 Argument may be line number, function name, or \"*\" and an address.\n\
8214 If line number is specified, all breakpoints in that line are cleared.\n\
8215 If function is specified, breakpoints at beginning of function are cleared.\n\
8216 If an address is specified, breakpoints at that address are cleared.\n\
8218 With no argument, clears all breakpoints in the line that the selected frame\n\
8221 See also the \"delete\" command which clears breakpoints by number."));
8223 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8224 Set breakpoint at specified line or function.\n"
8225 BREAK_ARGS_HELP ("break")));
8226 set_cmd_completer (c
, location_completer
);
8228 add_com_alias ("b", "break", class_run
, 1);
8229 add_com_alias ("br", "break", class_run
, 1);
8230 add_com_alias ("bre", "break", class_run
, 1);
8231 add_com_alias ("brea", "break", class_run
, 1);
8235 add_com_alias ("ba", "break", class_breakpoint
, 1);
8236 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8241 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8242 Break in function/address or break at a line in the current file."),
8243 &stoplist
, "stop ", 1, &cmdlist
);
8244 add_cmd ("in", class_breakpoint
, stopin_command
,
8245 _("Break in function or address."), &stoplist
);
8246 add_cmd ("at", class_breakpoint
, stopat_command
,
8247 _("Break at a line in the current file."), &stoplist
);
8248 add_com ("status", class_info
, breakpoints_info
, _("\
8249 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8250 The \"Type\" column indicates one of:\n\
8251 \tbreakpoint - normal breakpoint\n\
8252 \twatchpoint - watchpoint\n\
8253 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8254 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8255 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8256 address and file/line number respectively.\n\
8258 Convenience variable \"$_\" and default examine address for \"x\"\n\
8259 are set to the address of the last breakpoint listed unless the command\n\
8260 is prefixed with \"server \".\n\n\
8261 Convenience variable \"$bpnum\" contains the number of the last\n\
8265 add_info ("breakpoints", breakpoints_info
, _("\
8266 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8267 The \"Type\" column indicates one of:\n\
8268 \tbreakpoint - normal breakpoint\n\
8269 \twatchpoint - watchpoint\n\
8270 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8271 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8272 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8273 address and file/line number respectively.\n\
8275 Convenience variable \"$_\" and default examine address for \"x\"\n\
8276 are set to the address of the last breakpoint listed unless the command\n\
8277 is prefixed with \"server \".\n\n\
8278 Convenience variable \"$bpnum\" contains the number of the last\n\
8282 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8283 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8284 The \"Type\" column indicates one of:\n\
8285 \tbreakpoint - normal breakpoint\n\
8286 \twatchpoint - watchpoint\n\
8287 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8288 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8289 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8290 address and file/line number respectively.\n\
8292 Convenience variable \"$_\" and default examine address for \"x\"\n\
8293 are set to the address of the last breakpoint listed unless the command\n\
8294 is prefixed with \"server \".\n\n\
8295 Convenience variable \"$bpnum\" contains the number of the last\n\
8298 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8299 Status of all breakpoints, or breakpoint number NUMBER.\n\
8300 The \"Type\" column indicates one of:\n\
8301 \tbreakpoint - normal breakpoint\n\
8302 \twatchpoint - watchpoint\n\
8303 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8304 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8305 \tuntil - internal breakpoint used by the \"until\" command\n\
8306 \tfinish - internal breakpoint used by the \"finish\" command\n\
8307 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8308 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8309 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8310 address and file/line number respectively.\n\
8312 Convenience variable \"$_\" and default examine address for \"x\"\n\
8313 are set to the address of the last breakpoint listed unless the command\n\
8314 is prefixed with \"server \".\n\n\
8315 Convenience variable \"$bpnum\" contains the number of the last\n\
8317 &maintenanceinfolist
);
8319 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8320 Set catchpoints to catch events."),
8321 &catch_cmdlist
, "catch ",
8322 0/*allow-unknown*/, &cmdlist
);
8324 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8325 Set temporary catchpoints to catch events."),
8326 &tcatch_cmdlist
, "tcatch ",
8327 0/*allow-unknown*/, &cmdlist
);
8329 /* Add catch and tcatch sub-commands. */
8330 add_catch_command ("catch", _("\
8331 Catch an exception, when caught.\n\
8332 With an argument, catch only exceptions with the given name."),
8333 catch_catch_command
,
8336 add_catch_command ("throw", _("\
8337 Catch an exception, when thrown.\n\
8338 With an argument, catch only exceptions with the given name."),
8339 catch_throw_command
,
8342 add_catch_command ("fork", _("Catch calls to fork."),
8343 catch_fork_command_1
,
8344 (void *) (uintptr_t) catch_fork_permanent
,
8345 (void *) (uintptr_t) catch_fork_temporary
);
8346 add_catch_command ("vfork", _("Catch calls to vfork."),
8347 catch_fork_command_1
,
8348 (void *) (uintptr_t) catch_vfork_permanent
,
8349 (void *) (uintptr_t) catch_vfork_temporary
);
8350 add_catch_command ("exec", _("Catch calls to exec."),
8351 catch_exec_command_1
,
8354 add_catch_command ("exception", _("\
8355 Catch Ada exceptions, when raised.\n\
8356 With an argument, catch only exceptions with the given name."),
8357 catch_ada_exception_command
,
8360 add_catch_command ("assert", _("\
8361 Catch failed Ada assertions, when raised.\n\
8362 With an argument, catch only exceptions with the given name."),
8363 catch_assert_command
,
8367 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8368 Set a watchpoint for an expression.\n\
8369 A watchpoint stops execution of your program whenever the value of\n\
8370 an expression changes."));
8371 set_cmd_completer (c
, expression_completer
);
8373 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8374 Set a read watchpoint for an expression.\n\
8375 A watchpoint stops execution of your program whenever the value of\n\
8376 an expression is read."));
8377 set_cmd_completer (c
, expression_completer
);
8379 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8380 Set a watchpoint for an expression.\n\
8381 A watchpoint stops execution of your program whenever the value of\n\
8382 an expression is either read or written."));
8383 set_cmd_completer (c
, expression_completer
);
8385 add_info ("watchpoints", breakpoints_info
,
8386 _("Synonym for ``info breakpoints''."));
8389 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8390 respond to changes - contrary to the description. */
8391 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8392 &can_use_hw_watchpoints
, _("\
8393 Set debugger's willingness to use watchpoint hardware."), _("\
8394 Show debugger's willingness to use watchpoint hardware."), _("\
8395 If zero, gdb will not use hardware for new watchpoints, even if\n\
8396 such is available. (However, any hardware watchpoints that were\n\
8397 created before setting this to nonzero, will continue to use watchpoint\n\
8400 show_can_use_hw_watchpoints
,
8401 &setlist
, &showlist
);
8403 can_use_hw_watchpoints
= 1;
8405 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8406 Breakpoint specific settings\n\
8407 Configure various breakpoint-specific variables such as\n\
8408 pending breakpoint behavior"),
8409 &breakpoint_set_cmdlist
, "set breakpoint ",
8410 0/*allow-unknown*/, &setlist
);
8411 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8412 Breakpoint specific settings\n\
8413 Configure various breakpoint-specific variables such as\n\
8414 pending breakpoint behavior"),
8415 &breakpoint_show_cmdlist
, "show breakpoint ",
8416 0/*allow-unknown*/, &showlist
);
8418 add_setshow_auto_boolean_cmd ("pending", no_class
,
8419 &pending_break_support
, _("\
8420 Set debugger's behavior regarding pending breakpoints."), _("\
8421 Show debugger's behavior regarding pending breakpoints."), _("\
8422 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8423 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8424 an error. If auto, an unrecognized breakpoint location results in a\n\
8425 user-query to see if a pending breakpoint should be created."),
8427 show_pending_break_support
,
8428 &breakpoint_set_cmdlist
,
8429 &breakpoint_show_cmdlist
);
8431 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8433 add_setshow_boolean_cmd ("auto-hw", no_class
,
8434 &automatic_hardware_breakpoints
, _("\
8435 Set automatic usage of hardware breakpoints."), _("\
8436 Show automatic usage of hardware breakpoints."), _("\
8437 If set, the debugger will automatically use hardware breakpoints for\n\
8438 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8439 a warning will be emitted for such breakpoints."),
8441 show_automatic_hardware_breakpoints
,
8442 &breakpoint_set_cmdlist
,
8443 &breakpoint_show_cmdlist
);
8445 add_setshow_enum_cmd ("always-inserted", class_support
,
8446 always_inserted_enums
, &always_inserted_mode
, _("\
8447 Set mode for inserting breakpoints."), _("\
8448 Show mode for inserting breakpoints."), _("\
8449 When this mode is off, breakpoints are inserted in inferior when it is\n\
8450 resumed, and removed when execution stops. When this mode is on,\n\
8451 breakpoints are inserted immediately and removed only when the user\n\
8452 deletes the breakpoint. When this mode is auto (which is the default),\n\
8453 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8454 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8455 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8456 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8458 &show_always_inserted_mode
,
8459 &breakpoint_set_cmdlist
,
8460 &breakpoint_show_cmdlist
);
8462 automatic_hardware_breakpoints
= 1;