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 #include "xml-syscall.h"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_delete_breakpoint (struct breakpoint
*);
84 static void enable_once_command (char *, int);
86 static void enable_once_breakpoint (struct breakpoint
*);
88 static void disable_command (char *, int);
90 static void enable_command (char *, int);
92 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
94 static void ignore_command (char *, int);
96 static int breakpoint_re_set_one (void *);
98 static void clear_command (char *, int);
100 static void catch_command (char *, int);
102 static void watch_command (char *, int);
104 static int can_use_hardware_watchpoint (struct value
*);
106 static void break_command_1 (char *, int, int);
108 static void mention (struct breakpoint
*);
110 /* This function is used in gdbtk sources and thus can not be made static. */
111 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
112 struct symtab_and_line
,
115 static void check_duplicates (struct breakpoint
*);
117 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
119 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
123 static void describe_other_breakpoints (struct gdbarch
*, CORE_ADDR
,
124 struct obj_section
*, int);
126 static void breakpoints_info (char *, int);
128 static void breakpoint_1 (int, int);
130 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
132 static int breakpoint_cond_eval (void *);
134 static void cleanup_executing_breakpoints (void *);
136 static void commands_command (char *, int);
138 static void condition_command (char *, int);
140 static int get_number_trailer (char **, int);
142 void set_breakpoint_count (int);
151 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
153 static enum print_stop_action
print_it_typical (bpstat
);
155 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
157 static int watchpoint_check (void *);
159 static void maintenance_info_breakpoints (char *, int);
161 static int hw_breakpoint_used_count (void);
163 static int hw_watchpoint_used_count (enum bptype
, int *);
165 static void hbreak_command (char *, int);
167 static void thbreak_command (char *, int);
169 static void watch_command_1 (char *, int, int);
171 static void rwatch_command (char *, int);
173 static void awatch_command (char *, int);
175 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
177 static void stop_command (char *arg
, int from_tty
);
179 static void stopin_command (char *arg
, int from_tty
);
181 static void stopat_command (char *arg
, int from_tty
);
183 static char *ep_parse_optional_if_clause (char **arg
);
185 static char *ep_parse_optional_filename (char **arg
);
187 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
188 char *arg
, int tempflag
, int from_tty
);
190 static void tcatch_command (char *arg
, int from_tty
);
192 static void ep_skip_leading_whitespace (char **s
);
194 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
196 static void free_bp_location (struct bp_location
*loc
);
198 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
200 static void update_global_location_list (int);
202 static void update_global_location_list_nothrow (int);
204 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
206 static void insert_breakpoint_locations (void);
208 static int syscall_catchpoint_p (struct breakpoint
*b
);
210 static void tracepoints_info (char *, int);
212 static void delete_trace_command (char *, int);
214 static void enable_trace_command (char *, int);
216 static void disable_trace_command (char *, int);
218 static void trace_pass_command (char *, int);
220 static void skip_prologue_sal (struct symtab_and_line
*sal
);
223 /* Flag indicating that a command has proceeded the inferior past the
224 current breakpoint. */
226 static int breakpoint_proceeded
;
229 bpdisp_text (enum bpdisp disp
)
231 /* NOTE: the following values are a part of MI protocol and represent
232 values of 'disp' field returned when inferior stops at a breakpoint. */
233 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
234 return bpdisps
[(int) disp
];
237 /* Prototypes for exported functions. */
238 /* If FALSE, gdb will not use hardware support for watchpoints, even
239 if such is available. */
240 static int can_use_hw_watchpoints
;
243 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
244 struct cmd_list_element
*c
,
247 fprintf_filtered (file
, _("\
248 Debugger's willingness to use watchpoint hardware is %s.\n"),
252 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
253 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
254 for unrecognized breakpoint locations.
255 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
256 static enum auto_boolean pending_break_support
;
258 show_pending_break_support (struct ui_file
*file
, int from_tty
,
259 struct cmd_list_element
*c
,
262 fprintf_filtered (file
, _("\
263 Debugger's behavior regarding pending breakpoints is %s.\n"),
267 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
268 set with "break" but falling in read-only memory.
269 If 0, gdb will warn about such breakpoints, but won't automatically
270 use hardware breakpoints. */
271 static int automatic_hardware_breakpoints
;
273 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
274 struct cmd_list_element
*c
,
277 fprintf_filtered (file
, _("\
278 Automatic usage of hardware breakpoints is %s.\n"),
282 /* If on, gdb will keep breakpoints inserted even as inferior is
283 stopped, and immediately insert any new breakpoints. If off, gdb
284 will insert breakpoints into inferior only when resuming it, and
285 will remove breakpoints upon stop. If auto, GDB will behave as ON
286 if in non-stop mode, and as OFF if all-stop mode.*/
288 static const char always_inserted_auto
[] = "auto";
289 static const char always_inserted_on
[] = "on";
290 static const char always_inserted_off
[] = "off";
291 static const char *always_inserted_enums
[] = {
292 always_inserted_auto
,
297 static const char *always_inserted_mode
= always_inserted_auto
;
299 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
300 struct cmd_list_element
*c
, const char *value
)
302 if (always_inserted_mode
== always_inserted_auto
)
303 fprintf_filtered (file
, _("\
304 Always inserted breakpoint mode is %s (currently %s).\n"),
306 breakpoints_always_inserted_mode () ? "on" : "off");
308 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
312 breakpoints_always_inserted_mode (void)
314 return (always_inserted_mode
== always_inserted_on
315 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
318 void _initialize_breakpoint (void);
320 /* Are we executing breakpoint commands? */
321 static int executing_breakpoint_commands
;
323 /* Are overlay event breakpoints enabled? */
324 static int overlay_events_enabled
;
326 /* Are we executing startup code? */
327 static int executing_startup
;
329 /* Walk the following statement or block through all breakpoints.
330 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
333 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
335 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
336 for (B = breakpoint_chain; \
337 B ? (TMP=B->next, 1): 0; \
340 /* Similar iterators for the low-level breakpoints. */
342 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
344 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
345 for (B = bp_location_chain; \
346 B ? (TMP=B->global_next, 1): 0; \
349 /* Iterator for tracepoints only. */
351 #define ALL_TRACEPOINTS(B) \
352 for (B = breakpoint_chain; B; B = B->next) \
353 if ((B)->type == bp_tracepoint)
355 /* Chains of all breakpoints defined. */
357 struct breakpoint
*breakpoint_chain
;
359 struct bp_location
*bp_location_chain
;
361 /* The locations that no longer correspond to any breakpoint,
362 unlinked from bp_location_chain, but for which a hit
363 may still be reported by a target. */
364 VEC(bp_location_p
) *moribund_locations
= NULL
;
366 /* Number of last breakpoint made. */
368 int breakpoint_count
;
370 /* Number of last tracepoint made. */
372 int tracepoint_count
;
374 /* Return whether a breakpoint is an active enabled breakpoint. */
376 breakpoint_enabled (struct breakpoint
*b
)
378 return (b
->enable_state
== bp_enabled
);
381 /* Set breakpoint count to NUM. */
384 set_breakpoint_count (int num
)
386 breakpoint_count
= num
;
387 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
390 /* Used in run_command to zero the hit count when a new run starts. */
393 clear_breakpoint_hit_counts (void)
395 struct breakpoint
*b
;
401 /* Default address, symtab and line to put a breakpoint at
402 for "break" command with no arg.
403 if default_breakpoint_valid is zero, the other three are
404 not valid, and "break" with no arg is an error.
406 This set by print_stack_frame, which calls set_default_breakpoint. */
408 int default_breakpoint_valid
;
409 CORE_ADDR default_breakpoint_address
;
410 struct symtab
*default_breakpoint_symtab
;
411 int default_breakpoint_line
;
413 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
414 Advance *PP after the string and any trailing whitespace.
416 Currently the string can either be a number or "$" followed by the name
417 of a convenience variable. Making it an expression wouldn't work well
418 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
420 If the string is a NULL pointer, that denotes the last breakpoint.
422 TRAILER is a character which can be found after the number; most
423 commonly this is `-'. If you don't want a trailer, use \0. */
425 get_number_trailer (char **pp
, int trailer
)
427 int retval
= 0; /* default */
431 /* Empty line means refer to the last breakpoint. */
432 return breakpoint_count
;
435 /* Make a copy of the name, so we can null-terminate it
436 to pass to lookup_internalvar(). */
441 while (isalnum (*p
) || *p
== '_')
443 varname
= (char *) alloca (p
- start
+ 1);
444 strncpy (varname
, start
, p
- start
);
445 varname
[p
- start
] = '\0';
446 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
450 printf_filtered (_("Convenience variable must have integer value.\n"));
458 while (*p
>= '0' && *p
<= '9')
461 /* There is no number here. (e.g. "cond a == b"). */
463 /* Skip non-numeric token */
464 while (*p
&& !isspace((int) *p
))
466 /* Return zero, which caller must interpret as error. */
472 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
474 /* Trailing junk: return 0 and let caller print error msg. */
475 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
486 /* Like get_number_trailer, but don't allow a trailer. */
488 get_number (char **pp
)
490 return get_number_trailer (pp
, '\0');
493 /* Parse a number or a range.
494 * A number will be of the form handled by get_number.
495 * A range will be of the form <number1> - <number2>, and
496 * will represent all the integers between number1 and number2,
499 * While processing a range, this fuction is called iteratively;
500 * At each call it will return the next value in the range.
502 * At the beginning of parsing a range, the char pointer PP will
503 * be advanced past <number1> and left pointing at the '-' token.
504 * Subsequent calls will not advance the pointer until the range
505 * is completed. The call that completes the range will advance
506 * pointer PP past <number2>.
510 get_number_or_range (char **pp
)
512 static int last_retval
, end_value
;
513 static char *end_ptr
;
514 static int in_range
= 0;
518 /* Default case: pp is pointing either to a solo number,
519 or to the first number of a range. */
520 last_retval
= get_number_trailer (pp
, '-');
525 /* This is the start of a range (<number1> - <number2>).
526 Skip the '-', parse and remember the second number,
527 and also remember the end of the final token. */
531 while (isspace ((int) *end_ptr
))
532 end_ptr
++; /* skip white space */
533 end_value
= get_number (temp
);
534 if (end_value
< last_retval
)
536 error (_("inverted range"));
538 else if (end_value
== last_retval
)
540 /* degenerate range (number1 == number2). Advance the
541 token pointer so that the range will be treated as a
550 error (_("negative value"));
553 /* pp points to the '-' that betokens a range. All
554 number-parsing has already been done. Return the next
555 integer value (one greater than the saved previous value).
556 Do not advance the token pointer 'pp' until the end of range
559 if (++last_retval
== end_value
)
561 /* End of range reached; advance token pointer. */
569 /* Return the breakpoint with the specified number, or NULL
570 if the number does not refer to an existing breakpoint. */
573 get_breakpoint (int num
)
575 struct breakpoint
*b
;
578 if (b
->number
== num
)
585 /* condition N EXP -- set break condition of breakpoint N to EXP. */
588 condition_command (char *arg
, int from_tty
)
590 struct breakpoint
*b
;
595 error_no_arg (_("breakpoint number"));
598 bnum
= get_number (&p
);
600 error (_("Bad breakpoint argument: '%s'"), arg
);
603 if (b
->number
== bnum
)
605 struct bp_location
*loc
= b
->loc
;
606 for (; loc
; loc
= loc
->next
)
614 if (b
->cond_string
!= NULL
)
615 xfree (b
->cond_string
);
619 b
->cond_string
= NULL
;
621 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
626 /* I don't know if it matters whether this is the string the user
627 typed in or the decompiled expression. */
628 b
->cond_string
= xstrdup (arg
);
629 b
->condition_not_parsed
= 0;
630 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
634 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
636 error (_("Junk at end of expression"));
639 breakpoints_changed ();
640 observer_notify_breakpoint_modified (b
->number
);
644 error (_("No breakpoint number %d."), bnum
);
647 /* Set the command list of B to COMMANDS. */
650 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
652 free_command_lines (&b
->commands
);
653 b
->commands
= commands
;
654 breakpoints_changed ();
655 observer_notify_breakpoint_modified (b
->number
);
659 commands_command (char *arg
, int from_tty
)
661 struct breakpoint
*b
;
664 struct command_line
*l
;
666 /* If we allowed this, we would have problems with when to
667 free the storage, if we change the commands currently
670 if (executing_breakpoint_commands
)
671 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
674 bnum
= get_number (&p
);
677 error (_("Unexpected extra arguments following breakpoint number."));
680 if (b
->number
== bnum
)
682 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
684 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
685 l
= read_command_lines (tmpbuf
, from_tty
, 1);
686 do_cleanups (cleanups
);
687 breakpoint_set_commands (b
, l
);
690 error (_("No breakpoint number %d."), bnum
);
693 /* Like commands_command, but instead of reading the commands from
694 input stream, takes them from an already parsed command structure.
696 This is used by cli-script.c to DTRT with breakpoint commands
697 that are part of if and while bodies. */
698 enum command_control_type
699 commands_from_control_command (char *arg
, struct command_line
*cmd
)
701 struct breakpoint
*b
;
705 /* If we allowed this, we would have problems with when to
706 free the storage, if we change the commands currently
709 if (executing_breakpoint_commands
)
710 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
712 /* An empty string for the breakpoint number means the last
713 breakpoint, but get_number expects a NULL pointer. */
718 bnum
= get_number (&p
);
721 error (_("Unexpected extra arguments following breakpoint number."));
724 if (b
->number
== bnum
)
726 free_command_lines (&b
->commands
);
727 if (cmd
->body_count
!= 1)
728 error (_("Invalid \"commands\" block structure."));
729 /* We need to copy the commands because if/while will free the
730 list after it finishes execution. */
731 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
732 breakpoints_changed ();
733 observer_notify_breakpoint_modified (b
->number
);
734 return simple_control
;
736 error (_("No breakpoint number %d."), bnum
);
739 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
740 by replacing any memory breakpoints with their shadowed contents. */
743 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
745 struct bp_location
*b
;
746 CORE_ADDR bp_addr
= 0;
752 if (b
->owner
->type
== bp_none
)
753 warning (_("reading through apparently deleted breakpoint #%d?"),
756 if (b
->loc_type
!= bp_loc_software_breakpoint
)
760 /* Addresses and length of the part of the breakpoint that
762 bp_addr
= b
->target_info
.placed_address
;
763 bp_size
= b
->target_info
.shadow_len
;
765 /* bp isn't valid, or doesn't shadow memory. */
768 if (bp_addr
+ bp_size
<= memaddr
)
769 /* The breakpoint is entirely before the chunk of memory we
773 if (bp_addr
>= memaddr
+ len
)
774 /* The breakpoint is entirely after the chunk of memory we are
778 /* Offset within shadow_contents. */
779 if (bp_addr
< memaddr
)
781 /* Only copy the second part of the breakpoint. */
782 bp_size
-= memaddr
- bp_addr
;
783 bptoffset
= memaddr
- bp_addr
;
787 if (bp_addr
+ bp_size
> memaddr
+ len
)
789 /* Only copy the first part of the breakpoint. */
790 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
793 memcpy (buf
+ bp_addr
- memaddr
,
794 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
799 /* A wrapper function for inserting catchpoints. */
801 insert_catchpoint (struct ui_out
*uo
, void *args
)
803 struct breakpoint
*b
= (struct breakpoint
*) args
;
806 gdb_assert (b
->type
== bp_catchpoint
);
807 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
813 is_hardware_watchpoint (struct breakpoint
*bpt
)
815 return (bpt
->type
== bp_hardware_watchpoint
816 || bpt
->type
== bp_read_watchpoint
817 || bpt
->type
== bp_access_watchpoint
);
820 /* Find the current value of a watchpoint on EXP. Return the value in
821 *VALP and *RESULTP and the chain of intermediate and final values
822 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
825 If a memory error occurs while evaluating the expression, *RESULTP will
826 be set to NULL. *RESULTP may be a lazy value, if the result could
827 not be read from memory. It is used to determine whether a value
828 is user-specified (we should watch the whole value) or intermediate
829 (we should watch only the bit used to locate the final value).
831 If the final value, or any intermediate value, could not be read
832 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
833 set to any referenced values. *VALP will never be a lazy value.
834 This is the value which we store in struct breakpoint.
836 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
837 value chain. The caller must free the values individually. If
838 VAL_CHAIN is NULL, all generated values will be left on the value
842 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
843 struct value
**resultp
, struct value
**val_chain
)
845 struct value
*mark
, *new_mark
, *result
;
846 volatile struct gdb_exception ex
;
854 /* Evaluate the expression. */
855 mark
= value_mark ();
858 TRY_CATCH (ex
, RETURN_MASK_ALL
)
860 result
= evaluate_expression (exp
);
864 /* Ignore memory errors, we want watchpoints pointing at
865 inaccessible memory to still be created; otherwise, throw the
866 error to some higher catcher. */
872 throw_exception (ex
);
877 new_mark
= value_mark ();
878 if (mark
== new_mark
)
883 /* Make sure it's not lazy, so that after the target stops again we
884 have a non-lazy previous value to compare with. */
886 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
891 /* Return the chain of intermediate values. We use this to
892 decide which addresses to watch. */
893 *val_chain
= new_mark
;
894 value_release_to_mark (mark
);
898 /* Assuming that B is a watchpoint:
899 - Reparse watchpoint expression, if REPARSE is non-zero
900 - Evaluate expression and store the result in B->val
901 - Evaluate the condition if there is one, and store the result
903 - Update the list of values that must be watched in B->loc.
905 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
906 If this is local watchpoint that is out of scope, delete it. */
908 update_watchpoint (struct breakpoint
*b
, int reparse
)
910 int within_current_scope
;
911 struct frame_id saved_frame_id
;
912 struct bp_location
*loc
;
915 /* We don't free locations. They are stored in bp_location_chain and
916 update_global_locations will eventually delete them and remove
917 breakpoints if needed. */
920 if (b
->disposition
== disp_del_at_next_stop
)
923 /* Save the current frame's ID so we can restore it after
924 evaluating the watchpoint expression on its own frame. */
925 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
926 took a frame parameter, so that we didn't have to change the
928 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
930 /* Determine if the watchpoint is within scope. */
931 if (b
->exp_valid_block
== NULL
)
932 within_current_scope
= 1;
935 struct frame_info
*fi
;
936 fi
= frame_find_by_id (b
->watchpoint_frame
);
937 within_current_scope
= (fi
!= NULL
);
938 if (within_current_scope
)
942 if (within_current_scope
&& reparse
)
951 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
952 /* If the meaning of expression itself changed, the old value is
953 no longer relevant. We don't want to report a watchpoint hit
954 to the user when the old value and the new value may actually
955 be completely different objects. */
961 /* If we failed to parse the expression, for example because
962 it refers to a global variable in a not-yet-loaded shared library,
963 don't try to insert watchpoint. We don't automatically delete
964 such watchpoint, though, since failure to parse expression
965 is different from out-of-scope watchpoint. */
966 if (within_current_scope
&& b
->exp
)
968 struct value
*val_chain
, *v
, *result
, *next
;
970 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
972 /* Avoid setting b->val if it's already set. The meaning of
973 b->val is 'the last value' user saw, and we should update
974 it only if we reported that last value to user. As it
975 happens, the code that reports it updates b->val directly. */
982 /* Change the type of breakpoint between hardware assisted or an
983 ordinary watchpoint depending on the hardware support and free
984 hardware slots. REPARSE is set when the inferior is started. */
985 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
988 int i
, mem_cnt
, other_type_used
;
990 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
992 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
995 b
->type
= bp_watchpoint
;
998 int target_resources_ok
= target_can_use_hardware_watchpoint
999 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1000 if (target_resources_ok
<= 0)
1001 b
->type
= bp_watchpoint
;
1003 b
->type
= bp_hardware_watchpoint
;
1007 /* Look at each value on the value chain. */
1008 for (v
= val_chain
; v
; v
= next
)
1010 /* If it's a memory location, and GDB actually needed
1011 its contents to evaluate the expression, then we
1012 must watch it. If the first value returned is
1013 still lazy, that means an error occurred reading it;
1014 watch it anyway in case it becomes readable. */
1015 if (VALUE_LVAL (v
) == lval_memory
1016 && (v
== val_chain
|| ! value_lazy (v
)))
1018 struct type
*vtype
= check_typedef (value_type (v
));
1020 /* We only watch structs and arrays if user asked
1021 for it explicitly, never if they just happen to
1022 appear in the middle of some value chain. */
1024 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1025 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1029 struct bp_location
*loc
, **tmp
;
1031 addr
= value_address (v
);
1032 len
= TYPE_LENGTH (value_type (v
));
1034 if (b
->type
== bp_read_watchpoint
)
1036 else if (b
->type
== bp_access_watchpoint
)
1039 loc
= allocate_bp_location (b
);
1040 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1043 loc
->gdbarch
= get_type_arch (value_type (v
));
1044 loc
->address
= addr
;
1046 loc
->watchpoint_type
= type
;
1050 next
= value_next (v
);
1055 /* We just regenerated the list of breakpoint locations.
1056 The new location does not have its condition field set to anything
1057 and therefore, we must always reparse the cond_string, independently
1058 of the value of the reparse flag. */
1059 if (b
->cond_string
!= NULL
)
1061 char *s
= b
->cond_string
;
1062 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1065 else if (!within_current_scope
)
1067 printf_filtered (_("\
1068 Watchpoint %d deleted because the program has left the block \n\
1069 in which its expression is valid.\n"),
1071 if (b
->related_breakpoint
)
1072 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1073 b
->disposition
= disp_del_at_next_stop
;
1076 /* Restore the selected frame. */
1077 select_frame (frame_find_by_id (saved_frame_id
));
1081 /* Returns 1 iff breakpoint location should be
1082 inserted in the inferior. */
1084 should_be_inserted (struct bp_location
*bpt
)
1086 if (!breakpoint_enabled (bpt
->owner
))
1089 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1092 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1095 /* Tracepoints are inserted by the target at a time of its choosing,
1097 if (bpt
->owner
->type
== bp_tracepoint
)
1103 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1104 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1105 and HW_BREAKPOINT_ERROR are used to report problems.
1107 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1108 method for each breakpoint or catchpoint type. */
1110 insert_bp_location (struct bp_location
*bpt
,
1111 struct ui_file
*tmp_error_stream
,
1112 int *disabled_breaks
,
1113 int *hw_breakpoint_error
)
1117 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1120 /* Initialize the target-specific information. */
1121 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1122 bpt
->target_info
.placed_address
= bpt
->address
;
1124 if (bpt
->loc_type
== bp_loc_software_breakpoint
1125 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1127 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1129 /* If the explicitly specified breakpoint type
1130 is not hardware breakpoint, check the memory map to see
1131 if the breakpoint address is in read only memory or not.
1132 Two important cases are:
1133 - location type is not hardware breakpoint, memory
1134 is readonly. We change the type of the location to
1135 hardware breakpoint.
1136 - location type is hardware breakpoint, memory is read-write.
1137 This means we've previously made the location hardware one, but
1138 then the memory map changed, so we undo.
1140 When breakpoints are removed, remove_breakpoints will
1141 use location types we've just set here, the only possible
1142 problem is that memory map has changed during running program,
1143 but it's not going to work anyway with current gdb. */
1144 struct mem_region
*mr
1145 = lookup_mem_region (bpt
->target_info
.placed_address
);
1149 if (automatic_hardware_breakpoints
)
1152 enum bp_loc_type new_type
;
1154 if (mr
->attrib
.mode
!= MEM_RW
)
1155 new_type
= bp_loc_hardware_breakpoint
;
1157 new_type
= bp_loc_software_breakpoint
;
1159 if (new_type
!= bpt
->loc_type
)
1161 static int said
= 0;
1162 bpt
->loc_type
= new_type
;
1165 fprintf_filtered (gdb_stdout
, _("\
1166 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1171 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1172 && mr
->attrib
.mode
!= MEM_RW
)
1173 warning (_("cannot set software breakpoint at readonly address %s"),
1174 paddress (bpt
->gdbarch
, bpt
->address
));
1178 /* First check to see if we have to handle an overlay. */
1179 if (overlay_debugging
== ovly_off
1180 || bpt
->section
== NULL
1181 || !(section_is_overlay (bpt
->section
)))
1183 /* No overlay handling: just set the breakpoint. */
1185 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1186 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1189 val
= target_insert_breakpoint (bpt
->gdbarch
,
1194 /* This breakpoint is in an overlay section.
1195 Shall we set a breakpoint at the LMA? */
1196 if (!overlay_events_enabled
)
1198 /* Yes -- overlay event support is not active,
1199 so we must try to set a breakpoint at the LMA.
1200 This will not work for a hardware breakpoint. */
1201 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1202 warning (_("hardware breakpoint %d not supported in overlay!"),
1203 bpt
->owner
->number
);
1206 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1208 /* Set a software (trap) breakpoint at the LMA. */
1209 bpt
->overlay_target_info
= bpt
->target_info
;
1210 bpt
->overlay_target_info
.placed_address
= addr
;
1211 val
= target_insert_breakpoint (bpt
->gdbarch
,
1212 &bpt
->overlay_target_info
);
1214 fprintf_unfiltered (tmp_error_stream
,
1215 "Overlay breakpoint %d failed: in ROM?\n",
1216 bpt
->owner
->number
);
1219 /* Shall we set a breakpoint at the VMA? */
1220 if (section_is_mapped (bpt
->section
))
1222 /* Yes. This overlay section is mapped into memory. */
1223 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1224 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1227 val
= target_insert_breakpoint (bpt
->gdbarch
,
1232 /* No. This breakpoint will not be inserted.
1233 No error, but do not mark the bp as 'inserted'. */
1240 /* Can't set the breakpoint. */
1241 if (solib_name_from_address (bpt
->address
))
1243 /* See also: disable_breakpoints_in_shlibs. */
1245 bpt
->shlib_disabled
= 1;
1246 if (!*disabled_breaks
)
1248 fprintf_unfiltered (tmp_error_stream
,
1249 "Cannot insert breakpoint %d.\n",
1250 bpt
->owner
->number
);
1251 fprintf_unfiltered (tmp_error_stream
,
1252 "Temporarily disabling shared library breakpoints:\n");
1254 *disabled_breaks
= 1;
1255 fprintf_unfiltered (tmp_error_stream
,
1256 "breakpoint #%d\n", bpt
->owner
->number
);
1260 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1262 *hw_breakpoint_error
= 1;
1263 fprintf_unfiltered (tmp_error_stream
,
1264 "Cannot insert hardware breakpoint %d.\n",
1265 bpt
->owner
->number
);
1269 fprintf_unfiltered (tmp_error_stream
,
1270 "Cannot insert breakpoint %d.\n",
1271 bpt
->owner
->number
);
1272 fprintf_filtered (tmp_error_stream
,
1273 "Error accessing memory address ");
1274 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1276 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1277 safe_strerror (val
));
1288 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1289 /* NOTE drow/2003-09-08: This state only exists for removing
1290 watchpoints. It's not clear that it's necessary... */
1291 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1293 val
= target_insert_watchpoint (bpt
->address
,
1295 bpt
->watchpoint_type
);
1296 bpt
->inserted
= (val
!= -1);
1299 else if (bpt
->owner
->type
== bp_catchpoint
)
1301 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1302 bpt
->owner
, RETURN_MASK_ERROR
);
1303 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1304 bpt
->owner
->number
);
1306 bpt
->owner
->enable_state
= bp_disabled
;
1310 /* We've already printed an error message if there was a problem
1311 inserting this catchpoint, and we've disabled the catchpoint,
1312 so just return success. */
1319 /* Make sure all breakpoints are inserted in inferior.
1320 Throws exception on any error.
1321 A breakpoint that is already inserted won't be inserted
1322 again, so calling this function twice is safe. */
1324 insert_breakpoints (void)
1326 struct breakpoint
*bpt
;
1328 ALL_BREAKPOINTS (bpt
)
1329 if (is_hardware_watchpoint (bpt
))
1330 update_watchpoint (bpt
, 0 /* don't reparse. */);
1332 update_global_location_list (1);
1334 /* update_global_location_list does not insert breakpoints when
1335 always_inserted_mode is not enabled. Explicitly insert them
1337 if (!breakpoints_always_inserted_mode ())
1338 insert_breakpoint_locations ();
1341 /* insert_breakpoints is used when starting or continuing the program.
1342 remove_breakpoints is used when the program stops.
1343 Both return zero if successful,
1344 or an `errno' value if could not write the inferior. */
1347 insert_breakpoint_locations (void)
1349 struct breakpoint
*bpt
;
1350 struct bp_location
*b
, *temp
;
1353 int disabled_breaks
= 0;
1354 int hw_breakpoint_error
= 0;
1356 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1357 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1359 /* Explicitly mark the warning -- this will only be printed if
1360 there was an error. */
1361 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1363 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1365 if (!should_be_inserted (b
) || b
->inserted
)
1368 /* There is no point inserting thread-specific breakpoints if the
1369 thread no longer exists. */
1370 if (b
->owner
->thread
!= -1
1371 && !valid_thread_id (b
->owner
->thread
))
1374 val
= insert_bp_location (b
, tmp_error_stream
,
1376 &hw_breakpoint_error
);
1381 /* If we failed to insert all locations of a watchpoint,
1382 remove them, as half-inserted watchpoint is of limited use. */
1383 ALL_BREAKPOINTS (bpt
)
1385 int some_failed
= 0;
1386 struct bp_location
*loc
;
1388 if (!is_hardware_watchpoint (bpt
))
1391 if (!breakpoint_enabled (bpt
))
1394 if (bpt
->disposition
== disp_del_at_next_stop
)
1397 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1405 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1407 remove_breakpoint (loc
, mark_uninserted
);
1409 hw_breakpoint_error
= 1;
1410 fprintf_unfiltered (tmp_error_stream
,
1411 "Could not insert hardware watchpoint %d.\n",
1419 /* If a hardware breakpoint or watchpoint was inserted, add a
1420 message about possibly exhausted resources. */
1421 if (hw_breakpoint_error
)
1423 fprintf_unfiltered (tmp_error_stream
,
1424 "Could not insert hardware breakpoints:\n\
1425 You may have requested too many hardware breakpoints/watchpoints.\n");
1427 target_terminal_ours_for_output ();
1428 error_stream (tmp_error_stream
);
1431 do_cleanups (cleanups
);
1435 remove_breakpoints (void)
1437 struct bp_location
*b
;
1440 ALL_BP_LOCATIONS (b
)
1443 val
|= remove_breakpoint (b
, mark_uninserted
);
1449 remove_hw_watchpoints (void)
1451 struct bp_location
*b
;
1454 ALL_BP_LOCATIONS (b
)
1456 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1457 val
|= remove_breakpoint (b
, mark_uninserted
);
1463 reattach_breakpoints (int pid
)
1465 struct bp_location
*b
;
1467 struct cleanup
*old_chain
= save_inferior_ptid ();
1468 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1469 int dummy1
= 0, dummy2
= 0;
1471 make_cleanup_ui_file_delete (tmp_error_stream
);
1473 inferior_ptid
= pid_to_ptid (pid
);
1474 ALL_BP_LOCATIONS (b
)
1479 val
= insert_bp_location (b
, tmp_error_stream
,
1483 do_cleanups (old_chain
);
1488 do_cleanups (old_chain
);
1492 static int internal_breakpoint_number
= -1;
1494 static struct breakpoint
*
1495 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1496 CORE_ADDR address
, enum bptype type
)
1498 struct symtab_and_line sal
;
1499 struct breakpoint
*b
;
1501 init_sal (&sal
); /* initialize to zeroes */
1504 sal
.section
= find_pc_overlay (sal
.pc
);
1506 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1507 b
->number
= internal_breakpoint_number
--;
1508 b
->disposition
= disp_donttouch
;
1514 create_overlay_event_breakpoint (char *func_name
)
1516 struct objfile
*objfile
;
1518 ALL_OBJFILES (objfile
)
1520 struct breakpoint
*b
;
1521 struct minimal_symbol
*m
;
1523 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1527 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1528 SYMBOL_VALUE_ADDRESS (m
),
1530 b
->addr_string
= xstrdup (func_name
);
1532 if (overlay_debugging
== ovly_auto
)
1534 b
->enable_state
= bp_enabled
;
1535 overlay_events_enabled
= 1;
1539 b
->enable_state
= bp_disabled
;
1540 overlay_events_enabled
= 0;
1543 update_global_location_list (1);
1547 create_longjmp_master_breakpoint (char *func_name
)
1549 struct objfile
*objfile
;
1551 ALL_OBJFILES (objfile
)
1553 struct breakpoint
*b
;
1554 struct minimal_symbol
*m
;
1556 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1559 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1563 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1564 SYMBOL_VALUE_ADDRESS (m
),
1566 b
->addr_string
= xstrdup (func_name
);
1567 b
->enable_state
= bp_disabled
;
1569 update_global_location_list (1);
1573 update_breakpoints_after_exec (void)
1575 struct breakpoint
*b
;
1576 struct breakpoint
*temp
;
1577 struct bp_location
*bploc
;
1579 /* We're about to delete breakpoints from GDB's lists. If the
1580 INSERTED flag is true, GDB will try to lift the breakpoints by
1581 writing the breakpoints' "shadow contents" back into memory. The
1582 "shadow contents" are NOT valid after an exec, so GDB should not
1583 do that. Instead, the target is responsible from marking
1584 breakpoints out as soon as it detects an exec. We don't do that
1585 here instead, because there may be other attempts to delete
1586 breakpoints after detecting an exec and before reaching here. */
1587 ALL_BP_LOCATIONS (bploc
)
1588 gdb_assert (!bploc
->inserted
);
1590 ALL_BREAKPOINTS_SAFE (b
, temp
)
1592 /* Solib breakpoints must be explicitly reset after an exec(). */
1593 if (b
->type
== bp_shlib_event
)
1595 delete_breakpoint (b
);
1599 /* JIT breakpoints must be explicitly reset after an exec(). */
1600 if (b
->type
== bp_jit_event
)
1602 delete_breakpoint (b
);
1606 /* Thread event breakpoints must be set anew after an exec(),
1607 as must overlay event and longjmp master breakpoints. */
1608 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1609 || b
->type
== bp_longjmp_master
)
1611 delete_breakpoint (b
);
1615 /* Step-resume breakpoints are meaningless after an exec(). */
1616 if (b
->type
== bp_step_resume
)
1618 delete_breakpoint (b
);
1622 /* Longjmp and longjmp-resume breakpoints are also meaningless
1624 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1626 delete_breakpoint (b
);
1630 if (b
->type
== bp_catchpoint
)
1632 /* For now, none of the bp_catchpoint breakpoints need to
1633 do anything at this point. In the future, if some of
1634 the catchpoints need to something, we will need to add
1635 a new method, and call this method from here. */
1639 /* bp_finish is a special case. The only way we ought to be able
1640 to see one of these when an exec() has happened, is if the user
1641 caught a vfork, and then said "finish". Ordinarily a finish just
1642 carries them to the call-site of the current callee, by setting
1643 a temporary bp there and resuming. But in this case, the finish
1644 will carry them entirely through the vfork & exec.
1646 We don't want to allow a bp_finish to remain inserted now. But
1647 we can't safely delete it, 'cause finish_command has a handle to
1648 the bp on a bpstat, and will later want to delete it. There's a
1649 chance (and I've seen it happen) that if we delete the bp_finish
1650 here, that its storage will get reused by the time finish_command
1651 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1652 We really must allow finish_command to delete a bp_finish.
1654 In the absense of a general solution for the "how do we know
1655 it's safe to delete something others may have handles to?"
1656 problem, what we'll do here is just uninsert the bp_finish, and
1657 let finish_command delete it.
1659 (We know the bp_finish is "doomed" in the sense that it's
1660 momentary, and will be deleted as soon as finish_command sees
1661 the inferior stopped. So it doesn't matter that the bp's
1662 address is probably bogus in the new a.out, unlike e.g., the
1663 solib breakpoints.) */
1665 if (b
->type
== bp_finish
)
1670 /* Without a symbolic address, we have little hope of the
1671 pre-exec() address meaning the same thing in the post-exec()
1673 if (b
->addr_string
== NULL
)
1675 delete_breakpoint (b
);
1679 /* FIXME what about longjmp breakpoints? Re-create them here? */
1680 create_overlay_event_breakpoint ("_ovly_debug_event");
1681 create_longjmp_master_breakpoint ("longjmp");
1682 create_longjmp_master_breakpoint ("_longjmp");
1683 create_longjmp_master_breakpoint ("siglongjmp");
1684 create_longjmp_master_breakpoint ("_siglongjmp");
1688 detach_breakpoints (int pid
)
1690 struct bp_location
*b
;
1692 struct cleanup
*old_chain
= save_inferior_ptid ();
1694 if (pid
== PIDGET (inferior_ptid
))
1695 error (_("Cannot detach breakpoints of inferior_ptid"));
1697 /* Set inferior_ptid; remove_breakpoint uses this global. */
1698 inferior_ptid
= pid_to_ptid (pid
);
1699 ALL_BP_LOCATIONS (b
)
1702 val
|= remove_breakpoint (b
, mark_inserted
);
1704 do_cleanups (old_chain
);
1709 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1713 if (b
->owner
->enable_state
== bp_permanent
)
1714 /* Permanent breakpoints cannot be inserted or removed. */
1717 /* The type of none suggests that owner is actually deleted.
1718 This should not ever happen. */
1719 gdb_assert (b
->owner
->type
!= bp_none
);
1721 if (b
->loc_type
== bp_loc_software_breakpoint
1722 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1724 /* "Normal" instruction breakpoint: either the standard
1725 trap-instruction bp (bp_breakpoint), or a
1726 bp_hardware_breakpoint. */
1728 /* First check to see if we have to handle an overlay. */
1729 if (overlay_debugging
== ovly_off
1730 || b
->section
== NULL
1731 || !(section_is_overlay (b
->section
)))
1733 /* No overlay handling: just remove the breakpoint. */
1735 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1736 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
1738 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
1742 /* This breakpoint is in an overlay section.
1743 Did we set a breakpoint at the LMA? */
1744 if (!overlay_events_enabled
)
1746 /* Yes -- overlay event support is not active, so we
1747 should have set a breakpoint at the LMA. Remove it.
1749 /* Ignore any failures: if the LMA is in ROM, we will
1750 have already warned when we failed to insert it. */
1751 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1752 target_remove_hw_breakpoint (b
->gdbarch
,
1753 &b
->overlay_target_info
);
1755 target_remove_breakpoint (b
->gdbarch
,
1756 &b
->overlay_target_info
);
1758 /* Did we set a breakpoint at the VMA?
1759 If so, we will have marked the breakpoint 'inserted'. */
1762 /* Yes -- remove it. Previously we did not bother to
1763 remove the breakpoint if the section had been
1764 unmapped, but let's not rely on that being safe. We
1765 don't know what the overlay manager might do. */
1766 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1767 val
= target_remove_hw_breakpoint (b
->gdbarch
,
1770 /* However, we should remove *software* breakpoints only
1771 if the section is still mapped, or else we overwrite
1772 wrong code with the saved shadow contents. */
1773 else if (section_is_mapped (b
->section
))
1774 val
= target_remove_breakpoint (b
->gdbarch
,
1781 /* No -- not inserted, so no need to remove. No error. */
1786 /* In some cases, we might not be able to remove a breakpoint
1787 in a shared library that has already been removed, but we
1788 have not yet processed the shlib unload event. */
1789 if (val
&& solib_name_from_address (b
->address
))
1794 b
->inserted
= (is
== mark_inserted
);
1796 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1801 b
->inserted
= (is
== mark_inserted
);
1802 val
= target_remove_watchpoint (b
->address
, b
->length
,
1803 b
->watchpoint_type
);
1805 /* Failure to remove any of the hardware watchpoints comes here. */
1806 if ((is
== mark_uninserted
) && (b
->inserted
))
1807 warning (_("Could not remove hardware watchpoint %d."),
1810 else if (b
->owner
->type
== bp_catchpoint
1811 && breakpoint_enabled (b
->owner
)
1814 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1816 val
= b
->owner
->ops
->remove (b
->owner
);
1819 b
->inserted
= (is
== mark_inserted
);
1825 /* Clear the "inserted" flag in all breakpoints. */
1828 mark_breakpoints_out (void)
1830 struct bp_location
*bpt
;
1832 ALL_BP_LOCATIONS (bpt
)
1836 /* Clear the "inserted" flag in all breakpoints and delete any
1837 breakpoints which should go away between runs of the program.
1839 Plus other such housekeeping that has to be done for breakpoints
1842 Note: this function gets called at the end of a run (by
1843 generic_mourn_inferior) and when a run begins (by
1844 init_wait_for_inferior). */
1849 breakpoint_init_inferior (enum inf_context context
)
1851 struct breakpoint
*b
, *temp
;
1852 struct bp_location
*bpt
;
1855 /* If breakpoint locations are shared across processes, then there's
1857 if (gdbarch_has_global_breakpoints (target_gdbarch
))
1860 ALL_BP_LOCATIONS (bpt
)
1861 if (bpt
->owner
->enable_state
!= bp_permanent
)
1864 ALL_BREAKPOINTS_SAFE (b
, temp
)
1869 case bp_watchpoint_scope
:
1871 /* If the call dummy breakpoint is at the entry point it will
1872 cause problems when the inferior is rerun, so we better
1875 Also get rid of scope breakpoints. */
1876 delete_breakpoint (b
);
1880 case bp_hardware_watchpoint
:
1881 case bp_read_watchpoint
:
1882 case bp_access_watchpoint
:
1884 /* Likewise for watchpoints on local expressions. */
1885 if (b
->exp_valid_block
!= NULL
)
1886 delete_breakpoint (b
);
1887 else if (context
== inf_starting
)
1889 /* Reset val field to force reread of starting value
1890 in insert_breakpoints. */
1892 value_free (b
->val
);
1902 /* Get rid of the moribund locations. */
1903 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1904 free_bp_location (bpt
);
1905 VEC_free (bp_location_p
, moribund_locations
);
1908 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1909 exists at PC. It returns ordinary_breakpoint_here if it's an
1910 ordinary breakpoint, or permanent_breakpoint_here if it's a
1911 permanent breakpoint.
1912 - When continuing from a location with an ordinary breakpoint, we
1913 actually single step once before calling insert_breakpoints.
1914 - When continuing from a localion with a permanent breakpoint, we
1915 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1916 the target, to advance the PC past the breakpoint. */
1918 enum breakpoint_here
1919 breakpoint_here_p (CORE_ADDR pc
)
1921 const struct bp_location
*bpt
;
1922 int any_breakpoint_here
= 0;
1924 ALL_BP_LOCATIONS (bpt
)
1926 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1927 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1930 if ((breakpoint_enabled (bpt
->owner
)
1931 || bpt
->owner
->enable_state
== bp_permanent
)
1932 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1934 if (overlay_debugging
1935 && section_is_overlay (bpt
->section
)
1936 && !section_is_mapped (bpt
->section
))
1937 continue; /* unmapped overlay -- can't be a match */
1938 else if (bpt
->owner
->enable_state
== bp_permanent
)
1939 return permanent_breakpoint_here
;
1941 any_breakpoint_here
= 1;
1945 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1948 /* Return true if there's a moribund breakpoint at PC. */
1951 moribund_breakpoint_here_p (CORE_ADDR pc
)
1953 struct bp_location
*loc
;
1956 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1957 if (loc
->address
== pc
)
1963 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1964 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1965 This does not check for single-step breakpoints, which are
1966 inserted and removed using direct target manipulation. */
1969 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1971 const struct bp_location
*bpt
;
1973 ALL_BP_LOCATIONS (bpt
)
1975 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1976 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1980 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1982 if (overlay_debugging
1983 && section_is_overlay (bpt
->section
)
1984 && !section_is_mapped (bpt
->section
))
1985 continue; /* unmapped overlay -- can't be a match */
1993 /* Returns non-zero iff there's either regular breakpoint
1994 or a single step breakpoint inserted at PC. */
1997 breakpoint_inserted_here_p (CORE_ADDR pc
)
1999 if (regular_breakpoint_inserted_here_p (pc
))
2002 if (single_step_breakpoint_inserted_here_p (pc
))
2008 /* This function returns non-zero iff there is a software breakpoint
2012 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
2014 const struct bp_location
*bpt
;
2015 int any_breakpoint_here
= 0;
2017 ALL_BP_LOCATIONS (bpt
)
2019 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2023 && bpt
->address
== pc
) /* bp is enabled and matches pc */
2025 if (overlay_debugging
2026 && section_is_overlay (bpt
->section
)
2027 && !section_is_mapped (bpt
->section
))
2028 continue; /* unmapped overlay -- can't be a match */
2034 /* Also check for software single-step breakpoints. */
2035 if (single_step_breakpoint_inserted_here_p (pc
))
2041 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2042 PC is valid for process/thread PTID. */
2045 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
2047 const struct bp_location
*bpt
;
2048 /* The thread and task IDs associated to PTID, computed lazily. */
2052 ALL_BP_LOCATIONS (bpt
)
2054 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2055 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2058 if (!breakpoint_enabled (bpt
->owner
)
2059 && bpt
->owner
->enable_state
!= bp_permanent
)
2062 if (bpt
->address
!= pc
)
2065 if (bpt
->owner
->thread
!= -1)
2067 /* This is a thread-specific breakpoint. Check that ptid
2068 matches that thread. If thread hasn't been computed yet,
2069 it is now time to do so. */
2071 thread
= pid_to_thread_id (ptid
);
2072 if (bpt
->owner
->thread
!= thread
)
2076 if (bpt
->owner
->task
!= 0)
2078 /* This is a task-specific breakpoint. Check that ptid
2079 matches that task. If task hasn't been computed yet,
2080 it is now time to do so. */
2082 task
= ada_get_task_number (ptid
);
2083 if (bpt
->owner
->task
!= task
)
2087 if (overlay_debugging
2088 && section_is_overlay (bpt
->section
)
2089 && !section_is_mapped (bpt
->section
))
2090 continue; /* unmapped overlay -- can't be a match */
2099 /* bpstat stuff. External routines' interfaces are documented
2103 ep_is_catchpoint (struct breakpoint
*ep
)
2105 return (ep
->type
== bp_catchpoint
);
2109 bpstat_free (bpstat bs
)
2111 if (bs
->old_val
!= NULL
)
2112 value_free (bs
->old_val
);
2113 free_command_lines (&bs
->commands
);
2117 /* Clear a bpstat so that it says we are not at any breakpoint.
2118 Also free any storage that is part of a bpstat. */
2121 bpstat_clear (bpstat
*bsp
)
2138 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2139 is part of the bpstat is copied as well. */
2142 bpstat_copy (bpstat bs
)
2146 bpstat retval
= NULL
;
2151 for (; bs
!= NULL
; bs
= bs
->next
)
2153 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2154 memcpy (tmp
, bs
, sizeof (*tmp
));
2155 if (bs
->commands
!= NULL
)
2156 tmp
->commands
= copy_command_lines (bs
->commands
);
2157 if (bs
->old_val
!= NULL
)
2159 tmp
->old_val
= value_copy (bs
->old_val
);
2160 release_value (tmp
->old_val
);
2164 /* This is the first thing in the chain. */
2174 /* Find the bpstat associated with this breakpoint */
2177 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2182 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2184 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2190 /* Find a step_resume breakpoint associated with this bpstat.
2191 (If there are multiple step_resume bp's on the list, this function
2192 will arbitrarily pick one.)
2194 It is an error to use this function if BPSTAT doesn't contain a
2195 step_resume breakpoint.
2197 See wait_for_inferior's use of this function. */
2199 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2203 gdb_assert (bsp
!= NULL
);
2205 current_thread
= pid_to_thread_id (inferior_ptid
);
2207 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2209 if ((bsp
->breakpoint_at
!= NULL
)
2210 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2211 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2212 || bsp
->breakpoint_at
->owner
->thread
== -1))
2213 return bsp
->breakpoint_at
->owner
;
2216 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2220 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2221 at. *BSP upon return is a bpstat which points to the remaining
2222 breakpoints stopped at (but which is not guaranteed to be good for
2223 anything but further calls to bpstat_num).
2224 Return 0 if passed a bpstat which does not indicate any breakpoints.
2225 Return -1 if stopped at a breakpoint that has been deleted since
2227 Return 1 otherwise. */
2230 bpstat_num (bpstat
*bsp
, int *num
)
2232 struct breakpoint
*b
;
2235 return 0; /* No more breakpoint values */
2237 /* We assume we'll never have several bpstats that
2238 correspond to a single breakpoint -- otherwise,
2239 this function might return the same number more
2240 than once and this will look ugly. */
2241 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2242 *bsp
= (*bsp
)->next
;
2244 return -1; /* breakpoint that's been deleted since */
2246 *num
= b
->number
; /* We have its number */
2250 /* Modify BS so that the actions will not be performed. */
2253 bpstat_clear_actions (bpstat bs
)
2255 for (; bs
!= NULL
; bs
= bs
->next
)
2257 free_command_lines (&bs
->commands
);
2258 if (bs
->old_val
!= NULL
)
2260 value_free (bs
->old_val
);
2266 /* Called when a command is about to proceed the inferior. */
2269 breakpoint_about_to_proceed (void)
2271 if (!ptid_equal (inferior_ptid
, null_ptid
))
2273 struct thread_info
*tp
= inferior_thread ();
2275 /* Allow inferior function calls in breakpoint commands to not
2276 interrupt the command list. When the call finishes
2277 successfully, the inferior will be standing at the same
2278 breakpoint as if nothing happened. */
2283 breakpoint_proceeded
= 1;
2286 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2288 cleanup_executing_breakpoints (void *ignore
)
2290 executing_breakpoint_commands
= 0;
2293 /* Execute all the commands associated with all the breakpoints at this
2294 location. Any of these commands could cause the process to proceed
2295 beyond this point, etc. We look out for such changes by checking
2296 the global "breakpoint_proceeded" after each command.
2298 Returns true if a breakpoint command resumed the inferior. In that
2299 case, it is the caller's responsibility to recall it again with the
2300 bpstat of the current thread. */
2303 bpstat_do_actions_1 (bpstat
*bsp
)
2306 struct cleanup
*old_chain
;
2309 /* Avoid endless recursion if a `source' command is contained
2311 if (executing_breakpoint_commands
)
2314 executing_breakpoint_commands
= 1;
2315 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2317 /* This pointer will iterate over the list of bpstat's. */
2320 breakpoint_proceeded
= 0;
2321 for (; bs
!= NULL
; bs
= bs
->next
)
2323 struct command_line
*cmd
;
2324 struct cleanup
*this_cmd_tree_chain
;
2326 /* Take ownership of the BSP's command tree, if it has one.
2328 The command tree could legitimately contain commands like
2329 'step' and 'next', which call clear_proceed_status, which
2330 frees stop_bpstat's command tree. To make sure this doesn't
2331 free the tree we're executing out from under us, we need to
2332 take ownership of the tree ourselves. Since a given bpstat's
2333 commands are only executed once, we don't need to copy it; we
2334 can clear the pointer in the bpstat, and make sure we free
2335 the tree when we're done. */
2338 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2342 execute_control_command (cmd
);
2344 if (breakpoint_proceeded
)
2350 /* We can free this command tree now. */
2351 do_cleanups (this_cmd_tree_chain
);
2353 if (breakpoint_proceeded
)
2355 if (target_can_async_p ())
2356 /* If we are in async mode, then the target might be still
2357 running, not stopped at any breakpoint, so nothing for
2358 us to do here -- just return to the event loop. */
2361 /* In sync mode, when execute_control_command returns
2362 we're already standing on the next breakpoint.
2363 Breakpoint commands for that stop were not run, since
2364 execute_command does not run breakpoint commands --
2365 only command_line_handler does, but that one is not
2366 involved in execution of breakpoint commands. So, we
2367 can now execute breakpoint commands. It should be
2368 noted that making execute_command do bpstat actions is
2369 not an option -- in this case we'll have recursive
2370 invocation of bpstat for each breakpoint with a
2371 command, and can easily blow up GDB stack. Instead, we
2372 return true, which will trigger the caller to recall us
2373 with the new stop_bpstat. */
2378 do_cleanups (old_chain
);
2383 bpstat_do_actions (void)
2385 /* Do any commands attached to breakpoint we are stopped at. */
2386 while (!ptid_equal (inferior_ptid
, null_ptid
)
2387 && target_has_execution
2388 && !is_exited (inferior_ptid
)
2389 && !is_executing (inferior_ptid
))
2390 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2391 and only return when it is stopped at the next breakpoint, we
2392 keep doing breakpoint actions until it returns false to
2393 indicate the inferior was not resumed. */
2394 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2398 /* Print out the (old or new) value associated with a watchpoint. */
2401 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2404 fprintf_unfiltered (stream
, _("<unreadable>"));
2407 struct value_print_options opts
;
2408 get_user_print_options (&opts
);
2409 value_print (val
, stream
, &opts
);
2413 /* This is the normal print function for a bpstat. In the future,
2414 much of this logic could (should?) be moved to bpstat_stop_status,
2415 by having it set different print_it values.
2417 Current scheme: When we stop, bpstat_print() is called. It loops
2418 through the bpstat list of things causing this stop, calling the
2419 print_bp_stop_message function on each one. The behavior of the
2420 print_bp_stop_message function depends on the print_it field of
2421 bpstat. If such field so indicates, call this function here.
2423 Return values from this routine (ultimately used by bpstat_print()
2424 and normal_stop() to decide what to do):
2425 PRINT_NOTHING: Means we already printed all we needed to print,
2426 don't print anything else.
2427 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2428 that something to be followed by a location.
2429 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2430 that something to be followed by a location.
2431 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2434 static enum print_stop_action
2435 print_it_typical (bpstat bs
)
2437 struct cleanup
*old_chain
;
2438 struct breakpoint
*b
;
2439 const struct bp_location
*bl
;
2440 struct ui_stream
*stb
;
2442 enum print_stop_action result
;
2444 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2445 which has since been deleted. */
2446 if (bs
->breakpoint_at
== NULL
)
2447 return PRINT_UNKNOWN
;
2448 bl
= bs
->breakpoint_at
;
2451 stb
= ui_out_stream_new (uiout
);
2452 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2457 case bp_hardware_breakpoint
:
2458 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2459 if (bl
->address
!= bl
->requested_address
)
2460 breakpoint_adjustment_warning (bl
->requested_address
,
2463 annotate_breakpoint (b
->number
);
2465 ui_out_text (uiout
, "\nTemporary breakpoint ");
2467 ui_out_text (uiout
, "\nBreakpoint ");
2468 if (ui_out_is_mi_like_p (uiout
))
2470 ui_out_field_string (uiout
, "reason",
2471 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2472 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2474 ui_out_field_int (uiout
, "bkptno", b
->number
);
2475 ui_out_text (uiout
, ", ");
2476 result
= PRINT_SRC_AND_LOC
;
2479 case bp_shlib_event
:
2480 /* Did we stop because the user set the stop_on_solib_events
2481 variable? (If so, we report this as a generic, "Stopped due
2482 to shlib event" message.) */
2483 printf_filtered (_("Stopped due to shared library event\n"));
2484 result
= PRINT_NOTHING
;
2487 case bp_thread_event
:
2488 /* Not sure how we will get here.
2489 GDB should not stop for these breakpoints. */
2490 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2491 result
= PRINT_NOTHING
;
2494 case bp_overlay_event
:
2495 /* By analogy with the thread event, GDB should not stop for these. */
2496 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2497 result
= PRINT_NOTHING
;
2500 case bp_longjmp_master
:
2501 /* These should never be enabled. */
2502 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2503 result
= PRINT_NOTHING
;
2507 case bp_hardware_watchpoint
:
2508 annotate_watchpoint (b
->number
);
2509 if (ui_out_is_mi_like_p (uiout
))
2512 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2514 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2515 ui_out_text (uiout
, "\nOld value = ");
2516 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2517 ui_out_field_stream (uiout
, "old", stb
);
2518 ui_out_text (uiout
, "\nNew value = ");
2519 watchpoint_value_print (b
->val
, stb
->stream
);
2520 ui_out_field_stream (uiout
, "new", stb
);
2521 ui_out_text (uiout
, "\n");
2522 /* More than one watchpoint may have been triggered. */
2523 result
= PRINT_UNKNOWN
;
2526 case bp_read_watchpoint
:
2527 if (ui_out_is_mi_like_p (uiout
))
2530 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2532 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2533 ui_out_text (uiout
, "\nValue = ");
2534 watchpoint_value_print (b
->val
, stb
->stream
);
2535 ui_out_field_stream (uiout
, "value", stb
);
2536 ui_out_text (uiout
, "\n");
2537 result
= PRINT_UNKNOWN
;
2540 case bp_access_watchpoint
:
2541 if (bs
->old_val
!= NULL
)
2543 annotate_watchpoint (b
->number
);
2544 if (ui_out_is_mi_like_p (uiout
))
2547 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2549 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2550 ui_out_text (uiout
, "\nOld value = ");
2551 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2552 ui_out_field_stream (uiout
, "old", stb
);
2553 ui_out_text (uiout
, "\nNew value = ");
2558 if (ui_out_is_mi_like_p (uiout
))
2561 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2562 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2563 ui_out_text (uiout
, "\nValue = ");
2565 watchpoint_value_print (b
->val
, stb
->stream
);
2566 ui_out_field_stream (uiout
, "new", stb
);
2567 ui_out_text (uiout
, "\n");
2568 result
= PRINT_UNKNOWN
;
2571 /* Fall through, we don't deal with these types of breakpoints
2575 if (ui_out_is_mi_like_p (uiout
))
2578 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2579 result
= PRINT_UNKNOWN
;
2583 if (ui_out_is_mi_like_p (uiout
))
2586 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2587 result
= PRINT_UNKNOWN
;
2592 case bp_longjmp_resume
:
2593 case bp_step_resume
:
2594 case bp_watchpoint_scope
:
2599 result
= PRINT_UNKNOWN
;
2603 do_cleanups (old_chain
);
2607 /* Generic routine for printing messages indicating why we
2608 stopped. The behavior of this function depends on the value
2609 'print_it' in the bpstat structure. Under some circumstances we
2610 may decide not to print anything here and delegate the task to
2613 static enum print_stop_action
2614 print_bp_stop_message (bpstat bs
)
2616 switch (bs
->print_it
)
2619 /* Nothing should be printed for this bpstat entry. */
2620 return PRINT_UNKNOWN
;
2624 /* We still want to print the frame, but we already printed the
2625 relevant messages. */
2626 return PRINT_SRC_AND_LOC
;
2629 case print_it_normal
:
2631 const struct bp_location
*bl
= bs
->breakpoint_at
;
2632 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2634 /* Normal case. Call the breakpoint's print_it method, or
2635 print_it_typical. */
2636 /* FIXME: how breakpoint can ever be NULL here? */
2637 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2638 return b
->ops
->print_it (b
);
2640 return print_it_typical (bs
);
2645 internal_error (__FILE__
, __LINE__
,
2646 _("print_bp_stop_message: unrecognized enum value"));
2651 /* Print a message indicating what happened. This is called from
2652 normal_stop(). The input to this routine is the head of the bpstat
2653 list - a list of the eventpoints that caused this stop. This
2654 routine calls the generic print routine for printing a message
2655 about reasons for stopping. This will print (for example) the
2656 "Breakpoint n," part of the output. The return value of this
2659 PRINT_UNKNOWN: Means we printed nothing
2660 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2661 code to print the location. An example is
2662 "Breakpoint 1, " which should be followed by
2664 PRINT_SRC_ONLY: Means we printed something, but there is no need
2665 to also print the location part of the message.
2666 An example is the catch/throw messages, which
2667 don't require a location appended to the end.
2668 PRINT_NOTHING: We have done some printing and we don't need any
2669 further info to be printed.*/
2671 enum print_stop_action
2672 bpstat_print (bpstat bs
)
2676 /* Maybe another breakpoint in the chain caused us to stop.
2677 (Currently all watchpoints go on the bpstat whether hit or not.
2678 That probably could (should) be changed, provided care is taken
2679 with respect to bpstat_explains_signal). */
2680 for (; bs
; bs
= bs
->next
)
2682 val
= print_bp_stop_message (bs
);
2683 if (val
== PRINT_SRC_ONLY
2684 || val
== PRINT_SRC_AND_LOC
2685 || val
== PRINT_NOTHING
)
2689 /* We reached the end of the chain, or we got a null BS to start
2690 with and nothing was printed. */
2691 return PRINT_UNKNOWN
;
2694 /* Evaluate the expression EXP and return 1 if value is zero.
2695 This is used inside a catch_errors to evaluate the breakpoint condition.
2696 The argument is a "struct expression *" that has been cast to char * to
2697 make it pass through catch_errors. */
2700 breakpoint_cond_eval (void *exp
)
2702 struct value
*mark
= value_mark ();
2703 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2704 value_free_to_mark (mark
);
2708 /* Allocate a new bpstat and chain it to the current one. */
2711 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2715 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2717 bs
->breakpoint_at
= bl
;
2718 /* If the condition is false, etc., don't do the commands. */
2719 bs
->commands
= NULL
;
2721 bs
->print_it
= print_it_normal
;
2725 /* The target has stopped with waitstatus WS. Check if any hardware
2726 watchpoints have triggered, according to the target. */
2729 watchpoints_triggered (struct target_waitstatus
*ws
)
2731 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
2733 struct breakpoint
*b
;
2735 if (!stopped_by_watchpoint
)
2737 /* We were not stopped by a watchpoint. Mark all watchpoints
2738 as not triggered. */
2740 if (b
->type
== bp_hardware_watchpoint
2741 || b
->type
== bp_read_watchpoint
2742 || b
->type
== bp_access_watchpoint
)
2743 b
->watchpoint_triggered
= watch_triggered_no
;
2748 if (!target_stopped_data_address (¤t_target
, &addr
))
2750 /* We were stopped by a watchpoint, but we don't know where.
2751 Mark all watchpoints as unknown. */
2753 if (b
->type
== bp_hardware_watchpoint
2754 || b
->type
== bp_read_watchpoint
2755 || b
->type
== bp_access_watchpoint
)
2756 b
->watchpoint_triggered
= watch_triggered_unknown
;
2758 return stopped_by_watchpoint
;
2761 /* The target could report the data address. Mark watchpoints
2762 affected by this data address as triggered, and all others as not
2766 if (b
->type
== bp_hardware_watchpoint
2767 || b
->type
== bp_read_watchpoint
2768 || b
->type
== bp_access_watchpoint
)
2770 struct bp_location
*loc
;
2773 b
->watchpoint_triggered
= watch_triggered_no
;
2774 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2775 /* Exact match not required. Within range is
2777 if (target_watchpoint_addr_within_range (¤t_target
,
2781 b
->watchpoint_triggered
= watch_triggered_yes
;
2789 /* Possible return values for watchpoint_check (this can't be an enum
2790 because of check_errors). */
2791 /* The watchpoint has been deleted. */
2792 #define WP_DELETED 1
2793 /* The value has changed. */
2794 #define WP_VALUE_CHANGED 2
2795 /* The value has not changed. */
2796 #define WP_VALUE_NOT_CHANGED 3
2798 #define BP_TEMPFLAG 1
2799 #define BP_HARDWAREFLAG 2
2801 /* Check watchpoint condition. */
2804 watchpoint_check (void *p
)
2806 bpstat bs
= (bpstat
) p
;
2807 struct breakpoint
*b
;
2808 struct frame_info
*fr
;
2809 int within_current_scope
;
2811 b
= bs
->breakpoint_at
->owner
;
2813 if (b
->exp_valid_block
== NULL
)
2814 within_current_scope
= 1;
2817 struct frame_info
*frame
= get_current_frame ();
2818 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
2819 CORE_ADDR frame_pc
= get_frame_pc (frame
);
2821 fr
= frame_find_by_id (b
->watchpoint_frame
);
2822 within_current_scope
= (fr
!= NULL
);
2824 /* If we've gotten confused in the unwinder, we might have
2825 returned a frame that can't describe this variable. */
2826 if (within_current_scope
)
2828 struct symbol
*function
;
2830 function
= get_frame_function (fr
);
2831 if (function
== NULL
2832 || !contained_in (b
->exp_valid_block
,
2833 SYMBOL_BLOCK_VALUE (function
)))
2834 within_current_scope
= 0;
2837 /* in_function_epilogue_p() returns a non-zero value if we're still
2838 in the function but the stack frame has already been invalidated.
2839 Since we can't rely on the values of local variables after the
2840 stack has been destroyed, we are treating the watchpoint in that
2841 state as `not changed' without further checking. Don't mark
2842 watchpoints as changed if the current frame is in an epilogue -
2843 even if they are in some other frame, our view of the stack
2844 is likely to be wrong. */
2845 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
2846 return WP_VALUE_NOT_CHANGED
;
2848 if (within_current_scope
)
2849 /* If we end up stopping, the current frame will get selected
2850 in normal_stop. So this call to select_frame won't affect
2855 if (within_current_scope
)
2857 /* We use value_{,free_to_}mark because it could be a
2858 *long* time before we return to the command level and
2859 call free_all_values. We can't call free_all_values because
2860 we might be in the middle of evaluating a function call. */
2862 struct value
*mark
= value_mark ();
2863 struct value
*new_val
;
2865 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2866 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2867 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2869 if (new_val
!= NULL
)
2871 release_value (new_val
);
2872 value_free_to_mark (mark
);
2874 bs
->old_val
= b
->val
;
2877 /* We will stop here */
2878 return WP_VALUE_CHANGED
;
2882 /* Nothing changed, don't do anything. */
2883 value_free_to_mark (mark
);
2884 /* We won't stop here */
2885 return WP_VALUE_NOT_CHANGED
;
2890 /* This seems like the only logical thing to do because
2891 if we temporarily ignored the watchpoint, then when
2892 we reenter the block in which it is valid it contains
2893 garbage (in the case of a function, it may have two
2894 garbage values, one before and one after the prologue).
2895 So we can't even detect the first assignment to it and
2896 watch after that (since the garbage may or may not equal
2897 the first value assigned). */
2898 /* We print all the stop information in print_it_typical(), but
2899 in this case, by the time we call print_it_typical() this bp
2900 will be deleted already. So we have no choice but print the
2901 information here. */
2902 if (ui_out_is_mi_like_p (uiout
))
2904 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2905 ui_out_text (uiout
, "\nWatchpoint ");
2906 ui_out_field_int (uiout
, "wpnum", b
->number
);
2907 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2908 which its expression is valid.\n");
2910 if (b
->related_breakpoint
)
2911 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2912 b
->disposition
= disp_del_at_next_stop
;
2918 /* Return true if it looks like target has stopped due to hitting
2919 breakpoint location BL. This function does not check if we
2920 should stop, only if BL explains the stop. */
2922 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2924 struct breakpoint
*b
= bl
->owner
;
2926 if (b
->type
!= bp_watchpoint
2927 && b
->type
!= bp_hardware_watchpoint
2928 && b
->type
!= bp_read_watchpoint
2929 && b
->type
!= bp_access_watchpoint
2930 && b
->type
!= bp_hardware_breakpoint
2931 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2933 if (bl
->address
!= bp_addr
) /* address doesn't match */
2935 if (overlay_debugging
/* unmapped overlay section */
2936 && section_is_overlay (bl
->section
)
2937 && !section_is_mapped (bl
->section
))
2941 /* Continuable hardware watchpoints are treated as non-existent if the
2942 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2943 some data address). Otherwise gdb won't stop on a break instruction
2944 in the code (not from a breakpoint) when a hardware watchpoint has
2945 been defined. Also skip watchpoints which we know did not trigger
2946 (did not match the data address). */
2948 if ((b
->type
== bp_hardware_watchpoint
2949 || b
->type
== bp_read_watchpoint
2950 || b
->type
== bp_access_watchpoint
)
2951 && b
->watchpoint_triggered
== watch_triggered_no
)
2954 if (b
->type
== bp_hardware_breakpoint
)
2956 if (bl
->address
!= bp_addr
)
2958 if (overlay_debugging
/* unmapped overlay section */
2959 && section_is_overlay (bl
->section
)
2960 && !section_is_mapped (bl
->section
))
2964 if (b
->type
== bp_catchpoint
)
2966 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2967 if (!b
->ops
->breakpoint_hit (b
))
2974 /* If BS refers to a watchpoint, determine if the watched values
2975 has actually changed, and we should stop. If not, set BS->stop
2978 bpstat_check_watchpoint (bpstat bs
)
2980 const struct bp_location
*bl
= bs
->breakpoint_at
;
2981 struct breakpoint
*b
= bl
->owner
;
2983 if (b
->type
== bp_watchpoint
2984 || b
->type
== bp_read_watchpoint
2985 || b
->type
== bp_access_watchpoint
2986 || b
->type
== bp_hardware_watchpoint
)
2990 int must_check_value
= 0;
2992 if (b
->type
== bp_watchpoint
)
2993 /* For a software watchpoint, we must always check the
2995 must_check_value
= 1;
2996 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2997 /* We have a hardware watchpoint (read, write, or access)
2998 and the target earlier reported an address watched by
3000 must_check_value
= 1;
3001 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3002 && b
->type
== bp_hardware_watchpoint
)
3003 /* We were stopped by a hardware watchpoint, but the target could
3004 not report the data address. We must check the watchpoint's
3005 value. Access and read watchpoints are out of luck; without
3006 a data address, we can't figure it out. */
3007 must_check_value
= 1;
3009 if (must_check_value
)
3011 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3013 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3014 int e
= catch_errors (watchpoint_check
, bs
, message
,
3016 do_cleanups (cleanups
);
3020 /* We've already printed what needs to be printed. */
3021 bs
->print_it
= print_it_done
;
3024 case WP_VALUE_CHANGED
:
3025 if (b
->type
== bp_read_watchpoint
)
3027 /* Don't stop: read watchpoints shouldn't fire if
3028 the value has changed. This is for targets
3029 which cannot set read-only watchpoints. */
3030 bs
->print_it
= print_it_noop
;
3034 case WP_VALUE_NOT_CHANGED
:
3035 if (b
->type
== bp_hardware_watchpoint
3036 || b
->type
== bp_watchpoint
)
3038 /* Don't stop: write watchpoints shouldn't fire if
3039 the value hasn't changed. */
3040 bs
->print_it
= print_it_noop
;
3048 /* Error from catch_errors. */
3049 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3050 if (b
->related_breakpoint
)
3051 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3052 b
->disposition
= disp_del_at_next_stop
;
3053 /* We've already printed what needs to be printed. */
3054 bs
->print_it
= print_it_done
;
3058 else /* must_check_value == 0 */
3060 /* This is a case where some watchpoint(s) triggered, but
3061 not at the address of this watchpoint, or else no
3062 watchpoint triggered after all. So don't print
3063 anything for this watchpoint. */
3064 bs
->print_it
= print_it_noop
;
3071 /* Check conditions (condition proper, frame, thread and ignore count)
3072 of breakpoint referred to by BS. If we should not stop for this
3073 breakpoint, set BS->stop to 0. */
3075 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3077 int thread_id
= pid_to_thread_id (ptid
);
3078 const struct bp_location
*bl
= bs
->breakpoint_at
;
3079 struct breakpoint
*b
= bl
->owner
;
3081 if (frame_id_p (b
->frame_id
)
3082 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3086 int value_is_zero
= 0;
3088 /* If this is a scope breakpoint, mark the associated
3089 watchpoint as triggered so that we will handle the
3090 out-of-scope event. We'll get to the watchpoint next
3092 if (b
->type
== bp_watchpoint_scope
)
3093 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3095 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3097 /* We use value_mark and value_free_to_mark because it could
3098 be a long time before we return to the command level and
3099 call free_all_values. We can't call free_all_values
3100 because we might be in the middle of evaluating a
3102 struct value
*mark
= value_mark ();
3104 /* Need to select the frame, with all that implies so that
3105 the conditions will have the right context. Because we
3106 use the frame, we will not see an inlined function's
3107 variables when we arrive at a breakpoint at the start
3108 of the inlined function; the current frame will be the
3110 select_frame (get_current_frame ());
3112 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3113 "Error in testing breakpoint condition:\n",
3115 /* FIXME-someday, should give breakpoint # */
3116 value_free_to_mark (mark
);
3118 if (bl
->cond
&& value_is_zero
)
3122 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3126 else if (b
->ignore_count
> 0)
3129 annotate_ignore_count_change ();
3131 /* Increase the hit count even though we don't
3139 /* Get a bpstat associated with having just stopped at address
3140 BP_ADDR in thread PTID.
3142 Determine whether we stopped at a breakpoint, etc, or whether we
3143 don't understand this stop. Result is a chain of bpstat's such that:
3145 if we don't understand the stop, the result is a null pointer.
3147 if we understand why we stopped, the result is not null.
3149 Each element of the chain refers to a particular breakpoint or
3150 watchpoint at which we have stopped. (We may have stopped for
3151 several reasons concurrently.)
3153 Each element of the chain has valid next, breakpoint_at,
3154 commands, FIXME??? fields. */
3157 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3159 struct breakpoint
*b
= NULL
;
3160 const struct bp_location
*bl
;
3161 struct bp_location
*loc
;
3162 /* Root of the chain of bpstat's */
3163 struct bpstats root_bs
[1];
3164 /* Pointer to the last thing in the chain currently. */
3165 bpstat bs
= root_bs
;
3167 int need_remove_insert
;
3169 ALL_BP_LOCATIONS (bl
)
3173 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3176 /* For hardware watchpoints, we look only at the first location.
3177 The watchpoint_check function will work on entire expression,
3178 not the individual locations. For read watchopints, the
3179 watchpoints_triggered function have checked all locations
3182 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3185 if (!bpstat_check_location (bl
, bp_addr
))
3188 /* Come here if it's a watchpoint, or if the break address matches */
3190 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3192 /* Assume we stop. Should we find watchpoint that is not actually
3193 triggered, or if condition of breakpoint is false, we'll reset
3198 bpstat_check_watchpoint (bs
);
3202 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3203 || b
->type
== bp_longjmp_master
)
3204 /* We do not stop for these. */
3207 bpstat_check_breakpoint_conditions (bs
, ptid
);
3213 /* We will stop here */
3214 if (b
->disposition
== disp_disable
)
3216 if (b
->enable_state
!= bp_permanent
)
3217 b
->enable_state
= bp_disabled
;
3218 update_global_location_list (0);
3222 bs
->commands
= b
->commands
;
3224 && (strcmp ("silent", bs
->commands
->line
) == 0
3225 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3227 bs
->commands
= bs
->commands
->next
;
3230 bs
->commands
= copy_command_lines (bs
->commands
);
3233 /* Print nothing for this entry if we dont stop or if we dont print. */
3234 if (bs
->stop
== 0 || bs
->print
== 0)
3235 bs
->print_it
= print_it_noop
;
3238 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3240 if (loc
->address
== bp_addr
)
3242 bs
= bpstat_alloc (loc
, bs
);
3243 /* For hits of moribund locations, we should just proceed. */
3246 bs
->print_it
= print_it_noop
;
3250 bs
->next
= NULL
; /* Terminate the chain */
3251 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3253 /* If we aren't stopping, the value of some hardware watchpoint may
3254 not have changed, but the intermediate memory locations we are
3255 watching may have. Don't bother if we're stopping; this will get
3257 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3261 need_remove_insert
= 0;
3263 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3265 && bs
->breakpoint_at
->owner
3266 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3267 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3268 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3270 /* remove/insert can invalidate bs->breakpoint_at, if this
3271 location is no longer used by the watchpoint. Prevent
3272 further code from trying to use it. */
3273 bs
->breakpoint_at
= NULL
;
3274 need_remove_insert
= 1;
3277 if (need_remove_insert
)
3279 remove_breakpoints ();
3280 insert_breakpoints ();
3283 return root_bs
->next
;
3286 /* Tell what to do about this bpstat. */
3288 bpstat_what (bpstat bs
)
3290 /* Classify each bpstat as one of the following. */
3293 /* This bpstat element has no effect on the main_action. */
3296 /* There was a watchpoint, stop but don't print. */
3299 /* There was a watchpoint, stop and print. */
3302 /* There was a breakpoint but we're not stopping. */
3305 /* There was a breakpoint, stop but don't print. */
3308 /* There was a breakpoint, stop and print. */
3311 /* We hit the longjmp breakpoint. */
3314 /* We hit the longjmp_resume breakpoint. */
3317 /* We hit the step_resume breakpoint. */
3320 /* We hit the shared library event breakpoint. */
3323 /* We hit the jit event breakpoint. */
3326 /* This is just used to count how many enums there are. */
3330 /* Here is the table which drives this routine. So that we can
3331 format it pretty, we define some abbreviations for the
3332 enum bpstat_what codes. */
3333 #define kc BPSTAT_WHAT_KEEP_CHECKING
3334 #define ss BPSTAT_WHAT_STOP_SILENT
3335 #define sn BPSTAT_WHAT_STOP_NOISY
3336 #define sgl BPSTAT_WHAT_SINGLE
3337 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3338 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3339 #define sr BPSTAT_WHAT_STEP_RESUME
3340 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3341 #define jit BPSTAT_WHAT_CHECK_JIT
3343 /* "Can't happen." Might want to print an error message.
3344 abort() is not out of the question, but chances are GDB is just
3345 a bit confused, not unusable. */
3346 #define err BPSTAT_WHAT_STOP_NOISY
3348 /* Given an old action and a class, come up with a new action. */
3349 /* One interesting property of this table is that wp_silent is the same
3350 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3351 after stopping, the check for whether to step over a breakpoint
3352 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3353 reference to how we stopped. We retain separate wp_silent and
3354 bp_silent codes in case we want to change that someday.
3356 Another possibly interesting property of this table is that
3357 there's a partial ordering, priority-like, of the actions. Once
3358 you've decided that some action is appropriate, you'll never go
3359 back and decide something of a lower priority is better. The
3362 kc < jit clr sgl shl slr sn sr ss
3363 sgl < jit shl slr sn sr ss
3364 slr < jit err shl sn sr ss
3365 clr < jit err shl sn sr ss
3372 What I think this means is that we don't need a damned table
3373 here. If you just put the rows and columns in the right order,
3374 it'd look awfully regular. We could simply walk the bpstat list
3375 and choose the highest priority action we find, with a little
3376 logic to handle the 'err' cases. */
3378 /* step_resume entries: a step resume breakpoint overrides another
3379 breakpoint of signal handling (see comment in wait_for_inferior
3380 at where we set the step_resume breakpoint). */
3382 static const enum bpstat_what_main_action
3383 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3386 /* kc ss sn sgl slr clr sr shl jit */
3387 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
3388 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
3389 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
3390 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
3391 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
3392 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
3393 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
3394 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
3395 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3396 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
3397 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
3411 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3412 struct bpstat_what retval
;
3414 retval
.call_dummy
= 0;
3415 for (; bs
!= NULL
; bs
= bs
->next
)
3417 enum class bs_class
= no_effect
;
3418 if (bs
->breakpoint_at
== NULL
)
3419 /* I suspect this can happen if it was a momentary breakpoint
3420 which has since been deleted. */
3422 if (bs
->breakpoint_at
->owner
== NULL
)
3423 bs_class
= bp_nostop
;
3425 switch (bs
->breakpoint_at
->owner
->type
)
3431 case bp_hardware_breakpoint
:
3437 bs_class
= bp_noisy
;
3439 bs_class
= bp_silent
;
3442 bs_class
= bp_nostop
;
3445 case bp_hardware_watchpoint
:
3446 case bp_read_watchpoint
:
3447 case bp_access_watchpoint
:
3451 bs_class
= wp_noisy
;
3453 bs_class
= wp_silent
;
3456 /* There was a watchpoint, but we're not stopping.
3457 This requires no further action. */
3458 bs_class
= no_effect
;
3461 bs_class
= long_jump
;
3463 case bp_longjmp_resume
:
3464 bs_class
= long_resume
;
3466 case bp_step_resume
:
3469 bs_class
= step_resume
;
3472 /* It is for the wrong frame. */
3473 bs_class
= bp_nostop
;
3475 case bp_watchpoint_scope
:
3476 bs_class
= bp_nostop
;
3478 case bp_shlib_event
:
3479 bs_class
= shlib_event
;
3482 bs_class
= jit_event
;
3484 case bp_thread_event
:
3485 case bp_overlay_event
:
3486 case bp_longjmp_master
:
3487 bs_class
= bp_nostop
;
3493 bs_class
= bp_noisy
;
3495 bs_class
= bp_silent
;
3498 /* There was a catchpoint, but we're not stopping.
3499 This requires no further action. */
3500 bs_class
= no_effect
;
3503 /* Make sure the action is stop (silent or noisy),
3504 so infrun.c pops the dummy frame. */
3505 bs_class
= bp_silent
;
3506 retval
.call_dummy
= 1;
3509 /* Tracepoint hits should not be reported back to GDB, and
3510 if one got through somehow, it should have been filtered
3512 internal_error (__FILE__
, __LINE__
,
3513 _("bpstat_what: bp_tracepoint encountered"));
3516 current_action
= table
[(int) bs_class
][(int) current_action
];
3518 retval
.main_action
= current_action
;
3522 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3523 without hardware support). This isn't related to a specific bpstat,
3524 just to things like whether watchpoints are set. */
3527 bpstat_should_step (void)
3529 struct breakpoint
*b
;
3531 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3538 static void print_breakpoint_location (struct breakpoint
*b
,
3539 struct bp_location
*loc
,
3541 struct ui_stream
*stb
)
3546 = find_pc_sect_function (loc
->address
, loc
->section
);
3549 ui_out_text (uiout
, "in ");
3550 ui_out_field_string (uiout
, "func",
3551 SYMBOL_PRINT_NAME (sym
));
3552 ui_out_wrap_hint (uiout
, wrap_indent
);
3553 ui_out_text (uiout
, " at ");
3555 ui_out_field_string (uiout
, "file", b
->source_file
);
3556 ui_out_text (uiout
, ":");
3558 if (ui_out_is_mi_like_p (uiout
))
3560 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3561 char *fullname
= symtab_to_fullname (sal
.symtab
);
3564 ui_out_field_string (uiout
, "fullname", fullname
);
3567 ui_out_field_int (uiout
, "line", b
->line_number
);
3571 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3575 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3576 ui_out_field_stream (uiout
, "at", stb
);
3580 /* Print B to gdb_stdout. */
3582 print_one_breakpoint_location (struct breakpoint
*b
,
3583 struct bp_location
*loc
,
3585 struct bp_location
**last_loc
,
3586 int print_address_bits
)
3588 struct command_line
*l
;
3590 struct ep_type_description
3595 static struct ep_type_description bptypes
[] =
3597 {bp_none
, "?deleted?"},
3598 {bp_breakpoint
, "breakpoint"},
3599 {bp_hardware_breakpoint
, "hw breakpoint"},
3600 {bp_until
, "until"},
3601 {bp_finish
, "finish"},
3602 {bp_watchpoint
, "watchpoint"},
3603 {bp_hardware_watchpoint
, "hw watchpoint"},
3604 {bp_read_watchpoint
, "read watchpoint"},
3605 {bp_access_watchpoint
, "acc watchpoint"},
3606 {bp_longjmp
, "longjmp"},
3607 {bp_longjmp_resume
, "longjmp resume"},
3608 {bp_step_resume
, "step resume"},
3609 {bp_watchpoint_scope
, "watchpoint scope"},
3610 {bp_call_dummy
, "call dummy"},
3611 {bp_shlib_event
, "shlib events"},
3612 {bp_thread_event
, "thread events"},
3613 {bp_overlay_event
, "overlay events"},
3614 {bp_longjmp_master
, "longjmp master"},
3615 {bp_catchpoint
, "catchpoint"},
3616 {bp_tracepoint
, "tracepoint"},
3617 {bp_jit_event
, "jit events"},
3620 static char bpenables
[] = "nynny";
3621 char wrap_indent
[80];
3622 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3623 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3624 struct cleanup
*bkpt_chain
;
3626 int header_of_multiple
= 0;
3627 int part_of_multiple
= (loc
!= NULL
);
3628 struct value_print_options opts
;
3630 get_user_print_options (&opts
);
3632 gdb_assert (!loc
|| loc_number
!= 0);
3633 /* See comment in print_one_breakpoint concerning
3634 treatment of breakpoints with single disabled
3638 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3639 header_of_multiple
= 1;
3644 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3648 if (part_of_multiple
)
3651 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3652 ui_out_field_string (uiout
, "number", formatted
);
3657 ui_out_field_int (uiout
, "number", b
->number
);
3662 if (part_of_multiple
)
3663 ui_out_field_skip (uiout
, "type");
3666 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3667 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3668 internal_error (__FILE__
, __LINE__
,
3669 _("bptypes table does not describe type #%d."),
3671 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3676 if (part_of_multiple
)
3677 ui_out_field_skip (uiout
, "disp");
3679 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3684 if (part_of_multiple
)
3685 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3687 ui_out_field_fmt (uiout
, "enabled", "%c",
3688 bpenables
[(int) b
->enable_state
]);
3689 ui_out_spaces (uiout
, 2);
3693 strcpy (wrap_indent
, " ");
3694 if (opts
.addressprint
)
3696 if (print_address_bits
<= 32)
3697 strcat (wrap_indent
, " ");
3699 strcat (wrap_indent
, " ");
3702 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3704 /* Although the print_one can possibly print
3705 all locations, calling it here is not likely
3706 to get any nice result. So, make sure there's
3707 just one location. */
3708 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3709 b
->ops
->print_one (b
, last_loc
);
3715 internal_error (__FILE__
, __LINE__
,
3716 _("print_one_breakpoint: bp_none encountered\n"));
3720 case bp_hardware_watchpoint
:
3721 case bp_read_watchpoint
:
3722 case bp_access_watchpoint
:
3723 /* Field 4, the address, is omitted (which makes the columns
3724 not line up too nicely with the headers, but the effect
3725 is relatively readable). */
3726 if (opts
.addressprint
)
3727 ui_out_field_skip (uiout
, "addr");
3729 ui_out_field_string (uiout
, "what", b
->exp_string
);
3733 case bp_hardware_breakpoint
:
3737 case bp_longjmp_resume
:
3738 case bp_step_resume
:
3739 case bp_watchpoint_scope
:
3741 case bp_shlib_event
:
3742 case bp_thread_event
:
3743 case bp_overlay_event
:
3744 case bp_longjmp_master
:
3747 if (opts
.addressprint
)
3750 if (header_of_multiple
)
3751 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3752 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3753 ui_out_field_string (uiout
, "addr", "<PENDING>");
3755 ui_out_field_core_addr (uiout
, "addr",
3756 loc
->gdbarch
, loc
->address
);
3759 if (!header_of_multiple
)
3760 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3766 if (!part_of_multiple
)
3768 if (b
->thread
!= -1)
3770 /* FIXME: This seems to be redundant and lost here; see the
3771 "stop only in" line a little further down. */
3772 ui_out_text (uiout
, " thread ");
3773 ui_out_field_int (uiout
, "thread", b
->thread
);
3775 else if (b
->task
!= 0)
3777 ui_out_text (uiout
, " task ");
3778 ui_out_field_int (uiout
, "task", b
->task
);
3782 ui_out_text (uiout
, "\n");
3784 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3787 ui_out_text (uiout
, "\tstop only in stack frame at ");
3788 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3790 ui_out_field_core_addr (uiout
, "frame",
3791 b
->gdbarch
, b
->frame_id
.stack_addr
);
3792 ui_out_text (uiout
, "\n");
3795 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3797 /* We do not print the condition for Ada exception catchpoints
3798 because the condition is an internal implementation detail
3799 that we do not want to expose to the user. */
3801 if (b
->type
== bp_tracepoint
)
3802 ui_out_text (uiout
, "\ttrace only if ");
3804 ui_out_text (uiout
, "\tstop only if ");
3805 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3806 ui_out_text (uiout
, "\n");
3809 if (!part_of_multiple
&& b
->thread
!= -1)
3811 /* FIXME should make an annotation for this */
3812 ui_out_text (uiout
, "\tstop only in thread ");
3813 ui_out_field_int (uiout
, "thread", b
->thread
);
3814 ui_out_text (uiout
, "\n");
3817 if (!part_of_multiple
&& b
->hit_count
)
3819 /* FIXME should make an annotation for this */
3820 if (ep_is_catchpoint (b
))
3821 ui_out_text (uiout
, "\tcatchpoint");
3823 ui_out_text (uiout
, "\tbreakpoint");
3824 ui_out_text (uiout
, " already hit ");
3825 ui_out_field_int (uiout
, "times", b
->hit_count
);
3826 if (b
->hit_count
== 1)
3827 ui_out_text (uiout
, " time\n");
3829 ui_out_text (uiout
, " times\n");
3832 /* Output the count also if it is zero, but only if this is
3833 mi. FIXME: Should have a better test for this. */
3834 if (ui_out_is_mi_like_p (uiout
))
3835 if (!part_of_multiple
&& b
->hit_count
== 0)
3836 ui_out_field_int (uiout
, "times", b
->hit_count
);
3838 if (!part_of_multiple
&& b
->ignore_count
)
3841 ui_out_text (uiout
, "\tignore next ");
3842 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3843 ui_out_text (uiout
, " hits\n");
3847 if (!part_of_multiple
&& l
)
3849 struct cleanup
*script_chain
;
3852 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3853 print_command_lines (uiout
, l
, 4);
3854 do_cleanups (script_chain
);
3857 if (!part_of_multiple
&& b
->pass_count
)
3859 annotate_field (10);
3860 ui_out_text (uiout
, "\tpass count ");
3861 ui_out_field_int (uiout
, "pass", b
->pass_count
);
3862 ui_out_text (uiout
, " \n");
3865 if (!part_of_multiple
&& b
->step_count
)
3867 annotate_field (11);
3868 ui_out_text (uiout
, "\tstep count ");
3869 ui_out_field_int (uiout
, "step", b
->step_count
);
3870 ui_out_text (uiout
, " \n");
3873 if (!part_of_multiple
&& b
->actions
)
3875 struct action_line
*action
;
3876 annotate_field (12);
3877 for (action
= b
->actions
; action
; action
= action
->next
)
3879 ui_out_text (uiout
, " A\t");
3880 ui_out_text (uiout
, action
->action
);
3881 ui_out_text (uiout
, "\n");
3885 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3888 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3889 else if (b
->exp_string
)
3890 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3893 do_cleanups (bkpt_chain
);
3894 do_cleanups (old_chain
);
3898 print_one_breakpoint (struct breakpoint
*b
,
3899 struct bp_location
**last_loc
, int print_address_bits
)
3901 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, print_address_bits
);
3903 /* If this breakpoint has custom print function,
3904 it's already printed. Otherwise, print individual
3905 locations, if any. */
3906 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3908 /* If breakpoint has a single location that is
3909 disabled, we print it as if it had
3910 several locations, since otherwise it's hard to
3911 represent "breakpoint enabled, location disabled"
3913 Note that while hardware watchpoints have
3914 several locations internally, that's no a property
3917 && !is_hardware_watchpoint (b
)
3918 && (b
->loc
->next
|| !b
->loc
->enabled
)
3919 && !ui_out_is_mi_like_p (uiout
))
3921 struct bp_location
*loc
;
3923 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3924 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
3925 print_address_bits
);
3931 breakpoint_address_bits (struct breakpoint
*b
)
3933 int print_address_bits
= 0;
3934 struct bp_location
*loc
;
3936 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3938 int addr_bit
= gdbarch_addr_bit (b
->gdbarch
);
3939 if (addr_bit
> print_address_bits
)
3940 print_address_bits
= addr_bit
;
3943 return print_address_bits
;
3946 struct captured_breakpoint_query_args
3952 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3954 struct captured_breakpoint_query_args
*args
= data
;
3955 struct breakpoint
*b
;
3956 struct bp_location
*dummy_loc
= NULL
;
3959 if (args
->bnum
== b
->number
)
3961 int print_address_bits
= breakpoint_address_bits (b
);
3962 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
);
3970 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3972 struct captured_breakpoint_query_args args
;
3974 /* For the moment we don't trust print_one_breakpoint() to not throw
3976 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3977 error_message
, RETURN_MASK_ALL
) < 0)
3983 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3984 catchpoints, et.al.). */
3987 user_settable_breakpoint (const struct breakpoint
*b
)
3989 return (b
->type
== bp_breakpoint
3990 || b
->type
== bp_catchpoint
3991 || b
->type
== bp_hardware_breakpoint
3992 || b
->type
== bp_tracepoint
3993 || b
->type
== bp_watchpoint
3994 || b
->type
== bp_read_watchpoint
3995 || b
->type
== bp_access_watchpoint
3996 || b
->type
== bp_hardware_watchpoint
);
3999 /* Print information on user settable breakpoint (watchpoint, etc)
4000 number BNUM. If BNUM is -1 print all user settable breakpoints.
4001 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4004 breakpoint_1 (int bnum
, int allflag
)
4006 struct breakpoint
*b
;
4007 struct bp_location
*last_loc
= NULL
;
4008 int nr_printable_breakpoints
;
4009 struct cleanup
*bkpttbl_chain
;
4010 struct value_print_options opts
;
4011 int print_address_bits
= 0;
4013 get_user_print_options (&opts
);
4015 /* Compute the number of rows in the table, as well as the
4016 size required for address fields. */
4017 nr_printable_breakpoints
= 0;
4020 || bnum
== b
->number
)
4022 if (allflag
|| user_settable_breakpoint (b
))
4024 int addr_bit
= breakpoint_address_bits (b
);
4025 if (addr_bit
> print_address_bits
)
4026 print_address_bits
= addr_bit
;
4028 nr_printable_breakpoints
++;
4032 if (opts
.addressprint
)
4034 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4038 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4041 if (nr_printable_breakpoints
> 0)
4042 annotate_breakpoints_headers ();
4043 if (nr_printable_breakpoints
> 0)
4045 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4046 if (nr_printable_breakpoints
> 0)
4048 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4049 if (nr_printable_breakpoints
> 0)
4051 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4052 if (nr_printable_breakpoints
> 0)
4054 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4055 if (opts
.addressprint
)
4057 if (nr_printable_breakpoints
> 0)
4059 if (print_address_bits
<= 32)
4060 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4062 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4064 if (nr_printable_breakpoints
> 0)
4066 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4067 ui_out_table_body (uiout
);
4068 if (nr_printable_breakpoints
> 0)
4069 annotate_breakpoints_table ();
4073 || bnum
== b
->number
)
4075 /* We only print out user settable breakpoints unless the
4077 if (allflag
|| user_settable_breakpoint (b
))
4078 print_one_breakpoint (b
, &last_loc
, print_address_bits
);
4081 do_cleanups (bkpttbl_chain
);
4083 if (nr_printable_breakpoints
== 0)
4086 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4088 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4093 if (last_loc
&& !server_command
)
4094 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4097 /* FIXME? Should this be moved up so that it is only called when
4098 there have been breakpoints? */
4099 annotate_breakpoints_table_end ();
4103 breakpoints_info (char *bnum_exp
, int from_tty
)
4108 bnum
= parse_and_eval_long (bnum_exp
);
4110 breakpoint_1 (bnum
, 0);
4114 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4119 bnum
= parse_and_eval_long (bnum_exp
);
4121 breakpoint_1 (bnum
, 1);
4125 breakpoint_has_pc (struct breakpoint
*b
,
4126 CORE_ADDR pc
, struct obj_section
*section
)
4128 struct bp_location
*bl
= b
->loc
;
4129 for (; bl
; bl
= bl
->next
)
4131 if (bl
->address
== pc
4132 && (!overlay_debugging
|| bl
->section
== section
))
4138 /* Print a message describing any breakpoints set at PC. */
4141 describe_other_breakpoints (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
4142 struct obj_section
*section
, int thread
)
4145 struct breakpoint
*b
;
4148 others
+= breakpoint_has_pc (b
, pc
, section
);
4152 printf_filtered (_("Note: breakpoint "));
4153 else /* if (others == ???) */
4154 printf_filtered (_("Note: breakpoints "));
4156 if (breakpoint_has_pc (b
, pc
, section
))
4159 printf_filtered ("%d", b
->number
);
4160 if (b
->thread
== -1 && thread
!= -1)
4161 printf_filtered (" (all threads)");
4162 else if (b
->thread
!= -1)
4163 printf_filtered (" (thread %d)", b
->thread
);
4164 printf_filtered ("%s%s ",
4165 ((b
->enable_state
== bp_disabled
4166 || b
->enable_state
== bp_call_disabled
4167 || b
->enable_state
== bp_startup_disabled
)
4169 : b
->enable_state
== bp_permanent
4173 : ((others
== 1) ? " and" : ""));
4175 printf_filtered (_("also set at pc "));
4176 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4177 printf_filtered (".\n");
4181 /* Set the default place to put a breakpoint
4182 for the `break' command with no arguments. */
4185 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4188 default_breakpoint_valid
= valid
;
4189 default_breakpoint_address
= addr
;
4190 default_breakpoint_symtab
= symtab
;
4191 default_breakpoint_line
= line
;
4194 /* Return true iff it is meaningful to use the address member of
4195 BPT. For some breakpoint types, the address member is irrelevant
4196 and it makes no sense to attempt to compare it to other addresses
4197 (or use it for any other purpose either).
4199 More specifically, each of the following breakpoint types will always
4200 have a zero valued address and we don't want check_duplicates() to mark
4201 breakpoints of any of these types to be a duplicate of an actual
4202 breakpoint at address zero:
4205 bp_hardware_watchpoint
4207 bp_access_watchpoint
4211 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4213 enum bptype type
= bpt
->type
;
4215 return (type
!= bp_watchpoint
4216 && type
!= bp_hardware_watchpoint
4217 && type
!= bp_read_watchpoint
4218 && type
!= bp_access_watchpoint
4219 && type
!= bp_catchpoint
);
4222 /* Rescan breakpoints at the same address and section as BPT,
4223 marking the first one as "first" and any others as "duplicates".
4224 This is so that the bpt instruction is only inserted once.
4225 If we have a permanent breakpoint at the same place as BPT, make
4226 that one the official one, and the rest as duplicates. */
4229 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4231 struct bp_location
*b
;
4233 struct bp_location
*perm_bp
= 0;
4235 ALL_BP_LOCATIONS (b
)
4236 if (b
->owner
->enable_state
!= bp_disabled
4237 && b
->owner
->enable_state
!= bp_call_disabled
4238 && b
->owner
->enable_state
!= bp_startup_disabled
4240 && !b
->shlib_disabled
4241 && b
->address
== address
/* address / overlay match */
4242 && (!overlay_debugging
|| b
->section
== section
)
4243 && breakpoint_address_is_meaningful (b
->owner
))
4245 /* Have we found a permanent breakpoint? */
4246 if (b
->owner
->enable_state
== bp_permanent
)
4253 b
->duplicate
= count
> 1;
4256 /* If we found a permanent breakpoint at this address, go over the
4257 list again and declare all the other breakpoints there (except
4258 other permanent breakpoints) to be the duplicates. */
4261 perm_bp
->duplicate
= 0;
4263 /* Permanent breakpoint should always be inserted. */
4264 if (! perm_bp
->inserted
)
4265 internal_error (__FILE__
, __LINE__
,
4266 _("allegedly permanent breakpoint is not "
4267 "actually inserted"));
4269 ALL_BP_LOCATIONS (b
)
4272 if (b
->owner
->enable_state
!= bp_permanent
4273 && b
->owner
->enable_state
!= bp_disabled
4274 && b
->owner
->enable_state
!= bp_call_disabled
4275 && b
->owner
->enable_state
!= bp_startup_disabled
4276 && b
->enabled
&& !b
->shlib_disabled
4277 && b
->address
== address
/* address / overlay match */
4278 && (!overlay_debugging
|| b
->section
== section
)
4279 && breakpoint_address_is_meaningful (b
->owner
))
4282 internal_error (__FILE__
, __LINE__
,
4283 _("another breakpoint was inserted on top of "
4284 "a permanent breakpoint"));
4293 check_duplicates (struct breakpoint
*bpt
)
4295 struct bp_location
*bl
= bpt
->loc
;
4297 if (! breakpoint_address_is_meaningful (bpt
))
4300 for (; bl
; bl
= bl
->next
)
4301 check_duplicates_for (bl
->address
, bl
->section
);
4305 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4306 int bnum
, int have_bnum
)
4311 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4312 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4314 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4315 bnum
, astr1
, astr2
);
4317 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4320 /* Adjust a breakpoint's address to account for architectural constraints
4321 on breakpoint placement. Return the adjusted address. Note: Very
4322 few targets require this kind of adjustment. For most targets,
4323 this function is simply the identity function. */
4326 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4327 CORE_ADDR bpaddr
, enum bptype bptype
)
4329 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4331 /* Very few targets need any kind of breakpoint adjustment. */
4334 else if (bptype
== bp_watchpoint
4335 || bptype
== bp_hardware_watchpoint
4336 || bptype
== bp_read_watchpoint
4337 || bptype
== bp_access_watchpoint
4338 || bptype
== bp_catchpoint
)
4340 /* Watchpoints and the various bp_catch_* eventpoints should not
4341 have their addresses modified. */
4346 CORE_ADDR adjusted_bpaddr
;
4348 /* Some targets have architectural constraints on the placement
4349 of breakpoint instructions. Obtain the adjusted address. */
4350 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
4352 /* An adjusted breakpoint address can significantly alter
4353 a user's expectations. Print a warning if an adjustment
4355 if (adjusted_bpaddr
!= bpaddr
)
4356 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4358 return adjusted_bpaddr
;
4362 /* Allocate a struct bp_location. */
4364 static struct bp_location
*
4365 allocate_bp_location (struct breakpoint
*bpt
)
4367 struct bp_location
*loc
, *loc_p
;
4369 loc
= xmalloc (sizeof (struct bp_location
));
4370 memset (loc
, 0, sizeof (*loc
));
4374 loc
->shlib_disabled
= 0;
4384 case bp_longjmp_resume
:
4385 case bp_step_resume
:
4386 case bp_watchpoint_scope
:
4388 case bp_shlib_event
:
4389 case bp_thread_event
:
4390 case bp_overlay_event
:
4392 case bp_longjmp_master
:
4393 loc
->loc_type
= bp_loc_software_breakpoint
;
4395 case bp_hardware_breakpoint
:
4396 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4398 case bp_hardware_watchpoint
:
4399 case bp_read_watchpoint
:
4400 case bp_access_watchpoint
:
4401 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4405 loc
->loc_type
= bp_loc_other
;
4408 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4414 static void free_bp_location (struct bp_location
*loc
)
4419 if (loc
->function_name
)
4420 xfree (loc
->function_name
);
4425 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4426 that has type BPTYPE and has no locations as yet. */
4427 /* This function is used in gdbtk sources and thus can not be made static. */
4429 static struct breakpoint
*
4430 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
4433 struct breakpoint
*b
, *b1
;
4435 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4436 memset (b
, 0, sizeof (*b
));
4439 b
->gdbarch
= gdbarch
;
4440 b
->language
= current_language
->la_language
;
4441 b
->input_radix
= input_radix
;
4443 b
->enable_state
= bp_enabled
;
4446 b
->ignore_count
= 0;
4448 b
->frame_id
= null_frame_id
;
4449 b
->forked_inferior_pid
= null_ptid
;
4450 b
->exec_pathname
= NULL
;
4451 b
->syscalls_to_be_caught
= NULL
;
4453 b
->condition_not_parsed
= 0;
4455 /* Add this breakpoint to the end of the chain
4456 so that a list of breakpoints will come out in order
4457 of increasing numbers. */
4459 b1
= breakpoint_chain
;
4461 breakpoint_chain
= b
;
4471 /* Initialize loc->function_name. */
4473 set_breakpoint_location_function (struct bp_location
*loc
)
4475 if (loc
->owner
->type
== bp_breakpoint
4476 || loc
->owner
->type
== bp_hardware_breakpoint
4477 || loc
->owner
->type
== bp_tracepoint
)
4479 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4481 if (loc
->function_name
)
4482 loc
->function_name
= xstrdup (loc
->function_name
);
4486 /* Attempt to determine architecture of location identified by SAL. */
4487 static struct gdbarch
*
4488 get_sal_arch (struct symtab_and_line sal
)
4491 return get_objfile_arch (sal
.section
->objfile
);
4493 return get_objfile_arch (sal
.symtab
->objfile
);
4498 /* set_raw_breakpoint is a low level routine for allocating and
4499 partially initializing a breakpoint of type BPTYPE. The newly
4500 created breakpoint's address, section, source file name, and line
4501 number are provided by SAL. The newly created and partially
4502 initialized breakpoint is added to the breakpoint chain and
4503 is also returned as the value of this function.
4505 It is expected that the caller will complete the initialization of
4506 the newly created breakpoint struct as well as output any status
4507 information regarding the creation of a new breakpoint. In
4508 particular, set_raw_breakpoint does NOT set the breakpoint
4509 number! Care should be taken to not allow an error to occur
4510 prior to completing the initialization of the breakpoint. If this
4511 should happen, a bogus breakpoint will be left on the chain. */
4514 set_raw_breakpoint (struct gdbarch
*gdbarch
,
4515 struct symtab_and_line sal
, enum bptype bptype
)
4517 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
4518 CORE_ADDR adjusted_address
;
4519 struct gdbarch
*loc_gdbarch
;
4521 loc_gdbarch
= get_sal_arch (sal
);
4523 loc_gdbarch
= b
->gdbarch
;
4525 /* Adjust the breakpoint's address prior to allocating a location.
4526 Once we call allocate_bp_location(), that mostly uninitialized
4527 location will be placed on the location chain. Adjustment of the
4528 breakpoint may cause target_read_memory() to be called and we do
4529 not want its scan of the location chain to find a breakpoint and
4530 location that's only been partially initialized. */
4531 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
4533 b
->loc
= allocate_bp_location (b
);
4534 b
->loc
->gdbarch
= loc_gdbarch
;
4535 b
->loc
->requested_address
= sal
.pc
;
4536 b
->loc
->address
= adjusted_address
;
4538 if (sal
.symtab
== NULL
)
4539 b
->source_file
= NULL
;
4541 b
->source_file
= xstrdup (sal
.symtab
->filename
);
4542 b
->loc
->section
= sal
.section
;
4543 b
->line_number
= sal
.line
;
4545 set_breakpoint_location_function (b
->loc
);
4547 breakpoints_changed ();
4553 /* Note that the breakpoint object B describes a permanent breakpoint
4554 instruction, hard-wired into the inferior's code. */
4556 make_breakpoint_permanent (struct breakpoint
*b
)
4558 struct bp_location
*bl
;
4559 b
->enable_state
= bp_permanent
;
4561 /* By definition, permanent breakpoints are already present in the code.
4562 Mark all locations as inserted. For now, make_breakpoint_permanent
4563 is called in just one place, so it's hard to say if it's reasonable
4564 to have permanent breakpoint with multiple locations or not,
4565 but it's easy to implmement. */
4566 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4570 /* Call this routine when stepping and nexting to enable a breakpoint
4571 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4572 set_longjmp_resume_breakpoint() to figure out where we are going. */
4575 set_longjmp_breakpoint (int thread
)
4577 struct breakpoint
*b
, *temp
;
4579 /* To avoid having to rescan all objfile symbols at every step,
4580 we maintain a list of continually-inserted but always disabled
4581 longjmp "master" breakpoints. Here, we simply create momentary
4582 clones of those and enable them for the requested thread. */
4583 ALL_BREAKPOINTS_SAFE (b
, temp
)
4584 if (b
->type
== bp_longjmp_master
)
4586 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
4587 clone
->type
= bp_longjmp
;
4588 clone
->thread
= thread
;
4592 /* Delete all longjmp breakpoints from THREAD. */
4594 delete_longjmp_breakpoint (int thread
)
4596 struct breakpoint
*b
, *temp
;
4598 ALL_BREAKPOINTS_SAFE (b
, temp
)
4599 if (b
->type
== bp_longjmp
)
4601 if (b
->thread
== thread
)
4602 delete_breakpoint (b
);
4607 enable_overlay_breakpoints (void)
4609 struct breakpoint
*b
;
4612 if (b
->type
== bp_overlay_event
)
4614 b
->enable_state
= bp_enabled
;
4615 update_global_location_list (1);
4616 overlay_events_enabled
= 1;
4621 disable_overlay_breakpoints (void)
4623 struct breakpoint
*b
;
4626 if (b
->type
== bp_overlay_event
)
4628 b
->enable_state
= bp_disabled
;
4629 update_global_location_list (0);
4630 overlay_events_enabled
= 0;
4635 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4637 struct breakpoint
*b
;
4639 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
4641 b
->enable_state
= bp_enabled
;
4642 /* addr_string has to be used or breakpoint_re_set will delete me. */
4644 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
4646 update_global_location_list_nothrow (1);
4652 remove_thread_event_breakpoints (void)
4654 struct breakpoint
*b
, *temp
;
4656 ALL_BREAKPOINTS_SAFE (b
, temp
)
4657 if (b
->type
== bp_thread_event
)
4658 delete_breakpoint (b
);
4661 struct captured_parse_breakpoint_args
4664 struct symtabs_and_lines
*sals_p
;
4665 char ***addr_string_p
;
4669 struct lang_and_radix
4675 /* Create a breakpoint for JIT code registration and unregistration. */
4678 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4680 struct breakpoint
*b
;
4682 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
4683 update_global_location_list_nothrow (1);
4688 remove_solib_event_breakpoints (void)
4690 struct breakpoint
*b
, *temp
;
4692 ALL_BREAKPOINTS_SAFE (b
, temp
)
4693 if (b
->type
== bp_shlib_event
)
4694 delete_breakpoint (b
);
4698 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4700 struct breakpoint
*b
;
4702 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
4703 update_global_location_list_nothrow (1);
4707 /* Disable any breakpoints that are on code in shared libraries. Only
4708 apply to enabled breakpoints, disabled ones can just stay disabled. */
4711 disable_breakpoints_in_shlibs (void)
4713 struct bp_location
*loc
;
4715 ALL_BP_LOCATIONS (loc
)
4717 struct breakpoint
*b
= loc
->owner
;
4718 /* We apply the check to all breakpoints, including disabled
4719 for those with loc->duplicate set. This is so that when breakpoint
4720 becomes enabled, or the duplicate is removed, gdb will try to insert
4721 all breakpoints. If we don't set shlib_disabled here, we'll try
4722 to insert those breakpoints and fail. */
4723 if (((b
->type
== bp_breakpoint
)
4724 || (b
->type
== bp_hardware_breakpoint
)
4725 || (b
->type
== bp_tracepoint
))
4726 && !loc
->shlib_disabled
4728 && PC_SOLIB (loc
->address
)
4730 && solib_name_from_address (loc
->address
)
4734 loc
->shlib_disabled
= 1;
4739 /* Disable any breakpoints that are in in an unloaded shared library. Only
4740 apply to enabled breakpoints, disabled ones can just stay disabled. */
4743 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4745 struct bp_location
*loc
;
4746 int disabled_shlib_breaks
= 0;
4748 /* SunOS a.out shared libraries are always mapped, so do not
4749 disable breakpoints; they will only be reported as unloaded
4750 through clear_solib when GDB discards its shared library
4751 list. See clear_solib for more information. */
4752 if (exec_bfd
!= NULL
4753 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4756 ALL_BP_LOCATIONS (loc
)
4758 struct breakpoint
*b
= loc
->owner
;
4759 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4760 || loc
->loc_type
== bp_loc_software_breakpoint
)
4761 && !loc
->shlib_disabled
4762 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4763 && solib_contains_address_p (solib
, loc
->address
))
4765 loc
->shlib_disabled
= 1;
4766 /* At this point, we cannot rely on remove_breakpoint
4767 succeeding so we must mark the breakpoint as not inserted
4768 to prevent future errors occurring in remove_breakpoints. */
4770 if (!disabled_shlib_breaks
)
4772 target_terminal_ours_for_output ();
4773 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4776 disabled_shlib_breaks
= 1;
4781 /* FORK & VFORK catchpoints. */
4783 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4786 insert_catch_fork (struct breakpoint
*b
)
4788 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4791 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4794 remove_catch_fork (struct breakpoint
*b
)
4796 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4799 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4803 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4805 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4808 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4810 static enum print_stop_action
4811 print_it_catch_fork (struct breakpoint
*b
)
4813 annotate_catchpoint (b
->number
);
4814 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4815 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4816 return PRINT_SRC_AND_LOC
;
4819 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4822 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4824 struct value_print_options opts
;
4826 get_user_print_options (&opts
);
4828 /* Field 4, the address, is omitted (which makes the columns
4829 not line up too nicely with the headers, but the effect
4830 is relatively readable). */
4831 if (opts
.addressprint
)
4832 ui_out_field_skip (uiout
, "addr");
4834 ui_out_text (uiout
, "fork");
4835 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4837 ui_out_text (uiout
, ", process ");
4838 ui_out_field_int (uiout
, "what",
4839 ptid_get_pid (b
->forked_inferior_pid
));
4840 ui_out_spaces (uiout
, 1);
4844 /* Implement the "print_mention" breakpoint_ops method for fork
4848 print_mention_catch_fork (struct breakpoint
*b
)
4850 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4853 /* The breakpoint_ops structure to be used in fork catchpoints. */
4855 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4859 breakpoint_hit_catch_fork
,
4860 print_it_catch_fork
,
4861 print_one_catch_fork
,
4862 print_mention_catch_fork
4865 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4868 insert_catch_vfork (struct breakpoint
*b
)
4870 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4873 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4876 remove_catch_vfork (struct breakpoint
*b
)
4878 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4881 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4885 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4887 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4890 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4892 static enum print_stop_action
4893 print_it_catch_vfork (struct breakpoint
*b
)
4895 annotate_catchpoint (b
->number
);
4896 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4897 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4898 return PRINT_SRC_AND_LOC
;
4901 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4904 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4906 struct value_print_options opts
;
4908 get_user_print_options (&opts
);
4909 /* Field 4, the address, is omitted (which makes the columns
4910 not line up too nicely with the headers, but the effect
4911 is relatively readable). */
4912 if (opts
.addressprint
)
4913 ui_out_field_skip (uiout
, "addr");
4915 ui_out_text (uiout
, "vfork");
4916 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4918 ui_out_text (uiout
, ", process ");
4919 ui_out_field_int (uiout
, "what",
4920 ptid_get_pid (b
->forked_inferior_pid
));
4921 ui_out_spaces (uiout
, 1);
4925 /* Implement the "print_mention" breakpoint_ops method for vfork
4929 print_mention_catch_vfork (struct breakpoint
*b
)
4931 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4934 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4936 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4940 breakpoint_hit_catch_vfork
,
4941 print_it_catch_vfork
,
4942 print_one_catch_vfork
,
4943 print_mention_catch_vfork
4946 /* Implement the "insert" breakpoint_ops method for syscall
4950 insert_catch_syscall (struct breakpoint
*b
)
4952 struct inferior
*inf
= current_inferior ();
4954 ++inf
->total_syscalls_count
;
4955 if (!b
->syscalls_to_be_caught
)
4956 ++inf
->any_syscall_count
;
4961 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
4965 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
4967 int old_size
= VEC_length (int, inf
->syscalls_counts
);
4968 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
4970 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
4971 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
4973 memset ((void *) vec_addr
, 0,
4974 (iter
+ 1 - old_size
) * sizeof (int));
4976 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
4977 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
4981 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
4982 inf
->total_syscalls_count
!= 0,
4983 inf
->any_syscall_count
,
4984 VEC_length (int, inf
->syscalls_counts
),
4985 VEC_address (int, inf
->syscalls_counts
));
4988 /* Implement the "remove" breakpoint_ops method for syscall
4992 remove_catch_syscall (struct breakpoint
*b
)
4994 struct inferior
*inf
= current_inferior ();
4996 --inf
->total_syscalls_count
;
4997 if (!b
->syscalls_to_be_caught
)
4998 --inf
->any_syscall_count
;
5003 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5007 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5008 /* Shouldn't happen. */
5010 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5011 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5015 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5016 inf
->total_syscalls_count
!= 0,
5017 inf
->any_syscall_count
,
5018 VEC_length (int, inf
->syscalls_counts
),
5019 VEC_address (int, inf
->syscalls_counts
));
5022 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5026 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5028 /* We must check if we are catching specific syscalls in this breakpoint.
5029 If we are, then we must guarantee that the called syscall is the same
5030 syscall we are catching. */
5031 int syscall_number
= 0;
5033 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5036 /* Now, checking if the syscall is the same. */
5037 if (b
->syscalls_to_be_caught
)
5041 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5043 if (syscall_number
== iter
)
5053 /* Implement the "print_it" breakpoint_ops method for syscall
5056 static enum print_stop_action
5057 print_it_catch_syscall (struct breakpoint
*b
)
5059 /* These are needed because we want to know in which state a
5060 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
5061 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
5062 must print "called syscall" or "returned from syscall". */
5064 struct target_waitstatus last
;
5066 struct cleanup
*old_chain
;
5069 get_last_target_status (&ptid
, &last
);
5071 get_syscall_by_number (last
.value
.syscall_number
, &s
);
5073 annotate_catchpoint (b
->number
);
5076 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
5078 syscall_id
= xstrprintf ("'%s'", s
.name
);
5080 old_chain
= make_cleanup (xfree
, syscall_id
);
5082 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
5083 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
5084 b
->number
, syscall_id
);
5085 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
5086 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
5087 b
->number
, syscall_id
);
5089 do_cleanups (old_chain
);
5091 return PRINT_SRC_AND_LOC
;
5094 /* Implement the "print_one" breakpoint_ops method for syscall
5098 print_one_catch_syscall (struct breakpoint
*b
,
5099 struct bp_location
**last_loc
)
5101 struct value_print_options opts
;
5103 get_user_print_options (&opts
);
5104 /* Field 4, the address, is omitted (which makes the columns
5105 not line up too nicely with the headers, but the effect
5106 is relatively readable). */
5107 if (opts
.addressprint
)
5108 ui_out_field_skip (uiout
, "addr");
5111 if (b
->syscalls_to_be_caught
5112 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5113 ui_out_text (uiout
, "syscalls \"");
5115 ui_out_text (uiout
, "syscall \"");
5117 if (b
->syscalls_to_be_caught
)
5120 char *text
= xstrprintf ("%s", "");
5122 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5127 get_syscall_by_number (iter
, &s
);
5130 text
= xstrprintf ("%s%s, ", text
, s
.name
);
5132 text
= xstrprintf ("%s%d, ", text
, iter
);
5134 /* We have to xfree the last 'text' (now stored at 'x')
5135 because xstrprintf dinamically allocates new space for it
5139 /* Remove the last comma. */
5140 text
[strlen (text
) - 2] = '\0';
5141 ui_out_field_string (uiout
, "what", text
);
5144 ui_out_field_string (uiout
, "what", "<any syscall>");
5145 ui_out_text (uiout
, "\" ");
5148 /* Implement the "print_mention" breakpoint_ops method for syscall
5152 print_mention_catch_syscall (struct breakpoint
*b
)
5154 if (b
->syscalls_to_be_caught
)
5158 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5159 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
5161 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
5164 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5168 get_syscall_by_number (iter
, &s
);
5171 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
5173 printf_filtered (" %d", s
.number
);
5175 printf_filtered (")");
5178 printf_filtered (_("Catchpoint %d (any syscall)"),
5182 /* The breakpoint_ops structure to be used in syscall catchpoints. */
5184 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
5186 insert_catch_syscall
,
5187 remove_catch_syscall
,
5188 breakpoint_hit_catch_syscall
,
5189 print_it_catch_syscall
,
5190 print_one_catch_syscall
,
5191 print_mention_catch_syscall
5194 /* Returns non-zero if 'b' is a syscall catchpoint. */
5197 syscall_catchpoint_p (struct breakpoint
*b
)
5199 return (b
->ops
== &catch_syscall_breakpoint_ops
);
5202 /* Create a new breakpoint of the bp_catchpoint kind and return it,
5203 but does NOT mention it nor update the global location list.
5204 This is useful if you need to fill more fields in the
5205 struct breakpoint before calling mention.
5207 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5208 If COND_STRING is not NULL, then store it in the breakpoint.
5209 OPS, if not NULL, is the breakpoint_ops structure associated
5210 to the catchpoint. */
5212 static struct breakpoint
*
5213 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
5215 struct breakpoint_ops
*ops
)
5217 struct symtab_and_line sal
;
5218 struct breakpoint
*b
;
5222 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
5223 set_breakpoint_count (breakpoint_count
+ 1);
5224 b
->number
= breakpoint_count
;
5226 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
5228 b
->addr_string
= NULL
;
5229 b
->enable_state
= bp_enabled
;
5230 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5236 /* Create a new breakpoint of the bp_catchpoint kind and return it.
5238 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5239 If COND_STRING is not NULL, then store it in the breakpoint.
5240 OPS, if not NULL, is the breakpoint_ops structure associated
5241 to the catchpoint. */
5243 static struct breakpoint
*
5244 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
5245 char *cond_string
, struct breakpoint_ops
*ops
)
5247 struct breakpoint
*b
=
5248 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
5251 update_global_location_list (1);
5257 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
5258 int tempflag
, char *cond_string
,
5259 struct breakpoint_ops
*ops
)
5261 struct breakpoint
*b
5262 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
5264 /* FIXME: We should put this information in a breakpoint private data
5266 b
->forked_inferior_pid
= null_ptid
;
5269 /* Exec catchpoints. */
5272 insert_catch_exec (struct breakpoint
*b
)
5274 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
5278 remove_catch_exec (struct breakpoint
*b
)
5280 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
5284 breakpoint_hit_catch_exec (struct breakpoint
*b
)
5286 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
5289 static enum print_stop_action
5290 print_it_catch_exec (struct breakpoint
*b
)
5292 annotate_catchpoint (b
->number
);
5293 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
5295 return PRINT_SRC_AND_LOC
;
5299 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
5301 struct value_print_options opts
;
5303 get_user_print_options (&opts
);
5305 /* Field 4, the address, is omitted (which makes the columns
5306 not line up too nicely with the headers, but the effect
5307 is relatively readable). */
5308 if (opts
.addressprint
)
5309 ui_out_field_skip (uiout
, "addr");
5311 ui_out_text (uiout
, "exec");
5312 if (b
->exec_pathname
!= NULL
)
5314 ui_out_text (uiout
, ", program \"");
5315 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
5316 ui_out_text (uiout
, "\" ");
5321 print_mention_catch_exec (struct breakpoint
*b
)
5323 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
5326 static struct breakpoint_ops catch_exec_breakpoint_ops
=
5330 breakpoint_hit_catch_exec
,
5331 print_it_catch_exec
,
5332 print_one_catch_exec
,
5333 print_mention_catch_exec
5337 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
5338 struct breakpoint_ops
*ops
)
5340 struct gdbarch
*gdbarch
= get_current_arch ();
5341 struct breakpoint
*b
=
5342 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
5344 b
->syscalls_to_be_caught
= filter
;
5346 /* Now, we have to mention the breakpoint and update the global
5349 update_global_location_list (1);
5353 hw_breakpoint_used_count (void)
5355 struct breakpoint
*b
;
5360 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
5368 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
5370 struct breakpoint
*b
;
5373 *other_type_used
= 0;
5376 if (breakpoint_enabled (b
))
5378 if (b
->type
== type
)
5380 else if ((b
->type
== bp_hardware_watchpoint
5381 || b
->type
== bp_read_watchpoint
5382 || b
->type
== bp_access_watchpoint
))
5383 *other_type_used
= 1;
5390 disable_watchpoints_before_interactive_call_start (void)
5392 struct breakpoint
*b
;
5396 if (((b
->type
== bp_watchpoint
)
5397 || (b
->type
== bp_hardware_watchpoint
)
5398 || (b
->type
== bp_read_watchpoint
)
5399 || (b
->type
== bp_access_watchpoint
))
5400 && breakpoint_enabled (b
))
5402 b
->enable_state
= bp_call_disabled
;
5403 update_global_location_list (0);
5409 enable_watchpoints_after_interactive_call_stop (void)
5411 struct breakpoint
*b
;
5415 if (((b
->type
== bp_watchpoint
)
5416 || (b
->type
== bp_hardware_watchpoint
)
5417 || (b
->type
== bp_read_watchpoint
)
5418 || (b
->type
== bp_access_watchpoint
))
5419 && (b
->enable_state
== bp_call_disabled
))
5421 b
->enable_state
= bp_enabled
;
5422 update_global_location_list (1);
5428 disable_breakpoints_before_startup (void)
5430 struct breakpoint
*b
;
5435 if ((b
->type
== bp_breakpoint
5436 || b
->type
== bp_hardware_breakpoint
)
5437 && breakpoint_enabled (b
))
5439 b
->enable_state
= bp_startup_disabled
;
5445 update_global_location_list (0);
5447 executing_startup
= 1;
5451 enable_breakpoints_after_startup (void)
5453 struct breakpoint
*b
;
5456 executing_startup
= 0;
5460 if ((b
->type
== bp_breakpoint
5461 || b
->type
== bp_hardware_breakpoint
)
5462 && b
->enable_state
== bp_startup_disabled
)
5464 b
->enable_state
= bp_enabled
;
5470 breakpoint_re_set ();
5474 /* Set a breakpoint that will evaporate an end of command
5475 at address specified by SAL.
5476 Restrict it to frame FRAME if FRAME is nonzero. */
5479 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
5480 struct frame_id frame_id
, enum bptype type
)
5482 struct breakpoint
*b
;
5484 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5486 gdb_assert (!frame_id_inlined_p (frame_id
));
5488 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5489 b
->enable_state
= bp_enabled
;
5490 b
->disposition
= disp_donttouch
;
5491 b
->frame_id
= frame_id
;
5493 /* If we're debugging a multi-threaded program, then we
5494 want momentary breakpoints to be active in only a
5495 single thread of control. */
5496 if (in_thread_list (inferior_ptid
))
5497 b
->thread
= pid_to_thread_id (inferior_ptid
);
5499 update_global_location_list_nothrow (1);
5504 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5508 clone_momentary_breakpoint (struct breakpoint
*orig
)
5510 struct breakpoint
*copy
;
5512 /* If there's nothing to clone, then return nothing. */
5516 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
5517 copy
->loc
= allocate_bp_location (copy
);
5518 set_breakpoint_location_function (copy
->loc
);
5520 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
5521 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
5522 copy
->loc
->address
= orig
->loc
->address
;
5523 copy
->loc
->section
= orig
->loc
->section
;
5525 if (orig
->source_file
== NULL
)
5526 copy
->source_file
= NULL
;
5528 copy
->source_file
= xstrdup (orig
->source_file
);
5530 copy
->line_number
= orig
->line_number
;
5531 copy
->frame_id
= orig
->frame_id
;
5532 copy
->thread
= orig
->thread
;
5534 copy
->enable_state
= bp_enabled
;
5535 copy
->disposition
= disp_donttouch
;
5536 copy
->number
= internal_breakpoint_number
--;
5538 update_global_location_list_nothrow (0);
5543 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
5546 struct symtab_and_line sal
;
5548 sal
= find_pc_line (pc
, 0);
5550 sal
.section
= find_pc_overlay (pc
);
5551 sal
.explicit_pc
= 1;
5553 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
5557 /* Tell the user we have just set a breakpoint B. */
5560 mention (struct breakpoint
*b
)
5563 struct cleanup
*ui_out_chain
;
5564 struct value_print_options opts
;
5566 get_user_print_options (&opts
);
5568 /* FIXME: This is misplaced; mention() is called by things (like
5569 hitting a watchpoint) other than breakpoint creation. It should
5570 be possible to clean this up and at the same time replace the
5571 random calls to breakpoint_changed with this hook. */
5572 observer_notify_breakpoint_created (b
->number
);
5574 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5575 b
->ops
->print_mention (b
);
5580 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5583 ui_out_text (uiout
, "Watchpoint ");
5584 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5585 ui_out_field_int (uiout
, "number", b
->number
);
5586 ui_out_text (uiout
, ": ");
5587 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5588 do_cleanups (ui_out_chain
);
5590 case bp_hardware_watchpoint
:
5591 ui_out_text (uiout
, "Hardware watchpoint ");
5592 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5593 ui_out_field_int (uiout
, "number", b
->number
);
5594 ui_out_text (uiout
, ": ");
5595 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5596 do_cleanups (ui_out_chain
);
5598 case bp_read_watchpoint
:
5599 ui_out_text (uiout
, "Hardware read watchpoint ");
5600 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5601 ui_out_field_int (uiout
, "number", b
->number
);
5602 ui_out_text (uiout
, ": ");
5603 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5604 do_cleanups (ui_out_chain
);
5606 case bp_access_watchpoint
:
5607 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5608 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5609 ui_out_field_int (uiout
, "number", b
->number
);
5610 ui_out_text (uiout
, ": ");
5611 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5612 do_cleanups (ui_out_chain
);
5615 if (ui_out_is_mi_like_p (uiout
))
5620 if (b
->disposition
== disp_del
)
5621 printf_filtered (_("Temporary breakpoint"));
5623 printf_filtered (_("Breakpoint"));
5624 printf_filtered (_(" %d"), b
->number
);
5627 case bp_hardware_breakpoint
:
5628 if (ui_out_is_mi_like_p (uiout
))
5633 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5637 if (ui_out_is_mi_like_p (uiout
))
5642 printf_filtered (_("Tracepoint"));
5643 printf_filtered (_(" %d"), b
->number
);
5650 case bp_longjmp_resume
:
5651 case bp_step_resume
:
5653 case bp_watchpoint_scope
:
5654 case bp_shlib_event
:
5655 case bp_thread_event
:
5656 case bp_overlay_event
:
5658 case bp_longjmp_master
:
5664 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5668 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5672 if (opts
.addressprint
|| b
->source_file
== NULL
)
5674 printf_filtered (" at ");
5675 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
5679 printf_filtered (": file %s, line %d.",
5680 b
->source_file
, b
->line_number
);
5684 struct bp_location
*loc
= b
->loc
;
5686 for (; loc
; loc
= loc
->next
)
5688 printf_filtered (" (%d locations)", n
);
5693 if (ui_out_is_mi_like_p (uiout
))
5695 printf_filtered ("\n");
5699 static struct bp_location
*
5700 add_location_to_breakpoint (struct breakpoint
*b
,
5701 const struct symtab_and_line
*sal
)
5703 struct bp_location
*loc
, **tmp
;
5705 loc
= allocate_bp_location (b
);
5706 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5709 loc
->gdbarch
= get_sal_arch (*sal
);
5711 loc
->gdbarch
= b
->gdbarch
;
5712 loc
->requested_address
= sal
->pc
;
5713 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5714 loc
->requested_address
, b
->type
);
5715 loc
->section
= sal
->section
;
5717 set_breakpoint_location_function (loc
);
5722 /* Return 1 if LOC is pointing to a permanent breakpoint,
5723 return 0 otherwise. */
5726 bp_loc_is_permanent (struct bp_location
*loc
)
5730 const gdb_byte
*brk
;
5731 gdb_byte
*target_mem
;
5732 struct cleanup
*cleanup
;
5735 gdb_assert (loc
!= NULL
);
5737 addr
= loc
->address
;
5738 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
5740 /* Software breakpoints unsupported? */
5744 target_mem
= alloca (len
);
5746 /* Enable the automatic memory restoration from breakpoints while
5747 we read the memory. Otherwise we could say about our temporary
5748 breakpoints they are permanent. */
5749 cleanup
= make_show_memory_breakpoints_cleanup (0);
5751 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5752 && memcmp (target_mem
, brk
, len
) == 0)
5755 do_cleanups (cleanup
);
5762 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5763 as textual description of the location, and COND_STRING
5764 as condition expression. */
5767 create_breakpoint (struct gdbarch
*gdbarch
,
5768 struct symtabs_and_lines sals
, char *addr_string
,
5770 enum bptype type
, enum bpdisp disposition
,
5771 int thread
, int task
, int ignore_count
,
5772 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5774 struct breakpoint
*b
= NULL
;
5777 if (type
== bp_hardware_breakpoint
)
5779 int i
= hw_breakpoint_used_count ();
5780 int target_resources_ok
=
5781 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
5783 if (target_resources_ok
== 0)
5784 error (_("No hardware breakpoint support in the target."));
5785 else if (target_resources_ok
< 0)
5786 error (_("Hardware breakpoints used exceeds limit."));
5789 for (i
= 0; i
< sals
.nelts
; ++i
)
5791 struct symtab_and_line sal
= sals
.sals
[i
];
5792 struct bp_location
*loc
;
5796 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
5798 loc_gdbarch
= gdbarch
;
5800 describe_other_breakpoints (loc_gdbarch
,
5801 sal
.pc
, sal
.section
, thread
);
5806 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5807 set_breakpoint_count (breakpoint_count
+ 1);
5808 b
->number
= breakpoint_count
;
5812 b
->cond_string
= cond_string
;
5813 b
->ignore_count
= ignore_count
;
5814 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5815 b
->disposition
= disposition
;
5817 if (enabled
&& executing_startup
5818 && (b
->type
== bp_breakpoint
5819 || b
->type
== bp_hardware_breakpoint
))
5820 b
->enable_state
= bp_startup_disabled
;
5826 loc
= add_location_to_breakpoint (b
, &sal
);
5829 if (bp_loc_is_permanent (loc
))
5830 make_breakpoint_permanent (b
);
5834 char *arg
= b
->cond_string
;
5835 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5837 error (_("Garbage %s follows condition"), arg
);
5842 b
->addr_string
= addr_string
;
5844 /* addr_string has to be used or breakpoint_re_set will delete
5847 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5853 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5854 elements to fill the void space. */
5856 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5858 int i
= index_to_remove
+1;
5859 int last_index
= sal
->nelts
-1;
5861 for (;i
<= last_index
; ++i
)
5862 sal
->sals
[i
-1] = sal
->sals
[i
];
5867 /* If appropriate, obtains all sals that correspond
5868 to the same file and line as SAL. This is done
5869 only if SAL does not have explicit PC and has
5870 line and file information. If we got just a single
5871 expanded sal, return the original.
5873 Otherwise, if SAL.explicit_line is not set, filter out
5874 all sals for which the name of enclosing function
5875 is different from SAL. This makes sure that if we have
5876 breakpoint originally set in template instantiation, say
5877 foo<int>(), we won't expand SAL to locations at the same
5878 line in all existing instantiations of 'foo'.
5881 static struct symtabs_and_lines
5882 expand_line_sal_maybe (struct symtab_and_line sal
)
5884 struct symtabs_and_lines expanded
;
5885 CORE_ADDR original_pc
= sal
.pc
;
5886 char *original_function
= NULL
;
5890 /* If we have explicit pc, don't expand.
5891 If we have no line number, we can't expand. */
5892 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5895 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5896 expanded
.sals
[0] = sal
;
5901 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5903 expanded
= expand_line_sal (sal
);
5904 if (expanded
.nelts
== 1)
5906 /* We had one sal, we got one sal. Without futher
5907 processing, just return the original sal. */
5908 xfree (expanded
.sals
);
5910 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5911 sal
.pc
= original_pc
;
5912 expanded
.sals
[0] = sal
;
5916 if (!sal
.explicit_line
)
5918 CORE_ADDR func_addr
, func_end
;
5919 for (i
= 0; i
< expanded
.nelts
; ++i
)
5921 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5922 char *this_function
;
5923 if (find_pc_partial_function (pc
, &this_function
,
5924 &func_addr
, &func_end
))
5927 && strcmp (this_function
, original_function
) != 0)
5929 remove_sal (&expanded
, i
);
5932 else if (func_addr
== pc
)
5934 /* We're at beginning of a function, and should
5936 struct symbol
*sym
= find_pc_function (pc
);
5938 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5941 /* Since find_pc_partial_function returned true,
5942 we should really always find the section here. */
5943 struct obj_section
*section
= find_pc_section (pc
);
5946 struct gdbarch
*gdbarch
5947 = get_objfile_arch (section
->objfile
);
5949 = gdbarch_skip_prologue (gdbarch
, pc
);
5958 for (i
= 0; i
< expanded
.nelts
; ++i
)
5960 /* If this SAL corresponds to a breakpoint inserted using a
5961 line number, then skip the function prologue if necessary. */
5962 skip_prologue_sal (&expanded
.sals
[i
]);
5967 if (expanded
.nelts
<= 1)
5969 /* This is un ugly workaround. If we get zero
5970 expanded sals then something is really wrong.
5971 Fix that by returnign the original sal. */
5972 xfree (expanded
.sals
);
5974 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5975 sal
.pc
= original_pc
;
5976 expanded
.sals
[0] = sal
;
5983 for (i
= 0; i
< expanded
.nelts
; ++i
)
5984 if (expanded
.sals
[i
].pc
== original_pc
)
5995 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5996 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5997 value. COND_STRING, if not NULL, specified the condition to be
5998 used for all breakpoints. Essentially the only case where
5999 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6000 function. In that case, it's still not possible to specify
6001 separate conditions for different overloaded functions, so
6002 we take just a single condition string.
6004 NOTE: If the function succeeds, the caller is expected to cleanup
6005 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6006 array contents). If the function fails (error() is called), the
6007 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6008 COND and SALS arrays and each of those arrays contents. */
6011 create_breakpoints (struct gdbarch
*gdbarch
,
6012 struct symtabs_and_lines sals
, char **addr_string
,
6014 enum bptype type
, enum bpdisp disposition
,
6015 int thread
, int task
, int ignore_count
,
6016 struct breakpoint_ops
*ops
, int from_tty
,
6020 for (i
= 0; i
< sals
.nelts
; ++i
)
6022 struct symtabs_and_lines expanded
=
6023 expand_line_sal_maybe (sals
.sals
[i
]);
6025 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
6026 cond_string
, type
, disposition
,
6027 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6031 /* Parse ARG which is assumed to be a SAL specification possibly
6032 followed by conditionals. On return, SALS contains an array of SAL
6033 addresses found. ADDR_STRING contains a vector of (canonical)
6034 address strings. ARG points to the end of the SAL. */
6037 parse_breakpoint_sals (char **address
,
6038 struct symtabs_and_lines
*sals
,
6039 char ***addr_string
,
6042 char *addr_start
= *address
;
6043 *addr_string
= NULL
;
6044 /* If no arg given, or if first arg is 'if ', use the default
6046 if ((*address
) == NULL
6047 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
6049 if (default_breakpoint_valid
)
6051 struct symtab_and_line sal
;
6052 init_sal (&sal
); /* initialize to zeroes */
6053 sals
->sals
= (struct symtab_and_line
*)
6054 xmalloc (sizeof (struct symtab_and_line
));
6055 sal
.pc
= default_breakpoint_address
;
6056 sal
.line
= default_breakpoint_line
;
6057 sal
.symtab
= default_breakpoint_symtab
;
6058 sal
.section
= find_pc_overlay (sal
.pc
);
6060 /* "break" without arguments is equivalent to "break *PC" where PC is
6061 the default_breakpoint_address. So make sure to set
6062 sal.explicit_pc to prevent GDB from trying to expand the list of
6063 sals to include all other instances with the same symtab and line.
6065 sal
.explicit_pc
= 1;
6067 sals
->sals
[0] = sal
;
6071 error (_("No default breakpoint address now."));
6075 /* Force almost all breakpoints to be in terms of the
6076 current_source_symtab (which is decode_line_1's default). This
6077 should produce the results we want almost all of the time while
6078 leaving default_breakpoint_* alone.
6079 ObjC: However, don't match an Objective-C method name which
6080 may have a '+' or '-' succeeded by a '[' */
6082 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
6084 if (default_breakpoint_valid
6086 || ((strchr ("+-", (*address
)[0]) != NULL
)
6087 && ((*address
)[1] != '['))))
6088 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
6089 default_breakpoint_line
, addr_string
,
6092 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
6093 addr_string
, not_found_ptr
);
6095 /* For any SAL that didn't have a canonical string, fill one in. */
6096 if (sals
->nelts
> 0 && *addr_string
== NULL
)
6097 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
6098 if (addr_start
!= (*address
))
6101 for (i
= 0; i
< sals
->nelts
; i
++)
6103 /* Add the string if not present. */
6104 if ((*addr_string
)[i
] == NULL
)
6105 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
6111 /* Convert each SAL into a real PC. Verify that the PC can be
6112 inserted as a breakpoint. If it can't throw an error. */
6115 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
6119 for (i
= 0; i
< sals
->nelts
; i
++)
6120 resolve_sal_pc (&sals
->sals
[i
]);
6124 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
6126 struct captured_parse_breakpoint_args
*args
= data
;
6128 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
6129 args
->not_found_ptr
);
6132 /* Given TOK, a string specification of condition and thread, as
6133 accepted by the 'break' command, extract the condition
6134 string and thread number and set *COND_STRING and *THREAD.
6135 PC identifies the context at which the condition should be parsed.
6136 If no condition is found, *COND_STRING is set to NULL.
6137 If no thread is found, *THREAD is set to -1. */
6139 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
6140 char **cond_string
, int *thread
, int *task
)
6142 *cond_string
= NULL
;
6148 char *cond_start
= NULL
;
6149 char *cond_end
= NULL
;
6150 while (*tok
== ' ' || *tok
== '\t')
6155 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6158 toklen
= end_tok
- tok
;
6160 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6162 struct expression
*expr
;
6164 tok
= cond_start
= end_tok
+ 1;
6165 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
6168 *cond_string
= savestring (cond_start
,
6169 cond_end
- cond_start
);
6171 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6177 *thread
= strtol (tok
, &tok
, 0);
6179 error (_("Junk after thread keyword."));
6180 if (!valid_thread_id (*thread
))
6181 error (_("Unknown thread %d."), *thread
);
6183 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
6189 *task
= strtol (tok
, &tok
, 0);
6191 error (_("Junk after task keyword."));
6192 if (!valid_task_id (*task
))
6193 error (_("Unknown task %d\n"), *task
);
6196 error (_("Junk at end of arguments."));
6200 /* Set a breakpoint. This function is shared between
6201 CLI and MI functions for setting a breakpoint.
6202 This function has two major modes of operations,
6203 selected by the PARSE_CONDITION_AND_THREAD parameter.
6204 If non-zero, the function will parse arg, extracting
6205 breakpoint location, address and thread. Otherwise,
6206 ARG is just the location of breakpoint, with condition
6207 and thread specified by the COND_STRING and THREAD
6211 break_command_really (struct gdbarch
*gdbarch
,
6212 char *arg
, char *cond_string
, int thread
,
6213 int parse_condition_and_thread
,
6214 int tempflag
, int hardwareflag
, int traceflag
,
6216 enum auto_boolean pending_break_support
,
6217 struct breakpoint_ops
*ops
,
6221 struct gdb_exception e
;
6222 struct symtabs_and_lines sals
;
6223 struct symtab_and_line pending_sal
;
6226 char *addr_start
= arg
;
6228 struct cleanup
*old_chain
;
6229 struct cleanup
*bkpt_chain
= NULL
;
6230 struct captured_parse_breakpoint_args parse_args
;
6234 enum bptype type_wanted
;
6241 parse_args
.arg_p
= &arg
;
6242 parse_args
.sals_p
= &sals
;
6243 parse_args
.addr_string_p
= &addr_string
;
6244 parse_args
.not_found_ptr
= ¬_found
;
6246 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
6247 &parse_args
, RETURN_MASK_ALL
);
6249 /* If caller is interested in rc value from parse, set value. */
6253 throw_exception (e
);
6257 case NOT_FOUND_ERROR
:
6259 /* If pending breakpoint support is turned off, throw
6262 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
6263 throw_exception (e
);
6265 exception_print (gdb_stderr
, e
);
6267 /* If pending breakpoint support is auto query and the user
6268 selects no, then simply return the error code. */
6269 if (pending_break_support
== AUTO_BOOLEAN_AUTO
6270 && !nquery ("Make breakpoint pending on future shared library load? "))
6273 /* At this point, either the user was queried about setting
6274 a pending breakpoint and selected yes, or pending
6275 breakpoint behavior is on and thus a pending breakpoint
6276 is defaulted on behalf of the user. */
6277 copy_arg
= xstrdup (addr_start
);
6278 addr_string
= ©_arg
;
6280 sals
.sals
= &pending_sal
;
6285 throw_exception (e
);
6292 /* Create a chain of things that always need to be cleaned up. */
6293 old_chain
= make_cleanup (null_cleanup
, 0);
6297 /* Make sure that all storage allocated to SALS gets freed. */
6298 make_cleanup (xfree
, sals
.sals
);
6300 /* Cleanup the addr_string array but not its contents. */
6301 make_cleanup (xfree
, addr_string
);
6304 /* ----------------------------- SNIP -----------------------------
6305 Anything added to the cleanup chain beyond this point is assumed
6306 to be part of a breakpoint. If the breakpoint create succeeds
6307 then the memory is not reclaimed. */
6308 bkpt_chain
= make_cleanup (null_cleanup
, 0);
6310 /* Mark the contents of the addr_string for cleanup. These go on
6311 the bkpt_chain and only occur if the breakpoint create fails. */
6312 for (i
= 0; i
< sals
.nelts
; i
++)
6314 if (addr_string
[i
] != NULL
)
6315 make_cleanup (xfree
, addr_string
[i
]);
6318 /* Resolve all line numbers to PC's and verify that the addresses
6319 are ok for the target. */
6321 breakpoint_sals_to_pc (&sals
, addr_start
);
6323 type_wanted
= (traceflag
6325 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
6327 /* Verify that condition can be parsed, before setting any
6328 breakpoints. Allocate a separate condition expression for each
6332 if (parse_condition_and_thread
)
6334 /* Here we only parse 'arg' to separate condition
6335 from thread number, so parsing in context of first
6336 sal is OK. When setting the breakpoint we'll
6337 re-parse it in context of each sal. */
6340 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
6343 make_cleanup (xfree
, cond_string
);
6347 /* Create a private copy of condition string. */
6350 cond_string
= xstrdup (cond_string
);
6351 make_cleanup (xfree
, cond_string
);
6354 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
6355 tempflag
? disp_del
: disp_donttouch
,
6356 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6360 struct symtab_and_line sal
= {0};
6361 struct breakpoint
*b
;
6363 make_cleanup (xfree
, copy_arg
);
6365 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
6366 set_breakpoint_count (breakpoint_count
+ 1);
6367 b
->number
= breakpoint_count
;
6369 b
->addr_string
= addr_string
[0];
6370 b
->cond_string
= NULL
;
6371 b
->ignore_count
= ignore_count
;
6372 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6373 b
->condition_not_parsed
= 1;
6375 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6377 if (enabled
&& executing_startup
6378 && (b
->type
== bp_breakpoint
6379 || b
->type
== bp_hardware_breakpoint
))
6380 b
->enable_state
= bp_startup_disabled
;
6386 warning (_("Multiple breakpoints were set.\n"
6387 "Use the \"delete\" command to delete unwanted breakpoints."));
6388 /* That's it. Discard the cleanups for data inserted into the
6390 discard_cleanups (bkpt_chain
);
6391 /* But cleanup everything else. */
6392 do_cleanups (old_chain
);
6394 /* error call may happen here - have BKPT_CHAIN already discarded. */
6395 update_global_location_list (1);
6398 /* Set a breakpoint.
6399 ARG is a string describing breakpoint address,
6400 condition, and thread.
6401 FLAG specifies if a breakpoint is hardware on,
6402 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6406 break_command_1 (char *arg
, int flag
, int from_tty
)
6408 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
6409 int tempflag
= flag
& BP_TEMPFLAG
;
6411 break_command_really (get_current_arch (),
6413 NULL
, 0, 1 /* parse arg */,
6414 tempflag
, hardwareflag
, 0 /* traceflag */,
6415 0 /* Ignore count */,
6416 pending_break_support
,
6417 NULL
/* breakpoint_ops */,
6424 set_breakpoint (struct gdbarch
*gdbarch
,
6425 char *address
, char *condition
,
6426 int hardwareflag
, int tempflag
,
6427 int thread
, int ignore_count
,
6428 int pending
, int enabled
)
6430 break_command_really (gdbarch
,
6431 address
, condition
, thread
,
6432 0 /* condition and thread are valid. */,
6433 tempflag
, hardwareflag
, 0 /* traceflag */,
6436 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
6440 /* Adjust SAL to the first instruction past the function prologue.
6441 The end of the prologue is determined using the line table from
6442 the debugging information. explicit_pc and explicit_line are
6445 If SAL is already past the prologue, then do nothing. */
6448 skip_prologue_sal (struct symtab_and_line
*sal
)
6450 struct symbol
*sym
= find_pc_function (sal
->pc
);
6451 struct symtab_and_line start_sal
;
6456 start_sal
= find_function_start_sal (sym
, 1);
6457 if (sal
->pc
< start_sal
.pc
)
6459 start_sal
.explicit_line
= sal
->explicit_line
;
6460 start_sal
.explicit_pc
= sal
->explicit_pc
;
6465 /* Helper function for break_command_1 and disassemble_command. */
6468 resolve_sal_pc (struct symtab_and_line
*sal
)
6472 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
6474 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
6475 error (_("No line %d in file \"%s\"."),
6476 sal
->line
, sal
->symtab
->filename
);
6479 /* If this SAL corresponds to a breakpoint inserted using
6480 a line number, then skip the function prologue if necessary. */
6481 if (sal
->explicit_line
)
6483 /* Preserve the original line number. */
6484 int saved_line
= sal
->line
;
6485 skip_prologue_sal (sal
);
6486 sal
->line
= saved_line
;
6490 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
6492 struct blockvector
*bv
;
6496 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
6499 sym
= block_linkage_function (b
);
6502 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
6503 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
6507 /* It really is worthwhile to have the section, so we'll just
6508 have to look harder. This case can be executed if we have
6509 line numbers but no functions (as can happen in assembly
6512 struct minimal_symbol
*msym
;
6514 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
6516 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
6523 break_command (char *arg
, int from_tty
)
6525 break_command_1 (arg
, 0, from_tty
);
6529 tbreak_command (char *arg
, int from_tty
)
6531 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
6535 hbreak_command (char *arg
, int from_tty
)
6537 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
6541 thbreak_command (char *arg
, int from_tty
)
6543 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
6547 stop_command (char *arg
, int from_tty
)
6549 printf_filtered (_("Specify the type of breakpoint to set.\n\
6550 Usage: stop in <function | address>\n\
6551 stop at <line>\n"));
6555 stopin_command (char *arg
, int from_tty
)
6559 if (arg
== (char *) NULL
)
6561 else if (*arg
!= '*')
6566 /* look for a ':'. If this is a line number specification, then
6567 say it is bad, otherwise, it should be an address or
6568 function/method name */
6569 while (*argptr
&& !hasColon
)
6571 hasColon
= (*argptr
== ':');
6576 badInput
= (*argptr
!= ':'); /* Not a class::method */
6578 badInput
= isdigit (*arg
); /* a simple line number */
6582 printf_filtered (_("Usage: stop in <function | address>\n"));
6584 break_command_1 (arg
, 0, from_tty
);
6588 stopat_command (char *arg
, int from_tty
)
6592 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6599 /* look for a ':'. If there is a '::' then get out, otherwise
6600 it is probably a line number. */
6601 while (*argptr
&& !hasColon
)
6603 hasColon
= (*argptr
== ':');
6608 badInput
= (*argptr
== ':'); /* we have class::method */
6610 badInput
= !isdigit (*arg
); /* not a line number */
6614 printf_filtered (_("Usage: stop at <line>\n"));
6616 break_command_1 (arg
, 0, from_tty
);
6619 /* accessflag: hw_write: watch write,
6620 hw_read: watch read,
6621 hw_access: watch access (read or write) */
6623 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6625 struct gdbarch
*gdbarch
= get_current_arch ();
6626 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6627 struct symtab_and_line sal
;
6628 struct expression
*exp
;
6629 struct block
*exp_valid_block
;
6630 struct value
*val
, *mark
;
6631 struct frame_info
*frame
;
6632 char *exp_start
= NULL
;
6633 char *exp_end
= NULL
;
6634 char *tok
, *id_tok_start
, *end_tok
;
6636 char *cond_start
= NULL
;
6637 char *cond_end
= NULL
;
6638 struct expression
*cond
= NULL
;
6639 int i
, other_type_used
, target_resources_ok
= 0;
6640 enum bptype bp_type
;
6644 init_sal (&sal
); /* initialize to zeroes */
6646 /* Make sure that we actually have parameters to parse. */
6647 if (arg
!= NULL
&& arg
[0] != '\0')
6649 toklen
= strlen (arg
); /* Size of argument list. */
6651 /* Points tok to the end of the argument list. */
6652 tok
= arg
+ toklen
- 1;
6654 /* Go backwards in the parameters list. Skip the last parameter.
6655 If we're expecting a 'thread <thread_num>' parameter, this should
6656 be the thread identifier. */
6657 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6659 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6662 /* Points end_tok to the beginning of the last token. */
6663 id_tok_start
= tok
+ 1;
6665 /* Go backwards in the parameters list. Skip one more parameter.
6666 If we're expecting a 'thread <thread_num>' parameter, we should
6667 reach a "thread" token. */
6668 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6673 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6676 /* Move the pointer forward to skip the whitespace and
6677 calculate the length of the token. */
6679 toklen
= end_tok
- tok
;
6681 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6683 /* At this point we've found a "thread" token, which means
6684 the user is trying to set a watchpoint that triggers
6685 only in a specific thread. */
6688 /* Extract the thread ID from the next token. */
6689 thread
= strtol (id_tok_start
, &endp
, 0);
6691 /* Check if the user provided a valid numeric value for the
6693 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6694 error (_("Invalid thread ID specification %s."), id_tok_start
);
6696 /* Check if the thread actually exists. */
6697 if (!valid_thread_id (thread
))
6698 error (_("Unknown thread %d."), thread
);
6700 /* Truncate the string and get rid of the thread <thread_num>
6701 parameter before the parameter list is parsed by the
6702 evaluate_expression() function. */
6707 /* Parse the rest of the arguments. */
6708 innermost_block
= NULL
;
6710 exp
= parse_exp_1 (&arg
, 0, 0);
6712 /* Remove trailing whitespace from the expression before saving it.
6713 This makes the eventual display of the expression string a bit
6715 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
6718 exp_valid_block
= innermost_block
;
6719 mark
= value_mark ();
6720 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6722 release_value (val
);
6725 while (*tok
== ' ' || *tok
== '\t')
6729 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6732 toklen
= end_tok
- tok
;
6733 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6735 tok
= cond_start
= end_tok
+ 1;
6736 cond
= parse_exp_1 (&tok
, 0, 0);
6740 error (_("Junk at end of command."));
6742 if (accessflag
== hw_read
)
6743 bp_type
= bp_read_watchpoint
;
6744 else if (accessflag
== hw_access
)
6745 bp_type
= bp_access_watchpoint
;
6747 bp_type
= bp_hardware_watchpoint
;
6749 mem_cnt
= can_use_hardware_watchpoint (val
);
6750 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6751 error (_("Expression cannot be implemented with read/access watchpoint."));
6754 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6755 target_resources_ok
=
6756 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
6758 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6759 error (_("Target does not support this type of hardware watchpoint."));
6761 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6762 error (_("Target can only support one kind of HW watchpoint at a time."));
6765 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6766 watchpoint could not be set. */
6767 if (!mem_cnt
|| target_resources_ok
<= 0)
6768 bp_type
= bp_watchpoint
;
6770 frame
= block_innermost_frame (exp_valid_block
);
6772 /* If the expression is "local", then set up a "watchpoint scope"
6773 breakpoint at the point where we've left the scope of the watchpoint
6774 expression. Create the scope breakpoint before the watchpoint, so
6775 that we will encounter it first in bpstat_stop_status. */
6776 if (innermost_block
&& frame
)
6778 if (frame_id_p (frame_unwind_caller_id (frame
)))
6781 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
6782 frame_unwind_caller_pc (frame
),
6783 bp_watchpoint_scope
);
6785 scope_breakpoint
->enable_state
= bp_enabled
;
6787 /* Automatically delete the breakpoint when it hits. */
6788 scope_breakpoint
->disposition
= disp_del
;
6790 /* Only break in the proper frame (help with recursion). */
6791 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
6793 /* Set the address at which we will stop. */
6794 scope_breakpoint
->loc
->gdbarch
6795 = frame_unwind_caller_arch (frame
);
6796 scope_breakpoint
->loc
->requested_address
6797 = frame_unwind_caller_pc (frame
);
6798 scope_breakpoint
->loc
->address
6799 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
6800 scope_breakpoint
->loc
->requested_address
,
6801 scope_breakpoint
->type
);
6805 /* Now set up the breakpoint. */
6806 b
= set_raw_breakpoint (gdbarch
, sal
, bp_type
);
6807 set_breakpoint_count (breakpoint_count
+ 1);
6808 b
->number
= breakpoint_count
;
6810 b
->disposition
= disp_donttouch
;
6812 b
->exp_valid_block
= exp_valid_block
;
6813 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6816 b
->loc
->cond
= cond
;
6818 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6823 b
->watchpoint_frame
= get_frame_id (frame
);
6825 b
->watchpoint_frame
= null_frame_id
;
6827 if (scope_breakpoint
!= NULL
)
6829 /* The scope breakpoint is related to the watchpoint. We will
6830 need to act on them together. */
6831 b
->related_breakpoint
= scope_breakpoint
;
6832 scope_breakpoint
->related_breakpoint
= b
;
6835 value_free_to_mark (mark
);
6837 update_global_location_list (1);
6840 /* Return count of locations need to be watched and can be handled
6841 in hardware. If the watchpoint can not be handled
6842 in hardware return zero. */
6845 can_use_hardware_watchpoint (struct value
*v
)
6847 int found_memory_cnt
= 0;
6848 struct value
*head
= v
;
6850 /* Did the user specifically forbid us to use hardware watchpoints? */
6851 if (!can_use_hw_watchpoints
)
6854 /* Make sure that the value of the expression depends only upon
6855 memory contents, and values computed from them within GDB. If we
6856 find any register references or function calls, we can't use a
6857 hardware watchpoint.
6859 The idea here is that evaluating an expression generates a series
6860 of values, one holding the value of every subexpression. (The
6861 expression a*b+c has five subexpressions: a, b, a*b, c, and
6862 a*b+c.) GDB's values hold almost enough information to establish
6863 the criteria given above --- they identify memory lvalues,
6864 register lvalues, computed values, etcetera. So we can evaluate
6865 the expression, and then scan the chain of values that leaves
6866 behind to decide whether we can detect any possible change to the
6867 expression's final value using only hardware watchpoints.
6869 However, I don't think that the values returned by inferior
6870 function calls are special in any way. So this function may not
6871 notice that an expression involving an inferior function call
6872 can't be watched with hardware watchpoints. FIXME. */
6873 for (; v
; v
= value_next (v
))
6875 if (VALUE_LVAL (v
) == lval_memory
)
6878 /* A lazy memory lvalue is one that GDB never needed to fetch;
6879 we either just used its address (e.g., `a' in `a.b') or
6880 we never needed it at all (e.g., `a' in `a,b'). */
6884 /* Ahh, memory we actually used! Check if we can cover
6885 it with hardware watchpoints. */
6886 struct type
*vtype
= check_typedef (value_type (v
));
6888 /* We only watch structs and arrays if user asked for it
6889 explicitly, never if they just happen to appear in a
6890 middle of some value chain. */
6892 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6893 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6895 CORE_ADDR vaddr
= value_address (v
);
6896 int len
= TYPE_LENGTH (value_type (v
));
6898 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
6905 else if (VALUE_LVAL (v
) != not_lval
6906 && deprecated_value_modifiable (v
) == 0)
6907 return 0; /* ??? What does this represent? */
6908 else if (VALUE_LVAL (v
) == lval_register
)
6909 return 0; /* cannot watch a register with a HW watchpoint */
6912 /* The expression itself looks suitable for using a hardware
6913 watchpoint, but give the target machine a chance to reject it. */
6914 return found_memory_cnt
;
6918 watch_command_wrapper (char *arg
, int from_tty
)
6920 watch_command (arg
, from_tty
);
6924 watch_command (char *arg
, int from_tty
)
6926 watch_command_1 (arg
, hw_write
, from_tty
);
6930 rwatch_command_wrapper (char *arg
, int from_tty
)
6932 rwatch_command (arg
, from_tty
);
6936 rwatch_command (char *arg
, int from_tty
)
6938 watch_command_1 (arg
, hw_read
, from_tty
);
6942 awatch_command_wrapper (char *arg
, int from_tty
)
6944 awatch_command (arg
, from_tty
);
6948 awatch_command (char *arg
, int from_tty
)
6950 watch_command_1 (arg
, hw_access
, from_tty
);
6954 /* Helper routines for the until_command routine in infcmd.c. Here
6955 because it uses the mechanisms of breakpoints. */
6957 struct until_break_command_continuation_args
6959 struct breakpoint
*breakpoint
;
6960 struct breakpoint
*breakpoint2
;
6963 /* This function is called by fetch_inferior_event via the
6964 cmd_continuation pointer, to complete the until command. It takes
6965 care of cleaning up the temporary breakpoints set up by the until
6968 until_break_command_continuation (void *arg
)
6970 struct until_break_command_continuation_args
*a
= arg
;
6972 delete_breakpoint (a
->breakpoint
);
6974 delete_breakpoint (a
->breakpoint2
);
6978 until_break_command (char *arg
, int from_tty
, int anywhere
)
6980 struct symtabs_and_lines sals
;
6981 struct symtab_and_line sal
;
6982 struct frame_info
*frame
= get_selected_frame (NULL
);
6983 struct breakpoint
*breakpoint
;
6984 struct breakpoint
*breakpoint2
= NULL
;
6985 struct cleanup
*old_chain
;
6987 clear_proceed_status ();
6989 /* Set a breakpoint where the user wants it and at return from
6992 if (default_breakpoint_valid
)
6993 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6994 default_breakpoint_line
, (char ***) NULL
, NULL
);
6996 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6997 0, (char ***) NULL
, NULL
);
6999 if (sals
.nelts
!= 1)
7000 error (_("Couldn't get information on specified line."));
7003 xfree (sals
.sals
); /* malloc'd, so freed */
7006 error (_("Junk at end of arguments."));
7008 resolve_sal_pc (&sal
);
7011 /* If the user told us to continue until a specified location,
7012 we don't specify a frame at which we need to stop. */
7013 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7014 null_frame_id
, bp_until
);
7016 /* Otherwise, specify the selected frame, because we want to stop only
7017 at the very same frame. */
7018 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7019 get_stack_frame_id (frame
),
7022 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
7024 /* Keep within the current frame, or in frames called by the current
7027 if (frame_id_p (frame_unwind_caller_id (frame
)))
7029 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
7030 sal
.pc
= frame_unwind_caller_pc (frame
);
7031 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
7033 frame_unwind_caller_id (frame
),
7035 make_cleanup_delete_breakpoint (breakpoint2
);
7038 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
7040 /* If we are running asynchronously, and proceed call above has actually
7041 managed to start the target, arrange for breakpoints to be
7042 deleted when the target stops. Otherwise, we're already stopped and
7043 delete breakpoints via cleanup chain. */
7045 if (target_can_async_p () && is_running (inferior_ptid
))
7047 struct until_break_command_continuation_args
*args
;
7048 args
= xmalloc (sizeof (*args
));
7050 args
->breakpoint
= breakpoint
;
7051 args
->breakpoint2
= breakpoint2
;
7053 discard_cleanups (old_chain
);
7054 add_continuation (inferior_thread (),
7055 until_break_command_continuation
, args
,
7059 do_cleanups (old_chain
);
7063 ep_skip_leading_whitespace (char **s
)
7065 if ((s
== NULL
) || (*s
== NULL
))
7067 while (isspace (**s
))
7071 /* This function attempts to parse an optional "if <cond>" clause
7072 from the arg string. If one is not found, it returns NULL.
7074 Else, it returns a pointer to the condition string. (It does not
7075 attempt to evaluate the string against a particular block.) And,
7076 it updates arg to point to the first character following the parsed
7077 if clause in the arg string. */
7080 ep_parse_optional_if_clause (char **arg
)
7084 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
7087 /* Skip the "if" keyword. */
7090 /* Skip any extra leading whitespace, and record the start of the
7091 condition string. */
7092 ep_skip_leading_whitespace (arg
);
7095 /* Assume that the condition occupies the remainder of the arg string. */
7096 (*arg
) += strlen (cond_string
);
7101 /* This function attempts to parse an optional filename from the arg
7102 string. If one is not found, it returns NULL.
7104 Else, it returns a pointer to the parsed filename. (This function
7105 makes no attempt to verify that a file of that name exists, or is
7106 accessible.) And, it updates arg to point to the first character
7107 following the parsed filename in the arg string.
7109 Note that clients needing to preserve the returned filename for
7110 future access should copy it to their own buffers. */
7112 ep_parse_optional_filename (char **arg
)
7114 static char filename
[1024];
7119 if ((*arg_p
== '\0') || isspace (*arg_p
))
7137 /* Commands to deal with catching events, such as signals, exceptions,
7138 process start/exit, etc. */
7142 catch_fork_temporary
, catch_vfork_temporary
,
7143 catch_fork_permanent
, catch_vfork_permanent
7148 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7150 struct gdbarch
*gdbarch
= get_current_arch ();
7151 char *cond_string
= NULL
;
7152 catch_fork_kind fork_kind
;
7155 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
7156 tempflag
= (fork_kind
== catch_fork_temporary
7157 || fork_kind
== catch_vfork_temporary
);
7161 ep_skip_leading_whitespace (&arg
);
7163 /* The allowed syntax is:
7165 catch [v]fork if <cond>
7167 First, check if there's an if clause. */
7168 cond_string
= ep_parse_optional_if_clause (&arg
);
7170 if ((*arg
!= '\0') && !isspace (*arg
))
7171 error (_("Junk at end of arguments."));
7173 /* If this target supports it, create a fork or vfork catchpoint
7174 and enable reporting of such events. */
7177 case catch_fork_temporary
:
7178 case catch_fork_permanent
:
7179 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
7180 &catch_fork_breakpoint_ops
);
7182 case catch_vfork_temporary
:
7183 case catch_vfork_permanent
:
7184 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
7185 &catch_vfork_breakpoint_ops
);
7188 error (_("unsupported or unknown fork kind; cannot catch it"));
7194 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7196 struct gdbarch
*gdbarch
= get_current_arch ();
7198 char *cond_string
= NULL
;
7200 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7204 ep_skip_leading_whitespace (&arg
);
7206 /* The allowed syntax is:
7208 catch exec if <cond>
7210 First, check if there's an if clause. */
7211 cond_string
= ep_parse_optional_if_clause (&arg
);
7213 if ((*arg
!= '\0') && !isspace (*arg
))
7214 error (_("Junk at end of arguments."));
7216 /* If this target supports it, create an exec catchpoint
7217 and enable reporting of such events. */
7218 create_catchpoint (gdbarch
, tempflag
, cond_string
,
7219 &catch_exec_breakpoint_ops
);
7222 static enum print_stop_action
7223 print_exception_catchpoint (struct breakpoint
*b
)
7225 int bp_temp
, bp_throw
;
7227 annotate_catchpoint (b
->number
);
7229 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
7230 if (b
->loc
->address
!= b
->loc
->requested_address
)
7231 breakpoint_adjustment_warning (b
->loc
->requested_address
,
7234 bp_temp
= b
->disposition
== disp_del
;
7236 bp_temp
? "Temporary catchpoint "
7238 if (!ui_out_is_mi_like_p (uiout
))
7239 ui_out_field_int (uiout
, "bkptno", b
->number
);
7241 bp_throw
? " (exception thrown), "
7242 : " (exception caught), ");
7243 if (ui_out_is_mi_like_p (uiout
))
7245 ui_out_field_string (uiout
, "reason",
7246 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
7247 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7248 ui_out_field_int (uiout
, "bkptno", b
->number
);
7250 return PRINT_SRC_AND_LOC
;
7254 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
7256 struct value_print_options opts
;
7257 get_user_print_options (&opts
);
7258 if (opts
.addressprint
)
7261 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
7262 ui_out_field_string (uiout
, "addr", "<PENDING>");
7264 ui_out_field_core_addr (uiout
, "addr",
7265 b
->loc
->gdbarch
, b
->loc
->address
);
7270 if (strstr (b
->addr_string
, "throw") != NULL
)
7271 ui_out_field_string (uiout
, "what", "exception throw");
7273 ui_out_field_string (uiout
, "what", "exception catch");
7277 print_mention_exception_catchpoint (struct breakpoint
*b
)
7282 bp_temp
= b
->disposition
== disp_del
;
7283 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
7284 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
7285 : _("Catchpoint "));
7286 ui_out_field_int (uiout
, "bkptno", b
->number
);
7287 ui_out_text (uiout
, bp_throw
? _(" (throw)")
7291 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
7294 NULL
, /* breakpoint_hit */
7295 print_exception_catchpoint
,
7296 print_one_exception_catchpoint
,
7297 print_mention_exception_catchpoint
7301 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
7302 enum exception_event_kind ex_event
, int from_tty
)
7304 char *trigger_func_name
;
7306 if (ex_event
== EX_EVENT_CATCH
)
7307 trigger_func_name
= "__cxa_begin_catch";
7309 trigger_func_name
= "__cxa_throw";
7311 break_command_really (get_current_arch (),
7312 trigger_func_name
, cond_string
, -1,
7313 0 /* condition and thread are valid. */,
7316 AUTO_BOOLEAN_TRUE
/* pending */,
7317 &gnu_v3_exception_catchpoint_ops
, from_tty
,
7323 /* Deal with "catch catch" and "catch throw" commands */
7326 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
7327 int tempflag
, int from_tty
)
7329 char *cond_string
= NULL
;
7330 struct symtab_and_line
*sal
= NULL
;
7334 ep_skip_leading_whitespace (&arg
);
7336 cond_string
= ep_parse_optional_if_clause (&arg
);
7338 if ((*arg
!= '\0') && !isspace (*arg
))
7339 error (_("Junk at end of arguments."));
7341 if (ex_event
!= EX_EVENT_THROW
7342 && ex_event
!= EX_EVENT_CATCH
)
7343 error (_("Unsupported or unknown exception event; cannot catch it"));
7345 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
7348 warning (_("Unsupported with this platform/compiler combination."));
7351 /* Implementation of "catch catch" command. */
7354 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7356 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7357 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
7360 /* Implementation of "catch throw" command. */
7363 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7365 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7366 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
7369 /* Create a breakpoint struct for Ada exception catchpoints. */
7372 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
7373 struct symtab_and_line sal
,
7377 struct expression
*cond
,
7378 struct breakpoint_ops
*ops
,
7382 struct breakpoint
*b
;
7386 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7388 loc_gdbarch
= gdbarch
;
7390 describe_other_breakpoints (loc_gdbarch
, sal
.pc
, sal
.section
, -1);
7391 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7392 version for exception catchpoints, because two catchpoints
7393 used for different exception names will use the same address.
7394 In this case, a "breakpoint ... also set at..." warning is
7395 unproductive. Besides. the warning phrasing is also a bit
7396 inapropriate, we should use the word catchpoint, and tell
7397 the user what type of catchpoint it is. The above is good
7398 enough for now, though. */
7401 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
7402 set_breakpoint_count (breakpoint_count
+ 1);
7404 b
->enable_state
= bp_enabled
;
7405 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7406 b
->number
= breakpoint_count
;
7407 b
->ignore_count
= 0;
7408 b
->loc
->cond
= cond
;
7409 b
->addr_string
= addr_string
;
7410 b
->language
= language_ada
;
7411 b
->cond_string
= cond_string
;
7412 b
->exp_string
= exp_string
;
7417 update_global_location_list (1);
7420 /* Implement the "catch exception" command. */
7423 catch_ada_exception_command (char *arg
, int from_tty
,
7424 struct cmd_list_element
*command
)
7426 struct gdbarch
*gdbarch
= get_current_arch ();
7428 struct symtab_and_line sal
;
7430 char *addr_string
= NULL
;
7431 char *exp_string
= NULL
;
7432 char *cond_string
= NULL
;
7433 struct expression
*cond
= NULL
;
7434 struct breakpoint_ops
*ops
= NULL
;
7436 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7440 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
7441 &cond_string
, &cond
, &ops
);
7442 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
7443 cond_string
, cond
, ops
, tempflag
,
7447 /* Cleanup function for a syscall filter list. */
7449 clean_up_filters (void *arg
)
7451 VEC(int) *iter
= *(VEC(int) **) arg
;
7452 VEC_free (int, iter
);
7455 /* Splits the argument using space as delimiter. Returns an xmalloc'd
7456 filter list, or NULL if no filtering is required. */
7458 catch_syscall_split_args (char *arg
)
7460 VEC(int) *result
= NULL
;
7461 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
7463 while (*arg
!= '\0')
7465 int i
, syscall_number
;
7470 /* Skip whitespace. */
7471 while (isspace (*arg
))
7474 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
7475 cur_name
[i
] = arg
[i
];
7479 /* Check if the user provided a syscall name or a number. */
7480 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
7481 if (*endptr
== '\0')
7483 get_syscall_by_number (syscall_number
, &s
);
7486 /* We can issue just a warning, but still create the catchpoint.
7487 This is because, even not knowing the syscall name that
7488 this number represents, we can still try to catch the syscall
7490 warning (_("The number '%d' does not represent a known syscall."),
7495 /* We have a name. Let's check if it's valid and convert it
7497 get_syscall_by_name (cur_name
, &s
);
7499 if (s
.number
== UNKNOWN_SYSCALL
)
7500 /* Here we have to issue an error instead of a warning, because
7501 GDB cannot do anything useful if there's no syscall number to
7503 error (_("Unknown syscall name '%s'."), cur_name
);
7506 /* Ok, it's valid. */
7507 VEC_safe_push (int, result
, s
.number
);
7510 discard_cleanups (cleanup
);
7514 /* Implement the "catch syscall" command. */
7517 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7522 struct gdbarch
*gdbarch
= get_current_arch ();
7524 /* Checking if the feature if supported. */
7525 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
7526 error (_("The feature 'catch syscall' is not supported on \
7527 this architeture yet."));
7529 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7531 ep_skip_leading_whitespace (&arg
);
7533 /* We need to do this first "dummy" translation in order
7534 to get the syscall XML file loaded or, most important,
7535 to display a warning to the user if there's no XML file
7536 for his/her architecture. */
7537 get_syscall_by_number (0, &s
);
7539 /* The allowed syntax is:
7541 catch syscall <name | number> [<name | number> ... <name | number>]
7543 Let's check if there's a syscall name. */
7546 filter
= catch_syscall_split_args (arg
);
7550 create_syscall_event_catchpoint (tempflag
, filter
,
7551 &catch_syscall_breakpoint_ops
);
7554 /* Implement the "catch assert" command. */
7557 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7559 struct gdbarch
*gdbarch
= get_current_arch ();
7561 struct symtab_and_line sal
;
7562 char *addr_string
= NULL
;
7563 struct breakpoint_ops
*ops
= NULL
;
7565 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7569 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
7570 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
7571 ops
, tempflag
, from_tty
);
7575 catch_command (char *arg
, int from_tty
)
7577 error (_("Catch requires an event name."));
7582 tcatch_command (char *arg
, int from_tty
)
7584 error (_("Catch requires an event name."));
7587 /* Delete breakpoints by address or line. */
7590 clear_command (char *arg
, int from_tty
)
7592 struct breakpoint
*b
;
7593 VEC(breakpoint_p
) *found
= 0;
7596 struct symtabs_and_lines sals
;
7597 struct symtab_and_line sal
;
7602 sals
= decode_line_spec (arg
, 1);
7607 sals
.sals
= (struct symtab_and_line
*)
7608 xmalloc (sizeof (struct symtab_and_line
));
7609 make_cleanup (xfree
, sals
.sals
);
7610 init_sal (&sal
); /* initialize to zeroes */
7611 sal
.line
= default_breakpoint_line
;
7612 sal
.symtab
= default_breakpoint_symtab
;
7613 sal
.pc
= default_breakpoint_address
;
7614 if (sal
.symtab
== 0)
7615 error (_("No source file specified."));
7623 /* We don't call resolve_sal_pc here. That's not
7624 as bad as it seems, because all existing breakpoints
7625 typically have both file/line and pc set. So, if
7626 clear is given file/line, we can match this to existing
7627 breakpoint without obtaining pc at all.
7629 We only support clearing given the address explicitly
7630 present in breakpoint table. Say, we've set breakpoint
7631 at file:line. There were several PC values for that file:line,
7632 due to optimization, all in one block.
7633 We've picked one PC value. If "clear" is issued with another
7634 PC corresponding to the same file:line, the breakpoint won't
7635 be cleared. We probably can still clear the breakpoint, but
7636 since the other PC value is never presented to user, user
7637 can only find it by guessing, and it does not seem important
7640 /* For each line spec given, delete bps which correspond
7641 to it. Do it in two passes, solely to preserve the current
7642 behavior that from_tty is forced true if we delete more than
7646 for (i
= 0; i
< sals
.nelts
; i
++)
7648 /* If exact pc given, clear bpts at that pc.
7649 If line given (pc == 0), clear all bpts on specified line.
7650 If defaulting, clear all bpts on default line
7653 defaulting sal.pc != 0 tests to do
7658 1 0 <can't happen> */
7662 /* Find all matching breakpoints and add them to
7667 /* Are we going to delete b? */
7668 if (b
->type
!= bp_none
7669 && b
->type
!= bp_watchpoint
7670 && b
->type
!= bp_hardware_watchpoint
7671 && b
->type
!= bp_read_watchpoint
7672 && b
->type
!= bp_access_watchpoint
)
7674 struct bp_location
*loc
= b
->loc
;
7675 for (; loc
; loc
= loc
->next
)
7677 int pc_match
= sal
.pc
7678 && (loc
->address
== sal
.pc
)
7679 && (!section_is_overlay (loc
->section
)
7680 || loc
->section
== sal
.section
);
7681 int line_match
= ((default_match
|| (0 == sal
.pc
))
7682 && b
->source_file
!= NULL
7683 && sal
.symtab
!= NULL
7684 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7685 && b
->line_number
== sal
.line
);
7686 if (pc_match
|| line_match
)
7695 VEC_safe_push(breakpoint_p
, found
, b
);
7698 /* Now go thru the 'found' chain and delete them. */
7699 if (VEC_empty(breakpoint_p
, found
))
7702 error (_("No breakpoint at %s."), arg
);
7704 error (_("No breakpoint at this line."));
7707 if (VEC_length(breakpoint_p
, found
) > 1)
7708 from_tty
= 1; /* Always report if deleted more than one */
7711 if (VEC_length(breakpoint_p
, found
) == 1)
7712 printf_unfiltered (_("Deleted breakpoint "));
7714 printf_unfiltered (_("Deleted breakpoints "));
7716 breakpoints_changed ();
7718 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7721 printf_unfiltered ("%d ", b
->number
);
7722 delete_breakpoint (b
);
7725 putchar_unfiltered ('\n');
7728 /* Delete breakpoint in BS if they are `delete' breakpoints and
7729 all breakpoints that are marked for deletion, whether hit or not.
7730 This is called after any breakpoint is hit, or after errors. */
7733 breakpoint_auto_delete (bpstat bs
)
7735 struct breakpoint
*b
, *temp
;
7737 for (; bs
; bs
= bs
->next
)
7738 if (bs
->breakpoint_at
7739 && bs
->breakpoint_at
->owner
7740 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7742 delete_breakpoint (bs
->breakpoint_at
->owner
);
7744 ALL_BREAKPOINTS_SAFE (b
, temp
)
7746 if (b
->disposition
== disp_del_at_next_stop
)
7747 delete_breakpoint (b
);
7751 /* A cleanup function which destroys a vector. */
7754 do_vec_free (void *p
)
7756 VEC(bp_location_p
) **vec
= p
;
7758 VEC_free (bp_location_p
, *vec
);
7761 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7762 into the inferior, only remove already-inserted locations that no
7763 longer should be inserted. Functions that delete a breakpoint or
7764 breakpoints should pass false, so that deleting a breakpoint
7765 doesn't have the side effect of inserting the locations of other
7766 breakpoints that are marked not-inserted, but should_be_inserted
7767 returns true on them.
7769 This behaviour is useful is situations close to tear-down -- e.g.,
7770 after an exec, while the target still has execution, but breakpoint
7771 shadows of the previous executable image should *NOT* be restored
7772 to the new image; or before detaching, where the target still has
7773 execution and wants to delete breakpoints from GDB's lists, and all
7774 breakpoints had already been removed from the inferior. */
7777 update_global_location_list (int should_insert
)
7779 struct breakpoint
*b
;
7780 struct bp_location
**next
= &bp_location_chain
;
7781 struct bp_location
*loc
;
7782 struct bp_location
*loc2
;
7783 VEC(bp_location_p
) *old_locations
= NULL
;
7786 struct cleanup
*cleanups
;
7788 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
7789 /* Store old locations for future reference. */
7790 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7791 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7793 bp_location_chain
= NULL
;
7796 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7799 next
= &(loc
->global_next
);
7804 /* Identify bp_location instances that are no longer present in the new
7805 list, and therefore should be freed. Note that it's not necessary that
7806 those locations should be removed from inferior -- if there's another
7807 location at the same address (previously marked as duplicate),
7808 we don't need to remove/insert the location. */
7809 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7811 /* Tells if 'loc' is found amoung the new locations. If not, we
7813 int found_object
= 0;
7814 /* Tells if the location should remain inserted in the target. */
7815 int keep_in_target
= 0;
7817 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7824 /* If this location is no longer present, and inserted, look if there's
7825 maybe a new location at the same address. If so, mark that one
7826 inserted, and don't remove this one. This is needed so that we
7827 don't have a time window where a breakpoint at certain location is not
7832 /* If the location is inserted now, we might have to remove it. */
7834 if (found_object
&& should_be_inserted (loc
))
7836 /* The location is still present in the location list, and still
7837 should be inserted. Don't do anything. */
7842 /* The location is either no longer present, or got disabled.
7843 See if there's another location at the same address, in which
7844 case we don't need to remove this one from the target. */
7845 if (breakpoint_address_is_meaningful (loc
->owner
))
7846 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7848 /* For the sake of should_insert_location. The
7849 call to check_duplicates will fix up this later. */
7850 loc2
->duplicate
= 0;
7851 if (should_be_inserted (loc2
)
7852 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7855 loc2
->target_info
= loc
->target_info
;
7862 if (!keep_in_target
)
7864 if (remove_breakpoint (loc
, mark_uninserted
))
7866 /* This is just about all we can do. We could keep this
7867 location on the global list, and try to remove it next
7868 time, but there's no particular reason why we will
7871 Note that at this point, loc->owner is still valid,
7872 as delete_breakpoint frees the breakpoint only
7873 after calling us. */
7874 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7875 loc
->owner
->number
);
7883 if (removed
&& non_stop
)
7885 /* This location was removed from the targets. In non-stop mode,
7886 a race condition is possible where we've removed a breakpoint,
7887 but stop events for that breakpoint are already queued and will
7888 arrive later. To suppress spurious SIGTRAPs reported to user,
7889 we keep this breakpoint location for a bit, and will retire it
7890 after we see 3 * thread_count events.
7891 The theory here is that reporting of events should,
7892 "on the average", be fair, so after that many event we'll see
7893 events from all threads that have anything of interest, and no
7894 longer need to keep this breakpoint. This is just a
7895 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7896 which is usability issue, but not a correctness problem. */
7897 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7900 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7903 free_bp_location (loc
);
7909 check_duplicates (b
);
7912 if (breakpoints_always_inserted_mode () && should_insert
7913 && (have_live_inferiors ()
7914 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
7915 insert_breakpoint_locations ();
7917 do_cleanups (cleanups
);
7921 breakpoint_retire_moribund (void)
7923 struct bp_location
*loc
;
7926 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7927 if (--(loc
->events_till_retirement
) == 0)
7929 free_bp_location (loc
);
7930 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7936 update_global_location_list_nothrow (int inserting
)
7938 struct gdb_exception e
;
7939 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7940 update_global_location_list (inserting
);
7943 /* Clear BPT from a BPS. */
7945 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7948 for (bs
= bps
; bs
; bs
= bs
->next
)
7949 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7951 bs
->breakpoint_at
= NULL
;
7953 /* bs->commands will be freed later. */
7957 /* Callback for iterate_over_threads. */
7959 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7961 struct breakpoint
*bpt
= data
;
7962 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7966 /* Delete a breakpoint and clean up all traces of it in the data
7970 delete_breakpoint (struct breakpoint
*bpt
)
7972 struct breakpoint
*b
;
7973 struct bp_location
*loc
, *next
;
7975 gdb_assert (bpt
!= NULL
);
7977 /* Has this bp already been deleted? This can happen because multiple
7978 lists can hold pointers to bp's. bpstat lists are especial culprits.
7980 One example of this happening is a watchpoint's scope bp. When the
7981 scope bp triggers, we notice that the watchpoint is out of scope, and
7982 delete it. We also delete its scope bp. But the scope bp is marked
7983 "auto-deleting", and is already on a bpstat. That bpstat is then
7984 checked for auto-deleting bp's, which are deleted.
7986 A real solution to this problem might involve reference counts in bp's,
7987 and/or giving them pointers back to their referencing bpstat's, and
7988 teaching delete_breakpoint to only free a bp's storage when no more
7989 references were extent. A cheaper bandaid was chosen. */
7990 if (bpt
->type
== bp_none
)
7993 observer_notify_breakpoint_deleted (bpt
->number
);
7995 if (breakpoint_chain
== bpt
)
7996 breakpoint_chain
= bpt
->next
;
8001 b
->next
= bpt
->next
;
8005 free_command_lines (&bpt
->commands
);
8006 if (bpt
->cond_string
!= NULL
)
8007 xfree (bpt
->cond_string
);
8008 if (bpt
->addr_string
!= NULL
)
8009 xfree (bpt
->addr_string
);
8010 if (bpt
->exp
!= NULL
)
8012 if (bpt
->exp_string
!= NULL
)
8013 xfree (bpt
->exp_string
);
8014 if (bpt
->val
!= NULL
)
8015 value_free (bpt
->val
);
8016 if (bpt
->source_file
!= NULL
)
8017 xfree (bpt
->source_file
);
8018 if (bpt
->exec_pathname
!= NULL
)
8019 xfree (bpt
->exec_pathname
);
8020 clean_up_filters (&bpt
->syscalls_to_be_caught
);
8022 /* Be sure no bpstat's are pointing at it after it's been freed. */
8023 /* FIXME, how can we find all bpstat's?
8024 We just check stop_bpstat for now. Note that we cannot just
8025 remove bpstats pointing at bpt from the stop_bpstat list
8026 entirely, as breakpoint commands are associated with the bpstat;
8027 if we remove it here, then the later call to
8028 bpstat_do_actions (&stop_bpstat);
8029 in event-top.c won't do anything, and temporary breakpoints
8030 with commands won't work. */
8032 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
8034 /* Now that breakpoint is removed from breakpoint
8035 list, update the global location list. This
8036 will remove locations that used to belong to
8037 this breakpoint. Do this before freeing
8038 the breakpoint itself, since remove_breakpoint
8039 looks at location's owner. It might be better
8040 design to have location completely self-contained,
8041 but it's not the case now. */
8042 update_global_location_list (0);
8045 /* On the chance that someone will soon try again to delete this same
8046 bp, we mark it as deleted before freeing its storage. */
8047 bpt
->type
= bp_none
;
8053 do_delete_breakpoint_cleanup (void *b
)
8055 delete_breakpoint (b
);
8059 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
8061 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
8065 delete_command (char *arg
, int from_tty
)
8067 struct breakpoint
*b
, *temp
;
8073 int breaks_to_delete
= 0;
8075 /* Delete all breakpoints if no argument.
8076 Do not delete internal or call-dummy breakpoints, these
8077 have to be deleted with an explicit breakpoint number argument. */
8080 if (b
->type
!= bp_call_dummy
8081 && b
->type
!= bp_shlib_event
8082 && b
->type
!= bp_jit_event
8083 && b
->type
!= bp_thread_event
8084 && b
->type
!= bp_overlay_event
8085 && b
->type
!= bp_longjmp_master
8088 breaks_to_delete
= 1;
8093 /* Ask user only if there are some breakpoints to delete. */
8095 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
8097 ALL_BREAKPOINTS_SAFE (b
, temp
)
8099 if (b
->type
!= bp_call_dummy
8100 && b
->type
!= bp_shlib_event
8101 && b
->type
!= bp_thread_event
8102 && b
->type
!= bp_jit_event
8103 && b
->type
!= bp_overlay_event
8104 && b
->type
!= bp_longjmp_master
8106 delete_breakpoint (b
);
8111 map_breakpoint_numbers (arg
, delete_breakpoint
);
8115 all_locations_are_pending (struct bp_location
*loc
)
8117 for (; loc
; loc
= loc
->next
)
8118 if (!loc
->shlib_disabled
)
8123 /* Subroutine of update_breakpoint_locations to simplify it.
8124 Return non-zero if multiple fns in list LOC have the same name.
8125 Null names are ignored. */
8128 ambiguous_names_p (struct bp_location
*loc
)
8130 struct bp_location
*l
;
8131 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
8132 (int (*) (const void *, const void *)) streq
,
8133 NULL
, xcalloc
, xfree
);
8135 for (l
= loc
; l
!= NULL
; l
= l
->next
)
8138 const char *name
= l
->function_name
;
8140 /* Allow for some names to be NULL, ignore them. */
8144 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
8146 /* NOTE: We can assume slot != NULL here because xcalloc never returns
8161 update_breakpoint_locations (struct breakpoint
*b
,
8162 struct symtabs_and_lines sals
)
8166 struct bp_location
*existing_locations
= b
->loc
;
8168 /* If there's no new locations, and all existing locations
8169 are pending, don't do anything. This optimizes
8170 the common case where all locations are in the same
8171 shared library, that was unloaded. We'd like to
8172 retain the location, so that when the library
8173 is loaded again, we don't loose the enabled/disabled
8174 status of the individual locations. */
8175 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
8180 for (i
= 0; i
< sals
.nelts
; ++i
)
8182 struct bp_location
*new_loc
=
8183 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
8185 /* Reparse conditions, they might contain references to the
8187 if (b
->cond_string
!= NULL
)
8189 struct gdb_exception e
;
8192 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8194 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
8199 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
8200 b
->number
, e
.message
);
8201 new_loc
->enabled
= 0;
8205 if (b
->source_file
!= NULL
)
8206 xfree (b
->source_file
);
8207 if (sals
.sals
[i
].symtab
== NULL
)
8208 b
->source_file
= NULL
;
8210 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
8212 if (b
->line_number
== 0)
8213 b
->line_number
= sals
.sals
[i
].line
;
8216 /* Update locations of permanent breakpoints. */
8217 if (b
->enable_state
== bp_permanent
)
8218 make_breakpoint_permanent (b
);
8220 /* If possible, carry over 'disable' status from existing breakpoints. */
8222 struct bp_location
*e
= existing_locations
;
8223 /* If there are multiple breakpoints with the same function name,
8224 e.g. for inline functions, comparing function names won't work.
8225 Instead compare pc addresses; this is just a heuristic as things
8226 may have moved, but in practice it gives the correct answer
8227 often enough until a better solution is found. */
8228 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
8230 for (; e
; e
= e
->next
)
8232 if (!e
->enabled
&& e
->function_name
)
8234 struct bp_location
*l
= b
->loc
;
8235 if (have_ambiguous_names
)
8237 for (; l
; l
= l
->next
)
8238 if (e
->address
== l
->address
)
8246 for (; l
; l
= l
->next
)
8247 if (l
->function_name
8248 && strcmp (e
->function_name
, l
->function_name
) == 0)
8258 update_global_location_list (1);
8262 /* Reset a breakpoint given it's struct breakpoint * BINT.
8263 The value we return ends up being the return value from catch_errors.
8264 Unused in this case. */
8267 breakpoint_re_set_one (void *bint
)
8269 /* get past catch_errs */
8270 struct breakpoint
*b
= (struct breakpoint
*) bint
;
8274 int *not_found_ptr
= ¬_found
;
8275 struct symtabs_and_lines sals
= {};
8276 struct symtabs_and_lines expanded
;
8278 enum enable_state save_enable
;
8279 struct gdb_exception e
;
8280 struct cleanup
*cleanups
;
8285 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
8289 case bp_hardware_breakpoint
:
8291 /* Do not attempt to re-set breakpoints disabled during startup. */
8292 if (b
->enable_state
== bp_startup_disabled
)
8295 if (b
->addr_string
== NULL
)
8297 /* Anything without a string can't be re-set. */
8298 delete_breakpoint (b
);
8302 set_language (b
->language
);
8303 input_radix
= b
->input_radix
;
8305 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8307 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
8312 int not_found_and_ok
= 0;
8313 /* For pending breakpoints, it's expected that parsing
8314 will fail until the right shared library is loaded.
8315 User has already told to create pending breakpoints and
8316 don't need extra messages. If breakpoint is in bp_shlib_disabled
8317 state, then user already saw the message about that breakpoint
8318 being disabled, and don't want to see more errors. */
8320 && (b
->condition_not_parsed
8321 || (b
->loc
&& b
->loc
->shlib_disabled
)
8322 || b
->enable_state
== bp_disabled
))
8323 not_found_and_ok
= 1;
8325 if (!not_found_and_ok
)
8327 /* We surely don't want to warn about the same breakpoint
8328 10 times. One solution, implemented here, is disable
8329 the breakpoint on error. Another solution would be to
8330 have separate 'warning emitted' flag. Since this
8331 happens only when a binary has changed, I don't know
8332 which approach is better. */
8333 b
->enable_state
= bp_disabled
;
8334 throw_exception (e
);
8341 gdb_assert (sals
.nelts
== 1);
8342 resolve_sal_pc (&sals
.sals
[0]);
8343 if (b
->condition_not_parsed
&& s
&& s
[0])
8345 char *cond_string
= 0;
8349 find_condition_and_thread (s
, sals
.sals
[0].pc
,
8350 &cond_string
, &thread
, &task
);
8352 b
->cond_string
= cond_string
;
8355 b
->condition_not_parsed
= 0;
8357 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
8358 cleanups
= make_cleanup (xfree
, sals
.sals
);
8359 update_breakpoint_locations (b
, expanded
);
8360 do_cleanups (cleanups
);
8364 case bp_hardware_watchpoint
:
8365 case bp_read_watchpoint
:
8366 case bp_access_watchpoint
:
8367 /* Watchpoint can be either on expression using entirely global variables,
8368 or it can be on local variables.
8370 Watchpoints of the first kind are never auto-deleted, and even persist
8371 across program restarts. Since they can use variables from shared
8372 libraries, we need to reparse expression as libraries are loaded
8375 Watchpoints on local variables can also change meaning as result
8376 of solib event. For example, if a watchpoint uses both a local and
8377 a global variables in expression, it's a local watchpoint, but
8378 unloading of a shared library will make the expression invalid.
8379 This is not a very common use case, but we still re-evaluate
8380 expression, to avoid surprises to the user.
8382 Note that for local watchpoints, we re-evaluate it only if
8383 watchpoints frame id is still valid. If it's not, it means
8384 the watchpoint is out of scope and will be deleted soon. In fact,
8385 I'm not sure we'll ever be called in this case.
8387 If a local watchpoint's frame id is still valid, then
8388 b->exp_valid_block is likewise valid, and we can safely use it.
8390 Don't do anything about disabled watchpoints, since they will
8391 be reevaluated again when enabled. */
8392 update_watchpoint (b
, 1 /* reparse */);
8394 /* We needn't really do anything to reset these, since the mask
8395 that requests them is unaffected by e.g., new libraries being
8401 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
8403 /* Delete overlay event and longjmp master breakpoints; they will be
8404 reset later by breakpoint_re_set. */
8405 case bp_overlay_event
:
8406 case bp_longjmp_master
:
8407 delete_breakpoint (b
);
8410 /* This breakpoint is special, it's set up when the inferior
8411 starts and we really don't want to touch it. */
8412 case bp_shlib_event
:
8414 /* Like bp_shlib_event, this breakpoint type is special.
8415 Once it is set up, we do not want to touch it. */
8416 case bp_thread_event
:
8418 /* Keep temporary breakpoints, which can be encountered when we step
8419 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
8420 Otherwise these should have been blown away via the cleanup chain
8421 or by breakpoint_init_inferior when we rerun the executable. */
8424 case bp_watchpoint_scope
:
8426 case bp_step_resume
:
8428 case bp_longjmp_resume
:
8436 /* Re-set all breakpoints after symbols have been re-loaded. */
8438 breakpoint_re_set (void)
8440 struct breakpoint
*b
, *temp
;
8441 enum language save_language
;
8442 int save_input_radix
;
8444 save_language
= current_language
->la_language
;
8445 save_input_radix
= input_radix
;
8446 ALL_BREAKPOINTS_SAFE (b
, temp
)
8448 /* Format possible error msg */
8449 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
8451 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
8452 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
8453 do_cleanups (cleanups
);
8455 set_language (save_language
);
8456 input_radix
= save_input_radix
;
8458 jit_breakpoint_re_set ();
8460 create_overlay_event_breakpoint ("_ovly_debug_event");
8461 create_longjmp_master_breakpoint ("longjmp");
8462 create_longjmp_master_breakpoint ("_longjmp");
8463 create_longjmp_master_breakpoint ("siglongjmp");
8464 create_longjmp_master_breakpoint ("_siglongjmp");
8467 /* Reset the thread number of this breakpoint:
8469 - If the breakpoint is for all threads, leave it as-is.
8470 - Else, reset it to the current thread for inferior_ptid. */
8472 breakpoint_re_set_thread (struct breakpoint
*b
)
8474 if (b
->thread
!= -1)
8476 if (in_thread_list (inferior_ptid
))
8477 b
->thread
= pid_to_thread_id (inferior_ptid
);
8481 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8482 If from_tty is nonzero, it prints a message to that effect,
8483 which ends with a period (no newline). */
8486 set_ignore_count (int bptnum
, int count
, int from_tty
)
8488 struct breakpoint
*b
;
8494 if (b
->number
== bptnum
)
8496 b
->ignore_count
= count
;
8500 printf_filtered (_("Will stop next time breakpoint %d is reached."),
8502 else if (count
== 1)
8503 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
8506 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
8509 breakpoints_changed ();
8510 observer_notify_breakpoint_modified (b
->number
);
8514 error (_("No breakpoint number %d."), bptnum
);
8518 make_breakpoint_silent (struct breakpoint
*b
)
8520 /* Silence the breakpoint. */
8524 /* Command to set ignore-count of breakpoint N to COUNT. */
8527 ignore_command (char *args
, int from_tty
)
8533 error_no_arg (_("a breakpoint number"));
8535 num
= get_number (&p
);
8537 error (_("bad breakpoint number: '%s'"), args
);
8539 error (_("Second argument (specified ignore-count) is missing."));
8541 set_ignore_count (num
,
8542 longest_to_int (value_as_long (parse_and_eval (p
))),
8545 printf_filtered ("\n");
8548 /* Call FUNCTION on each of the breakpoints
8549 whose numbers are given in ARGS. */
8552 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
8557 struct breakpoint
*b
, *tmp
;
8561 error_no_arg (_("one or more breakpoint numbers"));
8568 num
= get_number_or_range (&p1
);
8571 warning (_("bad breakpoint number at or near '%s'"), p
);
8575 ALL_BREAKPOINTS_SAFE (b
, tmp
)
8576 if (b
->number
== num
)
8578 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
8581 if (related_breakpoint
)
8582 function (related_breakpoint
);
8586 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
8592 static struct bp_location
*
8593 find_location_by_number (char *number
)
8595 char *dot
= strchr (number
, '.');
8599 struct breakpoint
*b
;
8600 struct bp_location
*loc
;
8605 bp_num
= get_number_or_range (&p1
);
8607 error (_("Bad breakpoint number '%s'"), number
);
8610 if (b
->number
== bp_num
)
8615 if (!b
|| b
->number
!= bp_num
)
8616 error (_("Bad breakpoint number '%s'"), number
);
8619 loc_num
= get_number_or_range (&p1
);
8621 error (_("Bad breakpoint location number '%s'"), number
);
8625 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
8628 error (_("Bad breakpoint location number '%s'"), dot
+1);
8634 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8635 If from_tty is nonzero, it prints a message to that effect,
8636 which ends with a period (no newline). */
8639 disable_breakpoint (struct breakpoint
*bpt
)
8641 /* Never disable a watchpoint scope breakpoint; we want to
8642 hit them when we leave scope so we can delete both the
8643 watchpoint and its scope breakpoint at that time. */
8644 if (bpt
->type
== bp_watchpoint_scope
)
8647 /* You can't disable permanent breakpoints. */
8648 if (bpt
->enable_state
== bp_permanent
)
8651 bpt
->enable_state
= bp_disabled
;
8653 update_global_location_list (0);
8655 observer_notify_breakpoint_modified (bpt
->number
);
8659 disable_command (char *args
, int from_tty
)
8661 struct breakpoint
*bpt
;
8663 ALL_BREAKPOINTS (bpt
)
8667 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8673 case bp_hardware_breakpoint
:
8675 case bp_hardware_watchpoint
:
8676 case bp_read_watchpoint
:
8677 case bp_access_watchpoint
:
8678 disable_breakpoint (bpt
);
8682 else if (strchr (args
, '.'))
8684 struct bp_location
*loc
= find_location_by_number (args
);
8687 update_global_location_list (0);
8690 map_breakpoint_numbers (args
, disable_breakpoint
);
8694 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8696 int target_resources_ok
, other_type_used
;
8699 if (bpt
->type
== bp_hardware_breakpoint
)
8702 i
= hw_breakpoint_used_count ();
8703 target_resources_ok
=
8704 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8706 if (target_resources_ok
== 0)
8707 error (_("No hardware breakpoint support in the target."));
8708 else if (target_resources_ok
< 0)
8709 error (_("Hardware breakpoints used exceeds limit."));
8712 if (bpt
->type
== bp_watchpoint
8713 || bpt
->type
== bp_hardware_watchpoint
8714 || bpt
->type
== bp_read_watchpoint
8715 || bpt
->type
== bp_access_watchpoint
)
8717 struct gdb_exception e
;
8719 TRY_CATCH (e
, RETURN_MASK_ALL
)
8721 update_watchpoint (bpt
, 1 /* reparse */);
8725 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
8731 if (bpt
->enable_state
!= bp_permanent
)
8732 bpt
->enable_state
= bp_enabled
;
8733 bpt
->disposition
= disposition
;
8734 update_global_location_list (1);
8735 breakpoints_changed ();
8737 observer_notify_breakpoint_modified (bpt
->number
);
8742 enable_breakpoint (struct breakpoint
*bpt
)
8744 do_enable_breakpoint (bpt
, bpt
->disposition
);
8747 /* The enable command enables the specified breakpoints (or all defined
8748 breakpoints) so they once again become (or continue to be) effective
8749 in stopping the inferior. */
8752 enable_command (char *args
, int from_tty
)
8754 struct breakpoint
*bpt
;
8756 ALL_BREAKPOINTS (bpt
)
8760 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8766 case bp_hardware_breakpoint
:
8768 case bp_hardware_watchpoint
:
8769 case bp_read_watchpoint
:
8770 case bp_access_watchpoint
:
8771 enable_breakpoint (bpt
);
8775 else if (strchr (args
, '.'))
8777 struct bp_location
*loc
= find_location_by_number (args
);
8780 update_global_location_list (1);
8783 map_breakpoint_numbers (args
, enable_breakpoint
);
8787 enable_once_breakpoint (struct breakpoint
*bpt
)
8789 do_enable_breakpoint (bpt
, disp_disable
);
8793 enable_once_command (char *args
, int from_tty
)
8795 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8799 enable_delete_breakpoint (struct breakpoint
*bpt
)
8801 do_enable_breakpoint (bpt
, disp_del
);
8805 enable_delete_command (char *args
, int from_tty
)
8807 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8811 set_breakpoint_cmd (char *args
, int from_tty
)
8816 show_breakpoint_cmd (char *args
, int from_tty
)
8820 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8822 struct symtabs_and_lines
8823 decode_line_spec_1 (char *string
, int funfirstline
)
8825 struct symtabs_and_lines sals
;
8827 error (_("Empty line specification."));
8828 if (default_breakpoint_valid
)
8829 sals
= decode_line_1 (&string
, funfirstline
,
8830 default_breakpoint_symtab
,
8831 default_breakpoint_line
,
8832 (char ***) NULL
, NULL
);
8834 sals
= decode_line_1 (&string
, funfirstline
,
8835 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8837 error (_("Junk at end of line specification: %s"), string
);
8841 /* Create and insert a raw software breakpoint at PC. Return an
8842 identifier, which should be used to remove the breakpoint later.
8843 In general, places which call this should be using something on the
8844 breakpoint chain instead; this function should be eliminated
8848 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8850 struct bp_target_info
*bp_tgt
;
8852 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8853 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8855 bp_tgt
->placed_address
= pc
;
8856 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
8858 /* Could not insert the breakpoint. */
8866 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8869 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
8871 struct bp_target_info
*bp_tgt
= bp
;
8874 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
8880 /* One (or perhaps two) breakpoints used for software single stepping. */
8882 static void *single_step_breakpoints
[2];
8883 static struct gdbarch
*single_step_gdbarch
[2];
8885 /* Create and insert a breakpoint for software single step. */
8888 insert_single_step_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR next_pc
)
8892 if (single_step_breakpoints
[0] == NULL
)
8894 bpt_p
= &single_step_breakpoints
[0];
8895 single_step_gdbarch
[0] = gdbarch
;
8899 gdb_assert (single_step_breakpoints
[1] == NULL
);
8900 bpt_p
= &single_step_breakpoints
[1];
8901 single_step_gdbarch
[1] = gdbarch
;
8904 /* NOTE drow/2006-04-11: A future improvement to this function would be
8905 to only create the breakpoints once, and actually put them on the
8906 breakpoint chain. That would let us use set_raw_breakpoint. We could
8907 adjust the addresses each time they were needed. Doing this requires
8908 corresponding changes elsewhere where single step breakpoints are
8909 handled, however. So, for now, we use this. */
8911 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, next_pc
);
8913 error (_("Could not insert single-step breakpoint at %s"),
8914 paddress (gdbarch
, next_pc
));
8917 /* Remove and delete any breakpoints used for software single step. */
8920 remove_single_step_breakpoints (void)
8922 gdb_assert (single_step_breakpoints
[0] != NULL
);
8924 /* See insert_single_step_breakpoint for more about this deprecated
8926 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
8927 single_step_breakpoints
[0]);
8928 single_step_gdbarch
[0] = NULL
;
8929 single_step_breakpoints
[0] = NULL
;
8931 if (single_step_breakpoints
[1] != NULL
)
8933 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
8934 single_step_breakpoints
[1]);
8935 single_step_gdbarch
[1] = NULL
;
8936 single_step_breakpoints
[1] = NULL
;
8940 /* Check whether a software single-step breakpoint is inserted at PC. */
8943 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8947 for (i
= 0; i
< 2; i
++)
8949 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8950 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8957 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
8958 non-zero otherwise. */
8960 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
8962 if (syscall_catchpoint_p (bp
)
8963 && bp
->enable_state
!= bp_disabled
8964 && bp
->enable_state
!= bp_call_disabled
)
8971 catch_syscall_enabled (void)
8973 struct inferior
*inf
= current_inferior ();
8975 return inf
->total_syscalls_count
!= 0;
8979 catching_syscall_number (int syscall_number
)
8981 struct breakpoint
*bp
;
8983 ALL_BREAKPOINTS (bp
)
8984 if (is_syscall_catchpoint_enabled (bp
))
8986 if (bp
->syscalls_to_be_caught
)
8990 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
8992 if (syscall_number
== iter
)
9002 /* Complete syscall names. Used by "catch syscall". */
9004 catch_syscall_completer (struct cmd_list_element
*cmd
,
9005 char *text
, char *word
)
9007 const char **list
= get_syscall_names ();
9008 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
9011 /* Tracepoint-specific operations. */
9013 /* Set tracepoint count to NUM. */
9015 set_tracepoint_count (int num
)
9017 tracepoint_count
= num
;
9018 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
9022 trace_command (char *arg
, int from_tty
)
9024 break_command_really (get_current_arch (),
9026 NULL
, 0, 1 /* parse arg */,
9027 0 /* tempflag */, 0 /* hardwareflag */,
9029 0 /* Ignore count */,
9030 pending_break_support
,
9034 set_tracepoint_count (breakpoint_count
);
9037 /* Print information on tracepoint number TPNUM_EXP, or all if
9041 tracepoints_info (char *tpnum_exp
, int from_tty
)
9043 struct breakpoint
*b
;
9044 int tps_to_list
= 0;
9046 /* In the no-arguments case, say "No tracepoints" if none found. */
9059 ui_out_message (uiout
, 0, "No tracepoints.\n");
9064 /* Otherwise be the same as "info break". */
9065 breakpoints_info (tpnum_exp
, from_tty
);
9068 /* The 'enable trace' command enables tracepoints.
9069 Not supported by all targets. */
9071 enable_trace_command (char *args
, int from_tty
)
9073 enable_command (args
, from_tty
);
9076 /* The 'disable trace' command disables tracepoints.
9077 Not supported by all targets. */
9079 disable_trace_command (char *args
, int from_tty
)
9081 disable_command (args
, from_tty
);
9084 /* Remove a tracepoint (or all if no argument) */
9086 delete_trace_command (char *arg
, int from_tty
)
9088 struct breakpoint
*b
, *temp
;
9094 int breaks_to_delete
= 0;
9096 /* Delete all breakpoints if no argument.
9097 Do not delete internal or call-dummy breakpoints, these
9098 have to be deleted with an explicit breakpoint number argument. */
9103 breaks_to_delete
= 1;
9108 /* Ask user only if there are some breakpoints to delete. */
9110 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
9112 ALL_BREAKPOINTS_SAFE (b
, temp
)
9114 if (b
->type
== bp_tracepoint
9116 delete_breakpoint (b
);
9121 map_breakpoint_numbers (arg
, delete_breakpoint
);
9124 /* Set passcount for tracepoint.
9126 First command argument is passcount, second is tracepoint number.
9127 If tracepoint number omitted, apply to most recently defined.
9128 Also accepts special argument "all". */
9131 trace_pass_command (char *args
, int from_tty
)
9133 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
9137 if (args
== 0 || *args
== 0)
9138 error (_("passcount command requires an argument (count + optional TP num)"));
9140 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
9142 while (*args
&& isspace ((int) *args
))
9145 if (*args
&& strncasecmp (args
, "all", 3) == 0)
9147 args
+= 3; /* Skip special argument "all". */
9150 error (_("Junk at end of arguments."));
9153 t1
= get_tracepoint_by_number (&args
, 1, 1);
9159 ALL_TRACEPOINTS (t2
)
9160 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
9162 t2
->pass_count
= count
;
9163 observer_notify_tracepoint_modified (t2
->number
);
9165 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
9169 t1
= get_tracepoint_by_number (&args
, 1, 0);
9176 get_tracepoint (int num
)
9178 struct breakpoint
*t
;
9181 if (t
->number
== num
)
9187 /* Utility: parse a tracepoint number and look it up in the list.
9188 If MULTI_P is true, there might be a range of tracepoints in ARG.
9189 if OPTIONAL_P is true, then if the argument is missing, the most
9190 recent tracepoint (tracepoint_count) is returned. */
9192 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
9194 extern int tracepoint_count
;
9195 struct breakpoint
*t
;
9197 char *instring
= arg
== NULL
? NULL
: *arg
;
9199 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
9202 tpnum
= tracepoint_count
;
9204 error_no_arg (_("tracepoint number"));
9207 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
9211 if (instring
&& *instring
)
9212 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
9215 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
9220 if (t
->number
== tpnum
)
9225 /* FIXME: if we are in the middle of a range we don't want to give
9226 a message. The current interface to get_number_or_range doesn't
9227 allow us to discover this. */
9228 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
9232 /* save-tracepoints command */
9234 tracepoint_save_command (char *args
, int from_tty
)
9236 struct breakpoint
*tp
;
9238 struct action_line
*line
;
9240 char *i1
= " ", *i2
= " ";
9241 char *indent
, *actionline
, *pathname
;
9243 struct cleanup
*cleanup
;
9245 if (args
== 0 || *args
== 0)
9246 error (_("Argument required (file name in which to save tracepoints)"));
9248 /* See if we have anything to save. */
9249 ALL_TRACEPOINTS (tp
)
9256 warning (_("save-tracepoints: no tracepoints to save."));
9260 pathname
= tilde_expand (args
);
9261 cleanup
= make_cleanup (xfree
, pathname
);
9262 fp
= fopen (pathname
, "w");
9264 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
9265 args
, safe_strerror (errno
));
9266 make_cleanup_fclose (fp
);
9268 ALL_TRACEPOINTS (tp
)
9270 if (tp
->addr_string
)
9271 fprintf (fp
, "trace %s\n", tp
->addr_string
);
9274 sprintf_vma (tmp
, tp
->loc
->address
);
9275 fprintf (fp
, "trace *0x%s\n", tmp
);
9279 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
9283 fprintf (fp
, " actions\n");
9285 for (line
= tp
->actions
; line
; line
= line
->next
)
9287 struct cmd_list_element
*cmd
;
9289 QUIT
; /* allow user to bail out with ^C */
9290 actionline
= line
->action
;
9291 while (isspace ((int) *actionline
))
9294 fprintf (fp
, "%s%s\n", indent
, actionline
);
9295 if (*actionline
!= '#') /* skip for comment lines */
9297 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
9299 error (_("Bad action list item: %s"), actionline
);
9300 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
9302 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
9308 do_cleanups (cleanup
);
9310 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
9314 /* Create a vector of all tracepoints. */
9319 VEC(breakpoint_p
) *tp_vec
= 0;
9320 struct breakpoint
*tp
;
9322 ALL_TRACEPOINTS (tp
)
9324 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
9331 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
9332 It is defined as a macro to prevent duplication.
9333 COMMAND should be a string constant containing the name of the command. */
9334 #define BREAK_ARGS_HELP(command) \
9335 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
9336 LOCATION may be a line number, function name, or \"*\" and an address.\n\
9337 If a line number is specified, break at start of code for that line.\n\
9338 If a function is specified, break at start of code for that function.\n\
9339 If an address is specified, break at that exact address.\n\
9340 With no LOCATION, uses current execution address of selected stack frame.\n\
9341 This is useful for breaking on return to a stack frame.\n\
9343 THREADNUM is the number from \"info threads\".\n\
9344 CONDITION is a boolean expression.\n\
9346 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
9348 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
9350 /* List of subcommands for "catch". */
9351 static struct cmd_list_element
*catch_cmdlist
;
9353 /* List of subcommands for "tcatch". */
9354 static struct cmd_list_element
*tcatch_cmdlist
;
9356 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
9357 lists, and pass some additional user data to the command function. */
9359 add_catch_command (char *name
, char *docstring
,
9360 void (*sfunc
) (char *args
, int from_tty
,
9361 struct cmd_list_element
*command
),
9362 char **(*completer
) (struct cmd_list_element
*cmd
,
9363 char *text
, char *word
),
9364 void *user_data_catch
,
9365 void *user_data_tcatch
)
9367 struct cmd_list_element
*command
;
9369 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
9371 set_cmd_sfunc (command
, sfunc
);
9372 set_cmd_context (command
, user_data_catch
);
9373 set_cmd_completer (command
, completer
);
9375 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
9377 set_cmd_sfunc (command
, sfunc
);
9378 set_cmd_context (command
, user_data_tcatch
);
9379 set_cmd_completer (command
, completer
);
9383 _initialize_breakpoint (void)
9385 static struct cmd_list_element
*breakpoint_set_cmdlist
;
9386 static struct cmd_list_element
*breakpoint_show_cmdlist
;
9387 struct cmd_list_element
*c
;
9389 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
9391 breakpoint_chain
= 0;
9392 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
9393 before a breakpoint is set. */
9394 breakpoint_count
= 0;
9396 tracepoint_count
= 0;
9398 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
9399 Set ignore-count of breakpoint number N to COUNT.\n\
9400 Usage is `ignore N COUNT'."));
9402 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
9404 add_com ("commands", class_breakpoint
, commands_command
, _("\
9405 Set commands to be executed when a breakpoint is hit.\n\
9406 Give breakpoint number as argument after \"commands\".\n\
9407 With no argument, the targeted breakpoint is the last one set.\n\
9408 The commands themselves follow starting on the next line.\n\
9409 Type a line containing \"end\" to indicate the end of them.\n\
9410 Give \"silent\" as the first line to make the breakpoint silent;\n\
9411 then no output is printed when it is hit, except what the commands print."));
9413 add_com ("condition", class_breakpoint
, condition_command
, _("\
9414 Specify breakpoint number N to break only if COND is true.\n\
9415 Usage is `condition N COND', where N is an integer and COND is an\n\
9416 expression to be evaluated whenever breakpoint N is reached."));
9418 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
9419 Set a temporary breakpoint.\n\
9420 Like \"break\" except the breakpoint is only temporary,\n\
9421 so it will be deleted when hit. Equivalent to \"break\" followed\n\
9422 by using \"enable delete\" on the breakpoint number.\n\
9424 BREAK_ARGS_HELP ("tbreak")));
9425 set_cmd_completer (c
, location_completer
);
9427 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
9428 Set a hardware assisted breakpoint.\n\
9429 Like \"break\" except the breakpoint requires hardware support,\n\
9430 some target hardware may not have this support.\n\
9432 BREAK_ARGS_HELP ("hbreak")));
9433 set_cmd_completer (c
, location_completer
);
9435 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
9436 Set a temporary hardware assisted breakpoint.\n\
9437 Like \"hbreak\" except the breakpoint is only temporary,\n\
9438 so it will be deleted when hit.\n\
9440 BREAK_ARGS_HELP ("thbreak")));
9441 set_cmd_completer (c
, location_completer
);
9443 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
9444 Enable some breakpoints.\n\
9445 Give breakpoint numbers (separated by spaces) as arguments.\n\
9446 With no subcommand, breakpoints are enabled until you command otherwise.\n\
9447 This is used to cancel the effect of the \"disable\" command.\n\
9448 With a subcommand you can enable temporarily."),
9449 &enablelist
, "enable ", 1, &cmdlist
);
9451 add_com ("ab", class_breakpoint
, enable_command
, _("\
9452 Enable some breakpoints.\n\
9453 Give breakpoint numbers (separated by spaces) as arguments.\n\
9454 With no subcommand, breakpoints are enabled until you command otherwise.\n\
9455 This is used to cancel the effect of the \"disable\" command.\n\
9456 With a subcommand you can enable temporarily."));
9458 add_com_alias ("en", "enable", class_breakpoint
, 1);
9460 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
9461 Enable some breakpoints.\n\
9462 Give breakpoint numbers (separated by spaces) as arguments.\n\
9463 This is used to cancel the effect of the \"disable\" command.\n\
9464 May be abbreviated to simply \"enable\".\n"),
9465 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
9467 add_cmd ("once", no_class
, enable_once_command
, _("\
9468 Enable breakpoints for one hit. Give breakpoint numbers.\n\
9469 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
9472 add_cmd ("delete", no_class
, enable_delete_command
, _("\
9473 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
9474 If a breakpoint is hit while enabled in this fashion, it is deleted."),
9477 add_cmd ("delete", no_class
, enable_delete_command
, _("\
9478 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
9479 If a breakpoint is hit while enabled in this fashion, it is deleted."),
9482 add_cmd ("once", no_class
, enable_once_command
, _("\
9483 Enable breakpoints for one hit. Give breakpoint numbers.\n\
9484 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
9487 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
9488 Disable some breakpoints.\n\
9489 Arguments are breakpoint numbers with spaces in between.\n\
9490 To disable all breakpoints, give no argument.\n\
9491 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
9492 &disablelist
, "disable ", 1, &cmdlist
);
9493 add_com_alias ("dis", "disable", class_breakpoint
, 1);
9494 add_com_alias ("disa", "disable", class_breakpoint
, 1);
9496 add_com ("sb", class_breakpoint
, disable_command
, _("\
9497 Disable some breakpoints.\n\
9498 Arguments are breakpoint numbers with spaces in between.\n\
9499 To disable all breakpoints, give no argument.\n\
9500 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
9502 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
9503 Disable some breakpoints.\n\
9504 Arguments are breakpoint numbers with spaces in between.\n\
9505 To disable all breakpoints, give no argument.\n\
9506 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
9507 This command may be abbreviated \"disable\"."),
9510 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
9511 Delete some breakpoints or auto-display expressions.\n\
9512 Arguments are breakpoint numbers with spaces in between.\n\
9513 To delete all breakpoints, give no argument.\n\
9515 Also a prefix command for deletion of other GDB objects.\n\
9516 The \"unset\" command is also an alias for \"delete\"."),
9517 &deletelist
, "delete ", 1, &cmdlist
);
9518 add_com_alias ("d", "delete", class_breakpoint
, 1);
9519 add_com_alias ("del", "delete", class_breakpoint
, 1);
9521 add_com ("db", class_breakpoint
, delete_command
, _("\
9522 Delete some breakpoints.\n\
9523 Arguments are breakpoint numbers with spaces in between.\n\
9524 To delete all breakpoints, give no argument.\n"));
9526 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
9527 Delete some breakpoints or auto-display expressions.\n\
9528 Arguments are breakpoint numbers with spaces in between.\n\
9529 To delete all breakpoints, give no argument.\n\
9530 This command may be abbreviated \"delete\"."),
9533 add_com ("clear", class_breakpoint
, clear_command
, _("\
9534 Clear breakpoint at specified line or function.\n\
9535 Argument may be line number, function name, or \"*\" and an address.\n\
9536 If line number is specified, all breakpoints in that line are cleared.\n\
9537 If function is specified, breakpoints at beginning of function are cleared.\n\
9538 If an address is specified, breakpoints at that address are cleared.\n\
9540 With no argument, clears all breakpoints in the line that the selected frame\n\
9543 See also the \"delete\" command which clears breakpoints by number."));
9545 c
= add_com ("break", class_breakpoint
, break_command
, _("\
9546 Set breakpoint at specified line or function.\n"
9547 BREAK_ARGS_HELP ("break")));
9548 set_cmd_completer (c
, location_completer
);
9550 add_com_alias ("b", "break", class_run
, 1);
9551 add_com_alias ("br", "break", class_run
, 1);
9552 add_com_alias ("bre", "break", class_run
, 1);
9553 add_com_alias ("brea", "break", class_run
, 1);
9556 add_com_alias ("ba", "break", class_breakpoint
, 1);
9560 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
9561 Break in function/address or break at a line in the current file."),
9562 &stoplist
, "stop ", 1, &cmdlist
);
9563 add_cmd ("in", class_breakpoint
, stopin_command
,
9564 _("Break in function or address."), &stoplist
);
9565 add_cmd ("at", class_breakpoint
, stopat_command
,
9566 _("Break at a line in the current file."), &stoplist
);
9567 add_com ("status", class_info
, breakpoints_info
, _("\
9568 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9569 The \"Type\" column indicates one of:\n\
9570 \tbreakpoint - normal breakpoint\n\
9571 \twatchpoint - watchpoint\n\
9572 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9573 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9574 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9575 address and file/line number respectively.\n\
9577 Convenience variable \"$_\" and default examine address for \"x\"\n\
9578 are set to the address of the last breakpoint listed unless the command\n\
9579 is prefixed with \"server \".\n\n\
9580 Convenience variable \"$bpnum\" contains the number of the last\n\
9584 add_info ("breakpoints", breakpoints_info
, _("\
9585 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9586 The \"Type\" column indicates one of:\n\
9587 \tbreakpoint - normal breakpoint\n\
9588 \twatchpoint - watchpoint\n\
9589 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9590 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9591 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9592 address and file/line number respectively.\n\
9594 Convenience variable \"$_\" and default examine address for \"x\"\n\
9595 are set to the address of the last breakpoint listed unless the command\n\
9596 is prefixed with \"server \".\n\n\
9597 Convenience variable \"$bpnum\" contains the number of the last\n\
9601 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
9602 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9603 The \"Type\" column indicates one of:\n\
9604 \tbreakpoint - normal breakpoint\n\
9605 \twatchpoint - watchpoint\n\
9606 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9607 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9608 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9609 address and file/line number respectively.\n\
9611 Convenience variable \"$_\" and default examine address for \"x\"\n\
9612 are set to the address of the last breakpoint listed unless the command\n\
9613 is prefixed with \"server \".\n\n\
9614 Convenience variable \"$bpnum\" contains the number of the last\n\
9617 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
9618 Status of all breakpoints, or breakpoint number NUMBER.\n\
9619 The \"Type\" column indicates one of:\n\
9620 \tbreakpoint - normal breakpoint\n\
9621 \twatchpoint - watchpoint\n\
9622 \tlongjmp - internal breakpoint used to step through longjmp()\n\
9623 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
9624 \tuntil - internal breakpoint used by the \"until\" command\n\
9625 \tfinish - internal breakpoint used by the \"finish\" command\n\
9626 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9627 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9628 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9629 address and file/line number respectively.\n\
9631 Convenience variable \"$_\" and default examine address for \"x\"\n\
9632 are set to the address of the last breakpoint listed unless the command\n\
9633 is prefixed with \"server \".\n\n\
9634 Convenience variable \"$bpnum\" contains the number of the last\n\
9636 &maintenanceinfolist
);
9638 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
9639 Set catchpoints to catch events."),
9640 &catch_cmdlist
, "catch ",
9641 0/*allow-unknown*/, &cmdlist
);
9643 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
9644 Set temporary catchpoints to catch events."),
9645 &tcatch_cmdlist
, "tcatch ",
9646 0/*allow-unknown*/, &cmdlist
);
9648 /* Add catch and tcatch sub-commands. */
9649 add_catch_command ("catch", _("\
9650 Catch an exception, when caught.\n\
9651 With an argument, catch only exceptions with the given name."),
9652 catch_catch_command
,
9656 add_catch_command ("throw", _("\
9657 Catch an exception, when thrown.\n\
9658 With an argument, catch only exceptions with the given name."),
9659 catch_throw_command
,
9663 add_catch_command ("fork", _("Catch calls to fork."),
9664 catch_fork_command_1
,
9666 (void *) (uintptr_t) catch_fork_permanent
,
9667 (void *) (uintptr_t) catch_fork_temporary
);
9668 add_catch_command ("vfork", _("Catch calls to vfork."),
9669 catch_fork_command_1
,
9671 (void *) (uintptr_t) catch_vfork_permanent
,
9672 (void *) (uintptr_t) catch_vfork_temporary
);
9673 add_catch_command ("exec", _("Catch calls to exec."),
9674 catch_exec_command_1
,
9678 add_catch_command ("syscall", _("\
9679 Catch system calls by their names and/or numbers.\n\
9680 Arguments say which system calls to catch. If no arguments\n\
9681 are given, every system call will be caught.\n\
9682 Arguments, if given, should be one or more system call names\n\
9683 (if your system supports that), or system call numbers."),
9684 catch_syscall_command_1
,
9685 catch_syscall_completer
,
9688 add_catch_command ("exception", _("\
9689 Catch Ada exceptions, when raised.\n\
9690 With an argument, catch only exceptions with the given name."),
9691 catch_ada_exception_command
,
9695 add_catch_command ("assert", _("\
9696 Catch failed Ada assertions, when raised.\n\
9697 With an argument, catch only exceptions with the given name."),
9698 catch_assert_command
,
9703 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
9704 Set a watchpoint for an expression.\n\
9705 A watchpoint stops execution of your program whenever the value of\n\
9706 an expression changes."));
9707 set_cmd_completer (c
, expression_completer
);
9709 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
9710 Set a read watchpoint for an expression.\n\
9711 A watchpoint stops execution of your program whenever the value of\n\
9712 an expression is read."));
9713 set_cmd_completer (c
, expression_completer
);
9715 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
9716 Set a watchpoint for an expression.\n\
9717 A watchpoint stops execution of your program whenever the value of\n\
9718 an expression is either read or written."));
9719 set_cmd_completer (c
, expression_completer
);
9721 add_info ("watchpoints", breakpoints_info
,
9722 _("Synonym for ``info breakpoints''."));
9725 /* XXX: cagney/2005-02-23: This should be a boolean, and should
9726 respond to changes - contrary to the description. */
9727 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
9728 &can_use_hw_watchpoints
, _("\
9729 Set debugger's willingness to use watchpoint hardware."), _("\
9730 Show debugger's willingness to use watchpoint hardware."), _("\
9731 If zero, gdb will not use hardware for new watchpoints, even if\n\
9732 such is available. (However, any hardware watchpoints that were\n\
9733 created before setting this to nonzero, will continue to use watchpoint\n\
9736 show_can_use_hw_watchpoints
,
9737 &setlist
, &showlist
);
9739 can_use_hw_watchpoints
= 1;
9741 /* Tracepoint manipulation commands. */
9743 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
9744 Set a tracepoint at specified line or function.\n\
9746 BREAK_ARGS_HELP ("trace") "\n\
9747 Do \"help tracepoints\" for info on other tracepoint commands."));
9748 set_cmd_completer (c
, location_completer
);
9750 add_com_alias ("tp", "trace", class_alias
, 0);
9751 add_com_alias ("tr", "trace", class_alias
, 1);
9752 add_com_alias ("tra", "trace", class_alias
, 1);
9753 add_com_alias ("trac", "trace", class_alias
, 1);
9755 add_info ("tracepoints", tracepoints_info
, _("\
9756 Status of tracepoints, or tracepoint number NUMBER.\n\
9757 Convenience variable \"$tpnum\" contains the number of the\n\
9758 last tracepoint set."));
9760 add_info_alias ("tp", "tracepoints", 1);
9762 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
9763 Delete specified tracepoints.\n\
9764 Arguments are tracepoint numbers, separated by spaces.\n\
9765 No argument means delete all tracepoints."),
9768 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
9769 Disable specified tracepoints.\n\
9770 Arguments are tracepoint numbers, separated by spaces.\n\
9771 No argument means disable all tracepoints."),
9773 deprecate_cmd (c
, "disable");
9775 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
9776 Enable specified tracepoints.\n\
9777 Arguments are tracepoint numbers, separated by spaces.\n\
9778 No argument means enable all tracepoints."),
9780 deprecate_cmd (c
, "enable");
9782 add_com ("passcount", class_trace
, trace_pass_command
, _("\
9783 Set the passcount for a tracepoint.\n\
9784 The trace will end when the tracepoint has been passed 'count' times.\n\
9785 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
9786 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
9788 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
9789 Save current tracepoint definitions as a script.\n\
9790 Use the 'source' command in another debug session to restore them."));
9791 set_cmd_completer (c
, filename_completer
);
9793 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
9794 Breakpoint specific settings\n\
9795 Configure various breakpoint-specific variables such as\n\
9796 pending breakpoint behavior"),
9797 &breakpoint_set_cmdlist
, "set breakpoint ",
9798 0/*allow-unknown*/, &setlist
);
9799 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
9800 Breakpoint specific settings\n\
9801 Configure various breakpoint-specific variables such as\n\
9802 pending breakpoint behavior"),
9803 &breakpoint_show_cmdlist
, "show breakpoint ",
9804 0/*allow-unknown*/, &showlist
);
9806 add_setshow_auto_boolean_cmd ("pending", no_class
,
9807 &pending_break_support
, _("\
9808 Set debugger's behavior regarding pending breakpoints."), _("\
9809 Show debugger's behavior regarding pending breakpoints."), _("\
9810 If on, an unrecognized breakpoint location will cause gdb to create a\n\
9811 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9812 an error. If auto, an unrecognized breakpoint location results in a\n\
9813 user-query to see if a pending breakpoint should be created."),
9815 show_pending_break_support
,
9816 &breakpoint_set_cmdlist
,
9817 &breakpoint_show_cmdlist
);
9819 pending_break_support
= AUTO_BOOLEAN_AUTO
;
9821 add_setshow_boolean_cmd ("auto-hw", no_class
,
9822 &automatic_hardware_breakpoints
, _("\
9823 Set automatic usage of hardware breakpoints."), _("\
9824 Show automatic usage of hardware breakpoints."), _("\
9825 If set, the debugger will automatically use hardware breakpoints for\n\
9826 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9827 a warning will be emitted for such breakpoints."),
9829 show_automatic_hardware_breakpoints
,
9830 &breakpoint_set_cmdlist
,
9831 &breakpoint_show_cmdlist
);
9833 add_setshow_enum_cmd ("always-inserted", class_support
,
9834 always_inserted_enums
, &always_inserted_mode
, _("\
9835 Set mode for inserting breakpoints."), _("\
9836 Show mode for inserting breakpoints."), _("\
9837 When this mode is off, breakpoints are inserted in inferior when it is\n\
9838 resumed, and removed when execution stops. When this mode is on,\n\
9839 breakpoints are inserted immediately and removed only when the user\n\
9840 deletes the breakpoint. When this mode is auto (which is the default),\n\
9841 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9842 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9843 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9844 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9846 &show_always_inserted_mode
,
9847 &breakpoint_set_cmdlist
,
9848 &breakpoint_show_cmdlist
);
9850 automatic_hardware_breakpoints
= 1;
9852 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);