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 (CORE_ADDR
, struct obj_section
*, int);
122 static void breakpoints_info (char *, int);
124 static void breakpoint_1 (int, int);
126 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
128 static int breakpoint_cond_eval (void *);
130 static void cleanup_executing_breakpoints (void *);
132 static void commands_command (char *, int);
134 static void condition_command (char *, int);
136 static int get_number_trailer (char **, int);
138 void set_breakpoint_count (int);
147 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
149 static enum print_stop_action
print_it_typical (bpstat
);
151 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
153 static int watchpoint_check (void *);
155 static void maintenance_info_breakpoints (char *, int);
157 static int hw_breakpoint_used_count (void);
159 static int hw_watchpoint_used_count (enum bptype
, int *);
161 static void hbreak_command (char *, int);
163 static void thbreak_command (char *, int);
165 static void watch_command_1 (char *, int, int);
167 static void rwatch_command (char *, int);
169 static void awatch_command (char *, int);
171 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
173 static void stop_command (char *arg
, int from_tty
);
175 static void stopin_command (char *arg
, int from_tty
);
177 static void stopat_command (char *arg
, int from_tty
);
179 static char *ep_parse_optional_if_clause (char **arg
);
181 static char *ep_parse_optional_filename (char **arg
);
183 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
184 char *arg
, int tempflag
, int from_tty
);
186 static void tcatch_command (char *arg
, int from_tty
);
188 static void ep_skip_leading_whitespace (char **s
);
190 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
192 static void free_bp_location (struct bp_location
*loc
);
194 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
196 static void update_global_location_list (int);
198 static void update_global_location_list_nothrow (int);
200 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
202 static void insert_breakpoint_locations (void);
204 static void tracepoints_info (char *, int);
206 static void delete_trace_command (char *, int);
208 static void enable_trace_command (char *, int);
210 static void disable_trace_command (char *, int);
212 static void trace_pass_command (char *, int);
214 static void skip_prologue_sal (struct symtab_and_line
*sal
);
217 /* Flag indicating that a command has proceeded the inferior past the
218 current breakpoint. */
220 static int breakpoint_proceeded
;
223 bpdisp_text (enum bpdisp disp
)
225 /* NOTE: the following values are a part of MI protocol and represent
226 values of 'disp' field returned when inferior stops at a breakpoint. */
227 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
228 return bpdisps
[(int) disp
];
231 /* Prototypes for exported functions. */
232 /* If FALSE, gdb will not use hardware support for watchpoints, even
233 if such is available. */
234 static int can_use_hw_watchpoints
;
237 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
238 struct cmd_list_element
*c
,
241 fprintf_filtered (file
, _("\
242 Debugger's willingness to use watchpoint hardware is %s.\n"),
246 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
247 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
248 for unrecognized breakpoint locations.
249 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
250 static enum auto_boolean pending_break_support
;
252 show_pending_break_support (struct ui_file
*file
, int from_tty
,
253 struct cmd_list_element
*c
,
256 fprintf_filtered (file
, _("\
257 Debugger's behavior regarding pending breakpoints is %s.\n"),
261 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
262 set with "break" but falling in read-only memory.
263 If 0, gdb will warn about such breakpoints, but won't automatically
264 use hardware breakpoints. */
265 static int automatic_hardware_breakpoints
;
267 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
268 struct cmd_list_element
*c
,
271 fprintf_filtered (file
, _("\
272 Automatic usage of hardware breakpoints is %s.\n"),
276 /* If on, gdb will keep breakpoints inserted even as inferior is
277 stopped, and immediately insert any new breakpoints. If off, gdb
278 will insert breakpoints into inferior only when resuming it, and
279 will remove breakpoints upon stop. If auto, GDB will behave as ON
280 if in non-stop mode, and as OFF if all-stop mode.*/
282 static const char always_inserted_auto
[] = "auto";
283 static const char always_inserted_on
[] = "on";
284 static const char always_inserted_off
[] = "off";
285 static const char *always_inserted_enums
[] = {
286 always_inserted_auto
,
291 static const char *always_inserted_mode
= always_inserted_auto
;
293 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
294 struct cmd_list_element
*c
, const char *value
)
296 if (always_inserted_mode
== always_inserted_auto
)
297 fprintf_filtered (file
, _("\
298 Always inserted breakpoint mode is %s (currently %s).\n"),
300 breakpoints_always_inserted_mode () ? "on" : "off");
302 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
306 breakpoints_always_inserted_mode (void)
308 return (always_inserted_mode
== always_inserted_on
309 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
312 void _initialize_breakpoint (void);
314 /* Are we executing breakpoint commands? */
315 static int executing_breakpoint_commands
;
317 /* Are overlay event breakpoints enabled? */
318 static int overlay_events_enabled
;
320 /* Walk the following statement or block through all breakpoints.
321 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
324 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
326 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
327 for (B = breakpoint_chain; \
328 B ? (TMP=B->next, 1): 0; \
331 /* Similar iterators for the low-level breakpoints. */
333 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
335 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
336 for (B = bp_location_chain; \
337 B ? (TMP=B->global_next, 1): 0; \
340 /* Iterator for tracepoints only. */
342 #define ALL_TRACEPOINTS(B) \
343 for (B = breakpoint_chain; B; B = B->next) \
344 if ((B)->type == bp_tracepoint)
346 /* Chains of all breakpoints defined. */
348 struct breakpoint
*breakpoint_chain
;
350 struct bp_location
*bp_location_chain
;
352 /* The locations that no longer correspond to any breakpoint,
353 unlinked from bp_location_chain, but for which a hit
354 may still be reported by a target. */
355 VEC(bp_location_p
) *moribund_locations
= NULL
;
357 /* Number of last breakpoint made. */
359 int breakpoint_count
;
361 /* Number of last tracepoint made. */
363 int tracepoint_count
;
365 /* Return whether a breakpoint is an active enabled breakpoint. */
367 breakpoint_enabled (struct breakpoint
*b
)
369 return (b
->enable_state
== bp_enabled
);
372 /* Set breakpoint count to NUM. */
375 set_breakpoint_count (int num
)
377 breakpoint_count
= num
;
378 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
381 /* Used in run_command to zero the hit count when a new run starts. */
384 clear_breakpoint_hit_counts (void)
386 struct breakpoint
*b
;
392 /* Default address, symtab and line to put a breakpoint at
393 for "break" command with no arg.
394 if default_breakpoint_valid is zero, the other three are
395 not valid, and "break" with no arg is an error.
397 This set by print_stack_frame, which calls set_default_breakpoint. */
399 int default_breakpoint_valid
;
400 CORE_ADDR default_breakpoint_address
;
401 struct symtab
*default_breakpoint_symtab
;
402 int default_breakpoint_line
;
404 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
405 Advance *PP after the string and any trailing whitespace.
407 Currently the string can either be a number or "$" followed by the name
408 of a convenience variable. Making it an expression wouldn't work well
409 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
411 If the string is a NULL pointer, that denotes the last breakpoint.
413 TRAILER is a character which can be found after the number; most
414 commonly this is `-'. If you don't want a trailer, use \0. */
416 get_number_trailer (char **pp
, int trailer
)
418 int retval
= 0; /* default */
422 /* Empty line means refer to the last breakpoint. */
423 return breakpoint_count
;
426 /* Make a copy of the name, so we can null-terminate it
427 to pass to lookup_internalvar(). */
432 while (isalnum (*p
) || *p
== '_')
434 varname
= (char *) alloca (p
- start
+ 1);
435 strncpy (varname
, start
, p
- start
);
436 varname
[p
- start
] = '\0';
437 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
441 printf_filtered (_("Convenience variable must have integer value.\n"));
449 while (*p
>= '0' && *p
<= '9')
452 /* There is no number here. (e.g. "cond a == b"). */
454 /* Skip non-numeric token */
455 while (*p
&& !isspace((int) *p
))
457 /* Return zero, which caller must interpret as error. */
463 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
465 /* Trailing junk: return 0 and let caller print error msg. */
466 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
477 /* Like get_number_trailer, but don't allow a trailer. */
479 get_number (char **pp
)
481 return get_number_trailer (pp
, '\0');
484 /* Parse a number or a range.
485 * A number will be of the form handled by get_number.
486 * A range will be of the form <number1> - <number2>, and
487 * will represent all the integers between number1 and number2,
490 * While processing a range, this fuction is called iteratively;
491 * At each call it will return the next value in the range.
493 * At the beginning of parsing a range, the char pointer PP will
494 * be advanced past <number1> and left pointing at the '-' token.
495 * Subsequent calls will not advance the pointer until the range
496 * is completed. The call that completes the range will advance
497 * pointer PP past <number2>.
501 get_number_or_range (char **pp
)
503 static int last_retval
, end_value
;
504 static char *end_ptr
;
505 static int in_range
= 0;
509 /* Default case: pp is pointing either to a solo number,
510 or to the first number of a range. */
511 last_retval
= get_number_trailer (pp
, '-');
516 /* This is the start of a range (<number1> - <number2>).
517 Skip the '-', parse and remember the second number,
518 and also remember the end of the final token. */
522 while (isspace ((int) *end_ptr
))
523 end_ptr
++; /* skip white space */
524 end_value
= get_number (temp
);
525 if (end_value
< last_retval
)
527 error (_("inverted range"));
529 else if (end_value
== last_retval
)
531 /* degenerate range (number1 == number2). Advance the
532 token pointer so that the range will be treated as a
541 error (_("negative value"));
544 /* pp points to the '-' that betokens a range. All
545 number-parsing has already been done. Return the next
546 integer value (one greater than the saved previous value).
547 Do not advance the token pointer 'pp' until the end of range
550 if (++last_retval
== end_value
)
552 /* End of range reached; advance token pointer. */
562 /* condition N EXP -- set break condition of breakpoint N to EXP. */
565 condition_command (char *arg
, int from_tty
)
567 struct breakpoint
*b
;
572 error_no_arg (_("breakpoint number"));
575 bnum
= get_number (&p
);
577 error (_("Bad breakpoint argument: '%s'"), arg
);
580 if (b
->number
== bnum
)
582 struct bp_location
*loc
= b
->loc
;
583 for (; loc
; loc
= loc
->next
)
591 if (b
->cond_string
!= NULL
)
592 xfree (b
->cond_string
);
596 b
->cond_string
= NULL
;
598 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
603 /* I don't know if it matters whether this is the string the user
604 typed in or the decompiled expression. */
605 b
->cond_string
= xstrdup (arg
);
606 b
->condition_not_parsed
= 0;
607 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
611 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
613 error (_("Junk at end of expression"));
616 breakpoints_changed ();
617 observer_notify_breakpoint_modified (b
->number
);
621 error (_("No breakpoint number %d."), bnum
);
625 commands_command (char *arg
, int from_tty
)
627 struct breakpoint
*b
;
630 struct command_line
*l
;
632 /* If we allowed this, we would have problems with when to
633 free the storage, if we change the commands currently
636 if (executing_breakpoint_commands
)
637 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
640 bnum
= get_number (&p
);
643 error (_("Unexpected extra arguments following breakpoint number."));
646 if (b
->number
== bnum
)
648 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
650 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
651 l
= read_command_lines (tmpbuf
, from_tty
, 1);
652 do_cleanups (cleanups
);
653 free_command_lines (&b
->commands
);
655 breakpoints_changed ();
656 observer_notify_breakpoint_modified (b
->number
);
659 error (_("No breakpoint number %d."), bnum
);
662 /* Like commands_command, but instead of reading the commands from
663 input stream, takes them from an already parsed command structure.
665 This is used by cli-script.c to DTRT with breakpoint commands
666 that are part of if and while bodies. */
667 enum command_control_type
668 commands_from_control_command (char *arg
, struct command_line
*cmd
)
670 struct breakpoint
*b
;
674 /* If we allowed this, we would have problems with when to
675 free the storage, if we change the commands currently
678 if (executing_breakpoint_commands
)
679 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
681 /* An empty string for the breakpoint number means the last
682 breakpoint, but get_number expects a NULL pointer. */
687 bnum
= get_number (&p
);
690 error (_("Unexpected extra arguments following breakpoint number."));
693 if (b
->number
== bnum
)
695 free_command_lines (&b
->commands
);
696 if (cmd
->body_count
!= 1)
697 error (_("Invalid \"commands\" block structure."));
698 /* We need to copy the commands because if/while will free the
699 list after it finishes execution. */
700 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
701 breakpoints_changed ();
702 observer_notify_breakpoint_modified (b
->number
);
703 return simple_control
;
705 error (_("No breakpoint number %d."), bnum
);
708 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
709 by replacing any memory breakpoints with their shadowed contents. */
712 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
714 struct bp_location
*b
;
715 CORE_ADDR bp_addr
= 0;
721 if (b
->owner
->type
== bp_none
)
722 warning (_("reading through apparently deleted breakpoint #%d?"),
725 if (b
->loc_type
!= bp_loc_software_breakpoint
)
729 /* Addresses and length of the part of the breakpoint that
731 bp_addr
= b
->target_info
.placed_address
;
732 bp_size
= b
->target_info
.shadow_len
;
734 /* bp isn't valid, or doesn't shadow memory. */
737 if (bp_addr
+ bp_size
<= memaddr
)
738 /* The breakpoint is entirely before the chunk of memory we
742 if (bp_addr
>= memaddr
+ len
)
743 /* The breakpoint is entirely after the chunk of memory we are
747 /* Offset within shadow_contents. */
748 if (bp_addr
< memaddr
)
750 /* Only copy the second part of the breakpoint. */
751 bp_size
-= memaddr
- bp_addr
;
752 bptoffset
= memaddr
- bp_addr
;
756 if (bp_addr
+ bp_size
> memaddr
+ len
)
758 /* Only copy the first part of the breakpoint. */
759 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
762 memcpy (buf
+ bp_addr
- memaddr
,
763 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
768 /* A wrapper function for inserting catchpoints. */
770 insert_catchpoint (struct ui_out
*uo
, void *args
)
772 struct breakpoint
*b
= (struct breakpoint
*) args
;
775 gdb_assert (b
->type
== bp_catchpoint
);
776 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
782 is_hardware_watchpoint (struct breakpoint
*bpt
)
784 return (bpt
->type
== bp_hardware_watchpoint
785 || bpt
->type
== bp_read_watchpoint
786 || bpt
->type
== bp_access_watchpoint
);
789 /* Find the current value of a watchpoint on EXP. Return the value in
790 *VALP and *RESULTP and the chain of intermediate and final values
791 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
794 If a memory error occurs while evaluating the expression, *RESULTP will
795 be set to NULL. *RESULTP may be a lazy value, if the result could
796 not be read from memory. It is used to determine whether a value
797 is user-specified (we should watch the whole value) or intermediate
798 (we should watch only the bit used to locate the final value).
800 If the final value, or any intermediate value, could not be read
801 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
802 set to any referenced values. *VALP will never be a lazy value.
803 This is the value which we store in struct breakpoint.
805 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
806 value chain. The caller must free the values individually. If
807 VAL_CHAIN is NULL, all generated values will be left on the value
811 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
812 struct value
**resultp
, struct value
**val_chain
)
814 struct value
*mark
, *new_mark
, *result
;
815 volatile struct gdb_exception ex
;
823 /* Evaluate the expression. */
824 mark
= value_mark ();
827 TRY_CATCH (ex
, RETURN_MASK_ALL
)
829 result
= evaluate_expression (exp
);
833 /* Ignore memory errors, we want watchpoints pointing at
834 inaccessible memory to still be created; otherwise, throw the
835 error to some higher catcher. */
841 throw_exception (ex
);
846 new_mark
= value_mark ();
847 if (mark
== new_mark
)
852 /* Make sure it's not lazy, so that after the target stops again we
853 have a non-lazy previous value to compare with. */
855 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
860 /* Return the chain of intermediate values. We use this to
861 decide which addresses to watch. */
862 *val_chain
= new_mark
;
863 value_release_to_mark (mark
);
867 /* Assuming that B is a watchpoint:
868 - Reparse watchpoint expression, if REPARSE is non-zero
869 - Evaluate expression and store the result in B->val
870 - Evaluate the condition if there is one, and store the result
872 - Update the list of values that must be watched in B->loc.
874 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
875 If this is local watchpoint that is out of scope, delete it. */
877 update_watchpoint (struct breakpoint
*b
, int reparse
)
879 int within_current_scope
;
880 struct frame_id saved_frame_id
;
881 struct bp_location
*loc
;
884 /* We don't free locations. They are stored in bp_location_chain and
885 update_global_locations will eventually delete them and remove
886 breakpoints if needed. */
889 if (b
->disposition
== disp_del_at_next_stop
)
892 /* Save the current frame's ID so we can restore it after
893 evaluating the watchpoint expression on its own frame. */
894 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
895 took a frame parameter, so that we didn't have to change the
897 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
899 /* Determine if the watchpoint is within scope. */
900 if (b
->exp_valid_block
== NULL
)
901 within_current_scope
= 1;
904 struct frame_info
*fi
;
905 fi
= frame_find_by_id (b
->watchpoint_frame
);
906 within_current_scope
= (fi
!= NULL
);
907 if (within_current_scope
)
911 if (within_current_scope
&& reparse
)
920 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
921 /* If the meaning of expression itself changed, the old value is
922 no longer relevant. We don't want to report a watchpoint hit
923 to the user when the old value and the new value may actually
924 be completely different objects. */
930 /* If we failed to parse the expression, for example because
931 it refers to a global variable in a not-yet-loaded shared library,
932 don't try to insert watchpoint. We don't automatically delete
933 such watchpoint, though, since failure to parse expression
934 is different from out-of-scope watchpoint. */
935 if (within_current_scope
&& b
->exp
)
937 struct value
*val_chain
, *v
, *result
, *next
;
939 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
941 /* Avoid setting b->val if it's already set. The meaning of
942 b->val is 'the last value' user saw, and we should update
943 it only if we reported that last value to user. As it
944 happens, the code that reports it updates b->val directly. */
951 /* Change the type of breakpoint between hardware assisted or an
952 ordinary watchpoint depending on the hardware support and free
953 hardware slots. REPARSE is set when the inferior is started. */
954 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
957 int i
, mem_cnt
, other_type_used
;
959 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
961 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
964 b
->type
= bp_watchpoint
;
967 int target_resources_ok
= target_can_use_hardware_watchpoint
968 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
969 if (target_resources_ok
<= 0)
970 b
->type
= bp_watchpoint
;
972 b
->type
= bp_hardware_watchpoint
;
976 /* Look at each value on the value chain. */
977 for (v
= val_chain
; v
; v
= next
)
979 /* If it's a memory location, and GDB actually needed
980 its contents to evaluate the expression, then we
981 must watch it. If the first value returned is
982 still lazy, that means an error occurred reading it;
983 watch it anyway in case it becomes readable. */
984 if (VALUE_LVAL (v
) == lval_memory
985 && (v
== val_chain
|| ! value_lazy (v
)))
987 struct type
*vtype
= check_typedef (value_type (v
));
989 /* We only watch structs and arrays if user asked
990 for it explicitly, never if they just happen to
991 appear in the middle of some value chain. */
993 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
994 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
998 struct bp_location
*loc
, **tmp
;
1000 addr
= value_address (v
);
1001 len
= TYPE_LENGTH (value_type (v
));
1003 if (b
->type
== bp_read_watchpoint
)
1005 else if (b
->type
== bp_access_watchpoint
)
1008 loc
= allocate_bp_location (b
);
1009 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1012 loc
->gdbarch
= get_type_arch (value_type (v
));
1013 loc
->address
= addr
;
1015 loc
->watchpoint_type
= type
;
1019 next
= value_next (v
);
1024 /* We just regenerated the list of breakpoint locations.
1025 The new location does not have its condition field set to anything
1026 and therefore, we must always reparse the cond_string, independently
1027 of the value of the reparse flag. */
1028 if (b
->cond_string
!= NULL
)
1030 char *s
= b
->cond_string
;
1031 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1034 else if (!within_current_scope
)
1036 printf_filtered (_("\
1037 Watchpoint %d deleted because the program has left the block \n\
1038 in which its expression is valid.\n"),
1040 if (b
->related_breakpoint
)
1041 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1042 b
->disposition
= disp_del_at_next_stop
;
1045 /* Restore the selected frame. */
1046 select_frame (frame_find_by_id (saved_frame_id
));
1050 /* Returns 1 iff breakpoint location should be
1051 inserted in the inferior. */
1053 should_be_inserted (struct bp_location
*bpt
)
1055 if (!breakpoint_enabled (bpt
->owner
))
1058 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1061 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1064 /* Tracepoints are inserted by the target at a time of its choosing,
1066 if (bpt
->owner
->type
== bp_tracepoint
)
1072 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1073 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1074 and HW_BREAKPOINT_ERROR are used to report problems.
1076 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1077 method for each breakpoint or catchpoint type. */
1079 insert_bp_location (struct bp_location
*bpt
,
1080 struct ui_file
*tmp_error_stream
,
1081 int *disabled_breaks
,
1082 int *hw_breakpoint_error
)
1086 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1089 /* Initialize the target-specific information. */
1090 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1091 bpt
->target_info
.placed_address
= bpt
->address
;
1093 if (bpt
->loc_type
== bp_loc_software_breakpoint
1094 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1096 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1098 /* If the explicitly specified breakpoint type
1099 is not hardware breakpoint, check the memory map to see
1100 if the breakpoint address is in read only memory or not.
1101 Two important cases are:
1102 - location type is not hardware breakpoint, memory
1103 is readonly. We change the type of the location to
1104 hardware breakpoint.
1105 - location type is hardware breakpoint, memory is read-write.
1106 This means we've previously made the location hardware one, but
1107 then the memory map changed, so we undo.
1109 When breakpoints are removed, remove_breakpoints will
1110 use location types we've just set here, the only possible
1111 problem is that memory map has changed during running program,
1112 but it's not going to work anyway with current gdb. */
1113 struct mem_region
*mr
1114 = lookup_mem_region (bpt
->target_info
.placed_address
);
1118 if (automatic_hardware_breakpoints
)
1121 enum bp_loc_type new_type
;
1123 if (mr
->attrib
.mode
!= MEM_RW
)
1124 new_type
= bp_loc_hardware_breakpoint
;
1126 new_type
= bp_loc_software_breakpoint
;
1128 if (new_type
!= bpt
->loc_type
)
1130 static int said
= 0;
1131 bpt
->loc_type
= new_type
;
1134 fprintf_filtered (gdb_stdout
, _("\
1135 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1140 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1141 && mr
->attrib
.mode
!= MEM_RW
)
1142 warning (_("cannot set software breakpoint at readonly address %s"),
1143 paddr (bpt
->address
));
1147 /* First check to see if we have to handle an overlay. */
1148 if (overlay_debugging
== ovly_off
1149 || bpt
->section
== NULL
1150 || !(section_is_overlay (bpt
->section
)))
1152 /* No overlay handling: just set the breakpoint. */
1154 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1155 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1158 val
= target_insert_breakpoint (bpt
->gdbarch
,
1163 /* This breakpoint is in an overlay section.
1164 Shall we set a breakpoint at the LMA? */
1165 if (!overlay_events_enabled
)
1167 /* Yes -- overlay event support is not active,
1168 so we must try to set a breakpoint at the LMA.
1169 This will not work for a hardware breakpoint. */
1170 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1171 warning (_("hardware breakpoint %d not supported in overlay!"),
1172 bpt
->owner
->number
);
1175 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1177 /* Set a software (trap) breakpoint at the LMA. */
1178 bpt
->overlay_target_info
= bpt
->target_info
;
1179 bpt
->overlay_target_info
.placed_address
= addr
;
1180 val
= target_insert_breakpoint (bpt
->gdbarch
,
1181 &bpt
->overlay_target_info
);
1183 fprintf_unfiltered (tmp_error_stream
,
1184 "Overlay breakpoint %d failed: in ROM?\n",
1185 bpt
->owner
->number
);
1188 /* Shall we set a breakpoint at the VMA? */
1189 if (section_is_mapped (bpt
->section
))
1191 /* Yes. This overlay section is mapped into memory. */
1192 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1193 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1196 val
= target_insert_breakpoint (bpt
->gdbarch
,
1201 /* No. This breakpoint will not be inserted.
1202 No error, but do not mark the bp as 'inserted'. */
1209 /* Can't set the breakpoint. */
1210 if (solib_name_from_address (bpt
->address
))
1212 /* See also: disable_breakpoints_in_shlibs. */
1214 bpt
->shlib_disabled
= 1;
1215 if (!*disabled_breaks
)
1217 fprintf_unfiltered (tmp_error_stream
,
1218 "Cannot insert breakpoint %d.\n",
1219 bpt
->owner
->number
);
1220 fprintf_unfiltered (tmp_error_stream
,
1221 "Temporarily disabling shared library breakpoints:\n");
1223 *disabled_breaks
= 1;
1224 fprintf_unfiltered (tmp_error_stream
,
1225 "breakpoint #%d\n", bpt
->owner
->number
);
1229 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1231 *hw_breakpoint_error
= 1;
1232 fprintf_unfiltered (tmp_error_stream
,
1233 "Cannot insert hardware breakpoint %d.\n",
1234 bpt
->owner
->number
);
1238 fprintf_unfiltered (tmp_error_stream
,
1239 "Cannot insert breakpoint %d.\n",
1240 bpt
->owner
->number
);
1241 fprintf_filtered (tmp_error_stream
,
1242 "Error accessing memory address ");
1243 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1244 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1245 safe_strerror (val
));
1256 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1257 /* NOTE drow/2003-09-08: This state only exists for removing
1258 watchpoints. It's not clear that it's necessary... */
1259 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1261 val
= target_insert_watchpoint (bpt
->address
,
1263 bpt
->watchpoint_type
);
1264 bpt
->inserted
= (val
!= -1);
1267 else if (bpt
->owner
->type
== bp_catchpoint
)
1269 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1270 bpt
->owner
, RETURN_MASK_ERROR
);
1271 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1272 bpt
->owner
->number
);
1274 bpt
->owner
->enable_state
= bp_disabled
;
1278 /* We've already printed an error message if there was a problem
1279 inserting this catchpoint, and we've disabled the catchpoint,
1280 so just return success. */
1287 /* Make sure all breakpoints are inserted in inferior.
1288 Throws exception on any error.
1289 A breakpoint that is already inserted won't be inserted
1290 again, so calling this function twice is safe. */
1292 insert_breakpoints (void)
1294 struct breakpoint
*bpt
;
1296 ALL_BREAKPOINTS (bpt
)
1297 if (is_hardware_watchpoint (bpt
))
1298 update_watchpoint (bpt
, 0 /* don't reparse. */);
1300 update_global_location_list (1);
1302 /* update_global_location_list does not insert breakpoints when
1303 always_inserted_mode is not enabled. Explicitly insert them
1305 if (!breakpoints_always_inserted_mode ())
1306 insert_breakpoint_locations ();
1309 /* insert_breakpoints is used when starting or continuing the program.
1310 remove_breakpoints is used when the program stops.
1311 Both return zero if successful,
1312 or an `errno' value if could not write the inferior. */
1315 insert_breakpoint_locations (void)
1317 struct breakpoint
*bpt
;
1318 struct bp_location
*b
, *temp
;
1321 int disabled_breaks
= 0;
1322 int hw_breakpoint_error
= 0;
1324 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1325 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1327 /* Explicitly mark the warning -- this will only be printed if
1328 there was an error. */
1329 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1331 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1333 if (!should_be_inserted (b
) || b
->inserted
)
1336 /* There is no point inserting thread-specific breakpoints if the
1337 thread no longer exists. */
1338 if (b
->owner
->thread
!= -1
1339 && !valid_thread_id (b
->owner
->thread
))
1342 val
= insert_bp_location (b
, tmp_error_stream
,
1344 &hw_breakpoint_error
);
1349 /* If we failed to insert all locations of a watchpoint,
1350 remove them, as half-inserted watchpoint is of limited use. */
1351 ALL_BREAKPOINTS (bpt
)
1353 int some_failed
= 0;
1354 struct bp_location
*loc
;
1356 if (!is_hardware_watchpoint (bpt
))
1359 if (!breakpoint_enabled (bpt
))
1362 if (bpt
->disposition
== disp_del_at_next_stop
)
1365 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1373 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1375 remove_breakpoint (loc
, mark_uninserted
);
1377 hw_breakpoint_error
= 1;
1378 fprintf_unfiltered (tmp_error_stream
,
1379 "Could not insert hardware watchpoint %d.\n",
1387 /* If a hardware breakpoint or watchpoint was inserted, add a
1388 message about possibly exhausted resources. */
1389 if (hw_breakpoint_error
)
1391 fprintf_unfiltered (tmp_error_stream
,
1392 "Could not insert hardware breakpoints:\n\
1393 You may have requested too many hardware breakpoints/watchpoints.\n");
1395 target_terminal_ours_for_output ();
1396 error_stream (tmp_error_stream
);
1399 do_cleanups (cleanups
);
1403 remove_breakpoints (void)
1405 struct bp_location
*b
;
1408 ALL_BP_LOCATIONS (b
)
1412 val
= remove_breakpoint (b
, mark_uninserted
);
1421 remove_hw_watchpoints (void)
1423 struct bp_location
*b
;
1426 ALL_BP_LOCATIONS (b
)
1428 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1430 val
= remove_breakpoint (b
, mark_uninserted
);
1439 reattach_breakpoints (int pid
)
1441 struct bp_location
*b
;
1443 struct cleanup
*old_chain
= save_inferior_ptid ();
1444 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1445 int dummy1
= 0, dummy2
= 0;
1447 make_cleanup_ui_file_delete (tmp_error_stream
);
1449 inferior_ptid
= pid_to_ptid (pid
);
1450 ALL_BP_LOCATIONS (b
)
1455 val
= insert_bp_location (b
, tmp_error_stream
,
1459 do_cleanups (old_chain
);
1464 do_cleanups (old_chain
);
1468 static int internal_breakpoint_number
= -1;
1470 static struct breakpoint
*
1471 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1472 CORE_ADDR address
, enum bptype type
)
1474 struct symtab_and_line sal
;
1475 struct breakpoint
*b
;
1477 init_sal (&sal
); /* initialize to zeroes */
1480 sal
.section
= find_pc_overlay (sal
.pc
);
1482 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1483 b
->number
= internal_breakpoint_number
--;
1484 b
->disposition
= disp_donttouch
;
1490 create_overlay_event_breakpoint (char *func_name
)
1492 struct objfile
*objfile
;
1494 ALL_OBJFILES (objfile
)
1496 struct breakpoint
*b
;
1497 struct minimal_symbol
*m
;
1499 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1503 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1504 SYMBOL_VALUE_ADDRESS (m
),
1506 b
->addr_string
= xstrdup (func_name
);
1508 if (overlay_debugging
== ovly_auto
)
1510 b
->enable_state
= bp_enabled
;
1511 overlay_events_enabled
= 1;
1515 b
->enable_state
= bp_disabled
;
1516 overlay_events_enabled
= 0;
1519 update_global_location_list (1);
1523 create_longjmp_master_breakpoint (char *func_name
)
1525 struct objfile
*objfile
;
1527 ALL_OBJFILES (objfile
)
1529 struct breakpoint
*b
;
1530 struct minimal_symbol
*m
;
1532 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1535 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1539 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1540 SYMBOL_VALUE_ADDRESS (m
),
1542 b
->addr_string
= xstrdup (func_name
);
1543 b
->enable_state
= bp_disabled
;
1545 update_global_location_list (1);
1549 update_breakpoints_after_exec (void)
1551 struct breakpoint
*b
;
1552 struct breakpoint
*temp
;
1553 struct bp_location
*bploc
;
1555 /* We're about to delete breakpoints from GDB's lists. If the
1556 INSERTED flag is true, GDB will try to lift the breakpoints by
1557 writing the breakpoints' "shadow contents" back into memory. The
1558 "shadow contents" are NOT valid after an exec, so GDB should not
1559 do that. Instead, the target is responsible from marking
1560 breakpoints out as soon as it detects an exec. We don't do that
1561 here instead, because there may be other attempts to delete
1562 breakpoints after detecting an exec and before reaching here. */
1563 ALL_BP_LOCATIONS (bploc
)
1564 gdb_assert (!bploc
->inserted
);
1566 ALL_BREAKPOINTS_SAFE (b
, temp
)
1568 /* Solib breakpoints must be explicitly reset after an exec(). */
1569 if (b
->type
== bp_shlib_event
)
1571 delete_breakpoint (b
);
1575 /* Thread event breakpoints must be set anew after an exec(),
1576 as must overlay event and longjmp master breakpoints. */
1577 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1578 || b
->type
== bp_longjmp_master
)
1580 delete_breakpoint (b
);
1584 /* Step-resume breakpoints are meaningless after an exec(). */
1585 if (b
->type
== bp_step_resume
)
1587 delete_breakpoint (b
);
1591 /* Longjmp and longjmp-resume breakpoints are also meaningless
1593 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1595 delete_breakpoint (b
);
1599 if (b
->type
== bp_catchpoint
)
1601 /* For now, none of the bp_catchpoint breakpoints need to
1602 do anything at this point. In the future, if some of
1603 the catchpoints need to something, we will need to add
1604 a new method, and call this method from here. */
1608 /* bp_finish is a special case. The only way we ought to be able
1609 to see one of these when an exec() has happened, is if the user
1610 caught a vfork, and then said "finish". Ordinarily a finish just
1611 carries them to the call-site of the current callee, by setting
1612 a temporary bp there and resuming. But in this case, the finish
1613 will carry them entirely through the vfork & exec.
1615 We don't want to allow a bp_finish to remain inserted now. But
1616 we can't safely delete it, 'cause finish_command has a handle to
1617 the bp on a bpstat, and will later want to delete it. There's a
1618 chance (and I've seen it happen) that if we delete the bp_finish
1619 here, that its storage will get reused by the time finish_command
1620 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1621 We really must allow finish_command to delete a bp_finish.
1623 In the absense of a general solution for the "how do we know
1624 it's safe to delete something others may have handles to?"
1625 problem, what we'll do here is just uninsert the bp_finish, and
1626 let finish_command delete it.
1628 (We know the bp_finish is "doomed" in the sense that it's
1629 momentary, and will be deleted as soon as finish_command sees
1630 the inferior stopped. So it doesn't matter that the bp's
1631 address is probably bogus in the new a.out, unlike e.g., the
1632 solib breakpoints.) */
1634 if (b
->type
== bp_finish
)
1639 /* Without a symbolic address, we have little hope of the
1640 pre-exec() address meaning the same thing in the post-exec()
1642 if (b
->addr_string
== NULL
)
1644 delete_breakpoint (b
);
1648 /* FIXME what about longjmp breakpoints? Re-create them here? */
1649 create_overlay_event_breakpoint ("_ovly_debug_event");
1650 create_longjmp_master_breakpoint ("longjmp");
1651 create_longjmp_master_breakpoint ("_longjmp");
1652 create_longjmp_master_breakpoint ("siglongjmp");
1653 create_longjmp_master_breakpoint ("_siglongjmp");
1657 detach_breakpoints (int pid
)
1659 struct bp_location
*b
;
1661 struct cleanup
*old_chain
= save_inferior_ptid ();
1663 if (pid
== PIDGET (inferior_ptid
))
1664 error (_("Cannot detach breakpoints of inferior_ptid"));
1666 /* Set inferior_ptid; remove_breakpoint uses this global. */
1667 inferior_ptid
= pid_to_ptid (pid
);
1668 ALL_BP_LOCATIONS (b
)
1672 val
= remove_breakpoint (b
, mark_inserted
);
1675 do_cleanups (old_chain
);
1680 do_cleanups (old_chain
);
1685 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1689 if (b
->owner
->enable_state
== bp_permanent
)
1690 /* Permanent breakpoints cannot be inserted or removed. */
1693 /* The type of none suggests that owner is actually deleted.
1694 This should not ever happen. */
1695 gdb_assert (b
->owner
->type
!= bp_none
);
1697 if (b
->loc_type
== bp_loc_software_breakpoint
1698 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1700 /* "Normal" instruction breakpoint: either the standard
1701 trap-instruction bp (bp_breakpoint), or a
1702 bp_hardware_breakpoint. */
1704 /* First check to see if we have to handle an overlay. */
1705 if (overlay_debugging
== ovly_off
1706 || b
->section
== NULL
1707 || !(section_is_overlay (b
->section
)))
1709 /* No overlay handling: just remove the breakpoint. */
1711 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1712 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
1714 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
1718 /* This breakpoint is in an overlay section.
1719 Did we set a breakpoint at the LMA? */
1720 if (!overlay_events_enabled
)
1722 /* Yes -- overlay event support is not active, so we
1723 should have set a breakpoint at the LMA. Remove it.
1725 /* Ignore any failures: if the LMA is in ROM, we will
1726 have already warned when we failed to insert it. */
1727 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1728 target_remove_hw_breakpoint (b
->gdbarch
,
1729 &b
->overlay_target_info
);
1731 target_remove_breakpoint (b
->gdbarch
,
1732 &b
->overlay_target_info
);
1734 /* Did we set a breakpoint at the VMA?
1735 If so, we will have marked the breakpoint 'inserted'. */
1738 /* Yes -- remove it. Previously we did not bother to
1739 remove the breakpoint if the section had been
1740 unmapped, but let's not rely on that being safe. We
1741 don't know what the overlay manager might do. */
1742 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1743 val
= target_remove_hw_breakpoint (b
->gdbarch
,
1746 /* However, we should remove *software* breakpoints only
1747 if the section is still mapped, or else we overwrite
1748 wrong code with the saved shadow contents. */
1749 else if (section_is_mapped (b
->section
))
1750 val
= target_remove_breakpoint (b
->gdbarch
,
1757 /* No -- not inserted, so no need to remove. No error. */
1762 /* In some cases, we might not be able to remove a breakpoint
1763 in a shared library that has already been removed, but we
1764 have not yet processed the shlib unload event. */
1765 if (val
&& solib_name_from_address (b
->address
))
1770 b
->inserted
= (is
== mark_inserted
);
1772 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1777 b
->inserted
= (is
== mark_inserted
);
1778 val
= target_remove_watchpoint (b
->address
, b
->length
,
1779 b
->watchpoint_type
);
1781 /* Failure to remove any of the hardware watchpoints comes here. */
1782 if ((is
== mark_uninserted
) && (b
->inserted
))
1783 warning (_("Could not remove hardware watchpoint %d."),
1786 else if (b
->owner
->type
== bp_catchpoint
1787 && breakpoint_enabled (b
->owner
)
1790 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1792 val
= b
->owner
->ops
->remove (b
->owner
);
1795 b
->inserted
= (is
== mark_inserted
);
1801 /* Clear the "inserted" flag in all breakpoints. */
1804 mark_breakpoints_out (void)
1806 struct bp_location
*bpt
;
1808 ALL_BP_LOCATIONS (bpt
)
1812 /* Clear the "inserted" flag in all breakpoints and delete any
1813 breakpoints which should go away between runs of the program.
1815 Plus other such housekeeping that has to be done for breakpoints
1818 Note: this function gets called at the end of a run (by
1819 generic_mourn_inferior) and when a run begins (by
1820 init_wait_for_inferior). */
1825 breakpoint_init_inferior (enum inf_context context
)
1827 struct breakpoint
*b
, *temp
;
1828 struct bp_location
*bpt
;
1831 /* If breakpoint locations are shared across processes, then there's
1833 if (gdbarch_has_global_breakpoints (target_gdbarch
))
1836 ALL_BP_LOCATIONS (bpt
)
1837 if (bpt
->owner
->enable_state
!= bp_permanent
)
1840 ALL_BREAKPOINTS_SAFE (b
, temp
)
1845 case bp_watchpoint_scope
:
1847 /* If the call dummy breakpoint is at the entry point it will
1848 cause problems when the inferior is rerun, so we better
1851 Also get rid of scope breakpoints. */
1852 delete_breakpoint (b
);
1856 case bp_hardware_watchpoint
:
1857 case bp_read_watchpoint
:
1858 case bp_access_watchpoint
:
1860 /* Likewise for watchpoints on local expressions. */
1861 if (b
->exp_valid_block
!= NULL
)
1862 delete_breakpoint (b
);
1863 else if (context
== inf_starting
)
1865 /* Reset val field to force reread of starting value
1866 in insert_breakpoints. */
1868 value_free (b
->val
);
1878 /* Get rid of the moribund locations. */
1879 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1880 free_bp_location (bpt
);
1881 VEC_free (bp_location_p
, moribund_locations
);
1884 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1885 exists at PC. It returns ordinary_breakpoint_here if it's an
1886 ordinary breakpoint, or permanent_breakpoint_here if it's a
1887 permanent breakpoint.
1888 - When continuing from a location with an ordinary breakpoint, we
1889 actually single step once before calling insert_breakpoints.
1890 - When continuing from a localion with a permanent breakpoint, we
1891 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1892 the target, to advance the PC past the breakpoint. */
1894 enum breakpoint_here
1895 breakpoint_here_p (CORE_ADDR pc
)
1897 const struct bp_location
*bpt
;
1898 int any_breakpoint_here
= 0;
1900 ALL_BP_LOCATIONS (bpt
)
1902 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1903 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1906 if ((breakpoint_enabled (bpt
->owner
)
1907 || bpt
->owner
->enable_state
== bp_permanent
)
1908 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1910 if (overlay_debugging
1911 && section_is_overlay (bpt
->section
)
1912 && !section_is_mapped (bpt
->section
))
1913 continue; /* unmapped overlay -- can't be a match */
1914 else if (bpt
->owner
->enable_state
== bp_permanent
)
1915 return permanent_breakpoint_here
;
1917 any_breakpoint_here
= 1;
1921 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1924 /* Return true if there's a moribund breakpoint at PC. */
1927 moribund_breakpoint_here_p (CORE_ADDR pc
)
1929 struct bp_location
*loc
;
1932 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1933 if (loc
->address
== pc
)
1939 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1940 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1941 This does not check for single-step breakpoints, which are
1942 inserted and removed using direct target manipulation. */
1945 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1947 const struct bp_location
*bpt
;
1949 ALL_BP_LOCATIONS (bpt
)
1951 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1952 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1956 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1958 if (overlay_debugging
1959 && section_is_overlay (bpt
->section
)
1960 && !section_is_mapped (bpt
->section
))
1961 continue; /* unmapped overlay -- can't be a match */
1969 /* Returns non-zero iff there's either regular breakpoint
1970 or a single step breakpoint inserted at PC. */
1973 breakpoint_inserted_here_p (CORE_ADDR pc
)
1975 if (regular_breakpoint_inserted_here_p (pc
))
1978 if (single_step_breakpoint_inserted_here_p (pc
))
1984 /* This function returns non-zero iff there is a software breakpoint
1988 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1990 const struct bp_location
*bpt
;
1991 int any_breakpoint_here
= 0;
1993 ALL_BP_LOCATIONS (bpt
)
1995 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1999 && bpt
->address
== pc
) /* bp is enabled and matches pc */
2001 if (overlay_debugging
2002 && section_is_overlay (bpt
->section
)
2003 && !section_is_mapped (bpt
->section
))
2004 continue; /* unmapped overlay -- can't be a match */
2010 /* Also check for software single-step breakpoints. */
2011 if (single_step_breakpoint_inserted_here_p (pc
))
2017 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2018 PC is valid for process/thread PTID. */
2021 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
2023 const struct bp_location
*bpt
;
2024 /* The thread and task IDs associated to PTID, computed lazily. */
2028 ALL_BP_LOCATIONS (bpt
)
2030 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2031 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2034 if (!breakpoint_enabled (bpt
->owner
)
2035 && bpt
->owner
->enable_state
!= bp_permanent
)
2038 if (bpt
->address
!= pc
)
2041 if (bpt
->owner
->thread
!= -1)
2043 /* This is a thread-specific breakpoint. Check that ptid
2044 matches that thread. If thread hasn't been computed yet,
2045 it is now time to do so. */
2047 thread
= pid_to_thread_id (ptid
);
2048 if (bpt
->owner
->thread
!= thread
)
2052 if (bpt
->owner
->task
!= 0)
2054 /* This is a task-specific breakpoint. Check that ptid
2055 matches that task. If task hasn't been computed yet,
2056 it is now time to do so. */
2058 task
= ada_get_task_number (ptid
);
2059 if (bpt
->owner
->task
!= task
)
2063 if (overlay_debugging
2064 && section_is_overlay (bpt
->section
)
2065 && !section_is_mapped (bpt
->section
))
2066 continue; /* unmapped overlay -- can't be a match */
2075 /* bpstat stuff. External routines' interfaces are documented
2079 ep_is_catchpoint (struct breakpoint
*ep
)
2081 return (ep
->type
== bp_catchpoint
);
2085 bpstat_free (bpstat bs
)
2087 if (bs
->old_val
!= NULL
)
2088 value_free (bs
->old_val
);
2089 free_command_lines (&bs
->commands
);
2093 /* Clear a bpstat so that it says we are not at any breakpoint.
2094 Also free any storage that is part of a bpstat. */
2097 bpstat_clear (bpstat
*bsp
)
2114 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2115 is part of the bpstat is copied as well. */
2118 bpstat_copy (bpstat bs
)
2122 bpstat retval
= NULL
;
2127 for (; bs
!= NULL
; bs
= bs
->next
)
2129 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2130 memcpy (tmp
, bs
, sizeof (*tmp
));
2131 if (bs
->commands
!= NULL
)
2132 tmp
->commands
= copy_command_lines (bs
->commands
);
2133 if (bs
->old_val
!= NULL
)
2135 tmp
->old_val
= value_copy (bs
->old_val
);
2136 release_value (tmp
->old_val
);
2140 /* This is the first thing in the chain. */
2150 /* Find the bpstat associated with this breakpoint */
2153 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2158 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2160 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2166 /* Find a step_resume breakpoint associated with this bpstat.
2167 (If there are multiple step_resume bp's on the list, this function
2168 will arbitrarily pick one.)
2170 It is an error to use this function if BPSTAT doesn't contain a
2171 step_resume breakpoint.
2173 See wait_for_inferior's use of this function. */
2175 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2179 gdb_assert (bsp
!= NULL
);
2181 current_thread
= pid_to_thread_id (inferior_ptid
);
2183 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2185 if ((bsp
->breakpoint_at
!= NULL
)
2186 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2187 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2188 || bsp
->breakpoint_at
->owner
->thread
== -1))
2189 return bsp
->breakpoint_at
->owner
;
2192 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2196 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2197 at. *BSP upon return is a bpstat which points to the remaining
2198 breakpoints stopped at (but which is not guaranteed to be good for
2199 anything but further calls to bpstat_num).
2200 Return 0 if passed a bpstat which does not indicate any breakpoints.
2201 Return -1 if stopped at a breakpoint that has been deleted since
2203 Return 1 otherwise. */
2206 bpstat_num (bpstat
*bsp
, int *num
)
2208 struct breakpoint
*b
;
2211 return 0; /* No more breakpoint values */
2213 /* We assume we'll never have several bpstats that
2214 correspond to a single breakpoint -- otherwise,
2215 this function might return the same number more
2216 than once and this will look ugly. */
2217 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2218 *bsp
= (*bsp
)->next
;
2220 return -1; /* breakpoint that's been deleted since */
2222 *num
= b
->number
; /* We have its number */
2226 /* Modify BS so that the actions will not be performed. */
2229 bpstat_clear_actions (bpstat bs
)
2231 for (; bs
!= NULL
; bs
= bs
->next
)
2233 free_command_lines (&bs
->commands
);
2234 if (bs
->old_val
!= NULL
)
2236 value_free (bs
->old_val
);
2242 /* Called when a command is about to proceed the inferior. */
2245 breakpoint_about_to_proceed (void)
2247 if (!ptid_equal (inferior_ptid
, null_ptid
))
2249 struct thread_info
*tp
= inferior_thread ();
2251 /* Allow inferior function calls in breakpoint commands to not
2252 interrupt the command list. When the call finishes
2253 successfully, the inferior will be standing at the same
2254 breakpoint as if nothing happened. */
2259 breakpoint_proceeded
= 1;
2262 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2264 cleanup_executing_breakpoints (void *ignore
)
2266 executing_breakpoint_commands
= 0;
2269 /* Execute all the commands associated with all the breakpoints at this
2270 location. Any of these commands could cause the process to proceed
2271 beyond this point, etc. We look out for such changes by checking
2272 the global "breakpoint_proceeded" after each command.
2274 Returns true if a breakpoint command resumed the inferior. In that
2275 case, it is the caller's responsibility to recall it again with the
2276 bpstat of the current thread. */
2279 bpstat_do_actions_1 (bpstat
*bsp
)
2282 struct cleanup
*old_chain
;
2285 /* Avoid endless recursion if a `source' command is contained
2287 if (executing_breakpoint_commands
)
2290 executing_breakpoint_commands
= 1;
2291 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2293 /* This pointer will iterate over the list of bpstat's. */
2296 breakpoint_proceeded
= 0;
2297 for (; bs
!= NULL
; bs
= bs
->next
)
2299 struct command_line
*cmd
;
2300 struct cleanup
*this_cmd_tree_chain
;
2302 /* Take ownership of the BSP's command tree, if it has one.
2304 The command tree could legitimately contain commands like
2305 'step' and 'next', which call clear_proceed_status, which
2306 frees stop_bpstat's command tree. To make sure this doesn't
2307 free the tree we're executing out from under us, we need to
2308 take ownership of the tree ourselves. Since a given bpstat's
2309 commands are only executed once, we don't need to copy it; we
2310 can clear the pointer in the bpstat, and make sure we free
2311 the tree when we're done. */
2314 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2318 execute_control_command (cmd
);
2320 if (breakpoint_proceeded
)
2326 /* We can free this command tree now. */
2327 do_cleanups (this_cmd_tree_chain
);
2329 if (breakpoint_proceeded
)
2331 if (target_can_async_p ())
2332 /* If we are in async mode, then the target might be still
2333 running, not stopped at any breakpoint, so nothing for
2334 us to do here -- just return to the event loop. */
2337 /* In sync mode, when execute_control_command returns
2338 we're already standing on the next breakpoint.
2339 Breakpoint commands for that stop were not run, since
2340 execute_command does not run breakpoint commands --
2341 only command_line_handler does, but that one is not
2342 involved in execution of breakpoint commands. So, we
2343 can now execute breakpoint commands. It should be
2344 noted that making execute_command do bpstat actions is
2345 not an option -- in this case we'll have recursive
2346 invocation of bpstat for each breakpoint with a
2347 command, and can easily blow up GDB stack. Instead, we
2348 return true, which will trigger the caller to recall us
2349 with the new stop_bpstat. */
2354 do_cleanups (old_chain
);
2359 bpstat_do_actions (void)
2361 /* Do any commands attached to breakpoint we are stopped at. */
2362 while (!ptid_equal (inferior_ptid
, null_ptid
)
2363 && target_has_execution
2364 && !is_exited (inferior_ptid
)
2365 && !is_executing (inferior_ptid
))
2366 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2367 and only return when it is stopped at the next breakpoint, we
2368 keep doing breakpoint actions until it returns false to
2369 indicate the inferior was not resumed. */
2370 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2374 /* Print out the (old or new) value associated with a watchpoint. */
2377 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2380 fprintf_unfiltered (stream
, _("<unreadable>"));
2383 struct value_print_options opts
;
2384 get_user_print_options (&opts
);
2385 value_print (val
, stream
, &opts
);
2389 /* This is the normal print function for a bpstat. In the future,
2390 much of this logic could (should?) be moved to bpstat_stop_status,
2391 by having it set different print_it values.
2393 Current scheme: When we stop, bpstat_print() is called. It loops
2394 through the bpstat list of things causing this stop, calling the
2395 print_bp_stop_message function on each one. The behavior of the
2396 print_bp_stop_message function depends on the print_it field of
2397 bpstat. If such field so indicates, call this function here.
2399 Return values from this routine (ultimately used by bpstat_print()
2400 and normal_stop() to decide what to do):
2401 PRINT_NOTHING: Means we already printed all we needed to print,
2402 don't print anything else.
2403 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2404 that something to be followed by a location.
2405 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2406 that something to be followed by a location.
2407 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2410 static enum print_stop_action
2411 print_it_typical (bpstat bs
)
2413 struct cleanup
*old_chain
;
2414 struct breakpoint
*b
;
2415 const struct bp_location
*bl
;
2416 struct ui_stream
*stb
;
2418 enum print_stop_action result
;
2420 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2421 which has since been deleted. */
2422 if (bs
->breakpoint_at
== NULL
)
2423 return PRINT_UNKNOWN
;
2424 bl
= bs
->breakpoint_at
;
2427 stb
= ui_out_stream_new (uiout
);
2428 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2433 case bp_hardware_breakpoint
:
2434 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2435 if (bl
->address
!= bl
->requested_address
)
2436 breakpoint_adjustment_warning (bl
->requested_address
,
2439 annotate_breakpoint (b
->number
);
2441 ui_out_text (uiout
, "\nTemporary breakpoint ");
2443 ui_out_text (uiout
, "\nBreakpoint ");
2444 if (ui_out_is_mi_like_p (uiout
))
2446 ui_out_field_string (uiout
, "reason",
2447 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2448 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2450 ui_out_field_int (uiout
, "bkptno", b
->number
);
2451 ui_out_text (uiout
, ", ");
2452 result
= PRINT_SRC_AND_LOC
;
2455 case bp_shlib_event
:
2456 /* Did we stop because the user set the stop_on_solib_events
2457 variable? (If so, we report this as a generic, "Stopped due
2458 to shlib event" message.) */
2459 printf_filtered (_("Stopped due to shared library event\n"));
2460 result
= PRINT_NOTHING
;
2463 case bp_thread_event
:
2464 /* Not sure how we will get here.
2465 GDB should not stop for these breakpoints. */
2466 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2467 result
= PRINT_NOTHING
;
2470 case bp_overlay_event
:
2471 /* By analogy with the thread event, GDB should not stop for these. */
2472 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2473 result
= PRINT_NOTHING
;
2476 case bp_longjmp_master
:
2477 /* These should never be enabled. */
2478 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2479 result
= PRINT_NOTHING
;
2483 case bp_hardware_watchpoint
:
2484 annotate_watchpoint (b
->number
);
2485 if (ui_out_is_mi_like_p (uiout
))
2488 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2490 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2491 ui_out_text (uiout
, "\nOld value = ");
2492 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2493 ui_out_field_stream (uiout
, "old", stb
);
2494 ui_out_text (uiout
, "\nNew value = ");
2495 watchpoint_value_print (b
->val
, stb
->stream
);
2496 ui_out_field_stream (uiout
, "new", stb
);
2497 ui_out_text (uiout
, "\n");
2498 /* More than one watchpoint may have been triggered. */
2499 result
= PRINT_UNKNOWN
;
2502 case bp_read_watchpoint
:
2503 if (ui_out_is_mi_like_p (uiout
))
2506 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2508 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2509 ui_out_text (uiout
, "\nValue = ");
2510 watchpoint_value_print (b
->val
, stb
->stream
);
2511 ui_out_field_stream (uiout
, "value", stb
);
2512 ui_out_text (uiout
, "\n");
2513 result
= PRINT_UNKNOWN
;
2516 case bp_access_watchpoint
:
2517 if (bs
->old_val
!= NULL
)
2519 annotate_watchpoint (b
->number
);
2520 if (ui_out_is_mi_like_p (uiout
))
2523 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2525 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2526 ui_out_text (uiout
, "\nOld value = ");
2527 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2528 ui_out_field_stream (uiout
, "old", stb
);
2529 ui_out_text (uiout
, "\nNew value = ");
2534 if (ui_out_is_mi_like_p (uiout
))
2537 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2538 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2539 ui_out_text (uiout
, "\nValue = ");
2541 watchpoint_value_print (b
->val
, stb
->stream
);
2542 ui_out_field_stream (uiout
, "new", stb
);
2543 ui_out_text (uiout
, "\n");
2544 result
= PRINT_UNKNOWN
;
2547 /* Fall through, we don't deal with these types of breakpoints
2551 if (ui_out_is_mi_like_p (uiout
))
2554 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2555 result
= PRINT_UNKNOWN
;
2559 if (ui_out_is_mi_like_p (uiout
))
2562 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2563 result
= PRINT_UNKNOWN
;
2568 case bp_longjmp_resume
:
2569 case bp_step_resume
:
2570 case bp_watchpoint_scope
:
2574 result
= PRINT_UNKNOWN
;
2578 do_cleanups (old_chain
);
2582 /* Generic routine for printing messages indicating why we
2583 stopped. The behavior of this function depends on the value
2584 'print_it' in the bpstat structure. Under some circumstances we
2585 may decide not to print anything here and delegate the task to
2588 static enum print_stop_action
2589 print_bp_stop_message (bpstat bs
)
2591 switch (bs
->print_it
)
2594 /* Nothing should be printed for this bpstat entry. */
2595 return PRINT_UNKNOWN
;
2599 /* We still want to print the frame, but we already printed the
2600 relevant messages. */
2601 return PRINT_SRC_AND_LOC
;
2604 case print_it_normal
:
2606 const struct bp_location
*bl
= bs
->breakpoint_at
;
2607 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2609 /* Normal case. Call the breakpoint's print_it method, or
2610 print_it_typical. */
2611 /* FIXME: how breakpoint can ever be NULL here? */
2612 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2613 return b
->ops
->print_it (b
);
2615 return print_it_typical (bs
);
2620 internal_error (__FILE__
, __LINE__
,
2621 _("print_bp_stop_message: unrecognized enum value"));
2626 /* Print a message indicating what happened. This is called from
2627 normal_stop(). The input to this routine is the head of the bpstat
2628 list - a list of the eventpoints that caused this stop. This
2629 routine calls the generic print routine for printing a message
2630 about reasons for stopping. This will print (for example) the
2631 "Breakpoint n," part of the output. The return value of this
2634 PRINT_UNKNOWN: Means we printed nothing
2635 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2636 code to print the location. An example is
2637 "Breakpoint 1, " which should be followed by
2639 PRINT_SRC_ONLY: Means we printed something, but there is no need
2640 to also print the location part of the message.
2641 An example is the catch/throw messages, which
2642 don't require a location appended to the end.
2643 PRINT_NOTHING: We have done some printing and we don't need any
2644 further info to be printed.*/
2646 enum print_stop_action
2647 bpstat_print (bpstat bs
)
2651 /* Maybe another breakpoint in the chain caused us to stop.
2652 (Currently all watchpoints go on the bpstat whether hit or not.
2653 That probably could (should) be changed, provided care is taken
2654 with respect to bpstat_explains_signal). */
2655 for (; bs
; bs
= bs
->next
)
2657 val
= print_bp_stop_message (bs
);
2658 if (val
== PRINT_SRC_ONLY
2659 || val
== PRINT_SRC_AND_LOC
2660 || val
== PRINT_NOTHING
)
2664 /* We reached the end of the chain, or we got a null BS to start
2665 with and nothing was printed. */
2666 return PRINT_UNKNOWN
;
2669 /* Evaluate the expression EXP and return 1 if value is zero.
2670 This is used inside a catch_errors to evaluate the breakpoint condition.
2671 The argument is a "struct expression *" that has been cast to char * to
2672 make it pass through catch_errors. */
2675 breakpoint_cond_eval (void *exp
)
2677 struct value
*mark
= value_mark ();
2678 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2679 value_free_to_mark (mark
);
2683 /* Allocate a new bpstat and chain it to the current one. */
2686 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2690 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2692 bs
->breakpoint_at
= bl
;
2693 /* If the condition is false, etc., don't do the commands. */
2694 bs
->commands
= NULL
;
2696 bs
->print_it
= print_it_normal
;
2700 /* The target has stopped with waitstatus WS. Check if any hardware
2701 watchpoints have triggered, according to the target. */
2704 watchpoints_triggered (struct target_waitstatus
*ws
)
2706 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
2708 struct breakpoint
*b
;
2710 if (!stopped_by_watchpoint
)
2712 /* We were not stopped by a watchpoint. Mark all watchpoints
2713 as not triggered. */
2715 if (b
->type
== bp_hardware_watchpoint
2716 || b
->type
== bp_read_watchpoint
2717 || b
->type
== bp_access_watchpoint
)
2718 b
->watchpoint_triggered
= watch_triggered_no
;
2723 if (!target_stopped_data_address (¤t_target
, &addr
))
2725 /* We were stopped by a watchpoint, but we don't know where.
2726 Mark all watchpoints as unknown. */
2728 if (b
->type
== bp_hardware_watchpoint
2729 || b
->type
== bp_read_watchpoint
2730 || b
->type
== bp_access_watchpoint
)
2731 b
->watchpoint_triggered
= watch_triggered_unknown
;
2733 return stopped_by_watchpoint
;
2736 /* The target could report the data address. Mark watchpoints
2737 affected by this data address as triggered, and all others as not
2741 if (b
->type
== bp_hardware_watchpoint
2742 || b
->type
== bp_read_watchpoint
2743 || b
->type
== bp_access_watchpoint
)
2745 struct bp_location
*loc
;
2748 b
->watchpoint_triggered
= watch_triggered_no
;
2749 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2750 /* Exact match not required. Within range is
2752 if (target_watchpoint_addr_within_range (¤t_target
,
2756 b
->watchpoint_triggered
= watch_triggered_yes
;
2764 /* Possible return values for watchpoint_check (this can't be an enum
2765 because of check_errors). */
2766 /* The watchpoint has been deleted. */
2767 #define WP_DELETED 1
2768 /* The value has changed. */
2769 #define WP_VALUE_CHANGED 2
2770 /* The value has not changed. */
2771 #define WP_VALUE_NOT_CHANGED 3
2773 #define BP_TEMPFLAG 1
2774 #define BP_HARDWAREFLAG 2
2776 /* Check watchpoint condition. */
2779 watchpoint_check (void *p
)
2781 bpstat bs
= (bpstat
) p
;
2782 struct breakpoint
*b
;
2783 struct frame_info
*fr
;
2784 int within_current_scope
;
2786 b
= bs
->breakpoint_at
->owner
;
2788 if (b
->exp_valid_block
== NULL
)
2789 within_current_scope
= 1;
2792 struct frame_info
*frame
= get_current_frame ();
2793 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
2794 CORE_ADDR frame_pc
= get_frame_pc (frame
);
2796 fr
= frame_find_by_id (b
->watchpoint_frame
);
2797 within_current_scope
= (fr
!= NULL
);
2799 /* If we've gotten confused in the unwinder, we might have
2800 returned a frame that can't describe this variable. */
2801 if (within_current_scope
)
2803 struct symbol
*function
;
2805 function
= get_frame_function (fr
);
2806 if (function
== NULL
2807 || !contained_in (b
->exp_valid_block
,
2808 SYMBOL_BLOCK_VALUE (function
)))
2809 within_current_scope
= 0;
2812 /* in_function_epilogue_p() returns a non-zero value if we're still
2813 in the function but the stack frame has already been invalidated.
2814 Since we can't rely on the values of local variables after the
2815 stack has been destroyed, we are treating the watchpoint in that
2816 state as `not changed' without further checking. Don't mark
2817 watchpoints as changed if the current frame is in an epilogue -
2818 even if they are in some other frame, our view of the stack
2819 is likely to be wrong. */
2820 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
2821 return WP_VALUE_NOT_CHANGED
;
2823 if (within_current_scope
)
2824 /* If we end up stopping, the current frame will get selected
2825 in normal_stop. So this call to select_frame won't affect
2830 if (within_current_scope
)
2832 /* We use value_{,free_to_}mark because it could be a
2833 *long* time before we return to the command level and
2834 call free_all_values. We can't call free_all_values because
2835 we might be in the middle of evaluating a function call. */
2837 struct value
*mark
= value_mark ();
2838 struct value
*new_val
;
2840 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2841 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2842 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2844 if (new_val
!= NULL
)
2846 release_value (new_val
);
2847 value_free_to_mark (mark
);
2849 bs
->old_val
= b
->val
;
2852 /* We will stop here */
2853 return WP_VALUE_CHANGED
;
2857 /* Nothing changed, don't do anything. */
2858 value_free_to_mark (mark
);
2859 /* We won't stop here */
2860 return WP_VALUE_NOT_CHANGED
;
2865 /* This seems like the only logical thing to do because
2866 if we temporarily ignored the watchpoint, then when
2867 we reenter the block in which it is valid it contains
2868 garbage (in the case of a function, it may have two
2869 garbage values, one before and one after the prologue).
2870 So we can't even detect the first assignment to it and
2871 watch after that (since the garbage may or may not equal
2872 the first value assigned). */
2873 /* We print all the stop information in print_it_typical(), but
2874 in this case, by the time we call print_it_typical() this bp
2875 will be deleted already. So we have no choice but print the
2876 information here. */
2877 if (ui_out_is_mi_like_p (uiout
))
2879 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2880 ui_out_text (uiout
, "\nWatchpoint ");
2881 ui_out_field_int (uiout
, "wpnum", b
->number
);
2882 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2883 which its expression is valid.\n");
2885 if (b
->related_breakpoint
)
2886 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2887 b
->disposition
= disp_del_at_next_stop
;
2893 /* Return true if it looks like target has stopped due to hitting
2894 breakpoint location BL. This function does not check if we
2895 should stop, only if BL explains the stop. */
2897 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2899 struct breakpoint
*b
= bl
->owner
;
2901 if (b
->type
!= bp_watchpoint
2902 && b
->type
!= bp_hardware_watchpoint
2903 && b
->type
!= bp_read_watchpoint
2904 && b
->type
!= bp_access_watchpoint
2905 && b
->type
!= bp_hardware_breakpoint
2906 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2908 if (bl
->address
!= bp_addr
) /* address doesn't match */
2910 if (overlay_debugging
/* unmapped overlay section */
2911 && section_is_overlay (bl
->section
)
2912 && !section_is_mapped (bl
->section
))
2916 /* Continuable hardware watchpoints are treated as non-existent if the
2917 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2918 some data address). Otherwise gdb won't stop on a break instruction
2919 in the code (not from a breakpoint) when a hardware watchpoint has
2920 been defined. Also skip watchpoints which we know did not trigger
2921 (did not match the data address). */
2923 if ((b
->type
== bp_hardware_watchpoint
2924 || b
->type
== bp_read_watchpoint
2925 || b
->type
== bp_access_watchpoint
)
2926 && b
->watchpoint_triggered
== watch_triggered_no
)
2929 if (b
->type
== bp_hardware_breakpoint
)
2931 if (bl
->address
!= bp_addr
)
2933 if (overlay_debugging
/* unmapped overlay section */
2934 && section_is_overlay (bl
->section
)
2935 && !section_is_mapped (bl
->section
))
2939 if (b
->type
== bp_catchpoint
)
2941 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2942 if (!b
->ops
->breakpoint_hit (b
))
2949 /* If BS refers to a watchpoint, determine if the watched values
2950 has actually changed, and we should stop. If not, set BS->stop
2953 bpstat_check_watchpoint (bpstat bs
)
2955 const struct bp_location
*bl
= bs
->breakpoint_at
;
2956 struct breakpoint
*b
= bl
->owner
;
2958 if (b
->type
== bp_watchpoint
2959 || b
->type
== bp_read_watchpoint
2960 || b
->type
== bp_access_watchpoint
2961 || b
->type
== bp_hardware_watchpoint
)
2965 int must_check_value
= 0;
2967 if (b
->type
== bp_watchpoint
)
2968 /* For a software watchpoint, we must always check the
2970 must_check_value
= 1;
2971 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2972 /* We have a hardware watchpoint (read, write, or access)
2973 and the target earlier reported an address watched by
2975 must_check_value
= 1;
2976 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2977 && b
->type
== bp_hardware_watchpoint
)
2978 /* We were stopped by a hardware watchpoint, but the target could
2979 not report the data address. We must check the watchpoint's
2980 value. Access and read watchpoints are out of luck; without
2981 a data address, we can't figure it out. */
2982 must_check_value
= 1;
2984 if (must_check_value
)
2986 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2988 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2989 int e
= catch_errors (watchpoint_check
, bs
, message
,
2991 do_cleanups (cleanups
);
2995 /* We've already printed what needs to be printed. */
2996 bs
->print_it
= print_it_done
;
2999 case WP_VALUE_CHANGED
:
3000 if (b
->type
== bp_read_watchpoint
)
3002 /* Don't stop: read watchpoints shouldn't fire if
3003 the value has changed. This is for targets
3004 which cannot set read-only watchpoints. */
3005 bs
->print_it
= print_it_noop
;
3009 case WP_VALUE_NOT_CHANGED
:
3010 if (b
->type
== bp_hardware_watchpoint
3011 || b
->type
== bp_watchpoint
)
3013 /* Don't stop: write watchpoints shouldn't fire if
3014 the value hasn't changed. */
3015 bs
->print_it
= print_it_noop
;
3023 /* Error from catch_errors. */
3024 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3025 if (b
->related_breakpoint
)
3026 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3027 b
->disposition
= disp_del_at_next_stop
;
3028 /* We've already printed what needs to be printed. */
3029 bs
->print_it
= print_it_done
;
3033 else /* must_check_value == 0 */
3035 /* This is a case where some watchpoint(s) triggered, but
3036 not at the address of this watchpoint, or else no
3037 watchpoint triggered after all. So don't print
3038 anything for this watchpoint. */
3039 bs
->print_it
= print_it_noop
;
3046 /* Check conditions (condition proper, frame, thread and ignore count)
3047 of breakpoint referred to by BS. If we should not stop for this
3048 breakpoint, set BS->stop to 0. */
3050 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3052 int thread_id
= pid_to_thread_id (ptid
);
3053 const struct bp_location
*bl
= bs
->breakpoint_at
;
3054 struct breakpoint
*b
= bl
->owner
;
3056 if (frame_id_p (b
->frame_id
)
3057 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3061 int value_is_zero
= 0;
3063 /* If this is a scope breakpoint, mark the associated
3064 watchpoint as triggered so that we will handle the
3065 out-of-scope event. We'll get to the watchpoint next
3067 if (b
->type
== bp_watchpoint_scope
)
3068 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3070 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3072 /* We use value_mark and value_free_to_mark because it could
3073 be a long time before we return to the command level and
3074 call free_all_values. We can't call free_all_values
3075 because we might be in the middle of evaluating a
3077 struct value
*mark
= value_mark ();
3079 /* Need to select the frame, with all that implies so that
3080 the conditions will have the right context. Because we
3081 use the frame, we will not see an inlined function's
3082 variables when we arrive at a breakpoint at the start
3083 of the inlined function; the current frame will be the
3085 select_frame (get_current_frame ());
3087 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3088 "Error in testing breakpoint condition:\n",
3090 /* FIXME-someday, should give breakpoint # */
3091 value_free_to_mark (mark
);
3093 if (bl
->cond
&& value_is_zero
)
3097 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3101 else if (b
->ignore_count
> 0)
3104 annotate_ignore_count_change ();
3106 /* Increase the hit count even though we don't
3114 /* Get a bpstat associated with having just stopped at address
3115 BP_ADDR in thread PTID.
3117 Determine whether we stopped at a breakpoint, etc, or whether we
3118 don't understand this stop. Result is a chain of bpstat's such that:
3120 if we don't understand the stop, the result is a null pointer.
3122 if we understand why we stopped, the result is not null.
3124 Each element of the chain refers to a particular breakpoint or
3125 watchpoint at which we have stopped. (We may have stopped for
3126 several reasons concurrently.)
3128 Each element of the chain has valid next, breakpoint_at,
3129 commands, FIXME??? fields. */
3132 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3134 struct breakpoint
*b
= NULL
;
3135 const struct bp_location
*bl
;
3136 struct bp_location
*loc
;
3137 /* Root of the chain of bpstat's */
3138 struct bpstats root_bs
[1];
3139 /* Pointer to the last thing in the chain currently. */
3140 bpstat bs
= root_bs
;
3142 int need_remove_insert
;
3144 ALL_BP_LOCATIONS (bl
)
3148 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3151 /* For hardware watchpoints, we look only at the first location.
3152 The watchpoint_check function will work on entire expression,
3153 not the individual locations. For read watchopints, the
3154 watchpoints_triggered function have checked all locations
3157 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3160 if (!bpstat_check_location (bl
, bp_addr
))
3163 /* Come here if it's a watchpoint, or if the break address matches */
3165 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3167 /* Assume we stop. Should we find watchpoint that is not actually
3168 triggered, or if condition of breakpoint is false, we'll reset
3173 bpstat_check_watchpoint (bs
);
3177 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3178 || b
->type
== bp_longjmp_master
)
3179 /* We do not stop for these. */
3182 bpstat_check_breakpoint_conditions (bs
, ptid
);
3188 /* We will stop here */
3189 if (b
->disposition
== disp_disable
)
3191 if (b
->enable_state
!= bp_permanent
)
3192 b
->enable_state
= bp_disabled
;
3193 update_global_location_list (0);
3197 bs
->commands
= b
->commands
;
3199 && (strcmp ("silent", bs
->commands
->line
) == 0
3200 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3202 bs
->commands
= bs
->commands
->next
;
3205 bs
->commands
= copy_command_lines (bs
->commands
);
3208 /* Print nothing for this entry if we dont stop or if we dont print. */
3209 if (bs
->stop
== 0 || bs
->print
== 0)
3210 bs
->print_it
= print_it_noop
;
3213 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3215 if (loc
->address
== bp_addr
)
3217 bs
= bpstat_alloc (loc
, bs
);
3218 /* For hits of moribund locations, we should just proceed. */
3221 bs
->print_it
= print_it_noop
;
3225 bs
->next
= NULL
; /* Terminate the chain */
3226 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3228 /* If we aren't stopping, the value of some hardware watchpoint may
3229 not have changed, but the intermediate memory locations we are
3230 watching may have. Don't bother if we're stopping; this will get
3232 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3236 need_remove_insert
= 0;
3238 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3240 && bs
->breakpoint_at
->owner
3241 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3242 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3243 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3245 /* remove/insert can invalidate bs->breakpoint_at, if this
3246 location is no longer used by the watchpoint. Prevent
3247 further code from trying to use it. */
3248 bs
->breakpoint_at
= NULL
;
3249 need_remove_insert
= 1;
3252 if (need_remove_insert
)
3254 remove_breakpoints ();
3255 insert_breakpoints ();
3258 return root_bs
->next
;
3261 /* Tell what to do about this bpstat. */
3263 bpstat_what (bpstat bs
)
3265 /* Classify each bpstat as one of the following. */
3268 /* This bpstat element has no effect on the main_action. */
3271 /* There was a watchpoint, stop but don't print. */
3274 /* There was a watchpoint, stop and print. */
3277 /* There was a breakpoint but we're not stopping. */
3280 /* There was a breakpoint, stop but don't print. */
3283 /* There was a breakpoint, stop and print. */
3286 /* We hit the longjmp breakpoint. */
3289 /* We hit the longjmp_resume breakpoint. */
3292 /* We hit the step_resume breakpoint. */
3295 /* We hit the shared library event breakpoint. */
3298 /* This is just used to count how many enums there are. */
3302 /* Here is the table which drives this routine. So that we can
3303 format it pretty, we define some abbreviations for the
3304 enum bpstat_what codes. */
3305 #define kc BPSTAT_WHAT_KEEP_CHECKING
3306 #define ss BPSTAT_WHAT_STOP_SILENT
3307 #define sn BPSTAT_WHAT_STOP_NOISY
3308 #define sgl BPSTAT_WHAT_SINGLE
3309 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3310 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3311 #define sr BPSTAT_WHAT_STEP_RESUME
3312 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3314 /* "Can't happen." Might want to print an error message.
3315 abort() is not out of the question, but chances are GDB is just
3316 a bit confused, not unusable. */
3317 #define err BPSTAT_WHAT_STOP_NOISY
3319 /* Given an old action and a class, come up with a new action. */
3320 /* One interesting property of this table is that wp_silent is the same
3321 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3322 after stopping, the check for whether to step over a breakpoint
3323 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3324 reference to how we stopped. We retain separate wp_silent and
3325 bp_silent codes in case we want to change that someday.
3327 Another possibly interesting property of this table is that
3328 there's a partial ordering, priority-like, of the actions. Once
3329 you've decided that some action is appropriate, you'll never go
3330 back and decide something of a lower priority is better. The
3333 kc < clr sgl shl slr sn sr ss
3334 sgl < shl slr sn sr ss
3335 slr < err shl sn sr ss
3336 clr < err shl sn sr ss
3342 What I think this means is that we don't need a damned table
3343 here. If you just put the rows and columns in the right order,
3344 it'd look awfully regular. We could simply walk the bpstat list
3345 and choose the highest priority action we find, with a little
3346 logic to handle the 'err' cases. */
3348 /* step_resume entries: a step resume breakpoint overrides another
3349 breakpoint of signal handling (see comment in wait_for_inferior
3350 at where we set the step_resume breakpoint). */
3352 static const enum bpstat_what_main_action
3353 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3356 /* kc ss sn sgl slr clr sr shl
3359 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3361 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3363 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3365 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3367 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3369 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3371 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3373 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3375 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3377 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3390 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3391 struct bpstat_what retval
;
3393 retval
.call_dummy
= 0;
3394 for (; bs
!= NULL
; bs
= bs
->next
)
3396 enum class bs_class
= no_effect
;
3397 if (bs
->breakpoint_at
== NULL
)
3398 /* I suspect this can happen if it was a momentary breakpoint
3399 which has since been deleted. */
3401 if (bs
->breakpoint_at
->owner
== NULL
)
3402 bs_class
= bp_nostop
;
3404 switch (bs
->breakpoint_at
->owner
->type
)
3410 case bp_hardware_breakpoint
:
3416 bs_class
= bp_noisy
;
3418 bs_class
= bp_silent
;
3421 bs_class
= bp_nostop
;
3424 case bp_hardware_watchpoint
:
3425 case bp_read_watchpoint
:
3426 case bp_access_watchpoint
:
3430 bs_class
= wp_noisy
;
3432 bs_class
= wp_silent
;
3435 /* There was a watchpoint, but we're not stopping.
3436 This requires no further action. */
3437 bs_class
= no_effect
;
3440 bs_class
= long_jump
;
3442 case bp_longjmp_resume
:
3443 bs_class
= long_resume
;
3445 case bp_step_resume
:
3448 bs_class
= step_resume
;
3451 /* It is for the wrong frame. */
3452 bs_class
= bp_nostop
;
3454 case bp_watchpoint_scope
:
3455 bs_class
= bp_nostop
;
3457 case bp_shlib_event
:
3458 bs_class
= shlib_event
;
3460 case bp_thread_event
:
3461 case bp_overlay_event
:
3462 case bp_longjmp_master
:
3463 bs_class
= bp_nostop
;
3469 bs_class
= bp_noisy
;
3471 bs_class
= bp_silent
;
3474 /* There was a catchpoint, but we're not stopping.
3475 This requires no further action. */
3476 bs_class
= no_effect
;
3479 /* Make sure the action is stop (silent or noisy),
3480 so infrun.c pops the dummy frame. */
3481 bs_class
= bp_silent
;
3482 retval
.call_dummy
= 1;
3485 /* Tracepoint hits should not be reported back to GDB, and
3486 if one got through somehow, it should have been filtered
3488 internal_error (__FILE__
, __LINE__
,
3489 _("bpstat_what: bp_tracepoint encountered"));
3492 current_action
= table
[(int) bs_class
][(int) current_action
];
3494 retval
.main_action
= current_action
;
3498 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3499 without hardware support). This isn't related to a specific bpstat,
3500 just to things like whether watchpoints are set. */
3503 bpstat_should_step (void)
3505 struct breakpoint
*b
;
3507 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3514 static void print_breakpoint_location (struct breakpoint
*b
,
3515 struct bp_location
*loc
,
3517 struct ui_stream
*stb
)
3522 = find_pc_sect_function (loc
->address
, loc
->section
);
3525 ui_out_text (uiout
, "in ");
3526 ui_out_field_string (uiout
, "func",
3527 SYMBOL_PRINT_NAME (sym
));
3528 ui_out_wrap_hint (uiout
, wrap_indent
);
3529 ui_out_text (uiout
, " at ");
3531 ui_out_field_string (uiout
, "file", b
->source_file
);
3532 ui_out_text (uiout
, ":");
3534 if (ui_out_is_mi_like_p (uiout
))
3536 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3537 char *fullname
= symtab_to_fullname (sal
.symtab
);
3540 ui_out_field_string (uiout
, "fullname", fullname
);
3543 ui_out_field_int (uiout
, "line", b
->line_number
);
3547 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3551 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3552 ui_out_field_stream (uiout
, "at", stb
);
3556 /* Print B to gdb_stdout. */
3558 print_one_breakpoint_location (struct breakpoint
*b
,
3559 struct bp_location
*loc
,
3561 struct bp_location
**last_loc
,
3562 int print_address_bits
)
3564 struct command_line
*l
;
3566 struct ep_type_description
3571 static struct ep_type_description bptypes
[] =
3573 {bp_none
, "?deleted?"},
3574 {bp_breakpoint
, "breakpoint"},
3575 {bp_hardware_breakpoint
, "hw breakpoint"},
3576 {bp_until
, "until"},
3577 {bp_finish
, "finish"},
3578 {bp_watchpoint
, "watchpoint"},
3579 {bp_hardware_watchpoint
, "hw watchpoint"},
3580 {bp_read_watchpoint
, "read watchpoint"},
3581 {bp_access_watchpoint
, "acc watchpoint"},
3582 {bp_longjmp
, "longjmp"},
3583 {bp_longjmp_resume
, "longjmp resume"},
3584 {bp_step_resume
, "step resume"},
3585 {bp_watchpoint_scope
, "watchpoint scope"},
3586 {bp_call_dummy
, "call dummy"},
3587 {bp_shlib_event
, "shlib events"},
3588 {bp_thread_event
, "thread events"},
3589 {bp_overlay_event
, "overlay events"},
3590 {bp_longjmp_master
, "longjmp master"},
3591 {bp_catchpoint
, "catchpoint"},
3592 {bp_tracepoint
, "tracepoint"},
3595 static char bpenables
[] = "nynny";
3596 char wrap_indent
[80];
3597 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3598 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3599 struct cleanup
*bkpt_chain
;
3601 int header_of_multiple
= 0;
3602 int part_of_multiple
= (loc
!= NULL
);
3603 struct value_print_options opts
;
3605 get_user_print_options (&opts
);
3607 gdb_assert (!loc
|| loc_number
!= 0);
3608 /* See comment in print_one_breakpoint concerning
3609 treatment of breakpoints with single disabled
3613 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3614 header_of_multiple
= 1;
3619 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3623 if (part_of_multiple
)
3626 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3627 ui_out_field_string (uiout
, "number", formatted
);
3632 ui_out_field_int (uiout
, "number", b
->number
);
3637 if (part_of_multiple
)
3638 ui_out_field_skip (uiout
, "type");
3641 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3642 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3643 internal_error (__FILE__
, __LINE__
,
3644 _("bptypes table does not describe type #%d."),
3646 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3651 if (part_of_multiple
)
3652 ui_out_field_skip (uiout
, "disp");
3654 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3659 if (part_of_multiple
)
3660 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3662 ui_out_field_fmt (uiout
, "enabled", "%c",
3663 bpenables
[(int) b
->enable_state
]);
3664 ui_out_spaces (uiout
, 2);
3668 strcpy (wrap_indent
, " ");
3669 if (opts
.addressprint
)
3671 if (print_address_bits
<= 32)
3672 strcat (wrap_indent
, " ");
3674 strcat (wrap_indent
, " ");
3677 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3679 /* Although the print_one can possibly print
3680 all locations, calling it here is not likely
3681 to get any nice result. So, make sure there's
3682 just one location. */
3683 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3684 b
->ops
->print_one (b
, last_loc
);
3690 internal_error (__FILE__
, __LINE__
,
3691 _("print_one_breakpoint: bp_none encountered\n"));
3695 case bp_hardware_watchpoint
:
3696 case bp_read_watchpoint
:
3697 case bp_access_watchpoint
:
3698 /* Field 4, the address, is omitted (which makes the columns
3699 not line up too nicely with the headers, but the effect
3700 is relatively readable). */
3701 if (opts
.addressprint
)
3702 ui_out_field_skip (uiout
, "addr");
3704 ui_out_field_string (uiout
, "what", b
->exp_string
);
3708 case bp_hardware_breakpoint
:
3712 case bp_longjmp_resume
:
3713 case bp_step_resume
:
3714 case bp_watchpoint_scope
:
3716 case bp_shlib_event
:
3717 case bp_thread_event
:
3718 case bp_overlay_event
:
3719 case bp_longjmp_master
:
3721 if (opts
.addressprint
)
3724 if (header_of_multiple
)
3725 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3726 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3727 ui_out_field_string (uiout
, "addr", "<PENDING>");
3729 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3732 if (!header_of_multiple
)
3733 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3739 if (!part_of_multiple
)
3741 if (b
->thread
!= -1)
3743 /* FIXME: This seems to be redundant and lost here; see the
3744 "stop only in" line a little further down. */
3745 ui_out_text (uiout
, " thread ");
3746 ui_out_field_int (uiout
, "thread", b
->thread
);
3748 else if (b
->task
!= 0)
3750 ui_out_text (uiout
, " task ");
3751 ui_out_field_int (uiout
, "task", b
->task
);
3755 ui_out_text (uiout
, "\n");
3757 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3760 ui_out_text (uiout
, "\tstop only in stack frame at ");
3761 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3763 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3764 ui_out_text (uiout
, "\n");
3767 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3769 /* We do not print the condition for Ada exception catchpoints
3770 because the condition is an internal implementation detail
3771 that we do not want to expose to the user. */
3773 if (b
->type
== bp_tracepoint
)
3774 ui_out_text (uiout
, "\ttrace only if ");
3776 ui_out_text (uiout
, "\tstop only if ");
3777 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3778 ui_out_text (uiout
, "\n");
3781 if (!part_of_multiple
&& b
->thread
!= -1)
3783 /* FIXME should make an annotation for this */
3784 ui_out_text (uiout
, "\tstop only in thread ");
3785 ui_out_field_int (uiout
, "thread", b
->thread
);
3786 ui_out_text (uiout
, "\n");
3789 if (!part_of_multiple
&& b
->hit_count
)
3791 /* FIXME should make an annotation for this */
3792 if (ep_is_catchpoint (b
))
3793 ui_out_text (uiout
, "\tcatchpoint");
3795 ui_out_text (uiout
, "\tbreakpoint");
3796 ui_out_text (uiout
, " already hit ");
3797 ui_out_field_int (uiout
, "times", b
->hit_count
);
3798 if (b
->hit_count
== 1)
3799 ui_out_text (uiout
, " time\n");
3801 ui_out_text (uiout
, " times\n");
3804 /* Output the count also if it is zero, but only if this is
3805 mi. FIXME: Should have a better test for this. */
3806 if (ui_out_is_mi_like_p (uiout
))
3807 if (!part_of_multiple
&& b
->hit_count
== 0)
3808 ui_out_field_int (uiout
, "times", b
->hit_count
);
3810 if (!part_of_multiple
&& b
->ignore_count
)
3813 ui_out_text (uiout
, "\tignore next ");
3814 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3815 ui_out_text (uiout
, " hits\n");
3819 if (!part_of_multiple
&& l
)
3821 struct cleanup
*script_chain
;
3824 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3825 print_command_lines (uiout
, l
, 4);
3826 do_cleanups (script_chain
);
3829 if (!part_of_multiple
&& b
->pass_count
)
3831 annotate_field (10);
3832 ui_out_text (uiout
, "\tpass count ");
3833 ui_out_field_int (uiout
, "pass", b
->pass_count
);
3834 ui_out_text (uiout
, " \n");
3837 if (!part_of_multiple
&& b
->step_count
)
3839 annotate_field (11);
3840 ui_out_text (uiout
, "\tstep count ");
3841 ui_out_field_int (uiout
, "step", b
->step_count
);
3842 ui_out_text (uiout
, " \n");
3845 if (!part_of_multiple
&& b
->actions
)
3847 struct action_line
*action
;
3848 annotate_field (12);
3849 for (action
= b
->actions
; action
; action
= action
->next
)
3851 ui_out_text (uiout
, " A\t");
3852 ui_out_text (uiout
, action
->action
);
3853 ui_out_text (uiout
, "\n");
3857 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3860 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3861 else if (b
->exp_string
)
3862 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3865 do_cleanups (bkpt_chain
);
3866 do_cleanups (old_chain
);
3870 print_one_breakpoint (struct breakpoint
*b
,
3871 struct bp_location
**last_loc
, int print_address_bits
)
3873 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, print_address_bits
);
3875 /* If this breakpoint has custom print function,
3876 it's already printed. Otherwise, print individual
3877 locations, if any. */
3878 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3880 /* If breakpoint has a single location that is
3881 disabled, we print it as if it had
3882 several locations, since otherwise it's hard to
3883 represent "breakpoint enabled, location disabled"
3885 Note that while hardware watchpoints have
3886 several locations internally, that's no a property
3889 && !is_hardware_watchpoint (b
)
3890 && (b
->loc
->next
|| !b
->loc
->enabled
)
3891 && !ui_out_is_mi_like_p (uiout
))
3893 struct bp_location
*loc
;
3895 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3896 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
3897 print_address_bits
);
3903 breakpoint_address_bits (struct breakpoint
*b
)
3905 int print_address_bits
= 0;
3906 struct bp_location
*loc
;
3908 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3910 int addr_bit
= gdbarch_addr_bit (b
->gdbarch
);
3911 if (addr_bit
> print_address_bits
)
3912 print_address_bits
= addr_bit
;
3915 return print_address_bits
;
3918 struct captured_breakpoint_query_args
3924 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3926 struct captured_breakpoint_query_args
*args
= data
;
3927 struct breakpoint
*b
;
3928 struct bp_location
*dummy_loc
= NULL
;
3931 if (args
->bnum
== b
->number
)
3933 int print_address_bits
= breakpoint_address_bits (b
);
3934 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
);
3942 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3944 struct captured_breakpoint_query_args args
;
3946 /* For the moment we don't trust print_one_breakpoint() to not throw
3948 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3949 error_message
, RETURN_MASK_ALL
) < 0)
3955 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3956 catchpoints, et.al.). */
3959 user_settable_breakpoint (const struct breakpoint
*b
)
3961 return (b
->type
== bp_breakpoint
3962 || b
->type
== bp_catchpoint
3963 || b
->type
== bp_hardware_breakpoint
3964 || b
->type
== bp_tracepoint
3965 || b
->type
== bp_watchpoint
3966 || b
->type
== bp_read_watchpoint
3967 || b
->type
== bp_access_watchpoint
3968 || b
->type
== bp_hardware_watchpoint
);
3971 /* Print information on user settable breakpoint (watchpoint, etc)
3972 number BNUM. If BNUM is -1 print all user settable breakpoints.
3973 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3976 breakpoint_1 (int bnum
, int allflag
)
3978 struct breakpoint
*b
;
3979 struct bp_location
*last_loc
= NULL
;
3980 int nr_printable_breakpoints
;
3981 struct cleanup
*bkpttbl_chain
;
3982 struct value_print_options opts
;
3983 int print_address_bits
= 0;
3985 get_user_print_options (&opts
);
3987 /* Compute the number of rows in the table, as well as the
3988 size required for address fields. */
3989 nr_printable_breakpoints
= 0;
3992 || bnum
== b
->number
)
3994 if (allflag
|| user_settable_breakpoint (b
))
3996 int addr_bit
= breakpoint_address_bits (b
);
3997 if (addr_bit
> print_address_bits
)
3998 print_address_bits
= addr_bit
;
4000 nr_printable_breakpoints
++;
4004 if (opts
.addressprint
)
4006 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4010 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4013 if (nr_printable_breakpoints
> 0)
4014 annotate_breakpoints_headers ();
4015 if (nr_printable_breakpoints
> 0)
4017 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4018 if (nr_printable_breakpoints
> 0)
4020 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4021 if (nr_printable_breakpoints
> 0)
4023 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4024 if (nr_printable_breakpoints
> 0)
4026 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4027 if (opts
.addressprint
)
4029 if (nr_printable_breakpoints
> 0)
4031 if (print_address_bits
<= 32)
4032 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4034 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4036 if (nr_printable_breakpoints
> 0)
4038 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4039 ui_out_table_body (uiout
);
4040 if (nr_printable_breakpoints
> 0)
4041 annotate_breakpoints_table ();
4045 || bnum
== b
->number
)
4047 /* We only print out user settable breakpoints unless the
4049 if (allflag
|| user_settable_breakpoint (b
))
4050 print_one_breakpoint (b
, &last_loc
, print_address_bits
);
4053 do_cleanups (bkpttbl_chain
);
4055 if (nr_printable_breakpoints
== 0)
4058 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4060 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4065 if (last_loc
&& !server_command
)
4066 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4069 /* FIXME? Should this be moved up so that it is only called when
4070 there have been breakpoints? */
4071 annotate_breakpoints_table_end ();
4075 breakpoints_info (char *bnum_exp
, int from_tty
)
4080 bnum
= parse_and_eval_long (bnum_exp
);
4082 breakpoint_1 (bnum
, 0);
4086 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4091 bnum
= parse_and_eval_long (bnum_exp
);
4093 breakpoint_1 (bnum
, 1);
4097 breakpoint_has_pc (struct breakpoint
*b
,
4098 CORE_ADDR pc
, struct obj_section
*section
)
4100 struct bp_location
*bl
= b
->loc
;
4101 for (; bl
; bl
= bl
->next
)
4103 if (bl
->address
== pc
4104 && (!overlay_debugging
|| bl
->section
== section
))
4110 /* Print a message describing any breakpoints set at PC. */
4113 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
4117 struct breakpoint
*b
;
4120 others
+= breakpoint_has_pc (b
, pc
, section
);
4124 printf_filtered (_("Note: breakpoint "));
4125 else /* if (others == ???) */
4126 printf_filtered (_("Note: breakpoints "));
4128 if (breakpoint_has_pc (b
, pc
, section
))
4131 printf_filtered ("%d", b
->number
);
4132 if (b
->thread
== -1 && thread
!= -1)
4133 printf_filtered (" (all threads)");
4134 else if (b
->thread
!= -1)
4135 printf_filtered (" (thread %d)", b
->thread
);
4136 printf_filtered ("%s%s ",
4137 ((b
->enable_state
== bp_disabled
4138 || b
->enable_state
== bp_call_disabled
)
4140 : b
->enable_state
== bp_permanent
4144 : ((others
== 1) ? " and" : ""));
4146 printf_filtered (_("also set at pc "));
4147 fputs_filtered (paddress (pc
), gdb_stdout
);
4148 printf_filtered (".\n");
4152 /* Set the default place to put a breakpoint
4153 for the `break' command with no arguments. */
4156 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4159 default_breakpoint_valid
= valid
;
4160 default_breakpoint_address
= addr
;
4161 default_breakpoint_symtab
= symtab
;
4162 default_breakpoint_line
= line
;
4165 /* Return true iff it is meaningful to use the address member of
4166 BPT. For some breakpoint types, the address member is irrelevant
4167 and it makes no sense to attempt to compare it to other addresses
4168 (or use it for any other purpose either).
4170 More specifically, each of the following breakpoint types will always
4171 have a zero valued address and we don't want check_duplicates() to mark
4172 breakpoints of any of these types to be a duplicate of an actual
4173 breakpoint at address zero:
4176 bp_hardware_watchpoint
4178 bp_access_watchpoint
4182 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4184 enum bptype type
= bpt
->type
;
4186 return (type
!= bp_watchpoint
4187 && type
!= bp_hardware_watchpoint
4188 && type
!= bp_read_watchpoint
4189 && type
!= bp_access_watchpoint
4190 && type
!= bp_catchpoint
);
4193 /* Rescan breakpoints at the same address and section as BPT,
4194 marking the first one as "first" and any others as "duplicates".
4195 This is so that the bpt instruction is only inserted once.
4196 If we have a permanent breakpoint at the same place as BPT, make
4197 that one the official one, and the rest as duplicates. */
4200 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4202 struct bp_location
*b
;
4204 struct bp_location
*perm_bp
= 0;
4206 ALL_BP_LOCATIONS (b
)
4207 if (b
->owner
->enable_state
!= bp_disabled
4208 && b
->owner
->enable_state
!= bp_call_disabled
4210 && !b
->shlib_disabled
4211 && b
->address
== address
/* address / overlay match */
4212 && (!overlay_debugging
|| b
->section
== section
)
4213 && breakpoint_address_is_meaningful (b
->owner
))
4215 /* Have we found a permanent breakpoint? */
4216 if (b
->owner
->enable_state
== bp_permanent
)
4223 b
->duplicate
= count
> 1;
4226 /* If we found a permanent breakpoint at this address, go over the
4227 list again and declare all the other breakpoints there (except
4228 other permanent breakpoints) to be the duplicates. */
4231 perm_bp
->duplicate
= 0;
4233 /* Permanent breakpoint should always be inserted. */
4234 if (! perm_bp
->inserted
)
4235 internal_error (__FILE__
, __LINE__
,
4236 _("allegedly permanent breakpoint is not "
4237 "actually inserted"));
4239 ALL_BP_LOCATIONS (b
)
4242 if (b
->owner
->enable_state
!= bp_permanent
4243 && b
->owner
->enable_state
!= bp_disabled
4244 && b
->owner
->enable_state
!= bp_call_disabled
4245 && b
->enabled
&& !b
->shlib_disabled
4246 && b
->address
== address
/* address / overlay match */
4247 && (!overlay_debugging
|| b
->section
== section
)
4248 && breakpoint_address_is_meaningful (b
->owner
))
4251 internal_error (__FILE__
, __LINE__
,
4252 _("another breakpoint was inserted on top of "
4253 "a permanent breakpoint"));
4262 check_duplicates (struct breakpoint
*bpt
)
4264 struct bp_location
*bl
= bpt
->loc
;
4266 if (! breakpoint_address_is_meaningful (bpt
))
4269 for (; bl
; bl
= bl
->next
)
4270 check_duplicates_for (bl
->address
, bl
->section
);
4274 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4275 int bnum
, int have_bnum
)
4280 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4281 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4283 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4284 bnum
, astr1
, astr2
);
4286 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4289 /* Adjust a breakpoint's address to account for architectural constraints
4290 on breakpoint placement. Return the adjusted address. Note: Very
4291 few targets require this kind of adjustment. For most targets,
4292 this function is simply the identity function. */
4295 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4296 CORE_ADDR bpaddr
, enum bptype bptype
)
4298 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4300 /* Very few targets need any kind of breakpoint adjustment. */
4303 else if (bptype
== bp_watchpoint
4304 || bptype
== bp_hardware_watchpoint
4305 || bptype
== bp_read_watchpoint
4306 || bptype
== bp_access_watchpoint
4307 || bptype
== bp_catchpoint
)
4309 /* Watchpoints and the various bp_catch_* eventpoints should not
4310 have their addresses modified. */
4315 CORE_ADDR adjusted_bpaddr
;
4317 /* Some targets have architectural constraints on the placement
4318 of breakpoint instructions. Obtain the adjusted address. */
4319 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
4321 /* An adjusted breakpoint address can significantly alter
4322 a user's expectations. Print a warning if an adjustment
4324 if (adjusted_bpaddr
!= bpaddr
)
4325 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4327 return adjusted_bpaddr
;
4331 /* Allocate a struct bp_location. */
4333 static struct bp_location
*
4334 allocate_bp_location (struct breakpoint
*bpt
)
4336 struct bp_location
*loc
, *loc_p
;
4338 loc
= xmalloc (sizeof (struct bp_location
));
4339 memset (loc
, 0, sizeof (*loc
));
4343 loc
->shlib_disabled
= 0;
4353 case bp_longjmp_resume
:
4354 case bp_step_resume
:
4355 case bp_watchpoint_scope
:
4357 case bp_shlib_event
:
4358 case bp_thread_event
:
4359 case bp_overlay_event
:
4360 case bp_longjmp_master
:
4361 loc
->loc_type
= bp_loc_software_breakpoint
;
4363 case bp_hardware_breakpoint
:
4364 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4366 case bp_hardware_watchpoint
:
4367 case bp_read_watchpoint
:
4368 case bp_access_watchpoint
:
4369 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4373 loc
->loc_type
= bp_loc_other
;
4376 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4382 static void free_bp_location (struct bp_location
*loc
)
4387 if (loc
->function_name
)
4388 xfree (loc
->function_name
);
4393 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4394 that has type BPTYPE and has no locations as yet. */
4396 static struct breakpoint
*
4397 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
4400 struct breakpoint
*b
, *b1
;
4402 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4403 memset (b
, 0, sizeof (*b
));
4406 b
->gdbarch
= gdbarch
;
4407 b
->language
= current_language
->la_language
;
4408 b
->input_radix
= input_radix
;
4410 b
->enable_state
= bp_enabled
;
4413 b
->ignore_count
= 0;
4415 b
->frame_id
= null_frame_id
;
4416 b
->forked_inferior_pid
= null_ptid
;
4417 b
->exec_pathname
= NULL
;
4419 b
->condition_not_parsed
= 0;
4421 /* Add this breakpoint to the end of the chain
4422 so that a list of breakpoints will come out in order
4423 of increasing numbers. */
4425 b1
= breakpoint_chain
;
4427 breakpoint_chain
= b
;
4437 /* Initialize loc->function_name. */
4439 set_breakpoint_location_function (struct bp_location
*loc
)
4441 if (loc
->owner
->type
== bp_breakpoint
4442 || loc
->owner
->type
== bp_hardware_breakpoint
4443 || loc
->owner
->type
== bp_tracepoint
)
4445 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4447 if (loc
->function_name
)
4448 loc
->function_name
= xstrdup (loc
->function_name
);
4452 /* Attempt to determine architecture of location identified by SAL. */
4453 static struct gdbarch
*
4454 get_sal_arch (struct symtab_and_line sal
)
4457 return get_objfile_arch (sal
.section
->objfile
);
4459 return get_objfile_arch (sal
.symtab
->objfile
);
4464 /* set_raw_breakpoint is a low level routine for allocating and
4465 partially initializing a breakpoint of type BPTYPE. The newly
4466 created breakpoint's address, section, source file name, and line
4467 number are provided by SAL. The newly created and partially
4468 initialized breakpoint is added to the breakpoint chain and
4469 is also returned as the value of this function.
4471 It is expected that the caller will complete the initialization of
4472 the newly created breakpoint struct as well as output any status
4473 information regarding the creation of a new breakpoint. In
4474 particular, set_raw_breakpoint does NOT set the breakpoint
4475 number! Care should be taken to not allow an error to occur
4476 prior to completing the initialization of the breakpoint. If this
4477 should happen, a bogus breakpoint will be left on the chain. */
4479 static struct breakpoint
*
4480 set_raw_breakpoint (struct gdbarch
*gdbarch
,
4481 struct symtab_and_line sal
, enum bptype bptype
)
4483 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
4484 CORE_ADDR adjusted_address
;
4485 struct gdbarch
*loc_gdbarch
;
4487 loc_gdbarch
= get_sal_arch (sal
);
4489 loc_gdbarch
= b
->gdbarch
;
4491 /* Adjust the breakpoint's address prior to allocating a location.
4492 Once we call allocate_bp_location(), that mostly uninitialized
4493 location will be placed on the location chain. Adjustment of the
4494 breakpoint may cause target_read_memory() to be called and we do
4495 not want its scan of the location chain to find a breakpoint and
4496 location that's only been partially initialized. */
4497 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
4499 b
->loc
= allocate_bp_location (b
);
4500 b
->loc
->gdbarch
= loc_gdbarch
;
4501 b
->loc
->requested_address
= sal
.pc
;
4502 b
->loc
->address
= adjusted_address
;
4504 if (sal
.symtab
== NULL
)
4505 b
->source_file
= NULL
;
4507 b
->source_file
= xstrdup (sal
.symtab
->filename
);
4508 b
->loc
->section
= sal
.section
;
4509 b
->line_number
= sal
.line
;
4511 set_breakpoint_location_function (b
->loc
);
4513 breakpoints_changed ();
4519 /* Note that the breakpoint object B describes a permanent breakpoint
4520 instruction, hard-wired into the inferior's code. */
4522 make_breakpoint_permanent (struct breakpoint
*b
)
4524 struct bp_location
*bl
;
4525 b
->enable_state
= bp_permanent
;
4527 /* By definition, permanent breakpoints are already present in the code.
4528 Mark all locations as inserted. For now, make_breakpoint_permanent
4529 is called in just one place, so it's hard to say if it's reasonable
4530 to have permanent breakpoint with multiple locations or not,
4531 but it's easy to implmement. */
4532 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4536 /* Call this routine when stepping and nexting to enable a breakpoint
4537 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4538 set_longjmp_resume_breakpoint() to figure out where we are going. */
4541 set_longjmp_breakpoint (int thread
)
4543 struct breakpoint
*b
, *temp
;
4545 /* To avoid having to rescan all objfile symbols at every step,
4546 we maintain a list of continually-inserted but always disabled
4547 longjmp "master" breakpoints. Here, we simply create momentary
4548 clones of those and enable them for the requested thread. */
4549 ALL_BREAKPOINTS_SAFE (b
, temp
)
4550 if (b
->type
== bp_longjmp_master
)
4552 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
4553 clone
->type
= bp_longjmp
;
4554 clone
->thread
= thread
;
4558 /* Delete all longjmp breakpoints from THREAD. */
4560 delete_longjmp_breakpoint (int thread
)
4562 struct breakpoint
*b
, *temp
;
4564 ALL_BREAKPOINTS_SAFE (b
, temp
)
4565 if (b
->type
== bp_longjmp
)
4567 if (b
->thread
== thread
)
4568 delete_breakpoint (b
);
4573 enable_overlay_breakpoints (void)
4575 struct breakpoint
*b
;
4578 if (b
->type
== bp_overlay_event
)
4580 b
->enable_state
= bp_enabled
;
4581 update_global_location_list (1);
4582 overlay_events_enabled
= 1;
4587 disable_overlay_breakpoints (void)
4589 struct breakpoint
*b
;
4592 if (b
->type
== bp_overlay_event
)
4594 b
->enable_state
= bp_disabled
;
4595 update_global_location_list (0);
4596 overlay_events_enabled
= 0;
4601 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4603 struct breakpoint
*b
;
4605 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
4607 b
->enable_state
= bp_enabled
;
4608 /* addr_string has to be used or breakpoint_re_set will delete me. */
4609 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4611 update_global_location_list_nothrow (1);
4617 remove_thread_event_breakpoints (void)
4619 struct breakpoint
*b
, *temp
;
4621 ALL_BREAKPOINTS_SAFE (b
, temp
)
4622 if (b
->type
== bp_thread_event
)
4623 delete_breakpoint (b
);
4626 struct captured_parse_breakpoint_args
4629 struct symtabs_and_lines
*sals_p
;
4630 char ***addr_string_p
;
4634 struct lang_and_radix
4642 remove_solib_event_breakpoints (void)
4644 struct breakpoint
*b
, *temp
;
4646 ALL_BREAKPOINTS_SAFE (b
, temp
)
4647 if (b
->type
== bp_shlib_event
)
4648 delete_breakpoint (b
);
4652 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4654 struct breakpoint
*b
;
4656 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
4657 update_global_location_list_nothrow (1);
4661 /* Disable any breakpoints that are on code in shared libraries. Only
4662 apply to enabled breakpoints, disabled ones can just stay disabled. */
4665 disable_breakpoints_in_shlibs (void)
4667 struct bp_location
*loc
;
4669 ALL_BP_LOCATIONS (loc
)
4671 struct breakpoint
*b
= loc
->owner
;
4672 /* We apply the check to all breakpoints, including disabled
4673 for those with loc->duplicate set. This is so that when breakpoint
4674 becomes enabled, or the duplicate is removed, gdb will try to insert
4675 all breakpoints. If we don't set shlib_disabled here, we'll try
4676 to insert those breakpoints and fail. */
4677 if (((b
->type
== bp_breakpoint
)
4678 || (b
->type
== bp_hardware_breakpoint
)
4679 || (b
->type
== bp_tracepoint
))
4680 && !loc
->shlib_disabled
4682 && PC_SOLIB (loc
->address
)
4684 && solib_name_from_address (loc
->address
)
4688 loc
->shlib_disabled
= 1;
4693 /* Disable any breakpoints that are in in an unloaded shared library. Only
4694 apply to enabled breakpoints, disabled ones can just stay disabled. */
4697 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4699 struct bp_location
*loc
;
4700 int disabled_shlib_breaks
= 0;
4702 /* SunOS a.out shared libraries are always mapped, so do not
4703 disable breakpoints; they will only be reported as unloaded
4704 through clear_solib when GDB discards its shared library
4705 list. See clear_solib for more information. */
4706 if (exec_bfd
!= NULL
4707 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4710 ALL_BP_LOCATIONS (loc
)
4712 struct breakpoint
*b
= loc
->owner
;
4713 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4714 || loc
->loc_type
== bp_loc_software_breakpoint
)
4715 && !loc
->shlib_disabled
4716 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4717 && solib_contains_address_p (solib
, loc
->address
))
4719 loc
->shlib_disabled
= 1;
4720 /* At this point, we cannot rely on remove_breakpoint
4721 succeeding so we must mark the breakpoint as not inserted
4722 to prevent future errors occurring in remove_breakpoints. */
4724 if (!disabled_shlib_breaks
)
4726 target_terminal_ours_for_output ();
4727 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4730 disabled_shlib_breaks
= 1;
4735 /* FORK & VFORK catchpoints. */
4737 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4740 insert_catch_fork (struct breakpoint
*b
)
4742 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4745 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4748 remove_catch_fork (struct breakpoint
*b
)
4750 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4753 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4757 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4759 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4762 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4764 static enum print_stop_action
4765 print_it_catch_fork (struct breakpoint
*b
)
4767 annotate_catchpoint (b
->number
);
4768 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4769 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4770 return PRINT_SRC_AND_LOC
;
4773 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4776 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4778 struct value_print_options opts
;
4780 get_user_print_options (&opts
);
4782 /* Field 4, the address, is omitted (which makes the columns
4783 not line up too nicely with the headers, but the effect
4784 is relatively readable). */
4785 if (opts
.addressprint
)
4786 ui_out_field_skip (uiout
, "addr");
4788 ui_out_text (uiout
, "fork");
4789 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4791 ui_out_text (uiout
, ", process ");
4792 ui_out_field_int (uiout
, "what",
4793 ptid_get_pid (b
->forked_inferior_pid
));
4794 ui_out_spaces (uiout
, 1);
4798 /* Implement the "print_mention" breakpoint_ops method for fork
4802 print_mention_catch_fork (struct breakpoint
*b
)
4804 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4807 /* The breakpoint_ops structure to be used in fork catchpoints. */
4809 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4813 breakpoint_hit_catch_fork
,
4814 print_it_catch_fork
,
4815 print_one_catch_fork
,
4816 print_mention_catch_fork
4819 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4822 insert_catch_vfork (struct breakpoint
*b
)
4824 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4827 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4830 remove_catch_vfork (struct breakpoint
*b
)
4832 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4835 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4839 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4841 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4844 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4846 static enum print_stop_action
4847 print_it_catch_vfork (struct breakpoint
*b
)
4849 annotate_catchpoint (b
->number
);
4850 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4851 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4852 return PRINT_SRC_AND_LOC
;
4855 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4858 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4860 struct value_print_options opts
;
4862 get_user_print_options (&opts
);
4863 /* Field 4, the address, is omitted (which makes the columns
4864 not line up too nicely with the headers, but the effect
4865 is relatively readable). */
4866 if (opts
.addressprint
)
4867 ui_out_field_skip (uiout
, "addr");
4869 ui_out_text (uiout
, "vfork");
4870 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4872 ui_out_text (uiout
, ", process ");
4873 ui_out_field_int (uiout
, "what",
4874 ptid_get_pid (b
->forked_inferior_pid
));
4875 ui_out_spaces (uiout
, 1);
4879 /* Implement the "print_mention" breakpoint_ops method for vfork
4883 print_mention_catch_vfork (struct breakpoint
*b
)
4885 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4888 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4890 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4894 breakpoint_hit_catch_vfork
,
4895 print_it_catch_vfork
,
4896 print_one_catch_vfork
,
4897 print_mention_catch_vfork
4900 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4902 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4903 If COND_STRING is not NULL, then store it in the breakpoint.
4904 OPS, if not NULL, is the breakpoint_ops structure associated
4905 to the catchpoint. */
4907 static struct breakpoint
*
4908 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
4909 char *cond_string
, struct breakpoint_ops
*ops
)
4911 struct symtab_and_line sal
;
4912 struct breakpoint
*b
;
4919 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
4920 set_breakpoint_count (breakpoint_count
+ 1);
4921 b
->number
= breakpoint_count
;
4923 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
4925 b
->addr_string
= NULL
;
4926 b
->enable_state
= bp_enabled
;
4927 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4931 update_global_location_list (1);
4937 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
4938 int tempflag
, char *cond_string
,
4939 struct breakpoint_ops
*ops
)
4941 struct breakpoint
*b
4942 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
4944 /* FIXME: We should put this information in a breakpoint private data
4946 b
->forked_inferior_pid
= null_ptid
;
4949 /* Exec catchpoints. */
4952 insert_catch_exec (struct breakpoint
*b
)
4954 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4958 remove_catch_exec (struct breakpoint
*b
)
4960 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4964 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4966 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4969 static enum print_stop_action
4970 print_it_catch_exec (struct breakpoint
*b
)
4972 annotate_catchpoint (b
->number
);
4973 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4975 return PRINT_SRC_AND_LOC
;
4979 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
4981 struct value_print_options opts
;
4983 get_user_print_options (&opts
);
4985 /* Field 4, the address, is omitted (which makes the columns
4986 not line up too nicely with the headers, but the effect
4987 is relatively readable). */
4988 if (opts
.addressprint
)
4989 ui_out_field_skip (uiout
, "addr");
4991 ui_out_text (uiout
, "exec");
4992 if (b
->exec_pathname
!= NULL
)
4994 ui_out_text (uiout
, ", program \"");
4995 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4996 ui_out_text (uiout
, "\" ");
5001 print_mention_catch_exec (struct breakpoint
*b
)
5003 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
5006 static struct breakpoint_ops catch_exec_breakpoint_ops
=
5010 breakpoint_hit_catch_exec
,
5011 print_it_catch_exec
,
5012 print_one_catch_exec
,
5013 print_mention_catch_exec
5017 hw_breakpoint_used_count (void)
5019 struct breakpoint
*b
;
5024 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
5032 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
5034 struct breakpoint
*b
;
5037 *other_type_used
= 0;
5040 if (breakpoint_enabled (b
))
5042 if (b
->type
== type
)
5044 else if ((b
->type
== bp_hardware_watchpoint
5045 || b
->type
== bp_read_watchpoint
5046 || b
->type
== bp_access_watchpoint
))
5047 *other_type_used
= 1;
5054 disable_watchpoints_before_interactive_call_start (void)
5056 struct breakpoint
*b
;
5060 if (((b
->type
== bp_watchpoint
)
5061 || (b
->type
== bp_hardware_watchpoint
)
5062 || (b
->type
== bp_read_watchpoint
)
5063 || (b
->type
== bp_access_watchpoint
))
5064 && breakpoint_enabled (b
))
5066 b
->enable_state
= bp_call_disabled
;
5067 update_global_location_list (0);
5073 enable_watchpoints_after_interactive_call_stop (void)
5075 struct breakpoint
*b
;
5079 if (((b
->type
== bp_watchpoint
)
5080 || (b
->type
== bp_hardware_watchpoint
)
5081 || (b
->type
== bp_read_watchpoint
)
5082 || (b
->type
== bp_access_watchpoint
))
5083 && (b
->enable_state
== bp_call_disabled
))
5085 b
->enable_state
= bp_enabled
;
5086 update_global_location_list (1);
5092 /* Set a breakpoint that will evaporate an end of command
5093 at address specified by SAL.
5094 Restrict it to frame FRAME if FRAME is nonzero. */
5097 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
5098 struct frame_id frame_id
, enum bptype type
)
5100 struct breakpoint
*b
;
5102 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5104 gdb_assert (!frame_id_inlined_p (frame_id
));
5106 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5107 b
->enable_state
= bp_enabled
;
5108 b
->disposition
= disp_donttouch
;
5109 b
->frame_id
= frame_id
;
5111 /* If we're debugging a multi-threaded program, then we
5112 want momentary breakpoints to be active in only a
5113 single thread of control. */
5114 if (in_thread_list (inferior_ptid
))
5115 b
->thread
= pid_to_thread_id (inferior_ptid
);
5117 update_global_location_list_nothrow (1);
5122 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5126 clone_momentary_breakpoint (struct breakpoint
*orig
)
5128 struct breakpoint
*copy
;
5130 /* If there's nothing to clone, then return nothing. */
5134 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
5135 copy
->loc
= allocate_bp_location (copy
);
5136 set_breakpoint_location_function (copy
->loc
);
5138 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
5139 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
5140 copy
->loc
->address
= orig
->loc
->address
;
5141 copy
->loc
->section
= orig
->loc
->section
;
5143 if (orig
->source_file
== NULL
)
5144 copy
->source_file
= NULL
;
5146 copy
->source_file
= xstrdup (orig
->source_file
);
5148 copy
->line_number
= orig
->line_number
;
5149 copy
->frame_id
= orig
->frame_id
;
5150 copy
->thread
= orig
->thread
;
5152 copy
->enable_state
= bp_enabled
;
5153 copy
->disposition
= disp_donttouch
;
5154 copy
->number
= internal_breakpoint_number
--;
5156 update_global_location_list_nothrow (0);
5161 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
5164 struct symtab_and_line sal
;
5166 sal
= find_pc_line (pc
, 0);
5168 sal
.section
= find_pc_overlay (pc
);
5169 sal
.explicit_pc
= 1;
5171 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
5175 /* Tell the user we have just set a breakpoint B. */
5178 mention (struct breakpoint
*b
)
5181 struct cleanup
*ui_out_chain
;
5182 struct value_print_options opts
;
5184 get_user_print_options (&opts
);
5186 /* FIXME: This is misplaced; mention() is called by things (like
5187 hitting a watchpoint) other than breakpoint creation. It should
5188 be possible to clean this up and at the same time replace the
5189 random calls to breakpoint_changed with this hook. */
5190 observer_notify_breakpoint_created (b
->number
);
5192 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5193 b
->ops
->print_mention (b
);
5198 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5201 ui_out_text (uiout
, "Watchpoint ");
5202 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5203 ui_out_field_int (uiout
, "number", b
->number
);
5204 ui_out_text (uiout
, ": ");
5205 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5206 do_cleanups (ui_out_chain
);
5208 case bp_hardware_watchpoint
:
5209 ui_out_text (uiout
, "Hardware watchpoint ");
5210 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5211 ui_out_field_int (uiout
, "number", b
->number
);
5212 ui_out_text (uiout
, ": ");
5213 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5214 do_cleanups (ui_out_chain
);
5216 case bp_read_watchpoint
:
5217 ui_out_text (uiout
, "Hardware read watchpoint ");
5218 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5219 ui_out_field_int (uiout
, "number", b
->number
);
5220 ui_out_text (uiout
, ": ");
5221 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5222 do_cleanups (ui_out_chain
);
5224 case bp_access_watchpoint
:
5225 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5226 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5227 ui_out_field_int (uiout
, "number", b
->number
);
5228 ui_out_text (uiout
, ": ");
5229 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5230 do_cleanups (ui_out_chain
);
5233 if (ui_out_is_mi_like_p (uiout
))
5238 if (b
->disposition
== disp_del
)
5239 printf_filtered (_("Temporary breakpoint"));
5241 printf_filtered (_("Breakpoint"));
5242 printf_filtered (_(" %d"), b
->number
);
5245 case bp_hardware_breakpoint
:
5246 if (ui_out_is_mi_like_p (uiout
))
5251 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5255 if (ui_out_is_mi_like_p (uiout
))
5260 printf_filtered (_("Tracepoint"));
5261 printf_filtered (_(" %d"), b
->number
);
5268 case bp_longjmp_resume
:
5269 case bp_step_resume
:
5271 case bp_watchpoint_scope
:
5272 case bp_shlib_event
:
5273 case bp_thread_event
:
5274 case bp_overlay_event
:
5275 case bp_longjmp_master
:
5281 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5285 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5289 if (opts
.addressprint
|| b
->source_file
== NULL
)
5291 printf_filtered (" at ");
5292 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5295 printf_filtered (": file %s, line %d.",
5296 b
->source_file
, b
->line_number
);
5300 struct bp_location
*loc
= b
->loc
;
5302 for (; loc
; loc
= loc
->next
)
5304 printf_filtered (" (%d locations)", n
);
5309 if (ui_out_is_mi_like_p (uiout
))
5311 printf_filtered ("\n");
5315 static struct bp_location
*
5316 add_location_to_breakpoint (struct breakpoint
*b
,
5317 const struct symtab_and_line
*sal
)
5319 struct bp_location
*loc
, **tmp
;
5321 loc
= allocate_bp_location (b
);
5322 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5325 loc
->gdbarch
= get_sal_arch (*sal
);
5327 loc
->gdbarch
= b
->gdbarch
;
5328 loc
->requested_address
= sal
->pc
;
5329 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5330 loc
->requested_address
, b
->type
);
5331 loc
->section
= sal
->section
;
5333 set_breakpoint_location_function (loc
);
5338 /* Return 1 if LOC is pointing to a permanent breakpoint,
5339 return 0 otherwise. */
5342 bp_loc_is_permanent (struct bp_location
*loc
)
5346 const gdb_byte
*brk
;
5347 gdb_byte
*target_mem
;
5348 struct cleanup
*cleanup
;
5351 gdb_assert (loc
!= NULL
);
5353 addr
= loc
->address
;
5354 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
5356 /* Software breakpoints unsupported? */
5360 target_mem
= alloca (len
);
5362 /* Enable the automatic memory restoration from breakpoints while
5363 we read the memory. Otherwise we could say about our temporary
5364 breakpoints they are permanent. */
5365 cleanup
= make_show_memory_breakpoints_cleanup (0);
5367 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5368 && memcmp (target_mem
, brk
, len
) == 0)
5371 do_cleanups (cleanup
);
5378 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5379 as textual description of the location, and COND_STRING
5380 as condition expression. */
5383 create_breakpoint (struct gdbarch
*gdbarch
,
5384 struct symtabs_and_lines sals
, char *addr_string
,
5386 enum bptype type
, enum bpdisp disposition
,
5387 int thread
, int task
, int ignore_count
,
5388 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5390 struct breakpoint
*b
= NULL
;
5393 if (type
== bp_hardware_breakpoint
)
5395 int i
= hw_breakpoint_used_count ();
5396 int target_resources_ok
=
5397 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
5399 if (target_resources_ok
== 0)
5400 error (_("No hardware breakpoint support in the target."));
5401 else if (target_resources_ok
< 0)
5402 error (_("Hardware breakpoints used exceeds limit."));
5405 for (i
= 0; i
< sals
.nelts
; ++i
)
5407 struct symtab_and_line sal
= sals
.sals
[i
];
5408 struct bp_location
*loc
;
5411 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5415 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5416 set_breakpoint_count (breakpoint_count
+ 1);
5417 b
->number
= breakpoint_count
;
5421 b
->cond_string
= cond_string
;
5422 b
->ignore_count
= ignore_count
;
5423 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5424 b
->disposition
= disposition
;
5430 loc
= add_location_to_breakpoint (b
, &sal
);
5433 if (bp_loc_is_permanent (loc
))
5434 make_breakpoint_permanent (b
);
5438 char *arg
= b
->cond_string
;
5439 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5441 error (_("Garbage %s follows condition"), arg
);
5446 b
->addr_string
= addr_string
;
5448 /* addr_string has to be used or breakpoint_re_set will delete
5450 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5456 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5457 elements to fill the void space. */
5459 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5461 int i
= index_to_remove
+1;
5462 int last_index
= sal
->nelts
-1;
5464 for (;i
<= last_index
; ++i
)
5465 sal
->sals
[i
-1] = sal
->sals
[i
];
5470 /* If appropriate, obtains all sals that correspond
5471 to the same file and line as SAL. This is done
5472 only if SAL does not have explicit PC and has
5473 line and file information. If we got just a single
5474 expanded sal, return the original.
5476 Otherwise, if SAL.explicit_line is not set, filter out
5477 all sals for which the name of enclosing function
5478 is different from SAL. This makes sure that if we have
5479 breakpoint originally set in template instantiation, say
5480 foo<int>(), we won't expand SAL to locations at the same
5481 line in all existing instantiations of 'foo'.
5484 static struct symtabs_and_lines
5485 expand_line_sal_maybe (struct symtab_and_line sal
)
5487 struct symtabs_and_lines expanded
;
5488 CORE_ADDR original_pc
= sal
.pc
;
5489 char *original_function
= NULL
;
5493 /* If we have explicit pc, don't expand.
5494 If we have no line number, we can't expand. */
5495 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5498 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5499 expanded
.sals
[0] = sal
;
5504 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5506 expanded
= expand_line_sal (sal
);
5507 if (expanded
.nelts
== 1)
5509 /* We had one sal, we got one sal. Without futher
5510 processing, just return the original sal. */
5511 xfree (expanded
.sals
);
5513 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5514 sal
.pc
= original_pc
;
5515 expanded
.sals
[0] = sal
;
5519 if (!sal
.explicit_line
)
5521 CORE_ADDR func_addr
, func_end
;
5522 for (i
= 0; i
< expanded
.nelts
; ++i
)
5524 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5525 char *this_function
;
5526 if (find_pc_partial_function (pc
, &this_function
,
5527 &func_addr
, &func_end
))
5530 && strcmp (this_function
, original_function
) != 0)
5532 remove_sal (&expanded
, i
);
5535 else if (func_addr
== pc
)
5537 /* We're at beginning of a function, and should
5539 struct symbol
*sym
= find_pc_function (pc
);
5541 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5544 /* Since find_pc_partial_function returned true,
5545 we should really always find the section here. */
5546 struct obj_section
*section
= find_pc_section (pc
);
5549 struct gdbarch
*gdbarch
5550 = get_objfile_arch (section
->objfile
);
5552 = gdbarch_skip_prologue (gdbarch
, pc
);
5561 for (i
= 0; i
< expanded
.nelts
; ++i
)
5563 /* If this SAL corresponds to a breakpoint inserted using a
5564 line number, then skip the function prologue if necessary. */
5565 skip_prologue_sal (&expanded
.sals
[i
]);
5570 if (expanded
.nelts
<= 1)
5572 /* This is un ugly workaround. If we get zero
5573 expanded sals then something is really wrong.
5574 Fix that by returnign the original sal. */
5575 xfree (expanded
.sals
);
5577 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5578 sal
.pc
= original_pc
;
5579 expanded
.sals
[0] = sal
;
5586 for (i
= 0; i
< expanded
.nelts
; ++i
)
5587 if (expanded
.sals
[i
].pc
== original_pc
)
5598 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5599 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5600 value. COND_STRING, if not NULL, specified the condition to be
5601 used for all breakpoints. Essentially the only case where
5602 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5603 function. In that case, it's still not possible to specify
5604 separate conditions for different overloaded functions, so
5605 we take just a single condition string.
5607 NOTE: If the function succeeds, the caller is expected to cleanup
5608 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5609 array contents). If the function fails (error() is called), the
5610 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5611 COND and SALS arrays and each of those arrays contents. */
5614 create_breakpoints (struct gdbarch
*gdbarch
,
5615 struct symtabs_and_lines sals
, char **addr_string
,
5617 enum bptype type
, enum bpdisp disposition
,
5618 int thread
, int task
, int ignore_count
,
5619 struct breakpoint_ops
*ops
, int from_tty
,
5623 for (i
= 0; i
< sals
.nelts
; ++i
)
5625 struct symtabs_and_lines expanded
=
5626 expand_line_sal_maybe (sals
.sals
[i
]);
5628 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
5629 cond_string
, type
, disposition
,
5630 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5634 /* Parse ARG which is assumed to be a SAL specification possibly
5635 followed by conditionals. On return, SALS contains an array of SAL
5636 addresses found. ADDR_STRING contains a vector of (canonical)
5637 address strings. ARG points to the end of the SAL. */
5640 parse_breakpoint_sals (char **address
,
5641 struct symtabs_and_lines
*sals
,
5642 char ***addr_string
,
5645 char *addr_start
= *address
;
5646 *addr_string
= NULL
;
5647 /* If no arg given, or if first arg is 'if ', use the default
5649 if ((*address
) == NULL
5650 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5652 if (default_breakpoint_valid
)
5654 struct symtab_and_line sal
;
5655 init_sal (&sal
); /* initialize to zeroes */
5656 sals
->sals
= (struct symtab_and_line
*)
5657 xmalloc (sizeof (struct symtab_and_line
));
5658 sal
.pc
= default_breakpoint_address
;
5659 sal
.line
= default_breakpoint_line
;
5660 sal
.symtab
= default_breakpoint_symtab
;
5661 sal
.section
= find_pc_overlay (sal
.pc
);
5663 /* "break" without arguments is equivalent to "break *PC" where PC is
5664 the default_breakpoint_address. So make sure to set
5665 sal.explicit_pc to prevent GDB from trying to expand the list of
5666 sals to include all other instances with the same symtab and line.
5668 sal
.explicit_pc
= 1;
5670 sals
->sals
[0] = sal
;
5674 error (_("No default breakpoint address now."));
5678 /* Force almost all breakpoints to be in terms of the
5679 current_source_symtab (which is decode_line_1's default). This
5680 should produce the results we want almost all of the time while
5681 leaving default_breakpoint_* alone.
5682 ObjC: However, don't match an Objective-C method name which
5683 may have a '+' or '-' succeeded by a '[' */
5685 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5687 if (default_breakpoint_valid
5689 || ((strchr ("+-", (*address
)[0]) != NULL
)
5690 && ((*address
)[1] != '['))))
5691 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5692 default_breakpoint_line
, addr_string
,
5695 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5696 addr_string
, not_found_ptr
);
5698 /* For any SAL that didn't have a canonical string, fill one in. */
5699 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5700 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5701 if (addr_start
!= (*address
))
5704 for (i
= 0; i
< sals
->nelts
; i
++)
5706 /* Add the string if not present. */
5707 if ((*addr_string
)[i
] == NULL
)
5708 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5714 /* Convert each SAL into a real PC. Verify that the PC can be
5715 inserted as a breakpoint. If it can't throw an error. */
5718 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5722 for (i
= 0; i
< sals
->nelts
; i
++)
5723 resolve_sal_pc (&sals
->sals
[i
]);
5727 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5729 struct captured_parse_breakpoint_args
*args
= data
;
5731 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5732 args
->not_found_ptr
);
5735 /* Given TOK, a string specification of condition and thread, as
5736 accepted by the 'break' command, extract the condition
5737 string and thread number and set *COND_STRING and *THREAD.
5738 PC identifies the context at which the condition should be parsed.
5739 If no condition is found, *COND_STRING is set to NULL.
5740 If no thread is found, *THREAD is set to -1. */
5742 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5743 char **cond_string
, int *thread
, int *task
)
5745 *cond_string
= NULL
;
5751 char *cond_start
= NULL
;
5752 char *cond_end
= NULL
;
5753 while (*tok
== ' ' || *tok
== '\t')
5758 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5761 toklen
= end_tok
- tok
;
5763 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5765 struct expression
*expr
;
5767 tok
= cond_start
= end_tok
+ 1;
5768 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5771 *cond_string
= savestring (cond_start
,
5772 cond_end
- cond_start
);
5774 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5780 *thread
= strtol (tok
, &tok
, 0);
5782 error (_("Junk after thread keyword."));
5783 if (!valid_thread_id (*thread
))
5784 error (_("Unknown thread %d."), *thread
);
5786 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
5792 *task
= strtol (tok
, &tok
, 0);
5794 error (_("Junk after task keyword."));
5795 if (!valid_task_id (*task
))
5796 error (_("Unknown task %d\n"), *task
);
5799 error (_("Junk at end of arguments."));
5803 /* Set a breakpoint. This function is shared between
5804 CLI and MI functions for setting a breakpoint.
5805 This function has two major modes of operations,
5806 selected by the PARSE_CONDITION_AND_THREAD parameter.
5807 If non-zero, the function will parse arg, extracting
5808 breakpoint location, address and thread. Otherwise,
5809 ARG is just the location of breakpoint, with condition
5810 and thread specified by the COND_STRING and THREAD
5814 break_command_really (struct gdbarch
*gdbarch
,
5815 char *arg
, char *cond_string
, int thread
,
5816 int parse_condition_and_thread
,
5817 int tempflag
, int hardwareflag
, int traceflag
,
5819 enum auto_boolean pending_break_support
,
5820 struct breakpoint_ops
*ops
,
5824 struct gdb_exception e
;
5825 struct symtabs_and_lines sals
;
5826 struct symtab_and_line pending_sal
;
5829 char *addr_start
= arg
;
5831 struct cleanup
*old_chain
;
5832 struct cleanup
*bkpt_chain
= NULL
;
5833 struct captured_parse_breakpoint_args parse_args
;
5837 enum bptype type_wanted
;
5844 parse_args
.arg_p
= &arg
;
5845 parse_args
.sals_p
= &sals
;
5846 parse_args
.addr_string_p
= &addr_string
;
5847 parse_args
.not_found_ptr
= ¬_found
;
5849 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5850 &parse_args
, RETURN_MASK_ALL
);
5852 /* If caller is interested in rc value from parse, set value. */
5856 throw_exception (e
);
5860 case NOT_FOUND_ERROR
:
5862 /* If pending breakpoint support is turned off, throw
5865 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5866 throw_exception (e
);
5868 exception_print (gdb_stderr
, e
);
5870 /* If pending breakpoint support is auto query and the user
5871 selects no, then simply return the error code. */
5872 if (pending_break_support
== AUTO_BOOLEAN_AUTO
5873 && !nquery ("Make breakpoint pending on future shared library load? "))
5876 /* At this point, either the user was queried about setting
5877 a pending breakpoint and selected yes, or pending
5878 breakpoint behavior is on and thus a pending breakpoint
5879 is defaulted on behalf of the user. */
5880 copy_arg
= xstrdup (addr_start
);
5881 addr_string
= ©_arg
;
5883 sals
.sals
= &pending_sal
;
5888 throw_exception (e
);
5895 /* Create a chain of things that always need to be cleaned up. */
5896 old_chain
= make_cleanup (null_cleanup
, 0);
5900 /* Make sure that all storage allocated to SALS gets freed. */
5901 make_cleanup (xfree
, sals
.sals
);
5903 /* Cleanup the addr_string array but not its contents. */
5904 make_cleanup (xfree
, addr_string
);
5907 /* ----------------------------- SNIP -----------------------------
5908 Anything added to the cleanup chain beyond this point is assumed
5909 to be part of a breakpoint. If the breakpoint create succeeds
5910 then the memory is not reclaimed. */
5911 bkpt_chain
= make_cleanup (null_cleanup
, 0);
5913 /* Mark the contents of the addr_string for cleanup. These go on
5914 the bkpt_chain and only occur if the breakpoint create fails. */
5915 for (i
= 0; i
< sals
.nelts
; i
++)
5917 if (addr_string
[i
] != NULL
)
5918 make_cleanup (xfree
, addr_string
[i
]);
5921 /* Resolve all line numbers to PC's and verify that the addresses
5922 are ok for the target. */
5924 breakpoint_sals_to_pc (&sals
, addr_start
);
5926 type_wanted
= (traceflag
5928 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
5930 /* Verify that condition can be parsed, before setting any
5931 breakpoints. Allocate a separate condition expression for each
5935 if (parse_condition_and_thread
)
5937 /* Here we only parse 'arg' to separate condition
5938 from thread number, so parsing in context of first
5939 sal is OK. When setting the breakpoint we'll
5940 re-parse it in context of each sal. */
5943 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
5946 make_cleanup (xfree
, cond_string
);
5950 /* Create a private copy of condition string. */
5953 cond_string
= xstrdup (cond_string
);
5954 make_cleanup (xfree
, cond_string
);
5957 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
5958 tempflag
? disp_del
: disp_donttouch
,
5959 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5963 struct symtab_and_line sal
= {0};
5964 struct breakpoint
*b
;
5966 make_cleanup (xfree
, copy_arg
);
5968 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
5969 set_breakpoint_count (breakpoint_count
+ 1);
5970 b
->number
= breakpoint_count
;
5972 b
->addr_string
= addr_string
[0];
5973 b
->cond_string
= NULL
;
5974 b
->ignore_count
= ignore_count
;
5975 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5976 b
->condition_not_parsed
= 1;
5978 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5984 warning (_("Multiple breakpoints were set.\n"
5985 "Use the \"delete\" command to delete unwanted breakpoints."));
5986 /* That's it. Discard the cleanups for data inserted into the
5988 discard_cleanups (bkpt_chain
);
5989 /* But cleanup everything else. */
5990 do_cleanups (old_chain
);
5992 /* error call may happen here - have BKPT_CHAIN already discarded. */
5993 update_global_location_list (1);
5996 /* Set a breakpoint.
5997 ARG is a string describing breakpoint address,
5998 condition, and thread.
5999 FLAG specifies if a breakpoint is hardware on,
6000 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6004 break_command_1 (char *arg
, int flag
, int from_tty
)
6006 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
6007 int tempflag
= flag
& BP_TEMPFLAG
;
6009 break_command_really (get_current_arch (),
6011 NULL
, 0, 1 /* parse arg */,
6012 tempflag
, hardwareflag
, 0 /* traceflag */,
6013 0 /* Ignore count */,
6014 pending_break_support
,
6015 NULL
/* breakpoint_ops */,
6022 set_breakpoint (struct gdbarch
*gdbarch
,
6023 char *address
, char *condition
,
6024 int hardwareflag
, int tempflag
,
6025 int thread
, int ignore_count
,
6026 int pending
, int enabled
)
6028 break_command_really (gdbarch
,
6029 address
, condition
, thread
,
6030 0 /* condition and thread are valid. */,
6031 tempflag
, hardwareflag
, 0 /* traceflag */,
6034 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
6038 /* Adjust SAL to the first instruction past the function prologue.
6039 The end of the prologue is determined using the line table from
6040 the debugging information. explicit_pc and explicit_line are
6043 If SAL is already past the prologue, then do nothing. */
6046 skip_prologue_sal (struct symtab_and_line
*sal
)
6048 struct symbol
*sym
= find_pc_function (sal
->pc
);
6049 struct symtab_and_line start_sal
;
6054 start_sal
= find_function_start_sal (sym
, 1);
6055 if (sal
->pc
< start_sal
.pc
)
6057 start_sal
.explicit_line
= sal
->explicit_line
;
6058 start_sal
.explicit_pc
= sal
->explicit_pc
;
6063 /* Helper function for break_command_1 and disassemble_command. */
6066 resolve_sal_pc (struct symtab_and_line
*sal
)
6070 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
6072 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
6073 error (_("No line %d in file \"%s\"."),
6074 sal
->line
, sal
->symtab
->filename
);
6077 /* If this SAL corresponds to a breakpoint inserted using
6078 a line number, then skip the function prologue if necessary. */
6079 if (sal
->explicit_line
)
6081 /* Preserve the original line number. */
6082 int saved_line
= sal
->line
;
6083 skip_prologue_sal (sal
);
6084 sal
->line
= saved_line
;
6088 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
6090 struct blockvector
*bv
;
6094 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
6097 sym
= block_linkage_function (b
);
6100 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
6101 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
6105 /* It really is worthwhile to have the section, so we'll just
6106 have to look harder. This case can be executed if we have
6107 line numbers but no functions (as can happen in assembly
6110 struct minimal_symbol
*msym
;
6112 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
6114 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
6121 break_command (char *arg
, int from_tty
)
6123 break_command_1 (arg
, 0, from_tty
);
6127 tbreak_command (char *arg
, int from_tty
)
6129 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
6133 hbreak_command (char *arg
, int from_tty
)
6135 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
6139 thbreak_command (char *arg
, int from_tty
)
6141 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
6145 stop_command (char *arg
, int from_tty
)
6147 printf_filtered (_("Specify the type of breakpoint to set.\n\
6148 Usage: stop in <function | address>\n\
6149 stop at <line>\n"));
6153 stopin_command (char *arg
, int from_tty
)
6157 if (arg
== (char *) NULL
)
6159 else if (*arg
!= '*')
6164 /* look for a ':'. If this is a line number specification, then
6165 say it is bad, otherwise, it should be an address or
6166 function/method name */
6167 while (*argptr
&& !hasColon
)
6169 hasColon
= (*argptr
== ':');
6174 badInput
= (*argptr
!= ':'); /* Not a class::method */
6176 badInput
= isdigit (*arg
); /* a simple line number */
6180 printf_filtered (_("Usage: stop in <function | address>\n"));
6182 break_command_1 (arg
, 0, from_tty
);
6186 stopat_command (char *arg
, int from_tty
)
6190 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6197 /* look for a ':'. If there is a '::' then get out, otherwise
6198 it is probably a line number. */
6199 while (*argptr
&& !hasColon
)
6201 hasColon
= (*argptr
== ':');
6206 badInput
= (*argptr
== ':'); /* we have class::method */
6208 badInput
= !isdigit (*arg
); /* not a line number */
6212 printf_filtered (_("Usage: stop at <line>\n"));
6214 break_command_1 (arg
, 0, from_tty
);
6217 /* accessflag: hw_write: watch write,
6218 hw_read: watch read,
6219 hw_access: watch access (read or write) */
6221 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6223 struct gdbarch
*gdbarch
= get_current_arch ();
6224 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6225 struct symtab_and_line sal
;
6226 struct expression
*exp
;
6227 struct block
*exp_valid_block
;
6228 struct value
*val
, *mark
;
6229 struct frame_info
*frame
;
6230 char *exp_start
= NULL
;
6231 char *exp_end
= NULL
;
6232 char *tok
, *id_tok_start
, *end_tok
;
6234 char *cond_start
= NULL
;
6235 char *cond_end
= NULL
;
6236 struct expression
*cond
= NULL
;
6237 int i
, other_type_used
, target_resources_ok
= 0;
6238 enum bptype bp_type
;
6242 init_sal (&sal
); /* initialize to zeroes */
6244 /* Make sure that we actually have parameters to parse. */
6245 if (arg
!= NULL
&& arg
[0] != '\0')
6247 toklen
= strlen (arg
); /* Size of argument list. */
6249 /* Points tok to the end of the argument list. */
6250 tok
= arg
+ toklen
- 1;
6252 /* Go backwards in the parameters list. Skip the last parameter.
6253 If we're expecting a 'thread <thread_num>' parameter, this should
6254 be the thread identifier. */
6255 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6257 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6260 /* Points end_tok to the beginning of the last token. */
6261 id_tok_start
= tok
+ 1;
6263 /* Go backwards in the parameters list. Skip one more parameter.
6264 If we're expecting a 'thread <thread_num>' parameter, we should
6265 reach a "thread" token. */
6266 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6271 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6274 /* Move the pointer forward to skip the whitespace and
6275 calculate the length of the token. */
6277 toklen
= end_tok
- tok
;
6279 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6281 /* At this point we've found a "thread" token, which means
6282 the user is trying to set a watchpoint that triggers
6283 only in a specific thread. */
6286 /* Extract the thread ID from the next token. */
6287 thread
= strtol (id_tok_start
, &endp
, 0);
6289 /* Check if the user provided a valid numeric value for the
6291 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6292 error (_("Invalid thread ID specification %s."), id_tok_start
);
6294 /* Check if the thread actually exists. */
6295 if (!valid_thread_id (thread
))
6296 error (_("Unknown thread %d."), thread
);
6298 /* Truncate the string and get rid of the thread <thread_num>
6299 parameter before the parameter list is parsed by the
6300 evaluate_expression() function. */
6305 /* Parse the rest of the arguments. */
6306 innermost_block
= NULL
;
6308 exp
= parse_exp_1 (&arg
, 0, 0);
6310 /* Remove trailing whitespace from the expression before saving it.
6311 This makes the eventual display of the expression string a bit
6313 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
6316 exp_valid_block
= innermost_block
;
6317 mark
= value_mark ();
6318 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6320 release_value (val
);
6323 while (*tok
== ' ' || *tok
== '\t')
6327 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6330 toklen
= end_tok
- tok
;
6331 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6333 tok
= cond_start
= end_tok
+ 1;
6334 cond
= parse_exp_1 (&tok
, 0, 0);
6338 error (_("Junk at end of command."));
6340 if (accessflag
== hw_read
)
6341 bp_type
= bp_read_watchpoint
;
6342 else if (accessflag
== hw_access
)
6343 bp_type
= bp_access_watchpoint
;
6345 bp_type
= bp_hardware_watchpoint
;
6347 mem_cnt
= can_use_hardware_watchpoint (val
);
6348 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6349 error (_("Expression cannot be implemented with read/access watchpoint."));
6352 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6353 target_resources_ok
=
6354 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
6356 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6357 error (_("Target does not support this type of hardware watchpoint."));
6359 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6360 error (_("Target can only support one kind of HW watchpoint at a time."));
6363 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6364 watchpoint could not be set. */
6365 if (!mem_cnt
|| target_resources_ok
<= 0)
6366 bp_type
= bp_watchpoint
;
6368 frame
= block_innermost_frame (exp_valid_block
);
6370 /* If the expression is "local", then set up a "watchpoint scope"
6371 breakpoint at the point where we've left the scope of the watchpoint
6372 expression. Create the scope breakpoint before the watchpoint, so
6373 that we will encounter it first in bpstat_stop_status. */
6374 if (innermost_block
&& frame
)
6376 if (frame_id_p (frame_unwind_caller_id (frame
)))
6379 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
6380 frame_unwind_caller_pc (frame
),
6381 bp_watchpoint_scope
);
6383 scope_breakpoint
->enable_state
= bp_enabled
;
6385 /* Automatically delete the breakpoint when it hits. */
6386 scope_breakpoint
->disposition
= disp_del
;
6388 /* Only break in the proper frame (help with recursion). */
6389 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
6391 /* Set the address at which we will stop. */
6392 scope_breakpoint
->loc
->gdbarch
6393 = frame_unwind_caller_arch (frame
);
6394 scope_breakpoint
->loc
->requested_address
6395 = frame_unwind_caller_pc (frame
);
6396 scope_breakpoint
->loc
->address
6397 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
6398 scope_breakpoint
->loc
->requested_address
,
6399 scope_breakpoint
->type
);
6403 /* Now set up the breakpoint. */
6404 b
= set_raw_breakpoint (gdbarch
, sal
, bp_type
);
6405 set_breakpoint_count (breakpoint_count
+ 1);
6406 b
->number
= breakpoint_count
;
6408 b
->disposition
= disp_donttouch
;
6410 b
->exp_valid_block
= exp_valid_block
;
6411 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6414 b
->loc
->cond
= cond
;
6416 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6421 b
->watchpoint_frame
= get_frame_id (frame
);
6423 b
->watchpoint_frame
= null_frame_id
;
6425 if (scope_breakpoint
!= NULL
)
6427 /* The scope breakpoint is related to the watchpoint. We will
6428 need to act on them together. */
6429 b
->related_breakpoint
= scope_breakpoint
;
6430 scope_breakpoint
->related_breakpoint
= b
;
6433 value_free_to_mark (mark
);
6435 update_global_location_list (1);
6438 /* Return count of locations need to be watched and can be handled
6439 in hardware. If the watchpoint can not be handled
6440 in hardware return zero. */
6443 can_use_hardware_watchpoint (struct value
*v
)
6445 int found_memory_cnt
= 0;
6446 struct value
*head
= v
;
6448 /* Did the user specifically forbid us to use hardware watchpoints? */
6449 if (!can_use_hw_watchpoints
)
6452 /* Make sure that the value of the expression depends only upon
6453 memory contents, and values computed from them within GDB. If we
6454 find any register references or function calls, we can't use a
6455 hardware watchpoint.
6457 The idea here is that evaluating an expression generates a series
6458 of values, one holding the value of every subexpression. (The
6459 expression a*b+c has five subexpressions: a, b, a*b, c, and
6460 a*b+c.) GDB's values hold almost enough information to establish
6461 the criteria given above --- they identify memory lvalues,
6462 register lvalues, computed values, etcetera. So we can evaluate
6463 the expression, and then scan the chain of values that leaves
6464 behind to decide whether we can detect any possible change to the
6465 expression's final value using only hardware watchpoints.
6467 However, I don't think that the values returned by inferior
6468 function calls are special in any way. So this function may not
6469 notice that an expression involving an inferior function call
6470 can't be watched with hardware watchpoints. FIXME. */
6471 for (; v
; v
= value_next (v
))
6473 if (VALUE_LVAL (v
) == lval_memory
)
6476 /* A lazy memory lvalue is one that GDB never needed to fetch;
6477 we either just used its address (e.g., `a' in `a.b') or
6478 we never needed it at all (e.g., `a' in `a,b'). */
6482 /* Ahh, memory we actually used! Check if we can cover
6483 it with hardware watchpoints. */
6484 struct type
*vtype
= check_typedef (value_type (v
));
6486 /* We only watch structs and arrays if user asked for it
6487 explicitly, never if they just happen to appear in a
6488 middle of some value chain. */
6490 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6491 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6493 CORE_ADDR vaddr
= value_address (v
);
6494 int len
= TYPE_LENGTH (value_type (v
));
6496 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
6503 else if (VALUE_LVAL (v
) != not_lval
6504 && deprecated_value_modifiable (v
) == 0)
6505 return 0; /* ??? What does this represent? */
6506 else if (VALUE_LVAL (v
) == lval_register
)
6507 return 0; /* cannot watch a register with a HW watchpoint */
6510 /* The expression itself looks suitable for using a hardware
6511 watchpoint, but give the target machine a chance to reject it. */
6512 return found_memory_cnt
;
6516 watch_command_wrapper (char *arg
, int from_tty
)
6518 watch_command (arg
, from_tty
);
6522 watch_command (char *arg
, int from_tty
)
6524 watch_command_1 (arg
, hw_write
, from_tty
);
6528 rwatch_command_wrapper (char *arg
, int from_tty
)
6530 rwatch_command (arg
, from_tty
);
6534 rwatch_command (char *arg
, int from_tty
)
6536 watch_command_1 (arg
, hw_read
, from_tty
);
6540 awatch_command_wrapper (char *arg
, int from_tty
)
6542 awatch_command (arg
, from_tty
);
6546 awatch_command (char *arg
, int from_tty
)
6548 watch_command_1 (arg
, hw_access
, from_tty
);
6552 /* Helper routines for the until_command routine in infcmd.c. Here
6553 because it uses the mechanisms of breakpoints. */
6555 struct until_break_command_continuation_args
6557 struct breakpoint
*breakpoint
;
6558 struct breakpoint
*breakpoint2
;
6561 /* This function is called by fetch_inferior_event via the
6562 cmd_continuation pointer, to complete the until command. It takes
6563 care of cleaning up the temporary breakpoints set up by the until
6566 until_break_command_continuation (void *arg
)
6568 struct until_break_command_continuation_args
*a
= arg
;
6570 delete_breakpoint (a
->breakpoint
);
6572 delete_breakpoint (a
->breakpoint2
);
6576 until_break_command (char *arg
, int from_tty
, int anywhere
)
6578 struct symtabs_and_lines sals
;
6579 struct symtab_and_line sal
;
6580 struct frame_info
*frame
= get_selected_frame (NULL
);
6581 struct breakpoint
*breakpoint
;
6582 struct breakpoint
*breakpoint2
= NULL
;
6583 struct cleanup
*old_chain
;
6585 clear_proceed_status ();
6587 /* Set a breakpoint where the user wants it and at return from
6590 if (default_breakpoint_valid
)
6591 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6592 default_breakpoint_line
, (char ***) NULL
, NULL
);
6594 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6595 0, (char ***) NULL
, NULL
);
6597 if (sals
.nelts
!= 1)
6598 error (_("Couldn't get information on specified line."));
6601 xfree (sals
.sals
); /* malloc'd, so freed */
6604 error (_("Junk at end of arguments."));
6606 resolve_sal_pc (&sal
);
6609 /* If the user told us to continue until a specified location,
6610 we don't specify a frame at which we need to stop. */
6611 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6612 null_frame_id
, bp_until
);
6614 /* Otherwise, specify the selected frame, because we want to stop only
6615 at the very same frame. */
6616 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6617 get_stack_frame_id (frame
),
6620 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6622 /* Keep within the current frame, or in frames called by the current
6625 if (frame_id_p (frame_unwind_caller_id (frame
)))
6627 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
6628 sal
.pc
= frame_unwind_caller_pc (frame
);
6629 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
6631 frame_unwind_caller_id (frame
),
6633 make_cleanup_delete_breakpoint (breakpoint2
);
6636 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6638 /* If we are running asynchronously, and proceed call above has actually
6639 managed to start the target, arrange for breakpoints to be
6640 deleted when the target stops. Otherwise, we're already stopped and
6641 delete breakpoints via cleanup chain. */
6643 if (target_can_async_p () && is_running (inferior_ptid
))
6645 struct until_break_command_continuation_args
*args
;
6646 args
= xmalloc (sizeof (*args
));
6648 args
->breakpoint
= breakpoint
;
6649 args
->breakpoint2
= breakpoint2
;
6651 discard_cleanups (old_chain
);
6652 add_continuation (inferior_thread (),
6653 until_break_command_continuation
, args
,
6657 do_cleanups (old_chain
);
6661 ep_skip_leading_whitespace (char **s
)
6663 if ((s
== NULL
) || (*s
== NULL
))
6665 while (isspace (**s
))
6669 /* This function attempts to parse an optional "if <cond>" clause
6670 from the arg string. If one is not found, it returns NULL.
6672 Else, it returns a pointer to the condition string. (It does not
6673 attempt to evaluate the string against a particular block.) And,
6674 it updates arg to point to the first character following the parsed
6675 if clause in the arg string. */
6678 ep_parse_optional_if_clause (char **arg
)
6682 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6685 /* Skip the "if" keyword. */
6688 /* Skip any extra leading whitespace, and record the start of the
6689 condition string. */
6690 ep_skip_leading_whitespace (arg
);
6693 /* Assume that the condition occupies the remainder of the arg string. */
6694 (*arg
) += strlen (cond_string
);
6699 /* This function attempts to parse an optional filename from the arg
6700 string. If one is not found, it returns NULL.
6702 Else, it returns a pointer to the parsed filename. (This function
6703 makes no attempt to verify that a file of that name exists, or is
6704 accessible.) And, it updates arg to point to the first character
6705 following the parsed filename in the arg string.
6707 Note that clients needing to preserve the returned filename for
6708 future access should copy it to their own buffers. */
6710 ep_parse_optional_filename (char **arg
)
6712 static char filename
[1024];
6717 if ((*arg_p
== '\0') || isspace (*arg_p
))
6735 /* Commands to deal with catching events, such as signals, exceptions,
6736 process start/exit, etc. */
6740 catch_fork_temporary
, catch_vfork_temporary
,
6741 catch_fork_permanent
, catch_vfork_permanent
6746 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6748 struct gdbarch
*gdbarch
= get_current_arch ();
6749 char *cond_string
= NULL
;
6750 catch_fork_kind fork_kind
;
6753 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6754 tempflag
= (fork_kind
== catch_fork_temporary
6755 || fork_kind
== catch_vfork_temporary
);
6759 ep_skip_leading_whitespace (&arg
);
6761 /* The allowed syntax is:
6763 catch [v]fork if <cond>
6765 First, check if there's an if clause. */
6766 cond_string
= ep_parse_optional_if_clause (&arg
);
6768 if ((*arg
!= '\0') && !isspace (*arg
))
6769 error (_("Junk at end of arguments."));
6771 /* If this target supports it, create a fork or vfork catchpoint
6772 and enable reporting of such events. */
6775 case catch_fork_temporary
:
6776 case catch_fork_permanent
:
6777 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6778 &catch_fork_breakpoint_ops
);
6780 case catch_vfork_temporary
:
6781 case catch_vfork_permanent
:
6782 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6783 &catch_vfork_breakpoint_ops
);
6786 error (_("unsupported or unknown fork kind; cannot catch it"));
6792 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6794 struct gdbarch
*gdbarch
= get_current_arch ();
6796 char *cond_string
= NULL
;
6798 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6802 ep_skip_leading_whitespace (&arg
);
6804 /* The allowed syntax is:
6806 catch exec if <cond>
6808 First, check if there's an if clause. */
6809 cond_string
= ep_parse_optional_if_clause (&arg
);
6811 if ((*arg
!= '\0') && !isspace (*arg
))
6812 error (_("Junk at end of arguments."));
6814 /* If this target supports it, create an exec catchpoint
6815 and enable reporting of such events. */
6816 create_catchpoint (gdbarch
, tempflag
, cond_string
,
6817 &catch_exec_breakpoint_ops
);
6820 static enum print_stop_action
6821 print_exception_catchpoint (struct breakpoint
*b
)
6823 int bp_temp
, bp_throw
;
6825 annotate_catchpoint (b
->number
);
6827 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6828 if (b
->loc
->address
!= b
->loc
->requested_address
)
6829 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6832 bp_temp
= b
->disposition
== disp_del
;
6834 bp_temp
? "Temporary catchpoint "
6836 if (!ui_out_is_mi_like_p (uiout
))
6837 ui_out_field_int (uiout
, "bkptno", b
->number
);
6839 bp_throw
? " (exception thrown), "
6840 : " (exception caught), ");
6841 if (ui_out_is_mi_like_p (uiout
))
6843 ui_out_field_string (uiout
, "reason",
6844 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6845 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6846 ui_out_field_int (uiout
, "bkptno", b
->number
);
6848 return PRINT_SRC_AND_LOC
;
6852 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
6854 struct value_print_options opts
;
6855 get_user_print_options (&opts
);
6856 if (opts
.addressprint
)
6859 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6860 ui_out_field_string (uiout
, "addr", "<PENDING>");
6862 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6867 if (strstr (b
->addr_string
, "throw") != NULL
)
6868 ui_out_field_string (uiout
, "what", "exception throw");
6870 ui_out_field_string (uiout
, "what", "exception catch");
6874 print_mention_exception_catchpoint (struct breakpoint
*b
)
6879 bp_temp
= b
->disposition
== disp_del
;
6880 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6881 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6882 : _("Catchpoint "));
6883 ui_out_field_int (uiout
, "bkptno", b
->number
);
6884 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6888 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6891 NULL
, /* breakpoint_hit */
6892 print_exception_catchpoint
,
6893 print_one_exception_catchpoint
,
6894 print_mention_exception_catchpoint
6898 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6899 enum exception_event_kind ex_event
, int from_tty
)
6901 char *trigger_func_name
;
6903 if (ex_event
== EX_EVENT_CATCH
)
6904 trigger_func_name
= "__cxa_begin_catch";
6906 trigger_func_name
= "__cxa_throw";
6908 break_command_really (get_current_arch (),
6909 trigger_func_name
, cond_string
, -1,
6910 0 /* condition and thread are valid. */,
6913 AUTO_BOOLEAN_TRUE
/* pending */,
6914 &gnu_v3_exception_catchpoint_ops
, from_tty
,
6920 /* Deal with "catch catch" and "catch throw" commands */
6923 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6924 int tempflag
, int from_tty
)
6926 char *cond_string
= NULL
;
6927 struct symtab_and_line
*sal
= NULL
;
6931 ep_skip_leading_whitespace (&arg
);
6933 cond_string
= ep_parse_optional_if_clause (&arg
);
6935 if ((*arg
!= '\0') && !isspace (*arg
))
6936 error (_("Junk at end of arguments."));
6938 if (ex_event
!= EX_EVENT_THROW
6939 && ex_event
!= EX_EVENT_CATCH
)
6940 error (_("Unsupported or unknown exception event; cannot catch it"));
6942 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6945 warning (_("Unsupported with this platform/compiler combination."));
6948 /* Implementation of "catch catch" command. */
6951 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6953 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6954 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6957 /* Implementation of "catch throw" command. */
6960 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6962 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6963 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6966 /* Create a breakpoint struct for Ada exception catchpoints. */
6969 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
6970 struct symtab_and_line sal
,
6974 struct expression
*cond
,
6975 struct breakpoint_ops
*ops
,
6979 struct breakpoint
*b
;
6983 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6984 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6985 version for exception catchpoints, because two catchpoints
6986 used for different exception names will use the same address.
6987 In this case, a "breakpoint ... also set at..." warning is
6988 unproductive. Besides. the warning phrasing is also a bit
6989 inapropriate, we should use the word catchpoint, and tell
6990 the user what type of catchpoint it is. The above is good
6991 enough for now, though. */
6994 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
6995 set_breakpoint_count (breakpoint_count
+ 1);
6997 b
->enable_state
= bp_enabled
;
6998 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6999 b
->number
= breakpoint_count
;
7000 b
->ignore_count
= 0;
7001 b
->loc
->cond
= cond
;
7002 b
->addr_string
= addr_string
;
7003 b
->language
= language_ada
;
7004 b
->cond_string
= cond_string
;
7005 b
->exp_string
= exp_string
;
7010 update_global_location_list (1);
7013 /* Implement the "catch exception" command. */
7016 catch_ada_exception_command (char *arg
, int from_tty
,
7017 struct cmd_list_element
*command
)
7019 struct gdbarch
*gdbarch
= get_current_arch ();
7021 struct symtab_and_line sal
;
7023 char *addr_string
= NULL
;
7024 char *exp_string
= NULL
;
7025 char *cond_string
= NULL
;
7026 struct expression
*cond
= NULL
;
7027 struct breakpoint_ops
*ops
= NULL
;
7029 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7033 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
7034 &cond_string
, &cond
, &ops
);
7035 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
7036 cond_string
, cond
, ops
, tempflag
,
7040 /* Implement the "catch assert" command. */
7043 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7045 struct gdbarch
*gdbarch
= get_current_arch ();
7047 struct symtab_and_line sal
;
7048 char *addr_string
= NULL
;
7049 struct breakpoint_ops
*ops
= NULL
;
7051 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7055 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
7056 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
7057 ops
, tempflag
, from_tty
);
7061 catch_command (char *arg
, int from_tty
)
7063 error (_("Catch requires an event name."));
7068 tcatch_command (char *arg
, int from_tty
)
7070 error (_("Catch requires an event name."));
7073 /* Delete breakpoints by address or line. */
7076 clear_command (char *arg
, int from_tty
)
7078 struct breakpoint
*b
;
7079 VEC(breakpoint_p
) *found
= 0;
7082 struct symtabs_and_lines sals
;
7083 struct symtab_and_line sal
;
7088 sals
= decode_line_spec (arg
, 1);
7093 sals
.sals
= (struct symtab_and_line
*)
7094 xmalloc (sizeof (struct symtab_and_line
));
7095 make_cleanup (xfree
, sals
.sals
);
7096 init_sal (&sal
); /* initialize to zeroes */
7097 sal
.line
= default_breakpoint_line
;
7098 sal
.symtab
= default_breakpoint_symtab
;
7099 sal
.pc
= default_breakpoint_address
;
7100 if (sal
.symtab
== 0)
7101 error (_("No source file specified."));
7109 /* We don't call resolve_sal_pc here. That's not
7110 as bad as it seems, because all existing breakpoints
7111 typically have both file/line and pc set. So, if
7112 clear is given file/line, we can match this to existing
7113 breakpoint without obtaining pc at all.
7115 We only support clearing given the address explicitly
7116 present in breakpoint table. Say, we've set breakpoint
7117 at file:line. There were several PC values for that file:line,
7118 due to optimization, all in one block.
7119 We've picked one PC value. If "clear" is issued with another
7120 PC corresponding to the same file:line, the breakpoint won't
7121 be cleared. We probably can still clear the breakpoint, but
7122 since the other PC value is never presented to user, user
7123 can only find it by guessing, and it does not seem important
7126 /* For each line spec given, delete bps which correspond
7127 to it. Do it in two passes, solely to preserve the current
7128 behavior that from_tty is forced true if we delete more than
7132 for (i
= 0; i
< sals
.nelts
; i
++)
7134 /* If exact pc given, clear bpts at that pc.
7135 If line given (pc == 0), clear all bpts on specified line.
7136 If defaulting, clear all bpts on default line
7139 defaulting sal.pc != 0 tests to do
7144 1 0 <can't happen> */
7148 /* Find all matching breakpoints and add them to
7153 /* Are we going to delete b? */
7154 if (b
->type
!= bp_none
7155 && b
->type
!= bp_watchpoint
7156 && b
->type
!= bp_hardware_watchpoint
7157 && b
->type
!= bp_read_watchpoint
7158 && b
->type
!= bp_access_watchpoint
)
7160 struct bp_location
*loc
= b
->loc
;
7161 for (; loc
; loc
= loc
->next
)
7163 int pc_match
= sal
.pc
7164 && (loc
->address
== sal
.pc
)
7165 && (!section_is_overlay (loc
->section
)
7166 || loc
->section
== sal
.section
);
7167 int line_match
= ((default_match
|| (0 == sal
.pc
))
7168 && b
->source_file
!= NULL
7169 && sal
.symtab
!= NULL
7170 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7171 && b
->line_number
== sal
.line
);
7172 if (pc_match
|| line_match
)
7181 VEC_safe_push(breakpoint_p
, found
, b
);
7184 /* Now go thru the 'found' chain and delete them. */
7185 if (VEC_empty(breakpoint_p
, found
))
7188 error (_("No breakpoint at %s."), arg
);
7190 error (_("No breakpoint at this line."));
7193 if (VEC_length(breakpoint_p
, found
) > 1)
7194 from_tty
= 1; /* Always report if deleted more than one */
7197 if (VEC_length(breakpoint_p
, found
) == 1)
7198 printf_unfiltered (_("Deleted breakpoint "));
7200 printf_unfiltered (_("Deleted breakpoints "));
7202 breakpoints_changed ();
7204 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7207 printf_unfiltered ("%d ", b
->number
);
7208 delete_breakpoint (b
);
7211 putchar_unfiltered ('\n');
7214 /* Delete breakpoint in BS if they are `delete' breakpoints and
7215 all breakpoints that are marked for deletion, whether hit or not.
7216 This is called after any breakpoint is hit, or after errors. */
7219 breakpoint_auto_delete (bpstat bs
)
7221 struct breakpoint
*b
, *temp
;
7223 for (; bs
; bs
= bs
->next
)
7224 if (bs
->breakpoint_at
7225 && bs
->breakpoint_at
->owner
7226 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7228 delete_breakpoint (bs
->breakpoint_at
->owner
);
7230 ALL_BREAKPOINTS_SAFE (b
, temp
)
7232 if (b
->disposition
== disp_del_at_next_stop
)
7233 delete_breakpoint (b
);
7237 /* A cleanup function which destroys a vector. */
7240 do_vec_free (void *p
)
7242 VEC(bp_location_p
) **vec
= p
;
7244 VEC_free (bp_location_p
, *vec
);
7247 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7248 into the inferior, only remove already-inserted locations that no
7249 longer should be inserted. Functions that delete a breakpoint or
7250 breakpoints should pass false, so that deleting a breakpoint
7251 doesn't have the side effect of inserting the locations of other
7252 breakpoints that are marked not-inserted, but should_be_inserted
7253 returns true on them.
7255 This behaviour is useful is situations close to tear-down -- e.g.,
7256 after an exec, while the target still has execution, but breakpoint
7257 shadows of the previous executable image should *NOT* be restored
7258 to the new image; or before detaching, where the target still has
7259 execution and wants to delete breakpoints from GDB's lists, and all
7260 breakpoints had already been removed from the inferior. */
7263 update_global_location_list (int should_insert
)
7265 struct breakpoint
*b
;
7266 struct bp_location
**next
= &bp_location_chain
;
7267 struct bp_location
*loc
;
7268 struct bp_location
*loc2
;
7269 VEC(bp_location_p
) *old_locations
= NULL
;
7272 struct cleanup
*cleanups
;
7274 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
7275 /* Store old locations for future reference. */
7276 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7277 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7279 bp_location_chain
= NULL
;
7282 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7285 next
= &(loc
->global_next
);
7290 /* Identify bp_location instances that are no longer present in the new
7291 list, and therefore should be freed. Note that it's not necessary that
7292 those locations should be removed from inferior -- if there's another
7293 location at the same address (previously marked as duplicate),
7294 we don't need to remove/insert the location. */
7295 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7297 /* Tells if 'loc' is found amoung the new locations. If not, we
7299 int found_object
= 0;
7300 /* Tells if the location should remain inserted in the target. */
7301 int keep_in_target
= 0;
7303 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7310 /* If this location is no longer present, and inserted, look if there's
7311 maybe a new location at the same address. If so, mark that one
7312 inserted, and don't remove this one. This is needed so that we
7313 don't have a time window where a breakpoint at certain location is not
7318 /* If the location is inserted now, we might have to remove it. */
7320 if (found_object
&& should_be_inserted (loc
))
7322 /* The location is still present in the location list, and still
7323 should be inserted. Don't do anything. */
7328 /* The location is either no longer present, or got disabled.
7329 See if there's another location at the same address, in which
7330 case we don't need to remove this one from the target. */
7331 if (breakpoint_address_is_meaningful (loc
->owner
))
7332 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7334 /* For the sake of should_insert_location. The
7335 call to check_duplicates will fix up this later. */
7336 loc2
->duplicate
= 0;
7337 if (should_be_inserted (loc2
)
7338 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7341 loc2
->target_info
= loc
->target_info
;
7348 if (!keep_in_target
)
7350 if (remove_breakpoint (loc
, mark_uninserted
))
7352 /* This is just about all we can do. We could keep this
7353 location on the global list, and try to remove it next
7354 time, but there's no particular reason why we will
7357 Note that at this point, loc->owner is still valid,
7358 as delete_breakpoint frees the breakpoint only
7359 after calling us. */
7360 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7361 loc
->owner
->number
);
7369 if (removed
&& non_stop
)
7371 /* This location was removed from the targets. In non-stop mode,
7372 a race condition is possible where we've removed a breakpoint,
7373 but stop events for that breakpoint are already queued and will
7374 arrive later. To suppress spurious SIGTRAPs reported to user,
7375 we keep this breakpoint location for a bit, and will retire it
7376 after we see 3 * thread_count events.
7377 The theory here is that reporting of events should,
7378 "on the average", be fair, so after that many event we'll see
7379 events from all threads that have anything of interest, and no
7380 longer need to keep this breakpoint. This is just a
7381 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7382 which is usability issue, but not a correctness problem. */
7383 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7386 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7389 free_bp_location (loc
);
7395 check_duplicates (b
);
7398 if (breakpoints_always_inserted_mode () && should_insert
7399 && (have_live_inferiors ()
7400 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
7401 insert_breakpoint_locations ();
7403 do_cleanups (cleanups
);
7407 breakpoint_retire_moribund (void)
7409 struct bp_location
*loc
;
7412 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7413 if (--(loc
->events_till_retirement
) == 0)
7415 free_bp_location (loc
);
7416 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7422 update_global_location_list_nothrow (int inserting
)
7424 struct gdb_exception e
;
7425 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7426 update_global_location_list (inserting
);
7429 /* Clear BPT from a BPS. */
7431 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7434 for (bs
= bps
; bs
; bs
= bs
->next
)
7435 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7437 bs
->breakpoint_at
= NULL
;
7439 /* bs->commands will be freed later. */
7443 /* Callback for iterate_over_threads. */
7445 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7447 struct breakpoint
*bpt
= data
;
7448 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7452 /* Delete a breakpoint and clean up all traces of it in the data
7456 delete_breakpoint (struct breakpoint
*bpt
)
7458 struct breakpoint
*b
;
7459 struct bp_location
*loc
, *next
;
7461 gdb_assert (bpt
!= NULL
);
7463 /* Has this bp already been deleted? This can happen because multiple
7464 lists can hold pointers to bp's. bpstat lists are especial culprits.
7466 One example of this happening is a watchpoint's scope bp. When the
7467 scope bp triggers, we notice that the watchpoint is out of scope, and
7468 delete it. We also delete its scope bp. But the scope bp is marked
7469 "auto-deleting", and is already on a bpstat. That bpstat is then
7470 checked for auto-deleting bp's, which are deleted.
7472 A real solution to this problem might involve reference counts in bp's,
7473 and/or giving them pointers back to their referencing bpstat's, and
7474 teaching delete_breakpoint to only free a bp's storage when no more
7475 references were extent. A cheaper bandaid was chosen. */
7476 if (bpt
->type
== bp_none
)
7479 observer_notify_breakpoint_deleted (bpt
->number
);
7481 if (breakpoint_chain
== bpt
)
7482 breakpoint_chain
= bpt
->next
;
7487 b
->next
= bpt
->next
;
7491 free_command_lines (&bpt
->commands
);
7492 if (bpt
->cond_string
!= NULL
)
7493 xfree (bpt
->cond_string
);
7494 if (bpt
->addr_string
!= NULL
)
7495 xfree (bpt
->addr_string
);
7496 if (bpt
->exp
!= NULL
)
7498 if (bpt
->exp_string
!= NULL
)
7499 xfree (bpt
->exp_string
);
7500 if (bpt
->val
!= NULL
)
7501 value_free (bpt
->val
);
7502 if (bpt
->source_file
!= NULL
)
7503 xfree (bpt
->source_file
);
7504 if (bpt
->exec_pathname
!= NULL
)
7505 xfree (bpt
->exec_pathname
);
7507 /* Be sure no bpstat's are pointing at it after it's been freed. */
7508 /* FIXME, how can we find all bpstat's?
7509 We just check stop_bpstat for now. Note that we cannot just
7510 remove bpstats pointing at bpt from the stop_bpstat list
7511 entirely, as breakpoint commands are associated with the bpstat;
7512 if we remove it here, then the later call to
7513 bpstat_do_actions (&stop_bpstat);
7514 in event-top.c won't do anything, and temporary breakpoints
7515 with commands won't work. */
7517 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7519 /* Now that breakpoint is removed from breakpoint
7520 list, update the global location list. This
7521 will remove locations that used to belong to
7522 this breakpoint. Do this before freeing
7523 the breakpoint itself, since remove_breakpoint
7524 looks at location's owner. It might be better
7525 design to have location completely self-contained,
7526 but it's not the case now. */
7527 update_global_location_list (0);
7530 /* On the chance that someone will soon try again to delete this same
7531 bp, we mark it as deleted before freeing its storage. */
7532 bpt
->type
= bp_none
;
7538 do_delete_breakpoint_cleanup (void *b
)
7540 delete_breakpoint (b
);
7544 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7546 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7550 delete_command (char *arg
, int from_tty
)
7552 struct breakpoint
*b
, *temp
;
7558 int breaks_to_delete
= 0;
7560 /* Delete all breakpoints if no argument.
7561 Do not delete internal or call-dummy breakpoints, these
7562 have to be deleted with an explicit breakpoint number argument. */
7565 if (b
->type
!= bp_call_dummy
7566 && b
->type
!= bp_shlib_event
7567 && b
->type
!= bp_thread_event
7568 && b
->type
!= bp_overlay_event
7569 && b
->type
!= bp_longjmp_master
7572 breaks_to_delete
= 1;
7577 /* Ask user only if there are some breakpoints to delete. */
7579 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7581 ALL_BREAKPOINTS_SAFE (b
, temp
)
7583 if (b
->type
!= bp_call_dummy
7584 && b
->type
!= bp_shlib_event
7585 && b
->type
!= bp_thread_event
7586 && b
->type
!= bp_overlay_event
7587 && b
->type
!= bp_longjmp_master
7589 delete_breakpoint (b
);
7594 map_breakpoint_numbers (arg
, delete_breakpoint
);
7598 all_locations_are_pending (struct bp_location
*loc
)
7600 for (; loc
; loc
= loc
->next
)
7601 if (!loc
->shlib_disabled
)
7606 /* Subroutine of update_breakpoint_locations to simplify it.
7607 Return non-zero if multiple fns in list LOC have the same name.
7608 Null names are ignored. */
7611 ambiguous_names_p (struct bp_location
*loc
)
7613 struct bp_location
*l
;
7614 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7615 (int (*) (const void *, const void *)) streq
,
7616 NULL
, xcalloc
, xfree
);
7618 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7621 const char *name
= l
->function_name
;
7623 /* Allow for some names to be NULL, ignore them. */
7627 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7629 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7644 update_breakpoint_locations (struct breakpoint
*b
,
7645 struct symtabs_and_lines sals
)
7649 struct bp_location
*existing_locations
= b
->loc
;
7651 /* If there's no new locations, and all existing locations
7652 are pending, don't do anything. This optimizes
7653 the common case where all locations are in the same
7654 shared library, that was unloaded. We'd like to
7655 retain the location, so that when the library
7656 is loaded again, we don't loose the enabled/disabled
7657 status of the individual locations. */
7658 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7663 for (i
= 0; i
< sals
.nelts
; ++i
)
7665 struct bp_location
*new_loc
=
7666 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7668 /* Reparse conditions, they might contain references to the
7670 if (b
->cond_string
!= NULL
)
7672 struct gdb_exception e
;
7675 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7677 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7682 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7683 b
->number
, e
.message
);
7684 new_loc
->enabled
= 0;
7688 if (b
->source_file
!= NULL
)
7689 xfree (b
->source_file
);
7690 if (sals
.sals
[i
].symtab
== NULL
)
7691 b
->source_file
= NULL
;
7693 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
7695 if (b
->line_number
== 0)
7696 b
->line_number
= sals
.sals
[i
].line
;
7699 /* Update locations of permanent breakpoints. */
7700 if (b
->enable_state
== bp_permanent
)
7701 make_breakpoint_permanent (b
);
7703 /* If possible, carry over 'disable' status from existing breakpoints. */
7705 struct bp_location
*e
= existing_locations
;
7706 /* If there are multiple breakpoints with the same function name,
7707 e.g. for inline functions, comparing function names won't work.
7708 Instead compare pc addresses; this is just a heuristic as things
7709 may have moved, but in practice it gives the correct answer
7710 often enough until a better solution is found. */
7711 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7713 for (; e
; e
= e
->next
)
7715 if (!e
->enabled
&& e
->function_name
)
7717 struct bp_location
*l
= b
->loc
;
7718 if (have_ambiguous_names
)
7720 for (; l
; l
= l
->next
)
7721 if (e
->address
== l
->address
)
7729 for (; l
; l
= l
->next
)
7730 if (l
->function_name
7731 && strcmp (e
->function_name
, l
->function_name
) == 0)
7741 update_global_location_list (1);
7745 /* Reset a breakpoint given it's struct breakpoint * BINT.
7746 The value we return ends up being the return value from catch_errors.
7747 Unused in this case. */
7750 breakpoint_re_set_one (void *bint
)
7752 /* get past catch_errs */
7753 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7757 int *not_found_ptr
= ¬_found
;
7758 struct symtabs_and_lines sals
= {};
7759 struct symtabs_and_lines expanded
;
7761 enum enable_state save_enable
;
7762 struct gdb_exception e
;
7763 struct cleanup
*cleanups
;
7768 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7772 case bp_hardware_breakpoint
:
7774 if (b
->addr_string
== NULL
)
7776 /* Anything without a string can't be re-set. */
7777 delete_breakpoint (b
);
7781 set_language (b
->language
);
7782 input_radix
= b
->input_radix
;
7784 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7786 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7791 int not_found_and_ok
= 0;
7792 /* For pending breakpoints, it's expected that parsing
7793 will fail until the right shared library is loaded.
7794 User has already told to create pending breakpoints and
7795 don't need extra messages. If breakpoint is in bp_shlib_disabled
7796 state, then user already saw the message about that breakpoint
7797 being disabled, and don't want to see more errors. */
7799 && (b
->condition_not_parsed
7800 || (b
->loc
&& b
->loc
->shlib_disabled
)
7801 || b
->enable_state
== bp_disabled
))
7802 not_found_and_ok
= 1;
7804 if (!not_found_and_ok
)
7806 /* We surely don't want to warn about the same breakpoint
7807 10 times. One solution, implemented here, is disable
7808 the breakpoint on error. Another solution would be to
7809 have separate 'warning emitted' flag. Since this
7810 happens only when a binary has changed, I don't know
7811 which approach is better. */
7812 b
->enable_state
= bp_disabled
;
7813 throw_exception (e
);
7820 gdb_assert (sals
.nelts
== 1);
7821 resolve_sal_pc (&sals
.sals
[0]);
7822 if (b
->condition_not_parsed
&& s
&& s
[0])
7824 char *cond_string
= 0;
7828 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7829 &cond_string
, &thread
, &task
);
7831 b
->cond_string
= cond_string
;
7834 b
->condition_not_parsed
= 0;
7836 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7837 cleanups
= make_cleanup (xfree
, sals
.sals
);
7838 update_breakpoint_locations (b
, expanded
);
7839 do_cleanups (cleanups
);
7843 case bp_hardware_watchpoint
:
7844 case bp_read_watchpoint
:
7845 case bp_access_watchpoint
:
7846 /* Watchpoint can be either on expression using entirely global variables,
7847 or it can be on local variables.
7849 Watchpoints of the first kind are never auto-deleted, and even persist
7850 across program restarts. Since they can use variables from shared
7851 libraries, we need to reparse expression as libraries are loaded
7854 Watchpoints on local variables can also change meaning as result
7855 of solib event. For example, if a watchpoint uses both a local and
7856 a global variables in expression, it's a local watchpoint, but
7857 unloading of a shared library will make the expression invalid.
7858 This is not a very common use case, but we still re-evaluate
7859 expression, to avoid surprises to the user.
7861 Note that for local watchpoints, we re-evaluate it only if
7862 watchpoints frame id is still valid. If it's not, it means
7863 the watchpoint is out of scope and will be deleted soon. In fact,
7864 I'm not sure we'll ever be called in this case.
7866 If a local watchpoint's frame id is still valid, then
7867 b->exp_valid_block is likewise valid, and we can safely use it.
7869 Don't do anything about disabled watchpoints, since they will
7870 be reevaluated again when enabled. */
7871 update_watchpoint (b
, 1 /* reparse */);
7873 /* We needn't really do anything to reset these, since the mask
7874 that requests them is unaffected by e.g., new libraries being
7880 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7882 /* Delete overlay event and longjmp master breakpoints; they will be
7883 reset later by breakpoint_re_set. */
7884 case bp_overlay_event
:
7885 case bp_longjmp_master
:
7886 delete_breakpoint (b
);
7889 /* This breakpoint is special, it's set up when the inferior
7890 starts and we really don't want to touch it. */
7891 case bp_shlib_event
:
7893 /* Like bp_shlib_event, this breakpoint type is special.
7894 Once it is set up, we do not want to touch it. */
7895 case bp_thread_event
:
7897 /* Keep temporary breakpoints, which can be encountered when we step
7898 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7899 Otherwise these should have been blown away via the cleanup chain
7900 or by breakpoint_init_inferior when we rerun the executable. */
7903 case bp_watchpoint_scope
:
7905 case bp_step_resume
:
7907 case bp_longjmp_resume
:
7914 /* Re-set all breakpoints after symbols have been re-loaded. */
7916 breakpoint_re_set (void)
7918 struct breakpoint
*b
, *temp
;
7919 enum language save_language
;
7920 int save_input_radix
;
7922 save_language
= current_language
->la_language
;
7923 save_input_radix
= input_radix
;
7924 ALL_BREAKPOINTS_SAFE (b
, temp
)
7926 /* Format possible error msg */
7927 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7929 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7930 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7931 do_cleanups (cleanups
);
7933 set_language (save_language
);
7934 input_radix
= save_input_radix
;
7936 create_overlay_event_breakpoint ("_ovly_debug_event");
7937 create_longjmp_master_breakpoint ("longjmp");
7938 create_longjmp_master_breakpoint ("_longjmp");
7939 create_longjmp_master_breakpoint ("siglongjmp");
7940 create_longjmp_master_breakpoint ("_siglongjmp");
7943 /* Reset the thread number of this breakpoint:
7945 - If the breakpoint is for all threads, leave it as-is.
7946 - Else, reset it to the current thread for inferior_ptid. */
7948 breakpoint_re_set_thread (struct breakpoint
*b
)
7950 if (b
->thread
!= -1)
7952 if (in_thread_list (inferior_ptid
))
7953 b
->thread
= pid_to_thread_id (inferior_ptid
);
7957 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7958 If from_tty is nonzero, it prints a message to that effect,
7959 which ends with a period (no newline). */
7962 set_ignore_count (int bptnum
, int count
, int from_tty
)
7964 struct breakpoint
*b
;
7970 if (b
->number
== bptnum
)
7972 b
->ignore_count
= count
;
7976 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7978 else if (count
== 1)
7979 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7982 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7985 breakpoints_changed ();
7986 observer_notify_breakpoint_modified (b
->number
);
7990 error (_("No breakpoint number %d."), bptnum
);
7994 make_breakpoint_silent (struct breakpoint
*b
)
7996 /* Silence the breakpoint. */
8000 /* Command to set ignore-count of breakpoint N to COUNT. */
8003 ignore_command (char *args
, int from_tty
)
8009 error_no_arg (_("a breakpoint number"));
8011 num
= get_number (&p
);
8013 error (_("bad breakpoint number: '%s'"), args
);
8015 error (_("Second argument (specified ignore-count) is missing."));
8017 set_ignore_count (num
,
8018 longest_to_int (value_as_long (parse_and_eval (p
))),
8021 printf_filtered ("\n");
8024 /* Call FUNCTION on each of the breakpoints
8025 whose numbers are given in ARGS. */
8028 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
8033 struct breakpoint
*b
, *tmp
;
8037 error_no_arg (_("one or more breakpoint numbers"));
8044 num
= get_number_or_range (&p1
);
8047 warning (_("bad breakpoint number at or near '%s'"), p
);
8051 ALL_BREAKPOINTS_SAFE (b
, tmp
)
8052 if (b
->number
== num
)
8054 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
8057 if (related_breakpoint
)
8058 function (related_breakpoint
);
8062 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
8068 static struct bp_location
*
8069 find_location_by_number (char *number
)
8071 char *dot
= strchr (number
, '.');
8075 struct breakpoint
*b
;
8076 struct bp_location
*loc
;
8081 bp_num
= get_number_or_range (&p1
);
8083 error (_("Bad breakpoint number '%s'"), number
);
8086 if (b
->number
== bp_num
)
8091 if (!b
|| b
->number
!= bp_num
)
8092 error (_("Bad breakpoint number '%s'"), number
);
8095 loc_num
= get_number_or_range (&p1
);
8097 error (_("Bad breakpoint location number '%s'"), number
);
8101 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
8104 error (_("Bad breakpoint location number '%s'"), dot
+1);
8110 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8111 If from_tty is nonzero, it prints a message to that effect,
8112 which ends with a period (no newline). */
8115 disable_breakpoint (struct breakpoint
*bpt
)
8117 /* Never disable a watchpoint scope breakpoint; we want to
8118 hit them when we leave scope so we can delete both the
8119 watchpoint and its scope breakpoint at that time. */
8120 if (bpt
->type
== bp_watchpoint_scope
)
8123 /* You can't disable permanent breakpoints. */
8124 if (bpt
->enable_state
== bp_permanent
)
8127 bpt
->enable_state
= bp_disabled
;
8129 update_global_location_list (0);
8131 observer_notify_breakpoint_modified (bpt
->number
);
8135 disable_command (char *args
, int from_tty
)
8137 struct breakpoint
*bpt
;
8139 ALL_BREAKPOINTS (bpt
)
8143 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8149 case bp_hardware_breakpoint
:
8151 case bp_hardware_watchpoint
:
8152 case bp_read_watchpoint
:
8153 case bp_access_watchpoint
:
8154 disable_breakpoint (bpt
);
8158 else if (strchr (args
, '.'))
8160 struct bp_location
*loc
= find_location_by_number (args
);
8163 update_global_location_list (0);
8166 map_breakpoint_numbers (args
, disable_breakpoint
);
8170 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8172 int target_resources_ok
, other_type_used
;
8175 if (bpt
->type
== bp_hardware_breakpoint
)
8178 i
= hw_breakpoint_used_count ();
8179 target_resources_ok
=
8180 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8182 if (target_resources_ok
== 0)
8183 error (_("No hardware breakpoint support in the target."));
8184 else if (target_resources_ok
< 0)
8185 error (_("Hardware breakpoints used exceeds limit."));
8188 if (bpt
->type
== bp_watchpoint
8189 || bpt
->type
== bp_hardware_watchpoint
8190 || bpt
->type
== bp_read_watchpoint
8191 || bpt
->type
== bp_access_watchpoint
)
8193 struct gdb_exception e
;
8195 TRY_CATCH (e
, RETURN_MASK_ALL
)
8197 update_watchpoint (bpt
, 1 /* reparse */);
8201 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
8207 if (bpt
->enable_state
!= bp_permanent
)
8208 bpt
->enable_state
= bp_enabled
;
8209 bpt
->disposition
= disposition
;
8210 update_global_location_list (1);
8211 breakpoints_changed ();
8213 observer_notify_breakpoint_modified (bpt
->number
);
8218 enable_breakpoint (struct breakpoint
*bpt
)
8220 do_enable_breakpoint (bpt
, bpt
->disposition
);
8223 /* The enable command enables the specified breakpoints (or all defined
8224 breakpoints) so they once again become (or continue to be) effective
8225 in stopping the inferior. */
8228 enable_command (char *args
, int from_tty
)
8230 struct breakpoint
*bpt
;
8232 ALL_BREAKPOINTS (bpt
)
8236 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8242 case bp_hardware_breakpoint
:
8244 case bp_hardware_watchpoint
:
8245 case bp_read_watchpoint
:
8246 case bp_access_watchpoint
:
8247 enable_breakpoint (bpt
);
8251 else if (strchr (args
, '.'))
8253 struct bp_location
*loc
= find_location_by_number (args
);
8256 update_global_location_list (1);
8259 map_breakpoint_numbers (args
, enable_breakpoint
);
8263 enable_once_breakpoint (struct breakpoint
*bpt
)
8265 do_enable_breakpoint (bpt
, disp_disable
);
8269 enable_once_command (char *args
, int from_tty
)
8271 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8275 enable_delete_breakpoint (struct breakpoint
*bpt
)
8277 do_enable_breakpoint (bpt
, disp_del
);
8281 enable_delete_command (char *args
, int from_tty
)
8283 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8287 set_breakpoint_cmd (char *args
, int from_tty
)
8292 show_breakpoint_cmd (char *args
, int from_tty
)
8296 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8298 struct symtabs_and_lines
8299 decode_line_spec_1 (char *string
, int funfirstline
)
8301 struct symtabs_and_lines sals
;
8303 error (_("Empty line specification."));
8304 if (default_breakpoint_valid
)
8305 sals
= decode_line_1 (&string
, funfirstline
,
8306 default_breakpoint_symtab
,
8307 default_breakpoint_line
,
8308 (char ***) NULL
, NULL
);
8310 sals
= decode_line_1 (&string
, funfirstline
,
8311 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8313 error (_("Junk at end of line specification: %s"), string
);
8317 /* Create and insert a raw software breakpoint at PC. Return an
8318 identifier, which should be used to remove the breakpoint later.
8319 In general, places which call this should be using something on the
8320 breakpoint chain instead; this function should be eliminated
8324 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8326 struct bp_target_info
*bp_tgt
;
8328 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8329 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8331 bp_tgt
->placed_address
= pc
;
8332 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
8334 /* Could not insert the breakpoint. */
8342 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8345 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
8347 struct bp_target_info
*bp_tgt
= bp
;
8350 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
8356 /* One (or perhaps two) breakpoints used for software single stepping. */
8358 static void *single_step_breakpoints
[2];
8359 static struct gdbarch
*single_step_gdbarch
[2];
8361 /* Create and insert a breakpoint for software single step. */
8364 insert_single_step_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR next_pc
)
8368 if (single_step_breakpoints
[0] == NULL
)
8370 bpt_p
= &single_step_breakpoints
[0];
8371 single_step_gdbarch
[0] = gdbarch
;
8375 gdb_assert (single_step_breakpoints
[1] == NULL
);
8376 bpt_p
= &single_step_breakpoints
[1];
8377 single_step_gdbarch
[1] = gdbarch
;
8380 /* NOTE drow/2006-04-11: A future improvement to this function would be
8381 to only create the breakpoints once, and actually put them on the
8382 breakpoint chain. That would let us use set_raw_breakpoint. We could
8383 adjust the addresses each time they were needed. Doing this requires
8384 corresponding changes elsewhere where single step breakpoints are
8385 handled, however. So, for now, we use this. */
8387 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, next_pc
);
8389 error (_("Could not insert single-step breakpoint at 0x%s"),
8390 paddr_nz (next_pc
));
8393 /* Remove and delete any breakpoints used for software single step. */
8396 remove_single_step_breakpoints (void)
8398 gdb_assert (single_step_breakpoints
[0] != NULL
);
8400 /* See insert_single_step_breakpoint for more about this deprecated
8402 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
8403 single_step_breakpoints
[0]);
8404 single_step_gdbarch
[0] = NULL
;
8405 single_step_breakpoints
[0] = NULL
;
8407 if (single_step_breakpoints
[1] != NULL
)
8409 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
8410 single_step_breakpoints
[1]);
8411 single_step_gdbarch
[1] = NULL
;
8412 single_step_breakpoints
[1] = NULL
;
8416 /* Check whether a software single-step breakpoint is inserted at PC. */
8419 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8423 for (i
= 0; i
< 2; i
++)
8425 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8426 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8433 /* Tracepoint-specific operations. */
8435 /* Set tracepoint count to NUM. */
8437 set_tracepoint_count (int num
)
8439 tracepoint_count
= num
;
8440 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
8444 trace_command (char *arg
, int from_tty
)
8446 break_command_really (get_current_arch (),
8448 NULL
, 0, 1 /* parse arg */,
8449 0 /* tempflag */, 0 /* hardwareflag */,
8451 0 /* Ignore count */,
8452 pending_break_support
,
8456 set_tracepoint_count (breakpoint_count
);
8459 /* Print information on tracepoint number TPNUM_EXP, or all if
8463 tracepoints_info (char *tpnum_exp
, int from_tty
)
8465 struct breakpoint
*b
;
8466 int tps_to_list
= 0;
8468 /* In the no-arguments case, say "No tracepoints" if none found. */
8481 ui_out_message (uiout
, 0, "No tracepoints.\n");
8486 /* Otherwise be the same as "info break". */
8487 breakpoints_info (tpnum_exp
, from_tty
);
8490 /* The 'enable trace' command enables tracepoints.
8491 Not supported by all targets. */
8493 enable_trace_command (char *args
, int from_tty
)
8495 enable_command (args
, from_tty
);
8498 /* The 'disable trace' command disables tracepoints.
8499 Not supported by all targets. */
8501 disable_trace_command (char *args
, int from_tty
)
8503 disable_command (args
, from_tty
);
8506 /* Remove a tracepoint (or all if no argument) */
8508 delete_trace_command (char *arg
, int from_tty
)
8510 struct breakpoint
*b
, *temp
;
8516 int breaks_to_delete
= 0;
8518 /* Delete all breakpoints if no argument.
8519 Do not delete internal or call-dummy breakpoints, these
8520 have to be deleted with an explicit breakpoint number argument. */
8525 breaks_to_delete
= 1;
8530 /* Ask user only if there are some breakpoints to delete. */
8532 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
8534 ALL_BREAKPOINTS_SAFE (b
, temp
)
8536 if (b
->type
== bp_tracepoint
8538 delete_breakpoint (b
);
8543 map_breakpoint_numbers (arg
, delete_breakpoint
);
8546 /* Set passcount for tracepoint.
8548 First command argument is passcount, second is tracepoint number.
8549 If tracepoint number omitted, apply to most recently defined.
8550 Also accepts special argument "all". */
8553 trace_pass_command (char *args
, int from_tty
)
8555 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
8559 if (args
== 0 || *args
== 0)
8560 error (_("passcount command requires an argument (count + optional TP num)"));
8562 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
8564 while (*args
&& isspace ((int) *args
))
8567 if (*args
&& strncasecmp (args
, "all", 3) == 0)
8569 args
+= 3; /* Skip special argument "all". */
8572 error (_("Junk at end of arguments."));
8575 t1
= get_tracepoint_by_number (&args
, 1, 1);
8581 ALL_TRACEPOINTS (t2
)
8582 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
8584 t2
->pass_count
= count
;
8585 observer_notify_tracepoint_modified (t2
->number
);
8587 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8591 t1
= get_tracepoint_by_number (&args
, 1, 0);
8598 get_tracepoint (int num
)
8600 struct breakpoint
*t
;
8603 if (t
->number
== num
)
8609 /* Utility: parse a tracepoint number and look it up in the list.
8610 If MULTI_P is true, there might be a range of tracepoints in ARG.
8611 if OPTIONAL_P is true, then if the argument is missing, the most
8612 recent tracepoint (tracepoint_count) is returned. */
8614 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
8616 extern int tracepoint_count
;
8617 struct breakpoint
*t
;
8619 char *instring
= arg
== NULL
? NULL
: *arg
;
8621 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
8624 tpnum
= tracepoint_count
;
8626 error_no_arg (_("tracepoint number"));
8629 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
8633 if (instring
&& *instring
)
8634 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8637 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8642 if (t
->number
== tpnum
)
8647 /* FIXME: if we are in the middle of a range we don't want to give
8648 a message. The current interface to get_number_or_range doesn't
8649 allow us to discover this. */
8650 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
8654 /* save-tracepoints command */
8656 tracepoint_save_command (char *args
, int from_tty
)
8658 struct breakpoint
*tp
;
8660 struct action_line
*line
;
8662 char *i1
= " ", *i2
= " ";
8663 char *indent
, *actionline
, *pathname
;
8665 struct cleanup
*cleanup
;
8667 if (args
== 0 || *args
== 0)
8668 error (_("Argument required (file name in which to save tracepoints)"));
8670 /* See if we have anything to save. */
8671 ALL_TRACEPOINTS (tp
)
8678 warning (_("save-tracepoints: no tracepoints to save."));
8682 pathname
= tilde_expand (args
);
8683 cleanup
= make_cleanup (xfree
, pathname
);
8684 fp
= fopen (pathname
, "w");
8686 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8687 args
, safe_strerror (errno
));
8688 make_cleanup_fclose (fp
);
8690 ALL_TRACEPOINTS (tp
)
8692 if (tp
->addr_string
)
8693 fprintf (fp
, "trace %s\n", tp
->addr_string
);
8696 sprintf_vma (tmp
, tp
->loc
->address
);
8697 fprintf (fp
, "trace *0x%s\n", tmp
);
8701 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
8705 fprintf (fp
, " actions\n");
8707 for (line
= tp
->actions
; line
; line
= line
->next
)
8709 struct cmd_list_element
*cmd
;
8711 QUIT
; /* allow user to bail out with ^C */
8712 actionline
= line
->action
;
8713 while (isspace ((int) *actionline
))
8716 fprintf (fp
, "%s%s\n", indent
, actionline
);
8717 if (*actionline
!= '#') /* skip for comment lines */
8719 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
8721 error (_("Bad action list item: %s"), actionline
);
8722 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
8724 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
8730 do_cleanups (cleanup
);
8732 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
8736 /* Create a vector of all tracepoints. */
8741 VEC(breakpoint_p
) *tp_vec
= 0;
8742 struct breakpoint
*tp
;
8744 ALL_TRACEPOINTS (tp
)
8746 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
8753 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8754 It is defined as a macro to prevent duplication.
8755 COMMAND should be a string constant containing the name of the command. */
8756 #define BREAK_ARGS_HELP(command) \
8757 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8758 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8759 If a line number is specified, break at start of code for that line.\n\
8760 If a function is specified, break at start of code for that function.\n\
8761 If an address is specified, break at that exact address.\n\
8762 With no LOCATION, uses current execution address of selected stack frame.\n\
8763 This is useful for breaking on return to a stack frame.\n\
8765 THREADNUM is the number from \"info threads\".\n\
8766 CONDITION is a boolean expression.\n\
8768 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8770 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8772 /* List of subcommands for "catch". */
8773 static struct cmd_list_element
*catch_cmdlist
;
8775 /* List of subcommands for "tcatch". */
8776 static struct cmd_list_element
*tcatch_cmdlist
;
8778 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8779 lists, and pass some additional user data to the command function. */
8781 add_catch_command (char *name
, char *docstring
,
8782 void (*sfunc
) (char *args
, int from_tty
,
8783 struct cmd_list_element
*command
),
8784 void *user_data_catch
,
8785 void *user_data_tcatch
)
8787 struct cmd_list_element
*command
;
8789 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8791 set_cmd_sfunc (command
, sfunc
);
8792 set_cmd_context (command
, user_data_catch
);
8794 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8796 set_cmd_sfunc (command
, sfunc
);
8797 set_cmd_context (command
, user_data_tcatch
);
8801 _initialize_breakpoint (void)
8803 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8804 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8805 struct cmd_list_element
*c
;
8807 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8809 breakpoint_chain
= 0;
8810 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8811 before a breakpoint is set. */
8812 breakpoint_count
= 0;
8814 tracepoint_count
= 0;
8816 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8817 Set ignore-count of breakpoint number N to COUNT.\n\
8818 Usage is `ignore N COUNT'."));
8820 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8822 add_com ("commands", class_breakpoint
, commands_command
, _("\
8823 Set commands to be executed when a breakpoint is hit.\n\
8824 Give breakpoint number as argument after \"commands\".\n\
8825 With no argument, the targeted breakpoint is the last one set.\n\
8826 The commands themselves follow starting on the next line.\n\
8827 Type a line containing \"end\" to indicate the end of them.\n\
8828 Give \"silent\" as the first line to make the breakpoint silent;\n\
8829 then no output is printed when it is hit, except what the commands print."));
8831 add_com ("condition", class_breakpoint
, condition_command
, _("\
8832 Specify breakpoint number N to break only if COND is true.\n\
8833 Usage is `condition N COND', where N is an integer and COND is an\n\
8834 expression to be evaluated whenever breakpoint N is reached."));
8836 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8837 Set a temporary breakpoint.\n\
8838 Like \"break\" except the breakpoint is only temporary,\n\
8839 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8840 by using \"enable delete\" on the breakpoint number.\n\
8842 BREAK_ARGS_HELP ("tbreak")));
8843 set_cmd_completer (c
, location_completer
);
8845 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8846 Set a hardware assisted breakpoint.\n\
8847 Like \"break\" except the breakpoint requires hardware support,\n\
8848 some target hardware may not have this support.\n\
8850 BREAK_ARGS_HELP ("hbreak")));
8851 set_cmd_completer (c
, location_completer
);
8853 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8854 Set a temporary hardware assisted breakpoint.\n\
8855 Like \"hbreak\" except the breakpoint is only temporary,\n\
8856 so it will be deleted when hit.\n\
8858 BREAK_ARGS_HELP ("thbreak")));
8859 set_cmd_completer (c
, location_completer
);
8861 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8862 Enable some breakpoints.\n\
8863 Give breakpoint numbers (separated by spaces) as arguments.\n\
8864 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8865 This is used to cancel the effect of the \"disable\" command.\n\
8866 With a subcommand you can enable temporarily."),
8867 &enablelist
, "enable ", 1, &cmdlist
);
8869 add_com ("ab", class_breakpoint
, enable_command
, _("\
8870 Enable some breakpoints.\n\
8871 Give breakpoint numbers (separated by spaces) as arguments.\n\
8872 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8873 This is used to cancel the effect of the \"disable\" command.\n\
8874 With a subcommand you can enable temporarily."));
8876 add_com_alias ("en", "enable", class_breakpoint
, 1);
8878 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8879 Enable some breakpoints.\n\
8880 Give breakpoint numbers (separated by spaces) as arguments.\n\
8881 This is used to cancel the effect of the \"disable\" command.\n\
8882 May be abbreviated to simply \"enable\".\n"),
8883 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8885 add_cmd ("once", no_class
, enable_once_command
, _("\
8886 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8887 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8890 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8891 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8892 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8895 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8896 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8897 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8900 add_cmd ("once", no_class
, enable_once_command
, _("\
8901 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8902 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8905 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8906 Disable some breakpoints.\n\
8907 Arguments are breakpoint numbers with spaces in between.\n\
8908 To disable all breakpoints, give no argument.\n\
8909 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8910 &disablelist
, "disable ", 1, &cmdlist
);
8911 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8912 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8914 add_com ("sb", class_breakpoint
, disable_command
, _("\
8915 Disable some breakpoints.\n\
8916 Arguments are breakpoint numbers with spaces in between.\n\
8917 To disable all breakpoints, give no argument.\n\
8918 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8920 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8921 Disable some breakpoints.\n\
8922 Arguments are breakpoint numbers with spaces in between.\n\
8923 To disable all breakpoints, give no argument.\n\
8924 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8925 This command may be abbreviated \"disable\"."),
8928 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8929 Delete some breakpoints or auto-display expressions.\n\
8930 Arguments are breakpoint numbers with spaces in between.\n\
8931 To delete all breakpoints, give no argument.\n\
8933 Also a prefix command for deletion of other GDB objects.\n\
8934 The \"unset\" command is also an alias for \"delete\"."),
8935 &deletelist
, "delete ", 1, &cmdlist
);
8936 add_com_alias ("d", "delete", class_breakpoint
, 1);
8937 add_com_alias ("del", "delete", class_breakpoint
, 1);
8939 add_com ("db", class_breakpoint
, delete_command
, _("\
8940 Delete some breakpoints.\n\
8941 Arguments are breakpoint numbers with spaces in between.\n\
8942 To delete all breakpoints, give no argument.\n"));
8944 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8945 Delete some breakpoints or auto-display expressions.\n\
8946 Arguments are breakpoint numbers with spaces in between.\n\
8947 To delete all breakpoints, give no argument.\n\
8948 This command may be abbreviated \"delete\"."),
8951 add_com ("clear", class_breakpoint
, clear_command
, _("\
8952 Clear breakpoint at specified line or function.\n\
8953 Argument may be line number, function name, or \"*\" and an address.\n\
8954 If line number is specified, all breakpoints in that line are cleared.\n\
8955 If function is specified, breakpoints at beginning of function are cleared.\n\
8956 If an address is specified, breakpoints at that address are cleared.\n\
8958 With no argument, clears all breakpoints in the line that the selected frame\n\
8961 See also the \"delete\" command which clears breakpoints by number."));
8963 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8964 Set breakpoint at specified line or function.\n"
8965 BREAK_ARGS_HELP ("break")));
8966 set_cmd_completer (c
, location_completer
);
8968 add_com_alias ("b", "break", class_run
, 1);
8969 add_com_alias ("br", "break", class_run
, 1);
8970 add_com_alias ("bre", "break", class_run
, 1);
8971 add_com_alias ("brea", "break", class_run
, 1);
8974 add_com_alias ("ba", "break", class_breakpoint
, 1);
8978 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8979 Break in function/address or break at a line in the current file."),
8980 &stoplist
, "stop ", 1, &cmdlist
);
8981 add_cmd ("in", class_breakpoint
, stopin_command
,
8982 _("Break in function or address."), &stoplist
);
8983 add_cmd ("at", class_breakpoint
, stopat_command
,
8984 _("Break at a line in the current file."), &stoplist
);
8985 add_com ("status", class_info
, breakpoints_info
, _("\
8986 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8987 The \"Type\" column indicates one of:\n\
8988 \tbreakpoint - normal breakpoint\n\
8989 \twatchpoint - watchpoint\n\
8990 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8991 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8992 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8993 address and file/line number respectively.\n\
8995 Convenience variable \"$_\" and default examine address for \"x\"\n\
8996 are set to the address of the last breakpoint listed unless the command\n\
8997 is prefixed with \"server \".\n\n\
8998 Convenience variable \"$bpnum\" contains the number of the last\n\
9002 add_info ("breakpoints", breakpoints_info
, _("\
9003 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9004 The \"Type\" column indicates one of:\n\
9005 \tbreakpoint - normal breakpoint\n\
9006 \twatchpoint - watchpoint\n\
9007 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9008 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9009 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9010 address and file/line number respectively.\n\
9012 Convenience variable \"$_\" and default examine address for \"x\"\n\
9013 are set to the address of the last breakpoint listed unless the command\n\
9014 is prefixed with \"server \".\n\n\
9015 Convenience variable \"$bpnum\" contains the number of the last\n\
9019 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
9020 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9021 The \"Type\" column indicates one of:\n\
9022 \tbreakpoint - normal breakpoint\n\
9023 \twatchpoint - watchpoint\n\
9024 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9025 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9026 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9027 address and file/line number respectively.\n\
9029 Convenience variable \"$_\" and default examine address for \"x\"\n\
9030 are set to the address of the last breakpoint listed unless the command\n\
9031 is prefixed with \"server \".\n\n\
9032 Convenience variable \"$bpnum\" contains the number of the last\n\
9035 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
9036 Status of all breakpoints, or breakpoint number NUMBER.\n\
9037 The \"Type\" column indicates one of:\n\
9038 \tbreakpoint - normal breakpoint\n\
9039 \twatchpoint - watchpoint\n\
9040 \tlongjmp - internal breakpoint used to step through longjmp()\n\
9041 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
9042 \tuntil - internal breakpoint used by the \"until\" command\n\
9043 \tfinish - internal breakpoint used by the \"finish\" command\n\
9044 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9045 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9046 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9047 address and file/line number respectively.\n\
9049 Convenience variable \"$_\" and default examine address for \"x\"\n\
9050 are set to the address of the last breakpoint listed unless the command\n\
9051 is prefixed with \"server \".\n\n\
9052 Convenience variable \"$bpnum\" contains the number of the last\n\
9054 &maintenanceinfolist
);
9056 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
9057 Set catchpoints to catch events."),
9058 &catch_cmdlist
, "catch ",
9059 0/*allow-unknown*/, &cmdlist
);
9061 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
9062 Set temporary catchpoints to catch events."),
9063 &tcatch_cmdlist
, "tcatch ",
9064 0/*allow-unknown*/, &cmdlist
);
9066 /* Add catch and tcatch sub-commands. */
9067 add_catch_command ("catch", _("\
9068 Catch an exception, when caught.\n\
9069 With an argument, catch only exceptions with the given name."),
9070 catch_catch_command
,
9073 add_catch_command ("throw", _("\
9074 Catch an exception, when thrown.\n\
9075 With an argument, catch only exceptions with the given name."),
9076 catch_throw_command
,
9079 add_catch_command ("fork", _("Catch calls to fork."),
9080 catch_fork_command_1
,
9081 (void *) (uintptr_t) catch_fork_permanent
,
9082 (void *) (uintptr_t) catch_fork_temporary
);
9083 add_catch_command ("vfork", _("Catch calls to vfork."),
9084 catch_fork_command_1
,
9085 (void *) (uintptr_t) catch_vfork_permanent
,
9086 (void *) (uintptr_t) catch_vfork_temporary
);
9087 add_catch_command ("exec", _("Catch calls to exec."),
9088 catch_exec_command_1
,
9091 add_catch_command ("exception", _("\
9092 Catch Ada exceptions, when raised.\n\
9093 With an argument, catch only exceptions with the given name."),
9094 catch_ada_exception_command
,
9097 add_catch_command ("assert", _("\
9098 Catch failed Ada assertions, when raised.\n\
9099 With an argument, catch only exceptions with the given name."),
9100 catch_assert_command
,
9104 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
9105 Set a watchpoint for an expression.\n\
9106 A watchpoint stops execution of your program whenever the value of\n\
9107 an expression changes."));
9108 set_cmd_completer (c
, expression_completer
);
9110 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
9111 Set a read watchpoint for an expression.\n\
9112 A watchpoint stops execution of your program whenever the value of\n\
9113 an expression is read."));
9114 set_cmd_completer (c
, expression_completer
);
9116 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
9117 Set a watchpoint for an expression.\n\
9118 A watchpoint stops execution of your program whenever the value of\n\
9119 an expression is either read or written."));
9120 set_cmd_completer (c
, expression_completer
);
9122 add_info ("watchpoints", breakpoints_info
,
9123 _("Synonym for ``info breakpoints''."));
9126 /* XXX: cagney/2005-02-23: This should be a boolean, and should
9127 respond to changes - contrary to the description. */
9128 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
9129 &can_use_hw_watchpoints
, _("\
9130 Set debugger's willingness to use watchpoint hardware."), _("\
9131 Show debugger's willingness to use watchpoint hardware."), _("\
9132 If zero, gdb will not use hardware for new watchpoints, even if\n\
9133 such is available. (However, any hardware watchpoints that were\n\
9134 created before setting this to nonzero, will continue to use watchpoint\n\
9137 show_can_use_hw_watchpoints
,
9138 &setlist
, &showlist
);
9140 can_use_hw_watchpoints
= 1;
9142 /* Tracepoint manipulation commands. */
9144 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
9145 Set a tracepoint at specified line or function.\n\
9147 BREAK_ARGS_HELP ("trace") "\n\
9148 Do \"help tracepoints\" for info on other tracepoint commands."));
9149 set_cmd_completer (c
, location_completer
);
9151 add_com_alias ("tp", "trace", class_alias
, 0);
9152 add_com_alias ("tr", "trace", class_alias
, 1);
9153 add_com_alias ("tra", "trace", class_alias
, 1);
9154 add_com_alias ("trac", "trace", class_alias
, 1);
9156 add_info ("tracepoints", tracepoints_info
, _("\
9157 Status of tracepoints, or tracepoint number NUMBER.\n\
9158 Convenience variable \"$tpnum\" contains the number of the\n\
9159 last tracepoint set."));
9161 add_info_alias ("tp", "tracepoints", 1);
9163 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
9164 Delete specified tracepoints.\n\
9165 Arguments are tracepoint numbers, separated by spaces.\n\
9166 No argument means delete all tracepoints."),
9169 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
9170 Disable specified tracepoints.\n\
9171 Arguments are tracepoint numbers, separated by spaces.\n\
9172 No argument means disable all tracepoints."),
9174 deprecate_cmd (c
, "disable");
9176 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
9177 Enable specified tracepoints.\n\
9178 Arguments are tracepoint numbers, separated by spaces.\n\
9179 No argument means enable all tracepoints."),
9181 deprecate_cmd (c
, "enable");
9183 add_com ("passcount", class_trace
, trace_pass_command
, _("\
9184 Set the passcount for a tracepoint.\n\
9185 The trace will end when the tracepoint has been passed 'count' times.\n\
9186 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
9187 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
9189 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
9190 Save current tracepoint definitions as a script.\n\
9191 Use the 'source' command in another debug session to restore them."));
9192 set_cmd_completer (c
, filename_completer
);
9194 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
9195 Breakpoint specific settings\n\
9196 Configure various breakpoint-specific variables such as\n\
9197 pending breakpoint behavior"),
9198 &breakpoint_set_cmdlist
, "set breakpoint ",
9199 0/*allow-unknown*/, &setlist
);
9200 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
9201 Breakpoint specific settings\n\
9202 Configure various breakpoint-specific variables such as\n\
9203 pending breakpoint behavior"),
9204 &breakpoint_show_cmdlist
, "show breakpoint ",
9205 0/*allow-unknown*/, &showlist
);
9207 add_setshow_auto_boolean_cmd ("pending", no_class
,
9208 &pending_break_support
, _("\
9209 Set debugger's behavior regarding pending breakpoints."), _("\
9210 Show debugger's behavior regarding pending breakpoints."), _("\
9211 If on, an unrecognized breakpoint location will cause gdb to create a\n\
9212 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9213 an error. If auto, an unrecognized breakpoint location results in a\n\
9214 user-query to see if a pending breakpoint should be created."),
9216 show_pending_break_support
,
9217 &breakpoint_set_cmdlist
,
9218 &breakpoint_show_cmdlist
);
9220 pending_break_support
= AUTO_BOOLEAN_AUTO
;
9222 add_setshow_boolean_cmd ("auto-hw", no_class
,
9223 &automatic_hardware_breakpoints
, _("\
9224 Set automatic usage of hardware breakpoints."), _("\
9225 Show automatic usage of hardware breakpoints."), _("\
9226 If set, the debugger will automatically use hardware breakpoints for\n\
9227 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9228 a warning will be emitted for such breakpoints."),
9230 show_automatic_hardware_breakpoints
,
9231 &breakpoint_set_cmdlist
,
9232 &breakpoint_show_cmdlist
);
9234 add_setshow_enum_cmd ("always-inserted", class_support
,
9235 always_inserted_enums
, &always_inserted_mode
, _("\
9236 Set mode for inserting breakpoints."), _("\
9237 Show mode for inserting breakpoints."), _("\
9238 When this mode is off, breakpoints are inserted in inferior when it is\n\
9239 resumed, and removed when execution stops. When this mode is on,\n\
9240 breakpoints are inserted immediately and removed only when the user\n\
9241 deletes the breakpoint. When this mode is auto (which is the default),\n\
9242 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9243 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9244 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9245 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9247 &show_always_inserted_mode
,
9248 &breakpoint_set_cmdlist
,
9249 &breakpoint_show_cmdlist
);
9251 automatic_hardware_breakpoints
= 1;
9253 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);