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 "gdb_regex.h"
65 #include "cli/cli-utils.h"
66 #include "continuations.h"
69 #include "gdb_regex.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "python/python.h"
82 /* Prototypes for local functions. */
84 static void enable_delete_command (char *, int);
86 static void enable_once_command (char *, int);
88 static void enable_count_command (char *, int);
90 static void disable_command (char *, int);
92 static void enable_command (char *, int);
94 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
98 static void ignore_command (char *, int);
100 static int breakpoint_re_set_one (void *);
102 static void breakpoint_re_set_default (struct breakpoint
*);
104 static void create_sals_from_address_default (char **,
105 struct linespec_result
*,
109 static void create_breakpoints_sal_default (struct gdbarch
*,
110 struct linespec_result
*,
111 struct linespec_sals
*,
113 enum bpdisp
, int, int,
115 const struct breakpoint_ops
*,
116 int, int, int, unsigned);
118 static void decode_linespec_default (struct breakpoint
*, char **,
119 struct symtabs_and_lines
*);
121 static void clear_command (char *, int);
123 static void catch_command (char *, int);
125 static int can_use_hardware_watchpoint (struct value
*);
127 static void break_command_1 (char *, int, int);
129 static void mention (struct breakpoint
*);
131 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
133 const struct breakpoint_ops
*);
134 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
135 const struct symtab_and_line
*);
137 /* This function is used in gdbtk sources and thus can not be made
139 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
140 struct symtab_and_line
,
142 const struct breakpoint_ops
*);
144 static struct breakpoint
*
145 momentary_breakpoint_from_master (struct breakpoint
*orig
,
147 const struct breakpoint_ops
*ops
);
149 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
151 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
155 static void describe_other_breakpoints (struct gdbarch
*,
156 struct program_space
*, CORE_ADDR
,
157 struct obj_section
*, int);
159 static int breakpoint_address_match (struct address_space
*aspace1
,
161 struct address_space
*aspace2
,
164 static int watchpoint_locations_match (struct bp_location
*loc1
,
165 struct bp_location
*loc2
);
167 static int breakpoint_location_address_match (struct bp_location
*bl
,
168 struct address_space
*aspace
,
171 static void breakpoints_info (char *, int);
173 static void watchpoints_info (char *, int);
175 static int breakpoint_1 (char *, int,
176 int (*) (const struct breakpoint
*));
178 static int breakpoint_cond_eval (void *);
180 static void cleanup_executing_breakpoints (void *);
182 static void commands_command (char *, int);
184 static void condition_command (char *, int);
193 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
194 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
196 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
198 static int watchpoint_check (void *);
200 static void maintenance_info_breakpoints (char *, int);
202 static int hw_breakpoint_used_count (void);
204 static int hw_watchpoint_use_count (struct breakpoint
*);
206 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
208 int *other_type_used
);
210 static void hbreak_command (char *, int);
212 static void thbreak_command (char *, int);
214 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
217 static void stop_command (char *arg
, int from_tty
);
219 static void stopin_command (char *arg
, int from_tty
);
221 static void stopat_command (char *arg
, int from_tty
);
223 static char *ep_parse_optional_if_clause (char **arg
);
225 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
226 char *arg
, int tempflag
, int from_tty
);
228 static void tcatch_command (char *arg
, int from_tty
);
230 static void detach_single_step_breakpoints (void);
232 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
235 static void free_bp_location (struct bp_location
*loc
);
236 static void incref_bp_location (struct bp_location
*loc
);
237 static void decref_bp_location (struct bp_location
**loc
);
239 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
241 static void update_global_location_list (int);
243 static void update_global_location_list_nothrow (int);
245 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
247 static void insert_breakpoint_locations (void);
249 static int syscall_catchpoint_p (struct breakpoint
*b
);
251 static void tracepoints_info (char *, int);
253 static void delete_trace_command (char *, int);
255 static void enable_trace_command (char *, int);
257 static void disable_trace_command (char *, int);
259 static void trace_pass_command (char *, int);
261 static int is_masked_watchpoint (const struct breakpoint
*b
);
263 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
265 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
268 static int strace_marker_p (struct breakpoint
*b
);
270 static void init_catchpoint (struct breakpoint
*b
,
271 struct gdbarch
*gdbarch
, int tempflag
,
273 const struct breakpoint_ops
*ops
);
275 /* The abstract base class all breakpoint_ops structures inherit
277 static struct breakpoint_ops base_breakpoint_ops
;
279 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
280 that are implemented on top of software or hardware breakpoints
281 (user breakpoints, internal and momentary breakpoints, etc.). */
282 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
284 /* Internal breakpoints class type. */
285 static struct breakpoint_ops internal_breakpoint_ops
;
287 /* Momentary breakpoints class type. */
288 static struct breakpoint_ops momentary_breakpoint_ops
;
290 /* The breakpoint_ops structure to be used in regular user created
292 struct breakpoint_ops bkpt_breakpoint_ops
;
294 /* Breakpoints set on probes. */
295 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
297 /* A reference-counted struct command_line. This lets multiple
298 breakpoints share a single command list. */
299 struct counted_command_line
301 /* The reference count. */
304 /* The command list. */
305 struct command_line
*commands
;
308 struct command_line
*
309 breakpoint_commands (struct breakpoint
*b
)
311 return b
->commands
? b
->commands
->commands
: NULL
;
314 /* Flag indicating that a command has proceeded the inferior past the
315 current breakpoint. */
317 static int breakpoint_proceeded
;
320 bpdisp_text (enum bpdisp disp
)
322 /* NOTE: the following values are a part of MI protocol and
323 represent values of 'disp' field returned when inferior stops at
325 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
327 return bpdisps
[(int) disp
];
330 /* Prototypes for exported functions. */
331 /* If FALSE, gdb will not use hardware support for watchpoints, even
332 if such is available. */
333 static int can_use_hw_watchpoints
;
336 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
337 struct cmd_list_element
*c
,
340 fprintf_filtered (file
,
341 _("Debugger's willingness to use "
342 "watchpoint hardware is %s.\n"),
346 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
347 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
348 for unrecognized breakpoint locations.
349 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
350 static enum auto_boolean pending_break_support
;
352 show_pending_break_support (struct ui_file
*file
, int from_tty
,
353 struct cmd_list_element
*c
,
356 fprintf_filtered (file
,
357 _("Debugger's behavior regarding "
358 "pending breakpoints is %s.\n"),
362 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
363 set with "break" but falling in read-only memory.
364 If 0, gdb will warn about such breakpoints, but won't automatically
365 use hardware breakpoints. */
366 static int automatic_hardware_breakpoints
;
368 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
369 struct cmd_list_element
*c
,
372 fprintf_filtered (file
,
373 _("Automatic usage of hardware breakpoints is %s.\n"),
377 /* If on, gdb will keep breakpoints inserted even as inferior is
378 stopped, and immediately insert any new breakpoints. If off, gdb
379 will insert breakpoints into inferior only when resuming it, and
380 will remove breakpoints upon stop. If auto, GDB will behave as ON
381 if in non-stop mode, and as OFF if all-stop mode.*/
383 static const char always_inserted_auto
[] = "auto";
384 static const char always_inserted_on
[] = "on";
385 static const char always_inserted_off
[] = "off";
386 static const char *const always_inserted_enums
[] = {
387 always_inserted_auto
,
392 static const char *always_inserted_mode
= always_inserted_auto
;
394 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
395 struct cmd_list_element
*c
, const char *value
)
397 if (always_inserted_mode
== always_inserted_auto
)
398 fprintf_filtered (file
,
399 _("Always inserted breakpoint "
400 "mode is %s (currently %s).\n"),
402 breakpoints_always_inserted_mode () ? "on" : "off");
404 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
409 breakpoints_always_inserted_mode (void)
411 return (always_inserted_mode
== always_inserted_on
412 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
415 static const char condition_evaluation_both
[] = "host or target";
417 /* Modes for breakpoint condition evaluation. */
418 static const char condition_evaluation_auto
[] = "auto";
419 static const char condition_evaluation_host
[] = "host";
420 static const char condition_evaluation_target
[] = "target";
421 static const char *const condition_evaluation_enums
[] = {
422 condition_evaluation_auto
,
423 condition_evaluation_host
,
424 condition_evaluation_target
,
428 /* Global that holds the current mode for breakpoint condition evaluation. */
429 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
431 /* Global that we use to display information to the user (gets its value from
432 condition_evaluation_mode_1. */
433 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
435 /* Translate a condition evaluation mode MODE into either "host"
436 or "target". This is used mostly to translate from "auto" to the
437 real setting that is being used. It returns the translated
441 translate_condition_evaluation_mode (const char *mode
)
443 if (mode
== condition_evaluation_auto
)
445 if (target_supports_evaluation_of_breakpoint_conditions ())
446 return condition_evaluation_target
;
448 return condition_evaluation_host
;
454 /* Discovers what condition_evaluation_auto translates to. */
457 breakpoint_condition_evaluation_mode (void)
459 return translate_condition_evaluation_mode (condition_evaluation_mode
);
462 /* Return true if GDB should evaluate breakpoint conditions or false
466 gdb_evaluates_breakpoint_condition_p (void)
468 const char *mode
= breakpoint_condition_evaluation_mode ();
470 return (mode
== condition_evaluation_host
);
473 void _initialize_breakpoint (void);
475 /* Are we executing breakpoint commands? */
476 static int executing_breakpoint_commands
;
478 /* Are overlay event breakpoints enabled? */
479 static int overlay_events_enabled
;
481 /* See description in breakpoint.h. */
482 int target_exact_watchpoints
= 0;
484 /* Walk the following statement or block through all breakpoints.
485 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
486 current breakpoint. */
488 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
490 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
491 for (B = breakpoint_chain; \
492 B ? (TMP=B->next, 1): 0; \
495 /* Similar iterator for the low-level breakpoints. SAFE variant is
496 not provided so update_global_location_list must not be called
497 while executing the block of ALL_BP_LOCATIONS. */
499 #define ALL_BP_LOCATIONS(B,BP_TMP) \
500 for (BP_TMP = bp_location; \
501 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
504 /* Iterates through locations with address ADDRESS for the currently selected
505 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
506 to where the loop should start from.
507 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
508 appropriate location to start with. */
510 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
511 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
512 BP_LOCP_TMP = BP_LOCP_START; \
514 && (BP_LOCP_TMP < bp_location + bp_location_count \
515 && (*BP_LOCP_TMP)->address == ADDRESS); \
518 /* Iterator for tracepoints only. */
520 #define ALL_TRACEPOINTS(B) \
521 for (B = breakpoint_chain; B; B = B->next) \
522 if (is_tracepoint (B))
524 /* Chains of all breakpoints defined. */
526 struct breakpoint
*breakpoint_chain
;
528 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
530 static struct bp_location
**bp_location
;
532 /* Number of elements of BP_LOCATION. */
534 static unsigned bp_location_count
;
536 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
537 ADDRESS for the current elements of BP_LOCATION which get a valid
538 result from bp_location_has_shadow. You can use it for roughly
539 limiting the subrange of BP_LOCATION to scan for shadow bytes for
540 an address you need to read. */
542 static CORE_ADDR bp_location_placed_address_before_address_max
;
544 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
545 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
546 BP_LOCATION which get a valid result from bp_location_has_shadow.
547 You can use it for roughly limiting the subrange of BP_LOCATION to
548 scan for shadow bytes for an address you need to read. */
550 static CORE_ADDR bp_location_shadow_len_after_address_max
;
552 /* The locations that no longer correspond to any breakpoint, unlinked
553 from bp_location array, but for which a hit may still be reported
555 VEC(bp_location_p
) *moribund_locations
= NULL
;
557 /* Number of last breakpoint made. */
559 static int breakpoint_count
;
561 /* The value of `breakpoint_count' before the last command that
562 created breakpoints. If the last (break-like) command created more
563 than one breakpoint, then the difference between BREAKPOINT_COUNT
564 and PREV_BREAKPOINT_COUNT is more than one. */
565 static int prev_breakpoint_count
;
567 /* Number of last tracepoint made. */
569 static int tracepoint_count
;
571 static struct cmd_list_element
*breakpoint_set_cmdlist
;
572 static struct cmd_list_element
*breakpoint_show_cmdlist
;
573 struct cmd_list_element
*save_cmdlist
;
575 /* Return whether a breakpoint is an active enabled breakpoint. */
577 breakpoint_enabled (struct breakpoint
*b
)
579 return (b
->enable_state
== bp_enabled
);
582 /* Set breakpoint count to NUM. */
585 set_breakpoint_count (int num
)
587 prev_breakpoint_count
= breakpoint_count
;
588 breakpoint_count
= num
;
589 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
592 /* Used by `start_rbreak_breakpoints' below, to record the current
593 breakpoint count before "rbreak" creates any breakpoint. */
594 static int rbreak_start_breakpoint_count
;
596 /* Called at the start an "rbreak" command to record the first
600 start_rbreak_breakpoints (void)
602 rbreak_start_breakpoint_count
= breakpoint_count
;
605 /* Called at the end of an "rbreak" command to record the last
609 end_rbreak_breakpoints (void)
611 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
614 /* Used in run_command to zero the hit count when a new run starts. */
617 clear_breakpoint_hit_counts (void)
619 struct breakpoint
*b
;
625 /* Allocate a new counted_command_line with reference count of 1.
626 The new structure owns COMMANDS. */
628 static struct counted_command_line
*
629 alloc_counted_command_line (struct command_line
*commands
)
631 struct counted_command_line
*result
632 = xmalloc (sizeof (struct counted_command_line
));
635 result
->commands
= commands
;
639 /* Increment reference count. This does nothing if CMD is NULL. */
642 incref_counted_command_line (struct counted_command_line
*cmd
)
648 /* Decrement reference count. If the reference count reaches 0,
649 destroy the counted_command_line. Sets *CMDP to NULL. This does
650 nothing if *CMDP is NULL. */
653 decref_counted_command_line (struct counted_command_line
**cmdp
)
657 if (--(*cmdp
)->refc
== 0)
659 free_command_lines (&(*cmdp
)->commands
);
666 /* A cleanup function that calls decref_counted_command_line. */
669 do_cleanup_counted_command_line (void *arg
)
671 decref_counted_command_line (arg
);
674 /* Create a cleanup that calls decref_counted_command_line on the
677 static struct cleanup
*
678 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
680 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
684 /* Return the breakpoint with the specified number, or NULL
685 if the number does not refer to an existing breakpoint. */
688 get_breakpoint (int num
)
690 struct breakpoint
*b
;
693 if (b
->number
== num
)
701 /* Mark locations as "conditions have changed" in case the target supports
702 evaluating conditions on its side. */
705 mark_breakpoint_modified (struct breakpoint
*b
)
707 struct bp_location
*loc
;
709 /* This is only meaningful if the target is
710 evaluating conditions and if the user has
711 opted for condition evaluation on the target's
713 if (gdb_evaluates_breakpoint_condition_p ()
714 || !target_supports_evaluation_of_breakpoint_conditions ())
717 if (!is_breakpoint (b
))
720 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
721 loc
->condition_changed
= condition_modified
;
724 /* Mark location as "conditions have changed" in case the target supports
725 evaluating conditions on its side. */
728 mark_breakpoint_location_modified (struct bp_location
*loc
)
730 /* This is only meaningful if the target is
731 evaluating conditions and if the user has
732 opted for condition evaluation on the target's
734 if (gdb_evaluates_breakpoint_condition_p ()
735 || !target_supports_evaluation_of_breakpoint_conditions ())
739 if (!is_breakpoint (loc
->owner
))
742 loc
->condition_changed
= condition_modified
;
745 /* Sets the condition-evaluation mode using the static global
746 condition_evaluation_mode. */
749 set_condition_evaluation_mode (char *args
, int from_tty
,
750 struct cmd_list_element
*c
)
752 struct breakpoint
*b
;
753 const char *old_mode
, *new_mode
;
755 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
756 && !target_supports_evaluation_of_breakpoint_conditions ())
758 condition_evaluation_mode_1
= condition_evaluation_mode
;
759 warning (_("Target does not support breakpoint condition evaluation.\n"
760 "Using host evaluation mode instead."));
764 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
765 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
767 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
768 settings was "auto". */
769 condition_evaluation_mode
= condition_evaluation_mode_1
;
771 /* Only update the mode if the user picked a different one. */
772 if (new_mode
!= old_mode
)
774 struct bp_location
*loc
, **loc_tmp
;
775 /* If the user switched to a different evaluation mode, we
776 need to synch the changes with the target as follows:
778 "host" -> "target": Send all (valid) conditions to the target.
779 "target" -> "host": Remove all the conditions from the target.
782 if (new_mode
== condition_evaluation_target
)
784 /* Mark everything modified and synch conditions with the
786 ALL_BP_LOCATIONS (loc
, loc_tmp
)
787 mark_breakpoint_location_modified (loc
);
791 /* Manually mark non-duplicate locations to synch conditions
792 with the target. We do this to remove all the conditions the
793 target knows about. */
794 ALL_BP_LOCATIONS (loc
, loc_tmp
)
795 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
796 loc
->needs_update
= 1;
800 update_global_location_list (1);
806 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
807 what "auto" is translating to. */
810 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
811 struct cmd_list_element
*c
, const char *value
)
813 if (condition_evaluation_mode
== condition_evaluation_auto
)
814 fprintf_filtered (file
,
815 _("Breakpoint condition evaluation "
816 "mode is %s (currently %s).\n"),
818 breakpoint_condition_evaluation_mode ());
820 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
824 /* A comparison function for bp_location AP and BP that is used by
825 bsearch. This comparison function only cares about addresses, unlike
826 the more general bp_location_compare function. */
829 bp_location_compare_addrs (const void *ap
, const void *bp
)
831 struct bp_location
*a
= *(void **) ap
;
832 struct bp_location
*b
= *(void **) bp
;
834 if (a
->address
== b
->address
)
837 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
840 /* Helper function to skip all bp_locations with addresses
841 less than ADDRESS. It returns the first bp_location that
842 is greater than or equal to ADDRESS. If none is found, just
845 static struct bp_location
**
846 get_first_locp_gte_addr (CORE_ADDR address
)
848 struct bp_location dummy_loc
;
849 struct bp_location
*dummy_locp
= &dummy_loc
;
850 struct bp_location
**locp_found
= NULL
;
852 /* Initialize the dummy location's address field. */
853 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
854 dummy_loc
.address
= address
;
856 /* Find a close match to the first location at ADDRESS. */
857 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
858 sizeof (struct bp_location
**),
859 bp_location_compare_addrs
);
861 /* Nothing was found, nothing left to do. */
862 if (locp_found
== NULL
)
865 /* We may have found a location that is at ADDRESS but is not the first in the
866 location's list. Go backwards (if possible) and locate the first one. */
867 while ((locp_found
- 1) >= bp_location
868 && (*(locp_found
- 1))->address
== address
)
875 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
878 xfree (b
->cond_string
);
879 b
->cond_string
= NULL
;
881 if (is_watchpoint (b
))
883 struct watchpoint
*w
= (struct watchpoint
*) b
;
890 struct bp_location
*loc
;
892 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
897 /* No need to free the condition agent expression
898 bytecode (if we have one). We will handle this
899 when we go through update_global_location_list. */
906 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
912 /* I don't know if it matters whether this is the string the user
913 typed in or the decompiled expression. */
914 b
->cond_string
= xstrdup (arg
);
915 b
->condition_not_parsed
= 0;
917 if (is_watchpoint (b
))
919 struct watchpoint
*w
= (struct watchpoint
*) b
;
921 innermost_block
= NULL
;
923 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
925 error (_("Junk at end of expression"));
926 w
->cond_exp_valid_block
= innermost_block
;
930 struct bp_location
*loc
;
932 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
936 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
938 error (_("Junk at end of expression"));
942 mark_breakpoint_modified (b
);
944 breakpoints_changed ();
945 observer_notify_breakpoint_modified (b
);
948 /* condition N EXP -- set break condition of breakpoint N to EXP. */
951 condition_command (char *arg
, int from_tty
)
953 struct breakpoint
*b
;
958 error_no_arg (_("breakpoint number"));
961 bnum
= get_number (&p
);
963 error (_("Bad breakpoint argument: '%s'"), arg
);
966 if (b
->number
== bnum
)
968 /* Check if this breakpoint has a Python object assigned to
969 it, and if it has a definition of the "stop"
970 method. This method and conditions entered into GDB from
971 the CLI are mutually exclusive. */
973 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
974 error (_("Cannot set a condition where a Python 'stop' "
975 "method has been defined in the breakpoint."));
976 set_breakpoint_condition (b
, p
, from_tty
);
978 if (is_breakpoint (b
))
979 update_global_location_list (1);
984 error (_("No breakpoint number %d."), bnum
);
987 /* Check that COMMAND do not contain commands that are suitable
988 only for tracepoints and not suitable for ordinary breakpoints.
989 Throw if any such commands is found. */
992 check_no_tracepoint_commands (struct command_line
*commands
)
994 struct command_line
*c
;
996 for (c
= commands
; c
; c
= c
->next
)
1000 if (c
->control_type
== while_stepping_control
)
1001 error (_("The 'while-stepping' command can "
1002 "only be used for tracepoints"));
1004 for (i
= 0; i
< c
->body_count
; ++i
)
1005 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1007 /* Not that command parsing removes leading whitespace and comment
1008 lines and also empty lines. So, we only need to check for
1009 command directly. */
1010 if (strstr (c
->line
, "collect ") == c
->line
)
1011 error (_("The 'collect' command can only be used for tracepoints"));
1013 if (strstr (c
->line
, "teval ") == c
->line
)
1014 error (_("The 'teval' command can only be used for tracepoints"));
1018 /* Encapsulate tests for different types of tracepoints. */
1021 is_tracepoint_type (enum bptype type
)
1023 return (type
== bp_tracepoint
1024 || type
== bp_fast_tracepoint
1025 || type
== bp_static_tracepoint
);
1029 is_tracepoint (const struct breakpoint
*b
)
1031 return is_tracepoint_type (b
->type
);
1034 /* A helper function that validates that COMMANDS are valid for a
1035 breakpoint. This function will throw an exception if a problem is
1039 validate_commands_for_breakpoint (struct breakpoint
*b
,
1040 struct command_line
*commands
)
1042 if (is_tracepoint (b
))
1044 /* We need to verify that each top-level element of commands is
1045 valid for tracepoints, that there's at most one
1046 while-stepping element, and that while-stepping's body has
1047 valid tracing commands excluding nested while-stepping. */
1048 struct command_line
*c
;
1049 struct command_line
*while_stepping
= 0;
1050 for (c
= commands
; c
; c
= c
->next
)
1052 if (c
->control_type
== while_stepping_control
)
1054 if (b
->type
== bp_fast_tracepoint
)
1055 error (_("The 'while-stepping' command "
1056 "cannot be used for fast tracepoint"));
1057 else if (b
->type
== bp_static_tracepoint
)
1058 error (_("The 'while-stepping' command "
1059 "cannot be used for static tracepoint"));
1062 error (_("The 'while-stepping' command "
1063 "can be used only once"));
1070 struct command_line
*c2
;
1072 gdb_assert (while_stepping
->body_count
== 1);
1073 c2
= while_stepping
->body_list
[0];
1074 for (; c2
; c2
= c2
->next
)
1076 if (c2
->control_type
== while_stepping_control
)
1077 error (_("The 'while-stepping' command cannot be nested"));
1083 check_no_tracepoint_commands (commands
);
1087 /* Return a vector of all the static tracepoints set at ADDR. The
1088 caller is responsible for releasing the vector. */
1091 static_tracepoints_here (CORE_ADDR addr
)
1093 struct breakpoint
*b
;
1094 VEC(breakpoint_p
) *found
= 0;
1095 struct bp_location
*loc
;
1098 if (b
->type
== bp_static_tracepoint
)
1100 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1101 if (loc
->address
== addr
)
1102 VEC_safe_push(breakpoint_p
, found
, b
);
1108 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1109 validate that only allowed commands are included. */
1112 breakpoint_set_commands (struct breakpoint
*b
,
1113 struct command_line
*commands
)
1115 validate_commands_for_breakpoint (b
, commands
);
1117 decref_counted_command_line (&b
->commands
);
1118 b
->commands
= alloc_counted_command_line (commands
);
1119 breakpoints_changed ();
1120 observer_notify_breakpoint_modified (b
);
1123 /* Set the internal `silent' flag on the breakpoint. Note that this
1124 is not the same as the "silent" that may appear in the breakpoint's
1128 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1130 int old_silent
= b
->silent
;
1133 if (old_silent
!= silent
)
1134 observer_notify_breakpoint_modified (b
);
1137 /* Set the thread for this breakpoint. If THREAD is -1, make the
1138 breakpoint work for any thread. */
1141 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1143 int old_thread
= b
->thread
;
1146 if (old_thread
!= thread
)
1147 observer_notify_breakpoint_modified (b
);
1150 /* Set the task for this breakpoint. If TASK is 0, make the
1151 breakpoint work for any task. */
1154 breakpoint_set_task (struct breakpoint
*b
, int task
)
1156 int old_task
= b
->task
;
1159 if (old_task
!= task
)
1160 observer_notify_breakpoint_modified (b
);
1164 check_tracepoint_command (char *line
, void *closure
)
1166 struct breakpoint
*b
= closure
;
1168 validate_actionline (&line
, b
);
1171 /* A structure used to pass information through
1172 map_breakpoint_numbers. */
1174 struct commands_info
1176 /* True if the command was typed at a tty. */
1179 /* The breakpoint range spec. */
1182 /* Non-NULL if the body of the commands are being read from this
1183 already-parsed command. */
1184 struct command_line
*control
;
1186 /* The command lines read from the user, or NULL if they have not
1188 struct counted_command_line
*cmd
;
1191 /* A callback for map_breakpoint_numbers that sets the commands for
1192 commands_command. */
1195 do_map_commands_command (struct breakpoint
*b
, void *data
)
1197 struct commands_info
*info
= data
;
1199 if (info
->cmd
== NULL
)
1201 struct command_line
*l
;
1203 if (info
->control
!= NULL
)
1204 l
= copy_command_lines (info
->control
->body_list
[0]);
1207 struct cleanup
*old_chain
;
1210 str
= xstrprintf (_("Type commands for breakpoint(s) "
1211 "%s, one per line."),
1214 old_chain
= make_cleanup (xfree
, str
);
1216 l
= read_command_lines (str
,
1219 ? check_tracepoint_command
: 0),
1222 do_cleanups (old_chain
);
1225 info
->cmd
= alloc_counted_command_line (l
);
1228 /* If a breakpoint was on the list more than once, we don't need to
1230 if (b
->commands
!= info
->cmd
)
1232 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1233 incref_counted_command_line (info
->cmd
);
1234 decref_counted_command_line (&b
->commands
);
1235 b
->commands
= info
->cmd
;
1236 breakpoints_changed ();
1237 observer_notify_breakpoint_modified (b
);
1242 commands_command_1 (char *arg
, int from_tty
,
1243 struct command_line
*control
)
1245 struct cleanup
*cleanups
;
1246 struct commands_info info
;
1248 info
.from_tty
= from_tty
;
1249 info
.control
= control
;
1251 /* If we read command lines from the user, then `info' will hold an
1252 extra reference to the commands that we must clean up. */
1253 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1255 if (arg
== NULL
|| !*arg
)
1257 if (breakpoint_count
- prev_breakpoint_count
> 1)
1258 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1260 else if (breakpoint_count
> 0)
1261 arg
= xstrprintf ("%d", breakpoint_count
);
1264 /* So that we don't try to free the incoming non-NULL
1265 argument in the cleanup below. Mapping breakpoint
1266 numbers will fail in this case. */
1271 /* The command loop has some static state, so we need to preserve
1273 arg
= xstrdup (arg
);
1276 make_cleanup (xfree
, arg
);
1280 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1282 if (info
.cmd
== NULL
)
1283 error (_("No breakpoints specified."));
1285 do_cleanups (cleanups
);
1289 commands_command (char *arg
, int from_tty
)
1291 commands_command_1 (arg
, from_tty
, NULL
);
1294 /* Like commands_command, but instead of reading the commands from
1295 input stream, takes them from an already parsed command structure.
1297 This is used by cli-script.c to DTRT with breakpoint commands
1298 that are part of if and while bodies. */
1299 enum command_control_type
1300 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1302 commands_command_1 (arg
, 0, cmd
);
1303 return simple_control
;
1306 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1309 bp_location_has_shadow (struct bp_location
*bl
)
1311 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1315 if (bl
->target_info
.shadow_len
== 0)
1316 /* BL isn't valid, or doesn't shadow memory. */
1321 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1322 by replacing any memory breakpoints with their shadowed contents.
1324 If READBUF is not NULL, this buffer must not overlap with any of
1325 the breakpoint location's shadow_contents buffers. Otherwise,
1326 a failed assertion internal error will be raised.
1328 The range of shadowed area by each bp_location is:
1329 bl->address - bp_location_placed_address_before_address_max
1330 up to bl->address + bp_location_shadow_len_after_address_max
1331 The range we were requested to resolve shadows for is:
1332 memaddr ... memaddr + len
1333 Thus the safe cutoff boundaries for performance optimization are
1334 memaddr + len <= (bl->address
1335 - bp_location_placed_address_before_address_max)
1337 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1340 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1341 const gdb_byte
*writebuf_org
,
1342 ULONGEST memaddr
, LONGEST len
)
1344 /* Left boundary, right boundary and median element of our binary
1346 unsigned bc_l
, bc_r
, bc
;
1348 /* Find BC_L which is a leftmost element which may affect BUF
1349 content. It is safe to report lower value but a failure to
1350 report higher one. */
1353 bc_r
= bp_location_count
;
1354 while (bc_l
+ 1 < bc_r
)
1356 struct bp_location
*bl
;
1358 bc
= (bc_l
+ bc_r
) / 2;
1359 bl
= bp_location
[bc
];
1361 /* Check first BL->ADDRESS will not overflow due to the added
1362 constant. Then advance the left boundary only if we are sure
1363 the BC element can in no way affect the BUF content (MEMADDR
1364 to MEMADDR + LEN range).
1366 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1367 offset so that we cannot miss a breakpoint with its shadow
1368 range tail still reaching MEMADDR. */
1370 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1372 && (bl
->address
+ bp_location_shadow_len_after_address_max
1379 /* Due to the binary search above, we need to make sure we pick the
1380 first location that's at BC_L's address. E.g., if there are
1381 multiple locations at the same address, BC_L may end up pointing
1382 at a duplicate location, and miss the "master"/"inserted"
1383 location. Say, given locations L1, L2 and L3 at addresses A and
1386 L1@A, L2@A, L3@B, ...
1388 BC_L could end up pointing at location L2, while the "master"
1389 location could be L1. Since the `loc->inserted' flag is only set
1390 on "master" locations, we'd forget to restore the shadow of L1
1393 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1396 /* Now do full processing of the found relevant range of elements. */
1398 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1400 struct bp_location
*bl
= bp_location
[bc
];
1401 CORE_ADDR bp_addr
= 0;
1405 /* bp_location array has BL->OWNER always non-NULL. */
1406 if (bl
->owner
->type
== bp_none
)
1407 warning (_("reading through apparently deleted breakpoint #%d?"),
1410 /* Performance optimization: any further element can no longer affect BUF
1413 if (bl
->address
>= bp_location_placed_address_before_address_max
1414 && memaddr
+ len
<= (bl
->address
1415 - bp_location_placed_address_before_address_max
))
1418 if (!bp_location_has_shadow (bl
))
1420 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1421 current_program_space
->aspace
, 0))
1424 /* Addresses and length of the part of the breakpoint that
1426 bp_addr
= bl
->target_info
.placed_address
;
1427 bp_size
= bl
->target_info
.shadow_len
;
1429 if (bp_addr
+ bp_size
<= memaddr
)
1430 /* The breakpoint is entirely before the chunk of memory we
1434 if (bp_addr
>= memaddr
+ len
)
1435 /* The breakpoint is entirely after the chunk of memory we are
1439 /* Offset within shadow_contents. */
1440 if (bp_addr
< memaddr
)
1442 /* Only copy the second part of the breakpoint. */
1443 bp_size
-= memaddr
- bp_addr
;
1444 bptoffset
= memaddr
- bp_addr
;
1448 if (bp_addr
+ bp_size
> memaddr
+ len
)
1450 /* Only copy the first part of the breakpoint. */
1451 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1454 if (readbuf
!= NULL
)
1456 /* Verify that the readbuf buffer does not overlap with
1457 the shadow_contents buffer. */
1458 gdb_assert (bl
->target_info
.shadow_contents
>= readbuf
+ len
1459 || readbuf
>= (bl
->target_info
.shadow_contents
1460 + bl
->target_info
.shadow_len
));
1462 /* Update the read buffer with this inserted breakpoint's
1464 memcpy (readbuf
+ bp_addr
- memaddr
,
1465 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1469 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1470 const unsigned char *bp
;
1471 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1472 unsigned placed_size
= bl
->target_info
.placed_size
;
1474 /* Update the shadow with what we want to write to memory. */
1475 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1476 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1478 /* Determine appropriate breakpoint contents and size for this
1480 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1482 /* Update the final write buffer with this inserted
1483 breakpoint's INSN. */
1484 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1490 /* Return true if BPT is either a software breakpoint or a hardware
1494 is_breakpoint (const struct breakpoint
*bpt
)
1496 return (bpt
->type
== bp_breakpoint
1497 || bpt
->type
== bp_hardware_breakpoint
);
1500 /* Return true if BPT is of any hardware watchpoint kind. */
1503 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1505 return (bpt
->type
== bp_hardware_watchpoint
1506 || bpt
->type
== bp_read_watchpoint
1507 || bpt
->type
== bp_access_watchpoint
);
1510 /* Return true if BPT is of any watchpoint kind, hardware or
1514 is_watchpoint (const struct breakpoint
*bpt
)
1516 return (is_hardware_watchpoint (bpt
)
1517 || bpt
->type
== bp_watchpoint
);
1520 /* Returns true if the current thread and its running state are safe
1521 to evaluate or update watchpoint B. Watchpoints on local
1522 expressions need to be evaluated in the context of the thread that
1523 was current when the watchpoint was created, and, that thread needs
1524 to be stopped to be able to select the correct frame context.
1525 Watchpoints on global expressions can be evaluated on any thread,
1526 and in any state. It is presently left to the target allowing
1527 memory accesses when threads are running. */
1530 watchpoint_in_thread_scope (struct watchpoint
*b
)
1532 return (b
->base
.pspace
== current_program_space
1533 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1534 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1535 && !is_executing (inferior_ptid
))));
1538 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1539 associated bp_watchpoint_scope breakpoint. */
1542 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1544 struct breakpoint
*b
= &w
->base
;
1546 if (b
->related_breakpoint
!= b
)
1548 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1549 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1550 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1551 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1552 b
->related_breakpoint
= b
;
1554 b
->disposition
= disp_del_at_next_stop
;
1557 /* Assuming that B is a watchpoint:
1558 - Reparse watchpoint expression, if REPARSE is non-zero
1559 - Evaluate expression and store the result in B->val
1560 - Evaluate the condition if there is one, and store the result
1562 - Update the list of values that must be watched in B->loc.
1564 If the watchpoint disposition is disp_del_at_next_stop, then do
1565 nothing. If this is local watchpoint that is out of scope, delete
1568 Even with `set breakpoint always-inserted on' the watchpoints are
1569 removed + inserted on each stop here. Normal breakpoints must
1570 never be removed because they might be missed by a running thread
1571 when debugging in non-stop mode. On the other hand, hardware
1572 watchpoints (is_hardware_watchpoint; processed here) are specific
1573 to each LWP since they are stored in each LWP's hardware debug
1574 registers. Therefore, such LWP must be stopped first in order to
1575 be able to modify its hardware watchpoints.
1577 Hardware watchpoints must be reset exactly once after being
1578 presented to the user. It cannot be done sooner, because it would
1579 reset the data used to present the watchpoint hit to the user. And
1580 it must not be done later because it could display the same single
1581 watchpoint hit during multiple GDB stops. Note that the latter is
1582 relevant only to the hardware watchpoint types bp_read_watchpoint
1583 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1584 not user-visible - its hit is suppressed if the memory content has
1587 The following constraints influence the location where we can reset
1588 hardware watchpoints:
1590 * target_stopped_by_watchpoint and target_stopped_data_address are
1591 called several times when GDB stops.
1594 * Multiple hardware watchpoints can be hit at the same time,
1595 causing GDB to stop. GDB only presents one hardware watchpoint
1596 hit at a time as the reason for stopping, and all the other hits
1597 are presented later, one after the other, each time the user
1598 requests the execution to be resumed. Execution is not resumed
1599 for the threads still having pending hit event stored in
1600 LWP_INFO->STATUS. While the watchpoint is already removed from
1601 the inferior on the first stop the thread hit event is kept being
1602 reported from its cached value by linux_nat_stopped_data_address
1603 until the real thread resume happens after the watchpoint gets
1604 presented and thus its LWP_INFO->STATUS gets reset.
1606 Therefore the hardware watchpoint hit can get safely reset on the
1607 watchpoint removal from inferior. */
1610 update_watchpoint (struct watchpoint
*b
, int reparse
)
1612 int within_current_scope
;
1613 struct frame_id saved_frame_id
;
1616 /* If this is a local watchpoint, we only want to check if the
1617 watchpoint frame is in scope if the current thread is the thread
1618 that was used to create the watchpoint. */
1619 if (!watchpoint_in_thread_scope (b
))
1622 if (b
->base
.disposition
== disp_del_at_next_stop
)
1627 /* Determine if the watchpoint is within scope. */
1628 if (b
->exp_valid_block
== NULL
)
1629 within_current_scope
= 1;
1632 struct frame_info
*fi
= get_current_frame ();
1633 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1634 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1636 /* If we're in a function epilogue, unwinding may not work
1637 properly, so do not attempt to recreate locations at this
1638 point. See similar comments in watchpoint_check. */
1639 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1642 /* Save the current frame's ID so we can restore it after
1643 evaluating the watchpoint expression on its own frame. */
1644 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1645 took a frame parameter, so that we didn't have to change the
1648 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1650 fi
= frame_find_by_id (b
->watchpoint_frame
);
1651 within_current_scope
= (fi
!= NULL
);
1652 if (within_current_scope
)
1656 /* We don't free locations. They are stored in the bp_location array
1657 and update_global_location_list will eventually delete them and
1658 remove breakpoints if needed. */
1661 if (within_current_scope
&& reparse
)
1670 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1671 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1672 /* If the meaning of expression itself changed, the old value is
1673 no longer relevant. We don't want to report a watchpoint hit
1674 to the user when the old value and the new value may actually
1675 be completely different objects. */
1676 value_free (b
->val
);
1680 /* Note that unlike with breakpoints, the watchpoint's condition
1681 expression is stored in the breakpoint object, not in the
1682 locations (re)created below. */
1683 if (b
->base
.cond_string
!= NULL
)
1685 if (b
->cond_exp
!= NULL
)
1687 xfree (b
->cond_exp
);
1691 s
= b
->base
.cond_string
;
1692 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1696 /* If we failed to parse the expression, for example because
1697 it refers to a global variable in a not-yet-loaded shared library,
1698 don't try to insert watchpoint. We don't automatically delete
1699 such watchpoint, though, since failure to parse expression
1700 is different from out-of-scope watchpoint. */
1701 if ( !target_has_execution
)
1703 /* Without execution, memory can't change. No use to try and
1704 set watchpoint locations. The watchpoint will be reset when
1705 the target gains execution, through breakpoint_re_set. */
1707 else if (within_current_scope
&& b
->exp
)
1710 struct value
*val_chain
, *v
, *result
, *next
;
1711 struct program_space
*frame_pspace
;
1713 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1715 /* Avoid setting b->val if it's already set. The meaning of
1716 b->val is 'the last value' user saw, and we should update
1717 it only if we reported that last value to user. As it
1718 happens, the code that reports it updates b->val directly.
1719 We don't keep track of the memory value for masked
1721 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1727 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1729 /* Look at each value on the value chain. */
1730 for (v
= val_chain
; v
; v
= value_next (v
))
1732 /* If it's a memory location, and GDB actually needed
1733 its contents to evaluate the expression, then we
1734 must watch it. If the first value returned is
1735 still lazy, that means an error occurred reading it;
1736 watch it anyway in case it becomes readable. */
1737 if (VALUE_LVAL (v
) == lval_memory
1738 && (v
== val_chain
|| ! value_lazy (v
)))
1740 struct type
*vtype
= check_typedef (value_type (v
));
1742 /* We only watch structs and arrays if user asked
1743 for it explicitly, never if they just happen to
1744 appear in the middle of some value chain. */
1746 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1747 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1751 struct bp_location
*loc
, **tmp
;
1753 addr
= value_address (v
);
1754 len
= TYPE_LENGTH (value_type (v
));
1756 if (b
->base
.type
== bp_read_watchpoint
)
1758 else if (b
->base
.type
== bp_access_watchpoint
)
1761 loc
= allocate_bp_location (&b
->base
);
1762 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1765 loc
->gdbarch
= get_type_arch (value_type (v
));
1767 loc
->pspace
= frame_pspace
;
1768 loc
->address
= addr
;
1770 loc
->watchpoint_type
= type
;
1775 /* Change the type of breakpoint between hardware assisted or
1776 an ordinary watchpoint depending on the hardware support
1777 and free hardware slots. REPARSE is set when the inferior
1782 enum bp_loc_type loc_type
;
1783 struct bp_location
*bl
;
1785 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1789 int i
, target_resources_ok
, other_type_used
;
1792 /* Use an exact watchpoint when there's only one memory region to be
1793 watched, and only one debug register is needed to watch it. */
1794 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1796 /* We need to determine how many resources are already
1797 used for all other hardware watchpoints plus this one
1798 to see if we still have enough resources to also fit
1799 this watchpoint in as well. */
1801 /* If this is a software watchpoint, we try to turn it
1802 to a hardware one -- count resources as if B was of
1803 hardware watchpoint type. */
1804 type
= b
->base
.type
;
1805 if (type
== bp_watchpoint
)
1806 type
= bp_hardware_watchpoint
;
1808 /* This watchpoint may or may not have been placed on
1809 the list yet at this point (it won't be in the list
1810 if we're trying to create it for the first time,
1811 through watch_command), so always account for it
1814 /* Count resources used by all watchpoints except B. */
1815 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1817 /* Add in the resources needed for B. */
1818 i
+= hw_watchpoint_use_count (&b
->base
);
1821 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1822 if (target_resources_ok
<= 0)
1824 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1826 if (target_resources_ok
== 0 && !sw_mode
)
1827 error (_("Target does not support this type of "
1828 "hardware watchpoint."));
1829 else if (target_resources_ok
< 0 && !sw_mode
)
1830 error (_("There are not enough available hardware "
1831 "resources for this watchpoint."));
1833 /* Downgrade to software watchpoint. */
1834 b
->base
.type
= bp_watchpoint
;
1838 /* If this was a software watchpoint, we've just
1839 found we have enough resources to turn it to a
1840 hardware watchpoint. Otherwise, this is a
1842 b
->base
.type
= type
;
1845 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1846 error (_("Expression cannot be implemented with "
1847 "read/access watchpoint."));
1849 b
->base
.type
= bp_watchpoint
;
1851 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1852 : bp_loc_hardware_watchpoint
);
1853 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1854 bl
->loc_type
= loc_type
;
1857 for (v
= val_chain
; v
; v
= next
)
1859 next
= value_next (v
);
1864 /* If a software watchpoint is not watching any memory, then the
1865 above left it without any location set up. But,
1866 bpstat_stop_status requires a location to be able to report
1867 stops, so make sure there's at least a dummy one. */
1868 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1870 struct breakpoint
*base
= &b
->base
;
1871 base
->loc
= allocate_bp_location (base
);
1872 base
->loc
->pspace
= frame_pspace
;
1873 base
->loc
->address
= -1;
1874 base
->loc
->length
= -1;
1875 base
->loc
->watchpoint_type
= -1;
1878 else if (!within_current_scope
)
1880 printf_filtered (_("\
1881 Watchpoint %d deleted because the program has left the block\n\
1882 in which its expression is valid.\n"),
1884 watchpoint_del_at_next_stop (b
);
1887 /* Restore the selected frame. */
1889 select_frame (frame_find_by_id (saved_frame_id
));
1893 /* Returns 1 iff breakpoint location should be
1894 inserted in the inferior. We don't differentiate the type of BL's owner
1895 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1896 breakpoint_ops is not defined, because in insert_bp_location,
1897 tracepoint's insert_location will not be called. */
1899 should_be_inserted (struct bp_location
*bl
)
1901 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1904 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1907 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1910 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1913 /* This is set for example, when we're attached to the parent of a
1914 vfork, and have detached from the child. The child is running
1915 free, and we expect it to do an exec or exit, at which point the
1916 OS makes the parent schedulable again (and the target reports
1917 that the vfork is done). Until the child is done with the shared
1918 memory region, do not insert breakpoints in the parent, otherwise
1919 the child could still trip on the parent's breakpoints. Since
1920 the parent is blocked anyway, it won't miss any breakpoint. */
1921 if (bl
->pspace
->breakpoints_not_allowed
)
1927 /* Same as should_be_inserted but does the check assuming
1928 that the location is not duplicated. */
1931 unduplicated_should_be_inserted (struct bp_location
*bl
)
1934 const int save_duplicate
= bl
->duplicate
;
1937 result
= should_be_inserted (bl
);
1938 bl
->duplicate
= save_duplicate
;
1942 /* Parses a conditional described by an expression COND into an
1943 agent expression bytecode suitable for evaluation
1944 by the bytecode interpreter. Return NULL if there was
1945 any error during parsing. */
1947 static struct agent_expr
*
1948 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
1950 struct agent_expr
*aexpr
= NULL
;
1951 struct cleanup
*old_chain
= NULL
;
1952 volatile struct gdb_exception ex
;
1957 /* We don't want to stop processing, so catch any errors
1958 that may show up. */
1959 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1961 aexpr
= gen_eval_for_expr (scope
, cond
);
1966 /* If we got here, it means the condition could not be parsed to a valid
1967 bytecode expression and thus can't be evaluated on the target's side.
1968 It's no use iterating through the conditions. */
1972 /* We have a valid agent expression. */
1976 /* Based on location BL, create a list of breakpoint conditions to be
1977 passed on to the target. If we have duplicated locations with different
1978 conditions, we will add such conditions to the list. The idea is that the
1979 target will evaluate the list of conditions and will only notify GDB when
1980 one of them is true. */
1983 build_target_condition_list (struct bp_location
*bl
)
1985 struct bp_location
**locp
= NULL
, **loc2p
;
1986 int null_condition_or_parse_error
= 0;
1987 int modified
= bl
->needs_update
;
1988 struct bp_location
*loc
;
1990 /* This is only meaningful if the target is
1991 evaluating conditions and if the user has
1992 opted for condition evaluation on the target's
1994 if (gdb_evaluates_breakpoint_condition_p ()
1995 || !target_supports_evaluation_of_breakpoint_conditions ())
1998 /* Do a first pass to check for locations with no assigned
1999 conditions or conditions that fail to parse to a valid agent expression
2000 bytecode. If any of these happen, then it's no use to send conditions
2001 to the target since this location will always trigger and generate a
2002 response back to GDB. */
2003 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2006 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2010 struct agent_expr
*aexpr
;
2012 /* Re-parse the conditions since something changed. In that
2013 case we already freed the condition bytecodes (see
2014 force_breakpoint_reinsertion). We just
2015 need to parse the condition to bytecodes again. */
2016 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2017 loc
->cond_bytecode
= aexpr
;
2019 /* Check if we managed to parse the conditional expression
2020 correctly. If not, we will not send this condition
2026 /* If we have a NULL bytecode expression, it means something
2027 went wrong or we have a null condition expression. */
2028 if (!loc
->cond_bytecode
)
2030 null_condition_or_parse_error
= 1;
2036 /* If any of these happened, it means we will have to evaluate the conditions
2037 for the location's address on gdb's side. It is no use keeping bytecodes
2038 for all the other duplicate locations, thus we free all of them here.
2040 This is so we have a finer control over which locations' conditions are
2041 being evaluated by GDB or the remote stub. */
2042 if (null_condition_or_parse_error
)
2044 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2047 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2049 /* Only go as far as the first NULL bytecode is
2051 if (!loc
->cond_bytecode
)
2054 free_agent_expr (loc
->cond_bytecode
);
2055 loc
->cond_bytecode
= NULL
;
2060 /* No NULL conditions or failed bytecode generation. Build a condition list
2061 for this location's address. */
2062 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2066 && is_breakpoint (loc
->owner
)
2067 && loc
->pspace
->num
== bl
->pspace
->num
2068 && loc
->owner
->enable_state
== bp_enabled
2070 /* Add the condition to the vector. This will be used later to send the
2071 conditions to the target. */
2072 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2073 loc
->cond_bytecode
);
2079 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2080 location. Any error messages are printed to TMP_ERROR_STREAM; and
2081 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2082 Returns 0 for success, 1 if the bp_location type is not supported or
2085 NOTE drow/2003-09-09: This routine could be broken down to an
2086 object-style method for each breakpoint or catchpoint type. */
2088 insert_bp_location (struct bp_location
*bl
,
2089 struct ui_file
*tmp_error_stream
,
2090 int *disabled_breaks
,
2091 int *hw_breakpoint_error
)
2095 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2098 /* Note we don't initialize bl->target_info, as that wipes out
2099 the breakpoint location's shadow_contents if the breakpoint
2100 is still inserted at that location. This in turn breaks
2101 target_read_memory which depends on these buffers when
2102 a memory read is requested at the breakpoint location:
2103 Once the target_info has been wiped, we fail to see that
2104 we have a breakpoint inserted at that address and thus
2105 read the breakpoint instead of returning the data saved in
2106 the breakpoint location's shadow contents. */
2107 bl
->target_info
.placed_address
= bl
->address
;
2108 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2109 bl
->target_info
.length
= bl
->length
;
2111 /* When working with target-side conditions, we must pass all the conditions
2112 for the same breakpoint address down to the target since GDB will not
2113 insert those locations. With a list of breakpoint conditions, the target
2114 can decide when to stop and notify GDB. */
2116 if (is_breakpoint (bl
->owner
))
2118 build_target_condition_list (bl
);
2119 /* Reset the condition modification marker. */
2120 bl
->needs_update
= 0;
2123 if (bl
->loc_type
== bp_loc_software_breakpoint
2124 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2126 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2128 /* If the explicitly specified breakpoint type
2129 is not hardware breakpoint, check the memory map to see
2130 if the breakpoint address is in read only memory or not.
2132 Two important cases are:
2133 - location type is not hardware breakpoint, memory
2134 is readonly. We change the type of the location to
2135 hardware breakpoint.
2136 - location type is hardware breakpoint, memory is
2137 read-write. This means we've previously made the
2138 location hardware one, but then the memory map changed,
2141 When breakpoints are removed, remove_breakpoints will use
2142 location types we've just set here, the only possible
2143 problem is that memory map has changed during running
2144 program, but it's not going to work anyway with current
2146 struct mem_region
*mr
2147 = lookup_mem_region (bl
->target_info
.placed_address
);
2151 if (automatic_hardware_breakpoints
)
2153 enum bp_loc_type new_type
;
2155 if (mr
->attrib
.mode
!= MEM_RW
)
2156 new_type
= bp_loc_hardware_breakpoint
;
2158 new_type
= bp_loc_software_breakpoint
;
2160 if (new_type
!= bl
->loc_type
)
2162 static int said
= 0;
2164 bl
->loc_type
= new_type
;
2167 fprintf_filtered (gdb_stdout
,
2168 _("Note: automatically using "
2169 "hardware breakpoints for "
2170 "read-only addresses.\n"));
2175 else if (bl
->loc_type
== bp_loc_software_breakpoint
2176 && mr
->attrib
.mode
!= MEM_RW
)
2177 warning (_("cannot set software breakpoint "
2178 "at readonly address %s"),
2179 paddress (bl
->gdbarch
, bl
->address
));
2183 /* First check to see if we have to handle an overlay. */
2184 if (overlay_debugging
== ovly_off
2185 || bl
->section
== NULL
2186 || !(section_is_overlay (bl
->section
)))
2188 /* No overlay handling: just set the breakpoint. */
2190 val
= bl
->owner
->ops
->insert_location (bl
);
2194 /* This breakpoint is in an overlay section.
2195 Shall we set a breakpoint at the LMA? */
2196 if (!overlay_events_enabled
)
2198 /* Yes -- overlay event support is not active,
2199 so we must try to set a breakpoint at the LMA.
2200 This will not work for a hardware breakpoint. */
2201 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2202 warning (_("hardware breakpoint %d not supported in overlay!"),
2206 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2208 /* Set a software (trap) breakpoint at the LMA. */
2209 bl
->overlay_target_info
= bl
->target_info
;
2210 bl
->overlay_target_info
.placed_address
= addr
;
2211 val
= target_insert_breakpoint (bl
->gdbarch
,
2212 &bl
->overlay_target_info
);
2214 fprintf_unfiltered (tmp_error_stream
,
2215 "Overlay breakpoint %d "
2216 "failed: in ROM?\n",
2220 /* Shall we set a breakpoint at the VMA? */
2221 if (section_is_mapped (bl
->section
))
2223 /* Yes. This overlay section is mapped into memory. */
2224 val
= bl
->owner
->ops
->insert_location (bl
);
2228 /* No. This breakpoint will not be inserted.
2229 No error, but do not mark the bp as 'inserted'. */
2236 /* Can't set the breakpoint. */
2237 if (solib_name_from_address (bl
->pspace
, bl
->address
))
2239 /* See also: disable_breakpoints_in_shlibs. */
2241 bl
->shlib_disabled
= 1;
2242 observer_notify_breakpoint_modified (bl
->owner
);
2243 if (!*disabled_breaks
)
2245 fprintf_unfiltered (tmp_error_stream
,
2246 "Cannot insert breakpoint %d.\n",
2248 fprintf_unfiltered (tmp_error_stream
,
2249 "Temporarily disabling shared "
2250 "library breakpoints:\n");
2252 *disabled_breaks
= 1;
2253 fprintf_unfiltered (tmp_error_stream
,
2254 "breakpoint #%d\n", bl
->owner
->number
);
2258 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2260 *hw_breakpoint_error
= 1;
2261 fprintf_unfiltered (tmp_error_stream
,
2262 "Cannot insert hardware "
2268 fprintf_unfiltered (tmp_error_stream
,
2269 "Cannot insert breakpoint %d.\n",
2271 fprintf_filtered (tmp_error_stream
,
2272 "Error accessing memory address ");
2273 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
2275 fprintf_filtered (tmp_error_stream
, ": %s.\n",
2276 safe_strerror (val
));
2287 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2288 /* NOTE drow/2003-09-08: This state only exists for removing
2289 watchpoints. It's not clear that it's necessary... */
2290 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2292 gdb_assert (bl
->owner
->ops
!= NULL
2293 && bl
->owner
->ops
->insert_location
!= NULL
);
2295 val
= bl
->owner
->ops
->insert_location (bl
);
2297 /* If trying to set a read-watchpoint, and it turns out it's not
2298 supported, try emulating one with an access watchpoint. */
2299 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2301 struct bp_location
*loc
, **loc_temp
;
2303 /* But don't try to insert it, if there's already another
2304 hw_access location that would be considered a duplicate
2306 ALL_BP_LOCATIONS (loc
, loc_temp
)
2308 && loc
->watchpoint_type
== hw_access
2309 && watchpoint_locations_match (bl
, loc
))
2313 bl
->target_info
= loc
->target_info
;
2314 bl
->watchpoint_type
= hw_access
;
2321 bl
->watchpoint_type
= hw_access
;
2322 val
= bl
->owner
->ops
->insert_location (bl
);
2325 /* Back to the original value. */
2326 bl
->watchpoint_type
= hw_read
;
2330 bl
->inserted
= (val
== 0);
2333 else if (bl
->owner
->type
== bp_catchpoint
)
2335 gdb_assert (bl
->owner
->ops
!= NULL
2336 && bl
->owner
->ops
->insert_location
!= NULL
);
2338 val
= bl
->owner
->ops
->insert_location (bl
);
2341 bl
->owner
->enable_state
= bp_disabled
;
2345 Error inserting catchpoint %d: Your system does not support this type\n\
2346 of catchpoint."), bl
->owner
->number
);
2348 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2351 bl
->inserted
= (val
== 0);
2353 /* We've already printed an error message if there was a problem
2354 inserting this catchpoint, and we've disabled the catchpoint,
2355 so just return success. */
2362 /* This function is called when program space PSPACE is about to be
2363 deleted. It takes care of updating breakpoints to not reference
2367 breakpoint_program_space_exit (struct program_space
*pspace
)
2369 struct breakpoint
*b
, *b_temp
;
2370 struct bp_location
*loc
, **loc_temp
;
2372 /* Remove any breakpoint that was set through this program space. */
2373 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2375 if (b
->pspace
== pspace
)
2376 delete_breakpoint (b
);
2379 /* Breakpoints set through other program spaces could have locations
2380 bound to PSPACE as well. Remove those. */
2381 ALL_BP_LOCATIONS (loc
, loc_temp
)
2383 struct bp_location
*tmp
;
2385 if (loc
->pspace
== pspace
)
2387 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2388 if (loc
->owner
->loc
== loc
)
2389 loc
->owner
->loc
= loc
->next
;
2391 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2392 if (tmp
->next
== loc
)
2394 tmp
->next
= loc
->next
;
2400 /* Now update the global location list to permanently delete the
2401 removed locations above. */
2402 update_global_location_list (0);
2405 /* Make sure all breakpoints are inserted in inferior.
2406 Throws exception on any error.
2407 A breakpoint that is already inserted won't be inserted
2408 again, so calling this function twice is safe. */
2410 insert_breakpoints (void)
2412 struct breakpoint
*bpt
;
2414 ALL_BREAKPOINTS (bpt
)
2415 if (is_hardware_watchpoint (bpt
))
2417 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2419 update_watchpoint (w
, 0 /* don't reparse. */);
2422 update_global_location_list (1);
2424 /* update_global_location_list does not insert breakpoints when
2425 always_inserted_mode is not enabled. Explicitly insert them
2427 if (!breakpoints_always_inserted_mode ())
2428 insert_breakpoint_locations ();
2431 /* Invoke CALLBACK for each of bp_location. */
2434 iterate_over_bp_locations (walk_bp_location_callback callback
)
2436 struct bp_location
*loc
, **loc_tmp
;
2438 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2440 callback (loc
, NULL
);
2444 /* This is used when we need to synch breakpoint conditions between GDB and the
2445 target. It is the case with deleting and disabling of breakpoints when using
2446 always-inserted mode. */
2449 update_inserted_breakpoint_locations (void)
2451 struct bp_location
*bl
, **blp_tmp
;
2454 int disabled_breaks
= 0;
2455 int hw_breakpoint_error
= 0;
2457 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2458 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2460 /* Explicitly mark the warning -- this will only be printed if
2461 there was an error. */
2462 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2464 save_current_space_and_thread ();
2466 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2468 /* We only want to update software breakpoints and hardware
2470 if (!is_breakpoint (bl
->owner
))
2473 /* We only want to update locations that are already inserted
2474 and need updating. This is to avoid unwanted insertion during
2475 deletion of breakpoints. */
2476 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2479 switch_to_program_space_and_thread (bl
->pspace
);
2481 /* For targets that support global breakpoints, there's no need
2482 to select an inferior to insert breakpoint to. In fact, even
2483 if we aren't attached to any process yet, we should still
2484 insert breakpoints. */
2485 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2486 && ptid_equal (inferior_ptid
, null_ptid
))
2489 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2490 &hw_breakpoint_error
);
2497 target_terminal_ours_for_output ();
2498 error_stream (tmp_error_stream
);
2501 do_cleanups (cleanups
);
2504 /* Used when starting or continuing the program. */
2507 insert_breakpoint_locations (void)
2509 struct breakpoint
*bpt
;
2510 struct bp_location
*bl
, **blp_tmp
;
2513 int disabled_breaks
= 0;
2514 int hw_breakpoint_error
= 0;
2516 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2517 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2519 /* Explicitly mark the warning -- this will only be printed if
2520 there was an error. */
2521 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2523 save_current_space_and_thread ();
2525 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2527 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2530 /* There is no point inserting thread-specific breakpoints if
2531 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2532 has BL->OWNER always non-NULL. */
2533 if (bl
->owner
->thread
!= -1
2534 && !valid_thread_id (bl
->owner
->thread
))
2537 switch_to_program_space_and_thread (bl
->pspace
);
2539 /* For targets that support global breakpoints, there's no need
2540 to select an inferior to insert breakpoint to. In fact, even
2541 if we aren't attached to any process yet, we should still
2542 insert breakpoints. */
2543 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2544 && ptid_equal (inferior_ptid
, null_ptid
))
2547 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2548 &hw_breakpoint_error
);
2553 /* If we failed to insert all locations of a watchpoint, remove
2554 them, as half-inserted watchpoint is of limited use. */
2555 ALL_BREAKPOINTS (bpt
)
2557 int some_failed
= 0;
2558 struct bp_location
*loc
;
2560 if (!is_hardware_watchpoint (bpt
))
2563 if (!breakpoint_enabled (bpt
))
2566 if (bpt
->disposition
== disp_del_at_next_stop
)
2569 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2570 if (!loc
->inserted
&& should_be_inserted (loc
))
2577 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2579 remove_breakpoint (loc
, mark_uninserted
);
2581 hw_breakpoint_error
= 1;
2582 fprintf_unfiltered (tmp_error_stream
,
2583 "Could not insert hardware watchpoint %d.\n",
2591 /* If a hardware breakpoint or watchpoint was inserted, add a
2592 message about possibly exhausted resources. */
2593 if (hw_breakpoint_error
)
2595 fprintf_unfiltered (tmp_error_stream
,
2596 "Could not insert hardware breakpoints:\n\
2597 You may have requested too many hardware breakpoints/watchpoints.\n");
2599 target_terminal_ours_for_output ();
2600 error_stream (tmp_error_stream
);
2603 do_cleanups (cleanups
);
2606 /* Used when the program stops.
2607 Returns zero if successful, or non-zero if there was a problem
2608 removing a breakpoint location. */
2611 remove_breakpoints (void)
2613 struct bp_location
*bl
, **blp_tmp
;
2616 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2618 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2619 val
|= remove_breakpoint (bl
, mark_uninserted
);
2624 /* Remove breakpoints of process PID. */
2627 remove_breakpoints_pid (int pid
)
2629 struct bp_location
*bl
, **blp_tmp
;
2631 struct inferior
*inf
= find_inferior_pid (pid
);
2633 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2635 if (bl
->pspace
!= inf
->pspace
)
2640 val
= remove_breakpoint (bl
, mark_uninserted
);
2649 reattach_breakpoints (int pid
)
2651 struct cleanup
*old_chain
;
2652 struct bp_location
*bl
, **blp_tmp
;
2654 struct ui_file
*tmp_error_stream
;
2655 int dummy1
= 0, dummy2
= 0;
2656 struct inferior
*inf
;
2657 struct thread_info
*tp
;
2659 tp
= any_live_thread_of_process (pid
);
2663 inf
= find_inferior_pid (pid
);
2664 old_chain
= save_inferior_ptid ();
2666 inferior_ptid
= tp
->ptid
;
2668 tmp_error_stream
= mem_fileopen ();
2669 make_cleanup_ui_file_delete (tmp_error_stream
);
2671 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2673 if (bl
->pspace
!= inf
->pspace
)
2679 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2682 do_cleanups (old_chain
);
2687 do_cleanups (old_chain
);
2691 static int internal_breakpoint_number
= -1;
2693 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2694 If INTERNAL is non-zero, the breakpoint number will be populated
2695 from internal_breakpoint_number and that variable decremented.
2696 Otherwise the breakpoint number will be populated from
2697 breakpoint_count and that value incremented. Internal breakpoints
2698 do not set the internal var bpnum. */
2700 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2703 b
->number
= internal_breakpoint_number
--;
2706 set_breakpoint_count (breakpoint_count
+ 1);
2707 b
->number
= breakpoint_count
;
2711 static struct breakpoint
*
2712 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2713 CORE_ADDR address
, enum bptype type
,
2714 const struct breakpoint_ops
*ops
)
2716 struct symtab_and_line sal
;
2717 struct breakpoint
*b
;
2719 init_sal (&sal
); /* Initialize to zeroes. */
2722 sal
.section
= find_pc_overlay (sal
.pc
);
2723 sal
.pspace
= current_program_space
;
2725 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2726 b
->number
= internal_breakpoint_number
--;
2727 b
->disposition
= disp_donttouch
;
2732 static const char *const longjmp_names
[] =
2734 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2736 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2738 /* Per-objfile data private to breakpoint.c. */
2739 struct breakpoint_objfile_data
2741 /* Minimal symbol for "_ovly_debug_event" (if any). */
2742 struct minimal_symbol
*overlay_msym
;
2744 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2745 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2747 /* True if we have looked for longjmp probes. */
2748 int longjmp_searched
;
2750 /* SystemTap probe points for longjmp (if any). */
2751 VEC (probe_p
) *longjmp_probes
;
2753 /* Minimal symbol for "std::terminate()" (if any). */
2754 struct minimal_symbol
*terminate_msym
;
2756 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2757 struct minimal_symbol
*exception_msym
;
2759 /* True if we have looked for exception probes. */
2760 int exception_searched
;
2762 /* SystemTap probe points for unwinding (if any). */
2763 VEC (probe_p
) *exception_probes
;
2766 static const struct objfile_data
*breakpoint_objfile_key
;
2768 /* Minimal symbol not found sentinel. */
2769 static struct minimal_symbol msym_not_found
;
2771 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2774 msym_not_found_p (const struct minimal_symbol
*msym
)
2776 return msym
== &msym_not_found
;
2779 /* Return per-objfile data needed by breakpoint.c.
2780 Allocate the data if necessary. */
2782 static struct breakpoint_objfile_data
*
2783 get_breakpoint_objfile_data (struct objfile
*objfile
)
2785 struct breakpoint_objfile_data
*bp_objfile_data
;
2787 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2788 if (bp_objfile_data
== NULL
)
2790 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2791 sizeof (*bp_objfile_data
));
2793 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2794 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2796 return bp_objfile_data
;
2800 free_breakpoint_probes (struct objfile
*obj
, void *data
)
2802 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
2804 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
2805 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
2809 create_overlay_event_breakpoint (void)
2811 struct objfile
*objfile
;
2812 const char *const func_name
= "_ovly_debug_event";
2814 ALL_OBJFILES (objfile
)
2816 struct breakpoint
*b
;
2817 struct breakpoint_objfile_data
*bp_objfile_data
;
2820 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2822 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2825 if (bp_objfile_data
->overlay_msym
== NULL
)
2827 struct minimal_symbol
*m
;
2829 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2832 /* Avoid future lookups in this objfile. */
2833 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2836 bp_objfile_data
->overlay_msym
= m
;
2839 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2840 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2842 &internal_breakpoint_ops
);
2843 b
->addr_string
= xstrdup (func_name
);
2845 if (overlay_debugging
== ovly_auto
)
2847 b
->enable_state
= bp_enabled
;
2848 overlay_events_enabled
= 1;
2852 b
->enable_state
= bp_disabled
;
2853 overlay_events_enabled
= 0;
2856 update_global_location_list (1);
2860 create_longjmp_master_breakpoint (void)
2862 struct program_space
*pspace
;
2863 struct cleanup
*old_chain
;
2865 old_chain
= save_current_program_space ();
2867 ALL_PSPACES (pspace
)
2869 struct objfile
*objfile
;
2871 set_current_program_space (pspace
);
2873 ALL_OBJFILES (objfile
)
2876 struct gdbarch
*gdbarch
;
2877 struct breakpoint_objfile_data
*bp_objfile_data
;
2879 gdbarch
= get_objfile_arch (objfile
);
2880 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2883 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2885 if (!bp_objfile_data
->longjmp_searched
)
2887 bp_objfile_data
->longjmp_probes
2888 = find_probes_in_objfile (objfile
, "libc", "longjmp");
2889 bp_objfile_data
->longjmp_searched
= 1;
2892 if (bp_objfile_data
->longjmp_probes
!= NULL
)
2895 struct probe
*probe
;
2896 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2899 VEC_iterate (probe_p
,
2900 bp_objfile_data
->longjmp_probes
,
2904 struct breakpoint
*b
;
2906 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
2908 &internal_breakpoint_ops
);
2909 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
2910 b
->enable_state
= bp_disabled
;
2916 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2918 struct breakpoint
*b
;
2919 const char *func_name
;
2922 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2925 func_name
= longjmp_names
[i
];
2926 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2928 struct minimal_symbol
*m
;
2930 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2933 /* Prevent future lookups in this objfile. */
2934 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2937 bp_objfile_data
->longjmp_msym
[i
] = m
;
2940 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2941 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2942 &internal_breakpoint_ops
);
2943 b
->addr_string
= xstrdup (func_name
);
2944 b
->enable_state
= bp_disabled
;
2948 update_global_location_list (1);
2950 do_cleanups (old_chain
);
2953 /* Create a master std::terminate breakpoint. */
2955 create_std_terminate_master_breakpoint (void)
2957 struct program_space
*pspace
;
2958 struct cleanup
*old_chain
;
2959 const char *const func_name
= "std::terminate()";
2961 old_chain
= save_current_program_space ();
2963 ALL_PSPACES (pspace
)
2965 struct objfile
*objfile
;
2968 set_current_program_space (pspace
);
2970 ALL_OBJFILES (objfile
)
2972 struct breakpoint
*b
;
2973 struct breakpoint_objfile_data
*bp_objfile_data
;
2975 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2977 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2980 if (bp_objfile_data
->terminate_msym
== NULL
)
2982 struct minimal_symbol
*m
;
2984 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2985 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2986 && MSYMBOL_TYPE (m
) != mst_file_text
))
2988 /* Prevent future lookups in this objfile. */
2989 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2992 bp_objfile_data
->terminate_msym
= m
;
2995 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2996 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2997 bp_std_terminate_master
,
2998 &internal_breakpoint_ops
);
2999 b
->addr_string
= xstrdup (func_name
);
3000 b
->enable_state
= bp_disabled
;
3004 update_global_location_list (1);
3006 do_cleanups (old_chain
);
3009 /* Install a master breakpoint on the unwinder's debug hook. */
3012 create_exception_master_breakpoint (void)
3014 struct objfile
*objfile
;
3015 const char *const func_name
= "_Unwind_DebugHook";
3017 ALL_OBJFILES (objfile
)
3019 struct breakpoint
*b
;
3020 struct gdbarch
*gdbarch
;
3021 struct breakpoint_objfile_data
*bp_objfile_data
;
3024 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3026 /* We prefer the SystemTap probe point if it exists. */
3027 if (!bp_objfile_data
->exception_searched
)
3029 bp_objfile_data
->exception_probes
3030 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3031 bp_objfile_data
->exception_searched
= 1;
3034 if (bp_objfile_data
->exception_probes
!= NULL
)
3036 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3038 struct probe
*probe
;
3041 VEC_iterate (probe_p
,
3042 bp_objfile_data
->exception_probes
,
3046 struct breakpoint
*b
;
3048 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3049 bp_exception_master
,
3050 &internal_breakpoint_ops
);
3051 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3052 b
->enable_state
= bp_disabled
;
3058 /* Otherwise, try the hook function. */
3060 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
3063 gdbarch
= get_objfile_arch (objfile
);
3065 if (bp_objfile_data
->exception_msym
== NULL
)
3067 struct minimal_symbol
*debug_hook
;
3069 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3070 if (debug_hook
== NULL
)
3072 bp_objfile_data
->exception_msym
= &msym_not_found
;
3076 bp_objfile_data
->exception_msym
= debug_hook
;
3079 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3080 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3082 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3083 &internal_breakpoint_ops
);
3084 b
->addr_string
= xstrdup (func_name
);
3085 b
->enable_state
= bp_disabled
;
3088 update_global_location_list (1);
3092 update_breakpoints_after_exec (void)
3094 struct breakpoint
*b
, *b_tmp
;
3095 struct bp_location
*bploc
, **bplocp_tmp
;
3097 /* We're about to delete breakpoints from GDB's lists. If the
3098 INSERTED flag is true, GDB will try to lift the breakpoints by
3099 writing the breakpoints' "shadow contents" back into memory. The
3100 "shadow contents" are NOT valid after an exec, so GDB should not
3101 do that. Instead, the target is responsible from marking
3102 breakpoints out as soon as it detects an exec. We don't do that
3103 here instead, because there may be other attempts to delete
3104 breakpoints after detecting an exec and before reaching here. */
3105 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3106 if (bploc
->pspace
== current_program_space
)
3107 gdb_assert (!bploc
->inserted
);
3109 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3111 if (b
->pspace
!= current_program_space
)
3114 /* Solib breakpoints must be explicitly reset after an exec(). */
3115 if (b
->type
== bp_shlib_event
)
3117 delete_breakpoint (b
);
3121 /* JIT breakpoints must be explicitly reset after an exec(). */
3122 if (b
->type
== bp_jit_event
)
3124 delete_breakpoint (b
);
3128 /* Thread event breakpoints must be set anew after an exec(),
3129 as must overlay event and longjmp master breakpoints. */
3130 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3131 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3132 || b
->type
== bp_exception_master
)
3134 delete_breakpoint (b
);
3138 /* Step-resume breakpoints are meaningless after an exec(). */
3139 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3141 delete_breakpoint (b
);
3145 /* Longjmp and longjmp-resume breakpoints are also meaningless
3147 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3148 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3150 delete_breakpoint (b
);
3154 if (b
->type
== bp_catchpoint
)
3156 /* For now, none of the bp_catchpoint breakpoints need to
3157 do anything at this point. In the future, if some of
3158 the catchpoints need to something, we will need to add
3159 a new method, and call this method from here. */
3163 /* bp_finish is a special case. The only way we ought to be able
3164 to see one of these when an exec() has happened, is if the user
3165 caught a vfork, and then said "finish". Ordinarily a finish just
3166 carries them to the call-site of the current callee, by setting
3167 a temporary bp there and resuming. But in this case, the finish
3168 will carry them entirely through the vfork & exec.
3170 We don't want to allow a bp_finish to remain inserted now. But
3171 we can't safely delete it, 'cause finish_command has a handle to
3172 the bp on a bpstat, and will later want to delete it. There's a
3173 chance (and I've seen it happen) that if we delete the bp_finish
3174 here, that its storage will get reused by the time finish_command
3175 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3176 We really must allow finish_command to delete a bp_finish.
3178 In the absence of a general solution for the "how do we know
3179 it's safe to delete something others may have handles to?"
3180 problem, what we'll do here is just uninsert the bp_finish, and
3181 let finish_command delete it.
3183 (We know the bp_finish is "doomed" in the sense that it's
3184 momentary, and will be deleted as soon as finish_command sees
3185 the inferior stopped. So it doesn't matter that the bp's
3186 address is probably bogus in the new a.out, unlike e.g., the
3187 solib breakpoints.) */
3189 if (b
->type
== bp_finish
)
3194 /* Without a symbolic address, we have little hope of the
3195 pre-exec() address meaning the same thing in the post-exec()
3197 if (b
->addr_string
== NULL
)
3199 delete_breakpoint (b
);
3203 /* FIXME what about longjmp breakpoints? Re-create them here? */
3204 create_overlay_event_breakpoint ();
3205 create_longjmp_master_breakpoint ();
3206 create_std_terminate_master_breakpoint ();
3207 create_exception_master_breakpoint ();
3211 detach_breakpoints (int pid
)
3213 struct bp_location
*bl
, **blp_tmp
;
3215 struct cleanup
*old_chain
= save_inferior_ptid ();
3216 struct inferior
*inf
= current_inferior ();
3218 if (pid
== PIDGET (inferior_ptid
))
3219 error (_("Cannot detach breakpoints of inferior_ptid"));
3221 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3222 inferior_ptid
= pid_to_ptid (pid
);
3223 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3225 if (bl
->pspace
!= inf
->pspace
)
3229 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3232 /* Detach single-step breakpoints as well. */
3233 detach_single_step_breakpoints ();
3235 do_cleanups (old_chain
);
3239 /* Remove the breakpoint location BL from the current address space.
3240 Note that this is used to detach breakpoints from a child fork.
3241 When we get here, the child isn't in the inferior list, and neither
3242 do we have objects to represent its address space --- we should
3243 *not* look at bl->pspace->aspace here. */
3246 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3250 /* BL is never in moribund_locations by our callers. */
3251 gdb_assert (bl
->owner
!= NULL
);
3253 if (bl
->owner
->enable_state
== bp_permanent
)
3254 /* Permanent breakpoints cannot be inserted or removed. */
3257 /* The type of none suggests that owner is actually deleted.
3258 This should not ever happen. */
3259 gdb_assert (bl
->owner
->type
!= bp_none
);
3261 if (bl
->loc_type
== bp_loc_software_breakpoint
3262 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3264 /* "Normal" instruction breakpoint: either the standard
3265 trap-instruction bp (bp_breakpoint), or a
3266 bp_hardware_breakpoint. */
3268 /* First check to see if we have to handle an overlay. */
3269 if (overlay_debugging
== ovly_off
3270 || bl
->section
== NULL
3271 || !(section_is_overlay (bl
->section
)))
3273 /* No overlay handling: just remove the breakpoint. */
3274 val
= bl
->owner
->ops
->remove_location (bl
);
3278 /* This breakpoint is in an overlay section.
3279 Did we set a breakpoint at the LMA? */
3280 if (!overlay_events_enabled
)
3282 /* Yes -- overlay event support is not active, so we
3283 should have set a breakpoint at the LMA. Remove it.
3285 /* Ignore any failures: if the LMA is in ROM, we will
3286 have already warned when we failed to insert it. */
3287 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3288 target_remove_hw_breakpoint (bl
->gdbarch
,
3289 &bl
->overlay_target_info
);
3291 target_remove_breakpoint (bl
->gdbarch
,
3292 &bl
->overlay_target_info
);
3294 /* Did we set a breakpoint at the VMA?
3295 If so, we will have marked the breakpoint 'inserted'. */
3298 /* Yes -- remove it. Previously we did not bother to
3299 remove the breakpoint if the section had been
3300 unmapped, but let's not rely on that being safe. We
3301 don't know what the overlay manager might do. */
3303 /* However, we should remove *software* breakpoints only
3304 if the section is still mapped, or else we overwrite
3305 wrong code with the saved shadow contents. */
3306 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3307 || section_is_mapped (bl
->section
))
3308 val
= bl
->owner
->ops
->remove_location (bl
);
3314 /* No -- not inserted, so no need to remove. No error. */
3319 /* In some cases, we might not be able to remove a breakpoint
3320 in a shared library that has already been removed, but we
3321 have not yet processed the shlib unload event. */
3322 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3327 bl
->inserted
= (is
== mark_inserted
);
3329 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3331 gdb_assert (bl
->owner
->ops
!= NULL
3332 && bl
->owner
->ops
->remove_location
!= NULL
);
3334 bl
->inserted
= (is
== mark_inserted
);
3335 bl
->owner
->ops
->remove_location (bl
);
3337 /* Failure to remove any of the hardware watchpoints comes here. */
3338 if ((is
== mark_uninserted
) && (bl
->inserted
))
3339 warning (_("Could not remove hardware watchpoint %d."),
3342 else if (bl
->owner
->type
== bp_catchpoint
3343 && breakpoint_enabled (bl
->owner
)
3346 gdb_assert (bl
->owner
->ops
!= NULL
3347 && bl
->owner
->ops
->remove_location
!= NULL
);
3349 val
= bl
->owner
->ops
->remove_location (bl
);
3353 bl
->inserted
= (is
== mark_inserted
);
3360 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3363 struct cleanup
*old_chain
;
3365 /* BL is never in moribund_locations by our callers. */
3366 gdb_assert (bl
->owner
!= NULL
);
3368 if (bl
->owner
->enable_state
== bp_permanent
)
3369 /* Permanent breakpoints cannot be inserted or removed. */
3372 /* The type of none suggests that owner is actually deleted.
3373 This should not ever happen. */
3374 gdb_assert (bl
->owner
->type
!= bp_none
);
3376 old_chain
= save_current_space_and_thread ();
3378 switch_to_program_space_and_thread (bl
->pspace
);
3380 ret
= remove_breakpoint_1 (bl
, is
);
3382 do_cleanups (old_chain
);
3386 /* Clear the "inserted" flag in all breakpoints. */
3389 mark_breakpoints_out (void)
3391 struct bp_location
*bl
, **blp_tmp
;
3393 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3394 if (bl
->pspace
== current_program_space
)
3398 /* Clear the "inserted" flag in all breakpoints and delete any
3399 breakpoints which should go away between runs of the program.
3401 Plus other such housekeeping that has to be done for breakpoints
3404 Note: this function gets called at the end of a run (by
3405 generic_mourn_inferior) and when a run begins (by
3406 init_wait_for_inferior). */
3411 breakpoint_init_inferior (enum inf_context context
)
3413 struct breakpoint
*b
, *b_tmp
;
3414 struct bp_location
*bl
, **blp_tmp
;
3416 struct program_space
*pspace
= current_program_space
;
3418 /* If breakpoint locations are shared across processes, then there's
3420 if (gdbarch_has_global_breakpoints (target_gdbarch
))
3423 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3425 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3426 if (bl
->pspace
== pspace
3427 && bl
->owner
->enable_state
!= bp_permanent
)
3431 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3433 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3440 /* If the call dummy breakpoint is at the entry point it will
3441 cause problems when the inferior is rerun, so we better get
3444 case bp_watchpoint_scope
:
3446 /* Also get rid of scope breakpoints. */
3448 case bp_shlib_event
:
3450 /* Also remove solib event breakpoints. Their addresses may
3451 have changed since the last time we ran the program.
3452 Actually we may now be debugging against different target;
3453 and so the solib backend that installed this breakpoint may
3454 not be used in by the target. E.g.,
3456 (gdb) file prog-linux
3457 (gdb) run # native linux target
3460 (gdb) file prog-win.exe
3461 (gdb) tar rem :9999 # remote Windows gdbserver.
3464 case bp_step_resume
:
3466 /* Also remove step-resume breakpoints. */
3468 delete_breakpoint (b
);
3472 case bp_hardware_watchpoint
:
3473 case bp_read_watchpoint
:
3474 case bp_access_watchpoint
:
3476 struct watchpoint
*w
= (struct watchpoint
*) b
;
3478 /* Likewise for watchpoints on local expressions. */
3479 if (w
->exp_valid_block
!= NULL
)
3480 delete_breakpoint (b
);
3481 else if (context
== inf_starting
)
3483 /* Reset val field to force reread of starting value in
3484 insert_breakpoints. */
3486 value_free (w
->val
);
3497 /* Get rid of the moribund locations. */
3498 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3499 decref_bp_location (&bl
);
3500 VEC_free (bp_location_p
, moribund_locations
);
3503 /* These functions concern about actual breakpoints inserted in the
3504 target --- to e.g. check if we need to do decr_pc adjustment or if
3505 we need to hop over the bkpt --- so we check for address space
3506 match, not program space. */
3508 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3509 exists at PC. It returns ordinary_breakpoint_here if it's an
3510 ordinary breakpoint, or permanent_breakpoint_here if it's a
3511 permanent breakpoint.
3512 - When continuing from a location with an ordinary breakpoint, we
3513 actually single step once before calling insert_breakpoints.
3514 - When continuing from a location with a permanent breakpoint, we
3515 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3516 the target, to advance the PC past the breakpoint. */
3518 enum breakpoint_here
3519 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3521 struct bp_location
*bl
, **blp_tmp
;
3522 int any_breakpoint_here
= 0;
3524 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3526 if (bl
->loc_type
!= bp_loc_software_breakpoint
3527 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3530 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3531 if ((breakpoint_enabled (bl
->owner
)
3532 || bl
->owner
->enable_state
== bp_permanent
)
3533 && breakpoint_location_address_match (bl
, aspace
, pc
))
3535 if (overlay_debugging
3536 && section_is_overlay (bl
->section
)
3537 && !section_is_mapped (bl
->section
))
3538 continue; /* unmapped overlay -- can't be a match */
3539 else if (bl
->owner
->enable_state
== bp_permanent
)
3540 return permanent_breakpoint_here
;
3542 any_breakpoint_here
= 1;
3546 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
3549 /* Return true if there's a moribund breakpoint at PC. */
3552 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3554 struct bp_location
*loc
;
3557 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3558 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3564 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3565 inserted using regular breakpoint_chain / bp_location array
3566 mechanism. This does not check for single-step breakpoints, which
3567 are inserted and removed using direct target manipulation. */
3570 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
3573 struct bp_location
*bl
, **blp_tmp
;
3575 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3577 if (bl
->loc_type
!= bp_loc_software_breakpoint
3578 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3582 && breakpoint_location_address_match (bl
, aspace
, pc
))
3584 if (overlay_debugging
3585 && section_is_overlay (bl
->section
)
3586 && !section_is_mapped (bl
->section
))
3587 continue; /* unmapped overlay -- can't be a match */
3595 /* Returns non-zero iff there's either regular breakpoint
3596 or a single step breakpoint inserted at PC. */
3599 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3601 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3604 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3610 /* This function returns non-zero iff there is a software breakpoint
3614 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3617 struct bp_location
*bl
, **blp_tmp
;
3619 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3621 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3625 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3628 if (overlay_debugging
3629 && section_is_overlay (bl
->section
)
3630 && !section_is_mapped (bl
->section
))
3631 continue; /* unmapped overlay -- can't be a match */
3637 /* Also check for software single-step breakpoints. */
3638 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3645 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3646 CORE_ADDR addr
, ULONGEST len
)
3648 struct breakpoint
*bpt
;
3650 ALL_BREAKPOINTS (bpt
)
3652 struct bp_location
*loc
;
3654 if (bpt
->type
!= bp_hardware_watchpoint
3655 && bpt
->type
!= bp_access_watchpoint
)
3658 if (!breakpoint_enabled (bpt
))
3661 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3662 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3666 /* Check for intersection. */
3667 l
= max (loc
->address
, addr
);
3668 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3676 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3677 PC is valid for process/thread PTID. */
3680 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3683 struct bp_location
*bl
, **blp_tmp
;
3684 /* The thread and task IDs associated to PTID, computed lazily. */
3688 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3690 if (bl
->loc_type
!= bp_loc_software_breakpoint
3691 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3694 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3695 if (!breakpoint_enabled (bl
->owner
)
3696 && bl
->owner
->enable_state
!= bp_permanent
)
3699 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3702 if (bl
->owner
->thread
!= -1)
3704 /* This is a thread-specific breakpoint. Check that ptid
3705 matches that thread. If thread hasn't been computed yet,
3706 it is now time to do so. */
3708 thread
= pid_to_thread_id (ptid
);
3709 if (bl
->owner
->thread
!= thread
)
3713 if (bl
->owner
->task
!= 0)
3715 /* This is a task-specific breakpoint. Check that ptid
3716 matches that task. If task hasn't been computed yet,
3717 it is now time to do so. */
3719 task
= ada_get_task_number (ptid
);
3720 if (bl
->owner
->task
!= task
)
3724 if (overlay_debugging
3725 && section_is_overlay (bl
->section
)
3726 && !section_is_mapped (bl
->section
))
3727 continue; /* unmapped overlay -- can't be a match */
3736 /* bpstat stuff. External routines' interfaces are documented
3740 is_catchpoint (struct breakpoint
*ep
)
3742 return (ep
->type
== bp_catchpoint
);
3745 /* Frees any storage that is part of a bpstat. Does not walk the
3749 bpstat_free (bpstat bs
)
3751 if (bs
->old_val
!= NULL
)
3752 value_free (bs
->old_val
);
3753 decref_counted_command_line (&bs
->commands
);
3754 decref_bp_location (&bs
->bp_location_at
);
3758 /* Clear a bpstat so that it says we are not at any breakpoint.
3759 Also free any storage that is part of a bpstat. */
3762 bpstat_clear (bpstat
*bsp
)
3779 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3780 is part of the bpstat is copied as well. */
3783 bpstat_copy (bpstat bs
)
3787 bpstat retval
= NULL
;
3792 for (; bs
!= NULL
; bs
= bs
->next
)
3794 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3795 memcpy (tmp
, bs
, sizeof (*tmp
));
3796 incref_counted_command_line (tmp
->commands
);
3797 incref_bp_location (tmp
->bp_location_at
);
3798 if (bs
->old_val
!= NULL
)
3800 tmp
->old_val
= value_copy (bs
->old_val
);
3801 release_value (tmp
->old_val
);
3805 /* This is the first thing in the chain. */
3815 /* Find the bpstat associated with this breakpoint. */
3818 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3823 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3825 if (bsp
->breakpoint_at
== breakpoint
)
3831 /* Put in *NUM the breakpoint number of the first breakpoint we are
3832 stopped at. *BSP upon return is a bpstat which points to the
3833 remaining breakpoints stopped at (but which is not guaranteed to be
3834 good for anything but further calls to bpstat_num).
3836 Return 0 if passed a bpstat which does not indicate any breakpoints.
3837 Return -1 if stopped at a breakpoint that has been deleted since
3839 Return 1 otherwise. */
3842 bpstat_num (bpstat
*bsp
, int *num
)
3844 struct breakpoint
*b
;
3847 return 0; /* No more breakpoint values */
3849 /* We assume we'll never have several bpstats that correspond to a
3850 single breakpoint -- otherwise, this function might return the
3851 same number more than once and this will look ugly. */
3852 b
= (*bsp
)->breakpoint_at
;
3853 *bsp
= (*bsp
)->next
;
3855 return -1; /* breakpoint that's been deleted since */
3857 *num
= b
->number
; /* We have its number */
3861 /* See breakpoint.h. */
3864 bpstat_clear_actions (void)
3866 struct thread_info
*tp
;
3869 if (ptid_equal (inferior_ptid
, null_ptid
))
3872 tp
= find_thread_ptid (inferior_ptid
);
3876 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3878 decref_counted_command_line (&bs
->commands
);
3880 if (bs
->old_val
!= NULL
)
3882 value_free (bs
->old_val
);
3888 /* Called when a command is about to proceed the inferior. */
3891 breakpoint_about_to_proceed (void)
3893 if (!ptid_equal (inferior_ptid
, null_ptid
))
3895 struct thread_info
*tp
= inferior_thread ();
3897 /* Allow inferior function calls in breakpoint commands to not
3898 interrupt the command list. When the call finishes
3899 successfully, the inferior will be standing at the same
3900 breakpoint as if nothing happened. */
3901 if (tp
->control
.in_infcall
)
3905 breakpoint_proceeded
= 1;
3908 /* Stub for cleaning up our state if we error-out of a breakpoint
3911 cleanup_executing_breakpoints (void *ignore
)
3913 executing_breakpoint_commands
= 0;
3916 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3917 or its equivalent. */
3920 command_line_is_silent (struct command_line
*cmd
)
3922 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3923 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3926 /* Execute all the commands associated with all the breakpoints at
3927 this location. Any of these commands could cause the process to
3928 proceed beyond this point, etc. We look out for such changes by
3929 checking the global "breakpoint_proceeded" after each command.
3931 Returns true if a breakpoint command resumed the inferior. In that
3932 case, it is the caller's responsibility to recall it again with the
3933 bpstat of the current thread. */
3936 bpstat_do_actions_1 (bpstat
*bsp
)
3939 struct cleanup
*old_chain
;
3942 /* Avoid endless recursion if a `source' command is contained
3944 if (executing_breakpoint_commands
)
3947 executing_breakpoint_commands
= 1;
3948 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3950 prevent_dont_repeat ();
3952 /* This pointer will iterate over the list of bpstat's. */
3955 breakpoint_proceeded
= 0;
3956 for (; bs
!= NULL
; bs
= bs
->next
)
3958 struct counted_command_line
*ccmd
;
3959 struct command_line
*cmd
;
3960 struct cleanup
*this_cmd_tree_chain
;
3962 /* Take ownership of the BSP's command tree, if it has one.
3964 The command tree could legitimately contain commands like
3965 'step' and 'next', which call clear_proceed_status, which
3966 frees stop_bpstat's command tree. To make sure this doesn't
3967 free the tree we're executing out from under us, we need to
3968 take ownership of the tree ourselves. Since a given bpstat's
3969 commands are only executed once, we don't need to copy it; we
3970 can clear the pointer in the bpstat, and make sure we free
3971 the tree when we're done. */
3972 ccmd
= bs
->commands
;
3973 bs
->commands
= NULL
;
3974 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
3975 cmd
= ccmd
? ccmd
->commands
: NULL
;
3976 if (command_line_is_silent (cmd
))
3978 /* The action has been already done by bpstat_stop_status. */
3984 execute_control_command (cmd
);
3986 if (breakpoint_proceeded
)
3992 /* We can free this command tree now. */
3993 do_cleanups (this_cmd_tree_chain
);
3995 if (breakpoint_proceeded
)
3997 if (target_can_async_p ())
3998 /* If we are in async mode, then the target might be still
3999 running, not stopped at any breakpoint, so nothing for
4000 us to do here -- just return to the event loop. */
4003 /* In sync mode, when execute_control_command returns
4004 we're already standing on the next breakpoint.
4005 Breakpoint commands for that stop were not run, since
4006 execute_command does not run breakpoint commands --
4007 only command_line_handler does, but that one is not
4008 involved in execution of breakpoint commands. So, we
4009 can now execute breakpoint commands. It should be
4010 noted that making execute_command do bpstat actions is
4011 not an option -- in this case we'll have recursive
4012 invocation of bpstat for each breakpoint with a
4013 command, and can easily blow up GDB stack. Instead, we
4014 return true, which will trigger the caller to recall us
4015 with the new stop_bpstat. */
4020 do_cleanups (old_chain
);
4025 bpstat_do_actions (void)
4027 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4029 /* Do any commands attached to breakpoint we are stopped at. */
4030 while (!ptid_equal (inferior_ptid
, null_ptid
)
4031 && target_has_execution
4032 && !is_exited (inferior_ptid
)
4033 && !is_executing (inferior_ptid
))
4034 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4035 and only return when it is stopped at the next breakpoint, we
4036 keep doing breakpoint actions until it returns false to
4037 indicate the inferior was not resumed. */
4038 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4041 discard_cleanups (cleanup_if_error
);
4044 /* Print out the (old or new) value associated with a watchpoint. */
4047 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4050 fprintf_unfiltered (stream
, _("<unreadable>"));
4053 struct value_print_options opts
;
4054 get_user_print_options (&opts
);
4055 value_print (val
, stream
, &opts
);
4059 /* Generic routine for printing messages indicating why we
4060 stopped. The behavior of this function depends on the value
4061 'print_it' in the bpstat structure. Under some circumstances we
4062 may decide not to print anything here and delegate the task to
4065 static enum print_stop_action
4066 print_bp_stop_message (bpstat bs
)
4068 switch (bs
->print_it
)
4071 /* Nothing should be printed for this bpstat entry. */
4072 return PRINT_UNKNOWN
;
4076 /* We still want to print the frame, but we already printed the
4077 relevant messages. */
4078 return PRINT_SRC_AND_LOC
;
4081 case print_it_normal
:
4083 struct breakpoint
*b
= bs
->breakpoint_at
;
4085 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4086 which has since been deleted. */
4088 return PRINT_UNKNOWN
;
4090 /* Normal case. Call the breakpoint's print_it method. */
4091 return b
->ops
->print_it (bs
);
4096 internal_error (__FILE__
, __LINE__
,
4097 _("print_bp_stop_message: unrecognized enum value"));
4102 /* A helper function that prints a shared library stopped event. */
4105 print_solib_event (int is_catchpoint
)
4108 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4110 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4114 if (any_added
|| any_deleted
)
4115 ui_out_text (current_uiout
,
4116 _("Stopped due to shared library event:\n"));
4118 ui_out_text (current_uiout
,
4119 _("Stopped due to shared library event (no "
4120 "libraries added or removed)\n"));
4123 if (ui_out_is_mi_like_p (current_uiout
))
4124 ui_out_field_string (current_uiout
, "reason",
4125 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4129 struct cleanup
*cleanup
;
4133 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4134 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4137 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4142 ui_out_text (current_uiout
, " ");
4143 ui_out_field_string (current_uiout
, "library", name
);
4144 ui_out_text (current_uiout
, "\n");
4147 do_cleanups (cleanup
);
4152 struct so_list
*iter
;
4154 struct cleanup
*cleanup
;
4156 ui_out_text (current_uiout
, _(" Inferior loaded "));
4157 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4160 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4165 ui_out_text (current_uiout
, " ");
4166 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4167 ui_out_text (current_uiout
, "\n");
4170 do_cleanups (cleanup
);
4174 /* Print a message indicating what happened. This is called from
4175 normal_stop(). The input to this routine is the head of the bpstat
4176 list - a list of the eventpoints that caused this stop. KIND is
4177 the target_waitkind for the stopping event. This
4178 routine calls the generic print routine for printing a message
4179 about reasons for stopping. This will print (for example) the
4180 "Breakpoint n," part of the output. The return value of this
4183 PRINT_UNKNOWN: Means we printed nothing.
4184 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4185 code to print the location. An example is
4186 "Breakpoint 1, " which should be followed by
4188 PRINT_SRC_ONLY: Means we printed something, but there is no need
4189 to also print the location part of the message.
4190 An example is the catch/throw messages, which
4191 don't require a location appended to the end.
4192 PRINT_NOTHING: We have done some printing and we don't need any
4193 further info to be printed. */
4195 enum print_stop_action
4196 bpstat_print (bpstat bs
, int kind
)
4200 /* Maybe another breakpoint in the chain caused us to stop.
4201 (Currently all watchpoints go on the bpstat whether hit or not.
4202 That probably could (should) be changed, provided care is taken
4203 with respect to bpstat_explains_signal). */
4204 for (; bs
; bs
= bs
->next
)
4206 val
= print_bp_stop_message (bs
);
4207 if (val
== PRINT_SRC_ONLY
4208 || val
== PRINT_SRC_AND_LOC
4209 || val
== PRINT_NOTHING
)
4213 /* If we had hit a shared library event breakpoint,
4214 print_bp_stop_message would print out this message. If we hit an
4215 OS-level shared library event, do the same thing. */
4216 if (kind
== TARGET_WAITKIND_LOADED
)
4218 print_solib_event (0);
4219 return PRINT_NOTHING
;
4222 /* We reached the end of the chain, or we got a null BS to start
4223 with and nothing was printed. */
4224 return PRINT_UNKNOWN
;
4227 /* Evaluate the expression EXP and return 1 if value is zero. This is
4228 used inside a catch_errors to evaluate the breakpoint condition.
4229 The argument is a "struct expression *" that has been cast to a
4230 "char *" to make it pass through catch_errors. */
4233 breakpoint_cond_eval (void *exp
)
4235 struct value
*mark
= value_mark ();
4236 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4238 value_free_to_mark (mark
);
4242 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4245 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4249 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4251 **bs_link_pointer
= bs
;
4252 *bs_link_pointer
= &bs
->next
;
4253 bs
->breakpoint_at
= bl
->owner
;
4254 bs
->bp_location_at
= bl
;
4255 incref_bp_location (bl
);
4256 /* If the condition is false, etc., don't do the commands. */
4257 bs
->commands
= NULL
;
4259 bs
->print_it
= print_it_normal
;
4263 /* The target has stopped with waitstatus WS. Check if any hardware
4264 watchpoints have triggered, according to the target. */
4267 watchpoints_triggered (struct target_waitstatus
*ws
)
4269 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4271 struct breakpoint
*b
;
4273 if (!stopped_by_watchpoint
)
4275 /* We were not stopped by a watchpoint. Mark all watchpoints
4276 as not triggered. */
4278 if (is_hardware_watchpoint (b
))
4280 struct watchpoint
*w
= (struct watchpoint
*) b
;
4282 w
->watchpoint_triggered
= watch_triggered_no
;
4288 if (!target_stopped_data_address (¤t_target
, &addr
))
4290 /* We were stopped by a watchpoint, but we don't know where.
4291 Mark all watchpoints as unknown. */
4293 if (is_hardware_watchpoint (b
))
4295 struct watchpoint
*w
= (struct watchpoint
*) b
;
4297 w
->watchpoint_triggered
= watch_triggered_unknown
;
4300 return stopped_by_watchpoint
;
4303 /* The target could report the data address. Mark watchpoints
4304 affected by this data address as triggered, and all others as not
4308 if (is_hardware_watchpoint (b
))
4310 struct watchpoint
*w
= (struct watchpoint
*) b
;
4311 struct bp_location
*loc
;
4313 w
->watchpoint_triggered
= watch_triggered_no
;
4314 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4316 if (is_masked_watchpoint (b
))
4318 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4319 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4321 if (newaddr
== start
)
4323 w
->watchpoint_triggered
= watch_triggered_yes
;
4327 /* Exact match not required. Within range is sufficient. */
4328 else if (target_watchpoint_addr_within_range (¤t_target
,
4332 w
->watchpoint_triggered
= watch_triggered_yes
;
4341 /* Possible return values for watchpoint_check (this can't be an enum
4342 because of check_errors). */
4343 /* The watchpoint has been deleted. */
4344 #define WP_DELETED 1
4345 /* The value has changed. */
4346 #define WP_VALUE_CHANGED 2
4347 /* The value has not changed. */
4348 #define WP_VALUE_NOT_CHANGED 3
4349 /* Ignore this watchpoint, no matter if the value changed or not. */
4352 #define BP_TEMPFLAG 1
4353 #define BP_HARDWAREFLAG 2
4355 /* Evaluate watchpoint condition expression and check if its value
4358 P should be a pointer to struct bpstat, but is defined as a void *
4359 in order for this function to be usable with catch_errors. */
4362 watchpoint_check (void *p
)
4364 bpstat bs
= (bpstat
) p
;
4365 struct watchpoint
*b
;
4366 struct frame_info
*fr
;
4367 int within_current_scope
;
4369 /* BS is built from an existing struct breakpoint. */
4370 gdb_assert (bs
->breakpoint_at
!= NULL
);
4371 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4373 /* If this is a local watchpoint, we only want to check if the
4374 watchpoint frame is in scope if the current thread is the thread
4375 that was used to create the watchpoint. */
4376 if (!watchpoint_in_thread_scope (b
))
4379 if (b
->exp_valid_block
== NULL
)
4380 within_current_scope
= 1;
4383 struct frame_info
*frame
= get_current_frame ();
4384 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4385 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4387 /* in_function_epilogue_p() returns a non-zero value if we're
4388 still in the function but the stack frame has already been
4389 invalidated. Since we can't rely on the values of local
4390 variables after the stack has been destroyed, we are treating
4391 the watchpoint in that state as `not changed' without further
4392 checking. Don't mark watchpoints as changed if the current
4393 frame is in an epilogue - even if they are in some other
4394 frame, our view of the stack is likely to be wrong and
4395 frame_find_by_id could error out. */
4396 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4399 fr
= frame_find_by_id (b
->watchpoint_frame
);
4400 within_current_scope
= (fr
!= NULL
);
4402 /* If we've gotten confused in the unwinder, we might have
4403 returned a frame that can't describe this variable. */
4404 if (within_current_scope
)
4406 struct symbol
*function
;
4408 function
= get_frame_function (fr
);
4409 if (function
== NULL
4410 || !contained_in (b
->exp_valid_block
,
4411 SYMBOL_BLOCK_VALUE (function
)))
4412 within_current_scope
= 0;
4415 if (within_current_scope
)
4416 /* If we end up stopping, the current frame will get selected
4417 in normal_stop. So this call to select_frame won't affect
4422 if (within_current_scope
)
4424 /* We use value_{,free_to_}mark because it could be a *long*
4425 time before we return to the command level and call
4426 free_all_values. We can't call free_all_values because we
4427 might be in the middle of evaluating a function call. */
4431 struct value
*new_val
;
4433 if (is_masked_watchpoint (&b
->base
))
4434 /* Since we don't know the exact trigger address (from
4435 stopped_data_address), just tell the user we've triggered
4436 a mask watchpoint. */
4437 return WP_VALUE_CHANGED
;
4439 mark
= value_mark ();
4440 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
4442 /* We use value_equal_contents instead of value_equal because
4443 the latter coerces an array to a pointer, thus comparing just
4444 the address of the array instead of its contents. This is
4445 not what we want. */
4446 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4447 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4449 if (new_val
!= NULL
)
4451 release_value (new_val
);
4452 value_free_to_mark (mark
);
4454 bs
->old_val
= b
->val
;
4457 return WP_VALUE_CHANGED
;
4461 /* Nothing changed. */
4462 value_free_to_mark (mark
);
4463 return WP_VALUE_NOT_CHANGED
;
4468 struct ui_out
*uiout
= current_uiout
;
4470 /* This seems like the only logical thing to do because
4471 if we temporarily ignored the watchpoint, then when
4472 we reenter the block in which it is valid it contains
4473 garbage (in the case of a function, it may have two
4474 garbage values, one before and one after the prologue).
4475 So we can't even detect the first assignment to it and
4476 watch after that (since the garbage may or may not equal
4477 the first value assigned). */
4478 /* We print all the stop information in
4479 breakpoint_ops->print_it, but in this case, by the time we
4480 call breakpoint_ops->print_it this bp will be deleted
4481 already. So we have no choice but print the information
4483 if (ui_out_is_mi_like_p (uiout
))
4485 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4486 ui_out_text (uiout
, "\nWatchpoint ");
4487 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
4489 " deleted because the program has left the block in\n\
4490 which its expression is valid.\n");
4492 /* Make sure the watchpoint's commands aren't executed. */
4493 decref_counted_command_line (&b
->base
.commands
);
4494 watchpoint_del_at_next_stop (b
);
4500 /* Return true if it looks like target has stopped due to hitting
4501 breakpoint location BL. This function does not check if we should
4502 stop, only if BL explains the stop. */
4505 bpstat_check_location (const struct bp_location
*bl
,
4506 struct address_space
*aspace
, CORE_ADDR bp_addr
,
4507 const struct target_waitstatus
*ws
)
4509 struct breakpoint
*b
= bl
->owner
;
4511 /* BL is from an existing breakpoint. */
4512 gdb_assert (b
!= NULL
);
4514 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4517 /* Determine if the watched values have actually changed, and we
4518 should stop. If not, set BS->stop to 0. */
4521 bpstat_check_watchpoint (bpstat bs
)
4523 const struct bp_location
*bl
;
4524 struct watchpoint
*b
;
4526 /* BS is built for existing struct breakpoint. */
4527 bl
= bs
->bp_location_at
;
4528 gdb_assert (bl
!= NULL
);
4529 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4530 gdb_assert (b
!= NULL
);
4533 int must_check_value
= 0;
4535 if (b
->base
.type
== bp_watchpoint
)
4536 /* For a software watchpoint, we must always check the
4538 must_check_value
= 1;
4539 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4540 /* We have a hardware watchpoint (read, write, or access)
4541 and the target earlier reported an address watched by
4543 must_check_value
= 1;
4544 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4545 && b
->base
.type
== bp_hardware_watchpoint
)
4546 /* We were stopped by a hardware watchpoint, but the target could
4547 not report the data address. We must check the watchpoint's
4548 value. Access and read watchpoints are out of luck; without
4549 a data address, we can't figure it out. */
4550 must_check_value
= 1;
4552 if (must_check_value
)
4555 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4557 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4558 int e
= catch_errors (watchpoint_check
, bs
, message
,
4560 do_cleanups (cleanups
);
4564 /* We've already printed what needs to be printed. */
4565 bs
->print_it
= print_it_done
;
4569 bs
->print_it
= print_it_noop
;
4572 case WP_VALUE_CHANGED
:
4573 if (b
->base
.type
== bp_read_watchpoint
)
4575 /* There are two cases to consider here:
4577 1. We're watching the triggered memory for reads.
4578 In that case, trust the target, and always report
4579 the watchpoint hit to the user. Even though
4580 reads don't cause value changes, the value may
4581 have changed since the last time it was read, and
4582 since we're not trapping writes, we will not see
4583 those, and as such we should ignore our notion of
4586 2. We're watching the triggered memory for both
4587 reads and writes. There are two ways this may
4590 2.1. This is a target that can't break on data
4591 reads only, but can break on accesses (reads or
4592 writes), such as e.g., x86. We detect this case
4593 at the time we try to insert read watchpoints.
4595 2.2. Otherwise, the target supports read
4596 watchpoints, but, the user set an access or write
4597 watchpoint watching the same memory as this read
4600 If we're watching memory writes as well as reads,
4601 ignore watchpoint hits when we find that the
4602 value hasn't changed, as reads don't cause
4603 changes. This still gives false positives when
4604 the program writes the same value to memory as
4605 what there was already in memory (we will confuse
4606 it for a read), but it's much better than
4609 int other_write_watchpoint
= 0;
4611 if (bl
->watchpoint_type
== hw_read
)
4613 struct breakpoint
*other_b
;
4615 ALL_BREAKPOINTS (other_b
)
4616 if (other_b
->type
== bp_hardware_watchpoint
4617 || other_b
->type
== bp_access_watchpoint
)
4619 struct watchpoint
*other_w
=
4620 (struct watchpoint
*) other_b
;
4622 if (other_w
->watchpoint_triggered
4623 == watch_triggered_yes
)
4625 other_write_watchpoint
= 1;
4631 if (other_write_watchpoint
4632 || bl
->watchpoint_type
== hw_access
)
4634 /* We're watching the same memory for writes,
4635 and the value changed since the last time we
4636 updated it, so this trap must be for a write.
4638 bs
->print_it
= print_it_noop
;
4643 case WP_VALUE_NOT_CHANGED
:
4644 if (b
->base
.type
== bp_hardware_watchpoint
4645 || b
->base
.type
== bp_watchpoint
)
4647 /* Don't stop: write watchpoints shouldn't fire if
4648 the value hasn't changed. */
4649 bs
->print_it
= print_it_noop
;
4657 /* Error from catch_errors. */
4658 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
4659 watchpoint_del_at_next_stop (b
);
4660 /* We've already printed what needs to be printed. */
4661 bs
->print_it
= print_it_done
;
4665 else /* must_check_value == 0 */
4667 /* This is a case where some watchpoint(s) triggered, but
4668 not at the address of this watchpoint, or else no
4669 watchpoint triggered after all. So don't print
4670 anything for this watchpoint. */
4671 bs
->print_it
= print_it_noop
;
4678 /* Check conditions (condition proper, frame, thread and ignore count)
4679 of breakpoint referred to by BS. If we should not stop for this
4680 breakpoint, set BS->stop to 0. */
4683 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4685 int thread_id
= pid_to_thread_id (ptid
);
4686 const struct bp_location
*bl
;
4687 struct breakpoint
*b
;
4689 /* BS is built for existing struct breakpoint. */
4690 bl
= bs
->bp_location_at
;
4691 gdb_assert (bl
!= NULL
);
4692 b
= bs
->breakpoint_at
;
4693 gdb_assert (b
!= NULL
);
4695 /* Even if the target evaluated the condition on its end and notified GDB, we
4696 need to do so again since GDB does not know if we stopped due to a
4697 breakpoint or a single step breakpoint. */
4699 if (frame_id_p (b
->frame_id
)
4700 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4704 int value_is_zero
= 0;
4705 struct expression
*cond
;
4707 /* Evaluate Python breakpoints that have a "stop"
4708 method implemented. */
4709 if (b
->py_bp_object
)
4710 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4712 if (is_watchpoint (b
))
4714 struct watchpoint
*w
= (struct watchpoint
*) b
;
4721 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4723 int within_current_scope
= 1;
4724 struct watchpoint
* w
;
4726 /* We use value_mark and value_free_to_mark because it could
4727 be a long time before we return to the command level and
4728 call free_all_values. We can't call free_all_values
4729 because we might be in the middle of evaluating a
4731 struct value
*mark
= value_mark ();
4733 if (is_watchpoint (b
))
4734 w
= (struct watchpoint
*) b
;
4738 /* Need to select the frame, with all that implies so that
4739 the conditions will have the right context. Because we
4740 use the frame, we will not see an inlined function's
4741 variables when we arrive at a breakpoint at the start
4742 of the inlined function; the current frame will be the
4744 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4745 select_frame (get_current_frame ());
4748 struct frame_info
*frame
;
4750 /* For local watchpoint expressions, which particular
4751 instance of a local is being watched matters, so we
4752 keep track of the frame to evaluate the expression
4753 in. To evaluate the condition however, it doesn't
4754 really matter which instantiation of the function
4755 where the condition makes sense triggers the
4756 watchpoint. This allows an expression like "watch
4757 global if q > 10" set in `func', catch writes to
4758 global on all threads that call `func', or catch
4759 writes on all recursive calls of `func' by a single
4760 thread. We simply always evaluate the condition in
4761 the innermost frame that's executing where it makes
4762 sense to evaluate the condition. It seems
4764 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4766 select_frame (frame
);
4768 within_current_scope
= 0;
4770 if (within_current_scope
)
4772 = catch_errors (breakpoint_cond_eval
, cond
,
4773 "Error in testing breakpoint condition:\n",
4777 warning (_("Watchpoint condition cannot be tested "
4778 "in the current scope"));
4779 /* If we failed to set the right context for this
4780 watchpoint, unconditionally report it. */
4783 /* FIXME-someday, should give breakpoint #. */
4784 value_free_to_mark (mark
);
4787 if (cond
&& value_is_zero
)
4791 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4795 else if (b
->ignore_count
> 0)
4798 annotate_ignore_count_change ();
4800 /* Increase the hit count even though we don't stop. */
4802 observer_notify_breakpoint_modified (b
);
4808 /* Get a bpstat associated with having just stopped at address
4809 BP_ADDR in thread PTID.
4811 Determine whether we stopped at a breakpoint, etc, or whether we
4812 don't understand this stop. Result is a chain of bpstat's such
4815 if we don't understand the stop, the result is a null pointer.
4817 if we understand why we stopped, the result is not null.
4819 Each element of the chain refers to a particular breakpoint or
4820 watchpoint at which we have stopped. (We may have stopped for
4821 several reasons concurrently.)
4823 Each element of the chain has valid next, breakpoint_at,
4824 commands, FIXME??? fields. */
4827 bpstat_stop_status (struct address_space
*aspace
,
4828 CORE_ADDR bp_addr
, ptid_t ptid
,
4829 const struct target_waitstatus
*ws
)
4831 struct breakpoint
*b
= NULL
;
4832 struct bp_location
*bl
;
4833 struct bp_location
*loc
;
4834 /* First item of allocated bpstat's. */
4835 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4836 /* Pointer to the last thing in the chain currently. */
4839 int need_remove_insert
;
4842 /* First, build the bpstat chain with locations that explain a
4843 target stop, while being careful to not set the target running,
4844 as that may invalidate locations (in particular watchpoint
4845 locations are recreated). Resuming will happen here with
4846 breakpoint conditions or watchpoint expressions that include
4847 inferior function calls. */
4851 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4854 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4856 /* For hardware watchpoints, we look only at the first
4857 location. The watchpoint_check function will work on the
4858 entire expression, not the individual locations. For
4859 read watchpoints, the watchpoints_triggered function has
4860 checked all locations already. */
4861 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4864 if (bl
->shlib_disabled
)
4867 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
4870 /* Come here if it's a watchpoint, or if the break address
4873 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4876 /* Assume we stop. Should we find a watchpoint that is not
4877 actually triggered, or if the condition of the breakpoint
4878 evaluates as false, we'll reset 'stop' to 0. */
4882 /* If this is a scope breakpoint, mark the associated
4883 watchpoint as triggered so that we will handle the
4884 out-of-scope event. We'll get to the watchpoint next
4886 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4888 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4890 w
->watchpoint_triggered
= watch_triggered_yes
;
4895 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4897 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4899 bs
= bpstat_alloc (loc
, &bs_link
);
4900 /* For hits of moribund locations, we should just proceed. */
4903 bs
->print_it
= print_it_noop
;
4907 /* A bit of special processing for shlib breakpoints. We need to
4908 process solib loading here, so that the lists of loaded and
4909 unloaded libraries are correct before we handle "catch load" and
4911 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4913 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
4915 handle_solib_event ();
4920 /* Now go through the locations that caused the target to stop, and
4921 check whether we're interested in reporting this stop to higher
4922 layers, or whether we should resume the target transparently. */
4926 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4931 b
= bs
->breakpoint_at
;
4932 b
->ops
->check_status (bs
);
4935 bpstat_check_breakpoint_conditions (bs
, ptid
);
4940 observer_notify_breakpoint_modified (b
);
4942 /* We will stop here. */
4943 if (b
->disposition
== disp_disable
)
4945 --(b
->enable_count
);
4946 if (b
->enable_count
<= 0
4947 && b
->enable_state
!= bp_permanent
)
4948 b
->enable_state
= bp_disabled
;
4953 bs
->commands
= b
->commands
;
4954 incref_counted_command_line (bs
->commands
);
4955 if (command_line_is_silent (bs
->commands
4956 ? bs
->commands
->commands
: NULL
))
4962 /* Print nothing for this entry if we don't stop or don't
4964 if (!bs
->stop
|| !bs
->print
)
4965 bs
->print_it
= print_it_noop
;
4968 /* If we aren't stopping, the value of some hardware watchpoint may
4969 not have changed, but the intermediate memory locations we are
4970 watching may have. Don't bother if we're stopping; this will get
4972 need_remove_insert
= 0;
4973 if (! bpstat_causes_stop (bs_head
))
4974 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4976 && bs
->breakpoint_at
4977 && is_hardware_watchpoint (bs
->breakpoint_at
))
4979 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4981 update_watchpoint (w
, 0 /* don't reparse. */);
4982 need_remove_insert
= 1;
4985 if (need_remove_insert
)
4986 update_global_location_list (1);
4987 else if (removed_any
)
4988 update_global_location_list (0);
4994 handle_jit_event (void)
4996 struct frame_info
*frame
;
4997 struct gdbarch
*gdbarch
;
4999 /* Switch terminal for any messages produced by
5000 breakpoint_re_set. */
5001 target_terminal_ours_for_output ();
5003 frame
= get_current_frame ();
5004 gdbarch
= get_frame_arch (frame
);
5006 jit_event_handler (gdbarch
);
5008 target_terminal_inferior ();
5011 /* Handle an solib event by calling solib_add. */
5014 handle_solib_event (void)
5016 clear_program_space_solib_cache (current_inferior ()->pspace
);
5018 /* Check for any newly added shared libraries if we're supposed to
5019 be adding them automatically. Switch terminal for any messages
5020 produced by breakpoint_re_set. */
5021 target_terminal_ours_for_output ();
5023 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
5025 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
5027 target_terminal_inferior ();
5030 /* Prepare WHAT final decision for infrun. */
5032 /* Decide what infrun needs to do with this bpstat. */
5035 bpstat_what (bpstat bs_head
)
5037 struct bpstat_what retval
;
5041 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5042 retval
.call_dummy
= STOP_NONE
;
5043 retval
.is_longjmp
= 0;
5045 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5047 /* Extract this BS's action. After processing each BS, we check
5048 if its action overrides all we've seem so far. */
5049 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5052 if (bs
->breakpoint_at
== NULL
)
5054 /* I suspect this can happen if it was a momentary
5055 breakpoint which has since been deleted. */
5059 bptype
= bs
->breakpoint_at
->type
;
5066 case bp_hardware_breakpoint
:
5069 case bp_shlib_event
:
5073 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5075 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5078 this_action
= BPSTAT_WHAT_SINGLE
;
5081 case bp_hardware_watchpoint
:
5082 case bp_read_watchpoint
:
5083 case bp_access_watchpoint
:
5087 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5089 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5093 /* There was a watchpoint, but we're not stopping.
5094 This requires no further action. */
5099 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5100 retval
.is_longjmp
= bptype
== bp_longjmp
;
5102 case bp_longjmp_resume
:
5103 case bp_exception_resume
:
5104 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5105 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5107 case bp_step_resume
:
5109 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5112 /* It is for the wrong frame. */
5113 this_action
= BPSTAT_WHAT_SINGLE
;
5116 case bp_hp_step_resume
:
5118 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5121 /* It is for the wrong frame. */
5122 this_action
= BPSTAT_WHAT_SINGLE
;
5125 case bp_watchpoint_scope
:
5126 case bp_thread_event
:
5127 case bp_overlay_event
:
5128 case bp_longjmp_master
:
5129 case bp_std_terminate_master
:
5130 case bp_exception_master
:
5131 this_action
= BPSTAT_WHAT_SINGLE
;
5137 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5139 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5143 /* There was a catchpoint, but we're not stopping.
5144 This requires no further action. */
5149 this_action
= BPSTAT_WHAT_SINGLE
;
5152 /* Make sure the action is stop (silent or noisy),
5153 so infrun.c pops the dummy frame. */
5154 retval
.call_dummy
= STOP_STACK_DUMMY
;
5155 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5157 case bp_std_terminate
:
5158 /* Make sure the action is stop (silent or noisy),
5159 so infrun.c pops the dummy frame. */
5160 retval
.call_dummy
= STOP_STD_TERMINATE
;
5161 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5164 case bp_fast_tracepoint
:
5165 case bp_static_tracepoint
:
5166 /* Tracepoint hits should not be reported back to GDB, and
5167 if one got through somehow, it should have been filtered
5169 internal_error (__FILE__
, __LINE__
,
5170 _("bpstat_what: tracepoint encountered"));
5172 case bp_gnu_ifunc_resolver
:
5173 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5174 this_action
= BPSTAT_WHAT_SINGLE
;
5176 case bp_gnu_ifunc_resolver_return
:
5177 /* The breakpoint will be removed, execution will restart from the
5178 PC of the former breakpoint. */
5179 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5182 internal_error (__FILE__
, __LINE__
,
5183 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5186 retval
.main_action
= max (retval
.main_action
, this_action
);
5189 /* These operations may affect the bs->breakpoint_at state so they are
5190 delayed after MAIN_ACTION is decided above. */
5195 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5197 handle_jit_event ();
5200 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5202 struct breakpoint
*b
= bs
->breakpoint_at
;
5208 case bp_gnu_ifunc_resolver
:
5209 gnu_ifunc_resolver_stop (b
);
5211 case bp_gnu_ifunc_resolver_return
:
5212 gnu_ifunc_resolver_return_stop (b
);
5220 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5221 without hardware support). This isn't related to a specific bpstat,
5222 just to things like whether watchpoints are set. */
5225 bpstat_should_step (void)
5227 struct breakpoint
*b
;
5230 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5236 bpstat_causes_stop (bpstat bs
)
5238 for (; bs
!= NULL
; bs
= bs
->next
)
5247 /* Compute a string of spaces suitable to indent the next line
5248 so it starts at the position corresponding to the table column
5249 named COL_NAME in the currently active table of UIOUT. */
5252 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5254 static char wrap_indent
[80];
5255 int i
, total_width
, width
, align
;
5259 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5261 if (strcmp (text
, col_name
) == 0)
5263 gdb_assert (total_width
< sizeof wrap_indent
);
5264 memset (wrap_indent
, ' ', total_width
);
5265 wrap_indent
[total_width
] = 0;
5270 total_width
+= width
+ 1;
5276 /* Determine if the locations of this breakpoint will have their conditions
5277 evaluated by the target, host or a mix of both. Returns the following:
5279 "host": Host evals condition.
5280 "host or target": Host or Target evals condition.
5281 "target": Target evals condition.
5285 bp_condition_evaluator (struct breakpoint
*b
)
5287 struct bp_location
*bl
;
5288 char host_evals
= 0;
5289 char target_evals
= 0;
5294 if (!is_breakpoint (b
))
5297 if (gdb_evaluates_breakpoint_condition_p ()
5298 || !target_supports_evaluation_of_breakpoint_conditions ())
5299 return condition_evaluation_host
;
5301 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5303 if (bl
->cond_bytecode
)
5309 if (host_evals
&& target_evals
)
5310 return condition_evaluation_both
;
5311 else if (target_evals
)
5312 return condition_evaluation_target
;
5314 return condition_evaluation_host
;
5317 /* Determine the breakpoint location's condition evaluator. This is
5318 similar to bp_condition_evaluator, but for locations. */
5321 bp_location_condition_evaluator (struct bp_location
*bl
)
5323 if (bl
&& !is_breakpoint (bl
->owner
))
5326 if (gdb_evaluates_breakpoint_condition_p ()
5327 || !target_supports_evaluation_of_breakpoint_conditions ())
5328 return condition_evaluation_host
;
5330 if (bl
&& bl
->cond_bytecode
)
5331 return condition_evaluation_target
;
5333 return condition_evaluation_host
;
5336 /* Print the LOC location out of the list of B->LOC locations. */
5339 print_breakpoint_location (struct breakpoint
*b
,
5340 struct bp_location
*loc
)
5342 struct ui_out
*uiout
= current_uiout
;
5343 struct cleanup
*old_chain
= save_current_program_space ();
5345 if (loc
!= NULL
&& loc
->shlib_disabled
)
5349 set_current_program_space (loc
->pspace
);
5351 if (b
->display_canonical
)
5352 ui_out_field_string (uiout
, "what", b
->addr_string
);
5353 else if (loc
&& loc
->source_file
)
5356 = find_pc_sect_function (loc
->address
, loc
->section
);
5359 ui_out_text (uiout
, "in ");
5360 ui_out_field_string (uiout
, "func",
5361 SYMBOL_PRINT_NAME (sym
));
5362 ui_out_text (uiout
, " ");
5363 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5364 ui_out_text (uiout
, "at ");
5366 ui_out_field_string (uiout
, "file", loc
->source_file
);
5367 ui_out_text (uiout
, ":");
5369 if (ui_out_is_mi_like_p (uiout
))
5371 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
5372 char *fullname
= symtab_to_fullname (sal
.symtab
);
5375 ui_out_field_string (uiout
, "fullname", fullname
);
5378 ui_out_field_int (uiout
, "line", loc
->line_number
);
5382 struct ui_file
*stb
= mem_fileopen ();
5383 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5385 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5387 ui_out_field_stream (uiout
, "at", stb
);
5389 do_cleanups (stb_chain
);
5392 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5394 if (loc
&& is_breakpoint (b
)
5395 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5396 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5398 ui_out_text (uiout
, " (");
5399 ui_out_field_string (uiout
, "evaluated-by",
5400 bp_location_condition_evaluator (loc
));
5401 ui_out_text (uiout
, ")");
5404 do_cleanups (old_chain
);
5408 bptype_string (enum bptype type
)
5410 struct ep_type_description
5415 static struct ep_type_description bptypes
[] =
5417 {bp_none
, "?deleted?"},
5418 {bp_breakpoint
, "breakpoint"},
5419 {bp_hardware_breakpoint
, "hw breakpoint"},
5420 {bp_until
, "until"},
5421 {bp_finish
, "finish"},
5422 {bp_watchpoint
, "watchpoint"},
5423 {bp_hardware_watchpoint
, "hw watchpoint"},
5424 {bp_read_watchpoint
, "read watchpoint"},
5425 {bp_access_watchpoint
, "acc watchpoint"},
5426 {bp_longjmp
, "longjmp"},
5427 {bp_longjmp_resume
, "longjmp resume"},
5428 {bp_exception
, "exception"},
5429 {bp_exception_resume
, "exception resume"},
5430 {bp_step_resume
, "step resume"},
5431 {bp_hp_step_resume
, "high-priority step resume"},
5432 {bp_watchpoint_scope
, "watchpoint scope"},
5433 {bp_call_dummy
, "call dummy"},
5434 {bp_std_terminate
, "std::terminate"},
5435 {bp_shlib_event
, "shlib events"},
5436 {bp_thread_event
, "thread events"},
5437 {bp_overlay_event
, "overlay events"},
5438 {bp_longjmp_master
, "longjmp master"},
5439 {bp_std_terminate_master
, "std::terminate master"},
5440 {bp_exception_master
, "exception master"},
5441 {bp_catchpoint
, "catchpoint"},
5442 {bp_tracepoint
, "tracepoint"},
5443 {bp_fast_tracepoint
, "fast tracepoint"},
5444 {bp_static_tracepoint
, "static tracepoint"},
5445 {bp_jit_event
, "jit events"},
5446 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5447 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5450 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5451 || ((int) type
!= bptypes
[(int) type
].type
))
5452 internal_error (__FILE__
, __LINE__
,
5453 _("bptypes table does not describe type #%d."),
5456 return bptypes
[(int) type
].description
;
5459 /* Print B to gdb_stdout. */
5462 print_one_breakpoint_location (struct breakpoint
*b
,
5463 struct bp_location
*loc
,
5465 struct bp_location
**last_loc
,
5468 struct command_line
*l
;
5469 static char bpenables
[] = "nynny";
5471 struct ui_out
*uiout
= current_uiout
;
5472 int header_of_multiple
= 0;
5473 int part_of_multiple
= (loc
!= NULL
);
5474 struct value_print_options opts
;
5476 get_user_print_options (&opts
);
5478 gdb_assert (!loc
|| loc_number
!= 0);
5479 /* See comment in print_one_breakpoint concerning treatment of
5480 breakpoints with single disabled location. */
5483 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5484 header_of_multiple
= 1;
5492 if (part_of_multiple
)
5495 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
5496 ui_out_field_string (uiout
, "number", formatted
);
5501 ui_out_field_int (uiout
, "number", b
->number
);
5506 if (part_of_multiple
)
5507 ui_out_field_skip (uiout
, "type");
5509 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
5513 if (part_of_multiple
)
5514 ui_out_field_skip (uiout
, "disp");
5516 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
5521 if (part_of_multiple
)
5522 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
5524 ui_out_field_fmt (uiout
, "enabled", "%c",
5525 bpenables
[(int) b
->enable_state
]);
5526 ui_out_spaces (uiout
, 2);
5530 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
5532 /* Although the print_one can possibly print all locations,
5533 calling it here is not likely to get any nice result. So,
5534 make sure there's just one location. */
5535 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
5536 b
->ops
->print_one (b
, last_loc
);
5542 internal_error (__FILE__
, __LINE__
,
5543 _("print_one_breakpoint: bp_none encountered\n"));
5547 case bp_hardware_watchpoint
:
5548 case bp_read_watchpoint
:
5549 case bp_access_watchpoint
:
5551 struct watchpoint
*w
= (struct watchpoint
*) b
;
5553 /* Field 4, the address, is omitted (which makes the columns
5554 not line up too nicely with the headers, but the effect
5555 is relatively readable). */
5556 if (opts
.addressprint
)
5557 ui_out_field_skip (uiout
, "addr");
5559 ui_out_field_string (uiout
, "what", w
->exp_string
);
5564 case bp_hardware_breakpoint
:
5568 case bp_longjmp_resume
:
5570 case bp_exception_resume
:
5571 case bp_step_resume
:
5572 case bp_hp_step_resume
:
5573 case bp_watchpoint_scope
:
5575 case bp_std_terminate
:
5576 case bp_shlib_event
:
5577 case bp_thread_event
:
5578 case bp_overlay_event
:
5579 case bp_longjmp_master
:
5580 case bp_std_terminate_master
:
5581 case bp_exception_master
:
5583 case bp_fast_tracepoint
:
5584 case bp_static_tracepoint
:
5586 case bp_gnu_ifunc_resolver
:
5587 case bp_gnu_ifunc_resolver_return
:
5588 if (opts
.addressprint
)
5591 if (header_of_multiple
)
5592 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
5593 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
5594 ui_out_field_string (uiout
, "addr", "<PENDING>");
5596 ui_out_field_core_addr (uiout
, "addr",
5597 loc
->gdbarch
, loc
->address
);
5600 if (!header_of_multiple
)
5601 print_breakpoint_location (b
, loc
);
5608 /* For backward compatibility, don't display inferiors unless there
5611 && !header_of_multiple
5613 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
5614 && (number_of_program_spaces () > 1
5615 || number_of_inferiors () > 1)
5616 /* LOC is for existing B, it cannot be in
5617 moribund_locations and thus having NULL OWNER. */
5618 && loc
->owner
->type
!= bp_catchpoint
)))
5620 struct inferior
*inf
;
5623 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
5625 if (inf
->pspace
== loc
->pspace
)
5630 ui_out_text (uiout
, " inf ");
5633 ui_out_text (uiout
, ", ");
5634 ui_out_text (uiout
, plongest (inf
->num
));
5639 if (!part_of_multiple
)
5641 if (b
->thread
!= -1)
5643 /* FIXME: This seems to be redundant and lost here; see the
5644 "stop only in" line a little further down. */
5645 ui_out_text (uiout
, " thread ");
5646 ui_out_field_int (uiout
, "thread", b
->thread
);
5648 else if (b
->task
!= 0)
5650 ui_out_text (uiout
, " task ");
5651 ui_out_field_int (uiout
, "task", b
->task
);
5655 ui_out_text (uiout
, "\n");
5657 if (!part_of_multiple
)
5658 b
->ops
->print_one_detail (b
, uiout
);
5660 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
5663 ui_out_text (uiout
, "\tstop only in stack frame at ");
5664 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5666 ui_out_field_core_addr (uiout
, "frame",
5667 b
->gdbarch
, b
->frame_id
.stack_addr
);
5668 ui_out_text (uiout
, "\n");
5671 if (!part_of_multiple
&& b
->cond_string
)
5674 if (is_tracepoint (b
))
5675 ui_out_text (uiout
, "\ttrace only if ");
5677 ui_out_text (uiout
, "\tstop only if ");
5678 ui_out_field_string (uiout
, "cond", b
->cond_string
);
5680 /* Print whether the target is doing the breakpoint's condition
5681 evaluation. If GDB is doing the evaluation, don't print anything. */
5682 if (is_breakpoint (b
)
5683 && breakpoint_condition_evaluation_mode ()
5684 == condition_evaluation_target
)
5686 ui_out_text (uiout
, " (");
5687 ui_out_field_string (uiout
, "evaluated-by",
5688 bp_condition_evaluator (b
));
5689 ui_out_text (uiout
, " evals)");
5691 ui_out_text (uiout
, "\n");
5694 if (!part_of_multiple
&& b
->thread
!= -1)
5696 /* FIXME should make an annotation for this. */
5697 ui_out_text (uiout
, "\tstop only in thread ");
5698 ui_out_field_int (uiout
, "thread", b
->thread
);
5699 ui_out_text (uiout
, "\n");
5702 if (!part_of_multiple
&& b
->hit_count
)
5704 /* FIXME should make an annotation for this. */
5705 if (is_catchpoint (b
))
5706 ui_out_text (uiout
, "\tcatchpoint");
5707 else if (is_tracepoint (b
))
5708 ui_out_text (uiout
, "\ttracepoint");
5710 ui_out_text (uiout
, "\tbreakpoint");
5711 ui_out_text (uiout
, " already hit ");
5712 ui_out_field_int (uiout
, "times", b
->hit_count
);
5713 if (b
->hit_count
== 1)
5714 ui_out_text (uiout
, " time\n");
5716 ui_out_text (uiout
, " times\n");
5719 /* Output the count also if it is zero, but only if this is mi.
5720 FIXME: Should have a better test for this. */
5721 if (ui_out_is_mi_like_p (uiout
))
5722 if (!part_of_multiple
&& b
->hit_count
== 0)
5723 ui_out_field_int (uiout
, "times", b
->hit_count
);
5725 if (!part_of_multiple
&& b
->ignore_count
)
5728 ui_out_text (uiout
, "\tignore next ");
5729 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
5730 ui_out_text (uiout
, " hits\n");
5733 /* Note that an enable count of 1 corresponds to "enable once"
5734 behavior, which is reported by the combination of enablement and
5735 disposition, so we don't need to mention it here. */
5736 if (!part_of_multiple
&& b
->enable_count
> 1)
5739 ui_out_text (uiout
, "\tdisable after ");
5740 /* Tweak the wording to clarify that ignore and enable counts
5741 are distinct, and have additive effect. */
5742 if (b
->ignore_count
)
5743 ui_out_text (uiout
, "additional ");
5745 ui_out_text (uiout
, "next ");
5746 ui_out_field_int (uiout
, "enable", b
->enable_count
);
5747 ui_out_text (uiout
, " hits\n");
5750 if (!part_of_multiple
&& is_tracepoint (b
))
5752 struct tracepoint
*tp
= (struct tracepoint
*) b
;
5754 if (tp
->traceframe_usage
)
5756 ui_out_text (uiout
, "\ttrace buffer usage ");
5757 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
5758 ui_out_text (uiout
, " bytes\n");
5762 l
= b
->commands
? b
->commands
->commands
: NULL
;
5763 if (!part_of_multiple
&& l
)
5765 struct cleanup
*script_chain
;
5768 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
5769 print_command_lines (uiout
, l
, 4);
5770 do_cleanups (script_chain
);
5773 if (is_tracepoint (b
))
5775 struct tracepoint
*t
= (struct tracepoint
*) b
;
5777 if (!part_of_multiple
&& t
->pass_count
)
5779 annotate_field (10);
5780 ui_out_text (uiout
, "\tpass count ");
5781 ui_out_field_int (uiout
, "pass", t
->pass_count
);
5782 ui_out_text (uiout
, " \n");
5786 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5788 if (is_watchpoint (b
))
5790 struct watchpoint
*w
= (struct watchpoint
*) b
;
5792 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
5794 else if (b
->addr_string
)
5795 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5800 print_one_breakpoint (struct breakpoint
*b
,
5801 struct bp_location
**last_loc
,
5804 struct cleanup
*bkpt_chain
;
5805 struct ui_out
*uiout
= current_uiout
;
5807 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5809 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5810 do_cleanups (bkpt_chain
);
5812 /* If this breakpoint has custom print function,
5813 it's already printed. Otherwise, print individual
5814 locations, if any. */
5815 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5817 /* If breakpoint has a single location that is disabled, we
5818 print it as if it had several locations, since otherwise it's
5819 hard to represent "breakpoint enabled, location disabled"
5822 Note that while hardware watchpoints have several locations
5823 internally, that's not a property exposed to user. */
5825 && !is_hardware_watchpoint (b
)
5826 && (b
->loc
->next
|| !b
->loc
->enabled
))
5828 struct bp_location
*loc
;
5831 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5833 struct cleanup
*inner2
=
5834 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5835 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5836 do_cleanups (inner2
);
5843 breakpoint_address_bits (struct breakpoint
*b
)
5845 int print_address_bits
= 0;
5846 struct bp_location
*loc
;
5848 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5852 /* Software watchpoints that aren't watching memory don't have
5853 an address to print. */
5854 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5857 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5858 if (addr_bit
> print_address_bits
)
5859 print_address_bits
= addr_bit
;
5862 return print_address_bits
;
5865 struct captured_breakpoint_query_args
5871 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5873 struct captured_breakpoint_query_args
*args
= data
;
5874 struct breakpoint
*b
;
5875 struct bp_location
*dummy_loc
= NULL
;
5879 if (args
->bnum
== b
->number
)
5881 print_one_breakpoint (b
, &dummy_loc
, 0);
5889 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5890 char **error_message
)
5892 struct captured_breakpoint_query_args args
;
5895 /* For the moment we don't trust print_one_breakpoint() to not throw
5897 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5898 error_message
, RETURN_MASK_ALL
) < 0)
5904 /* Return true if this breakpoint was set by the user, false if it is
5905 internal or momentary. */
5908 user_breakpoint_p (struct breakpoint
*b
)
5910 return b
->number
> 0;
5913 /* Print information on user settable breakpoint (watchpoint, etc)
5914 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5915 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5916 FILTER is non-NULL, call it on each breakpoint and only include the
5917 ones for which it returns non-zero. Return the total number of
5918 breakpoints listed. */
5921 breakpoint_1 (char *args
, int allflag
,
5922 int (*filter
) (const struct breakpoint
*))
5924 struct breakpoint
*b
;
5925 struct bp_location
*last_loc
= NULL
;
5926 int nr_printable_breakpoints
;
5927 struct cleanup
*bkpttbl_chain
;
5928 struct value_print_options opts
;
5929 int print_address_bits
= 0;
5930 int print_type_col_width
= 14;
5931 struct ui_out
*uiout
= current_uiout
;
5933 get_user_print_options (&opts
);
5935 /* Compute the number of rows in the table, as well as the size
5936 required for address fields. */
5937 nr_printable_breakpoints
= 0;
5940 /* If we have a filter, only list the breakpoints it accepts. */
5941 if (filter
&& !filter (b
))
5944 /* If we have an "args" string, it is a list of breakpoints to
5945 accept. Skip the others. */
5946 if (args
!= NULL
&& *args
!= '\0')
5948 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5950 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5954 if (allflag
|| user_breakpoint_p (b
))
5956 int addr_bit
, type_len
;
5958 addr_bit
= breakpoint_address_bits (b
);
5959 if (addr_bit
> print_address_bits
)
5960 print_address_bits
= addr_bit
;
5962 type_len
= strlen (bptype_string (b
->type
));
5963 if (type_len
> print_type_col_width
)
5964 print_type_col_width
= type_len
;
5966 nr_printable_breakpoints
++;
5970 if (opts
.addressprint
)
5972 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5973 nr_printable_breakpoints
,
5977 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5978 nr_printable_breakpoints
,
5981 if (nr_printable_breakpoints
> 0)
5982 annotate_breakpoints_headers ();
5983 if (nr_printable_breakpoints
> 0)
5985 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5986 if (nr_printable_breakpoints
> 0)
5988 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5989 "type", "Type"); /* 2 */
5990 if (nr_printable_breakpoints
> 0)
5992 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5993 if (nr_printable_breakpoints
> 0)
5995 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5996 if (opts
.addressprint
)
5998 if (nr_printable_breakpoints
> 0)
6000 if (print_address_bits
<= 32)
6001 ui_out_table_header (uiout
, 10, ui_left
,
6002 "addr", "Address"); /* 5 */
6004 ui_out_table_header (uiout
, 18, ui_left
,
6005 "addr", "Address"); /* 5 */
6007 if (nr_printable_breakpoints
> 0)
6009 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6010 ui_out_table_body (uiout
);
6011 if (nr_printable_breakpoints
> 0)
6012 annotate_breakpoints_table ();
6017 /* If we have a filter, only list the breakpoints it accepts. */
6018 if (filter
&& !filter (b
))
6021 /* If we have an "args" string, it is a list of breakpoints to
6022 accept. Skip the others. */
6024 if (args
!= NULL
&& *args
!= '\0')
6026 if (allflag
) /* maintenance info breakpoint */
6028 if (parse_and_eval_long (args
) != b
->number
)
6031 else /* all others */
6033 if (!number_is_in_list (args
, b
->number
))
6037 /* We only print out user settable breakpoints unless the
6039 if (allflag
|| user_breakpoint_p (b
))
6040 print_one_breakpoint (b
, &last_loc
, allflag
);
6043 do_cleanups (bkpttbl_chain
);
6045 if (nr_printable_breakpoints
== 0)
6047 /* If there's a filter, let the caller decide how to report
6051 if (args
== NULL
|| *args
== '\0')
6052 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6054 ui_out_message (uiout
, 0,
6055 "No breakpoint or watchpoint matching '%s'.\n",
6061 if (last_loc
&& !server_command
)
6062 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6065 /* FIXME? Should this be moved up so that it is only called when
6066 there have been breakpoints? */
6067 annotate_breakpoints_table_end ();
6069 return nr_printable_breakpoints
;
6072 /* Display the value of default-collect in a way that is generally
6073 compatible with the breakpoint list. */
6076 default_collect_info (void)
6078 struct ui_out
*uiout
= current_uiout
;
6080 /* If it has no value (which is frequently the case), say nothing; a
6081 message like "No default-collect." gets in user's face when it's
6083 if (!*default_collect
)
6086 /* The following phrase lines up nicely with per-tracepoint collect
6088 ui_out_text (uiout
, "default collect ");
6089 ui_out_field_string (uiout
, "default-collect", default_collect
);
6090 ui_out_text (uiout
, " \n");
6094 breakpoints_info (char *args
, int from_tty
)
6096 breakpoint_1 (args
, 0, NULL
);
6098 default_collect_info ();
6102 watchpoints_info (char *args
, int from_tty
)
6104 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6105 struct ui_out
*uiout
= current_uiout
;
6107 if (num_printed
== 0)
6109 if (args
== NULL
|| *args
== '\0')
6110 ui_out_message (uiout
, 0, "No watchpoints.\n");
6112 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6117 maintenance_info_breakpoints (char *args
, int from_tty
)
6119 breakpoint_1 (args
, 1, NULL
);
6121 default_collect_info ();
6125 breakpoint_has_pc (struct breakpoint
*b
,
6126 struct program_space
*pspace
,
6127 CORE_ADDR pc
, struct obj_section
*section
)
6129 struct bp_location
*bl
= b
->loc
;
6131 for (; bl
; bl
= bl
->next
)
6133 if (bl
->pspace
== pspace
6134 && bl
->address
== pc
6135 && (!overlay_debugging
|| bl
->section
== section
))
6141 /* Print a message describing any user-breakpoints set at PC. This
6142 concerns with logical breakpoints, so we match program spaces, not
6146 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6147 struct program_space
*pspace
, CORE_ADDR pc
,
6148 struct obj_section
*section
, int thread
)
6151 struct breakpoint
*b
;
6154 others
+= (user_breakpoint_p (b
)
6155 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6159 printf_filtered (_("Note: breakpoint "));
6160 else /* if (others == ???) */
6161 printf_filtered (_("Note: breakpoints "));
6163 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6166 printf_filtered ("%d", b
->number
);
6167 if (b
->thread
== -1 && thread
!= -1)
6168 printf_filtered (" (all threads)");
6169 else if (b
->thread
!= -1)
6170 printf_filtered (" (thread %d)", b
->thread
);
6171 printf_filtered ("%s%s ",
6172 ((b
->enable_state
== bp_disabled
6173 || b
->enable_state
== bp_call_disabled
)
6175 : b
->enable_state
== bp_permanent
6179 : ((others
== 1) ? " and" : ""));
6181 printf_filtered (_("also set at pc "));
6182 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6183 printf_filtered (".\n");
6188 /* Return true iff it is meaningful to use the address member of
6189 BPT. For some breakpoint types, the address member is irrelevant
6190 and it makes no sense to attempt to compare it to other addresses
6191 (or use it for any other purpose either).
6193 More specifically, each of the following breakpoint types will
6194 always have a zero valued address and we don't want to mark
6195 breakpoints of any of these types to be a duplicate of an actual
6196 breakpoint at address zero:
6204 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6206 enum bptype type
= bpt
->type
;
6208 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6211 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6212 true if LOC1 and LOC2 represent the same watchpoint location. */
6215 watchpoint_locations_match (struct bp_location
*loc1
,
6216 struct bp_location
*loc2
)
6218 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6219 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6221 /* Both of them must exist. */
6222 gdb_assert (w1
!= NULL
);
6223 gdb_assert (w2
!= NULL
);
6225 /* If the target can evaluate the condition expression in hardware,
6226 then we we need to insert both watchpoints even if they are at
6227 the same place. Otherwise the watchpoint will only trigger when
6228 the condition of whichever watchpoint was inserted evaluates to
6229 true, not giving a chance for GDB to check the condition of the
6230 other watchpoint. */
6232 && target_can_accel_watchpoint_condition (loc1
->address
,
6234 loc1
->watchpoint_type
,
6237 && target_can_accel_watchpoint_condition (loc2
->address
,
6239 loc2
->watchpoint_type
,
6243 /* Note that this checks the owner's type, not the location's. In
6244 case the target does not support read watchpoints, but does
6245 support access watchpoints, we'll have bp_read_watchpoint
6246 watchpoints with hw_access locations. Those should be considered
6247 duplicates of hw_read locations. The hw_read locations will
6248 become hw_access locations later. */
6249 return (loc1
->owner
->type
== loc2
->owner
->type
6250 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6251 && loc1
->address
== loc2
->address
6252 && loc1
->length
== loc2
->length
);
6255 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6256 same breakpoint location. In most targets, this can only be true
6257 if ASPACE1 matches ASPACE2. On targets that have global
6258 breakpoints, the address space doesn't really matter. */
6261 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6262 struct address_space
*aspace2
, CORE_ADDR addr2
)
6264 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6265 || aspace1
== aspace2
)
6269 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6270 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6271 matches ASPACE2. On targets that have global breakpoints, the address
6272 space doesn't really matter. */
6275 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6276 int len1
, struct address_space
*aspace2
,
6279 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6280 || aspace1
== aspace2
)
6281 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6284 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6285 a ranged breakpoint. In most targets, a match happens only if ASPACE
6286 matches the breakpoint's address space. On targets that have global
6287 breakpoints, the address space doesn't really matter. */
6290 breakpoint_location_address_match (struct bp_location
*bl
,
6291 struct address_space
*aspace
,
6294 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6297 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6298 bl
->address
, bl
->length
,
6302 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6303 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6304 true, otherwise returns false. */
6307 tracepoint_locations_match (struct bp_location
*loc1
,
6308 struct bp_location
*loc2
)
6310 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6311 /* Since tracepoint locations are never duplicated with others', tracepoint
6312 locations at the same address of different tracepoints are regarded as
6313 different locations. */
6314 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6319 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6320 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6321 represent the same location. */
6324 breakpoint_locations_match (struct bp_location
*loc1
,
6325 struct bp_location
*loc2
)
6327 int hw_point1
, hw_point2
;
6329 /* Both of them must not be in moribund_locations. */
6330 gdb_assert (loc1
->owner
!= NULL
);
6331 gdb_assert (loc2
->owner
!= NULL
);
6333 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6334 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6336 if (hw_point1
!= hw_point2
)
6339 return watchpoint_locations_match (loc1
, loc2
);
6340 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6341 return tracepoint_locations_match (loc1
, loc2
);
6343 /* We compare bp_location.length in order to cover ranged breakpoints. */
6344 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6345 loc2
->pspace
->aspace
, loc2
->address
)
6346 && loc1
->length
== loc2
->length
);
6350 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6351 int bnum
, int have_bnum
)
6353 /* The longest string possibly returned by hex_string_custom
6354 is 50 chars. These must be at least that big for safety. */
6358 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6359 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6361 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6362 bnum
, astr1
, astr2
);
6364 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6367 /* Adjust a breakpoint's address to account for architectural
6368 constraints on breakpoint placement. Return the adjusted address.
6369 Note: Very few targets require this kind of adjustment. For most
6370 targets, this function is simply the identity function. */
6373 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6374 CORE_ADDR bpaddr
, enum bptype bptype
)
6376 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6378 /* Very few targets need any kind of breakpoint adjustment. */
6381 else if (bptype
== bp_watchpoint
6382 || bptype
== bp_hardware_watchpoint
6383 || bptype
== bp_read_watchpoint
6384 || bptype
== bp_access_watchpoint
6385 || bptype
== bp_catchpoint
)
6387 /* Watchpoints and the various bp_catch_* eventpoints should not
6388 have their addresses modified. */
6393 CORE_ADDR adjusted_bpaddr
;
6395 /* Some targets have architectural constraints on the placement
6396 of breakpoint instructions. Obtain the adjusted address. */
6397 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6399 /* An adjusted breakpoint address can significantly alter
6400 a user's expectations. Print a warning if an adjustment
6402 if (adjusted_bpaddr
!= bpaddr
)
6403 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6405 return adjusted_bpaddr
;
6410 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6411 struct breakpoint
*owner
)
6413 memset (loc
, 0, sizeof (*loc
));
6415 gdb_assert (ops
!= NULL
);
6420 loc
->cond_bytecode
= NULL
;
6421 loc
->shlib_disabled
= 0;
6424 switch (owner
->type
)
6430 case bp_longjmp_resume
:
6432 case bp_exception_resume
:
6433 case bp_step_resume
:
6434 case bp_hp_step_resume
:
6435 case bp_watchpoint_scope
:
6437 case bp_std_terminate
:
6438 case bp_shlib_event
:
6439 case bp_thread_event
:
6440 case bp_overlay_event
:
6442 case bp_longjmp_master
:
6443 case bp_std_terminate_master
:
6444 case bp_exception_master
:
6445 case bp_gnu_ifunc_resolver
:
6446 case bp_gnu_ifunc_resolver_return
:
6447 loc
->loc_type
= bp_loc_software_breakpoint
;
6448 mark_breakpoint_location_modified (loc
);
6450 case bp_hardware_breakpoint
:
6451 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6452 mark_breakpoint_location_modified (loc
);
6454 case bp_hardware_watchpoint
:
6455 case bp_read_watchpoint
:
6456 case bp_access_watchpoint
:
6457 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6462 case bp_fast_tracepoint
:
6463 case bp_static_tracepoint
:
6464 loc
->loc_type
= bp_loc_other
;
6467 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6473 /* Allocate a struct bp_location. */
6475 static struct bp_location
*
6476 allocate_bp_location (struct breakpoint
*bpt
)
6478 return bpt
->ops
->allocate_location (bpt
);
6482 free_bp_location (struct bp_location
*loc
)
6484 loc
->ops
->dtor (loc
);
6488 /* Increment reference count. */
6491 incref_bp_location (struct bp_location
*bl
)
6496 /* Decrement reference count. If the reference count reaches 0,
6497 destroy the bp_location. Sets *BLP to NULL. */
6500 decref_bp_location (struct bp_location
**blp
)
6502 gdb_assert ((*blp
)->refc
> 0);
6504 if (--(*blp
)->refc
== 0)
6505 free_bp_location (*blp
);
6509 /* Add breakpoint B at the end of the global breakpoint chain. */
6512 add_to_breakpoint_chain (struct breakpoint
*b
)
6514 struct breakpoint
*b1
;
6516 /* Add this breakpoint to the end of the chain so that a list of
6517 breakpoints will come out in order of increasing numbers. */
6519 b1
= breakpoint_chain
;
6521 breakpoint_chain
= b
;
6530 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6533 init_raw_breakpoint_without_location (struct breakpoint
*b
,
6534 struct gdbarch
*gdbarch
,
6536 const struct breakpoint_ops
*ops
)
6538 memset (b
, 0, sizeof (*b
));
6540 gdb_assert (ops
!= NULL
);
6544 b
->gdbarch
= gdbarch
;
6545 b
->language
= current_language
->la_language
;
6546 b
->input_radix
= input_radix
;
6548 b
->enable_state
= bp_enabled
;
6551 b
->ignore_count
= 0;
6553 b
->frame_id
= null_frame_id
;
6554 b
->condition_not_parsed
= 0;
6555 b
->py_bp_object
= NULL
;
6556 b
->related_breakpoint
= b
;
6559 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6560 that has type BPTYPE and has no locations as yet. */
6562 static struct breakpoint
*
6563 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
6565 const struct breakpoint_ops
*ops
)
6567 struct breakpoint
*b
= XNEW (struct breakpoint
);
6569 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6570 add_to_breakpoint_chain (b
);
6574 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6575 resolutions should be made as the user specified the location explicitly
6579 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
6581 gdb_assert (loc
->owner
!= NULL
);
6583 if (loc
->owner
->type
== bp_breakpoint
6584 || loc
->owner
->type
== bp_hardware_breakpoint
6585 || is_tracepoint (loc
->owner
))
6588 const char *function_name
;
6590 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
6591 NULL
, NULL
, &is_gnu_ifunc
);
6593 if (is_gnu_ifunc
&& !explicit_loc
)
6595 struct breakpoint
*b
= loc
->owner
;
6597 gdb_assert (loc
->pspace
== current_program_space
);
6598 if (gnu_ifunc_resolve_name (function_name
,
6599 &loc
->requested_address
))
6601 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6602 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6603 loc
->requested_address
,
6606 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
6607 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
6609 /* Create only the whole new breakpoint of this type but do not
6610 mess more complicated breakpoints with multiple locations. */
6611 b
->type
= bp_gnu_ifunc_resolver
;
6616 loc
->function_name
= xstrdup (function_name
);
6620 /* Attempt to determine architecture of location identified by SAL. */
6622 get_sal_arch (struct symtab_and_line sal
)
6625 return get_objfile_arch (sal
.section
->objfile
);
6627 return get_objfile_arch (sal
.symtab
->objfile
);
6632 /* Low level routine for partially initializing a breakpoint of type
6633 BPTYPE. The newly created breakpoint's address, section, source
6634 file name, and line number are provided by SAL.
6636 It is expected that the caller will complete the initialization of
6637 the newly created breakpoint struct as well as output any status
6638 information regarding the creation of a new breakpoint. */
6641 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
6642 struct symtab_and_line sal
, enum bptype bptype
,
6643 const struct breakpoint_ops
*ops
)
6645 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6647 add_location_to_breakpoint (b
, &sal
);
6649 if (bptype
!= bp_catchpoint
)
6650 gdb_assert (sal
.pspace
!= NULL
);
6652 /* Store the program space that was used to set the breakpoint,
6653 except for ordinary breakpoints, which are independent of the
6655 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
6656 b
->pspace
= sal
.pspace
;
6658 breakpoints_changed ();
6661 /* set_raw_breakpoint is a low level routine for allocating and
6662 partially initializing a breakpoint of type BPTYPE. The newly
6663 created breakpoint's address, section, source file name, and line
6664 number are provided by SAL. The newly created and partially
6665 initialized breakpoint is added to the breakpoint chain and
6666 is also returned as the value of this function.
6668 It is expected that the caller will complete the initialization of
6669 the newly created breakpoint struct as well as output any status
6670 information regarding the creation of a new breakpoint. In
6671 particular, set_raw_breakpoint does NOT set the breakpoint
6672 number! Care should be taken to not allow an error to occur
6673 prior to completing the initialization of the breakpoint. If this
6674 should happen, a bogus breakpoint will be left on the chain. */
6677 set_raw_breakpoint (struct gdbarch
*gdbarch
,
6678 struct symtab_and_line sal
, enum bptype bptype
,
6679 const struct breakpoint_ops
*ops
)
6681 struct breakpoint
*b
= XNEW (struct breakpoint
);
6683 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
6684 add_to_breakpoint_chain (b
);
6689 /* Note that the breakpoint object B describes a permanent breakpoint
6690 instruction, hard-wired into the inferior's code. */
6692 make_breakpoint_permanent (struct breakpoint
*b
)
6694 struct bp_location
*bl
;
6696 b
->enable_state
= bp_permanent
;
6698 /* By definition, permanent breakpoints are already present in the
6699 code. Mark all locations as inserted. For now,
6700 make_breakpoint_permanent is called in just one place, so it's
6701 hard to say if it's reasonable to have permanent breakpoint with
6702 multiple locations or not, but it's easy to implement. */
6703 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6707 /* Call this routine when stepping and nexting to enable a breakpoint
6708 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6709 initiated the operation. */
6712 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
6714 struct breakpoint
*b
, *b_tmp
;
6715 int thread
= tp
->num
;
6717 /* To avoid having to rescan all objfile symbols at every step,
6718 we maintain a list of continually-inserted but always disabled
6719 longjmp "master" breakpoints. Here, we simply create momentary
6720 clones of those and enable them for the requested thread. */
6721 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6722 if (b
->pspace
== current_program_space
6723 && (b
->type
== bp_longjmp_master
6724 || b
->type
== bp_exception_master
))
6726 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
6727 struct breakpoint
*clone
;
6729 clone
= momentary_breakpoint_from_master (b
, type
,
6730 &momentary_breakpoint_ops
);
6731 clone
->thread
= thread
;
6734 tp
->initiating_frame
= frame
;
6737 /* Delete all longjmp breakpoints from THREAD. */
6739 delete_longjmp_breakpoint (int thread
)
6741 struct breakpoint
*b
, *b_tmp
;
6743 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6744 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6746 if (b
->thread
== thread
)
6747 delete_breakpoint (b
);
6752 delete_longjmp_breakpoint_at_next_stop (int thread
)
6754 struct breakpoint
*b
, *b_tmp
;
6756 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6757 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6759 if (b
->thread
== thread
)
6760 b
->disposition
= disp_del_at_next_stop
;
6765 enable_overlay_breakpoints (void)
6767 struct breakpoint
*b
;
6770 if (b
->type
== bp_overlay_event
)
6772 b
->enable_state
= bp_enabled
;
6773 update_global_location_list (1);
6774 overlay_events_enabled
= 1;
6779 disable_overlay_breakpoints (void)
6781 struct breakpoint
*b
;
6784 if (b
->type
== bp_overlay_event
)
6786 b
->enable_state
= bp_disabled
;
6787 update_global_location_list (0);
6788 overlay_events_enabled
= 0;
6792 /* Set an active std::terminate breakpoint for each std::terminate
6793 master breakpoint. */
6795 set_std_terminate_breakpoint (void)
6797 struct breakpoint
*b
, *b_tmp
;
6799 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6800 if (b
->pspace
== current_program_space
6801 && b
->type
== bp_std_terminate_master
)
6803 momentary_breakpoint_from_master (b
, bp_std_terminate
,
6804 &momentary_breakpoint_ops
);
6808 /* Delete all the std::terminate breakpoints. */
6810 delete_std_terminate_breakpoint (void)
6812 struct breakpoint
*b
, *b_tmp
;
6814 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6815 if (b
->type
== bp_std_terminate
)
6816 delete_breakpoint (b
);
6820 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6822 struct breakpoint
*b
;
6824 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
6825 &internal_breakpoint_ops
);
6827 b
->enable_state
= bp_enabled
;
6828 /* addr_string has to be used or breakpoint_re_set will delete me. */
6830 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6832 update_global_location_list_nothrow (1);
6838 remove_thread_event_breakpoints (void)
6840 struct breakpoint
*b
, *b_tmp
;
6842 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6843 if (b
->type
== bp_thread_event
6844 && b
->loc
->pspace
== current_program_space
)
6845 delete_breakpoint (b
);
6848 struct lang_and_radix
6854 /* Create a breakpoint for JIT code registration and unregistration. */
6857 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6859 struct breakpoint
*b
;
6861 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6862 &internal_breakpoint_ops
);
6863 update_global_location_list_nothrow (1);
6867 /* Remove JIT code registration and unregistration breakpoint(s). */
6870 remove_jit_event_breakpoints (void)
6872 struct breakpoint
*b
, *b_tmp
;
6874 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6875 if (b
->type
== bp_jit_event
6876 && b
->loc
->pspace
== current_program_space
)
6877 delete_breakpoint (b
);
6881 remove_solib_event_breakpoints (void)
6883 struct breakpoint
*b
, *b_tmp
;
6885 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6886 if (b
->type
== bp_shlib_event
6887 && b
->loc
->pspace
== current_program_space
)
6888 delete_breakpoint (b
);
6892 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6894 struct breakpoint
*b
;
6896 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6897 &internal_breakpoint_ops
);
6898 update_global_location_list_nothrow (1);
6902 /* Disable any breakpoints that are on code in shared libraries. Only
6903 apply to enabled breakpoints, disabled ones can just stay disabled. */
6906 disable_breakpoints_in_shlibs (void)
6908 struct bp_location
*loc
, **locp_tmp
;
6910 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6912 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6913 struct breakpoint
*b
= loc
->owner
;
6915 /* We apply the check to all breakpoints, including disabled for
6916 those with loc->duplicate set. This is so that when breakpoint
6917 becomes enabled, or the duplicate is removed, gdb will try to
6918 insert all breakpoints. If we don't set shlib_disabled here,
6919 we'll try to insert those breakpoints and fail. */
6920 if (((b
->type
== bp_breakpoint
)
6921 || (b
->type
== bp_jit_event
)
6922 || (b
->type
== bp_hardware_breakpoint
)
6923 || (is_tracepoint (b
)))
6924 && loc
->pspace
== current_program_space
6925 && !loc
->shlib_disabled
6927 && PC_SOLIB (loc
->address
)
6929 && solib_name_from_address (loc
->pspace
, loc
->address
)
6933 loc
->shlib_disabled
= 1;
6938 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6939 library. Only apply to enabled breakpoints, disabled ones can just stay
6943 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6945 struct bp_location
*loc
, **locp_tmp
;
6946 int disabled_shlib_breaks
= 0;
6948 /* SunOS a.out shared libraries are always mapped, so do not
6949 disable breakpoints; they will only be reported as unloaded
6950 through clear_solib when GDB discards its shared library
6951 list. See clear_solib for more information. */
6952 if (exec_bfd
!= NULL
6953 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6956 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6958 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6959 struct breakpoint
*b
= loc
->owner
;
6961 if (solib
->pspace
== loc
->pspace
6962 && !loc
->shlib_disabled
6963 && (((b
->type
== bp_breakpoint
6964 || b
->type
== bp_jit_event
6965 || b
->type
== bp_hardware_breakpoint
)
6966 && (loc
->loc_type
== bp_loc_hardware_breakpoint
6967 || loc
->loc_type
== bp_loc_software_breakpoint
))
6968 || is_tracepoint (b
))
6969 && solib_contains_address_p (solib
, loc
->address
))
6971 loc
->shlib_disabled
= 1;
6972 /* At this point, we cannot rely on remove_breakpoint
6973 succeeding so we must mark the breakpoint as not inserted
6974 to prevent future errors occurring in remove_breakpoints. */
6977 /* This may cause duplicate notifications for the same breakpoint. */
6978 observer_notify_breakpoint_modified (b
);
6980 if (!disabled_shlib_breaks
)
6982 target_terminal_ours_for_output ();
6983 warning (_("Temporarily disabling breakpoints "
6984 "for unloaded shared library \"%s\""),
6987 disabled_shlib_breaks
= 1;
6992 /* FORK & VFORK catchpoints. */
6994 /* An instance of this type is used to represent a fork or vfork
6995 catchpoint. It includes a "struct breakpoint" as a kind of base
6996 class; users downcast to "struct breakpoint *" when needed. A
6997 breakpoint is really of this type iff its ops pointer points to
6998 CATCH_FORK_BREAKPOINT_OPS. */
7000 struct fork_catchpoint
7002 /* The base class. */
7003 struct breakpoint base
;
7005 /* Process id of a child process whose forking triggered this
7006 catchpoint. This field is only valid immediately after this
7007 catchpoint has triggered. */
7008 ptid_t forked_inferior_pid
;
7011 /* Implement the "insert" breakpoint_ops method for fork
7015 insert_catch_fork (struct bp_location
*bl
)
7017 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
7020 /* Implement the "remove" breakpoint_ops method for fork
7024 remove_catch_fork (struct bp_location
*bl
)
7026 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
7029 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7033 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7034 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7035 const struct target_waitstatus
*ws
)
7037 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7039 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7042 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7046 /* Implement the "print_it" breakpoint_ops method for fork
7049 static enum print_stop_action
7050 print_it_catch_fork (bpstat bs
)
7052 struct ui_out
*uiout
= current_uiout
;
7053 struct breakpoint
*b
= bs
->breakpoint_at
;
7054 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7056 annotate_catchpoint (b
->number
);
7057 if (b
->disposition
== disp_del
)
7058 ui_out_text (uiout
, "\nTemporary catchpoint ");
7060 ui_out_text (uiout
, "\nCatchpoint ");
7061 if (ui_out_is_mi_like_p (uiout
))
7063 ui_out_field_string (uiout
, "reason",
7064 async_reason_lookup (EXEC_ASYNC_FORK
));
7065 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7067 ui_out_field_int (uiout
, "bkptno", b
->number
);
7068 ui_out_text (uiout
, " (forked process ");
7069 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7070 ui_out_text (uiout
, "), ");
7071 return PRINT_SRC_AND_LOC
;
7074 /* Implement the "print_one" breakpoint_ops method for fork
7078 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7080 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7081 struct value_print_options opts
;
7082 struct ui_out
*uiout
= current_uiout
;
7084 get_user_print_options (&opts
);
7086 /* Field 4, the address, is omitted (which makes the columns not
7087 line up too nicely with the headers, but the effect is relatively
7089 if (opts
.addressprint
)
7090 ui_out_field_skip (uiout
, "addr");
7092 ui_out_text (uiout
, "fork");
7093 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7095 ui_out_text (uiout
, ", process ");
7096 ui_out_field_int (uiout
, "what",
7097 ptid_get_pid (c
->forked_inferior_pid
));
7098 ui_out_spaces (uiout
, 1);
7102 /* Implement the "print_mention" breakpoint_ops method for fork
7106 print_mention_catch_fork (struct breakpoint
*b
)
7108 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7111 /* Implement the "print_recreate" breakpoint_ops method for fork
7115 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7117 fprintf_unfiltered (fp
, "catch fork");
7118 print_recreate_thread (b
, fp
);
7121 /* The breakpoint_ops structure to be used in fork catchpoints. */
7123 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7125 /* Implement the "insert" breakpoint_ops method for vfork
7129 insert_catch_vfork (struct bp_location
*bl
)
7131 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
7134 /* Implement the "remove" breakpoint_ops method for vfork
7138 remove_catch_vfork (struct bp_location
*bl
)
7140 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
7143 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7147 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7148 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7149 const struct target_waitstatus
*ws
)
7151 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7153 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7156 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7160 /* Implement the "print_it" breakpoint_ops method for vfork
7163 static enum print_stop_action
7164 print_it_catch_vfork (bpstat bs
)
7166 struct ui_out
*uiout
= current_uiout
;
7167 struct breakpoint
*b
= bs
->breakpoint_at
;
7168 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7170 annotate_catchpoint (b
->number
);
7171 if (b
->disposition
== disp_del
)
7172 ui_out_text (uiout
, "\nTemporary catchpoint ");
7174 ui_out_text (uiout
, "\nCatchpoint ");
7175 if (ui_out_is_mi_like_p (uiout
))
7177 ui_out_field_string (uiout
, "reason",
7178 async_reason_lookup (EXEC_ASYNC_VFORK
));
7179 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7181 ui_out_field_int (uiout
, "bkptno", b
->number
);
7182 ui_out_text (uiout
, " (vforked process ");
7183 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7184 ui_out_text (uiout
, "), ");
7185 return PRINT_SRC_AND_LOC
;
7188 /* Implement the "print_one" breakpoint_ops method for vfork
7192 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7194 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7195 struct value_print_options opts
;
7196 struct ui_out
*uiout
= current_uiout
;
7198 get_user_print_options (&opts
);
7199 /* Field 4, the address, is omitted (which makes the columns not
7200 line up too nicely with the headers, but the effect is relatively
7202 if (opts
.addressprint
)
7203 ui_out_field_skip (uiout
, "addr");
7205 ui_out_text (uiout
, "vfork");
7206 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7208 ui_out_text (uiout
, ", process ");
7209 ui_out_field_int (uiout
, "what",
7210 ptid_get_pid (c
->forked_inferior_pid
));
7211 ui_out_spaces (uiout
, 1);
7215 /* Implement the "print_mention" breakpoint_ops method for vfork
7219 print_mention_catch_vfork (struct breakpoint
*b
)
7221 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7224 /* Implement the "print_recreate" breakpoint_ops method for vfork
7228 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7230 fprintf_unfiltered (fp
, "catch vfork");
7231 print_recreate_thread (b
, fp
);
7234 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7236 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7238 /* An instance of this type is used to represent an solib catchpoint.
7239 It includes a "struct breakpoint" as a kind of base class; users
7240 downcast to "struct breakpoint *" when needed. A breakpoint is
7241 really of this type iff its ops pointer points to
7242 CATCH_SOLIB_BREAKPOINT_OPS. */
7244 struct solib_catchpoint
7246 /* The base class. */
7247 struct breakpoint base
;
7249 /* True for "catch load", false for "catch unload". */
7250 unsigned char is_load
;
7252 /* Regular expression to match, if any. COMPILED is only valid when
7253 REGEX is non-NULL. */
7259 dtor_catch_solib (struct breakpoint
*b
)
7261 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7264 regfree (&self
->compiled
);
7265 xfree (self
->regex
);
7267 base_breakpoint_ops
.dtor (b
);
7271 insert_catch_solib (struct bp_location
*ignore
)
7277 remove_catch_solib (struct bp_location
*ignore
)
7283 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7284 struct address_space
*aspace
,
7286 const struct target_waitstatus
*ws
)
7288 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7289 struct breakpoint
*other
;
7291 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7294 ALL_BREAKPOINTS (other
)
7296 struct bp_location
*other_bl
;
7298 if (other
== bl
->owner
)
7301 if (other
->type
!= bp_shlib_event
)
7304 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7307 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7309 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7318 check_status_catch_solib (struct bpstats
*bs
)
7320 struct solib_catchpoint
*self
7321 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7326 struct so_list
*iter
;
7329 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
7334 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
7343 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
7348 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
7354 bs
->print_it
= print_it_noop
;
7357 static enum print_stop_action
7358 print_it_catch_solib (bpstat bs
)
7360 struct breakpoint
*b
= bs
->breakpoint_at
;
7361 struct ui_out
*uiout
= current_uiout
;
7363 annotate_catchpoint (b
->number
);
7364 if (b
->disposition
== disp_del
)
7365 ui_out_text (uiout
, "\nTemporary catchpoint ");
7367 ui_out_text (uiout
, "\nCatchpoint ");
7368 ui_out_field_int (uiout
, "bkptno", b
->number
);
7369 ui_out_text (uiout
, "\n");
7370 if (ui_out_is_mi_like_p (uiout
))
7371 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7372 print_solib_event (1);
7373 return PRINT_SRC_AND_LOC
;
7377 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7379 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7380 struct value_print_options opts
;
7381 struct ui_out
*uiout
= current_uiout
;
7384 get_user_print_options (&opts
);
7385 /* Field 4, the address, is omitted (which makes the columns not
7386 line up too nicely with the headers, but the effect is relatively
7388 if (opts
.addressprint
)
7391 ui_out_field_skip (uiout
, "addr");
7398 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
7400 msg
= xstrdup (_("load of library"));
7405 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
7407 msg
= xstrdup (_("unload of library"));
7409 ui_out_field_string (uiout
, "what", msg
);
7414 print_mention_catch_solib (struct breakpoint
*b
)
7416 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7418 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
7419 self
->is_load
? "load" : "unload");
7423 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
7425 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7427 fprintf_unfiltered (fp
, "%s %s",
7428 b
->disposition
== disp_del
? "tcatch" : "catch",
7429 self
->is_load
? "load" : "unload");
7431 fprintf_unfiltered (fp
, " %s", self
->regex
);
7432 fprintf_unfiltered (fp
, "\n");
7435 static struct breakpoint_ops catch_solib_breakpoint_ops
;
7437 /* A helper function that does all the work for "catch load" and
7441 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
7442 struct cmd_list_element
*command
)
7444 struct solib_catchpoint
*c
;
7445 struct gdbarch
*gdbarch
= get_current_arch ();
7448 struct cleanup
*cleanup
;
7450 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7454 arg
= skip_spaces (arg
);
7456 c
= XCNEW (struct solib_catchpoint
);
7457 cleanup
= make_cleanup (xfree
, c
);
7463 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
7466 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
7468 make_cleanup (xfree
, err
);
7469 error (_("Invalid regexp (%s): %s"), err
, arg
);
7471 c
->regex
= xstrdup (arg
);
7474 c
->is_load
= is_load
;
7475 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
,
7476 &catch_solib_breakpoint_ops
);
7478 discard_cleanups (cleanup
);
7479 install_breakpoint (0, &c
->base
, 1);
7483 catch_load_command_1 (char *arg
, int from_tty
,
7484 struct cmd_list_element
*command
)
7486 catch_load_or_unload (arg
, from_tty
, 1, command
);
7490 catch_unload_command_1 (char *arg
, int from_tty
,
7491 struct cmd_list_element
*command
)
7493 catch_load_or_unload (arg
, from_tty
, 0, command
);
7498 /* An instance of this type is used to represent a syscall catchpoint.
7499 It includes a "struct breakpoint" as a kind of base class; users
7500 downcast to "struct breakpoint *" when needed. A breakpoint is
7501 really of this type iff its ops pointer points to
7502 CATCH_SYSCALL_BREAKPOINT_OPS. */
7504 struct syscall_catchpoint
7506 /* The base class. */
7507 struct breakpoint base
;
7509 /* Syscall numbers used for the 'catch syscall' feature. If no
7510 syscall has been specified for filtering, its value is NULL.
7511 Otherwise, it holds a list of all syscalls to be caught. The
7512 list elements are allocated with xmalloc. */
7513 VEC(int) *syscalls_to_be_caught
;
7516 /* Implement the "dtor" breakpoint_ops method for syscall
7520 dtor_catch_syscall (struct breakpoint
*b
)
7522 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7524 VEC_free (int, c
->syscalls_to_be_caught
);
7526 base_breakpoint_ops
.dtor (b
);
7529 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
7531 struct catch_syscall_inferior_data
7533 /* We keep a count of the number of times the user has requested a
7534 particular syscall to be tracked, and pass this information to the
7535 target. This lets capable targets implement filtering directly. */
7537 /* Number of times that "any" syscall is requested. */
7538 int any_syscall_count
;
7540 /* Count of each system call. */
7541 VEC(int) *syscalls_counts
;
7543 /* This counts all syscall catch requests, so we can readily determine
7544 if any catching is necessary. */
7545 int total_syscalls_count
;
7548 static struct catch_syscall_inferior_data
*
7549 get_catch_syscall_inferior_data (struct inferior
*inf
)
7551 struct catch_syscall_inferior_data
*inf_data
;
7553 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
7554 if (inf_data
== NULL
)
7556 inf_data
= XZALLOC (struct catch_syscall_inferior_data
);
7557 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
7564 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
7570 /* Implement the "insert" breakpoint_ops method for syscall
7574 insert_catch_syscall (struct bp_location
*bl
)
7576 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7577 struct inferior
*inf
= current_inferior ();
7578 struct catch_syscall_inferior_data
*inf_data
7579 = get_catch_syscall_inferior_data (inf
);
7581 ++inf_data
->total_syscalls_count
;
7582 if (!c
->syscalls_to_be_caught
)
7583 ++inf_data
->any_syscall_count
;
7589 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7594 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
7596 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
7597 uintptr_t vec_addr_offset
7598 = old_size
* ((uintptr_t) sizeof (int));
7600 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
7601 vec_addr
= ((uintptr_t) VEC_address (int,
7602 inf_data
->syscalls_counts
)
7604 memset ((void *) vec_addr
, 0,
7605 (iter
+ 1 - old_size
) * sizeof (int));
7607 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
7608 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
7612 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7613 inf_data
->total_syscalls_count
!= 0,
7614 inf_data
->any_syscall_count
,
7616 inf_data
->syscalls_counts
),
7618 inf_data
->syscalls_counts
));
7621 /* Implement the "remove" breakpoint_ops method for syscall
7625 remove_catch_syscall (struct bp_location
*bl
)
7627 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7628 struct inferior
*inf
= current_inferior ();
7629 struct catch_syscall_inferior_data
*inf_data
7630 = get_catch_syscall_inferior_data (inf
);
7632 --inf_data
->total_syscalls_count
;
7633 if (!c
->syscalls_to_be_caught
)
7634 --inf_data
->any_syscall_count
;
7640 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7644 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
7645 /* Shouldn't happen. */
7647 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
7648 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
7652 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7653 inf_data
->total_syscalls_count
!= 0,
7654 inf_data
->any_syscall_count
,
7656 inf_data
->syscalls_counts
),
7658 inf_data
->syscalls_counts
));
7661 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7665 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
7666 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7667 const struct target_waitstatus
*ws
)
7669 /* We must check if we are catching specific syscalls in this
7670 breakpoint. If we are, then we must guarantee that the called
7671 syscall is the same syscall we are catching. */
7672 int syscall_number
= 0;
7673 const struct syscall_catchpoint
*c
7674 = (const struct syscall_catchpoint
*) bl
->owner
;
7676 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
7677 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
7680 syscall_number
= ws
->value
.syscall_number
;
7682 /* Now, checking if the syscall is the same. */
7683 if (c
->syscalls_to_be_caught
)
7688 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7690 if (syscall_number
== iter
)
7700 /* Implement the "print_it" breakpoint_ops method for syscall
7703 static enum print_stop_action
7704 print_it_catch_syscall (bpstat bs
)
7706 struct ui_out
*uiout
= current_uiout
;
7707 struct breakpoint
*b
= bs
->breakpoint_at
;
7708 /* These are needed because we want to know in which state a
7709 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7710 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7711 must print "called syscall" or "returned from syscall". */
7713 struct target_waitstatus last
;
7717 get_last_target_status (&ptid
, &last
);
7719 get_syscall_by_number (last
.value
.syscall_number
, &s
);
7721 annotate_catchpoint (b
->number
);
7723 if (b
->disposition
== disp_del
)
7724 ui_out_text (uiout
, "\nTemporary catchpoint ");
7726 ui_out_text (uiout
, "\nCatchpoint ");
7727 if (ui_out_is_mi_like_p (uiout
))
7729 ui_out_field_string (uiout
, "reason",
7730 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
7731 ? EXEC_ASYNC_SYSCALL_ENTRY
7732 : EXEC_ASYNC_SYSCALL_RETURN
));
7733 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7735 ui_out_field_int (uiout
, "bkptno", b
->number
);
7737 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
7738 ui_out_text (uiout
, " (call to syscall ");
7740 ui_out_text (uiout
, " (returned from syscall ");
7742 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
7743 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
7745 ui_out_field_string (uiout
, "syscall-name", s
.name
);
7747 ui_out_text (uiout
, "), ");
7749 return PRINT_SRC_AND_LOC
;
7752 /* Implement the "print_one" breakpoint_ops method for syscall
7756 print_one_catch_syscall (struct breakpoint
*b
,
7757 struct bp_location
**last_loc
)
7759 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7760 struct value_print_options opts
;
7761 struct ui_out
*uiout
= current_uiout
;
7763 get_user_print_options (&opts
);
7764 /* Field 4, the address, is omitted (which makes the columns not
7765 line up too nicely with the headers, but the effect is relatively
7767 if (opts
.addressprint
)
7768 ui_out_field_skip (uiout
, "addr");
7771 if (c
->syscalls_to_be_caught
7772 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7773 ui_out_text (uiout
, "syscalls \"");
7775 ui_out_text (uiout
, "syscall \"");
7777 if (c
->syscalls_to_be_caught
)
7780 char *text
= xstrprintf ("%s", "");
7783 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7788 get_syscall_by_number (iter
, &s
);
7791 text
= xstrprintf ("%s%s, ", text
, s
.name
);
7793 text
= xstrprintf ("%s%d, ", text
, iter
);
7795 /* We have to xfree the last 'text' (now stored at 'x')
7796 because xstrprintf dynamically allocates new space for it
7800 /* Remove the last comma. */
7801 text
[strlen (text
) - 2] = '\0';
7802 ui_out_field_string (uiout
, "what", text
);
7805 ui_out_field_string (uiout
, "what", "<any syscall>");
7806 ui_out_text (uiout
, "\" ");
7809 /* Implement the "print_mention" breakpoint_ops method for syscall
7813 print_mention_catch_syscall (struct breakpoint
*b
)
7815 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7817 if (c
->syscalls_to_be_caught
)
7821 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7822 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
7824 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
7827 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7831 get_syscall_by_number (iter
, &s
);
7834 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
7836 printf_filtered (" %d", s
.number
);
7838 printf_filtered (")");
7841 printf_filtered (_("Catchpoint %d (any syscall)"),
7845 /* Implement the "print_recreate" breakpoint_ops method for syscall
7849 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
7851 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7853 fprintf_unfiltered (fp
, "catch syscall");
7855 if (c
->syscalls_to_be_caught
)
7860 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7865 get_syscall_by_number (iter
, &s
);
7867 fprintf_unfiltered (fp
, " %s", s
.name
);
7869 fprintf_unfiltered (fp
, " %d", s
.number
);
7872 print_recreate_thread (b
, fp
);
7875 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7877 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
7879 /* Returns non-zero if 'b' is a syscall catchpoint. */
7882 syscall_catchpoint_p (struct breakpoint
*b
)
7884 return (b
->ops
== &catch_syscall_breakpoint_ops
);
7887 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7888 is non-zero, then make the breakpoint temporary. If COND_STRING is
7889 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7890 the breakpoint_ops structure associated to the catchpoint. */
7893 init_catchpoint (struct breakpoint
*b
,
7894 struct gdbarch
*gdbarch
, int tempflag
,
7896 const struct breakpoint_ops
*ops
)
7898 struct symtab_and_line sal
;
7901 sal
.pspace
= current_program_space
;
7903 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
7905 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
7906 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7910 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
7912 add_to_breakpoint_chain (b
);
7913 set_breakpoint_number (internal
, b
);
7916 observer_notify_breakpoint_created (b
);
7919 update_global_location_list (1);
7923 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
7924 int tempflag
, char *cond_string
,
7925 const struct breakpoint_ops
*ops
)
7927 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
7929 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
7931 c
->forked_inferior_pid
= null_ptid
;
7933 install_breakpoint (0, &c
->base
, 1);
7936 /* Exec catchpoints. */
7938 /* An instance of this type is used to represent an exec catchpoint.
7939 It includes a "struct breakpoint" as a kind of base class; users
7940 downcast to "struct breakpoint *" when needed. A breakpoint is
7941 really of this type iff its ops pointer points to
7942 CATCH_EXEC_BREAKPOINT_OPS. */
7944 struct exec_catchpoint
7946 /* The base class. */
7947 struct breakpoint base
;
7949 /* Filename of a program whose exec triggered this catchpoint.
7950 This field is only valid immediately after this catchpoint has
7952 char *exec_pathname
;
7955 /* Implement the "dtor" breakpoint_ops method for exec
7959 dtor_catch_exec (struct breakpoint
*b
)
7961 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
7963 xfree (c
->exec_pathname
);
7965 base_breakpoint_ops
.dtor (b
);
7969 insert_catch_exec (struct bp_location
*bl
)
7971 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
7975 remove_catch_exec (struct bp_location
*bl
)
7977 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
7981 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
7982 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7983 const struct target_waitstatus
*ws
)
7985 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
7987 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
7990 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
7994 static enum print_stop_action
7995 print_it_catch_exec (bpstat bs
)
7997 struct ui_out
*uiout
= current_uiout
;
7998 struct breakpoint
*b
= bs
->breakpoint_at
;
7999 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8001 annotate_catchpoint (b
->number
);
8002 if (b
->disposition
== disp_del
)
8003 ui_out_text (uiout
, "\nTemporary catchpoint ");
8005 ui_out_text (uiout
, "\nCatchpoint ");
8006 if (ui_out_is_mi_like_p (uiout
))
8008 ui_out_field_string (uiout
, "reason",
8009 async_reason_lookup (EXEC_ASYNC_EXEC
));
8010 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8012 ui_out_field_int (uiout
, "bkptno", b
->number
);
8013 ui_out_text (uiout
, " (exec'd ");
8014 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8015 ui_out_text (uiout
, "), ");
8017 return PRINT_SRC_AND_LOC
;
8021 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8023 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8024 struct value_print_options opts
;
8025 struct ui_out
*uiout
= current_uiout
;
8027 get_user_print_options (&opts
);
8029 /* Field 4, the address, is omitted (which makes the columns
8030 not line up too nicely with the headers, but the effect
8031 is relatively readable). */
8032 if (opts
.addressprint
)
8033 ui_out_field_skip (uiout
, "addr");
8035 ui_out_text (uiout
, "exec");
8036 if (c
->exec_pathname
!= NULL
)
8038 ui_out_text (uiout
, ", program \"");
8039 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8040 ui_out_text (uiout
, "\" ");
8045 print_mention_catch_exec (struct breakpoint
*b
)
8047 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8050 /* Implement the "print_recreate" breakpoint_ops method for exec
8054 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8056 fprintf_unfiltered (fp
, "catch exec");
8057 print_recreate_thread (b
, fp
);
8060 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8063 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8064 const struct breakpoint_ops
*ops
)
8066 struct syscall_catchpoint
*c
;
8067 struct gdbarch
*gdbarch
= get_current_arch ();
8069 c
= XNEW (struct syscall_catchpoint
);
8070 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8071 c
->syscalls_to_be_caught
= filter
;
8073 install_breakpoint (0, &c
->base
, 1);
8077 hw_breakpoint_used_count (void)
8080 struct breakpoint
*b
;
8081 struct bp_location
*bl
;
8085 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8086 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8088 /* Special types of hardware breakpoints may use more than
8090 i
+= b
->ops
->resources_needed (bl
);
8097 /* Returns the resources B would use if it were a hardware
8101 hw_watchpoint_use_count (struct breakpoint
*b
)
8104 struct bp_location
*bl
;
8106 if (!breakpoint_enabled (b
))
8109 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8111 /* Special types of hardware watchpoints may use more than
8113 i
+= b
->ops
->resources_needed (bl
);
8119 /* Returns the sum the used resources of all hardware watchpoints of
8120 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8121 the sum of the used resources of all hardware watchpoints of other
8122 types _not_ TYPE. */
8125 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8126 enum bptype type
, int *other_type_used
)
8129 struct breakpoint
*b
;
8131 *other_type_used
= 0;
8136 if (!breakpoint_enabled (b
))
8139 if (b
->type
== type
)
8140 i
+= hw_watchpoint_use_count (b
);
8141 else if (is_hardware_watchpoint (b
))
8142 *other_type_used
= 1;
8149 disable_watchpoints_before_interactive_call_start (void)
8151 struct breakpoint
*b
;
8155 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8157 b
->enable_state
= bp_call_disabled
;
8158 update_global_location_list (0);
8164 enable_watchpoints_after_interactive_call_stop (void)
8166 struct breakpoint
*b
;
8170 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8172 b
->enable_state
= bp_enabled
;
8173 update_global_location_list (1);
8179 disable_breakpoints_before_startup (void)
8181 current_program_space
->executing_startup
= 1;
8182 update_global_location_list (0);
8186 enable_breakpoints_after_startup (void)
8188 current_program_space
->executing_startup
= 0;
8189 breakpoint_re_set ();
8193 /* Set a breakpoint that will evaporate an end of command
8194 at address specified by SAL.
8195 Restrict it to frame FRAME if FRAME is nonzero. */
8198 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8199 struct frame_id frame_id
, enum bptype type
)
8201 struct breakpoint
*b
;
8203 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8205 gdb_assert (!frame_id_inlined_p (frame_id
));
8207 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8208 b
->enable_state
= bp_enabled
;
8209 b
->disposition
= disp_donttouch
;
8210 b
->frame_id
= frame_id
;
8212 /* If we're debugging a multi-threaded program, then we want
8213 momentary breakpoints to be active in only a single thread of
8215 if (in_thread_list (inferior_ptid
))
8216 b
->thread
= pid_to_thread_id (inferior_ptid
);
8218 update_global_location_list_nothrow (1);
8223 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8224 The new breakpoint will have type TYPE, and use OPS as it
8227 static struct breakpoint
*
8228 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8230 const struct breakpoint_ops
*ops
)
8232 struct breakpoint
*copy
;
8234 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8235 copy
->loc
= allocate_bp_location (copy
);
8236 set_breakpoint_location_function (copy
->loc
, 1);
8238 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8239 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8240 copy
->loc
->address
= orig
->loc
->address
;
8241 copy
->loc
->section
= orig
->loc
->section
;
8242 copy
->loc
->pspace
= orig
->loc
->pspace
;
8243 copy
->loc
->probe
= orig
->loc
->probe
;
8245 if (orig
->loc
->source_file
!= NULL
)
8246 copy
->loc
->source_file
= xstrdup (orig
->loc
->source_file
);
8248 copy
->loc
->line_number
= orig
->loc
->line_number
;
8249 copy
->frame_id
= orig
->frame_id
;
8250 copy
->thread
= orig
->thread
;
8251 copy
->pspace
= orig
->pspace
;
8253 copy
->enable_state
= bp_enabled
;
8254 copy
->disposition
= disp_donttouch
;
8255 copy
->number
= internal_breakpoint_number
--;
8257 update_global_location_list_nothrow (0);
8261 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8265 clone_momentary_breakpoint (struct breakpoint
*orig
)
8267 /* If there's nothing to clone, then return nothing. */
8271 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8275 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8278 struct symtab_and_line sal
;
8280 sal
= find_pc_line (pc
, 0);
8282 sal
.section
= find_pc_overlay (pc
);
8283 sal
.explicit_pc
= 1;
8285 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8289 /* Tell the user we have just set a breakpoint B. */
8292 mention (struct breakpoint
*b
)
8294 b
->ops
->print_mention (b
);
8295 if (ui_out_is_mi_like_p (current_uiout
))
8297 printf_filtered ("\n");
8301 static struct bp_location
*
8302 add_location_to_breakpoint (struct breakpoint
*b
,
8303 const struct symtab_and_line
*sal
)
8305 struct bp_location
*loc
, **tmp
;
8306 CORE_ADDR adjusted_address
;
8307 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8309 if (loc_gdbarch
== NULL
)
8310 loc_gdbarch
= b
->gdbarch
;
8312 /* Adjust the breakpoint's address prior to allocating a location.
8313 Once we call allocate_bp_location(), that mostly uninitialized
8314 location will be placed on the location chain. Adjustment of the
8315 breakpoint may cause target_read_memory() to be called and we do
8316 not want its scan of the location chain to find a breakpoint and
8317 location that's only been partially initialized. */
8318 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8321 loc
= allocate_bp_location (b
);
8322 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
8326 loc
->requested_address
= sal
->pc
;
8327 loc
->address
= adjusted_address
;
8328 loc
->pspace
= sal
->pspace
;
8329 loc
->probe
= sal
->probe
;
8330 gdb_assert (loc
->pspace
!= NULL
);
8331 loc
->section
= sal
->section
;
8332 loc
->gdbarch
= loc_gdbarch
;
8334 if (sal
->symtab
!= NULL
)
8335 loc
->source_file
= xstrdup (sal
->symtab
->filename
);
8336 loc
->line_number
= sal
->line
;
8338 set_breakpoint_location_function (loc
,
8339 sal
->explicit_pc
|| sal
->explicit_line
);
8344 /* Return 1 if LOC is pointing to a permanent breakpoint,
8345 return 0 otherwise. */
8348 bp_loc_is_permanent (struct bp_location
*loc
)
8352 const gdb_byte
*bpoint
;
8353 gdb_byte
*target_mem
;
8354 struct cleanup
*cleanup
;
8357 gdb_assert (loc
!= NULL
);
8359 addr
= loc
->address
;
8360 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
8362 /* Software breakpoints unsupported? */
8366 target_mem
= alloca (len
);
8368 /* Enable the automatic memory restoration from breakpoints while
8369 we read the memory. Otherwise we could say about our temporary
8370 breakpoints they are permanent. */
8371 cleanup
= save_current_space_and_thread ();
8373 switch_to_program_space_and_thread (loc
->pspace
);
8374 make_show_memory_breakpoints_cleanup (0);
8376 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
8377 && memcmp (target_mem
, bpoint
, len
) == 0)
8380 do_cleanups (cleanup
);
8387 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8388 as textual description of the location, and COND_STRING
8389 as condition expression. */
8392 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8393 struct symtabs_and_lines sals
, char *addr_string
,
8394 char *filter
, char *cond_string
,
8395 enum bptype type
, enum bpdisp disposition
,
8396 int thread
, int task
, int ignore_count
,
8397 const struct breakpoint_ops
*ops
, int from_tty
,
8398 int enabled
, int internal
, unsigned flags
,
8399 int display_canonical
)
8403 if (type
== bp_hardware_breakpoint
)
8405 int target_resources_ok
;
8407 i
= hw_breakpoint_used_count ();
8408 target_resources_ok
=
8409 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8411 if (target_resources_ok
== 0)
8412 error (_("No hardware breakpoint support in the target."));
8413 else if (target_resources_ok
< 0)
8414 error (_("Hardware breakpoints used exceeds limit."));
8417 gdb_assert (sals
.nelts
> 0);
8419 for (i
= 0; i
< sals
.nelts
; ++i
)
8421 struct symtab_and_line sal
= sals
.sals
[i
];
8422 struct bp_location
*loc
;
8426 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8428 loc_gdbarch
= gdbarch
;
8430 describe_other_breakpoints (loc_gdbarch
,
8431 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8436 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8440 b
->cond_string
= cond_string
;
8441 b
->ignore_count
= ignore_count
;
8442 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8443 b
->disposition
= disposition
;
8445 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8446 b
->loc
->inserted
= 1;
8448 if (type
== bp_static_tracepoint
)
8450 struct tracepoint
*t
= (struct tracepoint
*) b
;
8451 struct static_tracepoint_marker marker
;
8453 if (strace_marker_p (b
))
8455 /* We already know the marker exists, otherwise, we
8456 wouldn't see a sal for it. */
8457 char *p
= &addr_string
[3];
8461 p
= skip_spaces (p
);
8463 endp
= skip_to_space (p
);
8465 marker_str
= savestring (p
, endp
- p
);
8466 t
->static_trace_marker_id
= marker_str
;
8468 printf_filtered (_("Probed static tracepoint "
8470 t
->static_trace_marker_id
);
8472 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8474 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
8475 release_static_tracepoint_marker (&marker
);
8477 printf_filtered (_("Probed static tracepoint "
8479 t
->static_trace_marker_id
);
8482 warning (_("Couldn't determine the static "
8483 "tracepoint marker to probe"));
8490 loc
= add_location_to_breakpoint (b
, &sal
);
8491 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8495 if (bp_loc_is_permanent (loc
))
8496 make_breakpoint_permanent (b
);
8500 char *arg
= b
->cond_string
;
8501 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
8503 error (_("Garbage %s follows condition"), arg
);
8507 b
->display_canonical
= display_canonical
;
8509 b
->addr_string
= addr_string
;
8511 /* addr_string has to be used or breakpoint_re_set will delete
8514 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
8519 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8520 struct symtabs_and_lines sals
, char *addr_string
,
8521 char *filter
, char *cond_string
,
8522 enum bptype type
, enum bpdisp disposition
,
8523 int thread
, int task
, int ignore_count
,
8524 const struct breakpoint_ops
*ops
, int from_tty
,
8525 int enabled
, int internal
, unsigned flags
,
8526 int display_canonical
)
8528 struct breakpoint
*b
;
8529 struct cleanup
*old_chain
;
8531 if (is_tracepoint_type (type
))
8533 struct tracepoint
*t
;
8535 t
= XCNEW (struct tracepoint
);
8539 b
= XNEW (struct breakpoint
);
8541 old_chain
= make_cleanup (xfree
, b
);
8543 init_breakpoint_sal (b
, gdbarch
,
8545 filter
, cond_string
,
8547 thread
, task
, ignore_count
,
8549 enabled
, internal
, flags
,
8551 discard_cleanups (old_chain
);
8553 install_breakpoint (internal
, b
, 0);
8556 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8557 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8558 value. COND_STRING, if not NULL, specified the condition to be
8559 used for all breakpoints. Essentially the only case where
8560 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8561 function. In that case, it's still not possible to specify
8562 separate conditions for different overloaded functions, so
8563 we take just a single condition string.
8565 NOTE: If the function succeeds, the caller is expected to cleanup
8566 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8567 array contents). If the function fails (error() is called), the
8568 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8569 COND and SALS arrays and each of those arrays contents. */
8572 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8573 struct linespec_result
*canonical
,
8575 enum bptype type
, enum bpdisp disposition
,
8576 int thread
, int task
, int ignore_count
,
8577 const struct breakpoint_ops
*ops
, int from_tty
,
8578 int enabled
, int internal
, unsigned flags
)
8581 struct linespec_sals
*lsal
;
8583 if (canonical
->pre_expanded
)
8584 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
8586 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
8588 /* Note that 'addr_string' can be NULL in the case of a plain
8589 'break', without arguments. */
8590 char *addr_string
= (canonical
->addr_string
8591 ? xstrdup (canonical
->addr_string
)
8593 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
8594 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
8596 make_cleanup (xfree
, filter_string
);
8597 create_breakpoint_sal (gdbarch
, lsal
->sals
,
8600 cond_string
, type
, disposition
,
8601 thread
, task
, ignore_count
, ops
,
8602 from_tty
, enabled
, internal
, flags
,
8603 canonical
->special_display
);
8604 discard_cleanups (inner
);
8608 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8609 followed by conditionals. On return, SALS contains an array of SAL
8610 addresses found. ADDR_STRING contains a vector of (canonical)
8611 address strings. ADDRESS points to the end of the SAL.
8613 The array and the line spec strings are allocated on the heap, it is
8614 the caller's responsibility to free them. */
8617 parse_breakpoint_sals (char **address
,
8618 struct linespec_result
*canonical
)
8620 char *addr_start
= *address
;
8622 /* If no arg given, or if first arg is 'if ', use the default
8624 if ((*address
) == NULL
8625 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
8627 /* The last displayed codepoint, if it's valid, is our default breakpoint
8629 if (last_displayed_sal_is_valid ())
8631 struct linespec_sals lsal
;
8632 struct symtab_and_line sal
;
8634 init_sal (&sal
); /* Initialize to zeroes. */
8635 lsal
.sals
.sals
= (struct symtab_and_line
*)
8636 xmalloc (sizeof (struct symtab_and_line
));
8638 /* Set sal's pspace, pc, symtab, and line to the values
8639 corresponding to the last call to print_frame_info. */
8640 get_last_displayed_sal (&sal
);
8641 sal
.section
= find_pc_overlay (sal
.pc
);
8643 /* "break" without arguments is equivalent to "break *PC"
8644 where PC is the last displayed codepoint's address. So
8645 make sure to set sal.explicit_pc to prevent GDB from
8646 trying to expand the list of sals to include all other
8647 instances with the same symtab and line. */
8648 sal
.explicit_pc
= 1;
8650 lsal
.sals
.sals
[0] = sal
;
8651 lsal
.sals
.nelts
= 1;
8652 lsal
.canonical
= NULL
;
8654 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
8657 error (_("No default breakpoint address now."));
8661 /* Force almost all breakpoints to be in terms of the
8662 current_source_symtab (which is decode_line_1's default).
8663 This should produce the results we want almost all of the
8664 time while leaving default_breakpoint_* alone. */
8665 if (last_displayed_sal_is_valid ())
8666 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8667 get_last_displayed_symtab (),
8668 get_last_displayed_line (),
8669 canonical
, NULL
, NULL
);
8671 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8672 (struct symtab
*) NULL
, 0,
8673 canonical
, NULL
, NULL
);
8678 /* Convert each SAL into a real PC. Verify that the PC can be
8679 inserted as a breakpoint. If it can't throw an error. */
8682 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
8686 for (i
= 0; i
< sals
->nelts
; i
++)
8687 resolve_sal_pc (&sals
->sals
[i
]);
8690 /* Fast tracepoints may have restrictions on valid locations. For
8691 instance, a fast tracepoint using a jump instead of a trap will
8692 likely have to overwrite more bytes than a trap would, and so can
8693 only be placed where the instruction is longer than the jump, or a
8694 multi-instruction sequence does not have a jump into the middle of
8698 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8699 struct symtabs_and_lines
*sals
)
8702 struct symtab_and_line
*sal
;
8704 struct cleanup
*old_chain
;
8706 for (i
= 0; i
< sals
->nelts
; i
++)
8708 struct gdbarch
*sarch
;
8710 sal
= &sals
->sals
[i
];
8712 sarch
= get_sal_arch (*sal
);
8713 /* We fall back to GDBARCH if there is no architecture
8714 associated with SAL. */
8717 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
8719 old_chain
= make_cleanup (xfree
, msg
);
8722 error (_("May not have a fast tracepoint at 0x%s%s"),
8723 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
8725 do_cleanups (old_chain
);
8729 /* Given TOK, a string specification of condition and thread, as
8730 accepted by the 'break' command, extract the condition
8731 string and thread number and set *COND_STRING and *THREAD.
8732 PC identifies the context at which the condition should be parsed.
8733 If no condition is found, *COND_STRING is set to NULL.
8734 If no thread is found, *THREAD is set to -1. */
8736 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
8737 char **cond_string
, int *thread
, int *task
)
8739 *cond_string
= NULL
;
8745 char *cond_start
= NULL
;
8746 char *cond_end
= NULL
;
8748 tok
= skip_spaces (tok
);
8750 end_tok
= skip_to_space (tok
);
8752 toklen
= end_tok
- tok
;
8754 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8756 struct expression
*expr
;
8758 tok
= cond_start
= end_tok
+ 1;
8759 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
8762 *cond_string
= savestring (cond_start
,
8763 cond_end
- cond_start
);
8765 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8771 *thread
= strtol (tok
, &tok
, 0);
8773 error (_("Junk after thread keyword."));
8774 if (!valid_thread_id (*thread
))
8775 error (_("Unknown thread %d."), *thread
);
8777 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8783 *task
= strtol (tok
, &tok
, 0);
8785 error (_("Junk after task keyword."));
8786 if (!valid_task_id (*task
))
8787 error (_("Unknown task %d."), *task
);
8790 error (_("Junk at end of arguments."));
8794 /* Decode a static tracepoint marker spec. */
8796 static struct symtabs_and_lines
8797 decode_static_tracepoint_spec (char **arg_p
)
8799 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
8800 struct symtabs_and_lines sals
;
8801 struct symtab_and_line sal
;
8803 struct cleanup
*old_chain
;
8804 char *p
= &(*arg_p
)[3];
8809 p
= skip_spaces (p
);
8811 endp
= skip_to_space (p
);
8813 marker_str
= savestring (p
, endp
- p
);
8814 old_chain
= make_cleanup (xfree
, marker_str
);
8816 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
8817 if (VEC_empty(static_tracepoint_marker_p
, markers
))
8818 error (_("No known static tracepoint marker named %s"), marker_str
);
8820 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
8821 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
8823 for (i
= 0; i
< sals
.nelts
; i
++)
8825 struct static_tracepoint_marker
*marker
;
8827 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
8829 init_sal (&sals
.sals
[i
]);
8831 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
8832 sals
.sals
[i
].pc
= marker
->address
;
8834 release_static_tracepoint_marker (marker
);
8837 do_cleanups (old_chain
);
8843 /* Set a breakpoint. This function is shared between CLI and MI
8844 functions for setting a breakpoint. This function has two major
8845 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
8846 parameter. If non-zero, the function will parse arg, extracting
8847 breakpoint location, address and thread. Otherwise, ARG is just
8848 the location of breakpoint, with condition and thread specified by
8849 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
8850 the breakpoint number will be allocated from the internal
8851 breakpoint count. Returns true if any breakpoint was created;
8855 create_breakpoint (struct gdbarch
*gdbarch
,
8856 char *arg
, char *cond_string
, int thread
,
8857 int parse_condition_and_thread
,
8858 int tempflag
, enum bptype type_wanted
,
8860 enum auto_boolean pending_break_support
,
8861 const struct breakpoint_ops
*ops
,
8862 int from_tty
, int enabled
, int internal
,
8865 volatile struct gdb_exception e
;
8866 char *copy_arg
= NULL
;
8867 char *addr_start
= arg
;
8868 struct linespec_result canonical
;
8869 struct cleanup
*old_chain
;
8870 struct cleanup
*bkpt_chain
= NULL
;
8874 int prev_bkpt_count
= breakpoint_count
;
8876 gdb_assert (ops
!= NULL
);
8878 init_linespec_result (&canonical
);
8880 TRY_CATCH (e
, RETURN_MASK_ALL
)
8882 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
8883 addr_start
, ©_arg
);
8886 /* If caller is interested in rc value from parse, set value. */
8890 if (VEC_empty (linespec_sals
, canonical
.sals
))
8896 case NOT_FOUND_ERROR
:
8898 /* If pending breakpoint support is turned off, throw
8901 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8902 throw_exception (e
);
8904 exception_print (gdb_stderr
, e
);
8906 /* If pending breakpoint support is auto query and the user
8907 selects no, then simply return the error code. */
8908 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8909 && !nquery (_("Make %s pending on future shared library load? "),
8910 bptype_string (type_wanted
)))
8913 /* At this point, either the user was queried about setting
8914 a pending breakpoint and selected yes, or pending
8915 breakpoint behavior is on and thus a pending breakpoint
8916 is defaulted on behalf of the user. */
8918 struct linespec_sals lsal
;
8920 copy_arg
= xstrdup (addr_start
);
8921 lsal
.canonical
= xstrdup (copy_arg
);
8922 lsal
.sals
.nelts
= 1;
8923 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
8924 init_sal (&lsal
.sals
.sals
[0]);
8926 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
8930 throw_exception (e
);
8934 throw_exception (e
);
8937 /* Create a chain of things that always need to be cleaned up. */
8938 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
8940 /* ----------------------------- SNIP -----------------------------
8941 Anything added to the cleanup chain beyond this point is assumed
8942 to be part of a breakpoint. If the breakpoint create succeeds
8943 then the memory is not reclaimed. */
8944 bkpt_chain
= make_cleanup (null_cleanup
, 0);
8946 /* Resolve all line numbers to PC's and verify that the addresses
8947 are ok for the target. */
8951 struct linespec_sals
*iter
;
8953 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
8954 breakpoint_sals_to_pc (&iter
->sals
);
8957 /* Fast tracepoints may have additional restrictions on location. */
8958 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8961 struct linespec_sals
*iter
;
8963 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
8964 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
8967 /* Verify that condition can be parsed, before setting any
8968 breakpoints. Allocate a separate condition expression for each
8972 struct linespec_sals
*lsal
;
8974 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
8976 if (parse_condition_and_thread
)
8978 /* Here we only parse 'arg' to separate condition
8979 from thread number, so parsing in context of first
8980 sal is OK. When setting the breakpoint we'll
8981 re-parse it in context of each sal. */
8984 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
8987 make_cleanup (xfree
, cond_string
);
8991 /* Create a private copy of condition string. */
8994 cond_string
= xstrdup (cond_string
);
8995 make_cleanup (xfree
, cond_string
);
8999 ops
->create_breakpoints_sal (gdbarch
, &canonical
, lsal
,
9000 cond_string
, type_wanted
,
9001 tempflag
? disp_del
: disp_donttouch
,
9002 thread
, task
, ignore_count
, ops
,
9003 from_tty
, enabled
, internal
, flags
);
9007 struct breakpoint
*b
;
9009 make_cleanup (xfree
, copy_arg
);
9011 if (is_tracepoint_type (type_wanted
))
9013 struct tracepoint
*t
;
9015 t
= XCNEW (struct tracepoint
);
9019 b
= XNEW (struct breakpoint
);
9021 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9023 b
->addr_string
= copy_arg
;
9024 b
->cond_string
= NULL
;
9025 b
->ignore_count
= ignore_count
;
9026 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9027 b
->condition_not_parsed
= 1;
9028 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9029 if ((type_wanted
!= bp_breakpoint
9030 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9031 b
->pspace
= current_program_space
;
9033 install_breakpoint (internal
, b
, 0);
9036 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9038 warning (_("Multiple breakpoints were set.\nUse the "
9039 "\"delete\" command to delete unwanted breakpoints."));
9040 prev_breakpoint_count
= prev_bkpt_count
;
9043 /* That's it. Discard the cleanups for data inserted into the
9045 discard_cleanups (bkpt_chain
);
9046 /* But cleanup everything else. */
9047 do_cleanups (old_chain
);
9049 /* error call may happen here - have BKPT_CHAIN already discarded. */
9050 update_global_location_list (1);
9055 /* Set a breakpoint.
9056 ARG is a string describing breakpoint address,
9057 condition, and thread.
9058 FLAG specifies if a breakpoint is hardware on,
9059 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9063 break_command_1 (char *arg
, int flag
, int from_tty
)
9065 int tempflag
= flag
& BP_TEMPFLAG
;
9066 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9067 ? bp_hardware_breakpoint
9069 struct breakpoint_ops
*ops
;
9070 const char *arg_cp
= arg
;
9072 /* Matching breakpoints on probes. */
9073 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9074 ops
= &bkpt_probe_breakpoint_ops
;
9076 ops
= &bkpt_breakpoint_ops
;
9078 create_breakpoint (get_current_arch (),
9080 NULL
, 0, 1 /* parse arg */,
9081 tempflag
, type_wanted
,
9082 0 /* Ignore count */,
9083 pending_break_support
,
9091 /* Helper function for break_command_1 and disassemble_command. */
9094 resolve_sal_pc (struct symtab_and_line
*sal
)
9098 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9100 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9101 error (_("No line %d in file \"%s\"."),
9102 sal
->line
, sal
->symtab
->filename
);
9105 /* If this SAL corresponds to a breakpoint inserted using a line
9106 number, then skip the function prologue if necessary. */
9107 if (sal
->explicit_line
)
9108 skip_prologue_sal (sal
);
9111 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9113 struct blockvector
*bv
;
9117 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
9120 sym
= block_linkage_function (b
);
9123 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
9124 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
9128 /* It really is worthwhile to have the section, so we'll
9129 just have to look harder. This case can be executed
9130 if we have line numbers but no functions (as can
9131 happen in assembly source). */
9133 struct minimal_symbol
*msym
;
9134 struct cleanup
*old_chain
= save_current_space_and_thread ();
9136 switch_to_program_space_and_thread (sal
->pspace
);
9138 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9140 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
9142 do_cleanups (old_chain
);
9149 break_command (char *arg
, int from_tty
)
9151 break_command_1 (arg
, 0, from_tty
);
9155 tbreak_command (char *arg
, int from_tty
)
9157 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9161 hbreak_command (char *arg
, int from_tty
)
9163 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9167 thbreak_command (char *arg
, int from_tty
)
9169 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9173 stop_command (char *arg
, int from_tty
)
9175 printf_filtered (_("Specify the type of breakpoint to set.\n\
9176 Usage: stop in <function | address>\n\
9177 stop at <line>\n"));
9181 stopin_command (char *arg
, int from_tty
)
9185 if (arg
== (char *) NULL
)
9187 else if (*arg
!= '*')
9192 /* Look for a ':'. If this is a line number specification, then
9193 say it is bad, otherwise, it should be an address or
9194 function/method name. */
9195 while (*argptr
&& !hasColon
)
9197 hasColon
= (*argptr
== ':');
9202 badInput
= (*argptr
!= ':'); /* Not a class::method */
9204 badInput
= isdigit (*arg
); /* a simple line number */
9208 printf_filtered (_("Usage: stop in <function | address>\n"));
9210 break_command_1 (arg
, 0, from_tty
);
9214 stopat_command (char *arg
, int from_tty
)
9218 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9225 /* Look for a ':'. If there is a '::' then get out, otherwise
9226 it is probably a line number. */
9227 while (*argptr
&& !hasColon
)
9229 hasColon
= (*argptr
== ':');
9234 badInput
= (*argptr
== ':'); /* we have class::method */
9236 badInput
= !isdigit (*arg
); /* not a line number */
9240 printf_filtered (_("Usage: stop at <line>\n"));
9242 break_command_1 (arg
, 0, from_tty
);
9245 /* Implement the "breakpoint_hit" breakpoint_ops method for
9246 ranged breakpoints. */
9249 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9250 struct address_space
*aspace
,
9252 const struct target_waitstatus
*ws
)
9254 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9255 || ws
->value
.sig
!= TARGET_SIGNAL_TRAP
)
9258 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9259 bl
->length
, aspace
, bp_addr
);
9262 /* Implement the "resources_needed" breakpoint_ops method for
9263 ranged breakpoints. */
9266 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9268 return target_ranged_break_num_registers ();
9271 /* Implement the "print_it" breakpoint_ops method for
9272 ranged breakpoints. */
9274 static enum print_stop_action
9275 print_it_ranged_breakpoint (bpstat bs
)
9277 struct breakpoint
*b
= bs
->breakpoint_at
;
9278 struct bp_location
*bl
= b
->loc
;
9279 struct ui_out
*uiout
= current_uiout
;
9281 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9283 /* Ranged breakpoints have only one location. */
9284 gdb_assert (bl
&& bl
->next
== NULL
);
9286 annotate_breakpoint (b
->number
);
9287 if (b
->disposition
== disp_del
)
9288 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
9290 ui_out_text (uiout
, "\nRanged breakpoint ");
9291 if (ui_out_is_mi_like_p (uiout
))
9293 ui_out_field_string (uiout
, "reason",
9294 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9295 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9297 ui_out_field_int (uiout
, "bkptno", b
->number
);
9298 ui_out_text (uiout
, ", ");
9300 return PRINT_SRC_AND_LOC
;
9303 /* Implement the "print_one" breakpoint_ops method for
9304 ranged breakpoints. */
9307 print_one_ranged_breakpoint (struct breakpoint
*b
,
9308 struct bp_location
**last_loc
)
9310 struct bp_location
*bl
= b
->loc
;
9311 struct value_print_options opts
;
9312 struct ui_out
*uiout
= current_uiout
;
9314 /* Ranged breakpoints have only one location. */
9315 gdb_assert (bl
&& bl
->next
== NULL
);
9317 get_user_print_options (&opts
);
9319 if (opts
.addressprint
)
9320 /* We don't print the address range here, it will be printed later
9321 by print_one_detail_ranged_breakpoint. */
9322 ui_out_field_skip (uiout
, "addr");
9324 print_breakpoint_location (b
, bl
);
9328 /* Implement the "print_one_detail" breakpoint_ops method for
9329 ranged breakpoints. */
9332 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9333 struct ui_out
*uiout
)
9335 CORE_ADDR address_start
, address_end
;
9336 struct bp_location
*bl
= b
->loc
;
9337 struct ui_file
*stb
= mem_fileopen ();
9338 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
9342 address_start
= bl
->address
;
9343 address_end
= address_start
+ bl
->length
- 1;
9345 ui_out_text (uiout
, "\taddress range: ");
9346 fprintf_unfiltered (stb
, "[%s, %s]",
9347 print_core_address (bl
->gdbarch
, address_start
),
9348 print_core_address (bl
->gdbarch
, address_end
));
9349 ui_out_field_stream (uiout
, "addr", stb
);
9350 ui_out_text (uiout
, "\n");
9352 do_cleanups (cleanup
);
9355 /* Implement the "print_mention" breakpoint_ops method for
9356 ranged breakpoints. */
9359 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9361 struct bp_location
*bl
= b
->loc
;
9362 struct ui_out
*uiout
= current_uiout
;
9365 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9367 if (ui_out_is_mi_like_p (uiout
))
9370 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9371 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9372 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9375 /* Implement the "print_recreate" breakpoint_ops method for
9376 ranged breakpoints. */
9379 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9381 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
9382 b
->addr_string_range_end
);
9383 print_recreate_thread (b
, fp
);
9386 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9388 static struct breakpoint_ops ranged_breakpoint_ops
;
9390 /* Find the address where the end of the breakpoint range should be
9391 placed, given the SAL of the end of the range. This is so that if
9392 the user provides a line number, the end of the range is set to the
9393 last instruction of the given line. */
9396 find_breakpoint_range_end (struct symtab_and_line sal
)
9400 /* If the user provided a PC value, use it. Otherwise,
9401 find the address of the end of the given location. */
9402 if (sal
.explicit_pc
)
9409 ret
= find_line_pc_range (sal
, &start
, &end
);
9411 error (_("Could not find location of the end of the range."));
9413 /* find_line_pc_range returns the start of the next line. */
9420 /* Implement the "break-range" CLI command. */
9423 break_range_command (char *arg
, int from_tty
)
9425 char *arg_start
, *addr_string_start
, *addr_string_end
;
9426 struct linespec_result canonical_start
, canonical_end
;
9427 int bp_count
, can_use_bp
, length
;
9429 struct breakpoint
*b
;
9430 struct symtab_and_line sal_start
, sal_end
;
9431 struct cleanup
*cleanup_bkpt
;
9432 struct linespec_sals
*lsal_start
, *lsal_end
;
9434 /* We don't support software ranged breakpoints. */
9435 if (target_ranged_break_num_registers () < 0)
9436 error (_("This target does not support hardware ranged breakpoints."));
9438 bp_count
= hw_breakpoint_used_count ();
9439 bp_count
+= target_ranged_break_num_registers ();
9440 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9443 error (_("Hardware breakpoints used exceeds limit."));
9445 arg
= skip_spaces (arg
);
9446 if (arg
== NULL
|| arg
[0] == '\0')
9447 error(_("No address range specified."));
9449 init_linespec_result (&canonical_start
);
9452 parse_breakpoint_sals (&arg
, &canonical_start
);
9454 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
9457 error (_("Too few arguments."));
9458 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
9459 error (_("Could not find location of the beginning of the range."));
9461 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
9463 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
9464 || lsal_start
->sals
.nelts
!= 1)
9465 error (_("Cannot create a ranged breakpoint with multiple locations."));
9467 sal_start
= lsal_start
->sals
.sals
[0];
9468 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
9469 make_cleanup (xfree
, addr_string_start
);
9471 arg
++; /* Skip the comma. */
9472 arg
= skip_spaces (arg
);
9474 /* Parse the end location. */
9476 init_linespec_result (&canonical_end
);
9479 /* We call decode_line_full directly here instead of using
9480 parse_breakpoint_sals because we need to specify the start location's
9481 symtab and line as the default symtab and line for the end of the
9482 range. This makes it possible to have ranges like "foo.c:27, +14",
9483 where +14 means 14 lines from the start location. */
9484 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9485 sal_start
.symtab
, sal_start
.line
,
9486 &canonical_end
, NULL
, NULL
);
9488 make_cleanup_destroy_linespec_result (&canonical_end
);
9490 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
9491 error (_("Could not find location of the end of the range."));
9493 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
9494 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
9495 || lsal_end
->sals
.nelts
!= 1)
9496 error (_("Cannot create a ranged breakpoint with multiple locations."));
9498 sal_end
= lsal_end
->sals
.sals
[0];
9499 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
9500 make_cleanup (xfree
, addr_string_end
);
9502 end
= find_breakpoint_range_end (sal_end
);
9503 if (sal_start
.pc
> end
)
9504 error (_("Invalid address range, end precedes start."));
9506 length
= end
- sal_start
.pc
+ 1;
9508 /* Length overflowed. */
9509 error (_("Address range too large."));
9510 else if (length
== 1)
9512 /* This range is simple enough to be handled by
9513 the `hbreak' command. */
9514 hbreak_command (addr_string_start
, 1);
9516 do_cleanups (cleanup_bkpt
);
9521 /* Now set up the breakpoint. */
9522 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9523 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9524 set_breakpoint_count (breakpoint_count
+ 1);
9525 b
->number
= breakpoint_count
;
9526 b
->disposition
= disp_donttouch
;
9527 b
->addr_string
= xstrdup (addr_string_start
);
9528 b
->addr_string_range_end
= xstrdup (addr_string_end
);
9529 b
->loc
->length
= length
;
9531 do_cleanups (cleanup_bkpt
);
9534 observer_notify_breakpoint_created (b
);
9535 update_global_location_list (1);
9538 /* Return non-zero if EXP is verified as constant. Returned zero
9539 means EXP is variable. Also the constant detection may fail for
9540 some constant expressions and in such case still falsely return
9544 watchpoint_exp_is_const (const struct expression
*exp
)
9552 /* We are only interested in the descriptor of each element. */
9553 operator_length (exp
, i
, &oplenp
, &argsp
);
9556 switch (exp
->elts
[i
].opcode
)
9566 case BINOP_LOGICAL_AND
:
9567 case BINOP_LOGICAL_OR
:
9568 case BINOP_BITWISE_AND
:
9569 case BINOP_BITWISE_IOR
:
9570 case BINOP_BITWISE_XOR
:
9572 case BINOP_NOTEQUAL
:
9588 case TERNOP_SLICE_COUNT
:
9600 case OP_OBJC_NSSTRING
:
9603 case UNOP_LOGICAL_NOT
:
9604 case UNOP_COMPLEMENT
:
9608 /* Unary, binary and ternary operators: We have to check
9609 their operands. If they are constant, then so is the
9610 result of that operation. For instance, if A and B are
9611 determined to be constants, then so is "A + B".
9613 UNOP_IND is one exception to the rule above, because the
9614 value of *ADDR is not necessarily a constant, even when
9619 /* Check whether the associated symbol is a constant.
9621 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9622 possible that a buggy compiler could mark a variable as
9623 constant even when it is not, and TYPE_CONST would return
9624 true in this case, while SYMBOL_CLASS wouldn't.
9626 We also have to check for function symbols because they
9627 are always constant. */
9629 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9631 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9632 && SYMBOL_CLASS (s
) != LOC_CONST
9633 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9638 /* The default action is to return 0 because we are using
9639 the optimistic approach here: If we don't know something,
9640 then it is not a constant. */
9649 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9652 dtor_watchpoint (struct breakpoint
*self
)
9654 struct watchpoint
*w
= (struct watchpoint
*) self
;
9656 xfree (w
->cond_exp
);
9658 xfree (w
->exp_string
);
9659 xfree (w
->exp_string_reparse
);
9660 value_free (w
->val
);
9662 base_breakpoint_ops
.dtor (self
);
9665 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9668 re_set_watchpoint (struct breakpoint
*b
)
9670 struct watchpoint
*w
= (struct watchpoint
*) b
;
9672 /* Watchpoint can be either on expression using entirely global
9673 variables, or it can be on local variables.
9675 Watchpoints of the first kind are never auto-deleted, and even
9676 persist across program restarts. Since they can use variables
9677 from shared libraries, we need to reparse expression as libraries
9678 are loaded and unloaded.
9680 Watchpoints on local variables can also change meaning as result
9681 of solib event. For example, if a watchpoint uses both a local
9682 and a global variables in expression, it's a local watchpoint,
9683 but unloading of a shared library will make the expression
9684 invalid. This is not a very common use case, but we still
9685 re-evaluate expression, to avoid surprises to the user.
9687 Note that for local watchpoints, we re-evaluate it only if
9688 watchpoints frame id is still valid. If it's not, it means the
9689 watchpoint is out of scope and will be deleted soon. In fact,
9690 I'm not sure we'll ever be called in this case.
9692 If a local watchpoint's frame id is still valid, then
9693 w->exp_valid_block is likewise valid, and we can safely use it.
9695 Don't do anything about disabled watchpoints, since they will be
9696 reevaluated again when enabled. */
9697 update_watchpoint (w
, 1 /* reparse */);
9700 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9703 insert_watchpoint (struct bp_location
*bl
)
9705 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9706 int length
= w
->exact
? 1 : bl
->length
;
9708 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9712 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9715 remove_watchpoint (struct bp_location
*bl
)
9717 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9718 int length
= w
->exact
? 1 : bl
->length
;
9720 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9725 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
9726 struct address_space
*aspace
, CORE_ADDR bp_addr
,
9727 const struct target_waitstatus
*ws
)
9729 struct breakpoint
*b
= bl
->owner
;
9730 struct watchpoint
*w
= (struct watchpoint
*) b
;
9732 /* Continuable hardware watchpoints are treated as non-existent if the
9733 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9734 some data address). Otherwise gdb won't stop on a break instruction
9735 in the code (not from a breakpoint) when a hardware watchpoint has
9736 been defined. Also skip watchpoints which we know did not trigger
9737 (did not match the data address). */
9738 if (is_hardware_watchpoint (b
)
9739 && w
->watchpoint_triggered
== watch_triggered_no
)
9746 check_status_watchpoint (bpstat bs
)
9748 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9750 bpstat_check_watchpoint (bs
);
9753 /* Implement the "resources_needed" breakpoint_ops method for
9754 hardware watchpoints. */
9757 resources_needed_watchpoint (const struct bp_location
*bl
)
9759 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9760 int length
= w
->exact
? 1 : bl
->length
;
9762 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9765 /* Implement the "works_in_software_mode" breakpoint_ops method for
9766 hardware watchpoints. */
9769 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
9771 /* Read and access watchpoints only work with hardware support. */
9772 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
9775 static enum print_stop_action
9776 print_it_watchpoint (bpstat bs
)
9778 struct cleanup
*old_chain
;
9779 struct breakpoint
*b
;
9780 const struct bp_location
*bl
;
9781 struct ui_file
*stb
;
9782 enum print_stop_action result
;
9783 struct watchpoint
*w
;
9784 struct ui_out
*uiout
= current_uiout
;
9786 gdb_assert (bs
->bp_location_at
!= NULL
);
9788 bl
= bs
->bp_location_at
;
9789 b
= bs
->breakpoint_at
;
9790 w
= (struct watchpoint
*) b
;
9792 stb
= mem_fileopen ();
9793 old_chain
= make_cleanup_ui_file_delete (stb
);
9798 case bp_hardware_watchpoint
:
9799 annotate_watchpoint (b
->number
);
9800 if (ui_out_is_mi_like_p (uiout
))
9803 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9805 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9806 ui_out_text (uiout
, "\nOld value = ");
9807 watchpoint_value_print (bs
->old_val
, stb
);
9808 ui_out_field_stream (uiout
, "old", stb
);
9809 ui_out_text (uiout
, "\nNew value = ");
9810 watchpoint_value_print (w
->val
, stb
);
9811 ui_out_field_stream (uiout
, "new", stb
);
9812 ui_out_text (uiout
, "\n");
9813 /* More than one watchpoint may have been triggered. */
9814 result
= PRINT_UNKNOWN
;
9817 case bp_read_watchpoint
:
9818 if (ui_out_is_mi_like_p (uiout
))
9821 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9823 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9824 ui_out_text (uiout
, "\nValue = ");
9825 watchpoint_value_print (w
->val
, stb
);
9826 ui_out_field_stream (uiout
, "value", stb
);
9827 ui_out_text (uiout
, "\n");
9828 result
= PRINT_UNKNOWN
;
9831 case bp_access_watchpoint
:
9832 if (bs
->old_val
!= NULL
)
9834 annotate_watchpoint (b
->number
);
9835 if (ui_out_is_mi_like_p (uiout
))
9838 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9840 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9841 ui_out_text (uiout
, "\nOld value = ");
9842 watchpoint_value_print (bs
->old_val
, stb
);
9843 ui_out_field_stream (uiout
, "old", stb
);
9844 ui_out_text (uiout
, "\nNew value = ");
9849 if (ui_out_is_mi_like_p (uiout
))
9852 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9853 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9854 ui_out_text (uiout
, "\nValue = ");
9856 watchpoint_value_print (w
->val
, stb
);
9857 ui_out_field_stream (uiout
, "new", stb
);
9858 ui_out_text (uiout
, "\n");
9859 result
= PRINT_UNKNOWN
;
9862 result
= PRINT_UNKNOWN
;
9865 do_cleanups (old_chain
);
9869 /* Implement the "print_mention" breakpoint_ops method for hardware
9873 print_mention_watchpoint (struct breakpoint
*b
)
9875 struct cleanup
*ui_out_chain
;
9876 struct watchpoint
*w
= (struct watchpoint
*) b
;
9877 struct ui_out
*uiout
= current_uiout
;
9882 ui_out_text (uiout
, "Watchpoint ");
9883 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9885 case bp_hardware_watchpoint
:
9886 ui_out_text (uiout
, "Hardware watchpoint ");
9887 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9889 case bp_read_watchpoint
:
9890 ui_out_text (uiout
, "Hardware read watchpoint ");
9891 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
9893 case bp_access_watchpoint
:
9894 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
9895 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
9898 internal_error (__FILE__
, __LINE__
,
9899 _("Invalid hardware watchpoint type."));
9902 ui_out_field_int (uiout
, "number", b
->number
);
9903 ui_out_text (uiout
, ": ");
9904 ui_out_field_string (uiout
, "exp", w
->exp_string
);
9905 do_cleanups (ui_out_chain
);
9908 /* Implement the "print_recreate" breakpoint_ops method for
9912 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9914 struct watchpoint
*w
= (struct watchpoint
*) b
;
9919 case bp_hardware_watchpoint
:
9920 fprintf_unfiltered (fp
, "watch");
9922 case bp_read_watchpoint
:
9923 fprintf_unfiltered (fp
, "rwatch");
9925 case bp_access_watchpoint
:
9926 fprintf_unfiltered (fp
, "awatch");
9929 internal_error (__FILE__
, __LINE__
,
9930 _("Invalid watchpoint type."));
9933 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
9934 print_recreate_thread (b
, fp
);
9937 /* The breakpoint_ops structure to be used in hardware watchpoints. */
9939 static struct breakpoint_ops watchpoint_breakpoint_ops
;
9941 /* Implement the "insert" breakpoint_ops method for
9942 masked hardware watchpoints. */
9945 insert_masked_watchpoint (struct bp_location
*bl
)
9947 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9949 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9950 bl
->watchpoint_type
);
9953 /* Implement the "remove" breakpoint_ops method for
9954 masked hardware watchpoints. */
9957 remove_masked_watchpoint (struct bp_location
*bl
)
9959 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9961 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9962 bl
->watchpoint_type
);
9965 /* Implement the "resources_needed" breakpoint_ops method for
9966 masked hardware watchpoints. */
9969 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
9971 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9973 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
9976 /* Implement the "works_in_software_mode" breakpoint_ops method for
9977 masked hardware watchpoints. */
9980 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
9985 /* Implement the "print_it" breakpoint_ops method for
9986 masked hardware watchpoints. */
9988 static enum print_stop_action
9989 print_it_masked_watchpoint (bpstat bs
)
9991 struct breakpoint
*b
= bs
->breakpoint_at
;
9992 struct ui_out
*uiout
= current_uiout
;
9994 /* Masked watchpoints have only one location. */
9995 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9999 case bp_hardware_watchpoint
:
10000 annotate_watchpoint (b
->number
);
10001 if (ui_out_is_mi_like_p (uiout
))
10002 ui_out_field_string
10004 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10007 case bp_read_watchpoint
:
10008 if (ui_out_is_mi_like_p (uiout
))
10009 ui_out_field_string
10011 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10014 case bp_access_watchpoint
:
10015 if (ui_out_is_mi_like_p (uiout
))
10016 ui_out_field_string
10018 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10021 internal_error (__FILE__
, __LINE__
,
10022 _("Invalid hardware watchpoint type."));
10026 ui_out_text (uiout
, _("\n\
10027 Check the underlying instruction at PC for the memory\n\
10028 address and value which triggered this watchpoint.\n"));
10029 ui_out_text (uiout
, "\n");
10031 /* More than one watchpoint may have been triggered. */
10032 return PRINT_UNKNOWN
;
10035 /* Implement the "print_one_detail" breakpoint_ops method for
10036 masked hardware watchpoints. */
10039 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10040 struct ui_out
*uiout
)
10042 struct watchpoint
*w
= (struct watchpoint
*) b
;
10044 /* Masked watchpoints have only one location. */
10045 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10047 ui_out_text (uiout
, "\tmask ");
10048 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10049 ui_out_text (uiout
, "\n");
10052 /* Implement the "print_mention" breakpoint_ops method for
10053 masked hardware watchpoints. */
10056 print_mention_masked_watchpoint (struct breakpoint
*b
)
10058 struct watchpoint
*w
= (struct watchpoint
*) b
;
10059 struct ui_out
*uiout
= current_uiout
;
10060 struct cleanup
*ui_out_chain
;
10064 case bp_hardware_watchpoint
:
10065 ui_out_text (uiout
, "Masked hardware watchpoint ");
10066 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10068 case bp_read_watchpoint
:
10069 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10070 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10072 case bp_access_watchpoint
:
10073 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10074 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10077 internal_error (__FILE__
, __LINE__
,
10078 _("Invalid hardware watchpoint type."));
10081 ui_out_field_int (uiout
, "number", b
->number
);
10082 ui_out_text (uiout
, ": ");
10083 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10084 do_cleanups (ui_out_chain
);
10087 /* Implement the "print_recreate" breakpoint_ops method for
10088 masked hardware watchpoints. */
10091 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10093 struct watchpoint
*w
= (struct watchpoint
*) b
;
10098 case bp_hardware_watchpoint
:
10099 fprintf_unfiltered (fp
, "watch");
10101 case bp_read_watchpoint
:
10102 fprintf_unfiltered (fp
, "rwatch");
10104 case bp_access_watchpoint
:
10105 fprintf_unfiltered (fp
, "awatch");
10108 internal_error (__FILE__
, __LINE__
,
10109 _("Invalid hardware watchpoint type."));
10112 sprintf_vma (tmp
, w
->hw_wp_mask
);
10113 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10114 print_recreate_thread (b
, fp
);
10117 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10119 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10121 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10124 is_masked_watchpoint (const struct breakpoint
*b
)
10126 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10129 /* accessflag: hw_write: watch write,
10130 hw_read: watch read,
10131 hw_access: watch access (read or write) */
10133 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
10134 int just_location
, int internal
)
10136 volatile struct gdb_exception e
;
10137 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10138 struct expression
*exp
;
10139 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10140 struct value
*val
, *mark
, *result
;
10141 struct frame_info
*frame
;
10142 char *exp_start
= NULL
;
10143 char *exp_end
= NULL
;
10144 char *tok
, *end_tok
;
10146 char *cond_start
= NULL
;
10147 char *cond_end
= NULL
;
10148 enum bptype bp_type
;
10151 /* Flag to indicate whether we are going to use masks for
10152 the hardware watchpoint. */
10154 CORE_ADDR mask
= 0;
10155 struct watchpoint
*w
;
10157 /* Make sure that we actually have parameters to parse. */
10158 if (arg
!= NULL
&& arg
[0] != '\0')
10162 /* Look for "parameter value" pairs at the end
10163 of the arguments string. */
10164 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
10166 /* Skip whitespace at the end of the argument list. */
10167 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10170 /* Find the beginning of the last token.
10171 This is the value of the parameter. */
10172 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10174 value_start
= tok
+ 1;
10176 /* Skip whitespace. */
10177 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10182 /* Find the beginning of the second to last token.
10183 This is the parameter itself. */
10184 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10187 toklen
= end_tok
- tok
+ 1;
10189 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
10191 /* At this point we've found a "thread" token, which means
10192 the user is trying to set a watchpoint that triggers
10193 only in a specific thread. */
10197 error(_("You can specify only one thread."));
10199 /* Extract the thread ID from the next token. */
10200 thread
= strtol (value_start
, &endp
, 0);
10202 /* Check if the user provided a valid numeric value for the
10204 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10205 error (_("Invalid thread ID specification %s."), value_start
);
10207 /* Check if the thread actually exists. */
10208 if (!valid_thread_id (thread
))
10209 error (_("Unknown thread %d."), thread
);
10211 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
10213 /* We've found a "mask" token, which means the user wants to
10214 create a hardware watchpoint that is going to have the mask
10216 struct value
*mask_value
, *mark
;
10219 error(_("You can specify only one mask."));
10221 use_mask
= just_location
= 1;
10223 mark
= value_mark ();
10224 mask_value
= parse_to_comma_and_eval (&value_start
);
10225 mask
= value_as_address (mask_value
);
10226 value_free_to_mark (mark
);
10229 /* We didn't recognize what we found. We should stop here. */
10232 /* Truncate the string and get rid of the "parameter value" pair before
10233 the arguments string is parsed by the parse_exp_1 function. */
10238 /* Parse the rest of the arguments. */
10239 innermost_block
= NULL
;
10241 exp
= parse_exp_1 (&arg
, 0, 0);
10243 /* Remove trailing whitespace from the expression before saving it.
10244 This makes the eventual display of the expression string a bit
10246 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10249 /* Checking if the expression is not constant. */
10250 if (watchpoint_exp_is_const (exp
))
10254 len
= exp_end
- exp_start
;
10255 while (len
> 0 && isspace (exp_start
[len
- 1]))
10257 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10260 exp_valid_block
= innermost_block
;
10261 mark
= value_mark ();
10262 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
10268 exp_valid_block
= NULL
;
10269 val
= value_addr (result
);
10270 release_value (val
);
10271 value_free_to_mark (mark
);
10275 ret
= target_masked_watch_num_registers (value_as_address (val
),
10278 error (_("This target does not support masked watchpoints."));
10279 else if (ret
== -2)
10280 error (_("Invalid mask or memory region."));
10283 else if (val
!= NULL
)
10284 release_value (val
);
10286 tok
= skip_spaces (arg
);
10287 end_tok
= skip_to_space (tok
);
10289 toklen
= end_tok
- tok
;
10290 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10292 struct expression
*cond
;
10294 innermost_block
= NULL
;
10295 tok
= cond_start
= end_tok
+ 1;
10296 cond
= parse_exp_1 (&tok
, 0, 0);
10298 /* The watchpoint expression may not be local, but the condition
10299 may still be. E.g.: `watch global if local > 0'. */
10300 cond_exp_valid_block
= innermost_block
;
10306 error (_("Junk at end of command."));
10308 if (accessflag
== hw_read
)
10309 bp_type
= bp_read_watchpoint
;
10310 else if (accessflag
== hw_access
)
10311 bp_type
= bp_access_watchpoint
;
10313 bp_type
= bp_hardware_watchpoint
;
10315 frame
= block_innermost_frame (exp_valid_block
);
10317 /* If the expression is "local", then set up a "watchpoint scope"
10318 breakpoint at the point where we've left the scope of the watchpoint
10319 expression. Create the scope breakpoint before the watchpoint, so
10320 that we will encounter it first in bpstat_stop_status. */
10321 if (exp_valid_block
&& frame
)
10323 if (frame_id_p (frame_unwind_caller_id (frame
)))
10326 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
10327 frame_unwind_caller_pc (frame
),
10328 bp_watchpoint_scope
,
10329 &momentary_breakpoint_ops
);
10331 scope_breakpoint
->enable_state
= bp_enabled
;
10333 /* Automatically delete the breakpoint when it hits. */
10334 scope_breakpoint
->disposition
= disp_del
;
10336 /* Only break in the proper frame (help with recursion). */
10337 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
10339 /* Set the address at which we will stop. */
10340 scope_breakpoint
->loc
->gdbarch
10341 = frame_unwind_caller_arch (frame
);
10342 scope_breakpoint
->loc
->requested_address
10343 = frame_unwind_caller_pc (frame
);
10344 scope_breakpoint
->loc
->address
10345 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10346 scope_breakpoint
->loc
->requested_address
,
10347 scope_breakpoint
->type
);
10351 /* Now set up the breakpoint. */
10353 w
= XCNEW (struct watchpoint
);
10356 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10357 &masked_watchpoint_breakpoint_ops
);
10359 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10360 &watchpoint_breakpoint_ops
);
10361 b
->thread
= thread
;
10362 b
->disposition
= disp_donttouch
;
10363 b
->pspace
= current_program_space
;
10365 w
->exp_valid_block
= exp_valid_block
;
10366 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10369 struct type
*t
= value_type (val
);
10370 CORE_ADDR addr
= value_as_address (val
);
10373 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
10374 name
= type_to_string (t
);
10376 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
10377 core_addr_to_string (addr
));
10380 w
->exp_string
= xstrprintf ("-location %.*s",
10381 (int) (exp_end
- exp_start
), exp_start
);
10383 /* The above expression is in C. */
10384 b
->language
= language_c
;
10387 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10391 w
->hw_wp_mask
= mask
;
10400 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10402 b
->cond_string
= 0;
10406 w
->watchpoint_frame
= get_frame_id (frame
);
10407 w
->watchpoint_thread
= inferior_ptid
;
10411 w
->watchpoint_frame
= null_frame_id
;
10412 w
->watchpoint_thread
= null_ptid
;
10415 if (scope_breakpoint
!= NULL
)
10417 /* The scope breakpoint is related to the watchpoint. We will
10418 need to act on them together. */
10419 b
->related_breakpoint
= scope_breakpoint
;
10420 scope_breakpoint
->related_breakpoint
= b
;
10423 if (!just_location
)
10424 value_free_to_mark (mark
);
10426 TRY_CATCH (e
, RETURN_MASK_ALL
)
10428 /* Finally update the new watchpoint. This creates the locations
10429 that should be inserted. */
10430 update_watchpoint (w
, 1);
10434 delete_breakpoint (b
);
10435 throw_exception (e
);
10438 install_breakpoint (internal
, b
, 1);
10441 /* Return count of debug registers needed to watch the given expression.
10442 If the watchpoint cannot be handled in hardware return zero. */
10445 can_use_hardware_watchpoint (struct value
*v
)
10447 int found_memory_cnt
= 0;
10448 struct value
*head
= v
;
10450 /* Did the user specifically forbid us to use hardware watchpoints? */
10451 if (!can_use_hw_watchpoints
)
10454 /* Make sure that the value of the expression depends only upon
10455 memory contents, and values computed from them within GDB. If we
10456 find any register references or function calls, we can't use a
10457 hardware watchpoint.
10459 The idea here is that evaluating an expression generates a series
10460 of values, one holding the value of every subexpression. (The
10461 expression a*b+c has five subexpressions: a, b, a*b, c, and
10462 a*b+c.) GDB's values hold almost enough information to establish
10463 the criteria given above --- they identify memory lvalues,
10464 register lvalues, computed values, etcetera. So we can evaluate
10465 the expression, and then scan the chain of values that leaves
10466 behind to decide whether we can detect any possible change to the
10467 expression's final value using only hardware watchpoints.
10469 However, I don't think that the values returned by inferior
10470 function calls are special in any way. So this function may not
10471 notice that an expression involving an inferior function call
10472 can't be watched with hardware watchpoints. FIXME. */
10473 for (; v
; v
= value_next (v
))
10475 if (VALUE_LVAL (v
) == lval_memory
)
10477 if (v
!= head
&& value_lazy (v
))
10478 /* A lazy memory lvalue in the chain is one that GDB never
10479 needed to fetch; we either just used its address (e.g.,
10480 `a' in `a.b') or we never needed it at all (e.g., `a'
10481 in `a,b'). This doesn't apply to HEAD; if that is
10482 lazy then it was not readable, but watch it anyway. */
10486 /* Ahh, memory we actually used! Check if we can cover
10487 it with hardware watchpoints. */
10488 struct type
*vtype
= check_typedef (value_type (v
));
10490 /* We only watch structs and arrays if user asked for it
10491 explicitly, never if they just happen to appear in a
10492 middle of some value chain. */
10494 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10495 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10497 CORE_ADDR vaddr
= value_address (v
);
10501 len
= (target_exact_watchpoints
10502 && is_scalar_type_recursive (vtype
))?
10503 1 : TYPE_LENGTH (value_type (v
));
10505 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10509 found_memory_cnt
+= num_regs
;
10513 else if (VALUE_LVAL (v
) != not_lval
10514 && deprecated_value_modifiable (v
) == 0)
10515 return 0; /* These are values from the history (e.g., $1). */
10516 else if (VALUE_LVAL (v
) == lval_register
)
10517 return 0; /* Cannot watch a register with a HW watchpoint. */
10520 /* The expression itself looks suitable for using a hardware
10521 watchpoint, but give the target machine a chance to reject it. */
10522 return found_memory_cnt
;
10526 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
10528 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10531 /* A helper function that looks for an argument at the start of a
10532 string. The argument must also either be at the end of the string,
10533 or be followed by whitespace. Returns 1 if it finds the argument,
10534 0 otherwise. If the argument is found, it updates *STR. */
10537 check_for_argument (char **str
, char *arg
, int arg_len
)
10539 if (strncmp (*str
, arg
, arg_len
) == 0
10540 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
10548 /* A helper function that looks for the "-location" argument and then
10549 calls watch_command_1. */
10552 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
10554 int just_location
= 0;
10557 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10558 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10560 arg
= skip_spaces (arg
);
10564 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10568 watch_command (char *arg
, int from_tty
)
10570 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10574 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10576 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10580 rwatch_command (char *arg
, int from_tty
)
10582 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10586 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10588 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10592 awatch_command (char *arg
, int from_tty
)
10594 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10598 /* Helper routines for the until_command routine in infcmd.c. Here
10599 because it uses the mechanisms of breakpoints. */
10601 struct until_break_command_continuation_args
10603 struct breakpoint
*breakpoint
;
10604 struct breakpoint
*breakpoint2
;
10608 /* This function is called by fetch_inferior_event via the
10609 cmd_continuation pointer, to complete the until command. It takes
10610 care of cleaning up the temporary breakpoints set up by the until
10613 until_break_command_continuation (void *arg
, int err
)
10615 struct until_break_command_continuation_args
*a
= arg
;
10617 delete_breakpoint (a
->breakpoint
);
10618 if (a
->breakpoint2
)
10619 delete_breakpoint (a
->breakpoint2
);
10620 delete_longjmp_breakpoint (a
->thread_num
);
10624 until_break_command (char *arg
, int from_tty
, int anywhere
)
10626 struct symtabs_and_lines sals
;
10627 struct symtab_and_line sal
;
10628 struct frame_info
*frame
= get_selected_frame (NULL
);
10629 struct gdbarch
*frame_gdbarch
= get_frame_arch (frame
);
10630 struct frame_id stack_frame_id
= get_stack_frame_id (frame
);
10631 struct frame_id caller_frame_id
= frame_unwind_caller_id (frame
);
10632 struct breakpoint
*breakpoint
;
10633 struct breakpoint
*breakpoint2
= NULL
;
10634 struct cleanup
*old_chain
;
10636 struct thread_info
*tp
;
10638 clear_proceed_status ();
10640 /* Set a breakpoint where the user wants it and at return from
10643 if (last_displayed_sal_is_valid ())
10644 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10645 get_last_displayed_symtab (),
10646 get_last_displayed_line ());
10648 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10649 (struct symtab
*) NULL
, 0);
10651 if (sals
.nelts
!= 1)
10652 error (_("Couldn't get information on specified line."));
10654 sal
= sals
.sals
[0];
10655 xfree (sals
.sals
); /* malloc'd, so freed. */
10658 error (_("Junk at end of arguments."));
10660 resolve_sal_pc (&sal
);
10662 tp
= inferior_thread ();
10665 old_chain
= make_cleanup (null_cleanup
, NULL
);
10667 /* Installing a breakpoint invalidates the frame chain (as it may
10668 need to switch threads), so do any frame handling first. */
10670 /* Keep within the current frame, or in frames called by the current
10673 if (frame_id_p (caller_frame_id
))
10675 struct symtab_and_line sal2
;
10677 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10678 sal2
.pc
= frame_unwind_caller_pc (frame
);
10679 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
10683 make_cleanup_delete_breakpoint (breakpoint2
);
10685 set_longjmp_breakpoint (tp
, caller_frame_id
);
10686 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
10689 /* set_momentary_breakpoint could invalidate FRAME. */
10693 /* If the user told us to continue until a specified location,
10694 we don't specify a frame at which we need to stop. */
10695 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
10696 null_frame_id
, bp_until
);
10698 /* Otherwise, specify the selected frame, because we want to stop
10699 only at the very same frame. */
10700 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
10701 stack_frame_id
, bp_until
);
10702 make_cleanup_delete_breakpoint (breakpoint
);
10704 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
10706 /* If we are running asynchronously, and proceed call above has
10707 actually managed to start the target, arrange for breakpoints to
10708 be deleted when the target stops. Otherwise, we're already
10709 stopped and delete breakpoints via cleanup chain. */
10711 if (target_can_async_p () && is_running (inferior_ptid
))
10713 struct until_break_command_continuation_args
*args
;
10714 args
= xmalloc (sizeof (*args
));
10716 args
->breakpoint
= breakpoint
;
10717 args
->breakpoint2
= breakpoint2
;
10718 args
->thread_num
= thread
;
10720 discard_cleanups (old_chain
);
10721 add_continuation (inferior_thread (),
10722 until_break_command_continuation
, args
,
10726 do_cleanups (old_chain
);
10729 /* This function attempts to parse an optional "if <cond>" clause
10730 from the arg string. If one is not found, it returns NULL.
10732 Else, it returns a pointer to the condition string. (It does not
10733 attempt to evaluate the string against a particular block.) And,
10734 it updates arg to point to the first character following the parsed
10735 if clause in the arg string. */
10738 ep_parse_optional_if_clause (char **arg
)
10742 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
10745 /* Skip the "if" keyword. */
10748 /* Skip any extra leading whitespace, and record the start of the
10749 condition string. */
10750 *arg
= skip_spaces (*arg
);
10751 cond_string
= *arg
;
10753 /* Assume that the condition occupies the remainder of the arg
10755 (*arg
) += strlen (cond_string
);
10757 return cond_string
;
10760 /* Commands to deal with catching events, such as signals, exceptions,
10761 process start/exit, etc. */
10765 catch_fork_temporary
, catch_vfork_temporary
,
10766 catch_fork_permanent
, catch_vfork_permanent
10771 catch_fork_command_1 (char *arg
, int from_tty
,
10772 struct cmd_list_element
*command
)
10774 struct gdbarch
*gdbarch
= get_current_arch ();
10775 char *cond_string
= NULL
;
10776 catch_fork_kind fork_kind
;
10779 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
10780 tempflag
= (fork_kind
== catch_fork_temporary
10781 || fork_kind
== catch_vfork_temporary
);
10785 arg
= skip_spaces (arg
);
10787 /* The allowed syntax is:
10789 catch [v]fork if <cond>
10791 First, check if there's an if clause. */
10792 cond_string
= ep_parse_optional_if_clause (&arg
);
10794 if ((*arg
!= '\0') && !isspace (*arg
))
10795 error (_("Junk at end of arguments."));
10797 /* If this target supports it, create a fork or vfork catchpoint
10798 and enable reporting of such events. */
10801 case catch_fork_temporary
:
10802 case catch_fork_permanent
:
10803 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
10804 &catch_fork_breakpoint_ops
);
10806 case catch_vfork_temporary
:
10807 case catch_vfork_permanent
:
10808 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
10809 &catch_vfork_breakpoint_ops
);
10812 error (_("unsupported or unknown fork kind; cannot catch it"));
10818 catch_exec_command_1 (char *arg
, int from_tty
,
10819 struct cmd_list_element
*command
)
10821 struct exec_catchpoint
*c
;
10822 struct gdbarch
*gdbarch
= get_current_arch ();
10824 char *cond_string
= NULL
;
10826 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10830 arg
= skip_spaces (arg
);
10832 /* The allowed syntax is:
10834 catch exec if <cond>
10836 First, check if there's an if clause. */
10837 cond_string
= ep_parse_optional_if_clause (&arg
);
10839 if ((*arg
!= '\0') && !isspace (*arg
))
10840 error (_("Junk at end of arguments."));
10842 c
= XNEW (struct exec_catchpoint
);
10843 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
10844 &catch_exec_breakpoint_ops
);
10845 c
->exec_pathname
= NULL
;
10847 install_breakpoint (0, &c
->base
, 1);
10850 static enum print_stop_action
10851 print_it_exception_catchpoint (bpstat bs
)
10853 struct ui_out
*uiout
= current_uiout
;
10854 struct breakpoint
*b
= bs
->breakpoint_at
;
10855 int bp_temp
, bp_throw
;
10857 annotate_catchpoint (b
->number
);
10859 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10860 if (b
->loc
->address
!= b
->loc
->requested_address
)
10861 breakpoint_adjustment_warning (b
->loc
->requested_address
,
10864 bp_temp
= b
->disposition
== disp_del
;
10865 ui_out_text (uiout
,
10866 bp_temp
? "Temporary catchpoint "
10868 if (!ui_out_is_mi_like_p (uiout
))
10869 ui_out_field_int (uiout
, "bkptno", b
->number
);
10870 ui_out_text (uiout
,
10871 bp_throw
? " (exception thrown), "
10872 : " (exception caught), ");
10873 if (ui_out_is_mi_like_p (uiout
))
10875 ui_out_field_string (uiout
, "reason",
10876 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10877 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10878 ui_out_field_int (uiout
, "bkptno", b
->number
);
10880 return PRINT_SRC_AND_LOC
;
10884 print_one_exception_catchpoint (struct breakpoint
*b
,
10885 struct bp_location
**last_loc
)
10887 struct value_print_options opts
;
10888 struct ui_out
*uiout
= current_uiout
;
10890 get_user_print_options (&opts
);
10891 if (opts
.addressprint
)
10893 annotate_field (4);
10894 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
10895 ui_out_field_string (uiout
, "addr", "<PENDING>");
10897 ui_out_field_core_addr (uiout
, "addr",
10898 b
->loc
->gdbarch
, b
->loc
->address
);
10900 annotate_field (5);
10902 *last_loc
= b
->loc
;
10903 if (strstr (b
->addr_string
, "throw") != NULL
)
10904 ui_out_field_string (uiout
, "what", "exception throw");
10906 ui_out_field_string (uiout
, "what", "exception catch");
10910 print_mention_exception_catchpoint (struct breakpoint
*b
)
10912 struct ui_out
*uiout
= current_uiout
;
10916 bp_temp
= b
->disposition
== disp_del
;
10917 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10918 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
10919 : _("Catchpoint "));
10920 ui_out_field_int (uiout
, "bkptno", b
->number
);
10921 ui_out_text (uiout
, bp_throw
? _(" (throw)")
10925 /* Implement the "print_recreate" breakpoint_ops method for throw and
10926 catch catchpoints. */
10929 print_recreate_exception_catchpoint (struct breakpoint
*b
,
10930 struct ui_file
*fp
)
10935 bp_temp
= b
->disposition
== disp_del
;
10936 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10937 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
10938 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
10939 print_recreate_thread (b
, fp
);
10942 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
10945 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
10946 enum exception_event_kind ex_event
, int from_tty
)
10948 char *trigger_func_name
;
10950 if (ex_event
== EX_EVENT_CATCH
)
10951 trigger_func_name
= "__cxa_begin_catch";
10953 trigger_func_name
= "__cxa_throw";
10955 create_breakpoint (get_current_arch (),
10956 trigger_func_name
, cond_string
, -1,
10957 0 /* condition and thread are valid. */,
10958 tempflag
, bp_breakpoint
,
10960 AUTO_BOOLEAN_TRUE
/* pending */,
10961 &gnu_v3_exception_catchpoint_ops
, from_tty
,
10969 /* Deal with "catch catch" and "catch throw" commands. */
10972 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
10973 int tempflag
, int from_tty
)
10975 char *cond_string
= NULL
;
10979 arg
= skip_spaces (arg
);
10981 cond_string
= ep_parse_optional_if_clause (&arg
);
10983 if ((*arg
!= '\0') && !isspace (*arg
))
10984 error (_("Junk at end of arguments."));
10986 if (ex_event
!= EX_EVENT_THROW
10987 && ex_event
!= EX_EVENT_CATCH
)
10988 error (_("Unsupported or unknown exception event; cannot catch it"));
10990 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
10993 warning (_("Unsupported with this platform/compiler combination."));
10996 /* Implementation of "catch catch" command. */
10999 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
11001 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11003 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
11006 /* Implementation of "catch throw" command. */
11009 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
11011 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11013 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
11017 init_ada_exception_breakpoint (struct breakpoint
*b
,
11018 struct gdbarch
*gdbarch
,
11019 struct symtab_and_line sal
,
11021 const struct breakpoint_ops
*ops
,
11027 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11029 loc_gdbarch
= gdbarch
;
11031 describe_other_breakpoints (loc_gdbarch
,
11032 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11033 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11034 version for exception catchpoints, because two catchpoints
11035 used for different exception names will use the same address.
11036 In this case, a "breakpoint ... also set at..." warning is
11037 unproductive. Besides, the warning phrasing is also a bit
11038 inappropriate, we should use the word catchpoint, and tell
11039 the user what type of catchpoint it is. The above is good
11040 enough for now, though. */
11043 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11045 b
->enable_state
= bp_enabled
;
11046 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11047 b
->addr_string
= addr_string
;
11048 b
->language
= language_ada
;
11051 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11052 filter list, or NULL if no filtering is required. */
11054 catch_syscall_split_args (char *arg
)
11056 VEC(int) *result
= NULL
;
11057 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
11059 while (*arg
!= '\0')
11061 int i
, syscall_number
;
11063 char cur_name
[128];
11066 /* Skip whitespace. */
11067 while (isspace (*arg
))
11070 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
11071 cur_name
[i
] = arg
[i
];
11072 cur_name
[i
] = '\0';
11075 /* Check if the user provided a syscall name or a number. */
11076 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
11077 if (*endptr
== '\0')
11078 get_syscall_by_number (syscall_number
, &s
);
11081 /* We have a name. Let's check if it's valid and convert it
11083 get_syscall_by_name (cur_name
, &s
);
11085 if (s
.number
== UNKNOWN_SYSCALL
)
11086 /* Here we have to issue an error instead of a warning,
11087 because GDB cannot do anything useful if there's no
11088 syscall number to be caught. */
11089 error (_("Unknown syscall name '%s'."), cur_name
);
11092 /* Ok, it's valid. */
11093 VEC_safe_push (int, result
, s
.number
);
11096 discard_cleanups (cleanup
);
11100 /* Implement the "catch syscall" command. */
11103 catch_syscall_command_1 (char *arg
, int from_tty
,
11104 struct cmd_list_element
*command
)
11109 struct gdbarch
*gdbarch
= get_current_arch ();
11111 /* Checking if the feature if supported. */
11112 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11113 error (_("The feature 'catch syscall' is not supported on \
11114 this architecture yet."));
11116 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11118 arg
= skip_spaces (arg
);
11120 /* We need to do this first "dummy" translation in order
11121 to get the syscall XML file loaded or, most important,
11122 to display a warning to the user if there's no XML file
11123 for his/her architecture. */
11124 get_syscall_by_number (0, &s
);
11126 /* The allowed syntax is:
11128 catch syscall <name | number> [<name | number> ... <name | number>]
11130 Let's check if there's a syscall name. */
11133 filter
= catch_syscall_split_args (arg
);
11137 create_syscall_event_catchpoint (tempflag
, filter
,
11138 &catch_syscall_breakpoint_ops
);
11142 catch_command (char *arg
, int from_tty
)
11144 error (_("Catch requires an event name."));
11149 tcatch_command (char *arg
, int from_tty
)
11151 error (_("Catch requires an event name."));
11154 /* A qsort comparison function that sorts breakpoints in order. */
11157 compare_breakpoints (const void *a
, const void *b
)
11159 const breakpoint_p
*ba
= a
;
11160 uintptr_t ua
= (uintptr_t) *ba
;
11161 const breakpoint_p
*bb
= b
;
11162 uintptr_t ub
= (uintptr_t) *bb
;
11164 if ((*ba
)->number
< (*bb
)->number
)
11166 else if ((*ba
)->number
> (*bb
)->number
)
11169 /* Now sort by address, in case we see, e..g, two breakpoints with
11173 return ub
> ub
? 1 : 0;
11176 /* Delete breakpoints by address or line. */
11179 clear_command (char *arg
, int from_tty
)
11181 struct breakpoint
*b
, *prev
;
11182 VEC(breakpoint_p
) *found
= 0;
11185 struct symtabs_and_lines sals
;
11186 struct symtab_and_line sal
;
11188 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11192 sals
= decode_line_spec (arg
, (DECODE_LINE_FUNFIRSTLINE
11193 | DECODE_LINE_LIST_MODE
));
11198 sals
.sals
= (struct symtab_and_line
*)
11199 xmalloc (sizeof (struct symtab_and_line
));
11200 make_cleanup (xfree
, sals
.sals
);
11201 init_sal (&sal
); /* Initialize to zeroes. */
11203 /* Set sal's line, symtab, pc, and pspace to the values
11204 corresponding to the last call to print_frame_info. If the
11205 codepoint is not valid, this will set all the fields to 0. */
11206 get_last_displayed_sal (&sal
);
11207 if (sal
.symtab
== 0)
11208 error (_("No source file specified."));
11210 sals
.sals
[0] = sal
;
11216 /* We don't call resolve_sal_pc here. That's not as bad as it
11217 seems, because all existing breakpoints typically have both
11218 file/line and pc set. So, if clear is given file/line, we can
11219 match this to existing breakpoint without obtaining pc at all.
11221 We only support clearing given the address explicitly
11222 present in breakpoint table. Say, we've set breakpoint
11223 at file:line. There were several PC values for that file:line,
11224 due to optimization, all in one block.
11226 We've picked one PC value. If "clear" is issued with another
11227 PC corresponding to the same file:line, the breakpoint won't
11228 be cleared. We probably can still clear the breakpoint, but
11229 since the other PC value is never presented to user, user
11230 can only find it by guessing, and it does not seem important
11231 to support that. */
11233 /* For each line spec given, delete bps which correspond to it. Do
11234 it in two passes, solely to preserve the current behavior that
11235 from_tty is forced true if we delete more than one
11239 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11240 for (i
= 0; i
< sals
.nelts
; i
++)
11242 int is_abs
, sal_name_len
;
11244 /* If exact pc given, clear bpts at that pc.
11245 If line given (pc == 0), clear all bpts on specified line.
11246 If defaulting, clear all bpts on default line
11249 defaulting sal.pc != 0 tests to do
11254 1 0 <can't happen> */
11256 sal
= sals
.sals
[i
];
11257 is_abs
= sal
.symtab
== NULL
? 1 : IS_ABSOLUTE_PATH (sal
.symtab
->filename
);
11258 sal_name_len
= is_abs
? 0 : strlen (sal
.symtab
->filename
);
11260 /* Find all matching breakpoints and add them to 'found'. */
11261 ALL_BREAKPOINTS (b
)
11264 /* Are we going to delete b? */
11265 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11267 struct bp_location
*loc
= b
->loc
;
11268 for (; loc
; loc
= loc
->next
)
11270 /* If the user specified file:line, don't allow a PC
11271 match. This matches historical gdb behavior. */
11272 int pc_match
= (!sal
.explicit_line
11274 && (loc
->pspace
== sal
.pspace
)
11275 && (loc
->address
== sal
.pc
)
11276 && (!section_is_overlay (loc
->section
)
11277 || loc
->section
== sal
.section
));
11278 int line_match
= 0;
11280 if ((default_match
|| sal
.explicit_line
)
11281 && loc
->source_file
!= NULL
11282 && sal
.symtab
!= NULL
11283 && sal
.pspace
== loc
->pspace
11284 && loc
->line_number
== sal
.line
)
11286 if (filename_cmp (loc
->source_file
,
11287 sal
.symtab
->filename
) == 0)
11289 else if (!IS_ABSOLUTE_PATH (sal
.symtab
->filename
)
11290 && compare_filenames_for_search (loc
->source_file
,
11291 sal
.symtab
->filename
,
11296 if (pc_match
|| line_match
)
11305 VEC_safe_push(breakpoint_p
, found
, b
);
11309 /* Now go thru the 'found' chain and delete them. */
11310 if (VEC_empty(breakpoint_p
, found
))
11313 error (_("No breakpoint at %s."), arg
);
11315 error (_("No breakpoint at this line."));
11318 /* Remove duplicates from the vec. */
11319 qsort (VEC_address (breakpoint_p
, found
),
11320 VEC_length (breakpoint_p
, found
),
11321 sizeof (breakpoint_p
),
11322 compare_breakpoints
);
11323 prev
= VEC_index (breakpoint_p
, found
, 0);
11324 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11328 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11333 if (VEC_length(breakpoint_p
, found
) > 1)
11334 from_tty
= 1; /* Always report if deleted more than one. */
11337 if (VEC_length(breakpoint_p
, found
) == 1)
11338 printf_unfiltered (_("Deleted breakpoint "));
11340 printf_unfiltered (_("Deleted breakpoints "));
11342 breakpoints_changed ();
11344 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11347 printf_unfiltered ("%d ", b
->number
);
11348 delete_breakpoint (b
);
11351 putchar_unfiltered ('\n');
11353 do_cleanups (cleanups
);
11356 /* Delete breakpoint in BS if they are `delete' breakpoints and
11357 all breakpoints that are marked for deletion, whether hit or not.
11358 This is called after any breakpoint is hit, or after errors. */
11361 breakpoint_auto_delete (bpstat bs
)
11363 struct breakpoint
*b
, *b_tmp
;
11365 for (; bs
; bs
= bs
->next
)
11366 if (bs
->breakpoint_at
11367 && bs
->breakpoint_at
->disposition
== disp_del
11369 delete_breakpoint (bs
->breakpoint_at
);
11371 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11373 if (b
->disposition
== disp_del_at_next_stop
)
11374 delete_breakpoint (b
);
11378 /* A comparison function for bp_location AP and BP being interfaced to
11379 qsort. Sort elements primarily by their ADDRESS (no matter what
11380 does breakpoint_address_is_meaningful say for its OWNER),
11381 secondarily by ordering first bp_permanent OWNERed elements and
11382 terciarily just ensuring the array is sorted stable way despite
11383 qsort being an unstable algorithm. */
11386 bp_location_compare (const void *ap
, const void *bp
)
11388 struct bp_location
*a
= *(void **) ap
;
11389 struct bp_location
*b
= *(void **) bp
;
11390 /* A and B come from existing breakpoints having non-NULL OWNER. */
11391 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
11392 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
11394 if (a
->address
!= b
->address
)
11395 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11397 /* Sort locations at the same address by their pspace number, keeping
11398 locations of the same inferior (in a multi-inferior environment)
11401 if (a
->pspace
->num
!= b
->pspace
->num
)
11402 return ((a
->pspace
->num
> b
->pspace
->num
)
11403 - (a
->pspace
->num
< b
->pspace
->num
));
11405 /* Sort permanent breakpoints first. */
11406 if (a_perm
!= b_perm
)
11407 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
11409 /* Make the internal GDB representation stable across GDB runs
11410 where A and B memory inside GDB can differ. Breakpoint locations of
11411 the same type at the same address can be sorted in arbitrary order. */
11413 if (a
->owner
->number
!= b
->owner
->number
)
11414 return ((a
->owner
->number
> b
->owner
->number
)
11415 - (a
->owner
->number
< b
->owner
->number
));
11417 return (a
> b
) - (a
< b
);
11420 /* Set bp_location_placed_address_before_address_max and
11421 bp_location_shadow_len_after_address_max according to the current
11422 content of the bp_location array. */
11425 bp_location_target_extensions_update (void)
11427 struct bp_location
*bl
, **blp_tmp
;
11429 bp_location_placed_address_before_address_max
= 0;
11430 bp_location_shadow_len_after_address_max
= 0;
11432 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11434 CORE_ADDR start
, end
, addr
;
11436 if (!bp_location_has_shadow (bl
))
11439 start
= bl
->target_info
.placed_address
;
11440 end
= start
+ bl
->target_info
.shadow_len
;
11442 gdb_assert (bl
->address
>= start
);
11443 addr
= bl
->address
- start
;
11444 if (addr
> bp_location_placed_address_before_address_max
)
11445 bp_location_placed_address_before_address_max
= addr
;
11447 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11449 gdb_assert (bl
->address
< end
);
11450 addr
= end
- bl
->address
;
11451 if (addr
> bp_location_shadow_len_after_address_max
)
11452 bp_location_shadow_len_after_address_max
= addr
;
11456 /* Download tracepoint locations if they haven't been. */
11459 download_tracepoint_locations (void)
11461 struct bp_location
*bl
, **blp_tmp
;
11462 struct cleanup
*old_chain
;
11464 if (!target_can_download_tracepoint ())
11467 old_chain
= save_current_space_and_thread ();
11469 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11471 struct tracepoint
*t
;
11473 if (!is_tracepoint (bl
->owner
))
11476 if ((bl
->owner
->type
== bp_fast_tracepoint
11477 ? !may_insert_fast_tracepoints
11478 : !may_insert_tracepoints
))
11481 /* In tracepoint, locations are _never_ duplicated, so
11482 should_be_inserted is equivalent to
11483 unduplicated_should_be_inserted. */
11484 if (!should_be_inserted (bl
) || bl
->inserted
)
11487 switch_to_program_space_and_thread (bl
->pspace
);
11489 target_download_tracepoint (bl
);
11492 t
= (struct tracepoint
*) bl
->owner
;
11493 t
->number_on_target
= bl
->owner
->number
;
11496 do_cleanups (old_chain
);
11499 /* Swap the insertion/duplication state between two locations. */
11502 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11504 const int left_inserted
= left
->inserted
;
11505 const int left_duplicate
= left
->duplicate
;
11506 const int left_needs_update
= left
->needs_update
;
11507 const struct bp_target_info left_target_info
= left
->target_info
;
11509 /* Locations of tracepoints can never be duplicated. */
11510 if (is_tracepoint (left
->owner
))
11511 gdb_assert (!left
->duplicate
);
11512 if (is_tracepoint (right
->owner
))
11513 gdb_assert (!right
->duplicate
);
11515 left
->inserted
= right
->inserted
;
11516 left
->duplicate
= right
->duplicate
;
11517 left
->needs_update
= right
->needs_update
;
11518 left
->target_info
= right
->target_info
;
11519 right
->inserted
= left_inserted
;
11520 right
->duplicate
= left_duplicate
;
11521 right
->needs_update
= left_needs_update
;
11522 right
->target_info
= left_target_info
;
11525 /* Force the re-insertion of the locations at ADDRESS. This is called
11526 once a new/deleted/modified duplicate location is found and we are evaluating
11527 conditions on the target's side. Such conditions need to be updated on
11531 force_breakpoint_reinsertion (struct bp_location
*bl
)
11533 struct bp_location
**locp
= NULL
, **loc2p
;
11534 struct bp_location
*loc
;
11535 CORE_ADDR address
= 0;
11538 address
= bl
->address
;
11539 pspace_num
= bl
->pspace
->num
;
11541 /* This is only meaningful if the target is
11542 evaluating conditions and if the user has
11543 opted for condition evaluation on the target's
11545 if (gdb_evaluates_breakpoint_condition_p ()
11546 || !target_supports_evaluation_of_breakpoint_conditions ())
11549 /* Flag all breakpoint locations with this address and
11550 the same program space as the location
11551 as "its condition has changed". We need to
11552 update the conditions on the target's side. */
11553 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11557 if (!is_breakpoint (loc
->owner
)
11558 || pspace_num
!= loc
->pspace
->num
)
11561 /* Flag the location appropriately. We use a different state to
11562 let everyone know that we already updated the set of locations
11563 with addr bl->address and program space bl->pspace. This is so
11564 we don't have to keep calling these functions just to mark locations
11565 that have already been marked. */
11566 loc
->condition_changed
= condition_updated
;
11568 /* Free the agent expression bytecode as well. We will compute
11570 if (loc
->cond_bytecode
)
11572 free_agent_expr (loc
->cond_bytecode
);
11573 loc
->cond_bytecode
= NULL
;
11578 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11579 into the inferior, only remove already-inserted locations that no
11580 longer should be inserted. Functions that delete a breakpoint or
11581 breakpoints should pass false, so that deleting a breakpoint
11582 doesn't have the side effect of inserting the locations of other
11583 breakpoints that are marked not-inserted, but should_be_inserted
11584 returns true on them.
11586 This behaviour is useful is situations close to tear-down -- e.g.,
11587 after an exec, while the target still has execution, but breakpoint
11588 shadows of the previous executable image should *NOT* be restored
11589 to the new image; or before detaching, where the target still has
11590 execution and wants to delete breakpoints from GDB's lists, and all
11591 breakpoints had already been removed from the inferior. */
11594 update_global_location_list (int should_insert
)
11596 struct breakpoint
*b
;
11597 struct bp_location
**locp
, *loc
;
11598 struct cleanup
*cleanups
;
11599 /* Last breakpoint location address that was marked for update. */
11600 CORE_ADDR last_addr
= 0;
11601 /* Last breakpoint location program space that was marked for update. */
11602 int last_pspace_num
= -1;
11604 /* Used in the duplicates detection below. When iterating over all
11605 bp_locations, points to the first bp_location of a given address.
11606 Breakpoints and watchpoints of different types are never
11607 duplicates of each other. Keep one pointer for each type of
11608 breakpoint/watchpoint, so we only need to loop over all locations
11610 struct bp_location
*bp_loc_first
; /* breakpoint */
11611 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11612 struct bp_location
*awp_loc_first
; /* access watchpoint */
11613 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11615 /* Saved former bp_location array which we compare against the newly
11616 built bp_location from the current state of ALL_BREAKPOINTS. */
11617 struct bp_location
**old_location
, **old_locp
;
11618 unsigned old_location_count
;
11620 old_location
= bp_location
;
11621 old_location_count
= bp_location_count
;
11622 bp_location
= NULL
;
11623 bp_location_count
= 0;
11624 cleanups
= make_cleanup (xfree
, old_location
);
11626 ALL_BREAKPOINTS (b
)
11627 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11628 bp_location_count
++;
11630 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
11631 locp
= bp_location
;
11632 ALL_BREAKPOINTS (b
)
11633 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11635 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
11636 bp_location_compare
);
11638 bp_location_target_extensions_update ();
11640 /* Identify bp_location instances that are no longer present in the
11641 new list, and therefore should be freed. Note that it's not
11642 necessary that those locations should be removed from inferior --
11643 if there's another location at the same address (previously
11644 marked as duplicate), we don't need to remove/insert the
11647 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11648 and former bp_location array state respectively. */
11650 locp
= bp_location
;
11651 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
11654 struct bp_location
*old_loc
= *old_locp
;
11655 struct bp_location
**loc2p
;
11657 /* Tells if 'old_loc' is found among the new locations. If
11658 not, we have to free it. */
11659 int found_object
= 0;
11660 /* Tells if the location should remain inserted in the target. */
11661 int keep_in_target
= 0;
11664 /* Skip LOCP entries which will definitely never be needed.
11665 Stop either at or being the one matching OLD_LOC. */
11666 while (locp
< bp_location
+ bp_location_count
11667 && (*locp
)->address
< old_loc
->address
)
11671 (loc2p
< bp_location
+ bp_location_count
11672 && (*loc2p
)->address
== old_loc
->address
);
11675 /* Check if this is a new/duplicated location or a duplicated
11676 location that had its condition modified. If so, we want to send
11677 its condition to the target if evaluation of conditions is taking
11679 if ((*loc2p
)->condition_changed
== condition_modified
11680 && (last_addr
!= old_loc
->address
11681 || last_pspace_num
!= old_loc
->pspace
->num
))
11683 force_breakpoint_reinsertion (*loc2p
);
11684 last_pspace_num
= old_loc
->pspace
->num
;
11687 if (*loc2p
== old_loc
)
11691 /* We have already handled this address, update it so that we don't
11692 have to go through updates again. */
11693 last_addr
= old_loc
->address
;
11695 /* Target-side condition evaluation: Handle deleted locations. */
11697 force_breakpoint_reinsertion (old_loc
);
11699 /* If this location is no longer present, and inserted, look if
11700 there's maybe a new location at the same address. If so,
11701 mark that one inserted, and don't remove this one. This is
11702 needed so that we don't have a time window where a breakpoint
11703 at certain location is not inserted. */
11705 if (old_loc
->inserted
)
11707 /* If the location is inserted now, we might have to remove
11710 if (found_object
&& should_be_inserted (old_loc
))
11712 /* The location is still present in the location list,
11713 and still should be inserted. Don't do anything. */
11714 keep_in_target
= 1;
11718 /* This location still exists, but it won't be kept in the
11719 target since it may have been disabled. We proceed to
11720 remove its target-side condition. */
11722 /* The location is either no longer present, or got
11723 disabled. See if there's another location at the
11724 same address, in which case we don't need to remove
11725 this one from the target. */
11727 /* OLD_LOC comes from existing struct breakpoint. */
11728 if (breakpoint_address_is_meaningful (old_loc
->owner
))
11731 (loc2p
< bp_location
+ bp_location_count
11732 && (*loc2p
)->address
== old_loc
->address
);
11735 struct bp_location
*loc2
= *loc2p
;
11737 if (breakpoint_locations_match (loc2
, old_loc
))
11739 /* Read watchpoint locations are switched to
11740 access watchpoints, if the former are not
11741 supported, but the latter are. */
11742 if (is_hardware_watchpoint (old_loc
->owner
))
11744 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11745 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11748 /* loc2 is a duplicated location. We need to check
11749 if it should be inserted in case it will be
11751 if (loc2
!= old_loc
11752 && unduplicated_should_be_inserted (loc2
))
11754 swap_insertion (old_loc
, loc2
);
11755 keep_in_target
= 1;
11763 if (!keep_in_target
)
11765 if (remove_breakpoint (old_loc
, mark_uninserted
))
11767 /* This is just about all we can do. We could keep
11768 this location on the global list, and try to
11769 remove it next time, but there's no particular
11770 reason why we will succeed next time.
11772 Note that at this point, old_loc->owner is still
11773 valid, as delete_breakpoint frees the breakpoint
11774 only after calling us. */
11775 printf_filtered (_("warning: Error removing "
11776 "breakpoint %d\n"),
11777 old_loc
->owner
->number
);
11785 if (removed
&& non_stop
11786 && breakpoint_address_is_meaningful (old_loc
->owner
)
11787 && !is_hardware_watchpoint (old_loc
->owner
))
11789 /* This location was removed from the target. In
11790 non-stop mode, a race condition is possible where
11791 we've removed a breakpoint, but stop events for that
11792 breakpoint are already queued and will arrive later.
11793 We apply an heuristic to be able to distinguish such
11794 SIGTRAPs from other random SIGTRAPs: we keep this
11795 breakpoint location for a bit, and will retire it
11796 after we see some number of events. The theory here
11797 is that reporting of events should, "on the average",
11798 be fair, so after a while we'll see events from all
11799 threads that have anything of interest, and no longer
11800 need to keep this breakpoint location around. We
11801 don't hold locations forever so to reduce chances of
11802 mistaking a non-breakpoint SIGTRAP for a breakpoint
11805 The heuristic failing can be disastrous on
11806 decr_pc_after_break targets.
11808 On decr_pc_after_break targets, like e.g., x86-linux,
11809 if we fail to recognize a late breakpoint SIGTRAP,
11810 because events_till_retirement has reached 0 too
11811 soon, we'll fail to do the PC adjustment, and report
11812 a random SIGTRAP to the user. When the user resumes
11813 the inferior, it will most likely immediately crash
11814 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11815 corrupted, because of being resumed e.g., in the
11816 middle of a multi-byte instruction, or skipped a
11817 one-byte instruction. This was actually seen happen
11818 on native x86-linux, and should be less rare on
11819 targets that do not support new thread events, like
11820 remote, due to the heuristic depending on
11823 Mistaking a random SIGTRAP for a breakpoint trap
11824 causes similar symptoms (PC adjustment applied when
11825 it shouldn't), but then again, playing with SIGTRAPs
11826 behind the debugger's back is asking for trouble.
11828 Since hardware watchpoint traps are always
11829 distinguishable from other traps, so we don't need to
11830 apply keep hardware watchpoint moribund locations
11831 around. We simply always ignore hardware watchpoint
11832 traps we can no longer explain. */
11834 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
11835 old_loc
->owner
= NULL
;
11837 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
11841 old_loc
->owner
= NULL
;
11842 decref_bp_location (&old_loc
);
11847 /* Rescan breakpoints at the same address and section, marking the
11848 first one as "first" and any others as "duplicates". This is so
11849 that the bpt instruction is only inserted once. If we have a
11850 permanent breakpoint at the same place as BPT, make that one the
11851 official one, and the rest as duplicates. Permanent breakpoints
11852 are sorted first for the same address.
11854 Do the same for hardware watchpoints, but also considering the
11855 watchpoint's type (regular/access/read) and length. */
11857 bp_loc_first
= NULL
;
11858 wp_loc_first
= NULL
;
11859 awp_loc_first
= NULL
;
11860 rwp_loc_first
= NULL
;
11861 ALL_BP_LOCATIONS (loc
, locp
)
11863 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11865 struct bp_location
**loc_first_p
;
11868 if (!should_be_inserted (loc
)
11869 || !breakpoint_address_is_meaningful (b
)
11870 /* Don't detect duplicate for tracepoint locations because they are
11871 never duplicated. See the comments in field `duplicate' of
11872 `struct bp_location'. */
11873 || is_tracepoint (b
))
11875 /* Clear the condition modification flag. */
11876 loc
->condition_changed
= condition_unchanged
;
11880 /* Permanent breakpoint should always be inserted. */
11881 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
11882 internal_error (__FILE__
, __LINE__
,
11883 _("allegedly permanent breakpoint is not "
11884 "actually inserted"));
11886 if (b
->type
== bp_hardware_watchpoint
)
11887 loc_first_p
= &wp_loc_first
;
11888 else if (b
->type
== bp_read_watchpoint
)
11889 loc_first_p
= &rwp_loc_first
;
11890 else if (b
->type
== bp_access_watchpoint
)
11891 loc_first_p
= &awp_loc_first
;
11893 loc_first_p
= &bp_loc_first
;
11895 if (*loc_first_p
== NULL
11896 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11897 || !breakpoint_locations_match (loc
, *loc_first_p
))
11899 *loc_first_p
= loc
;
11900 loc
->duplicate
= 0;
11902 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11904 loc
->needs_update
= 1;
11905 /* Clear the condition modification flag. */
11906 loc
->condition_changed
= condition_unchanged
;
11912 /* This and the above ensure the invariant that the first location
11913 is not duplicated, and is the inserted one.
11914 All following are marked as duplicated, and are not inserted. */
11916 swap_insertion (loc
, *loc_first_p
);
11917 loc
->duplicate
= 1;
11919 /* Clear the condition modification flag. */
11920 loc
->condition_changed
= condition_unchanged
;
11922 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
11923 && b
->enable_state
!= bp_permanent
)
11924 internal_error (__FILE__
, __LINE__
,
11925 _("another breakpoint was inserted on top of "
11926 "a permanent breakpoint"));
11929 if (breakpoints_always_inserted_mode ()
11930 && (have_live_inferiors ()
11931 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
11934 insert_breakpoint_locations ();
11937 /* Though should_insert is false, we may need to update conditions
11938 on the target's side if it is evaluating such conditions. We
11939 only update conditions for locations that are marked
11941 update_inserted_breakpoint_locations ();
11946 download_tracepoint_locations ();
11948 do_cleanups (cleanups
);
11952 breakpoint_retire_moribund (void)
11954 struct bp_location
*loc
;
11957 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
11958 if (--(loc
->events_till_retirement
) == 0)
11960 decref_bp_location (&loc
);
11961 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
11967 update_global_location_list_nothrow (int inserting
)
11969 volatile struct gdb_exception e
;
11971 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11972 update_global_location_list (inserting
);
11975 /* Clear BKP from a BPS. */
11978 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
11982 for (bs
= bps
; bs
; bs
= bs
->next
)
11983 if (bs
->breakpoint_at
== bpt
)
11985 bs
->breakpoint_at
= NULL
;
11986 bs
->old_val
= NULL
;
11987 /* bs->commands will be freed later. */
11991 /* Callback for iterate_over_threads. */
11993 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11995 struct breakpoint
*bpt
= data
;
11997 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12001 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12005 say_where (struct breakpoint
*b
)
12007 struct ui_out
*uiout
= current_uiout
;
12008 struct value_print_options opts
;
12010 get_user_print_options (&opts
);
12012 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12014 if (b
->loc
== NULL
)
12016 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12020 if (opts
.addressprint
|| b
->loc
->source_file
== NULL
)
12022 printf_filtered (" at ");
12023 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12026 if (b
->loc
->source_file
)
12028 /* If there is a single location, we can print the location
12030 if (b
->loc
->next
== NULL
)
12031 printf_filtered (": file %s, line %d.",
12032 b
->loc
->source_file
, b
->loc
->line_number
);
12034 /* This is not ideal, but each location may have a
12035 different file name, and this at least reflects the
12036 real situation somewhat. */
12037 printf_filtered (": %s.", b
->addr_string
);
12042 struct bp_location
*loc
= b
->loc
;
12044 for (; loc
; loc
= loc
->next
)
12046 printf_filtered (" (%d locations)", n
);
12051 /* Default bp_location_ops methods. */
12054 bp_location_dtor (struct bp_location
*self
)
12056 xfree (self
->cond
);
12057 if (self
->cond_bytecode
)
12058 free_agent_expr (self
->cond_bytecode
);
12059 xfree (self
->function_name
);
12060 xfree (self
->source_file
);
12063 static const struct bp_location_ops bp_location_ops
=
12068 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12072 base_breakpoint_dtor (struct breakpoint
*self
)
12074 decref_counted_command_line (&self
->commands
);
12075 xfree (self
->cond_string
);
12076 xfree (self
->addr_string
);
12077 xfree (self
->filter
);
12078 xfree (self
->addr_string_range_end
);
12081 static struct bp_location
*
12082 base_breakpoint_allocate_location (struct breakpoint
*self
)
12084 struct bp_location
*loc
;
12086 loc
= XNEW (struct bp_location
);
12087 init_bp_location (loc
, &bp_location_ops
, self
);
12092 base_breakpoint_re_set (struct breakpoint
*b
)
12094 /* Nothing to re-set. */
12097 #define internal_error_pure_virtual_called() \
12098 gdb_assert_not_reached ("pure virtual function called")
12101 base_breakpoint_insert_location (struct bp_location
*bl
)
12103 internal_error_pure_virtual_called ();
12107 base_breakpoint_remove_location (struct bp_location
*bl
)
12109 internal_error_pure_virtual_called ();
12113 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12114 struct address_space
*aspace
,
12116 const struct target_waitstatus
*ws
)
12118 internal_error_pure_virtual_called ();
12122 base_breakpoint_check_status (bpstat bs
)
12127 /* A "works_in_software_mode" breakpoint_ops method that just internal
12131 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12133 internal_error_pure_virtual_called ();
12136 /* A "resources_needed" breakpoint_ops method that just internal
12140 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12142 internal_error_pure_virtual_called ();
12145 static enum print_stop_action
12146 base_breakpoint_print_it (bpstat bs
)
12148 internal_error_pure_virtual_called ();
12152 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12153 struct ui_out
*uiout
)
12159 base_breakpoint_print_mention (struct breakpoint
*b
)
12161 internal_error_pure_virtual_called ();
12165 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12167 internal_error_pure_virtual_called ();
12171 base_breakpoint_create_sals_from_address (char **arg
,
12172 struct linespec_result
*canonical
,
12173 enum bptype type_wanted
,
12177 internal_error_pure_virtual_called ();
12181 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12182 struct linespec_result
*c
,
12183 struct linespec_sals
*lsal
,
12185 enum bptype type_wanted
,
12186 enum bpdisp disposition
,
12188 int task
, int ignore_count
,
12189 const struct breakpoint_ops
*o
,
12190 int from_tty
, int enabled
,
12191 int internal
, unsigned flags
)
12193 internal_error_pure_virtual_called ();
12197 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12198 struct symtabs_and_lines
*sals
)
12200 internal_error_pure_virtual_called ();
12203 static struct breakpoint_ops base_breakpoint_ops
=
12205 base_breakpoint_dtor
,
12206 base_breakpoint_allocate_location
,
12207 base_breakpoint_re_set
,
12208 base_breakpoint_insert_location
,
12209 base_breakpoint_remove_location
,
12210 base_breakpoint_breakpoint_hit
,
12211 base_breakpoint_check_status
,
12212 base_breakpoint_resources_needed
,
12213 base_breakpoint_works_in_software_mode
,
12214 base_breakpoint_print_it
,
12216 base_breakpoint_print_one_detail
,
12217 base_breakpoint_print_mention
,
12218 base_breakpoint_print_recreate
,
12219 base_breakpoint_create_sals_from_address
,
12220 base_breakpoint_create_breakpoints_sal
,
12221 base_breakpoint_decode_linespec
,
12224 /* Default breakpoint_ops methods. */
12227 bkpt_re_set (struct breakpoint
*b
)
12229 /* FIXME: is this still reachable? */
12230 if (b
->addr_string
== NULL
)
12232 /* Anything without a string can't be re-set. */
12233 delete_breakpoint (b
);
12237 breakpoint_re_set_default (b
);
12241 bkpt_insert_location (struct bp_location
*bl
)
12243 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12244 return target_insert_hw_breakpoint (bl
->gdbarch
,
12247 return target_insert_breakpoint (bl
->gdbarch
,
12252 bkpt_remove_location (struct bp_location
*bl
)
12254 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12255 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12257 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12261 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12262 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12263 const struct target_waitstatus
*ws
)
12265 struct breakpoint
*b
= bl
->owner
;
12267 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12268 || ws
->value
.sig
!= TARGET_SIGNAL_TRAP
)
12271 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12275 if (overlay_debugging
/* unmapped overlay section */
12276 && section_is_overlay (bl
->section
)
12277 && !section_is_mapped (bl
->section
))
12284 bkpt_resources_needed (const struct bp_location
*bl
)
12286 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12291 static enum print_stop_action
12292 bkpt_print_it (bpstat bs
)
12294 struct breakpoint
*b
;
12295 const struct bp_location
*bl
;
12297 struct ui_out
*uiout
= current_uiout
;
12299 gdb_assert (bs
->bp_location_at
!= NULL
);
12301 bl
= bs
->bp_location_at
;
12302 b
= bs
->breakpoint_at
;
12304 bp_temp
= b
->disposition
== disp_del
;
12305 if (bl
->address
!= bl
->requested_address
)
12306 breakpoint_adjustment_warning (bl
->requested_address
,
12309 annotate_breakpoint (b
->number
);
12311 ui_out_text (uiout
, "\nTemporary breakpoint ");
12313 ui_out_text (uiout
, "\nBreakpoint ");
12314 if (ui_out_is_mi_like_p (uiout
))
12316 ui_out_field_string (uiout
, "reason",
12317 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12318 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12320 ui_out_field_int (uiout
, "bkptno", b
->number
);
12321 ui_out_text (uiout
, ", ");
12323 return PRINT_SRC_AND_LOC
;
12327 bkpt_print_mention (struct breakpoint
*b
)
12329 if (ui_out_is_mi_like_p (current_uiout
))
12334 case bp_breakpoint
:
12335 case bp_gnu_ifunc_resolver
:
12336 if (b
->disposition
== disp_del
)
12337 printf_filtered (_("Temporary breakpoint"));
12339 printf_filtered (_("Breakpoint"));
12340 printf_filtered (_(" %d"), b
->number
);
12341 if (b
->type
== bp_gnu_ifunc_resolver
)
12342 printf_filtered (_(" at gnu-indirect-function resolver"));
12344 case bp_hardware_breakpoint
:
12345 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12353 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12355 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12356 fprintf_unfiltered (fp
, "tbreak");
12357 else if (tp
->type
== bp_breakpoint
)
12358 fprintf_unfiltered (fp
, "break");
12359 else if (tp
->type
== bp_hardware_breakpoint
12360 && tp
->disposition
== disp_del
)
12361 fprintf_unfiltered (fp
, "thbreak");
12362 else if (tp
->type
== bp_hardware_breakpoint
)
12363 fprintf_unfiltered (fp
, "hbreak");
12365 internal_error (__FILE__
, __LINE__
,
12366 _("unhandled breakpoint type %d"), (int) tp
->type
);
12368 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12369 print_recreate_thread (tp
, fp
);
12373 bkpt_create_sals_from_address (char **arg
,
12374 struct linespec_result
*canonical
,
12375 enum bptype type_wanted
,
12376 char *addr_start
, char **copy_arg
)
12378 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12379 addr_start
, copy_arg
);
12383 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12384 struct linespec_result
*canonical
,
12385 struct linespec_sals
*lsal
,
12387 enum bptype type_wanted
,
12388 enum bpdisp disposition
,
12390 int task
, int ignore_count
,
12391 const struct breakpoint_ops
*ops
,
12392 int from_tty
, int enabled
,
12393 int internal
, unsigned flags
)
12395 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12396 cond_string
, type_wanted
,
12397 disposition
, thread
, task
,
12398 ignore_count
, ops
, from_tty
,
12399 enabled
, internal
, flags
);
12403 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
12404 struct symtabs_and_lines
*sals
)
12406 decode_linespec_default (b
, s
, sals
);
12409 /* Virtual table for internal breakpoints. */
12412 internal_bkpt_re_set (struct breakpoint
*b
)
12416 /* Delete overlay event and longjmp master breakpoints; they
12417 will be reset later by breakpoint_re_set. */
12418 case bp_overlay_event
:
12419 case bp_longjmp_master
:
12420 case bp_std_terminate_master
:
12421 case bp_exception_master
:
12422 delete_breakpoint (b
);
12425 /* This breakpoint is special, it's set up when the inferior
12426 starts and we really don't want to touch it. */
12427 case bp_shlib_event
:
12429 /* Like bp_shlib_event, this breakpoint type is special. Once
12430 it is set up, we do not want to touch it. */
12431 case bp_thread_event
:
12437 internal_bkpt_check_status (bpstat bs
)
12439 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12441 /* If requested, stop when the dynamic linker notifies GDB of
12442 events. This allows the user to get control and place
12443 breakpoints in initializer routines for dynamically loaded
12444 objects (among other things). */
12445 bs
->stop
= stop_on_solib_events
;
12446 bs
->print
= stop_on_solib_events
;
12452 static enum print_stop_action
12453 internal_bkpt_print_it (bpstat bs
)
12455 struct ui_out
*uiout
= current_uiout
;
12456 struct breakpoint
*b
;
12458 b
= bs
->breakpoint_at
;
12462 case bp_shlib_event
:
12463 /* Did we stop because the user set the stop_on_solib_events
12464 variable? (If so, we report this as a generic, "Stopped due
12465 to shlib event" message.) */
12466 print_solib_event (0);
12469 case bp_thread_event
:
12470 /* Not sure how we will get here.
12471 GDB should not stop for these breakpoints. */
12472 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12475 case bp_overlay_event
:
12476 /* By analogy with the thread event, GDB should not stop for these. */
12477 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12480 case bp_longjmp_master
:
12481 /* These should never be enabled. */
12482 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12485 case bp_std_terminate_master
:
12486 /* These should never be enabled. */
12487 printf_filtered (_("std::terminate Master Breakpoint: "
12488 "gdb should not stop!\n"));
12491 case bp_exception_master
:
12492 /* These should never be enabled. */
12493 printf_filtered (_("Exception Master Breakpoint: "
12494 "gdb should not stop!\n"));
12498 return PRINT_NOTHING
;
12502 internal_bkpt_print_mention (struct breakpoint
*b
)
12504 /* Nothing to mention. These breakpoints are internal. */
12507 /* Virtual table for momentary breakpoints */
12510 momentary_bkpt_re_set (struct breakpoint
*b
)
12512 /* Keep temporary breakpoints, which can be encountered when we step
12513 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12514 Otherwise these should have been blown away via the cleanup chain
12515 or by breakpoint_init_inferior when we rerun the executable. */
12519 momentary_bkpt_check_status (bpstat bs
)
12521 /* Nothing. The point of these breakpoints is causing a stop. */
12524 static enum print_stop_action
12525 momentary_bkpt_print_it (bpstat bs
)
12527 struct ui_out
*uiout
= current_uiout
;
12529 if (ui_out_is_mi_like_p (uiout
))
12531 struct breakpoint
*b
= bs
->breakpoint_at
;
12536 ui_out_field_string
12538 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
12542 ui_out_field_string
12544 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
12549 return PRINT_UNKNOWN
;
12553 momentary_bkpt_print_mention (struct breakpoint
*b
)
12555 /* Nothing to mention. These breakpoints are internal. */
12558 /* Specific methods for probe breakpoints. */
12561 bkpt_probe_insert_location (struct bp_location
*bl
)
12563 int v
= bkpt_insert_location (bl
);
12567 /* The insertion was successful, now let's set the probe's semaphore
12569 bl
->probe
->pops
->set_semaphore (bl
->probe
, bl
->gdbarch
);
12576 bkpt_probe_remove_location (struct bp_location
*bl
)
12578 /* Let's clear the semaphore before removing the location. */
12579 bl
->probe
->pops
->clear_semaphore (bl
->probe
, bl
->gdbarch
);
12581 return bkpt_remove_location (bl
);
12585 bkpt_probe_create_sals_from_address (char **arg
,
12586 struct linespec_result
*canonical
,
12587 enum bptype type_wanted
,
12588 char *addr_start
, char **copy_arg
)
12590 struct linespec_sals lsal
;
12592 lsal
.sals
= parse_probes (arg
, canonical
);
12594 *copy_arg
= xstrdup (canonical
->addr_string
);
12595 lsal
.canonical
= xstrdup (*copy_arg
);
12597 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
12601 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
12602 struct symtabs_and_lines
*sals
)
12604 *sals
= parse_probes (s
, NULL
);
12606 error (_("probe not found"));
12609 /* The breakpoint_ops structure to be used in tracepoints. */
12612 tracepoint_re_set (struct breakpoint
*b
)
12614 breakpoint_re_set_default (b
);
12618 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12619 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12620 const struct target_waitstatus
*ws
)
12622 /* By definition, the inferior does not report stops at
12628 tracepoint_print_one_detail (const struct breakpoint
*self
,
12629 struct ui_out
*uiout
)
12631 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12632 if (tp
->static_trace_marker_id
)
12634 gdb_assert (self
->type
== bp_static_tracepoint
);
12636 ui_out_text (uiout
, "\tmarker id is ");
12637 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
12638 tp
->static_trace_marker_id
);
12639 ui_out_text (uiout
, "\n");
12644 tracepoint_print_mention (struct breakpoint
*b
)
12646 if (ui_out_is_mi_like_p (current_uiout
))
12651 case bp_tracepoint
:
12652 printf_filtered (_("Tracepoint"));
12653 printf_filtered (_(" %d"), b
->number
);
12655 case bp_fast_tracepoint
:
12656 printf_filtered (_("Fast tracepoint"));
12657 printf_filtered (_(" %d"), b
->number
);
12659 case bp_static_tracepoint
:
12660 printf_filtered (_("Static tracepoint"));
12661 printf_filtered (_(" %d"), b
->number
);
12664 internal_error (__FILE__
, __LINE__
,
12665 _("unhandled tracepoint type %d"), (int) b
->type
);
12672 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12674 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12676 if (self
->type
== bp_fast_tracepoint
)
12677 fprintf_unfiltered (fp
, "ftrace");
12678 if (self
->type
== bp_static_tracepoint
)
12679 fprintf_unfiltered (fp
, "strace");
12680 else if (self
->type
== bp_tracepoint
)
12681 fprintf_unfiltered (fp
, "trace");
12683 internal_error (__FILE__
, __LINE__
,
12684 _("unhandled tracepoint type %d"), (int) self
->type
);
12686 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
12687 print_recreate_thread (self
, fp
);
12689 if (tp
->pass_count
)
12690 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12694 tracepoint_create_sals_from_address (char **arg
,
12695 struct linespec_result
*canonical
,
12696 enum bptype type_wanted
,
12697 char *addr_start
, char **copy_arg
)
12699 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12700 addr_start
, copy_arg
);
12704 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12705 struct linespec_result
*canonical
,
12706 struct linespec_sals
*lsal
,
12708 enum bptype type_wanted
,
12709 enum bpdisp disposition
,
12711 int task
, int ignore_count
,
12712 const struct breakpoint_ops
*ops
,
12713 int from_tty
, int enabled
,
12714 int internal
, unsigned flags
)
12716 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12717 cond_string
, type_wanted
,
12718 disposition
, thread
, task
,
12719 ignore_count
, ops
, from_tty
,
12720 enabled
, internal
, flags
);
12724 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
12725 struct symtabs_and_lines
*sals
)
12727 decode_linespec_default (b
, s
, sals
);
12730 struct breakpoint_ops tracepoint_breakpoint_ops
;
12732 /* The breakpoint_ops structure to be use on tracepoints placed in a
12736 tracepoint_probe_create_sals_from_address (char **arg
,
12737 struct linespec_result
*canonical
,
12738 enum bptype type_wanted
,
12739 char *addr_start
, char **copy_arg
)
12741 /* We use the same method for breakpoint on probes. */
12742 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
12743 addr_start
, copy_arg
);
12747 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
12748 struct symtabs_and_lines
*sals
)
12750 /* We use the same method for breakpoint on probes. */
12751 bkpt_probe_decode_linespec (b
, s
, sals
);
12754 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
12756 /* The breakpoint_ops structure to be used on static tracepoints with
12760 strace_marker_create_sals_from_address (char **arg
,
12761 struct linespec_result
*canonical
,
12762 enum bptype type_wanted
,
12763 char *addr_start
, char **copy_arg
)
12765 struct linespec_sals lsal
;
12767 lsal
.sals
= decode_static_tracepoint_spec (arg
);
12769 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
12771 canonical
->addr_string
= xstrdup (*copy_arg
);
12772 lsal
.canonical
= xstrdup (*copy_arg
);
12773 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
12777 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12778 struct linespec_result
*canonical
,
12779 struct linespec_sals
*lsal
,
12781 enum bptype type_wanted
,
12782 enum bpdisp disposition
,
12784 int task
, int ignore_count
,
12785 const struct breakpoint_ops
*ops
,
12786 int from_tty
, int enabled
,
12787 int internal
, unsigned flags
)
12791 /* If the user is creating a static tracepoint by marker id
12792 (strace -m MARKER_ID), then store the sals index, so that
12793 breakpoint_re_set can try to match up which of the newly
12794 found markers corresponds to this one, and, don't try to
12795 expand multiple locations for each sal, given than SALS
12796 already should contain all sals for MARKER_ID. */
12798 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
12800 struct symtabs_and_lines expanded
;
12801 struct tracepoint
*tp
;
12802 struct cleanup
*old_chain
;
12805 expanded
.nelts
= 1;
12806 expanded
.sals
= &lsal
->sals
.sals
[i
];
12808 addr_string
= xstrdup (canonical
->addr_string
);
12809 old_chain
= make_cleanup (xfree
, addr_string
);
12811 tp
= XCNEW (struct tracepoint
);
12812 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
12814 cond_string
, type_wanted
, disposition
,
12815 thread
, task
, ignore_count
, ops
,
12816 from_tty
, enabled
, internal
, flags
,
12817 canonical
->special_display
);
12818 /* Given that its possible to have multiple markers with
12819 the same string id, if the user is creating a static
12820 tracepoint by marker id ("strace -m MARKER_ID"), then
12821 store the sals index, so that breakpoint_re_set can
12822 try to match up which of the newly found markers
12823 corresponds to this one */
12824 tp
->static_trace_marker_id_idx
= i
;
12826 install_breakpoint (internal
, &tp
->base
, 0);
12828 discard_cleanups (old_chain
);
12833 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
12834 struct symtabs_and_lines
*sals
)
12836 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12838 *sals
= decode_static_tracepoint_spec (s
);
12839 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
12841 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
12845 error (_("marker %s not found"), tp
->static_trace_marker_id
);
12848 static struct breakpoint_ops strace_marker_breakpoint_ops
;
12851 strace_marker_p (struct breakpoint
*b
)
12853 return b
->ops
== &strace_marker_breakpoint_ops
;
12856 /* Delete a breakpoint and clean up all traces of it in the data
12860 delete_breakpoint (struct breakpoint
*bpt
)
12862 struct breakpoint
*b
;
12864 gdb_assert (bpt
!= NULL
);
12866 /* Has this bp already been deleted? This can happen because
12867 multiple lists can hold pointers to bp's. bpstat lists are
12870 One example of this happening is a watchpoint's scope bp. When
12871 the scope bp triggers, we notice that the watchpoint is out of
12872 scope, and delete it. We also delete its scope bp. But the
12873 scope bp is marked "auto-deleting", and is already on a bpstat.
12874 That bpstat is then checked for auto-deleting bp's, which are
12877 A real solution to this problem might involve reference counts in
12878 bp's, and/or giving them pointers back to their referencing
12879 bpstat's, and teaching delete_breakpoint to only free a bp's
12880 storage when no more references were extent. A cheaper bandaid
12882 if (bpt
->type
== bp_none
)
12885 /* At least avoid this stale reference until the reference counting
12886 of breakpoints gets resolved. */
12887 if (bpt
->related_breakpoint
!= bpt
)
12889 struct breakpoint
*related
;
12890 struct watchpoint
*w
;
12892 if (bpt
->type
== bp_watchpoint_scope
)
12893 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12894 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12895 w
= (struct watchpoint
*) bpt
;
12899 watchpoint_del_at_next_stop (w
);
12901 /* Unlink bpt from the bpt->related_breakpoint ring. */
12902 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12903 related
= related
->related_breakpoint
);
12904 related
->related_breakpoint
= bpt
->related_breakpoint
;
12905 bpt
->related_breakpoint
= bpt
;
12908 /* watch_command_1 creates a watchpoint but only sets its number if
12909 update_watchpoint succeeds in creating its bp_locations. If there's
12910 a problem in that process, we'll be asked to delete the half-created
12911 watchpoint. In that case, don't announce the deletion. */
12913 observer_notify_breakpoint_deleted (bpt
);
12915 if (breakpoint_chain
== bpt
)
12916 breakpoint_chain
= bpt
->next
;
12918 ALL_BREAKPOINTS (b
)
12919 if (b
->next
== bpt
)
12921 b
->next
= bpt
->next
;
12925 /* Be sure no bpstat's are pointing at the breakpoint after it's
12927 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12928 in all threads for now. Note that we cannot just remove bpstats
12929 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12930 commands are associated with the bpstat; if we remove it here,
12931 then the later call to bpstat_do_actions (&stop_bpstat); in
12932 event-top.c won't do anything, and temporary breakpoints with
12933 commands won't work. */
12935 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12937 /* Now that breakpoint is removed from breakpoint list, update the
12938 global location list. This will remove locations that used to
12939 belong to this breakpoint. Do this before freeing the breakpoint
12940 itself, since remove_breakpoint looks at location's owner. It
12941 might be better design to have location completely
12942 self-contained, but it's not the case now. */
12943 update_global_location_list (0);
12945 bpt
->ops
->dtor (bpt
);
12946 /* On the chance that someone will soon try again to delete this
12947 same bp, we mark it as deleted before freeing its storage. */
12948 bpt
->type
= bp_none
;
12953 do_delete_breakpoint_cleanup (void *b
)
12955 delete_breakpoint (b
);
12959 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
12961 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
12964 /* Iterator function to call a user-provided callback function once
12965 for each of B and its related breakpoints. */
12968 iterate_over_related_breakpoints (struct breakpoint
*b
,
12969 void (*function
) (struct breakpoint
*,
12973 struct breakpoint
*related
;
12978 struct breakpoint
*next
;
12980 /* FUNCTION may delete RELATED. */
12981 next
= related
->related_breakpoint
;
12983 if (next
== related
)
12985 /* RELATED is the last ring entry. */
12986 function (related
, data
);
12988 /* FUNCTION may have deleted it, so we'd never reach back to
12989 B. There's nothing left to do anyway, so just break
12994 function (related
, data
);
12998 while (related
!= b
);
13002 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13004 delete_breakpoint (b
);
13007 /* A callback for map_breakpoint_numbers that calls
13008 delete_breakpoint. */
13011 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13013 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13017 delete_command (char *arg
, int from_tty
)
13019 struct breakpoint
*b
, *b_tmp
;
13025 int breaks_to_delete
= 0;
13027 /* Delete all breakpoints if no argument. Do not delete
13028 internal breakpoints, these have to be deleted with an
13029 explicit breakpoint number argument. */
13030 ALL_BREAKPOINTS (b
)
13031 if (user_breakpoint_p (b
))
13033 breaks_to_delete
= 1;
13037 /* Ask user only if there are some breakpoints to delete. */
13039 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13041 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13042 if (user_breakpoint_p (b
))
13043 delete_breakpoint (b
);
13047 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13051 all_locations_are_pending (struct bp_location
*loc
)
13053 for (; loc
; loc
= loc
->next
)
13054 if (!loc
->shlib_disabled
13055 && !loc
->pspace
->executing_startup
)
13060 /* Subroutine of update_breakpoint_locations to simplify it.
13061 Return non-zero if multiple fns in list LOC have the same name.
13062 Null names are ignored. */
13065 ambiguous_names_p (struct bp_location
*loc
)
13067 struct bp_location
*l
;
13068 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13069 (int (*) (const void *,
13070 const void *)) streq
,
13071 NULL
, xcalloc
, xfree
);
13073 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13076 const char *name
= l
->function_name
;
13078 /* Allow for some names to be NULL, ignore them. */
13082 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13084 /* NOTE: We can assume slot != NULL here because xcalloc never
13088 htab_delete (htab
);
13094 htab_delete (htab
);
13098 /* When symbols change, it probably means the sources changed as well,
13099 and it might mean the static tracepoint markers are no longer at
13100 the same address or line numbers they used to be at last we
13101 checked. Losing your static tracepoints whenever you rebuild is
13102 undesirable. This function tries to resync/rematch gdb static
13103 tracepoints with the markers on the target, for static tracepoints
13104 that have not been set by marker id. Static tracepoint that have
13105 been set by marker id are reset by marker id in breakpoint_re_set.
13108 1) For a tracepoint set at a specific address, look for a marker at
13109 the old PC. If one is found there, assume to be the same marker.
13110 If the name / string id of the marker found is different from the
13111 previous known name, assume that means the user renamed the marker
13112 in the sources, and output a warning.
13114 2) For a tracepoint set at a given line number, look for a marker
13115 at the new address of the old line number. If one is found there,
13116 assume to be the same marker. If the name / string id of the
13117 marker found is different from the previous known name, assume that
13118 means the user renamed the marker in the sources, and output a
13121 3) If a marker is no longer found at the same address or line, it
13122 may mean the marker no longer exists. But it may also just mean
13123 the code changed a bit. Maybe the user added a few lines of code
13124 that made the marker move up or down (in line number terms). Ask
13125 the target for info about the marker with the string id as we knew
13126 it. If found, update line number and address in the matching
13127 static tracepoint. This will get confused if there's more than one
13128 marker with the same ID (possible in UST, although unadvised
13129 precisely because it confuses tools). */
13131 static struct symtab_and_line
13132 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13134 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13135 struct static_tracepoint_marker marker
;
13141 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13143 if (target_static_tracepoint_marker_at (pc
, &marker
))
13145 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13146 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13148 tp
->static_trace_marker_id
, marker
.str_id
);
13150 xfree (tp
->static_trace_marker_id
);
13151 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13152 release_static_tracepoint_marker (&marker
);
13157 /* Old marker wasn't found on target at lineno. Try looking it up
13159 if (!sal
.explicit_pc
13161 && sal
.symtab
!= NULL
13162 && tp
->static_trace_marker_id
!= NULL
)
13164 VEC(static_tracepoint_marker_p
) *markers
;
13167 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13169 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13171 struct symtab_and_line sal2
;
13172 struct symbol
*sym
;
13173 struct static_tracepoint_marker
*tpmarker
;
13174 struct ui_out
*uiout
= current_uiout
;
13176 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13178 xfree (tp
->static_trace_marker_id
);
13179 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13181 warning (_("marker for static tracepoint %d (%s) not "
13182 "found at previous line number"),
13183 b
->number
, tp
->static_trace_marker_id
);
13187 sal2
.pc
= tpmarker
->address
;
13189 sal2
= find_pc_line (tpmarker
->address
, 0);
13190 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13191 ui_out_text (uiout
, "Now in ");
13194 ui_out_field_string (uiout
, "func",
13195 SYMBOL_PRINT_NAME (sym
));
13196 ui_out_text (uiout
, " at ");
13198 ui_out_field_string (uiout
, "file", sal2
.symtab
->filename
);
13199 ui_out_text (uiout
, ":");
13201 if (ui_out_is_mi_like_p (uiout
))
13203 char *fullname
= symtab_to_fullname (sal2
.symtab
);
13206 ui_out_field_string (uiout
, "fullname", fullname
);
13209 ui_out_field_int (uiout
, "line", sal2
.line
);
13210 ui_out_text (uiout
, "\n");
13212 b
->loc
->line_number
= sal2
.line
;
13214 xfree (b
->loc
->source_file
);
13216 b
->loc
->source_file
= xstrdup (sal2
.symtab
->filename
);
13218 b
->loc
->source_file
= NULL
;
13220 xfree (b
->addr_string
);
13221 b
->addr_string
= xstrprintf ("%s:%d",
13222 sal2
.symtab
->filename
,
13223 b
->loc
->line_number
);
13225 /* Might be nice to check if function changed, and warn if
13228 release_static_tracepoint_marker (tpmarker
);
13234 /* Returns 1 iff locations A and B are sufficiently same that
13235 we don't need to report breakpoint as changed. */
13238 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13242 if (a
->address
!= b
->address
)
13245 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13248 if (a
->enabled
!= b
->enabled
)
13255 if ((a
== NULL
) != (b
== NULL
))
13261 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13262 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13263 a ranged breakpoint. */
13266 update_breakpoint_locations (struct breakpoint
*b
,
13267 struct symtabs_and_lines sals
,
13268 struct symtabs_and_lines sals_end
)
13271 struct bp_location
*existing_locations
= b
->loc
;
13273 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13275 /* Ranged breakpoints have only one start location and one end
13277 b
->enable_state
= bp_disabled
;
13278 update_global_location_list (1);
13279 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13280 "multiple locations found\n"),
13285 /* If there's no new locations, and all existing locations are
13286 pending, don't do anything. This optimizes the common case where
13287 all locations are in the same shared library, that was unloaded.
13288 We'd like to retain the location, so that when the library is
13289 loaded again, we don't loose the enabled/disabled status of the
13290 individual locations. */
13291 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13296 for (i
= 0; i
< sals
.nelts
; ++i
)
13298 struct bp_location
*new_loc
;
13300 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13302 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13304 /* Reparse conditions, they might contain references to the
13306 if (b
->cond_string
!= NULL
)
13309 volatile struct gdb_exception e
;
13311 s
= b
->cond_string
;
13312 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13314 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
13319 warning (_("failed to reevaluate condition "
13320 "for breakpoint %d: %s"),
13321 b
->number
, e
.message
);
13322 new_loc
->enabled
= 0;
13326 if (sals_end
.nelts
)
13328 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
13330 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
13334 /* Update locations of permanent breakpoints. */
13335 if (b
->enable_state
== bp_permanent
)
13336 make_breakpoint_permanent (b
);
13338 /* If possible, carry over 'disable' status from existing
13341 struct bp_location
*e
= existing_locations
;
13342 /* If there are multiple breakpoints with the same function name,
13343 e.g. for inline functions, comparing function names won't work.
13344 Instead compare pc addresses; this is just a heuristic as things
13345 may have moved, but in practice it gives the correct answer
13346 often enough until a better solution is found. */
13347 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13349 for (; e
; e
= e
->next
)
13351 if (!e
->enabled
&& e
->function_name
)
13353 struct bp_location
*l
= b
->loc
;
13354 if (have_ambiguous_names
)
13356 for (; l
; l
= l
->next
)
13357 if (breakpoint_locations_match (e
, l
))
13365 for (; l
; l
= l
->next
)
13366 if (l
->function_name
13367 && strcmp (e
->function_name
, l
->function_name
) == 0)
13377 if (!locations_are_equal (existing_locations
, b
->loc
))
13378 observer_notify_breakpoint_modified (b
);
13380 update_global_location_list (1);
13383 /* Find the SaL locations corresponding to the given ADDR_STRING.
13384 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13386 static struct symtabs_and_lines
13387 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
13390 struct symtabs_and_lines sals
= {0};
13391 volatile struct gdb_exception e
;
13393 gdb_assert (b
->ops
!= NULL
);
13396 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13398 b
->ops
->decode_linespec (b
, &s
, &sals
);
13402 int not_found_and_ok
= 0;
13403 /* For pending breakpoints, it's expected that parsing will
13404 fail until the right shared library is loaded. User has
13405 already told to create pending breakpoints and don't need
13406 extra messages. If breakpoint is in bp_shlib_disabled
13407 state, then user already saw the message about that
13408 breakpoint being disabled, and don't want to see more
13410 if (e
.error
== NOT_FOUND_ERROR
13411 && (b
->condition_not_parsed
13412 || (b
->loc
&& b
->loc
->shlib_disabled
)
13413 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13414 || b
->enable_state
== bp_disabled
))
13415 not_found_and_ok
= 1;
13417 if (!not_found_and_ok
)
13419 /* We surely don't want to warn about the same breakpoint
13420 10 times. One solution, implemented here, is disable
13421 the breakpoint on error. Another solution would be to
13422 have separate 'warning emitted' flag. Since this
13423 happens only when a binary has changed, I don't know
13424 which approach is better. */
13425 b
->enable_state
= bp_disabled
;
13426 throw_exception (e
);
13430 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
13434 for (i
= 0; i
< sals
.nelts
; ++i
)
13435 resolve_sal_pc (&sals
.sals
[i
]);
13436 if (b
->condition_not_parsed
&& s
&& s
[0])
13438 char *cond_string
= 0;
13442 find_condition_and_thread (s
, sals
.sals
[0].pc
,
13443 &cond_string
, &thread
, &task
);
13445 b
->cond_string
= cond_string
;
13446 b
->thread
= thread
;
13448 b
->condition_not_parsed
= 0;
13451 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13452 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
13462 /* The default re_set method, for typical hardware or software
13463 breakpoints. Reevaluate the breakpoint and recreate its
13467 breakpoint_re_set_default (struct breakpoint
*b
)
13470 struct symtabs_and_lines sals
, sals_end
;
13471 struct symtabs_and_lines expanded
= {0};
13472 struct symtabs_and_lines expanded_end
= {0};
13474 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
13477 make_cleanup (xfree
, sals
.sals
);
13481 if (b
->addr_string_range_end
)
13483 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
13486 make_cleanup (xfree
, sals_end
.sals
);
13487 expanded_end
= sals_end
;
13491 update_breakpoint_locations (b
, expanded
, expanded_end
);
13494 /* Default method for creating SALs from an address string. It basically
13495 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13498 create_sals_from_address_default (char **arg
,
13499 struct linespec_result
*canonical
,
13500 enum bptype type_wanted
,
13501 char *addr_start
, char **copy_arg
)
13503 parse_breakpoint_sals (arg
, canonical
);
13506 /* Call create_breakpoints_sal for the given arguments. This is the default
13507 function for the `create_breakpoints_sal' method of
13511 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13512 struct linespec_result
*canonical
,
13513 struct linespec_sals
*lsal
,
13515 enum bptype type_wanted
,
13516 enum bpdisp disposition
,
13518 int task
, int ignore_count
,
13519 const struct breakpoint_ops
*ops
,
13520 int from_tty
, int enabled
,
13521 int internal
, unsigned flags
)
13523 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
13524 type_wanted
, disposition
,
13525 thread
, task
, ignore_count
, ops
, from_tty
,
13526 enabled
, internal
, flags
);
13529 /* Decode the line represented by S by calling decode_line_full. This is the
13530 default function for the `decode_linespec' method of breakpoint_ops. */
13533 decode_linespec_default (struct breakpoint
*b
, char **s
,
13534 struct symtabs_and_lines
*sals
)
13536 struct linespec_result canonical
;
13538 init_linespec_result (&canonical
);
13539 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
13540 (struct symtab
*) NULL
, 0,
13541 &canonical
, multiple_symbols_all
,
13544 /* We should get 0 or 1 resulting SALs. */
13545 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
13547 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
13549 struct linespec_sals
*lsal
;
13551 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
13552 *sals
= lsal
->sals
;
13553 /* Arrange it so the destructor does not free the
13555 lsal
->sals
.sals
= NULL
;
13558 destroy_linespec_result (&canonical
);
13561 /* Prepare the global context for a re-set of breakpoint B. */
13563 static struct cleanup
*
13564 prepare_re_set_context (struct breakpoint
*b
)
13566 struct cleanup
*cleanups
;
13568 input_radix
= b
->input_radix
;
13569 cleanups
= save_current_space_and_thread ();
13570 if (b
->pspace
!= NULL
)
13571 switch_to_program_space_and_thread (b
->pspace
);
13572 set_language (b
->language
);
13577 /* Reset a breakpoint given it's struct breakpoint * BINT.
13578 The value we return ends up being the return value from catch_errors.
13579 Unused in this case. */
13582 breakpoint_re_set_one (void *bint
)
13584 /* Get past catch_errs. */
13585 struct breakpoint
*b
= (struct breakpoint
*) bint
;
13586 struct cleanup
*cleanups
;
13588 cleanups
= prepare_re_set_context (b
);
13589 b
->ops
->re_set (b
);
13590 do_cleanups (cleanups
);
13594 /* Re-set all breakpoints after symbols have been re-loaded. */
13596 breakpoint_re_set (void)
13598 struct breakpoint
*b
, *b_tmp
;
13599 enum language save_language
;
13600 int save_input_radix
;
13601 struct cleanup
*old_chain
;
13603 save_language
= current_language
->la_language
;
13604 save_input_radix
= input_radix
;
13605 old_chain
= save_current_program_space ();
13607 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13609 /* Format possible error msg. */
13610 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
13612 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
13613 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
13614 do_cleanups (cleanups
);
13616 set_language (save_language
);
13617 input_radix
= save_input_radix
;
13619 jit_breakpoint_re_set ();
13621 do_cleanups (old_chain
);
13623 create_overlay_event_breakpoint ();
13624 create_longjmp_master_breakpoint ();
13625 create_std_terminate_master_breakpoint ();
13626 create_exception_master_breakpoint ();
13628 /* While we're at it, reset the skip list too. */
13632 /* Reset the thread number of this breakpoint:
13634 - If the breakpoint is for all threads, leave it as-is.
13635 - Else, reset it to the current thread for inferior_ptid. */
13637 breakpoint_re_set_thread (struct breakpoint
*b
)
13639 if (b
->thread
!= -1)
13641 if (in_thread_list (inferior_ptid
))
13642 b
->thread
= pid_to_thread_id (inferior_ptid
);
13644 /* We're being called after following a fork. The new fork is
13645 selected as current, and unless this was a vfork will have a
13646 different program space from the original thread. Reset that
13648 b
->loc
->pspace
= current_program_space
;
13652 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13653 If from_tty is nonzero, it prints a message to that effect,
13654 which ends with a period (no newline). */
13657 set_ignore_count (int bptnum
, int count
, int from_tty
)
13659 struct breakpoint
*b
;
13664 ALL_BREAKPOINTS (b
)
13665 if (b
->number
== bptnum
)
13667 if (is_tracepoint (b
))
13669 if (from_tty
&& count
!= 0)
13670 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13675 b
->ignore_count
= count
;
13679 printf_filtered (_("Will stop next time "
13680 "breakpoint %d is reached."),
13682 else if (count
== 1)
13683 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13686 printf_filtered (_("Will ignore next %d "
13687 "crossings of breakpoint %d."),
13690 breakpoints_changed ();
13691 observer_notify_breakpoint_modified (b
);
13695 error (_("No breakpoint number %d."), bptnum
);
13698 /* Command to set ignore-count of breakpoint N to COUNT. */
13701 ignore_command (char *args
, int from_tty
)
13707 error_no_arg (_("a breakpoint number"));
13709 num
= get_number (&p
);
13711 error (_("bad breakpoint number: '%s'"), args
);
13713 error (_("Second argument (specified ignore-count) is missing."));
13715 set_ignore_count (num
,
13716 longest_to_int (value_as_long (parse_and_eval (p
))),
13719 printf_filtered ("\n");
13722 /* Call FUNCTION on each of the breakpoints
13723 whose numbers are given in ARGS. */
13726 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
13731 struct breakpoint
*b
, *tmp
;
13733 struct get_number_or_range_state state
;
13736 error_no_arg (_("one or more breakpoint numbers"));
13738 init_number_or_range (&state
, args
);
13740 while (!state
.finished
)
13742 char *p
= state
.string
;
13746 num
= get_number_or_range (&state
);
13749 warning (_("bad breakpoint number at or near '%s'"), p
);
13753 ALL_BREAKPOINTS_SAFE (b
, tmp
)
13754 if (b
->number
== num
)
13757 function (b
, data
);
13761 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
13766 static struct bp_location
*
13767 find_location_by_number (char *number
)
13769 char *dot
= strchr (number
, '.');
13773 struct breakpoint
*b
;
13774 struct bp_location
*loc
;
13779 bp_num
= get_number (&p1
);
13781 error (_("Bad breakpoint number '%s'"), number
);
13783 ALL_BREAKPOINTS (b
)
13784 if (b
->number
== bp_num
)
13789 if (!b
|| b
->number
!= bp_num
)
13790 error (_("Bad breakpoint number '%s'"), number
);
13793 loc_num
= get_number (&p1
);
13795 error (_("Bad breakpoint location number '%s'"), number
);
13799 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
13802 error (_("Bad breakpoint location number '%s'"), dot
+1);
13808 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13809 If from_tty is nonzero, it prints a message to that effect,
13810 which ends with a period (no newline). */
13813 disable_breakpoint (struct breakpoint
*bpt
)
13815 /* Never disable a watchpoint scope breakpoint; we want to
13816 hit them when we leave scope so we can delete both the
13817 watchpoint and its scope breakpoint at that time. */
13818 if (bpt
->type
== bp_watchpoint_scope
)
13821 /* You can't disable permanent breakpoints. */
13822 if (bpt
->enable_state
== bp_permanent
)
13825 bpt
->enable_state
= bp_disabled
;
13827 /* Mark breakpoint locations modified. */
13828 mark_breakpoint_modified (bpt
);
13830 if (target_supports_enable_disable_tracepoint ()
13831 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13833 struct bp_location
*location
;
13835 for (location
= bpt
->loc
; location
; location
= location
->next
)
13836 target_disable_tracepoint (location
);
13839 update_global_location_list (0);
13841 observer_notify_breakpoint_modified (bpt
);
13844 /* A callback for iterate_over_related_breakpoints. */
13847 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
13849 disable_breakpoint (b
);
13852 /* A callback for map_breakpoint_numbers that calls
13853 disable_breakpoint. */
13856 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
13858 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
13862 disable_command (char *args
, int from_tty
)
13866 struct breakpoint
*bpt
;
13868 ALL_BREAKPOINTS (bpt
)
13869 if (user_breakpoint_p (bpt
))
13870 disable_breakpoint (bpt
);
13872 else if (strchr (args
, '.'))
13874 struct bp_location
*loc
= find_location_by_number (args
);
13880 mark_breakpoint_location_modified (loc
);
13882 if (target_supports_enable_disable_tracepoint ()
13883 && current_trace_status ()->running
&& loc
->owner
13884 && is_tracepoint (loc
->owner
))
13885 target_disable_tracepoint (loc
);
13887 update_global_location_list (0);
13890 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
13894 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13897 int target_resources_ok
;
13899 if (bpt
->type
== bp_hardware_breakpoint
)
13902 i
= hw_breakpoint_used_count ();
13903 target_resources_ok
=
13904 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13906 if (target_resources_ok
== 0)
13907 error (_("No hardware breakpoint support in the target."));
13908 else if (target_resources_ok
< 0)
13909 error (_("Hardware breakpoints used exceeds limit."));
13912 if (is_watchpoint (bpt
))
13914 /* Initialize it just to avoid a GCC false warning. */
13915 enum enable_state orig_enable_state
= 0;
13916 volatile struct gdb_exception e
;
13918 TRY_CATCH (e
, RETURN_MASK_ALL
)
13920 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13922 orig_enable_state
= bpt
->enable_state
;
13923 bpt
->enable_state
= bp_enabled
;
13924 update_watchpoint (w
, 1 /* reparse */);
13928 bpt
->enable_state
= orig_enable_state
;
13929 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13935 if (bpt
->enable_state
!= bp_permanent
)
13936 bpt
->enable_state
= bp_enabled
;
13938 bpt
->enable_state
= bp_enabled
;
13940 /* Mark breakpoint locations modified. */
13941 mark_breakpoint_modified (bpt
);
13943 if (target_supports_enable_disable_tracepoint ()
13944 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13946 struct bp_location
*location
;
13948 for (location
= bpt
->loc
; location
; location
= location
->next
)
13949 target_enable_tracepoint (location
);
13952 bpt
->disposition
= disposition
;
13953 bpt
->enable_count
= count
;
13954 update_global_location_list (1);
13955 breakpoints_changed ();
13957 observer_notify_breakpoint_modified (bpt
);
13962 enable_breakpoint (struct breakpoint
*bpt
)
13964 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13968 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
13970 enable_breakpoint (bpt
);
13973 /* A callback for map_breakpoint_numbers that calls
13974 enable_breakpoint. */
13977 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
13979 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
13982 /* The enable command enables the specified breakpoints (or all defined
13983 breakpoints) so they once again become (or continue to be) effective
13984 in stopping the inferior. */
13987 enable_command (char *args
, int from_tty
)
13991 struct breakpoint
*bpt
;
13993 ALL_BREAKPOINTS (bpt
)
13994 if (user_breakpoint_p (bpt
))
13995 enable_breakpoint (bpt
);
13997 else if (strchr (args
, '.'))
13999 struct bp_location
*loc
= find_location_by_number (args
);
14005 mark_breakpoint_location_modified (loc
);
14007 if (target_supports_enable_disable_tracepoint ()
14008 && current_trace_status ()->running
&& loc
->owner
14009 && is_tracepoint (loc
->owner
))
14010 target_enable_tracepoint (loc
);
14012 update_global_location_list (1);
14015 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
14018 /* This struct packages up disposition data for application to multiple
14028 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14030 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14032 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14036 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14038 struct disp_data disp
= { disp_disable
, 1 };
14040 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14044 enable_once_command (char *args
, int from_tty
)
14046 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14050 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14052 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14054 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14058 enable_count_command (char *args
, int from_tty
)
14060 int count
= get_number (&args
);
14062 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14066 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14068 struct disp_data disp
= { disp_del
, 1 };
14070 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14074 enable_delete_command (char *args
, int from_tty
)
14076 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14080 set_breakpoint_cmd (char *args
, int from_tty
)
14085 show_breakpoint_cmd (char *args
, int from_tty
)
14089 /* Invalidate last known value of any hardware watchpoint if
14090 the memory which that value represents has been written to by
14094 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
14095 const bfd_byte
*data
)
14097 struct breakpoint
*bp
;
14099 ALL_BREAKPOINTS (bp
)
14100 if (bp
->enable_state
== bp_enabled
14101 && bp
->type
== bp_hardware_watchpoint
)
14103 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14105 if (wp
->val_valid
&& wp
->val
)
14107 struct bp_location
*loc
;
14109 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14110 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14111 && loc
->address
+ loc
->length
> addr
14112 && addr
+ len
> loc
->address
)
14114 value_free (wp
->val
);
14122 /* Use the last displayed codepoint's values, or nothing
14123 if they aren't valid. */
14125 struct symtabs_and_lines
14126 decode_line_spec_1 (char *string
, int flags
)
14128 struct symtabs_and_lines sals
;
14131 error (_("Empty line specification."));
14132 if (last_displayed_sal_is_valid ())
14133 sals
= decode_line_1 (&string
, flags
,
14134 get_last_displayed_symtab (),
14135 get_last_displayed_line ());
14137 sals
= decode_line_1 (&string
, flags
, (struct symtab
*) NULL
, 0);
14139 error (_("Junk at end of line specification: %s"), string
);
14143 /* Create and insert a raw software breakpoint at PC. Return an
14144 identifier, which should be used to remove the breakpoint later.
14145 In general, places which call this should be using something on the
14146 breakpoint chain instead; this function should be eliminated
14150 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
14151 struct address_space
*aspace
, CORE_ADDR pc
)
14153 struct bp_target_info
*bp_tgt
;
14155 bp_tgt
= XZALLOC (struct bp_target_info
);
14157 bp_tgt
->placed_address_space
= aspace
;
14158 bp_tgt
->placed_address
= pc
;
14160 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
14162 /* Could not insert the breakpoint. */
14170 /* Remove a breakpoint BP inserted by
14171 deprecated_insert_raw_breakpoint. */
14174 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
14176 struct bp_target_info
*bp_tgt
= bp
;
14179 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
14185 /* One (or perhaps two) breakpoints used for software single
14188 static void *single_step_breakpoints
[2];
14189 static struct gdbarch
*single_step_gdbarch
[2];
14191 /* Create and insert a breakpoint for software single step. */
14194 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14195 struct address_space
*aspace
,
14200 if (single_step_breakpoints
[0] == NULL
)
14202 bpt_p
= &single_step_breakpoints
[0];
14203 single_step_gdbarch
[0] = gdbarch
;
14207 gdb_assert (single_step_breakpoints
[1] == NULL
);
14208 bpt_p
= &single_step_breakpoints
[1];
14209 single_step_gdbarch
[1] = gdbarch
;
14212 /* NOTE drow/2006-04-11: A future improvement to this function would
14213 be to only create the breakpoints once, and actually put them on
14214 the breakpoint chain. That would let us use set_raw_breakpoint.
14215 We could adjust the addresses each time they were needed. Doing
14216 this requires corresponding changes elsewhere where single step
14217 breakpoints are handled, however. So, for now, we use this. */
14219 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
14220 if (*bpt_p
== NULL
)
14221 error (_("Could not insert single-step breakpoint at %s"),
14222 paddress (gdbarch
, next_pc
));
14225 /* Check if the breakpoints used for software single stepping
14226 were inserted or not. */
14229 single_step_breakpoints_inserted (void)
14231 return (single_step_breakpoints
[0] != NULL
14232 || single_step_breakpoints
[1] != NULL
);
14235 /* Remove and delete any breakpoints used for software single step. */
14238 remove_single_step_breakpoints (void)
14240 gdb_assert (single_step_breakpoints
[0] != NULL
);
14242 /* See insert_single_step_breakpoint for more about this deprecated
14244 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
14245 single_step_breakpoints
[0]);
14246 single_step_gdbarch
[0] = NULL
;
14247 single_step_breakpoints
[0] = NULL
;
14249 if (single_step_breakpoints
[1] != NULL
)
14251 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
14252 single_step_breakpoints
[1]);
14253 single_step_gdbarch
[1] = NULL
;
14254 single_step_breakpoints
[1] = NULL
;
14258 /* Delete software single step breakpoints without removing them from
14259 the inferior. This is intended to be used if the inferior's address
14260 space where they were inserted is already gone, e.g. after exit or
14264 cancel_single_step_breakpoints (void)
14268 for (i
= 0; i
< 2; i
++)
14269 if (single_step_breakpoints
[i
])
14271 xfree (single_step_breakpoints
[i
]);
14272 single_step_breakpoints
[i
] = NULL
;
14273 single_step_gdbarch
[i
] = NULL
;
14277 /* Detach software single-step breakpoints from INFERIOR_PTID without
14281 detach_single_step_breakpoints (void)
14285 for (i
= 0; i
< 2; i
++)
14286 if (single_step_breakpoints
[i
])
14287 target_remove_breakpoint (single_step_gdbarch
[i
],
14288 single_step_breakpoints
[i
]);
14291 /* Check whether a software single-step breakpoint is inserted at
14295 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14300 for (i
= 0; i
< 2; i
++)
14302 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
14304 && breakpoint_address_match (bp_tgt
->placed_address_space
,
14305 bp_tgt
->placed_address
,
14313 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14314 non-zero otherwise. */
14316 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
14318 if (syscall_catchpoint_p (bp
)
14319 && bp
->enable_state
!= bp_disabled
14320 && bp
->enable_state
!= bp_call_disabled
)
14327 catch_syscall_enabled (void)
14329 struct catch_syscall_inferior_data
*inf_data
14330 = get_catch_syscall_inferior_data (current_inferior ());
14332 return inf_data
->total_syscalls_count
!= 0;
14336 catching_syscall_number (int syscall_number
)
14338 struct breakpoint
*bp
;
14340 ALL_BREAKPOINTS (bp
)
14341 if (is_syscall_catchpoint_enabled (bp
))
14343 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
14345 if (c
->syscalls_to_be_caught
)
14349 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
14351 if (syscall_number
== iter
)
14361 /* Complete syscall names. Used by "catch syscall". */
14363 catch_syscall_completer (struct cmd_list_element
*cmd
,
14364 char *text
, char *word
)
14366 const char **list
= get_syscall_names ();
14368 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
14374 /* Tracepoint-specific operations. */
14376 /* Set tracepoint count to NUM. */
14378 set_tracepoint_count (int num
)
14380 tracepoint_count
= num
;
14381 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14385 trace_command (char *arg
, int from_tty
)
14387 struct breakpoint_ops
*ops
;
14388 const char *arg_cp
= arg
;
14390 if (arg
&& probe_linespec_to_ops (&arg_cp
))
14391 ops
= &tracepoint_probe_breakpoint_ops
;
14393 ops
= &tracepoint_breakpoint_ops
;
14395 if (create_breakpoint (get_current_arch (),
14397 NULL
, 0, 1 /* parse arg */,
14399 bp_tracepoint
/* type_wanted */,
14400 0 /* Ignore count */,
14401 pending_break_support
,
14405 0 /* internal */, 0))
14406 set_tracepoint_count (breakpoint_count
);
14410 ftrace_command (char *arg
, int from_tty
)
14412 if (create_breakpoint (get_current_arch (),
14414 NULL
, 0, 1 /* parse arg */,
14416 bp_fast_tracepoint
/* type_wanted */,
14417 0 /* Ignore count */,
14418 pending_break_support
,
14419 &tracepoint_breakpoint_ops
,
14422 0 /* internal */, 0))
14423 set_tracepoint_count (breakpoint_count
);
14426 /* strace command implementation. Creates a static tracepoint. */
14429 strace_command (char *arg
, int from_tty
)
14431 struct breakpoint_ops
*ops
;
14433 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14434 or with a normal static tracepoint. */
14435 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
14436 ops
= &strace_marker_breakpoint_ops
;
14438 ops
= &tracepoint_breakpoint_ops
;
14440 if (create_breakpoint (get_current_arch (),
14442 NULL
, 0, 1 /* parse arg */,
14444 bp_static_tracepoint
/* type_wanted */,
14445 0 /* Ignore count */,
14446 pending_break_support
,
14450 0 /* internal */, 0))
14451 set_tracepoint_count (breakpoint_count
);
14454 /* Set up a fake reader function that gets command lines from a linked
14455 list that was acquired during tracepoint uploading. */
14457 static struct uploaded_tp
*this_utp
;
14458 static int next_cmd
;
14461 read_uploaded_action (void)
14465 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14472 /* Given information about a tracepoint as recorded on a target (which
14473 can be either a live system or a trace file), attempt to create an
14474 equivalent GDB tracepoint. This is not a reliable process, since
14475 the target does not necessarily have all the information used when
14476 the tracepoint was originally defined. */
14478 struct tracepoint
*
14479 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14481 char *addr_str
, small_buf
[100];
14482 struct tracepoint
*tp
;
14484 if (utp
->at_string
)
14485 addr_str
= utp
->at_string
;
14488 /* In the absence of a source location, fall back to raw
14489 address. Since there is no way to confirm that the address
14490 means the same thing as when the trace was started, warn the
14492 warning (_("Uploaded tracepoint %d has no "
14493 "source location, using raw address"),
14495 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
14496 addr_str
= small_buf
;
14499 /* There's not much we can do with a sequence of bytecodes. */
14500 if (utp
->cond
&& !utp
->cond_string
)
14501 warning (_("Uploaded tracepoint %d condition "
14502 "has no source form, ignoring it"),
14505 if (!create_breakpoint (get_current_arch (),
14507 utp
->cond_string
, -1, 0 /* parse cond/thread */,
14509 utp
->type
/* type_wanted */,
14510 0 /* Ignore count */,
14511 pending_break_support
,
14512 &tracepoint_breakpoint_ops
,
14514 utp
->enabled
/* enabled */,
14516 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14519 set_tracepoint_count (breakpoint_count
);
14521 /* Get the tracepoint we just created. */
14522 tp
= get_tracepoint (tracepoint_count
);
14523 gdb_assert (tp
!= NULL
);
14527 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
14529 trace_pass_command (small_buf
, 0);
14532 /* If we have uploaded versions of the original commands, set up a
14533 special-purpose "reader" function and call the usual command line
14534 reader, then pass the result to the breakpoint command-setting
14536 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14538 struct command_line
*cmd_list
;
14543 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14545 breakpoint_set_commands (&tp
->base
, cmd_list
);
14547 else if (!VEC_empty (char_ptr
, utp
->actions
)
14548 || !VEC_empty (char_ptr
, utp
->step_actions
))
14549 warning (_("Uploaded tracepoint %d actions "
14550 "have no source form, ignoring them"),
14553 /* Copy any status information that might be available. */
14554 tp
->base
.hit_count
= utp
->hit_count
;
14555 tp
->traceframe_usage
= utp
->traceframe_usage
;
14560 /* Print information on tracepoint number TPNUM_EXP, or all if
14564 tracepoints_info (char *args
, int from_tty
)
14566 struct ui_out
*uiout
= current_uiout
;
14569 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14571 if (num_printed
== 0)
14573 if (args
== NULL
|| *args
== '\0')
14574 ui_out_message (uiout
, 0, "No tracepoints.\n");
14576 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
14579 default_collect_info ();
14582 /* The 'enable trace' command enables tracepoints.
14583 Not supported by all targets. */
14585 enable_trace_command (char *args
, int from_tty
)
14587 enable_command (args
, from_tty
);
14590 /* The 'disable trace' command disables tracepoints.
14591 Not supported by all targets. */
14593 disable_trace_command (char *args
, int from_tty
)
14595 disable_command (args
, from_tty
);
14598 /* Remove a tracepoint (or all if no argument). */
14600 delete_trace_command (char *arg
, int from_tty
)
14602 struct breakpoint
*b
, *b_tmp
;
14608 int breaks_to_delete
= 0;
14610 /* Delete all breakpoints if no argument.
14611 Do not delete internal or call-dummy breakpoints, these
14612 have to be deleted with an explicit breakpoint number
14614 ALL_TRACEPOINTS (b
)
14615 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14617 breaks_to_delete
= 1;
14621 /* Ask user only if there are some breakpoints to delete. */
14623 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14625 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14626 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14627 delete_breakpoint (b
);
14631 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14634 /* Helper function for trace_pass_command. */
14637 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14639 tp
->pass_count
= count
;
14640 observer_notify_tracepoint_modified (tp
->base
.number
);
14642 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14643 tp
->base
.number
, count
);
14646 /* Set passcount for tracepoint.
14648 First command argument is passcount, second is tracepoint number.
14649 If tracepoint number omitted, apply to most recently defined.
14650 Also accepts special argument "all". */
14653 trace_pass_command (char *args
, int from_tty
)
14655 struct tracepoint
*t1
;
14656 unsigned int count
;
14658 if (args
== 0 || *args
== 0)
14659 error (_("passcount command requires an "
14660 "argument (count + optional TP num)"));
14662 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
14664 while (*args
&& isspace ((int) *args
))
14667 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14669 struct breakpoint
*b
;
14671 args
+= 3; /* Skip special argument "all". */
14673 error (_("Junk at end of arguments."));
14675 ALL_TRACEPOINTS (b
)
14677 t1
= (struct tracepoint
*) b
;
14678 trace_pass_set_count (t1
, count
, from_tty
);
14681 else if (*args
== '\0')
14683 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
14685 trace_pass_set_count (t1
, count
, from_tty
);
14689 struct get_number_or_range_state state
;
14691 init_number_or_range (&state
, args
);
14692 while (!state
.finished
)
14694 t1
= get_tracepoint_by_number (&args
, &state
, 1);
14696 trace_pass_set_count (t1
, count
, from_tty
);
14701 struct tracepoint
*
14702 get_tracepoint (int num
)
14704 struct breakpoint
*t
;
14706 ALL_TRACEPOINTS (t
)
14707 if (t
->number
== num
)
14708 return (struct tracepoint
*) t
;
14713 /* Find the tracepoint with the given target-side number (which may be
14714 different from the tracepoint number after disconnecting and
14717 struct tracepoint
*
14718 get_tracepoint_by_number_on_target (int num
)
14720 struct breakpoint
*b
;
14722 ALL_TRACEPOINTS (b
)
14724 struct tracepoint
*t
= (struct tracepoint
*) b
;
14726 if (t
->number_on_target
== num
)
14733 /* Utility: parse a tracepoint number and look it up in the list.
14734 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14735 If OPTIONAL_P is true, then if the argument is missing, the most
14736 recent tracepoint (tracepoint_count) is returned. */
14737 struct tracepoint
*
14738 get_tracepoint_by_number (char **arg
,
14739 struct get_number_or_range_state
*state
,
14742 extern int tracepoint_count
;
14743 struct breakpoint
*t
;
14745 char *instring
= arg
== NULL
? NULL
: *arg
;
14749 gdb_assert (!state
->finished
);
14750 tpnum
= get_number_or_range (state
);
14752 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14755 tpnum
= tracepoint_count
;
14757 error_no_arg (_("tracepoint number"));
14760 tpnum
= get_number (arg
);
14764 if (instring
&& *instring
)
14765 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14768 printf_filtered (_("Tracepoint argument missing "
14769 "and no previous tracepoint\n"));
14773 ALL_TRACEPOINTS (t
)
14774 if (t
->number
== tpnum
)
14776 return (struct tracepoint
*) t
;
14779 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14784 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14786 if (b
->thread
!= -1)
14787 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14790 fprintf_unfiltered (fp
, " task %d", b
->task
);
14792 fprintf_unfiltered (fp
, "\n");
14795 /* Save information on user settable breakpoints (watchpoints, etc) to
14796 a new script file named FILENAME. If FILTER is non-NULL, call it
14797 on each breakpoint and only include the ones for which it returns
14801 save_breakpoints (char *filename
, int from_tty
,
14802 int (*filter
) (const struct breakpoint
*))
14804 struct breakpoint
*tp
;
14807 struct cleanup
*cleanup
;
14808 struct ui_file
*fp
;
14809 int extra_trace_bits
= 0;
14811 if (filename
== 0 || *filename
== 0)
14812 error (_("Argument required (file name in which to save)"));
14814 /* See if we have anything to save. */
14815 ALL_BREAKPOINTS (tp
)
14817 /* Skip internal and momentary breakpoints. */
14818 if (!user_breakpoint_p (tp
))
14821 /* If we have a filter, only save the breakpoints it accepts. */
14822 if (filter
&& !filter (tp
))
14827 if (is_tracepoint (tp
))
14829 extra_trace_bits
= 1;
14831 /* We can stop searching. */
14838 warning (_("Nothing to save."));
14842 pathname
= tilde_expand (filename
);
14843 cleanup
= make_cleanup (xfree
, pathname
);
14844 fp
= gdb_fopen (pathname
, "w");
14846 error (_("Unable to open file '%s' for saving (%s)"),
14847 filename
, safe_strerror (errno
));
14848 make_cleanup_ui_file_delete (fp
);
14850 if (extra_trace_bits
)
14851 save_trace_state_variables (fp
);
14853 ALL_BREAKPOINTS (tp
)
14855 /* Skip internal and momentary breakpoints. */
14856 if (!user_breakpoint_p (tp
))
14859 /* If we have a filter, only save the breakpoints it accepts. */
14860 if (filter
&& !filter (tp
))
14863 tp
->ops
->print_recreate (tp
, fp
);
14865 /* Note, we can't rely on tp->number for anything, as we can't
14866 assume the recreated breakpoint numbers will match. Use $bpnum
14869 if (tp
->cond_string
)
14870 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
14872 if (tp
->ignore_count
)
14873 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
14877 volatile struct gdb_exception ex
;
14879 fprintf_unfiltered (fp
, " commands\n");
14881 ui_out_redirect (current_uiout
, fp
);
14882 TRY_CATCH (ex
, RETURN_MASK_ALL
)
14884 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
14886 ui_out_redirect (current_uiout
, NULL
);
14889 throw_exception (ex
);
14891 fprintf_unfiltered (fp
, " end\n");
14894 if (tp
->enable_state
== bp_disabled
)
14895 fprintf_unfiltered (fp
, "disable\n");
14897 /* If this is a multi-location breakpoint, check if the locations
14898 should be individually disabled. Watchpoint locations are
14899 special, and not user visible. */
14900 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14902 struct bp_location
*loc
;
14905 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
14907 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
14911 if (extra_trace_bits
&& *default_collect
)
14912 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
14914 do_cleanups (cleanup
);
14916 printf_filtered (_("Saved to file '%s'.\n"), filename
);
14919 /* The `save breakpoints' command. */
14922 save_breakpoints_command (char *args
, int from_tty
)
14924 save_breakpoints (args
, from_tty
, NULL
);
14927 /* The `save tracepoints' command. */
14930 save_tracepoints_command (char *args
, int from_tty
)
14932 save_breakpoints (args
, from_tty
, is_tracepoint
);
14935 /* Create a vector of all tracepoints. */
14937 VEC(breakpoint_p
) *
14938 all_tracepoints (void)
14940 VEC(breakpoint_p
) *tp_vec
= 0;
14941 struct breakpoint
*tp
;
14943 ALL_TRACEPOINTS (tp
)
14945 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
14952 /* This help string is used for the break, hbreak, tbreak and thbreak
14953 commands. It is defined as a macro to prevent duplication.
14954 COMMAND should be a string constant containing the name of the
14956 #define BREAK_ARGS_HELP(command) \
14957 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
14958 LOCATION may be a line number, function name, or \"*\" and an address.\n\
14959 If a line number is specified, break at start of code for that line.\n\
14960 If a function is specified, break at start of code for that function.\n\
14961 If an address is specified, break at that exact address.\n\
14962 With no LOCATION, uses current execution address of the selected\n\
14963 stack frame. This is useful for breaking on return to a stack frame.\n\
14965 THREADNUM is the number from \"info threads\".\n\
14966 CONDITION is a boolean expression.\n\
14968 Multiple breakpoints at one place are permitted, and useful if their\n\
14969 conditions are different.\n\
14971 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14973 /* List of subcommands for "catch". */
14974 static struct cmd_list_element
*catch_cmdlist
;
14976 /* List of subcommands for "tcatch". */
14977 static struct cmd_list_element
*tcatch_cmdlist
;
14980 add_catch_command (char *name
, char *docstring
,
14981 void (*sfunc
) (char *args
, int from_tty
,
14982 struct cmd_list_element
*command
),
14983 char **(*completer
) (struct cmd_list_element
*cmd
,
14984 char *text
, char *word
),
14985 void *user_data_catch
,
14986 void *user_data_tcatch
)
14988 struct cmd_list_element
*command
;
14990 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
14992 set_cmd_sfunc (command
, sfunc
);
14993 set_cmd_context (command
, user_data_catch
);
14994 set_cmd_completer (command
, completer
);
14996 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
14998 set_cmd_sfunc (command
, sfunc
);
14999 set_cmd_context (command
, user_data_tcatch
);
15000 set_cmd_completer (command
, completer
);
15004 clear_syscall_counts (struct inferior
*inf
)
15006 struct catch_syscall_inferior_data
*inf_data
15007 = get_catch_syscall_inferior_data (inf
);
15009 inf_data
->total_syscalls_count
= 0;
15010 inf_data
->any_syscall_count
= 0;
15011 VEC_free (int, inf_data
->syscalls_counts
);
15015 save_command (char *arg
, int from_tty
)
15017 printf_unfiltered (_("\"save\" must be followed by "
15018 "the name of a save subcommand.\n"));
15019 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
15022 struct breakpoint
*
15023 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15026 struct breakpoint
*b
, *b_tmp
;
15028 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15030 if ((*callback
) (b
, data
))
15037 /* Zero if any of the breakpoint's locations could be a location where
15038 functions have been inlined, nonzero otherwise. */
15041 is_non_inline_function (struct breakpoint
*b
)
15043 /* The shared library event breakpoint is set on the address of a
15044 non-inline function. */
15045 if (b
->type
== bp_shlib_event
)
15051 /* Nonzero if the specified PC cannot be a location where functions
15052 have been inlined. */
15055 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15056 const struct target_waitstatus
*ws
)
15058 struct breakpoint
*b
;
15059 struct bp_location
*bl
;
15061 ALL_BREAKPOINTS (b
)
15063 if (!is_non_inline_function (b
))
15066 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15068 if (!bl
->shlib_disabled
15069 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15078 initialize_breakpoint_ops (void)
15080 static int initialized
= 0;
15082 struct breakpoint_ops
*ops
;
15088 /* The breakpoint_ops structure to be inherit by all kinds of
15089 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15090 internal and momentary breakpoints, etc.). */
15091 ops
= &bkpt_base_breakpoint_ops
;
15092 *ops
= base_breakpoint_ops
;
15093 ops
->re_set
= bkpt_re_set
;
15094 ops
->insert_location
= bkpt_insert_location
;
15095 ops
->remove_location
= bkpt_remove_location
;
15096 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15097 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15098 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15099 ops
->decode_linespec
= bkpt_decode_linespec
;
15101 /* The breakpoint_ops structure to be used in regular breakpoints. */
15102 ops
= &bkpt_breakpoint_ops
;
15103 *ops
= bkpt_base_breakpoint_ops
;
15104 ops
->re_set
= bkpt_re_set
;
15105 ops
->resources_needed
= bkpt_resources_needed
;
15106 ops
->print_it
= bkpt_print_it
;
15107 ops
->print_mention
= bkpt_print_mention
;
15108 ops
->print_recreate
= bkpt_print_recreate
;
15110 /* Ranged breakpoints. */
15111 ops
= &ranged_breakpoint_ops
;
15112 *ops
= bkpt_breakpoint_ops
;
15113 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15114 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15115 ops
->print_it
= print_it_ranged_breakpoint
;
15116 ops
->print_one
= print_one_ranged_breakpoint
;
15117 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15118 ops
->print_mention
= print_mention_ranged_breakpoint
;
15119 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15121 /* Internal breakpoints. */
15122 ops
= &internal_breakpoint_ops
;
15123 *ops
= bkpt_base_breakpoint_ops
;
15124 ops
->re_set
= internal_bkpt_re_set
;
15125 ops
->check_status
= internal_bkpt_check_status
;
15126 ops
->print_it
= internal_bkpt_print_it
;
15127 ops
->print_mention
= internal_bkpt_print_mention
;
15129 /* Momentary breakpoints. */
15130 ops
= &momentary_breakpoint_ops
;
15131 *ops
= bkpt_base_breakpoint_ops
;
15132 ops
->re_set
= momentary_bkpt_re_set
;
15133 ops
->check_status
= momentary_bkpt_check_status
;
15134 ops
->print_it
= momentary_bkpt_print_it
;
15135 ops
->print_mention
= momentary_bkpt_print_mention
;
15137 /* Probe breakpoints. */
15138 ops
= &bkpt_probe_breakpoint_ops
;
15139 *ops
= bkpt_breakpoint_ops
;
15140 ops
->insert_location
= bkpt_probe_insert_location
;
15141 ops
->remove_location
= bkpt_probe_remove_location
;
15142 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15143 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15145 /* GNU v3 exception catchpoints. */
15146 ops
= &gnu_v3_exception_catchpoint_ops
;
15147 *ops
= bkpt_breakpoint_ops
;
15148 ops
->print_it
= print_it_exception_catchpoint
;
15149 ops
->print_one
= print_one_exception_catchpoint
;
15150 ops
->print_mention
= print_mention_exception_catchpoint
;
15151 ops
->print_recreate
= print_recreate_exception_catchpoint
;
15154 ops
= &watchpoint_breakpoint_ops
;
15155 *ops
= base_breakpoint_ops
;
15156 ops
->dtor
= dtor_watchpoint
;
15157 ops
->re_set
= re_set_watchpoint
;
15158 ops
->insert_location
= insert_watchpoint
;
15159 ops
->remove_location
= remove_watchpoint
;
15160 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15161 ops
->check_status
= check_status_watchpoint
;
15162 ops
->resources_needed
= resources_needed_watchpoint
;
15163 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15164 ops
->print_it
= print_it_watchpoint
;
15165 ops
->print_mention
= print_mention_watchpoint
;
15166 ops
->print_recreate
= print_recreate_watchpoint
;
15168 /* Masked watchpoints. */
15169 ops
= &masked_watchpoint_breakpoint_ops
;
15170 *ops
= watchpoint_breakpoint_ops
;
15171 ops
->insert_location
= insert_masked_watchpoint
;
15172 ops
->remove_location
= remove_masked_watchpoint
;
15173 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15174 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15175 ops
->print_it
= print_it_masked_watchpoint
;
15176 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15177 ops
->print_mention
= print_mention_masked_watchpoint
;
15178 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15181 ops
= &tracepoint_breakpoint_ops
;
15182 *ops
= base_breakpoint_ops
;
15183 ops
->re_set
= tracepoint_re_set
;
15184 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15185 ops
->print_one_detail
= tracepoint_print_one_detail
;
15186 ops
->print_mention
= tracepoint_print_mention
;
15187 ops
->print_recreate
= tracepoint_print_recreate
;
15188 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15189 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15190 ops
->decode_linespec
= tracepoint_decode_linespec
;
15192 /* Probe tracepoints. */
15193 ops
= &tracepoint_probe_breakpoint_ops
;
15194 *ops
= tracepoint_breakpoint_ops
;
15195 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15196 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15198 /* Static tracepoints with marker (`-m'). */
15199 ops
= &strace_marker_breakpoint_ops
;
15200 *ops
= tracepoint_breakpoint_ops
;
15201 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15202 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15203 ops
->decode_linespec
= strace_marker_decode_linespec
;
15205 /* Fork catchpoints. */
15206 ops
= &catch_fork_breakpoint_ops
;
15207 *ops
= base_breakpoint_ops
;
15208 ops
->insert_location
= insert_catch_fork
;
15209 ops
->remove_location
= remove_catch_fork
;
15210 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15211 ops
->print_it
= print_it_catch_fork
;
15212 ops
->print_one
= print_one_catch_fork
;
15213 ops
->print_mention
= print_mention_catch_fork
;
15214 ops
->print_recreate
= print_recreate_catch_fork
;
15216 /* Vfork catchpoints. */
15217 ops
= &catch_vfork_breakpoint_ops
;
15218 *ops
= base_breakpoint_ops
;
15219 ops
->insert_location
= insert_catch_vfork
;
15220 ops
->remove_location
= remove_catch_vfork
;
15221 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15222 ops
->print_it
= print_it_catch_vfork
;
15223 ops
->print_one
= print_one_catch_vfork
;
15224 ops
->print_mention
= print_mention_catch_vfork
;
15225 ops
->print_recreate
= print_recreate_catch_vfork
;
15227 /* Exec catchpoints. */
15228 ops
= &catch_exec_breakpoint_ops
;
15229 *ops
= base_breakpoint_ops
;
15230 ops
->dtor
= dtor_catch_exec
;
15231 ops
->insert_location
= insert_catch_exec
;
15232 ops
->remove_location
= remove_catch_exec
;
15233 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15234 ops
->print_it
= print_it_catch_exec
;
15235 ops
->print_one
= print_one_catch_exec
;
15236 ops
->print_mention
= print_mention_catch_exec
;
15237 ops
->print_recreate
= print_recreate_catch_exec
;
15239 /* Syscall catchpoints. */
15240 ops
= &catch_syscall_breakpoint_ops
;
15241 *ops
= base_breakpoint_ops
;
15242 ops
->dtor
= dtor_catch_syscall
;
15243 ops
->insert_location
= insert_catch_syscall
;
15244 ops
->remove_location
= remove_catch_syscall
;
15245 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
15246 ops
->print_it
= print_it_catch_syscall
;
15247 ops
->print_one
= print_one_catch_syscall
;
15248 ops
->print_mention
= print_mention_catch_syscall
;
15249 ops
->print_recreate
= print_recreate_catch_syscall
;
15251 /* Solib-related catchpoints. */
15252 ops
= &catch_solib_breakpoint_ops
;
15253 *ops
= base_breakpoint_ops
;
15254 ops
->dtor
= dtor_catch_solib
;
15255 ops
->insert_location
= insert_catch_solib
;
15256 ops
->remove_location
= remove_catch_solib
;
15257 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15258 ops
->check_status
= check_status_catch_solib
;
15259 ops
->print_it
= print_it_catch_solib
;
15260 ops
->print_one
= print_one_catch_solib
;
15261 ops
->print_mention
= print_mention_catch_solib
;
15262 ops
->print_recreate
= print_recreate_catch_solib
;
15266 _initialize_breakpoint (void)
15268 struct cmd_list_element
*c
;
15270 initialize_breakpoint_ops ();
15272 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15273 observer_attach_inferior_exit (clear_syscall_counts
);
15274 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15276 breakpoint_objfile_key
15277 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15279 catch_syscall_inferior_data
15280 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup
);
15282 breakpoint_chain
= 0;
15283 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15284 before a breakpoint is set. */
15285 breakpoint_count
= 0;
15287 tracepoint_count
= 0;
15289 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15290 Set ignore-count of breakpoint number N to COUNT.\n\
15291 Usage is `ignore N COUNT'."));
15293 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
15295 add_com ("commands", class_breakpoint
, commands_command
, _("\
15296 Set commands to be executed when a breakpoint is hit.\n\
15297 Give breakpoint number as argument after \"commands\".\n\
15298 With no argument, the targeted breakpoint is the last one set.\n\
15299 The commands themselves follow starting on the next line.\n\
15300 Type a line containing \"end\" to indicate the end of them.\n\
15301 Give \"silent\" as the first line to make the breakpoint silent;\n\
15302 then no output is printed when it is hit, except what the commands print."));
15304 add_com ("condition", class_breakpoint
, condition_command
, _("\
15305 Specify breakpoint number N to break only if COND is true.\n\
15306 Usage is `condition N COND', where N is an integer and COND is an\n\
15307 expression to be evaluated whenever breakpoint N is reached."));
15309 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15310 Set a temporary breakpoint.\n\
15311 Like \"break\" except the breakpoint is only temporary,\n\
15312 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15313 by using \"enable delete\" on the breakpoint number.\n\
15315 BREAK_ARGS_HELP ("tbreak")));
15316 set_cmd_completer (c
, location_completer
);
15318 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15319 Set a hardware assisted breakpoint.\n\
15320 Like \"break\" except the breakpoint requires hardware support,\n\
15321 some target hardware may not have this support.\n\
15323 BREAK_ARGS_HELP ("hbreak")));
15324 set_cmd_completer (c
, location_completer
);
15326 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15327 Set a temporary hardware assisted breakpoint.\n\
15328 Like \"hbreak\" except the breakpoint is only temporary,\n\
15329 so it will be deleted when hit.\n\
15331 BREAK_ARGS_HELP ("thbreak")));
15332 set_cmd_completer (c
, location_completer
);
15334 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15335 Enable some breakpoints.\n\
15336 Give breakpoint numbers (separated by spaces) as arguments.\n\
15337 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15338 This is used to cancel the effect of the \"disable\" command.\n\
15339 With a subcommand you can enable temporarily."),
15340 &enablelist
, "enable ", 1, &cmdlist
);
15342 add_com ("ab", class_breakpoint
, enable_command
, _("\
15343 Enable some breakpoints.\n\
15344 Give breakpoint numbers (separated by spaces) as arguments.\n\
15345 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15346 This is used to cancel the effect of the \"disable\" command.\n\
15347 With a subcommand you can enable temporarily."));
15349 add_com_alias ("en", "enable", class_breakpoint
, 1);
15351 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15352 Enable some breakpoints.\n\
15353 Give breakpoint numbers (separated by spaces) as arguments.\n\
15354 This is used to cancel the effect of the \"disable\" command.\n\
15355 May be abbreviated to simply \"enable\".\n"),
15356 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15358 add_cmd ("once", no_class
, enable_once_command
, _("\
15359 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15360 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15363 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15364 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15365 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15368 add_cmd ("count", no_class
, enable_count_command
, _("\
15369 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15370 If a breakpoint is hit while enabled in this fashion,\n\
15371 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15374 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15375 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15376 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15379 add_cmd ("once", no_class
, enable_once_command
, _("\
15380 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15381 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15384 add_cmd ("count", no_class
, enable_count_command
, _("\
15385 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15386 If a breakpoint is hit while enabled in this fashion,\n\
15387 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15390 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15391 Disable some breakpoints.\n\
15392 Arguments are breakpoint numbers with spaces in between.\n\
15393 To disable all breakpoints, give no argument.\n\
15394 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15395 &disablelist
, "disable ", 1, &cmdlist
);
15396 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15397 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15399 add_com ("sb", class_breakpoint
, disable_command
, _("\
15400 Disable some breakpoints.\n\
15401 Arguments are breakpoint numbers with spaces in between.\n\
15402 To disable all breakpoints, give no argument.\n\
15403 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15405 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15406 Disable some breakpoints.\n\
15407 Arguments are breakpoint numbers with spaces in between.\n\
15408 To disable all breakpoints, give no argument.\n\
15409 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15410 This command may be abbreviated \"disable\"."),
15413 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15414 Delete some breakpoints or auto-display expressions.\n\
15415 Arguments are breakpoint numbers with spaces in between.\n\
15416 To delete all breakpoints, give no argument.\n\
15418 Also a prefix command for deletion of other GDB objects.\n\
15419 The \"unset\" command is also an alias for \"delete\"."),
15420 &deletelist
, "delete ", 1, &cmdlist
);
15421 add_com_alias ("d", "delete", class_breakpoint
, 1);
15422 add_com_alias ("del", "delete", class_breakpoint
, 1);
15424 add_com ("db", class_breakpoint
, delete_command
, _("\
15425 Delete some breakpoints.\n\
15426 Arguments are breakpoint numbers with spaces in between.\n\
15427 To delete all breakpoints, give no argument.\n"));
15429 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15430 Delete some breakpoints or auto-display expressions.\n\
15431 Arguments are breakpoint numbers with spaces in between.\n\
15432 To delete all breakpoints, give no argument.\n\
15433 This command may be abbreviated \"delete\"."),
15436 add_com ("clear", class_breakpoint
, clear_command
, _("\
15437 Clear breakpoint at specified line or function.\n\
15438 Argument may be line number, function name, or \"*\" and an address.\n\
15439 If line number is specified, all breakpoints in that line are cleared.\n\
15440 If function is specified, breakpoints at beginning of function are cleared.\n\
15441 If an address is specified, breakpoints at that address are cleared.\n\
15443 With no argument, clears all breakpoints in the line that the selected frame\n\
15444 is executing in.\n\
15446 See also the \"delete\" command which clears breakpoints by number."));
15447 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15449 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15450 Set breakpoint at specified line or function.\n"
15451 BREAK_ARGS_HELP ("break")));
15452 set_cmd_completer (c
, location_completer
);
15454 add_com_alias ("b", "break", class_run
, 1);
15455 add_com_alias ("br", "break", class_run
, 1);
15456 add_com_alias ("bre", "break", class_run
, 1);
15457 add_com_alias ("brea", "break", class_run
, 1);
15460 add_com_alias ("ba", "break", class_breakpoint
, 1);
15464 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15465 Break in function/address or break at a line in the current file."),
15466 &stoplist
, "stop ", 1, &cmdlist
);
15467 add_cmd ("in", class_breakpoint
, stopin_command
,
15468 _("Break in function or address."), &stoplist
);
15469 add_cmd ("at", class_breakpoint
, stopat_command
,
15470 _("Break at a line in the current file."), &stoplist
);
15471 add_com ("status", class_info
, breakpoints_info
, _("\
15472 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15473 The \"Type\" column indicates one of:\n\
15474 \tbreakpoint - normal breakpoint\n\
15475 \twatchpoint - watchpoint\n\
15476 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15477 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15478 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15479 address and file/line number respectively.\n\
15481 Convenience variable \"$_\" and default examine address for \"x\"\n\
15482 are set to the address of the last breakpoint listed unless the command\n\
15483 is prefixed with \"server \".\n\n\
15484 Convenience variable \"$bpnum\" contains the number of the last\n\
15485 breakpoint set."));
15488 add_info ("breakpoints", breakpoints_info
, _("\
15489 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15490 The \"Type\" column indicates one of:\n\
15491 \tbreakpoint - normal breakpoint\n\
15492 \twatchpoint - watchpoint\n\
15493 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15494 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15495 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15496 address and file/line number respectively.\n\
15498 Convenience variable \"$_\" and default examine address for \"x\"\n\
15499 are set to the address of the last breakpoint listed unless the command\n\
15500 is prefixed with \"server \".\n\n\
15501 Convenience variable \"$bpnum\" contains the number of the last\n\
15502 breakpoint set."));
15504 add_info_alias ("b", "breakpoints", 1);
15507 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
15508 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15509 The \"Type\" column indicates one of:\n\
15510 \tbreakpoint - normal breakpoint\n\
15511 \twatchpoint - watchpoint\n\
15512 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15513 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15514 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15515 address and file/line number respectively.\n\
15517 Convenience variable \"$_\" and default examine address for \"x\"\n\
15518 are set to the address of the last breakpoint listed unless the command\n\
15519 is prefixed with \"server \".\n\n\
15520 Convenience variable \"$bpnum\" contains the number of the last\n\
15521 breakpoint set."));
15523 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15524 Status of all breakpoints, or breakpoint number NUMBER.\n\
15525 The \"Type\" column indicates one of:\n\
15526 \tbreakpoint - normal breakpoint\n\
15527 \twatchpoint - watchpoint\n\
15528 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15529 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15530 \tuntil - internal breakpoint used by the \"until\" command\n\
15531 \tfinish - internal breakpoint used by the \"finish\" command\n\
15532 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15533 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15534 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15535 address and file/line number respectively.\n\
15537 Convenience variable \"$_\" and default examine address for \"x\"\n\
15538 are set to the address of the last breakpoint listed unless the command\n\
15539 is prefixed with \"server \".\n\n\
15540 Convenience variable \"$bpnum\" contains the number of the last\n\
15542 &maintenanceinfolist
);
15544 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15545 Set catchpoints to catch events."),
15546 &catch_cmdlist
, "catch ",
15547 0/*allow-unknown*/, &cmdlist
);
15549 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15550 Set temporary catchpoints to catch events."),
15551 &tcatch_cmdlist
, "tcatch ",
15552 0/*allow-unknown*/, &cmdlist
);
15554 /* Add catch and tcatch sub-commands. */
15555 add_catch_command ("catch", _("\
15556 Catch an exception, when caught."),
15557 catch_catch_command
,
15561 add_catch_command ("throw", _("\
15562 Catch an exception, when thrown."),
15563 catch_throw_command
,
15567 add_catch_command ("fork", _("Catch calls to fork."),
15568 catch_fork_command_1
,
15570 (void *) (uintptr_t) catch_fork_permanent
,
15571 (void *) (uintptr_t) catch_fork_temporary
);
15572 add_catch_command ("vfork", _("Catch calls to vfork."),
15573 catch_fork_command_1
,
15575 (void *) (uintptr_t) catch_vfork_permanent
,
15576 (void *) (uintptr_t) catch_vfork_temporary
);
15577 add_catch_command ("exec", _("Catch calls to exec."),
15578 catch_exec_command_1
,
15582 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15583 Usage: catch load [REGEX]\n\
15584 If REGEX is given, only stop for libraries matching the regular expression."),
15585 catch_load_command_1
,
15589 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15590 Usage: catch unload [REGEX]\n\
15591 If REGEX is given, only stop for libraries matching the regular expression."),
15592 catch_unload_command_1
,
15596 add_catch_command ("syscall", _("\
15597 Catch system calls by their names and/or numbers.\n\
15598 Arguments say which system calls to catch. If no arguments\n\
15599 are given, every system call will be caught.\n\
15600 Arguments, if given, should be one or more system call names\n\
15601 (if your system supports that), or system call numbers."),
15602 catch_syscall_command_1
,
15603 catch_syscall_completer
,
15607 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15608 Set a watchpoint for an expression.\n\
15609 Usage: watch [-l|-location] EXPRESSION\n\
15610 A watchpoint stops execution of your program whenever the value of\n\
15611 an expression changes.\n\
15612 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15613 the memory to which it refers."));
15614 set_cmd_completer (c
, expression_completer
);
15616 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15617 Set a read watchpoint for an expression.\n\
15618 Usage: rwatch [-l|-location] EXPRESSION\n\
15619 A watchpoint stops execution of your program whenever the value of\n\
15620 an expression is read.\n\
15621 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15622 the memory to which it refers."));
15623 set_cmd_completer (c
, expression_completer
);
15625 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15626 Set a watchpoint for an expression.\n\
15627 Usage: awatch [-l|-location] EXPRESSION\n\
15628 A watchpoint stops execution of your program whenever the value of\n\
15629 an expression is either read or written.\n\
15630 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15631 the memory to which it refers."));
15632 set_cmd_completer (c
, expression_completer
);
15634 add_info ("watchpoints", watchpoints_info
, _("\
15635 Status of specified watchpoints (all watchpoints if no argument)."));
15637 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15638 respond to changes - contrary to the description. */
15639 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15640 &can_use_hw_watchpoints
, _("\
15641 Set debugger's willingness to use watchpoint hardware."), _("\
15642 Show debugger's willingness to use watchpoint hardware."), _("\
15643 If zero, gdb will not use hardware for new watchpoints, even if\n\
15644 such is available. (However, any hardware watchpoints that were\n\
15645 created before setting this to nonzero, will continue to use watchpoint\n\
15648 show_can_use_hw_watchpoints
,
15649 &setlist
, &showlist
);
15651 can_use_hw_watchpoints
= 1;
15653 /* Tracepoint manipulation commands. */
15655 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15656 Set a tracepoint at specified line or function.\n\
15658 BREAK_ARGS_HELP ("trace") "\n\
15659 Do \"help tracepoints\" for info on other tracepoint commands."));
15660 set_cmd_completer (c
, location_completer
);
15662 add_com_alias ("tp", "trace", class_alias
, 0);
15663 add_com_alias ("tr", "trace", class_alias
, 1);
15664 add_com_alias ("tra", "trace", class_alias
, 1);
15665 add_com_alias ("trac", "trace", class_alias
, 1);
15667 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15668 Set a fast tracepoint at specified line or function.\n\
15670 BREAK_ARGS_HELP ("ftrace") "\n\
15671 Do \"help tracepoints\" for info on other tracepoint commands."));
15672 set_cmd_completer (c
, location_completer
);
15674 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15675 Set a static tracepoint at specified line, function or marker.\n\
15677 strace [LOCATION] [if CONDITION]\n\
15678 LOCATION may be a line number, function name, \"*\" and an address,\n\
15679 or -m MARKER_ID.\n\
15680 If a line number is specified, probe the marker at start of code\n\
15681 for that line. If a function is specified, probe the marker at start\n\
15682 of code for that function. If an address is specified, probe the marker\n\
15683 at that exact address. If a marker id is specified, probe the marker\n\
15684 with that name. With no LOCATION, uses current execution address of\n\
15685 the selected stack frame.\n\
15686 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15687 This collects arbitrary user data passed in the probe point call to the\n\
15688 tracing library. You can inspect it when analyzing the trace buffer,\n\
15689 by printing the $_sdata variable like any other convenience variable.\n\
15691 CONDITION is a boolean expression.\n\
15693 Multiple tracepoints at one place are permitted, and useful if their\n\
15694 conditions are different.\n\
15696 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15697 Do \"help tracepoints\" for info on other tracepoint commands."));
15698 set_cmd_completer (c
, location_completer
);
15700 add_info ("tracepoints", tracepoints_info
, _("\
15701 Status of specified tracepoints (all tracepoints if no argument).\n\
15702 Convenience variable \"$tpnum\" contains the number of the\n\
15703 last tracepoint set."));
15705 add_info_alias ("tp", "tracepoints", 1);
15707 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15708 Delete specified tracepoints.\n\
15709 Arguments are tracepoint numbers, separated by spaces.\n\
15710 No argument means delete all tracepoints."),
15713 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15714 Disable specified tracepoints.\n\
15715 Arguments are tracepoint numbers, separated by spaces.\n\
15716 No argument means disable all tracepoints."),
15718 deprecate_cmd (c
, "disable");
15720 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15721 Enable specified tracepoints.\n\
15722 Arguments are tracepoint numbers, separated by spaces.\n\
15723 No argument means enable all tracepoints."),
15725 deprecate_cmd (c
, "enable");
15727 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15728 Set the passcount for a tracepoint.\n\
15729 The trace will end when the tracepoint has been passed 'count' times.\n\
15730 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15731 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15733 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15734 _("Save breakpoint definitions as a script."),
15735 &save_cmdlist
, "save ",
15736 0/*allow-unknown*/, &cmdlist
);
15738 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15739 Save current breakpoint definitions as a script.\n\
15740 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15741 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15742 session to restore them."),
15744 set_cmd_completer (c
, filename_completer
);
15746 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15747 Save current tracepoint definitions as a script.\n\
15748 Use the 'source' command in another debug session to restore them."),
15750 set_cmd_completer (c
, filename_completer
);
15752 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15753 deprecate_cmd (c
, "save tracepoints");
15755 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15756 Breakpoint specific settings\n\
15757 Configure various breakpoint-specific variables such as\n\
15758 pending breakpoint behavior"),
15759 &breakpoint_set_cmdlist
, "set breakpoint ",
15760 0/*allow-unknown*/, &setlist
);
15761 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15762 Breakpoint specific settings\n\
15763 Configure various breakpoint-specific variables such as\n\
15764 pending breakpoint behavior"),
15765 &breakpoint_show_cmdlist
, "show breakpoint ",
15766 0/*allow-unknown*/, &showlist
);
15768 add_setshow_auto_boolean_cmd ("pending", no_class
,
15769 &pending_break_support
, _("\
15770 Set debugger's behavior regarding pending breakpoints."), _("\
15771 Show debugger's behavior regarding pending breakpoints."), _("\
15772 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15773 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15774 an error. If auto, an unrecognized breakpoint location results in a\n\
15775 user-query to see if a pending breakpoint should be created."),
15777 show_pending_break_support
,
15778 &breakpoint_set_cmdlist
,
15779 &breakpoint_show_cmdlist
);
15781 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15783 add_setshow_boolean_cmd ("auto-hw", no_class
,
15784 &automatic_hardware_breakpoints
, _("\
15785 Set automatic usage of hardware breakpoints."), _("\
15786 Show automatic usage of hardware breakpoints."), _("\
15787 If set, the debugger will automatically use hardware breakpoints for\n\
15788 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15789 a warning will be emitted for such breakpoints."),
15791 show_automatic_hardware_breakpoints
,
15792 &breakpoint_set_cmdlist
,
15793 &breakpoint_show_cmdlist
);
15795 add_setshow_enum_cmd ("always-inserted", class_support
,
15796 always_inserted_enums
, &always_inserted_mode
, _("\
15797 Set mode for inserting breakpoints."), _("\
15798 Show mode for inserting breakpoints."), _("\
15799 When this mode is off, breakpoints are inserted in inferior when it is\n\
15800 resumed, and removed when execution stops. When this mode is on,\n\
15801 breakpoints are inserted immediately and removed only when the user\n\
15802 deletes the breakpoint. When this mode is auto (which is the default),\n\
15803 the behaviour depends on the non-stop setting (see help set non-stop).\n\
15804 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
15805 behaves as if always-inserted mode is on; if gdb is controlling the\n\
15806 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
15808 &show_always_inserted_mode
,
15809 &breakpoint_set_cmdlist
,
15810 &breakpoint_show_cmdlist
);
15812 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15813 condition_evaluation_enums
,
15814 &condition_evaluation_mode_1
, _("\
15815 Set mode of breakpoint condition evaluation."), _("\
15816 Show mode of breakpoint condition evaluation."), _("\
15817 When this is set to \"host\", breakpoint conditions will be\n\
15818 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15819 breakpoint conditions will be downloaded to the target (if the target\n\
15820 supports such feature) and conditions will be evaluated on the target's side.\n\
15821 If this is set to \"auto\" (default), this will be automatically set to\n\
15822 \"target\" if it supports condition evaluation, otherwise it will\n\
15823 be set to \"gdb\""),
15824 &set_condition_evaluation_mode
,
15825 &show_condition_evaluation_mode
,
15826 &breakpoint_set_cmdlist
,
15827 &breakpoint_show_cmdlist
);
15829 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15830 Set a breakpoint for an address range.\n\
15831 break-range START-LOCATION, END-LOCATION\n\
15832 where START-LOCATION and END-LOCATION can be one of the following:\n\
15833 LINENUM, for that line in the current file,\n\
15834 FILE:LINENUM, for that line in that file,\n\
15835 +OFFSET, for that number of lines after the current line\n\
15836 or the start of the range\n\
15837 FUNCTION, for the first line in that function,\n\
15838 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15839 *ADDRESS, for the instruction at that address.\n\
15841 The breakpoint will stop execution of the inferior whenever it executes\n\
15842 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15843 range (including START-LOCATION and END-LOCATION)."));
15845 automatic_hardware_breakpoints
= 1;
15847 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);