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 watchpoint:
812 - Reparse watchpoint expression, if REPARSE is non-zero
813 - Evaluate expression and store the result in B->val
814 - Evaluate the condition if there is one, and store the result
816 - Update the list of values that must be watched in B->loc.
818 If the watchpoint is disabled, do nothing. If this is
819 local watchpoint that is out of scope, delete it. */
821 update_watchpoint (struct breakpoint
*b
, int reparse
)
823 int within_current_scope
;
824 struct frame_id saved_frame_id
;
825 struct bp_location
*loc
;
828 /* We don't free locations. They are stored in bp_location_chain and
829 update_global_locations will eventually delete them and remove
830 breakpoints if needed. */
833 if (b
->disposition
== disp_del_at_next_stop
)
836 /* Save the current frame's ID so we can restore it after
837 evaluating the watchpoint expression on its own frame. */
838 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
839 took a frame parameter, so that we didn't have to change the
841 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
843 /* Determine if the watchpoint is within scope. */
844 if (b
->exp_valid_block
== NULL
)
845 within_current_scope
= 1;
848 struct frame_info
*fi
;
849 fi
= frame_find_by_id (b
->watchpoint_frame
);
850 within_current_scope
= (fi
!= NULL
);
851 if (within_current_scope
)
855 if (within_current_scope
&& reparse
)
864 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
865 /* If the meaning of expression itself changed, the old value is
866 no longer relevant. We don't want to report a watchpoint hit
867 to the user when the old value and the new value may actually
868 be completely different objects. */
874 /* If we failed to parse the expression, for example because
875 it refers to a global variable in a not-yet-loaded shared library,
876 don't try to insert watchpoint. We don't automatically delete
877 such watchpoint, though, since failure to parse expression
878 is different from out-of-scope watchpoint. */
879 if (within_current_scope
&& b
->exp
)
881 struct value
*val_chain
, *v
, *result
, *next
;
883 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
885 /* Avoid setting b->val if it's already set. The meaning of
886 b->val is 'the last value' user saw, and we should update
887 it only if we reported that last value to user. As it
888 happens, the code that reports it updates b->val directly. */
895 /* Change the type of breakpoint between hardware assisted or an
896 ordinary watchpoint depending on the hardware support and free
897 hardware slots. REPARSE is set when the inferior is started. */
898 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
901 int i
, mem_cnt
, other_type_used
;
903 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
905 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
908 b
->type
= bp_watchpoint
;
911 int target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT
912 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
913 if (target_resources_ok
<= 0)
914 b
->type
= bp_watchpoint
;
916 b
->type
= bp_hardware_watchpoint
;
920 /* Look at each value on the value chain. */
921 for (v
= val_chain
; v
; v
= next
)
923 /* If it's a memory location, and GDB actually needed
924 its contents to evaluate the expression, then we
925 must watch it. If the first value returned is
926 still lazy, that means an error occurred reading it;
927 watch it anyway in case it becomes readable. */
928 if (VALUE_LVAL (v
) == lval_memory
929 && (v
== val_chain
|| ! value_lazy (v
)))
931 struct type
*vtype
= check_typedef (value_type (v
));
933 /* We only watch structs and arrays if user asked
934 for it explicitly, never if they just happen to
935 appear in the middle of some value chain. */
937 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
938 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
942 struct bp_location
*loc
, **tmp
;
944 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
945 len
= TYPE_LENGTH (value_type (v
));
947 if (b
->type
== bp_read_watchpoint
)
949 else if (b
->type
== bp_access_watchpoint
)
952 loc
= allocate_bp_location (b
);
953 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
958 loc
->watchpoint_type
= type
;
962 next
= value_next (v
);
967 /* We just regenerated the list of breakpoint locations.
968 The new location does not have its condition field set to anything
969 and therefore, we must always reparse the cond_string, independently
970 of the value of the reparse flag. */
971 if (b
->cond_string
!= NULL
)
973 char *s
= b
->cond_string
;
974 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
977 else if (!within_current_scope
)
979 printf_filtered (_("\
980 Watchpoint %d deleted because the program has left the block \n\
981 in which its expression is valid.\n"),
983 if (b
->related_breakpoint
)
984 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
985 b
->disposition
= disp_del_at_next_stop
;
988 /* Restore the selected frame. */
989 select_frame (frame_find_by_id (saved_frame_id
));
993 /* Returns 1 iff breakpoint location should be
994 inserted in the inferior. */
996 should_be_inserted (struct bp_location
*bpt
)
998 if (!breakpoint_enabled (bpt
->owner
))
1001 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1004 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1010 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1011 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1012 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1014 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1015 method for each breakpoint or catchpoint type. */
1017 insert_bp_location (struct bp_location
*bpt
,
1018 struct ui_file
*tmp_error_stream
,
1019 int *disabled_breaks
, int *process_warning
,
1020 int *hw_breakpoint_error
)
1024 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1027 /* Initialize the target-specific information. */
1028 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1029 bpt
->target_info
.placed_address
= bpt
->address
;
1031 if (bpt
->loc_type
== bp_loc_software_breakpoint
1032 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1034 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1036 /* If the explicitly specified breakpoint type
1037 is not hardware breakpoint, check the memory map to see
1038 if the breakpoint address is in read only memory or not.
1039 Two important cases are:
1040 - location type is not hardware breakpoint, memory
1041 is readonly. We change the type of the location to
1042 hardware breakpoint.
1043 - location type is hardware breakpoint, memory is read-write.
1044 This means we've previously made the location hardware one, but
1045 then the memory map changed, so we undo.
1047 When breakpoints are removed, remove_breakpoints will
1048 use location types we've just set here, the only possible
1049 problem is that memory map has changed during running program,
1050 but it's not going to work anyway with current gdb. */
1051 struct mem_region
*mr
1052 = lookup_mem_region (bpt
->target_info
.placed_address
);
1056 if (automatic_hardware_breakpoints
)
1059 enum bp_loc_type new_type
;
1061 if (mr
->attrib
.mode
!= MEM_RW
)
1062 new_type
= bp_loc_hardware_breakpoint
;
1064 new_type
= bp_loc_software_breakpoint
;
1066 if (new_type
!= bpt
->loc_type
)
1068 static int said
= 0;
1069 bpt
->loc_type
= new_type
;
1072 fprintf_filtered (gdb_stdout
, _("\
1073 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1078 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1079 && mr
->attrib
.mode
!= MEM_RW
)
1080 warning (_("cannot set software breakpoint at readonly address %s"),
1081 paddr (bpt
->address
));
1085 /* First check to see if we have to handle an overlay. */
1086 if (overlay_debugging
== ovly_off
1087 || bpt
->section
== NULL
1088 || !(section_is_overlay (bpt
->section
)))
1090 /* No overlay handling: just set the breakpoint. */
1092 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1093 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1095 val
= target_insert_breakpoint (&bpt
->target_info
);
1099 /* This breakpoint is in an overlay section.
1100 Shall we set a breakpoint at the LMA? */
1101 if (!overlay_events_enabled
)
1103 /* Yes -- overlay event support is not active,
1104 so we must try to set a breakpoint at the LMA.
1105 This will not work for a hardware breakpoint. */
1106 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1107 warning (_("hardware breakpoint %d not supported in overlay!"),
1108 bpt
->owner
->number
);
1111 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1113 /* Set a software (trap) breakpoint at the LMA. */
1114 bpt
->overlay_target_info
= bpt
->target_info
;
1115 bpt
->overlay_target_info
.placed_address
= addr
;
1116 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1118 fprintf_unfiltered (tmp_error_stream
,
1119 "Overlay breakpoint %d failed: in ROM?",
1120 bpt
->owner
->number
);
1123 /* Shall we set a breakpoint at the VMA? */
1124 if (section_is_mapped (bpt
->section
))
1126 /* Yes. This overlay section is mapped into memory. */
1127 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1128 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1130 val
= target_insert_breakpoint (&bpt
->target_info
);
1134 /* No. This breakpoint will not be inserted.
1135 No error, but do not mark the bp as 'inserted'. */
1142 /* Can't set the breakpoint. */
1143 if (solib_address (bpt
->address
))
1145 /* See also: disable_breakpoints_in_shlibs. */
1147 bpt
->shlib_disabled
= 1;
1148 if (!*disabled_breaks
)
1150 fprintf_unfiltered (tmp_error_stream
,
1151 "Cannot insert breakpoint %d.\n",
1152 bpt
->owner
->number
);
1153 fprintf_unfiltered (tmp_error_stream
,
1154 "Temporarily disabling shared library breakpoints:\n");
1156 *disabled_breaks
= 1;
1157 fprintf_unfiltered (tmp_error_stream
,
1158 "breakpoint #%d\n", bpt
->owner
->number
);
1162 #ifdef ONE_PROCESS_WRITETEXT
1163 *process_warning
= 1;
1165 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1167 *hw_breakpoint_error
= 1;
1168 fprintf_unfiltered (tmp_error_stream
,
1169 "Cannot insert hardware breakpoint %d.\n",
1170 bpt
->owner
->number
);
1174 fprintf_unfiltered (tmp_error_stream
,
1175 "Cannot insert breakpoint %d.\n",
1176 bpt
->owner
->number
);
1177 fprintf_filtered (tmp_error_stream
,
1178 "Error accessing memory address ");
1179 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1180 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1181 safe_strerror (val
));
1192 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1193 /* NOTE drow/2003-09-08: This state only exists for removing
1194 watchpoints. It's not clear that it's necessary... */
1195 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1197 val
= target_insert_watchpoint (bpt
->address
,
1199 bpt
->watchpoint_type
);
1200 bpt
->inserted
= (val
!= -1);
1203 else if (bpt
->owner
->type
== bp_catchpoint
)
1205 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1206 bpt
->owner
, RETURN_MASK_ERROR
);
1207 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1208 bpt
->owner
->number
);
1210 bpt
->owner
->enable_state
= bp_disabled
;
1214 /* We've already printed an error message if there was a problem
1215 inserting this catchpoint, and we've disabled the catchpoint,
1216 so just return success. */
1223 /* Make sure all breakpoints are inserted in inferior.
1224 Throws exception on any error.
1225 A breakpoint that is already inserted won't be inserted
1226 again, so calling this function twice is safe. */
1228 insert_breakpoints (void)
1230 struct breakpoint
*bpt
;
1232 ALL_BREAKPOINTS (bpt
)
1233 if (is_hardware_watchpoint (bpt
))
1234 update_watchpoint (bpt
, 0 /* don't reparse. */);
1236 update_global_location_list (1);
1238 if (!breakpoints_always_inserted_mode ()
1239 && (target_has_execution
1240 || (gdbarch_has_global_solist (target_gdbarch
)
1241 && target_supports_multi_process ())))
1242 /* update_global_location_list does not insert breakpoints
1243 when always_inserted_mode is not enabled. Explicitly
1245 insert_breakpoint_locations ();
1248 /* insert_breakpoints is used when starting or continuing the program.
1249 remove_breakpoints is used when the program stops.
1250 Both return zero if successful,
1251 or an `errno' value if could not write the inferior. */
1254 insert_breakpoint_locations (void)
1256 struct breakpoint
*bpt
;
1257 struct bp_location
*b
, *temp
;
1260 int disabled_breaks
= 0;
1261 int hw_breakpoint_error
= 0;
1262 int process_warning
= 0;
1264 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1265 make_cleanup_ui_file_delete (tmp_error_stream
);
1267 /* Explicitly mark the warning -- this will only be printed if
1268 there was an error. */
1269 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1271 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1273 if (!should_be_inserted (b
) || b
->inserted
)
1276 /* There is no point inserting thread-specific breakpoints if the
1277 thread no longer exists. */
1278 if (b
->owner
->thread
!= -1
1279 && !valid_thread_id (b
->owner
->thread
))
1282 val
= insert_bp_location (b
, tmp_error_stream
,
1283 &disabled_breaks
, &process_warning
,
1284 &hw_breakpoint_error
);
1289 /* If we failed to insert all locations of a watchpoint,
1290 remove them, as half-inserted watchpoint is of limited use. */
1291 ALL_BREAKPOINTS (bpt
)
1293 int some_failed
= 0;
1294 struct bp_location
*loc
;
1296 if (!is_hardware_watchpoint (bpt
))
1299 if (!breakpoint_enabled (bpt
))
1302 if (bpt
->disposition
== disp_del_at_next_stop
)
1305 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1313 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1315 remove_breakpoint (loc
, mark_uninserted
);
1317 hw_breakpoint_error
= 1;
1318 fprintf_unfiltered (tmp_error_stream
,
1319 "Could not insert hardware watchpoint %d.\n",
1327 /* If a hardware breakpoint or watchpoint was inserted, add a
1328 message about possibly exhausted resources. */
1329 if (hw_breakpoint_error
)
1331 fprintf_unfiltered (tmp_error_stream
,
1332 "Could not insert hardware breakpoints:\n\
1333 You may have requested too many hardware breakpoints/watchpoints.\n");
1335 #ifdef ONE_PROCESS_WRITETEXT
1336 if (process_warning
)
1337 fprintf_unfiltered (tmp_error_stream
,
1338 "The same program may be running in another process.");
1340 target_terminal_ours_for_output ();
1341 error_stream (tmp_error_stream
);
1346 remove_breakpoints (void)
1348 struct bp_location
*b
;
1351 ALL_BP_LOCATIONS (b
)
1355 val
= remove_breakpoint (b
, mark_uninserted
);
1364 remove_hw_watchpoints (void)
1366 struct bp_location
*b
;
1369 ALL_BP_LOCATIONS (b
)
1371 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1373 val
= remove_breakpoint (b
, mark_uninserted
);
1382 reattach_breakpoints (int pid
)
1384 struct bp_location
*b
;
1386 struct cleanup
*old_chain
= save_inferior_ptid ();
1387 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1388 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1390 make_cleanup_ui_file_delete (tmp_error_stream
);
1392 inferior_ptid
= pid_to_ptid (pid
);
1393 ALL_BP_LOCATIONS (b
)
1398 val
= insert_bp_location (b
, tmp_error_stream
,
1399 &dummy1
, &dummy2
, &dummy3
);
1402 do_cleanups (old_chain
);
1407 do_cleanups (old_chain
);
1412 update_breakpoints_after_exec (void)
1414 struct breakpoint
*b
;
1415 struct breakpoint
*temp
;
1416 struct bp_location
*bploc
;
1418 /* We're about to delete breakpoints from GDB's lists. If the
1419 INSERTED flag is true, GDB will try to lift the breakpoints by
1420 writing the breakpoints' "shadow contents" back into memory. The
1421 "shadow contents" are NOT valid after an exec, so GDB should not
1422 do that. Instead, the target is responsible from marking
1423 breakpoints out as soon as it detects an exec. We don't do that
1424 here instead, because there may be other attempts to delete
1425 breakpoints after detecting an exec and before reaching here. */
1426 ALL_BP_LOCATIONS (bploc
)
1427 gdb_assert (!bploc
->inserted
);
1429 ALL_BREAKPOINTS_SAFE (b
, temp
)
1431 /* Solib breakpoints must be explicitly reset after an exec(). */
1432 if (b
->type
== bp_shlib_event
)
1434 delete_breakpoint (b
);
1438 /* Thread event breakpoints must be set anew after an exec(),
1439 as must overlay event breakpoints. */
1440 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1442 delete_breakpoint (b
);
1446 /* Step-resume breakpoints are meaningless after an exec(). */
1447 if (b
->type
== bp_step_resume
)
1449 delete_breakpoint (b
);
1453 /* Longjmp and longjmp-resume breakpoints are also meaningless
1455 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1457 delete_breakpoint (b
);
1461 if (b
->type
== bp_catchpoint
)
1463 /* For now, none of the bp_catchpoint breakpoints need to
1464 do anything at this point. In the future, if some of
1465 the catchpoints need to something, we will need to add
1466 a new method, and call this method from here. */
1470 /* bp_finish is a special case. The only way we ought to be able
1471 to see one of these when an exec() has happened, is if the user
1472 caught a vfork, and then said "finish". Ordinarily a finish just
1473 carries them to the call-site of the current callee, by setting
1474 a temporary bp there and resuming. But in this case, the finish
1475 will carry them entirely through the vfork & exec.
1477 We don't want to allow a bp_finish to remain inserted now. But
1478 we can't safely delete it, 'cause finish_command has a handle to
1479 the bp on a bpstat, and will later want to delete it. There's a
1480 chance (and I've seen it happen) that if we delete the bp_finish
1481 here, that its storage will get reused by the time finish_command
1482 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1483 We really must allow finish_command to delete a bp_finish.
1485 In the absense of a general solution for the "how do we know
1486 it's safe to delete something others may have handles to?"
1487 problem, what we'll do here is just uninsert the bp_finish, and
1488 let finish_command delete it.
1490 (We know the bp_finish is "doomed" in the sense that it's
1491 momentary, and will be deleted as soon as finish_command sees
1492 the inferior stopped. So it doesn't matter that the bp's
1493 address is probably bogus in the new a.out, unlike e.g., the
1494 solib breakpoints.) */
1496 if (b
->type
== bp_finish
)
1501 /* Without a symbolic address, we have little hope of the
1502 pre-exec() address meaning the same thing in the post-exec()
1504 if (b
->addr_string
== NULL
)
1506 delete_breakpoint (b
);
1510 /* FIXME what about longjmp breakpoints? Re-create them here? */
1511 create_overlay_event_breakpoint ("_ovly_debug_event");
1515 detach_breakpoints (int pid
)
1517 struct bp_location
*b
;
1519 struct cleanup
*old_chain
= save_inferior_ptid ();
1521 if (pid
== PIDGET (inferior_ptid
))
1522 error (_("Cannot detach breakpoints of inferior_ptid"));
1524 /* Set inferior_ptid; remove_breakpoint uses this global. */
1525 inferior_ptid
= pid_to_ptid (pid
);
1526 ALL_BP_LOCATIONS (b
)
1530 val
= remove_breakpoint (b
, mark_inserted
);
1533 do_cleanups (old_chain
);
1538 do_cleanups (old_chain
);
1543 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1547 if (b
->owner
->enable_state
== bp_permanent
)
1548 /* Permanent breakpoints cannot be inserted or removed. */
1551 /* The type of none suggests that owner is actually deleted.
1552 This should not ever happen. */
1553 gdb_assert (b
->owner
->type
!= bp_none
);
1555 if (b
->loc_type
== bp_loc_software_breakpoint
1556 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1558 /* "Normal" instruction breakpoint: either the standard
1559 trap-instruction bp (bp_breakpoint), or a
1560 bp_hardware_breakpoint. */
1562 /* First check to see if we have to handle an overlay. */
1563 if (overlay_debugging
== ovly_off
1564 || b
->section
== NULL
1565 || !(section_is_overlay (b
->section
)))
1567 /* No overlay handling: just remove the breakpoint. */
1569 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1570 val
= target_remove_hw_breakpoint (&b
->target_info
);
1572 val
= target_remove_breakpoint (&b
->target_info
);
1576 /* This breakpoint is in an overlay section.
1577 Did we set a breakpoint at the LMA? */
1578 if (!overlay_events_enabled
)
1580 /* Yes -- overlay event support is not active, so we
1581 should have set a breakpoint at the LMA. Remove it.
1583 /* Ignore any failures: if the LMA is in ROM, we will
1584 have already warned when we failed to insert it. */
1585 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1586 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1588 target_remove_breakpoint (&b
->overlay_target_info
);
1590 /* Did we set a breakpoint at the VMA?
1591 If so, we will have marked the breakpoint 'inserted'. */
1594 /* Yes -- remove it. Previously we did not bother to
1595 remove the breakpoint if the section had been
1596 unmapped, but let's not rely on that being safe. We
1597 don't know what the overlay manager might do. */
1598 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1599 val
= target_remove_hw_breakpoint (&b
->target_info
);
1601 /* However, we should remove *software* breakpoints only
1602 if the section is still mapped, or else we overwrite
1603 wrong code with the saved shadow contents. */
1604 else if (section_is_mapped (b
->section
))
1605 val
= target_remove_breakpoint (&b
->target_info
);
1611 /* No -- not inserted, so no need to remove. No error. */
1616 /* In some cases, we might not be able to remove a breakpoint
1617 in a shared library that has already been removed, but we
1618 have not yet processed the shlib unload event. */
1619 if (val
&& solib_address (b
->address
))
1624 b
->inserted
= (is
== mark_inserted
);
1626 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1631 b
->inserted
= (is
== mark_inserted
);
1632 val
= target_remove_watchpoint (b
->address
, b
->length
,
1633 b
->watchpoint_type
);
1635 /* Failure to remove any of the hardware watchpoints comes here. */
1636 if ((is
== mark_uninserted
) && (b
->inserted
))
1637 warning (_("Could not remove hardware watchpoint %d."),
1640 else if (b
->owner
->type
== bp_catchpoint
1641 && breakpoint_enabled (b
->owner
)
1644 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1646 val
= b
->owner
->ops
->remove (b
->owner
);
1649 b
->inserted
= (is
== mark_inserted
);
1655 /* Clear the "inserted" flag in all breakpoints. */
1658 mark_breakpoints_out (void)
1660 struct bp_location
*bpt
;
1662 ALL_BP_LOCATIONS (bpt
)
1666 /* Clear the "inserted" flag in all breakpoints and delete any
1667 breakpoints which should go away between runs of the program.
1669 Plus other such housekeeping that has to be done for breakpoints
1672 Note: this function gets called at the end of a run (by
1673 generic_mourn_inferior) and when a run begins (by
1674 init_wait_for_inferior). */
1679 breakpoint_init_inferior (enum inf_context context
)
1681 struct breakpoint
*b
, *temp
;
1682 struct bp_location
*bpt
;
1685 /* If breakpoint locations are shared across processes, then there's
1687 if (gdbarch_has_global_solist (target_gdbarch
))
1690 ALL_BP_LOCATIONS (bpt
)
1691 if (bpt
->owner
->enable_state
!= bp_permanent
)
1694 ALL_BREAKPOINTS_SAFE (b
, temp
)
1699 case bp_watchpoint_scope
:
1701 /* If the call dummy breakpoint is at the entry point it will
1702 cause problems when the inferior is rerun, so we better
1705 Also get rid of scope breakpoints. */
1706 delete_breakpoint (b
);
1710 case bp_hardware_watchpoint
:
1711 case bp_read_watchpoint
:
1712 case bp_access_watchpoint
:
1714 /* Likewise for watchpoints on local expressions. */
1715 if (b
->exp_valid_block
!= NULL
)
1716 delete_breakpoint (b
);
1717 else if (context
== inf_starting
)
1719 /* Reset val field to force reread of starting value
1720 in insert_breakpoints. */
1722 value_free (b
->val
);
1732 /* Get rid of the moribund locations. */
1733 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1734 free_bp_location (bpt
);
1735 VEC_free (bp_location_p
, moribund_locations
);
1738 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1739 exists at PC. It returns ordinary_breakpoint_here if it's an
1740 ordinary breakpoint, or permanent_breakpoint_here if it's a
1741 permanent breakpoint.
1742 - When continuing from a location with an ordinary breakpoint, we
1743 actually single step once before calling insert_breakpoints.
1744 - When continuing from a localion with a permanent breakpoint, we
1745 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1746 the target, to advance the PC past the breakpoint. */
1748 enum breakpoint_here
1749 breakpoint_here_p (CORE_ADDR pc
)
1751 const struct bp_location
*bpt
;
1752 int any_breakpoint_here
= 0;
1754 ALL_BP_LOCATIONS (bpt
)
1756 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1757 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1760 if ((breakpoint_enabled (bpt
->owner
)
1761 || bpt
->owner
->enable_state
== bp_permanent
)
1762 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1764 if (overlay_debugging
1765 && section_is_overlay (bpt
->section
)
1766 && !section_is_mapped (bpt
->section
))
1767 continue; /* unmapped overlay -- can't be a match */
1768 else if (bpt
->owner
->enable_state
== bp_permanent
)
1769 return permanent_breakpoint_here
;
1771 any_breakpoint_here
= 1;
1775 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1778 /* Return true if there's a moribund breakpoint at PC. */
1781 moribund_breakpoint_here_p (CORE_ADDR pc
)
1783 struct bp_location
*loc
;
1786 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1787 if (loc
->address
== pc
)
1793 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1794 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1795 This does not check for single-step breakpoints, which are
1796 inserted and removed using direct target manipulation. */
1799 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1801 const struct bp_location
*bpt
;
1803 ALL_BP_LOCATIONS (bpt
)
1805 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1806 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1810 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1812 if (overlay_debugging
1813 && section_is_overlay (bpt
->section
)
1814 && !section_is_mapped (bpt
->section
))
1815 continue; /* unmapped overlay -- can't be a match */
1823 /* Returns non-zero iff there's either regular breakpoint
1824 or a single step breakpoint inserted at PC. */
1827 breakpoint_inserted_here_p (CORE_ADDR pc
)
1829 if (regular_breakpoint_inserted_here_p (pc
))
1832 if (single_step_breakpoint_inserted_here_p (pc
))
1838 /* This function returns non-zero iff there is a software breakpoint
1842 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1844 const struct bp_location
*bpt
;
1845 int any_breakpoint_here
= 0;
1847 ALL_BP_LOCATIONS (bpt
)
1849 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1853 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1855 if (overlay_debugging
1856 && section_is_overlay (bpt
->section
)
1857 && !section_is_mapped (bpt
->section
))
1858 continue; /* unmapped overlay -- can't be a match */
1864 /* Also check for software single-step breakpoints. */
1865 if (single_step_breakpoint_inserted_here_p (pc
))
1871 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1872 PC is valid for process/thread PTID. */
1875 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1877 const struct bp_location
*bpt
;
1880 thread
= pid_to_thread_id (ptid
);
1882 ALL_BP_LOCATIONS (bpt
)
1884 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1885 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1888 if ((breakpoint_enabled (bpt
->owner
)
1889 || bpt
->owner
->enable_state
== bp_permanent
)
1890 && bpt
->address
== pc
1891 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1893 if (overlay_debugging
1894 && section_is_overlay (bpt
->section
)
1895 && !section_is_mapped (bpt
->section
))
1896 continue; /* unmapped overlay -- can't be a match */
1906 /* bpstat stuff. External routines' interfaces are documented
1910 ep_is_catchpoint (struct breakpoint
*ep
)
1912 return (ep
->type
== bp_catchpoint
);
1916 bpstat_free (bpstat bs
)
1918 if (bs
->old_val
!= NULL
)
1919 value_free (bs
->old_val
);
1920 free_command_lines (&bs
->commands
);
1924 /* Clear a bpstat so that it says we are not at any breakpoint.
1925 Also free any storage that is part of a bpstat. */
1928 bpstat_clear (bpstat
*bsp
)
1945 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1946 is part of the bpstat is copied as well. */
1949 bpstat_copy (bpstat bs
)
1953 bpstat retval
= NULL
;
1958 for (; bs
!= NULL
; bs
= bs
->next
)
1960 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1961 memcpy (tmp
, bs
, sizeof (*tmp
));
1962 if (bs
->commands
!= NULL
)
1963 tmp
->commands
= copy_command_lines (bs
->commands
);
1964 if (bs
->old_val
!= NULL
)
1966 tmp
->old_val
= value_copy (bs
->old_val
);
1967 release_value (tmp
->old_val
);
1971 /* This is the first thing in the chain. */
1981 /* Find the bpstat associated with this breakpoint */
1984 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1989 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1991 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1997 /* Find a step_resume breakpoint associated with this bpstat.
1998 (If there are multiple step_resume bp's on the list, this function
1999 will arbitrarily pick one.)
2001 It is an error to use this function if BPSTAT doesn't contain a
2002 step_resume breakpoint.
2004 See wait_for_inferior's use of this function. */
2006 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2010 gdb_assert (bsp
!= NULL
);
2012 current_thread
= pid_to_thread_id (inferior_ptid
);
2014 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2016 if ((bsp
->breakpoint_at
!= NULL
) &&
2017 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2018 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2019 bsp
->breakpoint_at
->owner
->thread
== -1))
2020 return bsp
->breakpoint_at
->owner
;
2023 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2027 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2028 at. *BSP upon return is a bpstat which points to the remaining
2029 breakpoints stopped at (but which is not guaranteed to be good for
2030 anything but further calls to bpstat_num).
2031 Return 0 if passed a bpstat which does not indicate any breakpoints.
2032 Return -1 if stopped at a breakpoint that has been deleted since
2034 Return 1 otherwise. */
2037 bpstat_num (bpstat
*bsp
, int *num
)
2039 struct breakpoint
*b
;
2042 return 0; /* No more breakpoint values */
2044 /* We assume we'll never have several bpstats that
2045 correspond to a single breakpoint -- otherwise,
2046 this function might return the same number more
2047 than once and this will look ugly. */
2048 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2049 *bsp
= (*bsp
)->next
;
2051 return -1; /* breakpoint that's been deleted since */
2053 *num
= b
->number
; /* We have its number */
2057 /* Modify BS so that the actions will not be performed. */
2060 bpstat_clear_actions (bpstat bs
)
2062 for (; bs
!= NULL
; bs
= bs
->next
)
2064 free_command_lines (&bs
->commands
);
2065 if (bs
->old_val
!= NULL
)
2067 value_free (bs
->old_val
);
2073 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2075 cleanup_executing_breakpoints (void *ignore
)
2077 executing_breakpoint_commands
= 0;
2080 /* Execute all the commands associated with all the breakpoints at this
2081 location. Any of these commands could cause the process to proceed
2082 beyond this point, etc. We look out for such changes by checking
2083 the global "breakpoint_proceeded" after each command.
2085 Returns true if a breakpoint command resumed the inferior. In that
2086 case, it is the caller's responsibility to recall it again with the
2087 bpstat of the current thread. */
2090 bpstat_do_actions_1 (bpstat
*bsp
)
2093 struct cleanup
*old_chain
;
2096 /* Avoid endless recursion if a `source' command is contained
2098 if (executing_breakpoint_commands
)
2101 executing_breakpoint_commands
= 1;
2102 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2104 /* This pointer will iterate over the list of bpstat's. */
2107 breakpoint_proceeded
= 0;
2108 for (; bs
!= NULL
; bs
= bs
->next
)
2110 struct command_line
*cmd
;
2111 struct cleanup
*this_cmd_tree_chain
;
2113 /* Take ownership of the BSP's command tree, if it has one.
2115 The command tree could legitimately contain commands like
2116 'step' and 'next', which call clear_proceed_status, which
2117 frees stop_bpstat's command tree. To make sure this doesn't
2118 free the tree we're executing out from under us, we need to
2119 take ownership of the tree ourselves. Since a given bpstat's
2120 commands are only executed once, we don't need to copy it; we
2121 can clear the pointer in the bpstat, and make sure we free
2122 the tree when we're done. */
2125 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2129 execute_control_command (cmd
);
2131 if (breakpoint_proceeded
)
2137 /* We can free this command tree now. */
2138 do_cleanups (this_cmd_tree_chain
);
2140 if (breakpoint_proceeded
)
2142 if (target_can_async_p ())
2143 /* If we are in async mode, then the target might be still
2144 running, not stopped at any breakpoint, so nothing for
2145 us to do here -- just return to the event loop. */
2148 /* In sync mode, when execute_control_command returns
2149 we're already standing on the next breakpoint.
2150 Breakpoint commands for that stop were not run, since
2151 execute_command does not run breakpoint commands --
2152 only command_line_handler does, but that one is not
2153 involved in execution of breakpoint commands. So, we
2154 can now execute breakpoint commands. It should be
2155 noted that making execute_command do bpstat actions is
2156 not an option -- in this case we'll have recursive
2157 invocation of bpstat for each breakpoint with a
2158 command, and can easily blow up GDB stack. Instead, we
2159 return true, which will trigger the caller to recall us
2160 with the new stop_bpstat. */
2165 do_cleanups (old_chain
);
2170 bpstat_do_actions (void)
2172 /* Do any commands attached to breakpoint we are stopped at. */
2173 while (!ptid_equal (inferior_ptid
, null_ptid
)
2174 && target_has_execution
2175 && !is_exited (inferior_ptid
)
2176 && !is_executing (inferior_ptid
))
2177 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2178 and only return when it is stopped at the next breakpoint, we
2179 keep doing breakpoint actions until it returns false to
2180 indicate the inferior was not resumed. */
2181 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2185 /* Print out the (old or new) value associated with a watchpoint. */
2188 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2191 fprintf_unfiltered (stream
, _("<unreadable>"));
2194 struct value_print_options opts
;
2195 get_user_print_options (&opts
);
2196 value_print (val
, stream
, &opts
);
2200 /* This is the normal print function for a bpstat. In the future,
2201 much of this logic could (should?) be moved to bpstat_stop_status,
2202 by having it set different print_it values.
2204 Current scheme: When we stop, bpstat_print() is called. It loops
2205 through the bpstat list of things causing this stop, calling the
2206 print_bp_stop_message function on each one. The behavior of the
2207 print_bp_stop_message function depends on the print_it field of
2208 bpstat. If such field so indicates, call this function here.
2210 Return values from this routine (ultimately used by bpstat_print()
2211 and normal_stop() to decide what to do):
2212 PRINT_NOTHING: Means we already printed all we needed to print,
2213 don't print anything else.
2214 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2215 that something to be followed by a location.
2216 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2217 that something to be followed by a location.
2218 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2221 static enum print_stop_action
2222 print_it_typical (bpstat bs
)
2224 struct cleanup
*old_chain
, *ui_out_chain
;
2225 struct breakpoint
*b
;
2226 const struct bp_location
*bl
;
2227 struct ui_stream
*stb
;
2229 stb
= ui_out_stream_new (uiout
);
2230 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2231 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2232 which has since been deleted. */
2233 if (bs
->breakpoint_at
== NULL
)
2234 return PRINT_UNKNOWN
;
2235 bl
= bs
->breakpoint_at
;
2241 case bp_hardware_breakpoint
:
2242 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2243 if (bl
->address
!= bl
->requested_address
)
2244 breakpoint_adjustment_warning (bl
->requested_address
,
2247 annotate_breakpoint (b
->number
);
2249 ui_out_text (uiout
, "\nTemporary breakpoint ");
2251 ui_out_text (uiout
, "\nBreakpoint ");
2252 if (ui_out_is_mi_like_p (uiout
))
2254 ui_out_field_string (uiout
, "reason",
2255 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2256 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2258 ui_out_field_int (uiout
, "bkptno", b
->number
);
2259 ui_out_text (uiout
, ", ");
2260 return PRINT_SRC_AND_LOC
;
2263 case bp_shlib_event
:
2264 /* Did we stop because the user set the stop_on_solib_events
2265 variable? (If so, we report this as a generic, "Stopped due
2266 to shlib event" message.) */
2267 printf_filtered (_("Stopped due to shared library event\n"));
2268 return PRINT_NOTHING
;
2271 case bp_thread_event
:
2272 /* Not sure how we will get here.
2273 GDB should not stop for these breakpoints. */
2274 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2275 return PRINT_NOTHING
;
2278 case bp_overlay_event
:
2279 /* By analogy with the thread event, GDB should not stop for these. */
2280 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2281 return PRINT_NOTHING
;
2285 case bp_hardware_watchpoint
:
2286 annotate_watchpoint (b
->number
);
2287 if (ui_out_is_mi_like_p (uiout
))
2290 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2292 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2293 ui_out_text (uiout
, "\nOld value = ");
2294 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2295 ui_out_field_stream (uiout
, "old", stb
);
2296 ui_out_text (uiout
, "\nNew value = ");
2297 watchpoint_value_print (b
->val
, stb
->stream
);
2298 ui_out_field_stream (uiout
, "new", stb
);
2299 do_cleanups (ui_out_chain
);
2300 ui_out_text (uiout
, "\n");
2301 /* More than one watchpoint may have been triggered. */
2302 return PRINT_UNKNOWN
;
2305 case bp_read_watchpoint
:
2306 if (ui_out_is_mi_like_p (uiout
))
2309 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2311 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2312 ui_out_text (uiout
, "\nValue = ");
2313 watchpoint_value_print (b
->val
, stb
->stream
);
2314 ui_out_field_stream (uiout
, "value", stb
);
2315 do_cleanups (ui_out_chain
);
2316 ui_out_text (uiout
, "\n");
2317 return PRINT_UNKNOWN
;
2320 case bp_access_watchpoint
:
2321 if (bs
->old_val
!= NULL
)
2323 annotate_watchpoint (b
->number
);
2324 if (ui_out_is_mi_like_p (uiout
))
2327 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2329 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2330 ui_out_text (uiout
, "\nOld value = ");
2331 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2332 ui_out_field_stream (uiout
, "old", stb
);
2333 ui_out_text (uiout
, "\nNew value = ");
2338 if (ui_out_is_mi_like_p (uiout
))
2341 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2342 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2343 ui_out_text (uiout
, "\nValue = ");
2345 watchpoint_value_print (b
->val
, stb
->stream
);
2346 ui_out_field_stream (uiout
, "new", stb
);
2347 do_cleanups (ui_out_chain
);
2348 ui_out_text (uiout
, "\n");
2349 return PRINT_UNKNOWN
;
2352 /* Fall through, we don't deal with these types of breakpoints
2356 if (ui_out_is_mi_like_p (uiout
))
2359 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2360 return PRINT_UNKNOWN
;
2364 if (ui_out_is_mi_like_p (uiout
))
2367 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2368 return PRINT_UNKNOWN
;
2373 case bp_longjmp_resume
:
2374 case bp_step_resume
:
2375 case bp_watchpoint_scope
:
2378 return PRINT_UNKNOWN
;
2382 /* Generic routine for printing messages indicating why we
2383 stopped. The behavior of this function depends on the value
2384 'print_it' in the bpstat structure. Under some circumstances we
2385 may decide not to print anything here and delegate the task to
2388 static enum print_stop_action
2389 print_bp_stop_message (bpstat bs
)
2391 switch (bs
->print_it
)
2394 /* Nothing should be printed for this bpstat entry. */
2395 return PRINT_UNKNOWN
;
2399 /* We still want to print the frame, but we already printed the
2400 relevant messages. */
2401 return PRINT_SRC_AND_LOC
;
2404 case print_it_normal
:
2406 const struct bp_location
*bl
= bs
->breakpoint_at
;
2407 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2409 /* Normal case. Call the breakpoint's print_it method, or
2410 print_it_typical. */
2411 /* FIXME: how breakpoint can ever be NULL here? */
2412 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2413 return b
->ops
->print_it (b
);
2415 return print_it_typical (bs
);
2420 internal_error (__FILE__
, __LINE__
,
2421 _("print_bp_stop_message: unrecognized enum value"));
2426 /* Print a message indicating what happened. This is called from
2427 normal_stop(). The input to this routine is the head of the bpstat
2428 list - a list of the eventpoints that caused this stop. This
2429 routine calls the generic print routine for printing a message
2430 about reasons for stopping. This will print (for example) the
2431 "Breakpoint n," part of the output. The return value of this
2434 PRINT_UNKNOWN: Means we printed nothing
2435 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2436 code to print the location. An example is
2437 "Breakpoint 1, " which should be followed by
2439 PRINT_SRC_ONLY: Means we printed something, but there is no need
2440 to also print the location part of the message.
2441 An example is the catch/throw messages, which
2442 don't require a location appended to the end.
2443 PRINT_NOTHING: We have done some printing and we don't need any
2444 further info to be printed.*/
2446 enum print_stop_action
2447 bpstat_print (bpstat bs
)
2451 /* Maybe another breakpoint in the chain caused us to stop.
2452 (Currently all watchpoints go on the bpstat whether hit or not.
2453 That probably could (should) be changed, provided care is taken
2454 with respect to bpstat_explains_signal). */
2455 for (; bs
; bs
= bs
->next
)
2457 val
= print_bp_stop_message (bs
);
2458 if (val
== PRINT_SRC_ONLY
2459 || val
== PRINT_SRC_AND_LOC
2460 || val
== PRINT_NOTHING
)
2464 /* We reached the end of the chain, or we got a null BS to start
2465 with and nothing was printed. */
2466 return PRINT_UNKNOWN
;
2469 /* Evaluate the expression EXP and return 1 if value is zero.
2470 This is used inside a catch_errors to evaluate the breakpoint condition.
2471 The argument is a "struct expression *" that has been cast to char * to
2472 make it pass through catch_errors. */
2475 breakpoint_cond_eval (void *exp
)
2477 struct value
*mark
= value_mark ();
2478 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2479 value_free_to_mark (mark
);
2483 /* Allocate a new bpstat and chain it to the current one. */
2486 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2490 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2492 bs
->breakpoint_at
= bl
;
2493 /* If the condition is false, etc., don't do the commands. */
2494 bs
->commands
= NULL
;
2496 bs
->print_it
= print_it_normal
;
2500 /* The target has stopped with waitstatus WS. Check if any hardware
2501 watchpoints have triggered, according to the target. */
2504 watchpoints_triggered (struct target_waitstatus
*ws
)
2506 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2508 struct breakpoint
*b
;
2510 if (!stopped_by_watchpoint
)
2512 /* We were not stopped by a watchpoint. Mark all watchpoints
2513 as not triggered. */
2515 if (b
->type
== bp_hardware_watchpoint
2516 || b
->type
== bp_read_watchpoint
2517 || b
->type
== bp_access_watchpoint
)
2518 b
->watchpoint_triggered
= watch_triggered_no
;
2523 if (!target_stopped_data_address (¤t_target
, &addr
))
2525 /* We were stopped by a watchpoint, but we don't know where.
2526 Mark all watchpoints as unknown. */
2528 if (b
->type
== bp_hardware_watchpoint
2529 || b
->type
== bp_read_watchpoint
2530 || b
->type
== bp_access_watchpoint
)
2531 b
->watchpoint_triggered
= watch_triggered_unknown
;
2533 return stopped_by_watchpoint
;
2536 /* The target could report the data address. Mark watchpoints
2537 affected by this data address as triggered, and all others as not
2541 if (b
->type
== bp_hardware_watchpoint
2542 || b
->type
== bp_read_watchpoint
2543 || b
->type
== bp_access_watchpoint
)
2545 struct bp_location
*loc
;
2548 b
->watchpoint_triggered
= watch_triggered_no
;
2549 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2550 /* Exact match not required. Within range is
2552 if (target_watchpoint_addr_within_range (¤t_target
,
2556 b
->watchpoint_triggered
= watch_triggered_yes
;
2564 /* Possible return values for watchpoint_check (this can't be an enum
2565 because of check_errors). */
2566 /* The watchpoint has been deleted. */
2567 #define WP_DELETED 1
2568 /* The value has changed. */
2569 #define WP_VALUE_CHANGED 2
2570 /* The value has not changed. */
2571 #define WP_VALUE_NOT_CHANGED 3
2573 #define BP_TEMPFLAG 1
2574 #define BP_HARDWAREFLAG 2
2576 /* Check watchpoint condition. */
2579 watchpoint_check (void *p
)
2581 bpstat bs
= (bpstat
) p
;
2582 struct breakpoint
*b
;
2583 struct frame_info
*fr
;
2584 int within_current_scope
;
2586 b
= bs
->breakpoint_at
->owner
;
2588 if (b
->exp_valid_block
== NULL
)
2589 within_current_scope
= 1;
2592 /* There is no current frame at this moment. If we're going to have
2593 any chance of handling watchpoints on local variables, we'll need
2594 the frame chain (so we can determine if we're in scope). */
2595 reinit_frame_cache ();
2596 fr
= frame_find_by_id (b
->watchpoint_frame
);
2597 within_current_scope
= (fr
!= NULL
);
2599 /* If we've gotten confused in the unwinder, we might have
2600 returned a frame that can't describe this variable. */
2601 if (within_current_scope
2602 && (block_linkage_function (b
->exp_valid_block
)
2603 != get_frame_function (fr
)))
2604 within_current_scope
= 0;
2606 /* in_function_epilogue_p() returns a non-zero value if we're still
2607 in the function but the stack frame has already been invalidated.
2608 Since we can't rely on the values of local variables after the
2609 stack has been destroyed, we are treating the watchpoint in that
2610 state as `not changed' without further checking.
2612 vinschen/2003-09-04: The former implementation left out the case
2613 that the watchpoint frame couldn't be found by frame_find_by_id()
2614 because the current PC is currently in an epilogue. Calling
2615 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2616 if ((!within_current_scope
|| fr
== get_current_frame ())
2617 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2618 return WP_VALUE_NOT_CHANGED
;
2619 if (fr
&& within_current_scope
)
2620 /* If we end up stopping, the current frame will get selected
2621 in normal_stop. So this call to select_frame won't affect
2626 if (within_current_scope
)
2628 /* We use value_{,free_to_}mark because it could be a
2629 *long* time before we return to the command level and
2630 call free_all_values. We can't call free_all_values because
2631 we might be in the middle of evaluating a function call. */
2633 struct value
*mark
= value_mark ();
2634 struct value
*new_val
;
2636 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2637 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2638 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2640 if (new_val
!= NULL
)
2642 release_value (new_val
);
2643 value_free_to_mark (mark
);
2645 bs
->old_val
= b
->val
;
2648 /* We will stop here */
2649 return WP_VALUE_CHANGED
;
2653 /* Nothing changed, don't do anything. */
2654 value_free_to_mark (mark
);
2655 /* We won't stop here */
2656 return WP_VALUE_NOT_CHANGED
;
2661 /* This seems like the only logical thing to do because
2662 if we temporarily ignored the watchpoint, then when
2663 we reenter the block in which it is valid it contains
2664 garbage (in the case of a function, it may have two
2665 garbage values, one before and one after the prologue).
2666 So we can't even detect the first assignment to it and
2667 watch after that (since the garbage may or may not equal
2668 the first value assigned). */
2669 /* We print all the stop information in print_it_typical(), but
2670 in this case, by the time we call print_it_typical() this bp
2671 will be deleted already. So we have no choice but print the
2672 information here. */
2673 if (ui_out_is_mi_like_p (uiout
))
2675 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2676 ui_out_text (uiout
, "\nWatchpoint ");
2677 ui_out_field_int (uiout
, "wpnum", b
->number
);
2678 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2679 which its expression is valid.\n");
2681 if (b
->related_breakpoint
)
2682 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2683 b
->disposition
= disp_del_at_next_stop
;
2689 /* Return true if it looks like target has stopped due to hitting
2690 breakpoint location BL. This function does not check if we
2691 should stop, only if BL explains the stop. */
2693 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2695 struct breakpoint
*b
= bl
->owner
;
2697 if (b
->type
!= bp_watchpoint
2698 && b
->type
!= bp_hardware_watchpoint
2699 && b
->type
!= bp_read_watchpoint
2700 && b
->type
!= bp_access_watchpoint
2701 && b
->type
!= bp_hardware_breakpoint
2702 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2704 if (bl
->address
!= bp_addr
) /* address doesn't match */
2706 if (overlay_debugging
/* unmapped overlay section */
2707 && section_is_overlay (bl
->section
)
2708 && !section_is_mapped (bl
->section
))
2712 /* Continuable hardware watchpoints are treated as non-existent if the
2713 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2714 some data address). Otherwise gdb won't stop on a break instruction
2715 in the code (not from a breakpoint) when a hardware watchpoint has
2716 been defined. Also skip watchpoints which we know did not trigger
2717 (did not match the data address). */
2719 if ((b
->type
== bp_hardware_watchpoint
2720 || b
->type
== bp_read_watchpoint
2721 || b
->type
== bp_access_watchpoint
)
2722 && b
->watchpoint_triggered
== watch_triggered_no
)
2725 if (b
->type
== bp_hardware_breakpoint
)
2727 if (bl
->address
!= bp_addr
)
2729 if (overlay_debugging
/* unmapped overlay section */
2730 && section_is_overlay (bl
->section
)
2731 && !section_is_mapped (bl
->section
))
2735 if (b
->type
== bp_catchpoint
)
2737 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2738 if (!b
->ops
->breakpoint_hit (b
))
2745 /* If BS refers to a watchpoint, determine if the watched values
2746 has actually changed, and we should stop. If not, set BS->stop
2749 bpstat_check_watchpoint (bpstat bs
)
2751 const struct bp_location
*bl
= bs
->breakpoint_at
;
2752 struct breakpoint
*b
= bl
->owner
;
2754 if (b
->type
== bp_watchpoint
2755 || b
->type
== bp_read_watchpoint
2756 || b
->type
== bp_access_watchpoint
2757 || b
->type
== bp_hardware_watchpoint
)
2761 int must_check_value
= 0;
2763 if (b
->type
== bp_watchpoint
)
2764 /* For a software watchpoint, we must always check the
2766 must_check_value
= 1;
2767 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2768 /* We have a hardware watchpoint (read, write, or access)
2769 and the target earlier reported an address watched by
2771 must_check_value
= 1;
2772 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2773 && b
->type
== bp_hardware_watchpoint
)
2774 /* We were stopped by a hardware watchpoint, but the target could
2775 not report the data address. We must check the watchpoint's
2776 value. Access and read watchpoints are out of luck; without
2777 a data address, we can't figure it out. */
2778 must_check_value
= 1;
2780 if (must_check_value
)
2782 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2784 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2785 int e
= catch_errors (watchpoint_check
, bs
, message
,
2787 do_cleanups (cleanups
);
2791 /* We've already printed what needs to be printed. */
2792 bs
->print_it
= print_it_done
;
2795 case WP_VALUE_CHANGED
:
2796 if (b
->type
== bp_read_watchpoint
)
2798 /* Don't stop: read watchpoints shouldn't fire if
2799 the value has changed. This is for targets
2800 which cannot set read-only watchpoints. */
2801 bs
->print_it
= print_it_noop
;
2805 case WP_VALUE_NOT_CHANGED
:
2806 if (b
->type
== bp_hardware_watchpoint
2807 || b
->type
== bp_watchpoint
)
2809 /* Don't stop: write watchpoints shouldn't fire if
2810 the value hasn't changed. */
2811 bs
->print_it
= print_it_noop
;
2819 /* Error from catch_errors. */
2820 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2821 if (b
->related_breakpoint
)
2822 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2823 b
->disposition
= disp_del_at_next_stop
;
2824 /* We've already printed what needs to be printed. */
2825 bs
->print_it
= print_it_done
;
2829 else /* must_check_value == 0 */
2831 /* This is a case where some watchpoint(s) triggered, but
2832 not at the address of this watchpoint, or else no
2833 watchpoint triggered after all. So don't print
2834 anything for this watchpoint. */
2835 bs
->print_it
= print_it_noop
;
2842 /* Check conditions (condition proper, frame, thread and ignore count)
2843 of breakpoint referred to by BS. If we should not stop for this
2844 breakpoint, set BS->stop to 0. */
2846 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2848 int thread_id
= pid_to_thread_id (ptid
);
2849 const struct bp_location
*bl
= bs
->breakpoint_at
;
2850 struct breakpoint
*b
= bl
->owner
;
2852 if (frame_id_p (b
->frame_id
)
2853 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2857 int value_is_zero
= 0;
2859 /* If this is a scope breakpoint, mark the associated
2860 watchpoint as triggered so that we will handle the
2861 out-of-scope event. We'll get to the watchpoint next
2863 if (b
->type
== bp_watchpoint_scope
)
2864 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2866 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2868 /* Need to select the frame, with all that implies
2869 so that the conditions will have the right context. */
2870 select_frame (get_current_frame ());
2872 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2873 "Error in testing breakpoint condition:\n",
2875 /* FIXME-someday, should give breakpoint # */
2878 if (bl
->cond
&& value_is_zero
)
2882 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2886 else if (b
->ignore_count
> 0)
2889 annotate_ignore_count_change ();
2891 /* Increase the hit count even though we don't
2899 /* Get a bpstat associated with having just stopped at address
2900 BP_ADDR in thread PTID.
2902 Determine whether we stopped at a breakpoint, etc, or whether we
2903 don't understand this stop. Result is a chain of bpstat's such that:
2905 if we don't understand the stop, the result is a null pointer.
2907 if we understand why we stopped, the result is not null.
2909 Each element of the chain refers to a particular breakpoint or
2910 watchpoint at which we have stopped. (We may have stopped for
2911 several reasons concurrently.)
2913 Each element of the chain has valid next, breakpoint_at,
2914 commands, FIXME??? fields. */
2917 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2919 struct breakpoint
*b
= NULL
;
2920 const struct bp_location
*bl
;
2921 struct bp_location
*loc
;
2922 /* Root of the chain of bpstat's */
2923 struct bpstats root_bs
[1];
2924 /* Pointer to the last thing in the chain currently. */
2925 bpstat bs
= root_bs
;
2927 int need_remove_insert
;
2929 ALL_BP_LOCATIONS (bl
)
2933 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2936 /* For hardware watchpoints, we look only at the first location.
2937 The watchpoint_check function will work on entire expression,
2938 not the individual locations. For read watchopints, the
2939 watchpoints_triggered function have checked all locations
2942 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2945 if (!bpstat_check_location (bl
, bp_addr
))
2948 /* Come here if it's a watchpoint, or if the break address matches */
2950 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2952 /* Assume we stop. Should we find watchpoint that is not actually
2953 triggered, or if condition of breakpoint is false, we'll reset
2958 bpstat_check_watchpoint (bs
);
2962 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2963 /* We do not stop for these. */
2966 bpstat_check_breakpoint_conditions (bs
, ptid
);
2972 /* We will stop here */
2973 if (b
->disposition
== disp_disable
)
2975 if (b
->enable_state
!= bp_permanent
)
2976 b
->enable_state
= bp_disabled
;
2977 update_global_location_list (0);
2981 bs
->commands
= b
->commands
;
2983 (strcmp ("silent", bs
->commands
->line
) == 0
2984 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2986 bs
->commands
= bs
->commands
->next
;
2989 bs
->commands
= copy_command_lines (bs
->commands
);
2992 /* Print nothing for this entry if we dont stop or if we dont print. */
2993 if (bs
->stop
== 0 || bs
->print
== 0)
2994 bs
->print_it
= print_it_noop
;
2997 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2999 if (loc
->address
== bp_addr
)
3001 bs
= bpstat_alloc (loc
, bs
);
3002 /* For hits of moribund locations, we should just proceed. */
3005 bs
->print_it
= print_it_noop
;
3009 bs
->next
= NULL
; /* Terminate the chain */
3010 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3012 /* If we aren't stopping, the value of some hardware watchpoint may
3013 not have changed, but the intermediate memory locations we are
3014 watching may have. Don't bother if we're stopping; this will get
3016 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3020 need_remove_insert
= 0;
3022 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3024 && bs
->breakpoint_at
->owner
3025 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3026 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3027 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3029 /* remove/insert can invalidate bs->breakpoint_at, if this
3030 location is no longer used by the watchpoint. Prevent
3031 further code from trying to use it. */
3032 bs
->breakpoint_at
= NULL
;
3033 need_remove_insert
= 1;
3036 if (need_remove_insert
)
3038 remove_breakpoints ();
3039 insert_breakpoints ();
3042 return root_bs
->next
;
3045 /* Tell what to do about this bpstat. */
3047 bpstat_what (bpstat bs
)
3049 /* Classify each bpstat as one of the following. */
3052 /* This bpstat element has no effect on the main_action. */
3055 /* There was a watchpoint, stop but don't print. */
3058 /* There was a watchpoint, stop and print. */
3061 /* There was a breakpoint but we're not stopping. */
3064 /* There was a breakpoint, stop but don't print. */
3067 /* There was a breakpoint, stop and print. */
3070 /* We hit the longjmp breakpoint. */
3073 /* We hit the longjmp_resume breakpoint. */
3076 /* We hit the step_resume breakpoint. */
3079 /* We hit the shared library event breakpoint. */
3082 /* This is just used to count how many enums there are. */
3086 /* Here is the table which drives this routine. So that we can
3087 format it pretty, we define some abbreviations for the
3088 enum bpstat_what codes. */
3089 #define kc BPSTAT_WHAT_KEEP_CHECKING
3090 #define ss BPSTAT_WHAT_STOP_SILENT
3091 #define sn BPSTAT_WHAT_STOP_NOISY
3092 #define sgl BPSTAT_WHAT_SINGLE
3093 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3094 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3095 #define sr BPSTAT_WHAT_STEP_RESUME
3096 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3098 /* "Can't happen." Might want to print an error message.
3099 abort() is not out of the question, but chances are GDB is just
3100 a bit confused, not unusable. */
3101 #define err BPSTAT_WHAT_STOP_NOISY
3103 /* Given an old action and a class, come up with a new action. */
3104 /* One interesting property of this table is that wp_silent is the same
3105 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3106 after stopping, the check for whether to step over a breakpoint
3107 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3108 reference to how we stopped. We retain separate wp_silent and
3109 bp_silent codes in case we want to change that someday.
3111 Another possibly interesting property of this table is that
3112 there's a partial ordering, priority-like, of the actions. Once
3113 you've decided that some action is appropriate, you'll never go
3114 back and decide something of a lower priority is better. The
3117 kc < clr sgl shl slr sn sr ss
3118 sgl < shl slr sn sr ss
3119 slr < err shl sn sr ss
3120 clr < err shl sn sr ss
3126 What I think this means is that we don't need a damned table
3127 here. If you just put the rows and columns in the right order,
3128 it'd look awfully regular. We could simply walk the bpstat list
3129 and choose the highest priority action we find, with a little
3130 logic to handle the 'err' cases. */
3132 /* step_resume entries: a step resume breakpoint overrides another
3133 breakpoint of signal handling (see comment in wait_for_inferior
3134 at where we set the step_resume breakpoint). */
3136 static const enum bpstat_what_main_action
3137 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3140 /* kc ss sn sgl slr clr sr shl
3143 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3145 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3147 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3149 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3151 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3153 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3155 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3157 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3159 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3161 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3174 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3175 struct bpstat_what retval
;
3177 retval
.call_dummy
= 0;
3178 for (; bs
!= NULL
; bs
= bs
->next
)
3180 enum class bs_class
= no_effect
;
3181 if (bs
->breakpoint_at
== NULL
)
3182 /* I suspect this can happen if it was a momentary breakpoint
3183 which has since been deleted. */
3185 if (bs
->breakpoint_at
->owner
== NULL
)
3186 bs_class
= bp_nostop
;
3188 switch (bs
->breakpoint_at
->owner
->type
)
3194 case bp_hardware_breakpoint
:
3200 bs_class
= bp_noisy
;
3202 bs_class
= bp_silent
;
3205 bs_class
= bp_nostop
;
3208 case bp_hardware_watchpoint
:
3209 case bp_read_watchpoint
:
3210 case bp_access_watchpoint
:
3214 bs_class
= wp_noisy
;
3216 bs_class
= wp_silent
;
3219 /* There was a watchpoint, but we're not stopping.
3220 This requires no further action. */
3221 bs_class
= no_effect
;
3224 bs_class
= long_jump
;
3226 case bp_longjmp_resume
:
3227 bs_class
= long_resume
;
3229 case bp_step_resume
:
3232 bs_class
= step_resume
;
3235 /* It is for the wrong frame. */
3236 bs_class
= bp_nostop
;
3238 case bp_watchpoint_scope
:
3239 bs_class
= bp_nostop
;
3241 case bp_shlib_event
:
3242 bs_class
= shlib_event
;
3244 case bp_thread_event
:
3245 case bp_overlay_event
:
3246 bs_class
= bp_nostop
;
3252 bs_class
= bp_noisy
;
3254 bs_class
= bp_silent
;
3257 /* There was a catchpoint, but we're not stopping.
3258 This requires no further action. */
3259 bs_class
= no_effect
;
3262 /* Make sure the action is stop (silent or noisy),
3263 so infrun.c pops the dummy frame. */
3264 bs_class
= bp_silent
;
3265 retval
.call_dummy
= 1;
3268 current_action
= table
[(int) bs_class
][(int) current_action
];
3270 retval
.main_action
= current_action
;
3274 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3275 without hardware support). This isn't related to a specific bpstat,
3276 just to things like whether watchpoints are set. */
3279 bpstat_should_step (void)
3281 struct breakpoint
*b
;
3283 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3290 static void print_breakpoint_location (struct breakpoint
*b
,
3291 struct bp_location
*loc
,
3293 struct ui_stream
*stb
)
3298 = find_pc_sect_function (loc
->address
, loc
->section
);
3301 ui_out_text (uiout
, "in ");
3302 ui_out_field_string (uiout
, "func",
3303 SYMBOL_PRINT_NAME (sym
));
3304 ui_out_wrap_hint (uiout
, wrap_indent
);
3305 ui_out_text (uiout
, " at ");
3307 ui_out_field_string (uiout
, "file", b
->source_file
);
3308 ui_out_text (uiout
, ":");
3310 if (ui_out_is_mi_like_p (uiout
))
3312 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3313 char *fullname
= symtab_to_fullname (sal
.symtab
);
3316 ui_out_field_string (uiout
, "fullname", fullname
);
3319 ui_out_field_int (uiout
, "line", b
->line_number
);
3323 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3327 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3328 ui_out_field_stream (uiout
, "at", stb
);
3332 /* Print B to gdb_stdout. */
3334 print_one_breakpoint_location (struct breakpoint
*b
,
3335 struct bp_location
*loc
,
3337 CORE_ADDR
*last_addr
)
3339 struct command_line
*l
;
3341 struct ep_type_description
3346 static struct ep_type_description bptypes
[] =
3348 {bp_none
, "?deleted?"},
3349 {bp_breakpoint
, "breakpoint"},
3350 {bp_hardware_breakpoint
, "hw breakpoint"},
3351 {bp_until
, "until"},
3352 {bp_finish
, "finish"},
3353 {bp_watchpoint
, "watchpoint"},
3354 {bp_hardware_watchpoint
, "hw watchpoint"},
3355 {bp_read_watchpoint
, "read watchpoint"},
3356 {bp_access_watchpoint
, "acc watchpoint"},
3357 {bp_longjmp
, "longjmp"},
3358 {bp_longjmp_resume
, "longjmp resume"},
3359 {bp_step_resume
, "step resume"},
3360 {bp_watchpoint_scope
, "watchpoint scope"},
3361 {bp_call_dummy
, "call dummy"},
3362 {bp_shlib_event
, "shlib events"},
3363 {bp_thread_event
, "thread events"},
3364 {bp_overlay_event
, "overlay events"},
3365 {bp_catchpoint
, "catchpoint"},
3368 static char bpenables
[] = "nynny";
3369 char wrap_indent
[80];
3370 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3371 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3372 struct cleanup
*bkpt_chain
;
3374 int header_of_multiple
= 0;
3375 int part_of_multiple
= (loc
!= NULL
);
3376 struct value_print_options opts
;
3378 get_user_print_options (&opts
);
3380 gdb_assert (!loc
|| loc_number
!= 0);
3381 /* See comment in print_one_breakpoint concerning
3382 treatment of breakpoints with single disabled
3386 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3387 header_of_multiple
= 1;
3392 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3396 if (part_of_multiple
)
3399 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3400 ui_out_field_string (uiout
, "number", formatted
);
3405 ui_out_field_int (uiout
, "number", b
->number
);
3410 if (part_of_multiple
)
3411 ui_out_field_skip (uiout
, "type");
3414 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3415 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3416 internal_error (__FILE__
, __LINE__
,
3417 _("bptypes table does not describe type #%d."),
3419 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3424 if (part_of_multiple
)
3425 ui_out_field_skip (uiout
, "disp");
3427 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3432 if (part_of_multiple
)
3433 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3435 ui_out_field_fmt (uiout
, "enabled", "%c",
3436 bpenables
[(int) b
->enable_state
]);
3437 ui_out_spaces (uiout
, 2);
3441 strcpy (wrap_indent
, " ");
3442 if (opts
.addressprint
)
3444 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3445 strcat (wrap_indent
, " ");
3447 strcat (wrap_indent
, " ");
3450 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3452 /* Although the print_one can possibly print
3453 all locations, calling it here is not likely
3454 to get any nice result. So, make sure there's
3455 just one location. */
3456 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3457 b
->ops
->print_one (b
, last_addr
);
3463 internal_error (__FILE__
, __LINE__
,
3464 _("print_one_breakpoint: bp_none encountered\n"));
3468 case bp_hardware_watchpoint
:
3469 case bp_read_watchpoint
:
3470 case bp_access_watchpoint
:
3471 /* Field 4, the address, is omitted (which makes the columns
3472 not line up too nicely with the headers, but the effect
3473 is relatively readable). */
3474 if (opts
.addressprint
)
3475 ui_out_field_skip (uiout
, "addr");
3477 print_expression (b
->exp
, stb
->stream
);
3478 ui_out_field_stream (uiout
, "what", stb
);
3482 case bp_hardware_breakpoint
:
3486 case bp_longjmp_resume
:
3487 case bp_step_resume
:
3488 case bp_watchpoint_scope
:
3490 case bp_shlib_event
:
3491 case bp_thread_event
:
3492 case bp_overlay_event
:
3493 if (opts
.addressprint
)
3496 if (header_of_multiple
)
3497 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3498 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3499 ui_out_field_string (uiout
, "addr", "<PENDING>");
3501 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3504 if (!header_of_multiple
)
3505 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3507 *last_addr
= b
->loc
->address
;
3511 if (!part_of_multiple
&& b
->thread
!= -1)
3513 /* FIXME: This seems to be redundant and lost here; see the
3514 "stop only in" line a little further down. */
3515 ui_out_text (uiout
, " thread ");
3516 ui_out_field_int (uiout
, "thread", b
->thread
);
3519 ui_out_text (uiout
, "\n");
3521 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3524 ui_out_text (uiout
, "\tstop only in stack frame at ");
3525 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3527 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3528 ui_out_text (uiout
, "\n");
3531 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3533 /* We do not print the condition for Ada exception catchpoints
3534 because the condition is an internal implementation detail
3535 that we do not want to expose to the user. */
3537 ui_out_text (uiout
, "\tstop only if ");
3538 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3539 ui_out_text (uiout
, "\n");
3542 if (!part_of_multiple
&& b
->thread
!= -1)
3544 /* FIXME should make an annotation for this */
3545 ui_out_text (uiout
, "\tstop only in thread ");
3546 ui_out_field_int (uiout
, "thread", b
->thread
);
3547 ui_out_text (uiout
, "\n");
3550 if (!part_of_multiple
&& b
->hit_count
)
3552 /* FIXME should make an annotation for this */
3553 if (ep_is_catchpoint (b
))
3554 ui_out_text (uiout
, "\tcatchpoint");
3556 ui_out_text (uiout
, "\tbreakpoint");
3557 ui_out_text (uiout
, " already hit ");
3558 ui_out_field_int (uiout
, "times", b
->hit_count
);
3559 if (b
->hit_count
== 1)
3560 ui_out_text (uiout
, " time\n");
3562 ui_out_text (uiout
, " times\n");
3565 /* Output the count also if it is zero, but only if this is
3566 mi. FIXME: Should have a better test for this. */
3567 if (ui_out_is_mi_like_p (uiout
))
3568 if (!part_of_multiple
&& b
->hit_count
== 0)
3569 ui_out_field_int (uiout
, "times", b
->hit_count
);
3571 if (!part_of_multiple
&& b
->ignore_count
)
3574 ui_out_text (uiout
, "\tignore next ");
3575 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3576 ui_out_text (uiout
, " hits\n");
3579 if (!part_of_multiple
&& (l
= b
->commands
))
3581 struct cleanup
*script_chain
;
3584 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3585 print_command_lines (uiout
, l
, 4);
3586 do_cleanups (script_chain
);
3589 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3592 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3593 else if (b
->exp_string
)
3594 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3597 do_cleanups (bkpt_chain
);
3598 do_cleanups (old_chain
);
3602 print_one_breakpoint (struct breakpoint
*b
,
3603 CORE_ADDR
*last_addr
)
3605 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3607 /* If this breakpoint has custom print function,
3608 it's already printed. Otherwise, print individual
3609 locations, if any. */
3610 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3612 /* If breakpoint has a single location that is
3613 disabled, we print it as if it had
3614 several locations, since otherwise it's hard to
3615 represent "breakpoint enabled, location disabled"
3617 Note that while hardware watchpoints have
3618 several locations internally, that's no a property
3621 && !is_hardware_watchpoint (b
)
3622 && (b
->loc
->next
|| !b
->loc
->enabled
)
3623 && !ui_out_is_mi_like_p (uiout
))
3625 struct bp_location
*loc
;
3627 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3628 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3634 struct captured_breakpoint_query_args
3640 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3642 struct captured_breakpoint_query_args
*args
= data
;
3643 struct breakpoint
*b
;
3644 CORE_ADDR dummy_addr
= 0;
3647 if (args
->bnum
== b
->number
)
3649 print_one_breakpoint (b
, &dummy_addr
);
3657 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3659 struct captured_breakpoint_query_args args
;
3661 /* For the moment we don't trust print_one_breakpoint() to not throw
3663 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3664 error_message
, RETURN_MASK_ALL
) < 0)
3670 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3671 catchpoints, et.al.). */
3674 user_settable_breakpoint (const struct breakpoint
*b
)
3676 return (b
->type
== bp_breakpoint
3677 || b
->type
== bp_catchpoint
3678 || b
->type
== bp_hardware_breakpoint
3679 || b
->type
== bp_watchpoint
3680 || b
->type
== bp_read_watchpoint
3681 || b
->type
== bp_access_watchpoint
3682 || b
->type
== bp_hardware_watchpoint
);
3685 /* Print information on user settable breakpoint (watchpoint, etc)
3686 number BNUM. If BNUM is -1 print all user settable breakpoints.
3687 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3690 breakpoint_1 (int bnum
, int allflag
)
3692 struct breakpoint
*b
;
3693 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3694 int nr_printable_breakpoints
;
3695 struct cleanup
*bkpttbl_chain
;
3696 struct value_print_options opts
;
3698 get_user_print_options (&opts
);
3700 /* Compute the number of rows in the table. */
3701 nr_printable_breakpoints
= 0;
3704 || bnum
== b
->number
)
3706 if (allflag
|| user_settable_breakpoint (b
))
3707 nr_printable_breakpoints
++;
3710 if (opts
.addressprint
)
3712 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3716 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3719 if (nr_printable_breakpoints
> 0)
3720 annotate_breakpoints_headers ();
3721 if (nr_printable_breakpoints
> 0)
3723 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3724 if (nr_printable_breakpoints
> 0)
3726 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3727 if (nr_printable_breakpoints
> 0)
3729 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3730 if (nr_printable_breakpoints
> 0)
3732 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3733 if (opts
.addressprint
)
3735 if (nr_printable_breakpoints
> 0)
3737 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3738 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3740 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3742 if (nr_printable_breakpoints
> 0)
3744 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3745 ui_out_table_body (uiout
);
3746 if (nr_printable_breakpoints
> 0)
3747 annotate_breakpoints_table ();
3751 || bnum
== b
->number
)
3753 /* We only print out user settable breakpoints unless the
3755 if (allflag
|| user_settable_breakpoint (b
))
3756 print_one_breakpoint (b
, &last_addr
);
3759 do_cleanups (bkpttbl_chain
);
3761 if (nr_printable_breakpoints
== 0)
3764 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3766 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3771 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3772 that a comparison of an unsigned with -1 is always false. */
3773 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3774 set_next_address (current_gdbarch
, last_addr
);
3777 /* FIXME? Should this be moved up so that it is only called when
3778 there have been breakpoints? */
3779 annotate_breakpoints_table_end ();
3783 breakpoints_info (char *bnum_exp
, int from_tty
)
3788 bnum
= parse_and_eval_long (bnum_exp
);
3790 breakpoint_1 (bnum
, 0);
3794 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3799 bnum
= parse_and_eval_long (bnum_exp
);
3801 breakpoint_1 (bnum
, 1);
3805 breakpoint_has_pc (struct breakpoint
*b
,
3806 CORE_ADDR pc
, struct obj_section
*section
)
3808 struct bp_location
*bl
= b
->loc
;
3809 for (; bl
; bl
= bl
->next
)
3811 if (bl
->address
== pc
3812 && (!overlay_debugging
|| bl
->section
== section
))
3818 /* Print a message describing any breakpoints set at PC. */
3821 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3825 struct breakpoint
*b
;
3828 others
+= breakpoint_has_pc (b
, pc
, section
);
3832 printf_filtered (_("Note: breakpoint "));
3833 else /* if (others == ???) */
3834 printf_filtered (_("Note: breakpoints "));
3836 if (breakpoint_has_pc (b
, pc
, section
))
3839 printf_filtered ("%d", b
->number
);
3840 if (b
->thread
== -1 && thread
!= -1)
3841 printf_filtered (" (all threads)");
3842 else if (b
->thread
!= -1)
3843 printf_filtered (" (thread %d)", b
->thread
);
3844 printf_filtered ("%s%s ",
3845 ((b
->enable_state
== bp_disabled
||
3846 b
->enable_state
== bp_call_disabled
)
3848 : b
->enable_state
== bp_permanent
3852 : ((others
== 1) ? " and" : ""));
3854 printf_filtered (_("also set at pc "));
3855 fputs_filtered (paddress (pc
), gdb_stdout
);
3856 printf_filtered (".\n");
3860 /* Set the default place to put a breakpoint
3861 for the `break' command with no arguments. */
3864 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3867 default_breakpoint_valid
= valid
;
3868 default_breakpoint_address
= addr
;
3869 default_breakpoint_symtab
= symtab
;
3870 default_breakpoint_line
= line
;
3873 /* Return true iff it is meaningful to use the address member of
3874 BPT. For some breakpoint types, the address member is irrelevant
3875 and it makes no sense to attempt to compare it to other addresses
3876 (or use it for any other purpose either).
3878 More specifically, each of the following breakpoint types will always
3879 have a zero valued address and we don't want check_duplicates() to mark
3880 breakpoints of any of these types to be a duplicate of an actual
3881 breakpoint at address zero:
3884 bp_hardware_watchpoint
3886 bp_access_watchpoint
3890 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3892 enum bptype type
= bpt
->type
;
3894 return (type
!= bp_watchpoint
3895 && type
!= bp_hardware_watchpoint
3896 && type
!= bp_read_watchpoint
3897 && type
!= bp_access_watchpoint
3898 && type
!= bp_catchpoint
);
3901 /* Rescan breakpoints at the same address and section as BPT,
3902 marking the first one as "first" and any others as "duplicates".
3903 This is so that the bpt instruction is only inserted once.
3904 If we have a permanent breakpoint at the same place as BPT, make
3905 that one the official one, and the rest as duplicates. */
3908 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
3910 struct bp_location
*b
;
3912 struct bp_location
*perm_bp
= 0;
3914 ALL_BP_LOCATIONS (b
)
3915 if (b
->owner
->enable_state
!= bp_disabled
3916 && b
->owner
->enable_state
!= bp_call_disabled
3918 && !b
->shlib_disabled
3919 && b
->address
== address
/* address / overlay match */
3920 && (!overlay_debugging
|| b
->section
== section
)
3921 && breakpoint_address_is_meaningful (b
->owner
))
3923 /* Have we found a permanent breakpoint? */
3924 if (b
->owner
->enable_state
== bp_permanent
)
3931 b
->duplicate
= count
> 1;
3934 /* If we found a permanent breakpoint at this address, go over the
3935 list again and declare all the other breakpoints there to be the
3939 perm_bp
->duplicate
= 0;
3941 /* Permanent breakpoint should always be inserted. */
3942 if (! perm_bp
->inserted
)
3943 internal_error (__FILE__
, __LINE__
,
3944 _("allegedly permanent breakpoint is not "
3945 "actually inserted"));
3947 ALL_BP_LOCATIONS (b
)
3950 if (b
->owner
->enable_state
!= bp_disabled
3951 && b
->owner
->enable_state
!= bp_call_disabled
3952 && b
->enabled
&& !b
->shlib_disabled
3953 && b
->address
== address
/* address / overlay match */
3954 && (!overlay_debugging
|| b
->section
== section
)
3955 && breakpoint_address_is_meaningful (b
->owner
))
3958 internal_error (__FILE__
, __LINE__
,
3959 _("another breakpoint was inserted on top of "
3960 "a permanent breakpoint"));
3969 check_duplicates (struct breakpoint
*bpt
)
3971 struct bp_location
*bl
= bpt
->loc
;
3973 if (! breakpoint_address_is_meaningful (bpt
))
3976 for (; bl
; bl
= bl
->next
)
3977 check_duplicates_for (bl
->address
, bl
->section
);
3981 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3982 int bnum
, int have_bnum
)
3987 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
3988 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
3990 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
3991 bnum
, astr1
, astr2
);
3993 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
3996 /* Adjust a breakpoint's address to account for architectural constraints
3997 on breakpoint placement. Return the adjusted address. Note: Very
3998 few targets require this kind of adjustment. For most targets,
3999 this function is simply the identity function. */
4002 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4004 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4006 /* Very few targets need any kind of breakpoint adjustment. */
4009 else if (bptype
== bp_watchpoint
4010 || bptype
== bp_hardware_watchpoint
4011 || bptype
== bp_read_watchpoint
4012 || bptype
== bp_access_watchpoint
4013 || bptype
== bp_catchpoint
)
4015 /* Watchpoints and the various bp_catch_* eventpoints should not
4016 have their addresses modified. */
4021 CORE_ADDR adjusted_bpaddr
;
4023 /* Some targets have architectural constraints on the placement
4024 of breakpoint instructions. Obtain the adjusted address. */
4025 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4028 /* An adjusted breakpoint address can significantly alter
4029 a user's expectations. Print a warning if an adjustment
4031 if (adjusted_bpaddr
!= bpaddr
)
4032 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4034 return adjusted_bpaddr
;
4038 /* Allocate a struct bp_location. */
4040 static struct bp_location
*
4041 allocate_bp_location (struct breakpoint
*bpt
)
4043 struct bp_location
*loc
, *loc_p
;
4045 loc
= xmalloc (sizeof (struct bp_location
));
4046 memset (loc
, 0, sizeof (*loc
));
4050 loc
->shlib_disabled
= 0;
4059 case bp_longjmp_resume
:
4060 case bp_step_resume
:
4061 case bp_watchpoint_scope
:
4063 case bp_shlib_event
:
4064 case bp_thread_event
:
4065 case bp_overlay_event
:
4066 loc
->loc_type
= bp_loc_software_breakpoint
;
4068 case bp_hardware_breakpoint
:
4069 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4071 case bp_hardware_watchpoint
:
4072 case bp_read_watchpoint
:
4073 case bp_access_watchpoint
:
4074 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4078 loc
->loc_type
= bp_loc_other
;
4081 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4087 static void free_bp_location (struct bp_location
*loc
)
4092 if (loc
->function_name
)
4093 xfree (loc
->function_name
);
4098 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4099 that has type BPTYPE and has no locations as yet. */
4101 static struct breakpoint
*
4102 set_raw_breakpoint_without_location (enum bptype bptype
)
4104 struct breakpoint
*b
, *b1
;
4106 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4107 memset (b
, 0, sizeof (*b
));
4110 b
->language
= current_language
->la_language
;
4111 b
->input_radix
= input_radix
;
4113 b
->enable_state
= bp_enabled
;
4116 b
->ignore_count
= 0;
4118 b
->frame_id
= null_frame_id
;
4119 b
->forked_inferior_pid
= null_ptid
;
4120 b
->exec_pathname
= NULL
;
4122 b
->condition_not_parsed
= 0;
4124 /* Add this breakpoint to the end of the chain
4125 so that a list of breakpoints will come out in order
4126 of increasing numbers. */
4128 b1
= breakpoint_chain
;
4130 breakpoint_chain
= b
;
4140 /* Initialize loc->function_name. */
4142 set_breakpoint_location_function (struct bp_location
*loc
)
4144 if (loc
->owner
->type
== bp_breakpoint
4145 || loc
->owner
->type
== bp_hardware_breakpoint
)
4147 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4149 if (loc
->function_name
)
4150 loc
->function_name
= xstrdup (loc
->function_name
);
4154 /* set_raw_breakpoint is a low level routine for allocating and
4155 partially initializing a breakpoint of type BPTYPE. The newly
4156 created breakpoint's address, section, source file name, and line
4157 number are provided by SAL. The newly created and partially
4158 initialized breakpoint is added to the breakpoint chain and
4159 is also returned as the value of this function.
4161 It is expected that the caller will complete the initialization of
4162 the newly created breakpoint struct as well as output any status
4163 information regarding the creation of a new breakpoint. In
4164 particular, set_raw_breakpoint does NOT set the breakpoint
4165 number! Care should be taken to not allow an error to occur
4166 prior to completing the initialization of the breakpoint. If this
4167 should happen, a bogus breakpoint will be left on the chain. */
4170 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4172 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4173 CORE_ADDR adjusted_address
;
4175 /* Adjust the breakpoint's address prior to allocating a location.
4176 Once we call allocate_bp_location(), that mostly uninitialized
4177 location will be placed on the location chain. Adjustment of the
4178 breakpoint may cause target_read_memory() to be called and we do
4179 not want its scan of the location chain to find a breakpoint and
4180 location that's only been partially initialized. */
4181 adjusted_address
= adjust_breakpoint_address (sal
.pc
, b
->type
);
4183 b
->loc
= allocate_bp_location (b
);
4184 b
->loc
->requested_address
= sal
.pc
;
4185 b
->loc
->address
= adjusted_address
;
4187 if (sal
.symtab
== NULL
)
4188 b
->source_file
= NULL
;
4190 b
->source_file
= savestring (sal
.symtab
->filename
,
4191 strlen (sal
.symtab
->filename
));
4192 b
->loc
->section
= sal
.section
;
4193 b
->line_number
= sal
.line
;
4195 set_breakpoint_location_function (b
->loc
);
4197 breakpoints_changed ();
4203 /* Note that the breakpoint object B describes a permanent breakpoint
4204 instruction, hard-wired into the inferior's code. */
4206 make_breakpoint_permanent (struct breakpoint
*b
)
4208 struct bp_location
*bl
;
4209 b
->enable_state
= bp_permanent
;
4211 /* By definition, permanent breakpoints are already present in the code.
4212 Mark all locations as inserted. For now, make_breakpoint_permanent
4213 is called in just one place, so it's hard to say if it's reasonable
4214 to have permanent breakpoint with multiple locations or not,
4215 but it's easy to implmement. */
4216 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4220 static struct breakpoint
*
4221 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4223 static int internal_breakpoint_number
= -1;
4224 struct symtab_and_line sal
;
4225 struct breakpoint
*b
;
4227 init_sal (&sal
); /* initialize to zeroes */
4230 sal
.section
= find_pc_overlay (sal
.pc
);
4232 b
= set_raw_breakpoint (sal
, type
);
4233 b
->number
= internal_breakpoint_number
--;
4234 b
->disposition
= disp_donttouch
;
4241 create_longjmp_breakpoint (char *func_name
)
4243 struct minimal_symbol
*m
;
4245 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4247 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4248 update_global_location_list (1);
4251 /* Call this routine when stepping and nexting to enable a breakpoint
4252 if we do a longjmp(). When we hit that breakpoint, call
4253 set_longjmp_resume_breakpoint() to figure out where we are going. */
4256 set_longjmp_breakpoint (void)
4258 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4260 create_longjmp_breakpoint ("longjmp");
4261 create_longjmp_breakpoint ("_longjmp");
4262 create_longjmp_breakpoint ("siglongjmp");
4263 create_longjmp_breakpoint ("_siglongjmp");
4267 /* Delete all longjmp breakpoints from THREAD. */
4269 delete_longjmp_breakpoint (int thread
)
4271 struct breakpoint
*b
, *temp
;
4273 ALL_BREAKPOINTS_SAFE (b
, temp
)
4274 if (b
->type
== bp_longjmp
)
4276 if (b
->thread
== thread
)
4277 delete_breakpoint (b
);
4282 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4284 struct breakpoint
*b
;
4285 struct minimal_symbol
*m
;
4287 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4290 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4292 b
->addr_string
= xstrdup (func_name
);
4294 if (overlay_debugging
== ovly_auto
)
4296 b
->enable_state
= bp_enabled
;
4297 overlay_events_enabled
= 1;
4301 b
->enable_state
= bp_disabled
;
4302 overlay_events_enabled
= 0;
4304 update_global_location_list (1);
4308 create_overlay_event_breakpoint (char *func_name
)
4310 struct objfile
*objfile
;
4311 ALL_OBJFILES (objfile
)
4312 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4316 enable_overlay_breakpoints (void)
4318 struct breakpoint
*b
;
4321 if (b
->type
== bp_overlay_event
)
4323 b
->enable_state
= bp_enabled
;
4324 update_global_location_list (1);
4325 overlay_events_enabled
= 1;
4330 disable_overlay_breakpoints (void)
4332 struct breakpoint
*b
;
4335 if (b
->type
== bp_overlay_event
)
4337 b
->enable_state
= bp_disabled
;
4338 update_global_location_list (0);
4339 overlay_events_enabled
= 0;
4344 create_thread_event_breakpoint (CORE_ADDR address
)
4346 struct breakpoint
*b
;
4348 b
= create_internal_breakpoint (address
, bp_thread_event
);
4350 b
->enable_state
= bp_enabled
;
4351 /* addr_string has to be used or breakpoint_re_set will delete me. */
4352 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4354 update_global_location_list_nothrow (1);
4360 remove_thread_event_breakpoints (void)
4362 struct breakpoint
*b
, *temp
;
4364 ALL_BREAKPOINTS_SAFE (b
, temp
)
4365 if (b
->type
== bp_thread_event
)
4366 delete_breakpoint (b
);
4369 struct captured_parse_breakpoint_args
4372 struct symtabs_and_lines
*sals_p
;
4373 char ***addr_string_p
;
4377 struct lang_and_radix
4385 remove_solib_event_breakpoints (void)
4387 struct breakpoint
*b
, *temp
;
4389 ALL_BREAKPOINTS_SAFE (b
, temp
)
4390 if (b
->type
== bp_shlib_event
)
4391 delete_breakpoint (b
);
4395 create_solib_event_breakpoint (CORE_ADDR address
)
4397 struct breakpoint
*b
;
4399 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4400 update_global_location_list_nothrow (1);
4404 /* Disable any breakpoints that are on code in shared libraries. Only
4405 apply to enabled breakpoints, disabled ones can just stay disabled. */
4408 disable_breakpoints_in_shlibs (void)
4410 struct bp_location
*loc
;
4411 int disabled_shlib_breaks
= 0;
4413 ALL_BP_LOCATIONS (loc
)
4415 struct breakpoint
*b
= loc
->owner
;
4416 /* We apply the check to all breakpoints, including disabled
4417 for those with loc->duplicate set. This is so that when breakpoint
4418 becomes enabled, or the duplicate is removed, gdb will try to insert
4419 all breakpoints. If we don't set shlib_disabled here, we'll try
4420 to insert those breakpoints and fail. */
4421 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4422 && !loc
->shlib_disabled
4424 && PC_SOLIB (loc
->address
)
4426 && solib_address (loc
->address
)
4430 loc
->shlib_disabled
= 1;
4435 /* Disable any breakpoints that are in in an unloaded shared library. Only
4436 apply to enabled breakpoints, disabled ones can just stay disabled. */
4439 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4441 struct bp_location
*loc
;
4442 int disabled_shlib_breaks
= 0;
4444 ALL_BP_LOCATIONS (loc
)
4446 struct breakpoint
*b
= loc
->owner
;
4447 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4448 || loc
->loc_type
== bp_loc_software_breakpoint
)
4449 && !loc
->shlib_disabled
)
4452 char *so_name
= PC_SOLIB (loc
->address
);
4454 char *so_name
= solib_address (loc
->address
);
4456 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4458 loc
->shlib_disabled
= 1;
4459 /* At this point, we cannot rely on remove_breakpoint
4460 succeeding so we must mark the breakpoint as not inserted
4461 to prevent future errors occurring in remove_breakpoints. */
4463 if (!disabled_shlib_breaks
)
4465 target_terminal_ours_for_output ();
4466 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4469 disabled_shlib_breaks
= 1;
4475 /* FORK & VFORK catchpoints. */
4477 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4480 insert_catch_fork (struct breakpoint
*b
)
4482 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4485 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4488 remove_catch_fork (struct breakpoint
*b
)
4490 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4493 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4497 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4499 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4502 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4504 static enum print_stop_action
4505 print_it_catch_fork (struct breakpoint
*b
)
4507 annotate_catchpoint (b
->number
);
4508 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4509 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4510 return PRINT_SRC_AND_LOC
;
4513 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4516 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4518 struct value_print_options opts
;
4520 get_user_print_options (&opts
);
4522 /* Field 4, the address, is omitted (which makes the columns
4523 not line up too nicely with the headers, but the effect
4524 is relatively readable). */
4525 if (opts
.addressprint
)
4526 ui_out_field_skip (uiout
, "addr");
4528 ui_out_text (uiout
, "fork");
4529 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4531 ui_out_text (uiout
, ", process ");
4532 ui_out_field_int (uiout
, "what",
4533 ptid_get_pid (b
->forked_inferior_pid
));
4534 ui_out_spaces (uiout
, 1);
4538 /* Implement the "print_mention" breakpoint_ops method for fork
4542 print_mention_catch_fork (struct breakpoint
*b
)
4544 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4547 /* The breakpoint_ops structure to be used in fork catchpoints. */
4549 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4553 breakpoint_hit_catch_fork
,
4554 print_it_catch_fork
,
4555 print_one_catch_fork
,
4556 print_mention_catch_fork
4559 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4562 insert_catch_vfork (struct breakpoint
*b
)
4564 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4567 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4570 remove_catch_vfork (struct breakpoint
*b
)
4572 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4575 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4579 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4581 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4584 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4586 static enum print_stop_action
4587 print_it_catch_vfork (struct breakpoint
*b
)
4589 annotate_catchpoint (b
->number
);
4590 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4591 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4592 return PRINT_SRC_AND_LOC
;
4595 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4598 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4600 struct value_print_options opts
;
4602 get_user_print_options (&opts
);
4603 /* Field 4, the address, is omitted (which makes the columns
4604 not line up too nicely with the headers, but the effect
4605 is relatively readable). */
4606 if (opts
.addressprint
)
4607 ui_out_field_skip (uiout
, "addr");
4609 ui_out_text (uiout
, "vfork");
4610 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4612 ui_out_text (uiout
, ", process ");
4613 ui_out_field_int (uiout
, "what",
4614 ptid_get_pid (b
->forked_inferior_pid
));
4615 ui_out_spaces (uiout
, 1);
4619 /* Implement the "print_mention" breakpoint_ops method for vfork
4623 print_mention_catch_vfork (struct breakpoint
*b
)
4625 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4628 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4630 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4634 breakpoint_hit_catch_vfork
,
4635 print_it_catch_vfork
,
4636 print_one_catch_vfork
,
4637 print_mention_catch_vfork
4640 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4642 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4643 If COND_STRING is not NULL, then store it in the breakpoint.
4644 OPS, if not NULL, is the breakpoint_ops structure associated
4645 to the catchpoint. */
4647 static struct breakpoint
*
4648 create_catchpoint (int tempflag
, char *cond_string
,
4649 struct breakpoint_ops
*ops
)
4651 struct symtab_and_line sal
;
4652 struct breakpoint
*b
;
4659 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4660 set_breakpoint_count (breakpoint_count
+ 1);
4661 b
->number
= breakpoint_count
;
4663 b
->cond_string
= (cond_string
== NULL
) ?
4664 NULL
: savestring (cond_string
, strlen (cond_string
));
4666 b
->addr_string
= NULL
;
4667 b
->enable_state
= bp_enabled
;
4668 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4672 update_global_location_list (1);
4678 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4679 struct breakpoint_ops
*ops
)
4681 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4683 /* FIXME: We should put this information in a breakpoint private data
4685 b
->forked_inferior_pid
= null_ptid
;
4688 /* Exec catchpoints. */
4691 insert_catch_exec (struct breakpoint
*b
)
4693 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4697 remove_catch_exec (struct breakpoint
*b
)
4699 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4703 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4705 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4708 static enum print_stop_action
4709 print_it_catch_exec (struct breakpoint
*b
)
4711 annotate_catchpoint (b
->number
);
4712 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4714 return PRINT_SRC_AND_LOC
;
4718 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4720 struct value_print_options opts
;
4722 get_user_print_options (&opts
);
4724 /* Field 4, the address, is omitted (which makes the columns
4725 not line up too nicely with the headers, but the effect
4726 is relatively readable). */
4727 if (opts
.addressprint
)
4728 ui_out_field_skip (uiout
, "addr");
4730 ui_out_text (uiout
, "exec");
4731 if (b
->exec_pathname
!= NULL
)
4733 ui_out_text (uiout
, ", program \"");
4734 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4735 ui_out_text (uiout
, "\" ");
4740 print_mention_catch_exec (struct breakpoint
*b
)
4742 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4745 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4749 breakpoint_hit_catch_exec
,
4750 print_it_catch_exec
,
4751 print_one_catch_exec
,
4752 print_mention_catch_exec
4756 hw_breakpoint_used_count (void)
4758 struct breakpoint
*b
;
4763 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4771 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4773 struct breakpoint
*b
;
4776 *other_type_used
= 0;
4779 if (breakpoint_enabled (b
))
4781 if (b
->type
== type
)
4783 else if ((b
->type
== bp_hardware_watchpoint
||
4784 b
->type
== bp_read_watchpoint
||
4785 b
->type
== bp_access_watchpoint
))
4786 *other_type_used
= 1;
4793 disable_watchpoints_before_interactive_call_start (void)
4795 struct breakpoint
*b
;
4799 if (((b
->type
== bp_watchpoint
)
4800 || (b
->type
== bp_hardware_watchpoint
)
4801 || (b
->type
== bp_read_watchpoint
)
4802 || (b
->type
== bp_access_watchpoint
))
4803 && breakpoint_enabled (b
))
4805 b
->enable_state
= bp_call_disabled
;
4806 update_global_location_list (0);
4812 enable_watchpoints_after_interactive_call_stop (void)
4814 struct breakpoint
*b
;
4818 if (((b
->type
== bp_watchpoint
)
4819 || (b
->type
== bp_hardware_watchpoint
)
4820 || (b
->type
== bp_read_watchpoint
)
4821 || (b
->type
== bp_access_watchpoint
))
4822 && (b
->enable_state
== bp_call_disabled
))
4824 b
->enable_state
= bp_enabled
;
4825 update_global_location_list (1);
4831 /* Set a breakpoint that will evaporate an end of command
4832 at address specified by SAL.
4833 Restrict it to frame FRAME if FRAME is nonzero. */
4836 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4839 struct breakpoint
*b
;
4840 b
= set_raw_breakpoint (sal
, type
);
4841 b
->enable_state
= bp_enabled
;
4842 b
->disposition
= disp_donttouch
;
4843 b
->frame_id
= frame_id
;
4845 /* If we're debugging a multi-threaded program, then we
4846 want momentary breakpoints to be active in only a
4847 single thread of control. */
4848 if (in_thread_list (inferior_ptid
))
4849 b
->thread
= pid_to_thread_id (inferior_ptid
);
4851 update_global_location_list_nothrow (1);
4857 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4859 struct symtab_and_line sal
;
4861 sal
= find_pc_line (pc
, 0);
4863 sal
.section
= find_pc_overlay (pc
);
4864 sal
.explicit_pc
= 1;
4866 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4870 /* Tell the user we have just set a breakpoint B. */
4873 mention (struct breakpoint
*b
)
4876 struct cleanup
*old_chain
, *ui_out_chain
;
4877 struct ui_stream
*stb
;
4878 struct value_print_options opts
;
4880 get_user_print_options (&opts
);
4882 stb
= ui_out_stream_new (uiout
);
4883 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4885 /* FIXME: This is misplaced; mention() is called by things (like
4886 hitting a watchpoint) other than breakpoint creation. It should
4887 be possible to clean this up and at the same time replace the
4888 random calls to breakpoint_changed with this hook. */
4889 observer_notify_breakpoint_created (b
->number
);
4891 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4892 b
->ops
->print_mention (b
);
4897 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4900 ui_out_text (uiout
, "Watchpoint ");
4901 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4902 ui_out_field_int (uiout
, "number", b
->number
);
4903 ui_out_text (uiout
, ": ");
4904 print_expression (b
->exp
, stb
->stream
);
4905 ui_out_field_stream (uiout
, "exp", stb
);
4906 do_cleanups (ui_out_chain
);
4908 case bp_hardware_watchpoint
:
4909 ui_out_text (uiout
, "Hardware watchpoint ");
4910 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4911 ui_out_field_int (uiout
, "number", b
->number
);
4912 ui_out_text (uiout
, ": ");
4913 print_expression (b
->exp
, stb
->stream
);
4914 ui_out_field_stream (uiout
, "exp", stb
);
4915 do_cleanups (ui_out_chain
);
4917 case bp_read_watchpoint
:
4918 ui_out_text (uiout
, "Hardware read watchpoint ");
4919 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4920 ui_out_field_int (uiout
, "number", b
->number
);
4921 ui_out_text (uiout
, ": ");
4922 print_expression (b
->exp
, stb
->stream
);
4923 ui_out_field_stream (uiout
, "exp", stb
);
4924 do_cleanups (ui_out_chain
);
4926 case bp_access_watchpoint
:
4927 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4928 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4929 ui_out_field_int (uiout
, "number", b
->number
);
4930 ui_out_text (uiout
, ": ");
4931 print_expression (b
->exp
, stb
->stream
);
4932 ui_out_field_stream (uiout
, "exp", stb
);
4933 do_cleanups (ui_out_chain
);
4936 if (ui_out_is_mi_like_p (uiout
))
4941 if (b
->disposition
== disp_del
)
4942 printf_filtered (_("Temporary breakpoint"));
4944 printf_filtered (_("Breakpoint"));
4945 printf_filtered (_(" %d"), b
->number
);
4948 case bp_hardware_breakpoint
:
4949 if (ui_out_is_mi_like_p (uiout
))
4954 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4961 case bp_longjmp_resume
:
4962 case bp_step_resume
:
4964 case bp_watchpoint_scope
:
4965 case bp_shlib_event
:
4966 case bp_thread_event
:
4967 case bp_overlay_event
:
4973 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4977 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4981 if (opts
.addressprint
|| b
->source_file
== NULL
)
4983 printf_filtered (" at ");
4984 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4987 printf_filtered (": file %s, line %d.",
4988 b
->source_file
, b
->line_number
);
4992 struct bp_location
*loc
= b
->loc
;
4994 for (; loc
; loc
= loc
->next
)
4996 printf_filtered (" (%d locations)", n
);
5001 do_cleanups (old_chain
);
5002 if (ui_out_is_mi_like_p (uiout
))
5004 printf_filtered ("\n");
5008 static struct bp_location
*
5009 add_location_to_breakpoint (struct breakpoint
*b
,
5010 const struct symtab_and_line
*sal
)
5012 struct bp_location
*loc
, **tmp
;
5014 loc
= allocate_bp_location (b
);
5015 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5018 loc
->requested_address
= sal
->pc
;
5019 loc
->address
= adjust_breakpoint_address (loc
->requested_address
, b
->type
);
5020 loc
->section
= sal
->section
;
5022 set_breakpoint_location_function (loc
);
5027 /* Return 1 if LOC is pointing to a permanent breakpoint,
5028 return 0 otherwise. */
5031 bp_loc_is_permanent (struct bp_location
*loc
)
5035 const gdb_byte
*brk
;
5036 gdb_byte
*target_mem
;
5037 struct cleanup
*cleanup
;
5040 gdb_assert (loc
!= NULL
);
5042 addr
= loc
->address
;
5043 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5045 /* Software breakpoints unsupported? */
5049 target_mem
= alloca (len
);
5051 /* Enable the automatic memory restoration from breakpoints while
5052 we read the memory. Otherwise we could say about our temporary
5053 breakpoints they are permanent. */
5054 cleanup
= make_show_memory_breakpoints_cleanup (0);
5056 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5057 && memcmp (target_mem
, brk
, len
) == 0)
5060 do_cleanups (cleanup
);
5067 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5068 as textual description of the location, and COND_STRING
5069 as condition expression. */
5072 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5074 enum bptype type
, enum bpdisp disposition
,
5075 int thread
, int ignore_count
,
5076 struct breakpoint_ops
*ops
, int from_tty
)
5078 struct breakpoint
*b
= NULL
;
5081 if (type
== bp_hardware_breakpoint
)
5083 int i
= hw_breakpoint_used_count ();
5084 int target_resources_ok
=
5085 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5087 if (target_resources_ok
== 0)
5088 error (_("No hardware breakpoint support in the target."));
5089 else if (target_resources_ok
< 0)
5090 error (_("Hardware breakpoints used exceeds limit."));
5093 for (i
= 0; i
< sals
.nelts
; ++i
)
5095 struct symtab_and_line sal
= sals
.sals
[i
];
5096 struct bp_location
*loc
;
5099 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5103 b
= set_raw_breakpoint (sal
, type
);
5104 set_breakpoint_count (breakpoint_count
+ 1);
5105 b
->number
= breakpoint_count
;
5108 b
->cond_string
= cond_string
;
5109 b
->ignore_count
= ignore_count
;
5110 b
->enable_state
= bp_enabled
;
5111 b
->disposition
= disposition
;
5117 loc
= add_location_to_breakpoint (b
, &sal
);
5120 if (bp_loc_is_permanent (loc
))
5121 make_breakpoint_permanent (b
);
5125 char *arg
= b
->cond_string
;
5126 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5128 error (_("Garbage %s follows condition"), arg
);
5133 b
->addr_string
= addr_string
;
5135 /* addr_string has to be used or breakpoint_re_set will delete
5137 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5143 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5144 elements to fill the void space. */
5145 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5147 int i
= index_to_remove
+1;
5148 int last_index
= sal
->nelts
-1;
5150 for (;i
<= last_index
; ++i
)
5151 sal
->sals
[i
-1] = sal
->sals
[i
];
5156 /* If appropriate, obtains all sals that correspond
5157 to the same file and line as SAL. This is done
5158 only if SAL does not have explicit PC and has
5159 line and file information. If we got just a single
5160 expanded sal, return the original.
5162 Otherwise, if SAL.explicit_line is not set, filter out
5163 all sals for which the name of enclosing function
5164 is different from SAL. This makes sure that if we have
5165 breakpoint originally set in template instantiation, say
5166 foo<int>(), we won't expand SAL to locations at the same
5167 line in all existing instantiations of 'foo'.
5170 struct symtabs_and_lines
5171 expand_line_sal_maybe (struct symtab_and_line sal
)
5173 struct symtabs_and_lines expanded
;
5174 CORE_ADDR original_pc
= sal
.pc
;
5175 char *original_function
= NULL
;
5179 /* If we have explicit pc, don't expand.
5180 If we have no line number, we can't expand. */
5181 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5184 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5185 expanded
.sals
[0] = sal
;
5190 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5192 expanded
= expand_line_sal (sal
);
5193 if (expanded
.nelts
== 1)
5195 /* We had one sal, we got one sal. Without futher
5196 processing, just return the original sal. */
5197 xfree (expanded
.sals
);
5199 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5200 sal
.pc
= original_pc
;
5201 expanded
.sals
[0] = sal
;
5205 if (!sal
.explicit_line
)
5207 CORE_ADDR func_addr
, func_end
;
5208 for (i
= 0; i
< expanded
.nelts
; ++i
)
5210 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5211 char *this_function
;
5212 if (find_pc_partial_function (pc
, &this_function
,
5213 &func_addr
, &func_end
))
5215 if (this_function
&&
5216 strcmp (this_function
, original_function
) != 0)
5218 remove_sal (&expanded
, i
);
5221 else if (func_addr
== pc
)
5223 /* We're at beginning of a function, and should
5225 struct symbol
*sym
= find_pc_function (pc
);
5227 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5230 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5237 if (expanded
.nelts
<= 1)
5239 /* This is un ugly workaround. If we get zero
5240 expanded sals then something is really wrong.
5241 Fix that by returnign the original sal. */
5242 xfree (expanded
.sals
);
5244 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5245 sal
.pc
= original_pc
;
5246 expanded
.sals
[0] = sal
;
5253 for (i
= 0; i
< expanded
.nelts
; ++i
)
5254 if (expanded
.sals
[i
].pc
== original_pc
)
5265 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5266 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5267 value. COND_STRING, if not NULL, specified the condition to be
5268 used for all breakpoints. Essentially the only case where
5269 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5270 function. In that case, it's still not possible to specify
5271 separate conditions for different overloaded functions, so
5272 we take just a single condition string.
5274 NOTE: If the function succeeds, the caller is expected to cleanup
5275 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5276 array contents). If the function fails (error() is called), the
5277 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5278 COND and SALS arrays and each of those arrays contents. */
5281 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5283 enum bptype type
, enum bpdisp disposition
,
5284 int thread
, int ignore_count
,
5285 struct breakpoint_ops
*ops
, int from_tty
)
5288 for (i
= 0; i
< sals
.nelts
; ++i
)
5290 struct symtabs_and_lines expanded
=
5291 expand_line_sal_maybe (sals
.sals
[i
]);
5293 create_breakpoint (expanded
, addr_string
[i
],
5294 cond_string
, type
, disposition
,
5295 thread
, ignore_count
, ops
, from_tty
);
5298 update_global_location_list (1);
5301 /* Parse ARG which is assumed to be a SAL specification possibly
5302 followed by conditionals. On return, SALS contains an array of SAL
5303 addresses found. ADDR_STRING contains a vector of (canonical)
5304 address strings. ARG points to the end of the SAL. */
5307 parse_breakpoint_sals (char **address
,
5308 struct symtabs_and_lines
*sals
,
5309 char ***addr_string
,
5312 char *addr_start
= *address
;
5313 *addr_string
= NULL
;
5314 /* If no arg given, or if first arg is 'if ', use the default
5316 if ((*address
) == NULL
5317 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5319 if (default_breakpoint_valid
)
5321 struct symtab_and_line sal
;
5322 init_sal (&sal
); /* initialize to zeroes */
5323 sals
->sals
= (struct symtab_and_line
*)
5324 xmalloc (sizeof (struct symtab_and_line
));
5325 sal
.pc
= default_breakpoint_address
;
5326 sal
.line
= default_breakpoint_line
;
5327 sal
.symtab
= default_breakpoint_symtab
;
5328 sal
.section
= find_pc_overlay (sal
.pc
);
5329 sals
->sals
[0] = sal
;
5333 error (_("No default breakpoint address now."));
5337 /* Force almost all breakpoints to be in terms of the
5338 current_source_symtab (which is decode_line_1's default). This
5339 should produce the results we want almost all of the time while
5340 leaving default_breakpoint_* alone.
5341 ObjC: However, don't match an Objective-C method name which
5342 may have a '+' or '-' succeeded by a '[' */
5344 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5346 if (default_breakpoint_valid
5348 || ((strchr ("+-", (*address
)[0]) != NULL
)
5349 && ((*address
)[1] != '['))))
5350 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5351 default_breakpoint_line
, addr_string
,
5354 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5355 addr_string
, not_found_ptr
);
5357 /* For any SAL that didn't have a canonical string, fill one in. */
5358 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5359 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5360 if (addr_start
!= (*address
))
5363 for (i
= 0; i
< sals
->nelts
; i
++)
5365 /* Add the string if not present. */
5366 if ((*addr_string
)[i
] == NULL
)
5367 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5373 /* Convert each SAL into a real PC. Verify that the PC can be
5374 inserted as a breakpoint. If it can't throw an error. */
5377 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5381 for (i
= 0; i
< sals
->nelts
; i
++)
5382 resolve_sal_pc (&sals
->sals
[i
]);
5386 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5388 struct captured_parse_breakpoint_args
*args
= data
;
5390 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5391 args
->not_found_ptr
);
5394 /* Given TOK, a string specification of condition and thread, as
5395 accepted by the 'break' command, extract the condition
5396 string and thread number and set *COND_STRING and *THREAD.
5397 PC identifies the context at which the condition should be parsed.
5398 If no condition is found, *COND_STRING is set to NULL.
5399 If no thread is found, *THREAD is set to -1. */
5401 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5402 char **cond_string
, int *thread
)
5404 *cond_string
= NULL
;
5410 char *cond_start
= NULL
;
5411 char *cond_end
= NULL
;
5412 while (*tok
== ' ' || *tok
== '\t')
5417 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5420 toklen
= end_tok
- tok
;
5422 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5424 tok
= cond_start
= end_tok
+ 1;
5425 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5427 *cond_string
= savestring (cond_start
,
5428 cond_end
- cond_start
);
5430 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5436 *thread
= strtol (tok
, &tok
, 0);
5438 error (_("Junk after thread keyword."));
5439 if (!valid_thread_id (*thread
))
5440 error (_("Unknown thread %d."), *thread
);
5443 error (_("Junk at end of arguments."));
5447 /* Set a breakpoint. This function is shared between
5448 CLI and MI functions for setting a breakpoint.
5449 This function has two major modes of operations,
5450 selected by the PARSE_CONDITION_AND_THREAD parameter.
5451 If non-zero, the function will parse arg, extracting
5452 breakpoint location, address and thread. Otherwise,
5453 ARG is just the location of breakpoint, with condition
5454 and thread specified by the COND_STRING and THREAD
5458 break_command_really (char *arg
, char *cond_string
, int thread
,
5459 int parse_condition_and_thread
,
5460 int tempflag
, int hardwareflag
,
5462 enum auto_boolean pending_break_support
,
5463 struct breakpoint_ops
*ops
,
5466 struct gdb_exception e
;
5467 struct symtabs_and_lines sals
;
5468 struct symtab_and_line pending_sal
;
5471 char *addr_start
= arg
;
5473 struct cleanup
*old_chain
;
5474 struct cleanup
*breakpoint_chain
= NULL
;
5475 struct captured_parse_breakpoint_args parse_args
;
5484 parse_args
.arg_p
= &arg
;
5485 parse_args
.sals_p
= &sals
;
5486 parse_args
.addr_string_p
= &addr_string
;
5487 parse_args
.not_found_ptr
= ¬_found
;
5489 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5490 &parse_args
, RETURN_MASK_ALL
);
5492 /* If caller is interested in rc value from parse, set value. */
5496 throw_exception (e
);
5500 case NOT_FOUND_ERROR
:
5502 /* If pending breakpoint support is turned off, throw
5505 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5506 throw_exception (e
);
5508 exception_print (gdb_stderr
, e
);
5510 /* If pending breakpoint support is auto query and the user
5511 selects no, then simply return the error code. */
5512 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5513 !nquery ("Make breakpoint pending on future shared library load? "))
5516 /* At this point, either the user was queried about setting
5517 a pending breakpoint and selected yes, or pending
5518 breakpoint behavior is on and thus a pending breakpoint
5519 is defaulted on behalf of the user. */
5520 copy_arg
= xstrdup (addr_start
);
5521 addr_string
= ©_arg
;
5523 sals
.sals
= &pending_sal
;
5528 throw_exception (e
);
5535 /* Create a chain of things that always need to be cleaned up. */
5536 old_chain
= make_cleanup (null_cleanup
, 0);
5540 /* Make sure that all storage allocated to SALS gets freed. */
5541 make_cleanup (xfree
, sals
.sals
);
5543 /* Cleanup the addr_string array but not its contents. */
5544 make_cleanup (xfree
, addr_string
);
5547 /* ----------------------------- SNIP -----------------------------
5548 Anything added to the cleanup chain beyond this point is assumed
5549 to be part of a breakpoint. If the breakpoint create succeeds
5550 then the memory is not reclaimed. */
5551 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5553 /* Mark the contents of the addr_string for cleanup. These go on
5554 the breakpoint_chain and only occure if the breakpoint create
5556 for (i
= 0; i
< sals
.nelts
; i
++)
5558 if (addr_string
[i
] != NULL
)
5559 make_cleanup (xfree
, addr_string
[i
]);
5562 /* Resolve all line numbers to PC's and verify that the addresses
5563 are ok for the target. */
5565 breakpoint_sals_to_pc (&sals
, addr_start
);
5567 /* Verify that condition can be parsed, before setting any
5568 breakpoints. Allocate a separate condition expression for each
5572 if (parse_condition_and_thread
)
5574 /* Here we only parse 'arg' to separate condition
5575 from thread number, so parsing in context of first
5576 sal is OK. When setting the breakpoint we'll
5577 re-parse it in context of each sal. */
5580 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5582 make_cleanup (xfree
, cond_string
);
5586 /* Create a private copy of condition string. */
5589 cond_string
= xstrdup (cond_string
);
5590 make_cleanup (xfree
, cond_string
);
5593 create_breakpoints (sals
, addr_string
, cond_string
,
5594 hardwareflag
? bp_hardware_breakpoint
5596 tempflag
? disp_del
: disp_donttouch
,
5597 thread
, ignore_count
, ops
, from_tty
);
5601 struct symtab_and_line sal
= {0};
5602 struct breakpoint
*b
;
5604 make_cleanup (xfree
, copy_arg
);
5606 b
= set_raw_breakpoint_without_location (hardwareflag
5607 ? bp_hardware_breakpoint
5609 set_breakpoint_count (breakpoint_count
+ 1);
5610 b
->number
= breakpoint_count
;
5612 b
->addr_string
= addr_string
[0];
5613 b
->cond_string
= NULL
;
5614 b
->ignore_count
= ignore_count
;
5615 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5616 b
->condition_not_parsed
= 1;
5619 update_global_location_list (1);
5624 warning (_("Multiple breakpoints were set.\n"
5625 "Use the \"delete\" command to delete unwanted breakpoints."));
5626 /* That's it. Discard the cleanups for data inserted into the
5628 discard_cleanups (breakpoint_chain
);
5629 /* But cleanup everything else. */
5630 do_cleanups (old_chain
);
5633 /* Set a breakpoint.
5634 ARG is a string describing breakpoint address,
5635 condition, and thread.
5636 FLAG specifies if a breakpoint is hardware on,
5637 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5641 break_command_1 (char *arg
, int flag
, int from_tty
)
5643 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5644 int tempflag
= flag
& BP_TEMPFLAG
;
5646 break_command_really (arg
,
5647 NULL
, 0, 1 /* parse arg */,
5648 tempflag
, hardwareflag
,
5649 0 /* Ignore count */,
5650 pending_break_support
,
5651 NULL
/* breakpoint_ops */,
5657 set_breakpoint (char *address
, char *condition
,
5658 int hardwareflag
, int tempflag
,
5659 int thread
, int ignore_count
,
5662 break_command_really (address
, condition
, thread
,
5663 0 /* condition and thread are valid. */,
5664 tempflag
, hardwareflag
,
5667 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5671 /* Adjust SAL to the first instruction past the function prologue.
5672 The end of the prologue is determined using the line table from
5673 the debugging information.
5675 If SAL is already past the prologue, then do nothing. */
5678 skip_prologue_sal (struct symtab_and_line
*sal
)
5680 struct symbol
*sym
= find_pc_function (sal
->pc
);
5681 struct symtab_and_line start_sal
;
5686 start_sal
= find_function_start_sal (sym
, 1);
5687 if (sal
->pc
< start_sal
.pc
)
5691 /* Helper function for break_command_1 and disassemble_command. */
5694 resolve_sal_pc (struct symtab_and_line
*sal
)
5698 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5700 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5701 error (_("No line %d in file \"%s\"."),
5702 sal
->line
, sal
->symtab
->filename
);
5705 /* If this SAL corresponds to a breakpoint inserted using
5706 a line number, then skip the function prologue if necessary. */
5707 if (sal
->explicit_line
)
5708 skip_prologue_sal (sal
);
5711 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5713 struct blockvector
*bv
;
5717 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5720 sym
= block_linkage_function (b
);
5723 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5724 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5728 /* It really is worthwhile to have the section, so we'll just
5729 have to look harder. This case can be executed if we have
5730 line numbers but no functions (as can happen in assembly
5733 struct minimal_symbol
*msym
;
5735 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5737 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5744 break_command (char *arg
, int from_tty
)
5746 break_command_1 (arg
, 0, from_tty
);
5750 tbreak_command (char *arg
, int from_tty
)
5752 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5756 hbreak_command (char *arg
, int from_tty
)
5758 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5762 thbreak_command (char *arg
, int from_tty
)
5764 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5768 stop_command (char *arg
, int from_tty
)
5770 printf_filtered (_("Specify the type of breakpoint to set.\n\
5771 Usage: stop in <function | address>\n\
5772 stop at <line>\n"));
5776 stopin_command (char *arg
, int from_tty
)
5780 if (arg
== (char *) NULL
)
5782 else if (*arg
!= '*')
5787 /* look for a ':'. If this is a line number specification, then
5788 say it is bad, otherwise, it should be an address or
5789 function/method name */
5790 while (*argptr
&& !hasColon
)
5792 hasColon
= (*argptr
== ':');
5797 badInput
= (*argptr
!= ':'); /* Not a class::method */
5799 badInput
= isdigit (*arg
); /* a simple line number */
5803 printf_filtered (_("Usage: stop in <function | address>\n"));
5805 break_command_1 (arg
, 0, from_tty
);
5809 stopat_command (char *arg
, int from_tty
)
5813 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5820 /* look for a ':'. If there is a '::' then get out, otherwise
5821 it is probably a line number. */
5822 while (*argptr
&& !hasColon
)
5824 hasColon
= (*argptr
== ':');
5829 badInput
= (*argptr
== ':'); /* we have class::method */
5831 badInput
= !isdigit (*arg
); /* not a line number */
5835 printf_filtered (_("Usage: stop at <line>\n"));
5837 break_command_1 (arg
, 0, from_tty
);
5840 /* accessflag: hw_write: watch write,
5841 hw_read: watch read,
5842 hw_access: watch access (read or write) */
5844 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5846 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5847 struct symtab_and_line sal
;
5848 struct expression
*exp
;
5849 struct block
*exp_valid_block
;
5850 struct value
*val
, *mark
;
5851 struct frame_info
*frame
;
5852 struct frame_info
*prev_frame
= NULL
;
5853 char *exp_start
= NULL
;
5854 char *exp_end
= NULL
;
5855 char *tok
, *id_tok_start
, *end_tok
;
5857 char *cond_start
= NULL
;
5858 char *cond_end
= NULL
;
5859 struct expression
*cond
= NULL
;
5860 int i
, other_type_used
, target_resources_ok
= 0;
5861 enum bptype bp_type
;
5865 init_sal (&sal
); /* initialize to zeroes */
5867 /* Make sure that we actually have parameters to parse. */
5868 if (arg
!= NULL
&& arg
[0] != '\0')
5870 toklen
= strlen (arg
); /* Size of argument list. */
5872 /* Points tok to the end of the argument list. */
5873 tok
= arg
+ toklen
- 1;
5875 /* Go backwards in the parameters list. Skip the last parameter.
5876 If we're expecting a 'thread <thread_num>' parameter, this should
5877 be the thread identifier. */
5878 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5880 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5883 /* Points end_tok to the beginning of the last token. */
5884 id_tok_start
= tok
+ 1;
5886 /* Go backwards in the parameters list. Skip one more parameter.
5887 If we're expecting a 'thread <thread_num>' parameter, we should
5888 reach a "thread" token. */
5889 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5894 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5897 /* Move the pointer forward to skip the whitespace and
5898 calculate the length of the token. */
5900 toklen
= end_tok
- tok
;
5902 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5904 /* At this point we've found a "thread" token, which means
5905 the user is trying to set a watchpoint that triggers
5906 only in a specific thread. */
5909 /* Extract the thread ID from the next token. */
5910 thread
= strtol (id_tok_start
, &endp
, 0);
5912 /* Check if the user provided a valid numeric value for the
5914 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5915 error (_("Invalid thread ID specification %s."), id_tok_start
);
5917 /* Check if the thread actually exists. */
5918 if (!valid_thread_id (thread
))
5919 error (_("Unknown thread %d."), thread
);
5921 /* Truncate the string and get rid of the thread <thread_num>
5922 parameter before the parameter list is parsed by the
5923 evaluate_expression() function. */
5928 /* Parse the rest of the arguments. */
5929 innermost_block
= NULL
;
5931 exp
= parse_exp_1 (&arg
, 0, 0);
5933 exp_valid_block
= innermost_block
;
5934 mark
= value_mark ();
5935 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5937 release_value (val
);
5940 while (*tok
== ' ' || *tok
== '\t')
5944 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5947 toklen
= end_tok
- tok
;
5948 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5950 tok
= cond_start
= end_tok
+ 1;
5951 cond
= parse_exp_1 (&tok
, 0, 0);
5955 error (_("Junk at end of command."));
5957 if (accessflag
== hw_read
)
5958 bp_type
= bp_read_watchpoint
;
5959 else if (accessflag
== hw_access
)
5960 bp_type
= bp_access_watchpoint
;
5962 bp_type
= bp_hardware_watchpoint
;
5964 mem_cnt
= can_use_hardware_watchpoint (val
);
5965 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5966 error (_("Expression cannot be implemented with read/access watchpoint."));
5969 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5970 target_resources_ok
=
5971 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5973 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5974 error (_("Target does not support this type of hardware watchpoint."));
5976 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5977 error (_("Target can only support one kind of HW watchpoint at a time."));
5980 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5981 watchpoint could not be set. */
5982 if (!mem_cnt
|| target_resources_ok
<= 0)
5983 bp_type
= bp_watchpoint
;
5985 frame
= block_innermost_frame (exp_valid_block
);
5987 prev_frame
= get_prev_frame (frame
);
5991 /* If the expression is "local", then set up a "watchpoint scope"
5992 breakpoint at the point where we've left the scope of the watchpoint
5993 expression. Create the scope breakpoint before the watchpoint, so
5994 that we will encounter it first in bpstat_stop_status. */
5995 if (innermost_block
&& prev_frame
)
5997 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5998 bp_watchpoint_scope
);
6000 scope_breakpoint
->enable_state
= bp_enabled
;
6002 /* Automatically delete the breakpoint when it hits. */
6003 scope_breakpoint
->disposition
= disp_del
;
6005 /* Only break in the proper frame (help with recursion). */
6006 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6008 /* Set the address at which we will stop. */
6009 scope_breakpoint
->loc
->requested_address
6010 = get_frame_pc (prev_frame
);
6011 scope_breakpoint
->loc
->address
6012 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6013 scope_breakpoint
->type
);
6016 /* Now set up the breakpoint. */
6017 b
= set_raw_breakpoint (sal
, bp_type
);
6018 set_breakpoint_count (breakpoint_count
+ 1);
6019 b
->number
= breakpoint_count
;
6021 b
->disposition
= disp_donttouch
;
6023 b
->exp_valid_block
= exp_valid_block
;
6024 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6027 b
->loc
->cond
= cond
;
6029 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6034 b
->watchpoint_frame
= get_frame_id (frame
);
6036 b
->watchpoint_frame
= null_frame_id
;
6038 if (scope_breakpoint
!= NULL
)
6040 /* The scope breakpoint is related to the watchpoint. We will
6041 need to act on them together. */
6042 b
->related_breakpoint
= scope_breakpoint
;
6043 scope_breakpoint
->related_breakpoint
= b
;
6046 value_free_to_mark (mark
);
6048 update_global_location_list (1);
6051 /* Return count of locations need to be watched and can be handled
6052 in hardware. If the watchpoint can not be handled
6053 in hardware return zero. */
6056 can_use_hardware_watchpoint (struct value
*v
)
6058 int found_memory_cnt
= 0;
6059 struct value
*head
= v
;
6061 /* Did the user specifically forbid us to use hardware watchpoints? */
6062 if (!can_use_hw_watchpoints
)
6065 /* Make sure that the value of the expression depends only upon
6066 memory contents, and values computed from them within GDB. If we
6067 find any register references or function calls, we can't use a
6068 hardware watchpoint.
6070 The idea here is that evaluating an expression generates a series
6071 of values, one holding the value of every subexpression. (The
6072 expression a*b+c has five subexpressions: a, b, a*b, c, and
6073 a*b+c.) GDB's values hold almost enough information to establish
6074 the criteria given above --- they identify memory lvalues,
6075 register lvalues, computed values, etcetera. So we can evaluate
6076 the expression, and then scan the chain of values that leaves
6077 behind to decide whether we can detect any possible change to the
6078 expression's final value using only hardware watchpoints.
6080 However, I don't think that the values returned by inferior
6081 function calls are special in any way. So this function may not
6082 notice that an expression involving an inferior function call
6083 can't be watched with hardware watchpoints. FIXME. */
6084 for (; v
; v
= value_next (v
))
6086 if (VALUE_LVAL (v
) == lval_memory
)
6089 /* A lazy memory lvalue is one that GDB never needed to fetch;
6090 we either just used its address (e.g., `a' in `a.b') or
6091 we never needed it at all (e.g., `a' in `a,b'). */
6095 /* Ahh, memory we actually used! Check if we can cover
6096 it with hardware watchpoints. */
6097 struct type
*vtype
= check_typedef (value_type (v
));
6099 /* We only watch structs and arrays if user asked for it
6100 explicitly, never if they just happen to appear in a
6101 middle of some value chain. */
6103 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6104 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6106 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6107 int len
= TYPE_LENGTH (value_type (v
));
6109 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6116 else if (VALUE_LVAL (v
) != not_lval
6117 && deprecated_value_modifiable (v
) == 0)
6118 return 0; /* ??? What does this represent? */
6119 else if (VALUE_LVAL (v
) == lval_register
)
6120 return 0; /* cannot watch a register with a HW watchpoint */
6123 /* The expression itself looks suitable for using a hardware
6124 watchpoint, but give the target machine a chance to reject it. */
6125 return found_memory_cnt
;
6129 watch_command_wrapper (char *arg
, int from_tty
)
6131 watch_command (arg
, from_tty
);
6135 watch_command (char *arg
, int from_tty
)
6137 watch_command_1 (arg
, hw_write
, from_tty
);
6141 rwatch_command_wrapper (char *arg
, int from_tty
)
6143 rwatch_command (arg
, from_tty
);
6147 rwatch_command (char *arg
, int from_tty
)
6149 watch_command_1 (arg
, hw_read
, from_tty
);
6153 awatch_command_wrapper (char *arg
, int from_tty
)
6155 awatch_command (arg
, from_tty
);
6159 awatch_command (char *arg
, int from_tty
)
6161 watch_command_1 (arg
, hw_access
, from_tty
);
6165 /* Helper routines for the until_command routine in infcmd.c. Here
6166 because it uses the mechanisms of breakpoints. */
6168 struct until_break_command_continuation_args
6170 struct breakpoint
*breakpoint
;
6171 struct breakpoint
*breakpoint2
;
6174 /* This function is called by fetch_inferior_event via the
6175 cmd_continuation pointer, to complete the until command. It takes
6176 care of cleaning up the temporary breakpoints set up by the until
6179 until_break_command_continuation (void *arg
)
6181 struct until_break_command_continuation_args
*a
= arg
;
6183 delete_breakpoint (a
->breakpoint
);
6185 delete_breakpoint (a
->breakpoint2
);
6189 until_break_command (char *arg
, int from_tty
, int anywhere
)
6191 struct symtabs_and_lines sals
;
6192 struct symtab_and_line sal
;
6193 struct frame_info
*frame
= get_selected_frame (NULL
);
6194 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6195 struct breakpoint
*breakpoint
;
6196 struct breakpoint
*breakpoint2
= NULL
;
6197 struct cleanup
*old_chain
;
6199 clear_proceed_status ();
6201 /* Set a breakpoint where the user wants it and at return from
6204 if (default_breakpoint_valid
)
6205 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6206 default_breakpoint_line
, (char ***) NULL
, NULL
);
6208 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6209 0, (char ***) NULL
, NULL
);
6211 if (sals
.nelts
!= 1)
6212 error (_("Couldn't get information on specified line."));
6215 xfree (sals
.sals
); /* malloc'd, so freed */
6218 error (_("Junk at end of arguments."));
6220 resolve_sal_pc (&sal
);
6223 /* If the user told us to continue until a specified location,
6224 we don't specify a frame at which we need to stop. */
6225 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6227 /* Otherwise, specify the current frame, because we want to stop only
6228 at the very same frame. */
6229 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6232 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6234 /* Keep within the current frame, or in frames called by the current
6238 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6239 sal
.pc
= get_frame_pc (prev_frame
);
6240 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6242 make_cleanup_delete_breakpoint (breakpoint2
);
6245 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6247 /* If we are running asynchronously, and proceed call above has actually
6248 managed to start the target, arrange for breakpoints to be
6249 deleted when the target stops. Otherwise, we're already stopped and
6250 delete breakpoints via cleanup chain. */
6252 if (target_can_async_p () && is_running (inferior_ptid
))
6254 struct until_break_command_continuation_args
*args
;
6255 args
= xmalloc (sizeof (*args
));
6257 args
->breakpoint
= breakpoint
;
6258 args
->breakpoint2
= breakpoint2
;
6260 discard_cleanups (old_chain
);
6261 add_continuation (inferior_thread (),
6262 until_break_command_continuation
, args
,
6266 do_cleanups (old_chain
);
6270 ep_skip_leading_whitespace (char **s
)
6272 if ((s
== NULL
) || (*s
== NULL
))
6274 while (isspace (**s
))
6278 /* This function attempts to parse an optional "if <cond>" clause
6279 from the arg string. If one is not found, it returns NULL.
6281 Else, it returns a pointer to the condition string. (It does not
6282 attempt to evaluate the string against a particular block.) And,
6283 it updates arg to point to the first character following the parsed
6284 if clause in the arg string. */
6287 ep_parse_optional_if_clause (char **arg
)
6291 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6294 /* Skip the "if" keyword. */
6297 /* Skip any extra leading whitespace, and record the start of the
6298 condition string. */
6299 ep_skip_leading_whitespace (arg
);
6302 /* Assume that the condition occupies the remainder of the arg string. */
6303 (*arg
) += strlen (cond_string
);
6308 /* This function attempts to parse an optional filename from the arg
6309 string. If one is not found, it returns NULL.
6311 Else, it returns a pointer to the parsed filename. (This function
6312 makes no attempt to verify that a file of that name exists, or is
6313 accessible.) And, it updates arg to point to the first character
6314 following the parsed filename in the arg string.
6316 Note that clients needing to preserve the returned filename for
6317 future access should copy it to their own buffers. */
6319 ep_parse_optional_filename (char **arg
)
6321 static char filename
[1024];
6326 if ((*arg_p
== '\0') || isspace (*arg_p
))
6344 /* Commands to deal with catching events, such as signals, exceptions,
6345 process start/exit, etc. */
6349 catch_fork_temporary
, catch_vfork_temporary
,
6350 catch_fork_permanent
, catch_vfork_permanent
6355 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6357 char *cond_string
= NULL
;
6358 catch_fork_kind fork_kind
;
6361 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6362 tempflag
= (fork_kind
== catch_fork_temporary
6363 || fork_kind
== catch_vfork_temporary
);
6367 ep_skip_leading_whitespace (&arg
);
6369 /* The allowed syntax is:
6371 catch [v]fork if <cond>
6373 First, check if there's an if clause. */
6374 cond_string
= ep_parse_optional_if_clause (&arg
);
6376 if ((*arg
!= '\0') && !isspace (*arg
))
6377 error (_("Junk at end of arguments."));
6379 /* If this target supports it, create a fork or vfork catchpoint
6380 and enable reporting of such events. */
6383 case catch_fork_temporary
:
6384 case catch_fork_permanent
:
6385 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6386 &catch_fork_breakpoint_ops
);
6388 case catch_vfork_temporary
:
6389 case catch_vfork_permanent
:
6390 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6391 &catch_vfork_breakpoint_ops
);
6394 error (_("unsupported or unknown fork kind; cannot catch it"));
6400 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6403 char *cond_string
= NULL
;
6405 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6409 ep_skip_leading_whitespace (&arg
);
6411 /* The allowed syntax is:
6413 catch exec if <cond>
6415 First, check if there's an if clause. */
6416 cond_string
= ep_parse_optional_if_clause (&arg
);
6418 if ((*arg
!= '\0') && !isspace (*arg
))
6419 error (_("Junk at end of arguments."));
6421 /* If this target supports it, create an exec catchpoint
6422 and enable reporting of such events. */
6423 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6426 static enum print_stop_action
6427 print_exception_catchpoint (struct breakpoint
*b
)
6429 int bp_temp
, bp_throw
;
6431 annotate_catchpoint (b
->number
);
6433 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6434 if (b
->loc
->address
!= b
->loc
->requested_address
)
6435 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6438 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6440 bp_temp
? "Temporary catchpoint "
6442 if (!ui_out_is_mi_like_p (uiout
))
6443 ui_out_field_int (uiout
, "bkptno", b
->number
);
6445 bp_throw
? " (exception thrown), "
6446 : " (exception caught), ");
6447 if (ui_out_is_mi_like_p (uiout
))
6449 ui_out_field_string (uiout
, "reason",
6450 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6451 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6452 ui_out_field_int (uiout
, "bkptno", b
->number
);
6454 return PRINT_SRC_AND_LOC
;
6458 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6460 struct value_print_options opts
;
6461 get_user_print_options (&opts
);
6462 if (opts
.addressprint
)
6465 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6466 ui_out_field_string (uiout
, "addr", "<PENDING>");
6468 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6472 *last_addr
= b
->loc
->address
;
6473 if (strstr (b
->addr_string
, "throw") != NULL
)
6474 ui_out_field_string (uiout
, "what", "exception throw");
6476 ui_out_field_string (uiout
, "what", "exception catch");
6480 print_mention_exception_catchpoint (struct breakpoint
*b
)
6485 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6486 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6487 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6488 : _("Catchpoint "));
6489 ui_out_field_int (uiout
, "bkptno", b
->number
);
6490 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6494 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6497 NULL
, /* breakpoint_hit */
6498 print_exception_catchpoint
,
6499 print_one_exception_catchpoint
,
6500 print_mention_exception_catchpoint
6504 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6505 enum exception_event_kind ex_event
, int from_tty
)
6507 char *trigger_func_name
;
6509 if (ex_event
== EX_EVENT_CATCH
)
6510 trigger_func_name
= "__cxa_begin_catch";
6512 trigger_func_name
= "__cxa_throw";
6514 break_command_really (trigger_func_name
, cond_string
, -1,
6515 0 /* condition and thread are valid. */,
6518 AUTO_BOOLEAN_TRUE
/* pending */,
6519 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6524 /* Deal with "catch catch" and "catch throw" commands */
6527 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6528 int tempflag
, int from_tty
)
6530 char *cond_string
= NULL
;
6531 struct symtab_and_line
*sal
= NULL
;
6535 ep_skip_leading_whitespace (&arg
);
6537 cond_string
= ep_parse_optional_if_clause (&arg
);
6539 if ((*arg
!= '\0') && !isspace (*arg
))
6540 error (_("Junk at end of arguments."));
6542 if ((ex_event
!= EX_EVENT_THROW
) &&
6543 (ex_event
!= EX_EVENT_CATCH
))
6544 error (_("Unsupported or unknown exception event; cannot catch it"));
6546 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6549 warning (_("Unsupported with this platform/compiler combination."));
6552 /* Implementation of "catch catch" command. */
6555 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6557 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6558 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6561 /* Implementation of "catch throw" command. */
6564 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6566 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6567 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6570 /* Create a breakpoint struct for Ada exception catchpoints. */
6573 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6577 struct expression
*cond
,
6578 struct breakpoint_ops
*ops
,
6582 struct breakpoint
*b
;
6586 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6587 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6588 version for exception catchpoints, because two catchpoints
6589 used for different exception names will use the same address.
6590 In this case, a "breakpoint ... also set at..." warning is
6591 unproductive. Besides. the warning phrasing is also a bit
6592 inapropriate, we should use the word catchpoint, and tell
6593 the user what type of catchpoint it is. The above is good
6594 enough for now, though. */
6597 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6598 set_breakpoint_count (breakpoint_count
+ 1);
6600 b
->enable_state
= bp_enabled
;
6601 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6602 b
->number
= breakpoint_count
;
6603 b
->ignore_count
= 0;
6604 b
->loc
->cond
= cond
;
6605 b
->addr_string
= addr_string
;
6606 b
->language
= language_ada
;
6607 b
->cond_string
= cond_string
;
6608 b
->exp_string
= exp_string
;
6613 update_global_location_list (1);
6616 /* Implement the "catch exception" command. */
6619 catch_ada_exception_command (char *arg
, int from_tty
,
6620 struct cmd_list_element
*command
)
6623 struct symtab_and_line sal
;
6625 char *addr_string
= NULL
;
6626 char *exp_string
= NULL
;
6627 char *cond_string
= NULL
;
6628 struct expression
*cond
= NULL
;
6629 struct breakpoint_ops
*ops
= NULL
;
6631 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6635 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6636 &cond_string
, &cond
, &ops
);
6637 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6638 cond_string
, cond
, ops
, tempflag
,
6642 /* Implement the "catch assert" command. */
6645 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6648 struct symtab_and_line sal
;
6649 char *addr_string
= NULL
;
6650 struct breakpoint_ops
*ops
= NULL
;
6652 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6656 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6657 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6658 tempflag
, from_tty
);
6662 catch_command (char *arg
, int from_tty
)
6664 error (_("Catch requires an event name."));
6669 tcatch_command (char *arg
, int from_tty
)
6671 error (_("Catch requires an event name."));
6674 /* Delete breakpoints by address or line. */
6677 clear_command (char *arg
, int from_tty
)
6679 struct breakpoint
*b
;
6680 VEC(breakpoint_p
) *found
= 0;
6683 struct symtabs_and_lines sals
;
6684 struct symtab_and_line sal
;
6689 sals
= decode_line_spec (arg
, 1);
6694 sals
.sals
= (struct symtab_and_line
*)
6695 xmalloc (sizeof (struct symtab_and_line
));
6696 make_cleanup (xfree
, sals
.sals
);
6697 init_sal (&sal
); /* initialize to zeroes */
6698 sal
.line
= default_breakpoint_line
;
6699 sal
.symtab
= default_breakpoint_symtab
;
6700 sal
.pc
= default_breakpoint_address
;
6701 if (sal
.symtab
== 0)
6702 error (_("No source file specified."));
6710 /* We don't call resolve_sal_pc here. That's not
6711 as bad as it seems, because all existing breakpoints
6712 typically have both file/line and pc set. So, if
6713 clear is given file/line, we can match this to existing
6714 breakpoint without obtaining pc at all.
6716 We only support clearing given the address explicitly
6717 present in breakpoint table. Say, we've set breakpoint
6718 at file:line. There were several PC values for that file:line,
6719 due to optimization, all in one block.
6720 We've picked one PC value. If "clear" is issued with another
6721 PC corresponding to the same file:line, the breakpoint won't
6722 be cleared. We probably can still clear the breakpoint, but
6723 since the other PC value is never presented to user, user
6724 can only find it by guessing, and it does not seem important
6727 /* For each line spec given, delete bps which correspond
6728 to it. Do it in two passes, solely to preserve the current
6729 behavior that from_tty is forced true if we delete more than
6733 for (i
= 0; i
< sals
.nelts
; i
++)
6735 /* If exact pc given, clear bpts at that pc.
6736 If line given (pc == 0), clear all bpts on specified line.
6737 If defaulting, clear all bpts on default line
6740 defaulting sal.pc != 0 tests to do
6745 1 0 <can't happen> */
6749 /* Find all matching breakpoints and add them to
6754 /* Are we going to delete b? */
6755 if (b
->type
!= bp_none
6756 && b
->type
!= bp_watchpoint
6757 && b
->type
!= bp_hardware_watchpoint
6758 && b
->type
!= bp_read_watchpoint
6759 && b
->type
!= bp_access_watchpoint
)
6761 struct bp_location
*loc
= b
->loc
;
6762 for (; loc
; loc
= loc
->next
)
6764 int pc_match
= sal
.pc
6765 && (loc
->address
== sal
.pc
)
6766 && (!section_is_overlay (loc
->section
)
6767 || loc
->section
== sal
.section
);
6768 int line_match
= ((default_match
|| (0 == sal
.pc
))
6769 && b
->source_file
!= NULL
6770 && sal
.symtab
!= NULL
6771 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6772 && b
->line_number
== sal
.line
);
6773 if (pc_match
|| line_match
)
6782 VEC_safe_push(breakpoint_p
, found
, b
);
6785 /* Now go thru the 'found' chain and delete them. */
6786 if (VEC_empty(breakpoint_p
, found
))
6789 error (_("No breakpoint at %s."), arg
);
6791 error (_("No breakpoint at this line."));
6794 if (VEC_length(breakpoint_p
, found
) > 1)
6795 from_tty
= 1; /* Always report if deleted more than one */
6798 if (VEC_length(breakpoint_p
, found
) == 1)
6799 printf_unfiltered (_("Deleted breakpoint "));
6801 printf_unfiltered (_("Deleted breakpoints "));
6803 breakpoints_changed ();
6805 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6808 printf_unfiltered ("%d ", b
->number
);
6809 delete_breakpoint (b
);
6812 putchar_unfiltered ('\n');
6815 /* Delete breakpoint in BS if they are `delete' breakpoints and
6816 all breakpoints that are marked for deletion, whether hit or not.
6817 This is called after any breakpoint is hit, or after errors. */
6820 breakpoint_auto_delete (bpstat bs
)
6822 struct breakpoint
*b
, *temp
;
6824 for (; bs
; bs
= bs
->next
)
6825 if (bs
->breakpoint_at
6826 && bs
->breakpoint_at
->owner
6827 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6829 delete_breakpoint (bs
->breakpoint_at
->owner
);
6831 ALL_BREAKPOINTS_SAFE (b
, temp
)
6833 if (b
->disposition
== disp_del_at_next_stop
)
6834 delete_breakpoint (b
);
6838 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
6839 into the inferior, only remove already-inserted locations that no
6840 longer should be inserted. Functions that delete a breakpoint or
6841 breakpoints should pass false, so that deleting a breakpoint
6842 doesn't have the side effect of inserting the locations of other
6843 breakpoints that are marked not-inserted, but should_be_inserted
6844 returns true on them.
6846 This behaviour is useful is situations close to tear-down -- e.g.,
6847 after an exec, while the target still has execution, but breakpoint
6848 shadows of the previous executable image should *NOT* be restored
6849 to the new image; or before detaching, where the target still has
6850 execution and wants to delete breakpoints from GDB's lists, and all
6851 breakpoints had already been removed from the inferior. */
6854 update_global_location_list (int should_insert
)
6856 struct breakpoint
*b
;
6857 struct bp_location
**next
= &bp_location_chain
;
6858 struct bp_location
*loc
;
6859 struct bp_location
*loc2
;
6860 struct gdb_exception e
;
6861 VEC(bp_location_p
) *old_locations
= NULL
;
6865 /* Store old locations for future reference. */
6866 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6867 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6869 bp_location_chain
= NULL
;
6872 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6875 next
= &(loc
->global_next
);
6880 /* Identify bp_location instances that are no longer present in the new
6881 list, and therefore should be freed. Note that it's not necessary that
6882 those locations should be removed from inferior -- if there's another
6883 location at the same address (previously marked as duplicate),
6884 we don't need to remove/insert the location. */
6885 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6887 /* Tells if 'loc' is found amoung the new locations. If not, we
6889 int found_object
= 0;
6890 /* Tells if the location should remain inserted in the target. */
6891 int keep_in_target
= 0;
6893 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6900 /* If this location is no longer present, and inserted, look if there's
6901 maybe a new location at the same address. If so, mark that one
6902 inserted, and don't remove this one. This is needed so that we
6903 don't have a time window where a breakpoint at certain location is not
6908 /* If the location is inserted now, we might have to remove it. */
6910 if (found_object
&& should_be_inserted (loc
))
6912 /* The location is still present in the location list, and still
6913 should be inserted. Don't do anything. */
6918 /* The location is either no longer present, or got disabled.
6919 See if there's another location at the same address, in which
6920 case we don't need to remove this one from the target. */
6921 if (breakpoint_address_is_meaningful (loc
->owner
))
6922 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6924 /* For the sake of should_insert_location. The
6925 call to check_duplicates will fix up this later. */
6926 loc2
->duplicate
= 0;
6927 if (should_be_inserted (loc2
)
6928 && loc2
!= loc
&& loc2
->address
== loc
->address
)
6931 loc2
->target_info
= loc
->target_info
;
6938 if (!keep_in_target
)
6940 if (remove_breakpoint (loc
, mark_uninserted
))
6942 /* This is just about all we can do. We could keep this
6943 location on the global list, and try to remove it next
6944 time, but there's no particular reason why we will
6947 Note that at this point, loc->owner is still valid,
6948 as delete_breakpoint frees the breakpoint only
6949 after calling us. */
6950 printf_filtered (_("warning: Error removing breakpoint %d\n"),
6951 loc
->owner
->number
);
6959 if (removed
&& non_stop
)
6961 /* This location was removed from the targets. In non-stop mode,
6962 a race condition is possible where we've removed a breakpoint,
6963 but stop events for that breakpoint are already queued and will
6964 arrive later. To suppress spurious SIGTRAPs reported to user,
6965 we keep this breakpoint location for a bit, and will retire it
6966 after we see 3 * thread_count events.
6967 The theory here is that reporting of events should,
6968 "on the average", be fair, so after that many event we'll see
6969 events from all threads that have anything of interest, and no
6970 longer need to keep this breakpoint. This is just a
6971 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
6972 which is usability issue, but not a correctness problem. */
6973 loc
->events_till_retirement
= 3 * (thread_count () + 1);
6976 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
6979 free_bp_location (loc
);
6985 check_duplicates (b
);
6988 if (breakpoints_always_inserted_mode () && should_insert
6989 && (target_has_execution
6990 || (gdbarch_has_global_solist (target_gdbarch
)
6991 && target_supports_multi_process ())))
6992 insert_breakpoint_locations ();
6996 breakpoint_retire_moribund (void)
6998 struct bp_location
*loc
;
7001 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7002 if (--(loc
->events_till_retirement
) == 0)
7004 free_bp_location (loc
);
7005 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7011 update_global_location_list_nothrow (int inserting
)
7013 struct gdb_exception e
;
7014 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7015 update_global_location_list (inserting
);
7018 /* Clear BPT from a BPS. */
7020 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7023 for (bs
= bps
; bs
; bs
= bs
->next
)
7024 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7026 bs
->breakpoint_at
= NULL
;
7028 /* bs->commands will be freed later. */
7032 /* Callback for iterate_over_threads. */
7034 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7036 struct breakpoint
*bpt
= data
;
7037 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7041 /* Delete a breakpoint and clean up all traces of it in the data
7045 delete_breakpoint (struct breakpoint
*bpt
)
7047 struct breakpoint
*b
;
7048 struct bp_location
*loc
, *next
;
7050 gdb_assert (bpt
!= NULL
);
7052 /* Has this bp already been deleted? This can happen because multiple
7053 lists can hold pointers to bp's. bpstat lists are especial culprits.
7055 One example of this happening is a watchpoint's scope bp. When the
7056 scope bp triggers, we notice that the watchpoint is out of scope, and
7057 delete it. We also delete its scope bp. But the scope bp is marked
7058 "auto-deleting", and is already on a bpstat. That bpstat is then
7059 checked for auto-deleting bp's, which are deleted.
7061 A real solution to this problem might involve reference counts in bp's,
7062 and/or giving them pointers back to their referencing bpstat's, and
7063 teaching delete_breakpoint to only free a bp's storage when no more
7064 references were extent. A cheaper bandaid was chosen. */
7065 if (bpt
->type
== bp_none
)
7068 observer_notify_breakpoint_deleted (bpt
->number
);
7070 if (breakpoint_chain
== bpt
)
7071 breakpoint_chain
= bpt
->next
;
7076 b
->next
= bpt
->next
;
7080 free_command_lines (&bpt
->commands
);
7081 if (bpt
->cond_string
!= NULL
)
7082 xfree (bpt
->cond_string
);
7083 if (bpt
->addr_string
!= NULL
)
7084 xfree (bpt
->addr_string
);
7085 if (bpt
->exp
!= NULL
)
7087 if (bpt
->exp_string
!= NULL
)
7088 xfree (bpt
->exp_string
);
7089 if (bpt
->val
!= NULL
)
7090 value_free (bpt
->val
);
7091 if (bpt
->source_file
!= NULL
)
7092 xfree (bpt
->source_file
);
7093 if (bpt
->exec_pathname
!= NULL
)
7094 xfree (bpt
->exec_pathname
);
7096 /* Be sure no bpstat's are pointing at it after it's been freed. */
7097 /* FIXME, how can we find all bpstat's?
7098 We just check stop_bpstat for now. Note that we cannot just
7099 remove bpstats pointing at bpt from the stop_bpstat list
7100 entirely, as breakpoint commands are associated with the bpstat;
7101 if we remove it here, then the later call to
7102 bpstat_do_actions (&stop_bpstat);
7103 in event-top.c won't do anything, and temporary breakpoints
7104 with commands won't work. */
7106 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7108 /* Now that breakpoint is removed from breakpoint
7109 list, update the global location list. This
7110 will remove locations that used to belong to
7111 this breakpoint. Do this before freeing
7112 the breakpoint itself, since remove_breakpoint
7113 looks at location's owner. It might be better
7114 design to have location completely self-contained,
7115 but it's not the case now. */
7116 update_global_location_list (0);
7119 /* On the chance that someone will soon try again to delete this same
7120 bp, we mark it as deleted before freeing its storage. */
7121 bpt
->type
= bp_none
;
7127 do_delete_breakpoint_cleanup (void *b
)
7129 delete_breakpoint (b
);
7133 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7135 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7139 delete_command (char *arg
, int from_tty
)
7141 struct breakpoint
*b
, *temp
;
7147 int breaks_to_delete
= 0;
7149 /* Delete all breakpoints if no argument.
7150 Do not delete internal or call-dummy breakpoints, these
7151 have to be deleted with an explicit breakpoint number argument. */
7154 if (b
->type
!= bp_call_dummy
&&
7155 b
->type
!= bp_shlib_event
&&
7156 b
->type
!= bp_thread_event
&&
7157 b
->type
!= bp_overlay_event
&&
7160 breaks_to_delete
= 1;
7165 /* Ask user only if there are some breakpoints to delete. */
7167 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7169 ALL_BREAKPOINTS_SAFE (b
, temp
)
7171 if (b
->type
!= bp_call_dummy
&&
7172 b
->type
!= bp_shlib_event
&&
7173 b
->type
!= bp_thread_event
&&
7174 b
->type
!= bp_overlay_event
&&
7176 delete_breakpoint (b
);
7181 map_breakpoint_numbers (arg
, delete_breakpoint
);
7185 all_locations_are_pending (struct bp_location
*loc
)
7187 for (; loc
; loc
= loc
->next
)
7188 if (!loc
->shlib_disabled
)
7193 /* Subroutine of update_breakpoint_locations to simplify it.
7194 Return non-zero if multiple fns in list LOC have the same name.
7195 Null names are ignored. */
7198 ambiguous_names_p (struct bp_location
*loc
)
7200 struct bp_location
*l
;
7201 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7202 (int (*) (const void *, const void *)) streq
,
7203 NULL
, xcalloc
, xfree
);
7205 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7208 const char *name
= l
->function_name
;
7210 /* Allow for some names to be NULL, ignore them. */
7214 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7216 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7231 update_breakpoint_locations (struct breakpoint
*b
,
7232 struct symtabs_and_lines sals
)
7236 struct bp_location
*existing_locations
= b
->loc
;
7238 /* If there's no new locations, and all existing locations
7239 are pending, don't do anything. This optimizes
7240 the common case where all locations are in the same
7241 shared library, that was unloaded. We'd like to
7242 retain the location, so that when the library
7243 is loaded again, we don't loose the enabled/disabled
7244 status of the individual locations. */
7245 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7250 for (i
= 0; i
< sals
.nelts
; ++i
)
7252 struct bp_location
*new_loc
=
7253 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7255 /* Reparse conditions, they might contain references to the
7257 if (b
->cond_string
!= NULL
)
7259 struct gdb_exception e
;
7262 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7264 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7269 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7270 b
->number
, e
.message
);
7271 new_loc
->enabled
= 0;
7275 if (b
->source_file
!= NULL
)
7276 xfree (b
->source_file
);
7277 if (sals
.sals
[i
].symtab
== NULL
)
7278 b
->source_file
= NULL
;
7281 savestring (sals
.sals
[i
].symtab
->filename
,
7282 strlen (sals
.sals
[i
].symtab
->filename
));
7284 if (b
->line_number
== 0)
7285 b
->line_number
= sals
.sals
[i
].line
;
7288 /* Update locations of permanent breakpoints. */
7289 if (b
->enable_state
== bp_permanent
)
7290 make_breakpoint_permanent (b
);
7292 /* If possible, carry over 'disable' status from existing breakpoints. */
7294 struct bp_location
*e
= existing_locations
;
7295 /* If there are multiple breakpoints with the same function name,
7296 e.g. for inline functions, comparing function names won't work.
7297 Instead compare pc addresses; this is just a heuristic as things
7298 may have moved, but in practice it gives the correct answer
7299 often enough until a better solution is found. */
7300 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7302 for (; e
; e
= e
->next
)
7304 if (!e
->enabled
&& e
->function_name
)
7306 struct bp_location
*l
= b
->loc
;
7307 if (have_ambiguous_names
)
7309 for (; l
; l
= l
->next
)
7310 if (e
->address
== l
->address
)
7318 for (; l
; l
= l
->next
)
7319 if (l
->function_name
7320 && strcmp (e
->function_name
, l
->function_name
) == 0)
7330 update_global_location_list (1);
7334 /* Reset a breakpoint given it's struct breakpoint * BINT.
7335 The value we return ends up being the return value from catch_errors.
7336 Unused in this case. */
7339 breakpoint_re_set_one (void *bint
)
7341 /* get past catch_errs */
7342 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7346 int *not_found_ptr
= ¬_found
;
7347 struct symtabs_and_lines sals
= {};
7348 struct symtabs_and_lines expanded
;
7350 enum enable_state save_enable
;
7351 struct gdb_exception e
;
7357 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7361 case bp_hardware_breakpoint
:
7362 if (b
->addr_string
== NULL
)
7364 /* Anything without a string can't be re-set. */
7365 delete_breakpoint (b
);
7369 set_language (b
->language
);
7370 input_radix
= b
->input_radix
;
7372 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7374 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7379 int not_found_and_ok
= 0;
7380 /* For pending breakpoints, it's expected that parsing
7381 will fail until the right shared library is loaded.
7382 User has already told to create pending breakpoints and
7383 don't need extra messages. If breakpoint is in bp_shlib_disabled
7384 state, then user already saw the message about that breakpoint
7385 being disabled, and don't want to see more errors. */
7387 && (b
->condition_not_parsed
7388 || (b
->loc
&& b
->loc
->shlib_disabled
)
7389 || b
->enable_state
== bp_disabled
))
7390 not_found_and_ok
= 1;
7392 if (!not_found_and_ok
)
7394 /* We surely don't want to warn about the same breakpoint
7395 10 times. One solution, implemented here, is disable
7396 the breakpoint on error. Another solution would be to
7397 have separate 'warning emitted' flag. Since this
7398 happens only when a binary has changed, I don't know
7399 which approach is better. */
7400 b
->enable_state
= bp_disabled
;
7401 throw_exception (e
);
7408 gdb_assert (sals
.nelts
== 1);
7409 resolve_sal_pc (&sals
.sals
[0]);
7410 if (b
->condition_not_parsed
&& s
&& s
[0])
7412 char *cond_string
= 0;
7414 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7415 &cond_string
, &thread
);
7417 b
->cond_string
= cond_string
;
7419 b
->condition_not_parsed
= 0;
7421 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7422 update_breakpoint_locations (b
, expanded
);
7428 case bp_hardware_watchpoint
:
7429 case bp_read_watchpoint
:
7430 case bp_access_watchpoint
:
7431 /* Watchpoint can be either on expression using entirely global variables,
7432 or it can be on local variables.
7434 Watchpoints of the first kind are never auto-deleted, and even persist
7435 across program restarts. Since they can use variables from shared
7436 libraries, we need to reparse expression as libraries are loaded
7439 Watchpoints on local variables can also change meaning as result
7440 of solib event. For example, if a watchpoint uses both a local and
7441 a global variables in expression, it's a local watchpoint, but
7442 unloading of a shared library will make the expression invalid.
7443 This is not a very common use case, but we still re-evaluate
7444 expression, to avoid surprises to the user.
7446 Note that for local watchpoints, we re-evaluate it only if
7447 watchpoints frame id is still valid. If it's not, it means
7448 the watchpoint is out of scope and will be deleted soon. In fact,
7449 I'm not sure we'll ever be called in this case.
7451 If a local watchpoint's frame id is still valid, then
7452 b->exp_valid_block is likewise valid, and we can safely use it.
7454 Don't do anything about disabled watchpoints, since they will
7455 be reevaluated again when enabled. */
7456 update_watchpoint (b
, 1 /* reparse */);
7458 /* We needn't really do anything to reset these, since the mask
7459 that requests them is unaffected by e.g., new libraries being
7465 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7467 /* Delete overlay event breakpoints; they will be reset later by
7468 breakpoint_re_set. */
7469 case bp_overlay_event
:
7470 delete_breakpoint (b
);
7473 /* This breakpoint is special, it's set up when the inferior
7474 starts and we really don't want to touch it. */
7475 case bp_shlib_event
:
7477 /* Like bp_shlib_event, this breakpoint type is special.
7478 Once it is set up, we do not want to touch it. */
7479 case bp_thread_event
:
7481 /* Keep temporary breakpoints, which can be encountered when we step
7482 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7483 Otherwise these should have been blown away via the cleanup chain
7484 or by breakpoint_init_inferior when we rerun the executable. */
7487 case bp_watchpoint_scope
:
7489 case bp_step_resume
:
7491 case bp_longjmp_resume
:
7498 /* Re-set all breakpoints after symbols have been re-loaded. */
7500 breakpoint_re_set (void)
7502 struct breakpoint
*b
, *temp
;
7503 enum language save_language
;
7504 int save_input_radix
;
7506 save_language
= current_language
->la_language
;
7507 save_input_radix
= input_radix
;
7508 ALL_BREAKPOINTS_SAFE (b
, temp
)
7510 /* Format possible error msg */
7511 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7513 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7514 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7515 do_cleanups (cleanups
);
7517 set_language (save_language
);
7518 input_radix
= save_input_radix
;
7520 create_overlay_event_breakpoint ("_ovly_debug_event");
7523 /* Reset the thread number of this breakpoint:
7525 - If the breakpoint is for all threads, leave it as-is.
7526 - Else, reset it to the current thread for inferior_ptid. */
7528 breakpoint_re_set_thread (struct breakpoint
*b
)
7530 if (b
->thread
!= -1)
7532 if (in_thread_list (inferior_ptid
))
7533 b
->thread
= pid_to_thread_id (inferior_ptid
);
7537 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7538 If from_tty is nonzero, it prints a message to that effect,
7539 which ends with a period (no newline). */
7542 set_ignore_count (int bptnum
, int count
, int from_tty
)
7544 struct breakpoint
*b
;
7550 if (b
->number
== bptnum
)
7552 b
->ignore_count
= count
;
7556 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7558 else if (count
== 1)
7559 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7562 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7565 breakpoints_changed ();
7566 observer_notify_breakpoint_modified (b
->number
);
7570 error (_("No breakpoint number %d."), bptnum
);
7574 make_breakpoint_silent (struct breakpoint
*b
)
7576 /* Silence the breakpoint. */
7580 /* Command to set ignore-count of breakpoint N to COUNT. */
7583 ignore_command (char *args
, int from_tty
)
7589 error_no_arg (_("a breakpoint number"));
7591 num
= get_number (&p
);
7593 error (_("bad breakpoint number: '%s'"), args
);
7595 error (_("Second argument (specified ignore-count) is missing."));
7597 set_ignore_count (num
,
7598 longest_to_int (value_as_long (parse_and_eval (p
))),
7601 printf_filtered ("\n");
7604 /* Call FUNCTION on each of the breakpoints
7605 whose numbers are given in ARGS. */
7608 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7613 struct breakpoint
*b
, *tmp
;
7617 error_no_arg (_("one or more breakpoint numbers"));
7624 num
= get_number_or_range (&p1
);
7627 warning (_("bad breakpoint number at or near '%s'"), p
);
7631 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7632 if (b
->number
== num
)
7634 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7637 if (related_breakpoint
)
7638 function (related_breakpoint
);
7642 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7648 static struct bp_location
*
7649 find_location_by_number (char *number
)
7651 char *dot
= strchr (number
, '.');
7655 struct breakpoint
*b
;
7656 struct bp_location
*loc
;
7661 bp_num
= get_number_or_range (&p1
);
7663 error (_("Bad breakpoint number '%s'"), number
);
7666 if (b
->number
== bp_num
)
7671 if (!b
|| b
->number
!= bp_num
)
7672 error (_("Bad breakpoint number '%s'"), number
);
7675 loc_num
= get_number_or_range (&p1
);
7677 error (_("Bad breakpoint location number '%s'"), number
);
7681 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7684 error (_("Bad breakpoint location number '%s'"), dot
+1);
7690 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7691 If from_tty is nonzero, it prints a message to that effect,
7692 which ends with a period (no newline). */
7695 disable_breakpoint (struct breakpoint
*bpt
)
7697 /* Never disable a watchpoint scope breakpoint; we want to
7698 hit them when we leave scope so we can delete both the
7699 watchpoint and its scope breakpoint at that time. */
7700 if (bpt
->type
== bp_watchpoint_scope
)
7703 /* You can't disable permanent breakpoints. */
7704 if (bpt
->enable_state
== bp_permanent
)
7707 bpt
->enable_state
= bp_disabled
;
7709 update_global_location_list (0);
7711 observer_notify_breakpoint_modified (bpt
->number
);
7715 disable_command (char *args
, int from_tty
)
7717 struct breakpoint
*bpt
;
7719 ALL_BREAKPOINTS (bpt
)
7723 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7728 case bp_hardware_breakpoint
:
7730 case bp_hardware_watchpoint
:
7731 case bp_read_watchpoint
:
7732 case bp_access_watchpoint
:
7733 disable_breakpoint (bpt
);
7737 else if (strchr (args
, '.'))
7739 struct bp_location
*loc
= find_location_by_number (args
);
7742 update_global_location_list (0);
7745 map_breakpoint_numbers (args
, disable_breakpoint
);
7749 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7751 int target_resources_ok
, other_type_used
;
7754 if (bpt
->type
== bp_hardware_breakpoint
)
7757 i
= hw_breakpoint_used_count ();
7758 target_resources_ok
=
7759 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7761 if (target_resources_ok
== 0)
7762 error (_("No hardware breakpoint support in the target."));
7763 else if (target_resources_ok
< 0)
7764 error (_("Hardware breakpoints used exceeds limit."));
7767 if (bpt
->type
== bp_watchpoint
||
7768 bpt
->type
== bp_hardware_watchpoint
||
7769 bpt
->type
== bp_read_watchpoint
||
7770 bpt
->type
== bp_access_watchpoint
)
7772 struct frame_id saved_frame_id
;
7774 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7775 if (bpt
->exp_valid_block
!= NULL
)
7777 struct frame_info
*fr
=
7778 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7781 printf_filtered (_("\
7782 Cannot enable watchpoint %d because the block in which its expression\n\
7783 is valid is not currently in scope.\n"), bpt
->number
);
7790 value_free (bpt
->val
);
7791 mark
= value_mark ();
7792 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7794 release_value (bpt
->val
);
7797 if (bpt
->type
== bp_hardware_watchpoint
||
7798 bpt
->type
== bp_read_watchpoint
||
7799 bpt
->type
== bp_access_watchpoint
)
7801 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7802 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7804 /* Hack around 'unused var' error for some targets here */
7805 (void) mem_cnt
, (void) i
;
7806 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7807 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7808 /* we can consider of type is bp_hardware_watchpoint, convert to
7809 bp_watchpoint in the following condition */
7810 if (target_resources_ok
< 0)
7812 printf_filtered (_("\
7813 Cannot enable watchpoint %d because target watch resources\n\
7814 have been allocated for other watchpoints.\n"), bpt
->number
);
7815 value_free_to_mark (mark
);
7820 select_frame (frame_find_by_id (saved_frame_id
));
7821 value_free_to_mark (mark
);
7824 if (bpt
->enable_state
!= bp_permanent
)
7825 bpt
->enable_state
= bp_enabled
;
7826 bpt
->disposition
= disposition
;
7827 update_global_location_list (1);
7828 breakpoints_changed ();
7830 observer_notify_breakpoint_modified (bpt
->number
);
7835 enable_breakpoint (struct breakpoint
*bpt
)
7837 do_enable_breakpoint (bpt
, bpt
->disposition
);
7840 /* The enable command enables the specified breakpoints (or all defined
7841 breakpoints) so they once again become (or continue to be) effective
7842 in stopping the inferior. */
7845 enable_command (char *args
, int from_tty
)
7847 struct breakpoint
*bpt
;
7849 ALL_BREAKPOINTS (bpt
)
7853 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7858 case bp_hardware_breakpoint
:
7860 case bp_hardware_watchpoint
:
7861 case bp_read_watchpoint
:
7862 case bp_access_watchpoint
:
7863 enable_breakpoint (bpt
);
7867 else if (strchr (args
, '.'))
7869 struct bp_location
*loc
= find_location_by_number (args
);
7872 update_global_location_list (1);
7875 map_breakpoint_numbers (args
, enable_breakpoint
);
7879 enable_once_breakpoint (struct breakpoint
*bpt
)
7881 do_enable_breakpoint (bpt
, disp_disable
);
7885 enable_once_command (char *args
, int from_tty
)
7887 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7891 enable_delete_breakpoint (struct breakpoint
*bpt
)
7893 do_enable_breakpoint (bpt
, disp_del
);
7897 enable_delete_command (char *args
, int from_tty
)
7899 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7903 set_breakpoint_cmd (char *args
, int from_tty
)
7908 show_breakpoint_cmd (char *args
, int from_tty
)
7912 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7914 struct symtabs_and_lines
7915 decode_line_spec_1 (char *string
, int funfirstline
)
7917 struct symtabs_and_lines sals
;
7919 error (_("Empty line specification."));
7920 if (default_breakpoint_valid
)
7921 sals
= decode_line_1 (&string
, funfirstline
,
7922 default_breakpoint_symtab
,
7923 default_breakpoint_line
,
7924 (char ***) NULL
, NULL
);
7926 sals
= decode_line_1 (&string
, funfirstline
,
7927 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7929 error (_("Junk at end of line specification: %s"), string
);
7933 /* Create and insert a raw software breakpoint at PC. Return an
7934 identifier, which should be used to remove the breakpoint later.
7935 In general, places which call this should be using something on the
7936 breakpoint chain instead; this function should be eliminated
7940 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7942 struct bp_target_info
*bp_tgt
;
7944 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7945 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7947 bp_tgt
->placed_address
= pc
;
7948 if (target_insert_breakpoint (bp_tgt
) != 0)
7950 /* Could not insert the breakpoint. */
7958 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7961 deprecated_remove_raw_breakpoint (void *bp
)
7963 struct bp_target_info
*bp_tgt
= bp
;
7966 ret
= target_remove_breakpoint (bp_tgt
);
7972 /* One (or perhaps two) breakpoints used for software single stepping. */
7974 static void *single_step_breakpoints
[2];
7976 /* Create and insert a breakpoint for software single step. */
7979 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7983 if (single_step_breakpoints
[0] == NULL
)
7984 bpt_p
= &single_step_breakpoints
[0];
7987 gdb_assert (single_step_breakpoints
[1] == NULL
);
7988 bpt_p
= &single_step_breakpoints
[1];
7991 /* NOTE drow/2006-04-11: A future improvement to this function would be
7992 to only create the breakpoints once, and actually put them on the
7993 breakpoint chain. That would let us use set_raw_breakpoint. We could
7994 adjust the addresses each time they were needed. Doing this requires
7995 corresponding changes elsewhere where single step breakpoints are
7996 handled, however. So, for now, we use this. */
7998 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8000 error (_("Could not insert single-step breakpoint at 0x%s"),
8001 paddr_nz (next_pc
));
8004 /* Remove and delete any breakpoints used for software single step. */
8007 remove_single_step_breakpoints (void)
8009 gdb_assert (single_step_breakpoints
[0] != NULL
);
8011 /* See insert_single_step_breakpoint for more about this deprecated
8013 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8014 single_step_breakpoints
[0] = NULL
;
8016 if (single_step_breakpoints
[1] != NULL
)
8018 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8019 single_step_breakpoints
[1] = NULL
;
8023 /* Check whether a software single-step breakpoint is inserted at PC. */
8026 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8030 for (i
= 0; i
< 2; i
++)
8032 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8033 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8041 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8042 It is defined as a macro to prevent duplication.
8043 COMMAND should be a string constant containing the name of the command. */
8044 #define BREAK_ARGS_HELP(command) \
8045 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8046 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8047 If a line number is specified, break at start of code for that line.\n\
8048 If a function is specified, break at start of code for that function.\n\
8049 If an address is specified, break at that exact address.\n\
8050 With no LOCATION, uses current execution address of selected stack frame.\n\
8051 This is useful for breaking on return to a stack frame.\n\
8053 THREADNUM is the number from \"info threads\".\n\
8054 CONDITION is a boolean expression.\n\
8056 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8058 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8060 /* List of subcommands for "catch". */
8061 static struct cmd_list_element
*catch_cmdlist
;
8063 /* List of subcommands for "tcatch". */
8064 static struct cmd_list_element
*tcatch_cmdlist
;
8066 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8067 lists, and pass some additional user data to the command function. */
8069 add_catch_command (char *name
, char *docstring
,
8070 void (*sfunc
) (char *args
, int from_tty
,
8071 struct cmd_list_element
*command
),
8072 void *user_data_catch
,
8073 void *user_data_tcatch
)
8075 struct cmd_list_element
*command
;
8077 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8079 set_cmd_sfunc (command
, sfunc
);
8080 set_cmd_context (command
, user_data_catch
);
8082 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8084 set_cmd_sfunc (command
, sfunc
);
8085 set_cmd_context (command
, user_data_tcatch
);
8089 _initialize_breakpoint (void)
8091 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8092 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8093 struct cmd_list_element
*c
;
8095 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8097 breakpoint_chain
= 0;
8098 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8099 before a breakpoint is set. */
8100 breakpoint_count
= 0;
8102 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8103 Set ignore-count of breakpoint number N to COUNT.\n\
8104 Usage is `ignore N COUNT'."));
8106 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8108 add_com ("commands", class_breakpoint
, commands_command
, _("\
8109 Set commands to be executed when a breakpoint is hit.\n\
8110 Give breakpoint number as argument after \"commands\".\n\
8111 With no argument, the targeted breakpoint is the last one set.\n\
8112 The commands themselves follow starting on the next line.\n\
8113 Type a line containing \"end\" to indicate the end of them.\n\
8114 Give \"silent\" as the first line to make the breakpoint silent;\n\
8115 then no output is printed when it is hit, except what the commands print."));
8117 add_com ("condition", class_breakpoint
, condition_command
, _("\
8118 Specify breakpoint number N to break only if COND is true.\n\
8119 Usage is `condition N COND', where N is an integer and COND is an\n\
8120 expression to be evaluated whenever breakpoint N is reached."));
8122 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8123 Set a temporary breakpoint.\n\
8124 Like \"break\" except the breakpoint is only temporary,\n\
8125 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8126 by using \"enable delete\" on the breakpoint number.\n\
8128 BREAK_ARGS_HELP ("tbreak")));
8129 set_cmd_completer (c
, location_completer
);
8131 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8132 Set a hardware assisted breakpoint.\n\
8133 Like \"break\" except the breakpoint requires hardware support,\n\
8134 some target hardware may not have this support.\n\
8136 BREAK_ARGS_HELP ("hbreak")));
8137 set_cmd_completer (c
, location_completer
);
8139 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8140 Set a temporary hardware assisted breakpoint.\n\
8141 Like \"hbreak\" except the breakpoint is only temporary,\n\
8142 so it will be deleted when hit.\n\
8144 BREAK_ARGS_HELP ("thbreak")));
8145 set_cmd_completer (c
, location_completer
);
8147 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8148 Enable some breakpoints.\n\
8149 Give breakpoint numbers (separated by spaces) as arguments.\n\
8150 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8151 This is used to cancel the effect of the \"disable\" command.\n\
8152 With a subcommand you can enable temporarily."),
8153 &enablelist
, "enable ", 1, &cmdlist
);
8155 add_com ("ab", class_breakpoint
, enable_command
, _("\
8156 Enable some breakpoints.\n\
8157 Give breakpoint numbers (separated by spaces) as arguments.\n\
8158 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8159 This is used to cancel the effect of the \"disable\" command.\n\
8160 With a subcommand you can enable temporarily."));
8162 add_com_alias ("en", "enable", class_breakpoint
, 1);
8164 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8165 Enable some breakpoints.\n\
8166 Give breakpoint numbers (separated by spaces) as arguments.\n\
8167 This is used to cancel the effect of the \"disable\" command.\n\
8168 May be abbreviated to simply \"enable\".\n"),
8169 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8171 add_cmd ("once", no_class
, enable_once_command
, _("\
8172 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8173 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8176 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8177 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8178 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8181 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8182 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8183 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8186 add_cmd ("once", no_class
, enable_once_command
, _("\
8187 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8188 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8191 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8192 Disable some breakpoints.\n\
8193 Arguments are breakpoint numbers with spaces in between.\n\
8194 To disable all breakpoints, give no argument.\n\
8195 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8196 &disablelist
, "disable ", 1, &cmdlist
);
8197 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8198 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8200 add_com ("sb", class_breakpoint
, disable_command
, _("\
8201 Disable some breakpoints.\n\
8202 Arguments are breakpoint numbers with spaces in between.\n\
8203 To disable all breakpoints, give no argument.\n\
8204 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8206 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8207 Disable some breakpoints.\n\
8208 Arguments are breakpoint numbers with spaces in between.\n\
8209 To disable all breakpoints, give no argument.\n\
8210 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8211 This command may be abbreviated \"disable\"."),
8214 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8215 Delete some breakpoints or auto-display expressions.\n\
8216 Arguments are breakpoint numbers with spaces in between.\n\
8217 To delete all breakpoints, give no argument.\n\
8219 Also a prefix command for deletion of other GDB objects.\n\
8220 The \"unset\" command is also an alias for \"delete\"."),
8221 &deletelist
, "delete ", 1, &cmdlist
);
8222 add_com_alias ("d", "delete", class_breakpoint
, 1);
8223 add_com_alias ("del", "delete", class_breakpoint
, 1);
8225 add_com ("db", class_breakpoint
, delete_command
, _("\
8226 Delete some breakpoints.\n\
8227 Arguments are breakpoint numbers with spaces in between.\n\
8228 To delete all breakpoints, give no argument.\n"));
8230 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8231 Delete some breakpoints or auto-display expressions.\n\
8232 Arguments are breakpoint numbers with spaces in between.\n\
8233 To delete all breakpoints, give no argument.\n\
8234 This command may be abbreviated \"delete\"."),
8237 add_com ("clear", class_breakpoint
, clear_command
, _("\
8238 Clear breakpoint at specified line or function.\n\
8239 Argument may be line number, function name, or \"*\" and an address.\n\
8240 If line number is specified, all breakpoints in that line are cleared.\n\
8241 If function is specified, breakpoints at beginning of function are cleared.\n\
8242 If an address is specified, breakpoints at that address are cleared.\n\
8244 With no argument, clears all breakpoints in the line that the selected frame\n\
8247 See also the \"delete\" command which clears breakpoints by number."));
8249 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8250 Set breakpoint at specified line or function.\n"
8251 BREAK_ARGS_HELP ("break")));
8252 set_cmd_completer (c
, location_completer
);
8254 add_com_alias ("b", "break", class_run
, 1);
8255 add_com_alias ("br", "break", class_run
, 1);
8256 add_com_alias ("bre", "break", class_run
, 1);
8257 add_com_alias ("brea", "break", class_run
, 1);
8261 add_com_alias ("ba", "break", class_breakpoint
, 1);
8262 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8267 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8268 Break in function/address or break at a line in the current file."),
8269 &stoplist
, "stop ", 1, &cmdlist
);
8270 add_cmd ("in", class_breakpoint
, stopin_command
,
8271 _("Break in function or address."), &stoplist
);
8272 add_cmd ("at", class_breakpoint
, stopat_command
,
8273 _("Break at a line in the current file."), &stoplist
);
8274 add_com ("status", class_info
, breakpoints_info
, _("\
8275 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8276 The \"Type\" column indicates one of:\n\
8277 \tbreakpoint - normal breakpoint\n\
8278 \twatchpoint - watchpoint\n\
8279 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8280 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8281 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8282 address and file/line number respectively.\n\
8284 Convenience variable \"$_\" and default examine address for \"x\"\n\
8285 are set to the address of the last breakpoint listed unless the command\n\
8286 is prefixed with \"server \".\n\n\
8287 Convenience variable \"$bpnum\" contains the number of the last\n\
8291 add_info ("breakpoints", breakpoints_info
, _("\
8292 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8293 The \"Type\" column indicates one of:\n\
8294 \tbreakpoint - normal breakpoint\n\
8295 \twatchpoint - watchpoint\n\
8296 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8297 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8298 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8299 address and file/line number respectively.\n\
8301 Convenience variable \"$_\" and default examine address for \"x\"\n\
8302 are set to the address of the last breakpoint listed unless the command\n\
8303 is prefixed with \"server \".\n\n\
8304 Convenience variable \"$bpnum\" contains the number of the last\n\
8308 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8309 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8310 The \"Type\" column indicates one of:\n\
8311 \tbreakpoint - normal breakpoint\n\
8312 \twatchpoint - watchpoint\n\
8313 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8314 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8315 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8316 address and file/line number respectively.\n\
8318 Convenience variable \"$_\" and default examine address for \"x\"\n\
8319 are set to the address of the last breakpoint listed unless the command\n\
8320 is prefixed with \"server \".\n\n\
8321 Convenience variable \"$bpnum\" contains the number of the last\n\
8324 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8325 Status of all breakpoints, or breakpoint number NUMBER.\n\
8326 The \"Type\" column indicates one of:\n\
8327 \tbreakpoint - normal breakpoint\n\
8328 \twatchpoint - watchpoint\n\
8329 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8330 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8331 \tuntil - internal breakpoint used by the \"until\" command\n\
8332 \tfinish - internal breakpoint used by the \"finish\" command\n\
8333 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8334 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8335 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8336 address and file/line number respectively.\n\
8338 Convenience variable \"$_\" and default examine address for \"x\"\n\
8339 are set to the address of the last breakpoint listed unless the command\n\
8340 is prefixed with \"server \".\n\n\
8341 Convenience variable \"$bpnum\" contains the number of the last\n\
8343 &maintenanceinfolist
);
8345 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8346 Set catchpoints to catch events."),
8347 &catch_cmdlist
, "catch ",
8348 0/*allow-unknown*/, &cmdlist
);
8350 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8351 Set temporary catchpoints to catch events."),
8352 &tcatch_cmdlist
, "tcatch ",
8353 0/*allow-unknown*/, &cmdlist
);
8355 /* Add catch and tcatch sub-commands. */
8356 add_catch_command ("catch", _("\
8357 Catch an exception, when caught.\n\
8358 With an argument, catch only exceptions with the given name."),
8359 catch_catch_command
,
8362 add_catch_command ("throw", _("\
8363 Catch an exception, when thrown.\n\
8364 With an argument, catch only exceptions with the given name."),
8365 catch_throw_command
,
8368 add_catch_command ("fork", _("Catch calls to fork."),
8369 catch_fork_command_1
,
8370 (void *) (uintptr_t) catch_fork_permanent
,
8371 (void *) (uintptr_t) catch_fork_temporary
);
8372 add_catch_command ("vfork", _("Catch calls to vfork."),
8373 catch_fork_command_1
,
8374 (void *) (uintptr_t) catch_vfork_permanent
,
8375 (void *) (uintptr_t) catch_vfork_temporary
);
8376 add_catch_command ("exec", _("Catch calls to exec."),
8377 catch_exec_command_1
,
8380 add_catch_command ("exception", _("\
8381 Catch Ada exceptions, when raised.\n\
8382 With an argument, catch only exceptions with the given name."),
8383 catch_ada_exception_command
,
8386 add_catch_command ("assert", _("\
8387 Catch failed Ada assertions, when raised.\n\
8388 With an argument, catch only exceptions with the given name."),
8389 catch_assert_command
,
8393 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8394 Set a watchpoint for an expression.\n\
8395 A watchpoint stops execution of your program whenever the value of\n\
8396 an expression changes."));
8397 set_cmd_completer (c
, expression_completer
);
8399 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8400 Set a read watchpoint for an expression.\n\
8401 A watchpoint stops execution of your program whenever the value of\n\
8402 an expression is read."));
8403 set_cmd_completer (c
, expression_completer
);
8405 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8406 Set a watchpoint for an expression.\n\
8407 A watchpoint stops execution of your program whenever the value of\n\
8408 an expression is either read or written."));
8409 set_cmd_completer (c
, expression_completer
);
8411 add_info ("watchpoints", breakpoints_info
,
8412 _("Synonym for ``info breakpoints''."));
8415 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8416 respond to changes - contrary to the description. */
8417 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8418 &can_use_hw_watchpoints
, _("\
8419 Set debugger's willingness to use watchpoint hardware."), _("\
8420 Show debugger's willingness to use watchpoint hardware."), _("\
8421 If zero, gdb will not use hardware for new watchpoints, even if\n\
8422 such is available. (However, any hardware watchpoints that were\n\
8423 created before setting this to nonzero, will continue to use watchpoint\n\
8426 show_can_use_hw_watchpoints
,
8427 &setlist
, &showlist
);
8429 can_use_hw_watchpoints
= 1;
8431 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8432 Breakpoint specific settings\n\
8433 Configure various breakpoint-specific variables such as\n\
8434 pending breakpoint behavior"),
8435 &breakpoint_set_cmdlist
, "set breakpoint ",
8436 0/*allow-unknown*/, &setlist
);
8437 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8438 Breakpoint specific settings\n\
8439 Configure various breakpoint-specific variables such as\n\
8440 pending breakpoint behavior"),
8441 &breakpoint_show_cmdlist
, "show breakpoint ",
8442 0/*allow-unknown*/, &showlist
);
8444 add_setshow_auto_boolean_cmd ("pending", no_class
,
8445 &pending_break_support
, _("\
8446 Set debugger's behavior regarding pending breakpoints."), _("\
8447 Show debugger's behavior regarding pending breakpoints."), _("\
8448 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8449 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8450 an error. If auto, an unrecognized breakpoint location results in a\n\
8451 user-query to see if a pending breakpoint should be created."),
8453 show_pending_break_support
,
8454 &breakpoint_set_cmdlist
,
8455 &breakpoint_show_cmdlist
);
8457 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8459 add_setshow_boolean_cmd ("auto-hw", no_class
,
8460 &automatic_hardware_breakpoints
, _("\
8461 Set automatic usage of hardware breakpoints."), _("\
8462 Show automatic usage of hardware breakpoints."), _("\
8463 If set, the debugger will automatically use hardware breakpoints for\n\
8464 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8465 a warning will be emitted for such breakpoints."),
8467 show_automatic_hardware_breakpoints
,
8468 &breakpoint_set_cmdlist
,
8469 &breakpoint_show_cmdlist
);
8471 add_setshow_enum_cmd ("always-inserted", class_support
,
8472 always_inserted_enums
, &always_inserted_mode
, _("\
8473 Set mode for inserting breakpoints."), _("\
8474 Show mode for inserting breakpoints."), _("\
8475 When this mode is off, breakpoints are inserted in inferior when it is\n\
8476 resumed, and removed when execution stops. When this mode is on,\n\
8477 breakpoints are inserted immediately and removed only when the user\n\
8478 deletes the breakpoint. When this mode is auto (which is the default),\n\
8479 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8480 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8481 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8482 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8484 &show_always_inserted_mode
,
8485 &breakpoint_set_cmdlist
,
8486 &breakpoint_show_cmdlist
);
8488 automatic_hardware_breakpoints
= 1;