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 disposition is disp_del_at_next_stop, then do nothing.
839 If this is 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?\n",
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 struct cleanup
*cleanups
= 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
);
1355 do_cleanups (cleanups
);
1359 remove_breakpoints (void)
1361 struct bp_location
*b
;
1364 ALL_BP_LOCATIONS (b
)
1368 val
= remove_breakpoint (b
, mark_uninserted
);
1377 remove_hw_watchpoints (void)
1379 struct bp_location
*b
;
1382 ALL_BP_LOCATIONS (b
)
1384 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1386 val
= remove_breakpoint (b
, mark_uninserted
);
1395 reattach_breakpoints (int pid
)
1397 struct bp_location
*b
;
1399 struct cleanup
*old_chain
= save_inferior_ptid ();
1400 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1401 int dummy1
= 0, dummy2
= 0;
1403 make_cleanup_ui_file_delete (tmp_error_stream
);
1405 inferior_ptid
= pid_to_ptid (pid
);
1406 ALL_BP_LOCATIONS (b
)
1411 val
= insert_bp_location (b
, tmp_error_stream
,
1415 do_cleanups (old_chain
);
1420 do_cleanups (old_chain
);
1425 update_breakpoints_after_exec (void)
1427 struct breakpoint
*b
;
1428 struct breakpoint
*temp
;
1429 struct bp_location
*bploc
;
1431 /* We're about to delete breakpoints from GDB's lists. If the
1432 INSERTED flag is true, GDB will try to lift the breakpoints by
1433 writing the breakpoints' "shadow contents" back into memory. The
1434 "shadow contents" are NOT valid after an exec, so GDB should not
1435 do that. Instead, the target is responsible from marking
1436 breakpoints out as soon as it detects an exec. We don't do that
1437 here instead, because there may be other attempts to delete
1438 breakpoints after detecting an exec and before reaching here. */
1439 ALL_BP_LOCATIONS (bploc
)
1440 gdb_assert (!bploc
->inserted
);
1442 ALL_BREAKPOINTS_SAFE (b
, temp
)
1444 /* Solib breakpoints must be explicitly reset after an exec(). */
1445 if (b
->type
== bp_shlib_event
)
1447 delete_breakpoint (b
);
1451 /* Thread event breakpoints must be set anew after an exec(),
1452 as must overlay event breakpoints. */
1453 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1455 delete_breakpoint (b
);
1459 /* Step-resume breakpoints are meaningless after an exec(). */
1460 if (b
->type
== bp_step_resume
)
1462 delete_breakpoint (b
);
1466 /* Longjmp and longjmp-resume breakpoints are also meaningless
1468 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1470 delete_breakpoint (b
);
1474 if (b
->type
== bp_catchpoint
)
1476 /* For now, none of the bp_catchpoint breakpoints need to
1477 do anything at this point. In the future, if some of
1478 the catchpoints need to something, we will need to add
1479 a new method, and call this method from here. */
1483 /* bp_finish is a special case. The only way we ought to be able
1484 to see one of these when an exec() has happened, is if the user
1485 caught a vfork, and then said "finish". Ordinarily a finish just
1486 carries them to the call-site of the current callee, by setting
1487 a temporary bp there and resuming. But in this case, the finish
1488 will carry them entirely through the vfork & exec.
1490 We don't want to allow a bp_finish to remain inserted now. But
1491 we can't safely delete it, 'cause finish_command has a handle to
1492 the bp on a bpstat, and will later want to delete it. There's a
1493 chance (and I've seen it happen) that if we delete the bp_finish
1494 here, that its storage will get reused by the time finish_command
1495 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1496 We really must allow finish_command to delete a bp_finish.
1498 In the absense of a general solution for the "how do we know
1499 it's safe to delete something others may have handles to?"
1500 problem, what we'll do here is just uninsert the bp_finish, and
1501 let finish_command delete it.
1503 (We know the bp_finish is "doomed" in the sense that it's
1504 momentary, and will be deleted as soon as finish_command sees
1505 the inferior stopped. So it doesn't matter that the bp's
1506 address is probably bogus in the new a.out, unlike e.g., the
1507 solib breakpoints.) */
1509 if (b
->type
== bp_finish
)
1514 /* Without a symbolic address, we have little hope of the
1515 pre-exec() address meaning the same thing in the post-exec()
1517 if (b
->addr_string
== NULL
)
1519 delete_breakpoint (b
);
1523 /* FIXME what about longjmp breakpoints? Re-create them here? */
1524 create_overlay_event_breakpoint ("_ovly_debug_event");
1528 detach_breakpoints (int pid
)
1530 struct bp_location
*b
;
1532 struct cleanup
*old_chain
= save_inferior_ptid ();
1534 if (pid
== PIDGET (inferior_ptid
))
1535 error (_("Cannot detach breakpoints of inferior_ptid"));
1537 /* Set inferior_ptid; remove_breakpoint uses this global. */
1538 inferior_ptid
= pid_to_ptid (pid
);
1539 ALL_BP_LOCATIONS (b
)
1543 val
= remove_breakpoint (b
, mark_inserted
);
1546 do_cleanups (old_chain
);
1551 do_cleanups (old_chain
);
1556 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1560 if (b
->owner
->enable_state
== bp_permanent
)
1561 /* Permanent breakpoints cannot be inserted or removed. */
1564 /* The type of none suggests that owner is actually deleted.
1565 This should not ever happen. */
1566 gdb_assert (b
->owner
->type
!= bp_none
);
1568 if (b
->loc_type
== bp_loc_software_breakpoint
1569 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1571 /* "Normal" instruction breakpoint: either the standard
1572 trap-instruction bp (bp_breakpoint), or a
1573 bp_hardware_breakpoint. */
1575 /* First check to see if we have to handle an overlay. */
1576 if (overlay_debugging
== ovly_off
1577 || b
->section
== NULL
1578 || !(section_is_overlay (b
->section
)))
1580 /* No overlay handling: just remove the breakpoint. */
1582 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1583 val
= target_remove_hw_breakpoint (&b
->target_info
);
1585 val
= target_remove_breakpoint (&b
->target_info
);
1589 /* This breakpoint is in an overlay section.
1590 Did we set a breakpoint at the LMA? */
1591 if (!overlay_events_enabled
)
1593 /* Yes -- overlay event support is not active, so we
1594 should have set a breakpoint at the LMA. Remove it.
1596 /* Ignore any failures: if the LMA is in ROM, we will
1597 have already warned when we failed to insert it. */
1598 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1599 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1601 target_remove_breakpoint (&b
->overlay_target_info
);
1603 /* Did we set a breakpoint at the VMA?
1604 If so, we will have marked the breakpoint 'inserted'. */
1607 /* Yes -- remove it. Previously we did not bother to
1608 remove the breakpoint if the section had been
1609 unmapped, but let's not rely on that being safe. We
1610 don't know what the overlay manager might do. */
1611 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1612 val
= target_remove_hw_breakpoint (&b
->target_info
);
1614 /* However, we should remove *software* breakpoints only
1615 if the section is still mapped, or else we overwrite
1616 wrong code with the saved shadow contents. */
1617 else if (section_is_mapped (b
->section
))
1618 val
= target_remove_breakpoint (&b
->target_info
);
1624 /* No -- not inserted, so no need to remove. No error. */
1629 /* In some cases, we might not be able to remove a breakpoint
1630 in a shared library that has already been removed, but we
1631 have not yet processed the shlib unload event. */
1632 if (val
&& solib_address (b
->address
))
1637 b
->inserted
= (is
== mark_inserted
);
1639 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1644 b
->inserted
= (is
== mark_inserted
);
1645 val
= target_remove_watchpoint (b
->address
, b
->length
,
1646 b
->watchpoint_type
);
1648 /* Failure to remove any of the hardware watchpoints comes here. */
1649 if ((is
== mark_uninserted
) && (b
->inserted
))
1650 warning (_("Could not remove hardware watchpoint %d."),
1653 else if (b
->owner
->type
== bp_catchpoint
1654 && breakpoint_enabled (b
->owner
)
1657 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1659 val
= b
->owner
->ops
->remove (b
->owner
);
1662 b
->inserted
= (is
== mark_inserted
);
1668 /* Clear the "inserted" flag in all breakpoints. */
1671 mark_breakpoints_out (void)
1673 struct bp_location
*bpt
;
1675 ALL_BP_LOCATIONS (bpt
)
1679 /* Clear the "inserted" flag in all breakpoints and delete any
1680 breakpoints which should go away between runs of the program.
1682 Plus other such housekeeping that has to be done for breakpoints
1685 Note: this function gets called at the end of a run (by
1686 generic_mourn_inferior) and when a run begins (by
1687 init_wait_for_inferior). */
1692 breakpoint_init_inferior (enum inf_context context
)
1694 struct breakpoint
*b
, *temp
;
1695 struct bp_location
*bpt
;
1698 /* If breakpoint locations are shared across processes, then there's
1700 if (gdbarch_has_global_solist (target_gdbarch
))
1703 ALL_BP_LOCATIONS (bpt
)
1704 if (bpt
->owner
->enable_state
!= bp_permanent
)
1707 ALL_BREAKPOINTS_SAFE (b
, temp
)
1712 case bp_watchpoint_scope
:
1714 /* If the call dummy breakpoint is at the entry point it will
1715 cause problems when the inferior is rerun, so we better
1718 Also get rid of scope breakpoints. */
1719 delete_breakpoint (b
);
1723 case bp_hardware_watchpoint
:
1724 case bp_read_watchpoint
:
1725 case bp_access_watchpoint
:
1727 /* Likewise for watchpoints on local expressions. */
1728 if (b
->exp_valid_block
!= NULL
)
1729 delete_breakpoint (b
);
1730 else if (context
== inf_starting
)
1732 /* Reset val field to force reread of starting value
1733 in insert_breakpoints. */
1735 value_free (b
->val
);
1745 /* Get rid of the moribund locations. */
1746 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1747 free_bp_location (bpt
);
1748 VEC_free (bp_location_p
, moribund_locations
);
1751 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1752 exists at PC. It returns ordinary_breakpoint_here if it's an
1753 ordinary breakpoint, or permanent_breakpoint_here if it's a
1754 permanent breakpoint.
1755 - When continuing from a location with an ordinary breakpoint, we
1756 actually single step once before calling insert_breakpoints.
1757 - When continuing from a localion with a permanent breakpoint, we
1758 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1759 the target, to advance the PC past the breakpoint. */
1761 enum breakpoint_here
1762 breakpoint_here_p (CORE_ADDR pc
)
1764 const struct bp_location
*bpt
;
1765 int any_breakpoint_here
= 0;
1767 ALL_BP_LOCATIONS (bpt
)
1769 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1770 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1773 if ((breakpoint_enabled (bpt
->owner
)
1774 || bpt
->owner
->enable_state
== bp_permanent
)
1775 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1777 if (overlay_debugging
1778 && section_is_overlay (bpt
->section
)
1779 && !section_is_mapped (bpt
->section
))
1780 continue; /* unmapped overlay -- can't be a match */
1781 else if (bpt
->owner
->enable_state
== bp_permanent
)
1782 return permanent_breakpoint_here
;
1784 any_breakpoint_here
= 1;
1788 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1791 /* Return true if there's a moribund breakpoint at PC. */
1794 moribund_breakpoint_here_p (CORE_ADDR pc
)
1796 struct bp_location
*loc
;
1799 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1800 if (loc
->address
== pc
)
1806 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1807 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1808 This does not check for single-step breakpoints, which are
1809 inserted and removed using direct target manipulation. */
1812 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1814 const struct bp_location
*bpt
;
1816 ALL_BP_LOCATIONS (bpt
)
1818 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1819 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1823 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1825 if (overlay_debugging
1826 && section_is_overlay (bpt
->section
)
1827 && !section_is_mapped (bpt
->section
))
1828 continue; /* unmapped overlay -- can't be a match */
1836 /* Returns non-zero iff there's either regular breakpoint
1837 or a single step breakpoint inserted at PC. */
1840 breakpoint_inserted_here_p (CORE_ADDR pc
)
1842 if (regular_breakpoint_inserted_here_p (pc
))
1845 if (single_step_breakpoint_inserted_here_p (pc
))
1851 /* This function returns non-zero iff there is a software breakpoint
1855 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1857 const struct bp_location
*bpt
;
1858 int any_breakpoint_here
= 0;
1860 ALL_BP_LOCATIONS (bpt
)
1862 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1866 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1868 if (overlay_debugging
1869 && section_is_overlay (bpt
->section
)
1870 && !section_is_mapped (bpt
->section
))
1871 continue; /* unmapped overlay -- can't be a match */
1877 /* Also check for software single-step breakpoints. */
1878 if (single_step_breakpoint_inserted_here_p (pc
))
1884 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1885 PC is valid for process/thread PTID. */
1888 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1890 const struct bp_location
*bpt
;
1893 thread
= pid_to_thread_id (ptid
);
1895 ALL_BP_LOCATIONS (bpt
)
1897 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1898 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1901 if ((breakpoint_enabled (bpt
->owner
)
1902 || bpt
->owner
->enable_state
== bp_permanent
)
1903 && bpt
->address
== pc
1904 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1906 if (overlay_debugging
1907 && section_is_overlay (bpt
->section
)
1908 && !section_is_mapped (bpt
->section
))
1909 continue; /* unmapped overlay -- can't be a match */
1919 /* bpstat stuff. External routines' interfaces are documented
1923 ep_is_catchpoint (struct breakpoint
*ep
)
1925 return (ep
->type
== bp_catchpoint
);
1929 bpstat_free (bpstat bs
)
1931 if (bs
->old_val
!= NULL
)
1932 value_free (bs
->old_val
);
1933 free_command_lines (&bs
->commands
);
1937 /* Clear a bpstat so that it says we are not at any breakpoint.
1938 Also free any storage that is part of a bpstat. */
1941 bpstat_clear (bpstat
*bsp
)
1958 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1959 is part of the bpstat is copied as well. */
1962 bpstat_copy (bpstat bs
)
1966 bpstat retval
= NULL
;
1971 for (; bs
!= NULL
; bs
= bs
->next
)
1973 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1974 memcpy (tmp
, bs
, sizeof (*tmp
));
1975 if (bs
->commands
!= NULL
)
1976 tmp
->commands
= copy_command_lines (bs
->commands
);
1977 if (bs
->old_val
!= NULL
)
1979 tmp
->old_val
= value_copy (bs
->old_val
);
1980 release_value (tmp
->old_val
);
1984 /* This is the first thing in the chain. */
1994 /* Find the bpstat associated with this breakpoint */
1997 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2002 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2004 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2010 /* Find a step_resume breakpoint associated with this bpstat.
2011 (If there are multiple step_resume bp's on the list, this function
2012 will arbitrarily pick one.)
2014 It is an error to use this function if BPSTAT doesn't contain a
2015 step_resume breakpoint.
2017 See wait_for_inferior's use of this function. */
2019 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2023 gdb_assert (bsp
!= NULL
);
2025 current_thread
= pid_to_thread_id (inferior_ptid
);
2027 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2029 if ((bsp
->breakpoint_at
!= NULL
) &&
2030 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2031 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2032 bsp
->breakpoint_at
->owner
->thread
== -1))
2033 return bsp
->breakpoint_at
->owner
;
2036 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2040 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2041 at. *BSP upon return is a bpstat which points to the remaining
2042 breakpoints stopped at (but which is not guaranteed to be good for
2043 anything but further calls to bpstat_num).
2044 Return 0 if passed a bpstat which does not indicate any breakpoints.
2045 Return -1 if stopped at a breakpoint that has been deleted since
2047 Return 1 otherwise. */
2050 bpstat_num (bpstat
*bsp
, int *num
)
2052 struct breakpoint
*b
;
2055 return 0; /* No more breakpoint values */
2057 /* We assume we'll never have several bpstats that
2058 correspond to a single breakpoint -- otherwise,
2059 this function might return the same number more
2060 than once and this will look ugly. */
2061 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2062 *bsp
= (*bsp
)->next
;
2064 return -1; /* breakpoint that's been deleted since */
2066 *num
= b
->number
; /* We have its number */
2070 /* Modify BS so that the actions will not be performed. */
2073 bpstat_clear_actions (bpstat bs
)
2075 for (; bs
!= NULL
; bs
= bs
->next
)
2077 free_command_lines (&bs
->commands
);
2078 if (bs
->old_val
!= NULL
)
2080 value_free (bs
->old_val
);
2086 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2088 cleanup_executing_breakpoints (void *ignore
)
2090 executing_breakpoint_commands
= 0;
2093 /* Execute all the commands associated with all the breakpoints at this
2094 location. Any of these commands could cause the process to proceed
2095 beyond this point, etc. We look out for such changes by checking
2096 the global "breakpoint_proceeded" after each command.
2098 Returns true if a breakpoint command resumed the inferior. In that
2099 case, it is the caller's responsibility to recall it again with the
2100 bpstat of the current thread. */
2103 bpstat_do_actions_1 (bpstat
*bsp
)
2106 struct cleanup
*old_chain
;
2109 /* Avoid endless recursion if a `source' command is contained
2111 if (executing_breakpoint_commands
)
2114 executing_breakpoint_commands
= 1;
2115 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2117 /* This pointer will iterate over the list of bpstat's. */
2120 breakpoint_proceeded
= 0;
2121 for (; bs
!= NULL
; bs
= bs
->next
)
2123 struct command_line
*cmd
;
2124 struct cleanup
*this_cmd_tree_chain
;
2126 /* Take ownership of the BSP's command tree, if it has one.
2128 The command tree could legitimately contain commands like
2129 'step' and 'next', which call clear_proceed_status, which
2130 frees stop_bpstat's command tree. To make sure this doesn't
2131 free the tree we're executing out from under us, we need to
2132 take ownership of the tree ourselves. Since a given bpstat's
2133 commands are only executed once, we don't need to copy it; we
2134 can clear the pointer in the bpstat, and make sure we free
2135 the tree when we're done. */
2138 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2142 execute_control_command (cmd
);
2144 if (breakpoint_proceeded
)
2150 /* We can free this command tree now. */
2151 do_cleanups (this_cmd_tree_chain
);
2153 if (breakpoint_proceeded
)
2155 if (target_can_async_p ())
2156 /* If we are in async mode, then the target might be still
2157 running, not stopped at any breakpoint, so nothing for
2158 us to do here -- just return to the event loop. */
2161 /* In sync mode, when execute_control_command returns
2162 we're already standing on the next breakpoint.
2163 Breakpoint commands for that stop were not run, since
2164 execute_command does not run breakpoint commands --
2165 only command_line_handler does, but that one is not
2166 involved in execution of breakpoint commands. So, we
2167 can now execute breakpoint commands. It should be
2168 noted that making execute_command do bpstat actions is
2169 not an option -- in this case we'll have recursive
2170 invocation of bpstat for each breakpoint with a
2171 command, and can easily blow up GDB stack. Instead, we
2172 return true, which will trigger the caller to recall us
2173 with the new stop_bpstat. */
2178 do_cleanups (old_chain
);
2183 bpstat_do_actions (void)
2185 /* Do any commands attached to breakpoint we are stopped at. */
2186 while (!ptid_equal (inferior_ptid
, null_ptid
)
2187 && target_has_execution
2188 && !is_exited (inferior_ptid
)
2189 && !is_executing (inferior_ptid
))
2190 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2191 and only return when it is stopped at the next breakpoint, we
2192 keep doing breakpoint actions until it returns false to
2193 indicate the inferior was not resumed. */
2194 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2198 /* Print out the (old or new) value associated with a watchpoint. */
2201 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2204 fprintf_unfiltered (stream
, _("<unreadable>"));
2207 struct value_print_options opts
;
2208 get_user_print_options (&opts
);
2209 value_print (val
, stream
, &opts
);
2213 /* This is the normal print function for a bpstat. In the future,
2214 much of this logic could (should?) be moved to bpstat_stop_status,
2215 by having it set different print_it values.
2217 Current scheme: When we stop, bpstat_print() is called. It loops
2218 through the bpstat list of things causing this stop, calling the
2219 print_bp_stop_message function on each one. The behavior of the
2220 print_bp_stop_message function depends on the print_it field of
2221 bpstat. If such field so indicates, call this function here.
2223 Return values from this routine (ultimately used by bpstat_print()
2224 and normal_stop() to decide what to do):
2225 PRINT_NOTHING: Means we already printed all we needed to print,
2226 don't print anything else.
2227 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2228 that something to be followed by a location.
2229 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2230 that something to be followed by a location.
2231 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2234 static enum print_stop_action
2235 print_it_typical (bpstat bs
)
2237 struct cleanup
*old_chain
;
2238 struct breakpoint
*b
;
2239 const struct bp_location
*bl
;
2240 struct ui_stream
*stb
;
2242 enum print_stop_action result
;
2244 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2245 which has since been deleted. */
2246 if (bs
->breakpoint_at
== NULL
)
2247 return PRINT_UNKNOWN
;
2248 bl
= bs
->breakpoint_at
;
2251 stb
= ui_out_stream_new (uiout
);
2252 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2257 case bp_hardware_breakpoint
:
2258 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2259 if (bl
->address
!= bl
->requested_address
)
2260 breakpoint_adjustment_warning (bl
->requested_address
,
2263 annotate_breakpoint (b
->number
);
2265 ui_out_text (uiout
, "\nTemporary breakpoint ");
2267 ui_out_text (uiout
, "\nBreakpoint ");
2268 if (ui_out_is_mi_like_p (uiout
))
2270 ui_out_field_string (uiout
, "reason",
2271 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2272 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2274 ui_out_field_int (uiout
, "bkptno", b
->number
);
2275 ui_out_text (uiout
, ", ");
2276 result
= PRINT_SRC_AND_LOC
;
2279 case bp_shlib_event
:
2280 /* Did we stop because the user set the stop_on_solib_events
2281 variable? (If so, we report this as a generic, "Stopped due
2282 to shlib event" message.) */
2283 printf_filtered (_("Stopped due to shared library event\n"));
2284 result
= PRINT_NOTHING
;
2287 case bp_thread_event
:
2288 /* Not sure how we will get here.
2289 GDB should not stop for these breakpoints. */
2290 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2291 result
= PRINT_NOTHING
;
2294 case bp_overlay_event
:
2295 /* By analogy with the thread event, GDB should not stop for these. */
2296 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2297 result
= PRINT_NOTHING
;
2301 case bp_hardware_watchpoint
:
2302 annotate_watchpoint (b
->number
);
2303 if (ui_out_is_mi_like_p (uiout
))
2306 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2308 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2309 ui_out_text (uiout
, "\nOld value = ");
2310 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2311 ui_out_field_stream (uiout
, "old", stb
);
2312 ui_out_text (uiout
, "\nNew value = ");
2313 watchpoint_value_print (b
->val
, stb
->stream
);
2314 ui_out_field_stream (uiout
, "new", stb
);
2315 ui_out_text (uiout
, "\n");
2316 /* More than one watchpoint may have been triggered. */
2317 result
= PRINT_UNKNOWN
;
2320 case bp_read_watchpoint
:
2321 if (ui_out_is_mi_like_p (uiout
))
2324 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2326 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2327 ui_out_text (uiout
, "\nValue = ");
2328 watchpoint_value_print (b
->val
, stb
->stream
);
2329 ui_out_field_stream (uiout
, "value", stb
);
2330 ui_out_text (uiout
, "\n");
2331 result
= PRINT_UNKNOWN
;
2334 case bp_access_watchpoint
:
2335 if (bs
->old_val
!= NULL
)
2337 annotate_watchpoint (b
->number
);
2338 if (ui_out_is_mi_like_p (uiout
))
2341 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2343 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2344 ui_out_text (uiout
, "\nOld value = ");
2345 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2346 ui_out_field_stream (uiout
, "old", stb
);
2347 ui_out_text (uiout
, "\nNew value = ");
2352 if (ui_out_is_mi_like_p (uiout
))
2355 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2356 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2357 ui_out_text (uiout
, "\nValue = ");
2359 watchpoint_value_print (b
->val
, stb
->stream
);
2360 ui_out_field_stream (uiout
, "new", stb
);
2361 ui_out_text (uiout
, "\n");
2362 result
= PRINT_UNKNOWN
;
2365 /* Fall through, we don't deal with these types of breakpoints
2369 if (ui_out_is_mi_like_p (uiout
))
2372 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2373 result
= PRINT_UNKNOWN
;
2377 if (ui_out_is_mi_like_p (uiout
))
2380 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2381 result
= PRINT_UNKNOWN
;
2386 case bp_longjmp_resume
:
2387 case bp_step_resume
:
2388 case bp_watchpoint_scope
:
2391 result
= PRINT_UNKNOWN
;
2395 do_cleanups (old_chain
);
2399 /* Generic routine for printing messages indicating why we
2400 stopped. The behavior of this function depends on the value
2401 'print_it' in the bpstat structure. Under some circumstances we
2402 may decide not to print anything here and delegate the task to
2405 static enum print_stop_action
2406 print_bp_stop_message (bpstat bs
)
2408 switch (bs
->print_it
)
2411 /* Nothing should be printed for this bpstat entry. */
2412 return PRINT_UNKNOWN
;
2416 /* We still want to print the frame, but we already printed the
2417 relevant messages. */
2418 return PRINT_SRC_AND_LOC
;
2421 case print_it_normal
:
2423 const struct bp_location
*bl
= bs
->breakpoint_at
;
2424 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2426 /* Normal case. Call the breakpoint's print_it method, or
2427 print_it_typical. */
2428 /* FIXME: how breakpoint can ever be NULL here? */
2429 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2430 return b
->ops
->print_it (b
);
2432 return print_it_typical (bs
);
2437 internal_error (__FILE__
, __LINE__
,
2438 _("print_bp_stop_message: unrecognized enum value"));
2443 /* Print a message indicating what happened. This is called from
2444 normal_stop(). The input to this routine is the head of the bpstat
2445 list - a list of the eventpoints that caused this stop. This
2446 routine calls the generic print routine for printing a message
2447 about reasons for stopping. This will print (for example) the
2448 "Breakpoint n," part of the output. The return value of this
2451 PRINT_UNKNOWN: Means we printed nothing
2452 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2453 code to print the location. An example is
2454 "Breakpoint 1, " which should be followed by
2456 PRINT_SRC_ONLY: Means we printed something, but there is no need
2457 to also print the location part of the message.
2458 An example is the catch/throw messages, which
2459 don't require a location appended to the end.
2460 PRINT_NOTHING: We have done some printing and we don't need any
2461 further info to be printed.*/
2463 enum print_stop_action
2464 bpstat_print (bpstat bs
)
2468 /* Maybe another breakpoint in the chain caused us to stop.
2469 (Currently all watchpoints go on the bpstat whether hit or not.
2470 That probably could (should) be changed, provided care is taken
2471 with respect to bpstat_explains_signal). */
2472 for (; bs
; bs
= bs
->next
)
2474 val
= print_bp_stop_message (bs
);
2475 if (val
== PRINT_SRC_ONLY
2476 || val
== PRINT_SRC_AND_LOC
2477 || val
== PRINT_NOTHING
)
2481 /* We reached the end of the chain, or we got a null BS to start
2482 with and nothing was printed. */
2483 return PRINT_UNKNOWN
;
2486 /* Evaluate the expression EXP and return 1 if value is zero.
2487 This is used inside a catch_errors to evaluate the breakpoint condition.
2488 The argument is a "struct expression *" that has been cast to char * to
2489 make it pass through catch_errors. */
2492 breakpoint_cond_eval (void *exp
)
2494 struct value
*mark
= value_mark ();
2495 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2496 value_free_to_mark (mark
);
2500 /* Allocate a new bpstat and chain it to the current one. */
2503 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2507 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2509 bs
->breakpoint_at
= bl
;
2510 /* If the condition is false, etc., don't do the commands. */
2511 bs
->commands
= NULL
;
2513 bs
->print_it
= print_it_normal
;
2517 /* The target has stopped with waitstatus WS. Check if any hardware
2518 watchpoints have triggered, according to the target. */
2521 watchpoints_triggered (struct target_waitstatus
*ws
)
2523 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2525 struct breakpoint
*b
;
2527 if (!stopped_by_watchpoint
)
2529 /* We were not stopped by a watchpoint. Mark all watchpoints
2530 as not triggered. */
2532 if (b
->type
== bp_hardware_watchpoint
2533 || b
->type
== bp_read_watchpoint
2534 || b
->type
== bp_access_watchpoint
)
2535 b
->watchpoint_triggered
= watch_triggered_no
;
2540 if (!target_stopped_data_address (¤t_target
, &addr
))
2542 /* We were stopped by a watchpoint, but we don't know where.
2543 Mark all watchpoints as unknown. */
2545 if (b
->type
== bp_hardware_watchpoint
2546 || b
->type
== bp_read_watchpoint
2547 || b
->type
== bp_access_watchpoint
)
2548 b
->watchpoint_triggered
= watch_triggered_unknown
;
2550 return stopped_by_watchpoint
;
2553 /* The target could report the data address. Mark watchpoints
2554 affected by this data address as triggered, and all others as not
2558 if (b
->type
== bp_hardware_watchpoint
2559 || b
->type
== bp_read_watchpoint
2560 || b
->type
== bp_access_watchpoint
)
2562 struct bp_location
*loc
;
2565 b
->watchpoint_triggered
= watch_triggered_no
;
2566 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2567 /* Exact match not required. Within range is
2569 if (target_watchpoint_addr_within_range (¤t_target
,
2573 b
->watchpoint_triggered
= watch_triggered_yes
;
2581 /* Possible return values for watchpoint_check (this can't be an enum
2582 because of check_errors). */
2583 /* The watchpoint has been deleted. */
2584 #define WP_DELETED 1
2585 /* The value has changed. */
2586 #define WP_VALUE_CHANGED 2
2587 /* The value has not changed. */
2588 #define WP_VALUE_NOT_CHANGED 3
2590 #define BP_TEMPFLAG 1
2591 #define BP_HARDWAREFLAG 2
2593 /* Check watchpoint condition. */
2596 watchpoint_check (void *p
)
2598 bpstat bs
= (bpstat
) p
;
2599 struct breakpoint
*b
;
2600 struct frame_info
*fr
;
2601 int within_current_scope
;
2603 b
= bs
->breakpoint_at
->owner
;
2605 if (b
->exp_valid_block
== NULL
)
2606 within_current_scope
= 1;
2609 /* There is no current frame at this moment. If we're going to have
2610 any chance of handling watchpoints on local variables, we'll need
2611 the frame chain (so we can determine if we're in scope). */
2612 reinit_frame_cache ();
2613 fr
= frame_find_by_id (b
->watchpoint_frame
);
2614 within_current_scope
= (fr
!= NULL
);
2616 /* If we've gotten confused in the unwinder, we might have
2617 returned a frame that can't describe this variable. */
2618 if (within_current_scope
2619 && (block_linkage_function (b
->exp_valid_block
)
2620 != get_frame_function (fr
)))
2621 within_current_scope
= 0;
2623 /* in_function_epilogue_p() returns a non-zero value if we're still
2624 in the function but the stack frame has already been invalidated.
2625 Since we can't rely on the values of local variables after the
2626 stack has been destroyed, we are treating the watchpoint in that
2627 state as `not changed' without further checking.
2629 vinschen/2003-09-04: The former implementation left out the case
2630 that the watchpoint frame couldn't be found by frame_find_by_id()
2631 because the current PC is currently in an epilogue. Calling
2632 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2633 if ((!within_current_scope
|| fr
== get_current_frame ())
2634 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2635 return WP_VALUE_NOT_CHANGED
;
2636 if (fr
&& within_current_scope
)
2637 /* If we end up stopping, the current frame will get selected
2638 in normal_stop. So this call to select_frame won't affect
2643 if (within_current_scope
)
2645 /* We use value_{,free_to_}mark because it could be a
2646 *long* time before we return to the command level and
2647 call free_all_values. We can't call free_all_values because
2648 we might be in the middle of evaluating a function call. */
2650 struct value
*mark
= value_mark ();
2651 struct value
*new_val
;
2653 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2654 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2655 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2657 if (new_val
!= NULL
)
2659 release_value (new_val
);
2660 value_free_to_mark (mark
);
2662 bs
->old_val
= b
->val
;
2665 /* We will stop here */
2666 return WP_VALUE_CHANGED
;
2670 /* Nothing changed, don't do anything. */
2671 value_free_to_mark (mark
);
2672 /* We won't stop here */
2673 return WP_VALUE_NOT_CHANGED
;
2678 /* This seems like the only logical thing to do because
2679 if we temporarily ignored the watchpoint, then when
2680 we reenter the block in which it is valid it contains
2681 garbage (in the case of a function, it may have two
2682 garbage values, one before and one after the prologue).
2683 So we can't even detect the first assignment to it and
2684 watch after that (since the garbage may or may not equal
2685 the first value assigned). */
2686 /* We print all the stop information in print_it_typical(), but
2687 in this case, by the time we call print_it_typical() this bp
2688 will be deleted already. So we have no choice but print the
2689 information here. */
2690 if (ui_out_is_mi_like_p (uiout
))
2692 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2693 ui_out_text (uiout
, "\nWatchpoint ");
2694 ui_out_field_int (uiout
, "wpnum", b
->number
);
2695 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2696 which its expression is valid.\n");
2698 if (b
->related_breakpoint
)
2699 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2700 b
->disposition
= disp_del_at_next_stop
;
2706 /* Return true if it looks like target has stopped due to hitting
2707 breakpoint location BL. This function does not check if we
2708 should stop, only if BL explains the stop. */
2710 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2712 struct breakpoint
*b
= bl
->owner
;
2714 if (b
->type
!= bp_watchpoint
2715 && b
->type
!= bp_hardware_watchpoint
2716 && b
->type
!= bp_read_watchpoint
2717 && b
->type
!= bp_access_watchpoint
2718 && b
->type
!= bp_hardware_breakpoint
2719 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2721 if (bl
->address
!= bp_addr
) /* address doesn't match */
2723 if (overlay_debugging
/* unmapped overlay section */
2724 && section_is_overlay (bl
->section
)
2725 && !section_is_mapped (bl
->section
))
2729 /* Continuable hardware watchpoints are treated as non-existent if the
2730 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2731 some data address). Otherwise gdb won't stop on a break instruction
2732 in the code (not from a breakpoint) when a hardware watchpoint has
2733 been defined. Also skip watchpoints which we know did not trigger
2734 (did not match the data address). */
2736 if ((b
->type
== bp_hardware_watchpoint
2737 || b
->type
== bp_read_watchpoint
2738 || b
->type
== bp_access_watchpoint
)
2739 && b
->watchpoint_triggered
== watch_triggered_no
)
2742 if (b
->type
== bp_hardware_breakpoint
)
2744 if (bl
->address
!= bp_addr
)
2746 if (overlay_debugging
/* unmapped overlay section */
2747 && section_is_overlay (bl
->section
)
2748 && !section_is_mapped (bl
->section
))
2752 if (b
->type
== bp_catchpoint
)
2754 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2755 if (!b
->ops
->breakpoint_hit (b
))
2762 /* If BS refers to a watchpoint, determine if the watched values
2763 has actually changed, and we should stop. If not, set BS->stop
2766 bpstat_check_watchpoint (bpstat bs
)
2768 const struct bp_location
*bl
= bs
->breakpoint_at
;
2769 struct breakpoint
*b
= bl
->owner
;
2771 if (b
->type
== bp_watchpoint
2772 || b
->type
== bp_read_watchpoint
2773 || b
->type
== bp_access_watchpoint
2774 || b
->type
== bp_hardware_watchpoint
)
2778 int must_check_value
= 0;
2780 if (b
->type
== bp_watchpoint
)
2781 /* For a software watchpoint, we must always check the
2783 must_check_value
= 1;
2784 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2785 /* We have a hardware watchpoint (read, write, or access)
2786 and the target earlier reported an address watched by
2788 must_check_value
= 1;
2789 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2790 && b
->type
== bp_hardware_watchpoint
)
2791 /* We were stopped by a hardware watchpoint, but the target could
2792 not report the data address. We must check the watchpoint's
2793 value. Access and read watchpoints are out of luck; without
2794 a data address, we can't figure it out. */
2795 must_check_value
= 1;
2797 if (must_check_value
)
2799 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2801 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2802 int e
= catch_errors (watchpoint_check
, bs
, message
,
2804 do_cleanups (cleanups
);
2808 /* We've already printed what needs to be printed. */
2809 bs
->print_it
= print_it_done
;
2812 case WP_VALUE_CHANGED
:
2813 if (b
->type
== bp_read_watchpoint
)
2815 /* Don't stop: read watchpoints shouldn't fire if
2816 the value has changed. This is for targets
2817 which cannot set read-only watchpoints. */
2818 bs
->print_it
= print_it_noop
;
2822 case WP_VALUE_NOT_CHANGED
:
2823 if (b
->type
== bp_hardware_watchpoint
2824 || b
->type
== bp_watchpoint
)
2826 /* Don't stop: write watchpoints shouldn't fire if
2827 the value hasn't changed. */
2828 bs
->print_it
= print_it_noop
;
2836 /* Error from catch_errors. */
2837 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2838 if (b
->related_breakpoint
)
2839 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2840 b
->disposition
= disp_del_at_next_stop
;
2841 /* We've already printed what needs to be printed. */
2842 bs
->print_it
= print_it_done
;
2846 else /* must_check_value == 0 */
2848 /* This is a case where some watchpoint(s) triggered, but
2849 not at the address of this watchpoint, or else no
2850 watchpoint triggered after all. So don't print
2851 anything for this watchpoint. */
2852 bs
->print_it
= print_it_noop
;
2859 /* Check conditions (condition proper, frame, thread and ignore count)
2860 of breakpoint referred to by BS. If we should not stop for this
2861 breakpoint, set BS->stop to 0. */
2863 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2865 int thread_id
= pid_to_thread_id (ptid
);
2866 const struct bp_location
*bl
= bs
->breakpoint_at
;
2867 struct breakpoint
*b
= bl
->owner
;
2869 if (frame_id_p (b
->frame_id
)
2870 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2874 int value_is_zero
= 0;
2876 /* If this is a scope breakpoint, mark the associated
2877 watchpoint as triggered so that we will handle the
2878 out-of-scope event. We'll get to the watchpoint next
2880 if (b
->type
== bp_watchpoint_scope
)
2881 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2883 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2885 /* Need to select the frame, with all that implies
2886 so that the conditions will have the right context. */
2887 select_frame (get_current_frame ());
2889 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2890 "Error in testing breakpoint condition:\n",
2892 /* FIXME-someday, should give breakpoint # */
2895 if (bl
->cond
&& value_is_zero
)
2899 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2903 else if (b
->ignore_count
> 0)
2906 annotate_ignore_count_change ();
2908 /* Increase the hit count even though we don't
2916 /* Get a bpstat associated with having just stopped at address
2917 BP_ADDR in thread PTID.
2919 Determine whether we stopped at a breakpoint, etc, or whether we
2920 don't understand this stop. Result is a chain of bpstat's such that:
2922 if we don't understand the stop, the result is a null pointer.
2924 if we understand why we stopped, the result is not null.
2926 Each element of the chain refers to a particular breakpoint or
2927 watchpoint at which we have stopped. (We may have stopped for
2928 several reasons concurrently.)
2930 Each element of the chain has valid next, breakpoint_at,
2931 commands, FIXME??? fields. */
2934 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2936 struct breakpoint
*b
= NULL
;
2937 const struct bp_location
*bl
;
2938 struct bp_location
*loc
;
2939 /* Root of the chain of bpstat's */
2940 struct bpstats root_bs
[1];
2941 /* Pointer to the last thing in the chain currently. */
2942 bpstat bs
= root_bs
;
2944 int need_remove_insert
;
2946 ALL_BP_LOCATIONS (bl
)
2950 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2953 /* For hardware watchpoints, we look only at the first location.
2954 The watchpoint_check function will work on entire expression,
2955 not the individual locations. For read watchopints, the
2956 watchpoints_triggered function have checked all locations
2959 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2962 if (!bpstat_check_location (bl
, bp_addr
))
2965 /* Come here if it's a watchpoint, or if the break address matches */
2967 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2969 /* Assume we stop. Should we find watchpoint that is not actually
2970 triggered, or if condition of breakpoint is false, we'll reset
2975 bpstat_check_watchpoint (bs
);
2979 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2980 /* We do not stop for these. */
2983 bpstat_check_breakpoint_conditions (bs
, ptid
);
2989 /* We will stop here */
2990 if (b
->disposition
== disp_disable
)
2992 if (b
->enable_state
!= bp_permanent
)
2993 b
->enable_state
= bp_disabled
;
2994 update_global_location_list (0);
2998 bs
->commands
= b
->commands
;
3000 (strcmp ("silent", bs
->commands
->line
) == 0
3001 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3003 bs
->commands
= bs
->commands
->next
;
3006 bs
->commands
= copy_command_lines (bs
->commands
);
3009 /* Print nothing for this entry if we dont stop or if we dont print. */
3010 if (bs
->stop
== 0 || bs
->print
== 0)
3011 bs
->print_it
= print_it_noop
;
3014 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3016 if (loc
->address
== bp_addr
)
3018 bs
= bpstat_alloc (loc
, bs
);
3019 /* For hits of moribund locations, we should just proceed. */
3022 bs
->print_it
= print_it_noop
;
3026 bs
->next
= NULL
; /* Terminate the chain */
3027 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3029 /* If we aren't stopping, the value of some hardware watchpoint may
3030 not have changed, but the intermediate memory locations we are
3031 watching may have. Don't bother if we're stopping; this will get
3033 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3037 need_remove_insert
= 0;
3039 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3041 && bs
->breakpoint_at
->owner
3042 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3043 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3044 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3046 /* remove/insert can invalidate bs->breakpoint_at, if this
3047 location is no longer used by the watchpoint. Prevent
3048 further code from trying to use it. */
3049 bs
->breakpoint_at
= NULL
;
3050 need_remove_insert
= 1;
3053 if (need_remove_insert
)
3055 remove_breakpoints ();
3056 insert_breakpoints ();
3059 return root_bs
->next
;
3062 /* Tell what to do about this bpstat. */
3064 bpstat_what (bpstat bs
)
3066 /* Classify each bpstat as one of the following. */
3069 /* This bpstat element has no effect on the main_action. */
3072 /* There was a watchpoint, stop but don't print. */
3075 /* There was a watchpoint, stop and print. */
3078 /* There was a breakpoint but we're not stopping. */
3081 /* There was a breakpoint, stop but don't print. */
3084 /* There was a breakpoint, stop and print. */
3087 /* We hit the longjmp breakpoint. */
3090 /* We hit the longjmp_resume breakpoint. */
3093 /* We hit the step_resume breakpoint. */
3096 /* We hit the shared library event breakpoint. */
3099 /* This is just used to count how many enums there are. */
3103 /* Here is the table which drives this routine. So that we can
3104 format it pretty, we define some abbreviations for the
3105 enum bpstat_what codes. */
3106 #define kc BPSTAT_WHAT_KEEP_CHECKING
3107 #define ss BPSTAT_WHAT_STOP_SILENT
3108 #define sn BPSTAT_WHAT_STOP_NOISY
3109 #define sgl BPSTAT_WHAT_SINGLE
3110 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3111 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3112 #define sr BPSTAT_WHAT_STEP_RESUME
3113 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3115 /* "Can't happen." Might want to print an error message.
3116 abort() is not out of the question, but chances are GDB is just
3117 a bit confused, not unusable. */
3118 #define err BPSTAT_WHAT_STOP_NOISY
3120 /* Given an old action and a class, come up with a new action. */
3121 /* One interesting property of this table is that wp_silent is the same
3122 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3123 after stopping, the check for whether to step over a breakpoint
3124 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3125 reference to how we stopped. We retain separate wp_silent and
3126 bp_silent codes in case we want to change that someday.
3128 Another possibly interesting property of this table is that
3129 there's a partial ordering, priority-like, of the actions. Once
3130 you've decided that some action is appropriate, you'll never go
3131 back and decide something of a lower priority is better. The
3134 kc < clr sgl shl slr sn sr ss
3135 sgl < shl slr sn sr ss
3136 slr < err shl sn sr ss
3137 clr < err shl sn sr ss
3143 What I think this means is that we don't need a damned table
3144 here. If you just put the rows and columns in the right order,
3145 it'd look awfully regular. We could simply walk the bpstat list
3146 and choose the highest priority action we find, with a little
3147 logic to handle the 'err' cases. */
3149 /* step_resume entries: a step resume breakpoint overrides another
3150 breakpoint of signal handling (see comment in wait_for_inferior
3151 at where we set the step_resume breakpoint). */
3153 static const enum bpstat_what_main_action
3154 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3157 /* kc ss sn sgl slr clr sr shl
3160 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3162 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3164 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3166 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3168 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3170 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3172 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3174 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3176 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3178 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3191 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3192 struct bpstat_what retval
;
3194 retval
.call_dummy
= 0;
3195 for (; bs
!= NULL
; bs
= bs
->next
)
3197 enum class bs_class
= no_effect
;
3198 if (bs
->breakpoint_at
== NULL
)
3199 /* I suspect this can happen if it was a momentary breakpoint
3200 which has since been deleted. */
3202 if (bs
->breakpoint_at
->owner
== NULL
)
3203 bs_class
= bp_nostop
;
3205 switch (bs
->breakpoint_at
->owner
->type
)
3211 case bp_hardware_breakpoint
:
3217 bs_class
= bp_noisy
;
3219 bs_class
= bp_silent
;
3222 bs_class
= bp_nostop
;
3225 case bp_hardware_watchpoint
:
3226 case bp_read_watchpoint
:
3227 case bp_access_watchpoint
:
3231 bs_class
= wp_noisy
;
3233 bs_class
= wp_silent
;
3236 /* There was a watchpoint, but we're not stopping.
3237 This requires no further action. */
3238 bs_class
= no_effect
;
3241 bs_class
= long_jump
;
3243 case bp_longjmp_resume
:
3244 bs_class
= long_resume
;
3246 case bp_step_resume
:
3249 bs_class
= step_resume
;
3252 /* It is for the wrong frame. */
3253 bs_class
= bp_nostop
;
3255 case bp_watchpoint_scope
:
3256 bs_class
= bp_nostop
;
3258 case bp_shlib_event
:
3259 bs_class
= shlib_event
;
3261 case bp_thread_event
:
3262 case bp_overlay_event
:
3263 bs_class
= bp_nostop
;
3269 bs_class
= bp_noisy
;
3271 bs_class
= bp_silent
;
3274 /* There was a catchpoint, but we're not stopping.
3275 This requires no further action. */
3276 bs_class
= no_effect
;
3279 /* Make sure the action is stop (silent or noisy),
3280 so infrun.c pops the dummy frame. */
3281 bs_class
= bp_silent
;
3282 retval
.call_dummy
= 1;
3285 current_action
= table
[(int) bs_class
][(int) current_action
];
3287 retval
.main_action
= current_action
;
3291 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3292 without hardware support). This isn't related to a specific bpstat,
3293 just to things like whether watchpoints are set. */
3296 bpstat_should_step (void)
3298 struct breakpoint
*b
;
3300 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3307 static void print_breakpoint_location (struct breakpoint
*b
,
3308 struct bp_location
*loc
,
3310 struct ui_stream
*stb
)
3315 = find_pc_sect_function (loc
->address
, loc
->section
);
3318 ui_out_text (uiout
, "in ");
3319 ui_out_field_string (uiout
, "func",
3320 SYMBOL_PRINT_NAME (sym
));
3321 ui_out_wrap_hint (uiout
, wrap_indent
);
3322 ui_out_text (uiout
, " at ");
3324 ui_out_field_string (uiout
, "file", b
->source_file
);
3325 ui_out_text (uiout
, ":");
3327 if (ui_out_is_mi_like_p (uiout
))
3329 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3330 char *fullname
= symtab_to_fullname (sal
.symtab
);
3333 ui_out_field_string (uiout
, "fullname", fullname
);
3336 ui_out_field_int (uiout
, "line", b
->line_number
);
3340 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3344 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3345 ui_out_field_stream (uiout
, "at", stb
);
3349 /* Print B to gdb_stdout. */
3351 print_one_breakpoint_location (struct breakpoint
*b
,
3352 struct bp_location
*loc
,
3354 CORE_ADDR
*last_addr
)
3356 struct command_line
*l
;
3358 struct ep_type_description
3363 static struct ep_type_description bptypes
[] =
3365 {bp_none
, "?deleted?"},
3366 {bp_breakpoint
, "breakpoint"},
3367 {bp_hardware_breakpoint
, "hw breakpoint"},
3368 {bp_until
, "until"},
3369 {bp_finish
, "finish"},
3370 {bp_watchpoint
, "watchpoint"},
3371 {bp_hardware_watchpoint
, "hw watchpoint"},
3372 {bp_read_watchpoint
, "read watchpoint"},
3373 {bp_access_watchpoint
, "acc watchpoint"},
3374 {bp_longjmp
, "longjmp"},
3375 {bp_longjmp_resume
, "longjmp resume"},
3376 {bp_step_resume
, "step resume"},
3377 {bp_watchpoint_scope
, "watchpoint scope"},
3378 {bp_call_dummy
, "call dummy"},
3379 {bp_shlib_event
, "shlib events"},
3380 {bp_thread_event
, "thread events"},
3381 {bp_overlay_event
, "overlay events"},
3382 {bp_catchpoint
, "catchpoint"},
3385 static char bpenables
[] = "nynny";
3386 char wrap_indent
[80];
3387 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3388 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3389 struct cleanup
*bkpt_chain
;
3391 int header_of_multiple
= 0;
3392 int part_of_multiple
= (loc
!= NULL
);
3393 struct value_print_options opts
;
3395 get_user_print_options (&opts
);
3397 gdb_assert (!loc
|| loc_number
!= 0);
3398 /* See comment in print_one_breakpoint concerning
3399 treatment of breakpoints with single disabled
3403 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3404 header_of_multiple
= 1;
3409 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3413 if (part_of_multiple
)
3416 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3417 ui_out_field_string (uiout
, "number", formatted
);
3422 ui_out_field_int (uiout
, "number", b
->number
);
3427 if (part_of_multiple
)
3428 ui_out_field_skip (uiout
, "type");
3431 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3432 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3433 internal_error (__FILE__
, __LINE__
,
3434 _("bptypes table does not describe type #%d."),
3436 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3441 if (part_of_multiple
)
3442 ui_out_field_skip (uiout
, "disp");
3444 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3449 if (part_of_multiple
)
3450 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3452 ui_out_field_fmt (uiout
, "enabled", "%c",
3453 bpenables
[(int) b
->enable_state
]);
3454 ui_out_spaces (uiout
, 2);
3458 strcpy (wrap_indent
, " ");
3459 if (opts
.addressprint
)
3461 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3462 strcat (wrap_indent
, " ");
3464 strcat (wrap_indent
, " ");
3467 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3469 /* Although the print_one can possibly print
3470 all locations, calling it here is not likely
3471 to get any nice result. So, make sure there's
3472 just one location. */
3473 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3474 b
->ops
->print_one (b
, last_addr
);
3480 internal_error (__FILE__
, __LINE__
,
3481 _("print_one_breakpoint: bp_none encountered\n"));
3485 case bp_hardware_watchpoint
:
3486 case bp_read_watchpoint
:
3487 case bp_access_watchpoint
:
3488 /* Field 4, the address, is omitted (which makes the columns
3489 not line up too nicely with the headers, but the effect
3490 is relatively readable). */
3491 if (opts
.addressprint
)
3492 ui_out_field_skip (uiout
, "addr");
3494 ui_out_field_string (uiout
, "what", b
->exp_string
);
3498 case bp_hardware_breakpoint
:
3502 case bp_longjmp_resume
:
3503 case bp_step_resume
:
3504 case bp_watchpoint_scope
:
3506 case bp_shlib_event
:
3507 case bp_thread_event
:
3508 case bp_overlay_event
:
3509 if (opts
.addressprint
)
3512 if (header_of_multiple
)
3513 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3514 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3515 ui_out_field_string (uiout
, "addr", "<PENDING>");
3517 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3520 if (!header_of_multiple
)
3521 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3523 *last_addr
= b
->loc
->address
;
3527 if (!part_of_multiple
&& b
->thread
!= -1)
3529 /* FIXME: This seems to be redundant and lost here; see the
3530 "stop only in" line a little further down. */
3531 ui_out_text (uiout
, " thread ");
3532 ui_out_field_int (uiout
, "thread", b
->thread
);
3535 ui_out_text (uiout
, "\n");
3537 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3540 ui_out_text (uiout
, "\tstop only in stack frame at ");
3541 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3543 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3544 ui_out_text (uiout
, "\n");
3547 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3549 /* We do not print the condition for Ada exception catchpoints
3550 because the condition is an internal implementation detail
3551 that we do not want to expose to the user. */
3553 ui_out_text (uiout
, "\tstop only if ");
3554 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3555 ui_out_text (uiout
, "\n");
3558 if (!part_of_multiple
&& b
->thread
!= -1)
3560 /* FIXME should make an annotation for this */
3561 ui_out_text (uiout
, "\tstop only in thread ");
3562 ui_out_field_int (uiout
, "thread", b
->thread
);
3563 ui_out_text (uiout
, "\n");
3566 if (!part_of_multiple
&& b
->hit_count
)
3568 /* FIXME should make an annotation for this */
3569 if (ep_is_catchpoint (b
))
3570 ui_out_text (uiout
, "\tcatchpoint");
3572 ui_out_text (uiout
, "\tbreakpoint");
3573 ui_out_text (uiout
, " already hit ");
3574 ui_out_field_int (uiout
, "times", b
->hit_count
);
3575 if (b
->hit_count
== 1)
3576 ui_out_text (uiout
, " time\n");
3578 ui_out_text (uiout
, " times\n");
3581 /* Output the count also if it is zero, but only if this is
3582 mi. FIXME: Should have a better test for this. */
3583 if (ui_out_is_mi_like_p (uiout
))
3584 if (!part_of_multiple
&& b
->hit_count
== 0)
3585 ui_out_field_int (uiout
, "times", b
->hit_count
);
3587 if (!part_of_multiple
&& b
->ignore_count
)
3590 ui_out_text (uiout
, "\tignore next ");
3591 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3592 ui_out_text (uiout
, " hits\n");
3595 if (!part_of_multiple
&& (l
= b
->commands
))
3597 struct cleanup
*script_chain
;
3600 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3601 print_command_lines (uiout
, l
, 4);
3602 do_cleanups (script_chain
);
3605 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3608 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3609 else if (b
->exp_string
)
3610 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3613 do_cleanups (bkpt_chain
);
3614 do_cleanups (old_chain
);
3618 print_one_breakpoint (struct breakpoint
*b
,
3619 CORE_ADDR
*last_addr
)
3621 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3623 /* If this breakpoint has custom print function,
3624 it's already printed. Otherwise, print individual
3625 locations, if any. */
3626 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3628 /* If breakpoint has a single location that is
3629 disabled, we print it as if it had
3630 several locations, since otherwise it's hard to
3631 represent "breakpoint enabled, location disabled"
3633 Note that while hardware watchpoints have
3634 several locations internally, that's no a property
3637 && !is_hardware_watchpoint (b
)
3638 && (b
->loc
->next
|| !b
->loc
->enabled
)
3639 && !ui_out_is_mi_like_p (uiout
))
3641 struct bp_location
*loc
;
3643 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3644 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3650 struct captured_breakpoint_query_args
3656 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3658 struct captured_breakpoint_query_args
*args
= data
;
3659 struct breakpoint
*b
;
3660 CORE_ADDR dummy_addr
= 0;
3663 if (args
->bnum
== b
->number
)
3665 print_one_breakpoint (b
, &dummy_addr
);
3673 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3675 struct captured_breakpoint_query_args args
;
3677 /* For the moment we don't trust print_one_breakpoint() to not throw
3679 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3680 error_message
, RETURN_MASK_ALL
) < 0)
3686 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3687 catchpoints, et.al.). */
3690 user_settable_breakpoint (const struct breakpoint
*b
)
3692 return (b
->type
== bp_breakpoint
3693 || b
->type
== bp_catchpoint
3694 || b
->type
== bp_hardware_breakpoint
3695 || b
->type
== bp_watchpoint
3696 || b
->type
== bp_read_watchpoint
3697 || b
->type
== bp_access_watchpoint
3698 || b
->type
== bp_hardware_watchpoint
);
3701 /* Print information on user settable breakpoint (watchpoint, etc)
3702 number BNUM. If BNUM is -1 print all user settable breakpoints.
3703 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3706 breakpoint_1 (int bnum
, int allflag
)
3708 struct breakpoint
*b
;
3709 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3710 int nr_printable_breakpoints
;
3711 struct cleanup
*bkpttbl_chain
;
3712 struct value_print_options opts
;
3714 get_user_print_options (&opts
);
3716 /* Compute the number of rows in the table. */
3717 nr_printable_breakpoints
= 0;
3720 || bnum
== b
->number
)
3722 if (allflag
|| user_settable_breakpoint (b
))
3723 nr_printable_breakpoints
++;
3726 if (opts
.addressprint
)
3728 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3732 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3735 if (nr_printable_breakpoints
> 0)
3736 annotate_breakpoints_headers ();
3737 if (nr_printable_breakpoints
> 0)
3739 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3740 if (nr_printable_breakpoints
> 0)
3742 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3743 if (nr_printable_breakpoints
> 0)
3745 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3746 if (nr_printable_breakpoints
> 0)
3748 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3749 if (opts
.addressprint
)
3751 if (nr_printable_breakpoints
> 0)
3753 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3754 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3756 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3758 if (nr_printable_breakpoints
> 0)
3760 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3761 ui_out_table_body (uiout
);
3762 if (nr_printable_breakpoints
> 0)
3763 annotate_breakpoints_table ();
3767 || bnum
== b
->number
)
3769 /* We only print out user settable breakpoints unless the
3771 if (allflag
|| user_settable_breakpoint (b
))
3772 print_one_breakpoint (b
, &last_addr
);
3775 do_cleanups (bkpttbl_chain
);
3777 if (nr_printable_breakpoints
== 0)
3780 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3782 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3787 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3788 that a comparison of an unsigned with -1 is always false. */
3789 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3790 set_next_address (current_gdbarch
, last_addr
);
3793 /* FIXME? Should this be moved up so that it is only called when
3794 there have been breakpoints? */
3795 annotate_breakpoints_table_end ();
3799 breakpoints_info (char *bnum_exp
, int from_tty
)
3804 bnum
= parse_and_eval_long (bnum_exp
);
3806 breakpoint_1 (bnum
, 0);
3810 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3815 bnum
= parse_and_eval_long (bnum_exp
);
3817 breakpoint_1 (bnum
, 1);
3821 breakpoint_has_pc (struct breakpoint
*b
,
3822 CORE_ADDR pc
, struct obj_section
*section
)
3824 struct bp_location
*bl
= b
->loc
;
3825 for (; bl
; bl
= bl
->next
)
3827 if (bl
->address
== pc
3828 && (!overlay_debugging
|| bl
->section
== section
))
3834 /* Print a message describing any breakpoints set at PC. */
3837 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3841 struct breakpoint
*b
;
3844 others
+= breakpoint_has_pc (b
, pc
, section
);
3848 printf_filtered (_("Note: breakpoint "));
3849 else /* if (others == ???) */
3850 printf_filtered (_("Note: breakpoints "));
3852 if (breakpoint_has_pc (b
, pc
, section
))
3855 printf_filtered ("%d", b
->number
);
3856 if (b
->thread
== -1 && thread
!= -1)
3857 printf_filtered (" (all threads)");
3858 else if (b
->thread
!= -1)
3859 printf_filtered (" (thread %d)", b
->thread
);
3860 printf_filtered ("%s%s ",
3861 ((b
->enable_state
== bp_disabled
||
3862 b
->enable_state
== bp_call_disabled
)
3864 : b
->enable_state
== bp_permanent
3868 : ((others
== 1) ? " and" : ""));
3870 printf_filtered (_("also set at pc "));
3871 fputs_filtered (paddress (pc
), gdb_stdout
);
3872 printf_filtered (".\n");
3876 /* Set the default place to put a breakpoint
3877 for the `break' command with no arguments. */
3880 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3883 default_breakpoint_valid
= valid
;
3884 default_breakpoint_address
= addr
;
3885 default_breakpoint_symtab
= symtab
;
3886 default_breakpoint_line
= line
;
3889 /* Return true iff it is meaningful to use the address member of
3890 BPT. For some breakpoint types, the address member is irrelevant
3891 and it makes no sense to attempt to compare it to other addresses
3892 (or use it for any other purpose either).
3894 More specifically, each of the following breakpoint types will always
3895 have a zero valued address and we don't want check_duplicates() to mark
3896 breakpoints of any of these types to be a duplicate of an actual
3897 breakpoint at address zero:
3900 bp_hardware_watchpoint
3902 bp_access_watchpoint
3906 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3908 enum bptype type
= bpt
->type
;
3910 return (type
!= bp_watchpoint
3911 && type
!= bp_hardware_watchpoint
3912 && type
!= bp_read_watchpoint
3913 && type
!= bp_access_watchpoint
3914 && type
!= bp_catchpoint
);
3917 /* Rescan breakpoints at the same address and section as BPT,
3918 marking the first one as "first" and any others as "duplicates".
3919 This is so that the bpt instruction is only inserted once.
3920 If we have a permanent breakpoint at the same place as BPT, make
3921 that one the official one, and the rest as duplicates. */
3924 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
3926 struct bp_location
*b
;
3928 struct bp_location
*perm_bp
= 0;
3930 ALL_BP_LOCATIONS (b
)
3931 if (b
->owner
->enable_state
!= bp_disabled
3932 && b
->owner
->enable_state
!= bp_call_disabled
3934 && !b
->shlib_disabled
3935 && b
->address
== address
/* address / overlay match */
3936 && (!overlay_debugging
|| b
->section
== section
)
3937 && breakpoint_address_is_meaningful (b
->owner
))
3939 /* Have we found a permanent breakpoint? */
3940 if (b
->owner
->enable_state
== bp_permanent
)
3947 b
->duplicate
= count
> 1;
3950 /* If we found a permanent breakpoint at this address, go over the
3951 list again and declare all the other breakpoints there to be the
3955 perm_bp
->duplicate
= 0;
3957 /* Permanent breakpoint should always be inserted. */
3958 if (! perm_bp
->inserted
)
3959 internal_error (__FILE__
, __LINE__
,
3960 _("allegedly permanent breakpoint is not "
3961 "actually inserted"));
3963 ALL_BP_LOCATIONS (b
)
3966 if (b
->owner
->enable_state
!= bp_disabled
3967 && b
->owner
->enable_state
!= bp_call_disabled
3968 && b
->enabled
&& !b
->shlib_disabled
3969 && b
->address
== address
/* address / overlay match */
3970 && (!overlay_debugging
|| b
->section
== section
)
3971 && breakpoint_address_is_meaningful (b
->owner
))
3974 internal_error (__FILE__
, __LINE__
,
3975 _("another breakpoint was inserted on top of "
3976 "a permanent breakpoint"));
3985 check_duplicates (struct breakpoint
*bpt
)
3987 struct bp_location
*bl
= bpt
->loc
;
3989 if (! breakpoint_address_is_meaningful (bpt
))
3992 for (; bl
; bl
= bl
->next
)
3993 check_duplicates_for (bl
->address
, bl
->section
);
3997 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3998 int bnum
, int have_bnum
)
4003 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4004 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4006 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4007 bnum
, astr1
, astr2
);
4009 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4012 /* Adjust a breakpoint's address to account for architectural constraints
4013 on breakpoint placement. Return the adjusted address. Note: Very
4014 few targets require this kind of adjustment. For most targets,
4015 this function is simply the identity function. */
4018 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4020 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4022 /* Very few targets need any kind of breakpoint adjustment. */
4025 else if (bptype
== bp_watchpoint
4026 || bptype
== bp_hardware_watchpoint
4027 || bptype
== bp_read_watchpoint
4028 || bptype
== bp_access_watchpoint
4029 || bptype
== bp_catchpoint
)
4031 /* Watchpoints and the various bp_catch_* eventpoints should not
4032 have their addresses modified. */
4037 CORE_ADDR adjusted_bpaddr
;
4039 /* Some targets have architectural constraints on the placement
4040 of breakpoint instructions. Obtain the adjusted address. */
4041 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4044 /* An adjusted breakpoint address can significantly alter
4045 a user's expectations. Print a warning if an adjustment
4047 if (adjusted_bpaddr
!= bpaddr
)
4048 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4050 return adjusted_bpaddr
;
4054 /* Allocate a struct bp_location. */
4056 static struct bp_location
*
4057 allocate_bp_location (struct breakpoint
*bpt
)
4059 struct bp_location
*loc
, *loc_p
;
4061 loc
= xmalloc (sizeof (struct bp_location
));
4062 memset (loc
, 0, sizeof (*loc
));
4066 loc
->shlib_disabled
= 0;
4075 case bp_longjmp_resume
:
4076 case bp_step_resume
:
4077 case bp_watchpoint_scope
:
4079 case bp_shlib_event
:
4080 case bp_thread_event
:
4081 case bp_overlay_event
:
4082 loc
->loc_type
= bp_loc_software_breakpoint
;
4084 case bp_hardware_breakpoint
:
4085 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4087 case bp_hardware_watchpoint
:
4088 case bp_read_watchpoint
:
4089 case bp_access_watchpoint
:
4090 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4094 loc
->loc_type
= bp_loc_other
;
4097 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4103 static void free_bp_location (struct bp_location
*loc
)
4108 if (loc
->function_name
)
4109 xfree (loc
->function_name
);
4114 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4115 that has type BPTYPE and has no locations as yet. */
4117 static struct breakpoint
*
4118 set_raw_breakpoint_without_location (enum bptype bptype
)
4120 struct breakpoint
*b
, *b1
;
4122 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4123 memset (b
, 0, sizeof (*b
));
4126 b
->language
= current_language
->la_language
;
4127 b
->input_radix
= input_radix
;
4129 b
->enable_state
= bp_enabled
;
4132 b
->ignore_count
= 0;
4134 b
->frame_id
= null_frame_id
;
4135 b
->forked_inferior_pid
= null_ptid
;
4136 b
->exec_pathname
= NULL
;
4138 b
->condition_not_parsed
= 0;
4140 /* Add this breakpoint to the end of the chain
4141 so that a list of breakpoints will come out in order
4142 of increasing numbers. */
4144 b1
= breakpoint_chain
;
4146 breakpoint_chain
= b
;
4156 /* Initialize loc->function_name. */
4158 set_breakpoint_location_function (struct bp_location
*loc
)
4160 if (loc
->owner
->type
== bp_breakpoint
4161 || loc
->owner
->type
== bp_hardware_breakpoint
)
4163 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4165 if (loc
->function_name
)
4166 loc
->function_name
= xstrdup (loc
->function_name
);
4170 /* set_raw_breakpoint is a low level routine for allocating and
4171 partially initializing a breakpoint of type BPTYPE. The newly
4172 created breakpoint's address, section, source file name, and line
4173 number are provided by SAL. The newly created and partially
4174 initialized breakpoint is added to the breakpoint chain and
4175 is also returned as the value of this function.
4177 It is expected that the caller will complete the initialization of
4178 the newly created breakpoint struct as well as output any status
4179 information regarding the creation of a new breakpoint. In
4180 particular, set_raw_breakpoint does NOT set the breakpoint
4181 number! Care should be taken to not allow an error to occur
4182 prior to completing the initialization of the breakpoint. If this
4183 should happen, a bogus breakpoint will be left on the chain. */
4186 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4188 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4189 CORE_ADDR adjusted_address
;
4191 /* Adjust the breakpoint's address prior to allocating a location.
4192 Once we call allocate_bp_location(), that mostly uninitialized
4193 location will be placed on the location chain. Adjustment of the
4194 breakpoint may cause target_read_memory() to be called and we do
4195 not want its scan of the location chain to find a breakpoint and
4196 location that's only been partially initialized. */
4197 adjusted_address
= adjust_breakpoint_address (sal
.pc
, b
->type
);
4199 b
->loc
= allocate_bp_location (b
);
4200 b
->loc
->requested_address
= sal
.pc
;
4201 b
->loc
->address
= adjusted_address
;
4203 if (sal
.symtab
== NULL
)
4204 b
->source_file
= NULL
;
4206 b
->source_file
= savestring (sal
.symtab
->filename
,
4207 strlen (sal
.symtab
->filename
));
4208 b
->loc
->section
= sal
.section
;
4209 b
->line_number
= sal
.line
;
4211 set_breakpoint_location_function (b
->loc
);
4213 breakpoints_changed ();
4219 /* Note that the breakpoint object B describes a permanent breakpoint
4220 instruction, hard-wired into the inferior's code. */
4222 make_breakpoint_permanent (struct breakpoint
*b
)
4224 struct bp_location
*bl
;
4225 b
->enable_state
= bp_permanent
;
4227 /* By definition, permanent breakpoints are already present in the code.
4228 Mark all locations as inserted. For now, make_breakpoint_permanent
4229 is called in just one place, so it's hard to say if it's reasonable
4230 to have permanent breakpoint with multiple locations or not,
4231 but it's easy to implmement. */
4232 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4236 static struct breakpoint
*
4237 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4239 static int internal_breakpoint_number
= -1;
4240 struct symtab_and_line sal
;
4241 struct breakpoint
*b
;
4243 init_sal (&sal
); /* initialize to zeroes */
4246 sal
.section
= find_pc_overlay (sal
.pc
);
4248 b
= set_raw_breakpoint (sal
, type
);
4249 b
->number
= internal_breakpoint_number
--;
4250 b
->disposition
= disp_donttouch
;
4257 create_longjmp_breakpoint (char *func_name
)
4259 struct minimal_symbol
*m
;
4261 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4263 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4264 update_global_location_list (1);
4267 /* Call this routine when stepping and nexting to enable a breakpoint
4268 if we do a longjmp(). When we hit that breakpoint, call
4269 set_longjmp_resume_breakpoint() to figure out where we are going. */
4272 set_longjmp_breakpoint (void)
4274 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4276 create_longjmp_breakpoint ("longjmp");
4277 create_longjmp_breakpoint ("_longjmp");
4278 create_longjmp_breakpoint ("siglongjmp");
4279 create_longjmp_breakpoint ("_siglongjmp");
4283 /* Delete all longjmp breakpoints from THREAD. */
4285 delete_longjmp_breakpoint (int thread
)
4287 struct breakpoint
*b
, *temp
;
4289 ALL_BREAKPOINTS_SAFE (b
, temp
)
4290 if (b
->type
== bp_longjmp
)
4292 if (b
->thread
== thread
)
4293 delete_breakpoint (b
);
4298 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4300 struct breakpoint
*b
;
4301 struct minimal_symbol
*m
;
4303 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4306 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4308 b
->addr_string
= xstrdup (func_name
);
4310 if (overlay_debugging
== ovly_auto
)
4312 b
->enable_state
= bp_enabled
;
4313 overlay_events_enabled
= 1;
4317 b
->enable_state
= bp_disabled
;
4318 overlay_events_enabled
= 0;
4320 update_global_location_list (1);
4324 create_overlay_event_breakpoint (char *func_name
)
4326 struct objfile
*objfile
;
4327 ALL_OBJFILES (objfile
)
4328 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4332 enable_overlay_breakpoints (void)
4334 struct breakpoint
*b
;
4337 if (b
->type
== bp_overlay_event
)
4339 b
->enable_state
= bp_enabled
;
4340 update_global_location_list (1);
4341 overlay_events_enabled
= 1;
4346 disable_overlay_breakpoints (void)
4348 struct breakpoint
*b
;
4351 if (b
->type
== bp_overlay_event
)
4353 b
->enable_state
= bp_disabled
;
4354 update_global_location_list (0);
4355 overlay_events_enabled
= 0;
4360 create_thread_event_breakpoint (CORE_ADDR address
)
4362 struct breakpoint
*b
;
4364 b
= create_internal_breakpoint (address
, bp_thread_event
);
4366 b
->enable_state
= bp_enabled
;
4367 /* addr_string has to be used or breakpoint_re_set will delete me. */
4368 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4370 update_global_location_list_nothrow (1);
4376 remove_thread_event_breakpoints (void)
4378 struct breakpoint
*b
, *temp
;
4380 ALL_BREAKPOINTS_SAFE (b
, temp
)
4381 if (b
->type
== bp_thread_event
)
4382 delete_breakpoint (b
);
4385 struct captured_parse_breakpoint_args
4388 struct symtabs_and_lines
*sals_p
;
4389 char ***addr_string_p
;
4393 struct lang_and_radix
4401 remove_solib_event_breakpoints (void)
4403 struct breakpoint
*b
, *temp
;
4405 ALL_BREAKPOINTS_SAFE (b
, temp
)
4406 if (b
->type
== bp_shlib_event
)
4407 delete_breakpoint (b
);
4411 create_solib_event_breakpoint (CORE_ADDR address
)
4413 struct breakpoint
*b
;
4415 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4416 update_global_location_list_nothrow (1);
4420 /* Disable any breakpoints that are on code in shared libraries. Only
4421 apply to enabled breakpoints, disabled ones can just stay disabled. */
4424 disable_breakpoints_in_shlibs (void)
4426 struct bp_location
*loc
;
4428 ALL_BP_LOCATIONS (loc
)
4430 struct breakpoint
*b
= loc
->owner
;
4431 /* We apply the check to all breakpoints, including disabled
4432 for those with loc->duplicate set. This is so that when breakpoint
4433 becomes enabled, or the duplicate is removed, gdb will try to insert
4434 all breakpoints. If we don't set shlib_disabled here, we'll try
4435 to insert those breakpoints and fail. */
4436 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4437 && !loc
->shlib_disabled
4439 && PC_SOLIB (loc
->address
)
4441 && solib_address (loc
->address
)
4445 loc
->shlib_disabled
= 1;
4450 /* Disable any breakpoints that are in in an unloaded shared library. Only
4451 apply to enabled breakpoints, disabled ones can just stay disabled. */
4454 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4456 struct bp_location
*loc
;
4457 int disabled_shlib_breaks
= 0;
4459 /* SunOS a.out shared libraries are always mapped, so do not
4460 disable breakpoints; they will only be reported as unloaded
4461 through clear_solib when GDB discards its shared library
4462 list. See clear_solib for more information. */
4463 if (exec_bfd
!= NULL
4464 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4467 ALL_BP_LOCATIONS (loc
)
4469 struct breakpoint
*b
= loc
->owner
;
4470 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4471 || loc
->loc_type
== bp_loc_software_breakpoint
)
4472 && !loc
->shlib_disabled
)
4475 char *so_name
= PC_SOLIB (loc
->address
);
4477 char *so_name
= solib_address (loc
->address
);
4479 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4481 loc
->shlib_disabled
= 1;
4482 /* At this point, we cannot rely on remove_breakpoint
4483 succeeding so we must mark the breakpoint as not inserted
4484 to prevent future errors occurring in remove_breakpoints. */
4486 if (!disabled_shlib_breaks
)
4488 target_terminal_ours_for_output ();
4489 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4492 disabled_shlib_breaks
= 1;
4498 /* FORK & VFORK catchpoints. */
4500 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4503 insert_catch_fork (struct breakpoint
*b
)
4505 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4508 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4511 remove_catch_fork (struct breakpoint
*b
)
4513 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4516 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4520 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4522 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4525 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4527 static enum print_stop_action
4528 print_it_catch_fork (struct breakpoint
*b
)
4530 annotate_catchpoint (b
->number
);
4531 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4532 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4533 return PRINT_SRC_AND_LOC
;
4536 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4539 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4541 struct value_print_options opts
;
4543 get_user_print_options (&opts
);
4545 /* Field 4, the address, is omitted (which makes the columns
4546 not line up too nicely with the headers, but the effect
4547 is relatively readable). */
4548 if (opts
.addressprint
)
4549 ui_out_field_skip (uiout
, "addr");
4551 ui_out_text (uiout
, "fork");
4552 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4554 ui_out_text (uiout
, ", process ");
4555 ui_out_field_int (uiout
, "what",
4556 ptid_get_pid (b
->forked_inferior_pid
));
4557 ui_out_spaces (uiout
, 1);
4561 /* Implement the "print_mention" breakpoint_ops method for fork
4565 print_mention_catch_fork (struct breakpoint
*b
)
4567 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4570 /* The breakpoint_ops structure to be used in fork catchpoints. */
4572 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4576 breakpoint_hit_catch_fork
,
4577 print_it_catch_fork
,
4578 print_one_catch_fork
,
4579 print_mention_catch_fork
4582 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4585 insert_catch_vfork (struct breakpoint
*b
)
4587 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4590 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4593 remove_catch_vfork (struct breakpoint
*b
)
4595 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4598 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4602 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4604 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4607 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4609 static enum print_stop_action
4610 print_it_catch_vfork (struct breakpoint
*b
)
4612 annotate_catchpoint (b
->number
);
4613 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4614 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4615 return PRINT_SRC_AND_LOC
;
4618 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4621 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4623 struct value_print_options opts
;
4625 get_user_print_options (&opts
);
4626 /* Field 4, the address, is omitted (which makes the columns
4627 not line up too nicely with the headers, but the effect
4628 is relatively readable). */
4629 if (opts
.addressprint
)
4630 ui_out_field_skip (uiout
, "addr");
4632 ui_out_text (uiout
, "vfork");
4633 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4635 ui_out_text (uiout
, ", process ");
4636 ui_out_field_int (uiout
, "what",
4637 ptid_get_pid (b
->forked_inferior_pid
));
4638 ui_out_spaces (uiout
, 1);
4642 /* Implement the "print_mention" breakpoint_ops method for vfork
4646 print_mention_catch_vfork (struct breakpoint
*b
)
4648 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4651 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4653 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4657 breakpoint_hit_catch_vfork
,
4658 print_it_catch_vfork
,
4659 print_one_catch_vfork
,
4660 print_mention_catch_vfork
4663 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4665 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4666 If COND_STRING is not NULL, then store it in the breakpoint.
4667 OPS, if not NULL, is the breakpoint_ops structure associated
4668 to the catchpoint. */
4670 static struct breakpoint
*
4671 create_catchpoint (int tempflag
, char *cond_string
,
4672 struct breakpoint_ops
*ops
)
4674 struct symtab_and_line sal
;
4675 struct breakpoint
*b
;
4682 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4683 set_breakpoint_count (breakpoint_count
+ 1);
4684 b
->number
= breakpoint_count
;
4686 b
->cond_string
= (cond_string
== NULL
) ?
4687 NULL
: savestring (cond_string
, strlen (cond_string
));
4689 b
->addr_string
= NULL
;
4690 b
->enable_state
= bp_enabled
;
4691 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4695 update_global_location_list (1);
4701 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4702 struct breakpoint_ops
*ops
)
4704 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4706 /* FIXME: We should put this information in a breakpoint private data
4708 b
->forked_inferior_pid
= null_ptid
;
4711 /* Exec catchpoints. */
4714 insert_catch_exec (struct breakpoint
*b
)
4716 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4720 remove_catch_exec (struct breakpoint
*b
)
4722 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4726 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4728 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4731 static enum print_stop_action
4732 print_it_catch_exec (struct breakpoint
*b
)
4734 annotate_catchpoint (b
->number
);
4735 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4737 return PRINT_SRC_AND_LOC
;
4741 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4743 struct value_print_options opts
;
4745 get_user_print_options (&opts
);
4747 /* Field 4, the address, is omitted (which makes the columns
4748 not line up too nicely with the headers, but the effect
4749 is relatively readable). */
4750 if (opts
.addressprint
)
4751 ui_out_field_skip (uiout
, "addr");
4753 ui_out_text (uiout
, "exec");
4754 if (b
->exec_pathname
!= NULL
)
4756 ui_out_text (uiout
, ", program \"");
4757 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4758 ui_out_text (uiout
, "\" ");
4763 print_mention_catch_exec (struct breakpoint
*b
)
4765 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4768 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4772 breakpoint_hit_catch_exec
,
4773 print_it_catch_exec
,
4774 print_one_catch_exec
,
4775 print_mention_catch_exec
4779 hw_breakpoint_used_count (void)
4781 struct breakpoint
*b
;
4786 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4794 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4796 struct breakpoint
*b
;
4799 *other_type_used
= 0;
4802 if (breakpoint_enabled (b
))
4804 if (b
->type
== type
)
4806 else if ((b
->type
== bp_hardware_watchpoint
||
4807 b
->type
== bp_read_watchpoint
||
4808 b
->type
== bp_access_watchpoint
))
4809 *other_type_used
= 1;
4816 disable_watchpoints_before_interactive_call_start (void)
4818 struct breakpoint
*b
;
4822 if (((b
->type
== bp_watchpoint
)
4823 || (b
->type
== bp_hardware_watchpoint
)
4824 || (b
->type
== bp_read_watchpoint
)
4825 || (b
->type
== bp_access_watchpoint
))
4826 && breakpoint_enabled (b
))
4828 b
->enable_state
= bp_call_disabled
;
4829 update_global_location_list (0);
4835 enable_watchpoints_after_interactive_call_stop (void)
4837 struct breakpoint
*b
;
4841 if (((b
->type
== bp_watchpoint
)
4842 || (b
->type
== bp_hardware_watchpoint
)
4843 || (b
->type
== bp_read_watchpoint
)
4844 || (b
->type
== bp_access_watchpoint
))
4845 && (b
->enable_state
== bp_call_disabled
))
4847 b
->enable_state
= bp_enabled
;
4848 update_global_location_list (1);
4854 /* Set a breakpoint that will evaporate an end of command
4855 at address specified by SAL.
4856 Restrict it to frame FRAME if FRAME is nonzero. */
4859 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4862 struct breakpoint
*b
;
4863 b
= set_raw_breakpoint (sal
, type
);
4864 b
->enable_state
= bp_enabled
;
4865 b
->disposition
= disp_donttouch
;
4866 b
->frame_id
= frame_id
;
4868 /* If we're debugging a multi-threaded program, then we
4869 want momentary breakpoints to be active in only a
4870 single thread of control. */
4871 if (in_thread_list (inferior_ptid
))
4872 b
->thread
= pid_to_thread_id (inferior_ptid
);
4874 update_global_location_list_nothrow (1);
4880 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4882 struct symtab_and_line sal
;
4884 sal
= find_pc_line (pc
, 0);
4886 sal
.section
= find_pc_overlay (pc
);
4887 sal
.explicit_pc
= 1;
4889 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4893 /* Tell the user we have just set a breakpoint B. */
4896 mention (struct breakpoint
*b
)
4899 struct cleanup
*ui_out_chain
;
4900 struct value_print_options opts
;
4902 get_user_print_options (&opts
);
4904 /* FIXME: This is misplaced; mention() is called by things (like
4905 hitting a watchpoint) other than breakpoint creation. It should
4906 be possible to clean this up and at the same time replace the
4907 random calls to breakpoint_changed with this hook. */
4908 observer_notify_breakpoint_created (b
->number
);
4910 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4911 b
->ops
->print_mention (b
);
4916 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4919 ui_out_text (uiout
, "Watchpoint ");
4920 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4921 ui_out_field_int (uiout
, "number", b
->number
);
4922 ui_out_text (uiout
, ": ");
4923 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4924 do_cleanups (ui_out_chain
);
4926 case bp_hardware_watchpoint
:
4927 ui_out_text (uiout
, "Hardware watchpoint ");
4928 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4929 ui_out_field_int (uiout
, "number", b
->number
);
4930 ui_out_text (uiout
, ": ");
4931 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4932 do_cleanups (ui_out_chain
);
4934 case bp_read_watchpoint
:
4935 ui_out_text (uiout
, "Hardware read watchpoint ");
4936 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4937 ui_out_field_int (uiout
, "number", b
->number
);
4938 ui_out_text (uiout
, ": ");
4939 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4940 do_cleanups (ui_out_chain
);
4942 case bp_access_watchpoint
:
4943 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4944 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4945 ui_out_field_int (uiout
, "number", b
->number
);
4946 ui_out_text (uiout
, ": ");
4947 ui_out_field_string (uiout
, "exp", b
->exp_string
);
4948 do_cleanups (ui_out_chain
);
4951 if (ui_out_is_mi_like_p (uiout
))
4956 if (b
->disposition
== disp_del
)
4957 printf_filtered (_("Temporary breakpoint"));
4959 printf_filtered (_("Breakpoint"));
4960 printf_filtered (_(" %d"), b
->number
);
4963 case bp_hardware_breakpoint
:
4964 if (ui_out_is_mi_like_p (uiout
))
4969 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4976 case bp_longjmp_resume
:
4977 case bp_step_resume
:
4979 case bp_watchpoint_scope
:
4980 case bp_shlib_event
:
4981 case bp_thread_event
:
4982 case bp_overlay_event
:
4988 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4992 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4996 if (opts
.addressprint
|| b
->source_file
== NULL
)
4998 printf_filtered (" at ");
4999 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5002 printf_filtered (": file %s, line %d.",
5003 b
->source_file
, b
->line_number
);
5007 struct bp_location
*loc
= b
->loc
;
5009 for (; loc
; loc
= loc
->next
)
5011 printf_filtered (" (%d locations)", n
);
5016 if (ui_out_is_mi_like_p (uiout
))
5018 printf_filtered ("\n");
5022 static struct bp_location
*
5023 add_location_to_breakpoint (struct breakpoint
*b
,
5024 const struct symtab_and_line
*sal
)
5026 struct bp_location
*loc
, **tmp
;
5028 loc
= allocate_bp_location (b
);
5029 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5032 loc
->requested_address
= sal
->pc
;
5033 loc
->address
= adjust_breakpoint_address (loc
->requested_address
, b
->type
);
5034 loc
->section
= sal
->section
;
5036 set_breakpoint_location_function (loc
);
5041 /* Return 1 if LOC is pointing to a permanent breakpoint,
5042 return 0 otherwise. */
5045 bp_loc_is_permanent (struct bp_location
*loc
)
5049 const gdb_byte
*brk
;
5050 gdb_byte
*target_mem
;
5051 struct cleanup
*cleanup
;
5054 gdb_assert (loc
!= NULL
);
5056 addr
= loc
->address
;
5057 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5059 /* Software breakpoints unsupported? */
5063 target_mem
= alloca (len
);
5065 /* Enable the automatic memory restoration from breakpoints while
5066 we read the memory. Otherwise we could say about our temporary
5067 breakpoints they are permanent. */
5068 cleanup
= make_show_memory_breakpoints_cleanup (0);
5070 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5071 && memcmp (target_mem
, brk
, len
) == 0)
5074 do_cleanups (cleanup
);
5081 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5082 as textual description of the location, and COND_STRING
5083 as condition expression. */
5086 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5088 enum bptype type
, enum bpdisp disposition
,
5089 int thread
, int ignore_count
,
5090 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5092 struct breakpoint
*b
= NULL
;
5095 if (type
== bp_hardware_breakpoint
)
5097 int i
= hw_breakpoint_used_count ();
5098 int target_resources_ok
=
5099 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5101 if (target_resources_ok
== 0)
5102 error (_("No hardware breakpoint support in the target."));
5103 else if (target_resources_ok
< 0)
5104 error (_("Hardware breakpoints used exceeds limit."));
5107 for (i
= 0; i
< sals
.nelts
; ++i
)
5109 struct symtab_and_line sal
= sals
.sals
[i
];
5110 struct bp_location
*loc
;
5113 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5117 b
= set_raw_breakpoint (sal
, type
);
5118 set_breakpoint_count (breakpoint_count
+ 1);
5119 b
->number
= breakpoint_count
;
5122 b
->cond_string
= cond_string
;
5123 b
->ignore_count
= ignore_count
;
5124 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5125 b
->disposition
= disposition
;
5131 loc
= add_location_to_breakpoint (b
, &sal
);
5134 if (bp_loc_is_permanent (loc
))
5135 make_breakpoint_permanent (b
);
5139 char *arg
= b
->cond_string
;
5140 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5142 error (_("Garbage %s follows condition"), arg
);
5147 b
->addr_string
= addr_string
;
5149 /* addr_string has to be used or breakpoint_re_set will delete
5151 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5157 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5158 elements to fill the void space. */
5160 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5162 int i
= index_to_remove
+1;
5163 int last_index
= sal
->nelts
-1;
5165 for (;i
<= last_index
; ++i
)
5166 sal
->sals
[i
-1] = sal
->sals
[i
];
5171 /* If appropriate, obtains all sals that correspond
5172 to the same file and line as SAL. This is done
5173 only if SAL does not have explicit PC and has
5174 line and file information. If we got just a single
5175 expanded sal, return the original.
5177 Otherwise, if SAL.explicit_line is not set, filter out
5178 all sals for which the name of enclosing function
5179 is different from SAL. This makes sure that if we have
5180 breakpoint originally set in template instantiation, say
5181 foo<int>(), we won't expand SAL to locations at the same
5182 line in all existing instantiations of 'foo'.
5185 static struct symtabs_and_lines
5186 expand_line_sal_maybe (struct symtab_and_line sal
)
5188 struct symtabs_and_lines expanded
;
5189 CORE_ADDR original_pc
= sal
.pc
;
5190 char *original_function
= NULL
;
5194 /* If we have explicit pc, don't expand.
5195 If we have no line number, we can't expand. */
5196 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5199 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5200 expanded
.sals
[0] = sal
;
5205 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5207 expanded
= expand_line_sal (sal
);
5208 if (expanded
.nelts
== 1)
5210 /* We had one sal, we got one sal. Without futher
5211 processing, just return the original sal. */
5212 xfree (expanded
.sals
);
5214 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5215 sal
.pc
= original_pc
;
5216 expanded
.sals
[0] = sal
;
5220 if (!sal
.explicit_line
)
5222 CORE_ADDR func_addr
, func_end
;
5223 for (i
= 0; i
< expanded
.nelts
; ++i
)
5225 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5226 char *this_function
;
5227 if (find_pc_partial_function (pc
, &this_function
,
5228 &func_addr
, &func_end
))
5230 if (this_function
&&
5231 strcmp (this_function
, original_function
) != 0)
5233 remove_sal (&expanded
, i
);
5236 else if (func_addr
== pc
)
5238 /* We're at beginning of a function, and should
5240 struct symbol
*sym
= find_pc_function (pc
);
5242 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5245 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5252 if (expanded
.nelts
<= 1)
5254 /* This is un ugly workaround. If we get zero
5255 expanded sals then something is really wrong.
5256 Fix that by returnign the original sal. */
5257 xfree (expanded
.sals
);
5259 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5260 sal
.pc
= original_pc
;
5261 expanded
.sals
[0] = sal
;
5268 for (i
= 0; i
< expanded
.nelts
; ++i
)
5269 if (expanded
.sals
[i
].pc
== original_pc
)
5280 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5281 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5282 value. COND_STRING, if not NULL, specified the condition to be
5283 used for all breakpoints. Essentially the only case where
5284 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5285 function. In that case, it's still not possible to specify
5286 separate conditions for different overloaded functions, so
5287 we take just a single condition string.
5289 NOTE: If the function succeeds, the caller is expected to cleanup
5290 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5291 array contents). If the function fails (error() is called), the
5292 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5293 COND and SALS arrays and each of those arrays contents. */
5296 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5298 enum bptype type
, enum bpdisp disposition
,
5299 int thread
, int ignore_count
,
5300 struct breakpoint_ops
*ops
, int from_tty
,
5304 for (i
= 0; i
< sals
.nelts
; ++i
)
5306 struct symtabs_and_lines expanded
=
5307 expand_line_sal_maybe (sals
.sals
[i
]);
5309 create_breakpoint (expanded
, addr_string
[i
],
5310 cond_string
, type
, disposition
,
5311 thread
, ignore_count
, ops
, from_tty
, enabled
);
5314 update_global_location_list (1);
5317 /* Parse ARG which is assumed to be a SAL specification possibly
5318 followed by conditionals. On return, SALS contains an array of SAL
5319 addresses found. ADDR_STRING contains a vector of (canonical)
5320 address strings. ARG points to the end of the SAL. */
5323 parse_breakpoint_sals (char **address
,
5324 struct symtabs_and_lines
*sals
,
5325 char ***addr_string
,
5328 char *addr_start
= *address
;
5329 *addr_string
= NULL
;
5330 /* If no arg given, or if first arg is 'if ', use the default
5332 if ((*address
) == NULL
5333 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5335 if (default_breakpoint_valid
)
5337 struct symtab_and_line sal
;
5338 init_sal (&sal
); /* initialize to zeroes */
5339 sals
->sals
= (struct symtab_and_line
*)
5340 xmalloc (sizeof (struct symtab_and_line
));
5341 sal
.pc
= default_breakpoint_address
;
5342 sal
.line
= default_breakpoint_line
;
5343 sal
.symtab
= default_breakpoint_symtab
;
5344 sal
.section
= find_pc_overlay (sal
.pc
);
5345 sals
->sals
[0] = sal
;
5349 error (_("No default breakpoint address now."));
5353 /* Force almost all breakpoints to be in terms of the
5354 current_source_symtab (which is decode_line_1's default). This
5355 should produce the results we want almost all of the time while
5356 leaving default_breakpoint_* alone.
5357 ObjC: However, don't match an Objective-C method name which
5358 may have a '+' or '-' succeeded by a '[' */
5360 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5362 if (default_breakpoint_valid
5364 || ((strchr ("+-", (*address
)[0]) != NULL
)
5365 && ((*address
)[1] != '['))))
5366 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5367 default_breakpoint_line
, addr_string
,
5370 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5371 addr_string
, not_found_ptr
);
5373 /* For any SAL that didn't have a canonical string, fill one in. */
5374 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5375 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5376 if (addr_start
!= (*address
))
5379 for (i
= 0; i
< sals
->nelts
; i
++)
5381 /* Add the string if not present. */
5382 if ((*addr_string
)[i
] == NULL
)
5383 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5389 /* Convert each SAL into a real PC. Verify that the PC can be
5390 inserted as a breakpoint. If it can't throw an error. */
5393 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5397 for (i
= 0; i
< sals
->nelts
; i
++)
5398 resolve_sal_pc (&sals
->sals
[i
]);
5402 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5404 struct captured_parse_breakpoint_args
*args
= data
;
5406 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5407 args
->not_found_ptr
);
5410 /* Given TOK, a string specification of condition and thread, as
5411 accepted by the 'break' command, extract the condition
5412 string and thread number and set *COND_STRING and *THREAD.
5413 PC identifies the context at which the condition should be parsed.
5414 If no condition is found, *COND_STRING is set to NULL.
5415 If no thread is found, *THREAD is set to -1. */
5417 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5418 char **cond_string
, int *thread
)
5420 *cond_string
= NULL
;
5426 char *cond_start
= NULL
;
5427 char *cond_end
= NULL
;
5428 while (*tok
== ' ' || *tok
== '\t')
5433 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5436 toklen
= end_tok
- tok
;
5438 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5440 struct expression
*expr
;
5442 tok
= cond_start
= end_tok
+ 1;
5443 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5446 *cond_string
= savestring (cond_start
,
5447 cond_end
- cond_start
);
5449 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5455 *thread
= strtol (tok
, &tok
, 0);
5457 error (_("Junk after thread keyword."));
5458 if (!valid_thread_id (*thread
))
5459 error (_("Unknown thread %d."), *thread
);
5462 error (_("Junk at end of arguments."));
5466 /* Set a breakpoint. This function is shared between
5467 CLI and MI functions for setting a breakpoint.
5468 This function has two major modes of operations,
5469 selected by the PARSE_CONDITION_AND_THREAD parameter.
5470 If non-zero, the function will parse arg, extracting
5471 breakpoint location, address and thread. Otherwise,
5472 ARG is just the location of breakpoint, with condition
5473 and thread specified by the COND_STRING and THREAD
5477 break_command_really (char *arg
, char *cond_string
, int thread
,
5478 int parse_condition_and_thread
,
5479 int tempflag
, int hardwareflag
,
5481 enum auto_boolean pending_break_support
,
5482 struct breakpoint_ops
*ops
,
5486 struct gdb_exception e
;
5487 struct symtabs_and_lines sals
;
5488 struct symtab_and_line pending_sal
;
5491 char *addr_start
= arg
;
5493 struct cleanup
*old_chain
;
5494 struct cleanup
*breakpoint_chain
= NULL
;
5495 struct captured_parse_breakpoint_args parse_args
;
5504 parse_args
.arg_p
= &arg
;
5505 parse_args
.sals_p
= &sals
;
5506 parse_args
.addr_string_p
= &addr_string
;
5507 parse_args
.not_found_ptr
= ¬_found
;
5509 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5510 &parse_args
, RETURN_MASK_ALL
);
5512 /* If caller is interested in rc value from parse, set value. */
5516 throw_exception (e
);
5520 case NOT_FOUND_ERROR
:
5522 /* If pending breakpoint support is turned off, throw
5525 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5526 throw_exception (e
);
5528 exception_print (gdb_stderr
, e
);
5530 /* If pending breakpoint support is auto query and the user
5531 selects no, then simply return the error code. */
5532 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5533 !nquery ("Make breakpoint pending on future shared library load? "))
5536 /* At this point, either the user was queried about setting
5537 a pending breakpoint and selected yes, or pending
5538 breakpoint behavior is on and thus a pending breakpoint
5539 is defaulted on behalf of the user. */
5540 copy_arg
= xstrdup (addr_start
);
5541 addr_string
= ©_arg
;
5543 sals
.sals
= &pending_sal
;
5548 throw_exception (e
);
5555 /* Create a chain of things that always need to be cleaned up. */
5556 old_chain
= make_cleanup (null_cleanup
, 0);
5560 /* Make sure that all storage allocated to SALS gets freed. */
5561 make_cleanup (xfree
, sals
.sals
);
5563 /* Cleanup the addr_string array but not its contents. */
5564 make_cleanup (xfree
, addr_string
);
5567 /* ----------------------------- SNIP -----------------------------
5568 Anything added to the cleanup chain beyond this point is assumed
5569 to be part of a breakpoint. If the breakpoint create succeeds
5570 then the memory is not reclaimed. */
5571 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5573 /* Mark the contents of the addr_string for cleanup. These go on
5574 the breakpoint_chain and only occure if the breakpoint create
5576 for (i
= 0; i
< sals
.nelts
; i
++)
5578 if (addr_string
[i
] != NULL
)
5579 make_cleanup (xfree
, addr_string
[i
]);
5582 /* Resolve all line numbers to PC's and verify that the addresses
5583 are ok for the target. */
5585 breakpoint_sals_to_pc (&sals
, addr_start
);
5587 /* Verify that condition can be parsed, before setting any
5588 breakpoints. Allocate a separate condition expression for each
5592 if (parse_condition_and_thread
)
5594 /* Here we only parse 'arg' to separate condition
5595 from thread number, so parsing in context of first
5596 sal is OK. When setting the breakpoint we'll
5597 re-parse it in context of each sal. */
5600 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5602 make_cleanup (xfree
, cond_string
);
5606 /* Create a private copy of condition string. */
5609 cond_string
= xstrdup (cond_string
);
5610 make_cleanup (xfree
, cond_string
);
5613 create_breakpoints (sals
, addr_string
, cond_string
,
5614 hardwareflag
? bp_hardware_breakpoint
5616 tempflag
? disp_del
: disp_donttouch
,
5617 thread
, ignore_count
, ops
, from_tty
, enabled
);
5621 struct symtab_and_line sal
= {0};
5622 struct breakpoint
*b
;
5624 make_cleanup (xfree
, copy_arg
);
5626 b
= set_raw_breakpoint_without_location (hardwareflag
5627 ? bp_hardware_breakpoint
5629 set_breakpoint_count (breakpoint_count
+ 1);
5630 b
->number
= breakpoint_count
;
5632 b
->addr_string
= addr_string
[0];
5633 b
->cond_string
= NULL
;
5634 b
->ignore_count
= ignore_count
;
5635 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5636 b
->condition_not_parsed
= 1;
5638 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5640 update_global_location_list (1);
5645 warning (_("Multiple breakpoints were set.\n"
5646 "Use the \"delete\" command to delete unwanted breakpoints."));
5647 /* That's it. Discard the cleanups for data inserted into the
5649 discard_cleanups (breakpoint_chain
);
5650 /* But cleanup everything else. */
5651 do_cleanups (old_chain
);
5654 /* Set a breakpoint.
5655 ARG is a string describing breakpoint address,
5656 condition, and thread.
5657 FLAG specifies if a breakpoint is hardware on,
5658 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5662 break_command_1 (char *arg
, int flag
, int from_tty
)
5664 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5665 int tempflag
= flag
& BP_TEMPFLAG
;
5667 break_command_really (arg
,
5668 NULL
, 0, 1 /* parse arg */,
5669 tempflag
, hardwareflag
,
5670 0 /* Ignore count */,
5671 pending_break_support
,
5672 NULL
/* breakpoint_ops */,
5679 set_breakpoint (char *address
, char *condition
,
5680 int hardwareflag
, int tempflag
,
5681 int thread
, int ignore_count
,
5682 int pending
, int enabled
)
5684 break_command_really (address
, condition
, thread
,
5685 0 /* condition and thread are valid. */,
5686 tempflag
, hardwareflag
,
5689 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5693 /* Adjust SAL to the first instruction past the function prologue.
5694 The end of the prologue is determined using the line table from
5695 the debugging information.
5697 If SAL is already past the prologue, then do nothing. */
5700 skip_prologue_sal (struct symtab_and_line
*sal
)
5702 struct symbol
*sym
= find_pc_function (sal
->pc
);
5703 struct symtab_and_line start_sal
;
5708 start_sal
= find_function_start_sal (sym
, 1);
5709 if (sal
->pc
< start_sal
.pc
)
5713 /* Helper function for break_command_1 and disassemble_command. */
5716 resolve_sal_pc (struct symtab_and_line
*sal
)
5720 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5722 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5723 error (_("No line %d in file \"%s\"."),
5724 sal
->line
, sal
->symtab
->filename
);
5727 /* If this SAL corresponds to a breakpoint inserted using
5728 a line number, then skip the function prologue if necessary. */
5729 if (sal
->explicit_line
)
5730 skip_prologue_sal (sal
);
5733 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5735 struct blockvector
*bv
;
5739 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5742 sym
= block_linkage_function (b
);
5745 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5746 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5750 /* It really is worthwhile to have the section, so we'll just
5751 have to look harder. This case can be executed if we have
5752 line numbers but no functions (as can happen in assembly
5755 struct minimal_symbol
*msym
;
5757 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5759 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5766 break_command (char *arg
, int from_tty
)
5768 break_command_1 (arg
, 0, from_tty
);
5772 tbreak_command (char *arg
, int from_tty
)
5774 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5778 hbreak_command (char *arg
, int from_tty
)
5780 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5784 thbreak_command (char *arg
, int from_tty
)
5786 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5790 stop_command (char *arg
, int from_tty
)
5792 printf_filtered (_("Specify the type of breakpoint to set.\n\
5793 Usage: stop in <function | address>\n\
5794 stop at <line>\n"));
5798 stopin_command (char *arg
, int from_tty
)
5802 if (arg
== (char *) NULL
)
5804 else if (*arg
!= '*')
5809 /* look for a ':'. If this is a line number specification, then
5810 say it is bad, otherwise, it should be an address or
5811 function/method name */
5812 while (*argptr
&& !hasColon
)
5814 hasColon
= (*argptr
== ':');
5819 badInput
= (*argptr
!= ':'); /* Not a class::method */
5821 badInput
= isdigit (*arg
); /* a simple line number */
5825 printf_filtered (_("Usage: stop in <function | address>\n"));
5827 break_command_1 (arg
, 0, from_tty
);
5831 stopat_command (char *arg
, int from_tty
)
5835 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5842 /* look for a ':'. If there is a '::' then get out, otherwise
5843 it is probably a line number. */
5844 while (*argptr
&& !hasColon
)
5846 hasColon
= (*argptr
== ':');
5851 badInput
= (*argptr
== ':'); /* we have class::method */
5853 badInput
= !isdigit (*arg
); /* not a line number */
5857 printf_filtered (_("Usage: stop at <line>\n"));
5859 break_command_1 (arg
, 0, from_tty
);
5862 /* accessflag: hw_write: watch write,
5863 hw_read: watch read,
5864 hw_access: watch access (read or write) */
5866 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5868 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5869 struct symtab_and_line sal
;
5870 struct expression
*exp
;
5871 struct block
*exp_valid_block
;
5872 struct value
*val
, *mark
;
5873 struct frame_info
*frame
;
5874 struct frame_info
*prev_frame
= NULL
;
5875 char *exp_start
= NULL
;
5876 char *exp_end
= NULL
;
5877 char *tok
, *id_tok_start
, *end_tok
;
5879 char *cond_start
= NULL
;
5880 char *cond_end
= NULL
;
5881 struct expression
*cond
= NULL
;
5882 int i
, other_type_used
, target_resources_ok
= 0;
5883 enum bptype bp_type
;
5887 init_sal (&sal
); /* initialize to zeroes */
5889 /* Make sure that we actually have parameters to parse. */
5890 if (arg
!= NULL
&& arg
[0] != '\0')
5892 toklen
= strlen (arg
); /* Size of argument list. */
5894 /* Points tok to the end of the argument list. */
5895 tok
= arg
+ toklen
- 1;
5897 /* Go backwards in the parameters list. Skip the last parameter.
5898 If we're expecting a 'thread <thread_num>' parameter, this should
5899 be the thread identifier. */
5900 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5902 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5905 /* Points end_tok to the beginning of the last token. */
5906 id_tok_start
= tok
+ 1;
5908 /* Go backwards in the parameters list. Skip one more parameter.
5909 If we're expecting a 'thread <thread_num>' parameter, we should
5910 reach a "thread" token. */
5911 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5916 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5919 /* Move the pointer forward to skip the whitespace and
5920 calculate the length of the token. */
5922 toklen
= end_tok
- tok
;
5924 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5926 /* At this point we've found a "thread" token, which means
5927 the user is trying to set a watchpoint that triggers
5928 only in a specific thread. */
5931 /* Extract the thread ID from the next token. */
5932 thread
= strtol (id_tok_start
, &endp
, 0);
5934 /* Check if the user provided a valid numeric value for the
5936 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5937 error (_("Invalid thread ID specification %s."), id_tok_start
);
5939 /* Check if the thread actually exists. */
5940 if (!valid_thread_id (thread
))
5941 error (_("Unknown thread %d."), thread
);
5943 /* Truncate the string and get rid of the thread <thread_num>
5944 parameter before the parameter list is parsed by the
5945 evaluate_expression() function. */
5950 /* Parse the rest of the arguments. */
5951 innermost_block
= NULL
;
5953 exp
= parse_exp_1 (&arg
, 0, 0);
5955 /* Remove trailing whitespace from the expression before saving it.
5956 This makes the eventual display of the expression string a bit
5958 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
5961 exp_valid_block
= innermost_block
;
5962 mark
= value_mark ();
5963 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5965 release_value (val
);
5968 while (*tok
== ' ' || *tok
== '\t')
5972 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5975 toklen
= end_tok
- tok
;
5976 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5978 tok
= cond_start
= end_tok
+ 1;
5979 cond
= parse_exp_1 (&tok
, 0, 0);
5983 error (_("Junk at end of command."));
5985 if (accessflag
== hw_read
)
5986 bp_type
= bp_read_watchpoint
;
5987 else if (accessflag
== hw_access
)
5988 bp_type
= bp_access_watchpoint
;
5990 bp_type
= bp_hardware_watchpoint
;
5992 mem_cnt
= can_use_hardware_watchpoint (val
);
5993 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5994 error (_("Expression cannot be implemented with read/access watchpoint."));
5997 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5998 target_resources_ok
=
5999 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6001 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6002 error (_("Target does not support this type of hardware watchpoint."));
6004 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6005 error (_("Target can only support one kind of HW watchpoint at a time."));
6008 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6009 watchpoint could not be set. */
6010 if (!mem_cnt
|| target_resources_ok
<= 0)
6011 bp_type
= bp_watchpoint
;
6013 frame
= block_innermost_frame (exp_valid_block
);
6015 prev_frame
= get_prev_frame (frame
);
6019 /* If the expression is "local", then set up a "watchpoint scope"
6020 breakpoint at the point where we've left the scope of the watchpoint
6021 expression. Create the scope breakpoint before the watchpoint, so
6022 that we will encounter it first in bpstat_stop_status. */
6023 if (innermost_block
&& prev_frame
)
6025 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6026 bp_watchpoint_scope
);
6028 scope_breakpoint
->enable_state
= bp_enabled
;
6030 /* Automatically delete the breakpoint when it hits. */
6031 scope_breakpoint
->disposition
= disp_del
;
6033 /* Only break in the proper frame (help with recursion). */
6034 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6036 /* Set the address at which we will stop. */
6037 scope_breakpoint
->loc
->requested_address
6038 = get_frame_pc (prev_frame
);
6039 scope_breakpoint
->loc
->address
6040 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6041 scope_breakpoint
->type
);
6044 /* Now set up the breakpoint. */
6045 b
= set_raw_breakpoint (sal
, bp_type
);
6046 set_breakpoint_count (breakpoint_count
+ 1);
6047 b
->number
= breakpoint_count
;
6049 b
->disposition
= disp_donttouch
;
6051 b
->exp_valid_block
= exp_valid_block
;
6052 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6055 b
->loc
->cond
= cond
;
6057 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6062 b
->watchpoint_frame
= get_frame_id (frame
);
6064 b
->watchpoint_frame
= null_frame_id
;
6066 if (scope_breakpoint
!= NULL
)
6068 /* The scope breakpoint is related to the watchpoint. We will
6069 need to act on them together. */
6070 b
->related_breakpoint
= scope_breakpoint
;
6071 scope_breakpoint
->related_breakpoint
= b
;
6074 value_free_to_mark (mark
);
6076 update_global_location_list (1);
6079 /* Return count of locations need to be watched and can be handled
6080 in hardware. If the watchpoint can not be handled
6081 in hardware return zero. */
6084 can_use_hardware_watchpoint (struct value
*v
)
6086 int found_memory_cnt
= 0;
6087 struct value
*head
= v
;
6089 /* Did the user specifically forbid us to use hardware watchpoints? */
6090 if (!can_use_hw_watchpoints
)
6093 /* Make sure that the value of the expression depends only upon
6094 memory contents, and values computed from them within GDB. If we
6095 find any register references or function calls, we can't use a
6096 hardware watchpoint.
6098 The idea here is that evaluating an expression generates a series
6099 of values, one holding the value of every subexpression. (The
6100 expression a*b+c has five subexpressions: a, b, a*b, c, and
6101 a*b+c.) GDB's values hold almost enough information to establish
6102 the criteria given above --- they identify memory lvalues,
6103 register lvalues, computed values, etcetera. So we can evaluate
6104 the expression, and then scan the chain of values that leaves
6105 behind to decide whether we can detect any possible change to the
6106 expression's final value using only hardware watchpoints.
6108 However, I don't think that the values returned by inferior
6109 function calls are special in any way. So this function may not
6110 notice that an expression involving an inferior function call
6111 can't be watched with hardware watchpoints. FIXME. */
6112 for (; v
; v
= value_next (v
))
6114 if (VALUE_LVAL (v
) == lval_memory
)
6117 /* A lazy memory lvalue is one that GDB never needed to fetch;
6118 we either just used its address (e.g., `a' in `a.b') or
6119 we never needed it at all (e.g., `a' in `a,b'). */
6123 /* Ahh, memory we actually used! Check if we can cover
6124 it with hardware watchpoints. */
6125 struct type
*vtype
= check_typedef (value_type (v
));
6127 /* We only watch structs and arrays if user asked for it
6128 explicitly, never if they just happen to appear in a
6129 middle of some value chain. */
6131 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6132 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6134 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6135 int len
= TYPE_LENGTH (value_type (v
));
6137 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6144 else if (VALUE_LVAL (v
) != not_lval
6145 && deprecated_value_modifiable (v
) == 0)
6146 return 0; /* ??? What does this represent? */
6147 else if (VALUE_LVAL (v
) == lval_register
)
6148 return 0; /* cannot watch a register with a HW watchpoint */
6151 /* The expression itself looks suitable for using a hardware
6152 watchpoint, but give the target machine a chance to reject it. */
6153 return found_memory_cnt
;
6157 watch_command_wrapper (char *arg
, int from_tty
)
6159 watch_command (arg
, from_tty
);
6163 watch_command (char *arg
, int from_tty
)
6165 watch_command_1 (arg
, hw_write
, from_tty
);
6169 rwatch_command_wrapper (char *arg
, int from_tty
)
6171 rwatch_command (arg
, from_tty
);
6175 rwatch_command (char *arg
, int from_tty
)
6177 watch_command_1 (arg
, hw_read
, from_tty
);
6181 awatch_command_wrapper (char *arg
, int from_tty
)
6183 awatch_command (arg
, from_tty
);
6187 awatch_command (char *arg
, int from_tty
)
6189 watch_command_1 (arg
, hw_access
, from_tty
);
6193 /* Helper routines for the until_command routine in infcmd.c. Here
6194 because it uses the mechanisms of breakpoints. */
6196 struct until_break_command_continuation_args
6198 struct breakpoint
*breakpoint
;
6199 struct breakpoint
*breakpoint2
;
6202 /* This function is called by fetch_inferior_event via the
6203 cmd_continuation pointer, to complete the until command. It takes
6204 care of cleaning up the temporary breakpoints set up by the until
6207 until_break_command_continuation (void *arg
)
6209 struct until_break_command_continuation_args
*a
= arg
;
6211 delete_breakpoint (a
->breakpoint
);
6213 delete_breakpoint (a
->breakpoint2
);
6217 until_break_command (char *arg
, int from_tty
, int anywhere
)
6219 struct symtabs_and_lines sals
;
6220 struct symtab_and_line sal
;
6221 struct frame_info
*frame
= get_selected_frame (NULL
);
6222 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6223 struct breakpoint
*breakpoint
;
6224 struct breakpoint
*breakpoint2
= NULL
;
6225 struct cleanup
*old_chain
;
6227 clear_proceed_status ();
6229 /* Set a breakpoint where the user wants it and at return from
6232 if (default_breakpoint_valid
)
6233 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6234 default_breakpoint_line
, (char ***) NULL
, NULL
);
6236 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6237 0, (char ***) NULL
, NULL
);
6239 if (sals
.nelts
!= 1)
6240 error (_("Couldn't get information on specified line."));
6243 xfree (sals
.sals
); /* malloc'd, so freed */
6246 error (_("Junk at end of arguments."));
6248 resolve_sal_pc (&sal
);
6251 /* If the user told us to continue until a specified location,
6252 we don't specify a frame at which we need to stop. */
6253 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6255 /* Otherwise, specify the current frame, because we want to stop only
6256 at the very same frame. */
6257 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6260 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6262 /* Keep within the current frame, or in frames called by the current
6266 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6267 sal
.pc
= get_frame_pc (prev_frame
);
6268 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6270 make_cleanup_delete_breakpoint (breakpoint2
);
6273 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6275 /* If we are running asynchronously, and proceed call above has actually
6276 managed to start the target, arrange for breakpoints to be
6277 deleted when the target stops. Otherwise, we're already stopped and
6278 delete breakpoints via cleanup chain. */
6280 if (target_can_async_p () && is_running (inferior_ptid
))
6282 struct until_break_command_continuation_args
*args
;
6283 args
= xmalloc (sizeof (*args
));
6285 args
->breakpoint
= breakpoint
;
6286 args
->breakpoint2
= breakpoint2
;
6288 discard_cleanups (old_chain
);
6289 add_continuation (inferior_thread (),
6290 until_break_command_continuation
, args
,
6294 do_cleanups (old_chain
);
6298 ep_skip_leading_whitespace (char **s
)
6300 if ((s
== NULL
) || (*s
== NULL
))
6302 while (isspace (**s
))
6306 /* This function attempts to parse an optional "if <cond>" clause
6307 from the arg string. If one is not found, it returns NULL.
6309 Else, it returns a pointer to the condition string. (It does not
6310 attempt to evaluate the string against a particular block.) And,
6311 it updates arg to point to the first character following the parsed
6312 if clause in the arg string. */
6315 ep_parse_optional_if_clause (char **arg
)
6319 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6322 /* Skip the "if" keyword. */
6325 /* Skip any extra leading whitespace, and record the start of the
6326 condition string. */
6327 ep_skip_leading_whitespace (arg
);
6330 /* Assume that the condition occupies the remainder of the arg string. */
6331 (*arg
) += strlen (cond_string
);
6336 /* This function attempts to parse an optional filename from the arg
6337 string. If one is not found, it returns NULL.
6339 Else, it returns a pointer to the parsed filename. (This function
6340 makes no attempt to verify that a file of that name exists, or is
6341 accessible.) And, it updates arg to point to the first character
6342 following the parsed filename in the arg string.
6344 Note that clients needing to preserve the returned filename for
6345 future access should copy it to their own buffers. */
6347 ep_parse_optional_filename (char **arg
)
6349 static char filename
[1024];
6354 if ((*arg_p
== '\0') || isspace (*arg_p
))
6372 /* Commands to deal with catching events, such as signals, exceptions,
6373 process start/exit, etc. */
6377 catch_fork_temporary
, catch_vfork_temporary
,
6378 catch_fork_permanent
, catch_vfork_permanent
6383 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6385 char *cond_string
= NULL
;
6386 catch_fork_kind fork_kind
;
6389 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6390 tempflag
= (fork_kind
== catch_fork_temporary
6391 || fork_kind
== catch_vfork_temporary
);
6395 ep_skip_leading_whitespace (&arg
);
6397 /* The allowed syntax is:
6399 catch [v]fork if <cond>
6401 First, check if there's an if clause. */
6402 cond_string
= ep_parse_optional_if_clause (&arg
);
6404 if ((*arg
!= '\0') && !isspace (*arg
))
6405 error (_("Junk at end of arguments."));
6407 /* If this target supports it, create a fork or vfork catchpoint
6408 and enable reporting of such events. */
6411 case catch_fork_temporary
:
6412 case catch_fork_permanent
:
6413 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6414 &catch_fork_breakpoint_ops
);
6416 case catch_vfork_temporary
:
6417 case catch_vfork_permanent
:
6418 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6419 &catch_vfork_breakpoint_ops
);
6422 error (_("unsupported or unknown fork kind; cannot catch it"));
6428 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6431 char *cond_string
= NULL
;
6433 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6437 ep_skip_leading_whitespace (&arg
);
6439 /* The allowed syntax is:
6441 catch exec if <cond>
6443 First, check if there's an if clause. */
6444 cond_string
= ep_parse_optional_if_clause (&arg
);
6446 if ((*arg
!= '\0') && !isspace (*arg
))
6447 error (_("Junk at end of arguments."));
6449 /* If this target supports it, create an exec catchpoint
6450 and enable reporting of such events. */
6451 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6454 static enum print_stop_action
6455 print_exception_catchpoint (struct breakpoint
*b
)
6457 int bp_temp
, bp_throw
;
6459 annotate_catchpoint (b
->number
);
6461 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6462 if (b
->loc
->address
!= b
->loc
->requested_address
)
6463 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6466 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6468 bp_temp
? "Temporary catchpoint "
6470 if (!ui_out_is_mi_like_p (uiout
))
6471 ui_out_field_int (uiout
, "bkptno", b
->number
);
6473 bp_throw
? " (exception thrown), "
6474 : " (exception caught), ");
6475 if (ui_out_is_mi_like_p (uiout
))
6477 ui_out_field_string (uiout
, "reason",
6478 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6479 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6480 ui_out_field_int (uiout
, "bkptno", b
->number
);
6482 return PRINT_SRC_AND_LOC
;
6486 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6488 struct value_print_options opts
;
6489 get_user_print_options (&opts
);
6490 if (opts
.addressprint
)
6493 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6494 ui_out_field_string (uiout
, "addr", "<PENDING>");
6496 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6500 *last_addr
= b
->loc
->address
;
6501 if (strstr (b
->addr_string
, "throw") != NULL
)
6502 ui_out_field_string (uiout
, "what", "exception throw");
6504 ui_out_field_string (uiout
, "what", "exception catch");
6508 print_mention_exception_catchpoint (struct breakpoint
*b
)
6513 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6514 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6515 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6516 : _("Catchpoint "));
6517 ui_out_field_int (uiout
, "bkptno", b
->number
);
6518 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6522 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6525 NULL
, /* breakpoint_hit */
6526 print_exception_catchpoint
,
6527 print_one_exception_catchpoint
,
6528 print_mention_exception_catchpoint
6532 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6533 enum exception_event_kind ex_event
, int from_tty
)
6535 char *trigger_func_name
;
6537 if (ex_event
== EX_EVENT_CATCH
)
6538 trigger_func_name
= "__cxa_begin_catch";
6540 trigger_func_name
= "__cxa_throw";
6542 break_command_really (trigger_func_name
, cond_string
, -1,
6543 0 /* condition and thread are valid. */,
6546 AUTO_BOOLEAN_TRUE
/* pending */,
6547 &gnu_v3_exception_catchpoint_ops
, from_tty
,
6553 /* Deal with "catch catch" and "catch throw" commands */
6556 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6557 int tempflag
, int from_tty
)
6559 char *cond_string
= NULL
;
6560 struct symtab_and_line
*sal
= NULL
;
6564 ep_skip_leading_whitespace (&arg
);
6566 cond_string
= ep_parse_optional_if_clause (&arg
);
6568 if ((*arg
!= '\0') && !isspace (*arg
))
6569 error (_("Junk at end of arguments."));
6571 if ((ex_event
!= EX_EVENT_THROW
) &&
6572 (ex_event
!= EX_EVENT_CATCH
))
6573 error (_("Unsupported or unknown exception event; cannot catch it"));
6575 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6578 warning (_("Unsupported with this platform/compiler combination."));
6581 /* Implementation of "catch catch" command. */
6584 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6586 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6587 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6590 /* Implementation of "catch throw" command. */
6593 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6595 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6596 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6599 /* Create a breakpoint struct for Ada exception catchpoints. */
6602 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6606 struct expression
*cond
,
6607 struct breakpoint_ops
*ops
,
6611 struct breakpoint
*b
;
6615 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6616 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6617 version for exception catchpoints, because two catchpoints
6618 used for different exception names will use the same address.
6619 In this case, a "breakpoint ... also set at..." warning is
6620 unproductive. Besides. the warning phrasing is also a bit
6621 inapropriate, we should use the word catchpoint, and tell
6622 the user what type of catchpoint it is. The above is good
6623 enough for now, though. */
6626 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6627 set_breakpoint_count (breakpoint_count
+ 1);
6629 b
->enable_state
= bp_enabled
;
6630 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6631 b
->number
= breakpoint_count
;
6632 b
->ignore_count
= 0;
6633 b
->loc
->cond
= cond
;
6634 b
->addr_string
= addr_string
;
6635 b
->language
= language_ada
;
6636 b
->cond_string
= cond_string
;
6637 b
->exp_string
= exp_string
;
6642 update_global_location_list (1);
6645 /* Implement the "catch exception" command. */
6648 catch_ada_exception_command (char *arg
, int from_tty
,
6649 struct cmd_list_element
*command
)
6652 struct symtab_and_line sal
;
6654 char *addr_string
= NULL
;
6655 char *exp_string
= NULL
;
6656 char *cond_string
= NULL
;
6657 struct expression
*cond
= NULL
;
6658 struct breakpoint_ops
*ops
= NULL
;
6660 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6664 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6665 &cond_string
, &cond
, &ops
);
6666 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6667 cond_string
, cond
, ops
, tempflag
,
6671 /* Implement the "catch assert" command. */
6674 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6677 struct symtab_and_line sal
;
6678 char *addr_string
= NULL
;
6679 struct breakpoint_ops
*ops
= NULL
;
6681 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6685 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6686 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6687 tempflag
, from_tty
);
6691 catch_command (char *arg
, int from_tty
)
6693 error (_("Catch requires an event name."));
6698 tcatch_command (char *arg
, int from_tty
)
6700 error (_("Catch requires an event name."));
6703 /* Delete breakpoints by address or line. */
6706 clear_command (char *arg
, int from_tty
)
6708 struct breakpoint
*b
;
6709 VEC(breakpoint_p
) *found
= 0;
6712 struct symtabs_and_lines sals
;
6713 struct symtab_and_line sal
;
6718 sals
= decode_line_spec (arg
, 1);
6723 sals
.sals
= (struct symtab_and_line
*)
6724 xmalloc (sizeof (struct symtab_and_line
));
6725 make_cleanup (xfree
, sals
.sals
);
6726 init_sal (&sal
); /* initialize to zeroes */
6727 sal
.line
= default_breakpoint_line
;
6728 sal
.symtab
= default_breakpoint_symtab
;
6729 sal
.pc
= default_breakpoint_address
;
6730 if (sal
.symtab
== 0)
6731 error (_("No source file specified."));
6739 /* We don't call resolve_sal_pc here. That's not
6740 as bad as it seems, because all existing breakpoints
6741 typically have both file/line and pc set. So, if
6742 clear is given file/line, we can match this to existing
6743 breakpoint without obtaining pc at all.
6745 We only support clearing given the address explicitly
6746 present in breakpoint table. Say, we've set breakpoint
6747 at file:line. There were several PC values for that file:line,
6748 due to optimization, all in one block.
6749 We've picked one PC value. If "clear" is issued with another
6750 PC corresponding to the same file:line, the breakpoint won't
6751 be cleared. We probably can still clear the breakpoint, but
6752 since the other PC value is never presented to user, user
6753 can only find it by guessing, and it does not seem important
6756 /* For each line spec given, delete bps which correspond
6757 to it. Do it in two passes, solely to preserve the current
6758 behavior that from_tty is forced true if we delete more than
6762 for (i
= 0; i
< sals
.nelts
; i
++)
6764 /* If exact pc given, clear bpts at that pc.
6765 If line given (pc == 0), clear all bpts on specified line.
6766 If defaulting, clear all bpts on default line
6769 defaulting sal.pc != 0 tests to do
6774 1 0 <can't happen> */
6778 /* Find all matching breakpoints and add them to
6783 /* Are we going to delete b? */
6784 if (b
->type
!= bp_none
6785 && b
->type
!= bp_watchpoint
6786 && b
->type
!= bp_hardware_watchpoint
6787 && b
->type
!= bp_read_watchpoint
6788 && b
->type
!= bp_access_watchpoint
)
6790 struct bp_location
*loc
= b
->loc
;
6791 for (; loc
; loc
= loc
->next
)
6793 int pc_match
= sal
.pc
6794 && (loc
->address
== sal
.pc
)
6795 && (!section_is_overlay (loc
->section
)
6796 || loc
->section
== sal
.section
);
6797 int line_match
= ((default_match
|| (0 == sal
.pc
))
6798 && b
->source_file
!= NULL
6799 && sal
.symtab
!= NULL
6800 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6801 && b
->line_number
== sal
.line
);
6802 if (pc_match
|| line_match
)
6811 VEC_safe_push(breakpoint_p
, found
, b
);
6814 /* Now go thru the 'found' chain and delete them. */
6815 if (VEC_empty(breakpoint_p
, found
))
6818 error (_("No breakpoint at %s."), arg
);
6820 error (_("No breakpoint at this line."));
6823 if (VEC_length(breakpoint_p
, found
) > 1)
6824 from_tty
= 1; /* Always report if deleted more than one */
6827 if (VEC_length(breakpoint_p
, found
) == 1)
6828 printf_unfiltered (_("Deleted breakpoint "));
6830 printf_unfiltered (_("Deleted breakpoints "));
6832 breakpoints_changed ();
6834 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6837 printf_unfiltered ("%d ", b
->number
);
6838 delete_breakpoint (b
);
6841 putchar_unfiltered ('\n');
6844 /* Delete breakpoint in BS if they are `delete' breakpoints and
6845 all breakpoints that are marked for deletion, whether hit or not.
6846 This is called after any breakpoint is hit, or after errors. */
6849 breakpoint_auto_delete (bpstat bs
)
6851 struct breakpoint
*b
, *temp
;
6853 for (; bs
; bs
= bs
->next
)
6854 if (bs
->breakpoint_at
6855 && bs
->breakpoint_at
->owner
6856 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6858 delete_breakpoint (bs
->breakpoint_at
->owner
);
6860 ALL_BREAKPOINTS_SAFE (b
, temp
)
6862 if (b
->disposition
== disp_del_at_next_stop
)
6863 delete_breakpoint (b
);
6867 /* A cleanup function which destroys a vector. */
6870 do_vec_free (void *p
)
6872 VEC(bp_location_p
) **vec
= p
;
6874 VEC_free (bp_location_p
, *vec
);
6877 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
6878 into the inferior, only remove already-inserted locations that no
6879 longer should be inserted. Functions that delete a breakpoint or
6880 breakpoints should pass false, so that deleting a breakpoint
6881 doesn't have the side effect of inserting the locations of other
6882 breakpoints that are marked not-inserted, but should_be_inserted
6883 returns true on them.
6885 This behaviour is useful is situations close to tear-down -- e.g.,
6886 after an exec, while the target still has execution, but breakpoint
6887 shadows of the previous executable image should *NOT* be restored
6888 to the new image; or before detaching, where the target still has
6889 execution and wants to delete breakpoints from GDB's lists, and all
6890 breakpoints had already been removed from the inferior. */
6893 update_global_location_list (int should_insert
)
6895 struct breakpoint
*b
;
6896 struct bp_location
**next
= &bp_location_chain
;
6897 struct bp_location
*loc
;
6898 struct bp_location
*loc2
;
6899 VEC(bp_location_p
) *old_locations
= NULL
;
6902 struct cleanup
*cleanups
;
6904 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
6905 /* Store old locations for future reference. */
6906 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6907 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6909 bp_location_chain
= NULL
;
6912 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6915 next
= &(loc
->global_next
);
6920 /* Identify bp_location instances that are no longer present in the new
6921 list, and therefore should be freed. Note that it's not necessary that
6922 those locations should be removed from inferior -- if there's another
6923 location at the same address (previously marked as duplicate),
6924 we don't need to remove/insert the location. */
6925 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6927 /* Tells if 'loc' is found amoung the new locations. If not, we
6929 int found_object
= 0;
6930 /* Tells if the location should remain inserted in the target. */
6931 int keep_in_target
= 0;
6933 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6940 /* If this location is no longer present, and inserted, look if there's
6941 maybe a new location at the same address. If so, mark that one
6942 inserted, and don't remove this one. This is needed so that we
6943 don't have a time window where a breakpoint at certain location is not
6948 /* If the location is inserted now, we might have to remove it. */
6950 if (found_object
&& should_be_inserted (loc
))
6952 /* The location is still present in the location list, and still
6953 should be inserted. Don't do anything. */
6958 /* The location is either no longer present, or got disabled.
6959 See if there's another location at the same address, in which
6960 case we don't need to remove this one from the target. */
6961 if (breakpoint_address_is_meaningful (loc
->owner
))
6962 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6964 /* For the sake of should_insert_location. The
6965 call to check_duplicates will fix up this later. */
6966 loc2
->duplicate
= 0;
6967 if (should_be_inserted (loc2
)
6968 && loc2
!= loc
&& loc2
->address
== loc
->address
)
6971 loc2
->target_info
= loc
->target_info
;
6978 if (!keep_in_target
)
6980 if (remove_breakpoint (loc
, mark_uninserted
))
6982 /* This is just about all we can do. We could keep this
6983 location on the global list, and try to remove it next
6984 time, but there's no particular reason why we will
6987 Note that at this point, loc->owner is still valid,
6988 as delete_breakpoint frees the breakpoint only
6989 after calling us. */
6990 printf_filtered (_("warning: Error removing breakpoint %d\n"),
6991 loc
->owner
->number
);
6999 if (removed
&& non_stop
)
7001 /* This location was removed from the targets. In non-stop mode,
7002 a race condition is possible where we've removed a breakpoint,
7003 but stop events for that breakpoint are already queued and will
7004 arrive later. To suppress spurious SIGTRAPs reported to user,
7005 we keep this breakpoint location for a bit, and will retire it
7006 after we see 3 * thread_count events.
7007 The theory here is that reporting of events should,
7008 "on the average", be fair, so after that many event we'll see
7009 events from all threads that have anything of interest, and no
7010 longer need to keep this breakpoint. This is just a
7011 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7012 which is usability issue, but not a correctness problem. */
7013 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7016 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7019 free_bp_location (loc
);
7025 check_duplicates (b
);
7028 if (breakpoints_always_inserted_mode () && should_insert
7029 && (target_has_execution
7030 || (gdbarch_has_global_solist (target_gdbarch
)
7031 && target_supports_multi_process ())))
7032 insert_breakpoint_locations ();
7034 do_cleanups (cleanups
);
7038 breakpoint_retire_moribund (void)
7040 struct bp_location
*loc
;
7043 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7044 if (--(loc
->events_till_retirement
) == 0)
7046 free_bp_location (loc
);
7047 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7053 update_global_location_list_nothrow (int inserting
)
7055 struct gdb_exception e
;
7056 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7057 update_global_location_list (inserting
);
7060 /* Clear BPT from a BPS. */
7062 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7065 for (bs
= bps
; bs
; bs
= bs
->next
)
7066 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7068 bs
->breakpoint_at
= NULL
;
7070 /* bs->commands will be freed later. */
7074 /* Callback for iterate_over_threads. */
7076 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7078 struct breakpoint
*bpt
= data
;
7079 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7083 /* Delete a breakpoint and clean up all traces of it in the data
7087 delete_breakpoint (struct breakpoint
*bpt
)
7089 struct breakpoint
*b
;
7090 struct bp_location
*loc
, *next
;
7092 gdb_assert (bpt
!= NULL
);
7094 /* Has this bp already been deleted? This can happen because multiple
7095 lists can hold pointers to bp's. bpstat lists are especial culprits.
7097 One example of this happening is a watchpoint's scope bp. When the
7098 scope bp triggers, we notice that the watchpoint is out of scope, and
7099 delete it. We also delete its scope bp. But the scope bp is marked
7100 "auto-deleting", and is already on a bpstat. That bpstat is then
7101 checked for auto-deleting bp's, which are deleted.
7103 A real solution to this problem might involve reference counts in bp's,
7104 and/or giving them pointers back to their referencing bpstat's, and
7105 teaching delete_breakpoint to only free a bp's storage when no more
7106 references were extent. A cheaper bandaid was chosen. */
7107 if (bpt
->type
== bp_none
)
7110 observer_notify_breakpoint_deleted (bpt
->number
);
7112 if (breakpoint_chain
== bpt
)
7113 breakpoint_chain
= bpt
->next
;
7118 b
->next
= bpt
->next
;
7122 free_command_lines (&bpt
->commands
);
7123 if (bpt
->cond_string
!= NULL
)
7124 xfree (bpt
->cond_string
);
7125 if (bpt
->addr_string
!= NULL
)
7126 xfree (bpt
->addr_string
);
7127 if (bpt
->exp
!= NULL
)
7129 if (bpt
->exp_string
!= NULL
)
7130 xfree (bpt
->exp_string
);
7131 if (bpt
->val
!= NULL
)
7132 value_free (bpt
->val
);
7133 if (bpt
->source_file
!= NULL
)
7134 xfree (bpt
->source_file
);
7135 if (bpt
->exec_pathname
!= NULL
)
7136 xfree (bpt
->exec_pathname
);
7138 /* Be sure no bpstat's are pointing at it after it's been freed. */
7139 /* FIXME, how can we find all bpstat's?
7140 We just check stop_bpstat for now. Note that we cannot just
7141 remove bpstats pointing at bpt from the stop_bpstat list
7142 entirely, as breakpoint commands are associated with the bpstat;
7143 if we remove it here, then the later call to
7144 bpstat_do_actions (&stop_bpstat);
7145 in event-top.c won't do anything, and temporary breakpoints
7146 with commands won't work. */
7148 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7150 /* Now that breakpoint is removed from breakpoint
7151 list, update the global location list. This
7152 will remove locations that used to belong to
7153 this breakpoint. Do this before freeing
7154 the breakpoint itself, since remove_breakpoint
7155 looks at location's owner. It might be better
7156 design to have location completely self-contained,
7157 but it's not the case now. */
7158 update_global_location_list (0);
7161 /* On the chance that someone will soon try again to delete this same
7162 bp, we mark it as deleted before freeing its storage. */
7163 bpt
->type
= bp_none
;
7169 do_delete_breakpoint_cleanup (void *b
)
7171 delete_breakpoint (b
);
7175 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7177 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7181 delete_command (char *arg
, int from_tty
)
7183 struct breakpoint
*b
, *temp
;
7189 int breaks_to_delete
= 0;
7191 /* Delete all breakpoints if no argument.
7192 Do not delete internal or call-dummy breakpoints, these
7193 have to be deleted with an explicit breakpoint number argument. */
7196 if (b
->type
!= bp_call_dummy
&&
7197 b
->type
!= bp_shlib_event
&&
7198 b
->type
!= bp_thread_event
&&
7199 b
->type
!= bp_overlay_event
&&
7202 breaks_to_delete
= 1;
7207 /* Ask user only if there are some breakpoints to delete. */
7209 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7211 ALL_BREAKPOINTS_SAFE (b
, temp
)
7213 if (b
->type
!= bp_call_dummy
&&
7214 b
->type
!= bp_shlib_event
&&
7215 b
->type
!= bp_thread_event
&&
7216 b
->type
!= bp_overlay_event
&&
7218 delete_breakpoint (b
);
7223 map_breakpoint_numbers (arg
, delete_breakpoint
);
7227 all_locations_are_pending (struct bp_location
*loc
)
7229 for (; loc
; loc
= loc
->next
)
7230 if (!loc
->shlib_disabled
)
7235 /* Subroutine of update_breakpoint_locations to simplify it.
7236 Return non-zero if multiple fns in list LOC have the same name.
7237 Null names are ignored. */
7240 ambiguous_names_p (struct bp_location
*loc
)
7242 struct bp_location
*l
;
7243 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7244 (int (*) (const void *, const void *)) streq
,
7245 NULL
, xcalloc
, xfree
);
7247 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7250 const char *name
= l
->function_name
;
7252 /* Allow for some names to be NULL, ignore them. */
7256 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7258 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7273 update_breakpoint_locations (struct breakpoint
*b
,
7274 struct symtabs_and_lines sals
)
7278 struct bp_location
*existing_locations
= b
->loc
;
7280 /* If there's no new locations, and all existing locations
7281 are pending, don't do anything. This optimizes
7282 the common case where all locations are in the same
7283 shared library, that was unloaded. We'd like to
7284 retain the location, so that when the library
7285 is loaded again, we don't loose the enabled/disabled
7286 status of the individual locations. */
7287 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7292 for (i
= 0; i
< sals
.nelts
; ++i
)
7294 struct bp_location
*new_loc
=
7295 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7297 /* Reparse conditions, they might contain references to the
7299 if (b
->cond_string
!= NULL
)
7301 struct gdb_exception e
;
7304 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7306 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7311 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7312 b
->number
, e
.message
);
7313 new_loc
->enabled
= 0;
7317 if (b
->source_file
!= NULL
)
7318 xfree (b
->source_file
);
7319 if (sals
.sals
[i
].symtab
== NULL
)
7320 b
->source_file
= NULL
;
7323 savestring (sals
.sals
[i
].symtab
->filename
,
7324 strlen (sals
.sals
[i
].symtab
->filename
));
7326 if (b
->line_number
== 0)
7327 b
->line_number
= sals
.sals
[i
].line
;
7330 /* Update locations of permanent breakpoints. */
7331 if (b
->enable_state
== bp_permanent
)
7332 make_breakpoint_permanent (b
);
7334 /* If possible, carry over 'disable' status from existing breakpoints. */
7336 struct bp_location
*e
= existing_locations
;
7337 /* If there are multiple breakpoints with the same function name,
7338 e.g. for inline functions, comparing function names won't work.
7339 Instead compare pc addresses; this is just a heuristic as things
7340 may have moved, but in practice it gives the correct answer
7341 often enough until a better solution is found. */
7342 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7344 for (; e
; e
= e
->next
)
7346 if (!e
->enabled
&& e
->function_name
)
7348 struct bp_location
*l
= b
->loc
;
7349 if (have_ambiguous_names
)
7351 for (; l
; l
= l
->next
)
7352 if (e
->address
== l
->address
)
7360 for (; l
; l
= l
->next
)
7361 if (l
->function_name
7362 && strcmp (e
->function_name
, l
->function_name
) == 0)
7372 update_global_location_list (1);
7376 /* Reset a breakpoint given it's struct breakpoint * BINT.
7377 The value we return ends up being the return value from catch_errors.
7378 Unused in this case. */
7381 breakpoint_re_set_one (void *bint
)
7383 /* get past catch_errs */
7384 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7388 int *not_found_ptr
= ¬_found
;
7389 struct symtabs_and_lines sals
= {};
7390 struct symtabs_and_lines expanded
;
7392 enum enable_state save_enable
;
7393 struct gdb_exception e
;
7394 struct cleanup
*cleanups
;
7399 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7403 case bp_hardware_breakpoint
:
7404 if (b
->addr_string
== NULL
)
7406 /* Anything without a string can't be re-set. */
7407 delete_breakpoint (b
);
7411 set_language (b
->language
);
7412 input_radix
= b
->input_radix
;
7414 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7416 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7421 int not_found_and_ok
= 0;
7422 /* For pending breakpoints, it's expected that parsing
7423 will fail until the right shared library is loaded.
7424 User has already told to create pending breakpoints and
7425 don't need extra messages. If breakpoint is in bp_shlib_disabled
7426 state, then user already saw the message about that breakpoint
7427 being disabled, and don't want to see more errors. */
7429 && (b
->condition_not_parsed
7430 || (b
->loc
&& b
->loc
->shlib_disabled
)
7431 || b
->enable_state
== bp_disabled
))
7432 not_found_and_ok
= 1;
7434 if (!not_found_and_ok
)
7436 /* We surely don't want to warn about the same breakpoint
7437 10 times. One solution, implemented here, is disable
7438 the breakpoint on error. Another solution would be to
7439 have separate 'warning emitted' flag. Since this
7440 happens only when a binary has changed, I don't know
7441 which approach is better. */
7442 b
->enable_state
= bp_disabled
;
7443 throw_exception (e
);
7450 gdb_assert (sals
.nelts
== 1);
7451 resolve_sal_pc (&sals
.sals
[0]);
7452 if (b
->condition_not_parsed
&& s
&& s
[0])
7454 char *cond_string
= 0;
7456 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7457 &cond_string
, &thread
);
7459 b
->cond_string
= cond_string
;
7461 b
->condition_not_parsed
= 0;
7463 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7464 cleanups
= make_cleanup (xfree
, sals
.sals
);
7465 update_breakpoint_locations (b
, expanded
);
7466 do_cleanups (cleanups
);
7470 case bp_hardware_watchpoint
:
7471 case bp_read_watchpoint
:
7472 case bp_access_watchpoint
:
7473 /* Watchpoint can be either on expression using entirely global variables,
7474 or it can be on local variables.
7476 Watchpoints of the first kind are never auto-deleted, and even persist
7477 across program restarts. Since they can use variables from shared
7478 libraries, we need to reparse expression as libraries are loaded
7481 Watchpoints on local variables can also change meaning as result
7482 of solib event. For example, if a watchpoint uses both a local and
7483 a global variables in expression, it's a local watchpoint, but
7484 unloading of a shared library will make the expression invalid.
7485 This is not a very common use case, but we still re-evaluate
7486 expression, to avoid surprises to the user.
7488 Note that for local watchpoints, we re-evaluate it only if
7489 watchpoints frame id is still valid. If it's not, it means
7490 the watchpoint is out of scope and will be deleted soon. In fact,
7491 I'm not sure we'll ever be called in this case.
7493 If a local watchpoint's frame id is still valid, then
7494 b->exp_valid_block is likewise valid, and we can safely use it.
7496 Don't do anything about disabled watchpoints, since they will
7497 be reevaluated again when enabled. */
7498 update_watchpoint (b
, 1 /* reparse */);
7500 /* We needn't really do anything to reset these, since the mask
7501 that requests them is unaffected by e.g., new libraries being
7507 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7509 /* Delete overlay event breakpoints; they will be reset later by
7510 breakpoint_re_set. */
7511 case bp_overlay_event
:
7512 delete_breakpoint (b
);
7515 /* This breakpoint is special, it's set up when the inferior
7516 starts and we really don't want to touch it. */
7517 case bp_shlib_event
:
7519 /* Like bp_shlib_event, this breakpoint type is special.
7520 Once it is set up, we do not want to touch it. */
7521 case bp_thread_event
:
7523 /* Keep temporary breakpoints, which can be encountered when we step
7524 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7525 Otherwise these should have been blown away via the cleanup chain
7526 or by breakpoint_init_inferior when we rerun the executable. */
7529 case bp_watchpoint_scope
:
7531 case bp_step_resume
:
7533 case bp_longjmp_resume
:
7540 /* Re-set all breakpoints after symbols have been re-loaded. */
7542 breakpoint_re_set (void)
7544 struct breakpoint
*b
, *temp
;
7545 enum language save_language
;
7546 int save_input_radix
;
7548 save_language
= current_language
->la_language
;
7549 save_input_radix
= input_radix
;
7550 ALL_BREAKPOINTS_SAFE (b
, temp
)
7552 /* Format possible error msg */
7553 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7555 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7556 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7557 do_cleanups (cleanups
);
7559 set_language (save_language
);
7560 input_radix
= save_input_radix
;
7562 create_overlay_event_breakpoint ("_ovly_debug_event");
7565 /* Reset the thread number of this breakpoint:
7567 - If the breakpoint is for all threads, leave it as-is.
7568 - Else, reset it to the current thread for inferior_ptid. */
7570 breakpoint_re_set_thread (struct breakpoint
*b
)
7572 if (b
->thread
!= -1)
7574 if (in_thread_list (inferior_ptid
))
7575 b
->thread
= pid_to_thread_id (inferior_ptid
);
7579 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7580 If from_tty is nonzero, it prints a message to that effect,
7581 which ends with a period (no newline). */
7584 set_ignore_count (int bptnum
, int count
, int from_tty
)
7586 struct breakpoint
*b
;
7592 if (b
->number
== bptnum
)
7594 b
->ignore_count
= count
;
7598 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7600 else if (count
== 1)
7601 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7604 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7607 breakpoints_changed ();
7608 observer_notify_breakpoint_modified (b
->number
);
7612 error (_("No breakpoint number %d."), bptnum
);
7616 make_breakpoint_silent (struct breakpoint
*b
)
7618 /* Silence the breakpoint. */
7622 /* Command to set ignore-count of breakpoint N to COUNT. */
7625 ignore_command (char *args
, int from_tty
)
7631 error_no_arg (_("a breakpoint number"));
7633 num
= get_number (&p
);
7635 error (_("bad breakpoint number: '%s'"), args
);
7637 error (_("Second argument (specified ignore-count) is missing."));
7639 set_ignore_count (num
,
7640 longest_to_int (value_as_long (parse_and_eval (p
))),
7643 printf_filtered ("\n");
7646 /* Call FUNCTION on each of the breakpoints
7647 whose numbers are given in ARGS. */
7650 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7655 struct breakpoint
*b
, *tmp
;
7659 error_no_arg (_("one or more breakpoint numbers"));
7666 num
= get_number_or_range (&p1
);
7669 warning (_("bad breakpoint number at or near '%s'"), p
);
7673 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7674 if (b
->number
== num
)
7676 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7679 if (related_breakpoint
)
7680 function (related_breakpoint
);
7684 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7690 static struct bp_location
*
7691 find_location_by_number (char *number
)
7693 char *dot
= strchr (number
, '.');
7697 struct breakpoint
*b
;
7698 struct bp_location
*loc
;
7703 bp_num
= get_number_or_range (&p1
);
7705 error (_("Bad breakpoint number '%s'"), number
);
7708 if (b
->number
== bp_num
)
7713 if (!b
|| b
->number
!= bp_num
)
7714 error (_("Bad breakpoint number '%s'"), number
);
7717 loc_num
= get_number_or_range (&p1
);
7719 error (_("Bad breakpoint location number '%s'"), number
);
7723 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7726 error (_("Bad breakpoint location number '%s'"), dot
+1);
7732 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7733 If from_tty is nonzero, it prints a message to that effect,
7734 which ends with a period (no newline). */
7737 disable_breakpoint (struct breakpoint
*bpt
)
7739 /* Never disable a watchpoint scope breakpoint; we want to
7740 hit them when we leave scope so we can delete both the
7741 watchpoint and its scope breakpoint at that time. */
7742 if (bpt
->type
== bp_watchpoint_scope
)
7745 /* You can't disable permanent breakpoints. */
7746 if (bpt
->enable_state
== bp_permanent
)
7749 bpt
->enable_state
= bp_disabled
;
7751 update_global_location_list (0);
7753 observer_notify_breakpoint_modified (bpt
->number
);
7757 disable_command (char *args
, int from_tty
)
7759 struct breakpoint
*bpt
;
7761 ALL_BREAKPOINTS (bpt
)
7765 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7770 case bp_hardware_breakpoint
:
7772 case bp_hardware_watchpoint
:
7773 case bp_read_watchpoint
:
7774 case bp_access_watchpoint
:
7775 disable_breakpoint (bpt
);
7779 else if (strchr (args
, '.'))
7781 struct bp_location
*loc
= find_location_by_number (args
);
7784 update_global_location_list (0);
7787 map_breakpoint_numbers (args
, disable_breakpoint
);
7791 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7793 int target_resources_ok
, other_type_used
;
7796 if (bpt
->type
== bp_hardware_breakpoint
)
7799 i
= hw_breakpoint_used_count ();
7800 target_resources_ok
=
7801 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7803 if (target_resources_ok
== 0)
7804 error (_("No hardware breakpoint support in the target."));
7805 else if (target_resources_ok
< 0)
7806 error (_("Hardware breakpoints used exceeds limit."));
7809 if (bpt
->type
== bp_watchpoint
||
7810 bpt
->type
== bp_hardware_watchpoint
||
7811 bpt
->type
== bp_read_watchpoint
||
7812 bpt
->type
== bp_access_watchpoint
)
7814 struct gdb_exception e
;
7816 TRY_CATCH (e
, RETURN_MASK_ALL
)
7818 update_watchpoint (bpt
, 1 /* reparse */);
7822 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
7828 if (bpt
->enable_state
!= bp_permanent
)
7829 bpt
->enable_state
= bp_enabled
;
7830 bpt
->disposition
= disposition
;
7831 update_global_location_list (1);
7832 breakpoints_changed ();
7834 observer_notify_breakpoint_modified (bpt
->number
);
7839 enable_breakpoint (struct breakpoint
*bpt
)
7841 do_enable_breakpoint (bpt
, bpt
->disposition
);
7844 /* The enable command enables the specified breakpoints (or all defined
7845 breakpoints) so they once again become (or continue to be) effective
7846 in stopping the inferior. */
7849 enable_command (char *args
, int from_tty
)
7851 struct breakpoint
*bpt
;
7853 ALL_BREAKPOINTS (bpt
)
7857 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7862 case bp_hardware_breakpoint
:
7864 case bp_hardware_watchpoint
:
7865 case bp_read_watchpoint
:
7866 case bp_access_watchpoint
:
7867 enable_breakpoint (bpt
);
7871 else if (strchr (args
, '.'))
7873 struct bp_location
*loc
= find_location_by_number (args
);
7876 update_global_location_list (1);
7879 map_breakpoint_numbers (args
, enable_breakpoint
);
7883 enable_once_breakpoint (struct breakpoint
*bpt
)
7885 do_enable_breakpoint (bpt
, disp_disable
);
7889 enable_once_command (char *args
, int from_tty
)
7891 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7895 enable_delete_breakpoint (struct breakpoint
*bpt
)
7897 do_enable_breakpoint (bpt
, disp_del
);
7901 enable_delete_command (char *args
, int from_tty
)
7903 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7907 set_breakpoint_cmd (char *args
, int from_tty
)
7912 show_breakpoint_cmd (char *args
, int from_tty
)
7916 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7918 struct symtabs_and_lines
7919 decode_line_spec_1 (char *string
, int funfirstline
)
7921 struct symtabs_and_lines sals
;
7923 error (_("Empty line specification."));
7924 if (default_breakpoint_valid
)
7925 sals
= decode_line_1 (&string
, funfirstline
,
7926 default_breakpoint_symtab
,
7927 default_breakpoint_line
,
7928 (char ***) NULL
, NULL
);
7930 sals
= decode_line_1 (&string
, funfirstline
,
7931 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7933 error (_("Junk at end of line specification: %s"), string
);
7937 /* Create and insert a raw software breakpoint at PC. Return an
7938 identifier, which should be used to remove the breakpoint later.
7939 In general, places which call this should be using something on the
7940 breakpoint chain instead; this function should be eliminated
7944 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7946 struct bp_target_info
*bp_tgt
;
7948 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7949 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7951 bp_tgt
->placed_address
= pc
;
7952 if (target_insert_breakpoint (bp_tgt
) != 0)
7954 /* Could not insert the breakpoint. */
7962 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7965 deprecated_remove_raw_breakpoint (void *bp
)
7967 struct bp_target_info
*bp_tgt
= bp
;
7970 ret
= target_remove_breakpoint (bp_tgt
);
7976 /* One (or perhaps two) breakpoints used for software single stepping. */
7978 static void *single_step_breakpoints
[2];
7980 /* Create and insert a breakpoint for software single step. */
7983 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7987 if (single_step_breakpoints
[0] == NULL
)
7988 bpt_p
= &single_step_breakpoints
[0];
7991 gdb_assert (single_step_breakpoints
[1] == NULL
);
7992 bpt_p
= &single_step_breakpoints
[1];
7995 /* NOTE drow/2006-04-11: A future improvement to this function would be
7996 to only create the breakpoints once, and actually put them on the
7997 breakpoint chain. That would let us use set_raw_breakpoint. We could
7998 adjust the addresses each time they were needed. Doing this requires
7999 corresponding changes elsewhere where single step breakpoints are
8000 handled, however. So, for now, we use this. */
8002 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8004 error (_("Could not insert single-step breakpoint at 0x%s"),
8005 paddr_nz (next_pc
));
8008 /* Remove and delete any breakpoints used for software single step. */
8011 remove_single_step_breakpoints (void)
8013 gdb_assert (single_step_breakpoints
[0] != NULL
);
8015 /* See insert_single_step_breakpoint for more about this deprecated
8017 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8018 single_step_breakpoints
[0] = NULL
;
8020 if (single_step_breakpoints
[1] != NULL
)
8022 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8023 single_step_breakpoints
[1] = NULL
;
8027 /* Check whether a software single-step breakpoint is inserted at PC. */
8030 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8034 for (i
= 0; i
< 2; i
++)
8036 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8037 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8045 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8046 It is defined as a macro to prevent duplication.
8047 COMMAND should be a string constant containing the name of the command. */
8048 #define BREAK_ARGS_HELP(command) \
8049 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8050 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8051 If a line number is specified, break at start of code for that line.\n\
8052 If a function is specified, break at start of code for that function.\n\
8053 If an address is specified, break at that exact address.\n\
8054 With no LOCATION, uses current execution address of selected stack frame.\n\
8055 This is useful for breaking on return to a stack frame.\n\
8057 THREADNUM is the number from \"info threads\".\n\
8058 CONDITION is a boolean expression.\n\
8060 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8062 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8064 /* List of subcommands for "catch". */
8065 static struct cmd_list_element
*catch_cmdlist
;
8067 /* List of subcommands for "tcatch". */
8068 static struct cmd_list_element
*tcatch_cmdlist
;
8070 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8071 lists, and pass some additional user data to the command function. */
8073 add_catch_command (char *name
, char *docstring
,
8074 void (*sfunc
) (char *args
, int from_tty
,
8075 struct cmd_list_element
*command
),
8076 void *user_data_catch
,
8077 void *user_data_tcatch
)
8079 struct cmd_list_element
*command
;
8081 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8083 set_cmd_sfunc (command
, sfunc
);
8084 set_cmd_context (command
, user_data_catch
);
8086 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8088 set_cmd_sfunc (command
, sfunc
);
8089 set_cmd_context (command
, user_data_tcatch
);
8093 _initialize_breakpoint (void)
8095 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8096 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8097 struct cmd_list_element
*c
;
8099 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8101 breakpoint_chain
= 0;
8102 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8103 before a breakpoint is set. */
8104 breakpoint_count
= 0;
8106 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8107 Set ignore-count of breakpoint number N to COUNT.\n\
8108 Usage is `ignore N COUNT'."));
8110 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8112 add_com ("commands", class_breakpoint
, commands_command
, _("\
8113 Set commands to be executed when a breakpoint is hit.\n\
8114 Give breakpoint number as argument after \"commands\".\n\
8115 With no argument, the targeted breakpoint is the last one set.\n\
8116 The commands themselves follow starting on the next line.\n\
8117 Type a line containing \"end\" to indicate the end of them.\n\
8118 Give \"silent\" as the first line to make the breakpoint silent;\n\
8119 then no output is printed when it is hit, except what the commands print."));
8121 add_com ("condition", class_breakpoint
, condition_command
, _("\
8122 Specify breakpoint number N to break only if COND is true.\n\
8123 Usage is `condition N COND', where N is an integer and COND is an\n\
8124 expression to be evaluated whenever breakpoint N is reached."));
8126 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8127 Set a temporary breakpoint.\n\
8128 Like \"break\" except the breakpoint is only temporary,\n\
8129 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8130 by using \"enable delete\" on the breakpoint number.\n\
8132 BREAK_ARGS_HELP ("tbreak")));
8133 set_cmd_completer (c
, location_completer
);
8135 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8136 Set a hardware assisted breakpoint.\n\
8137 Like \"break\" except the breakpoint requires hardware support,\n\
8138 some target hardware may not have this support.\n\
8140 BREAK_ARGS_HELP ("hbreak")));
8141 set_cmd_completer (c
, location_completer
);
8143 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8144 Set a temporary hardware assisted breakpoint.\n\
8145 Like \"hbreak\" except the breakpoint is only temporary,\n\
8146 so it will be deleted when hit.\n\
8148 BREAK_ARGS_HELP ("thbreak")));
8149 set_cmd_completer (c
, location_completer
);
8151 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8152 Enable some breakpoints.\n\
8153 Give breakpoint numbers (separated by spaces) as arguments.\n\
8154 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8155 This is used to cancel the effect of the \"disable\" command.\n\
8156 With a subcommand you can enable temporarily."),
8157 &enablelist
, "enable ", 1, &cmdlist
);
8159 add_com ("ab", class_breakpoint
, enable_command
, _("\
8160 Enable some breakpoints.\n\
8161 Give breakpoint numbers (separated by spaces) as arguments.\n\
8162 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8163 This is used to cancel the effect of the \"disable\" command.\n\
8164 With a subcommand you can enable temporarily."));
8166 add_com_alias ("en", "enable", class_breakpoint
, 1);
8168 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8169 Enable some breakpoints.\n\
8170 Give breakpoint numbers (separated by spaces) as arguments.\n\
8171 This is used to cancel the effect of the \"disable\" command.\n\
8172 May be abbreviated to simply \"enable\".\n"),
8173 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8175 add_cmd ("once", no_class
, enable_once_command
, _("\
8176 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8177 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8180 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8181 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8182 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8185 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8186 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8187 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8190 add_cmd ("once", no_class
, enable_once_command
, _("\
8191 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8192 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8195 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8196 Disable some breakpoints.\n\
8197 Arguments are breakpoint numbers with spaces in between.\n\
8198 To disable all breakpoints, give no argument.\n\
8199 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8200 &disablelist
, "disable ", 1, &cmdlist
);
8201 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8202 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8204 add_com ("sb", class_breakpoint
, disable_command
, _("\
8205 Disable some breakpoints.\n\
8206 Arguments are breakpoint numbers with spaces in between.\n\
8207 To disable all breakpoints, give no argument.\n\
8208 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8210 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8211 Disable some breakpoints.\n\
8212 Arguments are breakpoint numbers with spaces in between.\n\
8213 To disable all breakpoints, give no argument.\n\
8214 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8215 This command may be abbreviated \"disable\"."),
8218 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8219 Delete some breakpoints or auto-display expressions.\n\
8220 Arguments are breakpoint numbers with spaces in between.\n\
8221 To delete all breakpoints, give no argument.\n\
8223 Also a prefix command for deletion of other GDB objects.\n\
8224 The \"unset\" command is also an alias for \"delete\"."),
8225 &deletelist
, "delete ", 1, &cmdlist
);
8226 add_com_alias ("d", "delete", class_breakpoint
, 1);
8227 add_com_alias ("del", "delete", class_breakpoint
, 1);
8229 add_com ("db", class_breakpoint
, delete_command
, _("\
8230 Delete some breakpoints.\n\
8231 Arguments are breakpoint numbers with spaces in between.\n\
8232 To delete all breakpoints, give no argument.\n"));
8234 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8235 Delete some breakpoints or auto-display expressions.\n\
8236 Arguments are breakpoint numbers with spaces in between.\n\
8237 To delete all breakpoints, give no argument.\n\
8238 This command may be abbreviated \"delete\"."),
8241 add_com ("clear", class_breakpoint
, clear_command
, _("\
8242 Clear breakpoint at specified line or function.\n\
8243 Argument may be line number, function name, or \"*\" and an address.\n\
8244 If line number is specified, all breakpoints in that line are cleared.\n\
8245 If function is specified, breakpoints at beginning of function are cleared.\n\
8246 If an address is specified, breakpoints at that address are cleared.\n\
8248 With no argument, clears all breakpoints in the line that the selected frame\n\
8251 See also the \"delete\" command which clears breakpoints by number."));
8253 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8254 Set breakpoint at specified line or function.\n"
8255 BREAK_ARGS_HELP ("break")));
8256 set_cmd_completer (c
, location_completer
);
8258 add_com_alias ("b", "break", class_run
, 1);
8259 add_com_alias ("br", "break", class_run
, 1);
8260 add_com_alias ("bre", "break", class_run
, 1);
8261 add_com_alias ("brea", "break", class_run
, 1);
8265 add_com_alias ("ba", "break", class_breakpoint
, 1);
8266 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8271 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8272 Break in function/address or break at a line in the current file."),
8273 &stoplist
, "stop ", 1, &cmdlist
);
8274 add_cmd ("in", class_breakpoint
, stopin_command
,
8275 _("Break in function or address."), &stoplist
);
8276 add_cmd ("at", class_breakpoint
, stopat_command
,
8277 _("Break at a line in the current file."), &stoplist
);
8278 add_com ("status", class_info
, breakpoints_info
, _("\
8279 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8280 The \"Type\" column indicates one of:\n\
8281 \tbreakpoint - normal breakpoint\n\
8282 \twatchpoint - watchpoint\n\
8283 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8284 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8285 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8286 address and file/line number respectively.\n\
8288 Convenience variable \"$_\" and default examine address for \"x\"\n\
8289 are set to the address of the last breakpoint listed unless the command\n\
8290 is prefixed with \"server \".\n\n\
8291 Convenience variable \"$bpnum\" contains the number of the last\n\
8295 add_info ("breakpoints", breakpoints_info
, _("\
8296 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8297 The \"Type\" column indicates one of:\n\
8298 \tbreakpoint - normal breakpoint\n\
8299 \twatchpoint - watchpoint\n\
8300 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8301 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8302 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8303 address and file/line number respectively.\n\
8305 Convenience variable \"$_\" and default examine address for \"x\"\n\
8306 are set to the address of the last breakpoint listed unless the command\n\
8307 is prefixed with \"server \".\n\n\
8308 Convenience variable \"$bpnum\" contains the number of the last\n\
8312 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8313 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8314 The \"Type\" column indicates one of:\n\
8315 \tbreakpoint - normal breakpoint\n\
8316 \twatchpoint - watchpoint\n\
8317 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8318 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8319 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8320 address and file/line number respectively.\n\
8322 Convenience variable \"$_\" and default examine address for \"x\"\n\
8323 are set to the address of the last breakpoint listed unless the command\n\
8324 is prefixed with \"server \".\n\n\
8325 Convenience variable \"$bpnum\" contains the number of the last\n\
8328 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8329 Status of all breakpoints, or breakpoint number NUMBER.\n\
8330 The \"Type\" column indicates one of:\n\
8331 \tbreakpoint - normal breakpoint\n\
8332 \twatchpoint - watchpoint\n\
8333 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8334 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8335 \tuntil - internal breakpoint used by the \"until\" command\n\
8336 \tfinish - internal breakpoint used by the \"finish\" command\n\
8337 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8338 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8339 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8340 address and file/line number respectively.\n\
8342 Convenience variable \"$_\" and default examine address for \"x\"\n\
8343 are set to the address of the last breakpoint listed unless the command\n\
8344 is prefixed with \"server \".\n\n\
8345 Convenience variable \"$bpnum\" contains the number of the last\n\
8347 &maintenanceinfolist
);
8349 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8350 Set catchpoints to catch events."),
8351 &catch_cmdlist
, "catch ",
8352 0/*allow-unknown*/, &cmdlist
);
8354 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8355 Set temporary catchpoints to catch events."),
8356 &tcatch_cmdlist
, "tcatch ",
8357 0/*allow-unknown*/, &cmdlist
);
8359 /* Add catch and tcatch sub-commands. */
8360 add_catch_command ("catch", _("\
8361 Catch an exception, when caught.\n\
8362 With an argument, catch only exceptions with the given name."),
8363 catch_catch_command
,
8366 add_catch_command ("throw", _("\
8367 Catch an exception, when thrown.\n\
8368 With an argument, catch only exceptions with the given name."),
8369 catch_throw_command
,
8372 add_catch_command ("fork", _("Catch calls to fork."),
8373 catch_fork_command_1
,
8374 (void *) (uintptr_t) catch_fork_permanent
,
8375 (void *) (uintptr_t) catch_fork_temporary
);
8376 add_catch_command ("vfork", _("Catch calls to vfork."),
8377 catch_fork_command_1
,
8378 (void *) (uintptr_t) catch_vfork_permanent
,
8379 (void *) (uintptr_t) catch_vfork_temporary
);
8380 add_catch_command ("exec", _("Catch calls to exec."),
8381 catch_exec_command_1
,
8384 add_catch_command ("exception", _("\
8385 Catch Ada exceptions, when raised.\n\
8386 With an argument, catch only exceptions with the given name."),
8387 catch_ada_exception_command
,
8390 add_catch_command ("assert", _("\
8391 Catch failed Ada assertions, when raised.\n\
8392 With an argument, catch only exceptions with the given name."),
8393 catch_assert_command
,
8397 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8398 Set a watchpoint for an expression.\n\
8399 A watchpoint stops execution of your program whenever the value of\n\
8400 an expression changes."));
8401 set_cmd_completer (c
, expression_completer
);
8403 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8404 Set a read watchpoint for an expression.\n\
8405 A watchpoint stops execution of your program whenever the value of\n\
8406 an expression is read."));
8407 set_cmd_completer (c
, expression_completer
);
8409 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8410 Set a watchpoint for an expression.\n\
8411 A watchpoint stops execution of your program whenever the value of\n\
8412 an expression is either read or written."));
8413 set_cmd_completer (c
, expression_completer
);
8415 add_info ("watchpoints", breakpoints_info
,
8416 _("Synonym for ``info breakpoints''."));
8419 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8420 respond to changes - contrary to the description. */
8421 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8422 &can_use_hw_watchpoints
, _("\
8423 Set debugger's willingness to use watchpoint hardware."), _("\
8424 Show debugger's willingness to use watchpoint hardware."), _("\
8425 If zero, gdb will not use hardware for new watchpoints, even if\n\
8426 such is available. (However, any hardware watchpoints that were\n\
8427 created before setting this to nonzero, will continue to use watchpoint\n\
8430 show_can_use_hw_watchpoints
,
8431 &setlist
, &showlist
);
8433 can_use_hw_watchpoints
= 1;
8435 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8436 Breakpoint specific settings\n\
8437 Configure various breakpoint-specific variables such as\n\
8438 pending breakpoint behavior"),
8439 &breakpoint_set_cmdlist
, "set breakpoint ",
8440 0/*allow-unknown*/, &setlist
);
8441 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8442 Breakpoint specific settings\n\
8443 Configure various breakpoint-specific variables such as\n\
8444 pending breakpoint behavior"),
8445 &breakpoint_show_cmdlist
, "show breakpoint ",
8446 0/*allow-unknown*/, &showlist
);
8448 add_setshow_auto_boolean_cmd ("pending", no_class
,
8449 &pending_break_support
, _("\
8450 Set debugger's behavior regarding pending breakpoints."), _("\
8451 Show debugger's behavior regarding pending breakpoints."), _("\
8452 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8453 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8454 an error. If auto, an unrecognized breakpoint location results in a\n\
8455 user-query to see if a pending breakpoint should be created."),
8457 show_pending_break_support
,
8458 &breakpoint_set_cmdlist
,
8459 &breakpoint_show_cmdlist
);
8461 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8463 add_setshow_boolean_cmd ("auto-hw", no_class
,
8464 &automatic_hardware_breakpoints
, _("\
8465 Set automatic usage of hardware breakpoints."), _("\
8466 Show automatic usage of hardware breakpoints."), _("\
8467 If set, the debugger will automatically use hardware breakpoints for\n\
8468 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8469 a warning will be emitted for such breakpoints."),
8471 show_automatic_hardware_breakpoints
,
8472 &breakpoint_set_cmdlist
,
8473 &breakpoint_show_cmdlist
);
8475 add_setshow_enum_cmd ("always-inserted", class_support
,
8476 always_inserted_enums
, &always_inserted_mode
, _("\
8477 Set mode for inserting breakpoints."), _("\
8478 Show mode for inserting breakpoints."), _("\
8479 When this mode is off, breakpoints are inserted in inferior when it is\n\
8480 resumed, and removed when execution stops. When this mode is on,\n\
8481 breakpoints are inserted immediately and removed only when the user\n\
8482 deletes the breakpoint. When this mode is auto (which is the default),\n\
8483 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8484 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8485 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8486 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8488 &show_always_inserted_mode
,
8489 &breakpoint_set_cmdlist
,
8490 &breakpoint_show_cmdlist
);
8492 automatic_hardware_breakpoints
= 1;