1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
61 #include "mi/mi-common.h"
63 /* Arguments to pass as context to some catch command handlers. */
64 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
65 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
67 /* Prototypes for local functions. */
69 static void enable_delete_command (char *, int);
71 static void enable_delete_breakpoint (struct breakpoint
*);
73 static void enable_once_command (char *, int);
75 static void enable_once_breakpoint (struct breakpoint
*);
77 static void disable_command (char *, int);
79 static void enable_command (char *, int);
81 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
83 static void ignore_command (char *, int);
85 static int breakpoint_re_set_one (void *);
87 static void clear_command (char *, int);
89 static void catch_command (char *, int);
91 static void watch_command (char *, int);
93 static int can_use_hardware_watchpoint (struct value
*);
95 static void break_command_1 (char *, int, int);
97 static void mention (struct breakpoint
*);
99 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
101 static void check_duplicates (struct breakpoint
*);
103 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
105 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
108 static void describe_other_breakpoints (CORE_ADDR
, struct obj_section
*, int);
110 static void breakpoints_info (char *, int);
112 static void breakpoint_1 (int, int);
114 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
116 static int breakpoint_cond_eval (void *);
118 static void cleanup_executing_breakpoints (void *);
120 static void commands_command (char *, int);
122 static void condition_command (char *, int);
124 static int get_number_trailer (char **, int);
126 void set_breakpoint_count (int);
135 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
137 static enum print_stop_action
print_it_typical (bpstat
);
139 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 static int watchpoint_check (void *);
143 static void maintenance_info_breakpoints (char *, int);
145 static void create_overlay_event_breakpoint (char *);
147 static int hw_breakpoint_used_count (void);
149 static int hw_watchpoint_used_count (enum bptype
, int *);
151 static void hbreak_command (char *, int);
153 static void thbreak_command (char *, int);
155 static void watch_command_1 (char *, int, int);
157 static void rwatch_command (char *, int);
159 static void awatch_command (char *, int);
161 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
163 static void stop_command (char *arg
, int from_tty
);
165 static void stopin_command (char *arg
, int from_tty
);
167 static void stopat_command (char *arg
, int from_tty
);
169 static char *ep_parse_optional_if_clause (char **arg
);
171 static char *ep_parse_optional_filename (char **arg
);
173 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
174 char *arg
, int tempflag
, int from_tty
);
176 static void tcatch_command (char *arg
, int from_tty
);
178 static void ep_skip_leading_whitespace (char **s
);
180 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
182 static void free_bp_location (struct bp_location
*loc
);
184 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
186 static void update_global_location_list (int);
188 static void update_global_location_list_nothrow (int);
190 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
192 static void insert_breakpoint_locations (void);
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 a memory 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
;
779 volatile struct gdb_exception ex
;
787 /* Evaluate the expression. */
788 mark
= value_mark ();
791 TRY_CATCH (ex
, RETURN_MASK_ALL
)
793 result
= evaluate_expression (exp
);
797 /* Ignore memory errors, we want watchpoints pointing at
798 inaccessible memory to still be created; otherwise, throw the
799 error to some higher catcher. */
805 throw_exception (ex
);
810 new_mark
= value_mark ();
811 if (mark
== new_mark
)
816 /* Make sure it's not lazy, so that after the target stops again we
817 have a non-lazy previous value to compare with. */
819 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
824 /* Return the chain of intermediate values. We use this to
825 decide which addresses to watch. */
826 *val_chain
= new_mark
;
827 value_release_to_mark (mark
);
831 /* Assuming that B is a watchpoint:
832 - Reparse watchpoint expression, if REPARSE is non-zero
833 - Evaluate expression and store the result in B->val
834 - Evaluate the condition if there is one, and store the result
836 - Update the list of values that must be watched in B->loc.
838 If the watchpoint is disabled, do nothing. If this is
839 local watchpoint that is out of scope, delete it. */
841 update_watchpoint (struct breakpoint
*b
, int reparse
)
843 int within_current_scope
;
844 struct frame_id saved_frame_id
;
845 struct bp_location
*loc
;
848 /* We don't free locations. They are stored in bp_location_chain and
849 update_global_locations will eventually delete them and remove
850 breakpoints if needed. */
853 if (b
->disposition
== disp_del_at_next_stop
)
856 /* Save the current frame's ID so we can restore it after
857 evaluating the watchpoint expression on its own frame. */
858 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
859 took a frame parameter, so that we didn't have to change the
861 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
863 /* Determine if the watchpoint is within scope. */
864 if (b
->exp_valid_block
== NULL
)
865 within_current_scope
= 1;
868 struct frame_info
*fi
;
869 fi
= frame_find_by_id (b
->watchpoint_frame
);
870 within_current_scope
= (fi
!= NULL
);
871 if (within_current_scope
)
875 if (within_current_scope
&& reparse
)
884 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
885 /* If the meaning of expression itself changed, the old value is
886 no longer relevant. We don't want to report a watchpoint hit
887 to the user when the old value and the new value may actually
888 be completely different objects. */
894 /* If we failed to parse the expression, for example because
895 it refers to a global variable in a not-yet-loaded shared library,
896 don't try to insert watchpoint. We don't automatically delete
897 such watchpoint, though, since failure to parse expression
898 is different from out-of-scope watchpoint. */
899 if (within_current_scope
&& b
->exp
)
901 struct value
*val_chain
, *v
, *result
, *next
;
903 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
905 /* Avoid setting b->val if it's already set. The meaning of
906 b->val is 'the last value' user saw, and we should update
907 it only if we reported that last value to user. As it
908 happens, the code that reports it updates b->val directly. */
915 /* Change the type of breakpoint between hardware assisted or an
916 ordinary watchpoint depending on the hardware support and free
917 hardware slots. REPARSE is set when the inferior is started. */
918 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
921 int i
, mem_cnt
, other_type_used
;
923 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
925 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
928 b
->type
= bp_watchpoint
;
931 int target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT
932 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
933 if (target_resources_ok
<= 0)
934 b
->type
= bp_watchpoint
;
936 b
->type
= bp_hardware_watchpoint
;
940 /* Look at each value on the value chain. */
941 for (v
= val_chain
; v
; v
= next
)
943 /* If it's a memory location, and GDB actually needed
944 its contents to evaluate the expression, then we
945 must watch it. If the first value returned is
946 still lazy, that means an error occurred reading it;
947 watch it anyway in case it becomes readable. */
948 if (VALUE_LVAL (v
) == lval_memory
949 && (v
== val_chain
|| ! value_lazy (v
)))
951 struct type
*vtype
= check_typedef (value_type (v
));
953 /* We only watch structs and arrays if user asked
954 for it explicitly, never if they just happen to
955 appear in the middle of some value chain. */
957 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
958 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
962 struct bp_location
*loc
, **tmp
;
964 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
965 len
= TYPE_LENGTH (value_type (v
));
967 if (b
->type
== bp_read_watchpoint
)
969 else if (b
->type
== bp_access_watchpoint
)
972 loc
= allocate_bp_location (b
);
973 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
978 loc
->watchpoint_type
= type
;
982 next
= value_next (v
);
987 /* We just regenerated the list of breakpoint locations.
988 The new location does not have its condition field set to anything
989 and therefore, we must always reparse the cond_string, independently
990 of the value of the reparse flag. */
991 if (b
->cond_string
!= NULL
)
993 char *s
= b
->cond_string
;
994 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
997 else if (!within_current_scope
)
999 printf_filtered (_("\
1000 Watchpoint %d deleted because the program has left the block \n\
1001 in which its expression is valid.\n"),
1003 if (b
->related_breakpoint
)
1004 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1005 b
->disposition
= disp_del_at_next_stop
;
1008 /* Restore the selected frame. */
1009 select_frame (frame_find_by_id (saved_frame_id
));
1013 /* Returns 1 iff breakpoint location should be
1014 inserted in the inferior. */
1016 should_be_inserted (struct bp_location
*bpt
)
1018 if (!breakpoint_enabled (bpt
->owner
))
1021 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1024 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1030 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1031 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1032 and HW_BREAKPOINT_ERROR are used to report problems.
1034 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1035 method for each breakpoint or catchpoint type. */
1037 insert_bp_location (struct bp_location
*bpt
,
1038 struct ui_file
*tmp_error_stream
,
1039 int *disabled_breaks
,
1040 int *hw_breakpoint_error
)
1044 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1047 /* Initialize the target-specific information. */
1048 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1049 bpt
->target_info
.placed_address
= bpt
->address
;
1051 if (bpt
->loc_type
== bp_loc_software_breakpoint
1052 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1054 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1056 /* If the explicitly specified breakpoint type
1057 is not hardware breakpoint, check the memory map to see
1058 if the breakpoint address is in read only memory or not.
1059 Two important cases are:
1060 - location type is not hardware breakpoint, memory
1061 is readonly. We change the type of the location to
1062 hardware breakpoint.
1063 - location type is hardware breakpoint, memory is read-write.
1064 This means we've previously made the location hardware one, but
1065 then the memory map changed, so we undo.
1067 When breakpoints are removed, remove_breakpoints will
1068 use location types we've just set here, the only possible
1069 problem is that memory map has changed during running program,
1070 but it's not going to work anyway with current gdb. */
1071 struct mem_region
*mr
1072 = lookup_mem_region (bpt
->target_info
.placed_address
);
1076 if (automatic_hardware_breakpoints
)
1079 enum bp_loc_type new_type
;
1081 if (mr
->attrib
.mode
!= MEM_RW
)
1082 new_type
= bp_loc_hardware_breakpoint
;
1084 new_type
= bp_loc_software_breakpoint
;
1086 if (new_type
!= bpt
->loc_type
)
1088 static int said
= 0;
1089 bpt
->loc_type
= new_type
;
1092 fprintf_filtered (gdb_stdout
, _("\
1093 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1098 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1099 && mr
->attrib
.mode
!= MEM_RW
)
1100 warning (_("cannot set software breakpoint at readonly address %s"),
1101 paddr (bpt
->address
));
1105 /* First check to see if we have to handle an overlay. */
1106 if (overlay_debugging
== ovly_off
1107 || bpt
->section
== NULL
1108 || !(section_is_overlay (bpt
->section
)))
1110 /* No overlay handling: just set the breakpoint. */
1112 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1113 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1115 val
= target_insert_breakpoint (&bpt
->target_info
);
1119 /* This breakpoint is in an overlay section.
1120 Shall we set a breakpoint at the LMA? */
1121 if (!overlay_events_enabled
)
1123 /* Yes -- overlay event support is not active,
1124 so we must try to set a breakpoint at the LMA.
1125 This will not work for a hardware breakpoint. */
1126 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1127 warning (_("hardware breakpoint %d not supported in overlay!"),
1128 bpt
->owner
->number
);
1131 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1133 /* Set a software (trap) breakpoint at the LMA. */
1134 bpt
->overlay_target_info
= bpt
->target_info
;
1135 bpt
->overlay_target_info
.placed_address
= addr
;
1136 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1138 fprintf_unfiltered (tmp_error_stream
,
1139 "Overlay breakpoint %d failed: in ROM?",
1140 bpt
->owner
->number
);
1143 /* Shall we set a breakpoint at the VMA? */
1144 if (section_is_mapped (bpt
->section
))
1146 /* Yes. This overlay section is mapped into memory. */
1147 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1148 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1150 val
= target_insert_breakpoint (&bpt
->target_info
);
1154 /* No. This breakpoint will not be inserted.
1155 No error, but do not mark the bp as 'inserted'. */
1162 /* Can't set the breakpoint. */
1163 if (solib_address (bpt
->address
))
1165 /* See also: disable_breakpoints_in_shlibs. */
1167 bpt
->shlib_disabled
= 1;
1168 if (!*disabled_breaks
)
1170 fprintf_unfiltered (tmp_error_stream
,
1171 "Cannot insert breakpoint %d.\n",
1172 bpt
->owner
->number
);
1173 fprintf_unfiltered (tmp_error_stream
,
1174 "Temporarily disabling shared library breakpoints:\n");
1176 *disabled_breaks
= 1;
1177 fprintf_unfiltered (tmp_error_stream
,
1178 "breakpoint #%d\n", bpt
->owner
->number
);
1182 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1184 *hw_breakpoint_error
= 1;
1185 fprintf_unfiltered (tmp_error_stream
,
1186 "Cannot insert hardware breakpoint %d.\n",
1187 bpt
->owner
->number
);
1191 fprintf_unfiltered (tmp_error_stream
,
1192 "Cannot insert breakpoint %d.\n",
1193 bpt
->owner
->number
);
1194 fprintf_filtered (tmp_error_stream
,
1195 "Error accessing memory address ");
1196 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1197 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1198 safe_strerror (val
));
1209 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1210 /* NOTE drow/2003-09-08: This state only exists for removing
1211 watchpoints. It's not clear that it's necessary... */
1212 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1214 val
= target_insert_watchpoint (bpt
->address
,
1216 bpt
->watchpoint_type
);
1217 bpt
->inserted
= (val
!= -1);
1220 else if (bpt
->owner
->type
== bp_catchpoint
)
1222 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1223 bpt
->owner
, RETURN_MASK_ERROR
);
1224 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1225 bpt
->owner
->number
);
1227 bpt
->owner
->enable_state
= bp_disabled
;
1231 /* We've already printed an error message if there was a problem
1232 inserting this catchpoint, and we've disabled the catchpoint,
1233 so just return success. */
1240 /* Make sure all breakpoints are inserted in inferior.
1241 Throws exception on any error.
1242 A breakpoint that is already inserted won't be inserted
1243 again, so calling this function twice is safe. */
1245 insert_breakpoints (void)
1247 struct breakpoint
*bpt
;
1249 ALL_BREAKPOINTS (bpt
)
1250 if (is_hardware_watchpoint (bpt
))
1251 update_watchpoint (bpt
, 0 /* don't reparse. */);
1253 update_global_location_list (1);
1255 if (!breakpoints_always_inserted_mode ()
1256 && (target_has_execution
1257 || (gdbarch_has_global_solist (target_gdbarch
)
1258 && target_supports_multi_process ())))
1259 /* update_global_location_list does not insert breakpoints
1260 when always_inserted_mode is not enabled. Explicitly
1262 insert_breakpoint_locations ();
1265 /* insert_breakpoints is used when starting or continuing the program.
1266 remove_breakpoints is used when the program stops.
1267 Both return zero if successful,
1268 or an `errno' value if could not write the inferior. */
1271 insert_breakpoint_locations (void)
1273 struct breakpoint
*bpt
;
1274 struct bp_location
*b
, *temp
;
1277 int disabled_breaks
= 0;
1278 int hw_breakpoint_error
= 0;
1280 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1281 make_cleanup_ui_file_delete (tmp_error_stream
);
1283 /* Explicitly mark the warning -- this will only be printed if
1284 there was an error. */
1285 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1287 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1289 if (!should_be_inserted (b
) || b
->inserted
)
1292 /* There is no point inserting thread-specific breakpoints if the
1293 thread no longer exists. */
1294 if (b
->owner
->thread
!= -1
1295 && !valid_thread_id (b
->owner
->thread
))
1298 val
= insert_bp_location (b
, tmp_error_stream
,
1300 &hw_breakpoint_error
);
1305 /* If we failed to insert all locations of a watchpoint,
1306 remove them, as half-inserted watchpoint is of limited use. */
1307 ALL_BREAKPOINTS (bpt
)
1309 int some_failed
= 0;
1310 struct bp_location
*loc
;
1312 if (!is_hardware_watchpoint (bpt
))
1315 if (!breakpoint_enabled (bpt
))
1318 if (bpt
->disposition
== disp_del_at_next_stop
)
1321 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1329 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1331 remove_breakpoint (loc
, mark_uninserted
);
1333 hw_breakpoint_error
= 1;
1334 fprintf_unfiltered (tmp_error_stream
,
1335 "Could not insert hardware watchpoint %d.\n",
1343 /* If a hardware breakpoint or watchpoint was inserted, add a
1344 message about possibly exhausted resources. */
1345 if (hw_breakpoint_error
)
1347 fprintf_unfiltered (tmp_error_stream
,
1348 "Could not insert hardware breakpoints:\n\
1349 You may have requested too many hardware breakpoints/watchpoints.\n");
1351 target_terminal_ours_for_output ();
1352 error_stream (tmp_error_stream
);
1357 remove_breakpoints (void)
1359 struct bp_location
*b
;
1362 ALL_BP_LOCATIONS (b
)
1366 val
= remove_breakpoint (b
, mark_uninserted
);
1375 remove_hw_watchpoints (void)
1377 struct bp_location
*b
;
1380 ALL_BP_LOCATIONS (b
)
1382 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1384 val
= remove_breakpoint (b
, mark_uninserted
);
1393 reattach_breakpoints (int pid
)
1395 struct bp_location
*b
;
1397 struct cleanup
*old_chain
= save_inferior_ptid ();
1398 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1399 int dummy1
= 0, dummy2
= 0;
1401 make_cleanup_ui_file_delete (tmp_error_stream
);
1403 inferior_ptid
= pid_to_ptid (pid
);
1404 ALL_BP_LOCATIONS (b
)
1409 val
= insert_bp_location (b
, tmp_error_stream
,
1413 do_cleanups (old_chain
);
1418 do_cleanups (old_chain
);
1423 update_breakpoints_after_exec (void)
1425 struct breakpoint
*b
;
1426 struct breakpoint
*temp
;
1427 struct bp_location
*bploc
;
1429 /* We're about to delete breakpoints from GDB's lists. If the
1430 INSERTED flag is true, GDB will try to lift the breakpoints by
1431 writing the breakpoints' "shadow contents" back into memory. The
1432 "shadow contents" are NOT valid after an exec, so GDB should not
1433 do that. Instead, the target is responsible from marking
1434 breakpoints out as soon as it detects an exec. We don't do that
1435 here instead, because there may be other attempts to delete
1436 breakpoints after detecting an exec and before reaching here. */
1437 ALL_BP_LOCATIONS (bploc
)
1438 gdb_assert (!bploc
->inserted
);
1440 ALL_BREAKPOINTS_SAFE (b
, temp
)
1442 /* Solib breakpoints must be explicitly reset after an exec(). */
1443 if (b
->type
== bp_shlib_event
)
1445 delete_breakpoint (b
);
1449 /* Thread event breakpoints must be set anew after an exec(),
1450 as must overlay event breakpoints. */
1451 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1453 delete_breakpoint (b
);
1457 /* Step-resume breakpoints are meaningless after an exec(). */
1458 if (b
->type
== bp_step_resume
)
1460 delete_breakpoint (b
);
1464 /* Longjmp and longjmp-resume breakpoints are also meaningless
1466 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1468 delete_breakpoint (b
);
1472 if (b
->type
== bp_catchpoint
)
1474 /* For now, none of the bp_catchpoint breakpoints need to
1475 do anything at this point. In the future, if some of
1476 the catchpoints need to something, we will need to add
1477 a new method, and call this method from here. */
1481 /* bp_finish is a special case. The only way we ought to be able
1482 to see one of these when an exec() has happened, is if the user
1483 caught a vfork, and then said "finish". Ordinarily a finish just
1484 carries them to the call-site of the current callee, by setting
1485 a temporary bp there and resuming. But in this case, the finish
1486 will carry them entirely through the vfork & exec.
1488 We don't want to allow a bp_finish to remain inserted now. But
1489 we can't safely delete it, 'cause finish_command has a handle to
1490 the bp on a bpstat, and will later want to delete it. There's a
1491 chance (and I've seen it happen) that if we delete the bp_finish
1492 here, that its storage will get reused by the time finish_command
1493 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1494 We really must allow finish_command to delete a bp_finish.
1496 In the absense of a general solution for the "how do we know
1497 it's safe to delete something others may have handles to?"
1498 problem, what we'll do here is just uninsert the bp_finish, and
1499 let finish_command delete it.
1501 (We know the bp_finish is "doomed" in the sense that it's
1502 momentary, and will be deleted as soon as finish_command sees
1503 the inferior stopped. So it doesn't matter that the bp's
1504 address is probably bogus in the new a.out, unlike e.g., the
1505 solib breakpoints.) */
1507 if (b
->type
== bp_finish
)
1512 /* Without a symbolic address, we have little hope of the
1513 pre-exec() address meaning the same thing in the post-exec()
1515 if (b
->addr_string
== NULL
)
1517 delete_breakpoint (b
);
1521 /* FIXME what about longjmp breakpoints? Re-create them here? */
1522 create_overlay_event_breakpoint ("_ovly_debug_event");
1526 detach_breakpoints (int pid
)
1528 struct bp_location
*b
;
1530 struct cleanup
*old_chain
= save_inferior_ptid ();
1532 if (pid
== PIDGET (inferior_ptid
))
1533 error (_("Cannot detach breakpoints of inferior_ptid"));
1535 /* Set inferior_ptid; remove_breakpoint uses this global. */
1536 inferior_ptid
= pid_to_ptid (pid
);
1537 ALL_BP_LOCATIONS (b
)
1541 val
= remove_breakpoint (b
, mark_inserted
);
1544 do_cleanups (old_chain
);
1549 do_cleanups (old_chain
);
1554 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1558 if (b
->owner
->enable_state
== bp_permanent
)
1559 /* Permanent breakpoints cannot be inserted or removed. */
1562 /* The type of none suggests that owner is actually deleted.
1563 This should not ever happen. */
1564 gdb_assert (b
->owner
->type
!= bp_none
);
1566 if (b
->loc_type
== bp_loc_software_breakpoint
1567 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1569 /* "Normal" instruction breakpoint: either the standard
1570 trap-instruction bp (bp_breakpoint), or a
1571 bp_hardware_breakpoint. */
1573 /* First check to see if we have to handle an overlay. */
1574 if (overlay_debugging
== ovly_off
1575 || b
->section
== NULL
1576 || !(section_is_overlay (b
->section
)))
1578 /* No overlay handling: just remove the breakpoint. */
1580 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1581 val
= target_remove_hw_breakpoint (&b
->target_info
);
1583 val
= target_remove_breakpoint (&b
->target_info
);
1587 /* This breakpoint is in an overlay section.
1588 Did we set a breakpoint at the LMA? */
1589 if (!overlay_events_enabled
)
1591 /* Yes -- overlay event support is not active, so we
1592 should have set a breakpoint at the LMA. Remove it.
1594 /* Ignore any failures: if the LMA is in ROM, we will
1595 have already warned when we failed to insert it. */
1596 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1597 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1599 target_remove_breakpoint (&b
->overlay_target_info
);
1601 /* Did we set a breakpoint at the VMA?
1602 If so, we will have marked the breakpoint 'inserted'. */
1605 /* Yes -- remove it. Previously we did not bother to
1606 remove the breakpoint if the section had been
1607 unmapped, but let's not rely on that being safe. We
1608 don't know what the overlay manager might do. */
1609 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1610 val
= target_remove_hw_breakpoint (&b
->target_info
);
1612 /* However, we should remove *software* breakpoints only
1613 if the section is still mapped, or else we overwrite
1614 wrong code with the saved shadow contents. */
1615 else if (section_is_mapped (b
->section
))
1616 val
= target_remove_breakpoint (&b
->target_info
);
1622 /* No -- not inserted, so no need to remove. No error. */
1627 /* In some cases, we might not be able to remove a breakpoint
1628 in a shared library that has already been removed, but we
1629 have not yet processed the shlib unload event. */
1630 if (val
&& solib_address (b
->address
))
1635 b
->inserted
= (is
== mark_inserted
);
1637 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1642 b
->inserted
= (is
== mark_inserted
);
1643 val
= target_remove_watchpoint (b
->address
, b
->length
,
1644 b
->watchpoint_type
);
1646 /* Failure to remove any of the hardware watchpoints comes here. */
1647 if ((is
== mark_uninserted
) && (b
->inserted
))
1648 warning (_("Could not remove hardware watchpoint %d."),
1651 else if (b
->owner
->type
== bp_catchpoint
1652 && breakpoint_enabled (b
->owner
)
1655 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1657 val
= b
->owner
->ops
->remove (b
->owner
);
1660 b
->inserted
= (is
== mark_inserted
);
1666 /* Clear the "inserted" flag in all breakpoints. */
1669 mark_breakpoints_out (void)
1671 struct bp_location
*bpt
;
1673 ALL_BP_LOCATIONS (bpt
)
1677 /* Clear the "inserted" flag in all breakpoints and delete any
1678 breakpoints which should go away between runs of the program.
1680 Plus other such housekeeping that has to be done for breakpoints
1683 Note: this function gets called at the end of a run (by
1684 generic_mourn_inferior) and when a run begins (by
1685 init_wait_for_inferior). */
1690 breakpoint_init_inferior (enum inf_context context
)
1692 struct breakpoint
*b
, *temp
;
1693 struct bp_location
*bpt
;
1696 /* If breakpoint locations are shared across processes, then there's
1698 if (gdbarch_has_global_solist (target_gdbarch
))
1701 ALL_BP_LOCATIONS (bpt
)
1702 if (bpt
->owner
->enable_state
!= bp_permanent
)
1705 ALL_BREAKPOINTS_SAFE (b
, temp
)
1710 case bp_watchpoint_scope
:
1712 /* If the call dummy breakpoint is at the entry point it will
1713 cause problems when the inferior is rerun, so we better
1716 Also get rid of scope breakpoints. */
1717 delete_breakpoint (b
);
1721 case bp_hardware_watchpoint
:
1722 case bp_read_watchpoint
:
1723 case bp_access_watchpoint
:
1725 /* Likewise for watchpoints on local expressions. */
1726 if (b
->exp_valid_block
!= NULL
)
1727 delete_breakpoint (b
);
1728 else if (context
== inf_starting
)
1730 /* Reset val field to force reread of starting value
1731 in insert_breakpoints. */
1733 value_free (b
->val
);
1743 /* Get rid of the moribund locations. */
1744 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1745 free_bp_location (bpt
);
1746 VEC_free (bp_location_p
, moribund_locations
);
1749 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1750 exists at PC. It returns ordinary_breakpoint_here if it's an
1751 ordinary breakpoint, or permanent_breakpoint_here if it's a
1752 permanent breakpoint.
1753 - When continuing from a location with an ordinary breakpoint, we
1754 actually single step once before calling insert_breakpoints.
1755 - When continuing from a localion with a permanent breakpoint, we
1756 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1757 the target, to advance the PC past the breakpoint. */
1759 enum breakpoint_here
1760 breakpoint_here_p (CORE_ADDR pc
)
1762 const struct bp_location
*bpt
;
1763 int any_breakpoint_here
= 0;
1765 ALL_BP_LOCATIONS (bpt
)
1767 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1768 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1771 if ((breakpoint_enabled (bpt
->owner
)
1772 || bpt
->owner
->enable_state
== bp_permanent
)
1773 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1775 if (overlay_debugging
1776 && section_is_overlay (bpt
->section
)
1777 && !section_is_mapped (bpt
->section
))
1778 continue; /* unmapped overlay -- can't be a match */
1779 else if (bpt
->owner
->enable_state
== bp_permanent
)
1780 return permanent_breakpoint_here
;
1782 any_breakpoint_here
= 1;
1786 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1789 /* Return true if there's a moribund breakpoint at PC. */
1792 moribund_breakpoint_here_p (CORE_ADDR pc
)
1794 struct bp_location
*loc
;
1797 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1798 if (loc
->address
== pc
)
1804 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1805 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1806 This does not check for single-step breakpoints, which are
1807 inserted and removed using direct target manipulation. */
1810 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1812 const struct bp_location
*bpt
;
1814 ALL_BP_LOCATIONS (bpt
)
1816 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1817 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1821 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1823 if (overlay_debugging
1824 && section_is_overlay (bpt
->section
)
1825 && !section_is_mapped (bpt
->section
))
1826 continue; /* unmapped overlay -- can't be a match */
1834 /* Returns non-zero iff there's either regular breakpoint
1835 or a single step breakpoint inserted at PC. */
1838 breakpoint_inserted_here_p (CORE_ADDR pc
)
1840 if (regular_breakpoint_inserted_here_p (pc
))
1843 if (single_step_breakpoint_inserted_here_p (pc
))
1849 /* This function returns non-zero iff there is a software breakpoint
1853 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1855 const struct bp_location
*bpt
;
1856 int any_breakpoint_here
= 0;
1858 ALL_BP_LOCATIONS (bpt
)
1860 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1864 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1866 if (overlay_debugging
1867 && section_is_overlay (bpt
->section
)
1868 && !section_is_mapped (bpt
->section
))
1869 continue; /* unmapped overlay -- can't be a match */
1875 /* Also check for software single-step breakpoints. */
1876 if (single_step_breakpoint_inserted_here_p (pc
))
1882 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1883 PC is valid for process/thread PTID. */
1886 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1888 const struct bp_location
*bpt
;
1891 thread
= pid_to_thread_id (ptid
);
1893 ALL_BP_LOCATIONS (bpt
)
1895 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1896 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1899 if ((breakpoint_enabled (bpt
->owner
)
1900 || bpt
->owner
->enable_state
== bp_permanent
)
1901 && bpt
->address
== pc
1902 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1904 if (overlay_debugging
1905 && section_is_overlay (bpt
->section
)
1906 && !section_is_mapped (bpt
->section
))
1907 continue; /* unmapped overlay -- can't be a match */
1917 /* bpstat stuff. External routines' interfaces are documented
1921 ep_is_catchpoint (struct breakpoint
*ep
)
1923 return (ep
->type
== bp_catchpoint
);
1927 bpstat_free (bpstat bs
)
1929 if (bs
->old_val
!= NULL
)
1930 value_free (bs
->old_val
);
1931 free_command_lines (&bs
->commands
);
1935 /* Clear a bpstat so that it says we are not at any breakpoint.
1936 Also free any storage that is part of a bpstat. */
1939 bpstat_clear (bpstat
*bsp
)
1956 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1957 is part of the bpstat is copied as well. */
1960 bpstat_copy (bpstat bs
)
1964 bpstat retval
= NULL
;
1969 for (; bs
!= NULL
; bs
= bs
->next
)
1971 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1972 memcpy (tmp
, bs
, sizeof (*tmp
));
1973 if (bs
->commands
!= NULL
)
1974 tmp
->commands
= copy_command_lines (bs
->commands
);
1975 if (bs
->old_val
!= NULL
)
1977 tmp
->old_val
= value_copy (bs
->old_val
);
1978 release_value (tmp
->old_val
);
1982 /* This is the first thing in the chain. */
1992 /* Find the bpstat associated with this breakpoint */
1995 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2000 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2002 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2008 /* Find a step_resume breakpoint associated with this bpstat.
2009 (If there are multiple step_resume bp's on the list, this function
2010 will arbitrarily pick one.)
2012 It is an error to use this function if BPSTAT doesn't contain a
2013 step_resume breakpoint.
2015 See wait_for_inferior's use of this function. */
2017 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2021 gdb_assert (bsp
!= NULL
);
2023 current_thread
= pid_to_thread_id (inferior_ptid
);
2025 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2027 if ((bsp
->breakpoint_at
!= NULL
) &&
2028 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2029 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2030 bsp
->breakpoint_at
->owner
->thread
== -1))
2031 return bsp
->breakpoint_at
->owner
;
2034 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2038 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2039 at. *BSP upon return is a bpstat which points to the remaining
2040 breakpoints stopped at (but which is not guaranteed to be good for
2041 anything but further calls to bpstat_num).
2042 Return 0 if passed a bpstat which does not indicate any breakpoints.
2043 Return -1 if stopped at a breakpoint that has been deleted since
2045 Return 1 otherwise. */
2048 bpstat_num (bpstat
*bsp
, int *num
)
2050 struct breakpoint
*b
;
2053 return 0; /* No more breakpoint values */
2055 /* We assume we'll never have several bpstats that
2056 correspond to a single breakpoint -- otherwise,
2057 this function might return the same number more
2058 than once and this will look ugly. */
2059 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2060 *bsp
= (*bsp
)->next
;
2062 return -1; /* breakpoint that's been deleted since */
2064 *num
= b
->number
; /* We have its number */
2068 /* Modify BS so that the actions will not be performed. */
2071 bpstat_clear_actions (bpstat bs
)
2073 for (; bs
!= NULL
; bs
= bs
->next
)
2075 free_command_lines (&bs
->commands
);
2076 if (bs
->old_val
!= NULL
)
2078 value_free (bs
->old_val
);
2084 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2086 cleanup_executing_breakpoints (void *ignore
)
2088 executing_breakpoint_commands
= 0;
2091 /* Execute all the commands associated with all the breakpoints at this
2092 location. Any of these commands could cause the process to proceed
2093 beyond this point, etc. We look out for such changes by checking
2094 the global "breakpoint_proceeded" after each command.
2096 Returns true if a breakpoint command resumed the inferior. In that
2097 case, it is the caller's responsibility to recall it again with the
2098 bpstat of the current thread. */
2101 bpstat_do_actions_1 (bpstat
*bsp
)
2104 struct cleanup
*old_chain
;
2107 /* Avoid endless recursion if a `source' command is contained
2109 if (executing_breakpoint_commands
)
2112 executing_breakpoint_commands
= 1;
2113 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2115 /* This pointer will iterate over the list of bpstat's. */
2118 breakpoint_proceeded
= 0;
2119 for (; bs
!= NULL
; bs
= bs
->next
)
2121 struct command_line
*cmd
;
2122 struct cleanup
*this_cmd_tree_chain
;
2124 /* Take ownership of the BSP's command tree, if it has one.
2126 The command tree could legitimately contain commands like
2127 'step' and 'next', which call clear_proceed_status, which
2128 frees stop_bpstat's command tree. To make sure this doesn't
2129 free the tree we're executing out from under us, we need to
2130 take ownership of the tree ourselves. Since a given bpstat's
2131 commands are only executed once, we don't need to copy it; we
2132 can clear the pointer in the bpstat, and make sure we free
2133 the tree when we're done. */
2136 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2140 execute_control_command (cmd
);
2142 if (breakpoint_proceeded
)
2148 /* We can free this command tree now. */
2149 do_cleanups (this_cmd_tree_chain
);
2151 if (breakpoint_proceeded
)
2153 if (target_can_async_p ())
2154 /* If we are in async mode, then the target might be still
2155 running, not stopped at any breakpoint, so nothing for
2156 us to do here -- just return to the event loop. */
2159 /* In sync mode, when execute_control_command returns
2160 we're already standing on the next breakpoint.
2161 Breakpoint commands for that stop were not run, since
2162 execute_command does not run breakpoint commands --
2163 only command_line_handler does, but that one is not
2164 involved in execution of breakpoint commands. So, we
2165 can now execute breakpoint commands. It should be
2166 noted that making execute_command do bpstat actions is
2167 not an option -- in this case we'll have recursive
2168 invocation of bpstat for each breakpoint with a
2169 command, and can easily blow up GDB stack. Instead, we
2170 return true, which will trigger the caller to recall us
2171 with the new stop_bpstat. */
2176 do_cleanups (old_chain
);
2181 bpstat_do_actions (void)
2183 /* Do any commands attached to breakpoint we are stopped at. */
2184 while (!ptid_equal (inferior_ptid
, null_ptid
)
2185 && target_has_execution
2186 && !is_exited (inferior_ptid
)
2187 && !is_executing (inferior_ptid
))
2188 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2189 and only return when it is stopped at the next breakpoint, we
2190 keep doing breakpoint actions until it returns false to
2191 indicate the inferior was not resumed. */
2192 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2196 /* Print out the (old or new) value associated with a watchpoint. */
2199 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2202 fprintf_unfiltered (stream
, _("<unreadable>"));
2205 struct value_print_options opts
;
2206 get_user_print_options (&opts
);
2207 value_print (val
, stream
, &opts
);
2211 /* This is the normal print function for a bpstat. In the future,
2212 much of this logic could (should?) be moved to bpstat_stop_status,
2213 by having it set different print_it values.
2215 Current scheme: When we stop, bpstat_print() is called. It loops
2216 through the bpstat list of things causing this stop, calling the
2217 print_bp_stop_message function on each one. The behavior of the
2218 print_bp_stop_message function depends on the print_it field of
2219 bpstat. If such field so indicates, call this function here.
2221 Return values from this routine (ultimately used by bpstat_print()
2222 and normal_stop() to decide what to do):
2223 PRINT_NOTHING: Means we already printed all we needed to print,
2224 don't print anything else.
2225 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2226 that something to be followed by a location.
2227 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2228 that something to be followed by a location.
2229 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2232 static enum print_stop_action
2233 print_it_typical (bpstat bs
)
2235 struct cleanup
*old_chain
, *ui_out_chain
;
2236 struct breakpoint
*b
;
2237 const struct bp_location
*bl
;
2238 struct ui_stream
*stb
;
2240 stb
= ui_out_stream_new (uiout
);
2241 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2242 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2243 which has since been deleted. */
2244 if (bs
->breakpoint_at
== NULL
)
2245 return PRINT_UNKNOWN
;
2246 bl
= bs
->breakpoint_at
;
2252 case bp_hardware_breakpoint
:
2253 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2254 if (bl
->address
!= bl
->requested_address
)
2255 breakpoint_adjustment_warning (bl
->requested_address
,
2258 annotate_breakpoint (b
->number
);
2260 ui_out_text (uiout
, "\nTemporary breakpoint ");
2262 ui_out_text (uiout
, "\nBreakpoint ");
2263 if (ui_out_is_mi_like_p (uiout
))
2265 ui_out_field_string (uiout
, "reason",
2266 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2267 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2269 ui_out_field_int (uiout
, "bkptno", b
->number
);
2270 ui_out_text (uiout
, ", ");
2271 return PRINT_SRC_AND_LOC
;
2274 case bp_shlib_event
:
2275 /* Did we stop because the user set the stop_on_solib_events
2276 variable? (If so, we report this as a generic, "Stopped due
2277 to shlib event" message.) */
2278 printf_filtered (_("Stopped due to shared library event\n"));
2279 return PRINT_NOTHING
;
2282 case bp_thread_event
:
2283 /* Not sure how we will get here.
2284 GDB should not stop for these breakpoints. */
2285 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2286 return PRINT_NOTHING
;
2289 case bp_overlay_event
:
2290 /* By analogy with the thread event, GDB should not stop for these. */
2291 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2292 return PRINT_NOTHING
;
2296 case bp_hardware_watchpoint
:
2297 annotate_watchpoint (b
->number
);
2298 if (ui_out_is_mi_like_p (uiout
))
2301 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2303 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2304 ui_out_text (uiout
, "\nOld value = ");
2305 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2306 ui_out_field_stream (uiout
, "old", stb
);
2307 ui_out_text (uiout
, "\nNew value = ");
2308 watchpoint_value_print (b
->val
, stb
->stream
);
2309 ui_out_field_stream (uiout
, "new", stb
);
2310 do_cleanups (ui_out_chain
);
2311 ui_out_text (uiout
, "\n");
2312 /* More than one watchpoint may have been triggered. */
2313 return PRINT_UNKNOWN
;
2316 case bp_read_watchpoint
:
2317 if (ui_out_is_mi_like_p (uiout
))
2320 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2322 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2323 ui_out_text (uiout
, "\nValue = ");
2324 watchpoint_value_print (b
->val
, stb
->stream
);
2325 ui_out_field_stream (uiout
, "value", stb
);
2326 do_cleanups (ui_out_chain
);
2327 ui_out_text (uiout
, "\n");
2328 return PRINT_UNKNOWN
;
2331 case bp_access_watchpoint
:
2332 if (bs
->old_val
!= NULL
)
2334 annotate_watchpoint (b
->number
);
2335 if (ui_out_is_mi_like_p (uiout
))
2338 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2340 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2341 ui_out_text (uiout
, "\nOld value = ");
2342 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2343 ui_out_field_stream (uiout
, "old", stb
);
2344 ui_out_text (uiout
, "\nNew value = ");
2349 if (ui_out_is_mi_like_p (uiout
))
2352 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2353 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2354 ui_out_text (uiout
, "\nValue = ");
2356 watchpoint_value_print (b
->val
, stb
->stream
);
2357 ui_out_field_stream (uiout
, "new", stb
);
2358 do_cleanups (ui_out_chain
);
2359 ui_out_text (uiout
, "\n");
2360 return PRINT_UNKNOWN
;
2363 /* Fall through, we don't deal with these types of breakpoints
2367 if (ui_out_is_mi_like_p (uiout
))
2370 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2371 return PRINT_UNKNOWN
;
2375 if (ui_out_is_mi_like_p (uiout
))
2378 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2379 return PRINT_UNKNOWN
;
2384 case bp_longjmp_resume
:
2385 case bp_step_resume
:
2386 case bp_watchpoint_scope
:
2389 return PRINT_UNKNOWN
;
2393 /* Generic routine for printing messages indicating why we
2394 stopped. The behavior of this function depends on the value
2395 'print_it' in the bpstat structure. Under some circumstances we
2396 may decide not to print anything here and delegate the task to
2399 static enum print_stop_action
2400 print_bp_stop_message (bpstat bs
)
2402 switch (bs
->print_it
)
2405 /* Nothing should be printed for this bpstat entry. */
2406 return PRINT_UNKNOWN
;
2410 /* We still want to print the frame, but we already printed the
2411 relevant messages. */
2412 return PRINT_SRC_AND_LOC
;
2415 case print_it_normal
:
2417 const struct bp_location
*bl
= bs
->breakpoint_at
;
2418 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2420 /* Normal case. Call the breakpoint's print_it method, or
2421 print_it_typical. */
2422 /* FIXME: how breakpoint can ever be NULL here? */
2423 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2424 return b
->ops
->print_it (b
);
2426 return print_it_typical (bs
);
2431 internal_error (__FILE__
, __LINE__
,
2432 _("print_bp_stop_message: unrecognized enum value"));
2437 /* Print a message indicating what happened. This is called from
2438 normal_stop(). The input to this routine is the head of the bpstat
2439 list - a list of the eventpoints that caused this stop. This
2440 routine calls the generic print routine for printing a message
2441 about reasons for stopping. This will print (for example) the
2442 "Breakpoint n," part of the output. The return value of this
2445 PRINT_UNKNOWN: Means we printed nothing
2446 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2447 code to print the location. An example is
2448 "Breakpoint 1, " which should be followed by
2450 PRINT_SRC_ONLY: Means we printed something, but there is no need
2451 to also print the location part of the message.
2452 An example is the catch/throw messages, which
2453 don't require a location appended to the end.
2454 PRINT_NOTHING: We have done some printing and we don't need any
2455 further info to be printed.*/
2457 enum print_stop_action
2458 bpstat_print (bpstat bs
)
2462 /* Maybe another breakpoint in the chain caused us to stop.
2463 (Currently all watchpoints go on the bpstat whether hit or not.
2464 That probably could (should) be changed, provided care is taken
2465 with respect to bpstat_explains_signal). */
2466 for (; bs
; bs
= bs
->next
)
2468 val
= print_bp_stop_message (bs
);
2469 if (val
== PRINT_SRC_ONLY
2470 || val
== PRINT_SRC_AND_LOC
2471 || val
== PRINT_NOTHING
)
2475 /* We reached the end of the chain, or we got a null BS to start
2476 with and nothing was printed. */
2477 return PRINT_UNKNOWN
;
2480 /* Evaluate the expression EXP and return 1 if value is zero.
2481 This is used inside a catch_errors to evaluate the breakpoint condition.
2482 The argument is a "struct expression *" that has been cast to char * to
2483 make it pass through catch_errors. */
2486 breakpoint_cond_eval (void *exp
)
2488 struct value
*mark
= value_mark ();
2489 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2490 value_free_to_mark (mark
);
2494 /* Allocate a new bpstat and chain it to the current one. */
2497 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2501 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2503 bs
->breakpoint_at
= bl
;
2504 /* If the condition is false, etc., don't do the commands. */
2505 bs
->commands
= NULL
;
2507 bs
->print_it
= print_it_normal
;
2511 /* The target has stopped with waitstatus WS. Check if any hardware
2512 watchpoints have triggered, according to the target. */
2515 watchpoints_triggered (struct target_waitstatus
*ws
)
2517 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2519 struct breakpoint
*b
;
2521 if (!stopped_by_watchpoint
)
2523 /* We were not stopped by a watchpoint. Mark all watchpoints
2524 as not triggered. */
2526 if (b
->type
== bp_hardware_watchpoint
2527 || b
->type
== bp_read_watchpoint
2528 || b
->type
== bp_access_watchpoint
)
2529 b
->watchpoint_triggered
= watch_triggered_no
;
2534 if (!target_stopped_data_address (¤t_target
, &addr
))
2536 /* We were stopped by a watchpoint, but we don't know where.
2537 Mark all watchpoints as unknown. */
2539 if (b
->type
== bp_hardware_watchpoint
2540 || b
->type
== bp_read_watchpoint
2541 || b
->type
== bp_access_watchpoint
)
2542 b
->watchpoint_triggered
= watch_triggered_unknown
;
2544 return stopped_by_watchpoint
;
2547 /* The target could report the data address. Mark watchpoints
2548 affected by this data address as triggered, and all others as not
2552 if (b
->type
== bp_hardware_watchpoint
2553 || b
->type
== bp_read_watchpoint
2554 || b
->type
== bp_access_watchpoint
)
2556 struct bp_location
*loc
;
2559 b
->watchpoint_triggered
= watch_triggered_no
;
2560 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2561 /* Exact match not required. Within range is
2563 if (target_watchpoint_addr_within_range (¤t_target
,
2567 b
->watchpoint_triggered
= watch_triggered_yes
;
2575 /* Possible return values for watchpoint_check (this can't be an enum
2576 because of check_errors). */
2577 /* The watchpoint has been deleted. */
2578 #define WP_DELETED 1
2579 /* The value has changed. */
2580 #define WP_VALUE_CHANGED 2
2581 /* The value has not changed. */
2582 #define WP_VALUE_NOT_CHANGED 3
2584 #define BP_TEMPFLAG 1
2585 #define BP_HARDWAREFLAG 2
2587 /* Check watchpoint condition. */
2590 watchpoint_check (void *p
)
2592 bpstat bs
= (bpstat
) p
;
2593 struct breakpoint
*b
;
2594 struct frame_info
*fr
;
2595 int within_current_scope
;
2597 b
= bs
->breakpoint_at
->owner
;
2599 if (b
->exp_valid_block
== NULL
)
2600 within_current_scope
= 1;
2603 /* There is no current frame at this moment. If we're going to have
2604 any chance of handling watchpoints on local variables, we'll need
2605 the frame chain (so we can determine if we're in scope). */
2606 reinit_frame_cache ();
2607 fr
= frame_find_by_id (b
->watchpoint_frame
);
2608 within_current_scope
= (fr
!= NULL
);
2610 /* If we've gotten confused in the unwinder, we might have
2611 returned a frame that can't describe this variable. */
2612 if (within_current_scope
2613 && (block_linkage_function (b
->exp_valid_block
)
2614 != get_frame_function (fr
)))
2615 within_current_scope
= 0;
2617 /* in_function_epilogue_p() returns a non-zero value if we're still
2618 in the function but the stack frame has already been invalidated.
2619 Since we can't rely on the values of local variables after the
2620 stack has been destroyed, we are treating the watchpoint in that
2621 state as `not changed' without further checking.
2623 vinschen/2003-09-04: The former implementation left out the case
2624 that the watchpoint frame couldn't be found by frame_find_by_id()
2625 because the current PC is currently in an epilogue. Calling
2626 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2627 if ((!within_current_scope
|| fr
== get_current_frame ())
2628 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2629 return WP_VALUE_NOT_CHANGED
;
2630 if (fr
&& within_current_scope
)
2631 /* If we end up stopping, the current frame will get selected
2632 in normal_stop. So this call to select_frame won't affect
2637 if (within_current_scope
)
2639 /* We use value_{,free_to_}mark because it could be a
2640 *long* time before we return to the command level and
2641 call free_all_values. We can't call free_all_values because
2642 we might be in the middle of evaluating a function call. */
2644 struct value
*mark
= value_mark ();
2645 struct value
*new_val
;
2647 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2648 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2649 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2651 if (new_val
!= NULL
)
2653 release_value (new_val
);
2654 value_free_to_mark (mark
);
2656 bs
->old_val
= b
->val
;
2659 /* We will stop here */
2660 return WP_VALUE_CHANGED
;
2664 /* Nothing changed, don't do anything. */
2665 value_free_to_mark (mark
);
2666 /* We won't stop here */
2667 return WP_VALUE_NOT_CHANGED
;
2672 /* This seems like the only logical thing to do because
2673 if we temporarily ignored the watchpoint, then when
2674 we reenter the block in which it is valid it contains
2675 garbage (in the case of a function, it may have two
2676 garbage values, one before and one after the prologue).
2677 So we can't even detect the first assignment to it and
2678 watch after that (since the garbage may or may not equal
2679 the first value assigned). */
2680 /* We print all the stop information in print_it_typical(), but
2681 in this case, by the time we call print_it_typical() this bp
2682 will be deleted already. So we have no choice but print the
2683 information here. */
2684 if (ui_out_is_mi_like_p (uiout
))
2686 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2687 ui_out_text (uiout
, "\nWatchpoint ");
2688 ui_out_field_int (uiout
, "wpnum", b
->number
);
2689 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2690 which its expression is valid.\n");
2692 if (b
->related_breakpoint
)
2693 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2694 b
->disposition
= disp_del_at_next_stop
;
2700 /* Return true if it looks like target has stopped due to hitting
2701 breakpoint location BL. This function does not check if we
2702 should stop, only if BL explains the stop. */
2704 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2706 struct breakpoint
*b
= bl
->owner
;
2708 if (b
->type
!= bp_watchpoint
2709 && b
->type
!= bp_hardware_watchpoint
2710 && b
->type
!= bp_read_watchpoint
2711 && b
->type
!= bp_access_watchpoint
2712 && b
->type
!= bp_hardware_breakpoint
2713 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2715 if (bl
->address
!= bp_addr
) /* address doesn't match */
2717 if (overlay_debugging
/* unmapped overlay section */
2718 && section_is_overlay (bl
->section
)
2719 && !section_is_mapped (bl
->section
))
2723 /* Continuable hardware watchpoints are treated as non-existent if the
2724 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2725 some data address). Otherwise gdb won't stop on a break instruction
2726 in the code (not from a breakpoint) when a hardware watchpoint has
2727 been defined. Also skip watchpoints which we know did not trigger
2728 (did not match the data address). */
2730 if ((b
->type
== bp_hardware_watchpoint
2731 || b
->type
== bp_read_watchpoint
2732 || b
->type
== bp_access_watchpoint
)
2733 && b
->watchpoint_triggered
== watch_triggered_no
)
2736 if (b
->type
== bp_hardware_breakpoint
)
2738 if (bl
->address
!= bp_addr
)
2740 if (overlay_debugging
/* unmapped overlay section */
2741 && section_is_overlay (bl
->section
)
2742 && !section_is_mapped (bl
->section
))
2746 if (b
->type
== bp_catchpoint
)
2748 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2749 if (!b
->ops
->breakpoint_hit (b
))
2756 /* If BS refers to a watchpoint, determine if the watched values
2757 has actually changed, and we should stop. If not, set BS->stop
2760 bpstat_check_watchpoint (bpstat bs
)
2762 const struct bp_location
*bl
= bs
->breakpoint_at
;
2763 struct breakpoint
*b
= bl
->owner
;
2765 if (b
->type
== bp_watchpoint
2766 || b
->type
== bp_read_watchpoint
2767 || b
->type
== bp_access_watchpoint
2768 || b
->type
== bp_hardware_watchpoint
)
2772 int must_check_value
= 0;
2774 if (b
->type
== bp_watchpoint
)
2775 /* For a software watchpoint, we must always check the
2777 must_check_value
= 1;
2778 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2779 /* We have a hardware watchpoint (read, write, or access)
2780 and the target earlier reported an address watched by
2782 must_check_value
= 1;
2783 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2784 && b
->type
== bp_hardware_watchpoint
)
2785 /* We were stopped by a hardware watchpoint, but the target could
2786 not report the data address. We must check the watchpoint's
2787 value. Access and read watchpoints are out of luck; without
2788 a data address, we can't figure it out. */
2789 must_check_value
= 1;
2791 if (must_check_value
)
2793 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2795 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2796 int e
= catch_errors (watchpoint_check
, bs
, message
,
2798 do_cleanups (cleanups
);
2802 /* We've already printed what needs to be printed. */
2803 bs
->print_it
= print_it_done
;
2806 case WP_VALUE_CHANGED
:
2807 if (b
->type
== bp_read_watchpoint
)
2809 /* Don't stop: read watchpoints shouldn't fire if
2810 the value has changed. This is for targets
2811 which cannot set read-only watchpoints. */
2812 bs
->print_it
= print_it_noop
;
2816 case WP_VALUE_NOT_CHANGED
:
2817 if (b
->type
== bp_hardware_watchpoint
2818 || b
->type
== bp_watchpoint
)
2820 /* Don't stop: write watchpoints shouldn't fire if
2821 the value hasn't changed. */
2822 bs
->print_it
= print_it_noop
;
2830 /* Error from catch_errors. */
2831 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2832 if (b
->related_breakpoint
)
2833 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2834 b
->disposition
= disp_del_at_next_stop
;
2835 /* We've already printed what needs to be printed. */
2836 bs
->print_it
= print_it_done
;
2840 else /* must_check_value == 0 */
2842 /* This is a case where some watchpoint(s) triggered, but
2843 not at the address of this watchpoint, or else no
2844 watchpoint triggered after all. So don't print
2845 anything for this watchpoint. */
2846 bs
->print_it
= print_it_noop
;
2853 /* Check conditions (condition proper, frame, thread and ignore count)
2854 of breakpoint referred to by BS. If we should not stop for this
2855 breakpoint, set BS->stop to 0. */
2857 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2859 int thread_id
= pid_to_thread_id (ptid
);
2860 const struct bp_location
*bl
= bs
->breakpoint_at
;
2861 struct breakpoint
*b
= bl
->owner
;
2863 if (frame_id_p (b
->frame_id
)
2864 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2868 int value_is_zero
= 0;
2870 /* If this is a scope breakpoint, mark the associated
2871 watchpoint as triggered so that we will handle the
2872 out-of-scope event. We'll get to the watchpoint next
2874 if (b
->type
== bp_watchpoint_scope
)
2875 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2877 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2879 /* Need to select the frame, with all that implies
2880 so that the conditions will have the right context. */
2881 select_frame (get_current_frame ());
2883 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2884 "Error in testing breakpoint condition:\n",
2886 /* FIXME-someday, should give breakpoint # */
2889 if (bl
->cond
&& value_is_zero
)
2893 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2897 else if (b
->ignore_count
> 0)
2900 annotate_ignore_count_change ();
2902 /* Increase the hit count even though we don't
2910 /* Get a bpstat associated with having just stopped at address
2911 BP_ADDR in thread PTID.
2913 Determine whether we stopped at a breakpoint, etc, or whether we
2914 don't understand this stop. Result is a chain of bpstat's such that:
2916 if we don't understand the stop, the result is a null pointer.
2918 if we understand why we stopped, the result is not null.
2920 Each element of the chain refers to a particular breakpoint or
2921 watchpoint at which we have stopped. (We may have stopped for
2922 several reasons concurrently.)
2924 Each element of the chain has valid next, breakpoint_at,
2925 commands, FIXME??? fields. */
2928 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2930 struct breakpoint
*b
= NULL
;
2931 const struct bp_location
*bl
;
2932 struct bp_location
*loc
;
2933 /* Root of the chain of bpstat's */
2934 struct bpstats root_bs
[1];
2935 /* Pointer to the last thing in the chain currently. */
2936 bpstat bs
= root_bs
;
2938 int need_remove_insert
;
2940 ALL_BP_LOCATIONS (bl
)
2944 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2947 /* For hardware watchpoints, we look only at the first location.
2948 The watchpoint_check function will work on entire expression,
2949 not the individual locations. For read watchopints, the
2950 watchpoints_triggered function have checked all locations
2953 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2956 if (!bpstat_check_location (bl
, bp_addr
))
2959 /* Come here if it's a watchpoint, or if the break address matches */
2961 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2963 /* Assume we stop. Should we find watchpoint that is not actually
2964 triggered, or if condition of breakpoint is false, we'll reset
2969 bpstat_check_watchpoint (bs
);
2973 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2974 /* We do not stop for these. */
2977 bpstat_check_breakpoint_conditions (bs
, ptid
);
2983 /* We will stop here */
2984 if (b
->disposition
== disp_disable
)
2986 if (b
->enable_state
!= bp_permanent
)
2987 b
->enable_state
= bp_disabled
;
2988 update_global_location_list (0);
2992 bs
->commands
= b
->commands
;
2994 (strcmp ("silent", bs
->commands
->line
) == 0
2995 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2997 bs
->commands
= bs
->commands
->next
;
3000 bs
->commands
= copy_command_lines (bs
->commands
);
3003 /* Print nothing for this entry if we dont stop or if we dont print. */
3004 if (bs
->stop
== 0 || bs
->print
== 0)
3005 bs
->print_it
= print_it_noop
;
3008 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3010 if (loc
->address
== bp_addr
)
3012 bs
= bpstat_alloc (loc
, bs
);
3013 /* For hits of moribund locations, we should just proceed. */
3016 bs
->print_it
= print_it_noop
;
3020 bs
->next
= NULL
; /* Terminate the chain */
3021 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3023 /* If we aren't stopping, the value of some hardware watchpoint may
3024 not have changed, but the intermediate memory locations we are
3025 watching may have. Don't bother if we're stopping; this will get
3027 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3031 need_remove_insert
= 0;
3033 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3035 && bs
->breakpoint_at
->owner
3036 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3037 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3038 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3040 /* remove/insert can invalidate bs->breakpoint_at, if this
3041 location is no longer used by the watchpoint. Prevent
3042 further code from trying to use it. */
3043 bs
->breakpoint_at
= NULL
;
3044 need_remove_insert
= 1;
3047 if (need_remove_insert
)
3049 remove_breakpoints ();
3050 insert_breakpoints ();
3053 return root_bs
->next
;
3056 /* Tell what to do about this bpstat. */
3058 bpstat_what (bpstat bs
)
3060 /* Classify each bpstat as one of the following. */
3063 /* This bpstat element has no effect on the main_action. */
3066 /* There was a watchpoint, stop but don't print. */
3069 /* There was a watchpoint, stop and print. */
3072 /* There was a breakpoint but we're not stopping. */
3075 /* There was a breakpoint, stop but don't print. */
3078 /* There was a breakpoint, stop and print. */
3081 /* We hit the longjmp breakpoint. */
3084 /* We hit the longjmp_resume breakpoint. */
3087 /* We hit the step_resume breakpoint. */
3090 /* We hit the shared library event breakpoint. */
3093 /* This is just used to count how many enums there are. */
3097 /* Here is the table which drives this routine. So that we can
3098 format it pretty, we define some abbreviations for the
3099 enum bpstat_what codes. */
3100 #define kc BPSTAT_WHAT_KEEP_CHECKING
3101 #define ss BPSTAT_WHAT_STOP_SILENT
3102 #define sn BPSTAT_WHAT_STOP_NOISY
3103 #define sgl BPSTAT_WHAT_SINGLE
3104 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3105 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3106 #define sr BPSTAT_WHAT_STEP_RESUME
3107 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3109 /* "Can't happen." Might want to print an error message.
3110 abort() is not out of the question, but chances are GDB is just
3111 a bit confused, not unusable. */
3112 #define err BPSTAT_WHAT_STOP_NOISY
3114 /* Given an old action and a class, come up with a new action. */
3115 /* One interesting property of this table is that wp_silent is the same
3116 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3117 after stopping, the check for whether to step over a breakpoint
3118 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3119 reference to how we stopped. We retain separate wp_silent and
3120 bp_silent codes in case we want to change that someday.
3122 Another possibly interesting property of this table is that
3123 there's a partial ordering, priority-like, of the actions. Once
3124 you've decided that some action is appropriate, you'll never go
3125 back and decide something of a lower priority is better. The
3128 kc < clr sgl shl slr sn sr ss
3129 sgl < shl slr sn sr ss
3130 slr < err shl sn sr ss
3131 clr < err shl sn sr ss
3137 What I think this means is that we don't need a damned table
3138 here. If you just put the rows and columns in the right order,
3139 it'd look awfully regular. We could simply walk the bpstat list
3140 and choose the highest priority action we find, with a little
3141 logic to handle the 'err' cases. */
3143 /* step_resume entries: a step resume breakpoint overrides another
3144 breakpoint of signal handling (see comment in wait_for_inferior
3145 at where we set the step_resume breakpoint). */
3147 static const enum bpstat_what_main_action
3148 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3151 /* kc ss sn sgl slr clr sr shl
3154 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3156 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3158 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3160 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3162 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3164 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3166 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3168 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3170 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3172 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3185 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3186 struct bpstat_what retval
;
3188 retval
.call_dummy
= 0;
3189 for (; bs
!= NULL
; bs
= bs
->next
)
3191 enum class bs_class
= no_effect
;
3192 if (bs
->breakpoint_at
== NULL
)
3193 /* I suspect this can happen if it was a momentary breakpoint
3194 which has since been deleted. */
3196 if (bs
->breakpoint_at
->owner
== NULL
)
3197 bs_class
= bp_nostop
;
3199 switch (bs
->breakpoint_at
->owner
->type
)
3205 case bp_hardware_breakpoint
:
3211 bs_class
= bp_noisy
;
3213 bs_class
= bp_silent
;
3216 bs_class
= bp_nostop
;
3219 case bp_hardware_watchpoint
:
3220 case bp_read_watchpoint
:
3221 case bp_access_watchpoint
:
3225 bs_class
= wp_noisy
;
3227 bs_class
= wp_silent
;
3230 /* There was a watchpoint, but we're not stopping.
3231 This requires no further action. */
3232 bs_class
= no_effect
;
3235 bs_class
= long_jump
;
3237 case bp_longjmp_resume
:
3238 bs_class
= long_resume
;
3240 case bp_step_resume
:
3243 bs_class
= step_resume
;
3246 /* It is for the wrong frame. */
3247 bs_class
= bp_nostop
;
3249 case bp_watchpoint_scope
:
3250 bs_class
= bp_nostop
;
3252 case bp_shlib_event
:
3253 bs_class
= shlib_event
;
3255 case bp_thread_event
:
3256 case bp_overlay_event
:
3257 bs_class
= bp_nostop
;
3263 bs_class
= bp_noisy
;
3265 bs_class
= bp_silent
;
3268 /* There was a catchpoint, but we're not stopping.
3269 This requires no further action. */
3270 bs_class
= no_effect
;
3273 /* Make sure the action is stop (silent or noisy),
3274 so infrun.c pops the dummy frame. */
3275 bs_class
= bp_silent
;
3276 retval
.call_dummy
= 1;
3279 current_action
= table
[(int) bs_class
][(int) current_action
];
3281 retval
.main_action
= current_action
;
3285 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3286 without hardware support). This isn't related to a specific bpstat,
3287 just to things like whether watchpoints are set. */
3290 bpstat_should_step (void)
3292 struct breakpoint
*b
;
3294 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3301 static void print_breakpoint_location (struct breakpoint
*b
,
3302 struct bp_location
*loc
,
3304 struct ui_stream
*stb
)
3309 = find_pc_sect_function (loc
->address
, loc
->section
);
3312 ui_out_text (uiout
, "in ");
3313 ui_out_field_string (uiout
, "func",
3314 SYMBOL_PRINT_NAME (sym
));
3315 ui_out_wrap_hint (uiout
, wrap_indent
);
3316 ui_out_text (uiout
, " at ");
3318 ui_out_field_string (uiout
, "file", b
->source_file
);
3319 ui_out_text (uiout
, ":");
3321 if (ui_out_is_mi_like_p (uiout
))
3323 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3324 char *fullname
= symtab_to_fullname (sal
.symtab
);
3327 ui_out_field_string (uiout
, "fullname", fullname
);
3330 ui_out_field_int (uiout
, "line", b
->line_number
);
3334 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3338 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3339 ui_out_field_stream (uiout
, "at", stb
);
3343 /* Print B to gdb_stdout. */
3345 print_one_breakpoint_location (struct breakpoint
*b
,
3346 struct bp_location
*loc
,
3348 CORE_ADDR
*last_addr
)
3350 struct command_line
*l
;
3352 struct ep_type_description
3357 static struct ep_type_description bptypes
[] =
3359 {bp_none
, "?deleted?"},
3360 {bp_breakpoint
, "breakpoint"},
3361 {bp_hardware_breakpoint
, "hw breakpoint"},
3362 {bp_until
, "until"},
3363 {bp_finish
, "finish"},
3364 {bp_watchpoint
, "watchpoint"},
3365 {bp_hardware_watchpoint
, "hw watchpoint"},
3366 {bp_read_watchpoint
, "read watchpoint"},
3367 {bp_access_watchpoint
, "acc watchpoint"},
3368 {bp_longjmp
, "longjmp"},
3369 {bp_longjmp_resume
, "longjmp resume"},
3370 {bp_step_resume
, "step resume"},
3371 {bp_watchpoint_scope
, "watchpoint scope"},
3372 {bp_call_dummy
, "call dummy"},
3373 {bp_shlib_event
, "shlib events"},
3374 {bp_thread_event
, "thread events"},
3375 {bp_overlay_event
, "overlay events"},
3376 {bp_catchpoint
, "catchpoint"},
3379 static char bpenables
[] = "nynny";
3380 char wrap_indent
[80];
3381 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3382 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3383 struct cleanup
*bkpt_chain
;
3385 int header_of_multiple
= 0;
3386 int part_of_multiple
= (loc
!= NULL
);
3387 struct value_print_options opts
;
3389 get_user_print_options (&opts
);
3391 gdb_assert (!loc
|| loc_number
!= 0);
3392 /* See comment in print_one_breakpoint concerning
3393 treatment of breakpoints with single disabled
3397 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3398 header_of_multiple
= 1;
3403 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3407 if (part_of_multiple
)
3410 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3411 ui_out_field_string (uiout
, "number", formatted
);
3416 ui_out_field_int (uiout
, "number", b
->number
);
3421 if (part_of_multiple
)
3422 ui_out_field_skip (uiout
, "type");
3425 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3426 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3427 internal_error (__FILE__
, __LINE__
,
3428 _("bptypes table does not describe type #%d."),
3430 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3435 if (part_of_multiple
)
3436 ui_out_field_skip (uiout
, "disp");
3438 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3443 if (part_of_multiple
)
3444 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3446 ui_out_field_fmt (uiout
, "enabled", "%c",
3447 bpenables
[(int) b
->enable_state
]);
3448 ui_out_spaces (uiout
, 2);
3452 strcpy (wrap_indent
, " ");
3453 if (opts
.addressprint
)
3455 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3456 strcat (wrap_indent
, " ");
3458 strcat (wrap_indent
, " ");
3461 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3463 /* Although the print_one can possibly print
3464 all locations, calling it here is not likely
3465 to get any nice result. So, make sure there's
3466 just one location. */
3467 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3468 b
->ops
->print_one (b
, last_addr
);
3474 internal_error (__FILE__
, __LINE__
,
3475 _("print_one_breakpoint: bp_none encountered\n"));
3479 case bp_hardware_watchpoint
:
3480 case bp_read_watchpoint
:
3481 case bp_access_watchpoint
:
3482 /* Field 4, the address, is omitted (which makes the columns
3483 not line up too nicely with the headers, but the effect
3484 is relatively readable). */
3485 if (opts
.addressprint
)
3486 ui_out_field_skip (uiout
, "addr");
3488 print_expression (b
->exp
, stb
->stream
);
3489 ui_out_field_stream (uiout
, "what", stb
);
3493 case bp_hardware_breakpoint
:
3497 case bp_longjmp_resume
:
3498 case bp_step_resume
:
3499 case bp_watchpoint_scope
:
3501 case bp_shlib_event
:
3502 case bp_thread_event
:
3503 case bp_overlay_event
:
3504 if (opts
.addressprint
)
3507 if (header_of_multiple
)
3508 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3509 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3510 ui_out_field_string (uiout
, "addr", "<PENDING>");
3512 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3515 if (!header_of_multiple
)
3516 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3518 *last_addr
= b
->loc
->address
;
3522 if (!part_of_multiple
&& b
->thread
!= -1)
3524 /* FIXME: This seems to be redundant and lost here; see the
3525 "stop only in" line a little further down. */
3526 ui_out_text (uiout
, " thread ");
3527 ui_out_field_int (uiout
, "thread", b
->thread
);
3530 ui_out_text (uiout
, "\n");
3532 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3535 ui_out_text (uiout
, "\tstop only in stack frame at ");
3536 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3538 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3539 ui_out_text (uiout
, "\n");
3542 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3544 /* We do not print the condition for Ada exception catchpoints
3545 because the condition is an internal implementation detail
3546 that we do not want to expose to the user. */
3548 ui_out_text (uiout
, "\tstop only if ");
3549 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3550 ui_out_text (uiout
, "\n");
3553 if (!part_of_multiple
&& b
->thread
!= -1)
3555 /* FIXME should make an annotation for this */
3556 ui_out_text (uiout
, "\tstop only in thread ");
3557 ui_out_field_int (uiout
, "thread", b
->thread
);
3558 ui_out_text (uiout
, "\n");
3561 if (!part_of_multiple
&& b
->hit_count
)
3563 /* FIXME should make an annotation for this */
3564 if (ep_is_catchpoint (b
))
3565 ui_out_text (uiout
, "\tcatchpoint");
3567 ui_out_text (uiout
, "\tbreakpoint");
3568 ui_out_text (uiout
, " already hit ");
3569 ui_out_field_int (uiout
, "times", b
->hit_count
);
3570 if (b
->hit_count
== 1)
3571 ui_out_text (uiout
, " time\n");
3573 ui_out_text (uiout
, " times\n");
3576 /* Output the count also if it is zero, but only if this is
3577 mi. FIXME: Should have a better test for this. */
3578 if (ui_out_is_mi_like_p (uiout
))
3579 if (!part_of_multiple
&& b
->hit_count
== 0)
3580 ui_out_field_int (uiout
, "times", b
->hit_count
);
3582 if (!part_of_multiple
&& b
->ignore_count
)
3585 ui_out_text (uiout
, "\tignore next ");
3586 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3587 ui_out_text (uiout
, " hits\n");
3590 if (!part_of_multiple
&& (l
= b
->commands
))
3592 struct cleanup
*script_chain
;
3595 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3596 print_command_lines (uiout
, l
, 4);
3597 do_cleanups (script_chain
);
3600 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3603 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3604 else if (b
->exp_string
)
3605 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3608 do_cleanups (bkpt_chain
);
3609 do_cleanups (old_chain
);
3613 print_one_breakpoint (struct breakpoint
*b
,
3614 CORE_ADDR
*last_addr
)
3616 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3618 /* If this breakpoint has custom print function,
3619 it's already printed. Otherwise, print individual
3620 locations, if any. */
3621 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3623 /* If breakpoint has a single location that is
3624 disabled, we print it as if it had
3625 several locations, since otherwise it's hard to
3626 represent "breakpoint enabled, location disabled"
3628 Note that while hardware watchpoints have
3629 several locations internally, that's no a property
3632 && !is_hardware_watchpoint (b
)
3633 && (b
->loc
->next
|| !b
->loc
->enabled
)
3634 && !ui_out_is_mi_like_p (uiout
))
3636 struct bp_location
*loc
;
3638 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3639 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3645 struct captured_breakpoint_query_args
3651 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3653 struct captured_breakpoint_query_args
*args
= data
;
3654 struct breakpoint
*b
;
3655 CORE_ADDR dummy_addr
= 0;
3658 if (args
->bnum
== b
->number
)
3660 print_one_breakpoint (b
, &dummy_addr
);
3668 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3670 struct captured_breakpoint_query_args args
;
3672 /* For the moment we don't trust print_one_breakpoint() to not throw
3674 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3675 error_message
, RETURN_MASK_ALL
) < 0)
3681 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3682 catchpoints, et.al.). */
3685 user_settable_breakpoint (const struct breakpoint
*b
)
3687 return (b
->type
== bp_breakpoint
3688 || b
->type
== bp_catchpoint
3689 || b
->type
== bp_hardware_breakpoint
3690 || b
->type
== bp_watchpoint
3691 || b
->type
== bp_read_watchpoint
3692 || b
->type
== bp_access_watchpoint
3693 || b
->type
== bp_hardware_watchpoint
);
3696 /* Print information on user settable breakpoint (watchpoint, etc)
3697 number BNUM. If BNUM is -1 print all user settable breakpoints.
3698 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3701 breakpoint_1 (int bnum
, int allflag
)
3703 struct breakpoint
*b
;
3704 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3705 int nr_printable_breakpoints
;
3706 struct cleanup
*bkpttbl_chain
;
3707 struct value_print_options opts
;
3709 get_user_print_options (&opts
);
3711 /* Compute the number of rows in the table. */
3712 nr_printable_breakpoints
= 0;
3715 || bnum
== b
->number
)
3717 if (allflag
|| user_settable_breakpoint (b
))
3718 nr_printable_breakpoints
++;
3721 if (opts
.addressprint
)
3723 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3727 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3730 if (nr_printable_breakpoints
> 0)
3731 annotate_breakpoints_headers ();
3732 if (nr_printable_breakpoints
> 0)
3734 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3735 if (nr_printable_breakpoints
> 0)
3737 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3738 if (nr_printable_breakpoints
> 0)
3740 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3741 if (nr_printable_breakpoints
> 0)
3743 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3744 if (opts
.addressprint
)
3746 if (nr_printable_breakpoints
> 0)
3748 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3749 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3751 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3753 if (nr_printable_breakpoints
> 0)
3755 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3756 ui_out_table_body (uiout
);
3757 if (nr_printable_breakpoints
> 0)
3758 annotate_breakpoints_table ();
3762 || bnum
== b
->number
)
3764 /* We only print out user settable breakpoints unless the
3766 if (allflag
|| user_settable_breakpoint (b
))
3767 print_one_breakpoint (b
, &last_addr
);
3770 do_cleanups (bkpttbl_chain
);
3772 if (nr_printable_breakpoints
== 0)
3775 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3777 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3782 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3783 that a comparison of an unsigned with -1 is always false. */
3784 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3785 set_next_address (current_gdbarch
, last_addr
);
3788 /* FIXME? Should this be moved up so that it is only called when
3789 there have been breakpoints? */
3790 annotate_breakpoints_table_end ();
3794 breakpoints_info (char *bnum_exp
, int from_tty
)
3799 bnum
= parse_and_eval_long (bnum_exp
);
3801 breakpoint_1 (bnum
, 0);
3805 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3810 bnum
= parse_and_eval_long (bnum_exp
);
3812 breakpoint_1 (bnum
, 1);
3816 breakpoint_has_pc (struct breakpoint
*b
,
3817 CORE_ADDR pc
, struct obj_section
*section
)
3819 struct bp_location
*bl
= b
->loc
;
3820 for (; bl
; bl
= bl
->next
)
3822 if (bl
->address
== pc
3823 && (!overlay_debugging
|| bl
->section
== section
))
3829 /* Print a message describing any breakpoints set at PC. */
3832 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3836 struct breakpoint
*b
;
3839 others
+= breakpoint_has_pc (b
, pc
, section
);
3843 printf_filtered (_("Note: breakpoint "));
3844 else /* if (others == ???) */
3845 printf_filtered (_("Note: breakpoints "));
3847 if (breakpoint_has_pc (b
, pc
, section
))
3850 printf_filtered ("%d", b
->number
);
3851 if (b
->thread
== -1 && thread
!= -1)
3852 printf_filtered (" (all threads)");
3853 else if (b
->thread
!= -1)
3854 printf_filtered (" (thread %d)", b
->thread
);
3855 printf_filtered ("%s%s ",
3856 ((b
->enable_state
== bp_disabled
||
3857 b
->enable_state
== bp_call_disabled
)
3859 : b
->enable_state
== bp_permanent
3863 : ((others
== 1) ? " and" : ""));
3865 printf_filtered (_("also set at pc "));
3866 fputs_filtered (paddress (pc
), gdb_stdout
);
3867 printf_filtered (".\n");
3871 /* Set the default place to put a breakpoint
3872 for the `break' command with no arguments. */
3875 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3878 default_breakpoint_valid
= valid
;
3879 default_breakpoint_address
= addr
;
3880 default_breakpoint_symtab
= symtab
;
3881 default_breakpoint_line
= line
;
3884 /* Return true iff it is meaningful to use the address member of
3885 BPT. For some breakpoint types, the address member is irrelevant
3886 and it makes no sense to attempt to compare it to other addresses
3887 (or use it for any other purpose either).
3889 More specifically, each of the following breakpoint types will always
3890 have a zero valued address and we don't want check_duplicates() to mark
3891 breakpoints of any of these types to be a duplicate of an actual
3892 breakpoint at address zero:
3895 bp_hardware_watchpoint
3897 bp_access_watchpoint
3901 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3903 enum bptype type
= bpt
->type
;
3905 return (type
!= bp_watchpoint
3906 && type
!= bp_hardware_watchpoint
3907 && type
!= bp_read_watchpoint
3908 && type
!= bp_access_watchpoint
3909 && type
!= bp_catchpoint
);
3912 /* Rescan breakpoints at the same address and section as BPT,
3913 marking the first one as "first" and any others as "duplicates".
3914 This is so that the bpt instruction is only inserted once.
3915 If we have a permanent breakpoint at the same place as BPT, make
3916 that one the official one, and the rest as duplicates. */
3919 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
3921 struct bp_location
*b
;
3923 struct bp_location
*perm_bp
= 0;
3925 ALL_BP_LOCATIONS (b
)
3926 if (b
->owner
->enable_state
!= bp_disabled
3927 && b
->owner
->enable_state
!= bp_call_disabled
3929 && !b
->shlib_disabled
3930 && b
->address
== address
/* address / overlay match */
3931 && (!overlay_debugging
|| b
->section
== section
)
3932 && breakpoint_address_is_meaningful (b
->owner
))
3934 /* Have we found a permanent breakpoint? */
3935 if (b
->owner
->enable_state
== bp_permanent
)
3942 b
->duplicate
= count
> 1;
3945 /* If we found a permanent breakpoint at this address, go over the
3946 list again and declare all the other breakpoints there to be the
3950 perm_bp
->duplicate
= 0;
3952 /* Permanent breakpoint should always be inserted. */
3953 if (! perm_bp
->inserted
)
3954 internal_error (__FILE__
, __LINE__
,
3955 _("allegedly permanent breakpoint is not "
3956 "actually inserted"));
3958 ALL_BP_LOCATIONS (b
)
3961 if (b
->owner
->enable_state
!= bp_disabled
3962 && b
->owner
->enable_state
!= bp_call_disabled
3963 && b
->enabled
&& !b
->shlib_disabled
3964 && b
->address
== address
/* address / overlay match */
3965 && (!overlay_debugging
|| b
->section
== section
)
3966 && breakpoint_address_is_meaningful (b
->owner
))
3969 internal_error (__FILE__
, __LINE__
,
3970 _("another breakpoint was inserted on top of "
3971 "a permanent breakpoint"));
3980 check_duplicates (struct breakpoint
*bpt
)
3982 struct bp_location
*bl
= bpt
->loc
;
3984 if (! breakpoint_address_is_meaningful (bpt
))
3987 for (; bl
; bl
= bl
->next
)
3988 check_duplicates_for (bl
->address
, bl
->section
);
3992 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3993 int bnum
, int have_bnum
)
3998 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
3999 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4001 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4002 bnum
, astr1
, astr2
);
4004 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4007 /* Adjust a breakpoint's address to account for architectural constraints
4008 on breakpoint placement. Return the adjusted address. Note: Very
4009 few targets require this kind of adjustment. For most targets,
4010 this function is simply the identity function. */
4013 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4015 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4017 /* Very few targets need any kind of breakpoint adjustment. */
4020 else if (bptype
== bp_watchpoint
4021 || bptype
== bp_hardware_watchpoint
4022 || bptype
== bp_read_watchpoint
4023 || bptype
== bp_access_watchpoint
4024 || bptype
== bp_catchpoint
)
4026 /* Watchpoints and the various bp_catch_* eventpoints should not
4027 have their addresses modified. */
4032 CORE_ADDR adjusted_bpaddr
;
4034 /* Some targets have architectural constraints on the placement
4035 of breakpoint instructions. Obtain the adjusted address. */
4036 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4039 /* An adjusted breakpoint address can significantly alter
4040 a user's expectations. Print a warning if an adjustment
4042 if (adjusted_bpaddr
!= bpaddr
)
4043 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4045 return adjusted_bpaddr
;
4049 /* Allocate a struct bp_location. */
4051 static struct bp_location
*
4052 allocate_bp_location (struct breakpoint
*bpt
)
4054 struct bp_location
*loc
, *loc_p
;
4056 loc
= xmalloc (sizeof (struct bp_location
));
4057 memset (loc
, 0, sizeof (*loc
));
4061 loc
->shlib_disabled
= 0;
4070 case bp_longjmp_resume
:
4071 case bp_step_resume
:
4072 case bp_watchpoint_scope
:
4074 case bp_shlib_event
:
4075 case bp_thread_event
:
4076 case bp_overlay_event
:
4077 loc
->loc_type
= bp_loc_software_breakpoint
;
4079 case bp_hardware_breakpoint
:
4080 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4082 case bp_hardware_watchpoint
:
4083 case bp_read_watchpoint
:
4084 case bp_access_watchpoint
:
4085 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4089 loc
->loc_type
= bp_loc_other
;
4092 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4098 static void free_bp_location (struct bp_location
*loc
)
4103 if (loc
->function_name
)
4104 xfree (loc
->function_name
);
4109 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4110 that has type BPTYPE and has no locations as yet. */
4112 static struct breakpoint
*
4113 set_raw_breakpoint_without_location (enum bptype bptype
)
4115 struct breakpoint
*b
, *b1
;
4117 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4118 memset (b
, 0, sizeof (*b
));
4121 b
->language
= current_language
->la_language
;
4122 b
->input_radix
= input_radix
;
4124 b
->enable_state
= bp_enabled
;
4127 b
->ignore_count
= 0;
4129 b
->frame_id
= null_frame_id
;
4130 b
->forked_inferior_pid
= null_ptid
;
4131 b
->exec_pathname
= NULL
;
4133 b
->condition_not_parsed
= 0;
4135 /* Add this breakpoint to the end of the chain
4136 so that a list of breakpoints will come out in order
4137 of increasing numbers. */
4139 b1
= breakpoint_chain
;
4141 breakpoint_chain
= b
;
4151 /* Initialize loc->function_name. */
4153 set_breakpoint_location_function (struct bp_location
*loc
)
4155 if (loc
->owner
->type
== bp_breakpoint
4156 || loc
->owner
->type
== bp_hardware_breakpoint
)
4158 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4160 if (loc
->function_name
)
4161 loc
->function_name
= xstrdup (loc
->function_name
);
4165 /* set_raw_breakpoint is a low level routine for allocating and
4166 partially initializing a breakpoint of type BPTYPE. The newly
4167 created breakpoint's address, section, source file name, and line
4168 number are provided by SAL. The newly created and partially
4169 initialized breakpoint is added to the breakpoint chain and
4170 is also returned as the value of this function.
4172 It is expected that the caller will complete the initialization of
4173 the newly created breakpoint struct as well as output any status
4174 information regarding the creation of a new breakpoint. In
4175 particular, set_raw_breakpoint does NOT set the breakpoint
4176 number! Care should be taken to not allow an error to occur
4177 prior to completing the initialization of the breakpoint. If this
4178 should happen, a bogus breakpoint will be left on the chain. */
4181 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4183 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4184 CORE_ADDR adjusted_address
;
4186 /* Adjust the breakpoint's address prior to allocating a location.
4187 Once we call allocate_bp_location(), that mostly uninitialized
4188 location will be placed on the location chain. Adjustment of the
4189 breakpoint may cause target_read_memory() to be called and we do
4190 not want its scan of the location chain to find a breakpoint and
4191 location that's only been partially initialized. */
4192 adjusted_address
= adjust_breakpoint_address (sal
.pc
, b
->type
);
4194 b
->loc
= allocate_bp_location (b
);
4195 b
->loc
->requested_address
= sal
.pc
;
4196 b
->loc
->address
= adjusted_address
;
4198 if (sal
.symtab
== NULL
)
4199 b
->source_file
= NULL
;
4201 b
->source_file
= savestring (sal
.symtab
->filename
,
4202 strlen (sal
.symtab
->filename
));
4203 b
->loc
->section
= sal
.section
;
4204 b
->line_number
= sal
.line
;
4206 set_breakpoint_location_function (b
->loc
);
4208 breakpoints_changed ();
4214 /* Note that the breakpoint object B describes a permanent breakpoint
4215 instruction, hard-wired into the inferior's code. */
4217 make_breakpoint_permanent (struct breakpoint
*b
)
4219 struct bp_location
*bl
;
4220 b
->enable_state
= bp_permanent
;
4222 /* By definition, permanent breakpoints are already present in the code.
4223 Mark all locations as inserted. For now, make_breakpoint_permanent
4224 is called in just one place, so it's hard to say if it's reasonable
4225 to have permanent breakpoint with multiple locations or not,
4226 but it's easy to implmement. */
4227 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4231 static struct breakpoint
*
4232 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4234 static int internal_breakpoint_number
= -1;
4235 struct symtab_and_line sal
;
4236 struct breakpoint
*b
;
4238 init_sal (&sal
); /* initialize to zeroes */
4241 sal
.section
= find_pc_overlay (sal
.pc
);
4243 b
= set_raw_breakpoint (sal
, type
);
4244 b
->number
= internal_breakpoint_number
--;
4245 b
->disposition
= disp_donttouch
;
4252 create_longjmp_breakpoint (char *func_name
)
4254 struct minimal_symbol
*m
;
4256 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4258 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4259 update_global_location_list (1);
4262 /* Call this routine when stepping and nexting to enable a breakpoint
4263 if we do a longjmp(). When we hit that breakpoint, call
4264 set_longjmp_resume_breakpoint() to figure out where we are going. */
4267 set_longjmp_breakpoint (void)
4269 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4271 create_longjmp_breakpoint ("longjmp");
4272 create_longjmp_breakpoint ("_longjmp");
4273 create_longjmp_breakpoint ("siglongjmp");
4274 create_longjmp_breakpoint ("_siglongjmp");
4278 /* Delete all longjmp breakpoints from THREAD. */
4280 delete_longjmp_breakpoint (int thread
)
4282 struct breakpoint
*b
, *temp
;
4284 ALL_BREAKPOINTS_SAFE (b
, temp
)
4285 if (b
->type
== bp_longjmp
)
4287 if (b
->thread
== thread
)
4288 delete_breakpoint (b
);
4293 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4295 struct breakpoint
*b
;
4296 struct minimal_symbol
*m
;
4298 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4301 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4303 b
->addr_string
= xstrdup (func_name
);
4305 if (overlay_debugging
== ovly_auto
)
4307 b
->enable_state
= bp_enabled
;
4308 overlay_events_enabled
= 1;
4312 b
->enable_state
= bp_disabled
;
4313 overlay_events_enabled
= 0;
4315 update_global_location_list (1);
4319 create_overlay_event_breakpoint (char *func_name
)
4321 struct objfile
*objfile
;
4322 ALL_OBJFILES (objfile
)
4323 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4327 enable_overlay_breakpoints (void)
4329 struct breakpoint
*b
;
4332 if (b
->type
== bp_overlay_event
)
4334 b
->enable_state
= bp_enabled
;
4335 update_global_location_list (1);
4336 overlay_events_enabled
= 1;
4341 disable_overlay_breakpoints (void)
4343 struct breakpoint
*b
;
4346 if (b
->type
== bp_overlay_event
)
4348 b
->enable_state
= bp_disabled
;
4349 update_global_location_list (0);
4350 overlay_events_enabled
= 0;
4355 create_thread_event_breakpoint (CORE_ADDR address
)
4357 struct breakpoint
*b
;
4359 b
= create_internal_breakpoint (address
, bp_thread_event
);
4361 b
->enable_state
= bp_enabled
;
4362 /* addr_string has to be used or breakpoint_re_set will delete me. */
4363 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4365 update_global_location_list_nothrow (1);
4371 remove_thread_event_breakpoints (void)
4373 struct breakpoint
*b
, *temp
;
4375 ALL_BREAKPOINTS_SAFE (b
, temp
)
4376 if (b
->type
== bp_thread_event
)
4377 delete_breakpoint (b
);
4380 struct captured_parse_breakpoint_args
4383 struct symtabs_and_lines
*sals_p
;
4384 char ***addr_string_p
;
4388 struct lang_and_radix
4396 remove_solib_event_breakpoints (void)
4398 struct breakpoint
*b
, *temp
;
4400 ALL_BREAKPOINTS_SAFE (b
, temp
)
4401 if (b
->type
== bp_shlib_event
)
4402 delete_breakpoint (b
);
4406 create_solib_event_breakpoint (CORE_ADDR address
)
4408 struct breakpoint
*b
;
4410 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4411 update_global_location_list_nothrow (1);
4415 /* Disable any breakpoints that are on code in shared libraries. Only
4416 apply to enabled breakpoints, disabled ones can just stay disabled. */
4419 disable_breakpoints_in_shlibs (void)
4421 struct bp_location
*loc
;
4422 int disabled_shlib_breaks
= 0;
4424 ALL_BP_LOCATIONS (loc
)
4426 struct breakpoint
*b
= loc
->owner
;
4427 /* We apply the check to all breakpoints, including disabled
4428 for those with loc->duplicate set. This is so that when breakpoint
4429 becomes enabled, or the duplicate is removed, gdb will try to insert
4430 all breakpoints. If we don't set shlib_disabled here, we'll try
4431 to insert those breakpoints and fail. */
4432 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4433 && !loc
->shlib_disabled
4435 && PC_SOLIB (loc
->address
)
4437 && solib_address (loc
->address
)
4441 loc
->shlib_disabled
= 1;
4446 /* Disable any breakpoints that are in in an unloaded shared library. Only
4447 apply to enabled breakpoints, disabled ones can just stay disabled. */
4450 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4452 struct bp_location
*loc
;
4453 int disabled_shlib_breaks
= 0;
4455 ALL_BP_LOCATIONS (loc
)
4457 struct breakpoint
*b
= loc
->owner
;
4458 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4459 || loc
->loc_type
== bp_loc_software_breakpoint
)
4460 && !loc
->shlib_disabled
)
4463 char *so_name
= PC_SOLIB (loc
->address
);
4465 char *so_name
= solib_address (loc
->address
);
4467 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4469 loc
->shlib_disabled
= 1;
4470 /* At this point, we cannot rely on remove_breakpoint
4471 succeeding so we must mark the breakpoint as not inserted
4472 to prevent future errors occurring in remove_breakpoints. */
4474 if (!disabled_shlib_breaks
)
4476 target_terminal_ours_for_output ();
4477 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4480 disabled_shlib_breaks
= 1;
4486 /* FORK & VFORK catchpoints. */
4488 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4491 insert_catch_fork (struct breakpoint
*b
)
4493 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4496 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4499 remove_catch_fork (struct breakpoint
*b
)
4501 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4504 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4508 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4510 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4513 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4515 static enum print_stop_action
4516 print_it_catch_fork (struct breakpoint
*b
)
4518 annotate_catchpoint (b
->number
);
4519 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4520 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4521 return PRINT_SRC_AND_LOC
;
4524 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4527 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4529 struct value_print_options opts
;
4531 get_user_print_options (&opts
);
4533 /* Field 4, the address, is omitted (which makes the columns
4534 not line up too nicely with the headers, but the effect
4535 is relatively readable). */
4536 if (opts
.addressprint
)
4537 ui_out_field_skip (uiout
, "addr");
4539 ui_out_text (uiout
, "fork");
4540 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4542 ui_out_text (uiout
, ", process ");
4543 ui_out_field_int (uiout
, "what",
4544 ptid_get_pid (b
->forked_inferior_pid
));
4545 ui_out_spaces (uiout
, 1);
4549 /* Implement the "print_mention" breakpoint_ops method for fork
4553 print_mention_catch_fork (struct breakpoint
*b
)
4555 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4558 /* The breakpoint_ops structure to be used in fork catchpoints. */
4560 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4564 breakpoint_hit_catch_fork
,
4565 print_it_catch_fork
,
4566 print_one_catch_fork
,
4567 print_mention_catch_fork
4570 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4573 insert_catch_vfork (struct breakpoint
*b
)
4575 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4578 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4581 remove_catch_vfork (struct breakpoint
*b
)
4583 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4586 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4590 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4592 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4595 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4597 static enum print_stop_action
4598 print_it_catch_vfork (struct breakpoint
*b
)
4600 annotate_catchpoint (b
->number
);
4601 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4602 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4603 return PRINT_SRC_AND_LOC
;
4606 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4609 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4611 struct value_print_options opts
;
4613 get_user_print_options (&opts
);
4614 /* Field 4, the address, is omitted (which makes the columns
4615 not line up too nicely with the headers, but the effect
4616 is relatively readable). */
4617 if (opts
.addressprint
)
4618 ui_out_field_skip (uiout
, "addr");
4620 ui_out_text (uiout
, "vfork");
4621 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4623 ui_out_text (uiout
, ", process ");
4624 ui_out_field_int (uiout
, "what",
4625 ptid_get_pid (b
->forked_inferior_pid
));
4626 ui_out_spaces (uiout
, 1);
4630 /* Implement the "print_mention" breakpoint_ops method for vfork
4634 print_mention_catch_vfork (struct breakpoint
*b
)
4636 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4639 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4641 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4645 breakpoint_hit_catch_vfork
,
4646 print_it_catch_vfork
,
4647 print_one_catch_vfork
,
4648 print_mention_catch_vfork
4651 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4653 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4654 If COND_STRING is not NULL, then store it in the breakpoint.
4655 OPS, if not NULL, is the breakpoint_ops structure associated
4656 to the catchpoint. */
4658 static struct breakpoint
*
4659 create_catchpoint (int tempflag
, char *cond_string
,
4660 struct breakpoint_ops
*ops
)
4662 struct symtab_and_line sal
;
4663 struct breakpoint
*b
;
4670 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4671 set_breakpoint_count (breakpoint_count
+ 1);
4672 b
->number
= breakpoint_count
;
4674 b
->cond_string
= (cond_string
== NULL
) ?
4675 NULL
: savestring (cond_string
, strlen (cond_string
));
4677 b
->addr_string
= NULL
;
4678 b
->enable_state
= bp_enabled
;
4679 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4683 update_global_location_list (1);
4689 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4690 struct breakpoint_ops
*ops
)
4692 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4694 /* FIXME: We should put this information in a breakpoint private data
4696 b
->forked_inferior_pid
= null_ptid
;
4699 /* Exec catchpoints. */
4702 insert_catch_exec (struct breakpoint
*b
)
4704 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4708 remove_catch_exec (struct breakpoint
*b
)
4710 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4714 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4716 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4719 static enum print_stop_action
4720 print_it_catch_exec (struct breakpoint
*b
)
4722 annotate_catchpoint (b
->number
);
4723 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4725 return PRINT_SRC_AND_LOC
;
4729 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4731 struct value_print_options opts
;
4733 get_user_print_options (&opts
);
4735 /* Field 4, the address, is omitted (which makes the columns
4736 not line up too nicely with the headers, but the effect
4737 is relatively readable). */
4738 if (opts
.addressprint
)
4739 ui_out_field_skip (uiout
, "addr");
4741 ui_out_text (uiout
, "exec");
4742 if (b
->exec_pathname
!= NULL
)
4744 ui_out_text (uiout
, ", program \"");
4745 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4746 ui_out_text (uiout
, "\" ");
4751 print_mention_catch_exec (struct breakpoint
*b
)
4753 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4756 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4760 breakpoint_hit_catch_exec
,
4761 print_it_catch_exec
,
4762 print_one_catch_exec
,
4763 print_mention_catch_exec
4767 hw_breakpoint_used_count (void)
4769 struct breakpoint
*b
;
4774 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4782 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4784 struct breakpoint
*b
;
4787 *other_type_used
= 0;
4790 if (breakpoint_enabled (b
))
4792 if (b
->type
== type
)
4794 else if ((b
->type
== bp_hardware_watchpoint
||
4795 b
->type
== bp_read_watchpoint
||
4796 b
->type
== bp_access_watchpoint
))
4797 *other_type_used
= 1;
4804 disable_watchpoints_before_interactive_call_start (void)
4806 struct breakpoint
*b
;
4810 if (((b
->type
== bp_watchpoint
)
4811 || (b
->type
== bp_hardware_watchpoint
)
4812 || (b
->type
== bp_read_watchpoint
)
4813 || (b
->type
== bp_access_watchpoint
))
4814 && breakpoint_enabled (b
))
4816 b
->enable_state
= bp_call_disabled
;
4817 update_global_location_list (0);
4823 enable_watchpoints_after_interactive_call_stop (void)
4825 struct breakpoint
*b
;
4829 if (((b
->type
== bp_watchpoint
)
4830 || (b
->type
== bp_hardware_watchpoint
)
4831 || (b
->type
== bp_read_watchpoint
)
4832 || (b
->type
== bp_access_watchpoint
))
4833 && (b
->enable_state
== bp_call_disabled
))
4835 b
->enable_state
= bp_enabled
;
4836 update_global_location_list (1);
4842 /* Set a breakpoint that will evaporate an end of command
4843 at address specified by SAL.
4844 Restrict it to frame FRAME if FRAME is nonzero. */
4847 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4850 struct breakpoint
*b
;
4851 b
= set_raw_breakpoint (sal
, type
);
4852 b
->enable_state
= bp_enabled
;
4853 b
->disposition
= disp_donttouch
;
4854 b
->frame_id
= frame_id
;
4856 /* If we're debugging a multi-threaded program, then we
4857 want momentary breakpoints to be active in only a
4858 single thread of control. */
4859 if (in_thread_list (inferior_ptid
))
4860 b
->thread
= pid_to_thread_id (inferior_ptid
);
4862 update_global_location_list_nothrow (1);
4868 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4870 struct symtab_and_line sal
;
4872 sal
= find_pc_line (pc
, 0);
4874 sal
.section
= find_pc_overlay (pc
);
4875 sal
.explicit_pc
= 1;
4877 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4881 /* Tell the user we have just set a breakpoint B. */
4884 mention (struct breakpoint
*b
)
4887 struct cleanup
*old_chain
, *ui_out_chain
;
4888 struct ui_stream
*stb
;
4889 struct value_print_options opts
;
4891 get_user_print_options (&opts
);
4893 stb
= ui_out_stream_new (uiout
);
4894 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4896 /* FIXME: This is misplaced; mention() is called by things (like
4897 hitting a watchpoint) other than breakpoint creation. It should
4898 be possible to clean this up and at the same time replace the
4899 random calls to breakpoint_changed with this hook. */
4900 observer_notify_breakpoint_created (b
->number
);
4902 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4903 b
->ops
->print_mention (b
);
4908 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4911 ui_out_text (uiout
, "Watchpoint ");
4912 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4913 ui_out_field_int (uiout
, "number", b
->number
);
4914 ui_out_text (uiout
, ": ");
4915 print_expression (b
->exp
, stb
->stream
);
4916 ui_out_field_stream (uiout
, "exp", stb
);
4917 do_cleanups (ui_out_chain
);
4919 case bp_hardware_watchpoint
:
4920 ui_out_text (uiout
, "Hardware watchpoint ");
4921 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4922 ui_out_field_int (uiout
, "number", b
->number
);
4923 ui_out_text (uiout
, ": ");
4924 print_expression (b
->exp
, stb
->stream
);
4925 ui_out_field_stream (uiout
, "exp", stb
);
4926 do_cleanups (ui_out_chain
);
4928 case bp_read_watchpoint
:
4929 ui_out_text (uiout
, "Hardware read watchpoint ");
4930 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4931 ui_out_field_int (uiout
, "number", b
->number
);
4932 ui_out_text (uiout
, ": ");
4933 print_expression (b
->exp
, stb
->stream
);
4934 ui_out_field_stream (uiout
, "exp", stb
);
4935 do_cleanups (ui_out_chain
);
4937 case bp_access_watchpoint
:
4938 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4939 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4940 ui_out_field_int (uiout
, "number", b
->number
);
4941 ui_out_text (uiout
, ": ");
4942 print_expression (b
->exp
, stb
->stream
);
4943 ui_out_field_stream (uiout
, "exp", stb
);
4944 do_cleanups (ui_out_chain
);
4947 if (ui_out_is_mi_like_p (uiout
))
4952 if (b
->disposition
== disp_del
)
4953 printf_filtered (_("Temporary breakpoint"));
4955 printf_filtered (_("Breakpoint"));
4956 printf_filtered (_(" %d"), b
->number
);
4959 case bp_hardware_breakpoint
:
4960 if (ui_out_is_mi_like_p (uiout
))
4965 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4972 case bp_longjmp_resume
:
4973 case bp_step_resume
:
4975 case bp_watchpoint_scope
:
4976 case bp_shlib_event
:
4977 case bp_thread_event
:
4978 case bp_overlay_event
:
4984 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4988 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4992 if (opts
.addressprint
|| b
->source_file
== NULL
)
4994 printf_filtered (" at ");
4995 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4998 printf_filtered (": file %s, line %d.",
4999 b
->source_file
, b
->line_number
);
5003 struct bp_location
*loc
= b
->loc
;
5005 for (; loc
; loc
= loc
->next
)
5007 printf_filtered (" (%d locations)", n
);
5012 do_cleanups (old_chain
);
5013 if (ui_out_is_mi_like_p (uiout
))
5015 printf_filtered ("\n");
5019 static struct bp_location
*
5020 add_location_to_breakpoint (struct breakpoint
*b
,
5021 const struct symtab_and_line
*sal
)
5023 struct bp_location
*loc
, **tmp
;
5025 loc
= allocate_bp_location (b
);
5026 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5029 loc
->requested_address
= sal
->pc
;
5030 loc
->address
= adjust_breakpoint_address (loc
->requested_address
, b
->type
);
5031 loc
->section
= sal
->section
;
5033 set_breakpoint_location_function (loc
);
5038 /* Return 1 if LOC is pointing to a permanent breakpoint,
5039 return 0 otherwise. */
5042 bp_loc_is_permanent (struct bp_location
*loc
)
5046 const gdb_byte
*brk
;
5047 gdb_byte
*target_mem
;
5048 struct cleanup
*cleanup
;
5051 gdb_assert (loc
!= NULL
);
5053 addr
= loc
->address
;
5054 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5056 /* Software breakpoints unsupported? */
5060 target_mem
= alloca (len
);
5062 /* Enable the automatic memory restoration from breakpoints while
5063 we read the memory. Otherwise we could say about our temporary
5064 breakpoints they are permanent. */
5065 cleanup
= make_show_memory_breakpoints_cleanup (0);
5067 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5068 && memcmp (target_mem
, brk
, len
) == 0)
5071 do_cleanups (cleanup
);
5078 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5079 as textual description of the location, and COND_STRING
5080 as condition expression. */
5083 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5085 enum bptype type
, enum bpdisp disposition
,
5086 int thread
, int ignore_count
,
5087 struct breakpoint_ops
*ops
, int from_tty
)
5089 struct breakpoint
*b
= NULL
;
5092 if (type
== bp_hardware_breakpoint
)
5094 int i
= hw_breakpoint_used_count ();
5095 int target_resources_ok
=
5096 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5098 if (target_resources_ok
== 0)
5099 error (_("No hardware breakpoint support in the target."));
5100 else if (target_resources_ok
< 0)
5101 error (_("Hardware breakpoints used exceeds limit."));
5104 for (i
= 0; i
< sals
.nelts
; ++i
)
5106 struct symtab_and_line sal
= sals
.sals
[i
];
5107 struct bp_location
*loc
;
5110 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5114 b
= set_raw_breakpoint (sal
, type
);
5115 set_breakpoint_count (breakpoint_count
+ 1);
5116 b
->number
= breakpoint_count
;
5119 b
->cond_string
= cond_string
;
5120 b
->ignore_count
= ignore_count
;
5121 b
->enable_state
= bp_enabled
;
5122 b
->disposition
= disposition
;
5128 loc
= add_location_to_breakpoint (b
, &sal
);
5131 if (bp_loc_is_permanent (loc
))
5132 make_breakpoint_permanent (b
);
5136 char *arg
= b
->cond_string
;
5137 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5139 error (_("Garbage %s follows condition"), arg
);
5144 b
->addr_string
= addr_string
;
5146 /* addr_string has to be used or breakpoint_re_set will delete
5148 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5154 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5155 elements to fill the void space. */
5156 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5158 int i
= index_to_remove
+1;
5159 int last_index
= sal
->nelts
-1;
5161 for (;i
<= last_index
; ++i
)
5162 sal
->sals
[i
-1] = sal
->sals
[i
];
5167 /* If appropriate, obtains all sals that correspond
5168 to the same file and line as SAL. This is done
5169 only if SAL does not have explicit PC and has
5170 line and file information. If we got just a single
5171 expanded sal, return the original.
5173 Otherwise, if SAL.explicit_line is not set, filter out
5174 all sals for which the name of enclosing function
5175 is different from SAL. This makes sure that if we have
5176 breakpoint originally set in template instantiation, say
5177 foo<int>(), we won't expand SAL to locations at the same
5178 line in all existing instantiations of 'foo'.
5181 struct symtabs_and_lines
5182 expand_line_sal_maybe (struct symtab_and_line sal
)
5184 struct symtabs_and_lines expanded
;
5185 CORE_ADDR original_pc
= sal
.pc
;
5186 char *original_function
= NULL
;
5190 /* If we have explicit pc, don't expand.
5191 If we have no line number, we can't expand. */
5192 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5195 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5196 expanded
.sals
[0] = sal
;
5201 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5203 expanded
= expand_line_sal (sal
);
5204 if (expanded
.nelts
== 1)
5206 /* We had one sal, we got one sal. Without futher
5207 processing, just return the original sal. */
5208 xfree (expanded
.sals
);
5210 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5211 sal
.pc
= original_pc
;
5212 expanded
.sals
[0] = sal
;
5216 if (!sal
.explicit_line
)
5218 CORE_ADDR func_addr
, func_end
;
5219 for (i
= 0; i
< expanded
.nelts
; ++i
)
5221 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5222 char *this_function
;
5223 if (find_pc_partial_function (pc
, &this_function
,
5224 &func_addr
, &func_end
))
5226 if (this_function
&&
5227 strcmp (this_function
, original_function
) != 0)
5229 remove_sal (&expanded
, i
);
5232 else if (func_addr
== pc
)
5234 /* We're at beginning of a function, and should
5236 struct symbol
*sym
= find_pc_function (pc
);
5238 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5241 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5248 if (expanded
.nelts
<= 1)
5250 /* This is un ugly workaround. If we get zero
5251 expanded sals then something is really wrong.
5252 Fix that by returnign the original sal. */
5253 xfree (expanded
.sals
);
5255 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5256 sal
.pc
= original_pc
;
5257 expanded
.sals
[0] = sal
;
5264 for (i
= 0; i
< expanded
.nelts
; ++i
)
5265 if (expanded
.sals
[i
].pc
== original_pc
)
5276 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5277 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5278 value. COND_STRING, if not NULL, specified the condition to be
5279 used for all breakpoints. Essentially the only case where
5280 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5281 function. In that case, it's still not possible to specify
5282 separate conditions for different overloaded functions, so
5283 we take just a single condition string.
5285 NOTE: If the function succeeds, the caller is expected to cleanup
5286 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5287 array contents). If the function fails (error() is called), the
5288 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5289 COND and SALS arrays and each of those arrays contents. */
5292 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5294 enum bptype type
, enum bpdisp disposition
,
5295 int thread
, int ignore_count
,
5296 struct breakpoint_ops
*ops
, int from_tty
)
5299 for (i
= 0; i
< sals
.nelts
; ++i
)
5301 struct symtabs_and_lines expanded
=
5302 expand_line_sal_maybe (sals
.sals
[i
]);
5304 create_breakpoint (expanded
, addr_string
[i
],
5305 cond_string
, type
, disposition
,
5306 thread
, ignore_count
, ops
, from_tty
);
5309 update_global_location_list (1);
5312 /* Parse ARG which is assumed to be a SAL specification possibly
5313 followed by conditionals. On return, SALS contains an array of SAL
5314 addresses found. ADDR_STRING contains a vector of (canonical)
5315 address strings. ARG points to the end of the SAL. */
5318 parse_breakpoint_sals (char **address
,
5319 struct symtabs_and_lines
*sals
,
5320 char ***addr_string
,
5323 char *addr_start
= *address
;
5324 *addr_string
= NULL
;
5325 /* If no arg given, or if first arg is 'if ', use the default
5327 if ((*address
) == NULL
5328 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5330 if (default_breakpoint_valid
)
5332 struct symtab_and_line sal
;
5333 init_sal (&sal
); /* initialize to zeroes */
5334 sals
->sals
= (struct symtab_and_line
*)
5335 xmalloc (sizeof (struct symtab_and_line
));
5336 sal
.pc
= default_breakpoint_address
;
5337 sal
.line
= default_breakpoint_line
;
5338 sal
.symtab
= default_breakpoint_symtab
;
5339 sal
.section
= find_pc_overlay (sal
.pc
);
5340 sals
->sals
[0] = sal
;
5344 error (_("No default breakpoint address now."));
5348 /* Force almost all breakpoints to be in terms of the
5349 current_source_symtab (which is decode_line_1's default). This
5350 should produce the results we want almost all of the time while
5351 leaving default_breakpoint_* alone.
5352 ObjC: However, don't match an Objective-C method name which
5353 may have a '+' or '-' succeeded by a '[' */
5355 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5357 if (default_breakpoint_valid
5359 || ((strchr ("+-", (*address
)[0]) != NULL
)
5360 && ((*address
)[1] != '['))))
5361 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5362 default_breakpoint_line
, addr_string
,
5365 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5366 addr_string
, not_found_ptr
);
5368 /* For any SAL that didn't have a canonical string, fill one in. */
5369 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5370 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5371 if (addr_start
!= (*address
))
5374 for (i
= 0; i
< sals
->nelts
; i
++)
5376 /* Add the string if not present. */
5377 if ((*addr_string
)[i
] == NULL
)
5378 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5384 /* Convert each SAL into a real PC. Verify that the PC can be
5385 inserted as a breakpoint. If it can't throw an error. */
5388 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5392 for (i
= 0; i
< sals
->nelts
; i
++)
5393 resolve_sal_pc (&sals
->sals
[i
]);
5397 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5399 struct captured_parse_breakpoint_args
*args
= data
;
5401 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5402 args
->not_found_ptr
);
5405 /* Given TOK, a string specification of condition and thread, as
5406 accepted by the 'break' command, extract the condition
5407 string and thread number and set *COND_STRING and *THREAD.
5408 PC identifies the context at which the condition should be parsed.
5409 If no condition is found, *COND_STRING is set to NULL.
5410 If no thread is found, *THREAD is set to -1. */
5412 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5413 char **cond_string
, int *thread
)
5415 *cond_string
= NULL
;
5421 char *cond_start
= NULL
;
5422 char *cond_end
= NULL
;
5423 while (*tok
== ' ' || *tok
== '\t')
5428 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5431 toklen
= end_tok
- tok
;
5433 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5435 tok
= cond_start
= end_tok
+ 1;
5436 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5438 *cond_string
= savestring (cond_start
,
5439 cond_end
- cond_start
);
5441 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5447 *thread
= strtol (tok
, &tok
, 0);
5449 error (_("Junk after thread keyword."));
5450 if (!valid_thread_id (*thread
))
5451 error (_("Unknown thread %d."), *thread
);
5454 error (_("Junk at end of arguments."));
5458 /* Set a breakpoint. This function is shared between
5459 CLI and MI functions for setting a breakpoint.
5460 This function has two major modes of operations,
5461 selected by the PARSE_CONDITION_AND_THREAD parameter.
5462 If non-zero, the function will parse arg, extracting
5463 breakpoint location, address and thread. Otherwise,
5464 ARG is just the location of breakpoint, with condition
5465 and thread specified by the COND_STRING and THREAD
5469 break_command_really (char *arg
, char *cond_string
, int thread
,
5470 int parse_condition_and_thread
,
5471 int tempflag
, int hardwareflag
,
5473 enum auto_boolean pending_break_support
,
5474 struct breakpoint_ops
*ops
,
5477 struct gdb_exception e
;
5478 struct symtabs_and_lines sals
;
5479 struct symtab_and_line pending_sal
;
5482 char *addr_start
= arg
;
5484 struct cleanup
*old_chain
;
5485 struct cleanup
*breakpoint_chain
= NULL
;
5486 struct captured_parse_breakpoint_args parse_args
;
5495 parse_args
.arg_p
= &arg
;
5496 parse_args
.sals_p
= &sals
;
5497 parse_args
.addr_string_p
= &addr_string
;
5498 parse_args
.not_found_ptr
= ¬_found
;
5500 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5501 &parse_args
, RETURN_MASK_ALL
);
5503 /* If caller is interested in rc value from parse, set value. */
5507 throw_exception (e
);
5511 case NOT_FOUND_ERROR
:
5513 /* If pending breakpoint support is turned off, throw
5516 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5517 throw_exception (e
);
5519 exception_print (gdb_stderr
, e
);
5521 /* If pending breakpoint support is auto query and the user
5522 selects no, then simply return the error code. */
5523 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5524 !nquery ("Make breakpoint pending on future shared library load? "))
5527 /* At this point, either the user was queried about setting
5528 a pending breakpoint and selected yes, or pending
5529 breakpoint behavior is on and thus a pending breakpoint
5530 is defaulted on behalf of the user. */
5531 copy_arg
= xstrdup (addr_start
);
5532 addr_string
= ©_arg
;
5534 sals
.sals
= &pending_sal
;
5539 throw_exception (e
);
5546 /* Create a chain of things that always need to be cleaned up. */
5547 old_chain
= make_cleanup (null_cleanup
, 0);
5551 /* Make sure that all storage allocated to SALS gets freed. */
5552 make_cleanup (xfree
, sals
.sals
);
5554 /* Cleanup the addr_string array but not its contents. */
5555 make_cleanup (xfree
, addr_string
);
5558 /* ----------------------------- SNIP -----------------------------
5559 Anything added to the cleanup chain beyond this point is assumed
5560 to be part of a breakpoint. If the breakpoint create succeeds
5561 then the memory is not reclaimed. */
5562 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5564 /* Mark the contents of the addr_string for cleanup. These go on
5565 the breakpoint_chain and only occure if the breakpoint create
5567 for (i
= 0; i
< sals
.nelts
; i
++)
5569 if (addr_string
[i
] != NULL
)
5570 make_cleanup (xfree
, addr_string
[i
]);
5573 /* Resolve all line numbers to PC's and verify that the addresses
5574 are ok for the target. */
5576 breakpoint_sals_to_pc (&sals
, addr_start
);
5578 /* Verify that condition can be parsed, before setting any
5579 breakpoints. Allocate a separate condition expression for each
5583 if (parse_condition_and_thread
)
5585 /* Here we only parse 'arg' to separate condition
5586 from thread number, so parsing in context of first
5587 sal is OK. When setting the breakpoint we'll
5588 re-parse it in context of each sal. */
5591 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5593 make_cleanup (xfree
, cond_string
);
5597 /* Create a private copy of condition string. */
5600 cond_string
= xstrdup (cond_string
);
5601 make_cleanup (xfree
, cond_string
);
5604 create_breakpoints (sals
, addr_string
, cond_string
,
5605 hardwareflag
? bp_hardware_breakpoint
5607 tempflag
? disp_del
: disp_donttouch
,
5608 thread
, ignore_count
, ops
, from_tty
);
5612 struct symtab_and_line sal
= {0};
5613 struct breakpoint
*b
;
5615 make_cleanup (xfree
, copy_arg
);
5617 b
= set_raw_breakpoint_without_location (hardwareflag
5618 ? bp_hardware_breakpoint
5620 set_breakpoint_count (breakpoint_count
+ 1);
5621 b
->number
= breakpoint_count
;
5623 b
->addr_string
= addr_string
[0];
5624 b
->cond_string
= NULL
;
5625 b
->ignore_count
= ignore_count
;
5626 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5627 b
->condition_not_parsed
= 1;
5630 update_global_location_list (1);
5635 warning (_("Multiple breakpoints were set.\n"
5636 "Use the \"delete\" command to delete unwanted breakpoints."));
5637 /* That's it. Discard the cleanups for data inserted into the
5639 discard_cleanups (breakpoint_chain
);
5640 /* But cleanup everything else. */
5641 do_cleanups (old_chain
);
5644 /* Set a breakpoint.
5645 ARG is a string describing breakpoint address,
5646 condition, and thread.
5647 FLAG specifies if a breakpoint is hardware on,
5648 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5652 break_command_1 (char *arg
, int flag
, int from_tty
)
5654 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5655 int tempflag
= flag
& BP_TEMPFLAG
;
5657 break_command_really (arg
,
5658 NULL
, 0, 1 /* parse arg */,
5659 tempflag
, hardwareflag
,
5660 0 /* Ignore count */,
5661 pending_break_support
,
5662 NULL
/* breakpoint_ops */,
5668 set_breakpoint (char *address
, char *condition
,
5669 int hardwareflag
, int tempflag
,
5670 int thread
, int ignore_count
,
5673 break_command_really (address
, condition
, thread
,
5674 0 /* condition and thread are valid. */,
5675 tempflag
, hardwareflag
,
5678 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5682 /* Adjust SAL to the first instruction past the function prologue.
5683 The end of the prologue is determined using the line table from
5684 the debugging information.
5686 If SAL is already past the prologue, then do nothing. */
5689 skip_prologue_sal (struct symtab_and_line
*sal
)
5691 struct symbol
*sym
= find_pc_function (sal
->pc
);
5692 struct symtab_and_line start_sal
;
5697 start_sal
= find_function_start_sal (sym
, 1);
5698 if (sal
->pc
< start_sal
.pc
)
5702 /* Helper function for break_command_1 and disassemble_command. */
5705 resolve_sal_pc (struct symtab_and_line
*sal
)
5709 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5711 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5712 error (_("No line %d in file \"%s\"."),
5713 sal
->line
, sal
->symtab
->filename
);
5716 /* If this SAL corresponds to a breakpoint inserted using
5717 a line number, then skip the function prologue if necessary. */
5718 if (sal
->explicit_line
)
5719 skip_prologue_sal (sal
);
5722 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5724 struct blockvector
*bv
;
5728 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5731 sym
= block_linkage_function (b
);
5734 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5735 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5739 /* It really is worthwhile to have the section, so we'll just
5740 have to look harder. This case can be executed if we have
5741 line numbers but no functions (as can happen in assembly
5744 struct minimal_symbol
*msym
;
5746 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5748 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5755 break_command (char *arg
, int from_tty
)
5757 break_command_1 (arg
, 0, from_tty
);
5761 tbreak_command (char *arg
, int from_tty
)
5763 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5767 hbreak_command (char *arg
, int from_tty
)
5769 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5773 thbreak_command (char *arg
, int from_tty
)
5775 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5779 stop_command (char *arg
, int from_tty
)
5781 printf_filtered (_("Specify the type of breakpoint to set.\n\
5782 Usage: stop in <function | address>\n\
5783 stop at <line>\n"));
5787 stopin_command (char *arg
, int from_tty
)
5791 if (arg
== (char *) NULL
)
5793 else if (*arg
!= '*')
5798 /* look for a ':'. If this is a line number specification, then
5799 say it is bad, otherwise, it should be an address or
5800 function/method name */
5801 while (*argptr
&& !hasColon
)
5803 hasColon
= (*argptr
== ':');
5808 badInput
= (*argptr
!= ':'); /* Not a class::method */
5810 badInput
= isdigit (*arg
); /* a simple line number */
5814 printf_filtered (_("Usage: stop in <function | address>\n"));
5816 break_command_1 (arg
, 0, from_tty
);
5820 stopat_command (char *arg
, int from_tty
)
5824 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5831 /* look for a ':'. If there is a '::' then get out, otherwise
5832 it is probably a line number. */
5833 while (*argptr
&& !hasColon
)
5835 hasColon
= (*argptr
== ':');
5840 badInput
= (*argptr
== ':'); /* we have class::method */
5842 badInput
= !isdigit (*arg
); /* not a line number */
5846 printf_filtered (_("Usage: stop at <line>\n"));
5848 break_command_1 (arg
, 0, from_tty
);
5851 /* accessflag: hw_write: watch write,
5852 hw_read: watch read,
5853 hw_access: watch access (read or write) */
5855 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5857 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5858 struct symtab_and_line sal
;
5859 struct expression
*exp
;
5860 struct block
*exp_valid_block
;
5861 struct value
*val
, *mark
;
5862 struct frame_info
*frame
;
5863 struct frame_info
*prev_frame
= NULL
;
5864 char *exp_start
= NULL
;
5865 char *exp_end
= NULL
;
5866 char *tok
, *id_tok_start
, *end_tok
;
5868 char *cond_start
= NULL
;
5869 char *cond_end
= NULL
;
5870 struct expression
*cond
= NULL
;
5871 int i
, other_type_used
, target_resources_ok
= 0;
5872 enum bptype bp_type
;
5876 init_sal (&sal
); /* initialize to zeroes */
5878 /* Make sure that we actually have parameters to parse. */
5879 if (arg
!= NULL
&& arg
[0] != '\0')
5881 toklen
= strlen (arg
); /* Size of argument list. */
5883 /* Points tok to the end of the argument list. */
5884 tok
= arg
+ toklen
- 1;
5886 /* Go backwards in the parameters list. Skip the last parameter.
5887 If we're expecting a 'thread <thread_num>' parameter, this should
5888 be the thread identifier. */
5889 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5891 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5894 /* Points end_tok to the beginning of the last token. */
5895 id_tok_start
= tok
+ 1;
5897 /* Go backwards in the parameters list. Skip one more parameter.
5898 If we're expecting a 'thread <thread_num>' parameter, we should
5899 reach a "thread" token. */
5900 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5905 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5908 /* Move the pointer forward to skip the whitespace and
5909 calculate the length of the token. */
5911 toklen
= end_tok
- tok
;
5913 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5915 /* At this point we've found a "thread" token, which means
5916 the user is trying to set a watchpoint that triggers
5917 only in a specific thread. */
5920 /* Extract the thread ID from the next token. */
5921 thread
= strtol (id_tok_start
, &endp
, 0);
5923 /* Check if the user provided a valid numeric value for the
5925 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5926 error (_("Invalid thread ID specification %s."), id_tok_start
);
5928 /* Check if the thread actually exists. */
5929 if (!valid_thread_id (thread
))
5930 error (_("Unknown thread %d."), thread
);
5932 /* Truncate the string and get rid of the thread <thread_num>
5933 parameter before the parameter list is parsed by the
5934 evaluate_expression() function. */
5939 /* Parse the rest of the arguments. */
5940 innermost_block
= NULL
;
5942 exp
= parse_exp_1 (&arg
, 0, 0);
5944 exp_valid_block
= innermost_block
;
5945 mark
= value_mark ();
5946 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5948 release_value (val
);
5951 while (*tok
== ' ' || *tok
== '\t')
5955 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5958 toklen
= end_tok
- tok
;
5959 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5961 tok
= cond_start
= end_tok
+ 1;
5962 cond
= parse_exp_1 (&tok
, 0, 0);
5966 error (_("Junk at end of command."));
5968 if (accessflag
== hw_read
)
5969 bp_type
= bp_read_watchpoint
;
5970 else if (accessflag
== hw_access
)
5971 bp_type
= bp_access_watchpoint
;
5973 bp_type
= bp_hardware_watchpoint
;
5975 mem_cnt
= can_use_hardware_watchpoint (val
);
5976 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5977 error (_("Expression cannot be implemented with read/access watchpoint."));
5980 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5981 target_resources_ok
=
5982 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5984 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5985 error (_("Target does not support this type of hardware watchpoint."));
5987 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5988 error (_("Target can only support one kind of HW watchpoint at a time."));
5991 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5992 watchpoint could not be set. */
5993 if (!mem_cnt
|| target_resources_ok
<= 0)
5994 bp_type
= bp_watchpoint
;
5996 frame
= block_innermost_frame (exp_valid_block
);
5998 prev_frame
= get_prev_frame (frame
);
6002 /* If the expression is "local", then set up a "watchpoint scope"
6003 breakpoint at the point where we've left the scope of the watchpoint
6004 expression. Create the scope breakpoint before the watchpoint, so
6005 that we will encounter it first in bpstat_stop_status. */
6006 if (innermost_block
&& prev_frame
)
6008 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6009 bp_watchpoint_scope
);
6011 scope_breakpoint
->enable_state
= bp_enabled
;
6013 /* Automatically delete the breakpoint when it hits. */
6014 scope_breakpoint
->disposition
= disp_del
;
6016 /* Only break in the proper frame (help with recursion). */
6017 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6019 /* Set the address at which we will stop. */
6020 scope_breakpoint
->loc
->requested_address
6021 = get_frame_pc (prev_frame
);
6022 scope_breakpoint
->loc
->address
6023 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6024 scope_breakpoint
->type
);
6027 /* Now set up the breakpoint. */
6028 b
= set_raw_breakpoint (sal
, bp_type
);
6029 set_breakpoint_count (breakpoint_count
+ 1);
6030 b
->number
= breakpoint_count
;
6032 b
->disposition
= disp_donttouch
;
6034 b
->exp_valid_block
= exp_valid_block
;
6035 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6038 b
->loc
->cond
= cond
;
6040 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6045 b
->watchpoint_frame
= get_frame_id (frame
);
6047 b
->watchpoint_frame
= null_frame_id
;
6049 if (scope_breakpoint
!= NULL
)
6051 /* The scope breakpoint is related to the watchpoint. We will
6052 need to act on them together. */
6053 b
->related_breakpoint
= scope_breakpoint
;
6054 scope_breakpoint
->related_breakpoint
= b
;
6057 value_free_to_mark (mark
);
6059 update_global_location_list (1);
6062 /* Return count of locations need to be watched and can be handled
6063 in hardware. If the watchpoint can not be handled
6064 in hardware return zero. */
6067 can_use_hardware_watchpoint (struct value
*v
)
6069 int found_memory_cnt
= 0;
6070 struct value
*head
= v
;
6072 /* Did the user specifically forbid us to use hardware watchpoints? */
6073 if (!can_use_hw_watchpoints
)
6076 /* Make sure that the value of the expression depends only upon
6077 memory contents, and values computed from them within GDB. If we
6078 find any register references or function calls, we can't use a
6079 hardware watchpoint.
6081 The idea here is that evaluating an expression generates a series
6082 of values, one holding the value of every subexpression. (The
6083 expression a*b+c has five subexpressions: a, b, a*b, c, and
6084 a*b+c.) GDB's values hold almost enough information to establish
6085 the criteria given above --- they identify memory lvalues,
6086 register lvalues, computed values, etcetera. So we can evaluate
6087 the expression, and then scan the chain of values that leaves
6088 behind to decide whether we can detect any possible change to the
6089 expression's final value using only hardware watchpoints.
6091 However, I don't think that the values returned by inferior
6092 function calls are special in any way. So this function may not
6093 notice that an expression involving an inferior function call
6094 can't be watched with hardware watchpoints. FIXME. */
6095 for (; v
; v
= value_next (v
))
6097 if (VALUE_LVAL (v
) == lval_memory
)
6100 /* A lazy memory lvalue is one that GDB never needed to fetch;
6101 we either just used its address (e.g., `a' in `a.b') or
6102 we never needed it at all (e.g., `a' in `a,b'). */
6106 /* Ahh, memory we actually used! Check if we can cover
6107 it with hardware watchpoints. */
6108 struct type
*vtype
= check_typedef (value_type (v
));
6110 /* We only watch structs and arrays if user asked for it
6111 explicitly, never if they just happen to appear in a
6112 middle of some value chain. */
6114 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6115 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6117 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6118 int len
= TYPE_LENGTH (value_type (v
));
6120 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6127 else if (VALUE_LVAL (v
) != not_lval
6128 && deprecated_value_modifiable (v
) == 0)
6129 return 0; /* ??? What does this represent? */
6130 else if (VALUE_LVAL (v
) == lval_register
)
6131 return 0; /* cannot watch a register with a HW watchpoint */
6134 /* The expression itself looks suitable for using a hardware
6135 watchpoint, but give the target machine a chance to reject it. */
6136 return found_memory_cnt
;
6140 watch_command_wrapper (char *arg
, int from_tty
)
6142 watch_command (arg
, from_tty
);
6146 watch_command (char *arg
, int from_tty
)
6148 watch_command_1 (arg
, hw_write
, from_tty
);
6152 rwatch_command_wrapper (char *arg
, int from_tty
)
6154 rwatch_command (arg
, from_tty
);
6158 rwatch_command (char *arg
, int from_tty
)
6160 watch_command_1 (arg
, hw_read
, from_tty
);
6164 awatch_command_wrapper (char *arg
, int from_tty
)
6166 awatch_command (arg
, from_tty
);
6170 awatch_command (char *arg
, int from_tty
)
6172 watch_command_1 (arg
, hw_access
, from_tty
);
6176 /* Helper routines for the until_command routine in infcmd.c. Here
6177 because it uses the mechanisms of breakpoints. */
6179 struct until_break_command_continuation_args
6181 struct breakpoint
*breakpoint
;
6182 struct breakpoint
*breakpoint2
;
6185 /* This function is called by fetch_inferior_event via the
6186 cmd_continuation pointer, to complete the until command. It takes
6187 care of cleaning up the temporary breakpoints set up by the until
6190 until_break_command_continuation (void *arg
)
6192 struct until_break_command_continuation_args
*a
= arg
;
6194 delete_breakpoint (a
->breakpoint
);
6196 delete_breakpoint (a
->breakpoint2
);
6200 until_break_command (char *arg
, int from_tty
, int anywhere
)
6202 struct symtabs_and_lines sals
;
6203 struct symtab_and_line sal
;
6204 struct frame_info
*frame
= get_selected_frame (NULL
);
6205 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6206 struct breakpoint
*breakpoint
;
6207 struct breakpoint
*breakpoint2
= NULL
;
6208 struct cleanup
*old_chain
;
6210 clear_proceed_status ();
6212 /* Set a breakpoint where the user wants it and at return from
6215 if (default_breakpoint_valid
)
6216 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6217 default_breakpoint_line
, (char ***) NULL
, NULL
);
6219 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6220 0, (char ***) NULL
, NULL
);
6222 if (sals
.nelts
!= 1)
6223 error (_("Couldn't get information on specified line."));
6226 xfree (sals
.sals
); /* malloc'd, so freed */
6229 error (_("Junk at end of arguments."));
6231 resolve_sal_pc (&sal
);
6234 /* If the user told us to continue until a specified location,
6235 we don't specify a frame at which we need to stop. */
6236 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6238 /* Otherwise, specify the current frame, because we want to stop only
6239 at the very same frame. */
6240 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6243 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6245 /* Keep within the current frame, or in frames called by the current
6249 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6250 sal
.pc
= get_frame_pc (prev_frame
);
6251 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6253 make_cleanup_delete_breakpoint (breakpoint2
);
6256 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6258 /* If we are running asynchronously, and proceed call above has actually
6259 managed to start the target, arrange for breakpoints to be
6260 deleted when the target stops. Otherwise, we're already stopped and
6261 delete breakpoints via cleanup chain. */
6263 if (target_can_async_p () && is_running (inferior_ptid
))
6265 struct until_break_command_continuation_args
*args
;
6266 args
= xmalloc (sizeof (*args
));
6268 args
->breakpoint
= breakpoint
;
6269 args
->breakpoint2
= breakpoint2
;
6271 discard_cleanups (old_chain
);
6272 add_continuation (inferior_thread (),
6273 until_break_command_continuation
, args
,
6277 do_cleanups (old_chain
);
6281 ep_skip_leading_whitespace (char **s
)
6283 if ((s
== NULL
) || (*s
== NULL
))
6285 while (isspace (**s
))
6289 /* This function attempts to parse an optional "if <cond>" clause
6290 from the arg string. If one is not found, it returns NULL.
6292 Else, it returns a pointer to the condition string. (It does not
6293 attempt to evaluate the string against a particular block.) And,
6294 it updates arg to point to the first character following the parsed
6295 if clause in the arg string. */
6298 ep_parse_optional_if_clause (char **arg
)
6302 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6305 /* Skip the "if" keyword. */
6308 /* Skip any extra leading whitespace, and record the start of the
6309 condition string. */
6310 ep_skip_leading_whitespace (arg
);
6313 /* Assume that the condition occupies the remainder of the arg string. */
6314 (*arg
) += strlen (cond_string
);
6319 /* This function attempts to parse an optional filename from the arg
6320 string. If one is not found, it returns NULL.
6322 Else, it returns a pointer to the parsed filename. (This function
6323 makes no attempt to verify that a file of that name exists, or is
6324 accessible.) And, it updates arg to point to the first character
6325 following the parsed filename in the arg string.
6327 Note that clients needing to preserve the returned filename for
6328 future access should copy it to their own buffers. */
6330 ep_parse_optional_filename (char **arg
)
6332 static char filename
[1024];
6337 if ((*arg_p
== '\0') || isspace (*arg_p
))
6355 /* Commands to deal with catching events, such as signals, exceptions,
6356 process start/exit, etc. */
6360 catch_fork_temporary
, catch_vfork_temporary
,
6361 catch_fork_permanent
, catch_vfork_permanent
6366 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6368 char *cond_string
= NULL
;
6369 catch_fork_kind fork_kind
;
6372 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6373 tempflag
= (fork_kind
== catch_fork_temporary
6374 || fork_kind
== catch_vfork_temporary
);
6378 ep_skip_leading_whitespace (&arg
);
6380 /* The allowed syntax is:
6382 catch [v]fork if <cond>
6384 First, check if there's an if clause. */
6385 cond_string
= ep_parse_optional_if_clause (&arg
);
6387 if ((*arg
!= '\0') && !isspace (*arg
))
6388 error (_("Junk at end of arguments."));
6390 /* If this target supports it, create a fork or vfork catchpoint
6391 and enable reporting of such events. */
6394 case catch_fork_temporary
:
6395 case catch_fork_permanent
:
6396 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6397 &catch_fork_breakpoint_ops
);
6399 case catch_vfork_temporary
:
6400 case catch_vfork_permanent
:
6401 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6402 &catch_vfork_breakpoint_ops
);
6405 error (_("unsupported or unknown fork kind; cannot catch it"));
6411 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6414 char *cond_string
= NULL
;
6416 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6420 ep_skip_leading_whitespace (&arg
);
6422 /* The allowed syntax is:
6424 catch exec if <cond>
6426 First, check if there's an if clause. */
6427 cond_string
= ep_parse_optional_if_clause (&arg
);
6429 if ((*arg
!= '\0') && !isspace (*arg
))
6430 error (_("Junk at end of arguments."));
6432 /* If this target supports it, create an exec catchpoint
6433 and enable reporting of such events. */
6434 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6437 static enum print_stop_action
6438 print_exception_catchpoint (struct breakpoint
*b
)
6440 int bp_temp
, bp_throw
;
6442 annotate_catchpoint (b
->number
);
6444 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6445 if (b
->loc
->address
!= b
->loc
->requested_address
)
6446 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6449 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6451 bp_temp
? "Temporary catchpoint "
6453 if (!ui_out_is_mi_like_p (uiout
))
6454 ui_out_field_int (uiout
, "bkptno", b
->number
);
6456 bp_throw
? " (exception thrown), "
6457 : " (exception caught), ");
6458 if (ui_out_is_mi_like_p (uiout
))
6460 ui_out_field_string (uiout
, "reason",
6461 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6462 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6463 ui_out_field_int (uiout
, "bkptno", b
->number
);
6465 return PRINT_SRC_AND_LOC
;
6469 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6471 struct value_print_options opts
;
6472 get_user_print_options (&opts
);
6473 if (opts
.addressprint
)
6476 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6477 ui_out_field_string (uiout
, "addr", "<PENDING>");
6479 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6483 *last_addr
= b
->loc
->address
;
6484 if (strstr (b
->addr_string
, "throw") != NULL
)
6485 ui_out_field_string (uiout
, "what", "exception throw");
6487 ui_out_field_string (uiout
, "what", "exception catch");
6491 print_mention_exception_catchpoint (struct breakpoint
*b
)
6496 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6497 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6498 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6499 : _("Catchpoint "));
6500 ui_out_field_int (uiout
, "bkptno", b
->number
);
6501 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6505 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6508 NULL
, /* breakpoint_hit */
6509 print_exception_catchpoint
,
6510 print_one_exception_catchpoint
,
6511 print_mention_exception_catchpoint
6515 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6516 enum exception_event_kind ex_event
, int from_tty
)
6518 char *trigger_func_name
;
6520 if (ex_event
== EX_EVENT_CATCH
)
6521 trigger_func_name
= "__cxa_begin_catch";
6523 trigger_func_name
= "__cxa_throw";
6525 break_command_really (trigger_func_name
, cond_string
, -1,
6526 0 /* condition and thread are valid. */,
6529 AUTO_BOOLEAN_TRUE
/* pending */,
6530 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6535 /* Deal with "catch catch" and "catch throw" commands */
6538 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6539 int tempflag
, int from_tty
)
6541 char *cond_string
= NULL
;
6542 struct symtab_and_line
*sal
= NULL
;
6546 ep_skip_leading_whitespace (&arg
);
6548 cond_string
= ep_parse_optional_if_clause (&arg
);
6550 if ((*arg
!= '\0') && !isspace (*arg
))
6551 error (_("Junk at end of arguments."));
6553 if ((ex_event
!= EX_EVENT_THROW
) &&
6554 (ex_event
!= EX_EVENT_CATCH
))
6555 error (_("Unsupported or unknown exception event; cannot catch it"));
6557 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6560 warning (_("Unsupported with this platform/compiler combination."));
6563 /* Implementation of "catch catch" command. */
6566 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6568 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6569 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6572 /* Implementation of "catch throw" command. */
6575 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6577 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6578 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6581 /* Create a breakpoint struct for Ada exception catchpoints. */
6584 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6588 struct expression
*cond
,
6589 struct breakpoint_ops
*ops
,
6593 struct breakpoint
*b
;
6597 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6598 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6599 version for exception catchpoints, because two catchpoints
6600 used for different exception names will use the same address.
6601 In this case, a "breakpoint ... also set at..." warning is
6602 unproductive. Besides. the warning phrasing is also a bit
6603 inapropriate, we should use the word catchpoint, and tell
6604 the user what type of catchpoint it is. The above is good
6605 enough for now, though. */
6608 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6609 set_breakpoint_count (breakpoint_count
+ 1);
6611 b
->enable_state
= bp_enabled
;
6612 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6613 b
->number
= breakpoint_count
;
6614 b
->ignore_count
= 0;
6615 b
->loc
->cond
= cond
;
6616 b
->addr_string
= addr_string
;
6617 b
->language
= language_ada
;
6618 b
->cond_string
= cond_string
;
6619 b
->exp_string
= exp_string
;
6624 update_global_location_list (1);
6627 /* Implement the "catch exception" command. */
6630 catch_ada_exception_command (char *arg
, int from_tty
,
6631 struct cmd_list_element
*command
)
6634 struct symtab_and_line sal
;
6636 char *addr_string
= NULL
;
6637 char *exp_string
= NULL
;
6638 char *cond_string
= NULL
;
6639 struct expression
*cond
= NULL
;
6640 struct breakpoint_ops
*ops
= NULL
;
6642 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6646 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6647 &cond_string
, &cond
, &ops
);
6648 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6649 cond_string
, cond
, ops
, tempflag
,
6653 /* Implement the "catch assert" command. */
6656 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6659 struct symtab_and_line sal
;
6660 char *addr_string
= NULL
;
6661 struct breakpoint_ops
*ops
= NULL
;
6663 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6667 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6668 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6669 tempflag
, from_tty
);
6673 catch_command (char *arg
, int from_tty
)
6675 error (_("Catch requires an event name."));
6680 tcatch_command (char *arg
, int from_tty
)
6682 error (_("Catch requires an event name."));
6685 /* Delete breakpoints by address or line. */
6688 clear_command (char *arg
, int from_tty
)
6690 struct breakpoint
*b
;
6691 VEC(breakpoint_p
) *found
= 0;
6694 struct symtabs_and_lines sals
;
6695 struct symtab_and_line sal
;
6700 sals
= decode_line_spec (arg
, 1);
6705 sals
.sals
= (struct symtab_and_line
*)
6706 xmalloc (sizeof (struct symtab_and_line
));
6707 make_cleanup (xfree
, sals
.sals
);
6708 init_sal (&sal
); /* initialize to zeroes */
6709 sal
.line
= default_breakpoint_line
;
6710 sal
.symtab
= default_breakpoint_symtab
;
6711 sal
.pc
= default_breakpoint_address
;
6712 if (sal
.symtab
== 0)
6713 error (_("No source file specified."));
6721 /* We don't call resolve_sal_pc here. That's not
6722 as bad as it seems, because all existing breakpoints
6723 typically have both file/line and pc set. So, if
6724 clear is given file/line, we can match this to existing
6725 breakpoint without obtaining pc at all.
6727 We only support clearing given the address explicitly
6728 present in breakpoint table. Say, we've set breakpoint
6729 at file:line. There were several PC values for that file:line,
6730 due to optimization, all in one block.
6731 We've picked one PC value. If "clear" is issued with another
6732 PC corresponding to the same file:line, the breakpoint won't
6733 be cleared. We probably can still clear the breakpoint, but
6734 since the other PC value is never presented to user, user
6735 can only find it by guessing, and it does not seem important
6738 /* For each line spec given, delete bps which correspond
6739 to it. Do it in two passes, solely to preserve the current
6740 behavior that from_tty is forced true if we delete more than
6744 for (i
= 0; i
< sals
.nelts
; i
++)
6746 /* If exact pc given, clear bpts at that pc.
6747 If line given (pc == 0), clear all bpts on specified line.
6748 If defaulting, clear all bpts on default line
6751 defaulting sal.pc != 0 tests to do
6756 1 0 <can't happen> */
6760 /* Find all matching breakpoints and add them to
6765 /* Are we going to delete b? */
6766 if (b
->type
!= bp_none
6767 && b
->type
!= bp_watchpoint
6768 && b
->type
!= bp_hardware_watchpoint
6769 && b
->type
!= bp_read_watchpoint
6770 && b
->type
!= bp_access_watchpoint
)
6772 struct bp_location
*loc
= b
->loc
;
6773 for (; loc
; loc
= loc
->next
)
6775 int pc_match
= sal
.pc
6776 && (loc
->address
== sal
.pc
)
6777 && (!section_is_overlay (loc
->section
)
6778 || loc
->section
== sal
.section
);
6779 int line_match
= ((default_match
|| (0 == sal
.pc
))
6780 && b
->source_file
!= NULL
6781 && sal
.symtab
!= NULL
6782 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6783 && b
->line_number
== sal
.line
);
6784 if (pc_match
|| line_match
)
6793 VEC_safe_push(breakpoint_p
, found
, b
);
6796 /* Now go thru the 'found' chain and delete them. */
6797 if (VEC_empty(breakpoint_p
, found
))
6800 error (_("No breakpoint at %s."), arg
);
6802 error (_("No breakpoint at this line."));
6805 if (VEC_length(breakpoint_p
, found
) > 1)
6806 from_tty
= 1; /* Always report if deleted more than one */
6809 if (VEC_length(breakpoint_p
, found
) == 1)
6810 printf_unfiltered (_("Deleted breakpoint "));
6812 printf_unfiltered (_("Deleted breakpoints "));
6814 breakpoints_changed ();
6816 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6819 printf_unfiltered ("%d ", b
->number
);
6820 delete_breakpoint (b
);
6823 putchar_unfiltered ('\n');
6826 /* Delete breakpoint in BS if they are `delete' breakpoints and
6827 all breakpoints that are marked for deletion, whether hit or not.
6828 This is called after any breakpoint is hit, or after errors. */
6831 breakpoint_auto_delete (bpstat bs
)
6833 struct breakpoint
*b
, *temp
;
6835 for (; bs
; bs
= bs
->next
)
6836 if (bs
->breakpoint_at
6837 && bs
->breakpoint_at
->owner
6838 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6840 delete_breakpoint (bs
->breakpoint_at
->owner
);
6842 ALL_BREAKPOINTS_SAFE (b
, temp
)
6844 if (b
->disposition
== disp_del_at_next_stop
)
6845 delete_breakpoint (b
);
6849 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
6850 into the inferior, only remove already-inserted locations that no
6851 longer should be inserted. Functions that delete a breakpoint or
6852 breakpoints should pass false, so that deleting a breakpoint
6853 doesn't have the side effect of inserting the locations of other
6854 breakpoints that are marked not-inserted, but should_be_inserted
6855 returns true on them.
6857 This behaviour is useful is situations close to tear-down -- e.g.,
6858 after an exec, while the target still has execution, but breakpoint
6859 shadows of the previous executable image should *NOT* be restored
6860 to the new image; or before detaching, where the target still has
6861 execution and wants to delete breakpoints from GDB's lists, and all
6862 breakpoints had already been removed from the inferior. */
6865 update_global_location_list (int should_insert
)
6867 struct breakpoint
*b
;
6868 struct bp_location
**next
= &bp_location_chain
;
6869 struct bp_location
*loc
;
6870 struct bp_location
*loc2
;
6871 struct gdb_exception e
;
6872 VEC(bp_location_p
) *old_locations
= NULL
;
6876 /* Store old locations for future reference. */
6877 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6878 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6880 bp_location_chain
= NULL
;
6883 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6886 next
= &(loc
->global_next
);
6891 /* Identify bp_location instances that are no longer present in the new
6892 list, and therefore should be freed. Note that it's not necessary that
6893 those locations should be removed from inferior -- if there's another
6894 location at the same address (previously marked as duplicate),
6895 we don't need to remove/insert the location. */
6896 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6898 /* Tells if 'loc' is found amoung the new locations. If not, we
6900 int found_object
= 0;
6901 /* Tells if the location should remain inserted in the target. */
6902 int keep_in_target
= 0;
6904 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6911 /* If this location is no longer present, and inserted, look if there's
6912 maybe a new location at the same address. If so, mark that one
6913 inserted, and don't remove this one. This is needed so that we
6914 don't have a time window where a breakpoint at certain location is not
6919 /* If the location is inserted now, we might have to remove it. */
6921 if (found_object
&& should_be_inserted (loc
))
6923 /* The location is still present in the location list, and still
6924 should be inserted. Don't do anything. */
6929 /* The location is either no longer present, or got disabled.
6930 See if there's another location at the same address, in which
6931 case we don't need to remove this one from the target. */
6932 if (breakpoint_address_is_meaningful (loc
->owner
))
6933 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6935 /* For the sake of should_insert_location. The
6936 call to check_duplicates will fix up this later. */
6937 loc2
->duplicate
= 0;
6938 if (should_be_inserted (loc2
)
6939 && loc2
!= loc
&& loc2
->address
== loc
->address
)
6942 loc2
->target_info
= loc
->target_info
;
6949 if (!keep_in_target
)
6951 if (remove_breakpoint (loc
, mark_uninserted
))
6953 /* This is just about all we can do. We could keep this
6954 location on the global list, and try to remove it next
6955 time, but there's no particular reason why we will
6958 Note that at this point, loc->owner is still valid,
6959 as delete_breakpoint frees the breakpoint only
6960 after calling us. */
6961 printf_filtered (_("warning: Error removing breakpoint %d\n"),
6962 loc
->owner
->number
);
6970 if (removed
&& non_stop
)
6972 /* This location was removed from the targets. In non-stop mode,
6973 a race condition is possible where we've removed a breakpoint,
6974 but stop events for that breakpoint are already queued and will
6975 arrive later. To suppress spurious SIGTRAPs reported to user,
6976 we keep this breakpoint location for a bit, and will retire it
6977 after we see 3 * thread_count events.
6978 The theory here is that reporting of events should,
6979 "on the average", be fair, so after that many event we'll see
6980 events from all threads that have anything of interest, and no
6981 longer need to keep this breakpoint. This is just a
6982 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
6983 which is usability issue, but not a correctness problem. */
6984 loc
->events_till_retirement
= 3 * (thread_count () + 1);
6987 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
6990 free_bp_location (loc
);
6996 check_duplicates (b
);
6999 if (breakpoints_always_inserted_mode () && should_insert
7000 && (target_has_execution
7001 || (gdbarch_has_global_solist (target_gdbarch
)
7002 && target_supports_multi_process ())))
7003 insert_breakpoint_locations ();
7007 breakpoint_retire_moribund (void)
7009 struct bp_location
*loc
;
7012 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7013 if (--(loc
->events_till_retirement
) == 0)
7015 free_bp_location (loc
);
7016 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7022 update_global_location_list_nothrow (int inserting
)
7024 struct gdb_exception e
;
7025 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7026 update_global_location_list (inserting
);
7029 /* Clear BPT from a BPS. */
7031 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7034 for (bs
= bps
; bs
; bs
= bs
->next
)
7035 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7037 bs
->breakpoint_at
= NULL
;
7039 /* bs->commands will be freed later. */
7043 /* Callback for iterate_over_threads. */
7045 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7047 struct breakpoint
*bpt
= data
;
7048 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7052 /* Delete a breakpoint and clean up all traces of it in the data
7056 delete_breakpoint (struct breakpoint
*bpt
)
7058 struct breakpoint
*b
;
7059 struct bp_location
*loc
, *next
;
7061 gdb_assert (bpt
!= NULL
);
7063 /* Has this bp already been deleted? This can happen because multiple
7064 lists can hold pointers to bp's. bpstat lists are especial culprits.
7066 One example of this happening is a watchpoint's scope bp. When the
7067 scope bp triggers, we notice that the watchpoint is out of scope, and
7068 delete it. We also delete its scope bp. But the scope bp is marked
7069 "auto-deleting", and is already on a bpstat. That bpstat is then
7070 checked for auto-deleting bp's, which are deleted.
7072 A real solution to this problem might involve reference counts in bp's,
7073 and/or giving them pointers back to their referencing bpstat's, and
7074 teaching delete_breakpoint to only free a bp's storage when no more
7075 references were extent. A cheaper bandaid was chosen. */
7076 if (bpt
->type
== bp_none
)
7079 observer_notify_breakpoint_deleted (bpt
->number
);
7081 if (breakpoint_chain
== bpt
)
7082 breakpoint_chain
= bpt
->next
;
7087 b
->next
= bpt
->next
;
7091 free_command_lines (&bpt
->commands
);
7092 if (bpt
->cond_string
!= NULL
)
7093 xfree (bpt
->cond_string
);
7094 if (bpt
->addr_string
!= NULL
)
7095 xfree (bpt
->addr_string
);
7096 if (bpt
->exp
!= NULL
)
7098 if (bpt
->exp_string
!= NULL
)
7099 xfree (bpt
->exp_string
);
7100 if (bpt
->val
!= NULL
)
7101 value_free (bpt
->val
);
7102 if (bpt
->source_file
!= NULL
)
7103 xfree (bpt
->source_file
);
7104 if (bpt
->exec_pathname
!= NULL
)
7105 xfree (bpt
->exec_pathname
);
7107 /* Be sure no bpstat's are pointing at it after it's been freed. */
7108 /* FIXME, how can we find all bpstat's?
7109 We just check stop_bpstat for now. Note that we cannot just
7110 remove bpstats pointing at bpt from the stop_bpstat list
7111 entirely, as breakpoint commands are associated with the bpstat;
7112 if we remove it here, then the later call to
7113 bpstat_do_actions (&stop_bpstat);
7114 in event-top.c won't do anything, and temporary breakpoints
7115 with commands won't work. */
7117 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7119 /* Now that breakpoint is removed from breakpoint
7120 list, update the global location list. This
7121 will remove locations that used to belong to
7122 this breakpoint. Do this before freeing
7123 the breakpoint itself, since remove_breakpoint
7124 looks at location's owner. It might be better
7125 design to have location completely self-contained,
7126 but it's not the case now. */
7127 update_global_location_list (0);
7130 /* On the chance that someone will soon try again to delete this same
7131 bp, we mark it as deleted before freeing its storage. */
7132 bpt
->type
= bp_none
;
7138 do_delete_breakpoint_cleanup (void *b
)
7140 delete_breakpoint (b
);
7144 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7146 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7150 delete_command (char *arg
, int from_tty
)
7152 struct breakpoint
*b
, *temp
;
7158 int breaks_to_delete
= 0;
7160 /* Delete all breakpoints if no argument.
7161 Do not delete internal or call-dummy breakpoints, these
7162 have to be deleted with an explicit breakpoint number argument. */
7165 if (b
->type
!= bp_call_dummy
&&
7166 b
->type
!= bp_shlib_event
&&
7167 b
->type
!= bp_thread_event
&&
7168 b
->type
!= bp_overlay_event
&&
7171 breaks_to_delete
= 1;
7176 /* Ask user only if there are some breakpoints to delete. */
7178 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7180 ALL_BREAKPOINTS_SAFE (b
, temp
)
7182 if (b
->type
!= bp_call_dummy
&&
7183 b
->type
!= bp_shlib_event
&&
7184 b
->type
!= bp_thread_event
&&
7185 b
->type
!= bp_overlay_event
&&
7187 delete_breakpoint (b
);
7192 map_breakpoint_numbers (arg
, delete_breakpoint
);
7196 all_locations_are_pending (struct bp_location
*loc
)
7198 for (; loc
; loc
= loc
->next
)
7199 if (!loc
->shlib_disabled
)
7204 /* Subroutine of update_breakpoint_locations to simplify it.
7205 Return non-zero if multiple fns in list LOC have the same name.
7206 Null names are ignored. */
7209 ambiguous_names_p (struct bp_location
*loc
)
7211 struct bp_location
*l
;
7212 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7213 (int (*) (const void *, const void *)) streq
,
7214 NULL
, xcalloc
, xfree
);
7216 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7219 const char *name
= l
->function_name
;
7221 /* Allow for some names to be NULL, ignore them. */
7225 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7227 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7242 update_breakpoint_locations (struct breakpoint
*b
,
7243 struct symtabs_and_lines sals
)
7247 struct bp_location
*existing_locations
= b
->loc
;
7249 /* If there's no new locations, and all existing locations
7250 are pending, don't do anything. This optimizes
7251 the common case where all locations are in the same
7252 shared library, that was unloaded. We'd like to
7253 retain the location, so that when the library
7254 is loaded again, we don't loose the enabled/disabled
7255 status of the individual locations. */
7256 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7261 for (i
= 0; i
< sals
.nelts
; ++i
)
7263 struct bp_location
*new_loc
=
7264 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7266 /* Reparse conditions, they might contain references to the
7268 if (b
->cond_string
!= NULL
)
7270 struct gdb_exception e
;
7273 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7275 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7280 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7281 b
->number
, e
.message
);
7282 new_loc
->enabled
= 0;
7286 if (b
->source_file
!= NULL
)
7287 xfree (b
->source_file
);
7288 if (sals
.sals
[i
].symtab
== NULL
)
7289 b
->source_file
= NULL
;
7292 savestring (sals
.sals
[i
].symtab
->filename
,
7293 strlen (sals
.sals
[i
].symtab
->filename
));
7295 if (b
->line_number
== 0)
7296 b
->line_number
= sals
.sals
[i
].line
;
7299 /* Update locations of permanent breakpoints. */
7300 if (b
->enable_state
== bp_permanent
)
7301 make_breakpoint_permanent (b
);
7303 /* If possible, carry over 'disable' status from existing breakpoints. */
7305 struct bp_location
*e
= existing_locations
;
7306 /* If there are multiple breakpoints with the same function name,
7307 e.g. for inline functions, comparing function names won't work.
7308 Instead compare pc addresses; this is just a heuristic as things
7309 may have moved, but in practice it gives the correct answer
7310 often enough until a better solution is found. */
7311 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7313 for (; e
; e
= e
->next
)
7315 if (!e
->enabled
&& e
->function_name
)
7317 struct bp_location
*l
= b
->loc
;
7318 if (have_ambiguous_names
)
7320 for (; l
; l
= l
->next
)
7321 if (e
->address
== l
->address
)
7329 for (; l
; l
= l
->next
)
7330 if (l
->function_name
7331 && strcmp (e
->function_name
, l
->function_name
) == 0)
7341 update_global_location_list (1);
7345 /* Reset a breakpoint given it's struct breakpoint * BINT.
7346 The value we return ends up being the return value from catch_errors.
7347 Unused in this case. */
7350 breakpoint_re_set_one (void *bint
)
7352 /* get past catch_errs */
7353 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7357 int *not_found_ptr
= ¬_found
;
7358 struct symtabs_and_lines sals
= {};
7359 struct symtabs_and_lines expanded
;
7361 enum enable_state save_enable
;
7362 struct gdb_exception e
;
7368 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7372 case bp_hardware_breakpoint
:
7373 if (b
->addr_string
== NULL
)
7375 /* Anything without a string can't be re-set. */
7376 delete_breakpoint (b
);
7380 set_language (b
->language
);
7381 input_radix
= b
->input_radix
;
7383 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7385 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7390 int not_found_and_ok
= 0;
7391 /* For pending breakpoints, it's expected that parsing
7392 will fail until the right shared library is loaded.
7393 User has already told to create pending breakpoints and
7394 don't need extra messages. If breakpoint is in bp_shlib_disabled
7395 state, then user already saw the message about that breakpoint
7396 being disabled, and don't want to see more errors. */
7398 && (b
->condition_not_parsed
7399 || (b
->loc
&& b
->loc
->shlib_disabled
)
7400 || b
->enable_state
== bp_disabled
))
7401 not_found_and_ok
= 1;
7403 if (!not_found_and_ok
)
7405 /* We surely don't want to warn about the same breakpoint
7406 10 times. One solution, implemented here, is disable
7407 the breakpoint on error. Another solution would be to
7408 have separate 'warning emitted' flag. Since this
7409 happens only when a binary has changed, I don't know
7410 which approach is better. */
7411 b
->enable_state
= bp_disabled
;
7412 throw_exception (e
);
7419 gdb_assert (sals
.nelts
== 1);
7420 resolve_sal_pc (&sals
.sals
[0]);
7421 if (b
->condition_not_parsed
&& s
&& s
[0])
7423 char *cond_string
= 0;
7425 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7426 &cond_string
, &thread
);
7428 b
->cond_string
= cond_string
;
7430 b
->condition_not_parsed
= 0;
7432 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7433 update_breakpoint_locations (b
, expanded
);
7439 case bp_hardware_watchpoint
:
7440 case bp_read_watchpoint
:
7441 case bp_access_watchpoint
:
7442 /* Watchpoint can be either on expression using entirely global variables,
7443 or it can be on local variables.
7445 Watchpoints of the first kind are never auto-deleted, and even persist
7446 across program restarts. Since they can use variables from shared
7447 libraries, we need to reparse expression as libraries are loaded
7450 Watchpoints on local variables can also change meaning as result
7451 of solib event. For example, if a watchpoint uses both a local and
7452 a global variables in expression, it's a local watchpoint, but
7453 unloading of a shared library will make the expression invalid.
7454 This is not a very common use case, but we still re-evaluate
7455 expression, to avoid surprises to the user.
7457 Note that for local watchpoints, we re-evaluate it only if
7458 watchpoints frame id is still valid. If it's not, it means
7459 the watchpoint is out of scope and will be deleted soon. In fact,
7460 I'm not sure we'll ever be called in this case.
7462 If a local watchpoint's frame id is still valid, then
7463 b->exp_valid_block is likewise valid, and we can safely use it.
7465 Don't do anything about disabled watchpoints, since they will
7466 be reevaluated again when enabled. */
7467 update_watchpoint (b
, 1 /* reparse */);
7469 /* We needn't really do anything to reset these, since the mask
7470 that requests them is unaffected by e.g., new libraries being
7476 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7478 /* Delete overlay event breakpoints; they will be reset later by
7479 breakpoint_re_set. */
7480 case bp_overlay_event
:
7481 delete_breakpoint (b
);
7484 /* This breakpoint is special, it's set up when the inferior
7485 starts and we really don't want to touch it. */
7486 case bp_shlib_event
:
7488 /* Like bp_shlib_event, this breakpoint type is special.
7489 Once it is set up, we do not want to touch it. */
7490 case bp_thread_event
:
7492 /* Keep temporary breakpoints, which can be encountered when we step
7493 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7494 Otherwise these should have been blown away via the cleanup chain
7495 or by breakpoint_init_inferior when we rerun the executable. */
7498 case bp_watchpoint_scope
:
7500 case bp_step_resume
:
7502 case bp_longjmp_resume
:
7509 /* Re-set all breakpoints after symbols have been re-loaded. */
7511 breakpoint_re_set (void)
7513 struct breakpoint
*b
, *temp
;
7514 enum language save_language
;
7515 int save_input_radix
;
7517 save_language
= current_language
->la_language
;
7518 save_input_radix
= input_radix
;
7519 ALL_BREAKPOINTS_SAFE (b
, temp
)
7521 /* Format possible error msg */
7522 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7524 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7525 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7526 do_cleanups (cleanups
);
7528 set_language (save_language
);
7529 input_radix
= save_input_radix
;
7531 create_overlay_event_breakpoint ("_ovly_debug_event");
7534 /* Reset the thread number of this breakpoint:
7536 - If the breakpoint is for all threads, leave it as-is.
7537 - Else, reset it to the current thread for inferior_ptid. */
7539 breakpoint_re_set_thread (struct breakpoint
*b
)
7541 if (b
->thread
!= -1)
7543 if (in_thread_list (inferior_ptid
))
7544 b
->thread
= pid_to_thread_id (inferior_ptid
);
7548 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7549 If from_tty is nonzero, it prints a message to that effect,
7550 which ends with a period (no newline). */
7553 set_ignore_count (int bptnum
, int count
, int from_tty
)
7555 struct breakpoint
*b
;
7561 if (b
->number
== bptnum
)
7563 b
->ignore_count
= count
;
7567 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7569 else if (count
== 1)
7570 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7573 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7576 breakpoints_changed ();
7577 observer_notify_breakpoint_modified (b
->number
);
7581 error (_("No breakpoint number %d."), bptnum
);
7585 make_breakpoint_silent (struct breakpoint
*b
)
7587 /* Silence the breakpoint. */
7591 /* Command to set ignore-count of breakpoint N to COUNT. */
7594 ignore_command (char *args
, int from_tty
)
7600 error_no_arg (_("a breakpoint number"));
7602 num
= get_number (&p
);
7604 error (_("bad breakpoint number: '%s'"), args
);
7606 error (_("Second argument (specified ignore-count) is missing."));
7608 set_ignore_count (num
,
7609 longest_to_int (value_as_long (parse_and_eval (p
))),
7612 printf_filtered ("\n");
7615 /* Call FUNCTION on each of the breakpoints
7616 whose numbers are given in ARGS. */
7619 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7624 struct breakpoint
*b
, *tmp
;
7628 error_no_arg (_("one or more breakpoint numbers"));
7635 num
= get_number_or_range (&p1
);
7638 warning (_("bad breakpoint number at or near '%s'"), p
);
7642 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7643 if (b
->number
== num
)
7645 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7648 if (related_breakpoint
)
7649 function (related_breakpoint
);
7653 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7659 static struct bp_location
*
7660 find_location_by_number (char *number
)
7662 char *dot
= strchr (number
, '.');
7666 struct breakpoint
*b
;
7667 struct bp_location
*loc
;
7672 bp_num
= get_number_or_range (&p1
);
7674 error (_("Bad breakpoint number '%s'"), number
);
7677 if (b
->number
== bp_num
)
7682 if (!b
|| b
->number
!= bp_num
)
7683 error (_("Bad breakpoint number '%s'"), number
);
7686 loc_num
= get_number_or_range (&p1
);
7688 error (_("Bad breakpoint location number '%s'"), number
);
7692 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7695 error (_("Bad breakpoint location number '%s'"), dot
+1);
7701 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7702 If from_tty is nonzero, it prints a message to that effect,
7703 which ends with a period (no newline). */
7706 disable_breakpoint (struct breakpoint
*bpt
)
7708 /* Never disable a watchpoint scope breakpoint; we want to
7709 hit them when we leave scope so we can delete both the
7710 watchpoint and its scope breakpoint at that time. */
7711 if (bpt
->type
== bp_watchpoint_scope
)
7714 /* You can't disable permanent breakpoints. */
7715 if (bpt
->enable_state
== bp_permanent
)
7718 bpt
->enable_state
= bp_disabled
;
7720 update_global_location_list (0);
7722 observer_notify_breakpoint_modified (bpt
->number
);
7726 disable_command (char *args
, int from_tty
)
7728 struct breakpoint
*bpt
;
7730 ALL_BREAKPOINTS (bpt
)
7734 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7739 case bp_hardware_breakpoint
:
7741 case bp_hardware_watchpoint
:
7742 case bp_read_watchpoint
:
7743 case bp_access_watchpoint
:
7744 disable_breakpoint (bpt
);
7748 else if (strchr (args
, '.'))
7750 struct bp_location
*loc
= find_location_by_number (args
);
7753 update_global_location_list (0);
7756 map_breakpoint_numbers (args
, disable_breakpoint
);
7760 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7762 int target_resources_ok
, other_type_used
;
7765 if (bpt
->type
== bp_hardware_breakpoint
)
7768 i
= hw_breakpoint_used_count ();
7769 target_resources_ok
=
7770 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7772 if (target_resources_ok
== 0)
7773 error (_("No hardware breakpoint support in the target."));
7774 else if (target_resources_ok
< 0)
7775 error (_("Hardware breakpoints used exceeds limit."));
7778 if (bpt
->type
== bp_watchpoint
||
7779 bpt
->type
== bp_hardware_watchpoint
||
7780 bpt
->type
== bp_read_watchpoint
||
7781 bpt
->type
== bp_access_watchpoint
)
7783 struct frame_id saved_frame_id
;
7785 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7786 if (bpt
->exp_valid_block
!= NULL
)
7788 struct frame_info
*fr
=
7789 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7792 printf_filtered (_("\
7793 Cannot enable watchpoint %d because the block in which its expression\n\
7794 is valid is not currently in scope.\n"), bpt
->number
);
7801 value_free (bpt
->val
);
7802 mark
= value_mark ();
7803 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7805 release_value (bpt
->val
);
7808 if (bpt
->type
== bp_hardware_watchpoint
||
7809 bpt
->type
== bp_read_watchpoint
||
7810 bpt
->type
== bp_access_watchpoint
)
7812 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7813 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7815 /* Hack around 'unused var' error for some targets here */
7816 (void) mem_cnt
, (void) i
;
7817 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7818 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7819 /* we can consider of type is bp_hardware_watchpoint, convert to
7820 bp_watchpoint in the following condition */
7821 if (target_resources_ok
< 0)
7823 printf_filtered (_("\
7824 Cannot enable watchpoint %d because target watch resources\n\
7825 have been allocated for other watchpoints.\n"), bpt
->number
);
7826 value_free_to_mark (mark
);
7831 select_frame (frame_find_by_id (saved_frame_id
));
7832 value_free_to_mark (mark
);
7835 if (bpt
->enable_state
!= bp_permanent
)
7836 bpt
->enable_state
= bp_enabled
;
7837 bpt
->disposition
= disposition
;
7838 update_global_location_list (1);
7839 breakpoints_changed ();
7841 observer_notify_breakpoint_modified (bpt
->number
);
7846 enable_breakpoint (struct breakpoint
*bpt
)
7848 do_enable_breakpoint (bpt
, bpt
->disposition
);
7851 /* The enable command enables the specified breakpoints (or all defined
7852 breakpoints) so they once again become (or continue to be) effective
7853 in stopping the inferior. */
7856 enable_command (char *args
, int from_tty
)
7858 struct breakpoint
*bpt
;
7860 ALL_BREAKPOINTS (bpt
)
7864 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7869 case bp_hardware_breakpoint
:
7871 case bp_hardware_watchpoint
:
7872 case bp_read_watchpoint
:
7873 case bp_access_watchpoint
:
7874 enable_breakpoint (bpt
);
7878 else if (strchr (args
, '.'))
7880 struct bp_location
*loc
= find_location_by_number (args
);
7883 update_global_location_list (1);
7886 map_breakpoint_numbers (args
, enable_breakpoint
);
7890 enable_once_breakpoint (struct breakpoint
*bpt
)
7892 do_enable_breakpoint (bpt
, disp_disable
);
7896 enable_once_command (char *args
, int from_tty
)
7898 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7902 enable_delete_breakpoint (struct breakpoint
*bpt
)
7904 do_enable_breakpoint (bpt
, disp_del
);
7908 enable_delete_command (char *args
, int from_tty
)
7910 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7914 set_breakpoint_cmd (char *args
, int from_tty
)
7919 show_breakpoint_cmd (char *args
, int from_tty
)
7923 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7925 struct symtabs_and_lines
7926 decode_line_spec_1 (char *string
, int funfirstline
)
7928 struct symtabs_and_lines sals
;
7930 error (_("Empty line specification."));
7931 if (default_breakpoint_valid
)
7932 sals
= decode_line_1 (&string
, funfirstline
,
7933 default_breakpoint_symtab
,
7934 default_breakpoint_line
,
7935 (char ***) NULL
, NULL
);
7937 sals
= decode_line_1 (&string
, funfirstline
,
7938 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7940 error (_("Junk at end of line specification: %s"), string
);
7944 /* Create and insert a raw software breakpoint at PC. Return an
7945 identifier, which should be used to remove the breakpoint later.
7946 In general, places which call this should be using something on the
7947 breakpoint chain instead; this function should be eliminated
7951 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7953 struct bp_target_info
*bp_tgt
;
7955 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7956 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7958 bp_tgt
->placed_address
= pc
;
7959 if (target_insert_breakpoint (bp_tgt
) != 0)
7961 /* Could not insert the breakpoint. */
7969 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7972 deprecated_remove_raw_breakpoint (void *bp
)
7974 struct bp_target_info
*bp_tgt
= bp
;
7977 ret
= target_remove_breakpoint (bp_tgt
);
7983 /* One (or perhaps two) breakpoints used for software single stepping. */
7985 static void *single_step_breakpoints
[2];
7987 /* Create and insert a breakpoint for software single step. */
7990 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7994 if (single_step_breakpoints
[0] == NULL
)
7995 bpt_p
= &single_step_breakpoints
[0];
7998 gdb_assert (single_step_breakpoints
[1] == NULL
);
7999 bpt_p
= &single_step_breakpoints
[1];
8002 /* NOTE drow/2006-04-11: A future improvement to this function would be
8003 to only create the breakpoints once, and actually put them on the
8004 breakpoint chain. That would let us use set_raw_breakpoint. We could
8005 adjust the addresses each time they were needed. Doing this requires
8006 corresponding changes elsewhere where single step breakpoints are
8007 handled, however. So, for now, we use this. */
8009 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8011 error (_("Could not insert single-step breakpoint at 0x%s"),
8012 paddr_nz (next_pc
));
8015 /* Remove and delete any breakpoints used for software single step. */
8018 remove_single_step_breakpoints (void)
8020 gdb_assert (single_step_breakpoints
[0] != NULL
);
8022 /* See insert_single_step_breakpoint for more about this deprecated
8024 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8025 single_step_breakpoints
[0] = NULL
;
8027 if (single_step_breakpoints
[1] != NULL
)
8029 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8030 single_step_breakpoints
[1] = NULL
;
8034 /* Check whether a software single-step breakpoint is inserted at PC. */
8037 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8041 for (i
= 0; i
< 2; i
++)
8043 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8044 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8052 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8053 It is defined as a macro to prevent duplication.
8054 COMMAND should be a string constant containing the name of the command. */
8055 #define BREAK_ARGS_HELP(command) \
8056 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8057 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8058 If a line number is specified, break at start of code for that line.\n\
8059 If a function is specified, break at start of code for that function.\n\
8060 If an address is specified, break at that exact address.\n\
8061 With no LOCATION, uses current execution address of selected stack frame.\n\
8062 This is useful for breaking on return to a stack frame.\n\
8064 THREADNUM is the number from \"info threads\".\n\
8065 CONDITION is a boolean expression.\n\
8067 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8069 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8071 /* List of subcommands for "catch". */
8072 static struct cmd_list_element
*catch_cmdlist
;
8074 /* List of subcommands for "tcatch". */
8075 static struct cmd_list_element
*tcatch_cmdlist
;
8077 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8078 lists, and pass some additional user data to the command function. */
8080 add_catch_command (char *name
, char *docstring
,
8081 void (*sfunc
) (char *args
, int from_tty
,
8082 struct cmd_list_element
*command
),
8083 void *user_data_catch
,
8084 void *user_data_tcatch
)
8086 struct cmd_list_element
*command
;
8088 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8090 set_cmd_sfunc (command
, sfunc
);
8091 set_cmd_context (command
, user_data_catch
);
8093 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8095 set_cmd_sfunc (command
, sfunc
);
8096 set_cmd_context (command
, user_data_tcatch
);
8100 _initialize_breakpoint (void)
8102 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8103 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8104 struct cmd_list_element
*c
;
8106 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8108 breakpoint_chain
= 0;
8109 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8110 before a breakpoint is set. */
8111 breakpoint_count
= 0;
8113 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8114 Set ignore-count of breakpoint number N to COUNT.\n\
8115 Usage is `ignore N COUNT'."));
8117 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8119 add_com ("commands", class_breakpoint
, commands_command
, _("\
8120 Set commands to be executed when a breakpoint is hit.\n\
8121 Give breakpoint number as argument after \"commands\".\n\
8122 With no argument, the targeted breakpoint is the last one set.\n\
8123 The commands themselves follow starting on the next line.\n\
8124 Type a line containing \"end\" to indicate the end of them.\n\
8125 Give \"silent\" as the first line to make the breakpoint silent;\n\
8126 then no output is printed when it is hit, except what the commands print."));
8128 add_com ("condition", class_breakpoint
, condition_command
, _("\
8129 Specify breakpoint number N to break only if COND is true.\n\
8130 Usage is `condition N COND', where N is an integer and COND is an\n\
8131 expression to be evaluated whenever breakpoint N is reached."));
8133 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8134 Set a temporary breakpoint.\n\
8135 Like \"break\" except the breakpoint is only temporary,\n\
8136 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8137 by using \"enable delete\" on the breakpoint number.\n\
8139 BREAK_ARGS_HELP ("tbreak")));
8140 set_cmd_completer (c
, location_completer
);
8142 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8143 Set a hardware assisted breakpoint.\n\
8144 Like \"break\" except the breakpoint requires hardware support,\n\
8145 some target hardware may not have this support.\n\
8147 BREAK_ARGS_HELP ("hbreak")));
8148 set_cmd_completer (c
, location_completer
);
8150 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8151 Set a temporary hardware assisted breakpoint.\n\
8152 Like \"hbreak\" except the breakpoint is only temporary,\n\
8153 so it will be deleted when hit.\n\
8155 BREAK_ARGS_HELP ("thbreak")));
8156 set_cmd_completer (c
, location_completer
);
8158 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8159 Enable some breakpoints.\n\
8160 Give breakpoint numbers (separated by spaces) as arguments.\n\
8161 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8162 This is used to cancel the effect of the \"disable\" command.\n\
8163 With a subcommand you can enable temporarily."),
8164 &enablelist
, "enable ", 1, &cmdlist
);
8166 add_com ("ab", class_breakpoint
, enable_command
, _("\
8167 Enable some breakpoints.\n\
8168 Give breakpoint numbers (separated by spaces) as arguments.\n\
8169 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8170 This is used to cancel the effect of the \"disable\" command.\n\
8171 With a subcommand you can enable temporarily."));
8173 add_com_alias ("en", "enable", class_breakpoint
, 1);
8175 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8176 Enable some breakpoints.\n\
8177 Give breakpoint numbers (separated by spaces) as arguments.\n\
8178 This is used to cancel the effect of the \"disable\" command.\n\
8179 May be abbreviated to simply \"enable\".\n"),
8180 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8182 add_cmd ("once", no_class
, enable_once_command
, _("\
8183 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8184 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8187 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8188 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8189 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8192 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8193 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8194 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8197 add_cmd ("once", no_class
, enable_once_command
, _("\
8198 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8199 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8202 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8203 Disable some breakpoints.\n\
8204 Arguments are breakpoint numbers with spaces in between.\n\
8205 To disable all breakpoints, give no argument.\n\
8206 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8207 &disablelist
, "disable ", 1, &cmdlist
);
8208 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8209 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8211 add_com ("sb", class_breakpoint
, disable_command
, _("\
8212 Disable some breakpoints.\n\
8213 Arguments are breakpoint numbers with spaces in between.\n\
8214 To disable all breakpoints, give no argument.\n\
8215 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8217 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8218 Disable some breakpoints.\n\
8219 Arguments are breakpoint numbers with spaces in between.\n\
8220 To disable all breakpoints, give no argument.\n\
8221 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8222 This command may be abbreviated \"disable\"."),
8225 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8226 Delete some breakpoints or auto-display expressions.\n\
8227 Arguments are breakpoint numbers with spaces in between.\n\
8228 To delete all breakpoints, give no argument.\n\
8230 Also a prefix command for deletion of other GDB objects.\n\
8231 The \"unset\" command is also an alias for \"delete\"."),
8232 &deletelist
, "delete ", 1, &cmdlist
);
8233 add_com_alias ("d", "delete", class_breakpoint
, 1);
8234 add_com_alias ("del", "delete", class_breakpoint
, 1);
8236 add_com ("db", class_breakpoint
, delete_command
, _("\
8237 Delete some breakpoints.\n\
8238 Arguments are breakpoint numbers with spaces in between.\n\
8239 To delete all breakpoints, give no argument.\n"));
8241 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8242 Delete some breakpoints or auto-display expressions.\n\
8243 Arguments are breakpoint numbers with spaces in between.\n\
8244 To delete all breakpoints, give no argument.\n\
8245 This command may be abbreviated \"delete\"."),
8248 add_com ("clear", class_breakpoint
, clear_command
, _("\
8249 Clear breakpoint at specified line or function.\n\
8250 Argument may be line number, function name, or \"*\" and an address.\n\
8251 If line number is specified, all breakpoints in that line are cleared.\n\
8252 If function is specified, breakpoints at beginning of function are cleared.\n\
8253 If an address is specified, breakpoints at that address are cleared.\n\
8255 With no argument, clears all breakpoints in the line that the selected frame\n\
8258 See also the \"delete\" command which clears breakpoints by number."));
8260 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8261 Set breakpoint at specified line or function.\n"
8262 BREAK_ARGS_HELP ("break")));
8263 set_cmd_completer (c
, location_completer
);
8265 add_com_alias ("b", "break", class_run
, 1);
8266 add_com_alias ("br", "break", class_run
, 1);
8267 add_com_alias ("bre", "break", class_run
, 1);
8268 add_com_alias ("brea", "break", class_run
, 1);
8272 add_com_alias ("ba", "break", class_breakpoint
, 1);
8273 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8278 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8279 Break in function/address or break at a line in the current file."),
8280 &stoplist
, "stop ", 1, &cmdlist
);
8281 add_cmd ("in", class_breakpoint
, stopin_command
,
8282 _("Break in function or address."), &stoplist
);
8283 add_cmd ("at", class_breakpoint
, stopat_command
,
8284 _("Break at a line in the current file."), &stoplist
);
8285 add_com ("status", class_info
, breakpoints_info
, _("\
8286 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8287 The \"Type\" column indicates one of:\n\
8288 \tbreakpoint - normal breakpoint\n\
8289 \twatchpoint - watchpoint\n\
8290 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8291 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8292 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8293 address and file/line number respectively.\n\
8295 Convenience variable \"$_\" and default examine address for \"x\"\n\
8296 are set to the address of the last breakpoint listed unless the command\n\
8297 is prefixed with \"server \".\n\n\
8298 Convenience variable \"$bpnum\" contains the number of the last\n\
8302 add_info ("breakpoints", breakpoints_info
, _("\
8303 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8304 The \"Type\" column indicates one of:\n\
8305 \tbreakpoint - normal breakpoint\n\
8306 \twatchpoint - watchpoint\n\
8307 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8308 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8309 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8310 address and file/line number respectively.\n\
8312 Convenience variable \"$_\" and default examine address for \"x\"\n\
8313 are set to the address of the last breakpoint listed unless the command\n\
8314 is prefixed with \"server \".\n\n\
8315 Convenience variable \"$bpnum\" contains the number of the last\n\
8319 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8320 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8321 The \"Type\" column indicates one of:\n\
8322 \tbreakpoint - normal breakpoint\n\
8323 \twatchpoint - watchpoint\n\
8324 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8325 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8326 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8327 address and file/line number respectively.\n\
8329 Convenience variable \"$_\" and default examine address for \"x\"\n\
8330 are set to the address of the last breakpoint listed unless the command\n\
8331 is prefixed with \"server \".\n\n\
8332 Convenience variable \"$bpnum\" contains the number of the last\n\
8335 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8336 Status of all breakpoints, or breakpoint number NUMBER.\n\
8337 The \"Type\" column indicates one of:\n\
8338 \tbreakpoint - normal breakpoint\n\
8339 \twatchpoint - watchpoint\n\
8340 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8341 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8342 \tuntil - internal breakpoint used by the \"until\" command\n\
8343 \tfinish - internal breakpoint used by the \"finish\" command\n\
8344 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8345 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8346 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8347 address and file/line number respectively.\n\
8349 Convenience variable \"$_\" and default examine address for \"x\"\n\
8350 are set to the address of the last breakpoint listed unless the command\n\
8351 is prefixed with \"server \".\n\n\
8352 Convenience variable \"$bpnum\" contains the number of the last\n\
8354 &maintenanceinfolist
);
8356 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8357 Set catchpoints to catch events."),
8358 &catch_cmdlist
, "catch ",
8359 0/*allow-unknown*/, &cmdlist
);
8361 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8362 Set temporary catchpoints to catch events."),
8363 &tcatch_cmdlist
, "tcatch ",
8364 0/*allow-unknown*/, &cmdlist
);
8366 /* Add catch and tcatch sub-commands. */
8367 add_catch_command ("catch", _("\
8368 Catch an exception, when caught.\n\
8369 With an argument, catch only exceptions with the given name."),
8370 catch_catch_command
,
8373 add_catch_command ("throw", _("\
8374 Catch an exception, when thrown.\n\
8375 With an argument, catch only exceptions with the given name."),
8376 catch_throw_command
,
8379 add_catch_command ("fork", _("Catch calls to fork."),
8380 catch_fork_command_1
,
8381 (void *) (uintptr_t) catch_fork_permanent
,
8382 (void *) (uintptr_t) catch_fork_temporary
);
8383 add_catch_command ("vfork", _("Catch calls to vfork."),
8384 catch_fork_command_1
,
8385 (void *) (uintptr_t) catch_vfork_permanent
,
8386 (void *) (uintptr_t) catch_vfork_temporary
);
8387 add_catch_command ("exec", _("Catch calls to exec."),
8388 catch_exec_command_1
,
8391 add_catch_command ("exception", _("\
8392 Catch Ada exceptions, when raised.\n\
8393 With an argument, catch only exceptions with the given name."),
8394 catch_ada_exception_command
,
8397 add_catch_command ("assert", _("\
8398 Catch failed Ada assertions, when raised.\n\
8399 With an argument, catch only exceptions with the given name."),
8400 catch_assert_command
,
8404 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8405 Set a watchpoint for an expression.\n\
8406 A watchpoint stops execution of your program whenever the value of\n\
8407 an expression changes."));
8408 set_cmd_completer (c
, expression_completer
);
8410 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8411 Set a read watchpoint for an expression.\n\
8412 A watchpoint stops execution of your program whenever the value of\n\
8413 an expression is read."));
8414 set_cmd_completer (c
, expression_completer
);
8416 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8417 Set a watchpoint for an expression.\n\
8418 A watchpoint stops execution of your program whenever the value of\n\
8419 an expression is either read or written."));
8420 set_cmd_completer (c
, expression_completer
);
8422 add_info ("watchpoints", breakpoints_info
,
8423 _("Synonym for ``info breakpoints''."));
8426 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8427 respond to changes - contrary to the description. */
8428 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8429 &can_use_hw_watchpoints
, _("\
8430 Set debugger's willingness to use watchpoint hardware."), _("\
8431 Show debugger's willingness to use watchpoint hardware."), _("\
8432 If zero, gdb will not use hardware for new watchpoints, even if\n\
8433 such is available. (However, any hardware watchpoints that were\n\
8434 created before setting this to nonzero, will continue to use watchpoint\n\
8437 show_can_use_hw_watchpoints
,
8438 &setlist
, &showlist
);
8440 can_use_hw_watchpoints
= 1;
8442 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8443 Breakpoint specific settings\n\
8444 Configure various breakpoint-specific variables such as\n\
8445 pending breakpoint behavior"),
8446 &breakpoint_set_cmdlist
, "set breakpoint ",
8447 0/*allow-unknown*/, &setlist
);
8448 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8449 Breakpoint specific settings\n\
8450 Configure various breakpoint-specific variables such as\n\
8451 pending breakpoint behavior"),
8452 &breakpoint_show_cmdlist
, "show breakpoint ",
8453 0/*allow-unknown*/, &showlist
);
8455 add_setshow_auto_boolean_cmd ("pending", no_class
,
8456 &pending_break_support
, _("\
8457 Set debugger's behavior regarding pending breakpoints."), _("\
8458 Show debugger's behavior regarding pending breakpoints."), _("\
8459 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8460 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8461 an error. If auto, an unrecognized breakpoint location results in a\n\
8462 user-query to see if a pending breakpoint should be created."),
8464 show_pending_break_support
,
8465 &breakpoint_set_cmdlist
,
8466 &breakpoint_show_cmdlist
);
8468 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8470 add_setshow_boolean_cmd ("auto-hw", no_class
,
8471 &automatic_hardware_breakpoints
, _("\
8472 Set automatic usage of hardware breakpoints."), _("\
8473 Show automatic usage of hardware breakpoints."), _("\
8474 If set, the debugger will automatically use hardware breakpoints for\n\
8475 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8476 a warning will be emitted for such breakpoints."),
8478 show_automatic_hardware_breakpoints
,
8479 &breakpoint_set_cmdlist
,
8480 &breakpoint_show_cmdlist
);
8482 add_setshow_enum_cmd ("always-inserted", class_support
,
8483 always_inserted_enums
, &always_inserted_mode
, _("\
8484 Set mode for inserting breakpoints."), _("\
8485 Show mode for inserting breakpoints."), _("\
8486 When this mode is off, breakpoints are inserted in inferior when it is\n\
8487 resumed, and removed when execution stops. When this mode is on,\n\
8488 breakpoints are inserted immediately and removed only when the user\n\
8489 deletes the breakpoint. When this mode is auto (which is the default),\n\
8490 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8491 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8492 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8493 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8495 &show_always_inserted_mode
,
8496 &breakpoint_set_cmdlist
,
8497 &breakpoint_show_cmdlist
);
8499 automatic_hardware_breakpoints
= 1;