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/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 /* readline include files */
64 #include "readline/readline.h"
65 #include "readline/history.h"
67 /* readline defines this. */
70 #include "mi/mi-common.h"
72 /* Arguments to pass as context to some catch command handlers. */
73 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
74 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
76 /* Prototypes for local functions. */
78 static void enable_delete_command (char *, int);
80 static void enable_delete_breakpoint (struct breakpoint
*);
82 static void enable_once_command (char *, int);
84 static void enable_once_breakpoint (struct breakpoint
*);
86 static void disable_command (char *, int);
88 static void enable_command (char *, int);
90 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
92 static void ignore_command (char *, int);
94 static int breakpoint_re_set_one (void *);
96 static void clear_command (char *, int);
98 static void catch_command (char *, int);
100 static void watch_command (char *, int);
102 static int can_use_hardware_watchpoint (struct value
*);
104 static void break_command_1 (char *, int, int);
106 static void mention (struct breakpoint
*);
108 static struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
109 struct symtab_and_line
,
112 static void check_duplicates (struct breakpoint
*);
114 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
116 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
120 static void describe_other_breakpoints (struct gdbarch
*, CORE_ADDR
,
121 struct obj_section
*, int);
123 static void breakpoints_info (char *, int);
125 static void breakpoint_1 (int, int);
127 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
129 static int breakpoint_cond_eval (void *);
131 static void cleanup_executing_breakpoints (void *);
133 static void commands_command (char *, int);
135 static void condition_command (char *, int);
137 static int get_number_trailer (char **, int);
139 void set_breakpoint_count (int);
148 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
150 static enum print_stop_action
print_it_typical (bpstat
);
152 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
154 static int watchpoint_check (void *);
156 static void maintenance_info_breakpoints (char *, int);
158 static int hw_breakpoint_used_count (void);
160 static int hw_watchpoint_used_count (enum bptype
, int *);
162 static void hbreak_command (char *, int);
164 static void thbreak_command (char *, int);
166 static void watch_command_1 (char *, int, int);
168 static void rwatch_command (char *, int);
170 static void awatch_command (char *, int);
172 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
174 static void stop_command (char *arg
, int from_tty
);
176 static void stopin_command (char *arg
, int from_tty
);
178 static void stopat_command (char *arg
, int from_tty
);
180 static char *ep_parse_optional_if_clause (char **arg
);
182 static char *ep_parse_optional_filename (char **arg
);
184 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
185 char *arg
, int tempflag
, int from_tty
);
187 static void tcatch_command (char *arg
, int from_tty
);
189 static void ep_skip_leading_whitespace (char **s
);
191 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
193 static void free_bp_location (struct bp_location
*loc
);
195 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
197 static void update_global_location_list (int);
199 static void update_global_location_list_nothrow (int);
201 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
203 static void insert_breakpoint_locations (void);
205 static void tracepoints_info (char *, int);
207 static void delete_trace_command (char *, int);
209 static void enable_trace_command (char *, int);
211 static void disable_trace_command (char *, int);
213 static void trace_pass_command (char *, int);
215 static void skip_prologue_sal (struct symtab_and_line
*sal
);
218 /* Flag indicating that a command has proceeded the inferior past the
219 current breakpoint. */
221 static int breakpoint_proceeded
;
224 bpdisp_text (enum bpdisp disp
)
226 /* NOTE: the following values are a part of MI protocol and represent
227 values of 'disp' field returned when inferior stops at a breakpoint. */
228 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
229 return bpdisps
[(int) disp
];
232 /* Prototypes for exported functions. */
233 /* If FALSE, gdb will not use hardware support for watchpoints, even
234 if such is available. */
235 static int can_use_hw_watchpoints
;
238 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
239 struct cmd_list_element
*c
,
242 fprintf_filtered (file
, _("\
243 Debugger's willingness to use watchpoint hardware is %s.\n"),
247 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
248 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
249 for unrecognized breakpoint locations.
250 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
251 static enum auto_boolean pending_break_support
;
253 show_pending_break_support (struct ui_file
*file
, int from_tty
,
254 struct cmd_list_element
*c
,
257 fprintf_filtered (file
, _("\
258 Debugger's behavior regarding pending breakpoints is %s.\n"),
262 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
263 set with "break" but falling in read-only memory.
264 If 0, gdb will warn about such breakpoints, but won't automatically
265 use hardware breakpoints. */
266 static int automatic_hardware_breakpoints
;
268 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
269 struct cmd_list_element
*c
,
272 fprintf_filtered (file
, _("\
273 Automatic usage of hardware breakpoints is %s.\n"),
277 /* If on, gdb will keep breakpoints inserted even as inferior is
278 stopped, and immediately insert any new breakpoints. If off, gdb
279 will insert breakpoints into inferior only when resuming it, and
280 will remove breakpoints upon stop. If auto, GDB will behave as ON
281 if in non-stop mode, and as OFF if all-stop mode.*/
283 static const char always_inserted_auto
[] = "auto";
284 static const char always_inserted_on
[] = "on";
285 static const char always_inserted_off
[] = "off";
286 static const char *always_inserted_enums
[] = {
287 always_inserted_auto
,
292 static const char *always_inserted_mode
= always_inserted_auto
;
294 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
295 struct cmd_list_element
*c
, const char *value
)
297 if (always_inserted_mode
== always_inserted_auto
)
298 fprintf_filtered (file
, _("\
299 Always inserted breakpoint mode is %s (currently %s).\n"),
301 breakpoints_always_inserted_mode () ? "on" : "off");
303 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
307 breakpoints_always_inserted_mode (void)
309 return (always_inserted_mode
== always_inserted_on
310 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
313 void _initialize_breakpoint (void);
315 /* Are we executing breakpoint commands? */
316 static int executing_breakpoint_commands
;
318 /* Are overlay event breakpoints enabled? */
319 static int overlay_events_enabled
;
321 /* Walk the following statement or block through all breakpoints.
322 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
325 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
327 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
328 for (B = breakpoint_chain; \
329 B ? (TMP=B->next, 1): 0; \
332 /* Similar iterators for the low-level breakpoints. */
334 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
336 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
337 for (B = bp_location_chain; \
338 B ? (TMP=B->global_next, 1): 0; \
341 /* Iterator for tracepoints only. */
343 #define ALL_TRACEPOINTS(B) \
344 for (B = breakpoint_chain; B; B = B->next) \
345 if ((B)->type == bp_tracepoint)
347 /* Chains of all breakpoints defined. */
349 struct breakpoint
*breakpoint_chain
;
351 struct bp_location
*bp_location_chain
;
353 /* The locations that no longer correspond to any breakpoint,
354 unlinked from bp_location_chain, but for which a hit
355 may still be reported by a target. */
356 VEC(bp_location_p
) *moribund_locations
= NULL
;
358 /* Number of last breakpoint made. */
360 int breakpoint_count
;
362 /* Number of last tracepoint made. */
364 int tracepoint_count
;
366 /* Return whether a breakpoint is an active enabled breakpoint. */
368 breakpoint_enabled (struct breakpoint
*b
)
370 return (b
->enable_state
== bp_enabled
);
373 /* Set breakpoint count to NUM. */
376 set_breakpoint_count (int num
)
378 breakpoint_count
= num
;
379 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
382 /* Used in run_command to zero the hit count when a new run starts. */
385 clear_breakpoint_hit_counts (void)
387 struct breakpoint
*b
;
393 /* Default address, symtab and line to put a breakpoint at
394 for "break" command with no arg.
395 if default_breakpoint_valid is zero, the other three are
396 not valid, and "break" with no arg is an error.
398 This set by print_stack_frame, which calls set_default_breakpoint. */
400 int default_breakpoint_valid
;
401 CORE_ADDR default_breakpoint_address
;
402 struct symtab
*default_breakpoint_symtab
;
403 int default_breakpoint_line
;
405 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
406 Advance *PP after the string and any trailing whitespace.
408 Currently the string can either be a number or "$" followed by the name
409 of a convenience variable. Making it an expression wouldn't work well
410 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
412 If the string is a NULL pointer, that denotes the last breakpoint.
414 TRAILER is a character which can be found after the number; most
415 commonly this is `-'. If you don't want a trailer, use \0. */
417 get_number_trailer (char **pp
, int trailer
)
419 int retval
= 0; /* default */
423 /* Empty line means refer to the last breakpoint. */
424 return breakpoint_count
;
427 /* Make a copy of the name, so we can null-terminate it
428 to pass to lookup_internalvar(). */
433 while (isalnum (*p
) || *p
== '_')
435 varname
= (char *) alloca (p
- start
+ 1);
436 strncpy (varname
, start
, p
- start
);
437 varname
[p
- start
] = '\0';
438 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
442 printf_filtered (_("Convenience variable must have integer value.\n"));
450 while (*p
>= '0' && *p
<= '9')
453 /* There is no number here. (e.g. "cond a == b"). */
455 /* Skip non-numeric token */
456 while (*p
&& !isspace((int) *p
))
458 /* Return zero, which caller must interpret as error. */
464 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
466 /* Trailing junk: return 0 and let caller print error msg. */
467 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
478 /* Like get_number_trailer, but don't allow a trailer. */
480 get_number (char **pp
)
482 return get_number_trailer (pp
, '\0');
485 /* Parse a number or a range.
486 * A number will be of the form handled by get_number.
487 * A range will be of the form <number1> - <number2>, and
488 * will represent all the integers between number1 and number2,
491 * While processing a range, this fuction is called iteratively;
492 * At each call it will return the next value in the range.
494 * At the beginning of parsing a range, the char pointer PP will
495 * be advanced past <number1> and left pointing at the '-' token.
496 * Subsequent calls will not advance the pointer until the range
497 * is completed. The call that completes the range will advance
498 * pointer PP past <number2>.
502 get_number_or_range (char **pp
)
504 static int last_retval
, end_value
;
505 static char *end_ptr
;
506 static int in_range
= 0;
510 /* Default case: pp is pointing either to a solo number,
511 or to the first number of a range. */
512 last_retval
= get_number_trailer (pp
, '-');
517 /* This is the start of a range (<number1> - <number2>).
518 Skip the '-', parse and remember the second number,
519 and also remember the end of the final token. */
523 while (isspace ((int) *end_ptr
))
524 end_ptr
++; /* skip white space */
525 end_value
= get_number (temp
);
526 if (end_value
< last_retval
)
528 error (_("inverted range"));
530 else if (end_value
== last_retval
)
532 /* degenerate range (number1 == number2). Advance the
533 token pointer so that the range will be treated as a
542 error (_("negative value"));
545 /* pp points to the '-' that betokens a range. All
546 number-parsing has already been done. Return the next
547 integer value (one greater than the saved previous value).
548 Do not advance the token pointer 'pp' until the end of range
551 if (++last_retval
== end_value
)
553 /* End of range reached; advance token pointer. */
563 /* condition N EXP -- set break condition of breakpoint N to EXP. */
566 condition_command (char *arg
, int from_tty
)
568 struct breakpoint
*b
;
573 error_no_arg (_("breakpoint number"));
576 bnum
= get_number (&p
);
578 error (_("Bad breakpoint argument: '%s'"), arg
);
581 if (b
->number
== bnum
)
583 struct bp_location
*loc
= b
->loc
;
584 for (; loc
; loc
= loc
->next
)
592 if (b
->cond_string
!= NULL
)
593 xfree (b
->cond_string
);
597 b
->cond_string
= NULL
;
599 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
604 /* I don't know if it matters whether this is the string the user
605 typed in or the decompiled expression. */
606 b
->cond_string
= xstrdup (arg
);
607 b
->condition_not_parsed
= 0;
608 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
612 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
614 error (_("Junk at end of expression"));
617 breakpoints_changed ();
618 observer_notify_breakpoint_modified (b
->number
);
622 error (_("No breakpoint number %d."), bnum
);
626 commands_command (char *arg
, int from_tty
)
628 struct breakpoint
*b
;
631 struct command_line
*l
;
633 /* If we allowed this, we would have problems with when to
634 free the storage, if we change the commands currently
637 if (executing_breakpoint_commands
)
638 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
641 bnum
= get_number (&p
);
644 error (_("Unexpected extra arguments following breakpoint number."));
647 if (b
->number
== bnum
)
649 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
651 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
652 l
= read_command_lines (tmpbuf
, from_tty
, 1);
653 do_cleanups (cleanups
);
654 free_command_lines (&b
->commands
);
656 breakpoints_changed ();
657 observer_notify_breakpoint_modified (b
->number
);
660 error (_("No breakpoint number %d."), bnum
);
663 /* Like commands_command, but instead of reading the commands from
664 input stream, takes them from an already parsed command structure.
666 This is used by cli-script.c to DTRT with breakpoint commands
667 that are part of if and while bodies. */
668 enum command_control_type
669 commands_from_control_command (char *arg
, struct command_line
*cmd
)
671 struct breakpoint
*b
;
675 /* If we allowed this, we would have problems with when to
676 free the storage, if we change the commands currently
679 if (executing_breakpoint_commands
)
680 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
682 /* An empty string for the breakpoint number means the last
683 breakpoint, but get_number expects a NULL pointer. */
688 bnum
= get_number (&p
);
691 error (_("Unexpected extra arguments following breakpoint number."));
694 if (b
->number
== bnum
)
696 free_command_lines (&b
->commands
);
697 if (cmd
->body_count
!= 1)
698 error (_("Invalid \"commands\" block structure."));
699 /* We need to copy the commands because if/while will free the
700 list after it finishes execution. */
701 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
702 breakpoints_changed ();
703 observer_notify_breakpoint_modified (b
->number
);
704 return simple_control
;
706 error (_("No breakpoint number %d."), bnum
);
709 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
710 by replacing any memory breakpoints with their shadowed contents. */
713 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
715 struct bp_location
*b
;
716 CORE_ADDR bp_addr
= 0;
722 if (b
->owner
->type
== bp_none
)
723 warning (_("reading through apparently deleted breakpoint #%d?"),
726 if (b
->loc_type
!= bp_loc_software_breakpoint
)
730 /* Addresses and length of the part of the breakpoint that
732 bp_addr
= b
->target_info
.placed_address
;
733 bp_size
= b
->target_info
.shadow_len
;
735 /* bp isn't valid, or doesn't shadow memory. */
738 if (bp_addr
+ bp_size
<= memaddr
)
739 /* The breakpoint is entirely before the chunk of memory we
743 if (bp_addr
>= memaddr
+ len
)
744 /* The breakpoint is entirely after the chunk of memory we are
748 /* Offset within shadow_contents. */
749 if (bp_addr
< memaddr
)
751 /* Only copy the second part of the breakpoint. */
752 bp_size
-= memaddr
- bp_addr
;
753 bptoffset
= memaddr
- bp_addr
;
757 if (bp_addr
+ bp_size
> memaddr
+ len
)
759 /* Only copy the first part of the breakpoint. */
760 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
763 memcpy (buf
+ bp_addr
- memaddr
,
764 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
769 /* A wrapper function for inserting catchpoints. */
771 insert_catchpoint (struct ui_out
*uo
, void *args
)
773 struct breakpoint
*b
= (struct breakpoint
*) args
;
776 gdb_assert (b
->type
== bp_catchpoint
);
777 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
783 is_hardware_watchpoint (struct breakpoint
*bpt
)
785 return (bpt
->type
== bp_hardware_watchpoint
786 || bpt
->type
== bp_read_watchpoint
787 || bpt
->type
== bp_access_watchpoint
);
790 /* Find the current value of a watchpoint on EXP. Return the value in
791 *VALP and *RESULTP and the chain of intermediate and final values
792 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
795 If a memory error occurs while evaluating the expression, *RESULTP will
796 be set to NULL. *RESULTP may be a lazy value, if the result could
797 not be read from memory. It is used to determine whether a value
798 is user-specified (we should watch the whole value) or intermediate
799 (we should watch only the bit used to locate the final value).
801 If the final value, or any intermediate value, could not be read
802 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
803 set to any referenced values. *VALP will never be a lazy value.
804 This is the value which we store in struct breakpoint.
806 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
807 value chain. The caller must free the values individually. If
808 VAL_CHAIN is NULL, all generated values will be left on the value
812 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
813 struct value
**resultp
, struct value
**val_chain
)
815 struct value
*mark
, *new_mark
, *result
;
816 volatile struct gdb_exception ex
;
824 /* Evaluate the expression. */
825 mark
= value_mark ();
828 TRY_CATCH (ex
, RETURN_MASK_ALL
)
830 result
= evaluate_expression (exp
);
834 /* Ignore memory errors, we want watchpoints pointing at
835 inaccessible memory to still be created; otherwise, throw the
836 error to some higher catcher. */
842 throw_exception (ex
);
847 new_mark
= value_mark ();
848 if (mark
== new_mark
)
853 /* Make sure it's not lazy, so that after the target stops again we
854 have a non-lazy previous value to compare with. */
856 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
861 /* Return the chain of intermediate values. We use this to
862 decide which addresses to watch. */
863 *val_chain
= new_mark
;
864 value_release_to_mark (mark
);
868 /* Assuming that B is a watchpoint:
869 - Reparse watchpoint expression, if REPARSE is non-zero
870 - Evaluate expression and store the result in B->val
871 - Evaluate the condition if there is one, and store the result
873 - Update the list of values that must be watched in B->loc.
875 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
876 If this is local watchpoint that is out of scope, delete it. */
878 update_watchpoint (struct breakpoint
*b
, int reparse
)
880 int within_current_scope
;
881 struct frame_id saved_frame_id
;
882 struct bp_location
*loc
;
885 /* We don't free locations. They are stored in bp_location_chain and
886 update_global_locations will eventually delete them and remove
887 breakpoints if needed. */
890 if (b
->disposition
== disp_del_at_next_stop
)
893 /* Save the current frame's ID so we can restore it after
894 evaluating the watchpoint expression on its own frame. */
895 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
896 took a frame parameter, so that we didn't have to change the
898 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
900 /* Determine if the watchpoint is within scope. */
901 if (b
->exp_valid_block
== NULL
)
902 within_current_scope
= 1;
905 struct frame_info
*fi
;
906 fi
= frame_find_by_id (b
->watchpoint_frame
);
907 within_current_scope
= (fi
!= NULL
);
908 if (within_current_scope
)
912 if (within_current_scope
&& reparse
)
921 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
922 /* If the meaning of expression itself changed, the old value is
923 no longer relevant. We don't want to report a watchpoint hit
924 to the user when the old value and the new value may actually
925 be completely different objects. */
931 /* If we failed to parse the expression, for example because
932 it refers to a global variable in a not-yet-loaded shared library,
933 don't try to insert watchpoint. We don't automatically delete
934 such watchpoint, though, since failure to parse expression
935 is different from out-of-scope watchpoint. */
936 if (within_current_scope
&& b
->exp
)
938 struct value
*val_chain
, *v
, *result
, *next
;
940 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
942 /* Avoid setting b->val if it's already set. The meaning of
943 b->val is 'the last value' user saw, and we should update
944 it only if we reported that last value to user. As it
945 happens, the code that reports it updates b->val directly. */
952 /* Change the type of breakpoint between hardware assisted or an
953 ordinary watchpoint depending on the hardware support and free
954 hardware slots. REPARSE is set when the inferior is started. */
955 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
958 int i
, mem_cnt
, other_type_used
;
960 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
962 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
965 b
->type
= bp_watchpoint
;
968 int target_resources_ok
= target_can_use_hardware_watchpoint
969 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
970 if (target_resources_ok
<= 0)
971 b
->type
= bp_watchpoint
;
973 b
->type
= bp_hardware_watchpoint
;
977 /* Look at each value on the value chain. */
978 for (v
= val_chain
; v
; v
= next
)
980 /* If it's a memory location, and GDB actually needed
981 its contents to evaluate the expression, then we
982 must watch it. If the first value returned is
983 still lazy, that means an error occurred reading it;
984 watch it anyway in case it becomes readable. */
985 if (VALUE_LVAL (v
) == lval_memory
986 && (v
== val_chain
|| ! value_lazy (v
)))
988 struct type
*vtype
= check_typedef (value_type (v
));
990 /* We only watch structs and arrays if user asked
991 for it explicitly, never if they just happen to
992 appear in the middle of some value chain. */
994 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
995 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
999 struct bp_location
*loc
, **tmp
;
1001 addr
= value_address (v
);
1002 len
= TYPE_LENGTH (value_type (v
));
1004 if (b
->type
== bp_read_watchpoint
)
1006 else if (b
->type
== bp_access_watchpoint
)
1009 loc
= allocate_bp_location (b
);
1010 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1013 loc
->gdbarch
= get_type_arch (value_type (v
));
1014 loc
->address
= addr
;
1016 loc
->watchpoint_type
= type
;
1020 next
= value_next (v
);
1025 /* We just regenerated the list of breakpoint locations.
1026 The new location does not have its condition field set to anything
1027 and therefore, we must always reparse the cond_string, independently
1028 of the value of the reparse flag. */
1029 if (b
->cond_string
!= NULL
)
1031 char *s
= b
->cond_string
;
1032 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1035 else if (!within_current_scope
)
1037 printf_filtered (_("\
1038 Watchpoint %d deleted because the program has left the block \n\
1039 in which its expression is valid.\n"),
1041 if (b
->related_breakpoint
)
1042 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1043 b
->disposition
= disp_del_at_next_stop
;
1046 /* Restore the selected frame. */
1047 select_frame (frame_find_by_id (saved_frame_id
));
1051 /* Returns 1 iff breakpoint location should be
1052 inserted in the inferior. */
1054 should_be_inserted (struct bp_location
*bpt
)
1056 if (!breakpoint_enabled (bpt
->owner
))
1059 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1062 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1065 /* Tracepoints are inserted by the target at a time of its choosing,
1067 if (bpt
->owner
->type
== bp_tracepoint
)
1073 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1074 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1075 and HW_BREAKPOINT_ERROR are used to report problems.
1077 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1078 method for each breakpoint or catchpoint type. */
1080 insert_bp_location (struct bp_location
*bpt
,
1081 struct ui_file
*tmp_error_stream
,
1082 int *disabled_breaks
,
1083 int *hw_breakpoint_error
)
1087 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1090 /* Initialize the target-specific information. */
1091 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1092 bpt
->target_info
.placed_address
= bpt
->address
;
1094 if (bpt
->loc_type
== bp_loc_software_breakpoint
1095 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1097 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1099 /* If the explicitly specified breakpoint type
1100 is not hardware breakpoint, check the memory map to see
1101 if the breakpoint address is in read only memory or not.
1102 Two important cases are:
1103 - location type is not hardware breakpoint, memory
1104 is readonly. We change the type of the location to
1105 hardware breakpoint.
1106 - location type is hardware breakpoint, memory is read-write.
1107 This means we've previously made the location hardware one, but
1108 then the memory map changed, so we undo.
1110 When breakpoints are removed, remove_breakpoints will
1111 use location types we've just set here, the only possible
1112 problem is that memory map has changed during running program,
1113 but it's not going to work anyway with current gdb. */
1114 struct mem_region
*mr
1115 = lookup_mem_region (bpt
->target_info
.placed_address
);
1119 if (automatic_hardware_breakpoints
)
1122 enum bp_loc_type new_type
;
1124 if (mr
->attrib
.mode
!= MEM_RW
)
1125 new_type
= bp_loc_hardware_breakpoint
;
1127 new_type
= bp_loc_software_breakpoint
;
1129 if (new_type
!= bpt
->loc_type
)
1131 static int said
= 0;
1132 bpt
->loc_type
= new_type
;
1135 fprintf_filtered (gdb_stdout
, _("\
1136 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1141 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1142 && mr
->attrib
.mode
!= MEM_RW
)
1143 warning (_("cannot set software breakpoint at readonly address %s"),
1144 paddress (bpt
->gdbarch
, bpt
->address
));
1148 /* First check to see if we have to handle an overlay. */
1149 if (overlay_debugging
== ovly_off
1150 || bpt
->section
== NULL
1151 || !(section_is_overlay (bpt
->section
)))
1153 /* No overlay handling: just set the breakpoint. */
1155 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1156 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1159 val
= target_insert_breakpoint (bpt
->gdbarch
,
1164 /* This breakpoint is in an overlay section.
1165 Shall we set a breakpoint at the LMA? */
1166 if (!overlay_events_enabled
)
1168 /* Yes -- overlay event support is not active,
1169 so we must try to set a breakpoint at the LMA.
1170 This will not work for a hardware breakpoint. */
1171 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1172 warning (_("hardware breakpoint %d not supported in overlay!"),
1173 bpt
->owner
->number
);
1176 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1178 /* Set a software (trap) breakpoint at the LMA. */
1179 bpt
->overlay_target_info
= bpt
->target_info
;
1180 bpt
->overlay_target_info
.placed_address
= addr
;
1181 val
= target_insert_breakpoint (bpt
->gdbarch
,
1182 &bpt
->overlay_target_info
);
1184 fprintf_unfiltered (tmp_error_stream
,
1185 "Overlay breakpoint %d failed: in ROM?\n",
1186 bpt
->owner
->number
);
1189 /* Shall we set a breakpoint at the VMA? */
1190 if (section_is_mapped (bpt
->section
))
1192 /* Yes. This overlay section is mapped into memory. */
1193 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1194 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1197 val
= target_insert_breakpoint (bpt
->gdbarch
,
1202 /* No. This breakpoint will not be inserted.
1203 No error, but do not mark the bp as 'inserted'. */
1210 /* Can't set the breakpoint. */
1211 if (solib_name_from_address (bpt
->address
))
1213 /* See also: disable_breakpoints_in_shlibs. */
1215 bpt
->shlib_disabled
= 1;
1216 if (!*disabled_breaks
)
1218 fprintf_unfiltered (tmp_error_stream
,
1219 "Cannot insert breakpoint %d.\n",
1220 bpt
->owner
->number
);
1221 fprintf_unfiltered (tmp_error_stream
,
1222 "Temporarily disabling shared library breakpoints:\n");
1224 *disabled_breaks
= 1;
1225 fprintf_unfiltered (tmp_error_stream
,
1226 "breakpoint #%d\n", bpt
->owner
->number
);
1230 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1232 *hw_breakpoint_error
= 1;
1233 fprintf_unfiltered (tmp_error_stream
,
1234 "Cannot insert hardware breakpoint %d.\n",
1235 bpt
->owner
->number
);
1239 fprintf_unfiltered (tmp_error_stream
,
1240 "Cannot insert breakpoint %d.\n",
1241 bpt
->owner
->number
);
1242 fprintf_filtered (tmp_error_stream
,
1243 "Error accessing memory address ");
1244 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1246 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1247 safe_strerror (val
));
1258 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1259 /* NOTE drow/2003-09-08: This state only exists for removing
1260 watchpoints. It's not clear that it's necessary... */
1261 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1263 val
= target_insert_watchpoint (bpt
->address
,
1265 bpt
->watchpoint_type
);
1266 bpt
->inserted
= (val
!= -1);
1269 else if (bpt
->owner
->type
== bp_catchpoint
)
1271 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1272 bpt
->owner
, RETURN_MASK_ERROR
);
1273 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1274 bpt
->owner
->number
);
1276 bpt
->owner
->enable_state
= bp_disabled
;
1280 /* We've already printed an error message if there was a problem
1281 inserting this catchpoint, and we've disabled the catchpoint,
1282 so just return success. */
1289 /* Make sure all breakpoints are inserted in inferior.
1290 Throws exception on any error.
1291 A breakpoint that is already inserted won't be inserted
1292 again, so calling this function twice is safe. */
1294 insert_breakpoints (void)
1296 struct breakpoint
*bpt
;
1298 ALL_BREAKPOINTS (bpt
)
1299 if (is_hardware_watchpoint (bpt
))
1300 update_watchpoint (bpt
, 0 /* don't reparse. */);
1302 update_global_location_list (1);
1304 /* update_global_location_list does not insert breakpoints when
1305 always_inserted_mode is not enabled. Explicitly insert them
1307 if (!breakpoints_always_inserted_mode ())
1308 insert_breakpoint_locations ();
1311 /* insert_breakpoints is used when starting or continuing the program.
1312 remove_breakpoints is used when the program stops.
1313 Both return zero if successful,
1314 or an `errno' value if could not write the inferior. */
1317 insert_breakpoint_locations (void)
1319 struct breakpoint
*bpt
;
1320 struct bp_location
*b
, *temp
;
1323 int disabled_breaks
= 0;
1324 int hw_breakpoint_error
= 0;
1326 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1327 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1329 /* Explicitly mark the warning -- this will only be printed if
1330 there was an error. */
1331 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1333 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1335 if (!should_be_inserted (b
) || b
->inserted
)
1338 /* There is no point inserting thread-specific breakpoints if the
1339 thread no longer exists. */
1340 if (b
->owner
->thread
!= -1
1341 && !valid_thread_id (b
->owner
->thread
))
1344 val
= insert_bp_location (b
, tmp_error_stream
,
1346 &hw_breakpoint_error
);
1351 /* If we failed to insert all locations of a watchpoint,
1352 remove them, as half-inserted watchpoint is of limited use. */
1353 ALL_BREAKPOINTS (bpt
)
1355 int some_failed
= 0;
1356 struct bp_location
*loc
;
1358 if (!is_hardware_watchpoint (bpt
))
1361 if (!breakpoint_enabled (bpt
))
1364 if (bpt
->disposition
== disp_del_at_next_stop
)
1367 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1375 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1377 remove_breakpoint (loc
, mark_uninserted
);
1379 hw_breakpoint_error
= 1;
1380 fprintf_unfiltered (tmp_error_stream
,
1381 "Could not insert hardware watchpoint %d.\n",
1389 /* If a hardware breakpoint or watchpoint was inserted, add a
1390 message about possibly exhausted resources. */
1391 if (hw_breakpoint_error
)
1393 fprintf_unfiltered (tmp_error_stream
,
1394 "Could not insert hardware breakpoints:\n\
1395 You may have requested too many hardware breakpoints/watchpoints.\n");
1397 target_terminal_ours_for_output ();
1398 error_stream (tmp_error_stream
);
1401 do_cleanups (cleanups
);
1405 remove_breakpoints (void)
1407 struct bp_location
*b
;
1410 ALL_BP_LOCATIONS (b
)
1414 val
= remove_breakpoint (b
, mark_uninserted
);
1423 remove_hw_watchpoints (void)
1425 struct bp_location
*b
;
1428 ALL_BP_LOCATIONS (b
)
1430 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1432 val
= remove_breakpoint (b
, mark_uninserted
);
1441 reattach_breakpoints (int pid
)
1443 struct bp_location
*b
;
1445 struct cleanup
*old_chain
= save_inferior_ptid ();
1446 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1447 int dummy1
= 0, dummy2
= 0;
1449 make_cleanup_ui_file_delete (tmp_error_stream
);
1451 inferior_ptid
= pid_to_ptid (pid
);
1452 ALL_BP_LOCATIONS (b
)
1457 val
= insert_bp_location (b
, tmp_error_stream
,
1461 do_cleanups (old_chain
);
1466 do_cleanups (old_chain
);
1470 static int internal_breakpoint_number
= -1;
1472 static struct breakpoint
*
1473 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1474 CORE_ADDR address
, enum bptype type
)
1476 struct symtab_and_line sal
;
1477 struct breakpoint
*b
;
1479 init_sal (&sal
); /* initialize to zeroes */
1482 sal
.section
= find_pc_overlay (sal
.pc
);
1484 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1485 b
->number
= internal_breakpoint_number
--;
1486 b
->disposition
= disp_donttouch
;
1492 create_overlay_event_breakpoint (char *func_name
)
1494 struct objfile
*objfile
;
1496 ALL_OBJFILES (objfile
)
1498 struct breakpoint
*b
;
1499 struct minimal_symbol
*m
;
1501 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1505 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1506 SYMBOL_VALUE_ADDRESS (m
),
1508 b
->addr_string
= xstrdup (func_name
);
1510 if (overlay_debugging
== ovly_auto
)
1512 b
->enable_state
= bp_enabled
;
1513 overlay_events_enabled
= 1;
1517 b
->enable_state
= bp_disabled
;
1518 overlay_events_enabled
= 0;
1521 update_global_location_list (1);
1525 create_longjmp_master_breakpoint (char *func_name
)
1527 struct objfile
*objfile
;
1529 ALL_OBJFILES (objfile
)
1531 struct breakpoint
*b
;
1532 struct minimal_symbol
*m
;
1534 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1537 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1541 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1542 SYMBOL_VALUE_ADDRESS (m
),
1544 b
->addr_string
= xstrdup (func_name
);
1545 b
->enable_state
= bp_disabled
;
1547 update_global_location_list (1);
1551 update_breakpoints_after_exec (void)
1553 struct breakpoint
*b
;
1554 struct breakpoint
*temp
;
1555 struct bp_location
*bploc
;
1557 /* We're about to delete breakpoints from GDB's lists. If the
1558 INSERTED flag is true, GDB will try to lift the breakpoints by
1559 writing the breakpoints' "shadow contents" back into memory. The
1560 "shadow contents" are NOT valid after an exec, so GDB should not
1561 do that. Instead, the target is responsible from marking
1562 breakpoints out as soon as it detects an exec. We don't do that
1563 here instead, because there may be other attempts to delete
1564 breakpoints after detecting an exec and before reaching here. */
1565 ALL_BP_LOCATIONS (bploc
)
1566 gdb_assert (!bploc
->inserted
);
1568 ALL_BREAKPOINTS_SAFE (b
, temp
)
1570 /* Solib breakpoints must be explicitly reset after an exec(). */
1571 if (b
->type
== bp_shlib_event
)
1573 delete_breakpoint (b
);
1577 /* Thread event breakpoints must be set anew after an exec(),
1578 as must overlay event and longjmp master breakpoints. */
1579 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1580 || b
->type
== bp_longjmp_master
)
1582 delete_breakpoint (b
);
1586 /* Step-resume breakpoints are meaningless after an exec(). */
1587 if (b
->type
== bp_step_resume
)
1589 delete_breakpoint (b
);
1593 /* Longjmp and longjmp-resume breakpoints are also meaningless
1595 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1597 delete_breakpoint (b
);
1601 if (b
->type
== bp_catchpoint
)
1603 /* For now, none of the bp_catchpoint breakpoints need to
1604 do anything at this point. In the future, if some of
1605 the catchpoints need to something, we will need to add
1606 a new method, and call this method from here. */
1610 /* bp_finish is a special case. The only way we ought to be able
1611 to see one of these when an exec() has happened, is if the user
1612 caught a vfork, and then said "finish". Ordinarily a finish just
1613 carries them to the call-site of the current callee, by setting
1614 a temporary bp there and resuming. But in this case, the finish
1615 will carry them entirely through the vfork & exec.
1617 We don't want to allow a bp_finish to remain inserted now. But
1618 we can't safely delete it, 'cause finish_command has a handle to
1619 the bp on a bpstat, and will later want to delete it. There's a
1620 chance (and I've seen it happen) that if we delete the bp_finish
1621 here, that its storage will get reused by the time finish_command
1622 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1623 We really must allow finish_command to delete a bp_finish.
1625 In the absense of a general solution for the "how do we know
1626 it's safe to delete something others may have handles to?"
1627 problem, what we'll do here is just uninsert the bp_finish, and
1628 let finish_command delete it.
1630 (We know the bp_finish is "doomed" in the sense that it's
1631 momentary, and will be deleted as soon as finish_command sees
1632 the inferior stopped. So it doesn't matter that the bp's
1633 address is probably bogus in the new a.out, unlike e.g., the
1634 solib breakpoints.) */
1636 if (b
->type
== bp_finish
)
1641 /* Without a symbolic address, we have little hope of the
1642 pre-exec() address meaning the same thing in the post-exec()
1644 if (b
->addr_string
== NULL
)
1646 delete_breakpoint (b
);
1650 /* FIXME what about longjmp breakpoints? Re-create them here? */
1651 create_overlay_event_breakpoint ("_ovly_debug_event");
1652 create_longjmp_master_breakpoint ("longjmp");
1653 create_longjmp_master_breakpoint ("_longjmp");
1654 create_longjmp_master_breakpoint ("siglongjmp");
1655 create_longjmp_master_breakpoint ("_siglongjmp");
1659 detach_breakpoints (int pid
)
1661 struct bp_location
*b
;
1663 struct cleanup
*old_chain
= save_inferior_ptid ();
1665 if (pid
== PIDGET (inferior_ptid
))
1666 error (_("Cannot detach breakpoints of inferior_ptid"));
1668 /* Set inferior_ptid; remove_breakpoint uses this global. */
1669 inferior_ptid
= pid_to_ptid (pid
);
1670 ALL_BP_LOCATIONS (b
)
1674 val
= remove_breakpoint (b
, mark_inserted
);
1677 do_cleanups (old_chain
);
1682 do_cleanups (old_chain
);
1687 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1691 if (b
->owner
->enable_state
== bp_permanent
)
1692 /* Permanent breakpoints cannot be inserted or removed. */
1695 /* The type of none suggests that owner is actually deleted.
1696 This should not ever happen. */
1697 gdb_assert (b
->owner
->type
!= bp_none
);
1699 if (b
->loc_type
== bp_loc_software_breakpoint
1700 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1702 /* "Normal" instruction breakpoint: either the standard
1703 trap-instruction bp (bp_breakpoint), or a
1704 bp_hardware_breakpoint. */
1706 /* First check to see if we have to handle an overlay. */
1707 if (overlay_debugging
== ovly_off
1708 || b
->section
== NULL
1709 || !(section_is_overlay (b
->section
)))
1711 /* No overlay handling: just remove the breakpoint. */
1713 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1714 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
1716 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
1720 /* This breakpoint is in an overlay section.
1721 Did we set a breakpoint at the LMA? */
1722 if (!overlay_events_enabled
)
1724 /* Yes -- overlay event support is not active, so we
1725 should have set a breakpoint at the LMA. Remove it.
1727 /* Ignore any failures: if the LMA is in ROM, we will
1728 have already warned when we failed to insert it. */
1729 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1730 target_remove_hw_breakpoint (b
->gdbarch
,
1731 &b
->overlay_target_info
);
1733 target_remove_breakpoint (b
->gdbarch
,
1734 &b
->overlay_target_info
);
1736 /* Did we set a breakpoint at the VMA?
1737 If so, we will have marked the breakpoint 'inserted'. */
1740 /* Yes -- remove it. Previously we did not bother to
1741 remove the breakpoint if the section had been
1742 unmapped, but let's not rely on that being safe. We
1743 don't know what the overlay manager might do. */
1744 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1745 val
= target_remove_hw_breakpoint (b
->gdbarch
,
1748 /* However, we should remove *software* breakpoints only
1749 if the section is still mapped, or else we overwrite
1750 wrong code with the saved shadow contents. */
1751 else if (section_is_mapped (b
->section
))
1752 val
= target_remove_breakpoint (b
->gdbarch
,
1759 /* No -- not inserted, so no need to remove. No error. */
1764 /* In some cases, we might not be able to remove a breakpoint
1765 in a shared library that has already been removed, but we
1766 have not yet processed the shlib unload event. */
1767 if (val
&& solib_name_from_address (b
->address
))
1772 b
->inserted
= (is
== mark_inserted
);
1774 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1779 b
->inserted
= (is
== mark_inserted
);
1780 val
= target_remove_watchpoint (b
->address
, b
->length
,
1781 b
->watchpoint_type
);
1783 /* Failure to remove any of the hardware watchpoints comes here. */
1784 if ((is
== mark_uninserted
) && (b
->inserted
))
1785 warning (_("Could not remove hardware watchpoint %d."),
1788 else if (b
->owner
->type
== bp_catchpoint
1789 && breakpoint_enabled (b
->owner
)
1792 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1794 val
= b
->owner
->ops
->remove (b
->owner
);
1797 b
->inserted
= (is
== mark_inserted
);
1803 /* Clear the "inserted" flag in all breakpoints. */
1806 mark_breakpoints_out (void)
1808 struct bp_location
*bpt
;
1810 ALL_BP_LOCATIONS (bpt
)
1814 /* Clear the "inserted" flag in all breakpoints and delete any
1815 breakpoints which should go away between runs of the program.
1817 Plus other such housekeeping that has to be done for breakpoints
1820 Note: this function gets called at the end of a run (by
1821 generic_mourn_inferior) and when a run begins (by
1822 init_wait_for_inferior). */
1827 breakpoint_init_inferior (enum inf_context context
)
1829 struct breakpoint
*b
, *temp
;
1830 struct bp_location
*bpt
;
1833 /* If breakpoint locations are shared across processes, then there's
1835 if (gdbarch_has_global_breakpoints (target_gdbarch
))
1838 ALL_BP_LOCATIONS (bpt
)
1839 if (bpt
->owner
->enable_state
!= bp_permanent
)
1842 ALL_BREAKPOINTS_SAFE (b
, temp
)
1847 case bp_watchpoint_scope
:
1849 /* If the call dummy breakpoint is at the entry point it will
1850 cause problems when the inferior is rerun, so we better
1853 Also get rid of scope breakpoints. */
1854 delete_breakpoint (b
);
1858 case bp_hardware_watchpoint
:
1859 case bp_read_watchpoint
:
1860 case bp_access_watchpoint
:
1862 /* Likewise for watchpoints on local expressions. */
1863 if (b
->exp_valid_block
!= NULL
)
1864 delete_breakpoint (b
);
1865 else if (context
== inf_starting
)
1867 /* Reset val field to force reread of starting value
1868 in insert_breakpoints. */
1870 value_free (b
->val
);
1880 /* Get rid of the moribund locations. */
1881 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1882 free_bp_location (bpt
);
1883 VEC_free (bp_location_p
, moribund_locations
);
1886 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1887 exists at PC. It returns ordinary_breakpoint_here if it's an
1888 ordinary breakpoint, or permanent_breakpoint_here if it's a
1889 permanent breakpoint.
1890 - When continuing from a location with an ordinary breakpoint, we
1891 actually single step once before calling insert_breakpoints.
1892 - When continuing from a localion with a permanent breakpoint, we
1893 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1894 the target, to advance the PC past the breakpoint. */
1896 enum breakpoint_here
1897 breakpoint_here_p (CORE_ADDR pc
)
1899 const struct bp_location
*bpt
;
1900 int any_breakpoint_here
= 0;
1902 ALL_BP_LOCATIONS (bpt
)
1904 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1905 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1908 if ((breakpoint_enabled (bpt
->owner
)
1909 || bpt
->owner
->enable_state
== bp_permanent
)
1910 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1912 if (overlay_debugging
1913 && section_is_overlay (bpt
->section
)
1914 && !section_is_mapped (bpt
->section
))
1915 continue; /* unmapped overlay -- can't be a match */
1916 else if (bpt
->owner
->enable_state
== bp_permanent
)
1917 return permanent_breakpoint_here
;
1919 any_breakpoint_here
= 1;
1923 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1926 /* Return true if there's a moribund breakpoint at PC. */
1929 moribund_breakpoint_here_p (CORE_ADDR pc
)
1931 struct bp_location
*loc
;
1934 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1935 if (loc
->address
== pc
)
1941 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1942 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1943 This does not check for single-step breakpoints, which are
1944 inserted and removed using direct target manipulation. */
1947 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1949 const struct bp_location
*bpt
;
1951 ALL_BP_LOCATIONS (bpt
)
1953 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1954 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1958 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1960 if (overlay_debugging
1961 && section_is_overlay (bpt
->section
)
1962 && !section_is_mapped (bpt
->section
))
1963 continue; /* unmapped overlay -- can't be a match */
1971 /* Returns non-zero iff there's either regular breakpoint
1972 or a single step breakpoint inserted at PC. */
1975 breakpoint_inserted_here_p (CORE_ADDR pc
)
1977 if (regular_breakpoint_inserted_here_p (pc
))
1980 if (single_step_breakpoint_inserted_here_p (pc
))
1986 /* This function returns non-zero iff there is a software breakpoint
1990 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1992 const struct bp_location
*bpt
;
1993 int any_breakpoint_here
= 0;
1995 ALL_BP_LOCATIONS (bpt
)
1997 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2001 && bpt
->address
== pc
) /* bp is enabled and matches pc */
2003 if (overlay_debugging
2004 && section_is_overlay (bpt
->section
)
2005 && !section_is_mapped (bpt
->section
))
2006 continue; /* unmapped overlay -- can't be a match */
2012 /* Also check for software single-step breakpoints. */
2013 if (single_step_breakpoint_inserted_here_p (pc
))
2019 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2020 PC is valid for process/thread PTID. */
2023 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
2025 const struct bp_location
*bpt
;
2026 /* The thread and task IDs associated to PTID, computed lazily. */
2030 ALL_BP_LOCATIONS (bpt
)
2032 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2033 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2036 if (!breakpoint_enabled (bpt
->owner
)
2037 && bpt
->owner
->enable_state
!= bp_permanent
)
2040 if (bpt
->address
!= pc
)
2043 if (bpt
->owner
->thread
!= -1)
2045 /* This is a thread-specific breakpoint. Check that ptid
2046 matches that thread. If thread hasn't been computed yet,
2047 it is now time to do so. */
2049 thread
= pid_to_thread_id (ptid
);
2050 if (bpt
->owner
->thread
!= thread
)
2054 if (bpt
->owner
->task
!= 0)
2056 /* This is a task-specific breakpoint. Check that ptid
2057 matches that task. If task hasn't been computed yet,
2058 it is now time to do so. */
2060 task
= ada_get_task_number (ptid
);
2061 if (bpt
->owner
->task
!= task
)
2065 if (overlay_debugging
2066 && section_is_overlay (bpt
->section
)
2067 && !section_is_mapped (bpt
->section
))
2068 continue; /* unmapped overlay -- can't be a match */
2077 /* bpstat stuff. External routines' interfaces are documented
2081 ep_is_catchpoint (struct breakpoint
*ep
)
2083 return (ep
->type
== bp_catchpoint
);
2087 bpstat_free (bpstat bs
)
2089 if (bs
->old_val
!= NULL
)
2090 value_free (bs
->old_val
);
2091 free_command_lines (&bs
->commands
);
2095 /* Clear a bpstat so that it says we are not at any breakpoint.
2096 Also free any storage that is part of a bpstat. */
2099 bpstat_clear (bpstat
*bsp
)
2116 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2117 is part of the bpstat is copied as well. */
2120 bpstat_copy (bpstat bs
)
2124 bpstat retval
= NULL
;
2129 for (; bs
!= NULL
; bs
= bs
->next
)
2131 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2132 memcpy (tmp
, bs
, sizeof (*tmp
));
2133 if (bs
->commands
!= NULL
)
2134 tmp
->commands
= copy_command_lines (bs
->commands
);
2135 if (bs
->old_val
!= NULL
)
2137 tmp
->old_val
= value_copy (bs
->old_val
);
2138 release_value (tmp
->old_val
);
2142 /* This is the first thing in the chain. */
2152 /* Find the bpstat associated with this breakpoint */
2155 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2160 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2162 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2168 /* Find a step_resume breakpoint associated with this bpstat.
2169 (If there are multiple step_resume bp's on the list, this function
2170 will arbitrarily pick one.)
2172 It is an error to use this function if BPSTAT doesn't contain a
2173 step_resume breakpoint.
2175 See wait_for_inferior's use of this function. */
2177 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2181 gdb_assert (bsp
!= NULL
);
2183 current_thread
= pid_to_thread_id (inferior_ptid
);
2185 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2187 if ((bsp
->breakpoint_at
!= NULL
)
2188 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2189 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2190 || bsp
->breakpoint_at
->owner
->thread
== -1))
2191 return bsp
->breakpoint_at
->owner
;
2194 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2198 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2199 at. *BSP upon return is a bpstat which points to the remaining
2200 breakpoints stopped at (but which is not guaranteed to be good for
2201 anything but further calls to bpstat_num).
2202 Return 0 if passed a bpstat which does not indicate any breakpoints.
2203 Return -1 if stopped at a breakpoint that has been deleted since
2205 Return 1 otherwise. */
2208 bpstat_num (bpstat
*bsp
, int *num
)
2210 struct breakpoint
*b
;
2213 return 0; /* No more breakpoint values */
2215 /* We assume we'll never have several bpstats that
2216 correspond to a single breakpoint -- otherwise,
2217 this function might return the same number more
2218 than once and this will look ugly. */
2219 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2220 *bsp
= (*bsp
)->next
;
2222 return -1; /* breakpoint that's been deleted since */
2224 *num
= b
->number
; /* We have its number */
2228 /* Modify BS so that the actions will not be performed. */
2231 bpstat_clear_actions (bpstat bs
)
2233 for (; bs
!= NULL
; bs
= bs
->next
)
2235 free_command_lines (&bs
->commands
);
2236 if (bs
->old_val
!= NULL
)
2238 value_free (bs
->old_val
);
2244 /* Called when a command is about to proceed the inferior. */
2247 breakpoint_about_to_proceed (void)
2249 if (!ptid_equal (inferior_ptid
, null_ptid
))
2251 struct thread_info
*tp
= inferior_thread ();
2253 /* Allow inferior function calls in breakpoint commands to not
2254 interrupt the command list. When the call finishes
2255 successfully, the inferior will be standing at the same
2256 breakpoint as if nothing happened. */
2261 breakpoint_proceeded
= 1;
2264 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2266 cleanup_executing_breakpoints (void *ignore
)
2268 executing_breakpoint_commands
= 0;
2271 /* Execute all the commands associated with all the breakpoints at this
2272 location. Any of these commands could cause the process to proceed
2273 beyond this point, etc. We look out for such changes by checking
2274 the global "breakpoint_proceeded" after each command.
2276 Returns true if a breakpoint command resumed the inferior. In that
2277 case, it is the caller's responsibility to recall it again with the
2278 bpstat of the current thread. */
2281 bpstat_do_actions_1 (bpstat
*bsp
)
2284 struct cleanup
*old_chain
;
2287 /* Avoid endless recursion if a `source' command is contained
2289 if (executing_breakpoint_commands
)
2292 executing_breakpoint_commands
= 1;
2293 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2295 /* This pointer will iterate over the list of bpstat's. */
2298 breakpoint_proceeded
= 0;
2299 for (; bs
!= NULL
; bs
= bs
->next
)
2301 struct command_line
*cmd
;
2302 struct cleanup
*this_cmd_tree_chain
;
2304 /* Take ownership of the BSP's command tree, if it has one.
2306 The command tree could legitimately contain commands like
2307 'step' and 'next', which call clear_proceed_status, which
2308 frees stop_bpstat's command tree. To make sure this doesn't
2309 free the tree we're executing out from under us, we need to
2310 take ownership of the tree ourselves. Since a given bpstat's
2311 commands are only executed once, we don't need to copy it; we
2312 can clear the pointer in the bpstat, and make sure we free
2313 the tree when we're done. */
2316 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2320 execute_control_command (cmd
);
2322 if (breakpoint_proceeded
)
2328 /* We can free this command tree now. */
2329 do_cleanups (this_cmd_tree_chain
);
2331 if (breakpoint_proceeded
)
2333 if (target_can_async_p ())
2334 /* If we are in async mode, then the target might be still
2335 running, not stopped at any breakpoint, so nothing for
2336 us to do here -- just return to the event loop. */
2339 /* In sync mode, when execute_control_command returns
2340 we're already standing on the next breakpoint.
2341 Breakpoint commands for that stop were not run, since
2342 execute_command does not run breakpoint commands --
2343 only command_line_handler does, but that one is not
2344 involved in execution of breakpoint commands. So, we
2345 can now execute breakpoint commands. It should be
2346 noted that making execute_command do bpstat actions is
2347 not an option -- in this case we'll have recursive
2348 invocation of bpstat for each breakpoint with a
2349 command, and can easily blow up GDB stack. Instead, we
2350 return true, which will trigger the caller to recall us
2351 with the new stop_bpstat. */
2356 do_cleanups (old_chain
);
2361 bpstat_do_actions (void)
2363 /* Do any commands attached to breakpoint we are stopped at. */
2364 while (!ptid_equal (inferior_ptid
, null_ptid
)
2365 && target_has_execution
2366 && !is_exited (inferior_ptid
)
2367 && !is_executing (inferior_ptid
))
2368 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2369 and only return when it is stopped at the next breakpoint, we
2370 keep doing breakpoint actions until it returns false to
2371 indicate the inferior was not resumed. */
2372 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2376 /* Print out the (old or new) value associated with a watchpoint. */
2379 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2382 fprintf_unfiltered (stream
, _("<unreadable>"));
2385 struct value_print_options opts
;
2386 get_user_print_options (&opts
);
2387 value_print (val
, stream
, &opts
);
2391 /* This is the normal print function for a bpstat. In the future,
2392 much of this logic could (should?) be moved to bpstat_stop_status,
2393 by having it set different print_it values.
2395 Current scheme: When we stop, bpstat_print() is called. It loops
2396 through the bpstat list of things causing this stop, calling the
2397 print_bp_stop_message function on each one. The behavior of the
2398 print_bp_stop_message function depends on the print_it field of
2399 bpstat. If such field so indicates, call this function here.
2401 Return values from this routine (ultimately used by bpstat_print()
2402 and normal_stop() to decide what to do):
2403 PRINT_NOTHING: Means we already printed all we needed to print,
2404 don't print anything else.
2405 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2406 that something to be followed by a location.
2407 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2408 that something to be followed by a location.
2409 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2412 static enum print_stop_action
2413 print_it_typical (bpstat bs
)
2415 struct cleanup
*old_chain
;
2416 struct breakpoint
*b
;
2417 const struct bp_location
*bl
;
2418 struct ui_stream
*stb
;
2420 enum print_stop_action result
;
2422 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2423 which has since been deleted. */
2424 if (bs
->breakpoint_at
== NULL
)
2425 return PRINT_UNKNOWN
;
2426 bl
= bs
->breakpoint_at
;
2429 stb
= ui_out_stream_new (uiout
);
2430 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2435 case bp_hardware_breakpoint
:
2436 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2437 if (bl
->address
!= bl
->requested_address
)
2438 breakpoint_adjustment_warning (bl
->requested_address
,
2441 annotate_breakpoint (b
->number
);
2443 ui_out_text (uiout
, "\nTemporary breakpoint ");
2445 ui_out_text (uiout
, "\nBreakpoint ");
2446 if (ui_out_is_mi_like_p (uiout
))
2448 ui_out_field_string (uiout
, "reason",
2449 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2450 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2452 ui_out_field_int (uiout
, "bkptno", b
->number
);
2453 ui_out_text (uiout
, ", ");
2454 result
= PRINT_SRC_AND_LOC
;
2457 case bp_shlib_event
:
2458 /* Did we stop because the user set the stop_on_solib_events
2459 variable? (If so, we report this as a generic, "Stopped due
2460 to shlib event" message.) */
2461 printf_filtered (_("Stopped due to shared library event\n"));
2462 result
= PRINT_NOTHING
;
2465 case bp_thread_event
:
2466 /* Not sure how we will get here.
2467 GDB should not stop for these breakpoints. */
2468 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2469 result
= PRINT_NOTHING
;
2472 case bp_overlay_event
:
2473 /* By analogy with the thread event, GDB should not stop for these. */
2474 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2475 result
= PRINT_NOTHING
;
2478 case bp_longjmp_master
:
2479 /* These should never be enabled. */
2480 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2481 result
= PRINT_NOTHING
;
2485 case bp_hardware_watchpoint
:
2486 annotate_watchpoint (b
->number
);
2487 if (ui_out_is_mi_like_p (uiout
))
2490 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2492 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2493 ui_out_text (uiout
, "\nOld value = ");
2494 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2495 ui_out_field_stream (uiout
, "old", stb
);
2496 ui_out_text (uiout
, "\nNew value = ");
2497 watchpoint_value_print (b
->val
, stb
->stream
);
2498 ui_out_field_stream (uiout
, "new", stb
);
2499 ui_out_text (uiout
, "\n");
2500 /* More than one watchpoint may have been triggered. */
2501 result
= PRINT_UNKNOWN
;
2504 case bp_read_watchpoint
:
2505 if (ui_out_is_mi_like_p (uiout
))
2508 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2510 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2511 ui_out_text (uiout
, "\nValue = ");
2512 watchpoint_value_print (b
->val
, stb
->stream
);
2513 ui_out_field_stream (uiout
, "value", stb
);
2514 ui_out_text (uiout
, "\n");
2515 result
= PRINT_UNKNOWN
;
2518 case bp_access_watchpoint
:
2519 if (bs
->old_val
!= NULL
)
2521 annotate_watchpoint (b
->number
);
2522 if (ui_out_is_mi_like_p (uiout
))
2525 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2527 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2528 ui_out_text (uiout
, "\nOld value = ");
2529 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2530 ui_out_field_stream (uiout
, "old", stb
);
2531 ui_out_text (uiout
, "\nNew value = ");
2536 if (ui_out_is_mi_like_p (uiout
))
2539 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2540 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2541 ui_out_text (uiout
, "\nValue = ");
2543 watchpoint_value_print (b
->val
, stb
->stream
);
2544 ui_out_field_stream (uiout
, "new", stb
);
2545 ui_out_text (uiout
, "\n");
2546 result
= PRINT_UNKNOWN
;
2549 /* Fall through, we don't deal with these types of breakpoints
2553 if (ui_out_is_mi_like_p (uiout
))
2556 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2557 result
= PRINT_UNKNOWN
;
2561 if (ui_out_is_mi_like_p (uiout
))
2564 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2565 result
= PRINT_UNKNOWN
;
2570 case bp_longjmp_resume
:
2571 case bp_step_resume
:
2572 case bp_watchpoint_scope
:
2576 result
= PRINT_UNKNOWN
;
2580 do_cleanups (old_chain
);
2584 /* Generic routine for printing messages indicating why we
2585 stopped. The behavior of this function depends on the value
2586 'print_it' in the bpstat structure. Under some circumstances we
2587 may decide not to print anything here and delegate the task to
2590 static enum print_stop_action
2591 print_bp_stop_message (bpstat bs
)
2593 switch (bs
->print_it
)
2596 /* Nothing should be printed for this bpstat entry. */
2597 return PRINT_UNKNOWN
;
2601 /* We still want to print the frame, but we already printed the
2602 relevant messages. */
2603 return PRINT_SRC_AND_LOC
;
2606 case print_it_normal
:
2608 const struct bp_location
*bl
= bs
->breakpoint_at
;
2609 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2611 /* Normal case. Call the breakpoint's print_it method, or
2612 print_it_typical. */
2613 /* FIXME: how breakpoint can ever be NULL here? */
2614 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2615 return b
->ops
->print_it (b
);
2617 return print_it_typical (bs
);
2622 internal_error (__FILE__
, __LINE__
,
2623 _("print_bp_stop_message: unrecognized enum value"));
2628 /* Print a message indicating what happened. This is called from
2629 normal_stop(). The input to this routine is the head of the bpstat
2630 list - a list of the eventpoints that caused this stop. This
2631 routine calls the generic print routine for printing a message
2632 about reasons for stopping. This will print (for example) the
2633 "Breakpoint n," part of the output. The return value of this
2636 PRINT_UNKNOWN: Means we printed nothing
2637 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2638 code to print the location. An example is
2639 "Breakpoint 1, " which should be followed by
2641 PRINT_SRC_ONLY: Means we printed something, but there is no need
2642 to also print the location part of the message.
2643 An example is the catch/throw messages, which
2644 don't require a location appended to the end.
2645 PRINT_NOTHING: We have done some printing and we don't need any
2646 further info to be printed.*/
2648 enum print_stop_action
2649 bpstat_print (bpstat bs
)
2653 /* Maybe another breakpoint in the chain caused us to stop.
2654 (Currently all watchpoints go on the bpstat whether hit or not.
2655 That probably could (should) be changed, provided care is taken
2656 with respect to bpstat_explains_signal). */
2657 for (; bs
; bs
= bs
->next
)
2659 val
= print_bp_stop_message (bs
);
2660 if (val
== PRINT_SRC_ONLY
2661 || val
== PRINT_SRC_AND_LOC
2662 || val
== PRINT_NOTHING
)
2666 /* We reached the end of the chain, or we got a null BS to start
2667 with and nothing was printed. */
2668 return PRINT_UNKNOWN
;
2671 /* Evaluate the expression EXP and return 1 if value is zero.
2672 This is used inside a catch_errors to evaluate the breakpoint condition.
2673 The argument is a "struct expression *" that has been cast to char * to
2674 make it pass through catch_errors. */
2677 breakpoint_cond_eval (void *exp
)
2679 struct value
*mark
= value_mark ();
2680 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2681 value_free_to_mark (mark
);
2685 /* Allocate a new bpstat and chain it to the current one. */
2688 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2692 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2694 bs
->breakpoint_at
= bl
;
2695 /* If the condition is false, etc., don't do the commands. */
2696 bs
->commands
= NULL
;
2698 bs
->print_it
= print_it_normal
;
2702 /* The target has stopped with waitstatus WS. Check if any hardware
2703 watchpoints have triggered, according to the target. */
2706 watchpoints_triggered (struct target_waitstatus
*ws
)
2708 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
2710 struct breakpoint
*b
;
2712 if (!stopped_by_watchpoint
)
2714 /* We were not stopped by a watchpoint. Mark all watchpoints
2715 as not triggered. */
2717 if (b
->type
== bp_hardware_watchpoint
2718 || b
->type
== bp_read_watchpoint
2719 || b
->type
== bp_access_watchpoint
)
2720 b
->watchpoint_triggered
= watch_triggered_no
;
2725 if (!target_stopped_data_address (¤t_target
, &addr
))
2727 /* We were stopped by a watchpoint, but we don't know where.
2728 Mark all watchpoints as unknown. */
2730 if (b
->type
== bp_hardware_watchpoint
2731 || b
->type
== bp_read_watchpoint
2732 || b
->type
== bp_access_watchpoint
)
2733 b
->watchpoint_triggered
= watch_triggered_unknown
;
2735 return stopped_by_watchpoint
;
2738 /* The target could report the data address. Mark watchpoints
2739 affected by this data address as triggered, and all others as not
2743 if (b
->type
== bp_hardware_watchpoint
2744 || b
->type
== bp_read_watchpoint
2745 || b
->type
== bp_access_watchpoint
)
2747 struct bp_location
*loc
;
2750 b
->watchpoint_triggered
= watch_triggered_no
;
2751 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2752 /* Exact match not required. Within range is
2754 if (target_watchpoint_addr_within_range (¤t_target
,
2758 b
->watchpoint_triggered
= watch_triggered_yes
;
2766 /* Possible return values for watchpoint_check (this can't be an enum
2767 because of check_errors). */
2768 /* The watchpoint has been deleted. */
2769 #define WP_DELETED 1
2770 /* The value has changed. */
2771 #define WP_VALUE_CHANGED 2
2772 /* The value has not changed. */
2773 #define WP_VALUE_NOT_CHANGED 3
2775 #define BP_TEMPFLAG 1
2776 #define BP_HARDWAREFLAG 2
2778 /* Check watchpoint condition. */
2781 watchpoint_check (void *p
)
2783 bpstat bs
= (bpstat
) p
;
2784 struct breakpoint
*b
;
2785 struct frame_info
*fr
;
2786 int within_current_scope
;
2788 b
= bs
->breakpoint_at
->owner
;
2790 if (b
->exp_valid_block
== NULL
)
2791 within_current_scope
= 1;
2794 struct frame_info
*frame
= get_current_frame ();
2795 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
2796 CORE_ADDR frame_pc
= get_frame_pc (frame
);
2798 fr
= frame_find_by_id (b
->watchpoint_frame
);
2799 within_current_scope
= (fr
!= NULL
);
2801 /* If we've gotten confused in the unwinder, we might have
2802 returned a frame that can't describe this variable. */
2803 if (within_current_scope
)
2805 struct symbol
*function
;
2807 function
= get_frame_function (fr
);
2808 if (function
== NULL
2809 || !contained_in (b
->exp_valid_block
,
2810 SYMBOL_BLOCK_VALUE (function
)))
2811 within_current_scope
= 0;
2814 /* in_function_epilogue_p() returns a non-zero value if we're still
2815 in the function but the stack frame has already been invalidated.
2816 Since we can't rely on the values of local variables after the
2817 stack has been destroyed, we are treating the watchpoint in that
2818 state as `not changed' without further checking. Don't mark
2819 watchpoints as changed if the current frame is in an epilogue -
2820 even if they are in some other frame, our view of the stack
2821 is likely to be wrong. */
2822 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
2823 return WP_VALUE_NOT_CHANGED
;
2825 if (within_current_scope
)
2826 /* If we end up stopping, the current frame will get selected
2827 in normal_stop. So this call to select_frame won't affect
2832 if (within_current_scope
)
2834 /* We use value_{,free_to_}mark because it could be a
2835 *long* time before we return to the command level and
2836 call free_all_values. We can't call free_all_values because
2837 we might be in the middle of evaluating a function call. */
2839 struct value
*mark
= value_mark ();
2840 struct value
*new_val
;
2842 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2843 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2844 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2846 if (new_val
!= NULL
)
2848 release_value (new_val
);
2849 value_free_to_mark (mark
);
2851 bs
->old_val
= b
->val
;
2854 /* We will stop here */
2855 return WP_VALUE_CHANGED
;
2859 /* Nothing changed, don't do anything. */
2860 value_free_to_mark (mark
);
2861 /* We won't stop here */
2862 return WP_VALUE_NOT_CHANGED
;
2867 /* This seems like the only logical thing to do because
2868 if we temporarily ignored the watchpoint, then when
2869 we reenter the block in which it is valid it contains
2870 garbage (in the case of a function, it may have two
2871 garbage values, one before and one after the prologue).
2872 So we can't even detect the first assignment to it and
2873 watch after that (since the garbage may or may not equal
2874 the first value assigned). */
2875 /* We print all the stop information in print_it_typical(), but
2876 in this case, by the time we call print_it_typical() this bp
2877 will be deleted already. So we have no choice but print the
2878 information here. */
2879 if (ui_out_is_mi_like_p (uiout
))
2881 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2882 ui_out_text (uiout
, "\nWatchpoint ");
2883 ui_out_field_int (uiout
, "wpnum", b
->number
);
2884 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2885 which its expression is valid.\n");
2887 if (b
->related_breakpoint
)
2888 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2889 b
->disposition
= disp_del_at_next_stop
;
2895 /* Return true if it looks like target has stopped due to hitting
2896 breakpoint location BL. This function does not check if we
2897 should stop, only if BL explains the stop. */
2899 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2901 struct breakpoint
*b
= bl
->owner
;
2903 if (b
->type
!= bp_watchpoint
2904 && b
->type
!= bp_hardware_watchpoint
2905 && b
->type
!= bp_read_watchpoint
2906 && b
->type
!= bp_access_watchpoint
2907 && b
->type
!= bp_hardware_breakpoint
2908 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2910 if (bl
->address
!= bp_addr
) /* address doesn't match */
2912 if (overlay_debugging
/* unmapped overlay section */
2913 && section_is_overlay (bl
->section
)
2914 && !section_is_mapped (bl
->section
))
2918 /* Continuable hardware watchpoints are treated as non-existent if the
2919 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2920 some data address). Otherwise gdb won't stop on a break instruction
2921 in the code (not from a breakpoint) when a hardware watchpoint has
2922 been defined. Also skip watchpoints which we know did not trigger
2923 (did not match the data address). */
2925 if ((b
->type
== bp_hardware_watchpoint
2926 || b
->type
== bp_read_watchpoint
2927 || b
->type
== bp_access_watchpoint
)
2928 && b
->watchpoint_triggered
== watch_triggered_no
)
2931 if (b
->type
== bp_hardware_breakpoint
)
2933 if (bl
->address
!= bp_addr
)
2935 if (overlay_debugging
/* unmapped overlay section */
2936 && section_is_overlay (bl
->section
)
2937 && !section_is_mapped (bl
->section
))
2941 if (b
->type
== bp_catchpoint
)
2943 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2944 if (!b
->ops
->breakpoint_hit (b
))
2951 /* If BS refers to a watchpoint, determine if the watched values
2952 has actually changed, and we should stop. If not, set BS->stop
2955 bpstat_check_watchpoint (bpstat bs
)
2957 const struct bp_location
*bl
= bs
->breakpoint_at
;
2958 struct breakpoint
*b
= bl
->owner
;
2960 if (b
->type
== bp_watchpoint
2961 || b
->type
== bp_read_watchpoint
2962 || b
->type
== bp_access_watchpoint
2963 || b
->type
== bp_hardware_watchpoint
)
2967 int must_check_value
= 0;
2969 if (b
->type
== bp_watchpoint
)
2970 /* For a software watchpoint, we must always check the
2972 must_check_value
= 1;
2973 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2974 /* We have a hardware watchpoint (read, write, or access)
2975 and the target earlier reported an address watched by
2977 must_check_value
= 1;
2978 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2979 && b
->type
== bp_hardware_watchpoint
)
2980 /* We were stopped by a hardware watchpoint, but the target could
2981 not report the data address. We must check the watchpoint's
2982 value. Access and read watchpoints are out of luck; without
2983 a data address, we can't figure it out. */
2984 must_check_value
= 1;
2986 if (must_check_value
)
2988 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2990 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2991 int e
= catch_errors (watchpoint_check
, bs
, message
,
2993 do_cleanups (cleanups
);
2997 /* We've already printed what needs to be printed. */
2998 bs
->print_it
= print_it_done
;
3001 case WP_VALUE_CHANGED
:
3002 if (b
->type
== bp_read_watchpoint
)
3004 /* Don't stop: read watchpoints shouldn't fire if
3005 the value has changed. This is for targets
3006 which cannot set read-only watchpoints. */
3007 bs
->print_it
= print_it_noop
;
3011 case WP_VALUE_NOT_CHANGED
:
3012 if (b
->type
== bp_hardware_watchpoint
3013 || b
->type
== bp_watchpoint
)
3015 /* Don't stop: write watchpoints shouldn't fire if
3016 the value hasn't changed. */
3017 bs
->print_it
= print_it_noop
;
3025 /* Error from catch_errors. */
3026 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3027 if (b
->related_breakpoint
)
3028 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3029 b
->disposition
= disp_del_at_next_stop
;
3030 /* We've already printed what needs to be printed. */
3031 bs
->print_it
= print_it_done
;
3035 else /* must_check_value == 0 */
3037 /* This is a case where some watchpoint(s) triggered, but
3038 not at the address of this watchpoint, or else no
3039 watchpoint triggered after all. So don't print
3040 anything for this watchpoint. */
3041 bs
->print_it
= print_it_noop
;
3048 /* Check conditions (condition proper, frame, thread and ignore count)
3049 of breakpoint referred to by BS. If we should not stop for this
3050 breakpoint, set BS->stop to 0. */
3052 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3054 int thread_id
= pid_to_thread_id (ptid
);
3055 const struct bp_location
*bl
= bs
->breakpoint_at
;
3056 struct breakpoint
*b
= bl
->owner
;
3058 if (frame_id_p (b
->frame_id
)
3059 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3063 int value_is_zero
= 0;
3065 /* If this is a scope breakpoint, mark the associated
3066 watchpoint as triggered so that we will handle the
3067 out-of-scope event. We'll get to the watchpoint next
3069 if (b
->type
== bp_watchpoint_scope
)
3070 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3072 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3074 /* We use value_mark and value_free_to_mark because it could
3075 be a long time before we return to the command level and
3076 call free_all_values. We can't call free_all_values
3077 because we might be in the middle of evaluating a
3079 struct value
*mark
= value_mark ();
3081 /* Need to select the frame, with all that implies so that
3082 the conditions will have the right context. Because we
3083 use the frame, we will not see an inlined function's
3084 variables when we arrive at a breakpoint at the start
3085 of the inlined function; the current frame will be the
3087 select_frame (get_current_frame ());
3089 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3090 "Error in testing breakpoint condition:\n",
3092 /* FIXME-someday, should give breakpoint # */
3093 value_free_to_mark (mark
);
3095 if (bl
->cond
&& value_is_zero
)
3099 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3103 else if (b
->ignore_count
> 0)
3106 annotate_ignore_count_change ();
3108 /* Increase the hit count even though we don't
3116 /* Get a bpstat associated with having just stopped at address
3117 BP_ADDR in thread PTID.
3119 Determine whether we stopped at a breakpoint, etc, or whether we
3120 don't understand this stop. Result is a chain of bpstat's such that:
3122 if we don't understand the stop, the result is a null pointer.
3124 if we understand why we stopped, the result is not null.
3126 Each element of the chain refers to a particular breakpoint or
3127 watchpoint at which we have stopped. (We may have stopped for
3128 several reasons concurrently.)
3130 Each element of the chain has valid next, breakpoint_at,
3131 commands, FIXME??? fields. */
3134 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3136 struct breakpoint
*b
= NULL
;
3137 const struct bp_location
*bl
;
3138 struct bp_location
*loc
;
3139 /* Root of the chain of bpstat's */
3140 struct bpstats root_bs
[1];
3141 /* Pointer to the last thing in the chain currently. */
3142 bpstat bs
= root_bs
;
3144 int need_remove_insert
;
3146 ALL_BP_LOCATIONS (bl
)
3150 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3153 /* For hardware watchpoints, we look only at the first location.
3154 The watchpoint_check function will work on entire expression,
3155 not the individual locations. For read watchopints, the
3156 watchpoints_triggered function have checked all locations
3159 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3162 if (!bpstat_check_location (bl
, bp_addr
))
3165 /* Come here if it's a watchpoint, or if the break address matches */
3167 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3169 /* Assume we stop. Should we find watchpoint that is not actually
3170 triggered, or if condition of breakpoint is false, we'll reset
3175 bpstat_check_watchpoint (bs
);
3179 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3180 || b
->type
== bp_longjmp_master
)
3181 /* We do not stop for these. */
3184 bpstat_check_breakpoint_conditions (bs
, ptid
);
3190 /* We will stop here */
3191 if (b
->disposition
== disp_disable
)
3193 if (b
->enable_state
!= bp_permanent
)
3194 b
->enable_state
= bp_disabled
;
3195 update_global_location_list (0);
3199 bs
->commands
= b
->commands
;
3201 && (strcmp ("silent", bs
->commands
->line
) == 0
3202 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3204 bs
->commands
= bs
->commands
->next
;
3207 bs
->commands
= copy_command_lines (bs
->commands
);
3210 /* Print nothing for this entry if we dont stop or if we dont print. */
3211 if (bs
->stop
== 0 || bs
->print
== 0)
3212 bs
->print_it
= print_it_noop
;
3215 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3217 if (loc
->address
== bp_addr
)
3219 bs
= bpstat_alloc (loc
, bs
);
3220 /* For hits of moribund locations, we should just proceed. */
3223 bs
->print_it
= print_it_noop
;
3227 bs
->next
= NULL
; /* Terminate the chain */
3228 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3230 /* If we aren't stopping, the value of some hardware watchpoint may
3231 not have changed, but the intermediate memory locations we are
3232 watching may have. Don't bother if we're stopping; this will get
3234 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3238 need_remove_insert
= 0;
3240 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3242 && bs
->breakpoint_at
->owner
3243 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3244 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3245 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3247 /* remove/insert can invalidate bs->breakpoint_at, if this
3248 location is no longer used by the watchpoint. Prevent
3249 further code from trying to use it. */
3250 bs
->breakpoint_at
= NULL
;
3251 need_remove_insert
= 1;
3254 if (need_remove_insert
)
3256 remove_breakpoints ();
3257 insert_breakpoints ();
3260 return root_bs
->next
;
3263 /* Tell what to do about this bpstat. */
3265 bpstat_what (bpstat bs
)
3267 /* Classify each bpstat as one of the following. */
3270 /* This bpstat element has no effect on the main_action. */
3273 /* There was a watchpoint, stop but don't print. */
3276 /* There was a watchpoint, stop and print. */
3279 /* There was a breakpoint but we're not stopping. */
3282 /* There was a breakpoint, stop but don't print. */
3285 /* There was a breakpoint, stop and print. */
3288 /* We hit the longjmp breakpoint. */
3291 /* We hit the longjmp_resume breakpoint. */
3294 /* We hit the step_resume breakpoint. */
3297 /* We hit the shared library event breakpoint. */
3300 /* This is just used to count how many enums there are. */
3304 /* Here is the table which drives this routine. So that we can
3305 format it pretty, we define some abbreviations for the
3306 enum bpstat_what codes. */
3307 #define kc BPSTAT_WHAT_KEEP_CHECKING
3308 #define ss BPSTAT_WHAT_STOP_SILENT
3309 #define sn BPSTAT_WHAT_STOP_NOISY
3310 #define sgl BPSTAT_WHAT_SINGLE
3311 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3312 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3313 #define sr BPSTAT_WHAT_STEP_RESUME
3314 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3316 /* "Can't happen." Might want to print an error message.
3317 abort() is not out of the question, but chances are GDB is just
3318 a bit confused, not unusable. */
3319 #define err BPSTAT_WHAT_STOP_NOISY
3321 /* Given an old action and a class, come up with a new action. */
3322 /* One interesting property of this table is that wp_silent is the same
3323 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3324 after stopping, the check for whether to step over a breakpoint
3325 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3326 reference to how we stopped. We retain separate wp_silent and
3327 bp_silent codes in case we want to change that someday.
3329 Another possibly interesting property of this table is that
3330 there's a partial ordering, priority-like, of the actions. Once
3331 you've decided that some action is appropriate, you'll never go
3332 back and decide something of a lower priority is better. The
3335 kc < clr sgl shl slr sn sr ss
3336 sgl < shl slr sn sr ss
3337 slr < err shl sn sr ss
3338 clr < err shl sn sr ss
3344 What I think this means is that we don't need a damned table
3345 here. If you just put the rows and columns in the right order,
3346 it'd look awfully regular. We could simply walk the bpstat list
3347 and choose the highest priority action we find, with a little
3348 logic to handle the 'err' cases. */
3350 /* step_resume entries: a step resume breakpoint overrides another
3351 breakpoint of signal handling (see comment in wait_for_inferior
3352 at where we set the step_resume breakpoint). */
3354 static const enum bpstat_what_main_action
3355 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3358 /* kc ss sn sgl slr clr sr shl
3361 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3363 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3365 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3367 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3369 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3371 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3373 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3375 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3377 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3379 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3392 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3393 struct bpstat_what retval
;
3395 retval
.call_dummy
= 0;
3396 for (; bs
!= NULL
; bs
= bs
->next
)
3398 enum class bs_class
= no_effect
;
3399 if (bs
->breakpoint_at
== NULL
)
3400 /* I suspect this can happen if it was a momentary breakpoint
3401 which has since been deleted. */
3403 if (bs
->breakpoint_at
->owner
== NULL
)
3404 bs_class
= bp_nostop
;
3406 switch (bs
->breakpoint_at
->owner
->type
)
3412 case bp_hardware_breakpoint
:
3418 bs_class
= bp_noisy
;
3420 bs_class
= bp_silent
;
3423 bs_class
= bp_nostop
;
3426 case bp_hardware_watchpoint
:
3427 case bp_read_watchpoint
:
3428 case bp_access_watchpoint
:
3432 bs_class
= wp_noisy
;
3434 bs_class
= wp_silent
;
3437 /* There was a watchpoint, but we're not stopping.
3438 This requires no further action. */
3439 bs_class
= no_effect
;
3442 bs_class
= long_jump
;
3444 case bp_longjmp_resume
:
3445 bs_class
= long_resume
;
3447 case bp_step_resume
:
3450 bs_class
= step_resume
;
3453 /* It is for the wrong frame. */
3454 bs_class
= bp_nostop
;
3456 case bp_watchpoint_scope
:
3457 bs_class
= bp_nostop
;
3459 case bp_shlib_event
:
3460 bs_class
= shlib_event
;
3462 case bp_thread_event
:
3463 case bp_overlay_event
:
3464 case bp_longjmp_master
:
3465 bs_class
= bp_nostop
;
3471 bs_class
= bp_noisy
;
3473 bs_class
= bp_silent
;
3476 /* There was a catchpoint, but we're not stopping.
3477 This requires no further action. */
3478 bs_class
= no_effect
;
3481 /* Make sure the action is stop (silent or noisy),
3482 so infrun.c pops the dummy frame. */
3483 bs_class
= bp_silent
;
3484 retval
.call_dummy
= 1;
3487 /* Tracepoint hits should not be reported back to GDB, and
3488 if one got through somehow, it should have been filtered
3490 internal_error (__FILE__
, __LINE__
,
3491 _("bpstat_what: bp_tracepoint encountered"));
3494 current_action
= table
[(int) bs_class
][(int) current_action
];
3496 retval
.main_action
= current_action
;
3500 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3501 without hardware support). This isn't related to a specific bpstat,
3502 just to things like whether watchpoints are set. */
3505 bpstat_should_step (void)
3507 struct breakpoint
*b
;
3509 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3516 static void print_breakpoint_location (struct breakpoint
*b
,
3517 struct bp_location
*loc
,
3519 struct ui_stream
*stb
)
3524 = find_pc_sect_function (loc
->address
, loc
->section
);
3527 ui_out_text (uiout
, "in ");
3528 ui_out_field_string (uiout
, "func",
3529 SYMBOL_PRINT_NAME (sym
));
3530 ui_out_wrap_hint (uiout
, wrap_indent
);
3531 ui_out_text (uiout
, " at ");
3533 ui_out_field_string (uiout
, "file", b
->source_file
);
3534 ui_out_text (uiout
, ":");
3536 if (ui_out_is_mi_like_p (uiout
))
3538 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3539 char *fullname
= symtab_to_fullname (sal
.symtab
);
3542 ui_out_field_string (uiout
, "fullname", fullname
);
3545 ui_out_field_int (uiout
, "line", b
->line_number
);
3549 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3553 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3554 ui_out_field_stream (uiout
, "at", stb
);
3558 /* Print B to gdb_stdout. */
3560 print_one_breakpoint_location (struct breakpoint
*b
,
3561 struct bp_location
*loc
,
3563 struct bp_location
**last_loc
,
3564 int print_address_bits
)
3566 struct command_line
*l
;
3568 struct ep_type_description
3573 static struct ep_type_description bptypes
[] =
3575 {bp_none
, "?deleted?"},
3576 {bp_breakpoint
, "breakpoint"},
3577 {bp_hardware_breakpoint
, "hw breakpoint"},
3578 {bp_until
, "until"},
3579 {bp_finish
, "finish"},
3580 {bp_watchpoint
, "watchpoint"},
3581 {bp_hardware_watchpoint
, "hw watchpoint"},
3582 {bp_read_watchpoint
, "read watchpoint"},
3583 {bp_access_watchpoint
, "acc watchpoint"},
3584 {bp_longjmp
, "longjmp"},
3585 {bp_longjmp_resume
, "longjmp resume"},
3586 {bp_step_resume
, "step resume"},
3587 {bp_watchpoint_scope
, "watchpoint scope"},
3588 {bp_call_dummy
, "call dummy"},
3589 {bp_shlib_event
, "shlib events"},
3590 {bp_thread_event
, "thread events"},
3591 {bp_overlay_event
, "overlay events"},
3592 {bp_longjmp_master
, "longjmp master"},
3593 {bp_catchpoint
, "catchpoint"},
3594 {bp_tracepoint
, "tracepoint"},
3597 static char bpenables
[] = "nynny";
3598 char wrap_indent
[80];
3599 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3600 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3601 struct cleanup
*bkpt_chain
;
3603 int header_of_multiple
= 0;
3604 int part_of_multiple
= (loc
!= NULL
);
3605 struct value_print_options opts
;
3607 get_user_print_options (&opts
);
3609 gdb_assert (!loc
|| loc_number
!= 0);
3610 /* See comment in print_one_breakpoint concerning
3611 treatment of breakpoints with single disabled
3615 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3616 header_of_multiple
= 1;
3621 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3625 if (part_of_multiple
)
3628 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3629 ui_out_field_string (uiout
, "number", formatted
);
3634 ui_out_field_int (uiout
, "number", b
->number
);
3639 if (part_of_multiple
)
3640 ui_out_field_skip (uiout
, "type");
3643 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3644 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3645 internal_error (__FILE__
, __LINE__
,
3646 _("bptypes table does not describe type #%d."),
3648 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3653 if (part_of_multiple
)
3654 ui_out_field_skip (uiout
, "disp");
3656 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3661 if (part_of_multiple
)
3662 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3664 ui_out_field_fmt (uiout
, "enabled", "%c",
3665 bpenables
[(int) b
->enable_state
]);
3666 ui_out_spaces (uiout
, 2);
3670 strcpy (wrap_indent
, " ");
3671 if (opts
.addressprint
)
3673 if (print_address_bits
<= 32)
3674 strcat (wrap_indent
, " ");
3676 strcat (wrap_indent
, " ");
3679 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3681 /* Although the print_one can possibly print
3682 all locations, calling it here is not likely
3683 to get any nice result. So, make sure there's
3684 just one location. */
3685 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3686 b
->ops
->print_one (b
, last_loc
);
3692 internal_error (__FILE__
, __LINE__
,
3693 _("print_one_breakpoint: bp_none encountered\n"));
3697 case bp_hardware_watchpoint
:
3698 case bp_read_watchpoint
:
3699 case bp_access_watchpoint
:
3700 /* Field 4, the address, is omitted (which makes the columns
3701 not line up too nicely with the headers, but the effect
3702 is relatively readable). */
3703 if (opts
.addressprint
)
3704 ui_out_field_skip (uiout
, "addr");
3706 ui_out_field_string (uiout
, "what", b
->exp_string
);
3710 case bp_hardware_breakpoint
:
3714 case bp_longjmp_resume
:
3715 case bp_step_resume
:
3716 case bp_watchpoint_scope
:
3718 case bp_shlib_event
:
3719 case bp_thread_event
:
3720 case bp_overlay_event
:
3721 case bp_longjmp_master
:
3723 if (opts
.addressprint
)
3726 if (header_of_multiple
)
3727 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3728 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3729 ui_out_field_string (uiout
, "addr", "<PENDING>");
3731 ui_out_field_core_addr (uiout
, "addr",
3732 loc
->gdbarch
, loc
->address
);
3735 if (!header_of_multiple
)
3736 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3742 if (!part_of_multiple
)
3744 if (b
->thread
!= -1)
3746 /* FIXME: This seems to be redundant and lost here; see the
3747 "stop only in" line a little further down. */
3748 ui_out_text (uiout
, " thread ");
3749 ui_out_field_int (uiout
, "thread", b
->thread
);
3751 else if (b
->task
!= 0)
3753 ui_out_text (uiout
, " task ");
3754 ui_out_field_int (uiout
, "task", b
->task
);
3758 ui_out_text (uiout
, "\n");
3760 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3763 ui_out_text (uiout
, "\tstop only in stack frame at ");
3764 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3766 ui_out_field_core_addr (uiout
, "frame",
3767 b
->gdbarch
, b
->frame_id
.stack_addr
);
3768 ui_out_text (uiout
, "\n");
3771 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3773 /* We do not print the condition for Ada exception catchpoints
3774 because the condition is an internal implementation detail
3775 that we do not want to expose to the user. */
3777 if (b
->type
== bp_tracepoint
)
3778 ui_out_text (uiout
, "\ttrace only if ");
3780 ui_out_text (uiout
, "\tstop only if ");
3781 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3782 ui_out_text (uiout
, "\n");
3785 if (!part_of_multiple
&& b
->thread
!= -1)
3787 /* FIXME should make an annotation for this */
3788 ui_out_text (uiout
, "\tstop only in thread ");
3789 ui_out_field_int (uiout
, "thread", b
->thread
);
3790 ui_out_text (uiout
, "\n");
3793 if (!part_of_multiple
&& b
->hit_count
)
3795 /* FIXME should make an annotation for this */
3796 if (ep_is_catchpoint (b
))
3797 ui_out_text (uiout
, "\tcatchpoint");
3799 ui_out_text (uiout
, "\tbreakpoint");
3800 ui_out_text (uiout
, " already hit ");
3801 ui_out_field_int (uiout
, "times", b
->hit_count
);
3802 if (b
->hit_count
== 1)
3803 ui_out_text (uiout
, " time\n");
3805 ui_out_text (uiout
, " times\n");
3808 /* Output the count also if it is zero, but only if this is
3809 mi. FIXME: Should have a better test for this. */
3810 if (ui_out_is_mi_like_p (uiout
))
3811 if (!part_of_multiple
&& b
->hit_count
== 0)
3812 ui_out_field_int (uiout
, "times", b
->hit_count
);
3814 if (!part_of_multiple
&& b
->ignore_count
)
3817 ui_out_text (uiout
, "\tignore next ");
3818 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3819 ui_out_text (uiout
, " hits\n");
3823 if (!part_of_multiple
&& l
)
3825 struct cleanup
*script_chain
;
3828 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3829 print_command_lines (uiout
, l
, 4);
3830 do_cleanups (script_chain
);
3833 if (!part_of_multiple
&& b
->pass_count
)
3835 annotate_field (10);
3836 ui_out_text (uiout
, "\tpass count ");
3837 ui_out_field_int (uiout
, "pass", b
->pass_count
);
3838 ui_out_text (uiout
, " \n");
3841 if (!part_of_multiple
&& b
->step_count
)
3843 annotate_field (11);
3844 ui_out_text (uiout
, "\tstep count ");
3845 ui_out_field_int (uiout
, "step", b
->step_count
);
3846 ui_out_text (uiout
, " \n");
3849 if (!part_of_multiple
&& b
->actions
)
3851 struct action_line
*action
;
3852 annotate_field (12);
3853 for (action
= b
->actions
; action
; action
= action
->next
)
3855 ui_out_text (uiout
, " A\t");
3856 ui_out_text (uiout
, action
->action
);
3857 ui_out_text (uiout
, "\n");
3861 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3864 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3865 else if (b
->exp_string
)
3866 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3869 do_cleanups (bkpt_chain
);
3870 do_cleanups (old_chain
);
3874 print_one_breakpoint (struct breakpoint
*b
,
3875 struct bp_location
**last_loc
, int print_address_bits
)
3877 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, print_address_bits
);
3879 /* If this breakpoint has custom print function,
3880 it's already printed. Otherwise, print individual
3881 locations, if any. */
3882 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3884 /* If breakpoint has a single location that is
3885 disabled, we print it as if it had
3886 several locations, since otherwise it's hard to
3887 represent "breakpoint enabled, location disabled"
3889 Note that while hardware watchpoints have
3890 several locations internally, that's no a property
3893 && !is_hardware_watchpoint (b
)
3894 && (b
->loc
->next
|| !b
->loc
->enabled
)
3895 && !ui_out_is_mi_like_p (uiout
))
3897 struct bp_location
*loc
;
3899 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3900 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
3901 print_address_bits
);
3907 breakpoint_address_bits (struct breakpoint
*b
)
3909 int print_address_bits
= 0;
3910 struct bp_location
*loc
;
3912 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3914 int addr_bit
= gdbarch_addr_bit (b
->gdbarch
);
3915 if (addr_bit
> print_address_bits
)
3916 print_address_bits
= addr_bit
;
3919 return print_address_bits
;
3922 struct captured_breakpoint_query_args
3928 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3930 struct captured_breakpoint_query_args
*args
= data
;
3931 struct breakpoint
*b
;
3932 struct bp_location
*dummy_loc
= NULL
;
3935 if (args
->bnum
== b
->number
)
3937 int print_address_bits
= breakpoint_address_bits (b
);
3938 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
);
3946 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3948 struct captured_breakpoint_query_args args
;
3950 /* For the moment we don't trust print_one_breakpoint() to not throw
3952 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3953 error_message
, RETURN_MASK_ALL
) < 0)
3959 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3960 catchpoints, et.al.). */
3963 user_settable_breakpoint (const struct breakpoint
*b
)
3965 return (b
->type
== bp_breakpoint
3966 || b
->type
== bp_catchpoint
3967 || b
->type
== bp_hardware_breakpoint
3968 || b
->type
== bp_tracepoint
3969 || b
->type
== bp_watchpoint
3970 || b
->type
== bp_read_watchpoint
3971 || b
->type
== bp_access_watchpoint
3972 || b
->type
== bp_hardware_watchpoint
);
3975 /* Print information on user settable breakpoint (watchpoint, etc)
3976 number BNUM. If BNUM is -1 print all user settable breakpoints.
3977 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3980 breakpoint_1 (int bnum
, int allflag
)
3982 struct breakpoint
*b
;
3983 struct bp_location
*last_loc
= NULL
;
3984 int nr_printable_breakpoints
;
3985 struct cleanup
*bkpttbl_chain
;
3986 struct value_print_options opts
;
3987 int print_address_bits
= 0;
3989 get_user_print_options (&opts
);
3991 /* Compute the number of rows in the table, as well as the
3992 size required for address fields. */
3993 nr_printable_breakpoints
= 0;
3996 || bnum
== b
->number
)
3998 if (allflag
|| user_settable_breakpoint (b
))
4000 int addr_bit
= breakpoint_address_bits (b
);
4001 if (addr_bit
> print_address_bits
)
4002 print_address_bits
= addr_bit
;
4004 nr_printable_breakpoints
++;
4008 if (opts
.addressprint
)
4010 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4014 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4017 if (nr_printable_breakpoints
> 0)
4018 annotate_breakpoints_headers ();
4019 if (nr_printable_breakpoints
> 0)
4021 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4022 if (nr_printable_breakpoints
> 0)
4024 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4025 if (nr_printable_breakpoints
> 0)
4027 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4028 if (nr_printable_breakpoints
> 0)
4030 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4031 if (opts
.addressprint
)
4033 if (nr_printable_breakpoints
> 0)
4035 if (print_address_bits
<= 32)
4036 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4038 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4040 if (nr_printable_breakpoints
> 0)
4042 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4043 ui_out_table_body (uiout
);
4044 if (nr_printable_breakpoints
> 0)
4045 annotate_breakpoints_table ();
4049 || bnum
== b
->number
)
4051 /* We only print out user settable breakpoints unless the
4053 if (allflag
|| user_settable_breakpoint (b
))
4054 print_one_breakpoint (b
, &last_loc
, print_address_bits
);
4057 do_cleanups (bkpttbl_chain
);
4059 if (nr_printable_breakpoints
== 0)
4062 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4064 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4069 if (last_loc
&& !server_command
)
4070 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4073 /* FIXME? Should this be moved up so that it is only called when
4074 there have been breakpoints? */
4075 annotate_breakpoints_table_end ();
4079 breakpoints_info (char *bnum_exp
, int from_tty
)
4084 bnum
= parse_and_eval_long (bnum_exp
);
4086 breakpoint_1 (bnum
, 0);
4090 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4095 bnum
= parse_and_eval_long (bnum_exp
);
4097 breakpoint_1 (bnum
, 1);
4101 breakpoint_has_pc (struct breakpoint
*b
,
4102 CORE_ADDR pc
, struct obj_section
*section
)
4104 struct bp_location
*bl
= b
->loc
;
4105 for (; bl
; bl
= bl
->next
)
4107 if (bl
->address
== pc
4108 && (!overlay_debugging
|| bl
->section
== section
))
4114 /* Print a message describing any breakpoints set at PC. */
4117 describe_other_breakpoints (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
4118 struct obj_section
*section
, int thread
)
4121 struct breakpoint
*b
;
4124 others
+= breakpoint_has_pc (b
, pc
, section
);
4128 printf_filtered (_("Note: breakpoint "));
4129 else /* if (others == ???) */
4130 printf_filtered (_("Note: breakpoints "));
4132 if (breakpoint_has_pc (b
, pc
, section
))
4135 printf_filtered ("%d", b
->number
);
4136 if (b
->thread
== -1 && thread
!= -1)
4137 printf_filtered (" (all threads)");
4138 else if (b
->thread
!= -1)
4139 printf_filtered (" (thread %d)", b
->thread
);
4140 printf_filtered ("%s%s ",
4141 ((b
->enable_state
== bp_disabled
4142 || b
->enable_state
== bp_call_disabled
)
4144 : b
->enable_state
== bp_permanent
4148 : ((others
== 1) ? " and" : ""));
4150 printf_filtered (_("also set at pc "));
4151 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4152 printf_filtered (".\n");
4156 /* Set the default place to put a breakpoint
4157 for the `break' command with no arguments. */
4160 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4163 default_breakpoint_valid
= valid
;
4164 default_breakpoint_address
= addr
;
4165 default_breakpoint_symtab
= symtab
;
4166 default_breakpoint_line
= line
;
4169 /* Return true iff it is meaningful to use the address member of
4170 BPT. For some breakpoint types, the address member is irrelevant
4171 and it makes no sense to attempt to compare it to other addresses
4172 (or use it for any other purpose either).
4174 More specifically, each of the following breakpoint types will always
4175 have a zero valued address and we don't want check_duplicates() to mark
4176 breakpoints of any of these types to be a duplicate of an actual
4177 breakpoint at address zero:
4180 bp_hardware_watchpoint
4182 bp_access_watchpoint
4186 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4188 enum bptype type
= bpt
->type
;
4190 return (type
!= bp_watchpoint
4191 && type
!= bp_hardware_watchpoint
4192 && type
!= bp_read_watchpoint
4193 && type
!= bp_access_watchpoint
4194 && type
!= bp_catchpoint
);
4197 /* Rescan breakpoints at the same address and section as BPT,
4198 marking the first one as "first" and any others as "duplicates".
4199 This is so that the bpt instruction is only inserted once.
4200 If we have a permanent breakpoint at the same place as BPT, make
4201 that one the official one, and the rest as duplicates. */
4204 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4206 struct bp_location
*b
;
4208 struct bp_location
*perm_bp
= 0;
4210 ALL_BP_LOCATIONS (b
)
4211 if (b
->owner
->enable_state
!= bp_disabled
4212 && b
->owner
->enable_state
!= bp_call_disabled
4214 && !b
->shlib_disabled
4215 && b
->address
== address
/* address / overlay match */
4216 && (!overlay_debugging
|| b
->section
== section
)
4217 && breakpoint_address_is_meaningful (b
->owner
))
4219 /* Have we found a permanent breakpoint? */
4220 if (b
->owner
->enable_state
== bp_permanent
)
4227 b
->duplicate
= count
> 1;
4230 /* If we found a permanent breakpoint at this address, go over the
4231 list again and declare all the other breakpoints there (except
4232 other permanent breakpoints) to be the duplicates. */
4235 perm_bp
->duplicate
= 0;
4237 /* Permanent breakpoint should always be inserted. */
4238 if (! perm_bp
->inserted
)
4239 internal_error (__FILE__
, __LINE__
,
4240 _("allegedly permanent breakpoint is not "
4241 "actually inserted"));
4243 ALL_BP_LOCATIONS (b
)
4246 if (b
->owner
->enable_state
!= bp_permanent
4247 && b
->owner
->enable_state
!= bp_disabled
4248 && b
->owner
->enable_state
!= bp_call_disabled
4249 && b
->enabled
&& !b
->shlib_disabled
4250 && b
->address
== address
/* address / overlay match */
4251 && (!overlay_debugging
|| b
->section
== section
)
4252 && breakpoint_address_is_meaningful (b
->owner
))
4255 internal_error (__FILE__
, __LINE__
,
4256 _("another breakpoint was inserted on top of "
4257 "a permanent breakpoint"));
4266 check_duplicates (struct breakpoint
*bpt
)
4268 struct bp_location
*bl
= bpt
->loc
;
4270 if (! breakpoint_address_is_meaningful (bpt
))
4273 for (; bl
; bl
= bl
->next
)
4274 check_duplicates_for (bl
->address
, bl
->section
);
4278 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4279 int bnum
, int have_bnum
)
4284 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4285 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4287 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4288 bnum
, astr1
, astr2
);
4290 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4293 /* Adjust a breakpoint's address to account for architectural constraints
4294 on breakpoint placement. Return the adjusted address. Note: Very
4295 few targets require this kind of adjustment. For most targets,
4296 this function is simply the identity function. */
4299 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4300 CORE_ADDR bpaddr
, enum bptype bptype
)
4302 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4304 /* Very few targets need any kind of breakpoint adjustment. */
4307 else if (bptype
== bp_watchpoint
4308 || bptype
== bp_hardware_watchpoint
4309 || bptype
== bp_read_watchpoint
4310 || bptype
== bp_access_watchpoint
4311 || bptype
== bp_catchpoint
)
4313 /* Watchpoints and the various bp_catch_* eventpoints should not
4314 have their addresses modified. */
4319 CORE_ADDR adjusted_bpaddr
;
4321 /* Some targets have architectural constraints on the placement
4322 of breakpoint instructions. Obtain the adjusted address. */
4323 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
4325 /* An adjusted breakpoint address can significantly alter
4326 a user's expectations. Print a warning if an adjustment
4328 if (adjusted_bpaddr
!= bpaddr
)
4329 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4331 return adjusted_bpaddr
;
4335 /* Allocate a struct bp_location. */
4337 static struct bp_location
*
4338 allocate_bp_location (struct breakpoint
*bpt
)
4340 struct bp_location
*loc
, *loc_p
;
4342 loc
= xmalloc (sizeof (struct bp_location
));
4343 memset (loc
, 0, sizeof (*loc
));
4347 loc
->shlib_disabled
= 0;
4357 case bp_longjmp_resume
:
4358 case bp_step_resume
:
4359 case bp_watchpoint_scope
:
4361 case bp_shlib_event
:
4362 case bp_thread_event
:
4363 case bp_overlay_event
:
4364 case bp_longjmp_master
:
4365 loc
->loc_type
= bp_loc_software_breakpoint
;
4367 case bp_hardware_breakpoint
:
4368 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4370 case bp_hardware_watchpoint
:
4371 case bp_read_watchpoint
:
4372 case bp_access_watchpoint
:
4373 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4377 loc
->loc_type
= bp_loc_other
;
4380 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4386 static void free_bp_location (struct bp_location
*loc
)
4391 if (loc
->function_name
)
4392 xfree (loc
->function_name
);
4397 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4398 that has type BPTYPE and has no locations as yet. */
4400 static struct breakpoint
*
4401 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
4404 struct breakpoint
*b
, *b1
;
4406 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4407 memset (b
, 0, sizeof (*b
));
4410 b
->gdbarch
= gdbarch
;
4411 b
->language
= current_language
->la_language
;
4412 b
->input_radix
= input_radix
;
4414 b
->enable_state
= bp_enabled
;
4417 b
->ignore_count
= 0;
4419 b
->frame_id
= null_frame_id
;
4420 b
->forked_inferior_pid
= null_ptid
;
4421 b
->exec_pathname
= NULL
;
4423 b
->condition_not_parsed
= 0;
4425 /* Add this breakpoint to the end of the chain
4426 so that a list of breakpoints will come out in order
4427 of increasing numbers. */
4429 b1
= breakpoint_chain
;
4431 breakpoint_chain
= b
;
4441 /* Initialize loc->function_name. */
4443 set_breakpoint_location_function (struct bp_location
*loc
)
4445 if (loc
->owner
->type
== bp_breakpoint
4446 || loc
->owner
->type
== bp_hardware_breakpoint
4447 || loc
->owner
->type
== bp_tracepoint
)
4449 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4451 if (loc
->function_name
)
4452 loc
->function_name
= xstrdup (loc
->function_name
);
4456 /* Attempt to determine architecture of location identified by SAL. */
4457 static struct gdbarch
*
4458 get_sal_arch (struct symtab_and_line sal
)
4461 return get_objfile_arch (sal
.section
->objfile
);
4463 return get_objfile_arch (sal
.symtab
->objfile
);
4468 /* set_raw_breakpoint is a low level routine for allocating and
4469 partially initializing a breakpoint of type BPTYPE. The newly
4470 created breakpoint's address, section, source file name, and line
4471 number are provided by SAL. The newly created and partially
4472 initialized breakpoint is added to the breakpoint chain and
4473 is also returned as the value of this function.
4475 It is expected that the caller will complete the initialization of
4476 the newly created breakpoint struct as well as output any status
4477 information regarding the creation of a new breakpoint. In
4478 particular, set_raw_breakpoint does NOT set the breakpoint
4479 number! Care should be taken to not allow an error to occur
4480 prior to completing the initialization of the breakpoint. If this
4481 should happen, a bogus breakpoint will be left on the chain. */
4483 static struct breakpoint
*
4484 set_raw_breakpoint (struct gdbarch
*gdbarch
,
4485 struct symtab_and_line sal
, enum bptype bptype
)
4487 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
4488 CORE_ADDR adjusted_address
;
4489 struct gdbarch
*loc_gdbarch
;
4491 loc_gdbarch
= get_sal_arch (sal
);
4493 loc_gdbarch
= b
->gdbarch
;
4495 /* Adjust the breakpoint's address prior to allocating a location.
4496 Once we call allocate_bp_location(), that mostly uninitialized
4497 location will be placed on the location chain. Adjustment of the
4498 breakpoint may cause target_read_memory() to be called and we do
4499 not want its scan of the location chain to find a breakpoint and
4500 location that's only been partially initialized. */
4501 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
4503 b
->loc
= allocate_bp_location (b
);
4504 b
->loc
->gdbarch
= loc_gdbarch
;
4505 b
->loc
->requested_address
= sal
.pc
;
4506 b
->loc
->address
= adjusted_address
;
4508 if (sal
.symtab
== NULL
)
4509 b
->source_file
= NULL
;
4511 b
->source_file
= xstrdup (sal
.symtab
->filename
);
4512 b
->loc
->section
= sal
.section
;
4513 b
->line_number
= sal
.line
;
4515 set_breakpoint_location_function (b
->loc
);
4517 breakpoints_changed ();
4523 /* Note that the breakpoint object B describes a permanent breakpoint
4524 instruction, hard-wired into the inferior's code. */
4526 make_breakpoint_permanent (struct breakpoint
*b
)
4528 struct bp_location
*bl
;
4529 b
->enable_state
= bp_permanent
;
4531 /* By definition, permanent breakpoints are already present in the code.
4532 Mark all locations as inserted. For now, make_breakpoint_permanent
4533 is called in just one place, so it's hard to say if it's reasonable
4534 to have permanent breakpoint with multiple locations or not,
4535 but it's easy to implmement. */
4536 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4540 /* Call this routine when stepping and nexting to enable a breakpoint
4541 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4542 set_longjmp_resume_breakpoint() to figure out where we are going. */
4545 set_longjmp_breakpoint (int thread
)
4547 struct breakpoint
*b
, *temp
;
4549 /* To avoid having to rescan all objfile symbols at every step,
4550 we maintain a list of continually-inserted but always disabled
4551 longjmp "master" breakpoints. Here, we simply create momentary
4552 clones of those and enable them for the requested thread. */
4553 ALL_BREAKPOINTS_SAFE (b
, temp
)
4554 if (b
->type
== bp_longjmp_master
)
4556 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
4557 clone
->type
= bp_longjmp
;
4558 clone
->thread
= thread
;
4562 /* Delete all longjmp breakpoints from THREAD. */
4564 delete_longjmp_breakpoint (int thread
)
4566 struct breakpoint
*b
, *temp
;
4568 ALL_BREAKPOINTS_SAFE (b
, temp
)
4569 if (b
->type
== bp_longjmp
)
4571 if (b
->thread
== thread
)
4572 delete_breakpoint (b
);
4577 enable_overlay_breakpoints (void)
4579 struct breakpoint
*b
;
4582 if (b
->type
== bp_overlay_event
)
4584 b
->enable_state
= bp_enabled
;
4585 update_global_location_list (1);
4586 overlay_events_enabled
= 1;
4591 disable_overlay_breakpoints (void)
4593 struct breakpoint
*b
;
4596 if (b
->type
== bp_overlay_event
)
4598 b
->enable_state
= bp_disabled
;
4599 update_global_location_list (0);
4600 overlay_events_enabled
= 0;
4605 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4607 struct breakpoint
*b
;
4609 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
4611 b
->enable_state
= bp_enabled
;
4612 /* addr_string has to be used or breakpoint_re_set will delete me. */
4614 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
4616 update_global_location_list_nothrow (1);
4622 remove_thread_event_breakpoints (void)
4624 struct breakpoint
*b
, *temp
;
4626 ALL_BREAKPOINTS_SAFE (b
, temp
)
4627 if (b
->type
== bp_thread_event
)
4628 delete_breakpoint (b
);
4631 struct captured_parse_breakpoint_args
4634 struct symtabs_and_lines
*sals_p
;
4635 char ***addr_string_p
;
4639 struct lang_and_radix
4647 remove_solib_event_breakpoints (void)
4649 struct breakpoint
*b
, *temp
;
4651 ALL_BREAKPOINTS_SAFE (b
, temp
)
4652 if (b
->type
== bp_shlib_event
)
4653 delete_breakpoint (b
);
4657 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4659 struct breakpoint
*b
;
4661 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
4662 update_global_location_list_nothrow (1);
4666 /* Disable any breakpoints that are on code in shared libraries. Only
4667 apply to enabled breakpoints, disabled ones can just stay disabled. */
4670 disable_breakpoints_in_shlibs (void)
4672 struct bp_location
*loc
;
4674 ALL_BP_LOCATIONS (loc
)
4676 struct breakpoint
*b
= loc
->owner
;
4677 /* We apply the check to all breakpoints, including disabled
4678 for those with loc->duplicate set. This is so that when breakpoint
4679 becomes enabled, or the duplicate is removed, gdb will try to insert
4680 all breakpoints. If we don't set shlib_disabled here, we'll try
4681 to insert those breakpoints and fail. */
4682 if (((b
->type
== bp_breakpoint
)
4683 || (b
->type
== bp_hardware_breakpoint
)
4684 || (b
->type
== bp_tracepoint
))
4685 && !loc
->shlib_disabled
4687 && PC_SOLIB (loc
->address
)
4689 && solib_name_from_address (loc
->address
)
4693 loc
->shlib_disabled
= 1;
4698 /* Disable any breakpoints that are in in an unloaded shared library. Only
4699 apply to enabled breakpoints, disabled ones can just stay disabled. */
4702 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4704 struct bp_location
*loc
;
4705 int disabled_shlib_breaks
= 0;
4707 /* SunOS a.out shared libraries are always mapped, so do not
4708 disable breakpoints; they will only be reported as unloaded
4709 through clear_solib when GDB discards its shared library
4710 list. See clear_solib for more information. */
4711 if (exec_bfd
!= NULL
4712 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4715 ALL_BP_LOCATIONS (loc
)
4717 struct breakpoint
*b
= loc
->owner
;
4718 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4719 || loc
->loc_type
== bp_loc_software_breakpoint
)
4720 && !loc
->shlib_disabled
4721 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4722 && solib_contains_address_p (solib
, loc
->address
))
4724 loc
->shlib_disabled
= 1;
4725 /* At this point, we cannot rely on remove_breakpoint
4726 succeeding so we must mark the breakpoint as not inserted
4727 to prevent future errors occurring in remove_breakpoints. */
4729 if (!disabled_shlib_breaks
)
4731 target_terminal_ours_for_output ();
4732 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4735 disabled_shlib_breaks
= 1;
4740 /* FORK & VFORK catchpoints. */
4742 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4745 insert_catch_fork (struct breakpoint
*b
)
4747 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4750 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4753 remove_catch_fork (struct breakpoint
*b
)
4755 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4758 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4762 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4764 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4767 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4769 static enum print_stop_action
4770 print_it_catch_fork (struct breakpoint
*b
)
4772 annotate_catchpoint (b
->number
);
4773 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4774 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4775 return PRINT_SRC_AND_LOC
;
4778 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4781 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4783 struct value_print_options opts
;
4785 get_user_print_options (&opts
);
4787 /* Field 4, the address, is omitted (which makes the columns
4788 not line up too nicely with the headers, but the effect
4789 is relatively readable). */
4790 if (opts
.addressprint
)
4791 ui_out_field_skip (uiout
, "addr");
4793 ui_out_text (uiout
, "fork");
4794 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4796 ui_out_text (uiout
, ", process ");
4797 ui_out_field_int (uiout
, "what",
4798 ptid_get_pid (b
->forked_inferior_pid
));
4799 ui_out_spaces (uiout
, 1);
4803 /* Implement the "print_mention" breakpoint_ops method for fork
4807 print_mention_catch_fork (struct breakpoint
*b
)
4809 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4812 /* The breakpoint_ops structure to be used in fork catchpoints. */
4814 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4818 breakpoint_hit_catch_fork
,
4819 print_it_catch_fork
,
4820 print_one_catch_fork
,
4821 print_mention_catch_fork
4824 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4827 insert_catch_vfork (struct breakpoint
*b
)
4829 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4832 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4835 remove_catch_vfork (struct breakpoint
*b
)
4837 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4840 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4844 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4846 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4849 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4851 static enum print_stop_action
4852 print_it_catch_vfork (struct breakpoint
*b
)
4854 annotate_catchpoint (b
->number
);
4855 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4856 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4857 return PRINT_SRC_AND_LOC
;
4860 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4863 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4865 struct value_print_options opts
;
4867 get_user_print_options (&opts
);
4868 /* Field 4, the address, is omitted (which makes the columns
4869 not line up too nicely with the headers, but the effect
4870 is relatively readable). */
4871 if (opts
.addressprint
)
4872 ui_out_field_skip (uiout
, "addr");
4874 ui_out_text (uiout
, "vfork");
4875 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4877 ui_out_text (uiout
, ", process ");
4878 ui_out_field_int (uiout
, "what",
4879 ptid_get_pid (b
->forked_inferior_pid
));
4880 ui_out_spaces (uiout
, 1);
4884 /* Implement the "print_mention" breakpoint_ops method for vfork
4888 print_mention_catch_vfork (struct breakpoint
*b
)
4890 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4893 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4895 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4899 breakpoint_hit_catch_vfork
,
4900 print_it_catch_vfork
,
4901 print_one_catch_vfork
,
4902 print_mention_catch_vfork
4905 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4907 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4908 If COND_STRING is not NULL, then store it in the breakpoint.
4909 OPS, if not NULL, is the breakpoint_ops structure associated
4910 to the catchpoint. */
4912 static struct breakpoint
*
4913 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
4914 char *cond_string
, struct breakpoint_ops
*ops
)
4916 struct symtab_and_line sal
;
4917 struct breakpoint
*b
;
4924 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
4925 set_breakpoint_count (breakpoint_count
+ 1);
4926 b
->number
= breakpoint_count
;
4928 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
4930 b
->addr_string
= NULL
;
4931 b
->enable_state
= bp_enabled
;
4932 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4936 update_global_location_list (1);
4942 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
4943 int tempflag
, char *cond_string
,
4944 struct breakpoint_ops
*ops
)
4946 struct breakpoint
*b
4947 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
4949 /* FIXME: We should put this information in a breakpoint private data
4951 b
->forked_inferior_pid
= null_ptid
;
4954 /* Exec catchpoints. */
4957 insert_catch_exec (struct breakpoint
*b
)
4959 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4963 remove_catch_exec (struct breakpoint
*b
)
4965 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4969 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4971 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4974 static enum print_stop_action
4975 print_it_catch_exec (struct breakpoint
*b
)
4977 annotate_catchpoint (b
->number
);
4978 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4980 return PRINT_SRC_AND_LOC
;
4984 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
4986 struct value_print_options opts
;
4988 get_user_print_options (&opts
);
4990 /* Field 4, the address, is omitted (which makes the columns
4991 not line up too nicely with the headers, but the effect
4992 is relatively readable). */
4993 if (opts
.addressprint
)
4994 ui_out_field_skip (uiout
, "addr");
4996 ui_out_text (uiout
, "exec");
4997 if (b
->exec_pathname
!= NULL
)
4999 ui_out_text (uiout
, ", program \"");
5000 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
5001 ui_out_text (uiout
, "\" ");
5006 print_mention_catch_exec (struct breakpoint
*b
)
5008 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
5011 static struct breakpoint_ops catch_exec_breakpoint_ops
=
5015 breakpoint_hit_catch_exec
,
5016 print_it_catch_exec
,
5017 print_one_catch_exec
,
5018 print_mention_catch_exec
5022 hw_breakpoint_used_count (void)
5024 struct breakpoint
*b
;
5029 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
5037 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
5039 struct breakpoint
*b
;
5042 *other_type_used
= 0;
5045 if (breakpoint_enabled (b
))
5047 if (b
->type
== type
)
5049 else if ((b
->type
== bp_hardware_watchpoint
5050 || b
->type
== bp_read_watchpoint
5051 || b
->type
== bp_access_watchpoint
))
5052 *other_type_used
= 1;
5059 disable_watchpoints_before_interactive_call_start (void)
5061 struct breakpoint
*b
;
5065 if (((b
->type
== bp_watchpoint
)
5066 || (b
->type
== bp_hardware_watchpoint
)
5067 || (b
->type
== bp_read_watchpoint
)
5068 || (b
->type
== bp_access_watchpoint
))
5069 && breakpoint_enabled (b
))
5071 b
->enable_state
= bp_call_disabled
;
5072 update_global_location_list (0);
5078 enable_watchpoints_after_interactive_call_stop (void)
5080 struct breakpoint
*b
;
5084 if (((b
->type
== bp_watchpoint
)
5085 || (b
->type
== bp_hardware_watchpoint
)
5086 || (b
->type
== bp_read_watchpoint
)
5087 || (b
->type
== bp_access_watchpoint
))
5088 && (b
->enable_state
== bp_call_disabled
))
5090 b
->enable_state
= bp_enabled
;
5091 update_global_location_list (1);
5097 /* Set a breakpoint that will evaporate an end of command
5098 at address specified by SAL.
5099 Restrict it to frame FRAME if FRAME is nonzero. */
5102 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
5103 struct frame_id frame_id
, enum bptype type
)
5105 struct breakpoint
*b
;
5107 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5109 gdb_assert (!frame_id_inlined_p (frame_id
));
5111 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5112 b
->enable_state
= bp_enabled
;
5113 b
->disposition
= disp_donttouch
;
5114 b
->frame_id
= frame_id
;
5116 /* If we're debugging a multi-threaded program, then we
5117 want momentary breakpoints to be active in only a
5118 single thread of control. */
5119 if (in_thread_list (inferior_ptid
))
5120 b
->thread
= pid_to_thread_id (inferior_ptid
);
5122 update_global_location_list_nothrow (1);
5127 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5131 clone_momentary_breakpoint (struct breakpoint
*orig
)
5133 struct breakpoint
*copy
;
5135 /* If there's nothing to clone, then return nothing. */
5139 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
5140 copy
->loc
= allocate_bp_location (copy
);
5141 set_breakpoint_location_function (copy
->loc
);
5143 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
5144 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
5145 copy
->loc
->address
= orig
->loc
->address
;
5146 copy
->loc
->section
= orig
->loc
->section
;
5148 if (orig
->source_file
== NULL
)
5149 copy
->source_file
= NULL
;
5151 copy
->source_file
= xstrdup (orig
->source_file
);
5153 copy
->line_number
= orig
->line_number
;
5154 copy
->frame_id
= orig
->frame_id
;
5155 copy
->thread
= orig
->thread
;
5157 copy
->enable_state
= bp_enabled
;
5158 copy
->disposition
= disp_donttouch
;
5159 copy
->number
= internal_breakpoint_number
--;
5161 update_global_location_list_nothrow (0);
5166 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
5169 struct symtab_and_line sal
;
5171 sal
= find_pc_line (pc
, 0);
5173 sal
.section
= find_pc_overlay (pc
);
5174 sal
.explicit_pc
= 1;
5176 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
5180 /* Tell the user we have just set a breakpoint B. */
5183 mention (struct breakpoint
*b
)
5186 struct cleanup
*ui_out_chain
;
5187 struct value_print_options opts
;
5189 get_user_print_options (&opts
);
5191 /* FIXME: This is misplaced; mention() is called by things (like
5192 hitting a watchpoint) other than breakpoint creation. It should
5193 be possible to clean this up and at the same time replace the
5194 random calls to breakpoint_changed with this hook. */
5195 observer_notify_breakpoint_created (b
->number
);
5197 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5198 b
->ops
->print_mention (b
);
5203 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5206 ui_out_text (uiout
, "Watchpoint ");
5207 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5208 ui_out_field_int (uiout
, "number", b
->number
);
5209 ui_out_text (uiout
, ": ");
5210 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5211 do_cleanups (ui_out_chain
);
5213 case bp_hardware_watchpoint
:
5214 ui_out_text (uiout
, "Hardware watchpoint ");
5215 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5216 ui_out_field_int (uiout
, "number", b
->number
);
5217 ui_out_text (uiout
, ": ");
5218 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5219 do_cleanups (ui_out_chain
);
5221 case bp_read_watchpoint
:
5222 ui_out_text (uiout
, "Hardware read watchpoint ");
5223 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5224 ui_out_field_int (uiout
, "number", b
->number
);
5225 ui_out_text (uiout
, ": ");
5226 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5227 do_cleanups (ui_out_chain
);
5229 case bp_access_watchpoint
:
5230 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5231 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5232 ui_out_field_int (uiout
, "number", b
->number
);
5233 ui_out_text (uiout
, ": ");
5234 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5235 do_cleanups (ui_out_chain
);
5238 if (ui_out_is_mi_like_p (uiout
))
5243 if (b
->disposition
== disp_del
)
5244 printf_filtered (_("Temporary breakpoint"));
5246 printf_filtered (_("Breakpoint"));
5247 printf_filtered (_(" %d"), b
->number
);
5250 case bp_hardware_breakpoint
:
5251 if (ui_out_is_mi_like_p (uiout
))
5256 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5260 if (ui_out_is_mi_like_p (uiout
))
5265 printf_filtered (_("Tracepoint"));
5266 printf_filtered (_(" %d"), b
->number
);
5273 case bp_longjmp_resume
:
5274 case bp_step_resume
:
5276 case bp_watchpoint_scope
:
5277 case bp_shlib_event
:
5278 case bp_thread_event
:
5279 case bp_overlay_event
:
5280 case bp_longjmp_master
:
5286 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5290 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5294 if (opts
.addressprint
|| b
->source_file
== NULL
)
5296 printf_filtered (" at ");
5297 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
5301 printf_filtered (": file %s, line %d.",
5302 b
->source_file
, b
->line_number
);
5306 struct bp_location
*loc
= b
->loc
;
5308 for (; loc
; loc
= loc
->next
)
5310 printf_filtered (" (%d locations)", n
);
5315 if (ui_out_is_mi_like_p (uiout
))
5317 printf_filtered ("\n");
5321 static struct bp_location
*
5322 add_location_to_breakpoint (struct breakpoint
*b
,
5323 const struct symtab_and_line
*sal
)
5325 struct bp_location
*loc
, **tmp
;
5327 loc
= allocate_bp_location (b
);
5328 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5331 loc
->gdbarch
= get_sal_arch (*sal
);
5333 loc
->gdbarch
= b
->gdbarch
;
5334 loc
->requested_address
= sal
->pc
;
5335 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5336 loc
->requested_address
, b
->type
);
5337 loc
->section
= sal
->section
;
5339 set_breakpoint_location_function (loc
);
5344 /* Return 1 if LOC is pointing to a permanent breakpoint,
5345 return 0 otherwise. */
5348 bp_loc_is_permanent (struct bp_location
*loc
)
5352 const gdb_byte
*brk
;
5353 gdb_byte
*target_mem
;
5354 struct cleanup
*cleanup
;
5357 gdb_assert (loc
!= NULL
);
5359 addr
= loc
->address
;
5360 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
5362 /* Software breakpoints unsupported? */
5366 target_mem
= alloca (len
);
5368 /* Enable the automatic memory restoration from breakpoints while
5369 we read the memory. Otherwise we could say about our temporary
5370 breakpoints they are permanent. */
5371 cleanup
= make_show_memory_breakpoints_cleanup (0);
5373 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5374 && memcmp (target_mem
, brk
, len
) == 0)
5377 do_cleanups (cleanup
);
5384 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5385 as textual description of the location, and COND_STRING
5386 as condition expression. */
5389 create_breakpoint (struct gdbarch
*gdbarch
,
5390 struct symtabs_and_lines sals
, char *addr_string
,
5392 enum bptype type
, enum bpdisp disposition
,
5393 int thread
, int task
, int ignore_count
,
5394 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5396 struct breakpoint
*b
= NULL
;
5399 if (type
== bp_hardware_breakpoint
)
5401 int i
= hw_breakpoint_used_count ();
5402 int target_resources_ok
=
5403 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
5405 if (target_resources_ok
== 0)
5406 error (_("No hardware breakpoint support in the target."));
5407 else if (target_resources_ok
< 0)
5408 error (_("Hardware breakpoints used exceeds limit."));
5411 for (i
= 0; i
< sals
.nelts
; ++i
)
5413 struct symtab_and_line sal
= sals
.sals
[i
];
5414 struct bp_location
*loc
;
5418 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
5420 loc_gdbarch
= gdbarch
;
5422 describe_other_breakpoints (loc_gdbarch
,
5423 sal
.pc
, sal
.section
, thread
);
5428 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5429 set_breakpoint_count (breakpoint_count
+ 1);
5430 b
->number
= breakpoint_count
;
5434 b
->cond_string
= cond_string
;
5435 b
->ignore_count
= ignore_count
;
5436 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5437 b
->disposition
= disposition
;
5443 loc
= add_location_to_breakpoint (b
, &sal
);
5446 if (bp_loc_is_permanent (loc
))
5447 make_breakpoint_permanent (b
);
5451 char *arg
= b
->cond_string
;
5452 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5454 error (_("Garbage %s follows condition"), arg
);
5459 b
->addr_string
= addr_string
;
5461 /* addr_string has to be used or breakpoint_re_set will delete
5464 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5470 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5471 elements to fill the void space. */
5473 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5475 int i
= index_to_remove
+1;
5476 int last_index
= sal
->nelts
-1;
5478 for (;i
<= last_index
; ++i
)
5479 sal
->sals
[i
-1] = sal
->sals
[i
];
5484 /* If appropriate, obtains all sals that correspond
5485 to the same file and line as SAL. This is done
5486 only if SAL does not have explicit PC and has
5487 line and file information. If we got just a single
5488 expanded sal, return the original.
5490 Otherwise, if SAL.explicit_line is not set, filter out
5491 all sals for which the name of enclosing function
5492 is different from SAL. This makes sure that if we have
5493 breakpoint originally set in template instantiation, say
5494 foo<int>(), we won't expand SAL to locations at the same
5495 line in all existing instantiations of 'foo'.
5498 static struct symtabs_and_lines
5499 expand_line_sal_maybe (struct symtab_and_line sal
)
5501 struct symtabs_and_lines expanded
;
5502 CORE_ADDR original_pc
= sal
.pc
;
5503 char *original_function
= NULL
;
5507 /* If we have explicit pc, don't expand.
5508 If we have no line number, we can't expand. */
5509 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5512 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5513 expanded
.sals
[0] = sal
;
5518 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5520 expanded
= expand_line_sal (sal
);
5521 if (expanded
.nelts
== 1)
5523 /* We had one sal, we got one sal. Without futher
5524 processing, just return the original sal. */
5525 xfree (expanded
.sals
);
5527 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5528 sal
.pc
= original_pc
;
5529 expanded
.sals
[0] = sal
;
5533 if (!sal
.explicit_line
)
5535 CORE_ADDR func_addr
, func_end
;
5536 for (i
= 0; i
< expanded
.nelts
; ++i
)
5538 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5539 char *this_function
;
5540 if (find_pc_partial_function (pc
, &this_function
,
5541 &func_addr
, &func_end
))
5544 && strcmp (this_function
, original_function
) != 0)
5546 remove_sal (&expanded
, i
);
5549 else if (func_addr
== pc
)
5551 /* We're at beginning of a function, and should
5553 struct symbol
*sym
= find_pc_function (pc
);
5555 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5558 /* Since find_pc_partial_function returned true,
5559 we should really always find the section here. */
5560 struct obj_section
*section
= find_pc_section (pc
);
5563 struct gdbarch
*gdbarch
5564 = get_objfile_arch (section
->objfile
);
5566 = gdbarch_skip_prologue (gdbarch
, pc
);
5575 for (i
= 0; i
< expanded
.nelts
; ++i
)
5577 /* If this SAL corresponds to a breakpoint inserted using a
5578 line number, then skip the function prologue if necessary. */
5579 skip_prologue_sal (&expanded
.sals
[i
]);
5584 if (expanded
.nelts
<= 1)
5586 /* This is un ugly workaround. If we get zero
5587 expanded sals then something is really wrong.
5588 Fix that by returnign the original sal. */
5589 xfree (expanded
.sals
);
5591 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5592 sal
.pc
= original_pc
;
5593 expanded
.sals
[0] = sal
;
5600 for (i
= 0; i
< expanded
.nelts
; ++i
)
5601 if (expanded
.sals
[i
].pc
== original_pc
)
5612 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5613 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5614 value. COND_STRING, if not NULL, specified the condition to be
5615 used for all breakpoints. Essentially the only case where
5616 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5617 function. In that case, it's still not possible to specify
5618 separate conditions for different overloaded functions, so
5619 we take just a single condition string.
5621 NOTE: If the function succeeds, the caller is expected to cleanup
5622 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5623 array contents). If the function fails (error() is called), the
5624 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5625 COND and SALS arrays and each of those arrays contents. */
5628 create_breakpoints (struct gdbarch
*gdbarch
,
5629 struct symtabs_and_lines sals
, char **addr_string
,
5631 enum bptype type
, enum bpdisp disposition
,
5632 int thread
, int task
, int ignore_count
,
5633 struct breakpoint_ops
*ops
, int from_tty
,
5637 for (i
= 0; i
< sals
.nelts
; ++i
)
5639 struct symtabs_and_lines expanded
=
5640 expand_line_sal_maybe (sals
.sals
[i
]);
5642 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
5643 cond_string
, type
, disposition
,
5644 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5648 /* Parse ARG which is assumed to be a SAL specification possibly
5649 followed by conditionals. On return, SALS contains an array of SAL
5650 addresses found. ADDR_STRING contains a vector of (canonical)
5651 address strings. ARG points to the end of the SAL. */
5654 parse_breakpoint_sals (char **address
,
5655 struct symtabs_and_lines
*sals
,
5656 char ***addr_string
,
5659 char *addr_start
= *address
;
5660 *addr_string
= NULL
;
5661 /* If no arg given, or if first arg is 'if ', use the default
5663 if ((*address
) == NULL
5664 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5666 if (default_breakpoint_valid
)
5668 struct symtab_and_line sal
;
5669 init_sal (&sal
); /* initialize to zeroes */
5670 sals
->sals
= (struct symtab_and_line
*)
5671 xmalloc (sizeof (struct symtab_and_line
));
5672 sal
.pc
= default_breakpoint_address
;
5673 sal
.line
= default_breakpoint_line
;
5674 sal
.symtab
= default_breakpoint_symtab
;
5675 sal
.section
= find_pc_overlay (sal
.pc
);
5677 /* "break" without arguments is equivalent to "break *PC" where PC is
5678 the default_breakpoint_address. So make sure to set
5679 sal.explicit_pc to prevent GDB from trying to expand the list of
5680 sals to include all other instances with the same symtab and line.
5682 sal
.explicit_pc
= 1;
5684 sals
->sals
[0] = sal
;
5688 error (_("No default breakpoint address now."));
5692 /* Force almost all breakpoints to be in terms of the
5693 current_source_symtab (which is decode_line_1's default). This
5694 should produce the results we want almost all of the time while
5695 leaving default_breakpoint_* alone.
5696 ObjC: However, don't match an Objective-C method name which
5697 may have a '+' or '-' succeeded by a '[' */
5699 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5701 if (default_breakpoint_valid
5703 || ((strchr ("+-", (*address
)[0]) != NULL
)
5704 && ((*address
)[1] != '['))))
5705 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5706 default_breakpoint_line
, addr_string
,
5709 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5710 addr_string
, not_found_ptr
);
5712 /* For any SAL that didn't have a canonical string, fill one in. */
5713 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5714 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5715 if (addr_start
!= (*address
))
5718 for (i
= 0; i
< sals
->nelts
; i
++)
5720 /* Add the string if not present. */
5721 if ((*addr_string
)[i
] == NULL
)
5722 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5728 /* Convert each SAL into a real PC. Verify that the PC can be
5729 inserted as a breakpoint. If it can't throw an error. */
5732 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5736 for (i
= 0; i
< sals
->nelts
; i
++)
5737 resolve_sal_pc (&sals
->sals
[i
]);
5741 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5743 struct captured_parse_breakpoint_args
*args
= data
;
5745 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5746 args
->not_found_ptr
);
5749 /* Given TOK, a string specification of condition and thread, as
5750 accepted by the 'break' command, extract the condition
5751 string and thread number and set *COND_STRING and *THREAD.
5752 PC identifies the context at which the condition should be parsed.
5753 If no condition is found, *COND_STRING is set to NULL.
5754 If no thread is found, *THREAD is set to -1. */
5756 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5757 char **cond_string
, int *thread
, int *task
)
5759 *cond_string
= NULL
;
5765 char *cond_start
= NULL
;
5766 char *cond_end
= NULL
;
5767 while (*tok
== ' ' || *tok
== '\t')
5772 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5775 toklen
= end_tok
- tok
;
5777 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5779 struct expression
*expr
;
5781 tok
= cond_start
= end_tok
+ 1;
5782 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5785 *cond_string
= savestring (cond_start
,
5786 cond_end
- cond_start
);
5788 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5794 *thread
= strtol (tok
, &tok
, 0);
5796 error (_("Junk after thread keyword."));
5797 if (!valid_thread_id (*thread
))
5798 error (_("Unknown thread %d."), *thread
);
5800 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
5806 *task
= strtol (tok
, &tok
, 0);
5808 error (_("Junk after task keyword."));
5809 if (!valid_task_id (*task
))
5810 error (_("Unknown task %d\n"), *task
);
5813 error (_("Junk at end of arguments."));
5817 /* Set a breakpoint. This function is shared between
5818 CLI and MI functions for setting a breakpoint.
5819 This function has two major modes of operations,
5820 selected by the PARSE_CONDITION_AND_THREAD parameter.
5821 If non-zero, the function will parse arg, extracting
5822 breakpoint location, address and thread. Otherwise,
5823 ARG is just the location of breakpoint, with condition
5824 and thread specified by the COND_STRING and THREAD
5828 break_command_really (struct gdbarch
*gdbarch
,
5829 char *arg
, char *cond_string
, int thread
,
5830 int parse_condition_and_thread
,
5831 int tempflag
, int hardwareflag
, int traceflag
,
5833 enum auto_boolean pending_break_support
,
5834 struct breakpoint_ops
*ops
,
5838 struct gdb_exception e
;
5839 struct symtabs_and_lines sals
;
5840 struct symtab_and_line pending_sal
;
5843 char *addr_start
= arg
;
5845 struct cleanup
*old_chain
;
5846 struct cleanup
*bkpt_chain
= NULL
;
5847 struct captured_parse_breakpoint_args parse_args
;
5851 enum bptype type_wanted
;
5858 parse_args
.arg_p
= &arg
;
5859 parse_args
.sals_p
= &sals
;
5860 parse_args
.addr_string_p
= &addr_string
;
5861 parse_args
.not_found_ptr
= ¬_found
;
5863 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5864 &parse_args
, RETURN_MASK_ALL
);
5866 /* If caller is interested in rc value from parse, set value. */
5870 throw_exception (e
);
5874 case NOT_FOUND_ERROR
:
5876 /* If pending breakpoint support is turned off, throw
5879 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5880 throw_exception (e
);
5882 exception_print (gdb_stderr
, e
);
5884 /* If pending breakpoint support is auto query and the user
5885 selects no, then simply return the error code. */
5886 if (pending_break_support
== AUTO_BOOLEAN_AUTO
5887 && !nquery ("Make breakpoint pending on future shared library load? "))
5890 /* At this point, either the user was queried about setting
5891 a pending breakpoint and selected yes, or pending
5892 breakpoint behavior is on and thus a pending breakpoint
5893 is defaulted on behalf of the user. */
5894 copy_arg
= xstrdup (addr_start
);
5895 addr_string
= ©_arg
;
5897 sals
.sals
= &pending_sal
;
5902 throw_exception (e
);
5909 /* Create a chain of things that always need to be cleaned up. */
5910 old_chain
= make_cleanup (null_cleanup
, 0);
5914 /* Make sure that all storage allocated to SALS gets freed. */
5915 make_cleanup (xfree
, sals
.sals
);
5917 /* Cleanup the addr_string array but not its contents. */
5918 make_cleanup (xfree
, addr_string
);
5921 /* ----------------------------- SNIP -----------------------------
5922 Anything added to the cleanup chain beyond this point is assumed
5923 to be part of a breakpoint. If the breakpoint create succeeds
5924 then the memory is not reclaimed. */
5925 bkpt_chain
= make_cleanup (null_cleanup
, 0);
5927 /* Mark the contents of the addr_string for cleanup. These go on
5928 the bkpt_chain and only occur if the breakpoint create fails. */
5929 for (i
= 0; i
< sals
.nelts
; i
++)
5931 if (addr_string
[i
] != NULL
)
5932 make_cleanup (xfree
, addr_string
[i
]);
5935 /* Resolve all line numbers to PC's and verify that the addresses
5936 are ok for the target. */
5938 breakpoint_sals_to_pc (&sals
, addr_start
);
5940 type_wanted
= (traceflag
5942 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
5944 /* Verify that condition can be parsed, before setting any
5945 breakpoints. Allocate a separate condition expression for each
5949 if (parse_condition_and_thread
)
5951 /* Here we only parse 'arg' to separate condition
5952 from thread number, so parsing in context of first
5953 sal is OK. When setting the breakpoint we'll
5954 re-parse it in context of each sal. */
5957 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
5960 make_cleanup (xfree
, cond_string
);
5964 /* Create a private copy of condition string. */
5967 cond_string
= xstrdup (cond_string
);
5968 make_cleanup (xfree
, cond_string
);
5971 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
5972 tempflag
? disp_del
: disp_donttouch
,
5973 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5977 struct symtab_and_line sal
= {0};
5978 struct breakpoint
*b
;
5980 make_cleanup (xfree
, copy_arg
);
5982 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
5983 set_breakpoint_count (breakpoint_count
+ 1);
5984 b
->number
= breakpoint_count
;
5986 b
->addr_string
= addr_string
[0];
5987 b
->cond_string
= NULL
;
5988 b
->ignore_count
= ignore_count
;
5989 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5990 b
->condition_not_parsed
= 1;
5992 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5998 warning (_("Multiple breakpoints were set.\n"
5999 "Use the \"delete\" command to delete unwanted breakpoints."));
6000 /* That's it. Discard the cleanups for data inserted into the
6002 discard_cleanups (bkpt_chain
);
6003 /* But cleanup everything else. */
6004 do_cleanups (old_chain
);
6006 /* error call may happen here - have BKPT_CHAIN already discarded. */
6007 update_global_location_list (1);
6010 /* Set a breakpoint.
6011 ARG is a string describing breakpoint address,
6012 condition, and thread.
6013 FLAG specifies if a breakpoint is hardware on,
6014 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6018 break_command_1 (char *arg
, int flag
, int from_tty
)
6020 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
6021 int tempflag
= flag
& BP_TEMPFLAG
;
6023 break_command_really (get_current_arch (),
6025 NULL
, 0, 1 /* parse arg */,
6026 tempflag
, hardwareflag
, 0 /* traceflag */,
6027 0 /* Ignore count */,
6028 pending_break_support
,
6029 NULL
/* breakpoint_ops */,
6036 set_breakpoint (struct gdbarch
*gdbarch
,
6037 char *address
, char *condition
,
6038 int hardwareflag
, int tempflag
,
6039 int thread
, int ignore_count
,
6040 int pending
, int enabled
)
6042 break_command_really (gdbarch
,
6043 address
, condition
, thread
,
6044 0 /* condition and thread are valid. */,
6045 tempflag
, hardwareflag
, 0 /* traceflag */,
6048 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
6052 /* Adjust SAL to the first instruction past the function prologue.
6053 The end of the prologue is determined using the line table from
6054 the debugging information. explicit_pc and explicit_line are
6057 If SAL is already past the prologue, then do nothing. */
6060 skip_prologue_sal (struct symtab_and_line
*sal
)
6062 struct symbol
*sym
= find_pc_function (sal
->pc
);
6063 struct symtab_and_line start_sal
;
6068 start_sal
= find_function_start_sal (sym
, 1);
6069 if (sal
->pc
< start_sal
.pc
)
6071 start_sal
.explicit_line
= sal
->explicit_line
;
6072 start_sal
.explicit_pc
= sal
->explicit_pc
;
6077 /* Helper function for break_command_1 and disassemble_command. */
6080 resolve_sal_pc (struct symtab_and_line
*sal
)
6084 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
6086 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
6087 error (_("No line %d in file \"%s\"."),
6088 sal
->line
, sal
->symtab
->filename
);
6091 /* If this SAL corresponds to a breakpoint inserted using
6092 a line number, then skip the function prologue if necessary. */
6093 if (sal
->explicit_line
)
6095 /* Preserve the original line number. */
6096 int saved_line
= sal
->line
;
6097 skip_prologue_sal (sal
);
6098 sal
->line
= saved_line
;
6102 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
6104 struct blockvector
*bv
;
6108 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
6111 sym
= block_linkage_function (b
);
6114 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
6115 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
6119 /* It really is worthwhile to have the section, so we'll just
6120 have to look harder. This case can be executed if we have
6121 line numbers but no functions (as can happen in assembly
6124 struct minimal_symbol
*msym
;
6126 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
6128 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
6135 break_command (char *arg
, int from_tty
)
6137 break_command_1 (arg
, 0, from_tty
);
6141 tbreak_command (char *arg
, int from_tty
)
6143 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
6147 hbreak_command (char *arg
, int from_tty
)
6149 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
6153 thbreak_command (char *arg
, int from_tty
)
6155 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
6159 stop_command (char *arg
, int from_tty
)
6161 printf_filtered (_("Specify the type of breakpoint to set.\n\
6162 Usage: stop in <function | address>\n\
6163 stop at <line>\n"));
6167 stopin_command (char *arg
, int from_tty
)
6171 if (arg
== (char *) NULL
)
6173 else if (*arg
!= '*')
6178 /* look for a ':'. If this is a line number specification, then
6179 say it is bad, otherwise, it should be an address or
6180 function/method name */
6181 while (*argptr
&& !hasColon
)
6183 hasColon
= (*argptr
== ':');
6188 badInput
= (*argptr
!= ':'); /* Not a class::method */
6190 badInput
= isdigit (*arg
); /* a simple line number */
6194 printf_filtered (_("Usage: stop in <function | address>\n"));
6196 break_command_1 (arg
, 0, from_tty
);
6200 stopat_command (char *arg
, int from_tty
)
6204 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6211 /* look for a ':'. If there is a '::' then get out, otherwise
6212 it is probably a line number. */
6213 while (*argptr
&& !hasColon
)
6215 hasColon
= (*argptr
== ':');
6220 badInput
= (*argptr
== ':'); /* we have class::method */
6222 badInput
= !isdigit (*arg
); /* not a line number */
6226 printf_filtered (_("Usage: stop at <line>\n"));
6228 break_command_1 (arg
, 0, from_tty
);
6231 /* accessflag: hw_write: watch write,
6232 hw_read: watch read,
6233 hw_access: watch access (read or write) */
6235 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6237 struct gdbarch
*gdbarch
= get_current_arch ();
6238 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6239 struct symtab_and_line sal
;
6240 struct expression
*exp
;
6241 struct block
*exp_valid_block
;
6242 struct value
*val
, *mark
;
6243 struct frame_info
*frame
;
6244 char *exp_start
= NULL
;
6245 char *exp_end
= NULL
;
6246 char *tok
, *id_tok_start
, *end_tok
;
6248 char *cond_start
= NULL
;
6249 char *cond_end
= NULL
;
6250 struct expression
*cond
= NULL
;
6251 int i
, other_type_used
, target_resources_ok
= 0;
6252 enum bptype bp_type
;
6256 init_sal (&sal
); /* initialize to zeroes */
6258 /* Make sure that we actually have parameters to parse. */
6259 if (arg
!= NULL
&& arg
[0] != '\0')
6261 toklen
= strlen (arg
); /* Size of argument list. */
6263 /* Points tok to the end of the argument list. */
6264 tok
= arg
+ toklen
- 1;
6266 /* Go backwards in the parameters list. Skip the last parameter.
6267 If we're expecting a 'thread <thread_num>' parameter, this should
6268 be the thread identifier. */
6269 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6271 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6274 /* Points end_tok to the beginning of the last token. */
6275 id_tok_start
= tok
+ 1;
6277 /* Go backwards in the parameters list. Skip one more parameter.
6278 If we're expecting a 'thread <thread_num>' parameter, we should
6279 reach a "thread" token. */
6280 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6285 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6288 /* Move the pointer forward to skip the whitespace and
6289 calculate the length of the token. */
6291 toklen
= end_tok
- tok
;
6293 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6295 /* At this point we've found a "thread" token, which means
6296 the user is trying to set a watchpoint that triggers
6297 only in a specific thread. */
6300 /* Extract the thread ID from the next token. */
6301 thread
= strtol (id_tok_start
, &endp
, 0);
6303 /* Check if the user provided a valid numeric value for the
6305 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6306 error (_("Invalid thread ID specification %s."), id_tok_start
);
6308 /* Check if the thread actually exists. */
6309 if (!valid_thread_id (thread
))
6310 error (_("Unknown thread %d."), thread
);
6312 /* Truncate the string and get rid of the thread <thread_num>
6313 parameter before the parameter list is parsed by the
6314 evaluate_expression() function. */
6319 /* Parse the rest of the arguments. */
6320 innermost_block
= NULL
;
6322 exp
= parse_exp_1 (&arg
, 0, 0);
6324 /* Remove trailing whitespace from the expression before saving it.
6325 This makes the eventual display of the expression string a bit
6327 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
6330 exp_valid_block
= innermost_block
;
6331 mark
= value_mark ();
6332 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6334 release_value (val
);
6337 while (*tok
== ' ' || *tok
== '\t')
6341 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6344 toklen
= end_tok
- tok
;
6345 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6347 tok
= cond_start
= end_tok
+ 1;
6348 cond
= parse_exp_1 (&tok
, 0, 0);
6352 error (_("Junk at end of command."));
6354 if (accessflag
== hw_read
)
6355 bp_type
= bp_read_watchpoint
;
6356 else if (accessflag
== hw_access
)
6357 bp_type
= bp_access_watchpoint
;
6359 bp_type
= bp_hardware_watchpoint
;
6361 mem_cnt
= can_use_hardware_watchpoint (val
);
6362 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6363 error (_("Expression cannot be implemented with read/access watchpoint."));
6366 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6367 target_resources_ok
=
6368 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
6370 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6371 error (_("Target does not support this type of hardware watchpoint."));
6373 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6374 error (_("Target can only support one kind of HW watchpoint at a time."));
6377 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6378 watchpoint could not be set. */
6379 if (!mem_cnt
|| target_resources_ok
<= 0)
6380 bp_type
= bp_watchpoint
;
6382 frame
= block_innermost_frame (exp_valid_block
);
6384 /* If the expression is "local", then set up a "watchpoint scope"
6385 breakpoint at the point where we've left the scope of the watchpoint
6386 expression. Create the scope breakpoint before the watchpoint, so
6387 that we will encounter it first in bpstat_stop_status. */
6388 if (innermost_block
&& frame
)
6390 if (frame_id_p (frame_unwind_caller_id (frame
)))
6393 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
6394 frame_unwind_caller_pc (frame
),
6395 bp_watchpoint_scope
);
6397 scope_breakpoint
->enable_state
= bp_enabled
;
6399 /* Automatically delete the breakpoint when it hits. */
6400 scope_breakpoint
->disposition
= disp_del
;
6402 /* Only break in the proper frame (help with recursion). */
6403 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
6405 /* Set the address at which we will stop. */
6406 scope_breakpoint
->loc
->gdbarch
6407 = frame_unwind_caller_arch (frame
);
6408 scope_breakpoint
->loc
->requested_address
6409 = frame_unwind_caller_pc (frame
);
6410 scope_breakpoint
->loc
->address
6411 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
6412 scope_breakpoint
->loc
->requested_address
,
6413 scope_breakpoint
->type
);
6417 /* Now set up the breakpoint. */
6418 b
= set_raw_breakpoint (gdbarch
, sal
, bp_type
);
6419 set_breakpoint_count (breakpoint_count
+ 1);
6420 b
->number
= breakpoint_count
;
6422 b
->disposition
= disp_donttouch
;
6424 b
->exp_valid_block
= exp_valid_block
;
6425 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6428 b
->loc
->cond
= cond
;
6430 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6435 b
->watchpoint_frame
= get_frame_id (frame
);
6437 b
->watchpoint_frame
= null_frame_id
;
6439 if (scope_breakpoint
!= NULL
)
6441 /* The scope breakpoint is related to the watchpoint. We will
6442 need to act on them together. */
6443 b
->related_breakpoint
= scope_breakpoint
;
6444 scope_breakpoint
->related_breakpoint
= b
;
6447 value_free_to_mark (mark
);
6449 update_global_location_list (1);
6452 /* Return count of locations need to be watched and can be handled
6453 in hardware. If the watchpoint can not be handled
6454 in hardware return zero. */
6457 can_use_hardware_watchpoint (struct value
*v
)
6459 int found_memory_cnt
= 0;
6460 struct value
*head
= v
;
6462 /* Did the user specifically forbid us to use hardware watchpoints? */
6463 if (!can_use_hw_watchpoints
)
6466 /* Make sure that the value of the expression depends only upon
6467 memory contents, and values computed from them within GDB. If we
6468 find any register references or function calls, we can't use a
6469 hardware watchpoint.
6471 The idea here is that evaluating an expression generates a series
6472 of values, one holding the value of every subexpression. (The
6473 expression a*b+c has five subexpressions: a, b, a*b, c, and
6474 a*b+c.) GDB's values hold almost enough information to establish
6475 the criteria given above --- they identify memory lvalues,
6476 register lvalues, computed values, etcetera. So we can evaluate
6477 the expression, and then scan the chain of values that leaves
6478 behind to decide whether we can detect any possible change to the
6479 expression's final value using only hardware watchpoints.
6481 However, I don't think that the values returned by inferior
6482 function calls are special in any way. So this function may not
6483 notice that an expression involving an inferior function call
6484 can't be watched with hardware watchpoints. FIXME. */
6485 for (; v
; v
= value_next (v
))
6487 if (VALUE_LVAL (v
) == lval_memory
)
6490 /* A lazy memory lvalue is one that GDB never needed to fetch;
6491 we either just used its address (e.g., `a' in `a.b') or
6492 we never needed it at all (e.g., `a' in `a,b'). */
6496 /* Ahh, memory we actually used! Check if we can cover
6497 it with hardware watchpoints. */
6498 struct type
*vtype
= check_typedef (value_type (v
));
6500 /* We only watch structs and arrays if user asked for it
6501 explicitly, never if they just happen to appear in a
6502 middle of some value chain. */
6504 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6505 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6507 CORE_ADDR vaddr
= value_address (v
);
6508 int len
= TYPE_LENGTH (value_type (v
));
6510 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
6517 else if (VALUE_LVAL (v
) != not_lval
6518 && deprecated_value_modifiable (v
) == 0)
6519 return 0; /* ??? What does this represent? */
6520 else if (VALUE_LVAL (v
) == lval_register
)
6521 return 0; /* cannot watch a register with a HW watchpoint */
6524 /* The expression itself looks suitable for using a hardware
6525 watchpoint, but give the target machine a chance to reject it. */
6526 return found_memory_cnt
;
6530 watch_command_wrapper (char *arg
, int from_tty
)
6532 watch_command (arg
, from_tty
);
6536 watch_command (char *arg
, int from_tty
)
6538 watch_command_1 (arg
, hw_write
, from_tty
);
6542 rwatch_command_wrapper (char *arg
, int from_tty
)
6544 rwatch_command (arg
, from_tty
);
6548 rwatch_command (char *arg
, int from_tty
)
6550 watch_command_1 (arg
, hw_read
, from_tty
);
6554 awatch_command_wrapper (char *arg
, int from_tty
)
6556 awatch_command (arg
, from_tty
);
6560 awatch_command (char *arg
, int from_tty
)
6562 watch_command_1 (arg
, hw_access
, from_tty
);
6566 /* Helper routines for the until_command routine in infcmd.c. Here
6567 because it uses the mechanisms of breakpoints. */
6569 struct until_break_command_continuation_args
6571 struct breakpoint
*breakpoint
;
6572 struct breakpoint
*breakpoint2
;
6575 /* This function is called by fetch_inferior_event via the
6576 cmd_continuation pointer, to complete the until command. It takes
6577 care of cleaning up the temporary breakpoints set up by the until
6580 until_break_command_continuation (void *arg
)
6582 struct until_break_command_continuation_args
*a
= arg
;
6584 delete_breakpoint (a
->breakpoint
);
6586 delete_breakpoint (a
->breakpoint2
);
6590 until_break_command (char *arg
, int from_tty
, int anywhere
)
6592 struct symtabs_and_lines sals
;
6593 struct symtab_and_line sal
;
6594 struct frame_info
*frame
= get_selected_frame (NULL
);
6595 struct breakpoint
*breakpoint
;
6596 struct breakpoint
*breakpoint2
= NULL
;
6597 struct cleanup
*old_chain
;
6599 clear_proceed_status ();
6601 /* Set a breakpoint where the user wants it and at return from
6604 if (default_breakpoint_valid
)
6605 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6606 default_breakpoint_line
, (char ***) NULL
, NULL
);
6608 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6609 0, (char ***) NULL
, NULL
);
6611 if (sals
.nelts
!= 1)
6612 error (_("Couldn't get information on specified line."));
6615 xfree (sals
.sals
); /* malloc'd, so freed */
6618 error (_("Junk at end of arguments."));
6620 resolve_sal_pc (&sal
);
6623 /* If the user told us to continue until a specified location,
6624 we don't specify a frame at which we need to stop. */
6625 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6626 null_frame_id
, bp_until
);
6628 /* Otherwise, specify the selected frame, because we want to stop only
6629 at the very same frame. */
6630 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6631 get_stack_frame_id (frame
),
6634 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6636 /* Keep within the current frame, or in frames called by the current
6639 if (frame_id_p (frame_unwind_caller_id (frame
)))
6641 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
6642 sal
.pc
= frame_unwind_caller_pc (frame
);
6643 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
6645 frame_unwind_caller_id (frame
),
6647 make_cleanup_delete_breakpoint (breakpoint2
);
6650 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6652 /* If we are running asynchronously, and proceed call above has actually
6653 managed to start the target, arrange for breakpoints to be
6654 deleted when the target stops. Otherwise, we're already stopped and
6655 delete breakpoints via cleanup chain. */
6657 if (target_can_async_p () && is_running (inferior_ptid
))
6659 struct until_break_command_continuation_args
*args
;
6660 args
= xmalloc (sizeof (*args
));
6662 args
->breakpoint
= breakpoint
;
6663 args
->breakpoint2
= breakpoint2
;
6665 discard_cleanups (old_chain
);
6666 add_continuation (inferior_thread (),
6667 until_break_command_continuation
, args
,
6671 do_cleanups (old_chain
);
6675 ep_skip_leading_whitespace (char **s
)
6677 if ((s
== NULL
) || (*s
== NULL
))
6679 while (isspace (**s
))
6683 /* This function attempts to parse an optional "if <cond>" clause
6684 from the arg string. If one is not found, it returns NULL.
6686 Else, it returns a pointer to the condition string. (It does not
6687 attempt to evaluate the string against a particular block.) And,
6688 it updates arg to point to the first character following the parsed
6689 if clause in the arg string. */
6692 ep_parse_optional_if_clause (char **arg
)
6696 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6699 /* Skip the "if" keyword. */
6702 /* Skip any extra leading whitespace, and record the start of the
6703 condition string. */
6704 ep_skip_leading_whitespace (arg
);
6707 /* Assume that the condition occupies the remainder of the arg string. */
6708 (*arg
) += strlen (cond_string
);
6713 /* This function attempts to parse an optional filename from the arg
6714 string. If one is not found, it returns NULL.
6716 Else, it returns a pointer to the parsed filename. (This function
6717 makes no attempt to verify that a file of that name exists, or is
6718 accessible.) And, it updates arg to point to the first character
6719 following the parsed filename in the arg string.
6721 Note that clients needing to preserve the returned filename for
6722 future access should copy it to their own buffers. */
6724 ep_parse_optional_filename (char **arg
)
6726 static char filename
[1024];
6731 if ((*arg_p
== '\0') || isspace (*arg_p
))
6749 /* Commands to deal with catching events, such as signals, exceptions,
6750 process start/exit, etc. */
6754 catch_fork_temporary
, catch_vfork_temporary
,
6755 catch_fork_permanent
, catch_vfork_permanent
6760 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6762 struct gdbarch
*gdbarch
= get_current_arch ();
6763 char *cond_string
= NULL
;
6764 catch_fork_kind fork_kind
;
6767 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6768 tempflag
= (fork_kind
== catch_fork_temporary
6769 || fork_kind
== catch_vfork_temporary
);
6773 ep_skip_leading_whitespace (&arg
);
6775 /* The allowed syntax is:
6777 catch [v]fork if <cond>
6779 First, check if there's an if clause. */
6780 cond_string
= ep_parse_optional_if_clause (&arg
);
6782 if ((*arg
!= '\0') && !isspace (*arg
))
6783 error (_("Junk at end of arguments."));
6785 /* If this target supports it, create a fork or vfork catchpoint
6786 and enable reporting of such events. */
6789 case catch_fork_temporary
:
6790 case catch_fork_permanent
:
6791 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6792 &catch_fork_breakpoint_ops
);
6794 case catch_vfork_temporary
:
6795 case catch_vfork_permanent
:
6796 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6797 &catch_vfork_breakpoint_ops
);
6800 error (_("unsupported or unknown fork kind; cannot catch it"));
6806 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6808 struct gdbarch
*gdbarch
= get_current_arch ();
6810 char *cond_string
= NULL
;
6812 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6816 ep_skip_leading_whitespace (&arg
);
6818 /* The allowed syntax is:
6820 catch exec if <cond>
6822 First, check if there's an if clause. */
6823 cond_string
= ep_parse_optional_if_clause (&arg
);
6825 if ((*arg
!= '\0') && !isspace (*arg
))
6826 error (_("Junk at end of arguments."));
6828 /* If this target supports it, create an exec catchpoint
6829 and enable reporting of such events. */
6830 create_catchpoint (gdbarch
, tempflag
, cond_string
,
6831 &catch_exec_breakpoint_ops
);
6834 static enum print_stop_action
6835 print_exception_catchpoint (struct breakpoint
*b
)
6837 int bp_temp
, bp_throw
;
6839 annotate_catchpoint (b
->number
);
6841 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6842 if (b
->loc
->address
!= b
->loc
->requested_address
)
6843 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6846 bp_temp
= b
->disposition
== disp_del
;
6848 bp_temp
? "Temporary catchpoint "
6850 if (!ui_out_is_mi_like_p (uiout
))
6851 ui_out_field_int (uiout
, "bkptno", b
->number
);
6853 bp_throw
? " (exception thrown), "
6854 : " (exception caught), ");
6855 if (ui_out_is_mi_like_p (uiout
))
6857 ui_out_field_string (uiout
, "reason",
6858 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6859 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6860 ui_out_field_int (uiout
, "bkptno", b
->number
);
6862 return PRINT_SRC_AND_LOC
;
6866 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
6868 struct value_print_options opts
;
6869 get_user_print_options (&opts
);
6870 if (opts
.addressprint
)
6873 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6874 ui_out_field_string (uiout
, "addr", "<PENDING>");
6876 ui_out_field_core_addr (uiout
, "addr",
6877 b
->loc
->gdbarch
, b
->loc
->address
);
6882 if (strstr (b
->addr_string
, "throw") != NULL
)
6883 ui_out_field_string (uiout
, "what", "exception throw");
6885 ui_out_field_string (uiout
, "what", "exception catch");
6889 print_mention_exception_catchpoint (struct breakpoint
*b
)
6894 bp_temp
= b
->disposition
== disp_del
;
6895 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6896 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6897 : _("Catchpoint "));
6898 ui_out_field_int (uiout
, "bkptno", b
->number
);
6899 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6903 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6906 NULL
, /* breakpoint_hit */
6907 print_exception_catchpoint
,
6908 print_one_exception_catchpoint
,
6909 print_mention_exception_catchpoint
6913 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6914 enum exception_event_kind ex_event
, int from_tty
)
6916 char *trigger_func_name
;
6918 if (ex_event
== EX_EVENT_CATCH
)
6919 trigger_func_name
= "__cxa_begin_catch";
6921 trigger_func_name
= "__cxa_throw";
6923 break_command_really (get_current_arch (),
6924 trigger_func_name
, cond_string
, -1,
6925 0 /* condition and thread are valid. */,
6928 AUTO_BOOLEAN_TRUE
/* pending */,
6929 &gnu_v3_exception_catchpoint_ops
, from_tty
,
6935 /* Deal with "catch catch" and "catch throw" commands */
6938 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6939 int tempflag
, int from_tty
)
6941 char *cond_string
= NULL
;
6942 struct symtab_and_line
*sal
= NULL
;
6946 ep_skip_leading_whitespace (&arg
);
6948 cond_string
= ep_parse_optional_if_clause (&arg
);
6950 if ((*arg
!= '\0') && !isspace (*arg
))
6951 error (_("Junk at end of arguments."));
6953 if (ex_event
!= EX_EVENT_THROW
6954 && ex_event
!= EX_EVENT_CATCH
)
6955 error (_("Unsupported or unknown exception event; cannot catch it"));
6957 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6960 warning (_("Unsupported with this platform/compiler combination."));
6963 /* Implementation of "catch catch" command. */
6966 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6968 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6969 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6972 /* Implementation of "catch throw" command. */
6975 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6977 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6978 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6981 /* Create a breakpoint struct for Ada exception catchpoints. */
6984 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
6985 struct symtab_and_line sal
,
6989 struct expression
*cond
,
6990 struct breakpoint_ops
*ops
,
6994 struct breakpoint
*b
;
6998 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7000 loc_gdbarch
= gdbarch
;
7002 describe_other_breakpoints (loc_gdbarch
, sal
.pc
, sal
.section
, -1);
7003 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7004 version for exception catchpoints, because two catchpoints
7005 used for different exception names will use the same address.
7006 In this case, a "breakpoint ... also set at..." warning is
7007 unproductive. Besides. the warning phrasing is also a bit
7008 inapropriate, we should use the word catchpoint, and tell
7009 the user what type of catchpoint it is. The above is good
7010 enough for now, though. */
7013 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
7014 set_breakpoint_count (breakpoint_count
+ 1);
7016 b
->enable_state
= bp_enabled
;
7017 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7018 b
->number
= breakpoint_count
;
7019 b
->ignore_count
= 0;
7020 b
->loc
->cond
= cond
;
7021 b
->addr_string
= addr_string
;
7022 b
->language
= language_ada
;
7023 b
->cond_string
= cond_string
;
7024 b
->exp_string
= exp_string
;
7029 update_global_location_list (1);
7032 /* Implement the "catch exception" command. */
7035 catch_ada_exception_command (char *arg
, int from_tty
,
7036 struct cmd_list_element
*command
)
7038 struct gdbarch
*gdbarch
= get_current_arch ();
7040 struct symtab_and_line sal
;
7042 char *addr_string
= NULL
;
7043 char *exp_string
= NULL
;
7044 char *cond_string
= NULL
;
7045 struct expression
*cond
= NULL
;
7046 struct breakpoint_ops
*ops
= NULL
;
7048 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7052 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
7053 &cond_string
, &cond
, &ops
);
7054 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
7055 cond_string
, cond
, ops
, tempflag
,
7059 /* Implement the "catch assert" command. */
7062 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7064 struct gdbarch
*gdbarch
= get_current_arch ();
7066 struct symtab_and_line sal
;
7067 char *addr_string
= NULL
;
7068 struct breakpoint_ops
*ops
= NULL
;
7070 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7074 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
7075 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
7076 ops
, tempflag
, from_tty
);
7080 catch_command (char *arg
, int from_tty
)
7082 error (_("Catch requires an event name."));
7087 tcatch_command (char *arg
, int from_tty
)
7089 error (_("Catch requires an event name."));
7092 /* Delete breakpoints by address or line. */
7095 clear_command (char *arg
, int from_tty
)
7097 struct breakpoint
*b
;
7098 VEC(breakpoint_p
) *found
= 0;
7101 struct symtabs_and_lines sals
;
7102 struct symtab_and_line sal
;
7107 sals
= decode_line_spec (arg
, 1);
7112 sals
.sals
= (struct symtab_and_line
*)
7113 xmalloc (sizeof (struct symtab_and_line
));
7114 make_cleanup (xfree
, sals
.sals
);
7115 init_sal (&sal
); /* initialize to zeroes */
7116 sal
.line
= default_breakpoint_line
;
7117 sal
.symtab
= default_breakpoint_symtab
;
7118 sal
.pc
= default_breakpoint_address
;
7119 if (sal
.symtab
== 0)
7120 error (_("No source file specified."));
7128 /* We don't call resolve_sal_pc here. That's not
7129 as bad as it seems, because all existing breakpoints
7130 typically have both file/line and pc set. So, if
7131 clear is given file/line, we can match this to existing
7132 breakpoint without obtaining pc at all.
7134 We only support clearing given the address explicitly
7135 present in breakpoint table. Say, we've set breakpoint
7136 at file:line. There were several PC values for that file:line,
7137 due to optimization, all in one block.
7138 We've picked one PC value. If "clear" is issued with another
7139 PC corresponding to the same file:line, the breakpoint won't
7140 be cleared. We probably can still clear the breakpoint, but
7141 since the other PC value is never presented to user, user
7142 can only find it by guessing, and it does not seem important
7145 /* For each line spec given, delete bps which correspond
7146 to it. Do it in two passes, solely to preserve the current
7147 behavior that from_tty is forced true if we delete more than
7151 for (i
= 0; i
< sals
.nelts
; i
++)
7153 /* If exact pc given, clear bpts at that pc.
7154 If line given (pc == 0), clear all bpts on specified line.
7155 If defaulting, clear all bpts on default line
7158 defaulting sal.pc != 0 tests to do
7163 1 0 <can't happen> */
7167 /* Find all matching breakpoints and add them to
7172 /* Are we going to delete b? */
7173 if (b
->type
!= bp_none
7174 && b
->type
!= bp_watchpoint
7175 && b
->type
!= bp_hardware_watchpoint
7176 && b
->type
!= bp_read_watchpoint
7177 && b
->type
!= bp_access_watchpoint
)
7179 struct bp_location
*loc
= b
->loc
;
7180 for (; loc
; loc
= loc
->next
)
7182 int pc_match
= sal
.pc
7183 && (loc
->address
== sal
.pc
)
7184 && (!section_is_overlay (loc
->section
)
7185 || loc
->section
== sal
.section
);
7186 int line_match
= ((default_match
|| (0 == sal
.pc
))
7187 && b
->source_file
!= NULL
7188 && sal
.symtab
!= NULL
7189 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7190 && b
->line_number
== sal
.line
);
7191 if (pc_match
|| line_match
)
7200 VEC_safe_push(breakpoint_p
, found
, b
);
7203 /* Now go thru the 'found' chain and delete them. */
7204 if (VEC_empty(breakpoint_p
, found
))
7207 error (_("No breakpoint at %s."), arg
);
7209 error (_("No breakpoint at this line."));
7212 if (VEC_length(breakpoint_p
, found
) > 1)
7213 from_tty
= 1; /* Always report if deleted more than one */
7216 if (VEC_length(breakpoint_p
, found
) == 1)
7217 printf_unfiltered (_("Deleted breakpoint "));
7219 printf_unfiltered (_("Deleted breakpoints "));
7221 breakpoints_changed ();
7223 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7226 printf_unfiltered ("%d ", b
->number
);
7227 delete_breakpoint (b
);
7230 putchar_unfiltered ('\n');
7233 /* Delete breakpoint in BS if they are `delete' breakpoints and
7234 all breakpoints that are marked for deletion, whether hit or not.
7235 This is called after any breakpoint is hit, or after errors. */
7238 breakpoint_auto_delete (bpstat bs
)
7240 struct breakpoint
*b
, *temp
;
7242 for (; bs
; bs
= bs
->next
)
7243 if (bs
->breakpoint_at
7244 && bs
->breakpoint_at
->owner
7245 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7247 delete_breakpoint (bs
->breakpoint_at
->owner
);
7249 ALL_BREAKPOINTS_SAFE (b
, temp
)
7251 if (b
->disposition
== disp_del_at_next_stop
)
7252 delete_breakpoint (b
);
7256 /* A cleanup function which destroys a vector. */
7259 do_vec_free (void *p
)
7261 VEC(bp_location_p
) **vec
= p
;
7263 VEC_free (bp_location_p
, *vec
);
7266 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7267 into the inferior, only remove already-inserted locations that no
7268 longer should be inserted. Functions that delete a breakpoint or
7269 breakpoints should pass false, so that deleting a breakpoint
7270 doesn't have the side effect of inserting the locations of other
7271 breakpoints that are marked not-inserted, but should_be_inserted
7272 returns true on them.
7274 This behaviour is useful is situations close to tear-down -- e.g.,
7275 after an exec, while the target still has execution, but breakpoint
7276 shadows of the previous executable image should *NOT* be restored
7277 to the new image; or before detaching, where the target still has
7278 execution and wants to delete breakpoints from GDB's lists, and all
7279 breakpoints had already been removed from the inferior. */
7282 update_global_location_list (int should_insert
)
7284 struct breakpoint
*b
;
7285 struct bp_location
**next
= &bp_location_chain
;
7286 struct bp_location
*loc
;
7287 struct bp_location
*loc2
;
7288 VEC(bp_location_p
) *old_locations
= NULL
;
7291 struct cleanup
*cleanups
;
7293 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
7294 /* Store old locations for future reference. */
7295 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7296 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7298 bp_location_chain
= NULL
;
7301 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7304 next
= &(loc
->global_next
);
7309 /* Identify bp_location instances that are no longer present in the new
7310 list, and therefore should be freed. Note that it's not necessary that
7311 those locations should be removed from inferior -- if there's another
7312 location at the same address (previously marked as duplicate),
7313 we don't need to remove/insert the location. */
7314 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7316 /* Tells if 'loc' is found amoung the new locations. If not, we
7318 int found_object
= 0;
7319 /* Tells if the location should remain inserted in the target. */
7320 int keep_in_target
= 0;
7322 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7329 /* If this location is no longer present, and inserted, look if there's
7330 maybe a new location at the same address. If so, mark that one
7331 inserted, and don't remove this one. This is needed so that we
7332 don't have a time window where a breakpoint at certain location is not
7337 /* If the location is inserted now, we might have to remove it. */
7339 if (found_object
&& should_be_inserted (loc
))
7341 /* The location is still present in the location list, and still
7342 should be inserted. Don't do anything. */
7347 /* The location is either no longer present, or got disabled.
7348 See if there's another location at the same address, in which
7349 case we don't need to remove this one from the target. */
7350 if (breakpoint_address_is_meaningful (loc
->owner
))
7351 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7353 /* For the sake of should_insert_location. The
7354 call to check_duplicates will fix up this later. */
7355 loc2
->duplicate
= 0;
7356 if (should_be_inserted (loc2
)
7357 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7360 loc2
->target_info
= loc
->target_info
;
7367 if (!keep_in_target
)
7369 if (remove_breakpoint (loc
, mark_uninserted
))
7371 /* This is just about all we can do. We could keep this
7372 location on the global list, and try to remove it next
7373 time, but there's no particular reason why we will
7376 Note that at this point, loc->owner is still valid,
7377 as delete_breakpoint frees the breakpoint only
7378 after calling us. */
7379 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7380 loc
->owner
->number
);
7388 if (removed
&& non_stop
)
7390 /* This location was removed from the targets. In non-stop mode,
7391 a race condition is possible where we've removed a breakpoint,
7392 but stop events for that breakpoint are already queued and will
7393 arrive later. To suppress spurious SIGTRAPs reported to user,
7394 we keep this breakpoint location for a bit, and will retire it
7395 after we see 3 * thread_count events.
7396 The theory here is that reporting of events should,
7397 "on the average", be fair, so after that many event we'll see
7398 events from all threads that have anything of interest, and no
7399 longer need to keep this breakpoint. This is just a
7400 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7401 which is usability issue, but not a correctness problem. */
7402 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7405 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7408 free_bp_location (loc
);
7414 check_duplicates (b
);
7417 if (breakpoints_always_inserted_mode () && should_insert
7418 && (have_live_inferiors ()
7419 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
7420 insert_breakpoint_locations ();
7422 do_cleanups (cleanups
);
7426 breakpoint_retire_moribund (void)
7428 struct bp_location
*loc
;
7431 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7432 if (--(loc
->events_till_retirement
) == 0)
7434 free_bp_location (loc
);
7435 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7441 update_global_location_list_nothrow (int inserting
)
7443 struct gdb_exception e
;
7444 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7445 update_global_location_list (inserting
);
7448 /* Clear BPT from a BPS. */
7450 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7453 for (bs
= bps
; bs
; bs
= bs
->next
)
7454 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7456 bs
->breakpoint_at
= NULL
;
7458 /* bs->commands will be freed later. */
7462 /* Callback for iterate_over_threads. */
7464 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7466 struct breakpoint
*bpt
= data
;
7467 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7471 /* Delete a breakpoint and clean up all traces of it in the data
7475 delete_breakpoint (struct breakpoint
*bpt
)
7477 struct breakpoint
*b
;
7478 struct bp_location
*loc
, *next
;
7480 gdb_assert (bpt
!= NULL
);
7482 /* Has this bp already been deleted? This can happen because multiple
7483 lists can hold pointers to bp's. bpstat lists are especial culprits.
7485 One example of this happening is a watchpoint's scope bp. When the
7486 scope bp triggers, we notice that the watchpoint is out of scope, and
7487 delete it. We also delete its scope bp. But the scope bp is marked
7488 "auto-deleting", and is already on a bpstat. That bpstat is then
7489 checked for auto-deleting bp's, which are deleted.
7491 A real solution to this problem might involve reference counts in bp's,
7492 and/or giving them pointers back to their referencing bpstat's, and
7493 teaching delete_breakpoint to only free a bp's storage when no more
7494 references were extent. A cheaper bandaid was chosen. */
7495 if (bpt
->type
== bp_none
)
7498 observer_notify_breakpoint_deleted (bpt
->number
);
7500 if (breakpoint_chain
== bpt
)
7501 breakpoint_chain
= bpt
->next
;
7506 b
->next
= bpt
->next
;
7510 free_command_lines (&bpt
->commands
);
7511 if (bpt
->cond_string
!= NULL
)
7512 xfree (bpt
->cond_string
);
7513 if (bpt
->addr_string
!= NULL
)
7514 xfree (bpt
->addr_string
);
7515 if (bpt
->exp
!= NULL
)
7517 if (bpt
->exp_string
!= NULL
)
7518 xfree (bpt
->exp_string
);
7519 if (bpt
->val
!= NULL
)
7520 value_free (bpt
->val
);
7521 if (bpt
->source_file
!= NULL
)
7522 xfree (bpt
->source_file
);
7523 if (bpt
->exec_pathname
!= NULL
)
7524 xfree (bpt
->exec_pathname
);
7526 /* Be sure no bpstat's are pointing at it after it's been freed. */
7527 /* FIXME, how can we find all bpstat's?
7528 We just check stop_bpstat for now. Note that we cannot just
7529 remove bpstats pointing at bpt from the stop_bpstat list
7530 entirely, as breakpoint commands are associated with the bpstat;
7531 if we remove it here, then the later call to
7532 bpstat_do_actions (&stop_bpstat);
7533 in event-top.c won't do anything, and temporary breakpoints
7534 with commands won't work. */
7536 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7538 /* Now that breakpoint is removed from breakpoint
7539 list, update the global location list. This
7540 will remove locations that used to belong to
7541 this breakpoint. Do this before freeing
7542 the breakpoint itself, since remove_breakpoint
7543 looks at location's owner. It might be better
7544 design to have location completely self-contained,
7545 but it's not the case now. */
7546 update_global_location_list (0);
7549 /* On the chance that someone will soon try again to delete this same
7550 bp, we mark it as deleted before freeing its storage. */
7551 bpt
->type
= bp_none
;
7557 do_delete_breakpoint_cleanup (void *b
)
7559 delete_breakpoint (b
);
7563 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7565 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7569 delete_command (char *arg
, int from_tty
)
7571 struct breakpoint
*b
, *temp
;
7577 int breaks_to_delete
= 0;
7579 /* Delete all breakpoints if no argument.
7580 Do not delete internal or call-dummy breakpoints, these
7581 have to be deleted with an explicit breakpoint number argument. */
7584 if (b
->type
!= bp_call_dummy
7585 && b
->type
!= bp_shlib_event
7586 && b
->type
!= bp_thread_event
7587 && b
->type
!= bp_overlay_event
7588 && b
->type
!= bp_longjmp_master
7591 breaks_to_delete
= 1;
7596 /* Ask user only if there are some breakpoints to delete. */
7598 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7600 ALL_BREAKPOINTS_SAFE (b
, temp
)
7602 if (b
->type
!= bp_call_dummy
7603 && b
->type
!= bp_shlib_event
7604 && b
->type
!= bp_thread_event
7605 && b
->type
!= bp_overlay_event
7606 && b
->type
!= bp_longjmp_master
7608 delete_breakpoint (b
);
7613 map_breakpoint_numbers (arg
, delete_breakpoint
);
7617 all_locations_are_pending (struct bp_location
*loc
)
7619 for (; loc
; loc
= loc
->next
)
7620 if (!loc
->shlib_disabled
)
7625 /* Subroutine of update_breakpoint_locations to simplify it.
7626 Return non-zero if multiple fns in list LOC have the same name.
7627 Null names are ignored. */
7630 ambiguous_names_p (struct bp_location
*loc
)
7632 struct bp_location
*l
;
7633 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7634 (int (*) (const void *, const void *)) streq
,
7635 NULL
, xcalloc
, xfree
);
7637 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7640 const char *name
= l
->function_name
;
7642 /* Allow for some names to be NULL, ignore them. */
7646 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7648 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7663 update_breakpoint_locations (struct breakpoint
*b
,
7664 struct symtabs_and_lines sals
)
7668 struct bp_location
*existing_locations
= b
->loc
;
7670 /* If there's no new locations, and all existing locations
7671 are pending, don't do anything. This optimizes
7672 the common case where all locations are in the same
7673 shared library, that was unloaded. We'd like to
7674 retain the location, so that when the library
7675 is loaded again, we don't loose the enabled/disabled
7676 status of the individual locations. */
7677 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7682 for (i
= 0; i
< sals
.nelts
; ++i
)
7684 struct bp_location
*new_loc
=
7685 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7687 /* Reparse conditions, they might contain references to the
7689 if (b
->cond_string
!= NULL
)
7691 struct gdb_exception e
;
7694 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7696 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7701 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7702 b
->number
, e
.message
);
7703 new_loc
->enabled
= 0;
7707 if (b
->source_file
!= NULL
)
7708 xfree (b
->source_file
);
7709 if (sals
.sals
[i
].symtab
== NULL
)
7710 b
->source_file
= NULL
;
7712 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
7714 if (b
->line_number
== 0)
7715 b
->line_number
= sals
.sals
[i
].line
;
7718 /* Update locations of permanent breakpoints. */
7719 if (b
->enable_state
== bp_permanent
)
7720 make_breakpoint_permanent (b
);
7722 /* If possible, carry over 'disable' status from existing breakpoints. */
7724 struct bp_location
*e
= existing_locations
;
7725 /* If there are multiple breakpoints with the same function name,
7726 e.g. for inline functions, comparing function names won't work.
7727 Instead compare pc addresses; this is just a heuristic as things
7728 may have moved, but in practice it gives the correct answer
7729 often enough until a better solution is found. */
7730 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7732 for (; e
; e
= e
->next
)
7734 if (!e
->enabled
&& e
->function_name
)
7736 struct bp_location
*l
= b
->loc
;
7737 if (have_ambiguous_names
)
7739 for (; l
; l
= l
->next
)
7740 if (e
->address
== l
->address
)
7748 for (; l
; l
= l
->next
)
7749 if (l
->function_name
7750 && strcmp (e
->function_name
, l
->function_name
) == 0)
7760 update_global_location_list (1);
7764 /* Reset a breakpoint given it's struct breakpoint * BINT.
7765 The value we return ends up being the return value from catch_errors.
7766 Unused in this case. */
7769 breakpoint_re_set_one (void *bint
)
7771 /* get past catch_errs */
7772 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7776 int *not_found_ptr
= ¬_found
;
7777 struct symtabs_and_lines sals
= {};
7778 struct symtabs_and_lines expanded
;
7780 enum enable_state save_enable
;
7781 struct gdb_exception e
;
7782 struct cleanup
*cleanups
;
7787 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7791 case bp_hardware_breakpoint
:
7793 if (b
->addr_string
== NULL
)
7795 /* Anything without a string can't be re-set. */
7796 delete_breakpoint (b
);
7800 set_language (b
->language
);
7801 input_radix
= b
->input_radix
;
7803 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7805 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7810 int not_found_and_ok
= 0;
7811 /* For pending breakpoints, it's expected that parsing
7812 will fail until the right shared library is loaded.
7813 User has already told to create pending breakpoints and
7814 don't need extra messages. If breakpoint is in bp_shlib_disabled
7815 state, then user already saw the message about that breakpoint
7816 being disabled, and don't want to see more errors. */
7818 && (b
->condition_not_parsed
7819 || (b
->loc
&& b
->loc
->shlib_disabled
)
7820 || b
->enable_state
== bp_disabled
))
7821 not_found_and_ok
= 1;
7823 if (!not_found_and_ok
)
7825 /* We surely don't want to warn about the same breakpoint
7826 10 times. One solution, implemented here, is disable
7827 the breakpoint on error. Another solution would be to
7828 have separate 'warning emitted' flag. Since this
7829 happens only when a binary has changed, I don't know
7830 which approach is better. */
7831 b
->enable_state
= bp_disabled
;
7832 throw_exception (e
);
7839 gdb_assert (sals
.nelts
== 1);
7840 resolve_sal_pc (&sals
.sals
[0]);
7841 if (b
->condition_not_parsed
&& s
&& s
[0])
7843 char *cond_string
= 0;
7847 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7848 &cond_string
, &thread
, &task
);
7850 b
->cond_string
= cond_string
;
7853 b
->condition_not_parsed
= 0;
7855 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7856 cleanups
= make_cleanup (xfree
, sals
.sals
);
7857 update_breakpoint_locations (b
, expanded
);
7858 do_cleanups (cleanups
);
7862 case bp_hardware_watchpoint
:
7863 case bp_read_watchpoint
:
7864 case bp_access_watchpoint
:
7865 /* Watchpoint can be either on expression using entirely global variables,
7866 or it can be on local variables.
7868 Watchpoints of the first kind are never auto-deleted, and even persist
7869 across program restarts. Since they can use variables from shared
7870 libraries, we need to reparse expression as libraries are loaded
7873 Watchpoints on local variables can also change meaning as result
7874 of solib event. For example, if a watchpoint uses both a local and
7875 a global variables in expression, it's a local watchpoint, but
7876 unloading of a shared library will make the expression invalid.
7877 This is not a very common use case, but we still re-evaluate
7878 expression, to avoid surprises to the user.
7880 Note that for local watchpoints, we re-evaluate it only if
7881 watchpoints frame id is still valid. If it's not, it means
7882 the watchpoint is out of scope and will be deleted soon. In fact,
7883 I'm not sure we'll ever be called in this case.
7885 If a local watchpoint's frame id is still valid, then
7886 b->exp_valid_block is likewise valid, and we can safely use it.
7888 Don't do anything about disabled watchpoints, since they will
7889 be reevaluated again when enabled. */
7890 update_watchpoint (b
, 1 /* reparse */);
7892 /* We needn't really do anything to reset these, since the mask
7893 that requests them is unaffected by e.g., new libraries being
7899 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7901 /* Delete overlay event and longjmp master breakpoints; they will be
7902 reset later by breakpoint_re_set. */
7903 case bp_overlay_event
:
7904 case bp_longjmp_master
:
7905 delete_breakpoint (b
);
7908 /* This breakpoint is special, it's set up when the inferior
7909 starts and we really don't want to touch it. */
7910 case bp_shlib_event
:
7912 /* Like bp_shlib_event, this breakpoint type is special.
7913 Once it is set up, we do not want to touch it. */
7914 case bp_thread_event
:
7916 /* Keep temporary breakpoints, which can be encountered when we step
7917 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7918 Otherwise these should have been blown away via the cleanup chain
7919 or by breakpoint_init_inferior when we rerun the executable. */
7922 case bp_watchpoint_scope
:
7924 case bp_step_resume
:
7926 case bp_longjmp_resume
:
7933 /* Re-set all breakpoints after symbols have been re-loaded. */
7935 breakpoint_re_set (void)
7937 struct breakpoint
*b
, *temp
;
7938 enum language save_language
;
7939 int save_input_radix
;
7941 save_language
= current_language
->la_language
;
7942 save_input_radix
= input_radix
;
7943 ALL_BREAKPOINTS_SAFE (b
, temp
)
7945 /* Format possible error msg */
7946 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7948 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7949 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7950 do_cleanups (cleanups
);
7952 set_language (save_language
);
7953 input_radix
= save_input_radix
;
7955 create_overlay_event_breakpoint ("_ovly_debug_event");
7956 create_longjmp_master_breakpoint ("longjmp");
7957 create_longjmp_master_breakpoint ("_longjmp");
7958 create_longjmp_master_breakpoint ("siglongjmp");
7959 create_longjmp_master_breakpoint ("_siglongjmp");
7962 /* Reset the thread number of this breakpoint:
7964 - If the breakpoint is for all threads, leave it as-is.
7965 - Else, reset it to the current thread for inferior_ptid. */
7967 breakpoint_re_set_thread (struct breakpoint
*b
)
7969 if (b
->thread
!= -1)
7971 if (in_thread_list (inferior_ptid
))
7972 b
->thread
= pid_to_thread_id (inferior_ptid
);
7976 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7977 If from_tty is nonzero, it prints a message to that effect,
7978 which ends with a period (no newline). */
7981 set_ignore_count (int bptnum
, int count
, int from_tty
)
7983 struct breakpoint
*b
;
7989 if (b
->number
== bptnum
)
7991 b
->ignore_count
= count
;
7995 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7997 else if (count
== 1)
7998 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
8001 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
8004 breakpoints_changed ();
8005 observer_notify_breakpoint_modified (b
->number
);
8009 error (_("No breakpoint number %d."), bptnum
);
8013 make_breakpoint_silent (struct breakpoint
*b
)
8015 /* Silence the breakpoint. */
8019 /* Command to set ignore-count of breakpoint N to COUNT. */
8022 ignore_command (char *args
, int from_tty
)
8028 error_no_arg (_("a breakpoint number"));
8030 num
= get_number (&p
);
8032 error (_("bad breakpoint number: '%s'"), args
);
8034 error (_("Second argument (specified ignore-count) is missing."));
8036 set_ignore_count (num
,
8037 longest_to_int (value_as_long (parse_and_eval (p
))),
8040 printf_filtered ("\n");
8043 /* Call FUNCTION on each of the breakpoints
8044 whose numbers are given in ARGS. */
8047 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
8052 struct breakpoint
*b
, *tmp
;
8056 error_no_arg (_("one or more breakpoint numbers"));
8063 num
= get_number_or_range (&p1
);
8066 warning (_("bad breakpoint number at or near '%s'"), p
);
8070 ALL_BREAKPOINTS_SAFE (b
, tmp
)
8071 if (b
->number
== num
)
8073 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
8076 if (related_breakpoint
)
8077 function (related_breakpoint
);
8081 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
8087 static struct bp_location
*
8088 find_location_by_number (char *number
)
8090 char *dot
= strchr (number
, '.');
8094 struct breakpoint
*b
;
8095 struct bp_location
*loc
;
8100 bp_num
= get_number_or_range (&p1
);
8102 error (_("Bad breakpoint number '%s'"), number
);
8105 if (b
->number
== bp_num
)
8110 if (!b
|| b
->number
!= bp_num
)
8111 error (_("Bad breakpoint number '%s'"), number
);
8114 loc_num
= get_number_or_range (&p1
);
8116 error (_("Bad breakpoint location number '%s'"), number
);
8120 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
8123 error (_("Bad breakpoint location number '%s'"), dot
+1);
8129 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8130 If from_tty is nonzero, it prints a message to that effect,
8131 which ends with a period (no newline). */
8134 disable_breakpoint (struct breakpoint
*bpt
)
8136 /* Never disable a watchpoint scope breakpoint; we want to
8137 hit them when we leave scope so we can delete both the
8138 watchpoint and its scope breakpoint at that time. */
8139 if (bpt
->type
== bp_watchpoint_scope
)
8142 /* You can't disable permanent breakpoints. */
8143 if (bpt
->enable_state
== bp_permanent
)
8146 bpt
->enable_state
= bp_disabled
;
8148 update_global_location_list (0);
8150 observer_notify_breakpoint_modified (bpt
->number
);
8154 disable_command (char *args
, int from_tty
)
8156 struct breakpoint
*bpt
;
8158 ALL_BREAKPOINTS (bpt
)
8162 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8168 case bp_hardware_breakpoint
:
8170 case bp_hardware_watchpoint
:
8171 case bp_read_watchpoint
:
8172 case bp_access_watchpoint
:
8173 disable_breakpoint (bpt
);
8177 else if (strchr (args
, '.'))
8179 struct bp_location
*loc
= find_location_by_number (args
);
8182 update_global_location_list (0);
8185 map_breakpoint_numbers (args
, disable_breakpoint
);
8189 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8191 int target_resources_ok
, other_type_used
;
8194 if (bpt
->type
== bp_hardware_breakpoint
)
8197 i
= hw_breakpoint_used_count ();
8198 target_resources_ok
=
8199 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8201 if (target_resources_ok
== 0)
8202 error (_("No hardware breakpoint support in the target."));
8203 else if (target_resources_ok
< 0)
8204 error (_("Hardware breakpoints used exceeds limit."));
8207 if (bpt
->type
== bp_watchpoint
8208 || bpt
->type
== bp_hardware_watchpoint
8209 || bpt
->type
== bp_read_watchpoint
8210 || bpt
->type
== bp_access_watchpoint
)
8212 struct gdb_exception e
;
8214 TRY_CATCH (e
, RETURN_MASK_ALL
)
8216 update_watchpoint (bpt
, 1 /* reparse */);
8220 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
8226 if (bpt
->enable_state
!= bp_permanent
)
8227 bpt
->enable_state
= bp_enabled
;
8228 bpt
->disposition
= disposition
;
8229 update_global_location_list (1);
8230 breakpoints_changed ();
8232 observer_notify_breakpoint_modified (bpt
->number
);
8237 enable_breakpoint (struct breakpoint
*bpt
)
8239 do_enable_breakpoint (bpt
, bpt
->disposition
);
8242 /* The enable command enables the specified breakpoints (or all defined
8243 breakpoints) so they once again become (or continue to be) effective
8244 in stopping the inferior. */
8247 enable_command (char *args
, int from_tty
)
8249 struct breakpoint
*bpt
;
8251 ALL_BREAKPOINTS (bpt
)
8255 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8261 case bp_hardware_breakpoint
:
8263 case bp_hardware_watchpoint
:
8264 case bp_read_watchpoint
:
8265 case bp_access_watchpoint
:
8266 enable_breakpoint (bpt
);
8270 else if (strchr (args
, '.'))
8272 struct bp_location
*loc
= find_location_by_number (args
);
8275 update_global_location_list (1);
8278 map_breakpoint_numbers (args
, enable_breakpoint
);
8282 enable_once_breakpoint (struct breakpoint
*bpt
)
8284 do_enable_breakpoint (bpt
, disp_disable
);
8288 enable_once_command (char *args
, int from_tty
)
8290 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8294 enable_delete_breakpoint (struct breakpoint
*bpt
)
8296 do_enable_breakpoint (bpt
, disp_del
);
8300 enable_delete_command (char *args
, int from_tty
)
8302 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8306 set_breakpoint_cmd (char *args
, int from_tty
)
8311 show_breakpoint_cmd (char *args
, int from_tty
)
8315 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8317 struct symtabs_and_lines
8318 decode_line_spec_1 (char *string
, int funfirstline
)
8320 struct symtabs_and_lines sals
;
8322 error (_("Empty line specification."));
8323 if (default_breakpoint_valid
)
8324 sals
= decode_line_1 (&string
, funfirstline
,
8325 default_breakpoint_symtab
,
8326 default_breakpoint_line
,
8327 (char ***) NULL
, NULL
);
8329 sals
= decode_line_1 (&string
, funfirstline
,
8330 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8332 error (_("Junk at end of line specification: %s"), string
);
8336 /* Create and insert a raw software breakpoint at PC. Return an
8337 identifier, which should be used to remove the breakpoint later.
8338 In general, places which call this should be using something on the
8339 breakpoint chain instead; this function should be eliminated
8343 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8345 struct bp_target_info
*bp_tgt
;
8347 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8348 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8350 bp_tgt
->placed_address
= pc
;
8351 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
8353 /* Could not insert the breakpoint. */
8361 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8364 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
8366 struct bp_target_info
*bp_tgt
= bp
;
8369 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
8375 /* One (or perhaps two) breakpoints used for software single stepping. */
8377 static void *single_step_breakpoints
[2];
8378 static struct gdbarch
*single_step_gdbarch
[2];
8380 /* Create and insert a breakpoint for software single step. */
8383 insert_single_step_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR next_pc
)
8387 if (single_step_breakpoints
[0] == NULL
)
8389 bpt_p
= &single_step_breakpoints
[0];
8390 single_step_gdbarch
[0] = gdbarch
;
8394 gdb_assert (single_step_breakpoints
[1] == NULL
);
8395 bpt_p
= &single_step_breakpoints
[1];
8396 single_step_gdbarch
[1] = gdbarch
;
8399 /* NOTE drow/2006-04-11: A future improvement to this function would be
8400 to only create the breakpoints once, and actually put them on the
8401 breakpoint chain. That would let us use set_raw_breakpoint. We could
8402 adjust the addresses each time they were needed. Doing this requires
8403 corresponding changes elsewhere where single step breakpoints are
8404 handled, however. So, for now, we use this. */
8406 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, next_pc
);
8408 error (_("Could not insert single-step breakpoint at %s"),
8409 paddress (gdbarch
, next_pc
));
8412 /* Remove and delete any breakpoints used for software single step. */
8415 remove_single_step_breakpoints (void)
8417 gdb_assert (single_step_breakpoints
[0] != NULL
);
8419 /* See insert_single_step_breakpoint for more about this deprecated
8421 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
8422 single_step_breakpoints
[0]);
8423 single_step_gdbarch
[0] = NULL
;
8424 single_step_breakpoints
[0] = NULL
;
8426 if (single_step_breakpoints
[1] != NULL
)
8428 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
8429 single_step_breakpoints
[1]);
8430 single_step_gdbarch
[1] = NULL
;
8431 single_step_breakpoints
[1] = NULL
;
8435 /* Check whether a software single-step breakpoint is inserted at PC. */
8438 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8442 for (i
= 0; i
< 2; i
++)
8444 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8445 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8452 /* Tracepoint-specific operations. */
8454 /* Set tracepoint count to NUM. */
8456 set_tracepoint_count (int num
)
8458 tracepoint_count
= num
;
8459 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
8463 trace_command (char *arg
, int from_tty
)
8465 break_command_really (get_current_arch (),
8467 NULL
, 0, 1 /* parse arg */,
8468 0 /* tempflag */, 0 /* hardwareflag */,
8470 0 /* Ignore count */,
8471 pending_break_support
,
8475 set_tracepoint_count (breakpoint_count
);
8478 /* Print information on tracepoint number TPNUM_EXP, or all if
8482 tracepoints_info (char *tpnum_exp
, int from_tty
)
8484 struct breakpoint
*b
;
8485 int tps_to_list
= 0;
8487 /* In the no-arguments case, say "No tracepoints" if none found. */
8500 ui_out_message (uiout
, 0, "No tracepoints.\n");
8505 /* Otherwise be the same as "info break". */
8506 breakpoints_info (tpnum_exp
, from_tty
);
8509 /* The 'enable trace' command enables tracepoints.
8510 Not supported by all targets. */
8512 enable_trace_command (char *args
, int from_tty
)
8514 enable_command (args
, from_tty
);
8517 /* The 'disable trace' command disables tracepoints.
8518 Not supported by all targets. */
8520 disable_trace_command (char *args
, int from_tty
)
8522 disable_command (args
, from_tty
);
8525 /* Remove a tracepoint (or all if no argument) */
8527 delete_trace_command (char *arg
, int from_tty
)
8529 struct breakpoint
*b
, *temp
;
8535 int breaks_to_delete
= 0;
8537 /* Delete all breakpoints if no argument.
8538 Do not delete internal or call-dummy breakpoints, these
8539 have to be deleted with an explicit breakpoint number argument. */
8544 breaks_to_delete
= 1;
8549 /* Ask user only if there are some breakpoints to delete. */
8551 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
8553 ALL_BREAKPOINTS_SAFE (b
, temp
)
8555 if (b
->type
== bp_tracepoint
8557 delete_breakpoint (b
);
8562 map_breakpoint_numbers (arg
, delete_breakpoint
);
8565 /* Set passcount for tracepoint.
8567 First command argument is passcount, second is tracepoint number.
8568 If tracepoint number omitted, apply to most recently defined.
8569 Also accepts special argument "all". */
8572 trace_pass_command (char *args
, int from_tty
)
8574 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
8578 if (args
== 0 || *args
== 0)
8579 error (_("passcount command requires an argument (count + optional TP num)"));
8581 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
8583 while (*args
&& isspace ((int) *args
))
8586 if (*args
&& strncasecmp (args
, "all", 3) == 0)
8588 args
+= 3; /* Skip special argument "all". */
8591 error (_("Junk at end of arguments."));
8594 t1
= get_tracepoint_by_number (&args
, 1, 1);
8600 ALL_TRACEPOINTS (t2
)
8601 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
8603 t2
->pass_count
= count
;
8604 observer_notify_tracepoint_modified (t2
->number
);
8606 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8610 t1
= get_tracepoint_by_number (&args
, 1, 0);
8617 get_tracepoint (int num
)
8619 struct breakpoint
*t
;
8622 if (t
->number
== num
)
8628 /* Utility: parse a tracepoint number and look it up in the list.
8629 If MULTI_P is true, there might be a range of tracepoints in ARG.
8630 if OPTIONAL_P is true, then if the argument is missing, the most
8631 recent tracepoint (tracepoint_count) is returned. */
8633 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
8635 extern int tracepoint_count
;
8636 struct breakpoint
*t
;
8638 char *instring
= arg
== NULL
? NULL
: *arg
;
8640 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
8643 tpnum
= tracepoint_count
;
8645 error_no_arg (_("tracepoint number"));
8648 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
8652 if (instring
&& *instring
)
8653 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8656 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8661 if (t
->number
== tpnum
)
8666 /* FIXME: if we are in the middle of a range we don't want to give
8667 a message. The current interface to get_number_or_range doesn't
8668 allow us to discover this. */
8669 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
8673 /* save-tracepoints command */
8675 tracepoint_save_command (char *args
, int from_tty
)
8677 struct breakpoint
*tp
;
8679 struct action_line
*line
;
8681 char *i1
= " ", *i2
= " ";
8682 char *indent
, *actionline
, *pathname
;
8684 struct cleanup
*cleanup
;
8686 if (args
== 0 || *args
== 0)
8687 error (_("Argument required (file name in which to save tracepoints)"));
8689 /* See if we have anything to save. */
8690 ALL_TRACEPOINTS (tp
)
8697 warning (_("save-tracepoints: no tracepoints to save."));
8701 pathname
= tilde_expand (args
);
8702 cleanup
= make_cleanup (xfree
, pathname
);
8703 fp
= fopen (pathname
, "w");
8705 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8706 args
, safe_strerror (errno
));
8707 make_cleanup_fclose (fp
);
8709 ALL_TRACEPOINTS (tp
)
8711 if (tp
->addr_string
)
8712 fprintf (fp
, "trace %s\n", tp
->addr_string
);
8715 sprintf_vma (tmp
, tp
->loc
->address
);
8716 fprintf (fp
, "trace *0x%s\n", tmp
);
8720 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
8724 fprintf (fp
, " actions\n");
8726 for (line
= tp
->actions
; line
; line
= line
->next
)
8728 struct cmd_list_element
*cmd
;
8730 QUIT
; /* allow user to bail out with ^C */
8731 actionline
= line
->action
;
8732 while (isspace ((int) *actionline
))
8735 fprintf (fp
, "%s%s\n", indent
, actionline
);
8736 if (*actionline
!= '#') /* skip for comment lines */
8738 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
8740 error (_("Bad action list item: %s"), actionline
);
8741 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
8743 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
8749 do_cleanups (cleanup
);
8751 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
8755 /* Create a vector of all tracepoints. */
8760 VEC(breakpoint_p
) *tp_vec
= 0;
8761 struct breakpoint
*tp
;
8763 ALL_TRACEPOINTS (tp
)
8765 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
8772 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8773 It is defined as a macro to prevent duplication.
8774 COMMAND should be a string constant containing the name of the command. */
8775 #define BREAK_ARGS_HELP(command) \
8776 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8777 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8778 If a line number is specified, break at start of code for that line.\n\
8779 If a function is specified, break at start of code for that function.\n\
8780 If an address is specified, break at that exact address.\n\
8781 With no LOCATION, uses current execution address of selected stack frame.\n\
8782 This is useful for breaking on return to a stack frame.\n\
8784 THREADNUM is the number from \"info threads\".\n\
8785 CONDITION is a boolean expression.\n\
8787 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8789 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8791 /* List of subcommands for "catch". */
8792 static struct cmd_list_element
*catch_cmdlist
;
8794 /* List of subcommands for "tcatch". */
8795 static struct cmd_list_element
*tcatch_cmdlist
;
8797 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8798 lists, and pass some additional user data to the command function. */
8800 add_catch_command (char *name
, char *docstring
,
8801 void (*sfunc
) (char *args
, int from_tty
,
8802 struct cmd_list_element
*command
),
8803 void *user_data_catch
,
8804 void *user_data_tcatch
)
8806 struct cmd_list_element
*command
;
8808 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8810 set_cmd_sfunc (command
, sfunc
);
8811 set_cmd_context (command
, user_data_catch
);
8813 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8815 set_cmd_sfunc (command
, sfunc
);
8816 set_cmd_context (command
, user_data_tcatch
);
8820 _initialize_breakpoint (void)
8822 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8823 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8824 struct cmd_list_element
*c
;
8826 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8828 breakpoint_chain
= 0;
8829 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8830 before a breakpoint is set. */
8831 breakpoint_count
= 0;
8833 tracepoint_count
= 0;
8835 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8836 Set ignore-count of breakpoint number N to COUNT.\n\
8837 Usage is `ignore N COUNT'."));
8839 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8841 add_com ("commands", class_breakpoint
, commands_command
, _("\
8842 Set commands to be executed when a breakpoint is hit.\n\
8843 Give breakpoint number as argument after \"commands\".\n\
8844 With no argument, the targeted breakpoint is the last one set.\n\
8845 The commands themselves follow starting on the next line.\n\
8846 Type a line containing \"end\" to indicate the end of them.\n\
8847 Give \"silent\" as the first line to make the breakpoint silent;\n\
8848 then no output is printed when it is hit, except what the commands print."));
8850 add_com ("condition", class_breakpoint
, condition_command
, _("\
8851 Specify breakpoint number N to break only if COND is true.\n\
8852 Usage is `condition N COND', where N is an integer and COND is an\n\
8853 expression to be evaluated whenever breakpoint N is reached."));
8855 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8856 Set a temporary breakpoint.\n\
8857 Like \"break\" except the breakpoint is only temporary,\n\
8858 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8859 by using \"enable delete\" on the breakpoint number.\n\
8861 BREAK_ARGS_HELP ("tbreak")));
8862 set_cmd_completer (c
, location_completer
);
8864 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8865 Set a hardware assisted breakpoint.\n\
8866 Like \"break\" except the breakpoint requires hardware support,\n\
8867 some target hardware may not have this support.\n\
8869 BREAK_ARGS_HELP ("hbreak")));
8870 set_cmd_completer (c
, location_completer
);
8872 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8873 Set a temporary hardware assisted breakpoint.\n\
8874 Like \"hbreak\" except the breakpoint is only temporary,\n\
8875 so it will be deleted when hit.\n\
8877 BREAK_ARGS_HELP ("thbreak")));
8878 set_cmd_completer (c
, location_completer
);
8880 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8881 Enable some breakpoints.\n\
8882 Give breakpoint numbers (separated by spaces) as arguments.\n\
8883 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8884 This is used to cancel the effect of the \"disable\" command.\n\
8885 With a subcommand you can enable temporarily."),
8886 &enablelist
, "enable ", 1, &cmdlist
);
8888 add_com ("ab", class_breakpoint
, enable_command
, _("\
8889 Enable some breakpoints.\n\
8890 Give breakpoint numbers (separated by spaces) as arguments.\n\
8891 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8892 This is used to cancel the effect of the \"disable\" command.\n\
8893 With a subcommand you can enable temporarily."));
8895 add_com_alias ("en", "enable", class_breakpoint
, 1);
8897 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8898 Enable some breakpoints.\n\
8899 Give breakpoint numbers (separated by spaces) as arguments.\n\
8900 This is used to cancel the effect of the \"disable\" command.\n\
8901 May be abbreviated to simply \"enable\".\n"),
8902 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8904 add_cmd ("once", no_class
, enable_once_command
, _("\
8905 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8906 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8909 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8910 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8911 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8914 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8915 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8916 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8919 add_cmd ("once", no_class
, enable_once_command
, _("\
8920 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8921 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8924 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8925 Disable some breakpoints.\n\
8926 Arguments are breakpoint numbers with spaces in between.\n\
8927 To disable all breakpoints, give no argument.\n\
8928 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8929 &disablelist
, "disable ", 1, &cmdlist
);
8930 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8931 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8933 add_com ("sb", class_breakpoint
, disable_command
, _("\
8934 Disable some breakpoints.\n\
8935 Arguments are breakpoint numbers with spaces in between.\n\
8936 To disable all breakpoints, give no argument.\n\
8937 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8939 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8940 Disable some breakpoints.\n\
8941 Arguments are breakpoint numbers with spaces in between.\n\
8942 To disable all breakpoints, give no argument.\n\
8943 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8944 This command may be abbreviated \"disable\"."),
8947 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8948 Delete some breakpoints or auto-display expressions.\n\
8949 Arguments are breakpoint numbers with spaces in between.\n\
8950 To delete all breakpoints, give no argument.\n\
8952 Also a prefix command for deletion of other GDB objects.\n\
8953 The \"unset\" command is also an alias for \"delete\"."),
8954 &deletelist
, "delete ", 1, &cmdlist
);
8955 add_com_alias ("d", "delete", class_breakpoint
, 1);
8956 add_com_alias ("del", "delete", class_breakpoint
, 1);
8958 add_com ("db", class_breakpoint
, delete_command
, _("\
8959 Delete some breakpoints.\n\
8960 Arguments are breakpoint numbers with spaces in between.\n\
8961 To delete all breakpoints, give no argument.\n"));
8963 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8964 Delete some breakpoints or auto-display expressions.\n\
8965 Arguments are breakpoint numbers with spaces in between.\n\
8966 To delete all breakpoints, give no argument.\n\
8967 This command may be abbreviated \"delete\"."),
8970 add_com ("clear", class_breakpoint
, clear_command
, _("\
8971 Clear breakpoint at specified line or function.\n\
8972 Argument may be line number, function name, or \"*\" and an address.\n\
8973 If line number is specified, all breakpoints in that line are cleared.\n\
8974 If function is specified, breakpoints at beginning of function are cleared.\n\
8975 If an address is specified, breakpoints at that address are cleared.\n\
8977 With no argument, clears all breakpoints in the line that the selected frame\n\
8980 See also the \"delete\" command which clears breakpoints by number."));
8982 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8983 Set breakpoint at specified line or function.\n"
8984 BREAK_ARGS_HELP ("break")));
8985 set_cmd_completer (c
, location_completer
);
8987 add_com_alias ("b", "break", class_run
, 1);
8988 add_com_alias ("br", "break", class_run
, 1);
8989 add_com_alias ("bre", "break", class_run
, 1);
8990 add_com_alias ("brea", "break", class_run
, 1);
8993 add_com_alias ("ba", "break", class_breakpoint
, 1);
8997 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8998 Break in function/address or break at a line in the current file."),
8999 &stoplist
, "stop ", 1, &cmdlist
);
9000 add_cmd ("in", class_breakpoint
, stopin_command
,
9001 _("Break in function or address."), &stoplist
);
9002 add_cmd ("at", class_breakpoint
, stopat_command
,
9003 _("Break at a line in the current file."), &stoplist
);
9004 add_com ("status", class_info
, breakpoints_info
, _("\
9005 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9006 The \"Type\" column indicates one of:\n\
9007 \tbreakpoint - normal breakpoint\n\
9008 \twatchpoint - watchpoint\n\
9009 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9010 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9011 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9012 address and file/line number respectively.\n\
9014 Convenience variable \"$_\" and default examine address for \"x\"\n\
9015 are set to the address of the last breakpoint listed unless the command\n\
9016 is prefixed with \"server \".\n\n\
9017 Convenience variable \"$bpnum\" contains the number of the last\n\
9021 add_info ("breakpoints", breakpoints_info
, _("\
9022 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9023 The \"Type\" column indicates one of:\n\
9024 \tbreakpoint - normal breakpoint\n\
9025 \twatchpoint - watchpoint\n\
9026 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9027 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9028 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9029 address and file/line number respectively.\n\
9031 Convenience variable \"$_\" and default examine address for \"x\"\n\
9032 are set to the address of the last breakpoint listed unless the command\n\
9033 is prefixed with \"server \".\n\n\
9034 Convenience variable \"$bpnum\" contains the number of the last\n\
9038 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
9039 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9040 The \"Type\" column indicates one of:\n\
9041 \tbreakpoint - normal breakpoint\n\
9042 \twatchpoint - watchpoint\n\
9043 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9044 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9045 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9046 address and file/line number respectively.\n\
9048 Convenience variable \"$_\" and default examine address for \"x\"\n\
9049 are set to the address of the last breakpoint listed unless the command\n\
9050 is prefixed with \"server \".\n\n\
9051 Convenience variable \"$bpnum\" contains the number of the last\n\
9054 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
9055 Status of all breakpoints, or breakpoint number NUMBER.\n\
9056 The \"Type\" column indicates one of:\n\
9057 \tbreakpoint - normal breakpoint\n\
9058 \twatchpoint - watchpoint\n\
9059 \tlongjmp - internal breakpoint used to step through longjmp()\n\
9060 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
9061 \tuntil - internal breakpoint used by the \"until\" command\n\
9062 \tfinish - internal breakpoint used by the \"finish\" command\n\
9063 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9064 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9065 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9066 address and file/line number respectively.\n\
9068 Convenience variable \"$_\" and default examine address for \"x\"\n\
9069 are set to the address of the last breakpoint listed unless the command\n\
9070 is prefixed with \"server \".\n\n\
9071 Convenience variable \"$bpnum\" contains the number of the last\n\
9073 &maintenanceinfolist
);
9075 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
9076 Set catchpoints to catch events."),
9077 &catch_cmdlist
, "catch ",
9078 0/*allow-unknown*/, &cmdlist
);
9080 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
9081 Set temporary catchpoints to catch events."),
9082 &tcatch_cmdlist
, "tcatch ",
9083 0/*allow-unknown*/, &cmdlist
);
9085 /* Add catch and tcatch sub-commands. */
9086 add_catch_command ("catch", _("\
9087 Catch an exception, when caught.\n\
9088 With an argument, catch only exceptions with the given name."),
9089 catch_catch_command
,
9092 add_catch_command ("throw", _("\
9093 Catch an exception, when thrown.\n\
9094 With an argument, catch only exceptions with the given name."),
9095 catch_throw_command
,
9098 add_catch_command ("fork", _("Catch calls to fork."),
9099 catch_fork_command_1
,
9100 (void *) (uintptr_t) catch_fork_permanent
,
9101 (void *) (uintptr_t) catch_fork_temporary
);
9102 add_catch_command ("vfork", _("Catch calls to vfork."),
9103 catch_fork_command_1
,
9104 (void *) (uintptr_t) catch_vfork_permanent
,
9105 (void *) (uintptr_t) catch_vfork_temporary
);
9106 add_catch_command ("exec", _("Catch calls to exec."),
9107 catch_exec_command_1
,
9110 add_catch_command ("exception", _("\
9111 Catch Ada exceptions, when raised.\n\
9112 With an argument, catch only exceptions with the given name."),
9113 catch_ada_exception_command
,
9116 add_catch_command ("assert", _("\
9117 Catch failed Ada assertions, when raised.\n\
9118 With an argument, catch only exceptions with the given name."),
9119 catch_assert_command
,
9123 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
9124 Set a watchpoint for an expression.\n\
9125 A watchpoint stops execution of your program whenever the value of\n\
9126 an expression changes."));
9127 set_cmd_completer (c
, expression_completer
);
9129 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
9130 Set a read watchpoint for an expression.\n\
9131 A watchpoint stops execution of your program whenever the value of\n\
9132 an expression is read."));
9133 set_cmd_completer (c
, expression_completer
);
9135 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
9136 Set a watchpoint for an expression.\n\
9137 A watchpoint stops execution of your program whenever the value of\n\
9138 an expression is either read or written."));
9139 set_cmd_completer (c
, expression_completer
);
9141 add_info ("watchpoints", breakpoints_info
,
9142 _("Synonym for ``info breakpoints''."));
9145 /* XXX: cagney/2005-02-23: This should be a boolean, and should
9146 respond to changes - contrary to the description. */
9147 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
9148 &can_use_hw_watchpoints
, _("\
9149 Set debugger's willingness to use watchpoint hardware."), _("\
9150 Show debugger's willingness to use watchpoint hardware."), _("\
9151 If zero, gdb will not use hardware for new watchpoints, even if\n\
9152 such is available. (However, any hardware watchpoints that were\n\
9153 created before setting this to nonzero, will continue to use watchpoint\n\
9156 show_can_use_hw_watchpoints
,
9157 &setlist
, &showlist
);
9159 can_use_hw_watchpoints
= 1;
9161 /* Tracepoint manipulation commands. */
9163 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
9164 Set a tracepoint at specified line or function.\n\
9166 BREAK_ARGS_HELP ("trace") "\n\
9167 Do \"help tracepoints\" for info on other tracepoint commands."));
9168 set_cmd_completer (c
, location_completer
);
9170 add_com_alias ("tp", "trace", class_alias
, 0);
9171 add_com_alias ("tr", "trace", class_alias
, 1);
9172 add_com_alias ("tra", "trace", class_alias
, 1);
9173 add_com_alias ("trac", "trace", class_alias
, 1);
9175 add_info ("tracepoints", tracepoints_info
, _("\
9176 Status of tracepoints, or tracepoint number NUMBER.\n\
9177 Convenience variable \"$tpnum\" contains the number of the\n\
9178 last tracepoint set."));
9180 add_info_alias ("tp", "tracepoints", 1);
9182 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
9183 Delete specified tracepoints.\n\
9184 Arguments are tracepoint numbers, separated by spaces.\n\
9185 No argument means delete all tracepoints."),
9188 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
9189 Disable specified tracepoints.\n\
9190 Arguments are tracepoint numbers, separated by spaces.\n\
9191 No argument means disable all tracepoints."),
9193 deprecate_cmd (c
, "disable");
9195 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
9196 Enable specified tracepoints.\n\
9197 Arguments are tracepoint numbers, separated by spaces.\n\
9198 No argument means enable all tracepoints."),
9200 deprecate_cmd (c
, "enable");
9202 add_com ("passcount", class_trace
, trace_pass_command
, _("\
9203 Set the passcount for a tracepoint.\n\
9204 The trace will end when the tracepoint has been passed 'count' times.\n\
9205 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
9206 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
9208 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
9209 Save current tracepoint definitions as a script.\n\
9210 Use the 'source' command in another debug session to restore them."));
9211 set_cmd_completer (c
, filename_completer
);
9213 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
9214 Breakpoint specific settings\n\
9215 Configure various breakpoint-specific variables such as\n\
9216 pending breakpoint behavior"),
9217 &breakpoint_set_cmdlist
, "set breakpoint ",
9218 0/*allow-unknown*/, &setlist
);
9219 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
9220 Breakpoint specific settings\n\
9221 Configure various breakpoint-specific variables such as\n\
9222 pending breakpoint behavior"),
9223 &breakpoint_show_cmdlist
, "show breakpoint ",
9224 0/*allow-unknown*/, &showlist
);
9226 add_setshow_auto_boolean_cmd ("pending", no_class
,
9227 &pending_break_support
, _("\
9228 Set debugger's behavior regarding pending breakpoints."), _("\
9229 Show debugger's behavior regarding pending breakpoints."), _("\
9230 If on, an unrecognized breakpoint location will cause gdb to create a\n\
9231 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9232 an error. If auto, an unrecognized breakpoint location results in a\n\
9233 user-query to see if a pending breakpoint should be created."),
9235 show_pending_break_support
,
9236 &breakpoint_set_cmdlist
,
9237 &breakpoint_show_cmdlist
);
9239 pending_break_support
= AUTO_BOOLEAN_AUTO
;
9241 add_setshow_boolean_cmd ("auto-hw", no_class
,
9242 &automatic_hardware_breakpoints
, _("\
9243 Set automatic usage of hardware breakpoints."), _("\
9244 Show automatic usage of hardware breakpoints."), _("\
9245 If set, the debugger will automatically use hardware breakpoints for\n\
9246 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9247 a warning will be emitted for such breakpoints."),
9249 show_automatic_hardware_breakpoints
,
9250 &breakpoint_set_cmdlist
,
9251 &breakpoint_show_cmdlist
);
9253 add_setshow_enum_cmd ("always-inserted", class_support
,
9254 always_inserted_enums
, &always_inserted_mode
, _("\
9255 Set mode for inserting breakpoints."), _("\
9256 Show mode for inserting breakpoints."), _("\
9257 When this mode is off, breakpoints are inserted in inferior when it is\n\
9258 resumed, and removed when execution stops. When this mode is on,\n\
9259 breakpoints are inserted immediately and removed only when the user\n\
9260 deletes the breakpoint. When this mode is auto (which is the default),\n\
9261 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9262 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9263 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9264 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9266 &show_always_inserted_mode
,
9267 &breakpoint_set_cmdlist
,
9268 &breakpoint_show_cmdlist
);
9270 automatic_hardware_breakpoints
= 1;
9272 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);