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, 2010 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 breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
117 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
121 static void describe_other_breakpoints (struct gdbarch
*,
122 struct program_space
*, CORE_ADDR
,
123 struct obj_section
*, int);
125 static int breakpoint_address_match (struct address_space
*aspace1
,
127 struct address_space
*aspace2
,
130 static int watchpoint_locations_match (struct bp_location
*loc1
,
131 struct bp_location
*loc2
);
133 static void breakpoints_info (char *, int);
135 static void breakpoint_1 (int, int);
137 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
139 static int breakpoint_cond_eval (void *);
141 static void cleanup_executing_breakpoints (void *);
143 static void commands_command (char *, int);
145 static void condition_command (char *, int);
147 static int get_number_trailer (char **, int);
149 void set_breakpoint_count (int);
158 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
159 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
161 static enum print_stop_action
print_it_typical (bpstat
);
163 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
165 static int watchpoint_check (void *);
167 static void maintenance_info_breakpoints (char *, int);
169 static int hw_breakpoint_used_count (void);
171 static int hw_watchpoint_used_count (enum bptype
, int *);
173 static void hbreak_command (char *, int);
175 static void thbreak_command (char *, int);
177 static void watch_command_1 (char *, int, int);
179 static void rwatch_command (char *, int);
181 static void awatch_command (char *, int);
183 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
185 static void stop_command (char *arg
, int from_tty
);
187 static void stopin_command (char *arg
, int from_tty
);
189 static void stopat_command (char *arg
, int from_tty
);
191 static char *ep_parse_optional_if_clause (char **arg
);
193 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
194 char *arg
, int tempflag
, int from_tty
);
196 static void tcatch_command (char *arg
, int from_tty
);
198 static void ep_skip_leading_whitespace (char **s
);
200 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
203 static void free_bp_location (struct bp_location
*loc
);
205 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
207 static void update_global_location_list (int);
209 static void update_global_location_list_nothrow (int);
211 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
213 static int is_watchpoint (struct breakpoint
*bpt
);
215 static void insert_breakpoint_locations (void);
217 static int syscall_catchpoint_p (struct breakpoint
*b
);
219 static void tracepoints_info (char *, int);
221 static void delete_trace_command (char *, int);
223 static void enable_trace_command (char *, int);
225 static void disable_trace_command (char *, int);
227 static void trace_pass_command (char *, int);
229 static void skip_prologue_sal (struct symtab_and_line
*sal
);
232 /* Flag indicating that a command has proceeded the inferior past the
233 current breakpoint. */
235 static int breakpoint_proceeded
;
238 bpdisp_text (enum bpdisp disp
)
240 /* NOTE: the following values are a part of MI protocol and represent
241 values of 'disp' field returned when inferior stops at a breakpoint. */
242 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
243 return bpdisps
[(int) disp
];
246 /* Prototypes for exported functions. */
247 /* If FALSE, gdb will not use hardware support for watchpoints, even
248 if such is available. */
249 static int can_use_hw_watchpoints
;
252 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
253 struct cmd_list_element
*c
,
256 fprintf_filtered (file
, _("\
257 Debugger's willingness to use watchpoint hardware is %s.\n"),
261 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
262 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
263 for unrecognized breakpoint locations.
264 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
265 static enum auto_boolean pending_break_support
;
267 show_pending_break_support (struct ui_file
*file
, int from_tty
,
268 struct cmd_list_element
*c
,
271 fprintf_filtered (file
, _("\
272 Debugger's behavior regarding pending breakpoints is %s.\n"),
276 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
277 set with "break" but falling in read-only memory.
278 If 0, gdb will warn about such breakpoints, but won't automatically
279 use hardware breakpoints. */
280 static int automatic_hardware_breakpoints
;
282 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
283 struct cmd_list_element
*c
,
286 fprintf_filtered (file
, _("\
287 Automatic usage of hardware breakpoints is %s.\n"),
291 /* If on, gdb will keep breakpoints inserted even as inferior is
292 stopped, and immediately insert any new breakpoints. If off, gdb
293 will insert breakpoints into inferior only when resuming it, and
294 will remove breakpoints upon stop. If auto, GDB will behave as ON
295 if in non-stop mode, and as OFF if all-stop mode.*/
297 static const char always_inserted_auto
[] = "auto";
298 static const char always_inserted_on
[] = "on";
299 static const char always_inserted_off
[] = "off";
300 static const char *always_inserted_enums
[] = {
301 always_inserted_auto
,
306 static const char *always_inserted_mode
= always_inserted_auto
;
308 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
309 struct cmd_list_element
*c
, const char *value
)
311 if (always_inserted_mode
== always_inserted_auto
)
312 fprintf_filtered (file
, _("\
313 Always inserted breakpoint mode is %s (currently %s).\n"),
315 breakpoints_always_inserted_mode () ? "on" : "off");
317 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
321 breakpoints_always_inserted_mode (void)
323 return (always_inserted_mode
== always_inserted_on
324 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
327 void _initialize_breakpoint (void);
329 /* Are we executing breakpoint commands? */
330 static int executing_breakpoint_commands
;
332 /* Are overlay event breakpoints enabled? */
333 static int overlay_events_enabled
;
335 /* Walk the following statement or block through all breakpoints.
336 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
339 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
341 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
342 for (B = breakpoint_chain; \
343 B ? (TMP=B->next, 1): 0; \
346 /* Similar iterator for the low-level breakpoints. SAFE variant is not
347 provided so update_global_location_list must not be called while executing
348 the block of ALL_BP_LOCATIONS. */
350 #define ALL_BP_LOCATIONS(B,BP_TMP) \
351 for (BP_TMP = bp_location; \
352 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
355 /* Iterator for tracepoints only. */
357 #define ALL_TRACEPOINTS(B) \
358 for (B = breakpoint_chain; B; B = B->next) \
359 if (tracepoint_type (B))
361 /* Chains of all breakpoints defined. */
363 struct breakpoint
*breakpoint_chain
;
365 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
367 static struct bp_location
**bp_location
;
369 /* Number of elements of BP_LOCATION. */
371 static unsigned bp_location_count
;
373 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
374 for the current elements of BP_LOCATION which get a valid result from
375 bp_location_has_shadow. You can use it for roughly limiting the subrange of
376 BP_LOCATION to scan for shadow bytes for an address you need to read. */
378 static CORE_ADDR bp_location_placed_address_before_address_max
;
380 /* Maximum offset plus alignment between
381 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
382 the current elements of BP_LOCATION which get a valid result from
383 bp_location_has_shadow. You can use it for roughly limiting the subrange of
384 BP_LOCATION to scan for shadow bytes for an address you need to read. */
386 static CORE_ADDR bp_location_shadow_len_after_address_max
;
388 /* The locations that no longer correspond to any breakpoint,
389 unlinked from bp_location array, but for which a hit
390 may still be reported by a target. */
391 VEC(bp_location_p
) *moribund_locations
= NULL
;
393 /* Number of last breakpoint made. */
395 int breakpoint_count
;
397 /* Number of last tracepoint made. */
399 int tracepoint_count
;
401 /* Return whether a breakpoint is an active enabled breakpoint. */
403 breakpoint_enabled (struct breakpoint
*b
)
405 return (b
->enable_state
== bp_enabled
);
408 /* Set breakpoint count to NUM. */
411 set_breakpoint_count (int num
)
413 breakpoint_count
= num
;
414 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
417 /* Used in run_command to zero the hit count when a new run starts. */
420 clear_breakpoint_hit_counts (void)
422 struct breakpoint
*b
;
428 /* Encapsulate tests for different types of tracepoints. */
431 tracepoint_type (const struct breakpoint
*b
)
433 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
436 /* Default address, symtab and line to put a breakpoint at
437 for "break" command with no arg.
438 if default_breakpoint_valid is zero, the other three are
439 not valid, and "break" with no arg is an error.
441 This set by print_stack_frame, which calls set_default_breakpoint. */
443 int default_breakpoint_valid
;
444 CORE_ADDR default_breakpoint_address
;
445 struct symtab
*default_breakpoint_symtab
;
446 int default_breakpoint_line
;
447 struct program_space
*default_breakpoint_pspace
;
450 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
451 Advance *PP after the string and any trailing whitespace.
453 Currently the string can either be a number or "$" followed by the name
454 of a convenience variable. Making it an expression wouldn't work well
455 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
457 If the string is a NULL pointer, that denotes the last breakpoint.
459 TRAILER is a character which can be found after the number; most
460 commonly this is `-'. If you don't want a trailer, use \0. */
462 get_number_trailer (char **pp
, int trailer
)
464 int retval
= 0; /* default */
468 /* Empty line means refer to the last breakpoint. */
469 return breakpoint_count
;
472 /* Make a copy of the name, so we can null-terminate it
473 to pass to lookup_internalvar(). */
478 while (isalnum (*p
) || *p
== '_')
480 varname
= (char *) alloca (p
- start
+ 1);
481 strncpy (varname
, start
, p
- start
);
482 varname
[p
- start
] = '\0';
483 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
487 printf_filtered (_("Convenience variable must have integer value.\n"));
495 while (*p
>= '0' && *p
<= '9')
498 /* There is no number here. (e.g. "cond a == b"). */
500 /* Skip non-numeric token */
501 while (*p
&& !isspace((int) *p
))
503 /* Return zero, which caller must interpret as error. */
509 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
511 /* Trailing junk: return 0 and let caller print error msg. */
512 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
523 /* Like get_number_trailer, but don't allow a trailer. */
525 get_number (char **pp
)
527 return get_number_trailer (pp
, '\0');
530 /* Parse a number or a range.
531 * A number will be of the form handled by get_number.
532 * A range will be of the form <number1> - <number2>, and
533 * will represent all the integers between number1 and number2,
536 * While processing a range, this fuction is called iteratively;
537 * At each call it will return the next value in the range.
539 * At the beginning of parsing a range, the char pointer PP will
540 * be advanced past <number1> and left pointing at the '-' token.
541 * Subsequent calls will not advance the pointer until the range
542 * is completed. The call that completes the range will advance
543 * pointer PP past <number2>.
547 get_number_or_range (char **pp
)
549 static int last_retval
, end_value
;
550 static char *end_ptr
;
551 static int in_range
= 0;
555 /* Default case: pp is pointing either to a solo number,
556 or to the first number of a range. */
557 last_retval
= get_number_trailer (pp
, '-');
562 /* This is the start of a range (<number1> - <number2>).
563 Skip the '-', parse and remember the second number,
564 and also remember the end of the final token. */
568 while (isspace ((int) *end_ptr
))
569 end_ptr
++; /* skip white space */
570 end_value
= get_number (temp
);
571 if (end_value
< last_retval
)
573 error (_("inverted range"));
575 else if (end_value
== last_retval
)
577 /* degenerate range (number1 == number2). Advance the
578 token pointer so that the range will be treated as a
587 error (_("negative value"));
590 /* pp points to the '-' that betokens a range. All
591 number-parsing has already been done. Return the next
592 integer value (one greater than the saved previous value).
593 Do not advance the token pointer 'pp' until the end of range
596 if (++last_retval
== end_value
)
598 /* End of range reached; advance token pointer. */
606 /* Return the breakpoint with the specified number, or NULL
607 if the number does not refer to an existing breakpoint. */
610 get_breakpoint (int num
)
612 struct breakpoint
*b
;
615 if (b
->number
== num
)
622 /* condition N EXP -- set break condition of breakpoint N to EXP. */
625 condition_command (char *arg
, int from_tty
)
627 struct breakpoint
*b
;
632 error_no_arg (_("breakpoint number"));
635 bnum
= get_number (&p
);
637 error (_("Bad breakpoint argument: '%s'"), arg
);
640 if (b
->number
== bnum
)
642 struct bp_location
*loc
= b
->loc
;
643 for (; loc
; loc
= loc
->next
)
648 xfree (b
->cond_string
);
649 b
->cond_string
= NULL
;
656 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
661 /* I don't know if it matters whether this is the string the user
662 typed in or the decompiled expression. */
663 b
->cond_string
= xstrdup (arg
);
664 b
->condition_not_parsed
= 0;
666 if (is_watchpoint (b
))
668 innermost_block
= NULL
;
670 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
672 error (_("Junk at end of expression"));
673 b
->cond_exp_valid_block
= innermost_block
;
677 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
681 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
683 error (_("Junk at end of expression"));
687 breakpoints_changed ();
688 observer_notify_breakpoint_modified (b
->number
);
692 error (_("No breakpoint number %d."), bnum
);
695 /* Set the command list of B to COMMANDS. */
698 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
700 free_command_lines (&b
->commands
);
701 b
->commands
= commands
;
702 breakpoints_changed ();
703 observer_notify_breakpoint_modified (b
->number
);
707 commands_command (char *arg
, int from_tty
)
709 struct breakpoint
*b
;
712 struct command_line
*l
;
714 /* If we allowed this, we would have problems with when to
715 free the storage, if we change the commands currently
718 if (executing_breakpoint_commands
)
719 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
722 bnum
= get_number (&p
);
725 error (_("Unexpected extra arguments following breakpoint number."));
728 if (b
->number
== bnum
)
730 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
732 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
733 l
= read_command_lines (tmpbuf
, from_tty
, 1);
734 do_cleanups (cleanups
);
735 breakpoint_set_commands (b
, l
);
738 error (_("No breakpoint number %d."), bnum
);
741 /* Like commands_command, but instead of reading the commands from
742 input stream, takes them from an already parsed command structure.
744 This is used by cli-script.c to DTRT with breakpoint commands
745 that are part of if and while bodies. */
746 enum command_control_type
747 commands_from_control_command (char *arg
, struct command_line
*cmd
)
749 struct breakpoint
*b
;
753 /* If we allowed this, we would have problems with when to
754 free the storage, if we change the commands currently
757 if (executing_breakpoint_commands
)
758 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
760 /* An empty string for the breakpoint number means the last
761 breakpoint, but get_number expects a NULL pointer. */
766 bnum
= get_number (&p
);
769 error (_("Unexpected extra arguments following breakpoint number."));
772 if (b
->number
== bnum
)
774 free_command_lines (&b
->commands
);
775 if (cmd
->body_count
!= 1)
776 error (_("Invalid \"commands\" block structure."));
777 /* We need to copy the commands because if/while will free the
778 list after it finishes execution. */
779 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
780 breakpoints_changed ();
781 observer_notify_breakpoint_modified (b
->number
);
782 return simple_control
;
784 error (_("No breakpoint number %d."), bnum
);
787 /* Return non-zero if BL->TARGET_INFO contains valid information. */
790 bp_location_has_shadow (struct bp_location
*bl
)
792 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
796 if (bl
->target_info
.shadow_len
== 0)
797 /* bp isn't valid, or doesn't shadow memory. */
802 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
803 by replacing any memory breakpoints with their shadowed contents.
805 The range of shadowed area by each bp_location is:
806 b->address - bp_location_placed_address_before_address_max
807 up to b->address + bp_location_shadow_len_after_address_max
808 The range we were requested to resolve shadows for is:
809 memaddr ... memaddr + len
810 Thus the safe cutoff boundaries for performance optimization are
811 memaddr + len <= b->address - bp_location_placed_address_before_address_max
813 b->address + bp_location_shadow_len_after_address_max <= memaddr */
816 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
818 /* Left boundary, right boundary and median element of our binary search. */
819 unsigned bc_l
, bc_r
, bc
;
821 /* Find BC_L which is a leftmost element which may affect BUF content. It is
822 safe to report lower value but a failure to report higher one. */
825 bc_r
= bp_location_count
;
826 while (bc_l
+ 1 < bc_r
)
828 struct bp_location
*b
;
830 bc
= (bc_l
+ bc_r
) / 2;
833 /* Check first B->ADDRESS will not overflow due to the added constant.
834 Then advance the left boundary only if we are sure the BC element can
835 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
837 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
838 we cannot miss a breakpoint with its shadow range tail still reaching
841 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
842 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
848 /* Now do full processing of the found relevant range of elements. */
850 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
852 struct bp_location
*b
= bp_location
[bc
];
853 CORE_ADDR bp_addr
= 0;
857 if (b
->owner
->type
== bp_none
)
858 warning (_("reading through apparently deleted breakpoint #%d?"),
861 /* Performance optimization: any futher element can no longer affect BUF
864 if (b
->address
>= bp_location_placed_address_before_address_max
865 && memaddr
+ len
<= b
->address
866 - bp_location_placed_address_before_address_max
)
869 if (!bp_location_has_shadow (b
))
871 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
872 current_program_space
->aspace
, 0))
875 /* Addresses and length of the part of the breakpoint that
877 bp_addr
= b
->target_info
.placed_address
;
878 bp_size
= b
->target_info
.shadow_len
;
880 if (bp_addr
+ bp_size
<= memaddr
)
881 /* The breakpoint is entirely before the chunk of memory we
885 if (bp_addr
>= memaddr
+ len
)
886 /* The breakpoint is entirely after the chunk of memory we are
890 /* Offset within shadow_contents. */
891 if (bp_addr
< memaddr
)
893 /* Only copy the second part of the breakpoint. */
894 bp_size
-= memaddr
- bp_addr
;
895 bptoffset
= memaddr
- bp_addr
;
899 if (bp_addr
+ bp_size
> memaddr
+ len
)
901 /* Only copy the first part of the breakpoint. */
902 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
905 memcpy (buf
+ bp_addr
- memaddr
,
906 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
911 /* A wrapper function for inserting catchpoints. */
913 insert_catchpoint (struct ui_out
*uo
, void *args
)
915 struct breakpoint
*b
= (struct breakpoint
*) args
;
918 gdb_assert (b
->type
== bp_catchpoint
);
919 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
924 /* Return true if BPT is of any hardware watchpoint kind. */
927 is_hardware_watchpoint (struct breakpoint
*bpt
)
929 return (bpt
->type
== bp_hardware_watchpoint
930 || bpt
->type
== bp_read_watchpoint
931 || bpt
->type
== bp_access_watchpoint
);
934 /* Return true if BPT is of any watchpoint kind, hardware or
938 is_watchpoint (struct breakpoint
*bpt
)
940 return (is_hardware_watchpoint (bpt
)
941 || bpt
->type
== bp_watchpoint
);
944 /* Find the current value of a watchpoint on EXP. Return the value in
945 *VALP and *RESULTP and the chain of intermediate and final values
946 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
949 If a memory error occurs while evaluating the expression, *RESULTP will
950 be set to NULL. *RESULTP may be a lazy value, if the result could
951 not be read from memory. It is used to determine whether a value
952 is user-specified (we should watch the whole value) or intermediate
953 (we should watch only the bit used to locate the final value).
955 If the final value, or any intermediate value, could not be read
956 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
957 set to any referenced values. *VALP will never be a lazy value.
958 This is the value which we store in struct breakpoint.
960 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
961 value chain. The caller must free the values individually. If
962 VAL_CHAIN is NULL, all generated values will be left on the value
966 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
967 struct value
**resultp
, struct value
**val_chain
)
969 struct value
*mark
, *new_mark
, *result
;
970 volatile struct gdb_exception ex
;
978 /* Evaluate the expression. */
979 mark
= value_mark ();
982 TRY_CATCH (ex
, RETURN_MASK_ALL
)
984 result
= evaluate_expression (exp
);
988 /* Ignore memory errors, we want watchpoints pointing at
989 inaccessible memory to still be created; otherwise, throw the
990 error to some higher catcher. */
996 throw_exception (ex
);
1001 new_mark
= value_mark ();
1002 if (mark
== new_mark
)
1007 /* Make sure it's not lazy, so that after the target stops again we
1008 have a non-lazy previous value to compare with. */
1010 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1015 /* Return the chain of intermediate values. We use this to
1016 decide which addresses to watch. */
1017 *val_chain
= new_mark
;
1018 value_release_to_mark (mark
);
1022 /* Assuming that B is a watchpoint: returns true if the current thread
1023 and its running state are safe to evaluate or update watchpoint B.
1024 Watchpoints on local expressions need to be evaluated in the
1025 context of the thread that was current when the watchpoint was
1026 created, and, that thread needs to be stopped to be able to select
1027 the correct frame context. Watchpoints on global expressions can
1028 be evaluated on any thread, and in any state. It is presently left
1029 to the target allowing memory accesses when threads are
1033 watchpoint_in_thread_scope (struct breakpoint
*b
)
1035 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1036 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1037 && !is_executing (inferior_ptid
)));
1040 /* Assuming that B is a watchpoint:
1041 - Reparse watchpoint expression, if REPARSE is non-zero
1042 - Evaluate expression and store the result in B->val
1043 - Evaluate the condition if there is one, and store the result
1045 - Update the list of values that must be watched in B->loc.
1047 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1048 If this is local watchpoint that is out of scope, delete it.
1050 Even with `set breakpoint always-inserted on' the watchpoints are removed
1051 + inserted on each stop here. Normal breakpoints must never be removed
1052 because they might be missed by a running thread when debugging in non-stop
1053 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1054 processed here) are specific to each LWP since they are stored in each LWP's
1055 hardware debug registers. Therefore, such LWP must be stopped first in
1056 order to be able to modify its hardware watchpoints.
1058 Hardware watchpoints must be reset exactly once after being presented to the
1059 user. It cannot be done sooner, because it would reset the data used to
1060 present the watchpoint hit to the user. And it must not be done later
1061 because it could display the same single watchpoint hit during multiple GDB
1062 stops. Note that the latter is relevant only to the hardware watchpoint
1063 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1064 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1065 memory content has not changed.
1067 The following constraints influence the location where we can reset hardware
1070 * target_stopped_by_watchpoint and target_stopped_data_address are called
1071 several times when GDB stops.
1074 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1075 stop. GDB only presents one hardware watchpoint hit at a time as the
1076 reason for stopping, and all the other hits are presented later, one after
1077 the other, each time the user requests the execution to be resumed.
1078 Execution is not resumed for the threads still having pending hit event
1079 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1080 the inferior on the first stop the thread hit event is kept being reported
1081 from its cached value by linux_nat_stopped_data_address until the real
1082 thread resume happens after the watchpoint gets presented and thus its
1083 LWP_INFO->STATUS gets reset.
1085 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1086 removal from inferior. */
1089 update_watchpoint (struct breakpoint
*b
, int reparse
)
1091 int within_current_scope
;
1092 struct frame_id saved_frame_id
;
1093 struct bp_location
*loc
;
1097 /* If this is a local watchpoint, we only want to check if the
1098 watchpoint frame is in scope if the current thread is the thread
1099 that was used to create the watchpoint. */
1100 if (!watchpoint_in_thread_scope (b
))
1103 /* We don't free locations. They are stored in bp_location array and
1104 update_global_locations will eventually delete them and remove
1105 breakpoints if needed. */
1108 if (b
->disposition
== disp_del_at_next_stop
)
1113 /* Determine if the watchpoint is within scope. */
1114 if (b
->exp_valid_block
== NULL
)
1115 within_current_scope
= 1;
1118 struct frame_info
*fi
;
1120 /* Save the current frame's ID so we can restore it after
1121 evaluating the watchpoint expression on its own frame. */
1122 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1123 took a frame parameter, so that we didn't have to change the
1126 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1128 fi
= frame_find_by_id (b
->watchpoint_frame
);
1129 within_current_scope
= (fi
!= NULL
);
1130 if (within_current_scope
)
1134 if (within_current_scope
&& reparse
)
1143 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1144 /* If the meaning of expression itself changed, the old value is
1145 no longer relevant. We don't want to report a watchpoint hit
1146 to the user when the old value and the new value may actually
1147 be completely different objects. */
1148 value_free (b
->val
);
1152 /* Note that unlike with breakpoints, the watchpoint's condition
1153 expression is stored in the breakpoint object, not in the
1154 locations (re)created below. */
1155 if (b
->cond_string
!= NULL
)
1157 if (b
->cond_exp
!= NULL
)
1159 xfree (b
->cond_exp
);
1164 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1168 /* If we failed to parse the expression, for example because
1169 it refers to a global variable in a not-yet-loaded shared library,
1170 don't try to insert watchpoint. We don't automatically delete
1171 such watchpoint, though, since failure to parse expression
1172 is different from out-of-scope watchpoint. */
1173 if ( !target_has_execution
)
1175 /* Without execution, memory can't change. No use to try and
1176 set watchpoint locations. The watchpoint will be reset when
1177 the target gains execution, through breakpoint_re_set. */
1179 else if (within_current_scope
&& b
->exp
)
1181 struct value
*val_chain
, *v
, *result
, *next
;
1182 struct program_space
*frame_pspace
;
1184 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1186 /* Avoid setting b->val if it's already set. The meaning of
1187 b->val is 'the last value' user saw, and we should update
1188 it only if we reported that last value to user. As it
1189 happens, the code that reports it updates b->val directly. */
1196 /* Change the type of breakpoint between hardware assisted or an
1197 ordinary watchpoint depending on the hardware support and free
1198 hardware slots. REPARSE is set when the inferior is started. */
1199 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1202 int i
, mem_cnt
, other_type_used
;
1204 /* We need to determine how many resources are already used
1205 for all other hardware watchpoints to see if we still have
1206 enough resources to also fit this watchpoint in as well.
1207 To avoid the hw_watchpoint_used_count call below from counting
1208 this watchpoint, make sure that it is marked as a software
1210 b
->type
= bp_watchpoint
;
1211 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1213 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1216 b
->type
= bp_watchpoint
;
1219 int target_resources_ok
= target_can_use_hardware_watchpoint
1220 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1221 if (target_resources_ok
<= 0)
1222 b
->type
= bp_watchpoint
;
1224 b
->type
= bp_hardware_watchpoint
;
1228 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1230 /* Look at each value on the value chain. */
1231 for (v
= val_chain
; v
; v
= next
)
1233 /* If it's a memory location, and GDB actually needed
1234 its contents to evaluate the expression, then we
1235 must watch it. If the first value returned is
1236 still lazy, that means an error occurred reading it;
1237 watch it anyway in case it becomes readable. */
1238 if (VALUE_LVAL (v
) == lval_memory
1239 && (v
== val_chain
|| ! value_lazy (v
)))
1241 struct type
*vtype
= check_typedef (value_type (v
));
1243 /* We only watch structs and arrays if user asked
1244 for it explicitly, never if they just happen to
1245 appear in the middle of some value chain. */
1247 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1248 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1252 struct bp_location
*loc
, **tmp
;
1254 addr
= value_address (v
);
1255 len
= TYPE_LENGTH (value_type (v
));
1257 if (b
->type
== bp_read_watchpoint
)
1259 else if (b
->type
== bp_access_watchpoint
)
1262 loc
= allocate_bp_location (b
);
1263 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1266 loc
->gdbarch
= get_type_arch (value_type (v
));
1268 loc
->pspace
= frame_pspace
;
1269 loc
->address
= addr
;
1271 loc
->watchpoint_type
= type
;
1275 next
= value_next (v
);
1280 /* If a software watchpoint is not watching any memory, then the
1281 above left it without any location set up. But,
1282 bpstat_stop_status requires a location to be able to report
1283 stops, so make sure there's at least a dummy one. */
1284 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1286 b
->loc
= allocate_bp_location (b
);
1287 b
->loc
->pspace
= frame_pspace
;
1288 b
->loc
->address
= -1;
1289 b
->loc
->length
= -1;
1290 b
->loc
->watchpoint_type
= -1;
1293 else if (!within_current_scope
)
1295 printf_filtered (_("\
1296 Watchpoint %d deleted because the program has left the block \n\
1297 in which its expression is valid.\n"),
1299 if (b
->related_breakpoint
)
1301 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1302 b
->related_breakpoint
->related_breakpoint
= NULL
;
1303 b
->related_breakpoint
= NULL
;
1305 b
->disposition
= disp_del_at_next_stop
;
1308 /* Restore the selected frame. */
1310 select_frame (frame_find_by_id (saved_frame_id
));
1314 /* Returns 1 iff breakpoint location should be
1315 inserted in the inferior. */
1317 should_be_inserted (struct bp_location
*bpt
)
1319 if (!breakpoint_enabled (bpt
->owner
))
1322 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1325 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1328 /* This is set for example, when we're attached to the parent of a
1329 vfork, and have detached from the child. The child is running
1330 free, and we expect it to do an exec or exit, at which point the
1331 OS makes the parent schedulable again (and the target reports
1332 that the vfork is done). Until the child is done with the shared
1333 memory region, do not insert breakpoints in the parent, otherwise
1334 the child could still trip on the parent's breakpoints. Since
1335 the parent is blocked anyway, it won't miss any breakpoint. */
1336 if (bpt
->pspace
->breakpoints_not_allowed
)
1339 /* Tracepoints are inserted by the target at a time of its choosing,
1341 if (tracepoint_type (bpt
->owner
))
1347 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1348 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1349 and HW_BREAKPOINT_ERROR are used to report problems.
1351 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1352 method for each breakpoint or catchpoint type. */
1354 insert_bp_location (struct bp_location
*bpt
,
1355 struct ui_file
*tmp_error_stream
,
1356 int *disabled_breaks
,
1357 int *hw_breakpoint_error
)
1361 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1364 /* Initialize the target-specific information. */
1365 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1366 bpt
->target_info
.placed_address
= bpt
->address
;
1367 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1369 if (bpt
->loc_type
== bp_loc_software_breakpoint
1370 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1372 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1374 /* If the explicitly specified breakpoint type
1375 is not hardware breakpoint, check the memory map to see
1376 if the breakpoint address is in read only memory or not.
1377 Two important cases are:
1378 - location type is not hardware breakpoint, memory
1379 is readonly. We change the type of the location to
1380 hardware breakpoint.
1381 - location type is hardware breakpoint, memory is read-write.
1382 This means we've previously made the location hardware one, but
1383 then the memory map changed, so we undo.
1385 When breakpoints are removed, remove_breakpoints will
1386 use location types we've just set here, the only possible
1387 problem is that memory map has changed during running program,
1388 but it's not going to work anyway with current gdb. */
1389 struct mem_region
*mr
1390 = lookup_mem_region (bpt
->target_info
.placed_address
);
1394 if (automatic_hardware_breakpoints
)
1397 enum bp_loc_type new_type
;
1399 if (mr
->attrib
.mode
!= MEM_RW
)
1400 new_type
= bp_loc_hardware_breakpoint
;
1402 new_type
= bp_loc_software_breakpoint
;
1404 if (new_type
!= bpt
->loc_type
)
1406 static int said
= 0;
1407 bpt
->loc_type
= new_type
;
1410 fprintf_filtered (gdb_stdout
, _("\
1411 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1416 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1417 && mr
->attrib
.mode
!= MEM_RW
)
1418 warning (_("cannot set software breakpoint at readonly address %s"),
1419 paddress (bpt
->gdbarch
, bpt
->address
));
1423 /* First check to see if we have to handle an overlay. */
1424 if (overlay_debugging
== ovly_off
1425 || bpt
->section
== NULL
1426 || !(section_is_overlay (bpt
->section
)))
1428 /* No overlay handling: just set the breakpoint. */
1430 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1431 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1434 val
= target_insert_breakpoint (bpt
->gdbarch
,
1439 /* This breakpoint is in an overlay section.
1440 Shall we set a breakpoint at the LMA? */
1441 if (!overlay_events_enabled
)
1443 /* Yes -- overlay event support is not active,
1444 so we must try to set a breakpoint at the LMA.
1445 This will not work for a hardware breakpoint. */
1446 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1447 warning (_("hardware breakpoint %d not supported in overlay!"),
1448 bpt
->owner
->number
);
1451 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1453 /* Set a software (trap) breakpoint at the LMA. */
1454 bpt
->overlay_target_info
= bpt
->target_info
;
1455 bpt
->overlay_target_info
.placed_address
= addr
;
1456 val
= target_insert_breakpoint (bpt
->gdbarch
,
1457 &bpt
->overlay_target_info
);
1459 fprintf_unfiltered (tmp_error_stream
,
1460 "Overlay breakpoint %d failed: in ROM?\n",
1461 bpt
->owner
->number
);
1464 /* Shall we set a breakpoint at the VMA? */
1465 if (section_is_mapped (bpt
->section
))
1467 /* Yes. This overlay section is mapped into memory. */
1468 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1469 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1472 val
= target_insert_breakpoint (bpt
->gdbarch
,
1477 /* No. This breakpoint will not be inserted.
1478 No error, but do not mark the bp as 'inserted'. */
1485 /* Can't set the breakpoint. */
1486 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1488 /* See also: disable_breakpoints_in_shlibs. */
1490 bpt
->shlib_disabled
= 1;
1491 if (!*disabled_breaks
)
1493 fprintf_unfiltered (tmp_error_stream
,
1494 "Cannot insert breakpoint %d.\n",
1495 bpt
->owner
->number
);
1496 fprintf_unfiltered (tmp_error_stream
,
1497 "Temporarily disabling shared library breakpoints:\n");
1499 *disabled_breaks
= 1;
1500 fprintf_unfiltered (tmp_error_stream
,
1501 "breakpoint #%d\n", bpt
->owner
->number
);
1505 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1507 *hw_breakpoint_error
= 1;
1508 fprintf_unfiltered (tmp_error_stream
,
1509 "Cannot insert hardware breakpoint %d.\n",
1510 bpt
->owner
->number
);
1514 fprintf_unfiltered (tmp_error_stream
,
1515 "Cannot insert breakpoint %d.\n",
1516 bpt
->owner
->number
);
1517 fprintf_filtered (tmp_error_stream
,
1518 "Error accessing memory address ");
1519 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1521 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1522 safe_strerror (val
));
1533 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1534 /* NOTE drow/2003-09-08: This state only exists for removing
1535 watchpoints. It's not clear that it's necessary... */
1536 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1538 val
= target_insert_watchpoint (bpt
->address
,
1540 bpt
->watchpoint_type
);
1542 /* If trying to set a read-watchpoint, and it turns out it's not
1543 supported, try emulating one with an access watchpoint. */
1544 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1546 struct bp_location
*loc
, **loc_temp
;
1548 /* But don't try to insert it, if there's already another
1549 hw_access location that would be considered a duplicate
1551 ALL_BP_LOCATIONS (loc
, loc_temp
)
1553 && loc
->watchpoint_type
== hw_access
1554 && watchpoint_locations_match (bpt
, loc
))
1558 bpt
->target_info
= loc
->target_info
;
1559 bpt
->watchpoint_type
= hw_access
;
1566 val
= target_insert_watchpoint (bpt
->address
,
1570 bpt
->watchpoint_type
= hw_access
;
1574 bpt
->inserted
= (val
== 0);
1577 else if (bpt
->owner
->type
== bp_catchpoint
)
1579 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1580 bpt
->owner
, RETURN_MASK_ERROR
);
1581 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1582 bpt
->owner
->number
);
1584 bpt
->owner
->enable_state
= bp_disabled
;
1588 /* We've already printed an error message if there was a problem
1589 inserting this catchpoint, and we've disabled the catchpoint,
1590 so just return success. */
1597 /* This function is called when program space PSPACE is about to be
1598 deleted. It takes care of updating breakpoints to not reference
1602 breakpoint_program_space_exit (struct program_space
*pspace
)
1604 struct breakpoint
*b
, *b_temp
;
1605 struct bp_location
*loc
, **loc_temp
;
1607 /* Remove any breakpoint that was set through this program space. */
1608 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1610 if (b
->pspace
== pspace
)
1611 delete_breakpoint (b
);
1614 /* Breakpoints set through other program spaces could have locations
1615 bound to PSPACE as well. Remove those. */
1616 ALL_BP_LOCATIONS (loc
, loc_temp
)
1618 struct bp_location
*tmp
;
1620 if (loc
->pspace
== pspace
)
1622 if (loc
->owner
->loc
== loc
)
1623 loc
->owner
->loc
= loc
->next
;
1625 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1626 if (tmp
->next
== loc
)
1628 tmp
->next
= loc
->next
;
1634 /* Now update the global location list to permanently delete the
1635 removed locations above. */
1636 update_global_location_list (0);
1639 /* Make sure all breakpoints are inserted in inferior.
1640 Throws exception on any error.
1641 A breakpoint that is already inserted won't be inserted
1642 again, so calling this function twice is safe. */
1644 insert_breakpoints (void)
1646 struct breakpoint
*bpt
;
1648 ALL_BREAKPOINTS (bpt
)
1649 if (is_hardware_watchpoint (bpt
))
1650 update_watchpoint (bpt
, 0 /* don't reparse. */);
1652 update_global_location_list (1);
1654 /* update_global_location_list does not insert breakpoints when
1655 always_inserted_mode is not enabled. Explicitly insert them
1657 if (!breakpoints_always_inserted_mode ())
1658 insert_breakpoint_locations ();
1661 /* insert_breakpoints is used when starting or continuing the program.
1662 remove_breakpoints is used when the program stops.
1663 Both return zero if successful,
1664 or an `errno' value if could not write the inferior. */
1667 insert_breakpoint_locations (void)
1669 struct breakpoint
*bpt
;
1670 struct bp_location
*b
, **bp_tmp
;
1673 int disabled_breaks
= 0;
1674 int hw_breakpoint_error
= 0;
1676 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1677 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1679 /* Explicitly mark the warning -- this will only be printed if
1680 there was an error. */
1681 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1683 save_current_space_and_thread ();
1685 ALL_BP_LOCATIONS (b
, bp_tmp
)
1687 struct thread_info
*tp
;
1688 CORE_ADDR last_addr
;
1690 if (!should_be_inserted (b
) || b
->inserted
)
1693 /* There is no point inserting thread-specific breakpoints if the
1694 thread no longer exists. */
1695 if (b
->owner
->thread
!= -1
1696 && !valid_thread_id (b
->owner
->thread
))
1699 switch_to_program_space_and_thread (b
->pspace
);
1701 /* For targets that support global breakpoints, there's no need
1702 to select an inferior to insert breakpoint to. In fact, even
1703 if we aren't attached to any process yet, we should still
1704 insert breakpoints. */
1705 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1706 && ptid_equal (inferior_ptid
, null_ptid
))
1709 val
= insert_bp_location (b
, tmp_error_stream
,
1711 &hw_breakpoint_error
);
1716 /* If we failed to insert all locations of a watchpoint,
1717 remove them, as half-inserted watchpoint is of limited use. */
1718 ALL_BREAKPOINTS (bpt
)
1720 int some_failed
= 0;
1721 struct bp_location
*loc
;
1723 if (!is_hardware_watchpoint (bpt
))
1726 if (!breakpoint_enabled (bpt
))
1729 if (bpt
->disposition
== disp_del_at_next_stop
)
1732 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1733 if (!loc
->inserted
&& should_be_inserted (loc
))
1740 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1742 remove_breakpoint (loc
, mark_uninserted
);
1744 hw_breakpoint_error
= 1;
1745 fprintf_unfiltered (tmp_error_stream
,
1746 "Could not insert hardware watchpoint %d.\n",
1754 /* If a hardware breakpoint or watchpoint was inserted, add a
1755 message about possibly exhausted resources. */
1756 if (hw_breakpoint_error
)
1758 fprintf_unfiltered (tmp_error_stream
,
1759 "Could not insert hardware breakpoints:\n\
1760 You may have requested too many hardware breakpoints/watchpoints.\n");
1762 target_terminal_ours_for_output ();
1763 error_stream (tmp_error_stream
);
1766 do_cleanups (cleanups
);
1770 remove_breakpoints (void)
1772 struct bp_location
*b
, **bp_tmp
;
1775 ALL_BP_LOCATIONS (b
, bp_tmp
)
1778 val
|= remove_breakpoint (b
, mark_uninserted
);
1783 /* Remove breakpoints of process PID. */
1786 remove_breakpoints_pid (int pid
)
1788 struct bp_location
*b
, **b_tmp
;
1790 struct inferior
*inf
= find_inferior_pid (pid
);
1792 ALL_BP_LOCATIONS (b
, b_tmp
)
1794 if (b
->pspace
!= inf
->pspace
)
1799 val
= remove_breakpoint (b
, mark_uninserted
);
1808 remove_hw_watchpoints (void)
1810 struct bp_location
*b
, **bp_tmp
;
1813 ALL_BP_LOCATIONS (b
, bp_tmp
)
1815 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1816 val
|= remove_breakpoint (b
, mark_uninserted
);
1822 reattach_breakpoints (int pid
)
1824 struct cleanup
*old_chain
;
1825 struct bp_location
*b
, **bp_tmp
;
1827 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1828 int dummy1
= 0, dummy2
= 0;
1829 struct inferior
*inf
;
1830 struct thread_info
*tp
;
1832 tp
= any_live_thread_of_process (pid
);
1836 inf
= find_inferior_pid (pid
);
1837 old_chain
= save_inferior_ptid ();
1839 inferior_ptid
= tp
->ptid
;
1841 make_cleanup_ui_file_delete (tmp_error_stream
);
1843 ALL_BP_LOCATIONS (b
, bp_tmp
)
1845 if (b
->pspace
!= inf
->pspace
)
1851 val
= insert_bp_location (b
, tmp_error_stream
,
1855 do_cleanups (old_chain
);
1860 do_cleanups (old_chain
);
1864 static int internal_breakpoint_number
= -1;
1866 static struct breakpoint
*
1867 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1868 CORE_ADDR address
, enum bptype type
)
1870 struct symtab_and_line sal
;
1871 struct breakpoint
*b
;
1873 init_sal (&sal
); /* initialize to zeroes */
1876 sal
.section
= find_pc_overlay (sal
.pc
);
1877 sal
.pspace
= current_program_space
;
1879 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1880 b
->number
= internal_breakpoint_number
--;
1881 b
->disposition
= disp_donttouch
;
1887 create_overlay_event_breakpoint (char *func_name
)
1889 struct objfile
*objfile
;
1891 ALL_OBJFILES (objfile
)
1893 struct breakpoint
*b
;
1894 struct minimal_symbol
*m
;
1896 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1900 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1901 SYMBOL_VALUE_ADDRESS (m
),
1903 b
->addr_string
= xstrdup (func_name
);
1905 if (overlay_debugging
== ovly_auto
)
1907 b
->enable_state
= bp_enabled
;
1908 overlay_events_enabled
= 1;
1912 b
->enable_state
= bp_disabled
;
1913 overlay_events_enabled
= 0;
1916 update_global_location_list (1);
1920 create_longjmp_master_breakpoint (char *func_name
)
1922 struct program_space
*pspace
;
1923 struct objfile
*objfile
;
1924 struct cleanup
*old_chain
;
1926 old_chain
= save_current_program_space ();
1928 ALL_PSPACES (pspace
)
1929 ALL_OBJFILES (objfile
)
1931 struct breakpoint
*b
;
1932 struct minimal_symbol
*m
;
1934 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1937 set_current_program_space (pspace
);
1939 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1943 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1944 SYMBOL_VALUE_ADDRESS (m
),
1946 b
->addr_string
= xstrdup (func_name
);
1947 b
->enable_state
= bp_disabled
;
1949 update_global_location_list (1);
1951 do_cleanups (old_chain
);
1955 update_breakpoints_after_exec (void)
1957 struct breakpoint
*b
;
1958 struct breakpoint
*temp
;
1959 struct bp_location
*bploc
, **bplocp_tmp
;
1961 /* We're about to delete breakpoints from GDB's lists. If the
1962 INSERTED flag is true, GDB will try to lift the breakpoints by
1963 writing the breakpoints' "shadow contents" back into memory. The
1964 "shadow contents" are NOT valid after an exec, so GDB should not
1965 do that. Instead, the target is responsible from marking
1966 breakpoints out as soon as it detects an exec. We don't do that
1967 here instead, because there may be other attempts to delete
1968 breakpoints after detecting an exec and before reaching here. */
1969 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
1970 if (bploc
->pspace
== current_program_space
)
1971 gdb_assert (!bploc
->inserted
);
1973 ALL_BREAKPOINTS_SAFE (b
, temp
)
1975 if (b
->pspace
!= current_program_space
)
1978 /* Solib breakpoints must be explicitly reset after an exec(). */
1979 if (b
->type
== bp_shlib_event
)
1981 delete_breakpoint (b
);
1985 /* JIT breakpoints must be explicitly reset after an exec(). */
1986 if (b
->type
== bp_jit_event
)
1988 delete_breakpoint (b
);
1992 /* Thread event breakpoints must be set anew after an exec(),
1993 as must overlay event and longjmp master breakpoints. */
1994 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1995 || b
->type
== bp_longjmp_master
)
1997 delete_breakpoint (b
);
2001 /* Step-resume breakpoints are meaningless after an exec(). */
2002 if (b
->type
== bp_step_resume
)
2004 delete_breakpoint (b
);
2008 /* Longjmp and longjmp-resume breakpoints are also meaningless
2010 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2012 delete_breakpoint (b
);
2016 if (b
->type
== bp_catchpoint
)
2018 /* For now, none of the bp_catchpoint breakpoints need to
2019 do anything at this point. In the future, if some of
2020 the catchpoints need to something, we will need to add
2021 a new method, and call this method from here. */
2025 /* bp_finish is a special case. The only way we ought to be able
2026 to see one of these when an exec() has happened, is if the user
2027 caught a vfork, and then said "finish". Ordinarily a finish just
2028 carries them to the call-site of the current callee, by setting
2029 a temporary bp there and resuming. But in this case, the finish
2030 will carry them entirely through the vfork & exec.
2032 We don't want to allow a bp_finish to remain inserted now. But
2033 we can't safely delete it, 'cause finish_command has a handle to
2034 the bp on a bpstat, and will later want to delete it. There's a
2035 chance (and I've seen it happen) that if we delete the bp_finish
2036 here, that its storage will get reused by the time finish_command
2037 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2038 We really must allow finish_command to delete a bp_finish.
2040 In the absense of a general solution for the "how do we know
2041 it's safe to delete something others may have handles to?"
2042 problem, what we'll do here is just uninsert the bp_finish, and
2043 let finish_command delete it.
2045 (We know the bp_finish is "doomed" in the sense that it's
2046 momentary, and will be deleted as soon as finish_command sees
2047 the inferior stopped. So it doesn't matter that the bp's
2048 address is probably bogus in the new a.out, unlike e.g., the
2049 solib breakpoints.) */
2051 if (b
->type
== bp_finish
)
2056 /* Without a symbolic address, we have little hope of the
2057 pre-exec() address meaning the same thing in the post-exec()
2059 if (b
->addr_string
== NULL
)
2061 delete_breakpoint (b
);
2065 /* FIXME what about longjmp breakpoints? Re-create them here? */
2066 create_overlay_event_breakpoint ("_ovly_debug_event");
2067 create_longjmp_master_breakpoint ("longjmp");
2068 create_longjmp_master_breakpoint ("_longjmp");
2069 create_longjmp_master_breakpoint ("siglongjmp");
2070 create_longjmp_master_breakpoint ("_siglongjmp");
2074 detach_breakpoints (int pid
)
2076 struct bp_location
*b
, **bp_tmp
;
2078 struct cleanup
*old_chain
= save_inferior_ptid ();
2079 struct inferior
*inf
= current_inferior ();
2081 if (pid
== PIDGET (inferior_ptid
))
2082 error (_("Cannot detach breakpoints of inferior_ptid"));
2084 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2085 inferior_ptid
= pid_to_ptid (pid
);
2086 ALL_BP_LOCATIONS (b
, bp_tmp
)
2088 if (b
->pspace
!= inf
->pspace
)
2092 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2094 do_cleanups (old_chain
);
2098 /* Remove the breakpoint location B from the current address space.
2099 Note that this is used to detach breakpoints from a child fork.
2100 When we get here, the child isn't in the inferior list, and neither
2101 do we have objects to represent its address space --- we should
2102 *not* look at b->pspace->aspace here. */
2105 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2108 struct cleanup
*old_chain
;
2110 if (b
->owner
->enable_state
== bp_permanent
)
2111 /* Permanent breakpoints cannot be inserted or removed. */
2114 /* The type of none suggests that owner is actually deleted.
2115 This should not ever happen. */
2116 gdb_assert (b
->owner
->type
!= bp_none
);
2118 if (b
->loc_type
== bp_loc_software_breakpoint
2119 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2121 /* "Normal" instruction breakpoint: either the standard
2122 trap-instruction bp (bp_breakpoint), or a
2123 bp_hardware_breakpoint. */
2125 /* First check to see if we have to handle an overlay. */
2126 if (overlay_debugging
== ovly_off
2127 || b
->section
== NULL
2128 || !(section_is_overlay (b
->section
)))
2130 /* No overlay handling: just remove the breakpoint. */
2132 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2133 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2135 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2139 /* This breakpoint is in an overlay section.
2140 Did we set a breakpoint at the LMA? */
2141 if (!overlay_events_enabled
)
2143 /* Yes -- overlay event support is not active, so we
2144 should have set a breakpoint at the LMA. Remove it.
2146 /* Ignore any failures: if the LMA is in ROM, we will
2147 have already warned when we failed to insert it. */
2148 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2149 target_remove_hw_breakpoint (b
->gdbarch
,
2150 &b
->overlay_target_info
);
2152 target_remove_breakpoint (b
->gdbarch
,
2153 &b
->overlay_target_info
);
2155 /* Did we set a breakpoint at the VMA?
2156 If so, we will have marked the breakpoint 'inserted'. */
2159 /* Yes -- remove it. Previously we did not bother to
2160 remove the breakpoint if the section had been
2161 unmapped, but let's not rely on that being safe. We
2162 don't know what the overlay manager might do. */
2163 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2164 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2167 /* However, we should remove *software* breakpoints only
2168 if the section is still mapped, or else we overwrite
2169 wrong code with the saved shadow contents. */
2170 else if (section_is_mapped (b
->section
))
2171 val
= target_remove_breakpoint (b
->gdbarch
,
2178 /* No -- not inserted, so no need to remove. No error. */
2183 /* In some cases, we might not be able to remove a breakpoint
2184 in a shared library that has already been removed, but we
2185 have not yet processed the shlib unload event. */
2186 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2191 b
->inserted
= (is
== mark_inserted
);
2193 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2198 b
->inserted
= (is
== mark_inserted
);
2199 val
= target_remove_watchpoint (b
->address
, b
->length
,
2200 b
->watchpoint_type
);
2202 /* Failure to remove any of the hardware watchpoints comes here. */
2203 if ((is
== mark_uninserted
) && (b
->inserted
))
2204 warning (_("Could not remove hardware watchpoint %d."),
2207 else if (b
->owner
->type
== bp_catchpoint
2208 && breakpoint_enabled (b
->owner
)
2211 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2213 val
= b
->owner
->ops
->remove (b
->owner
);
2216 b
->inserted
= (is
== mark_inserted
);
2223 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2226 struct cleanup
*old_chain
;
2228 if (b
->owner
->enable_state
== bp_permanent
)
2229 /* Permanent breakpoints cannot be inserted or removed. */
2232 /* The type of none suggests that owner is actually deleted.
2233 This should not ever happen. */
2234 gdb_assert (b
->owner
->type
!= bp_none
);
2236 old_chain
= save_current_space_and_thread ();
2238 switch_to_program_space_and_thread (b
->pspace
);
2240 ret
= remove_breakpoint_1 (b
, is
);
2242 do_cleanups (old_chain
);
2246 /* Clear the "inserted" flag in all breakpoints. */
2249 mark_breakpoints_out (void)
2251 struct bp_location
*bpt
, **bptp_tmp
;
2253 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2254 if (bpt
->pspace
== current_program_space
)
2258 /* Clear the "inserted" flag in all breakpoints and delete any
2259 breakpoints which should go away between runs of the program.
2261 Plus other such housekeeping that has to be done for breakpoints
2264 Note: this function gets called at the end of a run (by
2265 generic_mourn_inferior) and when a run begins (by
2266 init_wait_for_inferior). */
2271 breakpoint_init_inferior (enum inf_context context
)
2273 struct breakpoint
*b
, *temp
;
2274 struct bp_location
*bpt
, **bptp_tmp
;
2276 struct program_space
*pspace
= current_program_space
;
2278 /* If breakpoint locations are shared across processes, then there's
2280 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2283 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2285 if (bpt
->pspace
== pspace
2286 && bpt
->owner
->enable_state
!= bp_permanent
)
2290 ALL_BREAKPOINTS_SAFE (b
, temp
)
2292 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2299 /* If the call dummy breakpoint is at the entry point it will
2300 cause problems when the inferior is rerun, so we better get
2303 case bp_watchpoint_scope
:
2305 /* Also get rid of scope breakpoints. */
2307 case bp_shlib_event
:
2309 /* Also remove solib event breakpoints. Their addresses may
2310 have changed since the last time we ran the program.
2311 Actually we may now be debugging against different target;
2312 and so the solib backend that installed this breakpoint may
2313 not be used in by the target. E.g.,
2315 (gdb) file prog-linux
2316 (gdb) run # native linux target
2319 (gdb) file prog-win.exe
2320 (gdb) tar rem :9999 # remote Windows gdbserver.
2323 delete_breakpoint (b
);
2327 case bp_hardware_watchpoint
:
2328 case bp_read_watchpoint
:
2329 case bp_access_watchpoint
:
2331 /* Likewise for watchpoints on local expressions. */
2332 if (b
->exp_valid_block
!= NULL
)
2333 delete_breakpoint (b
);
2334 else if (context
== inf_starting
)
2336 /* Reset val field to force reread of starting value
2337 in insert_breakpoints. */
2339 value_free (b
->val
);
2349 /* Get rid of the moribund locations. */
2350 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2351 free_bp_location (bpt
);
2352 VEC_free (bp_location_p
, moribund_locations
);
2355 /* These functions concern about actual breakpoints inserted in the
2356 target --- to e.g. check if we need to do decr_pc adjustment or if
2357 we need to hop over the bkpt --- so we check for address space
2358 match, not program space. */
2360 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2361 exists at PC. It returns ordinary_breakpoint_here if it's an
2362 ordinary breakpoint, or permanent_breakpoint_here if it's a
2363 permanent breakpoint.
2364 - When continuing from a location with an ordinary breakpoint, we
2365 actually single step once before calling insert_breakpoints.
2366 - When continuing from a localion with a permanent breakpoint, we
2367 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2368 the target, to advance the PC past the breakpoint. */
2370 enum breakpoint_here
2371 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2373 struct bp_location
*bpt
, **bptp_tmp
;
2374 int any_breakpoint_here
= 0;
2376 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2378 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2379 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2382 if ((breakpoint_enabled (bpt
->owner
)
2383 || bpt
->owner
->enable_state
== bp_permanent
)
2384 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2387 if (overlay_debugging
2388 && section_is_overlay (bpt
->section
)
2389 && !section_is_mapped (bpt
->section
))
2390 continue; /* unmapped overlay -- can't be a match */
2391 else if (bpt
->owner
->enable_state
== bp_permanent
)
2392 return permanent_breakpoint_here
;
2394 any_breakpoint_here
= 1;
2398 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2401 /* Return true if there's a moribund breakpoint at PC. */
2404 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2406 struct bp_location
*loc
;
2409 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2410 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2417 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2418 inserted using regular breakpoint_chain / bp_location array mechanism.
2419 This does not check for single-step breakpoints, which are
2420 inserted and removed using direct target manipulation. */
2423 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2425 struct bp_location
*bpt
, **bptp_tmp
;
2427 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2429 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2430 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2434 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2437 if (overlay_debugging
2438 && section_is_overlay (bpt
->section
)
2439 && !section_is_mapped (bpt
->section
))
2440 continue; /* unmapped overlay -- can't be a match */
2448 /* Returns non-zero iff there's either regular breakpoint
2449 or a single step breakpoint inserted at PC. */
2452 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2454 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2457 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2463 /* This function returns non-zero iff there is a software breakpoint
2467 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2469 struct bp_location
*bpt
, **bptp_tmp
;
2470 int any_breakpoint_here
= 0;
2472 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2474 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2478 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2481 if (overlay_debugging
2482 && section_is_overlay (bpt
->section
)
2483 && !section_is_mapped (bpt
->section
))
2484 continue; /* unmapped overlay -- can't be a match */
2490 /* Also check for software single-step breakpoints. */
2491 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2498 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2499 CORE_ADDR addr
, ULONGEST len
)
2501 struct breakpoint
*bpt
;
2503 ALL_BREAKPOINTS (bpt
)
2505 struct bp_location
*loc
;
2507 if (bpt
->type
!= bp_hardware_watchpoint
2508 && bpt
->type
!= bp_access_watchpoint
)
2511 if (!breakpoint_enabled (bpt
))
2514 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2515 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2519 /* Check for intersection. */
2520 l
= max (loc
->address
, addr
);
2521 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2529 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2530 PC is valid for process/thread PTID. */
2533 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2536 struct bp_location
*bpt
, **bptp_tmp
;
2537 /* The thread and task IDs associated to PTID, computed lazily. */
2541 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2543 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2544 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2547 if (!breakpoint_enabled (bpt
->owner
)
2548 && bpt
->owner
->enable_state
!= bp_permanent
)
2551 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2555 if (bpt
->owner
->thread
!= -1)
2557 /* This is a thread-specific breakpoint. Check that ptid
2558 matches that thread. If thread hasn't been computed yet,
2559 it is now time to do so. */
2561 thread
= pid_to_thread_id (ptid
);
2562 if (bpt
->owner
->thread
!= thread
)
2566 if (bpt
->owner
->task
!= 0)
2568 /* This is a task-specific breakpoint. Check that ptid
2569 matches that task. If task hasn't been computed yet,
2570 it is now time to do so. */
2572 task
= ada_get_task_number (ptid
);
2573 if (bpt
->owner
->task
!= task
)
2577 if (overlay_debugging
2578 && section_is_overlay (bpt
->section
)
2579 && !section_is_mapped (bpt
->section
))
2580 continue; /* unmapped overlay -- can't be a match */
2589 /* bpstat stuff. External routines' interfaces are documented
2593 ep_is_catchpoint (struct breakpoint
*ep
)
2595 return (ep
->type
== bp_catchpoint
);
2599 bpstat_free (bpstat bs
)
2601 if (bs
->old_val
!= NULL
)
2602 value_free (bs
->old_val
);
2603 free_command_lines (&bs
->commands
);
2607 /* Clear a bpstat so that it says we are not at any breakpoint.
2608 Also free any storage that is part of a bpstat. */
2611 bpstat_clear (bpstat
*bsp
)
2628 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2629 is part of the bpstat is copied as well. */
2632 bpstat_copy (bpstat bs
)
2636 bpstat retval
= NULL
;
2641 for (; bs
!= NULL
; bs
= bs
->next
)
2643 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2644 memcpy (tmp
, bs
, sizeof (*tmp
));
2645 if (bs
->commands
!= NULL
)
2646 tmp
->commands
= copy_command_lines (bs
->commands
);
2647 if (bs
->old_val
!= NULL
)
2649 tmp
->old_val
= value_copy (bs
->old_val
);
2650 release_value (tmp
->old_val
);
2654 /* This is the first thing in the chain. */
2664 /* Find the bpstat associated with this breakpoint */
2667 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2672 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2674 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2680 /* Find a step_resume breakpoint associated with this bpstat.
2681 (If there are multiple step_resume bp's on the list, this function
2682 will arbitrarily pick one.)
2684 It is an error to use this function if BPSTAT doesn't contain a
2685 step_resume breakpoint.
2687 See wait_for_inferior's use of this function. */
2689 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2693 gdb_assert (bsp
!= NULL
);
2695 current_thread
= pid_to_thread_id (inferior_ptid
);
2697 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2699 if ((bsp
->breakpoint_at
!= NULL
)
2700 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2701 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2702 || bsp
->breakpoint_at
->owner
->thread
== -1))
2703 return bsp
->breakpoint_at
->owner
;
2706 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2710 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2711 at. *BSP upon return is a bpstat which points to the remaining
2712 breakpoints stopped at (but which is not guaranteed to be good for
2713 anything but further calls to bpstat_num).
2714 Return 0 if passed a bpstat which does not indicate any breakpoints.
2715 Return -1 if stopped at a breakpoint that has been deleted since
2717 Return 1 otherwise. */
2720 bpstat_num (bpstat
*bsp
, int *num
)
2722 struct breakpoint
*b
;
2725 return 0; /* No more breakpoint values */
2727 /* We assume we'll never have several bpstats that
2728 correspond to a single breakpoint -- otherwise,
2729 this function might return the same number more
2730 than once and this will look ugly. */
2731 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2732 *bsp
= (*bsp
)->next
;
2734 return -1; /* breakpoint that's been deleted since */
2736 *num
= b
->number
; /* We have its number */
2740 /* Modify BS so that the actions will not be performed. */
2743 bpstat_clear_actions (bpstat bs
)
2745 for (; bs
!= NULL
; bs
= bs
->next
)
2747 free_command_lines (&bs
->commands
);
2748 if (bs
->old_val
!= NULL
)
2750 value_free (bs
->old_val
);
2756 /* Called when a command is about to proceed the inferior. */
2759 breakpoint_about_to_proceed (void)
2761 if (!ptid_equal (inferior_ptid
, null_ptid
))
2763 struct thread_info
*tp
= inferior_thread ();
2765 /* Allow inferior function calls in breakpoint commands to not
2766 interrupt the command list. When the call finishes
2767 successfully, the inferior will be standing at the same
2768 breakpoint as if nothing happened. */
2773 breakpoint_proceeded
= 1;
2776 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2778 cleanup_executing_breakpoints (void *ignore
)
2780 executing_breakpoint_commands
= 0;
2783 /* Execute all the commands associated with all the breakpoints at this
2784 location. Any of these commands could cause the process to proceed
2785 beyond this point, etc. We look out for such changes by checking
2786 the global "breakpoint_proceeded" after each command.
2788 Returns true if a breakpoint command resumed the inferior. In that
2789 case, it is the caller's responsibility to recall it again with the
2790 bpstat of the current thread. */
2793 bpstat_do_actions_1 (bpstat
*bsp
)
2796 struct cleanup
*old_chain
;
2799 /* Avoid endless recursion if a `source' command is contained
2801 if (executing_breakpoint_commands
)
2804 executing_breakpoint_commands
= 1;
2805 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2807 /* This pointer will iterate over the list of bpstat's. */
2810 breakpoint_proceeded
= 0;
2811 for (; bs
!= NULL
; bs
= bs
->next
)
2813 struct command_line
*cmd
;
2814 struct cleanup
*this_cmd_tree_chain
;
2816 /* Take ownership of the BSP's command tree, if it has one.
2818 The command tree could legitimately contain commands like
2819 'step' and 'next', which call clear_proceed_status, which
2820 frees stop_bpstat's command tree. To make sure this doesn't
2821 free the tree we're executing out from under us, we need to
2822 take ownership of the tree ourselves. Since a given bpstat's
2823 commands are only executed once, we don't need to copy it; we
2824 can clear the pointer in the bpstat, and make sure we free
2825 the tree when we're done. */
2828 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2832 execute_control_command (cmd
);
2834 if (breakpoint_proceeded
)
2840 /* We can free this command tree now. */
2841 do_cleanups (this_cmd_tree_chain
);
2843 if (breakpoint_proceeded
)
2845 if (target_can_async_p ())
2846 /* If we are in async mode, then the target might be still
2847 running, not stopped at any breakpoint, so nothing for
2848 us to do here -- just return to the event loop. */
2851 /* In sync mode, when execute_control_command returns
2852 we're already standing on the next breakpoint.
2853 Breakpoint commands for that stop were not run, since
2854 execute_command does not run breakpoint commands --
2855 only command_line_handler does, but that one is not
2856 involved in execution of breakpoint commands. So, we
2857 can now execute breakpoint commands. It should be
2858 noted that making execute_command do bpstat actions is
2859 not an option -- in this case we'll have recursive
2860 invocation of bpstat for each breakpoint with a
2861 command, and can easily blow up GDB stack. Instead, we
2862 return true, which will trigger the caller to recall us
2863 with the new stop_bpstat. */
2868 do_cleanups (old_chain
);
2873 bpstat_do_actions (void)
2875 /* Do any commands attached to breakpoint we are stopped at. */
2876 while (!ptid_equal (inferior_ptid
, null_ptid
)
2877 && target_has_execution
2878 && !is_exited (inferior_ptid
)
2879 && !is_executing (inferior_ptid
))
2880 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2881 and only return when it is stopped at the next breakpoint, we
2882 keep doing breakpoint actions until it returns false to
2883 indicate the inferior was not resumed. */
2884 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2888 /* Print out the (old or new) value associated with a watchpoint. */
2891 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2894 fprintf_unfiltered (stream
, _("<unreadable>"));
2897 struct value_print_options opts
;
2898 get_user_print_options (&opts
);
2899 value_print (val
, stream
, &opts
);
2903 /* This is the normal print function for a bpstat. In the future,
2904 much of this logic could (should?) be moved to bpstat_stop_status,
2905 by having it set different print_it values.
2907 Current scheme: When we stop, bpstat_print() is called. It loops
2908 through the bpstat list of things causing this stop, calling the
2909 print_bp_stop_message function on each one. The behavior of the
2910 print_bp_stop_message function depends on the print_it field of
2911 bpstat. If such field so indicates, call this function here.
2913 Return values from this routine (ultimately used by bpstat_print()
2914 and normal_stop() to decide what to do):
2915 PRINT_NOTHING: Means we already printed all we needed to print,
2916 don't print anything else.
2917 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2918 that something to be followed by a location.
2919 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2920 that something to be followed by a location.
2921 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2924 static enum print_stop_action
2925 print_it_typical (bpstat bs
)
2927 struct cleanup
*old_chain
;
2928 struct breakpoint
*b
;
2929 const struct bp_location
*bl
;
2930 struct ui_stream
*stb
;
2932 enum print_stop_action result
;
2934 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2935 which has since been deleted. */
2936 if (bs
->breakpoint_at
== NULL
)
2937 return PRINT_UNKNOWN
;
2938 bl
= bs
->breakpoint_at
;
2941 stb
= ui_out_stream_new (uiout
);
2942 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2947 case bp_hardware_breakpoint
:
2948 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2949 if (bl
->address
!= bl
->requested_address
)
2950 breakpoint_adjustment_warning (bl
->requested_address
,
2953 annotate_breakpoint (b
->number
);
2955 ui_out_text (uiout
, "\nTemporary breakpoint ");
2957 ui_out_text (uiout
, "\nBreakpoint ");
2958 if (ui_out_is_mi_like_p (uiout
))
2960 ui_out_field_string (uiout
, "reason",
2961 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2962 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2964 ui_out_field_int (uiout
, "bkptno", b
->number
);
2965 ui_out_text (uiout
, ", ");
2966 result
= PRINT_SRC_AND_LOC
;
2969 case bp_shlib_event
:
2970 /* Did we stop because the user set the stop_on_solib_events
2971 variable? (If so, we report this as a generic, "Stopped due
2972 to shlib event" message.) */
2973 printf_filtered (_("Stopped due to shared library event\n"));
2974 result
= PRINT_NOTHING
;
2977 case bp_thread_event
:
2978 /* Not sure how we will get here.
2979 GDB should not stop for these breakpoints. */
2980 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2981 result
= PRINT_NOTHING
;
2984 case bp_overlay_event
:
2985 /* By analogy with the thread event, GDB should not stop for these. */
2986 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2987 result
= PRINT_NOTHING
;
2990 case bp_longjmp_master
:
2991 /* These should never be enabled. */
2992 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2993 result
= PRINT_NOTHING
;
2997 case bp_hardware_watchpoint
:
2998 annotate_watchpoint (b
->number
);
2999 if (ui_out_is_mi_like_p (uiout
))
3002 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3004 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3005 ui_out_text (uiout
, "\nOld value = ");
3006 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3007 ui_out_field_stream (uiout
, "old", stb
);
3008 ui_out_text (uiout
, "\nNew value = ");
3009 watchpoint_value_print (b
->val
, stb
->stream
);
3010 ui_out_field_stream (uiout
, "new", stb
);
3011 ui_out_text (uiout
, "\n");
3012 /* More than one watchpoint may have been triggered. */
3013 result
= PRINT_UNKNOWN
;
3016 case bp_read_watchpoint
:
3017 if (ui_out_is_mi_like_p (uiout
))
3020 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3022 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3023 ui_out_text (uiout
, "\nValue = ");
3024 watchpoint_value_print (b
->val
, stb
->stream
);
3025 ui_out_field_stream (uiout
, "value", stb
);
3026 ui_out_text (uiout
, "\n");
3027 result
= PRINT_UNKNOWN
;
3030 case bp_access_watchpoint
:
3031 if (bs
->old_val
!= NULL
)
3033 annotate_watchpoint (b
->number
);
3034 if (ui_out_is_mi_like_p (uiout
))
3037 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3039 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3040 ui_out_text (uiout
, "\nOld value = ");
3041 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3042 ui_out_field_stream (uiout
, "old", stb
);
3043 ui_out_text (uiout
, "\nNew value = ");
3048 if (ui_out_is_mi_like_p (uiout
))
3051 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3052 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3053 ui_out_text (uiout
, "\nValue = ");
3055 watchpoint_value_print (b
->val
, stb
->stream
);
3056 ui_out_field_stream (uiout
, "new", stb
);
3057 ui_out_text (uiout
, "\n");
3058 result
= PRINT_UNKNOWN
;
3061 /* Fall through, we don't deal with these types of breakpoints
3065 if (ui_out_is_mi_like_p (uiout
))
3068 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3069 result
= PRINT_UNKNOWN
;
3073 if (ui_out_is_mi_like_p (uiout
))
3076 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3077 result
= PRINT_UNKNOWN
;
3082 case bp_longjmp_resume
:
3083 case bp_step_resume
:
3084 case bp_watchpoint_scope
:
3087 case bp_fast_tracepoint
:
3090 result
= PRINT_UNKNOWN
;
3094 do_cleanups (old_chain
);
3098 /* Generic routine for printing messages indicating why we
3099 stopped. The behavior of this function depends on the value
3100 'print_it' in the bpstat structure. Under some circumstances we
3101 may decide not to print anything here and delegate the task to
3104 static enum print_stop_action
3105 print_bp_stop_message (bpstat bs
)
3107 switch (bs
->print_it
)
3110 /* Nothing should be printed for this bpstat entry. */
3111 return PRINT_UNKNOWN
;
3115 /* We still want to print the frame, but we already printed the
3116 relevant messages. */
3117 return PRINT_SRC_AND_LOC
;
3120 case print_it_normal
:
3122 const struct bp_location
*bl
= bs
->breakpoint_at
;
3123 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3125 /* Normal case. Call the breakpoint's print_it method, or
3126 print_it_typical. */
3127 /* FIXME: how breakpoint can ever be NULL here? */
3128 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3129 return b
->ops
->print_it (b
);
3131 return print_it_typical (bs
);
3136 internal_error (__FILE__
, __LINE__
,
3137 _("print_bp_stop_message: unrecognized enum value"));
3142 /* Print a message indicating what happened. This is called from
3143 normal_stop(). The input to this routine is the head of the bpstat
3144 list - a list of the eventpoints that caused this stop. This
3145 routine calls the generic print routine for printing a message
3146 about reasons for stopping. This will print (for example) the
3147 "Breakpoint n," part of the output. The return value of this
3150 PRINT_UNKNOWN: Means we printed nothing
3151 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3152 code to print the location. An example is
3153 "Breakpoint 1, " which should be followed by
3155 PRINT_SRC_ONLY: Means we printed something, but there is no need
3156 to also print the location part of the message.
3157 An example is the catch/throw messages, which
3158 don't require a location appended to the end.
3159 PRINT_NOTHING: We have done some printing and we don't need any
3160 further info to be printed.*/
3162 enum print_stop_action
3163 bpstat_print (bpstat bs
)
3167 /* Maybe another breakpoint in the chain caused us to stop.
3168 (Currently all watchpoints go on the bpstat whether hit or not.
3169 That probably could (should) be changed, provided care is taken
3170 with respect to bpstat_explains_signal). */
3171 for (; bs
; bs
= bs
->next
)
3173 val
= print_bp_stop_message (bs
);
3174 if (val
== PRINT_SRC_ONLY
3175 || val
== PRINT_SRC_AND_LOC
3176 || val
== PRINT_NOTHING
)
3180 /* We reached the end of the chain, or we got a null BS to start
3181 with and nothing was printed. */
3182 return PRINT_UNKNOWN
;
3185 /* Evaluate the expression EXP and return 1 if value is zero.
3186 This is used inside a catch_errors to evaluate the breakpoint condition.
3187 The argument is a "struct expression *" that has been cast to char * to
3188 make it pass through catch_errors. */
3191 breakpoint_cond_eval (void *exp
)
3193 struct value
*mark
= value_mark ();
3194 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3195 value_free_to_mark (mark
);
3199 /* Allocate a new bpstat and chain it to the current one. */
3202 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3206 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3208 bs
->breakpoint_at
= bl
;
3209 /* If the condition is false, etc., don't do the commands. */
3210 bs
->commands
= NULL
;
3212 bs
->print_it
= print_it_normal
;
3216 /* The target has stopped with waitstatus WS. Check if any hardware
3217 watchpoints have triggered, according to the target. */
3220 watchpoints_triggered (struct target_waitstatus
*ws
)
3222 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3224 struct breakpoint
*b
;
3226 if (!stopped_by_watchpoint
)
3228 /* We were not stopped by a watchpoint. Mark all watchpoints
3229 as not triggered. */
3231 if (b
->type
== bp_hardware_watchpoint
3232 || b
->type
== bp_read_watchpoint
3233 || b
->type
== bp_access_watchpoint
)
3234 b
->watchpoint_triggered
= watch_triggered_no
;
3239 if (!target_stopped_data_address (¤t_target
, &addr
))
3241 /* We were stopped by a watchpoint, but we don't know where.
3242 Mark all watchpoints as unknown. */
3244 if (b
->type
== bp_hardware_watchpoint
3245 || b
->type
== bp_read_watchpoint
3246 || b
->type
== bp_access_watchpoint
)
3247 b
->watchpoint_triggered
= watch_triggered_unknown
;
3249 return stopped_by_watchpoint
;
3252 /* The target could report the data address. Mark watchpoints
3253 affected by this data address as triggered, and all others as not
3257 if (b
->type
== bp_hardware_watchpoint
3258 || b
->type
== bp_read_watchpoint
3259 || b
->type
== bp_access_watchpoint
)
3261 struct bp_location
*loc
;
3264 b
->watchpoint_triggered
= watch_triggered_no
;
3265 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3266 /* Exact match not required. Within range is
3268 if (target_watchpoint_addr_within_range (¤t_target
,
3272 b
->watchpoint_triggered
= watch_triggered_yes
;
3280 /* Possible return values for watchpoint_check (this can't be an enum
3281 because of check_errors). */
3282 /* The watchpoint has been deleted. */
3283 #define WP_DELETED 1
3284 /* The value has changed. */
3285 #define WP_VALUE_CHANGED 2
3286 /* The value has not changed. */
3287 #define WP_VALUE_NOT_CHANGED 3
3288 /* Ignore this watchpoint, no matter if the value changed or not. */
3291 #define BP_TEMPFLAG 1
3292 #define BP_HARDWAREFLAG 2
3294 /* Evaluate watchpoint condition expression and check if its value changed.
3296 P should be a pointer to struct bpstat, but is defined as a void *
3297 in order for this function to be usable with catch_errors. */
3300 watchpoint_check (void *p
)
3302 bpstat bs
= (bpstat
) p
;
3303 struct breakpoint
*b
;
3304 struct frame_info
*fr
;
3305 int within_current_scope
;
3307 b
= bs
->breakpoint_at
->owner
;
3309 /* If this is a local watchpoint, we only want to check if the
3310 watchpoint frame is in scope if the current thread is the thread
3311 that was used to create the watchpoint. */
3312 if (!watchpoint_in_thread_scope (b
))
3315 if (b
->exp_valid_block
== NULL
)
3316 within_current_scope
= 1;
3319 struct frame_info
*frame
= get_current_frame ();
3320 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3321 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3323 /* in_function_epilogue_p() returns a non-zero value if we're still
3324 in the function but the stack frame has already been invalidated.
3325 Since we can't rely on the values of local variables after the
3326 stack has been destroyed, we are treating the watchpoint in that
3327 state as `not changed' without further checking. Don't mark
3328 watchpoints as changed if the current frame is in an epilogue -
3329 even if they are in some other frame, our view of the stack
3330 is likely to be wrong and frame_find_by_id could error out. */
3331 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3334 fr
= frame_find_by_id (b
->watchpoint_frame
);
3335 within_current_scope
= (fr
!= NULL
);
3337 /* If we've gotten confused in the unwinder, we might have
3338 returned a frame that can't describe this variable. */
3339 if (within_current_scope
)
3341 struct symbol
*function
;
3343 function
= get_frame_function (fr
);
3344 if (function
== NULL
3345 || !contained_in (b
->exp_valid_block
,
3346 SYMBOL_BLOCK_VALUE (function
)))
3347 within_current_scope
= 0;
3350 if (within_current_scope
)
3351 /* If we end up stopping, the current frame will get selected
3352 in normal_stop. So this call to select_frame won't affect
3357 if (within_current_scope
)
3359 /* We use value_{,free_to_}mark because it could be a
3360 *long* time before we return to the command level and
3361 call free_all_values. We can't call free_all_values because
3362 we might be in the middle of evaluating a function call. */
3364 struct value
*mark
= value_mark ();
3365 struct value
*new_val
;
3367 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3369 /* We use value_equal_contents instead of value_equal because the latter
3370 coerces an array to a pointer, thus comparing just the address of the
3371 array instead of its contents. This is not what we want. */
3372 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3373 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3375 if (new_val
!= NULL
)
3377 release_value (new_val
);
3378 value_free_to_mark (mark
);
3380 bs
->old_val
= b
->val
;
3383 return WP_VALUE_CHANGED
;
3387 /* Nothing changed. */
3388 value_free_to_mark (mark
);
3389 return WP_VALUE_NOT_CHANGED
;
3394 /* This seems like the only logical thing to do because
3395 if we temporarily ignored the watchpoint, then when
3396 we reenter the block in which it is valid it contains
3397 garbage (in the case of a function, it may have two
3398 garbage values, one before and one after the prologue).
3399 So we can't even detect the first assignment to it and
3400 watch after that (since the garbage may or may not equal
3401 the first value assigned). */
3402 /* We print all the stop information in print_it_typical(), but
3403 in this case, by the time we call print_it_typical() this bp
3404 will be deleted already. So we have no choice but print the
3405 information here. */
3406 if (ui_out_is_mi_like_p (uiout
))
3408 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3409 ui_out_text (uiout
, "\nWatchpoint ");
3410 ui_out_field_int (uiout
, "wpnum", b
->number
);
3411 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3412 which its expression is valid.\n");
3414 if (b
->related_breakpoint
)
3416 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3417 b
->related_breakpoint
->related_breakpoint
= NULL
;
3418 b
->related_breakpoint
= NULL
;
3420 b
->disposition
= disp_del_at_next_stop
;
3426 /* Return true if it looks like target has stopped due to hitting
3427 breakpoint location BL. This function does not check if we
3428 should stop, only if BL explains the stop. */
3430 bpstat_check_location (const struct bp_location
*bl
,
3431 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3433 struct breakpoint
*b
= bl
->owner
;
3435 /* By definition, the inferior does not report stops at
3437 if (tracepoint_type (b
))
3440 if (b
->type
!= bp_watchpoint
3441 && b
->type
!= bp_hardware_watchpoint
3442 && b
->type
!= bp_read_watchpoint
3443 && b
->type
!= bp_access_watchpoint
3444 && b
->type
!= bp_hardware_breakpoint
3445 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3447 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3450 if (overlay_debugging
/* unmapped overlay section */
3451 && section_is_overlay (bl
->section
)
3452 && !section_is_mapped (bl
->section
))
3456 /* Continuable hardware watchpoints are treated as non-existent if the
3457 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3458 some data address). Otherwise gdb won't stop on a break instruction
3459 in the code (not from a breakpoint) when a hardware watchpoint has
3460 been defined. Also skip watchpoints which we know did not trigger
3461 (did not match the data address). */
3463 if ((b
->type
== bp_hardware_watchpoint
3464 || b
->type
== bp_read_watchpoint
3465 || b
->type
== bp_access_watchpoint
)
3466 && b
->watchpoint_triggered
== watch_triggered_no
)
3469 if (b
->type
== bp_hardware_breakpoint
)
3471 if (bl
->address
!= bp_addr
)
3473 if (overlay_debugging
/* unmapped overlay section */
3474 && section_is_overlay (bl
->section
)
3475 && !section_is_mapped (bl
->section
))
3479 if (b
->type
== bp_catchpoint
)
3481 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3482 if (!b
->ops
->breakpoint_hit (b
))
3489 /* If BS refers to a watchpoint, determine if the watched values
3490 has actually changed, and we should stop. If not, set BS->stop
3493 bpstat_check_watchpoint (bpstat bs
)
3495 const struct bp_location
*bl
= bs
->breakpoint_at
;
3496 struct breakpoint
*b
= bl
->owner
;
3498 if (b
->type
== bp_watchpoint
3499 || b
->type
== bp_read_watchpoint
3500 || b
->type
== bp_access_watchpoint
3501 || b
->type
== bp_hardware_watchpoint
)
3505 int must_check_value
= 0;
3507 if (b
->type
== bp_watchpoint
)
3508 /* For a software watchpoint, we must always check the
3510 must_check_value
= 1;
3511 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3512 /* We have a hardware watchpoint (read, write, or access)
3513 and the target earlier reported an address watched by
3515 must_check_value
= 1;
3516 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3517 && b
->type
== bp_hardware_watchpoint
)
3518 /* We were stopped by a hardware watchpoint, but the target could
3519 not report the data address. We must check the watchpoint's
3520 value. Access and read watchpoints are out of luck; without
3521 a data address, we can't figure it out. */
3522 must_check_value
= 1;
3524 if (must_check_value
)
3526 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3528 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3529 int e
= catch_errors (watchpoint_check
, bs
, message
,
3531 do_cleanups (cleanups
);
3535 /* We've already printed what needs to be printed. */
3536 bs
->print_it
= print_it_done
;
3540 bs
->print_it
= print_it_noop
;
3543 case WP_VALUE_CHANGED
:
3544 if (b
->type
== bp_read_watchpoint
)
3546 /* There are two cases to consider here:
3548 1. we're watching the triggered memory for reads.
3549 In that case, trust the target, and always report
3550 the watchpoint hit to the user. Even though
3551 reads don't cause value changes, the value may
3552 have changed since the last time it was read, and
3553 since we're not trapping writes, we will not see
3554 those, and as such we should ignore our notion of
3557 2. we're watching the triggered memory for both
3558 reads and writes. There are two ways this may
3561 2.1. this is a target that can't break on data
3562 reads only, but can break on accesses (reads or
3563 writes), such as e.g., x86. We detect this case
3564 at the time we try to insert read watchpoints.
3566 2.2. otherwise, the target supports read
3567 watchpoints, but, the user set an access or write
3568 watchpoint watching the same memory as this read
3571 If we're watching memory writes as well as reads,
3572 ignore watchpoint hits when we find that the
3573 value hasn't changed, as reads don't cause
3574 changes. This still gives false positives when
3575 the program writes the same value to memory as
3576 what there was already in memory (we will confuse
3577 it for a read), but it's much better than
3580 int other_write_watchpoint
= 0;
3582 if (bl
->watchpoint_type
== hw_read
)
3584 struct breakpoint
*other_b
;
3586 ALL_BREAKPOINTS (other_b
)
3587 if ((other_b
->type
== bp_hardware_watchpoint
3588 || other_b
->type
== bp_access_watchpoint
)
3589 && (other_b
->watchpoint_triggered
3590 == watch_triggered_yes
))
3592 other_write_watchpoint
= 1;
3597 if (other_write_watchpoint
3598 || bl
->watchpoint_type
== hw_access
)
3600 /* We're watching the same memory for writes,
3601 and the value changed since the last time we
3602 updated it, so this trap must be for a write.
3604 bs
->print_it
= print_it_noop
;
3609 case WP_VALUE_NOT_CHANGED
:
3610 if (b
->type
== bp_hardware_watchpoint
3611 || b
->type
== bp_watchpoint
)
3613 /* Don't stop: write watchpoints shouldn't fire if
3614 the value hasn't changed. */
3615 bs
->print_it
= print_it_noop
;
3623 /* Error from catch_errors. */
3624 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3625 if (b
->related_breakpoint
)
3626 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3627 b
->disposition
= disp_del_at_next_stop
;
3628 /* We've already printed what needs to be printed. */
3629 bs
->print_it
= print_it_done
;
3633 else /* must_check_value == 0 */
3635 /* This is a case where some watchpoint(s) triggered, but
3636 not at the address of this watchpoint, or else no
3637 watchpoint triggered after all. So don't print
3638 anything for this watchpoint. */
3639 bs
->print_it
= print_it_noop
;
3646 /* Check conditions (condition proper, frame, thread and ignore count)
3647 of breakpoint referred to by BS. If we should not stop for this
3648 breakpoint, set BS->stop to 0. */
3650 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3652 int thread_id
= pid_to_thread_id (ptid
);
3653 const struct bp_location
*bl
= bs
->breakpoint_at
;
3654 struct breakpoint
*b
= bl
->owner
;
3656 if (frame_id_p (b
->frame_id
)
3657 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3661 int value_is_zero
= 0;
3662 struct expression
*cond
;
3664 /* If this is a scope breakpoint, mark the associated
3665 watchpoint as triggered so that we will handle the
3666 out-of-scope event. We'll get to the watchpoint next
3668 if (b
->type
== bp_watchpoint_scope
)
3669 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3671 if (is_watchpoint (b
))
3676 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3678 int within_current_scope
= 1;
3680 /* We use value_mark and value_free_to_mark because it could
3681 be a long time before we return to the command level and
3682 call free_all_values. We can't call free_all_values
3683 because we might be in the middle of evaluating a
3685 struct value
*mark
= value_mark ();
3687 /* Need to select the frame, with all that implies so that
3688 the conditions will have the right context. Because we
3689 use the frame, we will not see an inlined function's
3690 variables when we arrive at a breakpoint at the start
3691 of the inlined function; the current frame will be the
3693 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3694 select_frame (get_current_frame ());
3697 struct frame_info
*frame
;
3699 /* For local watchpoint expressions, which particular
3700 instance of a local is being watched matters, so we
3701 keep track of the frame to evaluate the expression
3702 in. To evaluate the condition however, it doesn't
3703 really matter which instantiation of the function
3704 where the condition makes sense triggers the
3705 watchpoint. This allows an expression like "watch
3706 global if q > 10" set in `func', catch writes to
3707 global on all threads that call `func', or catch
3708 writes on all recursive calls of `func' by a single
3709 thread. We simply always evaluate the condition in
3710 the innermost frame that's executing where it makes
3711 sense to evaluate the condition. It seems
3713 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3715 select_frame (frame
);
3717 within_current_scope
= 0;
3719 if (within_current_scope
)
3721 = catch_errors (breakpoint_cond_eval
, cond
,
3722 "Error in testing breakpoint condition:\n",
3726 warning (_("Watchpoint condition cannot be tested "
3727 "in the current scope"));
3728 /* If we failed to set the right context for this
3729 watchpoint, unconditionally report it. */
3732 /* FIXME-someday, should give breakpoint # */
3733 value_free_to_mark (mark
);
3736 if (cond
&& value_is_zero
)
3740 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3744 else if (b
->ignore_count
> 0)
3747 annotate_ignore_count_change ();
3749 /* Increase the hit count even though we don't
3757 /* Get a bpstat associated with having just stopped at address
3758 BP_ADDR in thread PTID.
3760 Determine whether we stopped at a breakpoint, etc, or whether we
3761 don't understand this stop. Result is a chain of bpstat's such that:
3763 if we don't understand the stop, the result is a null pointer.
3765 if we understand why we stopped, the result is not null.
3767 Each element of the chain refers to a particular breakpoint or
3768 watchpoint at which we have stopped. (We may have stopped for
3769 several reasons concurrently.)
3771 Each element of the chain has valid next, breakpoint_at,
3772 commands, FIXME??? fields. */
3775 bpstat_stop_status (struct address_space
*aspace
,
3776 CORE_ADDR bp_addr
, ptid_t ptid
)
3778 struct breakpoint
*b
= NULL
;
3779 struct bp_location
*bl
, **blp_tmp
;
3780 struct bp_location
*loc
;
3781 /* Root of the chain of bpstat's */
3782 struct bpstats root_bs
[1];
3783 /* Pointer to the last thing in the chain currently. */
3784 bpstat bs
= root_bs
;
3786 int need_remove_insert
;
3788 /* ALL_BP_LOCATIONS iteration would break across
3789 update_global_location_list possibly executed by
3790 bpstat_check_breakpoint_conditions's inferior call. */
3794 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3797 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
3799 /* For hardware watchpoints, we look only at the first location.
3800 The watchpoint_check function will work on entire expression,
3801 not the individual locations. For read watchopints, the
3802 watchpoints_triggered function have checked all locations
3804 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3807 if (bl
->shlib_disabled
)
3810 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
3813 /* Come here if it's a watchpoint, or if the break address matches */
3815 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3817 /* Assume we stop. Should we find watchpoint that is not actually
3818 triggered, or if condition of breakpoint is false, we'll reset
3823 bpstat_check_watchpoint (bs
);
3827 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3828 || b
->type
== bp_longjmp_master
)
3829 /* We do not stop for these. */
3832 bpstat_check_breakpoint_conditions (bs
, ptid
);
3838 /* We will stop here */
3839 if (b
->disposition
== disp_disable
)
3841 if (b
->enable_state
!= bp_permanent
)
3842 b
->enable_state
= bp_disabled
;
3843 update_global_location_list (0);
3847 bs
->commands
= b
->commands
;
3849 && (strcmp ("silent", bs
->commands
->line
) == 0
3850 || (xdb_commands
&& strcmp ("Q",
3851 bs
->commands
->line
) == 0)))
3853 bs
->commands
= bs
->commands
->next
;
3856 bs
->commands
= copy_command_lines (bs
->commands
);
3859 /* Print nothing for this entry if we dont stop or dont print. */
3860 if (bs
->stop
== 0 || bs
->print
== 0)
3861 bs
->print_it
= print_it_noop
;
3865 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3867 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
3870 bs
= bpstat_alloc (loc
, bs
);
3871 /* For hits of moribund locations, we should just proceed. */
3874 bs
->print_it
= print_it_noop
;
3878 bs
->next
= NULL
; /* Terminate the chain */
3880 /* If we aren't stopping, the value of some hardware watchpoint may
3881 not have changed, but the intermediate memory locations we are
3882 watching may have. Don't bother if we're stopping; this will get
3884 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3888 need_remove_insert
= 0;
3890 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3892 && bs
->breakpoint_at
->owner
3893 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
3895 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
3896 /* Updating watchpoints invalidates bs->breakpoint_at.
3897 Prevent further code from trying to use it. */
3898 bs
->breakpoint_at
= NULL
;
3899 need_remove_insert
= 1;
3902 if (need_remove_insert
)
3903 update_global_location_list (1);
3905 return root_bs
->next
;
3908 /* Tell what to do about this bpstat. */
3910 bpstat_what (bpstat bs
)
3912 /* Classify each bpstat as one of the following. */
3915 /* This bpstat element has no effect on the main_action. */
3918 /* There was a watchpoint, stop but don't print. */
3921 /* There was a watchpoint, stop and print. */
3924 /* There was a breakpoint but we're not stopping. */
3927 /* There was a breakpoint, stop but don't print. */
3930 /* There was a breakpoint, stop and print. */
3933 /* We hit the longjmp breakpoint. */
3936 /* We hit the longjmp_resume breakpoint. */
3939 /* We hit the step_resume breakpoint. */
3942 /* We hit the shared library event breakpoint. */
3945 /* We hit the jit event breakpoint. */
3948 /* This is just used to count how many enums there are. */
3952 /* Here is the table which drives this routine. So that we can
3953 format it pretty, we define some abbreviations for the
3954 enum bpstat_what codes. */
3955 #define kc BPSTAT_WHAT_KEEP_CHECKING
3956 #define ss BPSTAT_WHAT_STOP_SILENT
3957 #define sn BPSTAT_WHAT_STOP_NOISY
3958 #define sgl BPSTAT_WHAT_SINGLE
3959 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3960 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3961 #define sr BPSTAT_WHAT_STEP_RESUME
3962 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3963 #define jit BPSTAT_WHAT_CHECK_JIT
3965 /* "Can't happen." Might want to print an error message.
3966 abort() is not out of the question, but chances are GDB is just
3967 a bit confused, not unusable. */
3968 #define err BPSTAT_WHAT_STOP_NOISY
3970 /* Given an old action and a class, come up with a new action. */
3971 /* One interesting property of this table is that wp_silent is the same
3972 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3973 after stopping, the check for whether to step over a breakpoint
3974 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3975 reference to how we stopped. We retain separate wp_silent and
3976 bp_silent codes in case we want to change that someday.
3978 Another possibly interesting property of this table is that
3979 there's a partial ordering, priority-like, of the actions. Once
3980 you've decided that some action is appropriate, you'll never go
3981 back and decide something of a lower priority is better. The
3984 kc < jit clr sgl shl slr sn sr ss
3985 sgl < jit shl slr sn sr ss
3986 slr < jit err shl sn sr ss
3987 clr < jit err shl sn sr ss
3994 What I think this means is that we don't need a damned table
3995 here. If you just put the rows and columns in the right order,
3996 it'd look awfully regular. We could simply walk the bpstat list
3997 and choose the highest priority action we find, with a little
3998 logic to handle the 'err' cases. */
4000 /* step_resume entries: a step resume breakpoint overrides another
4001 breakpoint of signal handling (see comment in wait_for_inferior
4002 at where we set the step_resume breakpoint). */
4004 static const enum bpstat_what_main_action
4005 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4008 /* kc ss sn sgl slr clr sr shl jit */
4009 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4010 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4011 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4012 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4013 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4014 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4015 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4016 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4017 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4018 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4019 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4033 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4034 struct bpstat_what retval
;
4036 retval
.call_dummy
= 0;
4037 for (; bs
!= NULL
; bs
= bs
->next
)
4039 enum class bs_class
= no_effect
;
4040 if (bs
->breakpoint_at
== NULL
)
4041 /* I suspect this can happen if it was a momentary breakpoint
4042 which has since been deleted. */
4044 if (bs
->breakpoint_at
->owner
== NULL
)
4045 bs_class
= bp_nostop
;
4047 switch (bs
->breakpoint_at
->owner
->type
)
4053 case bp_hardware_breakpoint
:
4059 bs_class
= bp_noisy
;
4061 bs_class
= bp_silent
;
4064 bs_class
= bp_nostop
;
4067 case bp_hardware_watchpoint
:
4068 case bp_read_watchpoint
:
4069 case bp_access_watchpoint
:
4073 bs_class
= wp_noisy
;
4075 bs_class
= wp_silent
;
4078 /* There was a watchpoint, but we're not stopping.
4079 This requires no further action. */
4080 bs_class
= no_effect
;
4083 bs_class
= long_jump
;
4085 case bp_longjmp_resume
:
4086 bs_class
= long_resume
;
4088 case bp_step_resume
:
4091 bs_class
= step_resume
;
4094 /* It is for the wrong frame. */
4095 bs_class
= bp_nostop
;
4097 case bp_watchpoint_scope
:
4098 bs_class
= bp_nostop
;
4100 case bp_shlib_event
:
4101 bs_class
= shlib_event
;
4104 bs_class
= jit_event
;
4106 case bp_thread_event
:
4107 case bp_overlay_event
:
4108 case bp_longjmp_master
:
4109 bs_class
= bp_nostop
;
4115 bs_class
= bp_noisy
;
4117 bs_class
= bp_silent
;
4120 /* There was a catchpoint, but we're not stopping.
4121 This requires no further action. */
4122 bs_class
= no_effect
;
4125 /* Make sure the action is stop (silent or noisy),
4126 so infrun.c pops the dummy frame. */
4127 bs_class
= bp_silent
;
4128 retval
.call_dummy
= 1;
4131 case bp_fast_tracepoint
:
4132 /* Tracepoint hits should not be reported back to GDB, and
4133 if one got through somehow, it should have been filtered
4135 internal_error (__FILE__
, __LINE__
,
4136 _("bpstat_what: tracepoint encountered"));
4139 current_action
= table
[(int) bs_class
][(int) current_action
];
4141 retval
.main_action
= current_action
;
4145 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4146 without hardware support). This isn't related to a specific bpstat,
4147 just to things like whether watchpoints are set. */
4150 bpstat_should_step (void)
4152 struct breakpoint
*b
;
4154 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4160 bpstat_causes_stop (bpstat bs
)
4162 for (; bs
!= NULL
; bs
= bs
->next
)
4171 /* Print the LOC location out of the list of B->LOC locations. */
4173 static void print_breakpoint_location (struct breakpoint
*b
,
4174 struct bp_location
*loc
,
4176 struct ui_stream
*stb
)
4178 struct cleanup
*old_chain
= save_current_program_space ();
4180 if (loc
!= NULL
&& loc
->shlib_disabled
)
4184 set_current_program_space (loc
->pspace
);
4186 if (b
->source_file
&& loc
)
4189 = find_pc_sect_function (loc
->address
, loc
->section
);
4192 ui_out_text (uiout
, "in ");
4193 ui_out_field_string (uiout
, "func",
4194 SYMBOL_PRINT_NAME (sym
));
4195 ui_out_wrap_hint (uiout
, wrap_indent
);
4196 ui_out_text (uiout
, " at ");
4198 ui_out_field_string (uiout
, "file", b
->source_file
);
4199 ui_out_text (uiout
, ":");
4201 if (ui_out_is_mi_like_p (uiout
))
4203 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4204 char *fullname
= symtab_to_fullname (sal
.symtab
);
4207 ui_out_field_string (uiout
, "fullname", fullname
);
4210 ui_out_field_int (uiout
, "line", b
->line_number
);
4214 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4216 ui_out_field_stream (uiout
, "at", stb
);
4219 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4221 do_cleanups (old_chain
);
4224 /* Print B to gdb_stdout. */
4226 print_one_breakpoint_location (struct breakpoint
*b
,
4227 struct bp_location
*loc
,
4229 struct bp_location
**last_loc
,
4230 int print_address_bits
,
4233 struct command_line
*l
;
4235 struct ep_type_description
4240 static struct ep_type_description bptypes
[] =
4242 {bp_none
, "?deleted?"},
4243 {bp_breakpoint
, "breakpoint"},
4244 {bp_hardware_breakpoint
, "hw breakpoint"},
4245 {bp_until
, "until"},
4246 {bp_finish
, "finish"},
4247 {bp_watchpoint
, "watchpoint"},
4248 {bp_hardware_watchpoint
, "hw watchpoint"},
4249 {bp_read_watchpoint
, "read watchpoint"},
4250 {bp_access_watchpoint
, "acc watchpoint"},
4251 {bp_longjmp
, "longjmp"},
4252 {bp_longjmp_resume
, "longjmp resume"},
4253 {bp_step_resume
, "step resume"},
4254 {bp_watchpoint_scope
, "watchpoint scope"},
4255 {bp_call_dummy
, "call dummy"},
4256 {bp_shlib_event
, "shlib events"},
4257 {bp_thread_event
, "thread events"},
4258 {bp_overlay_event
, "overlay events"},
4259 {bp_longjmp_master
, "longjmp master"},
4260 {bp_catchpoint
, "catchpoint"},
4261 {bp_tracepoint
, "tracepoint"},
4262 {bp_fast_tracepoint
, "fast tracepoint"},
4263 {bp_jit_event
, "jit events"},
4266 static char bpenables
[] = "nynny";
4267 char wrap_indent
[80];
4268 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4269 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4270 struct cleanup
*bkpt_chain
;
4272 int header_of_multiple
= 0;
4273 int part_of_multiple
= (loc
!= NULL
);
4274 struct value_print_options opts
;
4276 get_user_print_options (&opts
);
4278 gdb_assert (!loc
|| loc_number
!= 0);
4279 /* See comment in print_one_breakpoint concerning
4280 treatment of breakpoints with single disabled
4284 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4285 header_of_multiple
= 1;
4290 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4294 if (part_of_multiple
)
4297 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4298 ui_out_field_string (uiout
, "number", formatted
);
4303 ui_out_field_int (uiout
, "number", b
->number
);
4308 if (part_of_multiple
)
4309 ui_out_field_skip (uiout
, "type");
4312 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4313 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4314 internal_error (__FILE__
, __LINE__
,
4315 _("bptypes table does not describe type #%d."),
4317 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4322 if (part_of_multiple
)
4323 ui_out_field_skip (uiout
, "disp");
4325 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4330 if (part_of_multiple
)
4331 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4333 ui_out_field_fmt (uiout
, "enabled", "%c",
4334 bpenables
[(int) b
->enable_state
]);
4335 ui_out_spaces (uiout
, 2);
4339 strcpy (wrap_indent
, " ");
4340 if (opts
.addressprint
)
4342 if (print_address_bits
<= 32)
4343 strcat (wrap_indent
, " ");
4345 strcat (wrap_indent
, " ");
4348 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4350 /* Although the print_one can possibly print
4351 all locations, calling it here is not likely
4352 to get any nice result. So, make sure there's
4353 just one location. */
4354 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4355 b
->ops
->print_one (b
, last_loc
);
4361 internal_error (__FILE__
, __LINE__
,
4362 _("print_one_breakpoint: bp_none encountered\n"));
4366 case bp_hardware_watchpoint
:
4367 case bp_read_watchpoint
:
4368 case bp_access_watchpoint
:
4369 /* Field 4, the address, is omitted (which makes the columns
4370 not line up too nicely with the headers, but the effect
4371 is relatively readable). */
4372 if (opts
.addressprint
)
4373 ui_out_field_skip (uiout
, "addr");
4375 ui_out_field_string (uiout
, "what", b
->exp_string
);
4379 case bp_hardware_breakpoint
:
4383 case bp_longjmp_resume
:
4384 case bp_step_resume
:
4385 case bp_watchpoint_scope
:
4387 case bp_shlib_event
:
4388 case bp_thread_event
:
4389 case bp_overlay_event
:
4390 case bp_longjmp_master
:
4392 case bp_fast_tracepoint
:
4394 if (opts
.addressprint
)
4397 if (header_of_multiple
)
4398 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4399 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4400 ui_out_field_string (uiout
, "addr", "<PENDING>");
4402 ui_out_field_core_addr (uiout
, "addr",
4403 loc
->gdbarch
, loc
->address
);
4406 if (!header_of_multiple
)
4407 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4414 /* For backward compatibility, don't display inferiors unless there
4417 && !header_of_multiple
4419 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4420 && (number_of_program_spaces () > 1
4421 || number_of_inferiors () > 1)
4422 && loc
->owner
->type
!= bp_catchpoint
)))
4424 struct inferior
*inf
;
4427 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4429 if (inf
->pspace
== loc
->pspace
)
4434 ui_out_text (uiout
, " inf ");
4437 ui_out_text (uiout
, ", ");
4438 ui_out_text (uiout
, plongest (inf
->num
));
4443 if (!part_of_multiple
)
4445 if (b
->thread
!= -1)
4447 /* FIXME: This seems to be redundant and lost here; see the
4448 "stop only in" line a little further down. */
4449 ui_out_text (uiout
, " thread ");
4450 ui_out_field_int (uiout
, "thread", b
->thread
);
4452 else if (b
->task
!= 0)
4454 ui_out_text (uiout
, " task ");
4455 ui_out_field_int (uiout
, "task", b
->task
);
4459 ui_out_text (uiout
, "\n");
4461 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4464 ui_out_text (uiout
, "\tstop only in stack frame at ");
4465 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4467 ui_out_field_core_addr (uiout
, "frame",
4468 b
->gdbarch
, b
->frame_id
.stack_addr
);
4469 ui_out_text (uiout
, "\n");
4472 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4474 /* We do not print the condition for Ada exception catchpoints
4475 because the condition is an internal implementation detail
4476 that we do not want to expose to the user. */
4478 if (tracepoint_type (b
))
4479 ui_out_text (uiout
, "\ttrace only if ");
4481 ui_out_text (uiout
, "\tstop only if ");
4482 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4483 ui_out_text (uiout
, "\n");
4486 if (!part_of_multiple
&& b
->thread
!= -1)
4488 /* FIXME should make an annotation for this */
4489 ui_out_text (uiout
, "\tstop only in thread ");
4490 ui_out_field_int (uiout
, "thread", b
->thread
);
4491 ui_out_text (uiout
, "\n");
4494 if (!part_of_multiple
&& b
->hit_count
)
4496 /* FIXME should make an annotation for this */
4497 if (ep_is_catchpoint (b
))
4498 ui_out_text (uiout
, "\tcatchpoint");
4500 ui_out_text (uiout
, "\tbreakpoint");
4501 ui_out_text (uiout
, " already hit ");
4502 ui_out_field_int (uiout
, "times", b
->hit_count
);
4503 if (b
->hit_count
== 1)
4504 ui_out_text (uiout
, " time\n");
4506 ui_out_text (uiout
, " times\n");
4509 /* Output the count also if it is zero, but only if this is
4510 mi. FIXME: Should have a better test for this. */
4511 if (ui_out_is_mi_like_p (uiout
))
4512 if (!part_of_multiple
&& b
->hit_count
== 0)
4513 ui_out_field_int (uiout
, "times", b
->hit_count
);
4515 if (!part_of_multiple
&& b
->ignore_count
)
4518 ui_out_text (uiout
, "\tignore next ");
4519 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4520 ui_out_text (uiout
, " hits\n");
4524 if (!part_of_multiple
&& l
)
4526 struct cleanup
*script_chain
;
4529 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4530 print_command_lines (uiout
, l
, 4);
4531 do_cleanups (script_chain
);
4534 if (!part_of_multiple
&& b
->pass_count
)
4536 annotate_field (10);
4537 ui_out_text (uiout
, "\tpass count ");
4538 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4539 ui_out_text (uiout
, " \n");
4542 if (!part_of_multiple
&& b
->step_count
)
4544 annotate_field (11);
4545 ui_out_text (uiout
, "\tstep count ");
4546 ui_out_field_int (uiout
, "step", b
->step_count
);
4547 ui_out_text (uiout
, " \n");
4550 if (!part_of_multiple
&& b
->actions
)
4552 struct action_line
*action
;
4553 annotate_field (12);
4554 for (action
= b
->actions
; action
; action
= action
->next
)
4556 ui_out_text (uiout
, " A\t");
4557 ui_out_text (uiout
, action
->action
);
4558 ui_out_text (uiout
, "\n");
4562 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4565 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4566 else if (b
->exp_string
)
4567 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4570 do_cleanups (bkpt_chain
);
4571 do_cleanups (old_chain
);
4575 print_one_breakpoint (struct breakpoint
*b
,
4576 struct bp_location
**last_loc
, int print_address_bits
,
4579 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4580 print_address_bits
, allflag
);
4582 /* If this breakpoint has custom print function,
4583 it's already printed. Otherwise, print individual
4584 locations, if any. */
4585 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4587 /* If breakpoint has a single location that is
4588 disabled, we print it as if it had
4589 several locations, since otherwise it's hard to
4590 represent "breakpoint enabled, location disabled"
4592 Note that while hardware watchpoints have
4593 several locations internally, that's no a property
4596 && !is_hardware_watchpoint (b
)
4597 && (b
->loc
->next
|| !b
->loc
->enabled
)
4598 && !ui_out_is_mi_like_p (uiout
))
4600 struct bp_location
*loc
;
4602 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4603 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4604 print_address_bits
, allflag
);
4610 breakpoint_address_bits (struct breakpoint
*b
)
4612 int print_address_bits
= 0;
4613 struct bp_location
*loc
;
4615 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4619 /* Software watchpoints that aren't watching memory don't have
4620 an address to print. */
4621 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4624 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4625 if (addr_bit
> print_address_bits
)
4626 print_address_bits
= addr_bit
;
4629 return print_address_bits
;
4632 struct captured_breakpoint_query_args
4638 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4640 struct captured_breakpoint_query_args
*args
= data
;
4641 struct breakpoint
*b
;
4642 struct bp_location
*dummy_loc
= NULL
;
4645 if (args
->bnum
== b
->number
)
4647 int print_address_bits
= breakpoint_address_bits (b
);
4648 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4656 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4658 struct captured_breakpoint_query_args args
;
4660 /* For the moment we don't trust print_one_breakpoint() to not throw
4662 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4663 error_message
, RETURN_MASK_ALL
) < 0)
4669 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4670 catchpoints, et.al.). */
4673 user_settable_breakpoint (const struct breakpoint
*b
)
4675 return (b
->type
== bp_breakpoint
4676 || b
->type
== bp_catchpoint
4677 || b
->type
== bp_hardware_breakpoint
4678 || tracepoint_type (b
)
4679 || b
->type
== bp_watchpoint
4680 || b
->type
== bp_read_watchpoint
4681 || b
->type
== bp_access_watchpoint
4682 || b
->type
== bp_hardware_watchpoint
);
4685 /* Print information on user settable breakpoint (watchpoint, etc)
4686 number BNUM. If BNUM is -1 print all user settable breakpoints.
4687 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4690 breakpoint_1 (int bnum
, int allflag
)
4692 struct breakpoint
*b
;
4693 struct bp_location
*last_loc
= NULL
;
4694 int nr_printable_breakpoints
;
4695 struct cleanup
*bkpttbl_chain
;
4696 struct value_print_options opts
;
4697 int print_address_bits
= 0;
4699 get_user_print_options (&opts
);
4701 /* Compute the number of rows in the table, as well as the
4702 size required for address fields. */
4703 nr_printable_breakpoints
= 0;
4706 || bnum
== b
->number
)
4708 if (allflag
|| user_settable_breakpoint (b
))
4710 int addr_bit
= breakpoint_address_bits (b
);
4711 if (addr_bit
> print_address_bits
)
4712 print_address_bits
= addr_bit
;
4714 nr_printable_breakpoints
++;
4718 if (opts
.addressprint
)
4720 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4724 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4727 if (nr_printable_breakpoints
> 0)
4728 annotate_breakpoints_headers ();
4729 if (nr_printable_breakpoints
> 0)
4731 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4732 if (nr_printable_breakpoints
> 0)
4734 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4735 if (nr_printable_breakpoints
> 0)
4737 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4738 if (nr_printable_breakpoints
> 0)
4740 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4741 if (opts
.addressprint
)
4743 if (nr_printable_breakpoints
> 0)
4745 if (print_address_bits
<= 32)
4746 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4748 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4750 if (nr_printable_breakpoints
> 0)
4752 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4753 ui_out_table_body (uiout
);
4754 if (nr_printable_breakpoints
> 0)
4755 annotate_breakpoints_table ();
4761 || bnum
== b
->number
)
4763 /* We only print out user settable breakpoints unless the
4765 if (allflag
|| user_settable_breakpoint (b
))
4766 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
4770 do_cleanups (bkpttbl_chain
);
4772 if (nr_printable_breakpoints
== 0)
4775 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4777 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4782 if (last_loc
&& !server_command
)
4783 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4786 /* FIXME? Should this be moved up so that it is only called when
4787 there have been breakpoints? */
4788 annotate_breakpoints_table_end ();
4792 breakpoints_info (char *bnum_exp
, int from_tty
)
4797 bnum
= parse_and_eval_long (bnum_exp
);
4799 breakpoint_1 (bnum
, 0);
4803 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4808 bnum
= parse_and_eval_long (bnum_exp
);
4810 breakpoint_1 (bnum
, 1);
4814 breakpoint_has_pc (struct breakpoint
*b
,
4815 struct program_space
*pspace
,
4816 CORE_ADDR pc
, struct obj_section
*section
)
4818 struct bp_location
*bl
= b
->loc
;
4819 for (; bl
; bl
= bl
->next
)
4821 if (bl
->pspace
== pspace
4822 && bl
->address
== pc
4823 && (!overlay_debugging
|| bl
->section
== section
))
4829 /* Print a message describing any breakpoints set at PC. This
4830 concerns with logical breakpoints, so we match program spaces, not
4834 describe_other_breakpoints (struct gdbarch
*gdbarch
,
4835 struct program_space
*pspace
, CORE_ADDR pc
,
4836 struct obj_section
*section
, int thread
)
4839 struct breakpoint
*b
;
4842 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
4846 printf_filtered (_("Note: breakpoint "));
4847 else /* if (others == ???) */
4848 printf_filtered (_("Note: breakpoints "));
4850 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
4853 printf_filtered ("%d", b
->number
);
4854 if (b
->thread
== -1 && thread
!= -1)
4855 printf_filtered (" (all threads)");
4856 else if (b
->thread
!= -1)
4857 printf_filtered (" (thread %d)", b
->thread
);
4858 printf_filtered ("%s%s ",
4859 ((b
->enable_state
== bp_disabled
4860 || b
->enable_state
== bp_call_disabled
4861 || b
->enable_state
== bp_startup_disabled
)
4863 : b
->enable_state
== bp_permanent
4867 : ((others
== 1) ? " and" : ""));
4869 printf_filtered (_("also set at pc "));
4870 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4871 printf_filtered (".\n");
4875 /* Set the default place to put a breakpoint
4876 for the `break' command with no arguments. */
4879 set_default_breakpoint (int valid
, struct program_space
*pspace
,
4880 CORE_ADDR addr
, struct symtab
*symtab
,
4883 default_breakpoint_valid
= valid
;
4884 default_breakpoint_pspace
= pspace
;
4885 default_breakpoint_address
= addr
;
4886 default_breakpoint_symtab
= symtab
;
4887 default_breakpoint_line
= line
;
4890 /* Return true iff it is meaningful to use the address member of
4891 BPT. For some breakpoint types, the address member is irrelevant
4892 and it makes no sense to attempt to compare it to other addresses
4893 (or use it for any other purpose either).
4895 More specifically, each of the following breakpoint types will always
4896 have a zero valued address and we don't want to mark breakpoints of any of
4897 these types to be a duplicate of an actual breakpoint at address zero:
4905 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4907 enum bptype type
= bpt
->type
;
4909 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
4912 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
4913 true if LOC1 and LOC2 represent the same watchpoint location. */
4916 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
4918 /* Note that this checks the owner's type, not the location's. In
4919 case the target does not support read watchpoints, but does
4920 support access watchpoints, we'll have bp_read_watchpoint
4921 watchpoints with hw_access locations. Those should be considered
4922 duplicates of hw_read locations. The hw_read locations will
4923 become hw_access locations later. */
4924 return (loc1
->owner
->type
== loc2
->owner
->type
4925 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
4926 && loc1
->address
== loc2
->address
4927 && loc1
->length
== loc2
->length
);
4930 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
4931 same breakpoint location. In most targets, this can only be true
4932 if ASPACE1 matches ASPACE2. On targets that have global
4933 breakpoints, the address space doesn't really matter. */
4936 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
4937 struct address_space
*aspace2
, CORE_ADDR addr2
)
4939 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
4940 || aspace1
== aspace2
)
4944 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
4945 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
4946 represent the same location. */
4949 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
4951 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
4952 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
4954 if (hw_point1
!= hw_point2
)
4957 return watchpoint_locations_match (loc1
, loc2
);
4959 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
4960 loc2
->pspace
->aspace
, loc2
->address
);
4964 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4965 int bnum
, int have_bnum
)
4970 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4971 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4973 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4974 bnum
, astr1
, astr2
);
4976 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4979 /* Adjust a breakpoint's address to account for architectural constraints
4980 on breakpoint placement. Return the adjusted address. Note: Very
4981 few targets require this kind of adjustment. For most targets,
4982 this function is simply the identity function. */
4985 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4986 CORE_ADDR bpaddr
, enum bptype bptype
)
4988 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4990 /* Very few targets need any kind of breakpoint adjustment. */
4993 else if (bptype
== bp_watchpoint
4994 || bptype
== bp_hardware_watchpoint
4995 || bptype
== bp_read_watchpoint
4996 || bptype
== bp_access_watchpoint
4997 || bptype
== bp_catchpoint
)
4999 /* Watchpoints and the various bp_catch_* eventpoints should not
5000 have their addresses modified. */
5005 CORE_ADDR adjusted_bpaddr
;
5007 /* Some targets have architectural constraints on the placement
5008 of breakpoint instructions. Obtain the adjusted address. */
5009 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5011 /* An adjusted breakpoint address can significantly alter
5012 a user's expectations. Print a warning if an adjustment
5014 if (adjusted_bpaddr
!= bpaddr
)
5015 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5017 return adjusted_bpaddr
;
5021 /* Allocate a struct bp_location. */
5023 static struct bp_location
*
5024 allocate_bp_location (struct breakpoint
*bpt
)
5026 struct bp_location
*loc
, *loc_p
;
5028 loc
= xmalloc (sizeof (struct bp_location
));
5029 memset (loc
, 0, sizeof (*loc
));
5033 loc
->shlib_disabled
= 0;
5042 case bp_longjmp_resume
:
5043 case bp_step_resume
:
5044 case bp_watchpoint_scope
:
5046 case bp_shlib_event
:
5047 case bp_thread_event
:
5048 case bp_overlay_event
:
5050 case bp_longjmp_master
:
5051 loc
->loc_type
= bp_loc_software_breakpoint
;
5053 case bp_hardware_breakpoint
:
5054 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5056 case bp_hardware_watchpoint
:
5057 case bp_read_watchpoint
:
5058 case bp_access_watchpoint
:
5059 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5064 case bp_fast_tracepoint
:
5065 loc
->loc_type
= bp_loc_other
;
5068 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5074 static void free_bp_location (struct bp_location
*loc
)
5079 if (loc
->function_name
)
5080 xfree (loc
->function_name
);
5085 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5086 that has type BPTYPE and has no locations as yet. */
5087 /* This function is used in gdbtk sources and thus can not be made static. */
5089 static struct breakpoint
*
5090 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5093 struct breakpoint
*b
, *b1
;
5095 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5096 memset (b
, 0, sizeof (*b
));
5099 b
->gdbarch
= gdbarch
;
5100 b
->language
= current_language
->la_language
;
5101 b
->input_radix
= input_radix
;
5103 b
->enable_state
= bp_enabled
;
5106 b
->ignore_count
= 0;
5108 b
->frame_id
= null_frame_id
;
5109 b
->forked_inferior_pid
= null_ptid
;
5110 b
->exec_pathname
= NULL
;
5111 b
->syscalls_to_be_caught
= NULL
;
5113 b
->condition_not_parsed
= 0;
5115 /* Add this breakpoint to the end of the chain
5116 so that a list of breakpoints will come out in order
5117 of increasing numbers. */
5119 b1
= breakpoint_chain
;
5121 breakpoint_chain
= b
;
5131 /* Initialize loc->function_name. */
5133 set_breakpoint_location_function (struct bp_location
*loc
)
5135 if (loc
->owner
->type
== bp_breakpoint
5136 || loc
->owner
->type
== bp_hardware_breakpoint
5137 || tracepoint_type (loc
->owner
))
5139 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5141 if (loc
->function_name
)
5142 loc
->function_name
= xstrdup (loc
->function_name
);
5146 /* Attempt to determine architecture of location identified by SAL. */
5147 static struct gdbarch
*
5148 get_sal_arch (struct symtab_and_line sal
)
5151 return get_objfile_arch (sal
.section
->objfile
);
5153 return get_objfile_arch (sal
.symtab
->objfile
);
5158 /* set_raw_breakpoint is a low level routine for allocating and
5159 partially initializing a breakpoint of type BPTYPE. The newly
5160 created breakpoint's address, section, source file name, and line
5161 number are provided by SAL. The newly created and partially
5162 initialized breakpoint is added to the breakpoint chain and
5163 is also returned as the value of this function.
5165 It is expected that the caller will complete the initialization of
5166 the newly created breakpoint struct as well as output any status
5167 information regarding the creation of a new breakpoint. In
5168 particular, set_raw_breakpoint does NOT set the breakpoint
5169 number! Care should be taken to not allow an error to occur
5170 prior to completing the initialization of the breakpoint. If this
5171 should happen, a bogus breakpoint will be left on the chain. */
5174 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5175 struct symtab_and_line sal
, enum bptype bptype
)
5177 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5178 CORE_ADDR adjusted_address
;
5179 struct gdbarch
*loc_gdbarch
;
5181 loc_gdbarch
= get_sal_arch (sal
);
5183 loc_gdbarch
= b
->gdbarch
;
5185 if (bptype
!= bp_catchpoint
)
5186 gdb_assert (sal
.pspace
!= NULL
);
5188 /* Adjust the breakpoint's address prior to allocating a location.
5189 Once we call allocate_bp_location(), that mostly uninitialized
5190 location will be placed on the location chain. Adjustment of the
5191 breakpoint may cause target_read_memory() to be called and we do
5192 not want its scan of the location chain to find a breakpoint and
5193 location that's only been partially initialized. */
5194 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5196 b
->loc
= allocate_bp_location (b
);
5197 b
->loc
->gdbarch
= loc_gdbarch
;
5198 b
->loc
->requested_address
= sal
.pc
;
5199 b
->loc
->address
= adjusted_address
;
5200 b
->loc
->pspace
= sal
.pspace
;
5202 /* Store the program space that was used to set the breakpoint, for
5203 breakpoint resetting. */
5204 b
->pspace
= sal
.pspace
;
5206 if (sal
.symtab
== NULL
)
5207 b
->source_file
= NULL
;
5209 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5210 b
->loc
->section
= sal
.section
;
5211 b
->line_number
= sal
.line
;
5213 set_breakpoint_location_function (b
->loc
);
5215 breakpoints_changed ();
5221 /* Note that the breakpoint object B describes a permanent breakpoint
5222 instruction, hard-wired into the inferior's code. */
5224 make_breakpoint_permanent (struct breakpoint
*b
)
5226 struct bp_location
*bl
;
5227 b
->enable_state
= bp_permanent
;
5229 /* By definition, permanent breakpoints are already present in the code.
5230 Mark all locations as inserted. For now, make_breakpoint_permanent
5231 is called in just one place, so it's hard to say if it's reasonable
5232 to have permanent breakpoint with multiple locations or not,
5233 but it's easy to implmement. */
5234 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5238 /* Call this routine when stepping and nexting to enable a breakpoint
5239 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5240 set_longjmp_resume_breakpoint() to figure out where we are going. */
5243 set_longjmp_breakpoint (int thread
)
5245 struct breakpoint
*b
, *temp
;
5247 /* To avoid having to rescan all objfile symbols at every step,
5248 we maintain a list of continually-inserted but always disabled
5249 longjmp "master" breakpoints. Here, we simply create momentary
5250 clones of those and enable them for the requested thread. */
5251 ALL_BREAKPOINTS_SAFE (b
, temp
)
5252 if (b
->pspace
== current_program_space
5253 && b
->type
== bp_longjmp_master
)
5255 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5256 clone
->type
= bp_longjmp
;
5257 clone
->thread
= thread
;
5261 /* Delete all longjmp breakpoints from THREAD. */
5263 delete_longjmp_breakpoint (int thread
)
5265 struct breakpoint
*b
, *temp
;
5267 ALL_BREAKPOINTS_SAFE (b
, temp
)
5268 if (b
->type
== bp_longjmp
)
5270 if (b
->thread
== thread
)
5271 delete_breakpoint (b
);
5276 enable_overlay_breakpoints (void)
5278 struct breakpoint
*b
;
5281 if (b
->type
== bp_overlay_event
)
5283 b
->enable_state
= bp_enabled
;
5284 update_global_location_list (1);
5285 overlay_events_enabled
= 1;
5290 disable_overlay_breakpoints (void)
5292 struct breakpoint
*b
;
5295 if (b
->type
== bp_overlay_event
)
5297 b
->enable_state
= bp_disabled
;
5298 update_global_location_list (0);
5299 overlay_events_enabled
= 0;
5304 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5306 struct breakpoint
*b
;
5308 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5310 b
->enable_state
= bp_enabled
;
5311 /* addr_string has to be used or breakpoint_re_set will delete me. */
5313 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5315 update_global_location_list_nothrow (1);
5321 remove_thread_event_breakpoints (void)
5323 struct breakpoint
*b
, *temp
;
5325 ALL_BREAKPOINTS_SAFE (b
, temp
)
5326 if (b
->type
== bp_thread_event
5327 && b
->loc
->pspace
== current_program_space
)
5328 delete_breakpoint (b
);
5331 struct captured_parse_breakpoint_args
5334 struct symtabs_and_lines
*sals_p
;
5335 char ***addr_string_p
;
5339 struct lang_and_radix
5345 /* Create a breakpoint for JIT code registration and unregistration. */
5348 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5350 struct breakpoint
*b
;
5352 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5353 update_global_location_list_nothrow (1);
5358 remove_solib_event_breakpoints (void)
5360 struct breakpoint
*b
, *temp
;
5362 ALL_BREAKPOINTS_SAFE (b
, temp
)
5363 if (b
->type
== bp_shlib_event
5364 && b
->loc
->pspace
== current_program_space
)
5365 delete_breakpoint (b
);
5369 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5371 struct breakpoint
*b
;
5373 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5374 update_global_location_list_nothrow (1);
5378 /* Disable any breakpoints that are on code in shared libraries. Only
5379 apply to enabled breakpoints, disabled ones can just stay disabled. */
5382 disable_breakpoints_in_shlibs (void)
5384 struct bp_location
*loc
, **locp_tmp
;
5386 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5388 struct breakpoint
*b
= loc
->owner
;
5389 /* We apply the check to all breakpoints, including disabled
5390 for those with loc->duplicate set. This is so that when breakpoint
5391 becomes enabled, or the duplicate is removed, gdb will try to insert
5392 all breakpoints. If we don't set shlib_disabled here, we'll try
5393 to insert those breakpoints and fail. */
5394 if (((b
->type
== bp_breakpoint
)
5395 || (b
->type
== bp_hardware_breakpoint
)
5396 || (tracepoint_type (b
)))
5397 && loc
->pspace
== current_program_space
5398 && !loc
->shlib_disabled
5400 && PC_SOLIB (loc
->address
)
5402 && solib_name_from_address (loc
->pspace
, loc
->address
)
5406 loc
->shlib_disabled
= 1;
5411 /* Disable any breakpoints that are in in an unloaded shared library. Only
5412 apply to enabled breakpoints, disabled ones can just stay disabled. */
5415 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5417 struct bp_location
*loc
, **locp_tmp
;
5418 int disabled_shlib_breaks
= 0;
5420 /* SunOS a.out shared libraries are always mapped, so do not
5421 disable breakpoints; they will only be reported as unloaded
5422 through clear_solib when GDB discards its shared library
5423 list. See clear_solib for more information. */
5424 if (exec_bfd
!= NULL
5425 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5428 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5430 struct breakpoint
*b
= loc
->owner
;
5431 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5432 || loc
->loc_type
== bp_loc_software_breakpoint
)
5433 && solib
->pspace
== loc
->pspace
5434 && !loc
->shlib_disabled
5435 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
5436 && solib_contains_address_p (solib
, loc
->address
))
5438 loc
->shlib_disabled
= 1;
5439 /* At this point, we cannot rely on remove_breakpoint
5440 succeeding so we must mark the breakpoint as not inserted
5441 to prevent future errors occurring in remove_breakpoints. */
5443 if (!disabled_shlib_breaks
)
5445 target_terminal_ours_for_output ();
5446 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5449 disabled_shlib_breaks
= 1;
5454 /* FORK & VFORK catchpoints. */
5456 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5459 insert_catch_fork (struct breakpoint
*b
)
5461 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5464 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5467 remove_catch_fork (struct breakpoint
*b
)
5469 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5472 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5476 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5478 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5481 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5483 static enum print_stop_action
5484 print_it_catch_fork (struct breakpoint
*b
)
5486 annotate_catchpoint (b
->number
);
5487 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5488 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5489 return PRINT_SRC_AND_LOC
;
5492 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5495 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5497 struct value_print_options opts
;
5499 get_user_print_options (&opts
);
5501 /* Field 4, the address, is omitted (which makes the columns
5502 not line up too nicely with the headers, but the effect
5503 is relatively readable). */
5504 if (opts
.addressprint
)
5505 ui_out_field_skip (uiout
, "addr");
5507 ui_out_text (uiout
, "fork");
5508 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5510 ui_out_text (uiout
, ", process ");
5511 ui_out_field_int (uiout
, "what",
5512 ptid_get_pid (b
->forked_inferior_pid
));
5513 ui_out_spaces (uiout
, 1);
5517 /* Implement the "print_mention" breakpoint_ops method for fork
5521 print_mention_catch_fork (struct breakpoint
*b
)
5523 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5526 /* The breakpoint_ops structure to be used in fork catchpoints. */
5528 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5532 breakpoint_hit_catch_fork
,
5533 print_it_catch_fork
,
5534 print_one_catch_fork
,
5535 print_mention_catch_fork
5538 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5541 insert_catch_vfork (struct breakpoint
*b
)
5543 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5546 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5549 remove_catch_vfork (struct breakpoint
*b
)
5551 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5554 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5558 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5560 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5563 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5565 static enum print_stop_action
5566 print_it_catch_vfork (struct breakpoint
*b
)
5568 annotate_catchpoint (b
->number
);
5569 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5570 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5571 return PRINT_SRC_AND_LOC
;
5574 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5577 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5579 struct value_print_options opts
;
5581 get_user_print_options (&opts
);
5582 /* Field 4, the address, is omitted (which makes the columns
5583 not line up too nicely with the headers, but the effect
5584 is relatively readable). */
5585 if (opts
.addressprint
)
5586 ui_out_field_skip (uiout
, "addr");
5588 ui_out_text (uiout
, "vfork");
5589 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5591 ui_out_text (uiout
, ", process ");
5592 ui_out_field_int (uiout
, "what",
5593 ptid_get_pid (b
->forked_inferior_pid
));
5594 ui_out_spaces (uiout
, 1);
5598 /* Implement the "print_mention" breakpoint_ops method for vfork
5602 print_mention_catch_vfork (struct breakpoint
*b
)
5604 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5607 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5609 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5613 breakpoint_hit_catch_vfork
,
5614 print_it_catch_vfork
,
5615 print_one_catch_vfork
,
5616 print_mention_catch_vfork
5619 /* Implement the "insert" breakpoint_ops method for syscall
5623 insert_catch_syscall (struct breakpoint
*b
)
5625 struct inferior
*inf
= current_inferior ();
5627 ++inf
->total_syscalls_count
;
5628 if (!b
->syscalls_to_be_caught
)
5629 ++inf
->any_syscall_count
;
5634 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5638 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5640 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5641 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5643 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5644 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5646 memset ((void *) vec_addr
, 0,
5647 (iter
+ 1 - old_size
) * sizeof (int));
5649 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5650 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5654 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5655 inf
->total_syscalls_count
!= 0,
5656 inf
->any_syscall_count
,
5657 VEC_length (int, inf
->syscalls_counts
),
5658 VEC_address (int, inf
->syscalls_counts
));
5661 /* Implement the "remove" breakpoint_ops method for syscall
5665 remove_catch_syscall (struct breakpoint
*b
)
5667 struct inferior
*inf
= current_inferior ();
5669 --inf
->total_syscalls_count
;
5670 if (!b
->syscalls_to_be_caught
)
5671 --inf
->any_syscall_count
;
5676 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5680 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5681 /* Shouldn't happen. */
5683 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5684 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5688 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5689 inf
->total_syscalls_count
!= 0,
5690 inf
->any_syscall_count
,
5691 VEC_length (int, inf
->syscalls_counts
),
5692 VEC_address (int, inf
->syscalls_counts
));
5695 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5699 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5701 /* We must check if we are catching specific syscalls in this breakpoint.
5702 If we are, then we must guarantee that the called syscall is the same
5703 syscall we are catching. */
5704 int syscall_number
= 0;
5706 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5709 /* Now, checking if the syscall is the same. */
5710 if (b
->syscalls_to_be_caught
)
5714 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5716 if (syscall_number
== iter
)
5726 /* Implement the "print_it" breakpoint_ops method for syscall
5729 static enum print_stop_action
5730 print_it_catch_syscall (struct breakpoint
*b
)
5732 /* These are needed because we want to know in which state a
5733 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
5734 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
5735 must print "called syscall" or "returned from syscall". */
5737 struct target_waitstatus last
;
5739 struct cleanup
*old_chain
;
5742 get_last_target_status (&ptid
, &last
);
5744 get_syscall_by_number (last
.value
.syscall_number
, &s
);
5746 annotate_catchpoint (b
->number
);
5749 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
5751 syscall_id
= xstrprintf ("'%s'", s
.name
);
5753 old_chain
= make_cleanup (xfree
, syscall_id
);
5755 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
5756 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
5757 b
->number
, syscall_id
);
5758 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
5759 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
5760 b
->number
, syscall_id
);
5762 do_cleanups (old_chain
);
5764 return PRINT_SRC_AND_LOC
;
5767 /* Implement the "print_one" breakpoint_ops method for syscall
5771 print_one_catch_syscall (struct breakpoint
*b
,
5772 struct bp_location
**last_loc
)
5774 struct value_print_options opts
;
5776 get_user_print_options (&opts
);
5777 /* Field 4, the address, is omitted (which makes the columns
5778 not line up too nicely with the headers, but the effect
5779 is relatively readable). */
5780 if (opts
.addressprint
)
5781 ui_out_field_skip (uiout
, "addr");
5784 if (b
->syscalls_to_be_caught
5785 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5786 ui_out_text (uiout
, "syscalls \"");
5788 ui_out_text (uiout
, "syscall \"");
5790 if (b
->syscalls_to_be_caught
)
5793 char *text
= xstrprintf ("%s", "");
5795 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5800 get_syscall_by_number (iter
, &s
);
5803 text
= xstrprintf ("%s%s, ", text
, s
.name
);
5805 text
= xstrprintf ("%s%d, ", text
, iter
);
5807 /* We have to xfree the last 'text' (now stored at 'x')
5808 because xstrprintf dinamically allocates new space for it
5812 /* Remove the last comma. */
5813 text
[strlen (text
) - 2] = '\0';
5814 ui_out_field_string (uiout
, "what", text
);
5817 ui_out_field_string (uiout
, "what", "<any syscall>");
5818 ui_out_text (uiout
, "\" ");
5821 /* Implement the "print_mention" breakpoint_ops method for syscall
5825 print_mention_catch_syscall (struct breakpoint
*b
)
5827 if (b
->syscalls_to_be_caught
)
5831 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5832 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
5834 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
5837 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5841 get_syscall_by_number (iter
, &s
);
5844 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
5846 printf_filtered (" %d", s
.number
);
5848 printf_filtered (")");
5851 printf_filtered (_("Catchpoint %d (any syscall)"),
5855 /* The breakpoint_ops structure to be used in syscall catchpoints. */
5857 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
5859 insert_catch_syscall
,
5860 remove_catch_syscall
,
5861 breakpoint_hit_catch_syscall
,
5862 print_it_catch_syscall
,
5863 print_one_catch_syscall
,
5864 print_mention_catch_syscall
5867 /* Returns non-zero if 'b' is a syscall catchpoint. */
5870 syscall_catchpoint_p (struct breakpoint
*b
)
5872 return (b
->ops
== &catch_syscall_breakpoint_ops
);
5875 /* Create a new breakpoint of the bp_catchpoint kind and return it,
5876 but does NOT mention it nor update the global location list.
5877 This is useful if you need to fill more fields in the
5878 struct breakpoint before calling mention.
5880 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5881 If COND_STRING is not NULL, then store it in the breakpoint.
5882 OPS, if not NULL, is the breakpoint_ops structure associated
5883 to the catchpoint. */
5885 static struct breakpoint
*
5886 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
5888 struct breakpoint_ops
*ops
)
5890 struct symtab_and_line sal
;
5891 struct breakpoint
*b
;
5894 sal
.pspace
= current_program_space
;
5896 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
5897 set_breakpoint_count (breakpoint_count
+ 1);
5898 b
->number
= breakpoint_count
;
5900 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
5902 b
->addr_string
= NULL
;
5903 b
->enable_state
= bp_enabled
;
5904 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5910 /* Create a new breakpoint of the bp_catchpoint kind and return it.
5912 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5913 If COND_STRING is not NULL, then store it in the breakpoint.
5914 OPS, if not NULL, is the breakpoint_ops structure associated
5915 to the catchpoint. */
5917 static struct breakpoint
*
5918 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
5919 char *cond_string
, struct breakpoint_ops
*ops
)
5921 struct breakpoint
*b
=
5922 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
5925 update_global_location_list (1);
5931 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
5932 int tempflag
, char *cond_string
,
5933 struct breakpoint_ops
*ops
)
5935 struct breakpoint
*b
5936 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
5938 /* FIXME: We should put this information in a breakpoint private data
5940 b
->forked_inferior_pid
= null_ptid
;
5943 /* Exec catchpoints. */
5946 insert_catch_exec (struct breakpoint
*b
)
5948 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
5952 remove_catch_exec (struct breakpoint
*b
)
5954 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
5958 breakpoint_hit_catch_exec (struct breakpoint
*b
)
5960 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
5963 static enum print_stop_action
5964 print_it_catch_exec (struct breakpoint
*b
)
5966 annotate_catchpoint (b
->number
);
5967 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
5969 return PRINT_SRC_AND_LOC
;
5973 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
5975 struct value_print_options opts
;
5977 get_user_print_options (&opts
);
5979 /* Field 4, the address, is omitted (which makes the columns
5980 not line up too nicely with the headers, but the effect
5981 is relatively readable). */
5982 if (opts
.addressprint
)
5983 ui_out_field_skip (uiout
, "addr");
5985 ui_out_text (uiout
, "exec");
5986 if (b
->exec_pathname
!= NULL
)
5988 ui_out_text (uiout
, ", program \"");
5989 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
5990 ui_out_text (uiout
, "\" ");
5995 print_mention_catch_exec (struct breakpoint
*b
)
5997 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6000 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6004 breakpoint_hit_catch_exec
,
6005 print_it_catch_exec
,
6006 print_one_catch_exec
,
6007 print_mention_catch_exec
6011 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6012 struct breakpoint_ops
*ops
)
6014 struct gdbarch
*gdbarch
= get_current_arch ();
6015 struct breakpoint
*b
=
6016 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6018 b
->syscalls_to_be_caught
= filter
;
6020 /* Now, we have to mention the breakpoint and update the global
6023 update_global_location_list (1);
6027 hw_breakpoint_used_count (void)
6029 struct breakpoint
*b
;
6034 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6042 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6044 struct breakpoint
*b
;
6047 *other_type_used
= 0;
6050 if (breakpoint_enabled (b
))
6052 if (b
->type
== type
)
6054 else if ((b
->type
== bp_hardware_watchpoint
6055 || b
->type
== bp_read_watchpoint
6056 || b
->type
== bp_access_watchpoint
))
6057 *other_type_used
= 1;
6064 disable_watchpoints_before_interactive_call_start (void)
6066 struct breakpoint
*b
;
6070 if (((b
->type
== bp_watchpoint
)
6071 || (b
->type
== bp_hardware_watchpoint
)
6072 || (b
->type
== bp_read_watchpoint
)
6073 || (b
->type
== bp_access_watchpoint
))
6074 && breakpoint_enabled (b
))
6076 b
->enable_state
= bp_call_disabled
;
6077 update_global_location_list (0);
6083 enable_watchpoints_after_interactive_call_stop (void)
6085 struct breakpoint
*b
;
6089 if (((b
->type
== bp_watchpoint
)
6090 || (b
->type
== bp_hardware_watchpoint
)
6091 || (b
->type
== bp_read_watchpoint
)
6092 || (b
->type
== bp_access_watchpoint
))
6093 && (b
->enable_state
== bp_call_disabled
))
6095 b
->enable_state
= bp_enabled
;
6096 update_global_location_list (1);
6102 disable_breakpoints_before_startup (void)
6104 struct breakpoint
*b
;
6109 if (b
->pspace
!= current_program_space
)
6112 if ((b
->type
== bp_breakpoint
6113 || b
->type
== bp_hardware_breakpoint
)
6114 && breakpoint_enabled (b
))
6116 b
->enable_state
= bp_startup_disabled
;
6122 update_global_location_list (0);
6124 current_program_space
->executing_startup
= 1;
6128 enable_breakpoints_after_startup (void)
6130 struct breakpoint
*b
;
6133 current_program_space
->executing_startup
= 0;
6137 if (b
->pspace
!= current_program_space
)
6140 if ((b
->type
== bp_breakpoint
6141 || b
->type
== bp_hardware_breakpoint
)
6142 && b
->enable_state
== bp_startup_disabled
)
6144 b
->enable_state
= bp_enabled
;
6150 breakpoint_re_set ();
6154 /* Set a breakpoint that will evaporate an end of command
6155 at address specified by SAL.
6156 Restrict it to frame FRAME if FRAME is nonzero. */
6159 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6160 struct frame_id frame_id
, enum bptype type
)
6162 struct breakpoint
*b
;
6164 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6166 gdb_assert (!frame_id_inlined_p (frame_id
));
6168 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6169 b
->enable_state
= bp_enabled
;
6170 b
->disposition
= disp_donttouch
;
6171 b
->frame_id
= frame_id
;
6173 /* If we're debugging a multi-threaded program, then we
6174 want momentary breakpoints to be active in only a
6175 single thread of control. */
6176 if (in_thread_list (inferior_ptid
))
6177 b
->thread
= pid_to_thread_id (inferior_ptid
);
6179 update_global_location_list_nothrow (1);
6184 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6188 clone_momentary_breakpoint (struct breakpoint
*orig
)
6190 struct breakpoint
*copy
;
6192 /* If there's nothing to clone, then return nothing. */
6196 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6197 copy
->loc
= allocate_bp_location (copy
);
6198 set_breakpoint_location_function (copy
->loc
);
6200 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6201 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6202 copy
->loc
->address
= orig
->loc
->address
;
6203 copy
->loc
->section
= orig
->loc
->section
;
6204 copy
->loc
->pspace
= orig
->loc
->pspace
;
6206 if (orig
->source_file
== NULL
)
6207 copy
->source_file
= NULL
;
6209 copy
->source_file
= xstrdup (orig
->source_file
);
6211 copy
->line_number
= orig
->line_number
;
6212 copy
->frame_id
= orig
->frame_id
;
6213 copy
->thread
= orig
->thread
;
6214 copy
->pspace
= orig
->pspace
;
6216 copy
->enable_state
= bp_enabled
;
6217 copy
->disposition
= disp_donttouch
;
6218 copy
->number
= internal_breakpoint_number
--;
6220 update_global_location_list_nothrow (0);
6225 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6228 struct symtab_and_line sal
;
6230 sal
= find_pc_line (pc
, 0);
6232 sal
.section
= find_pc_overlay (pc
);
6233 sal
.explicit_pc
= 1;
6235 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6239 /* Tell the user we have just set a breakpoint B. */
6242 mention (struct breakpoint
*b
)
6245 struct cleanup
*ui_out_chain
;
6246 struct value_print_options opts
;
6248 get_user_print_options (&opts
);
6250 /* FIXME: This is misplaced; mention() is called by things (like
6251 hitting a watchpoint) other than breakpoint creation. It should
6252 be possible to clean this up and at the same time replace the
6253 random calls to breakpoint_changed with this hook. */
6254 observer_notify_breakpoint_created (b
->number
);
6256 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6257 b
->ops
->print_mention (b
);
6262 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6265 ui_out_text (uiout
, "Watchpoint ");
6266 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6267 ui_out_field_int (uiout
, "number", b
->number
);
6268 ui_out_text (uiout
, ": ");
6269 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6270 do_cleanups (ui_out_chain
);
6272 case bp_hardware_watchpoint
:
6273 ui_out_text (uiout
, "Hardware watchpoint ");
6274 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6275 ui_out_field_int (uiout
, "number", b
->number
);
6276 ui_out_text (uiout
, ": ");
6277 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6278 do_cleanups (ui_out_chain
);
6280 case bp_read_watchpoint
:
6281 ui_out_text (uiout
, "Hardware read watchpoint ");
6282 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6283 ui_out_field_int (uiout
, "number", b
->number
);
6284 ui_out_text (uiout
, ": ");
6285 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6286 do_cleanups (ui_out_chain
);
6288 case bp_access_watchpoint
:
6289 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6290 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6291 ui_out_field_int (uiout
, "number", b
->number
);
6292 ui_out_text (uiout
, ": ");
6293 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6294 do_cleanups (ui_out_chain
);
6297 if (ui_out_is_mi_like_p (uiout
))
6302 if (b
->disposition
== disp_del
)
6303 printf_filtered (_("Temporary breakpoint"));
6305 printf_filtered (_("Breakpoint"));
6306 printf_filtered (_(" %d"), b
->number
);
6309 case bp_hardware_breakpoint
:
6310 if (ui_out_is_mi_like_p (uiout
))
6315 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6319 if (ui_out_is_mi_like_p (uiout
))
6324 printf_filtered (_("Tracepoint"));
6325 printf_filtered (_(" %d"), b
->number
);
6328 case bp_fast_tracepoint
:
6329 if (ui_out_is_mi_like_p (uiout
))
6334 printf_filtered (_("Fast tracepoint"));
6335 printf_filtered (_(" %d"), b
->number
);
6342 case bp_longjmp_resume
:
6343 case bp_step_resume
:
6345 case bp_watchpoint_scope
:
6346 case bp_shlib_event
:
6347 case bp_thread_event
:
6348 case bp_overlay_event
:
6350 case bp_longjmp_master
:
6356 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6360 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6364 if (opts
.addressprint
|| b
->source_file
== NULL
)
6366 printf_filtered (" at ");
6367 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6371 printf_filtered (": file %s, line %d.",
6372 b
->source_file
, b
->line_number
);
6376 struct bp_location
*loc
= b
->loc
;
6378 for (; loc
; loc
= loc
->next
)
6380 printf_filtered (" (%d locations)", n
);
6385 if (ui_out_is_mi_like_p (uiout
))
6387 printf_filtered ("\n");
6391 static struct bp_location
*
6392 add_location_to_breakpoint (struct breakpoint
*b
,
6393 const struct symtab_and_line
*sal
)
6395 struct bp_location
*loc
, **tmp
;
6397 loc
= allocate_bp_location (b
);
6398 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6401 loc
->gdbarch
= get_sal_arch (*sal
);
6403 loc
->gdbarch
= b
->gdbarch
;
6404 loc
->requested_address
= sal
->pc
;
6405 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6406 loc
->requested_address
, b
->type
);
6407 loc
->pspace
= sal
->pspace
;
6408 gdb_assert (loc
->pspace
!= NULL
);
6409 loc
->section
= sal
->section
;
6411 set_breakpoint_location_function (loc
);
6416 /* Return 1 if LOC is pointing to a permanent breakpoint,
6417 return 0 otherwise. */
6420 bp_loc_is_permanent (struct bp_location
*loc
)
6424 const gdb_byte
*brk
;
6425 gdb_byte
*target_mem
;
6426 struct cleanup
*cleanup
;
6429 gdb_assert (loc
!= NULL
);
6431 addr
= loc
->address
;
6432 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6434 /* Software breakpoints unsupported? */
6438 target_mem
= alloca (len
);
6440 /* Enable the automatic memory restoration from breakpoints while
6441 we read the memory. Otherwise we could say about our temporary
6442 breakpoints they are permanent. */
6443 cleanup
= save_current_space_and_thread ();
6445 switch_to_program_space_and_thread (loc
->pspace
);
6446 make_show_memory_breakpoints_cleanup (0);
6448 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6449 && memcmp (target_mem
, brk
, len
) == 0)
6452 do_cleanups (cleanup
);
6459 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6460 as textual description of the location, and COND_STRING
6461 as condition expression. */
6464 create_breakpoint (struct gdbarch
*gdbarch
,
6465 struct symtabs_and_lines sals
, char *addr_string
,
6467 enum bptype type
, enum bpdisp disposition
,
6468 int thread
, int task
, int ignore_count
,
6469 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6471 struct breakpoint
*b
= NULL
;
6474 if (type
== bp_hardware_breakpoint
)
6476 int i
= hw_breakpoint_used_count ();
6477 int target_resources_ok
=
6478 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6480 if (target_resources_ok
== 0)
6481 error (_("No hardware breakpoint support in the target."));
6482 else if (target_resources_ok
< 0)
6483 error (_("Hardware breakpoints used exceeds limit."));
6486 gdb_assert (sals
.nelts
> 0);
6488 for (i
= 0; i
< sals
.nelts
; ++i
)
6490 struct symtab_and_line sal
= sals
.sals
[i
];
6491 struct bp_location
*loc
;
6495 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6497 loc_gdbarch
= gdbarch
;
6499 describe_other_breakpoints (loc_gdbarch
,
6500 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6505 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6506 set_breakpoint_count (breakpoint_count
+ 1);
6507 b
->number
= breakpoint_count
;
6511 b
->cond_string
= cond_string
;
6512 b
->ignore_count
= ignore_count
;
6513 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6514 b
->disposition
= disposition
;
6516 b
->pspace
= sals
.sals
[0].pspace
;
6518 if (enabled
&& b
->pspace
->executing_startup
6519 && (b
->type
== bp_breakpoint
6520 || b
->type
== bp_hardware_breakpoint
))
6521 b
->enable_state
= bp_startup_disabled
;
6527 loc
= add_location_to_breakpoint (b
, &sal
);
6530 if (bp_loc_is_permanent (loc
))
6531 make_breakpoint_permanent (b
);
6535 char *arg
= b
->cond_string
;
6536 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6538 error (_("Garbage %s follows condition"), arg
);
6543 b
->addr_string
= addr_string
;
6545 /* addr_string has to be used or breakpoint_re_set will delete
6548 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6554 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6555 elements to fill the void space. */
6557 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6559 int i
= index_to_remove
+1;
6560 int last_index
= sal
->nelts
-1;
6562 for (;i
<= last_index
; ++i
)
6563 sal
->sals
[i
-1] = sal
->sals
[i
];
6568 /* If appropriate, obtains all sals that correspond to the same file
6569 and line as SAL, in all program spaces. Users debugging with IDEs,
6570 will want to set a breakpoint at foo.c:line, and not really care
6571 about program spaces. This is done only if SAL does not have
6572 explicit PC and has line and file information. If we got just a
6573 single expanded sal, return the original.
6575 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6576 which the name of enclosing function is different from SAL. This
6577 makes sure that if we have breakpoint originally set in template
6578 instantiation, say foo<int>(), we won't expand SAL to locations at
6579 the same line in all existing instantiations of 'foo'. */
6581 static struct symtabs_and_lines
6582 expand_line_sal_maybe (struct symtab_and_line sal
)
6584 struct symtabs_and_lines expanded
;
6585 CORE_ADDR original_pc
= sal
.pc
;
6586 char *original_function
= NULL
;
6589 struct cleanup
*old_chain
;
6591 /* If we have explicit pc, don't expand.
6592 If we have no line number, we can't expand. */
6593 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6596 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6597 expanded
.sals
[0] = sal
;
6603 old_chain
= save_current_space_and_thread ();
6605 switch_to_program_space_and_thread (sal
.pspace
);
6607 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6609 /* Note that expand_line_sal visits *all* program spaces. */
6610 expanded
= expand_line_sal (sal
);
6612 if (expanded
.nelts
== 1)
6614 /* We had one sal, we got one sal. Return that sal, adjusting it
6615 past the function prologue if necessary. */
6616 xfree (expanded
.sals
);
6618 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6619 sal
.pc
= original_pc
;
6620 expanded
.sals
[0] = sal
;
6621 skip_prologue_sal (&expanded
.sals
[0]);
6622 do_cleanups (old_chain
);
6626 if (!sal
.explicit_line
)
6628 CORE_ADDR func_addr
, func_end
;
6629 for (i
= 0; i
< expanded
.nelts
; ++i
)
6631 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6632 char *this_function
;
6634 /* We need to switch threads as well since we're about to
6636 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6638 if (find_pc_partial_function (pc
, &this_function
,
6639 &func_addr
, &func_end
))
6642 && strcmp (this_function
, original_function
) != 0)
6644 remove_sal (&expanded
, i
);
6647 else if (func_addr
== pc
)
6649 /* We're at beginning of a function, and should
6651 struct symbol
*sym
= find_pc_function (pc
);
6653 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
6656 /* Since find_pc_partial_function returned true,
6657 we should really always find the section here. */
6658 struct obj_section
*section
= find_pc_section (pc
);
6661 struct gdbarch
*gdbarch
6662 = get_objfile_arch (section
->objfile
);
6664 = gdbarch_skip_prologue (gdbarch
, pc
);
6673 for (i
= 0; i
< expanded
.nelts
; ++i
)
6675 /* If this SAL corresponds to a breakpoint inserted using a
6676 line number, then skip the function prologue if necessary. */
6677 skip_prologue_sal (&expanded
.sals
[i
]);
6681 do_cleanups (old_chain
);
6683 if (expanded
.nelts
<= 1)
6685 /* This is un ugly workaround. If we get zero
6686 expanded sals then something is really wrong.
6687 Fix that by returnign the original sal. */
6688 xfree (expanded
.sals
);
6690 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6691 sal
.pc
= original_pc
;
6692 expanded
.sals
[0] = sal
;
6699 for (i
= 0; i
< expanded
.nelts
; ++i
)
6700 if (expanded
.sals
[i
].pc
== original_pc
)
6711 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6712 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6713 value. COND_STRING, if not NULL, specified the condition to be
6714 used for all breakpoints. Essentially the only case where
6715 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6716 function. In that case, it's still not possible to specify
6717 separate conditions for different overloaded functions, so
6718 we take just a single condition string.
6720 NOTE: If the function succeeds, the caller is expected to cleanup
6721 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6722 array contents). If the function fails (error() is called), the
6723 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6724 COND and SALS arrays and each of those arrays contents. */
6727 create_breakpoints (struct gdbarch
*gdbarch
,
6728 struct symtabs_and_lines sals
, char **addr_string
,
6730 enum bptype type
, enum bpdisp disposition
,
6731 int thread
, int task
, int ignore_count
,
6732 struct breakpoint_ops
*ops
, int from_tty
,
6736 for (i
= 0; i
< sals
.nelts
; ++i
)
6738 struct symtabs_and_lines expanded
=
6739 expand_line_sal_maybe (sals
.sals
[i
]);
6741 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
6742 cond_string
, type
, disposition
,
6743 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6747 /* Parse ARG which is assumed to be a SAL specification possibly
6748 followed by conditionals. On return, SALS contains an array of SAL
6749 addresses found. ADDR_STRING contains a vector of (canonical)
6750 address strings. ARG points to the end of the SAL. */
6753 parse_breakpoint_sals (char **address
,
6754 struct symtabs_and_lines
*sals
,
6755 char ***addr_string
,
6758 char *addr_start
= *address
;
6759 *addr_string
= NULL
;
6760 /* If no arg given, or if first arg is 'if ', use the default
6762 if ((*address
) == NULL
6763 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
6765 if (default_breakpoint_valid
)
6767 struct symtab_and_line sal
;
6768 init_sal (&sal
); /* initialize to zeroes */
6769 sals
->sals
= (struct symtab_and_line
*)
6770 xmalloc (sizeof (struct symtab_and_line
));
6771 sal
.pc
= default_breakpoint_address
;
6772 sal
.line
= default_breakpoint_line
;
6773 sal
.symtab
= default_breakpoint_symtab
;
6774 sal
.pspace
= default_breakpoint_pspace
;
6775 sal
.section
= find_pc_overlay (sal
.pc
);
6777 /* "break" without arguments is equivalent to "break *PC" where PC is
6778 the default_breakpoint_address. So make sure to set
6779 sal.explicit_pc to prevent GDB from trying to expand the list of
6780 sals to include all other instances with the same symtab and line.
6782 sal
.explicit_pc
= 1;
6784 sals
->sals
[0] = sal
;
6788 error (_("No default breakpoint address now."));
6792 /* Force almost all breakpoints to be in terms of the
6793 current_source_symtab (which is decode_line_1's default). This
6794 should produce the results we want almost all of the time while
6795 leaving default_breakpoint_* alone.
6796 ObjC: However, don't match an Objective-C method name which
6797 may have a '+' or '-' succeeded by a '[' */
6799 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
6801 if (default_breakpoint_valid
6803 || ((strchr ("+-", (*address
)[0]) != NULL
)
6804 && ((*address
)[1] != '['))))
6805 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
6806 default_breakpoint_line
, addr_string
,
6809 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
6810 addr_string
, not_found_ptr
);
6812 /* For any SAL that didn't have a canonical string, fill one in. */
6813 if (sals
->nelts
> 0 && *addr_string
== NULL
)
6814 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
6815 if (addr_start
!= (*address
))
6818 for (i
= 0; i
< sals
->nelts
; i
++)
6820 /* Add the string if not present. */
6821 if ((*addr_string
)[i
] == NULL
)
6822 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
6828 /* Convert each SAL into a real PC. Verify that the PC can be
6829 inserted as a breakpoint. If it can't throw an error. */
6832 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
6836 for (i
= 0; i
< sals
->nelts
; i
++)
6837 resolve_sal_pc (&sals
->sals
[i
]);
6840 /* Fast tracepoints may have restrictions on valid locations. For
6841 instance, a fast tracepoint using a jump instead of a trap will
6842 likely have to overwrite more bytes than a trap would, and so can
6843 only be placed where the instruction is longer than the jump, or a
6844 multi-instruction sequence does not have a jump into the middle of
6848 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
6849 struct symtabs_and_lines
*sals
)
6852 struct symtab_and_line
*sal
;
6854 struct cleanup
*old_chain
;
6856 for (i
= 0; i
< sals
->nelts
; i
++)
6858 sal
= &sals
->sals
[i
];
6860 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
6862 old_chain
= make_cleanup (xfree
, msg
);
6865 error (_("May not have a fast tracepoint at 0x%s%s"),
6866 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
6868 do_cleanups (old_chain
);
6873 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
6875 struct captured_parse_breakpoint_args
*args
= data
;
6877 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
6878 args
->not_found_ptr
);
6881 /* Given TOK, a string specification of condition and thread, as
6882 accepted by the 'break' command, extract the condition
6883 string and thread number and set *COND_STRING and *THREAD.
6884 PC identifies the context at which the condition should be parsed.
6885 If no condition is found, *COND_STRING is set to NULL.
6886 If no thread is found, *THREAD is set to -1. */
6888 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
6889 char **cond_string
, int *thread
, int *task
)
6891 *cond_string
= NULL
;
6897 char *cond_start
= NULL
;
6898 char *cond_end
= NULL
;
6899 while (*tok
== ' ' || *tok
== '\t')
6904 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6907 toklen
= end_tok
- tok
;
6909 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6911 struct expression
*expr
;
6913 tok
= cond_start
= end_tok
+ 1;
6914 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
6917 *cond_string
= savestring (cond_start
,
6918 cond_end
- cond_start
);
6920 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6926 *thread
= strtol (tok
, &tok
, 0);
6928 error (_("Junk after thread keyword."));
6929 if (!valid_thread_id (*thread
))
6930 error (_("Unknown thread %d."), *thread
);
6932 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
6938 *task
= strtol (tok
, &tok
, 0);
6940 error (_("Junk after task keyword."));
6941 if (!valid_task_id (*task
))
6942 error (_("Unknown task %d."), *task
);
6945 error (_("Junk at end of arguments."));
6949 /* Set a breakpoint. This function is shared between CLI and MI
6950 functions for setting a breakpoint. This function has two major
6951 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
6952 parameter. If non-zero, the function will parse arg, extracting
6953 breakpoint location, address and thread. Otherwise, ARG is just the
6954 location of breakpoint, with condition and thread specified by the
6955 COND_STRING and THREAD parameters. Returns true if any breakpoint
6956 was created; false otherwise. */
6959 break_command_really (struct gdbarch
*gdbarch
,
6960 char *arg
, char *cond_string
, int thread
,
6961 int parse_condition_and_thread
,
6962 int tempflag
, int hardwareflag
, int traceflag
,
6964 enum auto_boolean pending_break_support
,
6965 struct breakpoint_ops
*ops
,
6969 struct gdb_exception e
;
6970 struct symtabs_and_lines sals
;
6971 struct symtab_and_line pending_sal
;
6974 char *addr_start
= arg
;
6976 struct cleanup
*old_chain
;
6977 struct cleanup
*bkpt_chain
= NULL
;
6978 struct captured_parse_breakpoint_args parse_args
;
6982 enum bptype type_wanted
;
6989 parse_args
.arg_p
= &arg
;
6990 parse_args
.sals_p
= &sals
;
6991 parse_args
.addr_string_p
= &addr_string
;
6992 parse_args
.not_found_ptr
= ¬_found
;
6994 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
6995 &parse_args
, RETURN_MASK_ALL
);
6997 /* If caller is interested in rc value from parse, set value. */
7001 throw_exception (e
);
7005 case NOT_FOUND_ERROR
:
7007 /* If pending breakpoint support is turned off, throw
7010 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7011 throw_exception (e
);
7013 exception_print (gdb_stderr
, e
);
7015 /* If pending breakpoint support is auto query and the user
7016 selects no, then simply return the error code. */
7017 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7018 && !nquery ("Make breakpoint pending on future shared library load? "))
7021 /* At this point, either the user was queried about setting
7022 a pending breakpoint and selected yes, or pending
7023 breakpoint behavior is on and thus a pending breakpoint
7024 is defaulted on behalf of the user. */
7025 copy_arg
= xstrdup (addr_start
);
7026 addr_string
= ©_arg
;
7028 sals
.sals
= &pending_sal
;
7033 throw_exception (e
);
7040 /* Create a chain of things that always need to be cleaned up. */
7041 old_chain
= make_cleanup (null_cleanup
, 0);
7045 /* Make sure that all storage allocated to SALS gets freed. */
7046 make_cleanup (xfree
, sals
.sals
);
7048 /* Cleanup the addr_string array but not its contents. */
7049 make_cleanup (xfree
, addr_string
);
7052 /* ----------------------------- SNIP -----------------------------
7053 Anything added to the cleanup chain beyond this point is assumed
7054 to be part of a breakpoint. If the breakpoint create succeeds
7055 then the memory is not reclaimed. */
7056 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7058 /* Mark the contents of the addr_string for cleanup. These go on
7059 the bkpt_chain and only occur if the breakpoint create fails. */
7060 for (i
= 0; i
< sals
.nelts
; i
++)
7062 if (addr_string
[i
] != NULL
)
7063 make_cleanup (xfree
, addr_string
[i
]);
7066 /* Resolve all line numbers to PC's and verify that the addresses
7067 are ok for the target. */
7069 breakpoint_sals_to_pc (&sals
, addr_start
);
7071 type_wanted
= (traceflag
7072 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7073 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7075 /* Fast tracepoints may have additional restrictions on location. */
7076 if (type_wanted
== bp_fast_tracepoint
)
7077 check_fast_tracepoint_sals (gdbarch
, &sals
);
7079 /* Verify that condition can be parsed, before setting any
7080 breakpoints. Allocate a separate condition expression for each
7084 if (parse_condition_and_thread
)
7086 /* Here we only parse 'arg' to separate condition
7087 from thread number, so parsing in context of first
7088 sal is OK. When setting the breakpoint we'll
7089 re-parse it in context of each sal. */
7092 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7095 make_cleanup (xfree
, cond_string
);
7099 /* Create a private copy of condition string. */
7102 cond_string
= xstrdup (cond_string
);
7103 make_cleanup (xfree
, cond_string
);
7106 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
7107 tempflag
? disp_del
: disp_donttouch
,
7108 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7112 struct symtab_and_line sal
= {0};
7113 struct breakpoint
*b
;
7115 make_cleanup (xfree
, copy_arg
);
7117 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7118 set_breakpoint_count (breakpoint_count
+ 1);
7119 b
->number
= breakpoint_count
;
7121 b
->addr_string
= addr_string
[0];
7122 b
->cond_string
= NULL
;
7123 b
->ignore_count
= ignore_count
;
7124 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7125 b
->condition_not_parsed
= 1;
7127 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7128 b
->pspace
= current_program_space
;
7130 if (enabled
&& b
->pspace
->executing_startup
7131 && (b
->type
== bp_breakpoint
7132 || b
->type
== bp_hardware_breakpoint
))
7133 b
->enable_state
= bp_startup_disabled
;
7139 warning (_("Multiple breakpoints were set.\n"
7140 "Use the \"delete\" command to delete unwanted breakpoints."));
7141 /* That's it. Discard the cleanups for data inserted into the
7143 discard_cleanups (bkpt_chain
);
7144 /* But cleanup everything else. */
7145 do_cleanups (old_chain
);
7147 /* error call may happen here - have BKPT_CHAIN already discarded. */
7148 update_global_location_list (1);
7153 /* Set a breakpoint.
7154 ARG is a string describing breakpoint address,
7155 condition, and thread.
7156 FLAG specifies if a breakpoint is hardware on,
7157 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7161 break_command_1 (char *arg
, int flag
, int from_tty
)
7163 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7164 int tempflag
= flag
& BP_TEMPFLAG
;
7166 break_command_really (get_current_arch (),
7168 NULL
, 0, 1 /* parse arg */,
7169 tempflag
, hardwareflag
, 0 /* traceflag */,
7170 0 /* Ignore count */,
7171 pending_break_support
,
7172 NULL
/* breakpoint_ops */,
7179 set_breakpoint (struct gdbarch
*gdbarch
,
7180 char *address
, char *condition
,
7181 int hardwareflag
, int tempflag
,
7182 int thread
, int ignore_count
,
7183 int pending
, int enabled
)
7185 break_command_really (gdbarch
,
7186 address
, condition
, thread
,
7187 0 /* condition and thread are valid. */,
7188 tempflag
, hardwareflag
, 0 /* traceflag */,
7191 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
7195 /* Adjust SAL to the first instruction past the function prologue.
7196 The end of the prologue is determined using the line table from
7197 the debugging information. explicit_pc and explicit_line are
7200 If SAL is already past the prologue, then do nothing. */
7203 skip_prologue_sal (struct symtab_and_line
*sal
)
7206 struct symtab_and_line start_sal
;
7207 struct cleanup
*old_chain
;
7209 old_chain
= save_current_space_and_thread ();
7211 sym
= find_pc_function (sal
->pc
);
7214 start_sal
= find_function_start_sal (sym
, 1);
7215 if (sal
->pc
< start_sal
.pc
)
7217 start_sal
.explicit_line
= sal
->explicit_line
;
7218 start_sal
.explicit_pc
= sal
->explicit_pc
;
7223 do_cleanups (old_chain
);
7226 /* Helper function for break_command_1 and disassemble_command. */
7229 resolve_sal_pc (struct symtab_and_line
*sal
)
7233 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7235 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7236 error (_("No line %d in file \"%s\"."),
7237 sal
->line
, sal
->symtab
->filename
);
7240 /* If this SAL corresponds to a breakpoint inserted using
7241 a line number, then skip the function prologue if necessary. */
7242 if (sal
->explicit_line
)
7244 /* Preserve the original line number. */
7245 int saved_line
= sal
->line
;
7246 skip_prologue_sal (sal
);
7247 sal
->line
= saved_line
;
7251 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7253 struct blockvector
*bv
;
7257 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7260 sym
= block_linkage_function (b
);
7263 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7264 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7268 /* It really is worthwhile to have the section, so we'll just
7269 have to look harder. This case can be executed if we have
7270 line numbers but no functions (as can happen in assembly
7273 struct minimal_symbol
*msym
;
7274 struct cleanup
*old_chain
= save_current_space_and_thread ();
7276 switch_to_program_space_and_thread (sal
->pspace
);
7278 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7280 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7282 do_cleanups (old_chain
);
7289 break_command (char *arg
, int from_tty
)
7291 break_command_1 (arg
, 0, from_tty
);
7295 tbreak_command (char *arg
, int from_tty
)
7297 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7301 hbreak_command (char *arg
, int from_tty
)
7303 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7307 thbreak_command (char *arg
, int from_tty
)
7309 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7313 stop_command (char *arg
, int from_tty
)
7315 printf_filtered (_("Specify the type of breakpoint to set.\n\
7316 Usage: stop in <function | address>\n\
7317 stop at <line>\n"));
7321 stopin_command (char *arg
, int from_tty
)
7325 if (arg
== (char *) NULL
)
7327 else if (*arg
!= '*')
7332 /* look for a ':'. If this is a line number specification, then
7333 say it is bad, otherwise, it should be an address or
7334 function/method name */
7335 while (*argptr
&& !hasColon
)
7337 hasColon
= (*argptr
== ':');
7342 badInput
= (*argptr
!= ':'); /* Not a class::method */
7344 badInput
= isdigit (*arg
); /* a simple line number */
7348 printf_filtered (_("Usage: stop in <function | address>\n"));
7350 break_command_1 (arg
, 0, from_tty
);
7354 stopat_command (char *arg
, int from_tty
)
7358 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7365 /* look for a ':'. If there is a '::' then get out, otherwise
7366 it is probably a line number. */
7367 while (*argptr
&& !hasColon
)
7369 hasColon
= (*argptr
== ':');
7374 badInput
= (*argptr
== ':'); /* we have class::method */
7376 badInput
= !isdigit (*arg
); /* not a line number */
7380 printf_filtered (_("Usage: stop at <line>\n"));
7382 break_command_1 (arg
, 0, from_tty
);
7385 /* accessflag: hw_write: watch write,
7386 hw_read: watch read,
7387 hw_access: watch access (read or write) */
7389 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7391 struct gdbarch
*gdbarch
= get_current_arch ();
7392 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7393 struct expression
*exp
;
7394 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7395 struct value
*val
, *mark
;
7396 struct frame_info
*frame
;
7397 char *exp_start
= NULL
;
7398 char *exp_end
= NULL
;
7399 char *tok
, *id_tok_start
, *end_tok
;
7401 char *cond_start
= NULL
;
7402 char *cond_end
= NULL
;
7403 int i
, other_type_used
, target_resources_ok
= 0;
7404 enum bptype bp_type
;
7408 /* Make sure that we actually have parameters to parse. */
7409 if (arg
!= NULL
&& arg
[0] != '\0')
7411 toklen
= strlen (arg
); /* Size of argument list. */
7413 /* Points tok to the end of the argument list. */
7414 tok
= arg
+ toklen
- 1;
7416 /* Go backwards in the parameters list. Skip the last parameter.
7417 If we're expecting a 'thread <thread_num>' parameter, this should
7418 be the thread identifier. */
7419 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7421 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7424 /* Points end_tok to the beginning of the last token. */
7425 id_tok_start
= tok
+ 1;
7427 /* Go backwards in the parameters list. Skip one more parameter.
7428 If we're expecting a 'thread <thread_num>' parameter, we should
7429 reach a "thread" token. */
7430 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7435 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7438 /* Move the pointer forward to skip the whitespace and
7439 calculate the length of the token. */
7441 toklen
= end_tok
- tok
;
7443 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7445 /* At this point we've found a "thread" token, which means
7446 the user is trying to set a watchpoint that triggers
7447 only in a specific thread. */
7450 /* Extract the thread ID from the next token. */
7451 thread
= strtol (id_tok_start
, &endp
, 0);
7453 /* Check if the user provided a valid numeric value for the
7455 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7456 error (_("Invalid thread ID specification %s."), id_tok_start
);
7458 /* Check if the thread actually exists. */
7459 if (!valid_thread_id (thread
))
7460 error (_("Unknown thread %d."), thread
);
7462 /* Truncate the string and get rid of the thread <thread_num>
7463 parameter before the parameter list is parsed by the
7464 evaluate_expression() function. */
7469 /* Parse the rest of the arguments. */
7470 innermost_block
= NULL
;
7472 exp
= parse_exp_1 (&arg
, 0, 0);
7474 /* Remove trailing whitespace from the expression before saving it.
7475 This makes the eventual display of the expression string a bit
7477 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7480 exp_valid_block
= innermost_block
;
7481 mark
= value_mark ();
7482 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7484 release_value (val
);
7487 while (*tok
== ' ' || *tok
== '\t')
7491 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7494 toklen
= end_tok
- tok
;
7495 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7497 struct expression
*cond
;
7499 innermost_block
= NULL
;
7500 tok
= cond_start
= end_tok
+ 1;
7501 cond
= parse_exp_1 (&tok
, 0, 0);
7503 /* The watchpoint expression may not be local, but the condition
7504 may still be. E.g.: `watch global if local > 0'. */
7505 cond_exp_valid_block
= innermost_block
;
7511 error (_("Junk at end of command."));
7513 if (accessflag
== hw_read
)
7514 bp_type
= bp_read_watchpoint
;
7515 else if (accessflag
== hw_access
)
7516 bp_type
= bp_access_watchpoint
;
7518 bp_type
= bp_hardware_watchpoint
;
7520 mem_cnt
= can_use_hardware_watchpoint (val
);
7521 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7522 error (_("Expression cannot be implemented with read/access watchpoint."));
7525 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7526 target_resources_ok
=
7527 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7529 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7530 error (_("Target does not support this type of hardware watchpoint."));
7532 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7533 error (_("Target can only support one kind of HW watchpoint at a time."));
7536 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7537 watchpoint could not be set. */
7538 if (!mem_cnt
|| target_resources_ok
<= 0)
7539 bp_type
= bp_watchpoint
;
7541 frame
= block_innermost_frame (exp_valid_block
);
7543 /* If the expression is "local", then set up a "watchpoint scope"
7544 breakpoint at the point where we've left the scope of the watchpoint
7545 expression. Create the scope breakpoint before the watchpoint, so
7546 that we will encounter it first in bpstat_stop_status. */
7547 if (exp_valid_block
&& frame
)
7549 if (frame_id_p (frame_unwind_caller_id (frame
)))
7552 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7553 frame_unwind_caller_pc (frame
),
7554 bp_watchpoint_scope
);
7556 scope_breakpoint
->enable_state
= bp_enabled
;
7558 /* Automatically delete the breakpoint when it hits. */
7559 scope_breakpoint
->disposition
= disp_del
;
7561 /* Only break in the proper frame (help with recursion). */
7562 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7564 /* Set the address at which we will stop. */
7565 scope_breakpoint
->loc
->gdbarch
7566 = frame_unwind_caller_arch (frame
);
7567 scope_breakpoint
->loc
->requested_address
7568 = frame_unwind_caller_pc (frame
);
7569 scope_breakpoint
->loc
->address
7570 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7571 scope_breakpoint
->loc
->requested_address
,
7572 scope_breakpoint
->type
);
7576 /* Now set up the breakpoint. */
7577 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7578 set_breakpoint_count (breakpoint_count
+ 1);
7579 b
->number
= breakpoint_count
;
7581 b
->disposition
= disp_donttouch
;
7583 b
->exp_valid_block
= exp_valid_block
;
7584 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7585 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7589 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7595 b
->watchpoint_frame
= get_frame_id (frame
);
7596 b
->watchpoint_thread
= inferior_ptid
;
7600 b
->watchpoint_frame
= null_frame_id
;
7601 b
->watchpoint_thread
= null_ptid
;
7604 if (scope_breakpoint
!= NULL
)
7606 /* The scope breakpoint is related to the watchpoint. We will
7607 need to act on them together. */
7608 b
->related_breakpoint
= scope_breakpoint
;
7609 scope_breakpoint
->related_breakpoint
= b
;
7612 value_free_to_mark (mark
);
7614 /* Finally update the new watchpoint. This creates the locations
7615 that should be inserted. */
7616 update_watchpoint (b
, 1);
7619 update_global_location_list (1);
7622 /* Return count of locations need to be watched and can be handled
7623 in hardware. If the watchpoint can not be handled
7624 in hardware return zero. */
7627 can_use_hardware_watchpoint (struct value
*v
)
7629 int found_memory_cnt
= 0;
7630 struct value
*head
= v
;
7632 /* Did the user specifically forbid us to use hardware watchpoints? */
7633 if (!can_use_hw_watchpoints
)
7636 /* Make sure that the value of the expression depends only upon
7637 memory contents, and values computed from them within GDB. If we
7638 find any register references or function calls, we can't use a
7639 hardware watchpoint.
7641 The idea here is that evaluating an expression generates a series
7642 of values, one holding the value of every subexpression. (The
7643 expression a*b+c has five subexpressions: a, b, a*b, c, and
7644 a*b+c.) GDB's values hold almost enough information to establish
7645 the criteria given above --- they identify memory lvalues,
7646 register lvalues, computed values, etcetera. So we can evaluate
7647 the expression, and then scan the chain of values that leaves
7648 behind to decide whether we can detect any possible change to the
7649 expression's final value using only hardware watchpoints.
7651 However, I don't think that the values returned by inferior
7652 function calls are special in any way. So this function may not
7653 notice that an expression involving an inferior function call
7654 can't be watched with hardware watchpoints. FIXME. */
7655 for (; v
; v
= value_next (v
))
7657 if (VALUE_LVAL (v
) == lval_memory
)
7660 /* A lazy memory lvalue is one that GDB never needed to fetch;
7661 we either just used its address (e.g., `a' in `a.b') or
7662 we never needed it at all (e.g., `a' in `a,b'). */
7666 /* Ahh, memory we actually used! Check if we can cover
7667 it with hardware watchpoints. */
7668 struct type
*vtype
= check_typedef (value_type (v
));
7670 /* We only watch structs and arrays if user asked for it
7671 explicitly, never if they just happen to appear in a
7672 middle of some value chain. */
7674 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7675 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7677 CORE_ADDR vaddr
= value_address (v
);
7678 int len
= TYPE_LENGTH (value_type (v
));
7680 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7687 else if (VALUE_LVAL (v
) != not_lval
7688 && deprecated_value_modifiable (v
) == 0)
7689 return 0; /* ??? What does this represent? */
7690 else if (VALUE_LVAL (v
) == lval_register
)
7691 return 0; /* cannot watch a register with a HW watchpoint */
7694 /* The expression itself looks suitable for using a hardware
7695 watchpoint, but give the target machine a chance to reject it. */
7696 return found_memory_cnt
;
7700 watch_command_wrapper (char *arg
, int from_tty
)
7702 watch_command (arg
, from_tty
);
7706 watch_command (char *arg
, int from_tty
)
7708 watch_command_1 (arg
, hw_write
, from_tty
);
7712 rwatch_command_wrapper (char *arg
, int from_tty
)
7714 rwatch_command (arg
, from_tty
);
7718 rwatch_command (char *arg
, int from_tty
)
7720 watch_command_1 (arg
, hw_read
, from_tty
);
7724 awatch_command_wrapper (char *arg
, int from_tty
)
7726 awatch_command (arg
, from_tty
);
7730 awatch_command (char *arg
, int from_tty
)
7732 watch_command_1 (arg
, hw_access
, from_tty
);
7736 /* Helper routines for the until_command routine in infcmd.c. Here
7737 because it uses the mechanisms of breakpoints. */
7739 struct until_break_command_continuation_args
7741 struct breakpoint
*breakpoint
;
7742 struct breakpoint
*breakpoint2
;
7745 /* This function is called by fetch_inferior_event via the
7746 cmd_continuation pointer, to complete the until command. It takes
7747 care of cleaning up the temporary breakpoints set up by the until
7750 until_break_command_continuation (void *arg
)
7752 struct until_break_command_continuation_args
*a
= arg
;
7754 delete_breakpoint (a
->breakpoint
);
7756 delete_breakpoint (a
->breakpoint2
);
7760 until_break_command (char *arg
, int from_tty
, int anywhere
)
7762 struct symtabs_and_lines sals
;
7763 struct symtab_and_line sal
;
7764 struct frame_info
*frame
= get_selected_frame (NULL
);
7765 struct breakpoint
*breakpoint
;
7766 struct breakpoint
*breakpoint2
= NULL
;
7767 struct cleanup
*old_chain
;
7769 clear_proceed_status ();
7771 /* Set a breakpoint where the user wants it and at return from
7774 if (default_breakpoint_valid
)
7775 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
7776 default_breakpoint_line
, (char ***) NULL
, NULL
);
7778 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
7779 0, (char ***) NULL
, NULL
);
7781 if (sals
.nelts
!= 1)
7782 error (_("Couldn't get information on specified line."));
7785 xfree (sals
.sals
); /* malloc'd, so freed */
7788 error (_("Junk at end of arguments."));
7790 resolve_sal_pc (&sal
);
7793 /* If the user told us to continue until a specified location,
7794 we don't specify a frame at which we need to stop. */
7795 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7796 null_frame_id
, bp_until
);
7798 /* Otherwise, specify the selected frame, because we want to stop only
7799 at the very same frame. */
7800 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7801 get_stack_frame_id (frame
),
7804 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
7806 /* Keep within the current frame, or in frames called by the current
7809 if (frame_id_p (frame_unwind_caller_id (frame
)))
7811 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
7812 sal
.pc
= frame_unwind_caller_pc (frame
);
7813 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
7815 frame_unwind_caller_id (frame
),
7817 make_cleanup_delete_breakpoint (breakpoint2
);
7820 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
7822 /* If we are running asynchronously, and proceed call above has actually
7823 managed to start the target, arrange for breakpoints to be
7824 deleted when the target stops. Otherwise, we're already stopped and
7825 delete breakpoints via cleanup chain. */
7827 if (target_can_async_p () && is_running (inferior_ptid
))
7829 struct until_break_command_continuation_args
*args
;
7830 args
= xmalloc (sizeof (*args
));
7832 args
->breakpoint
= breakpoint
;
7833 args
->breakpoint2
= breakpoint2
;
7835 discard_cleanups (old_chain
);
7836 add_continuation (inferior_thread (),
7837 until_break_command_continuation
, args
,
7841 do_cleanups (old_chain
);
7845 ep_skip_leading_whitespace (char **s
)
7847 if ((s
== NULL
) || (*s
== NULL
))
7849 while (isspace (**s
))
7853 /* This function attempts to parse an optional "if <cond>" clause
7854 from the arg string. If one is not found, it returns NULL.
7856 Else, it returns a pointer to the condition string. (It does not
7857 attempt to evaluate the string against a particular block.) And,
7858 it updates arg to point to the first character following the parsed
7859 if clause in the arg string. */
7862 ep_parse_optional_if_clause (char **arg
)
7866 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
7869 /* Skip the "if" keyword. */
7872 /* Skip any extra leading whitespace, and record the start of the
7873 condition string. */
7874 ep_skip_leading_whitespace (arg
);
7877 /* Assume that the condition occupies the remainder of the arg string. */
7878 (*arg
) += strlen (cond_string
);
7883 /* Commands to deal with catching events, such as signals, exceptions,
7884 process start/exit, etc. */
7888 catch_fork_temporary
, catch_vfork_temporary
,
7889 catch_fork_permanent
, catch_vfork_permanent
7894 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7896 struct gdbarch
*gdbarch
= get_current_arch ();
7897 char *cond_string
= NULL
;
7898 catch_fork_kind fork_kind
;
7901 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
7902 tempflag
= (fork_kind
== catch_fork_temporary
7903 || fork_kind
== catch_vfork_temporary
);
7907 ep_skip_leading_whitespace (&arg
);
7909 /* The allowed syntax is:
7911 catch [v]fork if <cond>
7913 First, check if there's an if clause. */
7914 cond_string
= ep_parse_optional_if_clause (&arg
);
7916 if ((*arg
!= '\0') && !isspace (*arg
))
7917 error (_("Junk at end of arguments."));
7919 /* If this target supports it, create a fork or vfork catchpoint
7920 and enable reporting of such events. */
7923 case catch_fork_temporary
:
7924 case catch_fork_permanent
:
7925 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
7926 &catch_fork_breakpoint_ops
);
7928 case catch_vfork_temporary
:
7929 case catch_vfork_permanent
:
7930 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
7931 &catch_vfork_breakpoint_ops
);
7934 error (_("unsupported or unknown fork kind; cannot catch it"));
7940 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7942 struct gdbarch
*gdbarch
= get_current_arch ();
7944 char *cond_string
= NULL
;
7946 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7950 ep_skip_leading_whitespace (&arg
);
7952 /* The allowed syntax is:
7954 catch exec if <cond>
7956 First, check if there's an if clause. */
7957 cond_string
= ep_parse_optional_if_clause (&arg
);
7959 if ((*arg
!= '\0') && !isspace (*arg
))
7960 error (_("Junk at end of arguments."));
7962 /* If this target supports it, create an exec catchpoint
7963 and enable reporting of such events. */
7964 create_catchpoint (gdbarch
, tempflag
, cond_string
,
7965 &catch_exec_breakpoint_ops
);
7968 static enum print_stop_action
7969 print_exception_catchpoint (struct breakpoint
*b
)
7971 int bp_temp
, bp_throw
;
7973 annotate_catchpoint (b
->number
);
7975 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
7976 if (b
->loc
->address
!= b
->loc
->requested_address
)
7977 breakpoint_adjustment_warning (b
->loc
->requested_address
,
7980 bp_temp
= b
->disposition
== disp_del
;
7982 bp_temp
? "Temporary catchpoint "
7984 if (!ui_out_is_mi_like_p (uiout
))
7985 ui_out_field_int (uiout
, "bkptno", b
->number
);
7987 bp_throw
? " (exception thrown), "
7988 : " (exception caught), ");
7989 if (ui_out_is_mi_like_p (uiout
))
7991 ui_out_field_string (uiout
, "reason",
7992 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
7993 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7994 ui_out_field_int (uiout
, "bkptno", b
->number
);
7996 return PRINT_SRC_AND_LOC
;
8000 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8002 struct value_print_options opts
;
8003 get_user_print_options (&opts
);
8004 if (opts
.addressprint
)
8007 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8008 ui_out_field_string (uiout
, "addr", "<PENDING>");
8010 ui_out_field_core_addr (uiout
, "addr",
8011 b
->loc
->gdbarch
, b
->loc
->address
);
8016 if (strstr (b
->addr_string
, "throw") != NULL
)
8017 ui_out_field_string (uiout
, "what", "exception throw");
8019 ui_out_field_string (uiout
, "what", "exception catch");
8023 print_mention_exception_catchpoint (struct breakpoint
*b
)
8028 bp_temp
= b
->disposition
== disp_del
;
8029 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8030 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8031 : _("Catchpoint "));
8032 ui_out_field_int (uiout
, "bkptno", b
->number
);
8033 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8037 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8040 NULL
, /* breakpoint_hit */
8041 print_exception_catchpoint
,
8042 print_one_exception_catchpoint
,
8043 print_mention_exception_catchpoint
8047 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8048 enum exception_event_kind ex_event
, int from_tty
)
8050 char *trigger_func_name
;
8052 if (ex_event
== EX_EVENT_CATCH
)
8053 trigger_func_name
= "__cxa_begin_catch";
8055 trigger_func_name
= "__cxa_throw";
8057 break_command_really (get_current_arch (),
8058 trigger_func_name
, cond_string
, -1,
8059 0 /* condition and thread are valid. */,
8062 AUTO_BOOLEAN_TRUE
/* pending */,
8063 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8069 /* Deal with "catch catch" and "catch throw" commands */
8072 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8073 int tempflag
, int from_tty
)
8075 char *cond_string
= NULL
;
8076 struct symtab_and_line
*sal
= NULL
;
8080 ep_skip_leading_whitespace (&arg
);
8082 cond_string
= ep_parse_optional_if_clause (&arg
);
8084 if ((*arg
!= '\0') && !isspace (*arg
))
8085 error (_("Junk at end of arguments."));
8087 if (ex_event
!= EX_EVENT_THROW
8088 && ex_event
!= EX_EVENT_CATCH
)
8089 error (_("Unsupported or unknown exception event; cannot catch it"));
8091 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8094 warning (_("Unsupported with this platform/compiler combination."));
8097 /* Implementation of "catch catch" command. */
8100 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8102 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8103 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8106 /* Implementation of "catch throw" command. */
8109 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8111 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8112 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8115 /* Create a breakpoint struct for Ada exception catchpoints. */
8118 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8119 struct symtab_and_line sal
,
8123 struct expression
*cond
,
8124 struct breakpoint_ops
*ops
,
8128 struct breakpoint
*b
;
8132 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8134 loc_gdbarch
= gdbarch
;
8136 describe_other_breakpoints (loc_gdbarch
,
8137 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8138 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8139 version for exception catchpoints, because two catchpoints
8140 used for different exception names will use the same address.
8141 In this case, a "breakpoint ... also set at..." warning is
8142 unproductive. Besides. the warning phrasing is also a bit
8143 inapropriate, we should use the word catchpoint, and tell
8144 the user what type of catchpoint it is. The above is good
8145 enough for now, though. */
8148 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8149 set_breakpoint_count (breakpoint_count
+ 1);
8151 b
->enable_state
= bp_enabled
;
8152 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8153 b
->number
= breakpoint_count
;
8154 b
->ignore_count
= 0;
8155 b
->loc
->cond
= cond
;
8156 b
->addr_string
= addr_string
;
8157 b
->language
= language_ada
;
8158 b
->cond_string
= cond_string
;
8159 b
->exp_string
= exp_string
;
8164 update_global_location_list (1);
8167 /* Implement the "catch exception" command. */
8170 catch_ada_exception_command (char *arg
, int from_tty
,
8171 struct cmd_list_element
*command
)
8173 struct gdbarch
*gdbarch
= get_current_arch ();
8175 struct symtab_and_line sal
;
8177 char *addr_string
= NULL
;
8178 char *exp_string
= NULL
;
8179 char *cond_string
= NULL
;
8180 struct expression
*cond
= NULL
;
8181 struct breakpoint_ops
*ops
= NULL
;
8183 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8187 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8188 &cond_string
, &cond
, &ops
);
8189 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8190 cond_string
, cond
, ops
, tempflag
,
8194 /* Cleanup function for a syscall filter list. */
8196 clean_up_filters (void *arg
)
8198 VEC(int) *iter
= *(VEC(int) **) arg
;
8199 VEC_free (int, iter
);
8202 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8203 filter list, or NULL if no filtering is required. */
8205 catch_syscall_split_args (char *arg
)
8207 VEC(int) *result
= NULL
;
8208 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8210 while (*arg
!= '\0')
8212 int i
, syscall_number
;
8217 /* Skip whitespace. */
8218 while (isspace (*arg
))
8221 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8222 cur_name
[i
] = arg
[i
];
8226 /* Check if the user provided a syscall name or a number. */
8227 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8228 if (*endptr
== '\0')
8229 get_syscall_by_number (syscall_number
, &s
);
8232 /* We have a name. Let's check if it's valid and convert it
8234 get_syscall_by_name (cur_name
, &s
);
8236 if (s
.number
== UNKNOWN_SYSCALL
)
8237 /* Here we have to issue an error instead of a warning, because
8238 GDB cannot do anything useful if there's no syscall number to
8240 error (_("Unknown syscall name '%s'."), cur_name
);
8243 /* Ok, it's valid. */
8244 VEC_safe_push (int, result
, s
.number
);
8247 discard_cleanups (cleanup
);
8251 /* Implement the "catch syscall" command. */
8254 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8259 struct gdbarch
*gdbarch
= get_current_arch ();
8261 /* Checking if the feature if supported. */
8262 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8263 error (_("The feature 'catch syscall' is not supported on \
8264 this architeture yet."));
8266 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8268 ep_skip_leading_whitespace (&arg
);
8270 /* We need to do this first "dummy" translation in order
8271 to get the syscall XML file loaded or, most important,
8272 to display a warning to the user if there's no XML file
8273 for his/her architecture. */
8274 get_syscall_by_number (0, &s
);
8276 /* The allowed syntax is:
8278 catch syscall <name | number> [<name | number> ... <name | number>]
8280 Let's check if there's a syscall name. */
8283 filter
= catch_syscall_split_args (arg
);
8287 create_syscall_event_catchpoint (tempflag
, filter
,
8288 &catch_syscall_breakpoint_ops
);
8291 /* Implement the "catch assert" command. */
8294 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8296 struct gdbarch
*gdbarch
= get_current_arch ();
8298 struct symtab_and_line sal
;
8299 char *addr_string
= NULL
;
8300 struct breakpoint_ops
*ops
= NULL
;
8302 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8306 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8307 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8308 ops
, tempflag
, from_tty
);
8312 catch_command (char *arg
, int from_tty
)
8314 error (_("Catch requires an event name."));
8319 tcatch_command (char *arg
, int from_tty
)
8321 error (_("Catch requires an event name."));
8324 /* Delete breakpoints by address or line. */
8327 clear_command (char *arg
, int from_tty
)
8329 struct breakpoint
*b
;
8330 VEC(breakpoint_p
) *found
= 0;
8333 struct symtabs_and_lines sals
;
8334 struct symtab_and_line sal
;
8339 sals
= decode_line_spec (arg
, 1);
8344 sals
.sals
= (struct symtab_and_line
*)
8345 xmalloc (sizeof (struct symtab_and_line
));
8346 make_cleanup (xfree
, sals
.sals
);
8347 init_sal (&sal
); /* initialize to zeroes */
8348 sal
.line
= default_breakpoint_line
;
8349 sal
.symtab
= default_breakpoint_symtab
;
8350 sal
.pc
= default_breakpoint_address
;
8351 sal
.pspace
= default_breakpoint_pspace
;
8352 if (sal
.symtab
== 0)
8353 error (_("No source file specified."));
8361 /* We don't call resolve_sal_pc here. That's not
8362 as bad as it seems, because all existing breakpoints
8363 typically have both file/line and pc set. So, if
8364 clear is given file/line, we can match this to existing
8365 breakpoint without obtaining pc at all.
8367 We only support clearing given the address explicitly
8368 present in breakpoint table. Say, we've set breakpoint
8369 at file:line. There were several PC values for that file:line,
8370 due to optimization, all in one block.
8371 We've picked one PC value. If "clear" is issued with another
8372 PC corresponding to the same file:line, the breakpoint won't
8373 be cleared. We probably can still clear the breakpoint, but
8374 since the other PC value is never presented to user, user
8375 can only find it by guessing, and it does not seem important
8378 /* For each line spec given, delete bps which correspond
8379 to it. Do it in two passes, solely to preserve the current
8380 behavior that from_tty is forced true if we delete more than
8384 for (i
= 0; i
< sals
.nelts
; i
++)
8386 /* If exact pc given, clear bpts at that pc.
8387 If line given (pc == 0), clear all bpts on specified line.
8388 If defaulting, clear all bpts on default line
8391 defaulting sal.pc != 0 tests to do
8396 1 0 <can't happen> */
8400 /* Find all matching breakpoints and add them to
8405 /* Are we going to delete b? */
8406 if (b
->type
!= bp_none
8407 && b
->type
!= bp_watchpoint
8408 && b
->type
!= bp_hardware_watchpoint
8409 && b
->type
!= bp_read_watchpoint
8410 && b
->type
!= bp_access_watchpoint
)
8412 struct bp_location
*loc
= b
->loc
;
8413 for (; loc
; loc
= loc
->next
)
8415 int pc_match
= sal
.pc
8416 && (loc
->pspace
== sal
.pspace
)
8417 && (loc
->address
== sal
.pc
)
8418 && (!section_is_overlay (loc
->section
)
8419 || loc
->section
== sal
.section
);
8420 int line_match
= ((default_match
|| (0 == sal
.pc
))
8421 && b
->source_file
!= NULL
8422 && sal
.symtab
!= NULL
8423 && sal
.pspace
== loc
->pspace
8424 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8425 && b
->line_number
== sal
.line
);
8426 if (pc_match
|| line_match
)
8435 VEC_safe_push(breakpoint_p
, found
, b
);
8438 /* Now go thru the 'found' chain and delete them. */
8439 if (VEC_empty(breakpoint_p
, found
))
8442 error (_("No breakpoint at %s."), arg
);
8444 error (_("No breakpoint at this line."));
8447 if (VEC_length(breakpoint_p
, found
) > 1)
8448 from_tty
= 1; /* Always report if deleted more than one */
8451 if (VEC_length(breakpoint_p
, found
) == 1)
8452 printf_unfiltered (_("Deleted breakpoint "));
8454 printf_unfiltered (_("Deleted breakpoints "));
8456 breakpoints_changed ();
8458 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8461 printf_unfiltered ("%d ", b
->number
);
8462 delete_breakpoint (b
);
8465 putchar_unfiltered ('\n');
8468 /* Delete breakpoint in BS if they are `delete' breakpoints and
8469 all breakpoints that are marked for deletion, whether hit or not.
8470 This is called after any breakpoint is hit, or after errors. */
8473 breakpoint_auto_delete (bpstat bs
)
8475 struct breakpoint
*b
, *temp
;
8477 for (; bs
; bs
= bs
->next
)
8478 if (bs
->breakpoint_at
8479 && bs
->breakpoint_at
->owner
8480 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8482 delete_breakpoint (bs
->breakpoint_at
->owner
);
8484 ALL_BREAKPOINTS_SAFE (b
, temp
)
8486 if (b
->disposition
== disp_del_at_next_stop
)
8487 delete_breakpoint (b
);
8491 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8492 Sort elements primarily by their ADDRESS (no matter what does
8493 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8494 first bp_permanent OWNERed elements and terciarily just ensuring the array
8495 is sorted stable way despite qsort being an instable algorithm. */
8498 bp_location_compare (const void *ap
, const void *bp
)
8500 struct bp_location
*a
= *(void **) ap
;
8501 struct bp_location
*b
= *(void **) bp
;
8502 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8503 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8505 if (a
->address
!= b
->address
)
8506 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8508 /* Sort permanent breakpoints first. */
8509 if (a_perm
!= b_perm
)
8510 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8512 /* Make the user-visible order stable across GDB runs. Locations of the same
8513 breakpoint can be sorted in arbitrary order. */
8515 if (a
->owner
->number
!= b
->owner
->number
)
8516 return (a
->owner
->number
> b
->owner
->number
)
8517 - (a
->owner
->number
< b
->owner
->number
);
8519 return (a
> b
) - (a
< b
);
8522 /* Set bp_location_placed_address_before_address_max and
8523 bp_location_shadow_len_after_address_max according to the current content of
8524 the bp_location array. */
8527 bp_location_target_extensions_update (void)
8529 struct bp_location
*bl
, **blp_tmp
;
8531 bp_location_placed_address_before_address_max
= 0;
8532 bp_location_shadow_len_after_address_max
= 0;
8534 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8536 CORE_ADDR start
, end
, addr
;
8538 if (!bp_location_has_shadow (bl
))
8541 start
= bl
->target_info
.placed_address
;
8542 end
= start
+ bl
->target_info
.shadow_len
;
8544 gdb_assert (bl
->address
>= start
);
8545 addr
= bl
->address
- start
;
8546 if (addr
> bp_location_placed_address_before_address_max
)
8547 bp_location_placed_address_before_address_max
= addr
;
8549 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8551 gdb_assert (bl
->address
< end
);
8552 addr
= end
- bl
->address
;
8553 if (addr
> bp_location_shadow_len_after_address_max
)
8554 bp_location_shadow_len_after_address_max
= addr
;
8558 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8559 into the inferior, only remove already-inserted locations that no
8560 longer should be inserted. Functions that delete a breakpoint or
8561 breakpoints should pass false, so that deleting a breakpoint
8562 doesn't have the side effect of inserting the locations of other
8563 breakpoints that are marked not-inserted, but should_be_inserted
8564 returns true on them.
8566 This behaviour is useful is situations close to tear-down -- e.g.,
8567 after an exec, while the target still has execution, but breakpoint
8568 shadows of the previous executable image should *NOT* be restored
8569 to the new image; or before detaching, where the target still has
8570 execution and wants to delete breakpoints from GDB's lists, and all
8571 breakpoints had already been removed from the inferior. */
8574 update_global_location_list (int should_insert
)
8576 struct breakpoint
*b
;
8577 struct bp_location
**locp
, *loc
;
8578 struct cleanup
*cleanups
;
8580 /* Used in the duplicates detection below. When iterating over all
8581 bp_locations, points to the first bp_location of a given address.
8582 Breakpoints and watchpoints of different types are never
8583 duplicates of each other. Keep one pointer for each type of
8584 breakpoint/watchpoint, so we only need to loop over all locations
8586 struct bp_location
*bp_loc_first
; /* breakpoint */
8587 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8588 struct bp_location
*awp_loc_first
; /* access watchpoint */
8589 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8591 /* Saved former bp_location array which we compare against the newly built
8592 bp_location from the current state of ALL_BREAKPOINTS. */
8593 struct bp_location
**old_location
, **old_locp
;
8594 unsigned old_location_count
;
8596 old_location
= bp_location
;
8597 old_location_count
= bp_location_count
;
8599 bp_location_count
= 0;
8600 cleanups
= make_cleanup (xfree
, old_location
);
8603 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8604 bp_location_count
++;
8606 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8609 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8611 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8612 bp_location_compare
);
8614 bp_location_target_extensions_update ();
8616 /* Identify bp_location instances that are no longer present in the new
8617 list, and therefore should be freed. Note that it's not necessary that
8618 those locations should be removed from inferior -- if there's another
8619 location at the same address (previously marked as duplicate),
8620 we don't need to remove/insert the location.
8622 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8623 former bp_location array state respectively. */
8626 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8629 struct bp_location
*old_loc
= *old_locp
;
8630 struct bp_location
**loc2p
;
8632 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8634 int found_object
= 0;
8635 /* Tells if the location should remain inserted in the target. */
8636 int keep_in_target
= 0;
8639 /* Skip LOCP entries which will definitely never be needed. Stop either
8640 at or being the one matching OLD_LOC. */
8641 while (locp
< bp_location
+ bp_location_count
8642 && (*locp
)->address
< old_loc
->address
)
8646 (loc2p
< bp_location
+ bp_location_count
8647 && (*loc2p
)->address
== old_loc
->address
);
8650 if (*loc2p
== old_loc
)
8657 /* If this location is no longer present, and inserted, look if there's
8658 maybe a new location at the same address. If so, mark that one
8659 inserted, and don't remove this one. This is needed so that we
8660 don't have a time window where a breakpoint at certain location is not
8663 if (old_loc
->inserted
)
8665 /* If the location is inserted now, we might have to remove it. */
8667 if (found_object
&& should_be_inserted (old_loc
))
8669 /* The location is still present in the location list, and still
8670 should be inserted. Don't do anything. */
8675 /* The location is either no longer present, or got disabled.
8676 See if there's another location at the same address, in which
8677 case we don't need to remove this one from the target. */
8679 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8682 (loc2p
< bp_location
+ bp_location_count
8683 && (*loc2p
)->address
== old_loc
->address
);
8686 struct bp_location
*loc2
= *loc2p
;
8688 if (breakpoint_locations_match (loc2
, old_loc
))
8690 /* For the sake of should_be_inserted.
8691 Duplicates check below will fix up this later. */
8692 loc2
->duplicate
= 0;
8694 /* Read watchpoint locations are switched to
8695 access watchpoints, if the former are not
8696 supported, but the latter are. */
8697 if (is_hardware_watchpoint (old_loc
->owner
))
8699 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8700 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8703 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8706 loc2
->target_info
= old_loc
->target_info
;
8715 if (!keep_in_target
)
8717 if (remove_breakpoint (old_loc
, mark_uninserted
))
8719 /* This is just about all we can do. We could keep this
8720 location on the global list, and try to remove it next
8721 time, but there's no particular reason why we will
8724 Note that at this point, old_loc->owner is still valid,
8725 as delete_breakpoint frees the breakpoint only
8726 after calling us. */
8727 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8728 old_loc
->owner
->number
);
8736 if (removed
&& non_stop
8737 && breakpoint_address_is_meaningful (old_loc
->owner
)
8738 && !is_hardware_watchpoint (old_loc
->owner
))
8740 /* This location was removed from the target. In
8741 non-stop mode, a race condition is possible where
8742 we've removed a breakpoint, but stop events for that
8743 breakpoint are already queued and will arrive later.
8744 We apply an heuristic to be able to distinguish such
8745 SIGTRAPs from other random SIGTRAPs: we keep this
8746 breakpoint location for a bit, and will retire it
8747 after we see some number of events. The theory here
8748 is that reporting of events should, "on the average",
8749 be fair, so after a while we'll see events from all
8750 threads that have anything of interest, and no longer
8751 need to keep this breakpoint location around. We
8752 don't hold locations forever so to reduce chances of
8753 mistaking a non-breakpoint SIGTRAP for a breakpoint
8756 The heuristic failing can be disastrous on
8757 decr_pc_after_break targets.
8759 On decr_pc_after_break targets, like e.g., x86-linux,
8760 if we fail to recognize a late breakpoint SIGTRAP,
8761 because events_till_retirement has reached 0 too
8762 soon, we'll fail to do the PC adjustment, and report
8763 a random SIGTRAP to the user. When the user resumes
8764 the inferior, it will most likely immediately crash
8765 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
8766 corrupted, because of being resumed e.g., in the
8767 middle of a multi-byte instruction, or skipped a
8768 one-byte instruction. This was actually seen happen
8769 on native x86-linux, and should be less rare on
8770 targets that do not support new thread events, like
8771 remote, due to the heuristic depending on
8774 Mistaking a random SIGTRAP for a breakpoint trap
8775 causes similar symptoms (PC adjustment applied when
8776 it shouldn't), but then again, playing with SIGTRAPs
8777 behind the debugger's back is asking for trouble.
8779 Since hardware watchpoint traps are always
8780 distinguishable from other traps, so we don't need to
8781 apply keep hardware watchpoint moribund locations
8782 around. We simply always ignore hardware watchpoint
8783 traps we can no longer explain. */
8785 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
8786 old_loc
->owner
= NULL
;
8788 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
8791 free_bp_location (old_loc
);
8795 /* Rescan breakpoints at the same address and section, marking the
8796 first one as "first" and any others as "duplicates". This is so
8797 that the bpt instruction is only inserted once. If we have a
8798 permanent breakpoint at the same place as BPT, make that one the
8799 official one, and the rest as duplicates. Permanent breakpoints
8800 are sorted first for the same address.
8802 Do the same for hardware watchpoints, but also considering the
8803 watchpoint's type (regular/access/read) and length. */
8805 bp_loc_first
= NULL
;
8806 wp_loc_first
= NULL
;
8807 awp_loc_first
= NULL
;
8808 rwp_loc_first
= NULL
;
8809 ALL_BP_LOCATIONS (loc
, locp
)
8811 struct breakpoint
*b
= loc
->owner
;
8812 struct bp_location
**loc_first_p
;
8814 if (b
->enable_state
== bp_disabled
8815 || b
->enable_state
== bp_call_disabled
8816 || b
->enable_state
== bp_startup_disabled
8818 || loc
->shlib_disabled
8819 || !breakpoint_address_is_meaningful (b
)
8820 || tracepoint_type (b
))
8823 /* Permanent breakpoint should always be inserted. */
8824 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
8825 internal_error (__FILE__
, __LINE__
,
8826 _("allegedly permanent breakpoint is not "
8827 "actually inserted"));
8829 if (b
->type
== bp_hardware_watchpoint
)
8830 loc_first_p
= &wp_loc_first
;
8831 else if (b
->type
== bp_read_watchpoint
)
8832 loc_first_p
= &rwp_loc_first
;
8833 else if (b
->type
== bp_access_watchpoint
)
8834 loc_first_p
= &awp_loc_first
;
8836 loc_first_p
= &bp_loc_first
;
8838 if (*loc_first_p
== NULL
8839 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
8840 || !breakpoint_locations_match (loc
, *loc_first_p
))
8849 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
8850 && b
->enable_state
!= bp_permanent
)
8851 internal_error (__FILE__
, __LINE__
,
8852 _("another breakpoint was inserted on top of "
8853 "a permanent breakpoint"));
8856 if (breakpoints_always_inserted_mode () && should_insert
8857 && (have_live_inferiors ()
8858 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
8859 insert_breakpoint_locations ();
8861 do_cleanups (cleanups
);
8865 breakpoint_retire_moribund (void)
8867 struct bp_location
*loc
;
8870 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
8871 if (--(loc
->events_till_retirement
) == 0)
8873 free_bp_location (loc
);
8874 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
8880 update_global_location_list_nothrow (int inserting
)
8882 struct gdb_exception e
;
8883 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8884 update_global_location_list (inserting
);
8887 /* Clear BPT from a BPS. */
8889 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
8892 for (bs
= bps
; bs
; bs
= bs
->next
)
8893 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
8895 bs
->breakpoint_at
= NULL
;
8897 /* bs->commands will be freed later. */
8901 /* Callback for iterate_over_threads. */
8903 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
8905 struct breakpoint
*bpt
= data
;
8906 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
8910 /* Delete a breakpoint and clean up all traces of it in the data
8914 delete_breakpoint (struct breakpoint
*bpt
)
8916 struct breakpoint
*b
;
8917 struct bp_location
*loc
, *next
;
8919 gdb_assert (bpt
!= NULL
);
8921 /* Has this bp already been deleted? This can happen because multiple
8922 lists can hold pointers to bp's. bpstat lists are especial culprits.
8924 One example of this happening is a watchpoint's scope bp. When the
8925 scope bp triggers, we notice that the watchpoint is out of scope, and
8926 delete it. We also delete its scope bp. But the scope bp is marked
8927 "auto-deleting", and is already on a bpstat. That bpstat is then
8928 checked for auto-deleting bp's, which are deleted.
8930 A real solution to this problem might involve reference counts in bp's,
8931 and/or giving them pointers back to their referencing bpstat's, and
8932 teaching delete_breakpoint to only free a bp's storage when no more
8933 references were extent. A cheaper bandaid was chosen. */
8934 if (bpt
->type
== bp_none
)
8937 /* At least avoid this stale reference until the reference counting of
8938 breakpoints gets resolved. */
8939 if (bpt
->related_breakpoint
!= NULL
)
8941 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
8942 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
8943 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
8944 bpt
->related_breakpoint
= NULL
;
8947 observer_notify_breakpoint_deleted (bpt
->number
);
8949 if (breakpoint_chain
== bpt
)
8950 breakpoint_chain
= bpt
->next
;
8955 b
->next
= bpt
->next
;
8959 free_command_lines (&bpt
->commands
);
8960 xfree (bpt
->cond_string
);
8961 xfree (bpt
->cond_exp
);
8962 xfree (bpt
->addr_string
);
8964 xfree (bpt
->exp_string
);
8965 value_free (bpt
->val
);
8966 xfree (bpt
->source_file
);
8967 xfree (bpt
->exec_pathname
);
8968 clean_up_filters (&bpt
->syscalls_to_be_caught
);
8970 /* Be sure no bpstat's are pointing at it after it's been freed. */
8971 /* FIXME, how can we find all bpstat's?
8972 We just check stop_bpstat for now. Note that we cannot just
8973 remove bpstats pointing at bpt from the stop_bpstat list
8974 entirely, as breakpoint commands are associated with the bpstat;
8975 if we remove it here, then the later call to
8976 bpstat_do_actions (&stop_bpstat);
8977 in event-top.c won't do anything, and temporary breakpoints
8978 with commands won't work. */
8980 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
8982 /* Now that breakpoint is removed from breakpoint
8983 list, update the global location list. This
8984 will remove locations that used to belong to
8985 this breakpoint. Do this before freeing
8986 the breakpoint itself, since remove_breakpoint
8987 looks at location's owner. It might be better
8988 design to have location completely self-contained,
8989 but it's not the case now. */
8990 update_global_location_list (0);
8993 /* On the chance that someone will soon try again to delete this same
8994 bp, we mark it as deleted before freeing its storage. */
8995 bpt
->type
= bp_none
;
9001 do_delete_breakpoint_cleanup (void *b
)
9003 delete_breakpoint (b
);
9007 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9009 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9013 delete_command (char *arg
, int from_tty
)
9015 struct breakpoint
*b
, *temp
;
9021 int breaks_to_delete
= 0;
9023 /* Delete all breakpoints if no argument.
9024 Do not delete internal or call-dummy breakpoints, these
9025 have to be deleted with an explicit breakpoint number argument. */
9028 if (b
->type
!= bp_call_dummy
9029 && b
->type
!= bp_shlib_event
9030 && b
->type
!= bp_jit_event
9031 && b
->type
!= bp_thread_event
9032 && b
->type
!= bp_overlay_event
9033 && b
->type
!= bp_longjmp_master
9036 breaks_to_delete
= 1;
9041 /* Ask user only if there are some breakpoints to delete. */
9043 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9045 ALL_BREAKPOINTS_SAFE (b
, temp
)
9047 if (b
->type
!= bp_call_dummy
9048 && b
->type
!= bp_shlib_event
9049 && b
->type
!= bp_thread_event
9050 && b
->type
!= bp_jit_event
9051 && b
->type
!= bp_overlay_event
9052 && b
->type
!= bp_longjmp_master
9054 delete_breakpoint (b
);
9059 map_breakpoint_numbers (arg
, delete_breakpoint
);
9063 all_locations_are_pending (struct bp_location
*loc
)
9065 for (; loc
; loc
= loc
->next
)
9066 if (!loc
->shlib_disabled
)
9071 /* Subroutine of update_breakpoint_locations to simplify it.
9072 Return non-zero if multiple fns in list LOC have the same name.
9073 Null names are ignored. */
9076 ambiguous_names_p (struct bp_location
*loc
)
9078 struct bp_location
*l
;
9079 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9080 (int (*) (const void *, const void *)) streq
,
9081 NULL
, xcalloc
, xfree
);
9083 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9086 const char *name
= l
->function_name
;
9088 /* Allow for some names to be NULL, ignore them. */
9092 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9094 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9109 update_breakpoint_locations (struct breakpoint
*b
,
9110 struct symtabs_and_lines sals
)
9114 struct bp_location
*existing_locations
= b
->loc
;
9116 /* If there's no new locations, and all existing locations
9117 are pending, don't do anything. This optimizes
9118 the common case where all locations are in the same
9119 shared library, that was unloaded. We'd like to
9120 retain the location, so that when the library
9121 is loaded again, we don't loose the enabled/disabled
9122 status of the individual locations. */
9123 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9128 for (i
= 0; i
< sals
.nelts
; ++i
)
9130 struct bp_location
*new_loc
=
9131 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9133 /* Reparse conditions, they might contain references to the
9135 if (b
->cond_string
!= NULL
)
9137 struct gdb_exception e
;
9140 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9142 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9147 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9148 b
->number
, e
.message
);
9149 new_loc
->enabled
= 0;
9153 if (b
->source_file
!= NULL
)
9154 xfree (b
->source_file
);
9155 if (sals
.sals
[i
].symtab
== NULL
)
9156 b
->source_file
= NULL
;
9158 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9160 if (b
->line_number
== 0)
9161 b
->line_number
= sals
.sals
[i
].line
;
9164 /* Update locations of permanent breakpoints. */
9165 if (b
->enable_state
== bp_permanent
)
9166 make_breakpoint_permanent (b
);
9168 /* If possible, carry over 'disable' status from existing breakpoints. */
9170 struct bp_location
*e
= existing_locations
;
9171 /* If there are multiple breakpoints with the same function name,
9172 e.g. for inline functions, comparing function names won't work.
9173 Instead compare pc addresses; this is just a heuristic as things
9174 may have moved, but in practice it gives the correct answer
9175 often enough until a better solution is found. */
9176 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9178 for (; e
; e
= e
->next
)
9180 if (!e
->enabled
&& e
->function_name
)
9182 struct bp_location
*l
= b
->loc
;
9183 if (have_ambiguous_names
)
9185 for (; l
; l
= l
->next
)
9186 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9187 l
->pspace
->aspace
, l
->address
))
9195 for (; l
; l
= l
->next
)
9196 if (l
->function_name
9197 && strcmp (e
->function_name
, l
->function_name
) == 0)
9207 update_global_location_list (1);
9211 /* Reset a breakpoint given it's struct breakpoint * BINT.
9212 The value we return ends up being the return value from catch_errors.
9213 Unused in this case. */
9216 breakpoint_re_set_one (void *bint
)
9218 /* get past catch_errs */
9219 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9223 int *not_found_ptr
= ¬_found
;
9224 struct symtabs_and_lines sals
= {0};
9225 struct symtabs_and_lines expanded
= {0};
9227 enum enable_state save_enable
;
9228 struct gdb_exception e
;
9229 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9234 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9238 case bp_hardware_breakpoint
:
9240 case bp_fast_tracepoint
:
9241 /* Do not attempt to re-set breakpoints disabled during startup. */
9242 if (b
->enable_state
== bp_startup_disabled
)
9245 if (b
->addr_string
== NULL
)
9247 /* Anything without a string can't be re-set. */
9248 delete_breakpoint (b
);
9252 set_language (b
->language
);
9253 input_radix
= b
->input_radix
;
9256 save_current_space_and_thread ();
9257 switch_to_program_space_and_thread (b
->pspace
);
9259 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9261 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9266 int not_found_and_ok
= 0;
9267 /* For pending breakpoints, it's expected that parsing
9268 will fail until the right shared library is loaded.
9269 User has already told to create pending breakpoints and
9270 don't need extra messages. If breakpoint is in bp_shlib_disabled
9271 state, then user already saw the message about that breakpoint
9272 being disabled, and don't want to see more errors. */
9274 && (b
->condition_not_parsed
9275 || (b
->loc
&& b
->loc
->shlib_disabled
)
9276 || b
->enable_state
== bp_disabled
))
9277 not_found_and_ok
= 1;
9279 if (!not_found_and_ok
)
9281 /* We surely don't want to warn about the same breakpoint
9282 10 times. One solution, implemented here, is disable
9283 the breakpoint on error. Another solution would be to
9284 have separate 'warning emitted' flag. Since this
9285 happens only when a binary has changed, I don't know
9286 which approach is better. */
9287 b
->enable_state
= bp_disabled
;
9288 throw_exception (e
);
9294 gdb_assert (sals
.nelts
== 1);
9296 resolve_sal_pc (&sals
.sals
[0]);
9297 if (b
->condition_not_parsed
&& s
&& s
[0])
9299 char *cond_string
= 0;
9303 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9304 &cond_string
, &thread
, &task
);
9306 b
->cond_string
= cond_string
;
9309 b
->condition_not_parsed
= 0;
9312 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9315 make_cleanup (xfree
, sals
.sals
);
9316 update_breakpoint_locations (b
, expanded
);
9320 case bp_hardware_watchpoint
:
9321 case bp_read_watchpoint
:
9322 case bp_access_watchpoint
:
9323 /* Watchpoint can be either on expression using entirely global variables,
9324 or it can be on local variables.
9326 Watchpoints of the first kind are never auto-deleted, and even persist
9327 across program restarts. Since they can use variables from shared
9328 libraries, we need to reparse expression as libraries are loaded
9331 Watchpoints on local variables can also change meaning as result
9332 of solib event. For example, if a watchpoint uses both a local and
9333 a global variables in expression, it's a local watchpoint, but
9334 unloading of a shared library will make the expression invalid.
9335 This is not a very common use case, but we still re-evaluate
9336 expression, to avoid surprises to the user.
9338 Note that for local watchpoints, we re-evaluate it only if
9339 watchpoints frame id is still valid. If it's not, it means
9340 the watchpoint is out of scope and will be deleted soon. In fact,
9341 I'm not sure we'll ever be called in this case.
9343 If a local watchpoint's frame id is still valid, then
9344 b->exp_valid_block is likewise valid, and we can safely use it.
9346 Don't do anything about disabled watchpoints, since they will
9347 be reevaluated again when enabled. */
9348 update_watchpoint (b
, 1 /* reparse */);
9350 /* We needn't really do anything to reset these, since the mask
9351 that requests them is unaffected by e.g., new libraries being
9357 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9359 /* Delete overlay event and longjmp master breakpoints; they will be
9360 reset later by breakpoint_re_set. */
9361 case bp_overlay_event
:
9362 case bp_longjmp_master
:
9363 delete_breakpoint (b
);
9366 /* This breakpoint is special, it's set up when the inferior
9367 starts and we really don't want to touch it. */
9368 case bp_shlib_event
:
9370 /* Like bp_shlib_event, this breakpoint type is special.
9371 Once it is set up, we do not want to touch it. */
9372 case bp_thread_event
:
9374 /* Keep temporary breakpoints, which can be encountered when we step
9375 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9376 Otherwise these should have been blown away via the cleanup chain
9377 or by breakpoint_init_inferior when we rerun the executable. */
9380 case bp_watchpoint_scope
:
9382 case bp_step_resume
:
9384 case bp_longjmp_resume
:
9389 do_cleanups (cleanups
);
9393 /* Re-set all breakpoints after symbols have been re-loaded. */
9395 breakpoint_re_set (void)
9397 struct breakpoint
*b
, *temp
;
9398 enum language save_language
;
9399 int save_input_radix
;
9400 struct cleanup
*old_chain
;
9402 save_language
= current_language
->la_language
;
9403 save_input_radix
= input_radix
;
9404 old_chain
= save_current_program_space ();
9406 ALL_BREAKPOINTS_SAFE (b
, temp
)
9408 /* Format possible error msg */
9409 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9411 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9412 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9413 do_cleanups (cleanups
);
9415 set_language (save_language
);
9416 input_radix
= save_input_radix
;
9418 jit_breakpoint_re_set ();
9420 do_cleanups (old_chain
);
9422 create_overlay_event_breakpoint ("_ovly_debug_event");
9423 create_longjmp_master_breakpoint ("longjmp");
9424 create_longjmp_master_breakpoint ("_longjmp");
9425 create_longjmp_master_breakpoint ("siglongjmp");
9426 create_longjmp_master_breakpoint ("_siglongjmp");
9429 /* Reset the thread number of this breakpoint:
9431 - If the breakpoint is for all threads, leave it as-is.
9432 - Else, reset it to the current thread for inferior_ptid. */
9434 breakpoint_re_set_thread (struct breakpoint
*b
)
9436 if (b
->thread
!= -1)
9438 if (in_thread_list (inferior_ptid
))
9439 b
->thread
= pid_to_thread_id (inferior_ptid
);
9441 /* We're being called after following a fork. The new fork is
9442 selected as current, and unless this was a vfork will have a
9443 different program space from the original thread. Reset that
9445 b
->loc
->pspace
= current_program_space
;
9449 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9450 If from_tty is nonzero, it prints a message to that effect,
9451 which ends with a period (no newline). */
9454 set_ignore_count (int bptnum
, int count
, int from_tty
)
9456 struct breakpoint
*b
;
9462 if (b
->number
== bptnum
)
9464 b
->ignore_count
= count
;
9468 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9470 else if (count
== 1)
9471 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9474 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9477 breakpoints_changed ();
9478 observer_notify_breakpoint_modified (b
->number
);
9482 error (_("No breakpoint number %d."), bptnum
);
9486 make_breakpoint_silent (struct breakpoint
*b
)
9488 /* Silence the breakpoint. */
9492 /* Command to set ignore-count of breakpoint N to COUNT. */
9495 ignore_command (char *args
, int from_tty
)
9501 error_no_arg (_("a breakpoint number"));
9503 num
= get_number (&p
);
9505 error (_("bad breakpoint number: '%s'"), args
);
9507 error (_("Second argument (specified ignore-count) is missing."));
9509 set_ignore_count (num
,
9510 longest_to_int (value_as_long (parse_and_eval (p
))),
9513 printf_filtered ("\n");
9516 /* Call FUNCTION on each of the breakpoints
9517 whose numbers are given in ARGS. */
9520 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
9525 struct breakpoint
*b
, *tmp
;
9529 error_no_arg (_("one or more breakpoint numbers"));
9536 num
= get_number_or_range (&p1
);
9539 warning (_("bad breakpoint number at or near '%s'"), p
);
9543 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9544 if (b
->number
== num
)
9546 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9549 if (related_breakpoint
)
9550 function (related_breakpoint
);
9554 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9560 static struct bp_location
*
9561 find_location_by_number (char *number
)
9563 char *dot
= strchr (number
, '.');
9567 struct breakpoint
*b
;
9568 struct bp_location
*loc
;
9573 bp_num
= get_number_or_range (&p1
);
9575 error (_("Bad breakpoint number '%s'"), number
);
9578 if (b
->number
== bp_num
)
9583 if (!b
|| b
->number
!= bp_num
)
9584 error (_("Bad breakpoint number '%s'"), number
);
9587 loc_num
= get_number_or_range (&p1
);
9589 error (_("Bad breakpoint location number '%s'"), number
);
9593 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9596 error (_("Bad breakpoint location number '%s'"), dot
+1);
9602 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9603 If from_tty is nonzero, it prints a message to that effect,
9604 which ends with a period (no newline). */
9607 disable_breakpoint (struct breakpoint
*bpt
)
9609 /* Never disable a watchpoint scope breakpoint; we want to
9610 hit them when we leave scope so we can delete both the
9611 watchpoint and its scope breakpoint at that time. */
9612 if (bpt
->type
== bp_watchpoint_scope
)
9615 /* You can't disable permanent breakpoints. */
9616 if (bpt
->enable_state
== bp_permanent
)
9619 bpt
->enable_state
= bp_disabled
;
9621 update_global_location_list (0);
9623 observer_notify_breakpoint_modified (bpt
->number
);
9627 disable_command (char *args
, int from_tty
)
9629 struct breakpoint
*bpt
;
9631 ALL_BREAKPOINTS (bpt
)
9635 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9640 case bp_fast_tracepoint
:
9642 case bp_hardware_breakpoint
:
9644 case bp_hardware_watchpoint
:
9645 case bp_read_watchpoint
:
9646 case bp_access_watchpoint
:
9647 disable_breakpoint (bpt
);
9651 else if (strchr (args
, '.'))
9653 struct bp_location
*loc
= find_location_by_number (args
);
9656 update_global_location_list (0);
9659 map_breakpoint_numbers (args
, disable_breakpoint
);
9663 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9665 int target_resources_ok
, other_type_used
;
9668 if (bpt
->type
== bp_hardware_breakpoint
)
9671 i
= hw_breakpoint_used_count ();
9672 target_resources_ok
=
9673 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9675 if (target_resources_ok
== 0)
9676 error (_("No hardware breakpoint support in the target."));
9677 else if (target_resources_ok
< 0)
9678 error (_("Hardware breakpoints used exceeds limit."));
9681 if (bpt
->type
== bp_watchpoint
9682 || bpt
->type
== bp_hardware_watchpoint
9683 || bpt
->type
== bp_read_watchpoint
9684 || bpt
->type
== bp_access_watchpoint
)
9686 struct gdb_exception e
;
9688 TRY_CATCH (e
, RETURN_MASK_ALL
)
9690 update_watchpoint (bpt
, 1 /* reparse */);
9694 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9700 if (bpt
->enable_state
!= bp_permanent
)
9701 bpt
->enable_state
= bp_enabled
;
9702 bpt
->disposition
= disposition
;
9703 update_global_location_list (1);
9704 breakpoints_changed ();
9706 observer_notify_breakpoint_modified (bpt
->number
);
9711 enable_breakpoint (struct breakpoint
*bpt
)
9713 do_enable_breakpoint (bpt
, bpt
->disposition
);
9716 /* The enable command enables the specified breakpoints (or all defined
9717 breakpoints) so they once again become (or continue to be) effective
9718 in stopping the inferior. */
9721 enable_command (char *args
, int from_tty
)
9723 struct breakpoint
*bpt
;
9725 ALL_BREAKPOINTS (bpt
)
9729 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
9734 case bp_fast_tracepoint
:
9736 case bp_hardware_breakpoint
:
9738 case bp_hardware_watchpoint
:
9739 case bp_read_watchpoint
:
9740 case bp_access_watchpoint
:
9741 enable_breakpoint (bpt
);
9745 else if (strchr (args
, '.'))
9747 struct bp_location
*loc
= find_location_by_number (args
);
9750 update_global_location_list (1);
9753 map_breakpoint_numbers (args
, enable_breakpoint
);
9757 enable_once_breakpoint (struct breakpoint
*bpt
)
9759 do_enable_breakpoint (bpt
, disp_disable
);
9763 enable_once_command (char *args
, int from_tty
)
9765 map_breakpoint_numbers (args
, enable_once_breakpoint
);
9769 enable_delete_breakpoint (struct breakpoint
*bpt
)
9771 do_enable_breakpoint (bpt
, disp_del
);
9775 enable_delete_command (char *args
, int from_tty
)
9777 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
9781 set_breakpoint_cmd (char *args
, int from_tty
)
9786 show_breakpoint_cmd (char *args
, int from_tty
)
9790 /* Invalidate last known value of any hardware watchpoint if
9791 the memory which that value represents has been written to by
9795 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
9796 const bfd_byte
*data
)
9798 struct breakpoint
*bp
;
9800 ALL_BREAKPOINTS (bp
)
9801 if (bp
->enable_state
== bp_enabled
9802 && bp
->type
== bp_hardware_watchpoint
9803 && bp
->val_valid
&& bp
->val
)
9805 struct bp_location
*loc
;
9807 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
9808 if (loc
->loc_type
== bp_loc_hardware_watchpoint
9809 && loc
->address
+ loc
->length
> addr
9810 && addr
+ len
> loc
->address
)
9812 value_free (bp
->val
);
9819 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
9821 struct symtabs_and_lines
9822 decode_line_spec_1 (char *string
, int funfirstline
)
9824 struct symtabs_and_lines sals
;
9826 error (_("Empty line specification."));
9827 if (default_breakpoint_valid
)
9828 sals
= decode_line_1 (&string
, funfirstline
,
9829 default_breakpoint_symtab
,
9830 default_breakpoint_line
,
9831 (char ***) NULL
, NULL
);
9833 sals
= decode_line_1 (&string
, funfirstline
,
9834 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
9836 error (_("Junk at end of line specification: %s"), string
);
9840 /* Create and insert a raw software breakpoint at PC. Return an
9841 identifier, which should be used to remove the breakpoint later.
9842 In general, places which call this should be using something on the
9843 breakpoint chain instead; this function should be eliminated
9847 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
9848 struct address_space
*aspace
, CORE_ADDR pc
)
9850 struct bp_target_info
*bp_tgt
;
9852 bp_tgt
= XZALLOC (struct bp_target_info
);
9854 bp_tgt
->placed_address_space
= aspace
;
9855 bp_tgt
->placed_address
= pc
;
9857 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
9859 /* Could not insert the breakpoint. */
9867 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
9870 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
9872 struct bp_target_info
*bp_tgt
= bp
;
9875 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
9881 /* One (or perhaps two) breakpoints used for software single stepping. */
9883 static void *single_step_breakpoints
[2];
9884 static struct gdbarch
*single_step_gdbarch
[2];
9886 /* Create and insert a breakpoint for software single step. */
9889 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
9890 struct address_space
*aspace
, CORE_ADDR next_pc
)
9894 if (single_step_breakpoints
[0] == NULL
)
9896 bpt_p
= &single_step_breakpoints
[0];
9897 single_step_gdbarch
[0] = gdbarch
;
9901 gdb_assert (single_step_breakpoints
[1] == NULL
);
9902 bpt_p
= &single_step_breakpoints
[1];
9903 single_step_gdbarch
[1] = gdbarch
;
9906 /* NOTE drow/2006-04-11: A future improvement to this function would be
9907 to only create the breakpoints once, and actually put them on the
9908 breakpoint chain. That would let us use set_raw_breakpoint. We could
9909 adjust the addresses each time they were needed. Doing this requires
9910 corresponding changes elsewhere where single step breakpoints are
9911 handled, however. So, for now, we use this. */
9913 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
9915 error (_("Could not insert single-step breakpoint at %s"),
9916 paddress (gdbarch
, next_pc
));
9919 /* Remove and delete any breakpoints used for software single step. */
9922 remove_single_step_breakpoints (void)
9924 gdb_assert (single_step_breakpoints
[0] != NULL
);
9926 /* See insert_single_step_breakpoint for more about this deprecated
9928 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
9929 single_step_breakpoints
[0]);
9930 single_step_gdbarch
[0] = NULL
;
9931 single_step_breakpoints
[0] = NULL
;
9933 if (single_step_breakpoints
[1] != NULL
)
9935 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
9936 single_step_breakpoints
[1]);
9937 single_step_gdbarch
[1] = NULL
;
9938 single_step_breakpoints
[1] = NULL
;
9942 /* Check whether a software single-step breakpoint is inserted at PC. */
9945 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
9949 for (i
= 0; i
< 2; i
++)
9951 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
9953 && breakpoint_address_match (bp_tgt
->placed_address_space
,
9954 bp_tgt
->placed_address
,
9962 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
9963 non-zero otherwise. */
9965 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
9967 if (syscall_catchpoint_p (bp
)
9968 && bp
->enable_state
!= bp_disabled
9969 && bp
->enable_state
!= bp_call_disabled
)
9976 catch_syscall_enabled (void)
9978 struct inferior
*inf
= current_inferior ();
9980 return inf
->total_syscalls_count
!= 0;
9984 catching_syscall_number (int syscall_number
)
9986 struct breakpoint
*bp
;
9988 ALL_BREAKPOINTS (bp
)
9989 if (is_syscall_catchpoint_enabled (bp
))
9991 if (bp
->syscalls_to_be_caught
)
9995 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
9997 if (syscall_number
== iter
)
10007 /* Complete syscall names. Used by "catch syscall". */
10009 catch_syscall_completer (struct cmd_list_element
*cmd
,
10010 char *text
, char *word
)
10012 const char **list
= get_syscall_names ();
10013 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10016 /* Tracepoint-specific operations. */
10018 /* Set tracepoint count to NUM. */
10020 set_tracepoint_count (int num
)
10022 tracepoint_count
= num
;
10023 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10027 trace_command (char *arg
, int from_tty
)
10029 if (break_command_really (get_current_arch (),
10031 NULL
, 0, 1 /* parse arg */,
10032 0 /* tempflag */, 0 /* hardwareflag */,
10034 0 /* Ignore count */,
10035 pending_break_support
,
10039 set_tracepoint_count (breakpoint_count
);
10043 ftrace_command (char *arg
, int from_tty
)
10045 if (break_command_really (get_current_arch (),
10047 NULL
, 0, 1 /* parse arg */,
10048 0 /* tempflag */, 1 /* hardwareflag */,
10050 0 /* Ignore count */,
10051 pending_break_support
,
10055 set_tracepoint_count (breakpoint_count
);
10058 /* Given information about a tracepoint as recorded on a target (which
10059 can be either a live system or a trace file), attempt to create an
10060 equivalent GDB tracepoint. This is not a reliable process, since
10061 the target does not necessarily have all the information used when
10062 the tracepoint was originally defined. */
10064 struct breakpoint
*
10065 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10068 struct breakpoint
*tp
;
10070 /* In the absence of a source location, fall back to raw address. */
10071 sprintf (buf
, "*%s", paddress (get_current_arch(), utp
->addr
));
10073 if (!break_command_really (get_current_arch (),
10075 NULL
, 0, 1 /* parse arg */,
10077 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10079 0 /* Ignore count */,
10080 pending_break_support
,
10083 utp
->enabled
/* enabled */))
10086 set_tracepoint_count (breakpoint_count
);
10088 tp
= get_tracepoint (tracepoint_count
);
10089 gdb_assert (tp
!= NULL
);
10093 sprintf (buf
, "%d %d", utp
->pass
, tp
->number
);
10095 trace_pass_command (buf
, 0);
10100 printf_filtered ("Want to restore a condition\n");
10103 if (utp
->numactions
> 0)
10105 printf_filtered ("Want to restore action list\n");
10108 if (utp
->num_step_actions
> 0)
10110 printf_filtered ("Want to restore action list\n");
10116 /* Print information on tracepoint number TPNUM_EXP, or all if
10120 tracepoints_info (char *tpnum_exp
, int from_tty
)
10122 struct breakpoint
*b
;
10123 int tps_to_list
= 0;
10125 /* In the no-arguments case, say "No tracepoints" if none found. */
10126 if (tpnum_exp
== 0)
10128 ALL_TRACEPOINTS (b
)
10130 if (b
->number
>= 0)
10138 ui_out_message (uiout
, 0, "No tracepoints.\n");
10143 /* Otherwise be the same as "info break". */
10144 breakpoints_info (tpnum_exp
, from_tty
);
10147 /* The 'enable trace' command enables tracepoints.
10148 Not supported by all targets. */
10150 enable_trace_command (char *args
, int from_tty
)
10152 enable_command (args
, from_tty
);
10155 /* The 'disable trace' command disables tracepoints.
10156 Not supported by all targets. */
10158 disable_trace_command (char *args
, int from_tty
)
10160 disable_command (args
, from_tty
);
10163 /* Remove a tracepoint (or all if no argument) */
10165 delete_trace_command (char *arg
, int from_tty
)
10167 struct breakpoint
*b
, *temp
;
10173 int breaks_to_delete
= 0;
10175 /* Delete all breakpoints if no argument.
10176 Do not delete internal or call-dummy breakpoints, these
10177 have to be deleted with an explicit breakpoint number argument. */
10178 ALL_TRACEPOINTS (b
)
10180 if (b
->number
>= 0)
10182 breaks_to_delete
= 1;
10187 /* Ask user only if there are some breakpoints to delete. */
10189 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10191 ALL_BREAKPOINTS_SAFE (b
, temp
)
10193 if (tracepoint_type (b
)
10195 delete_breakpoint (b
);
10200 map_breakpoint_numbers (arg
, delete_breakpoint
);
10203 /* Set passcount for tracepoint.
10205 First command argument is passcount, second is tracepoint number.
10206 If tracepoint number omitted, apply to most recently defined.
10207 Also accepts special argument "all". */
10210 trace_pass_command (char *args
, int from_tty
)
10212 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10213 unsigned int count
;
10216 if (args
== 0 || *args
== 0)
10217 error (_("passcount command requires an argument (count + optional TP num)"));
10219 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10221 while (*args
&& isspace ((int) *args
))
10224 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10226 args
+= 3; /* Skip special argument "all". */
10229 error (_("Junk at end of arguments."));
10232 t1
= get_tracepoint_by_number (&args
, 1, 1);
10238 ALL_TRACEPOINTS (t2
)
10239 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10241 t2
->pass_count
= count
;
10242 observer_notify_tracepoint_modified (t2
->number
);
10244 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10245 t2
->number
, count
);
10247 if (! all
&& *args
)
10248 t1
= get_tracepoint_by_number (&args
, 1, 0);
10254 struct breakpoint
*
10255 get_tracepoint (int num
)
10257 struct breakpoint
*t
;
10259 ALL_TRACEPOINTS (t
)
10260 if (t
->number
== num
)
10266 /* Find the tracepoint with the given target-side number (which may be
10267 different from the tracepoint number after disconnecting and
10270 struct breakpoint
*
10271 get_tracepoint_by_number_on_target (int num
)
10273 struct breakpoint
*t
;
10275 ALL_TRACEPOINTS (t
)
10276 if (t
->number_on_target
== num
)
10282 /* Utility: parse a tracepoint number and look it up in the list.
10283 If MULTI_P is true, there might be a range of tracepoints in ARG.
10284 if OPTIONAL_P is true, then if the argument is missing, the most
10285 recent tracepoint (tracepoint_count) is returned. */
10286 struct breakpoint
*
10287 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10289 extern int tracepoint_count
;
10290 struct breakpoint
*t
;
10292 char *instring
= arg
== NULL
? NULL
: *arg
;
10294 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10297 tpnum
= tracepoint_count
;
10299 error_no_arg (_("tracepoint number"));
10302 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10306 if (instring
&& *instring
)
10307 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10310 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10314 ALL_TRACEPOINTS (t
)
10315 if (t
->number
== tpnum
)
10320 /* FIXME: if we are in the middle of a range we don't want to give
10321 a message. The current interface to get_number_or_range doesn't
10322 allow us to discover this. */
10323 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10327 /* save-tracepoints command */
10329 tracepoint_save_command (char *args
, int from_tty
)
10331 struct breakpoint
*tp
;
10333 struct action_line
*line
;
10335 char *i1
= " ", *i2
= " ";
10336 char *indent
, *actionline
, *pathname
;
10338 struct cleanup
*cleanup
;
10340 if (args
== 0 || *args
== 0)
10341 error (_("Argument required (file name in which to save tracepoints)"));
10343 /* See if we have anything to save. */
10344 ALL_TRACEPOINTS (tp
)
10351 warning (_("save-tracepoints: no tracepoints to save."));
10355 pathname
= tilde_expand (args
);
10356 cleanup
= make_cleanup (xfree
, pathname
);
10357 fp
= fopen (pathname
, "w");
10359 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10360 args
, safe_strerror (errno
));
10361 make_cleanup_fclose (fp
);
10363 ALL_TRACEPOINTS (tp
)
10365 if (tp
->addr_string
)
10366 fprintf (fp
, "trace %s\n", tp
->addr_string
);
10369 sprintf_vma (tmp
, tp
->loc
->address
);
10370 fprintf (fp
, "trace *0x%s\n", tmp
);
10373 if (tp
->pass_count
)
10374 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
10378 fprintf (fp
, " actions\n");
10380 for (line
= tp
->actions
; line
; line
= line
->next
)
10382 struct cmd_list_element
*cmd
;
10384 QUIT
; /* allow user to bail out with ^C */
10385 actionline
= line
->action
;
10386 while (isspace ((int) *actionline
))
10389 fprintf (fp
, "%s%s\n", indent
, actionline
);
10390 if (*actionline
!= '#') /* skip for comment lines */
10392 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
10394 error (_("Bad action list item: %s"), actionline
);
10395 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
10397 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
10403 do_cleanups (cleanup
);
10405 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10409 /* Create a vector of all tracepoints. */
10411 VEC(breakpoint_p
) *
10414 VEC(breakpoint_p
) *tp_vec
= 0;
10415 struct breakpoint
*tp
;
10417 ALL_TRACEPOINTS (tp
)
10419 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10426 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10427 It is defined as a macro to prevent duplication.
10428 COMMAND should be a string constant containing the name of the command. */
10429 #define BREAK_ARGS_HELP(command) \
10430 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10431 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10432 If a line number is specified, break at start of code for that line.\n\
10433 If a function is specified, break at start of code for that function.\n\
10434 If an address is specified, break at that exact address.\n\
10435 With no LOCATION, uses current execution address of selected stack frame.\n\
10436 This is useful for breaking on return to a stack frame.\n\
10438 THREADNUM is the number from \"info threads\".\n\
10439 CONDITION is a boolean expression.\n\
10441 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10443 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10445 /* List of subcommands for "catch". */
10446 static struct cmd_list_element
*catch_cmdlist
;
10448 /* List of subcommands for "tcatch". */
10449 static struct cmd_list_element
*tcatch_cmdlist
;
10451 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10452 lists, and pass some additional user data to the command function. */
10454 add_catch_command (char *name
, char *docstring
,
10455 void (*sfunc
) (char *args
, int from_tty
,
10456 struct cmd_list_element
*command
),
10457 char **(*completer
) (struct cmd_list_element
*cmd
,
10458 char *text
, char *word
),
10459 void *user_data_catch
,
10460 void *user_data_tcatch
)
10462 struct cmd_list_element
*command
;
10464 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10466 set_cmd_sfunc (command
, sfunc
);
10467 set_cmd_context (command
, user_data_catch
);
10468 set_cmd_completer (command
, completer
);
10470 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10472 set_cmd_sfunc (command
, sfunc
);
10473 set_cmd_context (command
, user_data_tcatch
);
10474 set_cmd_completer (command
, completer
);
10478 clear_syscall_counts (struct inferior
*inf
)
10480 inf
->total_syscalls_count
= 0;
10481 inf
->any_syscall_count
= 0;
10482 VEC_free (int, inf
->syscalls_counts
);
10486 _initialize_breakpoint (void)
10488 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10489 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10490 struct cmd_list_element
*c
;
10492 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10493 observer_attach_inferior_exit (clear_syscall_counts
);
10494 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10496 breakpoint_chain
= 0;
10497 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10498 before a breakpoint is set. */
10499 breakpoint_count
= 0;
10501 tracepoint_count
= 0;
10503 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10504 Set ignore-count of breakpoint number N to COUNT.\n\
10505 Usage is `ignore N COUNT'."));
10507 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10509 add_com ("commands", class_breakpoint
, commands_command
, _("\
10510 Set commands to be executed when a breakpoint is hit.\n\
10511 Give breakpoint number as argument after \"commands\".\n\
10512 With no argument, the targeted breakpoint is the last one set.\n\
10513 The commands themselves follow starting on the next line.\n\
10514 Type a line containing \"end\" to indicate the end of them.\n\
10515 Give \"silent\" as the first line to make the breakpoint silent;\n\
10516 then no output is printed when it is hit, except what the commands print."));
10518 add_com ("condition", class_breakpoint
, condition_command
, _("\
10519 Specify breakpoint number N to break only if COND is true.\n\
10520 Usage is `condition N COND', where N is an integer and COND is an\n\
10521 expression to be evaluated whenever breakpoint N is reached."));
10523 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10524 Set a temporary breakpoint.\n\
10525 Like \"break\" except the breakpoint is only temporary,\n\
10526 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10527 by using \"enable delete\" on the breakpoint number.\n\
10529 BREAK_ARGS_HELP ("tbreak")));
10530 set_cmd_completer (c
, location_completer
);
10532 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10533 Set a hardware assisted breakpoint.\n\
10534 Like \"break\" except the breakpoint requires hardware support,\n\
10535 some target hardware may not have this support.\n\
10537 BREAK_ARGS_HELP ("hbreak")));
10538 set_cmd_completer (c
, location_completer
);
10540 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10541 Set a temporary hardware assisted breakpoint.\n\
10542 Like \"hbreak\" except the breakpoint is only temporary,\n\
10543 so it will be deleted when hit.\n\
10545 BREAK_ARGS_HELP ("thbreak")));
10546 set_cmd_completer (c
, location_completer
);
10548 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10549 Enable some breakpoints.\n\
10550 Give breakpoint numbers (separated by spaces) as arguments.\n\
10551 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10552 This is used to cancel the effect of the \"disable\" command.\n\
10553 With a subcommand you can enable temporarily."),
10554 &enablelist
, "enable ", 1, &cmdlist
);
10556 add_com ("ab", class_breakpoint
, enable_command
, _("\
10557 Enable some breakpoints.\n\
10558 Give breakpoint numbers (separated by spaces) as arguments.\n\
10559 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10560 This is used to cancel the effect of the \"disable\" command.\n\
10561 With a subcommand you can enable temporarily."));
10563 add_com_alias ("en", "enable", class_breakpoint
, 1);
10565 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10566 Enable some breakpoints.\n\
10567 Give breakpoint numbers (separated by spaces) as arguments.\n\
10568 This is used to cancel the effect of the \"disable\" command.\n\
10569 May be abbreviated to simply \"enable\".\n"),
10570 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10572 add_cmd ("once", no_class
, enable_once_command
, _("\
10573 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10574 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10577 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10578 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10579 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10582 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10583 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10584 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10587 add_cmd ("once", no_class
, enable_once_command
, _("\
10588 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10589 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10592 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10593 Disable some breakpoints.\n\
10594 Arguments are breakpoint numbers with spaces in between.\n\
10595 To disable all breakpoints, give no argument.\n\
10596 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10597 &disablelist
, "disable ", 1, &cmdlist
);
10598 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10599 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10601 add_com ("sb", class_breakpoint
, disable_command
, _("\
10602 Disable some breakpoints.\n\
10603 Arguments are breakpoint numbers with spaces in between.\n\
10604 To disable all breakpoints, give no argument.\n\
10605 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10607 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10608 Disable some breakpoints.\n\
10609 Arguments are breakpoint numbers with spaces in between.\n\
10610 To disable all breakpoints, give no argument.\n\
10611 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10612 This command may be abbreviated \"disable\"."),
10615 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10616 Delete some breakpoints or auto-display expressions.\n\
10617 Arguments are breakpoint numbers with spaces in between.\n\
10618 To delete all breakpoints, give no argument.\n\
10620 Also a prefix command for deletion of other GDB objects.\n\
10621 The \"unset\" command is also an alias for \"delete\"."),
10622 &deletelist
, "delete ", 1, &cmdlist
);
10623 add_com_alias ("d", "delete", class_breakpoint
, 1);
10624 add_com_alias ("del", "delete", class_breakpoint
, 1);
10626 add_com ("db", class_breakpoint
, delete_command
, _("\
10627 Delete some breakpoints.\n\
10628 Arguments are breakpoint numbers with spaces in between.\n\
10629 To delete all breakpoints, give no argument.\n"));
10631 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10632 Delete some breakpoints or auto-display expressions.\n\
10633 Arguments are breakpoint numbers with spaces in between.\n\
10634 To delete all breakpoints, give no argument.\n\
10635 This command may be abbreviated \"delete\"."),
10638 add_com ("clear", class_breakpoint
, clear_command
, _("\
10639 Clear breakpoint at specified line or function.\n\
10640 Argument may be line number, function name, or \"*\" and an address.\n\
10641 If line number is specified, all breakpoints in that line are cleared.\n\
10642 If function is specified, breakpoints at beginning of function are cleared.\n\
10643 If an address is specified, breakpoints at that address are cleared.\n\
10645 With no argument, clears all breakpoints in the line that the selected frame\n\
10646 is executing in.\n\
10648 See also the \"delete\" command which clears breakpoints by number."));
10650 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10651 Set breakpoint at specified line or function.\n"
10652 BREAK_ARGS_HELP ("break")));
10653 set_cmd_completer (c
, location_completer
);
10655 add_com_alias ("b", "break", class_run
, 1);
10656 add_com_alias ("br", "break", class_run
, 1);
10657 add_com_alias ("bre", "break", class_run
, 1);
10658 add_com_alias ("brea", "break", class_run
, 1);
10661 add_com_alias ("ba", "break", class_breakpoint
, 1);
10665 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10666 Break in function/address or break at a line in the current file."),
10667 &stoplist
, "stop ", 1, &cmdlist
);
10668 add_cmd ("in", class_breakpoint
, stopin_command
,
10669 _("Break in function or address."), &stoplist
);
10670 add_cmd ("at", class_breakpoint
, stopat_command
,
10671 _("Break at a line in the current file."), &stoplist
);
10672 add_com ("status", class_info
, breakpoints_info
, _("\
10673 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10674 The \"Type\" column indicates one of:\n\
10675 \tbreakpoint - normal breakpoint\n\
10676 \twatchpoint - watchpoint\n\
10677 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10678 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10679 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10680 address and file/line number respectively.\n\
10682 Convenience variable \"$_\" and default examine address for \"x\"\n\
10683 are set to the address of the last breakpoint listed unless the command\n\
10684 is prefixed with \"server \".\n\n\
10685 Convenience variable \"$bpnum\" contains the number of the last\n\
10686 breakpoint set."));
10689 add_info ("breakpoints", breakpoints_info
, _("\
10690 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10691 The \"Type\" column indicates one of:\n\
10692 \tbreakpoint - normal breakpoint\n\
10693 \twatchpoint - watchpoint\n\
10694 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10695 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10696 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10697 address and file/line number respectively.\n\
10699 Convenience variable \"$_\" and default examine address for \"x\"\n\
10700 are set to the address of the last breakpoint listed unless the command\n\
10701 is prefixed with \"server \".\n\n\
10702 Convenience variable \"$bpnum\" contains the number of the last\n\
10703 breakpoint set."));
10705 add_info_alias ("b", "breakpoints", 1);
10708 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
10709 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10710 The \"Type\" column indicates one of:\n\
10711 \tbreakpoint - normal breakpoint\n\
10712 \twatchpoint - watchpoint\n\
10713 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10714 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10715 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10716 address and file/line number respectively.\n\
10718 Convenience variable \"$_\" and default examine address for \"x\"\n\
10719 are set to the address of the last breakpoint listed unless the command\n\
10720 is prefixed with \"server \".\n\n\
10721 Convenience variable \"$bpnum\" contains the number of the last\n\
10722 breakpoint set."));
10724 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
10725 Status of all breakpoints, or breakpoint number NUMBER.\n\
10726 The \"Type\" column indicates one of:\n\
10727 \tbreakpoint - normal breakpoint\n\
10728 \twatchpoint - watchpoint\n\
10729 \tlongjmp - internal breakpoint used to step through longjmp()\n\
10730 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
10731 \tuntil - internal breakpoint used by the \"until\" command\n\
10732 \tfinish - internal breakpoint used by the \"finish\" command\n\
10733 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10734 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10735 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10736 address and file/line number respectively.\n\
10738 Convenience variable \"$_\" and default examine address for \"x\"\n\
10739 are set to the address of the last breakpoint listed unless the command\n\
10740 is prefixed with \"server \".\n\n\
10741 Convenience variable \"$bpnum\" contains the number of the last\n\
10743 &maintenanceinfolist
);
10745 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
10746 Set catchpoints to catch events."),
10747 &catch_cmdlist
, "catch ",
10748 0/*allow-unknown*/, &cmdlist
);
10750 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
10751 Set temporary catchpoints to catch events."),
10752 &tcatch_cmdlist
, "tcatch ",
10753 0/*allow-unknown*/, &cmdlist
);
10755 /* Add catch and tcatch sub-commands. */
10756 add_catch_command ("catch", _("\
10757 Catch an exception, when caught.\n\
10758 With an argument, catch only exceptions with the given name."),
10759 catch_catch_command
,
10763 add_catch_command ("throw", _("\
10764 Catch an exception, when thrown.\n\
10765 With an argument, catch only exceptions with the given name."),
10766 catch_throw_command
,
10770 add_catch_command ("fork", _("Catch calls to fork."),
10771 catch_fork_command_1
,
10773 (void *) (uintptr_t) catch_fork_permanent
,
10774 (void *) (uintptr_t) catch_fork_temporary
);
10775 add_catch_command ("vfork", _("Catch calls to vfork."),
10776 catch_fork_command_1
,
10778 (void *) (uintptr_t) catch_vfork_permanent
,
10779 (void *) (uintptr_t) catch_vfork_temporary
);
10780 add_catch_command ("exec", _("Catch calls to exec."),
10781 catch_exec_command_1
,
10785 add_catch_command ("syscall", _("\
10786 Catch system calls by their names and/or numbers.\n\
10787 Arguments say which system calls to catch. If no arguments\n\
10788 are given, every system call will be caught.\n\
10789 Arguments, if given, should be one or more system call names\n\
10790 (if your system supports that), or system call numbers."),
10791 catch_syscall_command_1
,
10792 catch_syscall_completer
,
10795 add_catch_command ("exception", _("\
10796 Catch Ada exceptions, when raised.\n\
10797 With an argument, catch only exceptions with the given name."),
10798 catch_ada_exception_command
,
10802 add_catch_command ("assert", _("\
10803 Catch failed Ada assertions, when raised.\n\
10804 With an argument, catch only exceptions with the given name."),
10805 catch_assert_command
,
10810 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
10811 Set a watchpoint for an expression.\n\
10812 A watchpoint stops execution of your program whenever the value of\n\
10813 an expression changes."));
10814 set_cmd_completer (c
, expression_completer
);
10816 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
10817 Set a read watchpoint for an expression.\n\
10818 A watchpoint stops execution of your program whenever the value of\n\
10819 an expression is read."));
10820 set_cmd_completer (c
, expression_completer
);
10822 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
10823 Set a watchpoint for an expression.\n\
10824 A watchpoint stops execution of your program whenever the value of\n\
10825 an expression is either read or written."));
10826 set_cmd_completer (c
, expression_completer
);
10828 add_info ("watchpoints", breakpoints_info
,
10829 _("Synonym for ``info breakpoints''."));
10832 /* XXX: cagney/2005-02-23: This should be a boolean, and should
10833 respond to changes - contrary to the description. */
10834 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
10835 &can_use_hw_watchpoints
, _("\
10836 Set debugger's willingness to use watchpoint hardware."), _("\
10837 Show debugger's willingness to use watchpoint hardware."), _("\
10838 If zero, gdb will not use hardware for new watchpoints, even if\n\
10839 such is available. (However, any hardware watchpoints that were\n\
10840 created before setting this to nonzero, will continue to use watchpoint\n\
10843 show_can_use_hw_watchpoints
,
10844 &setlist
, &showlist
);
10846 can_use_hw_watchpoints
= 1;
10848 /* Tracepoint manipulation commands. */
10850 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
10851 Set a tracepoint at specified line or function.\n\
10853 BREAK_ARGS_HELP ("trace") "\n\
10854 Do \"help tracepoints\" for info on other tracepoint commands."));
10855 set_cmd_completer (c
, location_completer
);
10857 add_com_alias ("tp", "trace", class_alias
, 0);
10858 add_com_alias ("tr", "trace", class_alias
, 1);
10859 add_com_alias ("tra", "trace", class_alias
, 1);
10860 add_com_alias ("trac", "trace", class_alias
, 1);
10862 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
10863 Set a fast tracepoint at specified line or function.\n\
10865 BREAK_ARGS_HELP ("ftrace") "\n\
10866 Do \"help tracepoints\" for info on other tracepoint commands."));
10867 set_cmd_completer (c
, location_completer
);
10869 add_info ("tracepoints", tracepoints_info
, _("\
10870 Status of tracepoints, or tracepoint number NUMBER.\n\
10871 Convenience variable \"$tpnum\" contains the number of the\n\
10872 last tracepoint set."));
10874 add_info_alias ("tp", "tracepoints", 1);
10876 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
10877 Delete specified tracepoints.\n\
10878 Arguments are tracepoint numbers, separated by spaces.\n\
10879 No argument means delete all tracepoints."),
10882 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
10883 Disable specified tracepoints.\n\
10884 Arguments are tracepoint numbers, separated by spaces.\n\
10885 No argument means disable all tracepoints."),
10887 deprecate_cmd (c
, "disable");
10889 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
10890 Enable specified tracepoints.\n\
10891 Arguments are tracepoint numbers, separated by spaces.\n\
10892 No argument means enable all tracepoints."),
10894 deprecate_cmd (c
, "enable");
10896 add_com ("passcount", class_trace
, trace_pass_command
, _("\
10897 Set the passcount for a tracepoint.\n\
10898 The trace will end when the tracepoint has been passed 'count' times.\n\
10899 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
10900 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
10902 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
10903 Save current tracepoint definitions as a script.\n\
10904 Use the 'source' command in another debug session to restore them."));
10905 set_cmd_completer (c
, filename_completer
);
10907 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
10908 Breakpoint specific settings\n\
10909 Configure various breakpoint-specific variables such as\n\
10910 pending breakpoint behavior"),
10911 &breakpoint_set_cmdlist
, "set breakpoint ",
10912 0/*allow-unknown*/, &setlist
);
10913 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
10914 Breakpoint specific settings\n\
10915 Configure various breakpoint-specific variables such as\n\
10916 pending breakpoint behavior"),
10917 &breakpoint_show_cmdlist
, "show breakpoint ",
10918 0/*allow-unknown*/, &showlist
);
10920 add_setshow_auto_boolean_cmd ("pending", no_class
,
10921 &pending_break_support
, _("\
10922 Set debugger's behavior regarding pending breakpoints."), _("\
10923 Show debugger's behavior regarding pending breakpoints."), _("\
10924 If on, an unrecognized breakpoint location will cause gdb to create a\n\
10925 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
10926 an error. If auto, an unrecognized breakpoint location results in a\n\
10927 user-query to see if a pending breakpoint should be created."),
10929 show_pending_break_support
,
10930 &breakpoint_set_cmdlist
,
10931 &breakpoint_show_cmdlist
);
10933 pending_break_support
= AUTO_BOOLEAN_AUTO
;
10935 add_setshow_boolean_cmd ("auto-hw", no_class
,
10936 &automatic_hardware_breakpoints
, _("\
10937 Set automatic usage of hardware breakpoints."), _("\
10938 Show automatic usage of hardware breakpoints."), _("\
10939 If set, the debugger will automatically use hardware breakpoints for\n\
10940 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
10941 a warning will be emitted for such breakpoints."),
10943 show_automatic_hardware_breakpoints
,
10944 &breakpoint_set_cmdlist
,
10945 &breakpoint_show_cmdlist
);
10947 add_setshow_enum_cmd ("always-inserted", class_support
,
10948 always_inserted_enums
, &always_inserted_mode
, _("\
10949 Set mode for inserting breakpoints."), _("\
10950 Show mode for inserting breakpoints."), _("\
10951 When this mode is off, breakpoints are inserted in inferior when it is\n\
10952 resumed, and removed when execution stops. When this mode is on,\n\
10953 breakpoints are inserted immediately and removed only when the user\n\
10954 deletes the breakpoint. When this mode is auto (which is the default),\n\
10955 the behaviour depends on the non-stop setting (see help set non-stop).\n\
10956 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
10957 behaves as if always-inserted mode is on; if gdb is controlling the\n\
10958 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
10960 &show_always_inserted_mode
,
10961 &breakpoint_set_cmdlist
,
10962 &breakpoint_show_cmdlist
);
10964 automatic_hardware_breakpoints
= 1;
10966 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);