1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "cli/cli-utils.h"
64 #include "continuations.h"
67 #include "gdb_regex.h"
70 /* readline include files */
71 #include "readline/readline.h"
72 #include "readline/history.h"
74 /* readline defines this. */
77 #include "mi/mi-common.h"
78 #include "python/python.h"
80 /* Prototypes for local functions. */
82 static void enable_delete_command (char *, int);
84 static void enable_once_command (char *, int);
86 static void enable_count_command (char *, int);
88 static void disable_command (char *, int);
90 static void enable_command (char *, int);
92 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
96 static void ignore_command (char *, int);
98 static int breakpoint_re_set_one (void *);
100 static void breakpoint_re_set_default (struct breakpoint
*);
102 static void create_sals_from_address_default (char **,
103 struct linespec_result
*,
107 static void create_breakpoints_sal_default (struct gdbarch
*,
108 struct linespec_result
*,
109 struct linespec_sals
*,
111 enum bpdisp
, int, int,
113 const struct breakpoint_ops
*,
114 int, int, int, unsigned);
116 static void decode_linespec_default (struct breakpoint
*, char **,
117 struct symtabs_and_lines
*);
119 static void clear_command (char *, int);
121 static void catch_command (char *, int);
123 static int can_use_hardware_watchpoint (struct value
*);
125 static void break_command_1 (char *, int, int);
127 static void mention (struct breakpoint
*);
129 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
131 const struct breakpoint_ops
*);
132 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
133 const struct symtab_and_line
*);
135 /* This function is used in gdbtk sources and thus can not be made
137 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
138 struct symtab_and_line
,
140 const struct breakpoint_ops
*);
142 static struct breakpoint
*
143 momentary_breakpoint_from_master (struct breakpoint
*orig
,
145 const struct breakpoint_ops
*ops
);
147 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
149 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
153 static void describe_other_breakpoints (struct gdbarch
*,
154 struct program_space
*, CORE_ADDR
,
155 struct obj_section
*, int);
157 static int breakpoint_address_match (struct address_space
*aspace1
,
159 struct address_space
*aspace2
,
162 static int watchpoint_locations_match (struct bp_location
*loc1
,
163 struct bp_location
*loc2
);
165 static int breakpoint_location_address_match (struct bp_location
*bl
,
166 struct address_space
*aspace
,
169 static void breakpoints_info (char *, int);
171 static void watchpoints_info (char *, int);
173 static int breakpoint_1 (char *, int,
174 int (*) (const struct breakpoint
*));
176 static int breakpoint_cond_eval (void *);
178 static void cleanup_executing_breakpoints (void *);
180 static void commands_command (char *, int);
182 static void condition_command (char *, int);
191 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
192 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
194 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
196 static int watchpoint_check (void *);
198 static void maintenance_info_breakpoints (char *, int);
200 static int hw_breakpoint_used_count (void);
202 static int hw_watchpoint_use_count (struct breakpoint
*);
204 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
206 int *other_type_used
);
208 static void hbreak_command (char *, int);
210 static void thbreak_command (char *, int);
212 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
215 static void stop_command (char *arg
, int from_tty
);
217 static void stopin_command (char *arg
, int from_tty
);
219 static void stopat_command (char *arg
, int from_tty
);
221 static char *ep_parse_optional_if_clause (char **arg
);
223 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
224 char *arg
, int tempflag
, int from_tty
);
226 static void tcatch_command (char *arg
, int from_tty
);
228 static void detach_single_step_breakpoints (void);
230 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
233 static void free_bp_location (struct bp_location
*loc
);
234 static void incref_bp_location (struct bp_location
*loc
);
235 static void decref_bp_location (struct bp_location
**loc
);
237 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
239 static void update_global_location_list (int);
241 static void update_global_location_list_nothrow (int);
243 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
245 static void insert_breakpoint_locations (void);
247 static int syscall_catchpoint_p (struct breakpoint
*b
);
249 static void tracepoints_info (char *, int);
251 static void delete_trace_command (char *, int);
253 static void enable_trace_command (char *, int);
255 static void disable_trace_command (char *, int);
257 static void trace_pass_command (char *, int);
259 static int is_masked_watchpoint (const struct breakpoint
*b
);
261 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
263 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
266 static int strace_marker_p (struct breakpoint
*b
);
268 static void init_catchpoint (struct breakpoint
*b
,
269 struct gdbarch
*gdbarch
, int tempflag
,
271 const struct breakpoint_ops
*ops
);
273 /* The abstract base class all breakpoint_ops structures inherit
275 static struct breakpoint_ops base_breakpoint_ops
;
277 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
278 that are implemented on top of software or hardware breakpoints
279 (user breakpoints, internal and momentary breakpoints, etc.). */
280 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
282 /* Internal breakpoints class type. */
283 static struct breakpoint_ops internal_breakpoint_ops
;
285 /* Momentary breakpoints class type. */
286 static struct breakpoint_ops momentary_breakpoint_ops
;
288 /* The breakpoint_ops structure to be used in regular user created
290 struct breakpoint_ops bkpt_breakpoint_ops
;
292 /* A reference-counted struct command_line. This lets multiple
293 breakpoints share a single command list. */
294 struct counted_command_line
296 /* The reference count. */
299 /* The command list. */
300 struct command_line
*commands
;
303 struct command_line
*
304 breakpoint_commands (struct breakpoint
*b
)
306 return b
->commands
? b
->commands
->commands
: NULL
;
309 /* Flag indicating that a command has proceeded the inferior past the
310 current breakpoint. */
312 static int breakpoint_proceeded
;
315 bpdisp_text (enum bpdisp disp
)
317 /* NOTE: the following values are a part of MI protocol and
318 represent values of 'disp' field returned when inferior stops at
320 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
322 return bpdisps
[(int) disp
];
325 /* Prototypes for exported functions. */
326 /* If FALSE, gdb will not use hardware support for watchpoints, even
327 if such is available. */
328 static int can_use_hw_watchpoints
;
331 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
332 struct cmd_list_element
*c
,
335 fprintf_filtered (file
,
336 _("Debugger's willingness to use "
337 "watchpoint hardware is %s.\n"),
341 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
342 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
343 for unrecognized breakpoint locations.
344 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
345 static enum auto_boolean pending_break_support
;
347 show_pending_break_support (struct ui_file
*file
, int from_tty
,
348 struct cmd_list_element
*c
,
351 fprintf_filtered (file
,
352 _("Debugger's behavior regarding "
353 "pending breakpoints is %s.\n"),
357 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
358 set with "break" but falling in read-only memory.
359 If 0, gdb will warn about such breakpoints, but won't automatically
360 use hardware breakpoints. */
361 static int automatic_hardware_breakpoints
;
363 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
364 struct cmd_list_element
*c
,
367 fprintf_filtered (file
,
368 _("Automatic usage of hardware breakpoints is %s.\n"),
372 /* If on, gdb will keep breakpoints inserted even as inferior is
373 stopped, and immediately insert any new breakpoints. If off, gdb
374 will insert breakpoints into inferior only when resuming it, and
375 will remove breakpoints upon stop. If auto, GDB will behave as ON
376 if in non-stop mode, and as OFF if all-stop mode.*/
378 static const char always_inserted_auto
[] = "auto";
379 static const char always_inserted_on
[] = "on";
380 static const char always_inserted_off
[] = "off";
381 static const char *const always_inserted_enums
[] = {
382 always_inserted_auto
,
387 static const char *always_inserted_mode
= always_inserted_auto
;
389 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
390 struct cmd_list_element
*c
, const char *value
)
392 if (always_inserted_mode
== always_inserted_auto
)
393 fprintf_filtered (file
,
394 _("Always inserted breakpoint "
395 "mode is %s (currently %s).\n"),
397 breakpoints_always_inserted_mode () ? "on" : "off");
399 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
404 breakpoints_always_inserted_mode (void)
406 return (always_inserted_mode
== always_inserted_on
407 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
410 static const char condition_evaluation_both
[] = "host or target";
412 /* Modes for breakpoint condition evaluation. */
413 static const char condition_evaluation_auto
[] = "auto";
414 static const char condition_evaluation_host
[] = "host";
415 static const char condition_evaluation_target
[] = "target";
416 static const char *const condition_evaluation_enums
[] = {
417 condition_evaluation_auto
,
418 condition_evaluation_host
,
419 condition_evaluation_target
,
423 /* Global that holds the current mode for breakpoint condition evaluation. */
424 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
426 /* Global that we use to display information to the user (gets its value from
427 condition_evaluation_mode_1. */
428 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
430 /* Translate a condition evaluation mode MODE into either "host"
431 or "target". This is used mostly to translate from "auto" to the
432 real setting that is being used. It returns the translated
436 translate_condition_evaluation_mode (const char *mode
)
438 if (mode
== condition_evaluation_auto
)
440 if (target_supports_evaluation_of_breakpoint_conditions ())
441 return condition_evaluation_target
;
443 return condition_evaluation_host
;
449 /* Discovers what condition_evaluation_auto translates to. */
452 breakpoint_condition_evaluation_mode (void)
454 return translate_condition_evaluation_mode (condition_evaluation_mode
);
457 /* Return true if GDB should evaluate breakpoint conditions or false
461 gdb_evaluates_breakpoint_condition_p (void)
463 const char *mode
= breakpoint_condition_evaluation_mode ();
465 return (mode
== condition_evaluation_host
);
468 void _initialize_breakpoint (void);
470 /* Are we executing breakpoint commands? */
471 static int executing_breakpoint_commands
;
473 /* Are overlay event breakpoints enabled? */
474 static int overlay_events_enabled
;
476 /* See description in breakpoint.h. */
477 int target_exact_watchpoints
= 0;
479 /* Walk the following statement or block through all breakpoints.
480 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
481 current breakpoint. */
483 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
485 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
486 for (B = breakpoint_chain; \
487 B ? (TMP=B->next, 1): 0; \
490 /* Similar iterator for the low-level breakpoints. SAFE variant is
491 not provided so update_global_location_list must not be called
492 while executing the block of ALL_BP_LOCATIONS. */
494 #define ALL_BP_LOCATIONS(B,BP_TMP) \
495 for (BP_TMP = bp_location; \
496 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
499 /* Iterates through locations with address ADDRESS for the currently selected
500 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
501 to where the loop should start from.
502 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
503 appropriate location to start with. */
505 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
506 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
507 BP_LOCP_TMP = BP_LOCP_START; \
509 && (BP_LOCP_TMP < bp_location + bp_location_count \
510 && (*BP_LOCP_TMP)->address == ADDRESS); \
513 /* Iterator for tracepoints only. */
515 #define ALL_TRACEPOINTS(B) \
516 for (B = breakpoint_chain; B; B = B->next) \
517 if (is_tracepoint (B))
519 /* Chains of all breakpoints defined. */
521 struct breakpoint
*breakpoint_chain
;
523 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
525 static struct bp_location
**bp_location
;
527 /* Number of elements of BP_LOCATION. */
529 static unsigned bp_location_count
;
531 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
532 ADDRESS for the current elements of BP_LOCATION which get a valid
533 result from bp_location_has_shadow. You can use it for roughly
534 limiting the subrange of BP_LOCATION to scan for shadow bytes for
535 an address you need to read. */
537 static CORE_ADDR bp_location_placed_address_before_address_max
;
539 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
540 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
541 BP_LOCATION which get a valid result from bp_location_has_shadow.
542 You can use it for roughly limiting the subrange of BP_LOCATION to
543 scan for shadow bytes for an address you need to read. */
545 static CORE_ADDR bp_location_shadow_len_after_address_max
;
547 /* The locations that no longer correspond to any breakpoint, unlinked
548 from bp_location array, but for which a hit may still be reported
550 VEC(bp_location_p
) *moribund_locations
= NULL
;
552 /* Number of last breakpoint made. */
554 static int breakpoint_count
;
556 /* The value of `breakpoint_count' before the last command that
557 created breakpoints. If the last (break-like) command created more
558 than one breakpoint, then the difference between BREAKPOINT_COUNT
559 and PREV_BREAKPOINT_COUNT is more than one. */
560 static int prev_breakpoint_count
;
562 /* Number of last tracepoint made. */
564 static int tracepoint_count
;
566 static struct cmd_list_element
*breakpoint_set_cmdlist
;
567 static struct cmd_list_element
*breakpoint_show_cmdlist
;
568 struct cmd_list_element
*save_cmdlist
;
570 /* Return whether a breakpoint is an active enabled breakpoint. */
572 breakpoint_enabled (struct breakpoint
*b
)
574 return (b
->enable_state
== bp_enabled
);
577 /* Set breakpoint count to NUM. */
580 set_breakpoint_count (int num
)
582 prev_breakpoint_count
= breakpoint_count
;
583 breakpoint_count
= num
;
584 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
587 /* Used by `start_rbreak_breakpoints' below, to record the current
588 breakpoint count before "rbreak" creates any breakpoint. */
589 static int rbreak_start_breakpoint_count
;
591 /* Called at the start an "rbreak" command to record the first
595 start_rbreak_breakpoints (void)
597 rbreak_start_breakpoint_count
= breakpoint_count
;
600 /* Called at the end of an "rbreak" command to record the last
604 end_rbreak_breakpoints (void)
606 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
609 /* Used in run_command to zero the hit count when a new run starts. */
612 clear_breakpoint_hit_counts (void)
614 struct breakpoint
*b
;
620 /* Allocate a new counted_command_line with reference count of 1.
621 The new structure owns COMMANDS. */
623 static struct counted_command_line
*
624 alloc_counted_command_line (struct command_line
*commands
)
626 struct counted_command_line
*result
627 = xmalloc (sizeof (struct counted_command_line
));
630 result
->commands
= commands
;
634 /* Increment reference count. This does nothing if CMD is NULL. */
637 incref_counted_command_line (struct counted_command_line
*cmd
)
643 /* Decrement reference count. If the reference count reaches 0,
644 destroy the counted_command_line. Sets *CMDP to NULL. This does
645 nothing if *CMDP is NULL. */
648 decref_counted_command_line (struct counted_command_line
**cmdp
)
652 if (--(*cmdp
)->refc
== 0)
654 free_command_lines (&(*cmdp
)->commands
);
661 /* A cleanup function that calls decref_counted_command_line. */
664 do_cleanup_counted_command_line (void *arg
)
666 decref_counted_command_line (arg
);
669 /* Create a cleanup that calls decref_counted_command_line on the
672 static struct cleanup
*
673 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
675 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
679 /* Return the breakpoint with the specified number, or NULL
680 if the number does not refer to an existing breakpoint. */
683 get_breakpoint (int num
)
685 struct breakpoint
*b
;
688 if (b
->number
== num
)
696 /* Mark locations as "conditions have changed" in case the target supports
697 evaluating conditions on its side. */
700 mark_breakpoint_modified (struct breakpoint
*b
)
702 struct bp_location
*loc
;
704 /* This is only meaningful if the target is
705 evaluating conditions and if the user has
706 opted for condition evaluation on the target's
708 if (gdb_evaluates_breakpoint_condition_p ()
709 || !target_supports_evaluation_of_breakpoint_conditions ())
712 if (!is_breakpoint (b
))
715 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
716 loc
->condition_changed
= condition_modified
;
719 /* Mark location as "conditions have changed" in case the target supports
720 evaluating conditions on its side. */
723 mark_breakpoint_location_modified (struct bp_location
*loc
)
725 /* This is only meaningful if the target is
726 evaluating conditions and if the user has
727 opted for condition evaluation on the target's
729 if (gdb_evaluates_breakpoint_condition_p ()
730 || !target_supports_evaluation_of_breakpoint_conditions ())
734 if (!is_breakpoint (loc
->owner
))
737 loc
->condition_changed
= condition_modified
;
740 /* Sets the condition-evaluation mode using the static global
741 condition_evaluation_mode. */
744 set_condition_evaluation_mode (char *args
, int from_tty
,
745 struct cmd_list_element
*c
)
747 struct breakpoint
*b
;
748 const char *old_mode
, *new_mode
;
750 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
751 && !target_supports_evaluation_of_breakpoint_conditions ())
753 condition_evaluation_mode_1
= condition_evaluation_mode
;
754 warning (_("Target does not support breakpoint condition evaluation.\n"
755 "Using host evaluation mode instead."));
759 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
760 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
762 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
763 settings was "auto". */
764 condition_evaluation_mode
= condition_evaluation_mode_1
;
766 /* Only update the mode if the user picked a different one. */
767 if (new_mode
!= old_mode
)
769 struct bp_location
*loc
, **loc_tmp
;
770 /* If the user switched to a different evaluation mode, we
771 need to synch the changes with the target as follows:
773 "host" -> "target": Send all (valid) conditions to the target.
774 "target" -> "host": Remove all the conditions from the target.
777 if (new_mode
== condition_evaluation_target
)
779 /* Mark everything modified and synch conditions with the
781 ALL_BP_LOCATIONS (loc
, loc_tmp
)
782 mark_breakpoint_location_modified (loc
);
786 /* Manually mark non-duplicate locations to synch conditions
787 with the target. We do this to remove all the conditions the
788 target knows about. */
789 ALL_BP_LOCATIONS (loc
, loc_tmp
)
790 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
791 loc
->needs_update
= 1;
795 update_global_location_list (1);
801 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
802 what "auto" is translating to. */
805 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
806 struct cmd_list_element
*c
, const char *value
)
808 if (condition_evaluation_mode
== condition_evaluation_auto
)
809 fprintf_filtered (file
,
810 _("Breakpoint condition evaluation "
811 "mode is %s (currently %s).\n"),
813 breakpoint_condition_evaluation_mode ());
815 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
819 /* A comparison function for bp_location AP and BP that is used by
820 bsearch. This comparison function only cares about addresses, unlike
821 the more general bp_location_compare function. */
824 bp_location_compare_addrs (const void *ap
, const void *bp
)
826 struct bp_location
*a
= *(void **) ap
;
827 struct bp_location
*b
= *(void **) bp
;
829 if (a
->address
== b
->address
)
832 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
835 /* Helper function to skip all bp_locations with addresses
836 less than ADDRESS. It returns the first bp_location that
837 is greater than or equal to ADDRESS. If none is found, just
840 static struct bp_location
**
841 get_first_locp_gte_addr (CORE_ADDR address
)
843 struct bp_location dummy_loc
;
844 struct bp_location
*dummy_locp
= &dummy_loc
;
845 struct bp_location
**locp_found
= NULL
;
847 /* Initialize the dummy location's address field. */
848 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
849 dummy_loc
.address
= address
;
851 /* Find a close match to the first location at ADDRESS. */
852 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
853 sizeof (struct bp_location
**),
854 bp_location_compare_addrs
);
856 /* Nothing was found, nothing left to do. */
857 if (locp_found
== NULL
)
860 /* We may have found a location that is at ADDRESS but is not the first in the
861 location's list. Go backwards (if possible) and locate the first one. */
862 while ((locp_found
- 1) >= bp_location
863 && (*(locp_found
- 1))->address
== address
)
870 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
873 xfree (b
->cond_string
);
874 b
->cond_string
= NULL
;
876 if (is_watchpoint (b
))
878 struct watchpoint
*w
= (struct watchpoint
*) b
;
885 struct bp_location
*loc
;
887 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
892 /* No need to free the condition agent expression
893 bytecode (if we have one). We will handle this
894 when we go through update_global_location_list. */
901 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
907 /* I don't know if it matters whether this is the string the user
908 typed in or the decompiled expression. */
909 b
->cond_string
= xstrdup (arg
);
910 b
->condition_not_parsed
= 0;
912 if (is_watchpoint (b
))
914 struct watchpoint
*w
= (struct watchpoint
*) b
;
916 innermost_block
= NULL
;
918 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
920 error (_("Junk at end of expression"));
921 w
->cond_exp_valid_block
= innermost_block
;
925 struct bp_location
*loc
;
927 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
931 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
933 error (_("Junk at end of expression"));
937 mark_breakpoint_modified (b
);
939 breakpoints_changed ();
940 observer_notify_breakpoint_modified (b
);
943 /* condition N EXP -- set break condition of breakpoint N to EXP. */
946 condition_command (char *arg
, int from_tty
)
948 struct breakpoint
*b
;
953 error_no_arg (_("breakpoint number"));
956 bnum
= get_number (&p
);
958 error (_("Bad breakpoint argument: '%s'"), arg
);
961 if (b
->number
== bnum
)
963 /* Check if this breakpoint has a Python object assigned to
964 it, and if it has a definition of the "stop"
965 method. This method and conditions entered into GDB from
966 the CLI are mutually exclusive. */
968 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
969 error (_("Cannot set a condition where a Python 'stop' "
970 "method has been defined in the breakpoint."));
971 set_breakpoint_condition (b
, p
, from_tty
);
973 if (is_breakpoint (b
))
974 update_global_location_list (1);
979 error (_("No breakpoint number %d."), bnum
);
982 /* Check that COMMAND do not contain commands that are suitable
983 only for tracepoints and not suitable for ordinary breakpoints.
984 Throw if any such commands is found. */
987 check_no_tracepoint_commands (struct command_line
*commands
)
989 struct command_line
*c
;
991 for (c
= commands
; c
; c
= c
->next
)
995 if (c
->control_type
== while_stepping_control
)
996 error (_("The 'while-stepping' command can "
997 "only be used for tracepoints"));
999 for (i
= 0; i
< c
->body_count
; ++i
)
1000 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1002 /* Not that command parsing removes leading whitespace and comment
1003 lines and also empty lines. So, we only need to check for
1004 command directly. */
1005 if (strstr (c
->line
, "collect ") == c
->line
)
1006 error (_("The 'collect' command can only be used for tracepoints"));
1008 if (strstr (c
->line
, "teval ") == c
->line
)
1009 error (_("The 'teval' command can only be used for tracepoints"));
1013 /* Encapsulate tests for different types of tracepoints. */
1016 is_tracepoint_type (enum bptype type
)
1018 return (type
== bp_tracepoint
1019 || type
== bp_fast_tracepoint
1020 || type
== bp_static_tracepoint
);
1024 is_tracepoint (const struct breakpoint
*b
)
1026 return is_tracepoint_type (b
->type
);
1029 /* A helper function that validates that COMMANDS are valid for a
1030 breakpoint. This function will throw an exception if a problem is
1034 validate_commands_for_breakpoint (struct breakpoint
*b
,
1035 struct command_line
*commands
)
1037 if (is_tracepoint (b
))
1039 /* We need to verify that each top-level element of commands is
1040 valid for tracepoints, that there's at most one
1041 while-stepping element, and that while-stepping's body has
1042 valid tracing commands excluding nested while-stepping. */
1043 struct command_line
*c
;
1044 struct command_line
*while_stepping
= 0;
1045 for (c
= commands
; c
; c
= c
->next
)
1047 if (c
->control_type
== while_stepping_control
)
1049 if (b
->type
== bp_fast_tracepoint
)
1050 error (_("The 'while-stepping' command "
1051 "cannot be used for fast tracepoint"));
1052 else if (b
->type
== bp_static_tracepoint
)
1053 error (_("The 'while-stepping' command "
1054 "cannot be used for static tracepoint"));
1057 error (_("The 'while-stepping' command "
1058 "can be used only once"));
1065 struct command_line
*c2
;
1067 gdb_assert (while_stepping
->body_count
== 1);
1068 c2
= while_stepping
->body_list
[0];
1069 for (; c2
; c2
= c2
->next
)
1071 if (c2
->control_type
== while_stepping_control
)
1072 error (_("The 'while-stepping' command cannot be nested"));
1078 check_no_tracepoint_commands (commands
);
1082 /* Return a vector of all the static tracepoints set at ADDR. The
1083 caller is responsible for releasing the vector. */
1086 static_tracepoints_here (CORE_ADDR addr
)
1088 struct breakpoint
*b
;
1089 VEC(breakpoint_p
) *found
= 0;
1090 struct bp_location
*loc
;
1093 if (b
->type
== bp_static_tracepoint
)
1095 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1096 if (loc
->address
== addr
)
1097 VEC_safe_push(breakpoint_p
, found
, b
);
1103 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1104 validate that only allowed commands are included. */
1107 breakpoint_set_commands (struct breakpoint
*b
,
1108 struct command_line
*commands
)
1110 validate_commands_for_breakpoint (b
, commands
);
1112 decref_counted_command_line (&b
->commands
);
1113 b
->commands
= alloc_counted_command_line (commands
);
1114 breakpoints_changed ();
1115 observer_notify_breakpoint_modified (b
);
1118 /* Set the internal `silent' flag on the breakpoint. Note that this
1119 is not the same as the "silent" that may appear in the breakpoint's
1123 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1125 int old_silent
= b
->silent
;
1128 if (old_silent
!= silent
)
1129 observer_notify_breakpoint_modified (b
);
1132 /* Set the thread for this breakpoint. If THREAD is -1, make the
1133 breakpoint work for any thread. */
1136 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1138 int old_thread
= b
->thread
;
1141 if (old_thread
!= thread
)
1142 observer_notify_breakpoint_modified (b
);
1145 /* Set the task for this breakpoint. If TASK is 0, make the
1146 breakpoint work for any task. */
1149 breakpoint_set_task (struct breakpoint
*b
, int task
)
1151 int old_task
= b
->task
;
1154 if (old_task
!= task
)
1155 observer_notify_breakpoint_modified (b
);
1159 check_tracepoint_command (char *line
, void *closure
)
1161 struct breakpoint
*b
= closure
;
1163 validate_actionline (&line
, b
);
1166 /* A structure used to pass information through
1167 map_breakpoint_numbers. */
1169 struct commands_info
1171 /* True if the command was typed at a tty. */
1174 /* The breakpoint range spec. */
1177 /* Non-NULL if the body of the commands are being read from this
1178 already-parsed command. */
1179 struct command_line
*control
;
1181 /* The command lines read from the user, or NULL if they have not
1183 struct counted_command_line
*cmd
;
1186 /* A callback for map_breakpoint_numbers that sets the commands for
1187 commands_command. */
1190 do_map_commands_command (struct breakpoint
*b
, void *data
)
1192 struct commands_info
*info
= data
;
1194 if (info
->cmd
== NULL
)
1196 struct command_line
*l
;
1198 if (info
->control
!= NULL
)
1199 l
= copy_command_lines (info
->control
->body_list
[0]);
1202 struct cleanup
*old_chain
;
1205 str
= xstrprintf (_("Type commands for breakpoint(s) "
1206 "%s, one per line."),
1209 old_chain
= make_cleanup (xfree
, str
);
1211 l
= read_command_lines (str
,
1214 ? check_tracepoint_command
: 0),
1217 do_cleanups (old_chain
);
1220 info
->cmd
= alloc_counted_command_line (l
);
1223 /* If a breakpoint was on the list more than once, we don't need to
1225 if (b
->commands
!= info
->cmd
)
1227 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1228 incref_counted_command_line (info
->cmd
);
1229 decref_counted_command_line (&b
->commands
);
1230 b
->commands
= info
->cmd
;
1231 breakpoints_changed ();
1232 observer_notify_breakpoint_modified (b
);
1237 commands_command_1 (char *arg
, int from_tty
,
1238 struct command_line
*control
)
1240 struct cleanup
*cleanups
;
1241 struct commands_info info
;
1243 info
.from_tty
= from_tty
;
1244 info
.control
= control
;
1246 /* If we read command lines from the user, then `info' will hold an
1247 extra reference to the commands that we must clean up. */
1248 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1250 if (arg
== NULL
|| !*arg
)
1252 if (breakpoint_count
- prev_breakpoint_count
> 1)
1253 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1255 else if (breakpoint_count
> 0)
1256 arg
= xstrprintf ("%d", breakpoint_count
);
1259 /* So that we don't try to free the incoming non-NULL
1260 argument in the cleanup below. Mapping breakpoint
1261 numbers will fail in this case. */
1266 /* The command loop has some static state, so we need to preserve
1268 arg
= xstrdup (arg
);
1271 make_cleanup (xfree
, arg
);
1275 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1277 if (info
.cmd
== NULL
)
1278 error (_("No breakpoints specified."));
1280 do_cleanups (cleanups
);
1284 commands_command (char *arg
, int from_tty
)
1286 commands_command_1 (arg
, from_tty
, NULL
);
1289 /* Like commands_command, but instead of reading the commands from
1290 input stream, takes them from an already parsed command structure.
1292 This is used by cli-script.c to DTRT with breakpoint commands
1293 that are part of if and while bodies. */
1294 enum command_control_type
1295 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1297 commands_command_1 (arg
, 0, cmd
);
1298 return simple_control
;
1301 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1304 bp_location_has_shadow (struct bp_location
*bl
)
1306 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1310 if (bl
->target_info
.shadow_len
== 0)
1311 /* BL isn't valid, or doesn't shadow memory. */
1316 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1317 by replacing any memory breakpoints with their shadowed contents.
1319 If READBUF is not NULL, this buffer must not overlap with any of
1320 the breakpoint location's shadow_contents buffers. Otherwise,
1321 a failed assertion internal error will be raised.
1323 The range of shadowed area by each bp_location is:
1324 bl->address - bp_location_placed_address_before_address_max
1325 up to bl->address + bp_location_shadow_len_after_address_max
1326 The range we were requested to resolve shadows for is:
1327 memaddr ... memaddr + len
1328 Thus the safe cutoff boundaries for performance optimization are
1329 memaddr + len <= (bl->address
1330 - bp_location_placed_address_before_address_max)
1332 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1335 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1336 const gdb_byte
*writebuf_org
,
1337 ULONGEST memaddr
, LONGEST len
)
1339 /* Left boundary, right boundary and median element of our binary
1341 unsigned bc_l
, bc_r
, bc
;
1343 /* Find BC_L which is a leftmost element which may affect BUF
1344 content. It is safe to report lower value but a failure to
1345 report higher one. */
1348 bc_r
= bp_location_count
;
1349 while (bc_l
+ 1 < bc_r
)
1351 struct bp_location
*bl
;
1353 bc
= (bc_l
+ bc_r
) / 2;
1354 bl
= bp_location
[bc
];
1356 /* Check first BL->ADDRESS will not overflow due to the added
1357 constant. Then advance the left boundary only if we are sure
1358 the BC element can in no way affect the BUF content (MEMADDR
1359 to MEMADDR + LEN range).
1361 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1362 offset so that we cannot miss a breakpoint with its shadow
1363 range tail still reaching MEMADDR. */
1365 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1367 && (bl
->address
+ bp_location_shadow_len_after_address_max
1374 /* Due to the binary search above, we need to make sure we pick the
1375 first location that's at BC_L's address. E.g., if there are
1376 multiple locations at the same address, BC_L may end up pointing
1377 at a duplicate location, and miss the "master"/"inserted"
1378 location. Say, given locations L1, L2 and L3 at addresses A and
1381 L1@A, L2@A, L3@B, ...
1383 BC_L could end up pointing at location L2, while the "master"
1384 location could be L1. Since the `loc->inserted' flag is only set
1385 on "master" locations, we'd forget to restore the shadow of L1
1388 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1391 /* Now do full processing of the found relevant range of elements. */
1393 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1395 struct bp_location
*bl
= bp_location
[bc
];
1396 CORE_ADDR bp_addr
= 0;
1400 /* bp_location array has BL->OWNER always non-NULL. */
1401 if (bl
->owner
->type
== bp_none
)
1402 warning (_("reading through apparently deleted breakpoint #%d?"),
1405 /* Performance optimization: any further element can no longer affect BUF
1408 if (bl
->address
>= bp_location_placed_address_before_address_max
1409 && memaddr
+ len
<= (bl
->address
1410 - bp_location_placed_address_before_address_max
))
1413 if (!bp_location_has_shadow (bl
))
1415 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1416 current_program_space
->aspace
, 0))
1419 /* Addresses and length of the part of the breakpoint that
1421 bp_addr
= bl
->target_info
.placed_address
;
1422 bp_size
= bl
->target_info
.shadow_len
;
1424 if (bp_addr
+ bp_size
<= memaddr
)
1425 /* The breakpoint is entirely before the chunk of memory we
1429 if (bp_addr
>= memaddr
+ len
)
1430 /* The breakpoint is entirely after the chunk of memory we are
1434 /* Offset within shadow_contents. */
1435 if (bp_addr
< memaddr
)
1437 /* Only copy the second part of the breakpoint. */
1438 bp_size
-= memaddr
- bp_addr
;
1439 bptoffset
= memaddr
- bp_addr
;
1443 if (bp_addr
+ bp_size
> memaddr
+ len
)
1445 /* Only copy the first part of the breakpoint. */
1446 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1449 if (readbuf
!= NULL
)
1451 /* Verify that the readbuf buffer does not overlap with
1452 the shadow_contents buffer. */
1453 gdb_assert (bl
->target_info
.shadow_contents
>= readbuf
+ len
1454 || readbuf
>= (bl
->target_info
.shadow_contents
1455 + bl
->target_info
.shadow_len
));
1457 /* Update the read buffer with this inserted breakpoint's
1459 memcpy (readbuf
+ bp_addr
- memaddr
,
1460 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1464 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1465 const unsigned char *bp
;
1466 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1467 unsigned placed_size
= bl
->target_info
.placed_size
;
1469 /* Update the shadow with what we want to write to memory. */
1470 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1471 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1473 /* Determine appropriate breakpoint contents and size for this
1475 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1477 /* Update the final write buffer with this inserted
1478 breakpoint's INSN. */
1479 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1485 /* Return true if BPT is either a software breakpoint or a hardware
1489 is_breakpoint (const struct breakpoint
*bpt
)
1491 return (bpt
->type
== bp_breakpoint
1492 || bpt
->type
== bp_hardware_breakpoint
);
1495 /* Return true if BPT is of any hardware watchpoint kind. */
1498 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1500 return (bpt
->type
== bp_hardware_watchpoint
1501 || bpt
->type
== bp_read_watchpoint
1502 || bpt
->type
== bp_access_watchpoint
);
1505 /* Return true if BPT is of any watchpoint kind, hardware or
1509 is_watchpoint (const struct breakpoint
*bpt
)
1511 return (is_hardware_watchpoint (bpt
)
1512 || bpt
->type
== bp_watchpoint
);
1515 /* Returns true if the current thread and its running state are safe
1516 to evaluate or update watchpoint B. Watchpoints on local
1517 expressions need to be evaluated in the context of the thread that
1518 was current when the watchpoint was created, and, that thread needs
1519 to be stopped to be able to select the correct frame context.
1520 Watchpoints on global expressions can be evaluated on any thread,
1521 and in any state. It is presently left to the target allowing
1522 memory accesses when threads are running. */
1525 watchpoint_in_thread_scope (struct watchpoint
*b
)
1527 return (b
->base
.pspace
== current_program_space
1528 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1529 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1530 && !is_executing (inferior_ptid
))));
1533 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1534 associated bp_watchpoint_scope breakpoint. */
1537 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1539 struct breakpoint
*b
= &w
->base
;
1541 if (b
->related_breakpoint
!= b
)
1543 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1544 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1545 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1546 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1547 b
->related_breakpoint
= b
;
1549 b
->disposition
= disp_del_at_next_stop
;
1552 /* Assuming that B is a watchpoint:
1553 - Reparse watchpoint expression, if REPARSE is non-zero
1554 - Evaluate expression and store the result in B->val
1555 - Evaluate the condition if there is one, and store the result
1557 - Update the list of values that must be watched in B->loc.
1559 If the watchpoint disposition is disp_del_at_next_stop, then do
1560 nothing. If this is local watchpoint that is out of scope, delete
1563 Even with `set breakpoint always-inserted on' the watchpoints are
1564 removed + inserted on each stop here. Normal breakpoints must
1565 never be removed because they might be missed by a running thread
1566 when debugging in non-stop mode. On the other hand, hardware
1567 watchpoints (is_hardware_watchpoint; processed here) are specific
1568 to each LWP since they are stored in each LWP's hardware debug
1569 registers. Therefore, such LWP must be stopped first in order to
1570 be able to modify its hardware watchpoints.
1572 Hardware watchpoints must be reset exactly once after being
1573 presented to the user. It cannot be done sooner, because it would
1574 reset the data used to present the watchpoint hit to the user. And
1575 it must not be done later because it could display the same single
1576 watchpoint hit during multiple GDB stops. Note that the latter is
1577 relevant only to the hardware watchpoint types bp_read_watchpoint
1578 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1579 not user-visible - its hit is suppressed if the memory content has
1582 The following constraints influence the location where we can reset
1583 hardware watchpoints:
1585 * target_stopped_by_watchpoint and target_stopped_data_address are
1586 called several times when GDB stops.
1589 * Multiple hardware watchpoints can be hit at the same time,
1590 causing GDB to stop. GDB only presents one hardware watchpoint
1591 hit at a time as the reason for stopping, and all the other hits
1592 are presented later, one after the other, each time the user
1593 requests the execution to be resumed. Execution is not resumed
1594 for the threads still having pending hit event stored in
1595 LWP_INFO->STATUS. While the watchpoint is already removed from
1596 the inferior on the first stop the thread hit event is kept being
1597 reported from its cached value by linux_nat_stopped_data_address
1598 until the real thread resume happens after the watchpoint gets
1599 presented and thus its LWP_INFO->STATUS gets reset.
1601 Therefore the hardware watchpoint hit can get safely reset on the
1602 watchpoint removal from inferior. */
1605 update_watchpoint (struct watchpoint
*b
, int reparse
)
1607 int within_current_scope
;
1608 struct frame_id saved_frame_id
;
1611 /* If this is a local watchpoint, we only want to check if the
1612 watchpoint frame is in scope if the current thread is the thread
1613 that was used to create the watchpoint. */
1614 if (!watchpoint_in_thread_scope (b
))
1617 if (b
->base
.disposition
== disp_del_at_next_stop
)
1622 /* Determine if the watchpoint is within scope. */
1623 if (b
->exp_valid_block
== NULL
)
1624 within_current_scope
= 1;
1627 struct frame_info
*fi
= get_current_frame ();
1628 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1629 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1631 /* If we're in a function epilogue, unwinding may not work
1632 properly, so do not attempt to recreate locations at this
1633 point. See similar comments in watchpoint_check. */
1634 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1637 /* Save the current frame's ID so we can restore it after
1638 evaluating the watchpoint expression on its own frame. */
1639 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1640 took a frame parameter, so that we didn't have to change the
1643 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1645 fi
= frame_find_by_id (b
->watchpoint_frame
);
1646 within_current_scope
= (fi
!= NULL
);
1647 if (within_current_scope
)
1651 /* We don't free locations. They are stored in the bp_location array
1652 and update_global_location_list will eventually delete them and
1653 remove breakpoints if needed. */
1656 if (within_current_scope
&& reparse
)
1665 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1666 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1667 /* If the meaning of expression itself changed, the old value is
1668 no longer relevant. We don't want to report a watchpoint hit
1669 to the user when the old value and the new value may actually
1670 be completely different objects. */
1671 value_free (b
->val
);
1675 /* Note that unlike with breakpoints, the watchpoint's condition
1676 expression is stored in the breakpoint object, not in the
1677 locations (re)created below. */
1678 if (b
->base
.cond_string
!= NULL
)
1680 if (b
->cond_exp
!= NULL
)
1682 xfree (b
->cond_exp
);
1686 s
= b
->base
.cond_string
;
1687 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1691 /* If we failed to parse the expression, for example because
1692 it refers to a global variable in a not-yet-loaded shared library,
1693 don't try to insert watchpoint. We don't automatically delete
1694 such watchpoint, though, since failure to parse expression
1695 is different from out-of-scope watchpoint. */
1696 if ( !target_has_execution
)
1698 /* Without execution, memory can't change. No use to try and
1699 set watchpoint locations. The watchpoint will be reset when
1700 the target gains execution, through breakpoint_re_set. */
1702 else if (within_current_scope
&& b
->exp
)
1705 struct value
*val_chain
, *v
, *result
, *next
;
1706 struct program_space
*frame_pspace
;
1708 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1710 /* Avoid setting b->val if it's already set. The meaning of
1711 b->val is 'the last value' user saw, and we should update
1712 it only if we reported that last value to user. As it
1713 happens, the code that reports it updates b->val directly.
1714 We don't keep track of the memory value for masked
1716 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1722 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1724 /* Look at each value on the value chain. */
1725 for (v
= val_chain
; v
; v
= value_next (v
))
1727 /* If it's a memory location, and GDB actually needed
1728 its contents to evaluate the expression, then we
1729 must watch it. If the first value returned is
1730 still lazy, that means an error occurred reading it;
1731 watch it anyway in case it becomes readable. */
1732 if (VALUE_LVAL (v
) == lval_memory
1733 && (v
== val_chain
|| ! value_lazy (v
)))
1735 struct type
*vtype
= check_typedef (value_type (v
));
1737 /* We only watch structs and arrays if user asked
1738 for it explicitly, never if they just happen to
1739 appear in the middle of some value chain. */
1741 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1742 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1746 struct bp_location
*loc
, **tmp
;
1748 addr
= value_address (v
);
1749 len
= TYPE_LENGTH (value_type (v
));
1751 if (b
->base
.type
== bp_read_watchpoint
)
1753 else if (b
->base
.type
== bp_access_watchpoint
)
1756 loc
= allocate_bp_location (&b
->base
);
1757 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1760 loc
->gdbarch
= get_type_arch (value_type (v
));
1762 loc
->pspace
= frame_pspace
;
1763 loc
->address
= addr
;
1765 loc
->watchpoint_type
= type
;
1770 /* Change the type of breakpoint between hardware assisted or
1771 an ordinary watchpoint depending on the hardware support
1772 and free hardware slots. REPARSE is set when the inferior
1777 enum bp_loc_type loc_type
;
1778 struct bp_location
*bl
;
1780 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1784 int i
, target_resources_ok
, other_type_used
;
1787 /* Use an exact watchpoint when there's only one memory region to be
1788 watched, and only one debug register is needed to watch it. */
1789 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1791 /* We need to determine how many resources are already
1792 used for all other hardware watchpoints plus this one
1793 to see if we still have enough resources to also fit
1794 this watchpoint in as well. */
1796 /* If this is a software watchpoint, we try to turn it
1797 to a hardware one -- count resources as if B was of
1798 hardware watchpoint type. */
1799 type
= b
->base
.type
;
1800 if (type
== bp_watchpoint
)
1801 type
= bp_hardware_watchpoint
;
1803 /* This watchpoint may or may not have been placed on
1804 the list yet at this point (it won't be in the list
1805 if we're trying to create it for the first time,
1806 through watch_command), so always account for it
1809 /* Count resources used by all watchpoints except B. */
1810 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1812 /* Add in the resources needed for B. */
1813 i
+= hw_watchpoint_use_count (&b
->base
);
1816 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1817 if (target_resources_ok
<= 0)
1819 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1821 if (target_resources_ok
== 0 && !sw_mode
)
1822 error (_("Target does not support this type of "
1823 "hardware watchpoint."));
1824 else if (target_resources_ok
< 0 && !sw_mode
)
1825 error (_("There are not enough available hardware "
1826 "resources for this watchpoint."));
1828 /* Downgrade to software watchpoint. */
1829 b
->base
.type
= bp_watchpoint
;
1833 /* If this was a software watchpoint, we've just
1834 found we have enough resources to turn it to a
1835 hardware watchpoint. Otherwise, this is a
1837 b
->base
.type
= type
;
1840 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1841 error (_("Expression cannot be implemented with "
1842 "read/access watchpoint."));
1844 b
->base
.type
= bp_watchpoint
;
1846 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1847 : bp_loc_hardware_watchpoint
);
1848 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1849 bl
->loc_type
= loc_type
;
1852 for (v
= val_chain
; v
; v
= next
)
1854 next
= value_next (v
);
1859 /* If a software watchpoint is not watching any memory, then the
1860 above left it without any location set up. But,
1861 bpstat_stop_status requires a location to be able to report
1862 stops, so make sure there's at least a dummy one. */
1863 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1865 struct breakpoint
*base
= &b
->base
;
1866 base
->loc
= allocate_bp_location (base
);
1867 base
->loc
->pspace
= frame_pspace
;
1868 base
->loc
->address
= -1;
1869 base
->loc
->length
= -1;
1870 base
->loc
->watchpoint_type
= -1;
1873 else if (!within_current_scope
)
1875 printf_filtered (_("\
1876 Watchpoint %d deleted because the program has left the block\n\
1877 in which its expression is valid.\n"),
1879 watchpoint_del_at_next_stop (b
);
1882 /* Restore the selected frame. */
1884 select_frame (frame_find_by_id (saved_frame_id
));
1888 /* Returns 1 iff breakpoint location should be
1889 inserted in the inferior. We don't differentiate the type of BL's owner
1890 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1891 breakpoint_ops is not defined, because in insert_bp_location,
1892 tracepoint's insert_location will not be called. */
1894 should_be_inserted (struct bp_location
*bl
)
1896 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1899 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1902 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1905 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1908 /* This is set for example, when we're attached to the parent of a
1909 vfork, and have detached from the child. The child is running
1910 free, and we expect it to do an exec or exit, at which point the
1911 OS makes the parent schedulable again (and the target reports
1912 that the vfork is done). Until the child is done with the shared
1913 memory region, do not insert breakpoints in the parent, otherwise
1914 the child could still trip on the parent's breakpoints. Since
1915 the parent is blocked anyway, it won't miss any breakpoint. */
1916 if (bl
->pspace
->breakpoints_not_allowed
)
1922 /* Same as should_be_inserted but does the check assuming
1923 that the location is not duplicated. */
1926 unduplicated_should_be_inserted (struct bp_location
*bl
)
1929 const int save_duplicate
= bl
->duplicate
;
1932 result
= should_be_inserted (bl
);
1933 bl
->duplicate
= save_duplicate
;
1937 /* Parses a conditional described by an expression COND into an
1938 agent expression bytecode suitable for evaluation
1939 by the bytecode interpreter. Return NULL if there was
1940 any error during parsing. */
1942 static struct agent_expr
*
1943 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
1945 struct agent_expr
*aexpr
= NULL
;
1946 struct cleanup
*old_chain
= NULL
;
1947 volatile struct gdb_exception ex
;
1952 /* We don't want to stop processing, so catch any errors
1953 that may show up. */
1954 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1956 aexpr
= gen_eval_for_expr (scope
, cond
);
1961 /* If we got here, it means the condition could not be parsed to a valid
1962 bytecode expression and thus can't be evaluated on the target's side.
1963 It's no use iterating through the conditions. */
1967 /* We have a valid agent expression. */
1971 /* Based on location BL, create a list of breakpoint conditions to be
1972 passed on to the target. If we have duplicated locations with different
1973 conditions, we will add such conditions to the list. The idea is that the
1974 target will evaluate the list of conditions and will only notify GDB when
1975 one of them is true. */
1978 build_target_condition_list (struct bp_location
*bl
)
1980 struct bp_location
**locp
= NULL
, **loc2p
;
1981 int null_condition_or_parse_error
= 0;
1982 int modified
= bl
->needs_update
;
1983 struct bp_location
*loc
;
1985 /* This is only meaningful if the target is
1986 evaluating conditions and if the user has
1987 opted for condition evaluation on the target's
1989 if (gdb_evaluates_breakpoint_condition_p ()
1990 || !target_supports_evaluation_of_breakpoint_conditions ())
1993 /* Do a first pass to check for locations with no assigned
1994 conditions or conditions that fail to parse to a valid agent expression
1995 bytecode. If any of these happen, then it's no use to send conditions
1996 to the target since this location will always trigger and generate a
1997 response back to GDB. */
1998 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2001 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2005 struct agent_expr
*aexpr
;
2007 /* Re-parse the conditions since something changed. In that
2008 case we already freed the condition bytecodes (see
2009 force_breakpoint_reinsertion). We just
2010 need to parse the condition to bytecodes again. */
2011 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2012 loc
->cond_bytecode
= aexpr
;
2014 /* Check if we managed to parse the conditional expression
2015 correctly. If not, we will not send this condition
2021 /* If we have a NULL bytecode expression, it means something
2022 went wrong or we have a null condition expression. */
2023 if (!loc
->cond_bytecode
)
2025 null_condition_or_parse_error
= 1;
2031 /* If any of these happened, it means we will have to evaluate the conditions
2032 for the location's address on gdb's side. It is no use keeping bytecodes
2033 for all the other duplicate locations, thus we free all of them here.
2035 This is so we have a finer control over which locations' conditions are
2036 being evaluated by GDB or the remote stub. */
2037 if (null_condition_or_parse_error
)
2039 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2042 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2044 /* Only go as far as the first NULL bytecode is
2046 if (!loc
->cond_bytecode
)
2049 free_agent_expr (loc
->cond_bytecode
);
2050 loc
->cond_bytecode
= NULL
;
2055 /* No NULL conditions or failed bytecode generation. Build a condition list
2056 for this location's address. */
2057 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2061 && is_breakpoint (loc
->owner
)
2062 && loc
->pspace
->num
== bl
->pspace
->num
2063 && loc
->owner
->enable_state
== bp_enabled
2065 /* Add the condition to the vector. This will be used later to send the
2066 conditions to the target. */
2067 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2068 loc
->cond_bytecode
);
2074 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2075 location. Any error messages are printed to TMP_ERROR_STREAM; and
2076 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2077 Returns 0 for success, 1 if the bp_location type is not supported or
2080 NOTE drow/2003-09-09: This routine could be broken down to an
2081 object-style method for each breakpoint or catchpoint type. */
2083 insert_bp_location (struct bp_location
*bl
,
2084 struct ui_file
*tmp_error_stream
,
2085 int *disabled_breaks
,
2086 int *hw_breakpoint_error
)
2090 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2093 /* Note we don't initialize bl->target_info, as that wipes out
2094 the breakpoint location's shadow_contents if the breakpoint
2095 is still inserted at that location. This in turn breaks
2096 target_read_memory which depends on these buffers when
2097 a memory read is requested at the breakpoint location:
2098 Once the target_info has been wiped, we fail to see that
2099 we have a breakpoint inserted at that address and thus
2100 read the breakpoint instead of returning the data saved in
2101 the breakpoint location's shadow contents. */
2102 bl
->target_info
.placed_address
= bl
->address
;
2103 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2104 bl
->target_info
.length
= bl
->length
;
2106 /* When working with target-side conditions, we must pass all the conditions
2107 for the same breakpoint address down to the target since GDB will not
2108 insert those locations. With a list of breakpoint conditions, the target
2109 can decide when to stop and notify GDB. */
2111 if (is_breakpoint (bl
->owner
))
2113 build_target_condition_list (bl
);
2114 /* Reset the condition modification marker. */
2115 bl
->needs_update
= 0;
2118 if (bl
->loc_type
== bp_loc_software_breakpoint
2119 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2121 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2123 /* If the explicitly specified breakpoint type
2124 is not hardware breakpoint, check the memory map to see
2125 if the breakpoint address is in read only memory or not.
2127 Two important cases are:
2128 - location type is not hardware breakpoint, memory
2129 is readonly. We change the type of the location to
2130 hardware breakpoint.
2131 - location type is hardware breakpoint, memory is
2132 read-write. This means we've previously made the
2133 location hardware one, but then the memory map changed,
2136 When breakpoints are removed, remove_breakpoints will use
2137 location types we've just set here, the only possible
2138 problem is that memory map has changed during running
2139 program, but it's not going to work anyway with current
2141 struct mem_region
*mr
2142 = lookup_mem_region (bl
->target_info
.placed_address
);
2146 if (automatic_hardware_breakpoints
)
2148 enum bp_loc_type new_type
;
2150 if (mr
->attrib
.mode
!= MEM_RW
)
2151 new_type
= bp_loc_hardware_breakpoint
;
2153 new_type
= bp_loc_software_breakpoint
;
2155 if (new_type
!= bl
->loc_type
)
2157 static int said
= 0;
2159 bl
->loc_type
= new_type
;
2162 fprintf_filtered (gdb_stdout
,
2163 _("Note: automatically using "
2164 "hardware breakpoints for "
2165 "read-only addresses.\n"));
2170 else if (bl
->loc_type
== bp_loc_software_breakpoint
2171 && mr
->attrib
.mode
!= MEM_RW
)
2172 warning (_("cannot set software breakpoint "
2173 "at readonly address %s"),
2174 paddress (bl
->gdbarch
, bl
->address
));
2178 /* First check to see if we have to handle an overlay. */
2179 if (overlay_debugging
== ovly_off
2180 || bl
->section
== NULL
2181 || !(section_is_overlay (bl
->section
)))
2183 /* No overlay handling: just set the breakpoint. */
2185 val
= bl
->owner
->ops
->insert_location (bl
);
2189 /* This breakpoint is in an overlay section.
2190 Shall we set a breakpoint at the LMA? */
2191 if (!overlay_events_enabled
)
2193 /* Yes -- overlay event support is not active,
2194 so we must try to set a breakpoint at the LMA.
2195 This will not work for a hardware breakpoint. */
2196 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2197 warning (_("hardware breakpoint %d not supported in overlay!"),
2201 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2203 /* Set a software (trap) breakpoint at the LMA. */
2204 bl
->overlay_target_info
= bl
->target_info
;
2205 bl
->overlay_target_info
.placed_address
= addr
;
2206 val
= target_insert_breakpoint (bl
->gdbarch
,
2207 &bl
->overlay_target_info
);
2209 fprintf_unfiltered (tmp_error_stream
,
2210 "Overlay breakpoint %d "
2211 "failed: in ROM?\n",
2215 /* Shall we set a breakpoint at the VMA? */
2216 if (section_is_mapped (bl
->section
))
2218 /* Yes. This overlay section is mapped into memory. */
2219 val
= bl
->owner
->ops
->insert_location (bl
);
2223 /* No. This breakpoint will not be inserted.
2224 No error, but do not mark the bp as 'inserted'. */
2231 /* Can't set the breakpoint. */
2232 if (solib_name_from_address (bl
->pspace
, bl
->address
))
2234 /* See also: disable_breakpoints_in_shlibs. */
2236 bl
->shlib_disabled
= 1;
2237 observer_notify_breakpoint_modified (bl
->owner
);
2238 if (!*disabled_breaks
)
2240 fprintf_unfiltered (tmp_error_stream
,
2241 "Cannot insert breakpoint %d.\n",
2243 fprintf_unfiltered (tmp_error_stream
,
2244 "Temporarily disabling shared "
2245 "library breakpoints:\n");
2247 *disabled_breaks
= 1;
2248 fprintf_unfiltered (tmp_error_stream
,
2249 "breakpoint #%d\n", bl
->owner
->number
);
2253 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2255 *hw_breakpoint_error
= 1;
2256 fprintf_unfiltered (tmp_error_stream
,
2257 "Cannot insert hardware "
2263 fprintf_unfiltered (tmp_error_stream
,
2264 "Cannot insert breakpoint %d.\n",
2266 fprintf_filtered (tmp_error_stream
,
2267 "Error accessing memory address ");
2268 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
2270 fprintf_filtered (tmp_error_stream
, ": %s.\n",
2271 safe_strerror (val
));
2282 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2283 /* NOTE drow/2003-09-08: This state only exists for removing
2284 watchpoints. It's not clear that it's necessary... */
2285 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2287 gdb_assert (bl
->owner
->ops
!= NULL
2288 && bl
->owner
->ops
->insert_location
!= NULL
);
2290 val
= bl
->owner
->ops
->insert_location (bl
);
2292 /* If trying to set a read-watchpoint, and it turns out it's not
2293 supported, try emulating one with an access watchpoint. */
2294 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2296 struct bp_location
*loc
, **loc_temp
;
2298 /* But don't try to insert it, if there's already another
2299 hw_access location that would be considered a duplicate
2301 ALL_BP_LOCATIONS (loc
, loc_temp
)
2303 && loc
->watchpoint_type
== hw_access
2304 && watchpoint_locations_match (bl
, loc
))
2308 bl
->target_info
= loc
->target_info
;
2309 bl
->watchpoint_type
= hw_access
;
2316 bl
->watchpoint_type
= hw_access
;
2317 val
= bl
->owner
->ops
->insert_location (bl
);
2320 /* Back to the original value. */
2321 bl
->watchpoint_type
= hw_read
;
2325 bl
->inserted
= (val
== 0);
2328 else if (bl
->owner
->type
== bp_catchpoint
)
2330 gdb_assert (bl
->owner
->ops
!= NULL
2331 && bl
->owner
->ops
->insert_location
!= NULL
);
2333 val
= bl
->owner
->ops
->insert_location (bl
);
2336 bl
->owner
->enable_state
= bp_disabled
;
2340 Error inserting catchpoint %d: Your system does not support this type\n\
2341 of catchpoint."), bl
->owner
->number
);
2343 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2346 bl
->inserted
= (val
== 0);
2348 /* We've already printed an error message if there was a problem
2349 inserting this catchpoint, and we've disabled the catchpoint,
2350 so just return success. */
2357 /* This function is called when program space PSPACE is about to be
2358 deleted. It takes care of updating breakpoints to not reference
2362 breakpoint_program_space_exit (struct program_space
*pspace
)
2364 struct breakpoint
*b
, *b_temp
;
2365 struct bp_location
*loc
, **loc_temp
;
2367 /* Remove any breakpoint that was set through this program space. */
2368 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2370 if (b
->pspace
== pspace
)
2371 delete_breakpoint (b
);
2374 /* Breakpoints set through other program spaces could have locations
2375 bound to PSPACE as well. Remove those. */
2376 ALL_BP_LOCATIONS (loc
, loc_temp
)
2378 struct bp_location
*tmp
;
2380 if (loc
->pspace
== pspace
)
2382 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2383 if (loc
->owner
->loc
== loc
)
2384 loc
->owner
->loc
= loc
->next
;
2386 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2387 if (tmp
->next
== loc
)
2389 tmp
->next
= loc
->next
;
2395 /* Now update the global location list to permanently delete the
2396 removed locations above. */
2397 update_global_location_list (0);
2400 /* Make sure all breakpoints are inserted in inferior.
2401 Throws exception on any error.
2402 A breakpoint that is already inserted won't be inserted
2403 again, so calling this function twice is safe. */
2405 insert_breakpoints (void)
2407 struct breakpoint
*bpt
;
2409 ALL_BREAKPOINTS (bpt
)
2410 if (is_hardware_watchpoint (bpt
))
2412 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2414 update_watchpoint (w
, 0 /* don't reparse. */);
2417 update_global_location_list (1);
2419 /* update_global_location_list does not insert breakpoints when
2420 always_inserted_mode is not enabled. Explicitly insert them
2422 if (!breakpoints_always_inserted_mode ())
2423 insert_breakpoint_locations ();
2426 /* Invoke CALLBACK for each of bp_location. */
2429 iterate_over_bp_locations (walk_bp_location_callback callback
)
2431 struct bp_location
*loc
, **loc_tmp
;
2433 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2435 callback (loc
, NULL
);
2439 /* This is used when we need to synch breakpoint conditions between GDB and the
2440 target. It is the case with deleting and disabling of breakpoints when using
2441 always-inserted mode. */
2444 update_inserted_breakpoint_locations (void)
2446 struct bp_location
*bl
, **blp_tmp
;
2449 int disabled_breaks
= 0;
2450 int hw_breakpoint_error
= 0;
2452 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2453 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2455 /* Explicitly mark the warning -- this will only be printed if
2456 there was an error. */
2457 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2459 save_current_space_and_thread ();
2461 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2463 /* We only want to update software breakpoints and hardware
2465 if (!is_breakpoint (bl
->owner
))
2468 /* We only want to update locations that are already inserted
2469 and need updating. This is to avoid unwanted insertion during
2470 deletion of breakpoints. */
2471 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2474 switch_to_program_space_and_thread (bl
->pspace
);
2476 /* For targets that support global breakpoints, there's no need
2477 to select an inferior to insert breakpoint to. In fact, even
2478 if we aren't attached to any process yet, we should still
2479 insert breakpoints. */
2480 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2481 && ptid_equal (inferior_ptid
, null_ptid
))
2484 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2485 &hw_breakpoint_error
);
2492 target_terminal_ours_for_output ();
2493 error_stream (tmp_error_stream
);
2496 do_cleanups (cleanups
);
2499 /* Used when starting or continuing the program. */
2502 insert_breakpoint_locations (void)
2504 struct breakpoint
*bpt
;
2505 struct bp_location
*bl
, **blp_tmp
;
2508 int disabled_breaks
= 0;
2509 int hw_breakpoint_error
= 0;
2511 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2512 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2514 /* Explicitly mark the warning -- this will only be printed if
2515 there was an error. */
2516 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2518 save_current_space_and_thread ();
2520 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2522 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2525 /* There is no point inserting thread-specific breakpoints if
2526 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2527 has BL->OWNER always non-NULL. */
2528 if (bl
->owner
->thread
!= -1
2529 && !valid_thread_id (bl
->owner
->thread
))
2532 switch_to_program_space_and_thread (bl
->pspace
);
2534 /* For targets that support global breakpoints, there's no need
2535 to select an inferior to insert breakpoint to. In fact, even
2536 if we aren't attached to any process yet, we should still
2537 insert breakpoints. */
2538 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2539 && ptid_equal (inferior_ptid
, null_ptid
))
2542 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2543 &hw_breakpoint_error
);
2548 /* If we failed to insert all locations of a watchpoint, remove
2549 them, as half-inserted watchpoint is of limited use. */
2550 ALL_BREAKPOINTS (bpt
)
2552 int some_failed
= 0;
2553 struct bp_location
*loc
;
2555 if (!is_hardware_watchpoint (bpt
))
2558 if (!breakpoint_enabled (bpt
))
2561 if (bpt
->disposition
== disp_del_at_next_stop
)
2564 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2565 if (!loc
->inserted
&& should_be_inserted (loc
))
2572 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2574 remove_breakpoint (loc
, mark_uninserted
);
2576 hw_breakpoint_error
= 1;
2577 fprintf_unfiltered (tmp_error_stream
,
2578 "Could not insert hardware watchpoint %d.\n",
2586 /* If a hardware breakpoint or watchpoint was inserted, add a
2587 message about possibly exhausted resources. */
2588 if (hw_breakpoint_error
)
2590 fprintf_unfiltered (tmp_error_stream
,
2591 "Could not insert hardware breakpoints:\n\
2592 You may have requested too many hardware breakpoints/watchpoints.\n");
2594 target_terminal_ours_for_output ();
2595 error_stream (tmp_error_stream
);
2598 do_cleanups (cleanups
);
2601 /* Used when the program stops.
2602 Returns zero if successful, or non-zero if there was a problem
2603 removing a breakpoint location. */
2606 remove_breakpoints (void)
2608 struct bp_location
*bl
, **blp_tmp
;
2611 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2613 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2614 val
|= remove_breakpoint (bl
, mark_uninserted
);
2619 /* Remove breakpoints of process PID. */
2622 remove_breakpoints_pid (int pid
)
2624 struct bp_location
*bl
, **blp_tmp
;
2626 struct inferior
*inf
= find_inferior_pid (pid
);
2628 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2630 if (bl
->pspace
!= inf
->pspace
)
2635 val
= remove_breakpoint (bl
, mark_uninserted
);
2644 reattach_breakpoints (int pid
)
2646 struct cleanup
*old_chain
;
2647 struct bp_location
*bl
, **blp_tmp
;
2649 struct ui_file
*tmp_error_stream
;
2650 int dummy1
= 0, dummy2
= 0;
2651 struct inferior
*inf
;
2652 struct thread_info
*tp
;
2654 tp
= any_live_thread_of_process (pid
);
2658 inf
= find_inferior_pid (pid
);
2659 old_chain
= save_inferior_ptid ();
2661 inferior_ptid
= tp
->ptid
;
2663 tmp_error_stream
= mem_fileopen ();
2664 make_cleanup_ui_file_delete (tmp_error_stream
);
2666 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2668 if (bl
->pspace
!= inf
->pspace
)
2674 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2677 do_cleanups (old_chain
);
2682 do_cleanups (old_chain
);
2686 static int internal_breakpoint_number
= -1;
2688 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2689 If INTERNAL is non-zero, the breakpoint number will be populated
2690 from internal_breakpoint_number and that variable decremented.
2691 Otherwise the breakpoint number will be populated from
2692 breakpoint_count and that value incremented. Internal breakpoints
2693 do not set the internal var bpnum. */
2695 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2698 b
->number
= internal_breakpoint_number
--;
2701 set_breakpoint_count (breakpoint_count
+ 1);
2702 b
->number
= breakpoint_count
;
2706 static struct breakpoint
*
2707 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2708 CORE_ADDR address
, enum bptype type
,
2709 const struct breakpoint_ops
*ops
)
2711 struct symtab_and_line sal
;
2712 struct breakpoint
*b
;
2714 init_sal (&sal
); /* Initialize to zeroes. */
2717 sal
.section
= find_pc_overlay (sal
.pc
);
2718 sal
.pspace
= current_program_space
;
2720 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2721 b
->number
= internal_breakpoint_number
--;
2722 b
->disposition
= disp_donttouch
;
2727 static const char *const longjmp_names
[] =
2729 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2731 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2733 /* Per-objfile data private to breakpoint.c. */
2734 struct breakpoint_objfile_data
2736 /* Minimal symbol for "_ovly_debug_event" (if any). */
2737 struct minimal_symbol
*overlay_msym
;
2739 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2740 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2742 /* Minimal symbol for "std::terminate()" (if any). */
2743 struct minimal_symbol
*terminate_msym
;
2745 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2746 struct minimal_symbol
*exception_msym
;
2749 static const struct objfile_data
*breakpoint_objfile_key
;
2751 /* Minimal symbol not found sentinel. */
2752 static struct minimal_symbol msym_not_found
;
2754 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2757 msym_not_found_p (const struct minimal_symbol
*msym
)
2759 return msym
== &msym_not_found
;
2762 /* Return per-objfile data needed by breakpoint.c.
2763 Allocate the data if necessary. */
2765 static struct breakpoint_objfile_data
*
2766 get_breakpoint_objfile_data (struct objfile
*objfile
)
2768 struct breakpoint_objfile_data
*bp_objfile_data
;
2770 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2771 if (bp_objfile_data
== NULL
)
2773 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2774 sizeof (*bp_objfile_data
));
2776 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2777 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2779 return bp_objfile_data
;
2783 create_overlay_event_breakpoint (void)
2785 struct objfile
*objfile
;
2786 const char *const func_name
= "_ovly_debug_event";
2788 ALL_OBJFILES (objfile
)
2790 struct breakpoint
*b
;
2791 struct breakpoint_objfile_data
*bp_objfile_data
;
2794 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2796 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2799 if (bp_objfile_data
->overlay_msym
== NULL
)
2801 struct minimal_symbol
*m
;
2803 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2806 /* Avoid future lookups in this objfile. */
2807 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2810 bp_objfile_data
->overlay_msym
= m
;
2813 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2814 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2816 &internal_breakpoint_ops
);
2817 b
->addr_string
= xstrdup (func_name
);
2819 if (overlay_debugging
== ovly_auto
)
2821 b
->enable_state
= bp_enabled
;
2822 overlay_events_enabled
= 1;
2826 b
->enable_state
= bp_disabled
;
2827 overlay_events_enabled
= 0;
2830 update_global_location_list (1);
2834 create_longjmp_master_breakpoint (void)
2836 struct program_space
*pspace
;
2837 struct cleanup
*old_chain
;
2839 old_chain
= save_current_program_space ();
2841 ALL_PSPACES (pspace
)
2843 struct objfile
*objfile
;
2845 set_current_program_space (pspace
);
2847 ALL_OBJFILES (objfile
)
2850 struct gdbarch
*gdbarch
;
2851 struct breakpoint_objfile_data
*bp_objfile_data
;
2853 gdbarch
= get_objfile_arch (objfile
);
2854 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2857 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2859 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2861 struct breakpoint
*b
;
2862 const char *func_name
;
2865 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2868 func_name
= longjmp_names
[i
];
2869 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2871 struct minimal_symbol
*m
;
2873 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2876 /* Prevent future lookups in this objfile. */
2877 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2880 bp_objfile_data
->longjmp_msym
[i
] = m
;
2883 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2884 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2885 &internal_breakpoint_ops
);
2886 b
->addr_string
= xstrdup (func_name
);
2887 b
->enable_state
= bp_disabled
;
2891 update_global_location_list (1);
2893 do_cleanups (old_chain
);
2896 /* Create a master std::terminate breakpoint. */
2898 create_std_terminate_master_breakpoint (void)
2900 struct program_space
*pspace
;
2901 struct cleanup
*old_chain
;
2902 const char *const func_name
= "std::terminate()";
2904 old_chain
= save_current_program_space ();
2906 ALL_PSPACES (pspace
)
2908 struct objfile
*objfile
;
2911 set_current_program_space (pspace
);
2913 ALL_OBJFILES (objfile
)
2915 struct breakpoint
*b
;
2916 struct breakpoint_objfile_data
*bp_objfile_data
;
2918 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2920 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2923 if (bp_objfile_data
->terminate_msym
== NULL
)
2925 struct minimal_symbol
*m
;
2927 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2928 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2929 && MSYMBOL_TYPE (m
) != mst_file_text
))
2931 /* Prevent future lookups in this objfile. */
2932 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2935 bp_objfile_data
->terminate_msym
= m
;
2938 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2939 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2940 bp_std_terminate_master
,
2941 &internal_breakpoint_ops
);
2942 b
->addr_string
= xstrdup (func_name
);
2943 b
->enable_state
= bp_disabled
;
2947 update_global_location_list (1);
2949 do_cleanups (old_chain
);
2952 /* Install a master breakpoint on the unwinder's debug hook. */
2955 create_exception_master_breakpoint (void)
2957 struct objfile
*objfile
;
2958 const char *const func_name
= "_Unwind_DebugHook";
2960 ALL_OBJFILES (objfile
)
2962 struct breakpoint
*b
;
2963 struct gdbarch
*gdbarch
;
2964 struct breakpoint_objfile_data
*bp_objfile_data
;
2967 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2969 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2972 gdbarch
= get_objfile_arch (objfile
);
2974 if (bp_objfile_data
->exception_msym
== NULL
)
2976 struct minimal_symbol
*debug_hook
;
2978 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2979 if (debug_hook
== NULL
)
2981 bp_objfile_data
->exception_msym
= &msym_not_found
;
2985 bp_objfile_data
->exception_msym
= debug_hook
;
2988 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2989 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2991 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2992 &internal_breakpoint_ops
);
2993 b
->addr_string
= xstrdup (func_name
);
2994 b
->enable_state
= bp_disabled
;
2997 update_global_location_list (1);
3001 update_breakpoints_after_exec (void)
3003 struct breakpoint
*b
, *b_tmp
;
3004 struct bp_location
*bploc
, **bplocp_tmp
;
3006 /* We're about to delete breakpoints from GDB's lists. If the
3007 INSERTED flag is true, GDB will try to lift the breakpoints by
3008 writing the breakpoints' "shadow contents" back into memory. The
3009 "shadow contents" are NOT valid after an exec, so GDB should not
3010 do that. Instead, the target is responsible from marking
3011 breakpoints out as soon as it detects an exec. We don't do that
3012 here instead, because there may be other attempts to delete
3013 breakpoints after detecting an exec and before reaching here. */
3014 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3015 if (bploc
->pspace
== current_program_space
)
3016 gdb_assert (!bploc
->inserted
);
3018 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3020 if (b
->pspace
!= current_program_space
)
3023 /* Solib breakpoints must be explicitly reset after an exec(). */
3024 if (b
->type
== bp_shlib_event
)
3026 delete_breakpoint (b
);
3030 /* JIT breakpoints must be explicitly reset after an exec(). */
3031 if (b
->type
== bp_jit_event
)
3033 delete_breakpoint (b
);
3037 /* Thread event breakpoints must be set anew after an exec(),
3038 as must overlay event and longjmp master breakpoints. */
3039 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3040 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3041 || b
->type
== bp_exception_master
)
3043 delete_breakpoint (b
);
3047 /* Step-resume breakpoints are meaningless after an exec(). */
3048 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3050 delete_breakpoint (b
);
3054 /* Longjmp and longjmp-resume breakpoints are also meaningless
3056 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3057 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3059 delete_breakpoint (b
);
3063 if (b
->type
== bp_catchpoint
)
3065 /* For now, none of the bp_catchpoint breakpoints need to
3066 do anything at this point. In the future, if some of
3067 the catchpoints need to something, we will need to add
3068 a new method, and call this method from here. */
3072 /* bp_finish is a special case. The only way we ought to be able
3073 to see one of these when an exec() has happened, is if the user
3074 caught a vfork, and then said "finish". Ordinarily a finish just
3075 carries them to the call-site of the current callee, by setting
3076 a temporary bp there and resuming. But in this case, the finish
3077 will carry them entirely through the vfork & exec.
3079 We don't want to allow a bp_finish to remain inserted now. But
3080 we can't safely delete it, 'cause finish_command has a handle to
3081 the bp on a bpstat, and will later want to delete it. There's a
3082 chance (and I've seen it happen) that if we delete the bp_finish
3083 here, that its storage will get reused by the time finish_command
3084 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3085 We really must allow finish_command to delete a bp_finish.
3087 In the absence of a general solution for the "how do we know
3088 it's safe to delete something others may have handles to?"
3089 problem, what we'll do here is just uninsert the bp_finish, and
3090 let finish_command delete it.
3092 (We know the bp_finish is "doomed" in the sense that it's
3093 momentary, and will be deleted as soon as finish_command sees
3094 the inferior stopped. So it doesn't matter that the bp's
3095 address is probably bogus in the new a.out, unlike e.g., the
3096 solib breakpoints.) */
3098 if (b
->type
== bp_finish
)
3103 /* Without a symbolic address, we have little hope of the
3104 pre-exec() address meaning the same thing in the post-exec()
3106 if (b
->addr_string
== NULL
)
3108 delete_breakpoint (b
);
3112 /* FIXME what about longjmp breakpoints? Re-create them here? */
3113 create_overlay_event_breakpoint ();
3114 create_longjmp_master_breakpoint ();
3115 create_std_terminate_master_breakpoint ();
3116 create_exception_master_breakpoint ();
3120 detach_breakpoints (int pid
)
3122 struct bp_location
*bl
, **blp_tmp
;
3124 struct cleanup
*old_chain
= save_inferior_ptid ();
3125 struct inferior
*inf
= current_inferior ();
3127 if (pid
== PIDGET (inferior_ptid
))
3128 error (_("Cannot detach breakpoints of inferior_ptid"));
3130 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3131 inferior_ptid
= pid_to_ptid (pid
);
3132 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3134 if (bl
->pspace
!= inf
->pspace
)
3138 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3141 /* Detach single-step breakpoints as well. */
3142 detach_single_step_breakpoints ();
3144 do_cleanups (old_chain
);
3148 /* Remove the breakpoint location BL from the current address space.
3149 Note that this is used to detach breakpoints from a child fork.
3150 When we get here, the child isn't in the inferior list, and neither
3151 do we have objects to represent its address space --- we should
3152 *not* look at bl->pspace->aspace here. */
3155 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3159 /* BL is never in moribund_locations by our callers. */
3160 gdb_assert (bl
->owner
!= NULL
);
3162 if (bl
->owner
->enable_state
== bp_permanent
)
3163 /* Permanent breakpoints cannot be inserted or removed. */
3166 /* The type of none suggests that owner is actually deleted.
3167 This should not ever happen. */
3168 gdb_assert (bl
->owner
->type
!= bp_none
);
3170 if (bl
->loc_type
== bp_loc_software_breakpoint
3171 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3173 /* "Normal" instruction breakpoint: either the standard
3174 trap-instruction bp (bp_breakpoint), or a
3175 bp_hardware_breakpoint. */
3177 /* First check to see if we have to handle an overlay. */
3178 if (overlay_debugging
== ovly_off
3179 || bl
->section
== NULL
3180 || !(section_is_overlay (bl
->section
)))
3182 /* No overlay handling: just remove the breakpoint. */
3183 val
= bl
->owner
->ops
->remove_location (bl
);
3187 /* This breakpoint is in an overlay section.
3188 Did we set a breakpoint at the LMA? */
3189 if (!overlay_events_enabled
)
3191 /* Yes -- overlay event support is not active, so we
3192 should have set a breakpoint at the LMA. Remove it.
3194 /* Ignore any failures: if the LMA is in ROM, we will
3195 have already warned when we failed to insert it. */
3196 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3197 target_remove_hw_breakpoint (bl
->gdbarch
,
3198 &bl
->overlay_target_info
);
3200 target_remove_breakpoint (bl
->gdbarch
,
3201 &bl
->overlay_target_info
);
3203 /* Did we set a breakpoint at the VMA?
3204 If so, we will have marked the breakpoint 'inserted'. */
3207 /* Yes -- remove it. Previously we did not bother to
3208 remove the breakpoint if the section had been
3209 unmapped, but let's not rely on that being safe. We
3210 don't know what the overlay manager might do. */
3212 /* However, we should remove *software* breakpoints only
3213 if the section is still mapped, or else we overwrite
3214 wrong code with the saved shadow contents. */
3215 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3216 || section_is_mapped (bl
->section
))
3217 val
= bl
->owner
->ops
->remove_location (bl
);
3223 /* No -- not inserted, so no need to remove. No error. */
3228 /* In some cases, we might not be able to remove a breakpoint
3229 in a shared library that has already been removed, but we
3230 have not yet processed the shlib unload event. */
3231 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3236 bl
->inserted
= (is
== mark_inserted
);
3238 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3240 gdb_assert (bl
->owner
->ops
!= NULL
3241 && bl
->owner
->ops
->remove_location
!= NULL
);
3243 bl
->inserted
= (is
== mark_inserted
);
3244 bl
->owner
->ops
->remove_location (bl
);
3246 /* Failure to remove any of the hardware watchpoints comes here. */
3247 if ((is
== mark_uninserted
) && (bl
->inserted
))
3248 warning (_("Could not remove hardware watchpoint %d."),
3251 else if (bl
->owner
->type
== bp_catchpoint
3252 && breakpoint_enabled (bl
->owner
)
3255 gdb_assert (bl
->owner
->ops
!= NULL
3256 && bl
->owner
->ops
->remove_location
!= NULL
);
3258 val
= bl
->owner
->ops
->remove_location (bl
);
3262 bl
->inserted
= (is
== mark_inserted
);
3269 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3272 struct cleanup
*old_chain
;
3274 /* BL is never in moribund_locations by our callers. */
3275 gdb_assert (bl
->owner
!= NULL
);
3277 if (bl
->owner
->enable_state
== bp_permanent
)
3278 /* Permanent breakpoints cannot be inserted or removed. */
3281 /* The type of none suggests that owner is actually deleted.
3282 This should not ever happen. */
3283 gdb_assert (bl
->owner
->type
!= bp_none
);
3285 old_chain
= save_current_space_and_thread ();
3287 switch_to_program_space_and_thread (bl
->pspace
);
3289 ret
= remove_breakpoint_1 (bl
, is
);
3291 do_cleanups (old_chain
);
3295 /* Clear the "inserted" flag in all breakpoints. */
3298 mark_breakpoints_out (void)
3300 struct bp_location
*bl
, **blp_tmp
;
3302 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3303 if (bl
->pspace
== current_program_space
)
3307 /* Clear the "inserted" flag in all breakpoints and delete any
3308 breakpoints which should go away between runs of the program.
3310 Plus other such housekeeping that has to be done for breakpoints
3313 Note: this function gets called at the end of a run (by
3314 generic_mourn_inferior) and when a run begins (by
3315 init_wait_for_inferior). */
3320 breakpoint_init_inferior (enum inf_context context
)
3322 struct breakpoint
*b
, *b_tmp
;
3323 struct bp_location
*bl
, **blp_tmp
;
3325 struct program_space
*pspace
= current_program_space
;
3327 /* If breakpoint locations are shared across processes, then there's
3329 if (gdbarch_has_global_breakpoints (target_gdbarch
))
3332 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3334 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3335 if (bl
->pspace
== pspace
3336 && bl
->owner
->enable_state
!= bp_permanent
)
3340 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3342 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3349 /* If the call dummy breakpoint is at the entry point it will
3350 cause problems when the inferior is rerun, so we better get
3353 case bp_watchpoint_scope
:
3355 /* Also get rid of scope breakpoints. */
3357 case bp_shlib_event
:
3359 /* Also remove solib event breakpoints. Their addresses may
3360 have changed since the last time we ran the program.
3361 Actually we may now be debugging against different target;
3362 and so the solib backend that installed this breakpoint may
3363 not be used in by the target. E.g.,
3365 (gdb) file prog-linux
3366 (gdb) run # native linux target
3369 (gdb) file prog-win.exe
3370 (gdb) tar rem :9999 # remote Windows gdbserver.
3373 case bp_step_resume
:
3375 /* Also remove step-resume breakpoints. */
3377 delete_breakpoint (b
);
3381 case bp_hardware_watchpoint
:
3382 case bp_read_watchpoint
:
3383 case bp_access_watchpoint
:
3385 struct watchpoint
*w
= (struct watchpoint
*) b
;
3387 /* Likewise for watchpoints on local expressions. */
3388 if (w
->exp_valid_block
!= NULL
)
3389 delete_breakpoint (b
);
3390 else if (context
== inf_starting
)
3392 /* Reset val field to force reread of starting value in
3393 insert_breakpoints. */
3395 value_free (w
->val
);
3406 /* Get rid of the moribund locations. */
3407 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3408 decref_bp_location (&bl
);
3409 VEC_free (bp_location_p
, moribund_locations
);
3412 /* These functions concern about actual breakpoints inserted in the
3413 target --- to e.g. check if we need to do decr_pc adjustment or if
3414 we need to hop over the bkpt --- so we check for address space
3415 match, not program space. */
3417 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3418 exists at PC. It returns ordinary_breakpoint_here if it's an
3419 ordinary breakpoint, or permanent_breakpoint_here if it's a
3420 permanent breakpoint.
3421 - When continuing from a location with an ordinary breakpoint, we
3422 actually single step once before calling insert_breakpoints.
3423 - When continuing from a location with a permanent breakpoint, we
3424 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3425 the target, to advance the PC past the breakpoint. */
3427 enum breakpoint_here
3428 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3430 struct bp_location
*bl
, **blp_tmp
;
3431 int any_breakpoint_here
= 0;
3433 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3435 if (bl
->loc_type
!= bp_loc_software_breakpoint
3436 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3439 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3440 if ((breakpoint_enabled (bl
->owner
)
3441 || bl
->owner
->enable_state
== bp_permanent
)
3442 && breakpoint_location_address_match (bl
, aspace
, pc
))
3444 if (overlay_debugging
3445 && section_is_overlay (bl
->section
)
3446 && !section_is_mapped (bl
->section
))
3447 continue; /* unmapped overlay -- can't be a match */
3448 else if (bl
->owner
->enable_state
== bp_permanent
)
3449 return permanent_breakpoint_here
;
3451 any_breakpoint_here
= 1;
3455 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
3458 /* Return true if there's a moribund breakpoint at PC. */
3461 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3463 struct bp_location
*loc
;
3466 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3467 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3473 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3474 inserted using regular breakpoint_chain / bp_location array
3475 mechanism. This does not check for single-step breakpoints, which
3476 are inserted and removed using direct target manipulation. */
3479 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
3482 struct bp_location
*bl
, **blp_tmp
;
3484 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3486 if (bl
->loc_type
!= bp_loc_software_breakpoint
3487 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3491 && breakpoint_location_address_match (bl
, aspace
, pc
))
3493 if (overlay_debugging
3494 && section_is_overlay (bl
->section
)
3495 && !section_is_mapped (bl
->section
))
3496 continue; /* unmapped overlay -- can't be a match */
3504 /* Returns non-zero iff there's either regular breakpoint
3505 or a single step breakpoint inserted at PC. */
3508 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3510 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3513 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3519 /* This function returns non-zero iff there is a software breakpoint
3523 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3526 struct bp_location
*bl
, **blp_tmp
;
3528 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3530 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3534 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3537 if (overlay_debugging
3538 && section_is_overlay (bl
->section
)
3539 && !section_is_mapped (bl
->section
))
3540 continue; /* unmapped overlay -- can't be a match */
3546 /* Also check for software single-step breakpoints. */
3547 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3554 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3555 CORE_ADDR addr
, ULONGEST len
)
3557 struct breakpoint
*bpt
;
3559 ALL_BREAKPOINTS (bpt
)
3561 struct bp_location
*loc
;
3563 if (bpt
->type
!= bp_hardware_watchpoint
3564 && bpt
->type
!= bp_access_watchpoint
)
3567 if (!breakpoint_enabled (bpt
))
3570 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3571 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3575 /* Check for intersection. */
3576 l
= max (loc
->address
, addr
);
3577 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3585 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3586 PC is valid for process/thread PTID. */
3589 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3592 struct bp_location
*bl
, **blp_tmp
;
3593 /* The thread and task IDs associated to PTID, computed lazily. */
3597 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3599 if (bl
->loc_type
!= bp_loc_software_breakpoint
3600 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3603 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3604 if (!breakpoint_enabled (bl
->owner
)
3605 && bl
->owner
->enable_state
!= bp_permanent
)
3608 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3611 if (bl
->owner
->thread
!= -1)
3613 /* This is a thread-specific breakpoint. Check that ptid
3614 matches that thread. If thread hasn't been computed yet,
3615 it is now time to do so. */
3617 thread
= pid_to_thread_id (ptid
);
3618 if (bl
->owner
->thread
!= thread
)
3622 if (bl
->owner
->task
!= 0)
3624 /* This is a task-specific breakpoint. Check that ptid
3625 matches that task. If task hasn't been computed yet,
3626 it is now time to do so. */
3628 task
= ada_get_task_number (ptid
);
3629 if (bl
->owner
->task
!= task
)
3633 if (overlay_debugging
3634 && section_is_overlay (bl
->section
)
3635 && !section_is_mapped (bl
->section
))
3636 continue; /* unmapped overlay -- can't be a match */
3645 /* bpstat stuff. External routines' interfaces are documented
3649 is_catchpoint (struct breakpoint
*ep
)
3651 return (ep
->type
== bp_catchpoint
);
3654 /* Frees any storage that is part of a bpstat. Does not walk the
3658 bpstat_free (bpstat bs
)
3660 if (bs
->old_val
!= NULL
)
3661 value_free (bs
->old_val
);
3662 decref_counted_command_line (&bs
->commands
);
3663 decref_bp_location (&bs
->bp_location_at
);
3667 /* Clear a bpstat so that it says we are not at any breakpoint.
3668 Also free any storage that is part of a bpstat. */
3671 bpstat_clear (bpstat
*bsp
)
3688 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3689 is part of the bpstat is copied as well. */
3692 bpstat_copy (bpstat bs
)
3696 bpstat retval
= NULL
;
3701 for (; bs
!= NULL
; bs
= bs
->next
)
3703 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3704 memcpy (tmp
, bs
, sizeof (*tmp
));
3705 incref_counted_command_line (tmp
->commands
);
3706 incref_bp_location (tmp
->bp_location_at
);
3707 if (bs
->old_val
!= NULL
)
3709 tmp
->old_val
= value_copy (bs
->old_val
);
3710 release_value (tmp
->old_val
);
3714 /* This is the first thing in the chain. */
3724 /* Find the bpstat associated with this breakpoint. */
3727 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3732 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3734 if (bsp
->breakpoint_at
== breakpoint
)
3740 /* Put in *NUM the breakpoint number of the first breakpoint we are
3741 stopped at. *BSP upon return is a bpstat which points to the
3742 remaining breakpoints stopped at (but which is not guaranteed to be
3743 good for anything but further calls to bpstat_num).
3745 Return 0 if passed a bpstat which does not indicate any breakpoints.
3746 Return -1 if stopped at a breakpoint that has been deleted since
3748 Return 1 otherwise. */
3751 bpstat_num (bpstat
*bsp
, int *num
)
3753 struct breakpoint
*b
;
3756 return 0; /* No more breakpoint values */
3758 /* We assume we'll never have several bpstats that correspond to a
3759 single breakpoint -- otherwise, this function might return the
3760 same number more than once and this will look ugly. */
3761 b
= (*bsp
)->breakpoint_at
;
3762 *bsp
= (*bsp
)->next
;
3764 return -1; /* breakpoint that's been deleted since */
3766 *num
= b
->number
; /* We have its number */
3770 /* See breakpoint.h. */
3773 bpstat_clear_actions (void)
3775 struct thread_info
*tp
;
3778 if (ptid_equal (inferior_ptid
, null_ptid
))
3781 tp
= find_thread_ptid (inferior_ptid
);
3785 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3787 decref_counted_command_line (&bs
->commands
);
3789 if (bs
->old_val
!= NULL
)
3791 value_free (bs
->old_val
);
3797 /* Called when a command is about to proceed the inferior. */
3800 breakpoint_about_to_proceed (void)
3802 if (!ptid_equal (inferior_ptid
, null_ptid
))
3804 struct thread_info
*tp
= inferior_thread ();
3806 /* Allow inferior function calls in breakpoint commands to not
3807 interrupt the command list. When the call finishes
3808 successfully, the inferior will be standing at the same
3809 breakpoint as if nothing happened. */
3810 if (tp
->control
.in_infcall
)
3814 breakpoint_proceeded
= 1;
3817 /* Stub for cleaning up our state if we error-out of a breakpoint
3820 cleanup_executing_breakpoints (void *ignore
)
3822 executing_breakpoint_commands
= 0;
3825 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3826 or its equivalent. */
3829 command_line_is_silent (struct command_line
*cmd
)
3831 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3832 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3835 /* Execute all the commands associated with all the breakpoints at
3836 this location. Any of these commands could cause the process to
3837 proceed beyond this point, etc. We look out for such changes by
3838 checking the global "breakpoint_proceeded" after each command.
3840 Returns true if a breakpoint command resumed the inferior. In that
3841 case, it is the caller's responsibility to recall it again with the
3842 bpstat of the current thread. */
3845 bpstat_do_actions_1 (bpstat
*bsp
)
3848 struct cleanup
*old_chain
;
3851 /* Avoid endless recursion if a `source' command is contained
3853 if (executing_breakpoint_commands
)
3856 executing_breakpoint_commands
= 1;
3857 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3859 prevent_dont_repeat ();
3861 /* This pointer will iterate over the list of bpstat's. */
3864 breakpoint_proceeded
= 0;
3865 for (; bs
!= NULL
; bs
= bs
->next
)
3867 struct counted_command_line
*ccmd
;
3868 struct command_line
*cmd
;
3869 struct cleanup
*this_cmd_tree_chain
;
3871 /* Take ownership of the BSP's command tree, if it has one.
3873 The command tree could legitimately contain commands like
3874 'step' and 'next', which call clear_proceed_status, which
3875 frees stop_bpstat's command tree. To make sure this doesn't
3876 free the tree we're executing out from under us, we need to
3877 take ownership of the tree ourselves. Since a given bpstat's
3878 commands are only executed once, we don't need to copy it; we
3879 can clear the pointer in the bpstat, and make sure we free
3880 the tree when we're done. */
3881 ccmd
= bs
->commands
;
3882 bs
->commands
= NULL
;
3883 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
3884 cmd
= ccmd
? ccmd
->commands
: NULL
;
3885 if (command_line_is_silent (cmd
))
3887 /* The action has been already done by bpstat_stop_status. */
3893 execute_control_command (cmd
);
3895 if (breakpoint_proceeded
)
3901 /* We can free this command tree now. */
3902 do_cleanups (this_cmd_tree_chain
);
3904 if (breakpoint_proceeded
)
3906 if (target_can_async_p ())
3907 /* If we are in async mode, then the target might be still
3908 running, not stopped at any breakpoint, so nothing for
3909 us to do here -- just return to the event loop. */
3912 /* In sync mode, when execute_control_command returns
3913 we're already standing on the next breakpoint.
3914 Breakpoint commands for that stop were not run, since
3915 execute_command does not run breakpoint commands --
3916 only command_line_handler does, but that one is not
3917 involved in execution of breakpoint commands. So, we
3918 can now execute breakpoint commands. It should be
3919 noted that making execute_command do bpstat actions is
3920 not an option -- in this case we'll have recursive
3921 invocation of bpstat for each breakpoint with a
3922 command, and can easily blow up GDB stack. Instead, we
3923 return true, which will trigger the caller to recall us
3924 with the new stop_bpstat. */
3929 do_cleanups (old_chain
);
3934 bpstat_do_actions (void)
3936 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
3938 /* Do any commands attached to breakpoint we are stopped at. */
3939 while (!ptid_equal (inferior_ptid
, null_ptid
)
3940 && target_has_execution
3941 && !is_exited (inferior_ptid
)
3942 && !is_executing (inferior_ptid
))
3943 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3944 and only return when it is stopped at the next breakpoint, we
3945 keep doing breakpoint actions until it returns false to
3946 indicate the inferior was not resumed. */
3947 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3950 discard_cleanups (cleanup_if_error
);
3953 /* Print out the (old or new) value associated with a watchpoint. */
3956 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3959 fprintf_unfiltered (stream
, _("<unreadable>"));
3962 struct value_print_options opts
;
3963 get_user_print_options (&opts
);
3964 value_print (val
, stream
, &opts
);
3968 /* Generic routine for printing messages indicating why we
3969 stopped. The behavior of this function depends on the value
3970 'print_it' in the bpstat structure. Under some circumstances we
3971 may decide not to print anything here and delegate the task to
3974 static enum print_stop_action
3975 print_bp_stop_message (bpstat bs
)
3977 switch (bs
->print_it
)
3980 /* Nothing should be printed for this bpstat entry. */
3981 return PRINT_UNKNOWN
;
3985 /* We still want to print the frame, but we already printed the
3986 relevant messages. */
3987 return PRINT_SRC_AND_LOC
;
3990 case print_it_normal
:
3992 struct breakpoint
*b
= bs
->breakpoint_at
;
3994 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3995 which has since been deleted. */
3997 return PRINT_UNKNOWN
;
3999 /* Normal case. Call the breakpoint's print_it method. */
4000 return b
->ops
->print_it (bs
);
4005 internal_error (__FILE__
, __LINE__
,
4006 _("print_bp_stop_message: unrecognized enum value"));
4011 /* A helper function that prints a shared library stopped event. */
4014 print_solib_event (int is_catchpoint
)
4017 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4019 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4023 if (any_added
|| any_deleted
)
4024 ui_out_text (current_uiout
,
4025 _("Stopped due to shared library event:\n"));
4027 ui_out_text (current_uiout
,
4028 _("Stopped due to shared library event (no "
4029 "libraries added or removed)\n"));
4032 if (ui_out_is_mi_like_p (current_uiout
))
4033 ui_out_field_string (current_uiout
, "reason",
4034 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4038 struct cleanup
*cleanup
;
4042 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4043 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4046 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4051 ui_out_text (current_uiout
, " ");
4052 ui_out_field_string (current_uiout
, "library", name
);
4053 ui_out_text (current_uiout
, "\n");
4056 do_cleanups (cleanup
);
4061 struct so_list
*iter
;
4063 struct cleanup
*cleanup
;
4065 ui_out_text (current_uiout
, _(" Inferior loaded "));
4066 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4069 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4074 ui_out_text (current_uiout
, " ");
4075 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4076 ui_out_text (current_uiout
, "\n");
4079 do_cleanups (cleanup
);
4083 /* Print a message indicating what happened. This is called from
4084 normal_stop(). The input to this routine is the head of the bpstat
4085 list - a list of the eventpoints that caused this stop. KIND is
4086 the target_waitkind for the stopping event. This
4087 routine calls the generic print routine for printing a message
4088 about reasons for stopping. This will print (for example) the
4089 "Breakpoint n," part of the output. The return value of this
4092 PRINT_UNKNOWN: Means we printed nothing.
4093 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4094 code to print the location. An example is
4095 "Breakpoint 1, " which should be followed by
4097 PRINT_SRC_ONLY: Means we printed something, but there is no need
4098 to also print the location part of the message.
4099 An example is the catch/throw messages, which
4100 don't require a location appended to the end.
4101 PRINT_NOTHING: We have done some printing and we don't need any
4102 further info to be printed. */
4104 enum print_stop_action
4105 bpstat_print (bpstat bs
, int kind
)
4109 /* Maybe another breakpoint in the chain caused us to stop.
4110 (Currently all watchpoints go on the bpstat whether hit or not.
4111 That probably could (should) be changed, provided care is taken
4112 with respect to bpstat_explains_signal). */
4113 for (; bs
; bs
= bs
->next
)
4115 val
= print_bp_stop_message (bs
);
4116 if (val
== PRINT_SRC_ONLY
4117 || val
== PRINT_SRC_AND_LOC
4118 || val
== PRINT_NOTHING
)
4122 /* If we had hit a shared library event breakpoint,
4123 print_bp_stop_message would print out this message. If we hit an
4124 OS-level shared library event, do the same thing. */
4125 if (kind
== TARGET_WAITKIND_LOADED
)
4127 print_solib_event (0);
4128 return PRINT_NOTHING
;
4131 /* We reached the end of the chain, or we got a null BS to start
4132 with and nothing was printed. */
4133 return PRINT_UNKNOWN
;
4136 /* Evaluate the expression EXP and return 1 if value is zero. This is
4137 used inside a catch_errors to evaluate the breakpoint condition.
4138 The argument is a "struct expression *" that has been cast to a
4139 "char *" to make it pass through catch_errors. */
4142 breakpoint_cond_eval (void *exp
)
4144 struct value
*mark
= value_mark ();
4145 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4147 value_free_to_mark (mark
);
4151 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4154 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4158 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4160 **bs_link_pointer
= bs
;
4161 *bs_link_pointer
= &bs
->next
;
4162 bs
->breakpoint_at
= bl
->owner
;
4163 bs
->bp_location_at
= bl
;
4164 incref_bp_location (bl
);
4165 /* If the condition is false, etc., don't do the commands. */
4166 bs
->commands
= NULL
;
4168 bs
->print_it
= print_it_normal
;
4172 /* The target has stopped with waitstatus WS. Check if any hardware
4173 watchpoints have triggered, according to the target. */
4176 watchpoints_triggered (struct target_waitstatus
*ws
)
4178 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4180 struct breakpoint
*b
;
4182 if (!stopped_by_watchpoint
)
4184 /* We were not stopped by a watchpoint. Mark all watchpoints
4185 as not triggered. */
4187 if (is_hardware_watchpoint (b
))
4189 struct watchpoint
*w
= (struct watchpoint
*) b
;
4191 w
->watchpoint_triggered
= watch_triggered_no
;
4197 if (!target_stopped_data_address (¤t_target
, &addr
))
4199 /* We were stopped by a watchpoint, but we don't know where.
4200 Mark all watchpoints as unknown. */
4202 if (is_hardware_watchpoint (b
))
4204 struct watchpoint
*w
= (struct watchpoint
*) b
;
4206 w
->watchpoint_triggered
= watch_triggered_unknown
;
4209 return stopped_by_watchpoint
;
4212 /* The target could report the data address. Mark watchpoints
4213 affected by this data address as triggered, and all others as not
4217 if (is_hardware_watchpoint (b
))
4219 struct watchpoint
*w
= (struct watchpoint
*) b
;
4220 struct bp_location
*loc
;
4222 w
->watchpoint_triggered
= watch_triggered_no
;
4223 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4225 if (is_masked_watchpoint (b
))
4227 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4228 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4230 if (newaddr
== start
)
4232 w
->watchpoint_triggered
= watch_triggered_yes
;
4236 /* Exact match not required. Within range is sufficient. */
4237 else if (target_watchpoint_addr_within_range (¤t_target
,
4241 w
->watchpoint_triggered
= watch_triggered_yes
;
4250 /* Possible return values for watchpoint_check (this can't be an enum
4251 because of check_errors). */
4252 /* The watchpoint has been deleted. */
4253 #define WP_DELETED 1
4254 /* The value has changed. */
4255 #define WP_VALUE_CHANGED 2
4256 /* The value has not changed. */
4257 #define WP_VALUE_NOT_CHANGED 3
4258 /* Ignore this watchpoint, no matter if the value changed or not. */
4261 #define BP_TEMPFLAG 1
4262 #define BP_HARDWAREFLAG 2
4264 /* Evaluate watchpoint condition expression and check if its value
4267 P should be a pointer to struct bpstat, but is defined as a void *
4268 in order for this function to be usable with catch_errors. */
4271 watchpoint_check (void *p
)
4273 bpstat bs
= (bpstat
) p
;
4274 struct watchpoint
*b
;
4275 struct frame_info
*fr
;
4276 int within_current_scope
;
4278 /* BS is built from an existing struct breakpoint. */
4279 gdb_assert (bs
->breakpoint_at
!= NULL
);
4280 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4282 /* If this is a local watchpoint, we only want to check if the
4283 watchpoint frame is in scope if the current thread is the thread
4284 that was used to create the watchpoint. */
4285 if (!watchpoint_in_thread_scope (b
))
4288 if (b
->exp_valid_block
== NULL
)
4289 within_current_scope
= 1;
4292 struct frame_info
*frame
= get_current_frame ();
4293 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4294 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4296 /* in_function_epilogue_p() returns a non-zero value if we're
4297 still in the function but the stack frame has already been
4298 invalidated. Since we can't rely on the values of local
4299 variables after the stack has been destroyed, we are treating
4300 the watchpoint in that state as `not changed' without further
4301 checking. Don't mark watchpoints as changed if the current
4302 frame is in an epilogue - even if they are in some other
4303 frame, our view of the stack is likely to be wrong and
4304 frame_find_by_id could error out. */
4305 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4308 fr
= frame_find_by_id (b
->watchpoint_frame
);
4309 within_current_scope
= (fr
!= NULL
);
4311 /* If we've gotten confused in the unwinder, we might have
4312 returned a frame that can't describe this variable. */
4313 if (within_current_scope
)
4315 struct symbol
*function
;
4317 function
= get_frame_function (fr
);
4318 if (function
== NULL
4319 || !contained_in (b
->exp_valid_block
,
4320 SYMBOL_BLOCK_VALUE (function
)))
4321 within_current_scope
= 0;
4324 if (within_current_scope
)
4325 /* If we end up stopping, the current frame will get selected
4326 in normal_stop. So this call to select_frame won't affect
4331 if (within_current_scope
)
4333 /* We use value_{,free_to_}mark because it could be a *long*
4334 time before we return to the command level and call
4335 free_all_values. We can't call free_all_values because we
4336 might be in the middle of evaluating a function call. */
4340 struct value
*new_val
;
4342 if (is_masked_watchpoint (&b
->base
))
4343 /* Since we don't know the exact trigger address (from
4344 stopped_data_address), just tell the user we've triggered
4345 a mask watchpoint. */
4346 return WP_VALUE_CHANGED
;
4348 mark
= value_mark ();
4349 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
4351 /* We use value_equal_contents instead of value_equal because
4352 the latter coerces an array to a pointer, thus comparing just
4353 the address of the array instead of its contents. This is
4354 not what we want. */
4355 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4356 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4358 if (new_val
!= NULL
)
4360 release_value (new_val
);
4361 value_free_to_mark (mark
);
4363 bs
->old_val
= b
->val
;
4366 return WP_VALUE_CHANGED
;
4370 /* Nothing changed. */
4371 value_free_to_mark (mark
);
4372 return WP_VALUE_NOT_CHANGED
;
4377 struct ui_out
*uiout
= current_uiout
;
4379 /* This seems like the only logical thing to do because
4380 if we temporarily ignored the watchpoint, then when
4381 we reenter the block in which it is valid it contains
4382 garbage (in the case of a function, it may have two
4383 garbage values, one before and one after the prologue).
4384 So we can't even detect the first assignment to it and
4385 watch after that (since the garbage may or may not equal
4386 the first value assigned). */
4387 /* We print all the stop information in
4388 breakpoint_ops->print_it, but in this case, by the time we
4389 call breakpoint_ops->print_it this bp will be deleted
4390 already. So we have no choice but print the information
4392 if (ui_out_is_mi_like_p (uiout
))
4394 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4395 ui_out_text (uiout
, "\nWatchpoint ");
4396 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
4398 " deleted because the program has left the block in\n\
4399 which its expression is valid.\n");
4401 /* Make sure the watchpoint's commands aren't executed. */
4402 decref_counted_command_line (&b
->base
.commands
);
4403 watchpoint_del_at_next_stop (b
);
4409 /* Return true if it looks like target has stopped due to hitting
4410 breakpoint location BL. This function does not check if we should
4411 stop, only if BL explains the stop. */
4414 bpstat_check_location (const struct bp_location
*bl
,
4415 struct address_space
*aspace
, CORE_ADDR bp_addr
,
4416 const struct target_waitstatus
*ws
)
4418 struct breakpoint
*b
= bl
->owner
;
4420 /* BL is from an existing breakpoint. */
4421 gdb_assert (b
!= NULL
);
4423 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4426 /* Determine if the watched values have actually changed, and we
4427 should stop. If not, set BS->stop to 0. */
4430 bpstat_check_watchpoint (bpstat bs
)
4432 const struct bp_location
*bl
;
4433 struct watchpoint
*b
;
4435 /* BS is built for existing struct breakpoint. */
4436 bl
= bs
->bp_location_at
;
4437 gdb_assert (bl
!= NULL
);
4438 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4439 gdb_assert (b
!= NULL
);
4442 int must_check_value
= 0;
4444 if (b
->base
.type
== bp_watchpoint
)
4445 /* For a software watchpoint, we must always check the
4447 must_check_value
= 1;
4448 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4449 /* We have a hardware watchpoint (read, write, or access)
4450 and the target earlier reported an address watched by
4452 must_check_value
= 1;
4453 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4454 && b
->base
.type
== bp_hardware_watchpoint
)
4455 /* We were stopped by a hardware watchpoint, but the target could
4456 not report the data address. We must check the watchpoint's
4457 value. Access and read watchpoints are out of luck; without
4458 a data address, we can't figure it out. */
4459 must_check_value
= 1;
4461 if (must_check_value
)
4464 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4466 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4467 int e
= catch_errors (watchpoint_check
, bs
, message
,
4469 do_cleanups (cleanups
);
4473 /* We've already printed what needs to be printed. */
4474 bs
->print_it
= print_it_done
;
4478 bs
->print_it
= print_it_noop
;
4481 case WP_VALUE_CHANGED
:
4482 if (b
->base
.type
== bp_read_watchpoint
)
4484 /* There are two cases to consider here:
4486 1. We're watching the triggered memory for reads.
4487 In that case, trust the target, and always report
4488 the watchpoint hit to the user. Even though
4489 reads don't cause value changes, the value may
4490 have changed since the last time it was read, and
4491 since we're not trapping writes, we will not see
4492 those, and as such we should ignore our notion of
4495 2. We're watching the triggered memory for both
4496 reads and writes. There are two ways this may
4499 2.1. This is a target that can't break on data
4500 reads only, but can break on accesses (reads or
4501 writes), such as e.g., x86. We detect this case
4502 at the time we try to insert read watchpoints.
4504 2.2. Otherwise, the target supports read
4505 watchpoints, but, the user set an access or write
4506 watchpoint watching the same memory as this read
4509 If we're watching memory writes as well as reads,
4510 ignore watchpoint hits when we find that the
4511 value hasn't changed, as reads don't cause
4512 changes. This still gives false positives when
4513 the program writes the same value to memory as
4514 what there was already in memory (we will confuse
4515 it for a read), but it's much better than
4518 int other_write_watchpoint
= 0;
4520 if (bl
->watchpoint_type
== hw_read
)
4522 struct breakpoint
*other_b
;
4524 ALL_BREAKPOINTS (other_b
)
4525 if (other_b
->type
== bp_hardware_watchpoint
4526 || other_b
->type
== bp_access_watchpoint
)
4528 struct watchpoint
*other_w
=
4529 (struct watchpoint
*) other_b
;
4531 if (other_w
->watchpoint_triggered
4532 == watch_triggered_yes
)
4534 other_write_watchpoint
= 1;
4540 if (other_write_watchpoint
4541 || bl
->watchpoint_type
== hw_access
)
4543 /* We're watching the same memory for writes,
4544 and the value changed since the last time we
4545 updated it, so this trap must be for a write.
4547 bs
->print_it
= print_it_noop
;
4552 case WP_VALUE_NOT_CHANGED
:
4553 if (b
->base
.type
== bp_hardware_watchpoint
4554 || b
->base
.type
== bp_watchpoint
)
4556 /* Don't stop: write watchpoints shouldn't fire if
4557 the value hasn't changed. */
4558 bs
->print_it
= print_it_noop
;
4566 /* Error from catch_errors. */
4567 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
4568 watchpoint_del_at_next_stop (b
);
4569 /* We've already printed what needs to be printed. */
4570 bs
->print_it
= print_it_done
;
4574 else /* must_check_value == 0 */
4576 /* This is a case where some watchpoint(s) triggered, but
4577 not at the address of this watchpoint, or else no
4578 watchpoint triggered after all. So don't print
4579 anything for this watchpoint. */
4580 bs
->print_it
= print_it_noop
;
4587 /* Check conditions (condition proper, frame, thread and ignore count)
4588 of breakpoint referred to by BS. If we should not stop for this
4589 breakpoint, set BS->stop to 0. */
4592 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4594 int thread_id
= pid_to_thread_id (ptid
);
4595 const struct bp_location
*bl
;
4596 struct breakpoint
*b
;
4598 /* BS is built for existing struct breakpoint. */
4599 bl
= bs
->bp_location_at
;
4600 gdb_assert (bl
!= NULL
);
4601 b
= bs
->breakpoint_at
;
4602 gdb_assert (b
!= NULL
);
4604 /* Even if the target evaluated the condition on its end and notified GDB, we
4605 need to do so again since GDB does not know if we stopped due to a
4606 breakpoint or a single step breakpoint. */
4608 if (frame_id_p (b
->frame_id
)
4609 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4613 int value_is_zero
= 0;
4614 struct expression
*cond
;
4616 /* Evaluate Python breakpoints that have a "stop"
4617 method implemented. */
4618 if (b
->py_bp_object
)
4619 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4621 if (is_watchpoint (b
))
4623 struct watchpoint
*w
= (struct watchpoint
*) b
;
4630 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4632 int within_current_scope
= 1;
4633 struct watchpoint
* w
;
4635 /* We use value_mark and value_free_to_mark because it could
4636 be a long time before we return to the command level and
4637 call free_all_values. We can't call free_all_values
4638 because we might be in the middle of evaluating a
4640 struct value
*mark
= value_mark ();
4642 if (is_watchpoint (b
))
4643 w
= (struct watchpoint
*) b
;
4647 /* Need to select the frame, with all that implies so that
4648 the conditions will have the right context. Because we
4649 use the frame, we will not see an inlined function's
4650 variables when we arrive at a breakpoint at the start
4651 of the inlined function; the current frame will be the
4653 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4654 select_frame (get_current_frame ());
4657 struct frame_info
*frame
;
4659 /* For local watchpoint expressions, which particular
4660 instance of a local is being watched matters, so we
4661 keep track of the frame to evaluate the expression
4662 in. To evaluate the condition however, it doesn't
4663 really matter which instantiation of the function
4664 where the condition makes sense triggers the
4665 watchpoint. This allows an expression like "watch
4666 global if q > 10" set in `func', catch writes to
4667 global on all threads that call `func', or catch
4668 writes on all recursive calls of `func' by a single
4669 thread. We simply always evaluate the condition in
4670 the innermost frame that's executing where it makes
4671 sense to evaluate the condition. It seems
4673 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4675 select_frame (frame
);
4677 within_current_scope
= 0;
4679 if (within_current_scope
)
4681 = catch_errors (breakpoint_cond_eval
, cond
,
4682 "Error in testing breakpoint condition:\n",
4686 warning (_("Watchpoint condition cannot be tested "
4687 "in the current scope"));
4688 /* If we failed to set the right context for this
4689 watchpoint, unconditionally report it. */
4692 /* FIXME-someday, should give breakpoint #. */
4693 value_free_to_mark (mark
);
4696 if (cond
&& value_is_zero
)
4700 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4704 else if (b
->ignore_count
> 0)
4707 annotate_ignore_count_change ();
4709 /* Increase the hit count even though we don't stop. */
4711 observer_notify_breakpoint_modified (b
);
4717 /* Get a bpstat associated with having just stopped at address
4718 BP_ADDR in thread PTID.
4720 Determine whether we stopped at a breakpoint, etc, or whether we
4721 don't understand this stop. Result is a chain of bpstat's such
4724 if we don't understand the stop, the result is a null pointer.
4726 if we understand why we stopped, the result is not null.
4728 Each element of the chain refers to a particular breakpoint or
4729 watchpoint at which we have stopped. (We may have stopped for
4730 several reasons concurrently.)
4732 Each element of the chain has valid next, breakpoint_at,
4733 commands, FIXME??? fields. */
4736 bpstat_stop_status (struct address_space
*aspace
,
4737 CORE_ADDR bp_addr
, ptid_t ptid
,
4738 const struct target_waitstatus
*ws
)
4740 struct breakpoint
*b
= NULL
;
4741 struct bp_location
*bl
;
4742 struct bp_location
*loc
;
4743 /* First item of allocated bpstat's. */
4744 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4745 /* Pointer to the last thing in the chain currently. */
4748 int need_remove_insert
;
4751 /* First, build the bpstat chain with locations that explain a
4752 target stop, while being careful to not set the target running,
4753 as that may invalidate locations (in particular watchpoint
4754 locations are recreated). Resuming will happen here with
4755 breakpoint conditions or watchpoint expressions that include
4756 inferior function calls. */
4760 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4763 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4765 /* For hardware watchpoints, we look only at the first
4766 location. The watchpoint_check function will work on the
4767 entire expression, not the individual locations. For
4768 read watchpoints, the watchpoints_triggered function has
4769 checked all locations already. */
4770 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4773 if (bl
->shlib_disabled
)
4776 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
4779 /* Come here if it's a watchpoint, or if the break address
4782 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4785 /* Assume we stop. Should we find a watchpoint that is not
4786 actually triggered, or if the condition of the breakpoint
4787 evaluates as false, we'll reset 'stop' to 0. */
4791 /* If this is a scope breakpoint, mark the associated
4792 watchpoint as triggered so that we will handle the
4793 out-of-scope event. We'll get to the watchpoint next
4795 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4797 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4799 w
->watchpoint_triggered
= watch_triggered_yes
;
4804 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4806 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4808 bs
= bpstat_alloc (loc
, &bs_link
);
4809 /* For hits of moribund locations, we should just proceed. */
4812 bs
->print_it
= print_it_noop
;
4816 /* A bit of special processing for shlib breakpoints. We need to
4817 process solib loading here, so that the lists of loaded and
4818 unloaded libraries are correct before we handle "catch load" and
4820 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4822 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
4824 handle_solib_event ();
4829 /* Now go through the locations that caused the target to stop, and
4830 check whether we're interested in reporting this stop to higher
4831 layers, or whether we should resume the target transparently. */
4835 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4840 b
= bs
->breakpoint_at
;
4841 b
->ops
->check_status (bs
);
4844 bpstat_check_breakpoint_conditions (bs
, ptid
);
4849 observer_notify_breakpoint_modified (b
);
4851 /* We will stop here. */
4852 if (b
->disposition
== disp_disable
)
4854 --(b
->enable_count
);
4855 if (b
->enable_count
<= 0
4856 && b
->enable_state
!= bp_permanent
)
4857 b
->enable_state
= bp_disabled
;
4862 bs
->commands
= b
->commands
;
4863 incref_counted_command_line (bs
->commands
);
4864 if (command_line_is_silent (bs
->commands
4865 ? bs
->commands
->commands
: NULL
))
4871 /* Print nothing for this entry if we don't stop or don't
4873 if (!bs
->stop
|| !bs
->print
)
4874 bs
->print_it
= print_it_noop
;
4877 /* If we aren't stopping, the value of some hardware watchpoint may
4878 not have changed, but the intermediate memory locations we are
4879 watching may have. Don't bother if we're stopping; this will get
4881 need_remove_insert
= 0;
4882 if (! bpstat_causes_stop (bs_head
))
4883 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4885 && bs
->breakpoint_at
4886 && is_hardware_watchpoint (bs
->breakpoint_at
))
4888 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4890 update_watchpoint (w
, 0 /* don't reparse. */);
4891 need_remove_insert
= 1;
4894 if (need_remove_insert
)
4895 update_global_location_list (1);
4896 else if (removed_any
)
4897 update_global_location_list (0);
4903 handle_jit_event (void)
4905 struct frame_info
*frame
;
4906 struct gdbarch
*gdbarch
;
4908 /* Switch terminal for any messages produced by
4909 breakpoint_re_set. */
4910 target_terminal_ours_for_output ();
4912 frame
= get_current_frame ();
4913 gdbarch
= get_frame_arch (frame
);
4915 jit_event_handler (gdbarch
);
4917 target_terminal_inferior ();
4920 /* Handle an solib event by calling solib_add. */
4923 handle_solib_event (void)
4925 clear_program_space_solib_cache (current_inferior ()->pspace
);
4927 /* Check for any newly added shared libraries if we're supposed to
4928 be adding them automatically. Switch terminal for any messages
4929 produced by breakpoint_re_set. */
4930 target_terminal_ours_for_output ();
4932 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4934 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4936 target_terminal_inferior ();
4939 /* Prepare WHAT final decision for infrun. */
4941 /* Decide what infrun needs to do with this bpstat. */
4944 bpstat_what (bpstat bs_head
)
4946 struct bpstat_what retval
;
4950 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4951 retval
.call_dummy
= STOP_NONE
;
4952 retval
.is_longjmp
= 0;
4954 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4956 /* Extract this BS's action. After processing each BS, we check
4957 if its action overrides all we've seem so far. */
4958 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4961 if (bs
->breakpoint_at
== NULL
)
4963 /* I suspect this can happen if it was a momentary
4964 breakpoint which has since been deleted. */
4968 bptype
= bs
->breakpoint_at
->type
;
4975 case bp_hardware_breakpoint
:
4978 case bp_shlib_event
:
4982 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4984 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4987 this_action
= BPSTAT_WHAT_SINGLE
;
4990 case bp_hardware_watchpoint
:
4991 case bp_read_watchpoint
:
4992 case bp_access_watchpoint
:
4996 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4998 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5002 /* There was a watchpoint, but we're not stopping.
5003 This requires no further action. */
5008 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5009 retval
.is_longjmp
= bptype
== bp_longjmp
;
5011 case bp_longjmp_resume
:
5012 case bp_exception_resume
:
5013 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5014 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5016 case bp_step_resume
:
5018 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5021 /* It is for the wrong frame. */
5022 this_action
= BPSTAT_WHAT_SINGLE
;
5025 case bp_hp_step_resume
:
5027 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5030 /* It is for the wrong frame. */
5031 this_action
= BPSTAT_WHAT_SINGLE
;
5034 case bp_watchpoint_scope
:
5035 case bp_thread_event
:
5036 case bp_overlay_event
:
5037 case bp_longjmp_master
:
5038 case bp_std_terminate_master
:
5039 case bp_exception_master
:
5040 this_action
= BPSTAT_WHAT_SINGLE
;
5046 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5048 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5052 /* There was a catchpoint, but we're not stopping.
5053 This requires no further action. */
5058 this_action
= BPSTAT_WHAT_SINGLE
;
5061 /* Make sure the action is stop (silent or noisy),
5062 so infrun.c pops the dummy frame. */
5063 retval
.call_dummy
= STOP_STACK_DUMMY
;
5064 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5066 case bp_std_terminate
:
5067 /* Make sure the action is stop (silent or noisy),
5068 so infrun.c pops the dummy frame. */
5069 retval
.call_dummy
= STOP_STD_TERMINATE
;
5070 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5073 case bp_fast_tracepoint
:
5074 case bp_static_tracepoint
:
5075 /* Tracepoint hits should not be reported back to GDB, and
5076 if one got through somehow, it should have been filtered
5078 internal_error (__FILE__
, __LINE__
,
5079 _("bpstat_what: tracepoint encountered"));
5081 case bp_gnu_ifunc_resolver
:
5082 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5083 this_action
= BPSTAT_WHAT_SINGLE
;
5085 case bp_gnu_ifunc_resolver_return
:
5086 /* The breakpoint will be removed, execution will restart from the
5087 PC of the former breakpoint. */
5088 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5091 internal_error (__FILE__
, __LINE__
,
5092 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5095 retval
.main_action
= max (retval
.main_action
, this_action
);
5098 /* These operations may affect the bs->breakpoint_at state so they are
5099 delayed after MAIN_ACTION is decided above. */
5104 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5106 handle_jit_event ();
5109 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5111 struct breakpoint
*b
= bs
->breakpoint_at
;
5117 case bp_gnu_ifunc_resolver
:
5118 gnu_ifunc_resolver_stop (b
);
5120 case bp_gnu_ifunc_resolver_return
:
5121 gnu_ifunc_resolver_return_stop (b
);
5129 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5130 without hardware support). This isn't related to a specific bpstat,
5131 just to things like whether watchpoints are set. */
5134 bpstat_should_step (void)
5136 struct breakpoint
*b
;
5139 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5145 bpstat_causes_stop (bpstat bs
)
5147 for (; bs
!= NULL
; bs
= bs
->next
)
5156 /* Compute a string of spaces suitable to indent the next line
5157 so it starts at the position corresponding to the table column
5158 named COL_NAME in the currently active table of UIOUT. */
5161 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5163 static char wrap_indent
[80];
5164 int i
, total_width
, width
, align
;
5168 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5170 if (strcmp (text
, col_name
) == 0)
5172 gdb_assert (total_width
< sizeof wrap_indent
);
5173 memset (wrap_indent
, ' ', total_width
);
5174 wrap_indent
[total_width
] = 0;
5179 total_width
+= width
+ 1;
5185 /* Determine if the locations of this breakpoint will have their conditions
5186 evaluated by the target, host or a mix of both. Returns the following:
5188 "host": Host evals condition.
5189 "host or target": Host or Target evals condition.
5190 "target": Target evals condition.
5194 bp_condition_evaluator (struct breakpoint
*b
)
5196 struct bp_location
*bl
;
5197 char host_evals
= 0;
5198 char target_evals
= 0;
5203 if (!is_breakpoint (b
))
5206 if (gdb_evaluates_breakpoint_condition_p ()
5207 || !target_supports_evaluation_of_breakpoint_conditions ())
5208 return condition_evaluation_host
;
5210 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5212 if (bl
->cond_bytecode
)
5218 if (host_evals
&& target_evals
)
5219 return condition_evaluation_both
;
5220 else if (target_evals
)
5221 return condition_evaluation_target
;
5223 return condition_evaluation_host
;
5226 /* Determine the breakpoint location's condition evaluator. This is
5227 similar to bp_condition_evaluator, but for locations. */
5230 bp_location_condition_evaluator (struct bp_location
*bl
)
5232 if (bl
&& !is_breakpoint (bl
->owner
))
5235 if (gdb_evaluates_breakpoint_condition_p ()
5236 || !target_supports_evaluation_of_breakpoint_conditions ())
5237 return condition_evaluation_host
;
5239 if (bl
&& bl
->cond_bytecode
)
5240 return condition_evaluation_target
;
5242 return condition_evaluation_host
;
5245 /* Print the LOC location out of the list of B->LOC locations. */
5248 print_breakpoint_location (struct breakpoint
*b
,
5249 struct bp_location
*loc
)
5251 struct ui_out
*uiout
= current_uiout
;
5252 struct cleanup
*old_chain
= save_current_program_space ();
5254 if (loc
!= NULL
&& loc
->shlib_disabled
)
5258 set_current_program_space (loc
->pspace
);
5260 if (b
->display_canonical
)
5261 ui_out_field_string (uiout
, "what", b
->addr_string
);
5262 else if (loc
&& loc
->source_file
)
5265 = find_pc_sect_function (loc
->address
, loc
->section
);
5268 ui_out_text (uiout
, "in ");
5269 ui_out_field_string (uiout
, "func",
5270 SYMBOL_PRINT_NAME (sym
));
5271 ui_out_text (uiout
, " ");
5272 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5273 ui_out_text (uiout
, "at ");
5275 ui_out_field_string (uiout
, "file", loc
->source_file
);
5276 ui_out_text (uiout
, ":");
5278 if (ui_out_is_mi_like_p (uiout
))
5280 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
5281 char *fullname
= symtab_to_fullname (sal
.symtab
);
5284 ui_out_field_string (uiout
, "fullname", fullname
);
5287 ui_out_field_int (uiout
, "line", loc
->line_number
);
5291 struct ui_file
*stb
= mem_fileopen ();
5292 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5294 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5296 ui_out_field_stream (uiout
, "at", stb
);
5298 do_cleanups (stb_chain
);
5301 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5303 if (loc
&& is_breakpoint (b
)
5304 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5305 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5307 ui_out_text (uiout
, " (");
5308 ui_out_field_string (uiout
, "evaluated-by",
5309 bp_location_condition_evaluator (loc
));
5310 ui_out_text (uiout
, ")");
5313 do_cleanups (old_chain
);
5317 bptype_string (enum bptype type
)
5319 struct ep_type_description
5324 static struct ep_type_description bptypes
[] =
5326 {bp_none
, "?deleted?"},
5327 {bp_breakpoint
, "breakpoint"},
5328 {bp_hardware_breakpoint
, "hw breakpoint"},
5329 {bp_until
, "until"},
5330 {bp_finish
, "finish"},
5331 {bp_watchpoint
, "watchpoint"},
5332 {bp_hardware_watchpoint
, "hw watchpoint"},
5333 {bp_read_watchpoint
, "read watchpoint"},
5334 {bp_access_watchpoint
, "acc watchpoint"},
5335 {bp_longjmp
, "longjmp"},
5336 {bp_longjmp_resume
, "longjmp resume"},
5337 {bp_exception
, "exception"},
5338 {bp_exception_resume
, "exception resume"},
5339 {bp_step_resume
, "step resume"},
5340 {bp_hp_step_resume
, "high-priority step resume"},
5341 {bp_watchpoint_scope
, "watchpoint scope"},
5342 {bp_call_dummy
, "call dummy"},
5343 {bp_std_terminate
, "std::terminate"},
5344 {bp_shlib_event
, "shlib events"},
5345 {bp_thread_event
, "thread events"},
5346 {bp_overlay_event
, "overlay events"},
5347 {bp_longjmp_master
, "longjmp master"},
5348 {bp_std_terminate_master
, "std::terminate master"},
5349 {bp_exception_master
, "exception master"},
5350 {bp_catchpoint
, "catchpoint"},
5351 {bp_tracepoint
, "tracepoint"},
5352 {bp_fast_tracepoint
, "fast tracepoint"},
5353 {bp_static_tracepoint
, "static tracepoint"},
5354 {bp_jit_event
, "jit events"},
5355 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5356 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5359 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5360 || ((int) type
!= bptypes
[(int) type
].type
))
5361 internal_error (__FILE__
, __LINE__
,
5362 _("bptypes table does not describe type #%d."),
5365 return bptypes
[(int) type
].description
;
5368 /* Print B to gdb_stdout. */
5371 print_one_breakpoint_location (struct breakpoint
*b
,
5372 struct bp_location
*loc
,
5374 struct bp_location
**last_loc
,
5377 struct command_line
*l
;
5378 static char bpenables
[] = "nynny";
5380 struct ui_out
*uiout
= current_uiout
;
5381 int header_of_multiple
= 0;
5382 int part_of_multiple
= (loc
!= NULL
);
5383 struct value_print_options opts
;
5385 get_user_print_options (&opts
);
5387 gdb_assert (!loc
|| loc_number
!= 0);
5388 /* See comment in print_one_breakpoint concerning treatment of
5389 breakpoints with single disabled location. */
5392 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5393 header_of_multiple
= 1;
5401 if (part_of_multiple
)
5404 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
5405 ui_out_field_string (uiout
, "number", formatted
);
5410 ui_out_field_int (uiout
, "number", b
->number
);
5415 if (part_of_multiple
)
5416 ui_out_field_skip (uiout
, "type");
5418 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
5422 if (part_of_multiple
)
5423 ui_out_field_skip (uiout
, "disp");
5425 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
5430 if (part_of_multiple
)
5431 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
5433 ui_out_field_fmt (uiout
, "enabled", "%c",
5434 bpenables
[(int) b
->enable_state
]);
5435 ui_out_spaces (uiout
, 2);
5439 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
5441 /* Although the print_one can possibly print all locations,
5442 calling it here is not likely to get any nice result. So,
5443 make sure there's just one location. */
5444 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
5445 b
->ops
->print_one (b
, last_loc
);
5451 internal_error (__FILE__
, __LINE__
,
5452 _("print_one_breakpoint: bp_none encountered\n"));
5456 case bp_hardware_watchpoint
:
5457 case bp_read_watchpoint
:
5458 case bp_access_watchpoint
:
5460 struct watchpoint
*w
= (struct watchpoint
*) b
;
5462 /* Field 4, the address, is omitted (which makes the columns
5463 not line up too nicely with the headers, but the effect
5464 is relatively readable). */
5465 if (opts
.addressprint
)
5466 ui_out_field_skip (uiout
, "addr");
5468 ui_out_field_string (uiout
, "what", w
->exp_string
);
5473 case bp_hardware_breakpoint
:
5477 case bp_longjmp_resume
:
5479 case bp_exception_resume
:
5480 case bp_step_resume
:
5481 case bp_hp_step_resume
:
5482 case bp_watchpoint_scope
:
5484 case bp_std_terminate
:
5485 case bp_shlib_event
:
5486 case bp_thread_event
:
5487 case bp_overlay_event
:
5488 case bp_longjmp_master
:
5489 case bp_std_terminate_master
:
5490 case bp_exception_master
:
5492 case bp_fast_tracepoint
:
5493 case bp_static_tracepoint
:
5495 case bp_gnu_ifunc_resolver
:
5496 case bp_gnu_ifunc_resolver_return
:
5497 if (opts
.addressprint
)
5500 if (header_of_multiple
)
5501 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
5502 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
5503 ui_out_field_string (uiout
, "addr", "<PENDING>");
5505 ui_out_field_core_addr (uiout
, "addr",
5506 loc
->gdbarch
, loc
->address
);
5509 if (!header_of_multiple
)
5510 print_breakpoint_location (b
, loc
);
5517 /* For backward compatibility, don't display inferiors unless there
5520 && !header_of_multiple
5522 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
5523 && (number_of_program_spaces () > 1
5524 || number_of_inferiors () > 1)
5525 /* LOC is for existing B, it cannot be in
5526 moribund_locations and thus having NULL OWNER. */
5527 && loc
->owner
->type
!= bp_catchpoint
)))
5529 struct inferior
*inf
;
5532 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
5534 if (inf
->pspace
== loc
->pspace
)
5539 ui_out_text (uiout
, " inf ");
5542 ui_out_text (uiout
, ", ");
5543 ui_out_text (uiout
, plongest (inf
->num
));
5548 if (!part_of_multiple
)
5550 if (b
->thread
!= -1)
5552 /* FIXME: This seems to be redundant and lost here; see the
5553 "stop only in" line a little further down. */
5554 ui_out_text (uiout
, " thread ");
5555 ui_out_field_int (uiout
, "thread", b
->thread
);
5557 else if (b
->task
!= 0)
5559 ui_out_text (uiout
, " task ");
5560 ui_out_field_int (uiout
, "task", b
->task
);
5564 ui_out_text (uiout
, "\n");
5566 if (!part_of_multiple
)
5567 b
->ops
->print_one_detail (b
, uiout
);
5569 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
5572 ui_out_text (uiout
, "\tstop only in stack frame at ");
5573 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5575 ui_out_field_core_addr (uiout
, "frame",
5576 b
->gdbarch
, b
->frame_id
.stack_addr
);
5577 ui_out_text (uiout
, "\n");
5580 if (!part_of_multiple
&& b
->cond_string
)
5583 if (is_tracepoint (b
))
5584 ui_out_text (uiout
, "\ttrace only if ");
5586 ui_out_text (uiout
, "\tstop only if ");
5587 ui_out_field_string (uiout
, "cond", b
->cond_string
);
5589 /* Print whether the target is doing the breakpoint's condition
5590 evaluation. If GDB is doing the evaluation, don't print anything. */
5591 if (is_breakpoint (b
)
5592 && breakpoint_condition_evaluation_mode ()
5593 == condition_evaluation_target
)
5595 ui_out_text (uiout
, " (");
5596 ui_out_field_string (uiout
, "evaluated-by",
5597 bp_condition_evaluator (b
));
5598 ui_out_text (uiout
, " evals)");
5600 ui_out_text (uiout
, "\n");
5603 if (!part_of_multiple
&& b
->thread
!= -1)
5605 /* FIXME should make an annotation for this. */
5606 ui_out_text (uiout
, "\tstop only in thread ");
5607 ui_out_field_int (uiout
, "thread", b
->thread
);
5608 ui_out_text (uiout
, "\n");
5611 if (!part_of_multiple
&& b
->hit_count
)
5613 /* FIXME should make an annotation for this. */
5614 if (is_catchpoint (b
))
5615 ui_out_text (uiout
, "\tcatchpoint");
5616 else if (is_tracepoint (b
))
5617 ui_out_text (uiout
, "\ttracepoint");
5619 ui_out_text (uiout
, "\tbreakpoint");
5620 ui_out_text (uiout
, " already hit ");
5621 ui_out_field_int (uiout
, "times", b
->hit_count
);
5622 if (b
->hit_count
== 1)
5623 ui_out_text (uiout
, " time\n");
5625 ui_out_text (uiout
, " times\n");
5628 /* Output the count also if it is zero, but only if this is mi.
5629 FIXME: Should have a better test for this. */
5630 if (ui_out_is_mi_like_p (uiout
))
5631 if (!part_of_multiple
&& b
->hit_count
== 0)
5632 ui_out_field_int (uiout
, "times", b
->hit_count
);
5634 if (!part_of_multiple
&& b
->ignore_count
)
5637 ui_out_text (uiout
, "\tignore next ");
5638 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
5639 ui_out_text (uiout
, " hits\n");
5642 /* Note that an enable count of 1 corresponds to "enable once"
5643 behavior, which is reported by the combination of enablement and
5644 disposition, so we don't need to mention it here. */
5645 if (!part_of_multiple
&& b
->enable_count
> 1)
5648 ui_out_text (uiout
, "\tdisable after ");
5649 /* Tweak the wording to clarify that ignore and enable counts
5650 are distinct, and have additive effect. */
5651 if (b
->ignore_count
)
5652 ui_out_text (uiout
, "additional ");
5654 ui_out_text (uiout
, "next ");
5655 ui_out_field_int (uiout
, "enable", b
->enable_count
);
5656 ui_out_text (uiout
, " hits\n");
5659 if (!part_of_multiple
&& is_tracepoint (b
))
5661 struct tracepoint
*tp
= (struct tracepoint
*) b
;
5663 if (tp
->traceframe_usage
)
5665 ui_out_text (uiout
, "\ttrace buffer usage ");
5666 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
5667 ui_out_text (uiout
, " bytes\n");
5671 l
= b
->commands
? b
->commands
->commands
: NULL
;
5672 if (!part_of_multiple
&& l
)
5674 struct cleanup
*script_chain
;
5677 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
5678 print_command_lines (uiout
, l
, 4);
5679 do_cleanups (script_chain
);
5682 if (is_tracepoint (b
))
5684 struct tracepoint
*t
= (struct tracepoint
*) b
;
5686 if (!part_of_multiple
&& t
->pass_count
)
5688 annotate_field (10);
5689 ui_out_text (uiout
, "\tpass count ");
5690 ui_out_field_int (uiout
, "pass", t
->pass_count
);
5691 ui_out_text (uiout
, " \n");
5695 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5697 if (is_watchpoint (b
))
5699 struct watchpoint
*w
= (struct watchpoint
*) b
;
5701 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
5703 else if (b
->addr_string
)
5704 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5709 print_one_breakpoint (struct breakpoint
*b
,
5710 struct bp_location
**last_loc
,
5713 struct cleanup
*bkpt_chain
;
5714 struct ui_out
*uiout
= current_uiout
;
5716 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5718 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5719 do_cleanups (bkpt_chain
);
5721 /* If this breakpoint has custom print function,
5722 it's already printed. Otherwise, print individual
5723 locations, if any. */
5724 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5726 /* If breakpoint has a single location that is disabled, we
5727 print it as if it had several locations, since otherwise it's
5728 hard to represent "breakpoint enabled, location disabled"
5731 Note that while hardware watchpoints have several locations
5732 internally, that's not a property exposed to user. */
5734 && !is_hardware_watchpoint (b
)
5735 && (b
->loc
->next
|| !b
->loc
->enabled
))
5737 struct bp_location
*loc
;
5740 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5742 struct cleanup
*inner2
=
5743 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5744 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5745 do_cleanups (inner2
);
5752 breakpoint_address_bits (struct breakpoint
*b
)
5754 int print_address_bits
= 0;
5755 struct bp_location
*loc
;
5757 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5761 /* Software watchpoints that aren't watching memory don't have
5762 an address to print. */
5763 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5766 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5767 if (addr_bit
> print_address_bits
)
5768 print_address_bits
= addr_bit
;
5771 return print_address_bits
;
5774 struct captured_breakpoint_query_args
5780 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5782 struct captured_breakpoint_query_args
*args
= data
;
5783 struct breakpoint
*b
;
5784 struct bp_location
*dummy_loc
= NULL
;
5788 if (args
->bnum
== b
->number
)
5790 print_one_breakpoint (b
, &dummy_loc
, 0);
5798 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5799 char **error_message
)
5801 struct captured_breakpoint_query_args args
;
5804 /* For the moment we don't trust print_one_breakpoint() to not throw
5806 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5807 error_message
, RETURN_MASK_ALL
) < 0)
5813 /* Return true if this breakpoint was set by the user, false if it is
5814 internal or momentary. */
5817 user_breakpoint_p (struct breakpoint
*b
)
5819 return b
->number
> 0;
5822 /* Print information on user settable breakpoint (watchpoint, etc)
5823 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5824 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5825 FILTER is non-NULL, call it on each breakpoint and only include the
5826 ones for which it returns non-zero. Return the total number of
5827 breakpoints listed. */
5830 breakpoint_1 (char *args
, int allflag
,
5831 int (*filter
) (const struct breakpoint
*))
5833 struct breakpoint
*b
;
5834 struct bp_location
*last_loc
= NULL
;
5835 int nr_printable_breakpoints
;
5836 struct cleanup
*bkpttbl_chain
;
5837 struct value_print_options opts
;
5838 int print_address_bits
= 0;
5839 int print_type_col_width
= 14;
5840 struct ui_out
*uiout
= current_uiout
;
5842 get_user_print_options (&opts
);
5844 /* Compute the number of rows in the table, as well as the size
5845 required for address fields. */
5846 nr_printable_breakpoints
= 0;
5849 /* If we have a filter, only list the breakpoints it accepts. */
5850 if (filter
&& !filter (b
))
5853 /* If we have an "args" string, it is a list of breakpoints to
5854 accept. Skip the others. */
5855 if (args
!= NULL
&& *args
!= '\0')
5857 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5859 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5863 if (allflag
|| user_breakpoint_p (b
))
5865 int addr_bit
, type_len
;
5867 addr_bit
= breakpoint_address_bits (b
);
5868 if (addr_bit
> print_address_bits
)
5869 print_address_bits
= addr_bit
;
5871 type_len
= strlen (bptype_string (b
->type
));
5872 if (type_len
> print_type_col_width
)
5873 print_type_col_width
= type_len
;
5875 nr_printable_breakpoints
++;
5879 if (opts
.addressprint
)
5881 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5882 nr_printable_breakpoints
,
5886 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5887 nr_printable_breakpoints
,
5890 if (nr_printable_breakpoints
> 0)
5891 annotate_breakpoints_headers ();
5892 if (nr_printable_breakpoints
> 0)
5894 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5895 if (nr_printable_breakpoints
> 0)
5897 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5898 "type", "Type"); /* 2 */
5899 if (nr_printable_breakpoints
> 0)
5901 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5902 if (nr_printable_breakpoints
> 0)
5904 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5905 if (opts
.addressprint
)
5907 if (nr_printable_breakpoints
> 0)
5909 if (print_address_bits
<= 32)
5910 ui_out_table_header (uiout
, 10, ui_left
,
5911 "addr", "Address"); /* 5 */
5913 ui_out_table_header (uiout
, 18, ui_left
,
5914 "addr", "Address"); /* 5 */
5916 if (nr_printable_breakpoints
> 0)
5918 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5919 ui_out_table_body (uiout
);
5920 if (nr_printable_breakpoints
> 0)
5921 annotate_breakpoints_table ();
5926 /* If we have a filter, only list the breakpoints it accepts. */
5927 if (filter
&& !filter (b
))
5930 /* If we have an "args" string, it is a list of breakpoints to
5931 accept. Skip the others. */
5933 if (args
!= NULL
&& *args
!= '\0')
5935 if (allflag
) /* maintenance info breakpoint */
5937 if (parse_and_eval_long (args
) != b
->number
)
5940 else /* all others */
5942 if (!number_is_in_list (args
, b
->number
))
5946 /* We only print out user settable breakpoints unless the
5948 if (allflag
|| user_breakpoint_p (b
))
5949 print_one_breakpoint (b
, &last_loc
, allflag
);
5952 do_cleanups (bkpttbl_chain
);
5954 if (nr_printable_breakpoints
== 0)
5956 /* If there's a filter, let the caller decide how to report
5960 if (args
== NULL
|| *args
== '\0')
5961 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5963 ui_out_message (uiout
, 0,
5964 "No breakpoint or watchpoint matching '%s'.\n",
5970 if (last_loc
&& !server_command
)
5971 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5974 /* FIXME? Should this be moved up so that it is only called when
5975 there have been breakpoints? */
5976 annotate_breakpoints_table_end ();
5978 return nr_printable_breakpoints
;
5981 /* Display the value of default-collect in a way that is generally
5982 compatible with the breakpoint list. */
5985 default_collect_info (void)
5987 struct ui_out
*uiout
= current_uiout
;
5989 /* If it has no value (which is frequently the case), say nothing; a
5990 message like "No default-collect." gets in user's face when it's
5992 if (!*default_collect
)
5995 /* The following phrase lines up nicely with per-tracepoint collect
5997 ui_out_text (uiout
, "default collect ");
5998 ui_out_field_string (uiout
, "default-collect", default_collect
);
5999 ui_out_text (uiout
, " \n");
6003 breakpoints_info (char *args
, int from_tty
)
6005 breakpoint_1 (args
, 0, NULL
);
6007 default_collect_info ();
6011 watchpoints_info (char *args
, int from_tty
)
6013 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6014 struct ui_out
*uiout
= current_uiout
;
6016 if (num_printed
== 0)
6018 if (args
== NULL
|| *args
== '\0')
6019 ui_out_message (uiout
, 0, "No watchpoints.\n");
6021 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6026 maintenance_info_breakpoints (char *args
, int from_tty
)
6028 breakpoint_1 (args
, 1, NULL
);
6030 default_collect_info ();
6034 breakpoint_has_pc (struct breakpoint
*b
,
6035 struct program_space
*pspace
,
6036 CORE_ADDR pc
, struct obj_section
*section
)
6038 struct bp_location
*bl
= b
->loc
;
6040 for (; bl
; bl
= bl
->next
)
6042 if (bl
->pspace
== pspace
6043 && bl
->address
== pc
6044 && (!overlay_debugging
|| bl
->section
== section
))
6050 /* Print a message describing any user-breakpoints set at PC. This
6051 concerns with logical breakpoints, so we match program spaces, not
6055 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6056 struct program_space
*pspace
, CORE_ADDR pc
,
6057 struct obj_section
*section
, int thread
)
6060 struct breakpoint
*b
;
6063 others
+= (user_breakpoint_p (b
)
6064 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6068 printf_filtered (_("Note: breakpoint "));
6069 else /* if (others == ???) */
6070 printf_filtered (_("Note: breakpoints "));
6072 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6075 printf_filtered ("%d", b
->number
);
6076 if (b
->thread
== -1 && thread
!= -1)
6077 printf_filtered (" (all threads)");
6078 else if (b
->thread
!= -1)
6079 printf_filtered (" (thread %d)", b
->thread
);
6080 printf_filtered ("%s%s ",
6081 ((b
->enable_state
== bp_disabled
6082 || b
->enable_state
== bp_call_disabled
)
6084 : b
->enable_state
== bp_permanent
6088 : ((others
== 1) ? " and" : ""));
6090 printf_filtered (_("also set at pc "));
6091 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6092 printf_filtered (".\n");
6097 /* Return true iff it is meaningful to use the address member of
6098 BPT. For some breakpoint types, the address member is irrelevant
6099 and it makes no sense to attempt to compare it to other addresses
6100 (or use it for any other purpose either).
6102 More specifically, each of the following breakpoint types will
6103 always have a zero valued address and we don't want to mark
6104 breakpoints of any of these types to be a duplicate of an actual
6105 breakpoint at address zero:
6113 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6115 enum bptype type
= bpt
->type
;
6117 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6120 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6121 true if LOC1 and LOC2 represent the same watchpoint location. */
6124 watchpoint_locations_match (struct bp_location
*loc1
,
6125 struct bp_location
*loc2
)
6127 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6128 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6130 /* Both of them must exist. */
6131 gdb_assert (w1
!= NULL
);
6132 gdb_assert (w2
!= NULL
);
6134 /* If the target can evaluate the condition expression in hardware,
6135 then we we need to insert both watchpoints even if they are at
6136 the same place. Otherwise the watchpoint will only trigger when
6137 the condition of whichever watchpoint was inserted evaluates to
6138 true, not giving a chance for GDB to check the condition of the
6139 other watchpoint. */
6141 && target_can_accel_watchpoint_condition (loc1
->address
,
6143 loc1
->watchpoint_type
,
6146 && target_can_accel_watchpoint_condition (loc2
->address
,
6148 loc2
->watchpoint_type
,
6152 /* Note that this checks the owner's type, not the location's. In
6153 case the target does not support read watchpoints, but does
6154 support access watchpoints, we'll have bp_read_watchpoint
6155 watchpoints with hw_access locations. Those should be considered
6156 duplicates of hw_read locations. The hw_read locations will
6157 become hw_access locations later. */
6158 return (loc1
->owner
->type
== loc2
->owner
->type
6159 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6160 && loc1
->address
== loc2
->address
6161 && loc1
->length
== loc2
->length
);
6164 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6165 same breakpoint location. In most targets, this can only be true
6166 if ASPACE1 matches ASPACE2. On targets that have global
6167 breakpoints, the address space doesn't really matter. */
6170 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6171 struct address_space
*aspace2
, CORE_ADDR addr2
)
6173 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6174 || aspace1
== aspace2
)
6178 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6179 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6180 matches ASPACE2. On targets that have global breakpoints, the address
6181 space doesn't really matter. */
6184 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6185 int len1
, struct address_space
*aspace2
,
6188 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6189 || aspace1
== aspace2
)
6190 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6193 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6194 a ranged breakpoint. In most targets, a match happens only if ASPACE
6195 matches the breakpoint's address space. On targets that have global
6196 breakpoints, the address space doesn't really matter. */
6199 breakpoint_location_address_match (struct bp_location
*bl
,
6200 struct address_space
*aspace
,
6203 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6206 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6207 bl
->address
, bl
->length
,
6211 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6212 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6213 true, otherwise returns false. */
6216 tracepoint_locations_match (struct bp_location
*loc1
,
6217 struct bp_location
*loc2
)
6219 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6220 /* Since tracepoint locations are never duplicated with others', tracepoint
6221 locations at the same address of different tracepoints are regarded as
6222 different locations. */
6223 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6228 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6229 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6230 represent the same location. */
6233 breakpoint_locations_match (struct bp_location
*loc1
,
6234 struct bp_location
*loc2
)
6236 int hw_point1
, hw_point2
;
6238 /* Both of them must not be in moribund_locations. */
6239 gdb_assert (loc1
->owner
!= NULL
);
6240 gdb_assert (loc2
->owner
!= NULL
);
6242 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6243 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6245 if (hw_point1
!= hw_point2
)
6248 return watchpoint_locations_match (loc1
, loc2
);
6249 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6250 return tracepoint_locations_match (loc1
, loc2
);
6252 /* We compare bp_location.length in order to cover ranged breakpoints. */
6253 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6254 loc2
->pspace
->aspace
, loc2
->address
)
6255 && loc1
->length
== loc2
->length
);
6259 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6260 int bnum
, int have_bnum
)
6262 /* The longest string possibly returned by hex_string_custom
6263 is 50 chars. These must be at least that big for safety. */
6267 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6268 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6270 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6271 bnum
, astr1
, astr2
);
6273 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6276 /* Adjust a breakpoint's address to account for architectural
6277 constraints on breakpoint placement. Return the adjusted address.
6278 Note: Very few targets require this kind of adjustment. For most
6279 targets, this function is simply the identity function. */
6282 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6283 CORE_ADDR bpaddr
, enum bptype bptype
)
6285 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6287 /* Very few targets need any kind of breakpoint adjustment. */
6290 else if (bptype
== bp_watchpoint
6291 || bptype
== bp_hardware_watchpoint
6292 || bptype
== bp_read_watchpoint
6293 || bptype
== bp_access_watchpoint
6294 || bptype
== bp_catchpoint
)
6296 /* Watchpoints and the various bp_catch_* eventpoints should not
6297 have their addresses modified. */
6302 CORE_ADDR adjusted_bpaddr
;
6304 /* Some targets have architectural constraints on the placement
6305 of breakpoint instructions. Obtain the adjusted address. */
6306 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6308 /* An adjusted breakpoint address can significantly alter
6309 a user's expectations. Print a warning if an adjustment
6311 if (adjusted_bpaddr
!= bpaddr
)
6312 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6314 return adjusted_bpaddr
;
6319 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6320 struct breakpoint
*owner
)
6322 memset (loc
, 0, sizeof (*loc
));
6324 gdb_assert (ops
!= NULL
);
6329 loc
->cond_bytecode
= NULL
;
6330 loc
->shlib_disabled
= 0;
6333 switch (owner
->type
)
6339 case bp_longjmp_resume
:
6341 case bp_exception_resume
:
6342 case bp_step_resume
:
6343 case bp_hp_step_resume
:
6344 case bp_watchpoint_scope
:
6346 case bp_std_terminate
:
6347 case bp_shlib_event
:
6348 case bp_thread_event
:
6349 case bp_overlay_event
:
6351 case bp_longjmp_master
:
6352 case bp_std_terminate_master
:
6353 case bp_exception_master
:
6354 case bp_gnu_ifunc_resolver
:
6355 case bp_gnu_ifunc_resolver_return
:
6356 loc
->loc_type
= bp_loc_software_breakpoint
;
6357 mark_breakpoint_location_modified (loc
);
6359 case bp_hardware_breakpoint
:
6360 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6361 mark_breakpoint_location_modified (loc
);
6363 case bp_hardware_watchpoint
:
6364 case bp_read_watchpoint
:
6365 case bp_access_watchpoint
:
6366 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6371 case bp_fast_tracepoint
:
6372 case bp_static_tracepoint
:
6373 loc
->loc_type
= bp_loc_other
;
6376 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6382 /* Allocate a struct bp_location. */
6384 static struct bp_location
*
6385 allocate_bp_location (struct breakpoint
*bpt
)
6387 return bpt
->ops
->allocate_location (bpt
);
6391 free_bp_location (struct bp_location
*loc
)
6393 loc
->ops
->dtor (loc
);
6397 /* Increment reference count. */
6400 incref_bp_location (struct bp_location
*bl
)
6405 /* Decrement reference count. If the reference count reaches 0,
6406 destroy the bp_location. Sets *BLP to NULL. */
6409 decref_bp_location (struct bp_location
**blp
)
6411 gdb_assert ((*blp
)->refc
> 0);
6413 if (--(*blp
)->refc
== 0)
6414 free_bp_location (*blp
);
6418 /* Add breakpoint B at the end of the global breakpoint chain. */
6421 add_to_breakpoint_chain (struct breakpoint
*b
)
6423 struct breakpoint
*b1
;
6425 /* Add this breakpoint to the end of the chain so that a list of
6426 breakpoints will come out in order of increasing numbers. */
6428 b1
= breakpoint_chain
;
6430 breakpoint_chain
= b
;
6439 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6442 init_raw_breakpoint_without_location (struct breakpoint
*b
,
6443 struct gdbarch
*gdbarch
,
6445 const struct breakpoint_ops
*ops
)
6447 memset (b
, 0, sizeof (*b
));
6449 gdb_assert (ops
!= NULL
);
6453 b
->gdbarch
= gdbarch
;
6454 b
->language
= current_language
->la_language
;
6455 b
->input_radix
= input_radix
;
6457 b
->enable_state
= bp_enabled
;
6460 b
->ignore_count
= 0;
6462 b
->frame_id
= null_frame_id
;
6463 b
->condition_not_parsed
= 0;
6464 b
->py_bp_object
= NULL
;
6465 b
->related_breakpoint
= b
;
6468 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6469 that has type BPTYPE and has no locations as yet. */
6471 static struct breakpoint
*
6472 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
6474 const struct breakpoint_ops
*ops
)
6476 struct breakpoint
*b
= XNEW (struct breakpoint
);
6478 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6479 add_to_breakpoint_chain (b
);
6483 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6484 resolutions should be made as the user specified the location explicitly
6488 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
6490 gdb_assert (loc
->owner
!= NULL
);
6492 if (loc
->owner
->type
== bp_breakpoint
6493 || loc
->owner
->type
== bp_hardware_breakpoint
6494 || is_tracepoint (loc
->owner
))
6497 const char *function_name
;
6499 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
6500 NULL
, NULL
, &is_gnu_ifunc
);
6502 if (is_gnu_ifunc
&& !explicit_loc
)
6504 struct breakpoint
*b
= loc
->owner
;
6506 gdb_assert (loc
->pspace
== current_program_space
);
6507 if (gnu_ifunc_resolve_name (function_name
,
6508 &loc
->requested_address
))
6510 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6511 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6512 loc
->requested_address
,
6515 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
6516 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
6518 /* Create only the whole new breakpoint of this type but do not
6519 mess more complicated breakpoints with multiple locations. */
6520 b
->type
= bp_gnu_ifunc_resolver
;
6525 loc
->function_name
= xstrdup (function_name
);
6529 /* Attempt to determine architecture of location identified by SAL. */
6531 get_sal_arch (struct symtab_and_line sal
)
6534 return get_objfile_arch (sal
.section
->objfile
);
6536 return get_objfile_arch (sal
.symtab
->objfile
);
6541 /* Low level routine for partially initializing a breakpoint of type
6542 BPTYPE. The newly created breakpoint's address, section, source
6543 file name, and line number are provided by SAL.
6545 It is expected that the caller will complete the initialization of
6546 the newly created breakpoint struct as well as output any status
6547 information regarding the creation of a new breakpoint. */
6550 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
6551 struct symtab_and_line sal
, enum bptype bptype
,
6552 const struct breakpoint_ops
*ops
)
6554 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6556 add_location_to_breakpoint (b
, &sal
);
6558 if (bptype
!= bp_catchpoint
)
6559 gdb_assert (sal
.pspace
!= NULL
);
6561 /* Store the program space that was used to set the breakpoint,
6562 except for ordinary breakpoints, which are independent of the
6564 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
6565 b
->pspace
= sal
.pspace
;
6567 breakpoints_changed ();
6570 /* set_raw_breakpoint is a low level routine for allocating and
6571 partially initializing a breakpoint of type BPTYPE. The newly
6572 created breakpoint's address, section, source file name, and line
6573 number are provided by SAL. The newly created and partially
6574 initialized breakpoint is added to the breakpoint chain and
6575 is also returned as the value of this function.
6577 It is expected that the caller will complete the initialization of
6578 the newly created breakpoint struct as well as output any status
6579 information regarding the creation of a new breakpoint. In
6580 particular, set_raw_breakpoint does NOT set the breakpoint
6581 number! Care should be taken to not allow an error to occur
6582 prior to completing the initialization of the breakpoint. If this
6583 should happen, a bogus breakpoint will be left on the chain. */
6586 set_raw_breakpoint (struct gdbarch
*gdbarch
,
6587 struct symtab_and_line sal
, enum bptype bptype
,
6588 const struct breakpoint_ops
*ops
)
6590 struct breakpoint
*b
= XNEW (struct breakpoint
);
6592 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
6593 add_to_breakpoint_chain (b
);
6598 /* Note that the breakpoint object B describes a permanent breakpoint
6599 instruction, hard-wired into the inferior's code. */
6601 make_breakpoint_permanent (struct breakpoint
*b
)
6603 struct bp_location
*bl
;
6605 b
->enable_state
= bp_permanent
;
6607 /* By definition, permanent breakpoints are already present in the
6608 code. Mark all locations as inserted. For now,
6609 make_breakpoint_permanent is called in just one place, so it's
6610 hard to say if it's reasonable to have permanent breakpoint with
6611 multiple locations or not, but it's easy to implement. */
6612 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6616 /* Call this routine when stepping and nexting to enable a breakpoint
6617 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6618 initiated the operation. */
6621 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
6623 struct breakpoint
*b
, *b_tmp
;
6624 int thread
= tp
->num
;
6626 /* To avoid having to rescan all objfile symbols at every step,
6627 we maintain a list of continually-inserted but always disabled
6628 longjmp "master" breakpoints. Here, we simply create momentary
6629 clones of those and enable them for the requested thread. */
6630 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6631 if (b
->pspace
== current_program_space
6632 && (b
->type
== bp_longjmp_master
6633 || b
->type
== bp_exception_master
))
6635 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
6636 struct breakpoint
*clone
;
6638 clone
= momentary_breakpoint_from_master (b
, type
,
6639 &momentary_breakpoint_ops
);
6640 clone
->thread
= thread
;
6643 tp
->initiating_frame
= frame
;
6646 /* Delete all longjmp breakpoints from THREAD. */
6648 delete_longjmp_breakpoint (int thread
)
6650 struct breakpoint
*b
, *b_tmp
;
6652 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6653 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6655 if (b
->thread
== thread
)
6656 delete_breakpoint (b
);
6661 delete_longjmp_breakpoint_at_next_stop (int thread
)
6663 struct breakpoint
*b
, *b_tmp
;
6665 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6666 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6668 if (b
->thread
== thread
)
6669 b
->disposition
= disp_del_at_next_stop
;
6674 enable_overlay_breakpoints (void)
6676 struct breakpoint
*b
;
6679 if (b
->type
== bp_overlay_event
)
6681 b
->enable_state
= bp_enabled
;
6682 update_global_location_list (1);
6683 overlay_events_enabled
= 1;
6688 disable_overlay_breakpoints (void)
6690 struct breakpoint
*b
;
6693 if (b
->type
== bp_overlay_event
)
6695 b
->enable_state
= bp_disabled
;
6696 update_global_location_list (0);
6697 overlay_events_enabled
= 0;
6701 /* Set an active std::terminate breakpoint for each std::terminate
6702 master breakpoint. */
6704 set_std_terminate_breakpoint (void)
6706 struct breakpoint
*b
, *b_tmp
;
6708 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6709 if (b
->pspace
== current_program_space
6710 && b
->type
== bp_std_terminate_master
)
6712 momentary_breakpoint_from_master (b
, bp_std_terminate
,
6713 &momentary_breakpoint_ops
);
6717 /* Delete all the std::terminate breakpoints. */
6719 delete_std_terminate_breakpoint (void)
6721 struct breakpoint
*b
, *b_tmp
;
6723 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6724 if (b
->type
== bp_std_terminate
)
6725 delete_breakpoint (b
);
6729 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6731 struct breakpoint
*b
;
6733 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
6734 &internal_breakpoint_ops
);
6736 b
->enable_state
= bp_enabled
;
6737 /* addr_string has to be used or breakpoint_re_set will delete me. */
6739 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6741 update_global_location_list_nothrow (1);
6747 remove_thread_event_breakpoints (void)
6749 struct breakpoint
*b
, *b_tmp
;
6751 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6752 if (b
->type
== bp_thread_event
6753 && b
->loc
->pspace
== current_program_space
)
6754 delete_breakpoint (b
);
6757 struct lang_and_radix
6763 /* Create a breakpoint for JIT code registration and unregistration. */
6766 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6768 struct breakpoint
*b
;
6770 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6771 &internal_breakpoint_ops
);
6772 update_global_location_list_nothrow (1);
6776 /* Remove JIT code registration and unregistration breakpoint(s). */
6779 remove_jit_event_breakpoints (void)
6781 struct breakpoint
*b
, *b_tmp
;
6783 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6784 if (b
->type
== bp_jit_event
6785 && b
->loc
->pspace
== current_program_space
)
6786 delete_breakpoint (b
);
6790 remove_solib_event_breakpoints (void)
6792 struct breakpoint
*b
, *b_tmp
;
6794 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6795 if (b
->type
== bp_shlib_event
6796 && b
->loc
->pspace
== current_program_space
)
6797 delete_breakpoint (b
);
6801 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6803 struct breakpoint
*b
;
6805 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6806 &internal_breakpoint_ops
);
6807 update_global_location_list_nothrow (1);
6811 /* Disable any breakpoints that are on code in shared libraries. Only
6812 apply to enabled breakpoints, disabled ones can just stay disabled. */
6815 disable_breakpoints_in_shlibs (void)
6817 struct bp_location
*loc
, **locp_tmp
;
6819 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6821 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6822 struct breakpoint
*b
= loc
->owner
;
6824 /* We apply the check to all breakpoints, including disabled for
6825 those with loc->duplicate set. This is so that when breakpoint
6826 becomes enabled, or the duplicate is removed, gdb will try to
6827 insert all breakpoints. If we don't set shlib_disabled here,
6828 we'll try to insert those breakpoints and fail. */
6829 if (((b
->type
== bp_breakpoint
)
6830 || (b
->type
== bp_jit_event
)
6831 || (b
->type
== bp_hardware_breakpoint
)
6832 || (is_tracepoint (b
)))
6833 && loc
->pspace
== current_program_space
6834 && !loc
->shlib_disabled
6836 && PC_SOLIB (loc
->address
)
6838 && solib_name_from_address (loc
->pspace
, loc
->address
)
6842 loc
->shlib_disabled
= 1;
6847 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6848 library. Only apply to enabled breakpoints, disabled ones can just stay
6852 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6854 struct bp_location
*loc
, **locp_tmp
;
6855 int disabled_shlib_breaks
= 0;
6857 /* SunOS a.out shared libraries are always mapped, so do not
6858 disable breakpoints; they will only be reported as unloaded
6859 through clear_solib when GDB discards its shared library
6860 list. See clear_solib for more information. */
6861 if (exec_bfd
!= NULL
6862 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6865 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6867 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6868 struct breakpoint
*b
= loc
->owner
;
6870 if (solib
->pspace
== loc
->pspace
6871 && !loc
->shlib_disabled
6872 && (((b
->type
== bp_breakpoint
6873 || b
->type
== bp_jit_event
6874 || b
->type
== bp_hardware_breakpoint
)
6875 && (loc
->loc_type
== bp_loc_hardware_breakpoint
6876 || loc
->loc_type
== bp_loc_software_breakpoint
))
6877 || is_tracepoint (b
))
6878 && solib_contains_address_p (solib
, loc
->address
))
6880 loc
->shlib_disabled
= 1;
6881 /* At this point, we cannot rely on remove_breakpoint
6882 succeeding so we must mark the breakpoint as not inserted
6883 to prevent future errors occurring in remove_breakpoints. */
6886 /* This may cause duplicate notifications for the same breakpoint. */
6887 observer_notify_breakpoint_modified (b
);
6889 if (!disabled_shlib_breaks
)
6891 target_terminal_ours_for_output ();
6892 warning (_("Temporarily disabling breakpoints "
6893 "for unloaded shared library \"%s\""),
6896 disabled_shlib_breaks
= 1;
6901 /* FORK & VFORK catchpoints. */
6903 /* An instance of this type is used to represent a fork or vfork
6904 catchpoint. It includes a "struct breakpoint" as a kind of base
6905 class; users downcast to "struct breakpoint *" when needed. A
6906 breakpoint is really of this type iff its ops pointer points to
6907 CATCH_FORK_BREAKPOINT_OPS. */
6909 struct fork_catchpoint
6911 /* The base class. */
6912 struct breakpoint base
;
6914 /* Process id of a child process whose forking triggered this
6915 catchpoint. This field is only valid immediately after this
6916 catchpoint has triggered. */
6917 ptid_t forked_inferior_pid
;
6920 /* Implement the "insert" breakpoint_ops method for fork
6924 insert_catch_fork (struct bp_location
*bl
)
6926 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6929 /* Implement the "remove" breakpoint_ops method for fork
6933 remove_catch_fork (struct bp_location
*bl
)
6935 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6938 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6942 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6943 struct address_space
*aspace
, CORE_ADDR bp_addr
,
6944 const struct target_waitstatus
*ws
)
6946 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6948 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
6951 c
->forked_inferior_pid
= ws
->value
.related_pid
;
6955 /* Implement the "print_it" breakpoint_ops method for fork
6958 static enum print_stop_action
6959 print_it_catch_fork (bpstat bs
)
6961 struct ui_out
*uiout
= current_uiout
;
6962 struct breakpoint
*b
= bs
->breakpoint_at
;
6963 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6965 annotate_catchpoint (b
->number
);
6966 if (b
->disposition
== disp_del
)
6967 ui_out_text (uiout
, "\nTemporary catchpoint ");
6969 ui_out_text (uiout
, "\nCatchpoint ");
6970 if (ui_out_is_mi_like_p (uiout
))
6972 ui_out_field_string (uiout
, "reason",
6973 async_reason_lookup (EXEC_ASYNC_FORK
));
6974 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6976 ui_out_field_int (uiout
, "bkptno", b
->number
);
6977 ui_out_text (uiout
, " (forked process ");
6978 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6979 ui_out_text (uiout
, "), ");
6980 return PRINT_SRC_AND_LOC
;
6983 /* Implement the "print_one" breakpoint_ops method for fork
6987 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6989 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6990 struct value_print_options opts
;
6991 struct ui_out
*uiout
= current_uiout
;
6993 get_user_print_options (&opts
);
6995 /* Field 4, the address, is omitted (which makes the columns not
6996 line up too nicely with the headers, but the effect is relatively
6998 if (opts
.addressprint
)
6999 ui_out_field_skip (uiout
, "addr");
7001 ui_out_text (uiout
, "fork");
7002 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7004 ui_out_text (uiout
, ", process ");
7005 ui_out_field_int (uiout
, "what",
7006 ptid_get_pid (c
->forked_inferior_pid
));
7007 ui_out_spaces (uiout
, 1);
7011 /* Implement the "print_mention" breakpoint_ops method for fork
7015 print_mention_catch_fork (struct breakpoint
*b
)
7017 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7020 /* Implement the "print_recreate" breakpoint_ops method for fork
7024 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7026 fprintf_unfiltered (fp
, "catch fork");
7027 print_recreate_thread (b
, fp
);
7030 /* The breakpoint_ops structure to be used in fork catchpoints. */
7032 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7034 /* Implement the "insert" breakpoint_ops method for vfork
7038 insert_catch_vfork (struct bp_location
*bl
)
7040 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
7043 /* Implement the "remove" breakpoint_ops method for vfork
7047 remove_catch_vfork (struct bp_location
*bl
)
7049 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
7052 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7056 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7057 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7058 const struct target_waitstatus
*ws
)
7060 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7062 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7065 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7069 /* Implement the "print_it" breakpoint_ops method for vfork
7072 static enum print_stop_action
7073 print_it_catch_vfork (bpstat bs
)
7075 struct ui_out
*uiout
= current_uiout
;
7076 struct breakpoint
*b
= bs
->breakpoint_at
;
7077 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7079 annotate_catchpoint (b
->number
);
7080 if (b
->disposition
== disp_del
)
7081 ui_out_text (uiout
, "\nTemporary catchpoint ");
7083 ui_out_text (uiout
, "\nCatchpoint ");
7084 if (ui_out_is_mi_like_p (uiout
))
7086 ui_out_field_string (uiout
, "reason",
7087 async_reason_lookup (EXEC_ASYNC_VFORK
));
7088 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7090 ui_out_field_int (uiout
, "bkptno", b
->number
);
7091 ui_out_text (uiout
, " (vforked process ");
7092 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7093 ui_out_text (uiout
, "), ");
7094 return PRINT_SRC_AND_LOC
;
7097 /* Implement the "print_one" breakpoint_ops method for vfork
7101 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7103 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7104 struct value_print_options opts
;
7105 struct ui_out
*uiout
= current_uiout
;
7107 get_user_print_options (&opts
);
7108 /* Field 4, the address, is omitted (which makes the columns not
7109 line up too nicely with the headers, but the effect is relatively
7111 if (opts
.addressprint
)
7112 ui_out_field_skip (uiout
, "addr");
7114 ui_out_text (uiout
, "vfork");
7115 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7117 ui_out_text (uiout
, ", process ");
7118 ui_out_field_int (uiout
, "what",
7119 ptid_get_pid (c
->forked_inferior_pid
));
7120 ui_out_spaces (uiout
, 1);
7124 /* Implement the "print_mention" breakpoint_ops method for vfork
7128 print_mention_catch_vfork (struct breakpoint
*b
)
7130 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7133 /* Implement the "print_recreate" breakpoint_ops method for vfork
7137 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7139 fprintf_unfiltered (fp
, "catch vfork");
7140 print_recreate_thread (b
, fp
);
7143 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7145 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7147 /* An instance of this type is used to represent an solib catchpoint.
7148 It includes a "struct breakpoint" as a kind of base class; users
7149 downcast to "struct breakpoint *" when needed. A breakpoint is
7150 really of this type iff its ops pointer points to
7151 CATCH_SOLIB_BREAKPOINT_OPS. */
7153 struct solib_catchpoint
7155 /* The base class. */
7156 struct breakpoint base
;
7158 /* True for "catch load", false for "catch unload". */
7159 unsigned char is_load
;
7161 /* Regular expression to match, if any. COMPILED is only valid when
7162 REGEX is non-NULL. */
7168 dtor_catch_solib (struct breakpoint
*b
)
7170 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7173 regfree (&self
->compiled
);
7174 xfree (self
->regex
);
7176 base_breakpoint_ops
.dtor (b
);
7180 insert_catch_solib (struct bp_location
*ignore
)
7186 remove_catch_solib (struct bp_location
*ignore
)
7192 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7193 struct address_space
*aspace
,
7195 const struct target_waitstatus
*ws
)
7197 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7198 struct breakpoint
*other
;
7200 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7203 ALL_BREAKPOINTS (other
)
7205 struct bp_location
*other_bl
;
7207 if (other
== bl
->owner
)
7210 if (other
->type
!= bp_shlib_event
)
7213 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7216 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7218 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7227 check_status_catch_solib (struct bpstats
*bs
)
7229 struct solib_catchpoint
*self
7230 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7235 struct so_list
*iter
;
7238 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
7243 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
7252 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
7257 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
7263 bs
->print_it
= print_it_noop
;
7266 static enum print_stop_action
7267 print_it_catch_solib (bpstat bs
)
7269 struct breakpoint
*b
= bs
->breakpoint_at
;
7270 struct ui_out
*uiout
= current_uiout
;
7272 annotate_catchpoint (b
->number
);
7273 if (b
->disposition
== disp_del
)
7274 ui_out_text (uiout
, "\nTemporary catchpoint ");
7276 ui_out_text (uiout
, "\nCatchpoint ");
7277 ui_out_field_int (uiout
, "bkptno", b
->number
);
7278 ui_out_text (uiout
, "\n");
7279 if (ui_out_is_mi_like_p (uiout
))
7280 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7281 print_solib_event (1);
7282 return PRINT_SRC_AND_LOC
;
7286 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7288 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7289 struct value_print_options opts
;
7290 struct ui_out
*uiout
= current_uiout
;
7293 get_user_print_options (&opts
);
7294 /* Field 4, the address, is omitted (which makes the columns not
7295 line up too nicely with the headers, but the effect is relatively
7297 if (opts
.addressprint
)
7300 ui_out_field_skip (uiout
, "addr");
7307 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
7309 msg
= xstrdup (_("load of library"));
7314 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
7316 msg
= xstrdup (_("unload of library"));
7318 ui_out_field_string (uiout
, "what", msg
);
7323 print_mention_catch_solib (struct breakpoint
*b
)
7325 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7327 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
7328 self
->is_load
? "load" : "unload");
7332 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
7334 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7336 fprintf_unfiltered (fp
, "%s %s",
7337 b
->disposition
== disp_del
? "tcatch" : "catch",
7338 self
->is_load
? "load" : "unload");
7340 fprintf_unfiltered (fp
, " %s", self
->regex
);
7341 fprintf_unfiltered (fp
, "\n");
7344 static struct breakpoint_ops catch_solib_breakpoint_ops
;
7346 /* A helper function that does all the work for "catch load" and
7350 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
7351 struct cmd_list_element
*command
)
7353 struct solib_catchpoint
*c
;
7354 struct gdbarch
*gdbarch
= get_current_arch ();
7357 struct cleanup
*cleanup
;
7359 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7363 arg
= skip_spaces (arg
);
7365 c
= XCNEW (struct solib_catchpoint
);
7366 cleanup
= make_cleanup (xfree
, c
);
7372 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
7375 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
7377 make_cleanup (xfree
, err
);
7378 error (_("Invalid regexp (%s): %s"), err
, arg
);
7380 c
->regex
= xstrdup (arg
);
7383 c
->is_load
= is_load
;
7384 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
,
7385 &catch_solib_breakpoint_ops
);
7387 discard_cleanups (cleanup
);
7388 install_breakpoint (0, &c
->base
, 1);
7392 catch_load_command_1 (char *arg
, int from_tty
,
7393 struct cmd_list_element
*command
)
7395 catch_load_or_unload (arg
, from_tty
, 1, command
);
7399 catch_unload_command_1 (char *arg
, int from_tty
,
7400 struct cmd_list_element
*command
)
7402 catch_load_or_unload (arg
, from_tty
, 0, command
);
7407 /* An instance of this type is used to represent a syscall catchpoint.
7408 It includes a "struct breakpoint" as a kind of base class; users
7409 downcast to "struct breakpoint *" when needed. A breakpoint is
7410 really of this type iff its ops pointer points to
7411 CATCH_SYSCALL_BREAKPOINT_OPS. */
7413 struct syscall_catchpoint
7415 /* The base class. */
7416 struct breakpoint base
;
7418 /* Syscall numbers used for the 'catch syscall' feature. If no
7419 syscall has been specified for filtering, its value is NULL.
7420 Otherwise, it holds a list of all syscalls to be caught. The
7421 list elements are allocated with xmalloc. */
7422 VEC(int) *syscalls_to_be_caught
;
7425 /* Implement the "dtor" breakpoint_ops method for syscall
7429 dtor_catch_syscall (struct breakpoint
*b
)
7431 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7433 VEC_free (int, c
->syscalls_to_be_caught
);
7435 base_breakpoint_ops
.dtor (b
);
7438 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
7440 struct catch_syscall_inferior_data
7442 /* We keep a count of the number of times the user has requested a
7443 particular syscall to be tracked, and pass this information to the
7444 target. This lets capable targets implement filtering directly. */
7446 /* Number of times that "any" syscall is requested. */
7447 int any_syscall_count
;
7449 /* Count of each system call. */
7450 VEC(int) *syscalls_counts
;
7452 /* This counts all syscall catch requests, so we can readily determine
7453 if any catching is necessary. */
7454 int total_syscalls_count
;
7457 static struct catch_syscall_inferior_data
*
7458 get_catch_syscall_inferior_data (struct inferior
*inf
)
7460 struct catch_syscall_inferior_data
*inf_data
;
7462 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
7463 if (inf_data
== NULL
)
7465 inf_data
= XZALLOC (struct catch_syscall_inferior_data
);
7466 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
7473 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
7479 /* Implement the "insert" breakpoint_ops method for syscall
7483 insert_catch_syscall (struct bp_location
*bl
)
7485 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7486 struct inferior
*inf
= current_inferior ();
7487 struct catch_syscall_inferior_data
*inf_data
7488 = get_catch_syscall_inferior_data (inf
);
7490 ++inf_data
->total_syscalls_count
;
7491 if (!c
->syscalls_to_be_caught
)
7492 ++inf_data
->any_syscall_count
;
7498 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7503 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
7505 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
7506 uintptr_t vec_addr_offset
7507 = old_size
* ((uintptr_t) sizeof (int));
7509 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
7510 vec_addr
= ((uintptr_t) VEC_address (int,
7511 inf_data
->syscalls_counts
)
7513 memset ((void *) vec_addr
, 0,
7514 (iter
+ 1 - old_size
) * sizeof (int));
7516 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
7517 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
7521 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7522 inf_data
->total_syscalls_count
!= 0,
7523 inf_data
->any_syscall_count
,
7525 inf_data
->syscalls_counts
),
7527 inf_data
->syscalls_counts
));
7530 /* Implement the "remove" breakpoint_ops method for syscall
7534 remove_catch_syscall (struct bp_location
*bl
)
7536 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7537 struct inferior
*inf
= current_inferior ();
7538 struct catch_syscall_inferior_data
*inf_data
7539 = get_catch_syscall_inferior_data (inf
);
7541 --inf_data
->total_syscalls_count
;
7542 if (!c
->syscalls_to_be_caught
)
7543 --inf_data
->any_syscall_count
;
7549 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7553 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
7554 /* Shouldn't happen. */
7556 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
7557 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
7561 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7562 inf_data
->total_syscalls_count
!= 0,
7563 inf_data
->any_syscall_count
,
7565 inf_data
->syscalls_counts
),
7567 inf_data
->syscalls_counts
));
7570 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7574 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
7575 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7576 const struct target_waitstatus
*ws
)
7578 /* We must check if we are catching specific syscalls in this
7579 breakpoint. If we are, then we must guarantee that the called
7580 syscall is the same syscall we are catching. */
7581 int syscall_number
= 0;
7582 const struct syscall_catchpoint
*c
7583 = (const struct syscall_catchpoint
*) bl
->owner
;
7585 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
7586 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
7589 syscall_number
= ws
->value
.syscall_number
;
7591 /* Now, checking if the syscall is the same. */
7592 if (c
->syscalls_to_be_caught
)
7597 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7599 if (syscall_number
== iter
)
7609 /* Implement the "print_it" breakpoint_ops method for syscall
7612 static enum print_stop_action
7613 print_it_catch_syscall (bpstat bs
)
7615 struct ui_out
*uiout
= current_uiout
;
7616 struct breakpoint
*b
= bs
->breakpoint_at
;
7617 /* These are needed because we want to know in which state a
7618 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7619 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7620 must print "called syscall" or "returned from syscall". */
7622 struct target_waitstatus last
;
7626 get_last_target_status (&ptid
, &last
);
7628 get_syscall_by_number (last
.value
.syscall_number
, &s
);
7630 annotate_catchpoint (b
->number
);
7632 if (b
->disposition
== disp_del
)
7633 ui_out_text (uiout
, "\nTemporary catchpoint ");
7635 ui_out_text (uiout
, "\nCatchpoint ");
7636 if (ui_out_is_mi_like_p (uiout
))
7638 ui_out_field_string (uiout
, "reason",
7639 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
7640 ? EXEC_ASYNC_SYSCALL_ENTRY
7641 : EXEC_ASYNC_SYSCALL_RETURN
));
7642 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7644 ui_out_field_int (uiout
, "bkptno", b
->number
);
7646 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
7647 ui_out_text (uiout
, " (call to syscall ");
7649 ui_out_text (uiout
, " (returned from syscall ");
7651 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
7652 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
7654 ui_out_field_string (uiout
, "syscall-name", s
.name
);
7656 ui_out_text (uiout
, "), ");
7658 return PRINT_SRC_AND_LOC
;
7661 /* Implement the "print_one" breakpoint_ops method for syscall
7665 print_one_catch_syscall (struct breakpoint
*b
,
7666 struct bp_location
**last_loc
)
7668 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7669 struct value_print_options opts
;
7670 struct ui_out
*uiout
= current_uiout
;
7672 get_user_print_options (&opts
);
7673 /* Field 4, the address, is omitted (which makes the columns not
7674 line up too nicely with the headers, but the effect is relatively
7676 if (opts
.addressprint
)
7677 ui_out_field_skip (uiout
, "addr");
7680 if (c
->syscalls_to_be_caught
7681 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7682 ui_out_text (uiout
, "syscalls \"");
7684 ui_out_text (uiout
, "syscall \"");
7686 if (c
->syscalls_to_be_caught
)
7689 char *text
= xstrprintf ("%s", "");
7692 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7697 get_syscall_by_number (iter
, &s
);
7700 text
= xstrprintf ("%s%s, ", text
, s
.name
);
7702 text
= xstrprintf ("%s%d, ", text
, iter
);
7704 /* We have to xfree the last 'text' (now stored at 'x')
7705 because xstrprintf dynamically allocates new space for it
7709 /* Remove the last comma. */
7710 text
[strlen (text
) - 2] = '\0';
7711 ui_out_field_string (uiout
, "what", text
);
7714 ui_out_field_string (uiout
, "what", "<any syscall>");
7715 ui_out_text (uiout
, "\" ");
7718 /* Implement the "print_mention" breakpoint_ops method for syscall
7722 print_mention_catch_syscall (struct breakpoint
*b
)
7724 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7726 if (c
->syscalls_to_be_caught
)
7730 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7731 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
7733 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
7736 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7740 get_syscall_by_number (iter
, &s
);
7743 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
7745 printf_filtered (" %d", s
.number
);
7747 printf_filtered (")");
7750 printf_filtered (_("Catchpoint %d (any syscall)"),
7754 /* Implement the "print_recreate" breakpoint_ops method for syscall
7758 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
7760 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7762 fprintf_unfiltered (fp
, "catch syscall");
7764 if (c
->syscalls_to_be_caught
)
7769 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7774 get_syscall_by_number (iter
, &s
);
7776 fprintf_unfiltered (fp
, " %s", s
.name
);
7778 fprintf_unfiltered (fp
, " %d", s
.number
);
7781 print_recreate_thread (b
, fp
);
7784 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7786 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
7788 /* Returns non-zero if 'b' is a syscall catchpoint. */
7791 syscall_catchpoint_p (struct breakpoint
*b
)
7793 return (b
->ops
== &catch_syscall_breakpoint_ops
);
7796 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7797 is non-zero, then make the breakpoint temporary. If COND_STRING is
7798 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7799 the breakpoint_ops structure associated to the catchpoint. */
7802 init_catchpoint (struct breakpoint
*b
,
7803 struct gdbarch
*gdbarch
, int tempflag
,
7805 const struct breakpoint_ops
*ops
)
7807 struct symtab_and_line sal
;
7810 sal
.pspace
= current_program_space
;
7812 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
7814 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
7815 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7819 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
7821 add_to_breakpoint_chain (b
);
7822 set_breakpoint_number (internal
, b
);
7825 observer_notify_breakpoint_created (b
);
7828 update_global_location_list (1);
7832 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
7833 int tempflag
, char *cond_string
,
7834 const struct breakpoint_ops
*ops
)
7836 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
7838 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
7840 c
->forked_inferior_pid
= null_ptid
;
7842 install_breakpoint (0, &c
->base
, 1);
7845 /* Exec catchpoints. */
7847 /* An instance of this type is used to represent an exec catchpoint.
7848 It includes a "struct breakpoint" as a kind of base class; users
7849 downcast to "struct breakpoint *" when needed. A breakpoint is
7850 really of this type iff its ops pointer points to
7851 CATCH_EXEC_BREAKPOINT_OPS. */
7853 struct exec_catchpoint
7855 /* The base class. */
7856 struct breakpoint base
;
7858 /* Filename of a program whose exec triggered this catchpoint.
7859 This field is only valid immediately after this catchpoint has
7861 char *exec_pathname
;
7864 /* Implement the "dtor" breakpoint_ops method for exec
7868 dtor_catch_exec (struct breakpoint
*b
)
7870 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
7872 xfree (c
->exec_pathname
);
7874 base_breakpoint_ops
.dtor (b
);
7878 insert_catch_exec (struct bp_location
*bl
)
7880 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
7884 remove_catch_exec (struct bp_location
*bl
)
7886 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
7890 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
7891 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7892 const struct target_waitstatus
*ws
)
7894 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
7896 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
7899 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
7903 static enum print_stop_action
7904 print_it_catch_exec (bpstat bs
)
7906 struct ui_out
*uiout
= current_uiout
;
7907 struct breakpoint
*b
= bs
->breakpoint_at
;
7908 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
7910 annotate_catchpoint (b
->number
);
7911 if (b
->disposition
== disp_del
)
7912 ui_out_text (uiout
, "\nTemporary catchpoint ");
7914 ui_out_text (uiout
, "\nCatchpoint ");
7915 if (ui_out_is_mi_like_p (uiout
))
7917 ui_out_field_string (uiout
, "reason",
7918 async_reason_lookup (EXEC_ASYNC_EXEC
));
7919 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7921 ui_out_field_int (uiout
, "bkptno", b
->number
);
7922 ui_out_text (uiout
, " (exec'd ");
7923 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
7924 ui_out_text (uiout
, "), ");
7926 return PRINT_SRC_AND_LOC
;
7930 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
7932 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
7933 struct value_print_options opts
;
7934 struct ui_out
*uiout
= current_uiout
;
7936 get_user_print_options (&opts
);
7938 /* Field 4, the address, is omitted (which makes the columns
7939 not line up too nicely with the headers, but the effect
7940 is relatively readable). */
7941 if (opts
.addressprint
)
7942 ui_out_field_skip (uiout
, "addr");
7944 ui_out_text (uiout
, "exec");
7945 if (c
->exec_pathname
!= NULL
)
7947 ui_out_text (uiout
, ", program \"");
7948 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
7949 ui_out_text (uiout
, "\" ");
7954 print_mention_catch_exec (struct breakpoint
*b
)
7956 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
7959 /* Implement the "print_recreate" breakpoint_ops method for exec
7963 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
7965 fprintf_unfiltered (fp
, "catch exec");
7966 print_recreate_thread (b
, fp
);
7969 static struct breakpoint_ops catch_exec_breakpoint_ops
;
7972 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
7973 const struct breakpoint_ops
*ops
)
7975 struct syscall_catchpoint
*c
;
7976 struct gdbarch
*gdbarch
= get_current_arch ();
7978 c
= XNEW (struct syscall_catchpoint
);
7979 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
7980 c
->syscalls_to_be_caught
= filter
;
7982 install_breakpoint (0, &c
->base
, 1);
7986 hw_breakpoint_used_count (void)
7989 struct breakpoint
*b
;
7990 struct bp_location
*bl
;
7994 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
7995 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7997 /* Special types of hardware breakpoints may use more than
7999 i
+= b
->ops
->resources_needed (bl
);
8006 /* Returns the resources B would use if it were a hardware
8010 hw_watchpoint_use_count (struct breakpoint
*b
)
8013 struct bp_location
*bl
;
8015 if (!breakpoint_enabled (b
))
8018 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8020 /* Special types of hardware watchpoints may use more than
8022 i
+= b
->ops
->resources_needed (bl
);
8028 /* Returns the sum the used resources of all hardware watchpoints of
8029 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8030 the sum of the used resources of all hardware watchpoints of other
8031 types _not_ TYPE. */
8034 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8035 enum bptype type
, int *other_type_used
)
8038 struct breakpoint
*b
;
8040 *other_type_used
= 0;
8045 if (!breakpoint_enabled (b
))
8048 if (b
->type
== type
)
8049 i
+= hw_watchpoint_use_count (b
);
8050 else if (is_hardware_watchpoint (b
))
8051 *other_type_used
= 1;
8058 disable_watchpoints_before_interactive_call_start (void)
8060 struct breakpoint
*b
;
8064 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8066 b
->enable_state
= bp_call_disabled
;
8067 update_global_location_list (0);
8073 enable_watchpoints_after_interactive_call_stop (void)
8075 struct breakpoint
*b
;
8079 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8081 b
->enable_state
= bp_enabled
;
8082 update_global_location_list (1);
8088 disable_breakpoints_before_startup (void)
8090 current_program_space
->executing_startup
= 1;
8091 update_global_location_list (0);
8095 enable_breakpoints_after_startup (void)
8097 current_program_space
->executing_startup
= 0;
8098 breakpoint_re_set ();
8102 /* Set a breakpoint that will evaporate an end of command
8103 at address specified by SAL.
8104 Restrict it to frame FRAME if FRAME is nonzero. */
8107 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8108 struct frame_id frame_id
, enum bptype type
)
8110 struct breakpoint
*b
;
8112 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8114 gdb_assert (!frame_id_inlined_p (frame_id
));
8116 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8117 b
->enable_state
= bp_enabled
;
8118 b
->disposition
= disp_donttouch
;
8119 b
->frame_id
= frame_id
;
8121 /* If we're debugging a multi-threaded program, then we want
8122 momentary breakpoints to be active in only a single thread of
8124 if (in_thread_list (inferior_ptid
))
8125 b
->thread
= pid_to_thread_id (inferior_ptid
);
8127 update_global_location_list_nothrow (1);
8132 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8133 The new breakpoint will have type TYPE, and use OPS as it
8136 static struct breakpoint
*
8137 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8139 const struct breakpoint_ops
*ops
)
8141 struct breakpoint
*copy
;
8143 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8144 copy
->loc
= allocate_bp_location (copy
);
8145 set_breakpoint_location_function (copy
->loc
, 1);
8147 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8148 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8149 copy
->loc
->address
= orig
->loc
->address
;
8150 copy
->loc
->section
= orig
->loc
->section
;
8151 copy
->loc
->pspace
= orig
->loc
->pspace
;
8153 if (orig
->loc
->source_file
!= NULL
)
8154 copy
->loc
->source_file
= xstrdup (orig
->loc
->source_file
);
8156 copy
->loc
->line_number
= orig
->loc
->line_number
;
8157 copy
->frame_id
= orig
->frame_id
;
8158 copy
->thread
= orig
->thread
;
8159 copy
->pspace
= orig
->pspace
;
8161 copy
->enable_state
= bp_enabled
;
8162 copy
->disposition
= disp_donttouch
;
8163 copy
->number
= internal_breakpoint_number
--;
8165 update_global_location_list_nothrow (0);
8169 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8173 clone_momentary_breakpoint (struct breakpoint
*orig
)
8175 /* If there's nothing to clone, then return nothing. */
8179 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8183 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8186 struct symtab_and_line sal
;
8188 sal
= find_pc_line (pc
, 0);
8190 sal
.section
= find_pc_overlay (pc
);
8191 sal
.explicit_pc
= 1;
8193 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8197 /* Tell the user we have just set a breakpoint B. */
8200 mention (struct breakpoint
*b
)
8202 b
->ops
->print_mention (b
);
8203 if (ui_out_is_mi_like_p (current_uiout
))
8205 printf_filtered ("\n");
8209 static struct bp_location
*
8210 add_location_to_breakpoint (struct breakpoint
*b
,
8211 const struct symtab_and_line
*sal
)
8213 struct bp_location
*loc
, **tmp
;
8214 CORE_ADDR adjusted_address
;
8215 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8217 if (loc_gdbarch
== NULL
)
8218 loc_gdbarch
= b
->gdbarch
;
8220 /* Adjust the breakpoint's address prior to allocating a location.
8221 Once we call allocate_bp_location(), that mostly uninitialized
8222 location will be placed on the location chain. Adjustment of the
8223 breakpoint may cause target_read_memory() to be called and we do
8224 not want its scan of the location chain to find a breakpoint and
8225 location that's only been partially initialized. */
8226 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8229 loc
= allocate_bp_location (b
);
8230 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
8234 loc
->requested_address
= sal
->pc
;
8235 loc
->address
= adjusted_address
;
8236 loc
->pspace
= sal
->pspace
;
8237 gdb_assert (loc
->pspace
!= NULL
);
8238 loc
->section
= sal
->section
;
8239 loc
->gdbarch
= loc_gdbarch
;
8241 if (sal
->symtab
!= NULL
)
8242 loc
->source_file
= xstrdup (sal
->symtab
->filename
);
8243 loc
->line_number
= sal
->line
;
8245 set_breakpoint_location_function (loc
,
8246 sal
->explicit_pc
|| sal
->explicit_line
);
8251 /* Return 1 if LOC is pointing to a permanent breakpoint,
8252 return 0 otherwise. */
8255 bp_loc_is_permanent (struct bp_location
*loc
)
8259 const gdb_byte
*bpoint
;
8260 gdb_byte
*target_mem
;
8261 struct cleanup
*cleanup
;
8264 gdb_assert (loc
!= NULL
);
8266 addr
= loc
->address
;
8267 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
8269 /* Software breakpoints unsupported? */
8273 target_mem
= alloca (len
);
8275 /* Enable the automatic memory restoration from breakpoints while
8276 we read the memory. Otherwise we could say about our temporary
8277 breakpoints they are permanent. */
8278 cleanup
= save_current_space_and_thread ();
8280 switch_to_program_space_and_thread (loc
->pspace
);
8281 make_show_memory_breakpoints_cleanup (0);
8283 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
8284 && memcmp (target_mem
, bpoint
, len
) == 0)
8287 do_cleanups (cleanup
);
8294 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8295 as textual description of the location, and COND_STRING
8296 as condition expression. */
8299 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8300 struct symtabs_and_lines sals
, char *addr_string
,
8301 char *filter
, char *cond_string
,
8302 enum bptype type
, enum bpdisp disposition
,
8303 int thread
, int task
, int ignore_count
,
8304 const struct breakpoint_ops
*ops
, int from_tty
,
8305 int enabled
, int internal
, unsigned flags
,
8306 int display_canonical
)
8310 if (type
== bp_hardware_breakpoint
)
8312 int target_resources_ok
;
8314 i
= hw_breakpoint_used_count ();
8315 target_resources_ok
=
8316 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8318 if (target_resources_ok
== 0)
8319 error (_("No hardware breakpoint support in the target."));
8320 else if (target_resources_ok
< 0)
8321 error (_("Hardware breakpoints used exceeds limit."));
8324 gdb_assert (sals
.nelts
> 0);
8326 for (i
= 0; i
< sals
.nelts
; ++i
)
8328 struct symtab_and_line sal
= sals
.sals
[i
];
8329 struct bp_location
*loc
;
8333 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8335 loc_gdbarch
= gdbarch
;
8337 describe_other_breakpoints (loc_gdbarch
,
8338 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8343 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8347 b
->cond_string
= cond_string
;
8348 b
->ignore_count
= ignore_count
;
8349 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8350 b
->disposition
= disposition
;
8352 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8353 b
->loc
->inserted
= 1;
8355 if (type
== bp_static_tracepoint
)
8357 struct tracepoint
*t
= (struct tracepoint
*) b
;
8358 struct static_tracepoint_marker marker
;
8360 if (strace_marker_p (b
))
8362 /* We already know the marker exists, otherwise, we
8363 wouldn't see a sal for it. */
8364 char *p
= &addr_string
[3];
8368 p
= skip_spaces (p
);
8370 endp
= skip_to_space (p
);
8372 marker_str
= savestring (p
, endp
- p
);
8373 t
->static_trace_marker_id
= marker_str
;
8375 printf_filtered (_("Probed static tracepoint "
8377 t
->static_trace_marker_id
);
8379 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8381 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
8382 release_static_tracepoint_marker (&marker
);
8384 printf_filtered (_("Probed static tracepoint "
8386 t
->static_trace_marker_id
);
8389 warning (_("Couldn't determine the static "
8390 "tracepoint marker to probe"));
8397 loc
= add_location_to_breakpoint (b
, &sal
);
8398 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8402 if (bp_loc_is_permanent (loc
))
8403 make_breakpoint_permanent (b
);
8407 char *arg
= b
->cond_string
;
8408 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
8410 error (_("Garbage %s follows condition"), arg
);
8414 b
->display_canonical
= display_canonical
;
8416 b
->addr_string
= addr_string
;
8418 /* addr_string has to be used or breakpoint_re_set will delete
8421 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
8426 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8427 struct symtabs_and_lines sals
, char *addr_string
,
8428 char *filter
, char *cond_string
,
8429 enum bptype type
, enum bpdisp disposition
,
8430 int thread
, int task
, int ignore_count
,
8431 const struct breakpoint_ops
*ops
, int from_tty
,
8432 int enabled
, int internal
, unsigned flags
,
8433 int display_canonical
)
8435 struct breakpoint
*b
;
8436 struct cleanup
*old_chain
;
8438 if (is_tracepoint_type (type
))
8440 struct tracepoint
*t
;
8442 t
= XCNEW (struct tracepoint
);
8446 b
= XNEW (struct breakpoint
);
8448 old_chain
= make_cleanup (xfree
, b
);
8450 init_breakpoint_sal (b
, gdbarch
,
8452 filter
, cond_string
,
8454 thread
, task
, ignore_count
,
8456 enabled
, internal
, flags
,
8458 discard_cleanups (old_chain
);
8460 install_breakpoint (internal
, b
, 0);
8463 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8464 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8465 value. COND_STRING, if not NULL, specified the condition to be
8466 used for all breakpoints. Essentially the only case where
8467 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8468 function. In that case, it's still not possible to specify
8469 separate conditions for different overloaded functions, so
8470 we take just a single condition string.
8472 NOTE: If the function succeeds, the caller is expected to cleanup
8473 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8474 array contents). If the function fails (error() is called), the
8475 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8476 COND and SALS arrays and each of those arrays contents. */
8479 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8480 struct linespec_result
*canonical
,
8482 enum bptype type
, enum bpdisp disposition
,
8483 int thread
, int task
, int ignore_count
,
8484 const struct breakpoint_ops
*ops
, int from_tty
,
8485 int enabled
, int internal
, unsigned flags
)
8488 struct linespec_sals
*lsal
;
8490 if (canonical
->pre_expanded
)
8491 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
8493 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
8495 /* Note that 'addr_string' can be NULL in the case of a plain
8496 'break', without arguments. */
8497 char *addr_string
= (canonical
->addr_string
8498 ? xstrdup (canonical
->addr_string
)
8500 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
8501 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
8503 make_cleanup (xfree
, filter_string
);
8504 create_breakpoint_sal (gdbarch
, lsal
->sals
,
8507 cond_string
, type
, disposition
,
8508 thread
, task
, ignore_count
, ops
,
8509 from_tty
, enabled
, internal
, flags
,
8510 canonical
->special_display
);
8511 discard_cleanups (inner
);
8515 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8516 followed by conditionals. On return, SALS contains an array of SAL
8517 addresses found. ADDR_STRING contains a vector of (canonical)
8518 address strings. ADDRESS points to the end of the SAL.
8520 The array and the line spec strings are allocated on the heap, it is
8521 the caller's responsibility to free them. */
8524 parse_breakpoint_sals (char **address
,
8525 struct linespec_result
*canonical
)
8527 char *addr_start
= *address
;
8529 /* If no arg given, or if first arg is 'if ', use the default
8531 if ((*address
) == NULL
8532 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
8534 /* The last displayed codepoint, if it's valid, is our default breakpoint
8536 if (last_displayed_sal_is_valid ())
8538 struct linespec_sals lsal
;
8539 struct symtab_and_line sal
;
8541 init_sal (&sal
); /* Initialize to zeroes. */
8542 lsal
.sals
.sals
= (struct symtab_and_line
*)
8543 xmalloc (sizeof (struct symtab_and_line
));
8545 /* Set sal's pspace, pc, symtab, and line to the values
8546 corresponding to the last call to print_frame_info. */
8547 get_last_displayed_sal (&sal
);
8548 sal
.section
= find_pc_overlay (sal
.pc
);
8550 /* "break" without arguments is equivalent to "break *PC"
8551 where PC is the last displayed codepoint's address. So
8552 make sure to set sal.explicit_pc to prevent GDB from
8553 trying to expand the list of sals to include all other
8554 instances with the same symtab and line. */
8555 sal
.explicit_pc
= 1;
8557 lsal
.sals
.sals
[0] = sal
;
8558 lsal
.sals
.nelts
= 1;
8559 lsal
.canonical
= NULL
;
8561 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
8564 error (_("No default breakpoint address now."));
8568 /* Force almost all breakpoints to be in terms of the
8569 current_source_symtab (which is decode_line_1's default).
8570 This should produce the results we want almost all of the
8571 time while leaving default_breakpoint_* alone. */
8572 if (last_displayed_sal_is_valid ())
8573 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8574 get_last_displayed_symtab (),
8575 get_last_displayed_line (),
8576 canonical
, NULL
, NULL
);
8578 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8579 (struct symtab
*) NULL
, 0,
8580 canonical
, NULL
, NULL
);
8585 /* Convert each SAL into a real PC. Verify that the PC can be
8586 inserted as a breakpoint. If it can't throw an error. */
8589 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
8593 for (i
= 0; i
< sals
->nelts
; i
++)
8594 resolve_sal_pc (&sals
->sals
[i
]);
8597 /* Fast tracepoints may have restrictions on valid locations. For
8598 instance, a fast tracepoint using a jump instead of a trap will
8599 likely have to overwrite more bytes than a trap would, and so can
8600 only be placed where the instruction is longer than the jump, or a
8601 multi-instruction sequence does not have a jump into the middle of
8605 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8606 struct symtabs_and_lines
*sals
)
8609 struct symtab_and_line
*sal
;
8611 struct cleanup
*old_chain
;
8613 for (i
= 0; i
< sals
->nelts
; i
++)
8615 struct gdbarch
*sarch
;
8617 sal
= &sals
->sals
[i
];
8619 sarch
= get_sal_arch (*sal
);
8620 /* We fall back to GDBARCH if there is no architecture
8621 associated with SAL. */
8624 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
8626 old_chain
= make_cleanup (xfree
, msg
);
8629 error (_("May not have a fast tracepoint at 0x%s%s"),
8630 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
8632 do_cleanups (old_chain
);
8636 /* Given TOK, a string specification of condition and thread, as
8637 accepted by the 'break' command, extract the condition
8638 string and thread number and set *COND_STRING and *THREAD.
8639 PC identifies the context at which the condition should be parsed.
8640 If no condition is found, *COND_STRING is set to NULL.
8641 If no thread is found, *THREAD is set to -1. */
8643 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
8644 char **cond_string
, int *thread
, int *task
)
8646 *cond_string
= NULL
;
8652 char *cond_start
= NULL
;
8653 char *cond_end
= NULL
;
8655 tok
= skip_spaces (tok
);
8657 end_tok
= skip_to_space (tok
);
8659 toklen
= end_tok
- tok
;
8661 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8663 struct expression
*expr
;
8665 tok
= cond_start
= end_tok
+ 1;
8666 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
8669 *cond_string
= savestring (cond_start
,
8670 cond_end
- cond_start
);
8672 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8678 *thread
= strtol (tok
, &tok
, 0);
8680 error (_("Junk after thread keyword."));
8681 if (!valid_thread_id (*thread
))
8682 error (_("Unknown thread %d."), *thread
);
8684 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8690 *task
= strtol (tok
, &tok
, 0);
8692 error (_("Junk after task keyword."));
8693 if (!valid_task_id (*task
))
8694 error (_("Unknown task %d."), *task
);
8697 error (_("Junk at end of arguments."));
8701 /* Decode a static tracepoint marker spec. */
8703 static struct symtabs_and_lines
8704 decode_static_tracepoint_spec (char **arg_p
)
8706 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
8707 struct symtabs_and_lines sals
;
8708 struct symtab_and_line sal
;
8710 struct cleanup
*old_chain
;
8711 char *p
= &(*arg_p
)[3];
8716 p
= skip_spaces (p
);
8718 endp
= skip_to_space (p
);
8720 marker_str
= savestring (p
, endp
- p
);
8721 old_chain
= make_cleanup (xfree
, marker_str
);
8723 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
8724 if (VEC_empty(static_tracepoint_marker_p
, markers
))
8725 error (_("No known static tracepoint marker named %s"), marker_str
);
8727 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
8728 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
8730 for (i
= 0; i
< sals
.nelts
; i
++)
8732 struct static_tracepoint_marker
*marker
;
8734 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
8736 init_sal (&sals
.sals
[i
]);
8738 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
8739 sals
.sals
[i
].pc
= marker
->address
;
8741 release_static_tracepoint_marker (marker
);
8744 do_cleanups (old_chain
);
8750 /* Set a breakpoint. This function is shared between CLI and MI
8751 functions for setting a breakpoint. This function has two major
8752 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
8753 parameter. If non-zero, the function will parse arg, extracting
8754 breakpoint location, address and thread. Otherwise, ARG is just
8755 the location of breakpoint, with condition and thread specified by
8756 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
8757 the breakpoint number will be allocated from the internal
8758 breakpoint count. Returns true if any breakpoint was created;
8762 create_breakpoint (struct gdbarch
*gdbarch
,
8763 char *arg
, char *cond_string
, int thread
,
8764 int parse_condition_and_thread
,
8765 int tempflag
, enum bptype type_wanted
,
8767 enum auto_boolean pending_break_support
,
8768 const struct breakpoint_ops
*ops
,
8769 int from_tty
, int enabled
, int internal
,
8772 volatile struct gdb_exception e
;
8773 char *copy_arg
= NULL
;
8774 char *addr_start
= arg
;
8775 struct linespec_result canonical
;
8776 struct cleanup
*old_chain
;
8777 struct cleanup
*bkpt_chain
= NULL
;
8781 int prev_bkpt_count
= breakpoint_count
;
8783 gdb_assert (ops
!= NULL
);
8785 init_linespec_result (&canonical
);
8787 TRY_CATCH (e
, RETURN_MASK_ALL
)
8789 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
8790 addr_start
, ©_arg
);
8793 /* If caller is interested in rc value from parse, set value. */
8797 if (VEC_empty (linespec_sals
, canonical
.sals
))
8803 case NOT_FOUND_ERROR
:
8805 /* If pending breakpoint support is turned off, throw
8808 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8809 throw_exception (e
);
8811 exception_print (gdb_stderr
, e
);
8813 /* If pending breakpoint support is auto query and the user
8814 selects no, then simply return the error code. */
8815 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8816 && !nquery (_("Make %s pending on future shared library load? "),
8817 bptype_string (type_wanted
)))
8820 /* At this point, either the user was queried about setting
8821 a pending breakpoint and selected yes, or pending
8822 breakpoint behavior is on and thus a pending breakpoint
8823 is defaulted on behalf of the user. */
8825 struct linespec_sals lsal
;
8827 copy_arg
= xstrdup (addr_start
);
8828 lsal
.canonical
= xstrdup (copy_arg
);
8829 lsal
.sals
.nelts
= 1;
8830 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
8831 init_sal (&lsal
.sals
.sals
[0]);
8833 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
8837 throw_exception (e
);
8841 throw_exception (e
);
8844 /* Create a chain of things that always need to be cleaned up. */
8845 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
8847 /* ----------------------------- SNIP -----------------------------
8848 Anything added to the cleanup chain beyond this point is assumed
8849 to be part of a breakpoint. If the breakpoint create succeeds
8850 then the memory is not reclaimed. */
8851 bkpt_chain
= make_cleanup (null_cleanup
, 0);
8853 /* Resolve all line numbers to PC's and verify that the addresses
8854 are ok for the target. */
8858 struct linespec_sals
*iter
;
8860 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
8861 breakpoint_sals_to_pc (&iter
->sals
);
8864 /* Fast tracepoints may have additional restrictions on location. */
8865 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8868 struct linespec_sals
*iter
;
8870 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
8871 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
8874 /* Verify that condition can be parsed, before setting any
8875 breakpoints. Allocate a separate condition expression for each
8879 struct linespec_sals
*lsal
;
8881 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
8883 if (parse_condition_and_thread
)
8885 /* Here we only parse 'arg' to separate condition
8886 from thread number, so parsing in context of first
8887 sal is OK. When setting the breakpoint we'll
8888 re-parse it in context of each sal. */
8891 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
8894 make_cleanup (xfree
, cond_string
);
8898 /* Create a private copy of condition string. */
8901 cond_string
= xstrdup (cond_string
);
8902 make_cleanup (xfree
, cond_string
);
8906 ops
->create_breakpoints_sal (gdbarch
, &canonical
, lsal
,
8907 cond_string
, type_wanted
,
8908 tempflag
? disp_del
: disp_donttouch
,
8909 thread
, task
, ignore_count
, ops
,
8910 from_tty
, enabled
, internal
, flags
);
8914 struct breakpoint
*b
;
8916 make_cleanup (xfree
, copy_arg
);
8918 if (is_tracepoint_type (type_wanted
))
8920 struct tracepoint
*t
;
8922 t
= XCNEW (struct tracepoint
);
8926 b
= XNEW (struct breakpoint
);
8928 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
8930 b
->addr_string
= copy_arg
;
8931 b
->cond_string
= NULL
;
8932 b
->ignore_count
= ignore_count
;
8933 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8934 b
->condition_not_parsed
= 1;
8935 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8936 if ((type_wanted
!= bp_breakpoint
8937 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
8938 b
->pspace
= current_program_space
;
8940 install_breakpoint (internal
, b
, 0);
8943 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
8945 warning (_("Multiple breakpoints were set.\nUse the "
8946 "\"delete\" command to delete unwanted breakpoints."));
8947 prev_breakpoint_count
= prev_bkpt_count
;
8950 /* That's it. Discard the cleanups for data inserted into the
8952 discard_cleanups (bkpt_chain
);
8953 /* But cleanup everything else. */
8954 do_cleanups (old_chain
);
8956 /* error call may happen here - have BKPT_CHAIN already discarded. */
8957 update_global_location_list (1);
8962 /* Set a breakpoint.
8963 ARG is a string describing breakpoint address,
8964 condition, and thread.
8965 FLAG specifies if a breakpoint is hardware on,
8966 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8970 break_command_1 (char *arg
, int flag
, int from_tty
)
8972 int tempflag
= flag
& BP_TEMPFLAG
;
8973 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8974 ? bp_hardware_breakpoint
8977 create_breakpoint (get_current_arch (),
8979 NULL
, 0, 1 /* parse arg */,
8980 tempflag
, type_wanted
,
8981 0 /* Ignore count */,
8982 pending_break_support
,
8983 &bkpt_breakpoint_ops
,
8990 /* Helper function for break_command_1 and disassemble_command. */
8993 resolve_sal_pc (struct symtab_and_line
*sal
)
8997 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8999 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9000 error (_("No line %d in file \"%s\"."),
9001 sal
->line
, sal
->symtab
->filename
);
9004 /* If this SAL corresponds to a breakpoint inserted using a line
9005 number, then skip the function prologue if necessary. */
9006 if (sal
->explicit_line
)
9007 skip_prologue_sal (sal
);
9010 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9012 struct blockvector
*bv
;
9016 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
9019 sym
= block_linkage_function (b
);
9022 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
9023 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
9027 /* It really is worthwhile to have the section, so we'll
9028 just have to look harder. This case can be executed
9029 if we have line numbers but no functions (as can
9030 happen in assembly source). */
9032 struct minimal_symbol
*msym
;
9033 struct cleanup
*old_chain
= save_current_space_and_thread ();
9035 switch_to_program_space_and_thread (sal
->pspace
);
9037 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9039 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
9041 do_cleanups (old_chain
);
9048 break_command (char *arg
, int from_tty
)
9050 break_command_1 (arg
, 0, from_tty
);
9054 tbreak_command (char *arg
, int from_tty
)
9056 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9060 hbreak_command (char *arg
, int from_tty
)
9062 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9066 thbreak_command (char *arg
, int from_tty
)
9068 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9072 stop_command (char *arg
, int from_tty
)
9074 printf_filtered (_("Specify the type of breakpoint to set.\n\
9075 Usage: stop in <function | address>\n\
9076 stop at <line>\n"));
9080 stopin_command (char *arg
, int from_tty
)
9084 if (arg
== (char *) NULL
)
9086 else if (*arg
!= '*')
9091 /* Look for a ':'. If this is a line number specification, then
9092 say it is bad, otherwise, it should be an address or
9093 function/method name. */
9094 while (*argptr
&& !hasColon
)
9096 hasColon
= (*argptr
== ':');
9101 badInput
= (*argptr
!= ':'); /* Not a class::method */
9103 badInput
= isdigit (*arg
); /* a simple line number */
9107 printf_filtered (_("Usage: stop in <function | address>\n"));
9109 break_command_1 (arg
, 0, from_tty
);
9113 stopat_command (char *arg
, int from_tty
)
9117 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9124 /* Look for a ':'. If there is a '::' then get out, otherwise
9125 it is probably a line number. */
9126 while (*argptr
&& !hasColon
)
9128 hasColon
= (*argptr
== ':');
9133 badInput
= (*argptr
== ':'); /* we have class::method */
9135 badInput
= !isdigit (*arg
); /* not a line number */
9139 printf_filtered (_("Usage: stop at <line>\n"));
9141 break_command_1 (arg
, 0, from_tty
);
9144 /* Implement the "breakpoint_hit" breakpoint_ops method for
9145 ranged breakpoints. */
9148 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9149 struct address_space
*aspace
,
9151 const struct target_waitstatus
*ws
)
9153 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9154 || ws
->value
.sig
!= TARGET_SIGNAL_TRAP
)
9157 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9158 bl
->length
, aspace
, bp_addr
);
9161 /* Implement the "resources_needed" breakpoint_ops method for
9162 ranged breakpoints. */
9165 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9167 return target_ranged_break_num_registers ();
9170 /* Implement the "print_it" breakpoint_ops method for
9171 ranged breakpoints. */
9173 static enum print_stop_action
9174 print_it_ranged_breakpoint (bpstat bs
)
9176 struct breakpoint
*b
= bs
->breakpoint_at
;
9177 struct bp_location
*bl
= b
->loc
;
9178 struct ui_out
*uiout
= current_uiout
;
9180 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9182 /* Ranged breakpoints have only one location. */
9183 gdb_assert (bl
&& bl
->next
== NULL
);
9185 annotate_breakpoint (b
->number
);
9186 if (b
->disposition
== disp_del
)
9187 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
9189 ui_out_text (uiout
, "\nRanged breakpoint ");
9190 if (ui_out_is_mi_like_p (uiout
))
9192 ui_out_field_string (uiout
, "reason",
9193 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9194 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9196 ui_out_field_int (uiout
, "bkptno", b
->number
);
9197 ui_out_text (uiout
, ", ");
9199 return PRINT_SRC_AND_LOC
;
9202 /* Implement the "print_one" breakpoint_ops method for
9203 ranged breakpoints. */
9206 print_one_ranged_breakpoint (struct breakpoint
*b
,
9207 struct bp_location
**last_loc
)
9209 struct bp_location
*bl
= b
->loc
;
9210 struct value_print_options opts
;
9211 struct ui_out
*uiout
= current_uiout
;
9213 /* Ranged breakpoints have only one location. */
9214 gdb_assert (bl
&& bl
->next
== NULL
);
9216 get_user_print_options (&opts
);
9218 if (opts
.addressprint
)
9219 /* We don't print the address range here, it will be printed later
9220 by print_one_detail_ranged_breakpoint. */
9221 ui_out_field_skip (uiout
, "addr");
9223 print_breakpoint_location (b
, bl
);
9227 /* Implement the "print_one_detail" breakpoint_ops method for
9228 ranged breakpoints. */
9231 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9232 struct ui_out
*uiout
)
9234 CORE_ADDR address_start
, address_end
;
9235 struct bp_location
*bl
= b
->loc
;
9236 struct ui_file
*stb
= mem_fileopen ();
9237 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
9241 address_start
= bl
->address
;
9242 address_end
= address_start
+ bl
->length
- 1;
9244 ui_out_text (uiout
, "\taddress range: ");
9245 fprintf_unfiltered (stb
, "[%s, %s]",
9246 print_core_address (bl
->gdbarch
, address_start
),
9247 print_core_address (bl
->gdbarch
, address_end
));
9248 ui_out_field_stream (uiout
, "addr", stb
);
9249 ui_out_text (uiout
, "\n");
9251 do_cleanups (cleanup
);
9254 /* Implement the "print_mention" breakpoint_ops method for
9255 ranged breakpoints. */
9258 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9260 struct bp_location
*bl
= b
->loc
;
9261 struct ui_out
*uiout
= current_uiout
;
9264 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9266 if (ui_out_is_mi_like_p (uiout
))
9269 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9270 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9271 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9274 /* Implement the "print_recreate" breakpoint_ops method for
9275 ranged breakpoints. */
9278 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9280 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
9281 b
->addr_string_range_end
);
9282 print_recreate_thread (b
, fp
);
9285 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9287 static struct breakpoint_ops ranged_breakpoint_ops
;
9289 /* Find the address where the end of the breakpoint range should be
9290 placed, given the SAL of the end of the range. This is so that if
9291 the user provides a line number, the end of the range is set to the
9292 last instruction of the given line. */
9295 find_breakpoint_range_end (struct symtab_and_line sal
)
9299 /* If the user provided a PC value, use it. Otherwise,
9300 find the address of the end of the given location. */
9301 if (sal
.explicit_pc
)
9308 ret
= find_line_pc_range (sal
, &start
, &end
);
9310 error (_("Could not find location of the end of the range."));
9312 /* find_line_pc_range returns the start of the next line. */
9319 /* Implement the "break-range" CLI command. */
9322 break_range_command (char *arg
, int from_tty
)
9324 char *arg_start
, *addr_string_start
, *addr_string_end
;
9325 struct linespec_result canonical_start
, canonical_end
;
9326 int bp_count
, can_use_bp
, length
;
9328 struct breakpoint
*b
;
9329 struct symtab_and_line sal_start
, sal_end
;
9330 struct cleanup
*cleanup_bkpt
;
9331 struct linespec_sals
*lsal_start
, *lsal_end
;
9333 /* We don't support software ranged breakpoints. */
9334 if (target_ranged_break_num_registers () < 0)
9335 error (_("This target does not support hardware ranged breakpoints."));
9337 bp_count
= hw_breakpoint_used_count ();
9338 bp_count
+= target_ranged_break_num_registers ();
9339 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9342 error (_("Hardware breakpoints used exceeds limit."));
9344 arg
= skip_spaces (arg
);
9345 if (arg
== NULL
|| arg
[0] == '\0')
9346 error(_("No address range specified."));
9348 init_linespec_result (&canonical_start
);
9351 parse_breakpoint_sals (&arg
, &canonical_start
);
9353 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
9356 error (_("Too few arguments."));
9357 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
9358 error (_("Could not find location of the beginning of the range."));
9360 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
9362 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
9363 || lsal_start
->sals
.nelts
!= 1)
9364 error (_("Cannot create a ranged breakpoint with multiple locations."));
9366 sal_start
= lsal_start
->sals
.sals
[0];
9367 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
9368 make_cleanup (xfree
, addr_string_start
);
9370 arg
++; /* Skip the comma. */
9371 arg
= skip_spaces (arg
);
9373 /* Parse the end location. */
9375 init_linespec_result (&canonical_end
);
9378 /* We call decode_line_full directly here instead of using
9379 parse_breakpoint_sals because we need to specify the start location's
9380 symtab and line as the default symtab and line for the end of the
9381 range. This makes it possible to have ranges like "foo.c:27, +14",
9382 where +14 means 14 lines from the start location. */
9383 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9384 sal_start
.symtab
, sal_start
.line
,
9385 &canonical_end
, NULL
, NULL
);
9387 make_cleanup_destroy_linespec_result (&canonical_end
);
9389 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
9390 error (_("Could not find location of the end of the range."));
9392 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
9393 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
9394 || lsal_end
->sals
.nelts
!= 1)
9395 error (_("Cannot create a ranged breakpoint with multiple locations."));
9397 sal_end
= lsal_end
->sals
.sals
[0];
9398 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
9399 make_cleanup (xfree
, addr_string_end
);
9401 end
= find_breakpoint_range_end (sal_end
);
9402 if (sal_start
.pc
> end
)
9403 error (_("Invalid address range, end precedes start."));
9405 length
= end
- sal_start
.pc
+ 1;
9407 /* Length overflowed. */
9408 error (_("Address range too large."));
9409 else if (length
== 1)
9411 /* This range is simple enough to be handled by
9412 the `hbreak' command. */
9413 hbreak_command (addr_string_start
, 1);
9415 do_cleanups (cleanup_bkpt
);
9420 /* Now set up the breakpoint. */
9421 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9422 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9423 set_breakpoint_count (breakpoint_count
+ 1);
9424 b
->number
= breakpoint_count
;
9425 b
->disposition
= disp_donttouch
;
9426 b
->addr_string
= xstrdup (addr_string_start
);
9427 b
->addr_string_range_end
= xstrdup (addr_string_end
);
9428 b
->loc
->length
= length
;
9430 do_cleanups (cleanup_bkpt
);
9433 observer_notify_breakpoint_created (b
);
9434 update_global_location_list (1);
9437 /* Return non-zero if EXP is verified as constant. Returned zero
9438 means EXP is variable. Also the constant detection may fail for
9439 some constant expressions and in such case still falsely return
9443 watchpoint_exp_is_const (const struct expression
*exp
)
9451 /* We are only interested in the descriptor of each element. */
9452 operator_length (exp
, i
, &oplenp
, &argsp
);
9455 switch (exp
->elts
[i
].opcode
)
9465 case BINOP_LOGICAL_AND
:
9466 case BINOP_LOGICAL_OR
:
9467 case BINOP_BITWISE_AND
:
9468 case BINOP_BITWISE_IOR
:
9469 case BINOP_BITWISE_XOR
:
9471 case BINOP_NOTEQUAL
:
9487 case TERNOP_SLICE_COUNT
:
9499 case OP_OBJC_NSSTRING
:
9502 case UNOP_LOGICAL_NOT
:
9503 case UNOP_COMPLEMENT
:
9507 /* Unary, binary and ternary operators: We have to check
9508 their operands. If they are constant, then so is the
9509 result of that operation. For instance, if A and B are
9510 determined to be constants, then so is "A + B".
9512 UNOP_IND is one exception to the rule above, because the
9513 value of *ADDR is not necessarily a constant, even when
9518 /* Check whether the associated symbol is a constant.
9520 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9521 possible that a buggy compiler could mark a variable as
9522 constant even when it is not, and TYPE_CONST would return
9523 true in this case, while SYMBOL_CLASS wouldn't.
9525 We also have to check for function symbols because they
9526 are always constant. */
9528 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9530 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9531 && SYMBOL_CLASS (s
) != LOC_CONST
9532 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9537 /* The default action is to return 0 because we are using
9538 the optimistic approach here: If we don't know something,
9539 then it is not a constant. */
9548 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9551 dtor_watchpoint (struct breakpoint
*self
)
9553 struct watchpoint
*w
= (struct watchpoint
*) self
;
9555 xfree (w
->cond_exp
);
9557 xfree (w
->exp_string
);
9558 xfree (w
->exp_string_reparse
);
9559 value_free (w
->val
);
9561 base_breakpoint_ops
.dtor (self
);
9564 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9567 re_set_watchpoint (struct breakpoint
*b
)
9569 struct watchpoint
*w
= (struct watchpoint
*) b
;
9571 /* Watchpoint can be either on expression using entirely global
9572 variables, or it can be on local variables.
9574 Watchpoints of the first kind are never auto-deleted, and even
9575 persist across program restarts. Since they can use variables
9576 from shared libraries, we need to reparse expression as libraries
9577 are loaded and unloaded.
9579 Watchpoints on local variables can also change meaning as result
9580 of solib event. For example, if a watchpoint uses both a local
9581 and a global variables in expression, it's a local watchpoint,
9582 but unloading of a shared library will make the expression
9583 invalid. This is not a very common use case, but we still
9584 re-evaluate expression, to avoid surprises to the user.
9586 Note that for local watchpoints, we re-evaluate it only if
9587 watchpoints frame id is still valid. If it's not, it means the
9588 watchpoint is out of scope and will be deleted soon. In fact,
9589 I'm not sure we'll ever be called in this case.
9591 If a local watchpoint's frame id is still valid, then
9592 w->exp_valid_block is likewise valid, and we can safely use it.
9594 Don't do anything about disabled watchpoints, since they will be
9595 reevaluated again when enabled. */
9596 update_watchpoint (w
, 1 /* reparse */);
9599 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9602 insert_watchpoint (struct bp_location
*bl
)
9604 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9605 int length
= w
->exact
? 1 : bl
->length
;
9607 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9611 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9614 remove_watchpoint (struct bp_location
*bl
)
9616 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9617 int length
= w
->exact
? 1 : bl
->length
;
9619 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9624 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
9625 struct address_space
*aspace
, CORE_ADDR bp_addr
,
9626 const struct target_waitstatus
*ws
)
9628 struct breakpoint
*b
= bl
->owner
;
9629 struct watchpoint
*w
= (struct watchpoint
*) b
;
9631 /* Continuable hardware watchpoints are treated as non-existent if the
9632 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9633 some data address). Otherwise gdb won't stop on a break instruction
9634 in the code (not from a breakpoint) when a hardware watchpoint has
9635 been defined. Also skip watchpoints which we know did not trigger
9636 (did not match the data address). */
9637 if (is_hardware_watchpoint (b
)
9638 && w
->watchpoint_triggered
== watch_triggered_no
)
9645 check_status_watchpoint (bpstat bs
)
9647 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9649 bpstat_check_watchpoint (bs
);
9652 /* Implement the "resources_needed" breakpoint_ops method for
9653 hardware watchpoints. */
9656 resources_needed_watchpoint (const struct bp_location
*bl
)
9658 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9659 int length
= w
->exact
? 1 : bl
->length
;
9661 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9664 /* Implement the "works_in_software_mode" breakpoint_ops method for
9665 hardware watchpoints. */
9668 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
9670 /* Read and access watchpoints only work with hardware support. */
9671 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
9674 static enum print_stop_action
9675 print_it_watchpoint (bpstat bs
)
9677 struct cleanup
*old_chain
;
9678 struct breakpoint
*b
;
9679 const struct bp_location
*bl
;
9680 struct ui_file
*stb
;
9681 enum print_stop_action result
;
9682 struct watchpoint
*w
;
9683 struct ui_out
*uiout
= current_uiout
;
9685 gdb_assert (bs
->bp_location_at
!= NULL
);
9687 bl
= bs
->bp_location_at
;
9688 b
= bs
->breakpoint_at
;
9689 w
= (struct watchpoint
*) b
;
9691 stb
= mem_fileopen ();
9692 old_chain
= make_cleanup_ui_file_delete (stb
);
9697 case bp_hardware_watchpoint
:
9698 annotate_watchpoint (b
->number
);
9699 if (ui_out_is_mi_like_p (uiout
))
9702 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9704 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9705 ui_out_text (uiout
, "\nOld value = ");
9706 watchpoint_value_print (bs
->old_val
, stb
);
9707 ui_out_field_stream (uiout
, "old", stb
);
9708 ui_out_text (uiout
, "\nNew value = ");
9709 watchpoint_value_print (w
->val
, stb
);
9710 ui_out_field_stream (uiout
, "new", stb
);
9711 ui_out_text (uiout
, "\n");
9712 /* More than one watchpoint may have been triggered. */
9713 result
= PRINT_UNKNOWN
;
9716 case bp_read_watchpoint
:
9717 if (ui_out_is_mi_like_p (uiout
))
9720 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9722 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9723 ui_out_text (uiout
, "\nValue = ");
9724 watchpoint_value_print (w
->val
, stb
);
9725 ui_out_field_stream (uiout
, "value", stb
);
9726 ui_out_text (uiout
, "\n");
9727 result
= PRINT_UNKNOWN
;
9730 case bp_access_watchpoint
:
9731 if (bs
->old_val
!= NULL
)
9733 annotate_watchpoint (b
->number
);
9734 if (ui_out_is_mi_like_p (uiout
))
9737 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9739 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9740 ui_out_text (uiout
, "\nOld value = ");
9741 watchpoint_value_print (bs
->old_val
, stb
);
9742 ui_out_field_stream (uiout
, "old", stb
);
9743 ui_out_text (uiout
, "\nNew value = ");
9748 if (ui_out_is_mi_like_p (uiout
))
9751 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9752 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9753 ui_out_text (uiout
, "\nValue = ");
9755 watchpoint_value_print (w
->val
, stb
);
9756 ui_out_field_stream (uiout
, "new", stb
);
9757 ui_out_text (uiout
, "\n");
9758 result
= PRINT_UNKNOWN
;
9761 result
= PRINT_UNKNOWN
;
9764 do_cleanups (old_chain
);
9768 /* Implement the "print_mention" breakpoint_ops method for hardware
9772 print_mention_watchpoint (struct breakpoint
*b
)
9774 struct cleanup
*ui_out_chain
;
9775 struct watchpoint
*w
= (struct watchpoint
*) b
;
9776 struct ui_out
*uiout
= current_uiout
;
9781 ui_out_text (uiout
, "Watchpoint ");
9782 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9784 case bp_hardware_watchpoint
:
9785 ui_out_text (uiout
, "Hardware watchpoint ");
9786 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9788 case bp_read_watchpoint
:
9789 ui_out_text (uiout
, "Hardware read watchpoint ");
9790 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
9792 case bp_access_watchpoint
:
9793 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
9794 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
9797 internal_error (__FILE__
, __LINE__
,
9798 _("Invalid hardware watchpoint type."));
9801 ui_out_field_int (uiout
, "number", b
->number
);
9802 ui_out_text (uiout
, ": ");
9803 ui_out_field_string (uiout
, "exp", w
->exp_string
);
9804 do_cleanups (ui_out_chain
);
9807 /* Implement the "print_recreate" breakpoint_ops method for
9811 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9813 struct watchpoint
*w
= (struct watchpoint
*) b
;
9818 case bp_hardware_watchpoint
:
9819 fprintf_unfiltered (fp
, "watch");
9821 case bp_read_watchpoint
:
9822 fprintf_unfiltered (fp
, "rwatch");
9824 case bp_access_watchpoint
:
9825 fprintf_unfiltered (fp
, "awatch");
9828 internal_error (__FILE__
, __LINE__
,
9829 _("Invalid watchpoint type."));
9832 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
9833 print_recreate_thread (b
, fp
);
9836 /* The breakpoint_ops structure to be used in hardware watchpoints. */
9838 static struct breakpoint_ops watchpoint_breakpoint_ops
;
9840 /* Implement the "insert" breakpoint_ops method for
9841 masked hardware watchpoints. */
9844 insert_masked_watchpoint (struct bp_location
*bl
)
9846 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9848 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9849 bl
->watchpoint_type
);
9852 /* Implement the "remove" breakpoint_ops method for
9853 masked hardware watchpoints. */
9856 remove_masked_watchpoint (struct bp_location
*bl
)
9858 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9860 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9861 bl
->watchpoint_type
);
9864 /* Implement the "resources_needed" breakpoint_ops method for
9865 masked hardware watchpoints. */
9868 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
9870 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9872 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
9875 /* Implement the "works_in_software_mode" breakpoint_ops method for
9876 masked hardware watchpoints. */
9879 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
9884 /* Implement the "print_it" breakpoint_ops method for
9885 masked hardware watchpoints. */
9887 static enum print_stop_action
9888 print_it_masked_watchpoint (bpstat bs
)
9890 struct breakpoint
*b
= bs
->breakpoint_at
;
9891 struct ui_out
*uiout
= current_uiout
;
9893 /* Masked watchpoints have only one location. */
9894 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9898 case bp_hardware_watchpoint
:
9899 annotate_watchpoint (b
->number
);
9900 if (ui_out_is_mi_like_p (uiout
))
9903 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9906 case bp_read_watchpoint
:
9907 if (ui_out_is_mi_like_p (uiout
))
9910 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9913 case bp_access_watchpoint
:
9914 if (ui_out_is_mi_like_p (uiout
))
9917 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9920 internal_error (__FILE__
, __LINE__
,
9921 _("Invalid hardware watchpoint type."));
9925 ui_out_text (uiout
, _("\n\
9926 Check the underlying instruction at PC for the memory\n\
9927 address and value which triggered this watchpoint.\n"));
9928 ui_out_text (uiout
, "\n");
9930 /* More than one watchpoint may have been triggered. */
9931 return PRINT_UNKNOWN
;
9934 /* Implement the "print_one_detail" breakpoint_ops method for
9935 masked hardware watchpoints. */
9938 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
9939 struct ui_out
*uiout
)
9941 struct watchpoint
*w
= (struct watchpoint
*) b
;
9943 /* Masked watchpoints have only one location. */
9944 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9946 ui_out_text (uiout
, "\tmask ");
9947 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
9948 ui_out_text (uiout
, "\n");
9951 /* Implement the "print_mention" breakpoint_ops method for
9952 masked hardware watchpoints. */
9955 print_mention_masked_watchpoint (struct breakpoint
*b
)
9957 struct watchpoint
*w
= (struct watchpoint
*) b
;
9958 struct ui_out
*uiout
= current_uiout
;
9959 struct cleanup
*ui_out_chain
;
9963 case bp_hardware_watchpoint
:
9964 ui_out_text (uiout
, "Masked hardware watchpoint ");
9965 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9967 case bp_read_watchpoint
:
9968 ui_out_text (uiout
, "Masked hardware read watchpoint ");
9969 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
9971 case bp_access_watchpoint
:
9972 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
9973 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
9976 internal_error (__FILE__
, __LINE__
,
9977 _("Invalid hardware watchpoint type."));
9980 ui_out_field_int (uiout
, "number", b
->number
);
9981 ui_out_text (uiout
, ": ");
9982 ui_out_field_string (uiout
, "exp", w
->exp_string
);
9983 do_cleanups (ui_out_chain
);
9986 /* Implement the "print_recreate" breakpoint_ops method for
9987 masked hardware watchpoints. */
9990 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9992 struct watchpoint
*w
= (struct watchpoint
*) b
;
9997 case bp_hardware_watchpoint
:
9998 fprintf_unfiltered (fp
, "watch");
10000 case bp_read_watchpoint
:
10001 fprintf_unfiltered (fp
, "rwatch");
10003 case bp_access_watchpoint
:
10004 fprintf_unfiltered (fp
, "awatch");
10007 internal_error (__FILE__
, __LINE__
,
10008 _("Invalid hardware watchpoint type."));
10011 sprintf_vma (tmp
, w
->hw_wp_mask
);
10012 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10013 print_recreate_thread (b
, fp
);
10016 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10018 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10020 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10023 is_masked_watchpoint (const struct breakpoint
*b
)
10025 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10028 /* accessflag: hw_write: watch write,
10029 hw_read: watch read,
10030 hw_access: watch access (read or write) */
10032 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
10033 int just_location
, int internal
)
10035 volatile struct gdb_exception e
;
10036 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10037 struct expression
*exp
;
10038 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10039 struct value
*val
, *mark
, *result
;
10040 struct frame_info
*frame
;
10041 char *exp_start
= NULL
;
10042 char *exp_end
= NULL
;
10043 char *tok
, *end_tok
;
10045 char *cond_start
= NULL
;
10046 char *cond_end
= NULL
;
10047 enum bptype bp_type
;
10050 /* Flag to indicate whether we are going to use masks for
10051 the hardware watchpoint. */
10053 CORE_ADDR mask
= 0;
10054 struct watchpoint
*w
;
10056 /* Make sure that we actually have parameters to parse. */
10057 if (arg
!= NULL
&& arg
[0] != '\0')
10061 /* Look for "parameter value" pairs at the end
10062 of the arguments string. */
10063 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
10065 /* Skip whitespace at the end of the argument list. */
10066 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10069 /* Find the beginning of the last token.
10070 This is the value of the parameter. */
10071 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10073 value_start
= tok
+ 1;
10075 /* Skip whitespace. */
10076 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10081 /* Find the beginning of the second to last token.
10082 This is the parameter itself. */
10083 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10086 toklen
= end_tok
- tok
+ 1;
10088 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
10090 /* At this point we've found a "thread" token, which means
10091 the user is trying to set a watchpoint that triggers
10092 only in a specific thread. */
10096 error(_("You can specify only one thread."));
10098 /* Extract the thread ID from the next token. */
10099 thread
= strtol (value_start
, &endp
, 0);
10101 /* Check if the user provided a valid numeric value for the
10103 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10104 error (_("Invalid thread ID specification %s."), value_start
);
10106 /* Check if the thread actually exists. */
10107 if (!valid_thread_id (thread
))
10108 error (_("Unknown thread %d."), thread
);
10110 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
10112 /* We've found a "mask" token, which means the user wants to
10113 create a hardware watchpoint that is going to have the mask
10115 struct value
*mask_value
, *mark
;
10118 error(_("You can specify only one mask."));
10120 use_mask
= just_location
= 1;
10122 mark
= value_mark ();
10123 mask_value
= parse_to_comma_and_eval (&value_start
);
10124 mask
= value_as_address (mask_value
);
10125 value_free_to_mark (mark
);
10128 /* We didn't recognize what we found. We should stop here. */
10131 /* Truncate the string and get rid of the "parameter value" pair before
10132 the arguments string is parsed by the parse_exp_1 function. */
10137 /* Parse the rest of the arguments. */
10138 innermost_block
= NULL
;
10140 exp
= parse_exp_1 (&arg
, 0, 0);
10142 /* Remove trailing whitespace from the expression before saving it.
10143 This makes the eventual display of the expression string a bit
10145 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10148 /* Checking if the expression is not constant. */
10149 if (watchpoint_exp_is_const (exp
))
10153 len
= exp_end
- exp_start
;
10154 while (len
> 0 && isspace (exp_start
[len
- 1]))
10156 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10159 exp_valid_block
= innermost_block
;
10160 mark
= value_mark ();
10161 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
10167 exp_valid_block
= NULL
;
10168 val
= value_addr (result
);
10169 release_value (val
);
10170 value_free_to_mark (mark
);
10174 ret
= target_masked_watch_num_registers (value_as_address (val
),
10177 error (_("This target does not support masked watchpoints."));
10178 else if (ret
== -2)
10179 error (_("Invalid mask or memory region."));
10182 else if (val
!= NULL
)
10183 release_value (val
);
10185 tok
= skip_spaces (arg
);
10186 end_tok
= skip_to_space (tok
);
10188 toklen
= end_tok
- tok
;
10189 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10191 struct expression
*cond
;
10193 innermost_block
= NULL
;
10194 tok
= cond_start
= end_tok
+ 1;
10195 cond
= parse_exp_1 (&tok
, 0, 0);
10197 /* The watchpoint expression may not be local, but the condition
10198 may still be. E.g.: `watch global if local > 0'. */
10199 cond_exp_valid_block
= innermost_block
;
10205 error (_("Junk at end of command."));
10207 if (accessflag
== hw_read
)
10208 bp_type
= bp_read_watchpoint
;
10209 else if (accessflag
== hw_access
)
10210 bp_type
= bp_access_watchpoint
;
10212 bp_type
= bp_hardware_watchpoint
;
10214 frame
= block_innermost_frame (exp_valid_block
);
10216 /* If the expression is "local", then set up a "watchpoint scope"
10217 breakpoint at the point where we've left the scope of the watchpoint
10218 expression. Create the scope breakpoint before the watchpoint, so
10219 that we will encounter it first in bpstat_stop_status. */
10220 if (exp_valid_block
&& frame
)
10222 if (frame_id_p (frame_unwind_caller_id (frame
)))
10225 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
10226 frame_unwind_caller_pc (frame
),
10227 bp_watchpoint_scope
,
10228 &momentary_breakpoint_ops
);
10230 scope_breakpoint
->enable_state
= bp_enabled
;
10232 /* Automatically delete the breakpoint when it hits. */
10233 scope_breakpoint
->disposition
= disp_del
;
10235 /* Only break in the proper frame (help with recursion). */
10236 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
10238 /* Set the address at which we will stop. */
10239 scope_breakpoint
->loc
->gdbarch
10240 = frame_unwind_caller_arch (frame
);
10241 scope_breakpoint
->loc
->requested_address
10242 = frame_unwind_caller_pc (frame
);
10243 scope_breakpoint
->loc
->address
10244 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10245 scope_breakpoint
->loc
->requested_address
,
10246 scope_breakpoint
->type
);
10250 /* Now set up the breakpoint. */
10252 w
= XCNEW (struct watchpoint
);
10255 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10256 &masked_watchpoint_breakpoint_ops
);
10258 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10259 &watchpoint_breakpoint_ops
);
10260 b
->thread
= thread
;
10261 b
->disposition
= disp_donttouch
;
10262 b
->pspace
= current_program_space
;
10264 w
->exp_valid_block
= exp_valid_block
;
10265 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10268 struct type
*t
= value_type (val
);
10269 CORE_ADDR addr
= value_as_address (val
);
10272 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
10273 name
= type_to_string (t
);
10275 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
10276 core_addr_to_string (addr
));
10279 w
->exp_string
= xstrprintf ("-location %.*s",
10280 (int) (exp_end
- exp_start
), exp_start
);
10282 /* The above expression is in C. */
10283 b
->language
= language_c
;
10286 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10290 w
->hw_wp_mask
= mask
;
10299 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10301 b
->cond_string
= 0;
10305 w
->watchpoint_frame
= get_frame_id (frame
);
10306 w
->watchpoint_thread
= inferior_ptid
;
10310 w
->watchpoint_frame
= null_frame_id
;
10311 w
->watchpoint_thread
= null_ptid
;
10314 if (scope_breakpoint
!= NULL
)
10316 /* The scope breakpoint is related to the watchpoint. We will
10317 need to act on them together. */
10318 b
->related_breakpoint
= scope_breakpoint
;
10319 scope_breakpoint
->related_breakpoint
= b
;
10322 if (!just_location
)
10323 value_free_to_mark (mark
);
10325 TRY_CATCH (e
, RETURN_MASK_ALL
)
10327 /* Finally update the new watchpoint. This creates the locations
10328 that should be inserted. */
10329 update_watchpoint (w
, 1);
10333 delete_breakpoint (b
);
10334 throw_exception (e
);
10337 install_breakpoint (internal
, b
, 1);
10340 /* Return count of debug registers needed to watch the given expression.
10341 If the watchpoint cannot be handled in hardware return zero. */
10344 can_use_hardware_watchpoint (struct value
*v
)
10346 int found_memory_cnt
= 0;
10347 struct value
*head
= v
;
10349 /* Did the user specifically forbid us to use hardware watchpoints? */
10350 if (!can_use_hw_watchpoints
)
10353 /* Make sure that the value of the expression depends only upon
10354 memory contents, and values computed from them within GDB. If we
10355 find any register references or function calls, we can't use a
10356 hardware watchpoint.
10358 The idea here is that evaluating an expression generates a series
10359 of values, one holding the value of every subexpression. (The
10360 expression a*b+c has five subexpressions: a, b, a*b, c, and
10361 a*b+c.) GDB's values hold almost enough information to establish
10362 the criteria given above --- they identify memory lvalues,
10363 register lvalues, computed values, etcetera. So we can evaluate
10364 the expression, and then scan the chain of values that leaves
10365 behind to decide whether we can detect any possible change to the
10366 expression's final value using only hardware watchpoints.
10368 However, I don't think that the values returned by inferior
10369 function calls are special in any way. So this function may not
10370 notice that an expression involving an inferior function call
10371 can't be watched with hardware watchpoints. FIXME. */
10372 for (; v
; v
= value_next (v
))
10374 if (VALUE_LVAL (v
) == lval_memory
)
10376 if (v
!= head
&& value_lazy (v
))
10377 /* A lazy memory lvalue in the chain is one that GDB never
10378 needed to fetch; we either just used its address (e.g.,
10379 `a' in `a.b') or we never needed it at all (e.g., `a'
10380 in `a,b'). This doesn't apply to HEAD; if that is
10381 lazy then it was not readable, but watch it anyway. */
10385 /* Ahh, memory we actually used! Check if we can cover
10386 it with hardware watchpoints. */
10387 struct type
*vtype
= check_typedef (value_type (v
));
10389 /* We only watch structs and arrays if user asked for it
10390 explicitly, never if they just happen to appear in a
10391 middle of some value chain. */
10393 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10394 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10396 CORE_ADDR vaddr
= value_address (v
);
10400 len
= (target_exact_watchpoints
10401 && is_scalar_type_recursive (vtype
))?
10402 1 : TYPE_LENGTH (value_type (v
));
10404 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10408 found_memory_cnt
+= num_regs
;
10412 else if (VALUE_LVAL (v
) != not_lval
10413 && deprecated_value_modifiable (v
) == 0)
10414 return 0; /* These are values from the history (e.g., $1). */
10415 else if (VALUE_LVAL (v
) == lval_register
)
10416 return 0; /* Cannot watch a register with a HW watchpoint. */
10419 /* The expression itself looks suitable for using a hardware
10420 watchpoint, but give the target machine a chance to reject it. */
10421 return found_memory_cnt
;
10425 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
10427 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10430 /* A helper function that looks for an argument at the start of a
10431 string. The argument must also either be at the end of the string,
10432 or be followed by whitespace. Returns 1 if it finds the argument,
10433 0 otherwise. If the argument is found, it updates *STR. */
10436 check_for_argument (char **str
, char *arg
, int arg_len
)
10438 if (strncmp (*str
, arg
, arg_len
) == 0
10439 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
10447 /* A helper function that looks for the "-location" argument and then
10448 calls watch_command_1. */
10451 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
10453 int just_location
= 0;
10456 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10457 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10459 arg
= skip_spaces (arg
);
10463 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10467 watch_command (char *arg
, int from_tty
)
10469 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10473 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10475 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10479 rwatch_command (char *arg
, int from_tty
)
10481 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10485 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10487 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10491 awatch_command (char *arg
, int from_tty
)
10493 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10497 /* Helper routines for the until_command routine in infcmd.c. Here
10498 because it uses the mechanisms of breakpoints. */
10500 struct until_break_command_continuation_args
10502 struct breakpoint
*breakpoint
;
10503 struct breakpoint
*breakpoint2
;
10507 /* This function is called by fetch_inferior_event via the
10508 cmd_continuation pointer, to complete the until command. It takes
10509 care of cleaning up the temporary breakpoints set up by the until
10512 until_break_command_continuation (void *arg
, int err
)
10514 struct until_break_command_continuation_args
*a
= arg
;
10516 delete_breakpoint (a
->breakpoint
);
10517 if (a
->breakpoint2
)
10518 delete_breakpoint (a
->breakpoint2
);
10519 delete_longjmp_breakpoint (a
->thread_num
);
10523 until_break_command (char *arg
, int from_tty
, int anywhere
)
10525 struct symtabs_and_lines sals
;
10526 struct symtab_and_line sal
;
10527 struct frame_info
*frame
= get_selected_frame (NULL
);
10528 struct gdbarch
*frame_gdbarch
= get_frame_arch (frame
);
10529 struct frame_id stack_frame_id
= get_stack_frame_id (frame
);
10530 struct frame_id caller_frame_id
= frame_unwind_caller_id (frame
);
10531 struct breakpoint
*breakpoint
;
10532 struct breakpoint
*breakpoint2
= NULL
;
10533 struct cleanup
*old_chain
;
10535 struct thread_info
*tp
;
10537 clear_proceed_status ();
10539 /* Set a breakpoint where the user wants it and at return from
10542 if (last_displayed_sal_is_valid ())
10543 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10544 get_last_displayed_symtab (),
10545 get_last_displayed_line ());
10547 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10548 (struct symtab
*) NULL
, 0);
10550 if (sals
.nelts
!= 1)
10551 error (_("Couldn't get information on specified line."));
10553 sal
= sals
.sals
[0];
10554 xfree (sals
.sals
); /* malloc'd, so freed. */
10557 error (_("Junk at end of arguments."));
10559 resolve_sal_pc (&sal
);
10561 tp
= inferior_thread ();
10564 old_chain
= make_cleanup (null_cleanup
, NULL
);
10566 /* Installing a breakpoint invalidates the frame chain (as it may
10567 need to switch threads), so do any frame handling first. */
10569 /* Keep within the current frame, or in frames called by the current
10572 if (frame_id_p (caller_frame_id
))
10574 struct symtab_and_line sal2
;
10576 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10577 sal2
.pc
= frame_unwind_caller_pc (frame
);
10578 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
10582 make_cleanup_delete_breakpoint (breakpoint2
);
10584 set_longjmp_breakpoint (tp
, caller_frame_id
);
10585 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
10588 /* set_momentary_breakpoint could invalidate FRAME. */
10592 /* If the user told us to continue until a specified location,
10593 we don't specify a frame at which we need to stop. */
10594 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
10595 null_frame_id
, bp_until
);
10597 /* Otherwise, specify the selected frame, because we want to stop
10598 only at the very same frame. */
10599 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
10600 stack_frame_id
, bp_until
);
10601 make_cleanup_delete_breakpoint (breakpoint
);
10603 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
10605 /* If we are running asynchronously, and proceed call above has
10606 actually managed to start the target, arrange for breakpoints to
10607 be deleted when the target stops. Otherwise, we're already
10608 stopped and delete breakpoints via cleanup chain. */
10610 if (target_can_async_p () && is_running (inferior_ptid
))
10612 struct until_break_command_continuation_args
*args
;
10613 args
= xmalloc (sizeof (*args
));
10615 args
->breakpoint
= breakpoint
;
10616 args
->breakpoint2
= breakpoint2
;
10617 args
->thread_num
= thread
;
10619 discard_cleanups (old_chain
);
10620 add_continuation (inferior_thread (),
10621 until_break_command_continuation
, args
,
10625 do_cleanups (old_chain
);
10628 /* This function attempts to parse an optional "if <cond>" clause
10629 from the arg string. If one is not found, it returns NULL.
10631 Else, it returns a pointer to the condition string. (It does not
10632 attempt to evaluate the string against a particular block.) And,
10633 it updates arg to point to the first character following the parsed
10634 if clause in the arg string. */
10637 ep_parse_optional_if_clause (char **arg
)
10641 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
10644 /* Skip the "if" keyword. */
10647 /* Skip any extra leading whitespace, and record the start of the
10648 condition string. */
10649 *arg
= skip_spaces (*arg
);
10650 cond_string
= *arg
;
10652 /* Assume that the condition occupies the remainder of the arg
10654 (*arg
) += strlen (cond_string
);
10656 return cond_string
;
10659 /* Commands to deal with catching events, such as signals, exceptions,
10660 process start/exit, etc. */
10664 catch_fork_temporary
, catch_vfork_temporary
,
10665 catch_fork_permanent
, catch_vfork_permanent
10670 catch_fork_command_1 (char *arg
, int from_tty
,
10671 struct cmd_list_element
*command
)
10673 struct gdbarch
*gdbarch
= get_current_arch ();
10674 char *cond_string
= NULL
;
10675 catch_fork_kind fork_kind
;
10678 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
10679 tempflag
= (fork_kind
== catch_fork_temporary
10680 || fork_kind
== catch_vfork_temporary
);
10684 arg
= skip_spaces (arg
);
10686 /* The allowed syntax is:
10688 catch [v]fork if <cond>
10690 First, check if there's an if clause. */
10691 cond_string
= ep_parse_optional_if_clause (&arg
);
10693 if ((*arg
!= '\0') && !isspace (*arg
))
10694 error (_("Junk at end of arguments."));
10696 /* If this target supports it, create a fork or vfork catchpoint
10697 and enable reporting of such events. */
10700 case catch_fork_temporary
:
10701 case catch_fork_permanent
:
10702 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
10703 &catch_fork_breakpoint_ops
);
10705 case catch_vfork_temporary
:
10706 case catch_vfork_permanent
:
10707 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
10708 &catch_vfork_breakpoint_ops
);
10711 error (_("unsupported or unknown fork kind; cannot catch it"));
10717 catch_exec_command_1 (char *arg
, int from_tty
,
10718 struct cmd_list_element
*command
)
10720 struct exec_catchpoint
*c
;
10721 struct gdbarch
*gdbarch
= get_current_arch ();
10723 char *cond_string
= NULL
;
10725 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10729 arg
= skip_spaces (arg
);
10731 /* The allowed syntax is:
10733 catch exec if <cond>
10735 First, check if there's an if clause. */
10736 cond_string
= ep_parse_optional_if_clause (&arg
);
10738 if ((*arg
!= '\0') && !isspace (*arg
))
10739 error (_("Junk at end of arguments."));
10741 c
= XNEW (struct exec_catchpoint
);
10742 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
10743 &catch_exec_breakpoint_ops
);
10744 c
->exec_pathname
= NULL
;
10746 install_breakpoint (0, &c
->base
, 1);
10749 static enum print_stop_action
10750 print_it_exception_catchpoint (bpstat bs
)
10752 struct ui_out
*uiout
= current_uiout
;
10753 struct breakpoint
*b
= bs
->breakpoint_at
;
10754 int bp_temp
, bp_throw
;
10756 annotate_catchpoint (b
->number
);
10758 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10759 if (b
->loc
->address
!= b
->loc
->requested_address
)
10760 breakpoint_adjustment_warning (b
->loc
->requested_address
,
10763 bp_temp
= b
->disposition
== disp_del
;
10764 ui_out_text (uiout
,
10765 bp_temp
? "Temporary catchpoint "
10767 if (!ui_out_is_mi_like_p (uiout
))
10768 ui_out_field_int (uiout
, "bkptno", b
->number
);
10769 ui_out_text (uiout
,
10770 bp_throw
? " (exception thrown), "
10771 : " (exception caught), ");
10772 if (ui_out_is_mi_like_p (uiout
))
10774 ui_out_field_string (uiout
, "reason",
10775 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10776 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10777 ui_out_field_int (uiout
, "bkptno", b
->number
);
10779 return PRINT_SRC_AND_LOC
;
10783 print_one_exception_catchpoint (struct breakpoint
*b
,
10784 struct bp_location
**last_loc
)
10786 struct value_print_options opts
;
10787 struct ui_out
*uiout
= current_uiout
;
10789 get_user_print_options (&opts
);
10790 if (opts
.addressprint
)
10792 annotate_field (4);
10793 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
10794 ui_out_field_string (uiout
, "addr", "<PENDING>");
10796 ui_out_field_core_addr (uiout
, "addr",
10797 b
->loc
->gdbarch
, b
->loc
->address
);
10799 annotate_field (5);
10801 *last_loc
= b
->loc
;
10802 if (strstr (b
->addr_string
, "throw") != NULL
)
10803 ui_out_field_string (uiout
, "what", "exception throw");
10805 ui_out_field_string (uiout
, "what", "exception catch");
10809 print_mention_exception_catchpoint (struct breakpoint
*b
)
10811 struct ui_out
*uiout
= current_uiout
;
10815 bp_temp
= b
->disposition
== disp_del
;
10816 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10817 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
10818 : _("Catchpoint "));
10819 ui_out_field_int (uiout
, "bkptno", b
->number
);
10820 ui_out_text (uiout
, bp_throw
? _(" (throw)")
10824 /* Implement the "print_recreate" breakpoint_ops method for throw and
10825 catch catchpoints. */
10828 print_recreate_exception_catchpoint (struct breakpoint
*b
,
10829 struct ui_file
*fp
)
10834 bp_temp
= b
->disposition
== disp_del
;
10835 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10836 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
10837 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
10838 print_recreate_thread (b
, fp
);
10841 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
10844 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
10845 enum exception_event_kind ex_event
, int from_tty
)
10847 char *trigger_func_name
;
10849 if (ex_event
== EX_EVENT_CATCH
)
10850 trigger_func_name
= "__cxa_begin_catch";
10852 trigger_func_name
= "__cxa_throw";
10854 create_breakpoint (get_current_arch (),
10855 trigger_func_name
, cond_string
, -1,
10856 0 /* condition and thread are valid. */,
10857 tempflag
, bp_breakpoint
,
10859 AUTO_BOOLEAN_TRUE
/* pending */,
10860 &gnu_v3_exception_catchpoint_ops
, from_tty
,
10868 /* Deal with "catch catch" and "catch throw" commands. */
10871 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
10872 int tempflag
, int from_tty
)
10874 char *cond_string
= NULL
;
10878 arg
= skip_spaces (arg
);
10880 cond_string
= ep_parse_optional_if_clause (&arg
);
10882 if ((*arg
!= '\0') && !isspace (*arg
))
10883 error (_("Junk at end of arguments."));
10885 if (ex_event
!= EX_EVENT_THROW
10886 && ex_event
!= EX_EVENT_CATCH
)
10887 error (_("Unsupported or unknown exception event; cannot catch it"));
10889 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
10892 warning (_("Unsupported with this platform/compiler combination."));
10895 /* Implementation of "catch catch" command. */
10898 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
10900 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10902 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
10905 /* Implementation of "catch throw" command. */
10908 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
10910 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10912 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
10916 init_ada_exception_breakpoint (struct breakpoint
*b
,
10917 struct gdbarch
*gdbarch
,
10918 struct symtab_and_line sal
,
10920 const struct breakpoint_ops
*ops
,
10926 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10928 loc_gdbarch
= gdbarch
;
10930 describe_other_breakpoints (loc_gdbarch
,
10931 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10932 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10933 version for exception catchpoints, because two catchpoints
10934 used for different exception names will use the same address.
10935 In this case, a "breakpoint ... also set at..." warning is
10936 unproductive. Besides, the warning phrasing is also a bit
10937 inappropriate, we should use the word catchpoint, and tell
10938 the user what type of catchpoint it is. The above is good
10939 enough for now, though. */
10942 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
10944 b
->enable_state
= bp_enabled
;
10945 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10946 b
->addr_string
= addr_string
;
10947 b
->language
= language_ada
;
10950 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10951 filter list, or NULL if no filtering is required. */
10953 catch_syscall_split_args (char *arg
)
10955 VEC(int) *result
= NULL
;
10956 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
10958 while (*arg
!= '\0')
10960 int i
, syscall_number
;
10962 char cur_name
[128];
10965 /* Skip whitespace. */
10966 while (isspace (*arg
))
10969 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
10970 cur_name
[i
] = arg
[i
];
10971 cur_name
[i
] = '\0';
10974 /* Check if the user provided a syscall name or a number. */
10975 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
10976 if (*endptr
== '\0')
10977 get_syscall_by_number (syscall_number
, &s
);
10980 /* We have a name. Let's check if it's valid and convert it
10982 get_syscall_by_name (cur_name
, &s
);
10984 if (s
.number
== UNKNOWN_SYSCALL
)
10985 /* Here we have to issue an error instead of a warning,
10986 because GDB cannot do anything useful if there's no
10987 syscall number to be caught. */
10988 error (_("Unknown syscall name '%s'."), cur_name
);
10991 /* Ok, it's valid. */
10992 VEC_safe_push (int, result
, s
.number
);
10995 discard_cleanups (cleanup
);
10999 /* Implement the "catch syscall" command. */
11002 catch_syscall_command_1 (char *arg
, int from_tty
,
11003 struct cmd_list_element
*command
)
11008 struct gdbarch
*gdbarch
= get_current_arch ();
11010 /* Checking if the feature if supported. */
11011 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11012 error (_("The feature 'catch syscall' is not supported on \
11013 this architecture yet."));
11015 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11017 arg
= skip_spaces (arg
);
11019 /* We need to do this first "dummy" translation in order
11020 to get the syscall XML file loaded or, most important,
11021 to display a warning to the user if there's no XML file
11022 for his/her architecture. */
11023 get_syscall_by_number (0, &s
);
11025 /* The allowed syntax is:
11027 catch syscall <name | number> [<name | number> ... <name | number>]
11029 Let's check if there's a syscall name. */
11032 filter
= catch_syscall_split_args (arg
);
11036 create_syscall_event_catchpoint (tempflag
, filter
,
11037 &catch_syscall_breakpoint_ops
);
11041 catch_command (char *arg
, int from_tty
)
11043 error (_("Catch requires an event name."));
11048 tcatch_command (char *arg
, int from_tty
)
11050 error (_("Catch requires an event name."));
11053 /* A qsort comparison function that sorts breakpoints in order. */
11056 compare_breakpoints (const void *a
, const void *b
)
11058 const breakpoint_p
*ba
= a
;
11059 uintptr_t ua
= (uintptr_t) *ba
;
11060 const breakpoint_p
*bb
= b
;
11061 uintptr_t ub
= (uintptr_t) *bb
;
11063 if ((*ba
)->number
< (*bb
)->number
)
11065 else if ((*ba
)->number
> (*bb
)->number
)
11068 /* Now sort by address, in case we see, e..g, two breakpoints with
11072 return ub
> ub
? 1 : 0;
11075 /* Delete breakpoints by address or line. */
11078 clear_command (char *arg
, int from_tty
)
11080 struct breakpoint
*b
, *prev
;
11081 VEC(breakpoint_p
) *found
= 0;
11084 struct symtabs_and_lines sals
;
11085 struct symtab_and_line sal
;
11087 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11091 sals
= decode_line_spec (arg
, (DECODE_LINE_FUNFIRSTLINE
11092 | DECODE_LINE_LIST_MODE
));
11097 sals
.sals
= (struct symtab_and_line
*)
11098 xmalloc (sizeof (struct symtab_and_line
));
11099 make_cleanup (xfree
, sals
.sals
);
11100 init_sal (&sal
); /* Initialize to zeroes. */
11102 /* Set sal's line, symtab, pc, and pspace to the values
11103 corresponding to the last call to print_frame_info. If the
11104 codepoint is not valid, this will set all the fields to 0. */
11105 get_last_displayed_sal (&sal
);
11106 if (sal
.symtab
== 0)
11107 error (_("No source file specified."));
11109 sals
.sals
[0] = sal
;
11115 /* We don't call resolve_sal_pc here. That's not as bad as it
11116 seems, because all existing breakpoints typically have both
11117 file/line and pc set. So, if clear is given file/line, we can
11118 match this to existing breakpoint without obtaining pc at all.
11120 We only support clearing given the address explicitly
11121 present in breakpoint table. Say, we've set breakpoint
11122 at file:line. There were several PC values for that file:line,
11123 due to optimization, all in one block.
11125 We've picked one PC value. If "clear" is issued with another
11126 PC corresponding to the same file:line, the breakpoint won't
11127 be cleared. We probably can still clear the breakpoint, but
11128 since the other PC value is never presented to user, user
11129 can only find it by guessing, and it does not seem important
11130 to support that. */
11132 /* For each line spec given, delete bps which correspond to it. Do
11133 it in two passes, solely to preserve the current behavior that
11134 from_tty is forced true if we delete more than one
11138 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11139 for (i
= 0; i
< sals
.nelts
; i
++)
11141 int is_abs
, sal_name_len
;
11143 /* If exact pc given, clear bpts at that pc.
11144 If line given (pc == 0), clear all bpts on specified line.
11145 If defaulting, clear all bpts on default line
11148 defaulting sal.pc != 0 tests to do
11153 1 0 <can't happen> */
11155 sal
= sals
.sals
[i
];
11156 is_abs
= sal
.symtab
== NULL
? 1 : IS_ABSOLUTE_PATH (sal
.symtab
->filename
);
11157 sal_name_len
= is_abs
? 0 : strlen (sal
.symtab
->filename
);
11159 /* Find all matching breakpoints and add them to 'found'. */
11160 ALL_BREAKPOINTS (b
)
11163 /* Are we going to delete b? */
11164 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11166 struct bp_location
*loc
= b
->loc
;
11167 for (; loc
; loc
= loc
->next
)
11169 /* If the user specified file:line, don't allow a PC
11170 match. This matches historical gdb behavior. */
11171 int pc_match
= (!sal
.explicit_line
11173 && (loc
->pspace
== sal
.pspace
)
11174 && (loc
->address
== sal
.pc
)
11175 && (!section_is_overlay (loc
->section
)
11176 || loc
->section
== sal
.section
));
11177 int line_match
= 0;
11179 if ((default_match
|| sal
.explicit_line
)
11180 && loc
->source_file
!= NULL
11181 && sal
.symtab
!= NULL
11182 && sal
.pspace
== loc
->pspace
11183 && loc
->line_number
== sal
.line
)
11185 if (filename_cmp (loc
->source_file
,
11186 sal
.symtab
->filename
) == 0)
11188 else if (!IS_ABSOLUTE_PATH (sal
.symtab
->filename
)
11189 && compare_filenames_for_search (loc
->source_file
,
11190 sal
.symtab
->filename
,
11195 if (pc_match
|| line_match
)
11204 VEC_safe_push(breakpoint_p
, found
, b
);
11208 /* Now go thru the 'found' chain and delete them. */
11209 if (VEC_empty(breakpoint_p
, found
))
11212 error (_("No breakpoint at %s."), arg
);
11214 error (_("No breakpoint at this line."));
11217 /* Remove duplicates from the vec. */
11218 qsort (VEC_address (breakpoint_p
, found
),
11219 VEC_length (breakpoint_p
, found
),
11220 sizeof (breakpoint_p
),
11221 compare_breakpoints
);
11222 prev
= VEC_index (breakpoint_p
, found
, 0);
11223 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11227 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11232 if (VEC_length(breakpoint_p
, found
) > 1)
11233 from_tty
= 1; /* Always report if deleted more than one. */
11236 if (VEC_length(breakpoint_p
, found
) == 1)
11237 printf_unfiltered (_("Deleted breakpoint "));
11239 printf_unfiltered (_("Deleted breakpoints "));
11241 breakpoints_changed ();
11243 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11246 printf_unfiltered ("%d ", b
->number
);
11247 delete_breakpoint (b
);
11250 putchar_unfiltered ('\n');
11252 do_cleanups (cleanups
);
11255 /* Delete breakpoint in BS if they are `delete' breakpoints and
11256 all breakpoints that are marked for deletion, whether hit or not.
11257 This is called after any breakpoint is hit, or after errors. */
11260 breakpoint_auto_delete (bpstat bs
)
11262 struct breakpoint
*b
, *b_tmp
;
11264 for (; bs
; bs
= bs
->next
)
11265 if (bs
->breakpoint_at
11266 && bs
->breakpoint_at
->disposition
== disp_del
11268 delete_breakpoint (bs
->breakpoint_at
);
11270 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11272 if (b
->disposition
== disp_del_at_next_stop
)
11273 delete_breakpoint (b
);
11277 /* A comparison function for bp_location AP and BP being interfaced to
11278 qsort. Sort elements primarily by their ADDRESS (no matter what
11279 does breakpoint_address_is_meaningful say for its OWNER),
11280 secondarily by ordering first bp_permanent OWNERed elements and
11281 terciarily just ensuring the array is sorted stable way despite
11282 qsort being an unstable algorithm. */
11285 bp_location_compare (const void *ap
, const void *bp
)
11287 struct bp_location
*a
= *(void **) ap
;
11288 struct bp_location
*b
= *(void **) bp
;
11289 /* A and B come from existing breakpoints having non-NULL OWNER. */
11290 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
11291 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
11293 if (a
->address
!= b
->address
)
11294 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11296 /* Sort locations at the same address by their pspace number, keeping
11297 locations of the same inferior (in a multi-inferior environment)
11300 if (a
->pspace
->num
!= b
->pspace
->num
)
11301 return ((a
->pspace
->num
> b
->pspace
->num
)
11302 - (a
->pspace
->num
< b
->pspace
->num
));
11304 /* Sort permanent breakpoints first. */
11305 if (a_perm
!= b_perm
)
11306 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
11308 /* Make the internal GDB representation stable across GDB runs
11309 where A and B memory inside GDB can differ. Breakpoint locations of
11310 the same type at the same address can be sorted in arbitrary order. */
11312 if (a
->owner
->number
!= b
->owner
->number
)
11313 return ((a
->owner
->number
> b
->owner
->number
)
11314 - (a
->owner
->number
< b
->owner
->number
));
11316 return (a
> b
) - (a
< b
);
11319 /* Set bp_location_placed_address_before_address_max and
11320 bp_location_shadow_len_after_address_max according to the current
11321 content of the bp_location array. */
11324 bp_location_target_extensions_update (void)
11326 struct bp_location
*bl
, **blp_tmp
;
11328 bp_location_placed_address_before_address_max
= 0;
11329 bp_location_shadow_len_after_address_max
= 0;
11331 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11333 CORE_ADDR start
, end
, addr
;
11335 if (!bp_location_has_shadow (bl
))
11338 start
= bl
->target_info
.placed_address
;
11339 end
= start
+ bl
->target_info
.shadow_len
;
11341 gdb_assert (bl
->address
>= start
);
11342 addr
= bl
->address
- start
;
11343 if (addr
> bp_location_placed_address_before_address_max
)
11344 bp_location_placed_address_before_address_max
= addr
;
11346 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11348 gdb_assert (bl
->address
< end
);
11349 addr
= end
- bl
->address
;
11350 if (addr
> bp_location_shadow_len_after_address_max
)
11351 bp_location_shadow_len_after_address_max
= addr
;
11355 /* Download tracepoint locations if they haven't been. */
11358 download_tracepoint_locations (void)
11360 struct bp_location
*bl
, **blp_tmp
;
11361 struct cleanup
*old_chain
;
11363 if (!target_can_download_tracepoint ())
11366 old_chain
= save_current_space_and_thread ();
11368 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11370 struct tracepoint
*t
;
11372 if (!is_tracepoint (bl
->owner
))
11375 if ((bl
->owner
->type
== bp_fast_tracepoint
11376 ? !may_insert_fast_tracepoints
11377 : !may_insert_tracepoints
))
11380 /* In tracepoint, locations are _never_ duplicated, so
11381 should_be_inserted is equivalent to
11382 unduplicated_should_be_inserted. */
11383 if (!should_be_inserted (bl
) || bl
->inserted
)
11386 switch_to_program_space_and_thread (bl
->pspace
);
11388 target_download_tracepoint (bl
);
11391 t
= (struct tracepoint
*) bl
->owner
;
11392 t
->number_on_target
= bl
->owner
->number
;
11395 do_cleanups (old_chain
);
11398 /* Swap the insertion/duplication state between two locations. */
11401 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11403 const int left_inserted
= left
->inserted
;
11404 const int left_duplicate
= left
->duplicate
;
11405 const int left_needs_update
= left
->needs_update
;
11406 const struct bp_target_info left_target_info
= left
->target_info
;
11408 /* Locations of tracepoints can never be duplicated. */
11409 if (is_tracepoint (left
->owner
))
11410 gdb_assert (!left
->duplicate
);
11411 if (is_tracepoint (right
->owner
))
11412 gdb_assert (!right
->duplicate
);
11414 left
->inserted
= right
->inserted
;
11415 left
->duplicate
= right
->duplicate
;
11416 left
->needs_update
= right
->needs_update
;
11417 left
->target_info
= right
->target_info
;
11418 right
->inserted
= left_inserted
;
11419 right
->duplicate
= left_duplicate
;
11420 right
->needs_update
= left_needs_update
;
11421 right
->target_info
= left_target_info
;
11424 /* Force the re-insertion of the locations at ADDRESS. This is called
11425 once a new/deleted/modified duplicate location is found and we are evaluating
11426 conditions on the target's side. Such conditions need to be updated on
11430 force_breakpoint_reinsertion (struct bp_location
*bl
)
11432 struct bp_location
**locp
= NULL
, **loc2p
;
11433 struct bp_location
*loc
;
11434 CORE_ADDR address
= 0;
11437 address
= bl
->address
;
11438 pspace_num
= bl
->pspace
->num
;
11440 /* This is only meaningful if the target is
11441 evaluating conditions and if the user has
11442 opted for condition evaluation on the target's
11444 if (gdb_evaluates_breakpoint_condition_p ()
11445 || !target_supports_evaluation_of_breakpoint_conditions ())
11448 /* Flag all breakpoint locations with this address and
11449 the same program space as the location
11450 as "its condition has changed". We need to
11451 update the conditions on the target's side. */
11452 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11456 if (!is_breakpoint (loc
->owner
)
11457 || pspace_num
!= loc
->pspace
->num
)
11460 /* Flag the location appropriately. We use a different state to
11461 let everyone know that we already updated the set of locations
11462 with addr bl->address and program space bl->pspace. This is so
11463 we don't have to keep calling these functions just to mark locations
11464 that have already been marked. */
11465 loc
->condition_changed
= condition_updated
;
11467 /* Free the agent expression bytecode as well. We will compute
11469 if (loc
->cond_bytecode
)
11471 free_agent_expr (loc
->cond_bytecode
);
11472 loc
->cond_bytecode
= NULL
;
11477 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11478 into the inferior, only remove already-inserted locations that no
11479 longer should be inserted. Functions that delete a breakpoint or
11480 breakpoints should pass false, so that deleting a breakpoint
11481 doesn't have the side effect of inserting the locations of other
11482 breakpoints that are marked not-inserted, but should_be_inserted
11483 returns true on them.
11485 This behaviour is useful is situations close to tear-down -- e.g.,
11486 after an exec, while the target still has execution, but breakpoint
11487 shadows of the previous executable image should *NOT* be restored
11488 to the new image; or before detaching, where the target still has
11489 execution and wants to delete breakpoints from GDB's lists, and all
11490 breakpoints had already been removed from the inferior. */
11493 update_global_location_list (int should_insert
)
11495 struct breakpoint
*b
;
11496 struct bp_location
**locp
, *loc
;
11497 struct cleanup
*cleanups
;
11498 /* Last breakpoint location address that was marked for update. */
11499 CORE_ADDR last_addr
= 0;
11500 /* Last breakpoint location program space that was marked for update. */
11501 int last_pspace_num
= -1;
11503 /* Used in the duplicates detection below. When iterating over all
11504 bp_locations, points to the first bp_location of a given address.
11505 Breakpoints and watchpoints of different types are never
11506 duplicates of each other. Keep one pointer for each type of
11507 breakpoint/watchpoint, so we only need to loop over all locations
11509 struct bp_location
*bp_loc_first
; /* breakpoint */
11510 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11511 struct bp_location
*awp_loc_first
; /* access watchpoint */
11512 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11514 /* Saved former bp_location array which we compare against the newly
11515 built bp_location from the current state of ALL_BREAKPOINTS. */
11516 struct bp_location
**old_location
, **old_locp
;
11517 unsigned old_location_count
;
11519 old_location
= bp_location
;
11520 old_location_count
= bp_location_count
;
11521 bp_location
= NULL
;
11522 bp_location_count
= 0;
11523 cleanups
= make_cleanup (xfree
, old_location
);
11525 ALL_BREAKPOINTS (b
)
11526 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11527 bp_location_count
++;
11529 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
11530 locp
= bp_location
;
11531 ALL_BREAKPOINTS (b
)
11532 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11534 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
11535 bp_location_compare
);
11537 bp_location_target_extensions_update ();
11539 /* Identify bp_location instances that are no longer present in the
11540 new list, and therefore should be freed. Note that it's not
11541 necessary that those locations should be removed from inferior --
11542 if there's another location at the same address (previously
11543 marked as duplicate), we don't need to remove/insert the
11546 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11547 and former bp_location array state respectively. */
11549 locp
= bp_location
;
11550 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
11553 struct bp_location
*old_loc
= *old_locp
;
11554 struct bp_location
**loc2p
;
11556 /* Tells if 'old_loc' is found among the new locations. If
11557 not, we have to free it. */
11558 int found_object
= 0;
11559 /* Tells if the location should remain inserted in the target. */
11560 int keep_in_target
= 0;
11563 /* Skip LOCP entries which will definitely never be needed.
11564 Stop either at or being the one matching OLD_LOC. */
11565 while (locp
< bp_location
+ bp_location_count
11566 && (*locp
)->address
< old_loc
->address
)
11570 (loc2p
< bp_location
+ bp_location_count
11571 && (*loc2p
)->address
== old_loc
->address
);
11574 /* Check if this is a new/duplicated location or a duplicated
11575 location that had its condition modified. If so, we want to send
11576 its condition to the target if evaluation of conditions is taking
11578 if ((*loc2p
)->condition_changed
== condition_modified
11579 && (last_addr
!= old_loc
->address
11580 || last_pspace_num
!= old_loc
->pspace
->num
))
11582 force_breakpoint_reinsertion (*loc2p
);
11583 last_pspace_num
= old_loc
->pspace
->num
;
11586 if (*loc2p
== old_loc
)
11590 /* We have already handled this address, update it so that we don't
11591 have to go through updates again. */
11592 last_addr
= old_loc
->address
;
11594 /* Target-side condition evaluation: Handle deleted locations. */
11596 force_breakpoint_reinsertion (old_loc
);
11598 /* If this location is no longer present, and inserted, look if
11599 there's maybe a new location at the same address. If so,
11600 mark that one inserted, and don't remove this one. This is
11601 needed so that we don't have a time window where a breakpoint
11602 at certain location is not inserted. */
11604 if (old_loc
->inserted
)
11606 /* If the location is inserted now, we might have to remove
11609 if (found_object
&& should_be_inserted (old_loc
))
11611 /* The location is still present in the location list,
11612 and still should be inserted. Don't do anything. */
11613 keep_in_target
= 1;
11617 /* This location still exists, but it won't be kept in the
11618 target since it may have been disabled. We proceed to
11619 remove its target-side condition. */
11621 /* The location is either no longer present, or got
11622 disabled. See if there's another location at the
11623 same address, in which case we don't need to remove
11624 this one from the target. */
11626 /* OLD_LOC comes from existing struct breakpoint. */
11627 if (breakpoint_address_is_meaningful (old_loc
->owner
))
11630 (loc2p
< bp_location
+ bp_location_count
11631 && (*loc2p
)->address
== old_loc
->address
);
11634 struct bp_location
*loc2
= *loc2p
;
11636 if (breakpoint_locations_match (loc2
, old_loc
))
11638 /* Read watchpoint locations are switched to
11639 access watchpoints, if the former are not
11640 supported, but the latter are. */
11641 if (is_hardware_watchpoint (old_loc
->owner
))
11643 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11644 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11647 /* loc2 is a duplicated location. We need to check
11648 if it should be inserted in case it will be
11650 if (loc2
!= old_loc
11651 && unduplicated_should_be_inserted (loc2
))
11653 swap_insertion (old_loc
, loc2
);
11654 keep_in_target
= 1;
11662 if (!keep_in_target
)
11664 if (remove_breakpoint (old_loc
, mark_uninserted
))
11666 /* This is just about all we can do. We could keep
11667 this location on the global list, and try to
11668 remove it next time, but there's no particular
11669 reason why we will succeed next time.
11671 Note that at this point, old_loc->owner is still
11672 valid, as delete_breakpoint frees the breakpoint
11673 only after calling us. */
11674 printf_filtered (_("warning: Error removing "
11675 "breakpoint %d\n"),
11676 old_loc
->owner
->number
);
11684 if (removed
&& non_stop
11685 && breakpoint_address_is_meaningful (old_loc
->owner
)
11686 && !is_hardware_watchpoint (old_loc
->owner
))
11688 /* This location was removed from the target. In
11689 non-stop mode, a race condition is possible where
11690 we've removed a breakpoint, but stop events for that
11691 breakpoint are already queued and will arrive later.
11692 We apply an heuristic to be able to distinguish such
11693 SIGTRAPs from other random SIGTRAPs: we keep this
11694 breakpoint location for a bit, and will retire it
11695 after we see some number of events. The theory here
11696 is that reporting of events should, "on the average",
11697 be fair, so after a while we'll see events from all
11698 threads that have anything of interest, and no longer
11699 need to keep this breakpoint location around. We
11700 don't hold locations forever so to reduce chances of
11701 mistaking a non-breakpoint SIGTRAP for a breakpoint
11704 The heuristic failing can be disastrous on
11705 decr_pc_after_break targets.
11707 On decr_pc_after_break targets, like e.g., x86-linux,
11708 if we fail to recognize a late breakpoint SIGTRAP,
11709 because events_till_retirement has reached 0 too
11710 soon, we'll fail to do the PC adjustment, and report
11711 a random SIGTRAP to the user. When the user resumes
11712 the inferior, it will most likely immediately crash
11713 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11714 corrupted, because of being resumed e.g., in the
11715 middle of a multi-byte instruction, or skipped a
11716 one-byte instruction. This was actually seen happen
11717 on native x86-linux, and should be less rare on
11718 targets that do not support new thread events, like
11719 remote, due to the heuristic depending on
11722 Mistaking a random SIGTRAP for a breakpoint trap
11723 causes similar symptoms (PC adjustment applied when
11724 it shouldn't), but then again, playing with SIGTRAPs
11725 behind the debugger's back is asking for trouble.
11727 Since hardware watchpoint traps are always
11728 distinguishable from other traps, so we don't need to
11729 apply keep hardware watchpoint moribund locations
11730 around. We simply always ignore hardware watchpoint
11731 traps we can no longer explain. */
11733 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
11734 old_loc
->owner
= NULL
;
11736 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
11740 old_loc
->owner
= NULL
;
11741 decref_bp_location (&old_loc
);
11746 /* Rescan breakpoints at the same address and section, marking the
11747 first one as "first" and any others as "duplicates". This is so
11748 that the bpt instruction is only inserted once. If we have a
11749 permanent breakpoint at the same place as BPT, make that one the
11750 official one, and the rest as duplicates. Permanent breakpoints
11751 are sorted first for the same address.
11753 Do the same for hardware watchpoints, but also considering the
11754 watchpoint's type (regular/access/read) and length. */
11756 bp_loc_first
= NULL
;
11757 wp_loc_first
= NULL
;
11758 awp_loc_first
= NULL
;
11759 rwp_loc_first
= NULL
;
11760 ALL_BP_LOCATIONS (loc
, locp
)
11762 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11764 struct bp_location
**loc_first_p
;
11767 if (!should_be_inserted (loc
)
11768 || !breakpoint_address_is_meaningful (b
)
11769 /* Don't detect duplicate for tracepoint locations because they are
11770 never duplicated. See the comments in field `duplicate' of
11771 `struct bp_location'. */
11772 || is_tracepoint (b
))
11774 /* Clear the condition modification flag. */
11775 loc
->condition_changed
= condition_unchanged
;
11779 /* Permanent breakpoint should always be inserted. */
11780 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
11781 internal_error (__FILE__
, __LINE__
,
11782 _("allegedly permanent breakpoint is not "
11783 "actually inserted"));
11785 if (b
->type
== bp_hardware_watchpoint
)
11786 loc_first_p
= &wp_loc_first
;
11787 else if (b
->type
== bp_read_watchpoint
)
11788 loc_first_p
= &rwp_loc_first
;
11789 else if (b
->type
== bp_access_watchpoint
)
11790 loc_first_p
= &awp_loc_first
;
11792 loc_first_p
= &bp_loc_first
;
11794 if (*loc_first_p
== NULL
11795 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11796 || !breakpoint_locations_match (loc
, *loc_first_p
))
11798 *loc_first_p
= loc
;
11799 loc
->duplicate
= 0;
11801 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11803 loc
->needs_update
= 1;
11804 /* Clear the condition modification flag. */
11805 loc
->condition_changed
= condition_unchanged
;
11811 /* This and the above ensure the invariant that the first location
11812 is not duplicated, and is the inserted one.
11813 All following are marked as duplicated, and are not inserted. */
11815 swap_insertion (loc
, *loc_first_p
);
11816 loc
->duplicate
= 1;
11818 /* Clear the condition modification flag. */
11819 loc
->condition_changed
= condition_unchanged
;
11821 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
11822 && b
->enable_state
!= bp_permanent
)
11823 internal_error (__FILE__
, __LINE__
,
11824 _("another breakpoint was inserted on top of "
11825 "a permanent breakpoint"));
11828 if (breakpoints_always_inserted_mode ()
11829 && (have_live_inferiors ()
11830 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
11833 insert_breakpoint_locations ();
11836 /* Though should_insert is false, we may need to update conditions
11837 on the target's side if it is evaluating such conditions. We
11838 only update conditions for locations that are marked
11840 update_inserted_breakpoint_locations ();
11845 download_tracepoint_locations ();
11847 do_cleanups (cleanups
);
11851 breakpoint_retire_moribund (void)
11853 struct bp_location
*loc
;
11856 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
11857 if (--(loc
->events_till_retirement
) == 0)
11859 decref_bp_location (&loc
);
11860 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
11866 update_global_location_list_nothrow (int inserting
)
11868 volatile struct gdb_exception e
;
11870 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11871 update_global_location_list (inserting
);
11874 /* Clear BKP from a BPS. */
11877 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
11881 for (bs
= bps
; bs
; bs
= bs
->next
)
11882 if (bs
->breakpoint_at
== bpt
)
11884 bs
->breakpoint_at
= NULL
;
11885 bs
->old_val
= NULL
;
11886 /* bs->commands will be freed later. */
11890 /* Callback for iterate_over_threads. */
11892 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11894 struct breakpoint
*bpt
= data
;
11896 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11900 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11904 say_where (struct breakpoint
*b
)
11906 struct ui_out
*uiout
= current_uiout
;
11907 struct value_print_options opts
;
11909 get_user_print_options (&opts
);
11911 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11913 if (b
->loc
== NULL
)
11915 printf_filtered (_(" (%s) pending."), b
->addr_string
);
11919 if (opts
.addressprint
|| b
->loc
->source_file
== NULL
)
11921 printf_filtered (" at ");
11922 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
11925 if (b
->loc
->source_file
)
11927 /* If there is a single location, we can print the location
11929 if (b
->loc
->next
== NULL
)
11930 printf_filtered (": file %s, line %d.",
11931 b
->loc
->source_file
, b
->loc
->line_number
);
11933 /* This is not ideal, but each location may have a
11934 different file name, and this at least reflects the
11935 real situation somewhat. */
11936 printf_filtered (": %s.", b
->addr_string
);
11941 struct bp_location
*loc
= b
->loc
;
11943 for (; loc
; loc
= loc
->next
)
11945 printf_filtered (" (%d locations)", n
);
11950 /* Default bp_location_ops methods. */
11953 bp_location_dtor (struct bp_location
*self
)
11955 xfree (self
->cond
);
11956 if (self
->cond_bytecode
)
11957 free_agent_expr (self
->cond_bytecode
);
11958 xfree (self
->function_name
);
11959 xfree (self
->source_file
);
11962 static const struct bp_location_ops bp_location_ops
=
11967 /* Default breakpoint_ops methods all breakpoint_ops ultimately
11971 base_breakpoint_dtor (struct breakpoint
*self
)
11973 decref_counted_command_line (&self
->commands
);
11974 xfree (self
->cond_string
);
11975 xfree (self
->addr_string
);
11976 xfree (self
->filter
);
11977 xfree (self
->addr_string_range_end
);
11980 static struct bp_location
*
11981 base_breakpoint_allocate_location (struct breakpoint
*self
)
11983 struct bp_location
*loc
;
11985 loc
= XNEW (struct bp_location
);
11986 init_bp_location (loc
, &bp_location_ops
, self
);
11991 base_breakpoint_re_set (struct breakpoint
*b
)
11993 /* Nothing to re-set. */
11996 #define internal_error_pure_virtual_called() \
11997 gdb_assert_not_reached ("pure virtual function called")
12000 base_breakpoint_insert_location (struct bp_location
*bl
)
12002 internal_error_pure_virtual_called ();
12006 base_breakpoint_remove_location (struct bp_location
*bl
)
12008 internal_error_pure_virtual_called ();
12012 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12013 struct address_space
*aspace
,
12015 const struct target_waitstatus
*ws
)
12017 internal_error_pure_virtual_called ();
12021 base_breakpoint_check_status (bpstat bs
)
12026 /* A "works_in_software_mode" breakpoint_ops method that just internal
12030 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12032 internal_error_pure_virtual_called ();
12035 /* A "resources_needed" breakpoint_ops method that just internal
12039 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12041 internal_error_pure_virtual_called ();
12044 static enum print_stop_action
12045 base_breakpoint_print_it (bpstat bs
)
12047 internal_error_pure_virtual_called ();
12051 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12052 struct ui_out
*uiout
)
12058 base_breakpoint_print_mention (struct breakpoint
*b
)
12060 internal_error_pure_virtual_called ();
12064 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12066 internal_error_pure_virtual_called ();
12070 base_breakpoint_create_sals_from_address (char **arg
,
12071 struct linespec_result
*canonical
,
12072 enum bptype type_wanted
,
12076 internal_error_pure_virtual_called ();
12080 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12081 struct linespec_result
*c
,
12082 struct linespec_sals
*lsal
,
12084 enum bptype type_wanted
,
12085 enum bpdisp disposition
,
12087 int task
, int ignore_count
,
12088 const struct breakpoint_ops
*o
,
12089 int from_tty
, int enabled
,
12090 int internal
, unsigned flags
)
12092 internal_error_pure_virtual_called ();
12096 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12097 struct symtabs_and_lines
*sals
)
12099 internal_error_pure_virtual_called ();
12102 static struct breakpoint_ops base_breakpoint_ops
=
12104 base_breakpoint_dtor
,
12105 base_breakpoint_allocate_location
,
12106 base_breakpoint_re_set
,
12107 base_breakpoint_insert_location
,
12108 base_breakpoint_remove_location
,
12109 base_breakpoint_breakpoint_hit
,
12110 base_breakpoint_check_status
,
12111 base_breakpoint_resources_needed
,
12112 base_breakpoint_works_in_software_mode
,
12113 base_breakpoint_print_it
,
12115 base_breakpoint_print_one_detail
,
12116 base_breakpoint_print_mention
,
12117 base_breakpoint_print_recreate
,
12118 base_breakpoint_create_sals_from_address
,
12119 base_breakpoint_create_breakpoints_sal
,
12120 base_breakpoint_decode_linespec
,
12123 /* Default breakpoint_ops methods. */
12126 bkpt_re_set (struct breakpoint
*b
)
12128 /* FIXME: is this still reachable? */
12129 if (b
->addr_string
== NULL
)
12131 /* Anything without a string can't be re-set. */
12132 delete_breakpoint (b
);
12136 breakpoint_re_set_default (b
);
12140 bkpt_insert_location (struct bp_location
*bl
)
12142 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12143 return target_insert_hw_breakpoint (bl
->gdbarch
,
12146 return target_insert_breakpoint (bl
->gdbarch
,
12151 bkpt_remove_location (struct bp_location
*bl
)
12153 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12154 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12156 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12160 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12161 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12162 const struct target_waitstatus
*ws
)
12164 struct breakpoint
*b
= bl
->owner
;
12166 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12167 || ws
->value
.sig
!= TARGET_SIGNAL_TRAP
)
12170 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12174 if (overlay_debugging
/* unmapped overlay section */
12175 && section_is_overlay (bl
->section
)
12176 && !section_is_mapped (bl
->section
))
12183 bkpt_resources_needed (const struct bp_location
*bl
)
12185 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12190 static enum print_stop_action
12191 bkpt_print_it (bpstat bs
)
12193 struct breakpoint
*b
;
12194 const struct bp_location
*bl
;
12196 struct ui_out
*uiout
= current_uiout
;
12198 gdb_assert (bs
->bp_location_at
!= NULL
);
12200 bl
= bs
->bp_location_at
;
12201 b
= bs
->breakpoint_at
;
12203 bp_temp
= b
->disposition
== disp_del
;
12204 if (bl
->address
!= bl
->requested_address
)
12205 breakpoint_adjustment_warning (bl
->requested_address
,
12208 annotate_breakpoint (b
->number
);
12210 ui_out_text (uiout
, "\nTemporary breakpoint ");
12212 ui_out_text (uiout
, "\nBreakpoint ");
12213 if (ui_out_is_mi_like_p (uiout
))
12215 ui_out_field_string (uiout
, "reason",
12216 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12217 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12219 ui_out_field_int (uiout
, "bkptno", b
->number
);
12220 ui_out_text (uiout
, ", ");
12222 return PRINT_SRC_AND_LOC
;
12226 bkpt_print_mention (struct breakpoint
*b
)
12228 if (ui_out_is_mi_like_p (current_uiout
))
12233 case bp_breakpoint
:
12234 case bp_gnu_ifunc_resolver
:
12235 if (b
->disposition
== disp_del
)
12236 printf_filtered (_("Temporary breakpoint"));
12238 printf_filtered (_("Breakpoint"));
12239 printf_filtered (_(" %d"), b
->number
);
12240 if (b
->type
== bp_gnu_ifunc_resolver
)
12241 printf_filtered (_(" at gnu-indirect-function resolver"));
12243 case bp_hardware_breakpoint
:
12244 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12252 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12254 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12255 fprintf_unfiltered (fp
, "tbreak");
12256 else if (tp
->type
== bp_breakpoint
)
12257 fprintf_unfiltered (fp
, "break");
12258 else if (tp
->type
== bp_hardware_breakpoint
12259 && tp
->disposition
== disp_del
)
12260 fprintf_unfiltered (fp
, "thbreak");
12261 else if (tp
->type
== bp_hardware_breakpoint
)
12262 fprintf_unfiltered (fp
, "hbreak");
12264 internal_error (__FILE__
, __LINE__
,
12265 _("unhandled breakpoint type %d"), (int) tp
->type
);
12267 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12268 print_recreate_thread (tp
, fp
);
12272 bkpt_create_sals_from_address (char **arg
,
12273 struct linespec_result
*canonical
,
12274 enum bptype type_wanted
,
12275 char *addr_start
, char **copy_arg
)
12277 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12278 addr_start
, copy_arg
);
12282 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12283 struct linespec_result
*canonical
,
12284 struct linespec_sals
*lsal
,
12286 enum bptype type_wanted
,
12287 enum bpdisp disposition
,
12289 int task
, int ignore_count
,
12290 const struct breakpoint_ops
*ops
,
12291 int from_tty
, int enabled
,
12292 int internal
, unsigned flags
)
12294 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12295 cond_string
, type_wanted
,
12296 disposition
, thread
, task
,
12297 ignore_count
, ops
, from_tty
,
12298 enabled
, internal
, flags
);
12302 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
12303 struct symtabs_and_lines
*sals
)
12305 decode_linespec_default (b
, s
, sals
);
12308 /* Virtual table for internal breakpoints. */
12311 internal_bkpt_re_set (struct breakpoint
*b
)
12315 /* Delete overlay event and longjmp master breakpoints; they
12316 will be reset later by breakpoint_re_set. */
12317 case bp_overlay_event
:
12318 case bp_longjmp_master
:
12319 case bp_std_terminate_master
:
12320 case bp_exception_master
:
12321 delete_breakpoint (b
);
12324 /* This breakpoint is special, it's set up when the inferior
12325 starts and we really don't want to touch it. */
12326 case bp_shlib_event
:
12328 /* Like bp_shlib_event, this breakpoint type is special. Once
12329 it is set up, we do not want to touch it. */
12330 case bp_thread_event
:
12336 internal_bkpt_check_status (bpstat bs
)
12338 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12340 /* If requested, stop when the dynamic linker notifies GDB of
12341 events. This allows the user to get control and place
12342 breakpoints in initializer routines for dynamically loaded
12343 objects (among other things). */
12344 bs
->stop
= stop_on_solib_events
;
12345 bs
->print
= stop_on_solib_events
;
12351 static enum print_stop_action
12352 internal_bkpt_print_it (bpstat bs
)
12354 struct ui_out
*uiout
= current_uiout
;
12355 struct breakpoint
*b
;
12357 b
= bs
->breakpoint_at
;
12361 case bp_shlib_event
:
12362 /* Did we stop because the user set the stop_on_solib_events
12363 variable? (If so, we report this as a generic, "Stopped due
12364 to shlib event" message.) */
12365 print_solib_event (0);
12368 case bp_thread_event
:
12369 /* Not sure how we will get here.
12370 GDB should not stop for these breakpoints. */
12371 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12374 case bp_overlay_event
:
12375 /* By analogy with the thread event, GDB should not stop for these. */
12376 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12379 case bp_longjmp_master
:
12380 /* These should never be enabled. */
12381 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12384 case bp_std_terminate_master
:
12385 /* These should never be enabled. */
12386 printf_filtered (_("std::terminate Master Breakpoint: "
12387 "gdb should not stop!\n"));
12390 case bp_exception_master
:
12391 /* These should never be enabled. */
12392 printf_filtered (_("Exception Master Breakpoint: "
12393 "gdb should not stop!\n"));
12397 return PRINT_NOTHING
;
12401 internal_bkpt_print_mention (struct breakpoint
*b
)
12403 /* Nothing to mention. These breakpoints are internal. */
12406 /* Virtual table for momentary breakpoints */
12409 momentary_bkpt_re_set (struct breakpoint
*b
)
12411 /* Keep temporary breakpoints, which can be encountered when we step
12412 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12413 Otherwise these should have been blown away via the cleanup chain
12414 or by breakpoint_init_inferior when we rerun the executable. */
12418 momentary_bkpt_check_status (bpstat bs
)
12420 /* Nothing. The point of these breakpoints is causing a stop. */
12423 static enum print_stop_action
12424 momentary_bkpt_print_it (bpstat bs
)
12426 struct ui_out
*uiout
= current_uiout
;
12428 if (ui_out_is_mi_like_p (uiout
))
12430 struct breakpoint
*b
= bs
->breakpoint_at
;
12435 ui_out_field_string
12437 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
12441 ui_out_field_string
12443 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
12448 return PRINT_UNKNOWN
;
12452 momentary_bkpt_print_mention (struct breakpoint
*b
)
12454 /* Nothing to mention. These breakpoints are internal. */
12457 /* The breakpoint_ops structure to be used in tracepoints. */
12460 tracepoint_re_set (struct breakpoint
*b
)
12462 breakpoint_re_set_default (b
);
12466 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12467 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12468 const struct target_waitstatus
*ws
)
12470 /* By definition, the inferior does not report stops at
12476 tracepoint_print_one_detail (const struct breakpoint
*self
,
12477 struct ui_out
*uiout
)
12479 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12480 if (tp
->static_trace_marker_id
)
12482 gdb_assert (self
->type
== bp_static_tracepoint
);
12484 ui_out_text (uiout
, "\tmarker id is ");
12485 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
12486 tp
->static_trace_marker_id
);
12487 ui_out_text (uiout
, "\n");
12492 tracepoint_print_mention (struct breakpoint
*b
)
12494 if (ui_out_is_mi_like_p (current_uiout
))
12499 case bp_tracepoint
:
12500 printf_filtered (_("Tracepoint"));
12501 printf_filtered (_(" %d"), b
->number
);
12503 case bp_fast_tracepoint
:
12504 printf_filtered (_("Fast tracepoint"));
12505 printf_filtered (_(" %d"), b
->number
);
12507 case bp_static_tracepoint
:
12508 printf_filtered (_("Static tracepoint"));
12509 printf_filtered (_(" %d"), b
->number
);
12512 internal_error (__FILE__
, __LINE__
,
12513 _("unhandled tracepoint type %d"), (int) b
->type
);
12520 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12522 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12524 if (self
->type
== bp_fast_tracepoint
)
12525 fprintf_unfiltered (fp
, "ftrace");
12526 if (self
->type
== bp_static_tracepoint
)
12527 fprintf_unfiltered (fp
, "strace");
12528 else if (self
->type
== bp_tracepoint
)
12529 fprintf_unfiltered (fp
, "trace");
12531 internal_error (__FILE__
, __LINE__
,
12532 _("unhandled tracepoint type %d"), (int) self
->type
);
12534 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
12535 print_recreate_thread (self
, fp
);
12537 if (tp
->pass_count
)
12538 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12542 tracepoint_create_sals_from_address (char **arg
,
12543 struct linespec_result
*canonical
,
12544 enum bptype type_wanted
,
12545 char *addr_start
, char **copy_arg
)
12547 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12548 addr_start
, copy_arg
);
12552 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12553 struct linespec_result
*canonical
,
12554 struct linespec_sals
*lsal
,
12556 enum bptype type_wanted
,
12557 enum bpdisp disposition
,
12559 int task
, int ignore_count
,
12560 const struct breakpoint_ops
*ops
,
12561 int from_tty
, int enabled
,
12562 int internal
, unsigned flags
)
12564 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12565 cond_string
, type_wanted
,
12566 disposition
, thread
, task
,
12567 ignore_count
, ops
, from_tty
,
12568 enabled
, internal
, flags
);
12572 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
12573 struct symtabs_and_lines
*sals
)
12575 decode_linespec_default (b
, s
, sals
);
12578 struct breakpoint_ops tracepoint_breakpoint_ops
;
12580 /* The breakpoint_ops structure to be used on static tracepoints with
12584 strace_marker_create_sals_from_address (char **arg
,
12585 struct linespec_result
*canonical
,
12586 enum bptype type_wanted
,
12587 char *addr_start
, char **copy_arg
)
12589 struct linespec_sals lsal
;
12591 lsal
.sals
= decode_static_tracepoint_spec (arg
);
12593 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
12595 canonical
->addr_string
= xstrdup (*copy_arg
);
12596 lsal
.canonical
= xstrdup (*copy_arg
);
12597 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
12601 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12602 struct linespec_result
*canonical
,
12603 struct linespec_sals
*lsal
,
12605 enum bptype type_wanted
,
12606 enum bpdisp disposition
,
12608 int task
, int ignore_count
,
12609 const struct breakpoint_ops
*ops
,
12610 int from_tty
, int enabled
,
12611 int internal
, unsigned flags
)
12615 /* If the user is creating a static tracepoint by marker id
12616 (strace -m MARKER_ID), then store the sals index, so that
12617 breakpoint_re_set can try to match up which of the newly
12618 found markers corresponds to this one, and, don't try to
12619 expand multiple locations for each sal, given than SALS
12620 already should contain all sals for MARKER_ID. */
12622 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
12624 struct symtabs_and_lines expanded
;
12625 struct tracepoint
*tp
;
12626 struct cleanup
*old_chain
;
12629 expanded
.nelts
= 1;
12630 expanded
.sals
= &lsal
->sals
.sals
[i
];
12632 addr_string
= xstrdup (canonical
->addr_string
);
12633 old_chain
= make_cleanup (xfree
, addr_string
);
12635 tp
= XCNEW (struct tracepoint
);
12636 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
12638 cond_string
, type_wanted
, disposition
,
12639 thread
, task
, ignore_count
, ops
,
12640 from_tty
, enabled
, internal
, flags
,
12641 canonical
->special_display
);
12642 /* Given that its possible to have multiple markers with
12643 the same string id, if the user is creating a static
12644 tracepoint by marker id ("strace -m MARKER_ID"), then
12645 store the sals index, so that breakpoint_re_set can
12646 try to match up which of the newly found markers
12647 corresponds to this one */
12648 tp
->static_trace_marker_id_idx
= i
;
12650 install_breakpoint (internal
, &tp
->base
, 0);
12652 discard_cleanups (old_chain
);
12657 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
12658 struct symtabs_and_lines
*sals
)
12660 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12662 *sals
= decode_static_tracepoint_spec (s
);
12663 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
12665 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
12669 error (_("marker %s not found"), tp
->static_trace_marker_id
);
12672 static struct breakpoint_ops strace_marker_breakpoint_ops
;
12675 strace_marker_p (struct breakpoint
*b
)
12677 return b
->ops
== &strace_marker_breakpoint_ops
;
12680 /* Delete a breakpoint and clean up all traces of it in the data
12684 delete_breakpoint (struct breakpoint
*bpt
)
12686 struct breakpoint
*b
;
12688 gdb_assert (bpt
!= NULL
);
12690 /* Has this bp already been deleted? This can happen because
12691 multiple lists can hold pointers to bp's. bpstat lists are
12694 One example of this happening is a watchpoint's scope bp. When
12695 the scope bp triggers, we notice that the watchpoint is out of
12696 scope, and delete it. We also delete its scope bp. But the
12697 scope bp is marked "auto-deleting", and is already on a bpstat.
12698 That bpstat is then checked for auto-deleting bp's, which are
12701 A real solution to this problem might involve reference counts in
12702 bp's, and/or giving them pointers back to their referencing
12703 bpstat's, and teaching delete_breakpoint to only free a bp's
12704 storage when no more references were extent. A cheaper bandaid
12706 if (bpt
->type
== bp_none
)
12709 /* At least avoid this stale reference until the reference counting
12710 of breakpoints gets resolved. */
12711 if (bpt
->related_breakpoint
!= bpt
)
12713 struct breakpoint
*related
;
12714 struct watchpoint
*w
;
12716 if (bpt
->type
== bp_watchpoint_scope
)
12717 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12718 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12719 w
= (struct watchpoint
*) bpt
;
12723 watchpoint_del_at_next_stop (w
);
12725 /* Unlink bpt from the bpt->related_breakpoint ring. */
12726 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12727 related
= related
->related_breakpoint
);
12728 related
->related_breakpoint
= bpt
->related_breakpoint
;
12729 bpt
->related_breakpoint
= bpt
;
12732 /* watch_command_1 creates a watchpoint but only sets its number if
12733 update_watchpoint succeeds in creating its bp_locations. If there's
12734 a problem in that process, we'll be asked to delete the half-created
12735 watchpoint. In that case, don't announce the deletion. */
12737 observer_notify_breakpoint_deleted (bpt
);
12739 if (breakpoint_chain
== bpt
)
12740 breakpoint_chain
= bpt
->next
;
12742 ALL_BREAKPOINTS (b
)
12743 if (b
->next
== bpt
)
12745 b
->next
= bpt
->next
;
12749 /* Be sure no bpstat's are pointing at the breakpoint after it's
12751 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12752 in all threads for now. Note that we cannot just remove bpstats
12753 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12754 commands are associated with the bpstat; if we remove it here,
12755 then the later call to bpstat_do_actions (&stop_bpstat); in
12756 event-top.c won't do anything, and temporary breakpoints with
12757 commands won't work. */
12759 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12761 /* Now that breakpoint is removed from breakpoint list, update the
12762 global location list. This will remove locations that used to
12763 belong to this breakpoint. Do this before freeing the breakpoint
12764 itself, since remove_breakpoint looks at location's owner. It
12765 might be better design to have location completely
12766 self-contained, but it's not the case now. */
12767 update_global_location_list (0);
12769 bpt
->ops
->dtor (bpt
);
12770 /* On the chance that someone will soon try again to delete this
12771 same bp, we mark it as deleted before freeing its storage. */
12772 bpt
->type
= bp_none
;
12777 do_delete_breakpoint_cleanup (void *b
)
12779 delete_breakpoint (b
);
12783 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
12785 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
12788 /* Iterator function to call a user-provided callback function once
12789 for each of B and its related breakpoints. */
12792 iterate_over_related_breakpoints (struct breakpoint
*b
,
12793 void (*function
) (struct breakpoint
*,
12797 struct breakpoint
*related
;
12802 struct breakpoint
*next
;
12804 /* FUNCTION may delete RELATED. */
12805 next
= related
->related_breakpoint
;
12807 if (next
== related
)
12809 /* RELATED is the last ring entry. */
12810 function (related
, data
);
12812 /* FUNCTION may have deleted it, so we'd never reach back to
12813 B. There's nothing left to do anyway, so just break
12818 function (related
, data
);
12822 while (related
!= b
);
12826 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
12828 delete_breakpoint (b
);
12831 /* A callback for map_breakpoint_numbers that calls
12832 delete_breakpoint. */
12835 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
12837 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
12841 delete_command (char *arg
, int from_tty
)
12843 struct breakpoint
*b
, *b_tmp
;
12849 int breaks_to_delete
= 0;
12851 /* Delete all breakpoints if no argument. Do not delete
12852 internal breakpoints, these have to be deleted with an
12853 explicit breakpoint number argument. */
12854 ALL_BREAKPOINTS (b
)
12855 if (user_breakpoint_p (b
))
12857 breaks_to_delete
= 1;
12861 /* Ask user only if there are some breakpoints to delete. */
12863 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12865 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12866 if (user_breakpoint_p (b
))
12867 delete_breakpoint (b
);
12871 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12875 all_locations_are_pending (struct bp_location
*loc
)
12877 for (; loc
; loc
= loc
->next
)
12878 if (!loc
->shlib_disabled
12879 && !loc
->pspace
->executing_startup
)
12884 /* Subroutine of update_breakpoint_locations to simplify it.
12885 Return non-zero if multiple fns in list LOC have the same name.
12886 Null names are ignored. */
12889 ambiguous_names_p (struct bp_location
*loc
)
12891 struct bp_location
*l
;
12892 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
12893 (int (*) (const void *,
12894 const void *)) streq
,
12895 NULL
, xcalloc
, xfree
);
12897 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12900 const char *name
= l
->function_name
;
12902 /* Allow for some names to be NULL, ignore them. */
12906 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
12908 /* NOTE: We can assume slot != NULL here because xcalloc never
12912 htab_delete (htab
);
12918 htab_delete (htab
);
12922 /* When symbols change, it probably means the sources changed as well,
12923 and it might mean the static tracepoint markers are no longer at
12924 the same address or line numbers they used to be at last we
12925 checked. Losing your static tracepoints whenever you rebuild is
12926 undesirable. This function tries to resync/rematch gdb static
12927 tracepoints with the markers on the target, for static tracepoints
12928 that have not been set by marker id. Static tracepoint that have
12929 been set by marker id are reset by marker id in breakpoint_re_set.
12932 1) For a tracepoint set at a specific address, look for a marker at
12933 the old PC. If one is found there, assume to be the same marker.
12934 If the name / string id of the marker found is different from the
12935 previous known name, assume that means the user renamed the marker
12936 in the sources, and output a warning.
12938 2) For a tracepoint set at a given line number, look for a marker
12939 at the new address of the old line number. If one is found there,
12940 assume to be the same marker. If the name / string id of the
12941 marker found is different from the previous known name, assume that
12942 means the user renamed the marker in the sources, and output a
12945 3) If a marker is no longer found at the same address or line, it
12946 may mean the marker no longer exists. But it may also just mean
12947 the code changed a bit. Maybe the user added a few lines of code
12948 that made the marker move up or down (in line number terms). Ask
12949 the target for info about the marker with the string id as we knew
12950 it. If found, update line number and address in the matching
12951 static tracepoint. This will get confused if there's more than one
12952 marker with the same ID (possible in UST, although unadvised
12953 precisely because it confuses tools). */
12955 static struct symtab_and_line
12956 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12958 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12959 struct static_tracepoint_marker marker
;
12965 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12967 if (target_static_tracepoint_marker_at (pc
, &marker
))
12969 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
12970 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12972 tp
->static_trace_marker_id
, marker
.str_id
);
12974 xfree (tp
->static_trace_marker_id
);
12975 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
12976 release_static_tracepoint_marker (&marker
);
12981 /* Old marker wasn't found on target at lineno. Try looking it up
12983 if (!sal
.explicit_pc
12985 && sal
.symtab
!= NULL
12986 && tp
->static_trace_marker_id
!= NULL
)
12988 VEC(static_tracepoint_marker_p
) *markers
;
12991 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
12993 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
12995 struct symtab_and_line sal2
;
12996 struct symbol
*sym
;
12997 struct static_tracepoint_marker
*tpmarker
;
12998 struct ui_out
*uiout
= current_uiout
;
13000 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13002 xfree (tp
->static_trace_marker_id
);
13003 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13005 warning (_("marker for static tracepoint %d (%s) not "
13006 "found at previous line number"),
13007 b
->number
, tp
->static_trace_marker_id
);
13011 sal2
.pc
= tpmarker
->address
;
13013 sal2
= find_pc_line (tpmarker
->address
, 0);
13014 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13015 ui_out_text (uiout
, "Now in ");
13018 ui_out_field_string (uiout
, "func",
13019 SYMBOL_PRINT_NAME (sym
));
13020 ui_out_text (uiout
, " at ");
13022 ui_out_field_string (uiout
, "file", sal2
.symtab
->filename
);
13023 ui_out_text (uiout
, ":");
13025 if (ui_out_is_mi_like_p (uiout
))
13027 char *fullname
= symtab_to_fullname (sal2
.symtab
);
13030 ui_out_field_string (uiout
, "fullname", fullname
);
13033 ui_out_field_int (uiout
, "line", sal2
.line
);
13034 ui_out_text (uiout
, "\n");
13036 b
->loc
->line_number
= sal2
.line
;
13038 xfree (b
->loc
->source_file
);
13040 b
->loc
->source_file
= xstrdup (sal2
.symtab
->filename
);
13042 b
->loc
->source_file
= NULL
;
13044 xfree (b
->addr_string
);
13045 b
->addr_string
= xstrprintf ("%s:%d",
13046 sal2
.symtab
->filename
,
13047 b
->loc
->line_number
);
13049 /* Might be nice to check if function changed, and warn if
13052 release_static_tracepoint_marker (tpmarker
);
13058 /* Returns 1 iff locations A and B are sufficiently same that
13059 we don't need to report breakpoint as changed. */
13062 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13066 if (a
->address
!= b
->address
)
13069 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13072 if (a
->enabled
!= b
->enabled
)
13079 if ((a
== NULL
) != (b
== NULL
))
13085 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13086 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13087 a ranged breakpoint. */
13090 update_breakpoint_locations (struct breakpoint
*b
,
13091 struct symtabs_and_lines sals
,
13092 struct symtabs_and_lines sals_end
)
13095 struct bp_location
*existing_locations
= b
->loc
;
13097 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13099 /* Ranged breakpoints have only one start location and one end
13101 b
->enable_state
= bp_disabled
;
13102 update_global_location_list (1);
13103 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13104 "multiple locations found\n"),
13109 /* If there's no new locations, and all existing locations are
13110 pending, don't do anything. This optimizes the common case where
13111 all locations are in the same shared library, that was unloaded.
13112 We'd like to retain the location, so that when the library is
13113 loaded again, we don't loose the enabled/disabled status of the
13114 individual locations. */
13115 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13120 for (i
= 0; i
< sals
.nelts
; ++i
)
13122 struct bp_location
*new_loc
;
13124 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13126 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13128 /* Reparse conditions, they might contain references to the
13130 if (b
->cond_string
!= NULL
)
13133 volatile struct gdb_exception e
;
13135 s
= b
->cond_string
;
13136 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13138 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
13143 warning (_("failed to reevaluate condition "
13144 "for breakpoint %d: %s"),
13145 b
->number
, e
.message
);
13146 new_loc
->enabled
= 0;
13150 if (sals_end
.nelts
)
13152 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
13154 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
13158 /* Update locations of permanent breakpoints. */
13159 if (b
->enable_state
== bp_permanent
)
13160 make_breakpoint_permanent (b
);
13162 /* If possible, carry over 'disable' status from existing
13165 struct bp_location
*e
= existing_locations
;
13166 /* If there are multiple breakpoints with the same function name,
13167 e.g. for inline functions, comparing function names won't work.
13168 Instead compare pc addresses; this is just a heuristic as things
13169 may have moved, but in practice it gives the correct answer
13170 often enough until a better solution is found. */
13171 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13173 for (; e
; e
= e
->next
)
13175 if (!e
->enabled
&& e
->function_name
)
13177 struct bp_location
*l
= b
->loc
;
13178 if (have_ambiguous_names
)
13180 for (; l
; l
= l
->next
)
13181 if (breakpoint_locations_match (e
, l
))
13189 for (; l
; l
= l
->next
)
13190 if (l
->function_name
13191 && strcmp (e
->function_name
, l
->function_name
) == 0)
13201 if (!locations_are_equal (existing_locations
, b
->loc
))
13202 observer_notify_breakpoint_modified (b
);
13204 update_global_location_list (1);
13207 /* Find the SaL locations corresponding to the given ADDR_STRING.
13208 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13210 static struct symtabs_and_lines
13211 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
13214 struct symtabs_and_lines sals
= {0};
13215 volatile struct gdb_exception e
;
13217 gdb_assert (b
->ops
!= NULL
);
13220 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13222 b
->ops
->decode_linespec (b
, &s
, &sals
);
13226 int not_found_and_ok
= 0;
13227 /* For pending breakpoints, it's expected that parsing will
13228 fail until the right shared library is loaded. User has
13229 already told to create pending breakpoints and don't need
13230 extra messages. If breakpoint is in bp_shlib_disabled
13231 state, then user already saw the message about that
13232 breakpoint being disabled, and don't want to see more
13234 if (e
.error
== NOT_FOUND_ERROR
13235 && (b
->condition_not_parsed
13236 || (b
->loc
&& b
->loc
->shlib_disabled
)
13237 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13238 || b
->enable_state
== bp_disabled
))
13239 not_found_and_ok
= 1;
13241 if (!not_found_and_ok
)
13243 /* We surely don't want to warn about the same breakpoint
13244 10 times. One solution, implemented here, is disable
13245 the breakpoint on error. Another solution would be to
13246 have separate 'warning emitted' flag. Since this
13247 happens only when a binary has changed, I don't know
13248 which approach is better. */
13249 b
->enable_state
= bp_disabled
;
13250 throw_exception (e
);
13254 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
13258 for (i
= 0; i
< sals
.nelts
; ++i
)
13259 resolve_sal_pc (&sals
.sals
[i
]);
13260 if (b
->condition_not_parsed
&& s
&& s
[0])
13262 char *cond_string
= 0;
13266 find_condition_and_thread (s
, sals
.sals
[0].pc
,
13267 &cond_string
, &thread
, &task
);
13269 b
->cond_string
= cond_string
;
13270 b
->thread
= thread
;
13272 b
->condition_not_parsed
= 0;
13275 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13276 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
13286 /* The default re_set method, for typical hardware or software
13287 breakpoints. Reevaluate the breakpoint and recreate its
13291 breakpoint_re_set_default (struct breakpoint
*b
)
13294 struct symtabs_and_lines sals
, sals_end
;
13295 struct symtabs_and_lines expanded
= {0};
13296 struct symtabs_and_lines expanded_end
= {0};
13298 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
13301 make_cleanup (xfree
, sals
.sals
);
13305 if (b
->addr_string_range_end
)
13307 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
13310 make_cleanup (xfree
, sals_end
.sals
);
13311 expanded_end
= sals_end
;
13315 update_breakpoint_locations (b
, expanded
, expanded_end
);
13318 /* Default method for creating SALs from an address string. It basically
13319 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13322 create_sals_from_address_default (char **arg
,
13323 struct linespec_result
*canonical
,
13324 enum bptype type_wanted
,
13325 char *addr_start
, char **copy_arg
)
13327 parse_breakpoint_sals (arg
, canonical
);
13330 /* Call create_breakpoints_sal for the given arguments. This is the default
13331 function for the `create_breakpoints_sal' method of
13335 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13336 struct linespec_result
*canonical
,
13337 struct linespec_sals
*lsal
,
13339 enum bptype type_wanted
,
13340 enum bpdisp disposition
,
13342 int task
, int ignore_count
,
13343 const struct breakpoint_ops
*ops
,
13344 int from_tty
, int enabled
,
13345 int internal
, unsigned flags
)
13347 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
13348 type_wanted
, disposition
,
13349 thread
, task
, ignore_count
, ops
, from_tty
,
13350 enabled
, internal
, flags
);
13353 /* Decode the line represented by S by calling decode_line_full. This is the
13354 default function for the `decode_linespec' method of breakpoint_ops. */
13357 decode_linespec_default (struct breakpoint
*b
, char **s
,
13358 struct symtabs_and_lines
*sals
)
13360 struct linespec_result canonical
;
13362 init_linespec_result (&canonical
);
13363 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
13364 (struct symtab
*) NULL
, 0,
13365 &canonical
, multiple_symbols_all
,
13368 /* We should get 0 or 1 resulting SALs. */
13369 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
13371 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
13373 struct linespec_sals
*lsal
;
13375 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
13376 *sals
= lsal
->sals
;
13377 /* Arrange it so the destructor does not free the
13379 lsal
->sals
.sals
= NULL
;
13382 destroy_linespec_result (&canonical
);
13385 /* Prepare the global context for a re-set of breakpoint B. */
13387 static struct cleanup
*
13388 prepare_re_set_context (struct breakpoint
*b
)
13390 struct cleanup
*cleanups
;
13392 input_radix
= b
->input_radix
;
13393 cleanups
= save_current_space_and_thread ();
13394 if (b
->pspace
!= NULL
)
13395 switch_to_program_space_and_thread (b
->pspace
);
13396 set_language (b
->language
);
13401 /* Reset a breakpoint given it's struct breakpoint * BINT.
13402 The value we return ends up being the return value from catch_errors.
13403 Unused in this case. */
13406 breakpoint_re_set_one (void *bint
)
13408 /* Get past catch_errs. */
13409 struct breakpoint
*b
= (struct breakpoint
*) bint
;
13410 struct cleanup
*cleanups
;
13412 cleanups
= prepare_re_set_context (b
);
13413 b
->ops
->re_set (b
);
13414 do_cleanups (cleanups
);
13418 /* Re-set all breakpoints after symbols have been re-loaded. */
13420 breakpoint_re_set (void)
13422 struct breakpoint
*b
, *b_tmp
;
13423 enum language save_language
;
13424 int save_input_radix
;
13425 struct cleanup
*old_chain
;
13427 save_language
= current_language
->la_language
;
13428 save_input_radix
= input_radix
;
13429 old_chain
= save_current_program_space ();
13431 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13433 /* Format possible error msg. */
13434 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
13436 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
13437 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
13438 do_cleanups (cleanups
);
13440 set_language (save_language
);
13441 input_radix
= save_input_radix
;
13443 jit_breakpoint_re_set ();
13445 do_cleanups (old_chain
);
13447 create_overlay_event_breakpoint ();
13448 create_longjmp_master_breakpoint ();
13449 create_std_terminate_master_breakpoint ();
13450 create_exception_master_breakpoint ();
13452 /* While we're at it, reset the skip list too. */
13456 /* Reset the thread number of this breakpoint:
13458 - If the breakpoint is for all threads, leave it as-is.
13459 - Else, reset it to the current thread for inferior_ptid. */
13461 breakpoint_re_set_thread (struct breakpoint
*b
)
13463 if (b
->thread
!= -1)
13465 if (in_thread_list (inferior_ptid
))
13466 b
->thread
= pid_to_thread_id (inferior_ptid
);
13468 /* We're being called after following a fork. The new fork is
13469 selected as current, and unless this was a vfork will have a
13470 different program space from the original thread. Reset that
13472 b
->loc
->pspace
= current_program_space
;
13476 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13477 If from_tty is nonzero, it prints a message to that effect,
13478 which ends with a period (no newline). */
13481 set_ignore_count (int bptnum
, int count
, int from_tty
)
13483 struct breakpoint
*b
;
13488 ALL_BREAKPOINTS (b
)
13489 if (b
->number
== bptnum
)
13491 if (is_tracepoint (b
))
13493 if (from_tty
&& count
!= 0)
13494 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13499 b
->ignore_count
= count
;
13503 printf_filtered (_("Will stop next time "
13504 "breakpoint %d is reached."),
13506 else if (count
== 1)
13507 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13510 printf_filtered (_("Will ignore next %d "
13511 "crossings of breakpoint %d."),
13514 breakpoints_changed ();
13515 observer_notify_breakpoint_modified (b
);
13519 error (_("No breakpoint number %d."), bptnum
);
13522 /* Command to set ignore-count of breakpoint N to COUNT. */
13525 ignore_command (char *args
, int from_tty
)
13531 error_no_arg (_("a breakpoint number"));
13533 num
= get_number (&p
);
13535 error (_("bad breakpoint number: '%s'"), args
);
13537 error (_("Second argument (specified ignore-count) is missing."));
13539 set_ignore_count (num
,
13540 longest_to_int (value_as_long (parse_and_eval (p
))),
13543 printf_filtered ("\n");
13546 /* Call FUNCTION on each of the breakpoints
13547 whose numbers are given in ARGS. */
13550 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
13555 struct breakpoint
*b
, *tmp
;
13557 struct get_number_or_range_state state
;
13560 error_no_arg (_("one or more breakpoint numbers"));
13562 init_number_or_range (&state
, args
);
13564 while (!state
.finished
)
13566 char *p
= state
.string
;
13570 num
= get_number_or_range (&state
);
13573 warning (_("bad breakpoint number at or near '%s'"), p
);
13577 ALL_BREAKPOINTS_SAFE (b
, tmp
)
13578 if (b
->number
== num
)
13581 function (b
, data
);
13585 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
13590 static struct bp_location
*
13591 find_location_by_number (char *number
)
13593 char *dot
= strchr (number
, '.');
13597 struct breakpoint
*b
;
13598 struct bp_location
*loc
;
13603 bp_num
= get_number (&p1
);
13605 error (_("Bad breakpoint number '%s'"), number
);
13607 ALL_BREAKPOINTS (b
)
13608 if (b
->number
== bp_num
)
13613 if (!b
|| b
->number
!= bp_num
)
13614 error (_("Bad breakpoint number '%s'"), number
);
13617 loc_num
= get_number (&p1
);
13619 error (_("Bad breakpoint location number '%s'"), number
);
13623 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
13626 error (_("Bad breakpoint location number '%s'"), dot
+1);
13632 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13633 If from_tty is nonzero, it prints a message to that effect,
13634 which ends with a period (no newline). */
13637 disable_breakpoint (struct breakpoint
*bpt
)
13639 /* Never disable a watchpoint scope breakpoint; we want to
13640 hit them when we leave scope so we can delete both the
13641 watchpoint and its scope breakpoint at that time. */
13642 if (bpt
->type
== bp_watchpoint_scope
)
13645 /* You can't disable permanent breakpoints. */
13646 if (bpt
->enable_state
== bp_permanent
)
13649 bpt
->enable_state
= bp_disabled
;
13651 /* Mark breakpoint locations modified. */
13652 mark_breakpoint_modified (bpt
);
13654 if (target_supports_enable_disable_tracepoint ()
13655 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13657 struct bp_location
*location
;
13659 for (location
= bpt
->loc
; location
; location
= location
->next
)
13660 target_disable_tracepoint (location
);
13663 update_global_location_list (0);
13665 observer_notify_breakpoint_modified (bpt
);
13668 /* A callback for iterate_over_related_breakpoints. */
13671 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
13673 disable_breakpoint (b
);
13676 /* A callback for map_breakpoint_numbers that calls
13677 disable_breakpoint. */
13680 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
13682 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
13686 disable_command (char *args
, int from_tty
)
13690 struct breakpoint
*bpt
;
13692 ALL_BREAKPOINTS (bpt
)
13693 if (user_breakpoint_p (bpt
))
13694 disable_breakpoint (bpt
);
13696 else if (strchr (args
, '.'))
13698 struct bp_location
*loc
= find_location_by_number (args
);
13704 mark_breakpoint_location_modified (loc
);
13706 if (target_supports_enable_disable_tracepoint ()
13707 && current_trace_status ()->running
&& loc
->owner
13708 && is_tracepoint (loc
->owner
))
13709 target_disable_tracepoint (loc
);
13711 update_global_location_list (0);
13714 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
13718 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13721 int target_resources_ok
;
13723 if (bpt
->type
== bp_hardware_breakpoint
)
13726 i
= hw_breakpoint_used_count ();
13727 target_resources_ok
=
13728 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13730 if (target_resources_ok
== 0)
13731 error (_("No hardware breakpoint support in the target."));
13732 else if (target_resources_ok
< 0)
13733 error (_("Hardware breakpoints used exceeds limit."));
13736 if (is_watchpoint (bpt
))
13738 /* Initialize it just to avoid a GCC false warning. */
13739 enum enable_state orig_enable_state
= 0;
13740 volatile struct gdb_exception e
;
13742 TRY_CATCH (e
, RETURN_MASK_ALL
)
13744 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13746 orig_enable_state
= bpt
->enable_state
;
13747 bpt
->enable_state
= bp_enabled
;
13748 update_watchpoint (w
, 1 /* reparse */);
13752 bpt
->enable_state
= orig_enable_state
;
13753 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13759 if (bpt
->enable_state
!= bp_permanent
)
13760 bpt
->enable_state
= bp_enabled
;
13762 bpt
->enable_state
= bp_enabled
;
13764 /* Mark breakpoint locations modified. */
13765 mark_breakpoint_modified (bpt
);
13767 if (target_supports_enable_disable_tracepoint ()
13768 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13770 struct bp_location
*location
;
13772 for (location
= bpt
->loc
; location
; location
= location
->next
)
13773 target_enable_tracepoint (location
);
13776 bpt
->disposition
= disposition
;
13777 bpt
->enable_count
= count
;
13778 update_global_location_list (1);
13779 breakpoints_changed ();
13781 observer_notify_breakpoint_modified (bpt
);
13786 enable_breakpoint (struct breakpoint
*bpt
)
13788 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13792 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
13794 enable_breakpoint (bpt
);
13797 /* A callback for map_breakpoint_numbers that calls
13798 enable_breakpoint. */
13801 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
13803 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
13806 /* The enable command enables the specified breakpoints (or all defined
13807 breakpoints) so they once again become (or continue to be) effective
13808 in stopping the inferior. */
13811 enable_command (char *args
, int from_tty
)
13815 struct breakpoint
*bpt
;
13817 ALL_BREAKPOINTS (bpt
)
13818 if (user_breakpoint_p (bpt
))
13819 enable_breakpoint (bpt
);
13821 else if (strchr (args
, '.'))
13823 struct bp_location
*loc
= find_location_by_number (args
);
13829 mark_breakpoint_location_modified (loc
);
13831 if (target_supports_enable_disable_tracepoint ()
13832 && current_trace_status ()->running
&& loc
->owner
13833 && is_tracepoint (loc
->owner
))
13834 target_enable_tracepoint (loc
);
13836 update_global_location_list (1);
13839 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
13842 /* This struct packages up disposition data for application to multiple
13852 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
13854 struct disp_data disp_data
= *(struct disp_data
*) arg
;
13856 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
13860 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
13862 struct disp_data disp
= { disp_disable
, 1 };
13864 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
13868 enable_once_command (char *args
, int from_tty
)
13870 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
13874 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
13876 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
13878 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
13882 enable_count_command (char *args
, int from_tty
)
13884 int count
= get_number (&args
);
13886 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
13890 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
13892 struct disp_data disp
= { disp_del
, 1 };
13894 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
13898 enable_delete_command (char *args
, int from_tty
)
13900 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
13904 set_breakpoint_cmd (char *args
, int from_tty
)
13909 show_breakpoint_cmd (char *args
, int from_tty
)
13913 /* Invalidate last known value of any hardware watchpoint if
13914 the memory which that value represents has been written to by
13918 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
13919 const bfd_byte
*data
)
13921 struct breakpoint
*bp
;
13923 ALL_BREAKPOINTS (bp
)
13924 if (bp
->enable_state
== bp_enabled
13925 && bp
->type
== bp_hardware_watchpoint
)
13927 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13929 if (wp
->val_valid
&& wp
->val
)
13931 struct bp_location
*loc
;
13933 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
13934 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13935 && loc
->address
+ loc
->length
> addr
13936 && addr
+ len
> loc
->address
)
13938 value_free (wp
->val
);
13946 /* Use the last displayed codepoint's values, or nothing
13947 if they aren't valid. */
13949 struct symtabs_and_lines
13950 decode_line_spec_1 (char *string
, int flags
)
13952 struct symtabs_and_lines sals
;
13955 error (_("Empty line specification."));
13956 if (last_displayed_sal_is_valid ())
13957 sals
= decode_line_1 (&string
, flags
,
13958 get_last_displayed_symtab (),
13959 get_last_displayed_line ());
13961 sals
= decode_line_1 (&string
, flags
, (struct symtab
*) NULL
, 0);
13963 error (_("Junk at end of line specification: %s"), string
);
13967 /* Create and insert a raw software breakpoint at PC. Return an
13968 identifier, which should be used to remove the breakpoint later.
13969 In general, places which call this should be using something on the
13970 breakpoint chain instead; this function should be eliminated
13974 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
13975 struct address_space
*aspace
, CORE_ADDR pc
)
13977 struct bp_target_info
*bp_tgt
;
13979 bp_tgt
= XZALLOC (struct bp_target_info
);
13981 bp_tgt
->placed_address_space
= aspace
;
13982 bp_tgt
->placed_address
= pc
;
13984 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
13986 /* Could not insert the breakpoint. */
13994 /* Remove a breakpoint BP inserted by
13995 deprecated_insert_raw_breakpoint. */
13998 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
14000 struct bp_target_info
*bp_tgt
= bp
;
14003 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
14009 /* One (or perhaps two) breakpoints used for software single
14012 static void *single_step_breakpoints
[2];
14013 static struct gdbarch
*single_step_gdbarch
[2];
14015 /* Create and insert a breakpoint for software single step. */
14018 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14019 struct address_space
*aspace
,
14024 if (single_step_breakpoints
[0] == NULL
)
14026 bpt_p
= &single_step_breakpoints
[0];
14027 single_step_gdbarch
[0] = gdbarch
;
14031 gdb_assert (single_step_breakpoints
[1] == NULL
);
14032 bpt_p
= &single_step_breakpoints
[1];
14033 single_step_gdbarch
[1] = gdbarch
;
14036 /* NOTE drow/2006-04-11: A future improvement to this function would
14037 be to only create the breakpoints once, and actually put them on
14038 the breakpoint chain. That would let us use set_raw_breakpoint.
14039 We could adjust the addresses each time they were needed. Doing
14040 this requires corresponding changes elsewhere where single step
14041 breakpoints are handled, however. So, for now, we use this. */
14043 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
14044 if (*bpt_p
== NULL
)
14045 error (_("Could not insert single-step breakpoint at %s"),
14046 paddress (gdbarch
, next_pc
));
14049 /* Check if the breakpoints used for software single stepping
14050 were inserted or not. */
14053 single_step_breakpoints_inserted (void)
14055 return (single_step_breakpoints
[0] != NULL
14056 || single_step_breakpoints
[1] != NULL
);
14059 /* Remove and delete any breakpoints used for software single step. */
14062 remove_single_step_breakpoints (void)
14064 gdb_assert (single_step_breakpoints
[0] != NULL
);
14066 /* See insert_single_step_breakpoint for more about this deprecated
14068 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
14069 single_step_breakpoints
[0]);
14070 single_step_gdbarch
[0] = NULL
;
14071 single_step_breakpoints
[0] = NULL
;
14073 if (single_step_breakpoints
[1] != NULL
)
14075 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
14076 single_step_breakpoints
[1]);
14077 single_step_gdbarch
[1] = NULL
;
14078 single_step_breakpoints
[1] = NULL
;
14082 /* Delete software single step breakpoints without removing them from
14083 the inferior. This is intended to be used if the inferior's address
14084 space where they were inserted is already gone, e.g. after exit or
14088 cancel_single_step_breakpoints (void)
14092 for (i
= 0; i
< 2; i
++)
14093 if (single_step_breakpoints
[i
])
14095 xfree (single_step_breakpoints
[i
]);
14096 single_step_breakpoints
[i
] = NULL
;
14097 single_step_gdbarch
[i
] = NULL
;
14101 /* Detach software single-step breakpoints from INFERIOR_PTID without
14105 detach_single_step_breakpoints (void)
14109 for (i
= 0; i
< 2; i
++)
14110 if (single_step_breakpoints
[i
])
14111 target_remove_breakpoint (single_step_gdbarch
[i
],
14112 single_step_breakpoints
[i
]);
14115 /* Check whether a software single-step breakpoint is inserted at
14119 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14124 for (i
= 0; i
< 2; i
++)
14126 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
14128 && breakpoint_address_match (bp_tgt
->placed_address_space
,
14129 bp_tgt
->placed_address
,
14137 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14138 non-zero otherwise. */
14140 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
14142 if (syscall_catchpoint_p (bp
)
14143 && bp
->enable_state
!= bp_disabled
14144 && bp
->enable_state
!= bp_call_disabled
)
14151 catch_syscall_enabled (void)
14153 struct catch_syscall_inferior_data
*inf_data
14154 = get_catch_syscall_inferior_data (current_inferior ());
14156 return inf_data
->total_syscalls_count
!= 0;
14160 catching_syscall_number (int syscall_number
)
14162 struct breakpoint
*bp
;
14164 ALL_BREAKPOINTS (bp
)
14165 if (is_syscall_catchpoint_enabled (bp
))
14167 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
14169 if (c
->syscalls_to_be_caught
)
14173 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
14175 if (syscall_number
== iter
)
14185 /* Complete syscall names. Used by "catch syscall". */
14187 catch_syscall_completer (struct cmd_list_element
*cmd
,
14188 char *text
, char *word
)
14190 const char **list
= get_syscall_names ();
14192 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
14198 /* Tracepoint-specific operations. */
14200 /* Set tracepoint count to NUM. */
14202 set_tracepoint_count (int num
)
14204 tracepoint_count
= num
;
14205 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14209 trace_command (char *arg
, int from_tty
)
14211 if (create_breakpoint (get_current_arch (),
14213 NULL
, 0, 1 /* parse arg */,
14215 bp_tracepoint
/* type_wanted */,
14216 0 /* Ignore count */,
14217 pending_break_support
,
14218 &tracepoint_breakpoint_ops
,
14221 0 /* internal */, 0))
14222 set_tracepoint_count (breakpoint_count
);
14226 ftrace_command (char *arg
, int from_tty
)
14228 if (create_breakpoint (get_current_arch (),
14230 NULL
, 0, 1 /* parse arg */,
14232 bp_fast_tracepoint
/* type_wanted */,
14233 0 /* Ignore count */,
14234 pending_break_support
,
14235 &tracepoint_breakpoint_ops
,
14238 0 /* internal */, 0))
14239 set_tracepoint_count (breakpoint_count
);
14242 /* strace command implementation. Creates a static tracepoint. */
14245 strace_command (char *arg
, int from_tty
)
14247 struct breakpoint_ops
*ops
;
14249 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14250 or with a normal static tracepoint. */
14251 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
14252 ops
= &strace_marker_breakpoint_ops
;
14254 ops
= &tracepoint_breakpoint_ops
;
14256 if (create_breakpoint (get_current_arch (),
14258 NULL
, 0, 1 /* parse arg */,
14260 bp_static_tracepoint
/* type_wanted */,
14261 0 /* Ignore count */,
14262 pending_break_support
,
14266 0 /* internal */, 0))
14267 set_tracepoint_count (breakpoint_count
);
14270 /* Set up a fake reader function that gets command lines from a linked
14271 list that was acquired during tracepoint uploading. */
14273 static struct uploaded_tp
*this_utp
;
14274 static int next_cmd
;
14277 read_uploaded_action (void)
14281 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14288 /* Given information about a tracepoint as recorded on a target (which
14289 can be either a live system or a trace file), attempt to create an
14290 equivalent GDB tracepoint. This is not a reliable process, since
14291 the target does not necessarily have all the information used when
14292 the tracepoint was originally defined. */
14294 struct tracepoint
*
14295 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14297 char *addr_str
, small_buf
[100];
14298 struct tracepoint
*tp
;
14300 if (utp
->at_string
)
14301 addr_str
= utp
->at_string
;
14304 /* In the absence of a source location, fall back to raw
14305 address. Since there is no way to confirm that the address
14306 means the same thing as when the trace was started, warn the
14308 warning (_("Uploaded tracepoint %d has no "
14309 "source location, using raw address"),
14311 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
14312 addr_str
= small_buf
;
14315 /* There's not much we can do with a sequence of bytecodes. */
14316 if (utp
->cond
&& !utp
->cond_string
)
14317 warning (_("Uploaded tracepoint %d condition "
14318 "has no source form, ignoring it"),
14321 if (!create_breakpoint (get_current_arch (),
14323 utp
->cond_string
, -1, 0 /* parse cond/thread */,
14325 utp
->type
/* type_wanted */,
14326 0 /* Ignore count */,
14327 pending_break_support
,
14328 &tracepoint_breakpoint_ops
,
14330 utp
->enabled
/* enabled */,
14332 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14335 set_tracepoint_count (breakpoint_count
);
14337 /* Get the tracepoint we just created. */
14338 tp
= get_tracepoint (tracepoint_count
);
14339 gdb_assert (tp
!= NULL
);
14343 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
14345 trace_pass_command (small_buf
, 0);
14348 /* If we have uploaded versions of the original commands, set up a
14349 special-purpose "reader" function and call the usual command line
14350 reader, then pass the result to the breakpoint command-setting
14352 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14354 struct command_line
*cmd_list
;
14359 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14361 breakpoint_set_commands (&tp
->base
, cmd_list
);
14363 else if (!VEC_empty (char_ptr
, utp
->actions
)
14364 || !VEC_empty (char_ptr
, utp
->step_actions
))
14365 warning (_("Uploaded tracepoint %d actions "
14366 "have no source form, ignoring them"),
14369 /* Copy any status information that might be available. */
14370 tp
->base
.hit_count
= utp
->hit_count
;
14371 tp
->traceframe_usage
= utp
->traceframe_usage
;
14376 /* Print information on tracepoint number TPNUM_EXP, or all if
14380 tracepoints_info (char *args
, int from_tty
)
14382 struct ui_out
*uiout
= current_uiout
;
14385 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14387 if (num_printed
== 0)
14389 if (args
== NULL
|| *args
== '\0')
14390 ui_out_message (uiout
, 0, "No tracepoints.\n");
14392 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
14395 default_collect_info ();
14398 /* The 'enable trace' command enables tracepoints.
14399 Not supported by all targets. */
14401 enable_trace_command (char *args
, int from_tty
)
14403 enable_command (args
, from_tty
);
14406 /* The 'disable trace' command disables tracepoints.
14407 Not supported by all targets. */
14409 disable_trace_command (char *args
, int from_tty
)
14411 disable_command (args
, from_tty
);
14414 /* Remove a tracepoint (or all if no argument). */
14416 delete_trace_command (char *arg
, int from_tty
)
14418 struct breakpoint
*b
, *b_tmp
;
14424 int breaks_to_delete
= 0;
14426 /* Delete all breakpoints if no argument.
14427 Do not delete internal or call-dummy breakpoints, these
14428 have to be deleted with an explicit breakpoint number
14430 ALL_TRACEPOINTS (b
)
14431 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14433 breaks_to_delete
= 1;
14437 /* Ask user only if there are some breakpoints to delete. */
14439 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14441 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14442 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14443 delete_breakpoint (b
);
14447 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14450 /* Helper function for trace_pass_command. */
14453 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14455 tp
->pass_count
= count
;
14456 observer_notify_tracepoint_modified (tp
->base
.number
);
14458 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14459 tp
->base
.number
, count
);
14462 /* Set passcount for tracepoint.
14464 First command argument is passcount, second is tracepoint number.
14465 If tracepoint number omitted, apply to most recently defined.
14466 Also accepts special argument "all". */
14469 trace_pass_command (char *args
, int from_tty
)
14471 struct tracepoint
*t1
;
14472 unsigned int count
;
14474 if (args
== 0 || *args
== 0)
14475 error (_("passcount command requires an "
14476 "argument (count + optional TP num)"));
14478 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
14480 while (*args
&& isspace ((int) *args
))
14483 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14485 struct breakpoint
*b
;
14487 args
+= 3; /* Skip special argument "all". */
14489 error (_("Junk at end of arguments."));
14491 ALL_TRACEPOINTS (b
)
14493 t1
= (struct tracepoint
*) b
;
14494 trace_pass_set_count (t1
, count
, from_tty
);
14497 else if (*args
== '\0')
14499 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
14501 trace_pass_set_count (t1
, count
, from_tty
);
14505 struct get_number_or_range_state state
;
14507 init_number_or_range (&state
, args
);
14508 while (!state
.finished
)
14510 t1
= get_tracepoint_by_number (&args
, &state
, 1);
14512 trace_pass_set_count (t1
, count
, from_tty
);
14517 struct tracepoint
*
14518 get_tracepoint (int num
)
14520 struct breakpoint
*t
;
14522 ALL_TRACEPOINTS (t
)
14523 if (t
->number
== num
)
14524 return (struct tracepoint
*) t
;
14529 /* Find the tracepoint with the given target-side number (which may be
14530 different from the tracepoint number after disconnecting and
14533 struct tracepoint
*
14534 get_tracepoint_by_number_on_target (int num
)
14536 struct breakpoint
*b
;
14538 ALL_TRACEPOINTS (b
)
14540 struct tracepoint
*t
= (struct tracepoint
*) b
;
14542 if (t
->number_on_target
== num
)
14549 /* Utility: parse a tracepoint number and look it up in the list.
14550 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14551 If OPTIONAL_P is true, then if the argument is missing, the most
14552 recent tracepoint (tracepoint_count) is returned. */
14553 struct tracepoint
*
14554 get_tracepoint_by_number (char **arg
,
14555 struct get_number_or_range_state
*state
,
14558 extern int tracepoint_count
;
14559 struct breakpoint
*t
;
14561 char *instring
= arg
== NULL
? NULL
: *arg
;
14565 gdb_assert (!state
->finished
);
14566 tpnum
= get_number_or_range (state
);
14568 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14571 tpnum
= tracepoint_count
;
14573 error_no_arg (_("tracepoint number"));
14576 tpnum
= get_number (arg
);
14580 if (instring
&& *instring
)
14581 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14584 printf_filtered (_("Tracepoint argument missing "
14585 "and no previous tracepoint\n"));
14589 ALL_TRACEPOINTS (t
)
14590 if (t
->number
== tpnum
)
14592 return (struct tracepoint
*) t
;
14595 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14600 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14602 if (b
->thread
!= -1)
14603 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14606 fprintf_unfiltered (fp
, " task %d", b
->task
);
14608 fprintf_unfiltered (fp
, "\n");
14611 /* Save information on user settable breakpoints (watchpoints, etc) to
14612 a new script file named FILENAME. If FILTER is non-NULL, call it
14613 on each breakpoint and only include the ones for which it returns
14617 save_breakpoints (char *filename
, int from_tty
,
14618 int (*filter
) (const struct breakpoint
*))
14620 struct breakpoint
*tp
;
14623 struct cleanup
*cleanup
;
14624 struct ui_file
*fp
;
14625 int extra_trace_bits
= 0;
14627 if (filename
== 0 || *filename
== 0)
14628 error (_("Argument required (file name in which to save)"));
14630 /* See if we have anything to save. */
14631 ALL_BREAKPOINTS (tp
)
14633 /* Skip internal and momentary breakpoints. */
14634 if (!user_breakpoint_p (tp
))
14637 /* If we have a filter, only save the breakpoints it accepts. */
14638 if (filter
&& !filter (tp
))
14643 if (is_tracepoint (tp
))
14645 extra_trace_bits
= 1;
14647 /* We can stop searching. */
14654 warning (_("Nothing to save."));
14658 pathname
= tilde_expand (filename
);
14659 cleanup
= make_cleanup (xfree
, pathname
);
14660 fp
= gdb_fopen (pathname
, "w");
14662 error (_("Unable to open file '%s' for saving (%s)"),
14663 filename
, safe_strerror (errno
));
14664 make_cleanup_ui_file_delete (fp
);
14666 if (extra_trace_bits
)
14667 save_trace_state_variables (fp
);
14669 ALL_BREAKPOINTS (tp
)
14671 /* Skip internal and momentary breakpoints. */
14672 if (!user_breakpoint_p (tp
))
14675 /* If we have a filter, only save the breakpoints it accepts. */
14676 if (filter
&& !filter (tp
))
14679 tp
->ops
->print_recreate (tp
, fp
);
14681 /* Note, we can't rely on tp->number for anything, as we can't
14682 assume the recreated breakpoint numbers will match. Use $bpnum
14685 if (tp
->cond_string
)
14686 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
14688 if (tp
->ignore_count
)
14689 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
14693 volatile struct gdb_exception ex
;
14695 fprintf_unfiltered (fp
, " commands\n");
14697 ui_out_redirect (current_uiout
, fp
);
14698 TRY_CATCH (ex
, RETURN_MASK_ALL
)
14700 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
14702 ui_out_redirect (current_uiout
, NULL
);
14705 throw_exception (ex
);
14707 fprintf_unfiltered (fp
, " end\n");
14710 if (tp
->enable_state
== bp_disabled
)
14711 fprintf_unfiltered (fp
, "disable\n");
14713 /* If this is a multi-location breakpoint, check if the locations
14714 should be individually disabled. Watchpoint locations are
14715 special, and not user visible. */
14716 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14718 struct bp_location
*loc
;
14721 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
14723 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
14727 if (extra_trace_bits
&& *default_collect
)
14728 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
14730 do_cleanups (cleanup
);
14732 printf_filtered (_("Saved to file '%s'.\n"), filename
);
14735 /* The `save breakpoints' command. */
14738 save_breakpoints_command (char *args
, int from_tty
)
14740 save_breakpoints (args
, from_tty
, NULL
);
14743 /* The `save tracepoints' command. */
14746 save_tracepoints_command (char *args
, int from_tty
)
14748 save_breakpoints (args
, from_tty
, is_tracepoint
);
14751 /* Create a vector of all tracepoints. */
14753 VEC(breakpoint_p
) *
14754 all_tracepoints (void)
14756 VEC(breakpoint_p
) *tp_vec
= 0;
14757 struct breakpoint
*tp
;
14759 ALL_TRACEPOINTS (tp
)
14761 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
14768 /* This help string is used for the break, hbreak, tbreak and thbreak
14769 commands. It is defined as a macro to prevent duplication.
14770 COMMAND should be a string constant containing the name of the
14772 #define BREAK_ARGS_HELP(command) \
14773 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
14774 LOCATION may be a line number, function name, or \"*\" and an address.\n\
14775 If a line number is specified, break at start of code for that line.\n\
14776 If a function is specified, break at start of code for that function.\n\
14777 If an address is specified, break at that exact address.\n\
14778 With no LOCATION, uses current execution address of the selected\n\
14779 stack frame. This is useful for breaking on return to a stack frame.\n\
14781 THREADNUM is the number from \"info threads\".\n\
14782 CONDITION is a boolean expression.\n\
14784 Multiple breakpoints at one place are permitted, and useful if their\n\
14785 conditions are different.\n\
14787 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14789 /* List of subcommands for "catch". */
14790 static struct cmd_list_element
*catch_cmdlist
;
14792 /* List of subcommands for "tcatch". */
14793 static struct cmd_list_element
*tcatch_cmdlist
;
14796 add_catch_command (char *name
, char *docstring
,
14797 void (*sfunc
) (char *args
, int from_tty
,
14798 struct cmd_list_element
*command
),
14799 char **(*completer
) (struct cmd_list_element
*cmd
,
14800 char *text
, char *word
),
14801 void *user_data_catch
,
14802 void *user_data_tcatch
)
14804 struct cmd_list_element
*command
;
14806 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
14808 set_cmd_sfunc (command
, sfunc
);
14809 set_cmd_context (command
, user_data_catch
);
14810 set_cmd_completer (command
, completer
);
14812 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
14814 set_cmd_sfunc (command
, sfunc
);
14815 set_cmd_context (command
, user_data_tcatch
);
14816 set_cmd_completer (command
, completer
);
14820 clear_syscall_counts (struct inferior
*inf
)
14822 struct catch_syscall_inferior_data
*inf_data
14823 = get_catch_syscall_inferior_data (inf
);
14825 inf_data
->total_syscalls_count
= 0;
14826 inf_data
->any_syscall_count
= 0;
14827 VEC_free (int, inf_data
->syscalls_counts
);
14831 save_command (char *arg
, int from_tty
)
14833 printf_unfiltered (_("\"save\" must be followed by "
14834 "the name of a save subcommand.\n"));
14835 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
14838 struct breakpoint
*
14839 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
14842 struct breakpoint
*b
, *b_tmp
;
14844 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14846 if ((*callback
) (b
, data
))
14853 /* Zero if any of the breakpoint's locations could be a location where
14854 functions have been inlined, nonzero otherwise. */
14857 is_non_inline_function (struct breakpoint
*b
)
14859 /* The shared library event breakpoint is set on the address of a
14860 non-inline function. */
14861 if (b
->type
== bp_shlib_event
)
14867 /* Nonzero if the specified PC cannot be a location where functions
14868 have been inlined. */
14871 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
14872 const struct target_waitstatus
*ws
)
14874 struct breakpoint
*b
;
14875 struct bp_location
*bl
;
14877 ALL_BREAKPOINTS (b
)
14879 if (!is_non_inline_function (b
))
14882 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
14884 if (!bl
->shlib_disabled
14885 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14894 initialize_breakpoint_ops (void)
14896 static int initialized
= 0;
14898 struct breakpoint_ops
*ops
;
14904 /* The breakpoint_ops structure to be inherit by all kinds of
14905 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14906 internal and momentary breakpoints, etc.). */
14907 ops
= &bkpt_base_breakpoint_ops
;
14908 *ops
= base_breakpoint_ops
;
14909 ops
->re_set
= bkpt_re_set
;
14910 ops
->insert_location
= bkpt_insert_location
;
14911 ops
->remove_location
= bkpt_remove_location
;
14912 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
14913 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
14914 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
14915 ops
->decode_linespec
= bkpt_decode_linespec
;
14917 /* The breakpoint_ops structure to be used in regular breakpoints. */
14918 ops
= &bkpt_breakpoint_ops
;
14919 *ops
= bkpt_base_breakpoint_ops
;
14920 ops
->re_set
= bkpt_re_set
;
14921 ops
->resources_needed
= bkpt_resources_needed
;
14922 ops
->print_it
= bkpt_print_it
;
14923 ops
->print_mention
= bkpt_print_mention
;
14924 ops
->print_recreate
= bkpt_print_recreate
;
14926 /* Ranged breakpoints. */
14927 ops
= &ranged_breakpoint_ops
;
14928 *ops
= bkpt_breakpoint_ops
;
14929 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
14930 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
14931 ops
->print_it
= print_it_ranged_breakpoint
;
14932 ops
->print_one
= print_one_ranged_breakpoint
;
14933 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
14934 ops
->print_mention
= print_mention_ranged_breakpoint
;
14935 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
14937 /* Internal breakpoints. */
14938 ops
= &internal_breakpoint_ops
;
14939 *ops
= bkpt_base_breakpoint_ops
;
14940 ops
->re_set
= internal_bkpt_re_set
;
14941 ops
->check_status
= internal_bkpt_check_status
;
14942 ops
->print_it
= internal_bkpt_print_it
;
14943 ops
->print_mention
= internal_bkpt_print_mention
;
14945 /* Momentary breakpoints. */
14946 ops
= &momentary_breakpoint_ops
;
14947 *ops
= bkpt_base_breakpoint_ops
;
14948 ops
->re_set
= momentary_bkpt_re_set
;
14949 ops
->check_status
= momentary_bkpt_check_status
;
14950 ops
->print_it
= momentary_bkpt_print_it
;
14951 ops
->print_mention
= momentary_bkpt_print_mention
;
14953 /* GNU v3 exception catchpoints. */
14954 ops
= &gnu_v3_exception_catchpoint_ops
;
14955 *ops
= bkpt_breakpoint_ops
;
14956 ops
->print_it
= print_it_exception_catchpoint
;
14957 ops
->print_one
= print_one_exception_catchpoint
;
14958 ops
->print_mention
= print_mention_exception_catchpoint
;
14959 ops
->print_recreate
= print_recreate_exception_catchpoint
;
14962 ops
= &watchpoint_breakpoint_ops
;
14963 *ops
= base_breakpoint_ops
;
14964 ops
->dtor
= dtor_watchpoint
;
14965 ops
->re_set
= re_set_watchpoint
;
14966 ops
->insert_location
= insert_watchpoint
;
14967 ops
->remove_location
= remove_watchpoint
;
14968 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
14969 ops
->check_status
= check_status_watchpoint
;
14970 ops
->resources_needed
= resources_needed_watchpoint
;
14971 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
14972 ops
->print_it
= print_it_watchpoint
;
14973 ops
->print_mention
= print_mention_watchpoint
;
14974 ops
->print_recreate
= print_recreate_watchpoint
;
14976 /* Masked watchpoints. */
14977 ops
= &masked_watchpoint_breakpoint_ops
;
14978 *ops
= watchpoint_breakpoint_ops
;
14979 ops
->insert_location
= insert_masked_watchpoint
;
14980 ops
->remove_location
= remove_masked_watchpoint
;
14981 ops
->resources_needed
= resources_needed_masked_watchpoint
;
14982 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
14983 ops
->print_it
= print_it_masked_watchpoint
;
14984 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
14985 ops
->print_mention
= print_mention_masked_watchpoint
;
14986 ops
->print_recreate
= print_recreate_masked_watchpoint
;
14989 ops
= &tracepoint_breakpoint_ops
;
14990 *ops
= base_breakpoint_ops
;
14991 ops
->re_set
= tracepoint_re_set
;
14992 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
14993 ops
->print_one_detail
= tracepoint_print_one_detail
;
14994 ops
->print_mention
= tracepoint_print_mention
;
14995 ops
->print_recreate
= tracepoint_print_recreate
;
14996 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
14997 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
14998 ops
->decode_linespec
= tracepoint_decode_linespec
;
15000 /* Static tracepoints with marker (`-m'). */
15001 ops
= &strace_marker_breakpoint_ops
;
15002 *ops
= tracepoint_breakpoint_ops
;
15003 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15004 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15005 ops
->decode_linespec
= strace_marker_decode_linespec
;
15007 /* Fork catchpoints. */
15008 ops
= &catch_fork_breakpoint_ops
;
15009 *ops
= base_breakpoint_ops
;
15010 ops
->insert_location
= insert_catch_fork
;
15011 ops
->remove_location
= remove_catch_fork
;
15012 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15013 ops
->print_it
= print_it_catch_fork
;
15014 ops
->print_one
= print_one_catch_fork
;
15015 ops
->print_mention
= print_mention_catch_fork
;
15016 ops
->print_recreate
= print_recreate_catch_fork
;
15018 /* Vfork catchpoints. */
15019 ops
= &catch_vfork_breakpoint_ops
;
15020 *ops
= base_breakpoint_ops
;
15021 ops
->insert_location
= insert_catch_vfork
;
15022 ops
->remove_location
= remove_catch_vfork
;
15023 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15024 ops
->print_it
= print_it_catch_vfork
;
15025 ops
->print_one
= print_one_catch_vfork
;
15026 ops
->print_mention
= print_mention_catch_vfork
;
15027 ops
->print_recreate
= print_recreate_catch_vfork
;
15029 /* Exec catchpoints. */
15030 ops
= &catch_exec_breakpoint_ops
;
15031 *ops
= base_breakpoint_ops
;
15032 ops
->dtor
= dtor_catch_exec
;
15033 ops
->insert_location
= insert_catch_exec
;
15034 ops
->remove_location
= remove_catch_exec
;
15035 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15036 ops
->print_it
= print_it_catch_exec
;
15037 ops
->print_one
= print_one_catch_exec
;
15038 ops
->print_mention
= print_mention_catch_exec
;
15039 ops
->print_recreate
= print_recreate_catch_exec
;
15041 /* Syscall catchpoints. */
15042 ops
= &catch_syscall_breakpoint_ops
;
15043 *ops
= base_breakpoint_ops
;
15044 ops
->dtor
= dtor_catch_syscall
;
15045 ops
->insert_location
= insert_catch_syscall
;
15046 ops
->remove_location
= remove_catch_syscall
;
15047 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
15048 ops
->print_it
= print_it_catch_syscall
;
15049 ops
->print_one
= print_one_catch_syscall
;
15050 ops
->print_mention
= print_mention_catch_syscall
;
15051 ops
->print_recreate
= print_recreate_catch_syscall
;
15053 /* Solib-related catchpoints. */
15054 ops
= &catch_solib_breakpoint_ops
;
15055 *ops
= base_breakpoint_ops
;
15056 ops
->dtor
= dtor_catch_solib
;
15057 ops
->insert_location
= insert_catch_solib
;
15058 ops
->remove_location
= remove_catch_solib
;
15059 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15060 ops
->check_status
= check_status_catch_solib
;
15061 ops
->print_it
= print_it_catch_solib
;
15062 ops
->print_one
= print_one_catch_solib
;
15063 ops
->print_mention
= print_mention_catch_solib
;
15064 ops
->print_recreate
= print_recreate_catch_solib
;
15068 _initialize_breakpoint (void)
15070 struct cmd_list_element
*c
;
15072 initialize_breakpoint_ops ();
15074 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15075 observer_attach_inferior_exit (clear_syscall_counts
);
15076 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15078 breakpoint_objfile_key
= register_objfile_data ();
15080 catch_syscall_inferior_data
15081 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup
);
15083 breakpoint_chain
= 0;
15084 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15085 before a breakpoint is set. */
15086 breakpoint_count
= 0;
15088 tracepoint_count
= 0;
15090 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15091 Set ignore-count of breakpoint number N to COUNT.\n\
15092 Usage is `ignore N COUNT'."));
15094 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
15096 add_com ("commands", class_breakpoint
, commands_command
, _("\
15097 Set commands to be executed when a breakpoint is hit.\n\
15098 Give breakpoint number as argument after \"commands\".\n\
15099 With no argument, the targeted breakpoint is the last one set.\n\
15100 The commands themselves follow starting on the next line.\n\
15101 Type a line containing \"end\" to indicate the end of them.\n\
15102 Give \"silent\" as the first line to make the breakpoint silent;\n\
15103 then no output is printed when it is hit, except what the commands print."));
15105 add_com ("condition", class_breakpoint
, condition_command
, _("\
15106 Specify breakpoint number N to break only if COND is true.\n\
15107 Usage is `condition N COND', where N is an integer and COND is an\n\
15108 expression to be evaluated whenever breakpoint N is reached."));
15110 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15111 Set a temporary breakpoint.\n\
15112 Like \"break\" except the breakpoint is only temporary,\n\
15113 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15114 by using \"enable delete\" on the breakpoint number.\n\
15116 BREAK_ARGS_HELP ("tbreak")));
15117 set_cmd_completer (c
, location_completer
);
15119 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15120 Set a hardware assisted breakpoint.\n\
15121 Like \"break\" except the breakpoint requires hardware support,\n\
15122 some target hardware may not have this support.\n\
15124 BREAK_ARGS_HELP ("hbreak")));
15125 set_cmd_completer (c
, location_completer
);
15127 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15128 Set a temporary hardware assisted breakpoint.\n\
15129 Like \"hbreak\" except the breakpoint is only temporary,\n\
15130 so it will be deleted when hit.\n\
15132 BREAK_ARGS_HELP ("thbreak")));
15133 set_cmd_completer (c
, location_completer
);
15135 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15136 Enable some breakpoints.\n\
15137 Give breakpoint numbers (separated by spaces) as arguments.\n\
15138 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15139 This is used to cancel the effect of the \"disable\" command.\n\
15140 With a subcommand you can enable temporarily."),
15141 &enablelist
, "enable ", 1, &cmdlist
);
15143 add_com ("ab", class_breakpoint
, enable_command
, _("\
15144 Enable some breakpoints.\n\
15145 Give breakpoint numbers (separated by spaces) as arguments.\n\
15146 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15147 This is used to cancel the effect of the \"disable\" command.\n\
15148 With a subcommand you can enable temporarily."));
15150 add_com_alias ("en", "enable", class_breakpoint
, 1);
15152 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15153 Enable some breakpoints.\n\
15154 Give breakpoint numbers (separated by spaces) as arguments.\n\
15155 This is used to cancel the effect of the \"disable\" command.\n\
15156 May be abbreviated to simply \"enable\".\n"),
15157 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15159 add_cmd ("once", no_class
, enable_once_command
, _("\
15160 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15161 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15164 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15165 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15166 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15169 add_cmd ("count", no_class
, enable_count_command
, _("\
15170 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15171 If a breakpoint is hit while enabled in this fashion,\n\
15172 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15175 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15176 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15177 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15180 add_cmd ("once", no_class
, enable_once_command
, _("\
15181 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15182 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15185 add_cmd ("count", no_class
, enable_count_command
, _("\
15186 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15187 If a breakpoint is hit while enabled in this fashion,\n\
15188 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15191 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15192 Disable some breakpoints.\n\
15193 Arguments are breakpoint numbers with spaces in between.\n\
15194 To disable all breakpoints, give no argument.\n\
15195 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15196 &disablelist
, "disable ", 1, &cmdlist
);
15197 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15198 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15200 add_com ("sb", class_breakpoint
, disable_command
, _("\
15201 Disable some breakpoints.\n\
15202 Arguments are breakpoint numbers with spaces in between.\n\
15203 To disable all breakpoints, give no argument.\n\
15204 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15206 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15207 Disable some breakpoints.\n\
15208 Arguments are breakpoint numbers with spaces in between.\n\
15209 To disable all breakpoints, give no argument.\n\
15210 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15211 This command may be abbreviated \"disable\"."),
15214 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15215 Delete some breakpoints or auto-display expressions.\n\
15216 Arguments are breakpoint numbers with spaces in between.\n\
15217 To delete all breakpoints, give no argument.\n\
15219 Also a prefix command for deletion of other GDB objects.\n\
15220 The \"unset\" command is also an alias for \"delete\"."),
15221 &deletelist
, "delete ", 1, &cmdlist
);
15222 add_com_alias ("d", "delete", class_breakpoint
, 1);
15223 add_com_alias ("del", "delete", class_breakpoint
, 1);
15225 add_com ("db", class_breakpoint
, delete_command
, _("\
15226 Delete some breakpoints.\n\
15227 Arguments are breakpoint numbers with spaces in between.\n\
15228 To delete all breakpoints, give no argument.\n"));
15230 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15231 Delete some breakpoints or auto-display expressions.\n\
15232 Arguments are breakpoint numbers with spaces in between.\n\
15233 To delete all breakpoints, give no argument.\n\
15234 This command may be abbreviated \"delete\"."),
15237 add_com ("clear", class_breakpoint
, clear_command
, _("\
15238 Clear breakpoint at specified line or function.\n\
15239 Argument may be line number, function name, or \"*\" and an address.\n\
15240 If line number is specified, all breakpoints in that line are cleared.\n\
15241 If function is specified, breakpoints at beginning of function are cleared.\n\
15242 If an address is specified, breakpoints at that address are cleared.\n\
15244 With no argument, clears all breakpoints in the line that the selected frame\n\
15245 is executing in.\n\
15247 See also the \"delete\" command which clears breakpoints by number."));
15248 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15250 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15251 Set breakpoint at specified line or function.\n"
15252 BREAK_ARGS_HELP ("break")));
15253 set_cmd_completer (c
, location_completer
);
15255 add_com_alias ("b", "break", class_run
, 1);
15256 add_com_alias ("br", "break", class_run
, 1);
15257 add_com_alias ("bre", "break", class_run
, 1);
15258 add_com_alias ("brea", "break", class_run
, 1);
15261 add_com_alias ("ba", "break", class_breakpoint
, 1);
15265 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15266 Break in function/address or break at a line in the current file."),
15267 &stoplist
, "stop ", 1, &cmdlist
);
15268 add_cmd ("in", class_breakpoint
, stopin_command
,
15269 _("Break in function or address."), &stoplist
);
15270 add_cmd ("at", class_breakpoint
, stopat_command
,
15271 _("Break at a line in the current file."), &stoplist
);
15272 add_com ("status", class_info
, breakpoints_info
, _("\
15273 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15274 The \"Type\" column indicates one of:\n\
15275 \tbreakpoint - normal breakpoint\n\
15276 \twatchpoint - watchpoint\n\
15277 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15278 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15279 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15280 address and file/line number respectively.\n\
15282 Convenience variable \"$_\" and default examine address for \"x\"\n\
15283 are set to the address of the last breakpoint listed unless the command\n\
15284 is prefixed with \"server \".\n\n\
15285 Convenience variable \"$bpnum\" contains the number of the last\n\
15286 breakpoint set."));
15289 add_info ("breakpoints", breakpoints_info
, _("\
15290 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15291 The \"Type\" column indicates one of:\n\
15292 \tbreakpoint - normal breakpoint\n\
15293 \twatchpoint - watchpoint\n\
15294 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15295 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15296 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15297 address and file/line number respectively.\n\
15299 Convenience variable \"$_\" and default examine address for \"x\"\n\
15300 are set to the address of the last breakpoint listed unless the command\n\
15301 is prefixed with \"server \".\n\n\
15302 Convenience variable \"$bpnum\" contains the number of the last\n\
15303 breakpoint set."));
15305 add_info_alias ("b", "breakpoints", 1);
15308 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
15309 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15310 The \"Type\" column indicates one of:\n\
15311 \tbreakpoint - normal breakpoint\n\
15312 \twatchpoint - watchpoint\n\
15313 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15314 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15315 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15316 address and file/line number respectively.\n\
15318 Convenience variable \"$_\" and default examine address for \"x\"\n\
15319 are set to the address of the last breakpoint listed unless the command\n\
15320 is prefixed with \"server \".\n\n\
15321 Convenience variable \"$bpnum\" contains the number of the last\n\
15322 breakpoint set."));
15324 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15325 Status of all breakpoints, or breakpoint number NUMBER.\n\
15326 The \"Type\" column indicates one of:\n\
15327 \tbreakpoint - normal breakpoint\n\
15328 \twatchpoint - watchpoint\n\
15329 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15330 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15331 \tuntil - internal breakpoint used by the \"until\" command\n\
15332 \tfinish - internal breakpoint used by the \"finish\" command\n\
15333 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15334 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15335 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15336 address and file/line number respectively.\n\
15338 Convenience variable \"$_\" and default examine address for \"x\"\n\
15339 are set to the address of the last breakpoint listed unless the command\n\
15340 is prefixed with \"server \".\n\n\
15341 Convenience variable \"$bpnum\" contains the number of the last\n\
15343 &maintenanceinfolist
);
15345 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15346 Set catchpoints to catch events."),
15347 &catch_cmdlist
, "catch ",
15348 0/*allow-unknown*/, &cmdlist
);
15350 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15351 Set temporary catchpoints to catch events."),
15352 &tcatch_cmdlist
, "tcatch ",
15353 0/*allow-unknown*/, &cmdlist
);
15355 /* Add catch and tcatch sub-commands. */
15356 add_catch_command ("catch", _("\
15357 Catch an exception, when caught."),
15358 catch_catch_command
,
15362 add_catch_command ("throw", _("\
15363 Catch an exception, when thrown."),
15364 catch_throw_command
,
15368 add_catch_command ("fork", _("Catch calls to fork."),
15369 catch_fork_command_1
,
15371 (void *) (uintptr_t) catch_fork_permanent
,
15372 (void *) (uintptr_t) catch_fork_temporary
);
15373 add_catch_command ("vfork", _("Catch calls to vfork."),
15374 catch_fork_command_1
,
15376 (void *) (uintptr_t) catch_vfork_permanent
,
15377 (void *) (uintptr_t) catch_vfork_temporary
);
15378 add_catch_command ("exec", _("Catch calls to exec."),
15379 catch_exec_command_1
,
15383 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15384 Usage: catch load [REGEX]\n\
15385 If REGEX is given, only stop for libraries matching the regular expression."),
15386 catch_load_command_1
,
15390 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15391 Usage: catch unload [REGEX]\n\
15392 If REGEX is given, only stop for libraries matching the regular expression."),
15393 catch_unload_command_1
,
15397 add_catch_command ("syscall", _("\
15398 Catch system calls by their names and/or numbers.\n\
15399 Arguments say which system calls to catch. If no arguments\n\
15400 are given, every system call will be caught.\n\
15401 Arguments, if given, should be one or more system call names\n\
15402 (if your system supports that), or system call numbers."),
15403 catch_syscall_command_1
,
15404 catch_syscall_completer
,
15408 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15409 Set a watchpoint for an expression.\n\
15410 Usage: watch [-l|-location] EXPRESSION\n\
15411 A watchpoint stops execution of your program whenever the value of\n\
15412 an expression changes.\n\
15413 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15414 the memory to which it refers."));
15415 set_cmd_completer (c
, expression_completer
);
15417 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15418 Set a read watchpoint for an expression.\n\
15419 Usage: rwatch [-l|-location] EXPRESSION\n\
15420 A watchpoint stops execution of your program whenever the value of\n\
15421 an expression is read.\n\
15422 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15423 the memory to which it refers."));
15424 set_cmd_completer (c
, expression_completer
);
15426 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15427 Set a watchpoint for an expression.\n\
15428 Usage: awatch [-l|-location] EXPRESSION\n\
15429 A watchpoint stops execution of your program whenever the value of\n\
15430 an expression is either read or written.\n\
15431 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15432 the memory to which it refers."));
15433 set_cmd_completer (c
, expression_completer
);
15435 add_info ("watchpoints", watchpoints_info
, _("\
15436 Status of specified watchpoints (all watchpoints if no argument)."));
15438 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15439 respond to changes - contrary to the description. */
15440 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15441 &can_use_hw_watchpoints
, _("\
15442 Set debugger's willingness to use watchpoint hardware."), _("\
15443 Show debugger's willingness to use watchpoint hardware."), _("\
15444 If zero, gdb will not use hardware for new watchpoints, even if\n\
15445 such is available. (However, any hardware watchpoints that were\n\
15446 created before setting this to nonzero, will continue to use watchpoint\n\
15449 show_can_use_hw_watchpoints
,
15450 &setlist
, &showlist
);
15452 can_use_hw_watchpoints
= 1;
15454 /* Tracepoint manipulation commands. */
15456 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15457 Set a tracepoint at specified line or function.\n\
15459 BREAK_ARGS_HELP ("trace") "\n\
15460 Do \"help tracepoints\" for info on other tracepoint commands."));
15461 set_cmd_completer (c
, location_completer
);
15463 add_com_alias ("tp", "trace", class_alias
, 0);
15464 add_com_alias ("tr", "trace", class_alias
, 1);
15465 add_com_alias ("tra", "trace", class_alias
, 1);
15466 add_com_alias ("trac", "trace", class_alias
, 1);
15468 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15469 Set a fast tracepoint at specified line or function.\n\
15471 BREAK_ARGS_HELP ("ftrace") "\n\
15472 Do \"help tracepoints\" for info on other tracepoint commands."));
15473 set_cmd_completer (c
, location_completer
);
15475 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15476 Set a static tracepoint at specified line, function or marker.\n\
15478 strace [LOCATION] [if CONDITION]\n\
15479 LOCATION may be a line number, function name, \"*\" and an address,\n\
15480 or -m MARKER_ID.\n\
15481 If a line number is specified, probe the marker at start of code\n\
15482 for that line. If a function is specified, probe the marker at start\n\
15483 of code for that function. If an address is specified, probe the marker\n\
15484 at that exact address. If a marker id is specified, probe the marker\n\
15485 with that name. With no LOCATION, uses current execution address of\n\
15486 the selected stack frame.\n\
15487 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15488 This collects arbitrary user data passed in the probe point call to the\n\
15489 tracing library. You can inspect it when analyzing the trace buffer,\n\
15490 by printing the $_sdata variable like any other convenience variable.\n\
15492 CONDITION is a boolean expression.\n\
15494 Multiple tracepoints at one place are permitted, and useful if their\n\
15495 conditions are different.\n\
15497 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15498 Do \"help tracepoints\" for info on other tracepoint commands."));
15499 set_cmd_completer (c
, location_completer
);
15501 add_info ("tracepoints", tracepoints_info
, _("\
15502 Status of specified tracepoints (all tracepoints if no argument).\n\
15503 Convenience variable \"$tpnum\" contains the number of the\n\
15504 last tracepoint set."));
15506 add_info_alias ("tp", "tracepoints", 1);
15508 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15509 Delete specified tracepoints.\n\
15510 Arguments are tracepoint numbers, separated by spaces.\n\
15511 No argument means delete all tracepoints."),
15514 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15515 Disable specified tracepoints.\n\
15516 Arguments are tracepoint numbers, separated by spaces.\n\
15517 No argument means disable all tracepoints."),
15519 deprecate_cmd (c
, "disable");
15521 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15522 Enable specified tracepoints.\n\
15523 Arguments are tracepoint numbers, separated by spaces.\n\
15524 No argument means enable all tracepoints."),
15526 deprecate_cmd (c
, "enable");
15528 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15529 Set the passcount for a tracepoint.\n\
15530 The trace will end when the tracepoint has been passed 'count' times.\n\
15531 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15532 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15534 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15535 _("Save breakpoint definitions as a script."),
15536 &save_cmdlist
, "save ",
15537 0/*allow-unknown*/, &cmdlist
);
15539 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15540 Save current breakpoint definitions as a script.\n\
15541 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15542 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15543 session to restore them."),
15545 set_cmd_completer (c
, filename_completer
);
15547 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15548 Save current tracepoint definitions as a script.\n\
15549 Use the 'source' command in another debug session to restore them."),
15551 set_cmd_completer (c
, filename_completer
);
15553 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15554 deprecate_cmd (c
, "save tracepoints");
15556 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15557 Breakpoint specific settings\n\
15558 Configure various breakpoint-specific variables such as\n\
15559 pending breakpoint behavior"),
15560 &breakpoint_set_cmdlist
, "set breakpoint ",
15561 0/*allow-unknown*/, &setlist
);
15562 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15563 Breakpoint specific settings\n\
15564 Configure various breakpoint-specific variables such as\n\
15565 pending breakpoint behavior"),
15566 &breakpoint_show_cmdlist
, "show breakpoint ",
15567 0/*allow-unknown*/, &showlist
);
15569 add_setshow_auto_boolean_cmd ("pending", no_class
,
15570 &pending_break_support
, _("\
15571 Set debugger's behavior regarding pending breakpoints."), _("\
15572 Show debugger's behavior regarding pending breakpoints."), _("\
15573 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15574 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15575 an error. If auto, an unrecognized breakpoint location results in a\n\
15576 user-query to see if a pending breakpoint should be created."),
15578 show_pending_break_support
,
15579 &breakpoint_set_cmdlist
,
15580 &breakpoint_show_cmdlist
);
15582 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15584 add_setshow_boolean_cmd ("auto-hw", no_class
,
15585 &automatic_hardware_breakpoints
, _("\
15586 Set automatic usage of hardware breakpoints."), _("\
15587 Show automatic usage of hardware breakpoints."), _("\
15588 If set, the debugger will automatically use hardware breakpoints for\n\
15589 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15590 a warning will be emitted for such breakpoints."),
15592 show_automatic_hardware_breakpoints
,
15593 &breakpoint_set_cmdlist
,
15594 &breakpoint_show_cmdlist
);
15596 add_setshow_enum_cmd ("always-inserted", class_support
,
15597 always_inserted_enums
, &always_inserted_mode
, _("\
15598 Set mode for inserting breakpoints."), _("\
15599 Show mode for inserting breakpoints."), _("\
15600 When this mode is off, breakpoints are inserted in inferior when it is\n\
15601 resumed, and removed when execution stops. When this mode is on,\n\
15602 breakpoints are inserted immediately and removed only when the user\n\
15603 deletes the breakpoint. When this mode is auto (which is the default),\n\
15604 the behaviour depends on the non-stop setting (see help set non-stop).\n\
15605 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
15606 behaves as if always-inserted mode is on; if gdb is controlling the\n\
15607 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
15609 &show_always_inserted_mode
,
15610 &breakpoint_set_cmdlist
,
15611 &breakpoint_show_cmdlist
);
15613 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15614 condition_evaluation_enums
,
15615 &condition_evaluation_mode_1
, _("\
15616 Set mode of breakpoint condition evaluation."), _("\
15617 Show mode of breakpoint condition evaluation."), _("\
15618 When this is set to \"host\", breakpoint conditions will be\n\
15619 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15620 breakpoint conditions will be downloaded to the target (if the target\n\
15621 supports such feature) and conditions will be evaluated on the target's side.\n\
15622 If this is set to \"auto\" (default), this will be automatically set to\n\
15623 \"target\" if it supports condition evaluation, otherwise it will\n\
15624 be set to \"gdb\""),
15625 &set_condition_evaluation_mode
,
15626 &show_condition_evaluation_mode
,
15627 &breakpoint_set_cmdlist
,
15628 &breakpoint_show_cmdlist
);
15630 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15631 Set a breakpoint for an address range.\n\
15632 break-range START-LOCATION, END-LOCATION\n\
15633 where START-LOCATION and END-LOCATION can be one of the following:\n\
15634 LINENUM, for that line in the current file,\n\
15635 FILE:LINENUM, for that line in that file,\n\
15636 +OFFSET, for that number of lines after the current line\n\
15637 or the start of the range\n\
15638 FUNCTION, for the first line in that function,\n\
15639 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15640 *ADDRESS, for the instruction at that address.\n\
15642 The breakpoint will stop execution of the inferior whenever it executes\n\
15643 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15644 range (including START-LOCATION and END-LOCATION)."));
15646 automatic_hardware_breakpoints
= 1;
15648 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);