1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_delete_breakpoint (struct breakpoint
*);
84 static void enable_once_command (char *, int);
86 static void enable_once_breakpoint (struct breakpoint
*);
88 static void disable_command (char *, int);
90 static void enable_command (char *, int);
92 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
94 static void ignore_command (char *, int);
96 static int breakpoint_re_set_one (void *);
98 static void clear_command (char *, int);
100 static void catch_command (char *, int);
102 static void watch_command (char *, int);
104 static int can_use_hardware_watchpoint (struct value
*);
106 static void break_command_1 (char *, int, int);
108 static void mention (struct breakpoint
*);
110 /* This function is used in gdbtk sources and thus can not be made static. */
111 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
112 struct symtab_and_line
,
115 static void 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 void breakpoints_info (char *, int);
132 static void breakpoint_1 (int, int);
134 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
136 static int breakpoint_cond_eval (void *);
138 static void cleanup_executing_breakpoints (void *);
140 static void commands_command (char *, int);
142 static void condition_command (char *, int);
144 static int get_number_trailer (char **, int);
146 void set_breakpoint_count (int);
155 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
156 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
158 static enum print_stop_action
print_it_typical (bpstat
);
160 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
162 static int watchpoint_check (void *);
164 static void maintenance_info_breakpoints (char *, int);
166 static int hw_breakpoint_used_count (void);
168 static int hw_watchpoint_used_count (enum bptype
, int *);
170 static void hbreak_command (char *, int);
172 static void thbreak_command (char *, int);
174 static void watch_command_1 (char *, int, int);
176 static void rwatch_command (char *, int);
178 static void awatch_command (char *, int);
180 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
182 static void stop_command (char *arg
, int from_tty
);
184 static void stopin_command (char *arg
, int from_tty
);
186 static void stopat_command (char *arg
, int from_tty
);
188 static char *ep_parse_optional_if_clause (char **arg
);
190 static char *ep_parse_optional_filename (char **arg
);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
193 char *arg
, int tempflag
, int from_tty
);
195 static void tcatch_command (char *arg
, int from_tty
);
197 static void ep_skip_leading_whitespace (char **s
);
199 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
202 static void free_bp_location (struct bp_location
*loc
);
204 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
206 static void update_global_location_list (int);
208 static void update_global_location_list_nothrow (int);
210 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
212 static void insert_breakpoint_locations (void);
214 static int syscall_catchpoint_p (struct breakpoint
*b
);
216 static void tracepoints_info (char *, int);
218 static void delete_trace_command (char *, int);
220 static void enable_trace_command (char *, int);
222 static void disable_trace_command (char *, int);
224 static void trace_pass_command (char *, int);
226 static void skip_prologue_sal (struct symtab_and_line
*sal
);
229 /* Flag indicating that a command has proceeded the inferior past the
230 current breakpoint. */
232 static int breakpoint_proceeded
;
235 bpdisp_text (enum bpdisp disp
)
237 /* NOTE: the following values are a part of MI protocol and represent
238 values of 'disp' field returned when inferior stops at a breakpoint. */
239 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
240 return bpdisps
[(int) disp
];
243 /* Prototypes for exported functions. */
244 /* If FALSE, gdb will not use hardware support for watchpoints, even
245 if such is available. */
246 static int can_use_hw_watchpoints
;
249 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
250 struct cmd_list_element
*c
,
253 fprintf_filtered (file
, _("\
254 Debugger's willingness to use watchpoint hardware is %s.\n"),
258 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
259 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
260 for unrecognized breakpoint locations.
261 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
262 static enum auto_boolean pending_break_support
;
264 show_pending_break_support (struct ui_file
*file
, int from_tty
,
265 struct cmd_list_element
*c
,
268 fprintf_filtered (file
, _("\
269 Debugger's behavior regarding pending breakpoints is %s.\n"),
273 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
274 set with "break" but falling in read-only memory.
275 If 0, gdb will warn about such breakpoints, but won't automatically
276 use hardware breakpoints. */
277 static int automatic_hardware_breakpoints
;
279 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
280 struct cmd_list_element
*c
,
283 fprintf_filtered (file
, _("\
284 Automatic usage of hardware breakpoints is %s.\n"),
288 /* If on, gdb will keep breakpoints inserted even as inferior is
289 stopped, and immediately insert any new breakpoints. If off, gdb
290 will insert breakpoints into inferior only when resuming it, and
291 will remove breakpoints upon stop. If auto, GDB will behave as ON
292 if in non-stop mode, and as OFF if all-stop mode.*/
294 static const char always_inserted_auto
[] = "auto";
295 static const char always_inserted_on
[] = "on";
296 static const char always_inserted_off
[] = "off";
297 static const char *always_inserted_enums
[] = {
298 always_inserted_auto
,
303 static const char *always_inserted_mode
= always_inserted_auto
;
305 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
306 struct cmd_list_element
*c
, const char *value
)
308 if (always_inserted_mode
== always_inserted_auto
)
309 fprintf_filtered (file
, _("\
310 Always inserted breakpoint mode is %s (currently %s).\n"),
312 breakpoints_always_inserted_mode () ? "on" : "off");
314 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
318 breakpoints_always_inserted_mode (void)
320 return (always_inserted_mode
== always_inserted_on
321 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
324 void _initialize_breakpoint (void);
326 /* Are we executing breakpoint commands? */
327 static int executing_breakpoint_commands
;
329 /* Are overlay event breakpoints enabled? */
330 static int overlay_events_enabled
;
332 /* Walk the following statement or block through all breakpoints.
333 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
336 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
338 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
339 for (B = breakpoint_chain; \
340 B ? (TMP=B->next, 1): 0; \
343 /* Similar iterator for the low-level breakpoints. SAFE variant is not
344 provided so update_global_location_list must not be called while executing
345 the block of ALL_BP_LOCATIONS. */
347 #define ALL_BP_LOCATIONS(B,BP_TMP) \
348 for (BP_TMP = bp_location; \
349 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
352 /* Iterator for tracepoints only. */
354 #define ALL_TRACEPOINTS(B) \
355 for (B = breakpoint_chain; B; B = B->next) \
356 if ((B)->type == bp_tracepoint)
358 /* Chains of all breakpoints defined. */
360 struct breakpoint
*breakpoint_chain
;
362 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
364 static struct bp_location
**bp_location
;
366 /* Number of elements of BP_LOCATION. */
368 static unsigned bp_location_count
;
370 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
371 for the current elements of BP_LOCATION which get a valid result from
372 bp_location_has_shadow. You can use it for roughly limiting the subrange of
373 BP_LOCATION to scan for shadow bytes for an address you need to read. */
375 static CORE_ADDR bp_location_placed_address_before_address_max
;
377 /* Maximum offset plus alignment between
378 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
379 the current elements of BP_LOCATION which get a valid result from
380 bp_location_has_shadow. You can use it for roughly limiting the subrange of
381 BP_LOCATION to scan for shadow bytes for an address you need to read. */
383 static CORE_ADDR bp_location_shadow_len_after_address_max
;
385 /* The locations that no longer correspond to any breakpoint,
386 unlinked from bp_location array, but for which a hit
387 may still be reported by a target. */
388 VEC(bp_location_p
) *moribund_locations
= NULL
;
390 /* Number of last breakpoint made. */
392 int breakpoint_count
;
394 /* Number of last tracepoint made. */
396 int tracepoint_count
;
398 /* Return whether a breakpoint is an active enabled breakpoint. */
400 breakpoint_enabled (struct breakpoint
*b
)
402 return (b
->enable_state
== bp_enabled
);
405 /* Set breakpoint count to NUM. */
408 set_breakpoint_count (int num
)
410 breakpoint_count
= num
;
411 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
414 /* Used in run_command to zero the hit count when a new run starts. */
417 clear_breakpoint_hit_counts (void)
419 struct breakpoint
*b
;
425 /* Default address, symtab and line to put a breakpoint at
426 for "break" command with no arg.
427 if default_breakpoint_valid is zero, the other three are
428 not valid, and "break" with no arg is an error.
430 This set by print_stack_frame, which calls set_default_breakpoint. */
432 int default_breakpoint_valid
;
433 CORE_ADDR default_breakpoint_address
;
434 struct symtab
*default_breakpoint_symtab
;
435 int default_breakpoint_line
;
436 struct program_space
*default_breakpoint_pspace
;
439 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
440 Advance *PP after the string and any trailing whitespace.
442 Currently the string can either be a number or "$" followed by the name
443 of a convenience variable. Making it an expression wouldn't work well
444 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
446 If the string is a NULL pointer, that denotes the last breakpoint.
448 TRAILER is a character which can be found after the number; most
449 commonly this is `-'. If you don't want a trailer, use \0. */
451 get_number_trailer (char **pp
, int trailer
)
453 int retval
= 0; /* default */
457 /* Empty line means refer to the last breakpoint. */
458 return breakpoint_count
;
461 /* Make a copy of the name, so we can null-terminate it
462 to pass to lookup_internalvar(). */
467 while (isalnum (*p
) || *p
== '_')
469 varname
= (char *) alloca (p
- start
+ 1);
470 strncpy (varname
, start
, p
- start
);
471 varname
[p
- start
] = '\0';
472 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
476 printf_filtered (_("Convenience variable must have integer value.\n"));
484 while (*p
>= '0' && *p
<= '9')
487 /* There is no number here. (e.g. "cond a == b"). */
489 /* Skip non-numeric token */
490 while (*p
&& !isspace((int) *p
))
492 /* Return zero, which caller must interpret as error. */
498 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
500 /* Trailing junk: return 0 and let caller print error msg. */
501 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
512 /* Like get_number_trailer, but don't allow a trailer. */
514 get_number (char **pp
)
516 return get_number_trailer (pp
, '\0');
519 /* Parse a number or a range.
520 * A number will be of the form handled by get_number.
521 * A range will be of the form <number1> - <number2>, and
522 * will represent all the integers between number1 and number2,
525 * While processing a range, this fuction is called iteratively;
526 * At each call it will return the next value in the range.
528 * At the beginning of parsing a range, the char pointer PP will
529 * be advanced past <number1> and left pointing at the '-' token.
530 * Subsequent calls will not advance the pointer until the range
531 * is completed. The call that completes the range will advance
532 * pointer PP past <number2>.
536 get_number_or_range (char **pp
)
538 static int last_retval
, end_value
;
539 static char *end_ptr
;
540 static int in_range
= 0;
544 /* Default case: pp is pointing either to a solo number,
545 or to the first number of a range. */
546 last_retval
= get_number_trailer (pp
, '-');
551 /* This is the start of a range (<number1> - <number2>).
552 Skip the '-', parse and remember the second number,
553 and also remember the end of the final token. */
557 while (isspace ((int) *end_ptr
))
558 end_ptr
++; /* skip white space */
559 end_value
= get_number (temp
);
560 if (end_value
< last_retval
)
562 error (_("inverted range"));
564 else if (end_value
== last_retval
)
566 /* degenerate range (number1 == number2). Advance the
567 token pointer so that the range will be treated as a
576 error (_("negative value"));
579 /* pp points to the '-' that betokens a range. All
580 number-parsing has already been done. Return the next
581 integer value (one greater than the saved previous value).
582 Do not advance the token pointer 'pp' until the end of range
585 if (++last_retval
== end_value
)
587 /* End of range reached; advance token pointer. */
595 /* Return the breakpoint with the specified number, or NULL
596 if the number does not refer to an existing breakpoint. */
599 get_breakpoint (int num
)
601 struct breakpoint
*b
;
604 if (b
->number
== num
)
611 /* condition N EXP -- set break condition of breakpoint N to EXP. */
614 condition_command (char *arg
, int from_tty
)
616 struct breakpoint
*b
;
621 error_no_arg (_("breakpoint number"));
624 bnum
= get_number (&p
);
626 error (_("Bad breakpoint argument: '%s'"), arg
);
629 if (b
->number
== bnum
)
631 struct bp_location
*loc
= b
->loc
;
632 for (; loc
; loc
= loc
->next
)
640 if (b
->cond_string
!= NULL
)
641 xfree (b
->cond_string
);
645 b
->cond_string
= NULL
;
647 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
652 /* I don't know if it matters whether this is the string the user
653 typed in or the decompiled expression. */
654 b
->cond_string
= xstrdup (arg
);
655 b
->condition_not_parsed
= 0;
656 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
660 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
662 error (_("Junk at end of expression"));
665 breakpoints_changed ();
666 observer_notify_breakpoint_modified (b
->number
);
670 error (_("No breakpoint number %d."), bnum
);
673 /* Set the command list of B to COMMANDS. */
676 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
678 free_command_lines (&b
->commands
);
679 b
->commands
= commands
;
680 breakpoints_changed ();
681 observer_notify_breakpoint_modified (b
->number
);
685 commands_command (char *arg
, int from_tty
)
687 struct breakpoint
*b
;
690 struct command_line
*l
;
692 /* If we allowed this, we would have problems with when to
693 free the storage, if we change the commands currently
696 if (executing_breakpoint_commands
)
697 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
700 bnum
= get_number (&p
);
703 error (_("Unexpected extra arguments following breakpoint number."));
706 if (b
->number
== bnum
)
708 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
710 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
711 l
= read_command_lines (tmpbuf
, from_tty
, 1);
712 do_cleanups (cleanups
);
713 breakpoint_set_commands (b
, l
);
716 error (_("No breakpoint number %d."), bnum
);
719 /* Like commands_command, but instead of reading the commands from
720 input stream, takes them from an already parsed command structure.
722 This is used by cli-script.c to DTRT with breakpoint commands
723 that are part of if and while bodies. */
724 enum command_control_type
725 commands_from_control_command (char *arg
, struct command_line
*cmd
)
727 struct breakpoint
*b
;
731 /* If we allowed this, we would have problems with when to
732 free the storage, if we change the commands currently
735 if (executing_breakpoint_commands
)
736 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
738 /* An empty string for the breakpoint number means the last
739 breakpoint, but get_number expects a NULL pointer. */
744 bnum
= get_number (&p
);
747 error (_("Unexpected extra arguments following breakpoint number."));
750 if (b
->number
== bnum
)
752 free_command_lines (&b
->commands
);
753 if (cmd
->body_count
!= 1)
754 error (_("Invalid \"commands\" block structure."));
755 /* We need to copy the commands because if/while will free the
756 list after it finishes execution. */
757 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
758 breakpoints_changed ();
759 observer_notify_breakpoint_modified (b
->number
);
760 return simple_control
;
762 error (_("No breakpoint number %d."), bnum
);
765 /* Return non-zero if BL->TARGET_INFO contains valid information. */
768 bp_location_has_shadow (struct bp_location
*bl
)
770 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
774 if (bl
->target_info
.shadow_len
== 0)
775 /* bp isn't valid, or doesn't shadow memory. */
780 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
781 by replacing any memory breakpoints with their shadowed contents.
783 The range of shadowed area by each bp_location is:
784 b->address - bp_location_placed_address_before_address_max
785 up to b->address + bp_location_shadow_len_after_address_max
786 The range we were requested to resolve shadows for is:
787 memaddr ... memaddr + len
788 Thus the safe cutoff boundaries for performance optimization are
789 memaddr + len <= b->address - bp_location_placed_address_before_address_max
791 b->address + bp_location_shadow_len_after_address_max <= memaddr */
794 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
796 /* Left boundary, right boundary and median element of our binary search. */
797 unsigned bc_l
, bc_r
, bc
;
799 /* Find BC_L which is a leftmost element which may affect BUF content. It is
800 safe to report lower value but a failure to report higher one. */
803 bc_r
= bp_location_count
;
804 while (bc_l
+ 1 < bc_r
)
806 struct bp_location
*b
;
808 bc
= (bc_l
+ bc_r
) / 2;
811 /* Check first B->ADDRESS will not overflow due to the added constant.
812 Then advance the left boundary only if we are sure the BC element can
813 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
815 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
816 we cannot miss a breakpoint with its shadow range tail still reaching
819 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
820 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
826 /* Now do full processing of the found relevant range of elements. */
828 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
830 struct bp_location
*b
= bp_location
[bc
];
831 CORE_ADDR bp_addr
= 0;
835 if (b
->owner
->type
== bp_none
)
836 warning (_("reading through apparently deleted breakpoint #%d?"),
839 /* Performance optimization: any futher element can no longer affect BUF
842 if (b
->address
>= bp_location_placed_address_before_address_max
843 && memaddr
+ len
<= b
->address
844 - bp_location_placed_address_before_address_max
)
847 if (!bp_location_has_shadow (b
))
849 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
850 current_program_space
->aspace
, 0))
853 /* Addresses and length of the part of the breakpoint that
855 bp_addr
= b
->target_info
.placed_address
;
856 bp_size
= b
->target_info
.shadow_len
;
858 if (bp_addr
+ bp_size
<= memaddr
)
859 /* The breakpoint is entirely before the chunk of memory we
863 if (bp_addr
>= memaddr
+ len
)
864 /* The breakpoint is entirely after the chunk of memory we are
868 /* Offset within shadow_contents. */
869 if (bp_addr
< memaddr
)
871 /* Only copy the second part of the breakpoint. */
872 bp_size
-= memaddr
- bp_addr
;
873 bptoffset
= memaddr
- bp_addr
;
877 if (bp_addr
+ bp_size
> memaddr
+ len
)
879 /* Only copy the first part of the breakpoint. */
880 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
883 memcpy (buf
+ bp_addr
- memaddr
,
884 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
889 /* A wrapper function for inserting catchpoints. */
891 insert_catchpoint (struct ui_out
*uo
, void *args
)
893 struct breakpoint
*b
= (struct breakpoint
*) args
;
896 gdb_assert (b
->type
== bp_catchpoint
);
897 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
903 is_hardware_watchpoint (struct breakpoint
*bpt
)
905 return (bpt
->type
== bp_hardware_watchpoint
906 || bpt
->type
== bp_read_watchpoint
907 || bpt
->type
== bp_access_watchpoint
);
910 /* Find the current value of a watchpoint on EXP. Return the value in
911 *VALP and *RESULTP and the chain of intermediate and final values
912 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
915 If a memory error occurs while evaluating the expression, *RESULTP will
916 be set to NULL. *RESULTP may be a lazy value, if the result could
917 not be read from memory. It is used to determine whether a value
918 is user-specified (we should watch the whole value) or intermediate
919 (we should watch only the bit used to locate the final value).
921 If the final value, or any intermediate value, could not be read
922 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
923 set to any referenced values. *VALP will never be a lazy value.
924 This is the value which we store in struct breakpoint.
926 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
927 value chain. The caller must free the values individually. If
928 VAL_CHAIN is NULL, all generated values will be left on the value
932 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
933 struct value
**resultp
, struct value
**val_chain
)
935 struct value
*mark
, *new_mark
, *result
;
936 volatile struct gdb_exception ex
;
944 /* Evaluate the expression. */
945 mark
= value_mark ();
948 TRY_CATCH (ex
, RETURN_MASK_ALL
)
950 result
= evaluate_expression (exp
);
954 /* Ignore memory errors, we want watchpoints pointing at
955 inaccessible memory to still be created; otherwise, throw the
956 error to some higher catcher. */
962 throw_exception (ex
);
967 new_mark
= value_mark ();
968 if (mark
== new_mark
)
973 /* Make sure it's not lazy, so that after the target stops again we
974 have a non-lazy previous value to compare with. */
976 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
981 /* Return the chain of intermediate values. We use this to
982 decide which addresses to watch. */
983 *val_chain
= new_mark
;
984 value_release_to_mark (mark
);
988 /* Assuming that B is a watchpoint: returns true if the current thread
989 and its running state are safe to evaluate or update watchpoint B.
990 Watchpoints on local expressions need to be evaluated in the
991 context of the thread that was current when the watchpoint was
992 created, and, that thread needs to be stopped to be able to select
993 the correct frame context. Watchpoints on global expressions can
994 be evaluated on any thread, and in any state. It is presently left
995 to the target allowing memory accesses when threads are
999 watchpoint_in_thread_scope (struct breakpoint
*b
)
1001 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1002 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1003 && !is_executing (inferior_ptid
)));
1006 /* Assuming that B is a watchpoint:
1007 - Reparse watchpoint expression, if REPARSE is non-zero
1008 - Evaluate expression and store the result in B->val
1009 - Evaluate the condition if there is one, and store the result
1011 - Update the list of values that must be watched in B->loc.
1013 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1014 If this is local watchpoint that is out of scope, delete it.
1016 Even with `set breakpoint always-inserted on' the watchpoints are removed
1017 + inserted on each stop here. Normal breakpoints must never be removed
1018 because they might be missed by a running thread when debugging in non-stop
1019 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1020 processed here) are specific to each LWP since they are stored in each LWP's
1021 hardware debug registers. Therefore, such LWP must be stopped first in
1022 order to be able to modify its hardware watchpoints.
1024 Hardware watchpoints must be reset exactly once after being presented to the
1025 user. It cannot be done sooner, because it would reset the data used to
1026 present the watchpoint hit to the user. And it must not be done later
1027 because it could display the same single watchpoint hit during multiple GDB
1028 stops. Note that the latter is relevant only to the hardware watchpoint
1029 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1030 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1031 memory content has not changed.
1033 The following constraints influence the location where we can reset hardware
1036 * target_stopped_by_watchpoint and target_stopped_data_address are called
1037 several times when GDB stops.
1040 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1041 stop. GDB only presents one hardware watchpoint hit at a time as the
1042 reason for stopping, and all the other hits are presented later, one after
1043 the other, each time the user requests the execution to be resumed.
1044 Execution is not resumed for the threads still having pending hit event
1045 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1046 the inferior on the first stop the thread hit event is kept being reported
1047 from its cached value by linux_nat_stopped_data_address until the real
1048 thread resume happens after the watchpoint gets presented and thus its
1049 LWP_INFO->STATUS gets reset.
1051 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1052 removal from inferior. */
1055 update_watchpoint (struct breakpoint
*b
, int reparse
)
1057 int within_current_scope
;
1058 struct frame_id saved_frame_id
;
1059 struct bp_location
*loc
;
1063 /* If this is a local watchpoint, we only want to check if the
1064 watchpoint frame is in scope if the current thread is the thread
1065 that was used to create the watchpoint. */
1066 if (!watchpoint_in_thread_scope (b
))
1069 /* We don't free locations. They are stored in bp_location array and
1070 update_global_locations will eventually delete them and remove
1071 breakpoints if needed. */
1074 if (b
->disposition
== disp_del_at_next_stop
)
1079 /* Determine if the watchpoint is within scope. */
1080 if (b
->exp_valid_block
== NULL
)
1081 within_current_scope
= 1;
1084 struct frame_info
*fi
;
1086 /* Save the current frame's ID so we can restore it after
1087 evaluating the watchpoint expression on its own frame. */
1088 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1089 took a frame parameter, so that we didn't have to change the
1092 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1094 fi
= frame_find_by_id (b
->watchpoint_frame
);
1095 within_current_scope
= (fi
!= NULL
);
1096 if (within_current_scope
)
1100 if (within_current_scope
&& reparse
)
1109 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1110 /* If the meaning of expression itself changed, the old value is
1111 no longer relevant. We don't want to report a watchpoint hit
1112 to the user when the old value and the new value may actually
1113 be completely different objects. */
1114 value_free (b
->val
);
1119 /* If we failed to parse the expression, for example because
1120 it refers to a global variable in a not-yet-loaded shared library,
1121 don't try to insert watchpoint. We don't automatically delete
1122 such watchpoint, though, since failure to parse expression
1123 is different from out-of-scope watchpoint. */
1124 if ( !target_has_execution
)
1126 /* Without execution, memory can't change. No use to try and
1127 set watchpoint locations. The watchpoint will be reset when
1128 the target gains execution, through breakpoint_re_set. */
1130 else if (within_current_scope
&& b
->exp
)
1132 struct value
*val_chain
, *v
, *result
, *next
;
1133 struct program_space
*frame_pspace
;
1135 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1137 /* Avoid setting b->val if it's already set. The meaning of
1138 b->val is 'the last value' user saw, and we should update
1139 it only if we reported that last value to user. As it
1140 happens, the code that reports it updates b->val directly. */
1147 /* Change the type of breakpoint between hardware assisted or an
1148 ordinary watchpoint depending on the hardware support and free
1149 hardware slots. REPARSE is set when the inferior is started. */
1150 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1153 int i
, mem_cnt
, other_type_used
;
1155 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1157 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1160 b
->type
= bp_watchpoint
;
1163 int target_resources_ok
= target_can_use_hardware_watchpoint
1164 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1165 if (target_resources_ok
<= 0)
1166 b
->type
= bp_watchpoint
;
1168 b
->type
= bp_hardware_watchpoint
;
1172 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1174 /* Look at each value on the value chain. */
1175 for (v
= val_chain
; v
; v
= next
)
1177 /* If it's a memory location, and GDB actually needed
1178 its contents to evaluate the expression, then we
1179 must watch it. If the first value returned is
1180 still lazy, that means an error occurred reading it;
1181 watch it anyway in case it becomes readable. */
1182 if (VALUE_LVAL (v
) == lval_memory
1183 && (v
== val_chain
|| ! value_lazy (v
)))
1185 struct type
*vtype
= check_typedef (value_type (v
));
1187 /* We only watch structs and arrays if user asked
1188 for it explicitly, never if they just happen to
1189 appear in the middle of some value chain. */
1191 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1192 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1196 struct bp_location
*loc
, **tmp
;
1198 addr
= value_address (v
);
1199 len
= TYPE_LENGTH (value_type (v
));
1201 if (b
->type
== bp_read_watchpoint
)
1203 else if (b
->type
== bp_access_watchpoint
)
1206 loc
= allocate_bp_location (b
);
1207 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1210 loc
->gdbarch
= get_type_arch (value_type (v
));
1212 loc
->pspace
= frame_pspace
;
1213 loc
->address
= addr
;
1215 loc
->watchpoint_type
= type
;
1219 next
= value_next (v
);
1224 /* We just regenerated the list of breakpoint locations.
1225 The new location does not have its condition field set to anything
1226 and therefore, we must always reparse the cond_string, independently
1227 of the value of the reparse flag. */
1228 if (b
->cond_string
!= NULL
)
1230 char *s
= b
->cond_string
;
1231 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1234 else if (!within_current_scope
)
1236 printf_filtered (_("\
1237 Watchpoint %d deleted because the program has left the block \n\
1238 in which its expression is valid.\n"),
1240 if (b
->related_breakpoint
)
1241 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1242 b
->disposition
= disp_del_at_next_stop
;
1245 /* Restore the selected frame. */
1247 select_frame (frame_find_by_id (saved_frame_id
));
1251 /* Returns 1 iff breakpoint location should be
1252 inserted in the inferior. */
1254 should_be_inserted (struct bp_location
*bpt
)
1256 if (!breakpoint_enabled (bpt
->owner
))
1259 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1262 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1265 /* This is set for example, when we're attached to the parent of a
1266 vfork, and have detached from the child. The child is running
1267 free, and we expect it to do an exec or exit, at which point the
1268 OS makes the parent schedulable again (and the target reports
1269 that the vfork is done). Until the child is done with the shared
1270 memory region, do not insert breakpoints in the parent, otherwise
1271 the child could still trip on the parent's breakpoints. Since
1272 the parent is blocked anyway, it won't miss any breakpoint. */
1273 if (bpt
->pspace
->breakpoints_not_allowed
)
1276 /* Tracepoints are inserted by the target at a time of its choosing,
1278 if (bpt
->owner
->type
== bp_tracepoint
)
1284 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1285 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1286 and HW_BREAKPOINT_ERROR are used to report problems.
1288 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1289 method for each breakpoint or catchpoint type. */
1291 insert_bp_location (struct bp_location
*bpt
,
1292 struct ui_file
*tmp_error_stream
,
1293 int *disabled_breaks
,
1294 int *hw_breakpoint_error
)
1298 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1301 /* Initialize the target-specific information. */
1302 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1303 bpt
->target_info
.placed_address
= bpt
->address
;
1304 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1306 if (bpt
->loc_type
== bp_loc_software_breakpoint
1307 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1309 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1311 /* If the explicitly specified breakpoint type
1312 is not hardware breakpoint, check the memory map to see
1313 if the breakpoint address is in read only memory or not.
1314 Two important cases are:
1315 - location type is not hardware breakpoint, memory
1316 is readonly. We change the type of the location to
1317 hardware breakpoint.
1318 - location type is hardware breakpoint, memory is read-write.
1319 This means we've previously made the location hardware one, but
1320 then the memory map changed, so we undo.
1322 When breakpoints are removed, remove_breakpoints will
1323 use location types we've just set here, the only possible
1324 problem is that memory map has changed during running program,
1325 but it's not going to work anyway with current gdb. */
1326 struct mem_region
*mr
1327 = lookup_mem_region (bpt
->target_info
.placed_address
);
1331 if (automatic_hardware_breakpoints
)
1334 enum bp_loc_type new_type
;
1336 if (mr
->attrib
.mode
!= MEM_RW
)
1337 new_type
= bp_loc_hardware_breakpoint
;
1339 new_type
= bp_loc_software_breakpoint
;
1341 if (new_type
!= bpt
->loc_type
)
1343 static int said
= 0;
1344 bpt
->loc_type
= new_type
;
1347 fprintf_filtered (gdb_stdout
, _("\
1348 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1353 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1354 && mr
->attrib
.mode
!= MEM_RW
)
1355 warning (_("cannot set software breakpoint at readonly address %s"),
1356 paddress (bpt
->gdbarch
, bpt
->address
));
1360 /* First check to see if we have to handle an overlay. */
1361 if (overlay_debugging
== ovly_off
1362 || bpt
->section
== NULL
1363 || !(section_is_overlay (bpt
->section
)))
1365 /* No overlay handling: just set the breakpoint. */
1367 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1368 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1371 val
= target_insert_breakpoint (bpt
->gdbarch
,
1376 /* This breakpoint is in an overlay section.
1377 Shall we set a breakpoint at the LMA? */
1378 if (!overlay_events_enabled
)
1380 /* Yes -- overlay event support is not active,
1381 so we must try to set a breakpoint at the LMA.
1382 This will not work for a hardware breakpoint. */
1383 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1384 warning (_("hardware breakpoint %d not supported in overlay!"),
1385 bpt
->owner
->number
);
1388 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1390 /* Set a software (trap) breakpoint at the LMA. */
1391 bpt
->overlay_target_info
= bpt
->target_info
;
1392 bpt
->overlay_target_info
.placed_address
= addr
;
1393 val
= target_insert_breakpoint (bpt
->gdbarch
,
1394 &bpt
->overlay_target_info
);
1396 fprintf_unfiltered (tmp_error_stream
,
1397 "Overlay breakpoint %d failed: in ROM?\n",
1398 bpt
->owner
->number
);
1401 /* Shall we set a breakpoint at the VMA? */
1402 if (section_is_mapped (bpt
->section
))
1404 /* Yes. This overlay section is mapped into memory. */
1405 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1406 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1409 val
= target_insert_breakpoint (bpt
->gdbarch
,
1414 /* No. This breakpoint will not be inserted.
1415 No error, but do not mark the bp as 'inserted'. */
1422 /* Can't set the breakpoint. */
1423 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1425 /* See also: disable_breakpoints_in_shlibs. */
1427 bpt
->shlib_disabled
= 1;
1428 if (!*disabled_breaks
)
1430 fprintf_unfiltered (tmp_error_stream
,
1431 "Cannot insert breakpoint %d.\n",
1432 bpt
->owner
->number
);
1433 fprintf_unfiltered (tmp_error_stream
,
1434 "Temporarily disabling shared library breakpoints:\n");
1436 *disabled_breaks
= 1;
1437 fprintf_unfiltered (tmp_error_stream
,
1438 "breakpoint #%d\n", bpt
->owner
->number
);
1442 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1444 *hw_breakpoint_error
= 1;
1445 fprintf_unfiltered (tmp_error_stream
,
1446 "Cannot insert hardware breakpoint %d.\n",
1447 bpt
->owner
->number
);
1451 fprintf_unfiltered (tmp_error_stream
,
1452 "Cannot insert breakpoint %d.\n",
1453 bpt
->owner
->number
);
1454 fprintf_filtered (tmp_error_stream
,
1455 "Error accessing memory address ");
1456 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1458 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1459 safe_strerror (val
));
1470 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1471 /* NOTE drow/2003-09-08: This state only exists for removing
1472 watchpoints. It's not clear that it's necessary... */
1473 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1475 val
= target_insert_watchpoint (bpt
->address
,
1477 bpt
->watchpoint_type
);
1478 bpt
->inserted
= (val
!= -1);
1481 else if (bpt
->owner
->type
== bp_catchpoint
)
1483 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1484 bpt
->owner
, RETURN_MASK_ERROR
);
1485 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1486 bpt
->owner
->number
);
1488 bpt
->owner
->enable_state
= bp_disabled
;
1492 /* We've already printed an error message if there was a problem
1493 inserting this catchpoint, and we've disabled the catchpoint,
1494 so just return success. */
1501 /* This function is called when program space PSPACE is about to be
1502 deleted. It takes care of updating breakpoints to not reference
1506 breakpoint_program_space_exit (struct program_space
*pspace
)
1508 struct breakpoint
*b
, *b_temp
;
1509 struct bp_location
*loc
, **loc_temp
;
1511 /* Remove any breakpoint that was set through this program space. */
1512 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1514 if (b
->pspace
== pspace
)
1515 delete_breakpoint (b
);
1518 /* Breakpoints set through other program spaces could have locations
1519 bound to PSPACE as well. Remove those. */
1520 ALL_BP_LOCATIONS (loc
, loc_temp
)
1522 struct bp_location
*tmp
;
1524 if (loc
->pspace
== pspace
)
1526 if (loc
->owner
->loc
== loc
)
1527 loc
->owner
->loc
= loc
->next
;
1529 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1530 if (tmp
->next
== loc
)
1532 tmp
->next
= loc
->next
;
1538 /* Now update the global location list to permanently delete the
1539 removed locations above. */
1540 update_global_location_list (0);
1543 /* Make sure all breakpoints are inserted in inferior.
1544 Throws exception on any error.
1545 A breakpoint that is already inserted won't be inserted
1546 again, so calling this function twice is safe. */
1548 insert_breakpoints (void)
1550 struct breakpoint
*bpt
;
1552 ALL_BREAKPOINTS (bpt
)
1553 if (is_hardware_watchpoint (bpt
))
1554 update_watchpoint (bpt
, 0 /* don't reparse. */);
1556 update_global_location_list (1);
1558 /* update_global_location_list does not insert breakpoints when
1559 always_inserted_mode is not enabled. Explicitly insert them
1561 if (!breakpoints_always_inserted_mode ())
1562 insert_breakpoint_locations ();
1565 /* insert_breakpoints is used when starting or continuing the program.
1566 remove_breakpoints is used when the program stops.
1567 Both return zero if successful,
1568 or an `errno' value if could not write the inferior. */
1571 insert_breakpoint_locations (void)
1573 struct breakpoint
*bpt
;
1574 struct bp_location
*b
, **bp_tmp
;
1577 int disabled_breaks
= 0;
1578 int hw_breakpoint_error
= 0;
1580 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1581 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1583 /* Explicitly mark the warning -- this will only be printed if
1584 there was an error. */
1585 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1587 save_current_space_and_thread ();
1589 ALL_BP_LOCATIONS (b
, bp_tmp
)
1591 struct thread_info
*tp
;
1592 CORE_ADDR last_addr
;
1594 if (!should_be_inserted (b
) || b
->inserted
)
1597 /* There is no point inserting thread-specific breakpoints if the
1598 thread no longer exists. */
1599 if (b
->owner
->thread
!= -1
1600 && !valid_thread_id (b
->owner
->thread
))
1603 switch_to_program_space_and_thread (b
->pspace
);
1605 /* For targets that support global breakpoints, there's no need
1606 to select an inferior to insert breakpoint to. In fact, even
1607 if we aren't attached to any process yet, we should still
1608 insert breakpoints. */
1609 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1610 && ptid_equal (inferior_ptid
, null_ptid
))
1613 val
= insert_bp_location (b
, tmp_error_stream
,
1615 &hw_breakpoint_error
);
1620 /* If we failed to insert all locations of a watchpoint,
1621 remove them, as half-inserted watchpoint is of limited use. */
1622 ALL_BREAKPOINTS (bpt
)
1624 int some_failed
= 0;
1625 struct bp_location
*loc
;
1627 if (!is_hardware_watchpoint (bpt
))
1630 if (!breakpoint_enabled (bpt
))
1633 if (bpt
->disposition
== disp_del_at_next_stop
)
1636 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1637 if (!loc
->inserted
&& should_be_inserted (loc
))
1644 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1646 remove_breakpoint (loc
, mark_uninserted
);
1648 hw_breakpoint_error
= 1;
1649 fprintf_unfiltered (tmp_error_stream
,
1650 "Could not insert hardware watchpoint %d.\n",
1658 /* If a hardware breakpoint or watchpoint was inserted, add a
1659 message about possibly exhausted resources. */
1660 if (hw_breakpoint_error
)
1662 fprintf_unfiltered (tmp_error_stream
,
1663 "Could not insert hardware breakpoints:\n\
1664 You may have requested too many hardware breakpoints/watchpoints.\n");
1666 target_terminal_ours_for_output ();
1667 error_stream (tmp_error_stream
);
1670 do_cleanups (cleanups
);
1674 remove_breakpoints (void)
1676 struct bp_location
*b
, **bp_tmp
;
1679 ALL_BP_LOCATIONS (b
, bp_tmp
)
1682 val
|= remove_breakpoint (b
, mark_uninserted
);
1687 /* Remove breakpoints of process PID. */
1690 remove_breakpoints_pid (int pid
)
1692 struct bp_location
*b
, **b_tmp
;
1694 struct inferior
*inf
= find_inferior_pid (pid
);
1696 ALL_BP_LOCATIONS (b
, b_tmp
)
1698 if (b
->pspace
!= inf
->pspace
)
1703 val
= remove_breakpoint (b
, mark_uninserted
);
1712 remove_hw_watchpoints (void)
1714 struct bp_location
*b
, **bp_tmp
;
1717 ALL_BP_LOCATIONS (b
, bp_tmp
)
1719 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1720 val
|= remove_breakpoint (b
, mark_uninserted
);
1726 reattach_breakpoints (int pid
)
1728 struct cleanup
*old_chain
;
1729 struct bp_location
*b
, **bp_tmp
;
1731 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1732 int dummy1
= 0, dummy2
= 0;
1733 struct inferior
*inf
;
1734 struct thread_info
*tp
;
1736 tp
= any_live_thread_of_process (pid
);
1740 inf
= find_inferior_pid (pid
);
1741 old_chain
= save_inferior_ptid ();
1743 inferior_ptid
= tp
->ptid
;
1745 make_cleanup_ui_file_delete (tmp_error_stream
);
1747 ALL_BP_LOCATIONS (b
, bp_tmp
)
1749 if (b
->pspace
!= inf
->pspace
)
1755 val
= insert_bp_location (b
, tmp_error_stream
,
1759 do_cleanups (old_chain
);
1764 do_cleanups (old_chain
);
1768 static int internal_breakpoint_number
= -1;
1770 static struct breakpoint
*
1771 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1772 CORE_ADDR address
, enum bptype type
)
1774 struct symtab_and_line sal
;
1775 struct breakpoint
*b
;
1777 init_sal (&sal
); /* initialize to zeroes */
1780 sal
.section
= find_pc_overlay (sal
.pc
);
1781 sal
.pspace
= current_program_space
;
1783 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1784 b
->number
= internal_breakpoint_number
--;
1785 b
->disposition
= disp_donttouch
;
1791 create_overlay_event_breakpoint (char *func_name
)
1793 struct objfile
*objfile
;
1795 ALL_OBJFILES (objfile
)
1797 struct breakpoint
*b
;
1798 struct minimal_symbol
*m
;
1800 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1804 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1805 SYMBOL_VALUE_ADDRESS (m
),
1807 b
->addr_string
= xstrdup (func_name
);
1809 if (overlay_debugging
== ovly_auto
)
1811 b
->enable_state
= bp_enabled
;
1812 overlay_events_enabled
= 1;
1816 b
->enable_state
= bp_disabled
;
1817 overlay_events_enabled
= 0;
1820 update_global_location_list (1);
1824 create_longjmp_master_breakpoint (char *func_name
)
1826 struct program_space
*pspace
;
1827 struct objfile
*objfile
;
1828 struct cleanup
*old_chain
;
1830 old_chain
= save_current_program_space ();
1832 ALL_PSPACES (pspace
)
1833 ALL_OBJFILES (objfile
)
1835 struct breakpoint
*b
;
1836 struct minimal_symbol
*m
;
1838 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1841 set_current_program_space (pspace
);
1843 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1847 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1848 SYMBOL_VALUE_ADDRESS (m
),
1850 b
->addr_string
= xstrdup (func_name
);
1851 b
->enable_state
= bp_disabled
;
1853 update_global_location_list (1);
1855 do_cleanups (old_chain
);
1859 update_breakpoints_after_exec (void)
1861 struct breakpoint
*b
;
1862 struct breakpoint
*temp
;
1863 struct bp_location
*bploc
, **bplocp_tmp
;
1865 /* We're about to delete breakpoints from GDB's lists. If the
1866 INSERTED flag is true, GDB will try to lift the breakpoints by
1867 writing the breakpoints' "shadow contents" back into memory. The
1868 "shadow contents" are NOT valid after an exec, so GDB should not
1869 do that. Instead, the target is responsible from marking
1870 breakpoints out as soon as it detects an exec. We don't do that
1871 here instead, because there may be other attempts to delete
1872 breakpoints after detecting an exec and before reaching here. */
1873 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
1874 if (bploc
->pspace
== current_program_space
)
1875 gdb_assert (!bploc
->inserted
);
1877 ALL_BREAKPOINTS_SAFE (b
, temp
)
1879 if (b
->pspace
!= current_program_space
)
1882 /* Solib breakpoints must be explicitly reset after an exec(). */
1883 if (b
->type
== bp_shlib_event
)
1885 delete_breakpoint (b
);
1889 /* JIT breakpoints must be explicitly reset after an exec(). */
1890 if (b
->type
== bp_jit_event
)
1892 delete_breakpoint (b
);
1896 /* Thread event breakpoints must be set anew after an exec(),
1897 as must overlay event and longjmp master breakpoints. */
1898 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1899 || b
->type
== bp_longjmp_master
)
1901 delete_breakpoint (b
);
1905 /* Step-resume breakpoints are meaningless after an exec(). */
1906 if (b
->type
== bp_step_resume
)
1908 delete_breakpoint (b
);
1912 /* Longjmp and longjmp-resume breakpoints are also meaningless
1914 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1916 delete_breakpoint (b
);
1920 if (b
->type
== bp_catchpoint
)
1922 /* For now, none of the bp_catchpoint breakpoints need to
1923 do anything at this point. In the future, if some of
1924 the catchpoints need to something, we will need to add
1925 a new method, and call this method from here. */
1929 /* bp_finish is a special case. The only way we ought to be able
1930 to see one of these when an exec() has happened, is if the user
1931 caught a vfork, and then said "finish". Ordinarily a finish just
1932 carries them to the call-site of the current callee, by setting
1933 a temporary bp there and resuming. But in this case, the finish
1934 will carry them entirely through the vfork & exec.
1936 We don't want to allow a bp_finish to remain inserted now. But
1937 we can't safely delete it, 'cause finish_command has a handle to
1938 the bp on a bpstat, and will later want to delete it. There's a
1939 chance (and I've seen it happen) that if we delete the bp_finish
1940 here, that its storage will get reused by the time finish_command
1941 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1942 We really must allow finish_command to delete a bp_finish.
1944 In the absense of a general solution for the "how do we know
1945 it's safe to delete something others may have handles to?"
1946 problem, what we'll do here is just uninsert the bp_finish, and
1947 let finish_command delete it.
1949 (We know the bp_finish is "doomed" in the sense that it's
1950 momentary, and will be deleted as soon as finish_command sees
1951 the inferior stopped. So it doesn't matter that the bp's
1952 address is probably bogus in the new a.out, unlike e.g., the
1953 solib breakpoints.) */
1955 if (b
->type
== bp_finish
)
1960 /* Without a symbolic address, we have little hope of the
1961 pre-exec() address meaning the same thing in the post-exec()
1963 if (b
->addr_string
== NULL
)
1965 delete_breakpoint (b
);
1969 /* FIXME what about longjmp breakpoints? Re-create them here? */
1970 create_overlay_event_breakpoint ("_ovly_debug_event");
1971 create_longjmp_master_breakpoint ("longjmp");
1972 create_longjmp_master_breakpoint ("_longjmp");
1973 create_longjmp_master_breakpoint ("siglongjmp");
1974 create_longjmp_master_breakpoint ("_siglongjmp");
1978 detach_breakpoints (int pid
)
1980 struct bp_location
*b
, **bp_tmp
;
1982 struct cleanup
*old_chain
= save_inferior_ptid ();
1983 struct inferior
*inf
= current_inferior ();
1985 if (pid
== PIDGET (inferior_ptid
))
1986 error (_("Cannot detach breakpoints of inferior_ptid"));
1988 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
1989 inferior_ptid
= pid_to_ptid (pid
);
1990 ALL_BP_LOCATIONS (b
, bp_tmp
)
1992 if (b
->pspace
!= inf
->pspace
)
1996 val
|= remove_breakpoint_1 (b
, mark_inserted
);
1998 do_cleanups (old_chain
);
2002 /* Remove the breakpoint location B from the current address space.
2003 Note that this is used to detach breakpoints from a child fork.
2004 When we get here, the child isn't in the inferior list, and neither
2005 do we have objects to represent its address space --- we should
2006 *not* look at b->pspace->aspace here. */
2009 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2012 struct cleanup
*old_chain
;
2014 if (b
->owner
->enable_state
== bp_permanent
)
2015 /* Permanent breakpoints cannot be inserted or removed. */
2018 /* The type of none suggests that owner is actually deleted.
2019 This should not ever happen. */
2020 gdb_assert (b
->owner
->type
!= bp_none
);
2022 if (b
->loc_type
== bp_loc_software_breakpoint
2023 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2025 /* "Normal" instruction breakpoint: either the standard
2026 trap-instruction bp (bp_breakpoint), or a
2027 bp_hardware_breakpoint. */
2029 /* First check to see if we have to handle an overlay. */
2030 if (overlay_debugging
== ovly_off
2031 || b
->section
== NULL
2032 || !(section_is_overlay (b
->section
)))
2034 /* No overlay handling: just remove the breakpoint. */
2036 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2037 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2039 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2043 /* This breakpoint is in an overlay section.
2044 Did we set a breakpoint at the LMA? */
2045 if (!overlay_events_enabled
)
2047 /* Yes -- overlay event support is not active, so we
2048 should have set a breakpoint at the LMA. Remove it.
2050 /* Ignore any failures: if the LMA is in ROM, we will
2051 have already warned when we failed to insert it. */
2052 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2053 target_remove_hw_breakpoint (b
->gdbarch
,
2054 &b
->overlay_target_info
);
2056 target_remove_breakpoint (b
->gdbarch
,
2057 &b
->overlay_target_info
);
2059 /* Did we set a breakpoint at the VMA?
2060 If so, we will have marked the breakpoint 'inserted'. */
2063 /* Yes -- remove it. Previously we did not bother to
2064 remove the breakpoint if the section had been
2065 unmapped, but let's not rely on that being safe. We
2066 don't know what the overlay manager might do. */
2067 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2068 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2071 /* However, we should remove *software* breakpoints only
2072 if the section is still mapped, or else we overwrite
2073 wrong code with the saved shadow contents. */
2074 else if (section_is_mapped (b
->section
))
2075 val
= target_remove_breakpoint (b
->gdbarch
,
2082 /* No -- not inserted, so no need to remove. No error. */
2087 /* In some cases, we might not be able to remove a breakpoint
2088 in a shared library that has already been removed, but we
2089 have not yet processed the shlib unload event. */
2090 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2095 b
->inserted
= (is
== mark_inserted
);
2097 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2102 b
->inserted
= (is
== mark_inserted
);
2103 val
= target_remove_watchpoint (b
->address
, b
->length
,
2104 b
->watchpoint_type
);
2106 /* Failure to remove any of the hardware watchpoints comes here. */
2107 if ((is
== mark_uninserted
) && (b
->inserted
))
2108 warning (_("Could not remove hardware watchpoint %d."),
2111 else if (b
->owner
->type
== bp_catchpoint
2112 && breakpoint_enabled (b
->owner
)
2115 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2117 val
= b
->owner
->ops
->remove (b
->owner
);
2120 b
->inserted
= (is
== mark_inserted
);
2127 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2130 struct cleanup
*old_chain
;
2132 if (b
->owner
->enable_state
== bp_permanent
)
2133 /* Permanent breakpoints cannot be inserted or removed. */
2136 /* The type of none suggests that owner is actually deleted.
2137 This should not ever happen. */
2138 gdb_assert (b
->owner
->type
!= bp_none
);
2140 old_chain
= save_current_space_and_thread ();
2142 switch_to_program_space_and_thread (b
->pspace
);
2144 ret
= remove_breakpoint_1 (b
, is
);
2146 do_cleanups (old_chain
);
2150 /* Clear the "inserted" flag in all breakpoints. */
2153 mark_breakpoints_out (void)
2155 struct bp_location
*bpt
, **bptp_tmp
;
2157 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2158 if (bpt
->pspace
== current_program_space
)
2162 /* Clear the "inserted" flag in all breakpoints and delete any
2163 breakpoints which should go away between runs of the program.
2165 Plus other such housekeeping that has to be done for breakpoints
2168 Note: this function gets called at the end of a run (by
2169 generic_mourn_inferior) and when a run begins (by
2170 init_wait_for_inferior). */
2175 breakpoint_init_inferior (enum inf_context context
)
2177 struct breakpoint
*b
, *temp
;
2178 struct bp_location
*bpt
, **bptp_tmp
;
2180 struct program_space
*pspace
= current_program_space
;
2182 /* If breakpoint locations are shared across processes, then there's
2184 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2187 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2189 if (bpt
->pspace
== pspace
2190 && bpt
->owner
->enable_state
!= bp_permanent
)
2194 ALL_BREAKPOINTS_SAFE (b
, temp
)
2196 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2202 case bp_watchpoint_scope
:
2204 /* If the call dummy breakpoint is at the entry point it will
2205 cause problems when the inferior is rerun, so we better
2208 Also get rid of scope breakpoints. */
2209 delete_breakpoint (b
);
2213 case bp_hardware_watchpoint
:
2214 case bp_read_watchpoint
:
2215 case bp_access_watchpoint
:
2217 /* Likewise for watchpoints on local expressions. */
2218 if (b
->exp_valid_block
!= NULL
)
2219 delete_breakpoint (b
);
2220 else if (context
== inf_starting
)
2222 /* Reset val field to force reread of starting value
2223 in insert_breakpoints. */
2225 value_free (b
->val
);
2235 /* Get rid of the moribund locations. */
2236 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2237 free_bp_location (bpt
);
2238 VEC_free (bp_location_p
, moribund_locations
);
2241 /* These functions concern about actual breakpoints inserted in the
2242 target --- to e.g. check if we need to do decr_pc adjustment or if
2243 we need to hop over the bkpt --- so we check for address space
2244 match, not program space. */
2246 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2247 exists at PC. It returns ordinary_breakpoint_here if it's an
2248 ordinary breakpoint, or permanent_breakpoint_here if it's a
2249 permanent breakpoint.
2250 - When continuing from a location with an ordinary breakpoint, we
2251 actually single step once before calling insert_breakpoints.
2252 - When continuing from a localion with a permanent breakpoint, we
2253 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2254 the target, to advance the PC past the breakpoint. */
2256 enum breakpoint_here
2257 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2259 struct bp_location
*bpt
, **bptp_tmp
;
2260 int any_breakpoint_here
= 0;
2262 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2264 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2265 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2268 if ((breakpoint_enabled (bpt
->owner
)
2269 || bpt
->owner
->enable_state
== bp_permanent
)
2270 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2273 if (overlay_debugging
2274 && section_is_overlay (bpt
->section
)
2275 && !section_is_mapped (bpt
->section
))
2276 continue; /* unmapped overlay -- can't be a match */
2277 else if (bpt
->owner
->enable_state
== bp_permanent
)
2278 return permanent_breakpoint_here
;
2280 any_breakpoint_here
= 1;
2284 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2287 /* Return true if there's a moribund breakpoint at PC. */
2290 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2292 struct bp_location
*loc
;
2295 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2296 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2303 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2304 inserted using regular breakpoint_chain / bp_location array mechanism.
2305 This does not check for single-step breakpoints, which are
2306 inserted and removed using direct target manipulation. */
2309 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2311 struct bp_location
*bpt
, **bptp_tmp
;
2313 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2315 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2316 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2320 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2323 if (overlay_debugging
2324 && section_is_overlay (bpt
->section
)
2325 && !section_is_mapped (bpt
->section
))
2326 continue; /* unmapped overlay -- can't be a match */
2334 /* Returns non-zero iff there's either regular breakpoint
2335 or a single step breakpoint inserted at PC. */
2338 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2340 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2343 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2349 /* This function returns non-zero iff there is a software breakpoint
2353 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2355 struct bp_location
*bpt
, **bptp_tmp
;
2356 int any_breakpoint_here
= 0;
2358 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2360 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2364 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2367 if (overlay_debugging
2368 && section_is_overlay (bpt
->section
)
2369 && !section_is_mapped (bpt
->section
))
2370 continue; /* unmapped overlay -- can't be a match */
2376 /* Also check for software single-step breakpoints. */
2377 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2384 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2385 CORE_ADDR addr
, ULONGEST len
)
2387 struct breakpoint
*bpt
;
2389 ALL_BREAKPOINTS (bpt
)
2391 struct bp_location
*loc
;
2393 if (bpt
->type
!= bp_hardware_watchpoint
2394 && bpt
->type
!= bp_access_watchpoint
)
2397 if (!breakpoint_enabled (bpt
))
2400 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2401 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2405 /* Check for intersection. */
2406 l
= max (loc
->address
, addr
);
2407 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2415 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2416 PC is valid for process/thread PTID. */
2419 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2422 struct bp_location
*bpt
, **bptp_tmp
;
2423 /* The thread and task IDs associated to PTID, computed lazily. */
2427 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2429 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2430 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2433 if (!breakpoint_enabled (bpt
->owner
)
2434 && bpt
->owner
->enable_state
!= bp_permanent
)
2437 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2441 if (bpt
->owner
->thread
!= -1)
2443 /* This is a thread-specific breakpoint. Check that ptid
2444 matches that thread. If thread hasn't been computed yet,
2445 it is now time to do so. */
2447 thread
= pid_to_thread_id (ptid
);
2448 if (bpt
->owner
->thread
!= thread
)
2452 if (bpt
->owner
->task
!= 0)
2454 /* This is a task-specific breakpoint. Check that ptid
2455 matches that task. If task hasn't been computed yet,
2456 it is now time to do so. */
2458 task
= ada_get_task_number (ptid
);
2459 if (bpt
->owner
->task
!= task
)
2463 if (overlay_debugging
2464 && section_is_overlay (bpt
->section
)
2465 && !section_is_mapped (bpt
->section
))
2466 continue; /* unmapped overlay -- can't be a match */
2475 /* bpstat stuff. External routines' interfaces are documented
2479 ep_is_catchpoint (struct breakpoint
*ep
)
2481 return (ep
->type
== bp_catchpoint
);
2485 bpstat_free (bpstat bs
)
2487 if (bs
->old_val
!= NULL
)
2488 value_free (bs
->old_val
);
2489 free_command_lines (&bs
->commands
);
2493 /* Clear a bpstat so that it says we are not at any breakpoint.
2494 Also free any storage that is part of a bpstat. */
2497 bpstat_clear (bpstat
*bsp
)
2514 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2515 is part of the bpstat is copied as well. */
2518 bpstat_copy (bpstat bs
)
2522 bpstat retval
= NULL
;
2527 for (; bs
!= NULL
; bs
= bs
->next
)
2529 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2530 memcpy (tmp
, bs
, sizeof (*tmp
));
2531 if (bs
->commands
!= NULL
)
2532 tmp
->commands
= copy_command_lines (bs
->commands
);
2533 if (bs
->old_val
!= NULL
)
2535 tmp
->old_val
= value_copy (bs
->old_val
);
2536 release_value (tmp
->old_val
);
2540 /* This is the first thing in the chain. */
2550 /* Find the bpstat associated with this breakpoint */
2553 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2558 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2560 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2566 /* Find a step_resume breakpoint associated with this bpstat.
2567 (If there are multiple step_resume bp's on the list, this function
2568 will arbitrarily pick one.)
2570 It is an error to use this function if BPSTAT doesn't contain a
2571 step_resume breakpoint.
2573 See wait_for_inferior's use of this function. */
2575 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2579 gdb_assert (bsp
!= NULL
);
2581 current_thread
= pid_to_thread_id (inferior_ptid
);
2583 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2585 if ((bsp
->breakpoint_at
!= NULL
)
2586 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2587 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2588 || bsp
->breakpoint_at
->owner
->thread
== -1))
2589 return bsp
->breakpoint_at
->owner
;
2592 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2596 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2597 at. *BSP upon return is a bpstat which points to the remaining
2598 breakpoints stopped at (but which is not guaranteed to be good for
2599 anything but further calls to bpstat_num).
2600 Return 0 if passed a bpstat which does not indicate any breakpoints.
2601 Return -1 if stopped at a breakpoint that has been deleted since
2603 Return 1 otherwise. */
2606 bpstat_num (bpstat
*bsp
, int *num
)
2608 struct breakpoint
*b
;
2611 return 0; /* No more breakpoint values */
2613 /* We assume we'll never have several bpstats that
2614 correspond to a single breakpoint -- otherwise,
2615 this function might return the same number more
2616 than once and this will look ugly. */
2617 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2618 *bsp
= (*bsp
)->next
;
2620 return -1; /* breakpoint that's been deleted since */
2622 *num
= b
->number
; /* We have its number */
2626 /* Modify BS so that the actions will not be performed. */
2629 bpstat_clear_actions (bpstat bs
)
2631 for (; bs
!= NULL
; bs
= bs
->next
)
2633 free_command_lines (&bs
->commands
);
2634 if (bs
->old_val
!= NULL
)
2636 value_free (bs
->old_val
);
2642 /* Called when a command is about to proceed the inferior. */
2645 breakpoint_about_to_proceed (void)
2647 if (!ptid_equal (inferior_ptid
, null_ptid
))
2649 struct thread_info
*tp
= inferior_thread ();
2651 /* Allow inferior function calls in breakpoint commands to not
2652 interrupt the command list. When the call finishes
2653 successfully, the inferior will be standing at the same
2654 breakpoint as if nothing happened. */
2659 breakpoint_proceeded
= 1;
2662 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2664 cleanup_executing_breakpoints (void *ignore
)
2666 executing_breakpoint_commands
= 0;
2669 /* Execute all the commands associated with all the breakpoints at this
2670 location. Any of these commands could cause the process to proceed
2671 beyond this point, etc. We look out for such changes by checking
2672 the global "breakpoint_proceeded" after each command.
2674 Returns true if a breakpoint command resumed the inferior. In that
2675 case, it is the caller's responsibility to recall it again with the
2676 bpstat of the current thread. */
2679 bpstat_do_actions_1 (bpstat
*bsp
)
2682 struct cleanup
*old_chain
;
2685 /* Avoid endless recursion if a `source' command is contained
2687 if (executing_breakpoint_commands
)
2690 executing_breakpoint_commands
= 1;
2691 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2693 /* This pointer will iterate over the list of bpstat's. */
2696 breakpoint_proceeded
= 0;
2697 for (; bs
!= NULL
; bs
= bs
->next
)
2699 struct command_line
*cmd
;
2700 struct cleanup
*this_cmd_tree_chain
;
2702 /* Take ownership of the BSP's command tree, if it has one.
2704 The command tree could legitimately contain commands like
2705 'step' and 'next', which call clear_proceed_status, which
2706 frees stop_bpstat's command tree. To make sure this doesn't
2707 free the tree we're executing out from under us, we need to
2708 take ownership of the tree ourselves. Since a given bpstat's
2709 commands are only executed once, we don't need to copy it; we
2710 can clear the pointer in the bpstat, and make sure we free
2711 the tree when we're done. */
2714 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2718 execute_control_command (cmd
);
2720 if (breakpoint_proceeded
)
2726 /* We can free this command tree now. */
2727 do_cleanups (this_cmd_tree_chain
);
2729 if (breakpoint_proceeded
)
2731 if (target_can_async_p ())
2732 /* If we are in async mode, then the target might be still
2733 running, not stopped at any breakpoint, so nothing for
2734 us to do here -- just return to the event loop. */
2737 /* In sync mode, when execute_control_command returns
2738 we're already standing on the next breakpoint.
2739 Breakpoint commands for that stop were not run, since
2740 execute_command does not run breakpoint commands --
2741 only command_line_handler does, but that one is not
2742 involved in execution of breakpoint commands. So, we
2743 can now execute breakpoint commands. It should be
2744 noted that making execute_command do bpstat actions is
2745 not an option -- in this case we'll have recursive
2746 invocation of bpstat for each breakpoint with a
2747 command, and can easily blow up GDB stack. Instead, we
2748 return true, which will trigger the caller to recall us
2749 with the new stop_bpstat. */
2754 do_cleanups (old_chain
);
2759 bpstat_do_actions (void)
2761 /* Do any commands attached to breakpoint we are stopped at. */
2762 while (!ptid_equal (inferior_ptid
, null_ptid
)
2763 && target_has_execution
2764 && !is_exited (inferior_ptid
)
2765 && !is_executing (inferior_ptid
))
2766 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2767 and only return when it is stopped at the next breakpoint, we
2768 keep doing breakpoint actions until it returns false to
2769 indicate the inferior was not resumed. */
2770 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2774 /* Print out the (old or new) value associated with a watchpoint. */
2777 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2780 fprintf_unfiltered (stream
, _("<unreadable>"));
2783 struct value_print_options opts
;
2784 get_user_print_options (&opts
);
2785 value_print (val
, stream
, &opts
);
2789 /* This is the normal print function for a bpstat. In the future,
2790 much of this logic could (should?) be moved to bpstat_stop_status,
2791 by having it set different print_it values.
2793 Current scheme: When we stop, bpstat_print() is called. It loops
2794 through the bpstat list of things causing this stop, calling the
2795 print_bp_stop_message function on each one. The behavior of the
2796 print_bp_stop_message function depends on the print_it field of
2797 bpstat. If such field so indicates, call this function here.
2799 Return values from this routine (ultimately used by bpstat_print()
2800 and normal_stop() to decide what to do):
2801 PRINT_NOTHING: Means we already printed all we needed to print,
2802 don't print anything else.
2803 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2804 that something to be followed by a location.
2805 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2806 that something to be followed by a location.
2807 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2810 static enum print_stop_action
2811 print_it_typical (bpstat bs
)
2813 struct cleanup
*old_chain
;
2814 struct breakpoint
*b
;
2815 const struct bp_location
*bl
;
2816 struct ui_stream
*stb
;
2818 enum print_stop_action result
;
2820 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2821 which has since been deleted. */
2822 if (bs
->breakpoint_at
== NULL
)
2823 return PRINT_UNKNOWN
;
2824 bl
= bs
->breakpoint_at
;
2827 stb
= ui_out_stream_new (uiout
);
2828 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2833 case bp_hardware_breakpoint
:
2834 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2835 if (bl
->address
!= bl
->requested_address
)
2836 breakpoint_adjustment_warning (bl
->requested_address
,
2839 annotate_breakpoint (b
->number
);
2841 ui_out_text (uiout
, "\nTemporary breakpoint ");
2843 ui_out_text (uiout
, "\nBreakpoint ");
2844 if (ui_out_is_mi_like_p (uiout
))
2846 ui_out_field_string (uiout
, "reason",
2847 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2848 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2850 ui_out_field_int (uiout
, "bkptno", b
->number
);
2851 ui_out_text (uiout
, ", ");
2852 result
= PRINT_SRC_AND_LOC
;
2855 case bp_shlib_event
:
2856 /* Did we stop because the user set the stop_on_solib_events
2857 variable? (If so, we report this as a generic, "Stopped due
2858 to shlib event" message.) */
2859 printf_filtered (_("Stopped due to shared library event\n"));
2860 result
= PRINT_NOTHING
;
2863 case bp_thread_event
:
2864 /* Not sure how we will get here.
2865 GDB should not stop for these breakpoints. */
2866 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2867 result
= PRINT_NOTHING
;
2870 case bp_overlay_event
:
2871 /* By analogy with the thread event, GDB should not stop for these. */
2872 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2873 result
= PRINT_NOTHING
;
2876 case bp_longjmp_master
:
2877 /* These should never be enabled. */
2878 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2879 result
= PRINT_NOTHING
;
2883 case bp_hardware_watchpoint
:
2884 annotate_watchpoint (b
->number
);
2885 if (ui_out_is_mi_like_p (uiout
))
2888 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2890 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2891 ui_out_text (uiout
, "\nOld value = ");
2892 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2893 ui_out_field_stream (uiout
, "old", stb
);
2894 ui_out_text (uiout
, "\nNew value = ");
2895 watchpoint_value_print (b
->val
, stb
->stream
);
2896 ui_out_field_stream (uiout
, "new", stb
);
2897 ui_out_text (uiout
, "\n");
2898 /* More than one watchpoint may have been triggered. */
2899 result
= PRINT_UNKNOWN
;
2902 case bp_read_watchpoint
:
2903 if (ui_out_is_mi_like_p (uiout
))
2906 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2908 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2909 ui_out_text (uiout
, "\nValue = ");
2910 watchpoint_value_print (b
->val
, stb
->stream
);
2911 ui_out_field_stream (uiout
, "value", stb
);
2912 ui_out_text (uiout
, "\n");
2913 result
= PRINT_UNKNOWN
;
2916 case bp_access_watchpoint
:
2917 if (bs
->old_val
!= NULL
)
2919 annotate_watchpoint (b
->number
);
2920 if (ui_out_is_mi_like_p (uiout
))
2923 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2925 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2926 ui_out_text (uiout
, "\nOld value = ");
2927 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2928 ui_out_field_stream (uiout
, "old", stb
);
2929 ui_out_text (uiout
, "\nNew value = ");
2934 if (ui_out_is_mi_like_p (uiout
))
2937 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2938 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2939 ui_out_text (uiout
, "\nValue = ");
2941 watchpoint_value_print (b
->val
, stb
->stream
);
2942 ui_out_field_stream (uiout
, "new", stb
);
2943 ui_out_text (uiout
, "\n");
2944 result
= PRINT_UNKNOWN
;
2947 /* Fall through, we don't deal with these types of breakpoints
2951 if (ui_out_is_mi_like_p (uiout
))
2954 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2955 result
= PRINT_UNKNOWN
;
2959 if (ui_out_is_mi_like_p (uiout
))
2962 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2963 result
= PRINT_UNKNOWN
;
2968 case bp_longjmp_resume
:
2969 case bp_step_resume
:
2970 case bp_watchpoint_scope
:
2975 result
= PRINT_UNKNOWN
;
2979 do_cleanups (old_chain
);
2983 /* Generic routine for printing messages indicating why we
2984 stopped. The behavior of this function depends on the value
2985 'print_it' in the bpstat structure. Under some circumstances we
2986 may decide not to print anything here and delegate the task to
2989 static enum print_stop_action
2990 print_bp_stop_message (bpstat bs
)
2992 switch (bs
->print_it
)
2995 /* Nothing should be printed for this bpstat entry. */
2996 return PRINT_UNKNOWN
;
3000 /* We still want to print the frame, but we already printed the
3001 relevant messages. */
3002 return PRINT_SRC_AND_LOC
;
3005 case print_it_normal
:
3007 const struct bp_location
*bl
= bs
->breakpoint_at
;
3008 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3010 /* Normal case. Call the breakpoint's print_it method, or
3011 print_it_typical. */
3012 /* FIXME: how breakpoint can ever be NULL here? */
3013 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3014 return b
->ops
->print_it (b
);
3016 return print_it_typical (bs
);
3021 internal_error (__FILE__
, __LINE__
,
3022 _("print_bp_stop_message: unrecognized enum value"));
3027 /* Print a message indicating what happened. This is called from
3028 normal_stop(). The input to this routine is the head of the bpstat
3029 list - a list of the eventpoints that caused this stop. This
3030 routine calls the generic print routine for printing a message
3031 about reasons for stopping. This will print (for example) the
3032 "Breakpoint n," part of the output. The return value of this
3035 PRINT_UNKNOWN: Means we printed nothing
3036 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3037 code to print the location. An example is
3038 "Breakpoint 1, " which should be followed by
3040 PRINT_SRC_ONLY: Means we printed something, but there is no need
3041 to also print the location part of the message.
3042 An example is the catch/throw messages, which
3043 don't require a location appended to the end.
3044 PRINT_NOTHING: We have done some printing and we don't need any
3045 further info to be printed.*/
3047 enum print_stop_action
3048 bpstat_print (bpstat bs
)
3052 /* Maybe another breakpoint in the chain caused us to stop.
3053 (Currently all watchpoints go on the bpstat whether hit or not.
3054 That probably could (should) be changed, provided care is taken
3055 with respect to bpstat_explains_signal). */
3056 for (; bs
; bs
= bs
->next
)
3058 val
= print_bp_stop_message (bs
);
3059 if (val
== PRINT_SRC_ONLY
3060 || val
== PRINT_SRC_AND_LOC
3061 || val
== PRINT_NOTHING
)
3065 /* We reached the end of the chain, or we got a null BS to start
3066 with and nothing was printed. */
3067 return PRINT_UNKNOWN
;
3070 /* Evaluate the expression EXP and return 1 if value is zero.
3071 This is used inside a catch_errors to evaluate the breakpoint condition.
3072 The argument is a "struct expression *" that has been cast to char * to
3073 make it pass through catch_errors. */
3076 breakpoint_cond_eval (void *exp
)
3078 struct value
*mark
= value_mark ();
3079 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3080 value_free_to_mark (mark
);
3084 /* Allocate a new bpstat and chain it to the current one. */
3087 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3091 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3093 bs
->breakpoint_at
= bl
;
3094 /* If the condition is false, etc., don't do the commands. */
3095 bs
->commands
= NULL
;
3097 bs
->print_it
= print_it_normal
;
3101 /* The target has stopped with waitstatus WS. Check if any hardware
3102 watchpoints have triggered, according to the target. */
3105 watchpoints_triggered (struct target_waitstatus
*ws
)
3107 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3109 struct breakpoint
*b
;
3111 if (!stopped_by_watchpoint
)
3113 /* We were not stopped by a watchpoint. Mark all watchpoints
3114 as not triggered. */
3116 if (b
->type
== bp_hardware_watchpoint
3117 || b
->type
== bp_read_watchpoint
3118 || b
->type
== bp_access_watchpoint
)
3119 b
->watchpoint_triggered
= watch_triggered_no
;
3124 if (!target_stopped_data_address (¤t_target
, &addr
))
3126 /* We were stopped by a watchpoint, but we don't know where.
3127 Mark all watchpoints as unknown. */
3129 if (b
->type
== bp_hardware_watchpoint
3130 || b
->type
== bp_read_watchpoint
3131 || b
->type
== bp_access_watchpoint
)
3132 b
->watchpoint_triggered
= watch_triggered_unknown
;
3134 return stopped_by_watchpoint
;
3137 /* The target could report the data address. Mark watchpoints
3138 affected by this data address as triggered, and all others as not
3142 if (b
->type
== bp_hardware_watchpoint
3143 || b
->type
== bp_read_watchpoint
3144 || b
->type
== bp_access_watchpoint
)
3146 struct bp_location
*loc
;
3149 b
->watchpoint_triggered
= watch_triggered_no
;
3150 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3151 /* Exact match not required. Within range is
3153 if (target_watchpoint_addr_within_range (¤t_target
,
3157 b
->watchpoint_triggered
= watch_triggered_yes
;
3165 /* Possible return values for watchpoint_check (this can't be an enum
3166 because of check_errors). */
3167 /* The watchpoint has been deleted. */
3168 #define WP_DELETED 1
3169 /* The value has changed. */
3170 #define WP_VALUE_CHANGED 2
3171 /* The value has not changed. */
3172 #define WP_VALUE_NOT_CHANGED 3
3174 #define BP_TEMPFLAG 1
3175 #define BP_HARDWAREFLAG 2
3177 /* Check watchpoint condition. */
3180 watchpoint_check (void *p
)
3182 bpstat bs
= (bpstat
) p
;
3183 struct breakpoint
*b
;
3184 struct frame_info
*fr
;
3185 int within_current_scope
;
3187 b
= bs
->breakpoint_at
->owner
;
3189 /* If this is a local watchpoint, we only want to check if the
3190 watchpoint frame is in scope if the current thread is the thread
3191 that was used to create the watchpoint. */
3192 if (!watchpoint_in_thread_scope (b
))
3193 return WP_VALUE_NOT_CHANGED
;
3195 if (b
->exp_valid_block
== NULL
)
3196 within_current_scope
= 1;
3199 struct frame_info
*frame
= get_current_frame ();
3200 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3201 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3203 fr
= frame_find_by_id (b
->watchpoint_frame
);
3204 within_current_scope
= (fr
!= NULL
);
3206 /* If we've gotten confused in the unwinder, we might have
3207 returned a frame that can't describe this variable. */
3208 if (within_current_scope
)
3210 struct symbol
*function
;
3212 function
= get_frame_function (fr
);
3213 if (function
== NULL
3214 || !contained_in (b
->exp_valid_block
,
3215 SYMBOL_BLOCK_VALUE (function
)))
3216 within_current_scope
= 0;
3219 /* in_function_epilogue_p() returns a non-zero value if we're still
3220 in the function but the stack frame has already been invalidated.
3221 Since we can't rely on the values of local variables after the
3222 stack has been destroyed, we are treating the watchpoint in that
3223 state as `not changed' without further checking. Don't mark
3224 watchpoints as changed if the current frame is in an epilogue -
3225 even if they are in some other frame, our view of the stack
3226 is likely to be wrong. */
3227 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3228 return WP_VALUE_NOT_CHANGED
;
3230 if (within_current_scope
)
3231 /* If we end up stopping, the current frame will get selected
3232 in normal_stop. So this call to select_frame won't affect
3237 if (within_current_scope
)
3239 /* We use value_{,free_to_}mark because it could be a
3240 *long* time before we return to the command level and
3241 call free_all_values. We can't call free_all_values because
3242 we might be in the middle of evaluating a function call. */
3244 struct value
*mark
= value_mark ();
3245 struct value
*new_val
;
3247 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3248 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3249 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
3251 if (new_val
!= NULL
)
3253 release_value (new_val
);
3254 value_free_to_mark (mark
);
3256 bs
->old_val
= b
->val
;
3259 /* We will stop here */
3260 return WP_VALUE_CHANGED
;
3264 /* Nothing changed, don't do anything. */
3265 value_free_to_mark (mark
);
3266 /* We won't stop here */
3267 return WP_VALUE_NOT_CHANGED
;
3272 /* This seems like the only logical thing to do because
3273 if we temporarily ignored the watchpoint, then when
3274 we reenter the block in which it is valid it contains
3275 garbage (in the case of a function, it may have two
3276 garbage values, one before and one after the prologue).
3277 So we can't even detect the first assignment to it and
3278 watch after that (since the garbage may or may not equal
3279 the first value assigned). */
3280 /* We print all the stop information in print_it_typical(), but
3281 in this case, by the time we call print_it_typical() this bp
3282 will be deleted already. So we have no choice but print the
3283 information here. */
3284 if (ui_out_is_mi_like_p (uiout
))
3286 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3287 ui_out_text (uiout
, "\nWatchpoint ");
3288 ui_out_field_int (uiout
, "wpnum", b
->number
);
3289 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3290 which its expression is valid.\n");
3292 if (b
->related_breakpoint
)
3293 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3294 b
->disposition
= disp_del_at_next_stop
;
3300 /* Return true if it looks like target has stopped due to hitting
3301 breakpoint location BL. This function does not check if we
3302 should stop, only if BL explains the stop. */
3304 bpstat_check_location (const struct bp_location
*bl
,
3305 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3307 struct breakpoint
*b
= bl
->owner
;
3309 /* By definition, the inferior does not report stops at
3311 if (b
->type
== bp_tracepoint
)
3314 if (b
->type
!= bp_watchpoint
3315 && b
->type
!= bp_hardware_watchpoint
3316 && b
->type
!= bp_read_watchpoint
3317 && b
->type
!= bp_access_watchpoint
3318 && b
->type
!= bp_hardware_breakpoint
3319 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3321 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3324 if (overlay_debugging
/* unmapped overlay section */
3325 && section_is_overlay (bl
->section
)
3326 && !section_is_mapped (bl
->section
))
3330 /* Continuable hardware watchpoints are treated as non-existent if the
3331 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3332 some data address). Otherwise gdb won't stop on a break instruction
3333 in the code (not from a breakpoint) when a hardware watchpoint has
3334 been defined. Also skip watchpoints which we know did not trigger
3335 (did not match the data address). */
3337 if ((b
->type
== bp_hardware_watchpoint
3338 || b
->type
== bp_read_watchpoint
3339 || b
->type
== bp_access_watchpoint
)
3340 && b
->watchpoint_triggered
== watch_triggered_no
)
3343 if (b
->type
== bp_hardware_breakpoint
)
3345 if (bl
->address
!= bp_addr
)
3347 if (overlay_debugging
/* unmapped overlay section */
3348 && section_is_overlay (bl
->section
)
3349 && !section_is_mapped (bl
->section
))
3353 if (b
->type
== bp_catchpoint
)
3355 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3356 if (!b
->ops
->breakpoint_hit (b
))
3363 /* If BS refers to a watchpoint, determine if the watched values
3364 has actually changed, and we should stop. If not, set BS->stop
3367 bpstat_check_watchpoint (bpstat bs
)
3369 const struct bp_location
*bl
= bs
->breakpoint_at
;
3370 struct breakpoint
*b
= bl
->owner
;
3372 if (b
->type
== bp_watchpoint
3373 || b
->type
== bp_read_watchpoint
3374 || b
->type
== bp_access_watchpoint
3375 || b
->type
== bp_hardware_watchpoint
)
3379 int must_check_value
= 0;
3381 if (b
->type
== bp_watchpoint
)
3382 /* For a software watchpoint, we must always check the
3384 must_check_value
= 1;
3385 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3386 /* We have a hardware watchpoint (read, write, or access)
3387 and the target earlier reported an address watched by
3389 must_check_value
= 1;
3390 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3391 && b
->type
== bp_hardware_watchpoint
)
3392 /* We were stopped by a hardware watchpoint, but the target could
3393 not report the data address. We must check the watchpoint's
3394 value. Access and read watchpoints are out of luck; without
3395 a data address, we can't figure it out. */
3396 must_check_value
= 1;
3398 if (must_check_value
)
3400 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3402 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3403 int e
= catch_errors (watchpoint_check
, bs
, message
,
3405 do_cleanups (cleanups
);
3409 /* We've already printed what needs to be printed. */
3410 bs
->print_it
= print_it_done
;
3413 case WP_VALUE_CHANGED
:
3414 if (b
->type
== bp_read_watchpoint
)
3416 /* Don't stop: read watchpoints shouldn't fire if
3417 the value has changed. This is for targets
3418 which cannot set read-only watchpoints. */
3419 bs
->print_it
= print_it_noop
;
3423 case WP_VALUE_NOT_CHANGED
:
3424 if (b
->type
== bp_hardware_watchpoint
3425 || b
->type
== bp_watchpoint
)
3427 /* Don't stop: write watchpoints shouldn't fire if
3428 the value hasn't changed. */
3429 bs
->print_it
= print_it_noop
;
3437 /* Error from catch_errors. */
3438 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3439 if (b
->related_breakpoint
)
3440 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3441 b
->disposition
= disp_del_at_next_stop
;
3442 /* We've already printed what needs to be printed. */
3443 bs
->print_it
= print_it_done
;
3447 else /* must_check_value == 0 */
3449 /* This is a case where some watchpoint(s) triggered, but
3450 not at the address of this watchpoint, or else no
3451 watchpoint triggered after all. So don't print
3452 anything for this watchpoint. */
3453 bs
->print_it
= print_it_noop
;
3460 /* Check conditions (condition proper, frame, thread and ignore count)
3461 of breakpoint referred to by BS. If we should not stop for this
3462 breakpoint, set BS->stop to 0. */
3464 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3466 int thread_id
= pid_to_thread_id (ptid
);
3467 const struct bp_location
*bl
= bs
->breakpoint_at
;
3468 struct breakpoint
*b
= bl
->owner
;
3470 if (frame_id_p (b
->frame_id
)
3471 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3475 int value_is_zero
= 0;
3477 /* If this is a scope breakpoint, mark the associated
3478 watchpoint as triggered so that we will handle the
3479 out-of-scope event. We'll get to the watchpoint next
3481 if (b
->type
== bp_watchpoint_scope
)
3482 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3484 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3486 /* We use value_mark and value_free_to_mark because it could
3487 be a long time before we return to the command level and
3488 call free_all_values. We can't call free_all_values
3489 because we might be in the middle of evaluating a
3491 struct value
*mark
= value_mark ();
3493 /* Need to select the frame, with all that implies so that
3494 the conditions will have the right context. Because we
3495 use the frame, we will not see an inlined function's
3496 variables when we arrive at a breakpoint at the start
3497 of the inlined function; the current frame will be the
3499 select_frame (get_current_frame ());
3501 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3502 "Error in testing breakpoint condition:\n",
3504 /* FIXME-someday, should give breakpoint # */
3505 value_free_to_mark (mark
);
3507 if (bl
->cond
&& value_is_zero
)
3511 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3515 else if (b
->ignore_count
> 0)
3518 annotate_ignore_count_change ();
3520 /* Increase the hit count even though we don't
3528 /* Get a bpstat associated with having just stopped at address
3529 BP_ADDR in thread PTID.
3531 Determine whether we stopped at a breakpoint, etc, or whether we
3532 don't understand this stop. Result is a chain of bpstat's such that:
3534 if we don't understand the stop, the result is a null pointer.
3536 if we understand why we stopped, the result is not null.
3538 Each element of the chain refers to a particular breakpoint or
3539 watchpoint at which we have stopped. (We may have stopped for
3540 several reasons concurrently.)
3542 Each element of the chain has valid next, breakpoint_at,
3543 commands, FIXME??? fields. */
3546 bpstat_stop_status (struct address_space
*aspace
,
3547 CORE_ADDR bp_addr
, ptid_t ptid
)
3549 struct breakpoint
*b
= NULL
;
3550 struct bp_location
*bl
, **blp_tmp
;
3551 struct bp_location
*loc
;
3552 /* Root of the chain of bpstat's */
3553 struct bpstats root_bs
[1];
3554 /* Pointer to the last thing in the chain currently. */
3555 bpstat bs
= root_bs
;
3557 int need_remove_insert
;
3559 /* ALL_BP_LOCATIONS iteration would break across
3560 update_global_location_list possibly executed by
3561 bpstat_check_breakpoint_conditions's inferior call. */
3565 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3568 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
3570 /* For hardware watchpoints, we look only at the first location.
3571 The watchpoint_check function will work on entire expression,
3572 not the individual locations. For read watchopints, the
3573 watchpoints_triggered function have checked all locations
3575 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3578 if (bl
->shlib_disabled
)
3581 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
3584 /* Come here if it's a watchpoint, or if the break address matches */
3586 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3588 /* Assume we stop. Should we find watchpoint that is not actually
3589 triggered, or if condition of breakpoint is false, we'll reset
3594 bpstat_check_watchpoint (bs
);
3598 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3599 || b
->type
== bp_longjmp_master
)
3600 /* We do not stop for these. */
3603 bpstat_check_breakpoint_conditions (bs
, ptid
);
3609 /* We will stop here */
3610 if (b
->disposition
== disp_disable
)
3612 if (b
->enable_state
!= bp_permanent
)
3613 b
->enable_state
= bp_disabled
;
3614 update_global_location_list (0);
3618 bs
->commands
= b
->commands
;
3620 && (strcmp ("silent", bs
->commands
->line
) == 0
3621 || (xdb_commands
&& strcmp ("Q",
3622 bs
->commands
->line
) == 0)))
3624 bs
->commands
= bs
->commands
->next
;
3627 bs
->commands
= copy_command_lines (bs
->commands
);
3630 /* Print nothing for this entry if we dont stop or dont print. */
3631 if (bs
->stop
== 0 || bs
->print
== 0)
3632 bs
->print_it
= print_it_noop
;
3636 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3638 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
3641 bs
= bpstat_alloc (loc
, bs
);
3642 /* For hits of moribund locations, we should just proceed. */
3645 bs
->print_it
= print_it_noop
;
3649 bs
->next
= NULL
; /* Terminate the chain */
3650 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3652 /* If we aren't stopping, the value of some hardware watchpoint may
3653 not have changed, but the intermediate memory locations we are
3654 watching may have. Don't bother if we're stopping; this will get
3656 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3660 need_remove_insert
= 0;
3662 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3664 && bs
->breakpoint_at
->owner
3665 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
3667 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
3668 /* Updating watchpoints invalidates bs->breakpoint_at.
3669 Prevent further code from trying to use it. */
3670 bs
->breakpoint_at
= NULL
;
3671 need_remove_insert
= 1;
3674 if (need_remove_insert
)
3675 update_global_location_list (1);
3677 return root_bs
->next
;
3680 /* Tell what to do about this bpstat. */
3682 bpstat_what (bpstat bs
)
3684 /* Classify each bpstat as one of the following. */
3687 /* This bpstat element has no effect on the main_action. */
3690 /* There was a watchpoint, stop but don't print. */
3693 /* There was a watchpoint, stop and print. */
3696 /* There was a breakpoint but we're not stopping. */
3699 /* There was a breakpoint, stop but don't print. */
3702 /* There was a breakpoint, stop and print. */
3705 /* We hit the longjmp breakpoint. */
3708 /* We hit the longjmp_resume breakpoint. */
3711 /* We hit the step_resume breakpoint. */
3714 /* We hit the shared library event breakpoint. */
3717 /* We hit the jit event breakpoint. */
3720 /* This is just used to count how many enums there are. */
3724 /* Here is the table which drives this routine. So that we can
3725 format it pretty, we define some abbreviations for the
3726 enum bpstat_what codes. */
3727 #define kc BPSTAT_WHAT_KEEP_CHECKING
3728 #define ss BPSTAT_WHAT_STOP_SILENT
3729 #define sn BPSTAT_WHAT_STOP_NOISY
3730 #define sgl BPSTAT_WHAT_SINGLE
3731 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3732 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3733 #define sr BPSTAT_WHAT_STEP_RESUME
3734 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3735 #define jit BPSTAT_WHAT_CHECK_JIT
3737 /* "Can't happen." Might want to print an error message.
3738 abort() is not out of the question, but chances are GDB is just
3739 a bit confused, not unusable. */
3740 #define err BPSTAT_WHAT_STOP_NOISY
3742 /* Given an old action and a class, come up with a new action. */
3743 /* One interesting property of this table is that wp_silent is the same
3744 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3745 after stopping, the check for whether to step over a breakpoint
3746 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3747 reference to how we stopped. We retain separate wp_silent and
3748 bp_silent codes in case we want to change that someday.
3750 Another possibly interesting property of this table is that
3751 there's a partial ordering, priority-like, of the actions. Once
3752 you've decided that some action is appropriate, you'll never go
3753 back and decide something of a lower priority is better. The
3756 kc < jit clr sgl shl slr sn sr ss
3757 sgl < jit shl slr sn sr ss
3758 slr < jit err shl sn sr ss
3759 clr < jit err shl sn sr ss
3766 What I think this means is that we don't need a damned table
3767 here. If you just put the rows and columns in the right order,
3768 it'd look awfully regular. We could simply walk the bpstat list
3769 and choose the highest priority action we find, with a little
3770 logic to handle the 'err' cases. */
3772 /* step_resume entries: a step resume breakpoint overrides another
3773 breakpoint of signal handling (see comment in wait_for_inferior
3774 at where we set the step_resume breakpoint). */
3776 static const enum bpstat_what_main_action
3777 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3780 /* kc ss sn sgl slr clr sr shl jit */
3781 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
3782 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
3783 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
3784 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
3785 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
3786 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
3787 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
3788 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
3789 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3790 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
3791 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
3805 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3806 struct bpstat_what retval
;
3808 retval
.call_dummy
= 0;
3809 for (; bs
!= NULL
; bs
= bs
->next
)
3811 enum class bs_class
= no_effect
;
3812 if (bs
->breakpoint_at
== NULL
)
3813 /* I suspect this can happen if it was a momentary breakpoint
3814 which has since been deleted. */
3816 if (bs
->breakpoint_at
->owner
== NULL
)
3817 bs_class
= bp_nostop
;
3819 switch (bs
->breakpoint_at
->owner
->type
)
3825 case bp_hardware_breakpoint
:
3831 bs_class
= bp_noisy
;
3833 bs_class
= bp_silent
;
3836 bs_class
= bp_nostop
;
3839 case bp_hardware_watchpoint
:
3840 case bp_read_watchpoint
:
3841 case bp_access_watchpoint
:
3845 bs_class
= wp_noisy
;
3847 bs_class
= wp_silent
;
3850 /* There was a watchpoint, but we're not stopping.
3851 This requires no further action. */
3852 bs_class
= no_effect
;
3855 bs_class
= long_jump
;
3857 case bp_longjmp_resume
:
3858 bs_class
= long_resume
;
3860 case bp_step_resume
:
3863 bs_class
= step_resume
;
3866 /* It is for the wrong frame. */
3867 bs_class
= bp_nostop
;
3869 case bp_watchpoint_scope
:
3870 bs_class
= bp_nostop
;
3872 case bp_shlib_event
:
3873 bs_class
= shlib_event
;
3876 bs_class
= jit_event
;
3878 case bp_thread_event
:
3879 case bp_overlay_event
:
3880 case bp_longjmp_master
:
3881 bs_class
= bp_nostop
;
3887 bs_class
= bp_noisy
;
3889 bs_class
= bp_silent
;
3892 /* There was a catchpoint, but we're not stopping.
3893 This requires no further action. */
3894 bs_class
= no_effect
;
3897 /* Make sure the action is stop (silent or noisy),
3898 so infrun.c pops the dummy frame. */
3899 bs_class
= bp_silent
;
3900 retval
.call_dummy
= 1;
3903 /* Tracepoint hits should not be reported back to GDB, and
3904 if one got through somehow, it should have been filtered
3906 internal_error (__FILE__
, __LINE__
,
3907 _("bpstat_what: bp_tracepoint encountered"));
3910 current_action
= table
[(int) bs_class
][(int) current_action
];
3912 retval
.main_action
= current_action
;
3916 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3917 without hardware support). This isn't related to a specific bpstat,
3918 just to things like whether watchpoints are set. */
3921 bpstat_should_step (void)
3923 struct breakpoint
*b
;
3925 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3931 bpstat_causes_stop (bpstat bs
)
3933 for (; bs
!= NULL
; bs
= bs
->next
)
3942 /* Print the LOC location out of the list of B->LOC locations. */
3944 static void print_breakpoint_location (struct breakpoint
*b
,
3945 struct bp_location
*loc
,
3947 struct ui_stream
*stb
)
3949 struct cleanup
*old_chain
= save_current_program_space ();
3951 if (loc
!= NULL
&& loc
->shlib_disabled
)
3955 set_current_program_space (loc
->pspace
);
3957 if (b
->source_file
&& loc
)
3960 = find_pc_sect_function (loc
->address
, loc
->section
);
3963 ui_out_text (uiout
, "in ");
3964 ui_out_field_string (uiout
, "func",
3965 SYMBOL_PRINT_NAME (sym
));
3966 ui_out_wrap_hint (uiout
, wrap_indent
);
3967 ui_out_text (uiout
, " at ");
3969 ui_out_field_string (uiout
, "file", b
->source_file
);
3970 ui_out_text (uiout
, ":");
3972 if (ui_out_is_mi_like_p (uiout
))
3974 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3975 char *fullname
= symtab_to_fullname (sal
.symtab
);
3978 ui_out_field_string (uiout
, "fullname", fullname
);
3981 ui_out_field_int (uiout
, "line", b
->line_number
);
3985 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
3987 ui_out_field_stream (uiout
, "at", stb
);
3990 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3992 do_cleanups (old_chain
);
3995 /* Print B to gdb_stdout. */
3997 print_one_breakpoint_location (struct breakpoint
*b
,
3998 struct bp_location
*loc
,
4000 struct bp_location
**last_loc
,
4001 int print_address_bits
,
4004 struct command_line
*l
;
4006 struct ep_type_description
4011 static struct ep_type_description bptypes
[] =
4013 {bp_none
, "?deleted?"},
4014 {bp_breakpoint
, "breakpoint"},
4015 {bp_hardware_breakpoint
, "hw breakpoint"},
4016 {bp_until
, "until"},
4017 {bp_finish
, "finish"},
4018 {bp_watchpoint
, "watchpoint"},
4019 {bp_hardware_watchpoint
, "hw watchpoint"},
4020 {bp_read_watchpoint
, "read watchpoint"},
4021 {bp_access_watchpoint
, "acc watchpoint"},
4022 {bp_longjmp
, "longjmp"},
4023 {bp_longjmp_resume
, "longjmp resume"},
4024 {bp_step_resume
, "step resume"},
4025 {bp_watchpoint_scope
, "watchpoint scope"},
4026 {bp_call_dummy
, "call dummy"},
4027 {bp_shlib_event
, "shlib events"},
4028 {bp_thread_event
, "thread events"},
4029 {bp_overlay_event
, "overlay events"},
4030 {bp_longjmp_master
, "longjmp master"},
4031 {bp_catchpoint
, "catchpoint"},
4032 {bp_tracepoint
, "tracepoint"},
4033 {bp_jit_event
, "jit events"},
4036 static char bpenables
[] = "nynny";
4037 char wrap_indent
[80];
4038 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4039 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4040 struct cleanup
*bkpt_chain
;
4042 int header_of_multiple
= 0;
4043 int part_of_multiple
= (loc
!= NULL
);
4044 struct value_print_options opts
;
4046 get_user_print_options (&opts
);
4048 gdb_assert (!loc
|| loc_number
!= 0);
4049 /* See comment in print_one_breakpoint concerning
4050 treatment of breakpoints with single disabled
4054 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4055 header_of_multiple
= 1;
4060 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4064 if (part_of_multiple
)
4067 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4068 ui_out_field_string (uiout
, "number", formatted
);
4073 ui_out_field_int (uiout
, "number", b
->number
);
4078 if (part_of_multiple
)
4079 ui_out_field_skip (uiout
, "type");
4082 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4083 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4084 internal_error (__FILE__
, __LINE__
,
4085 _("bptypes table does not describe type #%d."),
4087 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4092 if (part_of_multiple
)
4093 ui_out_field_skip (uiout
, "disp");
4095 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4100 if (part_of_multiple
)
4101 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4103 ui_out_field_fmt (uiout
, "enabled", "%c",
4104 bpenables
[(int) b
->enable_state
]);
4105 ui_out_spaces (uiout
, 2);
4109 strcpy (wrap_indent
, " ");
4110 if (opts
.addressprint
)
4112 if (print_address_bits
<= 32)
4113 strcat (wrap_indent
, " ");
4115 strcat (wrap_indent
, " ");
4118 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4120 /* Although the print_one can possibly print
4121 all locations, calling it here is not likely
4122 to get any nice result. So, make sure there's
4123 just one location. */
4124 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4125 b
->ops
->print_one (b
, last_loc
);
4131 internal_error (__FILE__
, __LINE__
,
4132 _("print_one_breakpoint: bp_none encountered\n"));
4136 case bp_hardware_watchpoint
:
4137 case bp_read_watchpoint
:
4138 case bp_access_watchpoint
:
4139 /* Field 4, the address, is omitted (which makes the columns
4140 not line up too nicely with the headers, but the effect
4141 is relatively readable). */
4142 if (opts
.addressprint
)
4143 ui_out_field_skip (uiout
, "addr");
4145 ui_out_field_string (uiout
, "what", b
->exp_string
);
4149 case bp_hardware_breakpoint
:
4153 case bp_longjmp_resume
:
4154 case bp_step_resume
:
4155 case bp_watchpoint_scope
:
4157 case bp_shlib_event
:
4158 case bp_thread_event
:
4159 case bp_overlay_event
:
4160 case bp_longjmp_master
:
4163 if (opts
.addressprint
)
4166 if (header_of_multiple
)
4167 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4168 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4169 ui_out_field_string (uiout
, "addr", "<PENDING>");
4171 ui_out_field_core_addr (uiout
, "addr",
4172 loc
->gdbarch
, loc
->address
);
4175 if (!header_of_multiple
)
4176 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4183 /* For backward compatibility, don't display inferiors unless there
4186 && !header_of_multiple
4188 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4189 && (number_of_program_spaces () > 1
4190 || number_of_inferiors () > 1)
4191 && loc
->owner
->type
!= bp_catchpoint
)))
4193 struct inferior
*inf
;
4196 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4198 if (inf
->pspace
== loc
->pspace
)
4203 ui_out_text (uiout
, " inf ");
4206 ui_out_text (uiout
, ", ");
4207 ui_out_text (uiout
, plongest (inf
->num
));
4212 if (!part_of_multiple
)
4214 if (b
->thread
!= -1)
4216 /* FIXME: This seems to be redundant and lost here; see the
4217 "stop only in" line a little further down. */
4218 ui_out_text (uiout
, " thread ");
4219 ui_out_field_int (uiout
, "thread", b
->thread
);
4221 else if (b
->task
!= 0)
4223 ui_out_text (uiout
, " task ");
4224 ui_out_field_int (uiout
, "task", b
->task
);
4228 ui_out_text (uiout
, "\n");
4230 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4233 ui_out_text (uiout
, "\tstop only in stack frame at ");
4234 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4236 ui_out_field_core_addr (uiout
, "frame",
4237 b
->gdbarch
, b
->frame_id
.stack_addr
);
4238 ui_out_text (uiout
, "\n");
4241 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4243 /* We do not print the condition for Ada exception catchpoints
4244 because the condition is an internal implementation detail
4245 that we do not want to expose to the user. */
4247 if (b
->type
== bp_tracepoint
)
4248 ui_out_text (uiout
, "\ttrace only if ");
4250 ui_out_text (uiout
, "\tstop only if ");
4251 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4252 ui_out_text (uiout
, "\n");
4255 if (!part_of_multiple
&& b
->thread
!= -1)
4257 /* FIXME should make an annotation for this */
4258 ui_out_text (uiout
, "\tstop only in thread ");
4259 ui_out_field_int (uiout
, "thread", b
->thread
);
4260 ui_out_text (uiout
, "\n");
4263 if (!part_of_multiple
&& b
->hit_count
)
4265 /* FIXME should make an annotation for this */
4266 if (ep_is_catchpoint (b
))
4267 ui_out_text (uiout
, "\tcatchpoint");
4269 ui_out_text (uiout
, "\tbreakpoint");
4270 ui_out_text (uiout
, " already hit ");
4271 ui_out_field_int (uiout
, "times", b
->hit_count
);
4272 if (b
->hit_count
== 1)
4273 ui_out_text (uiout
, " time\n");
4275 ui_out_text (uiout
, " times\n");
4278 /* Output the count also if it is zero, but only if this is
4279 mi. FIXME: Should have a better test for this. */
4280 if (ui_out_is_mi_like_p (uiout
))
4281 if (!part_of_multiple
&& b
->hit_count
== 0)
4282 ui_out_field_int (uiout
, "times", b
->hit_count
);
4284 if (!part_of_multiple
&& b
->ignore_count
)
4287 ui_out_text (uiout
, "\tignore next ");
4288 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4289 ui_out_text (uiout
, " hits\n");
4293 if (!part_of_multiple
&& l
)
4295 struct cleanup
*script_chain
;
4298 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4299 print_command_lines (uiout
, l
, 4);
4300 do_cleanups (script_chain
);
4303 if (!part_of_multiple
&& b
->pass_count
)
4305 annotate_field (10);
4306 ui_out_text (uiout
, "\tpass count ");
4307 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4308 ui_out_text (uiout
, " \n");
4311 if (!part_of_multiple
&& b
->step_count
)
4313 annotate_field (11);
4314 ui_out_text (uiout
, "\tstep count ");
4315 ui_out_field_int (uiout
, "step", b
->step_count
);
4316 ui_out_text (uiout
, " \n");
4319 if (!part_of_multiple
&& b
->actions
)
4321 struct action_line
*action
;
4322 annotate_field (12);
4323 for (action
= b
->actions
; action
; action
= action
->next
)
4325 ui_out_text (uiout
, " A\t");
4326 ui_out_text (uiout
, action
->action
);
4327 ui_out_text (uiout
, "\n");
4331 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4334 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4335 else if (b
->exp_string
)
4336 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4339 do_cleanups (bkpt_chain
);
4340 do_cleanups (old_chain
);
4344 print_one_breakpoint (struct breakpoint
*b
,
4345 struct bp_location
**last_loc
, int print_address_bits
,
4348 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4349 print_address_bits
, allflag
);
4351 /* If this breakpoint has custom print function,
4352 it's already printed. Otherwise, print individual
4353 locations, if any. */
4354 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4356 /* If breakpoint has a single location that is
4357 disabled, we print it as if it had
4358 several locations, since otherwise it's hard to
4359 represent "breakpoint enabled, location disabled"
4361 Note that while hardware watchpoints have
4362 several locations internally, that's no a property
4365 && !is_hardware_watchpoint (b
)
4366 && (b
->loc
->next
|| !b
->loc
->enabled
)
4367 && !ui_out_is_mi_like_p (uiout
))
4369 struct bp_location
*loc
;
4371 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4372 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4373 print_address_bits
, allflag
);
4379 breakpoint_address_bits (struct breakpoint
*b
)
4381 int print_address_bits
= 0;
4382 struct bp_location
*loc
;
4384 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4386 int addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4387 if (addr_bit
> print_address_bits
)
4388 print_address_bits
= addr_bit
;
4391 return print_address_bits
;
4394 struct captured_breakpoint_query_args
4400 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4402 struct captured_breakpoint_query_args
*args
= data
;
4403 struct breakpoint
*b
;
4404 struct bp_location
*dummy_loc
= NULL
;
4407 if (args
->bnum
== b
->number
)
4409 int print_address_bits
= breakpoint_address_bits (b
);
4410 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4418 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4420 struct captured_breakpoint_query_args args
;
4422 /* For the moment we don't trust print_one_breakpoint() to not throw
4424 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4425 error_message
, RETURN_MASK_ALL
) < 0)
4431 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4432 catchpoints, et.al.). */
4435 user_settable_breakpoint (const struct breakpoint
*b
)
4437 return (b
->type
== bp_breakpoint
4438 || b
->type
== bp_catchpoint
4439 || b
->type
== bp_hardware_breakpoint
4440 || b
->type
== bp_tracepoint
4441 || b
->type
== bp_watchpoint
4442 || b
->type
== bp_read_watchpoint
4443 || b
->type
== bp_access_watchpoint
4444 || b
->type
== bp_hardware_watchpoint
);
4447 /* Print information on user settable breakpoint (watchpoint, etc)
4448 number BNUM. If BNUM is -1 print all user settable breakpoints.
4449 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4452 breakpoint_1 (int bnum
, int allflag
)
4454 struct breakpoint
*b
;
4455 struct bp_location
*last_loc
= NULL
;
4456 int nr_printable_breakpoints
;
4457 struct cleanup
*bkpttbl_chain
;
4458 struct value_print_options opts
;
4459 int print_address_bits
= 0;
4461 get_user_print_options (&opts
);
4463 /* Compute the number of rows in the table, as well as the
4464 size required for address fields. */
4465 nr_printable_breakpoints
= 0;
4468 || bnum
== b
->number
)
4470 if (allflag
|| user_settable_breakpoint (b
))
4472 int addr_bit
= breakpoint_address_bits (b
);
4473 if (addr_bit
> print_address_bits
)
4474 print_address_bits
= addr_bit
;
4476 nr_printable_breakpoints
++;
4480 if (opts
.addressprint
)
4482 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4486 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4489 if (nr_printable_breakpoints
> 0)
4490 annotate_breakpoints_headers ();
4491 if (nr_printable_breakpoints
> 0)
4493 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4494 if (nr_printable_breakpoints
> 0)
4496 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4497 if (nr_printable_breakpoints
> 0)
4499 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4500 if (nr_printable_breakpoints
> 0)
4502 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4503 if (opts
.addressprint
)
4505 if (nr_printable_breakpoints
> 0)
4507 if (print_address_bits
<= 32)
4508 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4510 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4512 if (nr_printable_breakpoints
> 0)
4514 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4515 ui_out_table_body (uiout
);
4516 if (nr_printable_breakpoints
> 0)
4517 annotate_breakpoints_table ();
4521 || bnum
== b
->number
)
4523 /* We only print out user settable breakpoints unless the
4525 if (allflag
|| user_settable_breakpoint (b
))
4526 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
4529 do_cleanups (bkpttbl_chain
);
4531 if (nr_printable_breakpoints
== 0)
4534 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4536 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4541 if (last_loc
&& !server_command
)
4542 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4545 /* FIXME? Should this be moved up so that it is only called when
4546 there have been breakpoints? */
4547 annotate_breakpoints_table_end ();
4551 breakpoints_info (char *bnum_exp
, int from_tty
)
4556 bnum
= parse_and_eval_long (bnum_exp
);
4558 breakpoint_1 (bnum
, 0);
4562 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4567 bnum
= parse_and_eval_long (bnum_exp
);
4569 breakpoint_1 (bnum
, 1);
4573 breakpoint_has_pc (struct breakpoint
*b
,
4574 struct program_space
*pspace
,
4575 CORE_ADDR pc
, struct obj_section
*section
)
4577 struct bp_location
*bl
= b
->loc
;
4578 for (; bl
; bl
= bl
->next
)
4580 if (bl
->pspace
== pspace
4581 && bl
->address
== pc
4582 && (!overlay_debugging
|| bl
->section
== section
))
4588 /* Print a message describing any breakpoints set at PC. This
4589 concerns with logical breakpoints, so we match program spaces, not
4593 describe_other_breakpoints (struct gdbarch
*gdbarch
,
4594 struct program_space
*pspace
, CORE_ADDR pc
,
4595 struct obj_section
*section
, int thread
)
4598 struct breakpoint
*b
;
4601 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
4605 printf_filtered (_("Note: breakpoint "));
4606 else /* if (others == ???) */
4607 printf_filtered (_("Note: breakpoints "));
4609 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
4612 printf_filtered ("%d", b
->number
);
4613 if (b
->thread
== -1 && thread
!= -1)
4614 printf_filtered (" (all threads)");
4615 else if (b
->thread
!= -1)
4616 printf_filtered (" (thread %d)", b
->thread
);
4617 printf_filtered ("%s%s ",
4618 ((b
->enable_state
== bp_disabled
4619 || b
->enable_state
== bp_call_disabled
4620 || b
->enable_state
== bp_startup_disabled
)
4622 : b
->enable_state
== bp_permanent
4626 : ((others
== 1) ? " and" : ""));
4628 printf_filtered (_("also set at pc "));
4629 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4630 printf_filtered (".\n");
4634 /* Set the default place to put a breakpoint
4635 for the `break' command with no arguments. */
4638 set_default_breakpoint (int valid
, struct program_space
*pspace
,
4639 CORE_ADDR addr
, struct symtab
*symtab
,
4642 default_breakpoint_valid
= valid
;
4643 default_breakpoint_pspace
= pspace
;
4644 default_breakpoint_address
= addr
;
4645 default_breakpoint_symtab
= symtab
;
4646 default_breakpoint_line
= line
;
4649 /* Return true iff it is meaningful to use the address member of
4650 BPT. For some breakpoint types, the address member is irrelevant
4651 and it makes no sense to attempt to compare it to other addresses
4652 (or use it for any other purpose either).
4654 More specifically, each of the following breakpoint types will always
4655 have a zero valued address and we don't want to mark breakpoints of any of
4656 these types to be a duplicate of an actual breakpoint at address zero:
4664 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4666 enum bptype type
= bpt
->type
;
4668 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
4671 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
4672 true if LOC1 and LOC2 represent the same watchpoint location. */
4675 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
4677 return (loc1
->owner
->type
== loc2
->owner
->type
4678 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
4679 && loc1
->address
== loc2
->address
4680 && loc1
->length
== loc2
->length
);
4683 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
4684 same breakpoint location. In most targets, this can only be true
4685 if ASPACE1 matches ASPACE2. On targets that have global
4686 breakpoints, the address space doesn't really matter. */
4689 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
4690 struct address_space
*aspace2
, CORE_ADDR addr2
)
4692 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
4693 || aspace1
== aspace2
)
4697 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
4698 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
4699 represent the same location. */
4702 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
4704 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
4705 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
4707 if (hw_point1
!= hw_point2
)
4710 return watchpoint_locations_match (loc1
, loc2
);
4712 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
4713 loc2
->pspace
->aspace
, loc2
->address
);
4717 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4718 int bnum
, int have_bnum
)
4723 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4724 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4726 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4727 bnum
, astr1
, astr2
);
4729 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4732 /* Adjust a breakpoint's address to account for architectural constraints
4733 on breakpoint placement. Return the adjusted address. Note: Very
4734 few targets require this kind of adjustment. For most targets,
4735 this function is simply the identity function. */
4738 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4739 CORE_ADDR bpaddr
, enum bptype bptype
)
4741 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4743 /* Very few targets need any kind of breakpoint adjustment. */
4746 else if (bptype
== bp_watchpoint
4747 || bptype
== bp_hardware_watchpoint
4748 || bptype
== bp_read_watchpoint
4749 || bptype
== bp_access_watchpoint
4750 || bptype
== bp_catchpoint
)
4752 /* Watchpoints and the various bp_catch_* eventpoints should not
4753 have their addresses modified. */
4758 CORE_ADDR adjusted_bpaddr
;
4760 /* Some targets have architectural constraints on the placement
4761 of breakpoint instructions. Obtain the adjusted address. */
4762 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
4764 /* An adjusted breakpoint address can significantly alter
4765 a user's expectations. Print a warning if an adjustment
4767 if (adjusted_bpaddr
!= bpaddr
)
4768 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4770 return adjusted_bpaddr
;
4774 /* Allocate a struct bp_location. */
4776 static struct bp_location
*
4777 allocate_bp_location (struct breakpoint
*bpt
)
4779 struct bp_location
*loc
, *loc_p
;
4781 loc
= xmalloc (sizeof (struct bp_location
));
4782 memset (loc
, 0, sizeof (*loc
));
4786 loc
->shlib_disabled
= 0;
4796 case bp_longjmp_resume
:
4797 case bp_step_resume
:
4798 case bp_watchpoint_scope
:
4800 case bp_shlib_event
:
4801 case bp_thread_event
:
4802 case bp_overlay_event
:
4804 case bp_longjmp_master
:
4805 loc
->loc_type
= bp_loc_software_breakpoint
;
4807 case bp_hardware_breakpoint
:
4808 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4810 case bp_hardware_watchpoint
:
4811 case bp_read_watchpoint
:
4812 case bp_access_watchpoint
:
4813 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4817 loc
->loc_type
= bp_loc_other
;
4820 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4826 static void free_bp_location (struct bp_location
*loc
)
4831 if (loc
->function_name
)
4832 xfree (loc
->function_name
);
4837 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4838 that has type BPTYPE and has no locations as yet. */
4839 /* This function is used in gdbtk sources and thus can not be made static. */
4841 static struct breakpoint
*
4842 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
4845 struct breakpoint
*b
, *b1
;
4847 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4848 memset (b
, 0, sizeof (*b
));
4851 b
->gdbarch
= gdbarch
;
4852 b
->language
= current_language
->la_language
;
4853 b
->input_radix
= input_radix
;
4855 b
->enable_state
= bp_enabled
;
4858 b
->ignore_count
= 0;
4860 b
->frame_id
= null_frame_id
;
4861 b
->forked_inferior_pid
= null_ptid
;
4862 b
->exec_pathname
= NULL
;
4863 b
->syscalls_to_be_caught
= NULL
;
4865 b
->condition_not_parsed
= 0;
4867 /* Add this breakpoint to the end of the chain
4868 so that a list of breakpoints will come out in order
4869 of increasing numbers. */
4871 b1
= breakpoint_chain
;
4873 breakpoint_chain
= b
;
4883 /* Initialize loc->function_name. */
4885 set_breakpoint_location_function (struct bp_location
*loc
)
4887 if (loc
->owner
->type
== bp_breakpoint
4888 || loc
->owner
->type
== bp_hardware_breakpoint
4889 || loc
->owner
->type
== bp_tracepoint
)
4891 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4893 if (loc
->function_name
)
4894 loc
->function_name
= xstrdup (loc
->function_name
);
4898 /* Attempt to determine architecture of location identified by SAL. */
4899 static struct gdbarch
*
4900 get_sal_arch (struct symtab_and_line sal
)
4903 return get_objfile_arch (sal
.section
->objfile
);
4905 return get_objfile_arch (sal
.symtab
->objfile
);
4910 /* set_raw_breakpoint is a low level routine for allocating and
4911 partially initializing a breakpoint of type BPTYPE. The newly
4912 created breakpoint's address, section, source file name, and line
4913 number are provided by SAL. The newly created and partially
4914 initialized breakpoint is added to the breakpoint chain and
4915 is also returned as the value of this function.
4917 It is expected that the caller will complete the initialization of
4918 the newly created breakpoint struct as well as output any status
4919 information regarding the creation of a new breakpoint. In
4920 particular, set_raw_breakpoint does NOT set the breakpoint
4921 number! Care should be taken to not allow an error to occur
4922 prior to completing the initialization of the breakpoint. If this
4923 should happen, a bogus breakpoint will be left on the chain. */
4926 set_raw_breakpoint (struct gdbarch
*gdbarch
,
4927 struct symtab_and_line sal
, enum bptype bptype
)
4929 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
4930 CORE_ADDR adjusted_address
;
4931 struct gdbarch
*loc_gdbarch
;
4933 loc_gdbarch
= get_sal_arch (sal
);
4935 loc_gdbarch
= b
->gdbarch
;
4937 if (bptype
!= bp_catchpoint
)
4938 gdb_assert (sal
.pspace
!= NULL
);
4940 /* Adjust the breakpoint's address prior to allocating a location.
4941 Once we call allocate_bp_location(), that mostly uninitialized
4942 location will be placed on the location chain. Adjustment of the
4943 breakpoint may cause target_read_memory() to be called and we do
4944 not want its scan of the location chain to find a breakpoint and
4945 location that's only been partially initialized. */
4946 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
4948 b
->loc
= allocate_bp_location (b
);
4949 b
->loc
->gdbarch
= loc_gdbarch
;
4950 b
->loc
->requested_address
= sal
.pc
;
4951 b
->loc
->address
= adjusted_address
;
4952 b
->loc
->pspace
= sal
.pspace
;
4954 /* Store the program space that was used to set the breakpoint, for
4955 breakpoint resetting. */
4956 b
->pspace
= sal
.pspace
;
4958 if (sal
.symtab
== NULL
)
4959 b
->source_file
= NULL
;
4961 b
->source_file
= xstrdup (sal
.symtab
->filename
);
4962 b
->loc
->section
= sal
.section
;
4963 b
->line_number
= sal
.line
;
4965 set_breakpoint_location_function (b
->loc
);
4967 breakpoints_changed ();
4973 /* Note that the breakpoint object B describes a permanent breakpoint
4974 instruction, hard-wired into the inferior's code. */
4976 make_breakpoint_permanent (struct breakpoint
*b
)
4978 struct bp_location
*bl
;
4979 b
->enable_state
= bp_permanent
;
4981 /* By definition, permanent breakpoints are already present in the code.
4982 Mark all locations as inserted. For now, make_breakpoint_permanent
4983 is called in just one place, so it's hard to say if it's reasonable
4984 to have permanent breakpoint with multiple locations or not,
4985 but it's easy to implmement. */
4986 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4990 /* Call this routine when stepping and nexting to enable a breakpoint
4991 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4992 set_longjmp_resume_breakpoint() to figure out where we are going. */
4995 set_longjmp_breakpoint (int thread
)
4997 struct breakpoint
*b
, *temp
;
4999 /* To avoid having to rescan all objfile symbols at every step,
5000 we maintain a list of continually-inserted but always disabled
5001 longjmp "master" breakpoints. Here, we simply create momentary
5002 clones of those and enable them for the requested thread. */
5003 ALL_BREAKPOINTS_SAFE (b
, temp
)
5004 if (b
->pspace
== current_program_space
5005 && b
->type
== bp_longjmp_master
)
5007 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5008 clone
->type
= bp_longjmp
;
5009 clone
->thread
= thread
;
5013 /* Delete all longjmp breakpoints from THREAD. */
5015 delete_longjmp_breakpoint (int thread
)
5017 struct breakpoint
*b
, *temp
;
5019 ALL_BREAKPOINTS_SAFE (b
, temp
)
5020 if (b
->type
== bp_longjmp
)
5022 if (b
->thread
== thread
)
5023 delete_breakpoint (b
);
5028 enable_overlay_breakpoints (void)
5030 struct breakpoint
*b
;
5033 if (b
->type
== bp_overlay_event
)
5035 b
->enable_state
= bp_enabled
;
5036 update_global_location_list (1);
5037 overlay_events_enabled
= 1;
5042 disable_overlay_breakpoints (void)
5044 struct breakpoint
*b
;
5047 if (b
->type
== bp_overlay_event
)
5049 b
->enable_state
= bp_disabled
;
5050 update_global_location_list (0);
5051 overlay_events_enabled
= 0;
5056 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5058 struct breakpoint
*b
;
5060 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5062 b
->enable_state
= bp_enabled
;
5063 /* addr_string has to be used or breakpoint_re_set will delete me. */
5065 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5067 update_global_location_list_nothrow (1);
5073 remove_thread_event_breakpoints (void)
5075 struct breakpoint
*b
, *temp
;
5077 ALL_BREAKPOINTS_SAFE (b
, temp
)
5078 if (b
->type
== bp_thread_event
5079 && b
->loc
->pspace
== current_program_space
)
5080 delete_breakpoint (b
);
5083 struct captured_parse_breakpoint_args
5086 struct symtabs_and_lines
*sals_p
;
5087 char ***addr_string_p
;
5091 struct lang_and_radix
5097 /* Create a breakpoint for JIT code registration and unregistration. */
5100 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5102 struct breakpoint
*b
;
5104 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5105 update_global_location_list_nothrow (1);
5110 remove_solib_event_breakpoints (void)
5112 struct breakpoint
*b
, *temp
;
5114 ALL_BREAKPOINTS_SAFE (b
, temp
)
5115 if (b
->type
== bp_shlib_event
5116 && b
->loc
->pspace
== current_program_space
)
5117 delete_breakpoint (b
);
5121 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5123 struct breakpoint
*b
;
5125 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5126 update_global_location_list_nothrow (1);
5130 /* Disable any breakpoints that are on code in shared libraries. Only
5131 apply to enabled breakpoints, disabled ones can just stay disabled. */
5134 disable_breakpoints_in_shlibs (void)
5136 struct bp_location
*loc
, **locp_tmp
;
5138 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5140 struct breakpoint
*b
= loc
->owner
;
5141 /* We apply the check to all breakpoints, including disabled
5142 for those with loc->duplicate set. This is so that when breakpoint
5143 becomes enabled, or the duplicate is removed, gdb will try to insert
5144 all breakpoints. If we don't set shlib_disabled here, we'll try
5145 to insert those breakpoints and fail. */
5146 if (((b
->type
== bp_breakpoint
)
5147 || (b
->type
== bp_hardware_breakpoint
)
5148 || (b
->type
== bp_tracepoint
))
5149 && loc
->pspace
== current_program_space
5150 && !loc
->shlib_disabled
5152 && PC_SOLIB (loc
->address
)
5154 && solib_name_from_address (loc
->pspace
, loc
->address
)
5158 loc
->shlib_disabled
= 1;
5163 /* Disable any breakpoints that are in in an unloaded shared library. Only
5164 apply to enabled breakpoints, disabled ones can just stay disabled. */
5167 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5169 struct bp_location
*loc
, **locp_tmp
;
5170 int disabled_shlib_breaks
= 0;
5172 /* SunOS a.out shared libraries are always mapped, so do not
5173 disable breakpoints; they will only be reported as unloaded
5174 through clear_solib when GDB discards its shared library
5175 list. See clear_solib for more information. */
5176 if (exec_bfd
!= NULL
5177 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5180 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5182 struct breakpoint
*b
= loc
->owner
;
5183 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5184 || loc
->loc_type
== bp_loc_software_breakpoint
)
5185 && solib
->pspace
== loc
->pspace
5186 && !loc
->shlib_disabled
5187 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
5188 && solib_contains_address_p (solib
, loc
->address
))
5190 loc
->shlib_disabled
= 1;
5191 /* At this point, we cannot rely on remove_breakpoint
5192 succeeding so we must mark the breakpoint as not inserted
5193 to prevent future errors occurring in remove_breakpoints. */
5195 if (!disabled_shlib_breaks
)
5197 target_terminal_ours_for_output ();
5198 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5201 disabled_shlib_breaks
= 1;
5206 /* FORK & VFORK catchpoints. */
5208 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5211 insert_catch_fork (struct breakpoint
*b
)
5213 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5216 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5219 remove_catch_fork (struct breakpoint
*b
)
5221 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5224 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5228 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5230 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5233 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5235 static enum print_stop_action
5236 print_it_catch_fork (struct breakpoint
*b
)
5238 annotate_catchpoint (b
->number
);
5239 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5240 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5241 return PRINT_SRC_AND_LOC
;
5244 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5247 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5249 struct value_print_options opts
;
5251 get_user_print_options (&opts
);
5253 /* Field 4, the address, is omitted (which makes the columns
5254 not line up too nicely with the headers, but the effect
5255 is relatively readable). */
5256 if (opts
.addressprint
)
5257 ui_out_field_skip (uiout
, "addr");
5259 ui_out_text (uiout
, "fork");
5260 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5262 ui_out_text (uiout
, ", process ");
5263 ui_out_field_int (uiout
, "what",
5264 ptid_get_pid (b
->forked_inferior_pid
));
5265 ui_out_spaces (uiout
, 1);
5269 /* Implement the "print_mention" breakpoint_ops method for fork
5273 print_mention_catch_fork (struct breakpoint
*b
)
5275 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5278 /* The breakpoint_ops structure to be used in fork catchpoints. */
5280 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5284 breakpoint_hit_catch_fork
,
5285 print_it_catch_fork
,
5286 print_one_catch_fork
,
5287 print_mention_catch_fork
5290 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5293 insert_catch_vfork (struct breakpoint
*b
)
5295 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5298 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5301 remove_catch_vfork (struct breakpoint
*b
)
5303 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5306 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5310 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5312 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5315 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5317 static enum print_stop_action
5318 print_it_catch_vfork (struct breakpoint
*b
)
5320 annotate_catchpoint (b
->number
);
5321 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5322 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5323 return PRINT_SRC_AND_LOC
;
5326 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5329 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5331 struct value_print_options opts
;
5333 get_user_print_options (&opts
);
5334 /* Field 4, the address, is omitted (which makes the columns
5335 not line up too nicely with the headers, but the effect
5336 is relatively readable). */
5337 if (opts
.addressprint
)
5338 ui_out_field_skip (uiout
, "addr");
5340 ui_out_text (uiout
, "vfork");
5341 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5343 ui_out_text (uiout
, ", process ");
5344 ui_out_field_int (uiout
, "what",
5345 ptid_get_pid (b
->forked_inferior_pid
));
5346 ui_out_spaces (uiout
, 1);
5350 /* Implement the "print_mention" breakpoint_ops method for vfork
5354 print_mention_catch_vfork (struct breakpoint
*b
)
5356 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5359 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5361 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5365 breakpoint_hit_catch_vfork
,
5366 print_it_catch_vfork
,
5367 print_one_catch_vfork
,
5368 print_mention_catch_vfork
5371 /* Implement the "insert" breakpoint_ops method for syscall
5375 insert_catch_syscall (struct breakpoint
*b
)
5377 struct inferior
*inf
= current_inferior ();
5379 ++inf
->total_syscalls_count
;
5380 if (!b
->syscalls_to_be_caught
)
5381 ++inf
->any_syscall_count
;
5386 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5390 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5392 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5393 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5395 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5396 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5398 memset ((void *) vec_addr
, 0,
5399 (iter
+ 1 - old_size
) * sizeof (int));
5401 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5402 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5406 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5407 inf
->total_syscalls_count
!= 0,
5408 inf
->any_syscall_count
,
5409 VEC_length (int, inf
->syscalls_counts
),
5410 VEC_address (int, inf
->syscalls_counts
));
5413 /* Implement the "remove" breakpoint_ops method for syscall
5417 remove_catch_syscall (struct breakpoint
*b
)
5419 struct inferior
*inf
= current_inferior ();
5421 --inf
->total_syscalls_count
;
5422 if (!b
->syscalls_to_be_caught
)
5423 --inf
->any_syscall_count
;
5428 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5432 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5433 /* Shouldn't happen. */
5435 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5436 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5440 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5441 inf
->total_syscalls_count
!= 0,
5442 inf
->any_syscall_count
,
5443 VEC_length (int, inf
->syscalls_counts
),
5444 VEC_address (int, inf
->syscalls_counts
));
5447 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5451 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5453 /* We must check if we are catching specific syscalls in this breakpoint.
5454 If we are, then we must guarantee that the called syscall is the same
5455 syscall we are catching. */
5456 int syscall_number
= 0;
5458 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5461 /* Now, checking if the syscall is the same. */
5462 if (b
->syscalls_to_be_caught
)
5466 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5468 if (syscall_number
== iter
)
5478 /* Implement the "print_it" breakpoint_ops method for syscall
5481 static enum print_stop_action
5482 print_it_catch_syscall (struct breakpoint
*b
)
5484 /* These are needed because we want to know in which state a
5485 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
5486 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
5487 must print "called syscall" or "returned from syscall". */
5489 struct target_waitstatus last
;
5491 struct cleanup
*old_chain
;
5494 get_last_target_status (&ptid
, &last
);
5496 get_syscall_by_number (last
.value
.syscall_number
, &s
);
5498 annotate_catchpoint (b
->number
);
5501 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
5503 syscall_id
= xstrprintf ("'%s'", s
.name
);
5505 old_chain
= make_cleanup (xfree
, syscall_id
);
5507 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
5508 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
5509 b
->number
, syscall_id
);
5510 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
5511 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
5512 b
->number
, syscall_id
);
5514 do_cleanups (old_chain
);
5516 return PRINT_SRC_AND_LOC
;
5519 /* Implement the "print_one" breakpoint_ops method for syscall
5523 print_one_catch_syscall (struct breakpoint
*b
,
5524 struct bp_location
**last_loc
)
5526 struct value_print_options opts
;
5528 get_user_print_options (&opts
);
5529 /* Field 4, the address, is omitted (which makes the columns
5530 not line up too nicely with the headers, but the effect
5531 is relatively readable). */
5532 if (opts
.addressprint
)
5533 ui_out_field_skip (uiout
, "addr");
5536 if (b
->syscalls_to_be_caught
5537 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5538 ui_out_text (uiout
, "syscalls \"");
5540 ui_out_text (uiout
, "syscall \"");
5542 if (b
->syscalls_to_be_caught
)
5545 char *text
= xstrprintf ("%s", "");
5547 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5552 get_syscall_by_number (iter
, &s
);
5555 text
= xstrprintf ("%s%s, ", text
, s
.name
);
5557 text
= xstrprintf ("%s%d, ", text
, iter
);
5559 /* We have to xfree the last 'text' (now stored at 'x')
5560 because xstrprintf dinamically allocates new space for it
5564 /* Remove the last comma. */
5565 text
[strlen (text
) - 2] = '\0';
5566 ui_out_field_string (uiout
, "what", text
);
5569 ui_out_field_string (uiout
, "what", "<any syscall>");
5570 ui_out_text (uiout
, "\" ");
5573 /* Implement the "print_mention" breakpoint_ops method for syscall
5577 print_mention_catch_syscall (struct breakpoint
*b
)
5579 if (b
->syscalls_to_be_caught
)
5583 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5584 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
5586 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
5589 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5593 get_syscall_by_number (iter
, &s
);
5596 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
5598 printf_filtered (" %d", s
.number
);
5600 printf_filtered (")");
5603 printf_filtered (_("Catchpoint %d (any syscall)"),
5607 /* The breakpoint_ops structure to be used in syscall catchpoints. */
5609 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
5611 insert_catch_syscall
,
5612 remove_catch_syscall
,
5613 breakpoint_hit_catch_syscall
,
5614 print_it_catch_syscall
,
5615 print_one_catch_syscall
,
5616 print_mention_catch_syscall
5619 /* Returns non-zero if 'b' is a syscall catchpoint. */
5622 syscall_catchpoint_p (struct breakpoint
*b
)
5624 return (b
->ops
== &catch_syscall_breakpoint_ops
);
5627 /* Create a new breakpoint of the bp_catchpoint kind and return it,
5628 but does NOT mention it nor update the global location list.
5629 This is useful if you need to fill more fields in the
5630 struct breakpoint before calling mention.
5632 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5633 If COND_STRING is not NULL, then store it in the breakpoint.
5634 OPS, if not NULL, is the breakpoint_ops structure associated
5635 to the catchpoint. */
5637 static struct breakpoint
*
5638 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
5640 struct breakpoint_ops
*ops
)
5642 struct symtab_and_line sal
;
5643 struct breakpoint
*b
;
5646 sal
.pspace
= current_program_space
;
5648 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
5649 set_breakpoint_count (breakpoint_count
+ 1);
5650 b
->number
= breakpoint_count
;
5652 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
5654 b
->addr_string
= NULL
;
5655 b
->enable_state
= bp_enabled
;
5656 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5662 /* Create a new breakpoint of the bp_catchpoint kind and return it.
5664 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5665 If COND_STRING is not NULL, then store it in the breakpoint.
5666 OPS, if not NULL, is the breakpoint_ops structure associated
5667 to the catchpoint. */
5669 static struct breakpoint
*
5670 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
5671 char *cond_string
, struct breakpoint_ops
*ops
)
5673 struct breakpoint
*b
=
5674 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
5677 update_global_location_list (1);
5683 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
5684 int tempflag
, char *cond_string
,
5685 struct breakpoint_ops
*ops
)
5687 struct breakpoint
*b
5688 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
5690 /* FIXME: We should put this information in a breakpoint private data
5692 b
->forked_inferior_pid
= null_ptid
;
5695 /* Exec catchpoints. */
5698 insert_catch_exec (struct breakpoint
*b
)
5700 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
5704 remove_catch_exec (struct breakpoint
*b
)
5706 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
5710 breakpoint_hit_catch_exec (struct breakpoint
*b
)
5712 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
5715 static enum print_stop_action
5716 print_it_catch_exec (struct breakpoint
*b
)
5718 annotate_catchpoint (b
->number
);
5719 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
5721 return PRINT_SRC_AND_LOC
;
5725 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
5727 struct value_print_options opts
;
5729 get_user_print_options (&opts
);
5731 /* Field 4, the address, is omitted (which makes the columns
5732 not line up too nicely with the headers, but the effect
5733 is relatively readable). */
5734 if (opts
.addressprint
)
5735 ui_out_field_skip (uiout
, "addr");
5737 ui_out_text (uiout
, "exec");
5738 if (b
->exec_pathname
!= NULL
)
5740 ui_out_text (uiout
, ", program \"");
5741 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
5742 ui_out_text (uiout
, "\" ");
5747 print_mention_catch_exec (struct breakpoint
*b
)
5749 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
5752 static struct breakpoint_ops catch_exec_breakpoint_ops
=
5756 breakpoint_hit_catch_exec
,
5757 print_it_catch_exec
,
5758 print_one_catch_exec
,
5759 print_mention_catch_exec
5763 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
5764 struct breakpoint_ops
*ops
)
5766 struct gdbarch
*gdbarch
= get_current_arch ();
5767 struct breakpoint
*b
=
5768 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
5770 b
->syscalls_to_be_caught
= filter
;
5772 /* Now, we have to mention the breakpoint and update the global
5775 update_global_location_list (1);
5779 hw_breakpoint_used_count (void)
5781 struct breakpoint
*b
;
5786 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
5794 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
5796 struct breakpoint
*b
;
5799 *other_type_used
= 0;
5802 if (breakpoint_enabled (b
))
5804 if (b
->type
== type
)
5806 else if ((b
->type
== bp_hardware_watchpoint
5807 || b
->type
== bp_read_watchpoint
5808 || b
->type
== bp_access_watchpoint
))
5809 *other_type_used
= 1;
5816 disable_watchpoints_before_interactive_call_start (void)
5818 struct breakpoint
*b
;
5822 if (((b
->type
== bp_watchpoint
)
5823 || (b
->type
== bp_hardware_watchpoint
)
5824 || (b
->type
== bp_read_watchpoint
)
5825 || (b
->type
== bp_access_watchpoint
))
5826 && breakpoint_enabled (b
))
5828 b
->enable_state
= bp_call_disabled
;
5829 update_global_location_list (0);
5835 enable_watchpoints_after_interactive_call_stop (void)
5837 struct breakpoint
*b
;
5841 if (((b
->type
== bp_watchpoint
)
5842 || (b
->type
== bp_hardware_watchpoint
)
5843 || (b
->type
== bp_read_watchpoint
)
5844 || (b
->type
== bp_access_watchpoint
))
5845 && (b
->enable_state
== bp_call_disabled
))
5847 b
->enable_state
= bp_enabled
;
5848 update_global_location_list (1);
5854 disable_breakpoints_before_startup (void)
5856 struct breakpoint
*b
;
5861 if (b
->pspace
!= current_program_space
)
5864 if ((b
->type
== bp_breakpoint
5865 || b
->type
== bp_hardware_breakpoint
)
5866 && breakpoint_enabled (b
))
5868 b
->enable_state
= bp_startup_disabled
;
5874 update_global_location_list (0);
5876 current_program_space
->executing_startup
= 1;
5880 enable_breakpoints_after_startup (void)
5882 struct breakpoint
*b
;
5885 current_program_space
->executing_startup
= 0;
5889 if (b
->pspace
!= current_program_space
)
5892 if ((b
->type
== bp_breakpoint
5893 || b
->type
== bp_hardware_breakpoint
)
5894 && b
->enable_state
== bp_startup_disabled
)
5896 b
->enable_state
= bp_enabled
;
5902 breakpoint_re_set ();
5906 /* Set a breakpoint that will evaporate an end of command
5907 at address specified by SAL.
5908 Restrict it to frame FRAME if FRAME is nonzero. */
5911 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
5912 struct frame_id frame_id
, enum bptype type
)
5914 struct breakpoint
*b
;
5916 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5918 gdb_assert (!frame_id_inlined_p (frame_id
));
5920 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5921 b
->enable_state
= bp_enabled
;
5922 b
->disposition
= disp_donttouch
;
5923 b
->frame_id
= frame_id
;
5925 /* If we're debugging a multi-threaded program, then we
5926 want momentary breakpoints to be active in only a
5927 single thread of control. */
5928 if (in_thread_list (inferior_ptid
))
5929 b
->thread
= pid_to_thread_id (inferior_ptid
);
5931 update_global_location_list_nothrow (1);
5936 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5940 clone_momentary_breakpoint (struct breakpoint
*orig
)
5942 struct breakpoint
*copy
;
5944 /* If there's nothing to clone, then return nothing. */
5948 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
5949 copy
->loc
= allocate_bp_location (copy
);
5950 set_breakpoint_location_function (copy
->loc
);
5952 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
5953 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
5954 copy
->loc
->address
= orig
->loc
->address
;
5955 copy
->loc
->section
= orig
->loc
->section
;
5956 copy
->loc
->pspace
= orig
->loc
->pspace
;
5958 if (orig
->source_file
== NULL
)
5959 copy
->source_file
= NULL
;
5961 copy
->source_file
= xstrdup (orig
->source_file
);
5963 copy
->line_number
= orig
->line_number
;
5964 copy
->frame_id
= orig
->frame_id
;
5965 copy
->thread
= orig
->thread
;
5966 copy
->pspace
= orig
->pspace
;
5968 copy
->enable_state
= bp_enabled
;
5969 copy
->disposition
= disp_donttouch
;
5970 copy
->number
= internal_breakpoint_number
--;
5972 update_global_location_list_nothrow (0);
5977 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
5980 struct symtab_and_line sal
;
5982 sal
= find_pc_line (pc
, 0);
5984 sal
.section
= find_pc_overlay (pc
);
5985 sal
.explicit_pc
= 1;
5987 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
5991 /* Tell the user we have just set a breakpoint B. */
5994 mention (struct breakpoint
*b
)
5997 struct cleanup
*ui_out_chain
;
5998 struct value_print_options opts
;
6000 get_user_print_options (&opts
);
6002 /* FIXME: This is misplaced; mention() is called by things (like
6003 hitting a watchpoint) other than breakpoint creation. It should
6004 be possible to clean this up and at the same time replace the
6005 random calls to breakpoint_changed with this hook. */
6006 observer_notify_breakpoint_created (b
->number
);
6008 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6009 b
->ops
->print_mention (b
);
6014 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6017 ui_out_text (uiout
, "Watchpoint ");
6018 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6019 ui_out_field_int (uiout
, "number", b
->number
);
6020 ui_out_text (uiout
, ": ");
6021 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6022 do_cleanups (ui_out_chain
);
6024 case bp_hardware_watchpoint
:
6025 ui_out_text (uiout
, "Hardware watchpoint ");
6026 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6027 ui_out_field_int (uiout
, "number", b
->number
);
6028 ui_out_text (uiout
, ": ");
6029 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6030 do_cleanups (ui_out_chain
);
6032 case bp_read_watchpoint
:
6033 ui_out_text (uiout
, "Hardware read watchpoint ");
6034 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6035 ui_out_field_int (uiout
, "number", b
->number
);
6036 ui_out_text (uiout
, ": ");
6037 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6038 do_cleanups (ui_out_chain
);
6040 case bp_access_watchpoint
:
6041 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6042 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6043 ui_out_field_int (uiout
, "number", b
->number
);
6044 ui_out_text (uiout
, ": ");
6045 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6046 do_cleanups (ui_out_chain
);
6049 if (ui_out_is_mi_like_p (uiout
))
6054 if (b
->disposition
== disp_del
)
6055 printf_filtered (_("Temporary breakpoint"));
6057 printf_filtered (_("Breakpoint"));
6058 printf_filtered (_(" %d"), b
->number
);
6061 case bp_hardware_breakpoint
:
6062 if (ui_out_is_mi_like_p (uiout
))
6067 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6071 if (ui_out_is_mi_like_p (uiout
))
6076 printf_filtered (_("Tracepoint"));
6077 printf_filtered (_(" %d"), b
->number
);
6084 case bp_longjmp_resume
:
6085 case bp_step_resume
:
6087 case bp_watchpoint_scope
:
6088 case bp_shlib_event
:
6089 case bp_thread_event
:
6090 case bp_overlay_event
:
6092 case bp_longjmp_master
:
6098 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6102 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6106 if (opts
.addressprint
|| b
->source_file
== NULL
)
6108 printf_filtered (" at ");
6109 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6113 printf_filtered (": file %s, line %d.",
6114 b
->source_file
, b
->line_number
);
6118 struct bp_location
*loc
= b
->loc
;
6120 for (; loc
; loc
= loc
->next
)
6122 printf_filtered (" (%d locations)", n
);
6127 if (ui_out_is_mi_like_p (uiout
))
6129 printf_filtered ("\n");
6133 static struct bp_location
*
6134 add_location_to_breakpoint (struct breakpoint
*b
,
6135 const struct symtab_and_line
*sal
)
6137 struct bp_location
*loc
, **tmp
;
6139 loc
= allocate_bp_location (b
);
6140 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6143 loc
->gdbarch
= get_sal_arch (*sal
);
6145 loc
->gdbarch
= b
->gdbarch
;
6146 loc
->requested_address
= sal
->pc
;
6147 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6148 loc
->requested_address
, b
->type
);
6149 loc
->pspace
= sal
->pspace
;
6150 gdb_assert (loc
->pspace
!= NULL
);
6151 loc
->section
= sal
->section
;
6153 set_breakpoint_location_function (loc
);
6158 /* Return 1 if LOC is pointing to a permanent breakpoint,
6159 return 0 otherwise. */
6162 bp_loc_is_permanent (struct bp_location
*loc
)
6166 const gdb_byte
*brk
;
6167 gdb_byte
*target_mem
;
6168 struct cleanup
*cleanup
;
6171 gdb_assert (loc
!= NULL
);
6173 addr
= loc
->address
;
6174 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6176 /* Software breakpoints unsupported? */
6180 target_mem
= alloca (len
);
6182 /* Enable the automatic memory restoration from breakpoints while
6183 we read the memory. Otherwise we could say about our temporary
6184 breakpoints they are permanent. */
6185 cleanup
= save_current_space_and_thread ();
6187 switch_to_program_space_and_thread (loc
->pspace
);
6188 make_show_memory_breakpoints_cleanup (0);
6190 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6191 && memcmp (target_mem
, brk
, len
) == 0)
6194 do_cleanups (cleanup
);
6201 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6202 as textual description of the location, and COND_STRING
6203 as condition expression. */
6206 create_breakpoint (struct gdbarch
*gdbarch
,
6207 struct symtabs_and_lines sals
, char *addr_string
,
6209 enum bptype type
, enum bpdisp disposition
,
6210 int thread
, int task
, int ignore_count
,
6211 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6213 struct breakpoint
*b
= NULL
;
6216 if (type
== bp_hardware_breakpoint
)
6218 int i
= hw_breakpoint_used_count ();
6219 int target_resources_ok
=
6220 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6222 if (target_resources_ok
== 0)
6223 error (_("No hardware breakpoint support in the target."));
6224 else if (target_resources_ok
< 0)
6225 error (_("Hardware breakpoints used exceeds limit."));
6228 gdb_assert (sals
.nelts
> 0);
6230 for (i
= 0; i
< sals
.nelts
; ++i
)
6232 struct symtab_and_line sal
= sals
.sals
[i
];
6233 struct bp_location
*loc
;
6237 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6239 loc_gdbarch
= gdbarch
;
6241 describe_other_breakpoints (loc_gdbarch
,
6242 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6247 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6248 set_breakpoint_count (breakpoint_count
+ 1);
6249 b
->number
= breakpoint_count
;
6253 b
->cond_string
= cond_string
;
6254 b
->ignore_count
= ignore_count
;
6255 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6256 b
->disposition
= disposition
;
6258 b
->pspace
= sals
.sals
[0].pspace
;
6260 if (enabled
&& b
->pspace
->executing_startup
6261 && (b
->type
== bp_breakpoint
6262 || b
->type
== bp_hardware_breakpoint
))
6263 b
->enable_state
= bp_startup_disabled
;
6269 loc
= add_location_to_breakpoint (b
, &sal
);
6272 if (bp_loc_is_permanent (loc
))
6273 make_breakpoint_permanent (b
);
6277 char *arg
= b
->cond_string
;
6278 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6280 error (_("Garbage %s follows condition"), arg
);
6285 b
->addr_string
= addr_string
;
6287 /* addr_string has to be used or breakpoint_re_set will delete
6290 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6296 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6297 elements to fill the void space. */
6299 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6301 int i
= index_to_remove
+1;
6302 int last_index
= sal
->nelts
-1;
6304 for (;i
<= last_index
; ++i
)
6305 sal
->sals
[i
-1] = sal
->sals
[i
];
6310 /* If appropriate, obtains all sals that correspond to the same file
6311 and line as SAL, in all program spaces. Users debugging with IDEs,
6312 will want to set a breakpoint at foo.c:line, and not really care
6313 about program spaces. This is done only if SAL does not have
6314 explicit PC and has line and file information. If we got just a
6315 single expanded sal, return the original.
6317 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6318 which the name of enclosing function is different from SAL. This
6319 makes sure that if we have breakpoint originally set in template
6320 instantiation, say foo<int>(), we won't expand SAL to locations at
6321 the same line in all existing instantiations of 'foo'. */
6323 static struct symtabs_and_lines
6324 expand_line_sal_maybe (struct symtab_and_line sal
)
6326 struct symtabs_and_lines expanded
;
6327 CORE_ADDR original_pc
= sal
.pc
;
6328 char *original_function
= NULL
;
6331 struct cleanup
*old_chain
;
6333 /* If we have explicit pc, don't expand.
6334 If we have no line number, we can't expand. */
6335 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6338 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6339 expanded
.sals
[0] = sal
;
6345 old_chain
= save_current_space_and_thread ();
6347 switch_to_program_space_and_thread (sal
.pspace
);
6349 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6351 /* Note that expand_line_sal visits *all* program spaces. */
6352 expanded
= expand_line_sal (sal
);
6354 if (expanded
.nelts
== 1)
6356 /* We had one sal, we got one sal. Return that sal, adjusting it
6357 past the function prologue if necessary. */
6358 xfree (expanded
.sals
);
6360 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6361 sal
.pc
= original_pc
;
6362 expanded
.sals
[0] = sal
;
6363 skip_prologue_sal (&expanded
.sals
[0]);
6364 do_cleanups (old_chain
);
6368 if (!sal
.explicit_line
)
6370 CORE_ADDR func_addr
, func_end
;
6371 for (i
= 0; i
< expanded
.nelts
; ++i
)
6373 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6374 char *this_function
;
6376 /* We need to switch threads as well since we're about to
6378 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6380 if (find_pc_partial_function (pc
, &this_function
,
6381 &func_addr
, &func_end
))
6384 && strcmp (this_function
, original_function
) != 0)
6386 remove_sal (&expanded
, i
);
6389 else if (func_addr
== pc
)
6391 /* We're at beginning of a function, and should
6393 struct symbol
*sym
= find_pc_function (pc
);
6395 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
6398 /* Since find_pc_partial_function returned true,
6399 we should really always find the section here. */
6400 struct obj_section
*section
= find_pc_section (pc
);
6403 struct gdbarch
*gdbarch
6404 = get_objfile_arch (section
->objfile
);
6406 = gdbarch_skip_prologue (gdbarch
, pc
);
6415 for (i
= 0; i
< expanded
.nelts
; ++i
)
6417 /* If this SAL corresponds to a breakpoint inserted using a
6418 line number, then skip the function prologue if necessary. */
6419 skip_prologue_sal (&expanded
.sals
[i
]);
6423 do_cleanups (old_chain
);
6425 if (expanded
.nelts
<= 1)
6427 /* This is un ugly workaround. If we get zero
6428 expanded sals then something is really wrong.
6429 Fix that by returnign the original sal. */
6430 xfree (expanded
.sals
);
6432 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6433 sal
.pc
= original_pc
;
6434 expanded
.sals
[0] = sal
;
6441 for (i
= 0; i
< expanded
.nelts
; ++i
)
6442 if (expanded
.sals
[i
].pc
== original_pc
)
6453 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6454 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6455 value. COND_STRING, if not NULL, specified the condition to be
6456 used for all breakpoints. Essentially the only case where
6457 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6458 function. In that case, it's still not possible to specify
6459 separate conditions for different overloaded functions, so
6460 we take just a single condition string.
6462 NOTE: If the function succeeds, the caller is expected to cleanup
6463 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6464 array contents). If the function fails (error() is called), the
6465 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6466 COND and SALS arrays and each of those arrays contents. */
6469 create_breakpoints (struct gdbarch
*gdbarch
,
6470 struct symtabs_and_lines sals
, char **addr_string
,
6472 enum bptype type
, enum bpdisp disposition
,
6473 int thread
, int task
, int ignore_count
,
6474 struct breakpoint_ops
*ops
, int from_tty
,
6478 for (i
= 0; i
< sals
.nelts
; ++i
)
6480 struct symtabs_and_lines expanded
=
6481 expand_line_sal_maybe (sals
.sals
[i
]);
6483 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
6484 cond_string
, type
, disposition
,
6485 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6489 /* Parse ARG which is assumed to be a SAL specification possibly
6490 followed by conditionals. On return, SALS contains an array of SAL
6491 addresses found. ADDR_STRING contains a vector of (canonical)
6492 address strings. ARG points to the end of the SAL. */
6495 parse_breakpoint_sals (char **address
,
6496 struct symtabs_and_lines
*sals
,
6497 char ***addr_string
,
6500 char *addr_start
= *address
;
6501 *addr_string
= NULL
;
6502 /* If no arg given, or if first arg is 'if ', use the default
6504 if ((*address
) == NULL
6505 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
6507 if (default_breakpoint_valid
)
6509 struct symtab_and_line sal
;
6510 init_sal (&sal
); /* initialize to zeroes */
6511 sals
->sals
= (struct symtab_and_line
*)
6512 xmalloc (sizeof (struct symtab_and_line
));
6513 sal
.pc
= default_breakpoint_address
;
6514 sal
.line
= default_breakpoint_line
;
6515 sal
.symtab
= default_breakpoint_symtab
;
6516 sal
.pspace
= default_breakpoint_pspace
;
6517 sal
.section
= find_pc_overlay (sal
.pc
);
6519 /* "break" without arguments is equivalent to "break *PC" where PC is
6520 the default_breakpoint_address. So make sure to set
6521 sal.explicit_pc to prevent GDB from trying to expand the list of
6522 sals to include all other instances with the same symtab and line.
6524 sal
.explicit_pc
= 1;
6526 sals
->sals
[0] = sal
;
6530 error (_("No default breakpoint address now."));
6534 /* Force almost all breakpoints to be in terms of the
6535 current_source_symtab (which is decode_line_1's default). This
6536 should produce the results we want almost all of the time while
6537 leaving default_breakpoint_* alone.
6538 ObjC: However, don't match an Objective-C method name which
6539 may have a '+' or '-' succeeded by a '[' */
6541 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
6543 if (default_breakpoint_valid
6545 || ((strchr ("+-", (*address
)[0]) != NULL
)
6546 && ((*address
)[1] != '['))))
6547 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
6548 default_breakpoint_line
, addr_string
,
6551 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
6552 addr_string
, not_found_ptr
);
6554 /* For any SAL that didn't have a canonical string, fill one in. */
6555 if (sals
->nelts
> 0 && *addr_string
== NULL
)
6556 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
6557 if (addr_start
!= (*address
))
6560 for (i
= 0; i
< sals
->nelts
; i
++)
6562 /* Add the string if not present. */
6563 if ((*addr_string
)[i
] == NULL
)
6564 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
6570 /* Convert each SAL into a real PC. Verify that the PC can be
6571 inserted as a breakpoint. If it can't throw an error. */
6574 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
6578 for (i
= 0; i
< sals
->nelts
; i
++)
6579 resolve_sal_pc (&sals
->sals
[i
]);
6583 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
6585 struct captured_parse_breakpoint_args
*args
= data
;
6587 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
6588 args
->not_found_ptr
);
6591 /* Given TOK, a string specification of condition and thread, as
6592 accepted by the 'break' command, extract the condition
6593 string and thread number and set *COND_STRING and *THREAD.
6594 PC identifies the context at which the condition should be parsed.
6595 If no condition is found, *COND_STRING is set to NULL.
6596 If no thread is found, *THREAD is set to -1. */
6598 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
6599 char **cond_string
, int *thread
, int *task
)
6601 *cond_string
= NULL
;
6607 char *cond_start
= NULL
;
6608 char *cond_end
= NULL
;
6609 while (*tok
== ' ' || *tok
== '\t')
6614 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6617 toklen
= end_tok
- tok
;
6619 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6621 struct expression
*expr
;
6623 tok
= cond_start
= end_tok
+ 1;
6624 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
6627 *cond_string
= savestring (cond_start
,
6628 cond_end
- cond_start
);
6630 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6636 *thread
= strtol (tok
, &tok
, 0);
6638 error (_("Junk after thread keyword."));
6639 if (!valid_thread_id (*thread
))
6640 error (_("Unknown thread %d."), *thread
);
6642 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
6648 *task
= strtol (tok
, &tok
, 0);
6650 error (_("Junk after task keyword."));
6651 if (!valid_task_id (*task
))
6652 error (_("Unknown task %d."), *task
);
6655 error (_("Junk at end of arguments."));
6659 /* Set a breakpoint. This function is shared between
6660 CLI and MI functions for setting a breakpoint.
6661 This function has two major modes of operations,
6662 selected by the PARSE_CONDITION_AND_THREAD parameter.
6663 If non-zero, the function will parse arg, extracting
6664 breakpoint location, address and thread. Otherwise,
6665 ARG is just the location of breakpoint, with condition
6666 and thread specified by the COND_STRING and THREAD
6670 break_command_really (struct gdbarch
*gdbarch
,
6671 char *arg
, char *cond_string
, int thread
,
6672 int parse_condition_and_thread
,
6673 int tempflag
, int hardwareflag
, int traceflag
,
6675 enum auto_boolean pending_break_support
,
6676 struct breakpoint_ops
*ops
,
6680 struct gdb_exception e
;
6681 struct symtabs_and_lines sals
;
6682 struct symtab_and_line pending_sal
;
6685 char *addr_start
= arg
;
6687 struct cleanup
*old_chain
;
6688 struct cleanup
*bkpt_chain
= NULL
;
6689 struct captured_parse_breakpoint_args parse_args
;
6693 enum bptype type_wanted
;
6700 parse_args
.arg_p
= &arg
;
6701 parse_args
.sals_p
= &sals
;
6702 parse_args
.addr_string_p
= &addr_string
;
6703 parse_args
.not_found_ptr
= ¬_found
;
6705 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
6706 &parse_args
, RETURN_MASK_ALL
);
6708 /* If caller is interested in rc value from parse, set value. */
6712 throw_exception (e
);
6716 case NOT_FOUND_ERROR
:
6718 /* If pending breakpoint support is turned off, throw
6721 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
6722 throw_exception (e
);
6724 exception_print (gdb_stderr
, e
);
6726 /* If pending breakpoint support is auto query and the user
6727 selects no, then simply return the error code. */
6728 if (pending_break_support
== AUTO_BOOLEAN_AUTO
6729 && !nquery ("Make breakpoint pending on future shared library load? "))
6732 /* At this point, either the user was queried about setting
6733 a pending breakpoint and selected yes, or pending
6734 breakpoint behavior is on and thus a pending breakpoint
6735 is defaulted on behalf of the user. */
6736 copy_arg
= xstrdup (addr_start
);
6737 addr_string
= ©_arg
;
6739 sals
.sals
= &pending_sal
;
6744 throw_exception (e
);
6751 /* Create a chain of things that always need to be cleaned up. */
6752 old_chain
= make_cleanup (null_cleanup
, 0);
6756 /* Make sure that all storage allocated to SALS gets freed. */
6757 make_cleanup (xfree
, sals
.sals
);
6759 /* Cleanup the addr_string array but not its contents. */
6760 make_cleanup (xfree
, addr_string
);
6763 /* ----------------------------- SNIP -----------------------------
6764 Anything added to the cleanup chain beyond this point is assumed
6765 to be part of a breakpoint. If the breakpoint create succeeds
6766 then the memory is not reclaimed. */
6767 bkpt_chain
= make_cleanup (null_cleanup
, 0);
6769 /* Mark the contents of the addr_string for cleanup. These go on
6770 the bkpt_chain and only occur if the breakpoint create fails. */
6771 for (i
= 0; i
< sals
.nelts
; i
++)
6773 if (addr_string
[i
] != NULL
)
6774 make_cleanup (xfree
, addr_string
[i
]);
6777 /* Resolve all line numbers to PC's and verify that the addresses
6778 are ok for the target. */
6780 breakpoint_sals_to_pc (&sals
, addr_start
);
6782 type_wanted
= (traceflag
6784 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
6786 /* Verify that condition can be parsed, before setting any
6787 breakpoints. Allocate a separate condition expression for each
6791 if (parse_condition_and_thread
)
6793 /* Here we only parse 'arg' to separate condition
6794 from thread number, so parsing in context of first
6795 sal is OK. When setting the breakpoint we'll
6796 re-parse it in context of each sal. */
6799 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
6802 make_cleanup (xfree
, cond_string
);
6806 /* Create a private copy of condition string. */
6809 cond_string
= xstrdup (cond_string
);
6810 make_cleanup (xfree
, cond_string
);
6813 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
6814 tempflag
? disp_del
: disp_donttouch
,
6815 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6819 struct symtab_and_line sal
= {0};
6820 struct breakpoint
*b
;
6822 make_cleanup (xfree
, copy_arg
);
6824 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
6825 set_breakpoint_count (breakpoint_count
+ 1);
6826 b
->number
= breakpoint_count
;
6828 b
->addr_string
= addr_string
[0];
6829 b
->cond_string
= NULL
;
6830 b
->ignore_count
= ignore_count
;
6831 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6832 b
->condition_not_parsed
= 1;
6834 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6835 b
->pspace
= current_program_space
;
6837 if (enabled
&& b
->pspace
->executing_startup
6838 && (b
->type
== bp_breakpoint
6839 || b
->type
== bp_hardware_breakpoint
))
6840 b
->enable_state
= bp_startup_disabled
;
6846 warning (_("Multiple breakpoints were set.\n"
6847 "Use the \"delete\" command to delete unwanted breakpoints."));
6848 /* That's it. Discard the cleanups for data inserted into the
6850 discard_cleanups (bkpt_chain
);
6851 /* But cleanup everything else. */
6852 do_cleanups (old_chain
);
6854 /* error call may happen here - have BKPT_CHAIN already discarded. */
6855 update_global_location_list (1);
6858 /* Set a breakpoint.
6859 ARG is a string describing breakpoint address,
6860 condition, and thread.
6861 FLAG specifies if a breakpoint is hardware on,
6862 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6866 break_command_1 (char *arg
, int flag
, int from_tty
)
6868 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
6869 int tempflag
= flag
& BP_TEMPFLAG
;
6871 break_command_really (get_current_arch (),
6873 NULL
, 0, 1 /* parse arg */,
6874 tempflag
, hardwareflag
, 0 /* traceflag */,
6875 0 /* Ignore count */,
6876 pending_break_support
,
6877 NULL
/* breakpoint_ops */,
6884 set_breakpoint (struct gdbarch
*gdbarch
,
6885 char *address
, char *condition
,
6886 int hardwareflag
, int tempflag
,
6887 int thread
, int ignore_count
,
6888 int pending
, int enabled
)
6890 break_command_really (gdbarch
,
6891 address
, condition
, thread
,
6892 0 /* condition and thread are valid. */,
6893 tempflag
, hardwareflag
, 0 /* traceflag */,
6896 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
6900 /* Adjust SAL to the first instruction past the function prologue.
6901 The end of the prologue is determined using the line table from
6902 the debugging information. explicit_pc and explicit_line are
6905 If SAL is already past the prologue, then do nothing. */
6908 skip_prologue_sal (struct symtab_and_line
*sal
)
6911 struct symtab_and_line start_sal
;
6912 struct cleanup
*old_chain
;
6914 old_chain
= save_current_space_and_thread ();
6916 sym
= find_pc_function (sal
->pc
);
6919 start_sal
= find_function_start_sal (sym
, 1);
6920 if (sal
->pc
< start_sal
.pc
)
6922 start_sal
.explicit_line
= sal
->explicit_line
;
6923 start_sal
.explicit_pc
= sal
->explicit_pc
;
6928 do_cleanups (old_chain
);
6931 /* Helper function for break_command_1 and disassemble_command. */
6934 resolve_sal_pc (struct symtab_and_line
*sal
)
6938 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
6940 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
6941 error (_("No line %d in file \"%s\"."),
6942 sal
->line
, sal
->symtab
->filename
);
6945 /* If this SAL corresponds to a breakpoint inserted using
6946 a line number, then skip the function prologue if necessary. */
6947 if (sal
->explicit_line
)
6949 /* Preserve the original line number. */
6950 int saved_line
= sal
->line
;
6951 skip_prologue_sal (sal
);
6952 sal
->line
= saved_line
;
6956 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
6958 struct blockvector
*bv
;
6962 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
6965 sym
= block_linkage_function (b
);
6968 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
6969 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
6973 /* It really is worthwhile to have the section, so we'll just
6974 have to look harder. This case can be executed if we have
6975 line numbers but no functions (as can happen in assembly
6978 struct minimal_symbol
*msym
;
6979 struct cleanup
*old_chain
= save_current_space_and_thread ();
6981 switch_to_program_space_and_thread (sal
->pspace
);
6983 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
6985 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
6987 do_cleanups (old_chain
);
6994 break_command (char *arg
, int from_tty
)
6996 break_command_1 (arg
, 0, from_tty
);
7000 tbreak_command (char *arg
, int from_tty
)
7002 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7006 hbreak_command (char *arg
, int from_tty
)
7008 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7012 thbreak_command (char *arg
, int from_tty
)
7014 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7018 stop_command (char *arg
, int from_tty
)
7020 printf_filtered (_("Specify the type of breakpoint to set.\n\
7021 Usage: stop in <function | address>\n\
7022 stop at <line>\n"));
7026 stopin_command (char *arg
, int from_tty
)
7030 if (arg
== (char *) NULL
)
7032 else if (*arg
!= '*')
7037 /* look for a ':'. If this is a line number specification, then
7038 say it is bad, otherwise, it should be an address or
7039 function/method name */
7040 while (*argptr
&& !hasColon
)
7042 hasColon
= (*argptr
== ':');
7047 badInput
= (*argptr
!= ':'); /* Not a class::method */
7049 badInput
= isdigit (*arg
); /* a simple line number */
7053 printf_filtered (_("Usage: stop in <function | address>\n"));
7055 break_command_1 (arg
, 0, from_tty
);
7059 stopat_command (char *arg
, int from_tty
)
7063 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7070 /* look for a ':'. If there is a '::' then get out, otherwise
7071 it is probably a line number. */
7072 while (*argptr
&& !hasColon
)
7074 hasColon
= (*argptr
== ':');
7079 badInput
= (*argptr
== ':'); /* we have class::method */
7081 badInput
= !isdigit (*arg
); /* not a line number */
7085 printf_filtered (_("Usage: stop at <line>\n"));
7087 break_command_1 (arg
, 0, from_tty
);
7090 /* accessflag: hw_write: watch write,
7091 hw_read: watch read,
7092 hw_access: watch access (read or write) */
7094 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7096 struct gdbarch
*gdbarch
= get_current_arch ();
7097 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7098 struct expression
*exp
;
7099 struct block
*exp_valid_block
;
7100 struct value
*val
, *mark
;
7101 struct frame_info
*frame
;
7102 char *exp_start
= NULL
;
7103 char *exp_end
= NULL
;
7104 char *tok
, *id_tok_start
, *end_tok
;
7106 char *cond_start
= NULL
;
7107 char *cond_end
= NULL
;
7108 int i
, other_type_used
, target_resources_ok
= 0;
7109 enum bptype bp_type
;
7113 /* Make sure that we actually have parameters to parse. */
7114 if (arg
!= NULL
&& arg
[0] != '\0')
7116 toklen
= strlen (arg
); /* Size of argument list. */
7118 /* Points tok to the end of the argument list. */
7119 tok
= arg
+ toklen
- 1;
7121 /* Go backwards in the parameters list. Skip the last parameter.
7122 If we're expecting a 'thread <thread_num>' parameter, this should
7123 be the thread identifier. */
7124 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7126 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7129 /* Points end_tok to the beginning of the last token. */
7130 id_tok_start
= tok
+ 1;
7132 /* Go backwards in the parameters list. Skip one more parameter.
7133 If we're expecting a 'thread <thread_num>' parameter, we should
7134 reach a "thread" token. */
7135 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7140 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7143 /* Move the pointer forward to skip the whitespace and
7144 calculate the length of the token. */
7146 toklen
= end_tok
- tok
;
7148 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7150 /* At this point we've found a "thread" token, which means
7151 the user is trying to set a watchpoint that triggers
7152 only in a specific thread. */
7155 /* Extract the thread ID from the next token. */
7156 thread
= strtol (id_tok_start
, &endp
, 0);
7158 /* Check if the user provided a valid numeric value for the
7160 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7161 error (_("Invalid thread ID specification %s."), id_tok_start
);
7163 /* Check if the thread actually exists. */
7164 if (!valid_thread_id (thread
))
7165 error (_("Unknown thread %d."), thread
);
7167 /* Truncate the string and get rid of the thread <thread_num>
7168 parameter before the parameter list is parsed by the
7169 evaluate_expression() function. */
7174 /* Parse the rest of the arguments. */
7175 innermost_block
= NULL
;
7177 exp
= parse_exp_1 (&arg
, 0, 0);
7179 /* Remove trailing whitespace from the expression before saving it.
7180 This makes the eventual display of the expression string a bit
7182 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7185 exp_valid_block
= innermost_block
;
7186 mark
= value_mark ();
7187 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7189 release_value (val
);
7192 while (*tok
== ' ' || *tok
== '\t')
7196 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7199 toklen
= end_tok
- tok
;
7200 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7202 struct expression
*cond
;
7204 tok
= cond_start
= end_tok
+ 1;
7205 cond
= parse_exp_1 (&tok
, 0, 0);
7210 error (_("Junk at end of command."));
7212 if (accessflag
== hw_read
)
7213 bp_type
= bp_read_watchpoint
;
7214 else if (accessflag
== hw_access
)
7215 bp_type
= bp_access_watchpoint
;
7217 bp_type
= bp_hardware_watchpoint
;
7219 mem_cnt
= can_use_hardware_watchpoint (val
);
7220 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7221 error (_("Expression cannot be implemented with read/access watchpoint."));
7224 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7225 target_resources_ok
=
7226 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7228 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7229 error (_("Target does not support this type of hardware watchpoint."));
7231 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7232 error (_("Target can only support one kind of HW watchpoint at a time."));
7235 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7236 watchpoint could not be set. */
7237 if (!mem_cnt
|| target_resources_ok
<= 0)
7238 bp_type
= bp_watchpoint
;
7240 frame
= block_innermost_frame (exp_valid_block
);
7242 /* If the expression is "local", then set up a "watchpoint scope"
7243 breakpoint at the point where we've left the scope of the watchpoint
7244 expression. Create the scope breakpoint before the watchpoint, so
7245 that we will encounter it first in bpstat_stop_status. */
7246 if (innermost_block
&& frame
)
7248 if (frame_id_p (frame_unwind_caller_id (frame
)))
7251 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7252 frame_unwind_caller_pc (frame
),
7253 bp_watchpoint_scope
);
7255 scope_breakpoint
->enable_state
= bp_enabled
;
7257 /* Automatically delete the breakpoint when it hits. */
7258 scope_breakpoint
->disposition
= disp_del
;
7260 /* Only break in the proper frame (help with recursion). */
7261 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7263 /* Set the address at which we will stop. */
7264 scope_breakpoint
->loc
->gdbarch
7265 = frame_unwind_caller_arch (frame
);
7266 scope_breakpoint
->loc
->requested_address
7267 = frame_unwind_caller_pc (frame
);
7268 scope_breakpoint
->loc
->address
7269 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7270 scope_breakpoint
->loc
->requested_address
,
7271 scope_breakpoint
->type
);
7275 /* Now set up the breakpoint. */
7276 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7277 set_breakpoint_count (breakpoint_count
+ 1);
7278 b
->number
= breakpoint_count
;
7280 b
->disposition
= disp_donttouch
;
7282 b
->exp_valid_block
= exp_valid_block
;
7283 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7287 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7293 b
->watchpoint_frame
= get_frame_id (frame
);
7294 b
->watchpoint_thread
= inferior_ptid
;
7298 b
->watchpoint_frame
= null_frame_id
;
7299 b
->watchpoint_thread
= null_ptid
;
7302 if (scope_breakpoint
!= NULL
)
7304 /* The scope breakpoint is related to the watchpoint. We will
7305 need to act on them together. */
7306 b
->related_breakpoint
= scope_breakpoint
;
7307 scope_breakpoint
->related_breakpoint
= b
;
7310 value_free_to_mark (mark
);
7312 /* Finally update the new watchpoint. This creates the locations
7313 that should be inserted. */
7314 update_watchpoint (b
, 1);
7317 update_global_location_list (1);
7320 /* Return count of locations need to be watched and can be handled
7321 in hardware. If the watchpoint can not be handled
7322 in hardware return zero. */
7325 can_use_hardware_watchpoint (struct value
*v
)
7327 int found_memory_cnt
= 0;
7328 struct value
*head
= v
;
7330 /* Did the user specifically forbid us to use hardware watchpoints? */
7331 if (!can_use_hw_watchpoints
)
7334 /* Make sure that the value of the expression depends only upon
7335 memory contents, and values computed from them within GDB. If we
7336 find any register references or function calls, we can't use a
7337 hardware watchpoint.
7339 The idea here is that evaluating an expression generates a series
7340 of values, one holding the value of every subexpression. (The
7341 expression a*b+c has five subexpressions: a, b, a*b, c, and
7342 a*b+c.) GDB's values hold almost enough information to establish
7343 the criteria given above --- they identify memory lvalues,
7344 register lvalues, computed values, etcetera. So we can evaluate
7345 the expression, and then scan the chain of values that leaves
7346 behind to decide whether we can detect any possible change to the
7347 expression's final value using only hardware watchpoints.
7349 However, I don't think that the values returned by inferior
7350 function calls are special in any way. So this function may not
7351 notice that an expression involving an inferior function call
7352 can't be watched with hardware watchpoints. FIXME. */
7353 for (; v
; v
= value_next (v
))
7355 if (VALUE_LVAL (v
) == lval_memory
)
7358 /* A lazy memory lvalue is one that GDB never needed to fetch;
7359 we either just used its address (e.g., `a' in `a.b') or
7360 we never needed it at all (e.g., `a' in `a,b'). */
7364 /* Ahh, memory we actually used! Check if we can cover
7365 it with hardware watchpoints. */
7366 struct type
*vtype
= check_typedef (value_type (v
));
7368 /* We only watch structs and arrays if user asked for it
7369 explicitly, never if they just happen to appear in a
7370 middle of some value chain. */
7372 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7373 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7375 CORE_ADDR vaddr
= value_address (v
);
7376 int len
= TYPE_LENGTH (value_type (v
));
7378 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7385 else if (VALUE_LVAL (v
) != not_lval
7386 && deprecated_value_modifiable (v
) == 0)
7387 return 0; /* ??? What does this represent? */
7388 else if (VALUE_LVAL (v
) == lval_register
)
7389 return 0; /* cannot watch a register with a HW watchpoint */
7392 /* The expression itself looks suitable for using a hardware
7393 watchpoint, but give the target machine a chance to reject it. */
7394 return found_memory_cnt
;
7398 watch_command_wrapper (char *arg
, int from_tty
)
7400 watch_command (arg
, from_tty
);
7404 watch_command (char *arg
, int from_tty
)
7406 watch_command_1 (arg
, hw_write
, from_tty
);
7410 rwatch_command_wrapper (char *arg
, int from_tty
)
7412 rwatch_command (arg
, from_tty
);
7416 rwatch_command (char *arg
, int from_tty
)
7418 watch_command_1 (arg
, hw_read
, from_tty
);
7422 awatch_command_wrapper (char *arg
, int from_tty
)
7424 awatch_command (arg
, from_tty
);
7428 awatch_command (char *arg
, int from_tty
)
7430 watch_command_1 (arg
, hw_access
, from_tty
);
7434 /* Helper routines for the until_command routine in infcmd.c. Here
7435 because it uses the mechanisms of breakpoints. */
7437 struct until_break_command_continuation_args
7439 struct breakpoint
*breakpoint
;
7440 struct breakpoint
*breakpoint2
;
7443 /* This function is called by fetch_inferior_event via the
7444 cmd_continuation pointer, to complete the until command. It takes
7445 care of cleaning up the temporary breakpoints set up by the until
7448 until_break_command_continuation (void *arg
)
7450 struct until_break_command_continuation_args
*a
= arg
;
7452 delete_breakpoint (a
->breakpoint
);
7454 delete_breakpoint (a
->breakpoint2
);
7458 until_break_command (char *arg
, int from_tty
, int anywhere
)
7460 struct symtabs_and_lines sals
;
7461 struct symtab_and_line sal
;
7462 struct frame_info
*frame
= get_selected_frame (NULL
);
7463 struct breakpoint
*breakpoint
;
7464 struct breakpoint
*breakpoint2
= NULL
;
7465 struct cleanup
*old_chain
;
7467 clear_proceed_status ();
7469 /* Set a breakpoint where the user wants it and at return from
7472 if (default_breakpoint_valid
)
7473 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
7474 default_breakpoint_line
, (char ***) NULL
, NULL
);
7476 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
7477 0, (char ***) NULL
, NULL
);
7479 if (sals
.nelts
!= 1)
7480 error (_("Couldn't get information on specified line."));
7483 xfree (sals
.sals
); /* malloc'd, so freed */
7486 error (_("Junk at end of arguments."));
7488 resolve_sal_pc (&sal
);
7491 /* If the user told us to continue until a specified location,
7492 we don't specify a frame at which we need to stop. */
7493 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7494 null_frame_id
, bp_until
);
7496 /* Otherwise, specify the selected frame, because we want to stop only
7497 at the very same frame. */
7498 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7499 get_stack_frame_id (frame
),
7502 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
7504 /* Keep within the current frame, or in frames called by the current
7507 if (frame_id_p (frame_unwind_caller_id (frame
)))
7509 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
7510 sal
.pc
= frame_unwind_caller_pc (frame
);
7511 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
7513 frame_unwind_caller_id (frame
),
7515 make_cleanup_delete_breakpoint (breakpoint2
);
7518 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
7520 /* If we are running asynchronously, and proceed call above has actually
7521 managed to start the target, arrange for breakpoints to be
7522 deleted when the target stops. Otherwise, we're already stopped and
7523 delete breakpoints via cleanup chain. */
7525 if (target_can_async_p () && is_running (inferior_ptid
))
7527 struct until_break_command_continuation_args
*args
;
7528 args
= xmalloc (sizeof (*args
));
7530 args
->breakpoint
= breakpoint
;
7531 args
->breakpoint2
= breakpoint2
;
7533 discard_cleanups (old_chain
);
7534 add_continuation (inferior_thread (),
7535 until_break_command_continuation
, args
,
7539 do_cleanups (old_chain
);
7543 ep_skip_leading_whitespace (char **s
)
7545 if ((s
== NULL
) || (*s
== NULL
))
7547 while (isspace (**s
))
7551 /* This function attempts to parse an optional "if <cond>" clause
7552 from the arg string. If one is not found, it returns NULL.
7554 Else, it returns a pointer to the condition string. (It does not
7555 attempt to evaluate the string against a particular block.) And,
7556 it updates arg to point to the first character following the parsed
7557 if clause in the arg string. */
7560 ep_parse_optional_if_clause (char **arg
)
7564 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
7567 /* Skip the "if" keyword. */
7570 /* Skip any extra leading whitespace, and record the start of the
7571 condition string. */
7572 ep_skip_leading_whitespace (arg
);
7575 /* Assume that the condition occupies the remainder of the arg string. */
7576 (*arg
) += strlen (cond_string
);
7581 /* This function attempts to parse an optional filename from the arg
7582 string. If one is not found, it returns NULL.
7584 Else, it returns a pointer to the parsed filename. (This function
7585 makes no attempt to verify that a file of that name exists, or is
7586 accessible.) And, it updates arg to point to the first character
7587 following the parsed filename in the arg string.
7589 Note that clients needing to preserve the returned filename for
7590 future access should copy it to their own buffers. */
7592 ep_parse_optional_filename (char **arg
)
7594 static char filename
[1024];
7599 if ((*arg_p
== '\0') || isspace (*arg_p
))
7617 /* Commands to deal with catching events, such as signals, exceptions,
7618 process start/exit, etc. */
7622 catch_fork_temporary
, catch_vfork_temporary
,
7623 catch_fork_permanent
, catch_vfork_permanent
7628 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7630 struct gdbarch
*gdbarch
= get_current_arch ();
7631 char *cond_string
= NULL
;
7632 catch_fork_kind fork_kind
;
7635 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
7636 tempflag
= (fork_kind
== catch_fork_temporary
7637 || fork_kind
== catch_vfork_temporary
);
7641 ep_skip_leading_whitespace (&arg
);
7643 /* The allowed syntax is:
7645 catch [v]fork if <cond>
7647 First, check if there's an if clause. */
7648 cond_string
= ep_parse_optional_if_clause (&arg
);
7650 if ((*arg
!= '\0') && !isspace (*arg
))
7651 error (_("Junk at end of arguments."));
7653 /* If this target supports it, create a fork or vfork catchpoint
7654 and enable reporting of such events. */
7657 case catch_fork_temporary
:
7658 case catch_fork_permanent
:
7659 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
7660 &catch_fork_breakpoint_ops
);
7662 case catch_vfork_temporary
:
7663 case catch_vfork_permanent
:
7664 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
7665 &catch_vfork_breakpoint_ops
);
7668 error (_("unsupported or unknown fork kind; cannot catch it"));
7674 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7676 struct gdbarch
*gdbarch
= get_current_arch ();
7678 char *cond_string
= NULL
;
7680 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7684 ep_skip_leading_whitespace (&arg
);
7686 /* The allowed syntax is:
7688 catch exec if <cond>
7690 First, check if there's an if clause. */
7691 cond_string
= ep_parse_optional_if_clause (&arg
);
7693 if ((*arg
!= '\0') && !isspace (*arg
))
7694 error (_("Junk at end of arguments."));
7696 /* If this target supports it, create an exec catchpoint
7697 and enable reporting of such events. */
7698 create_catchpoint (gdbarch
, tempflag
, cond_string
,
7699 &catch_exec_breakpoint_ops
);
7702 static enum print_stop_action
7703 print_exception_catchpoint (struct breakpoint
*b
)
7705 int bp_temp
, bp_throw
;
7707 annotate_catchpoint (b
->number
);
7709 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
7710 if (b
->loc
->address
!= b
->loc
->requested_address
)
7711 breakpoint_adjustment_warning (b
->loc
->requested_address
,
7714 bp_temp
= b
->disposition
== disp_del
;
7716 bp_temp
? "Temporary catchpoint "
7718 if (!ui_out_is_mi_like_p (uiout
))
7719 ui_out_field_int (uiout
, "bkptno", b
->number
);
7721 bp_throw
? " (exception thrown), "
7722 : " (exception caught), ");
7723 if (ui_out_is_mi_like_p (uiout
))
7725 ui_out_field_string (uiout
, "reason",
7726 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
7727 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7728 ui_out_field_int (uiout
, "bkptno", b
->number
);
7730 return PRINT_SRC_AND_LOC
;
7734 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
7736 struct value_print_options opts
;
7737 get_user_print_options (&opts
);
7738 if (opts
.addressprint
)
7741 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
7742 ui_out_field_string (uiout
, "addr", "<PENDING>");
7744 ui_out_field_core_addr (uiout
, "addr",
7745 b
->loc
->gdbarch
, b
->loc
->address
);
7750 if (strstr (b
->addr_string
, "throw") != NULL
)
7751 ui_out_field_string (uiout
, "what", "exception throw");
7753 ui_out_field_string (uiout
, "what", "exception catch");
7757 print_mention_exception_catchpoint (struct breakpoint
*b
)
7762 bp_temp
= b
->disposition
== disp_del
;
7763 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
7764 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
7765 : _("Catchpoint "));
7766 ui_out_field_int (uiout
, "bkptno", b
->number
);
7767 ui_out_text (uiout
, bp_throw
? _(" (throw)")
7771 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
7774 NULL
, /* breakpoint_hit */
7775 print_exception_catchpoint
,
7776 print_one_exception_catchpoint
,
7777 print_mention_exception_catchpoint
7781 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
7782 enum exception_event_kind ex_event
, int from_tty
)
7784 char *trigger_func_name
;
7786 if (ex_event
== EX_EVENT_CATCH
)
7787 trigger_func_name
= "__cxa_begin_catch";
7789 trigger_func_name
= "__cxa_throw";
7791 break_command_really (get_current_arch (),
7792 trigger_func_name
, cond_string
, -1,
7793 0 /* condition and thread are valid. */,
7796 AUTO_BOOLEAN_TRUE
/* pending */,
7797 &gnu_v3_exception_catchpoint_ops
, from_tty
,
7803 /* Deal with "catch catch" and "catch throw" commands */
7806 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
7807 int tempflag
, int from_tty
)
7809 char *cond_string
= NULL
;
7810 struct symtab_and_line
*sal
= NULL
;
7814 ep_skip_leading_whitespace (&arg
);
7816 cond_string
= ep_parse_optional_if_clause (&arg
);
7818 if ((*arg
!= '\0') && !isspace (*arg
))
7819 error (_("Junk at end of arguments."));
7821 if (ex_event
!= EX_EVENT_THROW
7822 && ex_event
!= EX_EVENT_CATCH
)
7823 error (_("Unsupported or unknown exception event; cannot catch it"));
7825 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
7828 warning (_("Unsupported with this platform/compiler combination."));
7831 /* Implementation of "catch catch" command. */
7834 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7836 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7837 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
7840 /* Implementation of "catch throw" command. */
7843 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7845 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7846 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
7849 /* Create a breakpoint struct for Ada exception catchpoints. */
7852 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
7853 struct symtab_and_line sal
,
7857 struct expression
*cond
,
7858 struct breakpoint_ops
*ops
,
7862 struct breakpoint
*b
;
7866 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7868 loc_gdbarch
= gdbarch
;
7870 describe_other_breakpoints (loc_gdbarch
,
7871 sal
.pspace
, sal
.pc
, sal
.section
, -1);
7872 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7873 version for exception catchpoints, because two catchpoints
7874 used for different exception names will use the same address.
7875 In this case, a "breakpoint ... also set at..." warning is
7876 unproductive. Besides. the warning phrasing is also a bit
7877 inapropriate, we should use the word catchpoint, and tell
7878 the user what type of catchpoint it is. The above is good
7879 enough for now, though. */
7882 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
7883 set_breakpoint_count (breakpoint_count
+ 1);
7885 b
->enable_state
= bp_enabled
;
7886 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7887 b
->number
= breakpoint_count
;
7888 b
->ignore_count
= 0;
7889 b
->loc
->cond
= cond
;
7890 b
->addr_string
= addr_string
;
7891 b
->language
= language_ada
;
7892 b
->cond_string
= cond_string
;
7893 b
->exp_string
= exp_string
;
7898 update_global_location_list (1);
7901 /* Implement the "catch exception" command. */
7904 catch_ada_exception_command (char *arg
, int from_tty
,
7905 struct cmd_list_element
*command
)
7907 struct gdbarch
*gdbarch
= get_current_arch ();
7909 struct symtab_and_line sal
;
7911 char *addr_string
= NULL
;
7912 char *exp_string
= NULL
;
7913 char *cond_string
= NULL
;
7914 struct expression
*cond
= NULL
;
7915 struct breakpoint_ops
*ops
= NULL
;
7917 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7921 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
7922 &cond_string
, &cond
, &ops
);
7923 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
7924 cond_string
, cond
, ops
, tempflag
,
7928 /* Cleanup function for a syscall filter list. */
7930 clean_up_filters (void *arg
)
7932 VEC(int) *iter
= *(VEC(int) **) arg
;
7933 VEC_free (int, iter
);
7936 /* Splits the argument using space as delimiter. Returns an xmalloc'd
7937 filter list, or NULL if no filtering is required. */
7939 catch_syscall_split_args (char *arg
)
7941 VEC(int) *result
= NULL
;
7942 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
7944 while (*arg
!= '\0')
7946 int i
, syscall_number
;
7951 /* Skip whitespace. */
7952 while (isspace (*arg
))
7955 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
7956 cur_name
[i
] = arg
[i
];
7960 /* Check if the user provided a syscall name or a number. */
7961 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
7962 if (*endptr
== '\0')
7963 get_syscall_by_number (syscall_number
, &s
);
7966 /* We have a name. Let's check if it's valid and convert it
7968 get_syscall_by_name (cur_name
, &s
);
7970 if (s
.number
== UNKNOWN_SYSCALL
)
7971 /* Here we have to issue an error instead of a warning, because
7972 GDB cannot do anything useful if there's no syscall number to
7974 error (_("Unknown syscall name '%s'."), cur_name
);
7977 /* Ok, it's valid. */
7978 VEC_safe_push (int, result
, s
.number
);
7981 discard_cleanups (cleanup
);
7985 /* Implement the "catch syscall" command. */
7988 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7993 struct gdbarch
*gdbarch
= get_current_arch ();
7995 /* Checking if the feature if supported. */
7996 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
7997 error (_("The feature 'catch syscall' is not supported on \
7998 this architeture yet."));
8000 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8002 ep_skip_leading_whitespace (&arg
);
8004 /* We need to do this first "dummy" translation in order
8005 to get the syscall XML file loaded or, most important,
8006 to display a warning to the user if there's no XML file
8007 for his/her architecture. */
8008 get_syscall_by_number (0, &s
);
8010 /* The allowed syntax is:
8012 catch syscall <name | number> [<name | number> ... <name | number>]
8014 Let's check if there's a syscall name. */
8017 filter
= catch_syscall_split_args (arg
);
8021 create_syscall_event_catchpoint (tempflag
, filter
,
8022 &catch_syscall_breakpoint_ops
);
8025 /* Implement the "catch assert" command. */
8028 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8030 struct gdbarch
*gdbarch
= get_current_arch ();
8032 struct symtab_and_line sal
;
8033 char *addr_string
= NULL
;
8034 struct breakpoint_ops
*ops
= NULL
;
8036 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8040 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8041 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8042 ops
, tempflag
, from_tty
);
8046 catch_command (char *arg
, int from_tty
)
8048 error (_("Catch requires an event name."));
8053 tcatch_command (char *arg
, int from_tty
)
8055 error (_("Catch requires an event name."));
8058 /* Delete breakpoints by address or line. */
8061 clear_command (char *arg
, int from_tty
)
8063 struct breakpoint
*b
;
8064 VEC(breakpoint_p
) *found
= 0;
8067 struct symtabs_and_lines sals
;
8068 struct symtab_and_line sal
;
8073 sals
= decode_line_spec (arg
, 1);
8078 sals
.sals
= (struct symtab_and_line
*)
8079 xmalloc (sizeof (struct symtab_and_line
));
8080 make_cleanup (xfree
, sals
.sals
);
8081 init_sal (&sal
); /* initialize to zeroes */
8082 sal
.line
= default_breakpoint_line
;
8083 sal
.symtab
= default_breakpoint_symtab
;
8084 sal
.pc
= default_breakpoint_address
;
8085 sal
.pspace
= default_breakpoint_pspace
;
8086 if (sal
.symtab
== 0)
8087 error (_("No source file specified."));
8095 /* We don't call resolve_sal_pc here. That's not
8096 as bad as it seems, because all existing breakpoints
8097 typically have both file/line and pc set. So, if
8098 clear is given file/line, we can match this to existing
8099 breakpoint without obtaining pc at all.
8101 We only support clearing given the address explicitly
8102 present in breakpoint table. Say, we've set breakpoint
8103 at file:line. There were several PC values for that file:line,
8104 due to optimization, all in one block.
8105 We've picked one PC value. If "clear" is issued with another
8106 PC corresponding to the same file:line, the breakpoint won't
8107 be cleared. We probably can still clear the breakpoint, but
8108 since the other PC value is never presented to user, user
8109 can only find it by guessing, and it does not seem important
8112 /* For each line spec given, delete bps which correspond
8113 to it. Do it in two passes, solely to preserve the current
8114 behavior that from_tty is forced true if we delete more than
8118 for (i
= 0; i
< sals
.nelts
; i
++)
8120 /* If exact pc given, clear bpts at that pc.
8121 If line given (pc == 0), clear all bpts on specified line.
8122 If defaulting, clear all bpts on default line
8125 defaulting sal.pc != 0 tests to do
8130 1 0 <can't happen> */
8134 /* Find all matching breakpoints and add them to
8139 /* Are we going to delete b? */
8140 if (b
->type
!= bp_none
8141 && b
->type
!= bp_watchpoint
8142 && b
->type
!= bp_hardware_watchpoint
8143 && b
->type
!= bp_read_watchpoint
8144 && b
->type
!= bp_access_watchpoint
)
8146 struct bp_location
*loc
= b
->loc
;
8147 for (; loc
; loc
= loc
->next
)
8149 int pc_match
= sal
.pc
8150 && (loc
->pspace
== sal
.pspace
)
8151 && (loc
->address
== sal
.pc
)
8152 && (!section_is_overlay (loc
->section
)
8153 || loc
->section
== sal
.section
);
8154 int line_match
= ((default_match
|| (0 == sal
.pc
))
8155 && b
->source_file
!= NULL
8156 && sal
.symtab
!= NULL
8157 && sal
.pspace
== loc
->pspace
8158 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8159 && b
->line_number
== sal
.line
);
8160 if (pc_match
|| line_match
)
8169 VEC_safe_push(breakpoint_p
, found
, b
);
8172 /* Now go thru the 'found' chain and delete them. */
8173 if (VEC_empty(breakpoint_p
, found
))
8176 error (_("No breakpoint at %s."), arg
);
8178 error (_("No breakpoint at this line."));
8181 if (VEC_length(breakpoint_p
, found
) > 1)
8182 from_tty
= 1; /* Always report if deleted more than one */
8185 if (VEC_length(breakpoint_p
, found
) == 1)
8186 printf_unfiltered (_("Deleted breakpoint "));
8188 printf_unfiltered (_("Deleted breakpoints "));
8190 breakpoints_changed ();
8192 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8195 printf_unfiltered ("%d ", b
->number
);
8196 delete_breakpoint (b
);
8199 putchar_unfiltered ('\n');
8202 /* Delete breakpoint in BS if they are `delete' breakpoints and
8203 all breakpoints that are marked for deletion, whether hit or not.
8204 This is called after any breakpoint is hit, or after errors. */
8207 breakpoint_auto_delete (bpstat bs
)
8209 struct breakpoint
*b
, *temp
;
8211 for (; bs
; bs
= bs
->next
)
8212 if (bs
->breakpoint_at
8213 && bs
->breakpoint_at
->owner
8214 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8216 delete_breakpoint (bs
->breakpoint_at
->owner
);
8218 ALL_BREAKPOINTS_SAFE (b
, temp
)
8220 if (b
->disposition
== disp_del_at_next_stop
)
8221 delete_breakpoint (b
);
8225 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8226 Sort elements primarily by their ADDRESS (no matter what does
8227 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8228 first bp_permanent OWNERed elements and terciarily just ensuring the array
8229 is sorted stable way despite qsort being an instable algorithm. */
8232 bp_location_compare (const void *ap
, const void *bp
)
8234 struct bp_location
*a
= *(void **) ap
;
8235 struct bp_location
*b
= *(void **) bp
;
8236 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8237 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8239 if (a
->address
!= b
->address
)
8240 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8242 /* Sort permanent breakpoints first. */
8243 if (a_perm
!= b_perm
)
8244 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8246 /* Make the user-visible order stable across GDB runs. Locations of the same
8247 breakpoint can be sorted in arbitrary order. */
8249 if (a
->owner
->number
!= b
->owner
->number
)
8250 return (a
->owner
->number
> b
->owner
->number
)
8251 - (a
->owner
->number
< b
->owner
->number
);
8253 return (a
> b
) - (a
< b
);
8256 /* Set bp_location_placed_address_before_address_max and
8257 bp_location_shadow_len_after_address_max according to the current content of
8258 the bp_location array. */
8261 bp_location_target_extensions_update (void)
8263 struct bp_location
*bl
, **blp_tmp
;
8265 bp_location_placed_address_before_address_max
= 0;
8266 bp_location_shadow_len_after_address_max
= 0;
8268 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8270 CORE_ADDR start
, end
, addr
;
8272 if (!bp_location_has_shadow (bl
))
8275 start
= bl
->target_info
.placed_address
;
8276 end
= start
+ bl
->target_info
.shadow_len
;
8278 gdb_assert (bl
->address
>= start
);
8279 addr
= bl
->address
- start
;
8280 if (addr
> bp_location_placed_address_before_address_max
)
8281 bp_location_placed_address_before_address_max
= addr
;
8283 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8285 gdb_assert (bl
->address
< end
);
8286 addr
= end
- bl
->address
;
8287 if (addr
> bp_location_shadow_len_after_address_max
)
8288 bp_location_shadow_len_after_address_max
= addr
;
8292 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8293 into the inferior, only remove already-inserted locations that no
8294 longer should be inserted. Functions that delete a breakpoint or
8295 breakpoints should pass false, so that deleting a breakpoint
8296 doesn't have the side effect of inserting the locations of other
8297 breakpoints that are marked not-inserted, but should_be_inserted
8298 returns true on them.
8300 This behaviour is useful is situations close to tear-down -- e.g.,
8301 after an exec, while the target still has execution, but breakpoint
8302 shadows of the previous executable image should *NOT* be restored
8303 to the new image; or before detaching, where the target still has
8304 execution and wants to delete breakpoints from GDB's lists, and all
8305 breakpoints had already been removed from the inferior. */
8308 update_global_location_list (int should_insert
)
8310 struct breakpoint
*b
;
8311 struct bp_location
**locp
, *loc
;
8312 struct cleanup
*cleanups
;
8314 /* Used in the duplicates detection below. When iterating over all
8315 bp_locations, points to the first bp_location of a given address.
8316 Breakpoints and watchpoints of different types are never
8317 duplicates of each other. Keep one pointer for each type of
8318 breakpoint/watchpoint, so we only need to loop over all locations
8320 struct bp_location
*bp_loc_first
; /* breakpoint */
8321 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8322 struct bp_location
*awp_loc_first
; /* access watchpoint */
8323 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8325 /* Saved former bp_location array which we compare against the newly built
8326 bp_location from the current state of ALL_BREAKPOINTS. */
8327 struct bp_location
**old_location
, **old_locp
;
8328 unsigned old_location_count
;
8330 old_location
= bp_location
;
8331 old_location_count
= bp_location_count
;
8333 bp_location_count
= 0;
8334 cleanups
= make_cleanup (xfree
, old_location
);
8337 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8338 bp_location_count
++;
8340 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8343 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8345 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8346 bp_location_compare
);
8348 bp_location_target_extensions_update ();
8350 /* Identify bp_location instances that are no longer present in the new
8351 list, and therefore should be freed. Note that it's not necessary that
8352 those locations should be removed from inferior -- if there's another
8353 location at the same address (previously marked as duplicate),
8354 we don't need to remove/insert the location.
8356 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8357 former bp_location array state respectively. */
8360 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8363 struct bp_location
*old_loc
= *old_locp
;
8364 struct bp_location
**loc2p
;
8366 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8368 int found_object
= 0;
8369 /* Tells if the location should remain inserted in the target. */
8370 int keep_in_target
= 0;
8373 /* Skip LOCP entries which will definitely never be needed. Stop either
8374 at or being the one matching OLD_LOC. */
8375 while (locp
< bp_location
+ bp_location_count
8376 && (*locp
)->address
< old_loc
->address
)
8380 (loc2p
< bp_location
+ bp_location_count
8381 && (*loc2p
)->address
== old_loc
->address
);
8384 if (*loc2p
== old_loc
)
8391 /* If this location is no longer present, and inserted, look if there's
8392 maybe a new location at the same address. If so, mark that one
8393 inserted, and don't remove this one. This is needed so that we
8394 don't have a time window where a breakpoint at certain location is not
8397 if (old_loc
->inserted
)
8399 /* If the location is inserted now, we might have to remove it. */
8401 if (found_object
&& should_be_inserted (old_loc
))
8403 /* The location is still present in the location list, and still
8404 should be inserted. Don't do anything. */
8409 /* The location is either no longer present, or got disabled.
8410 See if there's another location at the same address, in which
8411 case we don't need to remove this one from the target. */
8413 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8416 (loc2p
< bp_location
+ bp_location_count
8417 && (*loc2p
)->address
== old_loc
->address
);
8420 struct bp_location
*loc2
= *loc2p
;
8422 if (breakpoint_locations_match (loc2
, old_loc
))
8424 /* For the sake of should_be_inserted.
8425 Duplicates check below will fix up this later. */
8426 loc2
->duplicate
= 0;
8427 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8430 loc2
->target_info
= old_loc
->target_info
;
8439 if (!keep_in_target
)
8441 if (remove_breakpoint (old_loc
, mark_uninserted
))
8443 /* This is just about all we can do. We could keep this
8444 location on the global list, and try to remove it next
8445 time, but there's no particular reason why we will
8448 Note that at this point, old_loc->owner is still valid,
8449 as delete_breakpoint frees the breakpoint only
8450 after calling us. */
8451 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8452 old_loc
->owner
->number
);
8460 if (removed
&& non_stop
8461 && breakpoint_address_is_meaningful (old_loc
->owner
)
8462 && !is_hardware_watchpoint (old_loc
->owner
))
8464 /* This location was removed from the target. In
8465 non-stop mode, a race condition is possible where
8466 we've removed a breakpoint, but stop events for that
8467 breakpoint are already queued and will arrive later.
8468 We apply an heuristic to be able to distinguish such
8469 SIGTRAPs from other random SIGTRAPs: we keep this
8470 breakpoint location for a bit, and will retire it
8471 after we see some number of events. The theory here
8472 is that reporting of events should, "on the average",
8473 be fair, so after a while we'll see events from all
8474 threads that have anything of interest, and no longer
8475 need to keep this breakpoint location around. We
8476 don't hold locations forever so to reduce chances of
8477 mistaking a non-breakpoint SIGTRAP for a breakpoint
8480 The heuristic failing can be disastrous on
8481 decr_pc_after_break targets.
8483 On decr_pc_after_break targets, like e.g., x86-linux,
8484 if we fail to recognize a late breakpoint SIGTRAP,
8485 because events_till_retirement has reached 0 too
8486 soon, we'll fail to do the PC adjustment, and report
8487 a random SIGTRAP to the user. When the user resumes
8488 the inferior, it will most likely immediately crash
8489 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
8490 corrupted, because of being resumed e.g., in the
8491 middle of a multi-byte instruction, or skipped a
8492 one-byte instruction. This was actually seen happen
8493 on native x86-linux, and should be less rare on
8494 targets that do not support new thread events, like
8495 remote, due to the heuristic depending on
8498 Mistaking a random SIGTRAP for a breakpoint trap
8499 causes similar symptoms (PC adjustment applied when
8500 it shouldn't), but then again, playing with SIGTRAPs
8501 behind the debugger's back is asking for trouble.
8503 Since hardware watchpoint traps are always
8504 distinguishable from other traps, so we don't need to
8505 apply keep hardware watchpoint moribund locations
8506 around. We simply always ignore hardware watchpoint
8507 traps we can no longer explain. */
8509 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
8510 old_loc
->owner
= NULL
;
8512 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
8515 free_bp_location (old_loc
);
8519 /* Rescan breakpoints at the same address and section, marking the
8520 first one as "first" and any others as "duplicates". This is so
8521 that the bpt instruction is only inserted once. If we have a
8522 permanent breakpoint at the same place as BPT, make that one the
8523 official one, and the rest as duplicates. Permanent breakpoints
8524 are sorted first for the same address.
8526 Do the same for hardware watchpoints, but also considering the
8527 watchpoint's type (regular/access/read) and length. */
8529 bp_loc_first
= NULL
;
8530 wp_loc_first
= NULL
;
8531 awp_loc_first
= NULL
;
8532 rwp_loc_first
= NULL
;
8533 ALL_BP_LOCATIONS (loc
, locp
)
8535 struct breakpoint
*b
= loc
->owner
;
8536 struct bp_location
**loc_first_p
;
8538 if (b
->enable_state
== bp_disabled
8539 || b
->enable_state
== bp_call_disabled
8540 || b
->enable_state
== bp_startup_disabled
8542 || loc
->shlib_disabled
8543 || !breakpoint_address_is_meaningful (b
))
8546 /* Permanent breakpoint should always be inserted. */
8547 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
8548 internal_error (__FILE__
, __LINE__
,
8549 _("allegedly permanent breakpoint is not "
8550 "actually inserted"));
8552 if (b
->type
== bp_hardware_watchpoint
)
8553 loc_first_p
= &wp_loc_first
;
8554 else if (b
->type
== bp_read_watchpoint
)
8555 loc_first_p
= &rwp_loc_first
;
8556 else if (b
->type
== bp_access_watchpoint
)
8557 loc_first_p
= &awp_loc_first
;
8559 loc_first_p
= &bp_loc_first
;
8561 if (*loc_first_p
== NULL
8562 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
8563 || !breakpoint_locations_match (loc
, *loc_first_p
))
8572 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
8573 && b
->enable_state
!= bp_permanent
)
8574 internal_error (__FILE__
, __LINE__
,
8575 _("another breakpoint was inserted on top of "
8576 "a permanent breakpoint"));
8579 if (breakpoints_always_inserted_mode () && should_insert
8580 && (have_live_inferiors ()
8581 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
8582 insert_breakpoint_locations ();
8584 do_cleanups (cleanups
);
8588 breakpoint_retire_moribund (void)
8590 struct bp_location
*loc
;
8593 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
8594 if (--(loc
->events_till_retirement
) == 0)
8596 free_bp_location (loc
);
8597 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
8603 update_global_location_list_nothrow (int inserting
)
8605 struct gdb_exception e
;
8606 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8607 update_global_location_list (inserting
);
8610 /* Clear BPT from a BPS. */
8612 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
8615 for (bs
= bps
; bs
; bs
= bs
->next
)
8616 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
8618 bs
->breakpoint_at
= NULL
;
8620 /* bs->commands will be freed later. */
8624 /* Callback for iterate_over_threads. */
8626 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
8628 struct breakpoint
*bpt
= data
;
8629 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
8633 /* Delete a breakpoint and clean up all traces of it in the data
8637 delete_breakpoint (struct breakpoint
*bpt
)
8639 struct breakpoint
*b
;
8640 struct bp_location
*loc
, *next
;
8642 gdb_assert (bpt
!= NULL
);
8644 /* Has this bp already been deleted? This can happen because multiple
8645 lists can hold pointers to bp's. bpstat lists are especial culprits.
8647 One example of this happening is a watchpoint's scope bp. When the
8648 scope bp triggers, we notice that the watchpoint is out of scope, and
8649 delete it. We also delete its scope bp. But the scope bp is marked
8650 "auto-deleting", and is already on a bpstat. That bpstat is then
8651 checked for auto-deleting bp's, which are deleted.
8653 A real solution to this problem might involve reference counts in bp's,
8654 and/or giving them pointers back to their referencing bpstat's, and
8655 teaching delete_breakpoint to only free a bp's storage when no more
8656 references were extent. A cheaper bandaid was chosen. */
8657 if (bpt
->type
== bp_none
)
8660 observer_notify_breakpoint_deleted (bpt
->number
);
8662 if (breakpoint_chain
== bpt
)
8663 breakpoint_chain
= bpt
->next
;
8668 b
->next
= bpt
->next
;
8672 free_command_lines (&bpt
->commands
);
8673 if (bpt
->cond_string
!= NULL
)
8674 xfree (bpt
->cond_string
);
8675 if (bpt
->addr_string
!= NULL
)
8676 xfree (bpt
->addr_string
);
8677 if (bpt
->exp
!= NULL
)
8679 if (bpt
->exp_string
!= NULL
)
8680 xfree (bpt
->exp_string
);
8681 if (bpt
->val
!= NULL
)
8682 value_free (bpt
->val
);
8683 if (bpt
->source_file
!= NULL
)
8684 xfree (bpt
->source_file
);
8685 if (bpt
->exec_pathname
!= NULL
)
8686 xfree (bpt
->exec_pathname
);
8687 clean_up_filters (&bpt
->syscalls_to_be_caught
);
8689 /* Be sure no bpstat's are pointing at it after it's been freed. */
8690 /* FIXME, how can we find all bpstat's?
8691 We just check stop_bpstat for now. Note that we cannot just
8692 remove bpstats pointing at bpt from the stop_bpstat list
8693 entirely, as breakpoint commands are associated with the bpstat;
8694 if we remove it here, then the later call to
8695 bpstat_do_actions (&stop_bpstat);
8696 in event-top.c won't do anything, and temporary breakpoints
8697 with commands won't work. */
8699 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
8701 /* Now that breakpoint is removed from breakpoint
8702 list, update the global location list. This
8703 will remove locations that used to belong to
8704 this breakpoint. Do this before freeing
8705 the breakpoint itself, since remove_breakpoint
8706 looks at location's owner. It might be better
8707 design to have location completely self-contained,
8708 but it's not the case now. */
8709 update_global_location_list (0);
8712 /* On the chance that someone will soon try again to delete this same
8713 bp, we mark it as deleted before freeing its storage. */
8714 bpt
->type
= bp_none
;
8720 do_delete_breakpoint_cleanup (void *b
)
8722 delete_breakpoint (b
);
8726 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
8728 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
8732 delete_command (char *arg
, int from_tty
)
8734 struct breakpoint
*b
, *temp
;
8740 int breaks_to_delete
= 0;
8742 /* Delete all breakpoints if no argument.
8743 Do not delete internal or call-dummy breakpoints, these
8744 have to be deleted with an explicit breakpoint number argument. */
8747 if (b
->type
!= bp_call_dummy
8748 && b
->type
!= bp_shlib_event
8749 && b
->type
!= bp_jit_event
8750 && b
->type
!= bp_thread_event
8751 && b
->type
!= bp_overlay_event
8752 && b
->type
!= bp_longjmp_master
8755 breaks_to_delete
= 1;
8760 /* Ask user only if there are some breakpoints to delete. */
8762 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
8764 ALL_BREAKPOINTS_SAFE (b
, temp
)
8766 if (b
->type
!= bp_call_dummy
8767 && b
->type
!= bp_shlib_event
8768 && b
->type
!= bp_thread_event
8769 && b
->type
!= bp_jit_event
8770 && b
->type
!= bp_overlay_event
8771 && b
->type
!= bp_longjmp_master
8773 delete_breakpoint (b
);
8778 map_breakpoint_numbers (arg
, delete_breakpoint
);
8782 all_locations_are_pending (struct bp_location
*loc
)
8784 for (; loc
; loc
= loc
->next
)
8785 if (!loc
->shlib_disabled
)
8790 /* Subroutine of update_breakpoint_locations to simplify it.
8791 Return non-zero if multiple fns in list LOC have the same name.
8792 Null names are ignored. */
8795 ambiguous_names_p (struct bp_location
*loc
)
8797 struct bp_location
*l
;
8798 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
8799 (int (*) (const void *, const void *)) streq
,
8800 NULL
, xcalloc
, xfree
);
8802 for (l
= loc
; l
!= NULL
; l
= l
->next
)
8805 const char *name
= l
->function_name
;
8807 /* Allow for some names to be NULL, ignore them. */
8811 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
8813 /* NOTE: We can assume slot != NULL here because xcalloc never returns
8828 update_breakpoint_locations (struct breakpoint
*b
,
8829 struct symtabs_and_lines sals
)
8833 struct bp_location
*existing_locations
= b
->loc
;
8835 /* If there's no new locations, and all existing locations
8836 are pending, don't do anything. This optimizes
8837 the common case where all locations are in the same
8838 shared library, that was unloaded. We'd like to
8839 retain the location, so that when the library
8840 is loaded again, we don't loose the enabled/disabled
8841 status of the individual locations. */
8842 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
8847 for (i
= 0; i
< sals
.nelts
; ++i
)
8849 struct bp_location
*new_loc
=
8850 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
8852 /* Reparse conditions, they might contain references to the
8854 if (b
->cond_string
!= NULL
)
8856 struct gdb_exception e
;
8859 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8861 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
8866 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
8867 b
->number
, e
.message
);
8868 new_loc
->enabled
= 0;
8872 if (b
->source_file
!= NULL
)
8873 xfree (b
->source_file
);
8874 if (sals
.sals
[i
].symtab
== NULL
)
8875 b
->source_file
= NULL
;
8877 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
8879 if (b
->line_number
== 0)
8880 b
->line_number
= sals
.sals
[i
].line
;
8883 /* Update locations of permanent breakpoints. */
8884 if (b
->enable_state
== bp_permanent
)
8885 make_breakpoint_permanent (b
);
8887 /* If possible, carry over 'disable' status from existing breakpoints. */
8889 struct bp_location
*e
= existing_locations
;
8890 /* If there are multiple breakpoints with the same function name,
8891 e.g. for inline functions, comparing function names won't work.
8892 Instead compare pc addresses; this is just a heuristic as things
8893 may have moved, but in practice it gives the correct answer
8894 often enough until a better solution is found. */
8895 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
8897 for (; e
; e
= e
->next
)
8899 if (!e
->enabled
&& e
->function_name
)
8901 struct bp_location
*l
= b
->loc
;
8902 if (have_ambiguous_names
)
8904 for (; l
; l
= l
->next
)
8905 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
8906 l
->pspace
->aspace
, l
->address
))
8914 for (; l
; l
= l
->next
)
8915 if (l
->function_name
8916 && strcmp (e
->function_name
, l
->function_name
) == 0)
8926 update_global_location_list (1);
8930 /* Reset a breakpoint given it's struct breakpoint * BINT.
8931 The value we return ends up being the return value from catch_errors.
8932 Unused in this case. */
8935 breakpoint_re_set_one (void *bint
)
8937 /* get past catch_errs */
8938 struct breakpoint
*b
= (struct breakpoint
*) bint
;
8942 int *not_found_ptr
= ¬_found
;
8943 struct symtabs_and_lines sals
= {0};
8944 struct symtabs_and_lines expanded
= {0};
8946 enum enable_state save_enable
;
8947 struct gdb_exception e
;
8948 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
8953 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
8957 case bp_hardware_breakpoint
:
8959 /* Do not attempt to re-set breakpoints disabled during startup. */
8960 if (b
->enable_state
== bp_startup_disabled
)
8963 if (b
->addr_string
== NULL
)
8965 /* Anything without a string can't be re-set. */
8966 delete_breakpoint (b
);
8970 set_language (b
->language
);
8971 input_radix
= b
->input_radix
;
8974 save_current_space_and_thread ();
8975 switch_to_program_space_and_thread (b
->pspace
);
8977 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8979 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
8984 int not_found_and_ok
= 0;
8985 /* For pending breakpoints, it's expected that parsing
8986 will fail until the right shared library is loaded.
8987 User has already told to create pending breakpoints and
8988 don't need extra messages. If breakpoint is in bp_shlib_disabled
8989 state, then user already saw the message about that breakpoint
8990 being disabled, and don't want to see more errors. */
8992 && (b
->condition_not_parsed
8993 || (b
->loc
&& b
->loc
->shlib_disabled
)
8994 || b
->enable_state
== bp_disabled
))
8995 not_found_and_ok
= 1;
8997 if (!not_found_and_ok
)
8999 /* We surely don't want to warn about the same breakpoint
9000 10 times. One solution, implemented here, is disable
9001 the breakpoint on error. Another solution would be to
9002 have separate 'warning emitted' flag. Since this
9003 happens only when a binary has changed, I don't know
9004 which approach is better. */
9005 b
->enable_state
= bp_disabled
;
9006 throw_exception (e
);
9012 gdb_assert (sals
.nelts
== 1);
9014 resolve_sal_pc (&sals
.sals
[0]);
9015 if (b
->condition_not_parsed
&& s
&& s
[0])
9017 char *cond_string
= 0;
9021 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9022 &cond_string
, &thread
, &task
);
9024 b
->cond_string
= cond_string
;
9027 b
->condition_not_parsed
= 0;
9030 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9033 make_cleanup (xfree
, sals
.sals
);
9034 update_breakpoint_locations (b
, expanded
);
9038 case bp_hardware_watchpoint
:
9039 case bp_read_watchpoint
:
9040 case bp_access_watchpoint
:
9041 /* Watchpoint can be either on expression using entirely global variables,
9042 or it can be on local variables.
9044 Watchpoints of the first kind are never auto-deleted, and even persist
9045 across program restarts. Since they can use variables from shared
9046 libraries, we need to reparse expression as libraries are loaded
9049 Watchpoints on local variables can also change meaning as result
9050 of solib event. For example, if a watchpoint uses both a local and
9051 a global variables in expression, it's a local watchpoint, but
9052 unloading of a shared library will make the expression invalid.
9053 This is not a very common use case, but we still re-evaluate
9054 expression, to avoid surprises to the user.
9056 Note that for local watchpoints, we re-evaluate it only if
9057 watchpoints frame id is still valid. If it's not, it means
9058 the watchpoint is out of scope and will be deleted soon. In fact,
9059 I'm not sure we'll ever be called in this case.
9061 If a local watchpoint's frame id is still valid, then
9062 b->exp_valid_block is likewise valid, and we can safely use it.
9064 Don't do anything about disabled watchpoints, since they will
9065 be reevaluated again when enabled. */
9066 update_watchpoint (b
, 1 /* reparse */);
9068 /* We needn't really do anything to reset these, since the mask
9069 that requests them is unaffected by e.g., new libraries being
9075 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9077 /* Delete overlay event and longjmp master breakpoints; they will be
9078 reset later by breakpoint_re_set. */
9079 case bp_overlay_event
:
9080 case bp_longjmp_master
:
9081 delete_breakpoint (b
);
9084 /* This breakpoint is special, it's set up when the inferior
9085 starts and we really don't want to touch it. */
9086 case bp_shlib_event
:
9088 /* Like bp_shlib_event, this breakpoint type is special.
9089 Once it is set up, we do not want to touch it. */
9090 case bp_thread_event
:
9092 /* Keep temporary breakpoints, which can be encountered when we step
9093 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9094 Otherwise these should have been blown away via the cleanup chain
9095 or by breakpoint_init_inferior when we rerun the executable. */
9098 case bp_watchpoint_scope
:
9100 case bp_step_resume
:
9102 case bp_longjmp_resume
:
9107 do_cleanups (cleanups
);
9111 /* Re-set all breakpoints after symbols have been re-loaded. */
9113 breakpoint_re_set (void)
9115 struct breakpoint
*b
, *temp
;
9116 enum language save_language
;
9117 int save_input_radix
;
9118 struct cleanup
*old_chain
;
9120 save_language
= current_language
->la_language
;
9121 save_input_radix
= input_radix
;
9122 old_chain
= save_current_program_space ();
9124 ALL_BREAKPOINTS_SAFE (b
, temp
)
9126 /* Format possible error msg */
9127 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9129 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9130 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9131 do_cleanups (cleanups
);
9133 set_language (save_language
);
9134 input_radix
= save_input_radix
;
9136 jit_breakpoint_re_set ();
9138 do_cleanups (old_chain
);
9140 create_overlay_event_breakpoint ("_ovly_debug_event");
9141 create_longjmp_master_breakpoint ("longjmp");
9142 create_longjmp_master_breakpoint ("_longjmp");
9143 create_longjmp_master_breakpoint ("siglongjmp");
9144 create_longjmp_master_breakpoint ("_siglongjmp");
9147 /* Reset the thread number of this breakpoint:
9149 - If the breakpoint is for all threads, leave it as-is.
9150 - Else, reset it to the current thread for inferior_ptid. */
9152 breakpoint_re_set_thread (struct breakpoint
*b
)
9154 if (b
->thread
!= -1)
9156 if (in_thread_list (inferior_ptid
))
9157 b
->thread
= pid_to_thread_id (inferior_ptid
);
9159 /* We're being called after following a fork. The new fork is
9160 selected as current, and unless this was a vfork will have a
9161 different program space from the original thread. Reset that
9163 b
->loc
->pspace
= current_program_space
;
9167 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9168 If from_tty is nonzero, it prints a message to that effect,
9169 which ends with a period (no newline). */
9172 set_ignore_count (int bptnum
, int count
, int from_tty
)
9174 struct breakpoint
*b
;
9180 if (b
->number
== bptnum
)
9182 b
->ignore_count
= count
;
9186 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9188 else if (count
== 1)
9189 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9192 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9195 breakpoints_changed ();
9196 observer_notify_breakpoint_modified (b
->number
);
9200 error (_("No breakpoint number %d."), bptnum
);
9204 make_breakpoint_silent (struct breakpoint
*b
)
9206 /* Silence the breakpoint. */
9210 /* Command to set ignore-count of breakpoint N to COUNT. */
9213 ignore_command (char *args
, int from_tty
)
9219 error_no_arg (_("a breakpoint number"));
9221 num
= get_number (&p
);
9223 error (_("bad breakpoint number: '%s'"), args
);
9225 error (_("Second argument (specified ignore-count) is missing."));
9227 set_ignore_count (num
,
9228 longest_to_int (value_as_long (parse_and_eval (p
))),
9231 printf_filtered ("\n");
9234 /* Call FUNCTION on each of the breakpoints
9235 whose numbers are given in ARGS. */
9238 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
9243 struct breakpoint
*b
, *tmp
;
9247 error_no_arg (_("one or more breakpoint numbers"));
9254 num
= get_number_or_range (&p1
);
9257 warning (_("bad breakpoint number at or near '%s'"), p
);
9261 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9262 if (b
->number
== num
)
9264 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9267 if (related_breakpoint
)
9268 function (related_breakpoint
);
9272 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9278 static struct bp_location
*
9279 find_location_by_number (char *number
)
9281 char *dot
= strchr (number
, '.');
9285 struct breakpoint
*b
;
9286 struct bp_location
*loc
;
9291 bp_num
= get_number_or_range (&p1
);
9293 error (_("Bad breakpoint number '%s'"), number
);
9296 if (b
->number
== bp_num
)
9301 if (!b
|| b
->number
!= bp_num
)
9302 error (_("Bad breakpoint number '%s'"), number
);
9305 loc_num
= get_number_or_range (&p1
);
9307 error (_("Bad breakpoint location number '%s'"), number
);
9311 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9314 error (_("Bad breakpoint location number '%s'"), dot
+1);
9320 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9321 If from_tty is nonzero, it prints a message to that effect,
9322 which ends with a period (no newline). */
9325 disable_breakpoint (struct breakpoint
*bpt
)
9327 /* Never disable a watchpoint scope breakpoint; we want to
9328 hit them when we leave scope so we can delete both the
9329 watchpoint and its scope breakpoint at that time. */
9330 if (bpt
->type
== bp_watchpoint_scope
)
9333 /* You can't disable permanent breakpoints. */
9334 if (bpt
->enable_state
== bp_permanent
)
9337 bpt
->enable_state
= bp_disabled
;
9339 update_global_location_list (0);
9341 observer_notify_breakpoint_modified (bpt
->number
);
9345 disable_command (char *args
, int from_tty
)
9347 struct breakpoint
*bpt
;
9349 ALL_BREAKPOINTS (bpt
)
9353 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9359 case bp_hardware_breakpoint
:
9361 case bp_hardware_watchpoint
:
9362 case bp_read_watchpoint
:
9363 case bp_access_watchpoint
:
9364 disable_breakpoint (bpt
);
9368 else if (strchr (args
, '.'))
9370 struct bp_location
*loc
= find_location_by_number (args
);
9373 update_global_location_list (0);
9376 map_breakpoint_numbers (args
, disable_breakpoint
);
9380 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9382 int target_resources_ok
, other_type_used
;
9385 if (bpt
->type
== bp_hardware_breakpoint
)
9388 i
= hw_breakpoint_used_count ();
9389 target_resources_ok
=
9390 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9392 if (target_resources_ok
== 0)
9393 error (_("No hardware breakpoint support in the target."));
9394 else if (target_resources_ok
< 0)
9395 error (_("Hardware breakpoints used exceeds limit."));
9398 if (bpt
->type
== bp_watchpoint
9399 || bpt
->type
== bp_hardware_watchpoint
9400 || bpt
->type
== bp_read_watchpoint
9401 || bpt
->type
== bp_access_watchpoint
)
9403 struct gdb_exception e
;
9405 TRY_CATCH (e
, RETURN_MASK_ALL
)
9407 update_watchpoint (bpt
, 1 /* reparse */);
9411 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9417 if (bpt
->enable_state
!= bp_permanent
)
9418 bpt
->enable_state
= bp_enabled
;
9419 bpt
->disposition
= disposition
;
9420 update_global_location_list (1);
9421 breakpoints_changed ();
9423 observer_notify_breakpoint_modified (bpt
->number
);
9428 enable_breakpoint (struct breakpoint
*bpt
)
9430 do_enable_breakpoint (bpt
, bpt
->disposition
);
9433 /* The enable command enables the specified breakpoints (or all defined
9434 breakpoints) so they once again become (or continue to be) effective
9435 in stopping the inferior. */
9438 enable_command (char *args
, int from_tty
)
9440 struct breakpoint
*bpt
;
9442 ALL_BREAKPOINTS (bpt
)
9446 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
9452 case bp_hardware_breakpoint
:
9454 case bp_hardware_watchpoint
:
9455 case bp_read_watchpoint
:
9456 case bp_access_watchpoint
:
9457 enable_breakpoint (bpt
);
9461 else if (strchr (args
, '.'))
9463 struct bp_location
*loc
= find_location_by_number (args
);
9466 update_global_location_list (1);
9469 map_breakpoint_numbers (args
, enable_breakpoint
);
9473 enable_once_breakpoint (struct breakpoint
*bpt
)
9475 do_enable_breakpoint (bpt
, disp_disable
);
9479 enable_once_command (char *args
, int from_tty
)
9481 map_breakpoint_numbers (args
, enable_once_breakpoint
);
9485 enable_delete_breakpoint (struct breakpoint
*bpt
)
9487 do_enable_breakpoint (bpt
, disp_del
);
9491 enable_delete_command (char *args
, int from_tty
)
9493 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
9497 set_breakpoint_cmd (char *args
, int from_tty
)
9502 show_breakpoint_cmd (char *args
, int from_tty
)
9506 /* Invalidate last known value of any hardware watchpoint if
9507 the memory which that value represents has been written to by
9511 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
9512 const bfd_byte
*data
)
9514 struct breakpoint
*bp
;
9516 ALL_BREAKPOINTS (bp
)
9517 if (bp
->enable_state
== bp_enabled
9518 && bp
->type
== bp_hardware_watchpoint
9519 && bp
->val_valid
&& bp
->val
)
9521 struct bp_location
*loc
;
9523 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
9524 if (loc
->loc_type
== bp_loc_hardware_watchpoint
9525 && loc
->address
+ loc
->length
> addr
9526 && addr
+ len
> loc
->address
)
9528 value_free (bp
->val
);
9535 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
9537 struct symtabs_and_lines
9538 decode_line_spec_1 (char *string
, int funfirstline
)
9540 struct symtabs_and_lines sals
;
9542 error (_("Empty line specification."));
9543 if (default_breakpoint_valid
)
9544 sals
= decode_line_1 (&string
, funfirstline
,
9545 default_breakpoint_symtab
,
9546 default_breakpoint_line
,
9547 (char ***) NULL
, NULL
);
9549 sals
= decode_line_1 (&string
, funfirstline
,
9550 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
9552 error (_("Junk at end of line specification: %s"), string
);
9556 /* Create and insert a raw software breakpoint at PC. Return an
9557 identifier, which should be used to remove the breakpoint later.
9558 In general, places which call this should be using something on the
9559 breakpoint chain instead; this function should be eliminated
9563 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
9564 struct address_space
*aspace
, CORE_ADDR pc
)
9566 struct bp_target_info
*bp_tgt
;
9568 bp_tgt
= XZALLOC (struct bp_target_info
);
9570 bp_tgt
->placed_address_space
= aspace
;
9571 bp_tgt
->placed_address
= pc
;
9573 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
9575 /* Could not insert the breakpoint. */
9583 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
9586 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
9588 struct bp_target_info
*bp_tgt
= bp
;
9591 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
9597 /* One (or perhaps two) breakpoints used for software single stepping. */
9599 static void *single_step_breakpoints
[2];
9600 static struct gdbarch
*single_step_gdbarch
[2];
9602 /* Create and insert a breakpoint for software single step. */
9605 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
9606 struct address_space
*aspace
, CORE_ADDR next_pc
)
9610 if (single_step_breakpoints
[0] == NULL
)
9612 bpt_p
= &single_step_breakpoints
[0];
9613 single_step_gdbarch
[0] = gdbarch
;
9617 gdb_assert (single_step_breakpoints
[1] == NULL
);
9618 bpt_p
= &single_step_breakpoints
[1];
9619 single_step_gdbarch
[1] = gdbarch
;
9622 /* NOTE drow/2006-04-11: A future improvement to this function would be
9623 to only create the breakpoints once, and actually put them on the
9624 breakpoint chain. That would let us use set_raw_breakpoint. We could
9625 adjust the addresses each time they were needed. Doing this requires
9626 corresponding changes elsewhere where single step breakpoints are
9627 handled, however. So, for now, we use this. */
9629 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
9631 error (_("Could not insert single-step breakpoint at %s"),
9632 paddress (gdbarch
, next_pc
));
9635 /* Remove and delete any breakpoints used for software single step. */
9638 remove_single_step_breakpoints (void)
9640 gdb_assert (single_step_breakpoints
[0] != NULL
);
9642 /* See insert_single_step_breakpoint for more about this deprecated
9644 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
9645 single_step_breakpoints
[0]);
9646 single_step_gdbarch
[0] = NULL
;
9647 single_step_breakpoints
[0] = NULL
;
9649 if (single_step_breakpoints
[1] != NULL
)
9651 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
9652 single_step_breakpoints
[1]);
9653 single_step_gdbarch
[1] = NULL
;
9654 single_step_breakpoints
[1] = NULL
;
9658 /* Check whether a software single-step breakpoint is inserted at PC. */
9661 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
9665 for (i
= 0; i
< 2; i
++)
9667 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
9669 && breakpoint_address_match (bp_tgt
->placed_address_space
,
9670 bp_tgt
->placed_address
,
9678 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
9679 non-zero otherwise. */
9681 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
9683 if (syscall_catchpoint_p (bp
)
9684 && bp
->enable_state
!= bp_disabled
9685 && bp
->enable_state
!= bp_call_disabled
)
9692 catch_syscall_enabled (void)
9694 struct inferior
*inf
= current_inferior ();
9696 return inf
->total_syscalls_count
!= 0;
9700 catching_syscall_number (int syscall_number
)
9702 struct breakpoint
*bp
;
9704 ALL_BREAKPOINTS (bp
)
9705 if (is_syscall_catchpoint_enabled (bp
))
9707 if (bp
->syscalls_to_be_caught
)
9711 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
9713 if (syscall_number
== iter
)
9723 /* Complete syscall names. Used by "catch syscall". */
9725 catch_syscall_completer (struct cmd_list_element
*cmd
,
9726 char *text
, char *word
)
9728 const char **list
= get_syscall_names ();
9729 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
9732 /* Tracepoint-specific operations. */
9734 /* Set tracepoint count to NUM. */
9736 set_tracepoint_count (int num
)
9738 tracepoint_count
= num
;
9739 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
9743 trace_command (char *arg
, int from_tty
)
9745 break_command_really (get_current_arch (),
9747 NULL
, 0, 1 /* parse arg */,
9748 0 /* tempflag */, 0 /* hardwareflag */,
9750 0 /* Ignore count */,
9751 pending_break_support
,
9755 set_tracepoint_count (breakpoint_count
);
9758 /* Print information on tracepoint number TPNUM_EXP, or all if
9762 tracepoints_info (char *tpnum_exp
, int from_tty
)
9764 struct breakpoint
*b
;
9765 int tps_to_list
= 0;
9767 /* In the no-arguments case, say "No tracepoints" if none found. */
9780 ui_out_message (uiout
, 0, "No tracepoints.\n");
9785 /* Otherwise be the same as "info break". */
9786 breakpoints_info (tpnum_exp
, from_tty
);
9789 /* The 'enable trace' command enables tracepoints.
9790 Not supported by all targets. */
9792 enable_trace_command (char *args
, int from_tty
)
9794 enable_command (args
, from_tty
);
9797 /* The 'disable trace' command disables tracepoints.
9798 Not supported by all targets. */
9800 disable_trace_command (char *args
, int from_tty
)
9802 disable_command (args
, from_tty
);
9805 /* Remove a tracepoint (or all if no argument) */
9807 delete_trace_command (char *arg
, int from_tty
)
9809 struct breakpoint
*b
, *temp
;
9815 int breaks_to_delete
= 0;
9817 /* Delete all breakpoints if no argument.
9818 Do not delete internal or call-dummy breakpoints, these
9819 have to be deleted with an explicit breakpoint number argument. */
9824 breaks_to_delete
= 1;
9829 /* Ask user only if there are some breakpoints to delete. */
9831 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
9833 ALL_BREAKPOINTS_SAFE (b
, temp
)
9835 if (b
->type
== bp_tracepoint
9837 delete_breakpoint (b
);
9842 map_breakpoint_numbers (arg
, delete_breakpoint
);
9845 /* Set passcount for tracepoint.
9847 First command argument is passcount, second is tracepoint number.
9848 If tracepoint number omitted, apply to most recently defined.
9849 Also accepts special argument "all". */
9852 trace_pass_command (char *args
, int from_tty
)
9854 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
9858 if (args
== 0 || *args
== 0)
9859 error (_("passcount command requires an argument (count + optional TP num)"));
9861 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
9863 while (*args
&& isspace ((int) *args
))
9866 if (*args
&& strncasecmp (args
, "all", 3) == 0)
9868 args
+= 3; /* Skip special argument "all". */
9871 error (_("Junk at end of arguments."));
9874 t1
= get_tracepoint_by_number (&args
, 1, 1);
9880 ALL_TRACEPOINTS (t2
)
9881 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
9883 t2
->pass_count
= count
;
9884 observer_notify_tracepoint_modified (t2
->number
);
9886 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
9890 t1
= get_tracepoint_by_number (&args
, 1, 0);
9897 get_tracepoint (int num
)
9899 struct breakpoint
*t
;
9902 if (t
->number
== num
)
9908 /* Utility: parse a tracepoint number and look it up in the list.
9909 If MULTI_P is true, there might be a range of tracepoints in ARG.
9910 if OPTIONAL_P is true, then if the argument is missing, the most
9911 recent tracepoint (tracepoint_count) is returned. */
9913 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
9915 extern int tracepoint_count
;
9916 struct breakpoint
*t
;
9918 char *instring
= arg
== NULL
? NULL
: *arg
;
9920 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
9923 tpnum
= tracepoint_count
;
9925 error_no_arg (_("tracepoint number"));
9928 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
9932 if (instring
&& *instring
)
9933 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
9936 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
9941 if (t
->number
== tpnum
)
9946 /* FIXME: if we are in the middle of a range we don't want to give
9947 a message. The current interface to get_number_or_range doesn't
9948 allow us to discover this. */
9949 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
9953 /* save-tracepoints command */
9955 tracepoint_save_command (char *args
, int from_tty
)
9957 struct breakpoint
*tp
;
9959 struct action_line
*line
;
9961 char *i1
= " ", *i2
= " ";
9962 char *indent
, *actionline
, *pathname
;
9964 struct cleanup
*cleanup
;
9966 if (args
== 0 || *args
== 0)
9967 error (_("Argument required (file name in which to save tracepoints)"));
9969 /* See if we have anything to save. */
9970 ALL_TRACEPOINTS (tp
)
9977 warning (_("save-tracepoints: no tracepoints to save."));
9981 pathname
= tilde_expand (args
);
9982 cleanup
= make_cleanup (xfree
, pathname
);
9983 fp
= fopen (pathname
, "w");
9985 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
9986 args
, safe_strerror (errno
));
9987 make_cleanup_fclose (fp
);
9989 ALL_TRACEPOINTS (tp
)
9991 if (tp
->addr_string
)
9992 fprintf (fp
, "trace %s\n", tp
->addr_string
);
9995 sprintf_vma (tmp
, tp
->loc
->address
);
9996 fprintf (fp
, "trace *0x%s\n", tmp
);
10000 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
10004 fprintf (fp
, " actions\n");
10006 for (line
= tp
->actions
; line
; line
= line
->next
)
10008 struct cmd_list_element
*cmd
;
10010 QUIT
; /* allow user to bail out with ^C */
10011 actionline
= line
->action
;
10012 while (isspace ((int) *actionline
))
10015 fprintf (fp
, "%s%s\n", indent
, actionline
);
10016 if (*actionline
!= '#') /* skip for comment lines */
10018 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
10020 error (_("Bad action list item: %s"), actionline
);
10021 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
10023 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
10029 do_cleanups (cleanup
);
10031 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10035 /* Create a vector of all tracepoints. */
10037 VEC(breakpoint_p
) *
10040 VEC(breakpoint_p
) *tp_vec
= 0;
10041 struct breakpoint
*tp
;
10043 ALL_TRACEPOINTS (tp
)
10045 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10052 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10053 It is defined as a macro to prevent duplication.
10054 COMMAND should be a string constant containing the name of the command. */
10055 #define BREAK_ARGS_HELP(command) \
10056 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10057 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10058 If a line number is specified, break at start of code for that line.\n\
10059 If a function is specified, break at start of code for that function.\n\
10060 If an address is specified, break at that exact address.\n\
10061 With no LOCATION, uses current execution address of selected stack frame.\n\
10062 This is useful for breaking on return to a stack frame.\n\
10064 THREADNUM is the number from \"info threads\".\n\
10065 CONDITION is a boolean expression.\n\
10067 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10069 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10071 /* List of subcommands for "catch". */
10072 static struct cmd_list_element
*catch_cmdlist
;
10074 /* List of subcommands for "tcatch". */
10075 static struct cmd_list_element
*tcatch_cmdlist
;
10077 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10078 lists, and pass some additional user data to the command function. */
10080 add_catch_command (char *name
, char *docstring
,
10081 void (*sfunc
) (char *args
, int from_tty
,
10082 struct cmd_list_element
*command
),
10083 char **(*completer
) (struct cmd_list_element
*cmd
,
10084 char *text
, char *word
),
10085 void *user_data_catch
,
10086 void *user_data_tcatch
)
10088 struct cmd_list_element
*command
;
10090 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10092 set_cmd_sfunc (command
, sfunc
);
10093 set_cmd_context (command
, user_data_catch
);
10094 set_cmd_completer (command
, completer
);
10096 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10098 set_cmd_sfunc (command
, sfunc
);
10099 set_cmd_context (command
, user_data_tcatch
);
10100 set_cmd_completer (command
, completer
);
10104 clear_syscall_counts (int pid
)
10106 struct inferior
*inf
= find_inferior_pid (pid
);
10108 inf
->total_syscalls_count
= 0;
10109 inf
->any_syscall_count
= 0;
10110 VEC_free (int, inf
->syscalls_counts
);
10114 _initialize_breakpoint (void)
10116 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10117 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10118 struct cmd_list_element
*c
;
10120 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10121 observer_attach_inferior_exit (clear_syscall_counts
);
10122 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10124 breakpoint_chain
= 0;
10125 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10126 before a breakpoint is set. */
10127 breakpoint_count
= 0;
10129 tracepoint_count
= 0;
10131 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10132 Set ignore-count of breakpoint number N to COUNT.\n\
10133 Usage is `ignore N COUNT'."));
10135 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10137 add_com ("commands", class_breakpoint
, commands_command
, _("\
10138 Set commands to be executed when a breakpoint is hit.\n\
10139 Give breakpoint number as argument after \"commands\".\n\
10140 With no argument, the targeted breakpoint is the last one set.\n\
10141 The commands themselves follow starting on the next line.\n\
10142 Type a line containing \"end\" to indicate the end of them.\n\
10143 Give \"silent\" as the first line to make the breakpoint silent;\n\
10144 then no output is printed when it is hit, except what the commands print."));
10146 add_com ("condition", class_breakpoint
, condition_command
, _("\
10147 Specify breakpoint number N to break only if COND is true.\n\
10148 Usage is `condition N COND', where N is an integer and COND is an\n\
10149 expression to be evaluated whenever breakpoint N is reached."));
10151 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10152 Set a temporary breakpoint.\n\
10153 Like \"break\" except the breakpoint is only temporary,\n\
10154 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10155 by using \"enable delete\" on the breakpoint number.\n\
10157 BREAK_ARGS_HELP ("tbreak")));
10158 set_cmd_completer (c
, location_completer
);
10160 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10161 Set a hardware assisted breakpoint.\n\
10162 Like \"break\" except the breakpoint requires hardware support,\n\
10163 some target hardware may not have this support.\n\
10165 BREAK_ARGS_HELP ("hbreak")));
10166 set_cmd_completer (c
, location_completer
);
10168 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10169 Set a temporary hardware assisted breakpoint.\n\
10170 Like \"hbreak\" except the breakpoint is only temporary,\n\
10171 so it will be deleted when hit.\n\
10173 BREAK_ARGS_HELP ("thbreak")));
10174 set_cmd_completer (c
, location_completer
);
10176 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10177 Enable some breakpoints.\n\
10178 Give breakpoint numbers (separated by spaces) as arguments.\n\
10179 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10180 This is used to cancel the effect of the \"disable\" command.\n\
10181 With a subcommand you can enable temporarily."),
10182 &enablelist
, "enable ", 1, &cmdlist
);
10184 add_com ("ab", class_breakpoint
, enable_command
, _("\
10185 Enable some breakpoints.\n\
10186 Give breakpoint numbers (separated by spaces) as arguments.\n\
10187 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10188 This is used to cancel the effect of the \"disable\" command.\n\
10189 With a subcommand you can enable temporarily."));
10191 add_com_alias ("en", "enable", class_breakpoint
, 1);
10193 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10194 Enable some breakpoints.\n\
10195 Give breakpoint numbers (separated by spaces) as arguments.\n\
10196 This is used to cancel the effect of the \"disable\" command.\n\
10197 May be abbreviated to simply \"enable\".\n"),
10198 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10200 add_cmd ("once", no_class
, enable_once_command
, _("\
10201 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10202 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10205 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10206 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10207 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10210 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10211 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10212 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10215 add_cmd ("once", no_class
, enable_once_command
, _("\
10216 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10217 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10220 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10221 Disable some breakpoints.\n\
10222 Arguments are breakpoint numbers with spaces in between.\n\
10223 To disable all breakpoints, give no argument.\n\
10224 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10225 &disablelist
, "disable ", 1, &cmdlist
);
10226 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10227 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10229 add_com ("sb", class_breakpoint
, disable_command
, _("\
10230 Disable some breakpoints.\n\
10231 Arguments are breakpoint numbers with spaces in between.\n\
10232 To disable all breakpoints, give no argument.\n\
10233 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10235 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10236 Disable some breakpoints.\n\
10237 Arguments are breakpoint numbers with spaces in between.\n\
10238 To disable all breakpoints, give no argument.\n\
10239 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10240 This command may be abbreviated \"disable\"."),
10243 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10244 Delete some breakpoints or auto-display expressions.\n\
10245 Arguments are breakpoint numbers with spaces in between.\n\
10246 To delete all breakpoints, give no argument.\n\
10248 Also a prefix command for deletion of other GDB objects.\n\
10249 The \"unset\" command is also an alias for \"delete\"."),
10250 &deletelist
, "delete ", 1, &cmdlist
);
10251 add_com_alias ("d", "delete", class_breakpoint
, 1);
10252 add_com_alias ("del", "delete", class_breakpoint
, 1);
10254 add_com ("db", class_breakpoint
, delete_command
, _("\
10255 Delete some breakpoints.\n\
10256 Arguments are breakpoint numbers with spaces in between.\n\
10257 To delete all breakpoints, give no argument.\n"));
10259 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10260 Delete some breakpoints or auto-display expressions.\n\
10261 Arguments are breakpoint numbers with spaces in between.\n\
10262 To delete all breakpoints, give no argument.\n\
10263 This command may be abbreviated \"delete\"."),
10266 add_com ("clear", class_breakpoint
, clear_command
, _("\
10267 Clear breakpoint at specified line or function.\n\
10268 Argument may be line number, function name, or \"*\" and an address.\n\
10269 If line number is specified, all breakpoints in that line are cleared.\n\
10270 If function is specified, breakpoints at beginning of function are cleared.\n\
10271 If an address is specified, breakpoints at that address are cleared.\n\
10273 With no argument, clears all breakpoints in the line that the selected frame\n\
10274 is executing in.\n\
10276 See also the \"delete\" command which clears breakpoints by number."));
10278 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10279 Set breakpoint at specified line or function.\n"
10280 BREAK_ARGS_HELP ("break")));
10281 set_cmd_completer (c
, location_completer
);
10283 add_com_alias ("b", "break", class_run
, 1);
10284 add_com_alias ("br", "break", class_run
, 1);
10285 add_com_alias ("bre", "break", class_run
, 1);
10286 add_com_alias ("brea", "break", class_run
, 1);
10289 add_com_alias ("ba", "break", class_breakpoint
, 1);
10293 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10294 Break in function/address or break at a line in the current file."),
10295 &stoplist
, "stop ", 1, &cmdlist
);
10296 add_cmd ("in", class_breakpoint
, stopin_command
,
10297 _("Break in function or address."), &stoplist
);
10298 add_cmd ("at", class_breakpoint
, stopat_command
,
10299 _("Break at a line in the current file."), &stoplist
);
10300 add_com ("status", class_info
, breakpoints_info
, _("\
10301 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10302 The \"Type\" column indicates one of:\n\
10303 \tbreakpoint - normal breakpoint\n\
10304 \twatchpoint - watchpoint\n\
10305 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10306 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10307 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10308 address and file/line number respectively.\n\
10310 Convenience variable \"$_\" and default examine address for \"x\"\n\
10311 are set to the address of the last breakpoint listed unless the command\n\
10312 is prefixed with \"server \".\n\n\
10313 Convenience variable \"$bpnum\" contains the number of the last\n\
10314 breakpoint set."));
10317 add_info ("breakpoints", breakpoints_info
, _("\
10318 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10319 The \"Type\" column indicates one of:\n\
10320 \tbreakpoint - normal breakpoint\n\
10321 \twatchpoint - watchpoint\n\
10322 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10323 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10324 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10325 address and file/line number respectively.\n\
10327 Convenience variable \"$_\" and default examine address for \"x\"\n\
10328 are set to the address of the last breakpoint listed unless the command\n\
10329 is prefixed with \"server \".\n\n\
10330 Convenience variable \"$bpnum\" contains the number of the last\n\
10331 breakpoint set."));
10333 add_info_alias ("b", "breakpoints", 1);
10336 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
10337 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10338 The \"Type\" column indicates one of:\n\
10339 \tbreakpoint - normal breakpoint\n\
10340 \twatchpoint - watchpoint\n\
10341 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10342 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10343 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10344 address and file/line number respectively.\n\
10346 Convenience variable \"$_\" and default examine address for \"x\"\n\
10347 are set to the address of the last breakpoint listed unless the command\n\
10348 is prefixed with \"server \".\n\n\
10349 Convenience variable \"$bpnum\" contains the number of the last\n\
10350 breakpoint set."));
10352 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
10353 Status of all breakpoints, or breakpoint number NUMBER.\n\
10354 The \"Type\" column indicates one of:\n\
10355 \tbreakpoint - normal breakpoint\n\
10356 \twatchpoint - watchpoint\n\
10357 \tlongjmp - internal breakpoint used to step through longjmp()\n\
10358 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
10359 \tuntil - internal breakpoint used by the \"until\" command\n\
10360 \tfinish - internal breakpoint used by the \"finish\" command\n\
10361 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10362 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10363 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10364 address and file/line number respectively.\n\
10366 Convenience variable \"$_\" and default examine address for \"x\"\n\
10367 are set to the address of the last breakpoint listed unless the command\n\
10368 is prefixed with \"server \".\n\n\
10369 Convenience variable \"$bpnum\" contains the number of the last\n\
10371 &maintenanceinfolist
);
10373 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
10374 Set catchpoints to catch events."),
10375 &catch_cmdlist
, "catch ",
10376 0/*allow-unknown*/, &cmdlist
);
10378 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
10379 Set temporary catchpoints to catch events."),
10380 &tcatch_cmdlist
, "tcatch ",
10381 0/*allow-unknown*/, &cmdlist
);
10383 /* Add catch and tcatch sub-commands. */
10384 add_catch_command ("catch", _("\
10385 Catch an exception, when caught.\n\
10386 With an argument, catch only exceptions with the given name."),
10387 catch_catch_command
,
10391 add_catch_command ("throw", _("\
10392 Catch an exception, when thrown.\n\
10393 With an argument, catch only exceptions with the given name."),
10394 catch_throw_command
,
10398 add_catch_command ("fork", _("Catch calls to fork."),
10399 catch_fork_command_1
,
10401 (void *) (uintptr_t) catch_fork_permanent
,
10402 (void *) (uintptr_t) catch_fork_temporary
);
10403 add_catch_command ("vfork", _("Catch calls to vfork."),
10404 catch_fork_command_1
,
10406 (void *) (uintptr_t) catch_vfork_permanent
,
10407 (void *) (uintptr_t) catch_vfork_temporary
);
10408 add_catch_command ("exec", _("Catch calls to exec."),
10409 catch_exec_command_1
,
10413 add_catch_command ("syscall", _("\
10414 Catch system calls by their names and/or numbers.\n\
10415 Arguments say which system calls to catch. If no arguments\n\
10416 are given, every system call will be caught.\n\
10417 Arguments, if given, should be one or more system call names\n\
10418 (if your system supports that), or system call numbers."),
10419 catch_syscall_command_1
,
10420 catch_syscall_completer
,
10423 add_catch_command ("exception", _("\
10424 Catch Ada exceptions, when raised.\n\
10425 With an argument, catch only exceptions with the given name."),
10426 catch_ada_exception_command
,
10430 add_catch_command ("assert", _("\
10431 Catch failed Ada assertions, when raised.\n\
10432 With an argument, catch only exceptions with the given name."),
10433 catch_assert_command
,
10438 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
10439 Set a watchpoint for an expression.\n\
10440 A watchpoint stops execution of your program whenever the value of\n\
10441 an expression changes."));
10442 set_cmd_completer (c
, expression_completer
);
10444 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
10445 Set a read watchpoint for an expression.\n\
10446 A watchpoint stops execution of your program whenever the value of\n\
10447 an expression is read."));
10448 set_cmd_completer (c
, expression_completer
);
10450 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
10451 Set a watchpoint for an expression.\n\
10452 A watchpoint stops execution of your program whenever the value of\n\
10453 an expression is either read or written."));
10454 set_cmd_completer (c
, expression_completer
);
10456 add_info ("watchpoints", breakpoints_info
,
10457 _("Synonym for ``info breakpoints''."));
10460 /* XXX: cagney/2005-02-23: This should be a boolean, and should
10461 respond to changes - contrary to the description. */
10462 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
10463 &can_use_hw_watchpoints
, _("\
10464 Set debugger's willingness to use watchpoint hardware."), _("\
10465 Show debugger's willingness to use watchpoint hardware."), _("\
10466 If zero, gdb will not use hardware for new watchpoints, even if\n\
10467 such is available. (However, any hardware watchpoints that were\n\
10468 created before setting this to nonzero, will continue to use watchpoint\n\
10471 show_can_use_hw_watchpoints
,
10472 &setlist
, &showlist
);
10474 can_use_hw_watchpoints
= 1;
10476 /* Tracepoint manipulation commands. */
10478 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
10479 Set a tracepoint at specified line or function.\n\
10481 BREAK_ARGS_HELP ("trace") "\n\
10482 Do \"help tracepoints\" for info on other tracepoint commands."));
10483 set_cmd_completer (c
, location_completer
);
10485 add_com_alias ("tp", "trace", class_alias
, 0);
10486 add_com_alias ("tr", "trace", class_alias
, 1);
10487 add_com_alias ("tra", "trace", class_alias
, 1);
10488 add_com_alias ("trac", "trace", class_alias
, 1);
10490 add_info ("tracepoints", tracepoints_info
, _("\
10491 Status of tracepoints, or tracepoint number NUMBER.\n\
10492 Convenience variable \"$tpnum\" contains the number of the\n\
10493 last tracepoint set."));
10495 add_info_alias ("tp", "tracepoints", 1);
10497 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
10498 Delete specified tracepoints.\n\
10499 Arguments are tracepoint numbers, separated by spaces.\n\
10500 No argument means delete all tracepoints."),
10503 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
10504 Disable specified tracepoints.\n\
10505 Arguments are tracepoint numbers, separated by spaces.\n\
10506 No argument means disable all tracepoints."),
10508 deprecate_cmd (c
, "disable");
10510 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
10511 Enable specified tracepoints.\n\
10512 Arguments are tracepoint numbers, separated by spaces.\n\
10513 No argument means enable all tracepoints."),
10515 deprecate_cmd (c
, "enable");
10517 add_com ("passcount", class_trace
, trace_pass_command
, _("\
10518 Set the passcount for a tracepoint.\n\
10519 The trace will end when the tracepoint has been passed 'count' times.\n\
10520 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
10521 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
10523 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
10524 Save current tracepoint definitions as a script.\n\
10525 Use the 'source' command in another debug session to restore them."));
10526 set_cmd_completer (c
, filename_completer
);
10528 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
10529 Breakpoint specific settings\n\
10530 Configure various breakpoint-specific variables such as\n\
10531 pending breakpoint behavior"),
10532 &breakpoint_set_cmdlist
, "set breakpoint ",
10533 0/*allow-unknown*/, &setlist
);
10534 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
10535 Breakpoint specific settings\n\
10536 Configure various breakpoint-specific variables such as\n\
10537 pending breakpoint behavior"),
10538 &breakpoint_show_cmdlist
, "show breakpoint ",
10539 0/*allow-unknown*/, &showlist
);
10541 add_setshow_auto_boolean_cmd ("pending", no_class
,
10542 &pending_break_support
, _("\
10543 Set debugger's behavior regarding pending breakpoints."), _("\
10544 Show debugger's behavior regarding pending breakpoints."), _("\
10545 If on, an unrecognized breakpoint location will cause gdb to create a\n\
10546 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
10547 an error. If auto, an unrecognized breakpoint location results in a\n\
10548 user-query to see if a pending breakpoint should be created."),
10550 show_pending_break_support
,
10551 &breakpoint_set_cmdlist
,
10552 &breakpoint_show_cmdlist
);
10554 pending_break_support
= AUTO_BOOLEAN_AUTO
;
10556 add_setshow_boolean_cmd ("auto-hw", no_class
,
10557 &automatic_hardware_breakpoints
, _("\
10558 Set automatic usage of hardware breakpoints."), _("\
10559 Show automatic usage of hardware breakpoints."), _("\
10560 If set, the debugger will automatically use hardware breakpoints for\n\
10561 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
10562 a warning will be emitted for such breakpoints."),
10564 show_automatic_hardware_breakpoints
,
10565 &breakpoint_set_cmdlist
,
10566 &breakpoint_show_cmdlist
);
10568 add_setshow_enum_cmd ("always-inserted", class_support
,
10569 always_inserted_enums
, &always_inserted_mode
, _("\
10570 Set mode for inserting breakpoints."), _("\
10571 Show mode for inserting breakpoints."), _("\
10572 When this mode is off, breakpoints are inserted in inferior when it is\n\
10573 resumed, and removed when execution stops. When this mode is on,\n\
10574 breakpoints are inserted immediately and removed only when the user\n\
10575 deletes the breakpoint. When this mode is auto (which is the default),\n\
10576 the behaviour depends on the non-stop setting (see help set non-stop).\n\
10577 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
10578 behaves as if always-inserted mode is on; if gdb is controlling the\n\
10579 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
10581 &show_always_inserted_mode
,
10582 &breakpoint_set_cmdlist
,
10583 &breakpoint_show_cmdlist
);
10585 automatic_hardware_breakpoints
= 1;
10587 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);